Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add utility helper to reduce redunandacy when enabling default drag b…
…ehavior
- Loading branch information
Showing
3 changed files
with
30 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* Helper to configure datatransfer for drag & drop operations | ||
*/ | ||
import { useEventStore } from "stores/eventStore"; | ||
|
||
export function setDrag(evt, data = null) { | ||
const eventStore = useEventStore(); | ||
if (data) { | ||
evt.dataTransfer.setData("text", JSON.stringify([data])); | ||
// data submitted through datatransfer is only available upon drop, | ||
// in order to access the drop data immediately this event store is used. | ||
eventStore.setDragData(data); | ||
} | ||
evt.dataTransfer.dropEffect = "move"; | ||
evt.dataTransfer.effectAllowed = "move"; | ||
const elem = document.getElementById("drag-ghost"); | ||
evt.dataTransfer.setDragImage(elem, 0, 0); | ||
} | ||
|
||
export function clearDrag() { | ||
const eventStore = useEventStore(); | ||
eventStore.clearDragData(data); | ||
} |