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