staffa 0.9.0 → 0.10.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.
Files changed (60) hide show
  1. package/README.md +106 -48
  2. package/dist/components/autocomplete.js +1 -1
  3. package/dist/components/box.d.ts +8 -16
  4. package/dist/components/box.js +21 -27
  5. package/dist/components/button.d.ts +40 -0
  6. package/dist/components/button.js +85 -12
  7. package/dist/components/buttonChooser.js +1 -1
  8. package/dist/components/checkbox.js +3 -3
  9. package/dist/components/field.js +3 -3
  10. package/dist/components/main.d.ts +134 -71
  11. package/dist/components/main.js +245 -174
  12. package/dist/components/menu.d.ts +72 -14
  13. package/dist/components/menu.js +231 -34
  14. package/dist/components/pages.d.ts +638 -0
  15. package/dist/components/pages.js +1510 -0
  16. package/dist/components/panels.d.ts +448 -225
  17. package/dist/components/panels.js +819 -435
  18. package/dist/components/tabs.d.ts +37 -0
  19. package/dist/components/tabs.js +128 -69
  20. package/dist/core.d.ts +1 -1
  21. package/dist/core.js +1 -1
  22. package/dist/glyphs.d.ts +24 -0
  23. package/dist/glyphs.js +25 -0
  24. package/dist/index.d.ts +4 -4
  25. package/dist/index.js +3 -4
  26. package/dist/staffa.esm.js +1 -1
  27. package/dist/theme.d.ts +67 -0
  28. package/dist/theme.js +12 -2
  29. package/package.json +2 -2
  30. package/skill/BoxOptions.md +7 -12
  31. package/skill/IconButtonOptions.md +41 -0
  32. package/skill/MainOptions.md +106 -58
  33. package/skill/MenuItem.md +16 -1
  34. package/skill/MenuListOptions.md +24 -0
  35. package/skill/MenuOptions.md +3 -2
  36. package/skill/Panel.md +190 -0
  37. package/skill/PanelStack.md +106 -0
  38. package/skill/SKILL.md +172 -64
  39. package/skill/ScrollStripOptions.md +21 -0
  40. package/skill/box.md +1 -4
  41. package/skill/closeNav.md +3 -3
  42. package/skill/iconButton.md +27 -0
  43. package/skill/main.md +13 -9
  44. package/skill/menu.md +29 -0
  45. package/skill/scrollStrip.md +28 -0
  46. package/src/components/autocomplete.ts +1 -1
  47. package/src/components/box.ts +29 -39
  48. package/src/components/button.ts +109 -8
  49. package/src/components/buttonChooser.ts +1 -1
  50. package/src/components/checkbox.ts +3 -3
  51. package/src/components/field.ts +3 -3
  52. package/src/components/main.ts +381 -188
  53. package/src/components/menu.ts +265 -37
  54. package/src/components/panels.ts +1136 -526
  55. package/src/components/tabs.ts +134 -68
  56. package/src/core.ts +1 -1
  57. package/src/index.ts +4 -4
  58. package/src/theme.ts +14 -3
  59. package/skill/Page.md +0 -119
  60. package/skill/panels.md +0 -10
package/skill/SKILL.md CHANGED
@@ -118,12 +118,12 @@ S.setDarkMode(undefined); // follow OS
118
118
 
119
119
  ### Panel-stack navigation
120
120
 
121
- Give `S.main()` a `routes` table instead of a `content` slot, and it takes over navigation for you. Each route draws one screen of your app. Staffa calls those screens **panels**, and it shows as many of them at a time as comfortably fit.
121
+ Give `S.main()` a `routes` table instead of a `content` slot, and it takes over navigation for you. Each route draws one screen of your app — Staffa calls those **panels** — and the shell shows as many of them at a time as comfortably fit, each in its own **column**.
122
122
 
123
123
  On a phone that means one panel at a time: a link opens a new panel on top of it, and closing that one brings the previous back, the way most mobile apps work. On a wider screen, panels that would have covered each other sit side by side instead. Pick a project from a list and it opens *beside* the list; pick another and it takes the first one's place. Your code doesn't know the difference.
124
124
 
125
125
  ```ts
126
- S.main({
126
+ const shell = S.main({
127
127
  title: "Trackle",
128
128
  nav: { items: [{ label: "Projects", href: "/projects" }] },
129
129
  routes: {
@@ -131,18 +131,19 @@ S.main({
131
131
  "/projects/[projectId]": drawProject,
132
132
  "/projects/[projectId]/tasks/[taskId=integer]": drawProjectTask,
133
133
  },
134
- notFound: ($page) => S.box({ header: "Not found", content: $page.path }),
134
+ notFound: ($panel) => S.box({ header: "Not found", content: $panel.path }),
135
135
  });
136
136
 
137
- function drawProject($page: S.Page<{ projectId: string }>) {
138
- const { projectId } = $page.params; // typed from the route key
137
+ function drawProject($panel: S.Panel<{ projectId: string }>) {
138
+ const { projectId } = $panel.params; // typed from the route key
139
+ $panel.title = `Project ${projectId}`; // the shell puts it wherever it fits
139
140
  A(`a href=/projects/${projectId}/tasks/1 #Open the first task`);
140
141
  }
141
142
 
142
143
  // Etc..
