import * as React from "react" import type { Editor } from "@tiptap/react" import type { VariantProps } from "class-variance-authority" import type { toggleVariants } from "@/components/ui/toggle" import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover" import { Link2Icon } from "@radix-ui/react-icons" import { ToolbarButton } from "../toolbar-button" import { LinkEditBlock } from "./link-edit-block" interface LinkEditPopoverProps extends VariantProps { editor: Editor } const LinkEditPopover = ({ editor, size, variant }: LinkEditPopoverProps) => { const [open, setOpen] = React.useState(false) const { from, to } = editor.state.selection const text = editor.state.doc.textBetween(from, to, " ") const onSetLink = React.useCallback( (url: string, text?: string, openInNewTab?: boolean) => { editor .chain() .focus() .extendMarkRange("link") .insertContent({ type: "text", text: text || url, marks: [ { type: "link", attrs: { href: url, target: openInNewTab ? "_blank" : "", }, }, ], }) .setLink({ href: url }) .run() editor.commands.enter() }, [editor], ) return ( ) } export { LinkEditPopover }