@seafile/seafile-calendar 0.0.2 → 0.0.3-Apoi0.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.
Files changed (46) hide show
  1. package/README.md +15 -0
  2. package/assets/index.css +44 -43
  3. package/dist/rc-calendar.css +44 -43
  4. package/dist/rc-calendar.css.map +1 -1
  5. package/dist/rc-calendar.js +1170 -5266
  6. package/dist/rc-calendar.js.map +1 -1
  7. package/dist/rc-calendar.min.css +44 -43
  8. package/dist/rc-calendar.min.css.map +1 -1
  9. package/dist/rc-calendar.min.js +1 -1
  10. package/es/Calendar.js +32 -10
  11. package/es/FullCalendar.js +2 -2
  12. package/es/MonthCalendar.js +8 -8
  13. package/es/RangeCalendar.js +4 -4
  14. package/es/calendar/CalendarHeader.js +2 -2
  15. package/es/calendar/CalendarRightPanel.js +47 -27
  16. package/es/date/DateConstants.js +16 -1
  17. package/es/date/DateInput.js +19 -42
  18. package/es/date/DateTBody.js +19 -11
  19. package/es/date/DateTHead.js +15 -8
  20. package/es/decade/DecadePanel.js +3 -3
  21. package/es/full-calendar/CalendarHeader.js +3 -3
  22. package/es/mixin/CalendarMixin.js +2 -2
  23. package/es/month/MonthTable.js +5 -5
  24. package/es/util/dayjs.js +17 -0
  25. package/es/util/index.js +451 -8
  26. package/es/year/YearPanel.js +5 -13
  27. package/index.d.ts +12 -11
  28. package/lib/Calendar.js +43 -11
  29. package/lib/FullCalendar.js +3 -3
  30. package/lib/MonthCalendar.js +9 -9
  31. package/lib/RangeCalendar.js +7 -7
  32. package/lib/calendar/CalendarHeader.js +2 -2
  33. package/lib/calendar/CalendarRightPanel.js +50 -29
  34. package/lib/date/DateConstants.js +16 -1
  35. package/lib/date/DateInput.js +20 -42
  36. package/lib/date/DateTBody.js +19 -11
  37. package/lib/date/DateTHead.js +15 -11
  38. package/lib/decade/DecadePanel.js +3 -3
  39. package/lib/full-calendar/CalendarHeader.js +3 -3
  40. package/lib/mixin/CalendarMixin.js +3 -3
  41. package/lib/month/MonthTable.js +5 -5
  42. package/lib/util/dayjs.js +46 -0
  43. package/lib/util/index.js +465 -9
  44. package/lib/year/YearPanel.js +5 -13
  45. package/package.json +7 -3
  46. package/HISTORY.md +0 -263
package/es/Calendar.js CHANGED
@@ -7,6 +7,7 @@ import ReactDOM from 'react-dom';
7
7
  import PropTypes from 'prop-types';
8
8
  import KeyCode from 'rc-util/es/KeyCode';
9
9
  import { polyfill } from 'react-lifecycles-compat';
10
+ import dayjs from 'dayjs';
10
11
  import DateTable from './date/DateTable';
11
12
  import CalendarHeader from './calendar/CalendarHeader';
12
13
  import CalendarFooter from './calendar/CalendarFooter';
@@ -16,12 +17,17 @@ import { commonMixinWrapper, propType, defaultProp } from './mixin/CommonMixin';
16
17
  import DateInput from './date/DateInput';
17
18
  import { getTimeConfig, getTodayTime, syncTime } from './util';
18
19
  import { goStartMonth, goEndMonth, goTime } from './util/toTime';
19
- import moment from 'moment';
20
+ import localeData from 'dayjs/plugin/localeData';
21
+ import utc from 'dayjs/plugin/utc';
22
+ import weekOfYear from 'dayjs/plugin/weekOfYear';
23
+ dayjs.extend(utc);
24
+ dayjs.extend(localeData);
25
+ dayjs.extend(weekOfYear);
20
26
 
21
27
  function noop() {}
22
28
 
