add wallnote

This commit is contained in:
2025-02-23 02:25:11 +08:00
parent 07d053abe7
commit a91f80c1ba
30 changed files with 3207 additions and 143 deletions

View File

@@ -0,0 +1,32 @@
import { TextEditor } from '@/modules/tiptap/editor';
import { useEffect, useRef, useState } from 'react';
import clsx from 'clsx';
type EditorProps = {
className?: string;
value?: string;
id?: string;
onChange?: (value: string) => void;
};
export const Editor = ({ className, value, onChange, id }: EditorProps) => {
const textEditorRef = useRef<TextEditor | null>(null);
const editorRef = useRef<HTMLDivElement>(null);
const [mount, setMount] = useState(false);
useEffect(() => {
const editor = new TextEditor();
textEditorRef.current = editor;
editor.createEditor(editorRef.current!, { html: value });
editor.onContentChange((content) => {
onChange?.(content);
});
setMount(true);
return () => {
editor.destroy();
};
}, []);
useEffect(() => {
if (textEditorRef.current && id && mount) {
textEditorRef.current.setContent(value || '');
}
}, [id, mount]);
return <div ref={editorRef} className={clsx('w-full h-full node-editor', className)}></div>;
};