stimeo-ui 0.16.0 → 0.18.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 (117) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +136 -0
  3. data/README.md +27 -11
  4. data/dist/cable/index.js +384 -449
  5. data/dist/controllers/accordion_controller.js +174 -55
  6. data/dist/controllers/alert_dialog_controller.js +903 -235
  7. data/dist/controllers/announcer_controller.js +238 -205
  8. data/dist/controllers/aspect_ratio_controller.js +0 -10
  9. data/dist/controllers/auto_submit_controller.js +414 -145
  10. data/dist/controllers/avatar_controller.js +185 -107
  11. data/dist/controllers/breadcrumb_controller.js +0 -130
  12. data/dist/controllers/bulk_select_controller.js +282 -58
  13. data/dist/controllers/calendar_controller.js +228 -260
  14. data/dist/controllers/carousel_controller.js +536 -436
  15. data/dist/controllers/character_counter_controller.js +493 -207
  16. data/dist/controllers/checkbox_controller.js +38 -74
  17. data/dist/controllers/clipboard_controller.js +261 -149
  18. data/dist/controllers/collapsible_controller.js +304 -120
  19. data/dist/controllers/color_picker_controller.js +178 -146
  20. data/dist/controllers/combobox_controller.js +522 -156
  21. data/dist/controllers/command_palette_controller.js +1156 -395
  22. data/dist/controllers/conditional_fields_controller.js +300 -171
  23. data/dist/controllers/confirm_controller.js +980 -262
  24. data/dist/controllers/context_menu_controller.js +346 -153
  25. data/dist/controllers/count_up_controller.js +73 -21
  26. data/dist/controllers/countdown_controller.js +281 -158
  27. data/dist/controllers/currency_input_controller.js +575 -225
  28. data/dist/controllers/data_grid_controller.js +248 -214
  29. data/dist/controllers/date_range_picker_controller.js +338 -235
  30. data/dist/controllers/dialog_controller.js +899 -237
  31. data/dist/controllers/direct_upload_controller.js +97 -167
  32. data/dist/controllers/dirty_form_controller.js +72 -69
  33. data/dist/controllers/dismissible_controller.js +196 -24
  34. data/dist/controllers/drawer_controller.js +974 -355
  35. data/dist/controllers/dropdown_controller.js +339 -96
  36. data/dist/controllers/editable_controller.js +315 -88
  37. data/dist/controllers/empty_state_controller.js +79 -58
  38. data/dist/controllers/file_dropzone_controller.js +322 -211
  39. data/dist/controllers/filter_controller.js +77 -42
  40. data/dist/controllers/flash_controller.js +238 -347
  41. data/dist/controllers/focus_controller.js +679 -240
  42. data/dist/controllers/form_field_controller.js +156 -132
  43. data/dist/controllers/form_validation_controller.js +31 -97
  44. data/dist/controllers/frame_loading_controller.js +275 -217
  45. data/dist/controllers/highlight_controller.js +107 -75
  46. data/dist/controllers/hover_card_controller.js +327 -130
  47. data/dist/controllers/idle_controller.js +271 -101
  48. data/dist/controllers/input_mask_controller.js +483 -97
  49. data/dist/controllers/intersection_controller.js +150 -106
  50. data/dist/controllers/lazy_frame_controller.js +24 -68
  51. data/dist/controllers/listbox_controller.js +523 -240
  52. data/dist/controllers/local_time_controller.js +102 -77
  53. data/dist/controllers/masonry_controller.js +80 -96
  54. data/dist/controllers/menu_controller.js +302 -188
  55. data/dist/controllers/menubar_controller.js +232 -345
  56. data/dist/controllers/meter_controller.js +417 -87
  57. data/dist/controllers/multi_select_controller.js +785 -393
  58. data/dist/controllers/navigation_menu_controller.js +190 -250
  59. data/dist/controllers/nested_form_controller.js +396 -192
  60. data/dist/controllers/network_status_controller.js +268 -62
  61. data/dist/controllers/number_input_controller.js +610 -303
  62. data/dist/controllers/optimistic_controller.js +45 -87
  63. data/dist/controllers/otp_controller.js +658 -255
  64. data/dist/controllers/overflow_indicator_controller.js +122 -113
  65. data/dist/controllers/overflow_menu_controller.js +470 -295
  66. data/dist/controllers/pagination_controller.js +332 -123
  67. data/dist/controllers/password_reveal_controller.js +392 -121
  68. data/dist/controllers/password_strength_controller.js +111 -158
  69. data/dist/controllers/persist_controller.js +165 -111
  70. data/dist/controllers/pointer_drag_controller.js +434 -188
  71. data/dist/controllers/popover_controller.js +269 -113
  72. data/dist/controllers/portal_controller.js +215 -76
  73. data/dist/controllers/preview_guard_controller.js +243 -116
  74. data/dist/controllers/progress_controller.js +391 -78
  75. data/dist/controllers/radio_group_controller.js +278 -211
  76. data/dist/controllers/range_slider_controller.js +220 -113
  77. data/dist/controllers/rating_controller.js +458 -211
  78. data/dist/controllers/read_more_controller.js +138 -63
  79. data/dist/controllers/reading_progress_controller.js +166 -137
  80. data/dist/controllers/relative_time_controller.js +211 -112
  81. data/dist/controllers/{reset_before_cache_controller.js → reset_on_restore_controller.js} +103 -38
  82. data/dist/controllers/resizable_controller.js +299 -150
  83. data/dist/controllers/roving_controller.js +49 -88
  84. data/dist/controllers/scroll_area_controller.js +490 -246
  85. data/dist/controllers/scroll_restore_controller.js +14 -55
  86. data/dist/controllers/scroll_visibility_controller.js +432 -149
  87. data/dist/controllers/scrollspy_controller.js +193 -248
  88. data/dist/controllers/separator_controller.js +285 -142
  89. data/dist/controllers/sidebar_controller.js +1069 -404
  90. data/dist/controllers/skeleton_controller.js +259 -101
  91. data/dist/controllers/slider_controller.js +187 -86
  92. data/dist/controllers/smart_sticky_header_controller.js +173 -66
  93. data/dist/controllers/sortable_controller.js +26 -125
  94. data/dist/controllers/spinner_controller.js +288 -173
  95. data/dist/controllers/step_indicator_controller.js +105 -46
  96. data/dist/controllers/stepper_controller.js +120 -73
  97. data/dist/controllers/stick_to_bottom_controller.js +275 -140
  98. data/dist/controllers/sticky_observer_controller.js +220 -49
  99. data/dist/controllers/submit_once_controller.js +376 -227
  100. data/dist/controllers/switch_controller.js +201 -84
  101. data/dist/controllers/tabs_controller.js +41 -30
  102. data/dist/controllers/tags_input_controller.js +293 -173
  103. data/dist/controllers/textarea_autosize_controller.js +108 -74
  104. data/dist/controllers/theme_controller.js +140 -116
  105. data/dist/controllers/time_picker_controller.js +331 -127
  106. data/dist/controllers/toast_controller.js +244 -324
  107. data/dist/controllers/toggle_group_controller.js +252 -191
  108. data/dist/controllers/toolbar_controller.js +219 -120
  109. data/dist/controllers/tooltip_controller.js +158 -124
  110. data/dist/controllers/transition_controller.js +123 -119
  111. data/dist/controllers/tree_view_controller.js +283 -369
  112. data/dist/index.js +8573 -10410
  113. data/dist/positioning/index.js +154 -47
  114. data/lib/generators/stimeo/install/install_generator.rb +7 -2
  115. data/lib/generators/stimeo/install/templates/stimeo.js +19 -6
  116. data/lib/stimeo/ui/version.rb +1 -1
  117. metadata +3 -3
