@steroidsjs/core 2.2.0 → 2.2.4
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/hoc/file.d.ts +4 -0
- package/hooks/useFile.js +2 -2
- package/package.json +1 -1
- 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
package/hoc/file.d.ts
CHANGED
package/hooks/useFile.js
CHANGED
|
@@ -39,7 +39,7 @@ function generateBackendUrl(props) {
|
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
41
|
function useFile(props) {
|
|
42
|
-
var uploader = useInitial_1["default"](function () { return new fileup_core_1["default"](__assign(__assign({ dropArea: {}, backendUrl: generateBackendUrl(props) }, props.uploader), { form: __assign(__assign({}, (props.uploader && props.uploader.form)), { multiple: props.multiple }) })); });
|
|
42
|
+
var uploader = useInitial_1["default"](function () { return new fileup_core_1["default"](__assign(__assign({ dropArea: {}, backendUrl: generateBackendUrl(props), uploaderConfig: __assign({}, props.uploaderConfig) }, props.uploader), { form: __assign(__assign({}, (props.uploader && props.uploader.form)), { multiple: props.multiple }) })); });
|
|
43
43
|
/**
|
|
44
44
|
* Force component update when file status or progress changes
|
|
45
45
|
* @private
|
|
@@ -156,7 +156,7 @@ function useFile(props) {
|
|
|
156
156
|
var prevInputValue = react_use_1.usePrevious(props.input.value);
|
|
157
157
|
//todo refactoring
|
|
158
158
|
react_1.useEffect(function () {
|
|
159
|
-
if (!isEqual_1["default"](prevInputValue !== props.input.value)) {
|
|
159
|
+
if (prevInputValue && !isEqual_1["default"](prevInputValue !== props.input.value)) {
|
|
160
160
|
var toRemove_1 = difference_1["default"]([].concat(props.input.value || []), [].concat(prevInputValue || []));
|
|
161
161
|
if (toRemove_1.length > 0) {
|
|
162
162
|
uploader.queue.remove(uploader.queue.getFiles().filter(function (file) { return (toRemove_1.indexOf(get_1["default"](file.getResultHttpMessage(), 'id')) !== -1); }));
|
package/package.json
CHANGED
|
@@ -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
|
};
|