1.0.6 • Published 7 years ago
dnd-details v1.0.6
dnd-details
Takes a DragEvent object and returns information about the dropped content.
Installation
yarn add dnd-detailsResources
Usage
import dndDetails from 'dnd-details';
...
onDrop(event) {
const details = dndDetails(event);
console.log(details);
}Returned object
The returned object has the shape
export interface IDropDetails {
files: FileList;
links: string[];
images: string[];
text: string;
html: string;
}Dragging from desktop
When files were dragged in from the local filesystem, the files list will be populated.
None of the other values will be populated.
Dragging from other browser windows
When dragging content from other browser windows, the files list will always be empty, but several of the other values will be populated.
- When a single link is dragged,
textshould contain the displayed text of the link, andlinksshould have one entry with thehrefURL of the link - When a single image is dragged,
imagesshould have one entry with thesrcURL of the image - When a linked image is dragged, both
linksandimagesshould be populated - When dragging in entire websites, e.g.
Ctrl+Athen drag and drop, you might have the data for many images and links - The
linksandimagesarrays will always exist, even if they're empty. So it's safe write code likeif (details.images.length > 0)and you don't needif (details.images && details.images.length > 0)