Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

5443 lignes
165 KiB

  1. import _extends from '@babel/runtime/helpers/esm/extends';
  2. import _objectWithoutPropertiesLoose from '@babel/runtime/helpers/esm/objectWithoutPropertiesLoose';
  3. import _inheritsLoose from '@babel/runtime/helpers/esm/inheritsLoose';
  4. import PropTypes from 'prop-types';
  5. import React, { Component } from 'react';
  6. import { uncontrollable } from 'uncontrollable';
  7. import clsx from 'clsx';
  8. import warning from 'warning';
  9. import invariant from 'invariant';
  10. import _assertThisInitialized from '@babel/runtime/helpers/esm/assertThisInitialized';
  11. import { findDOMNode } from 'react-dom';
  12. import { eq, add, startOf, endOf, lte, hours, minutes, seconds, milliseconds, lt, gte, month, max, min, gt, inRange as inRange$1 } from 'date-arithmetic';
  13. import chunk from 'lodash-es/chunk';
  14. import getPosition from 'dom-helpers/position';
  15. import { request, cancel } from 'dom-helpers/animationFrame';
  16. import getOffset from 'dom-helpers/offset';
  17. import getScrollTop from 'dom-helpers/scrollTop';
  18. import getScrollLeft from 'dom-helpers/scrollLeft';
  19. import Overlay from 'react-overlays/Overlay';
  20. import getHeight from 'dom-helpers/height';
  21. import qsa from 'dom-helpers/querySelectorAll';
  22. import contains from 'dom-helpers/contains';
  23. import closest from 'dom-helpers/closest';
  24. import listen from 'dom-helpers/listen';
  25. import findIndex from 'lodash-es/findIndex';
  26. import range$1 from 'lodash-es/range';
  27. import memoize from 'memoize-one';
  28. import _createClass from '@babel/runtime/helpers/esm/createClass';
  29. import sortBy from 'lodash-es/sortBy';
  30. import getWidth from 'dom-helpers/width';
  31. import scrollbarSize from 'dom-helpers/scrollbarSize';
  32. import addClass from 'dom-helpers/addClass';
  33. import removeClass from 'dom-helpers/removeClass';
  34. import omit from 'lodash-es/omit';
  35. import defaults from 'lodash-es/defaults';
  36. import transform from 'lodash-es/transform';
  37. import mapValues from 'lodash-es/mapValues';
  38. function NoopWrapper(props) {
  39. return props.children;
  40. }
  41. var navigate = {
  42. PREVIOUS: 'PREV',
  43. NEXT: 'NEXT',
  44. TODAY: 'TODAY',
  45. DATE: 'DATE'
  46. };
  47. var views = {
  48. MONTH: 'month',
  49. WEEK: 'week',
  50. WORK_WEEK: 'work_week',
  51. DAY: 'day',
  52. AGENDA: 'agenda'
  53. };
  54. var viewNames = Object.keys(views).map(function (k) {
  55. return views[k];
  56. });
  57. var accessor = PropTypes.oneOfType([PropTypes.string, PropTypes.func]);
  58. var dateFormat = PropTypes.any;
  59. var dateRangeFormat = PropTypes.func;
  60. /**
  61. * accepts either an array of builtin view names:
  62. *
  63. * ```
  64. * views={['month', 'day', 'agenda']}
  65. * ```
  66. *
  67. * or an object hash of the view name and the component (or boolean for builtin)
  68. *
  69. * ```
  70. * views={{
  71. * month: true,
  72. * week: false,
  73. * workweek: WorkWeekViewComponent,
  74. * }}
  75. * ```
  76. */
  77. var views$1 = PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOf(viewNames)), PropTypes.objectOf(function (prop, key) {
  78. var isBuiltinView = viewNames.indexOf(key) !== -1 && typeof prop[key] === 'boolean';
  79. if (isBuiltinView) {
  80. return null;
  81. } else {
  82. for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
  83. args[_key - 2] = arguments[_key];
  84. }
  85. return PropTypes.elementType.apply(PropTypes, [prop, key].concat(args));
  86. }
  87. })]);
  88. function notify(handler, args) {
  89. handler && handler.apply(null, [].concat(args));
  90. }
  91. var localePropType = PropTypes.oneOfType([PropTypes.string, PropTypes.func]);
  92. function _format(localizer, formatter, value, format, culture) {
  93. var result = typeof format === 'function' ? format(value, culture, localizer) : formatter.call(localizer, value, format, culture);
  94. !(result == null || typeof result === 'string') ? process.env.NODE_ENV !== "production" ? invariant(false, '`localizer format(..)` must return a string, null, or undefined') : invariant(false) : void 0;
  95. return result;
  96. }
  97. var DateLocalizer = function DateLocalizer(spec) {
  98. var _this = this;
  99. !(typeof spec.format === 'function') ? process.env.NODE_ENV !== "production" ? invariant(false, 'date localizer `format(..)` must be a function') : invariant(false) : void 0;
  100. !(typeof spec.firstOfWeek === 'function') ? process.env.NODE_ENV !== "production" ? invariant(false, 'date localizer `firstOfWeek(..)` must be a function') : invariant(false) : void 0;
  101. this.propType = spec.propType || localePropType;
  102. this.startOfWeek = spec.firstOfWeek;
  103. this.formats = spec.formats;
  104. this.format = function () {
  105. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  106. args[_key] = arguments[_key];
  107. }
  108. return _format.apply(void 0, [_this, spec.format].concat(args));
  109. };
  110. };
  111. function mergeWithDefaults(localizer, culture, formatOverrides, messages) {
  112. var formats = _extends({}, localizer.formats, formatOverrides);
  113. return _extends({}, localizer, {
  114. messages: messages,
  115. startOfWeek: function startOfWeek() {
  116. return localizer.startOfWeek(culture);
  117. },
  118. format: function format(value, _format2) {
  119. return localizer.format(value, formats[_format2] || _format2, culture);
  120. }
  121. });
  122. }
  123. var defaultMessages = {
  124. date: 'Date',
  125. time: 'Time',
  126. event: 'Event',
  127. allDay: 'All Day',
  128. week: 'Week',
  129. work_week: 'Work Week',
  130. day: 'Day',
  131. month: 'Month',
  132. previous: 'Back',
  133. next: 'Next',
  134. yesterday: 'Yesterday',
  135. tomorrow: 'Tomorrow',
  136. today: 'Today',
  137. agenda: 'Agenda',
  138. noEventsInRange: 'There are no events in this range.',
  139. showMore: function showMore(total) {
  140. return "+" + total + " more";
  141. }
  142. };
  143. function messages(msgs) {
  144. return _extends({}, defaultMessages, msgs);
  145. }
  146. /* eslint no-fallthrough: off */
  147. var MILLI = {
  148. seconds: 1000,
  149. minutes: 1000 * 60,
  150. hours: 1000 * 60 * 60,
  151. day: 1000 * 60 * 60 * 24
  152. };
  153. function firstVisibleDay(date, localizer) {
  154. var firstOfMonth = startOf(date, 'month');
  155. return startOf(firstOfMonth, 'week', localizer.startOfWeek());
  156. }
  157. function lastVisibleDay(date, localizer) {
  158. var endOfMonth = endOf(date, 'month');
  159. return endOf(endOfMonth, 'week', localizer.startOfWeek());
  160. }
  161. function visibleDays(date, localizer) {
  162. var current = firstVisibleDay(date, localizer),
  163. last = lastVisibleDay(date, localizer),
  164. days = [];
  165. while (lte(current, last, 'day')) {
  166. days.push(current);
  167. current = add(current, 1, 'day');
  168. }
  169. return days;
  170. }
  171. function ceil(date, unit) {
  172. var floor = startOf(date, unit);
  173. return eq(floor, date) ? floor : add(floor, 1, unit);
  174. }
  175. function range(start, end, unit) {
  176. if (unit === void 0) {
  177. unit = 'day';
  178. }
  179. var current = start,
  180. days = [];
  181. while (lte(current, end, unit)) {
  182. days.push(current);
  183. current = add(current, 1, unit);
  184. }
  185. return days;
  186. }
  187. function merge(date, time) {
  188. if (time == null && date == null) return null;
  189. if (time == null) time = new Date();
  190. if (date == null) date = new Date();
  191. date = startOf(date, 'day');
  192. date = hours(date, hours(time));
  193. date = minutes(date, minutes(time));
  194. date = seconds(date, seconds(time));
  195. return milliseconds(date, milliseconds(time));
  196. }
  197. function isJustDate(date) {
  198. return hours(date) === 0 && minutes(date) === 0 && seconds(date) === 0 && milliseconds(date) === 0;
  199. }
  200. function diff(dateA, dateB, unit) {
  201. if (!unit || unit === 'milliseconds') return Math.abs(+dateA - +dateB); // the .round() handles an edge case
  202. // with DST where the total won't be exact
  203. // since one day in the range may be shorter/longer by an hour
  204. return Math.round(Math.abs(+startOf(dateA, unit) / MILLI[unit] - +startOf(dateB, unit) / MILLI[unit]));
  205. }
  206. var EventCell =
  207. /*#__PURE__*/
  208. function (_React$Component) {
  209. _inheritsLoose(EventCell, _React$Component);
  210. function EventCell() {
  211. return _React$Component.apply(this, arguments) || this;
  212. }
  213. var _proto = EventCell.prototype;
  214. _proto.render = function render() {
  215. var _this$props = this.props,
  216. style = _this$props.style,
  217. className = _this$props.className,
  218. event = _this$props.event,
  219. selected = _this$props.selected,
  220. isAllDay = _this$props.isAllDay,
  221. onSelect = _this$props.onSelect,
  222. _onDoubleClick = _this$props.onDoubleClick,
  223. localizer = _this$props.localizer,
  224. continuesPrior = _this$props.continuesPrior,
  225. continuesAfter = _this$props.continuesAfter,
  226. accessors = _this$props.accessors,
  227. getters = _this$props.getters,
  228. children = _this$props.children,
  229. _this$props$component = _this$props.components,
  230. Event = _this$props$component.event,
  231. EventWrapper = _this$props$component.eventWrapper,
  232. slotStart = _this$props.slotStart,
  233. slotEnd = _this$props.slotEnd,
  234. props = _objectWithoutPropertiesLoose(_this$props, ["style", "className", "event", "selected", "isAllDay", "onSelect", "onDoubleClick", "localizer", "continuesPrior", "continuesAfter", "accessors", "getters", "children", "components", "slotStart", "slotEnd"]);
  235. var title = accessors.title(event);
  236. var tooltip = accessors.tooltip(event);
  237. var end = accessors.end(event);
  238. var start = accessors.start(event);
  239. var allDay = accessors.allDay(event);
  240. var showAsAllDay = isAllDay || allDay || diff(start, ceil(end, 'day'), 'day') > 1;
  241. var userProps = getters.eventProp(event, start, end, selected);
  242. var content = React.createElement("div", {
  243. className: "rbc-event-content",
  244. title: tooltip || undefined
  245. }, Event ? React.createElement(Event, {
  246. event: event,
  247. continuesPrior: continuesPrior,
  248. continuesAfter: continuesAfter,
  249. title: title,
  250. isAllDay: allDay,
  251. localizer: localizer,
  252. slotStart: slotStart,
  253. slotEnd: slotEnd
  254. }) : title);
  255. return React.createElement(EventWrapper, _extends({}, this.props, {
  256. type: "date"
  257. }), React.createElement("div", _extends({}, props, {
  258. tabIndex: 0,
  259. style: _extends({}, userProps.style, style),
  260. className: clsx('rbc-event', className, userProps.className, {
  261. 'rbc-selected': selected,
  262. 'rbc-event-allday': showAsAllDay,
  263. 'rbc-event-continues-prior': continuesPrior,
  264. 'rbc-event-continues-after': continuesAfter
  265. }),
  266. onClick: function onClick(e) {
  267. return onSelect && onSelect(event, e);
  268. },
  269. onDoubleClick: function onDoubleClick(e) {
  270. return _onDoubleClick && _onDoubleClick(event, e);
  271. }
  272. }), typeof children === 'function' ? children(content) : content));
  273. };
  274. return EventCell;
  275. }(React.Component);
  276. EventCell.propTypes = process.env.NODE_ENV !== "production" ? {
  277. event: PropTypes.object.isRequired,
  278. slotStart: PropTypes.instanceOf(Date),
  279. slotEnd: PropTypes.instanceOf(Date),
  280. selected: PropTypes.bool,
  281. isAllDay: PropTypes.bool,
  282. continuesPrior: PropTypes.bool,
  283. continuesAfter: PropTypes.bool,
  284. accessors: PropTypes.object.isRequired,
  285. components: PropTypes.object.isRequired,
  286. getters: PropTypes.object.isRequired,
  287. localizer: PropTypes.object,
  288. onSelect: PropTypes.func,
  289. onDoubleClick: PropTypes.func
  290. } : {};
  291. function isSelected(event, selected) {
  292. if (!event || selected == null) return false;
  293. return [].concat(selected).indexOf(event) !== -1;
  294. }
  295. function slotWidth(rowBox, slots) {
  296. var rowWidth = rowBox.right - rowBox.left;
  297. var cellWidth = rowWidth / slots;
  298. return cellWidth;
  299. }
  300. function getSlotAtX(rowBox, x, rtl, slots) {
  301. var cellWidth = slotWidth(rowBox, slots);
  302. return rtl ? slots - 1 - Math.floor((x - rowBox.left) / cellWidth) : Math.floor((x - rowBox.left) / cellWidth);
  303. }
  304. function pointInBox(box, _ref) {
  305. var x = _ref.x,
  306. y = _ref.y;
  307. return y >= box.top && y <= box.bottom && x >= box.left && x <= box.right;
  308. }
  309. function dateCellSelection(start, rowBox, box, slots, rtl) {
  310. var startIdx = -1;
  311. var endIdx = -1;
  312. var lastSlotIdx = slots - 1;
  313. var cellWidth = slotWidth(rowBox, slots); // cell under the mouse
  314. var currentSlot = getSlotAtX(rowBox, box.x, rtl, slots); // Identify row as either the initial row
  315. // or the row under the current mouse point
  316. var isCurrentRow = rowBox.top < box.y && rowBox.bottom > box.y;
  317. var isStartRow = rowBox.top < start.y && rowBox.bottom > start.y; // this row's position relative to the start point
  318. var isAboveStart = start.y > rowBox.bottom;
  319. var isBelowStart = rowBox.top > start.y;
  320. var isBetween = box.top < rowBox.top && box.bottom > rowBox.bottom; // this row is between the current and start rows, so entirely selected
  321. if (isBetween) {
  322. startIdx = 0;
  323. endIdx = lastSlotIdx;
  324. }
  325. if (isCurrentRow) {
  326. if (isBelowStart) {
  327. startIdx = 0;
  328. endIdx = currentSlot;
  329. } else if (isAboveStart) {
  330. startIdx = currentSlot;
  331. endIdx = lastSlotIdx;
  332. }
  333. }
  334. if (isStartRow) {
  335. // select the cell under the initial point
  336. startIdx = endIdx = rtl ? lastSlotIdx - Math.floor((start.x - rowBox.left) / cellWidth) : Math.floor((start.x - rowBox.left) / cellWidth);
  337. if (isCurrentRow) {
  338. if (currentSlot < startIdx) startIdx = currentSlot;else endIdx = currentSlot; //select current range
  339. } else if (start.y < box.y) {
  340. // the current row is below start row
  341. // select cells to the right of the start cell
  342. endIdx = lastSlotIdx;
  343. } else {
  344. // select cells to the left of the start cell
  345. startIdx = 0;
  346. }
  347. }
  348. return {
  349. startIdx: startIdx,
  350. endIdx: endIdx
  351. };
  352. }
  353. var Popup =
  354. /*#__PURE__*/
  355. function (_React$Component) {
  356. _inheritsLoose(Popup, _React$Component);
  357. function Popup() {
  358. return _React$Component.apply(this, arguments) || this;
  359. }
  360. var _proto = Popup.prototype;
  361. _proto.componentDidMount = function componentDidMount() {
  362. var _this$props = this.props,
  363. _this$props$popupOffs = _this$props.popupOffset,
  364. popupOffset = _this$props$popupOffs === void 0 ? 5 : _this$props$popupOffs,
  365. popperRef = _this$props.popperRef,
  366. _getOffset = getOffset(popperRef.current),
  367. top = _getOffset.top,
  368. left = _getOffset.left,
  369. width = _getOffset.width,
  370. height = _getOffset.height,
  371. viewBottom = window.innerHeight + getScrollTop(window),
  372. viewRight = window.innerWidth + getScrollLeft(window),
  373. bottom = top + height,
  374. right = left + width;
  375. if (bottom > viewBottom || right > viewRight) {
  376. var topOffset, leftOffset;
  377. if (bottom > viewBottom) topOffset = bottom - viewBottom + (popupOffset.y || +popupOffset || 0);
  378. if (right > viewRight) leftOffset = right - viewRight + (popupOffset.x || +popupOffset || 0);
  379. this.setState({
  380. topOffset: topOffset,
  381. leftOffset: leftOffset
  382. }); //eslint-disable-line
  383. }
  384. };
  385. _proto.render = function render() {
  386. var _this$props2 = this.props,
  387. events = _this$props2.events,
  388. selected = _this$props2.selected,
  389. getters = _this$props2.getters,
  390. accessors = _this$props2.accessors,
  391. components = _this$props2.components,
  392. onSelect = _this$props2.onSelect,
  393. onDoubleClick = _this$props2.onDoubleClick,
  394. slotStart = _this$props2.slotStart,
  395. slotEnd = _this$props2.slotEnd,
  396. localizer = _this$props2.localizer,
  397. popperRef = _this$props2.popperRef;
  398. var width = this.props.position.width,
  399. topOffset = (this.state || {}).topOffset || 0,
  400. leftOffset = (this.state || {}).leftOffset || 0;
  401. var style = {
  402. top: -topOffset,
  403. left: -leftOffset,
  404. minWidth: width + width / 2
  405. };
  406. return React.createElement("div", {
  407. style: _extends({}, this.props.style, style),
  408. className: "rbc-overlay",
  409. ref: popperRef
  410. }, React.createElement("div", {
  411. className: "rbc-overlay-header"
  412. }, localizer.format(slotStart, 'dayHeaderFormat')), events.map(function (event, idx) {
  413. return React.createElement(EventCell, {
  414. key: idx,
  415. type: "popup",
  416. event: event,
  417. getters: getters,
  418. onSelect: onSelect,
  419. accessors: accessors,
  420. components: components,
  421. onDoubleClick: onDoubleClick,
  422. continuesPrior: lt(accessors.end(event), slotStart, 'day'),
  423. continuesAfter: gte(accessors.start(event), slotEnd, 'day'),
  424. slotStart: slotStart,
  425. slotEnd: slotEnd,
  426. selected: isSelected(event, selected)
  427. });
  428. }));
  429. };
  430. return Popup;
  431. }(React.Component);
  432. Popup.propTypes = process.env.NODE_ENV !== "production" ? {
  433. position: PropTypes.object,
  434. popupOffset: PropTypes.oneOfType([PropTypes.number, PropTypes.shape({
  435. x: PropTypes.number,
  436. y: PropTypes.number
  437. })]),
  438. events: PropTypes.array,
  439. selected: PropTypes.object,
  440. accessors: PropTypes.object.isRequired,
  441. components: PropTypes.object.isRequired,
  442. getters: PropTypes.object.isRequired,
  443. localizer: PropTypes.object.isRequired,
  444. onSelect: PropTypes.func,
  445. onDoubleClick: PropTypes.func,
  446. slotStart: PropTypes.instanceOf(Date),
  447. slotEnd: PropTypes.number,
  448. popperRef: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
  449. current: PropTypes.Element
  450. })])
  451. /**
  452. * The Overlay component, of react-overlays, creates a ref that is passed to the Popup, and
  453. * requires proper ref forwarding to be used without error
  454. */
  455. } : {};
  456. var Popup$1 = React.forwardRef(function (props, ref) {
  457. return React.createElement(Popup, _extends({
  458. popperRef: ref
  459. }, props));
  460. });
  461. function addEventListener(type, handler, target) {
  462. if (target === void 0) {
  463. target = document;
  464. }
  465. return listen(target, type, handler, {
  466. passive: false
  467. });
  468. }
  469. function isOverContainer(container, x, y) {
  470. return !container || contains(container, document.elementFromPoint(x, y));
  471. }
  472. function getEventNodeFromPoint(node, _ref) {
  473. var clientX = _ref.clientX,
  474. clientY = _ref.clientY;
  475. var target = document.elementFromPoint(clientX, clientY);
  476. return closest(target, '.rbc-event', node);
  477. }
  478. function isEvent(node, bounds) {
  479. return !!getEventNodeFromPoint(node, bounds);
  480. }
  481. function getEventCoordinates(e) {
  482. var target = e;
  483. if (e.touches && e.touches.length) {
  484. target = e.touches[0];
  485. }
  486. return {
  487. clientX: target.clientX,
  488. clientY: target.clientY,
  489. pageX: target.pageX,
  490. pageY: target.pageY
  491. };
  492. }
  493. var clickTolerance = 5;
  494. var clickInterval = 250;
  495. var Selection =
  496. /*#__PURE__*/
  497. function () {
  498. function Selection(node, _temp) {
  499. var _ref2 = _temp === void 0 ? {} : _temp,
  500. _ref2$global = _ref2.global,
  501. global = _ref2$global === void 0 ? false : _ref2$global,
  502. _ref2$longPressThresh = _ref2.longPressThreshold,
  503. longPressThreshold = _ref2$longPressThresh === void 0 ? 250 : _ref2$longPressThresh;
  504. this.isDetached = false;
  505. this.container = node;
  506. this.globalMouse = !node || global;
  507. this.longPressThreshold = longPressThreshold;
  508. this._listeners = Object.create(null);
  509. this._handleInitialEvent = this._handleInitialEvent.bind(this);
  510. this._handleMoveEvent = this._handleMoveEvent.bind(this);
  511. this._handleTerminatingEvent = this._handleTerminatingEvent.bind(this);
  512. this._keyListener = this._keyListener.bind(this);
  513. this._dropFromOutsideListener = this._dropFromOutsideListener.bind(this);
  514. this._dragOverFromOutsideListener = this._dragOverFromOutsideListener.bind(this); // Fixes an iOS 10 bug where scrolling could not be prevented on the window.
  515. // https://github.com/metafizzy/flickity/issues/457#issuecomment-254501356
  516. this._removeTouchMoveWindowListener = addEventListener('touchmove', function () {}, window);
  517. this._removeKeyDownListener = addEventListener('keydown', this._keyListener);
  518. this._removeKeyUpListener = addEventListener('keyup', this._keyListener);
  519. this._removeDropFromOutsideListener = addEventListener('drop', this._dropFromOutsideListener);
  520. this._onDragOverfromOutisde = addEventListener('dragover', this._dragOverFromOutsideListener);
  521. this._addInitialEventListener();
  522. }
  523. var _proto = Selection.prototype;
  524. _proto.on = function on(type, handler) {
  525. var handlers = this._listeners[type] || (this._listeners[type] = []);
  526. handlers.push(handler);
  527. return {
  528. remove: function remove() {
  529. var idx = handlers.indexOf(handler);
  530. if (idx !== -1) handlers.splice(idx, 1);
  531. }
  532. };
  533. };
  534. _proto.emit = function emit(type) {
  535. for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  536. args[_key - 1] = arguments[_key];
  537. }
  538. var result;
  539. var handlers = this._listeners[type] || [];
  540. handlers.forEach(function (fn) {
  541. if (result === undefined) result = fn.apply(void 0, args);
  542. });
  543. return result;
  544. };
  545. _proto.teardown = function teardown() {
  546. this.isDetached = true;
  547. this.listeners = Object.create(null);
  548. this._removeTouchMoveWindowListener && this._removeTouchMoveWindowListener();
  549. this._removeInitialEventListener && this._removeInitialEventListener();
  550. this._removeEndListener && this._removeEndListener();
  551. this._onEscListener && this._onEscListener();
  552. this._removeMoveListener && this._removeMoveListener();
  553. this._removeKeyUpListener && this._removeKeyUpListener();
  554. this._removeKeyDownListener && this._removeKeyDownListener();
  555. this._removeDropFromOutsideListener && this._removeDropFromOutsideListener();
  556. };
  557. _proto.isSelected = function isSelected(node) {
  558. var box = this._selectRect;
  559. if (!box || !this.selecting) return false;
  560. return objectsCollide(box, getBoundsForNode(node));
  561. };
  562. _proto.filter = function filter(items) {
  563. var box = this._selectRect; //not selecting
  564. if (!box || !this.selecting) return [];
  565. return items.filter(this.isSelected, this);
  566. } // Adds a listener that will call the handler only after the user has pressed on the screen
  567. // without moving their finger for 250ms.
  568. ;
  569. _proto._addLongPressListener = function _addLongPressListener(handler, initialEvent) {
  570. var _this = this;
  571. var timer = null;
  572. var removeTouchMoveListener = null;
  573. var removeTouchEndListener = null;
  574. var handleTouchStart = function handleTouchStart(initialEvent) {
  575. timer = setTimeout(function () {
  576. cleanup();
  577. handler(initialEvent);
  578. }, _this.longPressThreshold);
  579. removeTouchMoveListener = addEventListener('touchmove', function () {
  580. return cleanup();
  581. });
  582. removeTouchEndListener = addEventListener('touchend', function () {
  583. return cleanup();
  584. });
  585. };
  586. var removeTouchStartListener = addEventListener('touchstart', handleTouchStart);
  587. var cleanup = function cleanup() {
  588. if (timer) {
  589. clearTimeout(timer);
  590. }
  591. if (removeTouchMoveListener) {
  592. removeTouchMoveListener();
  593. }
  594. if (removeTouchEndListener) {
  595. removeTouchEndListener();
  596. }
  597. timer = null;
  598. removeTouchMoveListener = null;
  599. removeTouchEndListener = null;
  600. };
  601. if (initialEvent) {
  602. handleTouchStart(initialEvent);
  603. }
  604. return function () {
  605. cleanup();
  606. removeTouchStartListener();
  607. };
  608. } // Listen for mousedown and touchstart events. When one is received, disable the other and setup
  609. // future event handling based on the type of event.
  610. ;
  611. _proto._addInitialEventListener = function _addInitialEventListener() {
  612. var _this2 = this;
  613. var removeMouseDownListener = addEventListener('mousedown', function (e) {
  614. _this2._removeInitialEventListener();
  615. _this2._handleInitialEvent(e);
  616. _this2._removeInitialEventListener = addEventListener('mousedown', _this2._handleInitialEvent);
  617. });
  618. var removeTouchStartListener = addEventListener('touchstart', function (e) {
  619. _this2._removeInitialEventListener();
  620. _this2._removeInitialEventListener = _this2._addLongPressListener(_this2._handleInitialEvent, e);
  621. });
  622. this._removeInitialEventListener = function () {
  623. removeMouseDownListener();
  624. removeTouchStartListener();
  625. };
  626. };
  627. _proto._dropFromOutsideListener = function _dropFromOutsideListener(e) {
  628. var _getEventCoordinates = getEventCoordinates(e),
  629. pageX = _getEventCoordinates.pageX,
  630. pageY = _getEventCoordinates.pageY,
  631. clientX = _getEventCoordinates.clientX,
  632. clientY = _getEventCoordinates.clientY;
  633. this.emit('dropFromOutside', {
  634. x: pageX,
  635. y: pageY,
  636. clientX: clientX,
  637. clientY: clientY
  638. });
  639. e.preventDefault();
  640. };
  641. _proto._dragOverFromOutsideListener = function _dragOverFromOutsideListener(e) {
  642. var _getEventCoordinates2 = getEventCoordinates(e),
  643. pageX = _getEventCoordinates2.pageX,
  644. pageY = _getEventCoordinates2.pageY,
  645. clientX = _getEventCoordinates2.clientX,
  646. clientY = _getEventCoordinates2.clientY;
  647. this.emit('dragOverFromOutside', {
  648. x: pageX,
  649. y: pageY,
  650. clientX: clientX,
  651. clientY: clientY
  652. });
  653. e.preventDefault();
  654. };
  655. _proto._handleInitialEvent = function _handleInitialEvent(e) {
  656. if (this.isDetached) {
  657. return;
  658. }
  659. var _getEventCoordinates3 = getEventCoordinates(e),
  660. clientX = _getEventCoordinates3.clientX,
  661. clientY = _getEventCoordinates3.clientY,
  662. pageX = _getEventCoordinates3.pageX,
  663. pageY = _getEventCoordinates3.pageY;
  664. var node = this.container(),
  665. collides,
  666. offsetData; // Right clicks
  667. if (e.which === 3 || e.button === 2 || !isOverContainer(node, clientX, clientY)) return;
  668. if (!this.globalMouse && node && !contains(node, e.target)) {
  669. var _normalizeDistance = normalizeDistance(0),
  670. top = _normalizeDistance.top,
  671. left = _normalizeDistance.left,
  672. bottom = _normalizeDistance.bottom,
  673. right = _normalizeDistance.right;
  674. offsetData = getBoundsForNode(node);
  675. collides = objectsCollide({
  676. top: offsetData.top - top,
  677. left: offsetData.left - left,
  678. bottom: offsetData.bottom + bottom,
  679. right: offsetData.right + right
  680. }, {
  681. top: pageY,
  682. left: pageX
  683. });
  684. if (!collides) return;
  685. }
  686. var result = this.emit('beforeSelect', this._initialEventData = {
  687. isTouch: /^touch/.test(e.type),
  688. x: pageX,
  689. y: pageY,
  690. clientX: clientX,
  691. clientY: clientY
  692. });
  693. if (result === false) return;
  694. switch (e.type) {
  695. case 'mousedown':
  696. this._removeEndListener = addEventListener('mouseup', this._handleTerminatingEvent);
  697. this._onEscListener = addEventListener('keydown', this._handleTerminatingEvent);
  698. this._removeMoveListener = addEventListener('mousemove', this._handleMoveEvent);
  699. break;
  700. case 'touchstart':
  701. this._handleMoveEvent(e);
  702. this._removeEndListener = addEventListener('touchend', this._handleTerminatingEvent);
  703. this._removeMoveListener = addEventListener('touchmove', this._handleMoveEvent);
  704. break;
  705. default:
  706. break;
  707. }
  708. };
  709. _proto._handleTerminatingEvent = function _handleTerminatingEvent(e) {
  710. var _getEventCoordinates4 = getEventCoordinates(e),
  711. pageX = _getEventCoordinates4.pageX,
  712. pageY = _getEventCoordinates4.pageY;
  713. this.selecting = false;
  714. this._removeEndListener && this._removeEndListener();
  715. this._removeMoveListener && this._removeMoveListener();
  716. if (!this._initialEventData) return;
  717. var inRoot = !this.container || contains(this.container(), e.target);
  718. var bounds = this._selectRect;
  719. var click = this.isClick(pageX, pageY);
  720. this._initialEventData = null;
  721. if (e.key === 'Escape') {
  722. return this.emit('reset');
  723. }
  724. if (!inRoot) {
  725. return this.emit('reset');
  726. }
  727. if (click && inRoot) {
  728. return this._handleClickEvent(e);
  729. } // User drag-clicked in the Selectable area
  730. if (!click) return this.emit('select', bounds);
  731. };
  732. _proto._handleClickEvent = function _handleClickEvent(e) {
  733. var _getEventCoordinates5 = getEventCoordinates(e),
  734. pageX = _getEventCoordinates5.pageX,
  735. pageY = _getEventCoordinates5.pageY,
  736. clientX = _getEventCoordinates5.clientX,
  737. clientY = _getEventCoordinates5.clientY;
  738. var now = new Date().getTime();
  739. if (this._lastClickData && now - this._lastClickData.timestamp < clickInterval) {
  740. // Double click event
  741. this._lastClickData = null;
  742. return this.emit('doubleClick', {
  743. x: pageX,
  744. y: pageY,
  745. clientX: clientX,
  746. clientY: clientY
  747. });
  748. } // Click event
  749. this._lastClickData = {
  750. timestamp: now
  751. };
  752. return this.emit('click', {
  753. x: pageX,
  754. y: pageY,
  755. clientX: clientX,
  756. clientY: clientY
  757. });
  758. };
  759. _proto._handleMoveEvent = function _handleMoveEvent(e) {
  760. if (this._initialEventData === null || this.isDetached) {
  761. return;
  762. }
  763. var _this$_initialEventDa = this._initialEventData,
  764. x = _this$_initialEventDa.x,
  765. y = _this$_initialEventDa.y;
  766. var _getEventCoordinates6 = getEventCoordinates(e),
  767. pageX = _getEventCoordinates6.pageX,
  768. pageY = _getEventCoordinates6.pageY;
  769. var w = Math.abs(x - pageX);
  770. var h = Math.abs(y - pageY);
  771. var left = Math.min(pageX, x),
  772. top = Math.min(pageY, y),
  773. old = this.selecting; // Prevent emitting selectStart event until mouse is moved.
  774. // in Chrome on Windows, mouseMove event may be fired just after mouseDown event.
  775. if (this.isClick(pageX, pageY) && !old && !(w || h)) {
  776. return;
  777. }
  778. this.selecting = true;
  779. this._selectRect = {
  780. top: top,
  781. left: left,
  782. x: pageX,
  783. y: pageY,
  784. right: left + w,
  785. bottom: top + h
  786. };
  787. if (!old) {
  788. this.emit('selectStart', this._initialEventData);
  789. }
  790. if (!this.isClick(pageX, pageY)) this.emit('selecting', this._selectRect);
  791. e.preventDefault();
  792. };
  793. _proto._keyListener = function _keyListener(e) {
  794. this.ctrl = e.metaKey || e.ctrlKey;
  795. };
  796. _proto.isClick = function isClick(pageX, pageY) {
  797. var _this$_initialEventDa2 = this._initialEventData,
  798. x = _this$_initialEventDa2.x,
  799. y = _this$_initialEventDa2.y,
  800. isTouch = _this$_initialEventDa2.isTouch;
  801. return !isTouch && Math.abs(pageX - x) <= clickTolerance && Math.abs(pageY - y) <= clickTolerance;
  802. };
  803. return Selection;
  804. }();
  805. /**
  806. * Resolve the disance prop from either an Int or an Object
  807. * @return {Object}
  808. */
  809. function normalizeDistance(distance) {
  810. if (distance === void 0) {
  811. distance = 0;
  812. }
  813. if (typeof distance !== 'object') distance = {
  814. top: distance,
  815. left: distance,
  816. right: distance,
  817. bottom: distance
  818. };
  819. return distance;
  820. }
  821. /**
  822. * Given two objects containing "top", "left", "offsetWidth" and "offsetHeight"
  823. * properties, determine if they collide.
  824. * @param {Object|HTMLElement} a
  825. * @param {Object|HTMLElement} b
  826. * @return {bool}
  827. */
  828. function objectsCollide(nodeA, nodeB, tolerance) {
  829. if (tolerance === void 0) {
  830. tolerance = 0;
  831. }
  832. var _getBoundsForNode = getBoundsForNode(nodeA),
  833. aTop = _getBoundsForNode.top,
  834. aLeft = _getBoundsForNode.left,
  835. _getBoundsForNode$rig = _getBoundsForNode.right,
  836. aRight = _getBoundsForNode$rig === void 0 ? aLeft : _getBoundsForNode$rig,
  837. _getBoundsForNode$bot = _getBoundsForNode.bottom,
  838. aBottom = _getBoundsForNode$bot === void 0 ? aTop : _getBoundsForNode$bot;
  839. var _getBoundsForNode2 = getBoundsForNode(nodeB),
  840. bTop = _getBoundsForNode2.top,
  841. bLeft = _getBoundsForNode2.left,
  842. _getBoundsForNode2$ri = _getBoundsForNode2.right,
  843. bRight = _getBoundsForNode2$ri === void 0 ? bLeft : _getBoundsForNode2$ri,
  844. _getBoundsForNode2$bo = _getBoundsForNode2.bottom,
  845. bBottom = _getBoundsForNode2$bo === void 0 ? bTop : _getBoundsForNode2$bo;
  846. return !( // 'a' bottom doesn't touch 'b' top
  847. aBottom - tolerance < bTop || // 'a' top doesn't touch 'b' bottom
  848. aTop + tolerance > bBottom || // 'a' right doesn't touch 'b' left
  849. aRight - tolerance < bLeft || // 'a' left doesn't touch 'b' right
  850. aLeft + tolerance > bRight);
  851. }
  852. /**
  853. * Given a node, get everything needed to calculate its boundaries
  854. * @param {HTMLElement} node
  855. * @return {Object}
  856. */
  857. function getBoundsForNode(node) {
  858. if (!node.getBoundingClientRect) return node;
  859. var rect = node.getBoundingClientRect(),
  860. left = rect.left + pageOffset('left'),
  861. top = rect.top + pageOffset('top');
  862. return {
  863. top: top,
  864. left: left,
  865. right: (node.offsetWidth || 0) + left,
  866. bottom: (node.offsetHeight || 0) + top
  867. };
  868. }
  869. function pageOffset(dir) {
  870. if (dir === 'left') return window.pageXOffset || document.body.scrollLeft || 0;
  871. if (dir === 'top') return window.pageYOffset || document.body.scrollTop || 0;
  872. }
  873. var BackgroundCells =
  874. /*#__PURE__*/
  875. function (_React$Component) {
  876. _inheritsLoose(BackgroundCells, _React$Component);
  877. function BackgroundCells(props, context) {
  878. var _this;
  879. _this = _React$Component.call(this, props, context) || this;
  880. _this.state = {
  881. selecting: false
  882. };
  883. return _this;
  884. }
  885. var _proto = BackgroundCells.prototype;
  886. _proto.componentDidMount = function componentDidMount() {
  887. this.props.selectable && this._selectable();
  888. };
  889. _proto.componentWillUnmount = function componentWillUnmount() {
  890. this._teardownSelectable();
  891. };
  892. _proto.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
  893. if (nextProps.selectable && !this.props.selectable) this._selectable();
  894. if (!nextProps.selectable && this.props.selectable) this._teardownSelectable();
  895. };
  896. _proto.render = function render() {
  897. var _this$props = this.props,
  898. range = _this$props.range,
  899. getNow = _this$props.getNow,
  900. getters = _this$props.getters,
  901. currentDate = _this$props.date,
  902. Wrapper = _this$props.components.dateCellWrapper;
  903. var _this$state = this.state,
  904. selecting = _this$state.selecting,
  905. startIdx = _this$state.startIdx,
  906. endIdx = _this$state.endIdx;
  907. var current = getNow();
  908. return React.createElement("div", {
  909. className: "rbc-row-bg"
  910. }, range.map(function (date, index) {
  911. var selected = selecting && index >= startIdx && index <= endIdx;
  912. var _getters$dayProp = getters.dayProp(date),
  913. className = _getters$dayProp.className,
  914. style = _getters$dayProp.style;
  915. return React.createElement(Wrapper, {
  916. key: index,
  917. value: date,
  918. range: range
  919. }, React.createElement("div", {
  920. style: style,
  921. className: clsx('rbc-day-bg', className, selected && 'rbc-selected-cell', eq(date, current, 'day') && 'rbc-today', currentDate && month(currentDate) !== month(date) && 'rbc-off-range-bg')
  922. }));
  923. }));
  924. };
  925. _proto._selectable = function _selectable() {
  926. var _this2 = this;
  927. var node = findDOMNode(this);
  928. var selector = this._selector = new Selection(this.props.container, {
  929. longPressThreshold: this.props.longPressThreshold
  930. });
  931. var selectorClicksHandler = function selectorClicksHandler(point, actionType) {
  932. if (!isEvent(findDOMNode(_this2), point)) {
  933. var rowBox = getBoundsForNode(node);
  934. var _this2$props = _this2.props,
  935. range = _this2$props.range,
  936. rtl = _this2$props.rtl;
  937. if (pointInBox(rowBox, point)) {
  938. var currentCell = getSlotAtX(rowBox, point.x, rtl, range.length);
  939. _this2._selectSlot({
  940. startIdx: currentCell,
  941. endIdx: currentCell,
  942. action: actionType,
  943. box: point
  944. });
  945. }
  946. }
  947. _this2._initial = {};
  948. _this2.setState({
  949. selecting: false
  950. });
  951. };
  952. selector.on('selecting', function (box) {
  953. var _this2$props2 = _this2.props,
  954. range = _this2$props2.range,
  955. rtl = _this2$props2.rtl;
  956. var startIdx = -1;
  957. var endIdx = -1;
  958. if (!_this2.state.selecting) {
  959. notify(_this2.props.onSelectStart, [box]);
  960. _this2._initial = {
  961. x: box.x,
  962. y: box.y
  963. };
  964. }
  965. if (selector.isSelected(node)) {
  966. var nodeBox = getBoundsForNode(node);
  967. var _dateCellSelection = dateCellSelection(_this2._initial, nodeBox, box, range.length, rtl);
  968. startIdx = _dateCellSelection.startIdx;
  969. endIdx = _dateCellSelection.endIdx;
  970. }
  971. _this2.setState({
  972. selecting: true,
  973. startIdx: startIdx,
  974. endIdx: endIdx
  975. });
  976. });
  977. selector.on('beforeSelect', function (box) {
  978. if (_this2.props.selectable !== 'ignoreEvents') return;
  979. return !isEvent(findDOMNode(_this2), box);
  980. });
  981. selector.on('click', function (point) {
  982. return selectorClicksHandler(point, 'click');
  983. });
  984. selector.on('doubleClick', function (point) {
  985. return selectorClicksHandler(point, 'doubleClick');
  986. });
  987. selector.on('select', function (bounds) {
  988. _this2._selectSlot(_extends({}, _this2.state, {
  989. action: 'select',
  990. bounds: bounds
  991. }));
  992. _this2._initial = {};
  993. _this2.setState({
  994. selecting: false
  995. });
  996. notify(_this2.props.onSelectEnd, [_this2.state]);
  997. });
  998. };
  999. _proto._teardownSelectable = function _teardownSelectable() {
  1000. if (!this._selector) return;
  1001. this._selector.teardown();
  1002. this._selector = null;
  1003. };
  1004. _proto._selectSlot = function _selectSlot(_ref) {
  1005. var endIdx = _ref.endIdx,
  1006. startIdx = _ref.startIdx,
  1007. action = _ref.action,
  1008. bounds = _ref.bounds,
  1009. box = _ref.box;
  1010. if (endIdx !== -1 && startIdx !== -1) this.props.onSelectSlot && this.props.onSelectSlot({
  1011. start: startIdx,
  1012. end: endIdx,
  1013. action: action,
  1014. bounds: bounds,
  1015. box: box
  1016. });
  1017. };
  1018. return BackgroundCells;
  1019. }(React.Component);
  1020. BackgroundCells.propTypes = process.env.NODE_ENV !== "production" ? {
  1021. date: PropTypes.instanceOf(Date),
  1022. getNow: PropTypes.func.isRequired,
  1023. getters: PropTypes.object.isRequired,
  1024. components: PropTypes.object.isRequired,
  1025. container: PropTypes.func,
  1026. dayPropGetter: PropTypes.func,
  1027. selectable: PropTypes.oneOf([true, false, 'ignoreEvents']),
  1028. longPressThreshold: PropTypes.number,
  1029. onSelectSlot: PropTypes.func.isRequired,
  1030. onSelectEnd: PropTypes.func,
  1031. onSelectStart: PropTypes.func,
  1032. range: PropTypes.arrayOf(PropTypes.instanceOf(Date)),
  1033. rtl: PropTypes.bool,
  1034. type: PropTypes.string
  1035. } : {};
  1036. /* eslint-disable react/prop-types */
  1037. var EventRowMixin = {
  1038. propTypes: {
  1039. slotMetrics: PropTypes.object.isRequired,
  1040. selected: PropTypes.object,
  1041. isAllDay: PropTypes.bool,
  1042. accessors: PropTypes.object.isRequired,
  1043. localizer: PropTypes.object.isRequired,
  1044. components: PropTypes.object.isRequired,
  1045. getters: PropTypes.object.isRequired,
  1046. onSelect: PropTypes.func,
  1047. onDoubleClick: PropTypes.func
  1048. },
  1049. defaultProps: {
  1050. segments: [],
  1051. selected: {}
  1052. },
  1053. renderEvent: function renderEvent(props, event) {
  1054. var selected = props.selected,
  1055. _ = props.isAllDay,
  1056. accessors = props.accessors,
  1057. getters = props.getters,
  1058. onSelect = props.onSelect,
  1059. onDoubleClick = props.onDoubleClick,
  1060. localizer = props.localizer,
  1061. slotMetrics = props.slotMetrics,
  1062. components = props.components;
  1063. var continuesPrior = slotMetrics.continuesPrior(event);
  1064. var continuesAfter = slotMetrics.continuesAfter(event);
  1065. return React.createElement(EventCell, {
  1066. event: event,
  1067. getters: getters,
  1068. localizer: localizer,
  1069. accessors: accessors,
  1070. components: components,
  1071. onSelect: onSelect,
  1072. onDoubleClick: onDoubleClick,
  1073. continuesPrior: continuesPrior,
  1074. continuesAfter: continuesAfter,
  1075. slotStart: slotMetrics.first,
  1076. slotEnd: slotMetrics.last,
  1077. selected: isSelected(event, selected)
  1078. });
  1079. },
  1080. renderSpan: function renderSpan(slots, len, key, content) {
  1081. if (content === void 0) {
  1082. content = ' ';
  1083. }
  1084. var per = Math.abs(len) / slots * 100 + '%';
  1085. return React.createElement("div", {
  1086. key: key,
  1087. className: "rbc-row-segment" // IE10/11 need max-width. flex-basis doesn't respect box-sizing
  1088. ,
  1089. style: {
  1090. WebkitFlexBasis: per,
  1091. flexBasis: per,
  1092. maxWidth: per
  1093. }
  1094. }, content);
  1095. }
  1096. };
  1097. var EventRow =
  1098. /*#__PURE__*/
  1099. function (_React$Component) {
  1100. _inheritsLoose(EventRow, _React$Component);
  1101. function EventRow() {
  1102. return _React$Component.apply(this, arguments) || this;
  1103. }
  1104. var _proto = EventRow.prototype;
  1105. _proto.render = function render() {
  1106. var _this = this;
  1107. var _this$props = this.props,
  1108. segments = _this$props.segments,
  1109. slots = _this$props.slotMetrics.slots,
  1110. className = _this$props.className;
  1111. var lastEnd = 1;
  1112. return React.createElement("div", {
  1113. className: clsx(className, 'rbc-row')
  1114. }, segments.reduce(function (row, _ref, li) {
  1115. var event = _ref.event,
  1116. left = _ref.left,
  1117. right = _ref.right,
  1118. span = _ref.span;
  1119. var key = '_lvl_' + li;
  1120. var gap = left - lastEnd;
  1121. var content = EventRowMixin.renderEvent(_this.props, event);
  1122. if (gap) row.push(EventRowMixin.renderSpan(slots, gap, key + "_gap"));
  1123. row.push(EventRowMixin.renderSpan(slots, span, key, content));
  1124. lastEnd = right + 1;
  1125. return row;
  1126. }, []));
  1127. };
  1128. return EventRow;
  1129. }(React.Component);
  1130. EventRow.propTypes = process.env.NODE_ENV !== "production" ? _extends({
  1131. segments: PropTypes.array
  1132. }, EventRowMixin.propTypes) : {};
  1133. EventRow.defaultProps = _extends({}, EventRowMixin.defaultProps);
  1134. function endOfRange(dateRange, unit) {
  1135. if (unit === void 0) {
  1136. unit = 'day';
  1137. }
  1138. return {
  1139. first: dateRange[0],
  1140. last: add(dateRange[dateRange.length - 1], 1, unit)
  1141. };
  1142. }
  1143. function eventSegments(event, range, accessors) {
  1144. var _endOfRange = endOfRange(range),
  1145. first = _endOfRange.first,
  1146. last = _endOfRange.last;
  1147. var slots = diff(first, last, 'day');
  1148. var start = max(startOf(accessors.start(event), 'day'), first);
  1149. var end = min(ceil(accessors.end(event), 'day'), last);
  1150. var padding = findIndex(range, function (x) {
  1151. return eq(x, start, 'day');
  1152. });
  1153. var span = diff(start, end, 'day');
  1154. span = Math.min(span, slots);
  1155. span = Math.max(span, 1);
  1156. return {
  1157. event: event,
  1158. span: span,
  1159. left: padding + 1,
  1160. right: Math.max(padding + span, 1)
  1161. };
  1162. }
  1163. function eventLevels(rowSegments, limit) {
  1164. if (limit === void 0) {
  1165. limit = Infinity;
  1166. }
  1167. var i,
  1168. j,
  1169. seg,
  1170. levels = [],
  1171. extra = [];
  1172. for (i = 0; i < rowSegments.length; i++) {
  1173. seg = rowSegments[i];
  1174. for (j = 0; j < levels.length; j++) {
  1175. if (!segsOverlap(seg, levels[j])) break;
  1176. }
  1177. if (j >= limit) {
  1178. extra.push(seg);
  1179. } else {
  1180. (levels[j] || (levels[j] = [])).push(seg);
  1181. }
  1182. }
  1183. for (i = 0; i < levels.length; i++) {
  1184. levels[i].sort(function (a, b) {
  1185. return a.left - b.left;
  1186. }); //eslint-disable-line
  1187. }
  1188. return {
  1189. levels: levels,
  1190. extra: extra
  1191. };
  1192. }
  1193. function inRange(e, start, end, accessors) {
  1194. var eStart = startOf(accessors.start(e), 'day');
  1195. var eEnd = accessors.end(e);
  1196. var startsBeforeEnd = lte(eStart, end, 'day'); // when the event is zero duration we need to handle a bit differently
  1197. var endsAfterStart = !eq(eStart, eEnd, 'minutes') ? gt(eEnd, start, 'minutes') : gte(eEnd, start, 'minutes');
  1198. return startsBeforeEnd && endsAfterStart;
  1199. }
  1200. function segsOverlap(seg, otherSegs) {
  1201. return otherSegs.some(function (otherSeg) {
  1202. return otherSeg.left <= seg.right && otherSeg.right >= seg.left;
  1203. });
  1204. }
  1205. function sortEvents(evtA, evtB, accessors) {
  1206. var startSort = +startOf(accessors.start(evtA), 'day') - +startOf(accessors.start(evtB), 'day');
  1207. var durA = diff(accessors.start(evtA), ceil(accessors.end(evtA), 'day'), 'day');
  1208. var durB = diff(accessors.start(evtB), ceil(accessors.end(evtB), 'day'), 'day');
  1209. return startSort || // sort by start Day first
  1210. Math.max(durB, 1) - Math.max(durA, 1) || // events spanning multiple days go first
  1211. !!accessors.allDay(evtB) - !!accessors.allDay(evtA) || // then allDay single day events
  1212. +accessors.start(evtA) - +accessors.start(evtB); // then sort by start time
  1213. }
  1214. var isSegmentInSlot = function isSegmentInSlot(seg, slot) {
  1215. return seg.left <= slot && seg.right >= slot;
  1216. };
  1217. var eventsInSlot = function eventsInSlot(segments, slot) {
  1218. return segments.filter(function (seg) {
  1219. return isSegmentInSlot(seg, slot);
  1220. }).length;
  1221. };
  1222. var EventEndingRow =
  1223. /*#__PURE__*/
  1224. function (_React$Component) {
  1225. _inheritsLoose(EventEndingRow, _React$Component);
  1226. function EventEndingRow() {
  1227. return _React$Component.apply(this, arguments) || this;
  1228. }
  1229. var _proto = EventEndingRow.prototype;
  1230. _proto.render = function render() {
  1231. var _this$props = this.props,
  1232. segments = _this$props.segments,
  1233. slots = _this$props.slotMetrics.slots;
  1234. var rowSegments = eventLevels(segments).levels[0];
  1235. var current = 1,
  1236. lastEnd = 1,
  1237. row = [];
  1238. while (current <= slots) {
  1239. var key = '_lvl_' + current;
  1240. var _ref = rowSegments.filter(function (seg) {
  1241. return isSegmentInSlot(seg, current);
  1242. })[0] || {},
  1243. event = _ref.event,
  1244. left = _ref.left,
  1245. right = _ref.right,
  1246. span = _ref.span; //eslint-disable-line
  1247. if (!event) {
  1248. current++;
  1249. continue;
  1250. }
  1251. var gap = Math.max(0, left - lastEnd);
  1252. if (this.canRenderSlotEvent(left, span)) {
  1253. var content = EventRowMixin.renderEvent(this.props, event);
  1254. if (gap) {
  1255. row.push(EventRowMixin.renderSpan(slots, gap, key + '_gap'));
  1256. }
  1257. row.push(EventRowMixin.renderSpan(slots, span, key, content));
  1258. lastEnd = current = right + 1;
  1259. } else {
  1260. if (gap) {
  1261. row.push(EventRowMixin.renderSpan(slots, gap, key + '_gap'));
  1262. }
  1263. row.push(EventRowMixin.renderSpan(slots, 1, key, this.renderShowMore(segments, current)));
  1264. lastEnd = current = current + 1;
  1265. }
  1266. }
  1267. return React.createElement("div", {
  1268. className: "rbc-row"
  1269. }, row);
  1270. };
  1271. _proto.canRenderSlotEvent = function canRenderSlotEvent(slot, span) {
  1272. var segments = this.props.segments;
  1273. return range$1(slot, slot + span).every(function (s) {
  1274. var count = eventsInSlot(segments, s);
  1275. return count === 1;
  1276. });
  1277. };
  1278. _proto.renderShowMore = function renderShowMore(segments, slot) {
  1279. var _this = this;
  1280. var localizer = this.props.localizer;
  1281. var count = eventsInSlot(segments, slot);
  1282. return count ? React.createElement("a", {
  1283. key: 'sm_' + slot,
  1284. href: "#",
  1285. className: 'rbc-show-more',
  1286. onClick: function onClick(e) {
  1287. return _this.showMore(slot, e);
  1288. }
  1289. }, localizer.messages.showMore(count)) : false;
  1290. };
  1291. _proto.showMore = function showMore(slot, e) {
  1292. e.preventDefault();
  1293. this.props.onShowMore(slot, e.target);
  1294. };
  1295. return EventEndingRow;
  1296. }(React.Component);
  1297. EventEndingRow.propTypes = process.env.NODE_ENV !== "production" ? _extends({
  1298. segments: PropTypes.array,
  1299. slots: PropTypes.number,
  1300. onShowMore: PropTypes.func
  1301. }, EventRowMixin.propTypes) : {};
  1302. EventEndingRow.defaultProps = _extends({}, EventRowMixin.defaultProps);
  1303. var isSegmentInSlot$1 = function isSegmentInSlot(seg, slot) {
  1304. return seg.left <= slot && seg.right >= slot;
  1305. };
  1306. var isEqual = function isEqual(a, b) {
  1307. return a.range === b.range && a.events === b.events;
  1308. };
  1309. function getSlotMetrics() {
  1310. return memoize(function (options) {
  1311. var range = options.range,
  1312. events = options.events,
  1313. maxRows = options.maxRows,
  1314. minRows = options.minRows,
  1315. accessors = options.accessors;
  1316. var _endOfRange = endOfRange(range),
  1317. first = _endOfRange.first,
  1318. last = _endOfRange.last;
  1319. var segments = events.map(function (evt) {
  1320. return eventSegments(evt, range, accessors);
  1321. });
  1322. var _eventLevels = eventLevels(segments, Math.max(maxRows - 1, 1)),
  1323. levels = _eventLevels.levels,
  1324. extra = _eventLevels.extra;
  1325. while (levels.length < minRows) {
  1326. levels.push([]);
  1327. }
  1328. return {
  1329. first: first,
  1330. last: last,
  1331. levels: levels,
  1332. extra: extra,
  1333. range: range,
  1334. slots: range.length,
  1335. clone: function clone(args) {
  1336. var metrics = getSlotMetrics();
  1337. return metrics(_extends({}, options, args));
  1338. },
  1339. getDateForSlot: function getDateForSlot(slotNumber) {
  1340. return range[slotNumber];
  1341. },
  1342. getSlotForDate: function getSlotForDate(date) {
  1343. return range.find(function (r) {
  1344. return eq(r, date, 'day');
  1345. });
  1346. },
  1347. getEventsForSlot: function getEventsForSlot(slot) {
  1348. return segments.filter(function (seg) {
  1349. return isSegmentInSlot$1(seg, slot);
  1350. }).map(function (seg) {
  1351. return seg.event;
  1352. });
  1353. },
  1354. continuesPrior: function continuesPrior(event) {
  1355. return lt(accessors.start(event), first, 'day');
  1356. },
  1357. continuesAfter: function continuesAfter(event) {
  1358. var eventEnd = accessors.end(event);
  1359. var singleDayDuration = eq(accessors.start(event), eventEnd, 'minutes');
  1360. return singleDayDuration ? gte(eventEnd, last, 'minutes') : gt(eventEnd, last, 'minutes');
  1361. }
  1362. };
  1363. }, isEqual);
  1364. }
  1365. var DateContentRow =
  1366. /*#__PURE__*/
  1367. function (_React$Component) {
  1368. _inheritsLoose(DateContentRow, _React$Component);
  1369. function DateContentRow() {
  1370. var _this;
  1371. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  1372. args[_key] = arguments[_key];
  1373. }
  1374. _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
  1375. _this.handleSelectSlot = function (slot) {
  1376. var _this$props = _this.props,
  1377. range = _this$props.range,
  1378. onSelectSlot = _this$props.onSelectSlot;
  1379. onSelectSlot(range.slice(slot.start, slot.end + 1), slot);
  1380. };
  1381. _this.handleShowMore = function (slot, target) {
  1382. var _this$props2 = _this.props,
  1383. range = _this$props2.range,
  1384. onShowMore = _this$props2.onShowMore;
  1385. var metrics = _this.slotMetrics(_this.props);
  1386. var row = qsa(findDOMNode(_assertThisInitialized(_this)), '.rbc-row-bg')[0];
  1387. var cell;
  1388. if (row) cell = row.children[slot - 1];
  1389. var events = metrics.getEventsForSlot(slot);
  1390. onShowMore(events, range[slot - 1], cell, slot, target);
  1391. };
  1392. _this.createHeadingRef = function (r) {
  1393. _this.headingRow = r;
  1394. };
  1395. _this.createEventRef = function (r) {
  1396. _this.eventRow = r;
  1397. };
  1398. _this.getContainer = function () {
  1399. var container = _this.props.container;
  1400. return container ? container() : findDOMNode(_assertThisInitialized(_this));
  1401. };
  1402. _this.renderHeadingCell = function (date, index) {
  1403. var _this$props3 = _this.props,
  1404. renderHeader = _this$props3.renderHeader,
  1405. getNow = _this$props3.getNow;
  1406. return renderHeader({
  1407. date: date,
  1408. key: "header_" + index,
  1409. className: clsx('rbc-date-cell', eq(date, getNow(), 'day') && 'rbc-now')
  1410. });
  1411. };
  1412. _this.renderDummy = function () {
  1413. var _this$props4 = _this.props,
  1414. className = _this$props4.className,
  1415. range = _this$props4.range,
  1416. renderHeader = _this$props4.renderHeader;
  1417. return React.createElement("div", {
  1418. className: className
  1419. }, React.createElement("div", {
  1420. className: "rbc-row-content"
  1421. }, renderHeader && React.createElement("div", {
  1422. className: "rbc-row",
  1423. ref: _this.createHeadingRef
  1424. }, range.map(_this.renderHeadingCell)), React.createElement("div", {
  1425. className: "rbc-row",
  1426. ref: _this.createEventRef
  1427. }, React.createElement("div", {
  1428. className: "rbc-row-segment"
  1429. }, React.createElement("div", {
  1430. className: "rbc-event"
  1431. }, React.createElement("div", {
  1432. className: "rbc-event-content"
  1433. }, "\xA0"))))));
  1434. };
  1435. _this.slotMetrics = getSlotMetrics();
  1436. return _this;
  1437. }
  1438. var _proto = DateContentRow.prototype;
  1439. _proto.getRowLimit = function getRowLimit() {
  1440. var eventHeight = getHeight(this.eventRow);
  1441. var headingHeight = this.headingRow ? getHeight(this.headingRow) : 0;
  1442. var eventSpace = getHeight(findDOMNode(this)) - headingHeight;
  1443. return Math.max(Math.floor(eventSpace / eventHeight), 1);
  1444. };
  1445. _proto.render = function render() {
  1446. var _this$props5 = this.props,
  1447. date = _this$props5.date,
  1448. rtl = _this$props5.rtl,
  1449. range = _this$props5.range,
  1450. className = _this$props5.className,
  1451. selected = _this$props5.selected,
  1452. selectable = _this$props5.selectable,
  1453. renderForMeasure = _this$props5.renderForMeasure,
  1454. accessors = _this$props5.accessors,
  1455. getters = _this$props5.getters,
  1456. components = _this$props5.components,
  1457. getNow = _this$props5.getNow,
  1458. renderHeader = _this$props5.renderHeader,
  1459. onSelect = _this$props5.onSelect,
  1460. localizer = _this$props5.localizer,
  1461. onSelectStart = _this$props5.onSelectStart,
  1462. onSelectEnd = _this$props5.onSelectEnd,
  1463. onDoubleClick = _this$props5.onDoubleClick,
  1464. resourceId = _this$props5.resourceId,
  1465. longPressThreshold = _this$props5.longPressThreshold,
  1466. isAllDay = _this$props5.isAllDay;
  1467. if (renderForMeasure) return this.renderDummy();
  1468. var metrics = this.slotMetrics(this.props);
  1469. var levels = metrics.levels,
  1470. extra = metrics.extra;
  1471. var WeekWrapper = components.weekWrapper;
  1472. var eventRowProps = {
  1473. selected: selected,
  1474. accessors: accessors,
  1475. getters: getters,
  1476. localizer: localizer,
  1477. components: components,
  1478. onSelect: onSelect,
  1479. onDoubleClick: onDoubleClick,
  1480. resourceId: resourceId,
  1481. slotMetrics: metrics
  1482. };
  1483. return React.createElement("div", {
  1484. className: className
  1485. }, React.createElement(BackgroundCells, {
  1486. date: date,
  1487. getNow: getNow,
  1488. rtl: rtl,
  1489. range: range,
  1490. selectable: selectable,
  1491. container: this.getContainer,
  1492. getters: getters,
  1493. onSelectStart: onSelectStart,
  1494. onSelectEnd: onSelectEnd,
  1495. onSelectSlot: this.handleSelectSlot,
  1496. components: components,
  1497. longPressThreshold: longPressThreshold
  1498. }), React.createElement("div", {
  1499. className: "rbc-row-content"
  1500. }, renderHeader && React.createElement("div", {
  1501. className: "rbc-row ",
  1502. ref: this.createHeadingRef
  1503. }, range.map(this.renderHeadingCell)), React.createElement(WeekWrapper, _extends({
  1504. isAllDay: isAllDay
  1505. }, eventRowProps), levels.map(function (segs, idx) {
  1506. return React.createElement(EventRow, _extends({
  1507. key: idx,
  1508. segments: segs
  1509. }, eventRowProps));
  1510. }), !!extra.length && React.createElement(EventEndingRow, _extends({
  1511. segments: extra,
  1512. onShowMore: this.handleShowMore
  1513. }, eventRowProps)))));
  1514. };
  1515. return DateContentRow;
  1516. }(React.Component);
  1517. DateContentRow.propTypes = process.env.NODE_ENV !== "production" ? {
  1518. date: PropTypes.instanceOf(Date),
  1519. events: PropTypes.array.isRequired,
  1520. range: PropTypes.array.isRequired,
  1521. rtl: PropTypes.bool,
  1522. resourceId: PropTypes.any,
  1523. renderForMeasure: PropTypes.bool,
  1524. renderHeader: PropTypes.func,
  1525. container: PropTypes.func,
  1526. selected: PropTypes.object,
  1527. selectable: PropTypes.oneOf([true, false, 'ignoreEvents']),
  1528. longPressThreshold: PropTypes.number,
  1529. onShowMore: PropTypes.func,
  1530. onSelectSlot: PropTypes.func,
  1531. onSelect: PropTypes.func,
  1532. onSelectEnd: PropTypes.func,
  1533. onSelectStart: PropTypes.func,
  1534. onDoubleClick: PropTypes.func,
  1535. dayPropGetter: PropTypes.func,
  1536. getNow: PropTypes.func.isRequired,
  1537. isAllDay: PropTypes.bool,
  1538. accessors: PropTypes.object.isRequired,
  1539. components: PropTypes.object.isRequired,
  1540. getters: PropTypes.object.isRequired,
  1541. localizer: PropTypes.object.isRequired,
  1542. minRows: PropTypes.number.isRequired,
  1543. maxRows: PropTypes.number.isRequired
  1544. } : {};
  1545. DateContentRow.defaultProps = {
  1546. minRows: 0,
  1547. maxRows: Infinity
  1548. };
  1549. var Header = function Header(_ref) {
  1550. var label = _ref.label;
  1551. return React.createElement("span", null, label);
  1552. };
  1553. Header.propTypes = process.env.NODE_ENV !== "production" ? {
  1554. label: PropTypes.node
  1555. } : {};
  1556. var DateHeader = function DateHeader(_ref) {
  1557. var label = _ref.label,
  1558. drilldownView = _ref.drilldownView,
  1559. onDrillDown = _ref.onDrillDown;
  1560. if (!drilldownView) {
  1561. return React.createElement("span", null, label);
  1562. }
  1563. return React.createElement("a", {
  1564. href: "#",
  1565. onClick: onDrillDown
  1566. }, label);
  1567. };
  1568. DateHeader.propTypes = process.env.NODE_ENV !== "production" ? {
  1569. label: PropTypes.node,
  1570. date: PropTypes.instanceOf(Date),
  1571. drilldownView: PropTypes.string,
  1572. onDrillDown: PropTypes.func,
  1573. isOffRange: PropTypes.bool
  1574. } : {};
  1575. var eventsForWeek = function eventsForWeek(evts, start, end, accessors) {
  1576. return evts.filter(function (e) {
  1577. return inRange(e, start, end, accessors);
  1578. });
  1579. };
  1580. var MonthView =
  1581. /*#__PURE__*/
  1582. function (_React$Component) {
  1583. _inheritsLoose(MonthView, _React$Component);
  1584. function MonthView() {
  1585. var _this;
  1586. for (var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++) {
  1587. _args[_key] = arguments[_key];
  1588. }
  1589. _this = _React$Component.call.apply(_React$Component, [this].concat(_args)) || this;
  1590. _this.getContainer = function () {
  1591. return findDOMNode(_assertThisInitialized(_this));
  1592. };
  1593. _this.renderWeek = function (week, weekIdx) {
  1594. var _this$props = _this.props,
  1595. events = _this$props.events,
  1596. components = _this$props.components,
  1597. selectable = _this$props.selectable,
  1598. getNow = _this$props.getNow,
  1599. selected = _this$props.selected,
  1600. date = _this$props.date,
  1601. localizer = _this$props.localizer,
  1602. longPressThreshold = _this$props.longPressThreshold,
  1603. accessors = _this$props.accessors,
  1604. getters = _this$props.getters;
  1605. var _this$state = _this.state,
  1606. needLimitMeasure = _this$state.needLimitMeasure,
  1607. rowLimit = _this$state.rowLimit;
  1608. events = eventsForWeek(events, week[0], week[week.length - 1], accessors);
  1609. events.sort(function (a, b) {
  1610. return sortEvents(a, b, accessors);
  1611. });
  1612. return React.createElement(DateContentRow, {
  1613. key: weekIdx,
  1614. ref: weekIdx === 0 ? _this.slotRowRef : undefined,
  1615. container: _this.getContainer,
  1616. className: "rbc-month-row",
  1617. getNow: getNow,
  1618. date: date,
  1619. range: week,
  1620. events: events,
  1621. maxRows: rowLimit,
  1622. selected: selected,
  1623. selectable: selectable,
  1624. components: components,
  1625. accessors: accessors,
  1626. getters: getters,
  1627. localizer: localizer,
  1628. renderHeader: _this.readerDateHeading,
  1629. renderForMeasure: needLimitMeasure,
  1630. onShowMore: _this.handleShowMore,
  1631. onSelect: _this.handleSelectEvent,
  1632. onDoubleClick: _this.handleDoubleClickEvent,
  1633. onSelectSlot: _this.handleSelectSlot,
  1634. longPressThreshold: longPressThreshold,
  1635. rtl: _this.props.rtl
  1636. });
  1637. };
  1638. _this.readerDateHeading = function (_ref) {
  1639. var date = _ref.date,
  1640. className = _ref.className,
  1641. props = _objectWithoutPropertiesLoose(_ref, ["date", "className"]);
  1642. var _this$props2 = _this.props,
  1643. currentDate = _this$props2.date,
  1644. getDrilldownView = _this$props2.getDrilldownView,
  1645. localizer = _this$props2.localizer;
  1646. var isOffRange = month(date) !== month(currentDate);
  1647. var isCurrent = eq(date, currentDate, 'day');
  1648. var drilldownView = getDrilldownView(date);
  1649. var label = localizer.format(date, 'dateFormat');
  1650. var DateHeaderComponent = _this.props.components.dateHeader || DateHeader;
  1651. return React.createElement("div", _extends({}, props, {
  1652. className: clsx(className, isOffRange && 'rbc-off-range', isCurrent && 'rbc-current')
  1653. }), React.createElement(DateHeaderComponent, {
  1654. label: label,
  1655. date: date,
  1656. drilldownView: drilldownView,
  1657. isOffRange: isOffRange,
  1658. onDrillDown: function onDrillDown(e) {
  1659. return _this.handleHeadingClick(date, drilldownView, e);
  1660. }
  1661. }));
  1662. };
  1663. _this.handleSelectSlot = function (range, slotInfo) {
  1664. _this._pendingSelection = _this._pendingSelection.concat(range);
  1665. clearTimeout(_this._selectTimer);
  1666. _this._selectTimer = setTimeout(function () {
  1667. return _this.selectDates(slotInfo);
  1668. });
  1669. };
  1670. _this.handleHeadingClick = function (date, view, e) {
  1671. e.preventDefault();
  1672. _this.clearSelection();
  1673. notify(_this.props.onDrillDown, [date, view]);
  1674. };
  1675. _this.handleSelectEvent = function () {
  1676. _this.clearSelection();
  1677. for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  1678. args[_key2] = arguments[_key2];
  1679. }
  1680. notify(_this.props.onSelectEvent, args);
  1681. };
  1682. _this.handleDoubleClickEvent = function () {
  1683. _this.clearSelection();
  1684. for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
  1685. args[_key3] = arguments[_key3];
  1686. }
  1687. notify(_this.props.onDoubleClickEvent, args);
  1688. };
  1689. _this.handleShowMore = function (events, date, cell, slot, target) {
  1690. var _this$props3 = _this.props,
  1691. popup = _this$props3.popup,
  1692. onDrillDown = _this$props3.onDrillDown,
  1693. onShowMore = _this$props3.onShowMore,
  1694. getDrilldownView = _this$props3.getDrilldownView; //cancel any pending selections so only the event click goes through.
  1695. _this.clearSelection();
  1696. if (popup) {
  1697. var position = getPosition(cell, findDOMNode(_assertThisInitialized(_this)));
  1698. _this.setState({
  1699. overlay: {
  1700. date: date,
  1701. events: events,
  1702. position: position,
  1703. target: target
  1704. }
  1705. });
  1706. } else {
  1707. notify(onDrillDown, [date, getDrilldownView(date) || views.DAY]);
  1708. }
  1709. notify(onShowMore, [events, date, slot]);
  1710. };
  1711. _this._bgRows = [];
  1712. _this._pendingSelection = [];
  1713. _this.slotRowRef = React.createRef();
  1714. _this.state = {
  1715. rowLimit: 5,
  1716. needLimitMeasure: true
  1717. };
  1718. return _this;
  1719. }
  1720. var _proto = MonthView.prototype;
  1721. _proto.componentWillReceiveProps = function componentWillReceiveProps(_ref2) {
  1722. var date = _ref2.date;
  1723. this.setState({
  1724. needLimitMeasure: !eq(date, this.props.date, 'month')
  1725. });
  1726. };
  1727. _proto.componentDidMount = function componentDidMount() {
  1728. var _this2 = this;
  1729. var running;
  1730. if (this.state.needLimitMeasure) this.measureRowLimit(this.props);
  1731. window.addEventListener('resize', this._resizeListener = function () {
  1732. if (!running) {
  1733. request(function () {
  1734. running = false;
  1735. _this2.setState({
  1736. needLimitMeasure: true
  1737. }); //eslint-disable-line
  1738. });
  1739. }
  1740. }, false);
  1741. };
  1742. _proto.componentDidUpdate = function componentDidUpdate() {
  1743. if (this.state.needLimitMeasure) this.measureRowLimit(this.props);
  1744. };
  1745. _proto.componentWillUnmount = function componentWillUnmount() {
  1746. window.removeEventListener('resize', this._resizeListener, false);
  1747. };
  1748. _proto.render = function render() {
  1749. var _this$props4 = this.props,
  1750. date = _this$props4.date,
  1751. localizer = _this$props4.localizer,
  1752. className = _this$props4.className,
  1753. month = visibleDays(date, localizer),
  1754. weeks = chunk(month, 7);
  1755. this._weekCount = weeks.length;
  1756. return React.createElement("div", {
  1757. className: clsx('rbc-month-view', className)
  1758. }, React.createElement("div", {
  1759. className: "rbc-row rbc-month-header"
  1760. }, this.renderHeaders(weeks[0])), weeks.map(this.renderWeek), this.props.popup && this.renderOverlay());
  1761. };
  1762. _proto.renderHeaders = function renderHeaders(row) {
  1763. var _this$props5 = this.props,
  1764. localizer = _this$props5.localizer,
  1765. components = _this$props5.components;
  1766. var first = row[0];
  1767. var last = row[row.length - 1];
  1768. var HeaderComponent = components.header || Header;
  1769. return range(first, last, 'day').map(function (day, idx) {
  1770. return React.createElement("div", {
  1771. key: 'header_' + idx,
  1772. className: "rbc-header"
  1773. }, React.createElement(HeaderComponent, {
  1774. date: day,
  1775. localizer: localizer,
  1776. label: localizer.format(day, 'weekdayFormat')
  1777. }));
  1778. });
  1779. };
  1780. _proto.renderOverlay = function renderOverlay() {
  1781. var _this3 = this;
  1782. var overlay = this.state && this.state.overlay || {};
  1783. var _this$props6 = this.props,
  1784. accessors = _this$props6.accessors,
  1785. localizer = _this$props6.localizer,
  1786. components = _this$props6.components,
  1787. getters = _this$props6.getters,
  1788. selected = _this$props6.selected,
  1789. popupOffset = _this$props6.popupOffset;
  1790. return React.createElement(Overlay, {
  1791. rootClose: true,
  1792. placement: "bottom",
  1793. show: !!overlay.position,
  1794. onHide: function onHide() {
  1795. return _this3.setState({
  1796. overlay: null
  1797. });
  1798. },
  1799. target: function target() {
  1800. return overlay.target;
  1801. }
  1802. }, function (_ref3) {
  1803. var props = _ref3.props;
  1804. return React.createElement(Popup$1, _extends({}, props, {
  1805. popupOffset: popupOffset,
  1806. accessors: accessors,
  1807. getters: getters,
  1808. selected: selected,
  1809. components: components,
  1810. localizer: localizer,
  1811. position: overlay.position,
  1812. events: overlay.events,
  1813. slotStart: overlay.date,
  1814. slotEnd: overlay.end,
  1815. onSelect: _this3.handleSelectEvent,
  1816. onDoubleClick: _this3.handleDoubleClickEvent
  1817. }));
  1818. });
  1819. };
  1820. _proto.measureRowLimit = function measureRowLimit() {
  1821. this.setState({
  1822. needLimitMeasure: false,
  1823. rowLimit: this.slotRowRef.current.getRowLimit()
  1824. });
  1825. };
  1826. _proto.selectDates = function selectDates(slotInfo) {
  1827. var slots = this._pendingSelection.slice();
  1828. this._pendingSelection = [];
  1829. slots.sort(function (a, b) {
  1830. return +a - +b;
  1831. });
  1832. notify(this.props.onSelectSlot, {
  1833. slots: slots,
  1834. start: slots[0],
  1835. end: slots[slots.length - 1],
  1836. action: slotInfo.action,
  1837. bounds: slotInfo.bounds,
  1838. box: slotInfo.box
  1839. });
  1840. };
  1841. _proto.clearSelection = function clearSelection() {
  1842. clearTimeout(this._selectTimer);
  1843. this._pendingSelection = [];
  1844. };
  1845. return MonthView;
  1846. }(React.Component);
  1847. MonthView.propTypes = process.env.NODE_ENV !== "production" ? {
  1848. events: PropTypes.array.isRequired,
  1849. date: PropTypes.instanceOf(Date),
  1850. min: PropTypes.instanceOf(Date),
  1851. max: PropTypes.instanceOf(Date),
  1852. step: PropTypes.number,
  1853. getNow: PropTypes.func.isRequired,
  1854. scrollToTime: PropTypes.instanceOf(Date),
  1855. rtl: PropTypes.bool,
  1856. width: PropTypes.number,
  1857. accessors: PropTypes.object.isRequired,
  1858. components: PropTypes.object.isRequired,
  1859. getters: PropTypes.object.isRequired,
  1860. localizer: PropTypes.object.isRequired,
  1861. selected: PropTypes.object,
  1862. selectable: PropTypes.oneOf([true, false, 'ignoreEvents']),
  1863. longPressThreshold: PropTypes.number,
  1864. onNavigate: PropTypes.func,
  1865. onSelectSlot: PropTypes.func,
  1866. onSelectEvent: PropTypes.func,
  1867. onDoubleClickEvent: PropTypes.func,
  1868. onShowMore: PropTypes.func,
  1869. onDrillDown: PropTypes.func,
  1870. getDrilldownView: PropTypes.func.isRequired,
  1871. popup: PropTypes.bool,
  1872. popupOffset: PropTypes.oneOfType([PropTypes.number, PropTypes.shape({
  1873. x: PropTypes.number,
  1874. y: PropTypes.number
  1875. })])
  1876. } : {};
  1877. MonthView.range = function (date, _ref4) {
  1878. var localizer = _ref4.localizer;
  1879. var start = firstVisibleDay(date, localizer);
  1880. var end = lastVisibleDay(date, localizer);
  1881. return {
  1882. start: start,
  1883. end: end
  1884. };
  1885. };
  1886. MonthView.navigate = function (date, action) {
  1887. switch (action) {
  1888. case navigate.PREVIOUS:
  1889. return add(date, -1, 'month');
  1890. case navigate.NEXT:
  1891. return add(date, 1, 'month');
  1892. default:
  1893. return date;
  1894. }
  1895. };
  1896. MonthView.title = function (date, _ref5) {
  1897. var localizer = _ref5.localizer;
  1898. return localizer.format(date, 'monthHeaderFormat');
  1899. };
  1900. var getDstOffset = function getDstOffset(start, end) {
  1901. return start.getTimezoneOffset() - end.getTimezoneOffset();
  1902. };
  1903. var getKey = function getKey(min, max, step, slots) {
  1904. return "" + +startOf(min, 'minutes') + ("" + +startOf(max, 'minutes')) + (step + "-" + slots);
  1905. };
  1906. function getSlotMetrics$1(_ref) {
  1907. var start = _ref.min,
  1908. end = _ref.max,
  1909. step = _ref.step,
  1910. timeslots = _ref.timeslots;
  1911. var key = getKey(start, end, step, timeslots); // if the start is on a DST-changing day but *after* the moment of DST
  1912. // transition we need to add those extra minutes to our minutesFromMidnight
  1913. var daystart = startOf(start, 'day');
  1914. var daystartdstoffset = getDstOffset(daystart, start);
  1915. var totalMin = 1 + diff(start, end, 'minutes') + getDstOffset(start, end);
  1916. var minutesFromMidnight = diff(daystart, start, 'minutes') + daystartdstoffset;
  1917. var numGroups = Math.ceil(totalMin / (step * timeslots));
  1918. var numSlots = numGroups * timeslots;
  1919. var groups = new Array(numGroups);
  1920. var slots = new Array(numSlots); // Each slot date is created from "zero", instead of adding `step` to
  1921. // the previous one, in order to avoid DST oddities
  1922. for (var grp = 0; grp < numGroups; grp++) {
  1923. groups[grp] = new Array(timeslots);
  1924. for (var slot = 0; slot < timeslots; slot++) {
  1925. var slotIdx = grp * timeslots + slot;
  1926. var minFromStart = slotIdx * step; // A date with total minutes calculated from the start of the day
  1927. slots[slotIdx] = groups[grp][slot] = new Date(start.getFullYear(), start.getMonth(), start.getDate(), 0, minutesFromMidnight + minFromStart, 0, 0);
  1928. }
  1929. } // Necessary to be able to select up until the last timeslot in a day
  1930. var lastSlotMinFromStart = slots.length * step;
  1931. slots.push(new Date(start.getFullYear(), start.getMonth(), start.getDate(), 0, minutesFromMidnight + lastSlotMinFromStart, 0, 0));
  1932. function positionFromDate(date) {
  1933. var diff$1 = diff(start, date, 'minutes') + getDstOffset(start, date);
  1934. return Math.min(diff$1, totalMin);
  1935. }
  1936. return {
  1937. groups: groups,
  1938. update: function update(args) {
  1939. if (getKey(args) !== key) return getSlotMetrics$1(args);
  1940. return this;
  1941. },
  1942. dateIsInGroup: function dateIsInGroup(date, groupIndex) {
  1943. var nextGroup = groups[groupIndex + 1];
  1944. return inRange$1(date, groups[groupIndex][0], nextGroup ? nextGroup[0] : end, 'minutes');
  1945. },
  1946. nextSlot: function nextSlot(slot) {
  1947. var next = slots[Math.min(slots.indexOf(slot) + 1, slots.length - 1)]; // in the case of the last slot we won't a long enough range so manually get it
  1948. if (next === slot) next = add(slot, step, 'minutes');
  1949. return next;
  1950. },
  1951. closestSlotToPosition: function closestSlotToPosition(percent) {
  1952. var slot = Math.min(slots.length - 1, Math.max(0, Math.floor(percent * numSlots)));
  1953. return slots[slot];
  1954. },
  1955. closestSlotFromPoint: function closestSlotFromPoint(point, boundaryRect) {
  1956. var range = Math.abs(boundaryRect.top - boundaryRect.bottom);
  1957. return this.closestSlotToPosition((point.y - boundaryRect.top) / range);
  1958. },
  1959. closestSlotFromDate: function closestSlotFromDate(date, offset) {
  1960. if (offset === void 0) {
  1961. offset = 0;
  1962. }
  1963. if (lt(date, start, 'minutes')) return slots[0];
  1964. var diffMins = diff(start, date, 'minutes');
  1965. return slots[(diffMins - diffMins % step) / step + offset];
  1966. },
  1967. startsBeforeDay: function startsBeforeDay(date) {
  1968. return lt(date, start, 'day');
  1969. },
  1970. startsAfterDay: function startsAfterDay(date) {
  1971. return gt(date, end, 'day');
  1972. },
  1973. startsBefore: function startsBefore(date) {
  1974. return lt(merge(start, date), start, 'minutes');
  1975. },
  1976. startsAfter: function startsAfter(date) {
  1977. return gt(merge(end, date), end, 'minutes');
  1978. },
  1979. getRange: function getRange(rangeStart, rangeEnd, ignoreMin, ignoreMax) {
  1980. if (!ignoreMin) rangeStart = min(end, max(start, rangeStart));
  1981. if (!ignoreMax) rangeEnd = min(end, max(start, rangeEnd));
  1982. var rangeStartMin = positionFromDate(rangeStart);
  1983. var rangeEndMin = positionFromDate(rangeEnd);
  1984. var top = rangeEndMin - rangeStartMin < step && !eq(end, rangeEnd) ? (rangeStartMin - step) / (step * numSlots) * 100 : rangeStartMin / (step * numSlots) * 100;
  1985. return {
  1986. top: top,
  1987. height: rangeEndMin / (step * numSlots) * 100 - top,
  1988. start: positionFromDate(rangeStart),
  1989. startDate: rangeStart,
  1990. end: positionFromDate(rangeEnd),
  1991. endDate: rangeEnd
  1992. };
  1993. },
  1994. getCurrentTimePosition: function getCurrentTimePosition(rangeStart) {
  1995. var rangeStartMin = positionFromDate(rangeStart);
  1996. var top = rangeStartMin / (step * numSlots) * 100;
  1997. return top;
  1998. }
  1999. };
  2000. }
  2001. var Event =
  2002. /*#__PURE__*/
  2003. function () {
  2004. function Event(data, _ref) {
  2005. var accessors = _ref.accessors,
  2006. slotMetrics = _ref.slotMetrics;
  2007. var _slotMetrics$getRange = slotMetrics.getRange(accessors.start(data), accessors.end(data)),
  2008. start = _slotMetrics$getRange.start,
  2009. startDate = _slotMetrics$getRange.startDate,
  2010. end = _slotMetrics$getRange.end,
  2011. endDate = _slotMetrics$getRange.endDate,
  2012. top = _slotMetrics$getRange.top,
  2013. height = _slotMetrics$getRange.height;
  2014. this.start = start;
  2015. this.end = end;
  2016. this.startMs = +startDate;
  2017. this.endMs = +endDate;
  2018. this.top = top;
  2019. this.height = height;
  2020. this.data = data;
  2021. }
  2022. /**
  2023. * The event's width without any overlap.
  2024. */
  2025. _createClass(Event, [{
  2026. key: "_width",
  2027. get: function get() {
  2028. // The container event's width is determined by the maximum number of
  2029. // events in any of its rows.
  2030. if (this.rows) {
  2031. var columns = this.rows.reduce(function (max, row) {
  2032. return Math.max(max, row.leaves.length + 1);
  2033. }, // add itself
  2034. 0) + 1; // add the container
  2035. return 100 / columns;
  2036. }
  2037. var availableWidth = 100 - this.container._width; // The row event's width is the space left by the container, divided
  2038. // among itself and its leaves.
  2039. if (this.leaves) {
  2040. return availableWidth / (this.leaves.length + 1);
  2041. } // The leaf event's width is determined by its row's width
  2042. return this.row._width;
  2043. }
  2044. /**
  2045. * The event's calculated width, possibly with extra width added for
  2046. * overlapping effect.
  2047. */
  2048. }, {
  2049. key: "width",
  2050. get: function get() {
  2051. var noOverlap = this._width;
  2052. var overlap = Math.min(100, this._width * 1.7); // Containers can always grow.
  2053. if (this.rows) {
  2054. return overlap;
  2055. } // Rows can grow if they have leaves.
  2056. if (this.leaves) {
  2057. return this.leaves.length > 0 ? overlap : noOverlap;
  2058. } // Leaves can grow unless they're the last item in a row.
  2059. var leaves = this.row.leaves;
  2060. var index = leaves.indexOf(this);
  2061. return index === leaves.length - 1 ? noOverlap : overlap;
  2062. }
  2063. }, {
  2064. key: "xOffset",
  2065. get: function get() {
  2066. // Containers have no offset.
  2067. if (this.rows) return 0; // Rows always start where their container ends.
  2068. if (this.leaves) return this.container._width; // Leaves are spread out evenly on the space left by its row.
  2069. var _this$row = this.row,
  2070. leaves = _this$row.leaves,
  2071. xOffset = _this$row.xOffset,
  2072. _width = _this$row._width;
  2073. var index = leaves.indexOf(this) + 1;
  2074. return xOffset + index * _width;
  2075. }
  2076. }]);
  2077. return Event;
  2078. }();
  2079. /**
  2080. * Return true if event a and b is considered to be on the same row.
  2081. */
  2082. function onSameRow(a, b, minimumStartDifference) {
  2083. return (// Occupies the same start slot.
  2084. Math.abs(b.start - a.start) < minimumStartDifference || // A's start slot overlaps with b's end slot.
  2085. b.start > a.start && b.start < a.end
  2086. );
  2087. }
  2088. function sortByRender(events) {
  2089. var sortedByTime = sortBy(events, ['startMs', function (e) {
  2090. return -e.endMs;
  2091. }]);
  2092. var sorted = [];
  2093. while (sortedByTime.length > 0) {
  2094. var event = sortedByTime.shift();
  2095. sorted.push(event);
  2096. for (var i = 0; i < sortedByTime.length; i++) {
  2097. var test = sortedByTime[i]; // Still inside this event, look for next.
  2098. if (event.endMs > test.startMs) continue; // We've found the first event of the next event group.
  2099. // If that event is not right next to our current event, we have to
  2100. // move it here.
  2101. if (i > 0) {
  2102. var _event = sortedByTime.splice(i, 1)[0];
  2103. sorted.push(_event);
  2104. } // We've already found the next event group, so stop looking.
  2105. break;
  2106. }
  2107. }
  2108. return sorted;
  2109. }
  2110. function getStyledEvents(_ref2) {
  2111. var events = _ref2.events,
  2112. minimumStartDifference = _ref2.minimumStartDifference,
  2113. slotMetrics = _ref2.slotMetrics,
  2114. accessors = _ref2.accessors;
  2115. // Create proxy events and order them so that we don't have
  2116. // to fiddle with z-indexes.
  2117. var proxies = events.map(function (event) {
  2118. return new Event(event, {
  2119. slotMetrics: slotMetrics,
  2120. accessors: accessors
  2121. });
  2122. });
  2123. var eventsInRenderOrder = sortByRender(proxies); // Group overlapping events, while keeping order.
  2124. // Every event is always one of: container, row or leaf.
  2125. // Containers can contain rows, and rows can contain leaves.
  2126. var containerEvents = [];
  2127. var _loop = function _loop(i) {
  2128. var event = eventsInRenderOrder[i]; // Check if this event can go into a container event.
  2129. var container = containerEvents.find(function (c) {
  2130. return c.end > event.start || Math.abs(event.start - c.start) < minimumStartDifference;
  2131. }); // Couldn't find a container — that means this event is a container.
  2132. if (!container) {
  2133. event.rows = [];
  2134. containerEvents.push(event);
  2135. return "continue";
  2136. } // Found a container for the event.
  2137. event.container = container; // Check if the event can be placed in an existing row.
  2138. // Start looking from behind.
  2139. var row = null;
  2140. for (var j = container.rows.length - 1; !row && j >= 0; j--) {
  2141. if (onSameRow(container.rows[j], event, minimumStartDifference)) {
  2142. row = container.rows[j];
  2143. }
  2144. }
  2145. if (row) {
  2146. // Found a row, so add it.
  2147. row.leaves.push(event);
  2148. event.row = row;
  2149. } else {
  2150. // Couldn't find a row – that means this event is a row.
  2151. event.leaves = [];
  2152. container.rows.push(event);
  2153. }
  2154. };
  2155. for (var i = 0; i < eventsInRenderOrder.length; i++) {
  2156. var _ret = _loop(i);
  2157. if (_ret === "continue") continue;
  2158. } // Return the original events, along with their styles.
  2159. return eventsInRenderOrder.map(function (event) {
  2160. return {
  2161. event: event.data,
  2162. style: {
  2163. top: event.top,
  2164. height: event.height,
  2165. width: event.width,
  2166. xOffset: event.xOffset
  2167. }
  2168. };
  2169. });
  2170. }
  2171. var TimeSlotGroup =
  2172. /*#__PURE__*/
  2173. function (_Component) {
  2174. _inheritsLoose(TimeSlotGroup, _Component);
  2175. function TimeSlotGroup() {
  2176. return _Component.apply(this, arguments) || this;
  2177. }
  2178. var _proto = TimeSlotGroup.prototype;
  2179. _proto.render = function render() {
  2180. var _this$props = this.props,
  2181. renderSlot = _this$props.renderSlot,
  2182. resource = _this$props.resource,
  2183. group = _this$props.group,
  2184. getters = _this$props.getters,
  2185. _this$props$component = _this$props.components;
  2186. _this$props$component = _this$props$component === void 0 ? {} : _this$props$component;
  2187. var _this$props$component2 = _this$props$component.timeSlotWrapper,
  2188. Wrapper = _this$props$component2 === void 0 ? NoopWrapper : _this$props$component2;
  2189. return React.createElement("div", {
  2190. className: "rbc-timeslot-group"
  2191. }, group.map(function (value, idx) {
  2192. var slotProps = getters ? getters.slotProp(value, resource) : {};
  2193. return React.createElement(Wrapper, {
  2194. key: idx,
  2195. value: value,
  2196. resource: resource
  2197. }, React.createElement("div", _extends({}, slotProps, {
  2198. className: clsx('rbc-time-slot', slotProps.className)
  2199. }), renderSlot && renderSlot(value, idx)));
  2200. }));
  2201. };
  2202. return TimeSlotGroup;
  2203. }(Component);
  2204. TimeSlotGroup.propTypes = process.env.NODE_ENV !== "production" ? {
  2205. renderSlot: PropTypes.func,
  2206. group: PropTypes.array.isRequired,
  2207. resource: PropTypes.any,
  2208. components: PropTypes.object,
  2209. getters: PropTypes.object
  2210. } : {};
  2211. /* eslint-disable react/prop-types */
  2212. function TimeGridEvent(props) {
  2213. var _extends2;
  2214. var style = props.style,
  2215. className = props.className,
  2216. event = props.event,
  2217. accessors = props.accessors,
  2218. rtl = props.rtl,
  2219. selected = props.selected,
  2220. label = props.label,
  2221. continuesEarlier = props.continuesEarlier,
  2222. continuesLater = props.continuesLater,
  2223. getters = props.getters,
  2224. onClick = props.onClick,
  2225. onDoubleClick = props.onDoubleClick,
  2226. _props$components = props.components,
  2227. Event = _props$components.event,
  2228. EventWrapper = _props$components.eventWrapper;
  2229. var title = accessors.title(event);
  2230. var tooltip = accessors.tooltip(event);
  2231. var end = accessors.end(event);
  2232. var start = accessors.start(event);
  2233. var userProps = getters.eventProp(event, start, end, selected);
  2234. var height = style.height,
  2235. top = style.top,
  2236. width = style.width,
  2237. xOffset = style.xOffset;
  2238. var inner = [React.createElement("div", {
  2239. key: "1",
  2240. className: "rbc-event-label"
  2241. }, label), React.createElement("div", {
  2242. key: "2",
  2243. className: "rbc-event-content"
  2244. }, Event ? React.createElement(Event, {
  2245. event: event,
  2246. title: title
  2247. }) : title)];
  2248. return React.createElement(EventWrapper, _extends({
  2249. type: "time"
  2250. }, props), React.createElement("div", {
  2251. onClick: onClick,
  2252. onDoubleClick: onDoubleClick,
  2253. style: _extends({}, userProps.style, (_extends2 = {
  2254. top: top + "%",
  2255. height: height + "%"
  2256. }, _extends2[rtl ? 'right' : 'left'] = Math.max(0, xOffset) + "%", _extends2.width = width + "%", _extends2)),
  2257. title: tooltip ? (typeof label === 'string' ? label + ': ' : '') + tooltip : undefined,
  2258. className: clsx('rbc-event', className, userProps.className, {
  2259. 'rbc-selected': selected,
  2260. 'rbc-event-continues-earlier': continuesEarlier,
  2261. 'rbc-event-continues-later': continuesLater
  2262. })
  2263. }, inner));
  2264. }
  2265. var DayColumn =
  2266. /*#__PURE__*/
  2267. function (_React$Component) {
  2268. _inheritsLoose(DayColumn, _React$Component);
  2269. function DayColumn() {
  2270. var _this;
  2271. for (var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++) {
  2272. _args[_key] = arguments[_key];
  2273. }
  2274. _this = _React$Component.call.apply(_React$Component, [this].concat(_args)) || this;
  2275. _this.state = {
  2276. selecting: false,
  2277. timeIndicatorPosition: null
  2278. };
  2279. _this.intervalTriggered = false;
  2280. _this.renderEvents = function () {
  2281. var _this$props = _this.props,
  2282. events = _this$props.events,
  2283. rtl = _this$props.rtl,
  2284. selected = _this$props.selected,
  2285. accessors = _this$props.accessors,
  2286. localizer = _this$props.localizer,
  2287. getters = _this$props.getters,
  2288. components = _this$props.components,
  2289. step = _this$props.step,
  2290. timeslots = _this$props.timeslots;
  2291. var _assertThisInitialize = _assertThisInitialized(_this),
  2292. slotMetrics = _assertThisInitialize.slotMetrics;
  2293. var messages = localizer.messages;
  2294. var styledEvents = getStyledEvents({
  2295. events: events,
  2296. accessors: accessors,
  2297. slotMetrics: slotMetrics,
  2298. minimumStartDifference: Math.ceil(step * timeslots / 2)
  2299. });
  2300. return styledEvents.map(function (_ref, idx) {
  2301. var event = _ref.event,
  2302. style = _ref.style;
  2303. var end = accessors.end(event);
  2304. var start = accessors.start(event);
  2305. var format = 'eventTimeRangeFormat';
  2306. var label;
  2307. var startsBeforeDay = slotMetrics.startsBeforeDay(start);
  2308. var startsAfterDay = slotMetrics.startsAfterDay(end);
  2309. if (startsBeforeDay) format = 'eventTimeRangeEndFormat';else if (startsAfterDay) format = 'eventTimeRangeStartFormat';
  2310. if (startsBeforeDay && startsAfterDay) label = messages.allDay;else label = localizer.format({
  2311. start: start,
  2312. end: end
  2313. }, format);
  2314. var continuesEarlier = startsBeforeDay || slotMetrics.startsBefore(start);
  2315. var continuesLater = startsAfterDay || slotMetrics.startsAfter(end);
  2316. return React.createElement(TimeGridEvent, {
  2317. style: style,
  2318. event: event,
  2319. label: label,
  2320. key: 'evt_' + idx,
  2321. getters: getters,
  2322. rtl: rtl,
  2323. components: components,
  2324. continuesEarlier: continuesEarlier,
  2325. continuesLater: continuesLater,
  2326. accessors: accessors,
  2327. selected: isSelected(event, selected),
  2328. onClick: function onClick(e) {
  2329. return _this._select(event, e);
  2330. },
  2331. onDoubleClick: function onDoubleClick(e) {
  2332. return _this._doubleClick(event, e);
  2333. }
  2334. });
  2335. });
  2336. };
  2337. _this._selectable = function () {
  2338. var node = findDOMNode(_assertThisInitialized(_this));
  2339. var selector = _this._selector = new Selection(function () {
  2340. return findDOMNode(_assertThisInitialized(_this));
  2341. }, {
  2342. longPressThreshold: _this.props.longPressThreshold
  2343. });
  2344. var maybeSelect = function maybeSelect(box) {
  2345. var onSelecting = _this.props.onSelecting;
  2346. var current = _this.state || {};
  2347. var state = selectionState(box);
  2348. var start = state.startDate,
  2349. end = state.endDate;
  2350. if (onSelecting) {
  2351. if (eq(current.startDate, start, 'minutes') && eq(current.endDate, end, 'minutes') || onSelecting({
  2352. start: start,
  2353. end: end
  2354. }) === false) return;
  2355. }
  2356. if (_this.state.start !== state.start || _this.state.end !== state.end || _this.state.selecting !== state.selecting) {
  2357. _this.setState(state);
  2358. }
  2359. };
  2360. var selectionState = function selectionState(point) {
  2361. var currentSlot = _this.slotMetrics.closestSlotFromPoint(point, getBoundsForNode(node));
  2362. if (!_this.state.selecting) {
  2363. _this._initialSlot = currentSlot;
  2364. }
  2365. var initialSlot = _this._initialSlot;
  2366. if (lte(initialSlot, currentSlot)) {
  2367. currentSlot = _this.slotMetrics.nextSlot(currentSlot);
  2368. } else if (gt(initialSlot, currentSlot)) {
  2369. initialSlot = _this.slotMetrics.nextSlot(initialSlot);
  2370. }
  2371. var selectRange = _this.slotMetrics.getRange(min(initialSlot, currentSlot), max(initialSlot, currentSlot));
  2372. return _extends({}, selectRange, {
  2373. selecting: true,
  2374. top: selectRange.top + "%",
  2375. height: selectRange.height + "%"
  2376. });
  2377. };
  2378. var selectorClicksHandler = function selectorClicksHandler(box, actionType) {
  2379. if (!isEvent(findDOMNode(_assertThisInitialized(_this)), box)) {
  2380. var _selectionState = selectionState(box),
  2381. startDate = _selectionState.startDate,
  2382. endDate = _selectionState.endDate;
  2383. _this._selectSlot({
  2384. startDate: startDate,
  2385. endDate: endDate,
  2386. action: actionType,
  2387. box: box
  2388. });
  2389. }
  2390. _this.setState({
  2391. selecting: false
  2392. });
  2393. };
  2394. selector.on('selecting', maybeSelect);
  2395. selector.on('selectStart', maybeSelect);
  2396. selector.on('beforeSelect', function (box) {
  2397. if (_this.props.selectable !== 'ignoreEvents') return;
  2398. return !isEvent(findDOMNode(_assertThisInitialized(_this)), box);
  2399. });
  2400. selector.on('click', function (box) {
  2401. return selectorClicksHandler(box, 'click');
  2402. });
  2403. selector.on('doubleClick', function (box) {
  2404. return selectorClicksHandler(box, 'doubleClick');
  2405. });
  2406. selector.on('select', function (bounds) {
  2407. if (_this.state.selecting) {
  2408. _this._selectSlot(_extends({}, _this.state, {
  2409. action: 'select',
  2410. bounds: bounds
  2411. }));
  2412. _this.setState({
  2413. selecting: false
  2414. });
  2415. }
  2416. });
  2417. selector.on('reset', function () {
  2418. if (_this.state.selecting) {
  2419. _this.setState({
  2420. selecting: false
  2421. });
  2422. }
  2423. });
  2424. };
  2425. _this._teardownSelectable = function () {
  2426. if (!_this._selector) return;
  2427. _this._selector.teardown();
  2428. _this._selector = null;
  2429. };
  2430. _this._selectSlot = function (_ref2) {
  2431. var startDate = _ref2.startDate,
  2432. endDate = _ref2.endDate,
  2433. action = _ref2.action,
  2434. bounds = _ref2.bounds,
  2435. box = _ref2.box;
  2436. var current = startDate,
  2437. slots = [];
  2438. while (lte(current, endDate)) {
  2439. slots.push(current);
  2440. current = add(current, _this.props.step, 'minutes');
  2441. }
  2442. notify(_this.props.onSelectSlot, {
  2443. slots: slots,
  2444. start: startDate,
  2445. end: endDate,
  2446. resourceId: _this.props.resource,
  2447. action: action,
  2448. bounds: bounds,
  2449. box: box
  2450. });
  2451. };
  2452. _this._select = function () {
  2453. for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  2454. args[_key2] = arguments[_key2];
  2455. }
  2456. notify(_this.props.onSelectEvent, args);
  2457. };
  2458. _this._doubleClick = function () {
  2459. for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
  2460. args[_key3] = arguments[_key3];
  2461. }
  2462. notify(_this.props.onDoubleClickEvent, args);
  2463. };
  2464. _this.slotMetrics = getSlotMetrics$1(_this.props);
  2465. return _this;
  2466. }
  2467. var _proto = DayColumn.prototype;
  2468. _proto.componentDidMount = function componentDidMount() {
  2469. this.props.selectable && this._selectable();
  2470. if (this.props.isNow) {
  2471. this.setTimeIndicatorPositionUpdateInterval();
  2472. }
  2473. };
  2474. _proto.componentWillUnmount = function componentWillUnmount() {
  2475. this._teardownSelectable();
  2476. this.clearTimeIndicatorInterval();
  2477. };
  2478. _proto.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
  2479. if (nextProps.selectable && !this.props.selectable) this._selectable();
  2480. if (!nextProps.selectable && this.props.selectable) this._teardownSelectable();
  2481. this.slotMetrics = this.slotMetrics.update(nextProps);
  2482. };
  2483. _proto.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {
  2484. var getNowChanged = !eq(prevProps.getNow(), this.props.getNow(), 'minutes');
  2485. if (prevProps.isNow !== this.props.isNow || getNowChanged) {
  2486. this.clearTimeIndicatorInterval();
  2487. if (this.props.isNow) {
  2488. var tail = !getNowChanged && eq(prevProps.date, this.props.date, 'minutes') && prevState.timeIndicatorPosition === this.state.timeIndicatorPosition;
  2489. this.setTimeIndicatorPositionUpdateInterval(tail);
  2490. }
  2491. } else if (this.props.isNow && (!eq(prevProps.min, this.props.min, 'minutes') || !eq(prevProps.max, this.props.max, 'minutes'))) {
  2492. this.positionTimeIndicator();
  2493. }
  2494. };
  2495. /**
  2496. * @param tail {Boolean} - whether `positionTimeIndicator` call should be
  2497. * deferred or called upon setting interval (`true` - if deferred);
  2498. */
  2499. _proto.setTimeIndicatorPositionUpdateInterval = function setTimeIndicatorPositionUpdateInterval(tail) {
  2500. var _this2 = this;
  2501. if (tail === void 0) {
  2502. tail = false;
  2503. }
  2504. if (!this.intervalTriggered && !tail) {
  2505. this.positionTimeIndicator();
  2506. }
  2507. this._timeIndicatorTimeout = window.setTimeout(function () {
  2508. _this2.intervalTriggered = true;
  2509. _this2.positionTimeIndicator();
  2510. _this2.setTimeIndicatorPositionUpdateInterval();
  2511. }, 60000);
  2512. };
  2513. _proto.clearTimeIndicatorInterval = function clearTimeIndicatorInterval() {
  2514. this.intervalTriggered = false;
  2515. window.clearTimeout(this._timeIndicatorTimeout);
  2516. };
  2517. _proto.positionTimeIndicator = function positionTimeIndicator() {
  2518. var _this$props2 = this.props,
  2519. min = _this$props2.min,
  2520. max = _this$props2.max,
  2521. getNow = _this$props2.getNow;
  2522. var current = getNow();
  2523. if (current >= min && current <= max) {
  2524. var top = this.slotMetrics.getCurrentTimePosition(current);
  2525. this.setState({
  2526. timeIndicatorPosition: top
  2527. });
  2528. } else {
  2529. this.clearTimeIndicatorInterval();
  2530. }
  2531. };
  2532. _proto.render = function render() {
  2533. var _this$props3 = this.props,
  2534. max = _this$props3.max,
  2535. rtl = _this$props3.rtl,
  2536. isNow = _this$props3.isNow,
  2537. resource = _this$props3.resource,
  2538. accessors = _this$props3.accessors,
  2539. localizer = _this$props3.localizer,
  2540. _this$props3$getters = _this$props3.getters,
  2541. dayProp = _this$props3$getters.dayProp,
  2542. getters = _objectWithoutPropertiesLoose(_this$props3$getters, ["dayProp"]),
  2543. _this$props3$componen = _this$props3.components,
  2544. EventContainer = _this$props3$componen.eventContainerWrapper,
  2545. components = _objectWithoutPropertiesLoose(_this$props3$componen, ["eventContainerWrapper"]);
  2546. var slotMetrics = this.slotMetrics;
  2547. var _this$state = this.state,
  2548. selecting = _this$state.selecting,
  2549. top = _this$state.top,
  2550. height = _this$state.height,
  2551. startDate = _this$state.startDate,
  2552. endDate = _this$state.endDate;
  2553. var selectDates = {
  2554. start: startDate,
  2555. end: endDate
  2556. };
  2557. var _dayProp = dayProp(max),
  2558. className = _dayProp.className,
  2559. style = _dayProp.style;
  2560. return React.createElement("div", {
  2561. style: style,
  2562. className: clsx(className, 'rbc-day-slot', 'rbc-time-column', isNow && 'rbc-now', isNow && 'rbc-today', // WHY
  2563. selecting && 'rbc-slot-selecting')
  2564. }, slotMetrics.groups.map(function (grp, idx) {
  2565. return React.createElement(TimeSlotGroup, {
  2566. key: idx,
  2567. group: grp,
  2568. resource: resource,
  2569. getters: getters,
  2570. components: components
  2571. });
  2572. }), React.createElement(EventContainer, {
  2573. localizer: localizer,
  2574. resource: resource,
  2575. accessors: accessors,
  2576. getters: getters,
  2577. components: components,
  2578. slotMetrics: slotMetrics
  2579. }, React.createElement("div", {
  2580. className: clsx('rbc-events-container', rtl && 'rtl')
  2581. }, this.renderEvents())), selecting && React.createElement("div", {
  2582. className: "rbc-slot-selection",
  2583. style: {
  2584. top: top,
  2585. height: height
  2586. }
  2587. }, React.createElement("span", null, localizer.format(selectDates, 'selectRangeFormat'))), isNow && React.createElement("div", {
  2588. className: "rbc-current-time-indicator",
  2589. style: {
  2590. top: this.state.timeIndicatorPosition + "%"
  2591. }
  2592. }));
  2593. };
  2594. return DayColumn;
  2595. }(React.Component);
  2596. DayColumn.propTypes = process.env.NODE_ENV !== "production" ? {
  2597. events: PropTypes.array.isRequired,
  2598. step: PropTypes.number.isRequired,
  2599. date: PropTypes.instanceOf(Date).isRequired,
  2600. min: PropTypes.instanceOf(Date).isRequired,
  2601. max: PropTypes.instanceOf(Date).isRequired,
  2602. getNow: PropTypes.func.isRequired,
  2603. isNow: PropTypes.bool,
  2604. rtl: PropTypes.bool,
  2605. accessors: PropTypes.object.isRequired,
  2606. components: PropTypes.object.isRequired,
  2607. getters: PropTypes.object.isRequired,
  2608. localizer: PropTypes.object.isRequired,
  2609. showMultiDayTimes: PropTypes.bool,
  2610. culture: PropTypes.string,
  2611. timeslots: PropTypes.number,
  2612. selected: PropTypes.object,
  2613. selectable: PropTypes.oneOf([true, false, 'ignoreEvents']),
  2614. eventOffset: PropTypes.number,
  2615. longPressThreshold: PropTypes.number,
  2616. onSelecting: PropTypes.func,
  2617. onSelectSlot: PropTypes.func.isRequired,
  2618. onSelectEvent: PropTypes.func.isRequired,
  2619. onDoubleClickEvent: PropTypes.func.isRequired,
  2620. className: PropTypes.string,
  2621. dragThroughEvents: PropTypes.bool,
  2622. resource: PropTypes.any
  2623. } : {};
  2624. DayColumn.defaultProps = {
  2625. dragThroughEvents: true,
  2626. timeslots: 2
  2627. };
  2628. var TimeGutter =
  2629. /*#__PURE__*/
  2630. function (_Component) {
  2631. _inheritsLoose(TimeGutter, _Component);
  2632. function TimeGutter() {
  2633. var _this;
  2634. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  2635. args[_key] = arguments[_key];
  2636. }
  2637. _this = _Component.call.apply(_Component, [this].concat(args)) || this;
  2638. _this.renderSlot = function (value, idx) {
  2639. if (idx !== 0) return null;
  2640. var _this$props = _this.props,
  2641. localizer = _this$props.localizer,
  2642. getNow = _this$props.getNow;
  2643. var isNow = _this.slotMetrics.dateIsInGroup(getNow(), idx);
  2644. return React.createElement("span", {
  2645. className: clsx('rbc-label', isNow && 'rbc-now')
  2646. }, localizer.format(value, 'timeGutterFormat'));
  2647. };
  2648. var _this$props2 = _this.props,
  2649. min = _this$props2.min,
  2650. max = _this$props2.max,
  2651. timeslots = _this$props2.timeslots,
  2652. step = _this$props2.step;
  2653. _this.slotMetrics = getSlotMetrics$1({
  2654. min: min,
  2655. max: max,
  2656. timeslots: timeslots,
  2657. step: step
  2658. });
  2659. return _this;
  2660. }
  2661. var _proto = TimeGutter.prototype;
  2662. _proto.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
  2663. var min = nextProps.min,
  2664. max = nextProps.max,
  2665. timeslots = nextProps.timeslots,
  2666. step = nextProps.step;
  2667. this.slotMetrics = this.slotMetrics.update({
  2668. min: min,
  2669. max: max,
  2670. timeslots: timeslots,
  2671. step: step
  2672. });
  2673. };
  2674. _proto.render = function render() {
  2675. var _this2 = this;
  2676. var _this$props3 = this.props,
  2677. resource = _this$props3.resource,
  2678. components = _this$props3.components;
  2679. return React.createElement("div", {
  2680. className: "rbc-time-gutter rbc-time-column"
  2681. }, this.slotMetrics.groups.map(function (grp, idx) {
  2682. return React.createElement(TimeSlotGroup, {
  2683. key: idx,
  2684. group: grp,
  2685. resource: resource,
  2686. components: components,
  2687. renderSlot: _this2.renderSlot
  2688. });
  2689. }));
  2690. };
  2691. return TimeGutter;
  2692. }(Component);
  2693. TimeGutter.propTypes = process.env.NODE_ENV !== "production" ? {
  2694. min: PropTypes.instanceOf(Date).isRequired,
  2695. max: PropTypes.instanceOf(Date).isRequired,
  2696. timeslots: PropTypes.number.isRequired,
  2697. step: PropTypes.number.isRequired,
  2698. getNow: PropTypes.func.isRequired,
  2699. components: PropTypes.object.isRequired,
  2700. localizer: PropTypes.object.isRequired,
  2701. resource: PropTypes.string
  2702. } : {};
  2703. var ResourceHeader = function ResourceHeader(_ref) {
  2704. var label = _ref.label;
  2705. return React.createElement(React.Fragment, null, label);
  2706. };
  2707. ResourceHeader.propTypes = process.env.NODE_ENV !== "production" ? {
  2708. label: PropTypes.node,
  2709. index: PropTypes.number,
  2710. resource: PropTypes.object
  2711. } : {};
  2712. var TimeGridHeader =
  2713. /*#__PURE__*/
  2714. function (_React$Component) {
  2715. _inheritsLoose(TimeGridHeader, _React$Component);
  2716. function TimeGridHeader() {
  2717. var _this;
  2718. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  2719. args[_key] = arguments[_key];
  2720. }
  2721. _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
  2722. _this.handleHeaderClick = function (date, view, e) {
  2723. e.preventDefault();
  2724. notify(_this.props.onDrillDown, [date, view]);
  2725. };
  2726. _this.renderRow = function (resource) {
  2727. var _this$props = _this.props,
  2728. events = _this$props.events,
  2729. rtl = _this$props.rtl,
  2730. selectable = _this$props.selectable,
  2731. getNow = _this$props.getNow,
  2732. range = _this$props.range,
  2733. getters = _this$props.getters,
  2734. localizer = _this$props.localizer,
  2735. accessors = _this$props.accessors,
  2736. components = _this$props.components;
  2737. var resourceId = accessors.resourceId(resource);
  2738. var eventsToDisplay = resource ? events.filter(function (event) {
  2739. return accessors.resource(event) === resourceId;
  2740. }) : events;
  2741. return React.createElement(DateContentRow, {
  2742. isAllDay: true,
  2743. rtl: rtl,
  2744. getNow: getNow,
  2745. minRows: 2,
  2746. range: range,
  2747. events: eventsToDisplay,
  2748. resourceId: resourceId,
  2749. className: "rbc-allday-cell",
  2750. selectable: selectable,
  2751. selected: _this.props.selected,
  2752. components: components,
  2753. accessors: accessors,
  2754. getters: getters,
  2755. localizer: localizer,
  2756. onSelect: _this.props.onSelectEvent,
  2757. onDoubleClick: _this.props.onDoubleClickEvent,
  2758. onSelectSlot: _this.props.onSelectSlot,
  2759. longPressThreshold: _this.props.longPressThreshold
  2760. });
  2761. };
  2762. return _this;
  2763. }
  2764. var _proto = TimeGridHeader.prototype;
  2765. _proto.renderHeaderCells = function renderHeaderCells(range) {
  2766. var _this2 = this;
  2767. var _this$props2 = this.props,
  2768. localizer = _this$props2.localizer,
  2769. getDrilldownView = _this$props2.getDrilldownView,
  2770. getNow = _this$props2.getNow,
  2771. dayProp = _this$props2.getters.dayProp,
  2772. _this$props2$componen = _this$props2.components.header,
  2773. HeaderComponent = _this$props2$componen === void 0 ? Header : _this$props2$componen;
  2774. var today = getNow();
  2775. return range.map(function (date, i) {
  2776. var drilldownView = getDrilldownView(date);
  2777. var label = localizer.format(date, 'dayFormat');
  2778. var _dayProp = dayProp(date),
  2779. className = _dayProp.className,
  2780. style = _dayProp.style;
  2781. var header = React.createElement(HeaderComponent, {
  2782. date: date,
  2783. label: label,
  2784. localizer: localizer
  2785. });
  2786. return React.createElement("div", {
  2787. key: i,
  2788. style: style,
  2789. className: clsx('rbc-header', className, eq(date, today, 'day') && 'rbc-today')
  2790. }, drilldownView ? React.createElement("a", {
  2791. href: "#",
  2792. onClick: function onClick(e) {
  2793. return _this2.handleHeaderClick(date, drilldownView, e);
  2794. }
  2795. }, header) : React.createElement("span", null, header));
  2796. });
  2797. };
  2798. _proto.render = function render() {
  2799. var _this3 = this;
  2800. var _this$props3 = this.props,
  2801. width = _this$props3.width,
  2802. rtl = _this$props3.rtl,
  2803. resources = _this$props3.resources,
  2804. range = _this$props3.range,
  2805. events = _this$props3.events,
  2806. getNow = _this$props3.getNow,
  2807. accessors = _this$props3.accessors,
  2808. selectable = _this$props3.selectable,
  2809. components = _this$props3.components,
  2810. getters = _this$props3.getters,
  2811. scrollRef = _this$props3.scrollRef,
  2812. localizer = _this$props3.localizer,
  2813. isOverflowing = _this$props3.isOverflowing,
  2814. _this$props3$componen = _this$props3.components,
  2815. TimeGutterHeader = _this$props3$componen.timeGutterHeader,
  2816. _this$props3$componen2 = _this$props3$componen.resourceHeader,
  2817. ResourceHeaderComponent = _this$props3$componen2 === void 0 ? ResourceHeader : _this$props3$componen2;
  2818. var style = {};
  2819. if (isOverflowing) {
  2820. style[rtl ? 'marginLeft' : 'marginRight'] = scrollbarSize() + "px";
  2821. }
  2822. var groupedEvents = resources.groupEvents(events);
  2823. return React.createElement("div", {
  2824. style: style,
  2825. ref: scrollRef,
  2826. className: clsx('rbc-time-header', isOverflowing && 'rbc-overflowing')
  2827. }, React.createElement("div", {
  2828. className: "rbc-label rbc-time-header-gutter",
  2829. style: {
  2830. width: width,
  2831. minWidth: width,
  2832. maxWidth: width
  2833. }
  2834. }, TimeGutterHeader && React.createElement(TimeGutterHeader, null)), resources.map(function (_ref, idx) {
  2835. var id = _ref[0],
  2836. resource = _ref[1];
  2837. return React.createElement("div", {
  2838. className: "rbc-time-header-content",
  2839. key: id || idx
  2840. }, resource && React.createElement("div", {
  2841. className: "rbc-row rbc-row-resource",
  2842. key: "resource_" + idx
  2843. }, React.createElement("div", {
  2844. className: "rbc-header"
  2845. }, React.createElement(ResourceHeaderComponent, {
  2846. index: idx,
  2847. label: accessors.resourceTitle(resource),
  2848. resource: resource
  2849. }))), React.createElement("div", {
  2850. className: "rbc-row rbc-time-header-cell" + (range.length <= 1 ? ' rbc-time-header-cell-single-day' : '')
  2851. }, _this3.renderHeaderCells(range)), React.createElement(DateContentRow, {
  2852. isAllDay: true,
  2853. rtl: rtl,
  2854. getNow: getNow,
  2855. minRows: 2,
  2856. range: range,
  2857. events: groupedEvents.get(id) || [],
  2858. resourceId: resource && id,
  2859. className: "rbc-allday-cell",
  2860. selectable: selectable,
  2861. selected: _this3.props.selected,
  2862. components: components,
  2863. accessors: accessors,
  2864. getters: getters,
  2865. localizer: localizer,
  2866. onSelect: _this3.props.onSelectEvent,
  2867. onDoubleClick: _this3.props.onDoubleClickEvent,
  2868. onSelectSlot: _this3.props.onSelectSlot,
  2869. longPressThreshold: _this3.props.longPressThreshold
  2870. }));
  2871. }));
  2872. };
  2873. return TimeGridHeader;
  2874. }(React.Component);
  2875. TimeGridHeader.propTypes = process.env.NODE_ENV !== "production" ? {
  2876. range: PropTypes.array.isRequired,
  2877. events: PropTypes.array.isRequired,
  2878. resources: PropTypes.object,
  2879. getNow: PropTypes.func.isRequired,
  2880. isOverflowing: PropTypes.bool,
  2881. rtl: PropTypes.bool,
  2882. width: PropTypes.number,
  2883. localizer: PropTypes.object.isRequired,
  2884. accessors: PropTypes.object.isRequired,
  2885. components: PropTypes.object.isRequired,
  2886. getters: PropTypes.object.isRequired,
  2887. selected: PropTypes.object,
  2888. selectable: PropTypes.oneOf([true, false, 'ignoreEvents']),
  2889. longPressThreshold: PropTypes.number,
  2890. onSelectSlot: PropTypes.func,
  2891. onSelectEvent: PropTypes.func,
  2892. onDoubleClickEvent: PropTypes.func,
  2893. onDrillDown: PropTypes.func,
  2894. getDrilldownView: PropTypes.func.isRequired,
  2895. scrollRef: PropTypes.any
  2896. } : {};
  2897. var NONE = {};
  2898. function Resources(resources, accessors) {
  2899. return {
  2900. map: function map(fn) {
  2901. if (!resources) return [fn([NONE, null], 0)];
  2902. return resources.map(function (resource, idx) {
  2903. return fn([accessors.resourceId(resource), resource], idx);
  2904. });
  2905. },
  2906. groupEvents: function groupEvents(events) {
  2907. var eventsByResource = new Map();
  2908. if (!resources) {
  2909. // Return all events if resources are not provided
  2910. eventsByResource.set(NONE, events);
  2911. return eventsByResource;
  2912. }
  2913. events.forEach(function (event) {
  2914. var id = accessors.resource(event) || NONE;
  2915. var resourceEvents = eventsByResource.get(id) || [];
  2916. resourceEvents.push(event);
  2917. eventsByResource.set(id, resourceEvents);
  2918. });
  2919. return eventsByResource;
  2920. }
  2921. };
  2922. }
  2923. var TimeGrid =
  2924. /*#__PURE__*/
  2925. function (_Component) {
  2926. _inheritsLoose(TimeGrid, _Component);
  2927. function TimeGrid(props) {
  2928. var _this;
  2929. _this = _Component.call(this, props) || this;
  2930. _this.handleScroll = function (e) {
  2931. if (_this.scrollRef.current) {
  2932. _this.scrollRef.current.scrollLeft = e.target.scrollLeft;
  2933. }
  2934. };
  2935. _this.handleResize = function () {
  2936. cancel(_this.rafHandle);
  2937. _this.rafHandle = request(_this.checkOverflow);
  2938. };
  2939. _this.gutterRef = function (ref) {
  2940. _this.gutter = ref && findDOMNode(ref);
  2941. };
  2942. _this.handleSelectAlldayEvent = function () {
  2943. //cancel any pending selections so only the event click goes through.
  2944. _this.clearSelection();
  2945. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  2946. args[_key] = arguments[_key];
  2947. }
  2948. notify(_this.props.onSelectEvent, args);
  2949. };
  2950. _this.handleSelectAllDaySlot = function (slots, slotInfo) {
  2951. var onSelectSlot = _this.props.onSelectSlot;
  2952. notify(onSelectSlot, {
  2953. slots: slots,
  2954. start: slots[0],
  2955. end: slots[slots.length - 1],
  2956. action: slotInfo.action
  2957. });
  2958. };
  2959. _this.checkOverflow = function () {
  2960. if (_this._updatingOverflow) return;
  2961. var content = _this.contentRef.current;
  2962. var isOverflowing = content.scrollHeight > content.clientHeight;
  2963. if (_this.state.isOverflowing !== isOverflowing) {
  2964. _this._updatingOverflow = true;
  2965. _this.setState({
  2966. isOverflowing: isOverflowing
  2967. }, function () {
  2968. _this._updatingOverflow = false;
  2969. });
  2970. }
  2971. };
  2972. _this.memoizedResources = memoize(function (resources, accessors) {
  2973. return Resources(resources, accessors);
  2974. });
  2975. _this.state = {
  2976. gutterWidth: undefined,
  2977. isOverflowing: null
  2978. };
  2979. _this.scrollRef = React.createRef();
  2980. _this.contentRef = React.createRef();
  2981. return _this;
  2982. }
  2983. var _proto = TimeGrid.prototype;
  2984. _proto.componentWillMount = function componentWillMount() {
  2985. this.calculateScroll();
  2986. };
  2987. _proto.componentDidMount = function componentDidMount() {
  2988. this.checkOverflow();
  2989. if (this.props.width == null) {
  2990. this.measureGutter();
  2991. }
  2992. this.applyScroll();
  2993. window.addEventListener('resize', this.handleResize);
  2994. };
  2995. _proto.componentWillUnmount = function componentWillUnmount() {
  2996. window.removeEventListener('resize', this.handleResize);
  2997. cancel(this.rafHandle);
  2998. if (this.measureGutterAnimationFrameRequest) {
  2999. window.cancelAnimationFrame(this.measureGutterAnimationFrameRequest);
  3000. }
  3001. };
  3002. _proto.componentDidUpdate = function componentDidUpdate() {
  3003. if (this.props.width == null) {
  3004. this.measureGutter();
  3005. }
  3006. this.applyScroll(); //this.checkOverflow()
  3007. };
  3008. _proto.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
  3009. var _this$props = this.props,
  3010. range = _this$props.range,
  3011. scrollToTime = _this$props.scrollToTime; // When paginating, reset scroll
  3012. if (!eq(nextProps.range[0], range[0], 'minute') || !eq(nextProps.scrollToTime, scrollToTime, 'minute')) {
  3013. this.calculateScroll(nextProps);
  3014. }
  3015. };
  3016. _proto.renderEvents = function renderEvents(range, events, now) {
  3017. var _this2 = this;
  3018. var _this$props2 = this.props,
  3019. min = _this$props2.min,
  3020. max = _this$props2.max,
  3021. components = _this$props2.components,
  3022. accessors = _this$props2.accessors,
  3023. localizer = _this$props2.localizer;
  3024. var resources = this.memoizedResources(this.props.resources, accessors);
  3025. var groupedEvents = resources.groupEvents(events);
  3026. return resources.map(function (_ref, i) {
  3027. var id = _ref[0],
  3028. resource = _ref[1];
  3029. return range.map(function (date, jj) {
  3030. var daysEvents = (groupedEvents.get(id) || []).filter(function (event) {
  3031. return inRange$1(date, accessors.start(event), accessors.end(event), 'day');
  3032. });
  3033. return React.createElement(DayColumn, _extends({}, _this2.props, {
  3034. localizer: localizer,
  3035. min: merge(date, min),
  3036. max: merge(date, max),
  3037. resource: resource && id,
  3038. components: components,
  3039. isNow: eq(date, now, 'day'),
  3040. key: i + '-' + jj,
  3041. date: date,
  3042. events: daysEvents
  3043. }));
  3044. });
  3045. });
  3046. };
  3047. _proto.render = function render() {
  3048. var _this$props3 = this.props,
  3049. events = _this$props3.events,
  3050. range = _this$props3.range,
  3051. width = _this$props3.width,
  3052. rtl = _this$props3.rtl,
  3053. selected = _this$props3.selected,
  3054. getNow = _this$props3.getNow,
  3055. resources = _this$props3.resources,
  3056. components = _this$props3.components,
  3057. accessors = _this$props3.accessors,
  3058. getters = _this$props3.getters,
  3059. localizer = _this$props3.localizer,
  3060. min = _this$props3.min,
  3061. max = _this$props3.max,
  3062. showMultiDayTimes = _this$props3.showMultiDayTimes,
  3063. longPressThreshold = _this$props3.longPressThreshold;
  3064. width = width || this.state.gutterWidth;
  3065. var start = range[0],
  3066. end = range[range.length - 1];
  3067. this.slots = range.length;
  3068. var allDayEvents = [],
  3069. rangeEvents = [];
  3070. events.forEach(function (event) {
  3071. if (inRange(event, start, end, accessors)) {
  3072. var eStart = accessors.start(event),
  3073. eEnd = accessors.end(event);
  3074. if (accessors.allDay(event) || isJustDate(eStart) && isJustDate(eEnd) || !showMultiDayTimes && !eq(eStart, eEnd, 'day')) {
  3075. allDayEvents.push(event);
  3076. } else {
  3077. rangeEvents.push(event);
  3078. }
  3079. }
  3080. });
  3081. allDayEvents.sort(function (a, b) {
  3082. return sortEvents(a, b, accessors);
  3083. });
  3084. return React.createElement("div", {
  3085. className: clsx('rbc-time-view', resources && 'rbc-time-view-resources')
  3086. }, React.createElement(TimeGridHeader, {
  3087. range: range,
  3088. events: allDayEvents,
  3089. width: width,
  3090. rtl: rtl,
  3091. getNow: getNow,
  3092. localizer: localizer,
  3093. selected: selected,
  3094. resources: this.memoizedResources(resources, accessors),
  3095. selectable: this.props.selectable,
  3096. accessors: accessors,
  3097. getters: getters,
  3098. components: components,
  3099. scrollRef: this.scrollRef,
  3100. isOverflowing: this.state.isOverflowing,
  3101. longPressThreshold: longPressThreshold,
  3102. onSelectSlot: this.handleSelectAllDaySlot,
  3103. onSelectEvent: this.handleSelectAlldayEvent,
  3104. onDoubleClickEvent: this.props.onDoubleClickEvent,
  3105. onDrillDown: this.props.onDrillDown,
  3106. getDrilldownView: this.props.getDrilldownView
  3107. }), React.createElement("div", {
  3108. ref: this.contentRef,
  3109. className: "rbc-time-content",
  3110. onScroll: this.handleScroll
  3111. }, React.createElement(TimeGutter, {
  3112. date: start,
  3113. ref: this.gutterRef,
  3114. localizer: localizer,
  3115. min: merge(start, min),
  3116. max: merge(start, max),
  3117. step: this.props.step,
  3118. getNow: this.props.getNow,
  3119. timeslots: this.props.timeslots,
  3120. components: components,
  3121. className: "rbc-time-gutter"
  3122. }), this.renderEvents(range, rangeEvents, getNow())));
  3123. };
  3124. _proto.clearSelection = function clearSelection() {
  3125. clearTimeout(this._selectTimer);
  3126. this._pendingSelection = [];
  3127. };
  3128. _proto.measureGutter = function measureGutter() {
  3129. var _this3 = this;
  3130. if (this.measureGutterAnimationFrameRequest) {
  3131. window.cancelAnimationFrame(this.measureGutterAnimationFrameRequest);
  3132. }
  3133. this.measureGutterAnimationFrameRequest = window.requestAnimationFrame(function () {
  3134. var width = getWidth(_this3.gutter);
  3135. if (width && _this3.state.gutterWidth !== width) {
  3136. _this3.setState({
  3137. gutterWidth: width
  3138. });
  3139. }
  3140. });
  3141. };
  3142. _proto.applyScroll = function applyScroll() {
  3143. if (this._scrollRatio) {
  3144. var content = this.contentRef.current;
  3145. content.scrollTop = content.scrollHeight * this._scrollRatio; // Only do this once
  3146. this._scrollRatio = null;
  3147. }
  3148. };
  3149. _proto.calculateScroll = function calculateScroll(props) {
  3150. if (props === void 0) {
  3151. props = this.props;
  3152. }
  3153. var _props = props,
  3154. min = _props.min,
  3155. max = _props.max,
  3156. scrollToTime = _props.scrollToTime;
  3157. var diffMillis = scrollToTime - startOf(scrollToTime, 'day');
  3158. var totalMillis = diff(max, min);
  3159. this._scrollRatio = diffMillis / totalMillis;
  3160. };
  3161. return TimeGrid;
  3162. }(Component);
  3163. TimeGrid.propTypes = process.env.NODE_ENV !== "production" ? {
  3164. events: PropTypes.array.isRequired,
  3165. resources: PropTypes.array,
  3166. step: PropTypes.number,
  3167. timeslots: PropTypes.number,
  3168. range: PropTypes.arrayOf(PropTypes.instanceOf(Date)),
  3169. min: PropTypes.instanceOf(Date),
  3170. max: PropTypes.instanceOf(Date),
  3171. getNow: PropTypes.func.isRequired,
  3172. scrollToTime: PropTypes.instanceOf(Date),
  3173. showMultiDayTimes: PropTypes.bool,
  3174. rtl: PropTypes.bool,
  3175. width: PropTypes.number,
  3176. accessors: PropTypes.object.isRequired,
  3177. components: PropTypes.object.isRequired,
  3178. getters: PropTypes.object.isRequired,
  3179. localizer: PropTypes.object.isRequired,
  3180. selected: PropTypes.object,
  3181. selectable: PropTypes.oneOf([true, false, 'ignoreEvents']),
  3182. longPressThreshold: PropTypes.number,
  3183. onNavigate: PropTypes.func,
  3184. onSelectSlot: PropTypes.func,
  3185. onSelectEnd: PropTypes.func,
  3186. onSelectStart: PropTypes.func,
  3187. onSelectEvent: PropTypes.func,
  3188. onDoubleClickEvent: PropTypes.func,
  3189. onDrillDown: PropTypes.func,
  3190. getDrilldownView: PropTypes.func.isRequired
  3191. } : {};
  3192. TimeGrid.defaultProps = {
  3193. step: 30,
  3194. timeslots: 2,
  3195. min: startOf(new Date(), 'day'),
  3196. max: endOf(new Date(), 'day'),
  3197. scrollToTime: startOf(new Date(), 'day')
  3198. };
  3199. var Day =
  3200. /*#__PURE__*/
  3201. function (_React$Component) {
  3202. _inheritsLoose(Day, _React$Component);
  3203. function Day() {
  3204. return _React$Component.apply(this, arguments) || this;
  3205. }
  3206. var _proto = Day.prototype;
  3207. _proto.render = function render() {
  3208. var _this$props = this.props,
  3209. date = _this$props.date,
  3210. props = _objectWithoutPropertiesLoose(_this$props, ["date"]);
  3211. var range = Day.range(date);
  3212. return React.createElement(TimeGrid, _extends({}, props, {
  3213. range: range,
  3214. eventOffset: 10
  3215. }));
  3216. };
  3217. return Day;
  3218. }(React.Component);
  3219. Day.propTypes = process.env.NODE_ENV !== "production" ? {
  3220. date: PropTypes.instanceOf(Date).isRequired
  3221. } : {};
  3222. Day.range = function (date) {
  3223. return [startOf(date, 'day')];
  3224. };
  3225. Day.navigate = function (date, action) {
  3226. switch (action) {
  3227. case navigate.PREVIOUS:
  3228. return add(date, -1, 'day');
  3229. case navigate.NEXT:
  3230. return add(date, 1, 'day');
  3231. default:
  3232. return date;
  3233. }
  3234. };
  3235. Day.title = function (date, _ref) {
  3236. var localizer = _ref.localizer;
  3237. return localizer.format(date, 'dayHeaderFormat');
  3238. };
  3239. var Week =
  3240. /*#__PURE__*/
  3241. function (_React$Component) {
  3242. _inheritsLoose(Week, _React$Component);
  3243. function Week() {
  3244. return _React$Component.apply(this, arguments) || this;
  3245. }
  3246. var _proto = Week.prototype;
  3247. _proto.render = function render() {
  3248. var _this$props = this.props,
  3249. date = _this$props.date,
  3250. props = _objectWithoutPropertiesLoose(_this$props, ["date"]);
  3251. var range = Week.range(date, this.props);
  3252. return React.createElement(TimeGrid, _extends({}, props, {
  3253. range: range,
  3254. eventOffset: 15
  3255. }));
  3256. };
  3257. return Week;
  3258. }(React.Component);
  3259. Week.propTypes = process.env.NODE_ENV !== "production" ? {
  3260. date: PropTypes.instanceOf(Date).isRequired
  3261. } : {};
  3262. Week.defaultProps = TimeGrid.defaultProps;
  3263. Week.navigate = function (date, action) {
  3264. switch (action) {
  3265. case navigate.PREVIOUS:
  3266. return add(date, -1, 'week');
  3267. case navigate.NEXT:
  3268. return add(date, 1, 'week');
  3269. default:
  3270. return date;
  3271. }
  3272. };
  3273. Week.range = function (date, _ref) {
  3274. var localizer = _ref.localizer;
  3275. var firstOfWeek = localizer.startOfWeek();
  3276. var start = startOf(date, 'week', firstOfWeek);
  3277. var end = endOf(date, 'week', firstOfWeek);
  3278. return range(start, end);
  3279. };
  3280. Week.title = function (date, _ref2) {
  3281. var localizer = _ref2.localizer;
  3282. var _Week$range = Week.range(date, {
  3283. localizer: localizer
  3284. }),
  3285. start = _Week$range[0],
  3286. rest = _Week$range.slice(1);
  3287. return localizer.format({
  3288. start: start,
  3289. end: rest.pop()
  3290. }, 'dayRangeHeaderFormat');
  3291. };
  3292. function workWeekRange(date, options) {
  3293. return Week.range(date, options).filter(function (d) {
  3294. return [6, 0].indexOf(d.getDay()) === -1;
  3295. });
  3296. }
  3297. var WorkWeek =
  3298. /*#__PURE__*/
  3299. function (_React$Component) {
  3300. _inheritsLoose(WorkWeek, _React$Component);
  3301. function WorkWeek() {
  3302. return _React$Component.apply(this, arguments) || this;
  3303. }
  3304. var _proto = WorkWeek.prototype;
  3305. _proto.render = function render() {
  3306. var _this$props = this.props,
  3307. date = _this$props.date,
  3308. props = _objectWithoutPropertiesLoose(_this$props, ["date"]);
  3309. var range = workWeekRange(date, this.props);
  3310. return React.createElement(TimeGrid, _extends({}, props, {
  3311. range: range,
  3312. eventOffset: 15
  3313. }));
  3314. };
  3315. return WorkWeek;
  3316. }(React.Component);
  3317. WorkWeek.propTypes = process.env.NODE_ENV !== "production" ? {
  3318. date: PropTypes.instanceOf(Date).isRequired
  3319. } : {};
  3320. WorkWeek.defaultProps = TimeGrid.defaultProps;
  3321. WorkWeek.range = workWeekRange;
  3322. WorkWeek.navigate = Week.navigate;
  3323. WorkWeek.title = function (date, _ref) {
  3324. var localizer = _ref.localizer;
  3325. var _workWeekRange = workWeekRange(date, {
  3326. localizer: localizer
  3327. }),
  3328. start = _workWeekRange[0],
  3329. rest = _workWeekRange.slice(1);
  3330. return localizer.format({
  3331. start: start,
  3332. end: rest.pop()
  3333. }, 'dayRangeHeaderFormat');
  3334. };
  3335. var Agenda =
  3336. /*#__PURE__*/
  3337. function (_React$Component) {
  3338. _inheritsLoose(Agenda, _React$Component);
  3339. function Agenda(props) {
  3340. var _this;
  3341. _this = _React$Component.call(this, props) || this;
  3342. _this.renderDay = function (day, events, dayKey) {
  3343. var _this$props = _this.props,
  3344. selected = _this$props.selected,
  3345. getters = _this$props.getters,
  3346. accessors = _this$props.accessors,
  3347. localizer = _this$props.localizer,
  3348. _this$props$component = _this$props.components,
  3349. Event = _this$props$component.event,
  3350. AgendaDate = _this$props$component.date;
  3351. events = events.filter(function (e) {
  3352. return inRange(e, startOf(day, 'day'), endOf(day, 'day'), accessors);
  3353. });
  3354. return events.map(function (event, idx) {
  3355. var title = accessors.title(event);
  3356. var end = accessors.end(event);
  3357. var start = accessors.start(event);
  3358. var userProps = getters.eventProp(event, start, end, isSelected(event, selected));
  3359. var dateLabel = idx === 0 && localizer.format(day, 'agendaDateFormat');
  3360. var first = idx === 0 ? React.createElement("td", {
  3361. rowSpan: events.length,
  3362. className: "rbc-agenda-date-cell"
  3363. }, AgendaDate ? React.createElement(AgendaDate, {
  3364. day: day,
  3365. label: dateLabel
  3366. }) : dateLabel) : false;
  3367. return React.createElement("tr", {
  3368. key: dayKey + '_' + idx,
  3369. className: userProps.className,
  3370. style: userProps.style
  3371. }, first, React.createElement("td", {
  3372. className: "rbc-agenda-time-cell"
  3373. }, _this.timeRangeLabel(day, event)), React.createElement("td", {
  3374. className: "rbc-agenda-event-cell"
  3375. }, Event ? React.createElement(Event, {
  3376. event: event,
  3377. title: title
  3378. }) : title));
  3379. }, []);
  3380. };
  3381. _this.timeRangeLabel = function (day, event) {
  3382. var _this$props2 = _this.props,
  3383. accessors = _this$props2.accessors,
  3384. localizer = _this$props2.localizer,
  3385. components = _this$props2.components;
  3386. var labelClass = '',
  3387. TimeComponent = components.time,
  3388. label = localizer.messages.allDay;
  3389. var end = accessors.end(event);
  3390. var start = accessors.start(event);
  3391. if (!accessors.allDay(event)) {
  3392. if (eq(start, end)) {
  3393. label = localizer.format(start, 'agendaTimeFormat');
  3394. } else if (eq(start, end, 'day')) {
  3395. label = localizer.format({
  3396. start: start,
  3397. end: end
  3398. }, 'agendaTimeRangeFormat');
  3399. } else if (eq(day, start, 'day')) {
  3400. label = localizer.format(start, 'agendaTimeFormat');
  3401. } else if (eq(day, end, 'day')) {
  3402. label = localizer.format(end, 'agendaTimeFormat');
  3403. }
  3404. }
  3405. if (gt(day, start, 'day')) labelClass = 'rbc-continues-prior';
  3406. if (lt(day, end, 'day')) labelClass += ' rbc-continues-after';
  3407. return React.createElement("span", {
  3408. className: labelClass.trim()
  3409. }, TimeComponent ? React.createElement(TimeComponent, {
  3410. event: event,
  3411. day: day,
  3412. label: label
  3413. }) : label);
  3414. };
  3415. _this._adjustHeader = function () {
  3416. if (!_this.tbodyRef.current) return;
  3417. var header = _this.headerRef.current;
  3418. var firstRow = _this.tbodyRef.current.firstChild;
  3419. if (!firstRow) return;
  3420. var isOverflowing = _this.contentRef.current.scrollHeight > _this.contentRef.current.clientHeight;
  3421. var widths = _this._widths || [];
  3422. _this._widths = [getWidth(firstRow.children[0]), getWidth(firstRow.children[1])];
  3423. if (widths[0] !== _this._widths[0] || widths[1] !== _this._widths[1]) {
  3424. _this.dateColRef.current.style.width = _this._widths[0] + 'px';
  3425. _this.timeColRef.current.style.width = _this._widths[1] + 'px';
  3426. }
  3427. if (isOverflowing) {
  3428. addClass(header, 'rbc-header-overflowing');
  3429. header.style.marginRight = scrollbarSize() + 'px';
  3430. } else {
  3431. removeClass(header, 'rbc-header-overflowing');
  3432. }
  3433. };
  3434. _this.headerRef = React.createRef();
  3435. _this.dateColRef = React.createRef();
  3436. _this.timeColRef = React.createRef();
  3437. _this.contentRef = React.createRef();
  3438. _this.tbodyRef = React.createRef();
  3439. return _this;
  3440. }
  3441. var _proto = Agenda.prototype;
  3442. _proto.componentDidMount = function componentDidMount() {
  3443. this._adjustHeader();
  3444. };
  3445. _proto.componentDidUpdate = function componentDidUpdate() {
  3446. this._adjustHeader();
  3447. };
  3448. _proto.render = function render() {
  3449. var _this2 = this;
  3450. var _this$props3 = this.props,
  3451. length = _this$props3.length,
  3452. date = _this$props3.date,
  3453. events = _this$props3.events,
  3454. accessors = _this$props3.accessors,
  3455. localizer = _this$props3.localizer;
  3456. var messages = localizer.messages;
  3457. var end = add(date, length, 'day');
  3458. var range$1 = range(date, end, 'day');
  3459. events = events.filter(function (event) {
  3460. return inRange(event, date, end, accessors);
  3461. });
  3462. events.sort(function (a, b) {
  3463. return +accessors.start(a) - +accessors.start(b);
  3464. });
  3465. return React.createElement("div", {
  3466. className: "rbc-agenda-view"
  3467. }, events.length !== 0 ? React.createElement(React.Fragment, null, React.createElement("table", {
  3468. ref: this.headerRef,
  3469. className: "rbc-agenda-table"
  3470. }, React.createElement("thead", null, React.createElement("tr", null, React.createElement("th", {
  3471. className: "rbc-header",
  3472. ref: this.dateColRef
  3473. }, messages.date), React.createElement("th", {
  3474. className: "rbc-header",
  3475. ref: this.timeColRef
  3476. }, messages.time), React.createElement("th", {
  3477. className: "rbc-header"
  3478. }, messages.event)))), React.createElement("div", {
  3479. className: "rbc-agenda-content",
  3480. ref: this.contentRef
  3481. }, React.createElement("table", {
  3482. className: "rbc-agenda-table"
  3483. }, React.createElement("tbody", {
  3484. ref: this.tbodyRef
  3485. }, range$1.map(function (day, idx) {
  3486. return _this2.renderDay(day, events, idx);
  3487. }))))) : React.createElement("span", {
  3488. className: "rbc-agenda-empty"
  3489. }, messages.noEventsInRange));
  3490. };
  3491. return Agenda;
  3492. }(React.Component);
  3493. Agenda.propTypes = process.env.NODE_ENV !== "production" ? {
  3494. events: PropTypes.array,
  3495. date: PropTypes.instanceOf(Date),
  3496. length: PropTypes.number.isRequired,
  3497. selected: PropTypes.object,
  3498. accessors: PropTypes.object.isRequired,
  3499. components: PropTypes.object.isRequired,
  3500. getters: PropTypes.object.isRequired,
  3501. localizer: PropTypes.object.isRequired
  3502. } : {};
  3503. Agenda.defaultProps = {
  3504. length: 30
  3505. };
  3506. Agenda.range = function (start, _ref) {
  3507. var _ref$length = _ref.length,
  3508. length = _ref$length === void 0 ? Agenda.defaultProps.length : _ref$length;
  3509. var end = add(start, length, 'day');
  3510. return {
  3511. start: start,
  3512. end: end
  3513. };
  3514. };
  3515. Agenda.navigate = function (date, action, _ref2) {
  3516. var _ref2$length = _ref2.length,
  3517. length = _ref2$length === void 0 ? Agenda.defaultProps.length : _ref2$length;
  3518. switch (action) {
  3519. case navigate.PREVIOUS:
  3520. return add(date, -length, 'day');
  3521. case navigate.NEXT:
  3522. return add(date, length, 'day');
  3523. default:
  3524. return date;
  3525. }
  3526. };
  3527. Agenda.title = function (start, _ref3) {
  3528. var _ref3$length = _ref3.length,
  3529. length = _ref3$length === void 0 ? Agenda.defaultProps.length : _ref3$length,
  3530. localizer = _ref3.localizer;
  3531. var end = add(start, length, 'day');
  3532. return localizer.format({
  3533. start: start,
  3534. end: end
  3535. }, 'agendaHeaderFormat');
  3536. };
  3537. var _VIEWS;
  3538. var VIEWS = (_VIEWS = {}, _VIEWS[views.MONTH] = MonthView, _VIEWS[views.WEEK] = Week, _VIEWS[views.WORK_WEEK] = WorkWeek, _VIEWS[views.DAY] = Day, _VIEWS[views.AGENDA] = Agenda, _VIEWS);
  3539. function moveDate(View, _ref) {
  3540. var action = _ref.action,
  3541. date = _ref.date,
  3542. today = _ref.today,
  3543. props = _objectWithoutPropertiesLoose(_ref, ["action", "date", "today"]);
  3544. View = typeof View === 'string' ? VIEWS[View] : View;
  3545. switch (action) {
  3546. case navigate.TODAY:
  3547. date = today || new Date();
  3548. break;
  3549. case navigate.DATE:
  3550. break;
  3551. default:
  3552. !(View && typeof View.navigate === 'function') ? process.env.NODE_ENV !== "production" ? invariant(false, 'Calendar View components must implement a static `.navigate(date, action)` method.s') : invariant(false) : void 0;
  3553. date = View.navigate(date, action, props);
  3554. }
  3555. return date;
  3556. }
  3557. var Toolbar =
  3558. /*#__PURE__*/
  3559. function (_React$Component) {
  3560. _inheritsLoose(Toolbar, _React$Component);
  3561. function Toolbar() {
  3562. var _this;
  3563. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  3564. args[_key] = arguments[_key];
  3565. }
  3566. _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
  3567. _this.navigate = function (action) {
  3568. _this.props.onNavigate(action);
  3569. };
  3570. _this.view = function (view) {
  3571. _this.props.onView(view);
  3572. };
  3573. return _this;
  3574. }
  3575. var _proto = Toolbar.prototype;
  3576. _proto.render = function render() {
  3577. var _this$props = this.props,
  3578. messages = _this$props.localizer.messages,
  3579. label = _this$props.label;
  3580. return React.createElement("div", {
  3581. className: "rbc-toolbar"
  3582. }, React.createElement("span", {
  3583. className: "rbc-btn-group"
  3584. }, React.createElement("button", {
  3585. type: "button",
  3586. onClick: this.navigate.bind(null, navigate.TODAY)
  3587. }, messages.today), React.createElement("button", {
  3588. type: "button",
  3589. onClick: this.navigate.bind(null, navigate.PREVIOUS)
  3590. }, messages.previous), React.createElement("button", {
  3591. type: "button",
  3592. onClick: this.navigate.bind(null, navigate.NEXT)
  3593. }, messages.next)), React.createElement("span", {
  3594. className: "rbc-toolbar-label"
  3595. }, label), React.createElement("span", {
  3596. className: "rbc-btn-group"
  3597. }, this.viewNamesGroup(messages)));
  3598. };
  3599. _proto.viewNamesGroup = function viewNamesGroup(messages) {
  3600. var _this2 = this;
  3601. var viewNames = this.props.views;
  3602. var view = this.props.view;
  3603. if (viewNames.length > 1) {
  3604. return viewNames.map(function (name) {
  3605. return React.createElement("button", {
  3606. type: "button",
  3607. key: name,
  3608. className: clsx({
  3609. 'rbc-active': view === name
  3610. }),
  3611. onClick: _this2.view.bind(null, name)
  3612. }, messages[name]);
  3613. });
  3614. }
  3615. };
  3616. return Toolbar;
  3617. }(React.Component);
  3618. Toolbar.propTypes = process.env.NODE_ENV !== "production" ? {
  3619. view: PropTypes.string.isRequired,
  3620. views: PropTypes.arrayOf(PropTypes.string).isRequired,
  3621. label: PropTypes.node.isRequired,
  3622. localizer: PropTypes.object,
  3623. onNavigate: PropTypes.func.isRequired,
  3624. onView: PropTypes.func.isRequired
  3625. } : {};
  3626. /**
  3627. * Retrieve via an accessor-like property
  3628. *
  3629. * accessor(obj, 'name') // => retrieves obj['name']
  3630. * accessor(data, func) // => retrieves func(data)
  3631. * ... otherwise null
  3632. */
  3633. function accessor$1(data, field) {
  3634. var value = null;
  3635. if (typeof field === 'function') value = field(data);else if (typeof field === 'string' && typeof data === 'object' && data != null && field in data) value = data[field];
  3636. return value;
  3637. }
  3638. var wrapAccessor = function wrapAccessor(acc) {
  3639. return function (data) {
  3640. return accessor$1(data, acc);
  3641. };
  3642. };
  3643. function viewNames$1(_views) {
  3644. return !Array.isArray(_views) ? Object.keys(_views) : _views;
  3645. }
  3646. function isValidView(view, _ref) {
  3647. var _views = _ref.views;
  3648. var names = viewNames$1(_views);
  3649. return names.indexOf(view) !== -1;
  3650. }
  3651. /**
  3652. * react-big-calendar is a full featured Calendar component for managing events and dates. It uses
  3653. * modern `flexbox` for layout, making it super responsive and performant. Leaving most of the layout heavy lifting
  3654. * to the browser. __note:__ The default styles use `height: 100%` which means your container must set an explicit
  3655. * height (feel free to adjust the styles to suit your specific needs).
  3656. *
  3657. * Big Calendar is unopiniated about editing and moving events, preferring to let you implement it in a way that makes
  3658. * the most sense to your app. It also tries not to be prescriptive about your event data structures, just tell it
  3659. * how to find the start and end datetimes and you can pass it whatever you want.
  3660. *
  3661. * One thing to note is that, `react-big-calendar` treats event start/end dates as an _exclusive_ range.
  3662. * which means that the event spans up to, but not including, the end date. In the case
  3663. * of displaying events on whole days, end dates are rounded _up_ to the next day. So an
  3664. * event ending on `Apr 8th 12:00:00 am` will not appear on the 8th, whereas one ending
  3665. * on `Apr 8th 12:01:00 am` will. If you want _inclusive_ ranges consider providing a
  3666. * function `endAccessor` that returns the end date + 1 day for those events that end at midnight.
  3667. */
  3668. var Calendar =
  3669. /*#__PURE__*/
  3670. function (_React$Component) {
  3671. _inheritsLoose(Calendar, _React$Component);
  3672. function Calendar() {
  3673. var _this;
  3674. for (var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++) {
  3675. _args[_key] = arguments[_key];
  3676. }
  3677. _this = _React$Component.call.apply(_React$Component, [this].concat(_args)) || this;
  3678. _this.getViews = function () {
  3679. var views = _this.props.views;
  3680. if (Array.isArray(views)) {
  3681. return transform(views, function (obj, name) {
  3682. return obj[name] = VIEWS[name];
  3683. }, {});
  3684. }
  3685. if (typeof views === 'object') {
  3686. return mapValues(views, function (value, key) {
  3687. if (value === true) {
  3688. return VIEWS[key];
  3689. }
  3690. return value;
  3691. });
  3692. }
  3693. return VIEWS;
  3694. };
  3695. _this.getView = function () {
  3696. var views = _this.getViews();
  3697. return views[_this.props.view];
  3698. };
  3699. _this.getDrilldownView = function (date) {
  3700. var _this$props = _this.props,
  3701. view = _this$props.view,
  3702. drilldownView = _this$props.drilldownView,
  3703. getDrilldownView = _this$props.getDrilldownView;
  3704. if (!getDrilldownView) return drilldownView;
  3705. return getDrilldownView(date, view, Object.keys(_this.getViews()));
  3706. };
  3707. _this.handleRangeChange = function (date, viewComponent, view) {
  3708. var _this$props2 = _this.props,
  3709. onRangeChange = _this$props2.onRangeChange,
  3710. localizer = _this$props2.localizer;
  3711. if (onRangeChange) {
  3712. if (viewComponent.range) {
  3713. onRangeChange(viewComponent.range(date, {
  3714. localizer: localizer
  3715. }), view);
  3716. } else {
  3717. process.env.NODE_ENV !== "production" ? warning(true, 'onRangeChange prop not supported for this view') : void 0;
  3718. }
  3719. }
  3720. };
  3721. _this.handleNavigate = function (action, newDate) {
  3722. var _this$props3 = _this.props,
  3723. view = _this$props3.view,
  3724. date = _this$props3.date,
  3725. getNow = _this$props3.getNow,
  3726. onNavigate = _this$props3.onNavigate,
  3727. props = _objectWithoutPropertiesLoose(_this$props3, ["view", "date", "getNow", "onNavigate"]);
  3728. var ViewComponent = _this.getView();
  3729. var today = getNow();
  3730. date = moveDate(ViewComponent, _extends({}, props, {
  3731. action: action,
  3732. date: newDate || date || today,
  3733. today: today
  3734. }));
  3735. onNavigate(date, view, action);
  3736. _this.handleRangeChange(date, ViewComponent);
  3737. };
  3738. _this.handleViewChange = function (view) {
  3739. if (view !== _this.props.view && isValidView(view, _this.props)) {
  3740. _this.props.onView(view);
  3741. }
  3742. var views = _this.getViews();
  3743. _this.handleRangeChange(_this.props.date || _this.props.getNow(), views[view], view);
  3744. };
  3745. _this.handleSelectEvent = function () {
  3746. for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  3747. args[_key2] = arguments[_key2];
  3748. }
  3749. notify(_this.props.onSelectEvent, args);
  3750. };
  3751. _this.handleDoubleClickEvent = function () {
  3752. for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
  3753. args[_key3] = arguments[_key3];
  3754. }
  3755. notify(_this.props.onDoubleClickEvent, args);
  3756. };
  3757. _this.handleSelectSlot = function (slotInfo) {
  3758. notify(_this.props.onSelectSlot, slotInfo);
  3759. };
  3760. _this.handleDrillDown = function (date, view) {
  3761. var onDrillDown = _this.props.onDrillDown;
  3762. if (onDrillDown) {
  3763. onDrillDown(date, view, _this.drilldownView);
  3764. return;
  3765. }
  3766. if (view) _this.handleViewChange(view);
  3767. _this.handleNavigate(navigate.DATE, date);
  3768. };
  3769. _this.state = {
  3770. context: _this.getContext(_this.props)
  3771. };
  3772. return _this;
  3773. }
  3774. var _proto = Calendar.prototype;
  3775. _proto.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
  3776. this.setState({
  3777. context: this.getContext(nextProps)
  3778. });
  3779. };
  3780. _proto.getContext = function getContext(_ref2) {
  3781. var startAccessor = _ref2.startAccessor,
  3782. endAccessor = _ref2.endAccessor,
  3783. allDayAccessor = _ref2.allDayAccessor,
  3784. tooltipAccessor = _ref2.tooltipAccessor,
  3785. titleAccessor = _ref2.titleAccessor,
  3786. resourceAccessor = _ref2.resourceAccessor,
  3787. resourceIdAccessor = _ref2.resourceIdAccessor,
  3788. resourceTitleAccessor = _ref2.resourceTitleAccessor,
  3789. eventPropGetter = _ref2.eventPropGetter,
  3790. slotPropGetter = _ref2.slotPropGetter,
  3791. dayPropGetter = _ref2.dayPropGetter,
  3792. view = _ref2.view,
  3793. views = _ref2.views,
  3794. localizer = _ref2.localizer,
  3795. culture = _ref2.culture,
  3796. _ref2$messages = _ref2.messages,
  3797. messages$1 = _ref2$messages === void 0 ? {} : _ref2$messages,
  3798. _ref2$components = _ref2.components,
  3799. components = _ref2$components === void 0 ? {} : _ref2$components,
  3800. _ref2$formats = _ref2.formats,
  3801. formats = _ref2$formats === void 0 ? {} : _ref2$formats;
  3802. var names = viewNames$1(views);
  3803. var msgs = messages(messages$1);
  3804. return {
  3805. viewNames: names,
  3806. localizer: mergeWithDefaults(localizer, culture, formats, msgs),
  3807. getters: {
  3808. eventProp: function eventProp() {
  3809. return eventPropGetter && eventPropGetter.apply(void 0, arguments) || {};
  3810. },
  3811. slotProp: function slotProp() {
  3812. return slotPropGetter && slotPropGetter.apply(void 0, arguments) || {};
  3813. },
  3814. dayProp: function dayProp() {
  3815. return dayPropGetter && dayPropGetter.apply(void 0, arguments) || {};
  3816. }
  3817. },
  3818. components: defaults(components[view] || {}, omit(components, names), {
  3819. eventWrapper: NoopWrapper,
  3820. eventContainerWrapper: NoopWrapper,
  3821. dateCellWrapper: NoopWrapper,
  3822. weekWrapper: NoopWrapper,
  3823. timeSlotWrapper: NoopWrapper
  3824. }),
  3825. accessors: {
  3826. start: wrapAccessor(startAccessor),
  3827. end: wrapAccessor(endAccessor),
  3828. allDay: wrapAccessor(allDayAccessor),
  3829. tooltip: wrapAccessor(tooltipAccessor),
  3830. title: wrapAccessor(titleAccessor),
  3831. resource: wrapAccessor(resourceAccessor),
  3832. resourceId: wrapAccessor(resourceIdAccessor),
  3833. resourceTitle: wrapAccessor(resourceTitleAccessor)
  3834. }
  3835. };
  3836. };
  3837. _proto.render = function render() {
  3838. var _this$props4 = this.props,
  3839. view = _this$props4.view,
  3840. toolbar = _this$props4.toolbar,
  3841. events = _this$props4.events,
  3842. style = _this$props4.style,
  3843. className = _this$props4.className,
  3844. elementProps = _this$props4.elementProps,
  3845. current = _this$props4.date,
  3846. getNow = _this$props4.getNow,
  3847. length = _this$props4.length,
  3848. showMultiDayTimes = _this$props4.showMultiDayTimes,
  3849. onShowMore = _this$props4.onShowMore,
  3850. _0 = _this$props4.components,
  3851. _1 = _this$props4.formats,
  3852. _2 = _this$props4.messages,
  3853. _3 = _this$props4.culture,
  3854. props = _objectWithoutPropertiesLoose(_this$props4, ["view", "toolbar", "events", "style", "className", "elementProps", "date", "getNow", "length", "showMultiDayTimes", "onShowMore", "components", "formats", "messages", "culture"]);
  3855. current = current || getNow();
  3856. var View = this.getView();
  3857. var _this$state$context = this.state.context,
  3858. accessors = _this$state$context.accessors,
  3859. components = _this$state$context.components,
  3860. getters = _this$state$context.getters,
  3861. localizer = _this$state$context.localizer,
  3862. viewNames = _this$state$context.viewNames;
  3863. var CalToolbar = components.toolbar || Toolbar;
  3864. var label = View.title(current, {
  3865. localizer: localizer,
  3866. length: length
  3867. });
  3868. return React.createElement("div", _extends({}, elementProps, {
  3869. className: clsx(className, 'rbc-calendar', props.rtl && 'rbc-rtl'),
  3870. style: style
  3871. }), toolbar && React.createElement(CalToolbar, {
  3872. date: current,
  3873. view: view,
  3874. views: viewNames,
  3875. label: label,
  3876. onView: this.handleViewChange,
  3877. onNavigate: this.handleNavigate,
  3878. localizer: localizer
  3879. }), React.createElement(View, _extends({}, props, {
  3880. events: events,
  3881. date: current,
  3882. getNow: getNow,
  3883. length: length,
  3884. localizer: localizer,
  3885. getters: getters,
  3886. components: components,
  3887. accessors: accessors,
  3888. showMultiDayTimes: showMultiDayTimes,
  3889. getDrilldownView: this.getDrilldownView,
  3890. onNavigate: this.handleNavigate,
  3891. onDrillDown: this.handleDrillDown,
  3892. onSelectEvent: this.handleSelectEvent,
  3893. onDoubleClickEvent: this.handleDoubleClickEvent,
  3894. onSelectSlot: this.handleSelectSlot,
  3895. onShowMore: onShowMore
  3896. })));
  3897. }
  3898. /**
  3899. *
  3900. * @param date
  3901. * @param viewComponent
  3902. * @param {'month'|'week'|'work_week'|'day'|'agenda'} [view] - optional
  3903. * parameter. It appears when range change on view changing. It could be handy
  3904. * when you need to have both: range and view type at once, i.e. for manage rbc
  3905. * state via url
  3906. */
  3907. ;
  3908. return Calendar;
  3909. }(React.Component);
  3910. Calendar.defaultProps = {
  3911. elementProps: {},
  3912. popup: false,
  3913. toolbar: true,
  3914. view: views.MONTH,
  3915. views: [views.MONTH, views.WEEK, views.DAY, views.AGENDA],
  3916. step: 30,
  3917. length: 30,
  3918. drilldownView: views.DAY,
  3919. titleAccessor: 'title',
  3920. tooltipAccessor: 'title',
  3921. allDayAccessor: 'allDay',
  3922. startAccessor: 'start',
  3923. endAccessor: 'end',
  3924. resourceAccessor: 'resourceId',
  3925. resourceIdAccessor: 'id',
  3926. resourceTitleAccessor: 'title',
  3927. longPressThreshold: 250,
  3928. getNow: function getNow() {
  3929. return new Date();
  3930. }
  3931. };
  3932. Calendar.propTypes = process.env.NODE_ENV !== "production" ? {
  3933. localizer: PropTypes.object.isRequired,
  3934. /**
  3935. * Props passed to main calendar `<div>`.
  3936. *
  3937. */
  3938. elementProps: PropTypes.object,
  3939. /**
  3940. * The current date value of the calendar. Determines the visible view range.
  3941. * If `date` is omitted then the result of `getNow` is used; otherwise the
  3942. * current date is used.
  3943. *
  3944. * @controllable onNavigate
  3945. */
  3946. date: PropTypes.instanceOf(Date),
  3947. /**
  3948. * The current view of the calendar.
  3949. *
  3950. * @default 'month'
  3951. * @controllable onView
  3952. */
  3953. view: PropTypes.string,
  3954. /**
  3955. * The initial view set for the Calendar.
  3956. * @type Calendar.Views ('month'|'week'|'work_week'|'day'|'agenda')
  3957. * @default 'month'
  3958. */
  3959. defaultView: PropTypes.string,
  3960. /**
  3961. * An array of event objects to display on the calendar. Events objects
  3962. * can be any shape, as long as the Calendar knows how to retrieve the
  3963. * following details of the event:
  3964. *
  3965. * - start time
  3966. * - end time
  3967. * - title
  3968. * - whether its an "all day" event or not
  3969. * - any resource the event may be related to
  3970. *
  3971. * Each of these properties can be customized or generated dynamically by
  3972. * setting the various "accessor" props. Without any configuration the default
  3973. * event should look like:
  3974. *
  3975. * ```js
  3976. * Event {
  3977. * title: string,
  3978. * start: Date,
  3979. * end: Date,
  3980. * allDay?: boolean
  3981. * resource?: any,
  3982. * }
  3983. * ```
  3984. */
  3985. events: PropTypes.arrayOf(PropTypes.object),
  3986. /**
  3987. * Accessor for the event title, used to display event information. Should
  3988. * resolve to a `renderable` value.
  3989. *
  3990. * ```js
  3991. * string | (event: Object) => string
  3992. * ```
  3993. *
  3994. * @type {(func|string)}
  3995. */
  3996. titleAccessor: accessor,
  3997. /**
  3998. * Accessor for the event tooltip. Should
  3999. * resolve to a `renderable` value. Removes the tooltip if null.
  4000. *
  4001. * ```js
  4002. * string | (event: Object) => string
  4003. * ```
  4004. *
  4005. * @type {(func|string)}
  4006. */
  4007. tooltipAccessor: accessor,
  4008. /**
  4009. * Determines whether the event should be considered an "all day" event and ignore time.
  4010. * Must resolve to a `boolean` value.
  4011. *
  4012. * ```js
  4013. * string | (event: Object) => boolean
  4014. * ```
  4015. *
  4016. * @type {(func|string)}
  4017. */
  4018. allDayAccessor: accessor,
  4019. /**
  4020. * The start date/time of the event. Must resolve to a JavaScript `Date` object.
  4021. *
  4022. * ```js
  4023. * string | (event: Object) => Date
  4024. * ```
  4025. *
  4026. * @type {(func|string)}
  4027. */
  4028. startAccessor: accessor,
  4029. /**
  4030. * The end date/time of the event. Must resolve to a JavaScript `Date` object.
  4031. *
  4032. * ```js
  4033. * string | (event: Object) => Date
  4034. * ```
  4035. *
  4036. * @type {(func|string)}
  4037. */
  4038. endAccessor: accessor,
  4039. /**
  4040. * Returns the id of the `resource` that the event is a member of. This
  4041. * id should match at least one resource in the `resources` array.
  4042. *
  4043. * ```js
  4044. * string | (event: Object) => Date
  4045. * ```
  4046. *
  4047. * @type {(func|string)}
  4048. */
  4049. resourceAccessor: accessor,
  4050. /**
  4051. * An array of resource objects that map events to a specific resource.
  4052. * Resource objects, like events, can be any shape or have any properties,
  4053. * but should be uniquly identifiable via the `resourceIdAccessor`, as
  4054. * well as a "title" or name as provided by the `resourceTitleAccessor` prop.
  4055. */
  4056. resources: PropTypes.arrayOf(PropTypes.object),
  4057. /**
  4058. * Provides a unique identifier for each resource in the `resources` array
  4059. *
  4060. * ```js
  4061. * string | (resource: Object) => any
  4062. * ```
  4063. *
  4064. * @type {(func|string)}
  4065. */
  4066. resourceIdAccessor: accessor,
  4067. /**
  4068. * Provides a human readable name for the resource object, used in headers.
  4069. *
  4070. * ```js
  4071. * string | (resource: Object) => any
  4072. * ```
  4073. *
  4074. * @type {(func|string)}
  4075. */
  4076. resourceTitleAccessor: accessor,
  4077. /**
  4078. * Determines the current date/time which is highlighted in the views.
  4079. *
  4080. * The value affects which day is shaded and which time is shown as
  4081. * the current time. It also affects the date used by the Today button in
  4082. * the toolbar.
  4083. *
  4084. * Providing a value here can be useful when you are implementing time zones
  4085. * using the `startAccessor` and `endAccessor` properties.
  4086. *
  4087. * @type {func}
  4088. * @default () => new Date()
  4089. */
  4090. getNow: PropTypes.func,
  4091. /**
  4092. * Callback fired when the `date` value changes.
  4093. *
  4094. * @controllable date
  4095. */
  4096. onNavigate: PropTypes.func,
  4097. /**
  4098. * Callback fired when the `view` value changes.
  4099. *
  4100. * @controllable view
  4101. */
  4102. onView: PropTypes.func,
  4103. /**
  4104. * Callback fired when date header, or the truncated events links are clicked
  4105. *
  4106. */
  4107. onDrillDown: PropTypes.func,
  4108. /**
  4109. *
  4110. * ```js
  4111. * (dates: Date[] | { start: Date; end: Date }, view?: 'month'|'week'|'work_week'|'day'|'agenda') => void
  4112. * ```
  4113. *
  4114. * Callback fired when the visible date range changes. Returns an Array of dates
  4115. * or an object with start and end dates for BUILTIN views. Optionally new `view`
  4116. * will be returned when callback called after view change.
  4117. *
  4118. * Custom views may return something different.
  4119. */
  4120. onRangeChange: PropTypes.func,
  4121. /**
  4122. * A callback fired when a date selection is made. Only fires when `selectable` is `true`.
  4123. *
  4124. * ```js
  4125. * (
  4126. * slotInfo: {
  4127. * start: Date,
  4128. * end: Date,
  4129. * slots: Array<Date>,
  4130. * action: "select" | "click" | "doubleClick",
  4131. * bounds: ?{ // For "select" action
  4132. * x: number,
  4133. * y: number,
  4134. * top: number,
  4135. * right: number,
  4136. * left: number,
  4137. * bottom: number,
  4138. * },
  4139. * box: ?{ // For "click" or "doubleClick" actions
  4140. * clientX: number,
  4141. * clientY: number,
  4142. * x: number,
  4143. * y: number,
  4144. * },
  4145. * }
  4146. * ) => any
  4147. * ```
  4148. */
  4149. onSelectSlot: PropTypes.func,
  4150. /**
  4151. * Callback fired when a calendar event is selected.
  4152. *
  4153. * ```js
  4154. * (event: Object, e: SyntheticEvent) => any
  4155. * ```
  4156. *
  4157. * @controllable selected
  4158. */
  4159. onSelectEvent: PropTypes.func,
  4160. /**
  4161. * Callback fired when a calendar event is clicked twice.
  4162. *
  4163. * ```js
  4164. * (event: Object, e: SyntheticEvent) => void
  4165. * ```
  4166. */
  4167. onDoubleClickEvent: PropTypes.func,
  4168. /**
  4169. * Callback fired when dragging a selection in the Time views.
  4170. *
  4171. * Returning `false` from the handler will prevent a selection.
  4172. *
  4173. * ```js
  4174. * (range: { start: Date, end: Date }) => ?boolean
  4175. * ```
  4176. */
  4177. onSelecting: PropTypes.func,
  4178. /**
  4179. * Callback fired when a +{count} more is clicked
  4180. *
  4181. * ```js
  4182. * (events: Object, date: Date) => any
  4183. * ```
  4184. */
  4185. onShowMore: PropTypes.func,
  4186. /**
  4187. * The selected event, if any.
  4188. */
  4189. selected: PropTypes.object,
  4190. /**
  4191. * An array of built-in view names to allow the calendar to display.
  4192. * accepts either an array of builtin view names,
  4193. *
  4194. * ```jsx
  4195. * views={['month', 'day', 'agenda']}
  4196. * ```
  4197. * or an object hash of the view name and the component (or boolean for builtin).
  4198. *
  4199. * ```jsx
  4200. * views={{
  4201. * month: true,
  4202. * week: false,
  4203. * myweek: WorkWeekViewComponent,
  4204. * }}
  4205. * ```
  4206. *
  4207. * Custom views can be any React component, that implements the following
  4208. * interface:
  4209. *
  4210. * ```js
  4211. * interface View {
  4212. * static title(date: Date, { formats: DateFormat[], culture: string?, ...props }): string
  4213. * static navigate(date: Date, action: 'PREV' | 'NEXT' | 'DATE'): Date
  4214. * }
  4215. * ```
  4216. *
  4217. * @type Views ('month'|'week'|'work_week'|'day'|'agenda')
  4218. * @View
  4219. ['month', 'week', 'day', 'agenda']
  4220. */
  4221. views: views$1,
  4222. /**
  4223. * The string name of the destination view for drill-down actions, such
  4224. * as clicking a date header, or the truncated events links. If
  4225. * `getDrilldownView` is also specified it will be used instead.
  4226. *
  4227. * Set to `null` to disable drill-down actions.
  4228. *
  4229. * ```js
  4230. * <Calendar
  4231. * drilldownView="agenda"
  4232. * />
  4233. * ```
  4234. */
  4235. drilldownView: PropTypes.string,
  4236. /**
  4237. * Functionally equivalent to `drilldownView`, but accepts a function
  4238. * that can return a view name. It's useful for customizing the drill-down
  4239. * actions depending on the target date and triggering view.
  4240. *
  4241. * Return `null` to disable drill-down actions.
  4242. *
  4243. * ```js
  4244. * <Calendar
  4245. * getDrilldownView={(targetDate, currentViewName, configuredViewNames) =>
  4246. * if (currentViewName === 'month' && configuredViewNames.includes('week'))
  4247. * return 'week'
  4248. *
  4249. * return null;
  4250. * }}
  4251. * />
  4252. * ```
  4253. */
  4254. getDrilldownView: PropTypes.func,
  4255. /**
  4256. * Determines the end date from date prop in the agenda view
  4257. * date prop + length (in number of days) = end date
  4258. */
  4259. length: PropTypes.number,
  4260. /**
  4261. * Determines whether the toolbar is displayed
  4262. */
  4263. toolbar: PropTypes.bool,
  4264. /**
  4265. * Show truncated events in an overlay when you click the "+_x_ more" link.
  4266. */
  4267. popup: PropTypes.bool,
  4268. /**
  4269. * Distance in pixels, from the edges of the viewport, the "show more" overlay should be positioned.
  4270. *
  4271. * ```jsx
  4272. * <Calendar popupOffset={30}/>
  4273. * <Calendar popupOffset={{x: 30, y: 20}}/>
  4274. * ```
  4275. */
  4276. popupOffset: PropTypes.oneOfType([PropTypes.number, PropTypes.shape({
  4277. x: PropTypes.number,
  4278. y: PropTypes.number
  4279. })]),
  4280. /**
  4281. * Allows mouse selection of ranges of dates/times.
  4282. *
  4283. * The 'ignoreEvents' option prevents selection code from running when a
  4284. * drag begins over an event. Useful when you want custom event click or drag
  4285. * logic
  4286. */
  4287. selectable: PropTypes.oneOf([true, false, 'ignoreEvents']),
  4288. /**
  4289. * Specifies the number of miliseconds the user must press and hold on the screen for a touch
  4290. * to be considered a "long press." Long presses are used for time slot selection on touch
  4291. * devices.
  4292. *
  4293. * @type {number}
  4294. * @default 250
  4295. */
  4296. longPressThreshold: PropTypes.number,
  4297. /**
  4298. * Determines the selectable time increments in week and day views
  4299. */
  4300. step: PropTypes.number,
  4301. /**
  4302. * The number of slots per "section" in the time grid views. Adjust with `step`
  4303. * to change the default of 1 hour long groups, with 30 minute slots.
  4304. */
  4305. timeslots: PropTypes.number,
  4306. /**
  4307. *Switch the calendar to a `right-to-left` read direction.
  4308. */
  4309. rtl: PropTypes.bool,
  4310. /**
  4311. * Optionally provide a function that returns an object of className or style props
  4312. * to be applied to the the event node.
  4313. *
  4314. * ```js
  4315. * (
  4316. * event: Object,
  4317. * start: Date,
  4318. * end: Date,
  4319. * isSelected: boolean
  4320. * ) => { className?: string, style?: Object }
  4321. * ```
  4322. */
  4323. eventPropGetter: PropTypes.func,
  4324. /**
  4325. * Optionally provide a function that returns an object of className or style props
  4326. * to be applied to the the time-slot node. Caution! Styles that change layout or
  4327. * position may break the calendar in unexpected ways.
  4328. *
  4329. * ```js
  4330. * (date: Date, resourceId: (number|string)) => { className?: string, style?: Object }
  4331. * ```
  4332. */
  4333. slotPropGetter: PropTypes.func,
  4334. /**
  4335. * Optionally provide a function that returns an object of className or style props
  4336. * to be applied to the the day background. Caution! Styles that change layout or
  4337. * position may break the calendar in unexpected ways.
  4338. *
  4339. * ```js
  4340. * (date: Date) => { className?: string, style?: Object }
  4341. * ```
  4342. */
  4343. dayPropGetter: PropTypes.func,
  4344. /**
  4345. * Support to show multi-day events with specific start and end times in the
  4346. * main time grid (rather than in the all day header).
  4347. *
  4348. * **Note: This may cause calendars with several events to look very busy in
  4349. * the week and day views.**
  4350. */
  4351. showMultiDayTimes: PropTypes.bool,
  4352. /**
  4353. * Constrains the minimum _time_ of the Day and Week views.
  4354. */
  4355. min: PropTypes.instanceOf(Date),
  4356. /**
  4357. * Constrains the maximum _time_ of the Day and Week views.
  4358. */
  4359. max: PropTypes.instanceOf(Date),
  4360. /**
  4361. * Determines how far down the scroll pane is initially scrolled down.
  4362. */
  4363. scrollToTime: PropTypes.instanceOf(Date),
  4364. /**
  4365. * Specify a specific culture code for the Calendar.
  4366. *
  4367. * **Note: it's generally better to handle this globally via your i18n library.**
  4368. */
  4369. culture: PropTypes.string,
  4370. /**
  4371. * Localizer specific formats, tell the Calendar how to format and display dates.
  4372. *
  4373. * `format` types are dependent on the configured localizer; both Moment and Globalize
  4374. * accept strings of tokens according to their own specification, such as: `'DD mm yyyy'`.
  4375. *
  4376. * ```jsx
  4377. * let formats = {
  4378. * dateFormat: 'dd',
  4379. *
  4380. * dayFormat: (date, , localizer) =>
  4381. * localizer.format(date, 'DDD', culture),
  4382. *
  4383. * dayRangeHeaderFormat: ({ start, end }, culture, localizer) =>
  4384. * localizer.format(start, { date: 'short' }, culture) + ' – ' +
  4385. * localizer.format(end, { date: 'short' }, culture)
  4386. * }
  4387. *
  4388. * <Calendar formats={formats} />
  4389. * ```
  4390. *
  4391. * All localizers accept a function of
  4392. * the form `(date: Date, culture: ?string, localizer: Localizer) -> string`
  4393. */
  4394. formats: PropTypes.shape({
  4395. /**
  4396. * Format for the day of the month heading in the Month view.
  4397. * e.g. "01", "02", "03", etc
  4398. */
  4399. dateFormat: dateFormat,
  4400. /**
  4401. * A day of the week format for Week and Day headings,
  4402. * e.g. "Wed 01/04"
  4403. *
  4404. */
  4405. dayFormat: dateFormat,
  4406. /**
  4407. * Week day name format for the Month week day headings,
  4408. * e.g: "Sun", "Mon", "Tue", etc
  4409. *
  4410. */
  4411. weekdayFormat: dateFormat,
  4412. /**
  4413. * The timestamp cell formats in Week and Time views, e.g. "4:00 AM"
  4414. */
  4415. timeGutterFormat: dateFormat,
  4416. /**
  4417. * Toolbar header format for the Month view, e.g "2015 April"
  4418. *
  4419. */
  4420. monthHeaderFormat: dateFormat,
  4421. /**
  4422. * Toolbar header format for the Week views, e.g. "Mar 29 - Apr 04"
  4423. */
  4424. dayRangeHeaderFormat: dateRangeFormat,
  4425. /**
  4426. * Toolbar header format for the Day view, e.g. "Wednesday Apr 01"
  4427. */
  4428. dayHeaderFormat: dateFormat,
  4429. /**
  4430. * Toolbar header format for the Agenda view, e.g. "4/1/2015 – 5/1/2015"
  4431. */
  4432. agendaHeaderFormat: dateRangeFormat,
  4433. /**
  4434. * A time range format for selecting time slots, e.g "8:00am – 2:00pm"
  4435. */
  4436. selectRangeFormat: dateRangeFormat,
  4437. agendaDateFormat: dateFormat,
  4438. agendaTimeFormat: dateFormat,
  4439. agendaTimeRangeFormat: dateRangeFormat,
  4440. /**
  4441. * Time range displayed on events.
  4442. */
  4443. eventTimeRangeFormat: dateRangeFormat,
  4444. /**
  4445. * An optional event time range for events that continue onto another day
  4446. */
  4447. eventTimeRangeStartFormat: dateFormat,
  4448. /**
  4449. * An optional event time range for events that continue from another day
  4450. */
  4451. eventTimeRangeEndFormat: dateFormat
  4452. }),
  4453. /**
  4454. * Customize how different sections of the calendar render by providing custom Components.
  4455. * In particular the `Event` component can be specified for the entire calendar, or you can
  4456. * provide an individual component for each view type.
  4457. *
  4458. * ```jsx
  4459. * let components = {
  4460. * event: MyEvent, // used by each view (Month, Day, Week)
  4461. * eventWrapper: MyEventWrapper,
  4462. * eventContainerWrapper: MyEventContainerWrapper,
  4463. * dateCellWrapper: MyDateCellWrapper,
  4464. * timeSlotWrapper: MyTimeSlotWrapper,
  4465. * timeGutterHeader: MyTimeGutterWrapper,
  4466. * toolbar: MyToolbar,
  4467. * agenda: {
  4468. * event: MyAgendaEvent // with the agenda view use a different component to render events
  4469. * time: MyAgendaTime,
  4470. * date: MyAgendaDate,
  4471. * },
  4472. * day: {
  4473. * header: MyDayHeader,
  4474. * event: MyDayEvent,
  4475. * },
  4476. * week: {
  4477. * header: MyWeekHeader,
  4478. * event: MyWeekEvent,
  4479. * },
  4480. * month: {
  4481. * header: MyMonthHeader,
  4482. * dateHeader: MyMonthDateHeader,
  4483. * event: MyMonthEvent,
  4484. * }
  4485. * }
  4486. * <Calendar components={components} />
  4487. * ```
  4488. */
  4489. components: PropTypes.shape({
  4490. event: PropTypes.elementType,
  4491. eventWrapper: PropTypes.elementType,
  4492. eventContainerWrapper: PropTypes.elementType,
  4493. dateCellWrapper: PropTypes.elementType,
  4494. timeSlotWrapper: PropTypes.elementType,
  4495. timeGutterHeader: PropTypes.elementType,
  4496. resourceHeader: PropTypes.elementType,
  4497. toolbar: PropTypes.elementType,
  4498. agenda: PropTypes.shape({
  4499. date: PropTypes.elementType,
  4500. time: PropTypes.elementType,
  4501. event: PropTypes.elementType
  4502. }),
  4503. day: PropTypes.shape({
  4504. header: PropTypes.elementType,
  4505. event: PropTypes.elementType
  4506. }),
  4507. week: PropTypes.shape({
  4508. header: PropTypes.elementType,
  4509. event: PropTypes.elementType
  4510. }),
  4511. month: PropTypes.shape({
  4512. header: PropTypes.elementType,
  4513. dateHeader: PropTypes.elementType,
  4514. event: PropTypes.elementType
  4515. })
  4516. }),
  4517. /**
  4518. * String messages used throughout the component, override to provide localizations
  4519. */
  4520. messages: PropTypes.shape({
  4521. allDay: PropTypes.node,
  4522. previous: PropTypes.node,
  4523. next: PropTypes.node,
  4524. today: PropTypes.node,
  4525. month: PropTypes.node,
  4526. week: PropTypes.node,
  4527. day: PropTypes.node,
  4528. agenda: PropTypes.node,
  4529. date: PropTypes.node,
  4530. time: PropTypes.node,
  4531. event: PropTypes.node,
  4532. noEventsInRange: PropTypes.node,
  4533. showMore: PropTypes.func
  4534. })
  4535. } : {};
  4536. var Calendar$1 = uncontrollable(Calendar, {
  4537. view: 'onView',
  4538. date: 'onNavigate',
  4539. selected: 'onSelectEvent'
  4540. });
  4541. var dateRangeFormat$1 = function dateRangeFormat(_ref, culture, local) {
  4542. var start = _ref.start,
  4543. end = _ref.end;
  4544. return local.format(start, 'L', culture) + ' – ' + local.format(end, 'L', culture);
  4545. };
  4546. var timeRangeFormat = function timeRangeFormat(_ref2, culture, local) {
  4547. var start = _ref2.start,
  4548. end = _ref2.end;
  4549. return local.format(start, 'LT', culture) + ' – ' + local.format(end, 'LT', culture);
  4550. };
  4551. var timeRangeStartFormat = function timeRangeStartFormat(_ref3, culture, local) {
  4552. var start = _ref3.start;
  4553. return local.format(start, 'LT', culture) + ' – ';
  4554. };
  4555. var timeRangeEndFormat = function timeRangeEndFormat(_ref4, culture, local) {
  4556. var end = _ref4.end;
  4557. return ' – ' + local.format(end, 'LT', culture);
  4558. };
  4559. var weekRangeFormat = function weekRangeFormat(_ref5, culture, local) {
  4560. var start = _ref5.start,
  4561. end = _ref5.end;
  4562. return local.format(start, 'MMMM DD', culture) + ' – ' + local.format(end, eq(start, end, 'month') ? 'DD' : 'MMMM DD', culture);
  4563. };
  4564. var formats = {
  4565. dateFormat: 'DD',
  4566. dayFormat: 'DD ddd',
  4567. weekdayFormat: 'ddd',
  4568. selectRangeFormat: timeRangeFormat,
  4569. eventTimeRangeFormat: timeRangeFormat,
  4570. eventTimeRangeStartFormat: timeRangeStartFormat,
  4571. eventTimeRangeEndFormat: timeRangeEndFormat,
  4572. timeGutterFormat: 'LT',
  4573. monthHeaderFormat: 'MMMM YYYY',
  4574. dayHeaderFormat: 'dddd MMM DD',
  4575. dayRangeHeaderFormat: weekRangeFormat,
  4576. agendaHeaderFormat: dateRangeFormat$1,
  4577. agendaDateFormat: 'ddd MMM DD',
  4578. agendaTimeFormat: 'LT',
  4579. agendaTimeRangeFormat: timeRangeFormat
  4580. };
  4581. function moment (moment) {
  4582. var locale = function locale(m, c) {
  4583. return c ? m.locale(c) : m;
  4584. };
  4585. return new DateLocalizer({
  4586. formats: formats,
  4587. firstOfWeek: function firstOfWeek(culture) {
  4588. var data = culture ? moment.localeData(culture) : moment.localeData();
  4589. return data ? data.firstDayOfWeek() : 0;
  4590. },
  4591. format: function format(value, _format, culture) {
  4592. return locale(moment(value), culture).format(_format);
  4593. }
  4594. });
  4595. }
  4596. var dateRangeFormat$2 = function dateRangeFormat(_ref, culture, local) {
  4597. var start = _ref.start,
  4598. end = _ref.end;
  4599. return local.format(start, 'd', culture) + ' – ' + local.format(end, 'd', culture);
  4600. };
  4601. var timeRangeFormat$1 = function timeRangeFormat(_ref2, culture, local) {
  4602. var start = _ref2.start,
  4603. end = _ref2.end;
  4604. return local.format(start, 't', culture) + ' – ' + local.format(end, 't', culture);
  4605. };
  4606. var timeRangeStartFormat$1 = function timeRangeStartFormat(_ref3, culture, local) {
  4607. var start = _ref3.start;
  4608. return local.format(start, 't', culture) + ' – ';
  4609. };
  4610. var timeRangeEndFormat$1 = function timeRangeEndFormat(_ref4, culture, local) {
  4611. var end = _ref4.end;
  4612. return ' – ' + local.format(end, 't', culture);
  4613. };
  4614. var weekRangeFormat$1 = function weekRangeFormat(_ref5, culture, local) {
  4615. var start = _ref5.start,
  4616. end = _ref5.end;
  4617. return local.format(start, 'MMM dd', culture) + ' – ' + local.format(end, eq(start, end, 'month') ? 'dd' : 'MMM dd', culture);
  4618. };
  4619. var formats$1 = {
  4620. dateFormat: 'dd',
  4621. dayFormat: 'ddd dd/MM',
  4622. weekdayFormat: 'ddd',
  4623. selectRangeFormat: timeRangeFormat$1,
  4624. eventTimeRangeFormat: timeRangeFormat$1,
  4625. eventTimeRangeStartFormat: timeRangeStartFormat$1,
  4626. eventTimeRangeEndFormat: timeRangeEndFormat$1,
  4627. timeGutterFormat: 't',
  4628. monthHeaderFormat: 'Y',
  4629. dayHeaderFormat: 'dddd MMM dd',
  4630. dayRangeHeaderFormat: weekRangeFormat$1,
  4631. agendaHeaderFormat: dateRangeFormat$2,
  4632. agendaDateFormat: 'ddd MMM dd',
  4633. agendaTimeFormat: 't',
  4634. agendaTimeRangeFormat: timeRangeFormat$1
  4635. };
  4636. function oldGlobalize (globalize) {
  4637. function getCulture(culture) {
  4638. return culture ? globalize.findClosestCulture(culture) : globalize.culture();
  4639. }
  4640. function firstOfWeek(culture) {
  4641. culture = getCulture(culture);
  4642. return culture && culture.calendar.firstDay || 0;
  4643. }
  4644. return new DateLocalizer({
  4645. firstOfWeek: firstOfWeek,
  4646. formats: formats$1,
  4647. format: function format(value, _format, culture) {
  4648. return globalize.format(value, _format, culture);
  4649. }
  4650. });
  4651. }
  4652. var dateRangeFormat$3 = function dateRangeFormat(_ref, culture, local) {
  4653. var start = _ref.start,
  4654. end = _ref.end;
  4655. return local.format(start, {
  4656. date: 'short'
  4657. }, culture) + ' – ' + local.format(end, {
  4658. date: 'short'
  4659. }, culture);
  4660. };
  4661. var timeRangeFormat$2 = function timeRangeFormat(_ref2, culture, local) {
  4662. var start = _ref2.start,
  4663. end = _ref2.end;
  4664. return local.format(start, {
  4665. time: 'short'
  4666. }, culture) + ' – ' + local.format(end, {
  4667. time: 'short'
  4668. }, culture);
  4669. };
  4670. var timeRangeStartFormat$2 = function timeRangeStartFormat(_ref3, culture, local) {
  4671. var start = _ref3.start;
  4672. return local.format(start, {
  4673. time: 'short'
  4674. }, culture) + ' – ';
  4675. };
  4676. var timeRangeEndFormat$2 = function timeRangeEndFormat(_ref4, culture, local) {
  4677. var end = _ref4.end;
  4678. return ' – ' + local.format(end, {
  4679. time: 'short'
  4680. }, culture);
  4681. };
  4682. var weekRangeFormat$2 = function weekRangeFormat(_ref5, culture, local) {
  4683. var start = _ref5.start,
  4684. end = _ref5.end;
  4685. return local.format(start, 'MMM dd', culture) + ' – ' + local.format(end, eq(start, end, 'month') ? 'dd' : 'MMM dd', culture);
  4686. };
  4687. var formats$2 = {
  4688. dateFormat: 'dd',
  4689. dayFormat: 'eee dd/MM',
  4690. weekdayFormat: 'eee',
  4691. selectRangeFormat: timeRangeFormat$2,
  4692. eventTimeRangeFormat: timeRangeFormat$2,
  4693. eventTimeRangeStartFormat: timeRangeStartFormat$2,
  4694. eventTimeRangeEndFormat: timeRangeEndFormat$2,
  4695. timeGutterFormat: {
  4696. time: 'short'
  4697. },
  4698. monthHeaderFormat: 'MMMM yyyy',
  4699. dayHeaderFormat: 'eeee MMM dd',
  4700. dayRangeHeaderFormat: weekRangeFormat$2,
  4701. agendaHeaderFormat: dateRangeFormat$3,
  4702. agendaDateFormat: 'eee MMM dd',
  4703. agendaTimeFormat: {
  4704. time: 'short'
  4705. },
  4706. agendaTimeRangeFormat: timeRangeFormat$2
  4707. };
  4708. function globalize (globalize) {
  4709. var locale = function locale(culture) {
  4710. return culture ? globalize(culture) : globalize;
  4711. }; // return the first day of the week from the locale data. Defaults to 'world'
  4712. // territory if no territory is derivable from CLDR.
  4713. // Failing to use CLDR supplemental (not loaded?), revert to the original
  4714. // method of getting first day of week.
  4715. function firstOfWeek(culture) {
  4716. try {
  4717. var days = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];
  4718. var cldr = locale(culture).cldr;
  4719. var territory = cldr.attributes.territory;
  4720. var weekData = cldr.get('supplemental').weekData;
  4721. var firstDay = weekData.firstDay[territory || '001'];
  4722. return days.indexOf(firstDay);
  4723. } catch (e) {
  4724. process.env.NODE_ENV !== "production" ? warning(true, "Failed to accurately determine first day of the week.\n Is supplemental data loaded into CLDR?") : void 0; // maybe cldr supplemental is not loaded? revert to original method
  4725. var date = new Date(); //cldr-data doesn't seem to be zero based
  4726. var localeDay = Math.max(parseInt(locale(culture).formatDate(date, {
  4727. raw: 'e'
  4728. }), 10) - 1, 0);
  4729. return Math.abs(date.getDay() - localeDay);
  4730. }
  4731. }
  4732. if (!globalize.load) return oldGlobalize(globalize);
  4733. return new DateLocalizer({
  4734. firstOfWeek: firstOfWeek,
  4735. formats: formats$2,
  4736. format: function format(value, _format, culture) {
  4737. _format = typeof _format === 'string' ? {
  4738. raw: _format
  4739. } : _format;
  4740. return locale(culture).formatDate(value, _format);
  4741. }
  4742. });
  4743. }
  4744. var components = {
  4745. eventWrapper: NoopWrapper,
  4746. timeSlotWrapper: NoopWrapper,
  4747. dateCellWrapper: NoopWrapper
  4748. };
  4749. export { Calendar$1 as Calendar, DateLocalizer, navigate as Navigate, views as Views, components, globalize as globalizeLocalizer, moment as momentLocalizer, moveDate as move };