How to use the @wordpress/rich-text.insertObject 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
//
// getTextContent
//
RT.getTextContent(VALUE);

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

//
// insertObject
//
RT.insertObject(VALUE, FORMAT);

//
// isCollapsed
//
RT.isCollapsed(VALUE);

//
// isEmpty
//
RT.isEmpty(VALUE);

//
// join
//
RT.join([VALUE, VALUE]);
RT.join([], VALUE);
github WordPress / gutenberg / packages / format-library / src / footnote / index.js View on Github external
// It does not matter what this is, as long as it is unique per page.
	const id = uuid();
	const format = {
		type: name,
		attributes: {
			href: `#${ id }`,
			id: `${ id }-anchor`,
			'data-core-footnotes-id': id,
		},
	};

	let newValue;

	if ( isCollapsed( value ) ) {
		const prevStart = value.start;
		newValue = insertObject( value, format );
		newValue.start = prevStart;
	} else {
		newValue = applyFormat( value, format );
	}

	return newValue;
};
github livinglab / openlab / wp-content / plugins / openlab-attributions / dist / js / formats / edit.js View on Github external
const addMarker = ( value, data ) => {
	const id = nanoid( 8 );
	const item = { ...data, id };
	const format = {
		type: 'ol/attributions',
		attributes: {
			href: `#ref-${ id }`,
			id: `anchor-${ id }`,
		},
	};

	// Add attribution.
	dispatch( 'openlab/attributions' ).add( item );

	const startIndex = isCollapsed( value ) ? value.start : value.end;
	const newValue = insertObject( value, format, startIndex );

	return newValue;
};
github WordPress / gutenberg / packages / format-library / src / image / index.js View on Github external
onSelect={ ( { id, url, alt, width } ) => {
							this.closeModal();
							onChange( insertObject( value, {
								type: name,
								attributes: {
									className: `wp-image-${ id }`,
									style: `width: ${ Math.min( width, 150 ) }px;`,
									url,
									alt,
								},
							} ) );
						} }
						onClose={ this.closeModal }