persian-number-input 4.0.7 → 4.0.9
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/LICENSE +21 -0
- package/README.md +389 -389
- package/dist/components/PersianNumberInput.d.ts +4 -12
- package/dist/components/PersianNumberInput.d.ts.map +1 -1
- package/dist/components/PersianNumberInput.js +9 -26
- package/dist/components/PersianNumberInput.js.map +1 -1
- package/dist/hooks/usePersianNumberInput.d.ts +9 -8
- package/dist/hooks/usePersianNumberInput.d.ts.map +1 -1
- package/dist/hooks/usePersianNumberInput.js +71 -93
- package/dist/hooks/usePersianNumberInput.js.map +1 -1
- package/dist/utils/digitUtils.d.ts +6 -32
- package/dist/utils/digitUtils.d.ts.map +1 -1
- package/dist/utils/digitUtils.js +65 -162
- package/dist/utils/digitUtils.js.map +1 -1
- package/dist/utils/transformNumber.d.ts +2 -11
- package/dist/utils/transformNumber.d.ts.map +1 -1
- package/dist/utils/transformNumber.js +16 -81
- package/dist/utils/transformNumber.js.map +1 -1
- package/package.json +48 -52
|
@@ -1,20 +1,12 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
import type { TransformNumberOptions } from
|
|
3
|
-
interface PersianNumberInputProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>,
|
|
4
|
-
Omit<TransformNumberOptions, 'maxDecimals'> {
|
|
5
|
-
/** مقدار اولیه */
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { TransformNumberOptions } from "../utils/transformNumber";
|
|
3
|
+
interface PersianNumberInputProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, "onChange" | "value" | "min" | "max">, Omit<TransformNumberOptions, "maxDecimals"> {
|
|
6
4
|
initialValue?: number | string;
|
|
7
|
-
/** تابعی که با تغییر مقدار خام (انگلیسی و بدون فرمت) فراخوانی میشود */
|
|
8
5
|
onValueChange?: (value: string | undefined) => void;
|
|
9
|
-
/** حداقل مقدار مجاز (اعشار پشتیبانی میشود) */
|
|
10
6
|
min?: number;
|
|
11
|
-
/** حداکثر مقدار مجاز (اعشار پشتیبانی میشود) */
|
|
12
7
|
max?: number;
|
|
13
|
-
/** حداکثر تعداد ارقام اعشار مجاز (undefined یعنی نامحدود) */
|
|
14
8
|
maxDecimals?: number;
|
|
15
|
-
/** کاراکتری که کاربر برای وارد کردن اعشار استفاده میکند (پیشفرض '.') */
|
|
16
|
-
inputDecimalSeparator?: string;
|
|
17
9
|
}
|
|
18
|
-
declare const PersianNumberInput: React.
|
|
10
|
+
declare const PersianNumberInput: React.ForwardRefExoticComponent<PersianNumberInputProps & React.RefAttributes<HTMLInputElement>>;
|
|
19
11
|
export default PersianNumberInput;
|
|
20
12
|
//# sourceMappingURL=PersianNumberInput.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PersianNumberInput.d.ts","sourceRoot":"","sources":["../../src/components/PersianNumberInput.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PersianNumberInput.d.ts","sourceRoot":"","sources":["../../src/components/PersianNumberInput.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA0C,MAAM,OAAO,CAAC;AAE/D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAEvE,UAAU,uBACR,SAAQ,IAAI,CACR,KAAK,CAAC,mBAAmB,CAAC,gBAAgB,CAAC,EAC3C,UAAU,GAAG,OAAO,GAAG,KAAK,GAAG,KAAK,CACrC,EACD,IAAI,CAAC,sBAAsB,EAAE,aAAa,CAAC;IAC7C,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/B,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,KAAK,IAAI,CAAC;IACpD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,QAAA,MAAM,kBAAkB,kGA6CtB,CAAC;AAIH,eAAe,kBAAkB,CAAC"}
|
|
@@ -12,27 +12,11 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
14
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
15
|
+
const react_1 = require("react");
|
|
15
16
|
const usePersianNumberInput_1 = require("../hooks/usePersianNumberInput");
|
|
16
|
-
const PersianNumberInput = (
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
initialValue, separatorCount, separatorChar, locale, showZero, onValueChange, min, max, maxDecimals, inputDecimalSeparator } = _a, // پراپ جدید
|
|
20
|
-
// بقیه پراپ ها (مثل className, style, placeholder, id, disabled و ...) به input اصلی منتقل می شوند
|
|
21
|
-
restInputProps = __rest(_a, ["initialValue", "separatorCount", "separatorChar", "locale", "showZero", "onValueChange", "min", "max", "maxDecimals", "inputDecimalSeparator"]);
|
|
22
|
-
// اعتبارسنجی پراپها (اختیاری ولی خوب)
|
|
23
|
-
if (maxDecimals !== undefined && maxDecimals < 0) {
|
|
24
|
-
console.warn('maxDecimals باید غیرمنفی باشد');
|
|
25
|
-
maxDecimals = 0;
|
|
26
|
-
}
|
|
27
|
-
if (min !== undefined && max !== undefined && min > max) {
|
|
28
|
-
console.warn('min نباید بزرگتر از max باشد');
|
|
29
|
-
// شاید بهتر باشد یکی را نادیده گرفت یا خطا داد؟ فعلا فقط هشدار.
|
|
30
|
-
}
|
|
31
|
-
const { value: formattedValue, // مقدار فرمت شده برای نمایش
|
|
32
|
-
onChange, // تابع onChange برای input
|
|
33
|
-
// setValue, // اگر نیاز به تنظیم مقدار از بیرون دارید
|
|
34
|
-
// rawValue, // مقدار خام انگلیسی بدون فرمت (اگر لازم دارید)
|
|
35
|
-
} = (0, usePersianNumberInput_1.usePersianNumberInput)({
|
|
17
|
+
const PersianNumberInput = (0, react_1.forwardRef)((props, ref) => {
|
|
18
|
+
const { initialValue, separatorCount, separatorChar, locale, showZero, onValueChange, min, max, maxDecimals, onBlur: propsOnBlur } = props, rest = __rest(props, ["initialValue", "separatorCount", "separatorChar", "locale", "showZero", "onValueChange", "min", "max", "maxDecimals", "onBlur"]);
|
|
19
|
+
const { value, onChange, onBlur, inputRef } = (0, usePersianNumberInput_1.usePersianNumberInput)({
|
|
36
20
|
initialValue,
|
|
37
21
|
separatorCount,
|
|
38
22
|
separatorChar,
|
|
@@ -42,12 +26,11 @@ const PersianNumberInput = (_a) => {
|
|
|
42
26
|
min,
|
|
43
27
|
max,
|
|
44
28
|
maxDecimals,
|
|
45
|
-
|
|
29
|
+
onBlur: propsOnBlur,
|
|
46
30
|
});
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
};
|
|
31
|
+
(0, react_1.useImperativeHandle)(ref, () => inputRef.current);
|
|
32
|
+
return ((0, jsx_runtime_1.jsx)("input", Object.assign({}, rest, { ref: inputRef, type: "text", inputMode: "decimal", dir: "ltr", value: value, onChange: onChange, onBlur: onBlur })));
|
|
33
|
+
});
|
|
34
|
+
PersianNumberInput.displayName = "PersianNumberInput";
|
|
52
35
|
exports.default = PersianNumberInput;
|
|
53
36
|
//# sourceMappingURL=PersianNumberInput.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PersianNumberInput.js","sourceRoot":"","sources":["../../src/components/PersianNumberInput.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"PersianNumberInput.js","sourceRoot":"","sources":["../../src/components/PersianNumberInput.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,iCAA+D;AAC/D,0EAAuE;AAgBvE,MAAM,kBAAkB,GAAG,IAAA,kBAAU,EAGnC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;IACf,MAAM,EACJ,YAAY,EACZ,cAAc,EACd,aAAa,EACb,MAAM,EACN,QAAQ,EACR,aAAa,EACb,GAAG,EACH,GAAG,EACH,WAAW,EACX,MAAM,EAAE,WAAW,KAEjB,KAAK,EADJ,IAAI,UACL,KAAK,EAZH,iIAYL,CAAQ,CAAC;IAEV,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAA,6CAAqB,EAAC;QAClE,YAAY;QACZ,cAAc;QACd,aAAa;QACb,MAAM;QACN,QAAQ;QACR,aAAa;QACb,GAAG;QACH,GAAG;QACH,WAAW;QACX,MAAM,EAAE,WAAW;KACpB,CAAC,CAAC;IAEH,IAAA,2BAAmB,EAAC,GAAG,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,OAAQ,CAAC,CAAC;IAElD,OAAO,CACL,kDACM,IAAI,IACR,GAAG,EAAE,QAAQ,EACb,IAAI,EAAC,MAAM,EACX,SAAS,EAAC,SAAS,EACnB,GAAG,EAAC,KAAK,EACT,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,IACd,CACH,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,kBAAkB,CAAC,WAAW,GAAG,oBAAoB,CAAC;AAEtD,kBAAe,kBAAkB,CAAC"}
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
import { TransformNumberOptions } from
|
|
3
|
-
interface UsePersianNumberInputProps extends Omit<TransformNumberOptions,
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { TransformNumberOptions } from "../utils/transformNumber";
|
|
3
|
+
interface UsePersianNumberInputProps extends Omit<TransformNumberOptions, "maxDecimals"> {
|
|
4
4
|
initialValue?: number | string;
|
|
5
5
|
onValueChange?: (value: string | undefined) => void;
|
|
6
6
|
min?: number;
|
|
7
7
|
max?: number;
|
|
8
8
|
maxDecimals?: number;
|
|
9
|
-
|
|
9
|
+
onBlur?: React.FocusEventHandler<HTMLInputElement>;
|
|
10
10
|
}
|
|
11
|
-
|
|
11
|
+
export declare const usePersianNumberInput: (props?: UsePersianNumberInputProps) => {
|
|
12
12
|
value: string;
|
|
13
13
|
onChange: (event: React.ChangeEvent<HTMLInputElement>) => void;
|
|
14
|
-
|
|
14
|
+
onBlur: (event: React.FocusEvent<HTMLInputElement>) => void;
|
|
15
15
|
rawValue: string | undefined;
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
inputRef: React.RefObject<HTMLInputElement | null>;
|
|
17
|
+
setRawValue: (nextRaw: string) => void;
|
|
18
|
+
};
|
|
18
19
|
export {};
|
|
19
20
|
//# sourceMappingURL=usePersianNumberInput.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePersianNumberInput.d.ts","sourceRoot":"","sources":["../../src/hooks/usePersianNumberInput.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"usePersianNumberInput.d.ts","sourceRoot":"","sources":["../../src/hooks/usePersianNumberInput.ts"],"names":[],"mappings":"AAAA,OAAO,KAAyD,MAAM,OAAO,CAAC;AAE9E,OAAO,EAEL,sBAAsB,EACvB,MAAM,0BAA0B,CAAC;AAGlC,UAAU,0BACR,SAAQ,IAAI,CAAC,sBAAsB,EAAE,aAAa,CAAC;IACnD,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/B,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,KAAK,IAAI,CAAC;IACpD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,KAAK,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,CAAC;CACpD;AAED,eAAO,MAAM,qBAAqB,GAChC,QAAO,0BAA+B;;sBAoDb,KAAK,CAAC,WAAW,CAAC,gBAAgB,CAAC;oBA0BlD,KAAK,CAAC,UAAU,CAAC,gBAAgB,CAAC;;;2BA9ChC,MAAM;CAmFnB,CAAC"}
|
|
@@ -4,112 +4,90 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.usePersianNumberInput = void 0;
|
|
7
|
-
// hooks/usePersianNumberInput.ts
|
|
8
7
|
const react_1 = require("react");
|
|
9
8
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
10
9
|
const transformNumber_1 = require("../utils/transformNumber");
|
|
11
10
|
const digitUtils_1 = require("../utils/digitUtils");
|
|
12
|
-
const usePersianNumberInput = (
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (
|
|
19
|
-
|
|
20
|
-
// در انتها بررسی میشود
|
|
11
|
+
const usePersianNumberInput = (props = {}) => {
|
|
12
|
+
const { initialValue, separatorCount = 3, separatorChar = ",", locale = "fa", showZero = false, onValueChange, min, max, maxDecimals, onBlur: externalOnBlur, } = props;
|
|
13
|
+
const [rawValue, setRawValue] = (0, react_1.useState)(() => (0, digitUtils_1.sanitizeNumericInput)(initialValue, maxDecimals));
|
|
14
|
+
const inputRef = (0, react_1.useRef)(null);
|
|
15
|
+
const selectionRef = (0, react_1.useRef)(null);
|
|
16
|
+
(0, react_1.useLayoutEffect)(() => {
|
|
17
|
+
if (inputRef.current && selectionRef.current !== null) {
|
|
18
|
+
inputRef.current.setSelectionRange(selectionRef.current, selectionRef.current);
|
|
21
19
|
}
|
|
22
|
-
|
|
20
|
+
});
|
|
21
|
+
const updateValue = (0, react_1.useCallback)((nextRaw) => {
|
|
22
|
+
if (nextRaw !== "" &&
|
|
23
|
+
nextRaw !== "-" &&
|
|
24
|
+
nextRaw !== "." &&
|
|
25
|
+
nextRaw !== "-.") {
|
|
23
26
|
try {
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
console.warn(`Value ${sanitized} is less than min ${min}. Clamping to min.`);
|
|
28
|
-
// مقدار را به min محدود کن: min را به رشته تبدیل، sanitize و round کن
|
|
29
|
-
const minStr = (0, digitUtils_1.sanitizeNumericInput)(String(min), '.'); // min را با نقطه استاندارد sanitize کن
|
|
30
|
-
sanitized = (0, digitUtils_1.roundToDecimals)(minStr, maxDecimals);
|
|
31
|
-
}
|
|
32
|
-
else if (max !== undefined && numericValue.gt(max)) {
|
|
33
|
-
console.warn(`Value ${sanitized} exceeds max ${max}. Clamping to max.`);
|
|
34
|
-
// مقدار را به max محدود کن: max را به رشته تبدیل، sanitize و round کن
|
|
35
|
-
const maxStr = (0, digitUtils_1.sanitizeNumericInput)(String(max), '.'); // max را با نقطه استاندارد sanitize کن
|
|
36
|
-
sanitized = (0, digitUtils_1.roundToDecimals)(maxStr, maxDecimals);
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
// اگر در محدوده بود، فقط مقدار اصلی sanitize شده را گرد کن
|
|
40
|
-
sanitized = (0, digitUtils_1.roundToDecimals)(sanitized, maxDecimals);
|
|
41
|
-
}
|
|
27
|
+
const num = new decimal_js_1.default(nextRaw);
|
|
28
|
+
if (max !== undefined && num.gt(max))
|
|
29
|
+
return;
|
|
42
30
|
}
|
|
43
|
-
catch (
|
|
44
|
-
|
|
45
|
-
console.warn(`Error processing sanitized value: ${sanitized}`, error);
|
|
46
|
-
return undefined; // مقدار نامعتبر است
|
|
31
|
+
catch (_a) {
|
|
32
|
+
return;
|
|
47
33
|
}
|
|
48
34
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
35
|
+
setRawValue(nextRaw);
|
|
36
|
+
onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange(nextRaw);
|
|
37
|
+
}, [max, onValueChange]);
|
|
38
|
+
const onChange = (event) => {
|
|
39
|
+
const input = event.target;
|
|
40
|
+
const value = input.value;
|
|
41
|
+
const sanitized = (0, digitUtils_1.sanitizeNumericInput)(value, maxDecimals);
|
|
42
|
+
const prevFormatted = (0, transformNumber_1.transformNumber)(rawValue, {
|
|
43
|
+
separatorCount,
|
|
44
|
+
separatorChar,
|
|
45
|
+
locale,
|
|
46
|
+
showZero,
|
|
47
|
+
});
|
|
48
|
+
const nextFormatted = (0, transformNumber_1.transformNumber)(sanitized, {
|
|
49
|
+
separatorCount,
|
|
50
|
+
separatorChar,
|
|
51
|
+
locale,
|
|
52
|
+
showZero,
|
|
53
|
+
});
|
|
54
|
+
let cursor = input.selectionStart || 0;
|
|
55
|
+
const diff = nextFormatted.length - prevFormatted.length;
|
|
56
|
+
selectionRef.current = cursor + diff;
|
|
57
|
+
updateValue(sanitized);
|
|
58
|
+
};
|
|
59
|
+
const onBlur = (0, react_1.useCallback)((event) => {
|
|
60
|
+
if (rawValue &&
|
|
61
|
+
rawValue !== "-" &&
|
|
62
|
+
rawValue !== "." &&
|
|
63
|
+
rawValue !== "-.") {
|
|
60
64
|
try {
|
|
61
|
-
|
|
62
|
-
|
|
65
|
+
const num = new decimal_js_1.default(rawValue);
|
|
66
|
+
if (min !== undefined && num.lt(min)) {
|
|
67
|
+
const minStr = String(min);
|
|
68
|
+
setRawValue(minStr);
|
|
69
|
+
onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange(minStr);
|
|
63
70
|
}
|
|
64
71
|
}
|
|
65
|
-
catch (
|
|
66
|
-
}
|
|
67
|
-
// در نهایت، اگر رشته خالی شده، undefined برگردان
|
|
68
|
-
return sanitized === '' ? undefined : sanitized;
|
|
69
|
-
}, [inputDecimalSeparator, min, max, maxDecimals, showZero]);
|
|
70
|
-
const [rawValue, setRawValue] = (0, react_1.useState)(() => getSanitizedAndRoundedValue(initialValue));
|
|
71
|
-
(0, react_1.useEffect)(() => {
|
|
72
|
-
// فقط اگر initialValue واقعا تغییر کرده، rawValue را آپدیت کن
|
|
73
|
-
// این از بازنشانی ناخواسته جلوگیری میکند
|
|
74
|
-
const newSanitized = getSanitizedAndRoundedValue(initialValue);
|
|
75
|
-
// مقایسه دقیق لازم است
|
|
76
|
-
if (newSanitized !== rawValue) {
|
|
77
|
-
// setRawValue(newSanitized); // آیا این لازم است؟ شاید باعث رفتار ناخواسته شود
|
|
78
|
-
}
|
|
79
|
-
// TODO: بررسی دقیق رفتار useEffect با initialValue
|
|
80
|
-
}, [initialValue]); // getSanitizedAndRoundedValue را از وابستگی حذف کردیم تا از لوپ جلوگیری شود
|
|
81
|
-
const displayValue = (0, react_1.useMemo)(() => {
|
|
82
|
-
const options = { separatorCount, separatorChar, locale, showZero, maxDecimals };
|
|
83
|
-
// تابع transformNumber حالا باید بتواند rawValue های مختلف را به درستی نمایش دهد
|
|
84
|
-
return (0, transformNumber_1.transformNumber)(rawValue, options);
|
|
85
|
-
}, [rawValue, separatorCount, separatorChar, locale, showZero, maxDecimals]);
|
|
86
|
-
const handleChange = (0, react_1.useCallback)((event) => {
|
|
87
|
-
const inputValue = event.target.value;
|
|
88
|
-
const newRawValue = getSanitizedAndRoundedValue(inputValue);
|
|
89
|
-
// فقط اگر مقدار خام جدید با مقدار قبلی متفاوت است، آپدیت کن
|
|
90
|
-
if (newRawValue !== rawValue) {
|
|
91
|
-
setRawValue(newRawValue);
|
|
92
|
-
if (onValueChange) {
|
|
93
|
-
onValueChange(newRawValue);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
// نکته: اگر کاربر کاراکتری وارد کند که باعث clamp شدن شود (مثلا در max)،
|
|
97
|
-
// newRawValue ممکن است با rawValue قبلی *متفاوت* باشد (برابر با max)،
|
|
98
|
-
// ولی با چیزی که کاربر تایپ کرده متفاوت است. input باید آپدیت شود تا مقدار clamp شده را نشان دهد.
|
|
99
|
-
// منطق فعلی این کار را انجام میدهد.
|
|
100
|
-
}, [rawValue, getSanitizedAndRoundedValue, onValueChange] // getSanitizedAndRoundedValue اینجا لازم است
|
|
101
|
-
);
|
|
102
|
-
const handleSetValue = (0, react_1.useCallback)((newValue) => {
|
|
103
|
-
const newRawValue = getSanitizedAndRoundedValue(newValue);
|
|
104
|
-
if (newRawValue !== rawValue) {
|
|
105
|
-
setRawValue(newRawValue);
|
|
106
|
-
if (onValueChange) {
|
|
107
|
-
onValueChange(newRawValue);
|
|
108
|
-
}
|
|
72
|
+
catch (_a) { }
|
|
109
73
|
}
|
|
110
|
-
|
|
111
|
-
);
|
|
112
|
-
|
|
74
|
+
externalOnBlur === null || externalOnBlur === void 0 ? void 0 : externalOnBlur(event);
|
|
75
|
+
}, [rawValue, min, onValueChange, externalOnBlur]);
|
|
76
|
+
const displayValue = (0, transformNumber_1.transformNumber)(rawValue, {
|
|
77
|
+
separatorCount,
|
|
78
|
+
separatorChar,
|
|
79
|
+
locale,
|
|
80
|
+
showZero,
|
|
81
|
+
maxDecimals,
|
|
82
|
+
});
|
|
83
|
+
return {
|
|
84
|
+
value: displayValue,
|
|
85
|
+
onChange,
|
|
86
|
+
onBlur,
|
|
87
|
+
rawValue,
|
|
88
|
+
inputRef,
|
|
89
|
+
setRawValue: updateValue,
|
|
90
|
+
};
|
|
113
91
|
};
|
|
114
92
|
exports.usePersianNumberInput = usePersianNumberInput;
|
|
115
93
|
//# sourceMappingURL=usePersianNumberInput.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePersianNumberInput.js","sourceRoot":"","sources":["../../src/hooks/usePersianNumberInput.ts"],"names":[],"mappings":";;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"usePersianNumberInput.js","sourceRoot":"","sources":["../../src/hooks/usePersianNumberInput.ts"],"names":[],"mappings":";;;;;;AAAA,iCAA8E;AAC9E,4DAAiC;AACjC,8DAGkC;AAClC,oDAA2D;AAYpD,MAAM,qBAAqB,GAAG,CACnC,QAAoC,EAAE,EACtC,EAAE;IACF,MAAM,EACJ,YAAY,EACZ,cAAc,GAAG,CAAC,EAClB,aAAa,GAAG,GAAG,EACnB,MAAM,GAAG,IAAI,EACb,QAAQ,GAAG,KAAK,EAChB,aAAa,EACb,GAAG,EACH,GAAG,EACH,WAAW,EACX,MAAM,EAAE,cAAc,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AAQ,EAAE,GAAG,EAAE,aAAa,EAAE,cAAc,CAAC,CAC/C,CAAC;IAEF,MAAM,YAAY,GAAG,IAAA,iCAAe,EAAC,QAAQ,EAAE;QAC7C,cAAc;QACd,aAAa;QACb,MAAM;QACN,QAAQ;QACR,WAAW;KACZ,CAAC,CAAC;IAEH,OAAO;QACL,KAAK,EAAE,YAAY;QACnB,QAAQ;QACR,MAAM;QACN,QAAQ;QACR,QAAQ;QACR,WAAW,EAAE,WAAW;KACzB,CAAC;AACJ,CAAC,CAAC;AApHW,QAAA,qBAAqB,yBAoHhC"}
|
|
@@ -1,36 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export declare const digitsMap: {
|
|
5
|
-
[key: string]: ReadonlyArray<string>;
|
|
6
|
-
};
|
|
7
|
-
/**
|
|
8
|
-
* نقشه جداکننده اعشار برای زبانهای مختلف (برای نمایش خروجی).
|
|
9
|
-
*/
|
|
10
|
-
export declare const decimalSeparatorMap: {
|
|
11
|
-
[key: string]: string;
|
|
12
|
-
};
|
|
1
|
+
export declare const digitsMap: Record<string, string[]>;
|
|
2
|
+
export declare const decimalSeparatorMap: Record<string, string>;
|
|
3
|
+
export declare const toEnglishDigits: (str: string) => string;
|
|
13
4
|
export declare const convertToEnglishDigits: (str: string) => string;
|
|
14
|
-
export declare const toLocalizedDigits: (numStr: string, locale:
|
|
15
|
-
export declare const localizeDecimalSeparator: (numStr: string, locale:
|
|
5
|
+
export declare const toLocalizedDigits: (numStr: string, locale: string) => string;
|
|
6
|
+
export declare const localizeDecimalSeparator: (numStr: string, locale: string) => string;
|
|
16
7
|
export declare const groupDigits: (numStr: string, separatorCount: number, separatorChar?: string) => string;
|
|
17
|
-
|
|
18
|
-
* پاکسازی ورودی عددی.
|
|
19
|
-
* ارقام محلی و جداکننده اعشار محلی (٫) و جداکننده دلخواه ورودی را به انگلیسی تبدیل میکند.
|
|
20
|
-
* کاراکترهای غیرمجاز را حذف میکند.
|
|
21
|
-
* فقط یک نقطه اعشار و یک علامت منفی در ابتدا را مجاز میداند.
|
|
22
|
-
*
|
|
23
|
-
* @param value رشته ورودی
|
|
24
|
-
* @param inputDecimalSeparator کاراکتر جداکننده اعشار که کاربر در ورودی استفاده میکند (پیشفرض '.')
|
|
25
|
-
* @returns رشته پاکشده با ارقام انگلیسی و نقطه استاندارد (.). میتواند شامل '-' یا '.' یا '-.' باشد.
|
|
26
|
-
*/
|
|
27
|
-
export declare const sanitizeNumericInput: (value: string | number | null | undefined, inputDecimalSeparator?: string) => string;
|
|
28
|
-
/**
|
|
29
|
-
* گرد کردن یا محدود کردن تعداد ارقام اعشار یک رشته عددی (انگلیسی).
|
|
30
|
-
* مهم: این تابع نقطه انتهایی را حفظ میکند اگر ورودی با نقطه تمام شود و maxDecimals صفر نباشد.
|
|
31
|
-
* @param value رشته عددی با ارقام انگلیسی و نقطه استاندارد.
|
|
32
|
-
* @param maxDecimals حداکثر تعداد اعشار مجاز (undefined یعنی بدون محدودیت).
|
|
33
|
-
* @returns رشته گرد شده یا محدود شده.
|
|
34
|
-
*/
|
|
8
|
+
export declare const sanitizeNumericInput: (value: string | number | null | undefined, maxDecimals?: number) => string;
|
|
35
9
|
export declare const roundToDecimals: (value: string, maxDecimals?: number) => string;
|
|
36
10
|
//# sourceMappingURL=digitUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"digitUtils.d.ts","sourceRoot":"","sources":["../../src/utils/digitUtils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"digitUtils.d.ts","sourceRoot":"","sources":["../../src/utils/digitUtils.ts"],"names":[],"mappings":"AAyBA,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAG9C,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAGtD,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,KAAK,MAAM,KAAG,MAK7C,CAAC;AAEF,eAAO,MAAM,sBAAsB,QAPE,MAAM,KAAG,MAOO,CAAC;AAEtD,eAAO,MAAM,iBAAiB,GAAI,QAAQ,MAAM,EAAE,QAAQ,MAAM,KAAG,MAIlE,CAAC;AAEF,eAAO,MAAM,wBAAwB,GACnC,QAAQ,MAAM,EACd,QAAQ,MAAM,KACb,MAKF,CAAC;AAEF,eAAO,MAAM,WAAW,GACtB,QAAQ,MAAM,EACd,gBAAgB,MAAM,EACtB,sBAAmB,KAClB,MAIF,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAC/B,OAAO,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,EACzC,cAAc,MAAM,KACnB,MA+BF,CAAC;AAEF,eAAO,MAAM,eAAe,GAC1B,OAAO,MAAM,EACb,cAAc,MAAM,KACnB,MAIF,CAAC"}
|