Files
tiptap/packages/core/src/extensions/focusEvents.ts
Dominik 53e39d0c47 refactor(maintainment): set dependency versions for prosemirror and y… (#2904)
* refactor(maintainment): set dependency versions for prosemirror and yjs to fixed versions

* refactor(docs): fix dependency versions in demos

* chore: update package-lock.json

* chore: update latest prosemirror packages
2022-06-21 00:17:10 +02:00

44 lines
1016 B
TypeScript

import { Plugin, PluginKey } from 'prosemirror-state'
import { Extension } from '../Extension'
export const FocusEvents = Extension.create({
name: 'focusEvents',
addProseMirrorPlugins() {
const { editor } = this
return [
new Plugin({
key: new PluginKey('focusEvents'),
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
},
},
},
}),
]
},
})