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.

20 lines (14 loc) 471 B
// Custom Types import type { State } from '../../types'; const getAtomicCount = (state: State, blockType: string) => { let count = 0; const contentState = state.getCurrentContent(); contentState.getBlockMap().forEach((block) => { if (block && block.getType() === 'atomic') { const entity = contentState.getEntity(block.getEntityAt(0)); if (entity.getType() === blockType) count++; } }); return count; }; export default getAtomicCount;