2021-03-30 20:07:18 +08:00
|
|
|
import Vue, { PropType } from 'vue'
|
|
|
|
import { BubbleMenuPlugin, BubbleMenuPluginKey, BubbleMenuPluginProps } from '@tiptap/extension-bubble-menu'
|
|
|
|
|
|
|
|
export const BubbleMenu = Vue.extend({
|
|
|
|
name: 'BubbleMenu',
|
|
|
|
|
|
|
|
props: {
|
|
|
|
editor: {
|
|
|
|
type: Object as PropType<BubbleMenuPluginProps['editor']>,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
watch: {
|
|
|
|
editor: {
|
|
|
|
immediate: true,
|
|
|
|
handler(editor: BubbleMenuPluginProps['editor']) {
|
|
|
|
if (!editor) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
editor.registerPlugin(BubbleMenuPlugin({
|
|
|
|
editor,
|
|
|
|
element: this.$el as HTMLElement,
|
|
|
|
}))
|
|
|
|
})
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
render(createElement) {
|
2021-04-01 23:55:32 +08:00
|
|
|
return createElement('div', { style: { visibility: 'hidden' } }, this.$slots.default)
|
2021-03-30 20:07:18 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
beforeDestroy() {
|
|
|
|
this.editor.unregisterPlugin(BubbleMenuPluginKey)
|
|
|
|
},
|
|
|
|
})
|