tiptap/packages/vue-3/src/FloatingMenu.ts

42 lines
840 B
TypeScript
Raw Normal View History

2021-04-01 21:55:19 +08:00
import {
h,
ref,
PropType,
onMounted,
onBeforeUnmount,
defineComponent,
} from 'vue'
import {
FloatingMenuPlugin,
FloatingMenuPluginKey,
FloatingMenuPluginProps,
} from '@tiptap/extension-floating-menu'
export const FloatingMenu = defineComponent({
name: 'FloatingMenu',
props: {
editor: {
type: Object as PropType<FloatingMenuPluginProps['editor']>,
required: true,
},
},
setup({ editor }, { slots }) {
const root = ref<HTMLElement | null>(null)
onMounted(() => {
editor.registerPlugin(FloatingMenuPlugin({
editor,
element: root.value as HTMLElement,
}))
})
onBeforeUnmount(() => {
editor.unregisterPlugin(FloatingMenuPluginKey)
})
2021-04-01 23:55:32 +08:00
return () => h('div', { ref: root, style: { visibility: 'hidden' } }, slots.default?.())
2021-04-01 21:55:19 +08:00
},
})