0.3.9修复onlyoffice 的打开问题

This commit is contained in:
liaibo
2026-01-26 13:19:48 +08:00
parent 0f22a3ff0b
commit d1f055f51a
12 changed files with 364 additions and 221 deletions
@@ -686,7 +686,7 @@ const computeDocumentStats = (blocks: Block<CustomBlockSchema>[]): DocumentStats
};
registerEditorBridge(bridge);
return () => registerEditorBridge(null);
}, [editor, registerEditorBridge]);
}, [editor, insertMediaAssetBlock, registerEditorBridge]);
useEffect(() => {
if (!editor) {
@@ -2176,47 +2176,53 @@ const MindmapBlockView = ({
};
// 处理图片删除(将 asset 移到垃圾桶)
const deleteImageAssets = async (assetIds: string[]) => {
if (!assetIds.length || !docId) return;
try {
const response = await fetch("/api/media/batch", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ action: "delete", assetIds }),
});
if (response.ok) {
// 记录到已删除列表
assetIds.forEach(id => deletedAssetIdsRef.current.add(id));
// 通知文件树刷新,传递被删除的 assetIds
emitAssetsChanged(docId, undefined, assetIds);
} else {
const payload = await response.json().catch(() => null);
console.error("删除图片资源失败", payload?.error);
const deleteImageAssets = useCallback(
async (assetIds: string[]) => {
if (!assetIds.length || !docId) return;
try {
const response = await fetch("/api/media/batch", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ action: "delete", assetIds }),
});
if (response.ok) {
// 记录到已删除列表
assetIds.forEach((id) => deletedAssetIdsRef.current.add(id));
// 通知文件树刷新,传递被删除的 assetIds
emitAssetsChanged(docId, undefined, assetIds);
} else {
const payload = await response.json().catch(() => null);
console.error("删除图片资源失败", payload?.error);
}
} catch (e) {
console.error("删除图片资源失败", e);
}
} catch (e) {
console.error("删除图片资源失败", e);
}
};
},
[docId],
);
// 处理图片恢复(从垃圾桶恢复)
const restoreImageAssets = async (assetIds: string[]) => {
if (!assetIds.length || !docId) return;
try {
const response = await fetch("/api/media/batch", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ action: "restore", assetIds }),
});
if (response.ok) {
// 从已删除列表移除
assetIds.forEach(id => deletedAssetIdsRef.current.delete(id));
// 通知文件树刷新,传递恢复的 assetIds(空列表表示需要重新获取)
emitAssetsChanged(docId);
const restoreImageAssets = useCallback(
async (assetIds: string[]) => {
if (!assetIds.length || !docId) return;
try {
const response = await fetch("/api/media/batch", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ action: "restore", assetIds }),
});
if (response.ok) {
// 从已删除列表移除
assetIds.forEach((id) => deletedAssetIdsRef.current.delete(id));
// 通知文件树刷新,传递恢复的 assetIds(空列表表示需要重新获取)
emitAssetsChanged(docId);
}
} catch (e) {
console.error("恢复图片资源失败", e);
}
} catch (e) {
console.error("恢复图片资源失败", e);
}
};
},
[docId],
);
const imgToolbarRef = useRef<HTMLDivElement | null>(null);
const [imgToolbarState, setImgToolbarState] = useState({
show: false,
@@ -2414,7 +2420,7 @@ const MindmapBlockView = ({
mindmap.off?.("back_forward", handleDataChange);
mindmap.off?.("node_data_change", handleDataChange);
};
}, [mindmap, docId]);
}, [deleteImageAssets, docId, mindmap, restoreImageAssets]);
// 悬浮图片位置工具条(参考 NodeImgPlacementToolbar.vue
const renderImgToolbar = () => {
@@ -174,6 +174,14 @@ export function MindmapContextMenu({ mindmap }: MindmapContextMenuProps) {
});
}, [targetNode]);
// 隐藏菜单
const hide = useCallback(() => {
setVisible(false);
setTargetNode(null);
setPosition({ x: -9999, y: -9999 });
requestShowRef.current = null;
}, []);
// 执行命令
const executeCommand = useCallback(
(key: string) => {
@@ -232,17 +240,9 @@ export function MindmapContextMenu({ mindmap }: MindmapContextMenuProps) {
hide();
},
[mindmap, targetNode]
[hide, mindmap, targetNode]
);
// 隐藏菜单
const hide = useCallback(() => {
setVisible(false);
setTargetNode(null);
setPosition({ x: -9999, y: -9999 });
requestShowRef.current = null;
}, []);
// 显示菜单 - 使用 requestAnimationFrame 确保 DOM 更新后再显示
const show = useCallback((x: number, y: number, node: MindMapNode) => {
setTargetNode(node);
@@ -2,7 +2,7 @@
import { BlockNoteEditor, Block } from "@blocknote/core";
import { createReactBlockSpec } from "@blocknote/react";
import React, { useCallback, useEffect, useMemo, useState } from "react";
import React, { useCallback, useMemo, useState } from "react";
import type { CustomBlockSchema } from "../schema";
import CompactTablePreview from "@/components/online-table/CompactTablePreview";
import { useEditorBridgeStore } from "@/store/editor-bridge";
@@ -53,12 +53,15 @@ const OnlineTableBlockComponent = ({
height: storedHeight ?? DEFAULT_HEIGHT,
});
useEffect(() => {
setDraftSize({
width: storedWidth ?? DEFAULT_WIDTH,
height: storedHeight ?? DEFAULT_HEIGHT,
});
}, [storedWidth, storedHeight]);
const clamp = (value: number, min: number, max: number) => Math.min(max, Math.max(min, value));
const committedSize = useMemo(
() => ({
width: clamp(storedWidth ?? DEFAULT_WIDTH, MIN_WIDTH, MAX_WIDTH),
height: clamp(storedHeight ?? DEFAULT_HEIGHT, MIN_HEIGHT, MAX_HEIGHT),
}),
[storedHeight, storedWidth],
);
const commitSize = useCallback(
(next: { width: number; height: number }) => {
@@ -71,7 +74,7 @@ const OnlineTableBlockComponent = ({
},
});
},
[block, block.props, editor],
[block, editor],
);
// 阶段三:实现双击/按钮进入全屏编辑
@@ -87,20 +90,19 @@ const OnlineTableBlockComponent = ({
editor.removeBlocks([block.id]);
}, [block.id, editor]);
const clamp = (value: number, min: number, max: number) => Math.min(max, Math.max(min, value));
const startResize = useCallback(
(handle: ResizeHandle) => (event: React.MouseEvent) => {
event.preventDefault();
event.stopPropagation();
const startX = event.clientX;
const startY = event.clientY;
const startWidth = draftSize.width;
const startHeight = draftSize.height;
const startWidth = committedSize.width;
const startHeight = committedSize.height;
let nextWidth = startWidth;
let nextHeight = startHeight;
const axes = handleMapping[handle];
setActiveHandle(handle);
setDraftSize({ width: startWidth, height: startHeight });
document.body.style.userSelect = "none";
const cursor =
axes.horizontal && axes.vertical
@@ -155,16 +157,16 @@ const OnlineTableBlockComponent = ({
window.addEventListener("mousemove", handleMove);
window.addEventListener("mouseup", handleUp);
},
[commitSize, draftSize.height, draftSize.width],
[commitSize, committedSize.height, committedSize.width],
);
const size = useMemo(
() => ({
width: clamp(draftSize.width, MIN_WIDTH, MAX_WIDTH),
height: clamp(draftSize.height, MIN_HEIGHT, MAX_HEIGHT),
}),
[draftSize.height, draftSize.width],
);
const size = useMemo(() => {
const src = activeHandle ? draftSize : committedSize;
return {
width: clamp(src.width, MIN_WIDTH, MAX_WIDTH),
height: clamp(src.height, MIN_HEIGHT, MAX_HEIGHT),
};
}, [activeHandle, committedSize, draftSize]);
const handleClass = (handle: ResizeHandle) =>
`wolai-table-resize-handle wolai-table-resize-handle--${handle} ${