How to use the @wordpress/rich-text.getActiveFormat 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
//
RT.create();
RT.create({ text: 'Hello World!' });
RT.create({ html: '<p>Hello World!</p><p>' });
RT.create({ element: document.createElement('div') });
RT.create({
    element: document.createElement('div'),
    multilineTag: 'p',
    multilineWrapperTags: ['div', 'p'],
    range: new Range(),
});

//
// getActiveFormat
//
RT.getActiveFormat(VALUE, 'foo');

//
// getActiveObject
//
RT.getActiveObject(VALUE);

//
// getTextContent
//
RT.getTextContent(VALUE);

//
// insert
//
RT.insert(VALUE, VALUE);
RT.insert(VALUE, VALUE, 10);</p>
github WordPress / gutenberg / packages / format-library / src / link / index.native.js View on Github external
getLinkSelection() {
			const { value, isActive } = this.props;
			const startFormat = getActiveFormat( value, 'core/link' );

			// if the link isn't selected, get the link manually by looking around the cursor
			// TODO: handle partly selected links
			if ( startFormat && isCollapsed( value ) && isActive ) {
				let startIndex = value.start;
				let endIndex = value.end;

				while ( find( value.formats[ startIndex ], startFormat ) ) {
					startIndex--;
				}

				endIndex++;

				while ( find( value.formats[ endIndex ], startFormat ) ) {
					endIndex++;
				}
github ampproject / amp-wp / assets / src / stories-editor / formats / text-color / edit.js View on Github external
const FormatEdit = ( { isActive, value, onChange } ) =&gt; {
	let activeColor;

	if ( isActive ) {
		const activeFormat = getActiveFormat( value, name );
		const style = activeFormat.attributes.style;
		activeColor = style.replace( new RegExp( `^color:\\s*` ), '' );
	}

	return (
		
			
				 (
github WordPress / gutenberg / packages / format-library / src / text-color / inline.js View on Github external
render() {
		const {
			name,
			value,
			onChange,
			isActive,
			addingColor,
		} = this.props;

		let activeColor;

		const isDisableCustomColors = get( select( 'core/block-editor' ).getSettings(), [ 'disableCustomColors' ], false );
		const colors = get( select( 'core/block-editor' ).getSettings(), [ 'colors' ], [] );
		const activeColorFormat = getActiveFormat( value, name );

		if ( activeColorFormat ) {
			const styleColor = activeColorFormat.attributes.style;
			if ( styleColor ) {
				activeColor = styleColor.replace( new RegExp( `^color:\\s*` ), '' );
			} else {
				const currentClass = activeColorFormat.attributes.class;
				if ( currentClass ) {
					const colorSlug = currentClass.replace( /.*has-(.*?)-color.*/, '$1' );
					activeColor = getColorObjectByAttributeValues( colors, colorSlug ).color;
				}
			}
		}

		return (
github ampproject / amp-wp / assets / src / stories-editor / formats / background-color / edit.js View on Github external
const FormatEdit = ( { isActive, value, onChange } ) =&gt; {
	let activeColor;

	if ( isActive ) {
		const activeFormat = getActiveFormat( value, name );
		const style = activeFormat.attributes.style;
		activeColor = style.replace( new RegExp( `^background-color:\\s*` ), '' );
	}

	return (
		
			
				 (