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
|
@@ -28,6 +28,7 @@ function ensureId(element, prefix = "stimeo") {
|
|
|
28
28
|
|
|
29
29
|
function setAttributeIfChanged(element, name, value, beforeWrite) {
|
|
30
30
|
if (element.getAttribute(name) === value) return false;
|
|
31
|
+
beforeWrite?.();
|
|
31
32
|
if (value === null) element.removeAttribute(name);
|
|
32
33
|
else element.setAttribute(name, value);
|
|
33
34
|
return true;
|
|
@@ -91,14 +92,34 @@ var AttributeLease = class {
|
|
|
91
92
|
const names = registry.names;
|
|
92
93
|
names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
|
|
93
94
|
}
|
|
94
|
-
write(element, value) {
|
|
95
|
+
write(element, value, beforeWrite) {
|
|
95
96
|
const stack = attributeStack(element, this.#attribute);
|
|
96
97
|
const hold = this.#take(stack) ?? this.#acquire(element, stack);
|
|
97
98
|
this.#held.add(element);
|
|
98
99
|
const shows = !this.#covered(element, stack, hold);
|
|
99
100
|
hold.written = value;
|
|
100
101
|
this.#mark(element, stack);
|
|
101
|
-
if (shows) this.#reflect(element, value);
|
|
102
|
+
if (shows) this.#reflect(element, value, beforeWrite);
|
|
103
|
+
}
|
|
104
|
+
adopt(element, options = {}) {
|
|
105
|
+
const known = registry.stacks.get(element)?.has(this.#attribute);
|
|
106
|
+
if (!this.#held.has(element) && !known && !element.hasAttribute(this.#record)) return false;
|
|
107
|
+
const stack = attributeStack(element, this.#attribute);
|
|
108
|
+
const hold = this.#take(stack);
|
|
109
|
+
if (!hold) return false;
|
|
110
|
+
const current = element.getAttribute(this.#attribute);
|
|
111
|
+
if (options.ifChanged && (current === hold.written || this.#covered(element, stack, hold))) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
this.#held.add(element);
|
|
115
|
+
hold.original = current;
|
|
116
|
+
hold.linked = false;
|
|
117
|
+
for (const above of stack.slice(stack.indexOf(hold) + 1)) {
|
|
118
|
+
if (!above.linked) break;
|
|
119
|
+
above.original = current;
|
|
120
|
+
}
|
|
121
|
+
this.#mark(element, stack);
|
|
122
|
+
return true;
|
|
102
123
|
}
|
|
103
124
|
return(element) {
|
|
104
125
|
const held = this.#held.delete(element);
|
|
@@ -164,8 +185,8 @@ var AttributeLease = class {
|
|
|
164
185
|
setAttributeIfChanged(element, name, recorded);
|
|
165
186
|
}
|
|
166
187
|
}
|
|
167
|
-
#reflect(element, value) {
|
|
168
|
-
setAttributeIfChanged(element, this.#attribute, value);
|
|
188
|
+
#reflect(element, value, beforeWrite) {
|
|
189
|
+
setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
|
|
169
190
|
}
|
|
170
191
|
};
|
|
171
192
|
|
|
@@ -182,6 +203,7 @@ var EscapeLayer = class _EscapeLayer {
|
|
|
182
203
|
);
|
|
183
204
|
#active = null;
|
|
184
205
|
activate(ownerDocument = document, options) {
|
|
206
|
+
const entry = { onDismiss: options.onDismiss, claims: options.claims ?? null };
|
|
185
207
|
this.deactivate();
|
|
186
208
|
let registry2 = _EscapeLayer.#registries.get(ownerDocument);
|
|
187
209
|
if (!registry2) {
|
|
@@ -189,7 +211,6 @@ var EscapeLayer = class _EscapeLayer {
|
|
|
189
211
|
_EscapeLayer.#registries.set(ownerDocument, registry2);
|
|
190
212
|
ownerDocument.addEventListener("keydown", registry2.onKeydown);
|
|
191
213
|
}
|
|
192
|
-
const entry = { onDismiss: options.onDismiss, claims: options.claims ?? null };
|
|
193
214
|
registry2.stack.push(entry);
|
|
194
215
|
this.#active = { document: ownerDocument, entry };
|
|
195
216
|
}
|
|
@@ -337,8 +358,8 @@ var DropdownController = class extends Controller {
|
|
|
337
358
|
};
|
|
338
359
|
#listeners = new ListenerSet();
|
|
339
360
|
connect() {
|
|
340
|
-
this.#
|
|
341
|
-
this.#
|
|
361
|
+
this.#menu = this.hasMenuTarget ? this.menuTarget : null;
|
|
362
|
+
this.#setOpen(false, "api");
|
|
342
363
|
this.#listeners.add(document, "click", this.#onOutsideClick, { capture: true });
|
|
343
364
|
this.#morphRender.observe(this.element);
|
|
344
365
|
this.#connected = true;
|
|
@@ -352,77 +373,71 @@ var DropdownController = class extends Controller {
|
|
|
352
373
|
this.#morphRender.disconnect();
|
|
353
374
|
}
|
|
354
375
|
triggerTargetConnected() {
|
|
355
|
-
|
|
376
|
+
this.#adoptMenu();
|
|
356
377
|
}
|
|
357
378
|
triggerTargetDisconnected(trigger) {
|
|
358
379
|
if (!this.triggerTargets.includes(trigger)) {
|
|
359
380
|
this.#expanded.return(trigger);
|
|
360
381
|
this.#withdrawControls(trigger);
|
|
361
382
|
}
|
|
362
|
-
|
|
383
|
+
this.#adoptMenu();
|
|
363
384
|
}
|
|
364
385
|
menuTargetConnected() {
|
|
365
|
-
this.#adoptMenu();
|
|
386
|
+
this.#adoptMenu(true);
|
|
366
387
|
}
|
|
367
388
|
menuTargetDisconnected(menu) {
|
|
368
|
-
this.#adoptMenu();
|
|
389
|
+
this.#adoptMenu(true);
|
|
369
390
|
if (!this.menuTargets.includes(menu)) this.#menuHidden.return(menu);
|
|
370
391
|
}
|
|
371
392
|
toggle(event) {
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
} else {
|
|
375
|
-
this.open(event);
|
|
376
|
-
}
|
|
393
|
+
this.#adoptMenu(true);
|
|
394
|
+
this.#setOpen(!this.#openState, stateReasonFor(event));
|
|
377
395
|
}
|
|
378
396
|
open(event) {
|
|
379
|
-
this.#
|
|
397
|
+
this.#adoptMenu(true);
|
|
398
|
+
this.#setOpen(true, stateReasonFor(event));
|
|
380
399
|
}
|
|
381
400
|
close(event) {
|
|
382
401
|
this.#close(stateReasonFor(event));
|
|
383
402
|
}
|
|
384
|
-
#open(reason) {
|
|
385
|
-
if (!this.hasMenuTarget) return;
|
|
386
|
-
const menu = this.menuTarget;
|
|
387
|
-
const was = this.#isOpen;
|
|
388
|
-
this.#escapeLayer.activate(document, {
|
|
389
|
-
onDismiss: () => this.#closeAndRestore(),
|
|
390
|
-
claims: claimsWhileFocusWithin(this.element)
|
|
391
|
-
});
|
|
392
|
-
this.#menuHidden.write(menu, null);
|
|
393
|
-
this.#menu = menu;
|
|
394
|
-
this.#openState = true;
|
|
395
|
-
if (this.hasTriggerTarget) this.#expanded.write(this.triggerTarget, "true");
|
|
396
|
-
if (!was && this.#reporting) this.dispatch("open", { detail: { reason }, cancelable: false });
|
|
397
|
-
}
|
|
398
403
|
#close(reason) {
|
|
399
|
-
|
|
400
|
-
this.#
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
404
|
+
this.#adoptMenu(true);
|
|
405
|
+
this.#setOpen(false, reason);
|
|
406
|
+
}
|
|
407
|
+
#setOpen(open, reason) {
|
|
408
|
+
const changed = open !== this.#openState;
|
|
409
|
+
this.#openState = open;
|
|
410
|
+
if (open) {
|
|
411
|
+
this.#escapeLayer.activate(document, {
|
|
412
|
+
onDismiss: () => this.#closeAndRestore(),
|
|
413
|
+
claims: claimsWhileFocusWithin(this.element)
|
|
414
|
+
});
|
|
415
|
+
} else {
|
|
416
|
+
this.#escapeLayer.deactivate();
|
|
417
|
+
}
|
|
418
|
+
if (this.#menu) this.#menuHidden.write(this.#menu, open ? null : "");
|
|
419
|
+
this.#reflectTrigger();
|
|
420
|
+
if (!changed || !this.#reporting) return;
|
|
421
|
+
if (open) this.dispatch("open", { detail: { reason }, cancelable: false });
|
|
422
|
+
else this.dispatch("close", { detail: { reason }, cancelable: false });
|
|
408
423
|
}
|
|
409
|
-
#adoptMenu() {
|
|
424
|
+
#adoptMenu(readCurrent = false) {
|
|
410
425
|
if (!this.#connected) return;
|
|
411
426
|
const menu = this.hasMenuTarget ? this.menuTarget : null;
|
|
412
427
|
const previous = this.#menu;
|
|
428
|
+
if (previous && (readCurrent || menu !== previous)) this.#openState = !previous.hidden;
|
|
429
|
+
if (!this.#openState) this.#escapeLayer.deactivate();
|
|
413
430
|
this.#menu = menu;
|
|
414
|
-
if (
|
|
415
|
-
this.#escapeLayer.deactivate();
|
|
416
|
-
this.#openState = false;
|
|
417
|
-
} else if (menu !== previous) {
|
|
418
|
-
this.#menuHidden.write(menu, previous?.hidden ?? true ? "" : null);
|
|
419
|
-
}
|
|
431
|
+
if (menu && menu !== previous) this.#menuHidden.write(menu, this.#openState ? null : "");
|
|
420
432
|
this.#reflectTrigger();
|
|
421
433
|
}
|
|
422
434
|
#reflectTrigger() {
|
|
423
435
|
if (!this.hasTriggerTarget) return;
|
|
424
|
-
this
|
|
425
|
-
this.#
|
|
436
|
+
const trigger = this.triggerTarget;
|
|
437
|
+
const expanded = this.#menu ? !this.#menu.hidden : this.#openState;
|
|
438
|
+
this.#expanded.write(trigger, String(expanded));
|
|
439
|
+
if (this.hasMenuTarget) this.#associateTriggerWithMenu();
|
|
440
|
+
else this.#withdrawControls(trigger);
|
|
426
441
|
}
|
|
427
442
|
#repair() {
|
|
428
443
|
if (!this.hasMenuTarget) return;
|
|
@@ -433,9 +448,6 @@ var DropdownController = class extends Controller {
|
|
|
433
448
|
this.#close("escape");
|
|
434
449
|
if (this.hasTriggerTarget) this.triggerTarget.focus();
|
|
435
450
|
}
|
|
436
|
-
get #isOpen() {
|
|
437
|
-
return this.hasMenuTarget && !this.menuTarget.hidden;
|
|
438
|
-
}
|
|
439
451
|
#associateTriggerWithMenu() {
|
|
440
452
|
if (!this.hasTriggerTarget || !this.hasMenuTarget) return;
|
|
441
453
|
const trigger = this.triggerTarget;
|
|
@@ -2,6 +2,7 @@ import { Controller } from '@hotwired/stimulus';
|
|
|
2
2
|
|
|
3
3
|
function setAttributeIfChanged(element, name, value, beforeWrite) {
|
|
4
4
|
if (element.getAttribute(name) === value) return false;
|
|
5
|
+
beforeWrite?.();
|
|
5
6
|
if (value === null) element.removeAttribute(name);
|
|
6
7
|
else element.setAttribute(name, value);
|
|
7
8
|
return true;
|
|
@@ -75,14 +76,34 @@ var AttributeLease = class {
|
|
|
75
76
|
const names = registry.names;
|
|
76
77
|
names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
|
|
77
78
|
}
|
|
78
|
-
write(element, value) {
|
|
79
|
+
write(element, value, beforeWrite) {
|
|
79
80
|
const stack = attributeStack(element, this.#attribute);
|
|
80
81
|
const hold = this.#take(stack) ?? this.#acquire(element, stack);
|
|
81
82
|
this.#held.add(element);
|
|
82
83
|
const shows = !this.#covered(element, stack, hold);
|
|
83
84
|
hold.written = value;
|
|
84
85
|
this.#mark(element, stack);
|
|
85
|
-
if (shows) this.#reflect(element, value);
|
|
86
|
+
if (shows) this.#reflect(element, value, beforeWrite);
|
|
87
|
+
}
|
|
88
|
+
adopt(element, options = {}) {
|
|
89
|
+
const known = registry.stacks.get(element)?.has(this.#attribute);
|
|
90
|
+
if (!this.#held.has(element) && !known && !element.hasAttribute(this.#record)) return false;
|
|
91
|
+
const stack = attributeStack(element, this.#attribute);
|
|
92
|
+
const hold = this.#take(stack);
|
|
93
|
+
if (!hold) return false;
|
|
94
|
+
const current = element.getAttribute(this.#attribute);
|
|
95
|
+
if (options.ifChanged && (current === hold.written || this.#covered(element, stack, hold))) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
this.#held.add(element);
|
|
99
|
+
hold.original = current;
|
|
100
|
+
hold.linked = false;
|
|
101
|
+
for (const above of stack.slice(stack.indexOf(hold) + 1)) {
|
|
102
|
+
if (!above.linked) break;
|
|
103
|
+
above.original = current;
|
|
104
|
+
}
|
|
105
|
+
this.#mark(element, stack);
|
|
106
|
+
return true;
|
|
86
107
|
}
|
|
87
108
|
return(element) {
|
|
88
109
|
const held = this.#held.delete(element);
|
|
@@ -148,8 +169,8 @@ var AttributeLease = class {
|
|
|
148
169
|
setAttributeIfChanged(element, name, recorded);
|
|
149
170
|
}
|
|
150
171
|
}
|
|
151
|
-
#reflect(element, value) {
|
|
152
|
-
setAttributeIfChanged(element, this.#attribute, value);
|
|
172
|
+
#reflect(element, value, beforeWrite) {
|
|
173
|
+
setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
|
|
153
174
|
}
|
|
154
175
|
};
|
|
155
176
|
|
|
@@ -163,7 +184,50 @@ function isCompositionInputType(inputType) {
|
|
|
163
184
|
return inputType !== void 0 && COMPOSITION_INPUT_TYPES.has(inputType);
|
|
164
185
|
}
|
|
165
186
|
var BEFORE_MORPH_ATTRIBUTE = "turbo:before-morph-attribute";
|
|
166
|
-
var textOf = (element) =>
|
|
187
|
+
var textOf = (element) => {
|
|
188
|
+
if ("value" in element) return element.value;
|
|
189
|
+
return element instanceof Element ? element.textContent : void 0;
|
|
190
|
+
};
|
|
191
|
+
var nodesOf = (element) => {
|
|
192
|
+
const nodes = [];
|
|
193
|
+
if ("value" in element || !(element instanceof Element)) return nodes;
|
|
194
|
+
const walker = element.ownerDocument.createTreeWalker(element);
|
|
195
|
+
for (let node = walker.nextNode(); node !== null; node = walker.nextNode()) nodes.push(node);
|
|
196
|
+
return nodes;
|
|
197
|
+
};
|
|
198
|
+
var folded = (text) => text.replaceAll("\xA0", " ");
|
|
199
|
+
var startOf = (node, data, replaced, caret) => {
|
|
200
|
+
const text = folded(node.data);
|
|
201
|
+
const composed = folded(data);
|
|
202
|
+
if (replaced?.startContainer === node && text.startsWith(composed, replaced.startOffset)) {
|
|
203
|
+
return replaced.startOffset;
|
|
204
|
+
}
|
|
205
|
+
const start = text.lastIndexOf(composed, caret);
|
|
206
|
+
return start !== -1 && start + composed.length >= caret ? start : -1;
|
|
207
|
+
};
|
|
208
|
+
var spotOf = (element, replaced, data) => {
|
|
209
|
+
if ("value" in element || !(element instanceof Element)) return null;
|
|
210
|
+
const selection = element.ownerDocument.getSelection();
|
|
211
|
+
const node = selection?.focusNode;
|
|
212
|
+
if (!(node instanceof Text) || node.data === "" || !element.contains(node)) return null;
|
|
213
|
+
const range = element.ownerDocument.createRange();
|
|
214
|
+
const start = typeof data === "string" && data !== "" ? startOf(node, data, replaced, selection?.focusOffset ?? 0) : -1;
|
|
215
|
+
if (start === -1) {
|
|
216
|
+
range.selectNodeContents(node);
|
|
217
|
+
} else {
|
|
218
|
+
range.setStart(node, start);
|
|
219
|
+
range.setEnd(node, start + data.length);
|
|
220
|
+
}
|
|
221
|
+
return range;
|
|
222
|
+
};
|
|
223
|
+
var replacedBy = (event) => typeof event.getTargetRanges === "function" ? event.getTargetRanges()[0] ?? null : null;
|
|
224
|
+
var rewritten = ({ element, text, nodes, spot }) => {
|
|
225
|
+
if (spot !== null) {
|
|
226
|
+
return spot.collapsed || !(element instanceof Node && element.contains(spot.startContainer));
|
|
227
|
+
}
|
|
228
|
+
const current = nodesOf(element);
|
|
229
|
+
return textOf(element) !== text || current.length !== nodes.length || current.some((node, index) => node !== nodes[index]);
|
|
230
|
+
};
|
|
167
231
|
var holdsFocus = (element) => element instanceof Node && element.getRootNode().activeElement === element;
|
|
168
232
|
var CompositionTracker = class {
|
|
169
233
|
#observedTargets = /* @__PURE__ */ new Set();
|
|
@@ -224,7 +288,7 @@ var CompositionTracker = class {
|
|
|
224
288
|
this.#confirmedTarget = null;
|
|
225
289
|
if (confirmed === null || confirmed !== event.target) return false;
|
|
226
290
|
const inputType = event.inputType;
|
|
227
|
-
return
|
|
291
|
+
return inputType ? isCompositionInputType(inputType) : event.isTrusted === true;
|
|
228
292
|
}
|
|
229
293
|
#release(target) {
|
|
230
294
|
target.removeEventListener("compositionstart", this.#handleStart);
|
|
@@ -254,11 +318,11 @@ var CompositionTracker = class {
|
|
|
254
318
|
}
|
|
255
319
|
#settle() {
|
|
256
320
|
const composition = this.#composition;
|
|
257
|
-
if (composition === null) return;
|
|
258
|
-
const { target, element
|
|
321
|
+
if (composition === null || !this.#observedTargets.has(composition.target)) return;
|
|
322
|
+
const { target, element } = composition;
|
|
259
323
|
if (target instanceof Node && element instanceof Node && !target.contains(element)) {
|
|
260
324
|
this.#composition = null;
|
|
261
|
-
} else if (
|
|
325
|
+
} else if (rewritten(composition)) {
|
|
262
326
|
this.#abandon(false);
|
|
263
327
|
}
|
|
264
328
|
}
|
|
@@ -283,7 +347,14 @@ var CompositionTracker = class {
|
|
|
283
347
|
this.#owe(true);
|
|
284
348
|
const target = event.currentTarget;
|
|
285
349
|
const element = event.target;
|
|
286
|
-
this.#composition = {
|
|
350
|
+
this.#composition = {
|
|
351
|
+
target,
|
|
352
|
+
element,
|
|
353
|
+
text: textOf(element),
|
|
354
|
+
nodes: nodesOf(element),
|
|
355
|
+
spot: spotOf(element, null, void 0),
|
|
356
|
+
replaced: null
|
|
357
|
+
};
|
|
287
358
|
this.#runAbandon();
|
|
288
359
|
this.#onStart?.(event);
|
|
289
360
|
};
|
|
@@ -307,6 +378,10 @@ var CompositionTracker = class {
|
|
|
307
378
|
if (this.#composition !== null && !keyComposing && !isComposing && inputType && !isCompositionInputType(inputType)) {
|
|
308
379
|
this.#abandon(true);
|
|
309
380
|
}
|
|
381
|
+
const composition = this.#composition;
|
|
382
|
+
if (composition !== null && event.target === composition.element) {
|
|
383
|
+
composition.replaced = replacedBy(event);
|
|
384
|
+
}
|
|
310
385
|
this.#runAbandon();
|
|
311
386
|
};
|
|
312
387
|
#handleInput = (event) => {
|
|
@@ -314,6 +389,15 @@ var CompositionTracker = class {
|
|
|
314
389
|
const { isTrusted, isComposing, inputType } = event;
|
|
315
390
|
if (composition !== null && event.target === composition.element && (isTrusted || isComposing || isCompositionInputType(inputType))) {
|
|
316
391
|
composition.text = textOf(composition.element);
|
|
392
|
+
composition.nodes = nodesOf(composition.element);
|
|
393
|
+
if (isCompositionInputType(inputType)) {
|
|
394
|
+
composition.spot = spotOf(
|
|
395
|
+
composition.element,
|
|
396
|
+
composition.replaced,
|
|
397
|
+
event.data
|
|
398
|
+
);
|
|
399
|
+
}
|
|
400
|
+
composition.replaced = null;
|
|
317
401
|
} else {
|
|
318
402
|
this.#settle();
|
|
319
403
|
}
|
|
@@ -334,7 +418,9 @@ var CompositionTracker = class {
|
|
|
334
418
|
const composition = this.#composition;
|
|
335
419
|
if (composition?.target !== event.currentTarget || event.target !== composition.element) return;
|
|
336
420
|
const detail = event.detail;
|
|
337
|
-
if (detail?.attributeName === "value"
|
|
421
|
+
if (detail?.attributeName === "value" && "value" in composition.element) {
|
|
422
|
+
event.preventDefault();
|
|
423
|
+
}
|
|
338
424
|
};
|
|
339
425
|
};
|
|
340
426
|
|
|
@@ -361,14 +447,49 @@ var EditableController = class extends Controller {
|
|
|
361
447
|
#composition = new CompositionTracker();
|
|
362
448
|
#hidden = new AttributeLease("hidden", this.identifier);
|
|
363
449
|
#connected = false;
|
|
450
|
+
#editorPress = null;
|
|
451
|
+
#deferredBlur = false;
|
|
364
452
|
#onFocusOut = (event) => {
|
|
365
453
|
const from = event.target;
|
|
366
454
|
if (this.hasDisplayTarget && from instanceof Node && this.displayTarget.contains(from)) return;
|
|
367
455
|
const next = event.relatedTarget;
|
|
368
456
|
if (next instanceof Node && this.element.contains(next)) return;
|
|
369
|
-
if (this.submitOnBlurValue)
|
|
457
|
+
if (!this.submitOnBlurValue) return;
|
|
458
|
+
if (next === null && this.#editorPress !== null) {
|
|
459
|
+
this.#deferredBlur = true;
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
this.#commit(false);
|
|
370
463
|
};
|
|
371
464
|
#listeners = new ListenerSet();
|
|
465
|
+
#editListeners = new ListenerSet();
|
|
466
|
+
#onPointerDown = (event) => {
|
|
467
|
+
if (event.pointerType !== "mouse" || !event.isPrimary || event.button !== 0) return;
|
|
468
|
+
const inside = event.composedPath().includes(this.element);
|
|
469
|
+
this.#editorPress = inside ? event.pointerId : null;
|
|
470
|
+
if (!inside) this.#commitDeferredBlur();
|
|
471
|
+
};
|
|
472
|
+
#onPointerEnd = (event) => {
|
|
473
|
+
if (event.pointerId !== this.#editorPress) return;
|
|
474
|
+
this.#editorPress = null;
|
|
475
|
+
if (event.type === "pointerup" && !event.composedPath().includes(this.element)) {
|
|
476
|
+
this.#commitDeferredBlur();
|
|
477
|
+
}
|
|
478
|
+
};
|
|
479
|
+
#onFocusIn = (event) => {
|
|
480
|
+
if (event.composedPath().includes(this.element)) this.#deferredBlur = false;
|
|
481
|
+
else this.#commitDeferredBlur();
|
|
482
|
+
};
|
|
483
|
+
#commitDeferredBlur() {
|
|
484
|
+
if (!this.#deferredBlur) return;
|
|
485
|
+
this.#deferredBlur = false;
|
|
486
|
+
if (this.submitOnBlurValue) this.#commit(false);
|
|
487
|
+
}
|
|
488
|
+
#clearEditListeners() {
|
|
489
|
+
this.#editListeners.dispose();
|
|
490
|
+
this.#editorPress = null;
|
|
491
|
+
this.#deferredBlur = false;
|
|
492
|
+
}
|
|
372
493
|
connect() {
|
|
373
494
|
this.#connected = true;
|
|
374
495
|
if (this.hasInputTarget) this.#composition.observe(this.inputTarget);
|
|
@@ -380,6 +501,7 @@ var EditableController = class extends Controller {
|
|
|
380
501
|
this.#connected = false;
|
|
381
502
|
this.#composition.disconnect();
|
|
382
503
|
this.#listeners.dispose();
|
|
504
|
+
this.#clearEditListeners();
|
|
383
505
|
}
|
|
384
506
|
inputTargetConnected(input) {
|
|
385
507
|
this.#composition.observe(input);
|
|
@@ -401,6 +523,11 @@ var EditableController = class extends Controller {
|
|
|
401
523
|
if (this.#isEditing || !this.hasInputTarget || !this.hasDisplayTarget) return;
|
|
402
524
|
this.#previousValue = this.#currentValue;
|
|
403
525
|
this.inputTarget.value = this.#previousValue;
|
|
526
|
+
const document = this.element.ownerDocument;
|
|
527
|
+
this.#editListeners.add(document, "pointerdown", this.#onPointerDown, { capture: true });
|
|
528
|
+
this.#editListeners.add(document, "pointerup", this.#onPointerEnd, { capture: true });
|
|
529
|
+
this.#editListeners.add(document, "pointercancel", this.#onPointerEnd, { capture: true });
|
|
530
|
+
this.#editListeners.add(document, "focusin", this.#onFocusIn, { capture: true });
|
|
404
531
|
this.#setMode("editing");
|
|
405
532
|
this.inputTarget.focus();
|
|
406
533
|
this.inputTarget.select();
|
|
@@ -465,6 +592,7 @@ var EditableController = class extends Controller {
|
|
|
465
592
|
if (this.hasInputTarget) this.#hidden.write(this.inputTarget, editing ? null : "");
|
|
466
593
|
}
|
|
467
594
|
#setMode(mode) {
|
|
595
|
+
if (mode === "display") this.#clearEditListeners();
|
|
468
596
|
this.element.dataset.mode = mode;
|
|
469
597
|
this.#applyMode();
|
|
470
598
|
}
|