Skip to content

Commit

Permalink
Show “Content” panel for sections when in “Simple” mode
Browse files Browse the repository at this point in the history
  • Loading branch information
getdave committed Sep 6, 2024
1 parent 7be5cd0 commit 4f29dcd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/block-editor/src/components/block-inspector/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,24 @@ const BlockInspector = ( { showNoBlockSelectedMessage = true } ) => {
getBlockName,
getContentLockingParent,
getTemplateLock,
getClosestSectionBlock,
getBlockEditingMode,
} = unlock( select( blockEditorStore ) );
const _selectedBlockClientId = getSelectedBlockClientId();
const _selectedBlockName =
_selectedBlockClientId && getBlockName( _selectedBlockClientId );
const _blockType =
_selectedBlockName && getBlockType( _selectedBlockName );

const closestSectionBlock = getClosestSectionBlock(
_selectedBlockClientId
);

const closestContentOnlySectionBlock =
getBlockEditingMode( closestSectionBlock ) === 'contentOnly'
? closestSectionBlock
: undefined;

return {
count: getSelectedBlockCount(),
selectedBlockClientId: _selectedBlockClientId,
Expand All @@ -117,7 +128,8 @@ const BlockInspector = ( { showNoBlockSelectedMessage = true } ) => {
( getTemplateLock( _selectedBlockClientId ) === 'contentOnly' ||
_selectedBlockName === 'core/block'
? _selectedBlockClientId
: undefined ),
: undefined ) ||
closestContentOnlySectionBlock,
};
}, [] );

Expand Down
21 changes: 21 additions & 0 deletions packages/block-editor/src/store/private-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -567,3 +567,24 @@ export function getSectionClientIds( state ) {
const sectionRootClientId = getSectionRootClientId( state );
return getBlockOrder( state, sectionRootClientId );
}

/**
* Retrieves the closest "section" block to the given client ID.
*
* @param {Object} state - The current state.
* @param {string} clientId - The client ID to start the search from.
* @return {string|undefined} The client ID of the closest section block, or undefined if not found.
*/
export function getClosestSectionBlock( state, clientId ) {
let current = clientId;
let result;
const sectionClientIds = getSectionClientIds( state );
while ( current ) {
if ( sectionClientIds.includes( current ) ) {
result = current;
break;
}
current = state.blocks.parents.get( current );
}
return result;
}

0 comments on commit 4f29dcd

Please sign in to comment.