staffa 0.12.1 → 0.14.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.
@@ -4,20 +4,24 @@ import { type Slot } from "../core.js";
4
4
  * Routed, multi-column panel navigation for {@link main}.
5
5
  *
6
6
  * Each route draws one screen of the app, called a *panel*. The open panels
7
- * form a **stack**, and one of them is the **current** panel: the one the URL
7
+ * form a **stack**, whose last panel is the **current** one: the panel the URL
8
8
  * names, and the rightmost column on screen. As many panels as fit are shown,
9
9
  * ending at the current one — on a phone that is one at a time, on a wider
10
10
  * screen the panels that would have covered each other sit side by side
11
11
  * instead. The app's own code is the same either way.
12
12
  *
13
- * Going to a panel that is already open — a breadcrumb, or any link to it —
14
- * just moves the current-panel cursor along the stack: panels right of it stay
15
- * open, parked past the right edge of the viewport, and nothing closes.
16
- * Opening a *new* panel is what prunes: everything after the panel it came
17
- * from closes, except panels the user pinned — which ride along beneath the
18
- * new panel — and panels holding unsaved work, which no navigation ever tears
19
- * down. Escape steps one panel left, closing the panel it leaves only when
20
- * that panel is the stack's discardable end.
13
+ * Whatever a navigation lands on becomes the top of that stack, and the same
14
+ * path is never in it twice. Opening a new panel closes everything after the
15
+ * panel it came from; a plain link to a panel that is already open — a
16
+ * breadcrumb, a nav item for the section you are in — returns to its own
17
+ * place, closing whatever was stacked on top, while a `replace` or `open`
18
+ * applies its usual shape, the open panel moving into it alive.
19
+ * Two kinds of panel survive that: the ones the user pinned, which ride along,
20
+ * and the ones holding unsaved work, which no navigation ever tears down.
21
+ * Those wait parked out of sight past the rightmost column, which is the only
22
+ * way a panel ever sits *after* the current one. Escape closes the current
23
+ * panel — or just steps left, when it holds unsaved work or panels sit parked
24
+ * beyond it.
21
25
  *
22
26
  * Navigation runs through `aberdeen/route`: the URL holds the current panel,
23
27
  * and the rest of the arrangement — the panels before it, the ones parked
@@ -83,6 +87,14 @@ export type AncestorsHandler<P = any> = (params: P, path: string) => readonly st
83
87
  export type AncestorTable<R> = {
84
88
  [K in keyof R & string]?: (params: Prettify<PathParams<K>>, path: string) => readonly string[] | undefined | void;
85
89
  };
90
+ /**
91
+ * How wide a panel asks to be — a ceiling the shell never exceeds; see
92
+ * {@link Panel.maxWidth}. `"small"` is the column the content area is divided
93
+ * into; `"medium"` and `"large"` are two and three of those, and `"none"` is
94
+ * the whole area. Each is capped at the content area, so on a narrow window
95
+ * they all come to the same thing.
96
+ */
97
+ export type PanelSize = "small" | "medium" | "large" | "none";
86
98
  /**
87
99
  * What a route handler gets: the params from its route, plus everything the
88
100
  * shell needs to know about the panel it is drawing. It's an Aberdeen proxy, so
@@ -153,33 +165,35 @@ export interface Panel<P = Record<string, string | number | string[]>> {
153
165
  */
154
166
  readonly visible: boolean;
