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
|
@@ -29,14 +29,15 @@ function fillTemplate(template, values) {
|
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
var afterFocus = /* @__PURE__ */ Symbol.for("stimeo--announcer:after-focus");
|
|
32
33
|
function announce(message, options = {}) {
|
|
33
34
|
const text = message.trim();
|
|
34
35
|
if (text.length === 0) return;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
);
|
|
36
|
+
const event = new CustomEvent("stimeo--announcer:announce", {
|
|
37
|
+
detail: { message: text, assertive: options.assertive === true }
|
|
38
|
+
});
|
|
39
|
+
if (options.afterFocus) event[afterFocus] = true;
|
|
40
|
+
window.dispatchEvent(event);
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
function sharedRegistry(key, create) {
|
|
@@ -84,6 +85,7 @@ function hasModifierChord(event) {
|
|
|
84
85
|
|
|
85
86
|
function setAttributeIfChanged(element, name, value, beforeWrite) {
|
|
86
87
|
if (element.getAttribute(name) === value) return false;
|
|
88
|
+
beforeWrite?.();
|
|
87
89
|
if (value === null) element.removeAttribute(name);
|
|
88
90
|
else element.setAttribute(name, value);
|
|
89
91
|
return true;
|
|
@@ -147,14 +149,34 @@ var AttributeLease = class {
|
|
|
147
149
|
const names = registry.names;
|
|
148
150
|
names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
|
|
149
151
|
}
|
|
150
|
-
write(element, value) {
|
|
152
|
+
write(element, value, beforeWrite) {
|
|
151
153
|
const stack = attributeStack(element, this.#attribute);
|
|
152
154
|
const hold = this.#take(stack) ?? this.#acquire(element, stack);
|
|
153
155
|
this.#held.add(element);
|
|
154
156
|
const shows = !this.#covered(element, stack, hold);
|
|
155
157
|
hold.written = value;
|
|
156
158
|
this.#mark(element, stack);
|
|
157
|
-
if (shows) this.#reflect(element, value);
|
|
159
|
+
if (shows) this.#reflect(element, value, beforeWrite);
|
|
160
|
+
}
|
|
161
|
+
adopt(element, options = {}) {
|
|
162
|
+
const known = registry.stacks.get(element)?.has(this.#attribute);
|
|
163
|
+
if (!this.#held.has(element) && !known && !element.hasAttribute(this.#record)) return false;
|
|
164
|
+
const stack = attributeStack(element, this.#attribute);
|
|
165
|
+
const hold = this.#take(stack);
|
|
166
|
+
if (!hold) return false;
|
|
167
|
+
const current = element.getAttribute(this.#attribute);
|
|
168
|
+
if (options.ifChanged && (current === hold.written || this.#covered(element, stack, hold))) {
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
this.#held.add(element);
|
|
172
|
+
hold.original = current;
|
|
173
|
+
hold.linked = false;
|
|
174
|
+
for (const above of stack.slice(stack.indexOf(hold) + 1)) {
|
|
175
|
+
if (!above.linked) break;
|
|
176
|
+
above.original = current;
|
|
177
|
+
}
|
|
178
|
+
this.#mark(element, stack);
|
|
179
|
+
return true;
|
|
158
180
|
}
|
|
159
181
|
return(element) {
|
|
160
182
|
const held = this.#held.delete(element);
|
|
@@ -220,8 +242,8 @@ var AttributeLease = class {
|
|
|
220
242
|
setAttributeIfChanged(element, name, recorded);
|
|
221
243
|
}
|
|
222
244
|
}
|
|
223
|
-
#reflect(element, value) {
|
|
224
|
-
setAttributeIfChanged(element, this.#attribute, value);
|
|
245
|
+
#reflect(element, value, beforeWrite) {
|
|
246
|
+
setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
|
|
225
247
|
}
|
|
226
248
|
};
|
|
227
249
|
|
|
@@ -229,10 +251,6 @@ function matchingPart(root, selector) {
|
|
|
229
251
|
return root.matches(selector) ? root : root.querySelector(selector);
|
|
230
252
|
}
|
|
231
253
|
function writeLabel(slot, text) {
|
|
232
|
-
if (slot.childElementCount === 0) {
|
|
233
|
-
slot.textContent = text;
|
|
234
|
-
return;
|
|
235
|
-
}
|
|
236
254
|
let first = null;
|
|
237
255
|
for (const node of Array.from(slot.childNodes)) {
|
|
238
256
|
if (node.nodeType !== Node.TEXT_NODE) continue;
|
|
@@ -253,8 +271,12 @@ function readLabel(slot) {
|
|
|
253
271
|
|
|
254
272
|
var RovingTabindex = class {
|
|
255
273
|
#getItems;
|
|
256
|
-
|
|
274
|
+
#write;
|
|
275
|
+
constructor(getItems, write = (item, tabindex) => {
|
|
276
|
+
item.tabIndex = tabindex;
|
|
277
|
+
}) {
|
|
257
278
|
this.#getItems = getItems;
|
|
279
|
+
this.#write = write;
|
|
258
280
|
}
|
|
259
281
|
get activeIndex() {
|
|
260
282
|
return this.#getItems().findIndex((item) => item.tabIndex === 0);
|
|
@@ -263,7 +285,7 @@ var RovingTabindex = class {
|
|
|
263
285
|
const { focus = false } = options;
|
|
264
286
|
const items = options.items ?? this.#getItems();
|
|
265
287
|
items.forEach((item, i) => {
|
|
266
|
-
item
|
|
288
|
+
this.#write(item, i === index ? 0 : -1);
|
|
267
289
|
});
|
|
268
290
|
if (focus) items[index]?.focus();
|
|
269
291
|
}
|
|
@@ -393,7 +415,50 @@ function isCompositionInputType(inputType) {
|
|
|
393
415
|
return inputType !== void 0 && COMPOSITION_INPUT_TYPES.has(inputType);
|
|
394
416
|
}
|
|
395
417
|
var BEFORE_MORPH_ATTRIBUTE = "turbo:before-morph-attribute";
|
|
396
|
-
var textOf = (element) =>
|
|
418
|
+
var textOf = (element) => {
|
|
419
|
+
if ("value" in element) return element.value;
|
|
420
|
+
return element instanceof Element ? element.textContent : void 0;
|
|
421
|
+
};
|
|
422
|
+
var nodesOf = (element) => {
|
|
423
|
+
const nodes = [];
|
|
424
|
+
if ("value" in element || !(element instanceof Element)) return nodes;
|
|
425
|
+
const walker = element.ownerDocument.createTreeWalker(element);
|
|
426
|
+
for (let node = walker.nextNode(); node !== null; node = walker.nextNode()) nodes.push(node);
|
|
427
|
+
return nodes;
|
|
428
|
+
};
|
|
429
|
+
var folded = (text) => text.replaceAll("\xA0", " ");
|
|
430
|
+
var startOf = (node, data, replaced, caret) => {
|
|
431
|
+
const text = folded(node.data);
|
|
432
|
+
const composed = folded(data);
|
|
433
|
+
if (replaced?.startContainer === node && text.startsWith(composed, replaced.startOffset)) {
|
|
434
|
+
return replaced.startOffset;
|
|
435
|
+
}
|
|
436
|
+
const start = text.lastIndexOf(composed, caret);
|
|
437
|
+
return start !== -1 && start + composed.length >= caret ? start : -1;
|
|
438
|
+
};
|
|
439
|
+
var spotOf = (element, replaced, data) => {
|
|
440
|
+
if ("value" in element || !(element instanceof Element)) return null;
|
|
441
|
+
const selection = element.ownerDocument.getSelection();
|
|
442
|
+
const node = selection?.focusNode;
|
|
443
|
+
if (!(node instanceof Text) || node.data === "" || !element.contains(node)) return null;
|
|
444
|
+
const range = element.ownerDocument.createRange();
|
|
445
|
+
const start = typeof data === "string" && data !== "" ? startOf(node, data, replaced, selection?.focusOffset ?? 0) : -1;
|
|
446
|
+
if (start === -1) {
|
|
447
|
+
range.selectNodeContents(node);
|
|
448
|
+
} else {
|
|
449
|
+
range.setStart(node, start);
|
|
450
|
+
range.setEnd(node, start + data.length);
|
|
451
|
+
}
|
|
452
|
+
return range;
|
|
453
|
+
};
|
|
454
|
+
var replacedBy = (event) => typeof event.getTargetRanges === "function" ? event.getTargetRanges()[0] ?? null : null;
|
|
455
|
+
var rewritten = ({ element, text, nodes, spot }) => {
|
|
456
|
+
if (spot !== null) {
|
|
457
|
+
return spot.collapsed || !(element instanceof Node && element.contains(spot.startContainer));
|
|
458
|
+
}
|
|
459
|
+
const current = nodesOf(element);
|
|
460
|
+
return textOf(element) !== text || current.length !== nodes.length || current.some((node, index) => node !== nodes[index]);
|
|
461
|
+
};
|
|
397
462
|
var holdsFocus = (element) => element instanceof Node && element.getRootNode().activeElement === element;
|
|
398
463
|
var CompositionTracker = class {
|
|
399
464
|
#observedTargets = /* @__PURE__ */ new Set();
|
|
@@ -454,7 +519,7 @@ var CompositionTracker = class {
|
|
|
454
519
|
this.#confirmedTarget = null;
|
|
455
520
|
if (confirmed === null || confirmed !== event.target) return false;
|
|
456
521
|
const inputType = event.inputType;
|
|
457
|
-
return
|
|
522
|
+
return inputType ? isCompositionInputType(inputType) : event.isTrusted === true;
|
|
458
523
|
}
|
|
459
524
|
#release(target) {
|
|
460
525
|
target.removeEventListener("compositionstart", this.#handleStart);
|
|
@@ -484,11 +549,11 @@ var CompositionTracker = class {
|
|
|
484
549
|
}
|
|
485
550
|
#settle() {
|
|
486
551
|
const composition = this.#composition;
|
|
487
|
-
if (composition === null) return;
|
|
488
|
-
const { target, element
|
|
552
|
+
if (composition === null || !this.#observedTargets.has(composition.target)) return;
|
|
553
|
+
const { target, element } = composition;
|
|
489
554
|
if (target instanceof Node && element instanceof Node && !target.contains(element)) {
|
|
490
555
|
this.#composition = null;
|
|
491
|
-
} else if (
|
|
556
|
+
} else if (rewritten(composition)) {
|
|
492
557
|
this.#abandon(false);
|
|
493
558
|
}
|
|
494
559
|
}
|
|
@@ -513,7 +578,14 @@ var CompositionTracker = class {
|
|
|
513
578
|
this.#owe(true);
|
|
514
579
|
const target = event.currentTarget;
|
|
515
580
|
const element = event.target;
|
|
516
|
-
this.#composition = {
|
|
581
|
+
this.#composition = {
|
|
582
|
+
target,
|
|
583
|
+
element,
|
|
584
|
+
text: textOf(element),
|
|
585
|
+
nodes: nodesOf(element),
|
|
586
|
+
spot: spotOf(element, null, void 0),
|
|
587
|
+
replaced: null
|
|
588
|
+
};
|
|
517
589
|
this.#runAbandon();
|
|
518
590
|
this.#onStart?.(event);
|
|
519
591
|
};
|
|
@@ -537,6 +609,10 @@ var CompositionTracker = class {
|
|
|
537
609
|
if (this.#composition !== null && !keyComposing && !isComposing && inputType && !isCompositionInputType(inputType)) {
|
|
538
610
|
this.#abandon(true);
|
|
539
611
|
}
|
|
612
|
+
const composition = this.#composition;
|
|
613
|
+
if (composition !== null && event.target === composition.element) {
|
|
614
|
+
composition.replaced = replacedBy(event);
|
|
615
|
+
}
|
|
540
616
|
this.#runAbandon();
|
|
541
617
|
};
|
|
542
618
|
#handleInput = (event) => {
|
|
@@ -544,6 +620,15 @@ var CompositionTracker = class {
|
|
|
544
620
|
const { isTrusted, isComposing, inputType } = event;
|
|
545
621
|
if (composition !== null && event.target === composition.element && (isTrusted || isComposing || isCompositionInputType(inputType))) {
|
|
546
622
|
composition.text = textOf(composition.element);
|
|
623
|
+
composition.nodes = nodesOf(composition.element);
|
|
624
|
+
if (isCompositionInputType(inputType)) {
|
|
625
|
+
composition.spot = spotOf(
|
|
626
|
+
composition.element,
|
|
627
|
+
composition.replaced,
|
|
628
|
+
event.data
|
|
629
|
+
);
|
|
630
|
+
}
|
|
631
|
+
composition.replaced = null;
|
|
547
632
|
} else {
|
|
548
633
|
this.#settle();
|
|
549
634
|
}
|
|
@@ -564,7 +649,9 @@ var CompositionTracker = class {
|
|
|
564
649
|
const composition = this.#composition;
|
|
565
650
|
if (composition?.target !== event.currentTarget || event.target !== composition.element) return;
|
|
566
651
|
const detail = event.detail;
|
|
567
|
-
if (detail?.attributeName === "value"
|
|
652
|
+
if (detail?.attributeName === "value" && "value" in composition.element) {
|
|
653
|
+
event.preventDefault();
|
|
654
|
+
}
|
|
568
655
|
};
|
|
569
656
|
};
|
|
570
657
|
|
|
@@ -1088,9 +1175,11 @@ var MultiSelectController = class _MultiSelectController extends Controller {
|
|
|
1088
1175
|
#activeOptionId = null;
|
|
1089
1176
|
#tabindex = new TabindexLoan("-1", this.identifier);
|
|
1090
1177
|
#selectionValues = [];
|
|
1178
|
+
#selectionChips = /* @__PURE__ */ new Map();
|
|
1091
1179
|
#connected = false;
|
|
1092
1180
|
#emptyRegion = new StateRegions({ whenTrue: () => this.emptyTargets }, this.identifier);
|
|
1093
|
-
#
|
|
1181
|
+
#hidden = new AttributeLease("hidden", this.identifier);
|
|
1182
|
+
#selected = new AttributeLease("aria-selected", this.identifier);
|
|
1094
1183
|
#expanded = new AttributeLease("aria-expanded", this.identifier);
|
|
1095
1184
|
#activeDescendant = new AttributeLease(
|
|
1096
1185
|
"aria-activedescendant",
|
|
@@ -1110,9 +1199,10 @@ var MultiSelectController = class _MultiSelectController extends Controller {
|
|
|
1110
1199
|
outcome: "changed no selection",
|
|
1111
1200
|
noun: "chip template"
|
|
1112
1201
|
});
|
|
1202
|
+
#rowInert = new AttributeLease("inert", this.identifier);
|
|
1113
1203
|
#chipRow = new ChipRow({
|
|
1114
1204
|
getDirectionElement: () => this.#chipDirectionElement,
|
|
1115
|
-
getItems: () => this
|
|
1205
|
+
getItems: () => this.#chips,
|
|
1116
1206
|
getButton: (tag) => matchingPart(tag, `button${this.#rows.selector("remove")}`),
|
|
1117
1207
|
onRemove: (index) => this.#removeTagAt(index),
|
|
1118
1208
|
focusAfterEnd: () => this.#focusInput()
|
|
@@ -1123,13 +1213,14 @@ var MultiSelectController = class _MultiSelectController extends Controller {
|
|
|
1123
1213
|
this.#tab = null;
|
|
1124
1214
|
this.#tabindex.reclaim(this.element);
|
|
1125
1215
|
this.#rows.connect();
|
|
1216
|
+
this.#settleTagsRows();
|
|
1126
1217
|
this.#normalizeSelection([]);
|
|
1127
1218
|
this.close();
|
|
1128
1219
|
if (this.hasTagsTarget) {
|
|
1129
|
-
this.#chipRow.connect(this.tagsTarget);
|
|
1130
1220
|
this.#rebuildTags();
|
|
1131
1221
|
}
|
|
1132
1222
|
this.#selectionValues = this.#values;
|
|
1223
|
+
this.#selectionChips = this.#chipsByValue;
|
|
1133
1224
|
this.#syncFields();
|
|
1134
1225
|
this.#listeners.add(document, "click", this.#onOutsideClick, { capture: true });
|
|
1135
1226
|
this.#listeners.add(this.element, "keydown", this.#onTab);
|
|
@@ -1146,7 +1237,7 @@ var MultiSelectController = class _MultiSelectController extends Controller {
|
|
|
1146
1237
|
if (!chip) return;
|
|
1147
1238
|
chips.push(chip);
|
|
1148
1239
|
}
|
|
1149
|
-
for (const tag of this
|
|
1240
|
+
for (const tag of this.#chips) tag.remove();
|
|
1150
1241
|
this.tagsTarget.append(...chips);
|
|
1151
1242
|
this.#chipRow.ensureTabStop();
|
|
1152
1243
|
}
|
|
@@ -1163,17 +1254,22 @@ var MultiSelectController = class _MultiSelectController extends Controller {
|
|
|
1163
1254
|
this.#scheduleOptionReconcile();
|
|
1164
1255
|
}
|
|
1165
1256
|
optionTargetDisconnected(option) {
|
|
1257
|
+
if (this.optionTargets.includes(option)) return;
|
|
1166
1258
|
option.removeAttribute("data-active");
|
|
1259
|
+
this.#selected.return(option);
|
|
1260
|
+
if (!this.listTargets.includes(option)) this.#hidden.return(option);
|
|
1167
1261
|
this.#scheduleOptionReconcile();
|
|
1168
1262
|
}
|
|
1169
1263
|
emptyTargetConnected() {
|
|
1170
1264
|
if (this.#connected) this.#reflectEmpty();
|
|
1171
1265
|
}
|
|
1172
|
-
tagsTargetConnected(
|
|
1173
|
-
this.#chipRow.connect(tags);
|
|
1266
|
+
tagsTargetConnected(_tags) {
|
|
1174
1267
|
this.#scheduleOptionReconcile();
|
|
1175
1268
|
}
|
|
1176
1269
|
tagsTargetDisconnected(tags) {
|
|
1270
|
+
if (!this.scope.containsElement(tags) || !this.tagsTargets.includes(tags)) {
|
|
1271
|
+
this.#rowInert.return(tags);
|
|
1272
|
+
}
|
|
1177
1273
|
this.#chipRow.disconnect(tags);
|
|
1178
1274
|
this.#scheduleOptionReconcile();
|
|
1179
1275
|
}
|
|
@@ -1194,7 +1290,7 @@ var MultiSelectController = class _MultiSelectController extends Controller {
|
|
|
1194
1290
|
this.#adoptPageClose();
|
|
1195
1291
|
this.#openList = null;
|
|
1196
1292
|
}
|
|
1197
|
-
this.#
|
|
1293
|
+
if (!this.optionTargets.includes(list)) this.#hidden.return(list);
|
|
1198
1294
|
}
|
|
1199
1295
|
if (!this.#connected) return;
|
|
1200
1296
|
this.#reconcileOpenState();
|
|
@@ -1213,6 +1309,7 @@ var MultiSelectController = class _MultiSelectController extends Controller {
|
|
|
1213
1309
|
this.#reconcile.schedule();
|
|
1214
1310
|
}
|
|
1215
1311
|
#reconcileOptions() {
|
|
1312
|
+
this.#settleTagsRows();
|
|
1216
1313
|
const visible = this.#visibleOptions;
|
|
1217
1314
|
const active = this.#activeOption;
|
|
1218
1315
|
const next = this.#isClosed ? null : active && !active.hidden ? active : visible[0] ?? null;
|
|
@@ -1220,18 +1317,18 @@ var MultiSelectController = class _MultiSelectController extends Controller {
|
|
|
1220
1317
|
this.#reflectEmpty();
|
|
1221
1318
|
const previous = this.#selectionValues;
|
|
1222
1319
|
const previousLabels = new Map(
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
readLabel(matchingPart(
|
|
1320
|
+
Array.from(this.#selectionChips, ([value, { chip, label }]) => [
|
|
1321
|
+
value,
|
|
1322
|
+
chip.dataset.value === value ? readLabel(matchingPart(chip, this.#rows.selector("label"))) : label
|
|
1226
1323
|
])
|
|
1227
1324
|
);
|
|
1228
1325
|
const priority = [
|
|
1229
|
-
.../* @__PURE__ */ new Set([...this.
|
|
1326
|
+
.../* @__PURE__ */ new Set([...this.#chips.map((tag) => tag.dataset.value ?? ""), ...previous])
|
|
1230
1327
|
];
|
|
1231
1328
|
this.#normalizeSelection(priority);
|
|
1232
1329
|
const selected = this.#selectedOptions;
|
|
1233
1330
|
const nextValues = selected.map((option) => this.#optionValue(option)).sort();
|
|
1234
|
-
const tagValues = this.
|
|
1331
|
+
const tagValues = this.#chips.map((tag) => tag.dataset.value ?? "").sort();
|
|
1235
1332
|
const unchanged = nextValues.length === tagValues.length && nextValues.every((value, index) => value === tagValues[index]);
|
|
1236
1333
|
if (unchanged) this.#refreshTagLabels(selected);
|
|
1237
1334
|
else this.#rebuildTags();
|
|
@@ -1239,6 +1336,7 @@ var MultiSelectController = class _MultiSelectController extends Controller {
|
|
|
1239
1336
|
const values = this.#values;
|
|
1240
1337
|
const changed = !this.#sameSelection(previous, values);
|
|
1241
1338
|
this.#selectionValues = values;
|
|
1339
|
+
this.#selectionChips = this.#chipsByValue;
|
|
1242
1340
|
if (!changed) return;
|
|
1243
1341
|
const token = this.#moves.record();
|
|
1244
1342
|
const options = new Map(selected.map((option) => [this.#optionValue(option), option]));
|
|
@@ -1279,9 +1377,13 @@ var MultiSelectController = class _MultiSelectController extends Controller {
|
|
|
1279
1377
|
}
|
|
1280
1378
|
}
|
|
1281
1379
|
for (const option of this.optionTargets) {
|
|
1282
|
-
option
|
|
1380
|
+
this.#writeSelected(option, kept.has(option));
|
|
1283
1381
|
}
|
|
1284
1382
|
}
|
|
1383
|
+
#writeSelected(option, selected) {
|
|
1384
|
+
const value = String(selected);
|
|
1385
|
+
if (option.getAttribute("aria-selected") !== value) this.#selected.write(option, value);
|
|
1386
|
+
}
|
|
1285
1387
|
inputTargetConnected(input) {
|
|
1286
1388
|
this.#composition.observe(input);
|
|
1287
1389
|
this.#describeInput(input);
|
|
@@ -1300,14 +1402,13 @@ var MultiSelectController = class _MultiSelectController extends Controller {
|
|
|
1300
1402
|
this.#activeDescendant.write(input, active ? ensureId(active, "stimeo-ms-opt") : null);
|
|
1301
1403
|
}
|
|
1302
1404
|
#reconcileOpenState() {
|
|
1303
|
-
if (!this.hasListTarget) return;
|
|
1304
1405
|
this.#adoptPageClose();
|
|
1305
|
-
const list = this.listTarget;
|
|
1406
|
+
const list = this.hasListTarget ? this.listTarget : null;
|
|
1306
1407
|
if (list !== this.#openList) {
|
|
1307
|
-
this.#showList(list, this.#open);
|
|
1408
|
+
if (list) this.#showList(list, this.#open);
|
|
1308
1409
|
this.#openList = list;
|
|
1309
1410
|
}
|
|
1310
|
-
if (this.hasInputTarget) this.#expanded.write(this.inputTarget, String(!
|
|
1411
|
+
if (this.hasInputTarget) this.#expanded.write(this.inputTarget, String(!this.#isClosed));
|
|
1311
1412
|
}
|
|
1312
1413
|
#adoptPageClose() {
|
|
1313
1414
|
if (this.#openList?.hidden) this.#open = false;
|
|
@@ -1319,7 +1420,8 @@ var MultiSelectController = class _MultiSelectController extends Controller {
|
|
|
1319
1420
|
const query = this.inputTarget.value.trim().toLowerCase();
|
|
1320
1421
|
for (const option of this.optionTargets) {
|
|
1321
1422
|
const label = (option.textContent ?? "").trim().toLowerCase();
|
|
1322
|
-
|
|
1423
|
+
if (query === "" || label.includes(query)) this.#hidden.return(option);
|
|
1424
|
+
else if (!option.hidden) this.#hidden.write(option, "");
|
|
1323
1425
|
}
|
|
1324
1426
|
this.open();
|
|
1325
1427
|
const visible = this.#visibleOptions;
|
|
@@ -1331,23 +1433,21 @@ var MultiSelectController = class _MultiSelectController extends Controller {
|
|
|
1331
1433
|
this.#tab = null;
|
|
1332
1434
|
return;
|
|
1333
1435
|
}
|
|
1334
|
-
if (!this.
|
|
1436
|
+
if (!this.hasInputTarget) {
|
|
1335
1437
|
this.#reflectEmpty();
|
|
1336
1438
|
return;
|
|
1337
1439
|
}
|
|
1338
|
-
this.#showList(this.listTarget, true);
|
|
1339
1440
|
this.#open = true;
|
|
1340
|
-
this.#openList = this.listTarget;
|
|
1441
|
+
this.#openList = this.hasListTarget ? this.listTarget : null;
|
|
1442
|
+
if (this.#openList) this.#showList(this.#openList, true);
|
|
1341
1443
|
this.#expanded.write(this.inputTarget, "true");
|
|
1342
1444
|
if (!this.#activeOption) this.#setActive(this.#visibleOptions[0] ?? null);
|
|
1343
1445
|
this.#reflectEmpty();
|
|
1344
1446
|
}
|
|
1345
1447
|
close() {
|
|
1346
1448
|
this.#open = false;
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
this.#openList = this.listTarget;
|
|
1350
|
-
}
|
|
1449
|
+
this.#openList = this.hasListTarget ? this.listTarget : null;
|
|
1450
|
+
if (this.#openList) this.#showList(this.#openList, false);
|
|
1351
1451
|
this.#setActive(null);
|
|
1352
1452
|
if (this.hasInputTarget) this.#expanded.write(this.inputTarget, "false");
|
|
1353
1453
|
this.#reflectEmpty();
|
|
@@ -1358,6 +1458,7 @@ var MultiSelectController = class _MultiSelectController extends Controller {
|
|
|
1358
1458
|
if ((event.key === "Home" || event.key === "End") && hasModifierChord(event)) return;
|
|
1359
1459
|
if (!this.hasInputTarget) return;
|
|
1360
1460
|
if (this.#composition.isComposing(event)) return;
|
|
1461
|
+
this.#reconcileOpenState();
|
|
1361
1462
|
this.#reconcileActiveForInteraction();
|
|
1362
1463
|
switch (logicalArrowKey(event.key, this.#chipDirectionElement)) {
|
|
1363
1464
|
case "ArrowDown":
|
|
@@ -1438,6 +1539,33 @@ var MultiSelectController = class _MultiSelectController extends Controller {
|
|
|
1438
1539
|
if (focus && (event !== null || this.element.contains(document.activeElement)))
|
|
1439
1540
|
this.#focusInput();
|
|
1440
1541
|
}
|
|
1542
|
+
get #chips() {
|
|
1543
|
+
if (!this.hasTagsTarget) return this.tagTargets;
|
|
1544
|
+
const row = this.tagsTarget;
|
|
1545
|
+
const selector = this.#rows.selector("tags");
|
|
1546
|
+
return this.tagTargets.filter((tag) => tag.closest(selector) === row);
|
|
1547
|
+
}
|
|
1548
|
+
get #chipsByValue() {
|
|
1549
|
+
return new Map(
|
|
1550
|
+
this.#chips.map((tag) => [
|
|
1551
|
+
tag.dataset.value ?? "",
|
|
1552
|
+
{ chip: tag, label: readLabel(matchingPart(tag, this.#rows.selector("label"))) }
|
|
1553
|
+
])
|
|
1554
|
+
);
|
|
1555
|
+
}
|
|
1556
|
+
#settleTagsRows() {
|
|
1557
|
+
const [current, ...behind] = this.tagsTargets;
|
|
1558
|
+
if (!current) {
|
|
1559
|
+
this.#chipRow.disconnect();
|
|
1560
|
+
return;
|
|
1561
|
+
}
|
|
1562
|
+
this.#rowInert.return(current);
|
|
1563
|
+
this.#chipRow.connect(current);
|
|
1564
|
+
for (const row of behind) {
|
|
1565
|
+
if (row.contains(document.activeElement)) this.#focusInput();
|
|
1566
|
+
this.#rowInert.write(row, "");
|
|
1567
|
+
}
|
|
1568
|
+
}
|
|
1441
1569
|
get #chipDirectionElement() {
|
|
1442
1570
|
return this.hasTagsTarget ? this.tagsTarget : this.element;
|
|
1443
1571
|
}
|
|
@@ -1475,11 +1603,11 @@ var MultiSelectController = class _MultiSelectController extends Controller {
|
|
|
1475
1603
|
return true;
|
|
1476
1604
|
}
|
|
1477
1605
|
if (selected) {
|
|
1478
|
-
option
|
|
1606
|
+
this.#writeSelected(option, false);
|
|
1479
1607
|
this.#removeTagFor(option);
|
|
1480
1608
|
} else {
|
|
1481
1609
|
if (this.hasTagTemplateTarget && !this.#appendTag(option)) return true;
|
|
1482
|
-
option
|
|
1610
|
+
this.#writeSelected(option, true);
|
|
1483
1611
|
}
|
|
1484
1612
|
this.#refreshRoving();
|
|
1485
1613
|
return this.#publishSelection(
|
|
@@ -1491,7 +1619,7 @@ var MultiSelectController = class _MultiSelectController extends Controller {
|
|
|
1491
1619
|
}
|
|
1492
1620
|
#refreshTagLabels(selected) {
|
|
1493
1621
|
const options = new Map(selected.map((option) => [this.#optionValue(option), option]));
|
|
1494
|
-
for (const tag of this
|
|
1622
|
+
for (const tag of this.#chips) {
|
|
1495
1623
|
const option = options.get(tag.dataset.value ?? "");
|
|
1496
1624
|
const text = this.#optionLabel(option);
|
|
1497
1625
|
const label = matchingPart(tag, this.#rows.selector("label"));
|
|
@@ -1529,18 +1657,21 @@ var MultiSelectController = class _MultiSelectController extends Controller {
|
|
|
1529
1657
|
}
|
|
1530
1658
|
#removeTagFor(option) {
|
|
1531
1659
|
const value = this.#optionValue(option);
|
|
1532
|
-
const tag = this.
|
|
1660
|
+
const tag = this.#chips.find((candidate) => candidate.dataset.value === value);
|
|
1533
1661
|
tag?.remove();
|
|
1534
1662
|
}
|
|
1535
1663
|
#removeTagAt(index, focus = "neighbor") {
|
|
1536
|
-
const
|
|
1664
|
+
const tags = this.#chips;
|
|
1665
|
+
const tag = tags[index];
|
|
1537
1666
|
if (!tag) return;
|
|
1667
|
+
const afterFocus2 = focus === "neighbor" && tags.length === 1 && this.hasInputTarget;
|
|
1538
1668
|
const value = tag.dataset.value ?? "";
|
|
1539
1669
|
const option = this.optionTargets.find((candidate) => this.#optionValue(candidate) === value);
|
|
1540
|
-
if (option) option
|
|
1670
|
+
if (option) this.#writeSelected(option, false);
|
|
1541
1671
|
tag.remove();
|
|
1542
1672
|
this.#refreshRoving();
|
|
1543
|
-
|
|
1673
|
+
const label = option ? this.#optionLabel(option) : value;
|
|
1674
|
+
if (!this.#publishSelection(false, label, value, "user", afterFocus2)) return;
|
|
1544
1675
|
if (focus === "input") {
|
|
1545
1676
|
this.#focusInput();
|
|
1546
1677
|
return;
|
|
@@ -1568,7 +1699,7 @@ var MultiSelectController = class _MultiSelectController extends Controller {
|
|
|
1568
1699
|
}
|
|
1569
1700
|
}
|
|
1570
1701
|
#reflectEmpty() {
|
|
1571
|
-
const empty = !this.#isClosed && this.#visibleOptions.length === 0;
|
|
1702
|
+
const empty = this.hasListTarget && !this.#isClosed && this.#visibleOptions.length === 0;
|
|
1572
1703
|
this.element.toggleAttribute(`data-${this.identifier}-empty`, empty);
|
|
1573
1704
|
this.#emptyRegion.reflect(this.element, empty);
|
|
1574
1705
|
}
|
|
@@ -1577,16 +1708,17 @@ var MultiSelectController = class _MultiSelectController extends Controller {
|
|
|
1577
1708
|
const options = { name: this.nameValue, form: this.formValue };
|
|
1578
1709
|
return writeFields(this.fieldsTarget, this.#values, options);
|
|
1579
1710
|
}
|
|
1580
|
-
#publishSelection(selected, label, value, reason = "user") {
|
|
1711
|
+
#publishSelection(selected, label, value, reason = "user", afterFocus2 = false) {
|
|
1581
1712
|
const values = this.#values;
|
|
1582
1713
|
const changed = !this.#sameSelection(this.#selectionValues, values);
|
|
1583
1714
|
const fieldChanged = this.#syncFields();
|
|
1584
1715
|
this.#selectionValues = values;
|
|
1716
|
+
this.#selectionChips = this.#chipsByValue;
|
|
1585
1717
|
if (!changed) return true;
|
|
1586
1718
|
const token = this.#moves.record();
|
|
1587
1719
|
if (fieldChanged) commitField(this.fieldsTarget);
|
|
1588
1720
|
if (!this.#moves.isLatest(token)) return false;
|
|
1589
|
-
this.#announceTransition(selected, label, value, values.length);
|
|
1721
|
+
this.#announceTransition(selected, label, value, values.length, afterFocus2);
|
|
1590
1722
|
if (!this.#moves.isLatest(token)) return false;
|
|
1591
1723
|
this.dispatch("change", { detail: { values, reason } });
|
|
1592
1724
|
return this.#moves.isLatest(token);
|
|
@@ -1594,9 +1726,9 @@ var MultiSelectController = class _MultiSelectController extends Controller {
|
|
|
1594
1726
|
#refreshRoving() {
|
|
1595
1727
|
this.#chipRow.ensureTabStop();
|
|
1596
1728
|
}
|
|
1597
|
-
#announceTransition(selected, label, value, count) {
|
|
1729
|
+
#announceTransition(selected, label, value, count, afterFocus2 = false) {
|
|
1598
1730
|
const template = selected ? this.announceTextValue : this.announceRemovedTextValue;
|
|
1599
|
-
announce(fillTemplate(template, { label, value, count }));
|
|
1731
|
+
announce(fillTemplate(template, { label, value, count }), { afterFocus: afterFocus2 });
|
|
1600
1732
|
}
|
|
1601
1733
|
#sameSelection(left, right) {
|
|
1602
1734
|
if (left.length !== right.length) return false;
|
|
@@ -1614,9 +1746,10 @@ var MultiSelectController = class _MultiSelectController extends Controller {
|
|
|
1614
1746
|
return option.dataset.value ?? this.#optionLabel(option);
|
|
1615
1747
|
}
|
|
1616
1748
|
get #visibleOptions() {
|
|
1617
|
-
return this.optionTargets.filter((option) => !option.hidden);
|
|
1749
|
+
return this.hasListTarget ? this.optionTargets.filter((option) => !option.hidden) : [];
|
|
1618
1750
|
}
|
|
1619
1751
|
get #activeOption() {
|
|
1752
|
+
if (!this.hasListTarget) return null;
|
|
1620
1753
|
return this.optionTargets.find((option) => option.id === this.#activeOptionId) ?? null;
|
|
1621
1754
|
}
|
|
1622
1755
|
get #selectedOptions() {
|
|
@@ -1630,10 +1763,10 @@ var MultiSelectController = class _MultiSelectController extends Controller {
|
|
|
1630
1763
|
return Math.max(1, Math.floor(this.#safeMax));
|
|
1631
1764
|
}
|
|
1632
1765
|
#showList(list, open) {
|
|
1633
|
-
this.#
|
|
1766
|
+
this.#hidden.write(list, open ? null : "");
|
|
1634
1767
|
}
|
|
1635
1768
|
get #isClosed() {
|
|
1636
|
-
return
|
|
1769
|
+
return this.#openList ? this.#openList.hidden !== false : !this.#open;
|
|
1637
1770
|
}
|
|
1638
1771
|
get #safeMax() {
|
|
1639
1772
|
return this.#numbers.read(
|
|
@@ -73,6 +73,7 @@ var EscapeLayer = class _EscapeLayer {
|
|
|
73
73
|
);
|
|
74
74
|
#active = null;
|
|
75
75
|
activate(ownerDocument = document, options) {
|
|
76
|
+
const entry = { onDismiss: options.onDismiss, claims: options.claims ?? null };
|
|
76
77
|
this.deactivate();
|
|
77
78
|
let registry = _EscapeLayer.#registries.get(ownerDocument);
|
|
78
79
|
if (!registry) {
|
|
@@ -80,7 +81,6 @@ var EscapeLayer = class _EscapeLayer {
|
|
|
80
81
|
_EscapeLayer.#registries.set(ownerDocument, registry);
|
|
81
82
|
ownerDocument.addEventListener("keydown", registry.onKeydown);
|
|
82
83
|
}
|
|
83
|
-
const entry = { onDismiss: options.onDismiss, claims: options.claims ?? null };
|
|
84
84
|
registry.stack.push(entry);
|
|
85
85
|
this.#active = { document: ownerDocument, entry };
|
|
86
86
|
}
|