@rockshin/tao-ui 0.0.58 → 0.0.59
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 +17 -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.js +383 -360
- 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 +89 -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 +22 -13
- package/dist/components/date-picker/range-picker.d.ts +2 -0
- package/dist/components/date-picker/range-picker.js +127 -70
- 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.js +11 -9
- package/dist/components/float-button/float-button.js +4 -4
- package/dist/components/form/form-item.d.ts +1 -1
- package/dist/components/form/form-item.js +160 -120
- 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/mentions/mentions.js +1 -0
- package/dist/components/menu/menu-render.js +1 -0
- package/dist/components/modal/confirm-dialog.js +11 -4
- package/dist/components/modal/modal.js +320 -315
- package/dist/components/pagination/pagination.d.ts +1 -0
- package/dist/components/pagination/pagination.js +1 -0
- package/dist/components/popover/popover.js +325 -289
- 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 +6 -3
- package/dist/components/select/select-model.js +2 -2
- package/dist/components/select/select.js +78 -39
- package/dist/components/select/use-select-selection.js +58 -58
- 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/switch/switch.js +45 -39
- package/dist/components/table/table.js +1 -0
- package/dist/components/table/use-table-data.js +2 -2
- package/dist/components/time-picker/time-picker.js +31 -1
- package/dist/components/tooltip/tooltip.js +237 -99
- package/dist/components/tree/tree.js +31 -3
- package/dist/components/tree-select/tree-select.js +1 -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.js +166 -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 +49 -49
- 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,195 @@
|
|
|
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 } = opts;
|
|
10
|
+
const value = 'number' == typeof externalValue ? toCanonical(externalValue) : externalValue;
|
|
16
11
|
const config = useTaoConfig();
|
|
17
12
|
const locale = localeProp ?? config.locale.numberLocale;
|
|
18
|
-
|
|
19
|
-
if ($[0] !== decimalSeparator || $[1] !== locale || $[2] !== thousandsSeparatorProp) {
|
|
20
|
-
t4 = resolveNumberFormat(locale, {
|
|
13
|
+
const fmtOpts = useMemo(()=>resolveNumberFormat(locale, {
|
|
21
14
|
decimalSeparator,
|
|
22
15
|
thousandsSeparator: thousandsSeparatorProp
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
} else t4 = $[3];
|
|
29
|
-
const fmtOpts = t4;
|
|
16
|
+
}), [
|
|
17
|
+
locale,
|
|
18
|
+
decimalSeparator,
|
|
19
|
+
thousandsSeparatorProp
|
|
20
|
+
]);
|
|
30
21
|
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);
|
|
22
|
+
const canonicalToDisplay = (actual)=>{
|
|
23
|
+
const canonical = isPercentage ? toPercent(actual) : actual;
|
|
24
|
+
return format(canonical, fmtOpts);
|
|
25
|
+
};
|
|
26
|
+
const isValueControlled = 'value' in opts;
|
|
27
|
+
const [buffer, setBuffer] = useState(()=>({
|
|
28
|
+
display: canonicalToDisplay(isValueControlled ? value ?? '' : defaultValue ?? ''),
|
|
29
|
+
format: fmtOpts,
|
|
30
|
+
isPercentage
|
|
31
|
+
}));
|
|
59
32
|
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;
|
|
33
|
+
const setDisplayBuffer = (display)=>setBuffer({
|
|
34
|
+
display,
|
|
35
|
+
format: fmtOpts,
|
|
36
|
+
isPercentage
|
|
37
|
+
});
|
|
72
38
|
const isFocusedRef = useRef(false);
|
|
73
39
|
const inputRef = useRef(null);
|
|
74
40
|
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({
|
|
41
|
+
useLayoutEffect(()=>{
|
|
42
|
+
if (buffer.format === fmtOpts && buffer.isPercentage === isPercentage) return;
|
|
43
|
+
const previousCanonical = parse(buffer.display, buffer.format);
|
|
44
|
+
const useExternalValue = isValueControlled && !isFocusedRef.current;
|
|
45
|
+
const actual_0 = useExternalValue ? value ?? '' : buffer.isPercentage ? fromPercent(previousCanonical) : previousCanonical;
|
|
46
|
+
let canonical_0 = isPercentage ? toPercent(actual_0) : actual_0;
|
|
47
|
+
if (!useExternalValue && previousCanonical.endsWith('.') && !canonical_0.includes('.')) canonical_0 += '.';
|
|
48
|
+
const display_0 = format(canonical_0, fmtOpts);
|
|
49
|
+
const input = inputRef.current;
|
|
50
|
+
if (isFocusedRef.current && input && display_0 !== buffer.display) {
|
|
51
|
+
const beforeCount = countAnchored(buffer.display, buffer.display.length, buffer.format.thousandsSeparator);
|
|
52
|
+
const afterCount = countAnchored(display_0, display_0.length, thousandsSeparator);
|
|
53
|
+
const mapCursor = (position)=>findCursorAt(display_0, afterCount - beforeCount + countAnchored(buffer.display, position, buffer.format.thousandsSeparator), thousandsSeparator);
|
|
54
|
+
pendingCursorRef.current = {
|
|
97
55
|
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
|
-
});
|
|
56
|
+
start: mapCursor(input.selectionStart ?? buffer.display.length),
|
|
57
|
+
end: mapCursor(input.selectionEnd ?? buffer.display.length)
|
|
174
58
|
};
|
|
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
|
|
59
|
+
}
|
|
60
|
+
setBuffer({
|
|
61
|
+
display: display_0,
|
|
62
|
+
format: fmtOpts,
|
|
63
|
+
isPercentage
|
|
64
|
+
});
|
|
65
|
+
}, [
|
|
66
|
+
buffer,
|
|
67
|
+
fmtOpts,
|
|
68
|
+
isPercentage,
|
|
69
|
+
isValueControlled,
|
|
70
|
+
value,
|
|
71
|
+
thousandsSeparator
|
|
72
|
+
]);
|
|
73
|
+
useEffect(()=>{
|
|
74
|
+
if (!isValueControlled) return;
|
|
75
|
+
if (isFocusedRef.current) return;
|
|
76
|
+
const display_1 = canonicalToDisplay(value ?? '');
|
|
77
|
+
if (displayBuffer !== display_1) setDisplayBuffer(display_1);
|
|
78
|
+
}, [
|
|
79
|
+
value,
|
|
80
|
+
isValueControlled
|
|
81
|
+
]);
|
|
82
|
+
useEffect(()=>{
|
|
83
|
+
if (isValueControlled) return;
|
|
84
|
+
const form = inputRef.current?.form;
|
|
85
|
+
const reset = (event)=>{
|
|
86
|
+
queueMicrotask(()=>{
|
|
87
|
+
if (event.defaultPrevented) return;
|
|
88
|
+
pendingCursorRef.current = null;
|
|
89
|
+
const initial = defaultValue ?? '';
|
|
90
|
+
setBuffer({
|
|
91
|
+
display: format(isPercentage ? toPercent(initial) : initial, fmtOpts),
|
|
92
|
+
format: fmtOpts,
|
|
93
|
+
isPercentage
|
|
94
|
+
});
|
|
230
95
|
});
|
|
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
96
|
};
|
|
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
|
-
}
|
|
97
|
+
form?.addEventListener('reset', reset);
|
|
98
|
+
return ()=>form?.removeEventListener('reset', reset);
|
|
99
|
+
}, [
|
|
100
|
+
defaultValue,
|
|
101
|
+
fmtOpts,
|
|
102
|
+
isPercentage,
|
|
103
|
+
isValueControlled
|
|
104
|
+
]);
|
|
105
|
+
useLayoutEffect(()=>{
|
|
106
|
+
const pending = pendingCursorRef.current;
|
|
107
|
+
if (pending?.display !== displayBuffer) return;
|
|
108
|
+
inputRef.current?.setSelectionRange(pending.start, pending.end);
|
|
109
|
+
pendingCursorRef.current = null;
|
|
110
|
+
}, [
|
|
111
|
+
displayBuffer
|
|
112
|
+
]);
|
|
113
|
+
const handleChange = (e)=>{
|
|
114
|
+
const raw = e.target.value;
|
|
115
|
+
const cursor = e.target.selectionStart ?? raw.length;
|
|
116
|
+
let canonical_1 = parse(raw, fmtOpts);
|
|
117
|
+
canonical_1 = stripDisallowedSign(canonical_1, allowNegative);
|
|
118
|
+
canonical_1 = truncateDecimals(canonical_1, decimalPlaces);
|
|
119
|
+
if (!isValidCanonical(canonical_1)) return;
|
|
120
|
+
const newDisplay = format(canonical_1, fmtOpts);
|
|
121
|
+
const cursorPosition = reposition({
|
|
122
|
+
before: raw,
|
|
123
|
+
beforeCursor: cursor,
|
|
124
|
+
after: newDisplay,
|
|
125
|
+
thousandsSeparator
|
|
126
|
+
});
|
|
127
|
+
pendingCursorRef.current = {
|
|
128
|
+
display: newDisplay,
|
|
129
|
+
start: cursorPosition,
|
|
130
|
+
end: cursorPosition
|
|
301
131
|
};
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
}
|
|
306
|
-
const
|
|
307
|
-
|
|
308
|
-
|
|
132
|
+
setDisplayBuffer(newDisplay);
|
|
133
|
+
const actual_1 = isPercentage ? fromPercent(canonical_1) : canonical_1;
|
|
134
|
+
onChange?.(actual_1);
|
|
135
|
+
};
|
|
136
|
+
const commit = ()=>{
|
|
137
|
+
const raw_0 = isValueControlled ? canonicalToDisplay(value ?? '') : inputRef.current?.value ?? displayBuffer;
|
|
138
|
+
let canonical_2 = truncateDecimals(parse(raw_0, fmtOpts), decimalPlaces);
|
|
139
|
+
canonical_2 = padOnBlur(canonical_2, decimalPlaces, padMode);
|
|
140
|
+
const beforeClamp = isPercentage ? fromPercent(canonical_2) : canonical_2;
|
|
141
|
+
const bounded = clampToRange(beforeClamp, min, max);
|
|
142
|
+
const actual_2 = !isPercentage && decimalPlaces > 0 && bounded !== beforeClamp ? padOnBlur(bounded, decimalPlaces, padMode) : bounded;
|
|
143
|
+
const canonicalAfter = isPercentage ? toPercent(actual_2) : actual_2;
|
|
144
|
+
const newDisplay_0 = format(canonicalAfter, fmtOpts);
|
|
145
|
+
setDisplayBuffer(newDisplay_0);
|
|
146
|
+
return actual_2;
|
|
147
|
+
};
|
|
148
|
+
const handleBlur = ()=>{
|
|
149
|
+
isFocusedRef.current = false;
|
|
150
|
+
const previous = isValueControlled ? value ?? '' : derivedActual;
|
|
151
|
+
const actual_3 = commit();
|
|
152
|
+
if (actual_3 !== previous) onChange?.(actual_3);
|
|
153
|
+
onBlur?.(actual_3);
|
|
154
|
+
};
|
|
155
|
+
const handleFocus = ()=>{
|
|
156
|
+
isFocusedRef.current = true;
|
|
157
|
+
};
|
|
158
|
+
const handleKeyDown = (e_0)=>{
|
|
159
|
+
if (e_0.nativeEvent.isComposing || 229 === e_0.keyCode) return;
|
|
160
|
+
if ('Enter' === e_0.key) {
|
|
161
|
+
const previous_0 = isValueControlled ? value ?? '' : derivedActual;
|
|
162
|
+
const actual_4 = commit();
|
|
163
|
+
if (actual_4 !== previous_0) onChange?.(actual_4);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
if ('Backspace' !== e_0.key) return;
|
|
167
|
+
const el = inputRef.current;
|
|
168
|
+
if (!el) return;
|
|
169
|
+
const cursor_0 = el.selectionStart ?? 0;
|
|
170
|
+
if (cursor_0 > 0 && el.selectionEnd === cursor_0 && isThousandSepBeforeCursor(displayBuffer, cursor_0, thousandsSeparator)) {
|
|
171
|
+
const beforeSeparator = cursor_0 - thousandsSeparator.length;
|
|
172
|
+
el.setSelectionRange(beforeSeparator, beforeSeparator);
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
const derivedActual = useMemo(()=>{
|
|
309
176
|
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 = {
|
|
177
|
+
return buffer.isPercentage ? fromPercent(canonical_3) : canonical_3;
|
|
178
|
+
}, [
|
|
179
|
+
buffer
|
|
180
|
+
]);
|
|
181
|
+
return {
|
|
182
|
+
inputProps: {
|
|
321
183
|
value: displayBuffer,
|
|
322
184
|
onChange: handleChange,
|
|
323
185
|
onBlur: handleBlur,
|
|
324
186
|
onFocus: handleFocus,
|
|
325
187
|
onKeyDown: handleKeyDown,
|
|
326
188
|
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;
|
|
189
|
+
inputMode: decimalPlaces > 0 ? 'decimal' : 'numeric'
|
|
190
|
+
},
|
|
191
|
+
value: derivedActual,
|
|
192
|
+
displayValue: displayBuffer
|
|
193
|
+
};
|
|
349
194
|
}
|
|
350
195
|
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;
|