@@ -74,14 +73,14 @@ export default class TextBlockForm extends Component {
setChildren( value ) }
+ onChange={ ( value ) => change( { content: value } ) }
focusConfig={ focusConfig }
onFocusChange={ focus }
/>
diff --git a/tinymce-per-block/src/blocks/text-block/index.js b/tinymce-per-block/src/blocks/text-block/index.js
index b714d2ccfd432d..d791a0de0941d7 100644
--- a/tinymce-per-block/src/blocks/text-block/index.js
+++ b/tinymce-per-block/src/blocks/text-block/index.js
@@ -7,10 +7,33 @@ import { EditorTableIcon } from 'dashicons';
/**
* Internal dependencies
*/
+import { parse } from 'parsers/block';
+import { serialize } from 'serializers/block';
import form from './form';
registerBlock( 'text', {
title: 'Text',
form: form,
icon: EditorTableIcon,
+ parse: ( rawBlock ) => {
+ return {
+ blockType: 'text',
+ align: rawBlock.attrs.align || 'no-align',
+ content: serialize( rawBlock.children ),
+ };
+ },
+ serialize: ( block ) => {
+ const children = parse( block.content );
+ const rawHtml = serialize( children );
+
+ return {
+ type: 'WP_Block',
+ blockType: 'text',
+ attrs: { /* align: block.align */ },
+ startText: '',
+ endText: '',
+ rawContent: '' + rawHtml + '',
+ children
+ };
+ }
} );
diff --git a/tinymce-per-block/src/external/wp-blocks/editable/index.js b/tinymce-per-block/src/external/wp-blocks/editable/index.js
index 30cae4684ef382..b1003762b14366 100644
--- a/tinymce-per-block/src/external/wp-blocks/editable/index.js
+++ b/tinymce-per-block/src/external/wp-blocks/editable/index.js
@@ -5,8 +5,6 @@ import { createElement, Component } from 'wp-elements';
import tinymce from 'tinymce';
import { isEqual } from 'lodash';
-import { parse } from 'parsers/block';
-
function initialize( node, inline, onSetup ) {
if ( ! node ) {
return;
@@ -132,7 +130,7 @@ export default class EditableComponent extends Component {
const hasAfter = !! childNodes.slice( splitIndex )
.reduce( ( memo, node ) => memo + node.textContent, '' );
this.editor.setContent( before );
- this.props.splitValue( parse( before ), hasAfter ? parse( after ) : '' );
+ this.props.splitValue( before, hasAfter ? after : '' );
} );
} else if ( event.keyCode === 8 ) {
if ( this.isStartOfEditor() ) {
@@ -202,7 +200,7 @@ export default class EditableComponent extends Component {
return;
}
- this.props.onChange( parse( content ) );
+ this.props.onChange( content );
};
setRef = ( node ) => {
diff --git a/tinymce-per-block/src/external/wp-blocks/input/index.js b/tinymce-per-block/src/external/wp-blocks/input/index.js
index 450369567a61f7..a9de1f929c19e3 100644
--- a/tinymce-per-block/src/external/wp-blocks/input/index.js
+++ b/tinymce-per-block/src/external/wp-blocks/input/index.js
@@ -71,7 +71,9 @@ export default class EnhancedInput extends Component {
render() {
// Keeping splitValue to exclude it from props
- const ignoredProps = [ 'value', 'splitValue', 'removePrevious', 'moveDown', 'moveUp', 'focusConfig', 'onFocusChange' ];
+ const ignoredProps = [
+ 'value', 'splitValue', 'removePrevious', 'moveDown', 'moveUp', 'focusConfig', 'onFocusChange'
+ ];
const { value } = this.props;
const props = omit( this.props, ignoredProps );
diff --git a/tinymce-per-block/src/index.js b/tinymce-per-block/src/index.js
index 287ba6453a02c6..b84fe2b689e1dd 100644
--- a/tinymce-per-block/src/index.js
+++ b/tinymce-per-block/src/index.js
@@ -30,7 +30,12 @@ class App extends Component {
this.setState( {
content: {
block: nextContent,
- html: serializers.block.serialize( nextContent )
+ html: serializers.block.serialize(
+ nextContent.map( block => {
+ const blockDefinition = getBlock( block.blockType );
+ return blockDefinition.serialize( block );
+ } )
+ )
}
} );
return;
@@ -38,7 +43,12 @@ class App extends Component {
this.setState( {
content: {
block: parsers.block.parse( nextContent )
- .filter( block => !! getBlock( block.blockType ) )
+ .filter( rawBlock => !! getBlock( rawBlock.blockType ) )
+ .map( rawBlock => {
+ const blockDefinition = getBlock( rawBlock.blockType );
+ const parsedBlock = blockDefinition.parse( rawBlock );
+ return parsedBlock ? parsedBlock : getBlock( 'text' ).parse( rawBlock );
+ } )
.map( block => Object.assign( { uid: uniqueId() }, block ) ),
html: nextContent
}
diff --git a/tinymce-per-block/src/renderers/block/block-list/block.js b/tinymce-per-block/src/renderers/block/block-list/block.js
index 4bc8c7f7e14756..50eea2da680498 100644
--- a/tinymce-per-block/src/renderers/block/block-list/block.js
+++ b/tinymce-per-block/src/renderers/block/block-list/block.js
@@ -4,7 +4,6 @@
import { createElement, Component } from 'wp-elements';
import classNames from 'classnames';
import { getBlock } from 'wp-blocks';
-import isEqualShallow from 'is-equal-shallow';
export default class BlockListBlock extends Component {
setRef = ( blockNode ) => {
@@ -37,25 +36,10 @@ export default class BlockListBlock extends Component {
const { executeCommand, tabIndex, onFocus } = this.props;
const state = {
- setChildren( children ) {
+ change( changes ) {
executeCommand( {
type: 'change',
- changes: { children }
- } );
- },
- setAttributes( attributes ) {
- if ( isEqualShallow( attributes, block.attrs ) ) {
- return;
- }
-
- executeCommand( {
- type: 'change',
- changes: {
- attrs: {
- ...block.attrs,
- ...attributes
- }
- }
+ changes
} );
},
appendBlock( newBlock ) {
diff --git a/tinymce-per-block/src/renderers/block/block-list/index.js b/tinymce-per-block/src/renderers/block/block-list/index.js
index dff9ab4c66a657..dd9aff38b65f84 100644
--- a/tinymce-per-block/src/renderers/block/block-list/index.js
+++ b/tinymce-per-block/src/renderers/block/block-list/index.js
@@ -60,20 +60,7 @@ class BlockList extends Component {
append: ( { block: commandBlock } ) => {
const createdBlock = commandBlock
? commandBlock
- : {
- type: 'WP_Block',
- blockType: 'paragraph',
- attrs: {},
- startText: '',
- endText: '',
- rawContent: '',
- children: [
- {
- type: 'Text',
- value: ' '
- }
- ]
- };
+ : { blockType: 'paragraph', content: ' ' };
this.onChange( [
...content.slice( 0, index + 1 ),
Object.assign( {}, createdBlock, { uid: uniqueId() } ),