diff --git a/editor/components/block-list/block-invalid-warning.js b/editor/components/block-list/block-invalid-warning.js
index b42e0a896e96cd..9d39c7d64a483e 100644
--- a/editor/components/block-list/block-invalid-warning.js
+++ b/editor/components/block-list/block-invalid-warning.js
@@ -2,62 +2,113 @@
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
-import { Button } from '@wordpress/components';
+import { Button, Modal } from '@wordpress/components';
+import { Component, compose } from '@wordpress/element';
import {
getBlockType,
createBlock,
rawHandler,
} from '@wordpress/blocks';
-import { withDispatch } from '@wordpress/data';
+import { withSelect, withDispatch } from '@wordpress/data';
/**
* Internal dependencies
*/
import Warning from '../warning';
+import BlockCompare from '../block-compare';
-function BlockInvalidWarning( { convertToHTML, convertToBlocks, convertToClassic } ) {
- const hasHTMLBlock = !! getBlockType( 'core/html' );
-
- return (
-
- { __( 'Convert to Blocks' ) }
- ,
- hasHTMLBlock && (
-
- ),
- ] }
- hiddenActions={ [
- { title: __( 'Convert to Blocks' ), onClick: convertToBlocks },
- { title: __( 'Convert to Classic Block' ), onClick: convertToClassic },
- ] }
- >
- { __( 'This block has been modified externally.' ) }
-
- );
+export class BlockInvalidWarning extends Component {
+ constructor( props ) {
+ super( props );
+
+ this.state = { compare: false };
+ this.onCompare = this.onCompare.bind( this );
+ this.onCompareClose = this.onCompareClose.bind( this );
+ }
+
+ onCompare() {
+ this.setState( { compare: true } );
+ }
+
+ onCompareClose() {
+ this.setState( { compare: false } );
+ }
+
+ render() {
+ const { convertToHTML, convertToBlocks, convertToClassic, 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 },
+ ];
+
+ if ( compare ) {
+ return (
+
+
+
+ );
+ }
+
+ return (
+
+ { __( 'Convert to Blocks' ) }
+ ,
+ hasHTMLBlock && (
+
+ ),
+ ] }
+ hiddenActions={ hiddenActions }
+ >
+ { __( 'This block has been modified externally.' ) }
+
+ );
+ }
}
-export default withDispatch( ( dispatch, { block } ) => {
- const { replaceBlock } = dispatch( 'core/editor' );
- return {
- convertToClassic() {
- replaceBlock( block.uid, createBlock( 'core/freeform', {
- content: block.originalContent,
- } ) );
- },
- convertToHTML() {
- replaceBlock( block.clientId, createBlock( 'core/html', {
- content: block.originalContent,
- } ) );
- },
- convertToBlocks() {
- replaceBlock( block.clientId, rawHandler( {
- HTML: block.originalContent,
- mode: 'BLOCKS',
- } ) );
- },
- };
-} )( BlockInvalidWarning );
+const blockToClassic = ( block ) => createBlock( 'core/freeform', {
+ content: block.originalContent,
+} );
+const blockToHTML = ( block ) => createBlock( 'core/html', {
+ content: block.originalContent,
+} );
+const blockToBlocks = ( block ) => rawHandler( {
+ HTML: block.originalContent,
+ mode: 'BLOCKS',
+} );
+
+export default compose(
+ withSelect( () => ( {} ) ),
+ withDispatch( ( dispatch, { block } ) => {
+ const { replaceBlock } = dispatch( 'core/editor' );
+ return {
+ convertToClassic() {
+ replaceBlock( block.clientId, blockToClassic( block ) );
+ },
+ convertToHTML() {
+ replaceBlock( block.clientId, blockToHTML( block ) );
+ },
+ convertToBlocks() {
+ replaceBlock( block.clientId, blockToBlocks( block ) );
+ },
+ };
+ } ),
+)( BlockInvalidWarning );