0.1.06文件树的选择问题及思维导图删除问题
This commit is contained in:
@@ -7,7 +7,7 @@ import {
|
||||
getDefaultReactSlashMenuItems,
|
||||
type DefaultReactSuggestionItem,
|
||||
} from "@blocknote/react";
|
||||
import { filterSuggestionItems, type BlockNoteEditor } from "@blocknote/core";
|
||||
import { filterSuggestionItems, type Block, type BlockNoteEditor } from "@blocknote/core";
|
||||
import { useRouter } from "next/navigation";
|
||||
import {
|
||||
FileImage,
|
||||
@@ -171,6 +171,34 @@ export const CustomSlashMenu = ({ editor, currentDocumentId }: Props) => {
|
||||
aliases: ["mindmap", "swdt", "导图"],
|
||||
icon: <Spline className="h-4 w-4 text-[#2563eb]" />,
|
||||
onItemClick: () => {
|
||||
// mindmap.json / /api/mindmap/:docId 是“按页面(documentId)维度”存储的,
|
||||
// 同一页面插入多个导图会共享同一份数据,用户会感知为“重复/镜像”。
|
||||
// 这里先限制一页只允许一个导图块,避免产生歧义。
|
||||
const blocks = editor.topLevelBlocks as Block<CustomBlockSchema>[];
|
||||
let existingMindmapId: string | null = null;
|
||||
const walk = (target: Block<CustomBlockSchema>[]) => {
|
||||
target.forEach((b) => {
|
||||
if (existingMindmapId) return;
|
||||
if (b.type === "mindmap") {
|
||||
existingMindmapId = b.id;
|
||||
return;
|
||||
}
|
||||
if (Array.isArray(b.children) && b.children.length > 0) {
|
||||
walk(b.children as Block<CustomBlockSchema>[]);
|
||||
}
|
||||
});
|
||||
};
|
||||
walk(blocks);
|
||||
if (existingMindmapId) {
|
||||
try {
|
||||
const el = document.querySelector<HTMLElement>(`[data-id="${existingMindmapId}"]`);
|
||||
el?.scrollIntoView?.({ behavior: "smooth", block: "center" });
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
window.alert("当前页面已存在思维导图,暂不支持插入多个。");
|
||||
return;
|
||||
}
|
||||
editor.insertBlocks(
|
||||
[
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user