diff --git a/packages/block-editor/src/components/block-tools/style.scss b/packages/block-editor/src/components/block-tools/style.scss
index c5920bdf2f7d38..e77654619255b9 100644
--- a/packages/block-editor/src/components/block-tools/style.scss
+++ b/packages/block-editor/src/components/block-tools/style.scss
@@ -262,3 +262,11 @@
.is-dragging-components-draggable .components-tooltip {
display: none;
}
+
+.components-popover.block-editor-block-popover__inbetween .block-editor-button-pattern-inserter__button {
+ pointer-events: all;
+ position: absolute;
+ transform: translateX(-50%) translateY(-50%);
+ top: 50%;
+ left: 50%;
+}
diff --git a/packages/block-editor/src/components/block-tools/zoom-out-mode-inserters.js b/packages/block-editor/src/components/block-tools/zoom-out-mode-inserters.js
index 5fad0e54e38a68..4396f54b19707b 100644
--- a/packages/block-editor/src/components/block-tools/zoom-out-mode-inserters.js
+++ b/packages/block-editor/src/components/block-tools/zoom-out-mode-inserters.js
@@ -2,25 +2,56 @@
* WordPress dependencies
*/
import { useSelect } from '@wordpress/data';
-import { useEffect, useState } from '@wordpress/element';
+import { useEffect, useRef, useState } from '@wordpress/element';
+import { Button } from '@wordpress/components';
+import { plus } from '@wordpress/icons';
+import { _x } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import BlockPopoverInbetween from '../block-popover/inbetween';
import { store as blockEditorStore } from '../../store';
-import Inserter from '../inserter';
import { unlock } from '../../lock-unlock';
-function ZoomOutModeInserters( { __unstableContentRef } ) {
+function ZoomOutModeInserters() {
const [ isReady, setIsReady ] = useState( false );
- const blockOrder = useSelect( ( select ) => {
- const { sectionRootClientId } = unlock(
- select( blockEditorStore ).getSettings()
- );
- return select( blockEditorStore ).getBlockOrder( sectionRootClientId );
+ const {
+ blockOrder,
+ sectionRootClientId,
+ insertionPoint,
+ setInserterIsOpened,
+ } = useSelect( ( select ) => {
+ const { getSettings, getBlockOrder } = select( blockEditorStore );
+ const { sectionRootClientId: root } = unlock( getSettings() );
+ // To do: move ZoomOutModeInserters to core/editor.
+ // Or we perhaps we should move the insertion point state to the
+ // block-editor store. I'm not sure what it was ever moved to the editor
+ // store, because all the inserter components all live in the
+ // block-editor package.
+ // eslint-disable-next-line @wordpress/data-no-store-string-literals
+ const editor = select( 'core/editor' );
+ return {
+ blockOrder: getBlockOrder( root ),
+ insertionPoint: unlock( editor ).getInsertionPoint(),
+ sectionRootClientId: root,
+ setInserterIsOpened:
+ getSettings().__experimentalSetIsInserterOpened,
+ };
}, [] );
+ const isMounted = useRef( false );
+
+ useEffect( () => {
+ if ( ! isMounted.current ) {
+ isMounted.current = true;
+ return;
+ }
+ // reset insertion point when the block order changes
+ setInserterIsOpened( true );
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [ blockOrder ] );
+
// Defer the initial rendering to avoid the jumps due to the animation.
useEffect( () => {
const timeout = setTimeout( () => {
@@ -41,15 +72,39 @@ function ZoomOutModeInserters( { __unstableContentRef } ) {
key={ index }
previousClientId={ clientId }
nextClientId={ blockOrder[ index ] }
- __unstableContentRef={ __unstableContentRef }
>
-
-
+ ) }
+ { insertionPoint.insertionIndex !== index && (
+
+ ) }
);
} );
diff --git a/packages/block-editor/src/components/inserter/library.js b/packages/block-editor/src/components/inserter/library.js
index 7e9b366e5e3a74..6be31f49b5fbe1 100644
--- a/packages/block-editor/src/components/inserter/library.js
+++ b/packages/block-editor/src/components/inserter/library.js
@@ -20,6 +20,8 @@ function InserterLibrary(
showInserterHelpPanel,
showMostUsedBlocks = false,
__experimentalInsertionIndex,
+ __experimentalInitialTab,
+ __experimentalInitialCategory,
__experimentalFilterValue,
__experimentalOnPatternCategorySelection,
onSelect = noop,
@@ -53,6 +55,8 @@ function InserterLibrary(
__experimentalOnPatternCategorySelection={
__experimentalOnPatternCategorySelection
}
+ __experimentalInitialTab={ __experimentalInitialTab }
+ __experimentalInitialCategory={ __experimentalInitialCategory }
shouldFocusBlock={ shouldFocusBlock }
ref={ ref }
onClose={ onClose }
diff --git a/packages/block-editor/src/components/inserter/menu.js b/packages/block-editor/src/components/inserter/menu.js
index 979a3b8199f0b0..f30edcf13894cb 100644
--- a/packages/block-editor/src/components/inserter/menu.js
+++ b/packages/block-editor/src/components/inserter/menu.js
@@ -48,6 +48,8 @@ function InserterMenu(
shouldFocusBlock = true,
__experimentalOnPatternCategorySelection = NOOP,
onClose,
+ __experimentalInitialTab,
+ __experimentalInitialCategory,
},
ref
) {
@@ -59,12 +61,15 @@ function InserterMenu(
const [ filterValue, setFilterValue, delayedFilterValue ] =
useDebouncedInput( __experimentalFilterValue );
const [ hoveredItem, setHoveredItem ] = useState( null );
- const [ selectedPatternCategory, setSelectedPatternCategory ] =
- useState( null );
+ const [ selectedPatternCategory, setSelectedPatternCategory ] = useState(
+ __experimentalInitialCategory
+ );
const [ patternFilter, setPatternFilter ] = useState( 'all' );
const [ selectedMediaCategory, setSelectedMediaCategory ] =
useState( null );
- const [ selectedTab, setSelectedTab ] = useState( 'blocks' );
+ const [ selectedTab, setSelectedTab ] = useState(
+ __experimentalInitialTab
+ );
const [ destinationRootClientId, onInsertBlocks, onToggleInsertionPoint ] =
useInsertionPoint( {
@@ -306,6 +311,7 @@ function InserterMenu(
ref={ tabsRef }
onSelect={ handleSetSelectedTab }
onClose={ onClose }
+ selectedTab={ selectedTab }
>
{ inserterSearch }
{ selectedTab === 'blocks' &&
diff --git a/packages/block-editor/src/components/inserter/tabs.js b/packages/block-editor/src/components/inserter/tabs.js
index c1486dda6dbf27..d3ce5d80993d3f 100644
--- a/packages/block-editor/src/components/inserter/tabs.js
+++ b/packages/block-editor/src/components/inserter/tabs.js
@@ -33,12 +33,12 @@ const mediaTab = {
title: __( 'Media' ),
};
-function InserterTabs( { onSelect, children, onClose }, ref ) {
+function InserterTabs( { onSelect, children, onClose, selectedTab }, ref ) {
const tabs = [ blocksTab, patternsTab, mediaTab ];
return (
-
+