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

Nested blocks: Show the side inserter on empty paragraphs #5139

Merged
merged 1 commit into from
Feb 26, 2018
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
10 changes: 8 additions & 2 deletions blocks/api/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
*/
import { every, keys, isEqual } from 'lodash';

/**
* WordPress dependencies
*/
import { applyFilters } from '@wordpress/hooks';

/**
* Internal dependencies
*/
Expand All @@ -25,10 +30,11 @@ export function isUnmodifiedDefaultBlock( block ) {
}

const newDefaultBlock = createBlock( defaultBlockName );
const attributeKeys = [

const attributeKeys = applyFilters( 'blocks.isUnmodifiedDefaultBlock.attributes', [
...keys( newDefaultBlock.attributes ),
...keys( block.attributes ),
];
] );

return every( attributeKeys, key =>
isEqual( newDefaultBlock.attributes[ key ], block.attributes[ key ] )
Expand Down
15 changes: 14 additions & 1 deletion blocks/hooks/layout.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { assign, compact, get } from 'lodash';
import { assign, compact, get, without } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -70,6 +70,19 @@ function preserveLayoutAttribute( transformedBlock, blocks ) {
return transformedBlock;
}

/**
* Excludes the layout from the list of attributes to check
* when determining if a block is unmodified or not.
*
* @param {Object} attributeKeys Attribute keys to check
*
* @return {Object} Modified list of attribute keys
*/
function excludeLayoutFromUnmodifiedBlockCheck( attributeKeys ) {
return without( attributeKeys, 'layout' );
}

addFilter( 'blocks.registerBlockType', 'core/layout/attribute', addAttribute );
addFilter( 'blocks.getSaveContent.extraProps', 'core/layout/save-props', addSaveProps );
addFilter( 'blocks.switchToBlockType.transformedBlock', 'core/layout/preserve-layout', preserveLayoutAttribute );
addFilter( 'blocks.isUnmodifiedDefaultBlock.attributes', 'core/layout/exclude-layout-attribute-check', excludeLayoutFromUnmodifiedBlockCheck );
10 changes: 10 additions & 0 deletions blocks/hooks/test/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,14 @@ describe( 'layout', () => {
expect( transformedBlock.attributes.layout ).toBe( 'wide' );
} );
} );

describe( 'excludeLayoutFromUnmodifiedBlockCheck', () => {
const excludeLayoutAttribute = applyFilters.bind( null, 'blocks.isUnmodifiedDefaultBlock.attributes' );

it( 'should exclude the layout attribute', () => {
const attributeKeys = excludeLayoutAttribute( [ 'align', 'content', 'layout' ] );

expect( attributeKeys ).toEqual( [ 'align', 'content' ] );
} );
} );
} );