@syware/jlib 0.14.0 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/README.md +12 -8
  2. package/dist/all.js +2 -2
  3. package/dist/atoms/jl-avatar.d.ts +2 -0
  4. package/dist/atoms/jl-avatar.js +11 -6
  5. package/dist/atoms/jl-button.d.ts +6 -0
  6. package/dist/atoms/jl-button.js +22 -8
  7. package/dist/atoms/jl-chip.js +2 -1
  8. package/dist/atoms/jl-input.js +3 -3
  9. package/dist/atoms/jl-link.d.ts +1 -0
  10. package/dist/atoms/jl-link.js +5 -2
  11. package/dist/atoms/jl-progress-ring.d.ts +2 -0
  12. package/dist/atoms/jl-progress-ring.js +6 -2
  13. package/dist/atoms/jl-progress.d.ts +1 -0
  14. package/dist/atoms/jl-progress.js +5 -2
  15. package/dist/atoms/jl-rating.d.ts +2 -0
  16. package/dist/atoms/jl-rating.js +11 -6
  17. package/dist/atoms/jl-select.css.js +1 -1
  18. package/dist/atoms/jl-select.d.ts +4 -0
  19. package/dist/atoms/jl-select.js +18 -2
  20. package/dist/atoms/jl-switch.css.js +1 -1
  21. package/dist/atoms/jl-textarea.js +2 -2
  22. package/dist/base/jl-form-control.d.ts +3 -2
  23. package/dist/base/jl-form-control.js +14 -4
  24. package/dist/index.d.ts +1 -0
  25. package/dist/index.js +2 -2
  26. package/dist/lib/dom.d.ts +5 -0
  27. package/dist/lib/dom.js +9 -1
  28. package/dist/lib/download.js +10 -2
  29. package/dist/lib/floating.d.ts +5 -0
  30. package/dist/lib/floating.js +21 -2
  31. package/dist/lib/fuzzy.d.ts +3 -2
  32. package/dist/lib/fuzzy.js +15 -4
  33. package/dist/lib/modal.d.ts +24 -0
  34. package/dist/lib/modal.js +52 -0
  35. package/dist/lib/numeric.d.ts +5 -0
  36. package/dist/lib/numeric.js +11 -1
  37. package/dist/lib/option-filter.d.ts +2 -0
  38. package/dist/lib/option-filter.js +1 -1
  39. package/dist/lib/press.d.ts +11 -0
  40. package/dist/lib/press.js +31 -0
  41. package/dist/lib/table.js +12 -4
  42. package/dist/lib/texts-de.d.ts +12 -0
  43. package/dist/lib/texts-de.js +12 -0
  44. package/dist/lib/texts-fr.d.ts +12 -0
  45. package/dist/lib/texts-fr.js +12 -0
  46. package/dist/lib/texts.d.ts +12 -0
  47. package/dist/lib/texts.js +12 -0
  48. package/dist/molecules/jl-accordion-item.js +2 -1
  49. package/dist/molecules/jl-calendar.d.ts +4 -0
  50. package/dist/molecules/jl-calendar.js +16 -5
  51. package/dist/molecules/jl-chip-group.css.js +1 -1
  52. package/dist/molecules/jl-chip-group.js +3 -3
  53. package/dist/molecules/jl-code-block.css.js +1 -1
  54. package/dist/molecules/jl-combobox.d.ts +4 -0
  55. package/dist/molecules/jl-combobox.js +23 -11
  56. package/dist/molecules/jl-copy-button.css.js +1 -1
  57. package/dist/molecules/jl-copy-button.d.ts +11 -4
  58. package/dist/molecules/jl-copy-button.js +48 -22
  59. package/dist/molecules/jl-date-picker.d.ts +4 -0
  60. package/dist/molecules/jl-date-picker.js +18 -12
  61. package/dist/molecules/jl-field.d.ts +5 -1
  62. package/dist/molecules/jl-field.js +24 -5
  63. package/dist/molecules/jl-file-drop.css.js +1 -1
  64. package/dist/molecules/jl-file-drop.d.ts +4 -0
  65. package/dist/molecules/jl-file-drop.js +16 -8
  66. package/dist/molecules/jl-input-list.js +13 -6
  67. package/dist/molecules/jl-load-state.d.ts +8 -0
  68. package/dist/molecules/jl-load-state.js +33 -7
  69. package/dist/molecules/jl-menu.d.ts +21 -1
  70. package/dist/molecules/jl-menu.js +58 -6
  71. package/dist/molecules/jl-number-input.d.ts +2 -0
  72. package/dist/molecules/jl-number-input.js +12 -8
  73. package/dist/molecules/jl-radio-group.js +3 -2
  74. package/dist/molecules/jl-search.js +2 -2
  75. package/dist/molecules/jl-segmented.js +2 -2
  76. package/dist/molecules/jl-tabs.js +2 -2
  77. package/dist/molecules/jl-tag-input.css.js +1 -1
  78. package/dist/molecules/jl-tag-input.d.ts +4 -0
  79. package/dist/molecules/jl-tag-input.js +17 -9
  80. package/dist/molecules/jl-toast.js +8 -4
  81. package/dist/molecules/jl-tooltip.js +8 -2
  82. package/dist/organisms/jl-command-palette.css.js +1 -1
  83. package/dist/organisms/jl-command-palette.d.ts +2 -0
  84. package/dist/organisms/jl-command-palette.js +9 -3
  85. package/dist/organisms/jl-dialog.d.ts +3 -0
  86. package/dist/organisms/jl-dialog.js +13 -3
  87. package/dist/organisms/jl-drawer.d.ts +3 -0
  88. package/dist/organisms/jl-drawer.js +13 -3
  89. package/dist/organisms/jl-flow.d.ts +2 -0
  90. package/dist/organisms/jl-flow.js +29 -9
  91. package/dist/organisms/jl-side-nav.css.js +1 -1
  92. package/dist/organisms/jl-side-nav.d.ts +43 -9
  93. package/dist/organisms/jl-side-nav.js +164 -24
  94. package/dist/organisms/jl-table.css.js +1 -1
  95. package/dist/organisms/jl-table.d.ts +16 -3
  96. package/dist/organisms/jl-table.js +56 -18
  97. package/dist/organisms/jl-toaster.d.ts +13 -2
  98. package/dist/organisms/jl-toaster.js +47 -4
  99. package/dist/organisms/jl-tree.css.js +1 -1
  100. package/dist/organisms/jl-tree.d.ts +23 -4
  101. package/dist/organisms/jl-tree.js +74 -18
  102. package/dist/styles/base.css.js +1 -1
  103. package/dist/styles/control.css.js +1 -1
  104. package/dist/styles/tokens.css.js +1 -1
  105. package/dist/templates/jl-app-shell.css.js +1 -1
  106. package/dist/templates/jl-app-shell.js +2 -0
  107. package/dist/tokens.css +8 -3
  108. package/dist/types/jl-load-state.types.d.ts +7 -0
  109. package/dist/types/jl-side-nav.types.d.ts +5 -0
  110. package/dist/types/jl-table.types.d.ts +12 -0
  111. package/dist/types/jl-tree.types.d.ts +17 -0
  112. package/dist/types/press.types.d.ts +6 -0
  113. package/package.json +6 -4
