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
 
@@ -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
 
@@ -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) {
@@ -126,6 +300,7 @@ var StepIndicatorController = class _StepIndicatorController extends Controller
126
300
  static actions = ["setIndex"];
127
301
  static events = ["change"];
128
302
  #repaint = new MorphRenderWatcher(() => this.#render());
303
+ #current = new AttributeLease("aria-current", this.identifier);
129
304
  connect() {
130
305
  this.#repaint.observe(this.element);
131
306
  this.#render();
@@ -136,7 +311,11 @@ var StepIndicatorController = class _StepIndicatorController extends Controller
136
311
  stepTargetConnected() {
137
312
  this.#repaint.schedule();
138
313
  }
139
- stepTargetDisconnected() {
314
+ stepTargetDisconnected(step) {
315
+ if (!this.stepTargets.includes(step)) {
316
+ step.removeAttribute("data-state");
317
+ this.#current.return(step);
318
+ }
140
319
  this.#repaint.schedule();
141
320
  }
142
321
  indexValueChanged() {
@@ -160,11 +339,7 @@ var StepIndicatorController = class _StepIndicatorController extends Controller
160
339
  const current = this.#clamp(this.#safeIndex);
161
340
  this.stepTargets.forEach((step, index) => {
162
341
  step.dataset.state = index < current ? "complete" : index === current ? "current" : "upcoming";
163
- if (index === current) {
164
- step.setAttribute("aria-current", "step");
165
- } else {
166
- step.removeAttribute("aria-current");
167
- }
342
+ this.#current.write(step, index === current ? "step" : null);
168
343
  });
169
344
  const ratio = total > 1 ? current / (total - 1) : 0;
170
345
  this.element.style.setProperty("--stimeo--step-indicator-ratio", String(ratio));
@@ -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 NUMBER_BOUNDS = {
4
178
  finite: { finite: true }};
5
179
  function matchesNumberBounds(value, bounds) {
@@ -133,6 +307,8 @@ var StepperController = class _StepperController extends Controller {
133
307
  static actions = ["goto", "next", "prev"];
134
308
  static events = ["change", "reconcile"];
135
309
  #repaint = new MorphRenderWatcher(() => this.#reconcileStep());
310
+ #current = new AttributeLease("aria-current", this.identifier);
311
+ #buttons = /* @__PURE__ */ new Map();
136
312
  #shown = null;
137
313
  connect() {
138
314
  this.#repaint.observe(this.element);
@@ -148,7 +324,13 @@ var StepperController = class _StepperController extends Controller {
148
324
  stepTargetConnected() {
149
325
  this.#repaint.schedule();
150
326
  }
151
- stepTargetDisconnected() {
327
+ stepTargetDisconnected(step) {
328
+ if (!this.stepTargets.includes(step)) {
329
+ step.removeAttribute("data-state");
330
+ const button = this.#buttons.get(step);
331
+ if (button) this.#current.return(button);
332
+ this.#buttons.delete(step);
333
+ }
152
334
  this.#repaint.schedule();
153
335
  }
154
336
  next() {
@@ -197,12 +379,12 @@ var StepperController = class _StepperController extends Controller {
197
379
  this.stepTargets.forEach((step, index) => {
198
380
  step.dataset.state = index < current ? "complete" : index === current ? "current" : "upcoming";
199
381
  const button = step.querySelector("button");
382
+ const previous = this.#buttons.get(step);
383
+ if (previous && previous !== button) this.#current.return(previous);
384
+ if (button) this.#buttons.set(step, button);
385
+ else this.#buttons.delete(step);
200
386
  if (!button) return;
201
- if (index === current) {
202
- button.setAttribute("aria-current", "step");
203
- } else {
204
- button.removeAttribute("aria-current");
205
- }
387
+ this.#current.write(button, index === current ? "step" : null);
206
388
  });
207
389
  }
208
390
  #clampIndex(index) {
@@ -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
 
@@ -13,6 +13,7 @@ function announce(message, options = {}) {
13
13
 
14
14
  function setAttributeIfChanged(element, name, value, beforeWrite) {
15
15
  if (element.getAttribute(name) === value) return false;
16
+ beforeWrite?.();
16
17
  if (value === null) element.removeAttribute(name);
17
18
  else element.setAttribute(name, value);
18
19
  return true;
@@ -86,14 +87,34 @@ var AttributeLease = class {
86
87
  const names = registry.names;
87
88
  names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
88
89
  }
89
- write(element, value) {
90
+ write(element, value, beforeWrite) {
90
91
  const stack = attributeStack(element, this.#attribute);
91
92
  const hold = this.#take(stack) ?? this.#acquire(element, stack);
92
93
  this.#held.add(element);
93
94
  const shows = !this.#covered(element, stack, hold);
94
95
  hold.written = value;
95
96
  this.#mark(element, stack);
96
- if (shows) this.#reflect(element, value);
97
+ if (shows) this.#reflect(element, value, beforeWrite);
98
+ }
99
+ adopt(element, options = {}) {
100
+ const known = registry.stacks.get(element)?.has(this.#attribute);
101
+ if (!this.#held.has(element) && !known && !element.hasAttribute(this.#record)) return false;
102
+ const stack = attributeStack(element, this.#attribute);
103
+ const hold = this.#take(stack);
104
+ if (!hold) return false;
105
+ const current = element.getAttribute(this.#attribute);
106
+ if (options.ifChanged && (current === hold.written || this.#covered(element, stack, hold))) {
107
+ return false;
108
+ }
109
+ this.#held.add(element);
110
+ hold.original = current;
111
+ hold.linked = false;
112
+ for (const above of stack.slice(stack.indexOf(hold) + 1)) {
113
+ if (!above.linked) break;
114
+ above.original = current;
115
+ }
116
+ this.#mark(element, stack);
117
+ return true;
97
118
  }
98
119
  return(element) {
99
120
  const held = this.#held.delete(element);
@@ -159,8 +180,8 @@ var AttributeLease = class {
159
180
  setAttributeIfChanged(element, name, recorded);
160
181
  }
161
182
  }
162
- #reflect(element, value) {
163
- setAttributeIfChanged(element, this.#attribute, value);
183
+ #reflect(element, value, beforeWrite) {
184
+ setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
164
185
  }
165
186
  };
166
187