@steroidsjs/core 2.1.1 → 2.2.3
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/components/LocaleComponent.js +0 -15
- package/package.json +3 -3
- package/ui/content/Calendar/Calendar.js +1 -1
- package/ui/form/DateField/useDateInputState.js +10 -9
- package/ui/form/DateField/useDateTime.js +2 -2
- package/ui/form/InputField/InputField.js +4 -1
- package/ui/form/NumberField/NumberField.js +4 -1
- package/utils/calendar.d.ts +1 -1
- package/utils/calendar.js +9 -3
|
@@ -28,21 +28,6 @@ var moment_1 = __importDefault(require("moment"));
|
|
|
28
28
|
var isObject_1 = __importDefault(require("lodash-es/isObject"));
|
|
29
29
|
require("moment/locale/it");
|
|
30
30
|
require("moment/locale/ru");
|
|
31
|
-
// Fix load locale data
|
|
32
|
-
if (process.env.IS_SSR) {
|
|
33
|
-
// @ts-ignore
|
|
34
|
-
global.IntlMessageFormat = intl_messageformat_1["default"];
|
|
35
|
-
require('intl-messageformat/dist/locale-data/ru');
|
|
36
|
-
// @ts-ignore
|
|
37
|
-
delete global.IntlMessageFormat;
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
// @ts-ignore
|
|
41
|
-
window.IntlMessageFormat = intl_messageformat_1["default"];
|
|
42
|
-
require('intl-messageformat/dist/locale-data/ru');
|
|
43
|
-
// @ts-ignore
|
|
44
|
-
delete window.IntlMessageFormat;
|
|
45
|
-
}
|
|
46
31
|
/**
|
|
47
32
|
* Locale Component
|
|
48
33
|
* Компонент для локализации приложения. Поддерживает конфигурацию языка и временной зоны
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@steroidsjs/core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "Vladimir Kozhin <hello@kozhindev.com>",
|
|
6
6
|
"repository": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"dot-prop-immutable": "^2.1.0",
|
|
30
30
|
"fileup-core": "^1.2.0",
|
|
31
31
|
"history": "^4.10.1",
|
|
32
|
-
"intl-messageformat": "^
|
|
32
|
+
"intl-messageformat": "^9.11.0",
|
|
33
33
|
"js-cookie": "^2.2.1",
|
|
34
34
|
"load-js": "^3.0.3",
|
|
35
35
|
"lodash": "^4.17.21",
|
|
@@ -82,6 +82,6 @@
|
|
|
82
82
|
"jest": "^26.6.3",
|
|
83
83
|
"jest-enzyme": "^7.1.2",
|
|
84
84
|
"ts-jest": "^26.5.1",
|
|
85
|
-
"typescript": "
|
|
85
|
+
"typescript": "4.2.2"
|
|
86
86
|
}
|
|
87
87
|
}
|
|
@@ -31,7 +31,7 @@ function Calendar(props) {
|
|
|
31
31
|
setMonth(selectedDates[0]);
|
|
32
32
|
}
|
|
33
33
|
}, [selectedDates]);
|
|
34
|
-
var onDaySelect = react_1.useCallback(function (date) { return props.onChange.call(null, calendar_1.convertDate(date, null, props.valueFormat)); }, [props.onChange, props.valueFormat]);
|
|
34
|
+
var onDaySelect = react_1.useCallback(function (date) { return props.onChange.call(null, calendar_1.convertDate(date, null, props.valueFormat, false, true)); }, [props.onChange, props.valueFormat]);
|
|
35
35
|
var toggleCaptionPanel = react_1.useCallback(function () {
|
|
36
36
|
setIsCaptionPanelVisible(!isCaptionPanelVisible);
|
|
37
37
|
}, [isCaptionPanelVisible]);
|
|
@@ -21,9 +21,9 @@ var calendar_1 = require("../../../utils/calendar");
|
|
|
21
21
|
function useDateInputState(props) {
|
|
22
22
|
// Get props value
|
|
23
23
|
var propsDisplayValue = react_1.useMemo(function () { return calendar_1.convertDate(props.input.value, [
|
|
24
|
-
props.displayFormat,
|
|
25
24
|
props.valueFormat,
|
|
26
|
-
|
|
25
|
+
props.displayFormat,
|
|
26
|
+
], props.displayFormat, false, true) || ''; }, [props.displayFormat, props.input.value, props.valueFormat]);
|
|
27
27
|
// Display value state
|
|
28
28
|
var _a = react_1.useState(propsDisplayValue), displayValue = _a[0], setDisplayValue = _a[1];
|
|
29
29
|
// Update display value on update props input value
|
|
@@ -40,15 +40,15 @@ function useDateInputState(props) {
|
|
|
40
40
|
// Display input change handler
|
|
41
41
|
var onDisplayValueChange = react_1.useCallback(function (value) {
|
|
42
42
|
setDisplayValue(value);
|
|
43
|
-
var parsedValue = calendar_1.convertDate(value, props.displayFormat, props.valueFormat,
|
|
43
|
+
var parsedValue = calendar_1.convertDate(value, props.displayFormat, props.valueFormat, true);
|
|
44
44
|
var newValue = parsedValue || !value ? parsedValue || null : false;
|
|
45
|
-
if (newValue
|
|
45
|
+
if (newValue && newValue !== props.input.value) {
|
|
46
46
|
props.input.onChange.call(null, newValue);
|
|
47
47
|
if (props.onChange) {
|
|
48
48
|
props.onChange.call(null, value);
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
-
}, [props.displayFormat, props.input.onChange, props.input.value, props.onChange, props.
|
|
51
|
+
}, [props.displayFormat, props.input.onChange, props.input.value, props.onChange, props.valueFormat]);
|
|
52
52
|
// Dropdown opened state
|
|
53
53
|
var _b = react_1.useState(false), isOpened = _b[0], setIsOpened = _b[1];
|
|
54
54
|
// Focus/blur handlers
|
|
@@ -56,10 +56,11 @@ function useDateInputState(props) {
|
|
|
56
56
|
e.preventDefault();
|
|
57
57
|
setIsOpened(true);
|
|
58
58
|
}, [setIsOpened]);
|
|
59
|
-
var onBlur = react_1.useCallback(function (
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
var onBlur = react_1.useCallback(function () {
|
|
60
|
+
if (propsDisplayValue !== displayValue) {
|
|
61
|
+
setDisplayValue(propsDisplayValue);
|
|
62
|
+
}
|
|
63
|
+
}, [displayValue, propsDisplayValue]);
|
|
63
64
|
var onClose = react_1.useCallback(function () {
|
|
64
65
|
setIsOpened(false);
|
|
65
66
|
if (propsDisplayValue !== displayValue) {
|
|
@@ -13,8 +13,8 @@ var calendar_1 = require("../../../utils/calendar");
|
|
|
13
13
|
*/
|
|
14
14
|
function useDateTime(props) {
|
|
15
15
|
var _a = props.valueFormat.split(props.dateTimeSeparator), dateValueFormat = _a[0], timeValueFormat = _a[1];
|
|
16
|
-
var dateValue = react_1.useMemo(function () { return calendar_1.convertDate(props.input.value, [props.
|
|
17
|
-
var timeValue = react_1.useMemo(function () { return calendar_1.convertDate(props.input.value, [props.displayFormat, props.valueFormat], timeValueFormat); }, [props.displayFormat, props.input.value, props.valueFormat, timeValueFormat]);
|
|
16
|
+
var dateValue = react_1.useMemo(function () { return calendar_1.convertDate(props.input.value, [props.valueFormat, props.displayFormat], dateValueFormat, false, true); }, [dateValueFormat, props.displayFormat, props.input.value, props.valueFormat]);
|
|
17
|
+
var timeValue = react_1.useMemo(function () { return calendar_1.convertDate(props.input.value, [props.displayFormat, props.valueFormat], timeValueFormat, false, true); }, [props.displayFormat, props.input.value, props.valueFormat, timeValueFormat]);
|
|
18
18
|
// Handler for calendar and time picker changes
|
|
19
19
|
var onDateSelect = react_1.useCallback(function (date) {
|
|
20
20
|
var result = date + props.dateTimeSeparator + (timeValue || '00:00');
|
|
@@ -40,7 +40,10 @@ var fieldWrapper_1 = __importDefault(require("../Field/fieldWrapper"));
|
|
|
40
40
|
var hooks_1 = require("../../../hooks");
|
|
41
41
|
function InputField(props) {
|
|
42
42
|
var components = hooks_1.useComponents();
|
|
43
|
-
var inputProps = react_1.useMemo(function () {
|
|
43
|
+
var inputProps = react_1.useMemo(function () {
|
|
44
|
+
var _a;
|
|
45
|
+
return (__assign({ type: props.type, name: props.input.name, value: (_a = props.input.value) !== null && _a !== void 0 ? _a : '', onChange: function (value) { return props.input.onChange(value); }, placeholder: props.placeholder, disabled: props.disabled }, props.inputProps));
|
|
46
|
+
}, [props.disabled, props.input, props.inputProps, props.placeholder, props.type]);
|
|
44
47
|
// No render for hidden input
|
|
45
48
|
if (props.type === 'hidden') {
|
|
46
49
|
return null;
|
|
@@ -19,7 +19,10 @@ var hooks_1 = require("../../../hooks");
|
|
|
19
19
|
var fieldWrapper_1 = __importDefault(require("../Field/fieldWrapper"));
|
|
20
20
|
function NumberField(props) {
|
|
21
21
|
var components = hooks_1.useComponents();
|
|
22
|
-
props.inputProps = react_1.useMemo(function () {
|
|
22
|
+
props.inputProps = react_1.useMemo(function () {
|
|
23
|
+
var _a;
|
|
24
|
+
return (__assign({ name: props.input.name, value: (_a = props.input.value) !== null && _a !== void 0 ? _a : undefined, onChange: function (e) { return props.input.onChange(e.target ? e.target.value : e.nativeEvent.text); }, type: 'number', min: props.min, max: props.max, step: props.step, placeholder: props.placeholder, disabled: props.disabled }, props.inputProps));
|
|
25
|
+
}, [props.disabled, props.input, props.inputProps, props.placeholder, props.min, props.max, props.step]);
|
|
23
26
|
return components.ui.renderView(props.view || 'form.NumberFieldView' || 'form.InputFieldView', props);
|
|
24
27
|
}
|
|
25
28
|
NumberField.defaultProps = {
|
package/utils/calendar.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const convertDate: (date: string | Date, fromFormats: string | string[], toFormat?: string, utc?: boolean) => any;
|
|
1
|
+
export declare const convertDate: (date: string | Date, fromFormats: string | string[], toFormat?: string, utc?: boolean, dateInUtc?: boolean) => any;
|
|
2
2
|
/**
|
|
3
3
|
* Регулярка проверяет соответствие введенной строки формату 'hh:mm'
|
|
4
4
|
* Максимальная величина - 23:59
|
package/utils/calendar.js
CHANGED
|
@@ -5,9 +5,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
exports.__esModule = true;
|
|
6
6
|
exports.convertDate = void 0;
|
|
7
7
|
var moment_1 = __importDefault(require("moment"));
|
|
8
|
-
var convertDate = function (date, fromFormats, toFormat, utc) {
|
|
8
|
+
var convertDate = function (date, fromFormats, toFormat, utc, dateInUtc) {
|
|
9
9
|
if (toFormat === void 0) { toFormat = null; }
|
|
10
10
|
if (utc === void 0) { utc = false; }
|
|
11
|
+
if (dateInUtc === void 0) { dateInUtc = false; }
|
|
11
12
|
if (!date) {
|
|
12
13
|
return null;
|
|
13
14
|
}
|
|
@@ -19,7 +20,12 @@ var convertDate = function (date, fromFormats, toFormat, utc) {
|
|
|
19
20
|
if (!validFormat) {
|
|
20
21
|
return null;
|
|
21
22
|
}
|
|
22
|
-
|
|
23
|
+
if (dateInUtc) {
|
|
24
|
+
momentDate = moment_1["default"].utc(date, validFormat);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
momentDate = moment_1["default"](date, validFormat);
|
|
28
|
+
}
|
|
23
29
|
}
|
|
24
30
|
else if (date instanceof Date) {
|
|
25
31
|
momentDate = moment_1["default"](date);
|
|
@@ -31,7 +37,7 @@ var convertDate = function (date, fromFormats, toFormat, utc) {
|
|
|
31
37
|
momentDate = momentDate.utc();
|
|
32
38
|
}
|
|
33
39
|
else {
|
|
34
|
-
momentDate = momentDate.
|
|
40
|
+
momentDate = momentDate.local();
|
|
35
41
|
}
|
|
36
42
|
return toFormat ? momentDate.format(toFormat) : momentDate.toDate();
|
|
37
43
|
};
|