staffa 0.9.0 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 +77 -14
  13. package/dist/components/menu.js +239 -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 +21 -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 +278 -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/README.md CHANGED
@@ -113,12 +113,12 @@ S.setDarkMode(undefined); // follow OS
113
113
 
114
114
  ### Panel-stack navigation
115
115
 
116
- 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.
116
+ 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**.
117
117
 
118
118
  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.
119
119
 
120
120
  ```ts
121
- S.main({
121
+ const shell = S.main({
122
122
  title: "Trackle",
123
123
  nav: { items: [{ label: "Projects", href: "/projects" }] },
124
124
  routes: {
@@ -126,18 +126,19 @@ S.main({
126
126
  "/projects/[projectId]": drawProject,
127
127
  "/projects/[projectId]/tasks/[taskId=integer]": drawProjectTask,
128
128
  },
129
- notFound: ($page) => S.box({ header: "Not found", content: $page.path }),
129
+ notFound: ($panel) => S.box({ header: "Not found", content: $panel.path }),
130
130
  });
131
131
 
132
- function drawProject($page: S.Page<{ projectId: string }>) {
133
- const { projectId } = $page.params; // typed from the route key
132
+ function drawProject($panel: S.Panel<{ projectId: string }>) {
133
+ const { projectId } = $panel.params; // typed from the route key
134
+ $panel.title = `Project ${projectId}`; // the shell puts it wherever it fits
134
135
  A(`a href=/projects/${projectId}/tasks/1 #Open the first task`);
135
136
  }
136
137
 
137
138
  // Etc..
