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 1 commit
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
42 changes: 22 additions & 20 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 @@ -34,37 +35,36 @@ import { unlock } from '../../lock-unlock';

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

function BlockInspectorLockedBlocks( { topLevelLockedBlock } ) {
const { getBlockName, getBlockEditingMode } = useSelect( blockEditorStore );
const { contentClientIds, hasBlockStyles } = useSelect(
( select ) => {
const {
getClientIdsOfDescendants,
getBlockName,
getBlockEditingMode,
} = select( blockEditorStore );
const { getClientIdsOfDescendants } = select( blockEditorStore );
const { getBlockStyles } = select( blocksStore );
return {
contentClientIds: getClientIdsOfDescendants(
topLevelLockedBlock
).filter(
( clientId ) =>
getBlockName( clientId ) !== 'core/list-item' &&
getBlockEditingMode( clientId ) === 'contentOnly'
),
contentClientIds:
getClientIdsOfDescendants( topLevelLockedBlock ),
hasBlockStyles: !! getBlockStyles(
getBlockName( topLevelLockedBlock )
)?.length,
};
},
[ topLevelLockedBlock ]
[ topLevelLockedBlock, getBlockName ]
);
const eligibleContentClientIds = useMemo(
() =>
contentClientIds.filter(
( clientId ) =>
getBlockName( clientId ) !== 'core/list-item' &&
getBlockEditingMode( clientId ) === 'contentOnly'
),
[ contentClientIds, getBlockName, getBlockEditingMode ]
ntsekouras marked this conversation as resolved.
Show resolved Hide resolved
);
const blockInformation = useBlockDisplayInformation( topLevelLockedBlock );
return (
Expand All @@ -78,9 +78,11 @@ function BlockInspectorLockedBlocks( { topLevelLockedBlock } ) {
{ hasBlockStyles && (
<BlockStylesPanel clientId={ topLevelLockedBlock } />
) }
{ contentClientIds.length > 0 && (
{ eligibleContentClientIds.length > 0 && (
<PanelBody title={ __( 'Content' ) }>
<BlockQuickNavigation clientIds={ contentClientIds } />
<BlockQuickNavigation
clientIds={ eligibleContentClientIds }
/>
</PanelBody>
) }
</div>
Expand Down
Loading