| 1 |
import { PointerDragEvent, ElementDragging } from '@fullcalendar/core/internal' |
| 2 |
import { PointerDragging } from '../dnd/PointerDragging.js' |
| 3 |
|
| 4 |
/* |
| 5 |
Detects when a *THIRD-PARTY* drag-n-drop system interacts with elements. |
| 6 |
The third-party system is responsible for drawing the visuals effects of the drag. |
| 7 |
This class simply monitors for pointer movements and fires events. |
| 8 |
It also has the ability to hide the moving element (the "mirror") during the drag. |
| 9 |
*/ |
| 10 |
export class InferredElementDragging extends ElementDragging { |
| 11 |
pointer: PointerDragging |
| 12 |
shouldIgnoreMove: boolean = false |
| 13 |
mirrorSelector: string = '' |
| 14 |
currentMirrorEl: HTMLElement | null = null |
| 15 |
|
| 16 |
constructor(containerEl: HTMLElement) { |
| 17 |
super(containerEl) |
| 18 |
|
| 19 |
let pointer = this.pointer = new PointerDragging(containerEl) |
| 20 |
pointer.emitter.on('pointerdown', this.handlePointerDown) |
| 21 |
pointer.emitter.on('pointermove', this.handlePointerMove) |
| 22 |
pointer.emitter.on('pointerup', this.handlePointerUp) |
| 23 |
} |
| 24 |
|
| 25 |
destroy() { |
| 26 |
this.pointer.destroy() |
| 27 |
} |
| 28 |
|
| 29 |
handlePointerDown = (ev: PointerDragEvent) => { |
| 30 |
this.emitter.trigger('pointerdown', ev) |
| 31 |
|
| 32 |
if (!this.shouldIgnoreMove) { |
| 33 |
// fire dragstart right away. does not support delay or min-distance |
| 34 |
this.emitter.trigger('dragstart', ev) |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
handlePointerMove = (ev: PointerDragEvent) => { |
| 39 |
if (!this.shouldIgnoreMove) { |
| 40 |
this.emitter.trigger('dragmove', ev) |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
handlePointerUp = (ev: PointerDragEvent) => { |
| 45 |
this.emitter.trigger('pointerup', ev) |
| 46 |
|
| 47 |
if (!this.shouldIgnoreMove) { |
| 48 |
// fire dragend right away. does not support a revert animation |
| 49 |
this.emitter.trigger('dragend', ev) |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
setIgnoreMove(bool: boolean) { |
| 54 |
this.shouldIgnoreMove = bool |
| 55 |
} |
| 56 |
|
| 57 |
setMirrorIsVisible(bool: boolean) { |
| 58 |
if (bool) { |
| 59 |
// restore a previously hidden element. |
| 60 |
// use the reference in case the selector class has already been removed. |
| 61 |
if (this.currentMirrorEl) { |
| 62 |
this.currentMirrorEl.style.visibility = '' |
| 63 |
this.currentMirrorEl = null |
| 64 |
} |
| 65 |
} else { |
| 66 |
let mirrorEl = this.mirrorSelector |
| 67 |
// TODO: somehow query FullCalendars WITHIN shadow-roots |
| 68 |
? document.querySelector(this.mirrorSelector) as HTMLElement |
| 69 |
: null |
| 70 |
|
| 71 |
if (mirrorEl) { |
| 72 |
this.currentMirrorEl = mirrorEl |
| 73 |
mirrorEl.style.visibility = 'hidden' |
| 74 |
} |
| 75 |
} |
| 76 |
} |
| 77 |
} |