diff --git a/src/components/EditorSection/index.tsx b/src/components/EditorSection/index.tsx index 9c00b94..6bbb027 100644 --- a/src/components/EditorSection/index.tsx +++ b/src/components/EditorSection/index.tsx @@ -6,6 +6,7 @@ import { isSSR } from '@/utils/is'; interface EditorSectionProps { initialContent?: string; + visible: boolean; onChange?: (content: string) => void; } @@ -34,9 +35,11 @@ const EditorViewer: React.FC<{ content: string }> = ({ content }) => { return
; }; -export default function EditorSection({ initialContent, onChange }: EditorSectionProps) { +export default function EditorSection({ initialContent, visible, onChange }: EditorSectionProps) { const [isClient, setIsClient] = useState(false); + const [currentContent, setCurrentContent] = useState(initialContent || ''); const editorRef = useRef(null); + const editorInstanceRef = useRef(null); useEffect(() => { if (!isSSR) { @@ -49,13 +52,16 @@ export default function EditorSection({ initialContent, onChange }: EditorSectio console.error('Failed to load Toast UI Editor:', error); }); } - }, []); + + // 更新当前内容当初始内容变化时 + setCurrentContent(initialContent || ''); + }, [initialContent, visible]); // 在服务端或组件未加载完成时,使用 Viewer 模式显示内容 - if (!isClient || !editorRef.current) { + if (!isClient || !editorRef.current || !visible) { return (
- +
); } @@ -65,13 +71,15 @@ export default function EditorSection({ initialContent, onChange }: EditorSectio return (
{ // 获取编辑器实例并读取内容 const editorInstance = editorRef.current?.getInstance?.(); if (editorInstance && onChange) { const content = editorInstance.getMarkdown(); + setCurrentContent(content); onChange(content); } }} diff --git a/src/pages/componentDevelopment/componentList/addComponentModal.tsx b/src/pages/componentDevelopment/componentList/addComponentModal.tsx index fd2226c..6e90c80 100644 --- a/src/pages/componentDevelopment/componentList/addComponentModal.tsx +++ b/src/pages/componentDevelopment/componentList/addComponentModal.tsx @@ -696,9 +696,8 @@ const AddComponentModal = ({ visible, baseInfo, setVisible, onReFresh, mode = 'c
描述:
setDescription(content)} />
diff --git a/src/pages/componentMarket/copyComponentModal.tsx b/src/pages/componentMarket/copyComponentModal.tsx index 7c497ce..536c46e 100644 --- a/src/pages/componentMarket/copyComponentModal.tsx +++ b/src/pages/componentMarket/copyComponentModal.tsx @@ -259,9 +259,8 @@ const CopyComponentModal: React.FC = ({ setDescription(content)} />