stimeo-ui 0.18.1 → 0.19.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 (90) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +54 -0
  3. data/dist/cable/index.js +6 -5
  4. data/dist/controllers/alert_dialog_controller.js +324 -76
  5. data/dist/controllers/announcer_controller.js +22 -9
  6. data/dist/controllers/auto_submit_controller.js +103 -16
  7. data/dist/controllers/avatar_controller.js +29 -9
  8. data/dist/controllers/breadcrumb_controller.js +205 -17
  9. data/dist/controllers/bulk_select_controller.js +31 -13
  10. data/dist/controllers/calendar_controller.js +242 -7
  11. data/dist/controllers/carousel_controller.js +70 -15
  12. data/dist/controllers/character_counter_controller.js +103 -16
  13. data/dist/controllers/clipboard_controller.js +6 -5
  14. data/dist/controllers/collapsible_controller.js +35 -8
  15. data/dist/controllers/combobox_controller.js +155 -26
  16. data/dist/controllers/command_palette_controller.js +445 -117
  17. data/dist/controllers/conditional_fields_controller.js +84 -44
  18. data/dist/controllers/confirm_controller.js +303 -68
  19. data/dist/controllers/context_menu_controller.js +59 -30
  20. data/dist/controllers/countdown_controller.js +6 -5
  21. data/dist/controllers/currency_input_controller.js +72 -7
  22. data/dist/controllers/data_grid_controller.js +273 -51
  23. data/dist/controllers/date_range_picker_controller.js +27 -5
  24. data/dist/controllers/dialog_controller.js +330 -79
  25. data/dist/controllers/direct_upload_controller.js +6 -5
  26. data/dist/controllers/dismissible_controller.js +68 -18
  27. data/dist/controllers/drawer_controller.js +362 -92
  28. data/dist/controllers/dropdown_controller.js +64 -52
  29. data/dist/controllers/editable_controller.js +140 -12
  30. data/dist/controllers/empty_state_controller.js +193 -9
  31. data/dist/controllers/file_dropzone_controller.js +313 -23
  32. data/dist/controllers/filter_controller.js +194 -5
  33. data/dist/controllers/flash_controller.js +205 -17
  34. data/dist/controllers/focus_controller.js +273 -57
  35. data/dist/controllers/form_field_controller.js +71 -14
  36. data/dist/controllers/form_validation_controller.js +11 -7
  37. data/dist/controllers/frame_loading_controller.js +75 -20
  38. data/dist/controllers/hover_card_controller.js +108 -39
  39. data/dist/controllers/input_mask_controller.js +95 -37
  40. data/dist/controllers/intersection_controller.js +61 -29
  41. data/dist/controllers/lazy_frame_controller.js +61 -29
  42. data/dist/controllers/listbox_controller.js +174 -83
  43. data/dist/controllers/local_time_controller.js +1 -7
  44. data/dist/controllers/menu_controller.js +45 -24
  45. data/dist/controllers/menubar_controller.js +232 -52
  46. data/dist/controllers/meter_controller.js +31 -9
  47. data/dist/controllers/multi_select_controller.js +195 -62
  48. data/dist/controllers/navigation_menu_controller.js +1 -1
  49. data/dist/controllers/nested_form_controller.js +275 -21
  50. data/dist/controllers/network_status_controller.js +31 -9
  51. data/dist/controllers/number_input_controller.js +180 -71
  52. data/dist/controllers/otp_controller.js +97 -11
  53. data/dist/controllers/overflow_menu_controller.js +190 -24
  54. data/dist/controllers/pagination_controller.js +186 -24
  55. data/dist/controllers/password_reveal_controller.js +25 -4
  56. data/dist/controllers/password_strength_controller.js +6 -5
  57. data/dist/controllers/popover_controller.js +466 -42
  58. data/dist/controllers/progress_controller.js +31 -9
  59. data/dist/controllers/radio_group_controller.js +279 -88
  60. data/dist/controllers/range_slider_controller.js +72 -54
  61. data/dist/controllers/rating_controller.js +58 -10
  62. data/dist/controllers/read_more_controller.js +191 -25
  63. data/dist/controllers/relative_time_controller.js +1 -7
  64. data/dist/controllers/roving_controller.js +204 -8
  65. data/dist/controllers/scroll_area_controller.js +61 -19
  66. data/dist/controllers/scroll_visibility_controller.js +25 -4
  67. data/dist/controllers/scrollspy_controller.js +240 -32
  68. data/dist/controllers/separator_controller.js +97 -58
  69. data/dist/controllers/sidebar_controller.js +368 -127
  70. data/dist/controllers/skeleton_controller.js +75 -20
  71. data/dist/controllers/slider_controller.js +72 -54
  72. data/dist/controllers/sortable_controller.js +6 -5
  73. data/dist/controllers/spinner_controller.js +75 -20
  74. data/dist/controllers/step_indicator_controller.js +181 -6
  75. data/dist/controllers/stepper_controller.js +188 -6
  76. data/dist/controllers/sticky_observer_controller.js +86 -33
  77. data/dist/controllers/submit_once_controller.js +31 -9
  78. data/dist/controllers/switch_controller.js +84 -44
  79. data/dist/controllers/tabs_controller.js +189 -3
  80. data/dist/controllers/tags_input_controller.js +293 -29
  81. data/dist/controllers/theme_controller.js +192 -5
  82. data/dist/controllers/time_picker_controller.js +77 -42
  83. data/dist/controllers/toast_controller.js +478 -16
  84. data/dist/controllers/toggle_group_controller.js +282 -79
  85. data/dist/controllers/toolbar_controller.js +276 -15
  86. data/dist/controllers/tooltip_controller.js +244 -46
  87. data/dist/controllers/tree_view_controller.js +287 -57
  88. data/dist/index.js +2258 -1016
  89. data/lib/stimeo/ui/version.rb +1 -1
  90. metadata +2 -2
