|
@@ -96,11 +96,7 @@ export const bindMindMapEvents = (
|
|
|
graph.on("node:mousemove", (args) => {
|
|
|
// 节点拖拽-处理影子节点吸附问题
|
|
|
if (currentShadowNode && setMindProjectInfo) {
|
|
|
- topicDragHander(
|
|
|
- graph,
|
|
|
- { x: args.x, y: args.y },
|
|
|
- args.node
|
|
|
- );
|
|
|
+ topicDragHander(graph, { x: args.x, y: args.y }, args.node);
|
|
|
}
|
|
|
});
|
|
|
|
|
@@ -113,7 +109,12 @@ export const bindMindMapEvents = (
|
|
|
}
|
|
|
|
|
|
// 成为自由节点
|
|
|
- if (currentShadowNode && !indicatorNode && args.node.data?.parentId) {
|
|
|
+ if (
|
|
|
+ currentShadowNode &&
|
|
|
+ !indicatorNode &&
|
|
|
+ args.node.data?.parentId &&
|
|
|
+ canBeFreeNode(args.x, args.y, args.node)
|
|
|
+ ) {
|
|
|
setMindProjectInfo &&
|
|
|
handleSwitchPosition(setMindProjectInfo, args.node.id, undefined, {
|
|
|
x: args.x,
|
|
@@ -143,11 +144,7 @@ export const bindMindMapEvents = (
|
|
|
graph.on("node:moving", (args) => {
|
|
|
if (!args.node.data?.parentId && setMindProjectInfo) {
|
|
|
setShadowMode(false, args.node, graph);
|
|
|
- topicDragHander(
|
|
|
- graph,
|
|
|
- { x: args.x, y: args.y },
|
|
|
- args.node
|
|
|
- );
|
|
|
+ topicDragHander(graph, { x: args.x, y: args.y }, args.node);
|
|
|
}
|
|
|
});
|
|
|
|
|
@@ -191,24 +188,28 @@ export const bindMindMapEvents = (
|
|
|
);
|
|
|
return;
|
|
|
}
|
|
|
- if(current?.links && current.links.length !== previous?.links?.length) {
|
|
|
+ if (current?.links && current.links.length !== previous?.links?.length) {
|
|
|
setMindProjectInfo &&
|
|
|
updateTopic(
|
|
|
args.cell.id,
|
|
|
{ links: current.links },
|
|
|
setMindProjectInfo
|
|
|
);
|
|
|
- }
|
|
|
+ }
|
|
|
// 本地缓存更新不会重新渲染
|
|
|
updateTopic(args.cell.id, current, (info) => {
|
|
|
localStorage.setItem("minMapProjectInfo", JSON.stringify(info));
|
|
|
});
|
|
|
}
|
|
|
- if(args.key === "position") {
|
|
|
- if(args.cell.isNode() && !args.cell.data.parentId) {
|
|
|
- updateTopic(args.cell.id, {...args.cell.data, x: current.x, y: current.y}, (info) => {
|
|
|
- localStorage.setItem("minMapProjectInfo", JSON.stringify(info));
|
|
|
- });
|
|
|
+ if (args.key === "position") {
|
|
|
+ if (args.cell.isNode() && !args.cell.data.parentId) {
|
|
|
+ updateTopic(
|
|
|
+ args.cell.id,
|
|
|
+ { ...args.cell.data, x: current.x, y: current.y },
|
|
|
+ (info) => {
|
|
|
+ localStorage.setItem("minMapProjectInfo", JSON.stringify(info));
|
|
|
+ }
|
|
|
+ );
|
|
|
}
|
|
|
}
|
|
|
if (args.key === "size") {
|
|
@@ -228,16 +229,16 @@ export const bindMindMapEvents = (
|
|
|
/**
|
|
|
* 连接线更改
|
|
|
*/
|
|
|
- graph.on("edge:change:*", args => {
|
|
|
- if(args.key === "vertices" || args.key === "labels") {
|
|
|
+ graph.on("edge:change:*", (args) => {
|
|
|
+ if (args.key === "vertices" || args.key === "labels") {
|
|
|
const link = args.edge.toJSON();
|
|
|
const source = args.edge.getSourceCell();
|
|
|
source?.setData({
|
|
|
links: source.data?.links.map((item: Edge.Properties) => {
|
|
|
- if(item.id === link.id) return link;
|
|
|
+ if (item.id === link.id) return link;
|
|
|
return item;
|
|
|
- })
|
|
|
- })
|
|
|
+ }),
|
|
|
+ });
|
|
|
}
|
|
|
});
|
|
|
|
|
@@ -245,16 +246,27 @@ export const bindMindMapEvents = (
|
|
|
* 连接线删除
|
|
|
*/
|
|
|
graph.on("edge:removed", (args) => {
|
|
|
- if(args.edge.data?.isLink) {
|
|
|
+ if (args.edge.data?.isLink) {
|
|
|
// @ts-ignore
|
|
|
const source = graph.getCellById(args.edge.source?.cell as string);
|
|
|
- source?.setData({
|
|
|
- links: source.data?.links?.filter((item: Edge.Properties) => item.id !== args.edge.id)
|
|
|
- }, {
|
|
|
- deep: false
|
|
|
- });
|
|
|
+ source?.setData(
|
|
|
+ {
|
|
|
+ links: source.data?.links?.filter(
|
|
|
+ (item: Edge.Properties) => item.id !== args.edge.id
|
|
|
+ ),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ deep: false,
|
|
|
+ }
|
|
|
+ );
|
|
|
}
|
|
|
- })
|
|
|
+ });
|
|
|
+};
|
|
|
+
|
|
|
+const canBeFreeNode = (x: number, y: number, node: Node): boolean => {
|
|
|
+ if (!moveStart) return false;
|
|
|
+
|
|
|
+ return Math.abs(x - moveStart.x) > 50 || Math.abs(y - moveStart.y) > 50;
|
|
|
};
|
|
|
|
|
|
/**
|
|
@@ -559,14 +571,14 @@ const handleSwitchPosition = (
|
|
|
y: position?.y,
|
|
|
type: TopicType.branch,
|
|
|
parentId: null,
|
|
|
- links: (source.links || []).map(item => {
|
|
|
+ links: (source.links || []).map((item) => {
|
|
|
// 修改sourceId
|
|
|
item.source = {
|
|
|
...item.source,
|
|
|
- id
|
|
|
+ id,
|
|
|
};
|
|
|
return item;
|
|
|
- })
|
|
|
+ }),
|
|
|
});
|
|
|
}
|
|
|
|