@@ -1,15 +1,109 @@
1
1
  import { Controller } from '@hotwired/stimulus';
2
2
 
3
- // src/controllers/switch_controller.ts
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
+ var AuthoredMutationWatcher = class {
12
+ #onAuthored;
13
+ #claims = null;
14
+ #observer = null;
15
+ constructor(onAuthored) {
16
+ this.#onAuthored = onAuthored;
17
+ }
18
+ observe(root, options) {
19
+ this.disconnect();
20
+ const observer = new MutationObserver((records) => {
21
+ if (this.#observer !== observer) return;
22
+ const authored = this.#filter(records);
23
+ if (authored.length > 0) this.#onAuthored(authored);
24
+ });
25
+ this.#observer = observer;
26
+ this.#claims = { attributes: /* @__PURE__ */ new Map(), children: /* @__PURE__ */ new Map() };
27
+ observer.observe(root, {
28
+ attributes: true,
29
+ attributeFilter: [...options.attributes],
30
+ subtree: options.subtree ?? false,
31
+ childList: options.childList ?? false
32
+ });
33
+ if (options.ancestorAttributes) {
34
+ let ancestor = root.parentElement;
35
+ while (ancestor) {
36
+ observer.observe(ancestor, {
37
+ attributes: true,
38
+ attributeFilter: [...options.ancestorAttributes]
39
+ });
40
+ ancestor = ancestor.parentElement;
41
+ }
42
+ }
43
+ }
44
+ claim(target, name, value) {
45
+ const claims = this.#claims?.attributes;
46
+ let attributes = claims?.get(target);
47
+ if (!attributes) {
48
+ attributes = /* @__PURE__ */ new Map();
49
+ claims?.set(target, attributes);
50
+ }
51
+ const pending = attributes.get(name);
52
+ attributes.set(name, { value, count: (pending?.count ?? 0) + 1 });
53
+ }
54
+ claimCurrent(target, name) {
55
+ this.claim(target, name, target.getAttribute(name));
56
+ }
57
+ claimChildList(target, added, removed) {
58
+ const claims = this.#claims?.children;
59
+ const pending = claims?.get(target) ?? { added: /* @__PURE__ */ new Map(), removed: /* @__PURE__ */ new Map() };
60
+ for (const node of added) pending.added.set(node, (pending.added.get(node) ?? 0) + 1);
61
+ for (const node of removed) pending.removed.set(node, (pending.removed.get(node) ?? 0) + 1);
62
+ claims?.set(target, pending);
63
+ }
64
+ take() {
65
+ return this.#filter(this.#observer?.takeRecords() ?? []);
66
+ }
67
+ disconnect() {
68
+ this.#observer?.disconnect();
69
+ this.#observer = null;
70
+ this.#claims = null;
71
+ }
72
+ #filter(records) {
73
+ const authored = records.filter((record) => !this.#consume(record));
74
+ this.#claims?.attributes.clear();
75
+ this.#claims?.children.clear();
76
+ return authored;
77
+ }
78
+ #consume(record) {
79
+ if (record.type === "attributes") {
80
+ const target = record.target;
81
+ const pending2 = this.#claims?.attributes.get(target)?.get(record.attributeName);
82
+ if (!pending2 || pending2.count === 0 || target.getAttribute(record.attributeName) !== pending2.value) {
83
+ return false;
84
+ }
85
+ pending2.count -= 1;
86
+ return true;
87
+ }
88
+ const pending = this.#claims?.children.get(record.target);
89
+ if (!pending) return false;
90
+ const added = [...record.addedNodes];
91
+ const removed = [...record.removedNodes];
92
+ if (added.some((node) => !pending.added.get(node)) || removed.some((node) => !pending.removed.get(node))) {
93
+ return false;
94
+ }
95
+ for (const node of added) pending.added.set(node, (pending.added.get(node) ?? 0) - 1);
96
+ for (const node of removed) pending.removed.set(node, (pending.removed.get(node) ?? 0) - 1);
97
+ return true;
98
+ }
99
+ };
4
100
 
