UNPKG

@tiptap/core

Version:

headless rich text editor

42 lines (30 loc) 1.01 kB
import { Plugin, PluginKey } from '@tiptap/pm/state' import { Extension } from '../Extension.js' export const focusEventsPluginKey = new PluginKey('focusEvents') export const FocusEvents = Extension.create({ name: 'focusEvents', addProseMirrorPlugins() { const { editor } = this return [ new Plugin({ key: focusEventsPluginKey, props: { handleDOMEvents: { focus: (view, event: Event) => { editor.isFocused = true const transaction = editor.state.tr.setMeta('focus', { event }).setMeta('addToHistory', false) view.dispatch(transaction) return false }, blur: (view, event: Event) => { editor.isFocused = false const transaction = editor.state.tr.setMeta('blur', { event }).setMeta('addToHistory', false) view.dispatch(transaction) return false }, }, }, }), ] }, })