Skip to content

Commit

Permalink
Invalid block: add an ‘overwrite’ option
Browse files Browse the repository at this point in the history
This converts the invalid block to a single block of the same type, with any invalid HTML corrected by the block creation process
  • Loading branch information
johngodley committed Sep 14, 2018
1 parent 51a0287 commit f17c6af
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ export class BlockInvalidWarning extends Component {
}

render() {
const { convertToHTML, convertToBlocks, convertToClassic, block } = this.props;
const { convertToHTML, convertToBlocks, convertToClassic, overwriteBlock, block } = this.props;
const hasHTMLBlock = !! getBlockType( 'core/html' );
const { compare } = this.state;
const hiddenActions = [
{ title: __( 'Convert to Blocks' ), onClick: convertToBlocks },
{ title: __( 'Convert to Classic Block' ), onClick: convertToClassic },
{ title: __( 'Compare Conversion' ), onClick: this.onCompare },
{ title: __( 'Overwrite with Valid Block' ), onCLick: overwriteBlock },
];

if ( compare ) {
Expand Down Expand Up @@ -93,6 +94,7 @@ const blockToBlocks = ( block ) => rawHandler( {
HTML: block.originalContent,
mode: 'BLOCKS',
} );
const blockOverwrite = ( { name, attributes } ) => createBlock( name, attributes );

export default withDispatch( ( dispatch, { block } ) => {
const { replaceBlock } = dispatch( 'core/editor' );
Expand All @@ -107,5 +109,8 @@ export default withDispatch( ( dispatch, { block } ) => {
convertToBlocks() {
replaceBlock( block.clientId, blockToBlocks( block ) );
},
overwriteBlock() {
replaceBlock( block.clientId, blockOverwrite( block ) );
},
};
} )( BlockInvalidWarning );

0 comments on commit f17c6af

Please sign in to comment.