@seafile/seafile-calendar 0.0.24-beta2 → 0.0.24-beta3

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.
Files changed (167) hide show
  1. package/assets/index.css +1177 -0
  2. package/dist/rc-calendar.css +1179 -0
  3. package/dist/rc-calendar.css.map +1 -0
  4. package/dist/rc-calendar.js +7064 -0
  5. package/dist/rc-calendar.js.map +1 -0
  6. package/dist/rc-calendar.min.css +1179 -0
  7. package/dist/rc-calendar.min.css.map +1 -0
  8. package/dist/rc-calendar.min.js +1 -0
  9. package/es/Calendar.js +440 -0
  10. package/es/FullCalendar.js +182 -0
  11. package/es/MonthCalendar.js +135 -0
  12. package/es/Picker.js +245 -0
  13. package/es/RangeCalendar.js +740 -661
  14. package/es/calendar/CalendarFooter.js +93 -0
  15. package/es/calendar/CalendarHeader.js +257 -0
  16. package/es/calendar/CalendarRightPanel.js +138 -0
  17. package/es/calendar/OkButton.js +22 -0
  18. package/es/calendar/TimePickerButton.js +28 -0
  19. package/es/calendar/TodayButton.js +28 -0
  20. package/es/date/DateConstants.js +4 -0
  21. package/es/date/DateInput.js +233 -0
  22. package/es/date/DateTBody.js +275 -0
  23. package/es/date/DateTHead.js +78 -0
  24. package/es/date/DateTable.js +32 -0
  25. package/es/decade/DecadePanel.js +181 -0
  26. package/es/full-calendar/CalendarHeader.js +180 -0
  27. package/es/index.js +3 -0
  28. package/es/locale/ar_EG.js +27 -0
  29. package/es/locale/bg_BG.js +27 -0
  30. package/es/locale/ca_ES.js +27 -0
  31. package/es/locale/cs_CZ.js +27 -0
  32. package/es/locale/da_DK.js +27 -0
  33. package/es/locale/de_DE.js +27 -0
  34. package/es/locale/el_GR.js +27 -0
  35. package/es/locale/en_GB.js +27 -0
  36. package/es/locale/en_US.js +28 -0
  37. package/es/locale/es_ES.js +27 -0
  38. package/es/locale/et_EE.js +27 -0
  39. package/es/locale/fa_IR.js +27 -0
  40. package/es/locale/fi_FI.js +27 -0
  41. package/es/locale/fr_BE.js +27 -0
  42. package/es/locale/fr_FR.js +27 -0
  43. package/es/locale/he_IL.js +28 -0
  44. package/es/locale/hi_IN.js +28 -0
  45. package/es/locale/hr_HR.js +28 -0
  46. package/es/locale/hu_HU.js +27 -0
  47. package/es/locale/id_ID.js +28 -0
  48. package/es/locale/is_IS.js +27 -0
  49. package/es/locale/it_IT.js +27 -0
  50. package/es/locale/ja_JP.js +26 -0
  51. package/es/locale/kn_IN.js +28 -0
  52. package/es/locale/ko_KR.js +27 -0
  53. package/es/locale/ku_IQ.js +27 -0
  54. package/es/locale/lv_LV.js +27 -0
  55. package/es/locale/mm_MM.js +28 -0
  56. package/es/locale/mn_MN.js +28 -0
  57. package/es/locale/ms_MY.js +27 -0
  58. package/es/locale/nb_NO.js +27 -0
  59. package/es/locale/nl_BE.js +27 -0
  60. package/es/locale/nl_NL.js +27 -0
  61. package/es/locale/pl_PL.js +27 -0
  62. package/es/locale/pt_BR.js +27 -0
  63. package/es/locale/pt_PT.js +27 -0
  64. package/es/locale/ro_RO.js +28 -0
  65. package/es/locale/ru_RU.js +27 -0
  66. package/es/locale/sk_SK.js +27 -0
  67. package/es/locale/sl_SI.js +27 -0
  68. package/es/locale/sr_RS.js +27 -0
  69. package/es/locale/sv_SE.js +27 -0
  70. package/es/locale/ta_IN.js +28 -0
  71. package/es/locale/th_TH.js +27 -0
  72. package/es/locale/tr_TR.js +27 -0
  73. package/es/locale/ug_CN.js +26 -0
  74. package/es/locale/uk_UA.js +27 -0
  75. package/es/locale/vi_VN.js +28 -0
  76. package/es/locale/zh_CN.js +27 -0
  77. package/es/locale/zh_TW.js +26 -0
  78. package/es/mixin/CalendarMixin.js +123 -0
  79. package/es/mixin/CommonMixin.js +85 -0
  80. package/es/month/MonthPanel.js +154 -0
  81. package/es/month/MonthTable.js +156 -0
  82. package/es/picker/placements.js +35 -0
  83. package/es/range-calendar/CalendarPart.js +151 -0
  84. package/es/util/dayjs.js +17 -0
  85. package/es/util/index.js +105 -0
  86. package/es/util/toTime.js +21 -0
  87. package/es/year/YearPanel.js +194 -0
  88. package/lib/Calendar.js +503 -0
  89. package/lib/FullCalendar.js +221 -0
  90. package/lib/MonthCalendar.js +172 -0
  91. package/lib/Picker.js +282 -0
  92. package/lib/RangeCalendar.js +831 -710
  93. package/lib/calendar/CalendarFooter.js +134 -0
  94. package/lib/calendar/CalendarHeader.js +290 -0
  95. package/lib/calendar/CalendarRightPanel.js +162 -0
  96. package/lib/calendar/OkButton.js +32 -0
  97. package/lib/calendar/TimePickerButton.js +41 -0
  98. package/lib/calendar/TodayButton.js +39 -0
  99. package/lib/date/DateConstants.js +8 -0
  100. package/lib/date/DateInput.js +265 -0
  101. package/lib/date/DateTBody.js +302 -0
  102. package/lib/date/DateTHead.js +95 -0
  103. package/lib/date/DateTable.js +54 -0
  104. package/lib/decade/DecadePanel.js +207 -0
  105. package/lib/full-calendar/CalendarHeader.js +201 -0
  106. package/lib/index.js +12 -0
  107. package/lib/locale/ar_EG.js +31 -0
  108. package/lib/locale/bg_BG.js +31 -0
  109. package/lib/locale/ca_ES.js +31 -0
  110. package/lib/locale/cs_CZ.js +31 -0
  111. package/lib/locale/da_DK.js +31 -0
  112. package/lib/locale/de_DE.js +31 -0
  113. package/lib/locale/el_GR.js +31 -0
  114. package/lib/locale/en_GB.js +31 -0
  115. package/lib/locale/en_US.js +32 -0
  116. package/lib/locale/es_ES.js +31 -0
  117. package/lib/locale/et_EE.js +31 -0
  118. package/lib/locale/fa_IR.js +31 -0
  119. package/lib/locale/fi_FI.js +31 -0
  120. package/lib/locale/fr_BE.js +31 -0
  121. package/lib/locale/fr_FR.js +31 -0
  122. package/lib/locale/he_IL.js +32 -0
  123. package/lib/locale/hi_IN.js +32 -0
  124. package/lib/locale/hr_HR.js +32 -0
  125. package/lib/locale/hu_HU.js +31 -0
  126. package/lib/locale/id_ID.js +32 -0
  127. package/lib/locale/is_IS.js +31 -0
  128. package/lib/locale/it_IT.js +31 -0
  129. package/lib/locale/ja_JP.js +30 -0
  130. package/lib/locale/kn_IN.js +32 -0
  131. package/lib/locale/ko_KR.js +31 -0
  132. package/lib/locale/ku_IQ.js +31 -0
  133. package/lib/locale/lv_LV.js +31 -0
  134. package/lib/locale/mm_MM.js +32 -0
  135. package/lib/locale/mn_MN.js +32 -0
  136. package/lib/locale/ms_MY.js +31 -0
  137. package/lib/locale/nb_NO.js +31 -0
  138. package/lib/locale/nl_BE.js +31 -0
  139. package/lib/locale/nl_NL.js +31 -0
  140. package/lib/locale/pl_PL.js +31 -0
  141. package/lib/locale/pt_BR.js +31 -0
  142. package/lib/locale/pt_PT.js +31 -0
  143. package/lib/locale/ro_RO.js +32 -0
  144. package/lib/locale/ru_RU.js +31 -0
  145. package/lib/locale/sk_SK.js +31 -0
  146. package/lib/locale/sl_SI.js +31 -0
  147. package/lib/locale/sr_RS.js +31 -0
  148. package/lib/locale/sv_SE.js +31 -0
  149. package/lib/locale/ta_IN.js +32 -0
  150. package/lib/locale/th_TH.js +31 -0
  151. package/lib/locale/tr_TR.js +31 -0
  152. package/lib/locale/ug_CN.js +30 -0
  153. package/lib/locale/uk_UA.js +31 -0
  154. package/lib/locale/vi_VN.js +32 -0
  155. package/lib/locale/zh_CN.js +31 -0
  156. package/lib/locale/zh_TW.js +30 -0
  157. package/lib/mixin/CalendarMixin.js +153 -0
  158. package/lib/mixin/CommonMixin.js +106 -0
  159. package/lib/month/MonthPanel.js +179 -0
  160. package/lib/month/MonthTable.js +181 -0
  161. package/lib/picker/placements.js +39 -0
  162. package/lib/range-calendar/CalendarPart.js +184 -0
  163. package/lib/util/dayjs.js +46 -0
  164. package/lib/util/index.js +130 -0
  165. package/lib/util/toTime.js +28 -0
  166. package/lib/year/YearPanel.js +219 -0
  167. package/package.json +7 -4
