Skip to content
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
24 changes: 15 additions & 9 deletions packages/editor/src/components/inner-blocks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ import { withBlockEditContext } from '../block-edit/context';
class InnerBlocks extends Component {
constructor() {
super( ...arguments );

this.state = {
templateInProcess: !! this.props.template,
};
this.updateNestedSettings();
}

Expand All @@ -39,7 +41,12 @@ class InnerBlocks extends Component {
const { innerBlocks } = this.props.block;
// only synchronize innerBlocks with template if innerBlocks are empty or a locking all exists
if ( innerBlocks.length === 0 || this.getTemplateLock() === 'all' ) {
return this.synchronizeBlocksWithTemplate();
this.synchronizeBlocksWithTemplate();
}
if ( this.state.templateInProcess ) {
this.setState( {
templateInProcess: false,
} );
}
}

Expand Down Expand Up @@ -93,23 +100,22 @@ class InnerBlocks extends Component {
render() {
const {
clientId,
allowedBlocks,
templateLock,
template,
isSmallScreen,
isSelectedBlockInRoot,
} = this.props;
const { templateInProcess } = this.state;

const classes = classnames( 'editor-inner-blocks', {
'has-overlay': isSmallScreen && ! isSelectedBlockInRoot,
} );

return (
<div className={ classes }>
<BlockList
rootClientId={ clientId }
{ ...{ allowedBlocks, templateLock, template } }
/>
{ ! templateInProcess && (
<BlockList
rootClientId={ clientId }
/>
) }
</div>
);
}
Expand Down
12 changes: 8 additions & 4 deletions test/e2e/specs/__snapshots__/container-blocks.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@ exports[`Container block without paragraph support ensures we can use the altern
<!-- /wp:test/container-without-paragraph -->"
`;

exports[`InnerBlocks Template Sync Ensure inner block writing flow works as expected without additional paragraphs added 1`] = `
"<!-- wp:test/test-inner-blocks-paragraph-placeholder -->
<!-- wp:paragraph {\\"placeholder\\":\\"Content…\\",\\"fontSize\\":\\"large\\"} -->
<p class=\\"has-large-font-size\\">Test Paragraph</p>
<!-- /wp:paragraph -->
<!-- /wp:test/test-inner-blocks-paragraph-placeholder -->"
`;

exports[`InnerBlocks Template Sync Ensures blocks without locking are kept intact even if they do not match the template 1`] = `
"<!-- wp:test/test-inner-blocks-no-locking -->
<!-- wp:paragraph {\\"fontSize\\":\\"large\\"} -->
<p class=\\"has-large-font-size\\">Content…</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>added paragraph</p>
<!-- /wp:paragraph -->
Expand Down
9 changes: 9 additions & 0 deletions test/e2e/specs/container-blocks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ describe( 'InnerBlocks Template Sync', () => {
await insertBlockAndAddParagraphInside( 'Test InnerBlocks locking all', 'test/test-inner-blocks-locking-all' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );

it( 'Ensure inner block writing flow works as expected without additional paragraphs added', async () => {
const TEST_BLOCK_NAME = 'Test Inner Blocks Paragraph Placeholder';

await insertBlock( TEST_BLOCK_NAME );
await page.keyboard.type( 'Test Paragraph' );

expect( await getEditedPostContent() ).toMatchSnapshot();
} );
} );

describe( 'Container block without paragraph support', () => {
Expand Down
24 changes: 24 additions & 0 deletions test/e2e/test-plugins/inner-blocks-templates/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
} ],
];

var TEMPLATE_PARAGRAPH_PLACEHOLDER = [
[ 'core/paragraph', {
fontSize: 'large',
placeholder: 'Content…',
} ],
];

var save = function() {
return el( InnerBlocks.Content );
};
Expand Down Expand Up @@ -48,4 +55,21 @@

save,
} );

registerBlockType( 'test/test-inner-blocks-paragraph-placeholder', {
title: 'Test Inner Blocks Paragraph Placeholder',
icon: 'cart',
category: 'common',

edit: function( props ) {
return el(
InnerBlocks,
{
template: TEMPLATE_PARAGRAPH_PLACEHOLDER,
}
);
},

save,
} );
} )();