Skip to content

Commit

Permalink
Zoom Out: Add a control to enter and leave zoom out mode
Browse files Browse the repository at this point in the history
  • Loading branch information
scruffian committed Jul 23, 2024
1 parent dd31d29 commit d5a7270
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
10 changes: 3 additions & 7 deletions packages/block-editor/src/components/inserter/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
import { VisuallyHidden, SearchControl, Popover } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useDebouncedInput } from '@wordpress/compose';
import { useSelect } from '@wordpress/data';
import { useDispatch, useSelect } from '@wordpress/data';

/**
* Internal dependencies
Expand All @@ -32,7 +32,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(
Expand All @@ -58,6 +57,7 @@ function InserterMenu(
select( blockEditorStore ).__unstableGetEditorMode() === 'zoom-out',
[]
);
const { __unstableSetEditorMode } = useDispatch( blockEditorStore );
const [ filterValue, setFilterValue, delayedFilterValue ] =
useDebouncedInput( __experimentalFilterValue );
const [ hoveredItem, setHoveredItem ] = useState( null );
Expand Down Expand Up @@ -135,6 +135,7 @@ function InserterMenu(
setSelectedPatternCategory( patternCategory );
setPatternFilter( filter );
onPatternCategorySelection?.();
__unstableSetEditorMode( 'zoom-out' );
},
[ setSelectedPatternCategory, onPatternCategorySelection ]
);
Expand All @@ -146,11 +147,6 @@ function InserterMenu(

const showMediaPanel = selectedTab === 'media' && !! selectedMediaCategory;

const showZoomOut =
showPatternPanel && !! window.__experimentalEnableZoomedOutPatternsTab;

useZoomOut( showZoomOut );

const inserterSearch = useMemo( () => {
if ( selectedTab === 'media' ) {
return null;
Expand Down
3 changes: 1 addition & 2 deletions packages/editor/src/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ function Header( {
showIconLabels,
hasFixedToolbar,
isNestedEntity,
isZoomedOutView,
} = useSelect( ( select ) => {
const { get: getPreference } = select( preferencesStore );
const {
Expand Down Expand Up @@ -136,7 +135,7 @@ function Header( {
) }
<PreviewDropdown
forceIsAutosaveable={ forceIsDirty }
disabled={ isNestedEntity || isZoomedOutView }
disabled={ isNestedEntity }
/>
<PostPreviewButton
className="editor-header__post-preview-button"
Expand Down
25 changes: 25 additions & 0 deletions packages/editor/src/components/preview-dropdown/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { check, desktop, mobile, tablet, external } from '@wordpress/icons';
import { useSelect, useDispatch } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import { store as preferencesStore } from '@wordpress/preferences';
import { store as blockEditorStore } from '@wordpress/block-editor';

/**
* Internal dependencies
Expand All @@ -37,6 +38,8 @@ export default function PreviewDropdown( { forceIsAutosaveable, disabled } ) {
};
}, [] );
const { setDeviceType } = useDispatch( editorStore );
const { __unstableSetEditorMode } = useDispatch( blockEditorStore );
const { __unstableGetEditorMode } = useSelect( blockEditorStore );
const isMobile = useViewportMatch( 'medium', '<' );
if ( isMobile ) {
return null;
Expand Down Expand Up @@ -94,6 +97,28 @@ export default function PreviewDropdown( { forceIsAutosaveable, disabled } ) {
{ __( 'Mobile' ) }
</MenuItem>
</MenuGroup>
{ !! window.__experimentalEnableZoomedOutPatternsTab && (
<MenuGroup>
{ __unstableGetEditorMode() !== 'zoom-out' && (
<MenuItem
onClick={ () =>
__unstableSetEditorMode( 'zoom-out' )
}
>
{ __( 'Zoom Out' ) }
</MenuItem>
) }
{ __unstableGetEditorMode() === 'zoom-out' && (
<MenuItem
onClick={ () =>
__unstableSetEditorMode( 'edit' )
}
>
{ __( 'Zoom In' ) }
</MenuItem>
) }
</MenuGroup>
) }
{ isTemplate && (
<MenuGroup>
<MenuItem
Expand Down

0 comments on commit d5a7270

Please sign in to comment.