stimeo-ui 0.18.2 → 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 (72) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +33 -0
  3. data/dist/controllers/alert_dialog_controller.js +246 -42
  4. data/dist/controllers/auto_submit_controller.js +26 -5
  5. data/dist/controllers/avatar_controller.js +29 -9
  6. data/dist/controllers/breadcrumb_controller.js +205 -17
  7. data/dist/controllers/bulk_select_controller.js +25 -4
  8. data/dist/controllers/calendar_controller.js +242 -7
  9. data/dist/controllers/carousel_controller.js +70 -15
  10. data/dist/controllers/character_counter_controller.js +26 -5
  11. data/dist/controllers/collapsible_controller.js +35 -8
  12. data/dist/controllers/combobox_controller.js +84 -20
  13. data/dist/controllers/command_palette_controller.js +296 -77
  14. data/dist/controllers/confirm_controller.js +225 -34
  15. data/dist/controllers/context_menu_controller.js +58 -29
  16. data/dist/controllers/currency_input_controller.js +1 -1
  17. data/dist/controllers/data_grid_controller.js +196 -9
  18. data/dist/controllers/date_range_picker_controller.js +25 -4
  19. data/dist/controllers/dialog_controller.js +252 -45
  20. data/dist/controllers/dismissible_controller.js +57 -11
  21. data/dist/controllers/drawer_controller.js +284 -58
  22. data/dist/controllers/dropdown_controller.js +63 -51
  23. data/dist/controllers/editable_controller.js +69 -6
  24. data/dist/controllers/empty_state_controller.js +187 -4
  25. data/dist/controllers/file_dropzone_controller.js +300 -12
  26. data/dist/controllers/filter_controller.js +194 -5
  27. data/dist/controllers/flash_controller.js +199 -12
  28. data/dist/controllers/focus_controller.js +195 -23
  29. data/dist/controllers/form_field_controller.js +65 -9
  30. data/dist/controllers/frame_loading_controller.js +25 -4
  31. data/dist/controllers/hover_card_controller.js +107 -38
  32. data/dist/controllers/input_mask_controller.js +1 -1
  33. data/dist/controllers/listbox_controller.js +94 -36
  34. data/dist/controllers/menu_controller.js +44 -23
  35. data/dist/controllers/menubar_controller.js +228 -46
  36. data/dist/controllers/meter_controller.js +25 -4
  37. data/dist/controllers/multi_select_controller.js +110 -42
  38. data/dist/controllers/nested_form_controller.js +258 -9
  39. data/dist/controllers/network_status_controller.js +25 -4
  40. data/dist/controllers/number_input_controller.js +26 -5
  41. data/dist/controllers/otp_controller.js +26 -5
  42. data/dist/controllers/overflow_menu_controller.js +183 -22
  43. data/dist/controllers/pagination_controller.js +179 -22
  44. data/dist/controllers/password_reveal_controller.js +25 -4
  45. data/dist/controllers/popover_controller.js +454 -34
  46. data/dist/controllers/progress_controller.js +25 -4
  47. data/dist/controllers/radio_group_controller.js +195 -40
  48. data/dist/controllers/rating_controller.js +58 -10
  49. data/dist/controllers/read_more_controller.js +191 -25
  50. data/dist/controllers/roving_controller.js +197 -6
  51. data/dist/controllers/scroll_area_controller.js +50 -12
  52. data/dist/controllers/scroll_visibility_controller.js +25 -4
  53. data/dist/controllers/scrollspy_controller.js +179 -3
  54. data/dist/controllers/separator_controller.js +25 -4
  55. data/dist/controllers/sidebar_controller.js +290 -93
  56. data/dist/controllers/skeleton_controller.js +25 -4
  57. data/dist/controllers/spinner_controller.js +25 -4
  58. data/dist/controllers/step_indicator_controller.js +181 -6
  59. data/dist/controllers/stepper_controller.js +188 -6
  60. data/dist/controllers/sticky_observer_controller.js +25 -4
  61. data/dist/controllers/submit_once_controller.js +25 -4
  62. data/dist/controllers/tabs_controller.js +189 -3
  63. data/dist/controllers/tags_input_controller.js +210 -9
  64. data/dist/controllers/theme_controller.js +192 -5
  65. data/dist/controllers/toast_controller.js +478 -16
  66. data/dist/controllers/toggle_group_controller.js +198 -35
  67. data/dist/controllers/toolbar_controller.js +198 -7
  68. data/dist/controllers/tooltip_controller.js +243 -45
  69. data/dist/controllers/tree_view_controller.js +200 -8
  70. data/dist/index.js +1764 -739
  71. data/lib/stimeo/ui/version.rb +1 -1
  72. metadata +2 -2
