stimeo-ui 0.18.2 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +33 -0
  3. data/dist/controllers/alert_dialog_controller.js +246 -42
  4. data/dist/controllers/auto_submit_controller.js +26 -5
  5. data/dist/controllers/avatar_controller.js +29 -9
  6. data/dist/controllers/breadcrumb_controller.js +205 -17
  7. data/dist/controllers/bulk_select_controller.js +25 -4
  8. data/dist/controllers/calendar_controller.js +242 -7
  9. data/dist/controllers/carousel_controller.js +70 -15
  10. data/dist/controllers/character_counter_controller.js +26 -5
  11. data/dist/controllers/collapsible_controller.js +35 -8
  12. data/dist/controllers/combobox_controller.js +84 -20
  13. data/dist/controllers/command_palette_controller.js +296 -77
  14. data/dist/controllers/confirm_controller.js +225 -34
  15. data/dist/controllers/context_menu_controller.js +58 -29
  16. data/dist/controllers/currency_input_controller.js +1 -1
  17. data/dist/controllers/data_grid_controller.js +196 -9
  18. data/dist/controllers/date_range_picker_controller.js +25 -4
  19. data/dist/controllers/dialog_controller.js +252 -45
  20. data/dist/controllers/dismissible_controller.js +57 -11
  21. data/dist/controllers/drawer_controller.js +284 -58
  22. data/dist/controllers/dropdown_controller.js +63 -51
  23. data/dist/controllers/editable_controller.js +69 -6
  24. data/dist/controllers/empty_state_controller.js +187 -4
  25. data/dist/controllers/file_dropzone_controller.js +300 -12
  26. data/dist/controllers/filter_controller.js +194 -5
  27. data/dist/controllers/flash_controller.js +199 -12
  28. data/dist/controllers/focus_controller.js +195 -23
  29. data/dist/controllers/form_field_controller.js +65 -9
  30. data/dist/controllers/frame_loading_controller.js +25 -4
  31. data/dist/controllers/hover_card_controller.js +107 -38
  32. data/dist/controllers/input_mask_controller.js +1 -1
  33. data/dist/controllers/listbox_controller.js +94 -36
  34. data/dist/controllers/menu_controller.js +44 -23
  35. data/dist/controllers/menubar_controller.js +228 -46
  36. data/dist/controllers/meter_controller.js +25 -4
  37. data/dist/controllers/multi_select_controller.js +110 -42
  38. data/dist/controllers/nested_form_controller.js +258 -9
  39. data/dist/controllers/network_status_controller.js +25 -4
  40. data/dist/controllers/number_input_controller.js +26 -5
  41. data/dist/controllers/otp_controller.js +26 -5
  42. data/dist/controllers/overflow_menu_controller.js +183 -22
  43. data/dist/controllers/pagination_controller.js +179 -22
  44. data/dist/controllers/password_reveal_controller.js +25 -4
  45. data/dist/controllers/popover_controller.js +454 -34
  46. data/dist/controllers/progress_controller.js +25 -4
  47. data/dist/controllers/radio_group_controller.js +195 -40
  48. data/dist/controllers/rating_controller.js +58 -10
  49. data/dist/controllers/read_more_controller.js +191 -25
  50. data/dist/controllers/roving_controller.js +197 -6
  51. data/dist/controllers/scroll_area_controller.js +50 -12
  52. data/dist/controllers/scroll_visibility_controller.js +25 -4
  53. data/dist/controllers/scrollspy_controller.js +179 -3
  54. data/dist/controllers/separator_controller.js +25 -4
  55. data/dist/controllers/sidebar_controller.js +290 -93
  56. data/dist/controllers/skeleton_controller.js +25 -4
  57. data/dist/controllers/spinner_controller.js +25 -4
  58. data/dist/controllers/step_indicator_controller.js +181 -6
  59. data/dist/controllers/stepper_controller.js +188 -6
  60. data/dist/controllers/sticky_observer_controller.js +25 -4
  61. data/dist/controllers/submit_once_controller.js +25 -4
  62. data/dist/controllers/tabs_controller.js +189 -3
  63. data/dist/controllers/tags_input_controller.js +210 -9
  64. data/dist/controllers/theme_controller.js +192 -5
  65. data/dist/controllers/toast_controller.js +478 -16
  66. data/dist/controllers/toggle_group_controller.js +198 -35
  67. data/dist/controllers/toolbar_controller.js +198 -7
  68. data/dist/controllers/tooltip_controller.js +243 -45
  69. data/dist/controllers/tree_view_controller.js +200 -8
  70. data/dist/index.js +1764 -739
  71. data/lib/stimeo/ui/version.rb +1 -1
  72. metadata +2 -2