143
144
  ```
144
145
 
145
- Each handler gets a `$page` object holding the params from its route, along with the things Staffa needs to know about the panel: its title, how much room it wants, whether it's still loading. It's an Aberdeen proxy, so you can set those later (when your data arrives, say) and the shell keeps up.
146
+ Each handler gets a `$panel` object holding the params from its route, along with the things Staffa needs to know about the panel: what it's called, what it can do, how much room it wants, whether it's still loading. It's an Aberdeen proxy, so you can set those later (when your data arrives, say) and the shell keeps up.
146
147
 
147
148
  **Route keys.** A segment wrapped in brackets is a param:
148
149
 
@@ -150,72 +151,126 @@ Each handler gets a `$page` object holding the params from its route, along with
150
151
  - `[name=integer]` matches one segment, as a number.
151
152
  - `[...name]` matches the rest of the path, as a string. It has to be the last thing in the key, and it needs at least one segment to match.
152
153
 
153
- The first key that matches wins, and a segment a param refuses simply doesn't match, so it falls through to a later route, or to `notFound`. TypeScript reads each key and types that handler's `$page.params` from it, so `params.taskId` above really is a `number`.
154
+ The first key that matches wins, and a segment a param refuses simply doesn't match, so it falls through to a later route, or to `notFound`. TypeScript reads each key and types that handler's `$panel.params` from it, so `params.taskId` above really is a `number`.
154
155
 
155
- `integer` only accepts spellings that survive a round trip back to the same URL: `42` and `-7` and `0`, but not `007`, `1.5`, `0x10`, `-0` or anything past `Number.MAX_SAFE_INTEGER`. Otherwise `/tasks/42` and `/tasks/0042` would be two different paths for one record, and could sit open in two panels at once. For ids that aren't safe integers, such as snowflakes, use a plain `[id]` and keep them as strings.
156
+ `integer` only accepts spellings that survive a round trip back to the same URL: `42` and `-7` and `0`, but not `007`, `1.5`, `0x10`, `-0` or anything past `Number.MAX_SAFE_INTEGER`. Otherwise `/tasks/42` and `/tasks/0042` would be two different paths for one record, and could sit open in two columns at once. For ids that aren't safe integers, such as snowflakes, use a plain `[id]` and keep them as strings.
156
157
 
157
158
  `[...name]` hands you the remaining path exactly as it appears in the URL, still percent-encoded. Decoding it for you would be lossy: an encoded slash inside a segment would come back looking just like a separator. When you want the pieces, `name.split("/").map(decodeURIComponent)` gives them to you. (Single-segment params have no such ambiguity, so those *are* decoded.)
158
159
 
159
160
  **Navigating is just links.** Write ordinary `<a href="/...">` links; Staffa handles the clicks (so don't also call Aberdeen's `interceptLinks()`).
160
161
 
161
- - A link inside a panel opens its target on top of that panel, closing anything that was above it first. That's why clicking a second project replaces the open project instead of adding a third column.
162
- - Add `data-panel=replace` and the link replaces the panel it sits in, rather than opening on top of it. That's what you want for prev/next buttons.
163
- - A link to something that's already open goes back to it instead of opening it twice. The same path is never in the stack twice.
164
- - A link that isn't inside a panel (a nav item, or one in a dialog) has no panel to build on, so it replaces the stack as a whole: the page you asked for, with its ancestor pages opened beneath it (see [below](#ancestors)). Panels that the new stack also contains stay as they are, so clicking the nav item for the section you're already in won't reset it. Clicking a nav item and opening that same URL in a fresh tab therefore give you the same columns.
162
+ The open panels form a **stack**, and one of them is the **current** panel: the one the URL names, and the rightmost column on screen. Usually that's the newest panel — but going back along the stack moves the cursor without closing anything (see the breadcrumbs below), so panels can sit *after* the current one too, parked just past the viewport's right edge.
163
+
164
+ - A link inside a panel opens its target on top of that panel, closing everything after it first. That's why clicking a second project replaces the open project instead of adding a third column — and why the panels you'd browsed past don't pile up.
165
+ - A `data-panel` attribute on the link picks a different one of the three navigations. `push` is the default just described; `replace` puts the target in place of the link's own panel rather than on top of it, which is what prev/next buttons want; and `open` leaves that panel behind altogether and gives the target its own stack, exactly as a nav item would — for a link that points somewhere else in the app, a search hit or a mention, where the panel you clicked from isn't the context you want to keep.
166
+ - A link to something that's already open goes back to it instead of opening it twice — a move along the stack, closing nothing. The same path is never in the stack twice.
167
+ - A link that isn't inside a panel (a nav item, or one in a dialog) has no panel to build on, so it replaces the stack as a whole: the panel you asked for, with its ancestor panels opened beneath it (see [below](#ancestors)). Panels that the new stack also contains stay as they are, so clicking the nav item for the section you're already in won't reset it. Clicking a nav item and opening that same URL in a fresh tab therefore give you the same columns.
168
+
169
+ **The stack is an object, not a global.** In routed mode `S.main()` hands back the panel stack, and every panel gets the same object as `$panel.stack` — which is what a route handler uses, since it runs while the `S.main()` call is still going and can't see its return value yet.
170
+
171
+ ```ts
172
+ shell.pushPanel(path); // on top of the current panel
173
+ shell.replacePanel(path); // in its place
174
+ shell.openPanelStack(path, beneath?); // a whole arrangement, the way a nav item does
175
+ shell.closePanel(path?); // the current panel, or a named one
176
+
177
+ shell.panels; // the open panels, oldest first — the Panel objects themselves
178
+ shell.currentPanelIndex; // which of them the URL is on
179
+ shell.currentPanel; // shorthand for panels[currentPanelIndex]
180
+ ```
165
181
 
166
- From code, `S.panels.push(path)` opens a panel on top of the top one, `.replace(path)` opens one in place of the top one, `.open(path, beneath?)` opens a whole arrangement at once (the way a nav item does — see [below](#ancestors)), and `.close(path?)` closes the top panel (or a named one). `S.panels.stack` is the list of open paths.
182
+ Navigations settle asynchronously (closes travel through the browser's history), so each of the four methods returns a `Promise<boolean>`: `true` once it lands, `false` when it doesn't — an unsaved panel refused to close, a route guard said no, or another navigation superseded it. Ignore it unless you care.
167
183
 
168
- Navigating faster than the shell can settle is fine: closing travels through the browser's history, so it takes a moment to land, and anything asked for in the meantime waits for it rather than being dropped. Two quick Escapes (or back gestures) peel two panels, each aimed at the stack the one before it was heading for. A `requestClose` that says no clears what was queued behind it, so an Escape can't sail past the panel that just refused to close.
184
+ `panels` is a live view rather than a copy, so writing through it works — `shell.panels[0].pinned = true` is the only way to pin a panel from outside its own handler. All three are reactive on the stack's shape: read one in a scope and it re-runs when panels open, close or the cursor moves. Don't hold a `Panel` across a navigation; read it fresh.
169
185
 
170
- **How much room a panel takes** is up to `$page.layout`. The content area is the page, at most 1280px wide, minus the nav sidebar:
186
+ Navigating faster than the shell can settle is fine: closing travels through the browser's history, so it takes a moment to land, and anything asked for in the meantime waits for it rather than being dropped. Two quick Escapes (or back gestures) peel two panels, each aimed at the stack the one before it was heading for.
171
187
 
172
- | `layout` | How wide the panel gets | Good for |
188
+ **Every panel must work at 360–540px**, because that is what it gets whenever two columns fit. `$panel.maxWidth` says how much *more* it can usefully take. The content area is the page, at most 1280px wide, minus the nav sidebar:
189
+
190
+ | `maxWidth` | How wide the panel gets | Good for |
173
191
  | --- | --- | --- |
174
- | `"small"` | 360 to 540px once two fit side by side. Below that, the whole content area (so up to ~730px). | lists, detail forms, anything that reads well at phone width |
175
- | `"medium"` (default) | The whole content area: up to ~1100px, and the screen width on a phone. | ordinary screens; the safe default |
176
- | `"large"` | The whole window, with no upper limit: ~1750px on a 1920px screen. | boards, wide tables, dense dashboards |
192
+ | `"half"` | Half the content area: 360 to 540px. | lists, detail forms — anything that reads well at phone width |
193
+ | `"full"` (default) | The whole content area: up to ~1100px. | ordinary screens; the safe default |
194
+ | `"screen"` | The whole window, no upper limit: ~1750px on a 1920px screen. | boards, wide tables, dense dashboards |
195
+
196
+ Below the width two columns need, everything takes the whole content area whatever it asked for. Those numbers assume a nav sidebar of around 170px; without one, add that back. Nothing fits beside a `"full"` on a standard 1280px page, but on a wide enough window a `"half"` still can, and the page grows past 1280px to hold both.
197
+
198
+ A column's width depends only on the size of the window, never on what else is open. So opening or closing a panel never resizes the ones already on screen, and never reflows what someone was reading. A lone `"half"` leaves its other half empty, and that is exactly where the next one lands. When more columns fit than the standard 1280px page holds (three halves, say), the page itself grows, staying centred, to hold them.
199
+
200
+ Columns tile that area, separated by a hairline and no gutter — a column brings its own padding, so their contents stay comfortably apart regardless.
201
+
202
+ The panel is sized before your handler runs, and `$panel.width` is the resolved figure in pixels — so a chart, a virtualised list or a column count has the real width from the first frame, with nothing to measure. Set `maxWidth` at the top of your handler and you draw at the new width; set it later and the panel reflows without being redrawn, so nothing in it is rebuilt or loses its state.
203
+
204
+ <a id="chrome"></a>
205
+
206
+ **A panel declares its chrome; the shell places it.** A screen says what it is called and what it can do; everything else in its column — headings, cards, boxes — is the screen's own content, drawn like any other. Where the chrome ends up depends on how many columns are showing and how wide the shell is, so the shell decides:
207
+
208
+ ```ts
209
+ function drawTask($panel: S.Panel<{ taskId: number }>) {
210
+ $panel.title = "Task 42";
211
+ $panel.actions = () => S.button({ content: "Save", attrs: ".small", click: save });
212
+ S.box({ header: "Task 42", content: drawTaskForm }); // ordinary content
213
+ }
214
+ ```
215
+
216
+ On a wide screen the title becomes the stack's last crumb and the Save button sits in a quiet strip at the top of the column. On a phone the crumb is still there and Save moves into the top bar, where the app menu was. Nothing in your code measures the viewport, and no screen is written twice.
217
+
218
+ **The breadcrumbs are the navigation.** The top bar's second line writes the open panels out as breadcrumbs — `Projects / Trackle / Task 42` — with the panels currently on screen in bold. Clicking an earlier crumb goes back to it *without closing anything*: the panels right of it stay open, parked just past the viewport's right edge, and clicking their crumbs brings them back. Browsing the stack is free — it's opening a *new* panel that closes the panels after the one it came from. The app's name and logo link to the app's home (the `home` option, `/` by default), going back to it when it's already open and opening it when it isn't. A stack too long for the bar scrolls sideways, in an `S.scrollStrip` like the tab strip's.
219
+
220
+ That line is the `subtitle`'s while the stack has nothing to add: one panel open, reachable from a nav item that is already highlighted in a visible sidebar. Otherwise the stack takes it, since it is then the only thing naming the screen.
221
+
222
+ Right-click (or long-press) a crumb for **Close** — which takes just that panel out, wherever it sits in the stack — and **Pin**. A pinned panel — its crumb wears a pin — never closes as a side effect of navigation elsewhere: where opening a new panel would prune it, it rides along beneath the new panel instead, one crumb click away. Pin the reference you keep coming back to, then navigate freely. An *explicit* close (Escape, `close()`, the crumb menu, `data-panel=replace`) still closes it, and it's yours from code as `$panel.pinned`. Because a crumb is a real link whose right-click the menu takes over, the menu also offers **Open in new tab** and **Copy link**.
223
+
224
+ A crumb can also wear a **●**: the panel holds unsaved work, and nothing will close it (see `$panel.unsaved` below).
177
225
 
178
- Those numbers assume a nav sidebar of around 170px; without a sidebar, add that back (a medium then reaches the full 1280px). Nothing fits beside a medium on a standard 1280px page, but on a wide enough window a small still can, and the page grows past 1280px to hold both.
226
+ | `$panel` | what it does |
227
+ | --- | --- |
228
+ | `title` | Names the screen: its breadcrumb, and `document.title` while it's the current panel. A panel that sets none borrows the first line of text in its own body — good enough for a crumb, but say it yourself. |
229
+ | `actions` | The screen's buttons or menu. In the column's chrome while several columns fit; in the top bar (taking the app `menu`'s place) once the shell is narrow. |
179
230
 
180
- A panel's width depends only on the size of the window, never on what else is open. So opening or closing a panel never resizes the ones already on screen, and never reflows what someone was reading. A lone small leaves its other half empty, and that is exactly where the next small lands. When more columns fit than the standard 1280px page holds (three smalls, say), the page itself grows, staying centred, to hold them.
231
+ Two deliberate rules there. `actions` are the screen's *verbs* — Save, Delete, Share, a menu — not a second way out: going back is the crumbs' job, at every width, and there is no back button even on a phone. And **`title` names the screen; it does not draw a heading** — a screen that wants its name in its own body writes it there, where it owns the typography.
181
232
 
182
- The panel is sized before your handler runs, so anything inside it that measures its own box — a chart, a virtualised list, a column count — gets a real one from the first frame rather than a zero-width one. A new panel starts at whatever `layout` says at that point, which is the default, so a handler that *assigns* `layout` is drawn at the medium width and reflowed immediately after. Assigning it later works too: the panel reflows to its new width without being redrawn, so nothing in it is rebuilt or loses its state, and the columns beside it move over.
233
+ A column's body keeps a comfortable `$3` of padding; a screen that wants edge-to-edge rows just writes `A("p:0")`, since the draw function's current element *is* the body.
183
234
 
184
- **The rest of `$page`:**
235
+ **The rest of `$panel`:**
185
236
 
186
237
  - `params` and `path`: read-only.
187
- - `title`: shown in `document.title` while this panel is the top one.
188
- - `layout`: as above, and live — set it whenever you like and the panel reflows.
238
+ - `maxWidth`: as above, and live — set it whenever you like and the panel reflows.
189
239
  - `loading`: set it while you're fetching. A new panel waits a moment before sliding in, so it can arrive with real content instead of empty, and shows a loading indicator if the wait drags on.
190
- - `close()`: closes this panel, wherever it sits in the stack.
191
- - `requestClose`: your chance to say no. Everything that would close the panel waits for it: Escape, the panel's own ✕ or Cancel button, the browser's back button, a link that would close it, `S.panels.close()`. Return `false` to keep the panel open.
240
+ - `width` and `visible`: read-only and reactive. `width` is this column's width in pixels, for the rare content that genuinely differs by width. `visible` says whether this panel is on screen — not crowded out, not parked, not closing — which is the right question for per-panel floating UI like a FAB, since "am I the current panel?" answers wrongly when two columns are up.
241
+ - `pinned`: the crumb menu's Pin, from code.
242
+ - `unsaved`: set it while the panel holds work that must not be lost — a dirty form, an upload in flight. An unsaved panel **cannot be closed, by anything**: navigation and the back button park it instead (wearing a ● in its crumb), `close()` and the crumb menu's Close refuse, Escape steps left, and closing the browser tab runs into the browser's own are-you-sure. The tab title carries a leading `•` while *any* open panel is unsaved. Only the app clears the flag, which is its explicit "this is now discardable":
192
243
 
193
244
  ```ts
