@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.
Files changed (93) hide show
  1. package/dist/components/affix/affix.js +38 -4
  2. package/dist/components/app/app-modals.js +11 -6
  3. package/dist/components/app/app-notices.js +105 -47
  4. package/dist/components/auto-complete/auto-complete.js +9 -2
  5. package/dist/components/calendar/calendar.js +22 -18
  6. package/dist/components/carousel/carousel.js +27 -14
  7. package/dist/components/cascader/cascader.js +17 -12
  8. package/dist/components/checkbox/checkbox.d.ts +3 -1
  9. package/dist/components/checkbox/checkbox.js +65 -58
  10. package/dist/components/color-picker/color-picker.js +383 -360
  11. package/dist/components/date-picker/calendar/calendar-grid.d.ts +5 -3
  12. package/dist/components/date-picker/calendar/calendar-grid.js +9 -4
  13. package/dist/components/date-picker/calendar/month-grid.d.ts +2 -1
  14. package/dist/components/date-picker/calendar/month-grid.js +61 -45
  15. package/dist/components/date-picker/calendar/time-panel.d.ts +8 -1
  16. package/dist/components/date-picker/calendar/time-panel.js +89 -88
  17. package/dist/components/date-picker/calendar/year-grid.d.ts +2 -1
  18. package/dist/components/date-picker/calendar/year-grid.js +60 -44
  19. package/dist/components/date-picker/date-picker.css +9 -0
  20. package/dist/components/date-picker/date-picker.js +22 -13
  21. package/dist/components/date-picker/range-picker.d.ts +2 -0
  22. package/dist/components/date-picker/range-picker.js +127 -70
  23. package/dist/components/date-picker/types.js +1 -1
  24. package/dist/components/drawer/drawer.d.ts +1 -1
  25. package/dist/components/drawer/drawer.js +4 -3
  26. package/dist/components/dropdown/dropdown.js +11 -9
  27. package/dist/components/float-button/float-button.js +4 -4
  28. package/dist/components/form/form-item.d.ts +1 -1
  29. package/dist/components/form/form-item.js +160 -120
  30. package/dist/components/form-field/form-field-view.d.ts +2 -1
  31. package/dist/components/form-field/form-field-view.js +173 -108
  32. package/dist/components/input/input-shared.js +3 -2
  33. package/dist/components/input/otp.js +114 -110
  34. package/dist/components/input/password.js +55 -61
  35. package/dist/components/input/search.js +8 -4
  36. package/dist/components/mentions/mentions.js +1 -0
  37. package/dist/components/menu/menu-render.js +1 -0
  38. package/dist/components/modal/confirm-dialog.js +11 -4
  39. package/dist/components/modal/modal.js +320 -315
  40. package/dist/components/pagination/pagination.d.ts +1 -0
  41. package/dist/components/pagination/pagination.js +1 -0
  42. package/dist/components/popover/popover.js +325 -289
  43. package/dist/components/qr-code/qr-code.js +157 -150
  44. package/dist/components/radio/radio.d.ts +3 -1
  45. package/dist/components/radio/radio.js +73 -64
  46. package/dist/components/select/mobile-select.js +6 -3
  47. package/dist/components/select/select-model.js +2 -2
  48. package/dist/components/select/select.js +78 -39
  49. package/dist/components/select/use-select-selection.js +58 -58
  50. package/dist/components/slider/slider.d.ts +2 -2
  51. package/dist/components/slider/slider.js +13 -2
  52. package/dist/components/sonner/sonner.js +2 -2
  53. package/dist/components/splitter/splitter.css +1 -0
  54. package/dist/components/splitter/splitter.js +152 -126
  55. package/dist/components/switch/switch.js +45 -39
  56. package/dist/components/table/table.js +1 -0
  57. package/dist/components/table/use-table-data.js +2 -2
  58. package/dist/components/time-picker/time-picker.js +31 -1
  59. package/dist/components/tooltip/tooltip.js +237 -99
  60. package/dist/components/tree/tree.js +31 -3
  61. package/dist/components/tree-select/tree-select.js +1 -1
  62. package/dist/components/upload/upload.js +67 -40
  63. package/dist/locales/ar-EG.js +2 -0
  64. package/dist/locales/de-DE.js +2 -0
  65. package/dist/locales/en-US.js +2 -0
  66. package/dist/locales/es-ES.js +2 -0
  67. package/dist/locales/fr-FR.js +2 -0
  68. package/dist/locales/hi-IN.js +2 -0
  69. package/dist/locales/id-ID.js +2 -0
  70. package/dist/locales/it-IT.js +2 -0
  71. package/dist/locales/ja-JP.js +2 -0
  72. package/dist/locales/ko-KR.js +2 -0
  73. package/dist/locales/pt-BR.js +2 -0
  74. package/dist/locales/ru-RU.js +2 -0
  75. package/dist/locales/th-TH.js +2 -0
  76. package/dist/locales/tr-TR.js +2 -0
  77. package/dist/locales/types.d.ts +2 -0
  78. package/dist/locales/vi-VN.js +2 -0
  79. package/dist/locales/zh-CN.js +2 -0
  80. package/dist/locales/zh-TW.js +2 -0
  81. package/dist/number-input/format.js +1 -1
  82. package/dist/number-input/use-number-input.js +166 -321
  83. package/dist/number-input/validate.d.ts +1 -0
  84. package/dist/number-input/validate.js +1 -1
  85. package/dist/provider/tao-provider.d.ts +2 -2
  86. package/dist/provider/tao-provider.js +49 -49
  87. package/dist/utils/composed-parent.d.ts +1 -0
  88. package/dist/utils/composed-parent.js +7 -0
  89. package/dist/utils/portal.d.ts +5 -0
  90. package/dist/utils/portal.js +7 -1
  91. package/dist/utils/refs.d.ts +3 -1
  92. package/dist/utils/refs.js +25 -1
  93. package/package.json +1 -1
