@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.
Files changed (111) 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 +18 -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.css +1 -1
  11. package/dist/components/color-picker/color-picker.js +386 -362
  12. package/dist/components/context-menu/context-menu.d.ts +3 -1
  13. package/dist/components/context-menu/context-menu.js +48 -43
  14. package/dist/components/date-picker/calendar/calendar-grid.d.ts +5 -3
  15. package/dist/components/date-picker/calendar/calendar-grid.js +9 -4
  16. package/dist/components/date-picker/calendar/month-grid.d.ts +2 -1
  17. package/dist/components/date-picker/calendar/month-grid.js +61 -45
  18. package/dist/components/date-picker/calendar/time-panel.d.ts +8 -1
  19. package/dist/components/date-picker/calendar/time-panel.js +93 -88
  20. package/dist/components/date-picker/calendar/year-grid.d.ts +2 -1
  21. package/dist/components/date-picker/calendar/year-grid.js +60 -44
  22. package/dist/components/date-picker/date-picker.css +9 -0
  23. package/dist/components/date-picker/date-picker.js +25 -14
  24. package/dist/components/date-picker/range-picker.d.ts +2 -0
  25. package/dist/components/date-picker/range-picker.js +132 -73
  26. package/dist/components/date-picker/types.js +1 -1
  27. package/dist/components/drawer/drawer.d.ts +1 -1
  28. package/dist/components/drawer/drawer.js +4 -3
  29. package/dist/components/dropdown/dropdown.d.ts +1 -0
  30. package/dist/components/dropdown/dropdown.js +29 -21
  31. package/dist/components/float-button/float-button.js +6 -5
  32. package/dist/components/form/form-item.d.ts +1 -1
  33. package/dist/components/form/form-item.js +160 -120
  34. package/dist/components/form/use-form.js +2 -1
  35. package/dist/components/form-field/form-field-view.d.ts +2 -1
  36. package/dist/components/form-field/form-field-view.js +173 -108
  37. package/dist/components/input/input-shared.js +3 -2
  38. package/dist/components/input/otp.js +114 -110
  39. package/dist/components/input/password.js +55 -61
  40. package/dist/components/input/search.js +8 -4
  41. package/dist/components/input-number/input-number.d.ts +2 -1
  42. package/dist/components/input-number/input-number.js +67 -52
  43. package/dist/components/mentions/mentions.js +4 -2
  44. package/dist/components/menu/menu-render.d.ts +6 -0
  45. package/dist/components/menu/menu-render.js +39 -26
  46. package/dist/components/modal/confirm-dialog.js +22 -10
  47. package/dist/components/modal/modal.js +320 -315
  48. package/dist/components/modal/use-modal.js +1 -1
  49. package/dist/components/pagination/pagination.d.ts +4 -2
  50. package/dist/components/pagination/pagination.js +128 -117
  51. package/dist/components/popover/popover.js +214 -351
  52. package/dist/components/qr-code/qr-code.js +157 -150
  53. package/dist/components/radio/radio.d.ts +3 -1
  54. package/dist/components/radio/radio.js +73 -64
  55. package/dist/components/select/mobile-select.js +7 -4
  56. package/dist/components/select/select-model.js +3 -3
  57. package/dist/components/select/select.js +78 -39
  58. package/dist/components/select/use-select-selection.js +100 -92
  59. package/dist/components/slider/slider.d.ts +2 -2
  60. package/dist/components/slider/slider.js +13 -2
  61. package/dist/components/sonner/sonner.js +2 -2
  62. package/dist/components/splitter/splitter.css +1 -0
  63. package/dist/components/splitter/splitter.js +152 -126
  64. package/dist/components/statistic/statistic.js +38 -31
  65. package/dist/components/switch/switch.js +45 -39
  66. package/dist/components/table/table-filter.d.ts +3 -1
  67. package/dist/components/table/table-filter.js +100 -74
  68. package/dist/components/table/table.js +2 -0
  69. package/dist/components/table/use-table-data.js +2 -2
  70. package/dist/components/tabs/tabs.d.ts +3 -2
  71. package/dist/components/tabs/tabs.js +122 -112
  72. package/dist/components/time-picker/time-picker.js +35 -3
  73. package/dist/components/tooltip/tooltip.d.ts +1 -1
  74. package/dist/components/tooltip/tooltip.js +220 -124
  75. package/dist/components/tree/tree.js +31 -3
  76. package/dist/components/tree-select/tree-select.js +2 -1
  77. package/dist/components/upload/upload.js +67 -40
  78. package/dist/locales/ar-EG.js +2 -0
  79. package/dist/locales/de-DE.js +2 -0
  80. package/dist/locales/en-US.js +2 -0
  81. package/dist/locales/es-ES.js +2 -0
  82. package/dist/locales/fr-FR.js +2 -0
  83. package/dist/locales/hi-IN.js +2 -0
  84. package/dist/locales/id-ID.js +2 -0
  85. package/dist/locales/it-IT.js +2 -0
  86. package/dist/locales/ja-JP.js +2 -0
  87. package/dist/locales/ko-KR.js +2 -0
  88. package/dist/locales/pt-BR.js +2 -0
  89. package/dist/locales/ru-RU.js +2 -0
  90. package/dist/locales/th-TH.js +2 -0
  91. package/dist/locales/tr-TR.js +2 -0
  92. package/dist/locales/types.d.ts +2 -0
  93. package/dist/locales/vi-VN.js +2 -0
  94. package/dist/locales/zh-CN.js +2 -0
  95. package/dist/locales/zh-TW.js +2 -0
  96. package/dist/number-input/format.js +1 -1
  97. package/dist/number-input/use-number-input.d.ts +1 -0
  98. package/dist/number-input/use-number-input.js +170 -321
  99. package/dist/number-input/validate.d.ts +1 -0
  100. package/dist/number-input/validate.js +1 -1
  101. package/dist/provider/tao-provider.d.ts +2 -2
  102. package/dist/provider/tao-provider.js +66 -52
  103. package/dist/theme/control.css +5 -1
  104. package/dist/theme/theme.css +2 -2
  105. package/dist/utils/composed-parent.d.ts +1 -0
  106. package/dist/utils/composed-parent.js +7 -0
  107. package/dist/utils/portal.d.ts +5 -0
  108. package/dist/utils/portal.js +7 -1
  109. package/dist/utils/refs.d.ts +3 -1
  110. package/dist/utils/refs.js +25 -1
  111. package/package.json +1 -1
@@ -1,350 +1,199 @@
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, 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
- let t4;
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
- $[0] = decimalSeparator;
25
- $[1] = locale;
26
- $[2] = thousandsSeparatorProp;
27
- $[3] = t4;
28
- } else t4 = $[3];
29
- const fmtOpts = t4;
17
+ }), [
18
+ locale,
19
+ decimalSeparator,
20
+ thousandsSeparatorProp
21
+ ]);
30
22
  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);
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
- 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;
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
- 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({
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
- 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
- });
57
+ start: mapCursor(input.selectionStart ?? buffer.display.length),
58
+ end: mapCursor(input.selectionEnd ?? buffer.display.length)
174
59
  };
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
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
- $[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
- }
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
- $[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) {
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
- 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 = {
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: 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;
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;
@@ -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;