add floating menu to vue 3 and react
This commit is contained in:
41
packages/vue-3/src/FloatingMenu.ts
Normal file
41
packages/vue-3/src/FloatingMenu.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
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)
|
||||
})
|
||||
|
||||
return () => h('div', { ref: root }, slots.default?.())
|
||||
},
|
||||
})
|
||||
@@ -2,6 +2,7 @@ export * from '@tiptap/core'
|
||||
export * from './BubbleMenu'
|
||||
export { Editor } from './Editor'
|
||||
export * from './EditorContent'
|
||||
export * from './FloatingMenu'
|
||||
export * from './useEditor'
|
||||
export * from './VueRenderer'
|
||||
export * from './VueNodeViewRenderer'
|
||||
|
||||
Reference in New Issue
Block a user