staffa 0.7.3 → 0.8.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 (41) hide show
  1. package/README.md +113 -7
  2. package/dist/components/autocomplete.js +9 -3
  3. package/dist/components/box.d.ts +20 -0
  4. package/dist/components/box.js +43 -3
  5. package/dist/components/dialog.js +17 -10
  6. package/dist/components/layers.d.ts +330 -0
  7. package/dist/components/layers.js +888 -0
  8. package/dist/components/main.d.ts +98 -6
  9. package/dist/components/main.js +222 -37
  10. package/dist/components/menu.d.ts +14 -1
  11. package/dist/components/menu.js +32 -4
  12. package/dist/components/panels.d.ts +349 -0
  13. package/dist/components/panels.js +933 -0
  14. package/dist/components/tabs.d.ts +5 -0
  15. package/dist/components/tabs.js +125 -19
  16. package/dist/core.d.ts +7 -0
  17. package/dist/core.js +7 -0
  18. package/dist/index.d.ts +3 -2
  19. package/dist/index.js +3 -2
  20. package/dist/staffa.esm.js +1 -1
  21. package/package.json +7 -5
  22. package/skill/BoxOptions.md +18 -0
  23. package/skill/MainOptions.md +99 -3
  24. package/skill/Page.md +108 -0
  25. package/skill/PathParams.md +7 -0
  26. package/skill/SKILL.md +185 -7
  27. package/skill/SegParams.md +8 -0
  28. package/skill/box.md +4 -0
  29. package/skill/isFloatingMenuOpen.md +12 -0
  30. package/skill/main.md +14 -2
  31. package/skill/panels.md +10 -0
  32. package/skill/tabs.md +5 -0
  33. package/src/components/autocomplete.ts +8 -2
  34. package/src/components/box.ts +57 -2
  35. package/src/components/dialog.ts +16 -10
  36. package/src/components/main.ts +314 -40
  37. package/src/components/menu.ts +33 -5
  38. package/src/components/panels.ts +1167 -0
  39. package/src/components/tabs.ts +126 -19
  40. package/src/core.ts +8 -0
  41. package/src/index.ts +3 -2
package/README.md CHANGED
@@ -77,7 +77,7 @@ S.box({ header: "See the [docs](/docs)", content: () => { ... } });
77
77
 
78
78
  Staffa builds on **surfaces**: elements marked with `.s-s` that have their own background and derived text/border tokens. There are two families:
79
79
 
80
- - **Neutral surfaces** — `.neutral` (and the implicit page at `:root`). A calm neutral whose shade steps automatically with nesting depth (page panel raised, capped). Use them for cards, bars, popovers — anything that just holds content. No variants.
80
+ - **Neutral surfaces** — `.neutral` (and the implicit page at `:root`). A calm neutral whose shade steps automatically with nesting depth (each level a step away from the page colour, up to a cap). Use them for cards, bars, popovers — anything that just holds content. No variants.
81
81
  - **Accent surfaces** — `.primary`, `.danger`, `.success`, `.warning`, `.link` (a bare `.s-s` defaults to primary). A bright fill with white ink, painted as a subtle single-colour gradient. They take a **variant**: `.filled` (default), `.tonal`, or `.outlined`. A surface nested *inside* an accent surface is always rendered filled, so it can't bleed into the vivid parent.
82
82
 
83
83
  Components are built from these (`S.button` is a `.s-s.primary`, `S.box` a `.s-s.neutral`, etc.). Because component options include an optional `attrs` string, which has Aberdeen `A()` string semantics, you can easily override it:
@@ -111,6 +111,110 @@ S.setDarkMode(undefined); // follow OS
111
111
 
112
112
  *Hint:* A `buttonChooser` is probably the right component for a color scheme selector.
113
113
 