@@ -1,27 +1,44 @@
1
1
  import { jlText } from "../lib/texts.js";
2
2
  import { BASE_STYLES } from "../styles/shared.js";
3
3
  import { JlElement } from "../base/jl-element.js";
4
- import { jsonOf, textOf } from "../lib/attributes.js";
4
+ import { jsonOf, oneOf, textOf } from "../lib/attributes.js";
5
5
  import { registerIcons } from "../lib/icons.js";
6
6
  import { JlIcon } from "../atoms/jl-icon.js";
7
7
  import { setOrRemove, uniqueId } from "../lib/dom.js";
8
8
  import { JlButton } from "../atoms/jl-button.js";
9
+ import { hotkeyLabels, isApplePlatform, matchesHotkey, parseHotkey } from "../lib/hotkey.js";
10
+ import { watchSizes } from "../lib/resize.js";
9
11
  import { findItem, firstLeaf, pathInSections } from "../lib/nav-tree.js";
10
12
  import jl_side_nav_default from "./jl-side-nav.css.js";
11
13
  import { css } from "@jadis/core";
12
14
  import { ChevronRight, PanelLeftClose, PanelLeftOpen } from "lucide";
13
- import { jsx, jsxs } from "@jadis/core/jsx-runtime";
15
+ import { Fragment, jsx, jsxs } from "@jadis/core/jsx-runtime";
14
16
  // src/organisms/jl-side-nav.tsx
15
17
  registerIcons({
16
18
  "chevron-right": ChevronRight,
17
19
  "panel-left-close": PanelLeftClose,
18
20
  "panel-left-open": PanelLeftOpen
19
21
  });
22
+ var SIDE_NAV_COLLAPSIBLES = [
23
+ "none",
24
+ "button",
25
+ "handle",
26
+ "knob"
27
+ ];
20
28
  var ICON_SIZE = 16;
21
29
  var CHEVRON_SIZE = 14;
22
30
  var COLLAPSE_ICON = "panel-left-close";
23
31
  var EXPAND_ICON = "panel-left-open";
32
+ var FOLD_BUTTON = "fold-button";
33
+ var KNOB = "knob";
34
+ var KNOB_ICON_SIZE = 12;
35
+ var KNOB_SIZE = 24;
36
+ var KNOB_MIN_TOP = 4;
37
+ var SECTIONS_GAP = 8;
38
+ var NO_HOTKEY = "none";
39
+ var FOLD_DRAG_PX = 24;
24
40
  var ROW_SELECTOR = ".item";
41
+ var GLIDING = "gliding";
25
42
  var NEW_TAB = "_blank";
26
43
  var SAFE_REL = "noopener noreferrer";
27
44
  var NO_ITEM = "";
@@ -30,13 +47,23 @@ var parseSections = (value) => {
30
47
  const parsed = jsonOf([])(value);
31
48
  return Array.isArray(parsed) ? parsed : [];
32
49
  };
50
+ /** Whether keys fold the side nav: an empty `hotkey` and `none` name no keys. */
51
+ var hasKeys = (hotkey) => hotkey !== "" && hotkey !== NO_HOTKEY;
52
+ var onApple = () => isApplePlatform(navigator.platform);
53
+ /** A fold label with its keys: "Collapse the menu (Ctrl+B)", "(⌘B)" on a Mac. */
54
+ var withKeys = (label, hotkey) => {
55
+ const apple = onApple();
56
+ return `${label} (${hotkeyLabels(hotkey, apple).join(apple ? "" : "+")})`;
57
+ };
58
+ /** The attribute written bare (`<jl-side-nav collapsible>`, as before it took a value) gives the handle. */
59
+ var parseCollapsible = (value) => value === "" ? "handle" : oneOf(SIDE_NAV_COLLAPSIBLES, "none")(value);
33
60
  var hasChildren = (item) => (item.children?.length ?? 0) > 0;
34
61
  /** A row is reachable when no closed list hides it. */
35
62
  var isReachable = (row) => row.closest("[hidden]") === null && row.offsetParent !== null;
36
63
  /**
37
64
  * The navigation of an app, down its side: sections of items with icons, badges and nested items that open with
38
65
  * a chevron. `value` is the active item (its parents open to show it); `collapsed` makes it a rail of icons, with
39
- * the labels as tooltips, and `collapsible` lets people fold and unfold it with a button at its bottom. Items with
66
+ * the labels as tooltips, and `collapsible` lets people fold and unfold it, with a button at its bottom, a handle along its edge or a knob on its edge line; the keys of `hotkey` do it too. Items with
40
67
  * an `href` are links; the others fire `select`. Typed by its ids, `JlSideNav<'jobs' | 'people'>` takes items of
41
68
  * those ids and gives `select` one of them.
42
69
  */
@@ -58,15 +85,30 @@ var JlSideNav = class extends JlElement {
58
85
  this.reflect("collapsed", value);
59
86
  this.schedule();
60
87
  }, { attribute: "collapsed" });
61
- /** Adds a button at the bottom that folds the side nav into its rail and unfolds it. */
62
- collapsible = this.useChange(false, (value) => this.reflect("collapsible", value), { attribute: "collapsible" });
63
- /** The fold button's text while the side nav is open; jlib's own when empty. */
88
+ /**
89
+ * What people fold the side nav into its rail with, and unfold it: `none` (the app's own control, setting
90
+ * `collapsed`), an icon `button` at its bottom, a `handle` along its edge, or a round `knob` on its edge line, under
91
+ * the header. The handle is dragged towards the fold, and back; from the keyboard, Enter folds it.
92
+ */
93
+ collapsible = this.useChange("none", (value) => {
94
+ this.reflect("collapsible", value);
95
+ this.schedule();
96
+ }, {
97
+ attribute: "collapsible",
98
+ parse: parseCollapsible
99
+ });
100
+ /** What the handle says while the side nav is open; jlib's own when empty. */
64
101
  collapseLabel = this.useChange("", () => this.schedule(), { attribute: "collapse-label" });
65
- /** Its hint while the side nav is a rail; jlib's own when empty. */
102
+ /** What it says while the side nav is a rail; jlib's own when empty. */
66
103
  expandLabel = this.useChange("", () => this.schedule(), { attribute: "expand-label" });
67
104
  /**
105
+ * The keys that fold and unfold it from anywhere in the page, whatever `collapsible` is: `mod+b` for ⌘B on a Mac
106
+ * and Ctrl+B elsewhere. None until the app names some.
107
+ */
108
+ hotkey = this.useChange("", () => this.schedule(), { attribute: "hotkey" });
109
+ /**
68
110
  * Set by `jl-app-shell` while the side nav is its drawer, on a narrow screen: the drawer shows it whole, and its
69
- * fold button hides, `collapsed` waiting for a wide screen again.
111
+ * handle hides, `collapsed` waiting for a wide screen again.
70
112
  */
