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
@@ -22,6 +22,180 @@ function actionSource(source) {
22
22
  };
23
23
  }
24
24
 
25
+ function setAttributeIfChanged(element, name, value, beforeWrite) {
26
+ if (element.getAttribute(name) === value) return false;
27
+ beforeWrite?.();
28
+ if (value === null) element.removeAttribute(name);
29
+ else element.setAttribute(name, value);
30
+ return true;
31
+ }
32
+
33
+ function sharedRegistry(key, create) {
34
+ const symbol = Symbol.for(key);
35
+ const scope = globalThis;
36
+ const existing = scope[symbol];
37
+ if (existing !== void 0) return existing;
38
+ const registry2 = create();
39
+ Object.defineProperty(globalThis, symbol, { value: registry2 });
40
+ return registry2;
41
+ }
42
+
43
+ var registry = sharedRegistry(
44
+ "stimeo-ui.attribute-lease.registry.v1",
45
+ () => ({ stacks: /* @__PURE__ */ new WeakMap(), names: /* @__PURE__ */ new Map() })
46
+ );
47
+ function isAttributeValue(value) {
48
+ return value === null || typeof value === "string";
49
+ }
50
+ function readLeaseRecord(element, record) {
51
+ try {
52
+ const parsed = JSON.parse(element.getAttribute(record) ?? "null");
53
+ if (!Array.isArray(parsed)) return void 0;
54
+ const [original, written, ...rest] = parsed;
55
+ const linked = rest[0] !== false;
56
+ const beneath = linked ? rest : rest.slice(1);
57
+ if (!beneath.every((under) => typeof under === "string")) return void 0;
58
+ return isAttributeValue(original) && isAttributeValue(written) ? { original, written, linked, beneath } : void 0;
59
+ } catch {
60
+ return void 0;
61
+ }
62
+ }
63
+ function attributeStack(element, attribute) {
64
+ const byAttribute = registry.stacks.get(element) ?? /* @__PURE__ */ new Map();
65
+ registry.stacks.set(element, byAttribute);
66
+ const known = byAttribute.get(attribute);
67
+ if (known) return known;
68
+ const found = [];
69
+ for (const record of registry.names.get(attribute) ?? []) {
70
+ const read = readLeaseRecord(element, record);
71
+ if (read) found.push({ ...read, record });
72
+ }
73
+ const depth = ({ beneath }) => beneath.filter((name) => found.some((other) => other.record === name)).length;
74
+ const stack = found.sort((one, other) => depth(one) - depth(other)).map(({ record, written, original, linked }, index) => ({
75
+ lease: null,
76
+ record,
77
+ written,
78
+ original,
79
+ linked: linked && index > 0
80
+ }));
81
+ byAttribute.set(attribute, stack);
82
+ return stack;
83
+ }
84
+ function findHold(stack, lease, record) {
85
+ return stack.find((held) => held.lease === lease) ?? stack.find((held) => held.lease === null && held.record === record);
86
+ }
87
+ var AttributeLease = class {
88
+ #attribute;
89
+ #record;
90
+ #base;
91
+ #preserveAuthor;
92
+ #held = /* @__PURE__ */ new Set();
93
+ constructor(attribute, owner, options = {}) {
94
+ this.#attribute = attribute;
95
+ this.#record = `data-${owner}-${attribute}-lease`;
96
+ this.#base = options.base === true;
97
+ this.#preserveAuthor = options.preserveAuthor === true;
98
+ const names = registry.names;
99
+ names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
100
+ }
101
+ write(element, value, beforeWrite) {
102
+ const stack = attributeStack(element, this.#attribute);
103
+ const hold = this.#take(stack) ?? this.#acquire(element, stack);
104
+ this.#held.add(element);
105
+ const shows = !this.#covered(element, stack, hold);
106
+ hold.written = value;
107
+ this.#mark(element, stack);
108
+ if (shows) this.#reflect(element, value, beforeWrite);
109
+ }
110
+ adopt(element, options = {}) {
111
+ const known = registry.stacks.get(element)?.has(this.#attribute);
112
+ if (!this.#held.has(element) && !known && !element.hasAttribute(this.#record)) return false;
113
+ const stack = attributeStack(element, this.#attribute);
114
+ const hold = this.#take(stack);
115
+ if (!hold) return false;
116
+ const current = element.getAttribute(this.#attribute);
117
+ if (options.ifChanged && (current === hold.written || this.#covered(element, stack, hold))) {
118
+ return false;
119
+ }
120
+ this.#held.add(element);
121
+ hold.original = current;
122
+ hold.linked = false;
123
+ for (const above of stack.slice(stack.indexOf(hold) + 1)) {
124
+ if (!above.linked) break;
125
+ above.original = current;
126
+ }
127
+ this.#mark(element, stack);
128
+ return true;
129
+ }
130
+ return(element) {
131
+ const held = this.#held.delete(element);
132
+ const known = registry.stacks.get(element)?.has(this.#attribute);
133
+ const stack = held || known || element.hasAttribute(this.#record) ? attributeStack(element, this.#attribute) : [];
134
+ const hold = this.#take(stack);
135
+ if (!hold) return false;
136
+ const carries = element.getAttribute(this.#attribute) === hold.written;
137
+ const owns = carries && !this.#covered(element, stack, hold);
138
+ const index = stack.indexOf(hold);
139
+ stack.splice(index, 1);
140
+ const above = stack[index];
141
+ if (above) above.linked &&= hold.linked;
142
+ this.#mark(element, stack);
143
+ if (!owns) return true;
144
+ const below = hold.linked ? stack[index - 1] : void 0;
145
+ this.#reflect(element, below ? below.written : hold.original);
146
+ return true;
147
+ }
148
+ returnAll() {
149
+ for (const element of Array.from(this.#held)) this.return(element);
150
+ }
151
+ #take(stack) {
152
+ const hold = findHold(stack, this, this.#record);
153
+ if (hold) hold.lease = this;
154
+ return hold;
155
+ }
156
+ #acquire(element, stack) {
157
+ const current = element.getAttribute(this.#attribute);
158
+ const top = stack.at(-1);
159
+ const bottom = stack[0];
160
+ const over = top?.written === current ? top : void 0;
161
+ const from = this.#base ? this.#preserveAuthor && !stack.some((held) => held.written === current) ? void 0 : bottom : over;
162
+ const hold = {
163
+ lease: this,
164
+ record: this.#record,
165
+ written: current,
166
+ original: from ? from.original : current,
167
+ linked: !this.#base && over !== void 0
168
+ };
169
+ if (this.#base && bottom) {
170
+ bottom.linked = true;
171
+ stack.unshift(hold);
172
+ } else stack.push(hold);
173
+ return hold;
174
+ }
175
+ #covered(element, stack, hold) {
176
+ const current = element.getAttribute(this.#attribute);
177
+ return stack.slice(stack.indexOf(hold) + 1).some((above) => above.written === current);
178
+ }
179
+ #mark(element, stack) {
180
+ const records = /* @__PURE__ */ new Map([[this.#record, null]]);
181
+ stack.forEach((hold, index) => {
182
+ const names = stack.slice(0, index).map((under) => under.record);
183
+ const beneath = [...new Set(names.reverse())].filter((name) => name !== hold.record);
184
+ const marker = hold.linked || beneath.length === 0 ? [] : [false];
185
+ records.set(
186
+ hold.record,
187
+ hold.written === hold.original && beneath.length === 0 && index === stack.length - 1 ? null : JSON.stringify([hold.original, hold.written, ...marker, ...beneath])
188
+ );
189
+ });
190
+ for (const [name, recorded] of records) {
191
+ setAttributeIfChanged(element, name, recorded);
192
+ }
193
+ }
194
+ #reflect(element, value, beforeWrite) {
195
+ setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
196
+ }
197
+ };
198
+
25
199
  function parseDeclared(raw, parse, fallback) {
26
200
  try {
27
201
  return parse(raw);
@@ -311,6 +485,7 @@ var ScrollspyController = class _ScrollspyController extends Controller {
311
485
  return this.#safeOffset;
312
486
  }
313
487
  #watcher = new IntersectionWatcher((entries) => this.#onIntersection(entries));
488
+ #current = new AttributeLease("aria-current", this.identifier);
314
489
  #isConnected = false;
315
490
  #intersectionStates = /* @__PURE__ */ new Map();
316
491
  #activeSectionId = "";
@@ -360,7 +535,8 @@ var ScrollspyController = class _ScrollspyController extends Controller {
360
535
  linkTargetConnected() {
361
536
  if (this.#isConnected) this.#scheduleResync();
362
537
  }
363
- linkTargetDisconnected() {
538
+ linkTargetDisconnected(link) {
539
+ if (!this.linkTargets.includes(link)) this.#current.return(link);
364
540
  if (this.#isConnected) this.#scheduleResync();
365
541
  }
366
542
  #scheduleResync() {
@@ -509,9 +685,9 @@ var ScrollspyController = class _ScrollspyController extends Controller {
509
685
  );
510
686
  for (const link of this.linkTargets) {
511
687
  if (activeLinks.includes(link)) {
512
- link.setAttribute("aria-current", "location");
688
+ this.#current.write(link, "location");
513
689
  } else if (link.getAttribute("aria-current") === "location") {
514
- link.removeAttribute("aria-current");
690
+ this.#current.write(link, null);
515
691
  }
516
692
  }
517
693
  if (!announce) return;
@@ -10,6 +10,7 @@ function hasModifierChord(event) {
10
10
 
11
11
  function setAttributeIfChanged(element, name, value, beforeWrite) {
12
12
  if (element.getAttribute(name) === value) return false;
13
+ beforeWrite?.();
13
14
  if (value === null) element.removeAttribute(name);
14
15
  else element.setAttribute(name, value);
15
16
  return true;
@@ -83,14 +84,34 @@ var AttributeLease = class {
83
84
  const names = registry.names;
84
85
  names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
85
86
  }
86
- write(element, value) {
87
+ write(element, value, beforeWrite) {
87
88
  const stack = attributeStack(element, this.#attribute);
88
89
  const hold = this.#take(stack) ?? this.#acquire(element, stack);
89
90
  this.#held.add(element);
90
91
  const shows = !this.#covered(element, stack, hold);
91
92
  hold.written = value;
92
93
  this.#mark(element, stack);
93
- if (shows) this.#reflect(element, value);
94
+ if (shows) this.#reflect(element, value, beforeWrite);
95
+ }
96
+ adopt(element, options = {}) {
97
+ const known = registry.stacks.get(element)?.has(this.#attribute);
98
+ if (!this.#held.has(element) && !known && !element.hasAttribute(this.#record)) return false;
99
+ const stack = attributeStack(element, this.#attribute);
100
+ const hold = this.#take(stack);
101
+ if (!hold) return false;
102
+ const current = element.getAttribute(this.#attribute);
103
+ if (options.ifChanged && (current === hold.written || this.#covered(element, stack, hold))) {
104
+ return false;
105
+ }
106
+ this.#held.add(element);
107
+ hold.original = current;
108
+ hold.linked = false;
109
+ for (const above of stack.slice(stack.indexOf(hold) + 1)) {
110
+ if (!above.linked) break;
111
+ above.original = current;
112
+ }
113
+ this.#mark(element, stack);
114
+ return true;
94
115
  }
95
116
  return(element) {
96
117
  const held = this.#held.delete(element);
@@ -156,8 +177,8 @@ var AttributeLease = class {
156
177
  setAttributeIfChanged(element, name, recorded);
157
178
  }
158
179
  }
159
- #reflect(element, value) {
160
- setAttributeIfChanged(element, this.#attribute, value);
180
+ #reflect(element, value, beforeWrite) {
181
+ setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
161
182
  }
162
183
  };
163
184