Skip to content
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

Make sure we use the standard API for file drops if it's available #38

Closed
wants to merge 1 commit into from
Closed

Make sure we use the standard API for file drops if it's available #38

wants to merge 1 commit into from

Conversation

ghost
Copy link

@ghost ghost commented Apr 11, 2018

As there are no tests, I do not know if this breaks anything. I assume the code was written so that both code path provide the same object.

The new code doesn't transform the files list to an array anymore as having a FileList instance is much more useful.

Copy link
Owner

@feross feross left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR but you bundled too many opinionated changes into one PR.

I would have merged the reversal, but I don't want to change the return type or code style.

if (files.length === 0) return

for (var i = 0; i < files.length; ++i) {
files[i].fullPath = '/' + files[i].name
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wasn't necessary to change the code style here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was, a FileList isn't an array, it doesn't have a forEach method.

@@ -110,7 +110,19 @@ function dragDrop (elem, listeners) {
}

// file drop support
if (e.dataTransfer.items) {
if (e.dataTransfer.files) {
var files = e.dataTransfer.files
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing the return type here is a breaking change.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's also the only reason to make this change, if the return type doesn't change, this library can't be used to transfer a file drag and drop to a file input

@feross
Copy link
Owner

feross commented Apr 13, 2018

I merged just the files vs. items change and released as 2.14.0.

@feross feross closed this Apr 13, 2018
feross added a commit that referenced this pull request Apr 13, 2018
@ghost
Copy link
Author

ghost commented Apr 13, 2018

Thanks for the PR but you bundled too many opinionated changes into one PR.

The change makes the dragDrop function return a FileList when possible, I made the minimal amount of change to make it do that. There is no opinion in there.

@feross
Copy link
Owner

feross commented Apr 13, 2018

@benjamin-demarteau I don't understand your use case. Can you explain it more completely?

@ghost
Copy link
Author

ghost commented Apr 13, 2018

I am using uppy to handle file upload, when dropping files into a drop zone, it registers the files to upload, but it doesn't add the files dropped to the html input, which means there is no user feedback (that and other problems when selecting the same file multiple times).

It is possible to add files to an input[type=file], but only if you have an instance of FileList. That restriction exists for a security reason: it makes sure you are adding files to the input based on a user interaction (FileList is not instantiable from user code).

Since uppy uses this library to handle the drag and drop events, before contributing that change, I need this library to provide a FileList to its consumers.

Reference: https://html.spec.whatwg.org/multipage/input.html#common-input-element-apis

input . files [ = files ]
Returns a FileList object listing the selected files of the form control.
Returns null if the control isn't a file control.
Can be set to a FileList object to change the selected files of the form control. For instance, as the result of a drag-and-drop operation.

@feross
Copy link
Owner

feross commented Apr 15, 2018

Understood. I decided to change the API to return a FileList and to drop older IE support. Published a new version as 3.0.0.

@ghost
Copy link
Author

ghost commented Apr 16, 2018

Thanks a bunch for this change!

@ghost ghost mentioned this pull request Apr 16, 2018
@feross feross mentioned this pull request Apr 19, 2018
@feross
Copy link
Owner

feross commented Apr 19, 2018

There was a regression, so I need to change the API once again. See: #39

feross added a commit that referenced this pull request Apr 19, 2018
crown0128 added a commit to crown0128/drag-drop that referenced this pull request Aug 24, 2023
crown0128 added a commit to crown0128/drag-drop that referenced this pull request Aug 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant