Skip to content
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

Refactor Zoom Out to scale iframe #63390

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
9c83e9e
Remove iframe wrappers; have scrollbar visible; improve centering
stokesman Jun 30, 2024
98c452b
Avoid changing scale once “zoomed out”
stokesman Jul 3, 2024
37f79cc
Remove resize listeners
stokesman Jul 3, 2024
26a67fa
Try without transitions
stokesman Jul 3, 2024
02362aa
Scale the iframe instead of its contents
stokesman Jul 5, 2024
4bcf2e3
Remove outdated fix for double scrollbars
stokesman Jul 11, 2024
d7aaedc
Restore main content area expansion
stokesman Jul 11, 2024
921e974
Move styles from JS to CSS; add comments
stokesman Jul 11, 2024
f32bed2
Factor in frameSize to “default” scaling
stokesman Jul 11, 2024
eddd3f8
Factor scale into adjustment of bubbled mouse events
stokesman Jul 12, 2024
72d0498
Try padding the vertical toolbars shift range
stokesman Jul 16, 2024
df78c42
Try outlining the iframe
stokesman Jul 16, 2024
a9c41dd
Remove scrollbar width counter-scaling
stokesman Jul 21, 2024
142ba05
Restore scale adjustment to limit zoomed out maximum width
stokesman Jul 21, 2024
d553e00
Remove changes to keep scale constant after zoomed out
stokesman Aug 2, 2024
35a54f1
Redo keep scale constant after zoomed out
stokesman Aug 3, 2024
1f63953
Combine effects
stokesman Aug 3, 2024
cdb3f22
Remove singly used animation mixin
stokesman Aug 3, 2024
cac6a5e
Improve transition; revise centering; organize styles
stokesman Aug 17, 2024
b3a005c
Restore CSS scale var for use in block list styles
stokesman Sep 20, 2024
c619cf9
Drop drop-shadow on zoomed out canvas
stokesman Sep 20, 2024
14e4c11
Fix inserter separator overflow and try alternate dragged over style
stokesman Sep 20, 2024
489a354
Try full height
stokesman Oct 6, 2024
2f826fd
Revert "Try padding the vertical toolbars shift range"
stokesman Oct 6, 2024
79ba58a
Stop keeping scale constant after zoomed out
stokesman Oct 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions packages/base-styles/_animations.scss
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@
@include reduce-motion("animation");
}

@mixin editor-canvas-resize-animation() {
transition: all 0.5s cubic-bezier(0.65, 0, 0.45, 1);
@include reduce-motion("transition");
}

