From b3664c6f69d4db63024fb22e303a80054bf8280e Mon Sep 17 00:00:00 2001 From: iseulde Date: Thu, 22 Aug 2019 10:46:44 +0200 Subject: [PATCH 1/2] Paste: do not force blocks for empty rich text --- .../src/components/rich-text/index.js | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/packages/block-editor/src/components/rich-text/index.js b/packages/block-editor/src/components/rich-text/index.js index 25bbcf9b47955d..b215d21d4344c8 100644 --- a/packages/block-editor/src/components/rich-text/index.js +++ b/packages/block-editor/src/components/rich-text/index.js @@ -138,12 +138,11 @@ class RichTextWrapper extends Component { mode: 'BLOCKS', tagName, } ); - const shouldReplace = onReplace && isEmpty( value ); // Allows us to ask for this information when we get a report. window.console.log( 'Received item:\n\n', file ); - if ( shouldReplace ) { + if ( onReplace && isEmpty( value ) ) { onReplace( content ); } else { this.onSplit( value, content ); @@ -152,21 +151,10 @@ class RichTextWrapper extends Component { return; } - const canReplace = onReplace && isEmpty( value ); - const canSplit = onReplace && onSplit; - - let mode = 'INLINE'; - - if ( canReplace ) { - mode = 'BLOCKS'; - } else if ( canSplit ) { - mode = 'AUTO'; - } - const content = pasteHandler( { HTML: html, plainText, - mode, + mode: onReplace && onSplit ? 'AUTO' : 'INLINE', tagName, canUserUseUnfilteredHTML, } ); @@ -182,7 +170,7 @@ class RichTextWrapper extends Component { onChange( insert( value, valueToInsert ) ); } else if ( content.length > 0 ) { - if ( canReplace ) { + if ( onReplace && isEmpty( value ) ) { onReplace( content ); } else { this.onSplit( value, content ); From eca8fc0cc57dc5fb883703e7682b55e9193f5665 Mon Sep 17 00:00:00 2001 From: iseulde Date: Thu, 22 Aug 2019 11:48:59 +0200 Subject: [PATCH 2/2] Enable embed on URL paste in paragraph block --- .../block-editor/src/components/rich-text/index.js | 14 +++++++++++++- packages/block-library/src/paragraph/edit.js | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/block-editor/src/components/rich-text/index.js b/packages/block-editor/src/components/rich-text/index.js index b215d21d4344c8..3b8bd06ca5ee8d 100644 --- a/packages/block-editor/src/components/rich-text/index.js +++ b/packages/block-editor/src/components/rich-text/index.js @@ -28,6 +28,7 @@ import { import { withFilters, IsolatedEventContainer } from '@wordpress/components'; import { createBlobURL } from '@wordpress/blob'; import deprecated from '@wordpress/deprecated'; +import { isURL } from '@wordpress/url'; /** * Internal dependencies @@ -129,6 +130,7 @@ class RichTextWrapper extends Component { tagName, canUserUseUnfilteredHTML, multiline, + __unstableEmbedURLOnPaste, } = this.props; if ( image && ! html ) { @@ -151,10 +153,20 @@ class RichTextWrapper extends Component { return; } + let mode = onReplace && onSplit ? 'AUTO' : 'INLINE'; + + if ( + __unstableEmbedURLOnPaste && + isEmpty( value ) && + isURL( plainText.trim() ) + ) { + mode = 'BLOCKS'; + } + const content = pasteHandler( { HTML: html, plainText, - mode: onReplace && onSplit ? 'AUTO' : 'INLINE', + mode, tagName, canUserUseUnfilteredHTML, } ); diff --git a/packages/block-library/src/paragraph/edit.js b/packages/block-library/src/paragraph/edit.js index c40fae904906fc..0d41efd5c26836 100644 --- a/packages/block-library/src/paragraph/edit.js +++ b/packages/block-library/src/paragraph/edit.js @@ -195,6 +195,7 @@ class ParagraphBlock extends Component { onRemove={ onReplace ? () => onReplace( [] ) : undefined } aria-label={ content ? __( 'Paragraph block' ) : __( 'Empty block; start writing or type forward slash to choose a block' ) } placeholder={ placeholder || __( 'Start writing or type / to choose a block' ) } + __unstableEmbedURLOnPaste /> );