add floating menu to vue 3 and react

This commit is contained in:
Philipp Kühn
2021-04-01 15:55:19 +02:00
parent 3f1fa81392
commit 3eac1ce319
8 changed files with 94 additions and 13 deletions

View File

@@ -28,6 +28,7 @@
},
"dependencies": {
"@tiptap/extension-bubble-menu": "^2.0.0-beta.3",
"@tiptap/extension-floating-menu": "^2.0.0-beta.0",
"prosemirror-view": "^1.18.2"
},
"devDependencies": {

View File

@@ -0,0 +1,29 @@
import React, { useEffect, useRef } from 'react'
import { FloatingMenuPlugin, FloatingMenuPluginKey, FloatingMenuPluginProps } from '@tiptap/extension-floating-menu'
export type FloatingMenuProps = Omit<FloatingMenuPluginProps, 'element'> & {
className?: string,
}
export const FloatingMenu: React.FC<FloatingMenuProps> = props => {
const element = useRef<HTMLDivElement>(null)
useEffect(() => {
const { editor } = props
editor.registerPlugin(FloatingMenuPlugin({
editor,
element: element.current as HTMLElement,
}))
return () => {
editor.unregisterPlugin(FloatingMenuPluginKey)
}
}, [])
return (
<div ref={element} className={props.className}>
{props.children}
</div>
)
}

View File

@@ -1,6 +1,7 @@
export * from '@tiptap/core'
export * from './BubbleMenu'
export { Editor } from './Editor'
export * from './FloatingMenu'
export * from './useEditor'
export * from './ReactRenderer'
export * from './ReactNodeViewRenderer'