From 9c83e9efb8ae5d21c94c47122cb88a2e4968c8d8 Mon Sep 17 00:00:00 2001 From: Mitchell Austin Date: Sun, 30 Jun 2024 14:17:41 -0700 Subject: [PATCH 01/25] Remove iframe wrappers; have scrollbar visible; improve centering --- .../src/components/iframe/content.scss | 28 ++----------- .../src/components/iframe/index.js | 42 ++----------------- 2 files changed, 8 insertions(+), 62 deletions(-) diff --git a/packages/block-editor/src/components/iframe/content.scss b/packages/block-editor/src/components/iframe/content.scss index 90b887993bf6db..e9c280f703647b 100644 --- a/packages/block-editor/src/components/iframe/content.scss +++ b/packages/block-editor/src/components/iframe/content.scss @@ -2,25 +2,6 @@ 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; @@ -29,27 +10,26 @@ .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}); + margin-inline: calc(-50% / #{$scale} + 50%); background-color: $gray-300; + $frame-size: var(--wp-block-editor-iframe-zoom-out-frame-size); // 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. + $content-height: var(--wp-block-editor-iframe-zoom-out-content-height); $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 { + $inner-height: var(--wp-block-editor-iframe-zoom-out-inner-height); min-height: calc((#{$inner-height} - #{$total-frame-height}) / #{$scale}); display: flex; flex-direction: column; diff --git a/packages/block-editor/src/components/iframe/index.js b/packages/block-editor/src/components/iframe/index.js index 3e022cf95ae556..901a8f1008ac3c 100644 --- a/packages/block-editor/src/components/iframe/index.js +++ b/packages/block-editor/src/components/iframe/index.js @@ -309,8 +309,7 @@ function Iframe( { iframeDocument.documentElement.style.setProperty( '--wp-block-editor-iframe-zoom-out-scale', scale === 'default' - ? Math.min( containerWidth, maxWidth ) / - prevContainerWidthRef.current + ? Math.min( 1, containerWidth / prevContainerWidthRef.current ) : scale ); iframeDocument.documentElement.style.setProperty( @@ -325,14 +324,6 @@ function Iframe( { '--wp-block-editor-iframe-zoom-out-inner-height', `${ iframeWindowInnerHeight }px` ); - iframeDocument.documentElement.style.setProperty( - '--wp-block-editor-iframe-zoom-out-container-width', - `${ containerWidth }px` - ); - iframeDocument.documentElement.style.setProperty( - '--wp-block-editor-iframe-zoom-out-prev-container-width', - `${ prevContainerWidthRef.current }px` - ); return () => { iframeDocument.documentElement.classList.remove( 'is-zoomed-out' ); @@ -349,12 +340,6 @@ function Iframe( { iframeDocument.documentElement.style.removeProperty( '--wp-block-editor-iframe-zoom-out-inner-height' ); - iframeDocument.documentElement.style.removeProperty( - '--wp-block-editor-iframe-zoom-out-container-width' - ); - iframeDocument.documentElement.style.removeProperty( - '--wp-block-editor-iframe-zoom-out-prev-container-width' - ); }; }, [ scale, @@ -371,8 +356,9 @@ function Iframe( { // mode. They're only needed to capture focus in edit mode. const shouldRenderFocusCaptureElements = tabIndex >= 0 && ! isPreviewMode; - const iframe = ( + return ( <> + { containerResizeListener } { shouldRenderFocusCaptureElements && before } { /* eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions */ }