@flowgram.ai/free-layout-core 0.1.22 → 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);
@@ -2297,7 +2204,6 @@ var WorkflowDragService = class {
2297
2204
  if (sameParent && sameParent.flowNodeType !== FlowNodeBaseType2.ROOT) {
2298
2205
  selectedNodes = [sameParent];
2299
2206
  }
2300
- const { altKey } = triggerEvent;
2301
2207
  let startPosition = this.getNodesPosition(selectedNodes);
2302
2208
  let startPositions = selectedNodes.map((node) => {
2303
2209
  const transform = node.getData(TransformData9);
@@ -2311,7 +2217,6 @@ var WorkflowDragService = class {
2311
2217
  type: "onDragStart",
2312
2218
  nodes: selectedNodes,
2313
2219
  startPositions,
2314
- altKey,
2315
2220
  dragEvent,
2316
2221
  triggerEvent,
2317
2222
  dragger
@@ -2320,25 +2225,6 @@ var WorkflowDragService = class {
2320
2225
  onDrag: (dragEvent) => {
2321
2226
  if (!dragSuccess && checkDragSuccess(Date.now() - startTime, dragEvent)) {
2322
2227
  dragSuccess = true;
2323
- if (altKey) {
2324
- const tryCopyNodes = selectedNodes;
2325
- if (tryCopyNodes.length > 0) {
2326
- this.selectService.clear();
2327
- this.commandService.executeCommand("PASTE_NODES" /* PASTE_NODES */, tryCopyNodes, true).then((newNodes) => {
2328
- if (newNodes && Array.isArray(newNodes) && newNodes.length > 0) {
2329
- selectedNodes = newNodes;
2330
- startPosition = this.getNodesPosition(tryCopyNodes);
2331
- startPositions = tryCopyNodes.filter((n) => !n.getNodeMeta().copyDisable).map((node) => {
2332
- const transform = node.getData(TransformData9);
2333
- return {
2334
- x: transform.position.x,
2335
- y: transform.position.y
2336
- };
2337
- });
2338
- }
2339
- });
2340
- }
2341
- }
2342
2228
  }
2343
2229
  const offset = this.getDragPosOffset({
2344
2230
  event: dragEvent,
@@ -2369,7 +2255,6 @@ var WorkflowDragService = class {
2369
2255
  nodes: selectedNodes,
2370
2256
  startPositions,
2371
2257
  positions,
2372
- altKey,
2373
2258
  dragEvent,
2374
2259
  triggerEvent,
2375
2260
  dragger
@@ -2381,7 +2266,6 @@ var WorkflowDragService = class {
2381
2266
  type: "onDragEnd",
2382
2267
  nodes: selectedNodes,
2383
2268
  startPositions,
2384
- altKey,
2385
2269
  dragEvent,
2386
2270
  triggerEvent,
2387
2271
  dragger