194
- $page.requestClose = async () => !$task.dirty || await S.confirm("Discard unsaved changes?");
245
+ A(() => { $panel.unsaved = $form.dirty || undefined; }); // the whole dirty check
246
+
247
+ S.button({ content: "Discard", attrs: ".neutral", click: () => {
248
+ $panel.unsaved = false; // explicitly: the reactive scope above reruns too late
249
+ void $panel.close();
250
+ }});
195
251
  ```
196
252
 
197
- **Every panel provides its own way out.** Staffa draws no back arrows and no ✕ of its own, because a panel knows better than the shell does what leaving it should look like: Cancel and Save buttons, or a ✕ in the corner of a box. So say it yourself:
253
+ So a panel that can *be* unsaved needs its own way out — a Save or Discard among its `actions`. There is no "discard changes?" dialog anywhere: leaving is never blocked, the work just waits, parked, one crumb away.
254
+
255
+ - `close()`: closes this panel, wherever it sits in the stack (refused while it's `unsaved`). Behind a Cancel button, or a Save that closes:
198
256
 
199
257
  ```ts
200
- S.box({ header: "Task 42", close: true, content: drawTask }); // a ✕ in the box's corner
201
- S.button({ content: "Cancel", attrs: ".neutral", click: () => $page.close() });
202
- S.panels.close(); // the top panel
203
- S.panels.close("/projects/7"); // that panel, wherever it is
258
+ S.button({ content: "Cancel", attrs: ".neutral", click: () => $panel.close() });
259
+ $panel.stack.closePanel(); // the current panel
260
+ $panel.stack.closePanel("/projects/7"); // that panel, wherever it is
204
261
  ```
205
262
 
206
- `S.box`'s `close: true` works out for itself which panel it's in, so the same code closes the right thing whether it's one column of several or a whole phone screen. (Pass a function instead if you'd rather do something else.)
207
-
208
- Closing the top panel goes back to whatever was underneath it. Closing one that *isn't* on top takes just that one away: the columns to its right stay where they are and keep their state, and the URL doesn't change, because the top panel didn't move. Either way it becomes a history entry, so the browser's back button brings the panel back.
263
+ Closing the current panel hands the focus to the panel on its left. Closing one that *isn't* current takes just that one away: the columns around it stay where they are and keep their state, and the URL doesn't change, because the current panel didn't move. Either way it becomes a history entry, so the browser's back button brings the panel back.
209
264
 
210
265
  A closed panel is torn down at once: its `A.clean()` hooks run the moment it closes, so subscriptions, timers and requests stop there and then. Only its element hangs around, inert and frozen, for the length of the exit animation.
211
266
 
212
- Staffa itself contributes two things: the Escape key, which closes the top panel (and jumps to the navigation once you're at the bottom of the stack), and making the browser's back button do the right thing. Both ask `requestClose` first.
267
+ Escape steps one panel back along the stack: at the stack's end that closes the current panel, mid-stack it just moves left and parks the panel you leave, and at the stack's start it jumps to the navigation. The browser's back button replays whole arrangements — it re-opens what a navigation closed and re-parks what a crumb click brought back.
213
268
 
214
269
  <a id="ancestors"></a>
215
270
 
216
- **The back button, and links from elsewhere.** The URL holds the top panel; the rest of the stack is stored beside it in the browser's history entry. So back and forward step through whole arrangements of columns, and a reload brings the same columns back.
271
+ **The back button, and links from elsewhere.** The URL holds the current panel; the rest of the stack — the panels before it, any parked after it, and which are pinned — is stored beside it in the browser's history entry. So back and forward step through whole arrangements of columns, and a reload brings the same columns back.
217
272
 
218
- A URL that arrives without any of that (a shared link, a bookmark, a new tab) has nothing to restore, so Staffa builds the stack from the path: it walks the parent paths and opens each one you have a route for. With the routes above, `/projects/7/tasks/42` opens as three panels: the project list, project 7, and task 42. A parent path you have no route for is skipped, so if you don't want one screen appearing under another, just don't give it a route.
273
+ A URL that arrives without any of that (a shared link, a bookmark, a new tab) has nothing to restore, so Staffa builds the stack from the path: it walks the parent paths and opens each one you have a route for. With the routes above, `/projects/7/tasks/42` opens as three columns: the project list, project 7, and task 42. A parent path you have no route for is skipped, so if you don't want one screen appearing under another, just don't give it a route.
219
274
 
220
275
  That only works for URLs that spell their own context out. A flat one — `/thread/[id]`, where a push notification lands — has no parent path to walk, so it would open as a lone column with nothing beneath it and nothing for Escape to do. `ancestors` is where you say what belongs under it. It's keyed by the same path templates as `routes`, so each entry gets that key's params, matched and typed:
221
276
 
@@ -233,17 +288,17 @@ S.main({
233
288
 
234
289
  Return the paths shallowest first, or nothing to leave that path to the parent-path walk — which is also what a route you don't list gets, so you only name the ones whose URL doesn't say where they belong. It's asked for every navigation that has no panel to build on, so a nav item and a fresh tab still agree.
235
290
 
236
- It has to answer without drawing anything, which is why it lives here rather than on `$page`: the panels being replaced are asked their `requestClose` *before* the navigation is applied, and that is before any route handler could have run.
291
+ It has to answer without drawing anything, which is why it lives here rather than on `$panel`: it's consulted while the navigation is still being worked out, before any route handler has run.
237
292
 
238
- From code, `S.panels.open(path, beneath?)` opens the same kind of arrangement, either asking `ancestors` for the stack or taking the one you hand it.
293
+ From code, `openPanelStack(path, beneath?)` opens the same kind of arrangement, either asking `ancestors` for the panels beneath or taking the ones you hand it.
239
294
 
240
- Search params and the `#hash` belong to the top panel only. Anything a panel deeper in the stack needs in order to redraw itself has to live in its path.
295
+ Search params and the `#hash` belong to the current panel only. Anything another panel in the stack needs in order to redraw itself has to live in its path. (A panel you browse away from does get its search and hash back when a crumb makes it current again.)
241
296
 
