stimeo-ui 0.18.1 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +54 -0
  3. data/dist/cable/index.js +6 -5
  4. data/dist/controllers/alert_dialog_controller.js +324 -76
  5. data/dist/controllers/announcer_controller.js +22 -9
  6. data/dist/controllers/auto_submit_controller.js +103 -16
  7. data/dist/controllers/avatar_controller.js +29 -9
  8. data/dist/controllers/breadcrumb_controller.js +205 -17
  9. data/dist/controllers/bulk_select_controller.js +31 -13
  10. data/dist/controllers/calendar_controller.js +242 -7
  11. data/dist/controllers/carousel_controller.js +70 -15
  12. data/dist/controllers/character_counter_controller.js +103 -16
  13. data/dist/controllers/clipboard_controller.js +6 -5
  14. data/dist/controllers/collapsible_controller.js +35 -8
  15. data/dist/controllers/combobox_controller.js +155 -26
  16. data/dist/controllers/command_palette_controller.js +445 -117
  17. data/dist/controllers/conditional_fields_controller.js +84 -44
  18. data/dist/controllers/confirm_controller.js +303 -68
  19. data/dist/controllers/context_menu_controller.js +59 -30
  20. data/dist/controllers/countdown_controller.js +6 -5
  21. data/dist/controllers/currency_input_controller.js +72 -7
  22. data/dist/controllers/data_grid_controller.js +273 -51
  23. data/dist/controllers/date_range_picker_controller.js +27 -5
  24. data/dist/controllers/dialog_controller.js +330 -79
  25. data/dist/controllers/direct_upload_controller.js +6 -5
  26. data/dist/controllers/dismissible_controller.js +68 -18
  27. data/dist/controllers/drawer_controller.js +362 -92
  28. data/dist/controllers/dropdown_controller.js +64 -52
  29. data/dist/controllers/editable_controller.js +140 -12
  30. data/dist/controllers/empty_state_controller.js +193 -9
  31. data/dist/controllers/file_dropzone_controller.js +313 -23
  32. data/dist/controllers/filter_controller.js +194 -5
  33. data/dist/controllers/flash_controller.js +205 -17
  34. data/dist/controllers/focus_controller.js +273 -57
  35. data/dist/controllers/form_field_controller.js +71 -14
  36. data/dist/controllers/form_validation_controller.js +11 -7
  37. data/dist/controllers/frame_loading_controller.js +75 -20
  38. data/dist/controllers/hover_card_controller.js +108 -39
  39. data/dist/controllers/input_mask_controller.js +95 -37
  40. data/dist/controllers/intersection_controller.js +61 -29
  41. data/dist/controllers/lazy_frame_controller.js +61 -29
  42. data/dist/controllers/listbox_controller.js +174 -83
  43. data/dist/controllers/local_time_controller.js +1 -7
  44. data/dist/controllers/menu_controller.js +45 -24
  45. data/dist/controllers/menubar_controller.js +232 -52
  46. data/dist/controllers/meter_controller.js +31 -9
  47. data/dist/controllers/multi_select_controller.js +195 -62
  48. data/dist/controllers/navigation_menu_controller.js +1 -1
  49. data/dist/controllers/nested_form_controller.js +275 -21
  50. data/dist/controllers/network_status_controller.js +31 -9
  51. data/dist/controllers/number_input_controller.js +180 -71
  52. data/dist/controllers/otp_controller.js +97 -11
  53. data/dist/controllers/overflow_menu_controller.js +190 -24
  54. data/dist/controllers/pagination_controller.js +186 -24
  55. data/dist/controllers/password_reveal_controller.js +25 -4
  56. data/dist/controllers/password_strength_controller.js +6 -5
  57. data/dist/controllers/popover_controller.js +466 -42
  58. data/dist/controllers/progress_controller.js +31 -9
  59. data/dist/controllers/radio_group_controller.js +279 -88
  60. data/dist/controllers/range_slider_controller.js +72 -54
  61. data/dist/controllers/rating_controller.js +58 -10
  62. data/dist/controllers/read_more_controller.js +191 -25
  63. data/dist/controllers/relative_time_controller.js +1 -7
  64. data/dist/controllers/roving_controller.js +204 -8
  65. data/dist/controllers/scroll_area_controller.js +61 -19
  66. data/dist/controllers/scroll_visibility_controller.js +25 -4
  67. data/dist/controllers/scrollspy_controller.js +240 -32
  68. data/dist/controllers/separator_controller.js +97 -58
  69. data/dist/controllers/sidebar_controller.js +368 -127
  70. data/dist/controllers/skeleton_controller.js +75 -20
  71. data/dist/controllers/slider_controller.js +72 -54
  72. data/dist/controllers/sortable_controller.js +6 -5
  73. data/dist/controllers/spinner_controller.js +75 -20
  74. data/dist/controllers/step_indicator_controller.js +181 -6
  75. data/dist/controllers/stepper_controller.js +188 -6
  76. data/dist/controllers/sticky_observer_controller.js +86 -33
  77. data/dist/controllers/submit_once_controller.js +31 -9
  78. data/dist/controllers/switch_controller.js +84 -44
  79. data/dist/controllers/tabs_controller.js +189 -3
  80. data/dist/controllers/tags_input_controller.js +293 -29
  81. data/dist/controllers/theme_controller.js +192 -5
  82. data/dist/controllers/time_picker_controller.js +77 -42
  83. data/dist/controllers/toast_controller.js +478 -16
  84. data/dist/controllers/toggle_group_controller.js +282 -79
  85. data/dist/controllers/toolbar_controller.js +276 -15
  86. data/dist/controllers/tooltip_controller.js +244 -46
  87. data/dist/controllers/tree_view_controller.js +287 -57
  88. data/dist/index.js +2258 -1016
  89. data/lib/stimeo/ui/version.rb +1 -1
  90. metadata +2 -2
