2022-04-15 14:24:30 +00:00
|
|
|
import { Directive } from 'vue'
|
|
|
|
|
|
|
|
export const droppable: Directive = {
|
2022-04-30 13:20:47 +00:00
|
|
|
created: (el: HTMLElement, binding) => {
|
2022-04-25 16:38:33 +00:00
|
|
|
el.addEventListener('dragenter', (event: DragEvent) => {
|
2022-04-15 14:24:30 +00:00
|
|
|
event.preventDefault()
|
2022-07-25 12:57:58 +00:00
|
|
|
el.classList.add('droppable')
|
2022-04-15 14:24:30 +00:00
|
|
|
event.dataTransfer!.dropEffect = 'move'
|
|
|
|
|
|
|
|
return false
|
|
|
|
})
|
|
|
|
|
2022-04-30 13:20:47 +00:00
|
|
|
el.addEventListener('dragover', (event: DragEvent) => event.preventDefault())
|
2022-07-25 12:57:58 +00:00
|
|
|
el.addEventListener('dragleave', () => el.classList.remove('droppable'))
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-04-25 16:38:33 +00:00
|
|
|
el.addEventListener('drop', (event: DragEvent) => {
|
2022-04-15 14:24:30 +00:00
|
|
|
event.preventDefault()
|
|
|
|
event.stopPropagation()
|
2022-07-25 12:57:58 +00:00
|
|
|
el.classList.remove('droppable')
|
2022-04-30 13:20:47 +00:00
|
|
|
binding.value(event)
|
2022-04-15 14:24:30 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|