@steroidsjs/core 2.2.0 → 2.2.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steroidsjs/core",
3
- "version": "2.2.0",
3
+ "version": "2.2.1",
4
4
  "description": "",
5
5
  "author": "Vladimir Kozhin <hello@kozhindev.com>",
6
6
  "repository": {
@@ -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
- ], props.displayFormat) || ''; }, [props.displayFormat, props.input.value, props.valueFormat]);
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, props.useUTC);
43
+ var parsedValue = calendar_1.convertDate(value, props.displayFormat, props.valueFormat, true);
44
44
  var newValue = parsedValue || !value ? parsedValue || null : false;
45
- if (newValue !== false && newValue !== props.input.value) {
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.useUTC, props.valueFormat]);
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 (e) {
60
- e.preventDefault();
61
- //setIsOpened(false);
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.displayFormat, props.valueFormat], dateValueFormat); }, [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); }, [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');
@@ -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
- momentDate = moment_1["default"](date, validFormat);
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.utc(true).local();
40
+ momentDate = momentDate.local();
35
41
  }
36
42
  return toFormat ? momentDate.format(toFormat) : momentDate.toDate();
37
43
  };