@fullcalendar/interaction 5.11.3 → 6.0.0-beta.2

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