Skip to content

Commit

Permalink
ContentOnly: Add support for block styles on top-level contentOnly lo…
Browse files Browse the repository at this point in the history
…cked blocks (WordPress#64872)

Co-authored-by: ntsekouras <ntsekouras@git.wordpress.org>
Co-authored-by: richtabor <richtabor@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
  • Loading branch information
4 people authored and bph committed Aug 31, 2024
1 parent 0a3c48a commit e813eb2
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions packages/block-editor/src/components/block-inspector/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ import { useBorderPanelLabel } from '../../hooks/border';

import { unlock } from '../../lock-unlock';

function BlockStylesPanel( { clientId } ) {
return (
<PanelBody title={ __( 'Styles' ) }>
<BlockStyles clientId={ clientId } />
</PanelBody>
);
}

function BlockInspectorLockedBlocks( { topLevelLockedBlock } ) {
const contentClientIds = useSelect(
( select ) => {
Expand All @@ -48,6 +56,15 @@ function BlockInspectorLockedBlocks( { topLevelLockedBlock } ) {
},
[ topLevelLockedBlock ]
);
const hasBlockStyles = useSelect(
( select ) => {
const { getBlockName } = select( blockEditorStore );
const { getBlockStyles } = select( blocksStore );
return !! getBlockStyles( getBlockName( topLevelLockedBlock ) )
?.length;
},
[ topLevelLockedBlock ]
);
const blockInformation = useBlockDisplayInformation( topLevelLockedBlock );
return (
<div className="block-editor-block-inspector">
Expand All @@ -57,6 +74,9 @@ function BlockInspectorLockedBlocks( { topLevelLockedBlock } ) {
/>
<BlockVariationTransforms blockClientId={ topLevelLockedBlock } />
<BlockInfo.Slot />
{ hasBlockStyles && (
<BlockStylesPanel clientId={ topLevelLockedBlock } />
) }
{ contentClientIds.length > 0 && (
<PanelBody title={ __( 'Content' ) }>
<BlockQuickNavigation clientIds={ contentClientIds } />
Expand All @@ -81,7 +101,6 @@ const BlockInspector = ( { showNoBlockSelectedMessage = true } ) => {
getContentLockingParent,
getTemplateLock,
} = unlock( select( blockEditorStore ) );

const _selectedBlockClientId = getSelectedBlockClientId();
const _selectedBlockName =
_selectedBlockClientId && getBlockName( _selectedBlockClientId );
Expand Down Expand Up @@ -276,11 +295,7 @@ const BlockInspectorSingleBlock = ( { clientId, blockName } ) => {
{ ! showTabs && (
<>
{ hasBlockStyles && (
<div>
<PanelBody title={ __( 'Styles' ) }>
<BlockStyles clientId={ clientId } />
</PanelBody>
</div>
<BlockStylesPanel clientId={ clientId } />
) }
<InspectorControls.Slot />
<InspectorControls.Slot group="list" />
Expand Down

0 comments on commit e813eb2

Please sign in to comment.