diff --git a/packages/block-editor/src/components/inserter/block-patterns-tab.js b/packages/block-editor/src/components/inserter/block-patterns-tab.js
index fd96923114d0e..673b2bcbfca42 100644
--- a/packages/block-editor/src/components/inserter/block-patterns-tab.js
+++ b/packages/block-editor/src/components/inserter/block-patterns-tab.js
@@ -23,6 +23,7 @@ import {
} from '@wordpress/components';
import { Icon, chevronRight, chevronLeft } from '@wordpress/icons';
import { focus } from '@wordpress/dom';
+import { useSelect } from '@wordpress/data';
/**
* Internal dependencies
@@ -30,6 +31,7 @@ import { focus } from '@wordpress/dom';
import usePatternsState from './hooks/use-patterns-state';
import BlockPatternList from '../block-patterns-list';
import PatternsExplorerModal from './block-patterns-explorer/explorer';
+import { store as blockEditorStore } from '../../store';
function usePatternsCategories() {
const [ allPatterns, allCategories ] = usePatternsState();
@@ -97,6 +99,20 @@ export function BlockPatternsCategoryDialog( {
return () => clearTimeout( timeout );
}, [ category ] );
+ const { getSettings } = useSelect( blockEditorStore );
+ useEffect( () => {
+ if ( getSettings().__experimentalOnInserterPatternTabCategoryOpen ) {
+ getSettings().__experimentalOnInserterPatternTabCategoryOpen();
+ }
+ return () => {
+ if (
+ getSettings().__experimentalOnInserterPatternTabCategoryClose
+ ) {
+ return getSettings().__experimentalOnInserterPatternTabCategoryClose();
+ }
+ };
+ }, [] );
+
return (
{
const {
__experimentalAdditionalBlockPatterns,
@@ -133,8 +139,16 @@ export default function BlockEditor( { setIsInserterOpen } ) {
...restStoredSettings,
__experimentalBlockPatterns: blockPatterns,
__experimentalBlockPatternCategories: blockPatternCategories,
+ __experimentalOnInserterPatternTabCategoryOpen,
+ __experimentalOnInserterPatternTabCategoryClose,
};
- }, [ storedSettings, blockPatterns, blockPatternCategories ] );
+ }, [
+ storedSettings,
+ blockPatterns,
+ blockPatternCategories,
+ __experimentalOnInserterPatternTabCategoryOpen,
+ __experimentalOnInserterPatternTabCategoryClose,
+ ] );
const [ blocks, onInput, onChange ] = useEntityBlockEditor(
'postType',
diff --git a/packages/edit-site/src/components/block-editor/use-open-zoom-out-on-patterns.js b/packages/edit-site/src/components/block-editor/use-open-zoom-out-on-patterns.js
new file mode 100644
index 0000000000000..7d98a6671db13
--- /dev/null
+++ b/packages/edit-site/src/components/block-editor/use-open-zoom-out-on-patterns.js
@@ -0,0 +1,34 @@
+/**
+ * WordPress dependencies
+ */
+import { useSelect, useDispatch } from '@wordpress/data';
+import { useCallback, useRef, useEffect } from '@wordpress/element';
+import { store as blockEditorStore } from '@wordpress/block-editor';
+
+export default function useOpenZoomOutOnPatterns() {
+ const { mode } = useSelect( ( select ) => {
+ return {
+ mode: select( blockEditorStore ).__unstableGetEditorMode(),
+ };
+ }, [] );
+ const { __unstableSetEditorMode } = useDispatch( blockEditorStore );
+ const shouldRevertInitialMode = useRef( null );
+ useEffect( () => {
+ // ignore changes to zoom-out mode as we explictily change to it on mount.
+ if ( mode !== 'zoom-out' ) {
+ shouldRevertInitialMode.current = false;
+ }
+ }, [ mode ] );
+ return [
+ useCallback( () => {
+ __unstableSetEditorMode( 'zoom-out' );
+ shouldRevertInitialMode.current = true;
+ }, [] ),
+ useCallback( () => {
+ // if there were not mode changes revert to the initial mode when unmounting.
+ if ( shouldRevertInitialMode.current ) {
+ __unstableSetEditorMode( mode );
+ }
+ }, [] ),
+ ];
+}