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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +54 -0
- data/dist/cable/index.js +6 -5
- data/dist/controllers/alert_dialog_controller.js +324 -76
- data/dist/controllers/announcer_controller.js +22 -9
- data/dist/controllers/auto_submit_controller.js +103 -16
- data/dist/controllers/avatar_controller.js +29 -9
- data/dist/controllers/breadcrumb_controller.js +205 -17
- data/dist/controllers/bulk_select_controller.js +31 -13
- data/dist/controllers/calendar_controller.js +242 -7
- data/dist/controllers/carousel_controller.js +70 -15
- data/dist/controllers/character_counter_controller.js +103 -16
- data/dist/controllers/clipboard_controller.js +6 -5
- data/dist/controllers/collapsible_controller.js +35 -8
- data/dist/controllers/combobox_controller.js +155 -26
- data/dist/controllers/command_palette_controller.js +445 -117
- data/dist/controllers/conditional_fields_controller.js +84 -44
- data/dist/controllers/confirm_controller.js +303 -68
- data/dist/controllers/context_menu_controller.js +59 -30
- data/dist/controllers/countdown_controller.js +6 -5
- data/dist/controllers/currency_input_controller.js +72 -7
- data/dist/controllers/data_grid_controller.js +273 -51
- data/dist/controllers/date_range_picker_controller.js +27 -5
- data/dist/controllers/dialog_controller.js +330 -79
- data/dist/controllers/direct_upload_controller.js +6 -5
- data/dist/controllers/dismissible_controller.js +68 -18
- data/dist/controllers/drawer_controller.js +362 -92
- data/dist/controllers/dropdown_controller.js +64 -52
- data/dist/controllers/editable_controller.js +140 -12
- data/dist/controllers/empty_state_controller.js +193 -9
- data/dist/controllers/file_dropzone_controller.js +313 -23
- data/dist/controllers/filter_controller.js +194 -5
- data/dist/controllers/flash_controller.js +205 -17
- data/dist/controllers/focus_controller.js +273 -57
- data/dist/controllers/form_field_controller.js +71 -14
- data/dist/controllers/form_validation_controller.js +11 -7
- data/dist/controllers/frame_loading_controller.js +75 -20
- data/dist/controllers/hover_card_controller.js +108 -39
- data/dist/controllers/input_mask_controller.js +95 -37
- data/dist/controllers/intersection_controller.js +61 -29
- data/dist/controllers/lazy_frame_controller.js +61 -29
- data/dist/controllers/listbox_controller.js +174 -83
- data/dist/controllers/local_time_controller.js +1 -7
- data/dist/controllers/menu_controller.js +45 -24
- data/dist/controllers/menubar_controller.js +232 -52
- data/dist/controllers/meter_controller.js +31 -9
- data/dist/controllers/multi_select_controller.js +195 -62
- data/dist/controllers/navigation_menu_controller.js +1 -1
- data/dist/controllers/nested_form_controller.js +275 -21
- data/dist/controllers/network_status_controller.js +31 -9
- data/dist/controllers/number_input_controller.js +180 -71
- data/dist/controllers/otp_controller.js +97 -11
- data/dist/controllers/overflow_menu_controller.js +190 -24
- data/dist/controllers/pagination_controller.js +186 -24
- data/dist/controllers/password_reveal_controller.js +25 -4
- data/dist/controllers/password_strength_controller.js +6 -5
- data/dist/controllers/popover_controller.js +466 -42
- data/dist/controllers/progress_controller.js +31 -9
- data/dist/controllers/radio_group_controller.js +279 -88
- data/dist/controllers/range_slider_controller.js +72 -54
- data/dist/controllers/rating_controller.js +58 -10
- data/dist/controllers/read_more_controller.js +191 -25
- data/dist/controllers/relative_time_controller.js +1 -7
- data/dist/controllers/roving_controller.js +204 -8
- data/dist/controllers/scroll_area_controller.js +61 -19
- data/dist/controllers/scroll_visibility_controller.js +25 -4
- data/dist/controllers/scrollspy_controller.js +240 -32
- data/dist/controllers/separator_controller.js +97 -58
- data/dist/controllers/sidebar_controller.js +368 -127
- data/dist/controllers/skeleton_controller.js +75 -20
- data/dist/controllers/slider_controller.js +72 -54
- data/dist/controllers/sortable_controller.js +6 -5
- data/dist/controllers/spinner_controller.js +75 -20
- data/dist/controllers/step_indicator_controller.js +181 -6
- data/dist/controllers/stepper_controller.js +188 -6
- data/dist/controllers/sticky_observer_controller.js +86 -33
- data/dist/controllers/submit_once_controller.js +31 -9
- data/dist/controllers/switch_controller.js +84 -44
- data/dist/controllers/tabs_controller.js +189 -3
- data/dist/controllers/tags_input_controller.js +293 -29
- data/dist/controllers/theme_controller.js +192 -5
- data/dist/controllers/time_picker_controller.js +77 -42
- data/dist/controllers/toast_controller.js +478 -16
- data/dist/controllers/toggle_group_controller.js +282 -79
- data/dist/controllers/toolbar_controller.js +276 -15
- data/dist/controllers/tooltip_controller.js +244 -46
- data/dist/controllers/tree_view_controller.js +287 -57
- data/dist/index.js +2258 -1016
- data/lib/stimeo/ui/version.rb +1 -1
- metadata +2 -2
|
@@ -2,6 +2,7 @@ import { Controller } from '@hotwired/stimulus';
|
|
|
2
2
|
|
|
3
3
|
function setAttributeIfChanged(element, name, value, beforeWrite) {
|
|
4
4
|
if (element.getAttribute(name) === value) return false;
|
|
5
|
+
beforeWrite?.();
|
|
5
6
|
if (value === null) element.removeAttribute(name);
|
|
6
7
|
else element.setAttribute(name, value);
|
|
7
8
|
return true;
|
|
@@ -75,14 +76,34 @@ var AttributeLease = class {
|
|
|
75
76
|
const names = registry.names;
|
|
76
77
|
names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
|
|
77
78
|
}
|
|
78
|
-
write(element, value) {
|
|
79
|
+
write(element, value, beforeWrite) {
|
|
79
80
|
const stack = attributeStack(element, this.#attribute);
|
|
80
81
|
const hold = this.#take(stack) ?? this.#acquire(element, stack);
|
|
81
82
|
this.#held.add(element);
|
|
82
83
|
const shows = !this.#covered(element, stack, hold);
|
|
83
84
|
hold.written = value;
|
|
84
85
|
this.#mark(element, stack);
|
|
85
|
-
if (shows) this.#reflect(element, value);
|
|
86
|
+
if (shows) this.#reflect(element, value, beforeWrite);
|
|
87
|
+
}
|
|
88
|
+
adopt(element, options = {}) {
|
|
89
|
+
const known = registry.stacks.get(element)?.has(this.#attribute);
|
|
90
|
+
if (!this.#held.has(element) && !known && !element.hasAttribute(this.#record)) return false;
|
|
91
|
+
const stack = attributeStack(element, this.#attribute);
|
|
92
|
+
const hold = this.#take(stack);
|
|
93
|
+
if (!hold) return false;
|
|
94
|
+
const current = element.getAttribute(this.#attribute);
|
|
95
|
+
if (options.ifChanged && (current === hold.written || this.#covered(element, stack, hold))) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
this.#held.add(element);
|
|
99
|
+
hold.original = current;
|
|
100
|
+
hold.linked = false;
|
|
101
|
+
for (const above of stack.slice(stack.indexOf(hold) + 1)) {
|
|
102
|
+
if (!above.linked) break;
|
|
103
|
+
above.original = current;
|
|
104
|
+
}
|
|
105
|
+
this.#mark(element, stack);
|
|
106
|
+
return true;
|
|
86
107
|
}
|
|
87
108
|
return(element) {
|
|
88
109
|
const held = this.#held.delete(element);
|
|
@@ -148,8 +169,8 @@ var AttributeLease = class {
|
|
|
148
169
|
setAttributeIfChanged(element, name, recorded);
|
|
149
170
|
}
|
|
150
171
|
}
|
|
151
|
-
#reflect(element, value) {
|
|
152
|
-
setAttributeIfChanged(element, this.#attribute, value);
|
|
172
|
+
#reflect(element, value, beforeWrite) {
|
|
173
|
+
setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
|
|
153
174
|
}
|
|
154
175
|
};
|
|
155
176
|
|
|
@@ -166,6 +187,7 @@ var EscapeLayer = class _EscapeLayer {
|
|
|
166
187
|
);
|
|
167
188
|
#active = null;
|
|
168
189
|
activate(ownerDocument = document, options) {
|
|
190
|
+
const entry = { onDismiss: options.onDismiss, claims: options.claims ?? null };
|
|
169
191
|
this.deactivate();
|
|
170
192
|
let registry2 = _EscapeLayer.#registries.get(ownerDocument);
|
|
171
193
|
if (!registry2) {
|
|
@@ -173,7 +195,6 @@ var EscapeLayer = class _EscapeLayer {
|
|
|
173
195
|
_EscapeLayer.#registries.set(ownerDocument, registry2);
|
|
174
196
|
ownerDocument.addEventListener("keydown", registry2.onKeydown);
|
|
175
197
|
}
|
|
176
|
-
const entry = { onDismiss: options.onDismiss, claims: options.claims ?? null };
|
|
177
198
|
registry2.stack.push(entry);
|
|
178
199
|
this.#active = { document: ownerDocument, entry };
|
|
179
200
|
}
|
|
@@ -222,11 +243,16 @@ var EscapeLayer = class _EscapeLayer {
|
|
|
222
243
|
}
|
|
223
244
|
};
|
|
224
245
|
|
|
246
|
+
var HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
|
|
225
247
|
function inheritsFieldsetDisabled(control) {
|
|
226
248
|
let fieldset = control.closest("fieldset[disabled]");
|
|
227
249
|
while (fieldset) {
|
|
228
|
-
|
|
229
|
-
|
|
250
|
+
if (fieldset.namespaceURI === HTML_NAMESPACE && fieldset.localName === "fieldset") {
|
|
251
|
+
const legend = Array.from(fieldset.children).find(
|
|
252
|
+
(child) => child.namespaceURI === HTML_NAMESPACE && child.localName === "legend"
|
|
253
|
+
);
|
|
254
|
+
if (!legend?.contains(control)) return true;
|
|
255
|
+
}
|
|
230
256
|
fieldset = fieldset.parentElement?.closest("fieldset[disabled]") ?? null;
|
|
231
257
|
}
|
|
232
258
|
return false;
|
|
@@ -240,6 +266,12 @@ function flatTreeParent(element) {
|
|
|
240
266
|
if (parent instanceof ShadowRoot) return parent.host;
|
|
241
267
|
return parent instanceof Element ? parent : null;
|
|
242
268
|
}
|
|
269
|
+
function flatTreeContains(ancestor, element) {
|
|
270
|
+
for (let node = element; node; node = flatTreeParent(node)) {
|
|
271
|
+
if (node === ancestor) return true;
|
|
272
|
+
}
|
|
273
|
+
return false;
|
|
274
|
+
}
|
|
243
275
|
function canTakeFocus(element) {
|
|
244
276
|
for (let node = element; node; node = flatTreeParent(node)) {
|
|
245
277
|
if (unslotted(node) || node.matches("[hidden], [inert]")) return false;
|
|
@@ -284,11 +316,10 @@ function hasNativeTabStop(element) {
|
|
|
284
316
|
if (element.tagName === "AUDIO" || element.tagName === "VIDEO") {
|
|
285
317
|
return element.hasAttribute("controls");
|
|
286
318
|
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
return false;
|
|
319
|
+
const details = element.parentElement;
|
|
320
|
+
return details instanceof HTMLDetailsElement && Array.from(details.children).find(
|
|
321
|
+
(child) => child.namespaceURI === HTML_NAMESPACE && child.localName === "summary"
|
|
322
|
+
) === element;
|
|
292
323
|
}
|
|
293
324
|
function hasEditableTabStop(element) {
|
|
294
325
|
const value = element.getAttribute("contenteditable")?.toLowerCase();
|
|
@@ -300,12 +331,239 @@ function isTabStop(element) {
|
|
|
300
331
|
if (tabindex !== null) return tabindex >= 0;
|
|
301
332
|
return hasNativeTabStop(element) || hasEditableTabStop(element);
|
|
302
333
|
}
|
|
303
|
-
function
|
|
304
|
-
|
|
305
|
-
|
|
334
|
+
function isRadio(element) {
|
|
335
|
+
return element instanceof HTMLInputElement && element.type === "radio";
|
|
336
|
+
}
|
|
337
|
+
function sameRadioGroup(a, b) {
|
|
338
|
+
return a.name !== "" && a.name === b.name && a.form === b.form && a.getRootNode() === b.getRootNode();
|
|
339
|
+
}
|
|
340
|
+
function isInEditableContent(element) {
|
|
341
|
+
for (let node = element.parentElement; node; node = node.parentElement) {
|
|
342
|
+
if (node.getAttribute("contenteditable")?.toLowerCase() === "false") return false;
|
|
343
|
+
if (hasEditableTabStop(node)) return true;
|
|
344
|
+
}
|
|
345
|
+
return false;
|
|
346
|
+
}
|
|
347
|
+
var XLINK_NAMESPACE = "http://www.w3.org/1999/xlink";
|
|
348
|
+
function isSvgLink(element) {
|
|
349
|
+
return element instanceof SVGElement && element.localName === "a" && (element.hasAttribute("href") || element.hasAttributeNS(XLINK_NAMESPACE, "href"));
|
|
350
|
+
}
|
|
351
|
+
function hasRenderedImage(area) {
|
|
352
|
+
const map = area.closest("map");
|
|
353
|
+
const key = map?.name || map?.id;
|
|
354
|
+
if (!map || !key) return false;
|
|
355
|
+
const root = map.getRootNode();
|
|
356
|
+
return Array.from(root.querySelectorAll("img[usemap]")).some(
|
|
357
|
+
(image) => image.getAttribute("usemap") === `#${key}` && isRenderedForFocus(image)
|
|
358
|
+
);
|
|
359
|
+
}
|
|
360
|
+
function isFocusableInOrder(element) {
|
|
361
|
+
const tabindex = authoredTabindex(element);
|
|
362
|
+
return (tabindex === null || tabindex >= 0) && canTakeFocus(element);
|
|
363
|
+
}
|
|
364
|
+
function extraStop(element) {
|
|
365
|
+
if (element instanceof HTMLAreaElement) {
|
|
366
|
+
const focusable = element.hasAttribute("href") || authoredTabindex(element) !== null;
|
|
367
|
+
return focusable && isFocusableInOrder(element) && hasRenderedImage(element);
|
|
368
|
+
}
|
|
369
|
+
if (element instanceof HTMLObjectElement) {
|
|
370
|
+
return isFocusableInOrder(element) && isRenderedForFocus(element) && element.contentWindow !== null;
|
|
371
|
+
}
|
|
372
|
+
if (isSvgLink(element))
|
|
373
|
+
return isFocusableInOrder(element) && isRenderedForFocus(element);
|
|
374
|
+
return null;
|
|
375
|
+
}
|
|
376
|
+
function isSequentialStop(element) {
|
|
377
|
+
const stop = extraStop(element) ?? (element.matches(TAB_STOP_CANDIDATE_SELECTOR) && isTabStop(element));
|
|
378
|
+
if (!stop) return false;
|
|
379
|
+
const link = element instanceof HTMLAnchorElement || element instanceof HTMLAreaElement || isSvgLink(element);
|
|
380
|
+
return !(link && authoredTabindex(element) === null && isInEditableContent(element));
|
|
381
|
+
}
|
|
382
|
+
function ownedScope(element) {
|
|
383
|
+
if (element.shadowRoot) return Array.from(element.shadowRoot.children);
|
|
384
|
+
if (element instanceof HTMLSlotElement) {
|
|
385
|
+
return element.assignedNodes().length > 0 ? element.assignedElements() : Array.from(element.children);
|
|
386
|
+
}
|
|
387
|
+
return null;
|
|
388
|
+
}
|
|
389
|
+
function orderScope(elements, walk) {
|
|
390
|
+
const entries = [];
|
|
391
|
+
const visit = (element) => {
|
|
392
|
+
const isFrom = element === walk.from;
|
|
393
|
+
if (isFrom && walk.side !== "after") walk.fromAt = walk.tree.length;
|
|
394
|
+
const tabindex = authoredTabindex(element) ?? 0;
|
|
395
|
+
let stop = null;
|
|
396
|
+
if ((element instanceof HTMLElement || element instanceof SVGElement) && isSequentialStop(element)) {
|
|
397
|
+
stop = element;
|
|
398
|
+
walk.tree.push(element);
|
|
399
|
+
}
|
|
400
|
+
const owned = ownedScope(element);
|
|
401
|
+
if (owned) {
|
|
402
|
+
if (tabindex >= 0) {
|
|
403
|
+
entries.push({ tabindex, stops: [...stop ? [stop] : [], ...orderScope(owned, walk)] });
|
|
404
|
+
} else if (walk.from && flatTreeContains(element, walk.from) && (!isFrom || walk.side === "on")) {
|
|
405
|
+
walk.fromAt = walk.tree.length;
|
|
406
|
+
walk.excludedScope = element;
|
|
407
|
+
orderScope(owned, {
|
|
408
|
+
from: walk.from,
|
|
409
|
+
side: walk.side,
|
|
410
|
+
tree: walk.tree,
|
|
411
|
+
fromAt: -1,
|
|
412
|
+
excludedScope: null
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
if (isFrom && walk.side === "after") walk.fromAt = walk.tree.length;
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
if (stop) entries.push({ tabindex, stops: [stop] });
|
|
419
|
+
for (const child of Array.from(element.children)) visit(child);
|
|
420
|
+
if (isFrom && walk.side === "after") walk.fromAt = walk.tree.length;
|
|
421
|
+
};
|
|
422
|
+
for (const element of elements) visit(element);
|
|
423
|
+
const positive = entries.filter((entry) => entry.tabindex > 0);
|
|
424
|
+
positive.sort((a, b) => a.tabindex - b.tabindex);
|
|
425
|
+
const rest = entries.filter((entry) => entry.tabindex === 0);
|
|
426
|
+
return [...positive, ...rest].flatMap((entry) => entry.stops);
|
|
427
|
+
}
|
|
428
|
+
function passesRadioRule(element, tree, focusedRadio, backward) {
|
|
429
|
+
if (!isRadio(element) || element.checked) return true;
|
|
430
|
+
const group = tree.filter(
|
|
431
|
+
(stop) => stop === element || isRadio(stop) && sameRadioGroup(stop, element)
|
|
432
|
+
);
|
|
433
|
+
if (group.some((radio) => radio.checked)) return false;
|
|
434
|
+
if (group[backward ? group.length - 1 : 0] !== element) return false;
|
|
435
|
+
return focusedRadio === null || !sameRadioGroup(focusedRadio, element);
|
|
436
|
+
}
|
|
437
|
+
function startIndex(order, walk, backward, isStop) {
|
|
438
|
+
if (walk.fromAt < 0) return backward ? order.length - 1 : 0;
|
|
439
|
+
const at = walk.side === "on" ? order.indexOf(walk.from) : -1;
|
|
440
|
+
if (at >= 0) return backward ? at - 1 : at + 1;
|
|
441
|
+
const neighbour = backward ? walk.tree.slice(0, walk.fromAt).reverse().find(isStop) : walk.tree.slice(walk.fromAt).find(isStop);
|
|
442
|
+
if (neighbour) return order.indexOf(neighbour);
|
|
443
|
+
return backward ? -1 : order.length;
|
|
444
|
+
}
|
|
445
|
+
function movesWithin(root, from, backward, wrap, radioContext, side = "on", position = { holder: null }) {
|
|
446
|
+
const walk = {
|
|
447
|
+
from,
|
|
448
|
+
side,
|
|
449
|
+
tree: [],
|
|
450
|
+
fromAt: from === root ? 0 : -1,
|
|
451
|
+
excludedScope: null
|
|
452
|
+
};
|
|
453
|
+
const order = orderScope(ownedScope(root) ?? Array.from(root.children), walk);
|
|
454
|
+
const radios = radioContext ?? {
|
|
455
|
+
tree: walk.tree,
|
|
456
|
+
focusedRadio: side === "on" && walk.fromAt >= 0 && isRadio(from) ? from : null
|
|
457
|
+
};
|
|
458
|
+
const isStop = (element) => passesRadioRule(element, radios.tree, radios.focusedRadio, backward);
|
|
459
|
+
const holds = (element) => position.holder !== null && flatTreeContains(element, position.holder);
|
|
460
|
+
const start = startIndex(
|
|
461
|
+
order,
|
|
462
|
+
walk,
|
|
463
|
+
backward,
|
|
464
|
+
(element) => order.includes(element) && isStop(element) && !holds(element)
|
|
465
|
+
);
|
|
466
|
+
const remaining = backward ? order.slice(0, start + 1).reverse() : order.slice(start);
|
|
467
|
+
const wrapped = wrap ? backward ? order.slice(start + 1).reverse() : order.slice(0, start) : [];
|
|
468
|
+
const excluded = walk.excludedScope;
|
|
469
|
+
const prefix = excluded && !(backward && from === excluded) ? movesWithin(
|
|
470
|
+
excluded,
|
|
471
|
+
from === excluded ? null : from,
|
|
472
|
+
backward,
|
|
473
|
+
false,
|
|
474
|
+
radios,
|
|
475
|
+
side,
|
|
476
|
+
position
|
|
477
|
+
) : [];
|
|
478
|
+
return [
|
|
479
|
+
...prefix,
|
|
480
|
+
...[...remaining, ...wrapped].filter(
|
|
481
|
+
(element) => (side !== "on" || element !== from) && isStop(element)
|
|
482
|
+
)
|
|
483
|
+
];
|
|
484
|
+
}
|
|
485
|
+
function flatParentNode(node) {
|
|
486
|
+
const parent = node.parentNode;
|
|
487
|
+
if (parent instanceof Element && parent.shadowRoot) {
|
|
488
|
+
for (const slot of parent.shadowRoot.querySelectorAll("slot")) {
|
|
489
|
+
if (slot.assignedNodes().includes(node)) return slot;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
return parent instanceof ShadowRoot ? parent.host : parent;
|
|
493
|
+
}
|
|
494
|
+
function flatChildNodes(node) {
|
|
495
|
+
if (node instanceof Element && node.shadowRoot) return Array.from(node.shadowRoot.childNodes);
|
|
496
|
+
if (node instanceof HTMLSlotElement) {
|
|
497
|
+
const assigned = node.assignedNodes();
|
|
498
|
+
return assigned.length > 0 ? assigned : Array.from(node.childNodes);
|
|
499
|
+
}
|
|
500
|
+
return Array.from(node.childNodes);
|
|
501
|
+
}
|
|
502
|
+
function flatNodeAfter(node, root) {
|
|
503
|
+
for (let current = node; current && current !== root; ) {
|
|
504
|
+
const parent = flatParentNode(current);
|
|
505
|
+
if (!parent) return null;
|
|
506
|
+
const siblings = flatChildNodes(parent);
|
|
507
|
+
const index = siblings.indexOf(current);
|
|
508
|
+
const next = index >= 0 ? siblings[index + 1] : void 0;
|
|
509
|
+
if (next) return next;
|
|
510
|
+
current = parent;
|
|
306
511
|
}
|
|
307
512
|
return null;
|
|
308
513
|
}
|
|
514
|
+
function flatElementBefore(node, root) {
|
|
515
|
+
for (let current = node; current && current !== root; ) {
|
|
516
|
+
const parent = flatParentNode(current);
|
|
517
|
+
if (!parent) return null;
|
|
518
|
+
const siblings = flatChildNodes(parent);
|
|
519
|
+
for (let index = siblings.indexOf(current) - 1; index >= 0; index--) {
|
|
520
|
+
const sibling = siblings[index];
|
|
521
|
+
if (sibling instanceof Element) return sibling;
|
|
522
|
+
}
|
|
523
|
+
current = parent;
|
|
524
|
+
}
|
|
525
|
+
return null;
|
|
526
|
+
}
|
|
527
|
+
function elementAfterPosition(container, offset, root) {
|
|
528
|
+
const owner = container instanceof ShadowRoot ? container.host : container;
|
|
529
|
+
const child = container.childNodes[offset];
|
|
530
|
+
const previous = container.childNodes[offset - 1];
|
|
531
|
+
let node = child ?? (previous ? flatNodeAfter(previous, root) : flatChildNodes(owner)[0] ?? flatNodeAfter(owner, root));
|
|
532
|
+
while (node && !(node instanceof Element)) {
|
|
533
|
+
node = flatChildNodes(node)[0] ?? flatNodeAfter(node, root);
|
|
534
|
+
}
|
|
535
|
+
return node;
|
|
536
|
+
}
|
|
537
|
+
function elementBeforePosition(container, offset, root) {
|
|
538
|
+
const child = container.childNodes[offset];
|
|
539
|
+
if (child) return flatElementBefore(child, root);
|
|
540
|
+
const previous = container.childNodes[offset - 1];
|
|
541
|
+
if (previous) return previous instanceof Element ? previous : flatElementBefore(previous, root);
|
|
542
|
+
return flatElementBefore(container instanceof ShadowRoot ? container.host : container, root);
|
|
543
|
+
}
|
|
544
|
+
function elementHoldingPosition(container, offset) {
|
|
545
|
+
if (container instanceof Element && container.shadowRoot) {
|
|
546
|
+
const near = container.childNodes[offset] ?? container.childNodes[offset - 1];
|
|
547
|
+
return near ? flatParentNode(near) : container;
|
|
548
|
+
}
|
|
549
|
+
if (container instanceof Element) return container;
|
|
550
|
+
if (container instanceof ShadowRoot) return container.host;
|
|
551
|
+
return flatParentNode(container);
|
|
552
|
+
}
|
|
553
|
+
function sequentialTabStops(root, from = null, backward = false) {
|
|
554
|
+
if (!(from instanceof Range)) return movesWithin(root, from, backward, true);
|
|
555
|
+
const container = backward ? from.startContainer : from.endContainer;
|
|
556
|
+
const offset = backward ? from.startOffset : from.endOffset;
|
|
557
|
+
const anchor = backward ? elementBeforePosition(container, offset, root) : elementAfterPosition(container, offset, root);
|
|
558
|
+
return movesWithin(root, anchor, backward, true, void 0, backward ? "after" : "before", {
|
|
559
|
+
holder: elementHoldingPosition(container, offset)
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
function deepActiveElement(ownerDocument) {
|
|
563
|
+
let active = ownerDocument.activeElement;
|
|
564
|
+
while (active?.shadowRoot?.activeElement) active = active.shadowRoot.activeElement;
|
|
565
|
+
return active;
|
|
566
|
+
}
|
|
309
567
|
|
|
310
568
|
var ListenerSet = class {
|
|
311
569
|
#abort = new AbortController();
|
|
@@ -351,6 +609,126 @@ function stateReasonFor(event) {
|
|
|
351
609
|
return "user";
|
|
352
610
|
}
|
|
353
611
|
|
|
612
|
+
function queryOpenDescendants(root, selector) {
|
|
613
|
+
const matches = [];
|
|
614
|
+
const roots = [root];
|
|
615
|
+
for (const scope of roots) {
|
|
616
|
+
matches.push(...scope.querySelectorAll(selector));
|
|
617
|
+
if (scope.nodeType === Node.ELEMENT_NODE) {
|
|
618
|
+
const shadow = scope.shadowRoot;
|
|
619
|
+
if (shadow) roots.push(shadow);
|
|
620
|
+
}
|
|
621
|
+
for (const element of scope.querySelectorAll("*")) {
|
|
622
|
+
if (element.shadowRoot) roots.push(element.shadowRoot);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
return matches;
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
function holdsFocus(element) {
|
|
629
|
+
return element.matches(":focus") || deepActiveElement(element.ownerDocument) === element;
|
|
630
|
+
}
|
|
631
|
+
var TabindexLoan = class _TabindexLoan {
|
|
632
|
+
static #registry = sharedRegistry(
|
|
633
|
+
"stimeo-ui.tabindex-loan.registry.v1",
|
|
634
|
+
() => ({ stacks: /* @__PURE__ */ new WeakMap(), names: /* @__PURE__ */ new Set() })
|
|
635
|
+
);
|
|
636
|
+
#value;
|
|
637
|
+
#record;
|
|
638
|
+
#preserveFocus;
|
|
639
|
+
#lent = /* @__PURE__ */ new Set();
|
|
640
|
+
constructor(value, owner, options = {}) {
|
|
641
|
+
this.#value = value;
|
|
642
|
+
this.#record = `data-${owner}-tabindex-loan`;
|
|
643
|
+
this.#preserveFocus = options.preserveFocus === true;
|
|
644
|
+
_TabindexLoan.#registry.names.add(this.#record);
|
|
645
|
+
}
|
|
646
|
+
lend(element, options = {}) {
|
|
647
|
+
const stack = this.#stack(element);
|
|
648
|
+
const current = element.getAttribute("tabindex");
|
|
649
|
+
const held = stack.find((hold) => hold.loan === this) ?? stack.find(
|
|
650
|
+
(hold) => hold.loan === null && hold.record === this.#record && hold.value === this.#value
|
|
651
|
+
);
|
|
652
|
+
const linked = stack.at(-1)?.value === current;
|
|
653
|
+
if (!held && options.onlyIfUnfocusable && (current !== null || element.tabIndex >= 0)) return;
|
|
654
|
+
if (!held && current !== null && !linked) return;
|
|
655
|
+
this.#lent.add(element);
|
|
656
|
+
if (held) held.loan = this;
|
|
657
|
+
else stack.push({ loan: this, record: this.#record, value: this.#value, linked });
|
|
658
|
+
this.#mark(element, stack);
|
|
659
|
+
if (current === null || !held && current !== this.#value) {
|
|
660
|
+
element.setAttribute("tabindex", this.#value);
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
return(element) {
|
|
664
|
+
const stack = this.#stack(element);
|
|
665
|
+
const hold = stack.find((held) => held.loan === this) ?? stack.find(
|
|
666
|
+
(held) => held.loan === null && held.record === this.#record && held.value === this.#value
|
|
667
|
+
);
|
|
668
|
+
if (!hold) return false;
|
|
669
|
+
if (!this.#release(element, stack, hold, this.#preserveFocus)) {
|
|
670
|
+
hold.loan = this;
|
|
671
|
+
this.#lent.add(element);
|
|
672
|
+
return false;
|
|
673
|
+
}
|
|
674
|
+
this.#lent.delete(element);
|
|
675
|
+
return true;
|
|
676
|
+
}
|
|
677
|
+
returnAll() {
|
|
678
|
+
for (const element of Array.from(this.#lent)) this.return(element);
|
|
679
|
+
}
|
|
680
|
+
reclaim(element) {
|
|
681
|
+
if (element.getAttribute(this.#record) !== this.#value) return;
|
|
682
|
+
const stack = this.#stack(element);
|
|
683
|
+
const hold = stack.find((held) => held.loan === null && held.record === this.#record);
|
|
684
|
+
if (hold && !holdsFocus(element)) this.#release(element, stack, hold);
|
|
685
|
+
}
|
|
686
|
+
reclaimWithin(root) {
|
|
687
|
+
for (const element of queryOpenDescendants(root, `[${this.#record}]`)) {
|
|
688
|
+
this.reclaim(element);
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
#stack(element) {
|
|
692
|
+
const stacks = _TabindexLoan.#registry.stacks;
|
|
693
|
+
const stack = stacks.get(element) ?? this.#seed(element);
|
|
694
|
+
stacks.set(element, stack);
|
|
695
|
+
return stack;
|
|
696
|
+
}
|
|
697
|
+
#seed(element) {
|
|
698
|
+
const current = element.getAttribute("tabindex");
|
|
699
|
+
const holds = [];
|
|
700
|
+
for (const record of _TabindexLoan.#registry.names) {
|
|
701
|
+
const value = element.getAttribute(record);
|
|
702
|
+
if (value !== null) holds.push({ loan: null, record, value, linked: true });
|
|
703
|
+
}
|
|
704
|
+
holds.sort((one, other) => Number(one.value === current) - Number(other.value === current));
|
|
705
|
+
for (const [index, hold] of holds.entries()) hold.linked = index > 0;
|
|
706
|
+
return holds;
|
|
707
|
+
}
|
|
708
|
+
#release(element, stack, hold, preserveFocus = false) {
|
|
709
|
+
const current = element.getAttribute("tabindex");
|
|
710
|
+
const index = stack.indexOf(hold);
|
|
711
|
+
const owns = current === hold.value && !stack.slice(index + 1).some((above2) => above2.value === current);
|
|
712
|
+
if (owns && preserveFocus && holdsFocus(element)) return false;
|
|
713
|
+
stack.splice(index, 1);
|
|
714
|
+
const above = stack[index];
|
|
715
|
+
if (above) above.linked &&= hold.linked;
|
|
716
|
+
this.#mark(element, stack);
|
|
717
|
+
if (!owns) return true;
|
|
718
|
+
const below = hold.linked ? stack[index - 1] : void 0;
|
|
719
|
+
if (!below) element.removeAttribute("tabindex");
|
|
720
|
+
else if (below.value !== current) element.setAttribute("tabindex", below.value);
|
|
721
|
+
return true;
|
|
722
|
+
}
|
|
723
|
+
#mark(element, stack) {
|
|
724
|
+
const records = /* @__PURE__ */ new Map([[this.#record, null]]);
|
|
725
|
+
for (const hold of stack) records.set(hold.record, hold.value);
|
|
726
|
+
for (const [name, recorded] of records) {
|
|
727
|
+
setAttributeIfChanged(element, name, recorded);
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
};
|
|
731
|
+
|
|
354
732
|
var PopoverController = class extends Controller {
|
|
355
733
|
static targets = ["trigger", "panel"];
|
|
356
734
|
static values = {
|
|
@@ -361,11 +739,18 @@ var PopoverController = class extends Controller {
|
|
|
361
739
|
#stopScrollDismiss = null;
|
|
362
740
|
#escapeLayer = new EscapeLayer();
|
|
363
741
|
#expanded = new AttributeLease("aria-expanded", this.identifier);
|
|
364
|
-
#
|
|
742
|
+
#openState = false;
|
|
743
|
+
#currentPanel = null;
|
|
744
|
+
#openToken = null;
|
|
745
|
+
#hidden = new AttributeLease("hidden", this.identifier);
|
|
746
|
+
#tabindex = new TabindexLoan("-1", this.identifier);
|
|
365
747
|
#connected = false;
|
|
366
748
|
#reporting = false;
|
|
367
749
|
#listeners = new ListenerSet();
|
|
368
750
|
connect() {
|
|
751
|
+
this.#reporting = false;
|
|
752
|
+
this.#openState = false;
|
|
753
|
+
this.#currentPanel = null;
|
|
369
754
|
this.#close("api");
|
|
370
755
|
this.#listeners.add(document, "click", this.#onOutsideClick, { capture: true });
|
|
371
756
|
this.#listeners.add(this.element, "focusout", this.#onFocusOut);
|
|
@@ -378,16 +763,20 @@ var PopoverController = class extends Controller {
|
|
|
378
763
|
this.#reporting = false;
|
|
379
764
|
this.#release();
|
|
380
765
|
this.#listeners.dispose();
|
|
766
|
+
this.#openState = false;
|
|
767
|
+
this.#currentPanel = null;
|
|
381
768
|
}
|
|
382
769
|
closeOnScrollValueChanged() {
|
|
383
|
-
if (this.#
|
|
770
|
+
if (this.#openState) this.#syncScrollDismiss();
|
|
771
|
+
}
|
|
772
|
+
panelTargetConnected() {
|
|
773
|
+
if (this.#connected) this.#syncPanel();
|
|
384
774
|
}
|
|
385
775
|
panelTargetDisconnected(panel) {
|
|
386
|
-
if (
|
|
387
|
-
if (this.panelTargets.includes(panel))
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
this.#reflectClosed();
|
|
776
|
+
if (this.#connected) this.#syncPanel();
|
|
777
|
+
if (!this.scope.containsElement(panel) || !this.panelTargets.includes(panel)) {
|
|
778
|
+
this.#returnPanel(panel);
|
|
779
|
+
}
|
|
391
780
|
}
|
|
392
781
|
triggerTargetConnected() {
|
|
393
782
|
if (this.#connected) this.#reflectTrigger();
|
|
@@ -404,19 +793,23 @@ var PopoverController = class extends Controller {
|
|
|
404
793
|
}
|
|
405
794
|
}
|
|
406
795
|
open(event) {
|
|
407
|
-
this.#
|
|
796
|
+
this.#reveal(stateReasonFor(event));
|
|
408
797
|
}
|
|
409
798
|
close(event) {
|
|
410
799
|
this.#close(stateReasonFor(event));
|
|
411
800
|
}
|
|
412
|
-
#
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
this.#
|
|
801
|
+
#reveal(reason) {
|
|
802
|
+
this.#syncPanel();
|
|
803
|
+
if (this.#isOpen) return;
|
|
804
|
+
this.#openState = true;
|
|
805
|
+
const token = {};
|
|
806
|
+
this.#openToken = token;
|
|
807
|
+
this.#reflectPanel(this.#currentPanel, true);
|
|
808
|
+
this.#reflectTrigger();
|
|
418
809
|
if (this.#reporting) this.dispatch("open", { detail: { reason }, cancelable: false });
|
|
419
|
-
if (this.#
|
|
810
|
+
if (!this.#openState || !this.#reporting) return;
|
|
811
|
+
this.#syncPanel();
|
|
812
|
+
if (this.#openToken !== token || !this.#isOpen) return;
|
|
420
813
|
this.#escapeLayer.activate(document, {
|
|
421
814
|
onDismiss: () => this.#closeAndRestore(),
|
|
422
815
|
claims: claimsWhileFocusWithin(this.element)
|
|
@@ -425,58 +818,89 @@ var PopoverController = class extends Controller {
|
|
|
425
818
|
this.#focusFirst();
|
|
426
819
|
}
|
|
427
820
|
#close(reason) {
|
|
821
|
+
this.#syncPanel();
|
|
428
822
|
const was = this.#isOpen;
|
|
823
|
+
this.#openState = false;
|
|
429
824
|
this.#release();
|
|
430
|
-
this.#
|
|
825
|
+
this.#reflectPanel(this.#currentPanel, false);
|
|
826
|
+
this.#reflectTrigger();
|
|
431
827
|
if (was && this.#reporting) this.dispatch("close", { detail: { reason }, cancelable: false });
|
|
432
828
|
}
|
|
433
|
-
#
|
|
434
|
-
|
|
435
|
-
|
|
829
|
+
#syncPanel() {
|
|
830
|
+
const next = this.hasPanelTarget ? this.panelTarget : null;
|
|
831
|
+
const current = this.#currentPanel;
|
|
832
|
+
if (current === next) return;
|
|
833
|
+
if (current) {
|
|
834
|
+
this.#openState = !current.hidden;
|
|
835
|
+
if (!this.scope.containsElement(current) || !this.panelTargets.includes(current)) {
|
|
836
|
+
this.#returnPanel(current);
|
|
837
|
+
} else this.#reflectPanel(current, false);
|
|
838
|
+
}
|
|
839
|
+
this.#currentPanel = next;
|
|
840
|
+
this.#reflectPanel(next, this.#openState);
|
|
841
|
+
this.#reflectTrigger();
|
|
842
|
+
if (!this.#openState) this.#release();
|
|
843
|
+
else this.#syncScrollDismiss();
|
|
844
|
+
}
|
|
845
|
+
#reflectPanel(panel, open) {
|
|
846
|
+
if (!panel) return;
|
|
847
|
+
this.#hidden.write(panel, open ? null : "");
|
|
848
|
+
if (!open) this.#tabindex.return(panel);
|
|
849
|
+
}
|
|
850
|
+
#returnPanel(panel) {
|
|
851
|
+
this.#hidden.return(panel);
|
|
852
|
+
this.#tabindex.return(panel);
|
|
436
853
|
}
|
|
437
854
|
#reflectTrigger() {
|
|
438
855
|
if (this.hasTriggerTarget) this.#expanded.write(this.triggerTarget, String(this.#isOpen));
|
|
439
856
|
}
|
|
440
857
|
#release() {
|
|
441
|
-
this.#
|
|
858
|
+
this.#openToken = null;
|
|
442
859
|
this.#escapeLayer.deactivate();
|
|
443
860
|
this.#stopScrollDismiss?.();
|
|
444
861
|
this.#stopScrollDismiss = null;
|
|
445
862
|
}
|
|
446
863
|
#syncScrollDismiss() {
|
|
447
|
-
if (this.closeOnScrollValue) {
|
|
448
|
-
this.#stopScrollDismiss ??= observeScrollDismiss(this.element, () =>
|
|
864
|
+
if (this.closeOnScrollValue && this.#currentPanel && this.#openState) {
|
|
865
|
+
this.#stopScrollDismiss ??= observeScrollDismiss(this.element, () => {
|
|
866
|
+
if (this.hasPanelTarget) this.#close("scroll");
|
|
867
|
+
});
|
|
449
868
|
return;
|
|
450
869
|
}
|
|
451
870
|
this.#stopScrollDismiss?.();
|
|
452
871
|
this.#stopScrollDismiss = null;
|
|
453
872
|
}
|
|
454
873
|
#focusFirst() {
|
|
455
|
-
const
|
|
874
|
+
const panel = this.#currentPanel;
|
|
875
|
+
if (!panel) return;
|
|
876
|
+
const [first] = sequentialTabStops(panel);
|
|
456
877
|
if (first) {
|
|
457
878
|
first.focus();
|
|
458
879
|
return;
|
|
459
880
|
}
|
|
460
|
-
|
|
461
|
-
|
|
881
|
+
this.#tabindex.lend(panel);
|
|
882
|
+
panel.focus();
|
|
462
883
|
}
|
|
463
884
|
#closeAndRestore() {
|
|
464
885
|
this.#close("escape");
|
|
465
886
|
if (this.hasTriggerTarget) this.triggerTarget.focus();
|
|
466
887
|
}
|
|
467
888
|
#onOutsideClick = (event) => {
|
|
889
|
+
this.#syncPanel();
|
|
468
890
|
const target = event.target;
|
|
469
891
|
if (this.#closable && target instanceof Node && !this.element.contains(target)) {
|
|
470
892
|
this.#close("outside");
|
|
471
893
|
}
|
|
472
894
|
};
|
|
473
895
|
#onFocusOut = (event) => {
|
|
896
|
+
this.#syncPanel();
|
|
474
897
|
if (!this.#closable) return;
|
|
475
898
|
const next = event.relatedTarget;
|
|
476
899
|
if (!(next instanceof Node) || this.element.contains(next)) return;
|
|
477
900
|
this.#close("focus");
|
|
478
901
|
};
|
|
479
902
|
#onDocumentFocusIn = (event) => {
|
|
903
|
+
this.#syncPanel();
|
|
480
904
|
if (!this.#closable) return;
|
|
481
905
|
const target = event.target;
|
|
482
906
|
if (!(target instanceof Node) || target === document.body || this.element.contains(target)) {
|
|
@@ -485,10 +909,10 @@ var PopoverController = class extends Controller {
|
|
|
485
909
|
this.#close("focus");
|
|
486
910
|
};
|
|
487
911
|
get #isOpen() {
|
|
488
|
-
return this
|
|
912
|
+
return this.#currentPanel ? !this.#currentPanel.hidden : this.#openState;
|
|
489
913
|
}
|
|
490
914
|
get #closable() {
|
|
491
|
-
return this.#isOpen || this.#
|
|
915
|
+
return this.#isOpen || this.#openState;
|
|
492
916
|
}
|
|
493
917
|
};
|
|
494
918
|
|