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