mirror of
https://gitee.com/ByteDance/flowgram.ai.git
synced 2025-07-07 17:43:29 +08:00
fix: node.toJSON use document.toNodeJSON (#418)
This commit is contained in:
parent
bf69e6cb89
commit
080d28ba1a
@ -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.toNodeJSON(this);
|
||||||
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!;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get isVertical(): boolean {
|
get isVertical(): boolean {
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user