numora-react 3.0.3 → 3.2.0

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/index.mjs CHANGED
@@ -1,429 +1,8 @@
1
- import require$$0, { forwardRef, useRef, useState, useLayoutEffect, useEffect, useCallback } from 'react';
2
- import { handleOnChangeNumoraInput, handleOnKeyDownNumoraInput, handleOnPasteNumoraInput, FormatOn, formatValueForDisplay, ThousandStyle, removeThousandSeparators } from 'numora';
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import { forwardRef, useRef, useMemo, useState, useLayoutEffect, useEffect, useCallback } from 'react';
3
+ import { handleOnChangeNumoraInput, handleOnKeyDownNumoraInput, handleOnPasteNumoraInput, FormatOn, formatValueForDisplay, ThousandStyle, validateNumoraInputOptions, resolveLocaleOptions, removeThousandSeparators } from 'numora';
3
4
  export { FormatOn, ThousandStyle } from 'numora';
4
5
 
5
- var jsxRuntime = {exports: {}};
6
-
7
- var reactJsxRuntime_production = {};
8
-
9
- /**
10
- * @license React
11
- * react-jsx-runtime.production.js
12
- *
13
- * Copyright (c) Meta Platforms, Inc. and affiliates.
14
- *
15
- * This source code is licensed under the MIT license found in the
16
- * LICENSE file in the root directory of this source tree.
17
- */
18
-
19
- var hasRequiredReactJsxRuntime_production;
20
-
21
- function requireReactJsxRuntime_production () {
22
- if (hasRequiredReactJsxRuntime_production) return reactJsxRuntime_production;
23
- hasRequiredReactJsxRuntime_production = 1;
24
- var REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"),
25
- REACT_FRAGMENT_TYPE = Symbol.for("react.fragment");
26
- function jsxProd(type, config, maybeKey) {
27
- var key = null;
28
- void 0 !== maybeKey && (key = "" + maybeKey);
29
- void 0 !== config.key && (key = "" + config.key);
30
- if ("key" in config) {
31
- maybeKey = {};
32
- for (var propName in config)
33
- "key" !== propName && (maybeKey[propName] = config[propName]);
34
- } else maybeKey = config;
35
- config = maybeKey.ref;
36
- return {
37
- $$typeof: REACT_ELEMENT_TYPE,
38
- type: type,
39
- key: key,
40
- ref: void 0 !== config ? config : null,
41
- props: maybeKey
42
- };
43
- }
44
- reactJsxRuntime_production.Fragment = REACT_FRAGMENT_TYPE;
45
- reactJsxRuntime_production.jsx = jsxProd;
46
- reactJsxRuntime_production.jsxs = jsxProd;
47
- return reactJsxRuntime_production;
48
- }
49
-
50
- var reactJsxRuntime_development = {};
51
-
52
- /**
53
- * @license React
54
- * react-jsx-runtime.development.js
55
- *
56
- * Copyright (c) Meta Platforms, Inc. and affiliates.
57
- *
58
- * This source code is licensed under the MIT license found in the
59
- * LICENSE file in the root directory of this source tree.
60
- */
61
-
62
- var hasRequiredReactJsxRuntime_development;
63
-
64
- function requireReactJsxRuntime_development () {
65
- if (hasRequiredReactJsxRuntime_development) return reactJsxRuntime_development;
66
- hasRequiredReactJsxRuntime_development = 1;
67
- "production" !== process.env.NODE_ENV &&
68
- (function () {
69
- function getComponentNameFromType(type) {
70
- if (null == type) return null;
71
- if ("function" === typeof type)
72
- return type.$$typeof === REACT_CLIENT_REFERENCE
73
- ? null
74
- : type.displayName || type.name || null;
75
- if ("string" === typeof type) return type;
76
- switch (type) {
77
- case REACT_FRAGMENT_TYPE:
78
- return "Fragment";
79
- case REACT_PROFILER_TYPE:
80
- return "Profiler";
81
- case REACT_STRICT_MODE_TYPE:
82
- return "StrictMode";
83
- case REACT_SUSPENSE_TYPE:
84
- return "Suspense";
85
- case REACT_SUSPENSE_LIST_TYPE:
86
- return "SuspenseList";
87
- case REACT_ACTIVITY_TYPE:
88
- return "Activity";
89
- }
90
- if ("object" === typeof type)
91
- switch (
92
- ("number" === typeof type.tag &&
93
- console.error(
94
- "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
95
- ),
96
- type.$$typeof)
97
- ) {
98
- case REACT_PORTAL_TYPE:
99
- return "Portal";
100
- case REACT_CONTEXT_TYPE:
101
- return type.displayName || "Context";
102
- case REACT_CONSUMER_TYPE:
103
- return (type._context.displayName || "Context") + ".Consumer";
104
- case REACT_FORWARD_REF_TYPE:
105
- var innerType = type.render;
106
- type = type.displayName;
107
- type ||
108
- ((type = innerType.displayName || innerType.name || ""),
109
- (type = "" !== type ? "ForwardRef(" + type + ")" : "ForwardRef"));
110
- return type;
111
- case REACT_MEMO_TYPE:
112
- return (
113
- (innerType = type.displayName || null),
114
- null !== innerType
115
- ? innerType
116
- : getComponentNameFromType(type.type) || "Memo"
117
- );
118
- case REACT_LAZY_TYPE:
119
- innerType = type._payload;
120
- type = type._init;
121
- try {
122
- return getComponentNameFromType(type(innerType));
123
- } catch (x) {}
124
- }
125
- return null;
126
- }
127
- function testStringCoercion(value) {
128
- return "" + value;
129
- }
130
- function checkKeyStringCoercion(value) {
131
- try {
132
- testStringCoercion(value);
133
- var JSCompiler_inline_result = !1;
134
- } catch (e) {
135
- JSCompiler_inline_result = true;
136
- }
137
- if (JSCompiler_inline_result) {
138
- JSCompiler_inline_result = console;
139
- var JSCompiler_temp_const = JSCompiler_inline_result.error;
140
- var JSCompiler_inline_result$jscomp$0 =
141
- ("function" === typeof Symbol &&
142
- Symbol.toStringTag &&
143
- value[Symbol.toStringTag]) ||
144
- value.constructor.name ||
145
- "Object";
146
- JSCompiler_temp_const.call(
147
- JSCompiler_inline_result,
148
- "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
149
- JSCompiler_inline_result$jscomp$0
150
- );
151
- return testStringCoercion(value);
152
- }
153
- }
154
- function getTaskName(type) {
155
- if (type === REACT_FRAGMENT_TYPE) return "<>";
156
- if (
157
- "object" === typeof type &&
158
- null !== type &&
159
- type.$$typeof === REACT_LAZY_TYPE
160
- )
161
- return "<...>";
162
- try {
163
- var name = getComponentNameFromType(type);
164
- return name ? "<" + name + ">" : "<...>";
165
- } catch (x) {
166
- return "<...>";
167
- }
168
- }
169
- function getOwner() {
170
- var dispatcher = ReactSharedInternals.A;
171
- return null === dispatcher ? null : dispatcher.getOwner();
172
- }
173
- function UnknownOwner() {
174
- return Error("react-stack-top-frame");
175
- }
176
- function hasValidKey(config) {
177
- if (hasOwnProperty.call(config, "key")) {
178
- var getter = Object.getOwnPropertyDescriptor(config, "key").get;
179
- if (getter && getter.isReactWarning) return false;
180
- }
181
- return void 0 !== config.key;
182
- }
183
- function defineKeyPropWarningGetter(props, displayName) {
184
- function warnAboutAccessingKey() {
185
- specialPropKeyWarningShown ||
186
- ((specialPropKeyWarningShown = true),
187
- console.error(
188
- "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
189
- displayName
190
- ));
191
- }
192
- warnAboutAccessingKey.isReactWarning = true;
193
- Object.defineProperty(props, "key", {
194
- get: warnAboutAccessingKey,
195
- configurable: true
196
- });
197
- }
198
- function elementRefGetterWithDeprecationWarning() {
199
- var componentName = getComponentNameFromType(this.type);
200
- didWarnAboutElementRef[componentName] ||
201
- ((didWarnAboutElementRef[componentName] = true),
202
- console.error(
203
- "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
204
- ));
205
- componentName = this.props.ref;
206
- return void 0 !== componentName ? componentName : null;
207
- }
208
- function ReactElement(type, key, props, owner, debugStack, debugTask) {
209
- var refProp = props.ref;
210
- type = {
211
- $$typeof: REACT_ELEMENT_TYPE,
212
- type: type,
213
- key: key,
214
- props: props,
215
- _owner: owner
216
- };
217
- null !== (void 0 !== refProp ? refProp : null)
218
- ? Object.defineProperty(type, "ref", {
219
- enumerable: false,
220
- get: elementRefGetterWithDeprecationWarning
221
- })
222
- : Object.defineProperty(type, "ref", { enumerable: false, value: null });
223
- type._store = {};
224
- Object.defineProperty(type._store, "validated", {
225
- configurable: false,
226
- enumerable: false,
227
- writable: true,
228
- value: 0
229
- });
230
- Object.defineProperty(type, "_debugInfo", {
231
- configurable: false,
232
- enumerable: false,
233
- writable: true,
234
- value: null
235
- });
236
- Object.defineProperty(type, "_debugStack", {
237
- configurable: false,
238
- enumerable: false,
239
- writable: true,
240
- value: debugStack
241
- });
242
- Object.defineProperty(type, "_debugTask", {
243
- configurable: false,
244
- enumerable: false,
245
- writable: true,
246
- value: debugTask
247
- });
248
- Object.freeze && (Object.freeze(type.props), Object.freeze(type));
249
- return type;
250
- }
251
- function jsxDEVImpl(
252
- type,
253
- config,
254
- maybeKey,
255
- isStaticChildren,
256
- debugStack,
257
- debugTask
258
- ) {
259
- var children = config.children;
260
- if (void 0 !== children)
261
- if (isStaticChildren)
262
- if (isArrayImpl(children)) {
263
- for (
264
- isStaticChildren = 0;
265
- isStaticChildren < children.length;
266
- isStaticChildren++
267
- )
268
- validateChildKeys(children[isStaticChildren]);
269
- Object.freeze && Object.freeze(children);
270
- } else
271
- console.error(
272
- "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
273
- );
274
- else validateChildKeys(children);
275
- if (hasOwnProperty.call(config, "key")) {
276
- children = getComponentNameFromType(type);
277
- var keys = Object.keys(config).filter(function (k) {
278
- return "key" !== k;
279
- });
280
- isStaticChildren =
281
- 0 < keys.length
282
- ? "{key: someKey, " + keys.join(": ..., ") + ": ...}"
283
- : "{key: someKey}";
284
- didWarnAboutKeySpread[children + isStaticChildren] ||
285
- ((keys =
286
- 0 < keys.length ? "{" + keys.join(": ..., ") + ": ...}" : "{}"),
287
- console.error(
288
- 'A props object containing a "key" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />',
289
- isStaticChildren,
290
- children,
291
- keys,
292
- children
293
- ),
294
- (didWarnAboutKeySpread[children + isStaticChildren] = true));
295
- }
296
- children = null;
297
- void 0 !== maybeKey &&
298
- (checkKeyStringCoercion(maybeKey), (children = "" + maybeKey));
299
- hasValidKey(config) &&
300
- (checkKeyStringCoercion(config.key), (children = "" + config.key));
301
- if ("key" in config) {
302
- maybeKey = {};
303
- for (var propName in config)
304
- "key" !== propName && (maybeKey[propName] = config[propName]);
305
- } else maybeKey = config;
306
- children &&
307
- defineKeyPropWarningGetter(
308
- maybeKey,
309
- "function" === typeof type
310
- ? type.displayName || type.name || "Unknown"
311
- : type
312
- );
313
- return ReactElement(
314
- type,
315
- children,
316
- maybeKey,
317
- getOwner(),
318
- debugStack,
319
- debugTask
320
- );
321
- }
322
- function validateChildKeys(node) {
323
- isValidElement(node)
324
- ? node._store && (node._store.validated = 1)
325
- : "object" === typeof node &&
326
- null !== node &&
327
- node.$$typeof === REACT_LAZY_TYPE &&
328
- ("fulfilled" === node._payload.status
329
- ? isValidElement(node._payload.value) &&
330
- node._payload.value._store &&
331
- (node._payload.value._store.validated = 1)
332
- : node._store && (node._store.validated = 1));
333
- }
334
- function isValidElement(object) {
335
- return (
336
- "object" === typeof object &&
337
- null !== object &&
338
- object.$$typeof === REACT_ELEMENT_TYPE
339
- );
340
- }
341
- var React = require$$0,
342
- REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"),
343
- REACT_PORTAL_TYPE = Symbol.for("react.portal"),
344
- REACT_FRAGMENT_TYPE = Symbol.for("react.fragment"),
345
- REACT_STRICT_MODE_TYPE = Symbol.for("react.strict_mode"),
346
- REACT_PROFILER_TYPE = Symbol.for("react.profiler"),
347
- REACT_CONSUMER_TYPE = Symbol.for("react.consumer"),
348
- REACT_CONTEXT_TYPE = Symbol.for("react.context"),
349
- REACT_FORWARD_REF_TYPE = Symbol.for("react.forward_ref"),
350
- REACT_SUSPENSE_TYPE = Symbol.for("react.suspense"),
351
- REACT_SUSPENSE_LIST_TYPE = Symbol.for("react.suspense_list"),
352
- REACT_MEMO_TYPE = Symbol.for("react.memo"),
353
- REACT_LAZY_TYPE = Symbol.for("react.lazy"),
354
- REACT_ACTIVITY_TYPE = Symbol.for("react.activity"),
355
- REACT_CLIENT_REFERENCE = Symbol.for("react.client.reference"),
356
- ReactSharedInternals =
357
- React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,
358
- hasOwnProperty = Object.prototype.hasOwnProperty,
359
- isArrayImpl = Array.isArray,
360
- createTask = console.createTask
361
- ? console.createTask
362
- : function () {
363
- return null;
364
- };
365
- React = {
366
- react_stack_bottom_frame: function (callStackForError) {
367
- return callStackForError();
368
- }
369
- };
370
- var specialPropKeyWarningShown;
371
- var didWarnAboutElementRef = {};
372
- var unknownOwnerDebugStack = React.react_stack_bottom_frame.bind(
373
- React,
374
- UnknownOwner
375
- )();
376
- var unknownOwnerDebugTask = createTask(getTaskName(UnknownOwner));
377
- var didWarnAboutKeySpread = {};
378
- reactJsxRuntime_development.Fragment = REACT_FRAGMENT_TYPE;
379
- reactJsxRuntime_development.jsx = function (type, config, maybeKey) {
380
- var trackActualOwner =
381
- 1e4 > ReactSharedInternals.recentlyCreatedOwnerStacks++;
382
- return jsxDEVImpl(
383
- type,
384
- config,
385
- maybeKey,
386
- false,
387
- trackActualOwner
388
- ? Error("react-stack-top-frame")
389
- : unknownOwnerDebugStack,
390
- trackActualOwner ? createTask(getTaskName(type)) : unknownOwnerDebugTask
391
- );
392
- };
393
- reactJsxRuntime_development.jsxs = function (type, config, maybeKey) {
394
- var trackActualOwner =
395
- 1e4 > ReactSharedInternals.recentlyCreatedOwnerStacks++;
396
- return jsxDEVImpl(
397
- type,
398
- config,
399
- maybeKey,
400
- true,
401
- trackActualOwner
402
- ? Error("react-stack-top-frame")
403
- : unknownOwnerDebugStack,
404
- trackActualOwner ? createTask(getTaskName(type)) : unknownOwnerDebugTask
405
- );
406
- };
407
- })();
408
- return reactJsxRuntime_development;
409
- }
410
-
411
- var hasRequiredJsxRuntime;
412
-
413
- function requireJsxRuntime () {
414
- if (hasRequiredJsxRuntime) return jsxRuntime.exports;
415
- hasRequiredJsxRuntime = 1;
416
-
417
- if (process.env.NODE_ENV === 'production') {
418
- jsxRuntime.exports = requireReactJsxRuntime_production();
419
- } else {
420
- jsxRuntime.exports = requireReactJsxRuntime_development();
421
- }
422
- return jsxRuntime.exports;
423
- }
424
-
425
- var jsxRuntimeExports = requireJsxRuntime();
426
-
427
6
  function handleNumoraOnChange(e, options) {
428
7
  const { formatted, raw } = handleOnChangeNumoraInput(e.nativeEvent, options.decimalMaxLength, options.caretPositionBeforeChange, options.formattingOptions);
429
8
  return {
@@ -455,22 +34,66 @@ function handleNumoraOnBlur(e, options) {
455
34
  };
456
35
  }
457
36
 
37
+ /**
38
+ * Creates a complete synthetic change event from a real HTMLInputElement.
39
+ * Used when a change needs to be signalled without an actual DOM change event
40
+ * (e.g. after paste with preventDefault, or after a controlled-value reformat).
41
+ */
42
+ function createSyntheticChangeEvent(input) {
43
+ const nativeEvent = new Event('change', { bubbles: true, cancelable: false });
44
+ return {
45
+ nativeEvent,
46
+ target: input,
47
+ currentTarget: input,
48
+ type: 'change',
49
+ bubbles: true,
50
+ cancelable: false,
51
+ defaultPrevented: false,
52
+ eventPhase: Event.AT_TARGET,
53
+ isTrusted: false,
54
+ timeStamp: Date.now(),
55
+ isDefaultPrevented: () => false,
56
+ isPropagationStopped: () => false,
57
+ persist: () => { },
58
+ preventDefault: () => { },
59
+ stopPropagation: () => { },
60
+ stopImmediatePropagation: () => { },
61
+ };
62
+ }
458
63
  const NumoraInput = forwardRef((props, ref) => {
459
- const { maxDecimals = 2, onChange, onPaste, onBlur, onKeyDown, onFocus, formatOn = FormatOn.Blur, thousandSeparator = ',', thousandStyle = ThousandStyle.Thousand, decimalSeparator = '.', decimalMinLength, enableCompactNotation = false, enableNegative = false, enableLeadingZeros = false, rawValueMode = false, value: controlledValue, defaultValue, ...rest } = props;
460
- const internalInputRef = useRef(null);
461
- const caretInfoRef = useRef(undefined);
462
- const lastCaretPosRef = useRef(null);
463
- const formattingOptions = {
64
+ const { maxDecimals = 2, onChange, onPaste, onBlur, onKeyDown, onFocus, onRawValueChange, formatOn = FormatOn.Blur, thousandSeparator, thousandStyle = ThousandStyle.Thousand, decimalSeparator, decimalMinLength, enableCompactNotation = false, enableNegative = false, enableLeadingZeros = false, rawValueMode = false, value: controlledValue, defaultValue, ...rest } = props;
65
+ validateNumoraInputOptions({
66
+ decimalMaxLength: maxDecimals,
67
+ decimalMinLength,
464
68
  formatOn,
465
69
  thousandSeparator,
466
- ThousandStyle: thousandStyle,
70
+ thousandStyle,
467
71
  decimalSeparator,
468
- decimalMinLength,
469
72
  enableCompactNotation,
470
73
  enableNegative,
471
74
  enableLeadingZeros,
472
75
  rawValueMode,
473
- };
76
+ });
77
+ const internalInputRef = useRef(null);
78
+ const caretInfoRef = useRef(undefined);
79
+ const lastCaretPosRef = useRef(null);
80
+ // Memoize to give callbacks a stable reference - avoids recreating all
81
+ // useCallback functions on every render when primitive props haven't changed.
82
+ const formattingOptions = useMemo(() => {
83
+ const resolved = resolveLocaleOptions({ thousandSeparator, thousandStyle, decimalSeparator });
84
+ return {
85
+ formatOn,
86
+ thousandSeparator: resolved.thousandSeparator,
87
+ ThousandStyle: resolved.thousandStyle,
88
+ decimalSeparator: resolved.decimalSeparator,
89
+ decimalMinLength,
90
+ enableCompactNotation,
91
+ enableNegative,
92
+ enableLeadingZeros,
93
+ rawValueMode,
94
+ };
95
+ }, [formatOn, thousandSeparator, thousandStyle, decimalSeparator, decimalMinLength,
96
+ enableCompactNotation, enableNegative, enableLeadingZeros, rawValueMode]);
474
97
  const getInitialValue = () => {
475
98
  const valueToFormat = controlledValue !== undefined ? controlledValue : defaultValue;
476
99
  if (valueToFormat !== undefined) {
@@ -480,6 +103,11 @@ const NumoraInput = forwardRef((props, ref) => {
480
103
  return '';
481
104
  };
482
105
  const [displayValue, setDisplayValue] = useState(getInitialValue);
106
+ // Track the current displayValue via a ref so the controlled-value useEffect
107
+ // can compare against it without adding displayValue as a dependency (which
108
+ // would cause the effect to re-run on every keystroke).
109
+ const displayValueRef = useRef(displayValue);
110
+ displayValueRef.current = displayValue;
483
111
  // Sync external ref with internal ref
484
112
  useLayoutEffect(() => {
485
113
  if (!ref)
@@ -491,32 +119,25 @@ const NumoraInput = forwardRef((props, ref) => {
491
119
  ref.current = internalInputRef.current;
492
120
  }
493
121
  }, [ref]);
494
- // When controlled value changes from outside, update display value
122
+ // When the controlled value or formatting options change, reformat the display.
123
+ // Uses displayValueRef (not displayValue in deps) to avoid re-running on every keystroke.
124
+ // Does NOT call onChange - that would create a circular loop with react-hook-form Controller.
495
125
  useEffect(() => {
496
126
  if (controlledValue !== undefined) {
497
127
  const { formatted, raw } = formatValueForDisplay(String(controlledValue), maxDecimals, formattingOptions);
498
- if (formatted !== displayValue) {
128
+ if (formatted !== displayValueRef.current) {
499
129
  setDisplayValue(formatted);
500
- // Fire onChange so the parent state stays in sync when formatting props
501
- // cause the value to be reformatted (e.g., maxDecimals changes from 4 to 2)
502
- if (onChange && internalInputRef.current) {
503
- const input = internalInputRef.current;
504
- // Set DOM value so e.target.value returns the formatted value
505
- const nativeSetter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value')?.set;
506
- nativeSetter?.call(input, formatted);
507
- input.rawValue = raw;
508
- const changeEvent = {
509
- target: input,
510
- currentTarget: input,
511
- };
512
- onChange(changeEvent);
130
+ if (internalInputRef.current) {
131
+ internalInputRef.current.rawValue = raw;
513
132
  }
133
+ onRawValueChange?.(raw);
514
134
  }
515
135
  }
516
- }, [controlledValue, maxDecimals, formattingOptions.ThousandStyle, formattingOptions.decimalSeparator, formattingOptions.decimalMinLength,
517
- formattingOptions.enableCompactNotation, formattingOptions.enableLeadingZeros, formattingOptions.enableNegative,
518
- formattingOptions.formatOn, formattingOptions.rawValueMode, formattingOptions.thousandSeparator]);
519
- // Restore cursor position after render
136
+ }, [controlledValue, maxDecimals, formattingOptions, onRawValueChange]);
137
+ // Restore cursor position after render.
138
+ // No dependency array is intentional: this must run after every render so it catches
139
+ // the re-render triggered by setDisplayValue in handleChange/handlePaste.
140
+ // lastCaretPosRef is a ref (not reactive), so it cannot be a dependency.
520
141
  useLayoutEffect(() => {
521
142
  if (internalInputRef.current && lastCaretPosRef.current !== null) {
522
143
  const input = internalInputRef.current;
@@ -531,9 +152,6 @@ const NumoraInput = forwardRef((props, ref) => {
531
152
  caretPositionBeforeChange: caretInfoRef.current,
532
153
  formattingOptions,
533
154
  });
534
- // Store cursor position AFTER core library has calculated and set it
535
- // The core library modifies the DOM element directly during handleNumoraOnChange
536
- // Read from the input ref (which is the same element) to get the position set by the core library
537
155
  if (internalInputRef.current) {
538
156
  const cursorPos = internalInputRef.current.selectionStart;
539
157
  if (cursorPos !== null && cursorPos !== undefined) {
@@ -542,15 +160,14 @@ const NumoraInput = forwardRef((props, ref) => {
542
160
  }
543
161
  caretInfoRef.current = undefined;
544
162
  e.target.rawValue = rawValue;
163
+ onRawValueChange?.(rawValue);
545
164
  setDisplayValue(value);
546
165
  if (onChange) {
547
166
  onChange(e);
548
167
  }
549
- }, [maxDecimals, formattingOptions, onChange]);
168
+ }, [maxDecimals, formattingOptions, onChange, onRawValueChange]);
550
169
  const handleKeyDown = useCallback((e) => {
551
170
  const coreCaretInfo = handleNumoraOnKeyDown(e, formattingOptions);
552
- // Always capture cursor position info, even if core library doesn't return it
553
- // This is needed for cursor position calculation during normal typing (not just Delete/Backspace)
554
171
  if (!coreCaretInfo && internalInputRef.current) {
555
172
  const selectionStart = internalInputRef.current.selectionStart ?? 0;
556
173
  const selectionEnd = internalInputRef.current.selectionEnd ?? 0;
@@ -571,43 +188,46 @@ const NumoraInput = forwardRef((props, ref) => {
571
188
  decimalMaxLength: maxDecimals,
572
189
  formattingOptions,
573
190
  });
574
- // For paste, we often want to move cursor to the end of pasted content
575
- // handleNumoraOnPaste already handles DOM value and cursor, but React will overwrite it.
576
- // So we capture where the core logic set the cursor.
577
191
  lastCaretPosRef.current = e.target.selectionStart;
578
192
  e.target.rawValue = rawValue;
193
+ onRawValueChange?.(rawValue);
579
194
  setDisplayValue(value);
580
195
  if (onPaste) {
581
196
  onPaste(e);
582
197
  }
583
- // Trigger onChange manually because paste event doesn't always trigger a ChangeEvent in all React versions
584
- // when we preventDefault.
198
+ // Paste calls e.preventDefault() internally, so React's onChange never fires.
199
+ // We synthesise a proper change event so consumers see a typed ChangeEvent.
585
200
  if (onChange) {
586
- const changeEvent = e;
587
- onChange(changeEvent);
201
+ onChange(createSyntheticChangeEvent(e.target));
588
202
  }
589
- }, [maxDecimals, formattingOptions, onPaste, onChange]);
203
+ }, [maxDecimals, formattingOptions, onPaste, onChange, onRawValueChange]);
590
204
  const handleFocus = useCallback((e) => {
591
- if (formattingOptions.formatOn === FormatOn.Blur && formattingOptions.thousandSeparator) {
592
- const unformattedValue = removeThousandSeparators(displayValue, formattingOptions.thousandSeparator);
593
- setDisplayValue(unformattedValue);
205
+ if (formattingOptions.formatOn === FormatOn.Blur &&
206
+ formattingOptions.thousandSeparator &&
207
+ formattingOptions.ThousandStyle !== ThousandStyle.None) {
208
+ // Read directly from the DOM element to avoid a stale displayValue closure
209
+ // and to eliminate displayValue from the deps array (which would recreate
210
+ // this callback on every keystroke).
211
+ const currentValue = e.target.value;
212
+ setDisplayValue(removeThousandSeparators(currentValue, formattingOptions.thousandSeparator));
594
213
  }
595
214
  if (onFocus) {
596
215
  onFocus(e);
597
216
  }
598
- }, [formattingOptions, onFocus, displayValue]);
217
+ }, [formattingOptions, onFocus]);
599
218
  const handleBlur = useCallback((e) => {
600
219
  const { value, rawValue } = handleNumoraOnBlur(e, {
601
220
  decimalMaxLength: maxDecimals,
602
221
  formattingOptions,
603
222
  });
604
223
  e.target.rawValue = rawValue;
224
+ onRawValueChange?.(rawValue);
605
225
  setDisplayValue(value);
606
226
  if (onBlur) {
607
227
  onBlur(e);
608
228
  }
609
- }, [maxDecimals, formattingOptions, onBlur]);
610
- return (jsxRuntimeExports.jsx("input", { ...rest, ref: internalInputRef, value: displayValue, onChange: handleChange, onKeyDown: handleKeyDown, onPaste: handlePaste, onFocus: handleFocus, onBlur: handleBlur, type: "text", inputMode: "decimal", spellCheck: false, autoComplete: "off" }));
229
+ }, [maxDecimals, formattingOptions, onBlur, onRawValueChange]);
230
+ return (jsx("input", { ...rest, ref: internalInputRef, value: displayValue, onChange: handleChange, onKeyDown: handleKeyDown, onPaste: handlePaste, onFocus: handleFocus, onBlur: handleBlur, type: "text", inputMode: "decimal", spellCheck: false, autoComplete: "off" }));
611
231
  });
612
232
  NumoraInput.displayName = 'NumoraInput';
613
233