@seafile/seafile-calendar 0.0.31 → 0.0.32-alpha.0
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/assets/index.css +11 -12
- package/dist/rc-calendar.css +11 -12
- package/dist/rc-calendar.css.map +1 -1
- package/dist/rc-calendar.js +108 -72
- package/dist/rc-calendar.js.map +1 -1
- package/dist/rc-calendar.min.css +11 -12
- package/dist/rc-calendar.min.css.map +1 -1
- package/dist/rc-calendar.min.js +1 -1
- package/es/Calendar.js +12 -6
- package/es/date/DateInput.js +51 -37
- package/es/date/DateTBody.js +6 -4
- package/es/util/index.js +14 -2
- package/lib/Calendar.js +11 -5
- package/lib/date/DateInput.js +50 -37
- package/lib/date/DateTBody.js +5 -3
- package/lib/util/index.js +15 -3
- package/package.json +2 -5
package/es/date/DateInput.js
CHANGED
|
@@ -8,14 +8,11 @@ import KeyCode from 'rc-util/es/KeyCode';
|
|
|
8
8
|
import { polyfill } from 'react-lifecycles-compat';
|
|
9
9
|
import dayjs from 'dayjs';
|
|
10
10
|
import { formatDate, initializeStr } from '../util';
|
|
11
|
+
|
|
11
12
|
var customParseFormat = require('dayjs/plugin/customParseFormat');
|
|
12
13
|
|
|
13
14
|
dayjs.extend(customParseFormat);
|
|
14
15
|
|
|
15
|
-
var cachedSelectionStart = void 0;
|
|
16
|
-
var cachedSelectionEnd = void 0;
|
|
17
|
-
var dateInputInstance = void 0;
|
|
18
|
-
|
|
19
16
|
var DateInput = function (_React$Component) {
|
|
20
17
|
_inherits(DateInput, _React$Component);
|
|
21
18
|
|
|
@@ -31,23 +28,35 @@ var DateInput = function (_React$Component) {
|
|
|
31
28
|
_this.state = {
|
|
32
29
|
str: formatDate(selectedValue, _this.props.format),
|
|
33
30
|
hasFocus: false,
|
|
31
|
+
isInputEmpty: false,
|
|
34
32
|
localFormat: _this.props.format[0]
|
|
35
33
|
};
|
|
34
|
+
_this.dateInputInstance = React.createRef();
|
|
35
|
+
_this.cachedSelectionStart = null;
|
|
36
|
+
_this.cachedSelectionEnd = null;
|
|
36
37
|
return _this;
|
|
37
38
|
}
|
|
38
39
|
|
|
40
|
+
DateInput.prototype.componentDidMount = function componentDidMount() {
|
|
41
|
+
var _this2 = this;
|
|
42
|
+
|
|
43
|
+
setTimeout(function () {
|
|
44
|
+
_this2.focus();
|
|
45
|
+
}, 1);
|
|
46
|
+
};
|
|
47
|
+
|
|
39
48
|
DateInput.prototype.componentDidUpdate = function componentDidUpdate() {
|
|
40
|
-
if (dateInputInstance && this.state.hasFocus && !(cachedSelectionStart === 0 && cachedSelectionEnd === 0)) {
|
|
41
|
-
dateInputInstance.setSelectionRange(cachedSelectionStart, cachedSelectionEnd);
|
|
49
|
+
if (this.dateInputInstance.current && this.state.hasFocus && !(this.cachedSelectionStart === 0 && this.cachedSelectionEnd === 0)) {
|
|
50
|
+
this.dateInputInstance.current.setSelectionRange(this.cachedSelectionStart, this.cachedSelectionEnd);
|
|
42
51
|
}
|
|
43
52
|
};
|
|
44
53
|
|
|
45
54
|
DateInput.getDerivedStateFromProps = function getDerivedStateFromProps(nextProps, state) {
|
|
46
55
|
var newState = {};
|
|
47
56
|
|
|
48
|
-
if (dateInputInstance) {
|
|
49
|
-
cachedSelectionStart = dateInputInstance.selectionStart;
|
|
50
|
-
cachedSelectionEnd = dateInputInstance.selectionEnd;
|
|
57
|
+
if (this.dateInputInstance.current) {
|
|
58
|
+
this.cachedSelectionStart = this.dateInputInstance.current.selectionStart;
|
|
59
|
+
this.cachedSelectionEnd = this.dateInputInstance.current.selectionEnd;
|
|
51
60
|
}
|
|
52
61
|
// when popup show, click body will call this, bug!
|
|
53
62
|
var selectedValue = nextProps.selectedValue;
|
|
@@ -59,7 +68,7 @@ var DateInput = function (_React$Component) {
|
|
|
59
68
|
};
|
|
60
69
|
|
|
61
70
|
DateInput.getInstance = function getInstance() {
|
|
62
|
-
return dateInputInstance;
|
|
71
|
+
return this.dateInputInstance.current;
|
|
63
72
|
};
|
|
64
73
|
|
|
65
74
|
DateInput.prototype.render = function render() {
|
|
@@ -78,7 +87,7 @@ var DateInput = function (_React$Component) {
|
|
|
78
87
|
'div',
|
|
79
88
|
{ className: prefixCls + '-date-input-wrap' },
|
|
80
89
|
React.createElement('input', {
|
|
81
|
-
ref: this.
|
|
90
|
+
ref: this.dateInputInstance,
|
|
82
91
|
className: prefixCls + '-input',
|
|
83
92
|
value: str,
|
|
84
93
|
disabled: props.disabled,
|
|
@@ -87,10 +96,11 @@ var DateInput = function (_React$Component) {
|
|
|
87
96
|
onKeyDown: this.onKeyDown,
|
|
88
97
|
onFocus: this.onFocus,
|
|
89
98
|
onBlur: this.onBlur,
|
|
90
|
-
inputMode: inputMode
|
|
99
|
+
inputMode: inputMode,
|
|
100
|
+
tabIndex: '0'
|
|
91
101
|
})
|
|
92
102
|
),
|
|
93
|
-
props.showClear
|
|
103
|
+
props.showClear && React.createElement(
|
|
94
104
|
'a',
|
|
95
105
|
{
|
|
96
106
|
role: 'button',
|
|
@@ -98,7 +108,7 @@ var DateInput = function (_React$Component) {
|
|
|
98
108
|
onClick: this.onClear
|
|
99
109
|
},
|
|
100
110
|
clearIcon || React.createElement('span', { className: prefixCls + '-clear-btn' })
|
|
101
|
-
)
|
|
111
|
+
)
|
|
102
112
|
);
|
|
103
113
|
};
|
|
104
114
|
|
|
@@ -123,50 +133,54 @@ DateInput.propTypes = {
|
|
|
123
133
|
};
|
|
124
134
|
|
|
125
135
|
var _initialiseProps = function _initialiseProps() {
|
|
126
|
-
var
|
|
136
|
+
var _this3 = this;
|
|
127
137
|
|
|
128
138
|
this.onClear = function () {
|
|
129
|
-
|
|
130
|
-
|
|
139
|
+
_this3.setState({ str: '' });
|
|
140
|
+
_this3.props.onClear(null);
|
|
131
141
|
};
|
|
132
142
|
|
|
133
143
|
this.onInputChange = function (event) {
|
|
134
144
|
var str = event.target.value;
|
|
135
|
-
var calendarStr = initializeStr(str,
|
|
136
|
-
var _props =
|
|
145
|
+
var calendarStr = initializeStr(str, _this3.state.localFormat) || '';
|
|
146
|
+
var _props = _this3.props,
|
|
137
147
|
disabledDate = _props.disabledDate,
|
|
138
148
|
format = _props.format,
|
|
139
149
|
onChange = _props.onChange,
|
|
140
150
|
selectedValue = _props.selectedValue;
|
|
141
151
|
|
|
142
|
-
// 没有内容,合法并直接退出
|
|
143
152
|
|
|
144
|
-
if (!calendarStr) {
|
|
145
|
-
|
|
146
|
-
|
|
153
|
+
if (!str || !calendarStr) {
|
|
154
|
+
_this3.setState({ isInputEmpty: true });
|
|
155
|
+
_this3.onClear();
|
|
147
156
|
return;
|
|
148
157
|
}
|
|
158
|
+
|
|
159
|
+
if (_this3.state.isInputEmpty) {
|
|
160
|
+
_this3.setState({ isInputEmpty: false });
|
|
161
|
+
}
|
|
162
|
+
|
|
149
163
|
var parsed = dayjs(calendarStr, format[0]);
|
|
150
|
-
var value =
|
|
164
|
+
var value = _this3.props.value.clone();
|
|
151
165
|
value = value.year(parsed.year()).month(parsed.month()).date(parsed.date()).hour(parsed.hour()).minute(parsed.minute()).second(parsed.second());
|
|
152
166
|
|
|
153
167
|
if (!value || disabledDate && disabledDate(value)) {
|
|
154
|
-
|
|
168
|
+
_this3.setState({ str: str });
|
|
155
169
|
return;
|
|
156
170
|
}
|
|
157
171
|
|
|
158
172
|
if (selectedValue !== value || selectedValue && value && !selectedValue.isSame(value)) {
|
|
159
|
-
|
|
173
|
+
_this3.setState({ str: str });
|
|
160
174
|
onChange(value);
|
|
161
175
|
}
|
|
162
176
|
};
|
|
163
177
|
|
|
164
178
|
this.onFocus = function () {
|
|
165
|
-
|
|
179
|
+
_this3.setState({ hasFocus: true });
|
|
166
180
|
};
|
|
167
181
|
|
|
168
182
|
this.onBlur = function () {
|
|
169
|
-
|
|
183
|
+
_this3.setState(function (prevState, prevProps) {
|
|
170
184
|
return {
|
|
171
185
|
hasFocus: false,
|
|
172
186
|
str: formatDate(prevProps.value, prevProps.format)
|
|
@@ -176,7 +190,7 @@ var _initialiseProps = function _initialiseProps() {
|
|
|
176
190
|
|
|
177
191
|
this.onKeyDown = function (event) {
|
|
178
192
|
var keyCode = event.keyCode;
|
|
179
|
-
var _props2 =
|
|
193
|
+
var _props2 = _this3.props,
|
|
180
194
|
onSelect = _props2.onSelect,
|
|
181
195
|
value = _props2.value,
|
|
182
196
|
disabledDate = _props2.disabledDate;
|
|
@@ -184,25 +198,25 @@ var _initialiseProps = function _initialiseProps() {
|
|
|
184
198
|
if (keyCode === KeyCode.ENTER && onSelect) {
|
|
185
199
|
var validateDate = !disabledDate || !disabledDate(value);
|
|
186
200
|
if (validateDate) {
|
|
187
|
-
|
|
201
|
+
if (_this3.state.isInputEmpty) {
|
|
202
|
+
onSelect(null);
|
|
203
|
+
} else {
|
|
204
|
+
onSelect(value.clone());
|
|
205
|
+
}
|
|
188
206
|
}
|
|
189
207
|
event.preventDefault();
|
|
190
208
|
}
|
|
191
209
|
};
|
|
192
210
|
|
|
193
211
|
this.getRootDOMNode = function () {
|
|
194
|
-
return ReactDOM.findDOMNode(
|
|
212
|
+
return ReactDOM.findDOMNode(_this3);
|
|
195
213
|
};
|
|
196
214
|
|
|
197
215
|
this.focus = function () {
|
|
198
|
-
if (dateInputInstance) {
|
|
199
|
-
dateInputInstance.focus();
|
|
216
|
+
if (_this3.dateInputInstance.current) {
|
|
217
|
+
_this3.dateInputInstance.current.focus();
|
|
200
218
|
}
|
|
201
219
|
};
|
|
202
|
-
|
|
203
|
-
this.saveDateInput = function (dateInput) {
|
|
204
|
-
dateInputInstance = dateInput;
|
|
205
|
-
};
|
|
206
220
|
};
|
|
207
221
|
|
|
208
222
|
polyfill(DateInput);
|
package/es/date/DateTBody.js
CHANGED
|
@@ -5,7 +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/';
|
|
8
|
+
import { getTitleString, getTodayTime, syncCurrentTime } from '../util/';
|
|
9
9
|
|
|
10
10
|
var DATE_ROW_COLUMN_COUNT = DateConstants.DATE_ROW_COLUMN_COUNT,
|
|
11
11
|
DAY_NAME_TO_INDEX = DateConstants.DAY_NAME_TO_INDEX;
|
|
@@ -52,7 +52,8 @@ var DateTBody = function (_React$Component) {
|
|
|
52
52
|
dateRender = props.dateRender,
|
|
53
53
|
disabledDate = props.disabledDate,
|
|
54
54
|
hoverValue = props.hoverValue,
|
|
55
|
-
firstDayOfWeek = props.firstDayOfWeek
|
|
55
|
+
firstDayOfWeek = props.firstDayOfWeek,
|
|
56
|
+
currentStatus = props.currentStatus;
|
|
56
57
|
|
|
57
58
|
var iIndex = void 0;
|
|
58
59
|
var jIndex = void 0;
|
|
@@ -120,7 +121,7 @@ var DateTBody = function (_React$Component) {
|
|
|
120
121
|
for (jIndex = 0; jIndex < DATE_ROW_COLUMN_COUNT.DATE_COL_COUNT; jIndex++) {
|
|
121
122
|
var next = null;
|
|
122
123
|
var last = null;
|
|
123
|
-
current = dateTable[passed];
|
|
124
|
+
current = syncCurrentTime(dateTable[passed], currentStatus);
|
|
124
125
|
if (jIndex < DATE_ROW_COLUMN_COUNT.DATE_COL_COUNT - 1) {
|
|
125
126
|
next = dateTable[passed + 1];
|
|
126
127
|
}
|
|
@@ -272,7 +273,8 @@ DateTBody.propTypes = {
|
|
|
272
273
|
value: PropTypes.object,
|
|
273
274
|
hoverValue: PropTypes.any,
|
|
274
275
|
showWeekNumber: PropTypes.bool,
|
|
275
|
-
firstDayOfWeek: PropTypes.string
|
|
276
|
+
firstDayOfWeek: PropTypes.string,
|
|
277
|
+
currentStatus: PropTypes.string
|
|
276
278
|
};
|
|
277
279
|
DateTBody.defaultProps = {
|
|
278
280
|
hoverValue: []
|
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 [];
|
|
@@ -478,7 +490,7 @@ export function initializeStr(str, format) {
|
|
|
478
490
|
return '' + _day10 + dateDelimater + _month10 + dateDelimater + _year10;
|
|
479
491
|
} else if (inputStrLength >= 1 && inputStrLength <= 8) {
|
|
480
492
|
var _dateStr6 = inputStr.slice(0, 2);
|
|
481
|
-
var _monthStr6 = inputStr.slice(2, 4);
|
|
493
|
+
var _monthStr6 = inputStr.slice(2, 4) || getCurrentMonth();
|
|
482
494
|
var _yearStr6 = inputStr.slice(4, inputStr.length);
|
|
483
495
|
var _validateYear11 = validateCalendarYear(_yearStr6);
|
|
484
496
|
|
|
@@ -522,7 +534,7 @@ export function initializeStr(str, format) {
|
|
|
522
534
|
return '' + _day12 + dateDelimater + _month12 + dateDelimater + _year12 + ' ' + time;
|
|
523
535
|
} else if (_datePart2.length >= 1 && _datePart2.length <= 8) {
|
|
524
536
|
var _dateStr7 = _datePart2.slice(0, 2);
|
|
525
|
-
var _monthStr7 = _datePart2.slice(2, 4);
|
|
537
|
+
var _monthStr7 = _datePart2.slice(2, 4) || getCurrentMonth();
|
|
526
538
|
var _yearStr7 = _datePart2.slice(4, _datePart2.length);
|
|
527
539
|
var _timeParts2 = tokenizeFormattedDate(inputStr, format);
|
|
528
540
|
time = validateTime(_timeParts2[1] + ':' + _timeParts2[2]);
|
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: _util.CALENDAR_STATUS.SPECIFIC_TIME
|
|
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:
|
|
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:
|
|
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: _util.CALENDAR_STATUS.CURRENT_TIME });
|
|
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: _util.CALENDAR_STATUS.SPECIFIC_TIME });
|
|
452
458
|
if (!selectedValue && timePicker) {
|
|
453
459
|
var timePickerDefaultValue = timePicker.props.defaultValue;
|
|
454
460
|
if (timePickerDefaultValue) {
|
package/lib/date/DateInput.js
CHANGED
|
@@ -44,10 +44,6 @@ var customParseFormat = require('dayjs/plugin/customParseFormat');
|
|
|
44
44
|
|
|
45
45
|
_dayjs2['default'].extend(customParseFormat);
|
|
46
46
|
|
|
47
|
-
var cachedSelectionStart = void 0;
|
|
48
|
-
var cachedSelectionEnd = void 0;
|
|
49
|
-
var dateInputInstance = void 0;
|
|
50
|
-
|
|
51
47
|
var DateInput = function (_React$Component) {
|
|
52
48
|
(0, _inherits3['default'])(DateInput, _React$Component);
|
|
53
49
|
|
|
@@ -63,23 +59,35 @@ var DateInput = function (_React$Component) {
|
|
|
63
59
|
_this.state = {
|
|
64
60
|
str: (0, _util.formatDate)(selectedValue, _this.props.format),
|
|
65
61
|
hasFocus: false,
|
|
62
|
+
isInputEmpty: false,
|
|
66
63
|
localFormat: _this.props.format[0]
|
|
67
64
|
};
|
|
65
|
+
_this.dateInputInstance = _react2['default'].createRef();
|
|
66
|
+
_this.cachedSelectionStart = null;
|
|
67
|
+
_this.cachedSelectionEnd = null;
|
|
68
68
|
return _this;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
DateInput.prototype.componentDidMount = function componentDidMount() {
|
|
72
|
+
var _this2 = this;
|
|
73
|
+
|
|
74
|
+
setTimeout(function () {
|
|
75
|
+
_this2.focus();
|
|
76
|
+
}, 1);
|
|
77
|
+
};
|
|
78
|
+
|
|
71
79
|
DateInput.prototype.componentDidUpdate = function componentDidUpdate() {
|
|
72
|
-
if (dateInputInstance && this.state.hasFocus && !(cachedSelectionStart === 0 && cachedSelectionEnd === 0)) {
|
|
73
|
-
dateInputInstance.setSelectionRange(cachedSelectionStart, cachedSelectionEnd);
|
|
80
|
+
if (this.dateInputInstance.current && this.state.hasFocus && !(this.cachedSelectionStart === 0 && this.cachedSelectionEnd === 0)) {
|
|
81
|
+
this.dateInputInstance.current.setSelectionRange(this.cachedSelectionStart, this.cachedSelectionEnd);
|
|
74
82
|
}
|
|
75
83
|
};
|
|
76
84
|
|
|
77
85
|
DateInput.getDerivedStateFromProps = function getDerivedStateFromProps(nextProps, state) {
|
|
78
86
|
var newState = {};
|
|
79
87
|
|
|
80
|
-
if (dateInputInstance) {
|
|
81
|
-
cachedSelectionStart = dateInputInstance.selectionStart;
|
|
82
|
-
cachedSelectionEnd = dateInputInstance.selectionEnd;
|
|
88
|
+
if (this.dateInputInstance.current) {
|
|
89
|
+
this.cachedSelectionStart = this.dateInputInstance.current.selectionStart;
|
|
90
|
+
this.cachedSelectionEnd = this.dateInputInstance.current.selectionEnd;
|
|
83
91
|
}
|
|
84
92
|
// when popup show, click body will call this, bug!
|
|
85
93
|
var selectedValue = nextProps.selectedValue;
|
|
@@ -91,7 +99,7 @@ var DateInput = function (_React$Component) {
|
|
|
91
99
|
};
|
|
92
100
|
|
|
93
101
|
DateInput.getInstance = function getInstance() {
|
|
94
|
-
return dateInputInstance;
|
|
102
|
+
return this.dateInputInstance.current;
|
|
95
103
|
};
|
|
96
104
|
|
|
97
105
|
DateInput.prototype.render = function render() {
|
|
@@ -110,7 +118,7 @@ var DateInput = function (_React$Component) {
|
|
|
110
118
|
'div',
|
|
111
119
|
{ className: prefixCls + '-date-input-wrap' },
|
|
112
120
|
_react2['default'].createElement('input', {
|
|
113
|
-
ref: this.
|
|
121
|
+
ref: this.dateInputInstance,
|
|
114
122
|
className: prefixCls + '-input',
|
|
115
123
|
value: str,
|
|
116
124
|
disabled: props.disabled,
|
|
@@ -119,10 +127,11 @@ var DateInput = function (_React$Component) {
|
|
|
119
127
|
onKeyDown: this.onKeyDown,
|
|
120
128
|
onFocus: this.onFocus,
|
|
121
129
|
onBlur: this.onBlur,
|
|
122
|
-
inputMode: inputMode
|
|
130
|
+
inputMode: inputMode,
|
|
131
|
+
tabIndex: '0'
|
|
123
132
|
})
|
|
124
133
|
),
|
|
125
|
-
props.showClear
|
|
134
|
+
props.showClear && _react2['default'].createElement(
|
|
126
135
|
'a',
|
|
127
136
|
{
|
|
128
137
|
role: 'button',
|
|
@@ -130,7 +139,7 @@ var DateInput = function (_React$Component) {
|
|
|
130
139
|
onClick: this.onClear
|
|
131
140
|
},
|
|
132
141
|
clearIcon || _react2['default'].createElement('span', { className: prefixCls + '-clear-btn' })
|
|
133
|
-
)
|
|
142
|
+
)
|
|
134
143
|
);
|
|
135
144
|
};
|
|
136
145
|
|
|
@@ -155,50 +164,54 @@ DateInput.propTypes = {
|
|
|
155
164
|
};
|
|
156
165
|
|
|
157
166
|
var _initialiseProps = function _initialiseProps() {
|
|
158
|
-
var
|
|
167
|
+
var _this3 = this;
|
|
159
168
|
|
|
160
169
|
this.onClear = function () {
|
|
161
|
-
|
|
162
|
-
|
|
170
|
+
_this3.setState({ str: '' });
|
|
171
|
+
_this3.props.onClear(null);
|
|
163
172
|
};
|
|
164
173
|
|
|
165
174
|
this.onInputChange = function (event) {
|
|
166
175
|
var str = event.target.value;
|
|
167
|
-
var calendarStr = (0, _util.initializeStr)(str,
|
|
168
|
-
var _props =
|
|
176
|
+
var calendarStr = (0, _util.initializeStr)(str, _this3.state.localFormat) || '';
|
|
177
|
+
var _props = _this3.props,
|
|
169
178
|
disabledDate = _props.disabledDate,
|
|
170
179
|
format = _props.format,
|
|
171
180
|
onChange = _props.onChange,
|
|
172
181
|
selectedValue = _props.selectedValue;
|
|
173
182
|
|
|
174
|
-
// 没有内容,合法并直接退出
|
|
175
183
|
|
|
176
|
-
if (!calendarStr) {
|
|
177
|
-
|
|
178
|
-
|
|
184
|
+
if (!str || !calendarStr) {
|
|
185
|
+
_this3.setState({ isInputEmpty: true });
|
|
186
|
+
_this3.onClear();
|
|
179
187
|
return;
|
|
180
188
|
}
|
|
189
|
+
|
|
190
|
+
if (_this3.state.isInputEmpty) {
|
|
191
|
+
_this3.setState({ isInputEmpty: false });
|
|
192
|
+
}
|
|
193
|
+
|
|
181
194
|
var parsed = (0, _dayjs2['default'])(calendarStr, format[0]);
|
|
182
|
-
var value =
|
|
195
|
+
var value = _this3.props.value.clone();
|
|
183
196
|
value = value.year(parsed.year()).month(parsed.month()).date(parsed.date()).hour(parsed.hour()).minute(parsed.minute()).second(parsed.second());
|
|
184
197
|
|
|
185
198
|
if (!value || disabledDate && disabledDate(value)) {
|
|
186
|
-
|
|
199
|
+
_this3.setState({ str: str });
|
|
187
200
|
return;
|
|
188
201
|
}
|
|
189
202
|
|
|
190
203
|
if (selectedValue !== value || selectedValue && value && !selectedValue.isSame(value)) {
|
|
191
|
-
|
|
204
|
+
_this3.setState({ str: str });
|
|
192
205
|
onChange(value);
|
|
193
206
|
}
|
|
194
207
|
};
|
|
195
208
|
|
|
196
209
|
this.onFocus = function () {
|
|
197
|
-
|
|
210
|
+
_this3.setState({ hasFocus: true });
|
|
198
211
|
};
|
|
199
212
|
|
|
200
213
|
this.onBlur = function () {
|
|
201
|
-
|
|
214
|
+
_this3.setState(function (prevState, prevProps) {
|
|
202
215
|
return {
|
|
203
216
|
hasFocus: false,
|
|
204
217
|
str: (0, _util.formatDate)(prevProps.value, prevProps.format)
|
|
@@ -208,7 +221,7 @@ var _initialiseProps = function _initialiseProps() {
|
|
|
208
221
|
|
|
209
222
|
this.onKeyDown = function (event) {
|
|
210
223
|
var keyCode = event.keyCode;
|
|
211
|
-
var _props2 =
|
|
224
|
+
var _props2 = _this3.props,
|
|
212
225
|
onSelect = _props2.onSelect,
|
|
213
226
|
value = _props2.value,
|
|
214
227
|
disabledDate = _props2.disabledDate;
|
|
@@ -216,25 +229,25 @@ var _initialiseProps = function _initialiseProps() {
|
|
|
216
229
|
if (keyCode === _KeyCode2['default'].ENTER && onSelect) {
|
|
217
230
|
var validateDate = !disabledDate || !disabledDate(value);
|
|
218
231
|
if (validateDate) {
|
|
219
|
-
|
|
232
|
+
if (_this3.state.isInputEmpty) {
|
|
233
|
+
onSelect(null);
|
|
234
|
+
} else {
|
|
235
|
+
onSelect(value.clone());
|
|
236
|
+
}
|
|
220
237
|
}
|
|
221
238
|
event.preventDefault();
|
|
222
239
|
}
|
|
223
240
|
};
|
|
224
241
|
|
|
225
242
|
this.getRootDOMNode = function () {
|
|
226
|
-
return _reactDom2['default'].findDOMNode(
|
|
243
|
+
return _reactDom2['default'].findDOMNode(_this3);
|
|
227
244
|
};
|
|
228
245
|
|
|
229
246
|
this.focus = function () {
|
|
230
|
-
if (dateInputInstance) {
|
|
231
|
-
dateInputInstance.focus();
|
|
247
|
+
if (_this3.dateInputInstance.current) {
|
|
248
|
+
_this3.dateInputInstance.current.focus();
|
|
232
249
|
}
|
|
233
250
|
};
|
|
234
|
-
|
|
235
|
-
this.saveDateInput = function (dateInput) {
|
|
236
|
-
dateInputInstance = dateInput;
|
|
237
|
-
};
|
|
238
251
|
};
|
|
239
252
|
|
|
240
253
|
(0, _reactLifecyclesCompat.polyfill)(DateInput);
|
package/lib/date/DateTBody.js
CHANGED
|
@@ -78,7 +78,8 @@ var DateTBody = function (_React$Component) {
|
|
|
78
78
|
dateRender = props.dateRender,
|
|
79
79
|
disabledDate = props.disabledDate,
|
|
80
80
|
hoverValue = props.hoverValue,
|
|
81
|
-
firstDayOfWeek = props.firstDayOfWeek
|
|
81
|
+
firstDayOfWeek = props.firstDayOfWeek,
|
|
82
|
+
currentStatus = props.currentStatus;
|
|
82
83
|
|
|
83
84
|
var iIndex = void 0;
|
|
84
85
|
var jIndex = void 0;
|
|
@@ -146,7 +147,7 @@ var DateTBody = function (_React$Component) {
|
|
|
146
147
|
for (jIndex = 0; jIndex < DATE_ROW_COLUMN_COUNT.DATE_COL_COUNT; jIndex++) {
|
|
147
148
|
var next = null;
|
|
148
149
|
var last = null;
|
|
149
|
-
current = dateTable[passed];
|
|
150
|
+
current = (0, _util.syncCurrentTime)(dateTable[passed], currentStatus);
|
|
150
151
|
if (jIndex < DATE_ROW_COLUMN_COUNT.DATE_COL_COUNT - 1) {
|
|
151
152
|
next = dateTable[passed + 1];
|
|
152
153
|
}
|
|
@@ -298,7 +299,8 @@ DateTBody.propTypes = {
|
|
|
298
299
|
value: _propTypes2['default'].object,
|
|
299
300
|
hoverValue: _propTypes2['default'].any,
|
|
300
301
|
showWeekNumber: _propTypes2['default'].bool,
|
|
301
|
-
firstDayOfWeek: _propTypes2['default'].string
|
|
302
|
+
firstDayOfWeek: _propTypes2['default'].string,
|
|
303
|
+
currentStatus: _propTypes2['default'].string
|
|
302
304
|
};
|
|
303
305
|
DateTBody.defaultProps = {
|
|
304
306
|
hoverValue: []
|
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 [];
|
|
@@ -513,7 +525,7 @@ function initializeStr(str, format) {
|
|
|
513
525
|
return '' + _day10 + dateDelimater + _month10 + dateDelimater + _year10;
|
|
514
526
|
} else if (inputStrLength >= 1 && inputStrLength <= 8) {
|
|
515
527
|
var _dateStr6 = inputStr.slice(0, 2);
|
|
516
|
-
var _monthStr6 = inputStr.slice(2, 4);
|
|
528
|
+
var _monthStr6 = inputStr.slice(2, 4) || getCurrentMonth();
|
|
517
529
|
var _yearStr6 = inputStr.slice(4, inputStr.length);
|
|
518
530
|
var _validateYear11 = validateCalendarYear(_yearStr6);
|
|
519
531
|
|
|
@@ -557,7 +569,7 @@ function initializeStr(str, format) {
|
|
|
557
569
|
return '' + _day12 + dateDelimater + _month12 + dateDelimater + _year12 + ' ' + time;
|
|
558
570
|
} else if (_datePart2.length >= 1 && _datePart2.length <= 8) {
|
|
559
571
|
var _dateStr7 = _datePart2.slice(0, 2);
|
|
560
|
-
var _monthStr7 = _datePart2.slice(2, 4);
|
|
572
|
+
var _monthStr7 = _datePart2.slice(2, 4) || getCurrentMonth();
|
|
561
573
|
var _yearStr7 = _datePart2.slice(4, _datePart2.length);
|
|
562
574
|
var _timeParts2 = tokenizeFormattedDate(inputStr, format);
|
|
563
575
|
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.
|
|
3
|
+
"version": "0.0.32-alpha.0",
|
|
4
4
|
"description": "React Calendar",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -68,13 +68,13 @@
|
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"@types/react": "^16.3.13",
|
|
70
70
|
"async": "~3.1.0",
|
|
71
|
+
"chokidar": "^4.0.3",
|
|
71
72
|
"dtslint": "^0.9.0",
|
|
72
73
|
"enzyme": "^3.3.0",
|
|
73
74
|
"enzyme-adapter-react-16": "^1.1.1",
|
|
74
75
|
"enzyme-to-json": "^3.3.1",
|
|
75
76
|
"jest": "^22.1.4",
|
|
76
77
|
"mockdate": "^2.0.1",
|
|
77
|
-
"pre-commit": "1.x",
|
|
78
78
|
"rc-dialog": "^7.0.0",
|
|
79
79
|
"rc-select": "^9.1.5",
|
|
80
80
|
"rc-time-picker": "^3.1.0",
|
|
@@ -85,9 +85,6 @@
|
|
|
85
85
|
"tslint": "^5.9.1",
|
|
86
86
|
"typescript": "^3.4.1"
|
|
87
87
|
},
|
|
88
|
-
"pre-commit": [
|
|
89
|
-
"lint"
|
|
90
|
-
],
|
|
91
88
|
"dependencies": {
|
|
92
89
|
"babel-runtime": "6.x",
|
|
93
90
|
"classnames": "2.x",
|