Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ContentOnly: Add support for block styles on top-level contentOnly locked blocks #64872

Merged
merged 3 commits into from
Aug 29, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 36 additions & 18 deletions packages/block-editor/src/components/block-inspector/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from '@wordpress/blocks';
import { PanelBody, __unstableMotion as motion } from '@wordpress/components';
import { useSelect } from '@wordpress/data';
import { useMemo } from '@wordpress/element';

/**
* Internal dependencies
Expand All @@ -32,21 +33,38 @@ 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(
const { getBlockName, getBlockEditingMode } = useSelect( blockEditorStore );
const { contentClientIds, hasBlockStyles } = useSelect(
( select ) => {
const {
getClientIdsOfDescendants,
getBlockName,
getBlockEditingMode,
} = select( blockEditorStore );
return getClientIdsOfDescendants( topLevelLockedBlock ).filter(
const { getClientIdsOfDescendants } = select( blockEditorStore );
const { getBlockStyles } = select( blocksStore );
return {
contentClientIds:
getClientIdsOfDescendants( topLevelLockedBlock ),
hasBlockStyles: !! getBlockStyles(
getBlockName( topLevelLockedBlock )
)?.length,
};
},
[ topLevelLockedBlock, getBlockName ]
);
const eligibleContentClientIds = useMemo(
() =>
contentClientIds.filter(
( clientId ) =>
getBlockName( clientId ) !== 'core/list-item' &&
getBlockEditingMode( clientId ) === 'contentOnly'
);
},
[ topLevelLockedBlock ]
),
[ contentClientIds, getBlockName, getBlockEditingMode ]
);
const blockInformation = useBlockDisplayInformation( topLevelLockedBlock );
return (
Expand All @@ -57,9 +75,14 @@ function BlockInspectorLockedBlocks( { topLevelLockedBlock } ) {
/>
<BlockVariationTransforms blockClientId={ topLevelLockedBlock } />
<BlockInfo.Slot />
{ contentClientIds.length > 0 && (
{ hasBlockStyles && (
<BlockStylesPanel clientId={ topLevelLockedBlock } />
) }
{ eligibleContentClientIds.length > 0 && (
<PanelBody title={ __( 'Content' ) }>
<BlockQuickNavigation clientIds={ contentClientIds } />
<BlockQuickNavigation
clientIds={ eligibleContentClientIds }
/>
</PanelBody>
) }
</div>
Expand All @@ -81,7 +104,6 @@ const BlockInspector = ( { showNoBlockSelectedMessage = true } ) => {
getContentLockingParent,
getTemplateLock,
} = unlock( select( blockEditorStore ) );

const _selectedBlockClientId = getSelectedBlockClientId();
const _selectedBlockName =
_selectedBlockClientId && getBlockName( _selectedBlockClientId );
Expand Down Expand Up @@ -276,11 +298,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
Loading