23
29
  var getMomentObjectIfValid = function getMomentObjectIfValid(date) {
24
- if (moment.isMoment(date) && date.isValid()) {
30
+ if (dayjs.isDayjs(date) && date.isValid()) {
25
31
  return date;
26
32
  }
27
33
  return false;
@@ -39,7 +45,7 @@ var Calendar = function (_React$Component) {
39
45
 
40
46
  _this.state = {
41
47
  mode: _this.props.mode || 'date',
42
- value: getMomentObjectIfValid(props.value) || getMomentObjectIfValid(props.defaultValue) || moment(),
48
+ value: getMomentObjectIfValid(props.value) || getMomentObjectIfValid(props.defaultValue) || dayjs(),
43
49
  selectedValue: props.selectedValue || props.defaultSelectedValue
44
50
  };
45
51
  return _this;
@@ -78,11 +84,14 @@ var Calendar = function (_React$Component) {
78
84
  disabledDate = props.disabledDate,
79
85
  dateInputPlaceholder = props.dateInputPlaceholder,
80
86
  timePicker = props.timePicker,
87
+ onClickRightPanelTime = props.onClickRightPanelTime,
81
88
  disabledTime = props.disabledTime,
82
89
  clearIcon = props.clearIcon,
83
90
  renderFooter = props.renderFooter,
84
91
  inputMode = props.inputMode,
85
- showTimeAndHour = props.showTimeAndHour;
92
+ showHourAndMinute = props.showHourAndMinute,
93
+ firstDayOfWeek = props.firstDayOfWeek,
94
+ showWeekNumber = props.showWeekNumber;
86
95
  var value = state.value,
87
96
  selectedValue = state.selectedValue,
88
97
  mode = state.mode;
@@ -109,13 +118,14 @@ var Calendar = function (_React$Component) {
109
118
 
110
119
  timePickerEle = React.cloneElement(timePicker, timePickerProps);
111
120
  }
121
+ var calendarInputPlaceholder = dateInputPlaceholder || (Array.isArray(this.getFormat()) ? this.getFormat()[0] : this.getFormat());
112
122
 
113
123
  var dateInputElement = props.showDateInput ? React.createElement(DateInput, {
114
124
  format: this.getFormat(),
115
125
  key: 'date-input',
116
126
  value: value,
117
127
  locale: locale,
118
- placeholder: dateInputPlaceholder,
128
+ placeholder: calendarInputPlaceholder,
119
129
  showClear: true,
120
130
  disabledTime: disabledTime,
121
131
  disabledDate: disabledDate,
@@ -175,7 +185,8 @@ var Calendar = function (_React$Component) {
175
185
  dateRender: props.dateRender,
176
186
  onSelect: this.onDateTableSelect,
177
187
  disabledDate: disabledDate,
178
- showWeekNumber: props.showWeekNumber
188
+ showWeekNumber: showWeekNumber,
189
+ firstDayOfWeek: firstDayOfWeek
179
190
  })
180
191
  ),
181
192
  React.createElement(CalendarFooter, {
@@ -200,10 +211,14 @@ var Calendar = function (_React$Component) {
200
211
  onCloseTimePicker: this.closeTimePicker
201
212
  })
202
213
  ),
203
- !showTimeAndHour && React.createElement(CalendarRightPanel, {
214
+ showHourAndMinute && React.createElement(CalendarRightPanel, {
204
215
  prefixCls: prefixCls,
205
216
  value: value,
206
- onSelect: this.onDateTableSelect
217
+ locale: locale,
218
+ onSelect: this.onDateTableSelect,
219
+ onClickRightPanelTime: onClickRightPanelTime,
220
+ defaultMinutesTime: this.props.defaultMinutesTime,
221
+ format: this.getFormat()
207
222
  })
208
223
  )
209
224
  ));
@@ -231,6 +246,8 @@ Calendar.propTypes = _extends({}, calendarMixinPropTypes, propType, {
231
246
  showWeekNumber: PropTypes.bool,
232
247
  showToday: PropTypes.bool,
233
248
  showOk: PropTypes.bool,
249
+ showHourAndMinute: PropTypes.bool,
250
+ defaultMinutesTime: PropTypes.string,
234
251
  onSelect: PropTypes.func,
235
252
  onOk: PropTypes.func,
236
253
  onKeyDown: PropTypes.func,
@@ -247,15 +264,20 @@ Calendar.propTypes = _extends({}, calendarMixinPropTypes, propType, {
247
264
  clearIcon: PropTypes.node,
248
265
  focusablePanel: PropTypes.bool,
249
266
  inputMode: PropTypes.string,
250
- onBlur: PropTypes.func
267
+ onBlur: PropTypes.func,
268
+ onClickRightPanelTime: PropTypes.func,
269
+ firstDayOfWeek: PropTypes.string
251
270
  });
252
271
  Calendar.defaultProps = _extends({}, calendarMixinDefaultProps, defaultProp, {
253
272
  showToday: true,
254
273
  showDateInput: true,
274
+ showHourAndMinute: false,
255
275
  timePicker: null,
256
276
  onOk: noop,
257
277
  onPanelChange: noop,
258
- focusablePanel: true
278
+ onClickRightPanelTime: noop,
279
+ focusablePanel: true,
280
+ firstDayOfWeek: 'Sunday'
259
281
  });
260
282
 
261
283
  var _initialiseProps = function _initialiseProps() {
@@ -10,7 +10,7 @@ import MonthTable from './month/MonthTable';
10
10
  import { calendarMixinWrapper, calendarMixinPropTypes, calendarMixinDefaultProps, getNowByCurrentStateValue } from './mixin/CalendarMixin';
11
11
  import { commonMixinWrapper, propType, defaultProp } from './mixin/CommonMixin';
12
12
  import CalendarHeader from './full-calendar/CalendarHeader';
13
- import moment from 'moment';
13
+ import dayjs from './util/dayjs';
14
14
 
15
15
  var FullCalendar = function (_React$Component) {
16
16
  _inherits(FullCalendar, _React$Component);
@@ -31,7 +31,7 @@ var FullCalendar = function (_React$Component) {
31
31
 
32
32
  _this.state = {
33
33
  type: type,
34
- value: props.value || props.defaultValue || moment(),
34
+ value: props.value || props.defaultValue || dayjs(),
35
35
  selectedValue: props.selectedValue || props.defaultSelectedValue
36
36
  };
37
37
  return _this;
@@ -10,7 +10,7 @@ import CalendarHeader from './calendar/CalendarHeader';
10
10
  import CalendarFooter from './calendar/CalendarFooter';
11
11
  import { calendarMixinWrapper, calendarMixinPropTypes, calendarMixinDefaultProps } from './mixin/CalendarMixin';
12
12
  import { commonMixinWrapper, propType, defaultProp } from './mixin/CommonMixin';
13
- import moment from 'moment';
13
+ import dayjs from './util/dayjs';
14
14
 
15
15
  var MonthCalendar = function (_React$Component) {
16
16
  _inherits(MonthCalendar, _React$Component);
@@ -30,26 +30,26 @@ var MonthCalendar = function (_React$Component) {
30
30
  switch (keyCode) {
31
31
  case KeyCode.DOWN:
32
32
  value = stateValue.clone();
33
- value.add(3, 'months');
33
+ value = value.add(3, 'months');
34
34
  break;
35
35
  case KeyCode.UP:
36
36
  value = stateValue.clone();
37
- value.add(-3, 'months');
37
+ value = value.add(-3, 'months');
38
38
  break;
39
39
  case KeyCode.LEFT:
40
40
  value = stateValue.clone();
41
41
  if (ctrlKey) {
42
- value.add(-1, 'years');
42
+ value = value.add(-1, 'years');
43
43
  } else {
44
- value.add(-1, 'months');
44
+ value = value.add(-1, 'months');
45
45
  }
46
46
  break;
47
47
  case KeyCode.RIGHT:
48
48
  value = stateValue.clone();
49
49
  if (ctrlKey) {
50
- value.add(1, 'years');
50
+ value = value.add(1, 'years');
51
51
  } else {
52
- value.add(1, 'months');
52
+ value = value.add(1, 'months');
53
53
  }
54
54
  break;
55
55
  case KeyCode.ENTER:
@@ -76,7 +76,7 @@ var MonthCalendar = function (_React$Component) {
76
76
 
77
77
  _this.state = {
78
78
  mode: 'month',
79
- value: props.value || props.defaultValue || moment(),
79
+ value: props.value || props.defaultValue || dayjs(),
80
80
  selectedValue: props.selectedValue || props.defaultSelectedValue
81
81
  };
82
82
  return _this;
@@ -4,7 +4,6 @@ import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructo
4
4
  import _inherits from 'babel-runtime/helpers/inherits';
5
5
  import React from 'react';
6
6
  import PropTypes from 'prop-types';
7
- import moment from 'moment';
8
7
  import classnames from 'classnames';
9
8
  import { polyfill } from 'react-lifecycles-compat';
10
9
  import KeyCode from 'rc-util/es/KeyCode';
@@ -15,6 +14,7 @@ import TimePickerButton from './calendar/TimePickerButton';
15
14
  import { commonMixinWrapper, propType, defaultProp } from './mixin/CommonMixin';
16
15
  import { syncTime, getTodayTime, isAllowedDate } from './util';
17
16
  import { goTime, goStartMonth, goEndMonth, includesTime } from './util/toTime';
17
+ import dayjs from './util/dayjs';
18
18
 
19
19
  function noop() {}
20
20
 
@@ -55,7 +55,7 @@ function normalizeAnchor(props, init) {
55
55
  var selectedValue = props.selectedValue || init && props.defaultSelectedValue;
56
56
  var value = props.value || init && props.defaultValue;
57
57
  var normalizedValue = value ? getValueFromSelectedValue(value) : getValueFromSelectedValue(selectedValue);
58
- return !isEmptyArray(normalizedValue) ? normalizedValue : init && [moment(), moment().add(1, 'months')];
58
+ return !isEmptyArray(normalizedValue) ? normalizedValue : init && [dayjs(), dayjs().add(1, 'months')];
59
59
  }
60
60
 
61
61
  function generateOptions(length, extraOptionGen) {
@@ -414,7 +414,7 @@ var _initialiseProps = function _initialiseProps() {
414
414
  var nextHoverValue = void 0;
415
415
 
416
416
  if (!firstSelectedValue) {
417
- currentHoverTime = hoverValue[0] || selectedValue[0] || value[0] || moment();
417
+ currentHoverTime = hoverValue[0] || selectedValue[0] || value[0] || dayjs();
418
418
  nextHoverTime = func(currentHoverTime);
419
419
  nextHoverValue = [nextHoverTime];
420
420
  _this2.fireHoverValueChange(nextHoverValue);
@@ -804,7 +804,7 @@ var _initialiseProps = function _initialiseProps() {
804
804
 
805
805
  // 尚未选择过时间,直接输入的话
806
806
  if (!_this2.state.selectedValue[0] || !_this2.state.selectedValue[1]) {
807
- var startValue = selectedValue[0] || moment();
807
+ var startValue = selectedValue[0] || dayjs();
808
808
  var endValue = selectedValue[1] || startValue.clone().add(1, 'months');
809
809
  _this2.setState({
810
810
  selectedValue: selectedValue,
@@ -10,13 +10,13 @@ import DecadePanel from '../decade/DecadePanel';
10
10
 
11
11
  function goMonth(direction) {
12
12
  var next = this.props.value.clone();
13
- next.add(direction, 'months');
13
+ next = next.add(direction, 'months');
14
14
  this.props.onValueChange(next);
15
15
  }
16
16
 
17
17
  function goYear(direction) {
18
18
  var next = this.props.value.clone();
19
- next.add(direction, 'years');
19
+ next = next.add(direction, 'years');
20
20
  this.props.onValueChange(next);
21
21
  }
22
22
 
@@ -3,7 +3,8 @@ import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructo
3
3
  import _inherits from 'babel-runtime/helpers/inherits';
4
4
  import React from 'react';
5
5
  import PropTypes from 'prop-types';
6
- import moment from 'moment';
6
+ import dayjs from 'dayjs';
7
+ import { tokenizeFormattedDate } from '../util';
7
8
 
8
9
  var CalendarRightPanel = function (_React$Component) {
9
10
  _inherits(CalendarRightPanel, _React$Component);
@@ -18,6 +19,18 @@ var CalendarRightPanel = function (_React$Component) {
18
19
  highlightTime: value
19
20
  });
20
21
  _this.props.onSelect(value);
22
+ _this.props.onClickRightPanelTime();
23
+ };
24
+
25
+ _this.getTimes = function () {
26
+ var times = [];
27
+ for (var i = 0; i < 24; i++) {
28
+ var str = (String(i) + ':00').padStart(5, '0');
29
+ var str1 = (String(i) + ':30').padStart(5, '0');
30
+ times.push(str);
31
+ times.push(str1);
32
+ }
33
+ return times;
21
34
  };
22
35
 
23
36
  _this.scrollUp = function () {
@@ -28,39 +41,45 @@ var CalendarRightPanel = function (_React$Component) {
28
41
  _this.timeRef.current.scrollBy(0, 200);
29
42
  };
30
43
 
44
+ var format = Array.isArray(_this.props.format) ? _this.props.format[0] : _this.props.format;
31
45
  _this.state = {
32
- highlightTime: _this.props.value || null
46
+ highlightTime: _this.props.value || null,
47
+ localeFormat: format
33
48
  };
34
49
  _this.timeRef = React.createRef();
50
+ _this.times = _this.getTimes();
35
51
  return _this;
36
52
  }
37
53
 
54
+ CalendarRightPanel.prototype.componentDidMount = function componentDidMount() {
55
+ var defaultMinutesTime = this.props.defaultMinutesTime;
56
+
57
+ var showTimeIndex = this.times.findIndex(function (item) {
58
+ return item >= defaultMinutesTime;
59
+ });
60
+ var scrollTimeIndex = showTimeIndex > -1 ? showTimeIndex - 1 : 16;
61
+ this.timeRef.current.scrollTo(0, 34 * scrollTimeIndex);
62
+ };
63
+
38
64
  CalendarRightPanel.prototype.render = function render() {
39
65
  var _this2 = this;
40
66
 
41
67
  var _props = this.props,
42
68
  value = _props.value,
43
- prefixCls = _props.prefixCls;
69
+ prefixCls = _props.prefixCls,
70
+ locale = _props.locale;
44
71
 
45
- var selectedDate = value.format().slice(0, 10);
46
- var times = [];
47
- for (var i = 0; i < 24; i++) {
48
- var str = (String(i) + ':00').padStart(5, '0');
49
- var str1 = (String(i) + ':30').padStart(5, '0');
50
- times.push(str);
51
- times.push(str1);
52
- }
72
+ var selectedDate = value.format().slice(0, String(value.format()).indexOf('T'));
73
+ var highlight = this.state.highlightTime;
74
+ var highlightTime = highlight ? highlight.format().slice(11, 16) : null;
75
+ var isZhcn = locale && locale.today === '今天';
53
76
  return React.createElement(
54
77
  'div',
55
78
  { className: prefixCls + '-right-panel' },
56
79
  React.createElement(
57
80
  'div',
58
81
  { className: prefixCls + '-right-panel-header', onClick: this.scrollUp },
59
- React.createElement(
60
- 'span',
61
- null,
62
- React.createElement('i', { className: 'fas fa-chevron-up' })
63
- )
82
+ React.createElement('span', null)
64
83
  ),
65
84
  React.createElement(
66
85
  'div',
@@ -68,15 +87,16 @@ var CalendarRightPanel = function (_React$Component) {
68
87
  React.createElement(
69
88
  'ul',
70
89
  null,
71
- times.map(function (time) {
72
- var current = moment(selectedDate + ' ' + time);
73
- var isHightlight = current.isSame(_this2.state.highlightTime) ? 'highlight' : '';
90
+ this.times.map(function (time) {
91
+ var parts = tokenizeFormattedDate(selectedDate, _this2.state.localeFormat);
92
+ var current = dayjs(selectedDate + ' ' + time).year(parts[0]).month(parts[1] - 1).date(parts[2]); // eslint-disable-line max-len
93
+ current = isZhcn ? current.locale('zh-cn') : current.locale('en-gb');
74
94
  return React.createElement(
75
95
  'li',
76
96
  {
77
97
  key: time,
78
- onClick: _this2.onSelect.bind(null, current),
79
- className: '' + isHightlight
98
+ onClick: _this2.onSelect.bind(_this2, current),
99
+ className: '' + (highlightTime === time ? prefixCls + '-selected-time' : '')
80
100
  },
81
101
  time
82
102
  );
@@ -86,11 +106,7 @@ var CalendarRightPanel = function (_React$Component) {
86
106
  React.createElement(
87
107
  'div',
88
108
  { className: prefixCls + '-right-panel-footer', onClick: this.scrollDown },
89
- React.createElement(
90
- 'span',
91
- null,
92
- React.createElement('i', { className: 'fas fa-chevron-down' })
93
- )
109
+ React.createElement('span', null)
94
110
  )
95
111
  );
96
112
  };
@@ -101,6 +117,10 @@ var CalendarRightPanel = function (_React$Component) {
101
117
  CalendarRightPanel.propTypes = {
102
118
  prefixCls: PropTypes.string,
103
119
  value: PropTypes.object,
104
- onSelect: PropTypes.func
120
+ onSelect: PropTypes.func,
121
+ onClickRightPanelTime: PropTypes.func,
122
+ locale: PropTypes.object,
123
+ defaultMinutesTime: PropTypes.string,
124
+ format: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)])
105
125
  };
106
126
  export default CalendarRightPanel;
@@ -1,4 +1,19 @@
1
- export default {
1
+ var DATE_ROW_COLUMN_COUNT = {
2
2
  DATE_ROW_COUNT: 6,
3
3
  DATE_COL_COUNT: 7
4
+ };
5
+
6
+ var DAY_NAME_TO_INDEX = {
7
+ Sunday: 0,
8
+ Monday: 1,
9
+ Tuesday: 2,
10
+ Wednesday: 3,
11
+ Thursday: 4,
12
+ Friday: 5,
13
+ Saturday: 6
14
+ };
15
+
16
+ export default {
17
+ DATE_ROW_COLUMN_COUNT: DATE_ROW_COLUMN_COUNT,
18
+ DAY_NAME_TO_INDEX: DAY_NAME_TO_INDEX
4
19
  };
@@ -6,8 +6,11 @@ import ReactDOM from 'react-dom';
6
6
  import PropTypes from 'prop-types';
7
7
  import KeyCode from 'rc-util/es/KeyCode';
8
8
  import { polyfill } from 'react-lifecycles-compat';
9
- import moment from 'moment';
10
- import { formatDate } from '../util';
9
+ import dayjs from 'dayjs';
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;
@@ -27,14 +30,14 @@ var DateInput = function (_React$Component) {
27
30
 
28
31
  _this.state = {
29
32
  str: formatDate(selectedValue, _this.props.format),
30
- invalid: false,
31
- hasFocus: false
33
+ hasFocus: false,
34
+ localFormat: _this.props.format[0]
32
35
  };
33
36
  return _this;
34
37
  }
35
38
 
36
39
  DateInput.prototype.componentDidUpdate = function componentDidUpdate() {
37
- if (dateInputInstance && this.state.hasFocus && !this.state.invalid && !(cachedSelectionStart === 0 && cachedSelectionEnd === 0)) {
40
+ if (dateInputInstance && this.state.hasFocus && !(cachedSelectionStart === 0 && cachedSelectionEnd === 0)) {
38
41
  dateInputInstance.setSelectionRange(cachedSelectionStart, cachedSelectionEnd);
39
42
  }
40
43
  };
@@ -49,10 +52,7 @@ var DateInput = function (_React$Component) {
49
52
  // when popup show, click body will call this, bug!
50
53
  var selectedValue = nextProps.selectedValue;
51
54
  if (!state.hasFocus) {
52
- newState = {
53
- str: formatDate(selectedValue, nextProps.format),
54
- invalid: false
55
- };
55
+ newState = { str: formatDate(selectedValue, nextProps.format) };
56
56
  }
57
57
 
58
58
  return newState;
@@ -64,16 +64,13 @@ var DateInput = function (_React$Component) {
64
64
 
65
65
  DateInput.prototype.render = function render() {
66
66
  var props = this.props;
67
- var _state = this.state,
68
- invalid = _state.invalid,
69
- str = _state.str;
67
+ var str = this.state.str;
70
68
  var locale = props.locale,
71
69
  prefixCls = props.prefixCls,
72
70
  placeholder = props.placeholder,
73
71
  clearIcon = props.clearIcon,
74
72
  inputMode = props.inputMode;
75
73
 
76
- var invalidClass = invalid ? prefixCls + '-input-invalid' : '';
77
74
  return React.createElement(
78
75
  'div',
79
76
  { className: prefixCls + '-input-wrap' },
@@ -82,7 +79,7 @@ var DateInput = function (_React$Component) {
82
79
  { className: prefixCls + '-date-input-wrap' },
83
80
  React.createElement('input', {
84
81
  ref: this.saveDateInput,
85
- className: prefixCls + '-input ' + invalidClass,
82
+ className: prefixCls + '-input',
86
83
  value: str,
87
84
  disabled: props.disabled,
88
85
  placeholder: placeholder,
@@ -129,14 +126,13 @@ var _initialiseProps = function _initialiseProps() {
129
126
  var _this2 = this;
130
127
 
131
128
  this.onClear = function () {
132
- _this2.setState({
133
- str: ''
134
- });
129
+ _this2.setState({ str: '' });
135
130
  _this2.props.onClear(null);
136
131
  };
137
132
 
138
133
  this.onInputChange = function (event) {
139
134
  var str = event.target.value;
135
+ var calendarStr = initializeStr(str, _this2.state.localFormat) || '';
140
136
  var _props = _this2.props,
141
137
  disabledDate = _props.disabledDate,
142
138
  format = _props.format,
@@ -145,41 +141,22 @@ var _initialiseProps = function _initialiseProps() {
145
141
 
146
142
  // 没有内容,合法并直接退出
147
143
 
148
- if (!str) {
144
+ if (!calendarStr) {
149
145
  onChange(null);
150
- _this2.setState({
151
- invalid: false,
152
- str: str
153
- });
146
+ _this2.setState({ str: '' });
154
147
  return;
155
148
  }
156
-
157
- // 不合法直接退出
158
- var parsed = moment(str, format, true);
159
- if (!parsed.isValid()) {
160
- _this2.setState({
161
- invalid: true,
162
- str: str
163
- });
164
- return;
165
- }
166
-
149
+ var parsed = dayjs(calendarStr, format[0]);
167
150
  var value = _this2.props.value.clone();
168
- value.year(parsed.year()).month(parsed.month()).date(parsed.date()).hour(parsed.hour()).minute(parsed.minute()).second(parsed.second());
151
+ value = value.year(parsed.year()).month(parsed.month()).date(parsed.date()).hour(parsed.hour()).minute(parsed.minute()).second(parsed.second());
169
152
 
170
153
  if (!value || disabledDate && disabledDate(value)) {
171
- _this2.setState({
172
- invalid: true,
173
- str: str
174
- });
154
+ _this2.setState({ str: str });
175
155
  return;
176
156
  }
177
157
 
178
158
  if (selectedValue !== value || selectedValue && value && !selectedValue.isSame(value)) {
179
- _this2.setState({
180
- invalid: false,
181
- str: str
182
- });
159
+ _this2.setState({ str: str });
183
160
  onChange(value);
184
161
  }
185
162
  };
@@ -7,6 +7,10 @@ import cx from 'classnames';
7
7
  import DateConstants from './DateConstants';
8
8
  import { getTitleString, getTodayTime } from '../util/';
9
9
 
10
+ var DATE_ROW_COLUMN_COUNT = DateConstants.DATE_ROW_COLUMN_COUNT,
11
+ DAY_NAME_TO_INDEX = DateConstants.DAY_NAME_TO_INDEX;
12
+
13
+
10
14
  function isSameDay(one, two) {
11
15
  return one && two && one.isSame(two, 'day');
12
16
  }
@@ -47,7 +51,8 @@ var DateTBody = function (_React$Component) {
47
51
  showWeekNumber = props.showWeekNumber,
48
52
  dateRender = props.dateRender,
49
53
  disabledDate = props.disabledDate,
50
- hoverValue = props.hoverValue;
54
+ hoverValue = props.hoverValue,
55
+ firstDayOfWeek = props.firstDayOfWeek;
51
56
 
52
57
  var iIndex = void 0;
53
58
  var jIndex = void 0;
@@ -70,20 +75,22 @@ var DateTBody = function (_React$Component) {
70
75
  var lastDisableClass = prefixCls + '-disabled-cell-last-of-row';
71
76
  var lastDayOfMonthClass = prefixCls + '-last-day-of-month';
72
77
  var month1 = value.clone();
73
- month1.date(1);
78
+ month1 = month1.date(1);
74
79
  var day = month1.day();
75
- var lastMonthDiffDay = (day + 7 - value.localeData().firstDayOfWeek()) % 7;
80
+ var firstDayName = typeof firstDayOfWeek === 'string' ? firstDayOfWeek[0].toUpperCase() + firstDayOfWeek.slice(1) : 'Sunday';
81
+ var firstDayIndex = DAY_NAME_TO_INDEX[firstDayName] ? DAY_NAME_TO_INDEX[firstDayName] : 0;
82
+ var lastMonthDiffDay = (day + 7 - firstDayIndex) % 7;
76
83
  // calculate last month
77
84
  var lastMonth1 = month1.clone();
78
- lastMonth1.add(0 - lastMonthDiffDay, 'days');
85
+ lastMonth1 = lastMonth1.add(0 - lastMonthDiffDay, 'days');
79
86
  var passed = 0;
80
87
 
81
- for (iIndex = 0; iIndex < DateConstants.DATE_ROW_COUNT; iIndex++) {
82
- for (jIndex = 0; jIndex < DateConstants.DATE_COL_COUNT; jIndex++) {
88
+ for (iIndex = 0; iIndex < DATE_ROW_COLUMN_COUNT.DATE_ROW_COUNT; iIndex++) {
89
+ for (jIndex = 0; jIndex < DATE_ROW_COLUMN_COUNT.DATE_COL_COUNT; jIndex++) {
83
90
  current = lastMonth1;
84
91
  if (passed) {
85
92
  current = current.clone();
86
- current.add(passed, 'days');
93
+ current = current.add(passed, 'days');
87
94
  }
88
95
  dateTable.push(current);
89
96
  passed++;
@@ -92,7 +99,7 @@ var DateTBody = function (_React$Component) {
92
99
  var tableHtml = [];
93
100
  passed = 0;
94
101
 
95
- for (iIndex = 0; iIndex < DateConstants.DATE_ROW_COUNT; iIndex++) {
102
+ for (iIndex = 0; iIndex < DATE_ROW_COLUMN_COUNT.DATE_ROW_COUNT; iIndex++) {
96
103
  var _cx;
97
104
 
98
105
  var isCurrentWeek = void 0;
@@ -110,11 +117,11 @@ var DateTBody = function (_React$Component) {
110
117
  dateTable[passed].week()
111
118
  );
112
119
  }
113
- for (jIndex = 0; jIndex < DateConstants.DATE_COL_COUNT; jIndex++) {
120
+ for (jIndex = 0; jIndex < DATE_ROW_COLUMN_COUNT.DATE_COL_COUNT; jIndex++) {
114
121
  var next = null;
115
122
  var last = null;
116
123
  current = dateTable[passed];
117
- if (jIndex < DateConstants.DATE_COL_COUNT - 1) {
124
+ if (jIndex < DATE_ROW_COLUMN_COUNT.DATE_COL_COUNT - 1) {
118
125
  next = dateTable[passed + 1];
119
126
  }
120
127
  if (jIndex > 0) {
@@ -264,7 +271,8 @@ DateTBody.propTypes = {
264
271
  selectedValue: PropTypes.oneOfType([PropTypes.object, PropTypes.arrayOf(PropTypes.object)]),
265
272
  value: PropTypes.object,
266
273
  hoverValue: PropTypes.any,
267
- showWeekNumber: PropTypes.bool
274
+ showWeekNumber: PropTypes.bool,
275
+ firstDayOfWeek: PropTypes.string
268
276
  };
269
277
  DateTBody.defaultProps = {
270
278
  hoverValue: []
@@ -3,7 +3,9 @@ import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructo
3
3
  import _inherits from 'babel-runtime/helpers/inherits';
4
4
  import React from 'react';
5
5
  import DateConstants from './DateConstants';
6
- import moment from 'moment';
6
+
7
+ var DAY_NAME_TO_INDEX = DateConstants.DAY_NAME_TO_INDEX,
8
+ DATE_ROW_COLUMN_COUNT = DateConstants.DATE_ROW_COLUMN_COUNT;
7
9
 
8
10
  var DateTHead = function (_React$Component) {
9
11
  _inherits(DateTHead, _React$Component);
@@ -21,14 +23,19 @@ var DateTHead = function (_React$Component) {
21
23
  var prefixCls = props.prefixCls;
22
24
  var veryShortWeekdays = [];
23
25
  var weekDays = [];
24
- var firstDayOfWeek = localeData.firstDayOfWeek();
26
+
27
+ var allWeekdaysMin = localeData.weekdaysMin();
28
+ var allWeekdaysShort = localeData.weekdaysShort();
29
+
30
+ var firstDayName = typeof props.firstDayOfWeek === 'string' ? props.firstDayOfWeek[0].toUpperCase() + props.firstDayOfWeek.slice(1) : 'Sunday';
31
+ var firstDay = DAY_NAME_TO_INDEX[firstDayName] ? DAY_NAME_TO_INDEX[firstDayName] : 0;
32
+
25
33
  var showWeekNumberEl = void 0;
26
- var now = moment();
27
- for (var dateColIndex = 0; dateColIndex < DateConstants.DATE_COL_COUNT; dateColIndex++) {
28
- var index = (firstDayOfWeek + dateColIndex) % DateConstants.DATE_COL_COUNT;
29
- now.day(index);
30
- veryShortWeekdays[dateColIndex] = localeData.weekdaysMin(now);
31
- weekDays[dateColIndex] = localeData.weekdaysShort(now);
34
+ var dateColumnCount = DATE_ROW_COLUMN_COUNT.DATE_COL_COUNT;
35
+ for (var dateColIndex = 0; dateColIndex < dateColumnCount; dateColIndex++) {
36
+ var index = (firstDay + dateColIndex) % dateColumnCount;
37
+ veryShortWeekdays[dateColIndex] = allWeekdaysMin[index];
38
+ weekDays[dateColIndex] = allWeekdaysShort[index];
32
39
  }
33
40
 
34
41
  if (props.showWeekNumber) {