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
@@ -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
  function ownerIndex(candidates, node) {
4
178
  if (!(node instanceof Node)) return -1;
5
179
  return candidates.findIndex((candidate) => candidate.contains(node));
@@ -217,13 +391,6 @@ var NumberValueReader = class {
217
391
  }
218
392
  };
219
393
 
220
- function setAttributeIfChanged(element, name, value, beforeWrite) {
221
- if (element.getAttribute(name) === value) return false;
222
- if (value === null) element.removeAttribute(name);
223
- else element.setAttribute(name, value);
224
- return true;
225
- }
226
-
227
394
  var OwnedText = class {
228
395
  #attribute;
229
396
  #channel;
@@ -355,16 +522,6 @@ function queryOpenDescendants(root, selector) {
355
522
  return matches;
356
523
  }
357
524
 
358
- function sharedRegistry(key, create) {
359
- const symbol = Symbol.for(key);
360
- const scope = globalThis;
361
- const existing = scope[symbol];
362
- if (existing !== void 0) return existing;
363
- const registry = create();
364
- Object.defineProperty(globalThis, symbol, { value: registry });
365
- return registry;
366
- }
367
-
368
525
  function holdsFocus(element) {
369
526
  return element.matches(":focus") || deepActiveElement(element.ownerDocument) === element;
370
527
  }
@@ -500,6 +657,7 @@ var OverflowMenuController = class _OverflowMenuController extends Controller {
500
657
  static events = ["change", "reconcile"];
501
658
  #layout = new LayoutObserver(() => this.#scheduleUpdate());
502
659
  #timers = new SafeTimeout();
660
+ #moreHidden = new AttributeLease("hidden", this.identifier);
503
661
  #items = [];
504
662
  #index = /* @__PURE__ */ new WeakMap();
505
663
  #widths = /* @__PURE__ */ new WeakMap();
@@ -525,7 +683,7 @@ var OverflowMenuController = class _OverflowMenuController extends Controller {
525
683
  this.#connected = false;
526
684
  this.#layout.disconnect();
527
685
  this.#timers.clearAll();
528
- this.#restoreAll();
686
+ if (this.element.isConnected) this.#restoreAll();
529
687
  this.#lastHidden = null;
530
688
  }
531
689
  itemsTargetConnected() {
@@ -539,7 +697,10 @@ var OverflowMenuController = class _OverflowMenuController extends Controller {
539
697
  this.#followTargets();
540
698
  }
541
699
  moreTargetDisconnected(more) {
542
- if (more === this.#wrapper && !this.moreTargets.includes(more)) this.#release();
700
+ if (!this.scope.containsElement(more) || !this.moreTargets.includes(more)) {
701
+ if (more === this.#wrapper) this.#release();
702
+ this.#moreHidden.return(more);
703
+ }
543
704
  this.#followTargets();
544
705
  }
545
706
  moreLabelValueChanged() {
@@ -561,7 +722,7 @@ var OverflowMenuController = class _OverflowMenuController extends Controller {
561
722
  this.#wrapper = this.moreTarget;
562
723
  this.#syncLabel();
563
724
  this.#syncItems(this.itemsTarget, this.moreTarget);
564
- this.moreTarget.hidden = false;
725
+ this.#moreHidden.write(this.moreTarget, null);
565
726
  if (this.#items.some((item) => item.parentElement !== this.itemsTarget && !this.#widths.has(item))) {
566
727
  this.#removeBoundary(this.itemsTarget);
567
728
  for (const item of this.#items) this.#unbank(item);
@@ -626,7 +787,7 @@ var OverflowMenuController = class _OverflowMenuController extends Controller {
626
787
  if (inMore && pass === this.#pass) this.#rescueFocus();
627
788
  if (pass !== this.#pass) return null;
628
789
  }
629
- this.moreTarget.hidden = count === 0;
790
+ this.#moreHidden.write(this.moreTarget, count === 0 ? "" : null);
630
791
  if (count > 0) this.element.setAttribute("data-overflowing", "true");
631
792
  else this.element.removeAttribute("data-overflowing");
632
793
  this.element.setAttribute("data-overflow-count", String(count));
@@ -841,7 +1002,7 @@ var OverflowMenuController = class _OverflowMenuController extends Controller {
841
1002
  this.#closeMenu(more);
842
1003
  const trigger = this.#trigger(more);
843
1004
  if (trigger !== null) this.#releaseLabel(trigger);
844
- more.hidden = true;
1005
+ this.#moreHidden.return(more);
845
1006
  this.element.removeAttribute("data-overflowing");
846
1007
  this.element.removeAttribute("data-overflow-count");
847
1008
  this.#tabindex.returnAll();
@@ -22,6 +22,180 @@ function actionSource(source) {
22
22
  };
23
23
  }
24
24
 
25
+ function setAttributeIfChanged(element, name, value, beforeWrite) {
26
+ if (element.getAttribute(name) === value) return false;
27
+ beforeWrite?.();
28
+ if (value === null) element.removeAttribute(name);
29
+ else element.setAttribute(name, value);
30
+ return true;
31
+ }
32
+
33
+ function sharedRegistry(key, create) {
34
+ const symbol = Symbol.for(key);
35
+ const scope = globalThis;
36
+ const existing = scope[symbol];
37
+ if (existing !== void 0) return existing;
38
+ const registry2 = create();
39
+ Object.defineProperty(globalThis, symbol, { value: registry2 });
40
+ return registry2;
41
+ }
42
+
43
+ var registry = sharedRegistry(
44
+ "stimeo-ui.attribute-lease.registry.v1",
45
+ () => ({ stacks: /* @__PURE__ */ new WeakMap(), names: /* @__PURE__ */ new Map() })
46
+ );
47
+ function isAttributeValue(value) {
48
+ return value === null || typeof value === "string";
49
+ }
50
+ function readLeaseRecord(element, record) {
51
+ try {
52
+ const parsed = JSON.parse(element.getAttribute(record) ?? "null");
53
+ if (!Array.isArray(parsed)) return void 0;
54
+ const [original, written, ...rest] = parsed;
55
+ const linked = rest[0] !== false;
56
+ const beneath = linked ? rest : rest.slice(1);
57
+ if (!beneath.every((under) => typeof under === "string")) return void 0;
58
+ return isAttributeValue(original) && isAttributeValue(written) ? { original, written, linked, beneath } : void 0;
59
+ } catch {
60
+ return void 0;
61
+ }
62
+ }
63
+ function attributeStack(element, attribute) {
64
+ const byAttribute = registry.stacks.get(element) ?? /* @__PURE__ */ new Map();
65
+ registry.stacks.set(element, byAttribute);
66
+ const known = byAttribute.get(attribute);
67
+ if (known) return known;
68
+ const found = [];
69
+ for (const record of registry.names.get(attribute) ?? []) {
70
+ const read = readLeaseRecord(element, record);
71
+ if (read) found.push({ ...read, record });
72
+ }
73
+ const depth = ({ beneath }) => beneath.filter((name) => found.some((other) => other.record === name)).length;
74
+ const stack = found.sort((one, other) => depth(one) - depth(other)).map(({ record, written, original, linked }, index) => ({
75
+ lease: null,
76
+ record,
77
+ written,
78
+ original,
79
+ linked: linked && index > 0
80
+ }));
81
+ byAttribute.set(attribute, stack);
82
+ return stack;
83
+ }
84
+ function findHold(stack, lease, record) {
85
+ return stack.find((held) => held.lease === lease) ?? stack.find((held) => held.lease === null && held.record === record);
86
+ }
87
+ var AttributeLease = class {
88
+ #attribute;
89
+ #record;
90
+ #base;
91
+ #preserveAuthor;
92
+ #held = /* @__PURE__ */ new Set();
93
+ constructor(attribute, owner, options = {}) {
94
+ this.#attribute = attribute;
95
+ this.#record = `data-${owner}-${attribute}-lease`;
96
+ this.#base = options.base === true;
97
+ this.#preserveAuthor = options.preserveAuthor === true;
98
+ const names = registry.names;
99
+ names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
100
+ }
101
+ write(element, value, beforeWrite) {
102
+ const stack = attributeStack(element, this.#attribute);
103
+ const hold = this.#take(stack) ?? this.#acquire(element, stack);
104
+ this.#held.add(element);
105
+ const shows = !this.#covered(element, stack, hold);
106
+ hold.written = value;
107
+ this.#mark(element, stack);
108
+ if (shows) this.#reflect(element, value, beforeWrite);
109
+ }
110
+ adopt(element, options = {}) {
111
+ const known = registry.stacks.get(element)?.has(this.#attribute);
112
+ if (!this.#held.has(element) && !known && !element.hasAttribute(this.#record)) return false;
113
+ const stack = attributeStack(element, this.#attribute);
114
+ const hold = this.#take(stack);
115
+ if (!hold) return false;
116
+ const current = element.getAttribute(this.#attribute);
117
+ if (options.ifChanged && (current === hold.written || this.#covered(element, stack, hold))) {
118
+ return false;
119
+ }
120
+ this.#held.add(element);
121
+ hold.original = current;
122
+ hold.linked = false;
123
+ for (const above of stack.slice(stack.indexOf(hold) + 1)) {
124
+ if (!above.linked) break;
125
+ above.original = current;
126
+ }
127
+ this.#mark(element, stack);
128
+ return true;
129
+ }
130
+ return(element) {
131
+ const held = this.#held.delete(element);
132
+ const known = registry.stacks.get(element)?.has(this.#attribute);
133
+ const stack = held || known || element.hasAttribute(this.#record) ? attributeStack(element, this.#attribute) : [];
134
+ const hold = this.#take(stack);
135
+ if (!hold) return false;
136
+ const carries = element.getAttribute(this.#attribute) === hold.written;
137
+ const owns = carries && !this.#covered(element, stack, hold);
138
+ const index = stack.indexOf(hold);
139
+ stack.splice(index, 1);
140
+ const above = stack[index];
141
+ if (above) above.linked &&= hold.linked;
142
+ this.#mark(element, stack);
143
+ if (!owns) return true;
144
+ const below = hold.linked ? stack[index - 1] : void 0;
145
+ this.#reflect(element, below ? below.written : hold.original);
146
+ return true;
147
+ }
148
+ returnAll() {
149
+ for (const element of Array.from(this.#held)) this.return(element);
150
+ }
151
+ #take(stack) {
152
+ const hold = findHold(stack, this, this.#record);
153
+ if (hold) hold.lease = this;
154
+ return hold;
155
+ }
156
+ #acquire(element, stack) {
157
+ const current = element.getAttribute(this.#attribute);
158
+ const top = stack.at(-1);
159
+ const bottom = stack[0];
160
+ const over = top?.written === current ? top : void 0;
161
+ const from = this.#base ? this.#preserveAuthor && !stack.some((held) => held.written === current) ? void 0 : bottom : over;
162
+ const hold = {
163
+ lease: this,
164
+ record: this.#record,
165
+ written: current,
166
+ original: from ? from.original : current,
167
+ linked: !this.#base && over !== void 0
168
+ };
169
+ if (this.#base && bottom) {
170
+ bottom.linked = true;
171
+ stack.unshift(hold);
172
+ } else stack.push(hold);
173
+ return hold;
174
+ }
175
+ #covered(element, stack, hold) {
176
+ const current = element.getAttribute(this.#attribute);
177
+ return stack.slice(stack.indexOf(hold) + 1).some((above) => above.written === current);
178
+ }
179
+ #mark(element, stack) {
180
+ const records = /* @__PURE__ */ new Map([[this.#record, null]]);
181
+ stack.forEach((hold, index) => {
182
+ const names = stack.slice(0, index).map((under) => under.record);
183
+ const beneath = [...new Set(names.reverse())].filter((name) => name !== hold.record);
184
+ const marker = hold.linked || beneath.length === 0 ? [] : [false];
185
+ records.set(
186
+ hold.record,
187
+ hold.written === hold.original && beneath.length === 0 && index === stack.length - 1 ? null : JSON.stringify([hold.original, hold.written, ...marker, ...beneath])
188
+ );
189
+ });
190
+ for (const [name, recorded] of records) {
191
+ setAttributeIfChanged(element, name, recorded);
192
+ }
193
+ }
194
+ #reflect(element, value, beforeWrite) {
195
+ setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
196
+ }
197
+ };
198
+
25
199
  var HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
26
200
  function inheritsFieldsetDisabled(control) {
27
201
  let fieldset = control.closest("fieldset[disabled]");
@@ -185,13 +359,6 @@ var NumberValueReader = class {
185
359
  }
186
360
  };
187
361
 
188
- function setAttributeIfChanged(element, name, value, beforeWrite) {
189
- if (element.getAttribute(name) === value) return false;
190
- if (value === null) element.removeAttribute(name);
191
- else element.setAttribute(name, value);
192
- return true;
193
- }
194
-
195
362
  function queryOpenDescendants(root, selector) {
196
363
  const matches = [];
197
364
  const roots = [root];
@@ -208,16 +375,6 @@ function queryOpenDescendants(root, selector) {
208
375
  return matches;
209
376
  }
210
377
 
211
- function sharedRegistry(key, create) {
212
- const symbol = Symbol.for(key);
213
- const scope = globalThis;
214
- const existing = scope[symbol];
215
- if (existing !== void 0) return existing;
216
- const registry = create();
217
- Object.defineProperty(globalThis, symbol, { value: registry });
218
- return registry;
219
- }
220
-
221
378
  function holdsFocus(element) {
222
379
  return element.matches(":focus") || deepActiveElement(element.ownerDocument) === element;
223
380
  }
@@ -345,6 +502,7 @@ var PaginationController = class _PaginationController extends Controller {
345
502
  return `data-${this.identifier}-boundary-disabled`;
346
503
  }
347
504
  #tabindex = new TabindexLoan("-1", this.identifier);
505
+ #current = new AttributeLease("aria-current", this.identifier);
348
506
  #repaint = new MorphRenderWatcher(() => this.#reconcilePage());
349
507
  #shown = 1;
350
508
  connect() {
@@ -366,6 +524,9 @@ var PaginationController = class _PaginationController extends Controller {
366
524
  pageTargetConnected() {
367
525
  this.#repaint.schedule();
368
526
  }
527
+ pageTargetDisconnected(button) {
528
+ if (!this.pageTargets.includes(button)) this.#current.return(button);
529
+ }
369
530
  prevTargetConnected() {
370
531
  this.#repaint.schedule();
371
532
  }
@@ -427,11 +588,7 @@ var PaginationController = class _PaginationController extends Controller {
427
588
  const token = this.#moveToken;
428
589
  const page = this.#page;
429
590
  for (const button of this.pageTargets) {
430
- if (Number(button.dataset.page) === page) {
431
- button.setAttribute("aria-current", "page");
432
- } else {
433
- button.removeAttribute("aria-current");
434
- }
591
+ this.#current.write(button, Number(button.dataset.page) === page ? "page" : null);
435
592
  }
436
593
  const prev = this.hasPrevTarget ? this.prevTarget : null;
437
594
  const next = this.hasNextTarget ? this.nextTarget : null;
@@ -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