@@ -106,14 +106,34 @@ var AttributeLease = class {
106
106
  const names = registry.names;
107
107
  names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
108
108
  }
109
- write(element, value) {
109
+ write(element, value, beforeWrite) {
110
110
  const stack = attributeStack(element, this.#attribute);
111
111
  const hold = this.#take(stack) ?? this.#acquire(element, stack);
112
112
  this.#held.add(element);
113
113
  const shows = !this.#covered(element, stack, hold);
114
114
  hold.written = value;
115
115
  this.#mark(element, stack);
116
- if (shows) this.#reflect(element, value);
116
+ if (shows) this.#reflect(element, value, beforeWrite);
117
+ }
118
+ adopt(element, options = {}) {
119
+ const known = registry.stacks.get(element)?.has(this.#attribute);
120
+ if (!this.#held.has(element) && !known && !element.hasAttribute(this.#record)) return false;
121
+ const stack = attributeStack(element, this.#attribute);
122
+ const hold = this.#take(stack);
123
+ if (!hold) return false;
124
+ const current = element.getAttribute(this.#attribute);
125
+ if (options.ifChanged && (current === hold.written || this.#covered(element, stack, hold))) {
126
+ return false;
127
+ }
128
+ this.#held.add(element);
129
+ hold.original = current;
130
+ hold.linked = false;
131
+ for (const above of stack.slice(stack.indexOf(hold) + 1)) {
132
+ if (!above.linked) break;
133
+ above.original = current;
134
+ }
135
+ this.#mark(element, stack);
136
+ return true;
117
137
  }
118
138
  return(element) {
119
139
  const held = this.#held.delete(element);
@@ -179,8 +199,8 @@ var AttributeLease = class {
179
199
  setAttributeIfChanged(element, name, recorded);
180
200
  }
181
201
  }
182
- #reflect(element, value) {
183
- setAttributeIfChanged(element, this.#attribute, value);
202
+ #reflect(element, value, beforeWrite) {
203
+ setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
184
204
  }
185
205
  };
186
206
 
@@ -588,10 +608,14 @@ var ListboxController = class extends Controller {
588
608
  #activeOrder = [];
589
609
  #reconcile = new MorphRenderWatcher(() => this.#reconcileOptions());
590
610
  #observer = new AuthoredMutationWatcher((records) => {
611
+ this.#adoptOptionWrites(records);
591
612
  if (this.#concernsOptions(records)) this.#reconcile.schedule();
592
613
  });
614
+ #selected = new AttributeLease("aria-selected", this.identifier);
615
+ #managedOptions = /* @__PURE__ */ new Set();
593
616
  #settled = { option: null, value: "" };
594
- #shownList = null;
617
+ #list = null;
618
+ #open = false;
595
619
  #listHidden = new AttributeLease("hidden", this.identifier);
596
620
  #expanded = new AttributeLease("aria-expanded", this.identifier);
597
621
  #activeDescendant = new AttributeLease(
@@ -601,6 +625,11 @@ var ListboxController = class extends Controller {
601
625
  #typeahead = new Typeahead();
602
626
  #listeners = new ListenerSet();
603
627
  connect() {
628
+ const options = new Set(this.optionTargets);
629
+ for (const option of this.#managedOptions) {
630
+ this.#selected.adopt(option, { ifChanged: true });
631
+ if (!options.has(option)) this.#releaseOption(option);
632
+ }
604
633
  this.#normalizeSelection();
605
634
  this.close();
606
635
  this.#listeners.add(document, "click", this.#onOutsideClick, { capture: true });
@@ -609,13 +638,21 @@ var ListboxController = class extends Controller {
609
638
  this.#observeOptions();
610
639
  }
611
640
  optionTargetConnected(option) {
612
- option.removeAttribute("data-active");
641
+ if (!this.#managedOptions.has(option)) option.removeAttribute("data-active");
613
642
  this.#reconcile.schedule();
614
643
  }
615
644
  optionTargetDisconnected(option) {
616
- option.removeAttribute("data-active");
645
+ if (!this.scope.containsElement(option) || !this.optionTargets.includes(option)) {
646
+ this.#flushMutations();
647
+ this.#releaseOption(option);
648
+ }
617
649
  this.#reconcile.schedule();
618
650
  }
651
+ #releaseOption(option) {
652
+ this.#managedOptions.delete(option);
653
+ this.#selected.return(option);
654
+ option.removeAttribute("data-active");
655
+ }
619
656
  triggerTargetConnected() {
620
657
  this.#reconcile.schedule();
621
658
  }
@@ -631,7 +668,7 @@ var ListboxController = class extends Controller {
631
668
  }
632
669
  listTargetDisconnected(list) {
633
670
  if (!this.listTargets.includes(list)) {
634
- if (list === this.#shownList) this.#adoptPageClose();
671
+ if (list === this.#list) this.#reconcileOpenState();
635
672
  this.#listHidden.return(list);
636
673
  }
637
674
  this.#reconcile.schedule();
@@ -664,23 +701,22 @@ var ListboxController = class extends Controller {
664
701
  this.#reportMove();
665
702
  }
666
703
  #reconcileOpenState() {
667
- if (!this.hasListTarget) {
668
- this.#shownList = null;
669
- return;
670
- }
671
- if (this.#shownList && this.listTargets.includes(this.#shownList)) this.#adoptPageClose();
672
- const list = this.listTarget;
673
- if (this.#shownList !== null && list !== this.#shownList) {
674
- this.#listHidden.write(list, null);
675
- this.#shownList = list;
704
+ const previous = this.#list;
705
+ if (previous) this.#open = !previous.hidden;
706
+ const list = this.hasListTarget ? this.listTarget : null;
707
+ if (list !== previous) {
708
+ this.#list = list;
709
+ if (list) {
710
+ this.#listHidden.write(list, this.#open ? null : "");
711
+ if (this.#open && previous === null && this.#activeId === null && this.hasTriggerTarget) {
712
+ this.#activateInitialOption();
713
+ }
714
+ }
676
715
  }
677
716
  if (this.hasTriggerTarget) {
678
- this.#expanded.write(this.triggerTarget, list.hidden ? "false" : "true");
717
+ this.#expanded.write(this.triggerTarget, String(this.#open));
679
718
  }
680
719
  }
681
- #adoptPageClose() {
682
- if (this.#shownList?.hidden) this.#shownList = null;
683
- }
684
720
  #reportMove() {
685
721
  const { option, value } = this.#selection();
686
722
  if (option === this.#settled.option && value === this.#settled.value) return;
@@ -692,6 +728,7 @@ var ListboxController = class extends Controller {
692
728
  return { option, value: option ? this.#optionValue(option) : "" };
693
729
  }
694
730
  disconnect() {
731
+ this.#flushMutations();
695
732
  this.#connectionGeneration += 1;
696
733
  this.#reconcile.disconnect();
697
734
  this.#observer.disconnect();
@@ -710,8 +747,9 @@ var ListboxController = class extends Controller {
710
747
  if (event.defaultPrevented) return;
711
748
  if (isReservedArrowChord(event)) return;
712
749
  if ((event.key === "Home" || event.key === "End") && hasModifierChord(event)) return;
750
+ this.#reconcileOpenState();
713
751
  if (!this.#isClosed) this.#reconcileActive();
714
- const options = this.optionTargets;
752
+ const options = this.hasListTarget ? this.optionTargets : [];
715
753
  const length = options.length;
716
754
  const activeIndex = this.#findActiveIndex(options);
717
755
  if (this.#isClosed) {
@@ -782,25 +820,29 @@ var ListboxController = class extends Controller {
782
820
  }
783
821
  }
784
822
  open() {
785
- if (!this.hasListTarget) return;
786
- this.#listHidden.write(this.listTarget, null);
787
- this.#shownList = this.listTarget;
823
+ if (!this.hasTriggerTarget) return;
824
+ this.#list = this.hasListTarget ? this.listTarget : null;
825
+ this.#open = true;
788
826
  this.#expanded.write(this.triggerTarget, "true");
789
- if (this.optionTargets.length === 0) {
790
- this.#setActive(-1);
791
- return;
827
+ if (this.#list) {
828
+ this.#listHidden.write(this.#list, null);
829
+ this.#activateInitialOption();
792
830
  }
831
+ }
832
+ #activateInitialOption() {
793
833
  const selected = this.optionTargets.findIndex(
794
834
  (option) => option.getAttribute("aria-selected") === "true"
795
835
  );
796
836
  this.#setActive(selected === -1 ? 0 : selected);
797
837
  }
798
838
  close() {
799
- if (!this.hasListTarget) return;
800
- this.#listHidden.write(this.listTarget, "");
801
- this.#shownList = null;
802
- this.#expanded.write(this.triggerTarget, "false");
803
- this.#setActive(-1);
839
+ this.#list = this.hasListTarget ? this.listTarget : null;
840
+ this.#open = false;
841
+ if (this.#list) this.#listHidden.write(this.#list, "");
842
+ if (this.hasTriggerTarget) {
843
+ this.#expanded.write(this.triggerTarget, "false");
844
+ this.#setActive(-1);
845
+ }
804
846
  this.#typeahead.reset();
805
847
  }
806
848
  #commitActive() {
@@ -824,6 +866,7 @@ var ListboxController = class extends Controller {
824
866
  return this.#moves.isLatest(token);
825
867
  }
826
868
  #applySelection(option) {
869
+ this.#flushMutations();
827
870
  for (const candidate of this.optionTargets) {
828
871
  this.#writeSelection(candidate, candidate === option ? "true" : "false");
829
872
  }
@@ -863,8 +906,18 @@ var ListboxController = class extends Controller {
863
906
  const options = new Set(this.optionTargets);
864
907
  return records.some((record) => options.has(record.target));
865
908
  }
909
+ #adoptOptionWrites(records) {
910
+ for (const record of records) {
911
+ const option = record.target;
912
+ if (record.attributeName === "aria-selected" && this.#managedOptions.has(option)) {
913
+ this.#selected.adopt(option);
914
+ }
915
+ }
916
+ }
866
917
  #flushMutations() {
867
- if (this.#concernsOptions(this.#observer.take())) this.#reconcile.schedule();
918
+ const records = this.#observer.take();
919
+ this.#adoptOptionWrites(records);
920
+ if (this.#concernsOptions(records)) this.#reconcile.schedule();
868
921
  }
869
922
  #setActive(index) {
870
923
  const options = this.optionTargets;
@@ -892,6 +945,10 @@ var ListboxController = class extends Controller {
892
945
  if (this.hasTriggerTarget) this.#setActive(-1);
893
946
  return;
894
947
  }
948
+ if (!this.hasListTarget) {
949
+ this.#activeDescendant.write(this.triggerTarget, null);
950
+ return;
951
+ }
895
952
  const options = this.optionTargets;
896
953
  const currentIndex = this.#findActiveIndex(options);
897
954
  if (currentIndex >= 0) {
@@ -935,10 +992,11 @@ var ListboxController = class extends Controller {
935
992
  if (!this.#isClosed && !this.element.contains(event.target)) this.close();
936
993
  };
937
994
  get #isClosed() {
938
- return !this.hasListTarget || this.listTarget.hidden !== false;
995
+ return this.#list ? this.#list.hidden !== false : !this.#open;
939
996
  }
940
997
  #writeSelection(target, value) {
941
- setAttributeIfChanged(target, "aria-selected", value, () => {
998
+ this.#managedOptions.add(target);
999
+ this.#selected.write(target, value, () => {
942
1000
  this.#observer.claim(target, "aria-selected", value);
943
1001
  });
944
1002
  }
@@ -17,6 +17,7 @@ function hasModifierChord(event) {
17
17
 
18
18
  function setAttributeIfChanged(element, name, value, beforeWrite) {
19
19
  if (element.getAttribute(name) === value) return false;
20
+ beforeWrite?.();
20
21
  if (value === null) element.removeAttribute(name);
21
22
  else element.setAttribute(name, value);
22
23
  return true;
@@ -90,14 +91,34 @@ var AttributeLease = class {
90
91
  const names = registry.names;
91
92
  names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
92
93
  }
93
- write(element, value) {
94
+ write(element, value, beforeWrite) {
94
95
  const stack = attributeStack(element, this.#attribute);
95
96
  const hold = this.#take(stack) ?? this.#acquire(element, stack);
96
97
  this.#held.add(element);
97
98
  const shows = !this.#covered(element, stack, hold);
98
99
  hold.written = value;
99
100
  this.#mark(element, stack);
100
- if (shows) this.#reflect(element, value);
101
+ if (shows) this.#reflect(element, value, beforeWrite);
102
+ }
103
+ adopt(element, options = {}) {
104
+ const known = registry.stacks.get(element)?.has(this.#attribute);
105
+ if (!this.#held.has(element) && !known && !element.hasAttribute(this.#record)) return false;
106
+ const stack = attributeStack(element, this.#attribute);
107
+ const hold = this.#take(stack);
108
+ if (!hold) return false;
109
+ const current = element.getAttribute(this.#attribute);
110
+ if (options.ifChanged && (current === hold.written || this.#covered(element, stack, hold))) {
111
+ return false;
112
+ }
113
+ this.#held.add(element);
114
+ hold.original = current;
115
+ hold.linked = false;
116
+ for (const above of stack.slice(stack.indexOf(hold) + 1)) {
117
+ if (!above.linked) break;
118
+ above.original = current;
119
+ }
120
+ this.#mark(element, stack);
121
+ return true;
101
122
  }
102
123
  return(element) {
103
124
  const held = this.#held.delete(element);
@@ -163,8 +184,8 @@ var AttributeLease = class {
163
184
  setAttributeIfChanged(element, name, recorded);
164
185
  }
165
186
  }
166
- #reflect(element, value) {
167
- setAttributeIfChanged(element, this.#attribute, value);
187
+ #reflect(element, value, beforeWrite) {
188
+ setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
168
189
  }
169
190
  };
170
191
 
@@ -331,6 +352,7 @@ var MenuController = class extends Controller {
331
352
  #menuHidden = new AttributeLease("hidden", this.identifier);
332
353
  #expanded = new AttributeLease("aria-expanded", this.identifier);
333
354
  #menu = null;
355
+ #openState = false;
334
356
  #clickOwner = null;
335
357
  #clickVerdicts = new ClickVerdicts();
336
358
  #activated = /* @__PURE__ */ new WeakSet();
@@ -338,6 +360,7 @@ var MenuController = class extends Controller {
338
360
  #reporting = false;
339
361
  #listeners = new ListenerSet();
340
362
  connect() {
363
+ this.#menu = this.hasMenuTarget ? this.menuTarget : null;
341
364
  this.#close("api");
342
365
  this.#listeners.add(this.element, "click", this.#onItemClickCapture, { capture: true });
343
366
  this.#listeners.add(this.element, "click", this.#onDelegatedItemClick);
@@ -383,39 +406,35 @@ var MenuController = class extends Controller {
383
406
  }
384
407
  #open(reason) {
385
408
  this.#timers.clearAll();
386
- if (!this.hasMenuTarget) return;
387
- const menu = this.menuTarget;
409
+ this.#adoptMenu();
388
410
  const was = this.#isOpen;
411
+ this.#openState = true;
389
412
  this.#escapeLayer.activate(document, {
390
413
  onDismiss: () => this.#closeAndRestore("escape"),
391
414
  claims: claimsWhileFocusWithin(this.element)
392
415
  });
393
- this.#menuHidden.write(menu, null);
394
- this.#menu = menu;
395
- if (this.hasTriggerTarget) this.#expanded.write(this.triggerTarget, "true");
416
+ if (this.#menu) this.#menuHidden.write(this.#menu, null);
417
+ this.#reflectTrigger();
396
418
  if (!was && this.#reporting) this.dispatch("open", { detail: { reason }, cancelable: false });
397
419
  }
398
420
  #close(reason) {
421
+ this.#adoptMenu();
422
+ const was = this.#isOpen;
399
423
  this.#timers.clearAll();
400
424
  this.#escapeLayer.deactivate();
401
- const menu = this.hasMenuTarget ? this.menuTarget : null;
402
- this.#menu = menu;
403
- if (!menu) return;
404
- const was = this.#isOpen;
405
- this.#menuHidden.write(menu, "");
406
- if (this.hasTriggerTarget) this.#expanded.write(this.triggerTarget, "false");
425
+ this.#openState = false;
426
+ if (this.#menu) this.#menuHidden.write(this.#menu, "");
427
+ this.#reflectTrigger();
407
428
  if (was && this.#reporting) this.dispatch("close", { detail: { reason }, cancelable: false });
408
429
  }
409
430
  #adoptMenu() {
410
431
  if (!this.#connected) return;
411
432
  const menu = this.hasMenuTarget ? this.menuTarget : null;
412
433
  const previous = this.#menu;
434
+ if (previous) this.#openState = !previous.hidden;
413
435
  this.#menu = menu;
414
- if (!menu) {
415
- this.#escapeLayer.deactivate();
416
- } else if (menu !== previous) {
417
- this.#menuHidden.write(menu, previous?.hidden ?? true ? "" : null);
418
- }
436
+ if (!this.#openState) this.#escapeLayer.deactivate();
437
+ if (menu && menu !== previous) this.#menuHidden.write(menu, this.#openState ? null : "");
419
438
  this.#reflectTrigger();
420
439
  }
421
440
  #reflectTrigger() {
@@ -518,11 +537,13 @@ var MenuController = class extends Controller {
518
537
  event.stopImmediatePropagation();
519
538
  };
520
539
  #focusFirst() {
521
- if (!this.#isOpen) return;
540
+ this.#adoptMenu();
541
+ if (!this.#menu || !this.#isOpen) return;
522
542
  this.#navigableItems[0]?.focus();
523
543
  }
524
544
  #focusLast() {
525
- if (!this.#isOpen) return;
545
+ this.#adoptMenu();
546
+ if (!this.#menu || !this.#isOpen) return;
526
547
  const items = this.#navigableItems;
527
548
  items[items.length - 1]?.focus();
528
549
  }
@@ -537,7 +558,7 @@ var MenuController = class extends Controller {
537
558
  return !this.#isNavigable(item) || isAriaDisabled(item);
538
559
  }
539
560
  get #isOpen() {
540
- return this.hasMenuTarget && !this.menuTarget.hidden;
561
+ return this.#menu ? !this.#menu.hidden : this.#openState;
541
562
  }
542
563
  };
543
564