@seafile/seafile-calendar 0.0.31 → 0.0.32-alpha.jh2

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/lib/Calendar.js CHANGED
@@ -108,7 +108,8 @@ var Calendar = function (_React$Component) {
108
108
  _this.state = {
109
109
  mode: _this.props.mode || 'date',
110
110
  value: getMomentObjectIfValid(props.value) || getMomentObjectIfValid(props.defaultValue) || (0, _dayjs2['default'])(),
111
- selectedValue: props.selectedValue || props.defaultSelectedValue
111
+ selectedValue: props.selectedValue || props.defaultSelectedValue,
112
+ currentStatus: 'selectDateTime'
112
113
  };
113
114
  return _this;
114
115
  }
@@ -156,7 +157,8 @@ var Calendar = function (_React$Component) {
156
157
  showWeekNumber = props.showWeekNumber;
157
158
  var value = state.value,
158
159
  selectedValue = state.selectedValue,
159
- mode = state.mode;
160
+ mode = state.mode,
161
+ currentStatus = state.currentStatus;
160
162
 
161
163
  var showTimePicker = mode === 'time';
162
164
  var disabledTimeConfig = showTimePicker && disabledTime && timePicker ? (0, _util.getTimeConfig)(selectedValue, disabledTime) : null;
@@ -181,9 +183,10 @@ var Calendar = function (_React$Component) {
181
183
  timePickerEle = _react2['default'].cloneElement(timePicker, timePickerProps);
182
184
  }
183
185
  var calendarInputPlaceholder = dateInputPlaceholder || (Array.isArray(this.getFormat()) ? this.getFormat()[0] : this.getFormat());
186
+ var inputFormat = Array.isArray(this.getFormat()) ? this.getFormat() : [this.getFormat()];
184
187
 
185
188
  var dateInputElement = props.showDateInput ? _react2['default'].createElement(_DateInput2['default'], {
186
- format: this.getFormat(),
189
+ format: inputFormat,
187
190
  key: 'date-input',
188
191
  value: value,
189
192
  locale: locale,
@@ -248,7 +251,8 @@ var Calendar = function (_React$Component) {
248
251
  onSelect: this.onDateTableSelect,
249
252
  disabledDate: disabledDate,
250
253
  showWeekNumber: showWeekNumber,
251
- firstDayOfWeek: firstDayOfWeek
254
+ firstDayOfWeek: firstDayOfWeek,
255
+ currentStatus: currentStatus
252
256
  })
253
257
  ),
254
258
  _react2['default'].createElement(_CalendarFooter2['default'], {
@@ -280,7 +284,7 @@ var Calendar = function (_React$Component) {
280
284
  onSelect: this.onDateTableSelect,
281
285
  onClickRightPanelTime: onClickRightPanelTime,
282
286
  defaultMinutesTime: this.props.defaultMinutesTime,
283
- format: this.getFormat()
287
+ format: inputFormat
284
288
  })
285
289
  )
286
290
  ));