@@ -22,6 +22,180 @@ function actionSource(source) {
22
22
  };
23
23
  }
24
24
 
25
+ function setAttributeIfChanged(element, name, value, beforeWrite) {
26
+ if (element.getAttribute(name) === value) return false;
27
+ beforeWrite?.();
28
+ if (value === null) element.removeAttribute(name);
29
+ else element.setAttribute(name, value);
30
+ return true;
31
+ }
32
+
33
+ function sharedRegistry(key, create) {
34
+ const symbol = Symbol.for(key);
35
+ const scope = globalThis;
36
+ const existing = scope[symbol];
37
+ if (existing !== void 0) return existing;
38
+ const registry2 = create();
39
+ Object.defineProperty(globalThis, symbol, { value: registry2 });
40
+ return registry2;
41
+ }
42
+
43
+ var registry = sharedRegistry(
44
+ "stimeo-ui.attribute-lease.registry.v1",
45
+ () => ({ stacks: /* @__PURE__ */ new WeakMap(), names: /* @__PURE__ */ new Map() })
46
+ );
47
+ function isAttributeValue(value) {
48
+ return value === null || typeof value === "string";
49
+ }
50
+ function readLeaseRecord(element, record) {
51
+ try {
52
+ const parsed = JSON.parse(element.getAttribute(record) ?? "null");
53
+ if (!Array.isArray(parsed)) return void 0;
54
+ const [original, written, ...rest] = parsed;
55
+ const linked = rest[0] !== false;
56
+ const beneath = linked ? rest : rest.slice(1);
57
+ if (!beneath.every((under) => typeof under === "string")) return void 0;
58
+ return isAttributeValue(original) && isAttributeValue(written) ? { original, written, linked, beneath } : void 0;
59
+ } catch {
60
+ return void 0;
61
+ }
62
+ }
63
+ function attributeStack(element, attribute) {
64
+ const byAttribute = registry.stacks.get(element) ?? /* @__PURE__ */ new Map();
65
+ registry.stacks.set(element, byAttribute);
66
+ const known = byAttribute.get(attribute);
67
+ if (known) return known;
68
+ const found = [];
69
+ for (const record of registry.names.get(attribute) ?? []) {
70
+ const read = readLeaseRecord(element, record);
71
+ if (read) found.push({ ...read, record });
72
+ }
73
+ const depth = ({ beneath }) => beneath.filter((name) => found.some((other) => other.record === name)).length;
74
+ const stack = found.sort((one, other) => depth(one) - depth(other)).map(({ record, written, original, linked }, index) => ({
75
+ lease: null,
76
+ record,
77
+ written,
78
+ original,
79
+ linked: linked && index > 0
80
+ }));
81
+ byAttribute.set(attribute, stack);
82
+ return stack;
83
+ }
84
+ function findHold(stack, lease, record) {
85
+ return stack.find((held) => held.lease === lease) ?? stack.find((held) => held.lease === null && held.record === record);
86
+ }
87
+ var AttributeLease = class {
88
+ #attribute;
89
+ #record;
90
+ #base;
91
+ #preserveAuthor;
92
+ #held = /* @__PURE__ */ new Set();
93
+ constructor(attribute, owner, options = {}) {
94
+ this.#attribute = attribute;
95
+ this.#record = `data-${owner}-${attribute}-lease`;
96
+ this.#base = options.base === true;
97
+ this.#preserveAuthor = options.preserveAuthor === true;
98
+ const names = registry.names;
99
+ names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
100
+ }
101
+ write(element, value, beforeWrite) {
102
+ const stack = attributeStack(element, this.#attribute);
103
+ const hold = this.#take(stack) ?? this.#acquire(element, stack);
104
+ this.#held.add(element);
105
+ const shows = !this.#covered(element, stack, hold);
106
+ hold.written = value;
107
+ this.#mark(element, stack);
108
+ if (shows) this.#reflect(element, value, beforeWrite);
109
+ }
110
+ adopt(element, options = {}) {
111
+ const known = registry.stacks.get(element)?.has(this.#attribute);
112
+ if (!this.#held.has(element) && !known && !element.hasAttribute(this.#record)) return false;
113
+ const stack = attributeStack(element, this.#attribute);
114
+ const hold = this.#take(stack);
115
+ if (!hold) return false;
116
+ const current = element.getAttribute(this.#attribute);
117
+ if (options.ifChanged && (current === hold.written || this.#covered(element, stack, hold))) {
118
+ return false;
119
+ }
120
+ this.#held.add(element);
121
+ hold.original = current;
122
+ hold.linked = false;
123
+ for (const above of stack.slice(stack.indexOf(hold) + 1)) {
124
+ if (!above.linked) break;
125
+ above.original = current;
126
+ }
127
+ this.#mark(element, stack);
128
+ return true;
129
+ }
130
+ return(element) {
131
+ const held = this.#held.delete(element);
132
+ const known = registry.stacks.get(element)?.has(this.#attribute);
133
+ const stack = held || known || element.hasAttribute(this.#record) ? attributeStack(element, this.#attribute) : [];
134
+ const hold = this.#take(stack);
135
+ if (!hold) return false;
136
+ const carries = element.getAttribute(this.#attribute) === hold.written;
137
+ const owns = carries && !this.#covered(element, stack, hold);
138
+ const index = stack.indexOf(hold);
139
+ stack.splice(index, 1);
140
+ const above = stack[index];
141
+ if (above) above.linked &&= hold.linked;
142
+ this.#mark(element, stack);
143
+ if (!owns) return true;
144
+ const below = hold.linked ? stack[index - 1] : void 0;
145
+ this.#reflect(element, below ? below.written : hold.original);
146
+ return true;
147
+ }
148
+ returnAll() {
149
+ for (const element of Array.from(this.#held)) this.return(element);
150
+ }
151
+ #take(stack) {
152
+ const hold = findHold(stack, this, this.#record);
153
+ if (hold) hold.lease = this;
154
+ return hold;
155
+ }
156
+ #acquire(element, stack) {
157
+ const current = element.getAttribute(this.#attribute);
158
+ const top = stack.at(-1);
159
+ const bottom = stack[0];
160
+ const over = top?.written === current ? top : void 0;
161
+ const from = this.#base ? this.#preserveAuthor && !stack.some((held) => held.written === current) ? void 0 : bottom : over;
162
+ const hold = {
163
+ lease: this,
164
+ record: this.#record,
165
+ written: current,
166
+ original: from ? from.original : current,
167
+ linked: !this.#base && over !== void 0
168
+ };
169
+ if (this.#base && bottom) {
170
+ bottom.linked = true;
171
+ stack.unshift(hold);
172
+ } else stack.push(hold);
173
+ return hold;
174
+ }
175
+ #covered(element, stack, hold) {
176
+ const current = element.getAttribute(this.#attribute);
177
+ return stack.slice(stack.indexOf(hold) + 1).some((above) => above.written === current);
178
+ }
179
+ #mark(element, stack) {
180
+ const records = /* @__PURE__ */ new Map([[this.#record, null]]);
181
+ stack.forEach((hold, index) => {
182
+ const names = stack.slice(0, index).map((under) => under.record);
183
+ const beneath = [...new Set(names.reverse())].filter((name) => name !== hold.record);
184
+ const marker = hold.linked || beneath.length === 0 ? [] : [false];
185
+ records.set(
186
+ hold.record,
187
+ hold.written === hold.original && beneath.length === 0 && index === stack.length - 1 ? null : JSON.stringify([hold.original, hold.written, ...marker, ...beneath])
188
+ );
189
+ });
190
+ for (const [name, recorded] of records) {
191
+ setAttributeIfChanged(element, name, recorded);
192
+ }
193
+ }
194
+ #reflect(element, value, beforeWrite) {
195
+ setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
196
+ }
197
+ };
198
+
25
199
  function ownerIndex(candidates, node) {
26
200
  if (!(node instanceof Node)) return -1;
27
201
  return candidates.findIndex((candidate) => candidate.contains(node));
@@ -30,6 +204,106 @@ function ownerOf(candidates, node) {
30
204
  return candidates[ownerIndex(candidates, node)] ?? null;
31
205
  }
32
206
 
207
+ var HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
208
+ function inheritsFieldsetDisabled(control) {
209
+ let fieldset = control.closest("fieldset[disabled]");
210
+ while (fieldset) {
211
+ if (fieldset.namespaceURI === HTML_NAMESPACE && fieldset.localName === "fieldset") {
212
+ const legend = Array.from(fieldset.children).find(
213
+ (child) => child.namespaceURI === HTML_NAMESPACE && child.localName === "legend"
214
+ );
215
+ if (!legend?.contains(control)) return true;
216
+ }
217
+ fieldset = fieldset.parentElement?.closest("fieldset[disabled]") ?? null;
218
+ }
219
+ return false;
220
+ }
221
+ function unslotted(element) {
222
+ return element.assignedSlot === null && element.parentElement?.shadowRoot != null;
223
+ }
224
+ function flatTreeParent(element) {
225
+ if (unslotted(element)) return null;
226
+ const parent = element.assignedSlot ?? element.parentNode;
227
+ if (parent instanceof ShadowRoot) return parent.host;
228
+ return parent instanceof Element ? parent : null;
229
+ }
230
+ function flatTreeContains(ancestor, element) {
231
+ for (let node = element; node; node = flatTreeParent(node)) {
232
+ if (node === ancestor) return true;
233
+ }
234
+ return false;
235
+ }
236
+ function canTakeFocus(element) {
237
+ for (let node = element; node; node = flatTreeParent(node)) {
238
+ if (unslotted(node) || node.matches("[hidden], [inert]")) return false;
239
+ }
240
+ if (element instanceof HTMLInputElement && element.type === "hidden") return false;
241
+ if (!("disabled" in element)) return true;
242
+ if (element.disabled) return false;
243
+ return !inheritsFieldsetDisabled(element);
244
+ }
245
+ var TAB_STOP_CANDIDATE_SELECTOR = [
246
+ "a[href]",
247
+ "area[href]",
248
+ "button",
249
+ "input",
250
+ "select",
251
+ "textarea",
252
+ "summary",
253
+ "iframe",
254
+ "audio[controls]",
255
+ "video[controls]",
256
+ "[tabindex]",
257
+ "[contenteditable]"
258
+ ].join(",");
259
+ function isRenderedForFocus(element) {
260
+ const check = element.checkVisibility;
261
+ return typeof check === "function" ? check.call(element, { visibilityProperty: true }) : true;
262
+ }
263
+ function authoredTabindex(element) {
264
+ const value = element.getAttribute("tabindex");
265
+ if (value === null || !/^[+-]?\d+$/.test(value.trim())) return null;
266
+ return Number(value);
267
+ }
268
+ function hasNativeTabStop(element) {
269
+ if (element instanceof HTMLAnchorElement || element instanceof HTMLAreaElement) {
270
+ return element.hasAttribute("href");
271
+ }
272
+ if (element instanceof HTMLButtonElement || element instanceof HTMLSelectElement || element instanceof HTMLTextAreaElement) {
273
+ return true;
274
+ }
275
+ if (element instanceof HTMLInputElement) return element.type !== "hidden";
276
+ if (element instanceof HTMLIFrameElement) return true;
277
+ if (element.tagName === "AUDIO" || element.tagName === "VIDEO") {
278
+ return element.hasAttribute("controls");
279
+ }
280
+ const details = element.parentElement;
281
+ return details instanceof HTMLDetailsElement && Array.from(details.children).find(
282
+ (child) => child.namespaceURI === HTML_NAMESPACE && child.localName === "summary"
283
+ ) === element;
284
+ }
285
+ function hasEditableTabStop(element) {
286
+ const value = element.getAttribute("contenteditable")?.toLowerCase();
287
+ return value === "" || value === "true" || value === "plaintext-only";
288
+ }
289
+ function isTabStop(element) {
290
+ if (!canTakeFocus(element) || !isRenderedForFocus(element)) return false;
291
+ const tabindex = authoredTabindex(element);
292
+ if (tabindex !== null) return tabindex >= 0;
293
+ return hasNativeTabStop(element) || hasEditableTabStop(element);
294
+ }
295
+ function firstTabStop(root) {
296
+ for (const candidate of root.querySelectorAll(TAB_STOP_CANDIDATE_SELECTOR)) {
297
+ if (isTabStop(candidate)) return candidate;
298
+ }
299
+ return null;
300
+ }
301
+ function deepActiveElement(ownerDocument) {
302
+ let active = ownerDocument.activeElement;
303
+ while (active?.shadowRoot?.activeElement) active = active.shadowRoot.activeElement;
304
+ return active;
305
+ }
306
+
33
307
  var ListenerSet = class {
34
308
  #abort = new AbortController();
35
309
  add(target, type, handler, options) {
@@ -308,6 +582,126 @@ var PausableTimers = class {
308
582
  }
309
583
  };
310
584
 
585
+ function queryOpenDescendants(root, selector) {
586
+ const matches = [];
587
+ const roots = [root];
588
+ for (const scope of roots) {
589
+ matches.push(...scope.querySelectorAll(selector));
590
+ if (scope.nodeType === Node.ELEMENT_NODE) {
591
+ const shadow = scope.shadowRoot;
592
+ if (shadow) roots.push(shadow);
593
+ }
594
+ for (const element of scope.querySelectorAll("*")) {
595
+ if (element.shadowRoot) roots.push(element.shadowRoot);
596
+ }
597
+ }
598
+ return matches;
599
+ }
600
+
601
+ function holdsFocus(element) {
602
+ return element.matches(":focus") || deepActiveElement(element.ownerDocument) === element;
603
+ }
604
+ var TabindexLoan = class _TabindexLoan {
605
+ static #registry = sharedRegistry(
606
+ "stimeo-ui.tabindex-loan.registry.v1",
607
+ () => ({ stacks: /* @__PURE__ */ new WeakMap(), names: /* @__PURE__ */ new Set() })
608
+ );
609
+ #value;
610
+ #record;
611
+ #preserveFocus;
612
+ #lent = /* @__PURE__ */ new Set();
613
+ constructor(value, owner, options = {}) {
614
+ this.#value = value;
615
+ this.#record = `data-${owner}-tabindex-loan`;
616
+ this.#preserveFocus = options.preserveFocus === true;
617
+ _TabindexLoan.#registry.names.add(this.#record);
618
+ }
619
+ lend(element, options = {}) {
620
+ const stack = this.#stack(element);
621
+ const current = element.getAttribute("tabindex");
622
+ const held = stack.find((hold) => hold.loan === this) ?? stack.find(
623
+ (hold) => hold.loan === null && hold.record === this.#record && hold.value === this.#value
624
+ );
625
+ const linked = stack.at(-1)?.value === current;
626
+ if (!held && options.onlyIfUnfocusable && (current !== null || element.tabIndex >= 0)) return;
627
+ if (!held && current !== null && !linked) return;
628
+ this.#lent.add(element);
629
+ if (held) held.loan = this;
630
+ else stack.push({ loan: this, record: this.#record, value: this.#value, linked });
631
+ this.#mark(element, stack);
632
+ if (current === null || !held && current !== this.#value) {
633
+ element.setAttribute("tabindex", this.#value);
634
+ }
635
+ }
636
+ return(element) {
637
+ const stack = this.#stack(element);
638
+ const hold = stack.find((held) => held.loan === this) ?? stack.find(
639
+ (held) => held.loan === null && held.record === this.#record && held.value === this.#value
640
+ );
641
+ if (!hold) return false;
642
+ if (!this.#release(element, stack, hold, this.#preserveFocus)) {
643
+ hold.loan = this;
644
+ this.#lent.add(element);
645
+ return false;
646
+ }
647
+ this.#lent.delete(element);
648
+ return true;
649
+ }
650
+ returnAll() {
651
+ for (const element of Array.from(this.#lent)) this.return(element);
652
+ }
653
+ reclaim(element) {
654
+ if (element.getAttribute(this.#record) !== this.#value) return;
655
+ const stack = this.#stack(element);
656
+ const hold = stack.find((held) => held.loan === null && held.record === this.#record);
657
+ if (hold && !holdsFocus(element)) this.#release(element, stack, hold);
658
+ }
659
+ reclaimWithin(root) {
660
+ for (const element of queryOpenDescendants(root, `[${this.#record}]`)) {
661
+ this.reclaim(element);
662
+ }
663
+ }
664
+ #stack(element) {
665
+ const stacks = _TabindexLoan.#registry.stacks;
666
+ const stack = stacks.get(element) ?? this.#seed(element);
667
+ stacks.set(element, stack);
668
+ return stack;
669
+ }
670
+ #seed(element) {
671
+ const current = element.getAttribute("tabindex");
672
+ const holds = [];
673
+ for (const record of _TabindexLoan.#registry.names) {
674
+ const value = element.getAttribute(record);
675
+ if (value !== null) holds.push({ loan: null, record, value, linked: true });
676
+ }
677
+ holds.sort((one, other) => Number(one.value === current) - Number(other.value === current));
678
+ for (const [index, hold] of holds.entries()) hold.linked = index > 0;
679
+ return holds;
680
+ }
681
+ #release(element, stack, hold, preserveFocus = false) {
682
+ const current = element.getAttribute("tabindex");
683
+ const index = stack.indexOf(hold);
684
+ const owns = current === hold.value && !stack.slice(index + 1).some((above2) => above2.value === current);
685
+ if (owns && preserveFocus && holdsFocus(element)) return false;
686
+ stack.splice(index, 1);
687
+ const above = stack[index];
688
+ if (above) above.linked &&= hold.linked;
689
+ this.#mark(element, stack);
690
+ if (!owns) return true;
691
+ const below = hold.linked ? stack[index - 1] : void 0;
692
+ if (!below) element.removeAttribute("tabindex");
693
+ else if (below.value !== current) element.setAttribute("tabindex", below.value);
694
+ return true;
695
+ }
696
+ #mark(element, stack) {
697
+ const records = /* @__PURE__ */ new Map([[this.#record, null]]);
698
+ for (const hold of stack) records.set(hold.record, hold.value);
699
+ for (const [name, recorded] of records) {
700
+ setAttributeIfChanged(element, name, recorded);
701
+ }
702
+ }
703
+ };
704
+
311
705
  function targetSelector(identifier, name) {
312
706
  return `[data-${identifier}-target~="${name}"]`;
313
707
  }
@@ -364,10 +758,13 @@ var ToastController = class _ToastController extends Controller {
364
758
  };
365
759
  static actions = ["dismiss", "onKeydown", "pause", "resume", "show"];
366
760
  static events = ["dismiss", "show"];
367
- #timers = new SafeTimeout();
761
+ #timers = new PausableTimers();
368
762
  #dismiss = new PausableTimers();
369
763
  #taken = /* @__PURE__ */ new Set();
370
764
  #outside = /* @__PURE__ */ new WeakSet();
765
+ #suspended = /* @__PURE__ */ new Set();
766
+ #listInert = new AttributeLease("inert", this.identifier);
767
+ #focusLoan = new TabindexLoan("-1", this.identifier);
371
768
  #phases = /* @__PURE__ */ new WeakMap();
372
769
  #reapply = new MorphRenderWatcher(() => this.#reapplyLimit());
373
770
  #spared = [];
@@ -388,7 +785,8 @@ var ToastController = class _ToastController extends Controller {
388
785
  if (!current.includes(item)) this.#arrivals.delete(item);
389
786
  }
390
787
  this.#reapply.observe(this.element);
391
- this.#connectDelegatedEvents();
788
+ this.#focusLoan.reclaim(this.element);
789
+ this.#settleLists();
392
790
  for (const item of this.itemTargets) {
393
791
  if (!this.#dismiss.tracks(item) && item.dataset.state !== "leaving") {
394
792
  this.#startTimer(item);
@@ -405,6 +803,9 @@ var ToastController = class _ToastController extends Controller {
405
803
  this.#timers.clearAll();
406
804
  this.#dismiss.clearAll();
407
805
  this.#taken.clear();
806
+ this.#suspended.clear();
807
+ this.#listInert.returnAll();
808
+ this.#focusLoan.returnAll();
408
809
  this.#reapply.disconnect();
409
810
  this.#spared = [];
410
811
  this.#pointer.dispose();
@@ -414,15 +815,13 @@ var ToastController = class _ToastController extends Controller {
414
815
  this.#rafHandles.clear();
415
816
  }
416
817
  listTargetConnected() {
417
- if (this.#delegatedList !== this.listTarget) this.#connectDelegatedEvents();
818
+ this.#settleLists();
418
819
  }
419
820
  listTargetDisconnected(element) {
821
+ if (!this.listTargets.includes(element)) this.#listInert.return(element);
420
822
  if (this.#delegatedList === element) this.#disconnectDelegatedEvents();
421
- if (!this.#connected || !this.hasListTarget || this.listTarget === element) return;
422
- if (this.#delegatedList !== this.listTarget) this.#connectDelegatedEvents();
423
- for (const item of this.itemTargets) {
424
- if (this.#outside.has(item)) this.#takeIn(item);
425
- }
823
+ if (!this.#connected || this.hasListTarget && this.listTarget === element) return;
824
+ this.#settleLists();
426
825
  }
427
826
  maxValueChanged() {
428
827
  if (!this.#connected) return;
@@ -434,7 +833,7 @@ var ToastController = class _ToastController extends Controller {
434
833
  }
435
834
  #takeIn(element) {
436
835
  if (this.#taken.has(element) || element.dataset.state === "leaving") return false;
437
- if (element.parentNode !== this.listTarget) {
836
+ if (!this.hasListTarget || element.parentNode !== this.listTarget) {
438
837
  this.#outside.add(element);
439
838
  return false;
440
839
  }
@@ -452,16 +851,21 @@ var ToastController = class _ToastController extends Controller {
452
851
  return true;
453
852
  }
454
853
  itemTargetDisconnected(element) {
854
+ if (!this.#taken.has(element)) return;
855
+ if (this.#suspended.has(element) && this.itemTargets.includes(element) && element.parentElement && this.listTargets.includes(element.parentElement))
856
+ return;
455
857
  const moved = this.#isShown(element) && element.matches(targetSelector(this.identifier, "item"));
456
858
  if (moved) {
457
859
  this.#afterMove(element);
458
860
  return;
459
861
  }
460
862
  this.#taken.delete(element);
863
+ this.#suspended.delete(element);
461
864
  this.#phases.delete(element);
462
865
  if (this.#connected) this.#arrivals.delete(element);
463
866
  element.removeAttribute("data-paused");
464
867
  this.#letGo(element);
868
+ this.#timers.clear(element);
465
869
  this.#cancelAnimation(element);
466
870
  }
467
871
  show(event) {
@@ -540,6 +944,7 @@ var ToastController = class _ToastController extends Controller {
540
944
  item.setAttribute("data-state", phase);
541
945
  }
542
946
  #reapplyLimit() {
947
+ this.#settleLists();
543
948
  for (const item of this.itemTargets) {
544
949
  if (!this.#taken.has(item) || !this.hasListTarget || item.parentNode !== this.listTarget)
545
950
  continue;
@@ -580,7 +985,8 @@ var ToastController = class _ToastController extends Controller {
580
985
  return event?.type === "focusin" || event?.type === "focusout" ? "focus" : "hover";
581
986
  }
582
987
  #startTimer(element) {
583
- if (element.dataset.state === "leaving" || element.parentNode !== this.listTarget) return;
988
+ if (element.dataset.state === "leaving" || !this.hasListTarget || element.parentNode !== this.listTarget)
989
+ return;
584
990
  const armed = this.#safeDuration > 0;
585
991
  if (armed) {
586
992
  this.#dismiss.set(
@@ -593,18 +999,19 @@ var ToastController = class _ToastController extends Controller {
593
999
  else element.removeAttribute("data-paused");
594
1000
  }
595
1001
  #removeWithTransition(element, reason) {
596
- if (element.dataset.state === "leaving" || element.parentNode !== this.listTarget) return;
1002
+ if (element.dataset.state === "leaving" || !this.hasListTarget || element.parentNode !== this.listTarget)
1003
+ return;
597
1004
  this.#letGo(element);
598
1005
  this.#cancelAnimation(element);
599
1006
  this.#setPhase(element, "leaving");
600
1007
  const finalize = () => {
601
- if (element.parentNode !== this.listTarget) return;
1008
+ if (!this.hasListTarget || element.parentNode !== this.listTarget) return;
602
1009
  this.listTarget.removeChild(element);
603
1010
  this.dispatch("dismiss", { detail: { item: element, reason } });
604
1011
  };
605
- const duration = maxTransitionTotalMs(window.getComputedStyle(element));
606
- if (duration > 0) {
607
- this.#timers.set(finalize, duration);
1012
+ const transitionDelay = maxTransitionTotalMs(window.getComputedStyle(element));
1013
+ if (transitionDelay > 0) {
1014
+ this.#timers.set(element, finalize, transitionDelay);
608
1015
  } else {
609
1016
  finalize();
610
1017
  }
@@ -627,7 +1034,7 @@ var ToastController = class _ToastController extends Controller {
627
1034
  #isShown(item) {
628
1035
  return this.#taken.has(item) && this.hasListTarget && item.parentNode === this.listTarget && item.dataset.state !== "leaving";
629
1036
  }
630
- #connectDelegatedEvents(list = this.hasListTarget ? this.listTarget : null) {
1037
+ #connectDelegatedEvents(list) {
631
1038
  this.#disconnectDelegatedEvents();
632
1039
  if (!list) return;
633
1040
  this.#delegatedList = list;
@@ -635,6 +1042,61 @@ var ToastController = class _ToastController extends Controller {
635
1042
  this.#listListeners.add(list, type, this.#onListEvent);
636
1043
  }
637
1044
  }
1045
+ #settleLists() {
1046
+ const [current, ...behind] = this.listTargets;
1047
+ if (current) this.#listInert.return(current);
1048
+ if (this.#delegatedList !== (current ?? null)) this.#connectDelegatedEvents(current ?? null);
1049
+ for (const item of this.#taken) {
1050
+ if (item.parentElement === current) continue;
1051
+ const parent = item.parentElement;
1052
+ if (!parent || !behind.includes(parent)) {
1053
+ this.#outside.add(item);
1054
+ this.#taken.delete(item);
1055
+ this.#suspended.delete(item);
1056
+ this.#phases.delete(item);
1057
+ this.#arrivals.delete(item);
1058
+ this.#letGo(item);
1059
+ this.#timers.clear(item);
1060
+ this.#cancelAnimation(item);
1061
+ item.removeAttribute("data-paused");
1062
+ continue;
1063
+ }
1064
+ if (this.#suspended.has(item)) continue;
1065
+ this.#dismiss.pause(item, "list");
1066
+ this.#timers.pause(item, "list");
1067
+ this.#pointer.cancel(item);
1068
+ this.#cancelAnimation(item);
1069
+ this.#suspended.add(item);
1070
+ }
1071
+ for (const list of behind) {
1072
+ if (flatTreeContains(list, deepActiveElement(this.element.ownerDocument))) {
1073
+ const destination = current ? firstTabStop(current) : null;
1074
+ if (destination) destination.focus();
1075
+ else {
1076
+ this.#focusLoan.lend(this.element);
1077
+ this.element.focus();
1078
+ }
1079
+ }
1080
+ this.#listInert.write(list, "");
1081
+ }
1082
+ if (!this.#connected || !current) return;
1083
+ for (const item of this.itemTargets) {
1084
+ if (item.parentElement !== current) continue;
1085
+ if (this.#suspended.delete(item)) {
1086
+ if (!flatTreeContains(item, deepActiveElement(this.element.ownerDocument)))
1087
+ this.#dismiss.resume(item, "focus");
1088
+ this.#dismiss.resume(item, "hover");
1089
+ this.#readHolds(item);
1090
+ this.#dismiss.resume(item, "list");
1091
+ this.#timers.resume(item, "list");
1092
+ const phase = this.#phases.get(item);
1093
+ if (phase === "entering") this.#setPhase(item, "visible");
1094
+ if (this.#dismiss.isHeld(item) && this.#dismiss.tracks(item))
1095
+ item.setAttribute("data-paused", "true");
1096
+ else item.removeAttribute("data-paused");
1097
+ } else if (this.#outside.has(item)) this.#takeIn(item);
1098
+ }
1099
+ }
638
1100
  #disconnectDelegatedEvents() {
639
1101
  this.#listListeners.dispose();
640
1102
  this.#delegatedList = null;