242
297
  **A few more things.**
243
298
 
244
- - `stacking: false` shows only the top panel, however wide the screen. Everything else behaves the same: the URL, the back button, `requestClose`, and the panels' own close buttons.
245
- - Only one routed `S.main()` can be mounted at a time; a second one throws. That's what lets `S.panels` be a plain module-level object. Each handler still gets its own `$page` rather than there being one global "current page", since several panels are alive at once.
246
- - Navigating with `aberdeen/route`'s own `go()` works and still asks `requestClose`, but, like a link from outside a panel, it builds the whole stack from the path. So prefer `S.panels`. If your app registered its own navigation guard before mounting (an auth redirect, say), it keeps working: Staffa asks it first, and puts it back when the shell goes away.
299
+ - `stacking: false` shows only the current panel, however wide the screen. Everything else behaves the same: the URL, the back button, unsaved panels, and the panels' own close buttons.
300
+ - Only one routed `S.main()` can be mounted at a time; a second one throws — the URL is global, so two of them would fight over it. Nothing else is global: the stack belongs to its shell, and each handler gets its own `$panel`, since several panels are alive at once.
301
+ - Navigating with `aberdeen/route`'s own `go()` works — an unsaved panel survives it too — but, like a link from outside a panel, it builds the whole stack from the path. So prefer the stack's own methods. A navigation guard your app registered with `route.setGuard` (an auth redirect, say) keeps working untouched: Staffa registers none of its own.
247
302
  - Deep links need your static server to serve the app for unknown paths (the usual SPA fallback). For `http-server` that's `-P`, as in the demo command below.
