2021-08-11 20:37:58 +08:00
|
|
|
import { BubbleMenuPlugin, BubbleMenuPluginProps } from '@tiptap/extension-bubble-menu'
|
2022-06-08 20:10:25 +08:00
|
|
|
import Vue, { Component, PropType } from 'vue'
|
2021-03-30 20:07:18 +08:00
|
|
|
|
2021-05-04 17:03:11 +08:00
|
|
|
export interface BubbleMenuInterface extends Vue {
|
2021-08-13 18:33:06 +08:00
|
|
|
pluginKey: BubbleMenuPluginProps['pluginKey'],
|
2021-05-04 17:03:11 +08:00
|
|
|
editor: BubbleMenuPluginProps['editor'],
|
2021-08-11 20:37:58 +08:00
|
|
|
tippyOptions: BubbleMenuPluginProps['tippyOptions'],
|
|
|
|
shouldShow: BubbleMenuPluginProps['shouldShow'],
|
2021-05-03 21:11:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const BubbleMenu: Component = {
|
2021-03-30 20:07:18 +08:00
|
|
|
name: 'BubbleMenu',
|
|
|
|
|
|
|
|
props: {
|
2021-08-11 20:37:58 +08:00
|
|
|
pluginKey: {
|
2021-08-13 18:33:06 +08:00
|
|
|
type: [String, Object as PropType<Exclude<BubbleMenuPluginProps['pluginKey'], string>>],
|
2021-08-11 20:37:58 +08:00
|
|
|
default: 'bubbleMenu',
|
|
|
|
},
|
|
|
|
|
2021-03-30 20:07:18 +08:00
|
|
|
editor: {
|
|
|
|
type: Object as PropType<BubbleMenuPluginProps['editor']>,
|
|
|
|
required: true,
|
|
|
|
},
|
2021-04-16 18:42:56 +08:00
|
|
|
|
|
|
|
tippyOptions: {
|
|
|
|
type: Object as PropType<BubbleMenuPluginProps['tippyOptions']>,
|
|
|
|
default: () => ({}),
|
|
|
|
},
|
2021-08-11 20:37:58 +08:00
|
|
|
|
|
|
|
shouldShow: {
|
|
|
|
type: Function as PropType<Exclude<BubbleMenuPluginProps['shouldShow'], null>>,
|
|
|
|
default: null,
|
|
|
|
},
|
2021-03-30 20:07:18 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
watch: {
|
|
|
|
editor: {
|
|
|
|
immediate: true,
|
2021-05-04 17:03:11 +08:00
|
|
|
handler(this: BubbleMenuInterface, editor: BubbleMenuPluginProps['editor']) {
|
2021-03-30 20:07:18 +08:00
|
|
|
if (!editor) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
editor.registerPlugin(BubbleMenuPlugin({
|
2021-08-13 18:33:06 +08:00
|
|
|
pluginKey: this.pluginKey,
|
2021-03-30 20:07:18 +08:00
|
|
|
editor,
|
|
|
|
element: this.$el as HTMLElement,
|
2021-04-16 18:42:56 +08:00
|
|
|
tippyOptions: this.tippyOptions,
|
2021-08-11 20:37:58 +08:00
|
|
|
shouldShow: this.shouldShow,
|
2021-03-30 20:07:18 +08:00
|
|
|
}))
|
|
|
|
})
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2021-05-04 17:03:11 +08:00
|
|
|
render(this: BubbleMenuInterface, 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
|
|
|
},
|
|
|
|
|
2021-05-04 17:03:11 +08:00
|
|
|
beforeDestroy(this: BubbleMenuInterface) {
|
2021-08-11 20:37:58 +08:00
|
|
|
this.editor.unregisterPlugin(this.pluginKey)
|
2021-03-30 20:07:18 +08:00
|
|
|
},
|
2021-05-03 21:11:26 +08:00
|
|
|
}
|