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
@@ -49,45 +49,234 @@ 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
- #claims = null;
55
- #observer = null;
220
+ #lifetime = null;
56
221
  constructor(onAuthored) {
57
222
  this.#onAuthored = onAuthored;
58
223
  }
59
224
  observe(root, options) {
60
- this.disconnect();
61
- const observer = new MutationObserver((records) => {
62
- if (this.#observer !== observer) return;
63
- const authored = this.#filter(records);
64
- if (authored.length > 0) this.#onAuthored(authored);
65
- });
66
- this.#observer = observer;
67
- this.#claims = { attributes: /* @__PURE__ */ new Map(), children: /* @__PURE__ */ new Map() };
68
- observer.observe(root, {
69
- attributes: true,
70
- attributeFilter: [...options.attributes],
71
- subtree: options.subtree ?? false,
72
- childList: options.childList ?? false
73
- });
74
- if (options.ancestorAttributes) {
75
- let ancestor = root.parentElement;
76
- while (ancestor) {
77
- observer.observe(ancestor, {
78
- attributes: true,
79
- attributeFilter: [...options.ancestorAttributes]
80
- });
81
- ancestor = ancestor.parentElement;
225
+ const previous = this.#lifetime;
226
+ const lifetime = {
227
+ observer: null,
228
+ active: false,
229
+ claims: { attributes: /* @__PURE__ */ new Map(), children: /* @__PURE__ */ new Map() }
230
+ };
231
+ this.#lifetime = lifetime;
232
+ let observer = null;
233
+ try {
234
+ if (previous) this.#release(previous);
235
+ if (this.#lifetime !== lifetime) return;
236
+ const attributes = [...options.attributes];
237
+ const subtree = options.subtree ?? false;
238
+ const childList = options.childList ?? false;
239
+ const inherited = options.ancestorAttributes;
240
+ const ancestorAttributes = inherited ? [...inherited] : null;
241
+ if (this.#lifetime !== lifetime) return;
242
+ observer = new MutationObserver((records) => {
243
+ const authored = this.#filter(records, lifetime.claims);
244
+ if (this.#lifetime === lifetime && lifetime.active && authored.length > 0) {
245
+ this.#onAuthored(authored);
246
+ }
247
+ });
248
+ if (this.#lifetime !== lifetime) return;
249
+ lifetime.observer = observer;
250
+ observer.observe(root, { attributes: true, attributeFilter: attributes, subtree, childList });
251
+ if (this.#lifetime !== lifetime) {
252
+ this.#release(lifetime, observer);
253
+ return;
254
+ }
255
+ if (ancestorAttributes) {
256
+ let ancestor = root.parentElement;
257
+ while (ancestor) {
258
+ observer.observe(ancestor, { attributes: true, attributeFilter: ancestorAttributes });
259
+ if (this.#lifetime !== lifetime) {
260
+ this.#release(lifetime, observer);
261
+ return;
262
+ }
263
+ ancestor = ancestor.parentElement;
264
+ }
82
265
  }
266
+ lifetime.active = true;
267
+ } catch (error) {
268
+ this.#release(lifetime, observer);
269
+ throw error;
83
270
  }
84
271
  }
85
272
  claim(target, name, value) {
86
- const claims = this.#claims?.attributes;
87
- let attributes = claims?.get(target);
273
+ const lifetime = this.#lifetime;
274
+ if (!lifetime?.active) return;
275
+ const claims = lifetime.claims.attributes;
276
+ let attributes = claims.get(target);
88
277
  if (!attributes) {
89
278
  attributes = /* @__PURE__ */ new Map();
90
- claims?.set(target, attributes);
279
+ claims.set(target, attributes);
91
280
  }
92
281
  const pending = attributes.get(name);
93
282
  attributes.set(name, { value, count: (pending?.count ?? 0) + 1 });
@@ -96,37 +285,49 @@ var AuthoredMutationWatcher = class {
96
285
  this.claim(target, name, target.getAttribute(name));
97
286
  }
98
287
  claimChildList(target, added, removed) {
99
- const claims = this.#claims?.children;
100
- const pending = claims?.get(target) ?? { added: /* @__PURE__ */ new Map(), removed: /* @__PURE__ */ new Map() };
288
+ const lifetime = this.#lifetime;
289
+ if (!lifetime?.active) return;
290
+ const claims = lifetime.claims.children;
291
+ const pending = claims.get(target) ?? { added: /* @__PURE__ */ new Map(), removed: /* @__PURE__ */ new Map() };
101
292
  for (const node of added) pending.added.set(node, (pending.added.get(node) ?? 0) + 1);
102
293
  for (const node of removed) pending.removed.set(node, (pending.removed.get(node) ?? 0) + 1);
103
- claims?.set(target, pending);
294
+ claims.set(target, pending);
104
295
  }
105
296
  take() {
106
- return this.#filter(this.#observer?.takeRecords() ?? []);
297
+ const lifetime = this.#lifetime;
298
+ const observer = lifetime?.observer;
299
+ if (!lifetime?.active || !observer) return [];
300
+ const records = observer.takeRecords();
301
+ const authored = this.#filter(records, lifetime.claims);
302
+ return this.#lifetime === lifetime && lifetime.active ? authored : [];
107
303
  }
108
304
  disconnect() {
109
- this.#observer?.disconnect();
110
- this.#observer = null;
111
- this.#claims = null;
112
- }
113
- #filter(records) {
114
- const authored = records.filter((record) => !this.#consume(record));
115
- this.#claims?.attributes.clear();
116
- this.#claims?.children.clear();
305
+ const lifetime = this.#lifetime;
306
+ if (lifetime) this.#release(lifetime);
307
+ }
308
+ #release(lifetime, observer = lifetime.observer) {
309
+ if (this.#lifetime === lifetime) this.#lifetime = null;
310
+ lifetime.claims.attributes.clear();
311
+ lifetime.claims.children.clear();
312
+ observer?.disconnect();
313
+ }
314
+ #filter(records, claims) {
315
+ const authored = records.filter((record) => !this.#consume(record, claims));
316
+ claims.attributes.clear();
317
+ claims.children.clear();
117
318
  return authored;
118
319
  }
119
- #consume(record) {
320
+ #consume(record, claims) {
120
321
  if (record.type === "attributes") {
121
322
  const target = record.target;
122
- const pending2 = this.#claims?.attributes.get(target)?.get(record.attributeName);
323
+ const pending2 = claims.attributes.get(target)?.get(record.attributeName);
123
324
  if (!pending2 || pending2.count === 0 || target.getAttribute(record.attributeName) !== pending2.value) {
124
325
  return false;
125
326
  }
126
327
  pending2.count -= 1;
127
328
  return true;
128
329
  }
129
- const pending = this.#claims?.children.get(record.target);
330
+ const pending = claims.children.get(record.target);
130
331
  if (!pending) return false;
131
332
  const added = [...record.addedNodes];
132
333
  const removed = [...record.removedNodes];
@@ -169,11 +370,16 @@ function commitField(target) {
169
370
  target.dispatchEvent(new Event("change", { bubbles: true }));
170
371
  }
171
372
 
373
+ var HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
172
374
  function inheritsFieldsetDisabled(control) {
173
375
  let fieldset = control.closest("fieldset[disabled]");
174
376
  while (fieldset) {
175
- const legend = Array.from(fieldset.children).find((child) => child.tagName === "LEGEND");
176
- if (!legend?.contains(control)) return true;
377
+ if (fieldset.namespaceURI === HTML_NAMESPACE && fieldset.localName === "fieldset") {
378
+ const legend = Array.from(fieldset.children).find(
379
+ (child) => child.namespaceURI === HTML_NAMESPACE && child.localName === "legend"
380
+ );
381
+ if (!legend?.contains(control)) return true;
382
+ }
177
383
  fieldset = fieldset.parentElement?.closest("fieldset[disabled]") ?? null;
178
384
  }
179
385
  return false;
@@ -278,8 +484,12 @@ var MoveCounter = class {
278
484
 
279
485
  var RovingTabindex = class {
280
486
  #getItems;
281
- constructor(getItems) {
487
+ #write;
488
+ constructor(getItems, write = (item, tabindex) => {
489
+ item.tabIndex = tabindex;
490
+ }) {
282
491
  this.#getItems = getItems;
492
+ this.#write = write;
283
493
  }
284
494
  get activeIndex() {
285
495
  return this.#getItems().findIndex((item) => item.tabIndex === 0);
@@ -288,7 +498,7 @@ var RovingTabindex = class {
288
498
  const { focus = false } = options;
289
499
  const items = options.items ?? this.#getItems();
290
500
  items.forEach((item, i) => {
291
- item.tabIndex = i === index ? 0 : -1;
501
+ this.#write(item, i === index ? 0 : -1);
292
502
  });
293
503
  if (focus) items[index]?.focus();
294
504
  }
@@ -305,6 +515,7 @@ function targetSelector(identifier, name) {
305
515
 
306
516
  var ITEM_ATTRIBUTES = [
307
517
  "aria-pressed",
518
+ "tabindex",
308
519
  "data-value",
309
520
  "disabled",
310
521
  "hidden",
@@ -324,11 +535,14 @@ var ToggleGroupController = class extends Controller {
324
535
  };
325
536
  static actions = ["onKeydown", "toggle"];
326
537
  static events = ["change", "reconcile"];
327
- #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
+ );
328
544
  #handledEvents = /* @__PURE__ */ new WeakSet();
329
545
  #managedItems = /* @__PURE__ */ new Set();
330
- #originalTabindex = /* @__PURE__ */ new WeakMap();
331
- #ownedPressed = /* @__PURE__ */ new Map();
332
546
  #pass = new MorphRenderWatcher(() => this.#reconcileDom());
333
547
  #observer = new AuthoredMutationWatcher((records) => {
334
548
  this.#releaseAuthoredPressed(records);
@@ -362,6 +576,7 @@ var ToggleGroupController = class extends Controller {
362
576
  this.#observeMutations();
363
577
  }
364
578
  disconnect() {
579
+ this.#releaseAuthoredPressed(this.#observer.take());
365
580
  this.#connectionGeneration += 1;
366
581
  this.#connected = false;
367
582
  this.#pass.disconnect();
@@ -374,9 +589,10 @@ var ToggleGroupController = class extends Controller {
374
589
  this.#pass.schedule();
375
590
  }
376
591
  itemTargetDisconnected(item) {
377
- if (!this.#connected) return;
592
+ if (this.scope.containsElement(item) && this.itemTargets.includes(item)) return;
593
+ this.#releaseAuthoredPressed(this.#observer.take());
378
594
  this.#releaseItem(item);
379
- this.#pass.schedule();
595
+ if (this.#connected) this.#pass.schedule();
380
596
  }
381
597
  modeValueChanged() {
382
598
  this.#pass.schedule();
@@ -530,26 +746,18 @@ var ToggleGroupController = class extends Controller {
530
746
  }
531
747
  if (!this.#managedItems.has(item)) {
532
748
  this.#managedItems.add(item);
533
- this.#originalTabindex.set(item, item.getAttribute("tabindex"));
534
- if (dropFromTabSequence) item.tabIndex = -1;
749
+ if (dropFromTabSequence) this.#writeAttribute(item, "tabindex", "-1");
535
750
  }
536
751
  this.#normalizePressed(item);
537
752
  }
538
753
  #releaseItem(item) {
539
- if (!this.#managedItems.delete(item)) return;
540
- const original = this.#originalTabindex.get(item);
541
- if (original === null) item.removeAttribute("tabindex");
542
- else if (original !== void 0) item.setAttribute("tabindex", original);
543
- if (this.#ownedPressed.delete(item)) this.#writePressed(item, null);
754
+ this.#managedItems.delete(item);
755
+ this.#tabindex.return(item);
756
+ this.#pressed.return(item);
544
757
  }
545
758
  #normalizePressed(item) {
546
759
  const value = item.getAttribute("aria-pressed");
547
- if (value === null) {
548
- this.#ownedPressed.set(item, "false");
549
- this.#writePressed(item, "false");
550
- } else if (value !== "true" && value !== "false") {
551
- this.#writePressed(item, "false");
552
- }
760
+ if (value !== "true" && value !== "false") this.#writePressed(item, "false");
553
761
  }
554
762
  #normalizeSelection() {
555
763
  if (this.modeValue !== "single") return;
@@ -623,12 +831,9 @@ var ToggleGroupController = class extends Controller {
623
831
  }
624
832
  #releaseAuthoredPressed(records) {
625
833
  for (const record of records) {
626
- if (record.attributeName !== "aria-pressed") continue;
627
834
  const item = record.target;
628
- const value = item.getAttribute("aria-pressed");
629
- if (value !== null) {
630
- this.#ownedPressed.delete(item);
631
- }
835
+ if (record.attributeName === "aria-pressed") this.#pressed.adopt(item);
836
+ else if (record.attributeName === "tabindex") this.#tabindex.adopt(item);
632
837
  }
633
838
  }
634
839
  #observeMutations() {
@@ -640,9 +845,9 @@ var ToggleGroupController = class extends Controller {
640
845
  });
641
846
  }
642
847
  #releaseDefaultsRewrittenWhileAway() {
643
- for (const [item, written] of this.#ownedPressed) {
644
- const current = item.getAttribute("aria-pressed");
645
- 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 });
646
851
  }
647
852
  }
648
853
  get #managedTargets() {
@@ -656,7 +861,6 @@ var ToggleGroupController = class extends Controller {
656
861
  }
657
862
  #setPressed(item, pressed) {
658
863
  const value = pressed ? "true" : "false";
659
- if (this.#ownedPressed.has(item)) this.#ownedPressed.set(item, value);
660
864
  this.#writePressed(item, value);
661
865
  }
662
866
  #pressedValues() {
@@ -666,12 +870,11 @@ var ToggleGroupController = class extends Controller {
666
870
  return item.getAttribute("data-value") ?? "";
667
871
  }
668
872
  #writePressed(item, value) {
669
- setAttributeIfChanged(
670
- item,
671
- "aria-pressed",
672
- value,
673
- () => this.#observer.claim(item, "aria-pressed", value)
674
- );
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));
675
878
  }
676
879
  };
677
880