New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set meta based on drop target event #2973
Conversation
…t on dragover. Added new option setMeta to enable setting specific meta fields depending on the drop event. This enables using one DropTarget with body as target with the meta fields being set depending on which DOM element the files was dropped.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for sending this. Would you be able to write tests for these options?
Simplify adding meta fields from setMeta in addFiles function. Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
….(file, event)` added.
Allow setMeta to be optional. Using more descriptive type for the setMeta option. Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
const descriptors = files.map((file) => { | ||
return { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason not to use the shorter form as before?
const descriptors = files.map((file) => { | |
return { | |
const descriptors = files.map((file) => ({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I'll fix this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a few questions/concerns about these changes.
- Why isn't
uppy.setFileMeta
enough for your use case? - Do we need
activeClass
? If you want custom styles, can't you target the existing class and override it?
What I needed was a way to set the file meta depending on which dom node the file was dropped. To do this I needed to get access to the drag event object which is why I implemented the setMeta hook, which includes the drag event. We have a small screencast of the functionality: https://share.iogates.com/show/511557/343338-34ys4uatjh0xhvhc
Our web app is old and we are using uppy in the traditional way, as a global library. It was easier for us to change the CSS changes by effectively disabling the default behaviour by changing the active class name. |
I think you could indeed achieve what you are trying to do by subclassing the class MyDropTarget extends DropTarget {
install(...args) {
const { addFiles, handleDrop } = this;
this.addFiles = (files) => {
addFiles(files);
return files;
};
this.handleDrop = (event) =>
handleDrop(event).then((files) => {
/* here you have access to `files`, `event`, and `uppy.setFileMeta` */
});
return super.install(...args);
}
}
uppy.use(MyDropTarget, {
target: document.body,
}); For the |
@tobiasps thanks for clarifying. I'm not happy with adding Could we instead only expose the events, like #2914, but pass the file ID as an additional parameter? Then you should be able to use |
Superseded by #3238 |
Great! Thanks for your work @Murderlon |
This pull request extends the DropTarget plugin to allow for manipulating the meta fields of the dropped file based on the DragEvent. As an example, this allows using DropTarget to enable uploads to specific folders in a UI by using the DragEvent to determine the parents of the event.
The pull request contains the following changes:
activeClass
for customizing the class added to target on dragover.setMeta
to enable setting specific meta fields depending on the drop event. This enables using one DropTarget with body as target with the meta fields being set depending on which DOM element the files were dropped.droptarget:dragover
,droptarget:dragleave
, anddroptarget:drop
events to allow for maniulating classes on the current element.