diff --git a/blocks/api/factory.js b/blocks/api/factory.js
new file mode 100644
index 00000000000000..bb27df7e56d09c
--- /dev/null
+++ b/blocks/api/factory.js
@@ -0,0 +1,19 @@
+/**
+ * External dependencies
+ */
+import uuid from 'uuid/v4';
+
+/**
+ * Returns a block object given its type and attributes
+ *
+ * @param {Object} blockType BlockType
+ * @param {Object} attributes Block attributes
+ * @return {Object} Block object
+ */
+export function createBlock( blockType, attributes = {} ) {
+ return {
+ uid: uuid(),
+ blockType,
+ attributes
+ };
+}
diff --git a/blocks/api/index.js b/blocks/api/index.js
index 3abf5b70d8385a..2d43c110f70696 100644
--- a/blocks/api/index.js
+++ b/blocks/api/index.js
@@ -4,6 +4,7 @@
import * as query from 'hpq';
export { query };
+export { createBlock } from './factory';
export { default as parse } from './parser';
export { default as serialize } from './serializer';
export { getCategories } from './categories';
diff --git a/blocks/api/parser.js b/blocks/api/parser.js
index 1b23bf7edd80a0..ea0a7b7183c625 100644
--- a/blocks/api/parser.js
+++ b/blocks/api/parser.js
@@ -2,13 +2,13 @@
* External dependencies
*/
import * as query from 'hpq';
-import uuid from 'uuid/v4';
/**
* Internal dependencies
*/
import { parse as grammarParse } from './post.pegjs';
import { getBlockSettings, getUnknownTypeHandler } from './registration';
+import { createBlock } from './factory';
/**
* Returns the block attributes of a registered block node given its settings.
@@ -53,12 +53,9 @@ export default function parse( content ) {
// Include in set only if settings were determined
if ( settings ) {
- memo.push( {
- blockType,
- uid: uuid(),
- rawContent: blockNode.rawContent,
- attributes: getBlockAttributes( blockNode, settings )
- } );
+ memo.push(
+ createBlock( blockType, getBlockAttributes( blockNode, settings ) )
+ );
}
return memo;
diff --git a/blocks/api/test/factory.js b/blocks/api/test/factory.js
new file mode 100644
index 00000000000000..d8c5accc5fcbe6
--- /dev/null
+++ b/blocks/api/test/factory.js
@@ -0,0 +1,25 @@
+/**
+ * External dependencies
+ */
+import { expect } from 'chai';
+
+/**
+ * Internal dependencies
+ */
+import { createBlock } from '../factory';
+
+describe( 'block factory', () => {
+ describe( 'createBlock()', () => {
+ it( 'should create a block given its blockType and attributes', () => {
+ const block = createBlock( 'core/test-block', {
+ align: 'left'
+ } );
+
+ expect( block.blockType ).to.eql( 'core/test-block' );
+ expect( block.attributes ).to.eql( {
+ align: 'left'
+ } );
+ expect( block.uid ).to.be.a( 'string' );
+ } );
+ } );
+} );
diff --git a/blocks/api/test/parser.js b/blocks/api/test/parser.js
index 45ac197d036e19..4ec62562f0b81a 100644
--- a/blocks/api/test/parser.js
+++ b/blocks/api/test/parser.js
@@ -101,7 +101,6 @@ describe( 'block parser', () => {
expect( parsed[ 0 ].attributes ).to.eql( {
content: 'Ribs & Chicken'
} );
- expect( parsed[ 0 ].rawContent ).to.equal( 'Ribs' );
expect( parsed[ 0 ].uid ).to.be.a( 'string' );
} );
diff --git a/blocks/components/editable/index.js b/blocks/components/editable/index.js
index d92d8999d73e7b..c2eebb4558541e 100644
--- a/blocks/components/editable/index.js
+++ b/blocks/components/editable/index.js
@@ -45,7 +45,8 @@ export default class Editable extends wp.element.Component {
}
onInit() {
- this.editor.setContent( this.props.value );
+ const { value = '' } = this.props;
+ this.editor.setContent( value );
}
onChange() {
diff --git a/editor/components/inserter/index.js b/editor/components/inserter/index.js
index fe7914e463897c..9b00deffebcfd4 100644
--- a/editor/components/inserter/index.js
+++ b/editor/components/inserter/index.js
@@ -8,6 +8,7 @@ class Inserter extends wp.element.Component {
constructor() {
super( ...arguments );
this.toggle = this.toggle.bind( this );
+ this.close = this.close.bind( this );
this.state = {
opened: false
};
@@ -19,6 +20,12 @@ class Inserter extends wp.element.Component {
} );
}
+ close() {
+ this.setState( {
+ opened: false
+ } );
+ }
+
render() {
const { opened } = this.state;
const { position } = this.props;
@@ -30,7 +37,7 @@ class Inserter extends wp.element.Component {
label={ wp.i18n.__( 'Insert block' ) }
onClick={ this.toggle }
className="editor-inserter__toggle" />
- { opened &&