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
@@ -20,6 +20,7 @@ function announce(message, options = {}) {
20
20
 
21
21
  function setAttributeIfChanged(element, name, value, beforeWrite) {
22
22
  if (element.getAttribute(name) === value) return false;
23
+ beforeWrite?.();
23
24
  if (value === null) element.removeAttribute(name);
24
25
  else element.setAttribute(name, value);
25
26
  return true;
@@ -93,14 +94,34 @@ var AttributeLease = class {
93
94
  const names = registry.names;
94
95
  names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
95
96
  }
96
- write(element, value) {
97
+ write(element, value, beforeWrite) {
97
98
  const stack = attributeStack(element, this.#attribute);
98
99
  const hold = this.#take(stack) ?? this.#acquire(element, stack);
99
100
  this.#held.add(element);
100
101
  const shows = !this.#covered(element, stack, hold);
101
102
  hold.written = value;
102
103
  this.#mark(element, stack);
103
- if (shows) this.#reflect(element, value);
104
+ if (shows) this.#reflect(element, value, beforeWrite);
105
+ }
106
+ adopt(element, options = {}) {
107
+ const known = registry.stacks.get(element)?.has(this.#attribute);
108
+ if (!this.#held.has(element) && !known && !element.hasAttribute(this.#record)) return false;
109
+ const stack = attributeStack(element, this.#attribute);
110
+ const hold = this.#take(stack);
111
+ if (!hold) return false;
112
+ const current = element.getAttribute(this.#attribute);
113
+ if (options.ifChanged && (current === hold.written || this.#covered(element, stack, hold))) {
114
+ return false;
115
+ }
116
+ this.#held.add(element);
117
+ hold.original = current;
118
+ hold.linked = false;
119
+ for (const above of stack.slice(stack.indexOf(hold) + 1)) {
120
+ if (!above.linked) break;
121
+ above.original = current;
122
+ }
123
+ this.#mark(element, stack);
124
+ return true;
104
125
  }
105
126
  return(element) {
106
127
  const held = this.#held.delete(element);
@@ -166,8 +187,8 @@ var AttributeLease = class {
166
187
  setAttributeIfChanged(element, name, recorded);
167
188
  }
168
189
  }
169
- #reflect(element, value) {
170
- setAttributeIfChanged(element, this.#attribute, value);
190
+ #reflect(element, value, beforeWrite) {
191
+ setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
171
192
  }
172
193
  };
173
194
 
@@ -244,6 +265,105 @@ function inheritsFieldsetDisabled(control) {
244
265
  }
245
266
  return false;
246
267
  }
268
+ function unslotted(element) {
269
+ return element.assignedSlot === null && element.parentElement?.shadowRoot != null;
270
+ }
271
+ function flatTreeParent(element) {
272
+ if (unslotted(element)) return null;
273
+ const parent = element.assignedSlot ?? element.parentNode;
274
+ if (parent instanceof ShadowRoot) return parent.host;
275
+ return parent instanceof Element ? parent : null;
276
+ }
277
+ function flatTreeContains(ancestor, element) {
278
+ for (let node = element; node; node = flatTreeParent(node)) {
279
+ if (node === ancestor) return true;
280
+ }
281
+ return false;
282
+ }
283
+ function canTakeFocus(element) {
284
+ for (let node = element; node; node = flatTreeParent(node)) {
285
+ if (unslotted(node) || node.matches("[hidden], [inert]")) return false;
286
+ }
287
+ if (element instanceof HTMLInputElement && element.type === "hidden") return false;
288
+ if (!("disabled" in element)) return true;
289
+ if (element.disabled) return false;
290
+ return !inheritsFieldsetDisabled(element);
291
+ }
292
+ function deepActiveElement(ownerDocument) {
293
+ let active = ownerDocument.activeElement;
294
+ while (active?.shadowRoot?.activeElement) active = active.shadowRoot.activeElement;
295
+ return active;
296
+ }
297
+
298
+ var ListenerSet = class {
299
+ #abort = new AbortController();
300
+ add(target, type, handler, options) {
301
+ target.addEventListener(type, handler, { ...options, signal: this.#abort.signal });
302
+ }
303
+ dispose() {
304
+ this.#abort.abort();
305
+ this.#abort = new AbortController();
306
+ }
307
+ };
308
+
309
+ var MicrotaskCoalescer = class {
310
+ #run;
311
+ #queued = false;
312
+ #active = false;
313
+ #generation = 0;
314
+ constructor(run) {
315
+ this.#run = run;
316
+ }
317
+ activate() {
318
+ this.#active = true;
319
+ }
320
+ cancel() {
321
+ this.#active = false;
322
+ this.#queued = false;
323
+ this.#generation += 1;
324
+ }
325
+ get pending() {
326
+ return this.#queued;
327
+ }
328
+ schedule() {
329
+ if (!this.#active || this.#queued) return;
330
+ this.#queued = true;
331
+ const generation = this.#generation;
332
+ queueMicrotask(() => {
333
+ if (generation !== this.#generation || !this.#queued || !this.#active) return;
334
+ this.#queued = false;
335
+ this.#run();
336
+ });
337
+ }
338
+ };
339
+
340
+ var MorphRenderWatcher = class {
341
+ #listeners = new ListenerSet();
342
+ #pass;
343
+ #element = null;
344
+ #onMorph = () => this.#pass.schedule();
345
+ constructor(run) {
346
+ this.#pass = new MicrotaskCoalescer(run);
347
+ }
348
+ observe(element) {
349
+ if (this.#element === element) return;
350
+ this.disconnect();
351
+ this.#element = element;
352
+ this.#pass.activate();
353
+ this.#listeners.add(element, "turbo:morph-element", this.#onMorph);
354
+ }
355
+ schedule() {
356
+ this.#pass.schedule();
357
+ }
358
+ get pending() {
359
+ return this.#pass.pending;
360
+ }
361
+ disconnect() {
362
+ this.#listeners.dispose();
363
+ this.#pass.cancel();
364
+ this.#element = null;
365
+ }
366
+ };
247
367
 
248
368
  var NUMBER_BOUNDS = {
249
369
  nonNegative: { finite: true, min: 0 }};
@@ -289,6 +409,126 @@ var NumberValueReader = class {
289
409
  }
290
410
  };
291
411
 
412
+ function queryOpenDescendants(root, selector) {
413
+ const matches = [];
414
+ const roots = [root];
415
+ for (const scope of roots) {
416
+ matches.push(...scope.querySelectorAll(selector));
417
+ if (scope.nodeType === Node.ELEMENT_NODE) {
418
+ const shadow = scope.shadowRoot;
419
+ if (shadow) roots.push(shadow);
420
+ }
421
+ for (const element of scope.querySelectorAll("*")) {
422
+ if (element.shadowRoot) roots.push(element.shadowRoot);
423
+ }
424
+ }
425
+ return matches;
426
+ }
427
+
428
+ function holdsFocus(element) {
429
+ return element.matches(":focus") || deepActiveElement(element.ownerDocument) === element;
430
+ }
431
+ var TabindexLoan = class _TabindexLoan {
432
+ static #registry = sharedRegistry(
433
+ "stimeo-ui.tabindex-loan.registry.v1",
434
+ () => ({ stacks: /* @__PURE__ */ new WeakMap(), names: /* @__PURE__ */ new Set() })
435
+ );
436
+ #value;
437
+ #record;
438
+ #preserveFocus;
439
+ #lent = /* @__PURE__ */ new Set();
440
+ constructor(value, owner, options = {}) {
441
+ this.#value = value;
442
+ this.#record = `data-${owner}-tabindex-loan`;
443
+ this.#preserveFocus = options.preserveFocus === true;
444
+ _TabindexLoan.#registry.names.add(this.#record);
445
+ }
446
+ lend(element, options = {}) {
447
+ const stack = this.#stack(element);
448
+ const current = element.getAttribute("tabindex");
449
+ const held = stack.find((hold) => hold.loan === this) ?? stack.find(
450
+ (hold) => hold.loan === null && hold.record === this.#record && hold.value === this.#value
451
+ );
452
+ const linked = stack.at(-1)?.value === current;
453
+ if (!held && options.onlyIfUnfocusable && (current !== null || element.tabIndex >= 0)) return;
454
+ if (!held && current !== null && !linked) return;
455
+ this.#lent.add(element);
456
+ if (held) held.loan = this;
457
+ else stack.push({ loan: this, record: this.#record, value: this.#value, linked });
458
+ this.#mark(element, stack);
459
+ if (current === null || !held && current !== this.#value) {
460
+ element.setAttribute("tabindex", this.#value);
461
+ }
462
+ }
463
+ return(element) {
464
+ const stack = this.#stack(element);
465
+ const hold = stack.find((held) => held.loan === this) ?? stack.find(
466
+ (held) => held.loan === null && held.record === this.#record && held.value === this.#value
467
+ );
468
+ if (!hold) return false;
469
+ if (!this.#release(element, stack, hold, this.#preserveFocus)) {
470
+ hold.loan = this;
471
+ this.#lent.add(element);
472
+ return false;
473
+ }
474
+ this.#lent.delete(element);
475
+ return true;
476
+ }
477
+ returnAll() {
478
+ for (const element of Array.from(this.#lent)) this.return(element);
479
+ }
480
+ reclaim(element) {
481
+ if (element.getAttribute(this.#record) !== this.#value) return;
482
+ const stack = this.#stack(element);
483
+ const hold = stack.find((held) => held.loan === null && held.record === this.#record);
484
+ if (hold && !holdsFocus(element)) this.#release(element, stack, hold);
485
+ }
486
+ reclaimWithin(root) {
487
+ for (const element of queryOpenDescendants(root, `[${this.#record}]`)) {
488
+ this.reclaim(element);
489
+ }
490
+ }
491
+ #stack(element) {
492
+ const stacks = _TabindexLoan.#registry.stacks;
493
+ const stack = stacks.get(element) ?? this.#seed(element);
494
+ stacks.set(element, stack);
495
+ return stack;
496
+ }
497
+ #seed(element) {
498
+ const current = element.getAttribute("tabindex");
499
+ const holds = [];
500
+ for (const record of _TabindexLoan.#registry.names) {
501
+ const value = element.getAttribute(record);
502
+ if (value !== null) holds.push({ loan: null, record, value, linked: true });
503
+ }
504
+ holds.sort((one, other) => Number(one.value === current) - Number(other.value === current));
505
+ for (const [index, hold] of holds.entries()) hold.linked = index > 0;
506
+ return holds;
507
+ }
508
+ #release(element, stack, hold, preserveFocus = false) {
509
+ const current = element.getAttribute("tabindex");
510
+ const index = stack.indexOf(hold);
511
+ const owns = current === hold.value && !stack.slice(index + 1).some((above2) => above2.value === current);
512
+ if (owns && preserveFocus && holdsFocus(element)) return false;
513
+ stack.splice(index, 1);
514
+ const above = stack[index];
515
+ if (above) above.linked &&= hold.linked;
516
+ this.#mark(element, stack);
517
+ if (!owns) return true;
518
+ const below = hold.linked ? stack[index - 1] : void 0;
519
+ if (!below) element.removeAttribute("tabindex");
520
+ else if (below.value !== current) element.setAttribute("tabindex", below.value);
521
+ return true;
522
+ }
523
+ #mark(element, stack) {
524
+ const records = /* @__PURE__ */ new Map([[this.#record, null]]);
525
+ for (const hold of stack) records.set(hold.record, hold.value);
526
+ for (const [name, recorded] of records) {
527
+ setAttributeIfChanged(element, name, recorded);
528
+ }
529
+ }
530
+ };
531
+
292
532
  function targetSelector(identifier, name) {
293
533
  return `[data-${identifier}-target~="${name}"]`;
294
534
  }
@@ -406,6 +646,11 @@ var FileDropzoneController = class _FileDropzoneController extends Controller {
406
646
  noun: "item template"
407
647
  });
408
648
  #gate = new DetachGate();
649
+ #listInert = new AttributeLease("inert", this.identifier);
650
+ #listListeners = new ListenerSet();
651
+ #listMorph = new MorphRenderWatcher(() => this.#settleLists());
652
+ #focusLoan = new TabindexLoan("-1", this.identifier);
653
+ #currentList = null;
409
654
  #listWatch = new MutationObserver((records) => {
410
655
  const lost = records.some(
411
656
  (record) => Array.from(record.removedNodes).some(
@@ -426,11 +671,17 @@ var FileDropzoneController = class _FileDropzoneController extends Controller {
426
671
  this.#connected = true;
427
672
  this.#rows.connect();
428
673
  if (!moved) this.#discardInherited();
674
+ this.#focusLoan.reclaim(this.element);
675
+ this.#listMorph.observe(this.element);
676
+ this.#settleLists();
429
677
  }
430
678
  disconnect() {
431
679
  this.#connected = false;
432
- for (const list of this.listTargets) list.removeEventListener("click", this.#onItemClick);
680
+ this.#listListeners.dispose();
681
+ this.#currentList = null;
433
682
  this.#listWatch.disconnect();
683
+ this.#listMorph.disconnect();
684
+ this.#focusLoan.returnAll();
434
685
  this.#gate.disconnected(this, () => this.#teardown());
435
686
  }
436
687
  #discardInherited() {
@@ -452,14 +703,12 @@ var FileDropzoneController = class _FileDropzoneController extends Controller {
452
703
  this.#syncInput();
453
704
  this.dispatch("reconcile", { detail: { files: this.#files } });
454
705
  }
455
- listTargetConnected(list) {
456
- list.addEventListener("click", this.#onItemClick);
457
- this.#listWatch.observe(list, { childList: true });
458
- this.#rehome();
706
+ listTargetConnected() {
707
+ if (this.#connected) this.#settleLists();
459
708
  }
460
709
  listTargetDisconnected(list) {
461
- list.removeEventListener("click", this.#onItemClick);
462
- if (this.#connected) this.#rehome();
710
+ if (!this.listTargets.includes(list)) this.#listInert.return(list);
711
+ if (this.#connected) this.#settleLists();
463
712
  }
464
713
  inputTargetConnected() {
465
714
  if (this.#connected) this.#syncInput();
@@ -512,7 +761,7 @@ var FileDropzoneController = class _FileDropzoneController extends Controller {
512
761
  if (index !== -1) this.#removeAt(index);
513
762
  };
514
763
  #addFiles(files) {
515
- this.#rehome();
764
+ this.#settleLists();
516
765
  this.#invalid = false;
517
766
  const rejected = /* @__PURE__ */ new Map();
518
767
  const turnedAway = [];
@@ -646,9 +895,47 @@ var FileDropzoneController = class _FileDropzoneController extends Controller {
646
895
  }
647
896
  #rehome() {
648
897
  if (!this.hasListTarget) return;
898
+ const focused = deepActiveElement(this.element.ownerDocument);
899
+ const restore = this.#entries.some((entry) => flatTreeContains(entry.item, focused));
649
900
  for (const entry of this.#entries) {
650
901
  if (!this.listTarget.contains(entry.item)) this.listTarget.appendChild(entry.item);
651
902
  }
903
+ if (restore && focused instanceof HTMLElement) {
904
+ if (canTakeFocus(focused)) focused.focus();
905
+ if (deepActiveElement(this.element.ownerDocument) !== focused) this.#rescueListFocus();
906
+ }
907
+ }
908
+ #settleLists() {
909
+ const [current, ...behind] = this.listTargets;
910
+ if (current) this.#listInert.return(current);
911
+ if (this.#currentList !== (current ?? null)) {
912
+ this.#listListeners.dispose();
913
+ this.#listWatch.disconnect();
914
+ this.#currentList = current ?? null;
915
+ if (current) {
916
+ this.#listListeners.add(current, "click", this.#onItemClick);
917
+ this.#listWatch.observe(current, { childList: true });
918
+ }
919
+ }
920
+ this.#rehome();
921
+ for (const list of behind) {
922
+ if (flatTreeContains(list, deepActiveElement(this.element.ownerDocument)))
923
+ this.#rescueListFocus();
924
+ this.#listInert.write(list, "");
925
+ }
926
+ }
927
+ #rescueListFocus() {
928
+ const candidates = [
929
+ ...this.hasTriggerTarget ? [this.triggerTarget] : [],
930
+ ...this.hasInputTarget ? [this.inputTarget] : []
931
+ ];
932
+ for (const candidate of candidates) {
933
+ if (!canTakeFocus(candidate)) continue;
934
+ candidate.focus();
935
+ if (deepActiveElement(this.element.ownerDocument) === candidate) return;
936
+ }
937
+ this.#focusLoan.lend(this.element);
938
+ this.element.focus();
652
939
  }
653
940
  #endDrag() {
654
941
  this.#dragging = false;
@@ -670,6 +957,7 @@ var FileDropzoneController = class _FileDropzoneController extends Controller {
670
957
  this.#endDrag();
671
958
  }
672
959
  #teardown() {
960
+ this.#listInert.returnAll();
673
961
  this.#reset();
674
962
  }
675
963
  get #isDisabled() {
@@ -1,5 +1,179 @@
1
1
  import { Controller } from '@hotwired/stimulus';
2
2
 
3
+ function setAttributeIfChanged(element, name, value, beforeWrite) {
4
+ if (element.getAttribute(name) === value) return false;
5
+ beforeWrite?.();
6
+ if (value === null) element.removeAttribute(name);
7
+ else element.setAttribute(name, value);
8
+ return true;
9
+ }
10
+
11
+ function sharedRegistry(key, create) {
12
+ const symbol = Symbol.for(key);
13
+ const scope = globalThis;
14
+ const existing = scope[symbol];
15
+ if (existing !== void 0) return existing;
16
+ const registry2 = create();
17
+ Object.defineProperty(globalThis, symbol, { value: registry2 });
18
+ return registry2;
19
+ }
20
+
21
+ var registry = sharedRegistry(
22
+ "stimeo-ui.attribute-lease.registry.v1",
23
+ () => ({ stacks: /* @__PURE__ */ new WeakMap(), names: /* @__PURE__ */ new Map() })
24
+ );
25
+ function isAttributeValue(value) {
26
+ return value === null || typeof value === "string";
27
+ }
28
+ function readLeaseRecord(element, record) {
29
+ try {
30
+ const parsed = JSON.parse(element.getAttribute(record) ?? "null");
31
+ if (!Array.isArray(parsed)) return void 0;
32
+ const [original, written, ...rest] = parsed;
33
+ const linked = rest[0] !== false;
34
+ const beneath = linked ? rest : rest.slice(1);
35
+ if (!beneath.every((under) => typeof under === "string")) return void 0;
36
+ return isAttributeValue(original) && isAttributeValue(written) ? { original, written, linked, beneath } : void 0;
37
+ } catch {
38
+ return void 0;
39
+ }
40
+ }
41
+ function attributeStack(element, attribute) {
42
+ const byAttribute = registry.stacks.get(element) ?? /* @__PURE__ */ new Map();
43
+ registry.stacks.set(element, byAttribute);
44
+ const known = byAttribute.get(attribute);
45
+ if (known) return known;
46
+ const found = [];
47
+ for (const record of registry.names.get(attribute) ?? []) {
48
+ const read = readLeaseRecord(element, record);
49
+ if (read) found.push({ ...read, record });
50
+ }
51
+ const depth = ({ beneath }) => beneath.filter((name) => found.some((other) => other.record === name)).length;
52
+ const stack = found.sort((one, other) => depth(one) - depth(other)).map(({ record, written, original, linked }, index) => ({
53
+ lease: null,
54
+ record,
55
+ written,
56
+ original,
57
+ linked: linked && index > 0
58
+ }));
59
+ byAttribute.set(attribute, stack);
60
+ return stack;
61
+ }
62
+ function findHold(stack, lease, record) {
63
+ return stack.find((held) => held.lease === lease) ?? stack.find((held) => held.lease === null && held.record === record);
64
+ }
65
+ var AttributeLease = class {
66
+ #attribute;
67
+ #record;
68
+ #base;
69
+ #preserveAuthor;
70
+ #held = /* @__PURE__ */ new Set();
71
+ constructor(attribute, owner, options = {}) {
72
+ this.#attribute = attribute;
73
+ this.#record = `data-${owner}-${attribute}-lease`;
74
+ this.#base = options.base === true;
75
+ this.#preserveAuthor = options.preserveAuthor === true;
76
+ const names = registry.names;
77
+ names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
78
+ }
79
+ write(element, value, beforeWrite) {
80
+ const stack = attributeStack(element, this.#attribute);
81
+ const hold = this.#take(stack) ?? this.#acquire(element, stack);
82
+ this.#held.add(element);
83
+ const shows = !this.#covered(element, stack, hold);
84
+ hold.written = value;
85
+ this.#mark(element, stack);
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;
107
+ }
108
+ return(element) {
109
+ const held = this.#held.delete(element);
110
+ const known = registry.stacks.get(element)?.has(this.#attribute);
111
+ const stack = held || known || element.hasAttribute(this.#record) ? attributeStack(element, this.#attribute) : [];
112
+ const hold = this.#take(stack);
113
+ if (!hold) return false;
114
+ const carries = element.getAttribute(this.#attribute) === hold.written;
115
+ const owns = carries && !this.#covered(element, stack, hold);
116
+ const index = stack.indexOf(hold);
117
+ stack.splice(index, 1);
118
+ const above = stack[index];
119
+ if (above) above.linked &&= hold.linked;
120
+ this.#mark(element, stack);
121
+ if (!owns) return true;
122
+ const below = hold.linked ? stack[index - 1] : void 0;
123
+ this.#reflect(element, below ? below.written : hold.original);
124
+ return true;
125
+ }
126
+ returnAll() {
127
+ for (const element of Array.from(this.#held)) this.return(element);
128
+ }
129
+ #take(stack) {
130
+ const hold = findHold(stack, this, this.#record);
131
+ if (hold) hold.lease = this;
132
+ return hold;
133
+ }
134
+ #acquire(element, stack) {
135
+ const current = element.getAttribute(this.#attribute);
136
+ const top = stack.at(-1);
137
+ const bottom = stack[0];
138
+ const over = top?.written === current ? top : void 0;
139
+ const from = this.#base ? this.#preserveAuthor && !stack.some((held) => held.written === current) ? void 0 : bottom : over;
140
+ const hold = {
141
+ lease: this,
142
+ record: this.#record,
143
+ written: current,
144
+ original: from ? from.original : current,
145
+ linked: !this.#base && over !== void 0
146
+ };
147
+ if (this.#base && bottom) {
148
+ bottom.linked = true;
149
+ stack.unshift(hold);
150
+ } else stack.push(hold);
151
+ return hold;
152
+ }
153
+ #covered(element, stack, hold) {
154
+ const current = element.getAttribute(this.#attribute);
155
+ return stack.slice(stack.indexOf(hold) + 1).some((above) => above.written === current);
156
+ }
157
+ #mark(element, stack) {
158
+ const records = /* @__PURE__ */ new Map([[this.#record, null]]);
159
+ stack.forEach((hold, index) => {
160
+ const names = stack.slice(0, index).map((under) => under.record);
161
+ const beneath = [...new Set(names.reverse())].filter((name) => name !== hold.record);
162
+ const marker = hold.linked || beneath.length === 0 ? [] : [false];
163
+ records.set(
164
+ hold.record,
165
+ hold.written === hold.original && beneath.length === 0 && index === stack.length - 1 ? null : JSON.stringify([hold.original, hold.written, ...marker, ...beneath])
166
+ );
167
+ });
168
+ for (const [name, recorded] of records) {
169
+ setAttributeIfChanged(element, name, recorded);
170
+ }
171
+ }
172
+ #reflect(element, value, beforeWrite) {
173
+ setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
174
+ }
175
+ };
176
+
3
177
  var ListenerSet = class {
4
178
  #abort = new AbortController();
5
179
  add(target, type, handler, options) {
@@ -81,6 +255,7 @@ var FilterController = class extends Controller {
81
255
  #reported = null;
82
256
  #connected = false;
83
257
  #morphRender = new MorphRenderWatcher(() => this.#evaluate());
258
+ #hidden = new AttributeLease("hidden", this.identifier);
84
259
  #listeners = new ListenerSet();
85
260
  connect() {
86
261
  this.#morphRender.observe(this.element);
@@ -94,6 +269,20 @@ var FilterController = class extends Controller {
94
269
  this.#connected = false;
95
270
  this.#listeners.dispose();
96
271
  }
272
+ itemTargetDisconnected(item) {
273
+ this.#releaseHidden(item);
274
+ }
275
+ groupTargetDisconnected(group) {
276
+ this.#releaseHidden(group);
277
+ }
278
+ emptyTargetDisconnected(empty) {
279
+ this.#releaseHidden(empty);
280
+ }
281
+ #releaseHidden(element) {
282
+ if (this.itemTargets.includes(element) || this.groupTargets.includes(element) || this.emptyTargets.includes(element))
283
+ return;
284
+ this.#hidden.return(element);
285
+ }
97
286
  matchValueChanged() {
98
287
  if (!this.#connected) return;
99
288
  this.#evaluate();
@@ -105,15 +294,15 @@ var FilterController = class extends Controller {
105
294
  const active = this.#activeTokens();
106
295
  let visibleCount = 0;
107
296
  for (const item of this.itemTargets) {
108
- const visible = this.#matches(item, active);
109
- item.hidden = !visible;
110
- if (visible) visibleCount += 1;
297
+ if (this.#matches(item, active)) this.#hidden.return(item);
298
+ else if (!item.hidden) this.#hidden.write(item, "");
299
+ if (!item.hidden) visibleCount += 1;
111
300
  }
112
301
  for (const group of this.groupTargets) {
113
- group.hidden = !this.#hasVisibleItem(group);
302
+ this.#hidden.write(group, this.#hasVisibleItem(group) ? null : "");
114
303
  }
115
304
  for (const empty of this.emptyTargets) {
116
- empty.hidden = visibleCount > 0;
305
+ this.#hidden.write(empty, visibleCount > 0 ? "" : null);
117
306
  }
118
307
  const total = this.itemTargets.length;
119
308
  const reported = this.#reported;