248
303
 
249
304
  ### CSS reset
@@ -298,9 +353,10 @@ Components share naming conventions for options: `attrs` (outermost element), `c
298
353
 
299
354
  ### Layout & containers
300
355
 
301
- - **`S.main(opts)`**: app shell, a sticky header with `icon`, `title`, `subtitle`, `menu`; scrollable content area; footer. Set `maxWidth` to center the content. Give it a `nav` for a sidebar that collapses to a hamburger below 640 px — where the nav becomes a full page sliding in from the left, handing over to the chosen screen with a matching slide in from the right. Its `items` may be a reactive array; adding or removing one redraws just the sidebar, never the content beside it. A navigation dismisses the collapsed nav by itself, links in your own custom rows included; `S.closeNav()` does it for the rows that *don't* navigate. Instead of a single `content` slot it can take a `routes` table — see [Panel-stack navigation](#panel-stack-navigation).
302
- - **`S.box(opts | content)`**: surface with optional `header`/`footer` and padded body. Pass a function for shorthand `{ content }`. `close: true` adds a ✕ that closes the panel the box is in (see [Panel-stack navigation](#panel-stack-navigation)); `close: fn` runs your own dismissal.
303
- - **`S.tabs(opts)`**: tablist with live panels and keyboard navigation. More tabs than fit make the strip scroll, with a ‹ / › button appearing at whichever end still has something to reach — so it's not just a swipe target. Selecting a tab any other way (the arrow keys, a `bind` written from elsewhere) scrolls it into view.
356
+ - **`S.main(opts)`**: app shell, a sticky header with `logo`, `title`, `subtitle`, `menu` — plus, in routed mode, the breadcrumbs of the open panels; scrollable content area; footer. Set `maxWidth` to center the content. Give it a `nav` for a sidebar that collapses to a hamburger below 640 px — where the nav becomes a full page sliding in from the left, handing over to the chosen screen with a matching slide in from the right. Its `items` may be a reactive array; adding or removing one redraws just the sidebar, never the content beside it. An item with `items` of its own becomes a collapsible submenu: only the branch holding the current page stays unfolded, and clicking a branch selects its first leaf (expanding a branch doesn't dismiss the phone's full-page nav — only picking a leaf does). A sidebar taller than the window scrolls, and follows the highlighted item: navigating to a page whose item sits past the fold scrolls it back into view. A navigation dismisses the collapsed nav by itself, links in your own custom rows included; `S.closeNav()` does it for the rows that *don't* navigate. Instead of a single `content` slot it can take a `routes` table — see [Panel-stack navigation](#panel-stack-navigation).
357
+ - **`S.box(opts | content)`**: surface with optional `header`/`footer` and padded body. Pass a function for shorthand `{ content }`. `close: fn` adds a ✕ that runs your dismissal — in the header row, or floating over the body when there is no header. (It is plain furniture: a routed screen gets its own way out from the shell, see [Panel-declared chrome](#chrome).)
358
+ - **`S.tabs(opts)`**: tablist with live tab panels and keyboard navigation. More tabs than fit make the strip scroll (see `S.scrollStrip`); selecting a tab any other way (the arrow keys, a `bind` written from elsewhere) scrolls it into view.
359
+ - **`S.scrollStrip(opts)`**: a horizontal row that scrolls once its content outgrows it, with a ‹ / › button appearing over whichever end still has something to reach — so it isn't just a swipe target. Its own scrollbar is hidden. `S.tabs` and the routed shell's breadcrumbs are built on it; reach for it for any row of chrome that can outgrow its space. `S.revealInStrip(el)` scrolls one of its children into view.
304
360
  - **`S.form(opts | content)`**: form aligning fields in a column or responsive grid, with an `actions` bar. Prevents the default page reload.
305
361
 
306
362
  ### Form fields
@@ -319,6 +375,7 @@ Components share naming conventions for options: `attrs` (outermost element), `c
319
375
  ### Actions
