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

feat: add FileSystemFileHandle support #79

Closed
wants to merge 5 commits into from

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.

src/file-selector.ts Outdated Show resolved Hide resolved
@@ -121,6 +121,10 @@ function flatten<T>(items: any[]): T[] {
}

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

src/file-selector.ts Outdated Show resolved Hide resolved
src/file-selector.ts Outdated Show resolved Hide resolved
@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