-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
chore(ui): migrate dnd library #7288
Merged
Merged
+3,625
−3,294
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
psychedelicious
requested review from
blessedcoolant,
maryhipp and
hipsterusername
as code owners
November 7, 2024 09:51
github-actions
bot
added
frontend-deps
PRs that change frontend dependencies
frontend
PRs that change frontend files
labels
Nov 7, 2024
hipsterusername
approved these changes
Nov 7, 2024
We don't need a "dnd" image system. We need a "image action" system. We need to execute specific flows with images from various "origins": - internal dnd e.g. from gallery - external dnd e.g. user drags an image file into the browser - direct file upload e.g. user clicks an upload button - some other internal app button e.g. a context menu The actions are now generalized to better support these various use-cases.
Have to do a bit of fanagling to get it to work and get `pragmatic-drag-and-drop` to not complain.
psychedelicious
force-pushed
the
psyche/chore/ui/migrate-dnd
branch
from
November 7, 2024 20:37
871df0b
to
7df8e29
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR migrates the application from
dnd-kit
topragmatic-drag-and-drop
.Why
dnd-kit
is a pure JS library, wholly divorced from browsers' native dnd. Dragging is accomplished by creating drag preview elements and moving them with JS.Using JS has some inherent issues:
The library has some other issues:
pragmatic-drag-and-drop
is a newcomer, created by Atlassian and powering their products. It uses native browser APIs for core functionality instead of JS.Its implementation resolves all of the issues with
dnd-kit
:Pdnd is a vanilla JS library, but it works very well with react and there are many react examples.
Changes
This PR migrates the library just a little bit past feature parity - it makes layers in Canvas sortable via dnd. Otherwise, the functionality in this PR is nearly identical*.
As part of the migration, I reworked a lot of logic around gallery & dnd-capable image rendering, making the components a lot simpler and providing a noticeable perf boost.
I also removed the type
SerializableObject
, switching toJsonObject
fromtype-fest
. Probably should have done it separately but it made some type stuff easier.Generalized image actions
Many image actions were implemented 2 or 3 times.
For example, "create raster layer from image" was implemented in at least 3 places:
To clean this up, these actions have been consolidated. Also, dnd is not handled in redux. It's in a pdnd "monitor" function.
*Nearly identical
Workflow field styling
There was an awkward border when mousing over fields, indicating they are related or for the selected node. This is now a small dot.
Multi-select dnd
Dragging images into the app from the OS
Previously, we used
react-dropzone
for the full-page external dnd. This library lets you do validation on drag payloads as the drag starts. For example, we could check if the user is dragging only images and show an error before they try to drop.Unfortunately, this is a nonstandard API - you shouldn't be able to access the file info before the drop for security reason. It appears Chrome and FF ignore this restriction and let you access file info, but Safari does not. In fact, dnd from external sources into the app has never worked correctly with Safari.
pragmatic-drag-and-drop
takes the position that if it cannot provide the same API across all browsers, it won't provide the API at all. As a result, when you drag files in from the OS, we cannot validate them until you drop.Related Issues / Discussions
Offline discussion.
QA Instructions
Merge Plan
Nothing special.
Checklist