try to improve drag handling
This commit is contained in:
@@ -46,6 +46,7 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
|
console.log('MOUNTED')
|
||||||
// setInterval(() => {
|
// setInterval(() => {
|
||||||
// this.random = `foo${Math.random()}`
|
// this.random = `foo${Math.random()}`
|
||||||
// }, 1000)
|
// }, 1000)
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ class VueNodeView implements NodeView {
|
|||||||
this.getPos = props.getPos
|
this.getPos = props.getPos
|
||||||
this.createUniqueId()
|
this.createUniqueId()
|
||||||
this.mount(component)
|
this.mount(component)
|
||||||
|
|
||||||
|
document.addEventListener('dragend', this.onDragEnd)
|
||||||
}
|
}
|
||||||
|
|
||||||
createUniqueId() {
|
createUniqueId() {
|
||||||
@@ -151,6 +153,15 @@ class VueNodeView implements NodeView {
|
|||||||
const isCutEvent = event.type === 'cut'
|
const isCutEvent = event.type === 'cut'
|
||||||
const isDragEvent = event.type.startsWith('drag') || event.type === 'drop'
|
const isDragEvent = event.type.startsWith('drag') || event.type === 'drop'
|
||||||
|
|
||||||
|
const isInElement = this.dom.contains(target) && !this.contentDOM?.contains(target)
|
||||||
|
|
||||||
|
// console.log({ isInElement })
|
||||||
|
if (!isInElement) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// console.log(this.isDragging, event.type)
|
||||||
|
|
||||||
if (isDragEvent && !this.isDragging) {
|
if (isDragEvent && !this.isDragging) {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
}
|
}
|
||||||
@@ -164,9 +175,21 @@ class VueNodeView implements NodeView {
|
|||||||
|
|
||||||
if (isValidDragHandle) {
|
if (isValidDragHandle) {
|
||||||
this.isDragging = true
|
this.isDragging = true
|
||||||
document.addEventListener('dragend', () => {
|
// document.addEventListener('dragend', (e: Event) => {
|
||||||
this.isDragging = false
|
// console.log('DRAGEEEND')
|
||||||
}, { once: true })
|
// // const t = (e.target as HTMLElement)
|
||||||
|
// // if (t === this.dom) {
|
||||||
|
// // console.log('JEP')
|
||||||
|
// // } else {
|
||||||
|
// // console.log('NOPE')
|
||||||
|
// // }
|
||||||
|
// // // if (t === this.dom) {
|
||||||
|
// // // this.isDragging = false
|
||||||
|
// // // }
|
||||||
|
// this.isDragging = false
|
||||||
|
// }, { once: true })
|
||||||
|
console.log('BIND EVENT', this.dom)
|
||||||
|
// document.addEventListener('dragend', this.onDragEnd, { once: true })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,6 +200,18 @@ class VueNodeView implements NodeView {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onDragEnd(event: Event) {
|
||||||
|
console.log('ONDRAGEND')
|
||||||
|
const target = (event.target as HTMLElement)
|
||||||
|
|
||||||
|
if (target === this.dom) {
|
||||||
|
console.log('JEP')
|
||||||
|
this.isDragging = false
|
||||||
|
} else {
|
||||||
|
console.log('NOPE')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ignoreMutation(mutation: MutationRecord | { type: 'selection'; target: Element }) {
|
ignoreMutation(mutation: MutationRecord | { type: 'selection'; target: Element }) {
|
||||||
if (mutation.type === 'selection') {
|
if (mutation.type === 'selection') {
|
||||||
return true
|
return true
|
||||||
@@ -204,6 +239,11 @@ class VueNodeView implements NodeView {
|
|||||||
// })
|
// })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
destroy() {
|
||||||
|
this.vm.$destroy()
|
||||||
|
document.removeEventListener('dragend', this.onDragEnd)
|
||||||
|
}
|
||||||
|
|
||||||
update(node: ProseMirrorNode, decorations: Decoration[]) {
|
update(node: ProseMirrorNode, decorations: Decoration[]) {
|
||||||
if (node.type !== this.node.type) {
|
if (node.type !== this.node.type) {
|
||||||
return false
|
return false
|
||||||
|
|||||||
Reference in New Issue
Block a user