diff --git a/wolai-frontend/.gitignore b/wolai-frontend/.gitignore index 2b84e14d..7583c207 100644 --- a/wolai-frontend/.gitignore +++ b/wolai-frontend/.gitignore @@ -43,4 +43,5 @@ next-env.d.ts #test **/test/ pw-tests/** -pw-tests/ \ No newline at end of file +pw-tests/ +wolai-frontend\public\documents \ No newline at end of file diff --git a/wolai-frontend/src/components/editor/blocks/MindmapBlock.tsx b/wolai-frontend/src/components/editor/blocks/MindmapBlock.tsx index d7163c60..eff55715 100644 --- a/wolai-frontend/src/components/editor/blocks/MindmapBlock.tsx +++ b/wolai-frontend/src/components/editor/blocks/MindmapBlock.tsx @@ -331,22 +331,6 @@ const MindmapBlockView = ({ }, 500); const initialSyncDone = useRef(false); - // 若渲染结束后激活列表被清空,定期兜底恢复根节点为选中,避免后续指令找不到父节点 - useEffect(() => { - if (!mindmap) return; - const timer = window.setInterval(() => { - const renderer = mindmap.renderer; - if (!renderer) return; - if (!renderer.activeNodeList || renderer.activeNodeList.length === 0) { - const root = getRootNode(mindmap); - if (root && renderer.addNodeToActiveList) { - renderer.addNodeToActiveList(root, true); - renderer.emitNodeActiveEvent?.(root); - } - } - }, 200); - return () => window.clearInterval(timer); - }, [getRootNode, mindmap]); useEffect(() => { if (!docId || !mindmap || initialSyncDone.current) return; initialSyncDone.current = true; @@ -757,17 +741,6 @@ const MindmapBlockView = ({ window.setTimeout(() => runWhenReady(fn, retry + 1), 50); } }; - const recenterIfNeeded = (mm?: MindMapInstance | null) => { - try { - const instance = mm ?? getInstanceCandidate(); - const renderer = instance?.renderer; - const view = instance?.view; - renderer?.setRootNodeCenter && renderer.setRootNodeCenter(); - view?.fit && view.fit(); - } catch { - /* 空 */ - } - }; const execWithReflow = (runner: (mm: MindMapInstance) => void) => { const attempt = (retry = 0) => { const instance = getInstanceCandidate(); @@ -777,14 +750,6 @@ const MindmapBlockView = ({ } const mm = ensureActiveBefore(instance); if (!mm) return; - try { - const renderer = mm.renderer as any; - if (renderer?.refresh) renderer.refresh(); - if (renderer?.reRender) renderer.reRender(); - recenterIfNeeded(mm); - } catch { - /* 空 */ - } runner(mm); }; attempt(); diff --git a/wolai-frontend/src/components/editor/blocks/MindmapCount.tsx b/wolai-frontend/src/components/editor/blocks/MindmapCount.tsx index 00b9d0e8..c219c40e 100644 --- a/wolai-frontend/src/components/editor/blocks/MindmapCount.tsx +++ b/wolai-frontend/src/components/editor/blocks/MindmapCount.tsx @@ -13,28 +13,34 @@ export const MindmapCount = ({ mindmap }: CountProps) => { const calculateCounts = (data: any) => { let nodes = 0; - let textStr = ""; + let words = 0; + + const stripHtmlLen = (html: string) => { + // 简易去标签统计长度:避免每次 data_change 都创建 DOM 容器造成卡顿 + const plain = html + .replace(/<[^>]*>/g, "") + .replace(/ /g, " ") + .replace(/\s+/g, " ") + .trim(); + return plain.length; + }; const walk = (nodeData: any) => { if (!nodeData) return; nodes++; - // simple-mind-map node data structure: { data: { text: ... }, children: [...] } + // simple-mind-map 节点数据结构:{ data: { text: ... }, children: [...] } const text = String(nodeData.data?.text || ""); - textStr += text; - + words += stripHtmlLen(text); + if (nodeData.children && Array.isArray(nodeData.children)) { nodeData.children.forEach(walk); } }; - walk(data); + const root = data?.root ?? data; + walk(root); - // Remove HTML tags for word count - const tempDiv = document.createElement("div"); - tempDiv.innerHTML = textStr; - const words = tempDiv.textContent?.length || 0; - - setCounts({ words, nodes }); + setCounts((prev) => (prev.words === words && prev.nodes === nodes ? prev : { words, nodes })); }; const onDataChange = (data: any) => { @@ -42,14 +48,13 @@ export const MindmapCount = ({ mindmap }: CountProps) => { }; mindmap.on("data_change", onDataChange); - - // Initial calculation if data is available - // mindmap.getData() might return full data object + + // 初次渲染时尝试计算一次(mindmap.getData() 可能返回完整数据对象) try { const initialData = mindmap.getData(); if (initialData) calculateCounts(initialData); } catch (e) { - console.warn("Failed to get initial mindmap data for count", e); + console.warn("获取思维导图初始数据用于统计失败", e); } return () => { diff --git a/wolai-frontend/src/components/editor/blocks/MindmapToolbar.tsx b/wolai-frontend/src/components/editor/blocks/MindmapToolbar.tsx index 45bbe485..80ea71d0 100644 --- a/wolai-frontend/src/components/editor/blocks/MindmapToolbar.tsx +++ b/wolai-frontend/src/components/editor/blocks/MindmapToolbar.tsx @@ -9,7 +9,6 @@ import { } from "./mindmapToolbarConfig"; const stopEditorEvent = (e: React.SyntheticEvent) => { - e.preventDefault(); e.stopPropagation(); };