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;
@@ -305,8 +471,12 @@ var MoveCounter = class {
305
471
 
306
472
  var RovingTabindex = class {
307
473
  #getItems;
308
- constructor(getItems) {
474
+ #write;
475
+ constructor(getItems, write = (item, tabindex) => {
476
+ item.tabIndex = tabindex;
477
+ }) {
309
478
  this.#getItems = getItems;
479
+ this.#write = write;
310
480
  }
311
481
  get activeIndex() {
312
482
  return this.#getItems().findIndex((item) => item.tabIndex === 0);
@@ -315,7 +485,7 @@ var RovingTabindex = class {
315
485
  const { focus = false } = options;
316
486
  const items = options.items ?? this.#getItems();
317
487
  items.forEach((item, i) => {
318
- item.tabIndex = i === index ? 0 : -1;
488
+ this.#write(item, i === index ? 0 : -1);
319
489
  });
320
490
  if (focus) items[index]?.focus();
321
491
  }
@@ -351,13 +521,15 @@ var RadioGroupController = class extends Controller {
351
521
  static targets = ["radio", "field"];
352
522
  static actions = ["onKeydown", "select"];
353
523
  static events = ["change", "reconcile"];
354
- #roving = new RovingTabindex(() => this.#managedTargets);
524
+ #checked = new AttributeLease("aria-checked", this.identifier);
525
+ #tabindex = new AttributeLease("tabindex", this.identifier);
526
+ #roving = new RovingTabindex(
527
+ () => this.#managedTargets,
528
+ (radio, value) => this.#writeTabindex(radio, value)
529
+ );
355
530
  #reconcile = new MorphRenderWatcher(() => this.#reconcileDom());
356
531
  #handledEvents = /* @__PURE__ */ new WeakSet();
357
532
  #managedRadios = /* @__PURE__ */ new Set();
358
- #originalTabindex = /* @__PURE__ */ new Map();
359
- #ownedChecked = /* @__PURE__ */ new Map();
360
- #writtenTabindex = /* @__PURE__ */ new WeakMap();
361
533
  #observer = new AuthoredMutationWatcher(
362
534
  (records) => this.#handleMutationRecords(records)
363
535
  );
@@ -392,6 +564,7 @@ var RadioGroupController = class extends Controller {
392
564
  this.#observeMutations();
393
565
  }
394
566
  disconnect() {
567
+ this.#handleMutationRecords(this.#observer.take());
395
568
  this.#connectionGeneration += 1;
396
569
  this.#connected = false;
397
570
  this.#reconcile.disconnect();
@@ -409,14 +582,17 @@ var RadioGroupController = class extends Controller {
409
582
  this.#reconcile.schedule();
410
583
  }
411
584
  radioTargetDisconnected(radio) {
412
- if (!this.#connected) return;
413
- if (this.#focusedRadio === radio) {
585
+ if (this.scope.containsElement(radio) && this.radioTargets.includes(radio)) return;
586
+ this.#handleMutationRecords(this.#observer.take());
587
+ if (this.#connected && this.#focusedRadio === radio) {
414
588
  this.#pendingFocusIndex = this.#lastOrder.indexOf(radio);
415
589
  this.#focusedRadio = null;
416
590
  }
417
591
  this.#releaseRadio(radio);
418
- this.#preferChecked = true;
419
- this.#reconcile.schedule();
592
+ if (this.#connected) {
593
+ this.#preferChecked = true;
594
+ this.#reconcile.schedule();
595
+ }
420
596
  }
421
597
  fieldTargetConnected() {
422
598
  this.#reconcile.schedule();
@@ -570,28 +746,18 @@ var RadioGroupController = class extends Controller {
570
746
  }
571
747
  if (!this.#managedRadios.has(radio)) {
572
748
  this.#managedRadios.add(radio);
573
- this.#originalTabindex.set(radio, radio.getAttribute("tabindex"));
574
749
  if (dropFromTabSequence) this.#writeTabindex(radio, -1);
575
750
  }
576
751
  this.#normalizeChecked(radio);
577
752
  }
578
753
  #releaseRadio(radio) {
579
754
  this.#managedRadios.delete(radio);
580
- const original = this.#originalTabindex.get(radio);
581
- if (original !== void 0) this.#writeAttribute(radio, "tabindex", original);
582
- this.#originalTabindex.delete(radio);
583
- if (this.#ownedChecked.delete(radio)) {
584
- this.#writeAttribute(radio, "aria-checked", null);
585
- }
755
+ this.#tabindex.return(radio);
756
+ this.#checked.return(radio);
586
757
  }
587
758
  #normalizeChecked(radio) {
588
759
  const value = radio.getAttribute("aria-checked");
589
- if (value === null) {
590
- this.#ownedChecked.set(radio, "false");
591
- this.#setChecked(radio, false);
592
- } else if (value !== "true" && value !== "false") {
593
- this.#setChecked(radio, false);
594
- }
760
+ if (value !== "true" && value !== "false") this.#setChecked(radio, false);
595
761
  }
596
762
  #normalizeSelection() {
597
763
  let found = false;
@@ -641,10 +807,6 @@ var RadioGroupController = class extends Controller {
641
807
  const items = this.#managedTargets;
642
808
  const index = items.indexOf(radio);
643
809
  this.#roving.setActive(index);
644
- for (const item of items) {
645
- this.#observer.claimCurrent(item, "tabindex");
646
- this.#writtenTabindex.set(item, item.getAttribute("tabindex"));
647
- }
648
810
  if (focus) radio?.focus();
649
811
  }
650
812
  #radioForEventTarget(target) {
@@ -686,12 +848,11 @@ var RadioGroupController = class extends Controller {
686
848
  const target = record.target;
687
849
  const attribute = record.attributeName;
688
850
  if (attribute === "aria-checked") {
689
- this.#ownedChecked.delete(target);
851
+ this.#checked.adopt(target);
690
852
  this.#preferChecked = true;
691
853
  external = true;
692
854
  } else if (attribute === "tabindex") {
693
- const value = target.getAttribute(attribute);
694
- if (this.#managedRadios.has(target)) this.#originalTabindex.set(target, value);
855
+ this.#tabindex.adopt(target);
695
856
  external = true;
696
857
  } else {
697
858
  external = true;
@@ -708,14 +869,9 @@ var RadioGroupController = class extends Controller {
708
869
  });
709
870
  }
710
871
  #releaseDefaultsRewrittenWhileAway() {
711
- for (const [radio, written] of this.#ownedChecked) {
712
- const current = radio.getAttribute("aria-checked");
713
- if (current !== null && current !== written) this.#ownedChecked.delete(radio);
714
- }
715
872
  for (const radio of this.#managedRadios) {
716
- const written = this.#writtenTabindex.get(radio);
717
- const current = radio.getAttribute("tabindex");
718
- if (current !== written) this.#originalTabindex.set(radio, current);
873
+ this.#checked.adopt(radio, { ifChanged: true });
874
+ this.#tabindex.adopt(radio, { ifChanged: true });
719
875
  }
720
876
  }
721
877
  get #managedTargets() {
@@ -736,16 +892,15 @@ var RadioGroupController = class extends Controller {
736
892
  }
737
893
  #setChecked(radio, checked) {
738
894
  const value = checked ? "true" : "false";
739
- if (this.#ownedChecked.has(radio)) this.#ownedChecked.set(radio, value);
740
895
  this.#writeAttribute(radio, "aria-checked", value);
741
896
  }
742
897
  #writeTabindex(radio, value) {
743
898
  const serialized = String(value);
744
- this.#writtenTabindex.set(radio, serialized);
745
899
  this.#writeAttribute(radio, "tabindex", serialized);
746
900
  }
747
901
  #writeAttribute(target, name, value) {
748
- setAttributeIfChanged(target, name, value, () => this.#observer.claim(target, name, value));
902
+ const lease = name === "aria-checked" ? this.#checked : this.#tabindex;
903
+ lease.write(target, value, () => this.#observer.claim(target, name, value));
749
904
  }
750
905
  #reflectField(radio) {
751
906
  const value = radio ? this.#radioValue(radio) : "";
@@ -36,6 +36,7 @@ function hasModifierChord(event) {
36
36
 
37
37
  function setAttributeIfChanged(element, name, value, beforeWrite) {
38
38
  if (element.getAttribute(name) === value) return false;
39
+ beforeWrite?.();
39
40
  if (value === null) element.removeAttribute(name);
40
41
  else element.setAttribute(name, value);
41
42
  return true;
@@ -109,14 +110,34 @@ var AttributeLease = class {
109
110
  const names = registry.names;
110
111
  names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
111
112
  }
112
- write(element, value) {
113
+ write(element, value, beforeWrite) {
113
114
  const stack = attributeStack(element, this.#attribute);
114
115
  const hold = this.#take(stack) ?? this.#acquire(element, stack);
115
116
  this.#held.add(element);
116
117
  const shows = !this.#covered(element, stack, hold);
117
118
  hold.written = value;
118
119
  this.#mark(element, stack);
119
- if (shows) this.#reflect(element, value);
120
+ if (shows) this.#reflect(element, value, beforeWrite);
121
+ }
122
+ adopt(element, options = {}) {
123
+ const known = registry.stacks.get(element)?.has(this.#attribute);
124
+ if (!this.#held.has(element) && !known && !element.hasAttribute(this.#record)) return false;
125
+ const stack = attributeStack(element, this.#attribute);
126
+ const hold = this.#take(stack);
127
+ if (!hold) return false;
128
+ const current = element.getAttribute(this.#attribute);
129
+ if (options.ifChanged && (current === hold.written || this.#covered(element, stack, hold))) {
130
+ return false;
131
+ }
132
+ this.#held.add(element);
133
+ hold.original = current;
134
+ hold.linked = false;
135
+ for (const above of stack.slice(stack.indexOf(hold) + 1)) {
136
+ if (!above.linked) break;
137
+ above.original = current;
138
+ }
139
+ this.#mark(element, stack);
140
+ return true;
120
141
  }
121
142
  return(element) {
122
143
  const held = this.#held.delete(element);
@@ -182,8 +203,8 @@ var AttributeLease = class {
182
203
  setAttributeIfChanged(element, name, recorded);
183
204
  }
184
205
  }
185
- #reflect(element, value) {
186
- setAttributeIfChanged(element, this.#attribute, value);
206
+ #reflect(element, value, beforeWrite) {
207
+ setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
187
208
  }
188
209
  };
189
210
 
@@ -323,8 +344,12 @@ var NumberValueReader = class {
323
344
 
324
345
  var RovingTabindex = class {
325
346
  #getItems;
326
- constructor(getItems) {
347
+ #write;
348
+ constructor(getItems, write = (item, tabindex) => {
349
+ item.tabIndex = tabindex;
350
+ }) {
327
351
  this.#getItems = getItems;
352
+ this.#write = write;
328
353
  }
329
354
  get activeIndex() {
330
355
  return this.#getItems().findIndex((item) => item.tabIndex === 0);
@@ -333,7 +358,7 @@ var RovingTabindex = class {
333
358
  const { focus = false } = options;
334
359
  const items = options.items ?? this.#getItems();
335
360
  items.forEach((item, i) => {
336
- item.tabIndex = i === index ? 0 : -1;
361
+ this.#write(item, i === index ? 0 : -1);
337
362
  });
338
363
  if (focus) items[index]?.focus();
339
364
  }
@@ -483,7 +508,13 @@ var RatingController = class _RatingController extends Controller {
483
508
  };
484
509
  static actions = ["endPreview", "onKeydown", "preview", "select"];
485
510
  static events = ["change", "reconcile"];
486
- #roving = new RovingTabindex(() => this.symbolTargets);
511
+ #checked = new AttributeLease("aria-checked", this.identifier);
512
+ #tabindex = new AttributeLease("tabindex", this.identifier);
513
+ #managedSymbols = /* @__PURE__ */ new Set();
514
+ #roving = new RovingTabindex(
515
+ () => this.symbolTargets,
516
+ (symbol, tabindex) => this.#tabindex.write(symbol, String(tabindex))
517
+ );
487
518
  #rootRole = new AttributeLease("role", this.identifier);
488
519
  #symbolRole = new AttributeLease("role", this.identifier);
489
520
  #symbolAriaHidden = new AttributeLease("aria-hidden", this.identifier);
@@ -493,6 +524,10 @@ var RatingController = class _RatingController extends Controller {
493
524
  #rescuedFocus = false;
494
525
  #shown = 0;
495
526
  connect() {
527
+ const current = new Set(this.symbolTargets);
528
+ for (const symbol of this.#managedSymbols) {
529
+ if (!current.has(symbol)) this.#releaseSymbol(symbol);
530
+ }
496
531
  this.#rootTabindex.reclaim(this.element);
497
532
  this.#repaint.observe(this.element);
498
533
  this.#shown = this.#normalize(this.#safeValue);
@@ -506,13 +541,25 @@ var RatingController = class _RatingController extends Controller {
506
541
  }
507
542
  symbolTargetConnected(symbol) {
508
543
  if (this.#connected === false) return;
509
- symbol.tabIndex = -1;
544
+ if (!this.#managedSymbols.has(symbol)) {
545
+ this.#managedSymbols.add(symbol);
546
+ this.#tabindex.write(symbol, "-1");
547
+ }
510
548
  this.#repaint.schedule();
511
549
  }
512
550
  symbolTargetDisconnected(symbol) {
551
+ if (!this.scope.containsElement(symbol) || !this.symbolTargets.includes(symbol)) {
552
+ this.#releaseSymbol(symbol);
553
+ }
554
+ this.#repaint.schedule();
555
+ }
556
+ #releaseSymbol(symbol) {
557
+ this.#managedSymbols.delete(symbol);
558
+ this.#checked.return(symbol);
559
+ this.#tabindex.return(symbol);
513
560
  this.#symbolRole.return(symbol);
514
561
  this.#symbolAriaHidden.return(symbol);
515
- this.#repaint.schedule();
562
+ symbol.removeAttribute("data-rating-hover");
516
563
  }
517
564
  fieldTargetConnected() {
518
565
  this.#repaint.schedule();
@@ -624,7 +671,8 @@ var RatingController = class _RatingController extends Controller {
624
671
  #apply(value, { focus }) {
625
672
  const move = this.#move;
626
673
  this.symbolTargets.forEach((symbol, index) => {
627
- symbol.setAttribute("aria-checked", value > 0 && index + 1 === value ? "true" : "false");
674
+ this.#managedSymbols.add(symbol);
675
+ this.#checked.write(symbol, value > 0 && index + 1 === value ? "true" : "false");
628
676
  });
629
677
  const field = this.hasFieldTarget ? this.fieldTarget : null;
630
678
  const moved = field && writeField(field, String(value));