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
@@ -28,6 +28,7 @@ function ensureId(element, prefix = "stimeo") {
28
28
 
29
29
  function setAttributeIfChanged(element, name, value, beforeWrite) {
30
30
  if (element.getAttribute(name) === value) return false;
31
+ beforeWrite?.();
31
32
  if (value === null) element.removeAttribute(name);
32
33
  else element.setAttribute(name, value);
33
34
  return true;
@@ -91,14 +92,34 @@ var AttributeLease = class {
91
92
  const names = registry.names;
92
93
  names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
93
94
  }
94
- write(element, value) {
95
+ write(element, value, beforeWrite) {
95
96
  const stack = attributeStack(element, this.#attribute);
96
97
  const hold = this.#take(stack) ?? this.#acquire(element, stack);
97
98
  this.#held.add(element);
98
99
  const shows = !this.#covered(element, stack, hold);
99
100
  hold.written = value;
100
101
  this.#mark(element, stack);
101
- if (shows) this.#reflect(element, value);
102
+ if (shows) this.#reflect(element, value, beforeWrite);
103
+ }
104
+ adopt(element, options = {}) {
105
+ const known = registry.stacks.get(element)?.has(this.#attribute);
106
+ if (!this.#held.has(element) && !known && !element.hasAttribute(this.#record)) return false;
107
+ const stack = attributeStack(element, this.#attribute);
108
+ const hold = this.#take(stack);
109
+ if (!hold) return false;
110
+ const current = element.getAttribute(this.#attribute);
111
+ if (options.ifChanged && (current === hold.written || this.#covered(element, stack, hold))) {
112
+ return false;
113
+ }
114
+ this.#held.add(element);
115
+ hold.original = current;
116
+ hold.linked = false;
117
+ for (const above of stack.slice(stack.indexOf(hold) + 1)) {
118
+ if (!above.linked) break;
119
+ above.original = current;
120
+ }
121
+ this.#mark(element, stack);
122
+ return true;
102
123
  }
103
124
  return(element) {
104
125
  const held = this.#held.delete(element);
@@ -164,8 +185,8 @@ var AttributeLease = class {
164
185
  setAttributeIfChanged(element, name, recorded);
165
186
  }
166
187
  }
167
- #reflect(element, value) {
168
- setAttributeIfChanged(element, this.#attribute, value);
188
+ #reflect(element, value, beforeWrite) {
189
+ setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
169
190
  }
170
191
  };
171
192
 
@@ -337,8 +358,8 @@ var DropdownController = class extends Controller {
337
358
  };
338
359
  #listeners = new ListenerSet();
339
360
  connect() {
340
- this.#associateTriggerWithMenu();
341
- this.#close("api");
361
+ this.#menu = this.hasMenuTarget ? this.menuTarget : null;
362
+ this.#setOpen(false, "api");
342
363
  this.#listeners.add(document, "click", this.#onOutsideClick, { capture: true });
343
364
  this.#morphRender.observe(this.element);
344
365
  this.#connected = true;
@@ -352,77 +373,71 @@ var DropdownController = class extends Controller {
352
373
  this.#morphRender.disconnect();
353
374
  }
354
375
  triggerTargetConnected() {
355
- if (this.#connected) this.#reflectTrigger();
376
+ this.#adoptMenu();
356
377
  }
357
378
  triggerTargetDisconnected(trigger) {
358
379
  if (!this.triggerTargets.includes(trigger)) {
359
380
  this.#expanded.return(trigger);
360
381
  this.#withdrawControls(trigger);
361
382
  }
362
- if (this.#connected) this.#reflectTrigger();
383
+ this.#adoptMenu();
363
384
  }
364
385
  menuTargetConnected() {
365
- this.#adoptMenu();
386
+ this.#adoptMenu(true);
366
387
  }
367
388
  menuTargetDisconnected(menu) {
368
- this.#adoptMenu();
389
+ this.#adoptMenu(true);
369
390
  if (!this.menuTargets.includes(menu)) this.#menuHidden.return(menu);
370
391
  }
371
392
  toggle(event) {
372
- if (this.#isOpen) {
373
- this.close(event);
374
- } else {
375
- this.open(event);
376
- }
393
+ this.#adoptMenu(true);
394
+ this.#setOpen(!this.#openState, stateReasonFor(event));
377
395
  }
378
396
  open(event) {
379
- this.#open(stateReasonFor(event));
397
+ this.#adoptMenu(true);
398
+ this.#setOpen(true, stateReasonFor(event));
380
399
  }
381
400
  close(event) {
382
401
  this.#close(stateReasonFor(event));
383
402
  }
384
- #open(reason) {
385
- if (!this.hasMenuTarget) return;
386
- const menu = this.menuTarget;
387
- const was = this.#isOpen;
388
- this.#escapeLayer.activate(document, {
389
- onDismiss: () => this.#closeAndRestore(),
390
- claims: claimsWhileFocusWithin(this.element)
391
- });
392
- this.#menuHidden.write(menu, null);
393
- this.#menu = menu;
394
- this.#openState = true;
395
- if (this.hasTriggerTarget) this.#expanded.write(this.triggerTarget, "true");
396
- if (!was && this.#reporting) this.dispatch("open", { detail: { reason }, cancelable: false });
397
- }
398
403
  #close(reason) {
399
- const was = this.#isOpen;
400
- this.#escapeLayer.deactivate();
401
- this.#openState = false;
402
- const menu = this.hasMenuTarget ? this.menuTarget : null;
403
- this.#menu = menu;
404
- if (!menu) return;
405
- this.#menuHidden.write(menu, "");
406
- if (this.hasTriggerTarget) this.#expanded.write(this.triggerTarget, "false");
407
- if (was && this.#reporting) this.dispatch("close", { detail: { reason }, cancelable: false });
404
+ this.#adoptMenu(true);
405
+ this.#setOpen(false, reason);
406
+ }
407
+ #setOpen(open, reason) {
408
+ const changed = open !== this.#openState;
409
+ this.#openState = open;
410
+ if (open) {
411
+ this.#escapeLayer.activate(document, {
412
+ onDismiss: () => this.#closeAndRestore(),
413
+ claims: claimsWhileFocusWithin(this.element)
414
+ });
415
+ } else {
416
+ this.#escapeLayer.deactivate();
417
+ }
418
+ if (this.#menu) this.#menuHidden.write(this.#menu, open ? null : "");
419
+ this.#reflectTrigger();
420
+ if (!changed || !this.#reporting) return;
421
+ if (open) this.dispatch("open", { detail: { reason }, cancelable: false });
422
+ else this.dispatch("close", { detail: { reason }, cancelable: false });
408
423
  }
409
- #adoptMenu() {
424
+ #adoptMenu(readCurrent = false) {
410
425
  if (!this.#connected) return;
411
426
  const menu = this.hasMenuTarget ? this.menuTarget : null;
412
427
  const previous = this.#menu;
428
+ if (previous && (readCurrent || menu !== previous)) this.#openState = !previous.hidden;
429
+ if (!this.#openState) this.#escapeLayer.deactivate();
413
430
  this.#menu = menu;
414
- if (!menu) {
415
- this.#escapeLayer.deactivate();
416
- this.#openState = false;
417
- } else if (menu !== previous) {
418
- this.#menuHidden.write(menu, previous?.hidden ?? true ? "" : null);
419
- }
431
+ if (menu && menu !== previous) this.#menuHidden.write(menu, this.#openState ? null : "");
420
432
  this.#reflectTrigger();
421
433
  }
422
434
  #reflectTrigger() {
423
435
  if (!this.hasTriggerTarget) return;
424
- this.#expanded.write(this.triggerTarget, String(this.#isOpen));
425
- this.#associateTriggerWithMenu();
436
+ const trigger = this.triggerTarget;
437
+ const expanded = this.#menu ? !this.#menu.hidden : this.#openState;
438
+ this.#expanded.write(trigger, String(expanded));
439
+ if (this.hasMenuTarget) this.#associateTriggerWithMenu();
440
+ else this.#withdrawControls(trigger);
426
441
  }
427
442
  #repair() {
428
443
  if (!this.hasMenuTarget) return;
@@ -433,9 +448,6 @@ var DropdownController = class extends Controller {
433
448
  this.#close("escape");
434
449
  if (this.hasTriggerTarget) this.triggerTarget.focus();
435
450
  }
436
- get #isOpen() {
437
- return this.hasMenuTarget && !this.menuTarget.hidden;
438
- }
439
451
  #associateTriggerWithMenu() {
440
452
  if (!this.hasTriggerTarget || !this.hasMenuTarget) return;
441
453
  const trigger = this.triggerTarget;
@@ -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
 
@@ -267,7 +288,7 @@ var CompositionTracker = class {
267
288
  this.#confirmedTarget = null;
268
289
  if (confirmed === null || confirmed !== event.target) return false;
269
290
  const inputType = event.inputType;
270
- return !inputType || isCompositionInputType(inputType);
291
+ return inputType ? isCompositionInputType(inputType) : event.isTrusted === true;
271
292
  }
272
293
  #release(target) {
273
294
  target.removeEventListener("compositionstart", this.#handleStart);
@@ -426,14 +447,49 @@ var EditableController = class extends Controller {
426
447
  #composition = new CompositionTracker();
427
448
  #hidden = new AttributeLease("hidden", this.identifier);
428
449
  #connected = false;
450
+ #editorPress = null;
451
+ #deferredBlur = false;
429
452
  #onFocusOut = (event) => {
430
453
  const from = event.target;
431
454
  if (this.hasDisplayTarget && from instanceof Node && this.displayTarget.contains(from)) return;
432
455
  const next = event.relatedTarget;
433
456
  if (next instanceof Node && this.element.contains(next)) return;
434
- if (this.submitOnBlurValue) this.#commit(false);
457
+ if (!this.submitOnBlurValue) return;
458
+ if (next === null && this.#editorPress !== null) {
459
+ this.#deferredBlur = true;
460
+ return;
461
+ }
462
+ this.#commit(false);
435
463
  };
436
464
  #listeners = new ListenerSet();
465
+ #editListeners = new ListenerSet();
466
+ #onPointerDown = (event) => {
467
+ if (event.pointerType !== "mouse" || !event.isPrimary || event.button !== 0) return;
468
+ const inside = event.composedPath().includes(this.element);
469
+ this.#editorPress = inside ? event.pointerId : null;
470
+ if (!inside) this.#commitDeferredBlur();
471
+ };
472
+ #onPointerEnd = (event) => {
473
+ if (event.pointerId !== this.#editorPress) return;
474
+ this.#editorPress = null;
475
+ if (event.type === "pointerup" && !event.composedPath().includes(this.element)) {
476
+ this.#commitDeferredBlur();
477
+ }
478
+ };
479
+ #onFocusIn = (event) => {
480
+ if (event.composedPath().includes(this.element)) this.#deferredBlur = false;
481
+ else this.#commitDeferredBlur();
482
+ };
483
+ #commitDeferredBlur() {
484
+ if (!this.#deferredBlur) return;
485
+ this.#deferredBlur = false;
486
+ if (this.submitOnBlurValue) this.#commit(false);
487
+ }
488
+ #clearEditListeners() {
489
+ this.#editListeners.dispose();
490
+ this.#editorPress = null;
491
+ this.#deferredBlur = false;
492
+ }
437
493
  connect() {
438
494
  this.#connected = true;
439
495
  if (this.hasInputTarget) this.#composition.observe(this.inputTarget);
@@ -445,6 +501,7 @@ var EditableController = class extends Controller {
445
501
  this.#connected = false;
446
502
  this.#composition.disconnect();
447
503
  this.#listeners.dispose();
504
+ this.#clearEditListeners();
448
505
  }
449
506
  inputTargetConnected(input) {
450
507
  this.#composition.observe(input);
@@ -466,6 +523,11 @@ var EditableController = class extends Controller {
466
523
  if (this.#isEditing || !this.hasInputTarget || !this.hasDisplayTarget) return;
467
524
  this.#previousValue = this.#currentValue;
468
525
  this.inputTarget.value = this.#previousValue;
526
+ const document = this.element.ownerDocument;
527
+ this.#editListeners.add(document, "pointerdown", this.#onPointerDown, { capture: true });
528
+ this.#editListeners.add(document, "pointerup", this.#onPointerEnd, { capture: true });
529
+ this.#editListeners.add(document, "pointercancel", this.#onPointerEnd, { capture: true });
530
+ this.#editListeners.add(document, "focusin", this.#onFocusIn, { capture: true });
469
531
  this.#setMode("editing");
470
532
  this.inputTarget.focus();
471
533
  this.inputTarget.select();
@@ -530,6 +592,7 @@ var EditableController = class extends Controller {
530
592
  if (this.hasInputTarget) this.#hidden.write(this.inputTarget, editing ? null : "");
531
593
  }
532
594
  #setMode(mode) {
595
+ if (mode === "display") this.#clearEditListeners();
533
596
  this.element.dataset.mode = mode;
534
597
  this.#applyMode();
535
598
  }
@@ -18,6 +18,180 @@ function announce(message, options = {}) {
18
18
  window.dispatchEvent(event);
19
19
  }
20
20
 
21
+ function setAttributeIfChanged(element, name, value, beforeWrite) {
22
+ if (element.getAttribute(name) === value) return false;
23
+ beforeWrite?.();
24
+ if (value === null) element.removeAttribute(name);
25
+ else element.setAttribute(name, value);
26
+ return true;
27
+ }
28
+
29
+ function sharedRegistry(key, create) {
30
+ const symbol = Symbol.for(key);
31
+ const scope = globalThis;
32
+ const existing = scope[symbol];
33
+ if (existing !== void 0) return existing;
34
+ const registry2 = create();
35
+ Object.defineProperty(globalThis, symbol, { value: registry2 });
36
+ return registry2;
37
+ }
38
+
39
+ var registry = sharedRegistry(
40
+ "stimeo-ui.attribute-lease.registry.v1",
41
+ () => ({ stacks: /* @__PURE__ */ new WeakMap(), names: /* @__PURE__ */ new Map() })
42
+ );
43
+ function isAttributeValue(value) {
44
+ return value === null || typeof value === "string";
45
+ }
46
+ function readLeaseRecord(element, record) {
47
+ try {
48
+ const parsed = JSON.parse(element.getAttribute(record) ?? "null");
49
+ if (!Array.isArray(parsed)) return void 0;
50
+ const [original, written, ...rest] = parsed;
51
+ const linked = rest[0] !== false;
52
+ const beneath = linked ? rest : rest.slice(1);
53
+ if (!beneath.every((under) => typeof under === "string")) return void 0;
54
+ return isAttributeValue(original) && isAttributeValue(written) ? { original, written, linked, beneath } : void 0;
55
+ } catch {
56
+ return void 0;
57
+ }
58
+ }
59
+ function attributeStack(element, attribute) {
60
+ const byAttribute = registry.stacks.get(element) ?? /* @__PURE__ */ new Map();
61
+ registry.stacks.set(element, byAttribute);
62
+ const known = byAttribute.get(attribute);
63
+ if (known) return known;
64
+ const found = [];
65
+ for (const record of registry.names.get(attribute) ?? []) {
66
+ const read = readLeaseRecord(element, record);
67
+ if (read) found.push({ ...read, record });
68
+ }
69
+ const depth = ({ beneath }) => beneath.filter((name) => found.some((other) => other.record === name)).length;
70
+ const stack = found.sort((one, other) => depth(one) - depth(other)).map(({ record, written, original, linked }, index) => ({
71
+ lease: null,
72
+ record,
73
+ written,
74
+ original,
75
+ linked: linked && index > 0
76
+ }));
77
+ byAttribute.set(attribute, stack);
78
+ return stack;
79
+ }
80
+ function findHold(stack, lease, record) {
81
+ return stack.find((held) => held.lease === lease) ?? stack.find((held) => held.lease === null && held.record === record);
82
+ }
83
+ var AttributeLease = class {
84
+ #attribute;
85
+ #record;
86
+ #base;
87
+ #preserveAuthor;
88
+ #held = /* @__PURE__ */ new Set();
89
+ constructor(attribute, owner, options = {}) {
90
+ this.#attribute = attribute;
91
+ this.#record = `data-${owner}-${attribute}-lease`;
92
+ this.#base = options.base === true;
93
+ this.#preserveAuthor = options.preserveAuthor === true;
94
+ const names = registry.names;
95
+ names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
96
+ }
97
+ write(element, value, beforeWrite) {
98
+ const stack = attributeStack(element, this.#attribute);
99
+ const hold = this.#take(stack) ?? this.#acquire(element, stack);
100
+ this.#held.add(element);
101
+ const shows = !this.#covered(element, stack, hold);
102
+ hold.written = value;
103
+ this.#mark(element, stack);
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;
125
+ }
126
+ return(element) {
127
+ const held = this.#held.delete(element);
128
+ const known = registry.stacks.get(element)?.has(this.#attribute);
129
+ const stack = held || known || element.hasAttribute(this.#record) ? attributeStack(element, this.#attribute) : [];
130
+ const hold = this.#take(stack);
131
+ if (!hold) return false;
132
+ const carries = element.getAttribute(this.#attribute) === hold.written;
133
+ const owns = carries && !this.#covered(element, stack, hold);
134
+ const index = stack.indexOf(hold);
135
+ stack.splice(index, 1);
136
+ const above = stack[index];
137
+ if (above) above.linked &&= hold.linked;
138
+ this.#mark(element, stack);
139
+ if (!owns) return true;
140
+ const below = hold.linked ? stack[index - 1] : void 0;
141
+ this.#reflect(element, below ? below.written : hold.original);
142
+ return true;
143
+ }
144
+ returnAll() {
145
+ for (const element of Array.from(this.#held)) this.return(element);
146
+ }
147
+ #take(stack) {
148
+ const hold = findHold(stack, this, this.#record);
149
+ if (hold) hold.lease = this;
150
+ return hold;
151
+ }
152
+ #acquire(element, stack) {
153
+ const current = element.getAttribute(this.#attribute);
154
+ const top = stack.at(-1);
155
+ const bottom = stack[0];
156
+ const over = top?.written === current ? top : void 0;
157
+ const from = this.#base ? this.#preserveAuthor && !stack.some((held) => held.written === current) ? void 0 : bottom : over;
158
+ const hold = {
159
+ lease: this,
160
+ record: this.#record,
161
+ written: current,
162
+ original: from ? from.original : current,
163
+ linked: !this.#base && over !== void 0
164
+ };
165
+ if (this.#base && bottom) {
166
+ bottom.linked = true;
167
+ stack.unshift(hold);
168
+ } else stack.push(hold);
169
+ return hold;
170
+ }
171
+ #covered(element, stack, hold) {
172
+ const current = element.getAttribute(this.#attribute);
173
+ return stack.slice(stack.indexOf(hold) + 1).some((above) => above.written === current);
174
+ }
175
+ #mark(element, stack) {
176
+ const records = /* @__PURE__ */ new Map([[this.#record, null]]);
177
+ stack.forEach((hold, index) => {
178
+ const names = stack.slice(0, index).map((under) => under.record);
179
+ const beneath = [...new Set(names.reverse())].filter((name) => name !== hold.record);
180
+ const marker = hold.linked || beneath.length === 0 ? [] : [false];
181
+ records.set(
182
+ hold.record,
183
+ hold.written === hold.original && beneath.length === 0 && index === stack.length - 1 ? null : JSON.stringify([hold.original, hold.written, ...marker, ...beneath])
184
+ );
185
+ });
186
+ for (const [name, recorded] of records) {
187
+ setAttributeIfChanged(element, name, recorded);
188
+ }
189
+ }
190
+ #reflect(element, value, beforeWrite) {
191
+ setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
192
+ }
193
+ };
194
+
21
195
  var ListenerSet = class {
22
196
  #abort = new AbortController();
23
197
  add(target, type, handler, options) {
@@ -99,6 +273,7 @@ var EmptyStateController = class extends Controller {
99
273
  #observer = null;
100
274
  #connected = false;
101
275
  #empty = null;
276
+ #hidden = new AttributeLease("hidden", this.identifier);
102
277
  #morphRender = new MorphRenderWatcher(() => this.#resync());
103
278
  connect() {
104
279
  this.#morphRender.observe(this.element);
@@ -110,17 +285,25 @@ var EmptyStateController = class extends Controller {
110
285
  this.#morphRender.disconnect();
111
286
  this.#connected = false;
112
287
  this.#stopObserving();
288
+ if (!this.scope.containsElement(this.element)) {
289
+ this.element.removeAttribute("data-count");
290
+ this.element.removeAttribute("data-empty");
291
+ }
113
292
  }
114
293
  listTargetConnected() {
115
294
  this.#resync();
116
295
  }
117
- listTargetDisconnected() {
296
+ listTargetDisconnected(element) {
297
+ if (!this.scope.containsElement(element) || !this.listTargets.includes(element))
298
+ this.#hidden.return(element);
118
299
  this.#resync();
119
300
  }
120
301
  emptyTargetConnected() {
121
302
  this.#resync();
122
303
  }
123
- emptyTargetDisconnected() {
304
+ emptyTargetDisconnected(element) {
305
+ if (!this.scope.containsElement(element) || !this.emptyTargets.includes(element))
306
+ this.#hidden.return(element);
124
307
  this.#resync();
125
308
  }
126
309
  itemSelectorValueChanged() {
@@ -175,8 +358,8 @@ var EmptyStateController = class extends Controller {
175
358
  } else {
176
359
  this.element.removeAttribute("data-empty");
177
360
  }
178
- this.listTarget.hidden = empty;
179
- if (this.hasEmptyTarget) this.emptyTarget.hidden = !empty;
361
+ this.#hidden.write(this.listTarget, empty ? "" : null);
362
+ if (this.hasEmptyTarget) this.#hidden.write(this.emptyTarget, empty ? null : "");
180
363
  return count;
181
364
  }
182
365
  #count() {