UNPKG

substance

Version:

Substance is a JavaScript library for web-based content editing. It provides building blocks for realizing custom text editors and web-based publishing system. It is developed to power our online editing platform [Substance](http://substance.io).

30 lines (27 loc) 997 B
import { AnnotationCommand } from '../editor' import { $$ } from '../dom' import LinkModal from './LinkModal' export default class CreateLinkCommand extends AnnotationCommand { // TODO: GDocs enables the tool even if over a link // but not creating a new link, but opening the editor for the existing link getCommandState (params, context) { const sel = params.selection const selectionState = params.selectionState if (sel && !sel.isNull() && sel.isPropertySelection()) { const links = selectionState.annosByType.get('link') || [] if (super.canCreate(links, sel, context)) { return { disabled: false } } } return { disabled: true } } execute (params, context) { context.editorSession.getRootComponent().send('requestModal', () => { return $$(LinkModal, { mode: 'create' }) }).then(modal => { if (!modal) return const href = modal.refs.href.val() context.api.insertAnnotation('link', { href }) }) } }