import { Editor } from "@tiptap/core"; import clsx from "clsx"; import { Check, ChevronDown, Heading1, Heading2, Heading3, TextQuote, ListOrdered, TextIcon, Code } from "lucide-react"; import { FC } from "react"; import { BubbleMenuItem } from "./EditorBubbleMenu"; interface NodeSelectorProps { editor: Editor; isOpen: boolean; setIsOpen: (isOpen: boolean) => void; } export const NodeSelector: FC = ({ editor, isOpen, setIsOpen }) => { const items: BubbleMenuItem[] = [ { name: "Text", icon: TextIcon, command: () => editor.chain().focus().toggleNode("paragraph", "paragraph").run(), // I feel like there has to be a more efficient way to do this – feel free to PR if you know how! isActive: () => editor.isActive("paragraph") && !editor.isActive("bulletList") && !editor.isActive("orderedList"), }, { name: "Heading 1", icon: Heading1, command: () => editor.chain().focus().toggleHeading({ level: 1 }).run(), isActive: () => editor.isActive("heading", { level: 1 }), }, { name: "Heading 2", icon: Heading2, command: () => editor.chain().focus().toggleHeading({ level: 2 }).run(), isActive: () => editor.isActive("heading", { level: 2 }), }, { name: "Heading 3", icon: Heading3, command: () => editor.chain().focus().toggleHeading({ level: 3 }).run(), isActive: () => editor.isActive("heading", { level: 3 }), }, { name: "List (•)", icon: ListOrdered, command: () => editor.chain().focus().toggleBulletList().run(), isActive: () => editor.isActive("bulletList"), }, { name: "List (1.)", icon: ListOrdered, command: () => editor.chain().focus().toggleOrderedList().run(), isActive: () => editor.isActive("orderedList"), }, { name: "Quote", icon: TextQuote, command: () => editor.chain().focus().toggleNode("paragraph", "paragraph").toggleBlockquote().run(), isActive: () => editor.isActive("blockquote"), }, { name: "Code", icon: Code, command: () => editor.chain().focus().toggleCodeBlock().run(), isActive: () => editor.isActive("codeBlock"), }, ]; const activeItem = items.filter((item) => item.isActive()).pop() ?? { name: "Multiple", }; return (
{isOpen && (
{items.map((item, index) => ( ))}
)}
); };