wcz-test 6.14.0 → 6.20.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.
Files changed (51) hide show
  1. package/dist/ApprovalStatus-C9HPyMiS.js.map +1 -1
  2. package/dist/DialogsHooks-Bi8dZoyu.js +338 -0
  3. package/dist/DialogsHooks-Bi8dZoyu.js.map +1 -0
  4. package/dist/FileHooks-hWKTwLCr.js +195 -0
  5. package/dist/FileHooks-hWKTwLCr.js.map +1 -0
  6. package/dist/FileMeta-G1oT3mYK.js.map +1 -1
  7. package/dist/{RouterListItemButton-Cx7rXEfm.js → RouterListItemButton-CHS7rofI.js} +4 -4
  8. package/dist/RouterListItemButton-CHS7rofI.js.map +1 -0
  9. package/dist/auth-client-B6cIXYDV.js +1417 -0
  10. package/dist/auth-client-B6cIXYDV.js.map +1 -0
  11. package/dist/client.d.ts +61 -49
  12. package/dist/client.js +7 -3
  13. package/dist/client.js.map +1 -1
  14. package/dist/components.js +68 -3405
  15. package/dist/components.js.map +1 -1
  16. package/dist/env-CoxTjaDr.js.map +1 -1
  17. package/dist/error-BhAKg8LX-X0sdNXNa.js +195 -0
  18. package/dist/error-BhAKg8LX-X0sdNXNa.js.map +1 -0
  19. package/dist/hooks.d.ts +6 -2
  20. package/dist/hooks.js +35 -1040
  21. package/dist/hooks.js.map +1 -1
  22. package/dist/index.js +90 -504
  23. package/dist/index.js.map +1 -1
  24. package/dist/manifest.webmanifest +18 -18
  25. package/dist/models.d.ts +10 -10
  26. package/dist/models.js +4 -4
  27. package/dist/models.js.map +1 -1
  28. package/dist/queries.d.ts +6 -6
  29. package/dist/queries.js +2 -2
  30. package/dist/queries.js.map +1 -1
  31. package/dist/server-mxQ3s5dx-CC81W42s.js +644 -0
  32. package/dist/server-mxQ3s5dx-CC81W42s.js.map +1 -0
  33. package/dist/server.d.ts +2 -0
  34. package/dist/server.js +8659 -5
  35. package/dist/server.js.map +1 -1
  36. package/dist/{utils-JYv9O0GI.js → utils-DKyKGba7.js} +2 -1
  37. package/dist/utils-DKyKGba7.js.map +1 -0
  38. package/dist/utils.d.ts +11 -0
  39. package/dist/utils.js +9 -0
  40. package/dist/utils.js.map +1 -0
  41. package/dist/vite.js +3 -0
  42. package/dist/vite.js.map +1 -1
  43. package/package.json +120 -116
  44. package/dist/DialogsHooks-BlUsVlfv.js +0 -39
  45. package/dist/DialogsHooks-BlUsVlfv.js.map +0 -1
  46. package/dist/FileHooks-41k6-RtZ.js +0 -3262
  47. package/dist/FileHooks-41k6-RtZ.js.map +0 -1
  48. package/dist/RouterListItemButton-Cx7rXEfm.js.map +0 -1
  49. package/dist/auth-client-o9U0_qmf.js +0 -79
  50. package/dist/auth-client-o9U0_qmf.js.map +0 -1
  51. package/dist/utils-JYv9O0GI.js.map +0 -1
package/dist/hooks.js CHANGED
@@ -1,14 +1,15 @@
1
1
  import { createFormHookContexts, createFormHook } from "@tanstack/react-form";
2
- import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { j as jsxRuntimeExports } from "./DialogsHooks-Bi8dZoyu.js";
3
+ import { u } from "./DialogsHooks-Bi8dZoyu.js";
3
4
  import { Autocomplete, TextField, FormControl, FormControlLabel, Checkbox, FormHelperText, FormLabel, RadioGroup, Radio, Slider, Button, Switch } from "@mui/material";
4
- import { g as getFieldStatus } from "./utils-JYv9O0GI.js";
5
+ import { g as getFieldStatus } from "./utils-DKyKGba7.js";
5
6
  import { DatePicker, DateRangePicker, TimePicker, TimeRangePicker, DateTimePicker, DateTimeRangePicker } from "@mui/x-date-pickers-pro";
