diff --git a/packages/block-editor/src/store/selectors.js b/packages/block-editor/src/store/selectors.js index d2a009b59c6399..a5d5050a5b2b7d 100644 --- a/packages/block-editor/src/store/selectors.js +++ b/packages/block-editor/src/store/selectors.js @@ -1036,6 +1036,12 @@ const canInsertBlockTypeUnmemoized = ( state, blockName, rootClientId = null ) = return list; } if ( isArray( list ) ) { + // TODO: when there is a canonical way to detect that we are editing a post + // the following check should be changed to something like: + // if ( includes( list, 'core/post-content' ) && getEditorMode() === 'post-content' && item === null ) + if ( includes( list, 'core/post-content' ) && item === null ) { + return true; + } return includes( list, item ); } return defaultResult; diff --git a/packages/block-editor/src/store/test/selectors.js b/packages/block-editor/src/store/test/selectors.js index 6000c76b824f0e..0d0785f6fd3522 100644 --- a/packages/block-editor/src/store/test/selectors.js +++ b/packages/block-editor/src/store/test/selectors.js @@ -121,6 +121,15 @@ describe( 'selectors', () => { }, } ); + registerBlockType( 'core/post-content-child', { + save: () => null, + category: 'common', + title: 'Test Block Post Content Child', + icon: 'test', + keywords: [ 'testing' ], + parent: [ 'core/post-content' ], + } ); + setFreeformContentHandlerName( 'core/test-freeform' ); cachedSelectors.forEach( ( { clear } ) => clear() ); @@ -132,6 +141,7 @@ describe( 'selectors', () => { unregisterBlockType( 'core/test-block-b' ); unregisterBlockType( 'core/test-block-c' ); unregisterBlockType( 'core/test-freeform' ); + unregisterBlockType( 'core/post-content-child' ); setFreeformContentHandlerName( undefined ); } ); @@ -1933,6 +1943,34 @@ describe( 'selectors', () => { }; expect( canInsertBlockType( state, 'core/test-block-c', 'block1' ) ).toBe( true ); } ); + + it( 'should deny blocks that restrict parent to core/post-content when not in editor root', () => { + const state = { + blocks: { + byClientId: { + block1: { name: 'core/test-block-c' }, + }, + attributes: { + block1: {}, + }, + }, + blockListSettings: {}, + settings: {}, + }; + expect( canInsertBlockType( state, 'core/post-content-child', 'block1' ) ).toBe( false ); + } ); + + it( 'should allow blocks that restrict parent to core/post-content when in editor root', () => { + const state = { + blocks: { + byClientId: {}, + attributes: {}, + }, + blockListSettings: {}, + settings: {}, + }; + expect( canInsertBlockType( state, 'core/post-content-child' ) ).toBe( true ); + } ); } ); describe( 'getInserterItems', () => { @@ -2033,6 +2071,7 @@ describe( 'selectors', () => { }; const itemIDs = getInserterItems( state ).map( ( item ) => item.id ); expect( itemIDs ).toEqual( [ + 'core/post-content-child', 'core/block/2', 'core/block/1', 'core/test-block-b', diff --git a/packages/block-library/src/nextpage/index.js b/packages/block-library/src/nextpage/index.js index 9f39f881d83def..00dedee31d7ff6 100644 --- a/packages/block-library/src/nextpage/index.js +++ b/packages/block-library/src/nextpage/index.js @@ -18,6 +18,7 @@ export { metadata, name }; export const settings = { title: __( 'Page Break' ), + parent: [ 'core/post-content' ], description: __( 'Separate your content into a multi-page experience.' ), icon, keywords: [ __( 'next page' ), __( 'pagination' ) ],