import { BubbleMenuPlugin, BubbleMenuPluginProps } from '@tiptap/extension-bubble-menu' import React, { useEffect, useState } from 'react' type Optional = Pick, K> & Omit; export type BubbleMenuProps = Omit, 'element'> & { className?: string; children: React.ReactNode; updateDelay?: number; }; export const BubbleMenu = (props: BubbleMenuProps) => { const [element, setElement] = useState(null) useEffect(() => { if (!element) { return } if (props.editor.isDestroyed) { return } const { pluginKey = 'bubbleMenu', editor, tippyOptions = {}, updateDelay, shouldShow = null, } = props const plugin = BubbleMenuPlugin({ updateDelay, editor, element, pluginKey, shouldShow, tippyOptions, }) editor.registerPlugin(plugin) return () => editor.unregisterPlugin(pluginKey) }, [props.editor, element]) return (
{props.children}
) }