UNPKG

contenido

Version:

Contenido is a library with a set of tools to help you create your own rich text editor on top of draft-js without thinking about how to handle things.

22 lines (18 loc) 522 B
// Types import type { ContentBlock, ContentState } from 'draft-js'; const findEntitiesOf = (entityType: string) => ( contentBlock: ContentBlock, callback: (start: number, end: number) => void, contentState: ContentState ) => { contentBlock.findEntityRanges((character) => { const entityKey = character.getEntity(); return ( entityKey !== null && contentState.getEntity(entityKey).getType() === entityType ); }, callback); }; export default findEntitiesOf;