import React, { useEffect, useRef } from 'react' import { FloatingMenuPlugin, FloatingMenuPluginProps } from '@tiptap/extension-floating-menu' type Optional = Pick, K> & Omit export type FloatingMenuProps = Omit, 'element'> & { className?: string, } export const FloatingMenu: React.FC = props => { const element = useRef(null) useEffect(() => { const { pluginKey = 'floatingMenu', editor, tippyOptions = {}, shouldShow = null, } = props editor.registerPlugin(FloatingMenuPlugin({ pluginKey, editor, element: element.current as HTMLElement, tippyOptions, shouldShow, })) return () => { editor.unregisterPlugin(pluginKey) } }, []) return (
{props.children}
) }