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
|
@@ -10,6 +10,7 @@ function hasModifierChord(event) {
|
|
|
10
10
|
|
|
11
11
|
function setAttributeIfChanged(element, name, value, beforeWrite) {
|
|
12
12
|
if (element.getAttribute(name) === value) return false;
|
|
13
|
+
beforeWrite?.();
|
|
13
14
|
if (value === null) element.removeAttribute(name);
|
|
14
15
|
else element.setAttribute(name, value);
|
|
15
16
|
return true;
|
|
@@ -83,14 +84,34 @@ var AttributeLease = class {
|
|
|
83
84
|
const names = registry.names;
|
|
84
85
|
names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
|
|
85
86
|
}
|
|
86
|
-
write(element, value) {
|
|
87
|
+
write(element, value, beforeWrite) {
|
|
87
88
|
const stack = attributeStack(element, this.#attribute);
|
|
88
89
|
const hold = this.#take(stack) ?? this.#acquire(element, stack);
|
|
89
90
|
this.#held.add(element);
|
|
90
91
|
const shows = !this.#covered(element, stack, hold);
|
|
91
92
|
hold.written = value;
|
|
92
93
|
this.#mark(element, stack);
|
|
93
|
-
if (shows) this.#reflect(element, value);
|
|
94
|
+
if (shows) this.#reflect(element, value, beforeWrite);
|
|
95
|
+
}
|
|
96
|
+
adopt(element, options = {}) {
|
|
97
|
+
const known = registry.stacks.get(element)?.has(this.#attribute);
|
|
98
|
+
if (!this.#held.has(element) && !known && !element.hasAttribute(this.#record)) return false;
|
|
99
|
+
const stack = attributeStack(element, this.#attribute);
|
|
100
|
+
const hold = this.#take(stack);
|
|
101
|
+
if (!hold) return false;
|
|
102
|
+
const current = element.getAttribute(this.#attribute);
|
|
103
|
+
if (options.ifChanged && (current === hold.written || this.#covered(element, stack, hold))) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
this.#held.add(element);
|
|
107
|
+
hold.original = current;
|
|
108
|
+
hold.linked = false;
|
|
109
|
+
for (const above of stack.slice(stack.indexOf(hold) + 1)) {
|
|
110
|
+
if (!above.linked) break;
|
|
111
|
+
above.original = current;
|
|
112
|
+
}
|
|
113
|
+
this.#mark(element, stack);
|
|
114
|
+
return true;
|
|
94
115
|
}
|
|
95
116
|
return(element) {
|
|
96
117
|
const held = this.#held.delete(element);
|
|
@@ -156,8 +177,8 @@ var AttributeLease = class {
|
|
|
156
177
|
setAttributeIfChanged(element, name, recorded);
|
|
157
178
|
}
|
|
158
179
|
}
|
|
159
|
-
#reflect(element, value) {
|
|
160
|
-
setAttributeIfChanged(element, this.#attribute, value);
|
|
180
|
+
#reflect(element, value, beforeWrite) {
|
|
181
|
+
setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
|
|
161
182
|
}
|
|
162
183
|
};
|
|
163
184
|
|
|
@@ -214,7 +235,50 @@ function isCompositionInputType(inputType) {
|
|
|
214
235
|
return inputType !== void 0 && COMPOSITION_INPUT_TYPES.has(inputType);
|
|
215
236
|
}
|
|
216
237
|
var BEFORE_MORPH_ATTRIBUTE = "turbo:before-morph-attribute";
|
|
217
|
-
var textOf = (element) =>
|
|
238
|
+
var textOf = (element) => {
|
|
239
|
+
if ("value" in element) return element.value;
|
|
240
|
+
return element instanceof Element ? element.textContent : void 0;
|
|
241
|
+
};
|
|
242
|
+
var nodesOf = (element) => {
|
|
243
|
+
const nodes = [];
|
|
244
|
+
if ("value" in element || !(element instanceof Element)) return nodes;
|
|
245
|
+
const walker = element.ownerDocument.createTreeWalker(element);
|
|
246
|
+
for (let node = walker.nextNode(); node !== null; node = walker.nextNode()) nodes.push(node);
|
|
247
|
+
return nodes;
|
|
248
|
+
};
|
|
249
|
+
var folded = (text) => text.replaceAll("\xA0", " ");
|
|
250
|
+
var startOf = (node, data, replaced, caret) => {
|
|
251
|
+
const text = folded(node.data);
|
|
252
|
+
const composed = folded(data);
|
|
253
|
+
if (replaced?.startContainer === node && text.startsWith(composed, replaced.startOffset)) {
|
|
254
|
+
return replaced.startOffset;
|
|
255
|
+
}
|
|
256
|
+
const start = text.lastIndexOf(composed, caret);
|
|
257
|
+
return start !== -1 && start + composed.length >= caret ? start : -1;
|
|
258
|
+
};
|
|
259
|
+
var spotOf = (element, replaced, data) => {
|
|
260
|
+
if ("value" in element || !(element instanceof Element)) return null;
|
|
261
|
+
const selection = element.ownerDocument.getSelection();
|
|
262
|
+
const node = selection?.focusNode;
|
|
263
|
+
if (!(node instanceof Text) || node.data === "" || !element.contains(node)) return null;
|
|
264
|
+
const range = element.ownerDocument.createRange();
|
|
265
|
+
const start = typeof data === "string" && data !== "" ? startOf(node, data, replaced, selection?.focusOffset ?? 0) : -1;
|
|
266
|
+
if (start === -1) {
|
|
267
|
+
range.selectNodeContents(node);
|
|
268
|
+
} else {
|
|
269
|
+
range.setStart(node, start);
|
|
270
|
+
range.setEnd(node, start + data.length);
|
|
271
|
+
}
|
|
272
|
+
return range;
|
|
273
|
+
};
|
|
274
|
+
var replacedBy = (event) => typeof event.getTargetRanges === "function" ? event.getTargetRanges()[0] ?? null : null;
|
|
275
|
+
var rewritten = ({ element, text, nodes, spot }) => {
|
|
276
|
+
if (spot !== null) {
|
|
277
|
+
return spot.collapsed || !(element instanceof Node && element.contains(spot.startContainer));
|
|
278
|
+
}
|
|
279
|
+
const current = nodesOf(element);
|
|
280
|
+
return textOf(element) !== text || current.length !== nodes.length || current.some((node, index) => node !== nodes[index]);
|
|
281
|
+
};
|
|
218
282
|
var holdsFocus = (element) => element instanceof Node && element.getRootNode().activeElement === element;
|
|
219
283
|
var CompositionTracker = class {
|
|
220
284
|
#observedTargets = /* @__PURE__ */ new Set();
|
|
@@ -275,7 +339,7 @@ var CompositionTracker = class {
|
|
|
275
339
|
this.#confirmedTarget = null;
|
|
276
340
|
if (confirmed === null || confirmed !== event.target) return false;
|
|
277
341
|
const inputType = event.inputType;
|
|
278
|
-
return
|
|
342
|
+
return inputType ? isCompositionInputType(inputType) : event.isTrusted === true;
|
|
279
343
|
}
|
|
280
344
|
#release(target) {
|
|
281
345
|
target.removeEventListener("compositionstart", this.#handleStart);
|
|
@@ -305,11 +369,11 @@ var CompositionTracker = class {
|
|
|
305
369
|
}
|
|
306
370
|
#settle() {
|
|
307
371
|
const composition = this.#composition;
|
|
308
|
-
if (composition === null) return;
|
|
309
|
-
const { target, element
|
|
372
|
+
if (composition === null || !this.#observedTargets.has(composition.target)) return;
|
|
373
|
+
const { target, element } = composition;
|
|
310
374
|
if (target instanceof Node && element instanceof Node && !target.contains(element)) {
|
|
311
375
|
this.#composition = null;
|
|
312
|
-
} else if (
|
|
376
|
+
} else if (rewritten(composition)) {
|
|
313
377
|
this.#abandon(false);
|
|
314
378
|
}
|
|
315
379
|
}
|
|
@@ -334,7 +398,14 @@ var CompositionTracker = class {
|
|
|
334
398
|
this.#owe(true);
|
|
335
399
|
const target = event.currentTarget;
|
|
336
400
|
const element = event.target;
|
|
337
|
-
this.#composition = {
|
|
401
|
+
this.#composition = {
|
|
402
|
+
target,
|
|
403
|
+
element,
|
|
404
|
+
text: textOf(element),
|
|
405
|
+
nodes: nodesOf(element),
|
|
406
|
+
spot: spotOf(element, null, void 0),
|
|
407
|
+
replaced: null
|
|
408
|
+
};
|
|
338
409
|
this.#runAbandon();
|
|
339
410
|
this.#onStart?.(event);
|
|
340
411
|
};
|
|
@@ -358,6 +429,10 @@ var CompositionTracker = class {
|
|
|
358
429
|
if (this.#composition !== null && !keyComposing && !isComposing && inputType && !isCompositionInputType(inputType)) {
|
|
359
430
|
this.#abandon(true);
|
|
360
431
|
}
|
|
432
|
+
const composition = this.#composition;
|
|
433
|
+
if (composition !== null && event.target === composition.element) {
|
|
434
|
+
composition.replaced = replacedBy(event);
|
|
435
|
+
}
|
|
361
436
|
this.#runAbandon();
|
|
362
437
|
};
|
|
363
438
|
#handleInput = (event) => {
|
|
@@ -365,6 +440,15 @@ var CompositionTracker = class {
|
|
|
365
440
|
const { isTrusted, isComposing, inputType } = event;
|
|
366
441
|
if (composition !== null && event.target === composition.element && (isTrusted || isComposing || isCompositionInputType(inputType))) {
|
|
367
442
|
composition.text = textOf(composition.element);
|
|
443
|
+
composition.nodes = nodesOf(composition.element);
|
|
444
|
+
if (isCompositionInputType(inputType)) {
|
|
445
|
+
composition.spot = spotOf(
|
|
446
|
+
composition.element,
|
|
447
|
+
composition.replaced,
|
|
448
|
+
event.data
|
|
449
|
+
);
|
|
450
|
+
}
|
|
451
|
+
composition.replaced = null;
|
|
368
452
|
} else {
|
|
369
453
|
this.#settle();
|
|
370
454
|
}
|
|
@@ -385,7 +469,9 @@ var CompositionTracker = class {
|
|
|
385
469
|
const composition = this.#composition;
|
|
386
470
|
if (composition?.target !== event.currentTarget || event.target !== composition.element) return;
|
|
387
471
|
const detail = event.detail;
|
|
388
|
-
if (detail?.attributeName === "value"
|
|
472
|
+
if (detail?.attributeName === "value" && "value" in composition.element) {
|
|
473
|
+
event.preventDefault();
|
|
474
|
+
}
|
|
389
475
|
};
|
|
390
476
|
};
|
|
391
477
|
|
|
@@ -588,25 +674,22 @@ function snapSteppedValue(raw, range) {
|
|
|
588
674
|
if (!(range.min <= range.max)) return finiteFallback(range.min, range.max);
|
|
589
675
|
const input = Number.isNaN(raw) ? finiteFallback(range.min, range.max) : raw;
|
|
590
676
|
const clamped = Math.min(range.max, Math.max(range.min, input));
|
|
591
|
-
const
|
|
592
|
-
const base = stepBase(range);
|
|
677
|
+
const grid = stepGrid(range);
|
|
593
678
|
const candidates = [];
|
|
594
679
|
if (Number.isFinite(range.min)) candidates.push(range.min);
|
|
595
680
|
if (Number.isFinite(range.max)) candidates.push(range.max);
|
|
596
|
-
const
|
|
597
|
-
if (Number.isFinite(
|
|
598
|
-
|
|
599
|
-
|
|
681
|
+
const position = gridPosition(clamped, grid);
|
|
682
|
+
if (Number.isFinite(position)) {
|
|
683
|
+
for (const index of [Math.floor(position), Math.ceil(position)]) {
|
|
684
|
+
const candidate = gridValue(index, grid);
|
|
685
|
+
if (inRange(candidate, range)) candidates.push(candidate);
|
|
686
|
+
}
|
|
600
687
|
}
|
|
601
688
|
if (candidates.length === 0) return clamped;
|
|
602
689
|
let nearest = candidates[0];
|
|
603
|
-
let nearestDistance = Math.abs(clamped - nearest);
|
|
604
690
|
for (const candidate of candidates.slice(1)) {
|
|
605
|
-
const
|
|
606
|
-
if (
|
|
607
|
-
nearest = candidate;
|
|
608
|
-
nearestDistance = distance;
|
|
609
|
-
}
|
|
691
|
+
const nearer = isMidpoint(clamped, candidate, nearest, range, grid) ? candidate > nearest : Math.abs(clamped - candidate) < Math.abs(clamped - nearest);
|
|
692
|
+
if (nearer) nearest = candidate;
|
|
610
693
|
}
|
|
611
694
|
return nearest;
|
|
612
695
|
}
|
|
@@ -615,46 +698,36 @@ function stepSteppedValue(current, count, range) {
|
|
|
615
698
|
const distance = Math.abs(Math.trunc(count));
|
|
616
699
|
if (!Number.isFinite(distance) || distance === 0) return value;
|
|
617
700
|
const direction = Math.sign(count);
|
|
618
|
-
const adjacent =
|
|
701
|
+
const adjacent = nextGridValue(value, direction, range);
|
|
702
|
+
if (adjacent === value) return value;
|
|
619
703
|
const raw = adjacent + direction * (distance - 1) * effectiveStep(range.step);
|
|
620
|
-
|
|
704
|
+
const endpoint = direction > 0 ? range.max : range.min;
|
|
705
|
+
return Number.isFinite(raw) || Number.isFinite(endpoint) ? snapSteppedValue(raw, range) : value;
|
|
706
|
+
}
|
|
707
|
+
function nextGridValue(current, direction, range) {
|
|
708
|
+
const grid = stepGrid(range);
|
|
709
|
+
const position = gridPosition(current, grid);
|
|
710
|
+
if (!Number.isFinite(position)) return current;
|
|
711
|
+
const index = direction > 0 ? Math.floor(position) + 1 : Math.ceil(position) - 1;
|
|
712
|
+
const first = gridValue(index, grid);
|
|
713
|
+
if (direction * (first - current) > 0 && !sameGridValue(first, current, grid.step)) {
|
|
714
|
+
return first;
|
|
715
|
+
}
|
|
716
|
+
const second = gridValue(index + direction, grid);
|
|
717
|
+
return direction * (second - current) > 0 ? second : current;
|
|
621
718
|
}
|
|
622
|
-
function
|
|
719
|
+
function stepGrid(range) {
|
|
623
720
|
const step = effectiveStep(range.step);
|
|
624
721
|
const base = stepBase(range);
|
|
625
|
-
const
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
if (candidate < current || nearlyEqual(candidate, current)) {
|
|
632
|
-
gridIndex += 1;
|
|
633
|
-
candidate = cleanGridValue(base + gridIndex * step, base, step);
|
|
634
|
-
}
|
|
635
|
-
if (candidate > current && !nearlyEqual(candidate, current) && within(candidate, range.min, range.max)) {
|
|
636
|
-
candidates.push(clamp(candidate, range));
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
return clamp(Math.min(...candidates), range);
|
|
640
|
-
}
|
|
641
|
-
const position = (current - base) / step;
|
|
642
|
-
if (Number.isFinite(position)) {
|
|
643
|
-
let gridIndex = Math.ceil(position) - 1;
|
|
644
|
-
let candidate = cleanGridValue(base + gridIndex * step, base, step);
|
|
645
|
-
if (candidate > current || nearlyEqual(candidate, current)) {
|
|
646
|
-
gridIndex -= 1;
|
|
647
|
-
candidate = cleanGridValue(base + gridIndex * step, base, step);
|
|
648
|
-
}
|
|
649
|
-
if (candidate < current && !nearlyEqual(candidate, current) && within(candidate, range.min, range.max)) {
|
|
650
|
-
candidates.push(clamp(candidate, range));
|
|
651
|
-
}
|
|
652
|
-
}
|
|
653
|
-
return clamp(Math.max(...candidates), range);
|
|
722
|
+
const near = base - Math.trunc(base / step) * step;
|
|
723
|
+
const origin = cleanGridValue(Number.isFinite(near) ? near % step : base % step, base, step);
|
|
724
|
+
return { step, base, origin };
|
|
725
|
+
}
|
|
726
|
+
function gridPosition(value, grid) {
|
|
727
|
+
return value / grid.step - grid.origin / grid.step;
|
|
654
728
|
}
|
|
655
|
-
function
|
|
656
|
-
|
|
657
|
-
if (within(candidate, range.min, range.max)) candidates.push(clamp(candidate, range));
|
|
729
|
+
function gridValue(index, grid) {
|
|
730
|
+
return cleanGridValue(grid.origin + index * grid.step, grid.base, grid.step);
|
|
658
731
|
}
|
|
659
732
|
function stepBase(range) {
|
|
660
733
|
if (range.base !== void 0 && Number.isFinite(range.base)) return range.base;
|
|
@@ -670,15 +743,46 @@ function decimalPlaces(value) {
|
|
|
670
743
|
const exponent = exponentText === void 0 ? 0 : Number(exponentText);
|
|
671
744
|
return Math.max(0, fractionLength - exponent);
|
|
672
745
|
}
|
|
673
|
-
function
|
|
674
|
-
return (value
|
|
746
|
+
function inRange(value, range) {
|
|
747
|
+
return Number.isFinite(value) && value >= range.min && value <= range.max;
|
|
748
|
+
}
|
|
749
|
+
function sameGridValue(left, right, step) {
|
|
750
|
+
const rounding = Number.EPSILON * Math.max(Math.abs(left), Math.abs(right));
|
|
751
|
+
return Math.abs(left - right) <= Math.min(rounding, step / 4);
|
|
752
|
+
}
|
|
753
|
+
function isMidpoint(value, left, right, range, grid) {
|
|
754
|
+
const imbalance = Math.abs(Math.abs(value - left) - Math.abs(value - right));
|
|
755
|
+
const rounding = 4 * Number.EPSILON * Math.max(Math.abs(value), Math.abs(left), Math.abs(right));
|
|
756
|
+
if (!(imbalance <= rounding)) return false;
|
|
757
|
+
if (imbalance <= Math.abs(left - right) / 4) return true;
|
|
758
|
+
const lower = Math.min(left, right);
|
|
759
|
+
const upper = Math.max(left, right);
|
|
760
|
+
return value > lower && value < upper && isDecimalMidpoint(value, lower, upper, range, grid);
|
|
675
761
|
}
|
|
676
|
-
function
|
|
677
|
-
|
|
762
|
+
function isDecimalMidpoint(value, lower, upper, range, grid) {
|
|
763
|
+
const raw = decimalParts(value);
|
|
764
|
+
const base = decimalParts(grid.base);
|
|
765
|
+
const step = decimalParts(grid.step);
|
|
766
|
+
const min = decimalParts(lower);
|
|
767
|
+
const max = decimalParts(upper);
|
|
768
|
+
const place = Math.min(raw.place, base.place, step.place, min.place, max.place);
|
|
769
|
+
const units = (part) => part.units * 10n ** BigInt(part.place - place);
|
|
770
|
+
const origin = units(base);
|
|
771
|
+
const stride = units(step);
|
|
772
|
+
const rawUnits = units(raw);
|
|
773
|
+
const remainder = (rawUnits - origin) % stride;
|
|
774
|
+
const below = rawUnits - (remainder < 0n ? remainder + stride : remainder);
|
|
775
|
+
const above = below + stride;
|
|
776
|
+
const minUnits = units(min);
|
|
777
|
+
const maxUnits = units(max);
|
|
778
|
+
const lowerUnits = lower === range.min && minUnits > below ? minUnits : below;
|
|
779
|
+
const upperUnits = upper === range.max && maxUnits < above ? maxUnits : above;
|
|
780
|
+
return Number(`${lowerUnits}e${place}`) === lower && Number(`${upperUnits}e${place}`) === upper && Number(`${(lowerUnits + upperUnits) * 5n}e${place - 1}`) === value;
|
|
678
781
|
}
|
|
679
|
-
function
|
|
680
|
-
const
|
|
681
|
-
|
|
782
|
+
function decimalParts(value) {
|
|
783
|
+
const [coefficient = "", exponent = "0"] = value.toString().split("e");
|
|
784
|
+
const [whole = "", fraction = ""] = coefficient.split(".");
|
|
785
|
+
return { units: BigInt(whole + fraction), place: Number(exponent) - fraction.length };
|
|
682
786
|
}
|
|
683
787
|
function finiteFallback(min, max) {
|
|
684
788
|
if (Number.isFinite(min)) return min;
|
|
@@ -877,16 +981,17 @@ var NumberInputController = class _NumberInputController extends Controller {
|
|
|
877
981
|
next = this.#safePageStep > 0 ? this.#currentValue() - this.#safePageStep : stepSteppedValue(this.#currentValue(), -10, this.#steppedRange);
|
|
878
982
|
break;
|
|
879
983
|
case "Home":
|
|
880
|
-
if (!Number.isFinite(this.#safeMin)) return;
|
|
881
984
|
next = this.#safeMin;
|
|
882
985
|
break;
|
|
883
986
|
case "End":
|
|
884
|
-
if (!Number.isFinite(this.#safeMax)) return;
|
|
885
987
|
next = this.#safeMax;
|
|
886
988
|
break;
|
|
887
989
|
default:
|
|
888
990
|
return;
|
|
889
991
|
}
|
|
992
|
+
if (next === Number.POSITIVE_INFINITY) next = this.#safeMax;
|
|
993
|
+
if (next === Number.NEGATIVE_INFINITY) next = this.#safeMin;
|
|
994
|
+
if (!Number.isFinite(next)) return;
|
|
890
995
|
event.preventDefault();
|
|
891
996
|
this.#commit(next, true);
|
|
892
997
|
}
|
|
@@ -1074,12 +1179,16 @@ var NumberInputController = class _NumberInputController extends Controller {
|
|
|
1074
1179
|
}
|
|
1075
1180
|
#updateButtons(value, range) {
|
|
1076
1181
|
const move = this.#move;
|
|
1077
|
-
|
|
1078
|
-
|
|
1182
|
+
const increments = this.incrementTargets;
|
|
1183
|
+
const canIncrement = increments.length > 0 && value < range.max && stepSteppedValue(value, 1, range) > value;
|
|
1184
|
+
for (const button of increments) {
|
|
1185
|
+
this.#toggleButton(button, canIncrement, move);
|
|
1079
1186
|
if (!this.#moves.isLatest(move)) return;
|
|
1080
1187
|
}
|
|
1081
|
-
|
|
1082
|
-
|
|
1188
|
+
const decrements = this.decrementTargets;
|
|
1189
|
+
const canDecrement = decrements.length > 0 && value > range.min && stepSteppedValue(value, -1, range) < value;
|
|
1190
|
+
for (const button of decrements) {
|
|
1191
|
+
this.#toggleButton(button, canDecrement, move);
|
|
1083
1192
|
if (!this.#moves.isLatest(move)) return;
|
|
1084
1193
|
}
|
|
1085
1194
|
}
|
|
@@ -45,6 +45,7 @@ function hasModifierChord(event) {
|
|
|
45
45
|
|
|
46
46
|
function setAttributeIfChanged(element, name, value, beforeWrite) {
|
|
47
47
|
if (element.getAttribute(name) === value) return false;
|
|
48
|
+
beforeWrite?.();
|
|
48
49
|
if (value === null) element.removeAttribute(name);
|
|
49
50
|
else element.setAttribute(name, value);
|
|
50
51
|
return true;
|
|
@@ -108,14 +109,34 @@ var AttributeLease = class {
|
|
|
108
109
|
const names = registry.names;
|
|
109
110
|
names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
|
|
110
111
|
}
|
|
111
|
-
write(element, value) {
|
|
112
|
+
write(element, value, beforeWrite) {
|
|
112
113
|
const stack = attributeStack(element, this.#attribute);
|
|
113
114
|
const hold = this.#take(stack) ?? this.#acquire(element, stack);
|
|
114
115
|
this.#held.add(element);
|
|
115
116
|
const shows = !this.#covered(element, stack, hold);
|
|
116
117
|
hold.written = value;
|
|
117
118
|
this.#mark(element, stack);
|
|
118
|
-
if (shows) this.#reflect(element, value);
|
|
119
|
+
if (shows) this.#reflect(element, value, beforeWrite);
|
|
120
|
+
}
|
|
121
|
+
adopt(element, options = {}) {
|
|
122
|
+
const known = registry.stacks.get(element)?.has(this.#attribute);
|
|
123
|
+
if (!this.#held.has(element) && !known && !element.hasAttribute(this.#record)) return false;
|
|
124
|
+
const stack = attributeStack(element, this.#attribute);
|
|
125
|
+
const hold = this.#take(stack);
|
|
126
|
+
if (!hold) return false;
|
|
127
|
+
const current = element.getAttribute(this.#attribute);
|
|
128
|
+
if (options.ifChanged && (current === hold.written || this.#covered(element, stack, hold))) {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
this.#held.add(element);
|
|
132
|
+
hold.original = current;
|
|
133
|
+
hold.linked = false;
|
|
134
|
+
for (const above of stack.slice(stack.indexOf(hold) + 1)) {
|
|
135
|
+
if (!above.linked) break;
|
|
136
|
+
above.original = current;
|
|
137
|
+
}
|
|
138
|
+
this.#mark(element, stack);
|
|
139
|
+
return true;
|
|
119
140
|
}
|
|
120
141
|
return(element) {
|
|
121
142
|
const held = this.#held.delete(element);
|
|
@@ -181,8 +202,8 @@ var AttributeLease = class {
|
|
|
181
202
|
setAttributeIfChanged(element, name, recorded);
|
|
182
203
|
}
|
|
183
204
|
}
|
|
184
|
-
#reflect(element, value) {
|
|
185
|
-
setAttributeIfChanged(element, this.#attribute, value);
|
|
205
|
+
#reflect(element, value, beforeWrite) {
|
|
206
|
+
setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
|
|
186
207
|
}
|
|
187
208
|
};
|
|
188
209
|
|
|
@@ -196,7 +217,50 @@ function isCompositionInputType(inputType) {
|
|
|
196
217
|
return inputType !== void 0 && COMPOSITION_INPUT_TYPES.has(inputType);
|
|
197
218
|
}
|
|
198
219
|
var BEFORE_MORPH_ATTRIBUTE = "turbo:before-morph-attribute";
|
|
199
|
-
var textOf = (element) =>
|
|
220
|
+
var textOf = (element) => {
|
|
221
|
+
if ("value" in element) return element.value;
|
|
222
|
+
return element instanceof Element ? element.textContent : void 0;
|
|
223
|
+
};
|
|
224
|
+
var nodesOf = (element) => {
|
|
225
|
+
const nodes = [];
|
|
226
|
+
if ("value" in element || !(element instanceof Element)) return nodes;
|
|
227
|
+
const walker = element.ownerDocument.createTreeWalker(element);
|
|
228
|
+
for (let node = walker.nextNode(); node !== null; node = walker.nextNode()) nodes.push(node);
|
|
229
|
+
return nodes;
|
|
230
|
+
};
|
|
231
|
+
var folded = (text) => text.replaceAll("\xA0", " ");
|
|
232
|
+
var startOf = (node, data, replaced, caret) => {
|
|
233
|
+
const text = folded(node.data);
|
|
234
|
+
const composed = folded(data);
|
|
235
|
+
if (replaced?.startContainer === node && text.startsWith(composed, replaced.startOffset)) {
|
|
236
|
+
return replaced.startOffset;
|
|
237
|
+
}
|
|
238
|
+
const start = text.lastIndexOf(composed, caret);
|
|
239
|
+
return start !== -1 && start + composed.length >= caret ? start : -1;
|
|
240
|
+
};
|
|
241
|
+
var spotOf = (element, replaced, data) => {
|
|
242
|
+
if ("value" in element || !(element instanceof Element)) return null;
|
|
243
|
+
const selection = element.ownerDocument.getSelection();
|
|
244
|
+
const node = selection?.focusNode;
|
|
245
|
+
if (!(node instanceof Text) || node.data === "" || !element.contains(node)) return null;
|
|
246
|
+
const range = element.ownerDocument.createRange();
|
|
247
|
+
const start = typeof data === "string" && data !== "" ? startOf(node, data, replaced, selection?.focusOffset ?? 0) : -1;
|
|
248
|
+
if (start === -1) {
|
|
249
|
+
range.selectNodeContents(node);
|
|
250
|
+
} else {
|
|
251
|
+
range.setStart(node, start);
|
|
252
|
+
range.setEnd(node, start + data.length);
|
|
253
|
+
}
|
|
254
|
+
return range;
|
|
255
|
+
};
|
|
256
|
+
var replacedBy = (event) => typeof event.getTargetRanges === "function" ? event.getTargetRanges()[0] ?? null : null;
|
|
257
|
+
var rewritten = ({ element, text, nodes, spot }) => {
|
|
258
|
+
if (spot !== null) {
|
|
259
|
+
return spot.collapsed || !(element instanceof Node && element.contains(spot.startContainer));
|
|
260
|
+
}
|
|
261
|
+
const current = nodesOf(element);
|
|
262
|
+
return textOf(element) !== text || current.length !== nodes.length || current.some((node, index) => node !== nodes[index]);
|
|
263
|
+
};
|
|
200
264
|
var holdsFocus = (element) => element instanceof Node && element.getRootNode().activeElement === element;
|
|
201
265
|
var CompositionTracker = class {
|
|
202
266
|
#observedTargets = /* @__PURE__ */ new Set();
|
|
@@ -257,7 +321,7 @@ var CompositionTracker = class {
|
|
|
257
321
|
this.#confirmedTarget = null;
|
|
258
322
|
if (confirmed === null || confirmed !== event.target) return false;
|
|
259
323
|
const inputType = event.inputType;
|
|
260
|
-
return
|
|
324
|
+
return inputType ? isCompositionInputType(inputType) : event.isTrusted === true;
|
|
261
325
|
}
|
|
262
326
|
#release(target) {
|
|
263
327
|
target.removeEventListener("compositionstart", this.#handleStart);
|
|
@@ -287,11 +351,11 @@ var CompositionTracker = class {
|
|
|
287
351
|
}
|
|
288
352
|
#settle() {
|
|
289
353
|
const composition = this.#composition;
|
|
290
|
-
if (composition === null) return;
|
|
291
|
-
const { target, element
|
|
354
|
+
if (composition === null || !this.#observedTargets.has(composition.target)) return;
|
|
355
|
+
const { target, element } = composition;
|
|
292
356
|
if (target instanceof Node && element instanceof Node && !target.contains(element)) {
|
|
293
357
|
this.#composition = null;
|
|
294
|
-
} else if (
|
|
358
|
+
} else if (rewritten(composition)) {
|
|
295
359
|
this.#abandon(false);
|
|
296
360
|
}
|
|
297
361
|
}
|
|
@@ -316,7 +380,14 @@ var CompositionTracker = class {
|
|
|
316
380
|
this.#owe(true);
|
|
317
381
|
const target = event.currentTarget;
|
|
318
382
|
const element = event.target;
|
|
319
|
-
this.#composition = {
|
|
383
|
+
this.#composition = {
|
|
384
|
+
target,
|
|
385
|
+
element,
|
|
386
|
+
text: textOf(element),
|
|
387
|
+
nodes: nodesOf(element),
|
|
388
|
+
spot: spotOf(element, null, void 0),
|
|
389
|
+
replaced: null
|
|
390
|
+
};
|
|
320
391
|
this.#runAbandon();
|
|
321
392
|
this.#onStart?.(event);
|
|
322
393
|
};
|
|
@@ -340,6 +411,10 @@ var CompositionTracker = class {
|
|
|
340
411
|
if (this.#composition !== null && !keyComposing && !isComposing && inputType && !isCompositionInputType(inputType)) {
|
|
341
412
|
this.#abandon(true);
|
|
342
413
|
}
|
|
414
|
+
const composition = this.#composition;
|
|
415
|
+
if (composition !== null && event.target === composition.element) {
|
|
416
|
+
composition.replaced = replacedBy(event);
|
|
417
|
+
}
|
|
343
418
|
this.#runAbandon();
|
|
344
419
|
};
|
|
345
420
|
#handleInput = (event) => {
|
|
@@ -347,6 +422,15 @@ var CompositionTracker = class {
|
|
|
347
422
|
const { isTrusted, isComposing, inputType } = event;
|
|
348
423
|
if (composition !== null && event.target === composition.element && (isTrusted || isComposing || isCompositionInputType(inputType))) {
|
|
349
424
|
composition.text = textOf(composition.element);
|
|
425
|
+
composition.nodes = nodesOf(composition.element);
|
|
426
|
+
if (isCompositionInputType(inputType)) {
|
|
427
|
+
composition.spot = spotOf(
|
|
428
|
+
composition.element,
|
|
429
|
+
composition.replaced,
|
|
430
|
+
event.data
|
|
431
|
+
);
|
|
432
|
+
}
|
|
433
|
+
composition.replaced = null;
|
|
350
434
|
} else {
|
|
351
435
|
this.#settle();
|
|
352
436
|
}
|
|
@@ -367,7 +451,9 @@ var CompositionTracker = class {
|
|
|
367
451
|
const composition = this.#composition;
|
|
368
452
|
if (composition?.target !== event.currentTarget || event.target !== composition.element) return;
|
|
369
453
|
const detail = event.detail;
|
|
370
|
-
if (detail?.attributeName === "value"
|
|
454
|
+
if (detail?.attributeName === "value" && "value" in composition.element) {
|
|
455
|
+
event.preventDefault();
|
|
456
|
+
}
|
|
371
457
|
};
|
|
372
458
|
};
|
|
373
459
|
|