Skip to content

Commit

Permalink
Removes command context when Style Book/Revisions open
Browse files Browse the repository at this point in the history
  • Loading branch information
creativecoder committed Jun 25, 2024
1 parent 759d242 commit 4000088
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 22 deletions.
12 changes: 10 additions & 2 deletions packages/edit-site/src/components/editor-canvas-container/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
* WordPress dependencies
*/
import { Children, cloneElement, useState } from '@wordpress/element';
import { Button } from '@wordpress/components';
import {
Button,
__experimentalUseSlotFills as useSlotFills,
} from '@wordpress/components';
import { ESCAPE } from '@wordpress/keycodes';
import { __ } from '@wordpress/i18n';
import { useDispatch, useSelect } from '@wordpress/data';
Expand Down Expand Up @@ -147,5 +150,10 @@ function EditorCanvasContainer( {
);
}

function useHasEditorCanvasContainer() {
const fills = useSlotFills( EditorContentSlotFill.privateKey );
return !! fills?.length;
}

export default EditorCanvasContainer;
export { getEditorCanvasContainerTitleAndIcon };
export { useHasEditorCanvasContainer, getEditorCanvasContainerTitleAndIcon };
10 changes: 6 additions & 4 deletions packages/edit-site/src/components/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,17 @@ import { useSpecificEditorSettings } from '../block-editor/use-site-editor-setti
import PluginTemplateSettingPanel from '../plugin-template-setting-panel';
import GlobalStylesSidebar from '../global-styles-sidebar';
import { isPreviewingTheme } from '../../utils/is-previewing-theme';
import { getEditorCanvasContainerTitleAndIcon } from '../editor-canvas-container';
import {
getEditorCanvasContainerTitleAndIcon,
useHasEditorCanvasContainer,
} from '../editor-canvas-container';
import SaveButton from '../save-button';
import SiteEditorMoreMenu from '../more-menu';
import SiteIcon from '../site-icon';
import useEditorIframeProps from '../block-editor/use-editor-iframe-props';
import useEditorTitle from './use-editor-title';

const { Editor, BackButton, useHasEditorContentOverlay } =
unlock( editorPrivateApis );
const { Editor, BackButton } = unlock( editorPrivateApis );
const { useHistory } = unlock( routerPrivateApis );
const { BlockKeyboardShortcuts } = unlock( blockLibraryPrivateApis );

Expand Down Expand Up @@ -91,7 +93,7 @@ export default function EditSiteEditor( { isLoading } ) {
}, [] );
useEditorTitle();
const _isPreviewingTheme = isPreviewingTheme();
const hasDefaultEditorCanvasView = ! useHasEditorContentOverlay();
const hasDefaultEditorCanvasView = ! useHasEditorCanvasContainer();
const iframeProps = useEditorIframeProps();
const isEditMode = canvasMode === 'edit';
const postWithTemplate = !! contextPostId;
Expand Down
12 changes: 12 additions & 0 deletions packages/edit-site/src/hooks/commands/use-set-command-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { store as blockEditorStore } from '@wordpress/block-editor';
*/
import { store as editSiteStore } from '../../store';
import { unlock } from '../../lock-unlock';
import { useHasEditorCanvasContainer } from '../../components/editor-canvas-container';

const { useCommandContext } = unlock( commandsPrivateApis );

Expand All @@ -25,6 +26,9 @@ export default function useSetCommandContext() {
hasBlockSelected: getBlockSelectionStart(),
};
}, [] );

const hasEditorCanvasContainer = useHasEditorCanvasContainer();

// Sets the right context for the command palette
let commandContext = 'site-editor';
if ( canvasMode === 'edit' ) {
Expand All @@ -33,5 +37,13 @@ export default function useSetCommandContext() {
if ( hasBlockSelected ) {
commandContext = 'block-selection-edit';
}
if ( hasEditorCanvasContainer ) {
/*
* The editor canvas overlay will likely be deprecated in the future, so for now we clear the command context
* to remove the suggested commands that may not make sense with Style Book or Style Revisions open.
* See https://github.com/WordPress/gutenberg/issues/62216.
*/
commandContext = '';
}
useCommandContext( commandContext );
}
4 changes: 1 addition & 3 deletions packages/editor/src/components/commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import { store as editorStore } from '../../store';
import { PATTERN_POST_TYPE } from '../../store/constants';
import { modalName as patternRenameModalName } from '../pattern-rename-modal';
import { modalName as patternDuplicateModalName } from '../pattern-duplicate-modal';
import { useHasEditorContentOverlay } from '../editor-interface/content-slot-fill';

function useEditorCommandLoader() {
const {
Expand Down Expand Up @@ -300,10 +299,9 @@ function useEditedEntityContextualCommands() {
};
}, [] );
const { openModal } = useDispatch( interfaceStore );
const hasEditorContentOverlay = useHasEditorContentOverlay();
const commands = [];

if ( ! hasEditorContentOverlay && postType === PATTERN_POST_TYPE ) {
if ( postType === PATTERN_POST_TYPE ) {
commands.push( {
name: 'core/rename-pattern',
label: __( 'Rename pattern' ),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
/**
* WordPress dependencies
*/
import {
privateApis as componentsPrivateApis,
__experimentalUseSlotFills as useSlotFills,
} from '@wordpress/components';
import { privateApis as componentsPrivateApis } from '@wordpress/components';

/**
* Internal dependencies
Expand All @@ -15,9 +12,4 @@ const { createPrivateSlotFill } = unlock( componentsPrivateApis );
const SLOT_FILL_NAME = 'EditCanvasContainerSlot';
const EditorContentSlotFill = createPrivateSlotFill( SLOT_FILL_NAME );

export function useHasEditorContentOverlay() {
const fills = useSlotFills( EditorContentSlotFill.privateKey );
return !! fills?.length;
}

export default EditorContentSlotFill;
5 changes: 1 addition & 4 deletions packages/editor/src/private-apis.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import * as interfaceApis from '@wordpress/interface';
*/
import { lock } from './lock-unlock';
import { EntitiesSavedStatesExtensible } from './components/entities-saved-states';
import EditorContentSlotFill, {
useHasEditorContentOverlay,
} from './components/editor-interface/content-slot-fill';
import EditorContentSlotFill from './components/editor-interface/content-slot-fill';
import useBlockEditorSettings from './components/provider/use-block-editor-settings';
import BackButton from './components/header/back-button';
import CreateTemplatePartModal from './components/create-template-part-modal';
Expand Down Expand Up @@ -46,7 +44,6 @@ lock( privateApis, {

// This is a temporary private API while we're updating the site editor to use EditorProvider.
useBlockEditorSettings,
useHasEditorContentOverlay,
interfaceStore,
...remainingInterfaceApis,
} );

0 comments on commit 4000088

Please sign in to comment.