@@ -1,350 +1,195 @@
1
- import { c } from "react-compiler-runtime";
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 $ = c(91);
11
- const { value, defaultValue, onChange, onBlur, locale: localeProp, decimalSeparator, thousandsSeparator: thousandsSeparatorProp, decimalPlaces: t0, padDecimalsOnBlur: t1, isPercentage: t2, allowNegative: t3, min, max } = opts;
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
- let t4;
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
- $[0] = decimalSeparator;
25
- $[1] = locale;
26
- $[2] = thousandsSeparatorProp;
27
- $[3] = t4;
28
- } else t4 = $[3];
29
- const fmtOpts = t4;
16
+ }), [
17
+ locale,
18
+ decimalSeparator,
19
+ thousandsSeparatorProp
20
+ ]);
30
21
  const thousandsSeparator = fmtOpts.thousandsSeparator;
31
- let t5;
32
- if ($[4] !== fmtOpts || $[5] !== isPercentage) {
33
- t5 = (actual)=>{
34
- const canonical = isPercentage ? toPercent(actual) : actual;
35
- return format(canonical, fmtOpts);
36
- };
37
- $[4] = fmtOpts;
38
- $[5] = isPercentage;
39
- $[6] = t5;
40
- } else t5 = $[6];
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
- let t7;
61
- if ($[14] !== fmtOpts || $[15] !== isPercentage) {
62
- t7 = (display)=>setBuffer({
63
- display,
64
- format: fmtOpts,
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
- let t8;
76
- if ($[17] !== buffer.display || $[18] !== buffer.format || $[19] !== buffer.isPercentage || $[20] !== fmtOpts || $[21] !== isPercentage || $[22] !== isValueControlled || $[23] !== thousandsSeparator || $[24] !== value) {
77
- t8 = ()=>{
78
- if (buffer.format === fmtOpts && buffer.isPercentage === isPercentage) return;
79
- const previousCanonical = parse(buffer.display, buffer.format);
80
- const useExternalValue = isValueControlled && !isFocusedRef.current;
81
- const actual_0 = useExternalValue ? value ?? "" : buffer.isPercentage ? fromPercent(previousCanonical) : previousCanonical;
82
- let canonical_0 = isPercentage ? toPercent(actual_0) : actual_0;
83
- if (!useExternalValue && previousCanonical.endsWith(".") && !canonical_0.includes(".")) canonical_0 += ".";
84
- const display_0 = format(canonical_0, fmtOpts);
85
- const input = inputRef.current;
86
- if (isFocusedRef.current && input && display_0 !== buffer.display) {
87
- const beforeCount = countAnchored(buffer.display, buffer.display.length, buffer.format.thousandsSeparator);
88
- const afterCount = countAnchored(display_0, display_0.length, thousandsSeparator);
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
- format: fmtOpts,
99
- isPercentage
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
- form?.addEventListener("reset", reset);
176
- return ()=>form?.removeEventListener("reset", reset);
177
- };
178
- t13 = [
179
- defaultValue,
180
- fmtOpts,
181
- isPercentage,
182
- isValueControlled
183
- ];
184
- $[42] = defaultValue;
185
- $[43] = fmtOpts;
186
- $[44] = isPercentage;
187
- $[45] = isValueControlled;
188
- $[46] = t12;
189
- $[47] = t13;
190
- } else {
191
- t12 = $[46];
192
- t13 = $[47];
193
- }
194
- useEffect(t12, t13);
195
- let t14;
196
- let t15;
197
- if ($[48] !== displayBuffer) {
198
- t14 = ()=>{
199
- const pending = pendingCursorRef.current;
200
- if (pending?.display !== displayBuffer) return;
201
- inputRef.current?.setSelectionRange(pending.start, pending.end);
202
- pendingCursorRef.current = null;
203
- };
204
- t15 = [
205
- displayBuffer
206
- ];
207
- $[48] = displayBuffer;
208
- $[49] = t14;
209
- $[50] = t15;
210
- } else {
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
- $[59] = canonicalToDisplay;
267
- $[60] = decimalPlaces;
268
- $[61] = displayBuffer;
269
- $[62] = fmtOpts;
270
- $[63] = isPercentage;
271
- $[64] = isValueControlled;
272
- $[65] = max;
273
- $[66] = min;
274
- $[67] = onBlur;
275
- $[68] = onChange;
276
- $[69] = padMode;
277
- $[70] = setDisplayBuffer;
278
- $[71] = value;
279
- $[72] = t17;
280
- } else t17 = $[72];
281
- const handleBlur = t17;
282
- let t18;
283
- if ($[73] === Symbol.for("react.memo_cache_sentinel")) {
284
- t18 = ()=>{
285
- isFocusedRef.current = true;
286
- };
287
- $[73] = t18;
288
- } else t18 = $[73];
289
- const handleFocus = t18;
290
- let t19;
291
- if ($[74] !== displayBuffer || $[75] !== thousandsSeparator) {
292
- t19 = (e_0)=>{
293
- if ("Backspace" !== e_0.key || e_0.nativeEvent.isComposing || 229 === e_0.keyCode) return;
294
- const el = inputRef.current;
295
- if (!el) return;
296
- const cursor_0 = el.selectionStart ?? 0;
297
- if (cursor_0 > 0 && el.selectionEnd === cursor_0 && isThousandSepBeforeCursor(displayBuffer, cursor_0, thousandsSeparator)) {
298
- const beforeSeparator = cursor_0 - thousandsSeparator.length;
299
- el.setSelectionRange(beforeSeparator, beforeSeparator);
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
- $[74] = displayBuffer;
303
- $[75] = thousandsSeparator;
304
- $[76] = t19;
305
- } else t19 = $[76];
306
- const handleKeyDown = t19;
307
- let t20;
308
- if ($[77] !== buffer.display || $[78] !== buffer.format || $[79] !== buffer.isPercentage) {
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
- t20 = buffer.isPercentage ? fromPercent(canonical_3) : canonical_3;
311
- $[77] = buffer.display;
312
- $[78] = buffer.format;
313
- $[79] = buffer.isPercentage;
314
- $[80] = t20;
315
- } else t20 = $[80];
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: t21
328
- };
329
- $[81] = displayBuffer;
330
- $[82] = handleBlur;
331
- $[83] = handleChange;
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;
@@ -46,4 +46,4 @@ function clampToRange(canonical, min, max) {
46
46
  }
47
47
  return canonical;
48
48
  }
49
- export { clampToRange, isValidCanonical, stripDisallowedSign };
49
+ export { clampToRange, isValidCanonical, stripDisallowedSign, toCanonical };
@@ -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 function TaoPortalScope({ children, style, asChild, direction: directionProp, }: {
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
- }): import("react").JSX.Element;
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;