schlechtenburg/packages/rich-text/lib/get-active-object.ts
2024-10-08 09:15:26 +02:00

22 lines
535 B
TypeScript

/**
* Internal dependencies
*/
import { OBJECT_REPLACEMENT_CHARACTER } from './special-characters';
import { RichTextValue } from './types';
/**
* Gets the active object, if there is any.
*
* @param {RichTextValue} value Value to inspect.
*
* @return {RichTextFormat|void} Active object, or undefined.
*/
export function getActiveObject( { start = 0, end = 0, replacements, text }: RichTextValue ) {
if ( start + 1 !== end || text[ start ] !== OBJECT_REPLACEMENT_CHARACTER ) {
return;
}
return replacements[ start ];
}