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