Skip to content

Commit

Permalink
only show the off canvas list view for children of content only locke…
Browse files Browse the repository at this point in the history
…d parents
  • Loading branch information
draganescu committed Nov 12, 2024
1 parent 13172ef commit 54f5ef2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 16 deletions.
45 changes: 33 additions & 12 deletions packages/block-editor/src/components/block-inspector/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,19 +249,38 @@ const BlockInspectorSingleBlock = ( {
[ isSectionBlock, clientId ]
);

const { selectedContentClientId, isSelectedContentClientIdControlling } =
useSelect( ( select ) => {
const { getSelectedBlockClientId, areInnerBlocksControlled } =
select( blockEditorStore );
const {
selectedContentClientId,
isSelectedContentClientIdControlling,
isSelectedBlockInContentOnlyContainer,
} = useSelect( ( select ) => {
const {
getSelectedBlockClientId,
areInnerBlocksControlled,
getBlockRootClientId,
getTemplateLock,
} = select( blockEditorStore );

const _selectedBlockClientId = getSelectedBlockClientId();
const _isSelectedContentClientIdControlling = areInnerBlocksControlled(
_selectedBlockClientId
);

const rootClientId = getBlockRootClientId( _selectedBlockClientId );
const templateLock = getTemplateLock( rootClientId );

const _isSelectedBlockInContentOnlyContainer =
templateLock === 'contentOnly';

const _selectedBlockClientId = getSelectedBlockClientId();
return {
selectedContentClientId: _selectedBlockClientId,
isSelectedContentClientIdControlling: areInnerBlocksControlled(
_selectedBlockClientId
),
};
} );
return {
selectedContentClientId: _selectedBlockClientId,
isSelectedContentClientIdControlling:
_isSelectedContentClientIdControlling,
isSelectedBlockInContentOnlyContainer:
_isSelectedBlockInContentOnlyContainer,
hasContentLockedParent: false,
};
} );
const { __unstableGetEditorMode } = useSelect( blockEditorStore );
const editorMode = __unstableGetEditorMode();

Expand Down Expand Up @@ -298,6 +317,7 @@ const BlockInspectorSingleBlock = ( {
) }

{ isSelectedContentClientIdControlling &&
isSelectedBlockInContentOnlyContainer &&
contentClientIds &&
contentClientIds?.length > 0 && (
<PanelBody title={ __( 'Content' ) }>
Expand All @@ -314,6 +334,7 @@ const BlockInspectorSingleBlock = ( {
{ ! isSectionBlock && (
<>
{ editorMode === 'navigation' &&
isSelectedBlockInContentOnlyContainer &&
isSelectedContentClientIdControlling && (
<PanelBody title={ __( 'Content' ) }>
<PrivateListView
Expand Down
10 changes: 6 additions & 4 deletions packages/block-editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -3046,6 +3046,12 @@ export const getBlockEditingMode = createRegistrySelector(
clientId = '';
}

// All controlling blocks are treated as content only
// by default.
if ( areInnerBlocksControlled( state, clientId ) ) {
return 'contentOnly';
}

// In zoom-out mode, override the behavior set by
// __unstableSetBlockEditingMode to only allow editing the top-level
// sections.
Expand Down Expand Up @@ -3075,10 +3081,6 @@ export const getBlockEditingMode = createRegistrySelector(
if ( editorMode === 'navigation' ) {
const sectionRootClientId = getSectionRootClientId( state );

if ( areInnerBlocksControlled( state, clientId ) ) {
return 'contentOnly';
}

// The root section is "default mode"
if ( clientId === sectionRootClientId ) {
return 'default';
Expand Down

0 comments on commit 54f5ef2

Please sign in to comment.