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

Iframe: scale html instead of iframe el for zoom out #59334

Merged
merged 4 commits into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,8 @@ _::-webkit-full-page-media, _:future, :root .has-multi-selection .block-editor-b
}
}

.block-editor-iframe__body {
.block-editor-iframe__html {
transition: all 0.3s;
background-color: $gray-300;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This background color appears to affect the entire editor canvas. See #59348

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we'll have to only apply it for zoom out

transform-origin: top center;
}
32 changes: 18 additions & 14 deletions packages/block-editor/src/components/iframe/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ function Iframe( {
tabIndex = 0,
scale = 1,
frameSize = 0,
expand = false,
readonly,
forwardedRef: ref,
...props
Expand Down Expand Up @@ -139,6 +138,8 @@ function Iframe( {
const { documentElement } = contentDocument;
iFrameDocument = contentDocument;

documentElement.classList.add( 'block-editor-iframe__html' );

clearerRef( documentElement );

// Ideally ALL classes that are added through get_body_class should
Expand Down Expand Up @@ -241,6 +242,21 @@ function Iframe( {
// top or bottom margin is 0.55 / 2 ((1 - scale) / 2).
const marginFromScaling = ( contentHeight * ( 1 - scale ) ) / 2;

useEffect( () => {
if ( iframeDocument && scale !== 1 ) {
iframeDocument.documentElement.style.transform = `scale( ${ scale } )`;
iframeDocument.documentElement.style.marginTop = `${ frameSize }px`;
iframeDocument.documentElement.style.marginBottom = `${
-marginFromScaling * 2 + frameSize
}px`;
return () => {
iframeDocument.documentElement.style.transform = '';
iframeDocument.documentElement.style.marginTop = '';
iframeDocument.documentElement.style.marginBottom = '';
};
}
}, [ scale, frameSize, marginFromScaling, iframeDocument ] );

return (
<>
{ tabIndex >= 0 && before }
Expand All @@ -250,19 +266,7 @@ function Iframe( {
style={ {
border: 0,
...props.style,
height: expand ? contentHeight : props.style?.height,
marginTop:
scale !== 1
? -marginFromScaling + frameSize
: props.style?.marginTop,
marginBottom:
scale !== 1
? -marginFromScaling + frameSize
: props.style?.marginBottom,
transform:
scale !== 1
? `scale( ${ scale } )`
: props.style?.transform,
height: props.style?.height,
transition: 'all .3s',
} }
ref={ useMergeRefs( [ ref, setRef ] ) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function ResizableBoxPopover( {
return (
<BlockPopoverCover
clientId={ clientId }
__unstablePopoverSlot="__unstable-block-tools-after"
__unstablePopoverSlot="block-toolbar"
{ ...props }
>
<ResizableBox { ...resizableBoxProps } />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ function EditorCanvas( { enableResizing, settings, children, ...props } ) {
renderAppender={ showBlockAppender }
styles={ styles }
iframeProps={ {
expand: isZoomOutMode,
scale: isZoomOutMode ? 0.45 : undefined,
frameSize: isZoomOutMode ? 100 : undefined,
className: classnames(
Expand Down
3 changes: 0 additions & 3 deletions packages/edit-site/src/components/block-editor/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
position: relative;
height: 100%;
display: block;
overflow: hidden;
background-color: $gray-300;
// Centralize the editor horizontally (flex-direction is column).
align-items: center;
Expand Down Expand Up @@ -62,8 +61,6 @@

.components-resizable-box__container {
margin: 0 auto;
// Removing this will cancel the bottom margins in the iframe.
overflow: auto;
}

&.is-view-mode {
Expand Down
2 changes: 1 addition & 1 deletion packages/edit-site/src/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ body.js.site-editor-php {
}

.interface-interface-skeleton__content {
background-color: $gray-900;
background-color: $gray-300;
}
}

Expand Down
Loading