How to use the @wordpress/rich-text.remove function in @wordpress/rich-text

To help you get started, we’ve selected a few @wordpress/rich-text examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / types / wordpress__rich-text / wordpress__rich-text-tests.tsx View on Github external
title: 'Foo',
    keywords: ['foo', 'bar', 'baz'],
    object: false,
    attributes: {
        className: 'class',
        myFoo: 'data-my-foo',
    },
    edit(props) {
        return <span data-is-active="{props.isActive}">{props.value}</span>;
    },
});

//
// remove
//
RT.remove(VALUE);
RT.remove(VALUE, 10);
RT.remove(VALUE, 10, 20);

//
// removeFormat
//
RT.removeFormat(VALUE, 'foo');
RT.removeFormat(VALUE, 'foo', 10);

//
// replace
//
RT.replace(VALUE, 'foo', 'bar');
RT.replace(VALUE, /foo/, 'bar');
RT.replace(VALUE, 'foo', match =&gt; `${match}bar`);
RT.replace(VALUE, /foo/, match =&gt; `${match}bar`);
github DefinitelyTyped / DefinitelyTyped / types / wordpress__rich-text / wordpress__rich-text-tests.tsx View on Github external
keywords: ['foo', 'bar', 'baz'],
    object: false,
    attributes: {
        className: 'class',
        myFoo: 'data-my-foo',
    },
    edit(props) {
        return <span data-is-active="{props.isActive}">{props.value}</span>;
    },
});

//
// remove
//
RT.remove(VALUE);
RT.remove(VALUE, 10);
RT.remove(VALUE, 10, 20);

//
// removeFormat
//
RT.removeFormat(VALUE, 'foo');
RT.removeFormat(VALUE, 'foo', 10);

//
// replace
//
RT.replace(VALUE, 'foo', 'bar');
RT.replace(VALUE, /foo/, 'bar');
RT.replace(VALUE, 'foo', match =&gt; `${match}bar`);
RT.replace(VALUE, /foo/, match =&gt; `${match}bar`);
RT.replace(VALUE, 'foo', (match, a, b) =&gt; `${match} ${a} ${b}`);
github DefinitelyTyped / DefinitelyTyped / types / wordpress__rich-text / wordpress__rich-text-tests.tsx View on Github external
object: false,
    attributes: {
        className: 'class',
        myFoo: 'data-my-foo',
    },
    edit(props) {
        return <span data-is-active="{props.isActive}">{props.value}</span>;
    },
});

//
// remove
//
RT.remove(VALUE);
RT.remove(VALUE, 10);
RT.remove(VALUE, 10, 20);

//
// removeFormat
//
RT.removeFormat(VALUE, 'foo');
RT.removeFormat(VALUE, 'foo', 10);

//
// replace
//
RT.replace(VALUE, 'foo', 'bar');
RT.replace(VALUE, /foo/, 'bar');
RT.replace(VALUE, 'foo', match =&gt; `${match}bar`);
RT.replace(VALUE, /foo/, match =&gt; `${match}bar`);
RT.replace(VALUE, 'foo', (match, a, b) =&gt; `${match} ${a} ${b}`);
github WordPress / gutenberg / packages / block-editor / src / store / effects.js View on Github external
// Calling the merge to update the attributes and remove the block to be merged
		const updatedAttributes = blockAType.merge(
			cloneA.attributes,
			blocksWithTheSameType[ 0 ].attributes
		);

		if ( hasTextSelection ) {
			const newAttributeKey = findKey( updatedAttributes, ( v ) =>
				typeof v === 'string' && v.indexOf( START_OF_SELECTED_AREA ) !== -1
			);
			const convertedHtml = updatedAttributes[ newAttributeKey ];
			const multilineTag = blockAType.attributes[ newAttributeKey ].multiline;
			const convertedValue = create( { html: convertedHtml, multilineTag } );
			const newOffset = convertedValue.text.indexOf( START_OF_SELECTED_AREA );
			const newValue = remove( convertedValue, newOffset, newOffset + 1 );
			const newHtml = toHTMLString( { value: newValue, multilineTag } );

			updatedAttributes[ newAttributeKey ] = newHtml;

			dispatch( selectionChange(
				blockA.clientId,
				newAttributeKey,
				newOffset,
				newOffset
			) );
		}

		dispatch( replaceBlocks(
			[ blockA.clientId, blockB.clientId ],
			[
				{
github WordPress / gutenberg / packages / format-library / src / footnote / index.js View on Github external
const removeFootnote = ( value ) => {
	const activeObject = getActiveObject( value );

	if ( activeObject && activeObject.type === name ) {
		return remove( value );
	}

	return removeFormat( value, name );
};
github WordPress / gutenberg / packages / block-editor / src / components / rich-text / patterns.js View on Github external
const textBefore = text.slice( 0, start - 1 );
			const indexBefore = textBefore.lastIndexOf( BACKTICK );

			if ( indexBefore === -1 ) {
				return record;
			}

			const startIndex = indexBefore;
			const endIndex = start - 2;

			if ( startIndex === endIndex ) {
				return record;
			}

			record = remove( record, startIndex, startIndex + 1 );
			record = remove( record, endIndex, endIndex + 1 );
			record = applyFormat( record, { type: 'code' }, startIndex, endIndex );

			return record;
		},
	];
github WordPress / gutenberg / packages / block-editor / src / components / rich-text / patterns.js View on Github external
const textBefore = text.slice( 0, start - 1 );
			const indexBefore = textBefore.lastIndexOf( BACKTICK );

			if ( indexBefore === -1 ) {
				return record;
			}

			const startIndex = indexBefore;
			const endIndex = start - 2;

			if ( startIndex === endIndex ) {
				return record;
			}

			record = remove( record, startIndex, startIndex + 1 );
			record = remove( record, endIndex, endIndex + 1 );
			record = applyFormat( record, { type: 'code' }, startIndex, endIndex );

			return record;
		},
	];
github dsifford / academic-bloggers-toolkit / src / js / gutenberg / formats / footnote / footnote.tsx View on Github external
-1,
                        );
                        const indices = value.formats.reduce(
                            (arr, formats = [], idx) =&gt;
                                formats.some(
                                    f =&gt;
                                        f.type === NAME &amp;&amp;
                                        get(f, ['attributes', 'id']) ===
                                            activeId,
                                )
                                    ? [...arr, idx]
                                    : arr,
                            [],
                        );
                        onChange(
                            remove(
                                value,
                                indices[0],
                                indices[indices.length - 1] + 1,
                            ),
                        );
                        parseFootnotes();
                    } else {
                        setIsOpen(true);
                    }
                }}
            /&gt;