diff --git a/packages/block-editor/src/components/iframe/index.js b/packages/block-editor/src/components/iframe/index.js index 669e2fe25a9fbb..3a0823f1c3cd47 100644 --- a/packages/block-editor/src/components/iframe/index.js +++ b/packages/block-editor/src/components/iframe/index.js @@ -242,10 +242,8 @@ function Iframe( { const isZoomedOut = scale !== 1; useEffect( () => { - if ( ! isZoomedOut ) { - prevContainerWidth.current = containerWidth; - } - }, [ containerWidth, isZoomedOut ] ); + prevContainerWidth.current = containerWidth; + }, [ containerWidth ] ); const disabledRef = useDisabled( { isDisabled: ! readonly } ); const bodyRef = useMergeRefs( [ diff --git a/packages/block-editor/src/components/inserter/menu.js b/packages/block-editor/src/components/inserter/menu.js index 17a98570843014..d3f2fd1831d426 100644 --- a/packages/block-editor/src/components/inserter/menu.js +++ b/packages/block-editor/src/components/inserter/menu.js @@ -10,6 +10,7 @@ import { forwardRef, useState, useCallback, + useEffect, useMemo, useRef, useLayoutEffect, @@ -17,7 +18,7 @@ import { import { VisuallyHidden, SearchControl, Popover } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; import { useDebouncedInput } from '@wordpress/compose'; -import { useSelect } from '@wordpress/data'; +import { useSelect, useDispatch } from '@wordpress/data'; /** * Internal dependencies @@ -32,7 +33,6 @@ import InserterSearchResults from './search-results'; import useInsertionPoint from './hooks/use-insertion-point'; import { store as blockEditorStore } from '../../store'; import TabbedSidebar from '../tabbed-sidebar'; -import { useZoomOut } from '../../hooks/use-zoom-out'; const NOOP = () => {}; function InserterMenu( @@ -149,7 +149,18 @@ function InserterMenu( const showZoomOut = showPatternPanel && !! window.__experimentalEnableZoomedOutPatternsTab; - useZoomOut( showZoomOut ); + const { __unstableSetEditorMode } = useDispatch( blockEditorStore ); + useEffect( () => { + if ( showZoomOut ) { + __unstableSetEditorMode( 'zoom-out' ); + } + + return () => { + if ( showZoomOut ) { + __unstableSetEditorMode( 'edit' ); // TODO: set back to whatever it was previously + } + }; + }, [ showZoomOut ] ); const inserterSearch = useMemo( () => { if ( selectedTab === 'media' ) { diff --git a/packages/editor/src/components/header/index.js b/packages/editor/src/components/header/index.js index 2a604229596005..b8eda30c721860 100644 --- a/packages/editor/src/components/header/index.js +++ b/packages/editor/src/components/header/index.js @@ -57,7 +57,6 @@ function Header( { showIconLabels, hasFixedToolbar, isNestedEntity, - isZoomedOutView, } = useSelect( ( select ) => { const { get: getPreference } = select( preferencesStore ); const { @@ -136,7 +135,7 @@ function Header( { ) } { + if ( __unstableGetEditorMode() === 'zoom-out' ) { + return __( '50%' ); + } + return __( '100%' ); + }; + + const getIcon = () => { + if ( isZoomOutExperiment && deviceType === 'Desktop' ) { + return zoomIcon; + } + return deviceIcons[ deviceType.toLowerCase() ]; + }; + + function handleDevicePreviewClick( targetDeviceType, editorMode ) { + if ( isZoomOutExperiment ) { + __unstableSetEditorMode( editorMode ); + } + setDeviceType( targetDeviceType ); + } + return ( @@ -76,19 +103,53 @@ export default function PreviewDropdown( { forceIsAutosaveable, disabled } ) { <> setDeviceType( 'Desktop' ) } - icon={ deviceType === 'Desktop' && check } + onClick={ () => { + handleDevicePreviewClick( 'Desktop', 'edit' ); // Rather than setting to edit, we may need to set back to whatever it was previously. + } } + icon={ + deviceType === 'Desktop' && + __unstableGetEditorMode() !== 'zoom-out' && + check + } > - { __( 'Desktop' ) } + { isZoomOutExperiment + ? __( 'Zoom to 100%' ) + : __( 'Desktop' ) } + { isZoomOutExperiment && ( + { + handleDevicePreviewClick( + 'Desktop', + 'zoom-out' + ); + } } + icon={ + __unstableGetEditorMode() === 'zoom-out' && + check + } + > + { __( 'Zoom to 50%' ) } + + ) } setDeviceType( 'Tablet' ) } + onClick={ () => { + handleDevicePreviewClick( + 'Tablet', + 'edit' // Rather than setting to edit, we may need to set back to whatever it was previously. + ); + } } icon={ deviceType === 'Tablet' && check } > { __( 'Tablet' ) } setDeviceType( 'Mobile' ) } + onClick={ () => { + handleDevicePreviewClick( + 'Mobile', + 'edit' // Rather than setting to edit, we may need to set back to whatever it was previously. + ); + } } icon={ deviceType === 'Mobile' && check } > { __( 'Mobile' ) } diff --git a/packages/editor/src/components/visual-editor/index.js b/packages/editor/src/components/visual-editor/index.js index 8b4877704f5f18..a67feb530e96a2 100644 --- a/packages/editor/src/components/visual-editor/index.js +++ b/packages/editor/src/components/visual-editor/index.js @@ -107,6 +107,7 @@ function VisualEditor( { } ) { const [ resizeObserver, sizes ] = useResizeObserver(); const isMobileViewport = useViewportMatch( 'small', '<' ); + const isTabletViewport = useViewportMatch( 'medium', '<' ); const { renderingMode, postContentAttributes, @@ -341,12 +342,13 @@ function VisualEditor( { } ), ] ); - const zoomOutProps = isZoomOutMode - ? { - scale: 'default', - frameSize: '48px', - } - : {}; + const zoomOutProps = + isZoomOutMode && ! isTabletViewport + ? { + scale: 'default', + frameSize: '48px', + } + : {}; const forceFullHeight = postType === NAVIGATION_POST_TYPE; const enableResizing =