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

[experimental] Native file dragging plugin #1584

Draft
wants to merge 6 commits into
base: experimental
Choose a base branch
from

Conversation

yf-yang
Copy link

@yf-yang yf-yang commented Jan 7, 2025

This PR aims at providing a plugin to drag and drop file from native fs to browser.

It is marked as draft because:

  • When dropping, activationEvent's data transfer is already cleared, so the file data is not accessible

I don't know how to fix it. Would you consider passing the DOM event to core dnd-kit events (dragstart, dragend, dragmove...)?

fixes #1581

Copy link

changeset-bot bot commented Jan 7, 2025

🦋 Changeset detected

Latest commit: c681a00

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 7 packages
Name Type
@dnd-kit/abstract Minor
@dnd-kit/dom Minor
@dnd-kit/collision Minor
@dnd-kit/helpers Minor
@dnd-kit/react Minor
@dnd-kit/geometry Minor
@dnd-kit/state Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

"build:core": "tsup src/core/index.ts",
"build:modifiers": "tsup --entry.modifiers src/modifiers/index.ts",
"build:plugins": "tsup --entry.debug src/plugins/debug/index.ts --outDir ./plugins",
"build:draggableFile": "tsup --entry.draggableFile src/plugins/draggableFile/index.ts --outDir ./plugins",
Copy link
Author

Choose a reason for hiding this comment

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

Didn't take times figuring out how to configure the command. Put it here for now

@yf-yang

This comment was marked as resolved.

@yf-yang yf-yang changed the title Native file dragging plugin [experimental] Native file dragging plugin Jan 7, 2025

if (!status.initialized || !shape) {
if (!status.initialized) {
return DEFAULT_VALUE;
Copy link
Author

Choose a reason for hiding this comment

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

It should be collision detection algorithm's responsibility to check shape's availability. File draggable does not have a shape and would be filtered by the original code implementation

@yf-yang yf-yang marked this pull request as ready for review January 8, 2025 04:39
@yf-yang yf-yang marked this pull request as draft January 8, 2025 04:49
// Make sure effects will re-run when those properties change
void position.current;
void shape;

Copy link
Author

@yf-yang yf-yang Jan 8, 2025

Choose a reason for hiding this comment

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

I don't know if it has a performance penalty (too many collisions recompute?)

@yf-yang
Copy link
Author

yf-yang commented Jan 24, 2025

@clauderic Can we discuss here or how can we get connected? Generally speaking, to support native file drop, I've make sure they can be handled by dnd kit, but the native dom event needs to be passed to dnd-kit event handlers (Particularly, 'drag' event needs to be passed to 'dragend' event)

You can contact me on discord yifei_31901

@clauderic
Copy link
Owner

Hey can you help me better understand the use-case for this? I was considering introducing a native drag and drop plugin, for example, to allow drag and drop across windows, but I had not considered it for files.

@yf-yang
Copy link
Author

yf-yang commented Feb 6, 2025

@clauderic It's simple: turning components to things like react-dropzone

I've tested it with a local storybook (not pushed yet), the lifecycle events are correct (at least for simple cases), but the dataTransfer is not accessible when dropping, so it is incomplete.

It's not the same with cross window drag and drop, as native dragging file is captured when it enters the window, but there isn't a programmable useDraggable hook for it.

Related #338 #306

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