Skip to content

Commit

Permalink
hide block settings slot in content only and zoom out, allow copy in …
Browse files Browse the repository at this point in the history
…content only
  • Loading branch information
draganescu committed Dec 9, 2024
1 parent e772438 commit 8d86348
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,13 @@ export function BlockSettingsDropdown( {
clientId={ firstBlockClientId }
/>
) }
{ ( ! isContentOnly || isZoomOut ) && (
<CopyMenuItem
clientIds={ clientIds }
onCopy={ onCopy }
shortcut={ displayShortcut.primary(
'c'
) }
/>
) }
<CopyMenuItem
clientIds={ clientIds }
onCopy={ onCopy }
shortcut={ displayShortcut.primary(
'c'
) }
/>
{ canDuplicate && (
<MenuItem
onClick={ pipe(
Expand Down Expand Up @@ -316,14 +314,16 @@ export function BlockSettingsDropdown( {
</MenuItem>
</MenuGroup>
) }
<BlockSettingsMenuControls.Slot
fillProps={ {
onClose,
count,
firstBlockClientId,
} }
clientIds={ clientIds }
/>
{ ! isContentOnly && ! isZoomOut && (
<BlockSettingsMenuControls.Slot
fillProps={ {
onClose,
count,
firstBlockClientId,
} }
clientIds={ clientIds }
/>
) }
{ typeof children === 'function'
? children( { onClose } )
: Children.map( ( child ) =>
Expand Down
19 changes: 3 additions & 16 deletions packages/editor/src/components/provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
BlockEditorProvider,
BlockContextProvider,
privateApis as blockEditorPrivateApis,
store as blockEditorStore,
} from '@wordpress/block-editor';
import { store as noticesStore } from '@wordpress/notices';
import { privateApis as editPatternsPrivateApis } from '@wordpress/patterns';
Expand Down Expand Up @@ -207,14 +206,6 @@ export const ExperimentalEditorProvider = withRegistryProvider(
[ post.type ]
);

const isZoomOut = useSelect( ( select ) => {
const { isZoomOut: _isZoomOut } = unlock(
select( blockEditorStore )
);

return _isZoomOut();
} );

const shouldRenderTemplate = !! template && mode !== 'post-only';
const rootLevelPost = shouldRenderTemplate ? template : post;
const defaultBlockContext = useMemo( () => {
Expand Down Expand Up @@ -367,13 +358,9 @@ export const ExperimentalEditorProvider = withRegistryProvider(
{ children }
{ ! settings.isPreviewMode && (
<>
{ ! isZoomOut && (
<>
<PatternsMenuItems />
<TemplatePartMenuItems />
<ContentOnlySettingsMenu />
</>
) }
<PatternsMenuItems />
<TemplatePartMenuItems />
<ContentOnlySettingsMenu />
{ mode === 'template-locked' && (
<DisableNonPageContentBlocks />
) }
Expand Down
27 changes: 26 additions & 1 deletion packages/patterns/src/components/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,40 @@
/**
* WordPress dependencies
*/
import { BlockSettingsMenuControls } from '@wordpress/block-editor';
import {
BlockSettingsMenuControls,
store as blockEditorStore,
} from '@wordpress/block-editor';
import { useSelect } from '@wordpress/data';

/**
* Internal dependencies
*/
import PatternConvertButton from './pattern-convert-button';
import PatternsManageButton from './patterns-manage-button';
import { unlock } from '../lock-unlock';

export default function PatternsMenuItems( { rootClientId } ) {
const { isZoomOut, isContentOnly } = useSelect( ( select ) => {
const {
isZoomOut: _isZoomOut,
getBlockEditingMode,
getSelectedBlockClientIds,
} = unlock( select( blockEditorStore ) );

const selectedBlockClientIds = getSelectedBlockClientIds();
const firstBlockClientId = selectedBlockClientIds[ 0 ];
return {
isZoomOut: _isZoomOut(),
isContentOnly:
getBlockEditingMode( firstBlockClientId ) === 'contentOnly',
};
} );

if ( isZoomOut || isContentOnly ) {
return;
}

return (
<BlockSettingsMenuControls>
{ ( { selectedClientIds, onClose } ) => (
Expand Down

0 comments on commit 8d86348

Please sign in to comment.