mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-12-15 02:59:01 +08:00
add menubar plugin
This commit is contained in:
parent
8b94b43919
commit
15fcb3cd1a
@ -1,3 +1,5 @@
|
||||
import MenuBar from '../Plugins/MenuBar'
|
||||
|
||||
export default {
|
||||
|
||||
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() {
|
||||
if (!this.editor) {
|
||||
return null
|
||||
|
29
packages/tiptap/src/Plugins/MenuBar.js
Normal file
29
packages/tiptap/src/Plugins/MenuBar.js
Normal 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 })
|
||||
},
|
||||
})
|
||||
}
|
Loading…
Reference in New Issue
Block a user