stimeo-ui 0.18.1 → 0.18.2
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 +21 -0
- data/dist/cable/index.js +6 -5
- data/dist/controllers/alert_dialog_controller.js +89 -45
- data/dist/controllers/announcer_controller.js +22 -9
- data/dist/controllers/auto_submit_controller.js +77 -11
- data/dist/controllers/bulk_select_controller.js +6 -9
- data/dist/controllers/character_counter_controller.js +77 -11
- data/dist/controllers/clipboard_controller.js +6 -5
- data/dist/controllers/combobox_controller.js +71 -6
- data/dist/controllers/command_palette_controller.js +160 -51
- data/dist/controllers/conditional_fields_controller.js +84 -44
- data/dist/controllers/confirm_controller.js +89 -45
- data/dist/controllers/context_menu_controller.js +1 -1
- data/dist/controllers/countdown_controller.js +6 -5
- data/dist/controllers/currency_input_controller.js +71 -6
- data/dist/controllers/data_grid_controller.js +77 -42
- data/dist/controllers/date_range_picker_controller.js +2 -1
- data/dist/controllers/dialog_controller.js +89 -45
- data/dist/controllers/direct_upload_controller.js +6 -5
- data/dist/controllers/dismissible_controller.js +11 -7
- data/dist/controllers/drawer_controller.js +89 -45
- data/dist/controllers/dropdown_controller.js +1 -1
- data/dist/controllers/editable_controller.js +71 -6
- data/dist/controllers/empty_state_controller.js +6 -5
- data/dist/controllers/file_dropzone_controller.js +13 -11
- data/dist/controllers/flash_controller.js +6 -5
- data/dist/controllers/focus_controller.js +89 -45
- data/dist/controllers/form_field_controller.js +6 -5
- data/dist/controllers/form_validation_controller.js +11 -7
- data/dist/controllers/frame_loading_controller.js +50 -16
- data/dist/controllers/hover_card_controller.js +1 -1
- data/dist/controllers/input_mask_controller.js +94 -36
- data/dist/controllers/intersection_controller.js +61 -29
- data/dist/controllers/lazy_frame_controller.js +61 -29
- data/dist/controllers/listbox_controller.js +80 -47
- data/dist/controllers/local_time_controller.js +1 -7
- data/dist/controllers/menu_controller.js +1 -1
- data/dist/controllers/menubar_controller.js +4 -6
- data/dist/controllers/meter_controller.js +6 -5
- data/dist/controllers/multi_select_controller.js +86 -21
- data/dist/controllers/navigation_menu_controller.js +1 -1
- data/dist/controllers/nested_form_controller.js +17 -12
- data/dist/controllers/network_status_controller.js +6 -5
- data/dist/controllers/number_input_controller.js +154 -66
- data/dist/controllers/otp_controller.js +71 -6
- data/dist/controllers/overflow_menu_controller.js +7 -2
- data/dist/controllers/pagination_controller.js +7 -2
- data/dist/controllers/password_strength_controller.js +6 -5
- data/dist/controllers/popover_controller.js +12 -8
- data/dist/controllers/progress_controller.js +6 -5
- data/dist/controllers/radio_group_controller.js +85 -49
- data/dist/controllers/range_slider_controller.js +72 -54
- data/dist/controllers/relative_time_controller.js +1 -7
- data/dist/controllers/roving_controller.js +7 -2
- data/dist/controllers/scroll_area_controller.js +11 -7
- data/dist/controllers/scrollspy_controller.js +61 -29
- data/dist/controllers/separator_controller.js +72 -54
- data/dist/controllers/sidebar_controller.js +89 -45
- data/dist/controllers/skeleton_controller.js +50 -16
- data/dist/controllers/slider_controller.js +72 -54
- data/dist/controllers/sortable_controller.js +6 -5
- data/dist/controllers/spinner_controller.js +50 -16
- data/dist/controllers/sticky_observer_controller.js +61 -29
- data/dist/controllers/submit_once_controller.js +6 -5
- data/dist/controllers/switch_controller.js +84 -44
- data/dist/controllers/tags_input_controller.js +83 -20
- data/dist/controllers/time_picker_controller.js +77 -42
- data/dist/controllers/toggle_group_controller.js +84 -44
- data/dist/controllers/toolbar_controller.js +78 -8
- data/dist/controllers/tooltip_controller.js +1 -1
- data/dist/controllers/tree_view_controller.js +87 -49
- data/dist/index.js +503 -286
- data/lib/stimeo/ui/version.rb +1 -1
- metadata +2 -2
|
@@ -10,43 +10,66 @@ function setAttributeIfChanged(element, name, value, beforeWrite) {
|
|
|
10
10
|
|
|
11
11
|
var AuthoredMutationWatcher = class {
|
|
12
12
|
#onAuthored;
|
|
13
|
-
#
|
|
14
|
-
#observer = null;
|
|
13
|
+
#lifetime = null;
|
|
15
14
|
constructor(onAuthored) {
|
|
16
15
|
this.#onAuthored = onAuthored;
|
|
17
16
|
}
|
|
18
17
|
observe(root, options) {
|
|
19
|
-
this
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
this.#
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
18
|
+
const previous = this.#lifetime;
|
|
19
|
+
const lifetime = {
|
|
20
|
+
observer: null,
|
|
21
|
+
active: false,
|
|
22
|
+
claims: { attributes: /* @__PURE__ */ new Map(), children: /* @__PURE__ */ new Map() }
|
|
23
|
+
};
|
|
24
|
+
this.#lifetime = lifetime;
|
|
25
|
+
let observer = null;
|
|
26
|
+
try {
|
|
27
|
+
if (previous) this.#release(previous);
|
|
28
|
+
if (this.#lifetime !== lifetime) return;
|
|
29
|
+
const attributes = [...options.attributes];
|
|
30
|
+
const subtree = options.subtree ?? false;
|
|
31
|
+
const childList = options.childList ?? false;
|
|
32
|
+
const inherited = options.ancestorAttributes;
|
|
33
|
+
const ancestorAttributes = inherited ? [...inherited] : null;
|
|
34
|
+
if (this.#lifetime !== lifetime) return;
|
|
35
|
+
observer = new MutationObserver((records) => {
|
|
36
|
+
const authored = this.#filter(records, lifetime.claims);
|
|
37
|
+
if (this.#lifetime === lifetime && lifetime.active && authored.length > 0) {
|
|
38
|
+
this.#onAuthored(authored);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
if (this.#lifetime !== lifetime) return;
|
|
42
|
+
lifetime.observer = observer;
|
|
43
|
+
observer.observe(root, { attributes: true, attributeFilter: attributes, subtree, childList });
|
|
44
|
+
if (this.#lifetime !== lifetime) {
|
|
45
|
+
this.#release(lifetime, observer);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (ancestorAttributes) {
|
|
49
|
+
let ancestor = root.parentElement;
|
|
50
|
+
while (ancestor) {
|
|
51
|
+
observer.observe(ancestor, { attributes: true, attributeFilter: ancestorAttributes });
|
|
52
|
+
if (this.#lifetime !== lifetime) {
|
|
53
|
+
this.#release(lifetime, observer);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
ancestor = ancestor.parentElement;
|
|
57
|
+
}
|
|
41
58
|
}
|
|
59
|
+
lifetime.active = true;
|
|
60
|
+
} catch (error) {
|
|
61
|
+
this.#release(lifetime, observer);
|
|
62
|
+
throw error;
|
|
42
63
|
}
|
|
43
64
|
}
|
|
44
65
|
claim(target, name, value) {
|
|
45
|
-
const
|
|
46
|
-
|
|
66
|
+
const lifetime = this.#lifetime;
|
|
67
|
+
if (!lifetime?.active) return;
|
|
68
|
+
const claims = lifetime.claims.attributes;
|
|
69
|
+
let attributes = claims.get(target);
|
|
47
70
|
if (!attributes) {
|
|
48
71
|
attributes = /* @__PURE__ */ new Map();
|
|
49
|
-
claims
|
|
72
|
+
claims.set(target, attributes);
|
|
50
73
|
}
|
|
51
74
|
const pending = attributes.get(name);
|
|
52
75
|
attributes.set(name, { value, count: (pending?.count ?? 0) + 1 });
|
|
@@ -55,37 +78,49 @@ var AuthoredMutationWatcher = class {
|
|
|
55
78
|
this.claim(target, name, target.getAttribute(name));
|
|
56
79
|
}
|
|
57
80
|
claimChildList(target, added, removed) {
|
|
58
|
-
const
|
|
59
|
-
|
|
81
|
+
const lifetime = this.#lifetime;
|
|
82
|
+
if (!lifetime?.active) return;
|
|
83
|
+
const claims = lifetime.claims.children;
|
|
84
|
+
const pending = claims.get(target) ?? { added: /* @__PURE__ */ new Map(), removed: /* @__PURE__ */ new Map() };
|
|
60
85
|
for (const node of added) pending.added.set(node, (pending.added.get(node) ?? 0) + 1);
|
|
61
86
|
for (const node of removed) pending.removed.set(node, (pending.removed.get(node) ?? 0) + 1);
|
|
62
|
-
claims
|
|
87
|
+
claims.set(target, pending);
|
|
63
88
|
}
|
|
64
89
|
take() {
|
|
65
|
-
|
|
90
|
+
const lifetime = this.#lifetime;
|
|
91
|
+
const observer = lifetime?.observer;
|
|
92
|
+
if (!lifetime?.active || !observer) return [];
|
|
93
|
+
const records = observer.takeRecords();
|
|
94
|
+
const authored = this.#filter(records, lifetime.claims);
|
|
95
|
+
return this.#lifetime === lifetime && lifetime.active ? authored : [];
|
|
66
96
|
}
|
|
67
97
|
disconnect() {
|
|
68
|
-
this.#
|
|
69
|
-
this.#
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
98
|
+
const lifetime = this.#lifetime;
|
|
99
|
+
if (lifetime) this.#release(lifetime);
|
|
100
|
+
}
|
|
101
|
+
#release(lifetime, observer = lifetime.observer) {
|
|
102
|
+
if (this.#lifetime === lifetime) this.#lifetime = null;
|
|
103
|
+
lifetime.claims.attributes.clear();
|
|
104
|
+
lifetime.claims.children.clear();
|
|
105
|
+
observer?.disconnect();
|
|
106
|
+
}
|
|
107
|
+
#filter(records, claims) {
|
|
108
|
+
const authored = records.filter((record) => !this.#consume(record, claims));
|
|
109
|
+
claims.attributes.clear();
|
|
110
|
+
claims.children.clear();
|
|
76
111
|
return authored;
|
|
77
112
|
}
|
|
78
|
-
#consume(record) {
|
|
113
|
+
#consume(record, claims) {
|
|
79
114
|
if (record.type === "attributes") {
|
|
80
115
|
const target = record.target;
|
|
81
|
-
const pending2 =
|
|
116
|
+
const pending2 = claims.attributes.get(target)?.get(record.attributeName);
|
|
82
117
|
if (!pending2 || pending2.count === 0 || target.getAttribute(record.attributeName) !== pending2.value) {
|
|
83
118
|
return false;
|
|
84
119
|
}
|
|
85
120
|
pending2.count -= 1;
|
|
86
121
|
return true;
|
|
87
122
|
}
|
|
88
|
-
const pending =
|
|
123
|
+
const pending = claims.children.get(record.target);
|
|
89
124
|
if (!pending) return false;
|
|
90
125
|
const added = [...record.addedNodes];
|
|
91
126
|
const removed = [...record.removedNodes];
|
|
@@ -103,11 +138,16 @@ function ownerIndex(candidates, node) {
|
|
|
103
138
|
return candidates.findIndex((candidate) => candidate.contains(node));
|
|
104
139
|
}
|
|
105
140
|
|
|
141
|
+
var HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
|
|
106
142
|
function inheritsFieldsetDisabled(control) {
|
|
107
143
|
let fieldset = control.closest("fieldset[disabled]");
|
|
108
144
|
while (fieldset) {
|
|
109
|
-
|
|
110
|
-
|
|
145
|
+
if (fieldset.namespaceURI === HTML_NAMESPACE && fieldset.localName === "fieldset") {
|
|
146
|
+
const legend = Array.from(fieldset.children).find(
|
|
147
|
+
(child) => child.namespaceURI === HTML_NAMESPACE && child.localName === "legend"
|
|
148
|
+
);
|
|
149
|
+
if (!legend?.contains(control)) return true;
|
|
150
|
+
}
|
|
111
151
|
fieldset = fieldset.parentElement?.closest("fieldset[disabled]") ?? null;
|
|
112
152
|
}
|
|
113
153
|
return false;
|
|
@@ -197,6 +197,7 @@ var EscapeLayer = class _EscapeLayer {
|
|
|
197
197
|
);
|
|
198
198
|
#active = null;
|
|
199
199
|
activate(ownerDocument = document, options) {
|
|
200
|
+
const entry = { onDismiss: options.onDismiss, claims: options.claims ?? null };
|
|
200
201
|
this.deactivate();
|
|
201
202
|
let registry2 = _EscapeLayer.#registries.get(ownerDocument);
|
|
202
203
|
if (!registry2) {
|
|
@@ -204,7 +205,6 @@ var EscapeLayer = class _EscapeLayer {
|
|
|
204
205
|
_EscapeLayer.#registries.set(ownerDocument, registry2);
|
|
205
206
|
ownerDocument.addEventListener("keydown", registry2.onKeydown);
|
|
206
207
|
}
|
|
207
|
-
const entry = { onDismiss: options.onDismiss, claims: options.claims ?? null };
|
|
208
208
|
registry2.stack.push(entry);
|
|
209
209
|
this.#active = { document: ownerDocument, entry };
|
|
210
210
|
}
|
|
@@ -253,11 +253,16 @@ var EscapeLayer = class _EscapeLayer {
|
|
|
253
253
|
}
|
|
254
254
|
};
|
|
255
255
|
|
|
256
|
+
var HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
|
|
256
257
|
function inheritsFieldsetDisabled(control) {
|
|
257
258
|
let fieldset = control.closest("fieldset[disabled]");
|
|
258
259
|
while (fieldset) {
|
|
259
|
-
|
|
260
|
-
|
|
260
|
+
if (fieldset.namespaceURI === HTML_NAMESPACE && fieldset.localName === "fieldset") {
|
|
261
|
+
const legend = Array.from(fieldset.children).find(
|
|
262
|
+
(child) => child.namespaceURI === HTML_NAMESPACE && child.localName === "legend"
|
|
263
|
+
);
|
|
264
|
+
if (!legend?.contains(control)) return true;
|
|
265
|
+
}
|
|
261
266
|
fieldset = fieldset.parentElement?.closest("fieldset[disabled]") ?? null;
|
|
262
267
|
}
|
|
263
268
|
return false;
|
|
@@ -330,11 +335,10 @@ function hasNativeTabStop(element) {
|
|
|
330
335
|
if (element.tagName === "AUDIO" || element.tagName === "VIDEO") {
|
|
331
336
|
return element.hasAttribute("controls");
|
|
332
337
|
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
return false;
|
|
338
|
+
const details = element.parentElement;
|
|
339
|
+
return details instanceof HTMLDetailsElement && Array.from(details.children).find(
|
|
340
|
+
(child) => child.namespaceURI === HTML_NAMESPACE && child.localName === "summary"
|
|
341
|
+
) === element;
|
|
338
342
|
}
|
|
339
343
|
function hasEditableTabStop(element) {
|
|
340
344
|
const value = element.getAttribute("contenteditable")?.toLowerCase();
|
|
@@ -397,8 +401,7 @@ function isSequentialStop(element) {
|
|
|
397
401
|
function ownedScope(element) {
|
|
398
402
|
if (element.shadowRoot) return Array.from(element.shadowRoot.children);
|
|
399
403
|
if (element instanceof HTMLSlotElement) {
|
|
400
|
-
|
|
401
|
-
return assigned.length > 0 ? assigned : Array.from(element.children);
|
|
404
|
+
return element.assignedNodes().length > 0 ? element.assignedElements() : Array.from(element.children);
|
|
402
405
|
}
|
|
403
406
|
return null;
|
|
404
407
|
}
|
|
@@ -407,12 +410,19 @@ function orderScope(elements, walk) {
|
|
|
407
410
|
const visit = (element) => {
|
|
408
411
|
if (element === walk.from) walk.fromAt = walk.tree.length;
|
|
409
412
|
const tabindex = authoredTabindex(element) ?? 0;
|
|
410
|
-
|
|
411
|
-
if (
|
|
413
|
+
let stop = null;
|
|
414
|
+
if ((element instanceof HTMLElement || element instanceof SVGElement) && isSequentialStop(element)) {
|
|
415
|
+
stop = element;
|
|
416
|
+
walk.tree.push(element);
|
|
417
|
+
}
|
|
412
418
|
const owned = ownedScope(element);
|
|
413
419
|
if (owned) {
|
|
414
420
|
if (tabindex >= 0) {
|
|
415
421
|
entries.push({ tabindex, stops: [...stop ? [stop] : [], ...orderScope(owned, walk)] });
|
|
422
|
+
} else if (walk.from && flatTreeContains(element, walk.from)) {
|
|
423
|
+
walk.fromAt = walk.tree.length;
|
|
424
|
+
walk.excludedScope = element;
|
|
425
|
+
orderScope(owned, { from: walk.from, tree: walk.tree, fromAt: -1, excludedScope: null });
|
|
416
426
|
}
|
|
417
427
|
return;
|
|
418
428
|
}
|
|
@@ -440,16 +450,38 @@ function startIndex(order, walk, backward, isStop) {
|
|
|
440
450
|
if (at >= 0) return backward ? at - 1 : at + 1;
|
|
441
451
|
const neighbour = backward ? walk.tree.slice(0, walk.fromAt).reverse().find(isStop) : walk.tree.slice(walk.fromAt).find(isStop);
|
|
442
452
|
if (neighbour) return order.indexOf(neighbour);
|
|
443
|
-
return backward ?
|
|
453
|
+
return backward ? -1 : order.length;
|
|
444
454
|
}
|
|
445
|
-
function
|
|
446
|
-
const walk = {
|
|
455
|
+
function movesWithin(root, from, backward, wrap, radioContext) {
|
|
456
|
+
const walk = {
|
|
457
|
+
from,
|
|
458
|
+
tree: [],
|
|
459
|
+
fromAt: from === root ? 0 : -1,
|
|
460
|
+
excludedScope: null
|
|
461
|
+
};
|
|
447
462
|
const order = orderScope(ownedScope(root) ?? Array.from(root.children), walk);
|
|
448
|
-
const
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
463
|
+
const radios = radioContext ?? {
|
|
464
|
+
tree: walk.tree,
|
|
465
|
+
focusedRadio: walk.fromAt >= 0 && isRadio(from) ? from : null
|
|
466
|
+
};
|
|
467
|
+
const isStop = (element) => passesRadioRule(element, radios.tree, radios.focusedRadio);
|
|
468
|
+
const start = startIndex(
|
|
469
|
+
order,
|
|
470
|
+
walk,
|
|
471
|
+
backward,
|
|
472
|
+
(element) => order.includes(element) && isStop(element)
|
|
473
|
+
);
|
|
474
|
+
const remaining = backward ? order.slice(0, start + 1).reverse() : order.slice(start);
|
|
475
|
+
const wrapped = wrap ? backward ? order.slice(start + 1).reverse() : order.slice(0, start) : [];
|
|
476
|
+
const excluded = walk.excludedScope;
|
|
477
|
+
const prefix = excluded && !(backward && from === excluded) ? movesWithin(excluded, from === excluded ? null : from, backward, false, radios) : [];
|
|
478
|
+
return [
|
|
479
|
+
...prefix,
|
|
480
|
+
...[...remaining, ...wrapped].filter((element) => element !== from && isStop(element))
|
|
481
|
+
];
|
|
482
|
+
}
|
|
483
|
+
function sequentialTabStops(root, from = null, backward = false) {
|
|
484
|
+
return movesWithin(root, from, backward, true);
|
|
453
485
|
}
|
|
454
486
|
function deepActiveElement(ownerDocument) {
|
|
455
487
|
let active = ownerDocument.activeElement;
|
|
@@ -636,7 +668,10 @@ var FocusTrap = class _FocusTrap {
|
|
|
636
668
|
constructor(getContainer, options = {}) {
|
|
637
669
|
this.#getContainer = getContainer;
|
|
638
670
|
this.#options = options;
|
|
639
|
-
this.#entry =
|
|
671
|
+
this.#entry = this.#createEntry();
|
|
672
|
+
}
|
|
673
|
+
#createEntry() {
|
|
674
|
+
return {
|
|
640
675
|
container: () => this.#readContainer(),
|
|
641
676
|
moveFocus: (backward) => this.#moveFocus(backward),
|
|
642
677
|
refocus: () => this.#refocus(),
|
|
@@ -652,6 +687,7 @@ var FocusTrap = class _FocusTrap {
|
|
|
652
687
|
activate() {
|
|
653
688
|
if (this.#activeState) return;
|
|
654
689
|
_FocusTrap.#sweep();
|
|
690
|
+
this.#entry = this.#createEntry();
|
|
655
691
|
this.#activeState = true;
|
|
656
692
|
this.#openers = _FocusTrap.#focusPath();
|
|
657
693
|
this.#entry.openedFrom = _FocusTrap.#trapHolding(this.#openers[0] ?? null);
|
|
@@ -668,14 +704,20 @@ var FocusTrap = class _FocusTrap {
|
|
|
668
704
|
this.#returnTabindexes();
|
|
669
705
|
return;
|
|
670
706
|
}
|
|
707
|
+
const entry = this.#entry;
|
|
708
|
+
const openers = this.#openers;
|
|
709
|
+
this.#openers = [];
|
|
671
710
|
this.#activeState = false;
|
|
672
711
|
this.#escapeLayer.deactivate();
|
|
673
|
-
const above = this.#leaveStack();
|
|
674
|
-
this.#unlockScroll();
|
|
712
|
+
const above = this.#leaveStack(entry);
|
|
713
|
+
this.#unlockScroll(entry);
|
|
675
714
|
_FocusTrap.#reconcileBackground(document);
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
715
|
+
try {
|
|
716
|
+
const wayBack = this.#handOver(entry, openers, above);
|
|
717
|
+
if (restoreFocus) this.#restore(wayBack, above);
|
|
718
|
+
} finally {
|
|
719
|
+
this.#returnTabindexes();
|
|
720
|
+
}
|
|
679
721
|
}
|
|
680
722
|
connect() {
|
|
681
723
|
this.#gate.cancel();
|
|
@@ -714,9 +756,9 @@ var FocusTrap = class _FocusTrap {
|
|
|
714
756
|
}
|
|
715
757
|
registry2.stack.push(this.#entry);
|
|
716
758
|
}
|
|
717
|
-
#leaveStack() {
|
|
759
|
+
#leaveStack(entry) {
|
|
718
760
|
const registry2 = _FocusTrap.#registry(document);
|
|
719
|
-
const index = registry2.stack.indexOf(
|
|
761
|
+
const index = registry2.stack.indexOf(entry);
|
|
720
762
|
const above = registry2.stack.slice(index + 1);
|
|
721
763
|
registry2.stack.splice(index, 1);
|
|
722
764
|
if (registry2.stack.length === 0) {
|
|
@@ -740,21 +782,23 @@ var FocusTrap = class _FocusTrap {
|
|
|
740
782
|
}
|
|
741
783
|
return null;
|
|
742
784
|
}
|
|
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 = [];
|
|
785
|
+
#handOver(entry, openers, above) {
|
|
786
|
+
const wayBack = [...openers];
|
|
787
|
+
const parent = entry.openedFrom;
|
|
788
|
+
const handedBack = entry.handedBack;
|
|
756
789
|
entry.openedFrom = null;
|
|
757
790
|
entry.handedBack = [];
|
|
791
|
+
try {
|
|
792
|
+
const fallback = this.#options.fallbackFocus?.();
|
|
793
|
+
if (fallback) wayBack.push(fallback);
|
|
794
|
+
} finally {
|
|
795
|
+
wayBack.push(...handedBack);
|
|
796
|
+
for (const trap of above) {
|
|
797
|
+
if (trap.openedFrom !== entry) continue;
|
|
798
|
+
trap.handedBack = [...trap.handedBack, ...wayBack];
|
|
799
|
+
trap.openedFrom = parent;
|
|
800
|
+
}
|
|
801
|
+
}
|
|
758
802
|
return wayBack;
|
|
759
803
|
}
|
|
760
804
|
#restore(wayBack, above) {
|
|
@@ -804,11 +848,11 @@ var FocusTrap = class _FocusTrap {
|
|
|
804
848
|
this.#entry.lockedBody = body;
|
|
805
849
|
body.style.overflow = "hidden";
|
|
806
850
|
}
|
|
807
|
-
#unlockScroll() {
|
|
851
|
+
#unlockScroll(entry) {
|
|
808
852
|
const registry2 = _FocusTrap.#registry(document);
|
|
809
|
-
const body =
|
|
810
|
-
|
|
811
|
-
if (!registry2.scrollLocks.delete(
|
|
853
|
+
const body = entry.lockedBody;
|
|
854
|
+
entry.lockedBody = null;
|
|
855
|
+
if (!registry2.scrollLocks.delete(entry) || !body) return;
|
|
812
856
|
if (!_FocusTrap.#isLocked(registry2, body)) _FocusTrap.#unlock(body);
|
|
813
857
|
}
|
|
814
858
|
static #isLocked(registry2, body) {
|
|
@@ -215,6 +215,7 @@ var EscapeLayer = class _EscapeLayer {
|
|
|
215
215
|
);
|
|
216
216
|
#active = null;
|
|
217
217
|
activate(ownerDocument = document, options) {
|
|
218
|
+
const entry = { onDismiss: options.onDismiss, claims: options.claims ?? null };
|
|
218
219
|
this.deactivate();
|
|
219
220
|
let registry2 = _EscapeLayer.#registries.get(ownerDocument);
|
|
220
221
|
if (!registry2) {
|
|
@@ -222,7 +223,6 @@ var EscapeLayer = class _EscapeLayer {
|
|
|
222
223
|
_EscapeLayer.#registries.set(ownerDocument, registry2);
|
|
223
224
|
ownerDocument.addEventListener("keydown", registry2.onKeydown);
|
|
224
225
|
}
|
|
225
|
-
const entry = { onDismiss: options.onDismiss, claims: options.claims ?? null };
|
|
226
226
|
registry2.stack.push(entry);
|
|
227
227
|
this.#active = { document: ownerDocument, entry };
|
|
228
228
|
}
|
|
@@ -7,14 +7,15 @@ function fillTemplate(template, values) {
|
|
|
7
7
|
});
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
var afterFocus = /* @__PURE__ */ Symbol.for("stimeo--announcer:after-focus");
|
|
10
11
|
function announce(message, options = {}) {
|
|
11
12
|
const text = message.trim();
|
|
12
13
|
if (text.length === 0) return;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
);
|
|
14
|
+
const event = new CustomEvent("stimeo--announcer:announce", {
|
|
15
|
+
detail: { message: text, assertive: options.assertive === true }
|
|
16
|
+
});
|
|
17
|
+
if (options.afterFocus) event[afterFocus] = true;
|
|
18
|
+
window.dispatchEvent(event);
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
var ListenerSet = class {
|
|
@@ -10,7 +10,50 @@ function isCompositionInputType(inputType) {
|
|
|
10
10
|
return inputType !== void 0 && COMPOSITION_INPUT_TYPES.has(inputType);
|
|
11
11
|
}
|
|
12
12
|
var BEFORE_MORPH_ATTRIBUTE = "turbo:before-morph-attribute";
|
|
13
|
-
var textOf = (element) =>
|
|
13
|
+
var textOf = (element) => {
|
|
14
|
+
if ("value" in element) return element.value;
|
|
15
|
+
return element instanceof Element ? element.textContent : void 0;
|
|
16
|
+
};
|
|
17
|
+
var nodesOf = (element) => {
|
|
18
|
+
const nodes = [];
|
|
19
|
+
if ("value" in element || !(element instanceof Element)) return nodes;
|
|
20
|
+
const walker = element.ownerDocument.createTreeWalker(element);
|
|
21
|
+
for (let node = walker.nextNode(); node !== null; node = walker.nextNode()) nodes.push(node);
|
|
22
|
+
return nodes;
|
|
23
|
+
};
|
|
24
|
+
var folded = (text) => text.replaceAll("\xA0", " ");
|
|
25
|
+
var startOf = (node, data, replaced, caret) => {
|
|
26
|
+
const text = folded(node.data);
|
|
27
|
+
const composed = folded(data);
|
|
28
|
+
if (replaced?.startContainer === node && text.startsWith(composed, replaced.startOffset)) {
|
|
29
|
+
return replaced.startOffset;
|
|
30
|
+
}
|
|
31
|
+
const start = text.lastIndexOf(composed, caret);
|
|
32
|
+
return start !== -1 && start + composed.length >= caret ? start : -1;
|
|
33
|
+
};
|
|
34
|
+
var spotOf = (element, replaced, data) => {
|
|
35
|
+
if ("value" in element || !(element instanceof Element)) return null;
|
|
36
|
+
const selection = element.ownerDocument.getSelection();
|
|
37
|
+
const node = selection?.focusNode;
|
|
38
|
+
if (!(node instanceof Text) || node.data === "" || !element.contains(node)) return null;
|
|
39
|
+
const range = element.ownerDocument.createRange();
|
|
40
|
+
const start = typeof data === "string" && data !== "" ? startOf(node, data, replaced, selection?.focusOffset ?? 0) : -1;
|
|
41
|
+
if (start === -1) {
|
|
42
|
+
range.selectNodeContents(node);
|
|
43
|
+
} else {
|
|
44
|
+
range.setStart(node, start);
|
|
45
|
+
range.setEnd(node, start + data.length);
|
|
46
|
+
}
|
|
47
|
+
return range;
|
|
48
|
+
};
|
|
49
|
+
var replacedBy = (event) => typeof event.getTargetRanges === "function" ? event.getTargetRanges()[0] ?? null : null;
|
|
50
|
+
var rewritten = ({ element, text, nodes, spot }) => {
|
|
51
|
+
if (spot !== null) {
|
|
52
|
+
return spot.collapsed || !(element instanceof Node && element.contains(spot.startContainer));
|
|
53
|
+
}
|
|
54
|
+
const current = nodesOf(element);
|
|
55
|
+
return textOf(element) !== text || current.length !== nodes.length || current.some((node, index) => node !== nodes[index]);
|
|
56
|
+
};
|
|
14
57
|
var holdsFocus = (element) => element instanceof Node && element.getRootNode().activeElement === element;
|
|
15
58
|
var CompositionTracker = class {
|
|
16
59
|
#observedTargets = /* @__PURE__ */ new Set();
|
|
@@ -101,11 +144,11 @@ var CompositionTracker = class {
|
|
|
101
144
|
}
|
|
102
145
|
#settle() {
|
|
103
146
|
const composition = this.#composition;
|
|
104
|
-
if (composition === null) return;
|
|
105
|
-
const { target, element
|
|
147
|
+
if (composition === null || !this.#observedTargets.has(composition.target)) return;
|
|
148
|
+
const { target, element } = composition;
|
|
106
149
|
if (target instanceof Node && element instanceof Node && !target.contains(element)) {
|
|
107
150
|
this.#composition = null;
|
|
108
|
-
} else if (
|
|
151
|
+
} else if (rewritten(composition)) {
|
|
109
152
|
this.#abandon(false);
|
|
110
153
|
}
|
|
111
154
|
}
|
|
@@ -130,7 +173,14 @@ var CompositionTracker = class {
|
|
|
130
173
|
this.#owe(true);
|
|
131
174
|
const target = event.currentTarget;
|
|
132
175
|
const element = event.target;
|
|
133
|
-
this.#composition = {
|
|
176
|
+
this.#composition = {
|
|
177
|
+
target,
|
|
178
|
+
element,
|
|
179
|
+
text: textOf(element),
|
|
180
|
+
nodes: nodesOf(element),
|
|
181
|
+
spot: spotOf(element, null, void 0),
|
|
182
|
+
replaced: null
|
|
183
|
+
};
|
|
134
184
|
this.#runAbandon();
|
|
135
185
|
this.#onStart?.(event);
|
|
136
186
|
};
|
|
@@ -154,6 +204,10 @@ var CompositionTracker = class {
|
|
|
154
204
|
if (this.#composition !== null && !keyComposing && !isComposing && inputType && !isCompositionInputType(inputType)) {
|
|
155
205
|
this.#abandon(true);
|
|
156
206
|
}
|
|
207
|
+
const composition = this.#composition;
|
|
208
|
+
if (composition !== null && event.target === composition.element) {
|
|
209
|
+
composition.replaced = replacedBy(event);
|
|
210
|
+
}
|
|
157
211
|
this.#runAbandon();
|
|
158
212
|
};
|
|
159
213
|
#handleInput = (event) => {
|
|
@@ -161,6 +215,15 @@ var CompositionTracker = class {
|
|
|
161
215
|
const { isTrusted, isComposing, inputType } = event;
|
|
162
216
|
if (composition !== null && event.target === composition.element && (isTrusted || isComposing || isCompositionInputType(inputType))) {
|
|
163
217
|
composition.text = textOf(composition.element);
|
|
218
|
+
composition.nodes = nodesOf(composition.element);
|
|
219
|
+
if (isCompositionInputType(inputType)) {
|
|
220
|
+
composition.spot = spotOf(
|
|
221
|
+
composition.element,
|
|
222
|
+
composition.replaced,
|
|
223
|
+
event.data
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
composition.replaced = null;
|
|
164
227
|
} else {
|
|
165
228
|
this.#settle();
|
|
166
229
|
}
|
|
@@ -181,7 +244,9 @@ var CompositionTracker = class {
|
|
|
181
244
|
const composition = this.#composition;
|
|
182
245
|
if (composition?.target !== event.currentTarget || event.target !== composition.element) return;
|
|
183
246
|
const detail = event.detail;
|
|
184
|
-
if (detail?.attributeName === "value"
|
|
247
|
+
if (detail?.attributeName === "value" && "value" in composition.element) {
|
|
248
|
+
event.preventDefault();
|
|
249
|
+
}
|
|
185
250
|
};
|
|
186
251
|
};
|
|
187
252
|
|