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
@@ -41,6 +41,180 @@ function hasModifierChord(event) {
41
41
  return event.altKey || event.ctrlKey || event.metaKey || event.shiftKey;
42
42
  }
43
43
 
44
+ function setAttributeIfChanged(element, name, value, beforeWrite) {
45
+ if (element.getAttribute(name) === value) return false;
46
+ beforeWrite?.();
47
+ if (value === null) element.removeAttribute(name);
48
+ else element.setAttribute(name, value);
49
+ return true;
50
+ }
51
+
52
+ function sharedRegistry(key, create) {
53
+ const symbol = Symbol.for(key);
54
+ const scope = globalThis;
55
+ const existing = scope[symbol];
56
+ if (existing !== void 0) return existing;
57
+ const registry2 = create();
58
+ Object.defineProperty(globalThis, symbol, { value: registry2 });
59
+ return registry2;
60
+ }
61
+
62
+ var registry = sharedRegistry(
63
+ "stimeo-ui.attribute-lease.registry.v1",
64
+ () => ({ stacks: /* @__PURE__ */ new WeakMap(), names: /* @__PURE__ */ new Map() })
65
+ );
66
+ function isAttributeValue(value) {
67
+ return value === null || typeof value === "string";
68
+ }
69
+ function readLeaseRecord(element, record) {
70
+ try {
71
+ const parsed = JSON.parse(element.getAttribute(record) ?? "null");
72
+ if (!Array.isArray(parsed)) return void 0;
73
+ const [original, written, ...rest] = parsed;
74
+ const linked = rest[0] !== false;
75
+ const beneath = linked ? rest : rest.slice(1);
76
+ if (!beneath.every((under) => typeof under === "string")) return void 0;
77
+ return isAttributeValue(original) && isAttributeValue(written) ? { original, written, linked, beneath } : void 0;
78
+ } catch {
79
+ return void 0;
80
+ }
81
+ }
82
+ function attributeStack(element, attribute) {
83
+ const byAttribute = registry.stacks.get(element) ?? /* @__PURE__ */ new Map();
84
+ registry.stacks.set(element, byAttribute);
85
+ const known = byAttribute.get(attribute);
86
+ if (known) return known;
87
+ const found = [];
88
+ for (const record of registry.names.get(attribute) ?? []) {
89
+ const read = readLeaseRecord(element, record);
90
+ if (read) found.push({ ...read, record });
91
+ }
92
+ const depth = ({ beneath }) => beneath.filter((name) => found.some((other) => other.record === name)).length;
93
+ const stack = found.sort((one, other) => depth(one) - depth(other)).map(({ record, written, original, linked }, index) => ({
94
+ lease: null,
95
+ record,
96
+ written,
97
+ original,
98
+ linked: linked && index > 0
99
+ }));
100
+ byAttribute.set(attribute, stack);
101
+ return stack;
102
+ }
103
+ function findHold(stack, lease, record) {
104
+ return stack.find((held) => held.lease === lease) ?? stack.find((held) => held.lease === null && held.record === record);
105
+ }
106
+ var AttributeLease = class {
107
+ #attribute;
108
+ #record;
109
+ #base;
110
+ #preserveAuthor;
111
+ #held = /* @__PURE__ */ new Set();
112
+ constructor(attribute, owner, options = {}) {
113
+ this.#attribute = attribute;
114
+ this.#record = `data-${owner}-${attribute}-lease`;
115
+ this.#base = options.base === true;
116
+ this.#preserveAuthor = options.preserveAuthor === true;
117
+ const names = registry.names;
118
+ names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
119
+ }
120
+ write(element, value, beforeWrite) {
121
+ const stack = attributeStack(element, this.#attribute);
122
+ const hold = this.#take(stack) ?? this.#acquire(element, stack);
123
+ this.#held.add(element);
124
+ const shows = !this.#covered(element, stack, hold);
125
+ hold.written = value;
126
+ this.#mark(element, stack);
127
+ if (shows) this.#reflect(element, value, beforeWrite);
128
+ }
129
+ adopt(element, options = {}) {
130
+ const known = registry.stacks.get(element)?.has(this.#attribute);
131
+ if (!this.#held.has(element) && !known && !element.hasAttribute(this.#record)) return false;
132
+ const stack = attributeStack(element, this.#attribute);
133
+ const hold = this.#take(stack);
134
+ if (!hold) return false;
135
+ const current = element.getAttribute(this.#attribute);
136
+ if (options.ifChanged && (current === hold.written || this.#covered(element, stack, hold))) {
137
+ return false;
138
+ }
139
+ this.#held.add(element);
140
+ hold.original = current;
141
+ hold.linked = false;
142
+ for (const above of stack.slice(stack.indexOf(hold) + 1)) {
143
+ if (!above.linked) break;
144
+ above.original = current;
145
+ }
146
+ this.#mark(element, stack);
147
+ return true;
148
+ }
149
+ return(element) {
150
+ const held = this.#held.delete(element);
151
+ const known = registry.stacks.get(element)?.has(this.#attribute);
152
+ const stack = held || known || element.hasAttribute(this.#record) ? attributeStack(element, this.#attribute) : [];
153
+ const hold = this.#take(stack);
154
+ if (!hold) return false;
155
+ const carries = element.getAttribute(this.#attribute) === hold.written;
156
+ const owns = carries && !this.#covered(element, stack, hold);
157
+ const index = stack.indexOf(hold);
158
+ stack.splice(index, 1);
159
+ const above = stack[index];
160
+ if (above) above.linked &&= hold.linked;
161
+ this.#mark(element, stack);
162
+ if (!owns) return true;
163
+ const below = hold.linked ? stack[index - 1] : void 0;
164
+ this.#reflect(element, below ? below.written : hold.original);
165
+ return true;
166
+ }
167
+ returnAll() {
168
+ for (const element of Array.from(this.#held)) this.return(element);
169
+ }
170
+ #take(stack) {
171
+ const hold = findHold(stack, this, this.#record);
172
+ if (hold) hold.lease = this;
173
+ return hold;
174
+ }
175
+ #acquire(element, stack) {
176
+ const current = element.getAttribute(this.#attribute);
177
+ const top = stack.at(-1);
178
+ const bottom = stack[0];
179
+ const over = top?.written === current ? top : void 0;
180
+ const from = this.#base ? this.#preserveAuthor && !stack.some((held) => held.written === current) ? void 0 : bottom : over;
181
+ const hold = {
182
+ lease: this,
183
+ record: this.#record,
184
+ written: current,
185
+ original: from ? from.original : current,
186
+ linked: !this.#base && over !== void 0
187
+ };
188
+ if (this.#base && bottom) {
189
+ bottom.linked = true;
190
+ stack.unshift(hold);
191
+ } else stack.push(hold);
192
+ return hold;
193
+ }
194
+ #covered(element, stack, hold) {
195
+ const current = element.getAttribute(this.#attribute);
196
+ return stack.slice(stack.indexOf(hold) + 1).some((above) => above.written === current);
197
+ }
198
+ #mark(element, stack) {
199
+ const records = /* @__PURE__ */ new Map([[this.#record, null]]);
200
+ stack.forEach((hold, index) => {
201
+ const names = stack.slice(0, index).map((under) => under.record);
202
+ const beneath = [...new Set(names.reverse())].filter((name) => name !== hold.record);
203
+ const marker = hold.linked || beneath.length === 0 ? [] : [false];
204
+ records.set(
205
+ hold.record,
206
+ hold.written === hold.original && beneath.length === 0 && index === stack.length - 1 ? null : JSON.stringify([hold.original, hold.written, ...marker, ...beneath])
207
+ );
208
+ });
209
+ for (const [name, recorded] of records) {
210
+ setAttributeIfChanged(element, name, recorded);
211
+ }
212
+ }
213
+ #reflect(element, value, beforeWrite) {
214
+ setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
215
+ }
216
+ };
217
+
44
218
  function parseDeclared(raw, parse, fallback) {
45
219
  try {
46
220
  return parse(raw);
@@ -132,8 +306,12 @@ var MorphRenderWatcher = class {
132
306
 
133
307
  var RovingTabindex = class {
134
308
  #getItems;
135
- constructor(getItems) {
309
+ #write;
310
+ constructor(getItems, write = (item, tabindex) => {
311
+ item.tabIndex = tabindex;
312
+ }) {
136
313
  this.#getItems = getItems;
314
+ this.#write = write;
137
315
  }
138
316
  get activeIndex() {
139
317
  return this.#getItems().findIndex((item) => item.tabIndex === 0);
@@ -142,7 +320,7 @@ var RovingTabindex = class {
142
320
  const { focus = false } = options;
143
321
  const items = options.items ?? this.#getItems();
144
322
  items.forEach((item, i) => {
145
- item.tabIndex = i === index ? 0 : -1;
323
+ this.#write(item, i === index ? 0 : -1);
146
324
  });
147
325
  if (focus) items[index]?.focus();
148
326
  }
@@ -191,7 +369,12 @@ var ThemeController = class extends Controller {
191
369
  #connected = false;
192
370
  #targetSelector = DEFAULT_TARGET;
193
371
  #storageKeyRead = null;
194
- #roving = new RovingTabindex(() => this.optionTargets);
372
+ #checked = new AttributeLease("aria-checked", this.identifier);
373
+ #tabindex = new AttributeLease("tabindex", this.identifier);
374
+ #roving = new RovingTabindex(
375
+ () => this.optionTargets,
376
+ (option, tabindex) => this.#tabindex.write(option, String(tabindex))
377
+ );
195
378
  #published = {
196
379
  mode: DEFAULT_MODE,
197
380
  resolved: "light"
@@ -279,7 +462,11 @@ var ThemeController = class extends Controller {
279
462
  optionTargetConnected() {
280
463
  if (this.#connected) this.#morph.schedule();
281
464
  }
282
- optionTargetDisconnected() {
465
+ optionTargetDisconnected(option) {
466
+ if (!this.optionTargets.includes(option)) {
467
+ this.#checked.return(option);
468
+ this.#tabindex.return(option);
469
+ }
283
470
  if (this.#connected) this.#morph.schedule();
284
471
  }
285
472
  set(source) {
@@ -336,7 +523,7 @@ var ThemeController = class extends Controller {
336
523
  let selected = -1;
337
524
  options.forEach((option, index) => {
338
525
  const isSelected = this.#optionMode(option) === mode;
339
- option.setAttribute("aria-checked", String(isSelected));
526
+ this.#checked.write(option, String(isSelected));
340
527
  if (isSelected && selected === -1) selected = index;
341
528
  });
342
529
  this.#roving.setActive(selected === -1 ? 0 : selected, { items: options });
@@ -27,43 +27,66 @@ function setAttributeIfChanged(element, name, value, beforeWrite) {
27
27
 
28
28
  var AuthoredMutationWatcher = class {
29
29
  #onAuthored;
30
- #claims = null;
31
- #observer = null;
30
+ #lifetime = null;
32
31
  constructor(onAuthored) {
33
32
  this.#onAuthored = onAuthored;
34
33
  }
35
34
  observe(root, options) {
36
- this.disconnect();
37
- const observer = new MutationObserver((records) => {
38
- if (this.#observer !== observer) return;
39
- const authored = this.#filter(records);
40
- if (authored.length > 0) this.#onAuthored(authored);
41
- });
42
- this.#observer = observer;
43
- this.#claims = { attributes: /* @__PURE__ */ new Map(), children: /* @__PURE__ */ new Map() };
44
- observer.observe(root, {
45
- attributes: true,
46
- attributeFilter: [...options.attributes],
47
- subtree: options.subtree ?? false,
48
- childList: options.childList ?? false
49
- });
50
- if (options.ancestorAttributes) {
51
- let ancestor = root.parentElement;
52
- while (ancestor) {
53
- observer.observe(ancestor, {
54
- attributes: true,
55
- attributeFilter: [...options.ancestorAttributes]
56
- });
57
- ancestor = ancestor.parentElement;
35
+ const previous = this.#lifetime;
36
+ const lifetime = {
37
+ observer: null,
38
+ active: false,
39
+ claims: { attributes: /* @__PURE__ */ new Map(), children: /* @__PURE__ */ new Map() }
40
+ };
41
+ this.#lifetime = lifetime;
42
+ let observer = null;
43
+ try {
44
+ if (previous) this.#release(previous);
45
+ if (this.#lifetime !== lifetime) return;
46
+ const attributes = [...options.attributes];
47
+ const subtree = options.subtree ?? false;
48
+ const childList = options.childList ?? false;
49
+ const inherited = options.ancestorAttributes;
50
+ const ancestorAttributes = inherited ? [...inherited] : null;
51
+ if (this.#lifetime !== lifetime) return;
52
+ observer = new MutationObserver((records) => {
53
+ const authored = this.#filter(records, lifetime.claims);
54
+ if (this.#lifetime === lifetime && lifetime.active && authored.length > 0) {
55
+ this.#onAuthored(authored);
56
+ }
57
+ });
58
+ if (this.#lifetime !== lifetime) return;
59
+ lifetime.observer = observer;
60
+ observer.observe(root, { attributes: true, attributeFilter: attributes, subtree, childList });
61
+ if (this.#lifetime !== lifetime) {
62
+ this.#release(lifetime, observer);
63
+ return;
64
+ }
65
+ if (ancestorAttributes) {
66
+ let ancestor = root.parentElement;
67
+ while (ancestor) {
68
+ observer.observe(ancestor, { attributes: true, attributeFilter: ancestorAttributes });
69
+ if (this.#lifetime !== lifetime) {
70
+ this.#release(lifetime, observer);
71
+ return;
72
+ }
73
+ ancestor = ancestor.parentElement;
74
+ }
58
75
  }
76
+ lifetime.active = true;
77
+ } catch (error) {
78
+ this.#release(lifetime, observer);
79
+ throw error;
59
80
  }
60
81
  }
61
82
  claim(target, name, value) {
62
- const claims = this.#claims?.attributes;
63
- let attributes = claims?.get(target);
83
+ const lifetime = this.#lifetime;
84
+ if (!lifetime?.active) return;
85
+ const claims = lifetime.claims.attributes;
86
+ let attributes = claims.get(target);
64
87
  if (!attributes) {
65
88
  attributes = /* @__PURE__ */ new Map();
66
- claims?.set(target, attributes);
89
+ claims.set(target, attributes);
67
90
  }
68
91
  const pending = attributes.get(name);
69
92
  attributes.set(name, { value, count: (pending?.count ?? 0) + 1 });
@@ -72,37 +95,49 @@ var AuthoredMutationWatcher = class {
72
95
  this.claim(target, name, target.getAttribute(name));
73
96
  }
74
97
  claimChildList(target, added, removed) {
75
- const claims = this.#claims?.children;
76
- const pending = claims?.get(target) ?? { added: /* @__PURE__ */ new Map(), removed: /* @__PURE__ */ new Map() };
98
+ const lifetime = this.#lifetime;
99
+ if (!lifetime?.active) return;
100
+ const claims = lifetime.claims.children;
101
+ const pending = claims.get(target) ?? { added: /* @__PURE__ */ new Map(), removed: /* @__PURE__ */ new Map() };
77
102
  for (const node of added) pending.added.set(node, (pending.added.get(node) ?? 0) + 1);
78
103
  for (const node of removed) pending.removed.set(node, (pending.removed.get(node) ?? 0) + 1);
79
- claims?.set(target, pending);
104
+ claims.set(target, pending);
80
105
  }
81
106
  take() {
82
- return this.#filter(this.#observer?.takeRecords() ?? []);
107
+ const lifetime = this.#lifetime;
108
+ const observer = lifetime?.observer;
109
+ if (!lifetime?.active || !observer) return [];
110
+ const records = observer.takeRecords();
111
+ const authored = this.#filter(records, lifetime.claims);
112
+ return this.#lifetime === lifetime && lifetime.active ? authored : [];
83
113
  }
84
114
  disconnect() {
85
- this.#observer?.disconnect();
86
- this.#observer = null;
87
- this.#claims = null;
88
- }
89
- #filter(records) {
90
- const authored = records.filter((record) => !this.#consume(record));
91
- this.#claims?.attributes.clear();
92
- this.#claims?.children.clear();
115
+ const lifetime = this.#lifetime;
116
+ if (lifetime) this.#release(lifetime);
117
+ }
118
+ #release(lifetime, observer = lifetime.observer) {
119
+ if (this.#lifetime === lifetime) this.#lifetime = null;
120
+ lifetime.claims.attributes.clear();
121
+ lifetime.claims.children.clear();
122
+ observer?.disconnect();
123
+ }
124
+ #filter(records, claims) {
125
+ const authored = records.filter((record) => !this.#consume(record, claims));
126
+ claims.attributes.clear();
127
+ claims.children.clear();
93
128
  return authored;
94
129
  }
95
- #consume(record) {
130
+ #consume(record, claims) {
96
131
  if (record.type === "attributes") {
97
132
  const target = record.target;
98
- const pending2 = this.#claims?.attributes.get(target)?.get(record.attributeName);
133
+ const pending2 = claims.attributes.get(target)?.get(record.attributeName);
99
134
  if (!pending2 || pending2.count === 0 || target.getAttribute(record.attributeName) !== pending2.value) {
100
135
  return false;
101
136
  }
102
137
  pending2.count -= 1;
103
138
  return true;
104
139
  }
105
- const pending = this.#claims?.children.get(record.target);
140
+ const pending = claims.children.get(record.target);
106
141
  if (!pending) return false;
107
142
  const added = [...record.addedNodes];
108
143
  const removed = [...record.removedNodes];