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

Enter zoom-out mode when selecting patterns in the inserter #56772

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion packages/block-editor/src/components/inserter/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from '@wordpress/element';
import { VisuallyHidden, SearchControl, Popover } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';
import { useSelect, useDispatch } from '@wordpress/data';
import { useDebouncedInput } from '@wordpress/compose';

/**
Expand Down Expand Up @@ -57,6 +57,8 @@ function InserterMenu(
const [ selectedMediaCategory, setSelectedMediaCategory ] =
useState( null );
const [ selectedTab, setSelectedTab ] = useState( null );
const { __unstableGetEditorMode } = useSelect( blockEditorStore );
const { __unstableSetEditorMode } = useDispatch( blockEditorStore );

const [ destinationRootClientId, onInsertBlocks, onToggleInsertionPoint ] =
useInsertionPoint( {
Expand Down Expand Up @@ -228,6 +230,14 @@ function InserterMenu(
if ( value !== 'patterns' ) {
setSelectedPatternCategory( null );
}

// Enter the zoom-out mode when selecting the patterns tab and exit otherwise.
if ( value === 'patterns' ) {
__unstableSetEditorMode( 'zoom-out' );
} else if ( __unstableGetEditorMode() === 'zoom-out' ) {
__unstableSetEditorMode( 'edit' );
}

setSelectedTab( value );
};

Expand Down
13 changes: 13 additions & 0 deletions packages/edit-site/src/components/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ export default function Editor( { listViewToggleElement, isLoading } ) {
};
}, [] );
const { setRenderingMode } = useDispatch( editorStore );
const { __unstableGetEditorMode: getBlockEditorMode } =
useSelect( blockEditorStore );
const { __unstableSetEditorMode: setBlockEditorMode } =
useDispatch( blockEditorStore );

const isViewMode = canvasMode === 'view';
const isEditMode = canvasMode === 'edit';
Expand Down Expand Up @@ -202,6 +206,15 @@ export default function Editor( { listViewToggleElement, isLoading } ) {
}
}, [ canvasMode, postWithTemplate, setRenderingMode ] );

useEffect(
function ExitZoomOutModeWhenInserterClosed() {
if ( ! shouldShowInserter && getBlockEditorMode() === 'zoom-out' ) {
setBlockEditorMode( 'edit' );
}
},
[ getBlockEditorMode, setBlockEditorMode, shouldShowInserter ]
);

return (
<>
{ ! isReady ? <CanvasLoader id={ loadingProgressId } /> : null }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ export default function InserterSidebar() {
const [ inserterDialogRef, inserterDialogProps ] = useDialog( {
onClose: () => setIsInserterOpened( false ),
focusOnMount: null,
// Don't close the inserter on focus outside.
// This is a temporary hack as we figure out the expected interactions
// in the zoom-out mode.
__unstableOnClose: ( eventName ) => {
if ( eventName === 'focus-outside' ) {
// Do nothing.
}
},
} );

const libraryRef = useRef();
Expand Down