Skip to content

Commit

Permalink
fix: Prevent drag event from being ignored
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewmullin01 committed Feb 7, 2023
1 parent e958128 commit db0c0d1
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions packages/core/src/NodeView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,12 @@ export class NodeView<
return false
}

const isDragEvent = event.type.startsWith('drag')
const isDropEvent = event.type === 'drop'
const isInput = ['INPUT', 'BUTTON', 'SELECT', 'TEXTAREA'].includes(target.tagName) || target.isContentEditable

// any input event within node views should be ignored by ProseMirror
if (isInput && !isDropEvent) {
if (isInput && !isDropEvent && !isDragEvent) {
return true
}

Expand All @@ -129,7 +130,6 @@ export class NodeView<
const isPasteEvent = event.type === 'paste'
const isCutEvent = event.type === 'cut'
const isClickEvent = event.type === 'mousedown'
const isDragEvent = event.type.startsWith('drag')

// ProseMirror tries to drag selectable nodes
// even if `draggable` is set to `false`
Expand All @@ -151,21 +151,17 @@ export class NodeView<
if (isValidDragHandle) {
this.isDragging = true

document.addEventListener(
'dragend',
() => {
this.isDragging = false
},
{ once: true },
)

document.addEventListener(
'mouseup',
() => {
this.isDragging = false
},
{ once: true },
)
document.addEventListener('dragend', () => {
this.isDragging = false
}, { once: true })

document.addEventListener('drop', () => {
this.isDragging = false
}, { once: true })

document.addEventListener('mouseup', () => {
this.isDragging = false
}, { once: true })
}
}

Expand Down

0 comments on commit db0c0d1

Please sign in to comment.