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
|
@@ -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
|
function isRtl(element) {
|
|
@@ -31,14 +32,184 @@ function isReservedArrowChord(event, allow = []) {
|
|
|
31
32
|
return event.altKey && !allow.includes("alt") || event.ctrlKey && !allow.includes("ctrl") || event.metaKey && !allow.includes("meta") || event.shiftKey && !allow.includes("shift");
|
|
32
33
|
}
|
|
33
34
|
|
|
35
|
+
function setAttributeIfChanged(element, name, value, beforeWrite) {
|
|
36
|
+
if (element.getAttribute(name) === value) return false;
|
|
37
|
+
beforeWrite?.();
|
|
38
|
+
if (value === null) element.removeAttribute(name);
|
|
39
|
+
else element.setAttribute(name, value);
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function sharedRegistry(key, create) {
|
|
44
|
+
const symbol = Symbol.for(key);
|
|
45
|
+
const scope = globalThis;
|
|
46
|
+
const existing = scope[symbol];
|
|
47
|
+
if (existing !== void 0) return existing;
|
|
48
|
+
const registry2 = create();
|
|
49
|
+
Object.defineProperty(globalThis, symbol, { value: registry2 });
|
|
50
|
+
return registry2;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
var registry = sharedRegistry(
|
|
54
|
+
"stimeo-ui.attribute-lease.registry.v1",
|
|
55
|
+
() => ({ stacks: /* @__PURE__ */ new WeakMap(), names: /* @__PURE__ */ new Map() })
|
|
56
|
+
);
|
|
57
|
+
function isAttributeValue(value) {
|
|
58
|
+
return value === null || typeof value === "string";
|
|
59
|
+
}
|
|
60
|
+
function readLeaseRecord(element, record) {
|
|
61
|
+
try {
|
|
62
|
+
const parsed = JSON.parse(element.getAttribute(record) ?? "null");
|
|
63
|
+
if (!Array.isArray(parsed)) return void 0;
|
|
64
|
+
const [original, written, ...rest] = parsed;
|
|
65
|
+
const linked = rest[0] !== false;
|
|
66
|
+
const beneath = linked ? rest : rest.slice(1);
|
|
67
|
+
if (!beneath.every((under) => typeof under === "string")) return void 0;
|
|
68
|
+
return isAttributeValue(original) && isAttributeValue(written) ? { original, written, linked, beneath } : void 0;
|
|
69
|
+
} catch {
|
|
70
|
+
return void 0;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function attributeStack(element, attribute) {
|
|
74
|
+
const byAttribute = registry.stacks.get(element) ?? /* @__PURE__ */ new Map();
|
|
75
|
+
registry.stacks.set(element, byAttribute);
|
|
76
|
+
const known = byAttribute.get(attribute);
|
|
77
|
+
if (known) return known;
|
|
78
|
+
const found = [];
|
|
79
|
+
for (const record of registry.names.get(attribute) ?? []) {
|
|
80
|
+
const read = readLeaseRecord(element, record);
|
|
81
|
+
if (read) found.push({ ...read, record });
|
|
82
|
+
}
|
|
83
|
+
const depth = ({ beneath }) => beneath.filter((name) => found.some((other) => other.record === name)).length;
|
|
84
|
+
const stack = found.sort((one, other) => depth(one) - depth(other)).map(({ record, written, original, linked }, index) => ({
|
|
85
|
+
lease: null,
|
|
86
|
+
record,
|
|
87
|
+
written,
|
|
88
|
+
original,
|
|
89
|
+
linked: linked && index > 0
|
|
90
|
+
}));
|
|
91
|
+
byAttribute.set(attribute, stack);
|
|
92
|
+
return stack;
|
|
93
|
+
}
|
|
94
|
+
function findHold(stack, lease, record) {
|
|
95
|
+
return stack.find((held) => held.lease === lease) ?? stack.find((held) => held.lease === null && held.record === record);
|
|
96
|
+
}
|
|
97
|
+
var AttributeLease = class {
|
|
98
|
+
#attribute;
|
|
99
|
+
#record;
|
|
100
|
+
#base;
|
|
101
|
+
#preserveAuthor;
|
|
102
|
+
#held = /* @__PURE__ */ new Set();
|
|
103
|
+
constructor(attribute, owner, options = {}) {
|
|
104
|
+
this.#attribute = attribute;
|
|
105
|
+
this.#record = `data-${owner}-${attribute}-lease`;
|
|
106
|
+
this.#base = options.base === true;
|
|
107
|
+
this.#preserveAuthor = options.preserveAuthor === true;
|
|
108
|
+
const names = registry.names;
|
|
109
|
+
names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
|
|
110
|
+
}
|
|
111
|
+
write(element, value, beforeWrite) {
|
|
112
|
+
const stack = attributeStack(element, this.#attribute);
|
|
113
|
+
const hold = this.#take(stack) ?? this.#acquire(element, stack);
|
|
114
|
+
this.#held.add(element);
|
|
115
|
+
const shows = !this.#covered(element, stack, hold);
|
|
116
|
+
hold.written = value;
|
|
117
|
+
this.#mark(element, stack);
|
|
118
|
+
if (shows) this.#reflect(element, value, beforeWrite);
|
|
119
|
+
}
|
|
120
|
+
adopt(element, options = {}) {
|
|
121
|
+
const known = registry.stacks.get(element)?.has(this.#attribute);
|
|
122
|
+
if (!this.#held.has(element) && !known && !element.hasAttribute(this.#record)) return false;
|
|
123
|
+
const stack = attributeStack(element, this.#attribute);
|
|
124
|
+
const hold = this.#take(stack);
|
|
125
|
+
if (!hold) return false;
|
|
126
|
+
const current = element.getAttribute(this.#attribute);
|
|
127
|
+
if (options.ifChanged && (current === hold.written || this.#covered(element, stack, hold))) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
this.#held.add(element);
|
|
131
|
+
hold.original = current;
|
|
132
|
+
hold.linked = false;
|
|
133
|
+
for (const above of stack.slice(stack.indexOf(hold) + 1)) {
|
|
134
|
+
if (!above.linked) break;
|
|
135
|
+
above.original = current;
|
|
136
|
+
}
|
|
137
|
+
this.#mark(element, stack);
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
return(element) {
|
|
141
|
+
const held = this.#held.delete(element);
|
|
142
|
+
const known = registry.stacks.get(element)?.has(this.#attribute);
|
|
143
|
+
const stack = held || known || element.hasAttribute(this.#record) ? attributeStack(element, this.#attribute) : [];
|
|
144
|
+
const hold = this.#take(stack);
|
|
145
|
+
if (!hold) return false;
|
|
146
|
+
const carries = element.getAttribute(this.#attribute) === hold.written;
|
|
147
|
+
const owns = carries && !this.#covered(element, stack, hold);
|
|
148
|
+
const index = stack.indexOf(hold);
|
|
149
|
+
stack.splice(index, 1);
|
|
150
|
+
const above = stack[index];
|
|
151
|
+
if (above) above.linked &&= hold.linked;
|
|
152
|
+
this.#mark(element, stack);
|
|
153
|
+
if (!owns) return true;
|
|
154
|
+
const below = hold.linked ? stack[index - 1] : void 0;
|
|
155
|
+
this.#reflect(element, below ? below.written : hold.original);
|
|
156
|
+
return true;
|
|
157
|
+
}
|
|
158
|
+
returnAll() {
|
|
159
|
+
for (const element of Array.from(this.#held)) this.return(element);
|
|
160
|
+
}
|
|
161
|
+
#take(stack) {
|
|
162
|
+
const hold = findHold(stack, this, this.#record);
|
|
163
|
+
if (hold) hold.lease = this;
|
|
164
|
+
return hold;
|
|
165
|
+
}
|
|
166
|
+
#acquire(element, stack) {
|
|
167
|
+
const current = element.getAttribute(this.#attribute);
|
|
168
|
+
const top = stack.at(-1);
|
|
169
|
+
const bottom = stack[0];
|
|
170
|
+
const over = top?.written === current ? top : void 0;
|
|
171
|
+
const from = this.#base ? this.#preserveAuthor && !stack.some((held) => held.written === current) ? void 0 : bottom : over;
|
|
172
|
+
const hold = {
|
|
173
|
+
lease: this,
|
|
174
|
+
record: this.#record,
|
|
175
|
+
written: current,
|
|
176
|
+
original: from ? from.original : current,
|
|
177
|
+
linked: !this.#base && over !== void 0
|
|
178
|
+
};
|
|
179
|
+
if (this.#base && bottom) {
|
|
180
|
+
bottom.linked = true;
|
|
181
|
+
stack.unshift(hold);
|
|
182
|
+
} else stack.push(hold);
|
|
183
|
+
return hold;
|
|
184
|
+
}
|
|
185
|
+
#covered(element, stack, hold) {
|
|
186
|
+
const current = element.getAttribute(this.#attribute);
|
|
187
|
+
return stack.slice(stack.indexOf(hold) + 1).some((above) => above.written === current);
|
|
188
|
+
}
|
|
189
|
+
#mark(element, stack) {
|
|
190
|
+
const records = /* @__PURE__ */ new Map([[this.#record, null]]);
|
|
191
|
+
stack.forEach((hold, index) => {
|
|
192
|
+
const names = stack.slice(0, index).map((under) => under.record);
|
|
193
|
+
const beneath = [...new Set(names.reverse())].filter((name) => name !== hold.record);
|
|
194
|
+
const marker = hold.linked || beneath.length === 0 ? [] : [false];
|
|
195
|
+
records.set(
|
|
196
|
+
hold.record,
|
|
197
|
+
hold.written === hold.original && beneath.length === 0 && index === stack.length - 1 ? null : JSON.stringify([hold.original, hold.written, ...marker, ...beneath])
|
|
198
|
+
);
|
|
199
|
+
});
|
|
200
|
+
for (const [name, recorded] of records) {
|
|
201
|
+
setAttributeIfChanged(element, name, recorded);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
#reflect(element, value, beforeWrite) {
|
|
205
|
+
setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
|
|
34
209
|
function matchingPart(root, selector) {
|
|
35
210
|
return root.matches(selector) ? root : root.querySelector(selector);
|
|
36
211
|
}
|
|
37
212
|
function writeLabel(slot, text) {
|
|
38
|
-
if (slot.childElementCount === 0) {
|
|
39
|
-
slot.textContent = text;
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
213
|
let first = null;
|
|
43
214
|
for (const node of Array.from(slot.childNodes)) {
|
|
44
215
|
if (node.nodeType !== Node.TEXT_NODE) continue;
|
|
@@ -51,8 +222,12 @@ function writeLabel(slot, text) {
|
|
|
51
222
|
|
|
52
223
|
var RovingTabindex = class {
|
|
53
224
|
#getItems;
|
|
54
|
-
|
|
225
|
+
#write;
|
|
226
|
+
constructor(getItems, write = (item, tabindex) => {
|
|
227
|
+
item.tabIndex = tabindex;
|
|
228
|
+
}) {
|
|
55
229
|
this.#getItems = getItems;
|
|
230
|
+
this.#write = write;
|
|
56
231
|
}
|
|
57
232
|
get activeIndex() {
|
|
58
233
|
return this.#getItems().findIndex((item) => item.tabIndex === 0);
|
|
@@ -61,7 +236,7 @@ var RovingTabindex = class {
|
|
|
61
236
|
const { focus = false } = options;
|
|
62
237
|
const items = options.items ?? this.#getItems();
|
|
63
238
|
items.forEach((item, i) => {
|
|
64
|
-
item
|
|
239
|
+
this.#write(item, i === index ? 0 : -1);
|
|
65
240
|
});
|
|
66
241
|
if (focus) items[index]?.focus();
|
|
67
242
|
}
|
|
@@ -191,7 +366,50 @@ function isCompositionInputType(inputType) {
|
|
|
191
366
|
return inputType !== void 0 && COMPOSITION_INPUT_TYPES.has(inputType);
|
|
192
367
|
}
|
|
193
368
|
var BEFORE_MORPH_ATTRIBUTE = "turbo:before-morph-attribute";
|
|
194
|
-
var textOf = (element) =>
|
|
369
|
+
var textOf = (element) => {
|
|
370
|
+
if ("value" in element) return element.value;
|
|
371
|
+
return element instanceof Element ? element.textContent : void 0;
|
|
372
|
+
};
|
|
373
|
+
var nodesOf = (element) => {
|
|
374
|
+
const nodes = [];
|
|
375
|
+
if ("value" in element || !(element instanceof Element)) return nodes;
|
|
376
|
+
const walker = element.ownerDocument.createTreeWalker(element);
|
|
377
|
+
for (let node = walker.nextNode(); node !== null; node = walker.nextNode()) nodes.push(node);
|
|
378
|
+
return nodes;
|
|
379
|
+
};
|
|
380
|
+
var folded = (text) => text.replaceAll("\xA0", " ");
|
|
381
|
+
var startOf = (node, data, replaced, caret) => {
|
|
382
|
+
const text = folded(node.data);
|
|
383
|
+
const composed = folded(data);
|
|
384
|
+
if (replaced?.startContainer === node && text.startsWith(composed, replaced.startOffset)) {
|
|
385
|
+
return replaced.startOffset;
|
|
386
|
+
}
|
|
387
|
+
const start = text.lastIndexOf(composed, caret);
|
|
388
|
+
return start !== -1 && start + composed.length >= caret ? start : -1;
|
|
389
|
+
};
|
|
390
|
+
var spotOf = (element, replaced, data) => {
|
|
391
|
+
if ("value" in element || !(element instanceof Element)) return null;
|
|
392
|
+
const selection = element.ownerDocument.getSelection();
|
|
393
|
+
const node = selection?.focusNode;
|
|
394
|
+
if (!(node instanceof Text) || node.data === "" || !element.contains(node)) return null;
|
|
395
|
+
const range = element.ownerDocument.createRange();
|
|
396
|
+
const start = typeof data === "string" && data !== "" ? startOf(node, data, replaced, selection?.focusOffset ?? 0) : -1;
|
|
397
|
+
if (start === -1) {
|
|
398
|
+
range.selectNodeContents(node);
|
|
399
|
+
} else {
|
|
400
|
+
range.setStart(node, start);
|
|
401
|
+
range.setEnd(node, start + data.length);
|
|
402
|
+
}
|
|
403
|
+
return range;
|
|
404
|
+
};
|
|
405
|
+
var replacedBy = (event) => typeof event.getTargetRanges === "function" ? event.getTargetRanges()[0] ?? null : null;
|
|
406
|
+
var rewritten = ({ element, text, nodes, spot }) => {
|
|
407
|
+
if (spot !== null) {
|
|
408
|
+
return spot.collapsed || !(element instanceof Node && element.contains(spot.startContainer));
|
|
409
|
+
}
|
|
410
|
+
const current = nodesOf(element);
|
|
411
|
+
return textOf(element) !== text || current.length !== nodes.length || current.some((node, index) => node !== nodes[index]);
|
|
412
|
+
};
|
|
195
413
|
var holdsFocus = (element) => element instanceof Node && element.getRootNode().activeElement === element;
|
|
196
414
|
var CompositionTracker = class {
|
|
197
415
|
#observedTargets = /* @__PURE__ */ new Set();
|
|
@@ -252,7 +470,7 @@ var CompositionTracker = class {
|
|
|
252
470
|
this.#confirmedTarget = null;
|
|
253
471
|
if (confirmed === null || confirmed !== event.target) return false;
|
|
254
472
|
const inputType = event.inputType;
|
|
255
|
-
return
|
|
473
|
+
return inputType ? isCompositionInputType(inputType) : event.isTrusted === true;
|
|
256
474
|
}
|
|
257
475
|
#release(target) {
|
|
258
476
|
target.removeEventListener("compositionstart", this.#handleStart);
|
|
@@ -282,11 +500,11 @@ var CompositionTracker = class {
|
|
|
282
500
|
}
|
|
283
501
|
#settle() {
|
|
284
502
|
const composition = this.#composition;
|
|
285
|
-
if (composition === null) return;
|
|
286
|
-
const { target, element
|
|
503
|
+
if (composition === null || !this.#observedTargets.has(composition.target)) return;
|
|
504
|
+
const { target, element } = composition;
|
|
287
505
|
if (target instanceof Node && element instanceof Node && !target.contains(element)) {
|
|
288
506
|
this.#composition = null;
|
|
289
|
-
} else if (
|
|
507
|
+
} else if (rewritten(composition)) {
|
|
290
508
|
this.#abandon(false);
|
|
291
509
|
}
|
|
292
510
|
}
|
|
@@ -311,7 +529,14 @@ var CompositionTracker = class {
|
|
|
311
529
|
this.#owe(true);
|
|
312
530
|
const target = event.currentTarget;
|
|
313
531
|
const element = event.target;
|
|
314
|
-
this.#composition = {
|
|
532
|
+
this.#composition = {
|
|
533
|
+
target,
|
|
534
|
+
element,
|
|
535
|
+
text: textOf(element),
|
|
536
|
+
nodes: nodesOf(element),
|
|
537
|
+
spot: spotOf(element, null, void 0),
|
|
538
|
+
replaced: null
|
|
539
|
+
};
|
|
315
540
|
this.#runAbandon();
|
|
316
541
|
this.#onStart?.(event);
|
|
317
542
|
};
|
|
@@ -335,6 +560,10 @@ var CompositionTracker = class {
|
|
|
335
560
|
if (this.#composition !== null && !keyComposing && !isComposing && inputType && !isCompositionInputType(inputType)) {
|
|
336
561
|
this.#abandon(true);
|
|
337
562
|
}
|
|
563
|
+
const composition = this.#composition;
|
|
564
|
+
if (composition !== null && event.target === composition.element) {
|
|
565
|
+
composition.replaced = replacedBy(event);
|
|
566
|
+
}
|
|
338
567
|
this.#runAbandon();
|
|
339
568
|
};
|
|
340
569
|
#handleInput = (event) => {
|
|
@@ -342,6 +571,15 @@ var CompositionTracker = class {
|
|
|
342
571
|
const { isTrusted, isComposing, inputType } = event;
|
|
343
572
|
if (composition !== null && event.target === composition.element && (isTrusted || isComposing || isCompositionInputType(inputType))) {
|
|
344
573
|
composition.text = textOf(composition.element);
|
|
574
|
+
composition.nodes = nodesOf(composition.element);
|
|
575
|
+
if (isCompositionInputType(inputType)) {
|
|
576
|
+
composition.spot = spotOf(
|
|
577
|
+
composition.element,
|
|
578
|
+
composition.replaced,
|
|
579
|
+
event.data
|
|
580
|
+
);
|
|
581
|
+
}
|
|
582
|
+
composition.replaced = null;
|
|
345
583
|
} else {
|
|
346
584
|
this.#settle();
|
|
347
585
|
}
|
|
@@ -362,7 +600,9 @@ var CompositionTracker = class {
|
|
|
362
600
|
const composition = this.#composition;
|
|
363
601
|
if (composition?.target !== event.currentTarget || event.target !== composition.element) return;
|
|
364
602
|
const detail = event.detail;
|
|
365
|
-
if (detail?.attributeName === "value"
|
|
603
|
+
if (detail?.attributeName === "value" && "value" in composition.element) {
|
|
604
|
+
event.preventDefault();
|
|
605
|
+
}
|
|
366
606
|
};
|
|
367
607
|
};
|
|
368
608
|
|
|
@@ -606,9 +846,10 @@ var TagsInputController = class _TagsInputController extends Controller {
|
|
|
606
846
|
noun: "chip template"
|
|
607
847
|
});
|
|
608
848
|
#reconcile = new MorphRenderWatcher(() => this.#reconcileTags());
|
|
849
|
+
#rowInert = new AttributeLease("inert", this.identifier);
|
|
609
850
|
#chipRow = new ChipRow({
|
|
610
851
|
getDirectionElement: () => this.#chipDirectionElement,
|
|
611
|
-
getItems: () => this
|
|
852
|
+
getItems: () => this.#chips,
|
|
612
853
|
getButton: (tag) => matchingPart(tag, `button${this.#rows.selector("remove")}`),
|
|
613
854
|
onRemove: (index) => this.#removeAt(index),
|
|
614
855
|
focusAfterEnd: () => this.#focusInput()
|
|
@@ -617,7 +858,7 @@ var TagsInputController = class _TagsInputController extends Controller {
|
|
|
617
858
|
connect() {
|
|
618
859
|
this.#rows.connect();
|
|
619
860
|
if (this.hasInputTarget) this.#composition.observe(this.inputTarget);
|
|
620
|
-
|
|
861
|
+
this.#settleTagsRows();
|
|
621
862
|
const tags = this.#values;
|
|
622
863
|
this.#syncState(tags);
|
|
623
864
|
this.#tagValues = tags;
|
|
@@ -638,6 +879,9 @@ var TagsInputController = class _TagsInputController extends Controller {
|
|
|
638
879
|
this.#reconcile.schedule();
|
|
639
880
|
}
|
|
640
881
|
tagsTargetDisconnected(tags) {
|
|
882
|
+
if (!this.scope.containsElement(tags) || !this.tagsTargets.includes(tags)) {
|
|
883
|
+
this.#rowInert.return(tags);
|
|
884
|
+
}
|
|
641
885
|
this.#chipRow.disconnect(tags);
|
|
642
886
|
this.#reconcile.schedule();
|
|
643
887
|
}
|
|
@@ -693,7 +937,7 @@ var TagsInputController = class _TagsInputController extends Controller {
|
|
|
693
937
|
this.#reject(value, "empty");
|
|
694
938
|
return;
|
|
695
939
|
}
|
|
696
|
-
if (this.#safeMax > 0 && this.
|
|
940
|
+
if (this.#safeMax > 0 && this.#chips.length >= this.#safeMax) {
|
|
697
941
|
this.#reject(value, "max");
|
|
698
942
|
return;
|
|
699
943
|
}
|
|
@@ -721,18 +965,38 @@ var TagsInputController = class _TagsInputController extends Controller {
|
|
|
721
965
|
return true;
|
|
722
966
|
}
|
|
723
967
|
#removeAt(index, focus = "neighbor") {
|
|
724
|
-
const tag = this
|
|
968
|
+
const tag = this.#chips[index];
|
|
725
969
|
if (!tag) return;
|
|
726
970
|
const value = tag.dataset.value ?? "";
|
|
727
971
|
tag.remove();
|
|
728
972
|
const tags = this.#values;
|
|
729
|
-
|
|
973
|
+
const afterFocus2 = focus === "neighbor" && tags.length === 0 && this.hasInputTarget;
|
|
974
|
+
if (!this.#publishTags(tags, false, value, afterFocus2)) return;
|
|
730
975
|
if (focus === "input") {
|
|
731
976
|
this.#focusInput();
|
|
732
977
|
return;
|
|
733
978
|
}
|
|
734
979
|
if (!this.#chipRow.focusAfterRemoval(index)) this.#focusInput();
|
|
735
980
|
}
|
|
981
|
+
get #chips() {
|
|
982
|
+
if (!this.hasTagsTarget) return this.tagTargets;
|
|
983
|
+
const row = this.tagsTarget;
|
|
984
|
+
const selector = this.#rows.selector("tags");
|
|
985
|
+
return this.tagTargets.filter((tag) => tag.closest(selector) === row);
|
|
986
|
+
}
|
|
987
|
+
#settleTagsRows() {
|
|
988
|
+
const [current, ...behind] = this.tagsTargets;
|
|
989
|
+
if (!current) {
|
|
990
|
+
this.#chipRow.disconnect();
|
|
991
|
+
return;
|
|
992
|
+
}
|
|
993
|
+
this.#rowInert.return(current);
|
|
994
|
+
this.#chipRow.connect(current);
|
|
995
|
+
for (const row of behind) {
|
|
996
|
+
if (row.contains(document.activeElement)) this.#focusInput();
|
|
997
|
+
this.#rowInert.write(row, "");
|
|
998
|
+
}
|
|
999
|
+
}
|
|
736
1000
|
get #chipDirectionElement() {
|
|
737
1001
|
return this.hasTagsTarget ? this.tagsTarget : this.element;
|
|
738
1002
|
}
|
|
@@ -750,7 +1014,7 @@ var TagsInputController = class _TagsInputController extends Controller {
|
|
|
750
1014
|
this.#chipRow.ensureTabStop();
|
|
751
1015
|
return fieldChanged;
|
|
752
1016
|
}
|
|
753
|
-
#publishTags(tags, added, value) {
|
|
1017
|
+
#publishTags(tags, added, value, afterFocus2 = false) {
|
|
754
1018
|
const changed = !this.#sameTags(this.#tagValues, tags);
|
|
755
1019
|
const fieldChanged = this.#syncState(tags);
|
|
756
1020
|
this.#tagValues = tags;
|
|
@@ -758,13 +1022,13 @@ var TagsInputController = class _TagsInputController extends Controller {
|
|
|
758
1022
|
const token = this.#moves.record();
|
|
759
1023
|
if (fieldChanged) commitField(this.fieldsTarget);
|
|
760
1024
|
if (!this.#moves.isLatest(token)) return false;
|
|
761
|
-
this.#announceTransition(added, value, tags.length);
|
|
1025
|
+
this.#announceTransition(added, value, tags.length, afterFocus2);
|
|
762
1026
|
if (!this.#moves.isLatest(token)) return false;
|
|
763
1027
|
this.dispatch("change", { detail: { tags } });
|
|
764
1028
|
return this.#moves.isLatest(token);
|
|
765
1029
|
}
|
|
766
1030
|
#reconcileTags() {
|
|
767
|
-
|
|
1031
|
+
this.#settleTagsRows();
|
|
768
1032
|
const tags = this.#values;
|
|
769
1033
|
this.#syncState(tags);
|
|
770
1034
|
const changed = !this.#sameTags(this.#tagValues, tags);
|
|
@@ -773,15 +1037,15 @@ var TagsInputController = class _TagsInputController extends Controller {
|
|
|
773
1037
|
this.dispatch("reconcile", { detail: { tags } });
|
|
774
1038
|
}
|
|
775
1039
|
}
|
|
776
|
-
#announceTransition(added, value, count) {
|
|
1040
|
+
#announceTransition(added, value, count, afterFocus2) {
|
|
777
1041
|
const template = added ? this.announceTextValue : this.announceRemovedTextValue;
|
|
778
|
-
announce(fillTemplate(template, { label: value, value, count }));
|
|
1042
|
+
announce(fillTemplate(template, { label: value, value, count }), { afterFocus: afterFocus2 });
|
|
779
1043
|
}
|
|
780
1044
|
#reject(value, reason) {
|
|
781
1045
|
this.dispatch("reject", { detail: { value, reason } });
|
|
782
1046
|
}
|
|
783
1047
|
get #values() {
|
|
784
|
-
return this.
|
|
1048
|
+
return this.#chips.map((tag) => tag.dataset.value ?? "");
|
|
785
1049
|
}
|
|
786
1050
|
#sameTags(left, right) {
|
|
787
1051
|
return left.length === right.length && left.every((value, index) => value === right[index]);
|