Skip to content

Commit

Permalink
Blocks Per Block: Fix HTML mode for blocks with comment attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Sep 29, 2017
1 parent 26b7eed commit 8db20ce
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions editor/modes/visual-editor/block-html.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* WordPress Dependencies
*/
import { isEqual } from 'lodash';
import { isEqual, omit, keys } from 'lodash';
import { Component } from '@wordpress/element';
import { getBlockContent, getSourcedAttributes, getBlockType, isValidBlock } from '@wordpress/blocks';

Expand Down Expand Up @@ -32,14 +32,19 @@ class BlockHTML extends Component {
if ( ! isEqual( nextProps.block.attributes, this.state.attributes ) ) {
this.setState( {
html: getBlockContent( nextProps.block ),
attributes: nextProps.block.attributes,
} );
}
}

onBlur() {
const blockType = getBlockType( this.props.block.name );
const attributes = getSourcedAttributes( this.state.html, blockType.attributes );
const isValid = isValidBlock( this.state.html, blockType, { ...this.props.block.attributes, attributes } );
const sourcedAttributes = getSourcedAttributes( this.state.html, blockType.attributes );
const attributes = {
...( omit( this.props.block.attributes, keys( sourcedAttributes ) ) ),
...sourcedAttributes,
};
const isValid = isValidBlock( this.state.html, blockType, attributes );
this.setState( { attributes } );
this.props.onChange( this.props.uid, attributes, this.state.html, isValid );
}
Expand Down

0 comments on commit 8db20ce

Please sign in to comment.