@rockshin/tao-ui 0.0.58 → 0.0.60
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/components/affix/affix.js +38 -4
- package/dist/components/app/app-modals.js +11 -6
- package/dist/components/app/app-notices.js +105 -47
- package/dist/components/auto-complete/auto-complete.js +9 -2
- package/dist/components/calendar/calendar.js +22 -18
- package/dist/components/carousel/carousel.js +27 -14
- package/dist/components/cascader/cascader.js +18 -12
- package/dist/components/checkbox/checkbox.d.ts +3 -1
- package/dist/components/checkbox/checkbox.js +65 -58
- package/dist/components/color-picker/color-picker.css +1 -1
- package/dist/components/color-picker/color-picker.js +386 -362
- package/dist/components/context-menu/context-menu.d.ts +3 -1
- package/dist/components/context-menu/context-menu.js +48 -43
- package/dist/components/date-picker/calendar/calendar-grid.d.ts +5 -3
- package/dist/components/date-picker/calendar/calendar-grid.js +9 -4
- package/dist/components/date-picker/calendar/month-grid.d.ts +2 -1
- package/dist/components/date-picker/calendar/month-grid.js +61 -45
- package/dist/components/date-picker/calendar/time-panel.d.ts +8 -1
- package/dist/components/date-picker/calendar/time-panel.js +93 -88
- package/dist/components/date-picker/calendar/year-grid.d.ts +2 -1
- package/dist/components/date-picker/calendar/year-grid.js +60 -44
- package/dist/components/date-picker/date-picker.css +9 -0
- package/dist/components/date-picker/date-picker.js +25 -14
- package/dist/components/date-picker/range-picker.d.ts +2 -0
- package/dist/components/date-picker/range-picker.js +132 -73
- package/dist/components/date-picker/types.js +1 -1
- package/dist/components/drawer/drawer.d.ts +1 -1
- package/dist/components/drawer/drawer.js +4 -3
- package/dist/components/dropdown/dropdown.d.ts +1 -0
- package/dist/components/dropdown/dropdown.js +29 -21
- package/dist/components/float-button/float-button.js +6 -5
- package/dist/components/form/form-item.d.ts +1 -1
- package/dist/components/form/form-item.js +160 -120
- package/dist/components/form/use-form.js +2 -1
- package/dist/components/form-field/form-field-view.d.ts +2 -1
- package/dist/components/form-field/form-field-view.js +173 -108
- package/dist/components/input/input-shared.js +3 -2
- package/dist/components/input/otp.js +114 -110
- package/dist/components/input/password.js +55 -61
- package/dist/components/input/search.js +8 -4
- package/dist/components/input-number/input-number.d.ts +2 -1
- package/dist/components/input-number/input-number.js +67 -52
- package/dist/components/mentions/mentions.js +4 -2
- package/dist/components/menu/menu-render.d.ts +6 -0
- package/dist/components/menu/menu-render.js +39 -26
- package/dist/components/modal/confirm-dialog.js +22 -10
- package/dist/components/modal/modal.js +320 -315
- package/dist/components/modal/use-modal.js +1 -1
- package/dist/components/pagination/pagination.d.ts +4 -2
- package/dist/components/pagination/pagination.js +128 -117
- package/dist/components/popover/popover.js +214 -351
- package/dist/components/qr-code/qr-code.js +157 -150
- package/dist/components/radio/radio.d.ts +3 -1
- package/dist/components/radio/radio.js +73 -64
- package/dist/components/select/mobile-select.js +7 -4
- package/dist/components/select/select-model.js +3 -3
- package/dist/components/select/select.js +78 -39
- package/dist/components/select/use-select-selection.js +100 -92
- package/dist/components/slider/slider.d.ts +2 -2
- package/dist/components/slider/slider.js +13 -2
- package/dist/components/sonner/sonner.js +2 -2
- package/dist/components/splitter/splitter.css +1 -0
- package/dist/components/splitter/splitter.js +152 -126
- package/dist/components/statistic/statistic.js +38 -31
- package/dist/components/switch/switch.js +45 -39
- package/dist/components/table/table-filter.d.ts +3 -1
- package/dist/components/table/table-filter.js +100 -74
- package/dist/components/table/table.js +2 -0
- package/dist/components/table/use-table-data.js +2 -2
- package/dist/components/tabs/tabs.d.ts +3 -2
- package/dist/components/tabs/tabs.js +122 -112
- package/dist/components/time-picker/time-picker.js +35 -3
- package/dist/components/tooltip/tooltip.d.ts +1 -1
- package/dist/components/tooltip/tooltip.js +220 -124
- package/dist/components/tree/tree.js +31 -3
- package/dist/components/tree-select/tree-select.js +2 -1
- package/dist/components/upload/upload.js +67 -40
- package/dist/locales/ar-EG.js +2 -0
- package/dist/locales/de-DE.js +2 -0
- package/dist/locales/en-US.js +2 -0
- package/dist/locales/es-ES.js +2 -0
- package/dist/locales/fr-FR.js +2 -0
- package/dist/locales/hi-IN.js +2 -0
- package/dist/locales/id-ID.js +2 -0
- package/dist/locales/it-IT.js +2 -0
- package/dist/locales/ja-JP.js +2 -0
- package/dist/locales/ko-KR.js +2 -0
- package/dist/locales/pt-BR.js +2 -0
- package/dist/locales/ru-RU.js +2 -0
- package/dist/locales/th-TH.js +2 -0
- package/dist/locales/tr-TR.js +2 -0
- package/dist/locales/types.d.ts +2 -0
- package/dist/locales/vi-VN.js +2 -0
- package/dist/locales/zh-CN.js +2 -0
- package/dist/locales/zh-TW.js +2 -0
- package/dist/number-input/format.js +1 -1
- package/dist/number-input/use-number-input.d.ts +1 -0
- package/dist/number-input/use-number-input.js +170 -321
- package/dist/number-input/validate.d.ts +1 -0
- package/dist/number-input/validate.js +1 -1
- package/dist/provider/tao-provider.d.ts +2 -2
- package/dist/provider/tao-provider.js +66 -52
- package/dist/theme/control.css +5 -1
- package/dist/theme/theme.css +2 -2
- package/dist/utils/composed-parent.d.ts +1 -0
- package/dist/utils/composed-parent.js +7 -0
- package/dist/utils/portal.d.ts +5 -0
- package/dist/utils/portal.js +7 -1
- package/dist/utils/refs.d.ts +3 -1
- package/dist/utils/refs.js +25 -1
- package/package.json +1 -1
|
@@ -1,350 +1,199 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
1
|
+
import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
3
2
|
import { useTaoConfig } from "../provider/tao-provider.js";
|
|
4
3
|
import { countAnchored, findCursorAt, isThousandSepBeforeCursor, reposition } from "./cursor.js";
|
|
5
4
|
import { format, padOnBlur, parse, truncateDecimals } from "./format.js";
|
|
6
5
|
import { resolveNumberFormat } from "./locale.js";
|
|
7
6
|
import { fromPercent, toPercent } from "./percentage.js";
|
|
8
|
-
import { clampToRange, isValidCanonical, stripDisallowedSign } from "./validate.js";
|
|
7
|
+
import { clampToRange, isValidCanonical, stripDisallowedSign, toCanonical } from "./validate.js";
|
|
9
8
|
function useNumberInput(opts) {
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const decimalPlaces = void 0 === t0 ? 2 : t0;
|
|
13
|
-
const padMode = void 0 === t1 ? "never" : t1;
|
|
14
|
-
const isPercentage = void 0 === t2 ? false : t2;
|
|
15
|
-
const allowNegative = void 0 === t3 ? false : t3;
|
|
9
|
+
const { value: externalValue, defaultValue, onChange, onBlur, locale: localeProp, decimalSeparator, thousandsSeparator: thousandsSeparatorProp, decimalPlaces = 2, padDecimalsOnBlur: padMode = 'never', isPercentage = false, allowNegative = false, min, max, disabled: disabledProp } = opts;
|
|
10
|
+
const value = 'number' == typeof externalValue ? toCanonical(externalValue) : externalValue;
|
|
16
11
|
const config = useTaoConfig();
|
|
12
|
+
const disabled = disabledProp ?? config.disabled;
|
|
17
13
|
const locale = localeProp ?? config.locale.numberLocale;
|
|
18
|
-
|
|
19
|
-
if ($[0] !== decimalSeparator || $[1] !== locale || $[2] !== thousandsSeparatorProp) {
|
|
20
|
-
t4 = resolveNumberFormat(locale, {
|
|
14
|
+
const fmtOpts = useMemo(()=>resolveNumberFormat(locale, {
|
|
21
15
|
decimalSeparator,
|
|
22
16
|
thousandsSeparator: thousandsSeparatorProp
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
} else t4 = $[3];
|
|
29
|
-
const fmtOpts = t4;
|
|
17
|
+
}), [
|
|
18
|
+
locale,
|
|
19
|
+
decimalSeparator,
|
|
20
|
+
thousandsSeparatorProp
|
|
21
|
+
]);
|
|
30
22
|
const thousandsSeparator = fmtOpts.thousandsSeparator;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const canonicalToDisplay = t5;
|
|
42
|
-
const isValueControlled = "value" in opts;
|
|
43
|
-
let t6;
|
|
44
|
-
if ($[7] !== canonicalToDisplay || $[8] !== defaultValue || $[9] !== fmtOpts || $[10] !== isPercentage || $[11] !== isValueControlled || $[12] !== value) {
|
|
45
|
-
t6 = ()=>({
|
|
46
|
-
display: canonicalToDisplay(isValueControlled ? value ?? "" : defaultValue ?? ""),
|
|
47
|
-
format: fmtOpts,
|
|
48
|
-
isPercentage
|
|
49
|
-
});
|
|
50
|
-
$[7] = canonicalToDisplay;
|
|
51
|
-
$[8] = defaultValue;
|
|
52
|
-
$[9] = fmtOpts;
|
|
53
|
-
$[10] = isPercentage;
|
|
54
|
-
$[11] = isValueControlled;
|
|
55
|
-
$[12] = value;
|
|
56
|
-
$[13] = t6;
|
|
57
|
-
} else t6 = $[13];
|
|
58
|
-
const [buffer, setBuffer] = useState(t6);
|
|
23
|
+
const canonicalToDisplay = (actual)=>{
|
|
24
|
+
const canonical = isPercentage ? toPercent(actual) : actual;
|
|
25
|
+
return format(canonical, fmtOpts);
|
|
26
|
+
};
|
|
27
|
+
const isValueControlled = 'value' in opts;
|
|
28
|
+
const [buffer, setBuffer] = useState(()=>({
|
|
29
|
+
display: canonicalToDisplay(isValueControlled ? value ?? '' : defaultValue ?? ''),
|
|
30
|
+
format: fmtOpts,
|
|
31
|
+
isPercentage
|
|
32
|
+
}));
|
|
59
33
|
const displayBuffer = buffer.display;
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
isPercentage
|
|
66
|
-
});
|
|
67
|
-
$[14] = fmtOpts;
|
|
68
|
-
$[15] = isPercentage;
|
|
69
|
-
$[16] = t7;
|
|
70
|
-
} else t7 = $[16];
|
|
71
|
-
const setDisplayBuffer = t7;
|
|
34
|
+
const setDisplayBuffer = (display)=>setBuffer({
|
|
35
|
+
display,
|
|
36
|
+
format: fmtOpts,
|
|
37
|
+
isPercentage
|
|
38
|
+
});
|
|
72
39
|
const isFocusedRef = useRef(false);
|
|
73
40
|
const inputRef = useRef(null);
|
|
74
41
|
const pendingCursorRef = useRef(null);
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
const mapCursor = (position)=>findCursorAt(display_0, afterCount - beforeCount + countAnchored(buffer.display, position, buffer.format.thousandsSeparator), thousandsSeparator);
|
|
90
|
-
pendingCursorRef.current = {
|
|
91
|
-
display: display_0,
|
|
92
|
-
start: mapCursor(input.selectionStart ?? buffer.display.length),
|
|
93
|
-
end: mapCursor(input.selectionEnd ?? buffer.display.length)
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
setBuffer({
|
|
42
|
+
useLayoutEffect(()=>{
|
|
43
|
+
if (buffer.format === fmtOpts && buffer.isPercentage === isPercentage) return;
|
|
44
|
+
const previousCanonical = parse(buffer.display, buffer.format);
|
|
45
|
+
const useExternalValue = isValueControlled && !isFocusedRef.current;
|
|
46
|
+
const actual_0 = useExternalValue ? value ?? '' : buffer.isPercentage ? fromPercent(previousCanonical) : previousCanonical;
|
|
47
|
+
let canonical_0 = isPercentage ? toPercent(actual_0) : actual_0;
|
|
48
|
+
if (!useExternalValue && previousCanonical.endsWith('.') && !canonical_0.includes('.')) canonical_0 += '.';
|
|
49
|
+
const display_0 = format(canonical_0, fmtOpts);
|
|
50
|
+
const input = inputRef.current;
|
|
51
|
+
if (isFocusedRef.current && input && display_0 !== buffer.display) {
|
|
52
|
+
const beforeCount = countAnchored(buffer.display, buffer.display.length, buffer.format.thousandsSeparator);
|
|
53
|
+
const afterCount = countAnchored(display_0, display_0.length, thousandsSeparator);
|
|
54
|
+
const mapCursor = (position)=>findCursorAt(display_0, afterCount - beforeCount + countAnchored(buffer.display, position, buffer.format.thousandsSeparator), thousandsSeparator);
|
|
55
|
+
pendingCursorRef.current = {
|
|
97
56
|
display: display_0,
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
});
|
|
101
|
-
};
|
|
102
|
-
$[17] = buffer.display;
|
|
103
|
-
$[18] = buffer.format;
|
|
104
|
-
$[19] = buffer.isPercentage;
|
|
105
|
-
$[20] = fmtOpts;
|
|
106
|
-
$[21] = isPercentage;
|
|
107
|
-
$[22] = isValueControlled;
|
|
108
|
-
$[23] = thousandsSeparator;
|
|
109
|
-
$[24] = value;
|
|
110
|
-
$[25] = t8;
|
|
111
|
-
} else t8 = $[25];
|
|
112
|
-
let t9;
|
|
113
|
-
if ($[26] !== buffer || $[27] !== fmtOpts || $[28] !== isPercentage || $[29] !== isValueControlled || $[30] !== thousandsSeparator || $[31] !== value) {
|
|
114
|
-
t9 = [
|
|
115
|
-
buffer,
|
|
116
|
-
fmtOpts,
|
|
117
|
-
isPercentage,
|
|
118
|
-
isValueControlled,
|
|
119
|
-
value,
|
|
120
|
-
thousandsSeparator
|
|
121
|
-
];
|
|
122
|
-
$[26] = buffer;
|
|
123
|
-
$[27] = fmtOpts;
|
|
124
|
-
$[28] = isPercentage;
|
|
125
|
-
$[29] = isValueControlled;
|
|
126
|
-
$[30] = thousandsSeparator;
|
|
127
|
-
$[31] = value;
|
|
128
|
-
$[32] = t9;
|
|
129
|
-
} else t9 = $[32];
|
|
130
|
-
useLayoutEffect(t8, t9);
|
|
131
|
-
let t10;
|
|
132
|
-
if ($[33] !== canonicalToDisplay || $[34] !== displayBuffer || $[35] !== isValueControlled || $[36] !== setDisplayBuffer || $[37] !== value) {
|
|
133
|
-
t10 = ()=>{
|
|
134
|
-
if (!isValueControlled) return;
|
|
135
|
-
if (isFocusedRef.current) return;
|
|
136
|
-
const display_1 = canonicalToDisplay(value ?? "");
|
|
137
|
-
if (displayBuffer !== display_1) setDisplayBuffer(display_1);
|
|
138
|
-
};
|
|
139
|
-
$[33] = canonicalToDisplay;
|
|
140
|
-
$[34] = displayBuffer;
|
|
141
|
-
$[35] = isValueControlled;
|
|
142
|
-
$[36] = setDisplayBuffer;
|
|
143
|
-
$[37] = value;
|
|
144
|
-
$[38] = t10;
|
|
145
|
-
} else t10 = $[38];
|
|
146
|
-
let t11;
|
|
147
|
-
if ($[39] !== isValueControlled || $[40] !== value) {
|
|
148
|
-
t11 = [
|
|
149
|
-
value,
|
|
150
|
-
isValueControlled
|
|
151
|
-
];
|
|
152
|
-
$[39] = isValueControlled;
|
|
153
|
-
$[40] = value;
|
|
154
|
-
$[41] = t11;
|
|
155
|
-
} else t11 = $[41];
|
|
156
|
-
useEffect(t10, t11);
|
|
157
|
-
let t12;
|
|
158
|
-
let t13;
|
|
159
|
-
if ($[42] !== defaultValue || $[43] !== fmtOpts || $[44] !== isPercentage || $[45] !== isValueControlled) {
|
|
160
|
-
t12 = ()=>{
|
|
161
|
-
if (isValueControlled) return;
|
|
162
|
-
const form = inputRef.current?.form;
|
|
163
|
-
const reset = (event)=>{
|
|
164
|
-
queueMicrotask(()=>{
|
|
165
|
-
if (event.defaultPrevented) return;
|
|
166
|
-
pendingCursorRef.current = null;
|
|
167
|
-
const initial = defaultValue ?? "";
|
|
168
|
-
setBuffer({
|
|
169
|
-
display: format(isPercentage ? toPercent(initial) : initial, fmtOpts),
|
|
170
|
-
format: fmtOpts,
|
|
171
|
-
isPercentage
|
|
172
|
-
});
|
|
173
|
-
});
|
|
57
|
+
start: mapCursor(input.selectionStart ?? buffer.display.length),
|
|
58
|
+
end: mapCursor(input.selectionEnd ?? buffer.display.length)
|
|
174
59
|
};
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
t14 = $[49];
|
|
212
|
-
t15 = $[50];
|
|
213
|
-
}
|
|
214
|
-
useLayoutEffect(t14, t15);
|
|
215
|
-
let t16;
|
|
216
|
-
if ($[51] !== allowNegative || $[52] !== decimalPlaces || $[53] !== fmtOpts || $[54] !== isPercentage || $[55] !== onChange || $[56] !== setDisplayBuffer || $[57] !== thousandsSeparator) {
|
|
217
|
-
t16 = (e)=>{
|
|
218
|
-
const raw = e.target.value;
|
|
219
|
-
const cursor = e.target.selectionStart ?? raw.length;
|
|
220
|
-
let canonical_1 = parse(raw, fmtOpts);
|
|
221
|
-
canonical_1 = stripDisallowedSign(canonical_1, allowNegative);
|
|
222
|
-
canonical_1 = truncateDecimals(canonical_1, decimalPlaces);
|
|
223
|
-
if (!isValidCanonical(canonical_1)) return;
|
|
224
|
-
const newDisplay = format(canonical_1, fmtOpts);
|
|
225
|
-
const cursorPosition = reposition({
|
|
226
|
-
before: raw,
|
|
227
|
-
beforeCursor: cursor,
|
|
228
|
-
after: newDisplay,
|
|
229
|
-
thousandsSeparator
|
|
60
|
+
}
|
|
61
|
+
setBuffer({
|
|
62
|
+
display: display_0,
|
|
63
|
+
format: fmtOpts,
|
|
64
|
+
isPercentage
|
|
65
|
+
});
|
|
66
|
+
}, [
|
|
67
|
+
buffer,
|
|
68
|
+
fmtOpts,
|
|
69
|
+
isPercentage,
|
|
70
|
+
isValueControlled,
|
|
71
|
+
value,
|
|
72
|
+
thousandsSeparator
|
|
73
|
+
]);
|
|
74
|
+
useEffect(()=>{
|
|
75
|
+
if (!isValueControlled) return;
|
|
76
|
+
if (isFocusedRef.current) return;
|
|
77
|
+
const display_1 = canonicalToDisplay(value ?? '');
|
|
78
|
+
if (displayBuffer !== display_1) setDisplayBuffer(display_1);
|
|
79
|
+
}, [
|
|
80
|
+
value,
|
|
81
|
+
isValueControlled
|
|
82
|
+
]);
|
|
83
|
+
useEffect(()=>{
|
|
84
|
+
if (isValueControlled) return;
|
|
85
|
+
const form = inputRef.current?.form;
|
|
86
|
+
const reset = (event)=>{
|
|
87
|
+
queueMicrotask(()=>{
|
|
88
|
+
if (event.defaultPrevented) return;
|
|
89
|
+
pendingCursorRef.current = null;
|
|
90
|
+
const initial = defaultValue ?? '';
|
|
91
|
+
setBuffer({
|
|
92
|
+
display: format(isPercentage ? toPercent(initial) : initial, fmtOpts),
|
|
93
|
+
format: fmtOpts,
|
|
94
|
+
isPercentage
|
|
95
|
+
});
|
|
230
96
|
});
|
|
231
|
-
pendingCursorRef.current = {
|
|
232
|
-
display: newDisplay,
|
|
233
|
-
start: cursorPosition,
|
|
234
|
-
end: cursorPosition
|
|
235
|
-
};
|
|
236
|
-
setDisplayBuffer(newDisplay);
|
|
237
|
-
const actual_1 = isPercentage ? fromPercent(canonical_1) : canonical_1;
|
|
238
|
-
onChange?.(actual_1);
|
|
239
|
-
};
|
|
240
|
-
$[51] = allowNegative;
|
|
241
|
-
$[52] = decimalPlaces;
|
|
242
|
-
$[53] = fmtOpts;
|
|
243
|
-
$[54] = isPercentage;
|
|
244
|
-
$[55] = onChange;
|
|
245
|
-
$[56] = setDisplayBuffer;
|
|
246
|
-
$[57] = thousandsSeparator;
|
|
247
|
-
$[58] = t16;
|
|
248
|
-
} else t16 = $[58];
|
|
249
|
-
const handleChange = t16;
|
|
250
|
-
let t17;
|
|
251
|
-
if ($[59] !== canonicalToDisplay || $[60] !== decimalPlaces || $[61] !== displayBuffer || $[62] !== fmtOpts || $[63] !== isPercentage || $[64] !== isValueControlled || $[65] !== max || $[66] !== min || $[67] !== onBlur || $[68] !== onChange || $[69] !== padMode || $[70] !== setDisplayBuffer || $[71] !== value) {
|
|
252
|
-
t17 = ()=>{
|
|
253
|
-
isFocusedRef.current = false;
|
|
254
|
-
const raw_0 = isValueControlled ? canonicalToDisplay(value ?? "") : inputRef.current?.value ?? displayBuffer;
|
|
255
|
-
let canonical_2 = parse(raw_0, fmtOpts);
|
|
256
|
-
canonical_2 = padOnBlur(canonical_2, decimalPlaces, padMode);
|
|
257
|
-
const beforeClamp = isPercentage ? fromPercent(canonical_2) : canonical_2;
|
|
258
|
-
const bounded = clampToRange(beforeClamp, min, max);
|
|
259
|
-
const actual_2 = !isPercentage && decimalPlaces > 0 && bounded !== beforeClamp ? padOnBlur(bounded, decimalPlaces, padMode) : bounded;
|
|
260
|
-
const canonicalAfter = isPercentage ? toPercent(actual_2) : actual_2;
|
|
261
|
-
const newDisplay_0 = format(canonicalAfter, fmtOpts);
|
|
262
|
-
setDisplayBuffer(newDisplay_0);
|
|
263
|
-
onChange?.(actual_2);
|
|
264
|
-
onBlur?.(actual_2);
|
|
265
97
|
};
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
98
|
+
form?.addEventListener('reset', reset);
|
|
99
|
+
return ()=>form?.removeEventListener('reset', reset);
|
|
100
|
+
}, [
|
|
101
|
+
defaultValue,
|
|
102
|
+
fmtOpts,
|
|
103
|
+
isPercentage,
|
|
104
|
+
isValueControlled
|
|
105
|
+
]);
|
|
106
|
+
useLayoutEffect(()=>{
|
|
107
|
+
const pending = pendingCursorRef.current;
|
|
108
|
+
if (pending?.display !== displayBuffer) return;
|
|
109
|
+
inputRef.current?.setSelectionRange(pending.start, pending.end);
|
|
110
|
+
pendingCursorRef.current = null;
|
|
111
|
+
}, [
|
|
112
|
+
displayBuffer
|
|
113
|
+
]);
|
|
114
|
+
const handleChange = (e)=>{
|
|
115
|
+
if (disabled) return;
|
|
116
|
+
const raw = e.target.value;
|
|
117
|
+
const cursor = e.target.selectionStart ?? raw.length;
|
|
118
|
+
let canonical_1 = parse(raw, fmtOpts);
|
|
119
|
+
canonical_1 = stripDisallowedSign(canonical_1, allowNegative);
|
|
120
|
+
canonical_1 = truncateDecimals(canonical_1, decimalPlaces);
|
|
121
|
+
if (!isValidCanonical(canonical_1)) return;
|
|
122
|
+
const newDisplay = format(canonical_1, fmtOpts);
|
|
123
|
+
const cursorPosition = reposition({
|
|
124
|
+
before: raw,
|
|
125
|
+
beforeCursor: cursor,
|
|
126
|
+
after: newDisplay,
|
|
127
|
+
thousandsSeparator
|
|
128
|
+
});
|
|
129
|
+
pendingCursorRef.current = {
|
|
130
|
+
display: newDisplay,
|
|
131
|
+
start: cursorPosition,
|
|
132
|
+
end: cursorPosition
|
|
301
133
|
};
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
}
|
|
306
|
-
const
|
|
307
|
-
|
|
308
|
-
|
|
134
|
+
setDisplayBuffer(newDisplay);
|
|
135
|
+
const actual_1 = isPercentage ? fromPercent(canonical_1) : canonical_1;
|
|
136
|
+
onChange?.(actual_1);
|
|
137
|
+
};
|
|
138
|
+
const commit = ()=>{
|
|
139
|
+
const raw_0 = isValueControlled ? canonicalToDisplay(value ?? '') : inputRef.current?.value ?? displayBuffer;
|
|
140
|
+
let canonical_2 = truncateDecimals(parse(raw_0, fmtOpts), decimalPlaces);
|
|
141
|
+
canonical_2 = padOnBlur(canonical_2, decimalPlaces, padMode);
|
|
142
|
+
const beforeClamp = isPercentage ? fromPercent(canonical_2) : canonical_2;
|
|
143
|
+
const bounded = clampToRange(beforeClamp, min, max);
|
|
144
|
+
const actual_2 = !isPercentage && decimalPlaces > 0 && bounded !== beforeClamp ? padOnBlur(bounded, decimalPlaces, padMode) : bounded;
|
|
145
|
+
const canonicalAfter = isPercentage ? toPercent(actual_2) : actual_2;
|
|
146
|
+
const newDisplay_0 = format(canonicalAfter, fmtOpts);
|
|
147
|
+
setDisplayBuffer(newDisplay_0);
|
|
148
|
+
return actual_2;
|
|
149
|
+
};
|
|
150
|
+
const handleBlur = ()=>{
|
|
151
|
+
isFocusedRef.current = false;
|
|
152
|
+
if (disabled) return;
|
|
153
|
+
const previous = isValueControlled ? value ?? '' : derivedActual;
|
|
154
|
+
const actual_3 = commit();
|
|
155
|
+
if (actual_3 !== previous) onChange?.(actual_3);
|
|
156
|
+
onBlur?.(actual_3);
|
|
157
|
+
};
|
|
158
|
+
const handleFocus = ()=>{
|
|
159
|
+
if (disabled) return;
|
|
160
|
+
isFocusedRef.current = true;
|
|
161
|
+
};
|
|
162
|
+
const handleKeyDown = (e_0)=>{
|
|
163
|
+
if (disabled || e_0.nativeEvent.isComposing || 229 === e_0.keyCode) return;
|
|
164
|
+
if ('Enter' === e_0.key) {
|
|
165
|
+
const previous_0 = isValueControlled ? value ?? '' : derivedActual;
|
|
166
|
+
const actual_4 = commit();
|
|
167
|
+
if (actual_4 !== previous_0) onChange?.(actual_4);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
if ('Backspace' !== e_0.key) return;
|
|
171
|
+
const el = inputRef.current;
|
|
172
|
+
if (!el) return;
|
|
173
|
+
const cursor_0 = el.selectionStart ?? 0;
|
|
174
|
+
if (cursor_0 > 0 && el.selectionEnd === cursor_0 && isThousandSepBeforeCursor(displayBuffer, cursor_0, thousandsSeparator)) {
|
|
175
|
+
const beforeSeparator = cursor_0 - thousandsSeparator.length;
|
|
176
|
+
el.setSelectionRange(beforeSeparator, beforeSeparator);
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
const derivedActual = useMemo(()=>{
|
|
309
180
|
const canonical_3 = parse(buffer.display, buffer.format);
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
const derivedActual = t20;
|
|
317
|
-
const t21 = decimalPlaces > 0 ? "decimal" : "numeric";
|
|
318
|
-
let t22;
|
|
319
|
-
if ($[81] !== displayBuffer || $[82] !== handleBlur || $[83] !== handleChange || $[84] !== handleKeyDown || $[85] !== t21) {
|
|
320
|
-
t22 = {
|
|
181
|
+
return buffer.isPercentage ? fromPercent(canonical_3) : canonical_3;
|
|
182
|
+
}, [
|
|
183
|
+
buffer
|
|
184
|
+
]);
|
|
185
|
+
return {
|
|
186
|
+
inputProps: {
|
|
321
187
|
value: displayBuffer,
|
|
322
188
|
onChange: handleChange,
|
|
323
189
|
onBlur: handleBlur,
|
|
324
190
|
onFocus: handleFocus,
|
|
325
191
|
onKeyDown: handleKeyDown,
|
|
326
192
|
ref: inputRef,
|
|
327
|
-
inputMode:
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
$[84] = handleKeyDown;
|
|
333
|
-
$[85] = t21;
|
|
334
|
-
$[86] = t22;
|
|
335
|
-
} else t22 = $[86];
|
|
336
|
-
let t23;
|
|
337
|
-
if ($[87] !== derivedActual || $[88] !== displayBuffer || $[89] !== t22) {
|
|
338
|
-
t23 = {
|
|
339
|
-
inputProps: t22,
|
|
340
|
-
value: derivedActual,
|
|
341
|
-
displayValue: displayBuffer
|
|
342
|
-
};
|
|
343
|
-
$[87] = derivedActual;
|
|
344
|
-
$[88] = displayBuffer;
|
|
345
|
-
$[89] = t22;
|
|
346
|
-
$[90] = t23;
|
|
347
|
-
} else t23 = $[90];
|
|
348
|
-
return t23;
|
|
193
|
+
inputMode: decimalPlaces > 0 ? 'decimal' : 'numeric'
|
|
194
|
+
},
|
|
195
|
+
value: derivedActual,
|
|
196
|
+
displayValue: displayBuffer
|
|
197
|
+
};
|
|
349
198
|
}
|
|
350
199
|
export { useNumberInput };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export declare function toCanonical(value: number): string;
|
|
1
2
|
export declare function isValidCanonical(canonical: string): boolean;
|
|
2
3
|
export declare function stripDisallowedSign(canonical: string, allowNegative: boolean): string;
|
|
3
4
|
export declare function clampToRange(canonical: string, min: number | undefined, max: number | undefined): string;
|
|
@@ -152,12 +152,12 @@ export declare function useTaoToken(): {
|
|
|
152
152
|
* div would otherwise render even while the popup is closed, leaving a ghost
|
|
153
153
|
* `<div data-tao-provider>` in the body for every mounted-but-closed Select.
|
|
154
154
|
*/
|
|
155
|
-
export declare
|
|
155
|
+
export declare const TaoPortalScope: import("react").ForwardRefExoticComponent<{
|
|
156
156
|
children: ReactNode;
|
|
157
157
|
style?: CSSProperties;
|
|
158
158
|
asChild?: boolean;
|
|
159
159
|
direction?: TaoDirection;
|
|
160
|
-
}
|
|
160
|
+
} & import("react").RefAttributes<HTMLElement>>;
|
|
161
161
|
export interface TaoProviderProps {
|
|
162
162
|
/** Text and interaction direction. Defaults to the surrounding DOM direction. */
|
|
163
163
|
direction?: TaoDirection;
|