@mantine/core 9.0.0-alpha.2 → 9.0.0-alpha.4

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 (36) hide show
  1. package/cjs/components/NumberInput/NumberInput.cjs +513 -290
  2. package/cjs/components/NumberInput/NumberInput.cjs.map +1 -1
  3. package/cjs/components/ScrollArea/ScrollArea.cjs +12 -1
  4. package/cjs/components/ScrollArea/ScrollArea.cjs.map +1 -1
  5. package/cjs/components/Tooltip/Tooltip.cjs +3 -1
  6. package/cjs/components/Tooltip/Tooltip.cjs.map +1 -1
  7. package/cjs/core/MantineProvider/color-functions/default-variant-colors-resolver/v8-default-variant-colors-resolver.cjs +196 -0
  8. package/cjs/core/MantineProvider/color-functions/default-variant-colors-resolver/v8-default-variant-colors-resolver.cjs.map +1 -0
  9. package/cjs/index.cjs +2 -2
  10. package/esm/components/NumberInput/NumberInput.mjs +514 -291
  11. package/esm/components/NumberInput/NumberInput.mjs.map +1 -1
  12. package/esm/components/ScrollArea/ScrollArea.mjs +12 -1
  13. package/esm/components/ScrollArea/ScrollArea.mjs.map +1 -1
  14. package/esm/components/Tooltip/Tooltip.mjs +3 -1
  15. package/esm/components/Tooltip/Tooltip.mjs.map +1 -1
  16. package/esm/core/MantineProvider/color-functions/default-variant-colors-resolver/v8-default-variant-colors-resolver.mjs +194 -0
  17. package/esm/core/MantineProvider/color-functions/default-variant-colors-resolver/v8-default-variant-colors-resolver.mjs.map +1 -0
  18. package/esm/index.mjs +1 -1
  19. package/lib/components/Input/use-input-props.d.ts +4 -4
  20. package/lib/components/NumberInput/NumberInput.d.ts +42 -10
  21. package/lib/components/NumberInput/index.d.ts +3 -3
  22. package/lib/components/Popover/use-popover.d.ts +1 -1
  23. package/lib/components/ScrollArea/ScrollArea.d.ts +5 -0
  24. package/lib/core/MantineProvider/MantineCssVariables/index.d.ts +1 -0
  25. package/lib/core/MantineProvider/MantineCssVariables/v8-css-variables-resolver.d.ts +2 -0
  26. package/lib/core/MantineProvider/color-functions/default-variant-colors-resolver/v8-default-variant-colors-resolver.d.ts +2 -0
  27. package/package.json +2 -2
  28. package/styles/AppShell.css +11 -1
  29. package/styles/AppShell.layer.css +11 -1
  30. package/styles.css +11 -1
  31. package/styles.layer.css +11 -1
  32. package/cjs/components/Slider/utils/get-floating-value/get-gloating-value.cjs +0 -9
  33. package/cjs/components/Slider/utils/get-floating-value/get-gloating-value.cjs.map +0 -1
  34. package/esm/components/Slider/utils/get-floating-value/get-gloating-value.mjs +0 -7
  35. package/esm/components/Slider/utils/get-floating-value/get-gloating-value.mjs.map +0 -1
  36. package/lib/components/Slider/utils/get-floating-value/get-gloating-value.d.ts +0 -1
@@ -37,12 +37,61 @@ const trailingDecimalSeparatorPattern = /^-?\d+\.$/;
37
37
  function isNumberString(value) {
38
38
  return typeof value === "string" && value !== "" && !Number.isNaN(Number(value));
39
39
  }
40
+ function isBigIntValue(value) {
41
+ return typeof value === "bigint";
42
+ }
40
43
  function canStep(value) {
41
44
  if (typeof value === "number") {
42
45
  return value < Number.MAX_SAFE_INTEGER;
43
46
  }
44
47
  return value === "" || isNumberString(value) && Number(value) < Number.MAX_SAFE_INTEGER;
45
48
  }
49
+ function isValidBigIntString(value, allowNegative) {
50
+ if (value === "") {
51
+ return false;
52
+ }
53
+ if (value === "-") {
54
+ return false;
55
+ }
56
+ if (!allowNegative && value.startsWith("-")) {
57
+ return false;
58
+ }
59
+ return /^-?\d+$/.test(value);
60
+ }
61
+ function canStepBigInt(value, allowNegative) {
62
+ if (typeof value === "bigint") {
63
+ return true;
64
+ }
65
+ return value === "" || isValidBigIntString(value, allowNegative);
66
+ }
67
+ function parseBigIntFromString(value) {
68
+ if (!/^-?\d+$/.test(value)) {
69
+ return null;
70
+ }
71
+ try {
72
+ return BigInt(value);
73
+ } catch {
74
+ return null;
75
+ }
76
+ }
77
+ function toBigIntOrUndefined(value) {
78
+ if (typeof value === "bigint") {
79
+ return value;
80
+ }
81
+ if (typeof value === "number" && Number.isFinite(value) && Number.isInteger(value)) {
82
+ return BigInt(value);
83
+ }
84
+ return void 0;
85
+ }
86
+ function clampBigInt(value, min, max) {
87
+ if (min !== void 0 && value < min) {
88
+ return min;
89
+ }
90
+ if (max !== void 0 && value > max) {
91
+ return max;
92
+ }
93
+ return value;
94
+ }
46
95
  function getTotalDigits(inputValue) {
47
96
  return inputValue.toString().replace(".", "").length;
48
97
  }
