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
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 39db221aeffefadda5ac2ba6f447de9a68e37c3e59f88b9b152ac776f05b3844
|
|
4
|
+
data.tar.gz: 4fbc0cf886a5e8089c466f5b775f90afbcf1d055bb6d8d3c2236529c72a902c2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 942b36cd7302fe31729b88c943b125aa041b326bc3e50b309cdfbc8cb97696baced2b384521099137f42fc4e69a80cfd7b479246ee7f047515ef6d90c1df3374
|
|
7
|
+
data.tar.gz: f23082bc52eb8553d9bf4d909705b98102541419fad5b79eb0fc5affa3d55a43c09f97045a10bdd850304e2545fbbfcbe02ee9b9609b76844bef7807ead649ff
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,38 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
While the version is `0.x`, the public API (the `stimeo--*` data attributes) may
|
|
8
8
|
change between releases.
|
|
9
9
|
|
|
10
|
+
## [0.19.0] - 2026-11-25
|
|
11
|
+
|
|
12
|
+
Minor release focused on keyboard focus, IME editing, and replacing component
|
|
13
|
+
markup during page updates.
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
|
|
17
|
+
- **Breaking** tree-view: add a `group` target to each child group the controller
|
|
18
|
+
should show or hide. `role="group"` still defines the hierarchy. Groups without
|
|
19
|
+
the target keep the page's `hidden` state.
|
|
20
|
+
- **Breaking** focus traps now follow the browser's Tab starting position after
|
|
21
|
+
a click on non-focusable content or when the focused element is removed or
|
|
22
|
+
hidden. This affects dialog, alert-dialog, confirm, drawer, sidebar in overlay
|
|
23
|
+
mode, command-palette, and focus.
|
|
24
|
+
|
|
25
|
+
### Fixed
|
|
26
|
+
|
|
27
|
+
- Tab and Shift+Tab enter an unchecked radio group at its first and last
|
|
28
|
+
reachable options, respectively. Focus handoffs use the checked option when
|
|
29
|
+
one exists.
|
|
30
|
+
- editable: Cancel discards the edit when pressing it blurs the input before the
|
|
31
|
+
click. hover-card stays open while the pointer remains inside after focus moves.
|
|
32
|
+
- character-counter, currency-input, multi-select, and otp accept values written
|
|
33
|
+
by the page after IME confirmation, including after focus leaves the field.
|
|
34
|
+
- Components restore authored attributes when targets leave their scope and
|
|
35
|
+
preserve state when targets move within it.
|
|
36
|
+
- Menus, popups, and dialogs preserve their open state, pending actions, and
|
|
37
|
+
Escape dismissal while their targets are replaced.
|
|
38
|
+
- tags-input, multi-select, file-dropzone, and toast keep later lists inactive
|
|
39
|
+
until the first list leaves. multi-select announces removed chips by their
|
|
40
|
+
former labels.
|
|
41
|
+
|
|
10
42
|
## [0.18.2] - 2026-11-21
|
|
11
43
|
|
|
12
44
|
Patch release focused on numeric stepping, focus, and text editing.
|
|
@@ -1460,6 +1492,7 @@ Initial public alpha: 101 behavior-only, accessible Stimulus controllers driven
|
|
|
1460
1492
|
by `data-*` attributes, shipping no CSS. Published to npm (with provenance) and
|
|
1461
1493
|
RubyGems.
|
|
1462
1494
|
|
|
1495
|
+
[0.19.0]: https://github.com/taiyaky/stimeo-ui/releases/tag/v0.19.0
|
|
1463
1496
|
[0.18.2]: https://github.com/taiyaky/stimeo-ui/releases/tag/v0.18.2
|
|
1464
1497
|
[0.18.1]: https://github.com/taiyaky/stimeo-ui/releases/tag/v0.18.1
|
|
1465
1498
|
[0.18.0]: https://github.com/taiyaky/stimeo-ui/releases/tag/v0.18.0
|
|
@@ -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();
|
|
@@ -1066,6 +1259,8 @@ var AlertDialogController = class extends Controller {
|
|
|
1066
1259
|
fallbackFocus: () => this.hasTriggerTarget ? this.triggerTarget : null
|
|
1067
1260
|
});
|
|
1068
1261
|
#connected = false;
|
|
1262
|
+
#openState = false;
|
|
1263
|
+
#seenDialog = false;
|
|
1069
1264
|
#dialog = null;
|
|
1070
1265
|
#hidden = new AttributeLease("hidden", this.identifier);
|
|
1071
1266
|
#morphRender = new MorphRenderWatcher(() => this.#repair());
|
|
@@ -1073,16 +1268,19 @@ var AlertDialogController = class extends Controller {
|
|
|
1073
1268
|
this.#trap.connect();
|
|
1074
1269
|
if (this.hasDialogTarget) this.#hidden.write(this.dialogTarget, "");
|
|
1075
1270
|
this.#dialog = this.hasDialogTarget ? this.dialogTarget : null;
|
|
1271
|
+
this.#seenDialog = this.#dialog !== null;
|
|
1272
|
+
this.#openState = false;
|
|
1076
1273
|
this.#connected = true;
|
|
1077
1274
|
this.#morphRender.observe(this.element);
|
|
1078
1275
|
}
|
|
1079
1276
|
disconnect() {
|
|
1080
1277
|
this.#morphRender.disconnect();
|
|
1081
1278
|
this.#connected = false;
|
|
1279
|
+
this.#openState = false;
|
|
1082
1280
|
this.#trap.disconnect(this);
|
|
1083
1281
|
}
|
|
1084
1282
|
#repair() {
|
|
1085
|
-
if (this.hasDialogTarget) this.#hidden.write(this.dialogTarget, this.#
|
|
1283
|
+
if (this.hasDialogTarget) this.#hidden.write(this.dialogTarget, this.#openState ? null : "");
|
|
1086
1284
|
}
|
|
1087
1285
|
dialogTargetConnected() {
|
|
1088
1286
|
if (this.#connected) this.#adoptDialog();
|
|
@@ -1093,11 +1291,14 @@ var AlertDialogController = class extends Controller {
|
|
|
1093
1291
|
if (this.#connected) this.#adoptDialog();
|
|
1094
1292
|
}
|
|
1095
1293
|
open() {
|
|
1096
|
-
|
|
1097
|
-
this.#
|
|
1294
|
+
this.#adoptDialog();
|
|
1295
|
+
if (!this.#connected || !this.#seenDialog || this.#isOpen) return;
|
|
1296
|
+
this.#openState = true;
|
|
1297
|
+
if (this.hasDialogTarget) this.#hidden.write(this.dialogTarget, null);
|
|
1098
1298
|
this.#trap.activate();
|
|
1099
1299
|
}
|
|
1100
1300
|
confirm() {
|
|
1301
|
+
this.#adoptDialog();
|
|
1101
1302
|
if (!this.#isOpen) return;
|
|
1102
1303
|
this.dispatch("confirm");
|
|
1103
1304
|
this.#closeDialog();
|
|
@@ -1106,31 +1307,34 @@ var AlertDialogController = class extends Controller {
|
|
|
1106
1307
|
this.#requestCancel("user");
|
|
1107
1308
|
}
|
|
1108
1309
|
#requestCancel(reason) {
|
|
1310
|
+
this.#adoptDialog();
|
|
1109
1311
|
if (!this.#isOpen) return;
|
|
1110
1312
|
this.dispatch("cancel", { detail: { reason } });
|
|
1111
1313
|
this.#closeDialog();
|
|
1112
1314
|
}
|
|
1113
1315
|
#closeDialog() {
|
|
1114
|
-
this.#
|
|
1316
|
+
this.#openState = false;
|
|
1317
|
+
this.#adoptDialog();
|
|
1318
|
+
if (this.hasDialogTarget) this.#hidden.write(this.dialogTarget, "");
|
|
1115
1319
|
this.#trap.deactivate();
|
|
1116
1320
|
}
|
|
1117
1321
|
#adoptDialog() {
|
|
1118
1322
|
const dialog = this.hasDialogTarget ? this.dialogTarget : null;
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
if (
|
|
1122
|
-
if (
|
|
1123
|
-
return;
|
|
1323
|
+
const previous = this.#dialog;
|
|
1324
|
+
if (dialog === previous) return;
|
|
1325
|
+
if (previous) {
|
|
1326
|
+
if (this.dialogTargets.includes(previous)) this.#hidden.write(previous, "");
|
|
1327
|
+
else this.#hidden.return(previous);
|
|
1124
1328
|
}
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1329
|
+
this.#dialog = dialog;
|
|
1330
|
+
if (dialog) {
|
|
1331
|
+
this.#seenDialog = true;
|
|
1332
|
+
this.#hidden.write(dialog, this.#openState ? null : "");
|
|
1128
1333
|
}
|
|
1129
|
-
this.#
|
|
1130
|
-
this.#trap.refreshContainer();
|
|
1334
|
+
if (this.#openState) this.#trap.refreshContainer();
|
|
1131
1335
|
}
|
|
1132
1336
|
get #isOpen() {
|
|
1133
|
-
return this
|
|
1337
|
+
return this.#openState;
|
|
1134
1338
|
}
|
|
1135
1339
|
};
|
|
1136
1340
|
|
|
@@ -13,6 +13,7 @@ function announce(message, options = {}) {
|
|
|
13
13
|
|
|
14
14
|
function setAttributeIfChanged(element, name, value, beforeWrite) {
|
|
15
15
|
if (element.getAttribute(name) === value) return false;
|
|
16
|
+
beforeWrite?.();
|
|
16
17
|
if (value === null) element.removeAttribute(name);
|
|
17
18
|
else element.setAttribute(name, value);
|
|
18
19
|
return true;
|
|
@@ -86,14 +87,34 @@ var AttributeLease = class {
|
|
|
86
87
|
const names = registry.names;
|
|
87
88
|
names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
|
|
88
89
|
}
|
|
89
|
-
write(element, value) {
|
|
90
|
+
write(element, value, beforeWrite) {
|
|
90
91
|
const stack = attributeStack(element, this.#attribute);
|
|
91
92
|
const hold = this.#take(stack) ?? this.#acquire(element, stack);
|
|
92
93
|
this.#held.add(element);
|
|
93
94
|
const shows = !this.#covered(element, stack, hold);
|
|
94
95
|
hold.written = value;
|
|
95
96
|
this.#mark(element, stack);
|
|
96
|
-
if (shows) this.#reflect(element, value);
|
|
97
|
+
if (shows) this.#reflect(element, value, beforeWrite);
|
|
98
|
+
}
|
|
99
|
+
adopt(element, options = {}) {
|
|
100
|
+
const known = registry.stacks.get(element)?.has(this.#attribute);
|
|
101
|
+
if (!this.#held.has(element) && !known && !element.hasAttribute(this.#record)) return false;
|
|
102
|
+
const stack = attributeStack(element, this.#attribute);
|
|
103
|
+
const hold = this.#take(stack);
|
|
104
|
+
if (!hold) return false;
|
|
105
|
+
const current = element.getAttribute(this.#attribute);
|
|
106
|
+
if (options.ifChanged && (current === hold.written || this.#covered(element, stack, hold))) {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
this.#held.add(element);
|
|
110
|
+
hold.original = current;
|
|
111
|
+
hold.linked = false;
|
|
112
|
+
for (const above of stack.slice(stack.indexOf(hold) + 1)) {
|
|
113
|
+
if (!above.linked) break;
|
|
114
|
+
above.original = current;
|
|
115
|
+
}
|
|
116
|
+
this.#mark(element, stack);
|
|
117
|
+
return true;
|
|
97
118
|
}
|
|
98
119
|
return(element) {
|
|
99
120
|
const held = this.#held.delete(element);
|
|
@@ -159,8 +180,8 @@ var AttributeLease = class {
|
|
|
159
180
|
setAttributeIfChanged(element, name, recorded);
|
|
160
181
|
}
|
|
161
182
|
}
|
|
162
|
-
#reflect(element, value) {
|
|
163
|
-
setAttributeIfChanged(element, this.#attribute, value);
|
|
183
|
+
#reflect(element, value, beforeWrite) {
|
|
184
|
+
setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
|
|
164
185
|
}
|
|
165
186
|
};
|
|
166
187
|
|
|
@@ -278,7 +299,7 @@ var CompositionTracker = class {
|
|
|
278
299
|
this.#confirmedTarget = null;
|
|
279
300
|
if (confirmed === null || confirmed !== event.target) return false;
|
|
280
301
|
const inputType = event.inputType;
|
|
281
|
-
return
|
|
302
|
+
return inputType ? isCompositionInputType(inputType) : event.isTrusted === true;
|
|
282
303
|
}
|
|
283
304
|
#release(target) {
|
|
284
305
|
target.removeEventListener("compositionstart", this.#handleStart);
|