import { Editor } from '@tiptap/core'; import React, { Dispatch, FC, SetStateAction } from 'react'; import { IconBlockquote, IconCheck, IconCheckbox, IconChevronDown, IconCode, IconH1, IconH2, IconH3, IconList, IconListNumbers, IconTypography, } from '@tabler/icons-react'; import { Popover, Button, rem, ScrollArea } from '@mantine/core'; import classes from '@/features/editor/components/bubble-menu/bubble-menu.module.css'; interface NodeSelectorProps { editor: Editor; isOpen: boolean; setIsOpen: Dispatch>; } export interface BubbleMenuItem { name: string; icon: React.ElementType; command: () => void; isActive: () => boolean; } export const NodeSelector: FC = ({ editor, isOpen, setIsOpen }) => { const items: BubbleMenuItem[] = [ { name: 'Text', icon: IconTypography, command: () => editor.chain().focus().toggleNode('paragraph', 'paragraph').run(), isActive: () => editor.isActive('paragraph') && !editor.isActive('bulletList') && !editor.isActive('orderedList'), }, { name: 'Heading 1', icon: IconH1, command: () => editor.chain().focus().toggleHeading({ level: 1 }).run(), isActive: () => editor.isActive('heading', { level: 1 }), }, { name: 'Heading 2', icon: IconH2, command: () => editor.chain().focus().toggleHeading({ level: 2 }).run(), isActive: () => editor.isActive('heading', { level: 2 }), }, { name: 'Heading 3', icon: IconH3, command: () => editor.chain().focus().toggleHeading({ level: 3 }).run(), isActive: () => editor.isActive('heading', { level: 3 }), }, { name: 'To-do List', icon: IconCheckbox, command: () => editor.chain().focus().toggleTaskList().run(), isActive: () => editor.isActive('taskItem'), }, { name: 'Bullet List', icon: IconList, command: () => editor.chain().focus().toggleBulletList().run(), isActive: () => editor.isActive('bulletList'), }, { name: 'Numbered List', icon: IconListNumbers, command: () => editor.chain().focus().toggleOrderedList().run(), isActive: () => editor.isActive('orderedList'), }, { name: 'Blockquote', icon: IconBlockquote, command: () => editor .chain() .focus() .toggleNode('paragraph', 'paragraph') .toggleBlockquote() .run(), isActive: () => editor.isActive('blockquote'), }, { name: 'Code', icon: IconCode, command: () => editor.chain().focus().toggleCodeBlock().run(), isActive: () => editor.isActive('codeBlock'), }, ]; const activeItem = items.filter((item) => item.isActive()).pop() ?? { name: 'Multiple', }; return ( {items.map((item, index) => ( ))} ); };