diff --git a/packages/block-editor/src/components/block-compare/index.js b/packages/block-editor/src/components/block-compare/index.js index 190bb85add2fb..00af03004fd40 100644 --- a/packages/block-editor/src/components/block-compare/index.js +++ b/packages/block-editor/src/components/block-compare/index.js @@ -11,7 +11,6 @@ import { diffChars } from 'diff/lib/diff/character'; * WordPress dependencies */ import { __ } from '@wordpress/i18n'; -import { Component } from '@wordpress/element'; import { getSaveContent, getSaveElement } from '@wordpress/blocks'; /** @@ -19,8 +18,14 @@ import { getSaveContent, getSaveElement } from '@wordpress/blocks'; */ import BlockView from './block-view'; -class BlockCompare extends Component { - getDifference( originalContent, newContent ) { +function BlockCompare( { + block, + onKeep, + onConvert, + convertor, + convertButtonText, +} ) { + function getDifference( originalContent, newContent ) { const difference = diffChars( originalContent, newContent ); return difference.map( ( item, pos ) => { @@ -37,16 +42,9 @@ class BlockCompare extends Component { } ); } - getOriginalContent( block ) { - return { - rawContent: block.originalContent, - renderedContent: getSaveElement( block.name, block.attributes ), - }; - } - - getConvertedContent( block ) { + function getConvertedContent( convertedBlock ) { // The convertor may return an array of items or a single item - const newBlocks = castArray( block ); + const newBlocks = castArray( convertedBlock ); // Get converted block details const newContent = newBlocks.map( ( item ) => @@ -62,43 +60,37 @@ class BlockCompare extends Component { }; } - render() { - const { - block, - onKeep, - onConvert, - convertor, - convertButtonText, - } = this.props; - const original = this.getOriginalContent( block ); - const converted = this.getConvertedContent( convertor( block ) ); - const difference = this.getDifference( - original.rawContent, - converted.rawContent - ); + const original = { + rawContent: block.originalContent, + renderedContent: getSaveElement( block.name, block.attributes ), + }; + const converted = getConvertedContent( convertor( block ) ); + const difference = getDifference( + original.rawContent, + converted.rawContent + ); - return ( -
- + return ( +
+ - -
- ); - } + +
+ ); } export default BlockCompare;