staffa 0.15.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +99 -271
- package/dist/components/autocomplete.js +4 -5
- package/dist/components/box.js +11 -21
- package/dist/components/button.d.ts +20 -5
- package/dist/components/button.js +55 -47
- package/dist/components/buttonChooser.js +1 -3
- package/dist/components/checkbox.js +1 -2
- package/dist/components/dialog.d.ts +9 -2
- package/dist/components/dialog.js +28 -32
- package/dist/components/field.d.ts +5 -8
- package/dist/components/field.js +4 -6
- package/dist/components/form.d.ts +5 -7
- package/dist/components/form.js +6 -9
- package/dist/components/keyhelp.d.ts +22 -0
- package/dist/components/keyhelp.js +91 -0
- package/dist/components/main.js +188 -271
- package/dist/components/menu.d.ts +48 -10
- package/dist/components/menu.js +228 -147
- package/dist/components/panels.d.ts +151 -239
- package/dist/components/panels.js +331 -558
- package/dist/components/select.js +1 -3
- package/dist/components/tabs.d.ts +10 -13
- package/dist/components/tabs.js +38 -58
- package/dist/components/textline.d.ts +3 -5
- package/dist/components/textline.js +3 -5
- package/dist/components/toast.d.ts +1 -3
- package/dist/components/toast.js +2 -3
- package/dist/components/tooltip.d.ts +4 -5
- package/dist/components/tooltip.js +13 -11
- package/dist/core.d.ts +17 -24
- package/dist/core.js +13 -18
- package/dist/icons-helpers.d.ts +3 -3
- package/dist/icons-helpers.js +6 -11
- package/dist/index.d.ts +3 -1
- package/dist/index.js +5 -4
- package/dist/keys.d.ts +92 -0
- package/dist/keys.js +279 -0
- package/dist/staffa.esm.js +1 -1
- package/dist/theme.d.ts +4 -10
- package/dist/theme.js +58 -123
- package/package.json +2 -2
- package/skill/ButtonOptions.md +12 -0
- package/skill/DialogOptions.md +11 -2
- package/skill/FieldOptions.md +3 -5
- package/skill/IconButtonOptions.md +8 -0
- package/skill/MenuItem.md +32 -3
- package/skill/Panel.md +11 -3
- package/skill/SKILL.md +161 -294
- package/skill/addTooltip.md +4 -5
- package/skill/bindKey.md +51 -0
- package/skill/box.md +1 -1
- package/skill/form.md +5 -7
- package/skill/formatKey.md +21 -0
- package/skill/iconButton.md +4 -5
- package/skill/scrollStrip.md +7 -9
- package/skill/showFloatingMenu.md +2 -2
- package/skill/showKeyHelp.md +17 -0
- package/skill/tabs.md +3 -4
- package/skill/textline.md +3 -5
- package/src/components/autocomplete.ts +4 -5
- package/src/components/box.ts +11 -21
- package/src/components/button.ts +70 -47
- package/src/components/buttonChooser.ts +1 -3
- package/src/components/checkbox.ts +1 -2
- package/src/components/dialog.ts +38 -34
- package/src/components/field.ts +7 -11
- package/src/components/form.ts +6 -9
- package/src/components/keyhelp.ts +96 -0
- package/src/components/main.ts +191 -270
- package/src/components/menu.ts +258 -150
- package/src/components/panels.ts +378 -623
- package/src/components/select.ts +1 -3
- package/src/components/tabs.ts +38 -58
- package/src/components/textline.ts +3 -5
- package/src/components/toast.ts +3 -6
- package/src/components/tooltip.ts +12 -11
- package/src/core.ts +17 -24
- package/src/icons-helpers.ts +6 -11
- package/src/index.ts +5 -4
- package/src/keys.ts +300 -0
- package/src/theme.ts +58 -123
- package/skill/Attributes.md +0 -10
|
@@ -110,158 +110,94 @@ function matchRoute(r, segments) {
|
|
|
110
110
|
// ─── Constants ───────────────────────────────────────────────────────────────
|
|
111
111
|
/**
|
|
112
112
|
* The one duration every bit of shell motion shares: the enter/exit fades, the
|
|
113
|
-
* `left` moves
|
|
114
|
-
*
|
|
115
|
-
* can't drift apart.
|
|
116
|
-
*
|
|
117
|
-
* Short enough to read as *the screen responded*, rather than as an animation
|
|
118
|
-
* being played at you: a panel arriving is navigation, and navigation should
|
|
119
|
-
* feel instant even when it moves.
|
|
113
|
+
* sideways `left` moves, the narrow-screen nav slide. Published below as the
|
|
114
|
+
* `--s-panel-ms` custom property, so CSS and JS can't drift apart.
|
|
120
115
|
*/
|
|
121
116
|
const PAGE_MS = 250;
|
|
122
117
|
/** How long a freshly pushed `loading` panel holds its enter animation. */
|
|
123
118
|
const LOADING_HOLD_MS = 300;
|
|
124
119
|
/**
|
|
125
|
-
* The bounds of a column
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
* 360)` stays under it), so capping the lone column of a 540–720px area to it
|
|
129
|
-
* too — centred, rather than stretched — makes an ask's ceiling uniform: never
|
|
130
|
-
* wider than its column count × 540. A content area narrower than 360 still
|
|
131
|
-
* gets its single column, just narrower than the minimum.
|
|
120
|
+
* The bounds of a column: at most 540px — the width columns aim for, the area
|
|
121
|
+
* dividing into the fewest of them that stay within it — and at least 360px,
|
|
122
|
+
* about the narrowest phone in common use, so where a panel's layout is aimed.
|
|
132
123
|
*/
|
|
133
124
|
const SMALL_MIN_PX = 360;
|
|
134
125
|
export const SMALL_MAX_PX = 540;
|
|
135
126
|
/**
|
|
136
|
-
*
|
|
137
|
-
* a
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
* over whatever it was covering — which is the way round both should read.
|
|
127
|
+
* Two `z-index` steps per panel: a panel sits on the odd layer for its depth in
|
|
128
|
+
* the stack, a *closing* one on the even layer just below. So a replacement
|
|
129
|
+
* comes in over the panel it replaces, while a closing panel fades out over
|
|
130
|
+
* whatever it was covering.
|
|
141
131
|
*/
|
|
142
132
|
const LAYER_STEP = 2;
|
|
143
133
|
// ─── Module-level styling ────────────────────────────────────────────────────
|
|
144
134
|
A.insertGlobalCss({
|
|
145
135
|
":root": `--s-panel-ms:${PAGE_MS}ms`,
|
|
146
|
-
// The clipping viewport
|
|
147
|
-
// positioned inside it,
|
|
148
|
-
// `
|
|
149
|
-
//
|
|
150
|
-
//
|
|
151
|
-
// the nav panel that slides across the body — however deep the stack gets.
|
|
152
|
-
// The region paints the columns' sheen over its own box, and every panel
|
|
153
|
-
// paints the very same one (see `.s-panel` below) — which, being a straight
|
|
154
|
-
// vertical wash over boxes of one height, comes out identical whatever a
|
|
155
|
-
// column's width, so the columns and the ground beside them are one
|
|
156
|
-
// continuous surface.
|
|
136
|
+
// The clipping viewport the columns slide through; panels are absolutely
|
|
137
|
+
// positioned inside it, sized and offset from JS (see `layout()`).
|
|
138
|
+
// `isolation` keeps their z-index layers (see LAYER_STEP) below the shell's
|
|
139
|
+
// own chrome. It paints the same PANEL_SHEEN as every panel, so columns and
|
|
140
|
+
// the ground beside them read as one surface.
|
|
157
141
|
// `overflow:clip`, not `hidden`: a hidden box is still a scroll container,
|
|
158
|
-
// and anything that
|
|
159
|
-
//
|
|
160
|
-
// sideways, permanently, because nothing here would ever scroll it back.
|
|
161
|
-
// `clip` clips without being scrollable at all, closing the whole class.
|
|
142
|
+
// and anything that scrolls it (find-in-page, an in-page anchor) shifts every
|
|
143
|
+
// column sideways permanently, with nothing to scroll it back.
|
|
162
144
|
".s-panels": "flex:1 min-width:0 min-height:0 position:relative overflow:clip isolation:isolate " +
|
|
163
145
|
PANEL_SHEEN,
|
|
164
146
|
".s-panel": {
|
|
165
|
-
// A panel rests at a plain `left` offset
|
|
166
|
-
//
|
|
167
|
-
//
|
|
168
|
-
//
|
|
169
|
-
//
|
|
170
|
-
//
|
|
171
|
-
//
|
|
172
|
-
//
|
|
173
|
-
//
|
|
174
|
-
//
|
|
175
|
-
//
|
|
176
|
-
// zero, which looks like the panel vanishing rather than fading.
|
|
177
|
-
// No `overflow:hidden` here: the scroll container below clips the content
|
|
178
|
-
// itself.
|
|
179
|
-
// Layering is set from JS (`layout()` and `beginClose`) rather than left to
|
|
180
|
-
// DOM order: a closing panel is no longer part of the reactive list, so
|
|
181
|
-
// where its element sits among the live ones is Aberdeen's business, not a
|
|
182
|
-
// thing to depend on. `LAYER_*` says what the numbers mean.
|
|
183
|
-
//
|
|
184
|
-
// Every panel paints an opaque ground, because panels animate over one
|
|
185
|
-
// another — entering, leaving, being crowded out — and two transparent ones
|
|
186
|
-
// mean text sliding over text. It takes {@link PANEL_SHEEN}, resolved here
|
|
187
|
-
// against the inherited `--s-bg` (a panel is not a surface, so it has to
|
|
188
|
-
// paint it itself).
|
|
189
|
-
//
|
|
190
|
-
// Painted per panel, over the panel's own box — and yet seamless with its
|
|
191
|
-
// neighbours and with the ground beside them, because that wash runs
|
|
192
|
-
// straight down: it takes its extent from the height these boxes all share,
|
|
193
|
-
// never from their differing widths. See PANEL_SHEEN for why that matters.
|
|
147
|
+
// A panel rests at a plain `left` offset with no transform: a transformed
|
|
148
|
+
// element is composited, costing it subpixel text antialiasing. Transform
|
|
149
|
+
// is used only for the enter/exit slides. No `width` transition either —
|
|
150
|
+
// animating one reflows the column's content every frame.
|
|
151
|
+
// The fade is deliberately `linear` while the drift eases out: an eased
|
|
152
|
+
// opacity spends its last stretch near zero, reading as a vanish.
|
|
153
|
+
// Layering is set from JS (`layout()`, `beginClose`), not DOM order: a
|
|
154
|
+
// closing panel is no longer in the reactive list, so its element's
|
|
155
|
+
// position among the live ones is Aberdeen's business. See LAYER_STEP.
|
|
156
|
+
// PANEL_SHEEN gives every panel an opaque ground (panels animate over one
|
|
157
|
+
// another, and two transparent ones mean text sliding over text).
|
|
194
158
|
"&": "position:absolute top:0 bottom:0 left:0 display:flex flex-direction:column " +
|
|
195
159
|
PANEL_SHEEN + " " +
|
|
196
160
|
"visibility:visible transition: left var(--s-panel-ms) ease, transform var(--s-panel-ms) ease-out, opacity var(--s-panel-ms) linear, visibility 0s;",
|
|
197
|
-
// The hairline between two columns, fading
|
|
198
|
-
//
|
|
199
|
-
//
|
|
200
|
-
// keeps two columns' *contents* comfortably apart, while a gutter on top
|
|
201
|
-
// of that only opened a strip of the panel's own ground between two columns
|
|
202
|
-
// painting theirs. So this sits exactly on the boundary — and an
|
|
203
|
-
// edge-to-edge column (`A("p:0")`) really does reach the line bounding it.
|
|
161
|
+
// The hairline between two columns, fading at both ends (like the sidebar's
|
|
162
|
+
// `.s-nav-sep`). Columns tile with no gutter — each brings its own `$3` of
|
|
163
|
+
// padding — so this sits exactly on the boundary.
|
|
204
164
|
"&.s-panel-sep::before": "content:'' position:absolute left:0 top:0.6rem bottom:0.6rem width:1px z-index:1 " +
|
|
205
165
|
"background: linear-gradient(to bottom, transparent, $s-faint 18%, $s-faint 82%, transparent);",
|
|
206
|
-
//
|
|
207
|
-
//
|
|
208
|
-
//
|
|
209
|
-
//
|
|
210
|
-
// The start state of an enter, adopted with transitions off and then
|
|
211
|
-
// dropped, which is what makes the panel settle instead of jumping.
|
|
166
|
+
// Enter and exit share one vocabulary: a fade over a short 8cqw drift
|
|
167
|
+
// (`cqw`: `.s-main` is the container). This start state is applied with
|
|
168
|
+
// transitions off and then dropped, so the panel settles instead of jumping.
|
|
212
169
|
"&.s-panel-enter": "opacity:0 transition:none transform: translateX(8cqw);",
|
|
213
|
-
// On its way out
|
|
214
|
-
// and out of reach while it does. It leaves the DOM when the fade itself
|
|
215
|
-
// ends (see `playExit`), never part-way through it.
|
|
170
|
+
// On its way out; leaves the DOM when the fade ends (see `playExit`).
|
|
216
171
|
"&.s-panel-closing": "opacity:0 pointer-events:none transform: translateX(8cqw);",
|
|
217
|
-
// Off screen but open: crowded out
|
|
218
|
-
//
|
|
219
|
-
//
|
|
220
|
-
//
|
|
221
|
-
//
|
|
222
|
-
// fade has played: a transitioned `visibility` counts as *visible* for the
|
|
223
|
-
// whole duration and flips at the very end. Revealing it again uses the
|
|
224
|
-
// rule above (`visibility 0s`), so it comes back instantly.
|
|
172
|
+
// Off screen but open: crowded out at the left edge (`hidden`) or parked
|
|
173
|
+
// past the right one (`parked`). Both keep their DOM — and so their scroll
|
|
174
|
+
// position and half-typed forms — hence `visibility`, not `display:none`.
|
|
175
|
+
// Transitioning it counts as *visible* for the whole fade, flipping at the
|
|
176
|
+
// very end; the rule above (`visibility 0s`) reveals it again instantly.
|
|
225
177
|
"&.s-panel-hidden, &.s-panel-parked": "opacity:0 visibility:hidden " +
|
|
226
178
|
"transition: left var(--s-panel-ms) ease, transform var(--s-panel-ms) ease-out, opacity var(--s-panel-ms) linear, visibility var(--s-panel-ms);",
|
|
227
179
|
"&.s-panel-hidden": "transform: translateX(-8cqw);",
|
|
228
180
|
"&.s-panel-parked": "transform: translateX(8cqw);",
|
|
229
181
|
},
|
|
230
|
-
// The scroll container, with the column's own padding.
|
|
231
|
-
//
|
|
232
|
-
//
|
|
233
|
-
// has something better to line up with: the hairline the next column starts
|
|
234
|
-
// at, or the edge of the content area. Both want the bar hard against them,
|
|
235
|
-
// and an inset would leave a strip of nothing between the two.
|
|
182
|
+
// The scroll container, with the column's own padding. Its scrollbar sits
|
|
183
|
+
// flush against the column edge (unlike content mode's inset one), so it meets
|
|
184
|
+
// the next column's hairline with no strip of nothing between.
|
|
236
185
|
".s-panel > .s-content": "flex:1 min-height:0 overflow-y:auto overflow-x:hidden p:$3",
|
|
237
186
|
// A panel's actions on a wide shell: a quiet strip at the column's top-right,
|
|
238
187
|
// above the scroll area (never sticky inside it). On a narrow shell the top
|
|
239
188
|
// bar carries them instead, and no strip is drawn at all.
|
|
240
189
|
".s-panel-actions": "display:flex align-items:center justify-content:flex-end gap:$1 flex-shrink:0 padding: $3 $3 0;",
|
|
241
|
-
// The breadcrumb stack the top bar shows: every open panel, oldest first,
|
|
242
|
-
//
|
|
243
|
-
//
|
|
244
|
-
// whichever edge has more stack behind it, so the cut-off reads as "keep
|
|
245
|
-
// going" rather than as the stack simply ending.
|
|
246
|
-
// The stack is a `.s-strip` (see tabs.ts), so the scrolling, the hidden
|
|
247
|
-
// scrollbar and the ‹ / › come with it; all that is left to say is the gap
|
|
248
|
-
// between a crumb and its chevron.
|
|
190
|
+
// The breadcrumb stack the top bar shows: every open panel, oldest first, the
|
|
191
|
+
// ones on screen in bold ink (see `drawCrumbs`). It is a `.s-strip` (see
|
|
192
|
+
// tabs.ts), so scrolling and the ‹ / › come with it; only the gap is left.
|
|
249
193
|
".s-crumbs > .s-strip-row": "gap:$m1",
|
|
250
194
|
".s-crumb": {
|
|
251
|
-
// Quiet ink for the stack, full ink and weight for the panels on screen
|
|
252
|
-
//
|
|
253
|
-
//
|
|
254
|
-
//
|
|
255
|
-
//
|
|
256
|
-
//
|
|
257
|
-
// (`max-width:max-content`) — so with room to spare every title shows in
|
|
258
|
-
// full, and under pressure it is the *longest* crumbs that give way
|
|
259
|
-
// first, equalising downward while short ones keep every character. No
|
|
260
|
-
// crumb drops below min(its text, 4rem) though: `flex-shrink:0`, so past
|
|
261
|
-
// that point the row overflows and the strip scrolls — which is what
|
|
262
|
-
// keeps a deep stack on a phone readable. (Crumbs allowed to shrink
|
|
263
|
-
// would ellipsise to a row of stubs instead, and the stack would never
|
|
264
|
-
// scroll.)
|
|
195
|
+
// Quiet ink for the stack, full ink and weight for the panels on screen.
|
|
196
|
+
// No padding of its own: the first crumb must start on the same pixel as
|
|
197
|
+
// the app's name above it. The flex shares out a tight row — every crumb
|
|
198
|
+
// grows from a 4rem basis and freezes at its own text, so the longest give
|
|
199
|
+
// way first. `flex-shrink:0` is what stops them ellipsising into a row of
|
|
200
|
+
// stubs: past that point the row overflows and the strip scrolls instead.
|
|
265
201
|
"&": "flex: 1 0 4rem; font-size:0.85em line-height:1.5 fg:$s-muted text-decoration:none " +
|
|
266
202
|
"white-space:nowrap max-width:max-content overflow:hidden text-overflow:ellipsis " +
|
|
267
203
|
"transition: color 0.12s;",
|
|
@@ -269,23 +205,19 @@ A.insertGlobalCss({
|
|
|
269
205
|
// The same hover treatment as a menu item. The panel you are on is a plain
|
|
270
206
|
// span rather than a link, so it needs no `:not()` guard here.
|
|
271
207
|
"a&:hover": "filter:none color: color-mix(in lab, $s-primary 33%, $s-text);",
|
|
272
|
-
// The pin of a pinned panel,
|
|
273
|
-
//
|
|
274
|
-
// body path filled solid reads as the classic pinned-tab pushpin.
|
|
208
|
+
// The pin of a pinned panel, inline before its title. Filled, because at
|
|
209
|
+
// crumb size the icon's hairline strokes alias into a wobble.
|
|
275
210
|
"svg.s-crumb-pin": "vertical-align:-0.12em margin-right:0.3em opacity:0.8 fill:currentColor",
|
|
276
211
|
// The ● of a panel holding unsaved work — the editors' dirty mark, filled
|
|
277
212
|
// solid for the same reason as the pin.
|
|
278
213
|
"svg.s-crumb-unsaved": "vertical-align:0.08em margin-right:0.3em fill:currentColor",
|
|
279
214
|
},
|
|
280
|
-
// A slash, not a chevron: the stack is a path, and a
|
|
281
|
-
//
|
|
282
|
-
// strip grows when the stack overflows (see `scrollStrip` in tabs.ts) — two
|
|
283
|
-
// near-identical chevrons, one meaningful and one a button, read as a bug.
|
|
215
|
+
// A slash, not a chevron: the stack is a path, and a chevron would be
|
|
216
|
+
// confusable with the strip's own ‹ / › scroll buttons (see tabs.ts).
|
|
284
217
|
"svg.s-crumb-sep": "flex-shrink:0 opacity:0.4",
|
|
285
|
-
// A
|
|
286
|
-
//
|
|
287
|
-
//
|
|
288
|
-
// after a forced reflow. Beats the standing transitions on specificity.
|
|
218
|
+
// A resize (and the first pass) must track the window instantly rather than
|
|
219
|
+
// rubber-band behind it: the layout engine raises this class, applies the new
|
|
220
|
+
// geometry, and drops it after a forced reflow.
|
|
289
221
|
".s-main.s-shell-snap .s-panel": "transition:none",
|
|
290
222
|
// A minimal "still fetching" hint, centred over the panel's content (which
|
|
291
223
|
// stays mounted underneath, so it can fill in reactively).
|
|
@@ -301,9 +233,8 @@ A.insertGlobalCss({
|
|
|
301
233
|
},
|
|
302
234
|
});
|
|
303
235
|
/**
|
|
304
|
-
* The URL is global, so two routed shells would fight over it
|
|
305
|
-
*
|
|
306
|
-
* back, never through a module-level singleton.
|
|
236
|
+
* The URL is global, so two routed shells would fight over it; this only guards
|
|
237
|
+
* against that. The stack itself is reached through `main()`'s return value.
|
|
307
238
|
*/
|
|
308
239
|
let mounted = false;
|
|
309
240
|
/**
|
|
@@ -314,10 +245,9 @@ let mounted = false;
|
|
|
314
245
|
*/
|
|
315
246
|
export class PanelStackController {
|
|
316
247
|
/**
|
|
317
|
-
* Kept out of Aberdeen's proxy wrapping:
|
|
318
|
-
*
|
|
319
|
-
*
|
|
320
|
-
* from `$state` and the panels, which are proxies in their own right.
|
|
248
|
+
* Kept out of Aberdeen's proxy wrapping: a class instance holding DOM nodes,
|
|
249
|
+
* timers and route handlers, riding inside every {@link Panel.stack}. Its
|
|
250
|
+
* reactivity comes from `$state` and the panels, which are proxies already.
|
|
321
251
|
*/
|
|
322
252
|
[OPAQUE] = true;
|
|
323
253
|
compiled;
|
|
@@ -325,35 +255,24 @@ export class PanelStackController {
|
|
|
325
255
|
ancestors;
|
|
326
256
|
opts;
|
|
327
257
|
/**
|
|
328
|
-
* The live stack, oldest first (closing panels
|
|
329
|
-
*
|
|
330
|
-
*
|
|
331
|
-
*
|
|
332
|
-
* assigning a fresh `live` array. The entries themselves are opaque (see
|
|
333
|
-
* {@link PanelEntry}), so the array carries their comings, goings and
|
|
334
|
-
* order — nothing deeper; a panel's own facts stay separately reactive on
|
|
335
|
-
* its `$panel`, which is what lets a panel rename itself without the
|
|
336
|
-
* stack redrawing.
|
|
258
|
+
* The live stack, oldest first (closing panels have left it), and which panel
|
|
259
|
+
* is current — the one reactive fact about the stack's *shape*. Each commit
|
|
260
|
+
* publishes the next shape by assigning a fresh `live` array; the entries are
|
|
261
|
+
* opaque, so a panel renaming itself doesn't redraw the stack.
|
|
337
262
|
*
|
|
338
|
-
*
|
|
339
|
-
* commands peek**.
|
|
340
|
-
*
|
|
341
|
-
*
|
|
342
|
-
*
|
|
343
|
-
* very stack it is changing — and everything those commands call through
|
|
344
|
-
* to, `propose` and `commit` included, inherits the same guarantee and
|
|
345
|
-
* reads the stack plainly.
|
|
263
|
+
* The invariant that makes this safe to touch from anywhere: **queries
|
|
264
|
+
* subscribe, commands peek**. Every navigation entry point (`navigate`,
|
|
265
|
+
* `closePath`, `back`, …) wraps itself in `A.peek`, so an app calling one
|
|
266
|
+
* from a reactive scope can't subscribe that scope to the stack it is
|
|
267
|
+
* changing; `propose` and `commit` inherit that and read the stack plainly.
|
|
346
268
|
*/
|
|
347
269
|
$state = A.proxy({ live: [], focus: 0 });
|
|
348
270
|
/**
|
|
349
|
-
* The open panels again, keyed by path — the shape
|
|
350
|
-
* `drawColumns`' `onEach` mounts
|
|
351
|
-
*
|
|
352
|
-
*
|
|
353
|
-
*
|
|
354
|
-
* and a splice renumbers every index after it, redrawing them all.) A
|
|
355
|
-
* key's value is its entry, by reference, and is never reassigned, so a
|
|
356
|
-
* panel only ever redraws wholesale when its path closes.
|
|
271
|
+
* The open panels again, keyed by path — the shape the DOM consumes.
|
|
272
|
+
* `drawColumns`' `onEach` mounts by key, so splicing a panel out of the
|
|
273
|
+
* middle touches exactly one key and the retained columns keep their scroll
|
|
274
|
+
* positions and half-typed forms. (Iterating `live` would key by array index,
|
|
275
|
+
* which a splice renumbers, redrawing every panel after it.)
|
|
357
276
|
*/
|
|
358
277
|
$open = A.proxy({});
|
|
359
278
|
/** Feeds {@link PanelEntry.order}: one shared counter, so keys never tie. */
|
|
@@ -383,25 +302,20 @@ export class PanelStackController {
|
|
|
383
302
|
this.ancestors = Object.entries(opts.ancestors ?? {})
|
|
384
303
|
.filter((entry) => entry[1] != null)
|
|
385
304
|
.map(([key, fn]) => ({ ...compileKey(key), fn }));
|
|
386
|
-
// Commit the stack whenever the URL or its snapshot changes —
|
|
387
|
-
//
|
|
388
|
-
// guard of
|
|
389
|
-
//
|
|
390
|
-
// keeps unsaved panels a navigation would drop), so a guard the app
|
|
391
|
-
// itself registered with `route.setGuard` — an auth redirect, say — is
|
|
392
|
-
// left exactly where it is and keeps working untouched.
|
|
305
|
+
// Commit the stack whenever the URL or its snapshot changes — initial load,
|
|
306
|
+
// our own navigations, browser back/forward. The shell registers no route
|
|
307
|
+
// guard of its own (closes are refused in `closePath` or repaired in
|
|
308
|
+
// `propose`), so an app's `route.setGuard` keeps working untouched.
|
|
393
309
|
A(() => {
|
|
394
310
|
const target = this.computeTarget();
|
|
395
|
-
// Subscribed
|
|
396
|
-
//
|
|
397
|
-
// restore stale ones.
|
|
311
|
+
// Subscribed, not peeked: a search/hash change with the path staying put
|
|
312
|
+
// must refresh `lastSeen` too, or the next stash restores stale ones.
|
|
398
313
|
const search = { ...route.current.search };
|
|
399
314
|
const hash = route.current.hash;
|
|
400
315
|
A.peek(() => {
|
|
401
|
-
// Stash the query of the panel the URL just left
|
|
402
|
-
//
|
|
403
|
-
//
|
|
404
|
-
// own navigations, an app's `route.go()`, and browser back/forward.
|
|
316
|
+
// Stash the query of the panel the URL just left, for when a crumb
|
|
317
|
+
// brings it back (see PanelEntry.search). Here on the shared pipeline,
|
|
318
|
+
// so our navigations, `route.go()` and back/forward are all covered.
|
|
405
319
|
const prev = this.lastSeen;
|
|
406
320
|
if (prev && prev.path !== route.current.path) {
|
|
407
321
|
const entry = this.$state.live.find((e) => e.path === prev.path);
|
|
@@ -412,11 +326,10 @@ export class PanelStackController {
|
|
|
412
326
|
}
|
|
413
327
|
this.lastSeen = { path: route.current.path, search, hash };
|
|
414
328
|
this.propose(target);
|
|
415
|
-
// A history entry
|
|
416
|
-
//
|
|
417
|
-
//
|
|
418
|
-
//
|
|
419
|
-
// `panels`/`parked` keys present, not merely compatible).
|
|
329
|
+
// A history entry describing no arrangement (initial load, an app's own
|
|
330
|
+
// `route.go()`) is stamped with the one it just produced, so a reload
|
|
331
|
+
// restores the same columns and `route.back()` can recognize the entry
|
|
332
|
+
// — its matching wants the `panels`/`parked` keys actually present.
|
|
420
333
|
if (!Array.isArray(route.current.state.panels)) {
|
|
421
334
|
Object.assign(route.current.state, this.stateFor({ stack: this.paths(), focus: this.$state.focus }));
|
|
422
335
|
}
|
|
@@ -429,8 +342,7 @@ export class PanelStackController {
|
|
|
429
342
|
for (const t of this.timers)
|
|
430
343
|
clearTimeout(t);
|
|
431
344
|
this.timers.clear();
|
|
432
|
-
//
|
|
433
|
-
// waiting its turn is answered rather than left hanging.
|
|
345
|
+
// Answer whatever was waiting its turn, rather than leave it hanging.
|
|
434
346
|
this.queued?.settle(false);
|
|
435
347
|
this.queued = null;
|
|
436
348
|
mounted = false;
|
|
@@ -453,17 +365,12 @@ export class PanelStackController {
|
|
|
453
365
|
}
|
|
454
366
|
/**
|
|
455
367
|
* The stack for origin-less navigation: a cold deep link, a nav item, a
|
|
456
|
-
* `route.go()` — anything
|
|
457
|
-
*
|
|
458
|
-
*
|
|
459
|
-
*
|
|
460
|
-
*
|
|
461
|
-
*
|
|
462
|
-
* has no opinion — every prefix of the path is probed against the route table
|
|
463
|
-
* and the matching ones become the stack. Either way, a path with no route is
|
|
464
|
-
* skipped rather than opened as a "not found" column, so an app that doesn't
|
|
465
|
-
* want one screen stacked under another simply doesn't route it. The path
|
|
466
|
-
* itself always ends the derived stack, matched or not.
|
|
368
|
+
* `route.go()` — anything with no panel to build on and no snapshot to
|
|
369
|
+
* restore. {@link PanelStackOptions.ancestors} gets first say; failing that,
|
|
370
|
+
* every prefix of the path is probed against the route table. A path with no
|
|
371
|
+
* route is skipped rather than opened as a "not found" column, so not routing
|
|
372
|
+
* a screen keeps it from appearing under another. The path itself always ends
|
|
373
|
+
* the derived stack, matched or not.
|
|
467
374
|
*/
|
|
468
375
|
deriveStack(path) {
|
|
469
376
|
const top = normalizePath(path);
|
|
@@ -478,10 +385,9 @@ export class PanelStackController {
|
|
|
478
385
|
return stack;
|
|
479
386
|
}
|
|
480
387
|
/**
|
|
481
|
-
* Ask the `ancestors` table what belongs beneath `path`. The first
|
|
482
|
-
*
|
|
483
|
-
*
|
|
484
|
-
* path to the prefix derivation just as an unlisted one is.
|
|
388
|
+
* Ask the `ancestors` table what belongs beneath `path`. The first matching
|
|
389
|
+
* key answers, with its own matched params; `undefined` means "no opinion",
|
|
390
|
+
* leaving the path to the prefix derivation as an unlisted one would be.
|
|
485
391
|
*/
|
|
486
392
|
askAncestors(path) {
|
|
487
393
|
const segments = splitPath(path);
|
|
@@ -517,23 +423,20 @@ export class PanelStackController {
|
|
|
517
423
|
return this.$state.live.find((e) => e.path === path)?.$panel.unsaved === true;
|
|
518
424
|
}
|
|
519
425
|
/**
|
|
520
|
-
* The arrangement a route implies: its snapshot around its path, or —
|
|
521
|
-
*
|
|
522
|
-
* any pinned panels carried along beneath it.
|
|
426
|
+
* The arrangement a route implies: its snapshot around its path, or — without
|
|
427
|
+
* one — derived, the new panel current at the end with pinned panels beneath.
|
|
523
428
|
*
|
|
524
|
-
* The snapshot reads subscribe
|
|
525
|
-
*
|
|
526
|
-
*
|
|
527
|
-
* and subscribing to it would re-run the observer once per commit.
|
|
429
|
+
* The snapshot reads subscribe (they are the URL's). The derivation is peeked:
|
|
430
|
+
* it reads the live stack for its pins, which the route observer rewrites, so
|
|
431
|
+
* subscribing would re-run that observer once per commit.
|
|
528
432
|
*/
|
|
529
433
|
targetFor(path, state) {
|
|
530
434
|
const before = Array.isArray(state?.panels) ? state.panels.map(String) : null;
|
|
531
435
|
if (before) {
|
|
532
436
|
const after = Array.isArray(state.parked) ? state.parked.map(String) : [];
|
|
533
437
|
// A stack never holds the same path twice: rendering reconciles by path,
|
|
534
|
-
// so a duplicate
|
|
535
|
-
//
|
|
536
|
-
// hand-written ones — drop duplicates rather than wedge.
|
|
438
|
+
// so a duplicate leaves a permanently element-less entry that stalls the
|
|
439
|
+
// layout. `route.go` accepts hand-written states, so drop rather than wedge.
|
|
537
440
|
const cur = normalizePath(path);
|
|
538
441
|
const seen = new Set([cur]);
|
|
539
442
|
const uniq = (paths) => paths.map(normalizePath).filter((p) => !seen.has(p) && !!seen.add(p));
|
|
@@ -555,13 +458,11 @@ export class PanelStackController {
|
|
|
555
458
|
return this.$state.live.map((e) => e.path);
|
|
556
459
|
}
|
|
557
460
|
/**
|
|
558
|
-
* Adopt an arrangement proposed by the URL
|
|
559
|
-
*
|
|
560
|
-
*
|
|
561
|
-
*
|
|
562
|
-
*
|
|
563
|
-
* deliberately not written into history entries: the work they protect
|
|
564
|
-
* lives in the page's DOM, which a reload clears anyway.)
|
|
461
|
+
* Adopt an arrangement proposed by the URL, after repairing it: a panel holding
|
|
462
|
+
* unsaved work is never torn down by any navigation — including a back to an
|
|
463
|
+
* entry from before it existed — so whatever the target drops, it stays, parked
|
|
464
|
+
* after the current panel. Parked panels are deliberately kept out of history
|
|
465
|
+
* entries: the work they protect lives in DOM a reload clears anyway.
|
|
565
466
|
*/
|
|
566
467
|
propose(target) {
|
|
567
468
|
const kept = this.$state.live
|
|
@@ -577,20 +478,17 @@ export class PanelStackController {
|
|
|
577
478
|
* Apply a target arrangement: unmount what's gone, mount what's new, animate
|
|
578
479
|
* the difference.
|
|
579
480
|
*
|
|
580
|
-
* Reconciliation is BY PATH
|
|
581
|
-
*
|
|
582
|
-
*
|
|
583
|
-
*
|
|
584
|
-
* remount every one of them, throwing away exactly the scroll and form state
|
|
585
|
-
* rule 5 promises to keep.
|
|
481
|
+
* Reconciliation is BY PATH, not by index: a panel in both stacks stays mounted
|
|
482
|
+
* even if its index shifted, which is what lets one be spliced out of the middle
|
|
483
|
+
* without disturbing the columns above it. A common-prefix diff would remount
|
|
484
|
+
* them all, throwing away their scroll and form state.
|
|
586
485
|
*/
|
|
587
486
|
commit(target, nav) {
|
|
588
|
-
//
|
|
589
|
-
//
|
|
487
|
+
// Panels size themselves as they draw, so make them measure the shell as it
|
|
488
|
+
// is now rather than trust the last pass's numbers.
|
|
590
489
|
this.geom = undefined;
|
|
591
|
-
// Pin flags for panels this commit *creates*
|
|
592
|
-
//
|
|
593
|
-
// the panel, not part of where back/forward travel.
|
|
490
|
+
// Pin flags for panels this commit *creates* (a reload or cold restore).
|
|
491
|
+
// Live panels keep their own: a pin is the user's mark, not history state.
|
|
594
492
|
const pinned = route.current.state.pinned;
|
|
595
493
|
const seedPins = new Set(Array.isArray(pinned) ? pinned.map(String) : []);
|
|
596
494
|
const existing = new Map(this.$state.live.map((entry) => [entry.path, entry]));
|
|
@@ -598,23 +496,19 @@ export class PanelStackController {
|
|
|
598
496
|
for (const path of target.stack) {
|
|
599
497
|
const kept = existing.get(path);
|
|
600
498
|
if (kept) {
|
|
601
|
-
// Retained
|
|
602
|
-
// DOM sort key) deliberately stays put — see PanelEntry.order.
|
|
499
|
+
// Retained; its `order` deliberately stays put — see PanelEntry.order.
|
|
603
500
|
existing.delete(path);
|
|
604
501
|
next.push(kept);
|
|
605
502
|
continue;
|
|
606
503
|
}
|
|
607
504
|
const entry = this.createEntry(path, next.length <= target.focus, seedPins.has(path));
|
|
608
|
-
// An initial load just appears, and so do panels *revealed* by a back
|
|
609
|
-
// they belong underneath the ones sliding away.
|
|
610
|
-
// the right edge, a replacement exactly like a push.
|
|
505
|
+
// An initial load just appears, and so do panels *revealed* by a back:
|
|
506
|
+
// they belong underneath the ones sliding away.
|
|
611
507
|
if (nav !== "load" && nav !== "back")
|
|
612
508
|
entry.enter = true;
|
|
613
509
|
next.push(entry);
|
|
614
510
|
this.$open[path] = entry;
|
|
615
511
|
}
|
|
616
|
-
// Whatever the target no longer holds leaves the same way: fading out over
|
|
617
|
-
// the right edge, which is also where its replacement (if any) comes in from.
|
|
618
512
|
for (const entry of existing.values())
|
|
619
513
|
this.beginClose(entry);
|
|
620
514
|
this.$state.live = next;
|
|
@@ -632,17 +526,11 @@ export class PanelStackController {
|
|
|
632
526
|
maxWidth: "medium",
|
|
633
527
|
width: 0,
|
|
634
528
|
};
|
|
635
|
-
// `close`
|
|
636
|
-
//
|
|
637
|
-
//
|
|
638
|
-
//
|
|
639
|
-
//
|
|
640
|
-
// like a link from nowhere.
|
|
641
|
-
//
|
|
642
|
-
// `visible` starts at what the panel's place implies: shown when it sits
|
|
643
|
-
// at or before the current panel (a pushed panel always does), hidden when
|
|
644
|
-
// it is restored already parked. `width` is filled in by the sizing scope
|
|
645
|
-
// in `drawPanel` before the handler draws.
|
|
529
|
+
// `close` and `open` resolve this panel's place in the stack at call time,
|
|
530
|
+
// so they keep working after a splice has moved it; an `open` from a panel
|
|
531
|
+
// that has since closed falls back to a derived stack, like a link from
|
|
532
|
+
// nowhere. `width` is filled in by `drawPanel`'s sizing scope before the
|
|
533
|
+
// handler draws.
|
|
646
534
|
entry.$panel = A.proxy({
|
|
647
535
|
stack: this,
|
|
648
536
|
params,
|
|
@@ -656,40 +544,31 @@ export class PanelStackController {
|
|
|
656
544
|
return entry;
|
|
657
545
|
}
|
|
658
546
|
/**
|
|
659
|
-
* Take a panel out of the shell. The *scope* goes now
|
|
660
|
-
* tick, so
|
|
661
|
-
*
|
|
662
|
-
*
|
|
663
|
-
* is what the `destroy=` hook in `drawPanel` is for: Aberdeen hands the
|
|
664
|
-
* element to {@link playExit} instead of removing it.
|
|
547
|
+
* Take a panel out of the shell. The *scope* goes now — its `A.clean` hooks run
|
|
548
|
+
* this tick, so subscriptions, timers and portals stop at the close rather than
|
|
549
|
+
* at the end of the animation. Only the element lingers to play that animation,
|
|
550
|
+
* which is what `drawPanel`'s `destroy=` hook hands to {@link playExit}.
|
|
665
551
|
*/
|
|
666
552
|
beginClose(entry) {
|
|
667
553
|
entry.closing = true;
|
|
668
|
-
// It is on its way out, so it is no longer "on screen" as far as anything
|
|
669
|
-
// hanging off `$panel.visible` is concerned — even though its element lingers
|
|
670
|
-
// to play the fade.
|
|
671
554
|
entry.$panel.visible = false;
|
|
672
|
-
// Frozen one layer below where it was,
|
|
673
|
-
//
|
|
674
|
-
//
|
|
675
|
-
// still ours — a moment later the scope, and with it `entry.el`, is gone.
|
|
555
|
+
// Frozen one layer below where it was, so it fades out over the panel it
|
|
556
|
+
// uncovers and under the one replacing it (see LAYER_STEP). Set here, while
|
|
557
|
+
// the element is still ours — a moment later `entry.el` is gone.
|
|
676
558
|
if (entry.el)
|
|
677
559
|
entry.el.style.zIndex = String(LAYER_STEP * this.$state.live.indexOf(entry));
|
|
678
560
|
delete this.$open[entry.path];
|
|
679
561
|
}
|
|
680
562
|
/**
|
|
681
|
-
* A closed panel's send-off, run by Aberdeen once
|
|
682
|
-
*
|
|
683
|
-
*
|
|
684
|
-
*
|
|
685
|
-
*
|
|
686
|
-
* then vanish. The timeout is just a fallback for when no `transitionend` is
|
|
687
|
-
* coming at all (transitions off, or an element that never got placed).
|
|
563
|
+
* A closed panel's send-off, run by Aberdeen once its scope is gone: it fades
|
|
564
|
+
* where it stands, inert, and leaves the DOM on `transitionend`. A fixed timer
|
|
565
|
+
* would race the transition and pull the element a frame early, making the
|
|
566
|
+
* panel appear to fade half-way and vanish; the timeout is only a fallback for
|
|
567
|
+
* when no `transitionend` is coming (transitions off, element never placed).
|
|
688
568
|
*/
|
|
689
569
|
playExit(entry, el) {
|
|
690
|
-
//
|
|
691
|
-
//
|
|
692
|
-
// one simply goes, so the new one isn't drawn over a ghost of the old.
|
|
570
|
+
// A panel being *redrawn* replaces its element through here too; that one
|
|
571
|
+
// simply goes, so the new one isn't drawn over a ghost of the old.
|
|
693
572
|
if (!entry.closing) {
|
|
694
573
|
el.remove();
|
|
695
574
|
return;
|
|
@@ -711,13 +590,10 @@ export class PanelStackController {
|
|
|
711
590
|
// ── Navigation ─────────────────────────────────────────────────────────
|
|
712
591
|
/**
|
|
713
592
|
* The arrangement navigation works from: the one we're on the way to while a
|
|
714
|
-
* change is still settling,
|
|
715
|
-
*
|
|
716
|
-
*
|
|
717
|
-
*
|
|
718
|
-
* app-registered route guard may be async. Working from the committed
|
|
719
|
-
* arrangement in that window would make a second Escape aim at the panel the
|
|
720
|
-
* first one is already taking away — so two quick Escapes would peel one panel.
|
|
593
|
+
* change is still settling, the one on screen otherwise. That window is common
|
|
594
|
+
* (every `route.back()` waits for a `popstate`), and working from the committed
|
|
595
|
+
* arrangement inside it would aim a second Escape at the panel the first is
|
|
596
|
+
* already taking away — two quick Escapes would peel one panel.
|
|
721
597
|
*/
|
|
722
598
|
intended() {
|
|
723
599
|
return this.intent ?? { stack: this.paths(), focus: this.$state.focus };
|
|
@@ -735,15 +611,10 @@ export class PanelStackController {
|
|
|
735
611
|
return this.$state.live.filter((e) => e.$panel.pinned).map((e) => e.path);
|
|
736
612
|
}
|
|
737
613
|
/**
|
|
738
|
-
* Put a navigation to the router, or — while one is still settling — behind
|
|
739
|
-
*
|
|
740
|
-
*
|
|
741
|
-
*
|
|
742
|
-
*
|
|
743
|
-
* A refusal empties the queue instead of running it: a navigation can still
|
|
744
|
-
* fail to land — an app-registered route guard vetoes it, or another one
|
|
745
|
-
* supersedes it — and what was queued behind it was worked out against the
|
|
746
|
-
* arrangement it would have produced.
|
|
614
|
+
* Put a navigation to the router, or — while one is still settling — behind the
|
|
615
|
+
* one that is. Only the newest waits; the one it displaces resolves `false`.
|
|
616
|
+
* A refusal empties the queue rather than running it, since what was queued
|
|
617
|
+
* was worked out against the arrangement the refused one would have produced.
|
|
747
618
|
*/
|
|
748
619
|
issue(target, run) {
|
|
749
620
|
this.intent = target;
|
|
@@ -758,10 +629,9 @@ export class PanelStackController {
|
|
|
758
629
|
this.settling = null;
|
|
759
630
|
const next = this.queued;
|
|
760
631
|
this.queued = null;
|
|
761
|
-
// The router
|
|
762
|
-
// commit has happened) before
|
|
763
|
-
//
|
|
764
|
-
// the stack as it stands now, not the one it was queued against.
|
|
632
|
+
// The router has already applied the change (and flushed Aberdeen's queue,
|
|
633
|
+
// so our commit has happened) before settling us, so the next one can go
|
|
634
|
+
// straight out against the stack as it now stands.
|
|
765
635
|
if (ok && next)
|
|
766
636
|
this.start(next.run).then(next.settle, () => next.settle(false));
|
|
767
637
|
else {
|
|
@@ -776,12 +646,8 @@ export class PanelStackController {
|
|
|
776
646
|
}
|
|
777
647
|
/**
|
|
778
648
|
* Make the stack's `index`th panel current without closing anything, leaving
|
|
779
|
-
* the panels right of it parked out of sight
|
|
780
|
-
*
|
|
781
|
-
* Only ever a step around a panel that refuses to close — nothing else is
|
|
782
|
-
* left sitting after the current one — so this is Escape's way past an
|
|
783
|
-
* unsaved panel, and the way back to one. It is a history entry, so the
|
|
784
|
-
* browser's back button returns the focus to where it was.
|
|
649
|
+
* the panels right of it parked out of sight — Escape's way past an unsaved
|
|
650
|
+
* panel, and back to one. A history entry, so back returns the focus.
|
|
785
651
|
*/
|
|
786
652
|
focusAt(index) {
|
|
787
653
|
const arr = this.intended();
|
|
@@ -796,12 +662,10 @@ export class PanelStackController {
|
|
|
796
662
|
});
|
|
797
663
|
}
|
|
798
664
|
/**
|
|
799
|
-
* One step back along the stack — what Escape does (`main()` calls this;
|
|
800
|
-
*
|
|
801
|
-
*
|
|
802
|
-
*
|
|
803
|
-
* simply moves to the panel on its left.
|
|
804
|
-
* Resolves `false` at the stack's start, where there is no left to go.
|
|
665
|
+
* One step back along the stack — what Escape does (`main()` calls this; it is
|
|
666
|
+
* not {@link PanelStack} API). Normally that closes the current panel; when it
|
|
667
|
+
* holds {@link Panel.unsaved} work, or panels sit parked beyond it, the focus
|
|
668
|
+
* moves left instead. Resolves `false` at the stack's start.
|
|
805
669
|
*/
|
|
806
670
|
back() {
|
|
807
671
|
return A.peek(() => {
|
|
@@ -817,21 +681,15 @@ export class PanelStackController {
|
|
|
817
681
|
/**
|
|
818
682
|
* Close whichever panel is open at `path`, current or not — what
|
|
819
683
|
* {@link Panel.close}, {@link PanelStack.closePanel} and the crumb menu's
|
|
820
|
-
* Close come down to. `false` when that path isn't open, is the stack's
|
|
821
|
-
* only panel, or holds {@link Panel.unsaved} work
|
|
822
|
-
* unsaved panel; the app clears the flag first, which is its explicit
|
|
823
|
-
* "this is now discardable".
|
|
684
|
+
* Close all come down to. `false` when that path isn't open, is the stack's
|
|
685
|
+
* only panel, or holds {@link Panel.unsaved} work.
|
|
824
686
|
*
|
|
825
|
-
* Closing the current panel at the stack's
|
|
826
|
-
*
|
|
827
|
-
*
|
|
828
|
-
*
|
|
829
|
-
*
|
|
830
|
-
*
|
|
831
|
-
* history entry, so the browser's back button restores the closed column
|
|
832
|
-
* like any other arrangement — which is why it goes through `route.go` here
|
|
833
|
-
* rather than through `navigate()`, whose "link to an open panel" check
|
|
834
|
-
* would turn it into a focus move.
|
|
687
|
+
* Closing the current panel at the stack's end pops back through history to
|
|
688
|
+
* the entry beneath it (restoring its scroll and search state); the
|
|
689
|
+
* arrangement is part of the match, so an entry where the closing panel was
|
|
690
|
+
* merely parked won't do. Every other close is a *splice*, which still earns
|
|
691
|
+
* its own history entry — hence `route.go` here rather than `navigate()`,
|
|
692
|
+
* whose "link to an open panel" check would turn it into a focus move.
|
|
835
693
|
*/
|
|
836
694
|
closePath(path) {
|
|
837
695
|
return A.peek(() => {
|
|
@@ -840,18 +698,15 @@ export class PanelStackController {
|
|
|
840
698
|
if (index < 0 || arr.stack.length < 2 || this.unsavedAt(arr.stack[index]))
|
|
841
699
|
return Promise.resolve(false);
|
|
842
700
|
const stack = arr.stack.filter((_, i) => i !== index);
|
|
843
|
-
// Closing the current panel hands the focus to the panel on its left
|
|
844
|
-
//
|
|
845
|
-
// any other panel moves the focus not at all.
|
|
701
|
+
// Closing the current panel hands the focus to the panel on its left;
|
|
702
|
+
// closing any other panel moves the focus not at all.
|
|
846
703
|
const focus = index === arr.focus ? Math.max(0, index - 1) : arr.focus - (index < arr.focus ? 1 : 0);
|
|
847
704
|
const target = { stack, focus };
|
|
848
705
|
if (index === arr.focus && index === arr.stack.length - 1) {
|
|
849
|
-
//
|
|
850
|
-
//
|
|
851
|
-
//
|
|
852
|
-
//
|
|
853
|
-
// the match target's — so they are re-stamped onto whatever entry we
|
|
854
|
-
// land on, the way `togglePin` writes them.
|
|
706
|
+
// With no matching history entry the current one is replaced instead,
|
|
707
|
+
// and the panel beneath gets its stashed query back via the fallback.
|
|
708
|
+
// Pins can't ride along there (the match target's `state` would shadow
|
|
709
|
+
// it), so they are re-stamped onto whatever entry we land on.
|
|
855
710
|
const beneath = this.$state.live.find((e) => e.path === stack[focus]);
|
|
856
711
|
const fallback = {};
|
|
857
712
|
if (beneath?.search)
|
|
@@ -868,9 +723,8 @@ export class PanelStackController {
|
|
|
868
723
|
const current = stack[focus];
|
|
869
724
|
const moved = current !== arr.stack[arr.focus];
|
|
870
725
|
return this.issue(target, () => {
|
|
871
|
-
// The current panel keeps its search
|
|
872
|
-
//
|
|
873
|
-
// close *did* move the focus, the newly current panel gets its own back.
|
|
726
|
+
// The current panel keeps its search and hash — `go()` would otherwise
|
|
727
|
+
// default them away. If the focus moved, the new panel gets its own back.
|
|
874
728
|
const entry = moved ? this.$state.live.find((e) => e.path === current) : undefined;
|
|
875
729
|
return route.go({
|
|
876
730
|
path: current,
|
|
@@ -883,28 +737,19 @@ export class PanelStackController {
|
|
|
883
737
|
}
|
|
884
738
|
/**
|
|
885
739
|
* Navigate to `href` — the one implementation behind a link click,
|
|
886
|
-
* {@link Panel.open} and the stack's own methods, so none
|
|
887
|
-
* behave differently.
|
|
740
|
+
* {@link Panel.open} and the stack's own methods, so none can drift.
|
|
888
741
|
*
|
|
889
|
-
* `from` is the
|
|
890
|
-
*
|
|
891
|
-
* that means the whole stack, which is then built instead (see
|
|
892
|
-
* {@link deriveStack}), or taken outright from `beneath`, for callers
|
|
893
|
-
* that know it.
|
|
742
|
+
* `from` is the panel the navigation starts from, absent when it has none (a
|
|
743
|
+
* nav item), in which case the stack is derived or taken from `beneath`.
|
|
894
744
|
*
|
|
895
|
-
* `how` is the link's `data-panel` attribute
|
|
896
|
-
*
|
|
897
|
-
*
|
|
898
|
-
*
|
|
899
|
-
*
|
|
900
|
-
*
|
|
901
|
-
* default, like a link without the attribute. A target that is already
|
|
902
|
-
* open is returned to by a push, and *moved* — alive, state intact — by
|
|
903
|
-
* the other two: the stack never holds a path twice.
|
|
745
|
+
* `how` is the link's `data-panel` attribute, picking how much of `from`'s
|
|
746
|
+
* context the target keeps: a push (the default, and the fallback for
|
|
747
|
+
* unrecognised values) builds on `from`, `"replace"` keeps only what is
|
|
748
|
+
* beneath it, `"open"` keeps nothing. A target that is already open is
|
|
749
|
+
* returned to by a push and *moved* — alive — by the other two, since the
|
|
750
|
+
* stack never holds a path twice.
|
|
904
751
|
*
|
|
905
|
-
* Resolves
|
|
906
|
-
* navigation lands, `false` when it doesn't (already there counts as
|
|
907
|
-
* landed).
|
|
752
|
+
* Resolves `true` once the navigation lands (already being there counts).
|
|
908
753
|
*/
|
|
909
754
|
navigate(href, { from, how, beneath } = {}) {
|
|
910
755
|
const mode = how ?? this.opts.linkNavigation;
|
|
@@ -920,54 +765,43 @@ export class PanelStackController {
|
|
|
920
765
|
}
|
|
921
766
|
const path = normalizePath(url.pathname);
|
|
922
767
|
const arr = this.intended();
|
|
923
|
-
//
|
|
924
|
-
// is what it lands on.
|
|
768
|
+
// The target always ends up on top; only what it lands on differs.
|
|
925
769
|
const open = beneath ? -1 : arr.stack.indexOf(path);
|
|
926
770
|
let target;
|
|
927
771
|
if (open >= 0 && mode !== "replace" && mode !== "open") {
|
|
928
|
-
// A push to
|
|
929
|
-
//
|
|
930
|
-
//
|
|
931
|
-
// copy to open — and a breadcrumb is exactly such a link.) Pinned
|
|
932
|
-
// panels above it are the exception, as ever: they stay in their
|
|
933
|
-
// order, parked past the panel we return to, one crumb click away.
|
|
772
|
+
// A push to an open path is a return: the panel takes back its place
|
|
773
|
+
// and whatever was stacked on top closes (a breadcrumb is such a
|
|
774
|
+
// link). Pinned panels above it park instead, keeping their order.
|
|
934
775
|
const above = this.pinnedIn(arr.stack.slice(open + 1), []);
|
|
935
776
|
target = { stack: [...arr.stack.slice(0, open + 1), ...above], focus: open };
|
|
936
777
|
}
|
|
937
778
|
else {
|
|
938
|
-
// The target opens on top of the
|
|
939
|
-
//
|
|
940
|
-
//
|
|
941
|
-
//
|
|
942
|
-
// makes a nav click and a deep link to the same URL land identically
|
|
943
|
-
// (bar the pins, which a fresh tab doesn't have).
|
|
779
|
+
// The target opens on top of the link's own panel — in its place for a
|
|
780
|
+
// `replace` — closing the panels after it. With no originating panel
|
|
781
|
+
// the base is the caller's `beneath` or derived from the path, which
|
|
782
|
+
// is what makes a nav click and a cold deep link land identically.
|
|
944
783
|
const originIndex = origin == null ? -1 : arr.stack.indexOf(origin);
|
|
945
784
|
const raw = beneath
|
|
946
785
|
? beneath.map(normalizePath)
|
|
947
786
|
: originIndex < 0
|
|
948
787
|
? this.deriveStack(path).slice(0, -1)
|
|
949
788
|
: arr.stack.slice(0, replace ? originIndex : originIndex + 1);
|
|
950
|
-
// A stack never holds the same path twice
|
|
951
|
-
//
|
|
952
|
-
//
|
|
953
|
-
// then simply *moves* to the top, alive — and a caller-supplied
|
|
954
|
-
// `beneath` is deduplicated for the same reason.
|
|
789
|
+
// A stack never holds the same path twice, so the target is dropped
|
|
790
|
+
// from the base (a `replace`/`open` aimed mid-stack moves that panel
|
|
791
|
+
// to the top, alive) and `beneath` is deduplicated for the same reason.
|
|
955
792
|
const base = raw.filter((p, i, all) => p !== path && all.indexOf(p) === i);
|
|
956
|
-
// Pinned panels ride along
|
|
957
|
-
// (unsaved ones
|
|
958
|
-
//
|
|
959
|
-
// doing, not somewhere else navigating over it.
|
|
793
|
+
// Pinned panels ride along beneath the new one, keeping their order
|
|
794
|
+
// (unsaved ones `propose` parks). A replaced origin closes pin or no
|
|
795
|
+
// pin: replacing is the panel's own doing, not navigation over it.
|
|
960
796
|
const under = [...base, ...this.pinnedIn(arr.stack, [...base, path, replace ? origin : null])];
|
|
961
797
|
target = { stack: [...under, path], focus: under.length };
|
|
962
798
|
}
|
|
963
|
-
//
|
|
964
|
-
//
|
|
965
|
-
// its own, which win.
|
|
799
|
+
// A panel we return to gets its own search and hash back (see
|
|
800
|
+
// PanelEntry.search), unless the link carries its own, which win.
|
|
966
801
|
const returning = open >= 0 ? this.$state.live.find((e) => e.path === path) : undefined;
|
|
967
802
|
const search = url.search ? Object.fromEntries(new URLSearchParams(url.search)) : returning?.search ?? {};
|
|
968
803
|
const hash = url.hash || returning?.hash || "";
|
|
969
|
-
// Going nowhere at all
|
|
970
|
-
// the link asks for. Not even a history entry.
|
|
804
|
+
// Going nowhere at all — not even a history entry.
|
|
971
805
|
if (target.focus === arr.focus && sameStack(target.stack, arr.stack)
|
|
972
806
|
&& url.search === location.search && (url.hash || "") === (location.hash || "")) {
|
|
973
807
|
return Promise.resolve(true);
|
|
@@ -984,24 +818,27 @@ export class PanelStackController {
|
|
|
984
818
|
}
|
|
985
819
|
// ── Link interception ──────────────────────────────────────────────────
|
|
986
820
|
/**
|
|
987
|
-
* Link handling through `route.interceptLinks()`, whose
|
|
988
|
-
*
|
|
989
|
-
*
|
|
990
|
-
* close guards run in `checkChange` when our navigation reaches the router.
|
|
821
|
+
* Link handling through `route.interceptLinks()`, whose hook hands us the
|
|
822
|
+
* anchor so we can decide what the click means. The exclusion rules (targets,
|
|
823
|
+
* downloads, modified clicks, external URLs) live in Aberdeen.
|
|
991
824
|
*
|
|
992
|
-
* A link inside a panel is that panel's {@link Panel.open},
|
|
993
|
-
*
|
|
994
|
-
*
|
|
995
|
-
* panel to build on, so it replaces the stack as a whole, exactly as a cold
|
|
996
|
-
* link to the same URL would open it.
|
|
825
|
+
* A link inside a panel is that panel's {@link Panel.open}, with `data-panel`
|
|
826
|
+
* as its `how`. A link outside every panel — a nav item, one in a dialog —
|
|
827
|
+
* has nothing to build on, so it replaces the stack as a cold link would.
|
|
997
828
|
*/
|
|
998
829
|
interceptLinks() {
|
|
999
|
-
route.interceptLinks((url, anchor) => {
|
|
830
|
+
route.interceptLinks((url, anchor, e) => {
|
|
831
|
+
// A modified keystroke is not a plain activation. Aberdeen leaves a
|
|
832
|
+
// ctrl/⌘/shift/alt *click* to the browser but not the Enter that stands
|
|
833
|
+
// in for it, so routing this one would turn the keyboard's own
|
|
834
|
+
// open-in-a-new-tab into an ordinary navigation. Declining leaves the
|
|
835
|
+
// event untouched, for the browser to open where the click would have.
|
|
836
|
+
if (e instanceof KeyboardEvent && (e.ctrlKey || e.metaKey || e.shiftKey || e.altKey))
|
|
837
|
+
return false;
|
|
1000
838
|
const how = anchor.getAttribute("data-panel") ?? undefined;
|
|
1001
|
-
// The panel the link lives in: the enclosing `.s-panel`, or
|
|
1002
|
-
//
|
|
1003
|
-
// (see main.ts), outside every `.s-panel
|
|
1004
|
-
// own chrome they remain at every width.
|
|
839
|
+
// The panel the link lives in: the enclosing `.s-panel`, or the current
|
|
840
|
+
// panel for its actions once a narrow shell has promoted them into the
|
|
841
|
+
// top bar (see main.ts), outside every `.s-panel`.
|
|
1005
842
|
const panelEl = anchor.closest(".s-panel");
|
|
1006
843
|
const entry = panelEl
|
|
1007
844
|
? this.$state.live.find((e) => e.el === panelEl)
|
|
@@ -1013,9 +850,8 @@ export class PanelStackController {
|
|
|
1013
850
|
});
|
|
1014
851
|
}
|
|
1015
852
|
// ── What the shell's top bar asks ──────────────────────────────────────
|
|
1016
|
-
// The {@link PanelStack} face, where
|
|
1017
|
-
//
|
|
1018
|
-
// read one in a scope and that scope follows the stack's shape.
|
|
853
|
+
// The {@link PanelStack} face, where the documentation lives. These are the
|
|
854
|
+
// *queries* of the "queries subscribe, commands peek" rule on `$state`.
|
|
1019
855
|
get currentPanel() {
|
|
1020
856
|
return this.$state.live[this.$state.focus]?.$panel;
|
|
1021
857
|
}
|
|
@@ -1041,13 +877,11 @@ export class PanelStackController {
|
|
|
1041
877
|
});
|
|
1042
878
|
}
|
|
1043
879
|
// ── Live settings ──────────────────────────────────────────────────────
|
|
1044
|
-
// `main()`
|
|
1045
|
-
//
|
|
1046
|
-
//
|
|
1047
|
-
//
|
|
1048
|
-
//
|
|
1049
|
-
// need no counterpart here: `navWidth` and `maxWidth` both resize the
|
|
1050
|
-
// column region, which the layout engine is already observing.
|
|
880
|
+
// `main()` feeds these from small reactive scopes, so an app changing them at
|
|
881
|
+
// runtime is adopted in place — nothing redrawn, no panel losing its state.
|
|
882
|
+
// Not {@link PanelStack} API: this is how `main()` talks to the stack.
|
|
883
|
+
// `navWidth`/`maxWidth` need no counterpart; they resize the column region,
|
|
884
|
+
// which the layout engine already observes.
|
|
1051
885
|
/** Adopt a changed `columns` setting: one layout pass, nothing redrawn. */
|
|
1052
886
|
setColumns(columns) {
|
|
1053
887
|
if (this.opts.columns === columns)
|
|
@@ -1060,19 +894,14 @@ export class PanelStackController {
|
|
|
1060
894
|
this.opts.linkNavigation = mode;
|
|
1061
895
|
}
|
|
1062
896
|
/**
|
|
1063
|
-
* The breadcrumb stack, drawn by `main()` into the top bar: every open
|
|
1064
|
-
*
|
|
1065
|
-
*
|
|
1066
|
-
*
|
|
1067
|
-
* so clicking a crumb goes back to that panel and closes what was stacked on
|
|
1068
|
-
* top of it, pinned and unsaved panels excepted. Right-click (or long-press)
|
|
1069
|
-
* offers pinning, and closing just that one panel — the close that splices
|
|
1070
|
-
* it out of the middle when it isn't last.
|
|
897
|
+
* The breadcrumb stack, drawn by `main()` into the top bar: every open panel,
|
|
898
|
+
* oldest first, the ones on screen in bold. Every crumb but the current one is
|
|
899
|
+
* a plain link, and a link to an open panel returns to it (see `navigate`),
|
|
900
|
+
* closing what was stacked on top. Right-click offers pinning and closing.
|
|
1071
901
|
*/
|
|
1072
902
|
drawCrumbs() {
|
|
1073
|
-
// The
|
|
1074
|
-
//
|
|
1075
|
-
// crumbs to reach — which a mouse can use, unlike a bare scroll area.
|
|
903
|
+
// The same row `S.tabs` uses: it scrolls when the stack outgrows the bar,
|
|
904
|
+
// with a ‹ / › a mouse can use over whichever end has crumbs left to reach.
|
|
1076
905
|
scrollStrip({
|
|
1077
906
|
attrs: ".s-crumbs role=navigation aria-label=Breadcrumbs",
|
|
1078
907
|
content: () => {
|
|
@@ -1095,23 +924,19 @@ export class PanelStackController {
|
|
|
1095
924
|
});
|
|
1096
925
|
}
|
|
1097
926
|
drawCrumb(path, index, current) {
|
|
1098
|
-
// Safe to close over: the crumb list is rebuilt whenever the stack
|
|
1099
|
-
//
|
|
1100
|
-
// whole life.
|
|
927
|
+
// Safe to close over: the crumb list is rebuilt whenever the stack or its
|
|
928
|
+
// focus changes, so this stays `paths[index]`'s entry for the crumb's life.
|
|
1101
929
|
const entry = this.$state.live[index];
|
|
1102
|
-
// A real link,
|
|
1103
|
-
//
|
|
1104
|
-
//
|
|
1105
|
-
// should be (see `navigate`). The panel you are on is a span: nowhere to go.
|
|
930
|
+
// A real link, so it can be hovered, middle-clicked and copied. No click
|
|
931
|
+
// handling of its own: link interception already turns a link to an open
|
|
932
|
+
// panel into the focus move a crumb wants (see `navigate`).
|
|
1106
933
|
return A(current ? "span.s-crumb aria-current=page" : "a.s-crumb", () => {
|
|
1107
934
|
if (!current)
|
|
1108
935
|
A("href=", path);
|
|
1109
|
-
// Bold = on screen right now, so the stack
|
|
1110
|
-
//
|
|
936
|
+
// Bold = on screen right now, so the stack says which panels are the
|
|
937
|
+
// visible columns, not just which one is current.
|
|
1111
938
|
A(() => { if (entry?.$panel.visible)
|
|
1112
939
|
A(".s-crumb-on"); });
|
|
1113
|
-
// The ● of unsaved work — the mark that nothing can close this panel —
|
|
1114
|
-
// and the pin of a panel that navigation elsewhere won't close.
|
|
1115
940
|
A(() => { if (entry?.$panel.unsaved)
|
|
1116
941
|
dotIcon({ size: "0.45em", attrs: ".s-crumb-unsaved" }); });
|
|
1117
942
|
A(() => { if (entry?.$panel.pinned)
|
|
@@ -1130,10 +955,8 @@ export class PanelStackController {
|
|
|
1130
955
|
{
|
|
1131
956
|
label: "Close",
|
|
1132
957
|
icon: closeIcon,
|
|
1133
|
-
//
|
|
1134
|
-
//
|
|
1135
|
-
// crumb's own scope, so the flag flipping redraws the crumb —
|
|
1136
|
-
// the ● above and this menu entry stay one truth.
|
|
958
|
+
// Read here, in the crumb's own scope, so flipping the flag
|
|
959
|
+
// redraws the crumb and the ● above stays in step with this.
|
|
1137
960
|
disabled: entry?.$panel.unsaved === true,
|
|
1138
961
|
click: () => void this.closePath(path),
|
|
1139
962
|
},
|
|
@@ -1141,9 +964,8 @@ export class PanelStackController {
|
|
|
1141
964
|
});
|
|
1142
965
|
}
|
|
1143
966
|
/**
|
|
1144
|
-
* Flip a panel's pin (see {@link Panel.pinned}). The
|
|
1145
|
-
*
|
|
1146
|
-
* the pin — a same-panel state tweak, which the router applies unguarded.
|
|
967
|
+
* Flip a panel's pin (see {@link Panel.pinned}). The current history entry's
|
|
968
|
+
* snapshot is rewritten too, so a reload keeps the pin.
|
|
1147
969
|
*/
|
|
1148
970
|
togglePin(entry) {
|
|
1149
971
|
entry.$panel.pinned = !entry.$panel.pinned || undefined;
|
|
@@ -1151,10 +973,9 @@ export class PanelStackController {
|
|
|
1151
973
|
}
|
|
1152
974
|
// ── document.title ─────────────────────────────────────────────────────
|
|
1153
975
|
/**
|
|
1154
|
-
* `"<panel title> · <app title>"`, kept in sync with the current panel
|
|
1155
|
-
* prefixed `"• "` while *any* open panel holds unsaved work
|
|
1156
|
-
*
|
|
1157
|
-
* losing the work is tab-wide, so the mark on the tab is too.
|
|
976
|
+
* `"<panel title> · <app title>"`, kept in sync with the current panel, and
|
|
977
|
+
* prefixed `"• "` while *any* open panel holds unsaved work — not just the
|
|
978
|
+
* current one, since the risk of losing it is tab-wide.
|
|
1158
979
|
*/
|
|
1159
980
|
watchTitle() {
|
|
1160
981
|
const original = document.title;
|
|
@@ -1162,8 +983,6 @@ export class PanelStackController {
|
|
|
1162
983
|
const entry = this.$state.live[this.$state.focus];
|
|
1163
984
|
const panelTitle = entry?.$panel.title ?? entry?.$ui.fallback;
|
|
1164
985
|
const appTitle = typeof this.opts.title === "string" ? this.opts.title : undefined;
|
|
1165
|
-
// Reading the stack re-runs this when its shape changes; each panel's
|
|
1166
|
-
// own `unsaved` (up to the first dirty one) does the rest.
|
|
1167
986
|
const dirty = this.$state.live.some((e) => e.$panel.unsaved);
|
|
1168
987
|
const title = panelTitle && appTitle ? `${panelTitle} · ${appTitle}` : panelTitle || appTitle;
|
|
1169
988
|
if (title)
|
|
@@ -1172,10 +991,9 @@ export class PanelStackController {
|
|
|
1172
991
|
A.clean(() => { document.title = original; });
|
|
1173
992
|
}
|
|
1174
993
|
/**
|
|
1175
|
-
* While any open panel holds unsaved work, closing the tab
|
|
1176
|
-
*
|
|
1177
|
-
*
|
|
1178
|
-
* holding the tab is in front of the user rather than parked out of sight.
|
|
994
|
+
* While any open panel holds unsaved work, closing the tab runs into the
|
|
995
|
+
* browser's own are-you-sure, with that panel brought on screen as the
|
|
996
|
+
* question is raised rather than left parked out of sight.
|
|
1179
997
|
*/
|
|
1180
998
|
guardTabClose() {
|
|
1181
999
|
if (typeof window === "undefined")
|
|
@@ -1186,26 +1004,19 @@ export class PanelStackController {
|
|
|
1186
1004
|
return;
|
|
1187
1005
|
e.preventDefault();
|
|
1188
1006
|
e.returnValue = true; // Chrome/Edge < 119
|
|
1189
|
-
// Bring the unsaved panel on screen
|
|
1190
|
-
//
|
|
1191
|
-
// browser paints that early, and the moment they choose to stay
|
|
1192
|
-
// otherwise. A confirmed leave unloads the document before any of it
|
|
1193
|
-
// is seen; the history entry the move makes is then where a back
|
|
1194
|
-
// navigation returns to, which is right: the panel that held the tab.
|
|
1007
|
+
// Bring the unsaved panel on screen, so what is holding the tab is in
|
|
1008
|
+
// front of the user the moment they choose to stay.
|
|
1195
1009
|
// `visible` is written by the layout pass, which waits for an animation
|
|
1196
|
-
// frame
|
|
1197
|
-
//
|
|
1198
|
-
//
|
|
1199
|
-
// ago still reads as on screen and the guard skips the very move it
|
|
1200
|
-
// exists to make.
|
|
1010
|
+
// frame that a tab on its way out may never get. Settle it first, or a
|
|
1011
|
+
// panel parked a moment ago still reads as on screen and the guard skips
|
|
1012
|
+
// the very move it exists to make.
|
|
1201
1013
|
this.flushLayout();
|
|
1202
1014
|
if (!dirty.$panel.visible)
|
|
1203
1015
|
void this.focusAt(this.intended().stack.indexOf(dirty.path));
|
|
1204
1016
|
};
|
|
1205
1017
|
// Registered only while a panel actually holds unsaved work: a page with a
|
|
1206
|
-
// `beforeunload` listener is shut out of the
|
|
1207
|
-
//
|
|
1208
|
-
// guard that almost never has anything to guard.
|
|
1018
|
+
// `beforeunload` listener is shut out of the back/forward cache, a tax
|
|
1019
|
+
// every navigation in the app would otherwise pay.
|
|
1209
1020
|
A(() => {
|
|
1210
1021
|
if (!this.$state.live.some((entry) => entry.$panel.unsaved))
|
|
1211
1022
|
return;
|
|
@@ -1217,26 +1028,23 @@ export class PanelStackController {
|
|
|
1217
1028
|
/**
|
|
1218
1029
|
* Draw the column viewport into the current element. Called by `main()`.
|
|
1219
1030
|
*
|
|
1220
|
-
* A column is the panel's own content
|
|
1221
|
-
* places for it: its {@link Panel.actions}
|
|
1222
|
-
* the top bar on narrow ones (see {@link drawActions}).
|
|
1031
|
+
* A column is the panel's own content plus the one bit of chrome the shell
|
|
1032
|
+
* places for it: its {@link Panel.actions} (see {@link drawActions}).
|
|
1223
1033
|
*/
|
|
1224
1034
|
drawColumns() {
|
|
1225
1035
|
const container = A("div.s-panels role=main", () => {
|
|
1226
|
-
// Published
|
|
1227
|
-
//
|
|
1228
|
-
//
|
|
1229
|
-
// running. `A()` without arguments is "the element we're in".
|
|
1036
|
+
// Published here rather than from the return value below: a panel sizes
|
|
1037
|
+
// itself from the shell's measurements, and the first ones do that while
|
|
1038
|
+
// this call is still running.
|
|
1230
1039
|
this.containerEl = A();
|
|
1231
|
-
// Mounted
|
|
1232
|
-
//
|
|
1233
|
-
// needs — `layout()` places and stacks the columns itself.
|
|
1040
|
+
// Mounted by path (see `$open`); DOM order is creation order, which is
|
|
1041
|
+
// all that's needed — `layout()` places and stacks the columns itself.
|
|
1234
1042
|
A.onEach(this.$open, (entry) => this.drawPanel(entry), (entry) => entry.order);
|
|
1235
1043
|
});
|
|
1236
1044
|
if (typeof ResizeObserver !== "undefined") {
|
|
1237
|
-
// The region *is* the content area every width is measured from
|
|
1238
|
-
//
|
|
1239
|
-
//
|
|
1045
|
+
// The region *is* the content area every width is measured from, so
|
|
1046
|
+
// watching it catches a window resize, the sidebar coming or going, and
|
|
1047
|
+
// the shell's own `maxWidth` changing alike.
|
|
1240
1048
|
const ro = new ResizeObserver(() => this.layout());
|
|
1241
1049
|
ro.observe(container);
|
|
1242
1050
|
A.clean(() => ro.disconnect());
|
|
@@ -1247,14 +1055,10 @@ export class PanelStackController {
|
|
|
1247
1055
|
}
|
|
1248
1056
|
drawPanel(entry) {
|
|
1249
1057
|
let el;
|
|
1250
|
-
// How much room the panel wants, resolved *before* its content is drawn:
|
|
1251
|
-
// element that arrives
|
|
1252
|
-
//
|
|
1253
|
-
//
|
|
1254
|
-
// created at the width the window gives it — the "medium" width until the
|
|
1255
|
-
// panel says otherwise. Reactively, too: a panel that changes its mind later
|
|
1256
|
-
// (when its data arrives, say) reflows in place rather than being redrawn,
|
|
1257
|
-
// and the columns beside it slide over to make room.
|
|
1058
|
+
// How much room the panel wants, resolved *before* its content is drawn:
|
|
1059
|
+
// an element that arrives width-less has no box for its content to measure
|
|
1060
|
+
// against until the next frame — a frame too late. Reactive, so a panel
|
|
1061
|
+
// changing its mind later reflows in place rather than being redrawn.
|
|
1258
1062
|
A(() => {
|
|
1259
1063
|
const asked = entry.$panel.maxWidth;
|
|
1260
1064
|
entry.maxWidth = asked === "small" || asked === "large" || asked === "none" ? asked : "medium";
|
|
@@ -1266,35 +1070,30 @@ export class PanelStackController {
|
|
|
1266
1070
|
// to draw into without measuring it.
|
|
1267
1071
|
if (A.peek(entry.$panel, "width") !== width)
|
|
1268
1072
|
entry.$panel.width = width;
|
|
1269
|
-
// The first run has no element
|
|
1270
|
-
// width, just below. Later runs are the panel changing its mind.
|
|
1073
|
+
// The first run has no element yet — it's created with this width below.
|
|
1271
1074
|
if (!el)
|
|
1272
1075
|
return;
|
|
1273
1076
|
el.style.width = `${width}px`;
|
|
1274
1077
|
this.scheduleLayout();
|
|
1275
1078
|
});
|
|
1276
1079
|
el = A(`section.s-panel${entry.width ? ` w:${entry.width}px` : ""}`, "destroy=", (node) => this.playExit(entry, node), () => {
|
|
1277
|
-
//
|
|
1278
|
-
// the panel changes its actions, when the shell crosses the narrow
|
|
1279
|
-
// threshold — but the body below never may.
|
|
1080
|
+
// In its own scope: the chrome may redraw freely, the body below may not.
|
|
1280
1081
|
A(() => this.drawActions(entry));
|
|
1281
1082
|
A("div.s-content", () => {
|
|
1282
1083
|
entry.draw(entry.$panel);
|
|
1283
1084
|
// After the content, so there is something to scroll when restoring.
|
|
1284
1085
|
route.persistScroll(entry.path);
|
|
1285
|
-
// A panel that
|
|
1286
|
-
//
|
|
1287
|
-
//
|
|
1288
|
-
// ever goes blank. Peeked: a rename must not redraw the panel.
|
|
1086
|
+
// A panel that set no title borrows its first line of text (the DOM
|
|
1087
|
+
// is built already — Aberdeen draws synchronously) so the crumbs and
|
|
1088
|
+
// document.title never go blank. Peeked: a rename must not redraw.
|
|
1289
1089
|
if (A.peek(entry.$panel, "title") == null) {
|
|
1290
1090
|
const text = firstText(A());
|
|
1291
1091
|
if (text && A.peek(entry.$ui, "fallback") !== text)
|
|
1292
1092
|
entry.$ui.fallback = text;
|
|
1293
1093
|
}
|
|
1294
1094
|
});
|
|
1295
|
-
//
|
|
1296
|
-
//
|
|
1297
|
-
// are still parked off screen, waiting to slide in with real content.
|
|
1095
|
+
// Its own scope, so flipping the flag doesn't redraw the panel's content.
|
|
1096
|
+
// A held-back panel shows nothing: it is still off screen.
|
|
1298
1097
|
A(() => {
|
|
1299
1098
|
if (!entry.$panel.loading || entry.$ui.holding)
|
|
1300
1099
|
return;
|
|
@@ -1302,11 +1101,10 @@ export class PanelStackController {
|
|
|
1302
1101
|
});
|
|
1303
1102
|
});
|
|
1304
1103
|
entry.el = el;
|
|
1305
|
-
//
|
|
1306
|
-
//
|
|
1307
|
-
//
|
|
1308
|
-
//
|
|
1309
|
-
// element that has to be placed again before it may animate.
|
|
1104
|
+
// Nothing may animate from the arbitrary initial spot; `layout()` gives the
|
|
1105
|
+
// panel its place (and turns transitions back on) in the coming frame,
|
|
1106
|
+
// before anything is painted. A redraw lands here too, with a new element
|
|
1107
|
+
// that has to be placed again first.
|
|
1310
1108
|
entry.placed = false;
|
|
1311
1109
|
el.style.transition = "none";
|
|
1312
1110
|
A.clean(() => { if (entry.el === el)
|
|
@@ -1321,9 +1119,7 @@ export class PanelStackController {
|
|
|
1321
1119
|
/**
|
|
1322
1120
|
* The one bit of column chrome the shell draws: the panel's actions, in a
|
|
1323
1121
|
* quiet strip above the scroll area — and only while the shell is wide, the
|
|
1324
|
-
* top bar carrying them otherwise. Everything else
|
|
1325
|
-
* own content: a screen that wants a heading or a card draws them itself.
|
|
1326
|
-
* Going back isn't here either — that is the breadcrumbs' job, in the bar.
|
|
1122
|
+
* top bar carrying them otherwise. Everything else is the panel's own content.
|
|
1327
1123
|
*/
|
|
1328
1124
|
drawActions(entry) {
|
|
1329
1125
|
if (this.opts.$shell.narrow || entry.$panel.actions == null)
|
|
@@ -1338,10 +1134,9 @@ export class PanelStackController {
|
|
|
1338
1134
|
requestAnimationFrame(() => this.flushLayout());
|
|
1339
1135
|
}
|
|
1340
1136
|
/**
|
|
1341
|
-
* Run the pending layout pass now
|
|
1342
|
-
*
|
|
1343
|
-
* `$panel.
|
|
1344
|
-
* option. Does nothing when no pass is owed.
|
|
1137
|
+
* Run the pending layout pass now instead of on the frame it waits for, for
|
|
1138
|
+
* callers that must read what only the pass knows (`$panel.visible`,
|
|
1139
|
+
* `$panel.width`) and can't wait. Does nothing when no pass is owed.
|
|
1345
1140
|
*/
|
|
1346
1141
|
flushLayout() {
|
|
1347
1142
|
if (!this.layoutQueued)
|
|
@@ -1351,41 +1146,35 @@ export class PanelStackController {
|
|
|
1351
1146
|
}
|
|
1352
1147
|
/**
|
|
1353
1148
|
* Measure the content area, and with it the width a panel of each size gets.
|
|
1149
|
+
* The column region *is* that area (CSS's doing), so there is nothing to add
|
|
1150
|
+
* up here that could drift from the bars above and below. Widths stay
|
|
1151
|
+
* fractional: a rounded column edge would drift a pixel away from that chrome.
|
|
1354
1152
|
*
|
|
1355
|
-
* The
|
|
1356
|
-
*
|
|
1357
|
-
*
|
|
1358
|
-
*
|
|
1359
|
-
*
|
|
1360
|
-
*
|
|
1153
|
+
* The area divides into the fewest whole number of columns of at most
|
|
1154
|
+
* {@link SMALL_MAX_PX} — so 1080px is two of 540, 1520px three of ~507 —
|
|
1155
|
+
* keeping columns as wide as the cap allows rather than as narrow as
|
|
1156
|
+
* {@link SMALL_MIN_PX} permits. Only below 720px can that division dip under
|
|
1157
|
+
* the minimum; there a single column, capped at 540, centres in the area
|
|
1158
|
+
* instead. A width is therefore a pure function of the window: a panel NEVER
|
|
1159
|
+
* resizes because a neighbour came or went.
|
|
1361
1160
|
*
|
|
1362
|
-
*
|
|
1363
|
-
*
|
|
1364
|
-
* a multiple of, capped at the area itself. So 1080px is three columns of 360
|
|
1365
|
-
* and 1520px four of 380. An area too narrow for two is a single column,
|
|
1366
|
-
* itself capped at {@link SMALL_MAX_PX}: a small centres there instead of
|
|
1367
|
-
* stretching toward 720, so its ceiling holds, while the larger sizes still
|
|
1368
|
-
* take the whole area. A width is thus a pure function of the window: a panel
|
|
1369
|
-
* NEVER resizes because a neighbour came or went, and only a window resize
|
|
1370
|
-
* (the snap pass in `layout`) changes one.
|
|
1371
|
-
*
|
|
1372
|
-
* `undefined` while the shell has no width to speak of (it isn't in a document
|
|
1373
|
-
* yet, or it's `display:none`); the next pass tries again.
|
|
1161
|
+
* `undefined` while the shell has no width yet (not in a document, or
|
|
1162
|
+
* `display:none`); the next pass tries again.
|
|
1374
1163
|
*/
|
|
1375
1164
|
measure() {
|
|
1376
1165
|
const el = this.containerEl;
|
|
1377
1166
|
const area = el ? el.getBoundingClientRect().width : 0;
|
|
1378
1167
|
if (!area)
|
|
1379
1168
|
return undefined;
|
|
1380
|
-
const
|
|
1169
|
+
const cols = Math.ceil(area / SMALL_MAX_PX);
|
|
1170
|
+
const small = area / cols >= SMALL_MIN_PX ? area / cols : Math.min(area, SMALL_MAX_PX);
|
|
1381
1171
|
const units = (n) => Math.min(n * small, area);
|
|
1382
1172
|
return { area, size: { small, medium: units(2), large: units(3), none: area } };
|
|
1383
1173
|
}
|
|
1384
1174
|
/**
|
|
1385
|
-
* The measurements this pass runs on
|
|
1386
|
-
*
|
|
1387
|
-
*
|
|
1388
|
-
* would be a forced reflow each, in the middle of building their DOM.
|
|
1175
|
+
* The measurements this pass runs on, taken once per pass and per commit and
|
|
1176
|
+
* shared with the panels drawn in between: they must all size against the
|
|
1177
|
+
* same shell, and a `getBoundingClientRect()` each is a forced reflow each.
|
|
1389
1178
|
*/
|
|
1390
1179
|
geometry() {
|
|
1391
1180
|
return (this.geom ??= this.measure());
|
|
@@ -1395,25 +1184,21 @@ export class PanelStackController {
|
|
|
1395
1184
|
return this.geometry()?.size[size] ?? 0;
|
|
1396
1185
|
}
|
|
1397
1186
|
/**
|
|
1398
|
-
* Size and position every panel
|
|
1399
|
-
*
|
|
1400
|
-
*
|
|
1401
|
-
* of them are visible, how wide each one is and where it sits. All the motion
|
|
1402
|
-
* between two of these arrangements is CSS's job.
|
|
1187
|
+
* Size and position every panel — everything CSS can't work out for itself:
|
|
1188
|
+
* which panels exist, which are visible, how wide each is and where it sits.
|
|
1189
|
+
* The motion between two such arrangements is CSS's job.
|
|
1403
1190
|
*/
|
|
1404
1191
|
layout() {
|
|
1405
1192
|
const container = this.containerEl;
|
|
1406
1193
|
const shell = container?.closest(".s-main");
|
|
1407
1194
|
if (!container || !shell)
|
|
1408
1195
|
return;
|
|
1409
|
-
//
|
|
1410
|
-
//
|
|
1411
|
-
// nothing here can subscribe to anything.
|
|
1196
|
+
// Always runs from a fresh frame (rAF, a ResizeObserver), so no reactive
|
|
1197
|
+
// scope is active and nothing read here can subscribe to anything.
|
|
1412
1198
|
const live = this.$state.live;
|
|
1413
1199
|
const n = live.length;
|
|
1414
|
-
// A panel that hasn't drawn yet has no width to contribute, which would
|
|
1415
|
-
// this pass
|
|
1416
|
-
// Every mount schedules another pass, so simply wait for it.
|
|
1200
|
+
// A panel that hasn't drawn yet has no width to contribute, which would
|
|
1201
|
+
// make this pass meaningless. Every mount schedules another, so just wait.
|
|
1417
1202
|
if (!n || live.some((entry) => !entry.el))
|
|
1418
1203
|
return;
|
|
1419
1204
|
// This pass measures afresh — it is the one thing that runs after a resize.
|
|
@@ -1422,11 +1207,9 @@ export class PanelStackController {
|
|
|
1422
1207
|
if (!geom)
|
|
1423
1208
|
return;
|
|
1424
1209
|
const single = this.opts.columns === "single";
|
|
1425
|
-
// A
|
|
1426
|
-
//
|
|
1427
|
-
//
|
|
1428
|
-
// animating itself into place on its first pass reads as a glitch. Only
|
|
1429
|
-
// what a *panel* did is worth animating, and none of those three are.
|
|
1210
|
+
// A resize of the window (or of the shell, via `navWidth`/`maxWidth`) must
|
|
1211
|
+
// be adopted instantly — geometry chasing the window through a transition
|
|
1212
|
+
// reads as lag. Only what a *panel* did is worth animating, so
|
|
1430
1213
|
// `.s-shell-snap` suppresses every standing transition for this one pass.
|
|
1431
1214
|
const snap = this.lastGeom?.area !== geom.area;
|
|
1432
1215
|
if (snap) {
|
|
@@ -1434,9 +1217,8 @@ export class PanelStackController {
|
|
|
1434
1217
|
shell.classList.add("s-shell-snap");
|
|
1435
1218
|
}
|
|
1436
1219
|
const width = (entry) => geom.size[entry.maxWidth];
|
|
1437
|
-
// The visible run: as many columns as
|
|
1438
|
-
//
|
|
1439
|
-
// Panels beyond it are parked past the right edge (see phase 1).
|
|
1220
|
+
// The visible run: as many columns as fit, ending at the current panel,
|
|
1221
|
+
// which always shows. Panels beyond it are parked (see phase 1).
|
|
1440
1222
|
const cur = Math.min(this.$state.focus, n - 1);
|
|
1441
1223
|
let first = cur;
|
|
1442
1224
|
let runSum = width(live[cur]);
|
|
@@ -1449,38 +1231,32 @@ export class PanelStackController {
|
|
|
1449
1231
|
first = i;
|
|
1450
1232
|
}
|
|
1451
1233
|
}
|
|
1452
|
-
// The content area is a fixed width, so a run that doesn't fill it
|
|
1453
|
-
//
|
|
1454
|
-
// the columns holds still meanwhile: the sidebar, the top bar and the
|
|
1455
|
-
// footer never move, however many columns come and go.
|
|
1234
|
+
// The content area is a fixed width, so a run that doesn't fill it centres
|
|
1235
|
+
// rather than hanging off the left edge — the chrome around it never moves.
|
|
1456
1236
|
const left = (geom.area - runSum) / 2;
|
|
1457
1237
|
for (let i = first; i <= cur; i++)
|
|
1458
1238
|
live[i].width = width(live[i]);
|
|
1459
|
-
//
|
|
1460
|
-
//
|
|
1239
|
+
// Never-visible panels get their would-be width, so a reveal doesn't start
|
|
1240
|
+
// from nothing.
|
|
1461
1241
|
for (const entry of live) {
|
|
1462
1242
|
if (!entry.width)
|
|
1463
1243
|
entry.width = width(entry);
|
|
1464
1244
|
}
|
|
1465
|
-
// Phase 1 — every panel's *start* state for this frame. Panels
|
|
1466
|
-
//
|
|
1467
|
-
//
|
|
1468
|
-
// adopted instantly and becomes the "before" of their enter animation.
|
|
1245
|
+
// Phase 1 — every panel's *start* state for this frame. Panels on screen
|
|
1246
|
+
// simply move; freshly mounted ones still have transitions off, so what is
|
|
1247
|
+
// set here is adopted instantly and becomes the "before" of their enter.
|
|
1469
1248
|
const fresh = [];
|
|
1470
1249
|
let x = left;
|
|
1471
1250
|
for (let i = 0; i < n; i++) {
|
|
1472
1251
|
const entry = live[i];
|
|
1473
1252
|
const el = entry.el;
|
|
1474
1253
|
const shown = i >= first && i <= cur;
|
|
1475
|
-
// Visible columns tile the run
|
|
1476
|
-
//
|
|
1477
|
-
//
|
|
1478
|
-
// layer over shallower ones, each on the odd layer for its depth (see
|
|
1479
|
-
// LAYER_STEP).
|
|
1254
|
+
// Visible columns tile the run left to right; crowded-out ones rest at
|
|
1255
|
+
// its left edge and parked ones just past its right, both keeping their
|
|
1256
|
+
// last width. Deeper panels layer over shallower (see LAYER_STEP).
|
|
1480
1257
|
place(el, shown ? x : i > cur ? left + runSum : left, entry.width, LAYER_STEP * i + 1);
|
|
1481
|
-
//
|
|
1482
|
-
//
|
|
1483
|
-
// change, so per-panel UI hanging off them isn't rebuilt by every pass.
|
|
1258
|
+
// Written only on a change, so per-panel UI hanging off `visible` or
|
|
1259
|
+
// `width` isn't rebuilt by every pass.
|
|
1484
1260
|
if (entry.$panel.visible !== shown)
|
|
1485
1261
|
entry.$panel.visible = shown;
|
|
1486
1262
|
if (entry.$panel.width !== entry.width)
|
|
@@ -1488,9 +1264,7 @@ export class PanelStackController {
|
|
|
1488
1264
|
if (shown)
|
|
1489
1265
|
x += entry.width;
|
|
1490
1266
|
el.classList.toggle("s-panel-sep", shown && i > first);
|
|
1491
|
-
// Off-screen panels fade out
|
|
1492
|
-
// faded, stop being rendered at all — but they keep their DOM, and
|
|
1493
|
-
// their scroll position.
|
|
1267
|
+
// Off-screen panels fade out and stop rendering, keeping their DOM.
|
|
1494
1268
|
el.classList.toggle("s-panel-hidden", i < first);
|
|
1495
1269
|
el.classList.toggle("s-panel-parked", i > cur);
|
|
1496
1270
|
el.toggleAttribute("inert", !shown);
|
|
@@ -1505,14 +1279,13 @@ export class PanelStackController {
|
|
|
1505
1279
|
entry.$ui.holding = true;
|
|
1506
1280
|
this.holdEnter(entry);
|
|
1507
1281
|
}
|
|
1508
|
-
// Already at its resting place; the enter
|
|
1509
|
-
//
|
|
1282
|
+
// Already at its resting place; the enter is the offset and transparency
|
|
1283
|
+
// it starts from, one edge to the right.
|
|
1510
1284
|
if (entry.enter && shown)
|
|
1511
1285
|
el.classList.add("s-panel-enter");
|
|
1512
1286
|
}
|
|
1513
|
-
// Phase 2 —
|
|
1514
|
-
// pass
|
|
1515
|
-
// (Reading a layout property is what does it.)
|
|
1287
|
+
// Phase 2 — reading a layout property forces the browser to adopt those
|
|
1288
|
+
// start states (and a snap pass's transition-free geometry) to animate from.
|
|
1516
1289
|
if (fresh.length || snap)
|
|
1517
1290
|
void container.offsetWidth;
|
|
1518
1291
|
if (snap)
|