'use client'; import React from 'react'; import { withRef } from '@udecode/cn'; import { AIChatPlugin } from '@udecode/plate-ai/react'; import { BlockquotePlugin } from '@udecode/plate-block-quote/react'; import { CodeBlockPlugin } from '@udecode/plate-code-block/react'; import { type PlateEditor, ParagraphPlugin } from '@udecode/plate-common/react'; import { DatePlugin } from '@udecode/plate-date/react'; import { HEADING_KEYS } from '@udecode/plate-heading'; import { TocPlugin } from '@udecode/plate-heading/react'; import { INDENT_LIST_KEYS, ListStyleType } from '@udecode/plate-indent-list'; import { TablePlugin } from '@udecode/plate-table/react'; import { TogglePlugin } from '@udecode/plate-toggle/react'; import { CalendarIcon, ChevronRightIcon, Code2, Columns3Icon, Heading1Icon, Heading2Icon, Heading3Icon, ListIcon, ListOrdered, PilcrowIcon, Quote, SparklesIcon, Square, Table, TableOfContentsIcon, } from 'lucide-react'; import { insertBlock, insertInlineElement, } from '~/components/editor/transforms'; import { InlineCombobox, InlineComboboxContent, InlineComboboxEmpty, InlineComboboxGroup, InlineComboboxGroupLabel, InlineComboboxInput, InlineComboboxItem, } from './inline-combobox'; import { PlateElement } from './plate-element'; type Group = { group: string; items: Item[]; }; interface Item { icon: React.ReactNode; onSelect: (editor: PlateEditor, value: string) => void; value: string; className?: string; focusEditor?: boolean; keywords?: string[]; label?: string; } const groups: Group[] = [ { group: 'AI', items: [ { focusEditor: false, icon: , value: 'AI', onSelect: (editor) => { editor.getApi(AIChatPlugin).aiChat.show(); }, }, ], }, { group: 'Basic blocks', items: [ { icon: , keywords: ['paragraph'], label: 'Text', value: ParagraphPlugin.key, }, { icon: , keywords: ['title', 'h1'], label: 'Heading 1', value: HEADING_KEYS.h1, }, { icon: , keywords: ['subtitle', 'h2'], label: 'Heading 2', value: HEADING_KEYS.h2, }, { icon: , keywords: ['subtitle', 'h3'], label: 'Heading 3', value: HEADING_KEYS.h3, }, { icon: , keywords: ['unordered', 'ul', '-'], label: 'Bulleted list', value: ListStyleType.Disc, }, { icon: , keywords: ['ordered', 'ol', '1'], label: 'Numbered list', value: ListStyleType.Decimal, }, { icon: , keywords: ['checklist', 'task', 'checkbox', '[]'], label: 'To-do list', value: INDENT_LIST_KEYS.todo, }, { icon: , keywords: ['collapsible', 'expandable'], label: 'Toggle', value: TogglePlugin.key, }, { icon: , keywords: ['```'], label: 'Code Block', value: CodeBlockPlugin.key, }, { icon: , label: 'Table', value: TablePlugin.key, }, { icon: , keywords: ['citation', 'blockquote', 'quote', '>'], label: 'Blockquote', value: BlockquotePlugin.key, }, ].map((item) => ({ ...item, onSelect: (editor, value) => { insertBlock(editor, value); }, })), }, { group: 'Advanced blocks', items: [ { icon: , keywords: ['toc'], label: 'Table of contents', value: TocPlugin.key, }, { icon: , label: '3 columns', value: 'action_three_columns', }, ].map((item) => ({ ...item, onSelect: (editor, value) => { insertBlock(editor, value); }, })), }, { group: 'Inline', items: [ { focusEditor: true, icon: , keywords: ['time'], label: 'Date', value: DatePlugin.key, }, ].map((item) => ({ ...item, onSelect: (editor, value) => { insertInlineElement(editor, value); }, })), }, ]; export const SlashInputElement = withRef( ({ className, ...props }, ref) => { const { children, editor, element } = props; return ( No results {groups.map(({ group, items }) => ( {group} {items.map( ({ focusEditor, icon, keywords, label, value, onSelect }) => ( onSelect(editor, value)} label={label} focusEditor={focusEditor} group={group} keywords={keywords} >
{icon}
{label ?? value}
) )}
))}
{children}
); } );