-
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
Allow dragging-and-dropping images from the inserter to image blocks #49673
Conversation
Size Change: +228 B (0%) Total Size: 1.37 MB
ℹ️ View Unchanged
|
Flaky tests detected in ab7605cd5e9053a3213e05ed73112caf4b66633f. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4796139894
|
a54f544
to
b0ae1b3
Compare
@@ -4,12 +4,6 @@ figure.wp-block-gallery { | |||
// See https://github.com/WordPress/gutenberg/pull/10358 | |||
|
|||
display: block; | |||
&.has-nested-images { |
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 have some unexpected side effects, unfortunately. Namely it will no longer be possible to drag between two image blocks when the gap is zero. We'll have to determine which is the better trade-off, and what potential other options we have to solve this.
2ed11b1
to
89365c4
Compare
packages/block-editor/src/components/media-placeholder/index.js
Outdated
Show resolved
Hide resolved
packages/block-editor/src/components/inserter/media-tab/media-preview.js
Outdated
Show resolved
Hide resolved
packages/block-editor/src/components/media-placeholder/index.js
Outdated
Show resolved
Hide resolved
773864c
to
6308224
Compare
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 the updates, I like this approach personally, WDYT?
It would be cool to handle video/audio blocks too.
packages/block-editor/src/components/media-placeholder/index.js
Outdated
Show resolved
Hide resolved
d1032c4
to
ab7605c
Compare
I updated it to also handle audio and video blocks, and ignore empty blocks. This is now ready for review! |
Am I doing something wrong, I can drag and drop an image into the placeholder, nothing happens for me. The first time it worked but stopped working since. |
2e4f9ab
to
de7ade2
Compare
@youknowriad Oh oops! I pushed the wrong commit. I believe it's now fixed! |
Ok this works better :) but there's a few notes that I think we should look at:
The biggest question for me is the Gallery block. It seems this PR has a big impact on how drag and drop works there. In trunk, I'm able to drag and drop to reorder images easily in the Gallery image without being bothered by placeholders for the image blocks within the gallery. I can also drag and drop an image from the inserter into the gallery block, it adds the image to the gallery. These flows don't work as smoothly in this branch. So the question here is whether we want maybe to disable that drop zone within gallery blocks or within image blocks that are "filled" (keep it only in the placeholder state). Also, let's get some design eyes here. cc @jasmussen @jameskoster |
c3ccbed
to
e2eddff
Compare
@@ -4,12 +4,16 @@ | |||
|
|||
- `CheckboxControl`, `CustomGradientPicker`, `FormToggle`, : Refactor and correct the focus style for consistency ([#50127](https://github.com/WordPress/gutenberg/pull/50127)). | |||
|
|||
### Breaking Changes | |||
|
|||
- `onDragStart` in `<Draggable>` is now a synchronous function to allow setting additional data for `event.dataTransfer` ([#49673](https://github.com/WordPress/gutenberg/pull/49673)). |
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.
Unfortunately, this is a breaking change, but I think it actually fixes a bug so it might not be that impactful. c.c. @ciampo if you think this is acceptable :).
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.
Sorry, still catching up through the notifications pile. Sounds good to me!
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.
We should probably add a dev note for this change, though. I've added the GH label
isDragging.current = true; | ||
// Defer hiding the dragged source element to the next | ||
// frame to enable dragging. | ||
window.requestAnimationFrame( () => { |
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 to retain the former behavior of asynchronous onDragStart
before. I also changed setTimeout
to requestAnimationFrame
to better describe the intent.
Kapture.2023-05-03.at.15.31.38.mp4I believe this now matches more closely to what we want now. We eventually will still want to handle blocks drop in some other components and will need the multiple data types trick, but fortunately not for the c.c. @jasmussen @jameskoster @youknowriad in case I missed anything 🙇 . |
Can you still drop an image from your local files onto the canvas to replace? If so this looks excellent! |
@jameskoster Yep, that's always supported! |
That looks like it threads the needle. Nice work. Let's just get the code sanity checked but otherwise landed. I'm noticing that there's a horizontal scrollbar when you drag an OV image with a caption into the gallery. I'm assuming this is an existing issue in trunk. If yes, let's create an issue for that and put it in the polish board. |
Thanks for this one! |
6.3 Dev NoteThe This change should have minimal impact on existing code. However, if it does affect your code, you can maintain the original behavior by wrapping your event callback inside a -onDragStart={ () => { doSomething(); } }
+onDragStart={ () => { setTimeout( doSomething, 0 ); } } |
What?
Alternative to #49297.
Allow dragging-and-dropping images from the inserter to image blocks.
Why?
Close #48919. See the issue for more info.
How?
I added some inline review comments below for some implementation details. The main idea is derived from #49297.
Testing Instructions
Testing Instructions for Keyboard
This is a feature about drag-and-drop, so unfortunately it cannot be tested with keyboard (yet).
Screenshots or screencast
Kapture.2023-04-10.at.16.31.57.mp4