-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Drag and drop: fix drop zones on block drag #67317
Drag and drop: fix drop zones on block drag #67317
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Size Change: -75 B (0%) Total Size: 1.82 MB
ℹ️ View Unchanged
|
883830f
to
daa7f35
Compare
Flaky tests detected in 74d4822. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/12047696285
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing this! I have a couple questions below but otherwise it's looking really good and working as expected!
pattern?.syncStatus !== 'unsynced' | ||
? [ createBlock( 'core/block', { ref: pattern.id } ) ] | ||
: undefined; | ||
}, [ pattern ] ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't this always run, because pattern
is a new object each render? Would it be worth checking equality of its properties instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, this can be improved. Fixed!
const html = event.dataTransfer?.getData( 'text/html' ); | ||
if ( ! event.dataTransfer ) { | ||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would the event ever not have a dataTransfer? If so, we're changing the behaviour of this function because currently on trunk onDrop gets called if it exists, regardless of dataTransfer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will never be the case, it's just to make TypeScript happy. We already had these conditions before
( ( type === 'file' && onFilesDrop ) || | ||
( type === 'html' && onHTMLDrop ) || | ||
( type === 'default' && onDrop ) ), | ||
'is-active': isActive, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, this looks a lot better!
This tests well according to the instructions. Thanks! Just confirming, "image" refers image blocks? TrunkKapture.2024-11-27.at.10.57.26.mp4This PRKapture.2024-11-27.at.10.59.02.mp4I tested dragging media files as well just in case, and it works as expected. |
packages/block-editor/src/components/media-placeholder/index.js
Outdated
Show resolved
Hide resolved
Yes, though you can also drag them from the block toolbar, I guess list view works too. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚢
Co-authored-by: ellatrix <ellatrix@git.wordpress.org> Co-authored-by: tellthemachines <isabel_brison@git.wordpress.org> Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
What?
Currently in trunk, when you drag an image in a gallery for example, it triggers the placeholder inside the other images.
This seems to be a regression #66986.
I ended up reverting that PR in 48fd68f.
Additionally I reverted the HTML drop on the media placeholder component introduced by #49673 in 732cca8. I did this because we're basically duplicating the custom block data transfer we already have with additional HTML data transfer that needs to be serialised and re-parsed.
Then finally, to restore the ability to drag media items from the inserter, I added new data transfer items for each block so that we can check the block types on drag start. Note that the data itself is never available at drag start (there's some browser security reasons behind that), but the data types are. So we just encode our block types into the data types so we can check them.
This solution allow the MediaPlaceholder to check for itself if the dragged blocks are accepted, rather than setting a different catch all key for the draggable item.
Testing Instructions
Testing Instructions for Keyboard
Screenshots or screencast