diff --git a/packages/rich-text/src/component/index.js b/packages/rich-text/src/component/index.js index 08196333afd37..fe3d887b3ba66 100644 --- a/packages/rich-text/src/component/index.js +++ b/packages/rich-text/src/component/index.js @@ -19,7 +19,7 @@ import { useSelectObject } from './use-select-object'; import { useInputAndSelection } from './use-input-and-selection'; import { useSelectionChangeCompat } from './use-selection-change-compat'; import { useDelete } from './use-delete'; -import { RichTextString } from '../value'; +import { createRichTextString } from '../value'; export function useRichText( { value = '', @@ -88,7 +88,7 @@ export function useRichText( { multilineTag === 'li' ? [ 'ul', 'ol' ] : undefined, preserveWhiteSpace, } ) - : { ...value }; + : value.value; if ( disableFormats ) { record.current.formats = Array( value.length ); record.current.replacements = Array( value.length ); @@ -144,7 +144,7 @@ export function useRichText( { if ( disableFormats ) { _value.current = newRecord.text; } else { - _value.current = new RichTextString( { + _value.current = createRichTextString( { value: __unstableBeforeSerialize ? { ...newRecord, diff --git a/packages/rich-text/src/create.js b/packages/rich-text/src/create.js index fed30ad07f7a4..c4f082eb289f7 100644 --- a/packages/rich-text/src/create.js +++ b/packages/rich-text/src/create.js @@ -14,7 +14,6 @@ import { OBJECT_REPLACEMENT_CHARACTER, ZWNBSP, } from './special-characters'; -import { RichTextString } from './value'; /** @typedef {import('./types').RichTextValue} RichTextValue */ @@ -165,7 +164,7 @@ export function create( { }; } - if ( html instanceof RichTextString ) { + if ( html instanceof String ) { return html; } diff --git a/packages/rich-text/src/value.js b/packages/rich-text/src/value.js index 5817b2d6d6a88..5beb9046612b3 100644 --- a/packages/rich-text/src/value.js +++ b/packages/rich-text/src/value.js @@ -2,20 +2,15 @@ * Internal dependencies */ import { toHTMLString } from './to-html-string'; -export class RichTextString extends String { - constructor( { value, ...settings } ) { - super( toHTMLString( { value, ...settings } ) ); - for ( const key in value ) { - Object.defineProperty( this, key, { - value: value[ key ], - enumerable: true, - } ); - } - for ( const key in settings ) { - Object.defineProperty( this, key, { - value: settings[ key ], - } ); - } +export function createRichTextString( args ) { + const string = new String( toHTMLString( args ) ); + + for ( const key in args ) { + Object.defineProperty( string, key, { + value: args[ key ], + } ); } + + return string; }