@steroidsjs/core 3.1.6 → 3.1.8

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/en.json CHANGED
@@ -1063,7 +1063,7 @@
1063
1063
  "Название цвета для Badge": "Color name for Badge",
1064
1064
  "Название цвета для Button": "Color name for Button",
1065
1065
  "Название цвета для Text, Title": "Color name for Text, Title",
1066
- "Промежуточное состояние чекбокса — часть дочерних элементов выбрана": "",
1067
- "Выбранная страна по умолчанию": "",
1068
- "Список доступных масок для телефонных номеров разных стран.\nКаждая маска определяет формат отображения номера.": ""
1066
+ "Промежуточное состояние чекбокса — часть дочерних элементов выбрана": "Indeterminate checkbox state — some child items are selected",
1067
+ "Выбранная страна по умолчанию": "Country selected by default",
1068
+ "Список доступных масок для телефонных номеров разных стран.\nКаждая маска определяет формат отображения номера.": "List of available masks for phone numbers from different countries.\nEach mask defines the number display format."
1069
1069
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steroidsjs/core",
3
- "version": "3.1.6",
3
+ "version": "3.1.8",
4
4
  "description": "",
5
5
  "author": "Vladimir Kozhin <hello@kozhindev.com>",
6
6
  "repository": {
@@ -26,6 +26,7 @@ var fieldWrapper_1 = __importDefault(require("../Field/fieldWrapper"));
26
26
  var DEFAULT_STEP = 1;
27
27
  var DECIMAL_SEPARATOR = '.';
28
28
  var MINUS_SIGN = '-';
29
+ var NUMBER_PATTERN = /^-?(?:\d+(?:\.\d*)?|\.\d+)$/;
29
30
  var isNotEmptyValue = function (rawValue) { return !(0, isNil_1["default"])(rawValue) && rawValue !== ''; };
30
31
  function NumberField(props) {
31
32
  var _a;
@@ -60,14 +61,32 @@ function NumberField(props) {
60
61
  }
61
62
  }, [currentInputRef, maskedInputRef]);
62
63
  (0, react_2.useEffect)(function () {
64
+ var _a, _b;
63
65
  var input = currentInputRef.current;
64
66
  var currentValue = props.input.value;
65
67
  var hasValue = isNotEmptyValue(currentValue);
66
- var numberValue = Number(currentValue);
67
- var isValid = !props.required
68
- || (hasValue && numberValue >= props.min && numberValue <= props.max);
68
+ var stringValue = String(currentValue);
69
+ // Remove visual formatting before checking the numeric value.
70
+ var normalizedValue = props.thousandSeparator
71
+ ? stringValue.split(props.thousandSeparator).join('')
72
+ : stringValue;
73
+ var numberValue = Number(normalizedValue);
74
+ var decimalPart = (_a = normalizedValue.split(DECIMAL_SEPARATOR)[1]) !== null && _a !== void 0 ? _a : '';
75
+ var maxPrecision = (_b = props.decimal) !== null && _b !== void 0 ? _b : 0;
76
+ // By default only integers are valid; decimal defines the maximum precision.
77
+ var hasValidPrecision = maxPrecision > 0
78
+ ? decimalPart.length <= maxPrecision
79
+ : !normalizedValue.includes(DECIMAL_SEPARATOR);
80
+ // Required only controls empty values. Every filled field must pass all numeric checks.
81
+ var isValid = hasValue
82
+ ? NUMBER_PATTERN.test(normalizedValue)
83
+ && ((0, isNil_1["default"])(props.min) || numberValue >= props.min)
84
+ && ((0, isNil_1["default"])(props.max) || numberValue <= props.max)
85
+ && hasValidPrecision
86
+ && (props.isCanBeNegative || numberValue >= 0)
87
+ : !props.required;
69
88
  input.setCustomValidity(isValid ? '' : __('The number is not valid.'));
70
- }, [currentInputRef, props.required, props.min, props.max, props.input.value, props]);
89
+ }, [currentInputRef, props.required, props.min, props.max, props.decimal, props.isCanBeNegative, props.thousandSeparator, props.input.value]);
71
90
  var clampToMinMax = (0, react_2.useCallback)(function (rawValue) {
72
91
  var val = rawValue;
73
92
  if (val < props.min) {