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
|
|
|
@@ -197,6 +218,7 @@ var EscapeLayer = class _EscapeLayer {
|
|
|
197
218
|
);
|
|
198
219
|
#active = null;
|
|
199
220
|
activate(ownerDocument = document, options) {
|
|
221
|
+
const entry = { onDismiss: options.onDismiss, claims: options.claims ?? null };
|
|
200
222
|
this.deactivate();
|
|
201
223
|
let registry2 = _EscapeLayer.#registries.get(ownerDocument);
|
|
202
224
|
if (!registry2) {
|
|
@@ -204,7 +226,6 @@ var EscapeLayer = class _EscapeLayer {
|
|
|
204
226
|
_EscapeLayer.#registries.set(ownerDocument, registry2);
|
|
205
227
|
ownerDocument.addEventListener("keydown", registry2.onKeydown);
|
|
206
228
|
}
|
|
207
|
-
const entry = { onDismiss: options.onDismiss, claims: options.claims ?? null };
|
|
208
229
|
registry2.stack.push(entry);
|
|
209
230
|
this.#active = { document: ownerDocument, entry };
|
|
210
231
|
}
|
|
@@ -253,11 +274,16 @@ var EscapeLayer = class _EscapeLayer {
|
|
|
253
274
|
}
|
|
254
275
|
};
|
|
255
276
|
|
|
277
|
+
var HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
|
|
256
278
|
function inheritsFieldsetDisabled(control) {
|
|
257
279
|
let fieldset = control.closest("fieldset[disabled]");
|
|
258
280
|
while (fieldset) {
|
|
259
|
-
|
|
260
|
-
|
|
281
|
+
if (fieldset.namespaceURI === HTML_NAMESPACE && fieldset.localName === "fieldset") {
|
|
282
|
+
const legend = Array.from(fieldset.children).find(
|
|
283
|
+
(child) => child.namespaceURI === HTML_NAMESPACE && child.localName === "legend"
|
|
284
|
+
);
|
|
285
|
+
if (!legend?.contains(control)) return true;
|
|
286
|
+
}
|
|
261
287
|
fieldset = fieldset.parentElement?.closest("fieldset[disabled]") ?? null;
|
|
262
288
|
}
|
|
263
289
|
return false;
|
|
@@ -330,11 +356,10 @@ function hasNativeTabStop(element) {
|
|
|
330
356
|
if (element.tagName === "AUDIO" || element.tagName === "VIDEO") {
|
|
331
357
|
return element.hasAttribute("controls");
|
|
332
358
|
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
return false;
|
|
359
|
+
const details = element.parentElement;
|
|
360
|
+
return details instanceof HTMLDetailsElement && Array.from(details.children).find(
|
|
361
|
+
(child) => child.namespaceURI === HTML_NAMESPACE && child.localName === "summary"
|
|
362
|
+
) === element;
|
|
338
363
|
}
|
|
339
364
|
function hasEditableTabStop(element) {
|
|
340
365
|
const value = element.getAttribute("contenteditable")?.toLowerCase();
|
|
@@ -397,27 +422,42 @@ function isSequentialStop(element) {
|
|
|
397
422
|
function ownedScope(element) {
|
|
398
423
|
if (element.shadowRoot) return Array.from(element.shadowRoot.children);
|
|
399
424
|
if (element instanceof HTMLSlotElement) {
|
|
400
|
-
|
|
401
|
-
return assigned.length > 0 ? assigned : Array.from(element.children);
|
|
425
|
+
return element.assignedNodes().length > 0 ? element.assignedElements() : Array.from(element.children);
|
|
402
426
|
}
|
|
403
427
|
return null;
|
|
404
428
|
}
|
|
405
429
|
function orderScope(elements, walk) {
|
|
406
430
|
const entries = [];
|
|
407
431
|
const visit = (element) => {
|
|
408
|
-
|
|
432
|
+
const isFrom = element === walk.from;
|
|
433
|
+
if (isFrom && walk.side !== "after") walk.fromAt = walk.tree.length;
|
|
409
434
|
const tabindex = authoredTabindex(element) ?? 0;
|
|
410
|
-
|
|
411
|
-
if (
|
|
435
|
+
let stop = null;
|
|
436
|
+
if ((element instanceof HTMLElement || element instanceof SVGElement) && isSequentialStop(element)) {
|
|
437
|
+
stop = element;
|
|
438
|
+
walk.tree.push(element);
|
|
439
|
+
}
|
|
412
440
|
const owned = ownedScope(element);
|
|
413
441
|
if (owned) {
|
|
414
442
|
if (tabindex >= 0) {
|
|
415
443
|
entries.push({ tabindex, stops: [...stop ? [stop] : [], ...orderScope(owned, walk)] });
|
|
444
|
+
} else if (walk.from && flatTreeContains(element, walk.from) && (!isFrom || walk.side === "on")) {
|
|
445
|
+
walk.fromAt = walk.tree.length;
|
|
446
|
+
walk.excludedScope = element;
|
|
447
|
+
orderScope(owned, {
|
|
448
|
+
from: walk.from,
|
|
449
|
+
side: walk.side,
|
|
450
|
+
tree: walk.tree,
|
|
451
|
+
fromAt: -1,
|
|
452
|
+
excludedScope: null
|
|
453
|
+
});
|
|
416
454
|
}
|
|
455
|
+
if (isFrom && walk.side === "after") walk.fromAt = walk.tree.length;
|
|
417
456
|
return;
|
|
418
457
|
}
|
|
419
458
|
if (stop) entries.push({ tabindex, stops: [stop] });
|
|
420
459
|
for (const child of Array.from(element.children)) visit(child);
|
|
460
|
+
if (isFrom && walk.side === "after") walk.fromAt = walk.tree.length;
|
|
421
461
|
};
|
|
422
462
|
for (const element of elements) visit(element);
|
|
423
463
|
const positive = entries.filter((entry) => entry.tabindex > 0);
|
|
@@ -425,31 +465,139 @@ function orderScope(elements, walk) {
|
|
|
425
465
|
const rest = entries.filter((entry) => entry.tabindex === 0);
|
|
426
466
|
return [...positive, ...rest].flatMap((entry) => entry.stops);
|
|
427
467
|
}
|
|
428
|
-
function passesRadioRule(element, tree, focusedRadio) {
|
|
468
|
+
function passesRadioRule(element, tree, focusedRadio, backward) {
|
|
429
469
|
if (!isRadio(element) || element.checked) return true;
|
|
430
470
|
const group = tree.filter(
|
|
431
471
|
(stop) => stop === element || isRadio(stop) && sameRadioGroup(stop, element)
|
|
432
472
|
);
|
|
433
473
|
if (group.some((radio) => radio.checked)) return false;
|
|
434
|
-
if (group[0] !== element) return false;
|
|
474
|
+
if (group[backward ? group.length - 1 : 0] !== element) return false;
|
|
435
475
|
return focusedRadio === null || !sameRadioGroup(focusedRadio, element);
|
|
436
476
|
}
|
|
437
477
|
function startIndex(order, walk, backward, isStop) {
|
|
438
478
|
if (walk.fromAt < 0) return backward ? order.length - 1 : 0;
|
|
439
|
-
const at = order.indexOf(walk.from);
|
|
479
|
+
const at = walk.side === "on" ? order.indexOf(walk.from) : -1;
|
|
440
480
|
if (at >= 0) return backward ? at - 1 : at + 1;
|
|
441
481
|
const neighbour = backward ? walk.tree.slice(0, walk.fromAt).reverse().find(isStop) : walk.tree.slice(walk.fromAt).find(isStop);
|
|
442
482
|
if (neighbour) return order.indexOf(neighbour);
|
|
443
|
-
return backward ?
|
|
483
|
+
return backward ? -1 : order.length;
|
|
444
484
|
}
|
|
445
|
-
function
|
|
446
|
-
const walk = {
|
|
485
|
+
function movesWithin(root, from, backward, wrap, radioContext, side = "on", position = { holder: null }) {
|
|
486
|
+
const walk = {
|
|
487
|
+
from,
|
|
488
|
+
side,
|
|
489
|
+
tree: [],
|
|
490
|
+
fromAt: from === root ? 0 : -1,
|
|
491
|
+
excludedScope: null
|
|
492
|
+
};
|
|
447
493
|
const order = orderScope(ownedScope(root) ?? Array.from(root.children), walk);
|
|
448
|
-
const
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
494
|
+
const radios = radioContext ?? {
|
|
495
|
+
tree: walk.tree,
|
|
496
|
+
focusedRadio: side === "on" && walk.fromAt >= 0 && isRadio(from) ? from : null
|
|
497
|
+
};
|
|
498
|
+
const isStop = (element) => passesRadioRule(element, radios.tree, radios.focusedRadio, backward);
|
|
499
|
+
const holds = (element) => position.holder !== null && flatTreeContains(element, position.holder);
|
|
500
|
+
const start = startIndex(
|
|
501
|
+
order,
|
|
502
|
+
walk,
|
|
503
|
+
backward,
|
|
504
|
+
(element) => order.includes(element) && isStop(element) && !holds(element)
|
|
505
|
+
);
|
|
506
|
+
const remaining = backward ? order.slice(0, start + 1).reverse() : order.slice(start);
|
|
507
|
+
const wrapped = wrap ? backward ? order.slice(start + 1).reverse() : order.slice(0, start) : [];
|
|
508
|
+
const excluded = walk.excludedScope;
|
|
509
|
+
const prefix = excluded && !(backward && from === excluded) ? movesWithin(
|
|
510
|
+
excluded,
|
|
511
|
+
from === excluded ? null : from,
|
|
512
|
+
backward,
|
|
513
|
+
false,
|
|
514
|
+
radios,
|
|
515
|
+
side,
|
|
516
|
+
position
|
|
517
|
+
) : [];
|
|
518
|
+
return [
|
|
519
|
+
...prefix,
|
|
520
|
+
...[...remaining, ...wrapped].filter(
|
|
521
|
+
(element) => (side !== "on" || element !== from) && isStop(element)
|
|
522
|
+
)
|
|
523
|
+
];
|
|
524
|
+
}
|
|
525
|
+
function flatParentNode(node) {
|
|
526
|
+
const parent = node.parentNode;
|
|
527
|
+
if (parent instanceof Element && parent.shadowRoot) {
|
|
528
|
+
for (const slot of parent.shadowRoot.querySelectorAll("slot")) {
|
|
529
|
+
if (slot.assignedNodes().includes(node)) return slot;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
return parent instanceof ShadowRoot ? parent.host : parent;
|
|
533
|
+
}
|
|
534
|
+
function flatChildNodes(node) {
|
|
535
|
+
if (node instanceof Element && node.shadowRoot) return Array.from(node.shadowRoot.childNodes);
|
|
536
|
+
if (node instanceof HTMLSlotElement) {
|
|
537
|
+
const assigned = node.assignedNodes();
|
|
538
|
+
return assigned.length > 0 ? assigned : Array.from(node.childNodes);
|
|
539
|
+
}
|
|
540
|
+
return Array.from(node.childNodes);
|
|
541
|
+
}
|
|
542
|
+
function flatNodeAfter(node, root) {
|
|
543
|
+
for (let current = node; current && current !== root; ) {
|
|
544
|
+
const parent = flatParentNode(current);
|
|
545
|
+
if (!parent) return null;
|
|
546
|
+
const siblings = flatChildNodes(parent);
|
|
547
|
+
const index = siblings.indexOf(current);
|
|
548
|
+
const next = index >= 0 ? siblings[index + 1] : void 0;
|
|
549
|
+
if (next) return next;
|
|
550
|
+
current = parent;
|
|
551
|
+
}
|
|
552
|
+
return null;
|
|
553
|
+
}
|
|
554
|
+
function flatElementBefore(node, root) {
|
|
555
|
+
for (let current = node; current && current !== root; ) {
|
|
556
|
+
const parent = flatParentNode(current);
|
|
557
|
+
if (!parent) return null;
|
|
558
|
+
const siblings = flatChildNodes(parent);
|
|
559
|
+
for (let index = siblings.indexOf(current) - 1; index >= 0; index--) {
|
|
560
|
+
const sibling = siblings[index];
|
|
561
|
+
if (sibling instanceof Element) return sibling;
|
|
562
|
+
}
|
|
563
|
+
current = parent;
|
|
564
|
+
}
|
|
565
|
+
return null;
|
|
566
|
+
}
|
|
567
|
+
function elementAfterPosition(container, offset, root) {
|
|
568
|
+
const owner = container instanceof ShadowRoot ? container.host : container;
|
|
569
|
+
const child = container.childNodes[offset];
|
|
570
|
+
const previous = container.childNodes[offset - 1];
|
|
571
|
+
let node = child ?? (previous ? flatNodeAfter(previous, root) : flatChildNodes(owner)[0] ?? flatNodeAfter(owner, root));
|
|
572
|
+
while (node && !(node instanceof Element)) {
|
|
573
|
+
node = flatChildNodes(node)[0] ?? flatNodeAfter(node, root);
|
|
574
|
+
}
|
|
575
|
+
return node;
|
|
576
|
+
}
|
|
577
|
+
function elementBeforePosition(container, offset, root) {
|
|
578
|
+
const child = container.childNodes[offset];
|
|
579
|
+
if (child) return flatElementBefore(child, root);
|
|
580
|
+
const previous = container.childNodes[offset - 1];
|
|
581
|
+
if (previous) return previous instanceof Element ? previous : flatElementBefore(previous, root);
|
|
582
|
+
return flatElementBefore(container instanceof ShadowRoot ? container.host : container, root);
|
|
583
|
+
}
|
|
584
|
+
function elementHoldingPosition(container, offset) {
|
|
585
|
+
if (container instanceof Element && container.shadowRoot) {
|
|
586
|
+
const near = container.childNodes[offset] ?? container.childNodes[offset - 1];
|
|
587
|
+
return near ? flatParentNode(near) : container;
|
|
588
|
+
}
|
|
589
|
+
if (container instanceof Element) return container;
|
|
590
|
+
if (container instanceof ShadowRoot) return container.host;
|
|
591
|
+
return flatParentNode(container);
|
|
592
|
+
}
|
|
593
|
+
function sequentialTabStops(root, from = null, backward = false) {
|
|
594
|
+
if (!(from instanceof Range)) return movesWithin(root, from, backward, true);
|
|
595
|
+
const container = backward ? from.startContainer : from.endContainer;
|
|
596
|
+
const offset = backward ? from.startOffset : from.endOffset;
|
|
597
|
+
const anchor = backward ? elementBeforePosition(container, offset, root) : elementAfterPosition(container, offset, root);
|
|
598
|
+
return movesWithin(root, anchor, backward, true, void 0, backward ? "after" : "before", {
|
|
599
|
+
holder: elementHoldingPosition(container, offset)
|
|
600
|
+
});
|
|
453
601
|
}
|
|
454
602
|
function deepActiveElement(ownerDocument) {
|
|
455
603
|
let active = ownerDocument.activeElement;
|
|
@@ -613,7 +761,7 @@ var INERT_MARK = `data-${FOCUS_TRAP_OWNER}-inert`;
|
|
|
613
761
|
var OVERFLOW_MARK = `data-${FOCUS_TRAP_OWNER}-overflow`;
|
|
614
762
|
var FocusTrap = class _FocusTrap {
|
|
615
763
|
static #registries = sharedRegistry(
|
|
616
|
-
"stimeo-ui.focus-trap.registry.
|
|
764
|
+
"stimeo-ui.focus-trap.registry.v3",
|
|
617
765
|
() => /* @__PURE__ */ new WeakMap()
|
|
618
766
|
);
|
|
619
767
|
static #TEXT_ENTRY_TYPES = /* @__PURE__ */ new Set([
|
|
@@ -636,15 +784,20 @@ var FocusTrap = class _FocusTrap {
|
|
|
636
784
|
constructor(getContainer, options = {}) {
|
|
637
785
|
this.#getContainer = getContainer;
|
|
638
786
|
this.#options = options;
|
|
639
|
-
this.#entry =
|
|
787
|
+
this.#entry = this.#createEntry();
|
|
788
|
+
}
|
|
789
|
+
#createEntry() {
|
|
790
|
+
const entry = {
|
|
640
791
|
container: () => this.#readContainer(),
|
|
641
792
|
moveFocus: (backward) => this.#moveFocus(backward),
|
|
642
793
|
refocus: () => this.#refocus(),
|
|
643
794
|
isolated: false,
|
|
644
795
|
lockedBody: null,
|
|
645
796
|
openedFrom: null,
|
|
646
|
-
handedBack: []
|
|
797
|
+
handedBack: [],
|
|
798
|
+
returnTargets: () => this.#activeReturnTargets(entry)
|
|
647
799
|
};
|
|
800
|
+
return entry;
|
|
648
801
|
}
|
|
649
802
|
get active() {
|
|
650
803
|
return this.#activeState;
|
|
@@ -652,6 +805,7 @@ var FocusTrap = class _FocusTrap {
|
|
|
652
805
|
activate() {
|
|
653
806
|
if (this.#activeState) return;
|
|
654
807
|
_FocusTrap.#sweep();
|
|
808
|
+
this.#entry = this.#createEntry();
|
|
655
809
|
this.#activeState = true;
|
|
656
810
|
this.#openers = _FocusTrap.#focusPath();
|
|
657
811
|
this.#entry.openedFrom = _FocusTrap.#trapHolding(this.#openers[0] ?? null);
|
|
@@ -668,14 +822,21 @@ var FocusTrap = class _FocusTrap {
|
|
|
668
822
|
this.#returnTabindexes();
|
|
669
823
|
return;
|
|
670
824
|
}
|
|
825
|
+
const entry = this.#entry;
|
|
826
|
+
const parent = entry.openedFrom;
|
|
827
|
+
const openers = this.#openers;
|
|
828
|
+
this.#openers = [];
|
|
671
829
|
this.#activeState = false;
|
|
672
830
|
this.#escapeLayer.deactivate();
|
|
673
|
-
const above = this.#leaveStack();
|
|
674
|
-
this.#unlockScroll();
|
|
831
|
+
const above = this.#leaveStack(entry);
|
|
832
|
+
this.#unlockScroll(entry);
|
|
675
833
|
_FocusTrap.#reconcileBackground(document);
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
834
|
+
try {
|
|
835
|
+
const wayBack = this.#handOver(entry, openers, above);
|
|
836
|
+
if (restoreFocus) this.#restore(wayBack, above, parent);
|
|
837
|
+
} finally {
|
|
838
|
+
this.#returnTabindexes();
|
|
839
|
+
}
|
|
679
840
|
}
|
|
680
841
|
connect() {
|
|
681
842
|
this.#gate.cancel();
|
|
@@ -711,18 +872,27 @@ var FocusTrap = class _FocusTrap {
|
|
|
711
872
|
document.addEventListener("keydown", registry2.onKeydown);
|
|
712
873
|
document.addEventListener("turbo:morph", registry2.onMorph);
|
|
713
874
|
document.addEventListener("turbo:morph-element", registry2.onMorph);
|
|
875
|
+
document.addEventListener("pointerdown", registry2.onPointerDown, {
|
|
876
|
+
capture: true,
|
|
877
|
+
passive: true
|
|
878
|
+
});
|
|
879
|
+
document.addEventListener("focusin", registry2.onFocusIn, { capture: true });
|
|
714
880
|
}
|
|
715
881
|
registry2.stack.push(this.#entry);
|
|
716
882
|
}
|
|
717
|
-
#leaveStack() {
|
|
883
|
+
#leaveStack(entry) {
|
|
718
884
|
const registry2 = _FocusTrap.#registry(document);
|
|
719
|
-
const index = registry2.stack.indexOf(
|
|
885
|
+
const index = registry2.stack.indexOf(entry);
|
|
720
886
|
const above = registry2.stack.slice(index + 1);
|
|
721
887
|
registry2.stack.splice(index, 1);
|
|
722
888
|
if (registry2.stack.length === 0) {
|
|
723
889
|
document.removeEventListener("keydown", registry2.onKeydown);
|
|
724
890
|
document.removeEventListener("turbo:morph", registry2.onMorph);
|
|
725
891
|
document.removeEventListener("turbo:morph-element", registry2.onMorph);
|
|
892
|
+
document.removeEventListener("pointerdown", registry2.onPointerDown, { capture: true });
|
|
893
|
+
document.removeEventListener("focusin", registry2.onFocusIn, { capture: true });
|
|
894
|
+
registry2.start = null;
|
|
895
|
+
registry2.pressed = false;
|
|
726
896
|
}
|
|
727
897
|
return above;
|
|
728
898
|
}
|
|
@@ -740,24 +910,26 @@ var FocusTrap = class _FocusTrap {
|
|
|
740
910
|
}
|
|
741
911
|
return null;
|
|
742
912
|
}
|
|
743
|
-
#handOver(above) {
|
|
744
|
-
const
|
|
745
|
-
const
|
|
746
|
-
|
|
747
|
-
this.#options.fallbackFocus?.() ?? null,
|
|
748
|
-
...entry.handedBack
|
|
749
|
-
].filter((element) => element !== null);
|
|
750
|
-
for (const trap of above) {
|
|
751
|
-
if (trap.openedFrom !== entry) continue;
|
|
752
|
-
trap.handedBack = [...trap.handedBack, ...wayBack];
|
|
753
|
-
trap.openedFrom = entry.openedFrom;
|
|
754
|
-
}
|
|
755
|
-
this.#openers = [];
|
|
913
|
+
#handOver(entry, openers, above) {
|
|
914
|
+
const wayBack = [...openers];
|
|
915
|
+
const parent = entry.openedFrom;
|
|
916
|
+
const handedBack = entry.handedBack;
|
|
756
917
|
entry.openedFrom = null;
|
|
757
918
|
entry.handedBack = [];
|
|
919
|
+
try {
|
|
920
|
+
const fallback = this.#options.fallbackFocus?.();
|
|
921
|
+
if (fallback) wayBack.push(fallback);
|
|
922
|
+
} finally {
|
|
923
|
+
wayBack.push(...handedBack);
|
|
924
|
+
for (const trap of above) {
|
|
925
|
+
if (trap.openedFrom !== entry) continue;
|
|
926
|
+
trap.handedBack = [...trap.handedBack, ...wayBack];
|
|
927
|
+
trap.openedFrom = parent;
|
|
928
|
+
}
|
|
929
|
+
}
|
|
758
930
|
return wayBack;
|
|
759
931
|
}
|
|
760
|
-
#restore(wayBack, above) {
|
|
932
|
+
#restore(wayBack, above, parent) {
|
|
761
933
|
const active = deepActiveElement(document);
|
|
762
934
|
const released = this.#readContainer();
|
|
763
935
|
const holds = (trap) => {
|
|
@@ -768,7 +940,7 @@ var FocusTrap = class _FocusTrap {
|
|
|
768
940
|
return !released || !flatTreeContains(released, active) || flatTreeContains(released, container);
|
|
769
941
|
};
|
|
770
942
|
if (above.some(holds)) return;
|
|
771
|
-
for (const element of wayBack) {
|
|
943
|
+
for (const element of _FocusTrap.#returnCandidates(wayBack, parent)) {
|
|
772
944
|
if (this.#activeState) return;
|
|
773
945
|
if (!element.isConnected || !canTakeFocus(element) || !isRenderedForFocus(element)) continue;
|
|
774
946
|
const before = deepActiveElement(document);
|
|
@@ -778,6 +950,19 @@ var FocusTrap = class _FocusTrap {
|
|
|
778
950
|
}
|
|
779
951
|
_FocusTrap.#tabOwner(_FocusTrap.#registry(document).stack)?.refocus();
|
|
780
952
|
}
|
|
953
|
+
*#activeReturnTargets(entry) {
|
|
954
|
+
if (!this.#activeState || this.#entry !== entry) return;
|
|
955
|
+
yield* this.#openers;
|
|
956
|
+
const fallback = this.#options.fallbackFocus?.();
|
|
957
|
+
if (fallback) yield fallback;
|
|
958
|
+
yield* entry.handedBack;
|
|
959
|
+
}
|
|
960
|
+
static *#returnCandidates(wayBack, parent) {
|
|
961
|
+
yield* wayBack;
|
|
962
|
+
for (let entry = parent; entry && !_FocusTrap.#takesTab(entry); entry = entry.openedFrom) {
|
|
963
|
+
yield* entry.returnTargets?.() ?? [];
|
|
964
|
+
}
|
|
965
|
+
}
|
|
781
966
|
#refocus() {
|
|
782
967
|
if (!this.#flag(this.#options.autoFocus, true)) return;
|
|
783
968
|
if (flatTreeContains(this.#getContainer(), deepActiveElement(document))) return;
|
|
@@ -792,8 +977,8 @@ var FocusTrap = class _FocusTrap {
|
|
|
792
977
|
const focused = deepActiveElement(document);
|
|
793
978
|
for (const [element, loan] of [...this.#tabindexLoans]) {
|
|
794
979
|
if (element === focused) continue;
|
|
795
|
-
loan.returnAll();
|
|
796
980
|
this.#tabindexLoans.delete(element);
|
|
981
|
+
loan.returnAll();
|
|
797
982
|
}
|
|
798
983
|
}
|
|
799
984
|
#lockScroll() {
|
|
@@ -804,11 +989,11 @@ var FocusTrap = class _FocusTrap {
|
|
|
804
989
|
this.#entry.lockedBody = body;
|
|
805
990
|
body.style.overflow = "hidden";
|
|
806
991
|
}
|
|
807
|
-
#unlockScroll() {
|
|
992
|
+
#unlockScroll(entry) {
|
|
808
993
|
const registry2 = _FocusTrap.#registry(document);
|
|
809
|
-
const body =
|
|
810
|
-
|
|
811
|
-
if (!registry2.scrollLocks.delete(
|
|
994
|
+
const body = entry.lockedBody;
|
|
995
|
+
entry.lockedBody = null;
|
|
996
|
+
if (!registry2.scrollLocks.delete(entry) || !body) return;
|
|
812
997
|
if (!_FocusTrap.#isLocked(registry2, body)) _FocusTrap.#unlock(body);
|
|
813
998
|
}
|
|
814
999
|
static #isLocked(registry2, body) {
|
|
@@ -838,8 +1023,12 @@ var FocusTrap = class _FocusTrap {
|
|
|
838
1023
|
stack: [],
|
|
839
1024
|
onKeydown: (event) => _FocusTrap.#resolveTab(registry2.stack, event),
|
|
840
1025
|
onMorph: () => morphs.schedule(),
|
|
1026
|
+
onPointerDown: (event) => _FocusTrap.#recordPress(registry2, event),
|
|
1027
|
+
onFocusIn: (event) => _FocusTrap.#recordFocus(registry2, event),
|
|
841
1028
|
inerted: /* @__PURE__ */ new Set(),
|
|
842
|
-
scrollLocks: /* @__PURE__ */ new Set()
|
|
1029
|
+
scrollLocks: /* @__PURE__ */ new Set(),
|
|
1030
|
+
start: null,
|
|
1031
|
+
pressed: false
|
|
843
1032
|
};
|
|
844
1033
|
_FocusTrap.#registries.set(ownerDocument, registry2);
|
|
845
1034
|
return registry2;
|
|
@@ -937,7 +1126,7 @@ var FocusTrap = class _FocusTrap {
|
|
|
937
1126
|
return _FocusTrap.#tabOwner(_FocusTrap.#registry(document).stack) === this.#entry;
|
|
938
1127
|
}
|
|
939
1128
|
#moveFocus(backward) {
|
|
940
|
-
const from =
|
|
1129
|
+
const from = _FocusTrap.#start();
|
|
941
1130
|
for (const stop of sequentialTabStops(this.#getContainer(), from, backward)) {
|
|
942
1131
|
if (!this.#ownsTab()) return;
|
|
943
1132
|
const before = deepActiveElement(document);
|
|
@@ -948,18 +1137,66 @@ var FocusTrap = class _FocusTrap {
|
|
|
948
1137
|
return;
|
|
949
1138
|
}
|
|
950
1139
|
}
|
|
1140
|
+
static #start() {
|
|
1141
|
+
const active = deepActiveElement(document);
|
|
1142
|
+
const start = _FocusTrap.#registry(document).start;
|
|
1143
|
+
if (active && active !== document.body) {
|
|
1144
|
+
const at = start ? elementHoldingPosition(start.startContainer, start.startOffset) : null;
|
|
1145
|
+
const pointInside = !(active instanceof HTMLElement && isTabStop(active)) && flatTreeContains(active, at);
|
|
1146
|
+
return pointInside ? start : active;
|
|
1147
|
+
}
|
|
1148
|
+
return start ?? active;
|
|
1149
|
+
}
|
|
1150
|
+
static #recordPress(registry2, event) {
|
|
1151
|
+
const path = event.composedPath();
|
|
1152
|
+
const target = path[0];
|
|
1153
|
+
const owner = target.ownerDocument ?? document;
|
|
1154
|
+
const roots = path.filter((node) => node instanceof ShadowRoot);
|
|
1155
|
+
const caret = _FocusTrap.#caretAt(owner, event.clientX, event.clientY, roots);
|
|
1156
|
+
const range = owner.createRange();
|
|
1157
|
+
const fits = caret !== null && target.contains(caret.node) && caret.offset <= (caret.node instanceof CharacterData ? caret.node.length : caret.node.childNodes.length);
|
|
1158
|
+
if (fits) range.setStart(caret.node, caret.offset);
|
|
1159
|
+
else range.setStart(target, 0);
|
|
1160
|
+
range.collapse(true);
|
|
1161
|
+
registry2.start = range;
|
|
1162
|
+
registry2.pressed = true;
|
|
1163
|
+
}
|
|
1164
|
+
static #recordFocus(registry2, event) {
|
|
1165
|
+
const target = event.composedPath()[0];
|
|
1166
|
+
const point = registry2.pressed ? registry2.start : null;
|
|
1167
|
+
const at = point ? elementHoldingPosition(point.startContainer, point.startOffset) : null;
|
|
1168
|
+
const keep = !(target instanceof HTMLElement && isTabStop(target)) && flatTreeContains(target, at);
|
|
1169
|
+
registry2.pressed = false;
|
|
1170
|
+
if (keep) return;
|
|
1171
|
+
const range = target.ownerDocument.createRange();
|
|
1172
|
+
range.selectNode(target);
|
|
1173
|
+
registry2.start = range;
|
|
1174
|
+
}
|
|
1175
|
+
static #caretAt(owner, x, y, roots) {
|
|
1176
|
+
if (typeof owner.caretPositionFromPoint === "function") {
|
|
1177
|
+
const position = owner.caretPositionFromPoint(x, y, { shadowRoots: roots });
|
|
1178
|
+
return position ? { node: position.offsetNode, offset: position.offset } : null;
|
|
1179
|
+
}
|
|
1180
|
+
const legacy = owner;
|
|
1181
|
+
if (typeof legacy.caretRangeFromPoint === "function") {
|
|
1182
|
+
const range = legacy.caretRangeFromPoint(x, y);
|
|
1183
|
+
return range ? { node: range.startContainer, offset: range.startOffset } : null;
|
|
1184
|
+
}
|
|
1185
|
+
return null;
|
|
1186
|
+
}
|
|
951
1187
|
static #selectOnEntry(stop) {
|
|
952
1188
|
if (stop instanceof HTMLInputElement && _FocusTrap.#TEXT_ENTRY_TYPES.has(stop.type)) {
|
|
953
1189
|
stop.select();
|
|
954
1190
|
}
|
|
955
1191
|
}
|
|
956
1192
|
#focusInitial() {
|
|
1193
|
+
const container = this.#readContainer();
|
|
1194
|
+
if (!container) return;
|
|
957
1195
|
const preferred = this.#options.initialFocus?.();
|
|
958
1196
|
if (preferred) {
|
|
959
1197
|
preferred.focus();
|
|
960
1198
|
return;
|
|
961
1199
|
}
|
|
962
|
-
const container = this.#getContainer();
|
|
963
1200
|
const [first] = sequentialTabStops(container);
|
|
964
1201
|
if (first) {
|
|
965
1202
|
first.focus();
|
|
@@ -1028,6 +1265,8 @@ var DialogController = class extends Controller {
|
|
|
1028
1265
|
});
|
|
1029
1266
|
#reporting = false;
|
|
1030
1267
|
#connected = false;
|
|
1268
|
+
#openState = false;
|
|
1269
|
+
#seenDialog = false;
|
|
1031
1270
|
#dialog = null;
|
|
1032
1271
|
#hidden = new AttributeLease("hidden", this.identifier);
|
|
1033
1272
|
#morphRender = new MorphRenderWatcher(() => this.#repair());
|
|
@@ -1036,17 +1275,20 @@ var DialogController = class extends Controller {
|
|
|
1036
1275
|
this.#connected = true;
|
|
1037
1276
|
if (this.hasDialogTarget) this.#hidden.write(this.dialogTarget, "");
|
|
1038
1277
|
this.#dialog = this.hasDialogTarget ? this.dialogTarget : null;
|
|
1278
|
+
this.#seenDialog = this.#dialog !== null;
|
|
1279
|
+
this.#openState = false;
|
|
1039
1280
|
this.#reporting = true;
|
|
1040
1281
|
this.#morphRender.observe(this.element);
|
|
1041
1282
|
}
|
|
1042
1283
|
disconnect() {
|
|
1043
1284
|
this.#morphRender.disconnect();
|
|
1044
1285
|
this.#connected = false;
|
|
1286
|
+
this.#openState = false;
|
|
1045
1287
|
this.#reporting = false;
|
|
1046
1288
|
this.#trap.disconnect(this);
|
|
1047
1289
|
}
|
|
1048
1290
|
#repair() {
|
|
1049
|
-
if (this.hasDialogTarget) this.#hidden.write(this.dialogTarget, this.#
|
|
1291
|
+
if (this.hasDialogTarget) this.#hidden.write(this.dialogTarget, this.#openState ? null : "");
|
|
1050
1292
|
}
|
|
1051
1293
|
dialogTargetConnected() {
|
|
1052
1294
|
if (this.#connected) this.#adoptDialog();
|
|
@@ -1063,39 +1305,48 @@ var DialogController = class extends Controller {
|
|
|
1063
1305
|
this.#close(stateReasonFor(event));
|
|
1064
1306
|
}
|
|
1065
1307
|
closeOnBackdrop(event) {
|
|
1066
|
-
if (event.target === this.dialogTarget) this.#close("outside");
|
|
1308
|
+
if (this.hasDialogTarget && event.target === this.dialogTarget) this.#close("outside");
|
|
1067
1309
|
}
|
|
1068
1310
|
#open(reason) {
|
|
1069
|
-
|
|
1070
|
-
this.#
|
|
1311
|
+
this.#adoptDialog();
|
|
1312
|
+
if (!this.#connected || !this.#seenDialog || this.#isOpen) return;
|
|
1313
|
+
this.#openState = true;
|
|
1314
|
+
if (this.hasDialogTarget) this.#hidden.write(this.dialogTarget, null);
|
|
1071
1315
|
if (this.#reporting) this.dispatch("open", { detail: { reason }, cancelable: false });
|
|
1072
|
-
if (!this.#isOpen) return;
|
|
1316
|
+
if (!this.#isOpen || !this.#connected) return;
|
|
1317
|
+
this.#adoptDialog();
|
|
1318
|
+
if (this.hasDialogTarget && this.dialogTarget.hidden) {
|
|
1319
|
+
this.#openState = false;
|
|
1320
|
+
return;
|
|
1321
|
+
}
|
|
1073
1322
|
this.#trap.activate();
|
|
1074
1323
|
}
|
|
1075
1324
|
#close(reason) {
|
|
1076
|
-
|
|
1077
|
-
this.#
|
|
1325
|
+
this.#adoptDialog();
|
|
1326
|
+
if (!this.#isOpen) return;
|
|
1327
|
+
this.#openState = false;
|
|
1328
|
+
if (this.hasDialogTarget) this.#hidden.write(this.dialogTarget, "");
|
|
1078
1329
|
if (this.#reporting) this.dispatch("close", { detail: { reason }, cancelable: false });
|
|
1079
1330
|
if (this.#isOpen) return;
|
|
1080
1331
|
this.#trap.deactivate();
|
|
1081
1332
|
}
|
|
1082
1333
|
#adoptDialog() {
|
|
1083
1334
|
const dialog = this.hasDialogTarget ? this.dialogTarget : null;
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
if (
|
|
1087
|
-
if (
|
|
1088
|
-
return;
|
|
1335
|
+
const previous = this.#dialog;
|
|
1336
|
+
if (dialog === previous) return;
|
|
1337
|
+
if (previous) {
|
|
1338
|
+
if (this.dialogTargets.includes(previous)) this.#hidden.write(previous, "");
|
|
1339
|
+
else this.#hidden.return(previous);
|
|
1089
1340
|
}
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1341
|
+
this.#dialog = dialog;
|
|
1342
|
+
if (dialog) {
|
|
1343
|
+
this.#seenDialog = true;
|
|
1344
|
+
this.#hidden.write(dialog, this.#openState ? null : "");
|
|
1093
1345
|
}
|
|
1094
|
-
this.#
|
|
1095
|
-
this.#trap.refreshContainer();
|
|
1346
|
+
if (this.#openState) this.#trap.refreshContainer();
|
|
1096
1347
|
}
|
|
1097
1348
|
get #isOpen() {
|
|
1098
|
-
return this
|
|
1349
|
+
return this.#openState;
|
|
1099
1350
|
}
|
|
1100
1351
|
};
|
|
1101
1352
|
|