|
|
|
|
@ -37,28 +37,30 @@ const EditorViewer: React.FC<{ content: string }> = ({ content }) => {
|
|
|
|
|
|
|
|
|
|
export default function EditorSection({ initialContent, visible, onChange }: EditorSectionProps) {
|
|
|
|
|
const [isClient, setIsClient] = useState(false);
|
|
|
|
|
const [editorLoaded, setEditorLoaded] = useState(false);
|
|
|
|
|
const [currentContent, setCurrentContent] = useState(initialContent || '');
|
|
|
|
|
const editorRef = useRef<any>(null);
|
|
|
|
|
const editorInstanceRef = useRef<ToastEditor | null>(null);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (!isSSR) {
|
|
|
|
|
if (!isSSR && visible && !editorRef.current) {
|
|
|
|
|
setIsClient(true);
|
|
|
|
|
|
|
|
|
|
// 动态导入编辑器组件
|
|
|
|
|
import('@toast-ui/react-editor').then((module) => {
|
|
|
|
|
editorRef.current = module.Editor;
|
|
|
|
|
setEditorLoaded(true); // 标记编辑器已加载
|
|
|
|
|
}).catch((error) => {
|
|
|
|
|
console.error('Failed to load Toast UI Editor:', error);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 更新当前内容当初始内容变化时
|
|
|
|
|
setCurrentContent(initialContent || '');
|
|
|
|
|
}, [initialContent, visible]);
|
|
|
|
|
|
|
|
|
|
// 在服务端或组件未加载完成时,使用 Viewer 模式显示内容
|
|
|
|
|
if (!isClient || !editorRef.current || !visible) {
|
|
|
|
|
if (!isClient || !editorLoaded || !visible) {
|
|
|
|
|
return (
|
|
|
|
|
<div className="mt-8">
|
|
|
|
|
<EditorViewer content={currentContent || ''} />
|
|
|
|
|
|