Repository URL to install this package:
|
Version:
2.4.1 ▾
|
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
var _momentTimezone = require('moment-timezone');
var _momentTimezone2 = _interopRequireDefault(_momentTimezone);
var _propTypes3 = require('../../utils/propTypes');
var _accessors = require('../../utils/accessors');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var EventWrapper = function (_React$Component) {
_inherits(EventWrapper, _React$Component);
function EventWrapper() {
var _ref;
var _temp, _this, _ret;
_classCallCheck(this, EventWrapper);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = EventWrapper.__proto__ || Object.getPrototypeOf(EventWrapper)).call.apply(_ref, [this].concat(args))), _this), _this.handleResizeUp = function (e) {
if (e.button !== 0) return;
e.stopPropagation();
_this.handleBeginAction(e, 'resize', 'UP');
}, _this.handleResizeDown = function (e) {
if (e.button !== 0) return;
e.stopPropagation();
_this.handleBeginAction(e, 'resize', 'DOWN');
}, _this.handleResizeLeft = function (e) {
if (e.button !== 0) return;
e.stopPropagation();
_this.handleBeginAction(e, 'resize', 'LEFT');
}, _this.handleResizeRight = function (e) {
if (e.button !== 0) return;
e.stopPropagation();
_this.handleBeginAction(e, 'resize', 'RIGHT');
}, _this.handleStartDragging = function (e) {
if (e.button === 0) {
_this.handleBeginAction(e, 'move');
}
}, _this.handleBeginAction = function (e, action, direction) {
var lastNativeEvent = _this.context.draggable.dragAndDropAction.nativeEvent;
var nativeEvent = e.nativeEvent.type;
var touchEndThenMouseDown = lastNativeEvent === 'touchend' && nativeEvent === 'mousedown';
var interacting = _this.context.draggable.dragAndDropAction.interacting;
_this.context.draggable.onBeginAction(_this.props.event, action, direction, nativeEvent);
if (nativeEvent === 'touchend' && !interacting || touchEndThenMouseDown) {
_this.context.draggable.onEnd(null);
}
}, _temp), _possibleConstructorReturn(_this, _ret);
}
_createClass(EventWrapper, [{
key: 'renderAnchor',
value: function renderAnchor(direction) {
var smallSlotSize = _momentTimezone2.default.duration(40, 'minutes').asMilliseconds();
var smallSlot = Date.parse(this.props.event.end) - Date.parse(this.props.event.start) < smallSlotSize;
var classMode = void 0;
switch (true) {
case this.props.isGenericCalendarMode:
classMode = 'fr';
break;
case direction === 'Up' || direction === 'Down':
classMode = 'ns';
break;
default:
classMode = 'ew';
}
return _react2.default.createElement(
'div',
{
className: smallSlot ? 'rbc-addons-dnd-resize-' + classMode + '-anchor-small ' : 'rbc-addons-dnd-resize-' + classMode + '-anchor',
onMouseDown: this['handleResize' + direction]
},
_react2.default.createElement('div', { className: 'rbc-addons-dnd-resize-' + classMode + '-icon' }),
_react2.default.createElement('div', { className: 'rbc-addons-dnd-resize-' + classMode + '-icon' })
);
}
}, {
key: 'render',
value: function render() {
var _props = this.props,
event = _props.event,
type = _props.type,
continuesPrior = _props.continuesPrior,
continuesAfter = _props.continuesAfter,
isGenericCalendarMode = _props.isGenericCalendarMode;
var children = this.props.children;
if (event.__isPreview) return _react2.default.cloneElement(children, {
className: (0, _classnames2.default)(children.props.className, 'rbc-addons-dnd-drag-preview')
});
var draggable = this.context.draggable;
var draggableAccessor = draggable.draggableAccessor,
resizableAccessor = draggable.resizableAccessor;
var isDraggable = draggableAccessor ? !!(0, _accessors.accessor)(event, draggableAccessor) : true;
/*
* The resizability of events depends on whether they are
* allDay events and how they are displayed.
*
* 1. If the event is being shown in an event row (because
* it is an allDay event shown in the header row or because as
* in month view the view is showing all events as rows) then we
* allow east-west resizing.
*
* 2. Otherwise the event is being displayed
* normally, we can drag it north-south to resize the times.
*
* See `DropWrappers` for handling of the drop of such events.
*
* Notwithstanding the above, we never show drag anchors for
* events which continue beyond current component. This happens
* in the middle of events when showMultiDay is true, and to
* events at the edges of the calendar's min/max location.
*/
var isResizable = resizableAccessor ? !!(0, _accessors.accessor)(event, resizableAccessor) : true;
/* Event is not draggable, no need to wrap it */
if (!isDraggable && !isResizable) {
return children;
}
if (isResizable || isDraggable) {
/*
* props.children is the singular <Event> component.
* BigCalendar positions the Event abolutely and we
* need the anchors to be part of that positioning.
* So we insert the anchors inside the Event's children
* rather than wrap the Event here as the latter approach
* would lose the positioning.
*/
var newProps = isDraggable ? {
onMouseDown: this.handleStartDragging,
onTouchStart: this.handleStartDragging
} : {};
if (isResizable) {
// replace original event child with anchor-embellished child
var StartAnchor = null;
var EndAnchor = null;
if (type === 'date') {
StartAnchor = !continuesPrior && this.renderAnchor('Left');
EndAnchor = !continuesAfter && this.renderAnchor('Right');
} else if (isGenericCalendarMode) {
StartAnchor = !continuesAfter && this.renderAnchor('Up');
EndAnchor = !continuesAfter && this.renderAnchor('Down');
} else {
EndAnchor = !continuesAfter && this.renderAnchor('Down');
}
newProps.children = _react2.default.createElement(
'div',
{ className: 'rbc-addons-dnd-resizable' },
StartAnchor,
children.props.children,
EndAnchor
);
}
if (draggable.dragAndDropAction.interacting && // if an event is being dragged right now
draggable.dragAndDropAction.event === event // and it's the current event
) {
// add a new class to it
newProps.className = (0, _classnames2.default)(children.props.className, 'rbc-addons-dnd-dragged-event');
}
children = _react2.default.cloneElement(children, newProps);
}
return children;
}
}]);
return EventWrapper;
}(_react2.default.Component);
EventWrapper.contextTypes = {
draggable: _propTypes2.default.shape({
onStart: _propTypes2.default.func,
onEnd: _propTypes2.default.func,
onBeginAction: _propTypes2.default.func,
draggableAccessor: _propTypes3.accessor,
resizableAccessor: _propTypes3.accessor,
dragAndDropAction: _propTypes2.default.object
})
};
EventWrapper.propTypes = {
type: _propTypes2.default.oneOf(['date', 'time']),
event: _propTypes2.default.object.isRequired,
draggable: _propTypes2.default.bool,
allDay: _propTypes2.default.bool,
isRow: _propTypes2.default.bool,
continuesPrior: _propTypes2.default.bool,
continuesAfter: _propTypes2.default.bool,
isDragging: _propTypes2.default.bool,
isResizing: _propTypes2.default.bool,
isGenericCalendarMode: _propTypes2.default.bool
};
exports.default = EventWrapper;