155
167
  /**
156
- * The widest this panel can usefully be. Every panel must work at 360–540px,
157
- * because that is what it gets when two columns fit; this says how much
158
- * *more* it can take.
159
- *
160
- * - `"half"` — nothing more. Half the content area (360–540px), so a second
161
- * column fits beside it. For lists and detail forms.
162
- * - `"full"` (the default) — the whole content area, up to ~1100px.
163
- * - `"screen"` — the whole window, unbounded: boards, wide tables, dense
164
- * dashboards. While one is open the columns stretch to the screen edges
165
- * instead of stopping at the standard 1280px page; the top bar and
166
- * footer hold the standard width throughout.
167
- *
168
- * Below the width two columns need, everything takes the content area
169
- * whatever it asked for. Widths depend only on the window, never on what
170
- * else is open, so opening or closing a panel never resizes another.
171
- *
172
- * This is a *layout regime*, not a width guarantee: handle whatever width
173
- * the bucket yields, and ask only for what your content can actually use —
174
- * a screen that would cap its own content narrower than its ask is holding
175
- * room that would have let another column fit beside it.
168
+ * The widest this panel can usefully be — a ceiling the shell never
169
+ * exceeds, so the draw function never has to look right past it. It is
170
+ * counted in the shell's *columns*: the content area divides into the
171
+ * narrowest whole number of columns of at least 360px each (three columns
172
+ * of 360 in a 1080px area, four of 380 in 1520px), and a column is never
173
+ * wider than 540 — where the area holds just one, a small centres in it
174
+ * rather than stretching. So an ask never exceeds its column count × 540:
175
+ *
176
+ * - `"small"` — one column, never above 540px: lists, detail forms.
177
+ * - `"medium"` (the default) — two columns, never above 1080px.
178
+ * - `"large"` — three columns, never above 1620px: wide tables.
179
+ * - `"none"` — the whole content area, unbounded: boards, dashboards.
180
+ * Bound it with the shell's own `maxWidth` where that matters.
181
+ *
182
+ * Every size is capped at the content area, so on a phone they all come to
183
+ * the same thing: one screen at a time. And a width depends only on the
184
+ * window, never on what else is open, so opening or closing a panel never
185
+ * resizes another — the run of columns just recentres in the area.
186
+ *
187
+ * Ask only for what your content can actually use: a panel that would cap
188
+ * its own content narrower than its ask is holding room that would have
189
+ * let another column fit beside it.
176
190
  *
177
191
  * Set it at the top of your handler and the panel is already that wide when
178
192
  * you draw (see {@link Panel.width}); set it later — when your data tells you
179
193
  * — and the panel reflows without being redrawn, keeping its state, while
180
194
  * the columns beside it move over.
181
195
  */
182
- maxWidth?: "half" | "full" | "screen";
196
+ maxWidth?: PanelSize;
183
197
  /**
184
198
  * Set this while you're fetching what the panel needs, and back to `false`
185
199
  * when you're done. A new panel waits a moment before sliding in, so it can
@@ -190,10 +204,10 @@ export interface Panel<P = Record<string, string | number | string[]>> {
190
204
  loading?: boolean;
191
205
  /**
192
206
  * Keeps this panel from being closed by navigation happening *elsewhere*.
193
- * Opening a new panel normally closes everything after the panel it came
194
- * from; a pinned panel survives that, staying in the stack — parked past the
195
- * right edge of the viewport — slotted in beneath the new panel, one crumb
196
- * click away. The user toggles it from the crumb's context menu
207
+ * A navigation normally closes everything after the panel it came from (or
208
+ * returned to); a pinned panel survives that, staying in the stack — slotted
209
+ * in beneath the new panel, or parked out of sight when the new panel was
210
+ * already beneath it. Either way it is one crumb click away. The user toggles it from the crumb's context menu
197
211
  * (right-click or long-press), which is also where the pin shows; setting
198
212
  * it from code does the same thing.
199
213
  *
@@ -205,12 +219,11 @@ export interface Panel<P = Record<string, string | number | string[]>> {
205
219
  /**
206
220
  * Set this while the panel holds work that must not be lost — a dirty form,
207
221
  * an upload in flight. An unsaved panel cannot be closed, by anything:
208
- * navigation that would prune it parks it instead, past the viewport's
209
- * right edge, wearing a ● in its crumb — even the browser's back button
210
- * only parks it. {@link Panel.close} and the crumb menu's Close refuse,
222
+ * navigation that would prune it parks it out of sight instead, wearing a
223
+ * ● in its crumb — even the browser's back button only parks it. {@link Panel.close} and the crumb menu's Close refuse,
211
224
  * Escape on it steps left along the stack rather than closing, and closing
212
- * the browser tab runs into the browser's own are-you-sure (after which the
213
- * shell brings the unsaved panel back on screen).
225
+ * the browser tab runs into the browser's own are-you-sure, the unsaved
226
+ * panel brought on screen as the question is raised.
214
227
  *
215
228
  * Only the app clears it; the user has no toggle. A Save or Discard button
216
229
  * clears it and then closes:
@@ -275,14 +288,7 @@ export interface Panel<P = Record<string, string | number | string[]>> {
275
288
  */
276
289
  open(href: string, how?: "push" | "replace" | "open"): Promise<boolean>;
277
290
  }
278
- /**
279
- * The standard page width: sidebar plus content area, capped by the window.
280
- * `"full"` fills the content-area part of this exactly; only a `"screen"`
281
- * page makes the shell grow past it. The top bar and footer keep to this
282
- * width even then (see main.ts), so the chrome holds still while the
283
- * columns stretch.
284
- */
285
- export declare const SHELL_PX = 1280;
291
+ export declare const SMALL_MAX_PX = 540;
286
292
  /** Options the stack needs from its shell. */
