diff --git a/packages/edit-site/src/components/editor-canvas-container/index.js b/packages/edit-site/src/components/editor-canvas-container/index.js index 3c3157e462c485..c8fcca4a3a99c2 100644 --- a/packages/edit-site/src/components/editor-canvas-container/index.js +++ b/packages/edit-site/src/components/editor-canvas-container/index.js @@ -5,6 +5,7 @@ import { Children, cloneElement, useState, useMemo } from '@wordpress/element'; import { Button, privateApis as componentsPrivateApis, + __experimentalUseSlotFills as useSlotFills, } from '@wordpress/components'; import { ESCAPE } from '@wordpress/keycodes'; import { __ } from '@wordpress/i18n'; @@ -25,7 +26,7 @@ import { store as editSiteStore } from '../../store'; * * @return {string} Translated string corresponding to value of view. Default is ''. */ -export function getEditorCanvasContainerTitle( view ) { +function getEditorCanvasContainerTitle( view ) { switch ( view ) { case 'style-book': return __( 'Style Book' ); @@ -37,8 +38,11 @@ export function getEditorCanvasContainerTitle( view ) { // Creates a private slot fill. const { createPrivateSlotFill } = unlock( componentsPrivateApis ); const SLOT_FILL_NAME = 'EditSiteEditorCanvasContainerSlot'; -const { Slot: EditorCanvasContainerSlot, Fill: EditorCanvasContainerFill } = - createPrivateSlotFill( SLOT_FILL_NAME ); +const { + privateKey, + Slot: EditorCanvasContainerSlot, + Fill: EditorCanvasContainerFill, +} = createPrivateSlotFill( SLOT_FILL_NAME ); function EditorCanvasContainer( { children, @@ -110,6 +114,11 @@ function EditorCanvasContainer( { ); } +function useHasEditorCanvasContainer() { + const fills = useSlotFills( privateKey ); + return !! fills?.length; +} EditorCanvasContainer.Slot = EditorCanvasContainerSlot; export default EditorCanvasContainer; +export { useHasEditorCanvasContainer, getEditorCanvasContainerTitle }; diff --git a/packages/edit-site/src/components/header-edit-mode/index.js b/packages/edit-site/src/components/header-edit-mode/index.js index 494e115863ee56..3f931ef0fb60fd 100644 --- a/packages/edit-site/src/components/header-edit-mode/index.js +++ b/packages/edit-site/src/components/header-edit-mode/index.js @@ -38,7 +38,10 @@ import UndoButton from './undo-redo/undo'; import RedoButton from './undo-redo/redo'; import DocumentActions from './document-actions'; import { store as editSiteStore } from '../../store'; -import { getEditorCanvasContainerTitle } from '../editor-canvas-container'; +import { + getEditorCanvasContainerTitle, + useHasEditorCanvasContainer, +} from '../editor-canvas-container'; import { unlock } from '../../private-apis'; const preventDefault = ( event ) => { @@ -122,7 +125,7 @@ export default function HeaderEditMode() { [ setIsListViewOpened, isListViewOpen ] ); - const hasDefaultEditorCanvasView = ! editorCanvasView; + const hasDefaultEditorCanvasView = ! useHasEditorCanvasContainer(); const isFocusMode = templateType === 'wp_template_part'; diff --git a/packages/edit-site/src/components/sidebar-edit-mode/global-styles-sidebar.js b/packages/edit-site/src/components/sidebar-edit-mode/global-styles-sidebar.js index d22c08efb6f8c5..b4513e3df5e1a2 100644 --- a/packages/edit-site/src/components/sidebar-edit-mode/global-styles-sidebar.js +++ b/packages/edit-site/src/components/sidebar-edit-mode/global-styles-sidebar.js @@ -21,27 +21,29 @@ export default function GlobalStylesSidebar() { const { shouldClearCanvasContainerView, isStyleBookOpened } = useSelect( ( select ) => { const { getActiveComplementaryArea } = select( interfaceStore ); + const { getEditorCanvasContainerView, getCanvasMode } = unlock( + select( editSiteStore ) + ); const _isVisualEditorMode = 'visual' === select( editSiteStore ).getEditorMode(); + const _isEditCanvasMode = 'edit' === getCanvasMode(); return { isStyleBookOpened: - 'style-book' === - unlock( - select( editSiteStore ) - ).getEditorCanvasContainerView(), + 'style-book' === getEditorCanvasContainerView(), shouldClearCanvasContainerView: 'edit-site/global-styles' !== getActiveComplementaryArea( 'core/edit-site' ) || - ! _isVisualEditorMode, + ! _isVisualEditorMode || + ! _isEditCanvasMode, }; }, [] ); - const { setEditorCanvasContainerView } = unlock( useDispatch( editSiteStore ) ); + useEffect( () => { if ( shouldClearCanvasContainerView ) { setEditorCanvasContainerView( undefined );