"use client";
import { Button } from "@mdxui/primitives/button";
import { Card } from "@mdxui/primitives/card";
import { cn } from "@mdxui/primitives/lib/utils";
import Placeholder from "@tiptap/extension-placeholder";
import { type Editor, EditorContent, useEditor } from "@tiptap/react";
import StarterKit from "@tiptap/starter-kit";
import {
Code,
Heading1,
Heading2,
Heading3,
List,
ListOrdered,
Quote,
Type,
} from "lucide-react";
import type React from "react";
import { useState } from "react";
export interface BlockEditorProps {
/** Initial JSON content */
initialValue?: any;
/** Callback when content changes */
onChange?: (json: any) => void;
/** Placeholder text */
placeholder?: string;
/** Height of the editor */
height?: string | number;
/** Additional CSS class */
className?: string;
/** Whether the editor is read-only */
readOnly?: boolean;
/** Available block types */
availableBlocks?: BlockType[];
}
export type BlockType =
| "paragraph"
| "heading1"
| "heading2"
| "heading3"
| "bulletList"
| "orderedList"
| "quote"
| "code"
| "image";
interface BlockMenuItem {
type: BlockType;
label: string;
icon: React.ReactNode;
action: (editor: Editor) => void;
}
const getBlockMenuItems = (_editor: Editor): BlockMenuItem[] => [
{
type: "paragraph",
label: "Text",
icon: ,
action: (e) => e.chain().focus().toggleBulletList().run(),
},
{
type: "orderedList",
label: "Numbered List",
icon:
,
action: (e) => e.chain().focus().toggleBlockquote().run(),
},
{
type: "code",
label: "Code",
icon:
,
action: (e) => e.chain().focus().toggleCodeBlock().run(),
},
];
const BlockMenu: React.FC<{
editor: Editor;
onClose: () => void;
availableBlocks?: BlockType[];
}> = ({ editor, onClose, availableBlocks }) => {
const items = getBlockMenuItems(editor).filter(
(item) => !availableBlocks || availableBlocks.includes(item.type),
);
return (