114
+ ### Panel-stack navigation
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.
117
+
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
+
120
+ ```ts
121
+ S.main({
122
+ title: "Trackle",
123
+ nav: { items: [{ label: "Projects", href: "/projects" }] },
124
+ routes: {
125
+ "/projects": drawProjectList,
126
+ "/projects/[projectId]": drawProject,
127
+ "/projects/[projectId]/tasks/[taskId=integer]": drawProjectTask,
128
+ },
129
+ notFound: ($page) => S.box({ header: "Not found", content: $page.path }),
130
+ });
131
+
132
+ function drawProject($page: S.Page<{ projectId: string }>) {
133
+ const { projectId } = $page.params; // typed from the route key
134
+ A(`a href=/projects/${projectId}/tasks/1 #Open the first task`);
135
+ }
136
+
137
+ // Etc..
138
+ ```
139
+
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
+
142
+ **Route keys.** A segment wrapped in brackets is a param:
143
+
144
+ - `[name]` matches one segment, as a string.
145
+ - `[name=integer]` matches one segment, as a number.
146
+ - `[...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
+ 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
+
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
+
152
+ `[...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
+ **Navigating is just links.** Write ordinary `<a href="/...">` links; Staffa handles the clicks (so don't also call Aberdeen's `interceptLinks()`).
155
+
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.
160
+
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, and `.close(path?)` closes the top panel (or a named one). `S.panels.stack` is the list of open paths.
162
+
163
+ **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:
164
+
165
+ | `layout` | How wide the panel gets | Good for |
166
+ | --- | --- | --- |
167
+ | `"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 |
168
+ | `"medium"` (default) | The whole content area: up to ~1100px, and the screen width on a phone. | ordinary screens; the safe default |
169
+ | `"large"` | The whole window, with no upper limit: ~1750px on a 1920px screen. | boards, wide tables, dense dashboards |
170
+
171
+ 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.
172
+
173
+ 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.
174
+
175
+ **The rest of `$page`:**
176
+
177
+ - `params` and `path`: read-only.
178
+ - `title`: shown in `document.title` while this panel is the top one.
179
+ - `layout`: as above. It's read once, right after your handler runs, so set it there.
180
+ - `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.
181
+ - `close()`: closes this panel, wherever it sits in the stack.
182
+ - `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.
183
+
184
+ ```ts
185
+ $page.requestClose = async () => !$task.dirty || await S.confirm("Discard unsaved changes?");
186
+ ```
187
+
188
+ **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:
189
+
190
+ ```ts
191
+ S.box({ header: "Task 42", close: true, content: drawTask }); // a ✕ in the box's corner
192
+ S.button({ content: "Cancel", attrs: ".neutral", click: () => $page.close() });
193
+ S.panels.close(); // the top panel
194
+ S.panels.close("/projects/7"); // that panel, wherever it is
195
+ ```
196
+
197
+ `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.)
198
+
199
+ 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.
200
+
201
+ 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.
202
+
203
+ <a id="ancestors"></a>
204
+
205
+ **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.
206
+
207
+ 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.
208
+
209
+ 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.
210
+
211
+ **A few more things.**
212
+
213
+ - `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.
214
+ - 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.
215
+ - 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.
216
+ - 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.
217
+
114
218
  ### CSS reset
115
219
 
116
220
  Staffa includes a lightweight CSS reset that makes bare semantic HTML look a bit better but unsurprising without additional styling.
@@ -163,9 +267,9 @@ Components share naming conventions for options: `attrs` (outermost element), `c
163
267
 
164
268
  ### Layout & containers
165
269
 
166
- - **`S.main(opts)`**: app shell, a sticky header with `icon`, `title`, `subtitle`, `menu`; scrollable content area; footer. Set `maxWidth` to center the content.
167
- - **`S.box(opts | content)`**: surface with optional `header`/`footer` and padded body. Pass a function for shorthand `{ content }`.
168
- - **`S.tabs(opts)`**: tablist with live panels and keyboard navigation.
270
+ - **`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. Instead of a single `content` slot it can take a `routes` table — see [Panel-stack navigation](#panel-stack-navigation).
271
+ - **`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.
272
+ - **`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.
169
273
  - **`S.form(opts | content)`**: form aligning fields in a column or responsive grid, with an `actions` bar. Prevents the default page reload.
170
274
 
171
275
  ### Form fields
@@ -220,6 +324,8 @@ Two-way binding uses Aberdeen proxies: pass `bind: A.ref($obj, "key")` to form f
220
324
  {
221
325
  "imports": {
222
326
  "aberdeen": "https://cdn.jsdelivr.net/npm/aberdeen/dist/src/aberdeen.js",
327
+ "aberdeen/route": "https://cdn.jsdelivr.net/npm/aberdeen/dist/src/route.js",
328
+ "aberdeen/transitions": "https://cdn.jsdelivr.net/npm/aberdeen/dist/src/transitions.js",
223
329
  "staffa/all.js": "https://cdn.jsdelivr.net/npm/staffa/dist/staffa.esm.js"
224
330
  }
225
331
  }
@@ -267,7 +373,7 @@ The previous section is good advice for any project-specific custom, but should
267
373
  2. Define `<Name>Options` extending `ContentOptions`, `FieldOptions`, or a plain interface. Add TSDoc on every option.
268
374
  3. Add a TSDoc `@example` on the function.
269
375
  4. Register in `src/index.ts` (the `S` object + type re-export).
270
- 5. Extend `smoke.mjs` to render it. Run `npm run smoke` and `npm run build`.
376
+ 5. Add it to the demo, cover it in the visual tests (`tests/*.spec.ts`), and run `npm run build` and `npm run typecheck`.
271
377
 
272
378
  See `src/components/button.ts` and `src/components/dialog.ts` for examples.
273
379
 
@@ -276,8 +382,8 @@ See `src/components/button.ts` and `src/components/dialog.ts` for examples.
276
382
  ```sh
277
383
  npm run build # compile TypeScript to dist/
278
384
  npm run typecheck # check types
279
- npm run smoke # render every component in jsdom
280
- npx http-server # allows demo to be viewed at http://localhost:8080/demo
385
+ npx http-server -P "http://localhost:8080/demo/index.html?" # demo at http://localhost:8080/demo
386
+ # (-P is the SPA fallback the demo's routed URLs need)
281
387
  npx shotest test # visual tests: click through the demo, screenshotting every step
282
388
  npx shotest review # review/accept the visual changes against the baseline
283
389
  ```
@@ -235,9 +235,15 @@ export function autocomplete(opts) {
235
235
  }
236
236
  }
237
237
  else if (e.key === "Escape") {
238
- $st.open = false;
239
- if (!opts.multi)
240
- $st.query = labelFor(selectedValues()[0] ?? "");
238
+ // Only consume Escape while the list is showing: it dismisses the
239
+ // innermost layer, so a surrounding dialog must not also close. With the
240
+ // list already closed, let it pass through to the dialog/nav handlers.
241
+ if ($st.open) {
242
+ e.preventDefault();
243
+ $st.open = false;
244
+ if (!opts.multi)
245
+ $st.query = labelFor(selectedValues()[0] ?? "");
246
+ }
241
247
  }
242
248
  else if (e.key === "Backspace" && opts.multi && $st.query === "") {
243
249
  const sel = selectedValues();
@@ -5,6 +5,22 @@ export interface BoxOptions extends ContentOptions {
5
5
  header?: Slot;
6
6
  /** Footer content, drawn in a styled bar below the body. */
7
7
  footer?: Slot;
8
+ /**
9
+ * Draws a small ✕ button in the box's top-right corner: in the header row when
10
+ * there is a {@link BoxOptions.header | header}, floating over the body when
11
+ * there isn't.
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.
22
+ */
23
+ close?: boolean | (() => void);
8
24
  /** Aberdeen attr/style string applied to the body (content-holding) element. */
9
25
  contentAttrs?: Attributes;
10
26
  /** Aberdeen attr/style string applied to the header bar. */
@@ -22,6 +38,9 @@ export interface BoxOptions extends ContentOptions {
22
38
  *
23
39
  * Shortcut: pass a function to use it directly as the body content.
24
40
  *
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
+ *
25
44
  * @example
26
45
  * ```ts
27
46
  * const $user = A.proxy({name: "Kvothe"});
@@ -29,6 +48,7 @@ export interface BoxOptions extends ContentOptions {
29
48
  * S.textline({ label: "Name", bind: A.ref($user, "name") });
30
49
  * }});
31
50
  * S.box(() => A("p#Just some content")); // shorthand
51
+ * S.box({ header: "Task 42", close: true, content: drawTask }); // ✕ closes this panel
32
52
  * ```
33
53
  */
34
54
  export declare function box(opts?: BoxOptions | Slot): void;
@@ -1,5 +1,6 @@
1
1
  import A from "aberdeen";
2
2
  import { drawSlot } from "../core.js";
3
+ import { closeContainingPanel } from "./panels.js";
3
4
  // The box itself is a `.neutral` surface; its header/footer are `.neutral` surfaces
4
5
  // too — nested one level deeper, so they pick up the next elevation shade
5
6
  // automatically. Colours and borders come from the contextual tokens, so a box
@@ -11,11 +12,22 @@ import { drawSlot } from "../core.js";
11
12
  // single divider.
12
13
  A.insertGlobalCss({
13
14
  ".s-box": {
14
- "&": "display:flex flex-direction:column overflow:hidden r: $s-radius-lg;",
15
+ // position:relative so a headerless box can hang its ✕ in the corner.
16
+ "&": "display:flex flex-direction:column overflow:hidden r: $s-radius-lg; position:relative",
15
17
  "&:not(:first-child)": "margin-top: $3",
16
18
  "> header": "display:flex align-items:center gap:$2 padding: $2 $3; border:0 border-bottom: 1px solid $s-faint; r:0 font-weight:600",
17
19
  "> 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",
18
20
  "> 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.
30
+ "> .s-box-close": "position:absolute top:$2 right:$2 z-index:1",
19
31
  },
20
32
  });
21
33
  /**
@@ -28,6 +40,9 @@ A.insertGlobalCss({
28
40
  *
29
41
  * Shortcut: pass a function to use it directly as the body content.
30
42
  *
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
+ *
31
46
  * @example
32
47
  * ```ts
33
48
  * const $user = A.proxy({name: "Kvothe"});
@@ -35,6 +50,7 @@ A.insertGlobalCss({
35
50
  * S.textline({ label: "Name", bind: A.ref($user, "name") });
36
51
  * }});
37
52
  * S.box(() => A("p#Just some content")); // shorthand
53
+ * S.box({ header: "Task 42", close: true, content: drawTask }); // ✕ closes this panel
38
54
  * ```
39
55
  */
40
56
  export function box(opts = {}) {
@@ -43,8 +59,16 @@ export function box(opts = {}) {
43
59
  // Header and footer get their own scopes so toggling them doesn't recreate
44
60
  // the body (which may hold focused inputs / lots of content).
45
61
  A(() => {
46
- if (o.header != null)
47
- A("header.s-s.neutral", o.headerAttrs, () => drawSlot(o.header));
62
+ if (o.header != null) {
63
+ A("header.s-s.neutral", o.headerAttrs, () => {
64
+ drawSlot(o.header);
65
+ if (o.close)
66
+ drawCloseButton(o.close);
67
+ });
68
+ }
69
+ else if (o.close) {
70
+ drawCloseButton(o.close);
71
+ }
48
72
  });
49
73
  A("div", o.contentAttrs, () => {
50
74
  drawSlot(o.content);
@@ -55,3 +79,19 @@ export function box(opts = {}) {
55
79
  });
56
80
  });
57
81
  }
82
+ /**
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.
86
+ */
87
+ 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 #✕");
96
+ });
97
+ }
@@ -98,17 +98,24 @@ export function dialog(opts) {
98
98
  if (!dialogCount) {
99
99
  // Install Esc handler the first time we create a dialog
100
100
  document.addEventListener("keydown", (e) => {
101
- if (e.key === "Escape" && opts.allowCancel !== false) {
102
- const ds = A.unproxy(dialogs);
103
- // Search for top-most dialog
104
- for (let i = dialogCount; i > 0; i--) {
105
- if (ds[i]) {
106
- if (ds[i].opts.allowCancel !== false) {
107
- // The clean handler should call resolve and onClose
108
- delete dialogs[i];
109
- }
110
- break;
101
+ // A layer above us that consumed Escape (an open floating menu's capture
102
+ // handler, or a widget inside the dialog like an open autocomplete list)
103
+ // marks it with preventDefault — the dialog must not also act on it.
104
+ if (e.key !== "Escape" || e.defaultPrevented)
105
+ return;
106
+ const ds = A.unproxy(dialogs);
107
+ // Search for top-most dialog
108
+ for (let i = dialogCount; i > 0; i--) {
109
+ if (ds[i]) {
110
+ // A dialog owns Escape, closable or not — handlers beneath it
111
+ // must not also act (main()'s nav jump and cooperative page
112
+ // handlers check defaultPrevented, or S.isDialogOpen()).
113
+ e.preventDefault();
114
+ if (ds[i].opts.allowCancel !== false) {
115
+ // The clean handler should call resolve and onClose
116
+ delete dialogs[i];
111
117
  }
118
+ break;
112
119
  }
113
120
  }
114
121
  });