@@ -91,306 +140,480 @@ function clampAndSanitizeInput(sanitizedValue, max, min) {
91
140
  }
92
141
  return clamped;
93
142
  }
94
- const NumberInput = factory.factory((_props) => {
95
- const props = useProps.useProps("NumberInput", defaultProps, _props);
96
- const {
97
- className,
98
- classNames,
99
- styles,
100
- unstyled,
101
- vars,
102
- onChange,
103
- onValueChange,
104
- value,
105
- defaultValue,
106
- max,
107
- min,
108
- step,
109
- hideControls,
110
- rightSection,
111
- isAllowed,
112
- clampBehavior,
113
- onBlur,
114
- allowDecimal,
115
- decimalScale,
116
- onKeyDown,
117
- onKeyDownCapture,
118
- handlersRef,
119
- startValue,
120
- disabled,
121
- rightSectionPointerEvents,
122
- allowNegative,
123
- readOnly,
124
- size,
125
- rightSectionWidth,
126
- stepHoldInterval,
127
- stepHoldDelay,
128
- allowLeadingZeros,
129
- withKeyboardEvents,
130
- trimLeadingZeroesOnBlur,
131
- allowedDecimalSeparators,
132
- selectAllOnFocus,
133
- onMinReached,
134
- onMaxReached,
135
- onFocus,
136
- attributes,
137
- ref,
138
- ...others
139
- } = props;
140
- const getStyles = useStyles.useStyles({
141
- name: "NumberInput",
142
- classes: NumberInput_module,
143
- props,
144
- classNames,
145
- styles,
146
- unstyled,
147
- attributes,
148
- vars,
149
- varsResolver
150
- });
151
- const { resolvedClassNames, resolvedStyles } = useResolvedStylesApi.useResolvedStylesApi({
152
- classNames,
153
- styles,
154
- props
155
- });
156
- const [_value, setValue] = hooks.useUncontrolled({
157
- value,
158
- defaultValue,
159
- finalValue: "",
160
- onChange
161
- });
162
- const shouldUseStepInterval = stepHoldDelay !== void 0 && stepHoldInterval !== void 0;
163
- const inputRef = React.useRef(null);
164
- const onStepTimeoutRef = React.useRef(null);
165
- const stepCountRef = React.useRef(0);
166
- const handleValueChange = (payload, event) => {
167
- if (event.source === "event") {
168
- setValue(
169
- isValidNumber(payload.floatValue, payload.value) && !leadingDecimalZeroPattern.test(payload.value) && !(allowLeadingZeros ? leadingZerosPattern.test(payload.value) : false) && !trailingZerosPattern.test(payload.value) && !trailingDecimalSeparatorPattern.test(payload.value) ? payload.floatValue : payload.value
170
- );
171
- }
172
- onValueChange?.(payload, event);
173
- };
174
- const getDecimalPlaces = (inputValue) => {
175
- const match = String(inputValue).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);
176
- if (!match) {
177
- return 0;
178
- }
179
- return Math.max(0, (match[1] ? match[1].length : 0) - (match[2] ? +match[2] : 0));
180
- };
181
- const adjustCursor = (position) => {
182
- if (inputRef.current && typeof position !== "undefined") {
183
- inputRef.current.setSelectionRange(position, position);
184
- }
185
- };
186
- const incrementRef = React.useRef(noop.noop);
187
- incrementRef.current = () => {
188
- if (!canStep(_value)) {
189
- return;
190
- }
191
- let val;
192
- const currentValuePrecision = getDecimalPlaces(_value);
193
- const stepPrecision = getDecimalPlaces(step);
194
- const maxPrecision = Math.max(currentValuePrecision, stepPrecision);
195
- const factor = 10 ** maxPrecision;
196
- if (!isNumberString(_value) && (typeof _value !== "number" || Number.isNaN(_value))) {
197
- val = hooks.clamp(startValue, min, max);
198
- } else if (max !== void 0) {
199
- const incrementedValue = (Math.round(Number(_value) * factor) + Math.round(step * factor)) / factor;
200
- if (incrementedValue > max) {
201
- onMaxReached?.();
202
- }
203
- val = incrementedValue <= max ? incrementedValue : max;
204
- } else {
205
- val = (Math.round(Number(_value) * factor) + Math.round(step * factor)) / factor;
206
- }
207
- const formattedValue = val.toFixed(maxPrecision);
208
- setValue(parseFloat(formattedValue));
209
- onValueChange?.(
210
- { floatValue: parseFloat(formattedValue), formattedValue, value: formattedValue },
211
- { source: "increment" }
143
+ function clampAndSanitizeBigIntInput(sanitizedValue, options) {
144
+ if (sanitizedValue === "" || sanitizedValue === "-") {
145
+ return sanitizedValue;
146
+ }
147
+ const parsed = parseBigIntFromString(sanitizedValue);
148
+ if (parsed === null) {
149
+ return sanitizedValue;
150
+ }
151
+ return options.clampBehavior === "blur" ? clampBigInt(parsed, options.min, options.max) : parsed;
152
+ }
153
+ const NumberInput = factory.genericFactory(
154
+ (_props) => {
155
+ const props = useProps.useProps(
156
+ "NumberInput",
157
+ defaultProps,
158
+ _props
212
159
  );
213
- setTimeout(() => adjustCursor(inputRef.current?.value.length), 0);
214
- };
215
- const decrementRef = React.useRef(noop.noop);
216
- decrementRef.current = () => {
217
- if (!canStep(_value)) {
218
- return;
219
- }
220
- let val;
221
- const minValue = min !== void 0 ? min : !allowNegative ? 0 : Number.MIN_SAFE_INTEGER;
222
- const currentValuePrecision = getDecimalPlaces(_value);
223
- const stepPrecision = getDecimalPlaces(step);
224
- const maxPrecision = Math.max(currentValuePrecision, stepPrecision);
225
- const factor = 10 ** maxPrecision;
226
- if (!isNumberString(_value) && typeof _value !== "number" || Number.isNaN(_value)) {
227
- val = hooks.clamp(startValue, minValue, max);
228
- } else {
229
- const decrementedValue = (Math.round(Number(_value) * factor) - Math.round(step * factor)) / factor;
230
- if (minValue !== void 0 && decrementedValue < minValue) {
231
- onMinReached?.();
232
- }
233
- val = minValue !== void 0 && decrementedValue < minValue ? minValue : decrementedValue;
234
- }
235
- const formattedValue = val.toFixed(maxPrecision);
236
- setValue(parseFloat(formattedValue));
237
- onValueChange?.(
238
- { floatValue: parseFloat(formattedValue), formattedValue, value: formattedValue },
239
- { source: "decrement" }
160
+ const {
161
+ className,
162
+ classNames,
163
+ styles,
164
+ unstyled,
165
+ vars,
166
+ onChange,
167
+ onValueChange,
168
+ value,
169
+ defaultValue,
170
+ max,
171
+ min,
172
+ step,
173
+ hideControls,
174
+ rightSection,
175
+ isAllowed,
176
+ clampBehavior,
177
+ onBlur,
178
+ allowDecimal,
179
+ decimalScale,
180
+ onKeyDown,
181
+ onKeyDownCapture,
182
+ handlersRef,
183
+ startValue,
184
+ disabled,
185
+ rightSectionPointerEvents,
186
+ allowNegative,
187
+ readOnly,
188
+ size,
189
+ rightSectionWidth,
190
+ stepHoldInterval,
191
+ stepHoldDelay,
192
+ allowLeadingZeros,
193
+ withKeyboardEvents,
194
+ trimLeadingZeroesOnBlur,
195
+ allowedDecimalSeparators,
196
+ selectAllOnFocus,
197
+ onMinReached,
198
+ onMaxReached,
199
+ onFocus,
200
+ attributes,
201
+ ref,
202
+ ...others
203
+ } = props;
204
+ const allowNegativeResolved = allowNegative ?? true;
205
+ const allowLeadingZerosResolved = allowLeadingZeros ?? true;
206
+ const getStyles = useStyles.useStyles({
207
+ name: "NumberInput",
208
+ classes: NumberInput_module,
209
+ props,
210
+ classNames,
211
+ styles,
212
+ unstyled,
213
+ attributes,
214
+ vars,
215
+ varsResolver
216
+ });
217
+ const { resolvedClassNames, resolvedStyles } = useResolvedStylesApi.useResolvedStylesApi({
218
+ classNames,
219
+ styles,
220
+ props
221
+ });
222
+ const valueModeRef = React.useRef(
223
+ isBigIntValue(value) || isBigIntValue(defaultValue) ? "bigint" : "number"
240
224
  );
241
- setTimeout(() => adjustCursor(inputRef.current?.value.length), 0);
242
- };
243
- const handleKeyDown = (event) => {
244
- onKeyDown?.(event);
245
- if (readOnly || !withKeyboardEvents) {
246
- return;
247
- }
248
- if (event.key === "ArrowUp") {
249
- event.preventDefault();
250
- incrementRef.current?.();
225
+ if (isBigIntValue(value)) {
226
+ valueModeRef.current = "bigint";
227
+ } else if (typeof value === "number") {
228
+ valueModeRef.current = "number";
251
229
  }
252
- if (event.key === "ArrowDown") {
253
- event.preventDefault();
254
- decrementRef.current?.();
255
- }
256
- };
257
- const handleKeyDownCapture = (event) => {
258
- onKeyDownCapture?.(event);
259
- if (event.key === "Backspace") {
260
- const input = inputRef.current;
261
- if (input && input.selectionStart === 0 && input.selectionStart === input.selectionEnd) {
230
+ const isBigIntMode = valueModeRef.current === "bigint";
231
+ const [_value, setValue] = hooks.useUncontrolled({
232
+ value,
233
+ defaultValue,
234
+ finalValue: "",
235
+ onChange
236
+ });
237
+ const shouldUseStepInterval = stepHoldDelay !== void 0 && stepHoldInterval !== void 0;
238
+ const inputRef = React.useRef(null);
239
+ const onStepTimeoutRef = React.useRef(null);
240
+ const stepCountRef = React.useRef(0);
241
+ const minNumber = typeof min === "number" ? min : void 0;
242
+ const maxNumber = typeof max === "number" ? max : void 0;
243
+ const stepNumber = typeof step === "number" ? step : defaultProps.step;
244
+ const startValueNumber = typeof startValue === "number" ? startValue : defaultProps.startValue;
245
+ const minBigInt = toBigIntOrUndefined(min);
246
+ const maxBigInt = toBigIntOrUndefined(max);
247
+ const stepBigInt = toBigIntOrUndefined(step) ?? BigInt(1);
248
+ const startValueBigInt = toBigIntOrUndefined(startValue) ?? BigInt(0);
249
+ const parseBigIntOrString = (inputValue) => {
250
+ if (!isValidBigIntString(inputValue, allowNegativeResolved) || allowLeadingZerosResolved && leadingZerosPattern.test(inputValue)) {
251
+ return inputValue;
252
+ }
253
+ const parsed = parseBigIntFromString(inputValue);
254
+ return parsed ?? inputValue;
255
+ };
256
+ const getBigIntFloatValue = (inputValue) => {
257
+ const numericValue = Number(inputValue);
258
+ return Number.isSafeInteger(numericValue) ? numericValue : void 0;
259
+ };
260
+ const handleValueChange = (payload, event) => {
261
+ if (event.source === "event") {
262
+ if (isBigIntMode) {
263
+ setValue(parseBigIntOrString(payload.value));
264
+ } else {
265
+ setValue(
266
+ isValidNumber(payload.floatValue, payload.value) && !leadingDecimalZeroPattern.test(payload.value) && !(allowLeadingZerosResolved ? leadingZerosPattern.test(payload.value) : false) && !trailingZerosPattern.test(payload.value) && !trailingDecimalSeparatorPattern.test(payload.value) ? payload.floatValue : payload.value
267
+ );
268
+ }
269
+ }
270
+ onValueChange?.(payload, event);
271
+ };
272
+ const getDecimalPlaces = (inputValue) => {
273
+ const match = String(inputValue).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);
274
+ if (!match) {
275
+ return 0;
276
+ }
277
+ return Math.max(0, (match[1] ? match[1].length : 0) - (match[2] ? +match[2] : 0));
278
+ };
279
+ const adjustCursor = (position) => {
280
+ if (inputRef.current && typeof position !== "undefined") {
281
+ inputRef.current.setSelectionRange(position, position);
282
+ }
283
+ };
284
+ const incrementRef = React.useRef(noop.noop);
285
+ incrementRef.current = () => {
286
+ if (isBigIntMode) {
287
+ if (!canStepBigInt(_value, allowNegativeResolved)) {
288
+ return;
289
+ }
290
+ let val2;
291
+ const currentValue = _value;
292
+ if (typeof currentValue === "bigint") {
293
+ const incrementedValue = currentValue + stepBigInt;
294
+ if (maxBigInt !== void 0 && incrementedValue > maxBigInt) {
295
+ onMaxReached?.();
296
+ }
297
+ val2 = maxBigInt !== void 0 && incrementedValue > maxBigInt ? maxBigInt : incrementedValue;
298
+ } else if (typeof currentValue === "string" && currentValue !== "") {
299
+ const parsed = parseBigIntFromString(currentValue);
300
+ if (parsed === null) {
301
+ return;
302
+ }
303
+ const incrementedValue = parsed + stepBigInt;
304
+ if (maxBigInt !== void 0 && incrementedValue > maxBigInt) {
305
+ onMaxReached?.();
306
+ }
307
+ val2 = maxBigInt !== void 0 && incrementedValue > maxBigInt ? maxBigInt : incrementedValue;
308
+ } else {
309
+ val2 = clampBigInt(startValueBigInt, minBigInt, maxBigInt);
310
+ }
311
+ const formattedValue2 = val2.toString();
312
+ setValue(val2);
313
+ onValueChange?.(
314
+ { floatValue: getBigIntFloatValue(val2), formattedValue: formattedValue2, value: formattedValue2 },
315
+ { source: "increment" }
316
+ );
317
+ setTimeout(() => adjustCursor(inputRef.current?.value.length), 0);
318
+ return;
319
+ }
320
+ if (!canStep(_value)) {
321
+ return;
322
+ }
323
+ let val;
324
+ const currentValuePrecision = getDecimalPlaces(_value);
325
+ const stepPrecision = getDecimalPlaces(stepNumber);
326
+ const maxPrecision = Math.max(currentValuePrecision, stepPrecision);
327
+ const factor = 10 ** maxPrecision;
328
+ if (!isNumberString(_value) && (typeof _value !== "number" || Number.isNaN(_value))) {
329
+ val = hooks.clamp(startValueNumber, minNumber, maxNumber);
330
+ } else if (maxNumber !== void 0) {
331
+ const incrementedValue = (Math.round(Number(_value) * factor) + Math.round(stepNumber * factor)) / factor;
332
+ if (incrementedValue > maxNumber) {
333
+ onMaxReached?.();
334
+ }
335
+ val = incrementedValue <= maxNumber ? incrementedValue : maxNumber;
336
+ } else {
337
+ val = (Math.round(Number(_value) * factor) + Math.round(stepNumber * factor)) / factor;
338
+ }
339
+ const formattedValue = val.toFixed(maxPrecision);
340
+ setValue(parseFloat(formattedValue));
341
+ onValueChange?.(
342
+ { floatValue: parseFloat(formattedValue), formattedValue, value: formattedValue },
343
+ { source: "increment" }
344
+ );
345
+ setTimeout(() => adjustCursor(inputRef.current?.value.length), 0);
346
+ };
347
+ const decrementRef = React.useRef(noop.noop);
348
+ decrementRef.current = () => {
349
+ if (isBigIntMode) {
350
+ if (!canStepBigInt(_value, allowNegativeResolved)) {
351
+ return;
352
+ }
353
+ let val2;
354
+ const minValue2 = minBigInt !== void 0 ? minBigInt : !allowNegativeResolved ? BigInt(0) : void 0;
355
+ const currentValue = _value;
356
+ if (typeof currentValue === "bigint") {
357
+ const decrementedValue = currentValue - stepBigInt;
358
+ if (minValue2 !== void 0 && decrementedValue < minValue2) {
359
+ onMinReached?.();
360
+ }
361
+ val2 = minValue2 !== void 0 && decrementedValue < minValue2 ? minValue2 : decrementedValue;
362
+ } else if (typeof currentValue === "string" && currentValue !== "") {
363
+ const parsed = parseBigIntFromString(currentValue);
364
+ if (parsed === null) {
365
+ return;
366
+ }
367
+ const decrementedValue = parsed - stepBigInt;
368
+ if (minValue2 !== void 0 && decrementedValue < minValue2) {
369
+ onMinReached?.();
370
+ }
371
+ val2 = minValue2 !== void 0 && decrementedValue < minValue2 ? minValue2 : decrementedValue;
372
+ } else {
373
+ val2 = clampBigInt(startValueBigInt, minValue2, maxBigInt);
374
+ }
375
+ const formattedValue2 = val2.toString();
376
+ setValue(val2);
377
+ onValueChange?.(
378
+ { floatValue: getBigIntFloatValue(val2), formattedValue: formattedValue2, value: formattedValue2 },
379
+ { source: "decrement" }
380
+ );
381
+ setTimeout(() => adjustCursor(inputRef.current?.value.length), 0);
382
+ return;
383
+ }
384
+ if (!canStep(_value)) {
385
+ return;
386
+ }
387
+ let val;
388
+ const minValue = minNumber !== void 0 ? minNumber : !allowNegativeResolved ? 0 : Number.MIN_SAFE_INTEGER;
389
+ const currentValuePrecision = getDecimalPlaces(_value);
390
+ const stepPrecision = getDecimalPlaces(stepNumber);
391
+ const maxPrecision = Math.max(currentValuePrecision, stepPrecision);
392
+ const factor = 10 ** maxPrecision;
393
+ if (!isNumberString(_value) && typeof _value !== "number" || Number.isNaN(_value)) {
394
+ val = hooks.clamp(startValueNumber, minValue, maxNumber);
395
+ } else {
396
+ const decrementedValue = (Math.round(Number(_value) * factor) - Math.round(stepNumber * factor)) / factor;
397
+ if (minValue !== void 0 && decrementedValue < minValue) {
398
+ onMinReached?.();
399
+ }
400
+ val = minValue !== void 0 && decrementedValue < minValue ? minValue : decrementedValue;
401
+ }
402
+ const formattedValue = val.toFixed(maxPrecision);
403
+ setValue(parseFloat(formattedValue));
404
+ onValueChange?.(
405
+ { floatValue: parseFloat(formattedValue), formattedValue, value: formattedValue },
406
+ { source: "decrement" }
407
+ );
408
+ setTimeout(() => adjustCursor(inputRef.current?.value.length), 0);
409
+ };
410
+ const handlePaste = (event) => {
411
+ const pastedText = event.clipboardData.getData("text");
412
+ const _decimalSeparator = others.decimalSeparator || ".";
413
+ const separatorsToReplace = (allowedDecimalSeparators || [".", ","]).filter(
414
+ (s) => s !== _decimalSeparator
415
+ );
416
+ if (separatorsToReplace.some((s) => pastedText.includes(s))) {
262
417
  event.preventDefault();
263
- window.setTimeout(() => adjustCursor(0), 0);
418
+ let modifiedText = pastedText;
419
+ separatorsToReplace.forEach((s) => {
420
+ modifiedText = modifiedText.split(s).join(_decimalSeparator);
421
+ });
422
+ const input = inputRef.current;
423
+ if (input) {
424
+ const start = input.selectionStart ?? 0;
425
+ const end = input.selectionEnd ?? 0;
426
+ const currentValue = input.value;
427
+ const newValue = currentValue.substring(0, start) + modifiedText + currentValue.substring(end);
428
+ const nativeInputValueSetter = Object.getOwnPropertyDescriptor(
429
+ window.HTMLInputElement.prototype,
430
+ "value"
431
+ )?.set;
432
+ nativeInputValueSetter?.call(input, newValue);
433
+ input.dispatchEvent(new Event("change", { bubbles: true }));
434
+ const cursorPos = start + modifiedText.length;
435
+ setTimeout(() => adjustCursor(cursorPos), 0);
436
+ }
264
437
  }
265
- }
266
- };
267
- const handleFocus = (event) => {
268
- if (selectAllOnFocus) {
269
- setTimeout(() => event.currentTarget.select(), 0);
270
- }
271
- onFocus?.(event);
272
- };
273
- const handleBlur = (event) => {
274
- let sanitizedValue = _value;
275
- if (clampBehavior === "blur" && typeof sanitizedValue === "number") {
276
- sanitizedValue = hooks.clamp(sanitizedValue, min, max);
277
- }
278
- if (trimLeadingZeroesOnBlur && typeof sanitizedValue === "string" && getDecimalPlaces(sanitizedValue) < 15) {
279
- sanitizedValue = clampAndSanitizeInput(sanitizedValue, max, min);
280
- }
281
- if (_value !== sanitizedValue) {
282
- setValue(sanitizedValue);
283
- }
284
- onBlur?.(event);
285
- };
286
- hooks.assignRef(handlersRef, { increment: incrementRef.current, decrement: decrementRef.current });
287
- const onStepHandleChange = (isIncrement) => {
288
- if (isIncrement) {
289
- incrementRef.current?.();
290
- } else {
291
- decrementRef.current?.();
292
- }
293
- stepCountRef.current += 1;
294
- };
295
- const onStepLoop = (isIncrement) => {
296
- onStepHandleChange(isIncrement);
297
- if (shouldUseStepInterval) {
298
- const interval = typeof stepHoldInterval === "number" ? stepHoldInterval : stepHoldInterval(stepCountRef.current);
299
- onStepTimeoutRef.current = window.setTimeout(() => onStepLoop(isIncrement), interval);
300
- }
301
- };
302
- const onStep = (event, isIncrement) => {
303
- event.preventDefault();
304
- inputRef.current?.focus();
305
- onStepHandleChange(isIncrement);
306
- if (shouldUseStepInterval) {
307
- onStepTimeoutRef.current = window.setTimeout(() => onStepLoop(isIncrement), stepHoldDelay);
308
- }
309
- };
310
- const onStepDone = () => {
311
- if (onStepTimeoutRef.current) {
312
- window.clearTimeout(onStepTimeoutRef.current);
313
- }
314
- onStepTimeoutRef.current = null;
315
- stepCountRef.current = 0;
316
- };
317
- const controls = /* @__PURE__ */ jsxRuntime.jsxs("div", { ...getStyles("controls"), children: [
318
- /* @__PURE__ */ jsxRuntime.jsx(
319
- UnstyledButton.UnstyledButton,
320
- {
321
- ...getStyles("control"),
322
- tabIndex: -1,
323
- "aria-hidden": true,
324
- disabled: disabled || typeof _value === "number" && max !== void 0 && _value >= max,
325
- mod: { direction: "up" },
326
- onMouseDown: (event) => event.preventDefault(),
327
- onPointerDown: (event) => {
328
- onStep(event, true);
329
- },
330
- onPointerUp: onStepDone,
331
- onPointerLeave: onStepDone,
332
- children: /* @__PURE__ */ jsxRuntime.jsx(NumberInputChevron.NumberInputChevron, { direction: "up" })
438
+ others.onPaste?.(event);
439
+ };
440
+ const handleKeyDown = (event) => {
441
+ onKeyDown?.(event);
442
+ if (readOnly || !withKeyboardEvents) {
443
+ return;
333
444
  }
334
- ),
335
- /* @__PURE__ */ jsxRuntime.jsx(
336
- UnstyledButton.UnstyledButton,
337
- {
338
- ...getStyles("control"),
339
- tabIndex: -1,
340
- "aria-hidden": true,
341
- disabled: disabled || typeof _value === "number" && min !== void 0 && _value <= min,
342
- mod: { direction: "down" },
343
- onMouseDown: (event) => event.preventDefault(),
344
- onPointerDown: (event) => {
345
- onStep(event, false);
346
- },
347
- onPointerUp: onStepDone,
348
- onPointerLeave: onStepDone,
349
- children: /* @__PURE__ */ jsxRuntime.jsx(NumberInputChevron.NumberInputChevron, { direction: "down" })
445
+ if (event.key === "ArrowUp") {
446
+ event.preventDefault();
447
+ incrementRef.current?.();
350
448
  }
351
- )
352
- ] });
353
- return /* @__PURE__ */ jsxRuntime.jsx(
354
- InputBase.InputBase,
355
- {
356
- component: reactNumberFormat.NumericFormat,
357
- allowNegative,
358
- className: cx__default.default(NumberInput_module.root, className),
359
- size,
360
- inputMode: "decimal",
361
- ...others,
362
- readOnly,
363
- disabled,
364
- value: _value,
365
- getInputRef: hooks.useMergedRef(ref, inputRef),
366
- onValueChange: handleValueChange,
367
- rightSection: hideControls || readOnly || !canStep(_value) ? rightSection : rightSection || controls,
368
- classNames: resolvedClassNames,
369
- styles: resolvedStyles,
370
- unstyled,
371
- __staticSelector: "NumberInput",
372
- decimalScale: allowDecimal ? decimalScale : 0,
373
- onFocus: handleFocus,
374
- onKeyDown: handleKeyDown,
375
- onKeyDownCapture: handleKeyDownCapture,
376
- rightSectionPointerEvents: rightSectionPointerEvents ?? (disabled ? "none" : void 0),
377
- rightSectionWidth: rightSectionWidth ?? `var(--ni-right-section-width-${size || "sm"})`,
378
- allowLeadingZeros,
379
- allowedDecimalSeparators,
380
- onBlur: handleBlur,
381
- attributes,
382
- isAllowed: (val) => {
383
- if (clampBehavior === "strict") {
384
- if (isAllowed) {
385
- return isAllowed(val) && isInRange(val.floatValue, min, max);
449
+ if (event.key === "ArrowDown") {
450
+ event.preventDefault();
451
+ decrementRef.current?.();
452
+ }
453
+ };
454
+ const handleKeyDownCapture = (event) => {
455
+ onKeyDownCapture?.(event);
456
+ if (event.key === "Backspace") {
457
+ const input = inputRef.current;
458
+ if (input && input.selectionStart === 0 && input.selectionStart === input.selectionEnd) {
459
+ event.preventDefault();
460
+ window.setTimeout(() => adjustCursor(0), 0);
461
+ }
462
+ }
463
+ };
464
+ const handleFocus = (event) => {
465
+ if (selectAllOnFocus) {
466
+ setTimeout(() => event.currentTarget.select(), 0);
467
+ }
468
+ onFocus?.(event);
469
+ };
470
+ const handleBlur = (event) => {
471
+ let sanitizedValue = _value;
472
+ if (isBigIntMode) {
473
+ if (clampBehavior === "blur" && typeof sanitizedValue === "bigint") {
474
+ sanitizedValue = clampBigInt(sanitizedValue, minBigInt, maxBigInt);
475
+ }
476
+ if (trimLeadingZeroesOnBlur && typeof sanitizedValue === "string") {
477
+ sanitizedValue = clampAndSanitizeBigIntInput(sanitizedValue, {
478
+ min: minBigInt,
479
+ max: maxBigInt,
480
+ clampBehavior
481
+ });
482
+ }
483
+ } else {
484
+ if (clampBehavior === "blur" && typeof sanitizedValue === "number") {
485
+ sanitizedValue = hooks.clamp(sanitizedValue, minNumber, maxNumber);
486
+ }
487
+ if (trimLeadingZeroesOnBlur && typeof sanitizedValue === "string" && getDecimalPlaces(sanitizedValue) < 15) {
488
+ sanitizedValue = clampAndSanitizeInput(sanitizedValue, maxNumber, minNumber);
489
+ }
490
+ }
491
+ if (_value !== sanitizedValue) {
492
+ setValue(sanitizedValue);
493
+ }
494
+ onBlur?.(event);
495
+ };
496
+ hooks.assignRef(handlersRef, { increment: incrementRef.current, decrement: decrementRef.current });
497
+ const onStepHandleChange = (isIncrement) => {
498
+ if (isIncrement) {
499
+ incrementRef.current?.();
500
+ } else {
501
+ decrementRef.current?.();
502
+ }
503
+ stepCountRef.current += 1;
504
+ };
505
+ const onStepLoop = (isIncrement) => {
506
+ onStepHandleChange(isIncrement);
507
+ if (shouldUseStepInterval) {
508
+ const interval = typeof stepHoldInterval === "number" ? stepHoldInterval : stepHoldInterval(stepCountRef.current);
509
+ onStepTimeoutRef.current = window.setTimeout(() => onStepLoop(isIncrement), interval);
510
+ }
511
+ };
512
+ const onStep = (event, isIncrement) => {
513
+ event.preventDefault();
514
+ inputRef.current?.focus();
515
+ onStepHandleChange(isIncrement);
516
+ if (shouldUseStepInterval) {
517
+ onStepTimeoutRef.current = window.setTimeout(() => onStepLoop(isIncrement), stepHoldDelay);
518
+ }
519
+ };
520
+ const onStepDone = () => {
521
+ if (onStepTimeoutRef.current) {
522
+ window.clearTimeout(onStepTimeoutRef.current);
523
+ }
524
+ onStepTimeoutRef.current = null;
525
+ stepCountRef.current = 0;
526
+ };
527
+ const controls = /* @__PURE__ */ jsxRuntime.jsxs("div", { ...getStyles("controls"), children: [
528
+ /* @__PURE__ */ jsxRuntime.jsx(
529
+ UnstyledButton.UnstyledButton,
530
+ {
531
+ ...getStyles("control"),
532
+ tabIndex: -1,
533
+ "aria-hidden": true,
534
+ disabled: disabled || typeof _value === "number" && maxNumber !== void 0 && _value >= maxNumber || typeof _value === "bigint" && maxBigInt !== void 0 && _value >= maxBigInt,
535
+ mod: { direction: "up" },
536
+ onMouseDown: (event) => event.preventDefault(),
537
+ onPointerDown: (event) => {
538
+ onStep(event, true);
539
+ },
540
+ onPointerUp: onStepDone,
541
+ onPointerLeave: onStepDone,
542
+ children: /* @__PURE__ */ jsxRuntime.jsx(NumberInputChevron.NumberInputChevron, { direction: "up" })
543
+ }
544
+ ),
545
+ /* @__PURE__ */ jsxRuntime.jsx(
546
+ UnstyledButton.UnstyledButton,
547
+ {
548
+ ...getStyles("control"),
549
+ tabIndex: -1,
550
+ "aria-hidden": true,
551
+ disabled: disabled || typeof _value === "number" && minNumber !== void 0 && _value <= minNumber || typeof _value === "bigint" && minBigInt !== void 0 && _value <= minBigInt,
552
+ mod: { direction: "down" },
553
+ onMouseDown: (event) => event.preventDefault(),
554
+ onPointerDown: (event) => {
555
+ onStep(event, false);
556
+ },
557
+ onPointerUp: onStepDone,
558
+ onPointerLeave: onStepDone,
559
+ children: /* @__PURE__ */ jsxRuntime.jsx(NumberInputChevron.NumberInputChevron, { direction: "down" })
560
+ }
561
+ )
562
+ ] });
563
+ return /* @__PURE__ */ jsxRuntime.jsx(
564
+ InputBase.InputBase,
565
+ {
566
+ component: reactNumberFormat.NumericFormat,
567
+ allowNegative,
568
+ className: cx__default.default(NumberInput_module.root, className),
569
+ size,
570
+ ...others,
571
+ inputMode: isBigIntMode ? "numeric" : "decimal",
572
+ readOnly,
573
+ disabled,
574
+ value: typeof _value === "bigint" ? _value.toString() : _value,
575
+ getInputRef: hooks.useMergedRef(ref, inputRef),
576
+ onValueChange: handleValueChange,
577
+ rightSection: hideControls || readOnly || !(isBigIntMode ? canStepBigInt(_value, allowNegativeResolved) : canStep(_value)) ? rightSection : rightSection || controls,
578
+ classNames: resolvedClassNames,
579
+ styles: resolvedStyles,
580
+ unstyled,
581
+ __staticSelector: "NumberInput",
582
+ decimalScale: isBigIntMode ? 0 : allowDecimal ? decimalScale : 0,
583
+ onPaste: handlePaste,
584
+ onFocus: handleFocus,
585
+ onKeyDown: handleKeyDown,
586
+ onKeyDownCapture: handleKeyDownCapture,
587
+ rightSectionPointerEvents: rightSectionPointerEvents ?? (disabled ? "none" : void 0),
588
+ rightSectionWidth: rightSectionWidth ?? `var(--ni-right-section-width-${size || "sm"})`,
589
+ allowLeadingZeros,
590
+ allowedDecimalSeparators,
591
+ onBlur: handleBlur,
592
+ attributes,
593
+ isAllowed: (val) => {
594
+ const userAllowed = isAllowed ? isAllowed(val) : true;
595
+ if (!userAllowed) {
596
+ return false;
386
597
  }
387
- return isInRange(val.floatValue, min, max);
598
+ if (clampBehavior !== "strict") {
599
+ return true;
600
+ }
601
+ if (!isBigIntMode) {
602
+ return isInRange(val.floatValue, minNumber, maxNumber);
603
+ }
604
+ if (val.value === "" || val.value === "-") {
605
+ return true;
606
+ }
607
+ const parsed = parseBigIntFromString(val.value);
608
+ if (parsed === null) {
609
+ return true;
610
+ }
611
+ return (minBigInt === void 0 || parsed >= minBigInt) && (maxBigInt === void 0 || parsed <= maxBigInt);
388
612
  }
389
- return isAllowed ? isAllowed(val) : true;
390
613
  }
391
- }
392
- );
393
- });
614
+ );
615
+ }
616
+ );
394
617
  NumberInput.classes = { ...InputBase.InputBase.classes, ...NumberInput_module };
395
618
  NumberInput.varsResolver = varsResolver;
396
619
  NumberInput.displayName = "@mantine/core/NumberInput";