Forráskód Böngészése

fix: node.toJSON use document.toNodeJSON (#418)

xiamidaxia 6 hónapja
szülő
commit
080d28ba1a

+ 1 - 31
packages/canvas-engine/document/src/entities/flow-node-entity.ts

@@ -337,37 +337,7 @@ export class FlowNodeEntity extends Entity<FlowNodeEntityConfig> {
    * @param newId
    * @param newId
    */
    */
   toJSON(): FlowNodeJSON {
   toJSON(): FlowNodeJSON {
-    if (this.document.options.toNodeJSON) {
-      return this.document.options.toNodeJSON(this);
-    }
-    const nodesMap: Record<string, FlowNodeJSON> = {};
-    let startNodeJSON: FlowNodeJSON;
-    this.document.traverse((node) => {
-      const isSystemNode = node.id.startsWith('$');
-      if (isSystemNode) return;
-      const nodeJSONData = this.getJSONData();
-      const nodeJSON: FlowNodeJSON = {
-        id: node.id,
-        type: node.flowNodeType,
-      };
-      if (nodeJSONData !== undefined) {
-        nodeJSON.data = nodeJSONData;
-      }
-      if (!startNodeJSON) startNodeJSON = nodeJSON;
-      let { parent } = node;
-      if (parent && parent.id.startsWith('$')) {
-        parent = parent.originParent;
-      }
-      const parentJSON = parent ? nodesMap[parent.id] : undefined;
-      if (parentJSON) {
-        if (!parentJSON.blocks) {
-          parentJSON.blocks = [];
-        }
-        parentJSON.blocks.push(nodeJSON);
-      }
-      nodesMap[node.id] = nodeJSON;
-    }, this);
-    return startNodeJSON!;
+    return this.document.toNodeJSON(this);
   }
   }
 
 
   get isVertical(): boolean {
   get isVertical(): boolean {

+ 34 - 0
packages/canvas-engine/document/src/flow-document.ts

@@ -593,6 +593,40 @@ export class FlowDocument<T = FlowDocumentJSON> implements Disposable {
     return result;
     return result;
   }
   }
 
 
+  toNodeJSON(node: FlowNodeEntity): FlowNodeJSON {
+    if (this.options.toNodeJSON) {
+      return this.options.toNodeJSON(node);
+    }
+    const nodesMap: Record<string, FlowNodeJSON> = {};
+    let startNodeJSON: FlowNodeJSON;
+    this.traverse((node) => {
+      const isSystemNode = node.id.startsWith('$');
+      if (isSystemNode) return;
+      const nodeJSONData = node.getJSONData();
+      const nodeJSON: FlowNodeJSON = {
+        id: node.id,
+        type: node.flowNodeType,
+      };
+      if (nodeJSONData !== undefined) {
+        nodeJSON.data = nodeJSONData;
+      }
+      if (!startNodeJSON) startNodeJSON = nodeJSON;
+      let { parent } = node;
+      if (parent && parent.id.startsWith('$')) {
+        parent = parent.originParent;
+      }
+      const parentJSON = parent ? nodesMap[parent.id] : undefined;
+      if (parentJSON) {
+        if (!parentJSON.blocks) {
+          parentJSON.blocks = [];
+        }
+        parentJSON.blocks.push(nodeJSON);
+      }
+      nodesMap[node.id] = nodeJSON;
+    }, node);
+    return startNodeJSON!;
+  }
+
   /**
   /**
    * 移动节点
    * 移动节点
    * @param param0
    * @param param0