@seafile/seafile-calendar 0.0.30-beta.3 → 0.0.30-beta.5
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/dist/rc-calendar.js +459 -436
- package/dist/rc-calendar.js.map +1 -1
- package/dist/rc-calendar.min.js +1 -1
- package/es/Calendar.js +3 -14
- package/es/calendar/CalendarRightPanel.js +8 -17
- package/es/date/DateInput.js +33 -267
- package/es/util/index.js +370 -97
- package/lib/Calendar.js +3 -14
- package/lib/calendar/CalendarRightPanel.js +7 -16
- package/lib/date/DateInput.js +33 -266
- package/lib/util/index.js +378 -105
- package/package.json +1 -2
package/es/date/DateInput.js
CHANGED
@@ -7,7 +7,10 @@ import PropTypes from 'prop-types';
|
|
7
7
|
import KeyCode from 'rc-util/es/KeyCode';
|
8
8
|
import { polyfill } from 'react-lifecycles-compat';
|
9
9
|
import dayjs from 'dayjs';
|
10
|
-
import { formatDate,
|
10
|
+
import { formatDate, initializeStr } from '../util';
|
11
|
+
var customParseFormat = require('dayjs/plugin/customParseFormat');
|
12
|
+
|
13
|
+
dayjs.extend(customParseFormat);
|
11
14
|
|
12
15
|
var cachedSelectionStart = void 0;
|
13
16
|
var cachedSelectionEnd = void 0;
|
@@ -24,15 +27,11 @@ var DateInput = function (_React$Component) {
|
|
24
27
|
_initialiseProps.call(_this);
|
25
28
|
|
26
29
|
var selectedValue = props.selectedValue;
|
27
|
-
|
30
|
+
|
28
31
|
_this.state = {
|
29
|
-
timeStr: '',
|
30
|
-
dateStr: '',
|
31
32
|
str: formatDate(selectedValue, _this.props.format),
|
32
33
|
hasFocus: false,
|
33
|
-
|
34
|
-
delimiter: delimate(formatPrefix),
|
35
|
-
cananderIput: ''
|
34
|
+
localFormat: _this.props.format[0]
|
36
35
|
};
|
37
36
|
return _this;
|
38
37
|
}
|
@@ -53,34 +52,9 @@ var DateInput = function (_React$Component) {
|
|
53
52
|
// when popup show, click body will call this, bug!
|
54
53
|
var selectedValue = nextProps.selectedValue;
|
55
54
|
if (!state.hasFocus) {
|
56
|
-
|
57
|
-
var parts = timeStr.split(state.delimiter);
|
58
|
-
var timeParts = formatDate(selectedValue, nextProps.format).split(' ')[1];
|
59
|
-
if (parts.length === 3) {
|
60
|
-
if (state.localeFormat === DATE_FORMATS.ISO) {
|
61
|
-
newState = { str: parts[0].padStart(4, 0) + '-' + parts[1] + '-' + parts[2] };
|
62
|
-
} else if (state.localeFormat === DATE_FORMATS.ISOAndTime) {
|
63
|
-
newState = {
|
64
|
-
str: parts[0].padStart(4, 0) + '-' + parts[1] + '-' + parts[2] + ' ' + (nextProps.showHourAndMinute ? timeParts : ''), // eslint-disable-line max-len
|
65
|
-
dateStr: parts[0].padStart(4, 0) + '-' + parts[1] + '-' + parts[2]
|
66
|
-
};
|
67
|
-
} else if (state.localeFormat === DATE_FORMATS.US) {
|
68
|
-
newState = { str: Number(parts[0]) + '/' + Number(parts[1]) + '/' + parts[2].padStart(4, 0) };
|
69
|
-
} else if (state.localeFormat === DATE_FORMATS.USAndTime) {
|
70
|
-
newState = {
|
71
|
-
str: Number(parts[0]) + '/' + Number(parts[1]) + '/' + parts[2].padStart(4, 0) + ' ' + (nextProps.showHourAndMinute ? timeParts : ''), // eslint-disable-line max-len
|
72
|
-
dateStr: Number(parts[0]) + '/' + Number(parts[1]) + '/' + parts[2].padStart(4, 0)
|
73
|
-
};
|
74
|
-
} else if (state.localeFormat === DATE_FORMATS.European || state.localeFormat === DATE_FORMATS.Germany_Russia_etc) {
|
75
|
-
newState = { str: '' + Number(parts[0]) + state.delimiter + Number(parts[1]) + state.delimiter + parts[2].padStart(4, 0) }; // eslint-disable-line max-len
|
76
|
-
} else if (state.localeFormat === DATE_FORMATS.EuropeanAndTime || state.localeFormat === DATE_FORMATS.Germany_Russia_etcAndTime) {
|
77
|
-
newState = {
|
78
|
-
str: '' + Number(parts[0]) + state.delimiter + Number(parts[1]) + state.delimiter + parts[2].padStart(4, 0) + ' ' + (nextProps.showHourAndMinute ? timeParts : ''), // eslint-disable-line max-len
|
79
|
-
dateStr: '' + Number(parts[0]) + state.delimiter + Number(parts[1]) + state.delimiter + parts[2].padStart(4, 0) // eslint-disable-line max-len
|
80
|
-
};
|
81
|
-
}
|
82
|
-
}
|
55
|
+
newState = { str: formatDate(selectedValue, nextProps.format) };
|
83
56
|
}
|
57
|
+
|
84
58
|
return newState;
|
85
59
|
};
|
86
60
|
|
@@ -88,181 +62,28 @@ var DateInput = function (_React$Component) {
|
|
88
62
|
return dateInputInstance;
|
89
63
|
};
|
90
64
|
|
91
|
-
DateInput.prototype.normalizeDateInput = function normalizeDateInput(str) {
|
92
|
-
var day = void 0;
|
93
|
-
var month = void 0;
|
94
|
-
var year = void 0;
|
95
|
-
var parts = formatDateLocal(str, this.state.localeFormat, DATE_FORMATS);
|
96
|
-
var delimiter = this.state.delimiter;
|
97
|
-
var hasSpecial = hasSpecialChar(str);
|
98
|
-
if (this.state.localeFormat === DATE_FORMATS.ISO || this.state.localeFormat === DATE_FORMATS.ISOAndTime) {
|
99
|
-
var numStr = str.replace(/[^0-9]/g, '');
|
100
|
-
if (numStr.length === 7) {
|
101
|
-
year = numStr.slice(0, 4);
|
102
|
-
month = numStr.slice(4, 6).padStart(2, '0');
|
103
|
-
day = numStr.slice(6, 7).padStart(2, '0');
|
104
|
-
if (!isValidDay(day)) {
|
105
|
-
return year + '-' + stringCurrentMonth + '-' + stringCurrentDate;
|
106
|
-
}
|
107
|
-
return year + '-' + month + '-' + day;
|
108
|
-
}
|
109
|
-
if (hasSpecial) {
|
110
|
-
year = fullValidYear(parts[0]);
|
111
|
-
month = Number(parts[1]);
|
112
|
-
day = Number(parts[2]);
|
113
|
-
if (month >= 1 && month <= 12) {
|
114
|
-
if (isValidDay(day)) {
|
115
|
-
return year + '-' + String(month).padStart(2, '0') + '-' + String(day).padStart(2, '0');
|
116
|
-
}
|
117
|
-
return year + '-' + String(month).padStart(2, '0') + '-01';
|
118
|
-
}
|
119
|
-
if ((month >= 13 || month < 1) && isNaN(day)) {
|
120
|
-
return year + '-' + stringCurrentMonth + '-' + stringCurrentDate;
|
121
|
-
}
|
122
|
-
if (!month && !day) {
|
123
|
-
return year + '-01-01';
|
124
|
-
}
|
125
|
-
}
|
126
|
-
if (str.length >= 1 && str.length <= 8) {
|
127
|
-
year = fullValidYear(str.slice(0, 4));
|
128
|
-
month = str.slice(4, 6);
|
129
|
-
day = Number(str.slice(6, 8));
|
130
|
-
if (str.length === 5 && Number(month) < 1) {
|
131
|
-
return year + '-' + stringCurrentMonth + '-' + stringCurrentDate + ' ';
|
132
|
-
}
|
133
|
-
if (str.length === 6 && Number(month) < 1) {
|
134
|
-
return year + '-' + stringCurrentMonth + '-' + stringCurrentDate;
|
135
|
-
}
|
136
|
-
if (str.length === 7) {
|
137
|
-
if (!isValidDay(day)) {
|
138
|
-
return year + '-' + String(isValidMonth(month)).padStart(2, '0') + '-' + stringCurrentDate;
|
139
|
-
}
|
140
|
-
return year + '-' + String(isValidMonth(month)).padStart(2, '0') + '-' + String(day).padStart(2, '0'); // eslint-disable-line max-len
|
141
|
-
}
|
142
|
-
if (str.length === 8) {
|
143
|
-
if (!isValidDay(day)) {
|
144
|
-
return isCurrentYear(year, month, day) + '-' + String(isValidMonth(month)).padStart(2, '0') + '-' + stringCurrentDate; // eslint-disable-line max-len
|
145
|
-
}
|
146
|
-
return isCurrentYear(year, month, day) + '-' + String(isValidMonth(month)).padStart(2, '0') + '-' + String(day).padStart(2, '0'); // eslint-disable-line max-len
|
147
|
-
}
|
148
|
-
if (Number(month) >= 1 && Number(month) <= 12 && isValidDay(day)) {
|
149
|
-
return year + '-' + month.padStart(2, '0') + '-' + String(day).padStart(2, '0');
|
150
|
-
}
|
151
|
-
return year + '-' + (month ? month.padStart(2, '0') : '01') + '-' + (day ? String(day).padStart(2, '0') : '01'); // eslint-disable-line max-len
|
152
|
-
}
|
153
|
-
return currentYear + '/' + stringCurrentMonth + '/' + stringCurrentDate;
|
154
|
-
}
|
155
|
-
if (this.state.localeFormat === DATE_FORMATS.US || this.state.localeFormat === DATE_FORMATS.USAndTime) {
|
156
|
-
if (hasSpecial) {
|
157
|
-
month = Number(parts[0]);
|
158
|
-
day = Number(parts[1]);
|
159
|
-
year = fullValidYear(parts[2]);
|
160
|
-
if (month >= 1 && month <= 12 && isValidDay(day)) {
|
161
|
-
return month + '/' + day + '/' + year;
|
162
|
-
}
|
163
|
-
return currentMonth + '/' + currentDate + '/' + currentYear;
|
164
|
-
}
|
165
|
-
if (str.length >= 1 && str.length <= 8) {
|
166
|
-
month = Number(str.slice(0, 2));
|
167
|
-
day = Number(str.slice(2, 4));
|
168
|
-
year = fullValidYear(str.slice(4, str.length));
|
169
|
-
if (month >= 1 && month <= 12) {
|
170
|
-
if (isValidDay(day)) {
|
171
|
-
return month + '/' + day + '/' + year;
|
172
|
-
}
|
173
|
-
if (!day) {
|
174
|
-
return month + '/1/' + year;
|
175
|
-
}
|
176
|
-
return currentMonth + '/' + currentDate + '/' + currentYear;
|
177
|
-
}
|
178
|
-
}
|
179
|
-
return currentMonth + '/' + currentDate + '/' + currentYear;
|
180
|
-
}
|
181
|
-
if (this.state.localeFormat === DATE_FORMATS.European || this.state.localeFormat === DATE_FORMATS.EuropeanAndTime || this.state.localeFormat === DATE_FORMATS.Germany_Russia_etcAndTime || this.state.localeFormat === DATE_FORMATS.Germany_Russia_etc) {
|
182
|
-
if (hasSpecial) {
|
183
|
-
day = parts[0];
|
184
|
-
month = parts[1];
|
185
|
-
year = fullValidYear(parts[2]);
|
186
|
-
if (isValidDay(day) && Number(month) >= 1 && Number(month) <= 12) {
|
187
|
-
return '' + Number(day) + delimiter + Number(month) + delimiter + year;
|
188
|
-
}
|
189
|
-
return '' + currentDate + delimiter + currentMonth + delimiter + currentYear;
|
190
|
-
}
|
191
|
-
if (str.length >= 1 && str.length <= 8) {
|
192
|
-
day = Number(str.slice(0, 2));
|
193
|
-
var monthStr = str.slice(2, 4);
|
194
|
-
month = isValidMonth(monthStr);
|
195
|
-
var yearStr = str.slice(4, str.length);
|
196
|
-
year = fullValidYear(yearStr);
|
197
|
-
if (Number(monthStr) >= 1 && Number(monthStr) <= 12 && isValidDay(day)) {
|
198
|
-
return '' + Number(day) + delimiter + Number(month) + delimiter + year;
|
199
|
-
}
|
200
|
-
}
|
201
|
-
return '' + currentDate + delimiter + currentMonth + delimiter + currentYear;
|
202
|
-
}
|
203
|
-
};
|
204
|
-
|
205
65
|
DateInput.prototype.render = function render() {
|
206
66
|
var props = this.props;
|
207
|
-
var
|
208
|
-
str = _state.str,
|
209
|
-
dateStr = _state.dateStr,
|
210
|
-
timeStr = _state.timeStr;
|
67
|
+
var str = this.state.str;
|
211
68
|
var locale = props.locale,
|
212
69
|
prefixCls = props.prefixCls,
|
213
70
|
placeholder = props.placeholder,
|
214
71
|
clearIcon = props.clearIcon,
|
215
|
-
inputMode = props.inputMode
|
216
|
-
showHourAndMinute = props.showHourAndMinute;
|
72
|
+
inputMode = props.inputMode;
|
217
73
|
|
218
74
|
return React.createElement(
|
219
75
|
'div',
|
220
76
|
{ className: prefixCls + '-input-wrap' },
|
221
|
-
|
77
|
+
React.createElement(
|
222
78
|
'div',
|
223
|
-
{ className: prefixCls + '-date-input-wrap'
|
224
|
-
React.createElement(
|
225
|
-
'div',
|
226
|
-
null,
|
227
|
-
React.createElement('input', {
|
228
|
-
ref: this.saveDateInput,
|
229
|
-
className: prefixCls + '-input',
|
230
|
-
value: dateStr,
|
231
|
-
disabled: props.disabled,
|
232
|
-
placeholder: placeholder.slice(0, 10),
|
233
|
-
onChange: this.onInputChangeDate,
|
234
|
-
onKeyDown: this.onKeyDown,
|
235
|
-
onFocus: this.onFocus,
|
236
|
-
onBlur: this.onBlur,
|
237
|
-
inputMode: inputMode
|
238
|
-
})
|
239
|
-
),
|
240
|
-
React.createElement(
|
241
|
-
'div',
|
242
|
-
null,
|
243
|
-
React.createElement('input', {
|
244
|
-
ref: this.saveDateInput,
|
245
|
-
className: prefixCls + '-input',
|
246
|
-
value: timeStr,
|
247
|
-
disabled: props.disabled,
|
248
|
-
placeholder: 'HH:mm',
|
249
|
-
onChange: this.onInputChangeHourMinute,
|
250
|
-
onKeyDown: this.onKeyDown,
|
251
|
-
onFocus: this.onFocus,
|
252
|
-
onBlur: this.TimeBlure,
|
253
|
-
inputMode: inputMode
|
254
|
-
})
|
255
|
-
)
|
256
|
-
) : React.createElement(
|
257
|
-
'div',
|
258
|
-
{ className: prefixCls + '-date-input-wrap', style: { display: 'flex' } },
|
79
|
+
{ className: prefixCls + '-date-input-wrap' },
|
259
80
|
React.createElement('input', {
|
260
81
|
ref: this.saveDateInput,
|
261
82
|
className: prefixCls + '-input',
|
262
83
|
value: str,
|
263
84
|
disabled: props.disabled,
|
264
85
|
placeholder: placeholder,
|
265
|
-
onChange: this.
|
86
|
+
onChange: this.onInputChange,
|
266
87
|
onKeyDown: this.onKeyDown,
|
267
88
|
onFocus: this.onFocus,
|
268
89
|
onBlur: this.onBlur,
|
@@ -298,65 +119,37 @@ DateInput.propTypes = {
|
|
298
119
|
onSelect: PropTypes.func,
|
299
120
|
selectedValue: PropTypes.object,
|
300
121
|
clearIcon: PropTypes.node,
|
301
|
-
inputMode: PropTypes.string
|
302
|
-
showHourAndMinute: PropTypes.bool,
|
303
|
-
onChangeCananderIput: PropTypes.func
|
122
|
+
inputMode: PropTypes.string
|
304
123
|
};
|
305
124
|
|
306
125
|
var _initialiseProps = function _initialiseProps() {
|
307
126
|
var _this2 = this;
|
308
127
|
|
309
128
|
this.onClear = function () {
|
310
|
-
|
311
|
-
|
312
|
-
onClear = _props.onClear;
|
313
|
-
|
314
|
-
if (showHourAndMinute) {
|
315
|
-
_this2.setState({
|
316
|
-
dateStr: '',
|
317
|
-
timeStr: ''
|
318
|
-
});
|
319
|
-
} else {
|
320
|
-
_this2.setState({
|
321
|
-
str: ''
|
322
|
-
});
|
323
|
-
}
|
324
|
-
onClear(null);
|
129
|
+
_this2.setState({ str: '' });
|
130
|
+
_this2.props.onClear(null);
|
325
131
|
};
|
326
132
|
|
327
|
-
this.onInputChange = function (
|
328
|
-
var
|
329
|
-
var
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
_this2.setState({ timeStr: hourMinuteStr });
|
337
|
-
cananderStr = cananderStr + ' ' + hourMinuteStr;
|
133
|
+
this.onInputChange = function (event) {
|
134
|
+
var str = event.target.value;
|
135
|
+
var calendarStr = initializeStr(str, _this2.state.localFormat) || '';
|
136
|
+
var _props = _this2.props,
|
137
|
+
disabledDate = _props.disabledDate,
|
138
|
+
format = _props.format,
|
139
|
+
onChange = _props.onChange,
|
140
|
+
selectedValue = _props.selectedValue;
|
141
|
+
|
338
142
|
// 没有内容,合法并直接退出
|
339
|
-
|
143
|
+
|
144
|
+
if (!calendarStr) {
|
340
145
|
onChange(null);
|
341
|
-
_this2.setState({ str:
|
146
|
+
_this2.setState({ str: '' });
|
342
147
|
return;
|
343
148
|
}
|
344
|
-
|
345
|
-
var format = getDateFormatByStr(cananderStr, _this2.state.localeFormat);
|
346
|
-
var parsed = dayjs(cananderStr, format);
|
149
|
+
var parsed = dayjs(calendarStr, format[0]);
|
347
150
|
var value = _this2.props.value.clone();
|
348
151
|
value = value.year(parsed.year()).month(parsed.month()).date(parsed.date()).hour(parsed.hour()).minute(parsed.minute()).second(parsed.second());
|
349
152
|
|
350
|
-
if (_this2.state.localeFormat === DATE_FORMATS.ISO || _this2.state.localeFormat === DATE_FORMATS.ISOAndTime) {
|
351
|
-
if (parts[0] && parts[0].length === 4 && (parts[0].slice(0, 3) === '000' || parts[0].slice(0, 2) === '00')) {
|
352
|
-
value.year(parts[0]);
|
353
|
-
}
|
354
|
-
}
|
355
|
-
if (_this2.state.localeFormat === DATE_FORMATS.European || _this2.state.localeFormat === DATE_FORMATS.EuropeanAndTime || _this2.state.localeFormat === DATE_FORMATS.US || _this2.state.localeFormat === DATE_FORMATS.USAndTime || _this2.state.localeFormat === DATE_FORMATS.Germany_Russia_etc || _this2.state.localeFormat === DATE_FORMATS.Germany_Russia_etcAndTime) {
|
356
|
-
if (parts[2] && parts[2].length === 4 && (parts[2].slice(0, 3) === '000' || parts[2].slice(0, 2) === '00')) {
|
357
|
-
value.year(parts[2]);
|
358
|
-
}
|
359
|
-
}
|
360
153
|
if (!value || disabledDate && disabledDate(value)) {
|
361
154
|
_this2.setState({ str: str });
|
362
155
|
return;
|
@@ -368,22 +161,6 @@ var _initialiseProps = function _initialiseProps() {
|
|
368
161
|
}
|
369
162
|
};
|
370
163
|
|
371
|
-
this.onInputChangeAll = function (event) {
|
372
|
-
var str = event.target.value;
|
373
|
-
_this2.onInputChange(str);
|
374
|
-
};
|
375
|
-
|
376
|
-
this.onInputChangeDate = function (event) {
|
377
|
-
var dateStr = event.target.value;
|
378
|
-
_this2.setState({ dateStr: dateStr });
|
379
|
-
_this2.onInputChange(dateStr);
|
380
|
-
};
|
381
|
-
|
382
|
-
this.onInputChangeHourMinute = function (e) {
|
383
|
-
var timeStr = e.target.value;
|
384
|
-
_this2.setState({ timeStr: timeStr });
|
385
|
-
};
|
386
|
-
|
387
164
|
this.onFocus = function () {
|
388
165
|
_this2.setState({ hasFocus: true });
|
389
166
|
};
|
@@ -399,10 +176,10 @@ var _initialiseProps = function _initialiseProps() {
|
|
399
176
|
|
400
177
|
this.onKeyDown = function (event) {
|
401
178
|
var keyCode = event.keyCode;
|
402
|
-
var
|
403
|
-
onSelect =
|
404
|
-
value =
|
405
|
-
disabledDate =
|
179
|
+
var _props2 = _this2.props,
|
180
|
+
onSelect = _props2.onSelect,
|
181
|
+
value = _props2.value,
|
182
|
+
disabledDate = _props2.disabledDate;
|
406
183
|
|
407
184
|
if (keyCode === KeyCode.ENTER && onSelect) {
|
408
185
|
var validateDate = !disabledDate || !disabledDate(value);
|
@@ -423,17 +200,6 @@ var _initialiseProps = function _initialiseProps() {
|
|
423
200
|
}
|
424
201
|
};
|
425
202
|
|
426
|
-
this.TimeBlure = function () {
|
427
|
-
var hourMinuteStr = validateTime(_this2.state.timeStr);
|
428
|
-
_this2.setState({ timeStr: hourMinuteStr }, function () {
|
429
|
-
_this2.onInputChange(_this2.state.str);
|
430
|
-
});
|
431
|
-
};
|
432
|
-
|
433
|
-
this.focusTimeInput = function (timeStr) {
|
434
|
-
_this2.setState({ timeStr: timeStr });
|
435
|
-
};
|
436
|
-
|
437
203
|
this.saveDateInput = function (dateInput) {
|
438
204
|
dateInputInstance = dateInput;
|
439
205
|
};
|