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

RichText: mark onSplit as unstable #11926

Merged
merged 2 commits into from
Nov 15, 2018
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
2 changes: 1 addition & 1 deletion packages/block-library/src/heading/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default function HeadingEdit( {
value={ content }
onChange={ ( value ) => setAttributes( { content: value } ) }
onMerge={ mergeBlocks }
onSplit={
unstableOnSplit={
insertBlocksAfter ?
( before, after, ...blocks ) => {
setAttributes( { content: before } );
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ export const settings = {
className={ className }
placeholder={ __( 'Write list…' ) }
onMerge={ mergeBlocks }
onSplit={
unstableOnSplit={
insertBlocksAfter ?
( before, after, ...blocks ) => {
if ( ! blocks.length ) {
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/paragraph/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ class ParagraphBlock extends Component {
content: nextContent,
} );
} }
onSplit={ this.splitBlock }
unstableOnSplit={ this.splitBlock }
onMerge={ mergeBlocks }
onReplace={ this.onReplace }
onRemove={ () => onReplace( [] ) }
Expand Down
29 changes: 20 additions & 9 deletions packages/editor/src/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
} from '@wordpress/rich-text';
import { decodeEntities } from '@wordpress/html-entities';
import { withFilters, IsolatedEventContainer } from '@wordpress/components';
import deprecated from '@wordpress/deprecated';

/**
* Internal dependencies
Expand Down Expand Up @@ -79,6 +80,17 @@ export class RichText extends Component {
this.multilineWrapperTags = [ 'ul', 'ol' ];
}

if ( this.props.onSplit ) {
this.onSplit = this.props.onSplit;

deprecated( 'wp.editor.RichText onSplit prop', {
plugin: 'Gutenberg',
alternative: 'wp.editor.RichText unstableOnSplit prop',
} );
} else if ( this.props.unstableOnSplit ) {
this.onSplit = this.props.unstableOnSplit;
}

this.onInit = this.onInit.bind( this );
this.onSetup = this.onSetup.bind( this );
this.onFocus = this.onFocus.bind( this );
Expand Down Expand Up @@ -295,7 +307,7 @@ export class RichText extends Component {
if ( shouldReplace ) {
// Necessary to allow the paste bin to be removed without errors.
this.props.setTimeout( () => this.props.onReplace( content ) );
} else if ( this.props.onSplit ) {
} else if ( this.onSplit ) {
// Necessary to get the right range.
// Also done in the TinyMCE paste plugin.
this.props.setTimeout( () => this.splitContent( content ) );
Expand Down Expand Up @@ -330,7 +342,7 @@ export class RichText extends Component {

if ( shouldReplace ) {
mode = 'BLOCKS';
} else if ( this.props.onSplit ) {
} else if ( this.onSplit ) {
mode = 'AUTO';
}

Expand All @@ -345,7 +357,7 @@ export class RichText extends Component {
if ( typeof content === 'string' ) {
const recordToInsert = create( { html: content } );
this.onChange( insert( this.getRecord(), recordToInsert ) );
} else if ( this.props.onSplit ) {
} else if ( this.onSplit ) {
if ( ! content.length ) {
return;
}
Expand Down Expand Up @@ -592,12 +604,12 @@ export class RichText extends Component {
}

if ( this.multilineTag ) {
if ( this.props.onSplit && isEmptyLine( record ) ) {
this.props.onSplit( ...split( record ).map( this.valueToFormat ) );
if ( this.onSplit && isEmptyLine( record ) ) {
this.onSplit( ...split( record ).map( this.valueToFormat ) );
} else {
this.onChange( insertLineSeparator( record ) );
}
} else if ( event.shiftKey || ! this.props.onSplit ) {
} else if ( event.shiftKey || ! this.onSplit ) {
const text = getTextContent( record );
const length = text.length;
let toInsert = '\n';
Expand Down Expand Up @@ -678,10 +690,9 @@ export class RichText extends Component {
* @param {Object} context The context for splitting.
*/
splitContent( blocks = [], context = {} ) {
const { onSplit } = this.props;
const record = this.createRecord();

if ( ! onSplit ) {
if ( ! this.onSplit ) {
return;
}

Expand Down Expand Up @@ -713,7 +724,7 @@ export class RichText extends Component {
after = this.valueToFormat( after );
}

onSplit( before, after, ...blocks );
this.onSplit( before, after, ...blocks );
}

onNodeChange( { parents } ) {
Expand Down