stimeo-ui 0.16.0 → 0.17.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 (115) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +31 -0
  3. data/README.md +8 -1
  4. data/dist/cable/index.js +363 -436
  5. data/dist/controllers/accordion_controller.js +166 -55
  6. data/dist/controllers/alert_dialog_controller.js +862 -221
  7. data/dist/controllers/announcer_controller.js +135 -198
  8. data/dist/controllers/aspect_ratio_controller.js +0 -10
  9. data/dist/controllers/auto_submit_controller.js +271 -127
  10. data/dist/controllers/avatar_controller.js +171 -105
  11. data/dist/controllers/breadcrumb_controller.js +0 -130
  12. data/dist/controllers/bulk_select_controller.js +262 -52
  13. data/dist/controllers/calendar_controller.js +175 -209
  14. data/dist/controllers/carousel_controller.js +461 -399
  15. data/dist/controllers/character_counter_controller.js +246 -156
  16. data/dist/controllers/checkbox_controller.js +32 -74
  17. data/dist/controllers/clipboard_controller.js +168 -147
  18. data/dist/controllers/collapsible_controller.js +301 -120
  19. data/dist/controllers/color_picker_controller.js +149 -139
  20. data/dist/controllers/combobox_controller.js +360 -133
  21. data/dist/controllers/command_palette_controller.js +970 -358
  22. data/dist/controllers/conditional_fields_controller.js +166 -124
  23. data/dist/controllers/confirm_controller.js +939 -248
  24. data/dist/controllers/context_menu_controller.js +256 -128
  25. data/dist/controllers/count_up_controller.js +73 -21
  26. data/dist/controllers/countdown_controller.js +183 -148
  27. data/dist/controllers/currency_input_controller.js +134 -158
  28. data/dist/controllers/data_grid_controller.js +114 -186
  29. data/dist/controllers/date_range_picker_controller.js +288 -206
  30. data/dist/controllers/dialog_controller.js +858 -223
  31. data/dist/controllers/direct_upload_controller.js +73 -153
  32. data/dist/controllers/dirty_form_controller.js +14 -48
  33. data/dist/controllers/dismissible_controller.js +175 -21
  34. data/dist/controllers/drawer_controller.js +933 -341
  35. data/dist/controllers/dropdown_controller.js +312 -82
  36. data/dist/controllers/editable_controller.js +158 -68
  37. data/dist/controllers/empty_state_controller.js +67 -53
  38. data/dist/controllers/file_dropzone_controller.js +311 -207
  39. data/dist/controllers/filter_controller.js +67 -39
  40. data/dist/controllers/flash_controller.js +172 -314
  41. data/dist/controllers/focus_controller.js +654 -240
  42. data/dist/controllers/form_field_controller.js +147 -132
  43. data/dist/controllers/form_validation_controller.js +13 -86
  44. data/dist/controllers/frame_loading_controller.js +264 -213
  45. data/dist/controllers/highlight_controller.js +107 -75
  46. data/dist/controllers/hover_card_controller.js +309 -118
  47. data/dist/controllers/idle_controller.js +267 -101
  48. data/dist/controllers/input_mask_controller.js +71 -72
  49. data/dist/controllers/intersection_controller.js +147 -106
  50. data/dist/controllers/lazy_frame_controller.js +9 -65
  51. data/dist/controllers/listbox_controller.js +306 -204
  52. data/dist/controllers/local_time_controller.js +54 -64
  53. data/dist/controllers/masonry_controller.js +70 -93
  54. data/dist/controllers/menu_controller.js +214 -156
  55. data/dist/controllers/menubar_controller.js +170 -329
  56. data/dist/controllers/meter_controller.js +151 -67
  57. data/dist/controllers/multi_select_controller.js +593 -358
  58. data/dist/controllers/navigation_menu_controller.js +124 -232
  59. data/dist/controllers/nested_form_controller.js +352 -182
  60. data/dist/controllers/network_status_controller.js +242 -54
  61. data/dist/controllers/number_input_controller.js +320 -263
  62. data/dist/controllers/optimistic_controller.js +16 -76
  63. data/dist/controllers/otp_controller.js +198 -193
  64. data/dist/controllers/overflow_indicator_controller.js +116 -113
  65. data/dist/controllers/overflow_menu_controller.js +343 -283
  66. data/dist/controllers/pagination_controller.js +295 -119
  67. data/dist/controllers/password_reveal_controller.js +389 -121
  68. data/dist/controllers/password_strength_controller.js +99 -153
  69. data/dist/controllers/persist_controller.js +237 -103
  70. data/dist/controllers/pointer_drag_controller.js +185 -165
  71. data/dist/controllers/popover_controller.js +236 -97
  72. data/dist/controllers/portal_controller.js +209 -76
  73. data/dist/controllers/preview_guard_controller.js +232 -116
  74. data/dist/controllers/progress_controller.js +125 -56
  75. data/dist/controllers/radio_group_controller.js +117 -137
  76. data/dist/controllers/range_slider_controller.js +192 -105
  77. data/dist/controllers/rating_controller.js +418 -207
  78. data/dist/controllers/read_more_controller.js +134 -63
  79. data/dist/controllers/reading_progress_controller.js +147 -135
  80. data/dist/controllers/relative_time_controller.js +145 -110
  81. data/dist/controllers/{reset_before_cache_controller.js → reset_on_restore_controller.js} +97 -38
  82. data/dist/controllers/resizable_controller.js +255 -139
  83. data/dist/controllers/roving_controller.js +39 -84
  84. data/dist/controllers/scroll_area_controller.js +428 -225
  85. data/dist/controllers/scroll_restore_controller.js +0 -53
  86. data/dist/controllers/scroll_visibility_controller.js +395 -145
  87. data/dist/controllers/scrollspy_controller.js +181 -242
  88. data/dist/controllers/separator_controller.js +267 -140
  89. data/dist/controllers/sidebar_controller.js +1023 -386
  90. data/dist/controllers/skeleton_controller.js +248 -97
  91. data/dist/controllers/slider_controller.js +159 -79
  92. data/dist/controllers/smart_sticky_header_controller.js +162 -63
  93. data/dist/controllers/sortable_controller.js +0 -112
  94. data/dist/controllers/spinner_controller.js +277 -169
  95. data/dist/controllers/step_indicator_controller.js +99 -46
  96. data/dist/controllers/stepper_controller.js +114 -73
  97. data/dist/controllers/stick_to_bottom_controller.js +262 -138
  98. data/dist/controllers/sticky_observer_controller.js +214 -49
  99. data/dist/controllers/submit_once_controller.js +294 -205
  100. data/dist/controllers/switch_controller.js +33 -60
  101. data/dist/controllers/tabs_controller.js +35 -29
  102. data/dist/controllers/tags_input_controller.js +136 -145
  103. data/dist/controllers/textarea_autosize_controller.js +71 -58
  104. data/dist/controllers/theme_controller.js +130 -112
  105. data/dist/controllers/time_picker_controller.js +146 -80
  106. data/dist/controllers/toast_controller.js +186 -297
  107. data/dist/controllers/toggle_group_controller.js +95 -136
  108. data/dist/controllers/toolbar_controller.js +68 -98
  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 +150 -345
  112. data/dist/index.js +6370 -9346
  113. data/dist/positioning/index.js +148 -47
  114. data/lib/stimeo/ui/version.rb +1 -1
  115. metadata +3 -3