@@ -22,6 +22,24 @@ function actionSource(source) {
22
22
  };
23
23
  }
24
24
 
25
+ function fillTemplate(template, values) {
26
+ return template.replace(/\{([a-zA-Z][a-zA-Z0-9]*)\}/g, (match, name) => {
27
+ const replacement = Object.hasOwn(values, name) ? values[name] : void 0;
28
+ return replacement === void 0 ? match : String(replacement);
29
+ });
30
+ }
31
+
32
+ var afterFocus = /* @__PURE__ */ Symbol.for("stimeo--announcer:after-focus");
33
+ function announce(message, options = {}) {
34
+ const text = message.trim();
35
+ if (text.length === 0) return;
36
+ const event = new CustomEvent("stimeo--announcer:announce", {
37
+ detail: { message: text, assertive: options.assertive === true }
38
+ });
39
+ if (options.afterFocus) event[afterFocus] = true;
40
+ window.dispatchEvent(event);
41
+ }
42
+
25
43
  function isRtl(element) {
26
44
  return window.getComputedStyle(element).direction === "rtl";
27
45
  }
@@ -43,6 +61,180 @@ function hasModifierChord(event) {
43
61
  return event.altKey || event.ctrlKey || event.metaKey || event.shiftKey;
44
62
  }
45
63
 
