InsertSiblingNode

This commit is contained in:
KuroSago 2025-05-06 18:14:11 +08:00
parent 5dbe82bd29
commit 9f48000e83
8 changed files with 85 additions and 3 deletions

View File

@ -18,7 +18,8 @@
"simple-mind-map-plugin-themes": "^1.0.0",
"@toast-ui/editor": "^3.1.5",
"axios": "^1.7.9",
"codemirror": "^5.65.16"
"codemirror": "^5.65.16",
"uuid": "^11.1.0"
},
"main": "src/index.ts",
"module": "src/index.ts",

View File

@ -1,6 +1,7 @@
<template>
<div class="absolute w-full border flex flex-row gap-[24px]">
<InsertChildNode/>
<InsertSiblingNode/>
<ImportBtn/>
<ExportBtn/>
</div>
@ -10,4 +11,5 @@
import InsertChildNode from "./ToolBar/InsertChildNode.vue";
import ImportBtn from "./ToolBar/ImportBtn.vue";
import ExportBtn from "./ToolBar/ExportBtn.vue";
import InsertSiblingNode from "./ToolBar/InsertSiblingNode.vue";
</script>

View File

@ -10,6 +10,7 @@
<script lang="ts" setup>
import { useMindMapStore } from "../../store/index";
import { v4 as uuidv4 } from "uuid";
const { insertChildNode } = useMindMapStore();
@ -17,7 +18,7 @@ async function addNewChildNode() {
insertChildNode(
async () => {
return {
uid: "newChildNode",
uid: uuidv4(),
text: "新节点22222",
};
}

View File

@ -0,0 +1,28 @@
<!-- 插入姐妹节点 -->
<template>
<div
@click="addNewSiblingNode"
class="w-[80px] h-[80px] flex justify-center items-center border"
>
姐妹节点
</div>
</template>
<script lang="ts" setup>
import { useMindMapStore } from "../../store/index";
import { v4 as uuidv4 } from "uuid";
const { insertSiblingNode } = useMindMapStore();
async function addNewSiblingNode() {
insertSiblingNode(
async () => {
return {
uid: uuidv4(),
text: "新节点22222",
};
}
);
}
</script>

View File

@ -1,4 +1,5 @@
import { useMindMapStore } from "../../store/index";
import { v4 as uuidv4 } from "uuid";
/**
*
@ -8,7 +9,7 @@ import { useMindMapStore } from "../../store/index";
*/
export async function insertChildNode(
beforeInsertCallback: () => Promise<({ uid: number | string, text: string } | boolean)>,
nodeOptions: Record<string, any> = { uid: 313123123, text: "新节点" }
nodeOptions: Record<string, any> = { uid: uuidv4(), text: " - " }
) {
const { getMindMapInstance } = useMindMapStore();

View File

@ -0,0 +1,38 @@
import { useMindMapStore } from "../../store/index";
import { v4 as uuidv4 } from "uuid";
// 插入同级节点
/**
*
* @param beforeInsertCallback
* @param nodeOptions
* @returns Promise
*/
export async function insertSiblingNode(
beforeInsertCallback: () => Promise<({ uid: number | string, text: string } | boolean)>,
nodeOptions: Record<string, any> = { uid: uuidv4(), text: " - " }
) {
const { getMindMapInstance } = useMindMapStore();
const _nodeOptions = {
...nodeOptions,
}
try {
// 如果提供了回调函数,先执行回调
const result = await beforeInsertCallback();
if (!result) return; // 如果直接 false 则不再执行插入操作
if (result) {
Object.assign(_nodeOptions, result);
}
// 执行插入同级节点命令
return getMindMapInstance()?.execCommand("INSERT_NODE", false, [], _nodeOptions);
} catch (error) {
console.error("插入同级节点失败:", error);
throw error;
}
}

View File

@ -4,6 +4,7 @@ import { importFile } from "../helpers/import";
import { exportFile } from "../helpers/export";
import { usePlugins } from "../helpers/usePlugin";
import { insertChildNode } from "../helpers/insertChildNode";
import { insertSiblingNode } from "../helpers/insertSiblingNode";
import MindMap from "simple-mind-map";
@ -47,6 +48,7 @@ export const useMindMapStore = defineStore(
importFile,
exportFile,
insertChildNode,
insertSiblingNode,
// func
initMindMap,

9
web3/pnpm-lock.yaml generated
View File

@ -100,6 +100,9 @@ importers:
simple-mind-map-plugin-themes:
specifier: ^1.0.0
version: 1.0.1
uuid:
specifier: ^11.1.0
version: 11.1.0
vue:
specifier: ^3.3.4
version: 3.5.13(typescript@5.8.3)
@ -1884,6 +1887,10 @@ packages:
util-deprecate@1.0.2:
resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==}
uuid@11.1.0:
resolution: {integrity: sha512-0/A9rDy9P7cJ+8w1c9WD9V//9Wj15Ce2MPz8Ri6032usz+NfePxx5AcN3bN+r6ZL6jEo066/yNYB3tn4pQEx+A==}
hasBin: true
v8-compile-cache-lib@3.0.1:
resolution: {integrity: sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==}
@ -3738,6 +3745,8 @@ snapshots:
util-deprecate@1.0.2: {}
uuid@11.1.0: {}
v8-compile-cache-lib@3.0.1: {}
vite@4.5.13(@types/node@22.15.3)(sass@1.87.0):