Skip to content

Conversation

@tomayac
Copy link

@tomayac tomayac commented Oct 4, 2024

What kind of change does this PR introduce?

Did you add tests for your changes?

  • Yes, my code is well tested
  • Not relevant

I think TypeScript doesn't know about this feature yet: Property 'getAsFileSystemHandle' does not exist on type 'DataTransferItem'..

If relevant, did you update the documentation?

  • Yes, I've updated the documentation
  • Not relevant

Summary
Dropped files could be edited right away (instead of forcing a download of a copy), which would be a great win for apps that need to modify dropped files, like online image editors. Also see the MDN docs.

Does this PR introduce a breaking change?
If this PR introduces a breaking change, please describe the impact and a migration path for existing applications.

Other information
Sorry, I don't know much TypeScript. This will need someone to teach TypeScript that 'getAsFileSystemHandle' exists on type 'DataTransferItem'. I wasn't sure how to test this in, since the tests fail because of the TypeScript issue.

Copy link
Collaborator

@rolandjitsu rolandjitsu left a comment

Choose a reason for hiding this comment

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

@tomayac thank you for your contribution. I only have a question and some unit tests would be good to have.

}

function fromDataTransferItem(item: DataTransferItem) {
if ('getAsFileSystemHandle' in DataTransferItem.prototype) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Some unit tests would be nice.

Copy link
Author

Choose a reason for hiding this comment

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

Not sure how, it seems like this runs tests against jsDOM, which doesn't emulate this API, unless I'm misunderstanding?

Copy link
Collaborator

Choose a reason for hiding this comment

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

If you check, I've mocked some of the APIs in order to get some unit tests running.

Copy link
Author

Choose a reason for hiding this comment

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

I looked into it, but it appears to be a rabbit hole. The current tests fail with ReferenceError: DataTransferItem is not defined, which is documented as jsdom/jsdom#2913, and jsdom/jsdom#2913 (comment) suggests a polyfill, but installing it fails with unresolvable dependency issues. YOLO-updating all dependencies also doesn't work. I'm not familiar with Jest and don't have time to learn how to mock stuff with it. If someone else has idle cycles or experience, this would be appreciated. Else, feel free to close the PR if the tests are a required dependency. No hard feelings.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I can try to have a look as well. As long as there are no regressions, we could probably merge without tests. Let me see what I can find.

I appreciate the contribution @tomayac

@rolandjitsu
Copy link
Collaborator

Released with #91.

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.

2 participants