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
@@ -24,16 +24,23 @@ function actionSource(source) {
24
24
 
25
25
  function setAttributeIfChanged(element, name, value, beforeWrite) {
26
26
  if (element.getAttribute(name) === value) return false;
27
+ beforeWrite?.();
27
28
  if (value === null) element.removeAttribute(name);
28
29
  else element.setAttribute(name, value);
29
30
  return true;
30
31
  }
31
32
 
32
- function syncActiveOption(options, active) {
33
+ function syncActiveOption(options, active, lease) {
33
34
  let written = 0;
34
35
  for (const option of options) {
35
36
  const next = option === active ? "true" : "false";
36
- if (setAttributeIfChanged(option, "aria-selected", next)) written += 1;
37
+ if (lease) {
38
+ if (option.getAttribute("aria-selected") === next) continue;
39
+ lease.adopt(option, { ifChanged: true });
40
+ lease.write(option, next, () => {
41
+ written += 1;
42
+ });
43
+ } else if (setAttributeIfChanged(option, "aria-selected", next)) written += 1;
37
44
  }
38
45
  return written;
39
46
  }
@@ -114,14 +121,34 @@ var AttributeLease = class {
114
121
  const names = registry.names;
115
122
  names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
116
123
  }
117
- write(element, value) {
124
+ write(element, value, beforeWrite) {
118
125
  const stack = attributeStack(element, this.#attribute);
119
126
  const hold = this.#take(stack) ?? this.#acquire(element, stack);
120
127
  this.#held.add(element);
121
128
  const shows = !this.#covered(element, stack, hold);
122
129
  hold.written = value;
123
130
  this.#mark(element, stack);
124
- if (shows) this.#reflect(element, value);
131
+ if (shows) this.#reflect(element, value, beforeWrite);
132
+ }
133
+ adopt(element, options = {}) {
134
+ const known = registry.stacks.get(element)?.has(this.#attribute);
135
+ if (!this.#held.has(element) && !known && !element.hasAttribute(this.#record)) return false;
136
+ const stack = attributeStack(element, this.#attribute);
137
+ const hold = this.#take(stack);
138
+ if (!hold) return false;
139
+ const current = element.getAttribute(this.#attribute);
140
+ if (options.ifChanged && (current === hold.written || this.#covered(element, stack, hold))) {
141
+ return false;
142
+ }
143
+ this.#held.add(element);
144
+ hold.original = current;
145
+ hold.linked = false;
146
+ for (const above of stack.slice(stack.indexOf(hold) + 1)) {
147
+ if (!above.linked) break;
148
+ above.original = current;
149
+ }
150
+ this.#mark(element, stack);
151
+ return true;
125
152
  }
126
153
  return(element) {
127
154
  const held = this.#held.delete(element);
@@ -187,8 +214,8 @@ var AttributeLease = class {
187
214
  setAttributeIfChanged(element, name, recorded);
188
215
  }
189
216
  }
190
- #reflect(element, value) {
191
- setAttributeIfChanged(element, this.#attribute, value);
217
+ #reflect(element, value, beforeWrite) {
218
+ setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
192
219
  }
193
220
  };
194
221
 
@@ -202,7 +229,50 @@ function isCompositionInputType(inputType) {
202
229
  return inputType !== void 0 && COMPOSITION_INPUT_TYPES.has(inputType);
203
230
  }
204
231
  var BEFORE_MORPH_ATTRIBUTE = "turbo:before-morph-attribute";
205
- var textOf = (element) => element.value;
232
+ var textOf = (element) => {
233
+ if ("value" in element) return element.value;
234
+ return element instanceof Element ? element.textContent : void 0;
235
+ };
236
+ var nodesOf = (element) => {
237
+ const nodes = [];
238
+ if ("value" in element || !(element instanceof Element)) return nodes;
239
+ const walker = element.ownerDocument.createTreeWalker(element);
240
+ for (let node = walker.nextNode(); node !== null; node = walker.nextNode()) nodes.push(node);
241
+ return nodes;
242
+ };
243
+ var folded = (text) => text.replaceAll("\xA0", " ");
244
+ var startOf = (node, data, replaced, caret) => {
245
+ const text = folded(node.data);
246
+ const composed = folded(data);
247
+ if (replaced?.startContainer === node && text.startsWith(composed, replaced.startOffset)) {
248
+ return replaced.startOffset;
249
+ }
250
+ const start = text.lastIndexOf(composed, caret);
251
+ return start !== -1 && start + composed.length >= caret ? start : -1;
252
+ };
253
+ var spotOf = (element, replaced, data) => {
254
+ if ("value" in element || !(element instanceof Element)) return null;
255
+ const selection = element.ownerDocument.getSelection();
256
+ const node = selection?.focusNode;
257
+ if (!(node instanceof Text) || node.data === "" || !element.contains(node)) return null;
258
+ const range = element.ownerDocument.createRange();
259
+ const start = typeof data === "string" && data !== "" ? startOf(node, data, replaced, selection?.focusOffset ?? 0) : -1;
260
+ if (start === -1) {
261
+ range.selectNodeContents(node);
262
+ } else {
263
+ range.setStart(node, start);
264
+ range.setEnd(node, start + data.length);
265
+ }
266
+ return range;
267
+ };
268
+ var replacedBy = (event) => typeof event.getTargetRanges === "function" ? event.getTargetRanges()[0] ?? null : null;
269
+ var rewritten = ({ element, text, nodes, spot }) => {
270
+ if (spot !== null) {
271
+ return spot.collapsed || !(element instanceof Node && element.contains(spot.startContainer));
272
+ }
273
+ const current = nodesOf(element);
274
+ return textOf(element) !== text || current.length !== nodes.length || current.some((node, index) => node !== nodes[index]);
275
+ };
206
276
  var holdsFocus = (element) => element instanceof Node && element.getRootNode().activeElement === element;
207
277
  var CompositionTracker = class {
208
278
  #observedTargets = /* @__PURE__ */ new Set();
@@ -263,7 +333,7 @@ var CompositionTracker = class {
263
333
  this.#confirmedTarget = null;
264
334
  if (confirmed === null || confirmed !== event.target) return false;
265
335
  const inputType = event.inputType;
266
- return !inputType || isCompositionInputType(inputType);
336
+ return inputType ? isCompositionInputType(inputType) : event.isTrusted === true;
267
337
  }
268
338
  #release(target) {
269
339
  target.removeEventListener("compositionstart", this.#handleStart);
@@ -293,11 +363,11 @@ var CompositionTracker = class {
293
363
  }
294
364
  #settle() {
295
365
  const composition = this.#composition;
296
- if (composition === null) return;
297
- const { target, element, text } = composition;
366
+ if (composition === null || !this.#observedTargets.has(composition.target)) return;
367
+ const { target, element } = composition;
298
368
  if (target instanceof Node && element instanceof Node && !target.contains(element)) {
299
369
  this.#composition = null;
300
- } else if (textOf(element) !== text) {
370
+ } else if (rewritten(composition)) {
301
371
  this.#abandon(false);
302
372
  }
303
373
  }
@@ -322,7 +392,14 @@ var CompositionTracker = class {
322
392
  this.#owe(true);
323
393
  const target = event.currentTarget;
324
394
  const element = event.target;
325
- this.#composition = { target, element, text: textOf(element) };
395
+ this.#composition = {
396
+ target,
397
+ element,
398
+ text: textOf(element),
399
+ nodes: nodesOf(element),
400
+ spot: spotOf(element, null, void 0),
401
+ replaced: null
402
+ };
326
403
  this.#runAbandon();
327
404
  this.#onStart?.(event);
328
405
  };
@@ -346,6 +423,10 @@ var CompositionTracker = class {
346
423
  if (this.#composition !== null && !keyComposing && !isComposing && inputType && !isCompositionInputType(inputType)) {
347
424
  this.#abandon(true);
348
425
  }
426
+ const composition = this.#composition;
427
+ if (composition !== null && event.target === composition.element) {
428
+ composition.replaced = replacedBy(event);
429
+ }
349
430
  this.#runAbandon();
350
431
  };
351
432
  #handleInput = (event) => {
@@ -353,6 +434,15 @@ var CompositionTracker = class {
353
434
  const { isTrusted, isComposing, inputType } = event;
354
435
  if (composition !== null && event.target === composition.element && (isTrusted || isComposing || isCompositionInputType(inputType))) {
355
436
  composition.text = textOf(composition.element);
437
+ composition.nodes = nodesOf(composition.element);
438
+ if (isCompositionInputType(inputType)) {
439
+ composition.spot = spotOf(
440
+ composition.element,
441
+ composition.replaced,
442
+ event.data
443
+ );
444
+ }
445
+ composition.replaced = null;
356
446
  } else {
357
447
  this.#settle();
358
448
  }
@@ -373,7 +463,9 @@ var CompositionTracker = class {
373
463
  const composition = this.#composition;
374
464
  if (composition?.target !== event.currentTarget || event.target !== composition.element) return;
375
465
  const detail = event.detail;
376
- if (detail?.attributeName === "value") event.preventDefault();
466
+ if (detail?.attributeName === "value" && "value" in composition.element) {
467
+ event.preventDefault();
468
+ }
377
469
  };
378
470
  };
379
471
 
@@ -601,17 +693,26 @@ var ComboboxController = class extends Controller {
601
693
  #activeId = null;
602
694
  #connected = false;
603
695
  #list = null;
696
+ #open = false;
697
+ #pendingEntry = null;
604
698
  #listHidden = new AttributeLease("hidden", this.identifier);
699
+ #optionHidden = new AttributeLease("hidden", this.identifier);
605
700
  #expanded = new AttributeLease("aria-expanded", this.identifier);
606
701
  #activeDescendant = new AttributeLease(
607
702
  "aria-activedescendant",
608
703
  this.identifier
609
704
  );
705
+ #optionSelected = new AttributeLease("aria-selected", this.identifier);
706
+ #knownOptions = /* @__PURE__ */ new Set();
610
707
  #reconcile = new MicrotaskCoalescer(() => this.#reconcileOptions());
611
708
  #suppressOpen = false;
612
709
  #composition = new CompositionTracker({ onEnd: () => this.filter() });
613
710
  #listeners = new ListenerSet();
614
711
  connect() {
712
+ const options = new Set(this.optionTargets);
713
+ for (const option of this.#knownOptions) {
714
+ if (!options.has(option)) this.#returnOption(option);
715
+ }
615
716
  if (this.hasInputTarget) this.#composition.observe(this.inputTarget);
616
717
  this.close();
617
718
  this.#list = this.hasListTarget ? this.listTarget : null;
@@ -648,21 +749,34 @@ var ComboboxController = class extends Controller {
648
749
  this.#reflectEmptyState();
649
750
  }
650
751
  optionTargetConnected(option) {
651
- option.setAttribute("aria-selected", "false");
752
+ if (!this.#knownOptions.has(option)) {
753
+ this.#knownOptions.add(option);
754
+ syncActiveOption([option], null, this.#optionSelected);
755
+ }
652
756
  if (this.#connected) this.#queueOptionReconciliation();
653
757
  }
654
758
  optionTargetDisconnected(option) {
655
- option.setAttribute("aria-selected", "false");
759
+ if (!this.scope.containsElement(option) || !this.optionTargets.includes(option)) {
760
+ this.#returnOption(option);
761
+ }
656
762
  if (this.#connected) this.#queueOptionReconciliation();
657
763
  }
764
+ #returnOption(option) {
765
+ this.#knownOptions.delete(option);
766
+ this.#optionSelected.return(option);
767
+ this.#optionHidden.return(option);
768
+ }
658
769
  filter(event) {
659
770
  if (this.#composition.isComposing(event)) return;
660
771
  this.open();
661
772
  }
662
773
  open() {
663
- if (!this.hasListTarget || !this.hasInputTarget || this.#suppressOpen) return;
774
+ if (!this.hasInputTarget || this.#suppressOpen) return;
775
+ this.#adoptList();
664
776
  this.#applyFilter();
665
- this.#listHidden.write(this.listTarget, null);
777
+ this.#open = true;
778
+ this.#pendingEntry = null;
779
+ if (this.hasListTarget) this.#listHidden.write(this.listTarget, null);
666
780
  this.#expanded.write(this.inputTarget, "true");
667
781
  this.#setActive(-1);
668
782
  this.#reflectEmptyState();
@@ -671,12 +785,15 @@ var ComboboxController = class extends Controller {
671
785
  const query = this.inputTarget.value.trim().toLowerCase();
672
786
  for (const option of this.optionTargets) {
673
787
  const text = (option.textContent ?? "").trim().toLowerCase();
674
- option.hidden = query.length > 0 && !text.includes(query);
788
+ if (text.includes(query)) this.#optionHidden.return(option);
789
+ else if (!option.hidden) this.#optionHidden.write(option, "");
675
790
  }
676
791
  }
677
792
  close() {
678
- if (!this.hasListTarget) return;
679
- this.#listHidden.write(this.listTarget, "");
793
+ this.#adoptList();
794
+ this.#open = false;
795
+ this.#pendingEntry = null;
796
+ if (this.hasListTarget) this.#listHidden.write(this.listTarget, "");
680
797
  this.#reflectEmptyState();
681
798
  if (this.hasInputTarget) this.#expanded.write(this.inputTarget, "false");
682
799
  this.#setActive(-1);
@@ -686,6 +803,7 @@ var ComboboxController = class extends Controller {
686
803
  if (event.defaultPrevented) return;
687
804
  if (isReservedArrowChord(event, ["alt"])) return;
688
805
  if ((event.key === "Home" || event.key === "End") && hasModifierChord(event)) return;
806
+ this.#adoptList();
689
807
  if (event.altKey && (event.key === "ArrowDown" || event.key === "ArrowUp")) {
690
808
  if (event.key === "ArrowDown" ? !this.#isClosed : this.#isClosed) return;
691
809
  event.preventDefault();
@@ -706,6 +824,8 @@ var ComboboxController = class extends Controller {
706
824
  const activeIndex = this.#findActiveIndex(visible);
707
825
  const next = activeIndex === -1 ? 0 : (activeIndex + 1) % visible.length;
708
826
  this.#setActive(next);
827
+ } else if (!this.hasListTarget) {
828
+ this.#pendingEntry = 1;
709
829
  }
710
830
  break;
711
831
  }
@@ -717,6 +837,8 @@ var ComboboxController = class extends Controller {
717
837
  const activeIndex = this.#findActiveIndex(visible);
718
838
  const next = activeIndex === -1 ? visible.length - 1 : (activeIndex - 1 + visible.length) % visible.length;
719
839
  this.#setActive(next);
840
+ } else if (!this.hasListTarget) {
841
+ this.#pendingEntry = -1;
720
842
  }
721
843
  break;
722
844
  }
@@ -790,7 +912,7 @@ var ComboboxController = class extends Controller {
790
912
  this.dispatch("selected", { detail: { value, reason } });
791
913
  }
792
914
  #reflectEmptyState() {
793
- const empty = !this.#isClosed && this.#visibleOptions().length === 0;
915
+ const empty = this.hasListTarget && !this.#isClosed && this.#visibleOptions().length === 0;
794
916
  if (empty) {
795
917
  this.element.setAttribute(`data-${this.identifier}-empty`, "");
796
918
  } else {
@@ -801,7 +923,7 @@ var ComboboxController = class extends Controller {
801
923
  #setActive(index) {
802
924
  const visible = this.#visibleOptions();
803
925
  const active = index === -1 ? null : visible[index] ?? null;
804
- syncActiveOption(this.optionTargets, active);
926
+ syncActiveOption(this.optionTargets, active, this.#optionSelected);
805
927
  this.#activeId = active?.id || null;
806
928
  if (this.hasInputTarget) this.#activeDescendant.write(this.inputTarget, active?.id || null);
807
929
  if (active && this.hasListTarget) scrollOptionIntoView(this.listTarget, active);
@@ -811,8 +933,9 @@ var ComboboxController = class extends Controller {
811
933
  const list = this.hasListTarget ? this.listTarget : null;
812
934
  const previous = this.#list;
813
935
  if (list === previous) return;
936
+ if (previous) this.#open = !previous.hidden;
814
937
  this.#list = list;
815
- if (list) this.#listHidden.write(list, previous?.hidden ?? true ? "" : null);
938
+ if (list) this.#listHidden.write(list, this.#open ? null : "");
816
939
  this.#queueOptionReconciliation();
817
940
  }
818
941
  #reconcileOptions() {
@@ -820,7 +943,13 @@ var ComboboxController = class extends Controller {
820
943
  this.#expanded.write(this.inputTarget, String(!this.#isClosed));
821
944
  if (!this.#isClosed) this.#applyFilter();
822
945
  }
823
- this.#reconcileActive();
946
+ if (this.#pendingEntry !== null && this.hasListTarget && this.hasInputTarget && !this.#isClosed) {
947
+ const index = this.#pendingEntry === 1 ? 0 : this.#visibleOptions().length - 1;
948
+ this.#pendingEntry = null;
949
+ this.#setActive(index);
950
+ } else {
951
+ this.#reconcileActive();
952
+ }
824
953
  this.#reflectEmptyState();
825
954
  }
826
955
  #reconcileActive() {
@@ -847,10 +976,10 @@ var ComboboxController = class extends Controller {
847
976
  this.#reconcile.schedule();
848
977
  }
849
978
  #visibleOptions() {
850
- return this.optionTargets.filter((option) => !option.hidden);
979
+ return this.hasListTarget ? this.optionTargets.filter((option) => !option.hidden) : [];
851
980
  }
852
981
  get #isClosed() {
853
- return !this.hasListTarget || this.listTarget.hidden !== false;
982
+ return this.#list ? this.#list.hidden !== false : !this.#open;
854
983
  }
855
984
  };
856
985