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
@@ -39,6 +39,7 @@ function hasModifierChord(event) {
39
39
 
40
40
  function setAttributeIfChanged(element, name, value, beforeWrite) {
41
41
  if (element.getAttribute(name) === value) return false;
42
+ beforeWrite?.();
42
43
  if (value === null) element.removeAttribute(name);
43
44
  else element.setAttribute(name, value);
44
45
  return true;
@@ -112,14 +113,34 @@ var AttributeLease = class {
112
113
  const names = registry.names;
113
114
  names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
114
115
  }
115
- write(element, value) {
116
+ write(element, value, beforeWrite) {
116
117
  const stack = attributeStack(element, this.#attribute);
117
118
  const hold = this.#take(stack) ?? this.#acquire(element, stack);
118
119
  this.#held.add(element);
119
120
  const shows = !this.#covered(element, stack, hold);
120
121
  hold.written = value;
121
122
  this.#mark(element, stack);
122
- if (shows) this.#reflect(element, value);
123
+ if (shows) this.#reflect(element, value, beforeWrite);
124
+ }
125
+ adopt(element, options = {}) {
126
+ const known = registry.stacks.get(element)?.has(this.#attribute);
127
+ if (!this.#held.has(element) && !known && !element.hasAttribute(this.#record)) return false;
128
+ const stack = attributeStack(element, this.#attribute);
129
+ const hold = this.#take(stack);
130
+ if (!hold) return false;
131
+ const current = element.getAttribute(this.#attribute);
132
+ if (options.ifChanged && (current === hold.written || this.#covered(element, stack, hold))) {
133
+ return false;
134
+ }
135
+ this.#held.add(element);
136
+ hold.original = current;
137
+ hold.linked = false;
138
+ for (const above of stack.slice(stack.indexOf(hold) + 1)) {
139
+ if (!above.linked) break;
140
+ above.original = current;
141
+ }
142
+ this.#mark(element, stack);
143
+ return true;
123
144
  }
124
145
  return(element) {
125
146
  const held = this.#held.delete(element);
@@ -185,8 +206,8 @@ var AttributeLease = class {
185
206
  setAttributeIfChanged(element, name, recorded);
186
207
  }
187
208
  }
188
- #reflect(element, value) {
189
- setAttributeIfChanged(element, this.#attribute, value);
209
+ #reflect(element, value, beforeWrite) {
210
+ setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
190
211
  }
191
212
  };
192
213
 
@@ -215,6 +236,7 @@ var EscapeLayer = class _EscapeLayer {
215
236
  );
216
237
  #active = null;
217
238
  activate(ownerDocument = document, options) {
239
+ const entry = { onDismiss: options.onDismiss, claims: options.claims ?? null };
218
240
  this.deactivate();
219
241
  let registry2 = _EscapeLayer.#registries.get(ownerDocument);
220
242
  if (!registry2) {
@@ -222,7 +244,6 @@ var EscapeLayer = class _EscapeLayer {
222
244
  _EscapeLayer.#registries.set(ownerDocument, registry2);
223
245
  ownerDocument.addEventListener("keydown", registry2.onKeydown);
224
246
  }
225
- const entry = { onDismiss: options.onDismiss, claims: options.claims ?? null };
226
247
  registry2.stack.push(entry);
227
248
  this.#active = { document: ownerDocument, entry };
228
249
  }
@@ -338,11 +359,14 @@ var ContextMenuController = class _ContextMenuController extends Controller {
338
359
  #menuHidden = new AttributeLease("hidden", this.identifier);
339
360
  #regionState = new AttributeLease("data-state", this.identifier);
340
361
  #menu = null;
362
+ #openState = false;
363
+ #position = ["", ""];
341
364
  #connected = false;
342
365
  #reporting = false;
343
366
  #clickVerdicts = new ClickVerdicts();
344
367
  #listeners = new ListenerSet();
345
368
  connect() {
369
+ this.#menu = this.hasMenuTarget ? this.menuTarget : null;
346
370
  this.#closeMenu("api");
347
371
  this.#listeners.add(this.element, "click", this.#onItemClickCapture, { capture: true });
348
372
  this.#listeners.add(document, "click", this.#onOutsidePointer, { capture: true });
@@ -438,52 +462,57 @@ var ContextMenuController = class _ContextMenuController extends Controller {
438
462
  );
439
463
  }
440
464
  #openAt(x, y, reason) {
441
- if (!this.hasMenuTarget) return;
442
465
  this.#timers.clearAll();
443
- const menu = this.menuTarget;
466
+ this.#adoptMenu();
444
467
  const was = this.#isOpen;
468
+ this.#openState = true;
469
+ this.#position = [`${x}px`, `${y}px`];
445
470
  this.#escapeLayer.activate(document, {
446
471
  onDismiss: () => this.#closeAndRestore("escape"),
447
472
  claims: claimsWhileFocusWithin(this.element)
448
473
  });
449
- menu.style.setProperty(_ContextMenuController.#COORDINATE[0], `${x}px`);
450
- menu.style.setProperty(_ContextMenuController.#COORDINATE[1], `${y}px`);
451
- this.#menuHidden.write(menu, null);
452
- this.#menu = menu;
453
- if (this.hasRegionTarget) this.#regionState.write(this.regionTarget, "open");
474
+ if (this.#menu) this.#showMenu(this.#menu);
475
+ this.#reflectRegion();
454
476
  if (!was && this.#reporting) this.dispatch("open", { detail: { reason }, cancelable: false });
455
- if (!this.#isOpen) return;
477
+ this.#adoptMenu();
478
+ if (!this.#menu || !this.#isOpen) return;
456
479
  this.#navigableItems[0]?.focus();
457
480
  }
458
481
  #closeMenu(reason) {
482
+ this.#adoptMenu();
483
+ const was = this.#isOpen;
459
484
  this.#timers.clearAll();
460
485
  this.#escapeLayer.deactivate();
461
- const menu = this.hasMenuTarget ? this.menuTarget : null;
462
- this.#menu = menu;
463
- if (!menu) return;
464
- const was = this.#isOpen;
465
- this.#menuHidden.write(menu, "");
466
- if (this.hasRegionTarget) this.#regionState.write(this.regionTarget, "closed");
486
+ this.#openState = false;
487
+ if (this.#menu) this.#menuHidden.write(this.#menu, "");
488
+ this.#reflectRegion();
467
489
  if (was && this.#reporting) this.dispatch("close", { detail: { reason }, cancelable: false });
468
490
  }
469
491
  #adoptMenu() {
470
492
  if (!this.#connected) return;
471
493
  const menu = this.hasMenuTarget ? this.menuTarget : null;
472
494
  const previous = this.#menu;
473
- this.#menu = menu;
474
- if (!menu) {
475
- this.#escapeLayer.deactivate();
476
- } else if (menu !== previous) {
477
- const open = previous !== null && !previous.hidden;
478
- if (open) {
479
- for (const property of _ContextMenuController.#COORDINATE) {
480
- menu.style.setProperty(property, previous.style.getPropertyValue(property));
481
- }
495
+ if (previous) {
496
+ this.#openState = !previous.hidden;
497
+ if (this.#openState && menu !== previous) {
498
+ const [x, y] = _ContextMenuController.#COORDINATE;
499
+ this.#position = [previous.style.getPropertyValue(x), previous.style.getPropertyValue(y)];
482
500
  }
483
- this.#menuHidden.write(menu, open ? null : "");
501
+ }
502
+ this.#menu = menu;
503
+ if (!this.#openState) this.#escapeLayer.deactivate();
504
+ if (menu && menu !== previous) {
505
+ if (this.#openState) this.#showMenu(menu);
506
+ else this.#menuHidden.write(menu, "");
484
507
  }
485
508
  this.#reflectRegion();
486
509
  }
510
+ #showMenu(menu) {
511
+ const [x, y] = _ContextMenuController.#COORDINATE;
512
+ menu.style.setProperty(x, this.#position[0]);
513
+ menu.style.setProperty(y, this.#position[1]);
514
+ this.#menuHidden.write(menu, null);
515
+ }
487
516
  #reflectRegion() {
488
517
  if (!this.hasRegionTarget) return;
489
518
  this.#regionState.write(this.regionTarget, this.#isOpen ? "open" : "closed");
@@ -517,7 +546,7 @@ var ContextMenuController = class _ContextMenuController extends Controller {
517
546
  return !this.#isNavigable(item) || isAriaDisabled(item);
518
547
  }
519
548
  get #isOpen() {
520
- return this.hasMenuTarget && !this.menuTarget.hidden;
549
+ return this.#menu ? !this.#menu.hidden : this.#openState;
521
550
  }
522
551
  };
523
552
 
@@ -7,14 +7,15 @@ function fillTemplate(template, values) {
7
7
  });
8
8
  }
9
9
 
10
+ var afterFocus = /* @__PURE__ */ Symbol.for("stimeo--announcer:after-focus");
10
11
  function announce(message, options = {}) {
11
12
  const text = message.trim();
12
13
  if (text.length === 0) return;
13
- window.dispatchEvent(
14
- new CustomEvent("stimeo--announcer:announce", {
15
- detail: { message: text, assertive: options.assertive === true }
16
- })
17
- );
14
+ const event = new CustomEvent("stimeo--announcer:announce", {
15
+ detail: { message: text, assertive: options.assertive === true }
16
+ });
17
+ if (options.afterFocus) event[afterFocus] = true;
18
+ window.dispatchEvent(event);
18
19
  }
19
20
 
20
21
  var ListenerSet = class {
@@ -10,7 +10,50 @@ function isCompositionInputType(inputType) {
10
10
  return inputType !== void 0 && COMPOSITION_INPUT_TYPES.has(inputType);
11
11
  }
12
12
  var BEFORE_MORPH_ATTRIBUTE = "turbo:before-morph-attribute";
13
- var textOf = (element) => element.value;
13
+ var textOf = (element) => {
14
+ if ("value" in element) return element.value;
15
+ return element instanceof Element ? element.textContent : void 0;
16
+ };
17
+ var nodesOf = (element) => {
18
+ const nodes = [];
19
+ if ("value" in element || !(element instanceof Element)) return nodes;
20
+ const walker = element.ownerDocument.createTreeWalker(element);
21
+ for (let node = walker.nextNode(); node !== null; node = walker.nextNode()) nodes.push(node);
22
+ return nodes;
23
+ };
24
+ var folded = (text) => text.replaceAll("\xA0", " ");
25
+ var startOf = (node, data, replaced, caret) => {
26
+ const text = folded(node.data);
27
+ const composed = folded(data);
28
+ if (replaced?.startContainer === node && text.startsWith(composed, replaced.startOffset)) {
29
+ return replaced.startOffset;
30
+ }
31
+ const start = text.lastIndexOf(composed, caret);
32
+ return start !== -1 && start + composed.length >= caret ? start : -1;
33
+ };
34
+ var spotOf = (element, replaced, data) => {
35
+ if ("value" in element || !(element instanceof Element)) return null;
36
+ const selection = element.ownerDocument.getSelection();
37
+ const node = selection?.focusNode;
38
+ if (!(node instanceof Text) || node.data === "" || !element.contains(node)) return null;
39
+ const range = element.ownerDocument.createRange();
40
+ const start = typeof data === "string" && data !== "" ? startOf(node, data, replaced, selection?.focusOffset ?? 0) : -1;
41
+ if (start === -1) {
42
+ range.selectNodeContents(node);
43
+ } else {
44
+ range.setStart(node, start);
45
+ range.setEnd(node, start + data.length);
46
+ }
47
+ return range;
48
+ };
49
+ var replacedBy = (event) => typeof event.getTargetRanges === "function" ? event.getTargetRanges()[0] ?? null : null;
50
+ var rewritten = ({ element, text, nodes, spot }) => {
51
+ if (spot !== null) {
52
+ return spot.collapsed || !(element instanceof Node && element.contains(spot.startContainer));
53
+ }
54
+ const current = nodesOf(element);
55
+ return textOf(element) !== text || current.length !== nodes.length || current.some((node, index) => node !== nodes[index]);
56
+ };
14
57
  var holdsFocus = (element) => element instanceof Node && element.getRootNode().activeElement === element;
15
58
  var CompositionTracker = class {
16
59
  #observedTargets = /* @__PURE__ */ new Set();
@@ -71,7 +114,7 @@ var CompositionTracker = class {
71
114
  this.#confirmedTarget = null;
72
115
  if (confirmed === null || confirmed !== event.target) return false;
73
116
  const inputType = event.inputType;
74
- return !inputType || isCompositionInputType(inputType);
117
+ return inputType ? isCompositionInputType(inputType) : event.isTrusted === true;
75
118
  }
76
119
  #release(target) {
77
120
  target.removeEventListener("compositionstart", this.#handleStart);
@@ -101,11 +144,11 @@ var CompositionTracker = class {
101
144
  }
102
145
  #settle() {
103
146
  const composition = this.#composition;
104
- if (composition === null) return;
105
- const { target, element, text } = composition;
147
+ if (composition === null || !this.#observedTargets.has(composition.target)) return;
148
+ const { target, element } = composition;
106
149
  if (target instanceof Node && element instanceof Node && !target.contains(element)) {
107
150
  this.#composition = null;
108
- } else if (textOf(element) !== text) {
151
+ } else if (rewritten(composition)) {
109
152
  this.#abandon(false);
110
153
  }
111
154
  }
@@ -130,7 +173,14 @@ var CompositionTracker = class {
130
173
  this.#owe(true);
131
174
  const target = event.currentTarget;
132
175
  const element = event.target;
133
- this.#composition = { target, element, text: textOf(element) };
176
+ this.#composition = {
177
+ target,
178
+ element,
179
+ text: textOf(element),
180
+ nodes: nodesOf(element),
181
+ spot: spotOf(element, null, void 0),
182
+ replaced: null
183
+ };
134
184
  this.#runAbandon();
135
185
  this.#onStart?.(event);
136
186
  };
@@ -154,6 +204,10 @@ var CompositionTracker = class {
154
204
  if (this.#composition !== null && !keyComposing && !isComposing && inputType && !isCompositionInputType(inputType)) {
155
205
  this.#abandon(true);
156
206
  }
207
+ const composition = this.#composition;
208
+ if (composition !== null && event.target === composition.element) {
209
+ composition.replaced = replacedBy(event);
210
+ }
157
211
  this.#runAbandon();
158
212
  };
159
213
  #handleInput = (event) => {
@@ -161,6 +215,15 @@ var CompositionTracker = class {
161
215
  const { isTrusted, isComposing, inputType } = event;
162
216
  if (composition !== null && event.target === composition.element && (isTrusted || isComposing || isCompositionInputType(inputType))) {
163
217
  composition.text = textOf(composition.element);
218
+ composition.nodes = nodesOf(composition.element);
219
+ if (isCompositionInputType(inputType)) {
220
+ composition.spot = spotOf(
221
+ composition.element,
222
+ composition.replaced,
223
+ event.data
224
+ );
225
+ }
226
+ composition.replaced = null;
164
227
  } else {
165
228
  this.#settle();
166
229
  }
@@ -181,7 +244,9 @@ var CompositionTracker = class {
181
244
  const composition = this.#composition;
182
245
  if (composition?.target !== event.currentTarget || event.target !== composition.element) return;
183
246
  const detail = event.detail;
184
- if (detail?.attributeName === "value") event.preventDefault();
247
+ if (detail?.attributeName === "value" && "value" in composition.element) {
248
+ event.preventDefault();
249
+ }
185
250
  };
186
251
  };
187
252