From 5f57dc38da9ab78e1a078484dfcf018fbbccdabd Mon Sep 17 00:00:00 2001 From: Wojciech Maj Date: Sat, 29 Jul 2017 22:51:33 +0200 Subject: [PATCH] Update compiled files --- build/Calendar.js | 234 +++++++++++++++++--------------- build/Calendar/Navigation.js | 90 ++++++------- build/CenturyView.js | 25 ++-- build/CenturyView/Decade.js | 24 +++- build/CenturyView/Decades.js | 46 ++++--- build/DecadeView.js | 25 ++-- build/DecadeView/Year.js | 26 ++-- build/DecadeView/Years.js | 46 ++++--- build/MonthView.js | 96 +++++++++---- build/MonthView/Day.js | 30 +++-- build/MonthView/Days.js | 61 ++++++--- build/MonthView/WeekNumbers.js | 108 +++++++++++++++ build/MonthView/Weekdays.js | 7 +- build/YearView.js | 23 ++-- build/YearView/Month.js | 24 ++-- build/YearView/Months.js | 38 ++++-- build/shared/dates.js | 240 +++++++++++++++------------------ build/shared/locales.js | 42 ++++++ build/shared/propTypes.js | 6 +- build/shared/utils.js | 64 +++++++++ 20 files changed, 780 insertions(+), 475 deletions(-) create mode 100644 build/MonthView/WeekNumbers.js create mode 100644 build/shared/locales.js create mode 100644 build/shared/utils.js diff --git a/build/Calendar.js b/build/Calendar.js index 8e36e704..eb062f1e 100644 --- a/build/Calendar.js +++ b/build/Calendar.js @@ -4,6 +4,8 @@ Object.defineProperty(exports, "__esModule", { value: true }); +var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; + var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); @@ -40,6 +42,12 @@ var _MonthView2 = _interopRequireDefault(_MonthView); var _dates = require('./shared/dates'); +var _locales = require('./shared/locales'); + +var _propTypes3 = require('./shared/propTypes'); + +var _utils = require('./shared/utils'); + function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -69,7 +77,6 @@ var Calendar = function (_Component) { return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = Calendar.__proto__ || Object.getPrototypeOf(Calendar)).call.apply(_ref, [this].concat(args))), _this), _this.state = { activeStartDate: _this.getActiveStartDate(), - value: _this.getValue(), view: _this.getView() }, _this.setView = function (view) { _this.setState(function (prevState) { @@ -83,25 +90,15 @@ var Calendar = function (_Component) { view: view }; }); - }, _this.setActiveRange = function (activeRange) { - var _activeRange2 = _slicedToArray(activeRange, 1), - activeStartDate = _activeRange2[0]; - - _this.setState({ - activeStartDate: activeStartDate - }); }, _this.setActiveStartDate = function (activeStartDate) { return _this.setState({ activeStartDate: activeStartDate }); - }, _this.drillDown = function (activeRange) { + }, _this.drillDown = function (activeStartDate) { if (!_this.drillDownAvailable) { return; } var views = _this.getLimitedViews(); - var _activeRange3 = _slicedToArray(activeRange, 1), - activeStartDate = _activeRange3[0]; - _this.setState(function (prevState) { return { activeStartDate: activeStartDate, @@ -120,35 +117,43 @@ var Calendar = function (_Component) { view: views[views.indexOf(prevState.view) - 1] }; }); - }, _this.onChange = function (valueRange) { - var onChange = _this.props.onChange; - - - var value = _this.getValueFromRange(valueRange); - + }, _this.onChange = function (value) { _this.setState({ value: value }); - if (onChange) onChange(value); - }, _this.onDrillDown = function (callback) { - return function (range) { - if (callback) callback(); + var onChange = _this.props.onChange; - if (_this.drillDownAvailable) { - _this.drillDown(range); - } else { - _this.onChange(range); - } - }; + var processedValue = _this.getProcessedValue(value); + if (onChange) onChange(processedValue); }, _temp), _possibleConstructorReturn(_this, _ret); } _createClass(Calendar, [{ - key: 'getLimitedViews', - + key: 'getValueArray', + value: function getValueArray(value) { + if (value instanceof Array) { + return value; + } + return (0, _dates.getRange)(this.valueType, value); + } + }, { + key: 'getValueFrom', + value: function getValueFrom(value) { + var rawValueFrom = value instanceof Array ? value[0] : value; + return (0, _dates.getRange)(this.valueType, rawValueFrom)[0]; + } + }, { + key: 'getValueTo', + value: function getValueTo(value) { + var rawValueFrom = value instanceof Array ? value[1] : value; + return (0, _dates.getRange)(this.valueType, rawValueFrom)[1]; + } /** * Returns views array with disallowed values cut off. */ + + }, { + key: 'getLimitedViews', value: function getLimitedViews() { var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.props; var minDetail = props.minDetail, @@ -158,19 +163,6 @@ var Calendar = function (_Component) { return allViews.slice(allViews.indexOf(minDetail), allViews.indexOf(maxDetail) + 1); } - /** - * Returns value type that can be returned with currently applied settings. - */ - - }, { - key: 'getValueType', - value: function getValueType() { - var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.props; - var maxDetail = props.maxDetail; - - return allValueTypes[allViews.indexOf(maxDetail)]; - } - /** * Determines whether a given view is allowed with currently applied settings. */ @@ -191,23 +183,27 @@ var Calendar = function (_Component) { */ }, { - key: 'getValueFromRange', - value: function getValueFromRange() { - var valueRange = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.state.value; + key: 'getProcessedValue', + value: function getProcessedValue(value) { var returnValue = this.props.returnValue; switch (returnValue) { case 'start': - return valueRange[0]; + return this.getValueFrom(value); case 'end': - return valueRange[1]; + return this.getValueTo(value); case 'range': - return valueRange; + return this.getValueArray(value); default: throw new Error('Invalid returnValue.'); } } + }, { + key: 'componentWillMount', + value: function componentWillMount() { + (0, _locales.setLocale)(this.props.locale); + } }, { key: 'componentWillReceiveProps', value: function componentWillReceiveProps(nextProps) { @@ -216,10 +212,22 @@ var Calendar = function (_Component) { var allowedViewChanged = nextProps.minDetail !== props.minDetail || nextProps.maxDetail !== props.maxDetail; - var valueChanged = nextProps.value && !props.value || nextProps.value && props.value && nextProps.value.getTime() !== props.value.getTime(); + var nextValueFrom = this.getValueFrom(nextProps.value); + var valueFrom = this.getValueFrom(props.value); + var valueFromChanged = nextValueFrom && !valueFrom || nextValueFrom && valueFrom && nextValueFrom.getTime() !== valueFrom.getTime(); + + var nextValueTo = this.getValueTo(nextProps.value); + var valueTo = this.getValueTo(props.value); + var valueToChanged = nextValueTo && !valueTo || nextValueTo && valueTo && nextValueTo.getTime() !== valueTo.getTime(); + + var valueChanged = valueFromChanged || valueToChanged; var nextState = {}; + if (nextProps.locale !== props.locale) { + (0, _locales.setLocale)(nextProps.locale); + } + if (allowedViewChanged) { if (!this.isViewAllowed(nextProps)) { nextState.view = this.getView(nextProps); @@ -227,7 +235,6 @@ var Calendar = function (_Component) { } if (allowedViewChanged || valueChanged) { - nextState.value = this.getValue(nextProps); nextState.activeStartDate = this.getActiveStartDate(nextProps); } @@ -239,15 +246,7 @@ var Calendar = function (_Component) { var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.props; var rangeType = this.getView(props); - return (0, _dates.getRange)(rangeType, props.value)[0]; - } - }, { - key: 'getValue', - value: function getValue() { - var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.props; - - var rangeType = this.getValueType(props); - return (0, _dates.getRange)(rangeType, props.value); + return (0, _dates.getBegin)(rangeType, this.getValueFrom(props.value)); } }, { key: 'getView', @@ -272,56 +271,48 @@ var Calendar = function (_Component) { * Called when the user uses navigation buttons. */ - - /** - * Called when the user uses navigation buttons. - */ - - - /** - * Called when the user clicks an item on any view. - * If they "hit the bottom" and they can't drill further down, onChange will be called. - * Otherwise, drillDown will be called. - */ - }, { key: 'renderContent', value: function renderContent() { + var setView = this.setView, + valueType = this.valueType; + var _props = this.props, + calendarType = _props.calendarType, + showWeekNumbers = _props.showWeekNumbers, + value = _props.value; var _state = this.state, activeStartDate = _state.activeStartDate, view = _state.view; - var _props = this.props, - onClickDay = _props.onClickDay, - onClickMonth = _props.onClickMonth, - onClickYear = _props.onClickYear, - onClickDecade = _props.onClickDecade; + var commonProps = { + activeStartDate: activeStartDate, + setView: setView, + value: value, + valueType: valueType + }; + + var clickAction = this.drillDownAvailable ? this.drillDown : this.onChange; + switch (view) { case 'century': - return _react2.default.createElement(_CenturyView2.default, { - century: activeStartDate, - onClickDecade: this.onDrillDown(onClickDecade), - setView: this.setView - }); + return _react2.default.createElement(_CenturyView2.default, _extends({ + onChange: (0, _utils.mergeFunctions)(clickAction, this.props.onClickDecade) + }, commonProps)); case 'decade': - return _react2.default.createElement(_DecadeView2.default, { - decade: activeStartDate, - onClickYear: this.onDrillDown(onClickYear), - setView: this.setView - }); + return _react2.default.createElement(_DecadeView2.default, _extends({ + onChange: (0, _utils.mergeFunctions)(clickAction, this.props.onClickYear) + }, commonProps)); case 'year': - return _react2.default.createElement(_YearView2.default, { - year: activeStartDate, - onClickMonth: this.onDrillDown(onClickMonth), - setView: this.setView - }); + return _react2.default.createElement(_YearView2.default, _extends({ + onChange: (0, _utils.mergeFunctions)(clickAction, this.props.onClickMonth) + }, commonProps)); case 'month': - return _react2.default.createElement(_MonthView2.default, { - month: activeStartDate, - onClickDay: this.onDrillDown(onClickDay), - setView: this.setView - }); + return _react2.default.createElement(_MonthView2.default, _extends({ + calendarType: calendarType, + onChange: (0, _utils.mergeFunctions)(clickAction, this.props.onClickDay), + showWeekNumbers: showWeekNumbers + }, commonProps)); default: throw new Error('Invalid view: ' + view + '.'); } @@ -329,22 +320,14 @@ var Calendar = function (_Component) { }, { key: 'renderNavigation', value: function renderNavigation() { - var _props2 = this.props, - prevLabel = _props2.prevLabel, - prev2Label = _props2.prev2Label, - nextLabel = _props2.nextLabel, - next2Label = _props2.next2Label; - - return _react2.default.createElement(_Navigation2.default, { activeRange: this.state.activeRange, activeStartDate: this.state.activeStartDate, drillUp: this.drillUp, - nextLabel: nextLabel, - next2Label: next2Label, - prevLabel: prevLabel, - prev2Label: prev2Label, - setActiveRange: this.setActiveRange, + nextLabel: this.props.nextLabel, + next2Label: this.props.next2Label, + prevLabel: this.props.prevLabel, + prev2Label: this.props.prev2Label, setActiveStartDate: this.setActiveStartDate, view: this.state.view, views: this.getLimitedViews() @@ -378,6 +361,32 @@ var Calendar = function (_Component) { return views.indexOf(view) > 0; } + + /** + * Returns value type that can be returned with currently applied settings. + */ + + }, { + key: 'valueType', + get: function get() { + var maxDetail = this.props.maxDetail; + + return allValueTypes[allViews.indexOf(maxDetail)]; + } + }, { + key: 'valueFrom', + get: function get() { + var value = this.props.value; + + return this.getValueFrom(value); + } + }, { + key: 'valueTo', + get: function get() { + var value = this.props.value; + + return this.getValueTo(value); + } }]); return Calendar; @@ -394,6 +403,8 @@ Calendar.defaultProps = { }; Calendar.propTypes = { + calendarType: _propTypes3.isCalendarType, + locale: _propTypes2.default.string, maxDetail: _propTypes2.default.oneOf(allViews), minDetail: _propTypes2.default.oneOf(allViews), next2Label: _propTypes2.default.string, @@ -406,6 +417,7 @@ Calendar.propTypes = { prev2Label: _propTypes2.default.string, prevLabel: _propTypes2.default.string, returnValue: _propTypes2.default.oneOf(['start', 'end', 'range']).isRequired, - value: _propTypes2.default.instanceOf(Date), - view: _propTypes2.default.oneOf(allViews) + showWeekNumbers: _propTypes2.default.bool, + value: _propTypes3.isValue, + view: _propTypes2.default.oneOf(allViews) // eslint-disable-line react/no-unused-prop-types }; \ No newline at end of file diff --git a/build/Calendar/Navigation.js b/build/Calendar/Navigation.js index f2d880aa..fc90bf1a 100644 --- a/build/Calendar/Navigation.js +++ b/build/Calendar/Navigation.js @@ -4,8 +4,6 @@ Object.defineProperty(exports, "__esModule", { value: true }); -var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); - var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _react = require('react'); @@ -48,65 +46,40 @@ var Navigation = function (_Component) { view = _this$props.view, setActiveStartDate = _this$props.setActiveStartDate; - setActiveStartDate((0, _dates.getPreviousRange)(view, date)[0]); + setActiveStartDate((0, _dates.getBeginPrevious)(view, date)); }, _this.onClickNext = function () { var _this$props2 = _this.props, date = _this$props2.activeStartDate, view = _this$props2.view, setActiveStartDate = _this$props2.setActiveStartDate; - setActiveStartDate((0, _dates.getNextRange)(view, date)[0]); + setActiveStartDate((0, _dates.getBeginNext)(view, date)); }, _this.onClickPrevious2 = function () { var _this$props3 = _this.props, date = _this$props3.activeStartDate, view = _this$props3.view, setActiveStartDate = _this$props3.setActiveStartDate; - setActiveStartDate((0, _dates.getPreviousRange2)(view, date)[0]); + setActiveStartDate((0, _dates.getBeginPrevious2)(view, date)); }, _this.onClickNext2 = function () { var _this$props4 = _this.props, date = _this$props4.activeStartDate, view = _this$props4.view, setActiveStartDate = _this$props4.setActiveStartDate; - setActiveStartDate((0, _dates.getNextRange2)(view, date)[0]); + setActiveStartDate((0, _dates.getBeginNext2)(view, date)); }, _temp), _possibleConstructorReturn(_this, _ret); } _createClass(Navigation, [{ key: 'render', value: function render() { + var label = this.label; var _props = this.props, - date = _props.activeStartDate, drillUp = _props.drillUp, view = _props.view; - var label = void 0; - switch (view) { - case 'century': - label = (0, _dates.getCenturyLabel)(date); - break; - case 'decade': - label = (0, _dates.getDecadeLabel)(date); - break; - case 'year': - label = (0, _dates.getYear)(date); - break; - case 'month': - label = (0, _dates.formatMonthYear)(date); - break; - default: - throw new Error('Invalid view: ' + view + '.'); - } - - var _props2 = this.props, - prevLabel = _props2.prevLabel, - prev2Label = _props2.prev2Label, - nextLabel = _props2.nextLabel, - next2Label = _props2.next2Label; - - return _react2.default.createElement( 'div', { className: 'react-calendar__navigation' }, @@ -116,7 +89,7 @@ var Navigation = function (_Component) { disabled: this.prev2ButtonDisabled, onClick: this.onClickPrevious2 }, - prev2Label + this.props.prev2Label ), _react2.default.createElement( 'button', @@ -124,7 +97,7 @@ var Navigation = function (_Component) { disabled: this.prevButtonDisabled, onClick: this.onClickPrevious }, - prevLabel + this.props.prevLabel ), _react2.default.createElement( 'button', @@ -140,60 +113,75 @@ var Navigation = function (_Component) { { onClick: this.onClickNext }, - nextLabel + this.props.nextLabel ), view !== 'century' && _react2.default.createElement( 'button', { onClick: this.onClickNext2 }, - next2Label + this.props.next2Label ) ); } }, { key: 'drillDownAvailable', get: function get() { - var _props3 = this.props, - view = _props3.view, - views = _props3.views; + var _props2 = this.props, + view = _props2.view, + views = _props2.views; return views.indexOf(view) < views.length - 1; } }, { key: 'drillUpAvailable', get: function get() { - var _props4 = this.props, - view = _props4.view, - views = _props4.views; + var _props3 = this.props, + view = _props3.view, + views = _props3.views; return views.indexOf(view) > 0; } }, { key: 'prevButtonDisabled', + get: function get() { + var _props4 = this.props, + date = _props4.activeStartDate, + view = _props4.view; + + var nextActiveStartDate = (0, _dates.getBeginPrevious)(view, date); + return nextActiveStartDate.getFullYear() < 1000; + } + }, { + key: 'prev2ButtonDisabled', get: function get() { var _props5 = this.props, date = _props5.activeStartDate, view = _props5.view; - var _getPreviousRange = (0, _dates.getPreviousRange)(view, date), - _getPreviousRange2 = _slicedToArray(_getPreviousRange, 1), - nextActiveStartDate = _getPreviousRange2[0]; - + var nextActiveStartDate = (0, _dates.getBeginPrevious2)(view, date); return nextActiveStartDate.getFullYear() < 1000; } }, { - key: 'prev2ButtonDisabled', + key: 'label', get: function get() { var _props6 = this.props, date = _props6.activeStartDate, view = _props6.view; - var _getPreviousRange3 = (0, _dates.getPreviousRange2)(view, date), - _getPreviousRange4 = _slicedToArray(_getPreviousRange3, 1), - nextActiveStartDate = _getPreviousRange4[0]; - return nextActiveStartDate.getFullYear() < 1000; + switch (view) { + case 'century': + return (0, _dates.getCenturyLabel)(date); + case 'decade': + return (0, _dates.getDecadeLabel)(date); + case 'year': + return (0, _dates.getYear)(date); + case 'month': + return (0, _dates.formatMonthYear)(date); + default: + throw new Error('Invalid view: ' + view + '.'); + } } }]); diff --git a/build/CenturyView.js b/build/CenturyView.js index 2158525c..e08a67eb 100644 --- a/build/CenturyView.js +++ b/build/CenturyView.js @@ -18,8 +18,12 @@ var _Decades = require('./CenturyView/Decades'); var _Decades2 = _interopRequireDefault(_Decades); +var _propTypes3 = require('./shared/propTypes'); + function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } + function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } @@ -47,16 +51,10 @@ var CenturyView = function (_Component) { key: 'renderDecades', value: function renderDecades() { var _props = this.props, - onClickDecade = _props.onClickDecade, - setActiveRange = _props.setActiveRange, - century = _props.century; - + setView = _props.setView, + childProps = _objectWithoutProperties(_props, ['setView']); - return _react2.default.createElement(_Decades2.default, { - century: century, - onClickDecade: onClickDecade, - setActiveRange: setActiveRange - }); + return _react2.default.createElement(_Decades2.default, childProps); } }, { key: 'render', @@ -76,9 +74,10 @@ exports.default = CenturyView; CenturyView.propTypes = { - century: _propTypes2.default.oneOfType([_propTypes2.default.string, // Only strings that are parseable to integer - _propTypes2.default.number, _propTypes2.default.instanceOf(Date)]).isRequired, - onClickDecade: _propTypes2.default.func, + activeStartDate: _propTypes2.default.instanceOf(Date).isRequired, + onChange: _propTypes2.default.func, setActiveRange: _propTypes2.default.func, - setView: _propTypes2.default.func + setView: _propTypes2.default.func, + value: _propTypes3.isValue, + valueType: _propTypes2.default.string }; \ No newline at end of file diff --git a/build/CenturyView/Decade.js b/build/CenturyView/Decade.js index d49fd39e..6f35ab04 100644 --- a/build/CenturyView/Decade.js +++ b/build/CenturyView/Decade.js @@ -19,23 +19,33 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de var className = 'react-calendar__century-view__decades__decade'; var Decade = function Decade(_ref) { - var decade = _ref.decade, - _onClick = _ref.onClick; + var active = _ref.active, + date = _ref.date, + decade = _ref.decade, + hasActive = _ref.hasActive, + onChange = _ref.onChange; return _react2.default.createElement( 'button', { - className: [className, 'react-calendar__tile'].join(' '), - onClick: function onClick() { - if (_onClick) _onClick((0, _dates.getDecadeRange)(decade)); + className: [className, active ? 'react-calendar__tile--active' : '', hasActive ? 'react-calendar__tile--hasActive' : '', 'react-calendar__tile'].join(' '), + onClick: onChange && function () { + return onChange(date); } }, - (0, _dates.getDecadeLabel)(decade) + _react2.default.createElement( + 'time', + null, + (0, _dates.getDecadeLabel)(decade) + ) ); }; Decade.propTypes = { + active: _propTypes2.default.bool.isRequired, + date: _propTypes2.default.instanceOf(Date).isRequired, decade: _propTypes2.default.number.isRequired, - onClick: _propTypes2.default.func + hasActive: _propTypes2.default.bool.isRequired, + onChange: _propTypes2.default.func }; exports.default = Decade; \ No newline at end of file diff --git a/build/CenturyView/Decades.js b/build/CenturyView/Decades.js index 2160fbc5..e5c568b6 100644 --- a/build/CenturyView/Decades.js +++ b/build/CenturyView/Decades.js @@ -4,6 +4,8 @@ Object.defineProperty(exports, "__esModule", { value: true }); +var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; + var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _react = require('react'); @@ -24,6 +26,10 @@ var _Decade2 = _interopRequireDefault(_Decade); var _dates = require('../shared/dates'); +var _utils = require('../shared/utils'); + +var _propTypes3 = require('../shared/propTypes'); + function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -36,36 +42,32 @@ var Decades = function (_Component) { _inherits(Decades, _Component); function Decades() { - var _ref; - - var _temp, _this, _ret; - _classCallCheck(this, Decades); - for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { - args[_key] = arguments[_key]; - } - - return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = Decades.__proto__ || Object.getPrototypeOf(Decades)).call.apply(_ref, [this].concat(args))), _this), _this.decadesInCentury = 10, _this.yearsInDecade = 10, _temp), _possibleConstructorReturn(_this, _ret); + return _possibleConstructorReturn(this, (Decades.__proto__ || Object.getPrototypeOf(Decades)).apply(this, arguments)); } _createClass(Decades, [{ key: 'render', value: function render() { - var yearsInDecade = this.yearsInDecade, - end = this.end, + var end = this.end, start = this.start; - var onClickDecade = this.props.onClickDecade; + var _props = this.props, + onChange = _props.onChange, + value = _props.value, + valueType = _props.valueType; var decades = []; + for (var decade = start; decade <= end; decade += 10) { + var date = (0, _dates.getBeginOfDecade)(decade); - for (var decade = start; decade < end; decade += yearsInDecade) { - decades.push(_react2.default.createElement(_Decade2.default, { + decades.push(_react2.default.createElement(_Decade2.default, _extends({}, (0, _utils.getTileActivityFlags)(value, valueType, date, 'decade'), { + date: date, decade: decade, key: decade, - onClick: onClickDecade - })); + onChange: onChange + }))); } return _react2.default.createElement( @@ -81,14 +83,14 @@ var Decades = function (_Component) { }, { key: 'start', get: function get() { - var century = this.props.century; + var activeStartDate = this.props.activeStartDate; - return (0, _dates.getBeginOfCenturyYear)(century); + return (0, _dates.getBeginOfCenturyYear)(activeStartDate); } }, { key: 'end', get: function get() { - return this.start + this.decadesInCentury * this.yearsInDecade; + return this.start + 99; } }]); @@ -99,6 +101,8 @@ exports.default = Decades; Decades.propTypes = { - century: _propTypes2.default.instanceOf(Date).isRequired, - onClickDecade: _propTypes2.default.func + activeStartDate: _propTypes2.default.instanceOf(Date).isRequired, + onChange: _propTypes2.default.func, + value: _propTypes3.isValue, + valueType: _propTypes2.default.string }; \ No newline at end of file diff --git a/build/DecadeView.js b/build/DecadeView.js index 739e5ad3..071416d6 100644 --- a/build/DecadeView.js +++ b/build/DecadeView.js @@ -18,8 +18,12 @@ var _Years = require('./DecadeView/Years'); var _Years2 = _interopRequireDefault(_Years); +var _propTypes3 = require('./shared/propTypes'); + function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } + function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } @@ -47,16 +51,10 @@ var DecadeView = function (_Component) { key: 'renderYears', value: function renderYears() { var _props = this.props, - onClickYear = _props.onClickYear, - setActiveRange = _props.setActiveRange, - decade = _props.decade; - + setView = _props.setView, + childProps = _objectWithoutProperties(_props, ['setView']); - return _react2.default.createElement(_Years2.default, { - decade: decade, - onClickYear: onClickYear, - setActiveRange: setActiveRange - }); + return _react2.default.createElement(_Years2.default, childProps); } }, { key: 'render', @@ -76,9 +74,10 @@ exports.default = DecadeView; DecadeView.propTypes = { - decade: _propTypes2.default.oneOfType([_propTypes2.default.string, // Only strings that are parseable to integer - _propTypes2.default.number, _propTypes2.default.instanceOf(Date)]).isRequired, - onClickYear: _propTypes2.default.func, + activeStartDate: _propTypes2.default.instanceOf(Date).isRequired, + onChange: _propTypes2.default.func, setActiveRange: _propTypes2.default.func, - setView: _propTypes2.default.func + setView: _propTypes2.default.func, + value: _propTypes3.isValue, + valueType: _propTypes2.default.string }; \ No newline at end of file diff --git a/build/DecadeView/Year.js b/build/DecadeView/Year.js index 7f6d9521..464e512d 100644 --- a/build/DecadeView/Year.js +++ b/build/DecadeView/Year.js @@ -12,29 +12,37 @@ var _propTypes = require('prop-types'); var _propTypes2 = _interopRequireDefault(_propTypes); -var _dates = require('../shared/dates'); - function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var className = 'react-calendar__decade-view__years__year'; var Year = function Year(_ref) { - var year = _ref.year, - _onClick = _ref.onClick; + var active = _ref.active, + date = _ref.date, + hasActive = _ref.hasActive, + onChange = _ref.onChange, + year = _ref.year; return _react2.default.createElement( 'button', { - className: [className, 'react-calendar__tile'].join(' '), - onClick: function onClick() { - if (_onClick) _onClick((0, _dates.getYearRange)(year)); + className: [className, active ? 'react-calendar__tile--active' : '', hasActive ? 'react-calendar__tile--hasActive' : '', 'react-calendar__tile'].join(' '), + onClick: onChange && function () { + return onChange(date); } }, - year + _react2.default.createElement( + 'time', + { dateTime: year }, + year + ) ); }; Year.propTypes = { - onClick: _propTypes2.default.func, + active: _propTypes2.default.bool.isRequired, + date: _propTypes2.default.instanceOf(Date).isRequired, + hasActive: _propTypes2.default.bool.isRequired, + onChange: _propTypes2.default.func, year: _propTypes2.default.number.isRequired }; diff --git a/build/DecadeView/Years.js b/build/DecadeView/Years.js index da85b053..c15e2cb2 100644 --- a/build/DecadeView/Years.js +++ b/build/DecadeView/Years.js @@ -4,6 +4,8 @@ Object.defineProperty(exports, "__esModule", { value: true }); +var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; + var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _react = require('react'); @@ -24,6 +26,10 @@ var _Year2 = _interopRequireDefault(_Year); var _dates = require('../shared/dates'); +var _utils = require('../shared/utils'); + +var _propTypes3 = require('../shared/propTypes'); + function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -36,17 +42,9 @@ var Years = function (_Component) { _inherits(Years, _Component); function Years() { - var _ref; - - var _temp, _this, _ret; - _classCallCheck(this, Years); - for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { - args[_key] = arguments[_key]; - } - - return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = Years.__proto__ || Object.getPrototypeOf(Years)).call.apply(_ref, [this].concat(args))), _this), _this.yearsInDecade = 10, _temp), _possibleConstructorReturn(_this, _ret); + return _possibleConstructorReturn(this, (Years.__proto__ || Object.getPrototypeOf(Years)).apply(this, arguments)); } _createClass(Years, [{ @@ -54,17 +52,22 @@ var Years = function (_Component) { value: function render() { var end = this.end, start = this.start; - var onClickYear = this.props.onClickYear; + var _props = this.props, + onChange = _props.onChange, + value = _props.value, + valueType = _props.valueType; var years = []; + for (var year = start; year <= end; year += 1) { + var date = new Date(year, 0, 1); - for (var year = start; year < end; year += 1) { - years.push(_react2.default.createElement(_Year2.default, { - year: year, + years.push(_react2.default.createElement(_Year2.default, _extends({}, (0, _utils.getTileActivityFlags)(value, valueType, date, 'year'), { + date: date, key: year, - onClick: onClickYear - })); + onChange: onChange, + year: year + }))); } return _react2.default.createElement( @@ -79,15 +82,14 @@ var Years = function (_Component) { }, { key: 'start', get: function get() { - var decade = this.props.decade; - + var activeStartDate = this.props.activeStartDate; - return (0, _dates.getBeginOfDecadeYear)(decade); + return (0, _dates.getBeginOfDecadeYear)(activeStartDate); } }, { key: 'end', get: function get() { - return this.start + this.yearsInDecade; + return this.start + 9; } }]); @@ -98,6 +100,8 @@ exports.default = Years; Years.propTypes = { - decade: _propTypes2.default.instanceOf(Date).isRequired, - onClickYear: _propTypes2.default.func + activeStartDate: _propTypes2.default.instanceOf(Date).isRequired, + onChange: _propTypes2.default.func, + value: _propTypes3.isValue, + valueType: _propTypes2.default.string }; \ No newline at end of file diff --git a/build/MonthView.js b/build/MonthView.js index 620d6f2d..4c1e2df0 100644 --- a/build/MonthView.js +++ b/build/MonthView.js @@ -4,6 +4,8 @@ Object.defineProperty(exports, "__esModule", { value: true }); +var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; + var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _react = require('react'); @@ -22,10 +24,18 @@ var _Weekdays = require('./MonthView/Weekdays'); var _Weekdays2 = _interopRequireDefault(_Weekdays); +var _WeekNumbers = require('./MonthView/WeekNumbers'); + +var _WeekNumbers2 = _interopRequireDefault(_WeekNumbers); + +var _locales = require('./shared/locales'); + var _propTypes3 = require('./shared/propTypes'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } + function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } @@ -52,43 +62,81 @@ var MonthView = function (_Component) { }, { key: 'renderWeekdays', value: function renderWeekdays() { - var _props = this.props, - calendarType = _props.calendarType, - month = _props.month; + var calendarType = this.calendarType; + var activeStartDate = this.props.activeStartDate; return _react2.default.createElement(_Weekdays2.default, { calendarType: calendarType, - month: month + month: activeStartDate }); } }, { - key: 'renderDays', - value: function renderDays() { - var _props2 = this.props, - calendarType = _props2.calendarType, - month = _props2.month, - onClickDay = _props2.onClickDay, - setActiveRange = _props2.setActiveRange; + key: 'renderWeekNumbers', + value: function renderWeekNumbers() { + var showWeekNumbers = this.props.showWeekNumbers; - return _react2.default.createElement(_Days2.default, { - calendarType: calendarType, - month: month, - onClickDay: onClickDay, - setActiveRange: setActiveRange + if (!showWeekNumbers) { + return null; + } + + var calendarType = this.calendarType; + var activeStartDate = this.props.activeStartDate; + + + return _react2.default.createElement(_WeekNumbers2.default, { + activeStartDate: activeStartDate, + calendarType: calendarType }); } + }, { + key: 'renderDays', + value: function renderDays() { + var _props = this.props, + setView = _props.setView, + calendarType = _props.calendarType, + childProps = _objectWithoutProperties(_props, ['setView', 'calendarType']); + + return _react2.default.createElement(_Days2.default, _extends({ + calendarType: this.calendarType + }, childProps)); + } }, { key: 'render', value: function render() { + var showWeekNumbers = this.props.showWeekNumbers; + + + var className = 'react-calendar__month-view'; + return _react2.default.createElement( 'div', - { className: 'react-calendar__month-view' }, + { + className: [className, showWeekNumbers ? className + '--weekNumbers' : ''].join(' ') + }, this.renderWeekdays(), + this.renderWeekNumbers(), this.renderDays() ); } + }, { + key: 'calendarType', + get: function get() { + var calendarType = this.props.calendarType; + + + if (calendarType) { + return calendarType; + } + + switch ((0, _locales.getLocale)()) { + case 'en-US': + return 'US'; + default: + return 'ISO 8601'; + } + } }]); return MonthView; @@ -97,15 +145,13 @@ var MonthView = function (_Component) { exports.default = MonthView; -MonthView.defaultProps = { - calendarType: 'ISO 8601' -}; - MonthView.propTypes = { + activeStartDate: _propTypes2.default.instanceOf(Date).isRequired, calendarType: _propTypes3.isCalendarType, - month: _propTypes2.default.oneOfType([_propTypes2.default.string, // Only strings that are parseable to integer - _propTypes2.default.number, _propTypes2.default.instanceOf(Date)]).isRequired, - onClickDay: _propTypes2.default.func, + onChange: _propTypes2.default.func, setActiveRange: _propTypes2.default.func, - setView: _propTypes2.default.func + setView: _propTypes2.default.func, + showWeekNumbers: _propTypes2.default.bool, + value: _propTypes3.isValue, + valueType: _propTypes2.default.string }; \ No newline at end of file diff --git a/build/MonthView/Day.js b/build/MonthView/Day.js index 6bae695b..2d6e640d 100644 --- a/build/MonthView/Day.js +++ b/build/MonthView/Day.js @@ -21,29 +21,35 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de var className = 'react-calendar__month-view__days__day'; var Day = function Day(_ref) { - var calendarType = _ref.calendarType, - day = _ref.day, - _onClick = _ref.onClick; + var active = _ref.active, + calendarType = _ref.calendarType, + date = _ref.date, + onChange = _ref.onChange; return _react2.default.createElement( 'button', { - className: [className, 'react-calendar__tile', (0, _dates.isWeekend)(day) ? ' ' + className + '--weekend' : ''].join(' '), - key: day, - onClick: function onClick() { - if (_onClick) _onClick((0, _dates.getDayRange)(day)); + className: [className, 'react-calendar__tile', active ? 'react-calendar__tile--active' : '', (0, _dates.isWeekend)(date) ? className + '--weekend' : ''].join(' '), + key: date, + onClick: onChange && function () { + return onChange(date); }, - style: (0, _dates.getDay)(day) === 1 ? { - gridColumnStart: (0, _dates.getDayOfWeek)(day, calendarType) + 1 + style: (0, _dates.getDay)(date) === 1 ? { + gridColumnStart: (0, _dates.getDayOfWeek)(date, calendarType) + 1 } : null }, - (0, _dates.getDay)(day) + _react2.default.createElement( + 'time', + { dateTime: date.toISOString() }, + (0, _dates.getDay)(date) + ) ); }; Day.propTypes = { + active: _propTypes2.default.bool.isRequired, calendarType: _propTypes3.isCalendarType, - day: _propTypes2.default.instanceOf(Date).isRequired, - onClick: _propTypes2.default.func + date: _propTypes2.default.instanceOf(Date).isRequired, + onChange: _propTypes2.default.func }; exports.default = Day; \ No newline at end of file diff --git a/build/MonthView/Days.js b/build/MonthView/Days.js index 65221cea..c47027b2 100644 --- a/build/MonthView/Days.js +++ b/build/MonthView/Days.js @@ -4,6 +4,8 @@ Object.defineProperty(exports, "__esModule", { value: true }); +var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; + var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _react = require('react'); @@ -26,6 +28,8 @@ var _dates = require('../shared/dates'); var _propTypes3 = require('../shared/propTypes'); +var _utils = require('../shared/utils'); + function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -38,30 +42,43 @@ var Days = function (_Component) { _inherits(Days, _Component); function Days() { + var _ref; + + var _temp, _this, _ret; + _classCallCheck(this, Days); - return _possibleConstructorReturn(this, (Days.__proto__ || Object.getPrototypeOf(Days)).apply(this, arguments)); + for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { + args[_key] = arguments[_key]; + } + + return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = Days.__proto__ || Object.getPrototypeOf(Days)).call.apply(_ref, [this].concat(args))), _this), _this.start = 1, _temp), _possibleConstructorReturn(_this, _ret); } _createClass(Days, [{ key: 'render', value: function render() { - var year = this.year, + var start = this.start, + end = this.end, + year = this.year, monthIndex = this.monthIndex; var _props = this.props, calendarType = _props.calendarType, - month = _props.month, - onClickDay = _props.onClickDay; + onChange = _props.onChange, + value = _props.value, + valueType = _props.valueType; var days = []; - for (var day = 1; day <= (0, _dates.getDaysInMonth)(month); day += 1) { - days.push(_react2.default.createElement(_Day2.default, { + for (var day = start; day <= end; day += 1) { + var date = new Date(year, monthIndex, day); + + days.push(_react2.default.createElement(_Day2.default, _extends({}, (0, _utils.getTileActivityFlags)(value, valueType, date, 'day'), { calendarType: calendarType, - day: new Date(year, monthIndex, day), + date: date, key: day, - onClick: onClickDay - })); + onChange: onChange + }))); } return _react2.default.createElement( @@ -75,20 +92,25 @@ var Days = function (_Component) { ); } }, { - key: 'year', + key: 'end', get: function get() { - var month = this.props.month; + var activeStartDate = this.props.activeStartDate; + return (0, _dates.getDaysInMonth)(activeStartDate); + } + }, { + key: 'year', + get: function get() { + var activeStartDate = this.props.activeStartDate; - return (0, _dates.getYear)(month); + return (0, _dates.getYear)(activeStartDate); } }, { key: 'monthIndex', get: function get() { - var month = this.props.month; - + var activeStartDate = this.props.activeStartDate; - return (0, _dates.getMonthIndex)(month); + return (0, _dates.getMonthIndex)(activeStartDate); } }]); @@ -99,8 +121,9 @@ exports.default = Days; Days.propTypes = { - calendarType: _propTypes3.isCalendarType, - month: _propTypes2.default.oneOfType([_propTypes2.default.string, // Only strings that are parseable to integer - _propTypes2.default.number, _propTypes2.default.instanceOf(Date)]).isRequired, - onClickDay: _propTypes2.default.func + activeStartDate: _propTypes2.default.instanceOf(Date).isRequired, + calendarType: _propTypes3.isCalendarType.isRequired, + onChange: _propTypes2.default.func, + value: _propTypes3.isValue, + valueType: _propTypes2.default.string }; \ No newline at end of file diff --git a/build/MonthView/WeekNumbers.js b/build/MonthView/WeekNumbers.js new file mode 100644 index 00000000..5ca9d0fd --- /dev/null +++ b/build/MonthView/WeekNumbers.js @@ -0,0 +1,108 @@ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +var _react = require('react'); + +var _react2 = _interopRequireDefault(_react); + +var _propTypes = require('prop-types'); + +var _propTypes2 = _interopRequireDefault(_propTypes); + +var _dates = require('../shared/dates'); + +var _propTypes3 = require('../shared/propTypes'); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var WeekNumbers = function (_Component) { + _inherits(WeekNumbers, _Component); + + function WeekNumbers() { + _classCallCheck(this, WeekNumbers); + + return _possibleConstructorReturn(this, (WeekNumbers.__proto__ || Object.getPrototypeOf(WeekNumbers)).apply(this, arguments)); + } + + _createClass(WeekNumbers, [{ + key: 'render', + value: function render() { + var startWeekNumber = this.startWeekNumber; + + var weekNumbers = Array(this.numberOfWeeks).fill(null).map(function (item, index) { + return index + startWeekNumber; + }).map(function (item) { + return item > 52 ? item % 52 : item; + }); + + return _react2.default.createElement( + 'div', + { className: 'react-calendar__month-view__weekNumbers' }, + weekNumbers.map(function (weekNumber) { + return _react2.default.createElement( + 'div', + { + className: 'react-calendar__tile', + key: weekNumber + }, + weekNumber + ); + }) + ); + } + }, { + key: 'numberOfDays', + get: function get() { + var activeStartDate = this.props.activeStartDate; + + return (0, _dates.getDaysInMonth)(activeStartDate); + } + }, { + key: 'startWeekday', + get: function get() { + var _props = this.props, + activeStartDate = _props.activeStartDate, + calendarType = _props.calendarType; + + return (0, _dates.getDayOfWeek)(activeStartDate, calendarType); + } + }, { + key: 'startWeekNumber', + get: function get() { + var _props2 = this.props, + activeStartDate = _props2.activeStartDate, + calendarType = _props2.calendarType; + + return (0, _dates.getWeekNumber)(activeStartDate, calendarType); + } + }, { + key: 'numberOfWeeks', + get: function get() { + var days = this.numberOfDays - (7 - this.startWeekday); + var weeks = 1 + Math.ceil(days / 7); + + return weeks; + } + }]); + + return WeekNumbers; +}(_react.Component); + +exports.default = WeekNumbers; + + +WeekNumbers.propTypes = { + activeStartDate: _propTypes2.default.instanceOf(Date).isRequired, + calendarType: _propTypes3.isCalendarType.isRequired +}; \ No newline at end of file diff --git a/build/MonthView/Weekdays.js b/build/MonthView/Weekdays.js index d293cc85..4b6b1cd3 100644 --- a/build/MonthView/Weekdays.js +++ b/build/MonthView/Weekdays.js @@ -102,13 +102,8 @@ var Weekdays = function (_Component) { exports.default = Weekdays; -Weekdays.defaultProps = { - calendarType: 'ISO 8601', - month: new Date() -}; - Weekdays.propTypes = { - calendarType: _propTypes3.isCalendarType, + calendarType: _propTypes3.isCalendarType.isRequired, month: _propTypes2.default.oneOfType([_propTypes2.default.string, // Only strings that are parseable to integer _propTypes2.default.number, _propTypes2.default.instanceOf(Date)]).isRequired }; \ No newline at end of file diff --git a/build/YearView.js b/build/YearView.js index e7672982..1c58f458 100644 --- a/build/YearView.js +++ b/build/YearView.js @@ -18,8 +18,12 @@ var _Months = require('./YearView/Months'); var _Months2 = _interopRequireDefault(_Months); +var _propTypes3 = require('./shared/propTypes'); + function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } + function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } @@ -47,16 +51,10 @@ var YearView = function (_Component) { key: 'renderMonths', value: function renderMonths() { var _props = this.props, - onClickMonth = _props.onClickMonth, - setActiveRange = _props.setActiveRange, - year = _props.year; - + setView = _props.setView, + childProps = _objectWithoutProperties(_props, ['setView']); - return _react2.default.createElement(_Months2.default, { - year: year, - onClickMonth: onClickMonth, - setActiveRange: setActiveRange - }); + return _react2.default.createElement(_Months2.default, childProps); } }, { key: 'render', @@ -76,9 +74,10 @@ exports.default = YearView; YearView.propTypes = { - onClickMonth: _propTypes2.default.func, + activeStartDate: _propTypes2.default.instanceOf(Date).isRequired, + onChange: _propTypes2.default.func, setActiveRange: _propTypes2.default.func, setView: _propTypes2.default.func, - year: _propTypes2.default.oneOfType([_propTypes2.default.string, // Only strings that are parseable to integer - _propTypes2.default.number, _propTypes2.default.instanceOf(Date)]).isRequired + value: _propTypes3.isValue, + valueType: _propTypes2.default.string }; \ No newline at end of file diff --git a/build/YearView/Month.js b/build/YearView/Month.js index 32e0658a..42833185 100644 --- a/build/YearView/Month.js +++ b/build/YearView/Month.js @@ -19,23 +19,31 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de var className = 'react-calendar__year-view__months__month'; var Month = function Month(_ref) { - var month = _ref.month, - _onClick = _ref.onClick; + var active = _ref.active, + date = _ref.date, + hasActive = _ref.hasActive, + onChange = _ref.onChange; return _react2.default.createElement( 'button', { - className: [className, 'react-calendar__tile'].join(' '), - onClick: function onClick() { - if (_onClick) _onClick((0, _dates.getMonthRange)(month)); + className: [className, active ? 'react-calendar__tile--active' : '', hasActive ? 'react-calendar__tile--hasActive' : '', 'react-calendar__tile'].join(' '), + onClick: onChange && function () { + return onChange(date); } }, - (0, _dates.formatMonth)(month) + _react2.default.createElement( + 'time', + { dateTime: date.toISOString() }, + (0, _dates.formatMonth)(date) + ) ); }; Month.propTypes = { - month: _propTypes2.default.instanceOf(Date).isRequired, - onClick: _propTypes2.default.func + active: _propTypes2.default.bool.isRequired, + date: _propTypes2.default.instanceOf(Date).isRequired, + hasActive: _propTypes2.default.bool.isRequired, + onChange: _propTypes2.default.func }; exports.default = Month; \ No newline at end of file diff --git a/build/YearView/Months.js b/build/YearView/Months.js index a34005c6..9bddc37b 100644 --- a/build/YearView/Months.js +++ b/build/YearView/Months.js @@ -4,6 +4,8 @@ Object.defineProperty(exports, "__esModule", { value: true }); +var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; + var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _react = require('react'); @@ -24,6 +26,10 @@ var _Month2 = _interopRequireDefault(_Month); var _dates = require('../shared/dates'); +var _utils = require('../shared/utils'); + +var _propTypes3 = require('../shared/propTypes'); + function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -46,25 +52,30 @@ var Months = function (_Component) { args[_key] = arguments[_key]; } - return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = Months.__proto__ || Object.getPrototypeOf(Months)).call.apply(_ref, [this].concat(args))), _this), _this.monthsInYear = 12, _temp), _possibleConstructorReturn(_this, _ret); + return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = Months.__proto__ || Object.getPrototypeOf(Months)).call.apply(_ref, [this].concat(args))), _this), _this.start = 0, _this.end = 11, _temp), _possibleConstructorReturn(_this, _ret); } _createClass(Months, [{ key: 'render', value: function render() { - var monthsInYear = this.monthsInYear, + var end = this.end, + start = this.start, year = this.year; - var onClickMonth = this.props.onClickMonth; + var _props = this.props, + onChange = _props.onChange, + value = _props.value, + valueType = _props.valueType; var months = []; + for (var monthIndex = start; monthIndex <= end; monthIndex += 1) { + var date = new Date(year, monthIndex, 1); - for (var monthIndex = 0; monthIndex < monthsInYear; monthIndex += 1) { - months.push(_react2.default.createElement(_Month2.default, { + months.push(_react2.default.createElement(_Month2.default, _extends({}, (0, _utils.getTileActivityFlags)(value, valueType, date, 'month'), { key: monthIndex, - month: new Date(year, monthIndex, 1), - onClick: onClickMonth - })); + date: date, + onChange: onChange + }))); } return _react2.default.createElement( @@ -79,10 +90,9 @@ var Months = function (_Component) { }, { key: 'year', get: function get() { - var year = this.props.year; - + var activeStartDate = this.props.activeStartDate; - return (0, _dates.getYear)(year); + return (0, _dates.getYear)(activeStartDate); } }]); @@ -93,6 +103,8 @@ exports.default = Months; Months.propTypes = { - onClickMonth: _propTypes2.default.func, - year: _propTypes2.default.instanceOf(Date).isRequired + activeStartDate: _propTypes2.default.instanceOf(Date).isRequired, + onChange: _propTypes2.default.func, + value: _propTypes3.isValue, + valueType: _propTypes2.default.string }; \ No newline at end of file diff --git a/build/shared/dates.js b/build/shared/dates.js index 6a089ff5..4fe48b2c 100644 --- a/build/shared/dates.js +++ b/build/shared/dates.js @@ -3,36 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.isWeekend = exports.getDecadeLabel = exports.getCenturyLabel = exports.getDaysInMonth = exports.getNextRange2 = exports.getPreviousRange2 = exports.getNextRange = exports.getPreviousRange = exports.getRange = exports.getDayRange = exports.getNextMonthRange = exports.getPreviousMonthRange = exports.getMonthRange = exports.getEndOfMonth = exports.getBeginOfMonth = exports.getNextYearRange = exports.getPreviousYearRange = exports.getYearRange = exports.getEndOfYear = exports.getBeginOfYear = exports.getNextDecadeRange = exports.getPreviousDecadeRange = exports.getDecadeRange = exports.getEndOfDecade = exports.getBeginOfDecade = exports.getBeginOfDecadeYear = exports.getNextCenturyRange = exports.getPreviousCenturyRange = exports.getCenturyRange = exports.getEndOfCentury = exports.getBeginOfCentury = exports.getBeginOfCenturyYear = exports.getDayOfWeek = exports.getDay = exports.getMonth = exports.getMonthIndex = exports.getYear = exports.formatShortWeekday = exports.formatLongWeekday = exports.formatMonth = exports.formatMonthYear = exports.formatDate = exports.getFormatter = undefined; +exports.isWeekend = exports.getDecadeLabel = exports.getCenturyLabel = exports.getDaysInMonth = exports.getBeginNext2 = exports.getBeginPrevious2 = exports.getBeginNext = exports.getBeginPrevious = exports.getBegin = exports.getRange = exports.getWeekNumber = exports.getBeginOfMonth = exports.getBeginOfDecade = exports.getBeginOfDecadeYear = exports.getBeginOfCenturyYear = exports.getDayOfWeek = exports.getDay = exports.getMonthIndex = exports.getYear = exports.formatShortWeekday = exports.formatMonth = exports.formatMonthYear = exports.formatDate = undefined; var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); -var _lodash = require('lodash.once'); - -var _lodash2 = _interopRequireDefault(_lodash); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } - -var getLocales = (0, _lodash2.default)(function () { - var languageList = []; - - if (window.navigator.languages) { - languageList.push.apply(languageList, _toConsumableArray(window.navigator.languages)); - } else if (window.navigator.userLanguage) { - languageList.push(window.navigator.userLanguage); - } - - // Fallback - languageList.push('en-GB'); - - return languageList; -}); - -var getLocale = (0, _lodash2.default)(function () { - return getLocales()[0]; -}); +var _locales = require('./locales'); var formatterCache = {}; @@ -40,8 +15,8 @@ var formatterCache = {}; * Gets Intl-based date formatter from formatter cache. If it doesn't exist in cache * just yet, it will be created on the fly. */ -var getFormatter = exports.getFormatter = function getFormatter(options) { - var locales = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : getLocale(); +var getFormatter = function getFormatter(options) { + var locales = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : (0, _locales.getLocale)(); var stringifiedOptions = JSON.stringify(options); @@ -68,10 +43,6 @@ var formatMonth = exports.formatMonth = function formatMonth(date) { return getFormatter({ month: 'long' })(date); }; -var formatLongWeekday = exports.formatLongWeekday = function formatLongWeekday(date) { - return getFormatter({ weekday: 'long' })(date); -}; - var formatShortWeekday = exports.formatShortWeekday = function formatShortWeekday(date) { return getFormatter({ weekday: 'short' })(date); }; @@ -100,10 +71,6 @@ var getMonthIndex = exports.getMonthIndex = function getMonthIndex(date) { return date.getMonth(); }; -var getMonth = exports.getMonth = function getMonth(date) { - return getMonthIndex(date) + 1; -}; - var getDay = exports.getDay = function getDay(date) { return date.getDate(); }; @@ -115,97 +82,77 @@ var getDayOfWeek = exports.getDayOfWeek = function getDayOfWeek(date) { switch (calendarType) { case 'ISO 8601': - if (weekday > 0) { - weekday -= 1; - } else { - weekday = 6; - } - break; + // Shifts days of the week so that Monday is 0, Sunday is 6 + return (weekday + 6) % 7; case 'US': - break; + return weekday; default: throw new Error('Unsupported calendar type.'); } - - return weekday; }; /* Complex getters - getting a property somehow related to a given point in time */ var getBeginOfCenturyYear = exports.getBeginOfCenturyYear = function getBeginOfCenturyYear(date) { var year = getYear(date); - return year + -year % 100 + 1; }; -var getBeginOfCentury = exports.getBeginOfCentury = function getBeginOfCentury(date) { +var getBeginOfCentury = function getBeginOfCentury(date) { var beginOfCenturyYear = getBeginOfCenturyYear(date); - return new Date(beginOfCenturyYear, 0, 1); }; -var getEndOfCentury = exports.getEndOfCentury = function getEndOfCentury(date) { +var getEndOfCentury = function getEndOfCentury(date) { var beginOfCenturyYear = getBeginOfCenturyYear(date); - return new Date(beginOfCenturyYear + 100, 0, 0, 0, 0, 0, -1); }; -var getCenturyRange = exports.getCenturyRange = function getCenturyRange(date) { - var beginOfCenturyYear = getBeginOfCenturyYear(date); - - return [new Date(beginOfCenturyYear, 0, 1), new Date(beginOfCenturyYear + 100, 0, 0, 0, 0, 0, -1)]; +var getCenturyRange = function getCenturyRange(date) { + return [getBeginOfCentury(date), getEndOfCentury(date)]; }; -var getPreviousCenturyRange = exports.getPreviousCenturyRange = function getPreviousCenturyRange(date) { +var getBeginOfPreviousCentury = function getBeginOfPreviousCentury(date) { var previousCenturyYear = getYear(date) - 100; - - return getCenturyRange(previousCenturyYear); + return getBeginOfCentury(previousCenturyYear); }; -var getNextCenturyRange = exports.getNextCenturyRange = function getNextCenturyRange(date) { +var getBeginOfNextCentury = function getBeginOfNextCentury(date) { var nextCenturyYear = getYear(date) + 100; - - return getCenturyRange(nextCenturyYear); + return getBeginOfCentury(nextCenturyYear); }; var getBeginOfDecadeYear = exports.getBeginOfDecadeYear = function getBeginOfDecadeYear(date) { - var year = getYear(date); - + var year = getYear(date) - 1; return year + -year % 10 + 1; }; var getBeginOfDecade = exports.getBeginOfDecade = function getBeginOfDecade(date) { var beginOfDecadeYear = getBeginOfDecadeYear(date); - return new Date(beginOfDecadeYear, 0, 1); }; -var getEndOfDecade = exports.getEndOfDecade = function getEndOfDecade(date) { +var getEndOfDecade = function getEndOfDecade(date) { var beginOfDecadeYear = getBeginOfDecadeYear(date); - return new Date(beginOfDecadeYear + 10, 0, 1, 0, 0, 0, -1); }; -var getDecadeRange = exports.getDecadeRange = function getDecadeRange(date) { - var beginOfDecadeYear = getBeginOfDecadeYear(date); - - return [new Date(beginOfDecadeYear, 0, 1), new Date(beginOfDecadeYear + 10, 0, 1, 0, 0, 0, -1)]; +var getDecadeRange = function getDecadeRange(date) { + return [getBeginOfDecade(date), getEndOfDecade(date)]; }; -var getPreviousDecadeRange = exports.getPreviousDecadeRange = function getPreviousDecadeRange(date) { +var getBeginOfPreviousDecade = function getBeginOfPreviousDecade(date) { var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10; var previousDecadeYear = getBeginOfDecadeYear(date) - offset; - - return getDecadeRange(previousDecadeYear); + return getBeginOfDecade(previousDecadeYear); }; -var getNextDecadeRange = exports.getNextDecadeRange = function getNextDecadeRange(date) { +var getBeginOfNextDecade = function getBeginOfNextDecade(date) { var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10; var nextDecadeYear = getBeginOfDecadeYear(date) + offset; - - return getDecadeRange(nextDecadeYear); + return getBeginOfDecade(nextDecadeYear); }; /** @@ -213,9 +160,8 @@ var getNextDecadeRange = exports.getNextDecadeRange = function getNextDecadeRang * * @param {Date} date Date. */ -var getBeginOfYear = exports.getBeginOfYear = function getBeginOfYear(date) { +var getBeginOfYear = function getBeginOfYear(date) { var year = getYear(date); - return new Date(year, 0, 1); }; @@ -224,9 +170,8 @@ var getBeginOfYear = exports.getBeginOfYear = function getBeginOfYear(date) { * * @param {Date} date Date. */ -var getEndOfYear = exports.getEndOfYear = function getEndOfYear(date) { +var getEndOfYear = function getEndOfYear(date) { var year = getYear(date); - return new Date(year + 1, 0, 1, 0, 0, 0, -1); }; @@ -235,26 +180,22 @@ var getEndOfYear = exports.getEndOfYear = function getEndOfYear(date) { * * @param {Date} date Date. */ -var getYearRange = exports.getYearRange = function getYearRange(date) { - var year = getYear(date); - - return [new Date(year, 0, 1), new Date(year + 1, 0, 1, 0, 0, 0, -1)]; +var getYearRange = function getYearRange(date) { + return [getBeginOfYear(date), getEndOfYear(date)]; }; -var getPreviousYearRange = exports.getPreviousYearRange = function getPreviousYearRange(date) { +var getBeginOfPreviousYear = function getBeginOfPreviousYear(date) { var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; var previousYear = getYear(date) - offset; - - return getYearRange(previousYear); + return getBeginOfYear(previousYear); }; -var getNextYearRange = exports.getNextYearRange = function getNextYearRange(date) { +var getBeginOfNextYear = function getBeginOfNextYear(date) { var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; var nextYear = getYear(date) + offset; - - return getYearRange(nextYear); + return getBeginOfYear(nextYear); }; /** @@ -265,7 +206,6 @@ var getNextYearRange = exports.getNextYearRange = function getNextYearRange(date var getBeginOfMonth = exports.getBeginOfMonth = function getBeginOfMonth(date) { var year = getYear(date); var monthIndex = getMonthIndex(date); - return new Date(year, monthIndex, 1); }; @@ -274,10 +214,9 @@ var getBeginOfMonth = exports.getBeginOfMonth = function getBeginOfMonth(date) { * * @param {Date} date Date. */ -var getEndOfMonth = exports.getEndOfMonth = function getEndOfMonth(date) { +var getEndOfMonth = function getEndOfMonth(date) { var year = getYear(date); var monthIndex = getMonthIndex(date); - return new Date(year, monthIndex + 1, 1, 0, 0, 0, -1); }; @@ -286,29 +225,38 @@ var getEndOfMonth = exports.getEndOfMonth = function getEndOfMonth(date) { * * @param {Date} date Date. */ -var getMonthRange = exports.getMonthRange = function getMonthRange(date) { - var year = getYear(date); - var monthIndex = getMonthIndex(date); - - return [new Date(year, monthIndex, 1), new Date(year, monthIndex + 1, 1, 0, 0, 0, -1)]; +var getMonthRange = function getMonthRange(date) { + return [getBeginOfMonth(date), getEndOfMonth(date)]; }; -var getPreviousMonthRange = exports.getPreviousMonthRange = function getPreviousMonthRange(date) { +var getBeginOfPreviousMonth = function getBeginOfPreviousMonth(date) { var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; var year = getYear(date); var previousMonthIndex = getMonthIndex(date) - offset; - - return [new Date(year, previousMonthIndex, 1), new Date(year, previousMonthIndex + 1, 1, 0, 0, 0, -1)]; + return getBeginOfMonth(new Date(year, previousMonthIndex, 1)); }; -var getNextMonthRange = exports.getNextMonthRange = function getNextMonthRange(date) { +var getBeginOfNextMonth = function getBeginOfNextMonth(date) { var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; var year = getYear(date); var nextMonthIndex = getMonthIndex(date) + offset; + return getBeginOfMonth(new Date(year, nextMonthIndex, 1)); +}; + +var getBeginOfDay = function getBeginOfDay(date) { + var year = getYear(date); + var monthIndex = getMonthIndex(date); + var day = getDay(date); + return new Date(year, monthIndex, day); +}; - return [new Date(year, nextMonthIndex, 1), new Date(year, nextMonthIndex + 1, 1, 0, 0, 0, -1)]; +var getEndOfDay = function getEndOfDay(date) { + var year = getYear(date); + var monthIndex = getMonthIndex(date); + var day = getDay(date); + return new Date(year, monthIndex, day + 1, 0, 0, 0, -1); }; /** @@ -316,14 +264,25 @@ var getNextMonthRange = exports.getNextMonthRange = function getNextMonthRange(d * * @param {Date} date Date. */ -var getDayRange = exports.getDayRange = function getDayRange(date) { - var year = getYear(date); - var monthIndex = getMonthIndex(date); - var day = getDay(date); +var getDayRange = function getDayRange(date) { + return [getBeginOfDay(date), getEndOfDay(date)]; +}; - return [new Date(year, monthIndex, day), new Date(year, monthIndex, day + 1, 0, 0, 0, -1)]; +var getWeekNumber = exports.getWeekNumber = function getWeekNumber(date) { + var calendarType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'ISO 8601'; + + var tempDate = new Date(+date); + tempDate.setDate(getDay(tempDate) + (4 - getDayOfWeek(tempDate, calendarType))); + var yearStart = getBeginOfYear(tempDate); + return Math.ceil((tempDate - yearStart) / 8.64e7 / 7); }; +/** + * Returns an array with the beginning and the end of a given range. + * + * @param {String} rangeType Range type (e.g. 'day') + * @param {Date} date Date. + */ var getRange = exports.getRange = function getRange(rangeType, date) { switch (rangeType) { case 'century': @@ -341,57 +300,80 @@ var getRange = exports.getRange = function getRange(rangeType, date) { } }; -var getPreviousRange = exports.getPreviousRange = function getPreviousRange(rangeType, date) { +/** + * Returns the beginning of a given range. + * + * @param {String} rangeType Range type (e.g. 'day') + * @param {Date} date Date. + */ +var getBegin = exports.getBegin = function getBegin(rangeType, date) { + switch (rangeType) { + case 'century': + return getBeginOfCentury(date); + case 'decade': + return getBeginOfDecade(date); + case 'year': + return getBeginOfYear(date); + case 'month': + return getBeginOfMonth(date); + case 'day': + return getBeginOfDay(date); + default: + throw new Error('Invalid rangeType: ' + rangeType); + } +}; + +var getBeginPrevious = exports.getBeginPrevious = function getBeginPrevious(rangeType, date) { switch (rangeType) { case 'century': - return getPreviousCenturyRange(date); + return getBeginOfPreviousCentury(date); case 'decade': - return getPreviousDecadeRange(date); + return getBeginOfPreviousDecade(date); case 'year': - return getPreviousYearRange(date); + return getBeginOfPreviousYear(date); case 'month': - return getPreviousMonthRange(date); + return getBeginOfPreviousMonth(date); default: throw new Error('Invalid rangeType: ' + rangeType); } }; -var getNextRange = exports.getNextRange = function getNextRange(rangeType, date) { +var getBeginNext = exports.getBeginNext = function getBeginNext(rangeType, date) { switch (rangeType) { case 'century': - return getNextCenturyRange(date); + return getBeginOfNextCentury(date); case 'decade': - return getNextDecadeRange(date); + return getBeginOfNextDecade(date); case 'year': - return getNextYearRange(date); + return getBeginOfNextYear(date); case 'month': - return getNextMonthRange(date); + return getBeginOfNextMonth(date); default: throw new Error('Invalid rangeType: ' + rangeType); } }; -var getPreviousRange2 = exports.getPreviousRange2 = function getPreviousRange2(rangeType, date) { +var getBeginPrevious2 = exports.getBeginPrevious2 = function getBeginPrevious2(rangeType, date) { switch (rangeType) { case 'decade': - return getPreviousDecadeRange(date, 100); + return getBeginOfPreviousDecade(date, 100); case 'year': - return getPreviousYearRange(date, 10); + return getBeginOfPreviousYear(date, 10); case 'month': - return getPreviousMonthRange(date, 12); + return getBeginOfPreviousMonth(date, 12); default: throw new Error('Invalid rangeType: ' + rangeType); } }; -var getNextRange2 = exports.getNextRange2 = function getNextRange2(rangeType, date) { +var getBeginNext2 = exports.getBeginNext2 = function getBeginNext2(rangeType, date) { switch (rangeType) { case 'decade': - return getNextDecadeRange(date, 100); + return getBeginOfNextDecade(date, 100); case 'year': - return getNextYearRange(date, 10); + return getBeginOfNextYear(date, 10); case 'month': - return getNextMonthRange(date, 12); + return getBeginOfNextMonth(date, 12); default: throw new Error('Invalid rangeType: ' + rangeType); } @@ -405,7 +387,6 @@ var getNextRange2 = exports.getNextRange2 = function getNextRange2(rangeType, da var getDaysInMonth = exports.getDaysInMonth = function getDaysInMonth(date) { var year = getYear(date); var monthIndex = getMonthIndex(date); - return new Date(year, monthIndex + 1, 0).getDate(); }; @@ -423,7 +404,6 @@ var getCenturyLabel = exports.getCenturyLabel = function getCenturyLabel(date) { var startLabel = getYear(start); var endLabel = getYear(end); - return startLabel + ' \u2013 ' + endLabel; }; @@ -441,7 +421,6 @@ var getDecadeLabel = exports.getDecadeLabel = function getDecadeLabel(date) { var startLabel = getYear(start); var endLabel = getYear(end); - return startLabel + ' \u2013 ' + endLabel; }; @@ -451,6 +430,5 @@ var getDecadeLabel = exports.getDecadeLabel = function getDecadeLabel(date) { */ var isWeekend = exports.isWeekend = function isWeekend(date) { var weekday = getDayOfWeek(date); - - return weekday === 5 || weekday === 6; + return weekday >= 5; }; \ No newline at end of file diff --git a/build/shared/locales.js b/build/shared/locales.js new file mode 100644 index 00000000..337a1202 --- /dev/null +++ b/build/shared/locales.js @@ -0,0 +1,42 @@ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.setLocale = exports.getLocale = undefined; + +var _lodash = require('lodash.once'); + +var _lodash2 = _interopRequireDefault(_lodash); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } + +var userLocale = null; + +var getDefaultLocales = (0, _lodash2.default)(function () { + var languageList = []; + + if (window.navigator.languages) { + languageList.push.apply(languageList, _toConsumableArray(window.navigator.languages)); + } else if (window.navigator.userLanguage) { + languageList.push(window.navigator.userLanguage); + } + + languageList.push('en-GB'); // Fallback + + return languageList; +}); + +var getDefaultLocale = (0, _lodash2.default)(function () { + return getDefaultLocales()[0]; +}); + +var getLocale = exports.getLocale = function getLocale() { + return userLocale || getDefaultLocale(); +}; + +var setLocale = exports.setLocale = function setLocale(locale) { + userLocale = locale; +}; \ No newline at end of file diff --git a/build/shared/propTypes.js b/build/shared/propTypes.js index 3ba66995..5db579c7 100644 --- a/build/shared/propTypes.js +++ b/build/shared/propTypes.js @@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.isCalendarType = undefined; +exports.isValue = exports.isCalendarType = undefined; var _propTypes = require('prop-types'); @@ -11,6 +11,6 @@ var _propTypes2 = _interopRequireDefault(_propTypes); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } -/* eslint-disable import/prefer-default-export */ +var isCalendarType = exports.isCalendarType = _propTypes2.default.oneOf(['ISO 8601', 'US']); -var isCalendarType = exports.isCalendarType = _propTypes2.default.oneOf(['ISO 8601', 'US']); \ No newline at end of file +var isValue = exports.isValue = _propTypes2.default.oneOfType([_propTypes2.default.instanceOf(Date), _propTypes2.default.arrayOf(_propTypes2.default.instanceOf(Date))]); \ No newline at end of file diff --git a/build/shared/utils.js b/build/shared/utils.js new file mode 100644 index 00000000..520f1810 --- /dev/null +++ b/build/shared/utils.js @@ -0,0 +1,64 @@ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.getTileActivityFlags = exports.mergeFunctions = undefined; + +var _dates = require('./dates'); + +/** + * Returns a function that, when called, calls all the functions + * passed to it, applying its arguments to them. + * + * @param {Function[]} functions + */ +var mergeFunctions = exports.mergeFunctions = function mergeFunctions() { + for (var _len = arguments.length, functions = Array(_len), _key = 0; _key < _len; _key++) { + functions[_key] = arguments[_key]; + } + + return function () { + for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { + args[_key2] = arguments[_key2]; + } + + return functions.filter(function (f) { + return f; + }).forEach(function (f) { + return f.apply(undefined, args); + }); + }; +}; + +var isValueWithinRange = function isValueWithinRange(value, range) { + return range[0].getTime() <= value.getTime() && range[1].getTime() >= value.getTime(); +}; + +var isRangeCoveringRange = function isRangeCoveringRange(valueRange, dateRange) { + return valueRange[0].getTime() <= dateRange[0].getTime() && valueRange[1].getTime() >= dateRange[1].getTime(); +}; + +var doRangesOverlap = function doRangesOverlap(valueRange, dateRange) { + return isValueWithinRange(valueRange[0], dateRange) || // Value begins in date + isValueWithinRange(valueRange[1], dateRange) || // Value ends in date + isRangeCoveringRange(valueRange, dateRange) // Value covers date + ; +}; + +var getTileActivityFlags = exports.getTileActivityFlags = function getTileActivityFlags(value, valueType, date, dateType) { + var flags = {}; + if (!value) { + flags.active = false; + flags.hasActive = false; + return flags; + } + + var valueRange = value instanceof Array ? value : (0, _dates.getRange)(valueType, value); + var dateRange = date instanceof Array ? date : (0, _dates.getRange)(dateType, date); + + flags.active = isRangeCoveringRange(valueRange, dateRange); + flags.hasActive = flags.active ? false : doRangesOverlap(valueRange, dateRange); + + return flags; +}; \ No newline at end of file