138
139
  ```
139
140
 
140
- 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.
141
+ 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.
141
142
 
142
143
  **Route keys.** A segment wrapped in brackets is a param:
143
144
 
@@ -145,72 +146,126 @@ Each handler gets a `$page` object holding the params from its route, along with
145
146
  - `[name=integer]` matches one segment, as a number.
146
147
  - `[...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.
147
148
 
148
- 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`.
149
+ 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`.
149
150
 
150
- `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.
151
+ `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.
151
152
 
152
153
  `[...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.)
153
154
 
154
155
  **Navigating is just links.** Write ordinary `<a href="/...">` links; Staffa handles the clicks (so don't also call Aberdeen's `interceptLinks()`).
155
156
 
156
- - 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.
157
- - 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.
158
- - 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.
159
- - 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.
157
+ 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.
158
+
159
+ - 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.
160
+ - 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.
161
+ - 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.
162
+ - 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.
163
+
164
+ **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.
165
+
166
+ ```ts
167
+ shell.pushPanel(path); // on top of the current panel
168
+ shell.replacePanel(path); // in its place
169
+ shell.openPanelStack(path, beneath?); // a whole arrangement, the way a nav item does
170
+ shell.closePanel(path?); // the current panel, or a named one
171
+
172
+ shell.panels; // the open panels, oldest first — the Panel objects themselves
173
+ shell.currentPanelIndex; // which of them the URL is on
174
+ shell.currentPanel; // shorthand for panels[currentPanelIndex]
175
+ ```
176
+
177
+ 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.
160
178
 
161
- 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.
179
+ `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.
162
180
 
163
- 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.
181
+ 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.
164
182
 
165
- **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:
183
+ **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:
166
184
 
167
- | `layout` | How wide the panel gets | Good for |
185
+ | `maxWidth` | How wide the panel gets | Good for |
168
186
  | --- | --- | --- |
169
- | `"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 |
170
- | `"medium"` (default) | The whole content area: up to ~1100px, and the screen width on a phone. | ordinary screens; the safe default |
171
- | `"large"` | The whole window, with no upper limit: ~1750px on a 1920px screen. | boards, wide tables, dense dashboards |
187
+ | `"half"` | Half the content area: 360 to 540px. | lists, detail forms anything that reads well at phone width |
188
+ | `"full"` (default) | The whole content area: up to ~1100px. | ordinary screens; the safe default |
189
+ | `"screen"` | The whole window, no upper limit: ~1750px on a 1920px screen. | boards, wide tables, dense dashboards |
172
190
 
173
- 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.
191
+ 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.
174
192
 
175
- 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.
193
+ 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.
176
194
 
177
- 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.
195
+ Columns tile that area, separated by a hairline and no gutter — a column brings its own padding, so their contents stay comfortably apart regardless.
178
196
 
179
- **The rest of `$page`:**
197
+ 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.
198
+
199
+ <a id="chrome"></a>
200
+
201
+ **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:
202
+
203
+ ```ts
204
+ function drawTask($panel: S.Panel<{ taskId: number }>) {
205
+ $panel.title = "Task 42";
206
+ $panel.actions = () => S.button({ content: "Save", attrs: ".small", click: save });
207
+ S.box({ header: "Task 42", content: drawTaskForm }); // ordinary content
208
+ }
209
+ ```
210
+
211
+ 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.
212
+
213
+ **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.
214
+
215
+ 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.
216
+
217
+ 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**.
218
+
219
+ A crumb can also wear a **●**: the panel holds unsaved work, and nothing will close it (see `$panel.unsaved` below).
220
+
221
+ | `$panel` | what it does |
222
+ | --- | --- |
223
+ | `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. |
224
+ | `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. |
225
+
226
+ 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.
227
+
228
+ 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.
229
+
230
+ **The rest of `$panel`:**
180
231
 
181
232
  - `params` and `path`: read-only.
182
- - `title`: shown in `document.title` while this panel is the top one.
183
- - `layout`: as above, and live — set it whenever you like and the panel reflows.
233
+ - `maxWidth`: as above, and live set it whenever you like and the panel reflows.
184
234
  - `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.
185
- - `close()`: closes this panel, wherever it sits in the stack.
186
- - `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.
235
+ - `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.
236
+ - `pinned`: the crumb menu's Pin, from code.
237
+ - `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":
187
238
 
188
239
  ```ts
189
- $page.requestClose = async () => !$task.dirty || await S.confirm("Discard unsaved changes?");
240
+ A(() => { $panel.unsaved = $form.dirty || undefined; }); // the whole dirty check
241
+
242
+ S.button({ content: "Discard", attrs: ".neutral", click: () => {
243
+ $panel.unsaved = false; // explicitly: the reactive scope above reruns too late
244
+ void $panel.close();
245
+ }});
190
246
  ```
191
247
 
192
- **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:
248
+ 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.
249
+
250
+ - `close()`: closes this panel, wherever it sits in the stack (refused while it's `unsaved`). Behind a Cancel button, or a Save that closes:
193
251
 
194
252
  ```ts
195
- S.box({ header: "Task 42", close: true, content: drawTask }); // a ✕ in the box's corner
196
- S.button({ content: "Cancel", attrs: ".neutral", click: () => $page.close() });
197
- S.panels.close(); // the top panel
198
- S.panels.close("/projects/7"); // that panel, wherever it is
253
+ S.button({ content: "Cancel", attrs: ".neutral", click: () => $panel.close() });
254
+ $panel.stack.closePanel(); // the current panel
255
+ $panel.stack.closePanel("/projects/7"); // that panel, wherever it is
199
256
  ```
200
257
 
201
- `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.)
202
-
203
- 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.
258
+ 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.
204
259
 
205
260
  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.
206
261
 
207
- 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.
262
+ 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.
208
263
 
209
264
  <a id="ancestors"></a>
210
265
 
211
- **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.
266
+ **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.
212
267
 
213
- 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.
268
+ 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.
214
269
 
215
270
  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:
216
271
 
@@ -228,17 +283,17 @@ S.main({
228
283
 
229
284
  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.
230
285
 
231
- 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.
286
+ 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.
232
287
 
233
- 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.
288
+ 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.
234
289
 
235
- 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.
290
+ 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.)
236
291
 
237
292
  **A few more things.**
238
293
 
239
- - `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.
240
- - 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.
241
- - 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.
294
+ - `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.
295
+ - 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.
296
+ - 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.
242
297
  - 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.
243
298
 
244
299
  ### CSS reset
@@ -293,9 +348,10 @@ Components share naming conventions for options: `attrs` (outermost element), `c
293
348
 
294
349
  ### Layout & containers
295
350
 
296
- - **`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).
297
- - **`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.
298
- - **`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.
351
+ - **`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).
352
+ - **`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).)
353
+ - **`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.
354
+ - **`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.
299
355
  - **`S.form(opts | content)`**: form aligning fields in a column or responsive grid, with an `actions` bar. Prevents the default page reload.
