InsertSiblingNode
This commit is contained in:
parent
5dbe82bd29
commit
9f48000e83
@ -18,7 +18,8 @@
|
|||||||
"simple-mind-map-plugin-themes": "^1.0.0",
|
"simple-mind-map-plugin-themes": "^1.0.0",
|
||||||
"@toast-ui/editor": "^3.1.5",
|
"@toast-ui/editor": "^3.1.5",
|
||||||
"axios": "^1.7.9",
|
"axios": "^1.7.9",
|
||||||
"codemirror": "^5.65.16"
|
"codemirror": "^5.65.16",
|
||||||
|
"uuid": "^11.1.0"
|
||||||
},
|
},
|
||||||
"main": "src/index.ts",
|
"main": "src/index.ts",
|
||||||
"module": "src/index.ts",
|
"module": "src/index.ts",
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="absolute w-full border flex flex-row gap-[24px]">
|
<div class="absolute w-full border flex flex-row gap-[24px]">
|
||||||
<InsertChildNode/>
|
<InsertChildNode/>
|
||||||
|
<InsertSiblingNode/>
|
||||||
<ImportBtn/>
|
<ImportBtn/>
|
||||||
<ExportBtn/>
|
<ExportBtn/>
|
||||||
</div>
|
</div>
|
||||||
@ -10,4 +11,5 @@
|
|||||||
import InsertChildNode from "./ToolBar/InsertChildNode.vue";
|
import InsertChildNode from "./ToolBar/InsertChildNode.vue";
|
||||||
import ImportBtn from "./ToolBar/ImportBtn.vue";
|
import ImportBtn from "./ToolBar/ImportBtn.vue";
|
||||||
import ExportBtn from "./ToolBar/ExportBtn.vue";
|
import ExportBtn from "./ToolBar/ExportBtn.vue";
|
||||||
|
import InsertSiblingNode from "./ToolBar/InsertSiblingNode.vue";
|
||||||
</script>
|
</script>
|
||||||
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { useMindMapStore } from "../../store/index";
|
import { useMindMapStore } from "../../store/index";
|
||||||
|
import { v4 as uuidv4 } from "uuid";
|
||||||
|
|
||||||
const { insertChildNode } = useMindMapStore();
|
const { insertChildNode } = useMindMapStore();
|
||||||
|
|
||||||
@ -17,7 +18,7 @@ async function addNewChildNode() {
|
|||||||
insertChildNode(
|
insertChildNode(
|
||||||
async () => {
|
async () => {
|
||||||
return {
|
return {
|
||||||
uid: "newChildNode",
|
uid: uuidv4(),
|
||||||
text: "新节点22222",
|
text: "新节点22222",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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>
|
||||||
|
|
||||||
@ -1,4 +1,5 @@
|
|||||||
import { useMindMapStore } from "../../store/index";
|
import { useMindMapStore } from "../../store/index";
|
||||||
|
import { v4 as uuidv4 } from "uuid";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 追加子节点
|
* 追加子节点
|
||||||
@ -8,7 +9,7 @@ import { useMindMapStore } from "../../store/index";
|
|||||||
*/
|
*/
|
||||||
export async function insertChildNode(
|
export async function insertChildNode(
|
||||||
beforeInsertCallback: () => Promise<({ uid: number | string, text: string } | boolean)>,
|
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();
|
const { getMindMapInstance } = useMindMapStore();
|
||||||
|
|
||||||
|
|||||||
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@ -4,6 +4,7 @@ import { importFile } from "../helpers/import";
|
|||||||
import { exportFile } from "../helpers/export";
|
import { exportFile } from "../helpers/export";
|
||||||
import { usePlugins } from "../helpers/usePlugin";
|
import { usePlugins } from "../helpers/usePlugin";
|
||||||
import { insertChildNode } from "../helpers/insertChildNode";
|
import { insertChildNode } from "../helpers/insertChildNode";
|
||||||
|
import { insertSiblingNode } from "../helpers/insertSiblingNode";
|
||||||
|
|
||||||
import MindMap from "simple-mind-map";
|
import MindMap from "simple-mind-map";
|
||||||
|
|
||||||
@ -47,6 +48,7 @@ export const useMindMapStore = defineStore(
|
|||||||
importFile,
|
importFile,
|
||||||
exportFile,
|
exportFile,
|
||||||
insertChildNode,
|
insertChildNode,
|
||||||
|
insertSiblingNode,
|
||||||
|
|
||||||
// func
|
// func
|
||||||
initMindMap,
|
initMindMap,
|
||||||
|
|||||||
9
web3/pnpm-lock.yaml
generated
9
web3/pnpm-lock.yaml
generated
@ -100,6 +100,9 @@ importers:
|
|||||||
simple-mind-map-plugin-themes:
|
simple-mind-map-plugin-themes:
|
||||||
specifier: ^1.0.0
|
specifier: ^1.0.0
|
||||||
version: 1.0.1
|
version: 1.0.1
|
||||||
|
uuid:
|
||||||
|
specifier: ^11.1.0
|
||||||
|
version: 11.1.0
|
||||||
vue:
|
vue:
|
||||||
specifier: ^3.3.4
|
specifier: ^3.3.4
|
||||||
version: 3.5.13(typescript@5.8.3)
|
version: 3.5.13(typescript@5.8.3)
|
||||||
@ -1884,6 +1887,10 @@ packages:
|
|||||||
util-deprecate@1.0.2:
|
util-deprecate@1.0.2:
|
||||||
resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==}
|
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:
|
v8-compile-cache-lib@3.0.1:
|
||||||
resolution: {integrity: sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==}
|
resolution: {integrity: sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==}
|
||||||
|
|
||||||
@ -3738,6 +3745,8 @@ snapshots:
|
|||||||
|
|
||||||
util-deprecate@1.0.2: {}
|
util-deprecate@1.0.2: {}
|
||||||
|
|
||||||
|
uuid@11.1.0: {}
|
||||||
|
|
||||||
v8-compile-cache-lib@3.0.1: {}
|
v8-compile-cache-lib@3.0.1: {}
|
||||||
|
|
||||||
vite@4.5.13(@types/node@22.15.3)(sass@1.87.0):
|
vite@4.5.13(@types/node@22.15.3)(sass@1.87.0):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user