This repository was archived by the owner on Jun 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 96
Feature request: Support native folder drop #8
Labels
Comments
👍 |
@vgatto thank you for this monkey patch! |
@vgatto really thank you for this path |
Doesn't work for me :( |
danii1
pushed a commit
to danii1/react-dnd-html5-backend
that referenced
this issue
Aug 2, 2017
Prevent access denied from crashing, and add logging We have [a very bad Firefox dnd bug](https://app.asana.com/0/148675973320328/334924376407244) that's coming from this library. I don't fully understand what's causing this yet, and we're not able to repro. This commit prevents it from crashing when this error happens, and logs what is being dragged. Looks like we had a similar bug fix before (react-dnd#4). Assigning to @Josh211ua since you reviewed that change and hopefully have some context. cc @epelz as previous ReactDnd AoR holder. https://app.asana.com/0/1149204378422/334924376407244
thanks @vgatto your sample was a great help. I created html-dir-content to help with the traversing of folder structure and your code helped me tie them together. In case someone ends up with a use case such as mine, here's what i ended up with: //dndBackendWithFolderSupport.js
import HTML5Backend from "react-dnd-html5-backend";
import {getFilesFromDragEvent} from "html-dir-content";
export default (manager: Object) => {
const backend = HTML5Backend(manager),
orgTopDropCapture = backend.handleTopDropCapture;
backend.handleTopDropCapture = (e) => {
orgTopDropCapture.call(backend, e);
backend.currentNativeSource.item.dirContent = getFilesFromDragEvent(e); //returns a promise
};
return backend;
}
//my component
const dndSpec = {
drop(props: Props, monitor: { getItem: () => any }) {
const dndItem = monitor.getItem();
if (dndItem) {
if (dndItem.urls && dndItem.urls.length) {
//handle urls
}
else {
dndItem.dirContent.then((files: Object[]) => {
if (files.length){
// handle dragged folder(s)
}
else if (dndItem.files && dndItem.files.length){
//handle dragged files
}
});
}
}
return {
dndFinished: true
};
},
};
|
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Currently, the native drag source for Files only extracts "files" from the data transfer object. In order to use Chrome's support for folders and folder traversal, it would be nice to have the "items" as well.
I've been able to monkey patch the HTML5Backend to pass along what I need.
The text was updated successfully, but these errors were encountered: