import { forwardRef, useImperativeHandle } from 'react';
import { useEditor, EditorContent } from '@tiptap/react';
import StarterKit from '@tiptap/starter-kit';
import Underline from '@tiptap/extension-underline';
import TextAlign from '@tiptap/extension-text-align';
import { Select } from 'antd';
import {
AlignCenterOutlined,
AlignLeftOutlined,
AlignRightOutlined,
BoldOutlined,
ItalicOutlined,
OrderedListOutlined,
RedoOutlined,
StrikethroughOutlined,
UnderlineOutlined,
UndoOutlined,
UnorderedListOutlined,
} from '@ant-design/icons';
export interface WysiwygEditorHandle {
getHTML: () => string;
getText: () => string;
setContent: (html: string) => void;
}
interface WysiwygEditorProps {
minHeight?: number;
}
function ToolBtn({
active,
disabled,
onClick,
title,
children,
}: {
active?: boolean;
disabled?: boolean;
onClick: () => void;
title?: string;
children: React.ReactNode;
}) {
return (
);
}
function Divider() {
return ;
}
const HEADING_OPTIONS = [
{ value: 'p', label: 'Normal' },
{ value: '1', label: 'Überschrift 1' },
{ value: '2', label: 'Überschrift 2' },
{ value: '3', label: 'Überschrift 3' },
];
export const WysiwygEditor = forwardRef(
({ minHeight = 200 }, ref) => {
const editor = useEditor({
extensions: [
StarterKit,
Underline,
TextAlign.configure({ types: ['heading', 'paragraph'] }),
],
content: '',
});
useImperativeHandle(
ref,
() => ({
getHTML: () => editor?.getHTML() ?? '',
getText: () => editor?.getText() ?? '',
setContent: (html: string) => {
editor?.commands.setContent(html);
},
}),
[editor],
);
if (!editor) return null;
const headingLevel = editor.isActive('heading', { level: 1 })
? '1'
: editor.isActive('heading', { level: 2 })
? '2'
: editor.isActive('heading', { level: 3 })
? '3'
: 'p';
return (
editor.chain().focus().undo().run()}
>
editor.chain().focus().redo().run()}
>
);
},
);