-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Integrate Resizable Editor with Device Preview #75121
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
base: trunk
Are you sure you want to change the base?
Conversation
|
Size Change: +311 B (+0.01%) Total Size: 3 MB
ℹ️ View Unchanged
|
| <PreviewDropdown | ||
| forceIsAutosaveable={ forceIsDirty } | ||
| disabled={ disablePreviewOption } | ||
| disabled={ isStylesCanvasActive } |
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.
The only exception is StyleBook, where the device preview dropdown is not available, and the canvas is not resizable. I plan to remove this limitation in a follow-up.
|
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. |
Mamaduka
left a comment
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.
I haven't tested this thoroughly, but I've left some notes based on the initial review.
I think it's an interesting approach. Can you elaborate a bit on why a new global state is needed rather than just using the previous method?
|
@Mamaduka Thanks for the review!
The reason I introduced the new |
|
Yes, but what prevents us from using I'm not saying that either option is better; I'm primarily curious about the technical decisions. |
@tellthemachines Can you try the following steps? I tested it on trunk (f2c4004).
d0d26373639acd414cd859e8ce4e469a.mp4 |
@Mamaduka Can you elaborate a bit more on your concerns? I may not be understanding you properly 😅 |
|
Nice, this looks great. There are some considerations, though, to be mindful of. Firstly, #73888 (which to my surprise is closed at the moment), but it nevertheless details using the viewport dropdown as a means to do responsive edits. One of the design conversations was whehter there should be a toggle inside, or not, and so far the latest instincts have gone towards this:
That is, since the dropdown is already so tailored to breakpoints, might as well not include the toggle at all, that any choice other than desktop, engages the responsive editing mode. Combine that with the ability to edit the values of each of the two breakpoints, and you have a viewport dropdown that is a bit more flexible than we're used to. That doesn't necessarily mean you can't do what you are proposing here—all that might still be valid. But the thing about those resize handles is that they are so useful in isolated editing mode for just previewing, that it might bring new appeal to using the viewport dropdown, and if that gets locked to making responsive edits, it's going to become a source of confusion. Mainly, I'd love @WordPress/gutenberg-design input here, and on the following thought, which is we should do one of the following:
I don't particularly love either of the above. But one of the main sources for this, is that the viewport dropdown is not a very discoverable place for hosting the "Preview in new tab" button. In using a Desktop icon, it suggests responsive tools, not previewing. The answer could be to move the option to a new page dropdown from the center title:
That's being discussed here, but it's going a bit back and forth. |
|
I like the direction of this PR. I think this is going to make it easier to implement custom breakpoints which is definitely something that folks are going to require for responsive editing. |
| } | ||
|
|
||
| const deviceTypeByCanvasWidth = getDeviceTypeByCanvasWidth( canvasWidth ); | ||
| const matchedDeviceType = getMatchedDeviceTypeByCanvasWidth( canvasWidth ); |
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.
Why do we need two kind of matching?
| icon: mobile, | ||
| canvasWidth: 480 - 1, // preview for useViewportMatch( 'mobile', '<' ) | ||
| }, | ||
| }; |
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.
So what's the plan there? Move this to the core "theme.json" in a follow-up?
Thanks Aki, I can reproduce it now! The problem is that useViewportMatch doesn't know about the editor iframe size. I'll put up a fix for that shortly. That fix shouldn't invalidate this PR, because it only fixes the block hiding bug. I'd still love to see the resizable editor used everywhere! Though @jasmussen raises some good points; this needs a bit more thought to reach the optimal solution. Edit: fix in #75156 |
|
I think this was closed by accident. |
|
Flaky tests detected in 07c3984. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/21616457870
|



What? Why?
Currently, we believe that device view and resizable editor are mutually exclusive, causing two major problems. This PR attempts to solve these problems by unifying the two modes:
Device View
In editors where device view is available, you cannot set any width other than the three device types. This includes the post editor, template editor, etc.
Resizable Editor
In resizable editors,
getDeviceTypealways returns Desktop, so the block hiding feature does not work in resizable editors, such as the Pattern Editor and Navigation Editor.How?
Here's a summary of the approach:
getDeviceTypeandsetDeviceTypeessentially act as wrappers for referencing and updating this newcanvasWidth:getDeviceTypewill return the appropriate device type based on the current canvas width: 481px wide or less is considered'Mobile', 781px or less is considered'Tablet', and anything else is considered'Desktop'.setDeviceTypeinternally sets the canvas width corresponding to the device type:undefinedfor Desktop,781pxfor Tablet, and479pxfor Mobile.useResizeCanvashook and make it a no-op function. Because this hook was for the device view.Testing Instructions
Post Editor, Template Editor
4dd92e2f8dde1b20e416c7c63516bf3e.mp4
Pattern Editor
The resize handles are always visible in this editor. Make sure the device preview dropdown and canvas width work together nicely.
7f71a97bacedc7e0526cc396311b7b28.mp4
Block Visibility
Related to #73735
8f8f000ca6dc4ac76a424659bbd823c4.mp4
With MetaBox
They should work well together without conflict.
4cec1f6a9b2d1b6dcb2976aad7b015f9.mp4