add menubar plugin

This commit is contained in:
Philipp Kühn 2019-08-07 12:18:58 +02:00
parent 8b94b43919
commit 15fcb3cd1a
2 changed files with 47 additions and 0 deletions

View File

@ -1,3 +1,5 @@
import MenuBar from '../Plugins/MenuBar'
export default { export default {
props: { props: {
@ -7,6 +9,22 @@ export default {
}, },
}, },
watch: {
editor: {
immediate: true,
handler(editor) {
if (editor) {
this.$nextTick(() => {
editor.registerPlugin(MenuBar({
editor,
element: this.$el,
}))
})
}
},
},
},
render() { render() {
if (!this.editor) { if (!this.editor) {
return null return null

View File

@ -0,0 +1,29 @@
import { Plugin, PluginKey } from 'prosemirror-state'
class Menu {
constructor({ options }) {
this.options = options
// the mousedown event is fired before blur so we can prevent it
this.options.element.addEventListener('mousedown', this.handleClick)
}
handleClick(event) {
event.preventDefault()
}
destroy() {
this.options.element.removeEventListener('mousedown', this.handleClick)
}
}
export default function (options) {
return new Plugin({
key: new PluginKey('menu_bar'),
view(editorView) {
return new Menu({ editorView, options })
},
})
}