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.

18 lines (15 loc) 606 B
// Custom Types import { State } from '../../types'; const isLink = (editorState: State, customLinkKey?: string) => { const selectionState = editorState.getSelection(); const contentState = editorState.getCurrentContent(); const block = contentState.getBlockForKey(selectionState.getStartKey()); const entityKey = block.getEntityAt(selectionState.getStartOffset()); if (entityKey) { const entity = contentState.getEntity(entityKey); const entityType = entity.getType(); return entityType === (customLinkKey ?? 'link'); } return false; }; export default isLink;