320
376
 
321
377
  - **`S.button(opts | text)`**: button surface; restyle via `attrs` (e.g. `.danger`, `.outlined`), plus `size`, `disabled`, `icon`, `href` (renders `<a role=button>`). Defaults to filled `.primary`.
378
+ - **`S.iconButton(opts)`**: a bare glyph in a square hit area — no fill, no border, ink that lifts on hover. For chrome that mustn't compete with what it sits beside: the app shell's ✕ and ☰ are made of it, and it's usually what a page's `actions` want.
322
379
  - **`S.buttonGroup(opts)`**: groups buttons, `attached` (segmented) or `spaced`.
323
380
  - **`S.buttonChooser(opts)`**: single-select segmented control bound to a value.
324
381
 
@@ -341,6 +398,7 @@ Options: `size`, `color` (defaults to `currentColor`), `strokeWidth`, `cap`, `jo
341
398
  ### Other
342
399
 
343
400
  - **`S.menuButton(opts)` / `S.addContextMenu(opts)` / `S.showFloatingMenu(opts)`**: dropdown menus from a button, right-click/long-press context menus, and the underlying floating menu primitive — with keyboard navigation. A menu closes itself when the page navigates.
401
+ - **`S.menu(opts)`**: the same menu rows drawn in place — for a nav or settings column of your own. Items with nested `items` form a collapsible tree; `onLeafSelect` fires only when a leaf is picked, never for a branch unfolding.
344
402
  - **`S.closeNav()`**: dismisses `S.main`'s navigation when it's showing as an overlay (the full page on a phone, the dropdown on a wider screen). For custom nav rows that act without navigating.
345
403
  - **`S.toast(opts)`**: transient notification at the bottom of the viewport.
346
404
  - **`S.addTooltip(el, opts)`**: tooltip on hover, attached to an existing element.
@@ -487,10 +545,22 @@ Options for `box`.
487
545
  A button. Tonal and outlined variants show a border; filled variants rely on
488
546
  their solid background for affordance.
489
547
 
548
+ ## [iconButton](iconButton.md) · function
549
+
550
+ A bare glyph in a square hit area — no fill, no border, just ink that lifts on
551
+ hover. The quiet end of the button family, for chrome that has to sit beside
552
+ something more important without competing with it: a ✕ on a box, the ☰ a
553
+ routed `S.main()` puts in its top bar, the verbs in a
554
+ | page's actions.
555
+
490
556
  ## [ButtonOptions](ButtonOptions.md) · interface
491
557
 
492
558
  Options for `button`.
493
559
 
560
+ ## [IconButtonOptions](IconButtonOptions.md) · interface
561
+
562
+ Options for `iconButton`.
563
+
494
564
  ## [buttonChooser](buttonChooser.md) · function
495
565
 
496
566
  A single-selection segmented control: an attached button group where exactly
@@ -532,30 +602,30 @@ Options for `form`.
532
602
  ## [main](main.md) · function
533
603
 
534
604
  An application shell that wires up the things almost every app needs: a sticky
535
- top bar (icon, title, subtitle, action menu), a scrollable content area, and a
605
+ top bar (logo, title, action menu), a scrollable content area, and a
536
606
  footer. With `MainOptions.maxWidth` the content area is centred and its
537
- width capped. Add a `nav` to get a responsive sidebar (auto-collapses to a
538
- menu button below 640 px, or always a button with `navPosition: "button"`).
539
- Below 640 px that button opens the nav as a full page sliding in from the
607
+ width capped. Add a `nav` to get a sidebar that collapses to a ☰ in the top bar
608
+ below 640 px, which there opens the nav as a full panel sliding in from the
540
609
  left; picking an item slides it away as the chosen screen enters from the
541
610
  right.
542
611
 
543
612
  ## [closeNav](closeNav.md) · function
544
613
 
545
- Close the navigation, if it's showing as an overlay: the full page it becomes
546
- on a narrow shell, or the dropdown its button opens on a wider one. A sidebar
547
- isn't an overlay and has nothing to dismiss, so there it does nothing.
614
+ Close the navigation, if it's showing as an overlay — the full panel it becomes
615
+ on a narrow shell. A sidebar isn't an overlay and has nothing to dismiss, so
616
+ on a wider shell this does nothing.
548
617
 
549
618
  ## [MainOptions](MainOptions.md) · interface
550
619
 
551
620
  Options for `main`.
552
621
 
553
- ## [panels](panels.md) · constant
622
+ ## [PanelStack](PanelStack.md) · interface
554
623
 
555
- Navigating the routed `S.main()` shell from code, for the times it isn't a
556
- link click, such as opening the screen for a record you just created.
624
+ The panel stack behind a routed `S.main()`, and what that call hands back:
625
+ the open `Panel`s, which of them is current, and the four ways to
626
+ change that. Everything on it is scoped to its own shell.
557
627
 
558
- ## [Page](Page.md) · interface
628
+ ## [Panel](Panel.md) · interface
559
629
 
560
630
  What a route handler gets: the params from its route, plus everything the
561
631
  shell needs to know about the panel it is drawing. It's an Aberdeen proxy, so
@@ -566,23 +636,23 @@ you can set things later, such as a `title` that arrives with your data or
566
636
 
567
637
  A route table: path templates mapped to panel draw functions. Used as the
568
638
  loose (non-inferred) type; `S.main()` infers a more precise type from the
569
- literal you pass, so each handler's `$page.params` is typed per its key.
639
+ literal you pass, so each handler's `$panel.params` is typed per its key.
570
640
 
571
641
  **Type:** `Record<string, RouteHandler>`
572
642
 
573
643
  ## RouteHandler · type
574
644
 
575
- A panel draw function: it receives the panel's `Page` and draws into the current scope.
645
+ A panel draw function: it receives the panel's `Panel` and draws into the current scope.
576
646
 
577
- **Type:** `(page: Page<P>) => void`
647
+ **Type:** `(panel: Panel<P>) => void`
578
648
 
579
649
  ## RouteTable · type
580
650
 
581
651
  The shape `S.main()`'s `routes` option is checked against: every key types its
582
652
  own handler's `params`. Used as a self-referential generic constraint, which
583
- is what makes `$page.params` infer from the route key.
653
+ is what makes `$panel.params` infer from the route key.
584
654
 
585
- **Type:** `{ [K in keyof R & string]: (page: Page<Prettify<PathParams<K>>>) => void }`
655
+ **Type:** `{ [K in keyof R & string]: (panel: Panel<Prettify<PathParams<K>>>) => void }`
586
656
 
587
657
  ## AncestorsHandler · type
588
658
 
@@ -610,6 +680,16 @@ The params object described by a path template, e.g.
610
680
  The params contributed by a single path-template segment: `[x]` a string,
611
681
  `[x=integer]` a number, `[...x]` the rest of the path as one raw string.
612
682
 
683
+ ## [menu](menu.md) · function
684
+
685
+ A menu drawn in place: the same list of rows the floating dropdown and
686
+ `S.main()`'s sidebar are made of, as a plain component — for a nav of your
687
+ own, a settings column, a sidebar the shell doesn't draw for you. Items are
688
+ real links/buttons with arrow-key navigation, `href` items highlight
689
+ themselves on the current page, and an item with `items` of its own becomes
690
+ a collapsible branch (see `MenuItem.items`): only the branch holding
691
+ the current page stays unfolded.
692
+
613
693
  ## [menuButton](menuButton.md) · function
614
694
 
615
695
  A button that opens a | floating dropdown menu on
@@ -648,6 +728,10 @@ menu can't steal someone else's.
648
728
 
649
729
  - `anchor?: HTMLElement`
650
730
 
731
+ ## [MenuListOptions](MenuListOptions.md) · interface
732
+
733
+ Options for `menu`.
734
+
651
735
  ## [MenuOptions](MenuOptions.md) · interface
652
736
 
653
737
  Options for `menuButton` and `MainOptions.nav`.
@@ -738,6 +822,26 @@ A selectable option: a bare string, or a `{ value, label }` pair.
738
822
  A tabbed view. Renders an ARIA `tablist` of buttons and a single live panel
739
823
  for the selected tab. Supports keyboard navigation (left/right/home/end).
740
824
 
825
+ ## [scrollStrip](scrollStrip.md) · function
826
+
827
+ A horizontal row that scrolls when its content outgrows it, with a ‹ / ›
828
+ button appearing over whichever end still has something left to reach — a
829
+ bare scroll area says nothing about itself to a mouse, and a scrollbar under
830
+ a row of chrome reads as a mistake. The row's own scrollbar is hidden, and
831
+ the buttons scroll it by most of a width at a time.
832
+
833
+ ## revealInStrip · function
834
+
835
+ Scroll `el`'s `scrollStrip` just far enough to bring it into view,
836
+ clearing the buttons that overlay the row's ends. Does nothing when `el`
837
+ isn't in a strip, or is already comfortably visible.
838
+
839
+ **Signature:** `(el: HTMLElement) => void`
840
+
841
+ **Parameters:**
842
+
843
+ - `el: HTMLElement`
844
+
741
845
  ## [Tab](Tab.md) · interface
742
846
 
743
847
  A single tab definition.
@@ -746,6 +850,10 @@ A single tab definition.
746
850
 
747
851
  Options for `tabs`.
748
852
 
853
+ ## [ScrollStripOptions](ScrollStripOptions.md) · interface
854
+
855
+ Options for `scrollStrip`.
856
+
749
857
  ## [textarea](textarea.md) · function
750
858
 
751
859
  A multi-line text input. Shares the field chrome and styling of
@@ -0,0 +1,21 @@
1
+ ## ScrollStripOptions · interface
2
+
3
+ Options for `scrollStrip`.
4
+
5
+ ### scrollStripOptions.content · member
6
+
7
+ The row's content, laid out left to right.
8
+
9
+ **Type:** `Slot`
10
+
11
+ ### scrollStripOptions.attrs · member
12
+
13
+ Aberdeen attr/style string applied to the outer element.
14
+
15
+ **Type:** `string`
16
+
17
+ ### scrollStripOptions.stripAttrs · member
18
+
19
+ Aberdeen attr/style string applied to the scrolling row itself.
20
+
21
+ **Type:** `string`
package/skill/box.md CHANGED
@@ -9,9 +9,6 @@ out as a flex container.
9
9
 
10
10
  Shortcut: pass a function to use it directly as the body content.
11
11
 
12
- | `close: true` adds a ✕ that closes the panel the box
13
- is drawn in: the usual way back out of a screen in a routed `S.main()`.
14
-
15
12
  **Signature:** `(opts?: BoxOptions | Slot) => void`
16
13
 
17
14
  **Parameters:**
@@ -26,5 +23,5 @@ S.box({ header: "Profile", contentAttrs: "display:flex flex-direction:column", c
26
23
  S.textline({ label: "Name", bind: A.ref($user, "name") });
27
24
  }});
28
25
  S.box(() => A("p#Just some content")); // shorthand
29
- S.box({ header: "Task 42", close: true, content: drawTask }); // ✕ closes this panel
26
+ S.box({ header: "Draft", close: () => discard(), content: drawDraft }); // ✕ runs discard()
30
27
  ```
