@flowgram.ai/free-layout-core 0.1.23 → 0.1.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/esm/index.js CHANGED
@@ -482,7 +482,7 @@ var _WorkflowNodeLinesData = class _WorkflowNodeLinesData extends EntityData2 {
482
482
  constructor(entity) {
483
483
  super(entity);
484
484
  this.entity = entity;
485
- this.toDispose.push(
485
+ this.entity.preDispose.push(
486
486
  Disposable.create(() => {
487
487
  this.inputLines.slice().forEach((line) => line.dispose());
488
488
  this.outputLines.slice().forEach((line) => line.dispose());
@@ -1701,10 +1701,12 @@ var WorkflowDocument = class extends FlowDocument {
1701
1701
  * @param json
1702
1702
  */
1703
1703
  fromJSON(json, fireRender = true) {
1704
- const { flattenJSON, nodeBlocks, nodeEdges } = this.flatJSON(json);
1705
- const nestedJSON = this.nestJSON(flattenJSON, nodeBlocks, nodeEdges);
1704
+ const workflowJSON = {
1705
+ nodes: json.nodes ?? [],
1706
+ edges: json.edges ?? []
1707
+ };
1706
1708
  this.entityManager.changeEntityLocked = true;
1707
- this.renderJSON(nestedJSON);
1709
+ this.renderJSON(workflowJSON);
1708
1710
  this.entityManager.changeEntityLocked = false;
1709
1711
  this.transformer.loading = false;
1710
1712
  if (fireRender) {
@@ -2042,112 +2044,17 @@ var WorkflowDocument = class extends FlowDocument {
2042
2044
  this.disposed = true;
2043
2045
  this._onReloadEmitter.dispose();
2044
2046
  }
2045
- getEdgeID(edge) {
2046
- return WorkflowLineEntity.portInfoToLineId({
2047
- from: edge.sourceNodeID,
2048
- to: edge.targetNodeID,
2049
- fromPort: edge.sourcePortID,
2050
- toPort: edge.targetPortID
2051
- });
2052
- }
2053
- /**
2054
- * 拍平树形json结构,将结构信息提取到map
2055
- */
2056
- flatJSON(json = { nodes: [], edges: [] }) {
2057
- const nodeBlocks = /* @__PURE__ */ new Map();
2058
- const nodeEdges = /* @__PURE__ */ new Map();
2059
- const rootNodes = json.nodes ?? [];
2060
- const rootEdges = json.edges ?? [];
2061
- const flattenNodeJSONs = [...rootNodes];
2062
- const flattenEdgeJSONs = [...rootEdges];
2063
- const rootBlockIDs = rootNodes.map((node) => node.id);
2064
- const rootEdgeIDs = rootEdges.map((edge) => this.getEdgeID(edge));
2065
- nodeBlocks.set(FlowNodeBaseType.ROOT, rootBlockIDs);
2066
- nodeEdges.set(FlowNodeBaseType.ROOT, rootEdgeIDs);
2067
- rootNodes.forEach((nodeJSON) => {
2068
- const { blocks, edges } = nodeJSON;
2069
- if (blocks) {
2070
- flattenNodeJSONs.push(...blocks);
2071
- const blockIDs = [];
2072
- blocks.forEach((block) => {
2073
- blockIDs.push(block.id);
2074
- });
2075
- nodeBlocks.set(nodeJSON.id, blockIDs);
2076
- delete nodeJSON.blocks;
2077
- }
2078
- if (edges) {
2079
- flattenEdgeJSONs.push(...edges);
2080
- const edgeIDs = [];
2081
- edges.forEach((edge) => {
2082
- const edgeID = this.getEdgeID(edge);
2083
- edgeIDs.push(edgeID);
2084
- });
2085
- nodeEdges.set(nodeJSON.id, edgeIDs);
2086
- delete nodeJSON.edges;
2087
- }
2088
- });
2089
- const flattenJSON = {
2090
- nodes: flattenNodeJSONs,
2091
- edges: flattenEdgeJSONs
2092
- };
2093
- return {
2094
- flattenJSON,
2095
- nodeBlocks,
2096
- nodeEdges
2097
- };
2098
- }
2099
- /**
2100
- * 对JSON进行分层
2101
- */
2102
- nestJSON(flattenJSON, nodeBlocks, nodeEdges) {
2103
- const nestJSON = {
2104
- nodes: [],
2105
- edges: []
2106
- };
2107
- const nodeMap = /* @__PURE__ */ new Map();
2108
- const edgeMap = /* @__PURE__ */ new Map();
2109
- const rootBlockSet = new Set(nodeBlocks.get(FlowNodeBaseType.ROOT) ?? []);
2110
- const rootEdgeSet = new Set(nodeEdges.get(FlowNodeBaseType.ROOT) ?? []);
2111
- flattenJSON.nodes.forEach((nodeJSON) => {
2112
- nodeMap.set(nodeJSON.id, nodeJSON);
2113
- });
2114
- flattenJSON.edges.forEach((edgeJSON) => {
2115
- const edgeID = this.getEdgeID(edgeJSON);
2116
- edgeMap.set(edgeID, edgeJSON);
2117
- });
2118
- flattenJSON.nodes.forEach((nodeJSON) => {
2119
- if (rootBlockSet.has(nodeJSON.id)) {
2120
- nestJSON.nodes.push(nodeJSON);
2121
- }
2122
- if (nodeBlocks.has(nodeJSON.id)) {
2123
- const blockIDs = nodeBlocks.get(nodeJSON.id);
2124
- const blockJSONs = blockIDs.map((blockID) => nodeMap.get(blockID)).filter(Boolean);
2125
- nodeJSON.blocks = blockJSONs;
2126
- }
2127
- if (nodeEdges.has(nodeJSON.id)) {
2128
- const edgeIDs = nodeEdges.get(nodeJSON.id);
2129
- const edgeJSONs = edgeIDs.map((edgeID) => edgeMap.get(edgeID)).filter(Boolean);
2130
- nodeJSON.edges = edgeJSONs;
2131
- }
2132
- });
2133
- flattenJSON.edges.forEach((edgeJSON) => {
2134
- const edgeID = this.getEdgeID(edgeJSON);
2135
- if (rootEdgeSet.has(edgeID)) {
2136
- nestJSON.edges.push(edgeJSON);
2137
- }
2138
- });
2139
- return nestJSON;
2140
- }
2141
2047
  /**
2142
2048
  * 逐层创建节点和线条
2143
2049
  */
2144
2050
  renderJSON(json, options) {
2145
2051
  const { parent = this.root, isClone = false } = options ?? {};
2146
2052
  const containerID = this.getNodeSubCanvas(parent)?.canvasNode.id ?? parent.id;
2147
- json.nodes.forEach((nodeJSON) => {
2148
- this.createWorkflowNode(nodeJSON, isClone, containerID);
2149
- }), // 创建线条
2150
- json.edges.forEach((edge) => this.createWorkflowLine(edge, containerID));
2053
+ const nodes = json.nodes.map(
2054
+ (nodeJSON) => this.createWorkflowNode(nodeJSON, isClone, containerID)
2055
+ );
2056
+ const edges = json.edges.map((edge) => this.createWorkflowLine(edge, containerID)).filter(Boolean);
2057
+ return { nodes, edges };
2151
2058
  }
2152
2059
  getNodeSubCanvas(node) {
2153
2060
  if (!node) return;
@@ -2287,7 +2194,7 @@ var WorkflowDragService = class {
2287
2194
  * 拖拽选中节点
2288
2195
  * @param triggerEvent
2289
2196
  */
2290
- startDragSelectedNodes(triggerEvent) {
2197
+ async startDragSelectedNodes(triggerEvent) {
2291
2198
  let { selectedNodes } = this.selectService;
2292
2199
  if (selectedNodes.length === 0 || this.playgroundConfig.readonly || this.playgroundConfig.disabled || this.isDragging) {
2293
2200
  return Promise.resolve(false);