@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/index.d.mts CHANGED
@@ -2,8 +2,8 @@ import { PlaygroundConfigEntity, CommandService, PlaygroundDragEvent, EntityData
2
2
  export { bindConfigEntity, useConfigEntity, useEntities, useEntityDataFromContext, useEntityFromContext, useListenEvents, usePlayground, usePlaygroundContainer, usePlaygroundContext, usePlaygroundLatest, useRefresh, useService } from '@flowgram.ai/core';
3
3
  import { NodeFormProps } from '@flowgram.ai/node';
4
4
  import { FlowOperationBaseService, FlowNodeType, FlowOperationBaseServiceImpl, FlowNodeEntityOrId, FlowNodeEntity } from '@flowgram.ai/document';
5
- import { W as WorkflowHoverService, a as WorkflowDocument, b as WorkflowLinesManager, c as WorkflowSelectService, d as WorkflowDocumentOptions, L as LineEventProps, N as NodesDragEvent, e as WorkflowNodeJSON, f as WorkflowPortEntity, g as WorkflowLineEntity, O as OnDragLineEnd, h as WorkflowPorts, i as WorkflowPortType, j as WorkflowPort, k as LineRenderType, l as WorkflowLineRenderContribution, m as LinePosition } from './workflow-line-entity-BCAgoA18.mjs';
6
- export { C as LINE_HOVER_DISTANCE, v as LineColor, w as LineColors, u as LineType, z as NodesDragEndEvent, y as NodesDragStartEvent, A as NodesDraggingEvent, P as POINT_RADIUS, G as PORT_SIZE, o as WORKFLOW_LINE_ENTITY, I as WorkfloEntityHoverable, s as WorkflowContentChangeEvent, r as WorkflowContentChangeType, K as WorkflowDocumentOptionsDefault, J as WorkflowDocumentProvider, q as WorkflowJSON, E as WorkflowLineEntityOpts, F as WorkflowLineInfo, D as WorkflowLinePortInfo, x as WorkflowLineRenderContributionFactory, t as WorkflowNodeMeta, H as WorkflowPortEntityOpts, p as domReactToBounds, n as getPortEntityId, B as onDragLineEndParams } from './workflow-line-entity-BCAgoA18.mjs';
5
+ import { W as WorkflowHoverService, a as WorkflowDocument, b as WorkflowLinesManager, c as WorkflowSelectService, d as WorkflowDocumentOptions, L as LineEventProps, N as NodesDragEvent, e as WorkflowNodeJSON, f as WorkflowPortEntity, g as WorkflowLineEntity, O as OnDragLineEnd, h as WorkflowPorts, i as WorkflowPortType, j as WorkflowPort, k as LineRenderType, l as WorkflowLineRenderContribution, m as LinePosition } from './workflow-line-entity-DgCmDX1d.mjs';
6
+ export { C as LINE_HOVER_DISTANCE, v as LineColor, w as LineColors, u as LineType, z as NodesDragEndEvent, y as NodesDragStartEvent, A as NodesDraggingEvent, P as POINT_RADIUS, G as PORT_SIZE, o as WORKFLOW_LINE_ENTITY, I as WorkfloEntityHoverable, s as WorkflowContentChangeEvent, r as WorkflowContentChangeType, K as WorkflowDocumentOptionsDefault, J as WorkflowDocumentProvider, q as WorkflowJSON, E as WorkflowLineEntityOpts, F as WorkflowLineInfo, D as WorkflowLinePortInfo, x as WorkflowLineRenderContributionFactory, t as WorkflowNodeMeta, H as WorkflowPortEntityOpts, p as domReactToBounds, n as getPortEntityId, B as onDragLineEndParams } from './workflow-line-entity-DgCmDX1d.mjs';
7
7
  import { W as WorkflowNodeEntity } from './workflow-sub-canvas-DOVla1mw.mjs';
8
8
  export { a as WorkflowSubCanvas } from './workflow-sub-canvas-DOVla1mw.mjs';
9
9
  import * as _flowgram_ai_utils from '@flowgram.ai/utils';
package/dist/index.d.ts CHANGED
@@ -2,8 +2,8 @@ import { PlaygroundConfigEntity, CommandService, PlaygroundDragEvent, EntityData
2
2
  export { bindConfigEntity, useConfigEntity, useEntities, useEntityDataFromContext, useEntityFromContext, useListenEvents, usePlayground, usePlaygroundContainer, usePlaygroundContext, usePlaygroundLatest, useRefresh, useService } from '@flowgram.ai/core';
3
3
  import { NodeFormProps } from '@flowgram.ai/node';
4
4
  import { FlowOperationBaseService, FlowNodeType, FlowOperationBaseServiceImpl, FlowNodeEntityOrId, FlowNodeEntity } from '@flowgram.ai/document';
5
- import { W as WorkflowHoverService, a as WorkflowDocument, b as WorkflowLinesManager, c as WorkflowSelectService, d as WorkflowDocumentOptions, L as LineEventProps, N as NodesDragEvent, e as WorkflowNodeJSON, f as WorkflowPortEntity, g as WorkflowLineEntity, O as OnDragLineEnd, h as WorkflowPorts, i as WorkflowPortType, j as WorkflowPort, k as LineRenderType, l as WorkflowLineRenderContribution, m as LinePosition } from './workflow-line-entity-DIyrK9yz.js';
6
- export { C as LINE_HOVER_DISTANCE, v as LineColor, w as LineColors, u as LineType, z as NodesDragEndEvent, y as NodesDragStartEvent, A as NodesDraggingEvent, P as POINT_RADIUS, G as PORT_SIZE, o as WORKFLOW_LINE_ENTITY, I as WorkfloEntityHoverable, s as WorkflowContentChangeEvent, r as WorkflowContentChangeType, K as WorkflowDocumentOptionsDefault, J as WorkflowDocumentProvider, q as WorkflowJSON, E as WorkflowLineEntityOpts, F as WorkflowLineInfo, D as WorkflowLinePortInfo, x as WorkflowLineRenderContributionFactory, t as WorkflowNodeMeta, H as WorkflowPortEntityOpts, p as domReactToBounds, n as getPortEntityId, B as onDragLineEndParams } from './workflow-line-entity-DIyrK9yz.js';
5
+ import { W as WorkflowHoverService, a as WorkflowDocument, b as WorkflowLinesManager, c as WorkflowSelectService, d as WorkflowDocumentOptions, L as LineEventProps, N as NodesDragEvent, e as WorkflowNodeJSON, f as WorkflowPortEntity, g as WorkflowLineEntity, O as OnDragLineEnd, h as WorkflowPorts, i as WorkflowPortType, j as WorkflowPort, k as LineRenderType, l as WorkflowLineRenderContribution, m as LinePosition } from './workflow-line-entity-B8wC-OVt.js';
6
+ export { C as LINE_HOVER_DISTANCE, v as LineColor, w as LineColors, u as LineType, z as NodesDragEndEvent, y as NodesDragStartEvent, A as NodesDraggingEvent, P as POINT_RADIUS, G as PORT_SIZE, o as WORKFLOW_LINE_ENTITY, I as WorkfloEntityHoverable, s as WorkflowContentChangeEvent, r as WorkflowContentChangeType, K as WorkflowDocumentOptionsDefault, J as WorkflowDocumentProvider, q as WorkflowJSON, E as WorkflowLineEntityOpts, F as WorkflowLineInfo, D as WorkflowLinePortInfo, x as WorkflowLineRenderContributionFactory, t as WorkflowNodeMeta, H as WorkflowPortEntityOpts, p as domReactToBounds, n as getPortEntityId, B as onDragLineEndParams } from './workflow-line-entity-B8wC-OVt.js';
7
7
  import { W as WorkflowNodeEntity } from './workflow-sub-canvas-DOVla1mw.js';
8
8
  export { a as WorkflowSubCanvas } from './workflow-sub-canvas-DOVla1mw.js';
9
9
  import * as _flowgram_ai_utils from '@flowgram.ai/utils';
package/dist/index.js CHANGED
@@ -528,7 +528,7 @@ var _WorkflowNodeLinesData = class _WorkflowNodeLinesData extends import_core6.E
528
528
  constructor(entity) {
529
529
  super(entity);
530
530
  this.entity = entity;
531
- this.toDispose.push(
531
+ this.entity.preDispose.push(
532
532
  import_utils6.Disposable.create(() => {
533
533
  this.inputLines.slice().forEach((line) => line.dispose());
534
534
  this.outputLines.slice().forEach((line) => line.dispose());
@@ -1755,10 +1755,12 @@ var WorkflowDocument = class extends import_document7.FlowDocument {
1755
1755
  * @param json
1756
1756
  */
1757
1757
  fromJSON(json, fireRender = true) {
1758
- const { flattenJSON, nodeBlocks, nodeEdges } = this.flatJSON(json);
1759
- const nestedJSON = this.nestJSON(flattenJSON, nodeBlocks, nodeEdges);
1758
+ const workflowJSON = {
1759
+ nodes: json.nodes ?? [],
1760
+ edges: json.edges ?? []
1761
+ };
1760
1762
  this.entityManager.changeEntityLocked = true;
1761
- this.renderJSON(nestedJSON);
1763
+ this.renderJSON(workflowJSON);
1762
1764
  this.entityManager.changeEntityLocked = false;
1763
1765
  this.transformer.loading = false;
1764
1766
  if (fireRender) {
@@ -2096,112 +2098,17 @@ var WorkflowDocument = class extends import_document7.FlowDocument {
2096
2098
  this.disposed = true;
2097
2099
  this._onReloadEmitter.dispose();
2098
2100
  }
2099
- getEdgeID(edge) {
2100
- return WorkflowLineEntity.portInfoToLineId({
2101
- from: edge.sourceNodeID,
2102
- to: edge.targetNodeID,
2103
- fromPort: edge.sourcePortID,
2104
- toPort: edge.targetPortID
2105
- });
2106
- }
2107
- /**
2108
- * 拍平树形json结构,将结构信息提取到map
2109
- */
2110
- flatJSON(json = { nodes: [], edges: [] }) {
2111
- const nodeBlocks = /* @__PURE__ */ new Map();
2112
- const nodeEdges = /* @__PURE__ */ new Map();
2113
- const rootNodes = json.nodes ?? [];
2114
- const rootEdges = json.edges ?? [];
2115
- const flattenNodeJSONs = [...rootNodes];
2116
- const flattenEdgeJSONs = [...rootEdges];
2117
- const rootBlockIDs = rootNodes.map((node) => node.id);
2118
- const rootEdgeIDs = rootEdges.map((edge) => this.getEdgeID(edge));
2119
- nodeBlocks.set(import_document7.FlowNodeBaseType.ROOT, rootBlockIDs);
2120
- nodeEdges.set(import_document7.FlowNodeBaseType.ROOT, rootEdgeIDs);
2121
- rootNodes.forEach((nodeJSON) => {
2122
- const { blocks, edges } = nodeJSON;
2123
- if (blocks) {
2124
- flattenNodeJSONs.push(...blocks);
2125
- const blockIDs = [];
2126
- blocks.forEach((block) => {
2127
- blockIDs.push(block.id);
2128
- });
2129
- nodeBlocks.set(nodeJSON.id, blockIDs);
2130
- delete nodeJSON.blocks;
2131
- }
2132
- if (edges) {
2133
- flattenEdgeJSONs.push(...edges);
2134
- const edgeIDs = [];
2135
- edges.forEach((edge) => {
2136
- const edgeID = this.getEdgeID(edge);
2137
- edgeIDs.push(edgeID);
2138
- });
2139
- nodeEdges.set(nodeJSON.id, edgeIDs);
2140
- delete nodeJSON.edges;
2141
- }
2142
- });
2143
- const flattenJSON = {
2144
- nodes: flattenNodeJSONs,
2145
- edges: flattenEdgeJSONs
2146
- };
2147
- return {
2148
- flattenJSON,
2149
- nodeBlocks,
2150
- nodeEdges
2151
- };
2152
- }
2153
- /**
2154
- * 对JSON进行分层
2155
- */
2156
- nestJSON(flattenJSON, nodeBlocks, nodeEdges) {
2157
- const nestJSON = {
2158
- nodes: [],
2159
- edges: []
2160
- };
2161
- const nodeMap = /* @__PURE__ */ new Map();
2162
- const edgeMap = /* @__PURE__ */ new Map();
2163
- const rootBlockSet = new Set(nodeBlocks.get(import_document7.FlowNodeBaseType.ROOT) ?? []);
2164
- const rootEdgeSet = new Set(nodeEdges.get(import_document7.FlowNodeBaseType.ROOT) ?? []);
2165
- flattenJSON.nodes.forEach((nodeJSON) => {
2166
- nodeMap.set(nodeJSON.id, nodeJSON);
2167
- });
2168
- flattenJSON.edges.forEach((edgeJSON) => {
2169
- const edgeID = this.getEdgeID(edgeJSON);
2170
- edgeMap.set(edgeID, edgeJSON);
2171
- });
2172
- flattenJSON.nodes.forEach((nodeJSON) => {
2173
- if (rootBlockSet.has(nodeJSON.id)) {
2174
- nestJSON.nodes.push(nodeJSON);
2175
- }
2176
- if (nodeBlocks.has(nodeJSON.id)) {
2177
- const blockIDs = nodeBlocks.get(nodeJSON.id);
2178
- const blockJSONs = blockIDs.map((blockID) => nodeMap.get(blockID)).filter(Boolean);
2179
- nodeJSON.blocks = blockJSONs;
2180
- }
2181
- if (nodeEdges.has(nodeJSON.id)) {
2182
- const edgeIDs = nodeEdges.get(nodeJSON.id);
2183
- const edgeJSONs = edgeIDs.map((edgeID) => edgeMap.get(edgeID)).filter(Boolean);
2184
- nodeJSON.edges = edgeJSONs;
2185
- }
2186
- });
2187
- flattenJSON.edges.forEach((edgeJSON) => {
2188
- const edgeID = this.getEdgeID(edgeJSON);
2189
- if (rootEdgeSet.has(edgeID)) {
2190
- nestJSON.edges.push(edgeJSON);
2191
- }
2192
- });
2193
- return nestJSON;
2194
- }
2195
2101
  /**
2196
2102
  * 逐层创建节点和线条
2197
2103
  */
2198
2104
  renderJSON(json, options) {
2199
2105
  const { parent = this.root, isClone = false } = options ?? {};
2200
2106
  const containerID = this.getNodeSubCanvas(parent)?.canvasNode.id ?? parent.id;
2201
- json.nodes.forEach((nodeJSON) => {
2202
- this.createWorkflowNode(nodeJSON, isClone, containerID);
2203
- }), // 创建线条
2204
- json.edges.forEach((edge) => this.createWorkflowLine(edge, containerID));
2107
+ const nodes = json.nodes.map(
2108
+ (nodeJSON) => this.createWorkflowNode(nodeJSON, isClone, containerID)
2109
+ );
2110
+ const edges = json.edges.map((edge) => this.createWorkflowLine(edge, containerID)).filter(Boolean);
2111
+ return { nodes, edges };
2205
2112
  }
2206
2113
  getNodeSubCanvas(node) {
2207
2114
  if (!node) return;
@@ -2341,7 +2248,7 @@ var WorkflowDragService = class {
2341
2248
  * 拖拽选中节点
2342
2249
  * @param triggerEvent
2343
2250
  */
2344
- startDragSelectedNodes(triggerEvent) {
2251
+ async startDragSelectedNodes(triggerEvent) {
2345
2252
  let { selectedNodes } = this.selectService;
2346
2253
  if (selectedNodes.length === 0 || this.playgroundConfig.readonly || this.playgroundConfig.disabled || this.isDragging) {
2347
2254
  return Promise.resolve(false);
@@ -2351,7 +2258,6 @@ var WorkflowDragService = class {
2351
2258
  if (sameParent && sameParent.flowNodeType !== import_document9.FlowNodeBaseType.ROOT) {
2352
2259
  selectedNodes = [sameParent];
2353
2260
  }
2354
- const { altKey } = triggerEvent;
2355
2261
  let startPosition = this.getNodesPosition(selectedNodes);
2356
2262
  let startPositions = selectedNodes.map((node) => {
2357
2263
  const transform = node.getData(import_core15.TransformData);
@@ -2365,7 +2271,6 @@ var WorkflowDragService = class {
2365
2271
  type: "onDragStart",
2366
2272
  nodes: selectedNodes,
2367
2273
  startPositions,
2368
- altKey,
2369
2274
  dragEvent,
2370
2275
  triggerEvent,
2371
2276
  dragger
@@ -2374,25 +2279,6 @@ var WorkflowDragService = class {
2374
2279
  onDrag: (dragEvent) => {
2375
2280
  if (!dragSuccess && checkDragSuccess(Date.now() - startTime, dragEvent)) {
2376
2281
  dragSuccess = true;
2377
- if (altKey) {
2378
- const tryCopyNodes = selectedNodes;
2379
- if (tryCopyNodes.length > 0) {
2380
- this.selectService.clear();
2381
- this.commandService.executeCommand("PASTE_NODES" /* PASTE_NODES */, tryCopyNodes, true).then((newNodes) => {
2382
- if (newNodes && Array.isArray(newNodes) && newNodes.length > 0) {
2383
- selectedNodes = newNodes;
2384
- startPosition = this.getNodesPosition(tryCopyNodes);
2385
- startPositions = tryCopyNodes.filter((n) => !n.getNodeMeta().copyDisable).map((node) => {
2386
- const transform = node.getData(import_core15.TransformData);
2387
- return {
2388
- x: transform.position.x,
2389
- y: transform.position.y
2390
- };
2391
- });
2392
- }
2393
- });
2394
- }
2395
- }
2396
2282
  }
2397
2283
  const offset = this.getDragPosOffset({
2398
2284
  event: dragEvent,
@@ -2423,7 +2309,6 @@ var WorkflowDragService = class {
2423
2309
  nodes: selectedNodes,
2424
2310
  startPositions,
2425
2311
  positions,
2426
- altKey,
2427
2312
  dragEvent,
2428
2313
  triggerEvent,
2429
2314
  dragger
@@ -2435,7 +2320,6 @@ var WorkflowDragService = class {
2435
2320
  type: "onDragEnd",
2436
2321
  nodes: selectedNodes,
2437
2322
  startPositions,
2438
- altKey,
2439
2323
  dragEvent,
2440
2324
  triggerEvent,
2441
2325
  dragger