better-staridc-MNBT
1/*!
2FullCalendar Interaction Plugin v4.3.0
3Docs & License: https://fullcalendar.io/
4(c) 2019 Adam Shaw
5*/
6
7import { config, elementClosest, EmitterMixin, applyStyle, whenTransitionDone, removeElement, ScrollController, ElementScrollController, computeInnerRect, WindowScrollController, preventSelection, preventContextMenu, allowSelection, allowContextMenu, ElementDragging, computeRect, getClippingParents, pointInsideRect, isDateSpansEqual, constrainPoint, intersectRects, getRectCenter, diffPoints, mapHash, rangeContainsRange, interactionSettingsToStore, Interaction, enableCursor, disableCursor, compareNumbers, getElSeg, getRelevantEvents, EventApi, createEmptyEventStore, applyMutationToEventStore, interactionSettingsStore, startOfDay, diffDates, createDuration, eventTupleToStore, isInteractionValid, parseDragMeta, elementMatches, parseEventDef, createEventInstance, globalDefaults, createPlugin } from '@fullcalendar/core';
8
9/*! *****************************************************************************
10Copyright (c) Microsoft Corporation. All rights reserved.
11Licensed under the Apache License, Version 2.0 (the "License"); you may not use
12this file except in compliance with the License. You may obtain a copy of the
13License at http://www.apache.org/licenses/LICENSE-2.0
14
15THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
17WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
18MERCHANTABLITY OR NON-INFRINGEMENT.
19
20See the Apache Version 2.0 License for specific language governing permissions
21and limitations under the License.
22***************************************************************************** */
23/* global Reflect, Promise */
24
25var extendStatics = function(d, b) {
26 extendStatics = Object.setPrototypeOf ||
27 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
28 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
29 return extendStatics(d, b);
30};
31
32function __extends(d, b) {
33 extendStatics(d, b);
34 function __() { this.constructor = d; }
35 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
36}
37
38var __assign = function() {
39 __assign = Object.assign || function __assign(t) {
40 for (var s, i = 1, n = arguments.length; i < n; i++) {
41 s = arguments[i];
42 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
43 }
44 return t;
45 };
46 return __assign.apply(this, arguments);
47};
48
49config.touchMouseIgnoreWait = 500;
50var ignoreMouseDepth = 0;
51var listenerCnt = 0;
52var isWindowTouchMoveCancelled = false;
53/*
54Uses a "pointer" abstraction, which monitors UI events for both mouse and touch.
55Tracks when the pointer "drags" on a certain element, meaning down+move+up.
56
57Also, tracks if there was touch-scrolling.
58Also, can prevent touch-scrolling from happening.
59Also, can fire pointermove events when scrolling happens underneath, even when no real pointer movement.
60
61emits:
62- pointerdown
63- pointermove
64- pointerup
65*/
66var PointerDragging = /** @class */ (function () {
67 function PointerDragging(containerEl) {
68 var _this = this;
69 this.subjectEl = null;
70 this.downEl = null;
71 // options that can be directly assigned by caller
72 this.selector = ''; // will cause subjectEl in all emitted events to be this element
73 this.handleSelector = '';
74 this.shouldIgnoreMove = false;
75 this.shouldWatchScroll = true; // for simulating pointermove on scroll
76 // internal states
77 this.isDragging = false;
78 this.isTouchDragging = false;
79 this.wasTouchScroll = false;
80 // Mouse
81 // ----------------------------------------------------------------------------------------------------
82 this.handleMouseDown = function (ev) {
83 if (!_this.shouldIgnoreMouse() &&
84 isPrimaryMouseButton(ev) &&
85 _this.tryStart(ev)) {
86 var pev = _this.createEventFromMouse(ev, true);
87 _this.emitter.trigger('pointerdown', pev);
88 _this.initScrollWatch(pev);
89 if (!_this.shouldIgnoreMove) {
90 document.addEventListener('mousemove', _this.handleMouseMove);
91 }
92 document.addEventListener('mouseup', _this.handleMouseUp);
93 }
94 };
95 this.handleMouseMove = function (ev) {
96 var pev = _this.createEventFromMouse(ev);
97 _this.recordCoords(pev);
98 _this.emitter.trigger('pointermove', pev);
99 };
100 this.handleMouseUp = function (ev) {
101 document.removeEventListener('mousemove', _this.handleMouseMove);
102 document.removeEventListener('mouseup', _this.handleMouseUp);
103 _this.emitter.trigger('pointerup', _this.createEventFromMouse(ev));
104 _this.cleanup(); // call last so that pointerup has access to props
105 };
106 // Touch
107 // ----------------------------------------------------------------------------------------------------
108 this.handleTouchStart = function (ev) {
109 if (_this.tryStart(ev)) {
110 _this.isTouchDragging = true;
111 var pev = _this.createEventFromTouch(ev, true);
112 _this.emitter.trigger('pointerdown', pev);
113 _this.initScrollWatch(pev);
114 // unlike mouse, need to attach to target, not document
115 // https://stackoverflow.com/a/45760014
116 var target = ev.target;
117 if (!_this.shouldIgnoreMove) {
118 target.addEventListener('touchmove', _this.handleTouchMove);
119 }
120 target.addEventListener('touchend', _this.handleTouchEnd);
121 target.addEventListener('touchcancel', _this.handleTouchEnd); // treat it as a touch end
122 // attach a handler to get called when ANY scroll action happens on the page.
123 // this was impossible to do with normal on/off because 'scroll' doesn't bubble.
124 // http://stackoverflow.com/a/32954565/96342
125 window.addEventListener('scroll', _this.handleTouchScroll, true // useCapture
126 );
127 }
128 };
129 this.handleTouchMove = function (ev) {
130 var pev = _this.createEventFromTouch(ev);
131 _this.recordCoords(pev);
132 _this.emitter.trigger('pointermove', pev);
133 };
134 this.handleTouchEnd = function (ev) {
135 if (_this.isDragging) { // done to guard against touchend followed by touchcancel
136 var target = ev.target;
137 target.removeEventListener('touchmove', _this.handleTouchMove);
138 target.removeEventListener('touchend', _this.handleTouchEnd);
139 target.removeEventListener('touchcancel', _this.handleTouchEnd);
140 window.removeEventListener('scroll', _this.handleTouchScroll, true); // useCaptured=true
141 _this.emitter.trigger('pointerup', _this.createEventFromTouch(ev));
142 _this.cleanup(); // call last so that pointerup has access to props
143 _this.isTouchDragging = false;
144 startIgnoringMouse();
145 }
146 };
147 this.handleTouchScroll = function () {
148 _this.wasTouchScroll = true;
149 };
150 this.handleScroll = function (ev) {
151 if (!_this.shouldIgnoreMove) {
152 var pageX = (window.pageXOffset - _this.prevScrollX) + _this.prevPageX;
153 var pageY = (window.pageYOffset - _this.prevScrollY) + _this.prevPageY;
154 _this.emitter.trigger('pointermove', {
155 origEvent: ev,
156 isTouch: _this.isTouchDragging,
157 subjectEl: _this.subjectEl,
158 pageX: pageX,
159 pageY: pageY,
160 deltaX: pageX - _this.origPageX,
161 deltaY: pageY - _this.origPageY
162 });
163 }
164 };
165 this.containerEl = containerEl;
166 this.emitter = new EmitterMixin();
167 containerEl.addEventListener('mousedown', this.handleMouseDown);
168 containerEl.addEventListener('touchstart', this.handleTouchStart, { passive: true });
169 listenerCreated();
170 }
171 PointerDragging.prototype.destroy = function () {
172 this.containerEl.removeEventListener('mousedown', this.handleMouseDown);
173 this.containerEl.removeEventListener('touchstart', this.handleTouchStart, { passive: true });
174 listenerDestroyed();
175 };
176 PointerDragging.prototype.tryStart = function (ev) {
177 var subjectEl = this.querySubjectEl(ev);
178 var downEl = ev.target;
179 if (subjectEl &&
180 (!this.handleSelector || elementClosest(downEl, this.handleSelector))) {
181 this.subjectEl = subjectEl;
182 this.downEl = downEl;
183 this.isDragging = true; // do this first so cancelTouchScroll will work
184 this.wasTouchScroll = false;
185 return true;
186 }
187 return false;
188 };
189 PointerDragging.prototype.cleanup = function () {
190 isWindowTouchMoveCancelled = false;
191 this.isDragging = false;
192 this.subjectEl = null;
193 this.downEl = null;
194 // keep wasTouchScroll around for later access
195 this.destroyScrollWatch();
196 };
197 PointerDragging.prototype.querySubjectEl = function (ev) {
198 if (this.selector) {
199 return elementClosest(ev.target, this.selector);
200 }
201 else {
202 return this.containerEl;
203 }
204 };
205 PointerDragging.prototype.shouldIgnoreMouse = function () {
206 return ignoreMouseDepth || this.isTouchDragging;
207 };
208 // can be called by user of this class, to cancel touch-based scrolling for the current drag
209 PointerDragging.prototype.cancelTouchScroll = function () {
210 if (this.isDragging) {
211 isWindowTouchMoveCancelled = true;
212 }
213 };
214 // Scrolling that simulates pointermoves
215 // ----------------------------------------------------------------------------------------------------
216 PointerDragging.prototype.initScrollWatch = function (ev) {
217 if (this.shouldWatchScroll) {
218 this.recordCoords(ev);
219 window.addEventListener('scroll', this.handleScroll, true); // useCapture=true
220 }
221 };
222 PointerDragging.prototype.recordCoords = function (ev) {
223 if (this.shouldWatchScroll) {
224 this.prevPageX = ev.pageX;
225 this.prevPageY = ev.pageY;
226 this.prevScrollX = window.pageXOffset;
227 this.prevScrollY = window.pageYOffset;
228 }
229 };
230 PointerDragging.prototype.destroyScrollWatch = function () {
231 if (this.shouldWatchScroll) {
232 window.removeEventListener('scroll', this.handleScroll, true); // useCaptured=true
233 }
234 };
235 // Event Normalization
236 // ----------------------------------------------------------------------------------------------------
237 PointerDragging.prototype.createEventFromMouse = function (ev, isFirst) {
238 var deltaX = 0;
239 var deltaY = 0;
240 // TODO: repeat code
241 if (isFirst) {
242 this.origPageX = ev.pageX;
243 this.origPageY = ev.pageY;
244 }
245 else {
246 deltaX = ev.pageX - this.origPageX;
247 deltaY = ev.pageY - this.origPageY;
248 }
249 return {
250 origEvent: ev,
251 isTouch: false,
252 subjectEl: this.subjectEl,
253 pageX: ev.pageX,
254 pageY: ev.pageY,
255 deltaX: deltaX,
256 deltaY: deltaY
257 };
258 };
259 PointerDragging.prototype.createEventFromTouch = function (ev, isFirst) {
260 var touches = ev.touches;
261 var pageX;
262 var pageY;
263 var deltaX = 0;
264 var deltaY = 0;
265 // if touch coords available, prefer,
266 // because FF would give bad ev.pageX ev.pageY
267 if (touches && touches.length) {
268 pageX = touches[0].pageX;
269 pageY = touches[0].pageY;
270 }
271 else {
272 pageX = ev.pageX;
273 pageY = ev.pageY;
274 }
275 // TODO: repeat code
276 if (isFirst) {
277 this.origPageX = pageX;
278 this.origPageY = pageY;
279 }
280 else {
281 deltaX = pageX - this.origPageX;
282 deltaY = pageY - this.origPageY;
283 }
284 return {
285 origEvent: ev,
286 isTouch: true,
287 subjectEl: this.subjectEl,
288 pageX: pageX,
289 pageY: pageY,
290 deltaX: deltaX,
291 deltaY: deltaY
292 };
293 };
294 return PointerDragging;
295}());
296// Returns a boolean whether this was a left mouse click and no ctrl key (which means right click on Mac)
297function isPrimaryMouseButton(ev) {
298 return ev.button === 0 && !ev.ctrlKey;
299}
300// Ignoring fake mouse events generated by touch
301// ----------------------------------------------------------------------------------------------------
302function startIgnoringMouse() {
303 ignoreMouseDepth++;
304 setTimeout(function () {
305 ignoreMouseDepth--;
306 }, config.touchMouseIgnoreWait);
307}
308// We want to attach touchmove as early as possible for Safari
309// ----------------------------------------------------------------------------------------------------
310function listenerCreated() {
311 if (!(listenerCnt++)) {
312 window.addEventListener('touchmove', onWindowTouchMove, { passive: false });
313 }
314}
315function listenerDestroyed() {
316 if (!(--listenerCnt)) {
317 window.removeEventListener('touchmove', onWindowTouchMove, { passive: false });
318 }
319}
320function onWindowTouchMove(ev) {
321 if (isWindowTouchMoveCancelled) {
322 ev.preventDefault();
323 }
324}
325
326/*
327An effect in which an element follows the movement of a pointer across the screen.
328The moving element is a clone of some other element.
329Must call start + handleMove + stop.
330*/
331var ElementMirror = /** @class */ (function () {
332 function ElementMirror() {
333 this.isVisible = false; // must be explicitly enabled
334 this.sourceEl = null;
335 this.mirrorEl = null;
336 this.sourceElRect = null; // screen coords relative to viewport
337 // options that can be set directly by caller
338 this.parentNode = document.body;
339 this.zIndex = 9999;
340 this.revertDuration = 0;
341 }
342 ElementMirror.prototype.start = function (sourceEl, pageX, pageY) {
343 this.sourceEl = sourceEl;
344 this.sourceElRect = this.sourceEl.getBoundingClientRect();
345 this.origScreenX = pageX - window.pageXOffset;
346 this.origScreenY = pageY - window.pageYOffset;
347 this.deltaX = 0;
348 this.deltaY = 0;
349 this.updateElPosition();
350 };
351 ElementMirror.prototype.handleMove = function (pageX, pageY) {
352 this.deltaX = (pageX - window.pageXOffset) - this.origScreenX;
353 this.deltaY = (pageY - window.pageYOffset) - this.origScreenY;
354 this.updateElPosition();
355 };
356 // can be called before start
357 ElementMirror.prototype.setIsVisible = function (bool) {
358 if (bool) {
359 if (!this.isVisible) {
360 if (this.mirrorEl) {
361 this.mirrorEl.style.display = '';
362 }
363 this.isVisible = bool; // needs to happen before updateElPosition
364 this.updateElPosition(); // because was not updating the position while invisible
365 }
366 }
367 else {
368 if (this.isVisible) {
369 if (this.mirrorEl) {
370 this.mirrorEl.style.display = 'none';
371 }
372 this.isVisible = bool;
373 }
374 }
375 };
376 // always async
377 ElementMirror.prototype.stop = function (needsRevertAnimation, callback) {
378 var _this = this;
379 var done = function () {
380 _this.cleanup();
381 callback();
382 };
383 if (needsRevertAnimation &&
384 this.mirrorEl &&
385 this.isVisible &&
386 this.revertDuration && // if 0, transition won't work
387 (this.deltaX || this.deltaY) // if same coords, transition won't work
388 ) {
389 this.doRevertAnimation(done, this.revertDuration);
390 }
391 else {
392 setTimeout(done, 0);
393 }
394 };
395 ElementMirror.prototype.doRevertAnimation = function (callback, revertDuration) {
396 var mirrorEl = this.mirrorEl;
397 var finalSourceElRect = this.sourceEl.getBoundingClientRect(); // because autoscrolling might have happened
398 mirrorEl.style.transition =
399 'top ' + revertDuration + 'ms,' +
400 'left ' + revertDuration + 'ms';
401 applyStyle(mirrorEl, {
402 left: finalSourceElRect.left,
403 top: finalSourceElRect.top
404 });
405 whenTransitionDone(mirrorEl, function () {
406 mirrorEl.style.transition = '';
407 callback();
408 });
409 };
410 ElementMirror.prototype.cleanup = function () {
411 if (this.mirrorEl) {
412 removeElement(this.mirrorEl);
413 this.mirrorEl = null;
414 }
415 this.sourceEl = null;
416 };
417 ElementMirror.prototype.updateElPosition = function () {
418 if (this.sourceEl && this.isVisible) {
419 applyStyle(this.getMirrorEl(), {
420 left: this.sourceElRect.left + this.deltaX,
421 top: this.sourceElRect.top + this.deltaY
422 });
423 }
424 };
425 ElementMirror.prototype.getMirrorEl = function () {
426 var sourceElRect = this.sourceElRect;
427 var mirrorEl = this.mirrorEl;
428 if (!mirrorEl) {
429 mirrorEl = this.mirrorEl = this.sourceEl.cloneNode(true); // cloneChildren=true
430 // we don't want long taps or any mouse interaction causing selection/menus.
431 // would use preventSelection(), but that prevents selectstart, causing problems.
432 mirrorEl.classList.add('fc-unselectable');
433 mirrorEl.classList.add('fc-dragging');
434 applyStyle(mirrorEl, {
435 position: 'fixed',
436 zIndex: this.zIndex,
437 visibility: '',
438 boxSizing: 'border-box',
439 width: sourceElRect.right - sourceElRect.left,
440 height: sourceElRect.bottom - sourceElRect.top,
441 right: 'auto',
442 bottom: 'auto',
443 margin: 0
444 });
445 this.parentNode.appendChild(mirrorEl);
446 }
447 return mirrorEl;
448 };
449 return ElementMirror;
450}());
451
452/*
453Is a cache for a given element's scroll information (all the info that ScrollController stores)
454in addition the "client rectangle" of the element.. the area within the scrollbars.
455
456The cache can be in one of two modes:
457- doesListening:false - ignores when the container is scrolled by someone else
458- doesListening:true - watch for scrolling and update the cache
459*/
460var ScrollGeomCache = /** @class */ (function (_super) {
461 __extends(ScrollGeomCache, _super);
462 function ScrollGeomCache(scrollController, doesListening) {
463 var _this = _super.call(this) || this;
464 _this.handleScroll = function () {
465 _this.scrollTop = _this.scrollController.getScrollTop();
466 _this.scrollLeft = _this.scrollController.getScrollLeft();
467 _this.handleScrollChange();
468 };
469 _this.scrollController = scrollController;
470 _this.doesListening = doesListening;
471 _this.scrollTop = _this.origScrollTop = scrollController.getScrollTop();
472 _this.scrollLeft = _this.origScrollLeft = scrollController.getScrollLeft();
473 _this.scrollWidth = scrollController.getScrollWidth();
474 _this.scrollHeight = scrollController.getScrollHeight();
475 _this.clientWidth = scrollController.getClientWidth();
476 _this.clientHeight = scrollController.getClientHeight();
477 _this.clientRect = _this.computeClientRect(); // do last in case it needs cached values
478 if (_this.doesListening) {
479 _this.getEventTarget().addEventListener('scroll', _this.handleScroll);
480 }
481 return _this;
482 }
483 ScrollGeomCache.prototype.destroy = function () {
484 if (this.doesListening) {
485 this.getEventTarget().removeEventListener('scroll', this.handleScroll);
486 }
487 };
488 ScrollGeomCache.prototype.getScrollTop = function () {
489 return this.scrollTop;
490 };
491 ScrollGeomCache.prototype.getScrollLeft = function () {
492 return this.scrollLeft;
493 };
494 ScrollGeomCache.prototype.setScrollTop = function (top) {
495 this.scrollController.setScrollTop(top);
496 if (!this.doesListening) {
497 // we are not relying on the element to normalize out-of-bounds scroll values
498 // so we need to sanitize ourselves
499 this.scrollTop = Math.max(Math.min(top, this.getMaxScrollTop()), 0);
500 this.handleScrollChange();
501 }
502 };
503 ScrollGeomCache.prototype.setScrollLeft = function (top) {
504 this.scrollController.setScrollLeft(top);
505 if (!this.doesListening) {
506 // we are not relying on the element to normalize out-of-bounds scroll values
507 // so we need to sanitize ourselves
508 this.scrollLeft = Math.max(Math.min(top, this.getMaxScrollLeft()), 0);
509 this.handleScrollChange();
510 }
511 };
512 ScrollGeomCache.prototype.getClientWidth = function () {
513 return this.clientWidth;
514 };
515 ScrollGeomCache.prototype.getClientHeight = function () {
516 return this.clientHeight;
517 };
518 ScrollGeomCache.prototype.getScrollWidth = function () {
519 return this.scrollWidth;
520 };
521 ScrollGeomCache.prototype.getScrollHeight = function () {
522 return this.scrollHeight;
523 };
524 ScrollGeomCache.prototype.handleScrollChange = function () {
525 };
526 return ScrollGeomCache;
527}(ScrollController));
528var ElementScrollGeomCache = /** @class */ (function (_super) {
529 __extends(ElementScrollGeomCache, _super);
530 function ElementScrollGeomCache(el, doesListening) {
531 return _super.call(this, new ElementScrollController(el), doesListening) || this;
532 }
533 ElementScrollGeomCache.prototype.getEventTarget = function () {
534 return this.scrollController.el;
535 };
536 ElementScrollGeomCache.prototype.computeClientRect = function () {
537 return computeInnerRect(this.scrollController.el);
538 };
539 return ElementScrollGeomCache;
540}(ScrollGeomCache));
541var WindowScrollGeomCache = /** @class */ (function (_super) {
542 __extends(WindowScrollGeomCache, _super);
543 function WindowScrollGeomCache(doesListening) {
544 return _super.call(this, new WindowScrollController(), doesListening) || this;
545 }
546 WindowScrollGeomCache.prototype.getEventTarget = function () {
547 return window;
548 };
549 WindowScrollGeomCache.prototype.computeClientRect = function () {
550 return {
551 left: this.scrollLeft,
552 right: this.scrollLeft + this.clientWidth,
553 top: this.scrollTop,
554 bottom: this.scrollTop + this.clientHeight
555 };
556 };
557 // the window is the only scroll object that changes it's rectangle relative
558 // to the document's topleft as it scrolls
559 WindowScrollGeomCache.prototype.handleScrollChange = function () {
560 this.clientRect = this.computeClientRect();
561 };
562 return WindowScrollGeomCache;
563}(ScrollGeomCache));
564
565// If available we are using native "performance" API instead of "Date"
566// Read more about it on MDN:
567// https://developer.mozilla.org/en-US/docs/Web/API/Performance
568var getTime = typeof performance === 'function' ? performance.now : Date.now;
569/*
570For a pointer interaction, automatically scrolls certain scroll containers when the pointer
571approaches the edge.
572
573The caller must call start + handleMove + stop.
574*/
575var AutoScroller = /** @class */ (function () {
576 function AutoScroller() {
577 var _this = this;
578 // options that can be set by caller
579 this.isEnabled = true;
580 this.scrollQuery = [window, '.fc-scroller'];
581 this.edgeThreshold = 50; // pixels
582 this.maxVelocity = 300; // pixels per second
583 // internal state
584 this.pointerScreenX = null;
585 this.pointerScreenY = null;
586 this.isAnimating = false;
587 this.scrollCaches = null;
588 // protect against the initial pointerdown being too close to an edge and starting the scroll
589 this.everMovedUp = false;
590 this.everMovedDown = false;
591 this.everMovedLeft = false;
592 this.everMovedRight = false;
593 this.animate = function () {
594 if (_this.isAnimating) { // wasn't cancelled between animation calls
595 var edge = _this.computeBestEdge(_this.pointerScreenX + window.pageXOffset, _this.pointerScreenY + window.pageYOffset);
596 if (edge) {
597 var now = getTime();
598 _this.handleSide(edge, (now - _this.msSinceRequest) / 1000);
599 _this.requestAnimation(now);
600 }
601 else {
602 _this.isAnimating = false; // will stop animation
603 }
604 }
605 };
606 }
607 AutoScroller.prototype.start = function (pageX, pageY) {
608 if (this.isEnabled) {
609 this.scrollCaches = this.buildCaches();
610 this.pointerScreenX = null;
611 this.pointerScreenY = null;
612 this.everMovedUp = false;
613 this.everMovedDown = false;
614 this.everMovedLeft = false;
615 this.everMovedRight = false;
616 this.handleMove(pageX, pageY);
617 }
618 };
619 AutoScroller.prototype.handleMove = function (pageX, pageY) {
620 if (this.isEnabled) {
621 var pointerScreenX = pageX - window.pageXOffset;
622 var pointerScreenY = pageY - window.pageYOffset;
623 var yDelta = this.pointerScreenY === null ? 0 : pointerScreenY - this.pointerScreenY;
624 var xDelta = this.pointerScreenX === null ? 0 : pointerScreenX - this.pointerScreenX;
625 if (yDelta < 0) {
626 this.everMovedUp = true;
627 }
628 else if (yDelta > 0) {
629 this.everMovedDown = true;
630 }
631 if (xDelta < 0) {
632 this.everMovedLeft = true;
633 }
634 else if (xDelta > 0) {
635 this.everMovedRight = true;
636 }
637 this.pointerScreenX = pointerScreenX;
638 this.pointerScreenY = pointerScreenY;
639 if (!this.isAnimating) {
640 this.isAnimating = true;
641 this.requestAnimation(getTime());
642 }
643 }
644 };
645 AutoScroller.prototype.stop = function () {
646 if (this.isEnabled) {
647 this.isAnimating = false; // will stop animation
648 for (var _i = 0, _a = this.scrollCaches; _i < _a.length; _i++) {
649 var scrollCache = _a[_i];
650 scrollCache.destroy();
651 }
652 this.scrollCaches = null;
653 }
654 };
655 AutoScroller.prototype.requestAnimation = function (now) {
656 this.msSinceRequest = now;
657 requestAnimationFrame(this.animate);
658 };
659 AutoScroller.prototype.handleSide = function (edge, seconds) {
660 var scrollCache = edge.scrollCache;
661 var edgeThreshold = this.edgeThreshold;
662 var invDistance = edgeThreshold - edge.distance;
663 var velocity = // the closer to the edge, the faster we scroll
664 (invDistance * invDistance) / (edgeThreshold * edgeThreshold) * // quadratic
665 this.maxVelocity * seconds;
666 var sign = 1;
667 switch (edge.name) {
668 case 'left':
669 sign = -1;
670 // falls through
671 case 'right':
672 scrollCache.setScrollLeft(scrollCache.getScrollLeft() + velocity * sign);
673 break;
674 case 'top':
675 sign = -1;
676 // falls through
677 case 'bottom':
678 scrollCache.setScrollTop(scrollCache.getScrollTop() + velocity * sign);
679 break;
680 }
681 };
682 // left/top are relative to document topleft
683 AutoScroller.prototype.computeBestEdge = function (left, top) {
684 var edgeThreshold = this.edgeThreshold;
685 var bestSide = null;
686 for (var _i = 0, _a = this.scrollCaches; _i < _a.length; _i++) {
687 var scrollCache = _a[_i];
688 var rect = scrollCache.clientRect;
689 var leftDist = left - rect.left;
690 var rightDist = rect.right - left;
691 var topDist = top - rect.top;
692 var bottomDist = rect.bottom - top;
693 // completely within the rect?
694 if (leftDist >= 0 && rightDist >= 0 && topDist >= 0 && bottomDist >= 0) {
695 if (topDist <= edgeThreshold && this.everMovedUp && scrollCache.canScrollUp() &&
696 (!bestSide || bestSide.distance > topDist)) {
697 bestSide = { scrollCache: scrollCache, name: 'top', distance: topDist };
698 }
699 if (bottomDist <= edgeThreshold && this.everMovedDown && scrollCache.canScrollDown() &&
700 (!bestSide || bestSide.distance > bottomDist)) {
701 bestSide = { scrollCache: scrollCache, name: 'bottom', distance: bottomDist };
702 }
703 if (leftDist <= edgeThreshold && this.everMovedLeft && scrollCache.canScrollLeft() &&
704 (!bestSide || bestSide.distance > leftDist)) {
705 bestSide = { scrollCache: scrollCache, name: 'left', distance: leftDist };
706 }
707 if (rightDist <= edgeThreshold && this.everMovedRight && scrollCache.canScrollRight() &&
708 (!bestSide || bestSide.distance > rightDist)) {
709 bestSide = { scrollCache: scrollCache, name: 'right', distance: rightDist };
710 }
711 }
712 }
713 return bestSide;
714 };
715 AutoScroller.prototype.buildCaches = function () {
716 return this.queryScrollEls().map(function (el) {
717 if (el === window) {
718 return new WindowScrollGeomCache(false); // false = don't listen to user-generated scrolls
719 }
720 else {
721 return new ElementScrollGeomCache(el, false); // false = don't listen to user-generated scrolls
722 }
723 });
724 };
725 AutoScroller.prototype.queryScrollEls = function () {
726 var els = [];
727 for (var _i = 0, _a = this.scrollQuery; _i < _a.length; _i++) {
728 var query = _a[_i];
729 if (typeof query === 'object') {
730 els.push(query);
731 }
732 else {
733 els.push.apply(els, Array.prototype.slice.call(document.querySelectorAll(query)));
734 }
735 }
736 return els;
737 };
738 return AutoScroller;
739}());
740
741/*
742Monitors dragging on an element. Has a number of high-level features:
743- minimum distance required before dragging
744- minimum wait time ("delay") before dragging
745- a mirror element that follows the pointer
746*/
747var FeaturefulElementDragging = /** @class */ (function (_super) {
748 __extends(FeaturefulElementDragging, _super);
749 function FeaturefulElementDragging(containerEl) {
750 var _this = _super.call(this, containerEl) || this;
751 // options that can be directly set by caller
752 // the caller can also set the PointerDragging's options as well
753 _this.delay = null;
754 _this.minDistance = 0;
755 _this.touchScrollAllowed = true; // prevents drag from starting and blocks scrolling during drag
756 _this.mirrorNeedsRevert = false;
757 _this.isInteracting = false; // is the user validly moving the pointer? lasts until pointerup
758 _this.isDragging = false; // is it INTENTFULLY dragging? lasts until after revert animation
759 _this.isDelayEnded = false;
760 _this.isDistanceSurpassed = false;
761 _this.delayTimeoutId = null;
762 _this.onPointerDown = function (ev) {
763 if (!_this.isDragging) { // so new drag doesn't happen while revert animation is going
764 _this.isInteracting = true;
765 _this.isDelayEnded = false;
766 _this.isDistanceSurpassed = false;
767 preventSelection(document.body);
768 preventContextMenu(document.body);
769 // prevent links from being visited if there's an eventual drag.
770 // also prevents selection in older browsers (maybe?).
771 // not necessary for touch, besides, browser would complain about passiveness.
772 if (!ev.isTouch) {
773 ev.origEvent.preventDefault();
774 }
775 _this.emitter.trigger('pointerdown', ev);
776 if (!_this.pointer.shouldIgnoreMove) {
777 // actions related to initiating dragstart+dragmove+dragend...
778 _this.mirror.setIsVisible(false); // reset. caller must set-visible
779 _this.mirror.start(ev.subjectEl, ev.pageX, ev.pageY); // must happen on first pointer down
780 _this.startDelay(ev);
781 if (!_this.minDistance) {
782 _this.handleDistanceSurpassed(ev);
783 }
784 }
785 }
786 };
787 _this.onPointerMove = function (ev) {
788 if (_this.isInteracting) { // if false, still waiting for previous drag's revert
789 _this.emitter.trigger('pointermove', ev);
790 if (!_this.isDistanceSurpassed) {
791 var minDistance = _this.minDistance;
792 var distanceSq = void 0; // current distance from the origin, squared
793 var deltaX = ev.deltaX, deltaY = ev.deltaY;
794 distanceSq = deltaX * deltaX + deltaY * deltaY;
795 if (distanceSq >= minDistance * minDistance) { // use pythagorean theorem
796 _this.handleDistanceSurpassed(ev);
797 }
798 }
799 if (_this.isDragging) {
800 // a real pointer move? (not one simulated by scrolling)
801 if (ev.origEvent.type !== 'scroll') {
802 _this.mirror.handleMove(ev.pageX, ev.pageY);
803 _this.autoScroller.handleMove(ev.pageX, ev.pageY);
804 }
805 _this.emitter.trigger('dragmove', ev);
806 }
807 }
808 };
809 _this.onPointerUp = function (ev) {
810 if (_this.isInteracting) { // if false, still waiting for previous drag's revert
811 _this.isInteracting = false;
812 allowSelection(document.body);
813 allowContextMenu(document.body);
814 _this.emitter.trigger('pointerup', ev); // can potentially set mirrorNeedsRevert
815 if (_this.isDragging) {
816 _this.autoScroller.stop();
817 _this.tryStopDrag(ev); // which will stop the mirror
818 }
819 if (_this.delayTimeoutId) {
820 clearTimeout(_this.delayTimeoutId);
821 _this.delayTimeoutId = null;
822 }
823 }
824 };
825 var pointer = _this.pointer = new PointerDragging(containerEl);
826 pointer.emitter.on('pointerdown', _this.onPointerDown);
827 pointer.emitter.on('pointermove', _this.onPointerMove);
828 pointer.emitter.on('pointerup', _this.onPointerUp);
829 _this.mirror = new ElementMirror();
830 _this.autoScroller = new AutoScroller();
831 return _this;
832 }
833 FeaturefulElementDragging.prototype.destroy = function () {
834 this.pointer.destroy();
835 };
836 FeaturefulElementDragging.prototype.startDelay = function (ev) {
837 var _this = this;
838 if (typeof this.delay === 'number') {
839 this.delayTimeoutId = setTimeout(function () {
840 _this.delayTimeoutId = null;
841 _this.handleDelayEnd(ev);
842 }, this.delay); // not assignable to number!
843 }
844 else {
845 this.handleDelayEnd(ev);
846 }
847 };
848 FeaturefulElementDragging.prototype.handleDelayEnd = function (ev) {
849 this.isDelayEnded = true;
850 this.tryStartDrag(ev);
851 };
852 FeaturefulElementDragging.prototype.handleDistanceSurpassed = function (ev) {
853 this.isDistanceSurpassed = true;
854 this.tryStartDrag(ev);
855 };
856 FeaturefulElementDragging.prototype.tryStartDrag = function (ev) {
857 if (this.isDelayEnded && this.isDistanceSurpassed) {
858 if (!this.pointer.wasTouchScroll || this.touchScrollAllowed) {
859 this.isDragging = true;
860 this.mirrorNeedsRevert = false;
861 this.autoScroller.start(ev.pageX, ev.pageY);
862 this.emitter.trigger('dragstart', ev);
863 if (this.touchScrollAllowed === false) {
864 this.pointer.cancelTouchScroll();
865 }
866 }
867 }
868 };
869 FeaturefulElementDragging.prototype.tryStopDrag = function (ev) {
870 // .stop() is ALWAYS asynchronous, which we NEED because we want all pointerup events
871 // that come from the document to fire beforehand. much more convenient this way.
872 this.mirror.stop(this.mirrorNeedsRevert, this.stopDrag.bind(this, ev) // bound with args
873 );
874 };
875 FeaturefulElementDragging.prototype.stopDrag = function (ev) {
876 this.isDragging = false;
877 this.emitter.trigger('dragend', ev);
878 };
879 // fill in the implementations...
880 FeaturefulElementDragging.prototype.setIgnoreMove = function (bool) {
881 this.pointer.shouldIgnoreMove = bool;
882 };
883 FeaturefulElementDragging.prototype.setMirrorIsVisible = function (bool) {
884 this.mirror.setIsVisible(bool);
885 };
886 FeaturefulElementDragging.prototype.setMirrorNeedsRevert = function (bool) {
887 this.mirrorNeedsRevert = bool;
888 };
889 FeaturefulElementDragging.prototype.setAutoScrollEnabled = function (bool) {
890 this.autoScroller.isEnabled = bool;
891 };
892 return FeaturefulElementDragging;
893}(ElementDragging));
894
895/*
896When this class is instantiated, it records the offset of an element (relative to the document topleft),
897and continues to monitor scrolling, updating the cached coordinates if it needs to.
898Does not access the DOM after instantiation, so highly performant.
899
900Also keeps track of all scrolling/overflow:hidden containers that are parents of the given element
901and an determine if a given point is inside the combined clipping rectangle.
902*/
903var OffsetTracker = /** @class */ (function () {
904 function OffsetTracker(el) {
905 this.origRect = computeRect(el);
906 // will work fine for divs that have overflow:hidden
907 this.scrollCaches = getClippingParents(el).map(function (el) {
908 return new ElementScrollGeomCache(el, true); // listen=true
909 });
910 }
911 OffsetTracker.prototype.destroy = function () {
912 for (var _i = 0, _a = this.scrollCaches; _i < _a.length; _i++) {
913 var scrollCache = _a[_i];
914 scrollCache.destroy();
915 }
916 };
917 OffsetTracker.prototype.computeLeft = function () {
918 var left = this.origRect.left;
919 for (var _i = 0, _a = this.scrollCaches; _i < _a.length; _i++) {
920 var scrollCache = _a[_i];
921 left += scrollCache.origScrollLeft - scrollCache.getScrollLeft();
922 }
923 return left;
924 };
925 OffsetTracker.prototype.computeTop = function () {
926 var top = this.origRect.top;
927 for (var _i = 0, _a = this.scrollCaches; _i < _a.length; _i++) {
928 var scrollCache = _a[_i];
929 top += scrollCache.origScrollTop - scrollCache.getScrollTop();
930 }
931 return top;
932 };
933 OffsetTracker.prototype.isWithinClipping = function (pageX, pageY) {
934 var point = { left: pageX, top: pageY };
935 for (var _i = 0, _a = this.scrollCaches; _i < _a.length; _i++) {
936 var scrollCache = _a[_i];
937 if (!isIgnoredClipping(scrollCache.getEventTarget()) &&
938 !pointInsideRect(point, scrollCache.clientRect)) {
939 return false;
940 }
941 }
942 return true;
943 };
944 return OffsetTracker;
945}());
946// certain clipping containers should never constrain interactions, like <html> and <body>
947// https://github.com/fullcalendar/fullcalendar/issues/3615
948function isIgnoredClipping(node) {
949 var tagName = node.tagName;
950 return tagName === 'HTML' || tagName === 'BODY';
951}
952
953/*
954Tracks movement over multiple droppable areas (aka "hits")
955that exist in one or more DateComponents.
956Relies on an existing draggable.
957
958emits:
959- pointerdown
960- dragstart
961- hitchange - fires initially, even if not over a hit
962- pointerup
963- (hitchange - again, to null, if ended over a hit)
964- dragend
965*/
966var HitDragging = /** @class */ (function () {
967 function HitDragging(dragging, droppableStore) {
968 var _this = this;
969 // options that can be set by caller
970 this.useSubjectCenter = false;
971 this.requireInitial = true; // if doesn't start out on a hit, won't emit any events
972 this.initialHit = null;
973 this.movingHit = null;
974 this.finalHit = null; // won't ever be populated if shouldIgnoreMove
975 this.handlePointerDown = function (ev) {
976 var dragging = _this.dragging;
977 _this.initialHit = null;
978 _this.movingHit = null;
979 _this.finalHit = null;
980 _this.prepareHits();
981 _this.processFirstCoord(ev);
982 if (_this.initialHit || !_this.requireInitial) {
983 dragging.setIgnoreMove(false);
984 _this.emitter.trigger('pointerdown', ev); // TODO: fire this before computing processFirstCoord, so listeners can cancel. this gets fired by almost every handler :(
985 }
986 else {
987 dragging.setIgnoreMove(true);
988 }
989 };
990 this.handleDragStart = function (ev) {
991 _this.emitter.trigger('dragstart', ev);
992 _this.handleMove(ev, true); // force = fire even if initially null
993 };
994 this.handleDragMove = function (ev) {
995 _this.emitter.trigger('dragmove', ev);
996 _this.handleMove(ev);
997 };
998 this.handlePointerUp = function (ev) {
999 _this.releaseHits();
1000 _this.emitter.trigger('pointerup', ev);
1001 };
1002 this.handleDragEnd = function (ev) {
1003 if (_this.movingHit) {
1004 _this.emitter.trigger('hitupdate', null, true, ev);
1005 }
1006 _this.finalHit = _this.movingHit;
1007 _this.movingHit = null;
1008 _this.emitter.trigger('dragend', ev);
1009 };
1010 this.droppableStore = droppableStore;
1011 dragging.emitter.on('pointerdown', this.handlePointerDown);
1012 dragging.emitter.on('dragstart', this.handleDragStart);
1013 dragging.emitter.on('dragmove', this.handleDragMove);
1014 dragging.emitter.on('pointerup', this.handlePointerUp);
1015 dragging.emitter.on('dragend', this.handleDragEnd);
1016 this.dragging = dragging;
1017 this.emitter = new EmitterMixin();
1018 }
1019 // sets initialHit
1020 // sets coordAdjust
1021 HitDragging.prototype.processFirstCoord = function (ev) {
1022 var origPoint = { left: ev.pageX, top: ev.pageY };
1023 var adjustedPoint = origPoint;
1024 var subjectEl = ev.subjectEl;
1025 var subjectRect;
1026 if (subjectEl !== document) {
1027 subjectRect = computeRect(subjectEl);
1028 adjustedPoint = constrainPoint(adjustedPoint, subjectRect);
1029 }
1030 var initialHit = this.initialHit = this.queryHitForOffset(adjustedPoint.left, adjustedPoint.top);
1031 if (initialHit) {
1032 if (this.useSubjectCenter && subjectRect) {
1033 var slicedSubjectRect = intersectRects(subjectRect, initialHit.rect);
1034 if (slicedSubjectRect) {
1035 adjustedPoint = getRectCenter(slicedSubjectRect);
1036 }
1037 }
1038 this.coordAdjust = diffPoints(adjustedPoint, origPoint);
1039 }
1040 else {
1041 this.coordAdjust = { left: 0, top: 0 };
1042 }
1043 };
1044 HitDragging.prototype.handleMove = function (ev, forceHandle) {
1045 var hit = this.queryHitForOffset(ev.pageX + this.coordAdjust.left, ev.pageY + this.coordAdjust.top);
1046 if (forceHandle || !isHitsEqual(this.movingHit, hit)) {
1047 this.movingHit = hit;
1048 this.emitter.trigger('hitupdate', hit, false, ev);
1049 }
1050 };
1051 HitDragging.prototype.prepareHits = function () {
1052 this.offsetTrackers = mapHash(this.droppableStore, function (interactionSettings) {
1053 interactionSettings.component.buildPositionCaches();
1054 return new OffsetTracker(interactionSettings.el);
1055 });
1056 };
1057 HitDragging.prototype.releaseHits = function () {
1058 var offsetTrackers = this.offsetTrackers;
1059 for (var id in offsetTrackers) {
1060 offsetTrackers[id].destroy();
1061 }
1062 this.offsetTrackers = {};
1063 };
1064 HitDragging.prototype.queryHitForOffset = function (offsetLeft, offsetTop) {
1065 var _a = this, droppableStore = _a.droppableStore, offsetTrackers = _a.offsetTrackers;
1066 var bestHit = null;
1067 for (var id in droppableStore) {
1068 var component = droppableStore[id].component;
1069 var offsetTracker = offsetTrackers[id];
1070 if (offsetTracker.isWithinClipping(offsetLeft, offsetTop)) {
1071 var originLeft = offsetTracker.computeLeft();
1072 var originTop = offsetTracker.computeTop();
1073 var positionLeft = offsetLeft - originLeft;
1074 var positionTop = offsetTop - originTop;
1075 var origRect = offsetTracker.origRect;
1076 var width = origRect.right - origRect.left;
1077 var height = origRect.bottom - origRect.top;
1078 if (
1079 // must be within the element's bounds
1080 positionLeft >= 0 && positionLeft < width &&
1081 positionTop >= 0 && positionTop < height) {
1082 var hit = component.queryHit(positionLeft, positionTop, width, height);
1083 if (hit &&
1084 (
1085 // make sure the hit is within activeRange, meaning it's not a deal cell
1086 !component.props.dateProfile || // hack for DayTile
1087 rangeContainsRange(component.props.dateProfile.activeRange, hit.dateSpan.range)) &&
1088 (!bestHit || hit.layer > bestHit.layer)) {
1089 // TODO: better way to re-orient rectangle
1090 hit.rect.left += originLeft;
1091 hit.rect.right += originLeft;
1092 hit.rect.top += originTop;
1093 hit.rect.bottom += originTop;
1094 bestHit = hit;
1095 }
1096 }
1097 }
1098 }
1099 return bestHit;
1100 };
1101 return HitDragging;
1102}());
1103function isHitsEqual(hit0, hit1) {
1104 if (!hit0 && !hit1) {
1105 return true;
1106 }
1107 if (Boolean(hit0) !== Boolean(hit1)) {
1108 return false;
1109 }
1110 return isDateSpansEqual(hit0.dateSpan, hit1.dateSpan);
1111}
1112
1113/*
1114Monitors when the user clicks on a specific date/time of a component.
1115A pointerdown+pointerup on the same "hit" constitutes a click.
1116*/
1117var DateClicking = /** @class */ (function (_super) {
1118 __extends(DateClicking, _super);
1119 function DateClicking(settings) {
1120 var _this = _super.call(this, settings) || this;
1121 _this.handlePointerDown = function (ev) {
1122 var dragging = _this.dragging;
1123 // do this in pointerdown (not dragend) because DOM might be mutated by the time dragend is fired
1124 dragging.setIgnoreMove(!_this.component.isValidDateDownEl(dragging.pointer.downEl));
1125 };
1126 // won't even fire if moving was ignored
1127 _this.handleDragEnd = function (ev) {
1128 var component = _this.component;
1129 var pointer = _this.dragging.pointer;
1130 if (!pointer.wasTouchScroll) {
1131 var _a = _this.hitDragging, initialHit = _a.initialHit, finalHit = _a.finalHit;
1132 if (initialHit && finalHit && isHitsEqual(initialHit, finalHit)) {
1133 component.calendar.triggerDateClick(initialHit.dateSpan, initialHit.dayEl, component.view, ev.origEvent);
1134 }
1135 }
1136 };
1137 var component = settings.component;
1138 // we DO want to watch pointer moves because otherwise finalHit won't get populated
1139 _this.dragging = new FeaturefulElementDragging(component.el);
1140 _this.dragging.autoScroller.isEnabled = false;
1141 var hitDragging = _this.hitDragging = new HitDragging(_this.dragging, interactionSettingsToStore(settings));
1142 hitDragging.emitter.on('pointerdown', _this.handlePointerDown);
1143 hitDragging.emitter.on('dragend', _this.handleDragEnd);
1144 return _this;
1145 }
1146 DateClicking.prototype.destroy = function () {
1147 this.dragging.destroy();
1148 };
1149 return DateClicking;
1150}(Interaction));
1151
1152/*
1153Tracks when the user selects a portion of time of a component,
1154constituted by a drag over date cells, with a possible delay at the beginning of the drag.
1155*/
1156var DateSelecting = /** @class */ (function (_super) {
1157 __extends(DateSelecting, _super);
1158 function DateSelecting(settings) {
1159 var _this = _super.call(this, settings) || this;
1160 _this.dragSelection = null;
1161 _this.handlePointerDown = function (ev) {
1162 var _a = _this, component = _a.component, dragging = _a.dragging;
1163 var canSelect = component.opt('selectable') &&
1164 component.isValidDateDownEl(ev.origEvent.target);
1165 // don't bother to watch expensive moves if component won't do selection
1166 dragging.setIgnoreMove(!canSelect);
1167 // if touch, require user to hold down
1168 dragging.delay = ev.isTouch ? getComponentTouchDelay(component) : null;
1169 };
1170 _this.handleDragStart = function (ev) {
1171 _this.component.calendar.unselect(ev); // unselect previous selections
1172 };
1173 _this.handleHitUpdate = function (hit, isFinal) {
1174 var calendar = _this.component.calendar;
1175 var dragSelection = null;
1176 var isInvalid = false;
1177 if (hit) {
1178 dragSelection = joinHitsIntoSelection(_this.hitDragging.initialHit, hit, calendar.pluginSystem.hooks.dateSelectionTransformers);
1179 if (!dragSelection || !_this.component.isDateSelectionValid(dragSelection)) {
1180 isInvalid = true;
1181 dragSelection = null;
1182 }
1183 }
1184 if (dragSelection) {
1185 calendar.dispatch({ type: 'SELECT_DATES', selection: dragSelection });
1186 }
1187 else if (!isFinal) { // only unselect if moved away while dragging
1188 calendar.dispatch({ type: 'UNSELECT_DATES' });
1189 }
1190 if (!isInvalid) {
1191 enableCursor();
1192 }
1193 else {
1194 disableCursor();
1195 }
1196 if (!isFinal) {
1197 _this.dragSelection = dragSelection; // only clear if moved away from all hits while dragging
1198 }
1199 };
1200 _this.handlePointerUp = function (pev) {
1201 if (_this.dragSelection) {
1202 // selection is already rendered, so just need to report selection
1203 _this.component.calendar.triggerDateSelect(_this.dragSelection, pev);
1204 _this.dragSelection = null;
1205 }
1206 };
1207 var component = settings.component;
1208 var dragging = _this.dragging = new FeaturefulElementDragging(component.el);
1209 dragging.touchScrollAllowed = false;
1210 dragging.minDistance = component.opt('selectMinDistance') || 0;
1211 dragging.autoScroller.isEnabled = component.opt('dragScroll');
1212 var hitDragging = _this.hitDragging = new HitDragging(_this.dragging, interactionSettingsToStore(settings));
1213 hitDragging.emitter.on('pointerdown', _this.handlePointerDown);
1214 hitDragging.emitter.on('dragstart', _this.handleDragStart);
1215 hitDragging.emitter.on('hitupdate', _this.handleHitUpdate);
1216 hitDragging.emitter.on('pointerup', _this.handlePointerUp);
1217 return _this;
1218 }
1219 DateSelecting.prototype.destroy = function () {
1220 this.dragging.destroy();
1221 };
1222 return DateSelecting;
1223}(Interaction));
1224function getComponentTouchDelay(component) {
1225 var delay = component.opt('selectLongPressDelay');
1226 if (delay == null) {
1227 delay = component.opt('longPressDelay');
1228 }
1229 return delay;
1230}
1231function joinHitsIntoSelection(hit0, hit1, dateSelectionTransformers) {
1232 var dateSpan0 = hit0.dateSpan;
1233 var dateSpan1 = hit1.dateSpan;
1234 var ms = [
1235 dateSpan0.range.start,
1236 dateSpan0.range.end,
1237 dateSpan1.range.start,
1238 dateSpan1.range.end
1239 ];
1240 ms.sort(compareNumbers);
1241 var props = {};
1242 for (var _i = 0, dateSelectionTransformers_1 = dateSelectionTransformers; _i < dateSelectionTransformers_1.length; _i++) {
1243 var transformer = dateSelectionTransformers_1[_i];
1244 var res = transformer(hit0, hit1);
1245 if (res === false) {
1246 return null;
1247 }
1248 else if (res) {
1249 __assign(props, res);
1250 }
1251 }
1252 props.range = { start: ms[0], end: ms[3] };
1253 props.allDay = dateSpan0.allDay;
1254 return props;
1255}
1256
1257var EventDragging = /** @class */ (function (_super) {
1258 __extends(EventDragging, _super);
1259 function EventDragging(settings) {
1260 var _this = _super.call(this, settings) || this;
1261 // internal state
1262 _this.subjectSeg = null; // the seg being selected/dragged
1263 _this.isDragging = false;
1264 _this.eventRange = null;
1265 _this.relevantEvents = null; // the events being dragged
1266 _this.receivingCalendar = null;
1267 _this.validMutation = null;
1268 _this.mutatedRelevantEvents = null;
1269 _this.handlePointerDown = function (ev) {
1270 var origTarget = ev.origEvent.target;
1271 var _a = _this, component = _a.component, dragging = _a.dragging;
1272 var mirror = dragging.mirror;
1273 var initialCalendar = component.calendar;
1274 var subjectSeg = _this.subjectSeg = getElSeg(ev.subjectEl);
1275 var eventRange = _this.eventRange = subjectSeg.eventRange;
1276 var eventInstanceId = eventRange.instance.instanceId;
1277 _this.relevantEvents = getRelevantEvents(initialCalendar.state.eventStore, eventInstanceId);
1278 dragging.minDistance = ev.isTouch ? 0 : component.opt('eventDragMinDistance');
1279 dragging.delay =
1280 // only do a touch delay if touch and this event hasn't been selected yet
1281 (ev.isTouch && eventInstanceId !== component.props.eventSelection) ?
1282 getComponentTouchDelay$1(component) :
1283 null;
1284 mirror.parentNode = initialCalendar.el;
1285 mirror.revertDuration = component.opt('dragRevertDuration');
1286 var isValid = component.isValidSegDownEl(origTarget) &&
1287 !elementClosest(origTarget, '.fc-resizer'); // NOT on a resizer
1288 dragging.setIgnoreMove(!isValid);
1289 // disable dragging for elements that are resizable (ie, selectable)
1290 // but are not draggable
1291 _this.isDragging = isValid &&
1292 ev.subjectEl.classList.contains('fc-draggable');
1293 };
1294 _this.handleDragStart = function (ev) {
1295 var initialCalendar = _this.component.calendar;
1296 var eventRange = _this.eventRange;
1297 var eventInstanceId = eventRange.instance.instanceId;
1298 if (ev.isTouch) {
1299 // need to select a different event?
1300 if (eventInstanceId !== _this.component.props.eventSelection) {
1301 initialCalendar.dispatch({ type: 'SELECT_EVENT', eventInstanceId: eventInstanceId });
1302 }
1303 }
1304 else {
1305 // if now using mouse, but was previous touch interaction, clear selected event
1306 initialCalendar.dispatch({ type: 'UNSELECT_EVENT' });
1307 }
1308 if (_this.isDragging) {
1309 initialCalendar.unselect(ev); // unselect *date* selection
1310 initialCalendar.publiclyTrigger('eventDragStart', [
1311 {
1312 el: _this.subjectSeg.el,
1313 event: new EventApi(initialCalendar, eventRange.def, eventRange.instance),
1314 jsEvent: ev.origEvent,
1315 view: _this.component.view
1316 }
1317 ]);
1318 }
1319 };
1320 _this.handleHitUpdate = function (hit, isFinal) {
1321 if (!_this.isDragging) {
1322 return;
1323 }
1324 var relevantEvents = _this.relevantEvents;
1325 var initialHit = _this.hitDragging.initialHit;
1326 var initialCalendar = _this.component.calendar;
1327 // states based on new hit
1328 var receivingCalendar = null;
1329 var mutation = null;
1330 var mutatedRelevantEvents = null;
1331 var isInvalid = false;
1332 var interaction = {
1333 affectedEvents: relevantEvents,
1334 mutatedEvents: createEmptyEventStore(),
1335 isEvent: true,
1336 origSeg: _this.subjectSeg
1337 };
1338 if (hit) {
1339 var receivingComponent = hit.component;
1340 receivingCalendar = receivingComponent.calendar;
1341 if (initialCalendar === receivingCalendar ||
1342 receivingComponent.opt('editable') && receivingComponent.opt('droppable')) {
1343 mutation = computeEventMutation(initialHit, hit, receivingCalendar.pluginSystem.hooks.eventDragMutationMassagers);
1344 if (mutation) {
1345 mutatedRelevantEvents = applyMutationToEventStore(relevantEvents, receivingCalendar.eventUiBases, mutation, receivingCalendar);
1346 interaction.mutatedEvents = mutatedRelevantEvents;
1347 if (!receivingComponent.isInteractionValid(interaction)) {
1348 isInvalid = true;
1349 mutation = null;
1350 mutatedRelevantEvents = null;
1351 interaction.mutatedEvents = createEmptyEventStore();
1352 }
1353 }
1354 }
1355 else {
1356 receivingCalendar = null;
1357 }
1358 }
1359 _this.displayDrag(receivingCalendar, interaction);
1360 if (!isInvalid) {
1361 enableCursor();
1362 }
1363 else {
1364 disableCursor();
1365 }
1366 if (!isFinal) {
1367 if (initialCalendar === receivingCalendar && // TODO: write test for this
1368 isHitsEqual(initialHit, hit)) {
1369 mutation = null;
1370 }
1371 _this.dragging.setMirrorNeedsRevert(!mutation);
1372 // render the mirror if no already-rendered mirror
1373 // TODO: wish we could somehow wait for dispatch to guarantee render
1374 _this.dragging.setMirrorIsVisible(!hit || !document.querySelector('.fc-mirror'));
1375 // assign states based on new hit
1376 _this.receivingCalendar = receivingCalendar;
1377 _this.validMutation = mutation;
1378 _this.mutatedRelevantEvents = mutatedRelevantEvents;
1379 }
1380 };
1381 _this.handlePointerUp = function () {
1382 if (!_this.isDragging) {
1383 _this.cleanup(); // because handleDragEnd won't fire
1384 }
1385 };
1386 _this.handleDragEnd = function (ev) {
1387 if (_this.isDragging) {
1388 var initialCalendar_1 = _this.component.calendar;
1389 var initialView = _this.component.view;
1390 var _a = _this, receivingCalendar = _a.receivingCalendar, validMutation = _a.validMutation;
1391 var eventDef = _this.eventRange.def;
1392 var eventInstance = _this.eventRange.instance;
1393 var eventApi = new EventApi(initialCalendar_1, eventDef, eventInstance);
1394 var relevantEvents_1 = _this.relevantEvents;
1395 var mutatedRelevantEvents = _this.mutatedRelevantEvents;
1396 var finalHit = _this.hitDragging.finalHit;
1397 _this.clearDrag(); // must happen after revert animation
1398 initialCalendar_1.publiclyTrigger('eventDragStop', [
1399 {
1400 el: _this.subjectSeg.el,
1401 event: eventApi,
1402 jsEvent: ev.origEvent,
1403 view: initialView
1404 }
1405 ]);
1406 if (validMutation) {
1407 // dropped within same calendar
1408 if (receivingCalendar === initialCalendar_1) {
1409 initialCalendar_1.dispatch({
1410 type: 'MERGE_EVENTS',
1411 eventStore: mutatedRelevantEvents
1412 });
1413 var transformed = {};
1414 for (var _i = 0, _b = initialCalendar_1.pluginSystem.hooks.eventDropTransformers; _i < _b.length; _i++) {
1415 var transformer = _b[_i];
1416 __assign(transformed, transformer(validMutation, initialCalendar_1));
1417 }
1418 var eventDropArg = __assign({}, transformed, { el: ev.subjectEl, delta: validMutation.datesDelta, oldEvent: eventApi, event: new EventApi(// the data AFTER the mutation
1419 initialCalendar_1, mutatedRelevantEvents.defs[eventDef.defId], eventInstance ? mutatedRelevantEvents.instances[eventInstance.instanceId] : null), revert: function () {
1420 initialCalendar_1.dispatch({
1421 type: 'MERGE_EVENTS',
1422 eventStore: relevantEvents_1
1423 });
1424 }, jsEvent: ev.origEvent, view: initialView });
1425 initialCalendar_1.publiclyTrigger('eventDrop', [eventDropArg]);
1426 // dropped in different calendar
1427 }
1428 else if (receivingCalendar) {
1429 initialCalendar_1.publiclyTrigger('eventLeave', [
1430 {
1431 draggedEl: ev.subjectEl,
1432 event: eventApi,
1433 view: initialView
1434 }
1435 ]);
1436 initialCalendar_1.dispatch({
1437 type: 'REMOVE_EVENT_INSTANCES',
1438 instances: _this.mutatedRelevantEvents.instances
1439 });
1440 receivingCalendar.dispatch({
1441 type: 'MERGE_EVENTS',
1442 eventStore: _this.mutatedRelevantEvents
1443 });
1444 if (ev.isTouch) {
1445 receivingCalendar.dispatch({
1446 type: 'SELECT_EVENT',
1447 eventInstanceId: eventInstance.instanceId
1448 });
1449 }
1450 var dropArg = __assign({}, receivingCalendar.buildDatePointApi(finalHit.dateSpan), { draggedEl: ev.subjectEl, jsEvent: ev.origEvent, view: finalHit.component // should this be finalHit.component.view? See #4644
1451 });
1452 receivingCalendar.publiclyTrigger('drop', [dropArg]);
1453 receivingCalendar.publiclyTrigger('eventReceive', [
1454 {
1455 draggedEl: ev.subjectEl,
1456 event: new EventApi(// the data AFTER the mutation
1457 receivingCalendar, mutatedRelevantEvents.defs[eventDef.defId], mutatedRelevantEvents.instances[eventInstance.instanceId]),
1458 view: finalHit.component // should this be finalHit.component.view? See #4644
1459 }
1460 ]);
1461 }
1462 }
1463 else {
1464 initialCalendar_1.publiclyTrigger('_noEventDrop');
1465 }
1466 }
1467 _this.cleanup();
1468 };
1469 var component = _this.component;
1470 var dragging = _this.dragging = new FeaturefulElementDragging(component.el);
1471 dragging.pointer.selector = EventDragging.SELECTOR;
1472 dragging.touchScrollAllowed = false;
1473 dragging.autoScroller.isEnabled = component.opt('dragScroll');
1474 var hitDragging = _this.hitDragging = new HitDragging(_this.dragging, interactionSettingsStore);
1475 hitDragging.useSubjectCenter = settings.useEventCenter;
1476 hitDragging.emitter.on('pointerdown', _this.handlePointerDown);
1477 hitDragging.emitter.on('dragstart', _this.handleDragStart);
1478 hitDragging.emitter.on('hitupdate', _this.handleHitUpdate);
1479 hitDragging.emitter.on('pointerup', _this.handlePointerUp);
1480 hitDragging.emitter.on('dragend', _this.handleDragEnd);
1481 return _this;
1482 }
1483 EventDragging.prototype.destroy = function () {
1484 this.dragging.destroy();
1485 };
1486 // render a drag state on the next receivingCalendar
1487 EventDragging.prototype.displayDrag = function (nextCalendar, state) {
1488 var initialCalendar = this.component.calendar;
1489 var prevCalendar = this.receivingCalendar;
1490 // does the previous calendar need to be cleared?
1491 if (prevCalendar && prevCalendar !== nextCalendar) {
1492 // does the initial calendar need to be cleared?
1493 // if so, don't clear all the way. we still need to to hide the affectedEvents
1494 if (prevCalendar === initialCalendar) {
1495 prevCalendar.dispatch({
1496 type: 'SET_EVENT_DRAG',
1497 state: {
1498 affectedEvents: state.affectedEvents,
1499 mutatedEvents: createEmptyEventStore(),
1500 isEvent: true,
1501 origSeg: state.origSeg
1502 }
1503 });
1504 // completely clear the old calendar if it wasn't the initial
1505 }
1506 else {
1507 prevCalendar.dispatch({ type: 'UNSET_EVENT_DRAG' });
1508 }
1509 }
1510 if (nextCalendar) {
1511 nextCalendar.dispatch({ type: 'SET_EVENT_DRAG', state: state });
1512 }
1513 };
1514 EventDragging.prototype.clearDrag = function () {
1515 var initialCalendar = this.component.calendar;
1516 var receivingCalendar = this.receivingCalendar;
1517 if (receivingCalendar) {
1518 receivingCalendar.dispatch({ type: 'UNSET_EVENT_DRAG' });
1519 }
1520 // the initial calendar might have an dummy drag state from displayDrag
1521 if (initialCalendar !== receivingCalendar) {
1522 initialCalendar.dispatch({ type: 'UNSET_EVENT_DRAG' });
1523 }
1524 };
1525 EventDragging.prototype.cleanup = function () {
1526 this.subjectSeg = null;
1527 this.isDragging = false;
1528 this.eventRange = null;
1529 this.relevantEvents = null;
1530 this.receivingCalendar = null;
1531 this.validMutation = null;
1532 this.mutatedRelevantEvents = null;
1533 };
1534 EventDragging.SELECTOR = '.fc-draggable, .fc-resizable'; // TODO: test this in IE11
1535 return EventDragging;
1536}(Interaction));
1537function computeEventMutation(hit0, hit1, massagers) {
1538 var dateSpan0 = hit0.dateSpan;
1539 var dateSpan1 = hit1.dateSpan;
1540 var date0 = dateSpan0.range.start;
1541 var date1 = dateSpan1.range.start;
1542 var standardProps = {};
1543 if (dateSpan0.allDay !== dateSpan1.allDay) {
1544 standardProps.allDay = dateSpan1.allDay;
1545 standardProps.hasEnd = hit1.component.opt('allDayMaintainDuration');
1546 if (dateSpan1.allDay) {
1547 // means date1 is already start-of-day,
1548 // but date0 needs to be converted
1549 date0 = startOfDay(date0);
1550 }
1551 }
1552 var delta = diffDates(date0, date1, hit0.component.dateEnv, hit0.component === hit1.component ?
1553 hit0.component.largeUnit :
1554 null);
1555 if (delta.milliseconds) { // has hours/minutes/seconds
1556 standardProps.allDay = false;
1557 }
1558 var mutation = {
1559 datesDelta: delta,
1560 standardProps: standardProps
1561 };
1562 for (var _i = 0, massagers_1 = massagers; _i < massagers_1.length; _i++) {
1563 var massager = massagers_1[_i];
1564 massager(mutation, hit0, hit1);
1565 }
1566 return mutation;
1567}
1568function getComponentTouchDelay$1(component) {
1569 var delay = component.opt('eventLongPressDelay');
1570 if (delay == null) {
1571 delay = component.opt('longPressDelay');
1572 }
1573 return delay;
1574}
1575
1576var EventDragging$1 = /** @class */ (function (_super) {
1577 __extends(EventDragging, _super);
1578 function EventDragging(settings) {
1579 var _this = _super.call(this, settings) || this;
1580 // internal state
1581 _this.draggingSeg = null; // TODO: rename to resizingSeg? subjectSeg?
1582 _this.eventRange = null;
1583 _this.relevantEvents = null;
1584 _this.validMutation = null;
1585 _this.mutatedRelevantEvents = null;
1586 _this.handlePointerDown = function (ev) {
1587 var component = _this.component;
1588 var seg = _this.querySeg(ev);
1589 var eventRange = _this.eventRange = seg.eventRange;
1590 _this.dragging.minDistance = component.opt('eventDragMinDistance');
1591 // if touch, need to be working with a selected event
1592 _this.dragging.setIgnoreMove(!_this.component.isValidSegDownEl(ev.origEvent.target) ||
1593 (ev.isTouch && _this.component.props.eventSelection !== eventRange.instance.instanceId));
1594 };
1595 _this.handleDragStart = function (ev) {
1596 var calendar = _this.component.calendar;
1597 var eventRange = _this.eventRange;
1598 _this.relevantEvents = getRelevantEvents(calendar.state.eventStore, _this.eventRange.instance.instanceId);
1599 _this.draggingSeg = _this.querySeg(ev);
1600 calendar.unselect();
1601 calendar.publiclyTrigger('eventResizeStart', [
1602 {
1603 el: _this.draggingSeg.el,
1604 event: new EventApi(calendar, eventRange.def, eventRange.instance),
1605 jsEvent: ev.origEvent,
1606 view: _this.component.view
1607 }
1608 ]);
1609 };
1610 _this.handleHitUpdate = function (hit, isFinal, ev) {
1611 var calendar = _this.component.calendar;
1612 var relevantEvents = _this.relevantEvents;
1613 var initialHit = _this.hitDragging.initialHit;
1614 var eventInstance = _this.eventRange.instance;
1615 var mutation = null;
1616 var mutatedRelevantEvents = null;
1617 var isInvalid = false;
1618 var interaction = {
1619 affectedEvents: relevantEvents,
1620 mutatedEvents: createEmptyEventStore(),
1621 isEvent: true,
1622 origSeg: _this.draggingSeg
1623 };
1624 if (hit) {
1625 mutation = computeMutation(initialHit, hit, ev.subjectEl.classList.contains('fc-start-resizer'), eventInstance.range, calendar.pluginSystem.hooks.eventResizeJoinTransforms);
1626 }
1627 if (mutation) {
1628 mutatedRelevantEvents = applyMutationToEventStore(relevantEvents, calendar.eventUiBases, mutation, calendar);
1629 interaction.mutatedEvents = mutatedRelevantEvents;
1630 if (!_this.component.isInteractionValid(interaction)) {
1631 isInvalid = true;
1632 mutation = null;
1633 mutatedRelevantEvents = null;
1634 interaction.mutatedEvents = null;
1635 }
1636 }
1637 if (mutatedRelevantEvents) {
1638 calendar.dispatch({
1639 type: 'SET_EVENT_RESIZE',
1640 state: interaction
1641 });
1642 }
1643 else {
1644 calendar.dispatch({ type: 'UNSET_EVENT_RESIZE' });
1645 }
1646 if (!isInvalid) {
1647 enableCursor();
1648 }
1649 else {
1650 disableCursor();
1651 }
1652 if (!isFinal) {
1653 if (mutation && isHitsEqual(initialHit, hit)) {
1654 mutation = null;
1655 }
1656 _this.validMutation = mutation;
1657 _this.mutatedRelevantEvents = mutatedRelevantEvents;
1658 }
1659 };
1660 _this.handleDragEnd = function (ev) {
1661 var calendar = _this.component.calendar;
1662 var view = _this.component.view;
1663 var eventDef = _this.eventRange.def;
1664 var eventInstance = _this.eventRange.instance;
1665 var eventApi = new EventApi(calendar, eventDef, eventInstance);
1666 var relevantEvents = _this.relevantEvents;
1667 var mutatedRelevantEvents = _this.mutatedRelevantEvents;
1668 calendar.publiclyTrigger('eventResizeStop', [
1669 {
1670 el: _this.draggingSeg.el,
1671 event: eventApi,
1672 jsEvent: ev.origEvent,
1673 view: view
1674 }
1675 ]);
1676 if (_this.validMutation) {
1677 calendar.dispatch({
1678 type: 'MERGE_EVENTS',
1679 eventStore: mutatedRelevantEvents
1680 });
1681 calendar.publiclyTrigger('eventResize', [
1682 {
1683 el: _this.draggingSeg.el,
1684 startDelta: _this.validMutation.startDelta || createDuration(0),
1685 endDelta: _this.validMutation.endDelta || createDuration(0),
1686 prevEvent: eventApi,
1687 event: new EventApi(// the data AFTER the mutation
1688 calendar, mutatedRelevantEvents.defs[eventDef.defId], eventInstance ? mutatedRelevantEvents.instances[eventInstance.instanceId] : null),
1689 revert: function () {
1690 calendar.dispatch({
1691 type: 'MERGE_EVENTS',
1692 eventStore: relevantEvents
1693 });
1694 },
1695 jsEvent: ev.origEvent,
1696 view: view
1697 }
1698 ]);
1699 }
1700 else {
1701 calendar.publiclyTrigger('_noEventResize');
1702 }
1703 // reset all internal state
1704 _this.draggingSeg = null;
1705 _this.relevantEvents = null;
1706 _this.validMutation = null;
1707 // okay to keep eventInstance around. useful to set it in handlePointerDown
1708 };
1709 var component = settings.component;
1710 var dragging = _this.dragging = new FeaturefulElementDragging(component.el);
1711 dragging.pointer.selector = '.fc-resizer';
1712 dragging.touchScrollAllowed = false;
1713 dragging.autoScroller.isEnabled = component.opt('dragScroll');
1714 var hitDragging = _this.hitDragging = new HitDragging(_this.dragging, interactionSettingsToStore(settings));
1715 hitDragging.emitter.on('pointerdown', _this.handlePointerDown);
1716 hitDragging.emitter.on('dragstart', _this.handleDragStart);
1717 hitDragging.emitter.on('hitupdate', _this.handleHitUpdate);
1718 hitDragging.emitter.on('dragend', _this.handleDragEnd);
1719 return _this;
1720 }
1721 EventDragging.prototype.destroy = function () {
1722 this.dragging.destroy();
1723 };
1724 EventDragging.prototype.querySeg = function (ev) {
1725 return getElSeg(elementClosest(ev.subjectEl, this.component.fgSegSelector));
1726 };
1727 return EventDragging;
1728}(Interaction));
1729function computeMutation(hit0, hit1, isFromStart, instanceRange, transforms) {
1730 var dateEnv = hit0.component.dateEnv;
1731 var date0 = hit0.dateSpan.range.start;
1732 var date1 = hit1.dateSpan.range.start;
1733 var delta = diffDates(date0, date1, dateEnv, hit0.component.largeUnit);
1734 var props = {};
1735 for (var _i = 0, transforms_1 = transforms; _i < transforms_1.length; _i++) {
1736 var transform = transforms_1[_i];
1737 var res = transform(hit0, hit1);
1738 if (res === false) {
1739 return null;
1740 }
1741 else if (res) {
1742 __assign(props, res);
1743 }
1744 }
1745 if (isFromStart) {
1746 if (dateEnv.add(instanceRange.start, delta) < instanceRange.end) {
1747 props.startDelta = delta;
1748 return props;
1749 }
1750 }
1751 else {
1752 if (dateEnv.add(instanceRange.end, delta) > instanceRange.start) {
1753 props.endDelta = delta;
1754 return props;
1755 }
1756 }
1757 return null;
1758}
1759
1760var UnselectAuto = /** @class */ (function () {
1761 function UnselectAuto(calendar) {
1762 var _this = this;
1763 this.isRecentPointerDateSelect = false; // wish we could use a selector to detect date selection, but uses hit system
1764 this.onSelect = function (selectInfo) {
1765 if (selectInfo.jsEvent) {
1766 _this.isRecentPointerDateSelect = true;
1767 }
1768 };
1769 this.onDocumentPointerUp = function (pev) {
1770 var _a = _this, calendar = _a.calendar, documentPointer = _a.documentPointer;
1771 var state = calendar.state;
1772 // touch-scrolling should never unfocus any type of selection
1773 if (!documentPointer.wasTouchScroll) {
1774 if (state.dateSelection && // an existing date selection?
1775 !_this.isRecentPointerDateSelect // a new pointer-initiated date selection since last onDocumentPointerUp?
1776 ) {
1777 var unselectAuto = calendar.viewOpt('unselectAuto');
1778 var unselectCancel = calendar.viewOpt('unselectCancel');
1779 if (unselectAuto && (!unselectAuto || !elementClosest(documentPointer.downEl, unselectCancel))) {
1780 calendar.unselect(pev);
1781 }
1782 }
1783 if (state.eventSelection && // an existing event selected?
1784 !elementClosest(documentPointer.downEl, EventDragging.SELECTOR) // interaction DIDN'T start on an event
1785 ) {
1786 calendar.dispatch({ type: 'UNSELECT_EVENT' });
1787 }
1788 }
1789 _this.isRecentPointerDateSelect = false;
1790 };
1791 this.calendar = calendar;
1792 var documentPointer = this.documentPointer = new PointerDragging(document);
1793 documentPointer.shouldIgnoreMove = true;
1794 documentPointer.shouldWatchScroll = false;
1795 documentPointer.emitter.on('pointerup', this.onDocumentPointerUp);
1796 /*
1797 TODO: better way to know about whether there was a selection with the pointer
1798 */
1799 calendar.on('select', this.onSelect);
1800 }
1801 UnselectAuto.prototype.destroy = function () {
1802 this.calendar.off('select', this.onSelect);
1803 this.documentPointer.destroy();
1804 };
1805 return UnselectAuto;
1806}());
1807
1808/*
1809Given an already instantiated draggable object for one-or-more elements,
1810Interprets any dragging as an attempt to drag an events that lives outside
1811of a calendar onto a calendar.
1812*/
1813var ExternalElementDragging = /** @class */ (function () {
1814 function ExternalElementDragging(dragging, suppliedDragMeta) {
1815 var _this = this;
1816 this.receivingCalendar = null;
1817 this.droppableEvent = null; // will exist for all drags, even if create:false
1818 this.suppliedDragMeta = null;
1819 this.dragMeta = null;
1820 this.handleDragStart = function (ev) {
1821 _this.dragMeta = _this.buildDragMeta(ev.subjectEl);
1822 };
1823 this.handleHitUpdate = function (hit, isFinal, ev) {
1824 var dragging = _this.hitDragging.dragging;
1825 var receivingCalendar = null;
1826 var droppableEvent = null;
1827 var isInvalid = false;
1828 var interaction = {
1829 affectedEvents: createEmptyEventStore(),
1830 mutatedEvents: createEmptyEventStore(),
1831 isEvent: _this.dragMeta.create,
1832 origSeg: null
1833 };
1834 if (hit) {
1835 receivingCalendar = hit.component.calendar;
1836 if (_this.canDropElOnCalendar(ev.subjectEl, receivingCalendar)) {
1837 droppableEvent = computeEventForDateSpan(hit.dateSpan, _this.dragMeta, receivingCalendar);
1838 interaction.mutatedEvents = eventTupleToStore(droppableEvent);
1839 isInvalid = !isInteractionValid(interaction, receivingCalendar);
1840 if (isInvalid) {
1841 interaction.mutatedEvents = createEmptyEventStore();
1842 droppableEvent = null;
1843 }
1844 }
1845 }
1846 _this.displayDrag(receivingCalendar, interaction);
1847 // show mirror if no already-rendered mirror element OR if we are shutting down the mirror (?)
1848 // TODO: wish we could somehow wait for dispatch to guarantee render
1849 dragging.setMirrorIsVisible(isFinal || !droppableEvent || !document.querySelector('.fc-mirror'));
1850 if (!isInvalid) {
1851 enableCursor();
1852 }
1853 else {
1854 disableCursor();
1855 }
1856 if (!isFinal) {
1857 dragging.setMirrorNeedsRevert(!droppableEvent);
1858 _this.receivingCalendar = receivingCalendar;
1859 _this.droppableEvent = droppableEvent;
1860 }
1861 };
1862 this.handleDragEnd = function (pev) {
1863 var _a = _this, receivingCalendar = _a.receivingCalendar, droppableEvent = _a.droppableEvent;
1864 _this.clearDrag();
1865 if (receivingCalendar && droppableEvent) {
1866 var finalHit = _this.hitDragging.finalHit;
1867 var finalView = finalHit.component.view;
1868 var dragMeta = _this.dragMeta;
1869 var arg = __assign({}, receivingCalendar.buildDatePointApi(finalHit.dateSpan), { draggedEl: pev.subjectEl, jsEvent: pev.origEvent, view: finalView });
1870 receivingCalendar.publiclyTrigger('drop', [arg]);
1871 if (dragMeta.create) {
1872 receivingCalendar.dispatch({
1873 type: 'MERGE_EVENTS',
1874 eventStore: eventTupleToStore(droppableEvent)
1875 });
1876 if (pev.isTouch) {
1877 receivingCalendar.dispatch({
1878 type: 'SELECT_EVENT',
1879 eventInstanceId: droppableEvent.instance.instanceId
1880 });
1881 }
1882 // signal that an external event landed
1883 receivingCalendar.publiclyTrigger('eventReceive', [
1884 {
1885 draggedEl: pev.subjectEl,
1886 event: new EventApi(receivingCalendar, droppableEvent.def, droppableEvent.instance),
1887 view: finalView
1888 }
1889 ]);
1890 }
1891 }
1892 _this.receivingCalendar = null;
1893 _this.droppableEvent = null;
1894 };
1895 var hitDragging = this.hitDragging = new HitDragging(dragging, interactionSettingsStore);
1896 hitDragging.requireInitial = false; // will start outside of a component
1897 hitDragging.emitter.on('dragstart', this.handleDragStart);
1898 hitDragging.emitter.on('hitupdate', this.handleHitUpdate);
1899 hitDragging.emitter.on('dragend', this.handleDragEnd);
1900 this.suppliedDragMeta = suppliedDragMeta;
1901 }
1902 ExternalElementDragging.prototype.buildDragMeta = function (subjectEl) {
1903 if (typeof this.suppliedDragMeta === 'object') {
1904 return parseDragMeta(this.suppliedDragMeta);
1905 }
1906 else if (typeof this.suppliedDragMeta === 'function') {
1907 return parseDragMeta(this.suppliedDragMeta(subjectEl));
1908 }
1909 else {
1910 return getDragMetaFromEl(subjectEl);
1911 }
1912 };
1913 ExternalElementDragging.prototype.displayDrag = function (nextCalendar, state) {
1914 var prevCalendar = this.receivingCalendar;
1915 if (prevCalendar && prevCalendar !== nextCalendar) {
1916 prevCalendar.dispatch({ type: 'UNSET_EVENT_DRAG' });
1917 }
1918 if (nextCalendar) {
1919 nextCalendar.dispatch({ type: 'SET_EVENT_DRAG', state: state });
1920 }
1921 };
1922 ExternalElementDragging.prototype.clearDrag = function () {
1923 if (this.receivingCalendar) {
1924 this.receivingCalendar.dispatch({ type: 'UNSET_EVENT_DRAG' });
1925 }
1926 };
1927 ExternalElementDragging.prototype.canDropElOnCalendar = function (el, receivingCalendar) {
1928 var dropAccept = receivingCalendar.opt('dropAccept');
1929 if (typeof dropAccept === 'function') {
1930 return dropAccept(el);
1931 }
1932 else if (typeof dropAccept === 'string' && dropAccept) {
1933 return Boolean(elementMatches(el, dropAccept));
1934 }
1935 return true;
1936 };
1937 return ExternalElementDragging;
1938}());
1939// Utils for computing event store from the DragMeta
1940// ----------------------------------------------------------------------------------------------------
1941function computeEventForDateSpan(dateSpan, dragMeta, calendar) {
1942 var defProps = __assign({}, dragMeta.leftoverProps);
1943 for (var _i = 0, _a = calendar.pluginSystem.hooks.externalDefTransforms; _i < _a.length; _i++) {
1944 var transform = _a[_i];
1945 __assign(defProps, transform(dateSpan, dragMeta));
1946 }
1947 var def = parseEventDef(defProps, dragMeta.sourceId, dateSpan.allDay, calendar.opt('forceEventDuration') || Boolean(dragMeta.duration), // hasEnd
1948 calendar);
1949 var start = dateSpan.range.start;
1950 // only rely on time info if drop zone is all-day,
1951 // otherwise, we already know the time
1952 if (dateSpan.allDay && dragMeta.startTime) {
1953 start = calendar.dateEnv.add(start, dragMeta.startTime);
1954 }
1955 var end = dragMeta.duration ?
1956 calendar.dateEnv.add(start, dragMeta.duration) :
1957 calendar.getDefaultEventEnd(dateSpan.allDay, start);
1958 var instance = createEventInstance(def.defId, { start: start, end: end });
1959 return { def: def, instance: instance };
1960}
1961// Utils for extracting data from element
1962// ----------------------------------------------------------------------------------------------------
1963function getDragMetaFromEl(el) {
1964 var str = getEmbeddedElData(el, 'event');
1965 var obj = str ?
1966 JSON.parse(str) :
1967 { create: false }; // if no embedded data, assume no event creation
1968 return parseDragMeta(obj);
1969}
1970config.dataAttrPrefix = '';
1971function getEmbeddedElData(el, name) {
1972 var prefix = config.dataAttrPrefix;
1973 var prefixedName = (prefix ? prefix + '-' : '') + name;
1974 return el.getAttribute('data-' + prefixedName) || '';
1975}
1976
1977/*
1978Makes an element (that is *external* to any calendar) draggable.
1979Can pass in data that determines how an event will be created when dropped onto a calendar.
1980Leverages FullCalendar's internal drag-n-drop functionality WITHOUT a third-party drag system.
1981*/
1982var ExternalDraggable = /** @class */ (function () {
1983 function ExternalDraggable(el, settings) {
1984 var _this = this;
1985 if (settings === void 0) { settings = {}; }
1986 this.handlePointerDown = function (ev) {
1987 var dragging = _this.dragging;
1988 var _a = _this.settings, minDistance = _a.minDistance, longPressDelay = _a.longPressDelay;
1989 dragging.minDistance =
1990 minDistance != null ?
1991 minDistance :
1992 (ev.isTouch ? 0 : globalDefaults.eventDragMinDistance);
1993 dragging.delay =
1994 ev.isTouch ? // TODO: eventually read eventLongPressDelay instead vvv
1995 (longPressDelay != null ? longPressDelay : globalDefaults.longPressDelay) :
1996 0;
1997 };
1998 this.handleDragStart = function (ev) {
1999 if (ev.isTouch &&
2000 _this.dragging.delay &&
2001 ev.subjectEl.classList.contains('fc-event')) {
2002 _this.dragging.mirror.getMirrorEl().classList.add('fc-selected');
2003 }
2004 };
2005 this.settings = settings;
2006 var dragging = this.dragging = new FeaturefulElementDragging(el);
2007 dragging.touchScrollAllowed = false;
2008 if (settings.itemSelector != null) {
2009 dragging.pointer.selector = settings.itemSelector;
2010 }
2011 if (settings.appendTo != null) {
2012 dragging.mirror.parentNode = settings.appendTo; // TODO: write tests
2013 }
2014 dragging.emitter.on('pointerdown', this.handlePointerDown);
2015 dragging.emitter.on('dragstart', this.handleDragStart);
2016 new ExternalElementDragging(dragging, settings.eventData);
2017 }
2018 ExternalDraggable.prototype.destroy = function () {
2019 this.dragging.destroy();
2020 };
2021 return ExternalDraggable;
2022}());
2023
2024/*
2025Detects when a *THIRD-PARTY* drag-n-drop system interacts with elements.
2026The third-party system is responsible for drawing the visuals effects of the drag.
2027This class simply monitors for pointer movements and fires events.
2028It also has the ability to hide the moving element (the "mirror") during the drag.
2029*/
2030var InferredElementDragging = /** @class */ (function (_super) {
2031 __extends(InferredElementDragging, _super);
2032 function InferredElementDragging(containerEl) {
2033 var _this = _super.call(this, containerEl) || this;
2034 _this.shouldIgnoreMove = false;
2035 _this.mirrorSelector = '';
2036 _this.currentMirrorEl = null;
2037 _this.handlePointerDown = function (ev) {
2038 _this.emitter.trigger('pointerdown', ev);
2039 if (!_this.shouldIgnoreMove) {
2040 // fire dragstart right away. does not support delay or min-distance
2041 _this.emitter.trigger('dragstart', ev);
2042 }
2043 };
2044 _this.handlePointerMove = function (ev) {
2045 if (!_this.shouldIgnoreMove) {
2046 _this.emitter.trigger('dragmove', ev);
2047 }
2048 };
2049 _this.handlePointerUp = function (ev) {
2050 _this.emitter.trigger('pointerup', ev);
2051 if (!_this.shouldIgnoreMove) {
2052 // fire dragend right away. does not support a revert animation
2053 _this.emitter.trigger('dragend', ev);
2054 }
2055 };
2056 var pointer = _this.pointer = new PointerDragging(containerEl);
2057 pointer.emitter.on('pointerdown', _this.handlePointerDown);
2058 pointer.emitter.on('pointermove', _this.handlePointerMove);
2059 pointer.emitter.on('pointerup', _this.handlePointerUp);
2060 return _this;
2061 }
2062 InferredElementDragging.prototype.destroy = function () {
2063 this.pointer.destroy();
2064 };
2065 InferredElementDragging.prototype.setIgnoreMove = function (bool) {
2066 this.shouldIgnoreMove = bool;
2067 };
2068 InferredElementDragging.prototype.setMirrorIsVisible = function (bool) {
2069 if (bool) {
2070 // restore a previously hidden element.
2071 // use the reference in case the selector class has already been removed.
2072 if (this.currentMirrorEl) {
2073 this.currentMirrorEl.style.visibility = '';
2074 this.currentMirrorEl = null;
2075 }
2076 }
2077 else {
2078 var mirrorEl = this.mirrorSelector ?
2079 document.querySelector(this.mirrorSelector) :
2080 null;
2081 if (mirrorEl) {
2082 this.currentMirrorEl = mirrorEl;
2083 mirrorEl.style.visibility = 'hidden';
2084 }
2085 }
2086 };
2087 return InferredElementDragging;
2088}(ElementDragging));
2089
2090/*
2091Bridges third-party drag-n-drop systems with FullCalendar.
2092Must be instantiated and destroyed by caller.
2093*/
2094var ThirdPartyDraggable = /** @class */ (function () {
2095 function ThirdPartyDraggable(containerOrSettings, settings) {
2096 var containerEl = document;
2097 if (
2098 // wish we could just test instanceof EventTarget, but doesn't work in IE11
2099 containerOrSettings === document ||
2100 containerOrSettings instanceof Element) {
2101 containerEl = containerOrSettings;
2102 settings = settings || {};
2103 }
2104 else {
2105 settings = (containerOrSettings || {});
2106 }
2107 var dragging = this.dragging = new InferredElementDragging(containerEl);
2108 if (typeof settings.itemSelector === 'string') {
2109 dragging.pointer.selector = settings.itemSelector;
2110 }
2111 else if (containerEl === document) {
2112 dragging.pointer.selector = '[data-event]';
2113 }
2114 if (typeof settings.mirrorSelector === 'string') {
2115 dragging.mirrorSelector = settings.mirrorSelector;
2116 }
2117 new ExternalElementDragging(dragging, settings.eventData);
2118 }
2119 ThirdPartyDraggable.prototype.destroy = function () {
2120 this.dragging.destroy();
2121 };
2122 return ThirdPartyDraggable;
2123}());
2124
2125var main = createPlugin({
2126 componentInteractions: [DateClicking, DateSelecting, EventDragging, EventDragging$1],
2127 calendarInteractions: [UnselectAuto],
2128 elementDraggingImpl: FeaturefulElementDragging
2129});
2130
2131export default main;
2132export { ExternalDraggable as Draggable, FeaturefulElementDragging, PointerDragging, ThirdPartyDraggable };