-
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: When dragging a mix of video, audio, and image blocks, create individual blocks as appropriate #65144
Drag and Drop: When dragging a mix of video, audio, and image blocks, create individual blocks as appropriate #65144
Conversation
… create individual blocks as appropriate
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: +12 B (0%) Total Size: 1.78 MB
ℹ️ View Unchanged
|
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 is working great. I'd like to tentatively approve, but will wait for overnight testers in case I missed something.
I dragged the following files to the canvas
- mp3 and wav files create audio blocks
- mp4 files create video blocks
- pdf/other files creates file blocks
Just one question - what do you think should happen when dragging multiple unsupported files onto the image block? Currently it switches to a gallery block. Should it remain an image block?
2024-09-09.17.19.05.mp4
❤️ |
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 works great! However, I think we might want to look at the implementation in onFilesDrop
.
gutenberg/packages/block-editor/src/components/use-on-block-drop/index.js
Lines 176 to 182 in 33b11ac
const transformation = findTransform( | |
getBlockTransforms( 'from' ), | |
( transform ) => | |
transform.type === 'files' && | |
canInsertBlockType( transform.blockName, targetRootClientId ) && | |
transform.isMatch( files ) | |
); |
The transformation only finds one for all files, instead of finding a transformation for each file. I wonder if we could (or should) iterate through each file and apply the transformations. 🤔 This should also check for canInsertBlockType
and other conditions in each block's transformation.
You mean in addition to the existing lookup, as a fallback? I think that makes sense from a responsibility perspective. Transformations can happen through other ways as well though, right? Like copy/paste or even manually through the UI. |
Thanks for testing, folks! 🙇
Oh, interesting! With a little digging, it looks like with the current approach we'll still wind up being guarded by gutenberg/packages/block-editor/src/store/actions.js Lines 374 to 377 in 9cf3162
Or here for insertions: gutenberg/packages/block-editor/src/store/actions.js Lines 579 to 582 in 9cf3162
So I believe what's currently happening in this PR is that the drop will bail if anything can't be inserted. Were there any other checks that happen in I quite liked the idea (if possible) of keeping the logic within the transformation if we can, as we've already got a bit of complexity happening in the dropping behaviour (especially in the That said, do let me know if you think it still needs moving around, though! |
What?
Fixes: #65074, and follow-up to: #65030
Allow dragging a mix of File, Audio, and Image blocks onto the editor canvas to create one of each block as appropriate.
This PR borrows the approach used by @swissspidy in the media-experiments plugin, as suggested in this comment: #65030 (comment)
The approach here differs slightly from that link, as here we can combine the logic with the fallback transform of the File block, since we're not working in a plugin.
Why?
Currently if you attempt to drag a mix of file types, you'll wind up with a File block for each file type. It's likely that a user dragging a mix of media files would expect media blocks to be in use rather than File blocks which are typically used to allow visitors to download the original file.
This PR proposes allowing image, video, and audio blocks to be created where appropriate, while still falling back to File blocks.
How?
Testing Instructions
trunk
it'll just create a bunch of File blocksScreenshots or screencast
2024-09-09.16.26.56.mp4