@seafile/seafile-calendar 0.0.88899 → 0.1.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.
@@ -5,8 +5,7 @@ import React from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import cx from 'classnames';
7
7
  import DateConstants from './DateConstants';
8
- import { getTitleString, getTodayTime } from '../util/';
9
- import dayjs from 'dayjs';
8
+ import { getTitleString, getTodayTime, syncCurrentTime } from '../util/';
10
9
 
11
10
  var DATE_ROW_COLUMN_COUNT = DateConstants.DATE_ROW_COLUMN_COUNT,
12
11
  DAY_NAME_TO_INDEX = DateConstants.DAY_NAME_TO_INDEX;
@@ -122,11 +121,7 @@ var DateTBody = function (_React$Component) {
122
121
  for (jIndex = 0; jIndex < DATE_ROW_COLUMN_COUNT.DATE_COL_COUNT; jIndex++) {
123
122
  var next = null;
124
123
  var last = null;
125
- if (currentStatus === 'todayTime') {
126
- current = dateTable[passed].hour(dayjs().hour()).minute(dayjs().minute()).second(dayjs().second()); // eslint-disable-line max-len
127
- } else {
128
- current = dateTable[passed];
129
- }
124
+ current = syncCurrentTime(dateTable[passed], currentStatus);
130
125
  if (jIndex < DATE_ROW_COLUMN_COUNT.DATE_COL_COUNT - 1) {
131
126
  next = dateTable[passed + 1];
132
127
  }
package/es/util/index.js CHANGED
@@ -27,6 +27,18 @@ export var DATE_FORMATS = {
27
27
  Germany_Russia_etcAndTime: 'DD.MM.YYYY HH:mm'
28
28
  };
29
29
 
30
+ export var CALENDAR_STATUS = {
31
+ SPECIFIC_TIME: 'specific_time',
32
+ CURRENT_TIME: 'current_time'
33
+ };
34
+
35
+ export var syncCurrentTime = function syncCurrentTime(date, status) {
36
+ if (status === CALENDAR_STATUS.CURRENT_TIME) {
37
+ return date.hour(dayjs().hour()).minute(dayjs().minute()).second(dayjs().second());
38
+ }
39
+ return date;
40
+ };
41
+
30
42
  var defaultDisabledTime = {
31
43
  disabledHours: function disabledHours() {
32
44
  return [];
package/lib/Calendar.js CHANGED
@@ -109,7 +109,7 @@ var Calendar = function (_React$Component) {
109
109
  mode: _this.props.mode || 'date',
110
110
  value: getMomentObjectIfValid(props.value) || getMomentObjectIfValid(props.defaultValue) || (0, _dayjs2['default'])(),
111
111
  selectedValue: props.selectedValue || props.defaultSelectedValue,
112
- currentStatus: 'selectDateTime'
112
+ currentStatus: _util.CALENDAR_STATUS.SPECIFIC_TIME
113
113
  };
114
114
  return _this;
115
115
  }
@@ -427,7 +427,7 @@ var _initialiseProps = function _initialiseProps() {
427
427
  this.onClear = function () {
428
428
  _this2.onSelect(null);
429
429
  _this2.props.onClear();
430
- _this2.setState({ currentStatus: 'todayTime' });
430
+ _this2.setState({ currentStatus: _util.CALENDAR_STATUS.CURRENT_TIME });
431
431
  };
432
432
 
433
433
  this.onOk = function () {
@@ -454,7 +454,7 @@ var _initialiseProps = function _initialiseProps() {
454
454
  var timePicker = _this2.props.timePicker;
455
455
  var selectedValue = _this2.state.selectedValue;
456
456
 
457
- _this2.setState({ currentStatus: 'selectDateTime' });
457
+ _this2.setState({ currentStatus: _util.CALENDAR_STATUS.SPECIFIC_TIME });
458
458
  if (!selectedValue && timePicker) {
459
459
  var timePickerDefaultValue = timePicker.props.defaultValue;
460
460
  if (timePickerDefaultValue) {
@@ -63,11 +63,20 @@ var DateInput = function (_React$Component) {
63
63
  _this.state = {
64
64
  str: (0, _util.formatDate)(selectedValue, _this.props.format),
65
65
  hasFocus: false,
66
+ isInputEmpty: false,
66
67
  localFormat: _this.props.format[0]
67
68
  };
68
69
  return _this;
69
70
  }
70
71
 
72
+ DateInput.prototype.componentDidMount = function componentDidMount() {
73
+ var _this2 = this;
74
+
75
+ setTimeout(function () {
76
+ _this2.focus();
77
+ }, 100);
78
+ };
79
+
71
80
  DateInput.prototype.componentDidUpdate = function componentDidUpdate() {
72
81
  if (dateInputInstance && this.state.hasFocus && !(cachedSelectionStart === 0 && cachedSelectionEnd === 0)) {
73
82
  dateInputInstance.setSelectionRange(cachedSelectionStart, cachedSelectionEnd);
@@ -119,10 +128,11 @@ var DateInput = function (_React$Component) {
119
128
  onKeyDown: this.onKeyDown,
120
129
  onFocus: this.onFocus,
121
130
  onBlur: this.onBlur,
122
- inputMode: inputMode
131
+ inputMode: inputMode,
132
+ tabIndex: '0'
123
133
  })
124
134
  ),
125
- props.showClear ? _react2['default'].createElement(
135
+ props.showClear && _react2['default'].createElement(
126
136
  'a',
127
137
  {
128
138
  role: 'button',
@@ -130,7 +140,7 @@ var DateInput = function (_React$Component) {
130
140
  onClick: this.onClear
131
141
  },
132
142
  clearIcon || _react2['default'].createElement('span', { className: prefixCls + '-clear-btn' })
133
- ) : null
143
+ )
134
144
  );
135
145
  };
136
146
 
@@ -155,48 +165,55 @@ DateInput.propTypes = {
155
165
  };
156
166
 
157
167
  var _initialiseProps = function _initialiseProps() {
158
- var _this2 = this;
168
+ var _this3 = this;
159
169
 
160
170
  this.onClear = function () {
161
- _this2.setState({ str: '' });
162
- _this2.props.onClear(null);
171
+ _this3.setState({ str: '' });
172
+ _this3.props.onClear(null);
163
173
  };
164
174
 
165
175
  this.onInputChange = function (event) {
166
176
  var str = event.target.value;
167
- var calendarStr = (0, _util.initializeStr)(str, _this2.state.localFormat) || '';
168
- var _props = _this2.props,
177
+ var calendarStr = (0, _util.initializeStr)(str, _this3.state.localFormat) || '';
178
+ var _props = _this3.props,
169
179
  disabledDate = _props.disabledDate,
170
180
  format = _props.format,
171
181
  onChange = _props.onChange,
172
182
  selectedValue = _props.selectedValue;
183
+
173
184
  // 没有内容,合法并直接退出
174
185
 
175
186
  if (!str || !calendarStr) {
176
- _this2.onClear();
187
+ _this3.setState({ isInputEmpty: true });
188
+ _this3.onClear();
177
189
  return;
178
190
  }
191
+
192
+ if (_this3.state.isInputEmpty) {
193
+ _this3.setState({ isInputEmpty: false });
194
+ }
195
+
179
196
  var parsed = (0, _dayjs2['default'])(calendarStr, format[0]);
180
- var value = _this2.props.value.clone();
197
+ var value = _this3.props.value.clone();
181
198
  value = value.year(parsed.year()).month(parsed.month()).date(parsed.date()).hour(parsed.hour()).minute(parsed.minute()).second(parsed.second());
182
199
 
183
200
  if (!value || disabledDate && disabledDate(value)) {
184
- _this2.setState({ str: str });
201
+ _this3.setState({ str: str });
185
202
  return;
186
203
  }
187
204
 
188
205
  if (selectedValue !== value || selectedValue && value && !selectedValue.isSame(value)) {
189
- _this2.setState({ str: str });
206
+ _this3.setState({ str: str });
190
207
  onChange(value);
191
208
  }
192
209
  };
193
210
 
194
211
  this.onFocus = function () {
195
- _this2.setState({ hasFocus: true });
212
+ _this3.setState({ hasFocus: true });
196
213
  };
197
214
 
198
215
  this.onBlur = function () {
199
- _this2.setState(function (prevState, prevProps) {
216
+ _this3.setState(function (prevState, prevProps) {
200
217
  return {
201
218
  hasFocus: false,
202
219
  str: (0, _util.formatDate)(prevProps.value, prevProps.format)
@@ -206,7 +223,7 @@ var _initialiseProps = function _initialiseProps() {
206
223
 
207
224
  this.onKeyDown = function (event) {
208
225
  var keyCode = event.keyCode;
209
- var _props2 = _this2.props,
226
+ var _props2 = _this3.props,
210
227
  onSelect = _props2.onSelect,
211
228
  value = _props2.value,
212
229
  disabledDate = _props2.disabledDate;
@@ -214,14 +231,18 @@ var _initialiseProps = function _initialiseProps() {
214
231
  if (keyCode === _KeyCode2['default'].ENTER && onSelect) {
215
232
  var validateDate = !disabledDate || !disabledDate(value);
216
233
  if (validateDate) {
217
- onSelect(value.clone());
234
+ if (_this3.state.isInputEmpty) {
235
+ onSelect(null);
236
+ } else {
237
+ onSelect(value.clone());
238
+ }
218
239
  }
219
240
  event.preventDefault();
220
241
  }
221
242
  };
222
243
 
223
244
  this.getRootDOMNode = function () {
224
- return _reactDom2['default'].findDOMNode(_this2);
245
+ return _reactDom2['default'].findDOMNode(_this3);
225
246
  };
226
247
 
227
248
  this.focus = function () {
@@ -32,10 +32,6 @@ 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
-
39
35
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
40
36
 
41
37
  var DATE_ROW_COLUMN_COUNT = _DateConstants2['default'].DATE_ROW_COLUMN_COUNT,
@@ -151,11 +147,7 @@ var DateTBody = function (_React$Component) {
151
147
  for (jIndex = 0; jIndex < DATE_ROW_COLUMN_COUNT.DATE_COL_COUNT; jIndex++) {
152
148
  var next = null;
153
149
  var last = null;
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
+ current = (0, _util.syncCurrentTime)(dateTable[passed], currentStatus);
159
151
  if (jIndex < DATE_ROW_COLUMN_COUNT.DATE_COL_COUNT - 1) {
160
152
  next = dateTable[passed + 1];
161
153
  }
package/lib/util/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  exports.__esModule = true;
4
- exports.isLeapYear = exports.DATE_FORMATS = exports.getCurrentTime = exports.getCurrentYear = exports.getCurrentMonth = exports.getCurrentDate = undefined;
4
+ exports.isLeapYear = exports.syncCurrentTime = exports.CALENDAR_STATUS = exports.DATE_FORMATS = exports.getCurrentTime = exports.getCurrentYear = exports.getCurrentMonth = exports.getCurrentDate = undefined;
5
5
 
6
6
  var _extends2 = require('babel-runtime/helpers/extends');
7
7
 
@@ -62,6 +62,18 @@ var DATE_FORMATS = exports.DATE_FORMATS = {
62
62
  Germany_Russia_etcAndTime: 'DD.MM.YYYY HH:mm'
63
63
  };
64
64
 
65
+ var CALENDAR_STATUS = exports.CALENDAR_STATUS = {
66
+ SPECIFIC_TIME: 'specific_time',
67
+ CURRENT_TIME: 'current_time'
68
+ };
69
+
70
+ var syncCurrentTime = exports.syncCurrentTime = function syncCurrentTime(date, status) {
71
+ if (status === CALENDAR_STATUS.CURRENT_TIME) {
72
+ return date.hour((0, _dayjs2['default'])().hour()).minute((0, _dayjs2['default'])().minute()).second((0, _dayjs2['default'])().second());
73
+ }
74
+ return date;
75
+ };
76
+
65
77
  var defaultDisabledTime = {
66
78
  disabledHours: function disabledHours() {
67
79
  return [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/seafile-calendar",
3
- "version": "0.0.88899",
3
+ "version": "0.1.1",
4
4
  "description": "React Calendar",
5
5
  "keywords": [
6
6
  "react",
@@ -48,6 +48,7 @@
48
48
  "lint": "rc-tools run lint",
49
49
  "test": "jest",
50
50
  "types": "tslint *.ts{,x} && tsc",
51
+ "prepublishOnly": "npm run compile",
51
52
  "coverage": "jest --coverage"
52
53
  },
53
54
  "jest": {
@@ -68,13 +69,13 @@
68
69
  "devDependencies": {
69
70
  "@types/react": "^16.3.13",
70
71
  "async": "~3.1.0",
72
+ "chokidar": "^4.0.3",
71
73
  "dtslint": "^0.9.0",
72
74
  "enzyme": "^3.3.0",
73
75
  "enzyme-adapter-react-16": "^1.1.1",
74
76
  "enzyme-to-json": "^3.3.1",
75
77
  "jest": "^22.1.4",
76
78
  "mockdate": "^2.0.1",
77
- "pre-commit": "1.x",
78
79
  "rc-dialog": "^7.0.0",
79
80
  "rc-select": "^9.1.5",
80
81
  "rc-time-picker": "^3.1.0",
@@ -85,9 +86,6 @@
85
86
  "tslint": "^5.9.1",
86
87
  "typescript": "^3.4.1"
87
88
  },
88
- "pre-commit": [
89
- "lint"
90
- ],
91
89
  "dependencies": {
92
90
  "babel-runtime": "6.x",
93
91
  "classnames": "2.x",