From 00e557f4101e574d34e8cf5dceeea63cf674ed97 Mon Sep 17 00:00:00 2001 From: Adam Ginzberg Date: Wed, 5 Feb 2020 15:11:02 -0800 Subject: [PATCH] bump memoize and migrate the fork --- .size-snapshot.json | 22 ++++---- lib/DayColumn.js | 16 +++--- lib/EventCell.js | 2 +- lib/EventRowMixin.js | 1 + lib/Popup.js | 10 ++-- lib/Selection.js | 14 ++--- lib/Views.js | 15 +++-- .../dragAndDrop/EventContainerWrapper.js | 1 - lib/addons/dragAndDrop/WeekWrapper.js | 1 - lib/addons/dragAndDrop/withDragAndDrop.js | 55 +++++++++++++++++++ lib/localizer.js | 7 +-- lib/utils/DateSlotMetrics.js | 4 +- lib/utils/messages.js | 2 +- package.json | 2 +- src/utils/DateSlotMetrics.js | 3 +- yarn.lock | 8 +-- 16 files changed, 105 insertions(+), 58 deletions(-) diff --git a/.size-snapshot.json b/.size-snapshot.json index a0d8a6920..9d003c669 100644 --- a/.size-snapshot.json +++ b/.size-snapshot.json @@ -1,25 +1,25 @@ { "./dist/react-big-calendar.js": { - "bundled": 508624, - "minified": 149246, - "gzipped": 45937 + "bundled": 506890, + "minified": 148898, + "gzipped": 45540 }, "./dist/react-big-calendar.min.js": { - "bundled": 445192, - "minified": 130121, - "gzipped": 41450 + "bundled": 444058, + "minified": 130004, + "gzipped": 41140 }, "dist/react-big-calendar.esm.js": { - "bundled": 173889, - "minified": 82988, - "gzipped": 20692, + "bundled": 173920, + "minified": 82985, + "gzipped": 20693, "treeshaked": { "rollup": { - "code": 60296, + "code": 60293, "import_statements": 1562 }, "webpack": { - "code": 64942 + "code": 64778 } } } diff --git a/lib/DayColumn.js b/lib/DayColumn.js index dc8a7414b..4761a3f50 100644 --- a/lib/DayColumn.js +++ b/lib/DayColumn.js @@ -455,16 +455,16 @@ var DayColumn = localizer = _this$props3.localizer, _this$props3$getters = _this$props3.getters, dayProp = _this$props3$getters.dayProp, - getters = (0, - _objectWithoutPropertiesLoose2.default)(_this$props3$getters, [ - 'dayProp', - ]), + getters = (0, _objectWithoutPropertiesLoose2.default)( + _this$props3$getters, + ['dayProp'] + ), _this$props3$componen = _this$props3.components, EventContainer = _this$props3$componen.eventContainerWrapper, - components = (0, - _objectWithoutPropertiesLoose2.default)(_this$props3$componen, [ - 'eventContainerWrapper', - ]) + components = (0, _objectWithoutPropertiesLoose2.default)( + _this$props3$componen, + ['eventContainerWrapper'] + ) var slotMetrics = this.slotMetrics var _this$state = this.state, selecting = _this$state.selecting, diff --git a/lib/EventCell.js b/lib/EventCell.js index 23e5f671a..d9bd20821 100644 --- a/lib/EventCell.js +++ b/lib/EventCell.js @@ -116,7 +116,7 @@ var EventCell = 'div', (0, _extends2.default)({}, props, { tabIndex: 0, - style: (0, _extends2.default)({}, userProps.style, {}, style), + style: (0, _extends2.default)({}, userProps.style, style), className: (0, _clsx.default)( 'rbc-event', className, diff --git a/lib/EventRowMixin.js b/lib/EventRowMixin.js index 620949939..67716b5ef 100644 --- a/lib/EventRowMixin.js +++ b/lib/EventRowMixin.js @@ -13,6 +13,7 @@ var _EventCell = _interopRequireDefault(require('./EventCell')) var _selection = require('./utils/selection') +/* eslint-disable react/prop-types */ var _default = { propTypes: { slotMetrics: _propTypes.default.object.isRequired, diff --git a/lib/Popup.js b/lib/Popup.js index 70d791375..213cf560a 100644 --- a/lib/Popup.js +++ b/lib/Popup.js @@ -95,7 +95,7 @@ var Popup = return _react.default.createElement( 'div', { - style: (0, _extends2.default)({}, this.props.style, {}, style), + style: (0, _extends2.default)({}, this.props.style, style), className: 'rbc-overlay', ref: popperRef, }, @@ -156,12 +156,12 @@ Popup.propTypes = current: _propTypes.default.Element, }), ]), + /** + * The Overlay component, of react-overlays, creates a ref that is passed to the Popup, and + * requires proper ref forwarding to be used without error + */ } : {} -/** - * The Overlay component, of react-overlays, creates a ref that is passed to the Popup, and - * requires proper ref forwarding to be used without error - */ var _default = _react.default.forwardRef(function(props, ref) { return _react.default.createElement( diff --git a/lib/Selection.js b/lib/Selection.js index 482f3f572..f145583d0 100644 --- a/lib/Selection.js +++ b/lib/Selection.js @@ -558,14 +558,12 @@ function objectsCollide(nodeA, nodeB, tolerance) { _getBoundsForNode2$bo = _getBoundsForNode2.bottom, bBottom = _getBoundsForNode2$bo === void 0 ? bTop : _getBoundsForNode2$bo - return !( - // 'a' bottom doesn't touch 'b' top - ( - aBottom - tolerance < bTop || // 'a' top doesn't touch 'b' bottom - aTop + tolerance > bBottom || // 'a' right doesn't touch 'b' left - aRight - tolerance < bLeft || // 'a' left doesn't touch 'b' right - aLeft + tolerance > bRight - ) + return !// 'a' bottom doesn't touch 'b' top + ( + aBottom - tolerance < bTop || // 'a' top doesn't touch 'b' bottom + aTop + tolerance > bBottom || // 'a' right doesn't touch 'b' left + aRight - tolerance < bLeft || // 'a' left doesn't touch 'b' right + aLeft + tolerance > bRight ) } /** diff --git a/lib/Views.js b/lib/Views.js index b2dda84f0..7a136fbf5 100644 --- a/lib/Views.js +++ b/lib/Views.js @@ -19,14 +19,13 @@ var _Agenda = _interopRequireDefault(require('./Agenda')) var _VIEWS -var VIEWS = - ((_VIEWS = {}), - (_VIEWS[_constants.views.MONTH] = _Month.default), - (_VIEWS[_constants.views.WEEK] = _Week.default), - (_VIEWS[_constants.views.WORK_WEEK] = _WorkWeek.default), - (_VIEWS[_constants.views.DAY] = _Day.default), - (_VIEWS[_constants.views.AGENDA] = _Agenda.default), - _VIEWS) +var VIEWS = ((_VIEWS = {}), +(_VIEWS[_constants.views.MONTH] = _Month.default), +(_VIEWS[_constants.views.WEEK] = _Week.default), +(_VIEWS[_constants.views.WORK_WEEK] = _WorkWeek.default), +(_VIEWS[_constants.views.DAY] = _Day.default), +(_VIEWS[_constants.views.AGENDA] = _Agenda.default), +_VIEWS) var _default = VIEWS exports.default = _default module.exports = exports['default'] diff --git a/lib/addons/dragAndDrop/EventContainerWrapper.js b/lib/addons/dragAndDrop/EventContainerWrapper.js index 3d8087a7d..43c8b47b9 100644 --- a/lib/addons/dragAndDrop/EventContainerWrapper.js +++ b/lib/addons/dragAndDrop/EventContainerWrapper.js @@ -318,7 +318,6 @@ var EventContainerWrapper = accessors: (0, _extends2.default)( {}, accessors, - {}, _common.dragAccessors ), continuesEarlier: startsBeforeDay, diff --git a/lib/addons/dragAndDrop/WeekWrapper.js b/lib/addons/dragAndDrop/WeekWrapper.js index 491b7b9bd..16b4c87dc 100644 --- a/lib/addons/dragAndDrop/WeekWrapper.js +++ b/lib/addons/dragAndDrop/WeekWrapper.js @@ -359,7 +359,6 @@ var WeekWrapper = accessors: (0, _extends2.default)( {}, accessors, - {}, _common.dragAccessors ), }) diff --git a/lib/addons/dragAndDrop/withDragAndDrop.js b/lib/addons/dragAndDrop/withDragAndDrop.js index 4a8717778..84483cf09 100644 --- a/lib/addons/dragAndDrop/withDragAndDrop.js +++ b/lib/addons/dragAndDrop/withDragAndDrop.js @@ -35,6 +35,61 @@ var _WeekWrapper = _interopRequireDefault(require('./WeekWrapper')) var _common = require('./common') +/** + * Creates a higher-order component (HOC) supporting drag & drop and optionally resizing + * of events: + * + * ```js + * import Calendar from 'react-big-calendar' + * import withDragAndDrop from 'react-big-calendar/lib/addons/dragAndDrop' + * export default withDragAndDrop(Calendar) + * ``` + * + * Set `resizable` to true in your calendar if you want events to be resizable. + * + * The HOC adds `onEventDrop`, `onEventResize`, and `onDragStart` callback properties if the events are + * moved or resized. These callbacks are called with these signatures: + * + * ```js + * function onEventDrop({ event, start, end, allDay }) {...} + * function onEventResize(type, { event, start, end, allDay }) {...} // type is always 'drop' + * function onDragStart({ event, action, direction }) {...} + * ``` + * + * Moving and resizing of events has some subtlety which one should be aware of. + * + * In some situations, non-allDay events are displayed in "row" format where they + * are rendered horizontally. This is the case for ALL events in a month view. It + * is also occurs with multi-day events in a day or week view (unless `showMultiDayTimes` + * is set). + * + * When dropping or resizing non-allDay events into a the header area or when + * resizing them horizontally because they are displayed in row format, their + * times are preserved, only their date is changed. + * + * If you care about these corner cases, you can examine the `allDay` param suppled + * in the callback to determine how the user dropped or resized the event. + * + * Additionally, this HOC adds the callback props `onDropFromOutside` and `onDragOver`. + * By default, the calendar will not respond to outside draggable items being dropped + * onto it. However, if `onDropFromOutside` callback is passed, then when draggable + * DOM elements are dropped on the calendar, the callback will fire, receiving an + * object with start and end times, and an allDay boolean. + * + * If `onDropFromOutside` is passed, but `onDragOver` is not, any draggable event will be + * droppable onto the calendar by default. On the other hand, if an `onDragOver` callback + * *is* passed, then it can discriminate as to whether a draggable item is droppable on the + * calendar. To designate a draggable item as droppable, call `event.preventDefault` + * inside `onDragOver`. If `event.preventDefault` is not called in the `onDragOver` + * callback, then the draggable item will not be droppable on the calendar. + * + * * ```js + * function onDropFromOutside({ start, end, allDay }) {...} + * function onDragOver(DragEvent: event) {...} + * ``` + * @param {*} Calendar + * @param {*} backend + */ function withDragAndDrop(Calendar) { var DragAndDropCalendar = /*#__PURE__*/ diff --git a/lib/localizer.js b/lib/localizer.js index 3eb9b4dea..60cd0b74a 100644 --- a/lib/localizer.js +++ b/lib/localizer.js @@ -74,12 +74,7 @@ var DateLocalizer = function DateLocalizer(spec) { exports.DateLocalizer = DateLocalizer function mergeWithDefaults(localizer, culture, formatOverrides, messages) { - var formats = (0, _extends2.default)( - {}, - localizer.formats, - {}, - formatOverrides - ) + var formats = (0, _extends2.default)({}, localizer.formats, formatOverrides) return (0, _extends2.default)({}, localizer, { messages: messages, startOfWeek: function startOfWeek() { diff --git a/lib/utils/DateSlotMetrics.js b/lib/utils/DateSlotMetrics.js index 9a65b77af..c4ceb9c5c 100644 --- a/lib/utils/DateSlotMetrics.js +++ b/lib/utils/DateSlotMetrics.js @@ -22,7 +22,7 @@ var isSegmentInSlot = function isSegmentInSlot(seg, slot) { } var isEqual = function isEqual(a, b) { - return a.range === b.range && a.events === b.events + return a[0].range === b[0].range && a[0].events === b[0].events } function getSlotMetrics() { @@ -61,7 +61,7 @@ function getSlotMetrics() { slots: range.length, clone: function clone(args) { var metrics = getSlotMetrics() - return metrics((0, _extends2.default)({}, options, {}, args)) + return metrics((0, _extends2.default)({}, options, args)) }, getDateForSlot: function getDateForSlot(slotNumber) { return range[slotNumber] diff --git a/lib/utils/messages.js b/lib/utils/messages.js index d014f26f2..cbd3e270b 100644 --- a/lib/utils/messages.js +++ b/lib/utils/messages.js @@ -31,7 +31,7 @@ var defaultMessages = { } function messages(msgs) { - return (0, _extends2.default)({}, defaultMessages, {}, msgs) + return (0, _extends2.default)({}, defaultMessages, msgs) } module.exports = exports['default'] diff --git a/package.json b/package.json index 67c88d9e0..c0d532541 100644 --- a/package.json +++ b/package.json @@ -134,7 +134,7 @@ "invariant": "^2.2.4", "lodash": "^4.17.11", "lodash-es": "^4.17.11", - "memoize-one": "^4.0.3", + "memoize-one": "5.0.4", "prop-types": "^15.6.2", "react-overlays": "^2.0.0-0", "uncontrollable": "^7.0.0" diff --git a/src/utils/DateSlotMetrics.js b/src/utils/DateSlotMetrics.js index 269d56ee9..873680653 100644 --- a/src/utils/DateSlotMetrics.js +++ b/src/utils/DateSlotMetrics.js @@ -4,7 +4,8 @@ import { eventSegments, endOfRange, eventLevels } from './eventLevels' let isSegmentInSlot = (seg, slot) => seg.left <= slot && seg.right >= slot -const isEqual = (a, b) => a.range === b.range && a.events === b.events +const isEqual = (a, b) => + a[0].range === b[0].range && a[0].events === b[0].events export function getSlotMetrics() { return memoize(options => { diff --git a/yarn.lock b/yarn.lock index b0839071a..5fc4b1024 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8531,10 +8531,10 @@ mem@^4.0.0: mimic-fn "^2.0.0" p-is-promise "^2.0.0" -memoize-one@^4.0.3: - version "4.1.0" - resolved "https://registry.yarnpkg.com/memoize-one/-/memoize-one-4.1.0.tgz#a2387c58c03fff27ca390c31b764a79addf3f906" - integrity sha512-2GApq0yI/b22J2j9rhbrAlsHb0Qcz+7yWxeLG8h+95sl1XPUgeLimQSOdur4Vw7cUhrBHwaUZxWFZueojqNRzA== +memoize-one@5.0.4: + version "5.0.4" + resolved "https://registry.yarnpkg.com/memoize-one/-/memoize-one-5.0.4.tgz#005928aced5c43d890a4dfab18ca908b0ec92cbc" + integrity sha512-P0z5IeAH6qHHGkJIXWw0xC2HNEgkx/9uWWBQw64FJj3/ol14VYdfVGWWr0fXfjhhv3TKVIqUq65os6O4GUNksA== memoizerific@^1.11.3: version "1.11.3"