@rtorcato/browser-common / draganddrop
draganddrop
Functions
enableFileDrop()
enableFileDrop(
element,onDrop): () =>void
Defined in: draganddrop/index.ts:44
Adds drag-and-drop event listeners to an element for basic file drop support.
Example
import { enableFileDrop } from '@rtorcato/browser-common/draganddrop'
const off = enableFileDrop(dropzone, (files) => upload(files))
off()
Parameters
element
HTMLElement
The element to attach listeners to.
onDrop
(files) => void
Callback for when files are dropped.
Returns
A function that removes the listeners.
() => void
makeDraggable()
makeDraggable(
element,data,effectAllowed?): () =>void
Defined in: draganddrop/index.ts:69
Sets up an element as draggable and attaches dragstart event.
Example
import { makeDraggable } from '@rtorcato/browser-common/draganddrop'
const off = makeDraggable(card, 'card-42')
off()
Parameters
element
HTMLElement
The element to make draggable.
data
string
The data to set for the drag event.
effectAllowed?
"link" | "none" | "copy" | "copyLink" | "copyMove" | "linkMove" | "move" | "all" | "uninitialized"
The allowed drag effect (e.g., 'move', 'copy').
Returns
A function that removes the listener and the draggable attribute.
() => void
enableTextDrop()
enableTextDrop(
element,onDrop): () =>void
Defined in: draganddrop/index.ts:101
Adds a drop target for plain text data.
Example
import { enableTextDrop } from '@rtorcato/browser-common/draganddrop'
const off = enableTextDrop(zone, (text) => console.log(text))
off()
Parameters
element
HTMLElement
The element to act as a drop target.
onDrop
(text) => void
Callback for when text is dropped.
Returns
A function that removes the listeners.
() => void
disableDragAndDrop()
disableDragAndDrop(
element):void
Defined in: draganddrop/index.ts:120
Removes drag-and-drop event listeners from an element.
Example
import { disableDragAndDrop } from '@rtorcato/browser-common/draganddrop'
disableDragAndDrop(dropzone)
Parameters
element
HTMLElement
The element to remove listeners from.
Returns
void
Deprecated
Call the cleanup function returned by enableFileDrop, enableTextDrop or
makeDraggable instead. This replaces the element with a clone, which strips every listener
on it (including other code's) and leaves existing references pointing at a detached node.