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
@@ -49,6 +49,172 @@ function setAttributeIfChanged(element, name, value, beforeWrite) {
49
49
  return true;
50
50
  }
51
51
 
52
+ function sharedRegistry(key, create) {
53
+ const symbol = Symbol.for(key);
54
+ const scope = globalThis;
55
+ const existing = scope[symbol];
56
+ if (existing !== void 0) return existing;
57
+ const registry2 = create();
58
+ Object.defineProperty(globalThis, symbol, { value: registry2 });
59
+ return registry2;
60
+ }
61
+
62
+ var registry = sharedRegistry(
63
+ "stimeo-ui.attribute-lease.registry.v1",
64
+ () => ({ stacks: /* @__PURE__ */ new WeakMap(), names: /* @__PURE__ */ new Map() })
65
+ );
66
+ function isAttributeValue(value) {
67
+ return value === null || typeof value === "string";
68
+ }
69
+ function readLeaseRecord(element, record) {
70
+ try {
71
+ const parsed = JSON.parse(element.getAttribute(record) ?? "null");
72
+ if (!Array.isArray(parsed)) return void 0;
73
+ const [original, written, ...rest] = parsed;
74
+ const linked = rest[0] !== false;
75
+ const beneath = linked ? rest : rest.slice(1);
76
+ if (!beneath.every((under) => typeof under === "string")) return void 0;
77
+ return isAttributeValue(original) && isAttributeValue(written) ? { original, written, linked, beneath } : void 0;
78
+ } catch {
79
+ return void 0;
80
+ }
81
+ }
82
+ function attributeStack(element, attribute) {
83
+ const byAttribute = registry.stacks.get(element) ?? /* @__PURE__ */ new Map();
84
+ registry.stacks.set(element, byAttribute);
85
+ const known = byAttribute.get(attribute);
86
+ if (known) return known;
87
+ const found = [];
88
+ for (const record of registry.names.get(attribute) ?? []) {
89
+ const read = readLeaseRecord(element, record);
90
+ if (read) found.push({ ...read, record });
91
+ }
92
+ const depth = ({ beneath }) => beneath.filter((name) => found.some((other) => other.record === name)).length;
93
+ const stack = found.sort((one, other) => depth(one) - depth(other)).map(({ record, written, original, linked }, index) => ({
94
+ lease: null,
95
+ record,
96
+ written,
97
+ original,
98
+ linked: linked && index > 0
99
+ }));
100
+ byAttribute.set(attribute, stack);
101
+ return stack;
102
+ }
103
+ function findHold(stack, lease, record) {
104
+ return stack.find((held) => held.lease === lease) ?? stack.find((held) => held.lease === null && held.record === record);
105
+ }
106
+ var AttributeLease = class {
107
+ #attribute;
108
+ #record;
109
+ #base;
110
+ #preserveAuthor;
111
+ #held = /* @__PURE__ */ new Set();
112
+ constructor(attribute, owner, options = {}) {
113
+ this.#attribute = attribute;
114
+ this.#record = `data-${owner}-${attribute}-lease`;
115
+ this.#base = options.base === true;
116
+ this.#preserveAuthor = options.preserveAuthor === true;
117
+ const names = registry.names;
118
+ names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
119
+ }
120
+ write(element, value, beforeWrite) {
121
+ const stack = attributeStack(element, this.#attribute);
122
+ const hold = this.#take(stack) ?? this.#acquire(element, stack);
123
+ this.#held.add(element);
124
+ const shows = !this.#covered(element, stack, hold);
125
+ hold.written = value;
126
+ this.#mark(element, stack);
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;
148
+ }
149
+ return(element) {
150
+ const held = this.#held.delete(element);
151
+ const known = registry.stacks.get(element)?.has(this.#attribute);
152
+ const stack = held || known || element.hasAttribute(this.#record) ? attributeStack(element, this.#attribute) : [];
153
+ const hold = this.#take(stack);
154
+ if (!hold) return false;
155
+ const carries = element.getAttribute(this.#attribute) === hold.written;
156
+ const owns = carries && !this.#covered(element, stack, hold);
157
+ const index = stack.indexOf(hold);
158
+ stack.splice(index, 1);
159
+ const above = stack[index];
160
+ if (above) above.linked &&= hold.linked;
161
+ this.#mark(element, stack);
162
+ if (!owns) return true;
163
+ const below = hold.linked ? stack[index - 1] : void 0;
164
+ this.#reflect(element, below ? below.written : hold.original);
165
+ return true;
166
+ }
167
+ returnAll() {
168
+ for (const element of Array.from(this.#held)) this.return(element);
169
+ }
170
+ #take(stack) {
171
+ const hold = findHold(stack, this, this.#record);
172
+ if (hold) hold.lease = this;
173
+ return hold;
174
+ }
175
+ #acquire(element, stack) {
176
+ const current = element.getAttribute(this.#attribute);
177
+ const top = stack.at(-1);
178
+ const bottom = stack[0];
179
+ const over = top?.written === current ? top : void 0;
180
+ const from = this.#base ? this.#preserveAuthor && !stack.some((held) => held.written === current) ? void 0 : bottom : over;
181
+ const hold = {
182
+ lease: this,
183
+ record: this.#record,
184
+ written: current,
185
+ original: from ? from.original : current,
186
+ linked: !this.#base && over !== void 0
187
+ };
188
+ if (this.#base && bottom) {
189
+ bottom.linked = true;
190
+ stack.unshift(hold);
191
+ } else stack.push(hold);
192
+ return hold;
193
+ }
194
+ #covered(element, stack, hold) {
195
+ const current = element.getAttribute(this.#attribute);
196
+ return stack.slice(stack.indexOf(hold) + 1).some((above) => above.written === current);
197
+ }
198
+ #mark(element, stack) {
199
+ const records = /* @__PURE__ */ new Map([[this.#record, null]]);
200
+ stack.forEach((hold, index) => {
201
+ const names = stack.slice(0, index).map((under) => under.record);
202
+ const beneath = [...new Set(names.reverse())].filter((name) => name !== hold.record);
203
+ const marker = hold.linked || beneath.length === 0 ? [] : [false];
204
+ records.set(
205
+ hold.record,
206
+ hold.written === hold.original && beneath.length === 0 && index === stack.length - 1 ? null : JSON.stringify([hold.original, hold.written, ...marker, ...beneath])
207
+ );
208
+ });
209
+ for (const [name, recorded] of records) {
210
+ setAttributeIfChanged(element, name, recorded);
211
+ }
212
+ }
213
+ #reflect(element, value, beforeWrite) {
214
+ setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
215
+ }
216
+ };
217
+
52
218
  var AuthoredMutationWatcher = class {
53
219
  #onAuthored;
54
220
  #lifetime = null;
@@ -318,8 +484,12 @@ var MoveCounter = class {
318
484
 
319
485
  var RovingTabindex = class {
320
486
  #getItems;
321
- constructor(getItems) {
487
+ #write;
488
+ constructor(getItems, write = (item, tabindex) => {
489
+ item.tabIndex = tabindex;
490
+ }) {
322
491
  this.#getItems = getItems;
492
+ this.#write = write;
323
493
  }
324
494
  get activeIndex() {
325
495
  return this.#getItems().findIndex((item) => item.tabIndex === 0);
@@ -328,7 +498,7 @@ var RovingTabindex = class {
328
498
  const { focus = false } = options;
329
499
  const items = options.items ?? this.#getItems();
330
500
  items.forEach((item, i) => {
331
- item.tabIndex = i === index ? 0 : -1;
501
+ this.#write(item, i === index ? 0 : -1);
332
502
  });
333
503
  if (focus) items[index]?.focus();
334
504
  }
@@ -345,6 +515,7 @@ function targetSelector(identifier, name) {
345
515
 
346
516
  var ITEM_ATTRIBUTES = [
347
517
  "aria-pressed",
518
+ "tabindex",
348
519
  "data-value",
349
520
  "disabled",
350
521
  "hidden",
@@ -364,11 +535,14 @@ var ToggleGroupController = class extends Controller {
364
535
  };
365
536
  static actions = ["onKeydown", "toggle"];
366
537
  static events = ["change", "reconcile"];
367
- #roving = new RovingTabindex(() => this.#managedTargets);
538
+ #pressed = new AttributeLease("aria-pressed", this.identifier);
539
+ #tabindex = new AttributeLease("tabindex", this.identifier);
540
+ #roving = new RovingTabindex(
541
+ () => this.#managedTargets,
542
+ (item, value) => this.#writeAttribute(item, "tabindex", String(value))
543
+ );
368
544
  #handledEvents = /* @__PURE__ */ new WeakSet();
369
545
  #managedItems = /* @__PURE__ */ new Set();
370
- #originalTabindex = /* @__PURE__ */ new WeakMap();
371
- #ownedPressed = /* @__PURE__ */ new Map();
372
546
  #pass = new MorphRenderWatcher(() => this.#reconcileDom());
373
547
  #observer = new AuthoredMutationWatcher((records) => {
374
548
  this.#releaseAuthoredPressed(records);
@@ -402,6 +576,7 @@ var ToggleGroupController = class extends Controller {
402
576
  this.#observeMutations();
403
577
  }
404
578
  disconnect() {
579
+ this.#releaseAuthoredPressed(this.#observer.take());
405
580
  this.#connectionGeneration += 1;
406
581
  this.#connected = false;
407
582
  this.#pass.disconnect();
@@ -414,9 +589,10 @@ var ToggleGroupController = class extends Controller {
414
589
  this.#pass.schedule();
415
590
  }
416
591
  itemTargetDisconnected(item) {
417
- if (!this.#connected) return;
592
+ if (this.scope.containsElement(item) && this.itemTargets.includes(item)) return;
593
+ this.#releaseAuthoredPressed(this.#observer.take());
418
594
  this.#releaseItem(item);
419
- this.#pass.schedule();
595
+ if (this.#connected) this.#pass.schedule();
420
596
  }
421
597
  modeValueChanged() {
422
598
  this.#pass.schedule();
@@ -570,26 +746,18 @@ var ToggleGroupController = class extends Controller {
570
746
  }
571
747
  if (!this.#managedItems.has(item)) {
572
748
  this.#managedItems.add(item);
573
- this.#originalTabindex.set(item, item.getAttribute("tabindex"));
574
- if (dropFromTabSequence) item.tabIndex = -1;
749
+ if (dropFromTabSequence) this.#writeAttribute(item, "tabindex", "-1");
575
750
  }
576
751
  this.#normalizePressed(item);
577
752
  }
578
753
  #releaseItem(item) {
579
- if (!this.#managedItems.delete(item)) return;
580
- const original = this.#originalTabindex.get(item);
581
- if (original === null) item.removeAttribute("tabindex");
582
- else if (original !== void 0) item.setAttribute("tabindex", original);
583
- if (this.#ownedPressed.delete(item)) this.#writePressed(item, null);
754
+ this.#managedItems.delete(item);
755
+ this.#tabindex.return(item);
756
+ this.#pressed.return(item);
584
757
  }
585
758
  #normalizePressed(item) {
586
759
  const value = item.getAttribute("aria-pressed");
587
- if (value === null) {
588
- this.#ownedPressed.set(item, "false");
589
- this.#writePressed(item, "false");
590
- } else if (value !== "true" && value !== "false") {
591
- this.#writePressed(item, "false");
592
- }
760
+ if (value !== "true" && value !== "false") this.#writePressed(item, "false");
593
761
  }
594
762
  #normalizeSelection() {
595
763
  if (this.modeValue !== "single") return;
@@ -663,12 +831,9 @@ var ToggleGroupController = class extends Controller {
663
831
  }
664
832
  #releaseAuthoredPressed(records) {
665
833
  for (const record of records) {
666
- if (record.attributeName !== "aria-pressed") continue;
667
834
  const item = record.target;
668
- const value = item.getAttribute("aria-pressed");
669
- if (value !== null) {
670
- this.#ownedPressed.delete(item);
671
- }
835
+ if (record.attributeName === "aria-pressed") this.#pressed.adopt(item);
836
+ else if (record.attributeName === "tabindex") this.#tabindex.adopt(item);
672
837
  }
673
838
  }
674
839
  #observeMutations() {
@@ -680,9 +845,9 @@ var ToggleGroupController = class extends Controller {
680
845
  });
681
846
  }
682
847
  #releaseDefaultsRewrittenWhileAway() {
683
- for (const [item, written] of this.#ownedPressed) {
684
- const current = item.getAttribute("aria-pressed");
685
- if (current !== null && current !== written) this.#ownedPressed.delete(item);
848
+ for (const item of this.#managedItems) {
849
+ this.#pressed.adopt(item, { ifChanged: true });
850
+ this.#tabindex.adopt(item, { ifChanged: true });
686
851
  }
687
852
  }
688
853
  get #managedTargets() {
@@ -696,7 +861,6 @@ var ToggleGroupController = class extends Controller {
696
861
  }
697
862
  #setPressed(item, pressed) {
698
863
  const value = pressed ? "true" : "false";
699
- if (this.#ownedPressed.has(item)) this.#ownedPressed.set(item, value);
700
864
  this.#writePressed(item, value);
701
865
  }
702
866
  #pressedValues() {
@@ -706,12 +870,11 @@ var ToggleGroupController = class extends Controller {
706
870
  return item.getAttribute("data-value") ?? "";
707
871
  }
708
872
  #writePressed(item, value) {
709
- setAttributeIfChanged(
710
- item,
711
- "aria-pressed",
712
- value,
713
- () => this.#observer.claim(item, "aria-pressed", value)
714
- );
873
+ this.#writeAttribute(item, "aria-pressed", value);
874
+ }
875
+ #writeAttribute(item, name, value) {
876
+ const lease = name === "aria-pressed" ? this.#pressed : this.#tabindex;
877
+ lease.write(item, value, () => this.#observer.claim(item, name, value));
715
878
  }
716
879
  };
717
880
 
@@ -12,6 +12,180 @@ function hasModifierChord(event) {
12
12
  return event.altKey || event.ctrlKey || event.metaKey || event.shiftKey;
13
13
  }
14
14
 
15
+ function setAttributeIfChanged(element, name, value, beforeWrite) {
16
+ if (element.getAttribute(name) === value) return false;
17
+ beforeWrite?.();
18
+ if (value === null) element.removeAttribute(name);
19
+ else element.setAttribute(name, value);
20
+ return true;
21
+ }
22
+
23
+ function sharedRegistry(key, create) {
24
+ const symbol = Symbol.for(key);
25
+ const scope = globalThis;
26
+ const existing = scope[symbol];
27
+ if (existing !== void 0) return existing;
28
+ const registry2 = create();
29
+ Object.defineProperty(globalThis, symbol, { value: registry2 });
30
+ return registry2;
31
+ }
32
+
33
+ var registry = sharedRegistry(
34
+ "stimeo-ui.attribute-lease.registry.v1",
35
+ () => ({ stacks: /* @__PURE__ */ new WeakMap(), names: /* @__PURE__ */ new Map() })
36
+ );
37
+ function isAttributeValue(value) {
38
+ return value === null || typeof value === "string";
39
+ }
40
+ function readLeaseRecord(element, record) {
41
+ try {
42
+ const parsed = JSON.parse(element.getAttribute(record) ?? "null");
43
+ if (!Array.isArray(parsed)) return void 0;
44
+ const [original, written, ...rest] = parsed;
45
+ const linked = rest[0] !== false;
46
+ const beneath = linked ? rest : rest.slice(1);
47
+ if (!beneath.every((under) => typeof under === "string")) return void 0;
48
+ return isAttributeValue(original) && isAttributeValue(written) ? { original, written, linked, beneath } : void 0;
49
+ } catch {
50
+ return void 0;
51
+ }
52
+ }
53
+ function attributeStack(element, attribute) {
54
+ const byAttribute = registry.stacks.get(element) ?? /* @__PURE__ */ new Map();
55
+ registry.stacks.set(element, byAttribute);
56
+ const known = byAttribute.get(attribute);
57
+ if (known) return known;
58
+ const found = [];
59
+ for (const record of registry.names.get(attribute) ?? []) {
60
+ const read = readLeaseRecord(element, record);
61
+ if (read) found.push({ ...read, record });
62
+ }
63
+ const depth = ({ beneath }) => beneath.filter((name) => found.some((other) => other.record === name)).length;
64
+ const stack = found.sort((one, other) => depth(one) - depth(other)).map(({ record, written, original, linked }, index) => ({
65
+ lease: null,
66
+ record,
67
+ written,
68
+ original,
69
+ linked: linked && index > 0
70
+ }));
71
+ byAttribute.set(attribute, stack);
72
+ return stack;
73
+ }
74
+ function findHold(stack, lease, record) {
75
+ return stack.find((held) => held.lease === lease) ?? stack.find((held) => held.lease === null && held.record === record);
76
+ }
77
+ var AttributeLease = class {
78
+ #attribute;
79
+ #record;
80
+ #base;
81
+ #preserveAuthor;
82
+ #held = /* @__PURE__ */ new Set();
83
+ constructor(attribute, owner, options = {}) {
84
+ this.#attribute = attribute;
85
+ this.#record = `data-${owner}-${attribute}-lease`;
86
+ this.#base = options.base === true;
87
+ this.#preserveAuthor = options.preserveAuthor === true;
88
+ const names = registry.names;
89
+ names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
90
+ }
91
+ write(element, value, beforeWrite) {
92
+ const stack = attributeStack(element, this.#attribute);
93
+ const hold = this.#take(stack) ?? this.#acquire(element, stack);
94
+ this.#held.add(element);
95
+ const shows = !this.#covered(element, stack, hold);
96
+ hold.written = value;
97
+ this.#mark(element, stack);
98
+ if (shows) this.#reflect(element, value, beforeWrite);
99
+ }
100
+ adopt(element, options = {}) {
101
+ const known = registry.stacks.get(element)?.has(this.#attribute);
102
+ if (!this.#held.has(element) && !known && !element.hasAttribute(this.#record)) return false;
103
+ const stack = attributeStack(element, this.#attribute);
104
+ const hold = this.#take(stack);
105
+ if (!hold) return false;
106
+ const current = element.getAttribute(this.#attribute);
107
+ if (options.ifChanged && (current === hold.written || this.#covered(element, stack, hold))) {
108
+ return false;
109
+ }
110
+ this.#held.add(element);
111
+ hold.original = current;
112
+ hold.linked = false;
113
+ for (const above of stack.slice(stack.indexOf(hold) + 1)) {
114
+ if (!above.linked) break;
115
+ above.original = current;
116
+ }
117
+ this.#mark(element, stack);
118
+ return true;
119
+ }
120
+ return(element) {
121
+ const held = this.#held.delete(element);
122
+ const known = registry.stacks.get(element)?.has(this.#attribute);
123
+ const stack = held || known || element.hasAttribute(this.#record) ? attributeStack(element, this.#attribute) : [];
124
+ const hold = this.#take(stack);
125
+ if (!hold) return false;
126
+ const carries = element.getAttribute(this.#attribute) === hold.written;
127
+ const owns = carries && !this.#covered(element, stack, hold);
128
+ const index = stack.indexOf(hold);
129
+ stack.splice(index, 1);
130
+ const above = stack[index];
131
+ if (above) above.linked &&= hold.linked;
132
+ this.#mark(element, stack);
133
+ if (!owns) return true;
134
+ const below = hold.linked ? stack[index - 1] : void 0;
135
+ this.#reflect(element, below ? below.written : hold.original);
136
+ return true;
137
+ }
138
+ returnAll() {
139
+ for (const element of Array.from(this.#held)) this.return(element);
140
+ }
141
+ #take(stack) {
142
+ const hold = findHold(stack, this, this.#record);
143
+ if (hold) hold.lease = this;
144
+ return hold;
145
+ }
146
+ #acquire(element, stack) {
147
+ const current = element.getAttribute(this.#attribute);
148
+ const top = stack.at(-1);
149
+ const bottom = stack[0];
150
+ const over = top?.written === current ? top : void 0;
151
+ const from = this.#base ? this.#preserveAuthor && !stack.some((held) => held.written === current) ? void 0 : bottom : over;
152
+ const hold = {
153
+ lease: this,
154
+ record: this.#record,
155
+ written: current,
156
+ original: from ? from.original : current,
157
+ linked: !this.#base && over !== void 0
158
+ };
159
+ if (this.#base && bottom) {
160
+ bottom.linked = true;
161
+ stack.unshift(hold);
162
+ } else stack.push(hold);
163
+ return hold;
164
+ }
165
+ #covered(element, stack, hold) {
166
+ const current = element.getAttribute(this.#attribute);
167
+ return stack.slice(stack.indexOf(hold) + 1).some((above) => above.written === current);
168
+ }
169
+ #mark(element, stack) {
170
+ const records = /* @__PURE__ */ new Map([[this.#record, null]]);
171
+ stack.forEach((hold, index) => {
172
+ const names = stack.slice(0, index).map((under) => under.record);
173
+ const beneath = [...new Set(names.reverse())].filter((name) => name !== hold.record);
174
+ const marker = hold.linked || beneath.length === 0 ? [] : [false];
175
+ records.set(
176
+ hold.record,
177
+ hold.written === hold.original && beneath.length === 0 && index === stack.length - 1 ? null : JSON.stringify([hold.original, hold.written, ...marker, ...beneath])
178
+ );
179
+ });
180
+ for (const [name, recorded] of records) {
181
+ setAttributeIfChanged(element, name, recorded);
182
+ }
183
+ }
184
+ #reflect(element, value, beforeWrite) {
185
+ setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
186
+ }
187
+ };
188
+
15
189
  var COMPOSITION_INPUT_TYPES = /* @__PURE__ */ new Set([
16
190
  "insertCompositionText",
17
191
  "insertFromComposition",
@@ -126,7 +300,7 @@ var CompositionTracker = class {
126
300
  this.#confirmedTarget = null;
127
301
  if (confirmed === null || confirmed !== event.target) return false;
128
302
  const inputType = event.inputType;
129
- return !inputType || isCompositionInputType(inputType);
303
+ return inputType ? isCompositionInputType(inputType) : event.isTrusted === true;
130
304
  }
131
305
  #release(target) {
132
306
  target.removeEventListener("compositionstart", this.#handleStart);
@@ -354,8 +528,12 @@ var MorphRenderWatcher = class {
354
528
 
355
529
  var RovingTabindex = class {
356
530
  #getItems;
357
- constructor(getItems) {
531
+ #write;
532
+ constructor(getItems, write = (item, tabindex) => {
533
+ item.tabIndex = tabindex;
534
+ }) {
358
535
  this.#getItems = getItems;
536
+ this.#write = write;
359
537
  }
360
538
  get activeIndex() {
361
539
  return this.#getItems().findIndex((item) => item.tabIndex === 0);
@@ -364,7 +542,7 @@ var RovingTabindex = class {
364
542
  const { focus = false } = options;
365
543
  const items = options.items ?? this.#getItems();
366
544
  items.forEach((item, i) => {
367
- item.tabIndex = i === index ? 0 : -1;
545
+ this.#write(item, i === index ? 0 : -1);
368
546
  });
369
547
  if (focus) items[index]?.focus();
370
548
  }
@@ -384,7 +562,12 @@ var ToolbarController = class extends Controller {
384
562
  wrap: { type: Boolean, default: true }
385
563
  };
386
564
  static actions = ["onKeydown"];
387
- #roving = new RovingTabindex(() => this.controlTargets);
565
+ #tabindex = new AttributeLease("tabindex", this.identifier);
566
+ #managedControls = /* @__PURE__ */ new WeakSet();
567
+ #roving = new RovingTabindex(
568
+ () => this.controlTargets,
569
+ (control, value) => this.#writeTabindex(control, value)
570
+ );
388
571
  #composition = new CompositionTracker();
389
572
  #observer = null;
390
573
  #connected = false;
@@ -420,14 +603,22 @@ var ToolbarController = class extends Controller {
420
603
  this.#observer = null;
421
604
  }
422
605
  controlTargetConnected(control) {
423
- if (!this.#connected) return;
424
- control.tabIndex = -1;
606
+ if (!this.#connected || this.#managedControls.has(control)) return;
607
+ this.#writeTabindex(control, -1);
425
608
  this.#ensureTabStop();
426
609
  }
427
- controlTargetDisconnected() {
610
+ controlTargetDisconnected(control) {
611
+ if (!this.scope.containsElement(control) || !this.controlTargets.includes(control)) {
612
+ this.#managedControls.delete(control);
613
+ this.#tabindex.return(control);
614
+ }
428
615
  if (!this.#connected) return;
429
616
  this.#ensureTabStop();
430
617
  }
618
+ #writeTabindex(control, value) {
619
+ this.#managedControls.add(control);
620
+ this.#tabindex.write(control, String(value));
621
+ }
431
622
  onKeydown(event) {
432
623
  this.#handleKeydown(event);
433
624
  }