@freecodecamp/react-calendar-heatmap
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -7,2 +7,29 @@ 'use strict'; | ||
function _iterableToArrayLimit(arr, i) { | ||
var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; | ||
if (null != _i) { | ||
var _s, | ||
_e, | ||
_x, | ||
_r, | ||
_arr = [], | ||
_n = !0, | ||
_d = !1; | ||
try { | ||
if (_x = (_i = _i.call(arr)).next, 0 === i) { | ||
if (Object(_i) !== _i) return; | ||
_n = !1; | ||
} else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); | ||
} catch (err) { | ||
_d = !0, _e = err; | ||
} finally { | ||
try { | ||
if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; | ||
} finally { | ||
if (_d) throw _e; | ||
} | ||
} | ||
return _arr; | ||
} | ||
} | ||
function _classCallCheck(instance, Constructor) { | ||
@@ -13,3 +40,2 @@ if (!(instance instanceof Constructor)) { | ||
} | ||
function _defineProperties(target, props) { | ||
@@ -21,13 +47,15 @@ for (var i = 0; i < props.length; i++) { | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); | ||
} | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
Object.defineProperty(Constructor, "prototype", { | ||
writable: false | ||
}); | ||
return Constructor; | ||
} | ||
function _defineProperty(obj, key, value) { | ||
key = _toPropertyKey(key); | ||
if (key in obj) { | ||
@@ -43,11 +71,8 @@ Object.defineProperty(obj, key, { | ||
} | ||
return obj; | ||
} | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
_extends = Object.assign ? Object.assign.bind() : function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
@@ -59,9 +84,6 @@ if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
function _inherits(subClass, superClass) { | ||
@@ -71,3 +93,2 @@ if (typeof superClass !== "function" && superClass !== null) { | ||
} | ||
subClass.prototype = Object.create(superClass && superClass.prototype, { | ||
@@ -80,7 +101,9 @@ constructor: { | ||
}); | ||
Object.defineProperty(subClass, "prototype", { | ||
writable: false | ||
}); | ||
if (superClass) _setPrototypeOf(subClass, superClass); | ||
} | ||
function _getPrototypeOf(o) { | ||
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { | ||
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { | ||
return o.__proto__ || Object.getPrototypeOf(o); | ||
@@ -90,12 +113,20 @@ }; | ||
} | ||
function _setPrototypeOf(o, p) { | ||
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { | ||
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { | ||
o.__proto__ = p; | ||
return o; | ||
}; | ||
return _setPrototypeOf(o, p); | ||
} | ||
function _isNativeReflectConstruct() { | ||
if (typeof Reflect === "undefined" || !Reflect.construct) return false; | ||
if (Reflect.construct.sham) return false; | ||
if (typeof Proxy === "function") return true; | ||
try { | ||
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
function _assertThisInitialized(self) { | ||
@@ -105,55 +136,62 @@ if (self === void 0) { | ||
} | ||
return self; | ||
} | ||
function _possibleConstructorReturn(self, call) { | ||
if (call && (typeof call === "object" || typeof call === "function")) { | ||
return call; | ||
} else if (call !== void 0) { | ||
throw new TypeError("Derived constructors may only return object or undefined"); | ||
} | ||
return _assertThisInitialized(self); | ||
} | ||
function _createSuper(Derived) { | ||
var hasNativeReflectConstruct = _isNativeReflectConstruct(); | ||
return function _createSuperInternal() { | ||
var Super = _getPrototypeOf(Derived), | ||
result; | ||
if (hasNativeReflectConstruct) { | ||
var NewTarget = _getPrototypeOf(this).constructor; | ||
result = Reflect.construct(Super, arguments, NewTarget); | ||
} else { | ||
result = Super.apply(this, arguments); | ||
} | ||
return _possibleConstructorReturn(this, result); | ||
}; | ||
} | ||
function _slicedToArray(arr, i) { | ||
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); | ||
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); | ||
} | ||
function _arrayWithHoles(arr) { | ||
if (Array.isArray(arr)) return arr; | ||
} | ||
function _iterableToArrayLimit(arr, i) { | ||
if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { | ||
return; | ||
} | ||
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"] != null) _i["return"](); | ||
} finally { | ||
if (_d) throw _e; | ||
} | ||
} | ||
return _arr; | ||
function _unsupportedIterableToArray(o, minLen) { | ||
if (!o) return; | ||
if (typeof o === "string") return _arrayLikeToArray(o, minLen); | ||
var n = Object.prototype.toString.call(o).slice(8, -1); | ||
if (n === "Object" && o.constructor) n = o.constructor.name; | ||
if (n === "Map" || n === "Set") return Array.from(o); | ||
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); | ||
} | ||
function _arrayLikeToArray(arr, len) { | ||
if (len == null || len > arr.length) len = arr.length; | ||
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
function _nonIterableRest() { | ||
throw new TypeError("Invalid attempt to destructure non-iterable instance"); | ||
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
function _toPrimitive(input, hint) { | ||
if (typeof input !== "object" || input === null) return input; | ||
var prim = input[Symbol.toPrimitive]; | ||
if (prim !== undefined) { | ||
var res = prim.call(input, hint || "default"); | ||
if (typeof res !== "object") return res; | ||
throw new TypeError("@@toPrimitive must return a primitive value."); | ||
} | ||
return (hint === "string" ? String : Number)(input); | ||
} | ||
function _toPropertyKey(arg) { | ||
var key = _toPrimitive(arg, "string"); | ||
return typeof key === "symbol" ? key : String(key); | ||
} | ||
@@ -199,2 +237,3 @@ function createCommonjsModule(fn, module) { | ||
array: shim, | ||
bigint: shim, | ||
bool: shim, | ||
@@ -243,2 +282,15 @@ func: shim, | ||
var safeIsNaN = Number.isNaN || | ||
function ponyfill(value) { | ||
return typeof value === 'number' && value !== value; | ||
}; | ||
function isEqual(first, second) { | ||
if (first === second) { | ||
return true; | ||
} | ||
if (safeIsNaN(first) && safeIsNaN(second)) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
function areInputsEqual(newInputs, lastInputs) { | ||
@@ -249,3 +301,3 @@ if (newInputs.length !== lastInputs.length) { | ||
for (var i = 0; i < newInputs.length; i++) { | ||
if (newInputs[i] !== lastInputs[i]) { | ||
if (!isEqual(newInputs[i], lastInputs[i])) { | ||
return false; | ||
@@ -293,4 +345,5 @@ } | ||
return new Date(date.getFullYear(), date.getMonth(), date.getDate()); | ||
} // obj can be a parseable string, a millisecond timestamp, or a Date object | ||
} | ||
// obj can be a parseable string, a millisecond timestamp, or a Date object | ||
function convertToDate(obj) { | ||
@@ -307,7 +360,5 @@ return obj instanceof Date ? obj : new Date(obj); | ||
var arr = []; | ||
for (var idx = 0; idx < count; idx += 1) { | ||
arr.push(idx); | ||
} | ||
return arr; | ||
@@ -319,21 +370,12 @@ } | ||
var CSS_PSEDUO_NAMESPACE = 'react-calendar-heatmap-'; | ||
var CalendarHeatmap = | ||
/*#__PURE__*/ | ||
function (_React$Component) { | ||
var CalendarHeatmap = /*#__PURE__*/function (_React$Component) { | ||
_inherits(CalendarHeatmap, _React$Component); | ||
var _super = _createSuper(CalendarHeatmap); | ||
function CalendarHeatmap() { | ||
var _getPrototypeOf2; | ||
var _this; | ||
_classCallCheck(this, CalendarHeatmap); | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
_this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(CalendarHeatmap)).call.apply(_getPrototypeOf2, [this].concat(args))); | ||
_this = _super.call.apply(_super, [this].concat(args)); | ||
_defineProperty(_assertThisInitialized(_this), "getValueCache", memoizeOne(function (props) { | ||
@@ -343,4 +385,5 @@ return props.values.reduce(function (memo, value) { | ||
var utc2 = convertToUtc(_this.getStartDateWithEmptyDays()); | ||
var index = Math.floor((utc1 - utc2) / MILLISECONDS_IN_ONE_DAY); // eslint-disable-next-line no-param-reassign | ||
var index = Math.floor((utc1 - utc2) / MILLISECONDS_IN_ONE_DAY); | ||
// eslint-disable-next-line no-param-reassign | ||
memo[index] = { | ||
@@ -355,6 +398,4 @@ value: value, | ||
})); | ||
return _this; | ||
} | ||
_createClass(CalendarHeatmap, [{ | ||
@@ -364,3 +405,2 @@ key: "getDateDifferenceInDays", | ||
var numDays = this.props.numDays; | ||
if (numDays) { | ||
@@ -371,3 +411,2 @@ // eslint-disable-next-line no-console | ||
} | ||
var utc1 = convertToUtc(this.getStartDate()); | ||
@@ -389,7 +428,5 @@ var utc2 = convertToUtc(shiftDate(this.getEndDate(), 1)); // shift date 1 because end date is inclusive | ||
} | ||
if (this.props.horizontal) { | ||
return SQUARE_SIZE + MONTH_LABEL_GUTTER_SIZE; | ||
} | ||
return 2 * (SQUARE_SIZE + MONTH_LABEL_GUTTER_SIZE); | ||
@@ -403,7 +440,5 @@ } | ||
} | ||
if (this.props.horizontal) { | ||
return 30; | ||
} | ||
return SQUARE_SIZE * 1.5; | ||
@@ -463,3 +498,2 @@ } | ||
} | ||
return null; | ||
@@ -473,3 +507,2 @@ } | ||
} | ||
return this.props.classForValue(null); | ||
@@ -483,3 +516,2 @@ } | ||
} | ||
return this.props.titleForValue ? this.props.titleForValue(null) : null; | ||
@@ -493,3 +525,2 @@ } | ||
} | ||
return this.getTooltipDataAttrsForValue({ | ||
@@ -504,7 +535,5 @@ date: null, | ||
var tooltipDataAttrs = this.props.tooltipDataAttrs; | ||
if (typeof tooltipDataAttrs === 'function') { | ||
return tooltipDataAttrs(value); | ||
} | ||
return tooltipDataAttrs; | ||
@@ -518,3 +547,2 @@ } | ||
} | ||
return "translate(0, ".concat(weekIndex * this.getSquareSizeWithGutter(), ")"); | ||
@@ -528,3 +556,2 @@ } | ||
} | ||
return null; | ||
@@ -538,3 +565,2 @@ } | ||
} | ||
return "translate(".concat(this.getWeekWidth() + MONTH_LABEL_GUTTER_SIZE, ", ").concat(this.getWeekdayLabelSize(), ")"); | ||
@@ -548,3 +574,2 @@ } | ||
} | ||
return "translate(0, ".concat(this.getWeekdayLabelSize(), ")"); | ||
@@ -558,3 +583,2 @@ } | ||
} | ||
return "0 0 ".concat(this.getHeight(), " ").concat(this.getWidth()); | ||
@@ -568,3 +592,2 @@ } | ||
} | ||
return [dayIndex * this.getSquareSizeWithGutter(), 0]; | ||
@@ -578,3 +601,2 @@ } | ||
} | ||
return [dayIndex * SQUARE_SIZE + dayIndex * this.props.gutterSize, SQUARE_SIZE]; | ||
@@ -588,3 +610,2 @@ } | ||
} | ||
var verticalOffset = -2; | ||
@@ -618,16 +639,14 @@ return [0, (weekIndex + 1) * this.getSquareSizeWithGutter() + verticalOffset]; | ||
var _this2 = this; | ||
var indexOutOfRange = index < this.getNumEmptyDaysAtStart() || index >= this.getNumEmptyDaysAtStart() + this.getDateDifferenceInDays(); | ||
if (indexOutOfRange && !this.props.showOutOfRangeDays) { | ||
return null; | ||
} | ||
var _this$getSquareCoordi = this.getSquareCoordinates(dayIndex), | ||
_this$getSquareCoordi2 = _slicedToArray(_this$getSquareCoordi, 2), | ||
x = _this$getSquareCoordi2[0], | ||
y = _this$getSquareCoordi2[1]; | ||
_this$getSquareCoordi2 = _slicedToArray(_this$getSquareCoordi, 2), | ||
x = _this$getSquareCoordi2[0], | ||
y = _this$getSquareCoordi2[1]; | ||
var value = this.getValueForIndex(index); | ||
var rect = // eslint-disable-next-line jsx-a11y/mouse-events-have-key-events | ||
var rect = | ||
/*#__PURE__*/ | ||
// eslint-disable-next-line jsx-a11y/mouse-events-have-key-events | ||
React.createElement("rect", _extends({ | ||
@@ -649,3 +668,3 @@ key: index, | ||
} | ||
}, this.getTooltipDataAttrsForIndex(index)), React.createElement("title", null, this.getTitleForIndex(index))); | ||
}, this.getTooltipDataAttrsForIndex(index)), /*#__PURE__*/React.createElement("title", null, this.getTitleForIndex(index))); | ||
var transformDayElement = this.props.transformDayElement; | ||
@@ -658,4 +677,3 @@ return transformDayElement ? transformDayElement(rect, value, index) : rect; | ||
var _this3 = this; | ||
return React.createElement("g", { | ||
return /*#__PURE__*/React.createElement("g", { | ||
key: weekIndex, | ||
@@ -672,3 +690,2 @@ transform: this.getTransformForWeek(weekIndex), | ||
var _this4 = this; | ||
return getRange(this.getWeekCount()).map(function (weekIndex) { | ||
@@ -682,18 +699,13 @@ return _this4.renderWeek(weekIndex); | ||
var _this5 = this; | ||
if (!this.props.showMonthLabels) { | ||
return null; | ||
} | ||
var weekRange = getRange(this.getWeekCount() - 1); // don't render for last week, because label will be cut off | ||
return weekRange.map(function (weekIndex) { | ||
var endOfWeek = shiftDate(_this5.getStartDateWithEmptyDays(), (weekIndex + 1) * DAYS_IN_WEEK); | ||
var _this5$getMonthLabelC = _this5.getMonthLabelCoordinates(weekIndex), | ||
_this5$getMonthLabelC2 = _slicedToArray(_this5$getMonthLabelC, 2), | ||
x = _this5$getMonthLabelC2[0], | ||
y = _this5$getMonthLabelC2[1]; | ||
return endOfWeek.getDate() >= 1 && endOfWeek.getDate() <= DAYS_IN_WEEK ? React.createElement("text", { | ||
_this5$getMonthLabelC2 = _slicedToArray(_this5$getMonthLabelC, 2), | ||
x = _this5$getMonthLabelC2[0], | ||
y = _this5$getMonthLabelC2[1]; | ||
return endOfWeek.getDate() >= 1 && endOfWeek.getDate() <= DAYS_IN_WEEK ? /*#__PURE__*/React.createElement("text", { | ||
key: weekIndex, | ||
@@ -710,16 +722,13 @@ x: x, | ||
var _this6 = this; | ||
if (!this.props.showWeekdayLabels) { | ||
return null; | ||
} | ||
return this.props.weekdayLabels.map(function (weekdayLabel, dayIndex) { | ||
var _this6$getWeekdayLabe = _this6.getWeekdayLabelCoordinates(dayIndex), | ||
_this6$getWeekdayLabe2 = _slicedToArray(_this6$getWeekdayLabe, 2), | ||
x = _this6$getWeekdayLabe2[0], | ||
y = _this6$getWeekdayLabe2[1]; | ||
var cssClasses = "".concat(_this6.props.horizontal ? '' : "".concat(CSS_PSEDUO_NAMESPACE, "small-text"), " ").concat(CSS_PSEDUO_NAMESPACE, "weekday-label"); // eslint-disable-next-line no-bitwise | ||
return dayIndex & 1 ? React.createElement("text", { | ||
_this6$getWeekdayLabe2 = _slicedToArray(_this6$getWeekdayLabe, 2), | ||
x = _this6$getWeekdayLabe2[0], | ||
y = _this6$getWeekdayLabe2[1]; | ||
var cssClasses = "".concat(_this6.props.horizontal ? '' : "".concat(CSS_PSEDUO_NAMESPACE, "small-text"), " ").concat(CSS_PSEDUO_NAMESPACE, "weekday-label"); | ||
// eslint-disable-next-line no-bitwise | ||
return dayIndex & 1 ? /*#__PURE__*/React.createElement("text", { | ||
key: "".concat(x).concat(y), | ||
@@ -736,12 +745,12 @@ x: x, | ||
this.valueCache = this.getValueCache(this.props); | ||
return React.createElement("svg", { | ||
return /*#__PURE__*/React.createElement("svg", { | ||
className: "react-calendar-heatmap", | ||
viewBox: this.getViewBox() | ||
}, React.createElement("g", { | ||
}, /*#__PURE__*/React.createElement("g", { | ||
transform: this.getTransformForMonthLabels(), | ||
className: "".concat(CSS_PSEDUO_NAMESPACE, "month-labels") | ||
}, this.renderMonthLabels()), React.createElement("g", { | ||
}, this.renderMonthLabels()), /*#__PURE__*/React.createElement("g", { | ||
transform: this.getTransformForAllWeeks(), | ||
className: "".concat(CSS_PSEDUO_NAMESPACE, "all-weeks") | ||
}, this.renderAllWeeks()), React.createElement("g", { | ||
}, this.renderAllWeeks()), /*#__PURE__*/React.createElement("g", { | ||
transform: this.getTransformForWeekdayLabels(), | ||
@@ -752,6 +761,4 @@ className: "".concat(CSS_PSEDUO_NAMESPACE, "weekday-labels") | ||
}]); | ||
return CalendarHeatmap; | ||
}(React.Component); | ||
CalendarHeatmap.propTypes = { | ||
@@ -795,4 +802,4 @@ values: propTypes.arrayOf(propTypes.shape({ | ||
transformDayElement: propTypes.func // function to further transform the svg element for a single day | ||
}; | ||
}; | ||
CalendarHeatmap.defaultProps = { | ||
@@ -799,0 +806,0 @@ numDays: null, |
import React from 'react'; | ||
function _iterableToArrayLimit(arr, i) { | ||
var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; | ||
if (null != _i) { | ||
var _s, | ||
_e, | ||
_x, | ||
_r, | ||
_arr = [], | ||
_n = !0, | ||
_d = !1; | ||
try { | ||
if (_x = (_i = _i.call(arr)).next, 0 === i) { | ||
if (Object(_i) !== _i) return; | ||
_n = !1; | ||
} else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); | ||
} catch (err) { | ||
_d = !0, _e = err; | ||
} finally { | ||
try { | ||
if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; | ||
} finally { | ||
if (_d) throw _e; | ||
} | ||
} | ||
return _arr; | ||
} | ||
} | ||
function _classCallCheck(instance, Constructor) { | ||
@@ -8,3 +35,2 @@ if (!(instance instanceof Constructor)) { | ||
} | ||
function _defineProperties(target, props) { | ||
@@ -16,13 +42,15 @@ for (var i = 0; i < props.length; i++) { | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); | ||
} | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
Object.defineProperty(Constructor, "prototype", { | ||
writable: false | ||
}); | ||
return Constructor; | ||
} | ||
function _defineProperty(obj, key, value) { | ||
key = _toPropertyKey(key); | ||
if (key in obj) { | ||
@@ -38,11 +66,8 @@ Object.defineProperty(obj, key, { | ||
} | ||
return obj; | ||
} | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
_extends = Object.assign ? Object.assign.bind() : function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
@@ -54,9 +79,6 @@ if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
function _inherits(subClass, superClass) { | ||
@@ -66,3 +88,2 @@ if (typeof superClass !== "function" && superClass !== null) { | ||
} | ||
subClass.prototype = Object.create(superClass && superClass.prototype, { | ||
@@ -75,7 +96,9 @@ constructor: { | ||
}); | ||
Object.defineProperty(subClass, "prototype", { | ||
writable: false | ||
}); | ||
if (superClass) _setPrototypeOf(subClass, superClass); | ||
} | ||
function _getPrototypeOf(o) { | ||
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { | ||
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { | ||
return o.__proto__ || Object.getPrototypeOf(o); | ||
@@ -85,12 +108,20 @@ }; | ||
} | ||
function _setPrototypeOf(o, p) { | ||
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { | ||
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { | ||
o.__proto__ = p; | ||
return o; | ||
}; | ||
return _setPrototypeOf(o, p); | ||
} | ||
function _isNativeReflectConstruct() { | ||
if (typeof Reflect === "undefined" || !Reflect.construct) return false; | ||
if (Reflect.construct.sham) return false; | ||
if (typeof Proxy === "function") return true; | ||
try { | ||
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
function _assertThisInitialized(self) { | ||
@@ -100,55 +131,62 @@ if (self === void 0) { | ||
} | ||
return self; | ||
} | ||
function _possibleConstructorReturn(self, call) { | ||
if (call && (typeof call === "object" || typeof call === "function")) { | ||
return call; | ||
} else if (call !== void 0) { | ||
throw new TypeError("Derived constructors may only return object or undefined"); | ||
} | ||
return _assertThisInitialized(self); | ||
} | ||
function _createSuper(Derived) { | ||
var hasNativeReflectConstruct = _isNativeReflectConstruct(); | ||
return function _createSuperInternal() { | ||
var Super = _getPrototypeOf(Derived), | ||
result; | ||
if (hasNativeReflectConstruct) { | ||
var NewTarget = _getPrototypeOf(this).constructor; | ||
result = Reflect.construct(Super, arguments, NewTarget); | ||
} else { | ||
result = Super.apply(this, arguments); | ||
} | ||
return _possibleConstructorReturn(this, result); | ||
}; | ||
} | ||
function _slicedToArray(arr, i) { | ||
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); | ||
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); | ||
} | ||
function _arrayWithHoles(arr) { | ||
if (Array.isArray(arr)) return arr; | ||
} | ||
function _iterableToArrayLimit(arr, i) { | ||
if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { | ||
return; | ||
} | ||
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"] != null) _i["return"](); | ||
} finally { | ||
if (_d) throw _e; | ||
} | ||
} | ||
return _arr; | ||
function _unsupportedIterableToArray(o, minLen) { | ||
if (!o) return; | ||
if (typeof o === "string") return _arrayLikeToArray(o, minLen); | ||
var n = Object.prototype.toString.call(o).slice(8, -1); | ||
if (n === "Object" && o.constructor) n = o.constructor.name; | ||
if (n === "Map" || n === "Set") return Array.from(o); | ||
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); | ||
} | ||
function _arrayLikeToArray(arr, len) { | ||
if (len == null || len > arr.length) len = arr.length; | ||
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
function _nonIterableRest() { | ||
throw new TypeError("Invalid attempt to destructure non-iterable instance"); | ||
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
function _toPrimitive(input, hint) { | ||
if (typeof input !== "object" || input === null) return input; | ||
var prim = input[Symbol.toPrimitive]; | ||
if (prim !== undefined) { | ||
var res = prim.call(input, hint || "default"); | ||
if (typeof res !== "object") return res; | ||
throw new TypeError("@@toPrimitive must return a primitive value."); | ||
} | ||
return (hint === "string" ? String : Number)(input); | ||
} | ||
function _toPropertyKey(arg) { | ||
var key = _toPrimitive(arg, "string"); | ||
return typeof key === "symbol" ? key : String(key); | ||
} | ||
@@ -194,2 +232,3 @@ function createCommonjsModule(fn, module) { | ||
array: shim, | ||
bigint: shim, | ||
bool: shim, | ||
@@ -238,2 +277,15 @@ func: shim, | ||
var safeIsNaN = Number.isNaN || | ||
function ponyfill(value) { | ||
return typeof value === 'number' && value !== value; | ||
}; | ||
function isEqual(first, second) { | ||
if (first === second) { | ||
return true; | ||
} | ||
if (safeIsNaN(first) && safeIsNaN(second)) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
function areInputsEqual(newInputs, lastInputs) { | ||
@@ -244,3 +296,3 @@ if (newInputs.length !== lastInputs.length) { | ||
for (var i = 0; i < newInputs.length; i++) { | ||
if (newInputs[i] !== lastInputs[i]) { | ||
if (!isEqual(newInputs[i], lastInputs[i])) { | ||
return false; | ||
@@ -288,4 +340,5 @@ } | ||
return new Date(date.getFullYear(), date.getMonth(), date.getDate()); | ||
} // obj can be a parseable string, a millisecond timestamp, or a Date object | ||
} | ||
// obj can be a parseable string, a millisecond timestamp, or a Date object | ||
function convertToDate(obj) { | ||
@@ -302,7 +355,5 @@ return obj instanceof Date ? obj : new Date(obj); | ||
var arr = []; | ||
for (var idx = 0; idx < count; idx += 1) { | ||
arr.push(idx); | ||
} | ||
return arr; | ||
@@ -314,21 +365,12 @@ } | ||
var CSS_PSEDUO_NAMESPACE = 'react-calendar-heatmap-'; | ||
var CalendarHeatmap = | ||
/*#__PURE__*/ | ||
function (_React$Component) { | ||
var CalendarHeatmap = /*#__PURE__*/function (_React$Component) { | ||
_inherits(CalendarHeatmap, _React$Component); | ||
var _super = _createSuper(CalendarHeatmap); | ||
function CalendarHeatmap() { | ||
var _getPrototypeOf2; | ||
var _this; | ||
_classCallCheck(this, CalendarHeatmap); | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
_this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(CalendarHeatmap)).call.apply(_getPrototypeOf2, [this].concat(args))); | ||
_this = _super.call.apply(_super, [this].concat(args)); | ||
_defineProperty(_assertThisInitialized(_this), "getValueCache", memoizeOne(function (props) { | ||
@@ -338,4 +380,5 @@ return props.values.reduce(function (memo, value) { | ||
var utc2 = convertToUtc(_this.getStartDateWithEmptyDays()); | ||
var index = Math.floor((utc1 - utc2) / MILLISECONDS_IN_ONE_DAY); // eslint-disable-next-line no-param-reassign | ||
var index = Math.floor((utc1 - utc2) / MILLISECONDS_IN_ONE_DAY); | ||
// eslint-disable-next-line no-param-reassign | ||
memo[index] = { | ||
@@ -350,6 +393,4 @@ value: value, | ||
})); | ||
return _this; | ||
} | ||
_createClass(CalendarHeatmap, [{ | ||
@@ -359,3 +400,2 @@ key: "getDateDifferenceInDays", | ||
var numDays = this.props.numDays; | ||
if (numDays) { | ||
@@ -366,3 +406,2 @@ // eslint-disable-next-line no-console | ||
} | ||
var utc1 = convertToUtc(this.getStartDate()); | ||
@@ -384,7 +423,5 @@ var utc2 = convertToUtc(shiftDate(this.getEndDate(), 1)); // shift date 1 because end date is inclusive | ||
} | ||
if (this.props.horizontal) { | ||
return SQUARE_SIZE + MONTH_LABEL_GUTTER_SIZE; | ||
} | ||
return 2 * (SQUARE_SIZE + MONTH_LABEL_GUTTER_SIZE); | ||
@@ -398,7 +435,5 @@ } | ||
} | ||
if (this.props.horizontal) { | ||
return 30; | ||
} | ||
return SQUARE_SIZE * 1.5; | ||
@@ -458,3 +493,2 @@ } | ||
} | ||
return null; | ||
@@ -468,3 +502,2 @@ } | ||
} | ||
return this.props.classForValue(null); | ||
@@ -478,3 +511,2 @@ } | ||
} | ||
return this.props.titleForValue ? this.props.titleForValue(null) : null; | ||
@@ -488,3 +520,2 @@ } | ||
} | ||
return this.getTooltipDataAttrsForValue({ | ||
@@ -499,7 +530,5 @@ date: null, | ||
var tooltipDataAttrs = this.props.tooltipDataAttrs; | ||
if (typeof tooltipDataAttrs === 'function') { | ||
return tooltipDataAttrs(value); | ||
} | ||
return tooltipDataAttrs; | ||
@@ -513,3 +542,2 @@ } | ||
} | ||
return "translate(0, ".concat(weekIndex * this.getSquareSizeWithGutter(), ")"); | ||
@@ -523,3 +551,2 @@ } | ||
} | ||
return null; | ||
@@ -533,3 +560,2 @@ } | ||
} | ||
return "translate(".concat(this.getWeekWidth() + MONTH_LABEL_GUTTER_SIZE, ", ").concat(this.getWeekdayLabelSize(), ")"); | ||
@@ -543,3 +569,2 @@ } | ||
} | ||
return "translate(0, ".concat(this.getWeekdayLabelSize(), ")"); | ||
@@ -553,3 +578,2 @@ } | ||
} | ||
return "0 0 ".concat(this.getHeight(), " ").concat(this.getWidth()); | ||
@@ -563,3 +587,2 @@ } | ||
} | ||
return [dayIndex * this.getSquareSizeWithGutter(), 0]; | ||
@@ -573,3 +596,2 @@ } | ||
} | ||
return [dayIndex * SQUARE_SIZE + dayIndex * this.props.gutterSize, SQUARE_SIZE]; | ||
@@ -583,3 +605,2 @@ } | ||
} | ||
var verticalOffset = -2; | ||
@@ -613,16 +634,14 @@ return [0, (weekIndex + 1) * this.getSquareSizeWithGutter() + verticalOffset]; | ||
var _this2 = this; | ||
var indexOutOfRange = index < this.getNumEmptyDaysAtStart() || index >= this.getNumEmptyDaysAtStart() + this.getDateDifferenceInDays(); | ||
if (indexOutOfRange && !this.props.showOutOfRangeDays) { | ||
return null; | ||
} | ||
var _this$getSquareCoordi = this.getSquareCoordinates(dayIndex), | ||
_this$getSquareCoordi2 = _slicedToArray(_this$getSquareCoordi, 2), | ||
x = _this$getSquareCoordi2[0], | ||
y = _this$getSquareCoordi2[1]; | ||
_this$getSquareCoordi2 = _slicedToArray(_this$getSquareCoordi, 2), | ||
x = _this$getSquareCoordi2[0], | ||
y = _this$getSquareCoordi2[1]; | ||
var value = this.getValueForIndex(index); | ||
var rect = // eslint-disable-next-line jsx-a11y/mouse-events-have-key-events | ||
var rect = | ||
/*#__PURE__*/ | ||
// eslint-disable-next-line jsx-a11y/mouse-events-have-key-events | ||
React.createElement("rect", _extends({ | ||
@@ -644,3 +663,3 @@ key: index, | ||
} | ||
}, this.getTooltipDataAttrsForIndex(index)), React.createElement("title", null, this.getTitleForIndex(index))); | ||
}, this.getTooltipDataAttrsForIndex(index)), /*#__PURE__*/React.createElement("title", null, this.getTitleForIndex(index))); | ||
var transformDayElement = this.props.transformDayElement; | ||
@@ -653,4 +672,3 @@ return transformDayElement ? transformDayElement(rect, value, index) : rect; | ||
var _this3 = this; | ||
return React.createElement("g", { | ||
return /*#__PURE__*/React.createElement("g", { | ||
key: weekIndex, | ||
@@ -667,3 +685,2 @@ transform: this.getTransformForWeek(weekIndex), | ||
var _this4 = this; | ||
return getRange(this.getWeekCount()).map(function (weekIndex) { | ||
@@ -677,18 +694,13 @@ return _this4.renderWeek(weekIndex); | ||
var _this5 = this; | ||
if (!this.props.showMonthLabels) { | ||
return null; | ||
} | ||
var weekRange = getRange(this.getWeekCount() - 1); // don't render for last week, because label will be cut off | ||
return weekRange.map(function (weekIndex) { | ||
var endOfWeek = shiftDate(_this5.getStartDateWithEmptyDays(), (weekIndex + 1) * DAYS_IN_WEEK); | ||
var _this5$getMonthLabelC = _this5.getMonthLabelCoordinates(weekIndex), | ||
_this5$getMonthLabelC2 = _slicedToArray(_this5$getMonthLabelC, 2), | ||
x = _this5$getMonthLabelC2[0], | ||
y = _this5$getMonthLabelC2[1]; | ||
return endOfWeek.getDate() >= 1 && endOfWeek.getDate() <= DAYS_IN_WEEK ? React.createElement("text", { | ||
_this5$getMonthLabelC2 = _slicedToArray(_this5$getMonthLabelC, 2), | ||
x = _this5$getMonthLabelC2[0], | ||
y = _this5$getMonthLabelC2[1]; | ||
return endOfWeek.getDate() >= 1 && endOfWeek.getDate() <= DAYS_IN_WEEK ? /*#__PURE__*/React.createElement("text", { | ||
key: weekIndex, | ||
@@ -705,16 +717,13 @@ x: x, | ||
var _this6 = this; | ||
if (!this.props.showWeekdayLabels) { | ||
return null; | ||
} | ||
return this.props.weekdayLabels.map(function (weekdayLabel, dayIndex) { | ||
var _this6$getWeekdayLabe = _this6.getWeekdayLabelCoordinates(dayIndex), | ||
_this6$getWeekdayLabe2 = _slicedToArray(_this6$getWeekdayLabe, 2), | ||
x = _this6$getWeekdayLabe2[0], | ||
y = _this6$getWeekdayLabe2[1]; | ||
var cssClasses = "".concat(_this6.props.horizontal ? '' : "".concat(CSS_PSEDUO_NAMESPACE, "small-text"), " ").concat(CSS_PSEDUO_NAMESPACE, "weekday-label"); // eslint-disable-next-line no-bitwise | ||
return dayIndex & 1 ? React.createElement("text", { | ||
_this6$getWeekdayLabe2 = _slicedToArray(_this6$getWeekdayLabe, 2), | ||
x = _this6$getWeekdayLabe2[0], | ||
y = _this6$getWeekdayLabe2[1]; | ||
var cssClasses = "".concat(_this6.props.horizontal ? '' : "".concat(CSS_PSEDUO_NAMESPACE, "small-text"), " ").concat(CSS_PSEDUO_NAMESPACE, "weekday-label"); | ||
// eslint-disable-next-line no-bitwise | ||
return dayIndex & 1 ? /*#__PURE__*/React.createElement("text", { | ||
key: "".concat(x).concat(y), | ||
@@ -731,12 +740,12 @@ x: x, | ||
this.valueCache = this.getValueCache(this.props); | ||
return React.createElement("svg", { | ||
return /*#__PURE__*/React.createElement("svg", { | ||
className: "react-calendar-heatmap", | ||
viewBox: this.getViewBox() | ||
}, React.createElement("g", { | ||
}, /*#__PURE__*/React.createElement("g", { | ||
transform: this.getTransformForMonthLabels(), | ||
className: "".concat(CSS_PSEDUO_NAMESPACE, "month-labels") | ||
}, this.renderMonthLabels()), React.createElement("g", { | ||
}, this.renderMonthLabels()), /*#__PURE__*/React.createElement("g", { | ||
transform: this.getTransformForAllWeeks(), | ||
className: "".concat(CSS_PSEDUO_NAMESPACE, "all-weeks") | ||
}, this.renderAllWeeks()), React.createElement("g", { | ||
}, this.renderAllWeeks()), /*#__PURE__*/React.createElement("g", { | ||
transform: this.getTransformForWeekdayLabels(), | ||
@@ -747,6 +756,4 @@ className: "".concat(CSS_PSEDUO_NAMESPACE, "weekday-labels") | ||
}]); | ||
return CalendarHeatmap; | ||
}(React.Component); | ||
CalendarHeatmap.propTypes = { | ||
@@ -790,4 +797,4 @@ values: propTypes.arrayOf(propTypes.shape({ | ||
transformDayElement: propTypes.func // function to further transform the svg element for a single day | ||
}; | ||
}; | ||
CalendarHeatmap.defaultProps = { | ||
@@ -794,0 +801,0 @@ numDays: null, |
@@ -7,4 +7,31 @@ (function (global, factory) { | ||
React = React && React.hasOwnProperty('default') ? React['default'] : React; | ||
React = React && Object.prototype.hasOwnProperty.call(React, 'default') ? React['default'] : React; | ||
function _iterableToArrayLimit(arr, i) { | ||
var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; | ||
if (null != _i) { | ||
var _s, | ||
_e, | ||
_x, | ||
_r, | ||
_arr = [], | ||
_n = !0, | ||
_d = !1; | ||
try { | ||
if (_x = (_i = _i.call(arr)).next, 0 === i) { | ||
if (Object(_i) !== _i) return; | ||
_n = !1; | ||
} else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); | ||
} catch (err) { | ||
_d = !0, _e = err; | ||
} finally { | ||
try { | ||
if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; | ||
} finally { | ||
if (_d) throw _e; | ||
} | ||
} | ||
return _arr; | ||
} | ||
} | ||
function _classCallCheck(instance, Constructor) { | ||
@@ -15,3 +42,2 @@ if (!(instance instanceof Constructor)) { | ||
} | ||
function _defineProperties(target, props) { | ||
@@ -23,13 +49,15 @@ for (var i = 0; i < props.length; i++) { | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); | ||
} | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
Object.defineProperty(Constructor, "prototype", { | ||
writable: false | ||
}); | ||
return Constructor; | ||
} | ||
function _defineProperty(obj, key, value) { | ||
key = _toPropertyKey(key); | ||
if (key in obj) { | ||
@@ -45,11 +73,8 @@ Object.defineProperty(obj, key, { | ||
} | ||
return obj; | ||
} | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
_extends = Object.assign ? Object.assign.bind() : function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
@@ -61,9 +86,6 @@ if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
function _inherits(subClass, superClass) { | ||
@@ -73,3 +95,2 @@ if (typeof superClass !== "function" && superClass !== null) { | ||
} | ||
subClass.prototype = Object.create(superClass && superClass.prototype, { | ||
@@ -82,7 +103,9 @@ constructor: { | ||
}); | ||
Object.defineProperty(subClass, "prototype", { | ||
writable: false | ||
}); | ||
if (superClass) _setPrototypeOf(subClass, superClass); | ||
} | ||
function _getPrototypeOf(o) { | ||
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { | ||
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { | ||
return o.__proto__ || Object.getPrototypeOf(o); | ||
@@ -92,12 +115,20 @@ }; | ||
} | ||
function _setPrototypeOf(o, p) { | ||
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { | ||
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { | ||
o.__proto__ = p; | ||
return o; | ||
}; | ||
return _setPrototypeOf(o, p); | ||
} | ||
function _isNativeReflectConstruct() { | ||
if (typeof Reflect === "undefined" || !Reflect.construct) return false; | ||
if (Reflect.construct.sham) return false; | ||
if (typeof Proxy === "function") return true; | ||
try { | ||
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
function _assertThisInitialized(self) { | ||
@@ -107,55 +138,62 @@ if (self === void 0) { | ||
} | ||
return self; | ||
} | ||
function _possibleConstructorReturn(self, call) { | ||
if (call && (typeof call === "object" || typeof call === "function")) { | ||
return call; | ||
} else if (call !== void 0) { | ||
throw new TypeError("Derived constructors may only return object or undefined"); | ||
} | ||
return _assertThisInitialized(self); | ||
} | ||
function _createSuper(Derived) { | ||
var hasNativeReflectConstruct = _isNativeReflectConstruct(); | ||
return function _createSuperInternal() { | ||
var Super = _getPrototypeOf(Derived), | ||
result; | ||
if (hasNativeReflectConstruct) { | ||
var NewTarget = _getPrototypeOf(this).constructor; | ||
result = Reflect.construct(Super, arguments, NewTarget); | ||
} else { | ||
result = Super.apply(this, arguments); | ||
} | ||
return _possibleConstructorReturn(this, result); | ||
}; | ||
} | ||
function _slicedToArray(arr, i) { | ||
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); | ||
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); | ||
} | ||
function _arrayWithHoles(arr) { | ||
if (Array.isArray(arr)) return arr; | ||
} | ||
function _iterableToArrayLimit(arr, i) { | ||
if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { | ||
return; | ||
} | ||
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"] != null) _i["return"](); | ||
} finally { | ||
if (_d) throw _e; | ||
} | ||
} | ||
return _arr; | ||
function _unsupportedIterableToArray(o, minLen) { | ||
if (!o) return; | ||
if (typeof o === "string") return _arrayLikeToArray(o, minLen); | ||
var n = Object.prototype.toString.call(o).slice(8, -1); | ||
if (n === "Object" && o.constructor) n = o.constructor.name; | ||
if (n === "Map" || n === "Set") return Array.from(o); | ||
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); | ||
} | ||
function _arrayLikeToArray(arr, len) { | ||
if (len == null || len > arr.length) len = arr.length; | ||
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
function _nonIterableRest() { | ||
throw new TypeError("Invalid attempt to destructure non-iterable instance"); | ||
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
function _toPrimitive(input, hint) { | ||
if (typeof input !== "object" || input === null) return input; | ||
var prim = input[Symbol.toPrimitive]; | ||
if (prim !== undefined) { | ||
var res = prim.call(input, hint || "default"); | ||
if (typeof res !== "object") return res; | ||
throw new TypeError("@@toPrimitive must return a primitive value."); | ||
} | ||
return (hint === "string" ? String : Number)(input); | ||
} | ||
function _toPropertyKey(arg) { | ||
var key = _toPrimitive(arg, "string"); | ||
return typeof key === "symbol" ? key : String(key); | ||
} | ||
@@ -201,2 +239,3 @@ function createCommonjsModule(fn, module) { | ||
array: shim, | ||
bigint: shim, | ||
bool: shim, | ||
@@ -245,2 +284,15 @@ func: shim, | ||
var safeIsNaN = Number.isNaN || | ||
function ponyfill(value) { | ||
return typeof value === 'number' && value !== value; | ||
}; | ||
function isEqual(first, second) { | ||
if (first === second) { | ||
return true; | ||
} | ||
if (safeIsNaN(first) && safeIsNaN(second)) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
function areInputsEqual(newInputs, lastInputs) { | ||
@@ -251,3 +303,3 @@ if (newInputs.length !== lastInputs.length) { | ||
for (var i = 0; i < newInputs.length; i++) { | ||
if (newInputs[i] !== lastInputs[i]) { | ||
if (!isEqual(newInputs[i], lastInputs[i])) { | ||
return false; | ||
@@ -295,4 +347,5 @@ } | ||
return new Date(date.getFullYear(), date.getMonth(), date.getDate()); | ||
} // obj can be a parseable string, a millisecond timestamp, or a Date object | ||
} | ||
// obj can be a parseable string, a millisecond timestamp, or a Date object | ||
function convertToDate(obj) { | ||
@@ -309,7 +362,5 @@ return obj instanceof Date ? obj : new Date(obj); | ||
var arr = []; | ||
for (var idx = 0; idx < count; idx += 1) { | ||
arr.push(idx); | ||
} | ||
return arr; | ||
@@ -321,21 +372,12 @@ } | ||
var CSS_PSEDUO_NAMESPACE = 'react-calendar-heatmap-'; | ||
var CalendarHeatmap = | ||
/*#__PURE__*/ | ||
function (_React$Component) { | ||
var CalendarHeatmap = /*#__PURE__*/function (_React$Component) { | ||
_inherits(CalendarHeatmap, _React$Component); | ||
var _super = _createSuper(CalendarHeatmap); | ||
function CalendarHeatmap() { | ||
var _getPrototypeOf2; | ||
var _this; | ||
_classCallCheck(this, CalendarHeatmap); | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
_this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(CalendarHeatmap)).call.apply(_getPrototypeOf2, [this].concat(args))); | ||
_this = _super.call.apply(_super, [this].concat(args)); | ||
_defineProperty(_assertThisInitialized(_this), "getValueCache", memoizeOne(function (props) { | ||
@@ -345,4 +387,5 @@ return props.values.reduce(function (memo, value) { | ||
var utc2 = convertToUtc(_this.getStartDateWithEmptyDays()); | ||
var index = Math.floor((utc1 - utc2) / MILLISECONDS_IN_ONE_DAY); // eslint-disable-next-line no-param-reassign | ||
var index = Math.floor((utc1 - utc2) / MILLISECONDS_IN_ONE_DAY); | ||
// eslint-disable-next-line no-param-reassign | ||
memo[index] = { | ||
@@ -357,6 +400,4 @@ value: value, | ||
})); | ||
return _this; | ||
} | ||
_createClass(CalendarHeatmap, [{ | ||
@@ -366,3 +407,2 @@ key: "getDateDifferenceInDays", | ||
var numDays = this.props.numDays; | ||
if (numDays) { | ||
@@ -373,3 +413,2 @@ // eslint-disable-next-line no-console | ||
} | ||
var utc1 = convertToUtc(this.getStartDate()); | ||
@@ -391,7 +430,5 @@ var utc2 = convertToUtc(shiftDate(this.getEndDate(), 1)); // shift date 1 because end date is inclusive | ||
} | ||
if (this.props.horizontal) { | ||
return SQUARE_SIZE + MONTH_LABEL_GUTTER_SIZE; | ||
} | ||
return 2 * (SQUARE_SIZE + MONTH_LABEL_GUTTER_SIZE); | ||
@@ -405,7 +442,5 @@ } | ||
} | ||
if (this.props.horizontal) { | ||
return 30; | ||
} | ||
return SQUARE_SIZE * 1.5; | ||
@@ -465,3 +500,2 @@ } | ||
} | ||
return null; | ||
@@ -475,3 +509,2 @@ } | ||
} | ||
return this.props.classForValue(null); | ||
@@ -485,3 +518,2 @@ } | ||
} | ||
return this.props.titleForValue ? this.props.titleForValue(null) : null; | ||
@@ -495,3 +527,2 @@ } | ||
} | ||
return this.getTooltipDataAttrsForValue({ | ||
@@ -506,7 +537,5 @@ date: null, | ||
var tooltipDataAttrs = this.props.tooltipDataAttrs; | ||
if (typeof tooltipDataAttrs === 'function') { | ||
return tooltipDataAttrs(value); | ||
} | ||
return tooltipDataAttrs; | ||
@@ -520,3 +549,2 @@ } | ||
} | ||
return "translate(0, ".concat(weekIndex * this.getSquareSizeWithGutter(), ")"); | ||
@@ -530,3 +558,2 @@ } | ||
} | ||
return null; | ||
@@ -540,3 +567,2 @@ } | ||
} | ||
return "translate(".concat(this.getWeekWidth() + MONTH_LABEL_GUTTER_SIZE, ", ").concat(this.getWeekdayLabelSize(), ")"); | ||
@@ -550,3 +576,2 @@ } | ||
} | ||
return "translate(0, ".concat(this.getWeekdayLabelSize(), ")"); | ||
@@ -560,3 +585,2 @@ } | ||
} | ||
return "0 0 ".concat(this.getHeight(), " ").concat(this.getWidth()); | ||
@@ -570,3 +594,2 @@ } | ||
} | ||
return [dayIndex * this.getSquareSizeWithGutter(), 0]; | ||
@@ -580,3 +603,2 @@ } | ||
} | ||
return [dayIndex * SQUARE_SIZE + dayIndex * this.props.gutterSize, SQUARE_SIZE]; | ||
@@ -590,3 +612,2 @@ } | ||
} | ||
var verticalOffset = -2; | ||
@@ -620,16 +641,14 @@ return [0, (weekIndex + 1) * this.getSquareSizeWithGutter() + verticalOffset]; | ||
var _this2 = this; | ||
var indexOutOfRange = index < this.getNumEmptyDaysAtStart() || index >= this.getNumEmptyDaysAtStart() + this.getDateDifferenceInDays(); | ||
if (indexOutOfRange && !this.props.showOutOfRangeDays) { | ||
return null; | ||
} | ||
var _this$getSquareCoordi = this.getSquareCoordinates(dayIndex), | ||
_this$getSquareCoordi2 = _slicedToArray(_this$getSquareCoordi, 2), | ||
x = _this$getSquareCoordi2[0], | ||
y = _this$getSquareCoordi2[1]; | ||
_this$getSquareCoordi2 = _slicedToArray(_this$getSquareCoordi, 2), | ||
x = _this$getSquareCoordi2[0], | ||
y = _this$getSquareCoordi2[1]; | ||
var value = this.getValueForIndex(index); | ||
var rect = // eslint-disable-next-line jsx-a11y/mouse-events-have-key-events | ||
var rect = | ||
/*#__PURE__*/ | ||
// eslint-disable-next-line jsx-a11y/mouse-events-have-key-events | ||
React.createElement("rect", _extends({ | ||
@@ -651,3 +670,3 @@ key: index, | ||
} | ||
}, this.getTooltipDataAttrsForIndex(index)), React.createElement("title", null, this.getTitleForIndex(index))); | ||
}, this.getTooltipDataAttrsForIndex(index)), /*#__PURE__*/React.createElement("title", null, this.getTitleForIndex(index))); | ||
var transformDayElement = this.props.transformDayElement; | ||
@@ -660,4 +679,3 @@ return transformDayElement ? transformDayElement(rect, value, index) : rect; | ||
var _this3 = this; | ||
return React.createElement("g", { | ||
return /*#__PURE__*/React.createElement("g", { | ||
key: weekIndex, | ||
@@ -674,3 +692,2 @@ transform: this.getTransformForWeek(weekIndex), | ||
var _this4 = this; | ||
return getRange(this.getWeekCount()).map(function (weekIndex) { | ||
@@ -684,18 +701,13 @@ return _this4.renderWeek(weekIndex); | ||
var _this5 = this; | ||
if (!this.props.showMonthLabels) { | ||
return null; | ||
} | ||
var weekRange = getRange(this.getWeekCount() - 1); // don't render for last week, because label will be cut off | ||
return weekRange.map(function (weekIndex) { | ||
var endOfWeek = shiftDate(_this5.getStartDateWithEmptyDays(), (weekIndex + 1) * DAYS_IN_WEEK); | ||
var _this5$getMonthLabelC = _this5.getMonthLabelCoordinates(weekIndex), | ||
_this5$getMonthLabelC2 = _slicedToArray(_this5$getMonthLabelC, 2), | ||
x = _this5$getMonthLabelC2[0], | ||
y = _this5$getMonthLabelC2[1]; | ||
return endOfWeek.getDate() >= 1 && endOfWeek.getDate() <= DAYS_IN_WEEK ? React.createElement("text", { | ||
_this5$getMonthLabelC2 = _slicedToArray(_this5$getMonthLabelC, 2), | ||
x = _this5$getMonthLabelC2[0], | ||
y = _this5$getMonthLabelC2[1]; | ||
return endOfWeek.getDate() >= 1 && endOfWeek.getDate() <= DAYS_IN_WEEK ? /*#__PURE__*/React.createElement("text", { | ||
key: weekIndex, | ||
@@ -712,16 +724,13 @@ x: x, | ||
var _this6 = this; | ||
if (!this.props.showWeekdayLabels) { | ||
return null; | ||
} | ||
return this.props.weekdayLabels.map(function (weekdayLabel, dayIndex) { | ||
var _this6$getWeekdayLabe = _this6.getWeekdayLabelCoordinates(dayIndex), | ||
_this6$getWeekdayLabe2 = _slicedToArray(_this6$getWeekdayLabe, 2), | ||
x = _this6$getWeekdayLabe2[0], | ||
y = _this6$getWeekdayLabe2[1]; | ||
var cssClasses = "".concat(_this6.props.horizontal ? '' : "".concat(CSS_PSEDUO_NAMESPACE, "small-text"), " ").concat(CSS_PSEDUO_NAMESPACE, "weekday-label"); // eslint-disable-next-line no-bitwise | ||
return dayIndex & 1 ? React.createElement("text", { | ||
_this6$getWeekdayLabe2 = _slicedToArray(_this6$getWeekdayLabe, 2), | ||
x = _this6$getWeekdayLabe2[0], | ||
y = _this6$getWeekdayLabe2[1]; | ||
var cssClasses = "".concat(_this6.props.horizontal ? '' : "".concat(CSS_PSEDUO_NAMESPACE, "small-text"), " ").concat(CSS_PSEDUO_NAMESPACE, "weekday-label"); | ||
// eslint-disable-next-line no-bitwise | ||
return dayIndex & 1 ? /*#__PURE__*/React.createElement("text", { | ||
key: "".concat(x).concat(y), | ||
@@ -738,12 +747,12 @@ x: x, | ||
this.valueCache = this.getValueCache(this.props); | ||
return React.createElement("svg", { | ||
return /*#__PURE__*/React.createElement("svg", { | ||
className: "react-calendar-heatmap", | ||
viewBox: this.getViewBox() | ||
}, React.createElement("g", { | ||
}, /*#__PURE__*/React.createElement("g", { | ||
transform: this.getTransformForMonthLabels(), | ||
className: "".concat(CSS_PSEDUO_NAMESPACE, "month-labels") | ||
}, this.renderMonthLabels()), React.createElement("g", { | ||
}, this.renderMonthLabels()), /*#__PURE__*/React.createElement("g", { | ||
transform: this.getTransformForAllWeeks(), | ||
className: "".concat(CSS_PSEDUO_NAMESPACE, "all-weeks") | ||
}, this.renderAllWeeks()), React.createElement("g", { | ||
}, this.renderAllWeeks()), /*#__PURE__*/React.createElement("g", { | ||
transform: this.getTransformForWeekdayLabels(), | ||
@@ -754,6 +763,4 @@ className: "".concat(CSS_PSEDUO_NAMESPACE, "weekday-labels") | ||
}]); | ||
return CalendarHeatmap; | ||
}(React.Component); | ||
CalendarHeatmap.propTypes = { | ||
@@ -797,4 +804,4 @@ values: propTypes.arrayOf(propTypes.shape({ | ||
transformDayElement: propTypes.func // function to further transform the svg element for a single day | ||
}; | ||
}; | ||
CalendarHeatmap.defaultProps = { | ||
@@ -801,0 +808,0 @@ numDays: null, |
{ | ||
"name": "@freecodecamp/react-calendar-heatmap", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "A calendar heatmap component built on SVG, inspired by Github's commit calendar graph.", | ||
@@ -39,3 +39,3 @@ "author": "Kevin Qi", | ||
"peerDependencies": { | ||
"react": "^0.14.0 || ^15.0.0 || ^16.0.0" | ||
"react": "^0.14.0 || ^15.0.0 || ^16.0.0 || ^17.0.0 || ^18.0.0" | ||
}, | ||
@@ -42,0 +42,0 @@ "dependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
163585
2343
9