// Deprecated
@mixin edit-post__fade-in-animation($speed: 0.08s, $delay: 0s) {
@warn "The `edit-post__fade-in-animation` mixin is deprecated. Use `animation__fade-in` instead.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export function ExperimentalBlockCanvas( {
return (
<BlockTools
__unstableContentRef={ localRef }
style={ { height, display: 'flex' } }
style={ { height, display: 'flex', justifyContent: 'center' } }
>
<Iframe
{ ...iframeProps }
Expand Down
18 changes: 17 additions & 1 deletion packages/block-editor/src/components/block-canvas/style.scss
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
iframe[name="editor-canvas"] {
position: relative;
inset-block: 0;
flex: 0 0 auto;
box-sizing: border-box;
width: 100%;
height: 100%;
display: block;
background-color: transparent;
@include editor-canvas-resize-animation;
transition: all 0.5s cubic-bezier(0.65, 0, 0.45, 1);
@include reduce-motion("transition");
transform-origin: 50% 0;
}

iframe[name="editor-canvas"].is-zoomed-out {
$max-width: 750px; // This is also hardcoded as ZOOM_OUT_MAX_WIDTH in the iframe component and needs to be manually kept in sync.
$scale: var(--wp-block-editor-iframe-zoom-out-scale);
$inset: var(--wp-block-editor-iframe-zoom-out-inset);
transform: scale(#{$scale});
flex-basis: calc((100% - #{$inset} * 2) / #{$scale});
height: calc(100% / #{$scale});
$inset-max-width: "(#{$max-width} - #{$inset} * 2)";
max-width: calc(#{$inset-max-width} / #{$scale});
}
40 changes: 21 additions & 19 deletions packages/block-editor/src/components/block-list/content.scss
Original file line number Diff line number Diff line change
Expand Up @@ -395,34 +395,36 @@ _::-webkit-full-page-media, _:future, :root .has-multi-selection .block-editor-b
}

.block-editor-block-list__zoom-out-separator {
/* same color as the iframe's background */
background: $gray-300;
// Additional -1px is required to avoid sub pixel rounding errors allowing background to show.
margin-left: -1px;
margin-right: -1px;
transition: background-color 0.3s ease;
color: $black;
display: flex;
align-items: center;
justify-content: center;
font-size: $default-font-size;
font-family: $default-font;
color: $black;
font-weight: normal;
.has-global-padding > & {
margin: 0;
}

.is-zoomed-out & {
// Scale the font size based on the zoom level.
font-size: calc(#{$default-font-size} * ( 2 - var(--wp-block-editor-iframe-zoom-out-scale) ));
}
font-size: calc(#{$default-font-size} / var(--wp-block-editor-iframe-zoom-out-scale));

&.is-dragged-over {
background: $gray-400;
}
}
& > * {
position: relative; // Puts the label in front of the ::before pseudo element.
}

// In Post Editor allow the separator to occupy the full width by ignoring (cancelling out) the global padding.
.has-global-padding > .block-editor-block-list__zoom-out-separator,
.block-editor-block-list__layout.is-root-container.has-global-padding > .block-editor-block-list__zoom-out-separator {
max-width: none;
// Additional -1px is required to avoid sub pixel rounding errors allowing background to show.
margin: 0 calc(-1 * var(--wp--style--root--padding-right) - 1px) 0 calc(-1 * var(--wp--style--root--padding-left) - 1px) !important;
&::before {
background: $gray-300; // same color as the iframe's background.
content: "";
transition: opacity 0.2s linear;
position: absolute;
inset: auto 0; // Horizontal edges to the full canvas width regardless of global padding.
height: inherit;
}

&.is-dragged-over::before {
opacity: 0.25;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,11 @@ export function ZoomOutSeparator( {
<AnimatePresence>
{ isVisible && (
<motion.div
as="button"
layout={ ! isReducedMotion }
initial={ { height: 0 } }
animate={ { height: '120px' } }
animate={ {
height: 'calc(60px / var(--wp-block-editor-iframe-zoom-out-scale)',
} }
exit={ { height: 0 } }
transition={ {
type: 'tween',
Expand All @@ -123,11 +124,20 @@ export function ZoomOutSeparator( {
>
<motion.div
initial={ { opacity: 0 } }
animate={ { opacity: 1 } }
animate={
isDraggedOver
? {
opacity: 0,
scale: isReducedMotion ? 1 : 0,
transition: { duration: 0.2, delay: 0 },
}
: { opacity: 1 }
}
exit={ { opacity: 0 } }
transition={ {
type: 'tween',
duration: 0.1,
delay: 0.1,
} }
>
{ __( 'Drop pattern.' ) }
Expand Down
81 changes: 22 additions & 59 deletions packages/block-editor/src/components/iframe/content.scss
Original file line number Diff line number Diff line change
@@ -1,68 +1,31 @@
.block-editor-iframe__body {
position: relative;
}

.block-editor-iframe__container {
width: 100%;
height: 100%;
overflow-x: hidden;
}

.block-editor-iframe__scale-container {
width: 100%;
height: 100%;
display: flex;
}

.block-editor-iframe__scale-container.is-zoomed-out {
$container-width: var(--wp-block-editor-iframe-zoom-out-container-width, 100vw);
$prev-container-width: var(--wp-block-editor-iframe-zoom-out-prev-container-width, 100vw);
width: $prev-container-width;
margin-left: calc(-1 * (#{$prev-container-width} - #{$container-width}) / 2);
}

.block-editor-iframe__html {
border: 0 solid $gray-300;
transform-origin: top center;
@include editor-canvas-resize-animation;
// Keeps body background styles from being clipped.
// See: https://github.com/WordPress/gutenberg/issues/44374#issuecomment-1260784743
height: auto;
// Keeps body background image from repeating.
// See: https://github.com/WordPress/gutenberg/issues/46782
min-height: 100%;
// Keeps the scrollbar gutter present to avoid a minor layout shift in case zoom out
// increases the height enough to remove overflow.
overflow-y: scroll;
}

.block-editor-iframe__html.is-zoomed-out {
$scale: var(--wp-block-editor-iframe-zoom-out-scale);
$frame-size: var(--wp-block-editor-iframe-zoom-out-frame-size);
$inner-height: var(--wp-block-editor-iframe-zoom-out-inner-height);
$content-height: var(--wp-block-editor-iframe-zoom-out-content-height);
$prev-container-width: var(--wp-block-editor-iframe-zoom-out-prev-container-width);

transform: scale(#{$scale});

background-color: $gray-300;

// Firefox and Safari don't render margin-bottom here and margin-bottom is needed for Chrome
// layout, so we use border matching the background instead of margins.
border: calc(#{$frame-size} / #{$scale}) solid $gray-300;

// Chrome seems to respect that transform scale shouldn't affect the layout size of the element,
// so we need to adjust the height of the content to match the scale by using negative margins.
$extra-content-height: calc(#{$content-height} * (1 - #{$scale}));
$total-frame-height: calc(2 * #{$frame-size});
$total-height: calc(#{$extra-content-height} + #{$total-frame-height} + 2px);
margin-bottom: calc(-1 * #{$total-height});

body {
min-height: calc((#{$inner-height} - #{$total-frame-height}) / #{$scale});
// Expands main content area.
// See: https://github.com/WordPress/gutenberg/pull/59512
&,
> body,
> body > .is-root-container:not(.wp-block-post-content) {
display: flex;
flex-direction: column;
flex: 1; // Doesn’t effect the html element but grouping is simpler this way.
}

> .is-root-container:not(.wp-block-post-content) {
flex: 1;
display: flex;
flex-direction: column;
height: 100%;

> main {
flex: 1;
}
}
> body > .is-root-container:not(.wp-block-post-content) > main {
flex: 1;
}
}

.block-editor-iframe__body {
position: relative;
}
Loading
Loading