Adam Shaw 7 лет назад
Родитель
Сommit
64249a41fe
3 измененных файлов с 22 добавлено и 9 удалено
  1. 11 5
      src/dnd/ElementMirror.ts
  2. 10 4
      src/dnd/PointerDragging.ts
  3. 1 0
      src/interactions/EventDragging.ts

+ 11 - 5
src/dnd/ElementMirror.ts

@@ -67,19 +67,25 @@ export default class ElementMirror {
       callback()
     }
 
-    if (needsRevertAnimation && this.mirrorEl && this.isVisible) {
-      this.doRevertAnimation(done)
+    if (
+      needsRevertAnimation &&
+      this.mirrorEl &&
+      this.isVisible &&
+      this.revertDuration && // if 0, transition won't work
+      (this.deltaX || this.deltaY) // if same coords, transition won't work
+    ) {
+      this.doRevertAnimation(done, this.revertDuration)
     } else {
       setTimeout(done, 0)
     }
   }
 
-  doRevertAnimation(callback: () => void) {
+  doRevertAnimation(callback: () => void, revertDuration: number) {
     let mirrorEl = this.mirrorEl!
 
     mirrorEl.style.transition =
-      'top ' + this.revertDuration + 'ms,' +
-      'left ' + this.revertDuration + 'ms'
+      'top ' + revertDuration + 'ms,' +
+      'left ' + revertDuration + 'ms'
 
     applyStyle(mirrorEl, {
       left: this.sourceElRect!.left,

+ 10 - 4
src/dnd/PointerDragging.ts

@@ -44,14 +44,14 @@ export default class PointerDragging {
   constructor(containerEl: EventTarget) {
     this.containerEl = containerEl
     this.emitter = new EmitterMixin()
-    containerEl.addEventListener('mousedown', this.handleMouseDown)
-    containerEl.addEventListener('touchstart', this.handleTouchStart)
+    containerEl.addEventListener('mousedown', this.handleMouseDown as EventListener)
+    containerEl.addEventListener('touchstart', this.handleTouchStart as EventListener)
     listenerCreated()
   }
 
   destroy() {
-    this.containerEl.removeEventListener('mousedown', this.handleMouseDown)
-    this.containerEl.removeEventListener('touchstart', this.handleTouchStart)
+    this.containerEl.removeEventListener('mousedown', this.handleMouseDown as EventListener)
+    this.containerEl.removeEventListener('touchstart', this.handleTouchStart as EventListener)
     listenerDestroyed()
   }
 
@@ -67,6 +67,7 @@ export default class PointerDragging {
       this.downEl = downEl
       this.isDragging = true // do this first so cancelTouchScroll will work
       this.wasTouchScroll = false
+
       return true
     }
 
@@ -99,6 +100,11 @@ export default class PointerDragging {
       isPrimaryMouseButton(ev) &&
       this.tryStart(ev)
     ) {
+      // prevent links from being visited if there's an eventual drag.
+      // also prevents selection in older browsers (maybe?).
+      // not necessary for touch, besides, browser would complain about passiveness.
+      ev.preventDefault()
+
       this.emitter.trigger('pointerdown', createEventFromMouse(ev, this.subjectEl!))
 
       if (!this.shouldIgnoreMove) {

+ 1 - 0
src/interactions/EventDragging.ts

@@ -43,6 +43,7 @@ export default class EventDragging {
   onPointerDown = (ev: PointerDragEvent) => {
     let { dragging } = this
 
+    dragging.minDistance = 5
     dragging.delay = this.computeDragDelay(ev)
 
     // to prevent from cloning the sourceEl before it is selected