@wix/site-ui 1.346.0 → 1.348.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.
- package/dist/{6706.js → 1093.js} +3 -3
- package/dist/{8724.js → 1219.js} +2 -2
- package/dist/{7373.js → 1288.js} +8 -2
- package/dist/{5299.js → 1381.js} +98 -127
- package/dist/{3056.js → 1607.js} +32 -34
- package/dist/1629.js +2 -0
- package/dist/1669.js +75 -0
- package/dist/1718.js +26 -0
- package/dist/{1477.js → 201.js} +17 -26
- package/dist/2221.js +9 -0
- package/dist/{2445.js → 226.js} +12 -48
- package/dist/2387.js +7 -0
- package/dist/2580.js +6 -0
- package/dist/{1500.js → 2859.js} +10 -34
- package/dist/3014.js +178 -0
- package/dist/{6247.js → 3054.js} +3 -3
- package/dist/{7642.js → 3093.js} +1 -1
- package/dist/3189.js +5 -0
- package/dist/{7564.js → 331.js} +2 -2
- package/dist/3357.js +7 -0
- package/dist/{487.js → 3398.js} +38 -39
- package/dist/3502.js +224 -0
- package/dist/3695.js +50 -0
- package/dist/3829.js +1 -1
- package/dist/{6588.js → 3859.js} +115 -92
- package/dist/{3670.js → 3910.js} +28 -21
- package/dist/392.js +7 -0
- package/dist/{4549.js → 4155.js} +11 -3
- package/dist/4226.js +7 -0
- package/dist/{6329.js → 4229.js} +1 -1
- package/dist/4293.js +3 -0
- package/dist/4346.js +853 -2
- package/dist/{285.js → 4472.js} +3 -3
- package/dist/4605.js +207 -0
- package/dist/{7366.js → 488.js} +60 -7
- package/dist/{8750.js → 497.js} +190 -375
- package/dist/4989.js +35 -0
- package/dist/{6270.js → 510.js} +157 -196
- package/dist/5258.js +26 -0
- package/dist/{5036.js → 5275.js} +0 -3
- package/dist/{8171.js → 5298.js} +90 -102
- package/dist/5473.js +11 -0
- package/dist/{4745.js → 5490.js} +3 -1
- package/dist/{6089.js → 5561.js} +869 -786
- package/dist/{8996.js → 5595.js} +4 -3
- package/dist/5890.js +25 -0
- package/dist/{6046.js → 5969.js} +1 -1
- package/dist/5984.js +38 -0
- package/dist/{8527.js → 6006.js} +3 -3
- package/dist/6040.js +97 -0
- package/dist/{8758.js → 6137.js} +10 -8
- package/dist/{4281.js → 6140.js} +18 -10
- package/dist/{8960.js → 6191.js} +2 -2
- package/dist/6240.js +121 -0
- package/dist/{4490.js → 6373.js} +7 -5
- package/dist/{904.js → 6487.js} +19 -17
- package/dist/{9635.js → 6498.js} +1 -1
- package/dist/6499.js +4 -7
- package/dist/6508.js +7 -0
- package/dist/{8225.js → 6540.js} +1 -0
- package/dist/6551.js +46 -0
- package/dist/{9369.js → 6620.js} +35 -34
- package/dist/{4143.js → 6838.js} +19 -10
- package/dist/6902.js +48 -0
- package/dist/6904.js +51 -0
- package/dist/70.js +24 -0
- package/dist/7024.js +39 -0
- package/dist/{6882.js → 721.js} +737 -362
- package/dist/{951.js → 7270.js} +4 -4
- package/dist/{3485.js → 7323.js} +143 -111
- package/dist/{7541.js → 7488.js} +2 -2
- package/dist/{4863.js → 7542.js} +7 -6
- package/dist/7551.js +28 -0
- package/dist/{7021.js → 7640.js} +1 -1
- package/dist/{353.js → 7692.js} +3 -7
- package/dist/{4707.js → 7930.js} +2 -2
- package/dist/{8052.js → 8.js} +80 -64
- package/dist/{6914.js → 8129.js} +3 -15
- package/dist/{3319.js → 8358.js} +62 -63
- package/dist/{5864.js → 8407.js} +13 -13
- package/dist/8488.js +15 -0
- package/dist/{4768.js → 8495.js} +1 -1
- package/dist/8734.js +171 -0
- package/dist/{1763.js → 9018.js} +205 -331
- package/dist/9053.js +29 -0
- package/dist/9067.js +41 -0
- package/dist/{2861.js → 9120.js} +2 -2
- package/dist/{42.js → 9197.js} +2 -2
- package/dist/{9189.js → 9248.js} +36 -17
- package/dist/{2801.js → 9252.js} +4 -9
- package/dist/9295.js +7 -0
- package/dist/9303.js +8 -0
- package/dist/{167.js → 9374.js} +1 -1
- package/dist/{9352.js → 9540.js} +17 -47
- package/dist/9576.js +51 -0
- package/dist/{8272.js → 9591.js} +36 -46
- package/dist/{6107.js → 9770.js} +2 -2
- package/dist/{5085.js → 9880.js} +6 -3
- package/dist/Accordion/index.d.ts +207 -41
- package/dist/Accordion/index.js +75 -177
- package/dist/AlertDialog/index.d.ts +440 -140
- package/dist/AlertDialog/index.js +3 -13
- package/dist/Autocomplete/index.d.ts +722 -150
- package/dist/Autocomplete/index.js +16 -29
- package/dist/Avatar/index.d.ts +38 -3
- package/dist/Avatar/index.js +82 -28
- package/dist/Breadcrumbs/index.d.ts +63 -91
- package/dist/Breadcrumbs/index.js +1 -1
- package/dist/Button/index.d.ts +11 -0
- package/dist/Button/index.js +2 -2
- package/dist/Checkbox/index.d.ts +206 -36
- package/dist/Checkbox/index.js +293 -8
- package/dist/CheckboxField/index.css +1 -1
- package/dist/CheckboxField/index.d.ts +40 -36
- package/dist/CheckboxGroup/index.d.ts +50 -36
- package/dist/CheckboxGroup/index.js +87 -58
- package/dist/CheckboxGroupField/index.css +1 -1
- package/dist/Collapsible/index.d.ts +128 -36
- package/dist/Collapsible/index.js +21 -25
- package/dist/Combobox/index.d.ts +801 -158
- package/dist/Combobox/index.js +70 -114
- package/dist/ContextMenu/index.d.ts +1162 -195
- package/dist/ContextMenu/index.js +46 -36
- package/dist/Dialog/index.d.ts +425 -133
- package/dist/Dialog/index.js +8 -4
- package/dist/Drawer/index.d.ts +589 -144
- package/dist/Drawer/index.js +482 -562
- package/dist/Field/index.css +1 -1
- package/dist/Field/index.d.ts +341 -42
- package/dist/Field/index.js +123 -273
- package/dist/Fieldset/index.d.ts +11 -0
- package/dist/Fieldset/index.js +10 -17
- package/dist/Form/index.d.ts +43 -39
- package/dist/Form/index.js +58 -50
- package/dist/Input/index.css +1 -1
- package/dist/Input/index.d.ts +94 -42
- package/dist/Input/index.js +1 -1
- package/dist/Menu/index.d.ts +1140 -175
- package/dist/Menu/index.js +51 -67
- package/dist/Menubar/index.d.ts +651 -173
- package/dist/Menubar/index.js +12 -16
- package/dist/Meter/index.js +21 -18
- package/dist/NavigationMenu/index.d.ts +370 -86
- package/dist/NavigationMenu/index.js +144 -178
- package/dist/NumberField/index.css +1 -1
- package/dist/NumberField/index.d.ts +507 -47
- package/dist/NumberField/index.js +434 -718
- package/dist/Popover/index.d.ts +561 -142
- package/dist/Popover/index.js +181 -252
- package/dist/PreviewCard/index.d.ts +507 -143
- package/dist/PreviewCard/index.js +97 -151
- package/dist/Progress/index.d.ts +117 -3
- package/dist/Progress/index.js +37 -36
- package/dist/Radio/index.d.ts +177 -7
- package/dist/Radio/index.js +54 -70
- package/dist/RadioField/index.css +1 -1
- package/dist/RadioField/index.d.ts +23 -7
- package/dist/RadioGroup/index.d.ts +51 -37
- package/dist/RadioGroup/index.js +60 -51
- package/dist/RadioGroupField/index.css +1 -1
- package/dist/RadioGroupField/index.d.ts +40 -37
- package/dist/ScrollArea/index.d.ts +295 -1
- package/dist/ScrollArea/index.js +256 -324
- package/dist/Select/index.d.ts +516 -123
- package/dist/Select/index.js +513 -635
- package/dist/SelectField/index.css +1 -1
- package/dist/SelectField/index.d.ts +109 -134
- package/dist/SelectField/index.js +5 -1
- package/dist/Separator/index.d.ts +12 -0
- package/dist/Separator/index.js +1 -1
- package/dist/Slider/index.d.ts +383 -64
- package/dist/Slider/index.js +298 -374
- package/dist/Switch/index.d.ts +184 -37
- package/dist/Switch/index.js +44 -58
- package/dist/Tabs/index.d.ts +220 -35
- package/dist/Tabs/index.js +199 -193
- package/dist/Toast/index.d.ts +280 -64
- package/dist/Toast/index.js +299 -374
- package/dist/Toggle/index.d.ts +55 -35
- package/dist/Toggle/index.js +19 -13
- package/dist/ToggleGroup/index.d.ts +62 -35
- package/dist/ToggleGroup/index.js +13 -31
- package/dist/Toolbar/index.d.ts +117 -2
- package/dist/Toolbar/index.js +31 -43
- package/dist/Tooltip/index.d.ts +507 -150
- package/dist/Tooltip/index.js +163 -213
- package/dist/index.d.ts +12912 -5382
- package/package.json +3 -3
- package/dist/2205.js +0 -26
- package/dist/2274.js +0 -34
- package/dist/2287.js +0 -17
- package/dist/3020.js +0 -7
- package/dist/3021.js +0 -72
- package/dist/3140.js +0 -4
- package/dist/3248.js +0 -307
- package/dist/4026.js +0 -12
- package/dist/4922.js +0 -15
- package/dist/5659.js +0 -4
- package/dist/5992.js +0 -447
- package/dist/6330.js +0 -30
- package/dist/6535.js +0 -72
- package/dist/6917.js +0 -55
- package/dist/7725.js +0 -10
- package/dist/7871.js +0 -38
- package/dist/8106.js +0 -239
- package/dist/8685.js +0 -102
- package/dist/8935.js +0 -8
- package/dist/8971.js +0 -40
- package/dist/8979.js +0 -10
- package/dist/9048.js +0 -52
- package/dist/9087.js +0 -256
- package/dist/9255.js +0 -136
- /package/dist/{1457.js → 1068.js} +0 -0
- /package/dist/{6003.js → 1234.js} +0 -0
- /package/dist/{4723.js → 1282.js} +0 -0
- /package/dist/{6825.js → 1876.js} +0 -0
- /package/dist/{5778.js → 1885.js} +0 -0
- /package/dist/{2445.js.LICENSE.txt → 226.js.LICENSE.txt} +0 -0
- /package/dist/{1279.js → 3278.js} +0 -0
- /package/dist/{3296.js → 5568.js} +0 -0
- /package/dist/{8685.css → 6240.css} +0 -0
- /package/dist/{9829.js → 6488.js} +0 -0
- /package/dist/{9863.js → 6534.js} +0 -0
- /package/dist/{4495.js → 7718.js} +0 -0
- /package/dist/{3395.js → 8866.js} +0 -0
- /package/dist/{2418.js → 9837.js} +0 -0
|
@@ -1,31 +1,33 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import clsx from "clsx";
|
|
3
|
-
import {
|
|
4
|
-
import { useLabelableContext, fieldValidityMapping, useFieldRootContext } from "../
|
|
5
|
-
import { formatNumber,
|
|
6
|
-
import { clamp } from "../
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
3
|
+
import { utils_formatErrorMessage } from "../5473.js";
|
|
4
|
+
import { useLabelableContext, fieldValidityMapping, useFieldRootContext } from "../201.js";
|
|
5
|
+
import { formatNumber, getFormatter } from "../8129.js";
|
|
6
|
+
import { clamp } from "../5568.js";
|
|
7
|
+
import { useFormContext } from "../9880.js";
|
|
8
|
+
import { useMergedRefs, useRenderElement, warn } from "../9591.js";
|
|
9
|
+
import { useLabelableId } from "../6551.js";
|
|
10
|
+
import { useControlled } from "../6006.js";
|
|
11
|
+
import { useValueAsRef } from "../7930.js";
|
|
12
|
+
import { useIsoLayoutEffect, SafeReact } from "../3357.js";
|
|
13
|
+
import { useForcedRerendering } from "../4989.js";
|
|
14
|
+
import { useStableCallback } from "../7488.js";
|
|
15
|
+
import { createGenericEventDetails, createChangeEventDetails } from "../8495.js";
|
|
16
|
+
import { ios } from "../2221.js";
|
|
17
|
+
import { getTarget, activeElement } from "../4155.js";
|
|
18
|
+
import { ownerDocument } from "../6488.js";
|
|
19
|
+
import { addEventListener } from "../1282.js";
|
|
20
|
+
import { visuallyHiddenInput, visuallyHidden } from "../6540.js";
|
|
21
|
+
import { keyboard, decrementPress, inputClear, incrementPress, inputBlur, inputChange, inputPaste } from "../9837.js";
|
|
22
|
+
import { usePressAndHold, isTouchLikePointerType } from "../8734.js";
|
|
23
|
+
import { useButton } from "../9248.js";
|
|
24
|
+
import { useSetFieldFocused } from "../5890.js";
|
|
25
|
+
import { useRegisterFieldControl } from "../6140.js";
|
|
26
|
+
import { useValueChanged } from "../9252.js";
|
|
22
27
|
import { getWindow } from "../3829.js";
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import { useValueChanged } from "../2801.js";
|
|
27
|
-
import { stopEvent } from "../6330.js";
|
|
28
|
-
import { mergeCleanups } from "../4495.js";
|
|
28
|
+
import { useTimeout } from "../9197.js";
|
|
29
|
+
import { gecko, webkit } from "../3189.js";
|
|
30
|
+
import { mergeCleanups } from "../7718.js";
|
|
29
31
|
import { Field, FieldLabel_FieldLabel } from "../Field/index.js";
|
|
30
32
|
import * as __rspack_external_react from "react";
|
|
31
33
|
import * as __rspack_external_react_dom_7136dc57 from "react-dom";
|
|
@@ -33,7 +35,7 @@ const NumberFieldRootContext = /*#__PURE__*/ __rspack_external_react.createConte
|
|
|
33
35
|
if ("production" !== process.env.NODE_ENV) NumberFieldRootContext.displayName = "NumberFieldRootContext";
|
|
34
36
|
function useNumberFieldRootContext() {
|
|
35
37
|
const context = __rspack_external_react.useContext(NumberFieldRootContext);
|
|
36
|
-
if (void 0 === context) throw new Error("production" !== process.env.NODE_ENV ? 'Base UI: NumberFieldRootContext is missing. NumberField parts must be placed within <NumberField.Root>.' :
|
|
38
|
+
if (void 0 === context) throw new Error("production" !== process.env.NODE_ENV ? 'Base UI: NumberFieldRootContext is missing. NumberField parts must be placed within <NumberField.Root>.' : utils_formatErrorMessage(43));
|
|
37
39
|
return context;
|
|
38
40
|
}
|
|
39
41
|
const stateAttributesMapping = {
|
|
@@ -41,68 +43,9 @@ const stateAttributesMapping = {
|
|
|
41
43
|
value: ()=>null,
|
|
42
44
|
...fieldValidityMapping
|
|
43
45
|
};
|
|
44
|
-
const HAN_NUMERALS =
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
'一',
|
|
48
|
-
'二',
|
|
49
|
-
'三',
|
|
50
|
-
'四',
|
|
51
|
-
'五',
|
|
52
|
-
'六',
|
|
53
|
-
'七',
|
|
54
|
-
'八',
|
|
55
|
-
'九'
|
|
56
|
-
];
|
|
57
|
-
const HAN_NUMERAL_TO_DIGIT = {
|
|
58
|
-
零: '0',
|
|
59
|
-
〇: '0',
|
|
60
|
-
一: '1',
|
|
61
|
-
二: '2',
|
|
62
|
-
三: '3',
|
|
63
|
-
四: '4',
|
|
64
|
-
五: '5',
|
|
65
|
-
六: '6',
|
|
66
|
-
七: '7',
|
|
67
|
-
八: '8',
|
|
68
|
-
九: '9'
|
|
69
|
-
};
|
|
70
|
-
const ARABIC_NUMERALS = [
|
|
71
|
-
'٠',
|
|
72
|
-
'١',
|
|
73
|
-
'٢',
|
|
74
|
-
'٣',
|
|
75
|
-
'٤',
|
|
76
|
-
'٥',
|
|
77
|
-
'٦',
|
|
78
|
-
'٧',
|
|
79
|
-
'٨',
|
|
80
|
-
'٩'
|
|
81
|
-
];
|
|
82
|
-
const PERSIAN_NUMERALS = [
|
|
83
|
-
'۰',
|
|
84
|
-
'۱',
|
|
85
|
-
'۲',
|
|
86
|
-
'۳',
|
|
87
|
-
'۴',
|
|
88
|
-
'۵',
|
|
89
|
-
'۶',
|
|
90
|
-
'۷',
|
|
91
|
-
'۸',
|
|
92
|
-
'۹'
|
|
93
|
-
];
|
|
94
|
-
const FULLWIDTH_NUMERALS = [
|
|
95
|
-
'0',
|
|
96
|
-
'1',
|
|
97
|
-
'2',
|
|
98
|
-
'3',
|
|
99
|
-
'4',
|
|
100
|
-
'5',
|
|
101
|
-
'6',
|
|
102
|
-
'7',
|
|
103
|
-
'8',
|
|
104
|
-
'9'
|
|
105
|
-
];
|
|
46
|
+
const HAN_NUMERALS = '零〇一二三四五六七八九';
|
|
47
|
+
const NON_ASCII_DIGIT_RE = /[٠-٩۰-۹0-9]/g;
|
|
48
|
+
const HAN_RE = /[零〇一二三四五六七八九]/g;
|
|
106
49
|
const PERCENTAGES = [
|
|
107
50
|
'%',
|
|
108
51
|
'٪',
|
|
@@ -113,30 +56,18 @@ const PERMILLE = [
|
|
|
113
56
|
'‰',
|
|
114
57
|
'؉'
|
|
115
58
|
];
|
|
116
|
-
const UNICODE_MINUS_SIGNS = [
|
|
117
|
-
'−',
|
|
118
|
-
'-',
|
|
119
|
-
'‒',
|
|
120
|
-
'–',
|
|
121
|
-
'—',
|
|
122
|
-
'﹣'
|
|
123
|
-
];
|
|
124
|
-
const UNICODE_PLUS_SIGNS = [
|
|
125
|
-
'+',
|
|
126
|
-
'﹢'
|
|
127
|
-
];
|
|
128
59
|
const FULLWIDTH_DECIMAL = '.';
|
|
129
60
|
const FULLWIDTH_GROUP = ',';
|
|
130
|
-
const
|
|
131
|
-
const
|
|
132
|
-
const
|
|
133
|
-
const
|
|
134
|
-
const
|
|
135
|
-
const PERMILLE_RE = new RegExp(`[${PERMILLE.join('')}]`);
|
|
136
|
-
const ARABIC_DETECT_RE = /[٠١٢٣٤٥٦٧٨٩]/;
|
|
137
|
-
const PERSIAN_DETECT_RE = /[۰۱۲۳۴۵۶۷۸۹]/;
|
|
61
|
+
const PERCENT_RE = /[%٪%﹪]/;
|
|
62
|
+
const PERMILLE_RE = /[‰؉]/;
|
|
63
|
+
const PERCENT_GLOBAL_RE = /[%٪%﹪]/g;
|
|
64
|
+
const PERMILLE_GLOBAL_RE = /[‰؉]/g;
|
|
65
|
+
const ARABIC_PERSIAN_DETECT_RE = /[٠-٩۰-۹]/;
|
|
138
66
|
const HAN_DETECT_RE = /[零〇一二三四五六七八九]/;
|
|
139
|
-
const
|
|
67
|
+
const ANY_NUMERAL_DETECT_RE = /[0-9٠-٩۰-۹0-9零〇一二三四五六七八九]/;
|
|
68
|
+
function isNumeralChar(char) {
|
|
69
|
+
return ANY_NUMERAL_DETECT_RE.test(char);
|
|
70
|
+
}
|
|
140
71
|
const BASE_NON_NUMERIC_SYMBOLS = [
|
|
141
72
|
'.',
|
|
142
73
|
',',
|
|
@@ -146,59 +77,65 @@ const BASE_NON_NUMERIC_SYMBOLS = [
|
|
|
146
77
|
'٬'
|
|
147
78
|
];
|
|
148
79
|
const SPACE_SEPARATOR_RE = /\p{Zs}/u;
|
|
80
|
+
const FORMAT_CONTROL_DETECT_RE = /\p{Cf}/u;
|
|
81
|
+
const FORMAT_CONTROL_GLOBAL_RE = /\p{Cf}/gu;
|
|
149
82
|
const PLUS_SIGNS_WITH_ASCII = [
|
|
150
83
|
'+',
|
|
151
|
-
|
|
84
|
+
'+',
|
|
85
|
+
'﹢'
|
|
152
86
|
];
|
|
153
87
|
const MINUS_SIGNS_WITH_ASCII = [
|
|
154
88
|
'-',
|
|
155
|
-
|
|
89
|
+
'−',
|
|
90
|
+
'-',
|
|
91
|
+
'‒',
|
|
92
|
+
'–',
|
|
93
|
+
'—',
|
|
94
|
+
'﹣'
|
|
156
95
|
];
|
|
157
96
|
const escapeRegExp = (s)=>s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
158
|
-
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
]
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
]
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
97
|
+
function shiftDecimal(value, exponentDelta) {
|
|
98
|
+
const [coefficient, exponent = '0'] = String(value).split('e');
|
|
99
|
+
return Number(`${coefficient}e${Number(exponent) + exponentDelta}`);
|
|
100
|
+
}
|
|
101
|
+
const ANY_MINUS_RE = /[-−-‒–—﹣]/gu;
|
|
102
|
+
const ANY_PLUS_RE = /[++﹢]/gu;
|
|
103
|
+
const ANY_MINUS_DETECT_RE = /[-−-‒–—﹣]/;
|
|
104
|
+
const ANY_PLUS_DETECT_RE = /[++﹢]/;
|
|
105
|
+
const SAMPLE_FORMAT_NUMBER = 11111.1;
|
|
106
|
+
function getFormatParts(locale, options) {
|
|
107
|
+
return getFormatter(locale, options).formatToParts(SAMPLE_FORMAT_NUMBER);
|
|
108
|
+
}
|
|
170
109
|
function getNumberLocaleDetails(locale, options) {
|
|
171
|
-
const parts =
|
|
110
|
+
const parts = getFormatParts(locale, options);
|
|
172
111
|
const result = {};
|
|
173
112
|
parts.forEach((part)=>{
|
|
174
113
|
result[part.type] = part.value;
|
|
175
114
|
});
|
|
115
|
+
let decimal = '.';
|
|
176
116
|
getFormatter(locale).formatToParts(0.1).forEach((part)=>{
|
|
177
|
-
if ('decimal' === part.type)
|
|
117
|
+
if ('decimal' === part.type) decimal = part.value;
|
|
178
118
|
});
|
|
179
|
-
return
|
|
119
|
+
return {
|
|
120
|
+
...result,
|
|
121
|
+
decimal
|
|
122
|
+
};
|
|
180
123
|
}
|
|
181
124
|
function parseNumber(formattedNumber, locale, options) {
|
|
182
|
-
|
|
183
|
-
let input = String(formattedNumber).replace(/\p{Cf}/gu, '').trim();
|
|
125
|
+
let input = formattedNumber.replace(FORMAT_CONTROL_GLOBAL_RE, '').trim();
|
|
184
126
|
input = input.replace(ANY_MINUS_RE, '-').replace(ANY_PLUS_RE, '+');
|
|
185
127
|
let isNegative = false;
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
const leading = input.match(/^\s*([+-])/);
|
|
192
|
-
if (leading) {
|
|
193
|
-
if ('-' === leading[1]) isNegative = true;
|
|
194
|
-
input = input.replace(/^\s*[+-]/, '');
|
|
195
|
-
}
|
|
128
|
+
const takeSign = (match, sign)=>{
|
|
129
|
+
if ('-' === sign) isNegative = true;
|
|
130
|
+
return '';
|
|
131
|
+
};
|
|
132
|
+
input = input.replace(/([+-])\s*$/, takeSign).replace(/^\s*([+-])/, takeSign);
|
|
196
133
|
let computedLocale = locale;
|
|
197
134
|
if (void 0 === computedLocale) {
|
|
198
|
-
if (
|
|
135
|
+
if (ARABIC_PERSIAN_DETECT_RE.test(input)) computedLocale = 'ar';
|
|
199
136
|
else if (HAN_DETECT_RE.test(input)) computedLocale = 'zh';
|
|
200
137
|
}
|
|
201
|
-
const { group, decimal, currency } = getNumberLocaleDetails(computedLocale, options);
|
|
138
|
+
const { group, decimal, currency, exponentSeparator } = getNumberLocaleDetails(computedLocale, options);
|
|
202
139
|
const unitParts = getFormatter(computedLocale, options).formatToParts(1).filter((p)=>'unit' === p.type).map((p)=>escapeRegExp(p.value));
|
|
203
140
|
const unitRegex = unitParts.length ? new RegExp(unitParts.join('|'), 'g') : null;
|
|
204
141
|
let groupRegex = null;
|
|
@@ -208,116 +145,116 @@ function parseNumber(formattedNumber, locale, options) {
|
|
|
208
145
|
groupRegex = isSpaceGroup ? /\p{Zs}/gu : isApostropheGroup ? /['’]/g : new RegExp(escapeRegExp(group), 'g');
|
|
209
146
|
}
|
|
210
147
|
const replacements = [
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
{
|
|
256
|
-
regex: HAN_RE,
|
|
257
|
-
replacement: (ch)=>HAN_NUMERAL_TO_DIGIT[ch]
|
|
258
|
-
}
|
|
148
|
+
[
|
|
149
|
+
groupRegex,
|
|
150
|
+
''
|
|
151
|
+
],
|
|
152
|
+
[
|
|
153
|
+
new RegExp(escapeRegExp(decimal), 'g'),
|
|
154
|
+
'.'
|
|
155
|
+
],
|
|
156
|
+
[
|
|
157
|
+
/[.٫]/g,
|
|
158
|
+
'.'
|
|
159
|
+
],
|
|
160
|
+
[
|
|
161
|
+
/[,٬]/g,
|
|
162
|
+
''
|
|
163
|
+
],
|
|
164
|
+
[
|
|
165
|
+
currency ? new RegExp(escapeRegExp(currency), 'g') : null,
|
|
166
|
+
''
|
|
167
|
+
],
|
|
168
|
+
[
|
|
169
|
+
unitRegex,
|
|
170
|
+
''
|
|
171
|
+
],
|
|
172
|
+
[
|
|
173
|
+
PERCENT_GLOBAL_RE,
|
|
174
|
+
''
|
|
175
|
+
],
|
|
176
|
+
[
|
|
177
|
+
PERMILLE_GLOBAL_RE,
|
|
178
|
+
''
|
|
179
|
+
],
|
|
180
|
+
[
|
|
181
|
+
exponentSeparator ? new RegExp(escapeRegExp(exponentSeparator), 'g') : null,
|
|
182
|
+
'e'
|
|
183
|
+
],
|
|
184
|
+
[
|
|
185
|
+
NON_ASCII_DIGIT_RE,
|
|
186
|
+
(ch)=>String(ch.charCodeAt(0) % 16)
|
|
187
|
+
],
|
|
188
|
+
[
|
|
189
|
+
HAN_RE,
|
|
190
|
+
(ch)=>String(Math.max(HAN_NUMERALS.indexOf(ch) - 1, 0))
|
|
191
|
+
]
|
|
259
192
|
];
|
|
260
|
-
let unformatted = replacements.reduce((acc,
|
|
193
|
+
let unformatted = replacements.reduce((acc, [regex, replacement])=>regex ? acc.replace(regex, replacement) : acc, input);
|
|
261
194
|
const lastDot = unformatted.lastIndexOf('.');
|
|
262
195
|
if (-1 !== lastDot) unformatted = `${unformatted.slice(0, lastDot).replace(/\./g, '')}.${unformatted.slice(lastDot + 1).replace(/\./g, '')}`;
|
|
263
|
-
if (/^[-+]?Infinity$/i.test(input) ||
|
|
196
|
+
if (/^[-+]?Infinity$/i.test(input) || input.includes('∞')) return null;
|
|
264
197
|
const parseTarget = (isNegative ? '-' : '') + unformatted;
|
|
265
198
|
let num = parseFloat(parseTarget);
|
|
266
199
|
const style = options?.style;
|
|
267
200
|
const isUnitPercent = 'unit' === style && options?.unit === 'percent';
|
|
268
201
|
const hasPercentSymbol = PERCENT_RE.test(formattedNumber) || 'percent' === style;
|
|
269
202
|
const hasPermilleSymbol = PERMILLE_RE.test(formattedNumber);
|
|
270
|
-
if (hasPermilleSymbol) num
|
|
271
|
-
else if (!isUnitPercent && hasPercentSymbol) num
|
|
272
|
-
if (Number.
|
|
203
|
+
if (hasPermilleSymbol) num = shiftDecimal(num, -3);
|
|
204
|
+
else if (!isUnitPercent && hasPercentSymbol) num = shiftDecimal(num, -2);
|
|
205
|
+
if (!Number.isFinite(num)) return null;
|
|
273
206
|
return num;
|
|
274
207
|
}
|
|
275
208
|
const STEP_EPSILON_FACTOR = 1e-10;
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
const maximumFractionDigits = Math.max(format?.maximumFractionDigits ?? defaultOptions.maximumFractionDigits ?? 20, minimumFractionDigits);
|
|
280
|
-
return {
|
|
281
|
-
maximumFractionDigits,
|
|
282
|
-
minimumFractionDigits
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
function roundToFractionDigits(value, maximumFractionDigits) {
|
|
286
|
-
if (!Number.isFinite(value)) return value;
|
|
287
|
-
const digits = Math.min(Math.max(maximumFractionDigits, 0), 20);
|
|
288
|
-
return Number(value.toFixed(digits));
|
|
209
|
+
const MAX_FLOATING_POINT_CLEANUP_DELTA = 1e-10;
|
|
210
|
+
function hasNumberFormatRoundingOptions(format) {
|
|
211
|
+
return format?.maximumFractionDigits != null || format?.minimumFractionDigits != null || format?.maximumSignificantDigits != null || format?.minimumSignificantDigits != null || format?.roundingIncrement != null || format?.roundingMode != null || format?.roundingPriority != null;
|
|
289
212
|
}
|
|
290
213
|
function removeFloatingPointErrors(value, format) {
|
|
291
|
-
|
|
292
|
-
|
|
214
|
+
if (!Number.isFinite(value)) return value;
|
|
215
|
+
if (!hasNumberFormatRoundingOptions(format)) {
|
|
216
|
+
const roundedValue = parseFloat(value.toPrecision(15));
|
|
217
|
+
const cleanupDelta = Math.abs(roundedValue - value);
|
|
218
|
+
const cleanupTolerance = Math.min(Number.EPSILON * Math.max(1, Math.abs(value)), MAX_FLOATING_POINT_CLEANUP_DELTA);
|
|
219
|
+
return cleanupDelta <= cleanupTolerance ? roundedValue : value;
|
|
220
|
+
}
|
|
221
|
+
const formatter = getFormatter('en-US', {
|
|
222
|
+
...format,
|
|
223
|
+
signDisplay: 'auto',
|
|
224
|
+
currencySign: 'standard',
|
|
225
|
+
notation: 'compact' === format.notation ? 'standard' : format.notation,
|
|
226
|
+
useGrouping: false
|
|
227
|
+
});
|
|
228
|
+
const roundedText = formatter.format(value);
|
|
229
|
+
const roundedValue = parseNumber(roundedText, 'en-US', format);
|
|
230
|
+
if (null === roundedValue) return value;
|
|
231
|
+
return formatter.format(roundedValue) === roundedText ? roundedValue : value;
|
|
293
232
|
}
|
|
294
|
-
function snapToStep(
|
|
295
|
-
if (0 === step) return clampedValue;
|
|
233
|
+
function snapToStep(value, base, step, nearest) {
|
|
296
234
|
const stepSize = Math.abs(step);
|
|
297
235
|
const direction = Math.sign(step);
|
|
298
236
|
const tolerance = stepSize * STEP_EPSILON_FACTOR * direction;
|
|
299
|
-
const
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
const stepForResult = 'nearest' === mode ? step : stepSize;
|
|
304
|
-
return base + snappedSteps * stepForResult;
|
|
237
|
+
const rawSteps = value - base + tolerance;
|
|
238
|
+
if (nearest) return base + Math.round(rawSteps / step) * step;
|
|
239
|
+
const snappedSteps = direction > 0 ? Math.floor(rawSteps / stepSize) : Math.ceil(rawSteps / stepSize);
|
|
240
|
+
return base + snappedSteps * stepSize;
|
|
305
241
|
}
|
|
306
|
-
function toValidatedNumber(value,
|
|
242
|
+
function toValidatedNumber(value, step, minWithDefault, maxWithDefault, minWithZeroDefault, format, snapOnStep, small, shouldClamp) {
|
|
307
243
|
if (null === value) return value;
|
|
308
|
-
|
|
309
|
-
if (null != step && snapOnStep) {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
if (!small && minWithDefault !== Number.MIN_SAFE_INTEGER) base = minWithDefault;
|
|
313
|
-
const snappedValue = snapToStep(clampedValue, base, step, small ? 'nearest' : 'directional');
|
|
314
|
-
return removeFloatingPointErrors(snappedValue, format);
|
|
244
|
+
let nextValue = value;
|
|
245
|
+
if (null != step && snapOnStep && 0 !== step) {
|
|
246
|
+
const base = small || minWithDefault === Number.MIN_SAFE_INTEGER ? minWithZeroDefault : minWithDefault;
|
|
247
|
+
nextValue = snapToStep(nextValue, base, step, small);
|
|
315
248
|
}
|
|
316
|
-
|
|
249
|
+
if (shouldClamp) nextValue = clamp(nextValue, minWithDefault, maxWithDefault);
|
|
250
|
+
if (null == step && !hasNumberFormatRoundingOptions(format)) return nextValue;
|
|
251
|
+
const roundedValue = removeFloatingPointErrors(nextValue, format);
|
|
252
|
+
return shouldClamp ? clamp(roundedValue, minWithDefault, maxWithDefault) : roundedValue;
|
|
317
253
|
}
|
|
318
254
|
const NumberFieldRoot_NumberFieldRoot = /*#__PURE__*/ __rspack_external_react.forwardRef(function(componentProps, forwardedRef) {
|
|
319
|
-
const { id: idProp, min, max, smallStep = 0.1, step: stepProp = 1, largeStep = 10, required = false, disabled: disabledProp = false, readOnly = false, form, name: nameProp, defaultValue, value: valueProp, onValueChange: onValueChangeProp, onValueCommitted: onValueCommittedProp, allowWheelScrub = false, snapOnStep = false, allowOutOfRange = false, format, locale, render, className, inputRef: inputRefProp, style, ...elementProps } = componentProps;
|
|
320
|
-
const { setDirty, validityData, disabled: fieldDisabled, setFilled,
|
|
255
|
+
const { id: idProp, min, max, smallStep = 0.1, step: stepProp = 1, largeStep = 10, required = false, disabled: disabledProp = false, readOnly = false, form, name: nameProp, defaultValue = null, value: valueProp, onValueChange: onValueChangeProp, onValueCommitted: onValueCommittedProp, allowWheelScrub = false, snapOnStep = false, allowOutOfRange = false, format, locale, render, className, inputRef: inputRefProp, style, ...elementProps } = componentProps;
|
|
256
|
+
const { setDirty, validityData, disabled: fieldDisabled, setFilled, name: fieldName, state: fieldState, validation } = useFieldRootContext();
|
|
257
|
+
const { clearErrors } = useFormContext();
|
|
321
258
|
const disabled = fieldDisabled || disabledProp;
|
|
322
259
|
const name = fieldName ?? nameProp;
|
|
323
260
|
const step = 'any' === stepProp ? 1 : stepProp;
|
|
@@ -331,13 +268,12 @@ const NumberFieldRoot_NumberFieldRoot = /*#__PURE__*/ __rspack_external_react.fo
|
|
|
331
268
|
const id = useLabelableId({
|
|
332
269
|
id: idProp
|
|
333
270
|
});
|
|
334
|
-
const [
|
|
271
|
+
const [value, setValueUnwrapped] = useControlled({
|
|
335
272
|
controlled: valueProp,
|
|
336
273
|
default: defaultValue,
|
|
337
274
|
name: 'NumberField',
|
|
338
275
|
state: 'value'
|
|
339
276
|
});
|
|
340
|
-
const value = valueUnwrapped ?? null;
|
|
341
277
|
const valueRef = useValueAsRef(value);
|
|
342
278
|
useIsoLayoutEffect(()=>{
|
|
343
279
|
setFilled(null !== value);
|
|
@@ -354,31 +290,25 @@ const NumberFieldRoot_NumberFieldRoot = /*#__PURE__*/ __rspack_external_react.fo
|
|
|
354
290
|
});
|
|
355
291
|
const allowInputSyncRef = __rspack_external_react.useRef(true);
|
|
356
292
|
const lastChangedValueRef = __rspack_external_react.useRef(null);
|
|
357
|
-
const [inputValue, setInputValue] = __rspack_external_react.useState(()=>
|
|
358
|
-
if (void 0 !== valueProp) return getControlledInputValue(value, locale, format);
|
|
359
|
-
return formatNumber(value, locale, format);
|
|
360
|
-
});
|
|
293
|
+
const [inputValue, setInputValue] = __rspack_external_react.useState(()=>formatNumber(value, locale, format));
|
|
361
294
|
const [inputMode, setInputMode] = __rspack_external_react.useState('numeric');
|
|
362
295
|
const getAllowedNonNumericKeys = useStableCallback(()=>{
|
|
363
|
-
const
|
|
364
|
-
const keys = new Set();
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
if (
|
|
370
|
-
|
|
296
|
+
const parts = getFormatParts(locale, format);
|
|
297
|
+
const keys = new Set(BASE_NON_NUMERIC_SYMBOLS);
|
|
298
|
+
const addAll = (chars)=>chars.forEach((char)=>keys.add(char));
|
|
299
|
+
const decimal = parts.find((part)=>'decimal' === part.type)?.value ?? getNumberLocaleDetails(locale, format).decimal;
|
|
300
|
+
keys.add(decimal);
|
|
301
|
+
parts.forEach((part)=>{
|
|
302
|
+
if ('integer' === part.type || 'fraction' === part.type || 'exponentInteger' === part.type || 'compact' === part.type) return;
|
|
303
|
+
addAll(Array.from(part.value));
|
|
304
|
+
if (SPACE_SEPARATOR_RE.test(part.value)) keys.add(' ');
|
|
305
|
+
});
|
|
371
306
|
const allowPercentSymbols = 'percent' === formatStyle || 'unit' === formatStyle && format?.unit === 'percent';
|
|
372
307
|
const allowPermilleSymbols = 'percent' === formatStyle || 'unit' === formatStyle && format?.unit === 'permille';
|
|
373
|
-
if (allowPercentSymbols) PERCENTAGES
|
|
374
|
-
if (allowPermilleSymbols) PERMILLE
|
|
375
|
-
|
|
376
|
-
if (
|
|
377
|
-
Array.from(literal).forEach((char)=>keys.add(char));
|
|
378
|
-
if (SPACE_SEPARATOR_RE.test(literal)) keys.add(' ');
|
|
379
|
-
}
|
|
380
|
-
PLUS_SIGNS_WITH_ASCII.forEach((key)=>keys.add(key));
|
|
381
|
-
if (minWithDefault < 0) MINUS_SIGNS_WITH_ASCII.forEach((key)=>keys.add(key));
|
|
308
|
+
if (allowPercentSymbols) addAll(PERCENTAGES);
|
|
309
|
+
if (allowPermilleSymbols) addAll(PERMILLE);
|
|
310
|
+
addAll(PLUS_SIGNS_WITH_ASCII);
|
|
311
|
+
if (minWithDefault < 0 || allowOutOfRange) addAll(MINUS_SIGNS_WITH_ASCII);
|
|
382
312
|
return keys;
|
|
383
313
|
});
|
|
384
314
|
const getStepAmount = useStableCallback((event)=>{
|
|
@@ -389,67 +319,67 @@ const NumberFieldRoot_NumberFieldRoot = /*#__PURE__*/ __rspack_external_react.fo
|
|
|
389
319
|
const setValue = useStableCallback((unvalidatedValue, details)=>{
|
|
390
320
|
const eventWithOptionalKeyState = details.event;
|
|
391
321
|
const dir = details.direction;
|
|
392
|
-
const
|
|
393
|
-
const shouldClampValue = !allowOutOfRange || !
|
|
394
|
-
const validatedValue = toValidatedNumber(unvalidatedValue,
|
|
395
|
-
step: dir ? getStepAmount(eventWithOptionalKeyState) * dir : void 0,
|
|
396
|
-
format: formatOptionsRef.current,
|
|
397
|
-
minWithDefault,
|
|
398
|
-
maxWithDefault,
|
|
399
|
-
minWithZeroDefault,
|
|
400
|
-
snapOnStep,
|
|
401
|
-
small: eventWithOptionalKeyState?.altKey ?? false,
|
|
402
|
-
clamp: shouldClampValue
|
|
403
|
-
});
|
|
404
|
-
const isInputReason = details.reason === inputChange || details.reason === inputClear || details.reason === inputBlur || details.reason === inputPaste || "none" === details.reason;
|
|
322
|
+
const isInputReason = details.reason.startsWith('input-') || "none" === details.reason;
|
|
323
|
+
const shouldClampValue = !allowOutOfRange || !isInputReason;
|
|
324
|
+
const validatedValue = toValidatedNumber(unvalidatedValue, dir ? getStepAmount(eventWithOptionalKeyState) * dir : void 0, minWithDefault, maxWithDefault, minWithZeroDefault, formatOptionsRef.current, snapOnStep, eventWithOptionalKeyState?.altKey ?? false, shouldClampValue);
|
|
405
325
|
const shouldFireChange = validatedValue !== value || isInputReason && (unvalidatedValue !== value || false === allowInputSyncRef.current);
|
|
406
326
|
if (shouldFireChange) {
|
|
407
|
-
lastChangedValueRef.current = validatedValue;
|
|
408
327
|
onValueChangeProp?.(validatedValue, details);
|
|
409
|
-
if (details.isCanceled) return
|
|
328
|
+
if (details.isCanceled) return false;
|
|
410
329
|
setValueUnwrapped(validatedValue);
|
|
411
330
|
setDirty(validatedValue !== validityData.initialValue);
|
|
412
331
|
hasPendingCommitRef.current = true;
|
|
413
332
|
}
|
|
333
|
+
lastChangedValueRef.current = validatedValue;
|
|
414
334
|
if (allowInputSyncRef.current) setInputValue(formatNumber(validatedValue, locale, format));
|
|
415
335
|
forceRender();
|
|
416
336
|
return shouldFireChange;
|
|
417
337
|
});
|
|
418
338
|
const incrementValue = useStableCallback((amount, { direction, currentValue, event, reason })=>{
|
|
419
339
|
const prevValue = null == currentValue ? valueRef.current : currentValue;
|
|
420
|
-
const nextValue = 'number' == typeof prevValue ? prevValue + amount * direction : Math.max(0, min ?? 0);
|
|
421
340
|
const nativeEvent = event;
|
|
422
|
-
return setValue(
|
|
341
|
+
if ('number' != typeof prevValue) return setValue(0, createChangeEventDetails(reason, nativeEvent));
|
|
342
|
+
return setValue(prevValue + amount * direction, createChangeEventDetails(reason, nativeEvent, void 0, {
|
|
423
343
|
direction
|
|
424
344
|
}));
|
|
425
345
|
});
|
|
426
346
|
useIsoLayoutEffect(function() {
|
|
427
347
|
if (!allowInputSyncRef.current) return;
|
|
428
|
-
const nextInputValue =
|
|
348
|
+
const nextInputValue = formatNumber(value, locale, format);
|
|
429
349
|
if (nextInputValue !== inputValue) setInputValue(nextInputValue);
|
|
430
350
|
});
|
|
431
351
|
useIsoLayoutEffect(function() {
|
|
432
|
-
if (!
|
|
352
|
+
if (!ios) return;
|
|
433
353
|
let computedInputMode = 'text';
|
|
434
354
|
if (minWithDefault >= 0) computedInputMode = 'decimal';
|
|
435
355
|
setInputMode(computedInputMode);
|
|
436
356
|
}, [
|
|
437
|
-
minWithDefault
|
|
438
|
-
formatStyle
|
|
357
|
+
minWithDefault
|
|
439
358
|
]);
|
|
359
|
+
const focusInput = useStableCallback(()=>{
|
|
360
|
+
const input = inputRef.current;
|
|
361
|
+
if (!input) return;
|
|
362
|
+
const length = input.value.length;
|
|
363
|
+
input.setSelectionRange(length, length);
|
|
364
|
+
input.focus();
|
|
365
|
+
});
|
|
440
366
|
__rspack_external_react.useEffect(function() {
|
|
441
367
|
const element = inputRef.current;
|
|
442
368
|
if (disabled || readOnly || !allowWheelScrub || !element) return;
|
|
443
369
|
function handleWheel(event) {
|
|
444
370
|
if (event.ctrlKey || activeElement(ownerDocument(inputRef.current)) !== inputRef.current) return;
|
|
371
|
+
const isHorizontal = Math.abs(event.deltaX) > Math.abs(event.deltaY);
|
|
372
|
+
const delta = event.shiftKey && isHorizontal ? event.deltaX : event.deltaY;
|
|
373
|
+
if (0 === delta || !event.shiftKey && isHorizontal) return;
|
|
445
374
|
event.preventDefault();
|
|
446
375
|
allowInputSyncRef.current = true;
|
|
447
|
-
const amount = getStepAmount(event)
|
|
448
|
-
incrementValue(amount, {
|
|
449
|
-
direction:
|
|
376
|
+
const amount = getStepAmount(event);
|
|
377
|
+
const changed = incrementValue(amount, {
|
|
378
|
+
direction: delta > 0 ? -1 : 1,
|
|
450
379
|
event,
|
|
451
|
-
reason:
|
|
380
|
+
reason: "wheel"
|
|
452
381
|
});
|
|
382
|
+
if (changed) onValueCommitted(lastChangedValueRef.current, createGenericEventDetails("wheel", event));
|
|
453
383
|
}
|
|
454
384
|
return addEventListener(element, 'wheel', handleWheel);
|
|
455
385
|
}, [
|
|
@@ -457,7 +387,10 @@ const NumberFieldRoot_NumberFieldRoot = /*#__PURE__*/ __rspack_external_react.fo
|
|
|
457
387
|
incrementValue,
|
|
458
388
|
disabled,
|
|
459
389
|
readOnly,
|
|
460
|
-
getStepAmount
|
|
390
|
+
getStepAmount,
|
|
391
|
+
onValueCommitted,
|
|
392
|
+
lastChangedValueRef,
|
|
393
|
+
valueRef
|
|
461
394
|
]);
|
|
462
395
|
const state = __rspack_external_react.useMemo(()=>({
|
|
463
396
|
...fieldState,
|
|
@@ -478,12 +411,9 @@ const NumberFieldRoot_NumberFieldRoot = /*#__PURE__*/ __rspack_external_react.fo
|
|
|
478
411
|
]);
|
|
479
412
|
const contextValue = __rspack_external_react.useMemo(()=>({
|
|
480
413
|
inputRef,
|
|
481
|
-
|
|
482
|
-
value,
|
|
414
|
+
focusInput,
|
|
483
415
|
minWithDefault,
|
|
484
416
|
maxWithDefault,
|
|
485
|
-
disabled,
|
|
486
|
-
readOnly,
|
|
487
417
|
id,
|
|
488
418
|
setValue,
|
|
489
419
|
incrementValue,
|
|
@@ -494,26 +424,21 @@ const NumberFieldRoot_NumberFieldRoot = /*#__PURE__*/ __rspack_external_react.fo
|
|
|
494
424
|
lastChangedValueRef,
|
|
495
425
|
hasPendingCommitRef,
|
|
496
426
|
name,
|
|
497
|
-
|
|
498
|
-
invalid,
|
|
427
|
+
nameProp,
|
|
499
428
|
inputMode,
|
|
500
429
|
getAllowedNonNumericKeys,
|
|
501
430
|
min,
|
|
502
431
|
max,
|
|
503
432
|
setInputValue,
|
|
504
433
|
locale,
|
|
505
|
-
isScrubbing,
|
|
506
434
|
setIsScrubbing,
|
|
507
435
|
state,
|
|
508
436
|
onValueCommitted
|
|
509
437
|
}), [
|
|
510
438
|
inputRef,
|
|
511
|
-
|
|
512
|
-
value,
|
|
439
|
+
focusInput,
|
|
513
440
|
minWithDefault,
|
|
514
441
|
maxWithDefault,
|
|
515
|
-
disabled,
|
|
516
|
-
readOnly,
|
|
517
442
|
id,
|
|
518
443
|
setValue,
|
|
519
444
|
incrementValue,
|
|
@@ -521,15 +446,13 @@ const NumberFieldRoot_NumberFieldRoot = /*#__PURE__*/ __rspack_external_react.fo
|
|
|
521
446
|
formatOptionsRef,
|
|
522
447
|
valueRef,
|
|
523
448
|
name,
|
|
524
|
-
|
|
525
|
-
invalid,
|
|
449
|
+
nameProp,
|
|
526
450
|
inputMode,
|
|
527
451
|
getAllowedNonNumericKeys,
|
|
528
452
|
min,
|
|
529
453
|
max,
|
|
530
454
|
setInputValue,
|
|
531
455
|
locale,
|
|
532
|
-
isScrubbing,
|
|
533
456
|
state,
|
|
534
457
|
onValueCommitted
|
|
535
458
|
]);
|
|
@@ -544,18 +467,18 @@ const NumberFieldRoot_NumberFieldRoot = /*#__PURE__*/ __rspack_external_react.fo
|
|
|
544
467
|
children: [
|
|
545
468
|
element,
|
|
546
469
|
/*#__PURE__*/ jsx("input", {
|
|
547
|
-
...validation.
|
|
470
|
+
...validation.getValidationProps(disabled, {
|
|
548
471
|
onFocus () {
|
|
549
|
-
|
|
472
|
+
focusInput();
|
|
550
473
|
},
|
|
551
474
|
onChange (event) {
|
|
552
|
-
if (event.nativeEvent.defaultPrevented || disabled || readOnly) return
|
|
475
|
+
if (event.nativeEvent.defaultPrevented || disabled || readOnly) return;
|
|
553
476
|
const nextValue = event.currentTarget.valueAsNumber;
|
|
554
477
|
const parsedValue = Number.isNaN(nextValue) ? null : nextValue;
|
|
555
478
|
const details = createChangeEventDetails("none", event.nativeEvent);
|
|
556
|
-
setDirty(parsedValue !== validityData.initialValue);
|
|
557
479
|
setValue(parsedValue, details);
|
|
558
|
-
|
|
480
|
+
clearErrors(name);
|
|
481
|
+
validation.change(lastChangedValueRef.current ?? parsedValue);
|
|
559
482
|
}
|
|
560
483
|
}),
|
|
561
484
|
ref: hiddenInputRef,
|
|
@@ -567,6 +490,7 @@ const NumberFieldRoot_NumberFieldRoot = /*#__PURE__*/ __rspack_external_react.fo
|
|
|
567
490
|
max: max,
|
|
568
491
|
step: stepProp,
|
|
569
492
|
disabled: disabled,
|
|
493
|
+
readOnly: readOnly,
|
|
570
494
|
required: required,
|
|
571
495
|
"aria-hidden": true,
|
|
572
496
|
tabIndex: -1,
|
|
@@ -577,10 +501,6 @@ const NumberFieldRoot_NumberFieldRoot = /*#__PURE__*/ __rspack_external_react.fo
|
|
|
577
501
|
});
|
|
578
502
|
});
|
|
579
503
|
if ("production" !== process.env.NODE_ENV) NumberFieldRoot_NumberFieldRoot.displayName = "NumberFieldRoot";
|
|
580
|
-
function getControlledInputValue(value, locale, format) {
|
|
581
|
-
const explicitPrecision = format?.maximumFractionDigits != null || format?.minimumFractionDigits != null;
|
|
582
|
-
return explicitPrecision ? formatNumber(value, locale, format) : formatNumberMaxPrecision(value, locale, format);
|
|
583
|
-
}
|
|
584
504
|
const NumberFieldGroup_NumberFieldGroup = /*#__PURE__*/ __rspack_external_react.forwardRef(function(componentProps, forwardedRef) {
|
|
585
505
|
const { render, className, style, ...elementProps } = componentProps;
|
|
586
506
|
const { state } = useNumberFieldRootContext();
|
|
@@ -598,178 +518,36 @@ const NumberFieldGroup_NumberFieldGroup = /*#__PURE__*/ __rspack_external_react.
|
|
|
598
518
|
return element;
|
|
599
519
|
});
|
|
600
520
|
if ("production" !== process.env.NODE_ENV) NumberFieldGroup_NumberFieldGroup.displayName = "NumberFieldGroup";
|
|
601
|
-
const
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
}
|
|
612
|
-
clear = ()=>{
|
|
613
|
-
if (this.currentId !== EMPTY) {
|
|
614
|
-
clearInterval(this.currentId);
|
|
615
|
-
this.currentId = EMPTY;
|
|
616
|
-
}
|
|
617
|
-
};
|
|
618
|
-
}
|
|
619
|
-
function useInterval() {
|
|
620
|
-
const timeout = useRefWithInit(Interval.create).current;
|
|
621
|
-
useOnMount(timeout.disposeEffect);
|
|
622
|
-
return timeout;
|
|
623
|
-
}
|
|
624
|
-
const DEFAULT_TICK_DELAY = 60;
|
|
625
|
-
const DEFAULT_START_DELAY = 400;
|
|
626
|
-
const DEFAULT_SCROLL_DISTANCE = 8;
|
|
627
|
-
const TOUCH_TIMEOUT = 50;
|
|
628
|
-
const MAX_POINTER_MOVES_AFTER_TOUCH = 3;
|
|
629
|
-
function isTouchLikePointerType(pointerType) {
|
|
630
|
-
return 'touch' === pointerType || 'pen' === pointerType;
|
|
631
|
-
}
|
|
632
|
-
function usePressAndHold(params) {
|
|
633
|
-
const { disabled, readOnly = false, tick, onStop, tickDelay = DEFAULT_TICK_DELAY, startDelay = DEFAULT_START_DELAY, scrollDistance = DEFAULT_SCROLL_DISTANCE, elementRef } = params;
|
|
634
|
-
const startTickTimeout = useTimeout();
|
|
635
|
-
const tickInterval = useInterval();
|
|
636
|
-
const intentionalTouchCheckTimeout = useTimeout();
|
|
637
|
-
const isPressedRef = __rspack_external_react.useRef(false);
|
|
638
|
-
const movesAfterTouchRef = __rspack_external_react.useRef(0);
|
|
639
|
-
const downCoordsRef = __rspack_external_react.useRef({
|
|
640
|
-
x: 0,
|
|
641
|
-
y: 0
|
|
642
|
-
});
|
|
643
|
-
const isTouchingButtonRef = __rspack_external_react.useRef(false);
|
|
644
|
-
const ignoreClickRef = __rspack_external_react.useRef(false);
|
|
645
|
-
const pointerTypeRef = __rspack_external_react.useRef('');
|
|
646
|
-
const unsubscribeFromGlobalContextMenuRef = __rspack_external_react.useRef(()=>{});
|
|
647
|
-
const stopAutoChange = useStableCallback(()=>{
|
|
648
|
-
intentionalTouchCheckTimeout.clear();
|
|
649
|
-
startTickTimeout.clear();
|
|
650
|
-
tickInterval.clear();
|
|
651
|
-
unsubscribeFromGlobalContextMenuRef.current();
|
|
652
|
-
movesAfterTouchRef.current = 0;
|
|
653
|
-
});
|
|
654
|
-
function startAutoChange(triggerNativeEvent) {
|
|
655
|
-
stopAutoChange();
|
|
656
|
-
const element = elementRef.current;
|
|
657
|
-
if (!element) return;
|
|
658
|
-
const win = getWindow(element);
|
|
659
|
-
function handleContextMenu(event) {
|
|
660
|
-
event.preventDefault();
|
|
661
|
-
}
|
|
662
|
-
unsubscribeFromGlobalContextMenuRef.current = addEventListener(win, 'contextmenu', handleContextMenu);
|
|
663
|
-
addEventListener(win, 'pointerup', (event)=>{
|
|
664
|
-
isPressedRef.current = false;
|
|
665
|
-
stopAutoChange();
|
|
666
|
-
onStop?.(event);
|
|
667
|
-
}, {
|
|
668
|
-
once: true
|
|
669
|
-
});
|
|
670
|
-
if (!tick(triggerNativeEvent)) return void stopAutoChange();
|
|
671
|
-
startTickTimeout.start(startDelay, ()=>{
|
|
672
|
-
tickInterval.start(tickDelay, ()=>{
|
|
673
|
-
if (!tick(triggerNativeEvent)) stopAutoChange();
|
|
674
|
-
});
|
|
675
|
-
});
|
|
676
|
-
}
|
|
677
|
-
__rspack_external_react.useEffect(()=>()=>stopAutoChange(), [
|
|
678
|
-
stopAutoChange
|
|
679
|
-
]);
|
|
680
|
-
const pointerHandlers = {
|
|
681
|
-
onTouchStart () {
|
|
682
|
-
isTouchingButtonRef.current = true;
|
|
683
|
-
},
|
|
684
|
-
onTouchEnd () {
|
|
685
|
-
isTouchingButtonRef.current = false;
|
|
686
|
-
},
|
|
687
|
-
onPointerDown (event) {
|
|
688
|
-
const isMainButton = !event.button || 0 === event.button;
|
|
689
|
-
if (event.defaultPrevented || !isMainButton || disabled || readOnly) return;
|
|
690
|
-
pointerTypeRef.current = event.pointerType;
|
|
691
|
-
ignoreClickRef.current = false;
|
|
692
|
-
isPressedRef.current = true;
|
|
693
|
-
downCoordsRef.current = {
|
|
694
|
-
x: event.clientX,
|
|
695
|
-
y: event.clientY
|
|
696
|
-
};
|
|
697
|
-
const isTouchPointer = isTouchLikePointerType(event.pointerType);
|
|
698
|
-
if (isTouchPointer) intentionalTouchCheckTimeout.start(TOUCH_TIMEOUT, ()=>{
|
|
699
|
-
const moves = movesAfterTouchRef.current;
|
|
700
|
-
movesAfterTouchRef.current = 0;
|
|
701
|
-
const stillPressed = isPressedRef.current;
|
|
702
|
-
if (stillPressed && moves < MAX_POINTER_MOVES_AFTER_TOUCH) {
|
|
703
|
-
startAutoChange(event.nativeEvent);
|
|
704
|
-
ignoreClickRef.current = true;
|
|
705
|
-
} else {
|
|
706
|
-
ignoreClickRef.current = false;
|
|
707
|
-
stopAutoChange();
|
|
708
|
-
}
|
|
709
|
-
});
|
|
710
|
-
else {
|
|
711
|
-
event.preventDefault();
|
|
712
|
-
startAutoChange(event.nativeEvent);
|
|
713
|
-
}
|
|
714
|
-
},
|
|
715
|
-
onPointerUp (event) {
|
|
716
|
-
if (isTouchLikePointerType(event.pointerType)) isPressedRef.current = false;
|
|
717
|
-
},
|
|
718
|
-
onPointerMove (event) {
|
|
719
|
-
if (disabled || readOnly || !isTouchLikePointerType(event.pointerType) || !isPressedRef.current) return;
|
|
720
|
-
if (null != movesAfterTouchRef.current) movesAfterTouchRef.current += 1;
|
|
721
|
-
const { x, y } = downCoordsRef.current;
|
|
722
|
-
const dx = x - event.clientX;
|
|
723
|
-
const dy = y - event.clientY;
|
|
724
|
-
if (dx ** 2 + dy ** 2 > scrollDistance ** 2) stopAutoChange();
|
|
725
|
-
},
|
|
726
|
-
onMouseEnter (event) {
|
|
727
|
-
if (event.defaultPrevented || disabled || readOnly || !isPressedRef.current || isTouchingButtonRef.current || isTouchLikePointerType(pointerTypeRef.current)) return;
|
|
728
|
-
startAutoChange(event.nativeEvent);
|
|
729
|
-
},
|
|
730
|
-
onMouseLeave () {
|
|
731
|
-
if (isTouchingButtonRef.current) return;
|
|
732
|
-
stopAutoChange();
|
|
733
|
-
},
|
|
734
|
-
onMouseUp () {
|
|
735
|
-
if (isTouchingButtonRef.current) return;
|
|
736
|
-
stopAutoChange();
|
|
737
|
-
}
|
|
738
|
-
};
|
|
739
|
-
const shouldSkipClick = useStableCallback((event)=>{
|
|
740
|
-
if (event.defaultPrevented) return true;
|
|
741
|
-
if (isTouchLikePointerType(pointerTypeRef.current)) return ignoreClickRef.current;
|
|
742
|
-
return 0 !== event.detail;
|
|
743
|
-
});
|
|
744
|
-
return {
|
|
745
|
-
pointerHandlers,
|
|
746
|
-
shouldSkipClick
|
|
747
|
-
};
|
|
748
|
-
}
|
|
749
|
-
function useNumberFieldButton_isTouchLikePointerType(pointerType) {
|
|
750
|
-
return 'touch' === pointerType || 'pen' === pointerType;
|
|
751
|
-
}
|
|
752
|
-
function useNumberFieldButton(params) {
|
|
753
|
-
const { allowInputSyncRef, disabled, formatOptionsRef, getStepAmount, id, incrementValue, inputRef, inputValue, isIncrement, locale, readOnly, setValue, valueRef, lastChangedValueRef, onValueCommitted } = params;
|
|
521
|
+
const SELECT_NONE_STYLE = {
|
|
522
|
+
WebkitUserSelect: 'none',
|
|
523
|
+
userSelect: 'none'
|
|
524
|
+
};
|
|
525
|
+
function useNumberFieldStepperButton(componentProps, forwardedRef, isIncrement) {
|
|
526
|
+
const { render, className, disabled: disabledProp = false, nativeButton = true, style, ...elementProps } = componentProps;
|
|
527
|
+
const { allowInputSyncRef, formatOptionsRef, getStepAmount, id, incrementValue, inputRef, focusInput, maxWithDefault, minWithDefault, setValue, state, valueRef, locale, lastChangedValueRef, onValueCommitted } = useNumberFieldRootContext();
|
|
528
|
+
const { disabled: contextDisabled, readOnly, value, inputValue } = state;
|
|
529
|
+
const isAtBoundary = null != value && (isIncrement ? value >= maxWithDefault : value <= minWithDefault);
|
|
530
|
+
const disabled = disabledProp || contextDisabled || isAtBoundary;
|
|
754
531
|
const pressReason = isIncrement ? incrementPress : decrementPress;
|
|
755
532
|
function commitValue(nativeEvent) {
|
|
533
|
+
const shouldCommitInputValue = !allowInputSyncRef.current;
|
|
756
534
|
allowInputSyncRef.current = true;
|
|
535
|
+
if (!shouldCommitInputValue) {
|
|
536
|
+
lastChangedValueRef.current = valueRef.current;
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
757
539
|
const parsedValue = parseNumber(inputValue, locale, formatOptionsRef.current);
|
|
758
540
|
if (null !== parsedValue) {
|
|
759
|
-
|
|
760
|
-
setValue(parsedValue,
|
|
761
|
-
|
|
762
|
-
}));
|
|
541
|
+
const details = createChangeEventDetails(pressReason, nativeEvent);
|
|
542
|
+
setValue(parsedValue, details);
|
|
543
|
+
if (!details.isCanceled) valueRef.current = parsedValue;
|
|
763
544
|
}
|
|
764
545
|
}
|
|
765
546
|
const { pointerHandlers, shouldSkipClick } = usePressAndHold({
|
|
766
547
|
disabled: disabled || readOnly,
|
|
767
548
|
elementRef: inputRef,
|
|
768
|
-
tickDelay: 60,
|
|
769
|
-
startDelay: 400,
|
|
770
|
-
scrollDistance: 8,
|
|
771
549
|
tick (triggerEvent) {
|
|
772
|
-
const amount = getStepAmount(triggerEvent)
|
|
550
|
+
const amount = getStepAmount(triggerEvent);
|
|
773
551
|
return incrementValue(amount, {
|
|
774
552
|
direction: isIncrement ? 1 : -1,
|
|
775
553
|
event: triggerEvent,
|
|
@@ -783,20 +561,16 @@ function useNumberFieldButton(params) {
|
|
|
783
561
|
});
|
|
784
562
|
const props = {
|
|
785
563
|
disabled,
|
|
786
|
-
'aria-readonly': readOnly || void 0,
|
|
787
564
|
'aria-label': isIncrement ? 'Increase' : 'Decrease',
|
|
788
565
|
'aria-controls': id,
|
|
789
566
|
tabIndex: -1,
|
|
790
|
-
style:
|
|
791
|
-
WebkitUserSelect: 'none',
|
|
792
|
-
userSelect: 'none'
|
|
793
|
-
},
|
|
567
|
+
style: SELECT_NONE_STYLE,
|
|
794
568
|
...pointerHandlers,
|
|
795
569
|
onClick (event) {
|
|
796
570
|
const isDisabled = disabled || readOnly;
|
|
797
571
|
if (event.defaultPrevented || isDisabled || shouldSkipClick(event)) return;
|
|
798
572
|
commitValue(event.nativeEvent);
|
|
799
|
-
const amount = getStepAmount(event)
|
|
573
|
+
const amount = getStepAmount(event);
|
|
800
574
|
const prev = valueRef.current;
|
|
801
575
|
incrementValue(amount, {
|
|
802
576
|
direction: isIncrement ? 1 : -1,
|
|
@@ -807,50 +581,23 @@ function useNumberFieldButton(params) {
|
|
|
807
581
|
if (committed !== prev) onValueCommitted(committed, createGenericEventDetails(pressReason, event.nativeEvent));
|
|
808
582
|
},
|
|
809
583
|
onPointerDown (event) {
|
|
810
|
-
|
|
811
|
-
if (event.defaultPrevented || readOnly || !isMainButton || disabled) return;
|
|
584
|
+
if (event.defaultPrevented || readOnly || event.button || disabled) return;
|
|
812
585
|
commitValue(event.nativeEvent);
|
|
813
|
-
|
|
586
|
+
lastChangedValueRef.current = null;
|
|
587
|
+
if (!isTouchLikePointerType(event.pointerType)) focusInput();
|
|
814
588
|
pointerHandlers.onPointerDown(event);
|
|
815
589
|
}
|
|
816
590
|
};
|
|
817
|
-
return props;
|
|
818
|
-
}
|
|
819
|
-
const NumberFieldIncrement_NumberFieldIncrement = /*#__PURE__*/ __rspack_external_react.forwardRef(function(componentProps, forwardedRef) {
|
|
820
|
-
const { render, className, disabled: disabledProp = false, nativeButton = true, style, ...elementProps } = componentProps;
|
|
821
|
-
const { allowInputSyncRef, disabled: contextDisabled, formatOptionsRef, getStepAmount, id, incrementValue, inputRef, inputValue, locale, maxWithDefault, readOnly, setValue, state, value, valueRef, lastChangedValueRef, onValueCommitted } = useNumberFieldRootContext();
|
|
822
|
-
const isMax = null != value && value >= maxWithDefault;
|
|
823
|
-
const disabled = disabledProp || contextDisabled || isMax;
|
|
824
|
-
const props = useNumberFieldButton({
|
|
825
|
-
isIncrement: true,
|
|
826
|
-
inputRef,
|
|
827
|
-
inputValue,
|
|
828
|
-
disabled,
|
|
829
|
-
readOnly,
|
|
830
|
-
id,
|
|
831
|
-
setValue,
|
|
832
|
-
getStepAmount,
|
|
833
|
-
incrementValue,
|
|
834
|
-
allowInputSyncRef,
|
|
835
|
-
formatOptionsRef,
|
|
836
|
-
valueRef,
|
|
837
|
-
locale,
|
|
838
|
-
lastChangedValueRef,
|
|
839
|
-
onValueCommitted
|
|
840
|
-
});
|
|
841
591
|
const { getButtonProps, buttonRef } = useButton({
|
|
842
|
-
disabled,
|
|
592
|
+
disabled: disabled || readOnly,
|
|
843
593
|
native: nativeButton,
|
|
844
594
|
focusableWhenDisabled: true
|
|
845
595
|
});
|
|
846
|
-
const buttonState =
|
|
847
|
-
|
|
848
|
-
disabled
|
|
849
|
-
}), [
|
|
850
|
-
state,
|
|
596
|
+
const buttonState = {
|
|
597
|
+
...state,
|
|
851
598
|
disabled
|
|
852
|
-
|
|
853
|
-
|
|
599
|
+
};
|
|
600
|
+
return useRenderElement('button', componentProps, {
|
|
854
601
|
ref: [
|
|
855
602
|
forwardedRef,
|
|
856
603
|
buttonRef
|
|
@@ -863,63 +610,15 @@ const NumberFieldIncrement_NumberFieldIncrement = /*#__PURE__*/ __rspack_externa
|
|
|
863
610
|
],
|
|
864
611
|
stateAttributesMapping: stateAttributesMapping
|
|
865
612
|
});
|
|
866
|
-
|
|
613
|
+
}
|
|
614
|
+
const NumberFieldIncrement_NumberFieldIncrement = /*#__PURE__*/ __rspack_external_react.forwardRef(function(componentProps, forwardedRef) {
|
|
615
|
+
return useNumberFieldStepperButton(componentProps, forwardedRef, true);
|
|
867
616
|
});
|
|
868
617
|
if ("production" !== process.env.NODE_ENV) NumberFieldIncrement_NumberFieldIncrement.displayName = "NumberFieldIncrement";
|
|
869
618
|
const NumberFieldDecrement_NumberFieldDecrement = /*#__PURE__*/ __rspack_external_react.forwardRef(function(componentProps, forwardedRef) {
|
|
870
|
-
|
|
871
|
-
const { allowInputSyncRef, disabled: contextDisabled, formatOptionsRef, getStepAmount, id, incrementValue, inputRef, inputValue, minWithDefault, readOnly, setValue, state, value, valueRef, locale, lastChangedValueRef, onValueCommitted } = useNumberFieldRootContext();
|
|
872
|
-
const isMin = null != value && value <= minWithDefault;
|
|
873
|
-
const disabled = disabledProp || contextDisabled || isMin;
|
|
874
|
-
const props = useNumberFieldButton({
|
|
875
|
-
isIncrement: false,
|
|
876
|
-
inputRef,
|
|
877
|
-
inputValue,
|
|
878
|
-
disabled,
|
|
879
|
-
readOnly,
|
|
880
|
-
id,
|
|
881
|
-
setValue,
|
|
882
|
-
getStepAmount,
|
|
883
|
-
incrementValue,
|
|
884
|
-
allowInputSyncRef,
|
|
885
|
-
formatOptionsRef,
|
|
886
|
-
valueRef,
|
|
887
|
-
locale,
|
|
888
|
-
lastChangedValueRef,
|
|
889
|
-
onValueCommitted
|
|
890
|
-
});
|
|
891
|
-
const { getButtonProps, buttonRef } = useButton({
|
|
892
|
-
disabled,
|
|
893
|
-
native: nativeButton,
|
|
894
|
-
focusableWhenDisabled: true
|
|
895
|
-
});
|
|
896
|
-
const buttonState = __rspack_external_react.useMemo(()=>({
|
|
897
|
-
...state,
|
|
898
|
-
disabled
|
|
899
|
-
}), [
|
|
900
|
-
state,
|
|
901
|
-
disabled
|
|
902
|
-
]);
|
|
903
|
-
const element = useRenderElement('button', componentProps, {
|
|
904
|
-
ref: [
|
|
905
|
-
forwardedRef,
|
|
906
|
-
buttonRef
|
|
907
|
-
],
|
|
908
|
-
state: buttonState,
|
|
909
|
-
props: [
|
|
910
|
-
props,
|
|
911
|
-
elementProps,
|
|
912
|
-
getButtonProps
|
|
913
|
-
],
|
|
914
|
-
stateAttributesMapping: stateAttributesMapping
|
|
915
|
-
});
|
|
916
|
-
return element;
|
|
619
|
+
return useNumberFieldStepperButton(componentProps, forwardedRef, false);
|
|
917
620
|
});
|
|
918
621
|
if ("production" !== process.env.NODE_ENV) NumberFieldDecrement_NumberFieldDecrement.displayName = "NumberFieldDecrement";
|
|
919
|
-
const NumberFieldInput_stateAttributesMapping = {
|
|
920
|
-
...fieldValidityMapping,
|
|
921
|
-
...stateAttributesMapping
|
|
922
|
-
};
|
|
923
622
|
const NAVIGATE_KEYS = new Set([
|
|
924
623
|
'Backspace',
|
|
925
624
|
'Delete',
|
|
@@ -931,23 +630,29 @@ const NAVIGATE_KEYS = new Set([
|
|
|
931
630
|
]);
|
|
932
631
|
const NumberFieldInput_NumberFieldInput = /*#__PURE__*/ __rspack_external_react.forwardRef(function(componentProps, forwardedRef) {
|
|
933
632
|
const { render, className, style, ...elementProps } = componentProps;
|
|
934
|
-
const { allowInputSyncRef,
|
|
633
|
+
const { allowInputSyncRef, formatOptionsRef, getAllowedNonNumericKeys, getStepAmount, id, incrementValue, inputMode, max, min, name, nameProp, setValue, state, setInputValue, locale, inputRef, onValueCommitted, lastChangedValueRef, hasPendingCommitRef, valueRef } = useNumberFieldRootContext();
|
|
634
|
+
const { disabled, readOnly, required, value, inputValue } = state;
|
|
935
635
|
const { clearErrors } = useFormContext();
|
|
936
|
-
const { validationMode, setTouched,
|
|
636
|
+
const { validationMode, setTouched, invalid, shouldValidateOnChange, validation } = useFieldRootContext();
|
|
937
637
|
const { labelId } = useLabelableContext();
|
|
938
|
-
const
|
|
638
|
+
const setFocused = useSetFieldFocused(disabled, inputRef);
|
|
939
639
|
const blockRevalidationRef = __rspack_external_react.useRef(false);
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
640
|
+
const pendingCaretRef = __rspack_external_react.useRef(null);
|
|
641
|
+
useRegisterFieldControl(inputRef, id, value, void 0, !disabled, nameProp);
|
|
642
|
+
useIsoLayoutEffect(()=>{
|
|
643
|
+
if (null != pendingCaretRef.current) {
|
|
644
|
+
const caret = pendingCaretRef.current;
|
|
645
|
+
pendingCaretRef.current = null;
|
|
646
|
+
inputRef.current?.setSelectionRange(caret, caret);
|
|
647
|
+
}
|
|
648
|
+
});
|
|
649
|
+
useValueChanged(value, ()=>{
|
|
943
650
|
clearErrors(name);
|
|
944
|
-
if (
|
|
945
|
-
if (previousValue === value || validateOnChange) return;
|
|
946
|
-
if (blockRevalidationRef.current) {
|
|
651
|
+
if (blockRevalidationRef.current && !shouldValidateOnChange()) {
|
|
947
652
|
blockRevalidationRef.current = false;
|
|
948
653
|
return;
|
|
949
654
|
}
|
|
950
|
-
validation.
|
|
655
|
+
validation.change(value);
|
|
951
656
|
});
|
|
952
657
|
const inputProps = {
|
|
953
658
|
id,
|
|
@@ -961,49 +666,54 @@ const NumberFieldInput_NumberFieldInput = /*#__PURE__*/ __rspack_external_react.
|
|
|
961
666
|
autoCorrect: 'off',
|
|
962
667
|
spellCheck: 'false',
|
|
963
668
|
"aria-roledescription": 'Number field',
|
|
964
|
-
'aria-invalid': invalid
|
|
669
|
+
'aria-invalid': !disabled && invalid ? true : void 0,
|
|
965
670
|
'aria-labelledby': labelId,
|
|
966
671
|
suppressHydrationWarning: true,
|
|
967
672
|
onFocus (event) {
|
|
968
|
-
if (event.defaultPrevented ||
|
|
673
|
+
if (event.defaultPrevented || disabled) return;
|
|
969
674
|
setFocused(true);
|
|
970
|
-
if (hasTouchedInputRef.current) return;
|
|
971
|
-
hasTouchedInputRef.current = true;
|
|
972
|
-
const target = event.currentTarget;
|
|
973
|
-
const length = target.value.length;
|
|
974
|
-
target.setSelectionRange(length, length);
|
|
975
675
|
},
|
|
976
676
|
onBlur (event) {
|
|
977
|
-
if (event.defaultPrevented ||
|
|
677
|
+
if (event.defaultPrevented || disabled) return;
|
|
978
678
|
setTouched(true);
|
|
979
679
|
setFocused(false);
|
|
680
|
+
if (readOnly) return;
|
|
980
681
|
const hadManualInput = !allowInputSyncRef.current;
|
|
981
682
|
const hadPendingProgrammaticChange = hasPendingCommitRef.current;
|
|
982
683
|
allowInputSyncRef.current = true;
|
|
983
684
|
if ('' === inputValue.trim()) {
|
|
984
|
-
|
|
685
|
+
const clearDetails = createChangeEventDetails(inputClear, event.nativeEvent);
|
|
686
|
+
setValue(null, clearDetails);
|
|
687
|
+
if (clearDetails.isCanceled) return;
|
|
985
688
|
if ('onBlur' === validationMode) validation.commit(null);
|
|
986
|
-
onValueCommitted(null, createGenericEventDetails(inputClear, event.nativeEvent));
|
|
689
|
+
if (hadManualInput || hadPendingProgrammaticChange || null !== value) onValueCommitted(null, createGenericEventDetails(inputClear, event.nativeEvent));
|
|
987
690
|
return;
|
|
988
691
|
}
|
|
989
692
|
const formatOptions = formatOptionsRef.current;
|
|
990
693
|
const parsedValue = parseNumber(inputValue, locale, formatOptions);
|
|
991
694
|
if (null === parsedValue) return;
|
|
992
|
-
const
|
|
993
|
-
|
|
994
|
-
|
|
695
|
+
const hasRoundingOptions = hasNumberFormatRoundingOptions(formatOptions);
|
|
696
|
+
let committed;
|
|
697
|
+
committed = hadManualInput || hasRoundingOptions ? hasRoundingOptions ? removeFloatingPointErrors(parsedValue, formatOptions) : parsedValue : value;
|
|
995
698
|
const nextEventDetails = createGenericEventDetails(inputBlur, event.nativeEvent);
|
|
996
699
|
const shouldUpdateValue = value !== committed;
|
|
997
700
|
const shouldCommit = hadManualInput || shouldUpdateValue || hadPendingProgrammaticChange;
|
|
998
|
-
|
|
701
|
+
let committedValue = committed;
|
|
999
702
|
if (shouldUpdateValue) {
|
|
703
|
+
const changeDetails = createChangeEventDetails(inputBlur, event.nativeEvent);
|
|
1000
704
|
blockRevalidationRef.current = true;
|
|
1001
|
-
setValue(committed,
|
|
705
|
+
setValue(committed, changeDetails);
|
|
706
|
+
if (changeDetails.isCanceled) {
|
|
707
|
+
blockRevalidationRef.current = false;
|
|
708
|
+
return;
|
|
709
|
+
}
|
|
710
|
+
committedValue = lastChangedValueRef.current;
|
|
711
|
+
if (committedValue === value) blockRevalidationRef.current = false;
|
|
1002
712
|
}
|
|
1003
|
-
if (
|
|
1004
|
-
|
|
1005
|
-
const
|
|
1006
|
-
if (
|
|
713
|
+
if ('onBlur' === validationMode) validation.commit(committedValue);
|
|
714
|
+
if (shouldCommit) onValueCommitted(committedValue, nextEventDetails);
|
|
715
|
+
const canonicalText = formatNumber(committedValue, locale, formatOptions);
|
|
716
|
+
if (inputValue !== canonicalText) setInputValue(canonicalText);
|
|
1007
717
|
},
|
|
1008
718
|
onChange (event) {
|
|
1009
719
|
if (event.nativeEvent.defaultPrevented) return;
|
|
@@ -1015,15 +725,7 @@ const NumberFieldInput_NumberFieldInput = /*#__PURE__*/ __rspack_external_react.
|
|
|
1015
725
|
return;
|
|
1016
726
|
}
|
|
1017
727
|
const allowedNonNumericKeys = getAllowedNonNumericKeys();
|
|
1018
|
-
const isValidCharacterString = Array.from(targetValue).every((ch)=>
|
|
1019
|
-
const isAsciiDigit = ch >= '0' && ch <= '9';
|
|
1020
|
-
const isArabicNumeral = ARABIC_DETECT_RE.test(ch);
|
|
1021
|
-
const isHanNumeral = HAN_DETECT_RE.test(ch);
|
|
1022
|
-
const isPersianNumeral = PERSIAN_DETECT_RE.test(ch);
|
|
1023
|
-
const isFullwidthNumeral = FULLWIDTH_DETECT_RE.test(ch);
|
|
1024
|
-
const isMinus = ANY_MINUS_DETECT_RE.test(ch);
|
|
1025
|
-
return isAsciiDigit || isArabicNumeral || isHanNumeral || isPersianNumeral || isFullwidthNumeral || isMinus || allowedNonNumericKeys.has(ch);
|
|
1026
|
-
});
|
|
728
|
+
const isValidCharacterString = Array.from(targetValue).every((ch)=>isNumeralChar(ch) || ANY_MINUS_DETECT_RE.test(ch) || allowedNonNumericKeys.has(ch) || FORMAT_CONTROL_DETECT_RE.test(ch));
|
|
1027
729
|
if (!isValidCharacterString) return;
|
|
1028
730
|
const parsedValue = parseNumber(targetValue, locale, formatOptionsRef.current);
|
|
1029
731
|
setInputValue(targetValue);
|
|
@@ -1032,7 +734,7 @@ const NumberFieldInput_NumberFieldInput = /*#__PURE__*/ __rspack_external_react.
|
|
|
1032
734
|
onKeyDown (event) {
|
|
1033
735
|
if (event.defaultPrevented || readOnly || disabled) return;
|
|
1034
736
|
const nativeEvent = event.nativeEvent;
|
|
1035
|
-
allowInputSyncRef.current
|
|
737
|
+
const hadManualInput = !allowInputSyncRef.current;
|
|
1036
738
|
const allowedNonNumericKeys = getAllowedNonNumericKeys();
|
|
1037
739
|
let isAllowedNonNumericKey = allowedNonNumericKeys.has(event.key);
|
|
1038
740
|
const { decimal, currency, percentSign } = getNumberLocaleDetails(locale, formatOptionsRef.current);
|
|
@@ -1040,16 +742,23 @@ const NumberFieldInput_NumberFieldInput = /*#__PURE__*/ __rspack_external_react.
|
|
|
1040
742
|
const selectionEnd = event.currentTarget.selectionEnd;
|
|
1041
743
|
const isAllSelected = 0 === selectionStart && selectionEnd === inputValue.length;
|
|
1042
744
|
const selectionContainsIndex = (index)=>null != selectionStart && null != selectionEnd && index >= selectionStart && index < selectionEnd;
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
745
|
+
const signGroups = [
|
|
746
|
+
[
|
|
747
|
+
ANY_MINUS_DETECT_RE,
|
|
748
|
+
ANY_MINUS_RE
|
|
749
|
+
],
|
|
750
|
+
[
|
|
751
|
+
ANY_PLUS_DETECT_RE,
|
|
752
|
+
ANY_PLUS_RE
|
|
753
|
+
]
|
|
754
|
+
];
|
|
755
|
+
signGroups.forEach(([detectRe, globalRe])=>{
|
|
756
|
+
if (detectRe.test(event.key) && Array.from(allowedNonNumericKeys).some((k)=>detectRe.test(k))) {
|
|
757
|
+
const existingIndex = inputValue.search(globalRe);
|
|
758
|
+
const isReplacingExisting = -1 !== existingIndex && selectionContainsIndex(existingIndex);
|
|
759
|
+
isAllowedNonNumericKey = !(ANY_MINUS_DETECT_RE.test(inputValue) || ANY_PLUS_DETECT_RE.test(inputValue)) || isAllSelected || isReplacingExisting;
|
|
760
|
+
}
|
|
761
|
+
});
|
|
1053
762
|
[
|
|
1054
763
|
decimal,
|
|
1055
764
|
currency,
|
|
@@ -1058,54 +767,57 @@ const NumberFieldInput_NumberFieldInput = /*#__PURE__*/ __rspack_external_react.
|
|
|
1058
767
|
if (event.key === symbol) {
|
|
1059
768
|
const symbolIndex = inputValue.indexOf(symbol);
|
|
1060
769
|
const isSymbolHighlighted = selectionContainsIndex(symbolIndex);
|
|
1061
|
-
isAllowedNonNumericKey =
|
|
770
|
+
isAllowedNonNumericKey = -1 === symbolIndex || isAllSelected || isSymbolHighlighted;
|
|
1062
771
|
}
|
|
1063
772
|
});
|
|
1064
|
-
const isAsciiDigit = event.key >= '0' && event.key <= '9';
|
|
1065
|
-
const isArabicNumeral = ARABIC_DETECT_RE.test(event.key);
|
|
1066
|
-
const isHanNumeral = HAN_DETECT_RE.test(event.key);
|
|
1067
|
-
const isPersianNumeral = PERSIAN_DETECT_RE.test(event.key);
|
|
1068
|
-
const isFullwidthNumeral = FULLWIDTH_DETECT_RE.test(event.key);
|
|
1069
773
|
const isNavigateKey = NAVIGATE_KEYS.has(event.key);
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
774
|
+
const isStepKey = 'ArrowUp' === event.key || 'ArrowDown' === event.key;
|
|
775
|
+
if (229 === event.which || event.altKey && !isStepKey || event.ctrlKey || event.metaKey || isAllowedNonNumericKey || isNumeralChar(event.key) || isNavigateKey) return;
|
|
776
|
+
let boundaryValue = null;
|
|
777
|
+
if ('Home' === event.key && null != min) boundaryValue = min;
|
|
778
|
+
else if ('End' === event.key && null != max) boundaryValue = max;
|
|
779
|
+
if (event.key.length > 1 && !isStepKey && null === boundaryValue) return;
|
|
780
|
+
const currentValue = hadManualInput ? parseNumber(inputValue, locale, formatOptionsRef.current) : null;
|
|
781
|
+
const amount = getStepAmount(event);
|
|
782
|
+
event.preventDefault();
|
|
783
|
+
event.stopPropagation();
|
|
1074
784
|
const commitDetails = createGenericEventDetails(keyboard, nativeEvent);
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
onValueCommitted(lastChangedValueRef.current ?? valueRef.current, commitDetails);
|
|
1083
|
-
} else if ('ArrowDown' === event.key) {
|
|
1084
|
-
incrementValue(amount, {
|
|
1085
|
-
direction: -1,
|
|
1086
|
-
currentValue: parsedValue,
|
|
785
|
+
let changed = false;
|
|
786
|
+
if (isStepKey || null !== boundaryValue) allowInputSyncRef.current = true;
|
|
787
|
+
if (isStepKey) {
|
|
788
|
+
if (!hadManualInput) lastChangedValueRef.current = valueRef.current;
|
|
789
|
+
changed = incrementValue(amount, {
|
|
790
|
+
direction: 'ArrowUp' === event.key ? 1 : -1,
|
|
791
|
+
currentValue,
|
|
1087
792
|
event: nativeEvent,
|
|
1088
793
|
reason: keyboard
|
|
1089
794
|
});
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
setValue(min, createChangeEventDetails(keyboard, nativeEvent));
|
|
1093
|
-
onValueCommitted(lastChangedValueRef.current ?? valueRef.current, commitDetails);
|
|
1094
|
-
} else if ('End' === event.key && null != max) {
|
|
1095
|
-
setValue(max, createChangeEventDetails(keyboard, nativeEvent));
|
|
1096
|
-
onValueCommitted(lastChangedValueRef.current ?? valueRef.current, commitDetails);
|
|
1097
|
-
}
|
|
795
|
+
} else if (null !== boundaryValue) changed = setValue(boundaryValue, createChangeEventDetails(keyboard, nativeEvent));
|
|
796
|
+
if (changed) onValueCommitted(lastChangedValueRef.current, commitDetails);
|
|
1098
797
|
},
|
|
1099
798
|
onPaste (event) {
|
|
1100
799
|
if (event.defaultPrevented || readOnly || disabled) return;
|
|
800
|
+
let pastedData = '';
|
|
801
|
+
try {
|
|
802
|
+
pastedData = event.clipboardData?.getData('text/plain') ?? '';
|
|
803
|
+
} catch {
|
|
804
|
+
if ('production' !== process.env.NODE_ENV) {
|
|
805
|
+
const ownerStackMessage = SafeReact.captureOwnerStack?.() || '';
|
|
806
|
+
warn('<NumberField.Input> could not read clipboard text during paste handling.', ownerStackMessage);
|
|
807
|
+
}
|
|
808
|
+
return;
|
|
809
|
+
}
|
|
1101
810
|
event.preventDefault();
|
|
1102
|
-
const
|
|
1103
|
-
const
|
|
1104
|
-
const
|
|
811
|
+
const input = event.currentTarget;
|
|
812
|
+
const selectionStart = input.selectionStart;
|
|
813
|
+
const selectionEnd = input.selectionEnd;
|
|
814
|
+
const nextText = inputValue.slice(0, selectionStart) + pastedData + inputValue.slice(selectionEnd);
|
|
815
|
+
const parsedValue = parseNumber(nextText, locale, formatOptionsRef.current);
|
|
1105
816
|
if (null !== parsedValue) {
|
|
1106
817
|
allowInputSyncRef.current = false;
|
|
818
|
+
pendingCaretRef.current = selectionStart + pastedData.length;
|
|
1107
819
|
setValue(parsedValue, createChangeEventDetails(inputPaste, event.nativeEvent));
|
|
1108
|
-
setInputValue(
|
|
820
|
+
setInputValue(nextText);
|
|
1109
821
|
}
|
|
1110
822
|
}
|
|
1111
823
|
};
|
|
@@ -1117,10 +829,10 @@ const NumberFieldInput_NumberFieldInput = /*#__PURE__*/ __rspack_external_react.
|
|
|
1117
829
|
state,
|
|
1118
830
|
props: [
|
|
1119
831
|
inputProps,
|
|
1120
|
-
|
|
1121
|
-
|
|
832
|
+
elementProps,
|
|
833
|
+
(props)=>validation.getValidationProps(disabled, props)
|
|
1122
834
|
],
|
|
1123
|
-
stateAttributesMapping:
|
|
835
|
+
stateAttributesMapping: stateAttributesMapping
|
|
1124
836
|
});
|
|
1125
837
|
return element;
|
|
1126
838
|
});
|
|
@@ -1129,66 +841,61 @@ const NumberFieldScrubAreaContext = /*#__PURE__*/ __rspack_external_react.create
|
|
|
1129
841
|
if ("production" !== process.env.NODE_ENV) NumberFieldScrubAreaContext.displayName = "NumberFieldScrubAreaContext";
|
|
1130
842
|
function useNumberFieldScrubAreaContext() {
|
|
1131
843
|
const context = __rspack_external_react.useContext(NumberFieldScrubAreaContext);
|
|
1132
|
-
if (void 0 === context) throw new Error("production" !== process.env.NODE_ENV ? 'Base UI: NumberFieldScrubAreaContext is missing. NumberFieldScrubArea parts must be placed within <NumberField.ScrubArea>.' :
|
|
844
|
+
if (void 0 === context) throw new Error("production" !== process.env.NODE_ENV ? 'Base UI: NumberFieldScrubAreaContext is missing. NumberFieldScrubArea parts must be placed within <NumberField.ScrubArea>.' : utils_formatErrorMessage(44));
|
|
1133
845
|
return context;
|
|
1134
846
|
}
|
|
1135
847
|
function getViewportRect(teleportDistance, scrubAreaEl) {
|
|
1136
848
|
const win = getWindow(scrubAreaEl);
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
849
|
+
if (null != teleportDistance) {
|
|
850
|
+
const rect = scrubAreaEl.getBoundingClientRect();
|
|
851
|
+
return {
|
|
852
|
+
left: rect.left - teleportDistance / 2,
|
|
853
|
+
top: rect.top - teleportDistance / 2,
|
|
854
|
+
right: rect.right + teleportDistance / 2,
|
|
855
|
+
bottom: rect.bottom + teleportDistance / 2
|
|
856
|
+
};
|
|
857
|
+
}
|
|
1144
858
|
const vV = win.visualViewport;
|
|
1145
859
|
if (vV) return {
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
860
|
+
left: vV.offsetLeft,
|
|
861
|
+
top: vV.offsetTop,
|
|
862
|
+
right: vV.offsetLeft + vV.width,
|
|
863
|
+
bottom: vV.offsetTop + vV.height
|
|
1150
864
|
};
|
|
1151
865
|
return {
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
866
|
+
left: 0,
|
|
867
|
+
top: 0,
|
|
868
|
+
right: win.document.documentElement.clientWidth,
|
|
869
|
+
bottom: win.document.documentElement.clientHeight
|
|
1156
870
|
};
|
|
1157
871
|
}
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
}
|
|
1164
|
-
handleVisualResize();
|
|
1165
|
-
return addEventListener(vV, 'resize', handleVisualResize);
|
|
1166
|
-
}
|
|
872
|
+
const SCRUB_AREA_STYLE = {
|
|
873
|
+
touchAction: 'none',
|
|
874
|
+
WebkitUserSelect: 'none',
|
|
875
|
+
userSelect: 'none'
|
|
876
|
+
};
|
|
1167
877
|
const NumberFieldScrubArea_NumberFieldScrubArea = /*#__PURE__*/ __rspack_external_react.forwardRef(function(componentProps, forwardedRef) {
|
|
1168
878
|
const { render, className, direction = 'horizontal', pixelSensitivity = 2, teleportDistance, style, ...elementProps } = componentProps;
|
|
1169
|
-
const { state, setIsScrubbing: setRootScrubbing,
|
|
879
|
+
const { state, setIsScrubbing: setRootScrubbing, inputRef, focusInput, incrementValue, allowInputSyncRef, getStepAmount, onValueCommitted, lastChangedValueRef, valueRef } = useNumberFieldRootContext();
|
|
880
|
+
const { disabled, readOnly } = state;
|
|
1170
881
|
const scrubAreaRef = __rspack_external_react.useRef(null);
|
|
1171
882
|
const isScrubbingRef = __rspack_external_react.useRef(false);
|
|
1172
883
|
const didMoveRef = __rspack_external_react.useRef(false);
|
|
1173
884
|
const pointerDownTargetRef = __rspack_external_react.useRef(null);
|
|
885
|
+
const nativeClickReceivedRef = __rspack_external_react.useRef(false);
|
|
1174
886
|
const scrubAreaCursorRef = __rspack_external_react.useRef(null);
|
|
1175
887
|
const virtualCursorCoords = __rspack_external_react.useRef({
|
|
1176
888
|
x: 0,
|
|
1177
889
|
y: 0
|
|
1178
890
|
});
|
|
1179
|
-
const visualScaleRef = __rspack_external_react.useRef(1);
|
|
1180
891
|
const exitPointerLockTimeout = useTimeout();
|
|
892
|
+
const syntheticClickTimeout = useTimeout();
|
|
1181
893
|
const [isTouchInput, setIsTouchInput] = __rspack_external_react.useState(false);
|
|
1182
894
|
const [isPointerLockDenied, setIsPointerLockDenied] = __rspack_external_react.useState(false);
|
|
1183
895
|
const [isScrubbing, setIsScrubbing] = __rspack_external_react.useState(false);
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
}, [
|
|
1188
|
-
isScrubbing
|
|
1189
|
-
]);
|
|
1190
|
-
function updateCursorTransform(x, y) {
|
|
1191
|
-
if (scrubAreaCursorRef.current) scrubAreaCursorRef.current.style.transform = `translate3d(${x}px,${y}px,0) scale(${1 / visualScaleRef.current})`;
|
|
896
|
+
function updateCursorTransform(virtualCursor, x, y) {
|
|
897
|
+
const scale = getWindow(virtualCursor).visualViewport?.scale ?? 1;
|
|
898
|
+
virtualCursor.style.transform = `translate3d(${x}px,${y}px,0) scale(${1 / scale})`;
|
|
1192
899
|
}
|
|
1193
900
|
const onScrub = useStableCallback(({ movementX, movementY })=>{
|
|
1194
901
|
const virtualCursor = scrubAreaCursorRef.current;
|
|
@@ -1196,18 +903,17 @@ const NumberFieldScrubArea_NumberFieldScrubArea = /*#__PURE__*/ __rspack_externa
|
|
|
1196
903
|
if (!virtualCursor || !scrubAreaEl) return;
|
|
1197
904
|
const rect = getViewportRect(teleportDistance, scrubAreaEl);
|
|
1198
905
|
const coords = virtualCursorCoords.current;
|
|
906
|
+
const wrap = (coord, halfSize, low, high)=>{
|
|
907
|
+
if (coord + halfSize < low) return high - halfSize;
|
|
908
|
+
if (coord + halfSize > high) return low - halfSize;
|
|
909
|
+
return coord;
|
|
910
|
+
};
|
|
1199
911
|
const newCoords = {
|
|
1200
|
-
x: Math.round(coords.x + movementX),
|
|
1201
|
-
y: Math.round(coords.y + movementY)
|
|
912
|
+
x: wrap(Math.round(coords.x + movementX), virtualCursor.offsetWidth / 2, rect.left, rect.right),
|
|
913
|
+
y: wrap(Math.round(coords.y + movementY), virtualCursor.offsetHeight / 2, rect.top, rect.bottom)
|
|
1202
914
|
};
|
|
1203
|
-
const cursorWidth = virtualCursor.offsetWidth;
|
|
1204
|
-
const cursorHeight = virtualCursor.offsetHeight;
|
|
1205
|
-
if (newCoords.x + cursorWidth / 2 < rect.x) newCoords.x = rect.width - cursorWidth / 2;
|
|
1206
|
-
else if (newCoords.x + cursorWidth / 2 > rect.width) newCoords.x = rect.x - cursorWidth / 2;
|
|
1207
|
-
if (newCoords.y + cursorHeight / 2 < rect.y) newCoords.y = rect.height - cursorHeight / 2;
|
|
1208
|
-
else if (newCoords.y + cursorHeight / 2 > rect.height) newCoords.y = rect.y - cursorHeight / 2;
|
|
1209
915
|
virtualCursorCoords.current = newCoords;
|
|
1210
|
-
updateCursorTransform(newCoords.x, newCoords.y);
|
|
916
|
+
updateCursorTransform(virtualCursor, newCoords.x, newCoords.y);
|
|
1211
917
|
});
|
|
1212
918
|
const onScrubbingChange = useStableCallback((scrubbingValue, { clientX, clientY })=>{
|
|
1213
919
|
__rspack_external_react_dom_7136dc57.flushSync(()=>{
|
|
@@ -1221,7 +927,7 @@ const NumberFieldScrubArea_NumberFieldScrubArea = /*#__PURE__*/ __rspack_externa
|
|
|
1221
927
|
y: clientY - virtualCursor.offsetHeight / 2
|
|
1222
928
|
};
|
|
1223
929
|
virtualCursorCoords.current = initialCoords;
|
|
1224
|
-
updateCursorTransform(initialCoords.x, initialCoords.y);
|
|
930
|
+
updateCursorTransform(virtualCursor, initialCoords.x, initialCoords.y);
|
|
1225
931
|
});
|
|
1226
932
|
__rspack_external_react.useEffect(function() {
|
|
1227
933
|
if (!inputRef.current || disabled || readOnly || !isScrubbing) return;
|
|
@@ -1236,15 +942,21 @@ const NumberFieldScrubArea_NumberFieldScrubArea = /*#__PURE__*/ __rspack_externa
|
|
|
1236
942
|
onValueCommitted(lastChangedValueRef.current ?? valueRef.current, createGenericEventDetails("scrub", event));
|
|
1237
943
|
const pointerDownTarget = pointerDownTargetRef.current;
|
|
1238
944
|
const input = inputRef.current;
|
|
1239
|
-
if (!didMoveRef.current && null != pointerDownTarget && input)
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
945
|
+
if (!didMoveRef.current && null != pointerDownTarget && input) {
|
|
946
|
+
const MouseEventConstructor = getWindow(input).MouseEvent;
|
|
947
|
+
syntheticClickTimeout.start(0, ()=>{
|
|
948
|
+
if (nativeClickReceivedRef.current) return;
|
|
949
|
+
pointerDownTarget.dispatchEvent(new MouseEventConstructor('click', {
|
|
950
|
+
bubbles: true,
|
|
951
|
+
cancelable: true
|
|
952
|
+
}));
|
|
953
|
+
});
|
|
954
|
+
}
|
|
1243
955
|
didMoveRef.current = false;
|
|
1244
956
|
pointerDownTargetRef.current = null;
|
|
1245
957
|
}
|
|
1246
958
|
}
|
|
1247
|
-
if (
|
|
959
|
+
if (gecko) exitPointerLockTimeout.start(20, handler);
|
|
1248
960
|
else handler();
|
|
1249
961
|
}
|
|
1250
962
|
function handleScrubPointerMove(event) {
|
|
@@ -1257,7 +969,7 @@ const NumberFieldScrubArea_NumberFieldScrubArea = /*#__PURE__*/ __rspack_externa
|
|
|
1257
969
|
cumulativeDelta = 0;
|
|
1258
970
|
didMoveRef.current = true;
|
|
1259
971
|
const dValue = 'vertical' === direction ? -movementY : movementX;
|
|
1260
|
-
const stepAmount = getStepAmount(event)
|
|
972
|
+
const stepAmount = getStepAmount(event);
|
|
1261
973
|
const rawAmount = dValue * stepAmount;
|
|
1262
974
|
if (0 !== rawAmount) {
|
|
1263
975
|
allowInputSyncRef.current = true;
|
|
@@ -1290,7 +1002,19 @@ const NumberFieldScrubArea_NumberFieldScrubArea = /*#__PURE__*/ __rspack_externa
|
|
|
1290
1002
|
lastChangedValueRef,
|
|
1291
1003
|
onValueCommitted,
|
|
1292
1004
|
valueRef,
|
|
1293
|
-
exitPointerLockTimeout
|
|
1005
|
+
exitPointerLockTimeout,
|
|
1006
|
+
syntheticClickTimeout
|
|
1007
|
+
]);
|
|
1008
|
+
__rspack_external_react.useEffect(()=>()=>{
|
|
1009
|
+
if (isScrubbingRef.current) {
|
|
1010
|
+
isScrubbingRef.current = false;
|
|
1011
|
+
setRootScrubbing(false);
|
|
1012
|
+
try {
|
|
1013
|
+
ownerDocument(scrubAreaRef.current).exitPointerLock();
|
|
1014
|
+
} catch {}
|
|
1015
|
+
}
|
|
1016
|
+
}, [
|
|
1017
|
+
setRootScrubbing
|
|
1294
1018
|
]);
|
|
1295
1019
|
__rspack_external_react.useEffect(function() {
|
|
1296
1020
|
const element = scrubAreaRef.current;
|
|
@@ -1305,33 +1029,31 @@ const NumberFieldScrubArea_NumberFieldScrubArea = /*#__PURE__*/ __rspack_externa
|
|
|
1305
1029
|
]);
|
|
1306
1030
|
const defaultProps = {
|
|
1307
1031
|
role: 'presentation',
|
|
1308
|
-
style:
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
userSelect: 'none'
|
|
1032
|
+
style: SCRUB_AREA_STYLE,
|
|
1033
|
+
onClickCapture () {
|
|
1034
|
+
nativeClickReceivedRef.current = true;
|
|
1312
1035
|
},
|
|
1313
1036
|
async onPointerDown (event) {
|
|
1314
|
-
|
|
1315
|
-
if (event.defaultPrevented || readOnly || !isMainButton || disabled) return;
|
|
1037
|
+
if (event.defaultPrevented || readOnly || event.button || disabled) return;
|
|
1316
1038
|
const isTouch = 'touch' === event.pointerType;
|
|
1317
1039
|
setIsTouchInput(isTouch);
|
|
1318
1040
|
if ('mouse' === event.pointerType) {
|
|
1319
1041
|
event.preventDefault();
|
|
1320
|
-
|
|
1042
|
+
focusInput();
|
|
1321
1043
|
}
|
|
1322
1044
|
isScrubbingRef.current = true;
|
|
1323
1045
|
didMoveRef.current = false;
|
|
1046
|
+
nativeClickReceivedRef.current = false;
|
|
1047
|
+
syntheticClickTimeout.clear();
|
|
1324
1048
|
pointerDownTargetRef.current = getTarget(event.nativeEvent);
|
|
1325
1049
|
onScrubbingChange(true, event.nativeEvent);
|
|
1326
|
-
if (!isTouch && !
|
|
1050
|
+
if (!isTouch && !webkit) try {
|
|
1327
1051
|
await ownerDocument(scrubAreaRef.current).body.requestPointerLock();
|
|
1328
1052
|
setIsPointerLockDenied(false);
|
|
1329
1053
|
} catch (error) {
|
|
1330
1054
|
setIsPointerLockDenied(true);
|
|
1331
1055
|
} finally{
|
|
1332
|
-
if (isScrubbingRef.current)
|
|
1333
|
-
onScrubbingChange(true, event.nativeEvent);
|
|
1334
|
-
});
|
|
1056
|
+
if (isScrubbingRef.current) onScrubbingChange(true, event.nativeEvent);
|
|
1335
1057
|
}
|
|
1336
1058
|
}
|
|
1337
1059
|
};
|
|
@@ -1351,18 +1073,11 @@ const NumberFieldScrubArea_NumberFieldScrubArea = /*#__PURE__*/ __rspack_externa
|
|
|
1351
1073
|
isScrubbing,
|
|
1352
1074
|
isTouchInput,
|
|
1353
1075
|
isPointerLockDenied,
|
|
1354
|
-
scrubAreaCursorRef
|
|
1355
|
-
scrubAreaRef,
|
|
1356
|
-
direction,
|
|
1357
|
-
pixelSensitivity,
|
|
1358
|
-
teleportDistance
|
|
1076
|
+
scrubAreaCursorRef
|
|
1359
1077
|
}), [
|
|
1360
1078
|
isScrubbing,
|
|
1361
1079
|
isTouchInput,
|
|
1362
|
-
isPointerLockDenied
|
|
1363
|
-
direction,
|
|
1364
|
-
pixelSensitivity,
|
|
1365
|
-
teleportDistance
|
|
1080
|
+
isPointerLockDenied
|
|
1366
1081
|
]);
|
|
1367
1082
|
return /*#__PURE__*/ jsx(NumberFieldScrubAreaContext.Provider, {
|
|
1368
1083
|
value: contextValue,
|
|
@@ -1370,12 +1085,18 @@ const NumberFieldScrubArea_NumberFieldScrubArea = /*#__PURE__*/ __rspack_externa
|
|
|
1370
1085
|
});
|
|
1371
1086
|
});
|
|
1372
1087
|
if ("production" !== process.env.NODE_ENV) NumberFieldScrubArea_NumberFieldScrubArea.displayName = "NumberFieldScrubArea";
|
|
1088
|
+
const CURSOR_STYLE = {
|
|
1089
|
+
position: 'fixed',
|
|
1090
|
+
top: 0,
|
|
1091
|
+
left: 0,
|
|
1092
|
+
pointerEvents: 'none'
|
|
1093
|
+
};
|
|
1373
1094
|
const NumberFieldScrubAreaCursor_NumberFieldScrubAreaCursor = /*#__PURE__*/ __rspack_external_react.forwardRef(function(componentProps, forwardedRef) {
|
|
1374
1095
|
const { render, className, style, ...elementProps } = componentProps;
|
|
1375
1096
|
const { state } = useNumberFieldRootContext();
|
|
1376
1097
|
const { isScrubbing, isTouchInput, isPointerLockDenied, scrubAreaCursorRef } = useNumberFieldScrubAreaContext();
|
|
1377
1098
|
const [domElement, setDomElement] = __rspack_external_react.useState(null);
|
|
1378
|
-
const shouldRender = isScrubbing && !
|
|
1099
|
+
const shouldRender = isScrubbing && !webkit && !isTouchInput && !isPointerLockDenied;
|
|
1379
1100
|
const element = useRenderElement('span', componentProps, {
|
|
1380
1101
|
enabled: shouldRender,
|
|
1381
1102
|
ref: [
|
|
@@ -1387,12 +1108,7 @@ const NumberFieldScrubAreaCursor_NumberFieldScrubAreaCursor = /*#__PURE__*/ __rs
|
|
|
1387
1108
|
props: [
|
|
1388
1109
|
{
|
|
1389
1110
|
role: 'presentation',
|
|
1390
|
-
style:
|
|
1391
|
-
position: 'fixed',
|
|
1392
|
-
top: 0,
|
|
1393
|
-
left: 0,
|
|
1394
|
-
pointerEvents: 'none'
|
|
1395
|
-
}
|
|
1111
|
+
style: CURSOR_STYLE
|
|
1396
1112
|
},
|
|
1397
1113
|
elementProps
|
|
1398
1114
|
],
|