numora-react 3.0.2 → 3.1.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/README.md +61 -0
- package/dist/index.cjs +241 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +9 -1
- package/dist/index.js +15 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +85 -458
- package/dist/index.mjs.map +1 -1
- package/package.json +15 -6
- package/rollup.config.mjs +2 -3
- package/src/index.tsx +104 -37
- package/tsconfig.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,429 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
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, 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,12 +34,52 @@ 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;
|
|
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,
|
|
68
|
+
formatOn,
|
|
69
|
+
thousandSeparator,
|
|
70
|
+
thousandStyle,
|
|
71
|
+
decimalSeparator,
|
|
72
|
+
enableCompactNotation,
|
|
73
|
+
enableNegative,
|
|
74
|
+
enableLeadingZeros,
|
|
75
|
+
rawValueMode,
|
|
76
|
+
});
|
|
460
77
|
const internalInputRef = useRef(null);
|
|
461
78
|
const caretInfoRef = useRef(undefined);
|
|
462
79
|
const lastCaretPosRef = useRef(null);
|
|
463
|
-
|
|
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(() => ({
|
|
464
83
|
formatOn,
|
|
465
84
|
thousandSeparator,
|
|
466
85
|
ThousandStyle: thousandStyle,
|
|
@@ -470,7 +89,8 @@ const NumoraInput = forwardRef((props, ref) => {
|
|
|
470
89
|
enableNegative,
|
|
471
90
|
enableLeadingZeros,
|
|
472
91
|
rawValueMode,
|
|
473
|
-
}
|
|
92
|
+
}), [formatOn, thousandSeparator, thousandStyle, decimalSeparator, decimalMinLength,
|
|
93
|
+
enableCompactNotation, enableNegative, enableLeadingZeros, rawValueMode]);
|
|
474
94
|
const getInitialValue = () => {
|
|
475
95
|
const valueToFormat = controlledValue !== undefined ? controlledValue : defaultValue;
|
|
476
96
|
if (valueToFormat !== undefined) {
|
|
@@ -480,6 +100,11 @@ const NumoraInput = forwardRef((props, ref) => {
|
|
|
480
100
|
return '';
|
|
481
101
|
};
|
|
482
102
|
const [displayValue, setDisplayValue] = useState(getInitialValue);
|
|
103
|
+
// Track the current displayValue via a ref so the controlled-value useEffect
|
|
104
|
+
// can compare against it without adding displayValue as a dependency (which
|
|
105
|
+
// would cause the effect to re-run on every keystroke).
|
|
106
|
+
const displayValueRef = useRef(displayValue);
|
|
107
|
+
displayValueRef.current = displayValue;
|
|
483
108
|
// Sync external ref with internal ref
|
|
484
109
|
useLayoutEffect(() => {
|
|
485
110
|
if (!ref)
|
|
@@ -491,18 +116,25 @@ const NumoraInput = forwardRef((props, ref) => {
|
|
|
491
116
|
ref.current = internalInputRef.current;
|
|
492
117
|
}
|
|
493
118
|
}, [ref]);
|
|
494
|
-
// When controlled value
|
|
119
|
+
// When the controlled value or formatting options change, reformat the display.
|
|
120
|
+
// Uses displayValueRef (not displayValue in deps) to avoid re-running on every keystroke.
|
|
121
|
+
// Does NOT call onChange - that would create a circular loop with react-hook-form Controller.
|
|
495
122
|
useEffect(() => {
|
|
496
123
|
if (controlledValue !== undefined) {
|
|
497
|
-
const { formatted } = formatValueForDisplay(String(controlledValue), maxDecimals, formattingOptions);
|
|
498
|
-
if (formatted !==
|
|
124
|
+
const { formatted, raw } = formatValueForDisplay(String(controlledValue), maxDecimals, formattingOptions);
|
|
125
|
+
if (formatted !== displayValueRef.current) {
|
|
499
126
|
setDisplayValue(formatted);
|
|
127
|
+
if (internalInputRef.current) {
|
|
128
|
+
internalInputRef.current.rawValue = raw;
|
|
129
|
+
}
|
|
130
|
+
onRawValueChange?.(raw);
|
|
500
131
|
}
|
|
501
132
|
}
|
|
502
|
-
}, [controlledValue, maxDecimals, formattingOptions
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
//
|
|
133
|
+
}, [controlledValue, maxDecimals, formattingOptions, onRawValueChange]);
|
|
134
|
+
// Restore cursor position after render.
|
|
135
|
+
// No dependency array is intentional: this must run after every render so it catches
|
|
136
|
+
// the re-render triggered by setDisplayValue in handleChange/handlePaste.
|
|
137
|
+
// lastCaretPosRef is a ref (not reactive), so it cannot be a dependency.
|
|
506
138
|
useLayoutEffect(() => {
|
|
507
139
|
if (internalInputRef.current && lastCaretPosRef.current !== null) {
|
|
508
140
|
const input = internalInputRef.current;
|
|
@@ -512,15 +144,11 @@ const NumoraInput = forwardRef((props, ref) => {
|
|
|
512
144
|
}
|
|
513
145
|
});
|
|
514
146
|
const handleChange = useCallback((e) => {
|
|
515
|
-
console.log('handleChange', e);
|
|
516
147
|
const { value, rawValue } = handleNumoraOnChange(e, {
|
|
517
148
|
decimalMaxLength: maxDecimals,
|
|
518
149
|
caretPositionBeforeChange: caretInfoRef.current,
|
|
519
150
|
formattingOptions,
|
|
520
151
|
});
|
|
521
|
-
// Store cursor position AFTER core library has calculated and set it
|
|
522
|
-
// The core library modifies the DOM element directly during handleNumoraOnChange
|
|
523
|
-
// Read from the input ref (which is the same element) to get the position set by the core library
|
|
524
152
|
if (internalInputRef.current) {
|
|
525
153
|
const cursorPos = internalInputRef.current.selectionStart;
|
|
526
154
|
if (cursorPos !== null && cursorPos !== undefined) {
|
|
@@ -529,16 +157,14 @@ const NumoraInput = forwardRef((props, ref) => {
|
|
|
529
157
|
}
|
|
530
158
|
caretInfoRef.current = undefined;
|
|
531
159
|
e.target.rawValue = rawValue;
|
|
160
|
+
onRawValueChange?.(rawValue);
|
|
532
161
|
setDisplayValue(value);
|
|
533
162
|
if (onChange) {
|
|
534
163
|
onChange(e);
|
|
535
164
|
}
|
|
536
|
-
}, [maxDecimals, formattingOptions, onChange]);
|
|
165
|
+
}, [maxDecimals, formattingOptions, onChange, onRawValueChange]);
|
|
537
166
|
const handleKeyDown = useCallback((e) => {
|
|
538
|
-
console.log('handleKeyDown', e);
|
|
539
167
|
const coreCaretInfo = handleNumoraOnKeyDown(e, formattingOptions);
|
|
540
|
-
// Always capture cursor position info, even if core library doesn't return it
|
|
541
|
-
// This is needed for cursor position calculation during normal typing (not just Delete/Backspace)
|
|
542
168
|
if (!coreCaretInfo && internalInputRef.current) {
|
|
543
169
|
const selectionStart = internalInputRef.current.selectionStart ?? 0;
|
|
544
170
|
const selectionEnd = internalInputRef.current.selectionEnd ?? 0;
|
|
@@ -559,45 +185,46 @@ const NumoraInput = forwardRef((props, ref) => {
|
|
|
559
185
|
decimalMaxLength: maxDecimals,
|
|
560
186
|
formattingOptions,
|
|
561
187
|
});
|
|
562
|
-
// For paste, we often want to move cursor to the end of pasted content
|
|
563
|
-
// handleNumoraOnPaste already handles DOM value and cursor, but React will overwrite it.
|
|
564
|
-
// So we capture where the core logic set the cursor.
|
|
565
188
|
lastCaretPosRef.current = e.target.selectionStart;
|
|
566
189
|
e.target.rawValue = rawValue;
|
|
190
|
+
onRawValueChange?.(rawValue);
|
|
567
191
|
setDisplayValue(value);
|
|
568
192
|
if (onPaste) {
|
|
569
193
|
onPaste(e);
|
|
570
194
|
}
|
|
571
|
-
//
|
|
572
|
-
//
|
|
195
|
+
// Paste calls e.preventDefault() internally, so React's onChange never fires.
|
|
196
|
+
// We synthesise a proper change event so consumers see a typed ChangeEvent.
|
|
573
197
|
if (onChange) {
|
|
574
|
-
|
|
575
|
-
onChange(changeEvent);
|
|
198
|
+
onChange(createSyntheticChangeEvent(e.target));
|
|
576
199
|
}
|
|
577
|
-
}, [maxDecimals, formattingOptions, onPaste, onChange]);
|
|
200
|
+
}, [maxDecimals, formattingOptions, onPaste, onChange, onRawValueChange]);
|
|
578
201
|
const handleFocus = useCallback((e) => {
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
202
|
+
if (formattingOptions.formatOn === FormatOn.Blur &&
|
|
203
|
+
formattingOptions.thousandSeparator &&
|
|
204
|
+
formattingOptions.ThousandStyle !== ThousandStyle.None) {
|
|
205
|
+
// Read directly from the DOM element to avoid a stale displayValue closure
|
|
206
|
+
// and to eliminate displayValue from the deps array (which would recreate
|
|
207
|
+
// this callback on every keystroke).
|
|
208
|
+
const currentValue = e.target.value;
|
|
209
|
+
setDisplayValue(removeThousandSeparators(currentValue, formattingOptions.thousandSeparator));
|
|
583
210
|
}
|
|
584
211
|
if (onFocus) {
|
|
585
212
|
onFocus(e);
|
|
586
213
|
}
|
|
587
|
-
}, [formattingOptions, onFocus
|
|
214
|
+
}, [formattingOptions, onFocus]);
|
|
588
215
|
const handleBlur = useCallback((e) => {
|
|
589
|
-
console.log('handleBlur', e);
|
|
590
216
|
const { value, rawValue } = handleNumoraOnBlur(e, {
|
|
591
217
|
decimalMaxLength: maxDecimals,
|
|
592
218
|
formattingOptions,
|
|
593
219
|
});
|
|
594
220
|
e.target.rawValue = rawValue;
|
|
221
|
+
onRawValueChange?.(rawValue);
|
|
595
222
|
setDisplayValue(value);
|
|
596
223
|
if (onBlur) {
|
|
597
224
|
onBlur(e);
|
|
598
225
|
}
|
|
599
|
-
}, [maxDecimals, formattingOptions, onBlur]);
|
|
600
|
-
return (
|
|
226
|
+
}, [maxDecimals, formattingOptions, onBlur, onRawValueChange]);
|
|
227
|
+
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" }));
|
|
601
228
|
});
|
|
602
229
|
NumoraInput.displayName = 'NumoraInput';
|
|
603
230
|
|