@@ -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
 
@@ -173,70 +194,102 @@ function queryRoot(selector) {
173
194
  }
174
195
  var IntersectionWatcher = class {
175
196
  #onEntries;
176
- #observer = null;
177
- #active = false;
178
- #usingPlatformDefaults = false;
197
+ #session = null;
179
198
  constructor(onEntries) {
180
199
  this.#onEntries = onEntries;
181
200
  }
182
201
  get active() {
183
- return this.#active;
202
+ return this.#session?.active ?? false;
184
203
  }
185
204
  get usingPlatformDefaults() {
186
- return this.#usingPlatformDefaults;
205
+ return this.#session?.usingPlatformDefaults ?? false;
187
206
  }
188
207
  start(targets, options = {}) {
189
- this.stop();
190
- if (typeof IntersectionObserver === "undefined") return false;
191
- const list = Array.isArray(targets) ? targets : [targets];
192
- if (list.length === 0) return false;
193
- const root = "root" in options ? options.root ?? null : queryRoot(options.rootSelector);
208
+ const previous = this.#session;
209
+ const session = {
210
+ observer: null,
211
+ active: false,
212
+ usingPlatformDefaults: false
213
+ };
214
+ this.#session = session;
194
215
  let observer = null;
195
216
  try {
217
+ if (previous) this.#release(previous);
218
+ if (this.#session !== session) return false;
219
+ if (typeof IntersectionObserver === "undefined") return false;
220
+ const list = Array.isArray(targets) ? targets : [targets];
221
+ const empty = list.length === 0;
222
+ if (this.#session !== session) return false;
223
+ if (empty) return false;
224
+ const root = "root" in options ? options.root ?? null : queryRoot(options.rootSelector);
225
+ if (this.#session !== session) return false;
196
226
  const onEntries = (entries) => {
197
- if (this.#active && this.#observer === observer) this.#onEntries(entries);
227
+ if (this.#session === session && session.active) this.#onEntries(entries);
198
228
  };
229
+ let usingPlatformDefaults = false;
199
230
  try {
200
- observer = new IntersectionObserver(onEntries, {
231
+ const configured = {
201
232
  root,
202
233
  rootMargin: options.rootMargin,
203
234
  threshold: options.threshold
204
- });
235
+ };
236
+ if (this.#session !== session) return false;
237
+ observer = new IntersectionObserver(onEntries, configured);
205
238
  } catch (error) {
239
+ if (this.#session !== session) return false;
206
240
  console.warn(
207
241
  "Stimeo UI: IntersectionObserver could not be constructed with the configured options; retrying with platform defaults.",
208
242
  error
209
243
  );
244
+ if (this.#session !== session) return false;
210
245
  observer = new IntersectionObserver(onEntries, { root });
211
- this.#usingPlatformDefaults = true;
246
+ usingPlatformDefaults = true;
212
247
  }
213
- for (const target of list) observer.observe(target);
214
- this.#observer = observer;
215
- this.#active = true;
248
+ if (this.#session !== session) {
249
+ this.#release(session, observer);
250
+ return false;
251
+ }
252
+ session.observer = observer;
253
+ for (const target of list) {
254
+ if (this.#session !== session) return false;
255
+ observer.observe(target);
256
+ if (this.#session !== session) {
257
+ this.#release(session, observer);
258
+ return false;
259
+ }
260
+ }
261
+ if (this.#session !== session) return false;
262
+ session.usingPlatformDefaults = usingPlatformDefaults;
263
+ session.active = true;
216
264
  return true;
217
265
  } catch (error) {
218
- observer?.disconnect();
219
- this.#observer = null;
220
- this.#active = false;
221
- this.#usingPlatformDefaults = false;
266
+ this.#release(session, observer);
222
267
  throw error;
223
268
  }
224
269
  }
225
270
  rearm(target) {
226
- if (!this.#observer) return;
271
+ const session = this.#session;
272
+ const observer = session?.observer;
273
+ if (!session?.active || !observer) return;
227
274
  try {
228
- this.#observer.unobserve(target);
229
- this.#observer.observe(target);
275
+ observer.unobserve(target);
276
+ if (this.#session !== session) return;
277
+ observer.observe(target);
278
+ if (this.#session !== session) this.#release(session, observer);
230
279
  } catch (error) {
231
- this.stop();
280
+ if (this.#session === session) this.#session = null;
281
+ this.#release(session, observer);
232
282
  throw error;
233
283
  }
234
284
  }
235
285
  stop() {
236
- this.#active = false;
237
- this.#observer?.disconnect();
238
- this.#observer = null;
239
- this.#usingPlatformDefaults = false;
286
+ const session = this.#session;
287
+ this.#session = null;
288
+ if (session) this.#release(session);
289
+ }
290
+ #release(session, observer = session.observer) {
291
+ session.observer = null;
292
+ observer?.disconnect();
240
293
  }
241
294
  };
242
295
 
@@ -1,17 +1,19 @@
1
1
  import { Controller } from '@hotwired/stimulus';
2
2
 
3
+ var afterFocus = /* @__PURE__ */ Symbol.for("stimeo--announcer:after-focus");
3
4
  function announce(message, options = {}) {
4
5
  const text = message.trim();
5
6
  if (text.length === 0) return;
6
- window.dispatchEvent(
7
- new CustomEvent("stimeo--announcer:announce", {
8
- detail: { message: text, assertive: options.assertive === true }
9
- })
10
- );
7
+ const event = new CustomEvent("stimeo--announcer:announce", {
8
+ detail: { message: text, assertive: options.assertive === true }
9
+ });
10
+ if (options.afterFocus) event[afterFocus] = true;
11
+ window.dispatchEvent(event);
11
12
  }
12
13
 
13
14
  function setAttributeIfChanged(element, name, value, beforeWrite) {
14
15
  if (element.getAttribute(name) === value) return false;
16
+ beforeWrite?.();
15
17
  if (value === null) element.removeAttribute(name);
16
18
  else element.setAttribute(name, value);
17
19
  return true;
@@ -85,14 +87,34 @@ var AttributeLease = class {
85
87
  const names = registry.names;
86
88
  names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
87
89
  }
88
- write(element, value) {
90
+ write(element, value, beforeWrite) {
89
91
  const stack = attributeStack(element, this.#attribute);
90
92
  const hold = this.#take(stack) ?? this.#acquire(element, stack);
91
93
  this.#held.add(element);
92
94
  const shows = !this.#covered(element, stack, hold);
93
95
  hold.written = value;
94
96
  this.#mark(element, stack);
95
- 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;
96
118
  }
97
119
  return(element) {
98
120
  const held = this.#held.delete(element);
@@ -158,8 +180,8 @@ var AttributeLease = class {
158
180
  setAttributeIfChanged(element, name, recorded);
159
181
  }
160
182
  }
161
- #reflect(element, value) {
162
- setAttributeIfChanged(element, this.#attribute, value);
183
+ #reflect(element, value, beforeWrite) {
184
+ setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
163
185
  }
164
186
  };
165
187