-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Position scaled html within available container space #66034
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. |
// This is to offset the movement of the iframe when we open sidebars | ||
margin-left: calc(-1 * (#{$prev-container-width} - #{$container-width}) / 2); |
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 was causing the scrollbar to be hidden off canvas.
$container-width: var(--wp-block-editor-iframe-zoom-out-container-width, 100vw); | ||
// Apply an X translation to center the scaled content within the available space. | ||
transform: scale(#{$scale}) translateX(calc(( #{$prev-container-width} - #{ $container-width }) / 2 / #{$scale})); |
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.
Move the scaled canvas to the right to occupy the space of the container.
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 think the translateX()
could precede the scale()
and the translation wouldn’t have to be manually counter-scaled but that’s a nit.
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.
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 think the translateX() could precede the scale()
We tried that as well, but it seems like it's still necessary to apply the scaling to the translateX
.
We could also use individual scale and translate properties
I'm going to try this, as I think we'll need to adjust the animating timings for this separately.
Size Change: +81 B (0%) Total Size: 1.77 MB
ℹ️ View Unchanged
|
Flaky tests detected in caba47c. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/11346746023
|
@@ -9,9 +9,10 @@ | |||
} | |||
|
|||
.block-editor-iframe__scale-container.is-zoomed-out { | |||
$container-width: var(--wp-block-editor-iframe-zoom-out-container-width, 100vw); |
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 be able to remove this from the JS too since it's no longer used outside the iframe.
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 tests well for me. An added bonus is that it fixes the centering of the canvas on devices whose scrollbars are shown. I noticed there can be an odd transition when exiting zoom out:
66034-unzoom-width-sidebars.mp4
I don’t think it’s a big deal considering all the other odd things that can go on during the transition and this already seems to improve some of those.
Great idea on the approach. I had the same (rough) idea in the back of my mind and I’m glad to see it seemed simple enough.
$container-width: var(--wp-block-editor-iframe-zoom-out-container-width, 100vw); | ||
// Apply an X translation to center the scaled content within the available space. | ||
transform: scale(#{$scale}) translateX(calc(( #{$prev-container-width} - #{ $container-width }) / 2 / #{$scale})); |
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 think the translateX()
could precede the scale()
and the translation wouldn’t have to be manually counter-scaled but that’s a nit.
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.
Gave this a look, and it seems to work much better!
The timing of the animation can be improved, but I'm sure that it can be worked out.
I also found a bug (~36 seconds in the video below):
- open a teamplate
- enable zoomed out view
- click on the W logo to open side editor sidebar
- click on another template
- zoomed out view is already enabled, and the iframe is misplaced
Kapture.2024-10-11.at.09.56.24.mp4
I'll let other folks with a lot more familiarity on this part of Gutenberg review this PR in depth (@draganescu @MaggieCabrera @getdave )
There are still some glitches: satate-of-zoom-out-improvement.mp4
Update: I tested with a RTL lang setting and this PR works just fine. |
Based on @draganescu's review this feels close. @jeryj can you let me know if this PR becomes blocked or gets very much more complex? I just want to keep an eye on the scope of the fixes targeting 6.7 (which I assume this is?). |
This is very close, and it doesn't change the size of the canvas when there are more or less sidebars open. Great job here! |
Do you think this is similar to #65783? |
The "zoomed out mode is already enabled" part is the same as #65783, but the other part of the bug that I wanted to highlight is that the iframe/canvas is clipped and misplaced when it loads in zoomed-out mode |
6be7c86
to
da3fc3e
Compare
@@ -4,5 +4,4 @@ iframe[name="editor-canvas"] { | |||
height: 100%; | |||
display: block; | |||
background-color: transparent; | |||
@include editor-canvas-resize-animation; |
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 doesn't appear to have any effect.
EOD Notes: There's one more way to improve this that I couldn't dial in: We only want to animate the scaling when entering or exiting zoom out. We don't want to animate scale when it updates from sidebars opening. This is what causes it to fly out to random areas. To reproduce:
If we don't animate scale at that point, it's handled by the resizing of the iframe window and looks much smoother. @MaggieCabrera Do you have any ideas on how to do that efficiently? Also, I do think this is ready for review. I think overall this is an improvement over trunk. |
I need to test this more thoroughly but my first thought is that we are animating everything that happens to the div, maybe we want to target something specific like the scale and that would be enough? As a CSS only solution my only other suggestion is to have a class specific to the moments we want animated and then remove it, but I bet that's something that framer does on its own, so maybe that's another avenue to explore |
d46d4e6
to
793f407
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.
This tests great for me with the rebase and the zoom out hook fixed - I can't repro the clipping which was the biggest issue of this PR. The bouncing is greatly reduced too
@@ -5,18 +5,20 @@ | |||
|
|||
.block-editor-iframe__html { | |||
transform-origin: top center; | |||
@include editor-canvas-resize-animation; | |||
transition: all 0.4s cubic-bezier(0.46, 0.03, 0.52, 0.96), transform 0s; |
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 could use a comment about the numbers even like, "this is what works" 😄
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.
It was just removing the mixin since it's only used once: https://github.com/WordPress/gutenberg/pull/66034/files#diff-3014a931b478b662a3c554c1306e3b548da2c2edd5b32114395b329404f8f50aL40
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 tried every which way I could to break this but it seems really solid. Great work everyone.
The scale container could be smaller than the available area if zoom out was initialized with a sidebar open, then closed. We were using prevContainerWidth in the CSS under the assumption it would always be the largest value, but that was not true. This renames prevContainerWidthRef to initialContainerWidth so it's clearer that this is the point when zoom out was initialized, then renames the CSS vars prev-container-width to outer-container-width, using the larger value of containerWidth or initialContainerWidth so it can be more consistently named.
@dhruvang21 Thank you for testing! I went ahead and merged this as the issues you found are both present on
|
There was a conflict while trying to cherry-pick the commit to the wp/6.7 branch. Please resolve the conflict manually and create a PR to the wp/6.7 branch. PRs to wp/6.7 are similar to PRs to trunk, but you should base your PR on the wp/6.7 branch instead of trunk.
|
@jeryj Could you take point on ensuring this PR cherry picks cleanly to the |
* Positions the iframed HTML canvas via translateX rather than margin-left on the iframe in order to have the scrollbar for the iframe available instead of hidden off canvas. This also fixes issues with the vertical toolbar and inserters not rerendering to their new positions. * Renames prevContainerWidthRef to initialContainerWidth so it's clearer that this is the point when zoom out was initialized, then renames the CSS vars prev-container-width to outer-container-width, using the larger value of containerWidth or initialContainerWidth so it can be more consistently named. * Force largest available window size to scale from If you started with a sidebar open, then entered zoom out, then closed the sidebar, your scaled canvas would be too large. It should match the same size as if you start with no sidebars open, then enter zoom out. This also fixes an issue where scaling could be larger than 1. * Only animate scaling on entry and exit of zoom out mode to improve animations when opening and closing sidebars. * Known divergence: When starting from a smaller canvas (sidebars open), entering zoom out, then closing sidebars, there will be reflow on the canvas. --------- Co-authored-by: jeryj <jeryj@git.wordpress.org> Co-authored-by: ajlende <ajlende@git.wordpress.org> Co-authored-by: stokesman <presstoke@git.wordpress.org> Co-authored-by: ciampo <mciampini@git.wordpress.org> Co-authored-by: MaggieCabrera <onemaggie@git.wordpress.org> Co-authored-by: draganescu <andraganescu@git.wordpress.org> Co-authored-by: getdave <get_dave@git.wordpress.org> Co-authored-by: dhruvang21 <dhruvang21@git.wordpress.org> Co-authored-by: AhmarZaidi <ahmarzaidi@git.wordpress.org> Co-authored-by: kevin940726 <kevin940726@git.wordpress.org>
// iframeDocument.documentElement.style.setProperty( | ||
// '--wp-block-editor-iframe-zoom-out-outer-container-width', | ||
// `${ Math.max( initialContainerWidth.current, containerWidth ) }px` | ||
// ); |
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 don't think these comments were meant to be committed.
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.
Nope!
const handleZoomOutAnimationClassname = () => { | ||
clearTimeout( zoomOutAnimationClassnameRef.current ); | ||
|
||
iframeDocument.documentElement.classList.add( 'zoom-out-animation' ); | ||
|
||
zoomOutAnimationClassnameRef.current = setTimeout( () => { | ||
iframeDocument.documentElement.classList.remove( | ||
'zoom-out-animation' | ||
); | ||
}, 400 ); // 400ms should match the animation speed used in components/iframe/content.scss | ||
}; |
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 function should be defined inside the useEffect
since that's the only place it's used.
'--wp-block-editor-iframe-zoom-out-prev-container-width', | ||
`${ prevContainerWidthRef.current }px` | ||
'--wp-block-editor-iframe-zoom-out-outer-container-width', | ||
`${ Math.max( initialContainerWidth.current, containerWidth ) }px` |
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 would make this a variable since it's used in three places where they are expected to always be the same.
@@ -336,13 +374,16 @@ function Iframe( { | |||
`${ containerWidth }px` | |||
); | |||
iframeDocument.documentElement.style.setProperty( | |||
'--wp-block-editor-iframe-zoom-out-prev-container-width', | |||
`${ prevContainerWidthRef.current }px` | |||
'--wp-block-editor-iframe-zoom-out-outer-container-width', |
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 would maybe rename this to --wp-block-editor-iframe-zoom-out-scale-container-width
instead since this is the width of the block-editor-iframe__scale-container
.
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 may not always call it scale container, so I'd be fine leaving this one named as is.
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.
Right, it may be changed, but for the current reader, the connection between the two would be more clear if the variable was named the same as the container that it's setting the width for.
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.
--wp-block-editor-iframe-scale-container-width
would be acceptable too.
* Positions the iframed HTML canvas via translateX rather than margin-left on the iframe in order to have the scrollbar for the iframe available instead of hidden off canvas. This also fixes issues with the vertical toolbar and inserters not rerendering to their new positions. * Renames prevContainerWidthRef to initialContainerWidth so it's clearer that this is the point when zoom out was initialized, then renames the CSS vars prev-container-width to outer-container-width, using the larger value of containerWidth or initialContainerWidth so it can be more consistently named. * Force largest available window size to scale from If you started with a sidebar open, then entered zoom out, then closed the sidebar, your scaled canvas would be too large. It should match the same size as if you start with no sidebars open, then enter zoom out. This also fixes an issue where scaling could be larger than 1. * Only animate scaling on entry and exit of zoom out mode to improve animations when opening and closing sidebars. * Known divergence: When starting from a smaller canvas (sidebars open), entering zoom out, then closing sidebars, there will be reflow on the canvas. --------- Co-authored-by: jeryj <jeryj@git.wordpress.org> Co-authored-by: ajlende <ajlende@git.wordpress.org> Co-authored-by: stokesman <presstoke@git.wordpress.org> Co-authored-by: ciampo <mciampini@git.wordpress.org> Co-authored-by: MaggieCabrera <onemaggie@git.wordpress.org> Co-authored-by: draganescu <andraganescu@git.wordpress.org> Co-authored-by: getdave <get_dave@git.wordpress.org> Co-authored-by: dhruvang21 <dhruvang21@git.wordpress.org> Co-authored-by: AhmarZaidi <ahmarzaidi@git.wordpress.org> Co-authored-by: kevin940726 <kevin940726@git.wordpress.org>
* Positions the iframed HTML canvas via translateX rather than margin-left on the iframe in order to have the scrollbar for the iframe available instead of hidden off canvas. This also fixes issues with the vertical toolbar and inserters not rerendering to their new positions. * Renames prevContainerWidthRef to initialContainerWidth so it's clearer that this is the point when zoom out was initialized, then renames the CSS vars prev-container-width to outer-container-width, using the larger value of containerWidth or initialContainerWidth so it can be more consistently named. * Force largest available window size to scale from If you started with a sidebar open, then entered zoom out, then closed the sidebar, your scaled canvas would be too large. It should match the same size as if you start with no sidebars open, then enter zoom out. This also fixes an issue where scaling could be larger than 1. * Only animate scaling on entry and exit of zoom out mode to improve animations when opening and closing sidebars. * Known divergence: When starting from a smaller canvas (sidebars open), entering zoom out, then closing sidebars, there will be reflow on the canvas. --------- Co-authored-by: jeryj <jeryj@git.wordpress.org> Co-authored-by: ajlende <ajlende@git.wordpress.org> Co-authored-by: stokesman <presstoke@git.wordpress.org> Co-authored-by: ciampo <mciampini@git.wordpress.org> Co-authored-by: MaggieCabrera <onemaggie@git.wordpress.org> Co-authored-by: draganescu <andraganescu@git.wordpress.org> Co-authored-by: getdave <get_dave@git.wordpress.org> Co-authored-by: dhruvang21 <dhruvang21@git.wordpress.org> Co-authored-by: AhmarZaidi <ahmarzaidi@git.wordpress.org> Co-authored-by: kevin940726 <kevin940726@git.wordpress.org>
* Positions the iframed HTML canvas via translateX rather than margin-left on the iframe in order to have the scrollbar for the iframe available instead of hidden off canvas. This also fixes issues with the vertical toolbar and inserters not rerendering to their new positions. * Renames prevContainerWidthRef to initialContainerWidth so it's clearer that this is the point when zoom out was initialized, then renames the CSS vars prev-container-width to outer-container-width, using the larger value of containerWidth or initialContainerWidth so it can be more consistently named. * Force largest available window size to scale from If you started with a sidebar open, then entered zoom out, then closed the sidebar, your scaled canvas would be too large. It should match the same size as if you start with no sidebars open, then enter zoom out. This also fixes an issue where scaling could be larger than 1. * Only animate scaling on entry and exit of zoom out mode to improve animations when opening and closing sidebars. * Known divergence: When starting from a smaller canvas (sidebars open), entering zoom out, then closing sidebars, there will be reflow on the canvas. --------- Co-authored-by: jeryj <jeryj@git.wordpress.org> Co-authored-by: ajlende <ajlende@git.wordpress.org> Co-authored-by: stokesman <presstoke@git.wordpress.org> Co-authored-by: ciampo <mciampini@git.wordpress.org> Co-authored-by: MaggieCabrera <onemaggie@git.wordpress.org> Co-authored-by: draganescu <andraganescu@git.wordpress.org> Co-authored-by: getdave <get_dave@git.wordpress.org> Co-authored-by: dhruvang21 <dhruvang21@git.wordpress.org> Co-authored-by: AhmarZaidi <ahmarzaidi@git.wordpress.org> Co-authored-by: kevin940726 <kevin940726@git.wordpress.org>
* Positions the iframed HTML canvas via translateX rather than margin-left on the iframe in order to have the scrollbar for the iframe available instead of hidden off canvas. This also fixes issues with the vertical toolbar and inserters not rerendering to their new positions. * Renames prevContainerWidthRef to initialContainerWidth so it's clearer that this is the point when zoom out was initialized, then renames the CSS vars prev-container-width to outer-container-width, using the larger value of containerWidth or initialContainerWidth so it can be more consistently named. * Force largest available window size to scale from If you started with a sidebar open, then entered zoom out, then closed the sidebar, your scaled canvas would be too large. It should match the same size as if you start with no sidebars open, then enter zoom out. This also fixes an issue where scaling could be larger than 1. * Only animate scaling on entry and exit of zoom out mode to improve animations when opening and closing sidebars. * Known divergence: When starting from a smaller canvas (sidebars open), entering zoom out, then closing sidebars, there will be reflow on the canvas. --------- Co-authored-by: jeryj <jeryj@git.wordpress.org> Co-authored-by: ajlende <ajlende@git.wordpress.org> Co-authored-by: stokesman <presstoke@git.wordpress.org> Co-authored-by: ciampo <mciampini@git.wordpress.org> Co-authored-by: MaggieCabrera <onemaggie@git.wordpress.org> Co-authored-by: draganescu <andraganescu@git.wordpress.org> Co-authored-by: getdave <get_dave@git.wordpress.org> Co-authored-by: dhruvang21 <dhruvang21@git.wordpress.org> Co-authored-by: AhmarZaidi <ahmarzaidi@git.wordpress.org> Co-authored-by: kevin940726 <kevin940726@git.wordpress.org>
* Positions the iframed HTML canvas via translateX rather than margin-left on the iframe in order to have the scrollbar for the iframe available instead of hidden off canvas. This also fixes issues with the vertical toolbar and inserters not rerendering to their new positions. * Renames prevContainerWidthRef to initialContainerWidth so it's clearer that this is the point when zoom out was initialized, then renames the CSS vars prev-container-width to outer-container-width, using the larger value of containerWidth or initialContainerWidth so it can be more consistently named. * Force largest available window size to scale from If you started with a sidebar open, then entered zoom out, then closed the sidebar, your scaled canvas would be too large. It should match the same size as if you start with no sidebars open, then enter zoom out. This also fixes an issue where scaling could be larger than 1. * Only animate scaling on entry and exit of zoom out mode to improve animations when opening and closing sidebars. * Known divergence: When starting from a smaller canvas (sidebars open), entering zoom out, then closing sidebars, there will be reflow on the canvas. --------- Co-authored-by: jeryj <jeryj@git.wordpress.org> Co-authored-by: ajlende <ajlende@git.wordpress.org> Co-authored-by: stokesman <presstoke@git.wordpress.org> Co-authored-by: ciampo <mciampini@git.wordpress.org> Co-authored-by: MaggieCabrera <onemaggie@git.wordpress.org> Co-authored-by: draganescu <andraganescu@git.wordpress.org> Co-authored-by: getdave <get_dave@git.wordpress.org> Co-authored-by: dhruvang21 <dhruvang21@git.wordpress.org> Co-authored-by: AhmarZaidi <ahmarzaidi@git.wordpress.org> Co-authored-by: kevin940726 <kevin940726@git.wordpress.org>
* Positions the iframed HTML canvas via translateX rather than margin-left on the iframe in order to have the scrollbar for the iframe available instead of hidden off canvas. This also fixes issues with the vertical toolbar and inserters not rerendering to their new positions. * Renames prevContainerWidthRef to initialContainerWidth so it's clearer that this is the point when zoom out was initialized, then renames the CSS vars prev-container-width to outer-container-width, using the larger value of containerWidth or initialContainerWidth so it can be more consistently named. * Force largest available window size to scale from If you started with a sidebar open, then entered zoom out, then closed the sidebar, your scaled canvas would be too large. It should match the same size as if you start with no sidebars open, then enter zoom out. This also fixes an issue where scaling could be larger than 1. * Only animate scaling on entry and exit of zoom out mode to improve animations when opening and closing sidebars. * Known divergence: When starting from a smaller canvas (sidebars open), entering zoom out, then closing sidebars, there will be reflow on the canvas. --------- Co-authored-by: jeryj <jeryj@git.wordpress.org> Co-authored-by: ajlende <ajlende@git.wordpress.org> Co-authored-by: stokesman <presstoke@git.wordpress.org> Co-authored-by: ciampo <mciampini@git.wordpress.org> Co-authored-by: MaggieCabrera <onemaggie@git.wordpress.org> Co-authored-by: draganescu <andraganescu@git.wordpress.org> Co-authored-by: getdave <get_dave@git.wordpress.org> Co-authored-by: dhruvang21 <dhruvang21@git.wordpress.org> Co-authored-by: AhmarZaidi <ahmarzaidi@git.wordpress.org> Co-authored-by: kevin940726 <kevin940726@git.wordpress.org>
Fixes #65188; fixes #65595
What?
Rework how the scaled canvas is centered to fix a few bugs.
Why?
How?
translateX
to account for open sidebars.The gist is, rather than push the iframe around, push the scaled html element around.
Before: Margin-left to move the center of the iframe to line up with the container
After: Iframe takes up full available space, scale html, then push it over to be in the available area
Known Reflow Points
There will be some reflow when:
This is because our initial scale point started from a size smaller than our total available window space (all sidebars closed). In this one instance, I think reflow is acceptable. If we don't reflow, then it reflows when we exit zoom out, which I think is worse.
Most important points for reflow to NOT happen:
When it could be allowed:
One way we can prevent this is if beginning from a smaller state (sidebar open, enter zoom out) then add padding on the iframe to force the HTML to account for the extra space and stay scaled smaller. I'm not sure this complexity is worth it though.
Testing Instructions
Testing Instructions for Keyboard
Screenshots or screencast
Iframe before.
Note the left side is pushed over. This was to center the scaled canvas in the container. It worked to center the canvas, but the scrollbar is also pushed to the right.
iframe after
The iframe is the same size as the previous container. This allows the scrollbar to be visible. Then, the scaled content is pushed to the left to take up its available space.