@@ -1,30 +1,20 @@
1
1
  import { Controller } from '@hotwired/stimulus';
2
2
 
3
- // src/controllers/breadcrumb_controller.ts
4
-
5
- // src/utils/blur_deferral.ts
6
3
  var BlurDeferral = class {
7
- /** Elements currently holding an update back, mapped to their `blur` listener. */
8
4
  #pending = /* @__PURE__ */ new Map();
9
- /** Called after a pending element blurs and has been detached. */
10
5
  #onRelease;
11
- /** @param onRelease - Invoked once `element` actually blurs; never on `release`. */
12
6
  constructor(onRelease) {
13
7
  this.#onRelease = onRelease;
14
8
  }
15
- /** Number of elements currently holding an update back. */
16
9
  get size() {
17
10
  return this.#pending.size;
18
11
  }
19
- /** Snapshot of the pending elements, safe to iterate while releasing them. */
20
12
  get elements() {
21
13
  return [...this.#pending.keys()];
22
14
  }
23
- /** Whether `element` is currently holding an update back. */
24
15
  has(element) {
25
16
  return this.#pending.has(element);
26
17
  }
27
- /** Holds an update back until `element` blurs. Idempotent (no stacked listeners). */
28
18
  defer(element) {
29
19
  if (this.#pending.has(element)) return;
30
20
  const onBlur = () => {
@@ -34,22 +24,18 @@ var BlurDeferral = class {
34
24
  this.#pending.set(element, onBlur);
35
25
  element.addEventListener("blur", onBlur);
36
26
  }
37
- /** Defers `element` as the only pending entry, cancelling any others. */
38
27
  deferOnly(element) {
39
28
  for (const pending of this.elements) {
40
29
  if (pending !== element) this.#detach(pending);
41
30
  }
42
31
  this.defer(element);
43
32
  }
44
- /** Cancels `element`'s deferral without completing it; no-ops when not pending. */
45
33
  release(element) {
46
34
  this.#detach(element);
47
35
  }
48
- /** Cancels every deferral without completing any of them. */
49
36
  releaseAll() {
50
37
  for (const element of this.elements) this.#detach(element);
51
38
  }
52
- /** Removes the `blur` listener for `element` and forgets it. */
53
39
  #detach(element) {
54
40
  const onBlur = this.#pending.get(element);
55
41
  if (onBlur) element.removeEventListener("blur", onBlur);
@@ -57,18 +43,15 @@ var BlurDeferral = class {
57
43
  }
58
44
  };
59
45
 
60
- // src/utils/layout_observer.ts
61
46
  var LayoutObserver = class {
62
47
  #callback;
63
48
  #resizeObserverFactory;
64
49
  #resizeObserver = null;
65
50
  #observingViewport = false;
66
51
  #loadContainer = null;
67
- /** Stable bound handler so add/removeEventListener target the same reference. */
68
52
  #handleViewportResize = () => {
69
53
  this.#callback();
70
54
  };
71
- /** Stable bound handler for the capture-phase `load`; see {@link observeDescendantLoads}. */
72
55
  #handleDescendantLoad = () => {
73
56
  this.#callback();
74
57
  };
@@ -76,11 +59,6 @@ var LayoutObserver = class {
76
59
  this.#callback = callback;
77
60
  this.#resizeObserverFactory = options.resizeObserverFactory ?? (typeof ResizeObserver === "undefined" ? null : (cb) => new ResizeObserver(cb));
78
61
  }
79
- /**
80
- * Starts observing an element's size. Repeated calls observe additional
81
- * elements through the same shared observer. No-ops when no
82
- * `ResizeObserver` implementation is available.
83
- */
84
62
  observe(element) {
85
63
  if (!this.#resizeObserverFactory) return;
86
64
  if (!this.#resizeObserver) {
@@ -90,47 +68,28 @@ var LayoutObserver = class {
90
68
  }
91
69
  this.#resizeObserver.observe(element);
92
70
  }
93
- /** Stops observing a single element while leaving any others in place. */
94
71
  unobserve(element) {
95
72
  this.#resizeObserver?.unobserve(element);
96
73
  }
97
- /** Starts observing viewport resizes. Idempotent: the listener is added once. */
98
74
  observeViewport() {
99
75
  if (this.#observingViewport) return;
100
76
  this.#observingViewport = true;
101
77
  window.addEventListener("resize", this.#handleViewportResize);
102
78
  }
103
- /** Stops observing viewport resizes without affecting element observation. */
104
79
  unobserveViewport() {
105
80
  if (!this.#observingViewport) return;
106
81
  this.#observingViewport = false;
107
82
  window.removeEventListener("resize", this.#handleViewportResize);
108
83
  }
109
- /**
110
- * Starts reporting a `load` from anywhere inside `container` — an image or a
111
- * frame settling changes the box it sits in, and it measures as zero high until
112
- * then. `load` does not bubble, so the subscription is a capture-phase listener
113
- * on the container itself and nothing the caller spells.
114
- *
115
- * **One container at a time.** A further call moves the observation, so a widget
116
- * whose content element is swapped at runtime releases the element it let go by
117
- * naming the new one — there is no second place for the release to drift from.
118
- */
119
84
  observeDescendantLoads(container) {
120
85
  this.unobserveDescendantLoads();
121
86
  this.#loadContainer = container;
122
87
  container.addEventListener("load", this.#handleDescendantLoad, true);
123
88
  }
124
- /** Stops reporting descendant loads without affecting element or viewport observation. */
125
89
  unobserveDescendantLoads() {
126
90
  this.#loadContainer?.removeEventListener("load", this.#handleDescendantLoad, true);
127
91
  this.#loadContainer = null;
128
92
  }
129
- /**
130
- * Releases every observation: disconnects the {@link ResizeObserver} and removes
131
- * the viewport and descendant-load listeners. Safe to call multiple times. Call
132
- * this from a controller's `disconnect()`.
133
- */
134
93
  disconnect() {
135
94
  this.#resizeObserver?.disconnect();
136
95
  this.#resizeObserver = null;
@@ -139,30 +98,23 @@ var LayoutObserver = class {
139
98
  }
140
99
  };
141
100
 
142
- // src/controllers/breadcrumb_controller.ts
143
101
  var OVERFLOW_EPSILON = 1;
144
102
  var BreadcrumbController = class extends Controller {
145
103
  static targets = ["list", "collapsible", "ellipsis", "trigger"];
146
104
  static actions = ["toggle", "update"];
147
105
  static events = ["toggle"];
148
- /** Guards target callbacks that can fire outside the connected window. */
149
106
  #connected = false;
150
- /** Whether the trail currently overflows its container. */
151
107
  #overflowing = false;
152
- /** Whether the user has expanded the collapsed items via the disclosure. */
153
108
  #expanded = false;
154
- /** The list element currently observed (resize + mutations), if any. */
155
109
  #observedList = null;
156
110
  #listMutations = null;
157
111
  #layout = new LayoutObserver(() => this.update());
158
112
  #onListMutation = () => {
159
113
  this.update();
160
114
  };
161
- /** Holds the ellipsis hide back while it contains focus; re-renders on blur. */
162
115
  #deferredHide = new BlurDeferral(() => {
163
116
  this.#render();
164
117
  });
165
- /** Starts observing for overflow and renders the initial state. */
166
118
  connect() {
167
119
  this.#connected = true;
168
120
  this.#expanded = this.#initialExpanded();
@@ -170,7 +122,6 @@ var BreadcrumbController = class extends Controller {
170
122
  this.#syncListObservation();
171
123
  this.update();
172
124
  }
173
- /** Releases the resize/mutation observation (Turbo navigation included). */
174
125
  disconnect() {
175
126
  this.#connected = false;
176
127
  this.#deferredHide.releaseAll();
@@ -186,91 +137,42 @@ var BreadcrumbController = class extends Controller {
186
137
  collapsibleTargetConnected() {
187
138
  this.#resync();
188
139
  }
189
- /**
190
- * Re-measures when an `ellipsis` target arrives. The `ellipsis` and `trigger`
191
- * targets form the disclosure set, a precondition for collapsing at all, so they
192
- * need the same watching the list and items get: without their callbacks a swap
193
- * that breaks or completes the set would only take effect at the next resize or
194
- * list mutation, which may never come.
195
- */
196
140
  ellipsisTargetConnected() {
197
141
  this.#resync();
198
142
  }
199
- /** Re-measures when an `ellipsis` target leaves the disclosure set. */
200
143
  ellipsisTargetDisconnected() {
201
144
  this.#resync();
202
145
  }
203
- /** Re-measures when a `trigger` target joins the disclosure set. */
204
146
  triggerTargetConnected() {
205
147
  this.#resync();
206
148
  }
207
- /** Re-measures when a `trigger` target leaves the disclosure set. */
208
149
  triggerTargetDisconnected() {
209
150
  this.#resync();
210
151
  }
211
- /**
212
- * Hands `hidden` back when an element stops being a `collapsible` target.
213
- *
214
- * The marker is the source of truth for what may be collapsed, so an element
215
- * that loses it while the controller is live is an always-visible item again —
216
- * and rendering only walks the *current* targets, so nothing else would ever
217
- * clear the `hidden` this controller put there.
218
- *
219
- * The `#connected` guard is load-bearing, not defensive. Stimulus fires this
220
- * callback for **every** target during teardown as well (`Context.disconnect()`
221
- * stops the target observer after `disconnect()` has run), and there the
222
- * collapsed DOM must survive untouched so Turbo's cache restores the trail in
223
- * the state the user left it (see the ownership note in {@link BreadcrumbController}).
224
- *
225
- * @param element - the element that just left the `collapsible` target set
226
- */
227
152
  collapsibleTargetDisconnected(element) {
228
153
  if (this.#connected) element.hidden = false;
229
154
  this.#resync();
230
155
  }
231
- /**
232
- * Expands or re-collapses the trail and dispatches `toggle`.
233
- *
234
- * No-op while the trail fits: there is nothing collapsed to reveal, and the
235
- * (hidden) trigger would otherwise keep a stale `aria-expanded="true"` that
236
- * surfaces pre-expanded the next time the trail overflows. No event is
237
- * dispatched in that case.
238
- */
239
156
  toggle() {
240
157
  if (!this.#connected || !this.#overflowing) return;
241
158
  this.#expanded = !this.#expanded;
242
159
  this.#render();
243
160
  this.dispatch("toggle", { detail: { expanded: this.#expanded } });
244
161
  }
245
- /**
246
- * Re-measures overflow and re-renders. Wired to resizes and list mutations;
247
- * exposed as an action so consumers can re-measure after a change the
248
- * observers cannot see (e.g. a web font swap that only alters text width).
249
- */
250
162
  update() {
251
163
  if (!this.#connected) return;
252
164
  this.#overflowing = this.#measureOverflow();
253
165
  if (!this.#overflowing) this.#expanded = false;
254
166
  this.#render();
255
167
  }
256
- /** Re-attaches the list observation (targets may have been swapped) and re-measures. */
257
168
  #resync() {
258
169
  if (!this.#connected) return;
259
170
  this.#syncListObservation();
260
171
  this.update();
261
172
  }
262
- /** Reads the expanded state back from its DOM home (the trigger's `aria-expanded`). */
263
173
  #initialExpanded() {
264
174
  return this.hasTriggerTarget && this.triggerTarget.getAttribute("aria-expanded") === "true";
265
175
  }
266
- /**
267
- * Points the resize + mutation observation at the current `list` target.
268
- *
269
- * The list is re-resolved rather than captured at connect so a target swapped
270
- * at runtime (Turbo Stream replacement of the `<ol>`) is observed too. Only
271
- * `childList` / `subtree` / `characterData` are watched — deliberately **not**
272
- * `attributes`, which the controller's own `hidden` writes would re-trigger.
273
- */
274
176
  #syncListObservation() {
275
177
  const next = this.hasListTarget ? this.listTarget : null;
276
178
  if (next === this.#observedList) return;
@@ -289,26 +191,6 @@ var BreadcrumbController = class extends Controller {
289
191
  this.#listMutations?.disconnect();
290
192
  this.#listMutations = null;
291
193
  }
292
- /**
293
- * Measures overflow against the **fully expanded** layout so hiding items does
294
- * not make the condition oscillate. Reveals every item, then compares the list's
295
- * own scroll width to its own client width; `#render` immediately re-applies
296
- * the correct hidden state afterward.
297
- *
298
- * Both widths are read from the list element itself (not the host `nav`) so the
299
- * check is independent of any padding/border on the host — comparing against the
300
- * host's `clientWidth` would over-report the available space by its padding and
301
- * miss real overflow in a padded container.
302
- *
303
- * With no `collapsible` items there is nothing to collapse, so the trail is
304
- * never reported as overflowing (which also keeps the disclosure out of the
305
- * tab order — a button controlling nothing).
306
- *
307
- * The full disclosure set is a precondition: collapsing without an `ellipsis`
308
- * *and* a `trigger` would hide items behind a control that does not exist, so
309
- * an incomplete set reports "not overflowing" and `#render` degrades the trail
310
- * to a plain breadcrumb. Losing layout is recoverable; losing the path is not.
311
- */
312
194
  #measureOverflow() {
313
195
  if (!this.hasListTarget || this.collapsibleTargets.length === 0) return false;
314
196
  if (!this.hasEllipsisTarget || !this.hasTriggerTarget) return false;
@@ -316,9 +198,6 @@ var BreadcrumbController = class extends Controller {
316
198
  this.ellipsisTarget.hidden = true;
317
199
  return this.listTarget.scrollWidth > this.listTarget.clientWidth + OVERFLOW_EPSILON;
318
200
  }
319
- /**
320
- * Applies the collapsed/expanded state to the items, ellipsis, and trigger.
321
- */
322
201
  #render() {
323
202
  const collapsed = this.#overflowing && !this.#expanded;
324
203
  const showEllipsis = this.#overflowing && this.collapsibleTargets.length > 0;
@@ -331,13 +210,6 @@ var BreadcrumbController = class extends Controller {
331
210
  }
332
211
  if (rescueFocus) this.triggerTarget.focus();
333
212
  }
334
- /**
335
- * Shows or hides the ellipsis item, deferring a hide that would blur the user.
336
- *
337
- * Hiding the element that currently holds focus drops focus to `<body>`, so the
338
- * hide waits for that element's `blur` and is re-applied then (the shared
339
- * `BlurDeferral` registry).
340
- */
341
213
  #applyEllipsisVisibility(show) {
342
214
  const ellipsis = this.ellipsisTarget;
343
215
  if (show) {
@@ -354,7 +226,6 @@ var BreadcrumbController = class extends Controller {
354
226
  this.#deferredHide.releaseAll();
355
227
  ellipsis.hidden = true;
356
228
  }
357
- /** Whether `element` contains (or is) the currently focused element. */
358
229
  #holdsFocus(element) {
359
230
  const active = document.activeElement;
360
231
  return active instanceof HTMLElement && element.contains(active);
@@ -362,5 +233,4 @@ var BreadcrumbController = class extends Controller {
362
233
  };
363
234
 
364
235
  export { BreadcrumbController };
365
- //# sourceMappingURL=breadcrumb_controller.js.map
366
236
  //# sourceMappingURL=breadcrumb_controller.js.map