6
- import React, { useRef, useState, useEffect, useLayoutEffect, useMemo } from "react";
7
- import { u } from "./DialogsHooks-BlUsVlfv.js";
7
+ import { NumericFormat } from "react-number-format";
8
+ import { useInView } from "react-intersection-observer";
8
9
  const FormAutocomplete = ({ textFieldProps, ...autocompleteProps }) => {
9
10
  const field = useFieldContext();
10
11
  const { isTouched, hasError, helperText } = getFieldStatus(field);
11
- return /* @__PURE__ */ jsx(
12
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(
12
13
  Autocomplete,
13
14
  {
14
15
  value: field.state.value,
@@ -17,7 +18,7 @@ const FormAutocomplete = ({ textFieldProps, ...autocompleteProps }) => {
17
18
  onBlur: field.handleBlur,
18
19
  "aria-label": field.name,
19
20
  ...autocompleteProps,
20
- renderInput: (parameters) => /* @__PURE__ */ jsx(
21
+ renderInput: (parameters) => /* @__PURE__ */ jsxRuntimeExports.jsx(
21
22
  TextField,
22
23
  {
23
24
  ...parameters,
@@ -33,11 +34,11 @@ const FormAutocomplete = ({ textFieldProps, ...autocompleteProps }) => {
33
34
  const FormCheckbox = (props) => {
34
35
  const field = useFieldContext();
35
36
  const { isTouched, hasError, helperText } = getFieldStatus(field);
36
- return /* @__PURE__ */ jsxs(FormControl, { component: "fieldset", children: [
37
- /* @__PURE__ */ jsx(
37
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs(FormControl, { component: "fieldset", children: [
38
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
38
39
  FormControlLabel,
39
40
  {
40
- control: /* @__PURE__ */ jsx(
41
+ control: /* @__PURE__ */ jsxRuntimeExports.jsx(
41
42
  Checkbox,
42
43
  {
43
44
  name: field.name,
@@ -51,13 +52,13 @@ const FormCheckbox = (props) => {
51
52
  label: props.label ?? ""
52
53
  }
53
54
  ),
54
- isTouched && hasError && /* @__PURE__ */ jsx(FormHelperText, { error: hasError, children: helperText })
55
+ isTouched && hasError && /* @__PURE__ */ jsxRuntimeExports.jsx(FormHelperText, { error: hasError, children: helperText })
55
56
  ] });
56
57
  };
57
58
  const FormDatePicker = (props) => {
58
59
  const field = useFieldContext();
59
60
  const { isTouched, hasError, helperText } = getFieldStatus(field);
60
- return /* @__PURE__ */ jsx(
61
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(
61
62
  DatePicker,
62
63
  {
63
64
  name: field.name,
@@ -80,7 +81,7 @@ const FormDatePicker = (props) => {
80
81
  const FormDateRangePicker = (props) => {
81
82
  const field = useFieldContext();
82
83
  const { isTouched, hasError, helperText } = getFieldStatus(field);
83
- return /* @__PURE__ */ jsx(
84
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(
84
85
  DateRangePicker,
85
86
  {
86
87
  name: field.name,
@@ -103,7 +104,7 @@ const FormDateRangePicker = (props) => {
103
104
  const FormTimePicker = (props) => {
104
105
  const field = useFieldContext();
105
106
  const { isTouched, hasError, helperText } = getFieldStatus(field);
106
- return /* @__PURE__ */ jsx(
107
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(
107
108
  TimePicker,
108
109
  {
109
110
  name: field.name,
@@ -126,7 +127,7 @@ const FormTimePicker = (props) => {
126
127
  const FormTimeRangePicker = (props) => {
127
128
  const field = useFieldContext();
128
129
  const { isTouched, hasError, helperText } = getFieldStatus(field);
129
- return /* @__PURE__ */ jsx(
130
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(
130
131
  TimeRangePicker,
131
132
  {
132
133
  name: field.name,
@@ -149,7 +150,7 @@ const FormTimeRangePicker = (props) => {
149
150
  const FormDateTimePicker = (props) => {
150
151
  const field = useFieldContext();
151
152
  const { isTouched, hasError, helperText } = getFieldStatus(field);
152
- return /* @__PURE__ */ jsx(
153
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(
153
154
  DateTimePicker,
154
155
  {
155
156
  name: field.name,
@@ -172,7 +173,7 @@ const FormDateTimePicker = (props) => {
172
173
  const FormDateTimeRangePicker = (props) => {
173
174
  const field = useFieldContext();
174
175
  const { isTouched, hasError, helperText } = getFieldStatus(field);
175
- return /* @__PURE__ */ jsx(
176
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(
176
177
  DateTimeRangePicker,
177
178
  {
178
179
  name: field.name,
@@ -192,1017 +193,10 @@ const FormDateTimeRangePicker = (props) => {
192
193
  }
193
194
  );
194
195
  };
195
- function __rest(s, e) {
196
- var t = {};
197
- for (var p in s) {
198
- if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) {
199
- t[p] = s[p];
200
- }
201
- }
202
- if (s != null && typeof Object.getOwnPropertySymbols === "function") {
203
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
204
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) {
205
- t[p[i]] = s[p[i]];
206
- }
207
- }
208
- }
209
- return t;
210
- }
211
- var SourceType;
212
- (function(SourceType2) {
213
- SourceType2["event"] = "event";
214
- SourceType2["props"] = "prop";
215
- })(SourceType || (SourceType = {}));
216
- function noop() {
217
- }
218
- function memoizeOnce(cb) {
219
- var lastArgs;
220
- var lastValue = void 0;
221
- return function() {
222
- var args = [], len = arguments.length;
223
- while (len--) args[len] = arguments[len];
224
- if (lastArgs && args.length === lastArgs.length && args.every(function(value, index) {
225
- return value === lastArgs[index];
226
- })) {
227
- return lastValue;
228
- }
229
- lastArgs = args;
230
- lastValue = cb.apply(void 0, args);
231
- return lastValue;
232
- };
233
- }
234
- function charIsNumber(char) {
235
- return !!(char || "").match(/\d/);
236
- }
237
- function isNil(val) {
238
- return val === null || val === void 0;
239
- }
240
- function isNanValue(val) {
241
- return typeof val === "number" && isNaN(val);
242
- }
243
- function isNotValidValue(val) {
244
- return isNil(val) || isNanValue(val) || typeof val === "number" && !isFinite(val);
245
- }
246
- function escapeRegExp(str) {
247
- return str.replace(/[-[\]/{}()*+?.\\^$|]/g, "\\$&");
248
- }
249
- function getThousandsGroupRegex(thousandsGroupStyle) {
250
- switch (thousandsGroupStyle) {
251
- case "lakh":
252
- return /(\d+?)(?=(\d\d)+(\d)(?!\d))(\.\d+)?/g;
253
- case "wan":
254
- return /(\d)(?=(\d{4})+(?!\d))/g;
255
- case "thousand":
256
- default:
257
- return /(\d)(?=(\d{3})+(?!\d))/g;
258
- }
259
- }
260
- function applyThousandSeparator(str, thousandSeparator, thousandsGroupStyle) {
261
- var thousandsGroupRegex = getThousandsGroupRegex(thousandsGroupStyle);
262
- var index = str.search(/[1-9]/);
263
- index = index === -1 ? str.length : index;
264
- return str.substring(0, index) + str.substring(index, str.length).replace(thousandsGroupRegex, "$1" + thousandSeparator);
265
- }
266
- function usePersistentCallback(cb) {
267
- var callbackRef = useRef(cb);
268
- callbackRef.current = cb;
269
- var persistentCbRef = useRef(function() {
270
- var args = [], len = arguments.length;
271
- while (len--) args[len] = arguments[len];
272
- return callbackRef.current.apply(callbackRef, args);
273
- });
274
- return persistentCbRef.current;
275
- }
276
- function splitDecimal(numStr, allowNegative) {
277
- if (allowNegative === void 0) allowNegative = true;
278
- var hasNegation = numStr[0] === "-";
279
- var addNegation = hasNegation && allowNegative;
280
- numStr = numStr.replace("-", "");
281
- var parts = numStr.split(".");
282
- var beforeDecimal = parts[0];
283
- var afterDecimal = parts[1] || "";
284
- return {
285
- beforeDecimal,
286
- afterDecimal,
287
- hasNegation,
288
- addNegation
289
- };
290
- }
291
- function fixLeadingZero(numStr) {
292
- if (!numStr) {
293
- return numStr;
294
- }
295
- var isNegative = numStr[0] === "-";
296
- if (isNegative) {
297
- numStr = numStr.substring(1, numStr.length);
298
- }
299
- var parts = numStr.split(".");
300
- var beforeDecimal = parts[0].replace(/^0+/, "") || "0";
301
- var afterDecimal = parts[1] || "";
302
- return (isNegative ? "-" : "") + beforeDecimal + (afterDecimal ? "." + afterDecimal : "");
303
- }
304
- function limitToScale(numStr, scale, fixedDecimalScale) {
305
- var str = "";
306
- var filler = fixedDecimalScale ? "0" : "";
307
- for (var i = 0; i <= scale - 1; i++) {
308
- str += numStr[i] || filler;
309
- }
310
- return str;
311
- }
312
- function repeat(str, count) {
313
- return Array(count + 1).join(str);
314
- }
315
- function toNumericString(num) {
316
- var _num = num + "";
317
- var sign = _num[0] === "-" ? "-" : "";
318
- if (sign) {
319
- _num = _num.substring(1);
320
- }
321
- var ref = _num.split(/[eE]/g);
322
- var coefficient = ref[0];
323
- var exponent = ref[1];
324
- exponent = Number(exponent);
325
- if (!exponent) {
326
- return sign + coefficient;
327
- }
328
- coefficient = coefficient.replace(".", "");
329
- var decimalIndex = 1 + exponent;
330
- var coffiecientLn = coefficient.length;
331
- if (decimalIndex < 0) {
332
- coefficient = "0." + repeat("0", Math.abs(decimalIndex)) + coefficient;
333
- } else if (decimalIndex >= coffiecientLn) {
334
- coefficient = coefficient + repeat("0", decimalIndex - coffiecientLn);
335
- } else {
336
- coefficient = (coefficient.substring(0, decimalIndex) || "0") + "." + coefficient.substring(decimalIndex);
337
- }
338
- return sign + coefficient;
339
- }
340
- function roundToPrecision(numStr, scale, fixedDecimalScale) {
341
- if (["", "-"].indexOf(numStr) !== -1) {
342
- return numStr;
343
- }
344
- var shouldHaveDecimalSeparator = (numStr.indexOf(".") !== -1 || fixedDecimalScale) && scale;
345
- var ref = splitDecimal(numStr);
346
- var beforeDecimal = ref.beforeDecimal;
347
- var afterDecimal = ref.afterDecimal;
348
- var hasNegation = ref.hasNegation;
349
- var floatValue = parseFloat("0." + (afterDecimal || "0"));
350
- var floatValueStr = afterDecimal.length <= scale ? "0." + afterDecimal : floatValue.toFixed(scale);
351
- var roundedDecimalParts = floatValueStr.split(".");
352
- var intPart = beforeDecimal;
353
- if (beforeDecimal && Number(roundedDecimalParts[0])) {
354
- intPart = beforeDecimal.split("").reverse().reduce(function(roundedStr, current, idx) {
355
- if (roundedStr.length > idx) {
356
- return (Number(roundedStr[0]) + Number(current)).toString() + roundedStr.substring(1, roundedStr.length);
357
- }
358
- return current + roundedStr;
359
- }, roundedDecimalParts[0]);
360
- }
361
- var decimalPart = limitToScale(roundedDecimalParts[1] || "", scale, fixedDecimalScale);
362
- var negation = hasNegation ? "-" : "";
363
- var decimalSeparator = shouldHaveDecimalSeparator ? "." : "";
364
- return "" + negation + intPart + decimalSeparator + decimalPart;
365
- }
366
- function setCaretPosition(el, caretPos) {
367
- el.value = el.value;
368
- if (el !== null) {
369
- if (el.createTextRange) {
370
- var range = el.createTextRange();
371
- range.move("character", caretPos);
372
- range.select();
373
- return true;
374
- }
375
- if (el.selectionStart || el.selectionStart === 0) {
376
- el.focus();
377
- el.setSelectionRange(caretPos, caretPos);
378
- return true;
379
- }
380
- el.focus();
381
- return false;
382
- }
383
- }
384
- var findChangeRange = memoizeOnce(function(prevValue, newValue) {
385
- var i = 0, j = 0;
386
- var prevLength = prevValue.length;
387
- var newLength = newValue.length;
388
- while (prevValue[i] === newValue[i] && i < prevLength) {
389
- i++;
390
- }
391
- while (prevValue[prevLength - 1 - j] === newValue[newLength - 1 - j] && newLength - j > i && prevLength - j > i) {
392
- j++;
393
- }
394
- return {
395
- from: { start: i, end: prevLength - j },
396
- to: { start: i, end: newLength - j }
397
- };
398
- });
399
- var findChangedRangeFromCaretPositions = function(lastCaretPositions, currentCaretPosition) {
400
- var startPosition = Math.min(lastCaretPositions.selectionStart, currentCaretPosition);
401
- return {
402
- from: { start: startPosition, end: lastCaretPositions.selectionEnd },
403
- to: { start: startPosition, end: currentCaretPosition }
404
- };
405
- };
406
- function clamp(num, min, max) {
407
- return Math.min(Math.max(num, min), max);
408
- }
409
- function geInputCaretPosition(el) {
410
- return Math.max(el.selectionStart, el.selectionEnd);
411
- }
412
- function addInputMode() {
413
- return typeof navigator !== "undefined" && !(navigator.platform && /iPhone|iPod/.test(navigator.platform));
414
- }
415
- function getDefaultChangeMeta(value) {
416
- return {
417
- from: {
418
- start: 0,
419
- end: 0
420
- },
421
- to: {
422
- start: 0,
423
- end: value.length
424
- },
425
- lastValue: ""
426
- };
427
- }
428
- function defaultIsCharacterSame(ref) {
429
- var currentValue = ref.currentValue;
430
- var formattedValue = ref.formattedValue;
431
- var currentValueIndex = ref.currentValueIndex;
432
- var formattedValueIndex = ref.formattedValueIndex;
433
- return currentValue[currentValueIndex] === formattedValue[formattedValueIndex];
434
- }
435
- function getCaretPosition(newFormattedValue, lastFormattedValue, curValue, curCaretPos, boundary, isValidInputCharacter, isCharacterSame) {
436
- if (isCharacterSame === void 0) isCharacterSame = defaultIsCharacterSame;
437
- var firstAllowedPosition = boundary.findIndex(function(b) {
438
- return b;
439
- });
440
- var prefixFormat = newFormattedValue.slice(0, firstAllowedPosition);
441
- if (!lastFormattedValue && !curValue.startsWith(prefixFormat)) {
442
- lastFormattedValue = prefixFormat;
443
- curValue = prefixFormat + curValue;
444
- curCaretPos = curCaretPos + prefixFormat.length;
445
- }
446
- var curValLn = curValue.length;
447
- var formattedValueLn = newFormattedValue.length;
448
- var addedIndexMap = {};
449
- var indexMap = new Array(curValLn);
450
- for (var i = 0; i < curValLn; i++) {
451
- indexMap[i] = -1;
452
- for (var j = 0, jLn = formattedValueLn; j < jLn; j++) {
453
- var isCharSame = isCharacterSame({
454
- currentValue: curValue,
455
- lastValue: lastFormattedValue,
456
- formattedValue: newFormattedValue,
457
- currentValueIndex: i,
458
- formattedValueIndex: j
459
- });
460
- if (isCharSame && addedIndexMap[j] !== true) {
461
- indexMap[i] = j;
462
- addedIndexMap[j] = true;
463
- break;
464
- }
465
- }
466
- }
467
- var pos = curCaretPos;
468
- while (pos < curValLn && (indexMap[pos] === -1 || !isValidInputCharacter(curValue[pos]))) {
469
- pos++;
470
- }
471
- var endIndex = pos === curValLn || indexMap[pos] === -1 ? formattedValueLn : indexMap[pos];
472
- pos = curCaretPos - 1;
473
- while (pos > 0 && indexMap[pos] === -1) {
474
- pos--;
475
- }
476
- var startIndex = pos === -1 || indexMap[pos] === -1 ? 0 : indexMap[pos] + 1;
477
- if (startIndex > endIndex) {
478
- return endIndex;
479
- }
480
- return curCaretPos - startIndex < endIndex - curCaretPos ? startIndex : endIndex;
481
- }
482
- function getCaretPosInBoundary(value, caretPos, boundary, direction) {
483
- var valLn = value.length;
484
- caretPos = clamp(caretPos, 0, valLn);
485
- if (direction === "left") {
486
- while (caretPos >= 0 && !boundary[caretPos]) {
487
- caretPos--;
488
- }
489
- if (caretPos === -1) {
490
- caretPos = boundary.indexOf(true);
491
- }
492
- } else {
493
- while (caretPos <= valLn && !boundary[caretPos]) {
494
- caretPos++;
495
- }
496
- if (caretPos > valLn) {
497
- caretPos = boundary.lastIndexOf(true);
498
- }
499
- }
500
- if (caretPos === -1) {
501
- caretPos = valLn;
502
- }
503
- return caretPos;
504
- }
505
- function caretUnknownFormatBoundary(formattedValue) {
506
- var boundaryAry = Array.from({ length: formattedValue.length + 1 }).map(function() {
507
- return true;
508
- });
509
- for (var i = 0, ln = boundaryAry.length; i < ln; i++) {
510
- boundaryAry[i] = Boolean(charIsNumber(formattedValue[i]) || charIsNumber(formattedValue[i - 1]));
511
- }
512
- return boundaryAry;
513
- }
514
- function useInternalValues(value, defaultValue, valueIsNumericString, format2, removeFormatting2, onValueChange) {
515
- if (onValueChange === void 0) onValueChange = noop;
516
- var getValues = usePersistentCallback(function(value2, valueIsNumericString2) {
517
- var formattedValue, numAsString;
518
- if (isNotValidValue(value2)) {
519
- numAsString = "";
520
- formattedValue = "";
521
- } else if (typeof value2 === "number" || valueIsNumericString2) {
522
- numAsString = typeof value2 === "number" ? toNumericString(value2) : value2;
523
- formattedValue = format2(numAsString);
524
- } else {
525
- numAsString = removeFormatting2(value2, void 0);
526
- formattedValue = format2(numAsString);
527
- }
528
- return { formattedValue, numAsString };
529
- });
530
- var ref = useState(function() {
531
- return getValues(isNil(value) ? defaultValue : value, valueIsNumericString);
532
- });
533
- var values = ref[0];
534
- var setValues = ref[1];
535
- var _onValueChange = function(newValues2, sourceInfo) {
536
- if (newValues2.formattedValue !== values.formattedValue) {
537
- setValues({
538
- formattedValue: newValues2.formattedValue,
539
- numAsString: newValues2.value
540
- });
541
- }
542
- onValueChange(newValues2, sourceInfo);
543
- };
544
- var _value = value;
545
- var _valueIsNumericString = valueIsNumericString;
546
- if (isNil(value)) {
547
- _value = values.numAsString;
548
- _valueIsNumericString = true;
549
- }
550
- var newValues = getValues(_value, _valueIsNumericString);
551
- useMemo(function() {
552
- setValues(newValues);
553
- }, [newValues.formattedValue]);
554
- return [values, _onValueChange];
555
- }
556
- function defaultRemoveFormatting(value) {
557
- return value.replace(/[^0-9]/g, "");
558
- }
559
- function defaultFormat(value) {
560
- return value;
561
- }
562
- function NumberFormatBase(props) {
563
- var type = props.type;
564
- if (type === void 0) type = "text";
565
- var displayType = props.displayType;
566
- if (displayType === void 0) displayType = "input";
567
- var customInput = props.customInput;
568
- var renderText = props.renderText;
569
- var getInputRef = props.getInputRef;
570
- var format2 = props.format;
571
- if (format2 === void 0) format2 = defaultFormat;
572
- var removeFormatting2 = props.removeFormatting;
573
- if (removeFormatting2 === void 0) removeFormatting2 = defaultRemoveFormatting;
574
- var defaultValue = props.defaultValue;
575
- var valueIsNumericString = props.valueIsNumericString;
576
- var onValueChange = props.onValueChange;
577
- var isAllowed = props.isAllowed;
578
- var onChange = props.onChange;
579
- if (onChange === void 0) onChange = noop;
580
- var onKeyDown = props.onKeyDown;
581
- if (onKeyDown === void 0) onKeyDown = noop;
582
- var onMouseUp = props.onMouseUp;
583
- if (onMouseUp === void 0) onMouseUp = noop;
584
- var onFocus = props.onFocus;
585
- if (onFocus === void 0) onFocus = noop;
586
- var onBlur = props.onBlur;
587
- if (onBlur === void 0) onBlur = noop;
588
- var propValue = props.value;
589
- var getCaretBoundary2 = props.getCaretBoundary;
590
- if (getCaretBoundary2 === void 0) getCaretBoundary2 = caretUnknownFormatBoundary;
591
- var isValidInputCharacter = props.isValidInputCharacter;
592
- if (isValidInputCharacter === void 0) isValidInputCharacter = charIsNumber;
593
- var isCharacterSame = props.isCharacterSame;
594
- var otherProps = __rest(props, ["type", "displayType", "customInput", "renderText", "getInputRef", "format", "removeFormatting", "defaultValue", "valueIsNumericString", "onValueChange", "isAllowed", "onChange", "onKeyDown", "onMouseUp", "onFocus", "onBlur", "value", "getCaretBoundary", "isValidInputCharacter", "isCharacterSame"]);
595
- var ref = useInternalValues(propValue, defaultValue, Boolean(valueIsNumericString), format2, removeFormatting2, onValueChange);
596
- var ref_0 = ref[0];
597
- var formattedValue = ref_0.formattedValue;
598
- var numAsString = ref_0.numAsString;
599
- var onFormattedValueChange = ref[1];
600
- var caretPositionBeforeChange = useRef();
601
- var lastUpdatedValue = useRef({ formattedValue, numAsString });
602
- var _onValueChange = function(values, source) {
603
- lastUpdatedValue.current = { formattedValue: values.formattedValue, numAsString: values.value };
604
- onFormattedValueChange(values, source);
605
- };
606
- var ref$1 = useState(false);
607
- var mounted = ref$1[0];
608
- var setMounted = ref$1[1];
609
- var focusedElm = useRef(null);
610
- var timeout = useRef({
611
- setCaretTimeout: null,
612
- focusTimeout: null
613
- });
614
- useEffect(function() {
615
- setMounted(true);
616
- return function() {
617
- clearTimeout(timeout.current.setCaretTimeout);
618
- clearTimeout(timeout.current.focusTimeout);
619
- };
620
- }, []);
621
- var _format = format2;
622
- var getValueObject = function(formattedValue2, numAsString2) {
623
- var floatValue = parseFloat(numAsString2);
624
- return {
625
- formattedValue: formattedValue2,
626
- value: numAsString2,
627
- floatValue: isNaN(floatValue) ? void 0 : floatValue
628
- };
629
- };
630
- var setPatchedCaretPosition = function(el, caretPos, currentValue) {
631
- if (el.selectionStart === 0 && el.selectionEnd === el.value.length) {
632
- return;
633
- }
634
- setCaretPosition(el, caretPos);
635
- timeout.current.setCaretTimeout = setTimeout(function() {
636
- if (el.value === currentValue && el.selectionStart !== caretPos) {
637
- setCaretPosition(el, caretPos);
638
- }
639
- }, 0);
640
- };
641
- var correctCaretPosition = function(value, caretPos, direction) {
642
- return getCaretPosInBoundary(value, caretPos, getCaretBoundary2(value), direction);
643
- };
644
- var getNewCaretPosition = function(inputValue, newFormattedValue, caretPos) {
645
- var caretBoundary = getCaretBoundary2(newFormattedValue);
646
- var updatedCaretPos = getCaretPosition(newFormattedValue, formattedValue, inputValue, caretPos, caretBoundary, isValidInputCharacter, isCharacterSame);
647
- updatedCaretPos = getCaretPosInBoundary(newFormattedValue, updatedCaretPos, caretBoundary);
648
- return updatedCaretPos;
649
- };
650
- var updateValueAndCaretPosition = function(params) {
651
- var newFormattedValue = params.formattedValue;
652
- if (newFormattedValue === void 0) newFormattedValue = "";
653
- var input = params.input;
654
- var source = params.source;
655
- var event = params.event;
656
- var numAsString2 = params.numAsString;
657
- var caretPos;
658
- if (input) {
659
- var inputValue = params.inputValue || input.value;
660
- var currentCaretPosition2 = geInputCaretPosition(input);
661
- input.value = newFormattedValue;
662
- caretPos = getNewCaretPosition(inputValue, newFormattedValue, currentCaretPosition2);
663
- if (caretPos !== void 0) {
664
- setPatchedCaretPosition(input, caretPos, newFormattedValue);
665
- }
666
- }
667
- if (newFormattedValue !== formattedValue) {
668
- _onValueChange(getValueObject(newFormattedValue, numAsString2), { event, source });
669
- }
670
- };
671
- useEffect(function() {
672
- var ref2 = lastUpdatedValue.current;
673
- var lastFormattedValue = ref2.formattedValue;
674
- var lastNumAsString = ref2.numAsString;
675
- if (formattedValue !== lastFormattedValue || numAsString !== lastNumAsString) {
676
- _onValueChange(getValueObject(formattedValue, numAsString), {
677
- event: void 0,
678
- source: SourceType.props
679
- });
680
- }
681
- }, [formattedValue, numAsString]);
682
- var currentCaretPosition = focusedElm.current ? geInputCaretPosition(focusedElm.current) : void 0;
683
- var useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect;
684
- useIsomorphicLayoutEffect(function() {
685
- var input = focusedElm.current;
686
- if (formattedValue !== lastUpdatedValue.current.formattedValue && input) {
687
- var caretPos = getNewCaretPosition(lastUpdatedValue.current.formattedValue, formattedValue, currentCaretPosition);
688
- input.value = formattedValue;
689
- setPatchedCaretPosition(input, caretPos, formattedValue);
690
- }
691
- }, [formattedValue]);
692
- var formatInputValue = function(inputValue, event, source) {
693
- var input = event.target;
694
- var changeRange = caretPositionBeforeChange.current ? findChangedRangeFromCaretPositions(caretPositionBeforeChange.current, input.selectionEnd) : findChangeRange(formattedValue, inputValue);
695
- var changeMeta = Object.assign(Object.assign({}, changeRange), { lastValue: formattedValue });
696
- var _numAsString = removeFormatting2(inputValue, changeMeta);
697
- var _formattedValue = _format(_numAsString);
698
- _numAsString = removeFormatting2(_formattedValue, void 0);
699
- if (isAllowed && !isAllowed(getValueObject(_formattedValue, _numAsString))) {
700
- var input$1 = event.target;
701
- var currentCaretPosition2 = geInputCaretPosition(input$1);
702
- var caretPos = getNewCaretPosition(inputValue, formattedValue, currentCaretPosition2);
703
- input$1.value = formattedValue;
704
- setPatchedCaretPosition(input$1, caretPos, formattedValue);
705
- return false;
706
- }
707
- updateValueAndCaretPosition({
708
- formattedValue: _formattedValue,
709
- numAsString: _numAsString,
710
- inputValue,
711
- event,
712
- source,
713
- input: event.target
714
- });
715
- return true;
716
- };
717
- var setCaretPositionInfoBeforeChange = function(el, endOffset) {
718
- if (endOffset === void 0) endOffset = 0;
719
- var selectionStart = el.selectionStart;
720
- var selectionEnd = el.selectionEnd;
721
- caretPositionBeforeChange.current = { selectionStart, selectionEnd: selectionEnd + endOffset };
722
- };
723
- var _onChange = function(e) {
724
- var el = e.target;
725
- var inputValue = el.value;
726
- var changed = formatInputValue(inputValue, e, SourceType.event);
727
- if (changed) {
728
- onChange(e);
729
- }
730
- caretPositionBeforeChange.current = void 0;
731
- };
732
- var _onKeyDown = function(e) {
733
- var el = e.target;
734
- var key = e.key;
735
- var selectionStart = el.selectionStart;
736
- var selectionEnd = el.selectionEnd;
737
- var value = el.value;
738
- if (value === void 0) value = "";
739
- var expectedCaretPosition;
740
- if (key === "ArrowLeft" || key === "Backspace") {
741
- expectedCaretPosition = Math.max(selectionStart - 1, 0);
742
- } else if (key === "ArrowRight") {
743
- expectedCaretPosition = Math.min(selectionStart + 1, value.length);
744
- } else if (key === "Delete") {
745
- expectedCaretPosition = selectionStart;
746
- }
747
- var endOffset = 0;
748
- if (key === "Delete" && selectionStart === selectionEnd) {
749
- endOffset = 1;
750
- }
751
- var isArrowKey = key === "ArrowLeft" || key === "ArrowRight";
752
- if (expectedCaretPosition === void 0 || selectionStart !== selectionEnd && !isArrowKey) {
753
- onKeyDown(e);
754
- setCaretPositionInfoBeforeChange(el, endOffset);
755
- return;
756
- }
757
- var newCaretPosition = expectedCaretPosition;
758
- if (isArrowKey) {
759
- var direction = key === "ArrowLeft" ? "left" : "right";
760
- newCaretPosition = correctCaretPosition(value, expectedCaretPosition, direction);
761
- if (newCaretPosition !== expectedCaretPosition) {
762
- e.preventDefault();
763
- }
764
- } else if (key === "Delete" && !isValidInputCharacter(value[expectedCaretPosition])) {
765
- newCaretPosition = correctCaretPosition(value, expectedCaretPosition, "right");
766
- } else if (key === "Backspace" && !isValidInputCharacter(value[expectedCaretPosition])) {
767
- newCaretPosition = correctCaretPosition(value, expectedCaretPosition, "left");
768
- }
769
- if (newCaretPosition !== expectedCaretPosition) {
770
- setPatchedCaretPosition(el, newCaretPosition, value);
771
- }
772
- onKeyDown(e);
773
- setCaretPositionInfoBeforeChange(el, endOffset);
774
- };
775
- var _onMouseUp = function(e) {
776
- var el = e.target;
777
- var correctCaretPositionIfRequired = function() {
778
- var selectionStart = el.selectionStart;
779
- var selectionEnd = el.selectionEnd;
780
- var value = el.value;
781
- if (value === void 0) value = "";
782
- if (selectionStart === selectionEnd) {
783
- var caretPosition = correctCaretPosition(value, selectionStart);
784
- if (caretPosition !== selectionStart) {
785
- setPatchedCaretPosition(el, caretPosition, value);
786
- }
787
- }
788
- };
789
- correctCaretPositionIfRequired();
790
- requestAnimationFrame(function() {
791
- correctCaretPositionIfRequired();
792
- });
793
- onMouseUp(e);
794
- setCaretPositionInfoBeforeChange(el);
795
- };
796
- var _onFocus = function(e) {
797
- if (e.persist) {
798
- e.persist();
799
- }
800
- var el = e.target;
801
- var currentTarget = e.currentTarget;
802
- focusedElm.current = el;
803
- timeout.current.focusTimeout = setTimeout(function() {
804
- var selectionStart = el.selectionStart;
805
- var selectionEnd = el.selectionEnd;
806
- var value = el.value;
807
- if (value === void 0) value = "";
808
- var caretPosition = correctCaretPosition(value, selectionStart);
809
- if (caretPosition !== selectionStart && !(selectionStart === 0 && selectionEnd === value.length)) {
810
- setPatchedCaretPosition(el, caretPosition, value);
811
- }
812
- onFocus(Object.assign(Object.assign({}, e), { currentTarget }));
813
- }, 0);
814
- };
815
- var _onBlur = function(e) {
816
- focusedElm.current = null;
817
- clearTimeout(timeout.current.focusTimeout);
818
- clearTimeout(timeout.current.setCaretTimeout);
819
- onBlur(e);
820
- };
821
- var inputMode = mounted && addInputMode() ? "numeric" : void 0;
822
- var inputProps = Object.assign({ inputMode }, otherProps, {
823
- type,
824
- value: formattedValue,
825
- onChange: _onChange,
826
- onKeyDown: _onKeyDown,
827
- onMouseUp: _onMouseUp,
828
- onFocus: _onFocus,
829
- onBlur: _onBlur
830
- });
831
- if (displayType === "text") {
832
- return renderText ? React.createElement(React.Fragment, null, renderText(formattedValue, otherProps) || null) : React.createElement("span", Object.assign({}, otherProps, { ref: getInputRef }), formattedValue);
833
- } else if (customInput) {
834
- var CustomInput = customInput;
835
- return React.createElement(CustomInput, Object.assign({}, inputProps, { ref: getInputRef }));
836
- }
837
- return React.createElement("input", Object.assign({}, inputProps, { ref: getInputRef }));
838
- }
839
- function format(numStr, props) {
840
- var decimalScale = props.decimalScale;
841
- var fixedDecimalScale = props.fixedDecimalScale;
842
- var prefix = props.prefix;
843
- if (prefix === void 0) prefix = "";
844
- var suffix = props.suffix;
845
- if (suffix === void 0) suffix = "";
846
- var allowNegative = props.allowNegative;
847
- var thousandsGroupStyle = props.thousandsGroupStyle;
848
- if (thousandsGroupStyle === void 0) thousandsGroupStyle = "thousand";
849
- if (numStr === "" || numStr === "-") {
850
- return numStr;
851
- }
852
- var ref = getSeparators(props);
853
- var thousandSeparator = ref.thousandSeparator;
854
- var decimalSeparator = ref.decimalSeparator;
855
- var hasDecimalSeparator = decimalScale !== 0 && numStr.indexOf(".") !== -1 || decimalScale && fixedDecimalScale;
856
- var ref$1 = splitDecimal(numStr, allowNegative);
857
- var beforeDecimal = ref$1.beforeDecimal;
858
- var afterDecimal = ref$1.afterDecimal;
859
- var addNegation = ref$1.addNegation;
860
- if (decimalScale !== void 0) {
861
- afterDecimal = limitToScale(afterDecimal, decimalScale, !!fixedDecimalScale);
862
- }
863
- if (thousandSeparator) {
864
- beforeDecimal = applyThousandSeparator(beforeDecimal, thousandSeparator, thousandsGroupStyle);
865
- }
866
- if (prefix) {
867
- beforeDecimal = prefix + beforeDecimal;
868
- }
869
- if (suffix) {
870
- afterDecimal = afterDecimal + suffix;
871
- }
872
- if (addNegation) {
873
- beforeDecimal = "-" + beforeDecimal;
874
- }
875
- numStr = beforeDecimal + (hasDecimalSeparator && decimalSeparator || "") + afterDecimal;
876
- return numStr;
877
- }
878
- function getSeparators(props) {
879
- var decimalSeparator = props.decimalSeparator;
880
- if (decimalSeparator === void 0) decimalSeparator = ".";
881
- var thousandSeparator = props.thousandSeparator;
882
- var allowedDecimalSeparators = props.allowedDecimalSeparators;
883
- if (thousandSeparator === true) {
884
- thousandSeparator = ",";
885
- }
886
- if (!allowedDecimalSeparators) {
887
- allowedDecimalSeparators = [decimalSeparator, "."];
888
- }
889
- return {
890
- decimalSeparator,
891
- thousandSeparator,
892
- allowedDecimalSeparators
893
- };
894
- }
895
- function handleNegation(value, allowNegative) {
896
- if (value === void 0) value = "";
897
- var negationRegex = new RegExp("(-)");
898
- var doubleNegationRegex = new RegExp("(-)(.)*(-)");
899
- var hasNegation = negationRegex.test(value);
900
- var removeNegation = doubleNegationRegex.test(value);
901
- value = value.replace(/-/g, "");
902
- if (hasNegation && !removeNegation && allowNegative) {
903
- value = "-" + value;
904
- }
905
- return value;
906
- }
907
- function getNumberRegex(decimalSeparator, global) {
908
- return new RegExp("(^-)|[0-9]|" + escapeRegExp(decimalSeparator), "g");
909
- }
910
- function isNumericString(val, prefix, suffix) {
911
- if (val === "") {
912
- return true;
913
- }
914
- return !(prefix === null || prefix === void 0 ? void 0 : prefix.match(/\d/)) && !(suffix === null || suffix === void 0 ? void 0 : suffix.match(/\d/)) && typeof val === "string" && !isNaN(Number(val));
915
- }
916
- function removeFormatting(value, changeMeta, props) {
917
- var assign;
918
- if (changeMeta === void 0) changeMeta = getDefaultChangeMeta(value);
919
- var allowNegative = props.allowNegative;
920
- var prefix = props.prefix;
921
- if (prefix === void 0) prefix = "";
922
- var suffix = props.suffix;
923
- if (suffix === void 0) suffix = "";
924
- var decimalScale = props.decimalScale;
925
- var from = changeMeta.from;
926
- var to = changeMeta.to;
927
- var start = to.start;
928
- var end = to.end;
929
- var ref = getSeparators(props);
930
- var allowedDecimalSeparators = ref.allowedDecimalSeparators;
931
- var decimalSeparator = ref.decimalSeparator;
932
- var isBeforeDecimalSeparator = value[end] === decimalSeparator;
933
- if (charIsNumber(value) && (value === prefix || value === suffix) && changeMeta.lastValue === "") {
934
- return value;
935
- }
936
- if (end - start === 1 && allowedDecimalSeparators.indexOf(value[start]) !== -1) {
937
- var separator = decimalScale === 0 ? "" : decimalSeparator;
938
- value = value.substring(0, start) + separator + value.substring(start + 1, value.length);
939
- }
940
- var stripNegation = function(value2, start2, end2) {
941
- var hasNegation2 = false;
942
- var hasDoubleNegation = false;
943
- if (prefix.startsWith("-")) {
944
- hasNegation2 = false;
945
- } else if (value2.startsWith("--")) {
946
- hasNegation2 = false;
947
- hasDoubleNegation = true;
948
- } else if (suffix.startsWith("-") && value2.length === suffix.length) {
949
- hasNegation2 = false;
950
- } else if (value2[0] === "-") {
951
- hasNegation2 = true;
952
- }
953
- var charsToRemove = hasNegation2 ? 1 : 0;
954
- if (hasDoubleNegation) {
955
- charsToRemove = 2;
956
- }
957
- if (charsToRemove) {
958
- value2 = value2.substring(charsToRemove);
959
- start2 -= charsToRemove;
960
- end2 -= charsToRemove;
961
- }
962
- return { value: value2, start: start2, end: end2, hasNegation: hasNegation2 };
963
- };
964
- var toMetadata = stripNegation(value, start, end);
965
- var hasNegation = toMetadata.hasNegation;
966
- assign = toMetadata, value = assign.value, start = assign.start, end = assign.end;
967
- var ref$1 = stripNegation(changeMeta.lastValue, from.start, from.end);
968
- var fromStart = ref$1.start;
969
- var fromEnd = ref$1.end;
970
- var lastValue = ref$1.value;
971
- var updatedSuffixPart = value.substring(start, end);
972
- if (value.length && lastValue.length && (fromStart > lastValue.length - suffix.length || fromEnd < prefix.length) && !(updatedSuffixPart && suffix.startsWith(updatedSuffixPart))) {
973
- value = lastValue;
974
- }
975
- var startIndex = 0;
976
- if (value.startsWith(prefix)) {
977
- startIndex += prefix.length;
978
- } else if (start < prefix.length) {
979
- startIndex = start;
980
- }
981
- value = value.substring(startIndex);
982
- end -= startIndex;
983
- var endIndex = value.length;
984
- var suffixStartIndex = value.length - suffix.length;
985
- if (value.endsWith(suffix)) {
986
- endIndex = suffixStartIndex;
987
- } else if (end > suffixStartIndex) {
988
- endIndex = end;
989
- } else if (end > value.length - suffix.length) {
990
- endIndex = end;
991
- }
992
- value = value.substring(0, endIndex);
993
- value = handleNegation(hasNegation ? "-" + value : value, allowNegative);
994
- value = (value.match(getNumberRegex(decimalSeparator)) || []).join("");
995
- var firstIndex = value.indexOf(decimalSeparator);
996
- value = value.replace(new RegExp(escapeRegExp(decimalSeparator), "g"), function(match, index) {
997
- return index === firstIndex ? "." : "";
998
- });
999
- var ref$2 = splitDecimal(value, allowNegative);
1000
- var beforeDecimal = ref$2.beforeDecimal;
1001
- var afterDecimal = ref$2.afterDecimal;
1002
- var addNegation = ref$2.addNegation;
1003
- if (to.end - to.start < from.end - from.start && beforeDecimal === "" && isBeforeDecimalSeparator && !parseFloat(afterDecimal)) {
1004
- value = addNegation ? "-" : "";
1005
- }
1006
- return value;
1007
- }
1008
- function getCaretBoundary(formattedValue, props) {
1009
- var prefix = props.prefix;
1010
- if (prefix === void 0) prefix = "";
1011
- var suffix = props.suffix;
1012
- if (suffix === void 0) suffix = "";
1013
- var boundaryAry = Array.from({ length: formattedValue.length + 1 }).map(function() {
1014
- return true;
1015
- });
1016
- var hasNegation = formattedValue[0] === "-";
1017
- boundaryAry.fill(false, 0, prefix.length + (hasNegation ? 1 : 0));
1018
- var valLn = formattedValue.length;
1019
- boundaryAry.fill(false, valLn - suffix.length + 1, valLn + 1);
1020
- return boundaryAry;
1021
- }
1022
- function validateAndUpdateProps(props) {
1023
- var ref = getSeparators(props);
1024
- var thousandSeparator = ref.thousandSeparator;
1025
- var decimalSeparator = ref.decimalSeparator;
1026
- var prefix = props.prefix;
1027
- if (prefix === void 0) prefix = "";
1028
- var allowNegative = props.allowNegative;
1029
- if (allowNegative === void 0) allowNegative = true;
1030
- if (thousandSeparator === decimalSeparator) {
1031
- throw new Error("\n Decimal separator can't be same as thousand separator.\n thousandSeparator: " + thousandSeparator + ' (thousandSeparator = {true} is same as thousandSeparator = ",")\n decimalSeparator: ' + decimalSeparator + " (default value for decimalSeparator is .)\n ");
1032
- }
1033
- if (prefix.startsWith("-") && allowNegative) {
1034
- console.error("\n Prefix can't start with '-' when allowNegative is true.\n prefix: " + prefix + "\n allowNegative: " + allowNegative + "\n ");
1035
- allowNegative = false;
1036
- }
1037
- return Object.assign(Object.assign({}, props), { allowNegative });
1038
- }
1039
- function useNumericFormat(props) {
1040
- props = validateAndUpdateProps(props);
1041
- props.decimalSeparator;
1042
- props.allowedDecimalSeparators;
1043
- props.thousandsGroupStyle;
1044
- var suffix = props.suffix;
1045
- var allowNegative = props.allowNegative;
1046
- var allowLeadingZeros = props.allowLeadingZeros;
1047
- var onKeyDown = props.onKeyDown;
1048
- if (onKeyDown === void 0) onKeyDown = noop;
1049
- var onBlur = props.onBlur;
1050
- if (onBlur === void 0) onBlur = noop;
1051
- var thousandSeparator = props.thousandSeparator;
1052
- var decimalScale = props.decimalScale;
1053
- var fixedDecimalScale = props.fixedDecimalScale;
1054
- var prefix = props.prefix;
1055
- if (prefix === void 0) prefix = "";
1056
- var defaultValue = props.defaultValue;
1057
- var value = props.value;
1058
- var valueIsNumericString = props.valueIsNumericString;
1059
- var onValueChange = props.onValueChange;
1060
- var restProps = __rest(props, ["decimalSeparator", "allowedDecimalSeparators", "thousandsGroupStyle", "suffix", "allowNegative", "allowLeadingZeros", "onKeyDown", "onBlur", "thousandSeparator", "decimalScale", "fixedDecimalScale", "prefix", "defaultValue", "value", "valueIsNumericString", "onValueChange"]);
1061
- var ref = getSeparators(props);
1062
- var decimalSeparator = ref.decimalSeparator;
1063
- var allowedDecimalSeparators = ref.allowedDecimalSeparators;
1064
- var _format = function(numStr) {
1065
- return format(numStr, props);
1066
- };
1067
- var _removeFormatting = function(inputValue, changeMeta) {
1068
- return removeFormatting(inputValue, changeMeta, props);
1069
- };
1070
- var _value = isNil(value) ? defaultValue : value;
1071
- var _valueIsNumericString = valueIsNumericString !== null && valueIsNumericString !== void 0 ? valueIsNumericString : isNumericString(_value, prefix, suffix);
1072
- if (!isNil(value)) {
1073
- _valueIsNumericString = _valueIsNumericString || typeof value === "number";
1074
- } else if (!isNil(defaultValue)) {
1075
- _valueIsNumericString = _valueIsNumericString || typeof defaultValue === "number";
1076
- }
1077
- var roundIncomingValueToPrecision = function(value2) {
1078
- if (isNotValidValue(value2)) {
1079
- return value2;
1080
- }
1081
- if (typeof value2 === "number") {
1082
- value2 = toNumericString(value2);
1083
- }
1084
- if (_valueIsNumericString && typeof decimalScale === "number") {
1085
- return roundToPrecision(value2, decimalScale, Boolean(fixedDecimalScale));
1086
- }
1087
- return value2;
1088
- };
1089
- var ref$1 = useInternalValues(roundIncomingValueToPrecision(value), roundIncomingValueToPrecision(defaultValue), Boolean(_valueIsNumericString), _format, _removeFormatting, onValueChange);
1090
- var ref$1_0 = ref$1[0];
1091
- var numAsString = ref$1_0.numAsString;
1092
- var formattedValue = ref$1_0.formattedValue;
1093
- var _onValueChange = ref$1[1];
1094
- var _onKeyDown = function(e) {
1095
- var el = e.target;
1096
- var key = e.key;
1097
- var selectionStart = el.selectionStart;
1098
- var selectionEnd = el.selectionEnd;
1099
- var value2 = el.value;
1100
- if (value2 === void 0) value2 = "";
1101
- if ((key === "Backspace" || key === "Delete") && selectionEnd < prefix.length) {
1102
- e.preventDefault();
1103
- return;
1104
- }
1105
- if (selectionStart !== selectionEnd) {
1106
- onKeyDown(e);
1107
- return;
1108
- }
1109
- if (key === "Backspace" && value2[0] === "-" && selectionStart === prefix.length + 1 && allowNegative) {
1110
- setCaretPosition(el, 1);
1111
- }
1112
- if (decimalScale && fixedDecimalScale) {
1113
- if (key === "Backspace" && value2[selectionStart - 1] === decimalSeparator) {
1114
- setCaretPosition(el, selectionStart - 1);
1115
- e.preventDefault();
1116
- } else if (key === "Delete" && value2[selectionStart] === decimalSeparator) {
1117
- e.preventDefault();
1118
- }
1119
- }
1120
- if ((allowedDecimalSeparators === null || allowedDecimalSeparators === void 0 ? void 0 : allowedDecimalSeparators.includes(key)) && value2[selectionStart] === decimalSeparator) {
1121
- setCaretPosition(el, selectionStart + 1);
1122
- }
1123
- var _thousandSeparator = thousandSeparator === true ? "," : thousandSeparator;
1124
- if (key === "Backspace" && value2[selectionStart - 1] === _thousandSeparator) {
1125
- setCaretPosition(el, selectionStart - 1);
1126
- }
1127
- if (key === "Delete" && value2[selectionStart] === _thousandSeparator) {
1128
- setCaretPosition(el, selectionStart + 1);
1129
- }
1130
- onKeyDown(e);
1131
- };
1132
- var _onBlur = function(e) {
1133
- var _value2 = numAsString;
1134
- if (!_value2.match(/\d/g)) {
1135
- _value2 = "";
1136
- }
1137
- if (!allowLeadingZeros) {
1138
- _value2 = fixLeadingZero(_value2);
1139
- }
1140
- if (fixedDecimalScale && decimalScale) {
1141
- _value2 = roundToPrecision(_value2, decimalScale, fixedDecimalScale);
1142
- }
1143
- if (_value2 !== numAsString) {
1144
- var formattedValue2 = format(_value2, props);
1145
- _onValueChange({
1146
- formattedValue: formattedValue2,
1147
- value: _value2,
1148
- floatValue: parseFloat(_value2)
1149
- }, {
1150
- event: e,
1151
- source: SourceType.event
1152
- });
1153
- }
1154
- onBlur(e);
1155
- };
1156
- var isValidInputCharacter = function(inputChar) {
1157
- if (inputChar === decimalSeparator) {
1158
- return true;
1159
- }
1160
- return charIsNumber(inputChar);
1161
- };
1162
- var isCharacterSame = function(ref2) {
1163
- var currentValue = ref2.currentValue;
1164
- var lastValue = ref2.lastValue;
1165
- var formattedValue2 = ref2.formattedValue;
1166
- var currentValueIndex = ref2.currentValueIndex;
1167
- var formattedValueIndex = ref2.formattedValueIndex;
1168
- var curChar = currentValue[currentValueIndex];
1169
- var newChar = formattedValue2[formattedValueIndex];
1170
- var typedRange = findChangeRange(lastValue, currentValue);
1171
- var to = typedRange.to;
1172
- var getDecimalSeparatorIndex = function(value2) {
1173
- return _removeFormatting(value2).indexOf(".") + prefix.length;
1174
- };
1175
- if (value === 0 && fixedDecimalScale && decimalScale && currentValue[to.start] === decimalSeparator && getDecimalSeparatorIndex(currentValue) < currentValueIndex && getDecimalSeparatorIndex(formattedValue2) > formattedValueIndex) {
1176
- return false;
1177
- }
1178
- if (currentValueIndex >= to.start && currentValueIndex < to.end && allowedDecimalSeparators && allowedDecimalSeparators.includes(curChar) && newChar === decimalSeparator) {
1179
- return true;
1180
- }
1181
- return curChar === newChar;
1182
- };
1183
- return Object.assign(Object.assign({}, restProps), {
1184
- value: formattedValue,
1185
- valueIsNumericString: false,
1186
- isValidInputCharacter,
1187
- isCharacterSame,
1188
- onValueChange: _onValueChange,
1189
- format: _format,
1190
- removeFormatting: _removeFormatting,
1191
- getCaretBoundary: function(formattedValue2) {
1192
- return getCaretBoundary(formattedValue2, props);
1193
- },
1194
- onKeyDown: _onKeyDown,
1195
- onBlur: _onBlur
1196
- });
1197
- }
1198
- function NumericFormat(props) {
1199
- var numericFormatProps = useNumericFormat(props);
1200
- return React.createElement(NumberFormatBase, Object.assign({}, numericFormatProps));
1201
- }
1202
196
  const FormNumberField = ({ options, ...props }) => {
1203
197
  const field = useFieldContext();
1204
198
  const { isTouched, hasError, helperText } = getFieldStatus(field);
1205
- return /* @__PURE__ */ jsx(
199
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(
1206
200
  NumericFormat,
1207
201
  {
1208
202
  customInput: TextField,
@@ -1221,9 +215,9 @@ const FormNumberField = ({ options, ...props }) => {
1221
215
  const FormRadioGroup = ({ label, options, ...props }) => {
1222
216
  const field = useFieldContext();
1223
217
  const { isTouched, hasError, helperText } = getFieldStatus(field);
1224
- return /* @__PURE__ */ jsxs(FormControl, { component: "fieldset", children: [
1225
- label && /* @__PURE__ */ jsx(FormLabel, { component: "legend", children: label }),
1226
- /* @__PURE__ */ jsx(
218
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs(FormControl, { component: "fieldset", children: [
219
+ label && /* @__PURE__ */ jsxRuntimeExports.jsx(FormLabel, { component: "legend", children: label }),
220
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
1227
221
  RadioGroup,
1228
222
  {
1229
223
  name: field.name,
@@ -1232,26 +226,26 @@ const FormRadioGroup = ({ label, options, ...props }) => {
1232
226
  onBlur: field.handleBlur,
1233
227
  "aria-label": field.name,
1234
228
  ...props,
1235
- children: options.map((option) => /* @__PURE__ */ jsx(
229
+ children: options.map((option) => /* @__PURE__ */ jsxRuntimeExports.jsx(
1236
230
  FormControlLabel,
1237
231
  {
1238
232
  value: option.value,
1239
- control: /* @__PURE__ */ jsx(Radio, {}),
233
+ control: /* @__PURE__ */ jsxRuntimeExports.jsx(Radio, {}),
1240
234
  label: option.label
1241
235
  },
1242
236
  option.value
1243
237
  ))
1244
238
  }
1245
239
  ),
1246
- isTouched && hasError && /* @__PURE__ */ jsx(FormHelperText, { error: hasError, children: helperText })
240
+ isTouched && hasError && /* @__PURE__ */ jsxRuntimeExports.jsx(FormHelperText, { error: hasError, children: helperText })
1247
241
  ] });
1248
242
  };
1249
243
  const FormSlider = ({ label, ...props }) => {
1250
244
  const field = useFieldContext();
1251
245
  const { isTouched, hasError, helperText } = getFieldStatus(field);
1252
- return /* @__PURE__ */ jsxs(FormControl, { component: "fieldset", children: [
1253
- label && /* @__PURE__ */ jsx(FormLabel, { children: label }),
1254
- /* @__PURE__ */ jsx(
246
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs(FormControl, { component: "fieldset", children: [
247
+ label && /* @__PURE__ */ jsxRuntimeExports.jsx(FormLabel, { children: label }),
248
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
1255
249
  Slider,
1256
250
  {
1257
251
  name: field.name,
@@ -1262,7 +256,7 @@ const FormSlider = ({ label, ...props }) => {
1262
256
  ...props
1263
257
  }
1264
258
  ),
1265
- isTouched && hasError && /* @__PURE__ */ jsx(FormHelperText, { error: hasError, children: helperText })
259
+ isTouched && hasError && /* @__PURE__ */ jsxRuntimeExports.jsx(FormHelperText, { error: hasError, children: helperText })
1266
260
  ] });
1267
261
  };
1268
262
  const FormSubmitButton = (props) => {
@@ -1272,7 +266,7 @@ const FormSubmitButton = (props) => {
1272
266
  event.stopPropagation();
1273
267
  form.handleSubmit();
1274
268
  };
1275
- return /* @__PURE__ */ jsx(form.Subscribe, { selector: (state) => [state.canSubmit, state.isSubmitting], children: ([canSubmit, isSubmitting]) => /* @__PURE__ */ jsx(
269
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(form.Subscribe, { selector: (state) => [state.canSubmit, state.isSubmitting], children: ([canSubmit, isSubmitting]) => /* @__PURE__ */ jsxRuntimeExports.jsx(
1276
270
  Button,
1277
271
  {
1278
272
  loading: isSubmitting,
@@ -1287,11 +281,11 @@ const FormSubmitButton = (props) => {
1287
281
  const FormSwitch = (props) => {
1288
282
  const field = useFieldContext();
1289
283
  const { isTouched, hasError, helperText } = getFieldStatus(field);
1290
- return /* @__PURE__ */ jsxs(FormControl, { component: "fieldset", children: [
1291
- /* @__PURE__ */ jsx(
284
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs(FormControl, { component: "fieldset", children: [
285
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
1292
286
  FormControlLabel,
1293
287
  {
1294
- control: /* @__PURE__ */ jsx(
288
+ control: /* @__PURE__ */ jsxRuntimeExports.jsx(
1295
289
  Switch,
1296
290
  {
1297
291
  name: field.name,
@@ -1305,13 +299,13 @@ const FormSwitch = (props) => {
1305
299
  label: props.label ?? ""
1306
300
  }
1307
301
  ),
1308
- isTouched && hasError && /* @__PURE__ */ jsx(FormHelperText, { error: hasError, children: helperText })
302
+ isTouched && hasError && /* @__PURE__ */ jsxRuntimeExports.jsx(FormHelperText, { error: hasError, children: helperText })
1309
303
  ] });
1310
304
  };
1311
305
  const FormTextField = (props) => {
1312
306
  const field = useFieldContext();
1313
307
  const { isTouched, hasError, helperText } = getFieldStatus(field);
1314
- return /* @__PURE__ */ jsx(
308
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(
1315
309
  TextField,
1316
310
  {
1317
311
  name: field.name,
@@ -1352,6 +346,7 @@ export {
1352
346
  u as useDialogs,
1353
347
  useFieldContext,
1354
348
  useFormContext,
349
+ useInView,
1355
350
  useLayoutForm,
1356
351
  withLayoutForm
1357
352
  };