287
293
  export interface PanelStackOptions {
288
294
  routes: Routes;
@@ -350,10 +356,10 @@ export interface PanelStack {
350
356
  * the new panel).
351
357
  *
352
358
  * The same rules as a link click apply: pushing a path that is already open
353
- * goes back to it — a focus move along the stack, closing nothing — rather
354
- * than opening it twice, and a panel holding {@link Panel.unsaved} work is
355
- * never closed, only parked. That's what a plain link does, and what
356
- * `data-panel=push` says outright.
359
+ * returns to it — closing whatever was stacked on top — rather than opening
360
+ * it twice, and a panel holding {@link Panel.unsaved} work is never closed,
361
+ * only parked. That's what a plain link does, and what `data-panel=push`
362
+ * says outright.
357
363
  *
358
364
  * Note that a link builds on the panel it is *drawn in*, which is the
359
365
  * current panel only while no column beside it has the focus. Code
@@ -455,8 +461,8 @@ export declare class PanelStackController implements PanelStack {
455
461
  private containerEl?;
456
462
  /** The shell's measurements, shared by everything drawn since they were taken. */
457
463
  private geom?;
458
- /** The body width at the last layout; a change means a window resize → snap. */
459
- private lastBodyW;
464
+ /** The measurements the last layout ran on; a change in them → snap. */
465
+ private lastGeom?;
460
466
  private layoutQueued;
461
467
  private timers;
462
468
  /** The arrangement the navigation in flight is heading for; see {@link intended}. */
@@ -588,19 +594,21 @@ export declare class PanelStackController implements PanelStack {
588
594
  private issue;
589
595
  private start;
590
596
  /**
591
- * Make the stack's `index`th panel current: the URL and the visible run move
592
- * to it, while the panels right of it stay open, parked past the right edge
593
- * of the viewport. Nothing closes; it is a history entry, so the browser's
594
- * back button returns the focus to where it was. What a click on a
595
- * breadcrumb — any link to an open panel — comes down to.
597
+ * Make the stack's `index`th panel current without closing anything, leaving
598
+ * the panels right of it parked out of sight.
599
+ *
600
+ * Only ever a step around a panel that refuses to close — nothing else is
601
+ * left sitting after the current one — so this is Escape's way past an
602
+ * unsaved panel, and the way back to one. It is a history entry, so the
603
+ * browser's back button returns the focus to where it was.
596
604
  */
597
605
  private focusAt;
598
606
  /**
599
607
  * One step back along the stack — what Escape does (`main()` calls this;
600
- * it is not {@link PanelStack} API). At the stack's end this closes the
601
- * current panel; mid-stack — with panels parked to the right — or when the
602
- * panel holds {@link Panel.unsaved} work, the panel stays open and the
603
- * focus just moves to the panel on its left, parking the one it leaves.
608
+ * it is not {@link PanelStack} API). Normally that closes the current panel,
609
+ * which is the stack's end. When it holds {@link Panel.unsaved} work — or
610
+ * panels sit parked beyond it — it stays open instead, and the focus
611
+ * simply moves to the panel on its left.
604
612
  * Resolves `false` at the stack's start, where there is no left to go.
605
613
  */
606
614
  back(): Promise<boolean>;
@@ -636,11 +644,14 @@ export declare class PanelStackController implements PanelStack {
636
644
  * that know it.
637
645
  *
638
646
  * `how` is the link's `data-panel` attribute (or the caller's word for
639
- * it): absent — like a link without the attribute — it is the shell's
640
- * `linkNavigation` default, an unrecognised value is a push on top of
641
- * `from`, `"replace"` swaps `from` out rather than stacking on it, and
642
- * `"open"` drops `from` altogether so the target arrives with its own
643
- * stack, the way a nav item's link does.
647
+ * it), picking how much of `from`'s context the target keeps: a push (the
648
+ * default, and what unrecognised values fall back to) keeps `from` and
649
+ * builds on it, `"replace"` keeps only what is beneath `from`, and
650
+ * `"open"` keeps nothing — the target arrives with its own stack, the way
651
+ * a nav item's link does. Absent, it is the shell's `linkNavigation`
652
+ * default, like a link without the attribute. A target that is already
653
+ * open is returned to by a push, and *moved* — alive, state intact — by
654
+ * the other two: the stack never holds a path twice.
644
655
  *
645
656
  * Resolves the way every {@link PanelStack} method does: `true` once the
646
657
  * navigation lands, `false` when it doesn't (already there counts as
@@ -677,11 +688,11 @@ export declare class PanelStackController implements PanelStack {
677
688
  * The breadcrumb stack, drawn by `main()` into the top bar: every open
678
689
  * panel, oldest first, the ones on screen right now in bold, pinned ones
679
690
  * wearing their pin. Every crumb but the current panel's is a plain link to
680
- * that panel, and a link to an open panel is a focus move (see `navigate`) —
681
- * so clicking along the stack closes nothing, in either direction, and the
682
- * panels right of the current one wait just past the viewport's edge.
683
- * Right-click (or long-press) offers pinning, and closing just that one
684
- * panel — the close that splices it out of the middle when it isn't last.
691
+ * that panel, and a link to an open panel returns to it (see `navigate`) —
692
+ * so clicking a crumb goes back to that panel and closes what was stacked on
693
+ * top of it, pinned and unsaved panels excepted. Right-click (or long-press)
694
+ * offers pinning, and closing just that one panel — the close that splices
695
+ * it out of the middle when it isn't last.
685
696
  */
686
697
  drawCrumbs(): void;
687
698
  private drawCrumb;
@@ -700,9 +711,9 @@ export declare class PanelStackController implements PanelStack {
700
711
  private watchTitle;
701
712
  /**
702
713
  * While any open panel holds unsaved work, closing the tab — or navigating
703
- * the whole browser away — runs into the browser's own are-you-sure. When
704
- * the user stays, the unsaved panel is brought back on screen if it wasn't,
705
- * so what held the tab is in front of them rather than parked out of sight.
714
+ * the whole browser away — runs into the browser's own are-you-sure, with
715
+ * the unsaved panel brought on screen as the question is raised, so what is
716
+ * holding the tab is in front of the user rather than parked out of sight.
706
717
  */
707
718
  private guardTabClose;
708
719
  /**
@@ -724,11 +735,24 @@ export declare class PanelStackController implements PanelStack {
724
735
  private drawActions;
725
736
  scheduleLayout(): void;
726
737
  /**
727
- * Measure the shell, and with it the width the window gives a panel of each
728
- * layout. Measured on the *shell*, not on the column region: the region's width
729
- * is the layout engine's own output, so reading it back would nail the layout
730
- * to whatever it happened to be a frame ago. Fractional widths throughout — a
731
- * rounded column edge would drift a pixel away from the chrome above it.
738
+ * Measure the content area, and with it the width a panel of each size gets.
739
+ *
740
+ * The column region *is* the content area: it takes whatever the shell has
741
+ * left beside the sidebar, capped by the shell's own `maxWidth` — all of it
742
+ * CSS's doing, so there is nothing to add up here and nothing that could
743
+ * drift from the width the bars above and below line up with. Fractional
744
+ * widths throughout: a rounded column edge would drift a pixel away from that
745
+ * chrome.
746
+ *
747
+ * The area divides into the narrowest whole number of columns that keeps each
748
+ * at least {@link SMALL_MIN_PX} wide — the `"small"` unit every other size is
749
+ * a multiple of, capped at the area itself. So 1080px is three columns of 360
750
+ * and 1520px four of 380. An area too narrow for two is a single column,
751
+ * itself capped at {@link SMALL_MAX_PX}: a small centres there instead of
752
+ * stretching toward 720, so its ceiling holds, while the larger sizes still
753
+ * take the whole area. A width is thus a pure function of the window: a panel
754
+ * NEVER resizes because a neighbour came or went, and only a window resize
755
+ * (the snap pass in `layout`) changes one.
732
756
  *
733
757
  * `undefined` while the shell has no width to speak of (it isn't in a document
734
758
  * yet, or it's `display:none`); the next pass tries again.
@@ -744,8 +768,7 @@ export declare class PanelStackController implements PanelStack {
744
768
  /** How wide a panel asking for this is, right now; 0 while the shell can't be measured. */
745
769
  private roomFor;
746
770
  /**
747
- * Size and position every panel, and publish the width of the whole ensemble
748
- * (sidebar + separator + columns) for the shell to centre itself on.
771
+ * Size and position every panel.
749
772
  *
750
773
  * This is everything CSS can't work out for itself: which panels exist, which
751
774
  * of them are visible, how wide each one is and where it sits. All the motion