Skip to content

Commit 1aab304

Browse files
committed
Add properties to String instance
1 parent 6725b4b commit 1aab304

File tree

3 files changed

+13
-19
lines changed

3 files changed

+13
-19
lines changed

packages/rich-text/src/component/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { useSelectObject } from './use-select-object';
1919
import { useInputAndSelection } from './use-input-and-selection';
2020
import { useSelectionChangeCompat } from './use-selection-change-compat';
2121
import { useDelete } from './use-delete';
22-
import { RichTextString } from '../value';
22+
import { createRichTextString } from '../value';
2323

2424
export function useRichText( {
2525
value = '',
@@ -88,7 +88,7 @@ export function useRichText( {
8888
multilineTag === 'li' ? [ 'ul', 'ol' ] : undefined,
8989
preserveWhiteSpace,
9090
} )
91-
: { ...value };
91+
: value.value;
9292
if ( disableFormats ) {
9393
record.current.formats = Array( value.length );
9494
record.current.replacements = Array( value.length );
@@ -145,7 +145,7 @@ export function useRichText( {
145145
if ( disableFormats ) {
146146
_value.current = newRecord.text;
147147
} else {
148-
_value.current = new RichTextString( {
148+
_value.current = createRichTextString( {
149149
value: __unstableBeforeSerialize
150150
? {
151151
...newRecord,

packages/rich-text/src/create.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
OBJECT_REPLACEMENT_CHARACTER,
1515
ZWNBSP,
1616
} from './special-characters';
17-
import { RichTextString } from './value';
1817

1918
/** @typedef {import('./types').RichTextValue} RichTextValue */
2019

@@ -170,7 +169,7 @@ export function create( {
170169
};
171170
}
172171

173-
if ( html instanceof RichTextString ) {
172+
if ( html instanceof String ) {
174173
return html;
175174
}
176175

packages/rich-text/src/value.js

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,15 @@
22
* Internal dependencies
33
*/
44
import { toHTMLString } from './to-html-string';
5-
export class RichTextString extends String {
6-
constructor( { value, ...settings } ) {
7-
super( toHTMLString( { value, ...settings } ) );
8-
for ( const key in value ) {
9-
Object.defineProperty( this, key, {
10-
value: value[ key ],
11-
enumerable: true,
12-
} );
13-
}
145

15-
for ( const key in settings ) {
16-
Object.defineProperty( this, key, {
17-
value: settings[ key ],
18-
} );
19-
}
6+
export function createRichTextString( args ) {
7+
const string = new String( toHTMLString( args ) );
8+
9+
for ( const key in args ) {
10+
Object.defineProperty( string, key, {
11+
value: args[ key ],
12+
} );
2013
}
14+
15+
return string;
2116
}

0 commit comments

Comments
 (0)