@@ -423,6 +427,7 @@ var _initialiseProps = function _initialiseProps() {
423
427
  this.onClear = function () {
424
428
  _this2.onSelect(null);
425
429
  _this2.props.onClear();
430
+ _this2.setState({ currentStatus: 'todayTime' });
426
431
  };
427
432
 
428
433
  this.onOk = function () {
@@ -449,6 +454,7 @@ var _initialiseProps = function _initialiseProps() {
449
454
  var timePicker = _this2.props.timePicker;
450
455
  var selectedValue = _this2.state.selectedValue;
451
456
 
457
+ _this2.setState({ currentStatus: 'selectDateTime' });
452
458
  if (!selectedValue && timePicker) {
453
459
  var timePickerDefaultValue = timePicker.props.defaultValue;
454
460
  if (timePickerDefaultValue) {
@@ -63,6 +63,7 @@ var DateInput = function (_React$Component) {
63
63
  _this.state = {
64
64
  str: (0, _util.formatDate)(selectedValue, _this.props.format),
65
65
  hasFocus: false,
66
+ emptyValue: false,
66
67
  localFormat: _this.props.format[0]
67
68
  };
68
69
  return _this;
@@ -170,14 +171,14 @@ var _initialiseProps = function _initialiseProps() {
170
171
  format = _props.format,
171
172
  onChange = _props.onChange,
172
173
  selectedValue = _props.selectedValue;
173
-
174
174
  // 没有内容,合法并直接退出
175
175
 
176
- if (!calendarStr) {
177
- onChange(null);
178
- _this2.setState({ str: '' });
176
+ if (!str || !calendarStr) {
177
+ _this2.setState({ emptyValue: true });
178
+ _this2.onClear();
179
179
  return;
180
180
  }
181
+ if (_this2.state.emptyValue) _this2.setState({ emptyValue: false });
181
182
  var parsed = (0, _dayjs2['default'])(calendarStr, format[0]);
182
183
  var value = _this2.props.value.clone();
183
184
  value = value.year(parsed.year()).month(parsed.month()).date(parsed.date()).hour(parsed.hour()).minute(parsed.minute()).second(parsed.second());
@@ -216,7 +217,11 @@ var _initialiseProps = function _initialiseProps() {
216
217
  if (keyCode === _KeyCode2['default'].ENTER && onSelect) {
217
218
  var validateDate = !disabledDate || !disabledDate(value);
218
219
  if (validateDate) {
219
- onSelect(value.clone());
220
+ if (_this2.state.emptyValue) {
221
+ onSelect(null);
222
+ } else {
223
+ onSelect(value.clone());
224
+ }
220
225
  }
221
226
  event.preventDefault();
222
227
  }
@@ -32,6 +32,10 @@ var _DateConstants2 = _interopRequireDefault(_DateConstants);
32
32
 
33
33
  var _util = require('../util/');
34
34
 
35
+ var _dayjs = require('dayjs');
36
+
37
+ var _dayjs2 = _interopRequireDefault(_dayjs);
38
+
35
39
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
36
40
 
37
41
  var DATE_ROW_COLUMN_COUNT = _DateConstants2['default'].DATE_ROW_COLUMN_COUNT,
@@ -78,7 +82,8 @@ var DateTBody = function (_React$Component) {
78
82
  dateRender = props.dateRender,
79
83
  disabledDate = props.disabledDate,
80
84
  hoverValue = props.hoverValue,
81
- firstDayOfWeek = props.firstDayOfWeek;
85
+ firstDayOfWeek = props.firstDayOfWeek,
86
+ currentStatus = props.currentStatus;
82
87
 
83
88
  var iIndex = void 0;
84
89
  var jIndex = void 0;
@@ -146,7 +151,11 @@ var DateTBody = function (_React$Component) {
146
151
  for (jIndex = 0; jIndex < DATE_ROW_COLUMN_COUNT.DATE_COL_COUNT; jIndex++) {
147
152
  var next = null;
148
153
  var last = null;
149
- current = dateTable[passed];
154
+ if (currentStatus === 'todayTime') {
155
+ current = dateTable[passed].hour((0, _dayjs2['default'])().hour()).minute((0, _dayjs2['default'])().minute()).second((0, _dayjs2['default'])().second()); // eslint-disable-line max-len
156
+ } else {
157
+ current = dateTable[passed];
158
+ }
150
159
  if (jIndex < DATE_ROW_COLUMN_COUNT.DATE_COL_COUNT - 1) {
151
160
  next = dateTable[passed + 1];
152
161
  }
@@ -298,7 +307,8 @@ DateTBody.propTypes = {
298
307
  value: _propTypes2['default'].object,
299
308
  hoverValue: _propTypes2['default'].any,
300
309
  showWeekNumber: _propTypes2['default'].bool,
301
- firstDayOfWeek: _propTypes2['default'].string
310
+ firstDayOfWeek: _propTypes2['default'].string,
311
+ currentStatus: _propTypes2['default'].string
302
312
  };
303
313
  DateTBody.defaultProps = {
304
314
  hoverValue: []
package/lib/util/index.js CHANGED
@@ -513,7 +513,7 @@ function initializeStr(str, format) {
513
513
  return '' + _day10 + dateDelimater + _month10 + dateDelimater + _year10;
514
514
  } else if (inputStrLength >= 1 && inputStrLength <= 8) {
515
515
  var _dateStr6 = inputStr.slice(0, 2);
516
- var _monthStr6 = inputStr.slice(2, 4);
516
+ var _monthStr6 = inputStr.slice(2, 4) || getCurrentMonth();
517
517
  var _yearStr6 = inputStr.slice(4, inputStr.length);
518
518
  var _validateYear11 = validateCalendarYear(_yearStr6);
519
519
 
@@ -557,7 +557,7 @@ function initializeStr(str, format) {
557
557
  return '' + _day12 + dateDelimater + _month12 + dateDelimater + _year12 + ' ' + time;
558
558
  } else if (_datePart2.length >= 1 && _datePart2.length <= 8) {
559
559
  var _dateStr7 = _datePart2.slice(0, 2);
560
- var _monthStr7 = _datePart2.slice(2, 4);
560
+ var _monthStr7 = _datePart2.slice(2, 4) || getCurrentMonth();
561
561
  var _yearStr7 = _datePart2.slice(4, _datePart2.length);
562
562
  var _timeParts2 = tokenizeFormattedDate(inputStr, format);
563
563
  time = validateTime(_timeParts2[1] + ':' + _timeParts2[2]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/seafile-calendar",
3
- "version": "0.0.31",
3
+ "version": "0.0.32-alpha.jh2",
4
4
  "description": "React Calendar",
5
5
  "keywords": [
6
6
  "react",