Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tiny PR] Paste: do not force blocks for empty rich text #17140

Merged
merged 2 commits into from
Sep 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions packages/block-editor/src/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -129,6 +130,7 @@ class RichTextWrapper extends Component {
tagName,
canUserUseUnfilteredHTML,
multiline,
__unstableEmbedURLOnPaste,
} = this.props;

if ( image && ! html ) {
Expand All @@ -138,12 +140,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 );
Expand All @@ -152,15 +153,14 @@ class RichTextWrapper extends Component {
return;
}

const canReplace = onReplace && isEmpty( value );
const canSplit = onReplace && onSplit;

let mode = 'INLINE';
let mode = onReplace && onSplit ? 'AUTO' : 'INLINE';

if ( canReplace ) {
if (
__unstableEmbedURLOnPaste &&
isEmpty( value ) &&
isURL( plainText.trim() )
) {
mode = 'BLOCKS';
} else if ( canSplit ) {
mode = 'AUTO';
}

const content = pasteHandler( {
Expand All @@ -182,7 +182,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 );
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/paragraph/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this prop newly introduced in this PR? (Could not find its reference anywhere else in the codebase.) What is its purpose?

Not sure, what's the convention for such unstable new props. But can we add some doc on this? Maybe inline comment, readme, somewhere else? Maybe better prop naming to reflect its use case better?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can provide an inline comment, but I thought the name is quite clear: it enables embedding when the user pastes a URL. This prop should normally only be used on the core paragraph block. We shouldn't document unstable props in a readme file.

An unstable API is one which serves as a means to an end. It is not desired to ever be converted into a public API.

https://developer.wordpress.org/block-editor/contributors/develop/coding-guidelines/

/>
</>
);
Expand Down