5
- // src/utils/default_attribute.ts
6
101
  function setDefaultAttribute(element, name, value) {
7
102
  if (element.hasAttribute(name)) return false;
8
103
  element.setAttribute(name, value);
9
104
  return true;
10
105
  }
11
106
 
12
- // src/utils/field_mirror.ts
13
107
  function writeField(field, value) {
14
108
  if (field.value === value) return false;
15
109
  field.value = value;
@@ -19,7 +113,6 @@ function commitField(target) {
19
113
  target.dispatchEvent(new Event("change", { bubbles: true }));
20
114
  }
21
115
 
22
- // src/utils/focus_candidate.ts
23
116
  function inheritsFieldsetDisabled(control) {
24
117
  let fieldset = control.closest("fieldset[disabled]");
25
118
  while (fieldset) {
@@ -30,7 +123,6 @@ function inheritsFieldsetDisabled(control) {
30
123
  return false;
31
124
  }
32
125
 
33
- // src/utils/interactive_host.ts
34
126
  var INTERACTIVE_HOST_SELECTOR = "button, input, select, textarea, label, a[href], area[href], summary, details, audio[controls], video[controls], iframe, object, embed";
35
127
  function isInteractiveHost(element) {
36
128
  if (element.matches(INTERACTIVE_HOST_SELECTOR)) return true;
@@ -47,27 +139,36 @@ function isInteractiveHost(element) {
47
139
  return false;
48
140
  }
49
141
 
50
- // src/utils/microtask_coalescer.ts
142
+ var ListenerSet = class {
143
+ #abort = new AbortController();
144
+ add(target, type, handler, options) {
145
+ target.addEventListener(type, handler, { ...options, signal: this.#abort.signal });
146
+ }
147
+ dispose() {
148
+ this.#abort.abort();
149
+ this.#abort = new AbortController();
150
+ }
151
+ };
152
+
51
153
  var MicrotaskCoalescer = class {
52
154
  #run;
53
155
  #queued = false;
54
156
  #active = false;
55
157
  #generation = 0;
56
- /** @param run - the single reconciliation pass, invoked at most once per batch. */
57
158
  constructor(run) {
58
159
  this.#run = run;
59
160
  }
60
- /** Opens the window in which {@link schedule} is honoured; call from `connect()`. */
61
161
  activate() {
62
162
  this.#active = true;
63
163
  }
64
- /** Closes the window and drops any pending pass; call from `disconnect()`. */
65
164
  cancel() {
66
165
  this.#active = false;
67
166
  this.#queued = false;
68
167
  this.#generation += 1;
69
168
  }
70
- /** Requests one pass after the batch settles. Idempotent; inert outside the window. */
169
+ get pending() {
170
+ return this.#queued;
171
+ }
71
172
  schedule() {
72
173
  if (!this.#active || this.#queued) return;
73
174
  this.#queued = true;
@@ -80,7 +181,45 @@ var MicrotaskCoalescer = class {
80
181
  }
81
182
  };
82
183
 
83
- // src/controllers/switch_controller.ts
184
+ var MorphRenderWatcher = class {
185
+ #listeners = new ListenerSet();
186
+ #pass;
187
+ #element = null;
188
+ #onMorph = () => this.#pass.schedule();
189
+ constructor(run) {
190
+ this.#pass = new MicrotaskCoalescer(run);
191
+ }
192
+ observe(element) {
193
+ if (this.#element === element) return;
194
+ this.disconnect();
195
+ this.#element = element;
196
+ this.#pass.activate();
197
+ this.#listeners.add(element, "turbo:morph-element", this.#onMorph);
198
+ }
199
+ schedule() {
200
+ this.#pass.schedule();
201
+ }
202
+ get pending() {
203
+ return this.#pass.pending;
204
+ }
205
+ disconnect() {
206
+ this.#listeners.dispose();
207
+ this.#pass.cancel();
208
+ this.#element = null;
209
+ }
210
+ };
211
+
212
+ var MoveCounter = class {
213
+ #sequence = 0;
214
+ record() {
215
+ this.#sequence += 1;
216
+ return this.#sequence;
217
+ }
218
+ isLatest(token) {
219
+ return token === this.#sequence;
220
+ }
221
+ };
222
+
84
223
  var OBSERVED_ATTRIBUTES = [
85
224
  "role",
86
225
  "aria-checked",
@@ -92,61 +231,49 @@ var OBSERVED_ATTRIBUTES = [
92
231
  ];
93
232
  var OBSERVED_ANCESTOR_ATTRIBUTES = ["contenteditable"];
94
233
  var SwitchController = class extends Controller {
234
+ #moves = new MoveCounter();
235
+ #connectionGeneration = 0;
95
236
  static targets = ["field"];
96
237
  static actions = ["onKeydown", "toggle"];
97
238
  static events = ["change", "reconcile"];
98
- /** Defaults this instance introduced and may therefore remove safely. */
99
- #ownedDefaults = /* @__PURE__ */ new Set();
100
- /** Controller writes that must not be mistaken for authored morph changes. */
101
- #internalAttributeValues = /* @__PURE__ */ new Map();
102
- /** One pass per batch of retained-element changes and field arrivals. */
103
- #pass = new MicrotaskCoalescer(() => this.#reconcile());
104
- /** The checked state last published: read on connect, then committed or reported. */
239
+ #ownedDefaults = /* @__PURE__ */ new Map();
240
+ #pass = new MorphRenderWatcher(() => this.#reconcile());
105
241
  #committedChecked = false;
106
- #attributeObserver = new MutationObserver((records) => {
242
+ #attributeObserver = new AuthoredMutationWatcher((records) => {
107
243
  this.#releaseAuthoredDefaults(records);
108
244
  this.#pass.schedule();
109
245
  });
110
- /** Blocks disabled pointer/native-key activation before consumer click handlers. */
111
246
  #onClickCapture = (event) => {
112
247
  if (!this.#isSupportedHost || !this.#isActivationDisabled) return;
113
248
  event.preventDefault();
114
249
  event.stopImmediatePropagation();
115
250
  };
116
- /**
117
- * Ensures the switch exposes a role and is keyboard-reachable, and takes the
118
- * state it finds as the one a later move is measured from, reporting nothing.
119
- */
251
+ #listeners = new ListenerSet();
120
252
  connect() {
253
+ this.#releaseDefaultsRewrittenWhileAway();
121
254
  this.#reconcileDefaults();
122
255
  this.#mirrorField(false);
123
256
  this.#committedChecked = this.#checked;
124
- this.element.addEventListener("click", this.#onClickCapture, true);
125
- this.#pass.activate();
257
+ this.#listeners.add(this.element, "click", this.#onClickCapture, { capture: true });
258
+ this.#pass.observe(this.element);
126
259
  this.#observeAttributes();
127
260
  }
128
- /** Fills a form field inserted or replaced at runtime with the current state. */
129
261
  fieldTargetConnected() {
130
262
  this.#pass.schedule();
131
263
  }
132
- /** Releases the click guard, the attribute observer, and a pass still queued. */
264
+ fieldTargetDisconnected() {
265
+ this.#pass.schedule();
266
+ }
133
267
  disconnect() {
134
- this.#pass.cancel();
135
- this.element.removeEventListener("click", this.#onClickCapture, true);
268
+ this.#connectionGeneration += 1;
269
+ this.#pass.disconnect();
270
+ this.#listeners.dispose();
136
271
  this.#attributeObserver.disconnect();
137
- this.#internalAttributeValues.clear();
138
272
  }
139
- /** Toggles the checked state. Bound via `data-action` (click). */
140
273
  toggle() {
141
274
  if (!this.#isSupportedHost || this.#isActivationDisabled) return;
142
275
  this.#commit(!this.#checked);
143
276
  }
144
- /**
145
- * Activates the switch on Space/Enter for non-native hosts and suppresses key
146
- * repeat. Bound via `data-action` (keydown). A native `<button type="button">`
147
- * owns the initial key-to-click synthesis; repeated keydowns are canceled before
148
- * the browser can synthesize additional clicks.
149
- */
150
277
  onKeydown(event) {
151
278
  if (event.defaultPrevented) return;
152
279
  if (!this.#isSupportedHost) return;
@@ -164,29 +291,21 @@ var SwitchController = class extends Controller {
164
291
  if (event.repeat) return;
165
292
  this.toggle();
166
293
  }
167
- /**
168
- * Re-derives the defaults and the field after the page changed the host, then
169
- * reports a checked state that moved. Records still queued are read first, so
170
- * an author's write is not lost when observation is suspended for this pass's
171
- * own writes; observation resumes before the report, so an edit a listener
172
- * makes is seen by the next pass.
173
- */
174
294
  #reconcile() {
175
- this.#releaseAuthoredDefaults(this.#attributeObserver.takeRecords());
176
- this.#attributeObserver.disconnect();
295
+ this.#releaseAuthoredDefaults(this.#attributeObserver.take());
177
296
  this.#reconcileDefaults();
178
297
  this.#mirrorField(false);
179
- this.#observeAttributes();
298
+ const authored = this.#attributeObserver.take();
299
+ this.#releaseAuthoredDefaults(authored);
300
+ if (authored.length > 0) this.#pass.schedule();
180
301
  this.#reportMove();
181
302
  }
182
- /** Reports a checked state that moved since the one this switch last published. */
183
303
  #reportMove() {
184
304
  const checked = this.#checked;
185
305
  if (checked === this.#committedChecked) return;
186
306
  this.#committedChecked = checked;
187
307
  this.dispatch("reconcile", { detail: { checked } });
188
308
  }
189
- /** Re-adds only missing defaults, preserving every authored attribute value. */
190
309
  #reconcileDefaults() {
191
310
  if (!this.#isSupportedHost) {
192
311
  this.#removeOwnedDefaults();
@@ -198,61 +317,50 @@ var SwitchController = class extends Controller {
198
317
  this.#setOwnedDefault("tabindex", "0");
199
318
  }
200
319
  }
201
- /** Mirrors the checked state into the optional form field. */
202
320
  #mirrorField(notify) {
203
321
  if (!this.hasFieldTarget) return;
204
322
  const moved = writeField(this.fieldTarget, this.#checked ? "true" : "false");
205
323
  if (moved && notify) commitField(this.fieldTarget);
206
324
  }
207
- /** Records a newly introduced default without claiming authored markup. */
208
325
  #setOwnedDefault(name, value) {
209
- if (setDefaultAttribute(this.element, name, value)) this.#ownedDefaults.add(name);
326
+ if (setDefaultAttribute(this.element, name, value)) {
327
+ this.#ownedDefaults.set(name, value);
328
+ this.#attributeObserver.claimCurrent(this.element, name);
329
+ }
330
+ }
331
+ #releaseDefaultsRewrittenWhileAway() {
332
+ for (const [name, written] of this.#ownedDefaults) {
333
+ const value = this.element.getAttribute(name);
334
+ if (value !== null && value !== written) this.#ownedDefaults.delete(name);
335
+ }
210
336
  }
211
- /**
212
- * Gives ownership back when a retained-element morph authors a value. Missing
213
- * owned attributes stay owned so reconciliation can restore them.
214
- */
215
337
  #releaseAuthoredDefaults(records) {
216
338
  for (const record of records) {
217
339
  if (record.target === this.element) {
218
340
  const name = record.attributeName;
219
341
  if (name && this.#ownedDefaults.has(name)) {
220
342
  const value = this.element.getAttribute(name);
221
- if (value !== null && this.#internalAttributeValues.get(name) !== value) {
343
+ if (value !== null) {
222
344
  this.#ownedDefaults.delete(name);
223
345
  }
224
346
  }
225
347
  }
226
348
  }
227
- this.#internalAttributeValues.clear();
228
349
  }
229
- /** Removes only defaults introduced by this instance when a host becomes invalid. */
230
350
  #removeOwnedDefaults() {
231
- for (const name of this.#ownedDefaults) this.element.removeAttribute(name);
351
+ for (const name of this.#ownedDefaults.keys()) this.#writeAttribute(name, null);
232
352
  this.#ownedDefaults.clear();
233
- this.#internalAttributeValues.clear();
234
353
  }
235
- /** Watches retained host attributes that Turbo can morph without reconnecting. */
236
354
  #observeAttributes() {
237
355
  this.#attributeObserver.observe(this.element, {
238
- attributes: true,
239
- attributeFilter: OBSERVED_ATTRIBUTES
356
+ attributes: OBSERVED_ATTRIBUTES,
357
+ ancestorAttributes: OBSERVED_ANCESTOR_ATTRIBUTES
240
358
  });
241
- let ancestor = this.element.parentElement;
242
- while (ancestor) {
243
- this.#attributeObserver.observe(ancestor, {
244
- attributes: true,
245
- attributeFilter: OBSERVED_ANCESTOR_ATTRIBUTES
246
- });
247
- ancestor = ancestor.parentElement;
248
- }
249
359
  }
250
- /** Whether the host has one activation model that this controller can own. */
251
360
  get #isSupportedHost() {
252
361
  if (this.element instanceof HTMLButtonElement) return this.element.type === "button";
253
362
  return !isInteractiveHost(this.element);
254
363
  }
255
- /** Whether ARIA or native HTML semantics make the supported switch inoperable. */
256
364
  get #isActivationDisabled() {
257
365
  let current = this.element;
258
366
  while (current) {
@@ -262,25 +370,34 @@ var SwitchController = class extends Controller {
262
370
  if (!(this.element instanceof HTMLButtonElement)) return false;
263
371
  return this.element.disabled || inheritsFieldsetDisabled(this.element);
264
372
  }
265
- /** Whether the switch is currently on. */
266
373
  get #checked() {
267
374
  return this.element.getAttribute("aria-checked") === "true";
268
375
  }
269
- /**
270
- * Applies one toggle the user made. The state is taken as published before
271
- * either report goes out, so a listener that toggles again or writes the
272
- * attribute is measured from it.
273
- */
274
376
  #commit(value) {
377
+ const generation = this.#connectionGeneration;
275
378
  const reflected = value ? "true" : "false";
276
- this.#internalAttributeValues.set("aria-checked", reflected);
277
- this.element.setAttribute("aria-checked", reflected);
379
+ const authored = this.#attributeObserver.take();
380
+ this.#releaseAuthoredDefaults(authored);
381
+ if (authored.length > 0) this.#pass.schedule();
382
+ if (this.#ownedDefaults.has("aria-checked")) this.#ownedDefaults.set("aria-checked", reflected);
383
+ this.#writeAttribute("aria-checked", reflected);
384
+ const changed = value !== this.#committedChecked;
278
385
  this.#committedChecked = value;
386
+ if (!changed) {
387
+ this.#mirrorField(false);
388
+ return;
389
+ }
390
+ const token = this.#moves.record();
279
391
  this.#mirrorField(true);
392
+ if (generation !== this.#connectionGeneration || !this.#moves.isLatest(token)) return;
280
393
  this.dispatch("change", { detail: { checked: value } });
281
394
  }
395
+ #writeAttribute(name, value) {
396
+ setAttributeIfChanged(this.element, name, value, () => {
397
+ this.#attributeObserver.claim(this.element, name, value);
398
+ });
399
+ }
282
400
  };
283
401
 
284
402
  export { SwitchController };
285
- //# sourceMappingURL=switch_controller.js.map
286
403
  //# sourceMappingURL=switch_controller.js.map
@@ -1,33 +1,48 @@
1
1
  import { Controller } from '@hotwired/stimulus';
2
2
 
3
- // src/controllers/tabs_controller.ts
3
+ var FOCUS_EVENTS = /* @__PURE__ */ new Set(["blur", "focus", "focusin", "focusout"]);
4
+ var POINTER_EVENTS = /* @__PURE__ */ new Set(["mouseenter", "mouseleave", "pointerenter", "pointerleave"]);
5
+ function stateReasonFor(event) {
6
+ if (!event) return "api";
7
+ if (FOCUS_EVENTS.has(event.type)) return "focus";
8
+ if (POINTER_EVENTS.has(event.type)) return "pointer";
9
+ return "user";
10
+ }
11
+
12
+ function actionSource(source) {
13
+ if (source instanceof HTMLElement) {
14
+ return { event: null, host: source, origin: source, reason: "api" };
15
+ }
16
+ const event = source ?? null;
17
+ return {
18
+ event,
19
+ host: event?.currentTarget instanceof Element ? event.currentTarget : null,
20
+ origin: event?.target instanceof Element ? event.target : null,
21
+ reason: stateReasonFor(event)
22
+ };
23
+ }
4
24
 
5
- // src/utils/logical_scroll.ts
6
25
  function isRtl(element) {
7
26
  return window.getComputedStyle(element).direction === "rtl";
8
27
  }
9
28
 
10
- // src/utils/arrow_step.ts
11
29
  function isReservedArrowChord(event, allow = []) {
12
30
  if (!event.key.startsWith("Arrow")) return false;
13
31
  return event.altKey && !allow.includes("alt") || event.ctrlKey && !allow.includes("ctrl") || event.metaKey && !allow.includes("meta") || event.shiftKey && !allow.includes("shift");
14
32
  }
33
+ function hasModifierChord(event) {
34
+ return event.altKey || event.ctrlKey || event.metaKey || event.shiftKey;
35
+ }
36
+
37
+ function targetSelector(identifier, name) {
38
+ return `[data-${identifier}-target~="${name}"]`;
39
+ }
15
40
 
16
- // src/controllers/tabs_controller.ts
17
41
  var TabsController = class extends Controller {
18
42
  static targets = ["tab", "panel", "list"];
19
43
  static actions = ["onKeydown", "select"];
20
44
  static events = ["change"];
21
- /** Whether selection moves are reported: set once `connect()` settled the baseline. */
22
45
  #reporting = false;
23
- /**
24
- * Selects the initially active tab: the pre-selected one, else the first.
25
- *
26
- * `findIndex` makes this first-wins when the author marked several — the first
27
- * in DOM order is the only deterministic reading of "which one did they mean" —
28
- * and `#selectIndex` then writes an explicit value onto every tab, so a
29
- * forgotten `aria-selected` cannot leave a tab looking unselectable.
30
- */
31
46
  connect() {
32
47
  const preselected = this.tabTargets.findIndex(
33
48
  (tab) => tab.getAttribute("aria-selected") === "true"
@@ -35,27 +50,28 @@ var TabsController = class extends Controller {
35
50
  this.#selectIndex(preselected === -1 ? 0 : preselected, { focus: false });
36
51
  this.#reporting = true;
37
52
  }
38
- /**
39
- * Stops reporting until the next `connect()` has settled its baseline, so that
40
- * normalization stays silent.
41
- */
42
53
  disconnect() {
43
54
  this.#reporting = false;
44
55
  }
45
- /** Selects the clicked tab. Bound via `data-action` (click). */
46
- select(event) {
47
- const index = this.tabTargets.indexOf(event.currentTarget);
48
- if (index !== -1) this.#selectIndex(index, { focus: false });
56
+ select(source) {
57
+ const { host, origin, reason } = actionSource(source);
58
+ const tab = host?.closest(targetSelector(this.identifier, "tab"));
59
+ if (!tab || !this.tabTargets.includes(tab)) return;
60
+ if (origin && origin.closest(`[data-controller~="${this.identifier}"]`) !== this.element)
61
+ return;
62
+ const index = this.tabTargets.indexOf(tab);
63
+ this.#selectIndex(index, { focus: false }, reason);
49
64
  }
50
- /** Implements arrow/Home/End navigation with automatic activation. */
51
65
  onKeydown(event) {
52
66
  if (event.defaultPrevented) return;
53
67
  if (isReservedArrowChord(event)) return;
68
+ if ((event.key === "Home" || event.key === "End") && hasModifierChord(event)) return;
54
69
  const tabs = this.tabTargets;
55
70
  const currentIndex = tabs.indexOf(event.currentTarget);
56
71
  if (currentIndex === -1) return;
57
72
  let nextIndex = null;
58
- const step = isRtl(this.element) ? -1 : 1;
73
+ const directionElement = this.hasListTarget ? this.listTarget : this.element;
74
+ const step = isRtl(directionElement) ? -1 : 1;
59
75
  switch (event.key) {
60
76
  case "ArrowRight":
61
77
  nextIndex = (currentIndex + step + tabs.length) % tabs.length;
@@ -75,11 +91,7 @@ var TabsController = class extends Controller {
75
91
  event.preventDefault();
76
92
  this.#selectIndex(nextIndex, { focus: true });
77
93
  }
78
- /**
79
- * Activates the tab/panel pair at `index`: updates `aria-selected`, the roving
80
- * `tabindex`, and panel visibility. Optionally moves focus to the new tab.
81
- */
82
- #selectIndex(index, { focus }) {
94
+ #selectIndex(index, { focus }, reason = "user") {
83
95
  const tabs = this.tabTargets;
84
96
  const previous = tabs.findIndex((tab) => tab.getAttribute("aria-selected") === "true");
85
97
  tabs.forEach((tab, i) => {
@@ -92,7 +104,7 @@ var TabsController = class extends Controller {
92
104
  });
93
105
  if (previous !== index && this.#reporting) {
94
106
  this.dispatch("change", {
95
- detail: { index, total: tabs.length, previous },
107
+ detail: { index, total: tabs.length, previous, reason },
96
108
  cancelable: false
97
109
  });
98
110
  }
@@ -101,5 +113,4 @@ var TabsController = class extends Controller {
101
113
  };
102
114
 
103
115
  export { TabsController };
104
- //# sourceMappingURL=tabs_controller.js.map
105
116
  //# sourceMappingURL=tabs_controller.js.map