300
356
 
301
357
  ### Form fields
@@ -314,6 +370,7 @@ Components share naming conventions for options: `attrs` (outermost element), `c
314
370
  ### Actions
315
371
 
316
372
  - **`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`.
373
+ - **`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.
317
374
  - **`S.buttonGroup(opts)`**: groups buttons, `attached` (segmented) or `spaced`.
318
375
  - **`S.buttonChooser(opts)`**: single-select segmented control bound to a value.
319
376
 
@@ -336,6 +393,7 @@ Options: `size`, `color` (defaults to `currentColor`), `strokeWidth`, `cap`, `jo
336
393
  ### Other
337
394
 
338
395
  - **`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.
396
+ - **`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.
339
397
  - **`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.
340
398
  - **`S.toast(opts)`**: transient notification at the bottom of the viewport.
341
399
  - **`S.addTooltip(el, opts)`**: tooltip on hover, attached to an existing element.
@@ -128,7 +128,7 @@ export function autocomplete(opts) {
128
128
  }
129
129
  });
130
130
  inputEl = A("input type=text role=combobox autocomplete=off", () => {
131
- A(`id=${id} aria-controls=${menuId} aria-autocomplete=list`);
131
+ A("id=", id, `aria-controls=${menuId} aria-autocomplete=list`);
132
132
  if (opts.placeholder != null)
133
133
  A("placeholder=", opts.placeholder);
134
134
  if (opts.disabled)
@@ -6,21 +6,16 @@ export interface BoxOptions extends ContentOptions {
6
6
  /** Footer content, drawn in a styled bar below the body. */
7
7
  footer?: Slot;
8
8
  /**
9
- * Draws a small ✕ button in the box's top-right corner: in the header row when
9
+ * Draws a small ✕ button in the box's top-right corner in the header row when
10
10
  * there is a {@link BoxOptions.header | header}, floating over the body when
11
- * there isn't.
11
+ * there isn't — and runs this when it's clicked.
12
12
  *
13
- * `true` closes the panel the box is drawn in, which is how a screen of a
14
- * routed `S.main()` gives the user a way back (the shell draws no back
15
- * arrows or of its own). Which panel that is gets worked out from the DOM
16
- * when it's clicked, so the box needs no `$page` handed to it and works from
17
- * any column, top of the stack or not. A box in a column further left closes
18
- * just that column and leaves the others alone. Outside a routed shell it
19
- * does nothing but warn.
20
- *
21
- * Pass a function to run that instead, for a dismissal of your own.
13
+ * It is plain furniture: a box that happens to sit in a page of a routed
14
+ * `S.main()` does **not** close that page the shell's breadcrumbs are the
15
+ * way out of those. Wire it to `$panel.close()` yourself if a box really is
16
+ * the whole page and wants its own ✕.
22
17
  */
23
- close?: boolean | (() => void);
18
+ close?: () => void;
24
19
  /** Aberdeen attr/style string applied to the body (content-holding) element. */
25
20
  contentAttrs?: Attributes;
26
21
  /** Aberdeen attr/style string applied to the header bar. */
@@ -38,9 +33,6 @@ export interface BoxOptions extends ContentOptions {
38
33
  *
39
34
  * Shortcut: pass a function to use it directly as the body content.
40
35
  *
41
- * {@link BoxOptions.close | `close: true`} adds a ✕ that closes the panel the box
42
- * is drawn in: the usual way back out of a screen in a routed `S.main()`.
43
- *
44
36
  * @example
45
37
  * ```ts
46
38
  * const $user = A.proxy({name: "Kvothe"});
@@ -48,7 +40,7 @@ export interface BoxOptions extends ContentOptions {
48
40
  * S.textline({ label: "Name", bind: A.ref($user, "name") });
49
41
  * }});
50
42
  * S.box(() => A("p#Just some content")); // shorthand
51
- * S.box({ header: "Task 42", close: true, content: drawTask }); // ✕ closes this panel
43
+ * S.box({ header: "Draft", close: () => discard(), content: drawDraft }); // ✕ runs discard()
52
44
  * ```
53
45
  */
54
46
  export declare function box(opts?: BoxOptions | Slot): void;
@@ -1,6 +1,7 @@
1
1
  import A from "aberdeen";
2
2
  import { drawSlot } from "../core.js";
3
- import { closeContainingPanel } from "./panels.js";
3
+ import { x as closeIcon } from "../icons.js";
4
+ import { iconButton } from "./button.js";
4
5
  // The box itself is a `.neutral` surface; its header/footer are `.neutral` surfaces
5
6
  // too — nested one level deeper, so they pick up the next elevation shade
6
7
  // automatically. Colours and borders come from the contextual tokens, so a box
@@ -18,15 +19,11 @@ A.insertGlobalCss({
18
19
  "> header": "display:flex align-items:center gap:$2 padding: $2 $3; border:0 border-bottom: 1px solid $s-faint; r:0 font-weight:600",
19
20
  "> footer": "display:flex align-items:center justify-content:flex-end gap:$2 padding: $2 $3; border:0 border-top: 1px solid $s-faint; r:0",
20
21
  "> div": "p:$3 gap:$3",
21
- // The ✕: quiet until you're near it, and drawn in the surface's own tokens
22
- // so it works on whatever the box was recoloured to. `margin-left:auto`
23
- // parks it at the far end of the header's flex row.
24
- ".s-box-close": "flex-shrink:0 margin-left:auto display:flex align-items:center justify-content:center " +
25
- "width:1.6rem height:1.6rem p:0 border:0 background:transparent cursor:pointer " +
26
- "fg:$s-muted font-size:0.95rem line-height:1 r:$s-radius-sm " +
27
- "transition: color 0.12s, background 0.12s;",
28
- ".s-box-close:hover": "fg:$s-text background: color-mix(in srgb, $s-text 8%, transparent);",
29
- // Without a header there is no row to sit in, so it floats over the body.
22
+ // The is an `S.iconButton` (see `drawCloseButton`); this only places it.
23
+ // In a header row it parks at the far end...
24
+ "> header > .s-box-close": "margin-left:auto",
25
+ // ...and without a header there is no row to sit in, so it floats over the
26
+ // body's top-right corner instead.
30
27
  "> .s-box-close": "position:absolute top:$2 right:$2 z-index:1",
31
28
  },
32
29
  });
@@ -40,9 +37,6 @@ A.insertGlobalCss({
40
37
  *
41
38
  * Shortcut: pass a function to use it directly as the body content.
42
39
  *
43
- * {@link BoxOptions.close | `close: true`} adds a ✕ that closes the panel the box
44
- * is drawn in: the usual way back out of a screen in a routed `S.main()`.
45
- *
46
40
  * @example
47
41
  * ```ts
48
42
  * const $user = A.proxy({name: "Kvothe"});
@@ -50,7 +44,7 @@ A.insertGlobalCss({
50
44
  * S.textline({ label: "Name", bind: A.ref($user, "name") });
51
45
  * }});
52
46
  * S.box(() => A("p#Just some content")); // shorthand
53
- * S.box({ header: "Task 42", close: true, content: drawTask }); // ✕ closes this panel
47
+ * S.box({ header: "Draft", close: () => discard(), content: drawDraft }); // ✕ runs discard()
54
48
  * ```
55
49
  */
56
50
  export function box(opts = {}) {
@@ -59,14 +53,17 @@ export function box(opts = {}) {
59
53
  // Header and footer get their own scopes so toggling them doesn't recreate
60
54
  // the body (which may hold focused inputs / lots of content).
61
55
  A(() => {
56
+ // The typeof guards against v0.9's `close: true` (removed API) reaching
57
+ // us from unchecked JS: a ✕ whose handler isn't a function would render
58
+ // but do nothing, which is worse than not rendering at all.
62
59
  if (o.header != null) {
63
60
  A("header.s-s.neutral", o.headerAttrs, () => {
64
61
  drawSlot(o.header);
65
- if (o.close)
62
+ if (typeof o.close === "function")
66
63
  drawCloseButton(o.close);
67
64
  });
68
65
  }
69
- else if (o.close) {
66
+ else if (typeof o.close === "function") {
70
67
  drawCloseButton(o.close);
71
68
  }
72
69
  });
@@ -80,18 +77,15 @@ export function box(opts = {}) {
80
77
  });
81
78
  }
82
79
  /**
83
- * The box's ✕. With `close: true` the panel to close is resolved from the DOM at
84
- * click time so one box can close whichever column it happens to be drawn in,
85
- * and a box outside a routed shell simply warns.
80
+ * The box's ✕: one definition, so the glyph, the label and the hit area are
81
+ * identical whether it sits in the header row or floats over a headerless body.
82
+ * The `.s-box-close` class is only a hook for the placement rules above.
86
83
  */
87
84
  function drawCloseButton(close) {
88
- A("button.s-box-close type=button aria-label=Close", () => {
89
- A("click=", (e) => {
90
- if (typeof close === "function")
91
- close();
92
- else
93
- void closeContainingPanel(e.currentTarget);
94
- });
95
- A("span aria-hidden=true #✕");
85
+ iconButton({
86
+ icon: closeIcon,
87
+ ariaLabel: "Close",
88
+ click: close,
89
+ attrs: ".s-box-close",
96
90
  });
97
91
  }
@@ -1,4 +1,23 @@
1
1
  import { type Slot, type Attributes } from "../core.js";
2
+ /** Options for {@link iconButton}. */
3
+ export interface IconButtonOptions {
4
+ /** The glyph, usually one of the `staffa/icons` draw functions. */
5
+ icon: Slot;
6
+ /** What it does, for screen readers. Required: there is no visible text to read. */
7
+ ariaLabel: string;
8
+ /** Click handler. */
9
+ click?: (event: Event) => void;
10
+ /** Render as a link (`<a role=button>`) pointing here instead of a `<button>`. */
11
+ href?: string;
12
+ /** Disables it. */
13
+ disabled?: boolean;
14
+ /**
15
+ * Aberdeen attr/style string applied to the button. `.small` and `.large`
16
+ * size the hit area (medium is the default and needs no class); a `.small`
17
+ * or `.large` parent sizes the ones inside it, as with {@link button}.
18
+ */
19
+ attrs?: Attributes;
20
+ }
2
21
  /** Options for {@link button}. */
3
22
  export interface ButtonOptions {
4
23
  /** Button content: a string for plain text, or a function for custom markup. */
@@ -27,6 +46,27 @@ export interface ButtonOptions {
27
46
  */
28
47
  attrs?: Attributes;
29
48
  }
49
+ /**
50
+ * A bare glyph in a square hit area — no fill, no border, just ink that lifts on
51
+ * hover. The quiet end of the button family, for chrome that has to sit beside
52
+ * something more important without competing with it: a ✕ on a box, the ☰ a
53
+ * routed `S.main()` puts in its top bar, the verbs in a
54
+ * {@link Panel.actions | page's actions}.
55
+ *
56
+ * Reach for {@link button} instead whenever the thing has a name worth reading;
57
+ * an icon alone is only unambiguous for a handful of universal actions.
58
+ *
59
+ * @example
60
+ * ```ts
61
+ * import { trash2, share2 } from "staffa/icons";
62
+ *
63
+ * $panel.actions = () => {
64
+ * S.iconButton({ icon: share2, ariaLabel: "Share", click: share });
65
+ * S.iconButton({ icon: trash2, ariaLabel: "Delete", click: del, attrs: "fg:$s-danger" });
66
+ * };
67
+ * ```
68
+ */
69
+ export declare function iconButton(opts: IconButtonOptions): void;
30
70
  /**
31
71
  * A button. Tonal and outlined variants show a border; filled variants rely on
32
72
  * their solid background for affordance.