Skip to content
Closed
Changes from all 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
29 changes: 27 additions & 2 deletions packages/block-editor/src/store/private-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { createSelector, createRegistrySelector } from '@wordpress/data';
import {
hasBlockSupport,
getBlockType,
privateApis as blocksPrivateApis,
} from '@wordpress/blocks';

Expand All @@ -23,6 +24,7 @@ import {
getBlockAttributes,
} from './selectors';
import {
checkAllowList,
checkAllowListRecursive,
getAllPatternsDependants,
getInsertBlockTypeDependants,
Expand Down Expand Up @@ -102,14 +104,37 @@ export function isContainerInsertableToInContentOnlyMode(
blockName,
rootClientId
) {
const isBlockContentBlock = isContentBlock( blockName );
const rootBlockName = getBlockName( state, rootClientId );
const isContainerContentBlock = isContentBlock( rootBlockName );
const isRootBlockMain = getSectionRootClientId( state ) === rootClientId;

// Special case: Allow all navigation child blocks in contentOnly mode
if ( rootBlockName === 'core/navigation' ) {
Comment on lines +110 to +111

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The crux of this PR is that it's a temporary workaround that restores the original functionality.

The downside is that it might be masking problems as we move forward with developing contentOnly mode.

const blockType = getBlockType( blockName );
const parentBlockType = getBlockType( rootBlockName );

// Check if block has core/navigation as parent
const hasNavigationParent = checkAllowList(
blockType?.parent,
'core/navigation'
);

// Check if block is in navigation's allowedBlocks
const isInNavigationAllowedBlocks = checkAllowList(
parentBlockType?.allowedBlocks,
blockName
);

// If it's a valid navigation child, allow insertion
if ( hasNavigationParent || isInNavigationAllowedBlocks ) {
return true;
}
}

// In contentOnly mode, containers shouldn't be inserted into unless:
// 1. they are a section root;
// 2. they are a content block and the block to be inserted is also content.
const isBlockContentBlock = isContentBlock( blockName );
const isContainerContentBlock = isContentBlock( rootBlockName );
return (
isRootBlockMain || ( isContainerContentBlock && isBlockContentBlock )
);
Expand Down
Loading