package/skill/closeNav.md CHANGED
@@ -1,8 +1,8 @@
1
1
  ## closeNav · function
2
2
 
3
- Close the navigation, if it's showing as an overlay: the full page it becomes
4
- on a narrow shell, or the dropdown its button opens on a wider one. A sidebar
5
- isn't an overlay and has nothing to dismiss, so there it does nothing.
3
+ Close the navigation, if it's showing as an overlay — the full panel it becomes
4
+ on a narrow shell. A sidebar isn't an overlay and has nothing to dismiss, so
5
+ on a wider shell this does nothing.
6
6
 
7
7
  A navigation closes the nav by itself, links in your own custom rows included,
8
8
  so this is for the items that *don't* navigate — one that opens a dialog, or
@@ -0,0 +1,27 @@
1
+ ## iconButton · function
2
+
3
+ A bare glyph in a square hit area — no fill, no border, just ink that lifts on
4
+ hover. The quiet end of the button family, for chrome that has to sit beside
5
+ something more important without competing with it: a ✕ on a box, the ☰ a
6
+ routed `S.main()` puts in its top bar, the verbs in a
7
+ | page's actions.
8
+
9
+ Reach for `button` instead whenever the thing has a name worth reading;
10
+ an icon alone is only unambiguous for a handful of universal actions.
11
+
12
+ **Signature:** `(opts: IconButtonOptions) => void`
13
+
14
+ **Parameters:**
15
+
16
+ - `opts: IconButtonOptions`
17
+
18
+ **Examples:**
19
+
20
+ ```ts
21
+ import { trash2, share2 } from "staffa/icons";
22
+
23
+ $panel.actions = () => {
24
+ S.iconButton({ icon: share2, ariaLabel: "Share", click: share });
25
+ S.iconButton({ icon: trash2, ariaLabel: "Delete", click: del, attrs: "fg:$s-danger" });
26
+ };
27
+ ```
package/skill/main.md CHANGED
@@ -1,20 +1,24 @@
1
1
  ## main · function