@@ -1,84 +1,111 @@
1
- "use strict";
1
+ 'use strict';
2
+
3
+ exports.__esModule = true;
4
+
5
+ var _extends2 = require('babel-runtime/helpers/extends');
6
+
7
+ var _extends3 = _interopRequireDefault(_extends2);
8
+
9
+ var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
10
+
11
+ var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
12
+
13
+ var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
14
+
15
+ var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
16
+
17
+ var _inherits2 = require('babel-runtime/helpers/inherits');
18
+
19
+ var _inherits3 = _interopRequireDefault(_inherits2);
20
+
21
+ var _react = require('react');
22
+
23
+ var _react2 = _interopRequireDefault(_react);
24
+
25
+ var _propTypes = require('prop-types');
26
+
27
+ var _propTypes2 = _interopRequireDefault(_propTypes);
28
+
29
+ var _classnames2 = require('classnames');
30
+
31
+ var _classnames3 = _interopRequireDefault(_classnames2);
32
+
33
+ var _reactLifecyclesCompat = require('react-lifecycles-compat');
34
+
35
+ var _KeyCode = require('rc-util/lib/KeyCode');
36
+
37
+ var _KeyCode2 = _interopRequireDefault(_KeyCode);
38
+
39
+ var _CalendarPart = require('./range-calendar/CalendarPart');
40
+
41
+ var _CalendarPart2 = _interopRequireDefault(_CalendarPart);
42
+
43
+ var _TodayButton = require('./calendar/TodayButton');
44
+
45
+ var _TodayButton2 = _interopRequireDefault(_TodayButton);
46
+
47
+ var _OkButton = require('./calendar/OkButton');
48
+
49
+ var _OkButton2 = _interopRequireDefault(_OkButton);
50
+
51
+ var _TimePickerButton = require('./calendar/TimePickerButton');
52
+
53
+ var _TimePickerButton2 = _interopRequireDefault(_TimePickerButton);
54
+
55
+ var _CommonMixin = require('./mixin/CommonMixin');
56
+
57
+ var _util = require('./util');
58
+
59
+ var _toTime = require('./util/toTime');
60
+
61
+ var _dayjs = require('./util/dayjs');
62
+
63
+ var _dayjs2 = _interopRequireDefault(_dayjs);
64
+
65
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
2
66
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
- var _react = _interopRequireDefault(require("react"));
8
- var _propTypes = _interopRequireDefault(require("prop-types"));
9
- var _classnames2 = _interopRequireDefault(require("classnames"));
10
- var _reactLifecyclesCompat = require("react-lifecycles-compat");
11
- var _KeyCode = _interopRequireDefault(require("rc-util/lib/KeyCode"));
12
- var _CalendarPart = _interopRequireDefault(require("./range-calendar/CalendarPart"));
13
- var _TodayButton = _interopRequireDefault(require("./calendar/TodayButton"));
14
- var _OkButton = _interopRequireDefault(require("./calendar/OkButton"));
15
- var _TimePickerButton = _interopRequireDefault(require("./calendar/TimePickerButton"));
16
- var _CommonMixin = require("./mixin/CommonMixin");
17
- var _util = require("./util");
18
- var _toTime = require("./util/toTime");
19
- var _dayjs = _interopRequireDefault(require("./util/dayjs"));
20
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
21
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
22
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
23
- function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
24
- function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
25
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
26
- function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
27
- function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
28
- function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
29
- function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
30
- function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
31
- function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
32
- function _possibleConstructorReturn(t, e) { if (e && ("object" == typeof e || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
33
- function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
34
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
35
- function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
36
- function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
37
- function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
38
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
39
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
40
- function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
41
- function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
42
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
43
- function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
44
- function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
45
- function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
46
- function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
47
67
  function noop() {}
68
+
48
69
  function isEmptyArray(arr) {
49
70
  return Array.isArray(arr) && (arr.length === 0 || arr.every(function (i) {
50
71
  return !i;
51
72
  }));
52
73
  }
74
+
53
75
  function isArraysEqual(a, b) {
54
76
  if (a === b) return true;
55
77
  if (a === null || typeof a === 'undefined' || b === null || typeof b === 'undefined') {
56
78
  return false;
57
79
  }
58
80
  if (a.length !== b.length) return false;
81
+
59
82
  for (var i = 0; i < a.length; ++i) {
60
83
  if (a[i] !== b[i]) return false;
61
84
  }
62
85
  return true;
63
86
  }
87
+
64
88
  function getValueFromSelectedValue(selectedValue) {
65
- var _selectedValue = _slicedToArray(selectedValue, 2),
66
- start = _selectedValue[0],
67
- end = _selectedValue[1];
89
+ var start = selectedValue[0],
90
+ end = selectedValue[1];
91
+
68
92
  if (end && (start === undefined || start === null)) {
69
93
  start = end.clone().subtract(1, 'month');
70
94
  }
95
+
71
96
  if (start && (end === undefined || end === null)) {
72
97
  end = start.clone().add(1, 'month');
73
98
  }
74
99
  return [start, end];
75
100
  }
101
+
76
102
  function normalizeAnchor(props, init) {
77
103
  var selectedValue = props.selectedValue || init && props.defaultSelectedValue;
78
104
  var value = props.value || init && props.defaultValue;
79
105
  var normalizedValue = value ? getValueFromSelectedValue(value) : getValueFromSelectedValue(selectedValue);
80
- return !isEmptyArray(normalizedValue) ? normalizedValue : init && [(0, _dayjs["default"])(), (0, _dayjs["default"])().add(1, 'months')];
106
+ return !isEmptyArray(normalizedValue) ? normalizedValue : init && [(0, _dayjs2['default'])(), (0, _dayjs2['default'])().add(1, 'months')];
81
107
  }
108
+
82
109
  function generateOptions(length, extraOptionGen) {
83
110
  var arr = extraOptionGen ? extraOptionGen().concat() : [];
84
111
  for (var value = 0; value < length; value++) {
@@ -88,6 +115,7 @@ function generateOptions(length, extraOptionGen) {
88
115
  }
89
116
  return arr;
90
117
  }
118
+
91
119
  function onInputSelect(direction, value, cause) {
92
120
  if (!value) {
93
121
  return;
@@ -100,523 +128,61 @@ function onInputSelect(direction, value, cause) {
100
128
  selectedValue[1 - index] = this.state.showTimePicker ? selectedValue[index] : undefined;
101
129
  }
102
130
  this.props.onInputSelect(selectedValue);
103
- this.fireSelectValueChange(selectedValue, null, cause || {
104
- source: 'dateInput'
105
- });
131
+ this.fireSelectValueChange(selectedValue, null, cause || { source: 'dateInput' });
106
132
  }
107
- var RangeCalendar = /*#__PURE__*/function (_React$Component) {
108
- function RangeCalendar(_props) {
109
- var _this;
110
- _classCallCheck(this, RangeCalendar);
111
- _this = _callSuper(this, RangeCalendar, [_props]);
112
- _defineProperty(_this, "onDatePanelEnter", function () {
113
- if (_this.hasSelectedValue()) {
114
- _this.fireHoverValueChange(_this.state.selectedValue.concat());
115
- }
116
- });
117
- _defineProperty(_this, "onDatePanelLeave", function () {
118
- if (_this.hasSelectedValue()) {
119
- _this.fireHoverValueChange([]);
120
- }
121
- });
122
- _defineProperty(_this, "onSelect", function (value) {
123
- var type = _this.props.type;
124
- var _this$state = _this.state,
125
- selectedValue = _this$state.selectedValue,
126
- prevSelectedValue = _this$state.prevSelectedValue,
127
- firstSelectedValue = _this$state.firstSelectedValue;
128
- var nextSelectedValue;
129
- if (type === 'both') {
130
- if (!firstSelectedValue) {
131
- (0, _util.syncTime)(prevSelectedValue[0], value);
132
- nextSelectedValue = [value];
133
- } else if (_this.compare(firstSelectedValue, value) < 0) {
134
- (0, _util.syncTime)(prevSelectedValue[1], value);
135
- nextSelectedValue = [firstSelectedValue, value];
136
- } else {
137
- (0, _util.syncTime)(prevSelectedValue[0], value);
138
- (0, _util.syncTime)(prevSelectedValue[1], firstSelectedValue);
139
- nextSelectedValue = [value, firstSelectedValue];
140
- }
141
- } else if (type === 'start') {
142
- (0, _util.syncTime)(prevSelectedValue[0], value);
143
- var endValue = selectedValue[1];
144
- nextSelectedValue = endValue && _this.compare(endValue, value) > 0 ? [value, endValue] : [value];
145
- } else {
146
- // type === 'end'
147
- var startValue = selectedValue[0];
148
- if (startValue && _this.compare(startValue, value) <= 0) {
149
- (0, _util.syncTime)(prevSelectedValue[1], value);
150
- nextSelectedValue = [startValue, value];
151
- } else {
152
- (0, _util.syncTime)(prevSelectedValue[0], value);
153
- nextSelectedValue = [value];
154
- }
155
- }
156
- _this.fireSelectValueChange(nextSelectedValue);
157
- });
158
- _defineProperty(_this, "onKeyDown", function (event) {
159
- if (event.target.nodeName.toLowerCase() === 'input') {
160
- return;
161
- }
162
- var keyCode = event.keyCode;
163
- var ctrlKey = event.ctrlKey || event.metaKey;
164
- var _this$state2 = _this.state,
165
- selectedValue = _this$state2.selectedValue,
166
- hoverValue = _this$state2.hoverValue,
167
- firstSelectedValue = _this$state2.firstSelectedValue,
168
- value = _this$state2.value;
169
- var _this$props = _this.props,
170
- onKeyDown = _this$props.onKeyDown,
171
- disabledDate = _this$props.disabledDate;
172
-
173
- // Update last time of the picker
174
- var updateHoverPoint = function updateHoverPoint(func) {
175
- // Change hover to make focus in UI
176
- var currentHoverTime;
177
- var nextHoverTime;
178
- var nextHoverValue;
179
- if (!firstSelectedValue) {
180
- currentHoverTime = hoverValue[0] || selectedValue[0] || value[0] || (0, _dayjs["default"])();
181
- nextHoverTime = func(currentHoverTime);
182
- nextHoverValue = [nextHoverTime];
183
- _this.fireHoverValueChange(nextHoverValue);
184
- } else {
185
- if (hoverValue.length === 1) {
186
- currentHoverTime = hoverValue[0].clone();
187
- nextHoverTime = func(currentHoverTime);
188
- nextHoverValue = _this.onDayHover(nextHoverTime);
189
- } else {
190
- currentHoverTime = hoverValue[0].isSame(firstSelectedValue, 'day') ? hoverValue[1] : hoverValue[0];
191
- nextHoverTime = func(currentHoverTime);
192
- nextHoverValue = _this.onDayHover(nextHoverTime);
193
- }
194
- }
195
133
 
196
- // Find origin hover time on value index
197
- if (nextHoverValue.length >= 2) {
198
- var miss = nextHoverValue.some(function (ht) {
199
- return !(0, _toTime.includesTime)(value, ht, 'month');
200
- });
201
- if (miss) {
202
- var newValue = nextHoverValue.slice().sort(function (t1, t2) {
203
- return t1.valueOf() - t2.valueOf();
204
- });
205
- if (newValue[0].isSame(newValue[1], 'month')) {
206
- newValue[1] = newValue[0].clone().add(1, 'month');
207
- }
208
- _this.fireValueChange(newValue);
209
- }
210
- } else if (nextHoverValue.length === 1) {
211
- // If only one value, let's keep the origin panel
212
- var oriValueIndex = value.findIndex(function (time) {
213
- return time.isSame(currentHoverTime, 'month');
214
- });
215
- if (oriValueIndex === -1) oriValueIndex = 0;
216
- if (value.every(function (time) {
217
- return !time.isSame(nextHoverTime, 'month');
218
- })) {
219
- var _newValue = value.slice();
220
- _newValue[oriValueIndex] = nextHoverTime.clone();
221
- _this.fireValueChange(_newValue);
222
- }
223
- }
224
- event.preventDefault();
225
- return nextHoverTime;
226
- };
227
- switch (keyCode) {
228
- case _KeyCode["default"].DOWN:
229
- updateHoverPoint(function (time) {
230
- return (0, _toTime.goTime)(time, 1, 'weeks');
231
- });
232
- return;
233
- case _KeyCode["default"].UP:
234
- updateHoverPoint(function (time) {
235
- return (0, _toTime.goTime)(time, -1, 'weeks');
236
- });
237
- return;
238
- case _KeyCode["default"].LEFT:
239
- if (ctrlKey) {
240
- updateHoverPoint(function (time) {
241
- return (0, _toTime.goTime)(time, -1, 'years');
242
- });
243
- } else {
244
- updateHoverPoint(function (time) {
245
- return (0, _toTime.goTime)(time, -1, 'days');
246
- });
247
- }
248
- return;
249
- case _KeyCode["default"].RIGHT:
250
- if (ctrlKey) {
251
- updateHoverPoint(function (time) {
252
- return (0, _toTime.goTime)(time, 1, 'years');
253
- });
254
- } else {
255
- updateHoverPoint(function (time) {
256
- return (0, _toTime.goTime)(time, 1, 'days');
257
- });
258
- }
259
- return;
260
- case _KeyCode["default"].HOME:
261
- updateHoverPoint(function (time) {
262
- return (0, _toTime.goStartMonth)(time);
263
- });
264
- return;
265
- case _KeyCode["default"].END:
266
- updateHoverPoint(function (time) {
267
- return (0, _toTime.goEndMonth)(time);
268
- });
269
- return;
270
- case _KeyCode["default"].PAGE_DOWN:
271
- updateHoverPoint(function (time) {
272
- return (0, _toTime.goTime)(time, 1, 'month');
273
- });
274
- return;
275
- case _KeyCode["default"].PAGE_UP:
276
- updateHoverPoint(function (time) {
277
- return (0, _toTime.goTime)(time, -1, 'month');
278
- });
279
- return;
280
- case _KeyCode["default"].ENTER:
281
- {
282
- var lastValue;
283
- if (hoverValue.length === 0) {
284
- lastValue = updateHoverPoint(function (time) {
285
- return time;
286
- });
287
- } else if (hoverValue.length === 1) {
288
- lastValue = hoverValue[0];
289
- } else {
290
- lastValue = hoverValue[0].isSame(firstSelectedValue, 'day') ? hoverValue[1] : hoverValue[0];
291
- }
292
- if (lastValue && (!disabledDate || !disabledDate(lastValue))) {
293
- _this.onSelect(lastValue);
294
- }
295
- event.preventDefault();
296
- return;
297
- }
298
- default:
299
- if (onKeyDown) {
300
- onKeyDown(event);
301
- }
302
- }
303
- });
304
- _defineProperty(_this, "onDayHover", function (value) {
305
- var hoverValue = [];
306
- var _this$state3 = _this.state,
307
- selectedValue = _this$state3.selectedValue,
308
- firstSelectedValue = _this$state3.firstSelectedValue;
309
- var type = _this.props.type;
310
- if (type === 'start' && selectedValue[1]) {
311
- hoverValue = _this.compare(value, selectedValue[1]) < 0 ? [value, selectedValue[1]] : [value];
312
- } else if (type === 'end' && selectedValue[0]) {
313
- hoverValue = _this.compare(value, selectedValue[0]) > 0 ? [selectedValue[0], value] : [];
314
- } else {
315
- if (!firstSelectedValue) {
316
- if (_this.state.hoverValue.length) {
317
- _this.setState({
318
- hoverValue: []
319
- });
320
- }
321
- return hoverValue;
322
- }
323
- hoverValue = _this.compare(value, firstSelectedValue) < 0 ? [value, firstSelectedValue] : [firstSelectedValue, value];
324
- }
325
- _this.fireHoverValueChange(hoverValue);
326
- return hoverValue;
327
- });
328
- _defineProperty(_this, "onToday", function () {
329
- var startValue = (0, _util.getTodayTime)(_this.state.value[0]);
330
- var endValue = startValue.clone().add(1, 'months');
331
- _this.setState({
332
- value: [startValue, endValue]
333
- });
334
- });
335
- _defineProperty(_this, "onOpenTimePicker", function () {
336
- _this.setState({
337
- showTimePicker: true
338
- });
339
- });
340
- _defineProperty(_this, "onCloseTimePicker", function () {
341
- _this.setState({
342
- showTimePicker: false
343
- });
344
- });
345
- _defineProperty(_this, "onOk", function () {
346
- var selectedValue = _this.state.selectedValue;
347
- if (_this.isAllowedDateAndTime(selectedValue)) {
348
- _this.props.onOk(_this.state.selectedValue);
349
- }
350
- });
351
- _defineProperty(_this, "onStartInputChange", function () {
352
- for (var _len = arguments.length, oargs = new Array(_len), _key = 0; _key < _len; _key++) {
353
- oargs[_key] = arguments[_key];
354
- }
355
- var args = ['left'].concat(oargs);
356
- return onInputSelect.apply(_this, args);
357
- });
358
- _defineProperty(_this, "onEndInputChange", function () {
359
- for (var _len2 = arguments.length, oargs = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
360
- oargs[_key2] = arguments[_key2];
361
- }
362
- var args = ['right'].concat(oargs);
363
- return onInputSelect.apply(_this, args);
364
- });
365
- _defineProperty(_this, "onStartInputSelect", function (value) {
366
- var args = ['left', value, {
367
- source: 'dateInputSelect'
368
- }];
369
- return onInputSelect.apply(_this, args);
370
- });
371
- _defineProperty(_this, "onEndInputSelect", function (value) {
372
- var args = ['right', value, {
373
- source: 'dateInputSelect'
374
- }];
375
- return onInputSelect.apply(_this, args);
376
- });
377
- _defineProperty(_this, "onStartValueChange", function (leftValue) {
378
- var value = _toConsumableArray(_this.state.value);
379
- value[0] = leftValue;
380
- return _this.fireValueChange(value);
381
- });
382
- _defineProperty(_this, "onEndValueChange", function (rightValue) {
383
- var value = _toConsumableArray(_this.state.value);
384
- value[1] = rightValue;
385
- return _this.fireValueChange(value);
386
- });
387
- _defineProperty(_this, "onStartPanelChange", function (value, mode) {
388
- var _this2 = _this,
389
- props = _this2.props,
390
- state = _this2.state;
391
- var newMode = [mode, state.mode[1]];
392
- var newState = {
393
- panelTriggerSource: 'start'
394
- };
395
- if (!('mode' in props)) {
396
- newState.mode = newMode;
397
- }
398
- _this.setState(newState);
399
- var newValue = [value || state.value[0], state.value[1]];
400
- props.onPanelChange(newValue, newMode);
401
- });
402
- _defineProperty(_this, "onEndPanelChange", function (value, mode) {
403
- var _this3 = _this,
404
- props = _this3.props,
405
- state = _this3.state;
406
- var newMode = [state.mode[0], mode];
407
- var newState = {
408
- panelTriggerSource: 'end'
409
- };
410
- if (!('mode' in props)) {
411
- newState.mode = newMode;
412
- }
413
- _this.setState(newState);
414
- var newValue = [state.value[0], value || state.value[1]];
415
- props.onPanelChange(newValue, newMode);
416
- });
417
- _defineProperty(_this, "getStartValue", function () {
418
- var _this$state4 = _this.state,
419
- selectedValue = _this$state4.selectedValue,
420
- showTimePicker = _this$state4.showTimePicker,
421
- value = _this$state4.value,
422
- mode = _this$state4.mode,
423
- panelTriggerSource = _this$state4.panelTriggerSource;
424
- var startValue = value[0];
425
- // keep selectedTime when select date
426
- if (selectedValue[0] && _this.props.timePicker) {
427
- startValue = startValue.clone();
428
- (0, _util.syncTime)(selectedValue[0], startValue);
429
- }
430
- if (showTimePicker && selectedValue[0]) {
431
- startValue = selectedValue[0];
432
- }
134
+ var RangeCalendar = function (_React$Component) {
135
+ (0, _inherits3['default'])(RangeCalendar, _React$Component);
433
136
 
434
- // Adjust month if date not align
435
- if (panelTriggerSource === 'end' && mode[0] === 'date' && mode[1] === 'date' && startValue.isSame(value[1], 'month')) {
436
- startValue = startValue.clone().subtract(1, 'month');
437
- }
438
- return startValue;
439
- });
440
- _defineProperty(_this, "getEndValue", function () {
441
- var _this$state5 = _this.state,
442
- value = _this$state5.value,
443
- selectedValue = _this$state5.selectedValue,
444
- showTimePicker = _this$state5.showTimePicker,
445
- mode = _this$state5.mode,
446
- panelTriggerSource = _this$state5.panelTriggerSource;
447
- var endValue = value[1] ? value[1].clone() : value[0].clone().add(1, 'month');
448
- // keep selectedTime when select date
449
- if (selectedValue[1] && _this.props.timePicker) {
450
- (0, _util.syncTime)(selectedValue[1], endValue);
451
- }
452
- if (showTimePicker) {
453
- endValue = selectedValue[1] ? selectedValue[1] : _this.getStartValue();
454
- }
137
+ function RangeCalendar(props) {
138
+ (0, _classCallCheck3['default'])(this, RangeCalendar);
455
139
 
456
- // Adjust month if date not align
457
- if (!showTimePicker && panelTriggerSource !== 'end' && mode[0] === 'date' && mode[1] === 'date' && endValue.isSame(value[0], 'month')) {
458
- endValue = endValue.clone().add(1, 'month');
459
- }
460
- return endValue;
461
- });
462
- // get disabled hours for second picker
463
- _defineProperty(_this, "getEndDisableTime", function () {
464
- var _this$state6 = _this.state,
465
- selectedValue = _this$state6.selectedValue,
466
- value = _this$state6.value;
467
- var disabledTime = _this.props.disabledTime;
468
- var userSettingDisabledTime = disabledTime(selectedValue, 'end') || {};
469
- var startValue = selectedValue && selectedValue[0] || value[0].clone();
470
- // if startTime and endTime is same day..
471
- // the second time picker will not able to pick time before first time picker
472
- if (!selectedValue[1] || startValue.isSame(selectedValue[1], 'day')) {
473
- var hours = startValue.hour();
474
- var minutes = startValue.minute();
475
- var second = startValue.second();
476
- var _disabledHours = userSettingDisabledTime.disabledHours,
477
- _disabledMinutes = userSettingDisabledTime.disabledMinutes,
478
- _disabledSeconds = userSettingDisabledTime.disabledSeconds;
479
- var oldDisabledMinutes = _disabledMinutes ? _disabledMinutes() : [];
480
- var olddisabledSeconds = _disabledSeconds ? _disabledSeconds() : [];
481
- _disabledHours = generateOptions(hours, _disabledHours);
482
- _disabledMinutes = generateOptions(minutes, _disabledMinutes);
483
- _disabledSeconds = generateOptions(second, _disabledSeconds);
484
- return {
485
- disabledHours: function disabledHours() {
486
- return _disabledHours;
487
- },
488
- disabledMinutes: function disabledMinutes(hour) {
489
- if (hour === hours) {
490
- return _disabledMinutes;
491
- }
492
- return oldDisabledMinutes;
493
- },
494
- disabledSeconds: function disabledSeconds(hour, minute) {
495
- if (hour === hours && minute === minutes) {
496
- return _disabledSeconds;
497
- }
498
- return olddisabledSeconds;
499
- }
500
- };
501
- }
502
- return userSettingDisabledTime;
503
- });
504
- _defineProperty(_this, "isAllowedDateAndTime", function (selectedValue) {
505
- return (0, _util.isAllowedDate)(selectedValue[0], _this.props.disabledDate, _this.disabledStartTime) && (0, _util.isAllowedDate)(selectedValue[1], _this.props.disabledDate, _this.disabledEndTime);
506
- });
507
- _defineProperty(_this, "isMonthYearPanelShow", function (mode) {
508
- return ['month', 'year', 'decade'].indexOf(mode) > -1;
509
- });
510
- _defineProperty(_this, "hasSelectedValue", function () {
511
- var selectedValue = _this.state.selectedValue;
512
- return !!selectedValue[1] && !!selectedValue[0];
513
- });
514
- _defineProperty(_this, "compare", function (v1, v2) {
515
- if (_this.props.timePicker) {
516
- return v1.diff(v2);
517
- }
518
- return v1.diff(v2, 'days');
519
- });
520
- _defineProperty(_this, "fireSelectValueChange", function (selectedValue, direct, cause) {
521
- var timePicker = _this.props.timePicker;
522
- var prevSelectedValue = _this.state.prevSelectedValue;
523
- if (timePicker && timePicker.props.defaultValue) {
524
- var timePickerDefaultValue = timePicker.props.defaultValue;
525
- if (!prevSelectedValue[0] && selectedValue[0]) {
526
- (0, _util.syncTime)(timePickerDefaultValue[0], selectedValue[0]);
527
- }
528
- if (!prevSelectedValue[1] && selectedValue[1]) {
529
- (0, _util.syncTime)(timePickerDefaultValue[1], selectedValue[1]);
530
- }
531
- }
532
- if (!('selectedValue' in _this.props)) {
533
- _this.setState({
534
- selectedValue: selectedValue
535
- });
536
- }
140
+ var _this = (0, _possibleConstructorReturn3['default'])(this, _React$Component.call(this, props));
537
141
 
538
- // 尚未选择过时间,直接输入的话
539
- if (!_this.state.selectedValue[0] || !_this.state.selectedValue[1]) {
540
- var startValue = selectedValue[0] || (0, _dayjs["default"])();
541
- var endValue = selectedValue[1] || startValue.clone().add(1, 'months');
542
- _this.setState({
543
- selectedValue: selectedValue,
544
- value: getValueFromSelectedValue([startValue, endValue])
545
- });
546
- }
547
- if (selectedValue[0] && !selectedValue[1]) {
548
- _this.setState({
549
- firstSelectedValue: selectedValue[0]
550
- });
551
- _this.fireHoverValueChange(selectedValue.concat());
552
- }
553
- _this.props.onChange(selectedValue);
554
- if (direct || selectedValue[0] && selectedValue[1]) {
555
- _this.setState({
556
- prevSelectedValue: selectedValue,
557
- firstSelectedValue: null
558
- });
559
- _this.fireHoverValueChange([]);
560
- _this.props.onSelect(selectedValue, cause);
561
- }
562
- });
563
- _defineProperty(_this, "fireValueChange", function (value) {
564
- var props = _this.props;
565
- if (!('value' in props)) {
566
- _this.setState({
567
- value: value
568
- });
569
- }
570
- props.onValueChange(value);
571
- });
572
- _defineProperty(_this, "fireHoverValueChange", function (hoverValue) {
573
- var props = _this.props;
574
- if (!('hoverValue' in props)) {
575
- _this.setState({
576
- hoverValue: hoverValue
577
- });
578
- }
579
- props.onHoverChange(hoverValue);
580
- });
581
- _defineProperty(_this, "clear", function () {
582
- _this.fireSelectValueChange([], true);
583
- _this.props.onClear();
584
- });
585
- _defineProperty(_this, "disabledStartTime", function (time) {
586
- return _this.props.disabledTime(time, 'start');
587
- });
588
- _defineProperty(_this, "disabledEndTime", function (time) {
589
- return _this.props.disabledTime(time, 'end');
590
- });
591
- _defineProperty(_this, "disabledStartMonth", function (month) {
592
- var value = _this.state.value;
593
- return month.isAfter(value[1], 'month');
594
- });
595
- _defineProperty(_this, "disabledEndMonth", function (month) {
596
- var value = _this.state.value;
597
- return month.isBefore(value[0], 'month');
598
- });
599
- var _selectedValue2 = _props.selectedValue || _props.defaultSelectedValue;
600
- var _value = normalizeAnchor(_props, 1);
142
+ _initialiseProps.call(_this);
143
+
144
+ var selectedValue = props.selectedValue || props.defaultSelectedValue;
145
+ var value = normalizeAnchor(props, 1);
601
146
  _this.state = {
602
- selectedValue: _selectedValue2,
603
- prevSelectedValue: _selectedValue2,
147
+ selectedValue: selectedValue,
148
+ prevSelectedValue: selectedValue,
604
149
  firstSelectedValue: null,
605
- hoverValue: _props.hoverValue || [],
606
- value: _value,
150
+ hoverValue: props.hoverValue || [],
151
+ value: value,
607
152
  showTimePicker: false,
608
- mode: _props.mode || ['date', 'date'],
153
+ mode: props.mode || ['date', 'date'],
609
154
  panelTriggerSource: '' // Trigger by which picker panel: 'start' & 'end'
610
155
  };
611
156
  return _this;
612
157
  }
613
- _inherits(RangeCalendar, _React$Component);
614
- return _createClass(RangeCalendar, [{
615
- key: "render",
616
- value: function render() {
617
- var props = this.props,
158
+
159
+ RangeCalendar.getDerivedStateFromProps = function getDerivedStateFromProps(nextProps, state) {
160
+ var newState = {};
161
+ if ('value' in nextProps) {
162
+ newState.value = normalizeAnchor(nextProps, 0);
163
+ }
164
+ if ('hoverValue' in nextProps && !isArraysEqual(state.hoverValue, nextProps.hoverValue)) {
165
+ newState.hoverValue = nextProps.hoverValue;
166
+ }
167
+ if ('selectedValue' in nextProps) {
168
+ newState.selectedValue = nextProps.selectedValue;
169
+ newState.prevSelectedValue = nextProps.selectedValue;
170
+ }
171
+ if ('mode' in nextProps && !isArraysEqual(state.mode, nextProps.mode)) {
172
+ newState.mode = nextProps.mode;
173
+ }
174
+ return newState;
175
+ };
176
+
177
+ // get disabled hours for second picker
178
+
179
+
180
+ RangeCalendar.prototype.render = function render() {
181
+ var _className, _classnames;
182
+
183
+ var props = this.props,
618
184
  state = this.state;
619
- var prefixCls = props.prefixCls,
185
+ var prefixCls = props.prefixCls,
620
186
  dateInputPlaceholder = props.dateInputPlaceholder,
621
187
  seperator = props.seperator,
622
188
  timePicker = props.timePicker,
@@ -626,169 +192,183 @@ var RangeCalendar = /*#__PURE__*/function (_React$Component) {
626
192
  showToday = props.showToday,
627
193
  type = props.type,
628
194
  clearIcon = props.clearIcon;
629
- var hoverValue = state.hoverValue,
195
+ var hoverValue = state.hoverValue,
630
196
  selectedValue = state.selectedValue,
631
197
  mode = state.mode,
632
198
  showTimePicker = state.showTimePicker;
633
- var className = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, props.className, !!props.className), prefixCls, 1), "".concat(prefixCls, "-hidden"), !props.visible), "".concat(prefixCls, "-range"), 1), "".concat(prefixCls, "-show-time-picker"), showTimePicker), "".concat(prefixCls, "-week-number"), props.showWeekNumber);
634
- var classes = (0, _classnames2["default"])(className);
635
- var newProps = {
636
- selectedValue: state.selectedValue,
637
- onSelect: this.onSelect,
638
- onDayHover: type === 'start' && selectedValue[1] || type === 'end' && selectedValue[0] || !!hoverValue.length ? this.onDayHover : undefined
639
- };
640
- var placeholder1;
641
- var placeholder2;
642
- if (dateInputPlaceholder) {
643
- if (Array.isArray(dateInputPlaceholder)) {
644
- var _dateInputPlaceholder = _slicedToArray(dateInputPlaceholder, 2);
645
- placeholder1 = _dateInputPlaceholder[0];
646
- placeholder2 = _dateInputPlaceholder[1];
647
- } else {
648
- placeholder1 = placeholder2 = dateInputPlaceholder;
649
- }
199
+
200
+ var className = (_className = {}, _className[props.className] = !!props.className, _className[prefixCls] = 1, _className[prefixCls + '-hidden'] = !props.visible, _className[prefixCls + '-range'] = 1, _className[prefixCls + '-show-time-picker'] = showTimePicker, _className[prefixCls + '-week-number'] = props.showWeekNumber, _className);
201
+ var classes = (0, _classnames3['default'])(className);
202
+ var newProps = {
203
+ selectedValue: state.selectedValue,
204
+ onSelect: this.onSelect,
205
+ onDayHover: type === 'start' && selectedValue[1] || type === 'end' && selectedValue[0] || !!hoverValue.length ? this.onDayHover : undefined
206
+ };
207
+
208
+ var placeholder1 = void 0;
209
+ var placeholder2 = void 0;
210
+
211
+ if (dateInputPlaceholder) {
212
+ if (Array.isArray(dateInputPlaceholder)) {
213
+ placeholder1 = dateInputPlaceholder[0];
214
+ placeholder2 = dateInputPlaceholder[1];
215
+ } else {
216
+ placeholder1 = placeholder2 = dateInputPlaceholder;
650
217
  }
651
- var showOkButton = showOk === true || showOk !== false && !!timePicker;
652
- var cls = (0, _classnames2["default"])(_defineProperty(_defineProperty(_defineProperty({}, "".concat(prefixCls, "-footer"), true), "".concat(prefixCls, "-range-bottom"), true), "".concat(prefixCls, "-footer-show-ok"), showOkButton));
653
- var startValue = this.getStartValue();
654
- var endValue = this.getEndValue();
655
- var todayTime = (0, _util.getTodayTime)(startValue);
656
- var thisMonth = todayTime.month();
657
- var thisYear = todayTime.year();
658
- var isTodayInView = startValue.year() === thisYear && startValue.month() === thisMonth || endValue.year() === thisYear && endValue.month() === thisMonth;
659
- var nextMonthOfStart = startValue.clone().add(1, 'months');
660
- var isClosestMonths = nextMonthOfStart.year() === endValue.year() && nextMonthOfStart.month() === endValue.month();
661
- var extraFooter = props.renderFooter();
662
- return /*#__PURE__*/_react["default"].createElement("div", {
218
+ }
219
+ var showOkButton = showOk === true || showOk !== false && !!timePicker;
220
+ var cls = (0, _classnames3['default'])((_classnames = {}, _classnames[prefixCls + '-footer'] = true, _classnames[prefixCls + '-range-bottom'] = true, _classnames[prefixCls + '-footer-show-ok'] = showOkButton, _classnames));
221
+
222
+ var startValue = this.getStartValue();
223
+ var endValue = this.getEndValue();
224
+ var todayTime = (0, _util.getTodayTime)(startValue);
225
+ var thisMonth = todayTime.month();
226
+ var thisYear = todayTime.year();
227
+ var isTodayInView = startValue.year() === thisYear && startValue.month() === thisMonth || endValue.year() === thisYear && endValue.month() === thisMonth;
228
+ var nextMonthOfStart = startValue.clone().add(1, 'months');
229
+ var isClosestMonths = nextMonthOfStart.year() === endValue.year() && nextMonthOfStart.month() === endValue.month();
230
+
231
+ var extraFooter = props.renderFooter();
232
+
233
+ return _react2['default'].createElement(
234
+ 'div',
235
+ {
663
236
  ref: this.saveRoot,
664
237
  className: classes,
665
238
  style: props.style,
666
- tabIndex: "0",
239
+ tabIndex: '0',
667
240
  onKeyDown: this.onKeyDown
668
- }, props.renderSidebar(), /*#__PURE__*/_react["default"].createElement("div", {
669
- className: "".concat(prefixCls, "-panel")
670
- }, showClear && selectedValue[0] && selectedValue[1] ? /*#__PURE__*/_react["default"].createElement("a", {
671
- role: "button",
672
- title: locale.clear,
673
- onClick: this.clear
674
- }, clearIcon || /*#__PURE__*/_react["default"].createElement("span", {
675
- className: "".concat(prefixCls, "-clear-btn")
676
- })) : null, /*#__PURE__*/_react["default"].createElement("div", {
677
- className: "".concat(prefixCls, "-date-panel"),
678
- onMouseLeave: type !== 'both' ? this.onDatePanelLeave : undefined,
679
- onMouseEnter: type !== 'both' ? this.onDatePanelEnter : undefined
680
- }, /*#__PURE__*/_react["default"].createElement(_CalendarPart["default"], _extends({}, props, newProps, {
681
- hoverValue: hoverValue,
682
- direction: "left",
683
- disabledTime: this.disabledStartTime,
684
- disabledMonth: this.disabledStartMonth,
685
- format: this.getFormat(),
686
- value: startValue,
687
- mode: mode[0],
688
- placeholder: placeholder1,
689
- onInputChange: this.onStartInputChange,
690
- onInputSelect: this.onStartInputSelect,
691
- onValueChange: this.onStartValueChange,
692
- onPanelChange: this.onStartPanelChange,
693
- showDateInput: this.props.showDateInput,
694
- timePicker: timePicker,
695
- showTimePicker: showTimePicker || mode[0] === 'time',
696
- enablePrev: true,
697
- enableNext: !isClosestMonths || this.isMonthYearPanelShow(mode[1]),
698
- clearIcon: clearIcon
699
- })), /*#__PURE__*/_react["default"].createElement("span", {
700
- className: "".concat(prefixCls, "-range-middle")
701
- }, seperator), /*#__PURE__*/_react["default"].createElement(_CalendarPart["default"], _extends({}, props, newProps, {
702
- hoverValue: hoverValue,
703
- direction: "right",
704
- format: this.getFormat(),
705
- timePickerDisabledTime: this.getEndDisableTime(),
706
- placeholder: placeholder2,
707
- value: endValue,
708
- mode: mode[1],
709
- onInputChange: this.onEndInputChange,
710
- onInputSelect: this.onEndInputSelect,
711
- onValueChange: this.onEndValueChange,
712
- onPanelChange: this.onEndPanelChange,
713
- showDateInput: this.props.showDateInput,
714
- timePicker: timePicker,
715
- showTimePicker: showTimePicker || mode[1] === 'time',
716
- disabledTime: this.disabledEndTime,
717
- disabledMonth: this.disabledEndMonth,
718
- enablePrev: !isClosestMonths || this.isMonthYearPanelShow(mode[0]),
719
- enableNext: true,
720
- clearIcon: clearIcon
721
- }))), /*#__PURE__*/_react["default"].createElement("div", {
722
- className: cls
723
- }, showToday || props.timePicker || showOkButton || extraFooter ? /*#__PURE__*/_react["default"].createElement("div", {
724
- className: "".concat(prefixCls, "-footer-btn")
725
- }, extraFooter, showToday ? /*#__PURE__*/_react["default"].createElement(_TodayButton["default"], _extends({}, props, {
726
- disabled: isTodayInView,
727
- value: state.value[0],
728
- onToday: this.onToday,
729
- text: locale.backToToday
730
- })) : null, props.timePicker ? /*#__PURE__*/_react["default"].createElement(_TimePickerButton["default"], _extends({}, props, {
731
- showTimePicker: showTimePicker || mode[0] === 'time' && mode[1] === 'time',
732
- onOpenTimePicker: this.onOpenTimePicker,
733
- onCloseTimePicker: this.onCloseTimePicker,
734
- timePickerDisabled: !this.hasSelectedValue() || hoverValue.length
735
- })) : null, showOkButton ? /*#__PURE__*/_react["default"].createElement(_OkButton["default"], _extends({}, props, {
736
- onOk: this.onOk,
737
- okDisabled: !this.isAllowedDateAndTime(selectedValue) || !this.hasSelectedValue() || hoverValue.length
738
- })) : null) : null)));
739
- }
740
- }], [{
741
- key: "getDerivedStateFromProps",
742
- value: function getDerivedStateFromProps(nextProps, state) {
743
- var newState = {};
744
- if ('value' in nextProps) {
745
- newState.value = normalizeAnchor(nextProps, 0);
746
- }
747
- if ('hoverValue' in nextProps && !isArraysEqual(state.hoverValue, nextProps.hoverValue)) {
748
- newState.hoverValue = nextProps.hoverValue;
749
- }
750
- if ('selectedValue' in nextProps) {
751
- newState.selectedValue = nextProps.selectedValue;
752
- newState.prevSelectedValue = nextProps.selectedValue;
753
- }
754
- if ('mode' in nextProps && !isArraysEqual(state.mode, nextProps.mode)) {
755
- newState.mode = nextProps.mode;
756
- }
757
- return newState;
758
- }
759
- }]);
760
- }(_react["default"].Component);
761
- _defineProperty(RangeCalendar, "propTypes", _objectSpread(_objectSpread({}, _CommonMixin.propType), {}, {
762
- prefixCls: _propTypes["default"].string,
763
- dateInputPlaceholder: _propTypes["default"].any,
764
- seperator: _propTypes["default"].string,
765
- defaultValue: _propTypes["default"].any,
766
- value: _propTypes["default"].any,
767
- hoverValue: _propTypes["default"].any,
768
- mode: _propTypes["default"].arrayOf(_propTypes["default"].oneOf(['time', 'date', 'month', 'year', 'decade'])),
769
- showDateInput: _propTypes["default"].bool,
770
- timePicker: _propTypes["default"].any,
771
- showOk: _propTypes["default"].bool,
772
- showToday: _propTypes["default"].bool,
773
- defaultSelectedValue: _propTypes["default"].array,
774
- selectedValue: _propTypes["default"].array,
775
- onOk: _propTypes["default"].func,
776
- showClear: _propTypes["default"].bool,
777
- locale: _propTypes["default"].object,
778
- onChange: _propTypes["default"].func,
779
- onSelect: _propTypes["default"].func,
780
- onValueChange: _propTypes["default"].func,
781
- onHoverChange: _propTypes["default"].func,
782
- onPanelChange: _propTypes["default"].func,
783
- format: _propTypes["default"].oneOfType([_propTypes["default"].object, _propTypes["default"].string]),
784
- onClear: _propTypes["default"].func,
785
- type: _propTypes["default"].any,
786
- disabledDate: _propTypes["default"].func,
787
- disabledTime: _propTypes["default"].func,
788
- clearIcon: _propTypes["default"].node,
789
- onKeyDown: _propTypes["default"].func
790
- }));
791
- _defineProperty(RangeCalendar, "defaultProps", _objectSpread(_objectSpread({}, _CommonMixin.defaultProp), {}, {
241
+ },
242
+ props.renderSidebar(),
243
+ _react2['default'].createElement(
244
+ 'div',
245
+ { className: prefixCls + '-panel' },
246
+ showClear && selectedValue[0] && selectedValue[1] ? _react2['default'].createElement(
247
+ 'a',
248
+ {
249
+ role: 'button',
250
+ title: locale.clear,
251
+ onClick: this.clear
252
+ },
253
+ clearIcon || _react2['default'].createElement('span', { className: prefixCls + '-clear-btn' })
254
+ ) : null,
255
+ _react2['default'].createElement(
256
+ 'div',
257
+ {
258
+ className: prefixCls + '-date-panel',
259
+ onMouseLeave: type !== 'both' ? this.onDatePanelLeave : undefined,
260
+ onMouseEnter: type !== 'both' ? this.onDatePanelEnter : undefined
261
+ },
262
+ _react2['default'].createElement(_CalendarPart2['default'], (0, _extends3['default'])({}, props, newProps, {
263
+ hoverValue: hoverValue,
264
+ direction: 'left',
265
+ disabledTime: this.disabledStartTime,
266
+ disabledMonth: this.disabledStartMonth,
267
+ format: this.getFormat(),
268
+ value: startValue,
269
+ mode: mode[0],
270
+ placeholder: placeholder1,
271
+ onInputChange: this.onStartInputChange,
272
+ onInputSelect: this.onStartInputSelect,
273
+ onValueChange: this.onStartValueChange,
274
+ onPanelChange: this.onStartPanelChange,
275
+ showDateInput: this.props.showDateInput,
276
+ timePicker: timePicker,
277
+ showTimePicker: showTimePicker || mode[0] === 'time',
278
+ enablePrev: true,
279
+ enableNext: !isClosestMonths || this.isMonthYearPanelShow(mode[1]),
280
+ clearIcon: clearIcon
281
+ })),
282
+ _react2['default'].createElement(
283
+ 'span',
284
+ { className: prefixCls + '-range-middle' },
285
+ seperator
286
+ ),
287
+ _react2['default'].createElement(_CalendarPart2['default'], (0, _extends3['default'])({}, props, newProps, {
288
+ hoverValue: hoverValue,
289
+ direction: 'right',
290
+ format: this.getFormat(),
291
+ timePickerDisabledTime: this.getEndDisableTime(),
292
+ placeholder: placeholder2,
293
+ value: endValue,
294
+ mode: mode[1],
295
+ onInputChange: this.onEndInputChange,
296
+ onInputSelect: this.onEndInputSelect,
297
+ onValueChange: this.onEndValueChange,
298
+ onPanelChange: this.onEndPanelChange,
299
+ showDateInput: this.props.showDateInput,
300
+ timePicker: timePicker,
301
+ showTimePicker: showTimePicker || mode[1] === 'time',
302
+ disabledTime: this.disabledEndTime,
303
+ disabledMonth: this.disabledEndMonth,
304
+ enablePrev: !isClosestMonths || this.isMonthYearPanelShow(mode[0]),
305
+ enableNext: true,
306
+ clearIcon: clearIcon
307
+ }))
308
+ ),
309
+ _react2['default'].createElement(
310
+ 'div',
311
+ { className: cls },
312
+ showToday || props.timePicker || showOkButton || extraFooter ? _react2['default'].createElement(
313
+ 'div',
314
+ { className: prefixCls + '-footer-btn' },
315
+ extraFooter,
316
+ showToday ? _react2['default'].createElement(_TodayButton2['default'], (0, _extends3['default'])({}, props, {
317
+ disabled: isTodayInView,
318
+ value: state.value[0],
319
+ onToday: this.onToday,
320
+ text: locale.backToToday
321
+ })) : null,
322
+ props.timePicker ? _react2['default'].createElement(_TimePickerButton2['default'], (0, _extends3['default'])({}, props, {
323
+ showTimePicker: showTimePicker || mode[0] === 'time' && mode[1] === 'time',
324
+ onOpenTimePicker: this.onOpenTimePicker,
325
+ onCloseTimePicker: this.onCloseTimePicker,
326
+ timePickerDisabled: !this.hasSelectedValue() || hoverValue.length
327
+ })) : null,
328
+ showOkButton ? _react2['default'].createElement(_OkButton2['default'], (0, _extends3['default'])({}, props, {
329
+ onOk: this.onOk,
330
+ okDisabled: !this.isAllowedDateAndTime(selectedValue) || !this.hasSelectedValue() || hoverValue.length
331
+ })) : null
332
+ ) : null
333
+ )
334
+ )
335
+ );
336
+ };
337
+
338
+ return RangeCalendar;
339
+ }(_react2['default'].Component);
340
+
341
+ RangeCalendar.propTypes = (0, _extends3['default'])({}, _CommonMixin.propType, {
342
+ prefixCls: _propTypes2['default'].string,
343
+ dateInputPlaceholder: _propTypes2['default'].any,
344
+ seperator: _propTypes2['default'].string,
345
+ defaultValue: _propTypes2['default'].any,
346
+ value: _propTypes2['default'].any,
347
+ hoverValue: _propTypes2['default'].any,
348
+ mode: _propTypes2['default'].arrayOf(_propTypes2['default'].oneOf(['time', 'date', 'month', 'year', 'decade'])),
349
+ showDateInput: _propTypes2['default'].bool,
350
+ timePicker: _propTypes2['default'].any,
351
+ showOk: _propTypes2['default'].bool,
352
+ showToday: _propTypes2['default'].bool,
353
+ defaultSelectedValue: _propTypes2['default'].array,
354
+ selectedValue: _propTypes2['default'].array,
355
+ onOk: _propTypes2['default'].func,
356
+ showClear: _propTypes2['default'].bool,
357
+ locale: _propTypes2['default'].object,
358
+ onChange: _propTypes2['default'].func,
359
+ onSelect: _propTypes2['default'].func,
360
+ onValueChange: _propTypes2['default'].func,
361
+ onHoverChange: _propTypes2['default'].func,
362
+ onPanelChange: _propTypes2['default'].func,
363
+ format: _propTypes2['default'].oneOfType([_propTypes2['default'].object, _propTypes2['default'].string]),
364
+ onClear: _propTypes2['default'].func,
365
+ type: _propTypes2['default'].any,
366
+ disabledDate: _propTypes2['default'].func,
367
+ disabledTime: _propTypes2['default'].func,
368
+ clearIcon: _propTypes2['default'].node,
369
+ onKeyDown: _propTypes2['default'].func
370
+ });
371
+ RangeCalendar.defaultProps = (0, _extends3['default'])({}, _CommonMixin.defaultProp, {
792
372
  type: 'both',
793
373
  seperator: '~',
794
374
  defaultSelectedValue: [],
@@ -799,6 +379,547 @@ _defineProperty(RangeCalendar, "defaultProps", _objectSpread(_objectSpread({}, _
799
379
  onInputSelect: noop,
800
380
  showToday: true,
801
381
  showDateInput: true
802
- }));
382
+ });
383
+
384
+ var _initialiseProps = function _initialiseProps() {
385
+ var _this2 = this;
386
+
387
+ this.onDatePanelEnter = function () {
388
+ if (_this2.hasSelectedValue()) {
389
+ _this2.fireHoverValueChange(_this2.state.selectedValue.concat());
390
+ }
391
+ };
392
+
393
+ this.onDatePanelLeave = function () {
394
+ if (_this2.hasSelectedValue()) {
395
+ _this2.fireHoverValueChange([]);
396
+ }
397
+ };
398
+
399
+ this.onSelect = function (value) {
400
+ var type = _this2.props.type;
401
+ var _state = _this2.state,
402
+ selectedValue = _state.selectedValue,
403
+ prevSelectedValue = _state.prevSelectedValue,
404
+ firstSelectedValue = _state.firstSelectedValue;
405
+
406
+ var nextSelectedValue = void 0;
407
+ if (type === 'both') {
408
+ if (!firstSelectedValue) {
409
+ (0, _util.syncTime)(prevSelectedValue[0], value);
410
+ nextSelectedValue = [value];
411
+ } else if (_this2.compare(firstSelectedValue, value) < 0) {
412
+ (0, _util.syncTime)(prevSelectedValue[1], value);
413
+ nextSelectedValue = [firstSelectedValue, value];
414
+ } else {
415
+ (0, _util.syncTime)(prevSelectedValue[0], value);
416
+ (0, _util.syncTime)(prevSelectedValue[1], firstSelectedValue);
417
+ nextSelectedValue = [value, firstSelectedValue];
418
+ }
419
+ } else if (type === 'start') {
420
+ (0, _util.syncTime)(prevSelectedValue[0], value);
421
+ var endValue = selectedValue[1];
422
+ nextSelectedValue = endValue && _this2.compare(endValue, value) > 0 ? [value, endValue] : [value];
423
+ } else {
424
+ // type === 'end'
425
+ var startValue = selectedValue[0];
426
+ if (startValue && _this2.compare(startValue, value) <= 0) {
427
+ (0, _util.syncTime)(prevSelectedValue[1], value);
428
+ nextSelectedValue = [startValue, value];
429
+ } else {
430
+ (0, _util.syncTime)(prevSelectedValue[0], value);
431
+ nextSelectedValue = [value];
432
+ }
433
+ }
434
+
435
+ _this2.fireSelectValueChange(nextSelectedValue);
436
+ };
437
+
438
+ this.onKeyDown = function (event) {
439
+ if (event.target.nodeName.toLowerCase() === 'input') {
440
+ return;
441
+ }
442
+
443
+ var keyCode = event.keyCode;
444
+
445
+ var ctrlKey = event.ctrlKey || event.metaKey;
446
+
447
+ var _state2 = _this2.state,
448
+ selectedValue = _state2.selectedValue,
449
+ hoverValue = _state2.hoverValue,
450
+ firstSelectedValue = _state2.firstSelectedValue,
451
+ value = _state2.value;
452
+ var _props = _this2.props,
453
+ onKeyDown = _props.onKeyDown,
454
+ disabledDate = _props.disabledDate;
455
+
456
+ // Update last time of the picker
457
+
458
+ var updateHoverPoint = function updateHoverPoint(func) {
459
+ // Change hover to make focus in UI
460
+ var currentHoverTime = void 0;
461
+ var nextHoverTime = void 0;
462
+ var nextHoverValue = void 0;
463
+
464
+ if (!firstSelectedValue) {
465
+ currentHoverTime = hoverValue[0] || selectedValue[0] || value[0] || (0, _dayjs2['default'])();
466
+ nextHoverTime = func(currentHoverTime);
467
+ nextHoverValue = [nextHoverTime];
468
+ _this2.fireHoverValueChange(nextHoverValue);
469
+ } else {
470
+ if (hoverValue.length === 1) {
471
+ currentHoverTime = hoverValue[0].clone();
472
+ nextHoverTime = func(currentHoverTime);
473
+ nextHoverValue = _this2.onDayHover(nextHoverTime);
474
+ } else {
475
+ currentHoverTime = hoverValue[0].isSame(firstSelectedValue, 'day') ? hoverValue[1] : hoverValue[0];
476
+ nextHoverTime = func(currentHoverTime);
477
+ nextHoverValue = _this2.onDayHover(nextHoverTime);
478
+ }
479
+ }
480
+
481
+ // Find origin hover time on value index
482
+ if (nextHoverValue.length >= 2) {
483
+ var miss = nextHoverValue.some(function (ht) {
484
+ return !(0, _toTime.includesTime)(value, ht, 'month');
485
+ });
486
+ if (miss) {
487
+ var newValue = nextHoverValue.slice().sort(function (t1, t2) {
488
+ return t1.valueOf() - t2.valueOf();
489
+ });
490
+ if (newValue[0].isSame(newValue[1], 'month')) {
491
+ newValue[1] = newValue[0].clone().add(1, 'month');
492
+ }
493
+ _this2.fireValueChange(newValue);
494
+ }
495
+ } else if (nextHoverValue.length === 1) {
496
+ // If only one value, let's keep the origin panel
497
+ var oriValueIndex = value.findIndex(function (time) {
498
+ return time.isSame(currentHoverTime, 'month');
499
+ });
500
+ if (oriValueIndex === -1) oriValueIndex = 0;
501
+
502
+ if (value.every(function (time) {
503
+ return !time.isSame(nextHoverTime, 'month');
504
+ })) {
505
+ var _newValue = value.slice();
506
+ _newValue[oriValueIndex] = nextHoverTime.clone();
507
+ _this2.fireValueChange(_newValue);
508
+ }
509
+ }
510
+
511
+ event.preventDefault();
512
+
513
+ return nextHoverTime;
514
+ };
515
+
516
+ switch (keyCode) {
517
+ case _KeyCode2['default'].DOWN:
518
+ updateHoverPoint(function (time) {
519
+ return (0, _toTime.goTime)(time, 1, 'weeks');
520
+ });
521
+ return;
522
+ case _KeyCode2['default'].UP:
523
+ updateHoverPoint(function (time) {
524
+ return (0, _toTime.goTime)(time, -1, 'weeks');
525
+ });
526
+ return;
527
+ case _KeyCode2['default'].LEFT:
528
+ if (ctrlKey) {
529
+ updateHoverPoint(function (time) {
530
+ return (0, _toTime.goTime)(time, -1, 'years');
531
+ });
532
+ } else {
533
+ updateHoverPoint(function (time) {
534
+ return (0, _toTime.goTime)(time, -1, 'days');
535
+ });
536
+ }
537
+ return;
538
+ case _KeyCode2['default'].RIGHT:
539
+ if (ctrlKey) {
540
+ updateHoverPoint(function (time) {
541
+ return (0, _toTime.goTime)(time, 1, 'years');
542
+ });
543
+ } else {
544
+ updateHoverPoint(function (time) {
545
+ return (0, _toTime.goTime)(time, 1, 'days');
546
+ });
547
+ }
548
+ return;
549
+ case _KeyCode2['default'].HOME:
550
+ updateHoverPoint(function (time) {
551
+ return (0, _toTime.goStartMonth)(time);
552
+ });
553
+ return;
554
+ case _KeyCode2['default'].END:
555
+ updateHoverPoint(function (time) {
556
+ return (0, _toTime.goEndMonth)(time);
557
+ });
558
+ return;
559
+ case _KeyCode2['default'].PAGE_DOWN:
560
+ updateHoverPoint(function (time) {
561
+ return (0, _toTime.goTime)(time, 1, 'month');
562
+ });
563
+ return;
564
+ case _KeyCode2['default'].PAGE_UP:
565
+ updateHoverPoint(function (time) {
566
+ return (0, _toTime.goTime)(time, -1, 'month');
567
+ });
568
+ return;
569
+ case _KeyCode2['default'].ENTER:
570
+ {
571
+ var lastValue = void 0;
572
+ if (hoverValue.length === 0) {
573
+ lastValue = updateHoverPoint(function (time) {
574
+ return time;
575
+ });
576
+ } else if (hoverValue.length === 1) {
577
+ lastValue = hoverValue[0];
578
+ } else {
579
+ lastValue = hoverValue[0].isSame(firstSelectedValue, 'day') ? hoverValue[1] : hoverValue[0];
580
+ }
581
+ if (lastValue && (!disabledDate || !disabledDate(lastValue))) {
582
+ _this2.onSelect(lastValue);
583
+ }
584
+ event.preventDefault();
585
+ return;
586
+ }
587
+ default:
588
+ if (onKeyDown) {
589
+ onKeyDown(event);
590
+ }
591
+ }
592
+ };
593
+
594
+ this.onDayHover = function (value) {
595
+ var hoverValue = [];
596
+ var _state3 = _this2.state,
597
+ selectedValue = _state3.selectedValue,
598
+ firstSelectedValue = _state3.firstSelectedValue;
599
+ var type = _this2.props.type;
600
+
601
+ if (type === 'start' && selectedValue[1]) {
602
+ hoverValue = _this2.compare(value, selectedValue[1]) < 0 ? [value, selectedValue[1]] : [value];
603
+ } else if (type === 'end' && selectedValue[0]) {
604
+ hoverValue = _this2.compare(value, selectedValue[0]) > 0 ? [selectedValue[0], value] : [];
605
+ } else {
606
+ if (!firstSelectedValue) {
607
+ if (_this2.state.hoverValue.length) {
608
+ _this2.setState({ hoverValue: [] });
609
+ }
610
+ return hoverValue;
611
+ }
612
+ hoverValue = _this2.compare(value, firstSelectedValue) < 0 ? [value, firstSelectedValue] : [firstSelectedValue, value];
613
+ }
614
+ _this2.fireHoverValueChange(hoverValue);
615
+
616
+ return hoverValue;
617
+ };
618
+
619
+ this.onToday = function () {
620
+ var startValue = (0, _util.getTodayTime)(_this2.state.value[0]);
621
+ var endValue = startValue.clone().add(1, 'months');
622
+ _this2.setState({ value: [startValue, endValue] });
623
+ };
624
+
625
+ this.onOpenTimePicker = function () {
626
+ _this2.setState({
627
+ showTimePicker: true
628
+ });
629
+ };
630
+
631
+ this.onCloseTimePicker = function () {
632
+ _this2.setState({
633
+ showTimePicker: false
634
+ });
635
+ };
636
+
637
+ this.onOk = function () {
638
+ var selectedValue = _this2.state.selectedValue;
639
+
640
+ if (_this2.isAllowedDateAndTime(selectedValue)) {
641
+ _this2.props.onOk(_this2.state.selectedValue);
642
+ }
643
+ };
644
+
645
+ this.onStartInputChange = function () {
646
+ for (var _len = arguments.length, oargs = Array(_len), _key = 0; _key < _len; _key++) {
647
+ oargs[_key] = arguments[_key];
648
+ }
649
+
650
+ var args = ['left'].concat(oargs);
651
+ return onInputSelect.apply(_this2, args);
652
+ };
653
+
654
+ this.onEndInputChange = function () {
655
+ for (var _len2 = arguments.length, oargs = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
656
+ oargs[_key2] = arguments[_key2];
657
+ }
658
+
659
+ var args = ['right'].concat(oargs);
660
+ return onInputSelect.apply(_this2, args);
661
+ };
662
+
663
+ this.onStartInputSelect = function (value) {
664
+ var args = ['left', value, { source: 'dateInputSelect' }];
665
+ return onInputSelect.apply(_this2, args);
666
+ };
667
+
668
+ this.onEndInputSelect = function (value) {
669
+ var args = ['right', value, { source: 'dateInputSelect' }];
670
+ return onInputSelect.apply(_this2, args);
671
+ };
672
+
673
+ this.onStartValueChange = function (leftValue) {
674
+ var value = [].concat(_this2.state.value);
675
+ value[0] = leftValue;
676
+ return _this2.fireValueChange(value);
677
+ };
678
+
679
+ this.onEndValueChange = function (rightValue) {
680
+ var value = [].concat(_this2.state.value);
681
+ value[1] = rightValue;
682
+ return _this2.fireValueChange(value);
683
+ };
684
+
685
+ this.onStartPanelChange = function (value, mode) {
686
+ var props = _this2.props,
687
+ state = _this2.state;
688
+
689
+ var newMode = [mode, state.mode[1]];
690
+ var newState = {
691
+ panelTriggerSource: 'start'
692
+ };
693
+ if (!('mode' in props)) {
694
+ newState.mode = newMode;
695
+ }
696
+ _this2.setState(newState);
697
+ var newValue = [value || state.value[0], state.value[1]];
698
+ props.onPanelChange(newValue, newMode);
699
+ };
700
+
701
+ this.onEndPanelChange = function (value, mode) {
702
+ var props = _this2.props,
703
+ state = _this2.state;
704
+
705
+ var newMode = [state.mode[0], mode];
706
+ var newState = {
707
+ panelTriggerSource: 'end'
708
+ };
709
+ if (!('mode' in props)) {
710
+ newState.mode = newMode;
711
+ }
712
+ _this2.setState(newState);
713
+ var newValue = [state.value[0], value || state.value[1]];
714
+ props.onPanelChange(newValue, newMode);
715
+ };
716
+
717
+ this.getStartValue = function () {
718
+ var _state4 = _this2.state,
719
+ selectedValue = _state4.selectedValue,
720
+ showTimePicker = _state4.showTimePicker,
721
+ value = _state4.value,
722
+ mode = _state4.mode,
723
+ panelTriggerSource = _state4.panelTriggerSource;
724
+
725
+ var startValue = value[0];
726
+ // keep selectedTime when select date
727
+ if (selectedValue[0] && _this2.props.timePicker) {
728
+ startValue = startValue.clone();
729
+ (0, _util.syncTime)(selectedValue[0], startValue);
730
+ }
731
+ if (showTimePicker && selectedValue[0]) {
732
+ startValue = selectedValue[0];
733
+ }
734
+
735
+ // Adjust month if date not align
736
+ if (panelTriggerSource === 'end' && mode[0] === 'date' && mode[1] === 'date' && startValue.isSame(value[1], 'month')) {
737
+ startValue = startValue.clone().subtract(1, 'month');
738
+ }
739
+
740
+ return startValue;
741
+ };
742
+
743
+ this.getEndValue = function () {
744
+ var _state5 = _this2.state,
745
+ value = _state5.value,
746
+ selectedValue = _state5.selectedValue,
747
+ showTimePicker = _state5.showTimePicker,
748
+ mode = _state5.mode,
749
+ panelTriggerSource = _state5.panelTriggerSource;
750
+
751
+ var endValue = value[1] ? value[1].clone() : value[0].clone().add(1, 'month');
752
+ // keep selectedTime when select date
753
+ if (selectedValue[1] && _this2.props.timePicker) {
754
+ (0, _util.syncTime)(selectedValue[1], endValue);
755
+ }
756
+ if (showTimePicker) {
757
+ endValue = selectedValue[1] ? selectedValue[1] : _this2.getStartValue();
758
+ }
759
+
760
+ // Adjust month if date not align
761
+ if (!showTimePicker && panelTriggerSource !== 'end' && mode[0] === 'date' && mode[1] === 'date' && endValue.isSame(value[0], 'month')) {
762
+ endValue = endValue.clone().add(1, 'month');
763
+ }
764
+
765
+ return endValue;
766
+ };
767
+
768
+ this.getEndDisableTime = function () {
769
+ var _state6 = _this2.state,
770
+ selectedValue = _state6.selectedValue,
771
+ value = _state6.value;
772
+ var disabledTime = _this2.props.disabledTime;
773
+
774
+ var userSettingDisabledTime = disabledTime(selectedValue, 'end') || {};
775
+ var startValue = selectedValue && selectedValue[0] || value[0].clone();
776
+ // if startTime and endTime is same day..
777
+ // the second time picker will not able to pick time before first time picker
778
+ if (!selectedValue[1] || startValue.isSame(selectedValue[1], 'day')) {
779
+ var hours = startValue.hour();
780
+ var minutes = startValue.minute();
781
+ var second = startValue.second();
782
+ var _disabledHours = userSettingDisabledTime.disabledHours,
783
+ _disabledMinutes = userSettingDisabledTime.disabledMinutes,
784
+ _disabledSeconds = userSettingDisabledTime.disabledSeconds;
785
+
786
+ var oldDisabledMinutes = _disabledMinutes ? _disabledMinutes() : [];
787
+ var olddisabledSeconds = _disabledSeconds ? _disabledSeconds() : [];
788
+ _disabledHours = generateOptions(hours, _disabledHours);
789
+ _disabledMinutes = generateOptions(minutes, _disabledMinutes);
790
+ _disabledSeconds = generateOptions(second, _disabledSeconds);
791
+ return {
792
+ disabledHours: function disabledHours() {
793
+ return _disabledHours;
794
+ },
795
+ disabledMinutes: function disabledMinutes(hour) {
796
+ if (hour === hours) {
797
+ return _disabledMinutes;
798
+ }
799
+ return oldDisabledMinutes;
800
+ },
801
+ disabledSeconds: function disabledSeconds(hour, minute) {
802
+ if (hour === hours && minute === minutes) {
803
+ return _disabledSeconds;
804
+ }
805
+ return olddisabledSeconds;
806
+ }
807
+ };
808
+ }
809
+ return userSettingDisabledTime;
810
+ };
811
+
812
+ this.isAllowedDateAndTime = function (selectedValue) {
813
+ return (0, _util.isAllowedDate)(selectedValue[0], _this2.props.disabledDate, _this2.disabledStartTime) && (0, _util.isAllowedDate)(selectedValue[1], _this2.props.disabledDate, _this2.disabledEndTime);
814
+ };
815
+
816
+ this.isMonthYearPanelShow = function (mode) {
817
+ return ['month', 'year', 'decade'].indexOf(mode) > -1;
818
+ };
819
+
820
+ this.hasSelectedValue = function () {
821
+ var selectedValue = _this2.state.selectedValue;
822
+
823
+ return !!selectedValue[1] && !!selectedValue[0];
824
+ };
825
+
826
+ this.compare = function (v1, v2) {
827
+ if (_this2.props.timePicker) {
828
+ return v1.diff(v2);
829
+ }
830
+ return v1.diff(v2, 'days');
831
+ };
832
+
833
+ this.fireSelectValueChange = function (selectedValue, direct, cause) {
834
+ var timePicker = _this2.props.timePicker;
835
+ var prevSelectedValue = _this2.state.prevSelectedValue;
836
+
837
+ if (timePicker && timePicker.props.defaultValue) {
838
+ var timePickerDefaultValue = timePicker.props.defaultValue;
839
+ if (!prevSelectedValue[0] && selectedValue[0]) {
840
+ (0, _util.syncTime)(timePickerDefaultValue[0], selectedValue[0]);
841
+ }
842
+ if (!prevSelectedValue[1] && selectedValue[1]) {
843
+ (0, _util.syncTime)(timePickerDefaultValue[1], selectedValue[1]);
844
+ }
845
+ }
846
+
847
+ if (!('selectedValue' in _this2.props)) {
848
+ _this2.setState({
849
+ selectedValue: selectedValue
850
+ });
851
+ }
852
+
853
+ // 尚未选择过时间,直接输入的话
854
+ if (!_this2.state.selectedValue[0] || !_this2.state.selectedValue[1]) {
855
+ var startValue = selectedValue[0] || (0, _dayjs2['default'])();
856
+ var endValue = selectedValue[1] || startValue.clone().add(1, 'months');
857
+ _this2.setState({
858
+ selectedValue: selectedValue,
859
+ value: getValueFromSelectedValue([startValue, endValue])
860
+ });
861
+ }
862
+
863
+ if (selectedValue[0] && !selectedValue[1]) {
864
+ _this2.setState({ firstSelectedValue: selectedValue[0] });
865
+ _this2.fireHoverValueChange(selectedValue.concat());
866
+ }
867
+ _this2.props.onChange(selectedValue);
868
+ if (direct || selectedValue[0] && selectedValue[1]) {
869
+ _this2.setState({
870
+ prevSelectedValue: selectedValue,
871
+ firstSelectedValue: null
872
+ });
873
+ _this2.fireHoverValueChange([]);
874
+ _this2.props.onSelect(selectedValue, cause);
875
+ }
876
+ };
877
+
878
+ this.fireValueChange = function (value) {
879
+ var props = _this2.props;
880
+ if (!('value' in props)) {
881
+ _this2.setState({
882
+ value: value
883
+ });
884
+ }
885
+ props.onValueChange(value);
886
+ };
887
+
888
+ this.fireHoverValueChange = function (hoverValue) {
889
+ var props = _this2.props;
890
+ if (!('hoverValue' in props)) {
891
+ _this2.setState({ hoverValue: hoverValue });
892
+ }
893
+ props.onHoverChange(hoverValue);
894
+ };
895
+
896
+ this.clear = function () {
897
+ _this2.fireSelectValueChange([], true);
898
+ _this2.props.onClear();
899
+ };
900
+
901
+ this.disabledStartTime = function (time) {
902
+ return _this2.props.disabledTime(time, 'start');
903
+ };
904
+
905
+ this.disabledEndTime = function (time) {
906
+ return _this2.props.disabledTime(time, 'end');
907
+ };
908
+
909
+ this.disabledStartMonth = function (month) {
910
+ var value = _this2.state.value;
911
+
912
+ return month.isAfter(value[1], 'month');
913
+ };
914
+
915
+ this.disabledEndMonth = function (month) {
916
+ var value = _this2.state.value;
917
+
918
+ return month.isBefore(value[0], 'month');
919
+ };
920
+ };
921
+
803
922
  (0, _reactLifecyclesCompat.polyfill)(RangeCalendar);
804
- var _default = exports["default"] = (0, _CommonMixin.commonMixinWrapper)(RangeCalendar);
923
+
924
+ exports['default'] = (0, _CommonMixin.commonMixinWrapper)(RangeCalendar);
925
+ module.exports = exports['default'];