stimeo-ui 0.18.1 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +54 -0
- data/dist/cable/index.js +6 -5
- data/dist/controllers/alert_dialog_controller.js +324 -76
- data/dist/controllers/announcer_controller.js +22 -9
- data/dist/controllers/auto_submit_controller.js +103 -16
- data/dist/controllers/avatar_controller.js +29 -9
- data/dist/controllers/breadcrumb_controller.js +205 -17
- data/dist/controllers/bulk_select_controller.js +31 -13
- data/dist/controllers/calendar_controller.js +242 -7
- data/dist/controllers/carousel_controller.js +70 -15
- data/dist/controllers/character_counter_controller.js +103 -16
- data/dist/controllers/clipboard_controller.js +6 -5
- data/dist/controllers/collapsible_controller.js +35 -8
- data/dist/controllers/combobox_controller.js +155 -26
- data/dist/controllers/command_palette_controller.js +445 -117
- data/dist/controllers/conditional_fields_controller.js +84 -44
- data/dist/controllers/confirm_controller.js +303 -68
- data/dist/controllers/context_menu_controller.js +59 -30
- data/dist/controllers/countdown_controller.js +6 -5
- data/dist/controllers/currency_input_controller.js +72 -7
- data/dist/controllers/data_grid_controller.js +273 -51
- data/dist/controllers/date_range_picker_controller.js +27 -5
- data/dist/controllers/dialog_controller.js +330 -79
- data/dist/controllers/direct_upload_controller.js +6 -5
- data/dist/controllers/dismissible_controller.js +68 -18
- data/dist/controllers/drawer_controller.js +362 -92
- data/dist/controllers/dropdown_controller.js +64 -52
- data/dist/controllers/editable_controller.js +140 -12
- data/dist/controllers/empty_state_controller.js +193 -9
- data/dist/controllers/file_dropzone_controller.js +313 -23
- data/dist/controllers/filter_controller.js +194 -5
- data/dist/controllers/flash_controller.js +205 -17
- data/dist/controllers/focus_controller.js +273 -57
- data/dist/controllers/form_field_controller.js +71 -14
- data/dist/controllers/form_validation_controller.js +11 -7
- data/dist/controllers/frame_loading_controller.js +75 -20
- data/dist/controllers/hover_card_controller.js +108 -39
- data/dist/controllers/input_mask_controller.js +95 -37
- data/dist/controllers/intersection_controller.js +61 -29
- data/dist/controllers/lazy_frame_controller.js +61 -29
- data/dist/controllers/listbox_controller.js +174 -83
- data/dist/controllers/local_time_controller.js +1 -7
- data/dist/controllers/menu_controller.js +45 -24
- data/dist/controllers/menubar_controller.js +232 -52
- data/dist/controllers/meter_controller.js +31 -9
- data/dist/controllers/multi_select_controller.js +195 -62
- data/dist/controllers/navigation_menu_controller.js +1 -1
- data/dist/controllers/nested_form_controller.js +275 -21
- data/dist/controllers/network_status_controller.js +31 -9
- data/dist/controllers/number_input_controller.js +180 -71
- data/dist/controllers/otp_controller.js +97 -11
- data/dist/controllers/overflow_menu_controller.js +190 -24
- data/dist/controllers/pagination_controller.js +186 -24
- data/dist/controllers/password_reveal_controller.js +25 -4
- data/dist/controllers/password_strength_controller.js +6 -5
- data/dist/controllers/popover_controller.js +466 -42
- data/dist/controllers/progress_controller.js +31 -9
- data/dist/controllers/radio_group_controller.js +279 -88
- data/dist/controllers/range_slider_controller.js +72 -54
- data/dist/controllers/rating_controller.js +58 -10
- data/dist/controllers/read_more_controller.js +191 -25
- data/dist/controllers/relative_time_controller.js +1 -7
- data/dist/controllers/roving_controller.js +204 -8
- data/dist/controllers/scroll_area_controller.js +61 -19
- data/dist/controllers/scroll_visibility_controller.js +25 -4
- data/dist/controllers/scrollspy_controller.js +240 -32
- data/dist/controllers/separator_controller.js +97 -58
- data/dist/controllers/sidebar_controller.js +368 -127
- data/dist/controllers/skeleton_controller.js +75 -20
- data/dist/controllers/slider_controller.js +72 -54
- data/dist/controllers/sortable_controller.js +6 -5
- data/dist/controllers/spinner_controller.js +75 -20
- data/dist/controllers/step_indicator_controller.js +181 -6
- data/dist/controllers/stepper_controller.js +188 -6
- data/dist/controllers/sticky_observer_controller.js +86 -33
- data/dist/controllers/submit_once_controller.js +31 -9
- data/dist/controllers/switch_controller.js +84 -44
- data/dist/controllers/tabs_controller.js +189 -3
- data/dist/controllers/tags_input_controller.js +293 -29
- data/dist/controllers/theme_controller.js +192 -5
- data/dist/controllers/time_picker_controller.js +77 -42
- data/dist/controllers/toast_controller.js +478 -16
- data/dist/controllers/toggle_group_controller.js +282 -79
- data/dist/controllers/toolbar_controller.js +276 -15
- data/dist/controllers/tooltip_controller.js +244 -46
- data/dist/controllers/tree_view_controller.js +287 -57
- data/dist/index.js +2258 -1016
- data/lib/stimeo/ui/version.rb +1 -1
- metadata +2 -2
|
@@ -24,16 +24,23 @@ function actionSource(source) {
|
|
|
24
24
|
|
|
25
25
|
function setAttributeIfChanged(element, name, value, beforeWrite) {
|
|
26
26
|
if (element.getAttribute(name) === value) return false;
|
|
27
|
+
beforeWrite?.();
|
|
27
28
|
if (value === null) element.removeAttribute(name);
|
|
28
29
|
else element.setAttribute(name, value);
|
|
29
30
|
return true;
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
function syncActiveOption(options, active) {
|
|
33
|
+
function syncActiveOption(options, active, lease) {
|
|
33
34
|
let written = 0;
|
|
34
35
|
for (const option of options) {
|
|
35
36
|
const next = option === active ? "true" : "false";
|
|
36
|
-
if (
|
|
37
|
+
if (lease) {
|
|
38
|
+
if (option.getAttribute("aria-selected") === next) continue;
|
|
39
|
+
lease.adopt(option, { ifChanged: true });
|
|
40
|
+
lease.write(option, next, () => {
|
|
41
|
+
written += 1;
|
|
42
|
+
});
|
|
43
|
+
} else if (setAttributeIfChanged(option, "aria-selected", next)) written += 1;
|
|
37
44
|
}
|
|
38
45
|
return written;
|
|
39
46
|
}
|
|
@@ -114,14 +121,34 @@ var AttributeLease = class {
|
|
|
114
121
|
const names = registry.names;
|
|
115
122
|
names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
|
|
116
123
|
}
|
|
117
|
-
write(element, value) {
|
|
124
|
+
write(element, value, beforeWrite) {
|
|
118
125
|
const stack = attributeStack(element, this.#attribute);
|
|
119
126
|
const hold = this.#take(stack) ?? this.#acquire(element, stack);
|
|
120
127
|
this.#held.add(element);
|
|
121
128
|
const shows = !this.#covered(element, stack, hold);
|
|
122
129
|
hold.written = value;
|
|
123
130
|
this.#mark(element, stack);
|
|
124
|
-
if (shows) this.#reflect(element, value);
|
|
131
|
+
if (shows) this.#reflect(element, value, beforeWrite);
|
|
132
|
+
}
|
|
133
|
+
adopt(element, options = {}) {
|
|
134
|
+
const known = registry.stacks.get(element)?.has(this.#attribute);
|
|
135
|
+
if (!this.#held.has(element) && !known && !element.hasAttribute(this.#record)) return false;
|
|
136
|
+
const stack = attributeStack(element, this.#attribute);
|
|
137
|
+
const hold = this.#take(stack);
|
|
138
|
+
if (!hold) return false;
|
|
139
|
+
const current = element.getAttribute(this.#attribute);
|
|
140
|
+
if (options.ifChanged && (current === hold.written || this.#covered(element, stack, hold))) {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
this.#held.add(element);
|
|
144
|
+
hold.original = current;
|
|
145
|
+
hold.linked = false;
|
|
146
|
+
for (const above of stack.slice(stack.indexOf(hold) + 1)) {
|
|
147
|
+
if (!above.linked) break;
|
|
148
|
+
above.original = current;
|
|
149
|
+
}
|
|
150
|
+
this.#mark(element, stack);
|
|
151
|
+
return true;
|
|
125
152
|
}
|
|
126
153
|
return(element) {
|
|
127
154
|
const held = this.#held.delete(element);
|
|
@@ -187,8 +214,8 @@ var AttributeLease = class {
|
|
|
187
214
|
setAttributeIfChanged(element, name, recorded);
|
|
188
215
|
}
|
|
189
216
|
}
|
|
190
|
-
#reflect(element, value) {
|
|
191
|
-
setAttributeIfChanged(element, this.#attribute, value);
|
|
217
|
+
#reflect(element, value, beforeWrite) {
|
|
218
|
+
setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
|
|
192
219
|
}
|
|
193
220
|
};
|
|
194
221
|
|
|
@@ -202,7 +229,50 @@ function isCompositionInputType(inputType) {
|
|
|
202
229
|
return inputType !== void 0 && COMPOSITION_INPUT_TYPES.has(inputType);
|
|
203
230
|
}
|
|
204
231
|
var BEFORE_MORPH_ATTRIBUTE = "turbo:before-morph-attribute";
|
|
205
|
-
var textOf = (element) =>
|
|
232
|
+
var textOf = (element) => {
|
|
233
|
+
if ("value" in element) return element.value;
|
|
234
|
+
return element instanceof Element ? element.textContent : void 0;
|
|
235
|
+
};
|
|
236
|
+
var nodesOf = (element) => {
|
|
237
|
+
const nodes = [];
|
|
238
|
+
if ("value" in element || !(element instanceof Element)) return nodes;
|
|
239
|
+
const walker = element.ownerDocument.createTreeWalker(element);
|
|
240
|
+
for (let node = walker.nextNode(); node !== null; node = walker.nextNode()) nodes.push(node);
|
|
241
|
+
return nodes;
|
|
242
|
+
};
|
|
243
|
+
var folded = (text) => text.replaceAll("\xA0", " ");
|
|
244
|
+
var startOf = (node, data, replaced, caret) => {
|
|
245
|
+
const text = folded(node.data);
|
|
246
|
+
const composed = folded(data);
|
|
247
|
+
if (replaced?.startContainer === node && text.startsWith(composed, replaced.startOffset)) {
|
|
248
|
+
return replaced.startOffset;
|
|
249
|
+
}
|
|
250
|
+
const start = text.lastIndexOf(composed, caret);
|
|
251
|
+
return start !== -1 && start + composed.length >= caret ? start : -1;
|
|
252
|
+
};
|
|
253
|
+
var spotOf = (element, replaced, data) => {
|
|
254
|
+
if ("value" in element || !(element instanceof Element)) return null;
|
|
255
|
+
const selection = element.ownerDocument.getSelection();
|
|
256
|
+
const node = selection?.focusNode;
|
|
257
|
+
if (!(node instanceof Text) || node.data === "" || !element.contains(node)) return null;
|
|
258
|
+
const range = element.ownerDocument.createRange();
|
|
259
|
+
const start = typeof data === "string" && data !== "" ? startOf(node, data, replaced, selection?.focusOffset ?? 0) : -1;
|
|
260
|
+
if (start === -1) {
|
|
261
|
+
range.selectNodeContents(node);
|
|
262
|
+
} else {
|
|
263
|
+
range.setStart(node, start);
|
|
264
|
+
range.setEnd(node, start + data.length);
|
|
265
|
+
}
|
|
266
|
+
return range;
|
|
267
|
+
};
|
|
268
|
+
var replacedBy = (event) => typeof event.getTargetRanges === "function" ? event.getTargetRanges()[0] ?? null : null;
|
|
269
|
+
var rewritten = ({ element, text, nodes, spot }) => {
|
|
270
|
+
if (spot !== null) {
|
|
271
|
+
return spot.collapsed || !(element instanceof Node && element.contains(spot.startContainer));
|
|
272
|
+
}
|
|
273
|
+
const current = nodesOf(element);
|
|
274
|
+
return textOf(element) !== text || current.length !== nodes.length || current.some((node, index) => node !== nodes[index]);
|
|
275
|
+
};
|
|
206
276
|
var holdsFocus = (element) => element instanceof Node && element.getRootNode().activeElement === element;
|
|
207
277
|
var CompositionTracker = class {
|
|
208
278
|
#observedTargets = /* @__PURE__ */ new Set();
|
|
@@ -263,7 +333,7 @@ var CompositionTracker = class {
|
|
|
263
333
|
this.#confirmedTarget = null;
|
|
264
334
|
if (confirmed === null || confirmed !== event.target) return false;
|
|
265
335
|
const inputType = event.inputType;
|
|
266
|
-
return
|
|
336
|
+
return inputType ? isCompositionInputType(inputType) : event.isTrusted === true;
|
|
267
337
|
}
|
|
268
338
|
#release(target) {
|
|
269
339
|
target.removeEventListener("compositionstart", this.#handleStart);
|
|
@@ -293,11 +363,11 @@ var CompositionTracker = class {
|
|
|
293
363
|
}
|
|
294
364
|
#settle() {
|
|
295
365
|
const composition = this.#composition;
|
|
296
|
-
if (composition === null) return;
|
|
297
|
-
const { target, element
|
|
366
|
+
if (composition === null || !this.#observedTargets.has(composition.target)) return;
|
|
367
|
+
const { target, element } = composition;
|
|
298
368
|
if (target instanceof Node && element instanceof Node && !target.contains(element)) {
|
|
299
369
|
this.#composition = null;
|
|
300
|
-
} else if (
|
|
370
|
+
} else if (rewritten(composition)) {
|
|
301
371
|
this.#abandon(false);
|
|
302
372
|
}
|
|
303
373
|
}
|
|
@@ -322,7 +392,14 @@ var CompositionTracker = class {
|
|
|
322
392
|
this.#owe(true);
|
|
323
393
|
const target = event.currentTarget;
|
|
324
394
|
const element = event.target;
|
|
325
|
-
this.#composition = {
|
|
395
|
+
this.#composition = {
|
|
396
|
+
target,
|
|
397
|
+
element,
|
|
398
|
+
text: textOf(element),
|
|
399
|
+
nodes: nodesOf(element),
|
|
400
|
+
spot: spotOf(element, null, void 0),
|
|
401
|
+
replaced: null
|
|
402
|
+
};
|
|
326
403
|
this.#runAbandon();
|
|
327
404
|
this.#onStart?.(event);
|
|
328
405
|
};
|
|
@@ -346,6 +423,10 @@ var CompositionTracker = class {
|
|
|
346
423
|
if (this.#composition !== null && !keyComposing && !isComposing && inputType && !isCompositionInputType(inputType)) {
|
|
347
424
|
this.#abandon(true);
|
|
348
425
|
}
|
|
426
|
+
const composition = this.#composition;
|
|
427
|
+
if (composition !== null && event.target === composition.element) {
|
|
428
|
+
composition.replaced = replacedBy(event);
|
|
429
|
+
}
|
|
349
430
|
this.#runAbandon();
|
|
350
431
|
};
|
|
351
432
|
#handleInput = (event) => {
|
|
@@ -353,6 +434,15 @@ var CompositionTracker = class {
|
|
|
353
434
|
const { isTrusted, isComposing, inputType } = event;
|
|
354
435
|
if (composition !== null && event.target === composition.element && (isTrusted || isComposing || isCompositionInputType(inputType))) {
|
|
355
436
|
composition.text = textOf(composition.element);
|
|
437
|
+
composition.nodes = nodesOf(composition.element);
|
|
438
|
+
if (isCompositionInputType(inputType)) {
|
|
439
|
+
composition.spot = spotOf(
|
|
440
|
+
composition.element,
|
|
441
|
+
composition.replaced,
|
|
442
|
+
event.data
|
|
443
|
+
);
|
|
444
|
+
}
|
|
445
|
+
composition.replaced = null;
|
|
356
446
|
} else {
|
|
357
447
|
this.#settle();
|
|
358
448
|
}
|
|
@@ -373,7 +463,9 @@ var CompositionTracker = class {
|
|
|
373
463
|
const composition = this.#composition;
|
|
374
464
|
if (composition?.target !== event.currentTarget || event.target !== composition.element) return;
|
|
375
465
|
const detail = event.detail;
|
|
376
|
-
if (detail?.attributeName === "value"
|
|
466
|
+
if (detail?.attributeName === "value" && "value" in composition.element) {
|
|
467
|
+
event.preventDefault();
|
|
468
|
+
}
|
|
377
469
|
};
|
|
378
470
|
};
|
|
379
471
|
|
|
@@ -421,6 +513,7 @@ var EscapeLayer = class _EscapeLayer {
|
|
|
421
513
|
);
|
|
422
514
|
#active = null;
|
|
423
515
|
activate(ownerDocument = document, options) {
|
|
516
|
+
const entry = { onDismiss: options.onDismiss, claims: options.claims ?? null };
|
|
424
517
|
this.deactivate();
|
|
425
518
|
let registry2 = _EscapeLayer.#registries.get(ownerDocument);
|
|
426
519
|
if (!registry2) {
|
|
@@ -428,7 +521,6 @@ var EscapeLayer = class _EscapeLayer {
|
|
|
428
521
|
_EscapeLayer.#registries.set(ownerDocument, registry2);
|
|
429
522
|
ownerDocument.addEventListener("keydown", registry2.onKeydown);
|
|
430
523
|
}
|
|
431
|
-
const entry = { onDismiss: options.onDismiss, claims: options.claims ?? null };
|
|
432
524
|
registry2.stack.push(entry);
|
|
433
525
|
this.#active = { document: ownerDocument, entry };
|
|
434
526
|
}
|
|
@@ -477,11 +569,16 @@ var EscapeLayer = class _EscapeLayer {
|
|
|
477
569
|
}
|
|
478
570
|
};
|
|
479
571
|
|
|
572
|
+
var HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
|
|
480
573
|
function inheritsFieldsetDisabled(control) {
|
|
481
574
|
let fieldset = control.closest("fieldset[disabled]");
|
|
482
575
|
while (fieldset) {
|
|
483
|
-
|
|
484
|
-
|
|
576
|
+
if (fieldset.namespaceURI === HTML_NAMESPACE && fieldset.localName === "fieldset") {
|
|
577
|
+
const legend = Array.from(fieldset.children).find(
|
|
578
|
+
(child) => child.namespaceURI === HTML_NAMESPACE && child.localName === "legend"
|
|
579
|
+
);
|
|
580
|
+
if (!legend?.contains(control)) return true;
|
|
581
|
+
}
|
|
485
582
|
fieldset = fieldset.parentElement?.closest("fieldset[disabled]") ?? null;
|
|
486
583
|
}
|
|
487
584
|
return false;
|
|
@@ -554,11 +651,10 @@ function hasNativeTabStop(element) {
|
|
|
554
651
|
if (element.tagName === "AUDIO" || element.tagName === "VIDEO") {
|
|
555
652
|
return element.hasAttribute("controls");
|
|
556
653
|
}
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
return false;
|
|
654
|
+
const details = element.parentElement;
|
|
655
|
+
return details instanceof HTMLDetailsElement && Array.from(details.children).find(
|
|
656
|
+
(child) => child.namespaceURI === HTML_NAMESPACE && child.localName === "summary"
|
|
657
|
+
) === element;
|
|
562
658
|
}
|
|
563
659
|
function hasEditableTabStop(element) {
|
|
564
660
|
const value = element.getAttribute("contenteditable")?.toLowerCase();
|
|
@@ -621,27 +717,42 @@ function isSequentialStop(element) {
|
|
|
621
717
|
function ownedScope(element) {
|
|
622
718
|
if (element.shadowRoot) return Array.from(element.shadowRoot.children);
|
|
623
719
|
if (element instanceof HTMLSlotElement) {
|
|
624
|
-
|
|
625
|
-
return assigned.length > 0 ? assigned : Array.from(element.children);
|
|
720
|
+
return element.assignedNodes().length > 0 ? element.assignedElements() : Array.from(element.children);
|
|
626
721
|
}
|
|
627
722
|
return null;
|
|
628
723
|
}
|
|
629
724
|
function orderScope(elements, walk) {
|
|
630
725
|
const entries = [];
|
|
631
726
|
const visit = (element) => {
|
|
632
|
-
|
|
727
|
+
const isFrom = element === walk.from;
|
|
728
|
+
if (isFrom && walk.side !== "after") walk.fromAt = walk.tree.length;
|
|
633
729
|
const tabindex = authoredTabindex(element) ?? 0;
|
|
634
|
-
|
|
635
|
-
if (
|
|
730
|
+
let stop = null;
|
|
731
|
+
if ((element instanceof HTMLElement || element instanceof SVGElement) && isSequentialStop(element)) {
|
|
732
|
+
stop = element;
|
|
733
|
+
walk.tree.push(element);
|
|
734
|
+
}
|
|
636
735
|
const owned = ownedScope(element);
|
|
637
736
|
if (owned) {
|
|
638
737
|
if (tabindex >= 0) {
|
|
639
738
|
entries.push({ tabindex, stops: [...stop ? [stop] : [], ...orderScope(owned, walk)] });
|
|
739
|
+
} else if (walk.from && flatTreeContains(element, walk.from) && (!isFrom || walk.side === "on")) {
|
|
740
|
+
walk.fromAt = walk.tree.length;
|
|
741
|
+
walk.excludedScope = element;
|
|
742
|
+
orderScope(owned, {
|
|
743
|
+
from: walk.from,
|
|
744
|
+
side: walk.side,
|
|
745
|
+
tree: walk.tree,
|
|
746
|
+
fromAt: -1,
|
|
747
|
+
excludedScope: null
|
|
748
|
+
});
|
|
640
749
|
}
|
|
750
|
+
if (isFrom && walk.side === "after") walk.fromAt = walk.tree.length;
|
|
641
751
|
return;
|
|
642
752
|
}
|
|
643
753
|
if (stop) entries.push({ tabindex, stops: [stop] });
|
|
644
754
|
for (const child of Array.from(element.children)) visit(child);
|
|
755
|
+
if (isFrom && walk.side === "after") walk.fromAt = walk.tree.length;
|
|
645
756
|
};
|
|
646
757
|
for (const element of elements) visit(element);
|
|
647
758
|
const positive = entries.filter((entry) => entry.tabindex > 0);
|
|
@@ -649,31 +760,139 @@ function orderScope(elements, walk) {
|
|
|
649
760
|
const rest = entries.filter((entry) => entry.tabindex === 0);
|
|
650
761
|
return [...positive, ...rest].flatMap((entry) => entry.stops);
|
|
651
762
|
}
|
|
652
|
-
function passesRadioRule(element, tree, focusedRadio) {
|
|
763
|
+
function passesRadioRule(element, tree, focusedRadio, backward) {
|
|
653
764
|
if (!isRadio(element) || element.checked) return true;
|
|
654
765
|
const group = tree.filter(
|
|
655
766
|
(stop) => stop === element || isRadio(stop) && sameRadioGroup(stop, element)
|
|
656
767
|
);
|
|
657
768
|
if (group.some((radio) => radio.checked)) return false;
|
|
658
|
-
if (group[0] !== element) return false;
|
|
769
|
+
if (group[backward ? group.length - 1 : 0] !== element) return false;
|
|
659
770
|
return focusedRadio === null || !sameRadioGroup(focusedRadio, element);
|
|
660
771
|
}
|
|
661
772
|
function startIndex(order, walk, backward, isStop) {
|
|
662
773
|
if (walk.fromAt < 0) return backward ? order.length - 1 : 0;
|
|
663
|
-
const at = order.indexOf(walk.from);
|
|
774
|
+
const at = walk.side === "on" ? order.indexOf(walk.from) : -1;
|
|
664
775
|
if (at >= 0) return backward ? at - 1 : at + 1;
|
|
665
776
|
const neighbour = backward ? walk.tree.slice(0, walk.fromAt).reverse().find(isStop) : walk.tree.slice(walk.fromAt).find(isStop);
|
|
666
777
|
if (neighbour) return order.indexOf(neighbour);
|
|
667
|
-
return backward ?
|
|
778
|
+
return backward ? -1 : order.length;
|
|
668
779
|
}
|
|
669
|
-
function
|
|
670
|
-
const walk = {
|
|
780
|
+
function movesWithin(root, from, backward, wrap, radioContext, side = "on", position = { holder: null }) {
|
|
781
|
+
const walk = {
|
|
782
|
+
from,
|
|
783
|
+
side,
|
|
784
|
+
tree: [],
|
|
785
|
+
fromAt: from === root ? 0 : -1,
|
|
786
|
+
excludedScope: null
|
|
787
|
+
};
|
|
671
788
|
const order = orderScope(ownedScope(root) ?? Array.from(root.children), walk);
|
|
672
|
-
const
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
789
|
+
const radios = radioContext ?? {
|
|
790
|
+
tree: walk.tree,
|
|
791
|
+
focusedRadio: side === "on" && walk.fromAt >= 0 && isRadio(from) ? from : null
|
|
792
|
+
};
|
|
793
|
+
const isStop = (element) => passesRadioRule(element, radios.tree, radios.focusedRadio, backward);
|
|
794
|
+
const holds = (element) => position.holder !== null && flatTreeContains(element, position.holder);
|
|
795
|
+
const start = startIndex(
|
|
796
|
+
order,
|
|
797
|
+
walk,
|
|
798
|
+
backward,
|
|
799
|
+
(element) => order.includes(element) && isStop(element) && !holds(element)
|
|
800
|
+
);
|
|
801
|
+
const remaining = backward ? order.slice(0, start + 1).reverse() : order.slice(start);
|
|
802
|
+
const wrapped = wrap ? backward ? order.slice(start + 1).reverse() : order.slice(0, start) : [];
|
|
803
|
+
const excluded = walk.excludedScope;
|
|
804
|
+
const prefix = excluded && !(backward && from === excluded) ? movesWithin(
|
|
805
|
+
excluded,
|
|
806
|
+
from === excluded ? null : from,
|
|
807
|
+
backward,
|
|
808
|
+
false,
|
|
809
|
+
radios,
|
|
810
|
+
side,
|
|
811
|
+
position
|
|
812
|
+
) : [];
|
|
813
|
+
return [
|
|
814
|
+
...prefix,
|
|
815
|
+
...[...remaining, ...wrapped].filter(
|
|
816
|
+
(element) => (side !== "on" || element !== from) && isStop(element)
|
|
817
|
+
)
|
|
818
|
+
];
|
|
819
|
+
}
|
|
820
|
+
function flatParentNode(node) {
|
|
821
|
+
const parent = node.parentNode;
|
|
822
|
+
if (parent instanceof Element && parent.shadowRoot) {
|
|
823
|
+
for (const slot of parent.shadowRoot.querySelectorAll("slot")) {
|
|
824
|
+
if (slot.assignedNodes().includes(node)) return slot;
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
return parent instanceof ShadowRoot ? parent.host : parent;
|
|
828
|
+
}
|
|
829
|
+
function flatChildNodes(node) {
|
|
830
|
+
if (node instanceof Element && node.shadowRoot) return Array.from(node.shadowRoot.childNodes);
|
|
831
|
+
if (node instanceof HTMLSlotElement) {
|
|
832
|
+
const assigned = node.assignedNodes();
|
|
833
|
+
return assigned.length > 0 ? assigned : Array.from(node.childNodes);
|
|
834
|
+
}
|
|
835
|
+
return Array.from(node.childNodes);
|
|
836
|
+
}
|
|
837
|
+
function flatNodeAfter(node, root) {
|
|
838
|
+
for (let current = node; current && current !== root; ) {
|
|
839
|
+
const parent = flatParentNode(current);
|
|
840
|
+
if (!parent) return null;
|
|
841
|
+
const siblings = flatChildNodes(parent);
|
|
842
|
+
const index = siblings.indexOf(current);
|
|
843
|
+
const next = index >= 0 ? siblings[index + 1] : void 0;
|
|
844
|
+
if (next) return next;
|
|
845
|
+
current = parent;
|
|
846
|
+
}
|
|
847
|
+
return null;
|
|
848
|
+
}
|
|
849
|
+
function flatElementBefore(node, root) {
|
|
850
|
+
for (let current = node; current && current !== root; ) {
|
|
851
|
+
const parent = flatParentNode(current);
|
|
852
|
+
if (!parent) return null;
|
|
853
|
+
const siblings = flatChildNodes(parent);
|
|
854
|
+
for (let index = siblings.indexOf(current) - 1; index >= 0; index--) {
|
|
855
|
+
const sibling = siblings[index];
|
|
856
|
+
if (sibling instanceof Element) return sibling;
|
|
857
|
+
}
|
|
858
|
+
current = parent;
|
|
859
|
+
}
|
|
860
|
+
return null;
|
|
861
|
+
}
|
|
862
|
+
function elementAfterPosition(container, offset, root) {
|
|
863
|
+
const owner = container instanceof ShadowRoot ? container.host : container;
|
|
864
|
+
const child = container.childNodes[offset];
|
|
865
|
+
const previous = container.childNodes[offset - 1];
|
|
866
|
+
let node = child ?? (previous ? flatNodeAfter(previous, root) : flatChildNodes(owner)[0] ?? flatNodeAfter(owner, root));
|
|
867
|
+
while (node && !(node instanceof Element)) {
|
|
868
|
+
node = flatChildNodes(node)[0] ?? flatNodeAfter(node, root);
|
|
869
|
+
}
|
|
870
|
+
return node;
|
|
871
|
+
}
|
|
872
|
+
function elementBeforePosition(container, offset, root) {
|
|
873
|
+
const child = container.childNodes[offset];
|
|
874
|
+
if (child) return flatElementBefore(child, root);
|
|
875
|
+
const previous = container.childNodes[offset - 1];
|
|
876
|
+
if (previous) return previous instanceof Element ? previous : flatElementBefore(previous, root);
|
|
877
|
+
return flatElementBefore(container instanceof ShadowRoot ? container.host : container, root);
|
|
878
|
+
}
|
|
879
|
+
function elementHoldingPosition(container, offset) {
|
|
880
|
+
if (container instanceof Element && container.shadowRoot) {
|
|
881
|
+
const near = container.childNodes[offset] ?? container.childNodes[offset - 1];
|
|
882
|
+
return near ? flatParentNode(near) : container;
|
|
883
|
+
}
|
|
884
|
+
if (container instanceof Element) return container;
|
|
885
|
+
if (container instanceof ShadowRoot) return container.host;
|
|
886
|
+
return flatParentNode(container);
|
|
887
|
+
}
|
|
888
|
+
function sequentialTabStops(root, from = null, backward = false) {
|
|
889
|
+
if (!(from instanceof Range)) return movesWithin(root, from, backward, true);
|
|
890
|
+
const container = backward ? from.startContainer : from.endContainer;
|
|
891
|
+
const offset = backward ? from.startOffset : from.endOffset;
|
|
892
|
+
const anchor = backward ? elementBeforePosition(container, offset, root) : elementAfterPosition(container, offset, root);
|
|
893
|
+
return movesWithin(root, anchor, backward, true, void 0, backward ? "after" : "before", {
|
|
894
|
+
holder: elementHoldingPosition(container, offset)
|
|
895
|
+
});
|
|
677
896
|
}
|
|
678
897
|
function deepActiveElement(ownerDocument) {
|
|
679
898
|
let active = ownerDocument.activeElement;
|
|
@@ -837,7 +1056,7 @@ var INERT_MARK = `data-${FOCUS_TRAP_OWNER}-inert`;
|
|
|
837
1056
|
var OVERFLOW_MARK = `data-${FOCUS_TRAP_OWNER}-overflow`;
|
|
838
1057
|
var FocusTrap = class _FocusTrap {
|
|
839
1058
|
static #registries = sharedRegistry(
|
|
840
|
-
"stimeo-ui.focus-trap.registry.
|
|
1059
|
+
"stimeo-ui.focus-trap.registry.v3",
|
|
841
1060
|
() => /* @__PURE__ */ new WeakMap()
|
|
842
1061
|
);
|
|
843
1062
|
static #TEXT_ENTRY_TYPES = /* @__PURE__ */ new Set([
|
|
@@ -860,15 +1079,20 @@ var FocusTrap = class _FocusTrap {
|
|
|
860
1079
|
constructor(getContainer, options = {}) {
|
|
861
1080
|
this.#getContainer = getContainer;
|
|
862
1081
|
this.#options = options;
|
|
863
|
-
this.#entry =
|
|
1082
|
+
this.#entry = this.#createEntry();
|
|
1083
|
+
}
|
|
1084
|
+
#createEntry() {
|
|
1085
|
+
const entry = {
|
|
864
1086
|
container: () => this.#readContainer(),
|
|
865
1087
|
moveFocus: (backward) => this.#moveFocus(backward),
|
|
866
1088
|
refocus: () => this.#refocus(),
|
|
867
1089
|
isolated: false,
|
|
868
1090
|
lockedBody: null,
|
|
869
1091
|
openedFrom: null,
|
|
870
|
-
handedBack: []
|
|
1092
|
+
handedBack: [],
|
|
1093
|
+
returnTargets: () => this.#activeReturnTargets(entry)
|
|
871
1094
|
};
|
|
1095
|
+
return entry;
|
|
872
1096
|
}
|
|
873
1097
|
get active() {
|
|
874
1098
|
return this.#activeState;
|
|
@@ -876,6 +1100,7 @@ var FocusTrap = class _FocusTrap {
|
|
|
876
1100
|
activate() {
|
|
877
1101
|
if (this.#activeState) return;
|
|
878
1102
|
_FocusTrap.#sweep();
|
|
1103
|
+
this.#entry = this.#createEntry();
|
|
879
1104
|
this.#activeState = true;
|
|
880
1105
|
this.#openers = _FocusTrap.#focusPath();
|
|
881
1106
|
this.#entry.openedFrom = _FocusTrap.#trapHolding(this.#openers[0] ?? null);
|
|
@@ -892,14 +1117,21 @@ var FocusTrap = class _FocusTrap {
|
|
|
892
1117
|
this.#returnTabindexes();
|
|
893
1118
|
return;
|
|
894
1119
|
}
|
|
1120
|
+
const entry = this.#entry;
|
|
1121
|
+
const parent = entry.openedFrom;
|
|
1122
|
+
const openers = this.#openers;
|
|
1123
|
+
this.#openers = [];
|
|
895
1124
|
this.#activeState = false;
|
|
896
1125
|
this.#escapeLayer.deactivate();
|
|
897
|
-
const above = this.#leaveStack();
|
|
898
|
-
this.#unlockScroll();
|
|
1126
|
+
const above = this.#leaveStack(entry);
|
|
1127
|
+
this.#unlockScroll(entry);
|
|
899
1128
|
_FocusTrap.#reconcileBackground(document);
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
1129
|
+
try {
|
|
1130
|
+
const wayBack = this.#handOver(entry, openers, above);
|
|
1131
|
+
if (restoreFocus) this.#restore(wayBack, above, parent);
|
|
1132
|
+
} finally {
|
|
1133
|
+
this.#returnTabindexes();
|
|
1134
|
+
}
|
|
903
1135
|
}
|
|
904
1136
|
connect() {
|
|
905
1137
|
this.#gate.cancel();
|
|
@@ -935,18 +1167,27 @@ var FocusTrap = class _FocusTrap {
|
|
|
935
1167
|
document.addEventListener("keydown", registry2.onKeydown);
|
|
936
1168
|
document.addEventListener("turbo:morph", registry2.onMorph);
|
|
937
1169
|
document.addEventListener("turbo:morph-element", registry2.onMorph);
|
|
1170
|
+
document.addEventListener("pointerdown", registry2.onPointerDown, {
|
|
1171
|
+
capture: true,
|
|
1172
|
+
passive: true
|
|
1173
|
+
});
|
|
1174
|
+
document.addEventListener("focusin", registry2.onFocusIn, { capture: true });
|
|
938
1175
|
}
|
|
939
1176
|
registry2.stack.push(this.#entry);
|
|
940
1177
|
}
|
|
941
|
-
#leaveStack() {
|
|
1178
|
+
#leaveStack(entry) {
|
|
942
1179
|
const registry2 = _FocusTrap.#registry(document);
|
|
943
|
-
const index = registry2.stack.indexOf(
|
|
1180
|
+
const index = registry2.stack.indexOf(entry);
|
|
944
1181
|
const above = registry2.stack.slice(index + 1);
|
|
945
1182
|
registry2.stack.splice(index, 1);
|
|
946
1183
|
if (registry2.stack.length === 0) {
|
|
947
1184
|
document.removeEventListener("keydown", registry2.onKeydown);
|
|
948
1185
|
document.removeEventListener("turbo:morph", registry2.onMorph);
|
|
949
1186
|
document.removeEventListener("turbo:morph-element", registry2.onMorph);
|
|
1187
|
+
document.removeEventListener("pointerdown", registry2.onPointerDown, { capture: true });
|
|
1188
|
+
document.removeEventListener("focusin", registry2.onFocusIn, { capture: true });
|
|
1189
|
+
registry2.start = null;
|
|
1190
|
+
registry2.pressed = false;
|
|
950
1191
|
}
|
|
951
1192
|
return above;
|
|
952
1193
|
}
|
|
@@ -964,24 +1205,26 @@ var FocusTrap = class _FocusTrap {
|
|
|
964
1205
|
}
|
|
965
1206
|
return null;
|
|
966
1207
|
}
|
|
967
|
-
#handOver(above) {
|
|
968
|
-
const
|
|
969
|
-
const
|
|
970
|
-
|
|
971
|
-
this.#options.fallbackFocus?.() ?? null,
|
|
972
|
-
...entry.handedBack
|
|
973
|
-
].filter((element) => element !== null);
|
|
974
|
-
for (const trap of above) {
|
|
975
|
-
if (trap.openedFrom !== entry) continue;
|
|
976
|
-
trap.handedBack = [...trap.handedBack, ...wayBack];
|
|
977
|
-
trap.openedFrom = entry.openedFrom;
|
|
978
|
-
}
|
|
979
|
-
this.#openers = [];
|
|
1208
|
+
#handOver(entry, openers, above) {
|
|
1209
|
+
const wayBack = [...openers];
|
|
1210
|
+
const parent = entry.openedFrom;
|
|
1211
|
+
const handedBack = entry.handedBack;
|
|
980
1212
|
entry.openedFrom = null;
|
|
981
1213
|
entry.handedBack = [];
|
|
1214
|
+
try {
|
|
1215
|
+
const fallback = this.#options.fallbackFocus?.();
|
|
1216
|
+
if (fallback) wayBack.push(fallback);
|
|
1217
|
+
} finally {
|
|
1218
|
+
wayBack.push(...handedBack);
|
|
1219
|
+
for (const trap of above) {
|
|
1220
|
+
if (trap.openedFrom !== entry) continue;
|
|
1221
|
+
trap.handedBack = [...trap.handedBack, ...wayBack];
|
|
1222
|
+
trap.openedFrom = parent;
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
982
1225
|
return wayBack;
|
|
983
1226
|
}
|
|
984
|
-
#restore(wayBack, above) {
|
|
1227
|
+
#restore(wayBack, above, parent) {
|
|
985
1228
|
const active = deepActiveElement(document);
|
|
986
1229
|
const released = this.#readContainer();
|
|
987
1230
|
const holds = (trap) => {
|
|
@@ -992,7 +1235,7 @@ var FocusTrap = class _FocusTrap {
|
|
|
992
1235
|
return !released || !flatTreeContains(released, active) || flatTreeContains(released, container);
|
|
993
1236
|
};
|
|
994
1237
|
if (above.some(holds)) return;
|
|
995
|
-
for (const element of wayBack) {
|
|
1238
|
+
for (const element of _FocusTrap.#returnCandidates(wayBack, parent)) {
|
|
996
1239
|
if (this.#activeState) return;
|
|
997
1240
|
if (!element.isConnected || !canTakeFocus(element) || !isRenderedForFocus(element)) continue;
|
|
998
1241
|
const before = deepActiveElement(document);
|
|
@@ -1002,6 +1245,19 @@ var FocusTrap = class _FocusTrap {
|
|
|
1002
1245
|
}
|
|
1003
1246
|
_FocusTrap.#tabOwner(_FocusTrap.#registry(document).stack)?.refocus();
|
|
1004
1247
|
}
|
|
1248
|
+
*#activeReturnTargets(entry) {
|
|
1249
|
+
if (!this.#activeState || this.#entry !== entry) return;
|
|
1250
|
+
yield* this.#openers;
|
|
1251
|
+
const fallback = this.#options.fallbackFocus?.();
|
|
1252
|
+
if (fallback) yield fallback;
|
|
1253
|
+
yield* entry.handedBack;
|
|
1254
|
+
}
|
|
1255
|
+
static *#returnCandidates(wayBack, parent) {
|
|
1256
|
+
yield* wayBack;
|
|
1257
|
+
for (let entry = parent; entry && !_FocusTrap.#takesTab(entry); entry = entry.openedFrom) {
|
|
1258
|
+
yield* entry.returnTargets?.() ?? [];
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1005
1261
|
#refocus() {
|
|
1006
1262
|
if (!this.#flag(this.#options.autoFocus, true)) return;
|
|
1007
1263
|
if (flatTreeContains(this.#getContainer(), deepActiveElement(document))) return;
|
|
@@ -1016,8 +1272,8 @@ var FocusTrap = class _FocusTrap {
|
|
|
1016
1272
|
const focused = deepActiveElement(document);
|
|
1017
1273
|
for (const [element, loan] of [...this.#tabindexLoans]) {
|
|
1018
1274
|
if (element === focused) continue;
|
|
1019
|
-
loan.returnAll();
|
|
1020
1275
|
this.#tabindexLoans.delete(element);
|
|
1276
|
+
loan.returnAll();
|
|
1021
1277
|
}
|
|
1022
1278
|
}
|
|
1023
1279
|
#lockScroll() {
|
|
@@ -1028,11 +1284,11 @@ var FocusTrap = class _FocusTrap {
|
|
|
1028
1284
|
this.#entry.lockedBody = body;
|
|
1029
1285
|
body.style.overflow = "hidden";
|
|
1030
1286
|
}
|
|
1031
|
-
#unlockScroll() {
|
|
1287
|
+
#unlockScroll(entry) {
|
|
1032
1288
|
const registry2 = _FocusTrap.#registry(document);
|
|
1033
|
-
const body =
|
|
1034
|
-
|
|
1035
|
-
if (!registry2.scrollLocks.delete(
|
|
1289
|
+
const body = entry.lockedBody;
|
|
1290
|
+
entry.lockedBody = null;
|
|
1291
|
+
if (!registry2.scrollLocks.delete(entry) || !body) return;
|
|
1036
1292
|
if (!_FocusTrap.#isLocked(registry2, body)) _FocusTrap.#unlock(body);
|
|
1037
1293
|
}
|
|
1038
1294
|
static #isLocked(registry2, body) {
|
|
@@ -1062,8 +1318,12 @@ var FocusTrap = class _FocusTrap {
|
|
|
1062
1318
|
stack: [],
|
|
1063
1319
|
onKeydown: (event) => _FocusTrap.#resolveTab(registry2.stack, event),
|
|
1064
1320
|
onMorph: () => morphs.schedule(),
|
|
1321
|
+
onPointerDown: (event) => _FocusTrap.#recordPress(registry2, event),
|
|
1322
|
+
onFocusIn: (event) => _FocusTrap.#recordFocus(registry2, event),
|
|
1065
1323
|
inerted: /* @__PURE__ */ new Set(),
|
|
1066
|
-
scrollLocks: /* @__PURE__ */ new Set()
|
|
1324
|
+
scrollLocks: /* @__PURE__ */ new Set(),
|
|
1325
|
+
start: null,
|
|
1326
|
+
pressed: false
|
|
1067
1327
|
};
|
|
1068
1328
|
_FocusTrap.#registries.set(ownerDocument, registry2);
|
|
1069
1329
|
return registry2;
|
|
@@ -1161,7 +1421,7 @@ var FocusTrap = class _FocusTrap {
|
|
|
1161
1421
|
return _FocusTrap.#tabOwner(_FocusTrap.#registry(document).stack) === this.#entry;
|
|
1162
1422
|
}
|
|
1163
1423
|
#moveFocus(backward) {
|
|
1164
|
-
const from =
|
|
1424
|
+
const from = _FocusTrap.#start();
|
|
1165
1425
|
for (const stop of sequentialTabStops(this.#getContainer(), from, backward)) {
|
|
1166
1426
|
if (!this.#ownsTab()) return;
|
|
1167
1427
|
const before = deepActiveElement(document);
|
|
@@ -1172,18 +1432,66 @@ var FocusTrap = class _FocusTrap {
|
|
|
1172
1432
|
return;
|
|
1173
1433
|
}
|
|
1174
1434
|
}
|
|
1435
|
+
static #start() {
|
|
1436
|
+
const active = deepActiveElement(document);
|
|
1437
|
+
const start = _FocusTrap.#registry(document).start;
|
|
1438
|
+
if (active && active !== document.body) {
|
|
1439
|
+
const at = start ? elementHoldingPosition(start.startContainer, start.startOffset) : null;
|
|
1440
|
+
const pointInside = !(active instanceof HTMLElement && isTabStop(active)) && flatTreeContains(active, at);
|
|
1441
|
+
return pointInside ? start : active;
|
|
1442
|
+
}
|
|
1443
|
+
return start ?? active;
|
|
1444
|
+
}
|
|
1445
|
+
static #recordPress(registry2, event) {
|
|
1446
|
+
const path = event.composedPath();
|
|
1447
|
+
const target = path[0];
|
|
1448
|
+
const owner = target.ownerDocument ?? document;
|
|
1449
|
+
const roots = path.filter((node) => node instanceof ShadowRoot);
|
|
1450
|
+
const caret = _FocusTrap.#caretAt(owner, event.clientX, event.clientY, roots);
|
|
1451
|
+
const range = owner.createRange();
|
|
1452
|
+
const fits = caret !== null && target.contains(caret.node) && caret.offset <= (caret.node instanceof CharacterData ? caret.node.length : caret.node.childNodes.length);
|
|
1453
|
+
if (fits) range.setStart(caret.node, caret.offset);
|
|
1454
|
+
else range.setStart(target, 0);
|
|
1455
|
+
range.collapse(true);
|
|
1456
|
+
registry2.start = range;
|
|
1457
|
+
registry2.pressed = true;
|
|
1458
|
+
}
|
|
1459
|
+
static #recordFocus(registry2, event) {
|
|
1460
|
+
const target = event.composedPath()[0];
|
|
1461
|
+
const point = registry2.pressed ? registry2.start : null;
|
|
1462
|
+
const at = point ? elementHoldingPosition(point.startContainer, point.startOffset) : null;
|
|
1463
|
+
const keep = !(target instanceof HTMLElement && isTabStop(target)) && flatTreeContains(target, at);
|
|
1464
|
+
registry2.pressed = false;
|
|
1465
|
+
if (keep) return;
|
|
1466
|
+
const range = target.ownerDocument.createRange();
|
|
1467
|
+
range.selectNode(target);
|
|
1468
|
+
registry2.start = range;
|
|
1469
|
+
}
|
|
1470
|
+
static #caretAt(owner, x, y, roots) {
|
|
1471
|
+
if (typeof owner.caretPositionFromPoint === "function") {
|
|
1472
|
+
const position = owner.caretPositionFromPoint(x, y, { shadowRoots: roots });
|
|
1473
|
+
return position ? { node: position.offsetNode, offset: position.offset } : null;
|
|
1474
|
+
}
|
|
1475
|
+
const legacy = owner;
|
|
1476
|
+
if (typeof legacy.caretRangeFromPoint === "function") {
|
|
1477
|
+
const range = legacy.caretRangeFromPoint(x, y);
|
|
1478
|
+
return range ? { node: range.startContainer, offset: range.startOffset } : null;
|
|
1479
|
+
}
|
|
1480
|
+
return null;
|
|
1481
|
+
}
|
|
1175
1482
|
static #selectOnEntry(stop) {
|
|
1176
1483
|
if (stop instanceof HTMLInputElement && _FocusTrap.#TEXT_ENTRY_TYPES.has(stop.type)) {
|
|
1177
1484
|
stop.select();
|
|
1178
1485
|
}
|
|
1179
1486
|
}
|
|
1180
1487
|
#focusInitial() {
|
|
1488
|
+
const container = this.#readContainer();
|
|
1489
|
+
if (!container) return;
|
|
1181
1490
|
const preferred = this.#options.initialFocus?.();
|
|
1182
1491
|
if (preferred) {
|
|
1183
1492
|
preferred.focus();
|
|
1184
1493
|
return;
|
|
1185
1494
|
}
|
|
1186
|
-
const container = this.#getContainer();
|
|
1187
1495
|
const [first] = sequentialTabStops(container);
|
|
1188
1496
|
if (first) {
|
|
1189
1497
|
first.focus();
|
|
@@ -1284,7 +1592,13 @@ var CommandPaletteController = class _CommandPaletteController extends Controlle
|
|
|
1284
1592
|
#connected = false;
|
|
1285
1593
|
#lived = new LivedMark(this.identifier);
|
|
1286
1594
|
#dialog = null;
|
|
1595
|
+
#openState = false;
|
|
1596
|
+
#seedOnDialogArrival = false;
|
|
1287
1597
|
#hidden = new AttributeLease("hidden", this.identifier);
|
|
1598
|
+
#optionHidden = new AttributeLease("hidden", this.identifier);
|
|
1599
|
+
#optionSelected = new AttributeLease("aria-selected", this.identifier);
|
|
1600
|
+
#knownOptions = /* @__PURE__ */ new Set();
|
|
1601
|
+
#optionDisabled = new AttributeLease("aria-disabled", this.identifier);
|
|
1288
1602
|
#expanded = new AttributeLease("aria-expanded", this.identifier);
|
|
1289
1603
|
#activeDescendant = new AttributeLease(
|
|
1290
1604
|
"aria-activedescendant",
|
|
@@ -1309,19 +1623,24 @@ var CommandPaletteController = class _CommandPaletteController extends Controlle
|
|
|
1309
1623
|
});
|
|
1310
1624
|
#listeners = new ListenerSet();
|
|
1311
1625
|
connect() {
|
|
1626
|
+
const options = new Set(this.optionTargets);
|
|
1627
|
+
const departed = [...this.#knownOptions].filter((option) => !options.has(option));
|
|
1628
|
+
for (const option of departed) this.#returnOption(option);
|
|
1312
1629
|
const connection = this.#lived.connect(this.element);
|
|
1313
1630
|
this.#trap.connect();
|
|
1314
1631
|
this.#listeners.add(document, "keydown", this.#onGlobalKeydown);
|
|
1315
1632
|
if (this.hasInputTarget) this.#composition.observe(this.inputTarget);
|
|
1316
1633
|
this.#syncOptionSemantics();
|
|
1634
|
+
this.#dialog = this.hasDialogTarget ? this.dialogTarget : null;
|
|
1635
|
+
this.#openState = this.#dialog ? !this.#dialog.hidden : this.#openState;
|
|
1317
1636
|
if (connection === "reconnect" && this.#isOpen) {
|
|
1637
|
+
if (departed.length > 0) this.#reconcileActive();
|
|
1318
1638
|
this.#trap.activate();
|
|
1319
1639
|
} else {
|
|
1320
1640
|
const shouldOpen = connection !== "restored" && (this.#isOpen || this.openValue);
|
|
1321
1641
|
this.#resetToClosedState();
|
|
1322
1642
|
if (shouldOpen) this.open();
|
|
1323
1643
|
}
|
|
1324
|
-
this.#dialog = this.hasDialogTarget ? this.dialogTarget : null;
|
|
1325
1644
|
this.#connected = true;
|
|
1326
1645
|
this.#reconcile.activate();
|
|
1327
1646
|
this.#morphRender.observe(this.element);
|
|
@@ -1336,16 +1655,38 @@ var CommandPaletteController = class _CommandPaletteController extends Controlle
|
|
|
1336
1655
|
this.#trap.disconnect(this);
|
|
1337
1656
|
}
|
|
1338
1657
|
optionTargetConnected(option) {
|
|
1658
|
+
const original = option.getAttribute(_CommandPaletteController.#ORIGINAL_ARIA_DISABLED);
|
|
1659
|
+
if (original !== null) {
|
|
1660
|
+
option.removeAttribute(_CommandPaletteController.#ORIGINAL_ARIA_DISABLED);
|
|
1661
|
+
if (option.getAttribute("aria-disabled") === "true") {
|
|
1662
|
+
if (original === _CommandPaletteController.#ABSENT_ARIA_DISABLED) {
|
|
1663
|
+
option.removeAttribute("aria-disabled");
|
|
1664
|
+
} else {
|
|
1665
|
+
option.setAttribute("aria-disabled", original);
|
|
1666
|
+
}
|
|
1667
|
+
}
|
|
1668
|
+
}
|
|
1339
1669
|
this.#syncOptionSemanticsFor(option);
|
|
1340
|
-
|
|
1341
|
-
|
|
1670
|
+
if (!this.#knownOptions.has(option)) {
|
|
1671
|
+
this.#knownOptions.add(option);
|
|
1672
|
+
syncActiveOption([option], null, this.#optionSelected);
|
|
1673
|
+
option.removeAttribute("data-active");
|
|
1674
|
+
}
|
|
1342
1675
|
if (this.#connected) this.#queueOptionReconciliation();
|
|
1343
1676
|
}
|
|
1344
1677
|
optionTargetDisconnected(option) {
|
|
1345
|
-
option.
|
|
1346
|
-
|
|
1678
|
+
if (!this.scope.containsElement(option) || !this.optionTargets.includes(option)) {
|
|
1679
|
+
this.#returnOption(option);
|
|
1680
|
+
}
|
|
1347
1681
|
if (this.#connected) this.#queueOptionReconciliation();
|
|
1348
1682
|
}
|
|
1683
|
+
#returnOption(option) {
|
|
1684
|
+
this.#knownOptions.delete(option);
|
|
1685
|
+
this.#optionHidden.return(option);
|
|
1686
|
+
this.#optionDisabled.return(option);
|
|
1687
|
+
this.#optionSelected.return(option);
|
|
1688
|
+
option.removeAttribute("data-active");
|
|
1689
|
+
}
|
|
1349
1690
|
inputTargetConnected(input) {
|
|
1350
1691
|
this.#composition.observe(input);
|
|
1351
1692
|
if (this.#connected) this.#queueOptionReconciliation();
|
|
@@ -1381,11 +1722,14 @@ var CommandPaletteController = class _CommandPaletteController extends Controlle
|
|
|
1381
1722
|
}
|
|
1382
1723
|
}
|
|
1383
1724
|
open() {
|
|
1384
|
-
|
|
1385
|
-
this.#
|
|
1725
|
+
this.#adoptDialog();
|
|
1726
|
+
if (this.#isOpen) return;
|
|
1727
|
+
this.#openState = true;
|
|
1728
|
+
if (this.#dialog) this.#hidden.write(this.#dialog, null);
|
|
1386
1729
|
this.openValue = true;
|
|
1387
1730
|
if (this.hasInputTarget) this.#expanded.write(this.inputTarget, "true");
|
|
1388
|
-
this.#
|
|
1731
|
+
this.#seedOnDialogArrival = this.#dialog === null;
|
|
1732
|
+
if (!this.#seedOnDialogArrival) this.#resetFilter();
|
|
1389
1733
|
this.#trap.activate();
|
|
1390
1734
|
}
|
|
1391
1735
|
close() {
|
|
@@ -1395,20 +1739,17 @@ var CommandPaletteController = class _CommandPaletteController extends Controlle
|
|
|
1395
1739
|
const dialog = this.hasDialogTarget ? this.dialogTarget : null;
|
|
1396
1740
|
if (dialog === this.#dialog) return;
|
|
1397
1741
|
this.#dialog = dialog;
|
|
1398
|
-
if (
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
this.#trap.deactivate();
|
|
1405
|
-
return;
|
|
1742
|
+
if (dialog) {
|
|
1743
|
+
this.#hidden.write(dialog, this.#openState ? null : "");
|
|
1744
|
+
if (this.#seedOnDialogArrival) {
|
|
1745
|
+
this.#seedOnDialogArrival = false;
|
|
1746
|
+
this.#resetFilter();
|
|
1747
|
+
}
|
|
1406
1748
|
}
|
|
1407
|
-
this.#hidden.write(dialog, null);
|
|
1408
1749
|
this.#trap.refreshContainer();
|
|
1409
1750
|
}
|
|
1410
1751
|
#close(restoreFocus) {
|
|
1411
|
-
if (!this
|
|
1752
|
+
if (!this.#isOpen) return;
|
|
1412
1753
|
this.#resetToClosedState();
|
|
1413
1754
|
this.#trap.deactivate({ restoreFocus });
|
|
1414
1755
|
}
|
|
@@ -1423,10 +1764,10 @@ var CommandPaletteController = class _CommandPaletteController extends Controlle
|
|
|
1423
1764
|
const searchText = (option.dataset.searchValue || option.textContent || "").trim().toLowerCase();
|
|
1424
1765
|
const matches = searchText.includes(query);
|
|
1425
1766
|
if (matches) {
|
|
1426
|
-
|
|
1427
|
-
if (this.#isNavigable(option)) hasSelectableMatch = true;
|
|
1428
|
-
} else {
|
|
1429
|
-
|
|
1767
|
+
this.#optionHidden.return(option);
|
|
1768
|
+
if (!option.hasAttribute("hidden") && this.#isNavigable(option)) hasSelectableMatch = true;
|
|
1769
|
+
} else if (!option.hasAttribute("hidden")) {
|
|
1770
|
+
this.#optionHidden.write(option, "true");
|
|
1430
1771
|
}
|
|
1431
1772
|
}
|
|
1432
1773
|
if (this.hasEmptyTarget) {
|
|
@@ -1464,6 +1805,8 @@ var CommandPaletteController = class _CommandPaletteController extends Controlle
|
|
|
1464
1805
|
if (isReservedArrowChord(event)) return;
|
|
1465
1806
|
if ((event.key === "Home" || event.key === "End") && hasModifierChord(event)) return;
|
|
1466
1807
|
if (this.#composition.isComposing(event) || !this.#isOpen) return;
|
|
1808
|
+
this.#adoptDialog();
|
|
1809
|
+
if (!this.#dialog) return;
|
|
1467
1810
|
this.#reconcileActive();
|
|
1468
1811
|
switch (event.key) {
|
|
1469
1812
|
case "ArrowDown":
|
|
@@ -1504,7 +1847,7 @@ var CommandPaletteController = class _CommandPaletteController extends Controlle
|
|
|
1504
1847
|
this.#syncOptionSemantics();
|
|
1505
1848
|
const visible = this.#visibleOptions;
|
|
1506
1849
|
const activeOption = visible[index] ?? null;
|
|
1507
|
-
syncActiveOption(this.optionTargets, activeOption);
|
|
1850
|
+
syncActiveOption(this.optionTargets, activeOption, this.#optionSelected);
|
|
1508
1851
|
for (const option of this.optionTargets) {
|
|
1509
1852
|
if (option === activeOption) option.setAttribute("data-active", "true");
|
|
1510
1853
|
else option.removeAttribute("data-active");
|
|
@@ -1584,7 +1927,7 @@ var CommandPaletteController = class _CommandPaletteController extends Controlle
|
|
|
1584
1927
|
#resetFilter() {
|
|
1585
1928
|
if (this.hasInputTarget) this.inputTarget.value = "";
|
|
1586
1929
|
for (const option of this.optionTargets) {
|
|
1587
|
-
|
|
1930
|
+
this.#optionHidden.return(option);
|
|
1588
1931
|
}
|
|
1589
1932
|
const hasSelectableOption = this.#visibleOptions.length > 0;
|
|
1590
1933
|
this.#reflectEmptyState();
|
|
@@ -1605,28 +1948,13 @@ var CommandPaletteController = class _CommandPaletteController extends Controlle
|
|
|
1605
1948
|
for (const option of this.optionTargets) this.#syncOptionSemanticsFor(option);
|
|
1606
1949
|
}
|
|
1607
1950
|
#syncOptionSemanticsFor(option) {
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
if (originalValue === null) {
|
|
1612
|
-
option.setAttribute(
|
|
1613
|
-
originalAttribute,
|
|
1614
|
-
option.getAttribute("aria-disabled") ?? _CommandPaletteController.#ABSENT_ARIA_DISABLED
|
|
1615
|
-
);
|
|
1616
|
-
}
|
|
1617
|
-
option.setAttribute("aria-disabled", "true");
|
|
1618
|
-
return;
|
|
1619
|
-
}
|
|
1620
|
-
if (originalValue === null) return;
|
|
1621
|
-
if (originalValue === _CommandPaletteController.#ABSENT_ARIA_DISABLED) {
|
|
1622
|
-
option.removeAttribute("aria-disabled");
|
|
1623
|
-
} else {
|
|
1624
|
-
option.setAttribute("aria-disabled", originalValue);
|
|
1951
|
+
if (option.dataset.disabled !== "true") this.#optionDisabled.return(option);
|
|
1952
|
+
else if (option.getAttribute("aria-disabled") !== "true") {
|
|
1953
|
+
this.#optionDisabled.write(option, "true");
|
|
1625
1954
|
}
|
|
1626
|
-
option.removeAttribute(originalAttribute);
|
|
1627
1955
|
}
|
|
1628
1956
|
get #isOpen() {
|
|
1629
|
-
return this
|
|
1957
|
+
return this.#openState;
|
|
1630
1958
|
}
|
|
1631
1959
|
#onGlobalKeydown = (event) => {
|
|
1632
1960
|
if (event.defaultPrevented) return;
|
|
@@ -1656,13 +1984,13 @@ var CommandPaletteController = class _CommandPaletteController extends Controlle
|
|
|
1656
1984
|
return null;
|
|
1657
1985
|
}
|
|
1658
1986
|
#resetToClosedState() {
|
|
1987
|
+
this.#openState = false;
|
|
1988
|
+
this.#seedOnDialogArrival = false;
|
|
1659
1989
|
this.#activeId = null;
|
|
1660
1990
|
this.#activeOrder = [];
|
|
1661
1991
|
this.openValue = false;
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
option.removeAttribute("data-active");
|
|
1665
|
-
}
|
|
1992
|
+
syncActiveOption(this.optionTargets, null, this.#optionSelected);
|
|
1993
|
+
for (const option of this.optionTargets) option.removeAttribute("data-active");
|
|
1666
1994
|
if (this.hasDialogTarget) {
|
|
1667
1995
|
this.#hidden.write(this.dialogTarget, "");
|
|
1668
1996
|
}
|