2
2
 
3
3
  An application shell that wires up the things almost every app needs: a sticky
4
- top bar (icon, title, subtitle, action menu), a scrollable content area, and a
4
+ top bar (logo, title, action menu), a scrollable content area, and a
5
5
  footer. With `MainOptions.maxWidth` the content area is centred and its
6
- width capped. Add a `nav` to get a responsive sidebar (auto-collapses to a
7
- menu button below 640 px, or always a button with `navPosition: "button"`).
8
- Below 640 px that button opens the nav as a full page sliding in from the
6
+ width capped. Add a `nav` to get a sidebar that collapses to a ☰ in the top bar
7
+ below 640 px, which there opens the nav as a full panel sliding in from the
9
8
  left; picking an item slides it away as the chosen screen enters from the
10
9
  right.
11
10
 
12
11
  Instead of a single `content` slot, pass `MainOptions.routes` and the
13
12
  shell takes over navigation: each route draws one screen, called a panel,
14
- and as many panels as fit are shown at a time, side by side on a wide screen
15
- and one at a time on a phone. See `MainOptions.routes` and `Page`.
13
+ and as many columns as fit are shown at a time, side by side on a wide screen
14
+ and one at a time on a phone. Each panel *declares* its chrome — its
15
+ `Panel.title` and its `Panel.actions` — and this shell places it:
16
+ the stack of titles as breadcrumbs in the bar, the actions on the panel's
17
+ column while several fit and in the bar once the shell is narrow enough
18
+ that the current panel is the whole screen. See `MainOptions.routes` and
19
+ `Panel`.
16
20
 
17
- **Signature:** `<R extends RouteTable<R>>(opts?: MainOptions<R>) => void`
21
+ **Signature:** `{ <R extends RouteTable<R>>(opts: MainOptions<R> & { routes: object; }): PanelStack; (opts?: MainOptions<{}> & { routes?: undefined; }): void; }`
18
22
 
19
23
  **Type Parameters:**
20
24
 
@@ -22,13 +26,13 @@ and one at a time on a phone. See `MainOptions.routes` and `Page`.
22
26
 
23
27
  **Parameters:**
24
28
 
25
- - `opts: MainOptions<R>` (optional)
29
+ - `opts: MainOptions<R> & { routes: object }`
26
30
 
27
31
  **Examples:**
28
32
 
29
33
  ```ts
30
34
  S.main({
31
- icon: "✦",
35
+ logo: "✦",
32
36
  title: "Staffa Demo",
33
37
  maxWidth: "56rem",
34
38
  nav: {
package/skill/menu.md ADDED
@@ -0,0 +1,29 @@
1
+ ## menu · function
2
+
3
+ A menu drawn in place: the same list of rows the floating dropdown and
4
+ `S.main()`'s sidebar are made of, as a plain component — for a nav of your
5
+ own, a settings column, a sidebar the shell doesn't draw for you. Items are
6
+ real links/buttons with arrow-key navigation, `href` items highlight
7
+ themselves on the current page, and an item with `items` of its own becomes
8
+ a collapsible branch (see `MenuItem.items`): only the branch holding
9
+ the current page stays unfolded.
10
+
11
+ **Signature:** `(opts: MenuListOptions) => void`
12
+
13
+ **Parameters:**
14
+
15
+ - `opts: MenuListOptions`
16
+
17
+ **Examples:**
18
+
19
+ ```ts
20
+ S.menu({
21
+ items: [
22
+ { label: "Overview", href: "/docs" },
23
+ { label: "Guides", items: [
24
+ { label: "Install", href: "/docs/install" },
25
+ { label: "Theming", href: "/docs/theming" },
26
+ ]},
27
+ ],
28
+ });
29
+ ```