@seafile/seafile-calendar 0.0.29-alpha.4 → 0.0.29-alpha12
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.css +1179 -0
- package/dist/rc-calendar.css.map +1 -0
- package/dist/rc-calendar.js +7588 -0
- package/dist/rc-calendar.js.map +1 -0
- package/dist/rc-calendar.min.css +1179 -0
- package/dist/rc-calendar.min.css.map +1 -0
- package/dist/rc-calendar.min.js +1 -0
- package/es/Calendar.js +8 -4
- package/es/Picker.js +1 -0
- package/es/calendar/CalendarRightPanel.js +17 -3
- package/es/date/DateInput.js +59 -43
- package/es/date/DateTHead.js +3 -2
- package/es/util/index.js +459 -0
- package/lib/Calendar.js +8 -4
- package/lib/Picker.js +1 -0
- package/lib/calendar/CalendarRightPanel.js +18 -3
- package/lib/date/DateInput.js +58 -42
- package/lib/date/DateTHead.js +3 -2
- package/lib/util/index.js +471 -0
- package/package.json +1 -1
package/lib/Calendar.js
CHANGED
@@ -186,7 +186,7 @@ var Calendar = function (_React$Component) {
|
|
186
186
|
key: 'date-input',
|
187
187
|
value: value,
|
188
188
|
locale: locale,
|
189
|
-
placeholder: dateInputPlaceholder,
|
189
|
+
placeholder: dateInputPlaceholder || this.getFormat()[0],
|
190
190
|
showClear: true,
|
191
191
|
disabledTime: disabledTime,
|
192
192
|
disabledDate: disabledDate,
|
@@ -196,7 +196,8 @@ var Calendar = function (_React$Component) {
|
|
196
196
|
onChange: this.onDateInputChange,
|
197
197
|
onSelect: this.onDateInputSelect,
|
198
198
|
clearIcon: clearIcon,
|
199
|
-
inputMode: inputMode
|
199
|
+
inputMode: inputMode,
|
200
|
+
showHourAndMinute: showHourAndMinute
|
200
201
|
}) : null;
|
201
202
|
|
202
203
|
var children = [];
|
@@ -278,7 +279,9 @@ var Calendar = function (_React$Component) {
|
|
278
279
|
locale: locale,
|
279
280
|
onSelect: this.onDateTableSelect,
|
280
281
|
onClickRightPanelTime: onClickRightPanelTime,
|
281
|
-
defaultMinutesTime: this.props.defaultMinutesTime
|
282
|
+
defaultMinutesTime: this.props.defaultMinutesTime,
|
283
|
+
showHourAndMinute: showHourAndMinute,
|
284
|
+
format: this.getFormat()
|
282
285
|
})
|
283
286
|
)
|
284
287
|
));
|
@@ -325,7 +328,8 @@ Calendar.propTypes = (0, _extends3['default'])({}, _CalendarMixin.calendarMixinP
|
|
325
328
|
focusablePanel: _propTypes2['default'].bool,
|
326
329
|
inputMode: _propTypes2['default'].string,
|
327
330
|
onBlur: _propTypes2['default'].func,
|
328
|
-
onClickRightPanelTime: _propTypes2['default'].func
|
331
|
+
onClickRightPanelTime: _propTypes2['default'].func,
|
332
|
+
firstDayOfWeek: _propTypes2['default'].string
|
329
333
|
});
|
330
334
|
Calendar.defaultProps = (0, _extends3['default'])({}, _CalendarMixin.calendarMixinDefaultProps, _CommonMixin.defaultProp, {
|
331
335
|
showToday: true,
|
package/lib/Picker.js
CHANGED
@@ -195,6 +195,7 @@ var _initialiseProps = function _initialiseProps() {
|
|
195
195
|
if (cause.source === 'keyboard' || cause.source === 'dateInputSelect' || !props.calendar.props.timePicker && cause.source !== 'dateInput' || cause.source === 'todayButton') {
|
196
196
|
_this2.close(_this2.focus);
|
197
197
|
}
|
198
|
+
console.log('onCalendarSelect', value, cause);
|
198
199
|
props.onChange(value);
|
199
200
|
};
|
200
201
|
|
@@ -26,6 +26,8 @@ var _dayjs = require('dayjs');
|
|
26
26
|
|
27
27
|
var _dayjs2 = _interopRequireDefault(_dayjs);
|
28
28
|
|
29
|
+
var _util = require('../util');
|
30
|
+
|
29
31
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
30
32
|
|
31
33
|
var CalendarRightPanel = function (_React$Component) {
|
@@ -64,7 +66,8 @@ var CalendarRightPanel = function (_React$Component) {
|
|
64
66
|
};
|
65
67
|
|
66
68
|
_this.state = {
|
67
|
-
highlightTime: _this.props.value || null
|
69
|
+
highlightTime: _this.props.value || null,
|
70
|
+
localeFormat: _this.props.format[0]
|
68
71
|
};
|
69
72
|
_this.timeRef = _react2['default'].createRef();
|
70
73
|
_this.times = _this.getTimes();
|
@@ -87,9 +90,13 @@ var CalendarRightPanel = function (_React$Component) {
|
|
87
90
|
var _props = this.props,
|
88
91
|
value = _props.value,
|
89
92
|
prefixCls = _props.prefixCls,
|
90
|
-
locale = _props.locale
|
93
|
+
locale = _props.locale,
|
94
|
+
showHourAndMinute = _props.showHourAndMinute;
|
91
95
|
|
92
96
|
var selectedDate = value.format().slice(0, 10);
|
97
|
+
if (showHourAndMinute) {
|
98
|
+
selectedDate = value.format().slice(0, String(value.format()).indexOf('T')).padStart(10, 0);
|
99
|
+
}
|
93
100
|
var highlight = this.state.highlightTime;
|
94
101
|
var highlightTime = highlight ? highlight.format().slice(11, 16) : null;
|
95
102
|
var isZhcn = locale && locale.today === '今天';
|
@@ -109,6 +116,12 @@ var CalendarRightPanel = function (_React$Component) {
|
|
109
116
|
null,
|
110
117
|
this.times.map(function (time) {
|
111
118
|
var current = (0, _dayjs2['default'])(selectedDate + ' ' + time);
|
119
|
+
if (showHourAndMinute) {
|
120
|
+
var parts = (0, _util.formatDateLocal)(selectedDate, _this2.state.localeFormat);
|
121
|
+
if (parts[0] && parts[0].length === 4 && (parts[0].slice(0, 3) === '000' || parts[0].slice(0, 2) === '00')) {
|
122
|
+
current.year(parts[0]);
|
123
|
+
}
|
124
|
+
}
|
112
125
|
current = isZhcn ? current.locale('zh-cn') : current.locale('en-gb');
|
113
126
|
return _react2['default'].createElement(
|
114
127
|
'li',
|
@@ -139,7 +152,9 @@ CalendarRightPanel.propTypes = {
|
|
139
152
|
onSelect: _propTypes2['default'].func,
|
140
153
|
onClickRightPanelTime: _propTypes2['default'].func,
|
141
154
|
locale: _propTypes2['default'].object,
|
142
|
-
defaultMinutesTime: _propTypes2['default'].string
|
155
|
+
defaultMinutesTime: _propTypes2['default'].string,
|
156
|
+
format: _propTypes2['default'].oneOfType([_propTypes2['default'].string, _propTypes2['default'].arrayOf(_propTypes2['default'].string)]),
|
157
|
+
showHourAndMinute: _propTypes2['default'].bool
|
143
158
|
};
|
144
159
|
exports['default'] = CalendarRightPanel;
|
145
160
|
module.exports = exports['default'];
|
package/lib/date/DateInput.js
CHANGED
@@ -55,17 +55,19 @@ var DateInput = function (_React$Component) {
|
|
55
55
|
_initialiseProps.call(_this);
|
56
56
|
|
57
57
|
var selectedValue = props.selectedValue;
|
58
|
-
|
58
|
+
var formatPrefix = _this.props.format[0];
|
59
59
|
_this.state = {
|
60
60
|
str: (0, _util.formatDate)(selectedValue, _this.props.format),
|
61
|
-
|
62
|
-
|
61
|
+
hasFocus: false,
|
62
|
+
localeFormat: formatPrefix,
|
63
|
+
delimiter: (0, _util.delimate)(formatPrefix),
|
64
|
+
cananderIput: ''
|
63
65
|
};
|
64
66
|
return _this;
|
65
67
|
}
|
66
68
|
|
67
69
|
DateInput.prototype.componentDidUpdate = function componentDidUpdate() {
|
68
|
-
if (dateInputInstance && this.state.hasFocus && !
|
70
|
+
if (dateInputInstance && this.state.hasFocus && !(cachedSelectionStart === 0 && cachedSelectionEnd === 0)) {
|
69
71
|
dateInputInstance.setSelectionRange(cachedSelectionStart, cachedSelectionEnd);
|
70
72
|
}
|
71
73
|
};
|
@@ -80,12 +82,31 @@ var DateInput = function (_React$Component) {
|
|
80
82
|
// when popup show, click body will call this, bug!
|
81
83
|
var selectedValue = nextProps.selectedValue;
|
82
84
|
if (!state.hasFocus) {
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
85
|
+
var timeStr = (0, _util.formatDate)(selectedValue, nextProps.format).split(' ')[0];
|
86
|
+
var parts = timeStr.split(state.delimiter);
|
87
|
+
var timeParts = (0, _util.formatDate)(selectedValue, nextProps.format).split(' ')[1];
|
88
|
+
if (parts.length === 3) {
|
89
|
+
if (state.localeFormat === _util.DATE_FORMATS.ISO) {
|
90
|
+
newState = { str: parts[0].padStart(4, 0) + '-' + parts[1] + '-' + parts[2] };
|
91
|
+
} else if (state.localeFormat === _util.DATE_FORMATS.ISOAndTime) {
|
92
|
+
newState = {
|
93
|
+
str: parts[0].padStart(4, 0) + '-' + parts[1] + '-' + parts[2] + ' ' + (nextProps.showHourAndMinute ? timeParts : '') // eslint-disable-line max-len
|
94
|
+
};
|
95
|
+
} else if (state.localeFormat === _util.DATE_FORMATS.US) {
|
96
|
+
newState = { str: Number(parts[0]) + '/' + Number(parts[1]) + '/' + parts[2].padStart(4, 0) };
|
97
|
+
} else if (state.localeFormat === _util.DATE_FORMATS.USAndTime) {
|
98
|
+
newState = {
|
99
|
+
str: Number(parts[0]) + '/' + Number(parts[1]) + '/' + parts[2].padStart(4, 0) + ' ' + (nextProps.showHourAndMinute ? timeParts : '') // eslint-disable-line max-len
|
100
|
+
};
|
101
|
+
} else if (state.localeFormat === _util.DATE_FORMATS.European || state.localeFormat === _util.DATE_FORMATS.Germany_Russia_etc) {
|
102
|
+
newState = { str: '' + Number(parts[0]) + state.delimiter + Number(parts[1]) + state.delimiter + parts[2].padStart(4, 0) }; // eslint-disable-line max-len
|
103
|
+
} else if (state.localeFormat === _util.DATE_FORMATS.EuropeanAndTime || state.localeFormat === _util.DATE_FORMATS.Germany_Russia_etcAndTime) {
|
104
|
+
newState = {
|
105
|
+
str: '' + Number(parts[0]) + state.delimiter + Number(parts[1]) + state.delimiter + parts[2].padStart(4, 0) + ' ' + (nextProps.showHourAndMinute ? timeParts : '') // eslint-disable-line max-len
|
106
|
+
};
|
107
|
+
}
|
108
|
+
}
|
87
109
|
}
|
88
|
-
|
89
110
|
return newState;
|
90
111
|
};
|
91
112
|
|
@@ -95,16 +116,13 @@ var DateInput = function (_React$Component) {
|
|
95
116
|
|
96
117
|
DateInput.prototype.render = function render() {
|
97
118
|
var props = this.props;
|
98
|
-
var
|
99
|
-
invalid = _state.invalid,
|
100
|
-
str = _state.str;
|
119
|
+
var str = this.state.str;
|
101
120
|
var locale = props.locale,
|
102
121
|
prefixCls = props.prefixCls,
|
103
122
|
placeholder = props.placeholder,
|
104
123
|
clearIcon = props.clearIcon,
|
105
124
|
inputMode = props.inputMode;
|
106
125
|
|
107
|
-
var invalidClass = invalid ? prefixCls + '-input-invalid' : '';
|
108
126
|
return _react2['default'].createElement(
|
109
127
|
'div',
|
110
128
|
{ className: prefixCls + '-input-wrap' },
|
@@ -113,11 +131,11 @@ var DateInput = function (_React$Component) {
|
|
113
131
|
{ className: prefixCls + '-date-input-wrap' },
|
114
132
|
_react2['default'].createElement('input', {
|
115
133
|
ref: this.saveDateInput,
|
116
|
-
className: prefixCls + '-input
|
134
|
+
className: prefixCls + '-input',
|
117
135
|
value: str,
|
118
136
|
disabled: props.disabled,
|
119
137
|
placeholder: placeholder,
|
120
|
-
onChange: this.
|
138
|
+
onChange: this.onInputChangeAll,
|
121
139
|
onKeyDown: this.onKeyDown,
|
122
140
|
onFocus: this.onFocus,
|
123
141
|
onBlur: this.onBlur,
|
@@ -153,7 +171,8 @@ DateInput.propTypes = {
|
|
153
171
|
onSelect: _propTypes2['default'].func,
|
154
172
|
selectedValue: _propTypes2['default'].object,
|
155
173
|
clearIcon: _propTypes2['default'].node,
|
156
|
-
inputMode: _propTypes2['default'].string
|
174
|
+
inputMode: _propTypes2['default'].string,
|
175
|
+
showHourAndMinute: _propTypes2['default'].bool
|
157
176
|
};
|
158
177
|
|
159
178
|
var _initialiseProps = function _initialiseProps() {
|
@@ -166,55 +185,52 @@ var _initialiseProps = function _initialiseProps() {
|
|
166
185
|
_this2.props.onClear(null);
|
167
186
|
};
|
168
187
|
|
169
|
-
this.onInputChange = function (
|
170
|
-
var
|
188
|
+
this.onInputChange = function (str) {
|
189
|
+
var cananderStr = (0, _util.normalizeDateInput)(str, _this2.state.localeFormat, _this2.state.delimiter);
|
171
190
|
var _props = _this2.props,
|
172
191
|
disabledDate = _props.disabledDate,
|
173
|
-
format = _props.format,
|
174
192
|
onChange = _props.onChange,
|
175
193
|
selectedValue = _props.selectedValue;
|
176
194
|
|
195
|
+
var parts = (0, _util.formatDateLocal)(cananderStr, _this2.state.localeFormat);
|
177
196
|
// 没有内容,合法并直接退出
|
178
|
-
|
179
197
|
if (!str) {
|
180
198
|
onChange(null);
|
181
|
-
_this2.setState({
|
182
|
-
invalid: false,
|
183
|
-
str: str
|
184
|
-
});
|
199
|
+
_this2.setState({ str: str });
|
185
200
|
return;
|
186
201
|
}
|
187
|
-
|
188
202
|
// 不合法直接退出
|
189
|
-
var
|
190
|
-
|
191
|
-
_this2.setState({
|
192
|
-
invalid: true,
|
193
|
-
str: str
|
194
|
-
});
|
195
|
-
return;
|
196
|
-
}
|
197
|
-
|
203
|
+
var format = (0, _util.getDateFormatByStr)(cananderStr, _this2.state.localeFormat);
|
204
|
+
var parsed = (0, _dayjs2['default'])(cananderStr, format);
|
198
205
|
var value = _this2.props.value.clone();
|
199
206
|
value = value.year(parsed.year()).month(parsed.month()).date(parsed.date()).hour(parsed.hour()).minute(parsed.minute()).second(parsed.second());
|
200
207
|
|
208
|
+
if (_this2.state.localeFormat === _util.DATE_FORMATS.ISO || _this2.state.localeFormat === _util.DATE_FORMATS.ISOAndTime) {
|
209
|
+
if (parts[0] && parts[0].length === 4 && (parts[0].slice(0, 3) === '000' || parts[0].slice(0, 2) === '00')) {
|
210
|
+
value.year(parts[0]);
|
211
|
+
}
|
212
|
+
}
|
213
|
+
if (_this2.state.localeFormat === _util.DATE_FORMATS.European || _this2.state.localeFormat === _util.DATE_FORMATS.EuropeanAndTime || _this2.state.localeFormat === _util.DATE_FORMATS.US || _this2.state.localeFormat === _util.DATE_FORMATS.USAndTime || _this2.state.localeFormat === _util.DATE_FORMATS.Germany_Russia_etc || _this2.state.localeFormat === _util.DATE_FORMATS.Germany_Russia_etcAndTime) {
|
214
|
+
if (parts[2] && parts[2].length === 4 && (parts[2].slice(0, 3) === '000' || parts[2].slice(0, 2) === '00')) {
|
215
|
+
value.year(parts[2]);
|
216
|
+
}
|
217
|
+
}
|
201
218
|
if (!value || disabledDate && disabledDate(value)) {
|
202
|
-
_this2.setState({
|
203
|
-
invalid: true,
|
204
|
-
str: str
|
205
|
-
});
|
219
|
+
_this2.setState({ str: str });
|
206
220
|
return;
|
207
221
|
}
|
208
222
|
|
209
223
|
if (selectedValue !== value || selectedValue && value && !selectedValue.isSame(value)) {
|
210
|
-
_this2.setState({
|
211
|
-
invalid: false,
|
212
|
-
str: str
|
213
|
-
});
|
224
|
+
_this2.setState({ str: str });
|
214
225
|
onChange(value);
|
215
226
|
}
|
216
227
|
};
|
217
228
|
|
229
|
+
this.onInputChangeAll = function (event) {
|
230
|
+
var str = event.target.value;
|
231
|
+
_this2.onInputChange(str);
|
232
|
+
};
|
233
|
+
|
218
234
|
this.onFocus = function () {
|
219
235
|
_this2.setState({ hasFocus: true });
|
220
236
|
};
|
package/lib/date/DateTHead.js
CHANGED
@@ -50,8 +50,9 @@ var DateTHead = function (_React$Component) {
|
|
50
50
|
var firstDay = DAY_NAME_TO_INDEX[firstDayName] ? DAY_NAME_TO_INDEX[firstDayName] : 0;
|
51
51
|
|
52
52
|
var showWeekNumberEl = void 0;
|
53
|
-
|
54
|
-
|
53
|
+
var dateColumnCount = DATE_ROW_COLUMN_COUNT.DATE_COL_COUNT;
|
54
|
+
for (var dateColIndex = 0; dateColIndex < dateColumnCount; dateColIndex++) {
|
55
|
+
var index = (firstDay + dateColIndex) % dateColumnCount;
|
55
56
|
veryShortWeekdays[dateColIndex] = allWeekdaysMin[index];
|
56
57
|
weekDays[dateColIndex] = allWeekdaysShort[index];
|
57
58
|
}
|