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

Limit of Next Page (Page Break) block to root level only #18260

Merged
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions packages/block-editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
39 changes: 39 additions & 0 deletions packages/block-editor/src/store/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
Expand All @@ -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' );
glendaviesnz marked this conversation as resolved.
Show resolved Hide resolved

setFreeformContentHandlerName( undefined );
} );
Expand Down Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/nextpage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) ],
Expand Down