64
+ function setAttributeIfChanged(element, name, value, beforeWrite) {
65
+ if (element.getAttribute(name) === value) return false;
66
+ beforeWrite?.();
67
+ if (value === null) element.removeAttribute(name);
68
+ else element.setAttribute(name, value);
69
+ return true;
70
+ }
71
+
72
+ function sharedRegistry(key, create) {
73
+ const symbol = Symbol.for(key);
74
+ const scope = globalThis;
75
+ const existing = scope[symbol];
76
+ if (existing !== void 0) return existing;
77
+ const registry2 = create();
78
+ Object.defineProperty(globalThis, symbol, { value: registry2 });
79
+ return registry2;
80
+ }
81
+
82
+ var registry = sharedRegistry(
83
+ "stimeo-ui.attribute-lease.registry.v1",
84
+ () => ({ stacks: /* @__PURE__ */ new WeakMap(), names: /* @__PURE__ */ new Map() })
85
+ );
86
+ function isAttributeValue(value) {
87
+ return value === null || typeof value === "string";
88
+ }
89
+ function readLeaseRecord(element, record) {
90
+ try {
91
+ const parsed = JSON.parse(element.getAttribute(record) ?? "null");
92
+ if (!Array.isArray(parsed)) return void 0;
93
+ const [original, written, ...rest] = parsed;
94
+ const linked = rest[0] !== false;
95
+ const beneath = linked ? rest : rest.slice(1);
96
+ if (!beneath.every((under) => typeof under === "string")) return void 0;
97
+ return isAttributeValue(original) && isAttributeValue(written) ? { original, written, linked, beneath } : void 0;
98
+ } catch {
99
+ return void 0;
100
+ }
101
+ }
102
+ function attributeStack(element, attribute) {
103
+ const byAttribute = registry.stacks.get(element) ?? /* @__PURE__ */ new Map();
104
+ registry.stacks.set(element, byAttribute);
105
+ const known = byAttribute.get(attribute);
106
+ if (known) return known;
107
+ const found = [];
108
+ for (const record of registry.names.get(attribute) ?? []) {
109
+ const read = readLeaseRecord(element, record);
110
+ if (read) found.push({ ...read, record });
111
+ }
112
+ const depth = ({ beneath }) => beneath.filter((name) => found.some((other) => other.record === name)).length;
113
+ const stack = found.sort((one, other) => depth(one) - depth(other)).map(({ record, written, original, linked }, index) => ({
114
+ lease: null,
115
+ record,
116
+ written,
117
+ original,
118
+ linked: linked && index > 0
119
+ }));
120
+ byAttribute.set(attribute, stack);
121
+ return stack;
122
+ }
123
+ function findHold(stack, lease, record) {
124
+ return stack.find((held) => held.lease === lease) ?? stack.find((held) => held.lease === null && held.record === record);
125
+ }
126
+ var AttributeLease = class {
127
+ #attribute;
128
+ #record;
129
+ #base;
130
+ #preserveAuthor;
131
+ #held = /* @__PURE__ */ new Set();
132
+ constructor(attribute, owner, options = {}) {
133
+ this.#attribute = attribute;
134
+ this.#record = `data-${owner}-${attribute}-lease`;
135
+ this.#base = options.base === true;
136
+ this.#preserveAuthor = options.preserveAuthor === true;
137
+ const names = registry.names;
138
+ names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
139
+ }
140
+ write(element, value, beforeWrite) {
141
+ const stack = attributeStack(element, this.#attribute);
142
+ const hold = this.#take(stack) ?? this.#acquire(element, stack);
143
+ this.#held.add(element);
144
+ const shows = !this.#covered(element, stack, hold);
145
+ hold.written = value;
146
+ this.#mark(element, stack);
147
+ if (shows) this.#reflect(element, value, beforeWrite);
148
+ }
149
+ adopt(element, options = {}) {
150
+ const known = registry.stacks.get(element)?.has(this.#attribute);
151
+ if (!this.#held.has(element) && !known && !element.hasAttribute(this.#record)) return false;
152
+ const stack = attributeStack(element, this.#attribute);
153
+ const hold = this.#take(stack);
154
+ if (!hold) return false;
155
+ const current = element.getAttribute(this.#attribute);
156
+ if (options.ifChanged && (current === hold.written || this.#covered(element, stack, hold))) {
157
+ return false;
158
+ }
159
+ this.#held.add(element);
160
+ hold.original = current;
161
+ hold.linked = false;
162
+ for (const above of stack.slice(stack.indexOf(hold) + 1)) {
163
+ if (!above.linked) break;
164
+ above.original = current;
165
+ }
166
+ this.#mark(element, stack);
167
+ return true;
168
+ }
169
+ return(element) {
170
+ const held = this.#held.delete(element);
171
+ const known = registry.stacks.get(element)?.has(this.#attribute);
172
+ const stack = held || known || element.hasAttribute(this.#record) ? attributeStack(element, this.#attribute) : [];
173
+ const hold = this.#take(stack);
174
+ if (!hold) return false;
175
+ const carries = element.getAttribute(this.#attribute) === hold.written;
176
+ const owns = carries && !this.#covered(element, stack, hold);
177
+ const index = stack.indexOf(hold);
178
+ stack.splice(index, 1);
179
+ const above = stack[index];
180
+ if (above) above.linked &&= hold.linked;
181
+ this.#mark(element, stack);
182
+ if (!owns) return true;
183
+ const below = hold.linked ? stack[index - 1] : void 0;
184
+ this.#reflect(element, below ? below.written : hold.original);
185
+ return true;
186
+ }
187
+ returnAll() {
188
+ for (const element of Array.from(this.#held)) this.return(element);
189
+ }
190
+ #take(stack) {
191
+ const hold = findHold(stack, this, this.#record);
192
+ if (hold) hold.lease = this;
193
+ return hold;
194
+ }
195
+ #acquire(element, stack) {
196
+ const current = element.getAttribute(this.#attribute);
197
+ const top = stack.at(-1);
198
+ const bottom = stack[0];
199
+ const over = top?.written === current ? top : void 0;
200
+ const from = this.#base ? this.#preserveAuthor && !stack.some((held) => held.written === current) ? void 0 : bottom : over;
201
+ const hold = {
202
+ lease: this,
203
+ record: this.#record,
204
+ written: current,
205
+ original: from ? from.original : current,
206
+ linked: !this.#base && over !== void 0
207
+ };
208
+ if (this.#base && bottom) {
209
+ bottom.linked = true;
210
+ stack.unshift(hold);
211
+ } else stack.push(hold);
212
+ return hold;
213
+ }
214
+ #covered(element, stack, hold) {
215
+ const current = element.getAttribute(this.#attribute);
216
+ return stack.slice(stack.indexOf(hold) + 1).some((above) => above.written === current);
217
+ }
218
+ #mark(element, stack) {
219
+ const records = /* @__PURE__ */ new Map([[this.#record, null]]);
220
+ stack.forEach((hold, index) => {
221
+ const names = stack.slice(0, index).map((under) => under.record);
222
+ const beneath = [...new Set(names.reverse())].filter((name) => name !== hold.record);
223
+ const marker = hold.linked || beneath.length === 0 ? [] : [false];
224
+ records.set(
225
+ hold.record,
226
+ hold.written === hold.original && beneath.length === 0 && index === stack.length - 1 ? null : JSON.stringify([hold.original, hold.written, ...marker, ...beneath])
227
+ );
228
+ });
229
+ for (const [name, recorded] of records) {
230
+ setAttributeIfChanged(element, name, recorded);
231
+ }
232
+ }
233
+ #reflect(element, value, beforeWrite) {
234
+ setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
235
+ }
236
+ };
237
+
46
238
  var formatters = /* @__PURE__ */ new WeakMap();
47
239
  function intlFormatter(factory, locale, options, fallbackLocale) {
48
240
  const cache = cacheFor(factory);
@@ -275,13 +467,19 @@ var CalendarController = class _CalendarController extends Controller {
275
467
  min: { type: String, default: "" },
276
468
  max: { type: String, default: "" },
277
469
  weekStart: { type: Number, default: 0 },
278
- locale: { type: String, default: "" }
470
+ locale: { type: String, default: "" },
471
+ announceText: { type: String, default: "" }
279
472
  };
280
473
  static valueConstraints = {
281
474
  weekStart: { finite: true, integer: true, min: 0, max: 6 }
282
475
  };
283
476
  static actions = ["next", "onKeydown", "prev", "select"];
284
477
  static events = ["monthchange", "reconcile", "select"];
478
+ #daySelection = new AttributeLease("aria-selected", this.identifier);
479
+ #dayTabindex = new AttributeLease("tabindex", this.identifier);
480
+ #dayDate = new AttributeLease("data-date", this.identifier);
481
+ #dayOutside = new AttributeLease("data-outside", this.identifier);
482
+ #dayToday = new AttributeLease("data-today", this.identifier);
285
483
  focusedDate = /* @__PURE__ */ new Date();
286
484
  #connected = false;
287
485
  #published = "";
@@ -314,6 +512,9 @@ var CalendarController = class _CalendarController extends Controller {
314
512
  this.#connected = false;
315
513
  this.#repaint.disconnect();
316
514
  this.#settleFocus.cancel();
515
+ if (!(this.element.getAttribute("data-controller") ?? "").split(/\s+/).includes(this.identifier)) {
516
+ this.#returnAllDayLeases();
517
+ }
317
518
  }
318
519
  monthValueChanged() {
319
520
  if (!this.monthValue) return;
@@ -461,15 +662,15 @@ var CalendarController = class _CalendarController extends Controller {
461
662
  if (kept !== void 0) el.setAttribute("aria-disabled", kept);
462
663
  }
463
664
  this.#paintedDates.set(el, dateStr);
464
- el.setAttribute("data-date", dateStr);
665
+ this.#dayDate.write(el, dateStr);
465
666
  el.textContent = String(date.getDate());
466
667
  const isOutside = date.getFullYear() !== year || date.getMonth() !== month - 1;
467
- el.setAttribute("data-outside", String(isOutside));
668
+ this.#dayOutside.write(el, String(isOutside));
468
669
  const todayStr = toISODateString(/* @__PURE__ */ new Date());
469
- el.setAttribute("data-today", String(dateStr === todayStr));
470
- el.setAttribute("aria-selected", String(dateStr === selection));
670
+ this.#dayToday.write(el, String(dateStr === todayStr));
671
+ this.#daySelection.write(el, String(dateStr === selection));
471
672
  const isFocused = toISODateString(this.focusedDate) === dateStr;
472
- el.setAttribute("tabindex", isFocused ? "0" : "-1");
673
+ this.#dayTabindex.write(el, isFocused ? "0" : "-1");
473
674
  const isDisabled = this.#isDateOutOfBounds(dateStr);
474
675
  if (isDisabled) {
475
676
  if (!el.hasAttribute("aria-disabled")) el.setAttribute(this.#ownedDisabled, "");
@@ -481,7 +682,7 @@ var CalendarController = class _CalendarController extends Controller {
481
682
  }
482
683
  if (!dayElements.some((el) => el.getAttribute("tabindex") === "0")) {
483
684
  const fallback = dayElements.find((el) => el.getAttribute("data-outside") === "false") ?? dayElements[0];
484
- fallback?.setAttribute("tabindex", "0");
685
+ if (fallback) this.#dayTabindex.write(fallback, "0");
485
686
  }
486
687
  const painted = toISOMonthString(monthStart);
487
688
  const previous = this.#paintedMonth;
@@ -536,6 +737,12 @@ var CalendarController = class _CalendarController extends Controller {
536
737
  labelTargetDisconnected() {
537
738
  this.#repaint.schedule();
538
739
  }
740
+ dayTargetDisconnected(day) {
741
+ queueMicrotask(() => {
742
+ if (this.dayTargets.includes(day)) return;
743
+ this.#returnDayLeases(day);
744
+ });
745
+ }
539
746
  fieldTargetConnected(field) {
540
747
  this.#writeField(field, this.#selection);
541
748
  }
@@ -553,6 +760,20 @@ var CalendarController = class _CalendarController extends Controller {
553
760
  this.#fieldWrites.set(field, (this.#fieldWrites.get(field) ?? 0) + 1);
554
761
  return true;
555
762
  }
763
+ #returnDayLeases(day) {
764
+ this.#daySelection.return(day);
765
+ this.#dayTabindex.return(day);
766
+ this.#dayDate.return(day);
767
+ this.#dayOutside.return(day);
768
+ this.#dayToday.return(day);
769
+ }
770
+ #returnAllDayLeases() {
771
+ this.#daySelection.returnAll();
772
+ this.#dayTabindex.returnAll();
773
+ this.#dayDate.returnAll();
774
+ this.#dayOutside.returnAll();
775
+ this.#dayToday.returnAll();
776
+ }
556
777
  #mirrorFields(painted, selection, reconciled) {
557
778
  const ownMove = this.#ownMove;
558
779
  this.#ownMove = false;
@@ -584,6 +805,20 @@ var CalendarController = class _CalendarController extends Controller {
584
805
  this.#repaintKeepingFocus();
585
806
  if (!changed || move !== this.#selectionMoves) return;
586
807
  this.dispatch("select", { detail: { date: dateStr, reason } });
808
+ if (selected && move === this.#selectionMoves && this.#selection === dateStr) {
809
+ this.#announceSelection(selected);
810
+ }
811
+ }
812
+ #announceSelection(date) {
813
+ const formatter = intlFormatter(
814
+ Intl.DateTimeFormat,
815
+ resolveLocale(this.element, this.localeValue),
816
+ { dateStyle: "long" },
817
+ "en"
818
+ );
819
+ announce(fillTemplate(this.announceTextValue, { date: formatter.format(date) }), {
820
+ afterFocus: true
821
+ });
587
822
  }
588
823
  #focusAndNavigateToDate(date) {
589
824
  this.focusedDate = date;
@@ -43,6 +43,7 @@ function hasModifierChord(event) {
43
43
 
44
44
  function setAttributeIfChanged(element, name, value, beforeWrite) {
45
45
  if (element.getAttribute(name) === value) return false;
46
+ beforeWrite?.();
46
47
  if (value === null) element.removeAttribute(name);
47
48
  else element.setAttribute(name, value);
48
49
  return true;
@@ -116,14 +117,34 @@ var AttributeLease = class {
116
117
  const names = registry.names;
117
118
  names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
118
119
  }
119
- write(element, value) {
120
+ write(element, value, beforeWrite) {
120
121
  const stack = attributeStack(element, this.#attribute);
121
122
  const hold = this.#take(stack) ?? this.#acquire(element, stack);
122
123
  this.#held.add(element);
123
124
  const shows = !this.#covered(element, stack, hold);
124
125
  hold.written = value;
125
126
  this.#mark(element, stack);
126
- if (shows) this.#reflect(element, value);
127
+ if (shows) this.#reflect(element, value, beforeWrite);
128
+ }
129
+ adopt(element, options = {}) {
130
+ const known = registry.stacks.get(element)?.has(this.#attribute);
131
+ if (!this.#held.has(element) && !known && !element.hasAttribute(this.#record)) return false;
132
+ const stack = attributeStack(element, this.#attribute);
133
+ const hold = this.#take(stack);
134
+ if (!hold) return false;
135
+ const current = element.getAttribute(this.#attribute);
136
+ if (options.ifChanged && (current === hold.written || this.#covered(element, stack, hold))) {
137
+ return false;
138
+ }
139
+ this.#held.add(element);
140
+ hold.original = current;
141
+ hold.linked = false;
142
+ for (const above of stack.slice(stack.indexOf(hold) + 1)) {
143
+ if (!above.linked) break;
144
+ above.original = current;
145
+ }
146
+ this.#mark(element, stack);
147
+ return true;
127
148
  }
128
149
  return(element) {
129
150
  const held = this.#held.delete(element);
@@ -189,8 +210,8 @@ var AttributeLease = class {
189
210
  setAttributeIfChanged(element, name, recorded);
190
211
  }
191
212
  }
192
- #reflect(element, value) {
193
- setAttributeIfChanged(element, this.#attribute, value);
213
+ #reflect(element, value, beforeWrite) {
214
+ setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
194
215
  }
195
216
  };
196
217
 
@@ -412,8 +433,12 @@ function prefersReducedMotion() {
412
433
 
413
434
  var RovingTabindex = class {
414
435
  #getItems;
415
- constructor(getItems) {
436
+ #write;
437
+ constructor(getItems, write = (item, tabindex) => {
438
+ item.tabIndex = tabindex;
439
+ }) {
416
440
  this.#getItems = getItems;
441
+ this.#write = write;
417
442
  }
418
443
  get activeIndex() {
419
444
  return this.#getItems().findIndex((item) => item.tabIndex === 0);
@@ -422,7 +447,7 @@ var RovingTabindex = class {
422
447
  const { focus = false } = options;
423
448
  const items = options.items ?? this.#getItems();
424
449
  items.forEach((item, i) => {
425
- item.tabIndex = i === index ? 0 : -1;
450
+ this.#write(item, i === index ? 0 : -1);
426
451
  });
427
452
  if (focus) items[index]?.focus();
428
453
  }
@@ -644,7 +669,17 @@ var CarouselController = class _CarouselController extends Controller {
644
669
  "togglePlay"
645
670
  ];
646
671
  static events = ["change", "pause", "play", "reconcile"];
647
- #roving = new RovingTabindex(() => this.pickerTargets);
672
+ #slideState = new AttributeLease("data-state", this.identifier);
673
+ #slideHidden = new AttributeLease("hidden", this.identifier);
674
+ #slideInert = new AttributeLease("inert", this.identifier);
675
+ #pickerSelected = new AttributeLease("aria-selected", this.identifier);
676
+ #pickerTabindex = new AttributeLease("tabindex", this.identifier);
677
+ #roving = new RovingTabindex(
678
+ () => this.pickerTargets,
679
+ (picker, tabindex) => {
680
+ this.#pickerTabindex.write(picker, String(tabindex));
681
+ }
682
+ );
648
683
  #reconcileTargets = new MorphRenderWatcher(() => this.#reconcileTargetSet());
649
684
  #intervals = new SafeInterval();
650
685
  #ariaDisabled = new AttributeLease("aria-disabled", this.identifier);
@@ -719,19 +754,32 @@ var CarouselController = class _CarouselController extends Controller {
719
754
  this.#hiddenPaused = false;
720
755
  this.#activeSlide = null;
721
756
  this.#returnLeases();
757
+ if (!(this.element.getAttribute("data-controller") ?? "").split(/\s+/).includes(this.identifier)) {
758
+ this.#returnTargetLeases();
759
+ }
722
760
  this.#gate.disconnected(this, () => this.#endRun());
723
761
  }
724
- pickerTargetConnected(picker) {
725
- picker.tabIndex = -1;
762
+ pickerTargetConnected() {
726
763
  this.#reconcileTargets.schedule();
727
764
  }
728
- pickerTargetDisconnected() {
765
+ pickerTargetDisconnected(picker) {
766
+ queueMicrotask(() => {
767
+ if (this.pickerTargets.includes(picker)) return;
768
+ this.#pickerSelected.return(picker);
769
+ this.#pickerTabindex.return(picker);
770
+ });
729
771
  this.#reconcileTargets.schedule();
730
772
  }
731
773
  slideTargetConnected() {
732
774
  this.#reconcileTargets.schedule();
733
775
  }
734
- slideTargetDisconnected() {
776
+ slideTargetDisconnected(slide) {
777
+ queueMicrotask(() => {
778
+ if (this.slideTargets.includes(slide)) return;
779
+ this.#slideState.return(slide);
780
+ this.#slideHidden.return(slide);
781
+ this.#slideInert.return(slide);
782
+ });
735
783
  this.#reconcileTargets.schedule();
736
784
  }
737
785
  viewportTargetConnected() {
@@ -941,13 +989,13 @@ var CarouselController = class _CarouselController extends Controller {
941
989
  this.#activeSlide = this.slideTargets[this.#index] ?? null;
942
990
  this.slideTargets.forEach((slide, i) => {
943
991
  const active = i === this.#index;
944
- setAttributeIfChanged(slide, "data-state", active ? "active" : "inactive");
945
- if (slide.hidden !== !active) slide.hidden = !active;
946
- slide.toggleAttribute("inert", !active);
992
+ this.#slideState.write(slide, active ? "active" : "inactive");
993
+ this.#slideHidden.write(slide, active ? null : "");
994
+ this.#slideInert.write(slide, active ? null : "");
947
995
  });
948
996
  const pickerIndex = Math.min(this.#index, this.pickerTargets.length - 1);
949
997
  this.pickerTargets.forEach((picker, i) => {
950
- setAttributeIfChanged(picker, "aria-selected", i === pickerIndex ? "true" : "false");
998
+ this.#pickerSelected.write(picker, i === pickerIndex ? "true" : "false");
951
999
  });
952
1000
  this.#syncStepControls();
953
1001
  this.#roving.setActive(pickerIndex, { focus });
@@ -1050,6 +1098,13 @@ var CarouselController = class _CarouselController extends Controller {
1050
1098
  this.#ariaLive.returnAll();
1051
1099
  this.#ariaAtomic.returnAll();
1052
1100
  }
1101
+ #returnTargetLeases() {
1102
+ this.#slideState.returnAll();
1103
+ this.#slideHidden.returnAll();
1104
+ this.#slideInert.returnAll();
1105
+ this.#pickerSelected.returnAll();
1106
+ this.#pickerTabindex.returnAll();
1107
+ }
1053
1108
  get #safeInterval() {
1054
1109
  return this.#numbers.read(
1055
1110
  this,
@@ -20,6 +20,7 @@ function announce(message, options = {}) {
20
20
 
21
21
  function setAttributeIfChanged(element, name, value, beforeWrite) {
22
22
  if (element.getAttribute(name) === value) return false;
23
+ beforeWrite?.();
23
24
  if (value === null) element.removeAttribute(name);
24
25
  else element.setAttribute(name, value);
25
26
  return true;
@@ -93,14 +94,34 @@ var AttributeLease = class {
93
94
  const names = registry.names;
94
95
  names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
95
96
  }
96
- write(element, value) {
97
+ write(element, value, beforeWrite) {
97
98
  const stack = attributeStack(element, this.#attribute);
98
99
  const hold = this.#take(stack) ?? this.#acquire(element, stack);
99
100
  this.#held.add(element);
100
101
  const shows = !this.#covered(element, stack, hold);
101
102
  hold.written = value;
102
103
  this.#mark(element, stack);
103
- if (shows) this.#reflect(element, value);
104
+ if (shows) this.#reflect(element, value, beforeWrite);
105
+ }
106
+ adopt(element, options = {}) {
107
+ const known = registry.stacks.get(element)?.has(this.#attribute);
108
+ if (!this.#held.has(element) && !known && !element.hasAttribute(this.#record)) return false;
109
+ const stack = attributeStack(element, this.#attribute);
110
+ const hold = this.#take(stack);
111
+ if (!hold) return false;
112
+ const current = element.getAttribute(this.#attribute);
113
+ if (options.ifChanged && (current === hold.written || this.#covered(element, stack, hold))) {
114
+ return false;
115
+ }
116
+ this.#held.add(element);
117
+ hold.original = current;
118
+ hold.linked = false;
119
+ for (const above of stack.slice(stack.indexOf(hold) + 1)) {
120
+ if (!above.linked) break;
121
+ above.original = current;
122
+ }
123
+ this.#mark(element, stack);
124
+ return true;
104
125
  }
105
126
  return(element) {
106
127
  const held = this.#held.delete(element);
@@ -166,8 +187,8 @@ var AttributeLease = class {
166
187
  setAttributeIfChanged(element, name, recorded);
167
188
  }
168
189
  }
169
- #reflect(element, value) {
170
- setAttributeIfChanged(element, this.#attribute, value);
190
+ #reflect(element, value, beforeWrite) {
191
+ setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
171
192
  }
172
193
  };
173
194
 
@@ -285,7 +306,7 @@ var CompositionTracker = class {
285
306
  this.#confirmedTarget = null;
286
307
  if (confirmed === null || confirmed !== event.target) return false;
287
308
  const inputType = event.inputType;
288
- return !inputType || isCompositionInputType(inputType);
309
+ return inputType ? isCompositionInputType(inputType) : event.isTrusted === true;
289
310
  }
290
311
  #release(target) {
291
312
  target.removeEventListener("compositionstart", this.#handleStart);
@@ -2,6 +2,7 @@ import { Controller } from '@hotwired/stimulus';
2
2
 
3
3
  function setAttributeIfChanged(element, name, value, beforeWrite) {
4
4
  if (element.getAttribute(name) === value) return false;
5
+ beforeWrite?.();
5
6
  if (value === null) element.removeAttribute(name);
6
7
  else element.setAttribute(name, value);
7
8
  return true;
@@ -75,14 +76,34 @@ var AttributeLease = class {
75
76
  const names = registry.names;
76
77
  names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
77
78
  }
78
- write(element, value) {
79
+ write(element, value, beforeWrite) {
79
80
  const stack = attributeStack(element, this.#attribute);
80
81
  const hold = this.#take(stack) ?? this.#acquire(element, stack);
81
82
  this.#held.add(element);
82
83
  const shows = !this.#covered(element, stack, hold);
83
84
  hold.written = value;
84
85
  this.#mark(element, stack);
85
- if (shows) this.#reflect(element, value);
86
+ if (shows) this.#reflect(element, value, beforeWrite);
87
+ }
88
+ adopt(element, options = {}) {
89
+ const known = registry.stacks.get(element)?.has(this.#attribute);
90
+ if (!this.#held.has(element) && !known && !element.hasAttribute(this.#record)) return false;
91
+ const stack = attributeStack(element, this.#attribute);
92
+ const hold = this.#take(stack);
93
+ if (!hold) return false;
94
+ const current = element.getAttribute(this.#attribute);
95
+ if (options.ifChanged && (current === hold.written || this.#covered(element, stack, hold))) {
96
+ return false;
97
+ }
98
+ this.#held.add(element);
99
+ hold.original = current;
100
+ hold.linked = false;
101
+ for (const above of stack.slice(stack.indexOf(hold) + 1)) {
102
+ if (!above.linked) break;
103
+ above.original = current;
104
+ }
105
+ this.#mark(element, stack);
106
+ return true;
86
107
  }
87
108
  return(element) {
88
109
  const held = this.#held.delete(element);
@@ -148,8 +169,8 @@ var AttributeLease = class {
148
169
  setAttributeIfChanged(element, name, recorded);
149
170
  }
150
171
  }
151
- #reflect(element, value) {
152
- setAttributeIfChanged(element, this.#attribute, value);
172
+ #reflect(element, value, beforeWrite) {
173
+ setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
153
174
  }
154
175
  };
155
176
 
@@ -476,6 +497,7 @@ var CollapsibleController = class extends Controller {
476
497
  );
477
498
  #connected = false;
478
499
  #reporting = false;
500
+ #syncedTrigger = null;
479
501
  connect() {
480
502
  this.#connected = true;
481
503
  this.#apply(this.#initialOpen(), false, "api");
@@ -496,6 +518,7 @@ var CollapsibleController = class extends Controller {
496
518
  disconnect() {
497
519
  this.#connected = false;
498
520
  this.#reporting = false;
521
+ this.#syncedTrigger = null;
499
522
  this.#transition.cancel();
500
523
  }
501
524
  triggerTargetConnected(trigger) {
@@ -509,6 +532,7 @@ var CollapsibleController = class extends Controller {
509
532
  if (this.#connected && this.hasTriggerTarget) this.#reconcileTrigger(this.triggerTarget);
510
533
  }
511
534
  #reconcileTrigger(trigger) {
535
+ if (this.hasTriggerTarget && this.triggerTarget === trigger) this.#syncedTrigger = trigger;
512
536
  if (this.hasContentTarget) {
513
537
  this.#expanded.write(
514
538
  trigger,
@@ -549,16 +573,19 @@ var CollapsibleController = class extends Controller {
549
573
  this.#apply(!this.#isOpen, true, stateReasonFor(event));
550
574
  }
551
575
  get #isOpen() {
552
- if (this.hasTriggerTarget) {
553
- return this.triggerTarget.getAttribute("aria-expanded") === "true";
576
+ const trigger = this.hasTriggerTarget ? this.triggerTarget : null;
577
+ if (trigger && (trigger === this.#syncedTrigger || !this.hasContentTarget)) {
578
+ return trigger.getAttribute("aria-expanded") === "true";
554
579
  }
555
580
  return this.hasContentTarget && this.contentTarget.getAttribute("data-state") === "open";
556
581
  }
557
582
  #apply(open, waitForCloseTransition, reason) {
558
583
  const was = this.#isOpen;
559
584
  if (this.hasTriggerTarget) {
560
- this.#expanded.write(this.triggerTarget, open ? "true" : "false");
561
- this.#labels.reflect(this.triggerTarget, open);
585
+ const trigger = this.triggerTarget;
586
+ this.#syncedTrigger = trigger;
587
+ this.#expanded.write(trigger, open ? "true" : "false");
588
+ this.#labels.reflect(trigger, open);
562
589
  }
563
590
  if (this.hasContentTarget) {
564
591
  const content = this.contentTarget;