stimeo-ui 0.18.2 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +33 -0
- data/dist/controllers/alert_dialog_controller.js +246 -42
- data/dist/controllers/auto_submit_controller.js +26 -5
- data/dist/controllers/avatar_controller.js +29 -9
- data/dist/controllers/breadcrumb_controller.js +205 -17
- data/dist/controllers/bulk_select_controller.js +25 -4
- data/dist/controllers/calendar_controller.js +242 -7
- data/dist/controllers/carousel_controller.js +70 -15
- data/dist/controllers/character_counter_controller.js +26 -5
- data/dist/controllers/collapsible_controller.js +35 -8
- data/dist/controllers/combobox_controller.js +84 -20
- data/dist/controllers/command_palette_controller.js +296 -77
- data/dist/controllers/confirm_controller.js +225 -34
- data/dist/controllers/context_menu_controller.js +58 -29
- data/dist/controllers/currency_input_controller.js +1 -1
- data/dist/controllers/data_grid_controller.js +196 -9
- data/dist/controllers/date_range_picker_controller.js +25 -4
- data/dist/controllers/dialog_controller.js +252 -45
- data/dist/controllers/dismissible_controller.js +57 -11
- data/dist/controllers/drawer_controller.js +284 -58
- data/dist/controllers/dropdown_controller.js +63 -51
- data/dist/controllers/editable_controller.js +69 -6
- data/dist/controllers/empty_state_controller.js +187 -4
- data/dist/controllers/file_dropzone_controller.js +300 -12
- data/dist/controllers/filter_controller.js +194 -5
- data/dist/controllers/flash_controller.js +199 -12
- data/dist/controllers/focus_controller.js +195 -23
- data/dist/controllers/form_field_controller.js +65 -9
- data/dist/controllers/frame_loading_controller.js +25 -4
- data/dist/controllers/hover_card_controller.js +107 -38
- data/dist/controllers/input_mask_controller.js +1 -1
- data/dist/controllers/listbox_controller.js +94 -36
- data/dist/controllers/menu_controller.js +44 -23
- data/dist/controllers/menubar_controller.js +228 -46
- data/dist/controllers/meter_controller.js +25 -4
- data/dist/controllers/multi_select_controller.js +110 -42
- data/dist/controllers/nested_form_controller.js +258 -9
- data/dist/controllers/network_status_controller.js +25 -4
- data/dist/controllers/number_input_controller.js +26 -5
- data/dist/controllers/otp_controller.js +26 -5
- data/dist/controllers/overflow_menu_controller.js +183 -22
- data/dist/controllers/pagination_controller.js +179 -22
- data/dist/controllers/password_reveal_controller.js +25 -4
- data/dist/controllers/popover_controller.js +454 -34
- data/dist/controllers/progress_controller.js +25 -4
- data/dist/controllers/radio_group_controller.js +195 -40
- data/dist/controllers/rating_controller.js +58 -10
- data/dist/controllers/read_more_controller.js +191 -25
- data/dist/controllers/roving_controller.js +197 -6
- data/dist/controllers/scroll_area_controller.js +50 -12
- data/dist/controllers/scroll_visibility_controller.js +25 -4
- data/dist/controllers/scrollspy_controller.js +179 -3
- data/dist/controllers/separator_controller.js +25 -4
- data/dist/controllers/sidebar_controller.js +290 -93
- data/dist/controllers/skeleton_controller.js +25 -4
- data/dist/controllers/spinner_controller.js +25 -4
- data/dist/controllers/step_indicator_controller.js +181 -6
- data/dist/controllers/stepper_controller.js +188 -6
- data/dist/controllers/sticky_observer_controller.js +25 -4
- data/dist/controllers/submit_once_controller.js +25 -4
- data/dist/controllers/tabs_controller.js +189 -3
- data/dist/controllers/tags_input_controller.js +210 -9
- data/dist/controllers/theme_controller.js +192 -5
- data/dist/controllers/toast_controller.js +478 -16
- data/dist/controllers/toggle_group_controller.js +198 -35
- data/dist/controllers/toolbar_controller.js +198 -7
- data/dist/controllers/tooltip_controller.js +243 -45
- data/dist/controllers/tree_view_controller.js +200 -8
- data/dist/index.js +1764 -739
- 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
|
|
|
@@ -408,7 +429,8 @@ function ownedScope(element) {
|
|
|
408
429
|
function orderScope(elements, walk) {
|
|
409
430
|
const entries = [];
|
|
410
431
|
const visit = (element) => {
|
|
411
|
-
|
|
432
|
+
const isFrom = element === walk.from;
|
|
433
|
+
if (isFrom && walk.side !== "after") walk.fromAt = walk.tree.length;
|
|
412
434
|
const tabindex = authoredTabindex(element) ?? 0;
|
|
413
435
|
let stop = null;
|
|
414
436
|
if ((element instanceof HTMLElement || element instanceof SVGElement) && isSequentialStop(element)) {
|
|
@@ -419,15 +441,23 @@ function orderScope(elements, walk) {
|
|
|
419
441
|
if (owned) {
|
|
420
442
|
if (tabindex >= 0) {
|
|
421
443
|
entries.push({ tabindex, stops: [...stop ? [stop] : [], ...orderScope(owned, walk)] });
|
|
422
|
-
} else if (walk.from && flatTreeContains(element, walk.from)) {
|
|
444
|
+
} else if (walk.from && flatTreeContains(element, walk.from) && (!isFrom || walk.side === "on")) {
|
|
423
445
|
walk.fromAt = walk.tree.length;
|
|
424
446
|
walk.excludedScope = element;
|
|
425
|
-
orderScope(owned, {
|
|
447
|
+
orderScope(owned, {
|
|
448
|
+
from: walk.from,
|
|
449
|
+
side: walk.side,
|
|
450
|
+
tree: walk.tree,
|
|
451
|
+
fromAt: -1,
|
|
452
|
+
excludedScope: null
|
|
453
|
+
});
|
|
426
454
|
}
|
|
455
|
+
if (isFrom && walk.side === "after") walk.fromAt = walk.tree.length;
|
|
427
456
|
return;
|
|
428
457
|
}
|
|
429
458
|
if (stop) entries.push({ tabindex, stops: [stop] });
|
|
430
459
|
for (const child of Array.from(element.children)) visit(child);
|
|
460
|
+
if (isFrom && walk.side === "after") walk.fromAt = walk.tree.length;
|
|
431
461
|
};
|
|
432
462
|
for (const element of elements) visit(element);
|
|
433
463
|
const positive = entries.filter((entry) => entry.tabindex > 0);
|
|
@@ -435,26 +465,27 @@ function orderScope(elements, walk) {
|
|
|
435
465
|
const rest = entries.filter((entry) => entry.tabindex === 0);
|
|
436
466
|
return [...positive, ...rest].flatMap((entry) => entry.stops);
|
|
437
467
|
}
|
|
438
|
-
function passesRadioRule(element, tree, focusedRadio) {
|
|
468
|
+
function passesRadioRule(element, tree, focusedRadio, backward) {
|
|
439
469
|
if (!isRadio(element) || element.checked) return true;
|
|
440
470
|
const group = tree.filter(
|
|
441
471
|
(stop) => stop === element || isRadio(stop) && sameRadioGroup(stop, element)
|
|
442
472
|
);
|
|
443
473
|
if (group.some((radio) => radio.checked)) return false;
|
|
444
|
-
if (group[0] !== element) return false;
|
|
474
|
+
if (group[backward ? group.length - 1 : 0] !== element) return false;
|
|
445
475
|
return focusedRadio === null || !sameRadioGroup(focusedRadio, element);
|
|
446
476
|
}
|
|
447
477
|
function startIndex(order, walk, backward, isStop) {
|
|
448
478
|
if (walk.fromAt < 0) return backward ? order.length - 1 : 0;
|
|
449
|
-
const at = order.indexOf(walk.from);
|
|
479
|
+
const at = walk.side === "on" ? order.indexOf(walk.from) : -1;
|
|
450
480
|
if (at >= 0) return backward ? at - 1 : at + 1;
|
|
451
481
|
const neighbour = backward ? walk.tree.slice(0, walk.fromAt).reverse().find(isStop) : walk.tree.slice(walk.fromAt).find(isStop);
|
|
452
482
|
if (neighbour) return order.indexOf(neighbour);
|
|
453
483
|
return backward ? -1 : order.length;
|
|
454
484
|
}
|
|
455
|
-
function movesWithin(root, from, backward, wrap, radioContext) {
|
|
485
|
+
function movesWithin(root, from, backward, wrap, radioContext, side = "on", position = { holder: null }) {
|
|
456
486
|
const walk = {
|
|
457
487
|
from,
|
|
488
|
+
side,
|
|
458
489
|
tree: [],
|
|
459
490
|
fromAt: from === root ? 0 : -1,
|
|
460
491
|
excludedScope: null
|
|
@@ -462,26 +493,111 @@ function movesWithin(root, from, backward, wrap, radioContext) {
|
|
|
462
493
|
const order = orderScope(ownedScope(root) ?? Array.from(root.children), walk);
|
|
463
494
|
const radios = radioContext ?? {
|
|
464
495
|
tree: walk.tree,
|
|
465
|
-
focusedRadio: walk.fromAt >= 0 && isRadio(from) ? from : null
|
|
496
|
+
focusedRadio: side === "on" && walk.fromAt >= 0 && isRadio(from) ? from : null
|
|
466
497
|
};
|
|
467
|
-
const isStop = (element) => passesRadioRule(element, radios.tree, radios.focusedRadio);
|
|
498
|
+
const isStop = (element) => passesRadioRule(element, radios.tree, radios.focusedRadio, backward);
|
|
499
|
+
const holds = (element) => position.holder !== null && flatTreeContains(element, position.holder);
|
|
468
500
|
const start = startIndex(
|
|
469
501
|
order,
|
|
470
502
|
walk,
|
|
471
503
|
backward,
|
|
472
|
-
(element) => order.includes(element) && isStop(element)
|
|
504
|
+
(element) => order.includes(element) && isStop(element) && !holds(element)
|
|
473
505
|
);
|
|
474
506
|
const remaining = backward ? order.slice(0, start + 1).reverse() : order.slice(start);
|
|
475
507
|
const wrapped = wrap ? backward ? order.slice(start + 1).reverse() : order.slice(0, start) : [];
|
|
476
508
|
const excluded = walk.excludedScope;
|
|
477
|
-
const prefix = excluded && !(backward && from === excluded) ? movesWithin(
|
|
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
|
+
) : [];
|
|
478
518
|
return [
|
|
479
519
|
...prefix,
|
|
480
|
-
...[...remaining, ...wrapped].filter(
|
|
520
|
+
...[...remaining, ...wrapped].filter(
|
|
521
|
+
(element) => (side !== "on" || element !== from) && isStop(element)
|
|
522
|
+
)
|
|
481
523
|
];
|
|
482
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
|
+
}
|
|
483
593
|
function sequentialTabStops(root, from = null, backward = false) {
|
|
484
|
-
return movesWithin(root, from, backward, true);
|
|
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
|
+
});
|
|
485
601
|
}
|
|
486
602
|
function deepActiveElement(ownerDocument) {
|
|
487
603
|
let active = ownerDocument.activeElement;
|
|
@@ -645,7 +761,7 @@ var INERT_MARK = `data-${FOCUS_TRAP_OWNER}-inert`;
|
|
|
645
761
|
var OVERFLOW_MARK = `data-${FOCUS_TRAP_OWNER}-overflow`;
|
|
646
762
|
var FocusTrap = class _FocusTrap {
|
|
647
763
|
static #registries = sharedRegistry(
|
|
648
|
-
"stimeo-ui.focus-trap.registry.
|
|
764
|
+
"stimeo-ui.focus-trap.registry.v3",
|
|
649
765
|
() => /* @__PURE__ */ new WeakMap()
|
|
650
766
|
);
|
|
651
767
|
static #TEXT_ENTRY_TYPES = /* @__PURE__ */ new Set([
|
|
@@ -671,15 +787,17 @@ var FocusTrap = class _FocusTrap {
|
|
|
671
787
|
this.#entry = this.#createEntry();
|
|
672
788
|
}
|
|
673
789
|
#createEntry() {
|
|
674
|
-
|
|
790
|
+
const entry = {
|
|
675
791
|
container: () => this.#readContainer(),
|
|
676
792
|
moveFocus: (backward) => this.#moveFocus(backward),
|
|
677
793
|
refocus: () => this.#refocus(),
|
|
678
794
|
isolated: false,
|
|
679
795
|
lockedBody: null,
|
|
680
796
|
openedFrom: null,
|
|
681
|
-
handedBack: []
|
|
797
|
+
handedBack: [],
|
|
798
|
+
returnTargets: () => this.#activeReturnTargets(entry)
|
|
682
799
|
};
|
|
800
|
+
return entry;
|
|
683
801
|
}
|
|
684
802
|
get active() {
|
|
685
803
|
return this.#activeState;
|
|
@@ -705,6 +823,7 @@ var FocusTrap = class _FocusTrap {
|
|
|
705
823
|
return;
|
|
706
824
|
}
|
|
707
825
|
const entry = this.#entry;
|
|
826
|
+
const parent = entry.openedFrom;
|
|
708
827
|
const openers = this.#openers;
|
|
709
828
|
this.#openers = [];
|
|
710
829
|
this.#activeState = false;
|
|
@@ -714,7 +833,7 @@ var FocusTrap = class _FocusTrap {
|
|
|
714
833
|
_FocusTrap.#reconcileBackground(document);
|
|
715
834
|
try {
|
|
716
835
|
const wayBack = this.#handOver(entry, openers, above);
|
|
717
|
-
if (restoreFocus) this.#restore(wayBack, above);
|
|
836
|
+
if (restoreFocus) this.#restore(wayBack, above, parent);
|
|
718
837
|
} finally {
|
|
719
838
|
this.#returnTabindexes();
|
|
720
839
|
}
|
|
@@ -753,6 +872,11 @@ var FocusTrap = class _FocusTrap {
|
|
|
753
872
|
document.addEventListener("keydown", registry2.onKeydown);
|
|
754
873
|
document.addEventListener("turbo:morph", registry2.onMorph);
|
|
755
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 });
|
|
756
880
|
}
|
|
757
881
|
registry2.stack.push(this.#entry);
|
|
758
882
|
}
|
|
@@ -765,6 +889,10 @@ var FocusTrap = class _FocusTrap {
|
|
|
765
889
|
document.removeEventListener("keydown", registry2.onKeydown);
|
|
766
890
|
document.removeEventListener("turbo:morph", registry2.onMorph);
|
|
767
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;
|
|
768
896
|
}
|
|
769
897
|
return above;
|
|
770
898
|
}
|
|
@@ -801,7 +929,7 @@ var FocusTrap = class _FocusTrap {
|
|
|
801
929
|
}
|
|
802
930
|
return wayBack;
|
|
803
931
|
}
|
|
804
|
-
#restore(wayBack, above) {
|
|
932
|
+
#restore(wayBack, above, parent) {
|
|
805
933
|
const active = deepActiveElement(document);
|
|
806
934
|
const released = this.#readContainer();
|
|
807
935
|
const holds = (trap) => {
|
|
@@ -812,7 +940,7 @@ var FocusTrap = class _FocusTrap {
|
|
|
812
940
|
return !released || !flatTreeContains(released, active) || flatTreeContains(released, container);
|
|
813
941
|
};
|
|
814
942
|
if (above.some(holds)) return;
|
|
815
|
-
for (const element of wayBack) {
|
|
943
|
+
for (const element of _FocusTrap.#returnCandidates(wayBack, parent)) {
|
|
816
944
|
if (this.#activeState) return;
|
|
817
945
|
if (!element.isConnected || !canTakeFocus(element) || !isRenderedForFocus(element)) continue;
|
|
818
946
|
const before = deepActiveElement(document);
|
|
@@ -822,6 +950,19 @@ var FocusTrap = class _FocusTrap {
|
|
|
822
950
|
}
|
|
823
951
|
_FocusTrap.#tabOwner(_FocusTrap.#registry(document).stack)?.refocus();
|
|
824
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
|
+
}
|
|
825
966
|
#refocus() {
|
|
826
967
|
if (!this.#flag(this.#options.autoFocus, true)) return;
|
|
827
968
|
if (flatTreeContains(this.#getContainer(), deepActiveElement(document))) return;
|
|
@@ -836,8 +977,8 @@ var FocusTrap = class _FocusTrap {
|
|
|
836
977
|
const focused = deepActiveElement(document);
|
|
837
978
|
for (const [element, loan] of [...this.#tabindexLoans]) {
|
|
838
979
|
if (element === focused) continue;
|
|
839
|
-
loan.returnAll();
|
|
840
980
|
this.#tabindexLoans.delete(element);
|
|
981
|
+
loan.returnAll();
|
|
841
982
|
}
|
|
842
983
|
}
|
|
843
984
|
#lockScroll() {
|
|
@@ -882,8 +1023,12 @@ var FocusTrap = class _FocusTrap {
|
|
|
882
1023
|
stack: [],
|
|
883
1024
|
onKeydown: (event) => _FocusTrap.#resolveTab(registry2.stack, event),
|
|
884
1025
|
onMorph: () => morphs.schedule(),
|
|
1026
|
+
onPointerDown: (event) => _FocusTrap.#recordPress(registry2, event),
|
|
1027
|
+
onFocusIn: (event) => _FocusTrap.#recordFocus(registry2, event),
|
|
885
1028
|
inerted: /* @__PURE__ */ new Set(),
|
|
886
|
-
scrollLocks: /* @__PURE__ */ new Set()
|
|
1029
|
+
scrollLocks: /* @__PURE__ */ new Set(),
|
|
1030
|
+
start: null,
|
|
1031
|
+
pressed: false
|
|
887
1032
|
};
|
|
888
1033
|
_FocusTrap.#registries.set(ownerDocument, registry2);
|
|
889
1034
|
return registry2;
|
|
@@ -981,7 +1126,7 @@ var FocusTrap = class _FocusTrap {
|
|
|
981
1126
|
return _FocusTrap.#tabOwner(_FocusTrap.#registry(document).stack) === this.#entry;
|
|
982
1127
|
}
|
|
983
1128
|
#moveFocus(backward) {
|
|
984
|
-
const from =
|
|
1129
|
+
const from = _FocusTrap.#start();
|
|
985
1130
|
for (const stop of sequentialTabStops(this.#getContainer(), from, backward)) {
|
|
986
1131
|
if (!this.#ownsTab()) return;
|
|
987
1132
|
const before = deepActiveElement(document);
|
|
@@ -992,18 +1137,66 @@ var FocusTrap = class _FocusTrap {
|
|
|
992
1137
|
return;
|
|
993
1138
|
}
|
|
994
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
|
+
}
|
|
995
1187
|
static #selectOnEntry(stop) {
|
|
996
1188
|
if (stop instanceof HTMLInputElement && _FocusTrap.#TEXT_ENTRY_TYPES.has(stop.type)) {
|
|
997
1189
|
stop.select();
|
|
998
1190
|
}
|
|
999
1191
|
}
|
|
1000
1192
|
#focusInitial() {
|
|
1193
|
+
const container = this.#readContainer();
|
|
1194
|
+
if (!container) return;
|
|
1001
1195
|
const preferred = this.#options.initialFocus?.();
|
|
1002
1196
|
if (preferred) {
|
|
1003
1197
|
preferred.focus();
|
|
1004
1198
|
return;
|
|
1005
1199
|
}
|
|
1006
|
-
const container = this.#getContainer();
|
|
1007
1200
|
const [first] = sequentialTabStops(container);
|
|
1008
1201
|
if (first) {
|
|
1009
1202
|
first.focus();
|
|
@@ -1142,10 +1335,10 @@ var ConfirmController = class _ConfirmController extends Controller {
|
|
|
1142
1335
|
}
|
|
1143
1336
|
#prompt(message) {
|
|
1144
1337
|
if (!this.#connected) return Promise.resolve(false);
|
|
1145
|
-
if (!this.hasDialogTarget) return Promise.resolve(window.confirm(message));
|
|
1146
1338
|
const asked = ++this.#asked;
|
|
1147
1339
|
this.#resolve(false);
|
|
1148
|
-
if (asked !== this.#asked) return Promise.resolve(false);
|
|
1340
|
+
if (!this.#connected || asked !== this.#asked) return Promise.resolve(false);
|
|
1341
|
+
if (!this.hasDialogTarget) return Promise.resolve(window.confirm(message));
|
|
1149
1342
|
this.#wording = { message, confirm: this.confirmLabelValue, cancel: this.cancelLabelValue };
|
|
1150
1343
|
this.#applyWording();
|
|
1151
1344
|
return new Promise((resolve) => {
|
|
@@ -1190,12 +1383,10 @@ var ConfirmController = class _ConfirmController extends Controller {
|
|
|
1190
1383
|
if (dialog) this.#hidden.write(dialog, "");
|
|
1191
1384
|
return;
|
|
1192
1385
|
}
|
|
1193
|
-
if (
|
|
1194
|
-
this.#
|
|
1195
|
-
|
|
1386
|
+
if (dialog) {
|
|
1387
|
+
this.#hidden.write(dialog, null);
|
|
1388
|
+
this.#applyWording();
|
|
1196
1389
|
}
|
|
1197
|
-
this.#hidden.write(dialog, null);
|
|
1198
|
-
this.#applyWording();
|
|
1199
1390
|
this.#trap.refreshContainer();
|
|
1200
1391
|
}
|
|
1201
1392
|
#messageOf(element, submitter) {
|
|
@@ -39,6 +39,7 @@ function hasModifierChord(event) {
|
|
|
39
39
|
|
|
40
40
|
function setAttributeIfChanged(element, name, value, beforeWrite) {
|
|
41
41
|
if (element.getAttribute(name) === value) return false;
|
|
42
|
+
beforeWrite?.();
|
|
42
43
|
if (value === null) element.removeAttribute(name);
|
|
43
44
|
else element.setAttribute(name, value);
|
|
44
45
|
return true;
|
|
@@ -112,14 +113,34 @@ var AttributeLease = class {
|
|
|
112
113
|
const names = registry.names;
|
|
113
114
|
names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
|
|
114
115
|
}
|
|
115
|
-
write(element, value) {
|
|
116
|
+
write(element, value, beforeWrite) {
|
|
116
117
|
const stack = attributeStack(element, this.#attribute);
|
|
117
118
|
const hold = this.#take(stack) ?? this.#acquire(element, stack);
|
|
118
119
|
this.#held.add(element);
|
|
119
120
|
const shows = !this.#covered(element, stack, hold);
|
|
120
121
|
hold.written = value;
|
|
121
122
|
this.#mark(element, stack);
|
|
122
|
-
if (shows) this.#reflect(element, value);
|
|
123
|
+
if (shows) this.#reflect(element, value, beforeWrite);
|
|
124
|
+
}
|
|
125
|
+
adopt(element, options = {}) {
|
|
126
|
+
const known = registry.stacks.get(element)?.has(this.#attribute);
|
|
127
|
+
if (!this.#held.has(element) && !known && !element.hasAttribute(this.#record)) return false;
|
|
128
|
+
const stack = attributeStack(element, this.#attribute);
|
|
129
|
+
const hold = this.#take(stack);
|
|
130
|
+
if (!hold) return false;
|
|
131
|
+
const current = element.getAttribute(this.#attribute);
|
|
132
|
+
if (options.ifChanged && (current === hold.written || this.#covered(element, stack, hold))) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
this.#held.add(element);
|
|
136
|
+
hold.original = current;
|
|
137
|
+
hold.linked = false;
|
|
138
|
+
for (const above of stack.slice(stack.indexOf(hold) + 1)) {
|
|
139
|
+
if (!above.linked) break;
|
|
140
|
+
above.original = current;
|
|
141
|
+
}
|
|
142
|
+
this.#mark(element, stack);
|
|
143
|
+
return true;
|
|
123
144
|
}
|
|
124
145
|
return(element) {
|
|
125
146
|
const held = this.#held.delete(element);
|
|
@@ -185,8 +206,8 @@ var AttributeLease = class {
|
|
|
185
206
|
setAttributeIfChanged(element, name, recorded);
|
|
186
207
|
}
|
|
187
208
|
}
|
|
188
|
-
#reflect(element, value) {
|
|
189
|
-
setAttributeIfChanged(element, this.#attribute, value);
|
|
209
|
+
#reflect(element, value, beforeWrite) {
|
|
210
|
+
setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
|
|
190
211
|
}
|
|
191
212
|
};
|
|
192
213
|
|
|
@@ -338,11 +359,14 @@ var ContextMenuController = class _ContextMenuController extends Controller {
|
|
|
338
359
|
#menuHidden = new AttributeLease("hidden", this.identifier);
|
|
339
360
|
#regionState = new AttributeLease("data-state", this.identifier);
|
|
340
361
|
#menu = null;
|
|
362
|
+
#openState = false;
|
|
363
|
+
#position = ["", ""];
|
|
341
364
|
#connected = false;
|
|
342
365
|
#reporting = false;
|
|
343
366
|
#clickVerdicts = new ClickVerdicts();
|
|
344
367
|
#listeners = new ListenerSet();
|
|
345
368
|
connect() {
|
|
369
|
+
this.#menu = this.hasMenuTarget ? this.menuTarget : null;
|
|
346
370
|
this.#closeMenu("api");
|
|
347
371
|
this.#listeners.add(this.element, "click", this.#onItemClickCapture, { capture: true });
|
|
348
372
|
this.#listeners.add(document, "click", this.#onOutsidePointer, { capture: true });
|
|
@@ -438,52 +462,57 @@ var ContextMenuController = class _ContextMenuController extends Controller {
|
|
|
438
462
|
);
|
|
439
463
|
}
|
|
440
464
|
#openAt(x, y, reason) {
|
|
441
|
-
if (!this.hasMenuTarget) return;
|
|
442
465
|
this.#timers.clearAll();
|
|
443
|
-
|
|
466
|
+
this.#adoptMenu();
|
|
444
467
|
const was = this.#isOpen;
|
|
468
|
+
this.#openState = true;
|
|
469
|
+
this.#position = [`${x}px`, `${y}px`];
|
|
445
470
|
this.#escapeLayer.activate(document, {
|
|
446
471
|
onDismiss: () => this.#closeAndRestore("escape"),
|
|
447
472
|
claims: claimsWhileFocusWithin(this.element)
|
|
448
473
|
});
|
|
449
|
-
menu
|
|
450
|
-
|
|
451
|
-
this.#menuHidden.write(menu, null);
|
|
452
|
-
this.#menu = menu;
|
|
453
|
-
if (this.hasRegionTarget) this.#regionState.write(this.regionTarget, "open");
|
|
474
|
+
if (this.#menu) this.#showMenu(this.#menu);
|
|
475
|
+
this.#reflectRegion();
|
|
454
476
|
if (!was && this.#reporting) this.dispatch("open", { detail: { reason }, cancelable: false });
|
|
455
|
-
|
|
477
|
+
this.#adoptMenu();
|
|
478
|
+
if (!this.#menu || !this.#isOpen) return;
|
|
456
479
|
this.#navigableItems[0]?.focus();
|
|
457
480
|
}
|
|
458
481
|
#closeMenu(reason) {
|
|
482
|
+
this.#adoptMenu();
|
|
483
|
+
const was = this.#isOpen;
|
|
459
484
|
this.#timers.clearAll();
|
|
460
485
|
this.#escapeLayer.deactivate();
|
|
461
|
-
|
|
462
|
-
this.#menu
|
|
463
|
-
|
|
464
|
-
const was = this.#isOpen;
|
|
465
|
-
this.#menuHidden.write(menu, "");
|
|
466
|
-
if (this.hasRegionTarget) this.#regionState.write(this.regionTarget, "closed");
|
|
486
|
+
this.#openState = false;
|
|
487
|
+
if (this.#menu) this.#menuHidden.write(this.#menu, "");
|
|
488
|
+
this.#reflectRegion();
|
|
467
489
|
if (was && this.#reporting) this.dispatch("close", { detail: { reason }, cancelable: false });
|
|
468
490
|
}
|
|
469
491
|
#adoptMenu() {
|
|
470
492
|
if (!this.#connected) return;
|
|
471
493
|
const menu = this.hasMenuTarget ? this.menuTarget : null;
|
|
472
494
|
const previous = this.#menu;
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
this.#
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
if (open) {
|
|
479
|
-
for (const property of _ContextMenuController.#COORDINATE) {
|
|
480
|
-
menu.style.setProperty(property, previous.style.getPropertyValue(property));
|
|
481
|
-
}
|
|
495
|
+
if (previous) {
|
|
496
|
+
this.#openState = !previous.hidden;
|
|
497
|
+
if (this.#openState && menu !== previous) {
|
|
498
|
+
const [x, y] = _ContextMenuController.#COORDINATE;
|
|
499
|
+
this.#position = [previous.style.getPropertyValue(x), previous.style.getPropertyValue(y)];
|
|
482
500
|
}
|
|
483
|
-
|
|
501
|
+
}
|
|
502
|
+
this.#menu = menu;
|
|
503
|
+
if (!this.#openState) this.#escapeLayer.deactivate();
|
|
504
|
+
if (menu && menu !== previous) {
|
|
505
|
+
if (this.#openState) this.#showMenu(menu);
|
|
506
|
+
else this.#menuHidden.write(menu, "");
|
|
484
507
|
}
|
|
485
508
|
this.#reflectRegion();
|
|
486
509
|
}
|
|
510
|
+
#showMenu(menu) {
|
|
511
|
+
const [x, y] = _ContextMenuController.#COORDINATE;
|
|
512
|
+
menu.style.setProperty(x, this.#position[0]);
|
|
513
|
+
menu.style.setProperty(y, this.#position[1]);
|
|
514
|
+
this.#menuHidden.write(menu, null);
|
|
515
|
+
}
|
|
487
516
|
#reflectRegion() {
|
|
488
517
|
if (!this.hasRegionTarget) return;
|
|
489
518
|
this.#regionState.write(this.regionTarget, this.#isOpen ? "open" : "closed");
|
|
@@ -517,7 +546,7 @@ var ContextMenuController = class _ContextMenuController extends Controller {
|
|
|
517
546
|
return !this.#isNavigable(item) || isAriaDisabled(item);
|
|
518
547
|
}
|
|
519
548
|
get #isOpen() {
|
|
520
|
-
return this
|
|
549
|
+
return this.#menu ? !this.#menu.hidden : this.#openState;
|
|
521
550
|
}
|
|
522
551
|
};
|
|
523
552
|
|
|
@@ -114,7 +114,7 @@ var CompositionTracker = class {
|
|
|
114
114
|
this.#confirmedTarget = null;
|
|
115
115
|
if (confirmed === null || confirmed !== event.target) return false;
|
|
116
116
|
const inputType = event.inputType;
|
|
117
|
-
return
|
|
117
|
+
return inputType ? isCompositionInputType(inputType) : event.isTrusted === true;
|
|
118
118
|
}
|
|
119
119
|
#release(target) {
|
|
120
120
|
target.removeEventListener("compositionstart", this.#handleStart);
|