-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
70 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
packages/block-editor/src/components/rich-text/with-deprecations.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { forwardRef } from '@wordpress/element'; | ||
import { children as childrenSource } from '@wordpress/blocks'; | ||
import { useInstanceId } from '@wordpress/compose'; | ||
import { __unstableCreateElement } from '@wordpress/rich-text'; | ||
import deprecated from '@wordpress/deprecated'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import RichTextMultiline from './multiline'; | ||
|
||
export function withDeprecations( Component ) { | ||
return forwardRef( ( props, ref ) => { | ||
let value = props.value; | ||
let onChange = props.onChange; | ||
|
||
// Handle deprecated format. | ||
if ( Array.isArray( value ) ) { | ||
deprecated( 'wp.blockEditor.RichText value prop as children type', { | ||
since: '6.1', | ||
version: '6.3', | ||
alternative: 'value prop as string', | ||
link: 'https://developer.wordpress.org/block-editor/how-to-guides/block-tutorial/introducing-attributes-and-editable-fields/', | ||
} ); | ||
|
||
value = childrenSource.toHTML( props.value ); | ||
onChange = ( newValue ) => | ||
props.onChange( | ||
childrenSource.fromDOM( | ||
__unstableCreateElement( document, newValue ).childNodes | ||
) | ||
); | ||
} | ||
|
||
const NewComponent = props.multiline ? RichTextMultiline : Component; | ||
const instanceId = useInstanceId( NewComponent ); | ||
|
||
return ( | ||
<NewComponent | ||
{ ...props } | ||
identifier={ props.identifier || instanceId } | ||
value={ value } | ||
onChange={ onChange } | ||
ref={ ref } | ||
/> | ||
); | ||
} ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters