From e3438e389d639d3080da41c5ad0861b1ed1bd5ee Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Wed, 26 Apr 2017 11:38:06 +0100 Subject: [PATCH 1/3] Text Block: Fix updating the content of an empty text block --- blocks/components/editable/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/blocks/components/editable/index.js b/blocks/components/editable/index.js index db9977dc633996..027c254c000cba 100644 --- a/blocks/components/editable/index.js +++ b/blocks/components/editable/index.js @@ -261,7 +261,8 @@ export default class Editable extends wp.element.Component { if ( this.props.tagName === prevProps.tagName && - this.props.value !== prevProps.value + this.props.value !== prevProps.value && + ! isEqual( this.props.value, prevProps.value ) ) { this.updateContent(); } From 91f2ba47c3052ba987b1a9bd297703c42cdc1163 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Thu, 27 Apr 2017 09:56:14 -0400 Subject: [PATCH 2/3] Enable blocks to specify default attributes --- blocks/api/parser.js | 1 + blocks/api/test/parser.js | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/blocks/api/parser.js b/blocks/api/parser.js index b5fa7c23d86330..648f0bc363c673 100644 --- a/blocks/api/parser.js +++ b/blocks/api/parser.js @@ -42,6 +42,7 @@ export function getBlockAttributes( blockSettings, rawContent, attributes ) { if ( blockSettings ) { attributes = { ...attributes, + ...blockSettings.defaultAttributes, ...parseBlockAttributes( rawContent, blockSettings ), }; } diff --git a/blocks/api/test/parser.js b/blocks/api/test/parser.js index d483366a252dce..f752390139fb1a 100644 --- a/blocks/api/test/parser.js +++ b/blocks/api/test/parser.js @@ -66,12 +66,15 @@ describe( 'block parser', () => { } ); describe( 'getBlockAttributes()', () => { - it( 'should merge attributes with the parsed attributes', () => { + it( 'should merge attributes with the parsed and default attributes', () => { const blockSettings = { attributes: function( rawContent ) { return { content: rawContent + ' & Chicken' }; + }, + defaultAttributes: { + topic: 'none' } }; @@ -80,6 +83,7 @@ describe( 'block parser', () => { expect( getBlockAttributes( blockSettings, rawContent, attrs ) ).to.eql( { align: 'left', + topic: 'none', content: 'Ribs & Chicken' } ); } ); From 83df98b9fe395aba9e79a7d85e08c463e6901b37 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Thu, 27 Apr 2017 10:56:07 -0400 Subject: [PATCH 3/3] Specify text block defaultAttributes --- blocks/library/text/index.js | 6 +++++- languages/gutenberg.pot | 6 +++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/blocks/library/text/index.js b/blocks/library/text/index.js index 9d82d80b19419d..b74e8de99a93d0 100644 --- a/blocks/library/text/index.js +++ b/blocks/library/text/index.js @@ -17,6 +17,10 @@ registerBlock( 'core/text', { content: children(), }, + defaultAttributes: { + content:

+ }, + controls: [ { icon: 'editor-alignleft', @@ -51,7 +55,7 @@ registerBlock( 'core/text', { }, edit( { attributes, setAttributes, insertBlockAfter, focus, setFocus, mergeWithPrevious } ) { - const { content =

, align } = attributes; + const { content, align } = attributes; return (