71
113
  inDrawer = this.useChange(false, (value) => {
72
114
  this.reflect("in-drawer", value);
@@ -83,41 +125,59 @@ var JlSideNav = class extends JlElement {
83
125
  rail: false,
84
126
  sections: void 0
85
127
  };
128
+ /** Where the drag of the handle counts from: where it began, then where it last folded or turned back. */
129
+ _drag = { from: 0 };
130
+ _sizes = watchSizes(() => this.placeKnob());
86
131
  _refs = this.useRefs((ref) => ({
87
- fold: ref(JlButton),
132
+ bottom: ref(".bottom"),
133
+ fold: ref(".fold"),
88
134
  nav: ref("nav"),
135
+ over: ref(".over"),
89
136
  sections: ref(".sections")
90
137
  }));
91
138
  templateHtml() {
92
- return /* @__PURE__ */ jsxs("nav", {
139
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("nav", {
93
140
  attrs: { part: "base" },
94
141
  children: [
95
142
  /* @__PURE__ */ jsx("slot", { name: "header" }),
96
143
  /* @__PURE__ */ jsx("div", { class: "sections" }),
97
- /* @__PURE__ */ jsxs("div", {
144
+ /* @__PURE__ */ jsx("div", {
98
145
  class: "bottom",
99
- children: [/* @__PURE__ */ jsx("slot", { name: "footer" }), /* @__PURE__ */ jsx(JlButton, {
100
- class: "fold",
101
- variant: "ghost",
102
- block: true
103
- })]
146
+ children: /* @__PURE__ */ jsx("slot", { name: "footer" })
104
147
  })
105
148
  ]
106
- });
149
+ }), /* @__PURE__ */ jsx("div", {
150
+ class: "over",
151
+ children: /* @__PURE__ */ jsx("button", {
152
+ type: "button",
153
+ class: "fold",
154
+ children: /* @__PURE__ */ jsx("span", { class: "grip" })
155
+ })
156
+ })] });
107
157
  }
108
158
  templateCss() {
109
159
  return css`${BASE_STYLES}${jl_side_nav_default}`;
110
160
  }
111
161
  onConnect() {
112
- this._refs.fold.events.register("press", () => this.fold());
162
+ this._sizes.observe(this._refs.sections);
163
+ this.on(this._refs.fold, "click", (event) => this.foldOnKeyboardClick(event));
164
+ this.on(this._refs.fold, "pointerdown", (event) => this.startDrag(event));
165
+ this.on(this._refs.fold, "pointermove", (event) => this.foldOnDrag(event));
166
+ document.addEventListener("keydown", (event) => this.foldOnHotkey(event), { signal: this.killSignal });
113
167
  this.on(this._refs.sections, "click", (event) => this.onClick(event));
114
168
  this.on(this._refs.sections, "keydown", (event) => this.onKey(event));
115
169
  }
170
+ onDisconnect() {
171
+ this._sizes.disconnect();
172
+ }
116
173
  /** Opens or closes a parent item. */
117
174
  toggleItem(id, force) {
118
175
  if (force ?? !this._state.open.has(id)) this._state.open.add(id);
119
176
  else this._state.open.delete(id);
120
- this.whenRendered(() => this.renderOpen());
177
+ this.whenRendered(() => {
178
+ this._refs.sections.classList.add(GLIDING);
179
+ this.renderOpen();
180
+ });
121
181
  }
122
182
  onClick(event) {
123
183
  const target = event.target;
@@ -139,6 +199,34 @@ var JlSideNav = class extends JlElement {
139
199
  isRail() {
140
200
  return this.collapsed.get() && !this.inDrawer.get();
141
201
  }
202
+ /** The handle is dragged, not pressed: only the keyboard's Enter or Space, a click with no pointer, folds it. */
203
+ foldOnKeyboardClick(event) {
204
+ if (event.detail === 0) this.fold();
205
+ }
206
+ /** The handle keeps the pointer for the drag, wherever it goes. */
207
+ startDrag(event) {
208
+ this._drag.from = event.clientX;
209
+ this._refs.fold.setPointerCapture(event.pointerId);
210
+ }
211
+ /**
212
+ * Dragged far enough towards the fold (or away from it, as a rail), the side nav follows; the drag goes on from
213
+ * there, so coming back the same distance undoes it. A move the other way only takes the starting point along.
214
+ */
215
+ foldOnDrag(event) {
216
+ if (!this._refs.fold.hasPointerCapture(event.pointerId)) return;
217
+ const moved = event.clientX - this._drag.from;
218
+ const towardsNext = this.isRail() ? moved : -moved;
219
+ if (towardsNext > 0 && towardsNext < FOLD_DRAG_PX) return;
220
+ this._drag.from = event.clientX;
221
+ if (towardsNext >= FOLD_DRAG_PX) this.fold();
222
+ }
223
+ /** The keys fold it wherever the focus is, unless the page used them or a drawer shows it whole. */
224
+ foldOnHotkey(event) {
225
+ const hotkey = this.hotkey.get();
226
+ if (!(!this.inDrawer.get() && hasKeys(hotkey)) || event.defaultPrevented || !matchesHotkey(event, parseHotkey(hotkey), onApple())) return;
227
+ event.preventDefault();
228
+ this.fold();
229
+ }
142
230
  fold() {
143
231
  const collapsed = !this.collapsed.get();
144
232
  this.collapsed.set(collapsed);
@@ -179,13 +267,64 @@ var JlSideNav = class extends JlElement {
179
267
  renderLabel() {
180
268
  this._refs.nav.setAttribute("aria-label", this.label.get() || jlText("mainNavigation"));
181
269
  }
182
- /** The fold button's icon and text; the CSS hides it unless `collapsible`, and in a drawer. */
270
+ /** What the handle or the button says and does next; the CSS shows the one `collapsible` names, none in a drawer. */
183
271
  renderFold() {
184
272
  const fold = this._refs.fold;
185
273
  const rail = this.isRail();
186
- fold.icon.set(rail ? EXPAND_ICON : COLLAPSE_ICON);
187
- fold.label.set(rail ? "" : this.collapseLabel.get() || jlText("collapseMenu"));
188
- fold.hint.set(rail ? this.expandLabel.get() || jlText("expandMenu") : "");
274
+ const hotkey = this.hotkey.get();
275
+ const label = rail ? this.expandLabel.get() || jlText("expandMenu") : this.collapseLabel.get() || jlText("collapseMenu");
276
+ const hint = hasKeys(hotkey) ? withKeys(label, hotkey) : label;
277
+ const mode = this.collapsible.get();
278
+ const natives = mode === "knob" ? [fold, this.knob()] : [fold];
279
+ for (const control of natives) {
280
+ control.setAttribute("aria-label", label);
281
+ control.setAttribute("aria-expanded", String(!rail));
282
+ control.title = hint;
283
+ }
284
+ if (mode === "button") {
285
+ const button = this.foldButton();
286
+ button.icon.set(rail ? EXPAND_ICON : COLLAPSE_ICON);
287
+ button.hint.set(hint);
288
+ }
289
+ }
290
+ /** The knob on the edge line, made the first time `collapsible` asks for it. */
291
+ knob() {
292
+ const over = this._refs.over;
293
+ const made = over.querySelector(`.${KNOB}`);
294
+ if (made !== null) return made;
295
+ const knob = /* @__PURE__ */ jsx("button", {
296
+ type: "button",
297
+ class: KNOB,
298
+ onClick: () => this.fold(),
299
+ children: /* @__PURE__ */ jsx(JlIcon, {
300
+ class: "knob-icon",
301
+ name: "chevron-right",
302
+ size: KNOB_ICON_SIZE
303
+ })
304
+ });
305
+ over.append(knob);
306
+ this.placeKnob();
307
+ return knob;
308
+ }
309
+ /** Puts the knob's centre in the gap between the header and the first section, wherever the header ends. */
310
+ placeKnob() {
311
+ const knob = this._refs.over.querySelector(`.${KNOB}`);
312
+ if (knob === null) return;
313
+ const gapCentre = this._refs.sections.offsetTop - SECTIONS_GAP / 2;
314
+ knob.style.top = `${Math.max(KNOB_MIN_TOP, gapCentre - KNOB_SIZE / 2)}px`;
315
+ }
316
+ /** The button at the bottom, made the first time `collapsible` asks for it. */
317
+ foldButton() {
318
+ const bottom = this._refs.bottom;
319
+ const made = bottom.querySelector(`.${FOLD_BUTTON}`);
320
+ if (made !== null) return made;
321
+ const button = /* @__PURE__ */ jsx(JlButton, {
322
+ class: FOLD_BUTTON,
323
+ variant: "ghost"
324
+ });
325
+ button.addEventListener("press", () => this.fold());
326
+ bottom.append(button);
327
+ return button;
189
328
  }
190
329
  choose(id) {
191
330
  this.value.set(id);
@@ -228,6 +367,7 @@ var JlSideNav = class extends JlElement {
228
367
  }
229
368
  render() {
230
369
  for (const id of pathInSections(this.sections.get(), this.value.get()).slice(0, -1)) this._state.open.add(id);
370
+ this._refs.sections.classList.remove(GLIDING);
231
371
  this._refs.sections.replaceChildren(...this.sections.get().map((section, index) => this.sectionNode(section, index)));
232
372
  this.renderOpen();
233
373
  this.renderActive(this.value.get());
@@ -362,4 +502,4 @@ var JlSideNav = class extends JlElement {
362
502
  }
363
503
  };
364
504
  JlSideNav.register();
365
- export { JlSideNav };
505
+ export { JlSideNav, SIDE_NAV_COLLAPSIBLES };
@@ -1,3 +1,3 @@
1
1
  // src/organisms/jl-table.css?inline
2
- var jl_table_default = ":host{contain:inline-size;--max-height:none;--cell-y:10px;--cell-x:14px;--select-width:44px;--expand-width:36px;--lead:0px;display:block}:host([expandable]){--lead:var(--expand-width)}:host([expandable][selectable]){--expand-width:28px;--lead:calc(var(--select-width) + var(--expand-width))}:host([dense]){--cell-y:6px;--cell-x:12px}.scroll{max-height:var(--max-height);border:1px solid var(--jl-line);border-radius:var(--jl-radius);background:var(--jl-surface);overscroll-behavior-x:contain;position:relative;overflow:auto}:host([expandable]) .scroll{container-type:inline-size}table{border-collapse:separate;border-spacing:0;width:100%;color:var(--jl-text);font-size:var(--jl-font-md);line-height:20px}th,td{padding:var(--cell-y) var(--cell-x);white-space:nowrap;vertical-align:middle}th{z-index:1;border-bottom:1px solid var(--jl-line);background:var(--jl-surface-2);color:var(--jl-muted);font-size:var(--jl-font-xs);letter-spacing:.01em;text-align:left;font-weight:600;position:sticky;top:0}td{border-top:1px solid var(--jl-line-soft)}tbody tr:first-child td{border-top:none}tbody tr.empty td{padding:40px var(--cell-x);color:var(--jl-muted);text-align:center}tbody tr.detail td{padding:0 var(--cell-x) calc(var(--cell-y) + 6px) calc(var(--lead) + var(--cell-x));white-space:normal;cursor:auto;border-top:none}.detail-body{left:calc(var(--lead) + var(--cell-x));max-width:calc(100cqi - var(--lead) - 2 * var(--cell-x));position:sticky}.align-left{text-align:left}.align-center{text-align:center}.align-right{text-align:right}.sort{border-radius:var(--jl-radius-xs);color:inherit;font-weight:inherit;letter-spacing:inherit;cursor:pointer;background:0 0;border:none;align-items:center;gap:4px;margin:-2px -4px;padding:2px 4px;display:inline-flex}.sort:hover{color:var(--jl-text)}.sort-icon{color:var(--jl-faint)}th[aria-sort]{color:var(--jl-text)}th[aria-sort] .sort-icon{color:var(--jl-accent)}tbody tr[data-marked] td{background:var(--jl-accent-soft)}tbody tr[data-marked] td:first-child{box-shadow:inset 3px 0 0 var(--jl-accent)}tbody tr:has(>.select-cell .checkbox:checked) td{background:var(--jl-accent-soft)}tbody tr:not(.empty,.skeleton,.detail,:has(>.select-cell .checkbox:checked)):hover td,:host([striped]) tbody tr:nth-child(2n of :where(:not(.detail))):not(.empty,[data-marked],:has(>.select-cell .checkbox:checked)) td{background:var(--jl-surface-2)}:host([striped]) tbody tr:not(.empty,.skeleton,.detail,:has(>.select-cell .checkbox:checked)):hover td{background:var(--jl-surface-3)}:host([striped]) tbody tr:nth-child(2n of :where(:not(.detail))):not([data-marked],:has(>.select-cell .checkbox:checked))+.detail td{background:var(--jl-surface-2)}.format-number{font-variant-numeric:tabular-nums}td.wrap{white-space:normal;overflow-wrap:anywhere;min-width:160px}.format-date{color:var(--jl-text-2);font-variant-numeric:tabular-nums}code{border-radius:var(--jl-radius-xs);background:var(--jl-code-bg);font-size:var(--jl-font-xs);padding:2px 6px}.select-cell{width:var(--select-width);padding-right:0;line-height:0}.expand-cell{width:var(--expand-width);padding-right:0;padding-left:calc(var(--cell-x) - 4px);line-height:0}.select-cell+.expand-cell{padding-left:0}:host([expandable]) tbody tr[data-index]{cursor:pointer}.expand{border-radius:var(--jl-radius-xs);width:24px;height:24px;color:var(--jl-muted);cursor:pointer;background:0 0;border:none;justify-content:center;align-items:center;margin:-2px 0;padding:0;display:inline-flex}.expand:hover{color:var(--jl-text)}.chevron{transition:rotate var(--jl-fast) var(--jl-ease)}.expand[aria-expanded=true] .chevron{rotate:90deg}.check{display:inline-flex;position:relative}.checkbox{border:1.5px solid var(--jl-line-strong);background:var(--jl-surface);cursor:pointer;appearance:none;width:16px;height:16px;transition:background var(--jl-fast) var(--jl-ease), border-color var(--jl-fast) var(--jl-ease);border-radius:4px;margin:0}.checkbox:hover{border-color:var(--jl-muted)}.checkbox:checked,.checkbox:indeterminate{border-color:var(--jl-accent);background:var(--jl-accent)}.checkbox:disabled{cursor:not-allowed;opacity:.5}.mark{pointer-events:none;position:absolute;inset:0}.checkbox:checked+.mark:after{border:solid var(--jl-on-accent);content:\"\";border-width:0 2px 2px 0;width:5px;height:9px;position:absolute;top:2.5px;left:5.5px;rotate:45deg}.checkbox:indeterminate+.mark:after{background:var(--jl-on-accent);content:\"\";border-radius:1px;height:2px;position:absolute;top:7px;left:4px;right:4px}.empty-content{align-items:center;gap:8px;display:inline-flex}.empty jl-icon{color:var(--jl-faint)}.bone{border-radius:var(--jl-radius-pill);background:linear-gradient(90deg, var(--jl-surface-3) 30%, var(--jl-surface-2) 50%, var(--jl-surface-3) 70%) 0 0 / 300% 100%;vertical-align:middle;width:70%;max-width:160px;height:10px;animation:1.4s linear infinite shimmer;display:inline-block}.bone.box{border-radius:4px;width:16px;height:16px}tbody tr.skeleton:nth-child(3n+2) .bone:not(.box){width:50%}tbody tr.skeleton:nth-child(3n) .bone:not(.box){width:85%}@media (prefers-reduced-motion:reduce){.bone{animation:none}}@keyframes shimmer{0%{background-position:100% 0}to{background-position:0 0}}.cell-description{color:var(--jl-muted);font-size:var(--jl-font-xs);margin-top:2px}";
2
+ var jl_table_default = ":host{contain:inline-size;--max-height:none;--cell-y:10px;--cell-x:14px;--foot-y:8px;--select-width:44px;--expand-width:36px;--lead:0px;display:block}:host([expandable]){--lead:var(--expand-width)}:host([expandable][selectable]){--expand-width:28px;--lead:calc(var(--select-width) + var(--expand-width))}:host([dense]){--cell-y:6px;--cell-x:12px;--foot-y:6px}.frame{border:1px solid var(--jl-line);border-radius:var(--jl-radius);background:var(--jl-surface);overflow:hidden}.scroll{max-height:var(--max-height);overscroll-behavior-x:contain;position:relative;overflow:auto}.foot{padding:var(--foot-y) var(--cell-x);border-top:1px solid var(--jl-line);color:var(--jl-muted);font-size:var(--jl-font-sm);flex-wrap:wrap;justify-content:space-between;align-items:center;gap:8px 16px;display:flex}.foot.alone{justify-content:flex-end}:host([expandable]) .scroll{container-type:inline-size}table{border-collapse:separate;border-spacing:0;width:100%;color:var(--jl-text);font-size:var(--jl-font-md);line-height:20px}th,td{padding:var(--cell-y) var(--cell-x);white-space:nowrap;vertical-align:middle}th{z-index:1;border-bottom:1px solid var(--jl-line);background:var(--jl-surface-2);color:var(--jl-muted);font-size:var(--jl-font-xs);letter-spacing:.01em;text-align:left;font-weight:600;position:sticky;top:0}td{border-top:1px solid var(--jl-line-soft)}tbody tr:first-child td{border-top:none}tbody tr.empty td{padding:40px var(--cell-x);color:var(--jl-muted);text-align:center}tbody tr.detail td{padding:0 var(--cell-x) calc(var(--cell-y) + 6px) calc(var(--lead) + var(--cell-x));white-space:normal;cursor:auto;border-top:none}.detail-body{left:calc(var(--lead) + var(--cell-x));max-width:calc(100cqi - var(--lead) - 2 * var(--cell-x));position:sticky}.align-left{text-align:left}.align-center{text-align:center}.align-right{text-align:right}.sort{border-radius:var(--jl-radius-xs);color:inherit;font-weight:inherit;letter-spacing:inherit;cursor:pointer;background:0 0;border:none;align-items:center;gap:4px;margin:-2px -4px;padding:2px 4px;display:inline-flex}.sort:hover{color:var(--jl-text)}.sort-icon{color:var(--jl-faint)}th[aria-sort]{color:var(--jl-text)}th[aria-sort] .sort-icon{color:var(--jl-accent)}tbody tr[data-marked] td{background:var(--jl-accent-soft)}tbody tr[data-marked] td:first-child{box-shadow:inset 3px 0 0 var(--jl-accent)}tbody tr:has(>.select-cell .checkbox:checked) td{background:var(--jl-accent-soft)}tbody tr:not(.empty,.skeleton,.detail,:has(>.select-cell .checkbox:checked)):hover td,:host([striped]) tbody tr:nth-child(2n of :where(:not(.detail))):not(.empty,[data-marked],:has(>.select-cell .checkbox:checked)) td{background:var(--jl-surface-2)}:host([striped]) tbody tr:not(.empty,.skeleton,.detail,:has(>.select-cell .checkbox:checked)):hover td{background:var(--jl-surface-3)}:host([striped]) tbody tr:nth-child(2n of :where(:not(.detail))):not([data-marked],:has(>.select-cell .checkbox:checked))+.detail td{background:var(--jl-surface-2)}.format-number{font-variant-numeric:tabular-nums}td.wrap{white-space:normal;overflow-wrap:anywhere;min-width:160px}.format-date{color:var(--jl-text-2);font-variant-numeric:tabular-nums}code{border-radius:var(--jl-radius-xs);background:var(--jl-code-bg);font-size:var(--jl-font-xs);padding:2px 6px}.select-cell{width:var(--select-width);padding-right:0;line-height:0}.expand-cell{width:var(--expand-width);padding-right:0;padding-left:calc(var(--cell-x) - 4px);line-height:0}.select-cell+.expand-cell{padding-left:0}tbody tr[data-index]{cursor:var(--row-cursor,auto)}:host([expandable]) tbody tr[data-index]{cursor:pointer}.expand{border-radius:var(--jl-radius-xs);width:24px;height:24px;color:var(--jl-muted);cursor:pointer;background:0 0;border:none;justify-content:center;align-items:center;margin:-2px 0;padding:0;display:inline-flex}.expand:hover{color:var(--jl-text)}.chevron{transition:rotate var(--jl-fast) var(--jl-ease)}.expand[aria-expanded=true] .chevron{rotate:90deg}.check{display:inline-flex;position:relative}.checkbox{border:1.5px solid var(--jl-line-strong);background:var(--jl-surface);cursor:pointer;appearance:none;width:16px;height:16px;transition:background var(--jl-fast) var(--jl-ease), border-color var(--jl-fast) var(--jl-ease);border-radius:4px;margin:0}.checkbox:hover{border-color:var(--jl-muted)}.checkbox:checked,.checkbox:indeterminate{border-color:var(--jl-accent);background:var(--jl-accent)}.checkbox:disabled{cursor:not-allowed;opacity:.5}.mark{pointer-events:none;position:absolute;inset:0}.checkbox:checked+.mark:after{border:solid var(--jl-on-accent);content:\"\";border-width:0 2px 2px 0;width:5px;height:9px;position:absolute;top:2.5px;left:5.5px;rotate:45deg}.checkbox:indeterminate+.mark:after{background:var(--jl-on-accent);content:\"\";border-radius:1px;height:2px;position:absolute;top:7px;left:4px;right:4px}.empty-content{align-items:center;gap:8px;display:inline-flex}.empty jl-icon{color:var(--jl-faint)}.bone{border-radius:var(--jl-radius-pill);background:linear-gradient(90deg, var(--jl-surface-3) 30%, var(--jl-surface-2) 50%, var(--jl-surface-3) 70%) 0 0 / 300% 100%;vertical-align:middle;width:70%;max-width:160px;height:10px;animation:1.4s linear infinite shimmer;display:inline-block}.bone.box{border-radius:4px;width:16px;height:16px}tbody tr.skeleton:nth-child(3n+2) .bone:not(.box){width:50%}tbody tr.skeleton:nth-child(3n) .bone:not(.box){width:85%}@media (prefers-reduced-motion:reduce){.bone{animation:none}}@keyframes shimmer{0%{background-position:100% 0}to{background-position:0 0}}.cell-description{color:var(--jl-muted);font-size:var(--jl-font-xs);margin-top:2px}";
3
3
  export { jl_table_default as default };
@@ -1,5 +1,5 @@
1
1
  import { JlElement } from '../base/jl-element';
2
- import type { TableColumn, TableColumnKey, TableDetailRenderer, TableExpansion, TableField, TableRenderers, TableRow, TableRowKey, TableSort, TableSortDirection, TableToggle } from '../types/jl-table.types';
2
+ import type { TableColumn, TableColumnKey, TableDetailRenderer, TableExpansion, TableField, TablePress, TableRenderers, TableRow, TableRowKey, TableSort, TableSortDirection, TableToggle } from '../types/jl-table.types';
3
3
  export declare const TABLE_SORT_DIRECTIONS: readonly TableSortDirection[];
4
4
  export declare const TABLE_EXPANSIONS: readonly TableExpansion[];
5
5
  /**
@@ -8,7 +8,8 @@ export declare const TABLE_EXPANSIONS: readonly TableExpansion[];
8
8
  * rows in place; `selectable` adds a checkbox column. The header stays on top while the rows scroll within
9
9
  * `max-height`, and the table scrolls sideways on narrow screens. Cells of a column can be drawn by code with
10
10
  * `renderers`. `expandable` rows open on a press to show their `detail` under them, the row staying as it is: one at
11
- * a time (`single`) or any number (`multiple`).
11
+ * a time (`single`) or any number (`multiple`). A press on a row fires `press` with the row, the button and the
12
+ * browser's event, which a page cancels to refuse it: to open a record on a click, its own menu on a right click.
12
13
  *
13
14
  * Typed by its rows, `JlTable<Order>` checks and completes the fields its columns name, and hands its renderers and
14
15
  * `detail` an order; `JlTable<Order, 'actions'>` adds a column that is not a field, which a renderer draws.
@@ -19,6 +20,7 @@ export declare class JlTable<Row extends object = TableRow, Extra extends string
19
20
  sort: TableSort<Row, Extra>;
20
21
  selection: TableRowKey[];
21
22
  toggle: TableToggle;
23
+ press: TablePress<Row>;
22
24
  }>>;
23
25
  readonly columns: Readonly<Readonly<{
24
26
  get(): TableColumn<Row, Extra>[];
@@ -118,6 +120,8 @@ export declare class JlTable<Row extends object = TableRow, Extra extends string
118
120
  templateHtml(): Node;
119
121
  templateCss(): string;
120
122
  onConnect(): void;
123
+ /** The bar under the rows shows when the page put something in it; what stands there alone goes to its end. */
124
+ private drawFoot;
121
125
  /** Draws on the next microtask: the inputs set while connecting give one drawing, not one each. */
122
126
  protected drawTexts(): void;
123
127
  private schedule;
@@ -125,9 +129,19 @@ export declare class JlTable<Row extends object = TableRow, Extra extends string
125
129
  private sortBy;
126
130
  private changeSelection;
127
131
  /** A press on a row's chevron, or on the row anywhere but its controls and its checkbox, opens or closes it. */
132
+ /**
133
+ * A press on a row. The page hears of it first (`press`); then, for a click it did not refuse, an expandable row
134
+ * opens or closes.
135
+ */
128
136
  private pressRow;
129
137
  /** The row of data a press is on: one of the table's, not a row in the content of a detail. */
130
138
  private dataRowOf;
139
+ /**
140
+ * Whether a press is on the row itself: not on a control in it (a link, a button, its chevron), nor in its
141
+ * selection cell, nor the end of a drag that selected text. Those keep their press for themselves.
142
+ */
143
+ private isOnRowItself;
144
+ /** An expandable row opens on a press on itself, and on its chevron. */
131
145
  private opensOnPress;
132
146
  private renderMaxHeight;
133
147
  private isExpandable;
@@ -152,7 +166,6 @@ export declare class JlTable<Row extends object = TableRow, Extra extends string
152
166
  private cellValue;
153
167
  private skeletonRows;
154
168
  private emptyRow;
155
- private keyOf;
156
169
  /**
157
170
  * Draws a state on the rows whose keys came into it or left it since it was last drawn: checking or opening one
158
171
  * row changes that row alone, whatever the number of rows.
@@ -6,8 +6,10 @@ import { registerIcons } from "../lib/icons.js";
6
6
  import { columnAlign, columnWidth, fieldOf, formatCell, nextSortDirection, openRows, rowKeyOf, rowToggles, selectionState, sortBy, toggleAll, toggleKey, withRowOpen } from "../lib/table.js";
7
7
  import { JlIcon } from "../atoms/jl-icon.js";
8
8
  import { setOrRemove } from "../lib/dom.js";
9
+ import { hasSlotted } from "../lib/slots.js";
9
10
  import { JlBadge } from "../atoms/jl-badge.js";
10
11
  import { startedOnControl } from "../lib/surface.js";
12
+ import { PRESS_EVENTS, pressButtonOf, tellPress } from "../lib/press.js";
11
13
  import jl_table_default from "./jl-table.css.js";
12
14
  import { css } from "@jadis/core";
13
15
  import { ArrowDown, ArrowUp, ChevronRight, ChevronsUpDown, Inbox } from "lucide";
@@ -103,7 +105,8 @@ var isOpen = (row) => row.querySelector(":scope > .expand-cell > .expand")?.getA
103
105
  * rows in place; `selectable` adds a checkbox column. The header stays on top while the rows scroll within
104
106
  * `max-height`, and the table scrolls sideways on narrow screens. Cells of a column can be drawn by code with
105
107
  * `renderers`. `expandable` rows open on a press to show their `detail` under them, the row staying as it is: one at
106
- * a time (`single`) or any number (`multiple`).
108
+ * a time (`single`) or any number (`multiple`). A press on a row fires `press` with the row, the button and the
109
+ * browser's event, which a page cancels to refuse it: to open a record on a click, its own menu on a right click.
107
110
  *
108
111
  * Typed by its rows, `JlTable<Order>` checks and completes the fields its columns name, and hands its renderers and
109
112
  * `detail` an order; `JlTable<Order, 'actions'>` adds a column that is not a field, which a renderer draws.
@@ -198,6 +201,8 @@ var JlTable = class extends JlElement {
198
201
  };
199
202
  _refs = this.useRefs((ref) => ({
200
203
  body: ref("tbody"),
204
+ foot: ref(".foot"),
205
+ footSlot: ref("slot[name=\"footer\"]"),
201
206
  head: ref("thead"),
202
207
  table: ref("table")
203
208
  }));
@@ -219,16 +224,26 @@ var JlTable = class extends JlElement {
219
224
  for (const change of rowToggles(before, openRows(expanded, expansion))) this.events.emit("toggle", change);
220
225
  }
221
226
  templateHtml() {
222
- return /* @__PURE__ */ jsx("div", {
223
- class: "scroll",
227
+ return /* @__PURE__ */ jsxs("div", {
228
+ class: "frame",
224
229
  attrs: { part: "base" },
225
- children: /* @__PURE__ */ jsxs("table", { children: [/* @__PURE__ */ jsx("thead", {}), /* @__PURE__ */ jsx("tbody", {})] })
230
+ children: [/* @__PURE__ */ jsx("div", {
231
+ class: "scroll",
232
+ children: /* @__PURE__ */ jsxs("table", { children: [/* @__PURE__ */ jsx("thead", {}), /* @__PURE__ */ jsx("tbody", {})] })
233
+ }), /* @__PURE__ */ jsx("div", {
234
+ class: "foot",
235
+ attrs: { part: "footer" },
236
+ hidden: true,
237
+ children: /* @__PURE__ */ jsx("slot", { name: "footer" })
238
+ })]
226
239
  });
227
240
  }
228
241
  templateCss() {
229
242
  return css`${BASE_STYLES}${jl_table_default}`;
230
243
  }
231
244
  onConnect() {
245
+ this.drawFoot();
246
+ this.on(this._refs.footSlot, "slotchange", () => this.drawFoot());
232
247
  this.on(this._refs.head, "click", (event) => {
233
248
  const key = event.target.closest("button.sort")?.dataset.key;
234
249
  if (key !== void 0) this.sortBy(key);
@@ -236,7 +251,13 @@ var JlTable = class extends JlElement {
236
251
  this.on(this._refs.table, "change", (event) => {
237
252
  if (isTableCheckbox(event.target)) this.changeSelection(event.target);
238
253
  });
239
- this.on(this._refs.body, "click", (event) => this.pressRow(event));
254
+ for (const type of PRESS_EVENTS) this.on(this._refs.body, type, (event) => this.pressRow(event));
255
+ }
256
+ /** The bar under the rows shows when the page put something in it; what stands there alone goes to its end. */
257
+ drawFoot() {
258
+ const foot = this._refs.foot;
259
+ foot.hidden = !hasSlotted(this._refs.footSlot);
260
+ foot.classList.toggle("alone", this._refs.footSlot.assignedElements({ flatten: true }).length === 1);
240
261
  }
241
262
  /** Draws on the next microtask: the inputs set while connecting give one drawing, not one each. */
242
263
  drawTexts() {
@@ -284,24 +305,43 @@ var JlTable = class extends JlElement {
284
305
  this.events.emit("selection", keys);
285
306
  }
286
307
  /** A press on a row's chevron, or on the row anywhere but its controls and its checkbox, opens or closes it. */
308
+ /**
309
+ * A press on a row. The page hears of it first (`press`); then, for a click it did not refuse, an expandable row
310
+ * opens or closes.
311
+ */
287
312
  pressRow(event) {
288
- const row = this.dataRowOf(event);
289
- const key = row === void 0 ? void 0 : this.keyOf(row);
290
- if (row === void 0 || key === void 0 || !this.opensOnPress(event, row)) return;
291
- this.toggle(key, !isOpen(row));
313
+ const element = this.dataRowOf(event);
314
+ const drawn = element === void 0 ? void 0 : this._view.drawn[Number(element.dataset.index)];
315
+ const button = pressButtonOf(event);
316
+ if (element === void 0 || drawn === void 0 || button === null) return;
317
+ const onRow = this.isOnRowItself(event, element);
318
+ const press = {
319
+ button,
320
+ event,
321
+ key: drawn.key,
322
+ row: drawn.row
323
+ };
324
+ if (onRow && tellPress(event, () => this.events.emit("press", press)) || button !== "main" || !this.opensOnPress(event, element, onRow)) return;
325
+ this.toggle(drawn.key, !isOpen(element));
292
326
  }
293
327
  /** The row of data a press is on: one of the table's, not a row in the content of a detail. */
294
328
  dataRowOf(event) {
295
329
  const body = this._refs.body;
296
330
  return event.composedPath().find((target) => target instanceof HTMLTableRowElement && target.parentElement === body && target.dataset.index !== void 0);
297
331
  }
298
- opensOnPress(event, row) {
299
- const path = event.composedPath();
300
- const chevron = row.querySelector("button.expand");
301
- if (chevron === null) return false;
332
+ /**
333
+ * Whether a press is on the row itself: not on a control in it (a link, a button, its chevron), nor in its
334
+ * selection cell, nor the end of a drag that selected text. Those keep their press for themselves.
335
+ */
336
+ isOnRowItself(event, row) {
302
337
  const select = row.querySelector(".select-cell");
303
- const elsewhere = startedOnControl(event, row) || select !== null && path.includes(select) || isSelectingText();
304
- return path.includes(chevron) || !elsewhere;
338
+ const onSelectCell = select !== null && event.composedPath().includes(select);
339
+ return !(startedOnControl(event, row) || onSelectCell || isSelectingText());
340
+ }
341
+ /** An expandable row opens on a press on itself, and on its chevron. */
342
+ opensOnPress(event, row, onRow) {
343
+ const chevron = row.querySelector("button.expand");
344
+ return chevron !== null && (onRow || event.composedPath().includes(chevron));
305
345
  }
306
346
  renderMaxHeight(value) {
307
347
  const height = /^\d+(\.\d+)?$/.test(value.trim()) ? `${value.trim()}px` : value;
@@ -398,6 +438,7 @@ var JlTable = class extends JlElement {
398
438
  setView(drawn) {
399
439
  this._view.drawn = drawn;
400
440
  this._view.byKey = Map.groupBy(drawn, ({ key }) => key);
441
+ this._view.keys = [];
401
442
  this._view.shown = NO_ROW_STATES();
402
443
  }
403
444
  /** The rows in the order of the sort, whose keys the select-all box goes by from now on. */
@@ -503,9 +544,6 @@ var JlTable = class extends JlElement {
503
544
  })
504
545
  });
505
546
  }
506
- keyOf(row) {
507
- return this._view.drawn[Number(row.dataset.index)]?.key;
508
- }
509
547
  /**
510
548
  * Draws a state on the rows whose keys came into it or left it since it was last drawn: checking or opening one
511
549
  * row changes that row alone, whatever the number of rows.
@@ -3,8 +3,9 @@ import type { DownloadOptions, DownloadResult, DownloadTexts, ToasterPlacement,
3
3
  export declare const TOASTER_PLACEMENTS: readonly ToasterPlacement[];
4
4
  /**
5
5
  * The corner of the window where notifications stack, newest nearest the edge, at most `max` at a time. It lives in
6
- * the top layer, so it shows over open dialogs, and its live region reads new toasts to screen readers. Pages
7
- * usually call `toast({ heading, text, tone })`, which finds or makes the page's toaster.
6
+ * the top layer, so it shows over open dialogs, and its live region reads new toasts to screen readers. While one of
7
+ * jlib's modals shows, the toaster sits inside it, where its toasts can be pressed. Pages usually call
8
+ * `toast({ heading, text, tone })`, which finds or makes the page's toaster.
8
9
  */
9
10
  export declare class JlToaster extends JlElement {
10
11
  static readonly selector = "jl-toaster";
@@ -23,6 +24,8 @@ export declare class JlToaster extends JlElement {
23
24
  set(setter: string | ((prevState: string) => string)): void;
24
25
  }>>;
25
26
  private readonly _watched;
27
+ /** Where the toaster stood before it moved into a modal: it goes back there. */
28
+ private readonly _home;
26
29
  private readonly _refs;
27
30
  /**
28
31
  * Shows a notification. It stays 5 seconds unless `duration` says otherwise, 8 for an error or with an action;
@@ -34,6 +37,14 @@ export declare class JlToaster extends JlElement {
34
37
  protected drawTexts(): void;
35
38
  onConnect(): void;
36
39
  onDisconnect(): void;
40
+ /**
41
+ * A modal makes everything outside it inert, the top layer included: a toast shown over one could not be pressed,
42
+ * and a click on it reached the modal's backdrop. While a modal shows, the toaster sits inside the one on top; it
43
+ * goes back to its place when the last one closes.
44
+ */
45
+ private followModal;
46
+ private moveInto;
47
+ private moveHome;
37
48
  private toasts;
38
49
  /** The newest `max` toasts show; the older ones wait. A dismissed toast leaves the toaster. */
39
50
  private renderStack;
@@ -7,6 +7,7 @@ import { registerIcons } from "../lib/icons.js";
7
7
  import { formatDuration } from "../lib/time.js";
8
8
  import { formatFileSize } from "../lib/files.js";
9
9
  import { JlToast } from "../molecules/jl-toast.js";
10
+ import { modalBus, topModal } from "../lib/modal.js";
10
11
  import { answerError, dispositionFileName, readWithProgress, saveBlob, urlFileName } from "../lib/download.js";
11
12
  import jl_toaster_default from "./jl-toaster.css.js";
12
13
  import { css } from "@jadis/core";
@@ -46,10 +47,12 @@ var TOAST_SETTERS = {
46
47
  function updateToast(toast, changes) {
47
48
  for (const key of Object.keys(changes)) TOAST_SETTERS[key](toast, changes[key]);
48
49
  }
50
+ var connectedToasters = /* @__PURE__ */ new Set();
49
51
  /**
50
52
  * The corner of the window where notifications stack, newest nearest the edge, at most `max` at a time. It lives in
51
- * the top layer, so it shows over open dialogs, and its live region reads new toasts to screen readers. Pages
52
- * usually call `toast({ heading, text, tone })`, which finds or makes the page's toaster.
53
+ * the top layer, so it shows over open dialogs, and its live region reads new toasts to screen readers. While one of
54
+ * jlib's modals shows, the toaster sits inside it, where its toasts can be pressed. Pages usually call
55
+ * `toast({ heading, text, tone })`, which finds or makes the page's toaster.
53
56
  */
54
57
  var JlToaster = class extends JlElement {
55
58
  static selector = "jl-toaster";
@@ -65,6 +68,11 @@ var JlToaster = class extends JlElement {
65
68
  /** The region's name for screen readers. */
66
69
  label = this.useChange("", () => this.drawTexts(), { attribute: "label" });
67
70
  _watched = /* @__PURE__ */ new WeakSet();
71
+ /** Where the toaster stood before it moved into a modal: it goes back there. */
72
+ _home = {
73
+ next: null,
74
+ parent: null
75
+ };
68
76
  _refs = this.useRefs((ref) => ({
69
77
  region: ref(".region"),
70
78
  slot: ref("slot")
@@ -116,11 +124,45 @@ var JlToaster = class extends JlElement {
116
124
  onConnect() {
117
125
  this.renderStack();
118
126
  this.on(this._refs.slot, "slotchange", () => this.renderStack());
127
+ connectedToasters.add(this);
128
+ this.followModal();
129
+ this.onBus(modalBus, "change", () => this.followModal());
119
130
  }
120
131
  onDisconnect() {
132
+ connectedToasters.delete(this);
121
133
  const region = this._refs.region;
122
134
  if (region.matches(OPEN)) region.hidePopover();
123
135
  }
136
+ /**
137
+ * A modal makes everything outside it inert, the top layer included: a toast shown over one could not be pressed,
138
+ * and a click on it reached the modal's backdrop. While a modal shows, the toaster sits inside the one on top; it
139
+ * goes back to its place when the last one closes.
140
+ */
141
+ followModal() {
142
+ const modal = topModal();
143
+ if (modal === void 0) {
144
+ this.moveHome();
145
+ return;
146
+ }
147
+ this.moveInto(modal);
148
+ }
149
+ moveInto(modal) {
150
+ if (this.parentNode === modal) return;
151
+ if (this._home.parent === null) {
152
+ this._home.parent = this.parentNode;
153
+ this._home.next = this.nextSibling;
154
+ }
155
+ modal.append(this);
156
+ this.renderStack();
157
+ }
158
+ moveHome() {
159
+ const { next, parent } = this._home;
160
+ if (parent === null) return;
161
+ this._home.parent = null;
162
+ this._home.next = null;
163
+ parent.insertBefore(this, next?.parentNode === parent ? next : null);
164
+ this.renderStack();
165
+ }
124
166
  toasts() {
125
167
  return [...this.children].filter((child) => child instanceof JlToast && !child.hidden);
126
168
  }
@@ -165,9 +207,10 @@ var JlToaster = class extends JlElement {
165
207
  }
166
208
  };
167
209
  JlToaster.register();
168
- /** The page's toaster: the first one in the document, or a new one at the end of the body. */
210
+ /** The page's toaster: the first one connected, or in the document, or a new one at the end of the body. */
169
211
  function pageToaster() {
170
- const found = document.querySelector(JlToaster.selector);
212
+ const [connected] = connectedToasters;
213
+ const found = connected ?? document.querySelector(JlToaster.selector);
171
214
  if (found !== null) return found;
172
215
  const toaster = new JlToaster();
173
216
  document.body.append(toaster);