@seafile/seafile-calendar 1.0.1-beta.4 → 1.0.2-alpha.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/lib/Calendar.js CHANGED
@@ -144,8 +144,6 @@ var Calendar = function (_React$Component) {
144
144
  };
145
145
 
146
146
  Calendar.prototype.render = function render() {
147
- var _this2 = this;
148
-
149
147
  var props = this.props,
150
148
  state = this.state;
151
149
  var locale = props.locale,
@@ -250,7 +248,11 @@ var Calendar = function (_React$Component) {
250
248
  showTimeControls && _react2['default'].createElement(
251
249
  'div',
252
250
  { className: prefixCls + '-time-input-col' },
253
- timeInputTopElement
251
+ _react2['default'].createElement(
252
+ 'div',
253
+ { className: prefixCls + '-time-input' },
254
+ timeInputTopElement
255
+ )
254
256
  )
255
257
  ),
256
258
  _react2['default'].createElement(
@@ -303,9 +305,7 @@ var Calendar = function (_React$Component) {
303
305
  value: value,
304
306
  selectedValue: selectedValue,
305
307
  locale: locale,
306
- onSelect: function onSelect(v) {
307
- return _this2.onDateTableSelect(v);
308
- },
308
+ onSelect: this.onDateTableSelect,
309
309
  onClickRightPanelTime: onClickRightPanelTime,
310
310
  defaultMinutesTime: this.props.defaultMinutesTime,
311
311
  format: inputFormat
@@ -392,14 +392,14 @@ Calendar.defaultProps = (0, _extends3['default'])({}, _CalendarMixin.calendarMix
392
392
  });
393
393
 
394
394
  var _initialiseProps = function _initialiseProps() {
395
- var _this3 = this;
395
+ var _this2 = this;
396
396
 
397
397
  this.onPanelChange = function (value, mode) {
398
- var props = _this3.props,
399
- state = _this3.state;
398
+ var props = _this2.props,
399
+ state = _this2.state;
400
400
 
401
401
  if (!('mode' in props)) {
402
- _this3.setState({ mode: mode });
402
+ _this2.setState({ mode: mode });
403
403
  }
404
404
  props.onPanelChange(value || state.value, mode);
405
405
  };
@@ -411,109 +411,112 @@ var _initialiseProps = function _initialiseProps() {
411
411
  var keyCode = event.keyCode;
412
412
  // mac
413
413
  var ctrlKey = event.ctrlKey || event.metaKey;
414
- var disabledDate = _this3.props.disabledDate;
415
- var value = _this3.state.value;
414
+ var disabledDate = _this2.props.disabledDate;
415
+ var value = _this2.state.value;
416
416
 
417
417
  switch (keyCode) {
418
418
  case _KeyCode2['default'].DOWN:
419
- _this3.goTime(1, 'weeks');
419
+ _this2.goTime(1, 'weeks');
420
420
  event.preventDefault();
421
421
  return 1;
422
422
  case _KeyCode2['default'].UP:
423
- _this3.goTime(-1, 'weeks');
423
+ _this2.goTime(-1, 'weeks');
424
424
  event.preventDefault();
425
425
  return 1;
426
426
  case _KeyCode2['default'].LEFT:
427
427
  if (ctrlKey) {
428
- _this3.goTime(-1, 'years');
428
+ _this2.goTime(-1, 'years');
429
429
  } else {
430
- _this3.goTime(-1, 'days');
430
+ _this2.goTime(-1, 'days');
431
431
  }
432
432
  event.preventDefault();
433
433
  return 1;
434
434
  case _KeyCode2['default'].RIGHT:
435
435
  if (ctrlKey) {
436
- _this3.goTime(1, 'years');
436
+ _this2.goTime(1, 'years');
437
437
  } else {
438
- _this3.goTime(1, 'days');
438
+ _this2.goTime(1, 'days');
439
439
  }
440
440
  event.preventDefault();
441
441
  return 1;
442
442
  case _KeyCode2['default'].HOME:
443
- _this3.setValue((0, _toTime.goStartMonth)(_this3.state.value));
443
+ _this2.setValue((0, _toTime.goStartMonth)(_this2.state.value));
444
444
  event.preventDefault();
445
445
  return 1;
446
446
  case _KeyCode2['default'].END:
447
- _this3.setValue((0, _toTime.goEndMonth)(_this3.state.value));
447
+ _this2.setValue((0, _toTime.goEndMonth)(_this2.state.value));
448
448
  event.preventDefault();
449
449
  return 1;
450
450
  case _KeyCode2['default'].PAGE_DOWN:
451
- _this3.goTime(1, 'month');
451
+ _this2.goTime(1, 'month');
452
452
  event.preventDefault();
453
453
  return 1;
454
454
  case _KeyCode2['default'].PAGE_UP:
455
- _this3.goTime(-1, 'month');
455
+ _this2.goTime(-1, 'month');
456
456
  event.preventDefault();
457
457
  return 1;
458
458
  case _KeyCode2['default'].ENTER:
459
459
  if (!disabledDate || !disabledDate(value)) {
460
- _this3.onSelect(value, {
460
+ _this2.onSelect(value, {
461
461
  source: 'keyboard'
462
462
  });
463
463
  }
464
464
  event.preventDefault();
465
465
  return 1;
466
466
  default:
467
- _this3.props.onKeyDown(event);
467
+ _this2.props.onKeyDown(event);
468
468
  return 1;
469
469
  }
470
470
  };
471
471
 
472
472
  this.onClear = function () {
473
- _this3.onSelect(null);
474
- _this3.props.onClear();
475
- _this3.setState({ currentStatus: _util.CALENDAR_STATUS.CURRENT_TIME });
473
+ _this2.onSelect(null);
474
+ _this2.props.onClear();
475
+ _this2.setState({ currentStatus: _util.CALENDAR_STATUS.CURRENT_TIME });
476
476
  };
477
477
 
478
478
  this.onOk = function () {
479
- var selectedValue = _this3.state.selectedValue;
479
+ var selectedValue = _this2.state.selectedValue;
480
480
 
481
- if (_this3.isAllowedDate(selectedValue)) {
482
- _this3.props.onOk(selectedValue);
481
+ if (_this2.isAllowedDate(selectedValue)) {
482
+ _this2.props.onOk(selectedValue);
483
483
  }
484
484
  };
485
485
 
486
486
  this.onDateInputChange = function (value) {
487
- _this3.onSelect(value, {
487
+ var now = (0, _dayjs2['default'])();
488
+ if (value && value.hour() === 0 && value.minute() === 0 && value.second() === 0) {
489
+ value = value.hour(now.hour()).minute(now.minute()).second(now.second());
490
+ }
491
+ _this2.onSelect(value, {
488
492
  source: 'dateInput'
489
493
  });
490
494
  };
491
495
 
492
496
  this.onDateInputSelect = function (value) {
493
- _this3.onSelect(value, {
497
+ var now = (0, _dayjs2['default'])();
498
+ if (value && value.hour() === 0 && value.minute() === 0 && value.second() === 0) {
499
+ value = value.hour(now.hour()).minute(now.minute()).second(now.second());
500
+ }
501
+ _this2.onSelect(value, {
494
502
  source: 'dateInputSelect'
495
503
  });
496
504
  };
497
505
 
498
506
  this.onDateTableSelect = function (value) {
499
- var timePicker = _this3.props.timePicker;
500
- var selectedValue = _this3.state.selectedValue;
501
-
502
- _this3.setState({ currentStatus: _util.CALENDAR_STATUS.SPECIFIC_TIME });
503
- if (!selectedValue && timePicker) {
504
- var timePickerDefaultValue = timePicker.props.defaultValue;
505
- if (timePickerDefaultValue) {
506
- (0, _util.syncTime)(timePickerDefaultValue, value);
507
- }
507
+ _this2.setState({ currentStatus: _util.CALENDAR_STATUS.SPECIFIC_TIME });
508
+ var now = (0, _dayjs2['default'])();
509
+ if (value && value.hour() === 0 && value.minute() === 0 && value.second() === 0) {
510
+ value = value.hour(now.hour()).minute(now.minute()).second(now.second());
508
511
  }
509
- _this3.onSelect(value);
512
+ _this2.onSelect(value);
510
513
  };
511
514
 
512
515
  this.onToday = function () {
513
- var value = _this3.state.value;
516
+ var value = _this2.state.value;
514
517
 
515
518
  var now = (0, _util.getTodayTime)(value);
516
- _this3.onSelect(now, {
519
+ _this2.onSelect(now, {
517
520
  source: 'todayButton'
518
521
  });
519
522
  };
@@ -522,41 +525,41 @@ var _initialiseProps = function _initialiseProps() {
522
525
  setTimeout(function () {
523
526
  var dateInput = _DateInput2['default'].getInstance();
524
527
  var timeInput = _TimeInput2['default'].getInstance && _TimeInput2['default'].getInstance();
525
- var rootInstance = _this3.rootInstance;
528
+ var rootInstance = _this2.rootInstance;
526
529
 
527
530
  if (!rootInstance || rootInstance.contains(document.activeElement) || dateInput && dateInput.contains(document.activeElement) || timeInput && timeInput.contains && timeInput.contains(document.activeElement)) {
528
531
  // focused element is still part of Calendar
529
532
  return;
530
533
  }
531
534
 
532
- if (_this3.props.onBlur) {
533
- _this3.props.onBlur(event);
535
+ if (_this2.props.onBlur) {
536
+ _this2.props.onBlur(event);
534
537
  }
535
538
  }, 0);
536
539
  };
537
540
 
538
541
  this.onTimeInputChange = function (value) {
539
- _this3.onSelect(value, { source: 'timeInputChange' });
542
+ _this2.onSelect(value, { source: 'timeInputChange' });
540
543
  };
541
544
 
542
545
  this.onTimeInputSelect = function (value) {
543
- _this3.onSelect(value, { source: 'timeInputSelect' });
546
+ _this2.onSelect(value, { source: 'timeInputSelect' });
544
547
  };
545
548
 
546
549
  this.getRootDOMNode = function () {
547
- return _reactDom2['default'].findDOMNode(_this3);
550
+ return _reactDom2['default'].findDOMNode(_this2);
548
551
  };
549
552
 
550
553
  this.openTimePicker = function () {
551
- _this3.onPanelChange(null, 'time');
554
+ _this2.onPanelChange(null, 'time');
552
555
  };
553
556
 
554
557
  this.closeTimePicker = function () {
555
- _this3.onPanelChange(null, 'date');
558
+ _this2.onPanelChange(null, 'date');
556
559
  };
557
560
 
558
561
  this.goTime = function (direction, unit) {
559
- _this3.setValue((0, _toTime.goTime)(_this3.state.value, direction, unit));
562
+ _this2.setValue((0, _toTime.goTime)(_this2.state.value, direction, unit));
560
563
  };
561
564
  };
562
565
 
@@ -132,7 +132,7 @@ var CalendarHeader = function (_React$Component) {
132
132
  { className: prefixCls + '-header' },
133
133
  _react2['default'].createElement(
134
134
  'div',
135
- { style: { position: 'relative' } },
135
+ { style: { position: 'relative', height: '100%', display: 'flex', alignItems: 'center', justifyContent: 'center' } },
136
136
  showIf(enablePrev && !showTimePicker, _react2['default'].createElement('a', {
137
137
  className: prefixCls + '-prev-year-btn',
138
138
  role: 'button',
@@ -49,9 +49,10 @@ var CalendarRightPanel = function (_React$Component) {
49
49
  };
50
50
 
51
51
  _this.onSelectMinute = function (minute) {
52
- var base = _this.props.selectedValue || _this.props.value || _this.state.highlightTime || (0, _dayjs2['default'])();
53
- var h = parseInt(_this.getSelectedHour(), 10) || 0;
54
- var m = parseInt(minute, 10) || 0;
52
+ var base = _this.props.selectedValue || _this.state.highlightTime || _this.props.value || (0, _dayjs2['default'])();
53
+ var selectedHour = _this.getSelectedHour();
54
+ var h = selectedHour !== null ? parseInt(selectedHour, 10) : (0, _dayjs2['default'])().hour();
55
+ var m = parseInt(minute, 10);
55
56
  var current = base.clone().hour(h).minute(m);
56
57
  _this.skipScrollUpdates = 2;
57
58
  _this.setState({ highlightTime: current });
@@ -62,9 +63,10 @@ var CalendarRightPanel = function (_React$Component) {
62
63
  };
63
64
 
64
65
  _this.onSelectHour = function (hour) {
65
- var base = _this.props.selectedValue || _this.props.value || _this.state.highlightTime || (0, _dayjs2['default'])();
66
- var h = parseInt(hour, 10) || 0;
67
- var m = parseInt(_this.getSelectedMinute(), 10) || 0;
66
+ var base = _this.props.selectedValue || _this.state.highlightTime || (0, _dayjs2['default'])();
67
+ var h = parseInt(hour, 10);
68
+ var selectedMinute = _this.getSelectedMinute();
69
+ var m = selectedMinute !== null ? parseInt(selectedMinute, 10) : (0, _dayjs2['default'])().minute();
68
70
  var current = base.clone().hour(h).minute(m);
69
71
  _this.skipScrollUpdates = 2;
70
72
  _this.setState({ highlightTime: current });
@@ -85,27 +87,23 @@ var CalendarRightPanel = function (_React$Component) {
85
87
 
86
88
  _this.getSelectedHour = function () {
87
89
  var highlightTime = _this.state.highlightTime;
88
- var _this$props = _this.props,
89
- value = _this$props.value,
90
- selectedValue = _this$props.selectedValue;
90
+ var selectedValue = _this.props.selectedValue;
91
91
 
92
- var v = highlightTime || selectedValue || value;
93
- return v ? v.format('HH') : '00';
92
+ var v = highlightTime || selectedValue || null;
93
+ return v ? v.format('HH') : null;
94
94
  };
95
95
 
96
96
  _this.getSelectedMinute = function () {
97
97
  var highlightTime = _this.state.highlightTime;
98
- var _this$props2 = _this.props,
99
- value = _this$props2.value,
100
- selectedValue = _this$props2.selectedValue;
98
+ var selectedValue = _this.props.selectedValue;
101
99
 
102
- var v = highlightTime || selectedValue || value;
103
- return v ? v.format('mm') : '00';
100
+ var v = highlightTime || selectedValue || null;
101
+ return v ? v.format('mm') : null;
104
102
  };
105
103
 
106
104
  var format = Array.isArray(_this.props.format) ? _this.props.format[0] : _this.props.format;
107
105
  _this.state = {
108
- highlightTime: _this.props.selectedValue || _this.props.value || null,
106
+ highlightTime: _this.props.selectedValue || null,
109
107
  localeFormat: format
110
108
  };
111
109
 
@@ -132,10 +130,9 @@ var CalendarRightPanel = function (_React$Component) {
132
130
 
133
131
  var _props = this.props,
134
132
  defaultMinutesTime = _props.defaultMinutesTime,
135
- value = _props.value,
136
133
  selectedValue = _props.selectedValue;
137
134
 
138
- var baseTime = defaultMinutesTime || (selectedValue || value ? (selectedValue || value).format('HH:mm') : '00:00');
135
+ var baseTime = defaultMinutesTime || (selectedValue ? selectedValue.format('HH:mm') : (0, _dayjs2['default'])().format('HH:mm'));
139
136
  var base = baseTime.split(':');
140
137
  var hIdx = this.hours.findIndex(function (h) {
141
138
  return h === base[0];
@@ -160,8 +157,8 @@ var CalendarRightPanel = function (_React$Component) {
160
157
  CalendarRightPanel.prototype.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {
161
158
  var _this3 = this;
162
159
 
163
- var prevV = prevState.highlightTime || prevProps.selectedValue || prevProps.value;
164
- var currV = this.state.highlightTime || this.props.selectedValue || this.props.value;
160
+ var prevV = prevState.highlightTime || prevProps.selectedValue || (0, _dayjs2['default'])();
161
+ var currV = this.state.highlightTime || this.props.selectedValue || (0, _dayjs2['default'])();
165
162
 
166
163
  var prevH = prevV ? prevV.format('HH') : '00';
167
164
  var prevM = prevV ? prevV.format('mm') : '00';
@@ -207,15 +204,20 @@ var CalendarRightPanel = function (_React$Component) {
207
204
 
208
205
  var selectedHour = this.getSelectedHour();
209
206
  var selectedMinute = this.getSelectedMinute();
207
+ var currentHour = (0, _dayjs2['default'])().format('HH');
208
+ var currentMinute = (0, _dayjs2['default'])().format('mm');
209
+ var displayHour = selectedHour || currentHour;
210
+ var displayMinute = selectedMinute || currentMinute;
211
+
210
212
  return _react2['default'].createElement(
211
213
  'div',
212
214
  { className: prefixCls + '-right-panel' },
213
215
  _react2['default'].createElement(
214
216
  'div',
215
- { className: prefixCls + '-right-panel-time-header' },
216
- selectedHour,
217
+ { className: prefixCls + '-right-panel-header ' + prefixCls + '-header' },
218
+ displayHour,
217
219
  ':',
218
- selectedMinute
220
+ displayMinute
219
221
  ),
220
222
  _react2['default'].createElement(
221
223
  'div',
@@ -227,6 +229,9 @@ var CalendarRightPanel = function (_React$Component) {
227
229
  'ul',
228
230
  null,
229
231
  this.hours.map(function (h) {
232
+ var isSelected = selectedHour && h === selectedHour;
233
+ var isCurrent = !selectedHour && h === currentHour;
234
+ var className = prefixCls + '-right-panel-item-text ' + (isSelected ? prefixCls + '-right-panel-item-selected' : '') + ' ' + (isCurrent ? prefixCls + '-right-panel-item-current' : '');
230
235
  return _react2['default'].createElement(
231
236
  'li',
232
237
  {
@@ -234,10 +239,14 @@ var CalendarRightPanel = function (_React$Component) {
234
239
  onClick: function onClick() {
235
240
  return _this4.onSelectHour(h);
236
241
  },
237
- className: prefixCls + '-right-panel-item ' + (h === selectedHour ? prefixCls + '-right-panel-item-selected' : ''),
242
+ className: prefixCls + '-right-panel-item',
238
243
  title: h
239
244
  },
240
- h
245
+ _react2['default'].createElement(
246
+ 'span',
247
+ { className: className },
248
+ h
249
+ )
241
250
  );
242
251
  })
243
252
  )
@@ -249,6 +258,9 @@ var CalendarRightPanel = function (_React$Component) {
249
258
  'ul',
250
259
  null,
251
260
  this.minutes.map(function (m) {
261
+ var isSelected = selectedMinute && m === selectedMinute;
262
+ var isCurrent = !selectedMinute && m === currentMinute;
263
+ var className = prefixCls + '-right-panel-item-text ' + (isSelected ? prefixCls + '-right-panel-item-selected' : '') + ' ' + (isCurrent ? prefixCls + '-right-panel-item-current' : '');
252
264
  return _react2['default'].createElement(
253
265
  'li',
254
266
  {
@@ -256,10 +268,14 @@ var CalendarRightPanel = function (_React$Component) {
256
268
  onClick: function onClick() {
257
269
  return _this4.onSelectMinute(m);
258
270
  },
259
- className: prefixCls + '-right-panel-item ' + (m === selectedMinute ? prefixCls + '-right-panel-item-selected' : ''),
271
+ className: prefixCls + '-right-panel-item',
260
272
  title: m
261
273
  },
262
- m
274
+ _react2['default'].createElement(
275
+ 'span',
276
+ { className: className },
277
+ m
278
+ )
263
279
  );
264
280
  })
265
281
  )
@@ -119,6 +119,7 @@ var DateInput = function (_React$Component) {
119
119
  'div',
120
120
  { className: prefixCls + '-date-input-wrap' },
121
121
  _react2['default'].createElement('input', {
122
+ id: 'date-input',
122
123
  ref: this.saveDateInput,
123
124
  className: prefixCls + '-input',
124
125
  value: str,
@@ -165,22 +165,27 @@ var TimeInput = function (_React$Component) {
165
165
  disabled = _props.disabled,
166
166
  className = _props.className;
167
167
 
168
- var inputCls = className || prefixCls + '-time-input ' + prefixCls + '-text-input';
168
+ var inputCls = className || prefixCls + '-input';
169
169
  return _react2['default'].createElement(
170
170
  'div',
171
- { className: prefixCls + '-time-input-outer' },
172
- _react2['default'].createElement('input', {
173
- ref: this.saveRef,
174
- className: inputCls,
175
- value: this.state.str,
176
- disabled: disabled,
177
- placeholder: placeholder,
178
- onChange: this.onInputChange,
179
- onKeyDown: this.onKeyDown,
180
- onFocus: this.onFocus,
181
- onBlur: this.onBlur,
182
- inputMode: inputMode
183
- })
171
+ { className: prefixCls + '-input-wrap' },
172
+ _react2['default'].createElement(
173
+ 'div',
174
+ { className: prefixCls + '-time-input-wrap' },
175
+ _react2['default'].createElement('input', {
176
+ id: 'time-input',
177
+ ref: this.saveRef,
178
+ className: inputCls,
179
+ value: this.state.str,
180
+ disabled: disabled,
181
+ placeholder: placeholder,
182
+ onChange: this.onInputChange,
183
+ onKeyDown: this.onKeyDown,
184
+ onFocus: this.onFocus,
185
+ onBlur: this.onBlur,
186
+ inputMode: inputMode
187
+ })
188
+ )
184
189
  );
185
190
  };
186
191
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/seafile-calendar",
3
- "version": "1.0.1-beta.4",
3
+ "version": "1.0.2-alpha.1",
4
4
  "description": "React Calendar",
5
5
  "keywords": [
6
6
  "react",