@flowgram.ai/free-layout-core 0.1.0-alpha.5 → 0.1.0-alpha.7

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-CF97dniV.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-CF97dniV.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-niuFXSbE.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-niuFXSbE.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
@@ -293,10 +293,17 @@ var WorkflowPortEntity = class extends import_core4.Entity {
293
293
  }
294
294
  /**
295
295
  * 当前点位上连接的线条
296
+ * @deprecated use `availableLines` instead
296
297
  */
297
298
  get lines() {
298
299
  return this.allLines.filter((line) => !line.isDrawing);
299
300
  }
301
+ /**
302
+ * 当前有效的线条,不包含正在画的线条和隐藏的线条(这个出现在线条重连会先把原来的线条隐藏)
303
+ */
304
+ get availableLines() {
305
+ return this.allLines.filter((line) => !line.isDrawing && !line.isHidden);
306
+ }
300
307
  /**
301
308
  * 当前点位上连接的线条(包含 isDrawing === true 的线条)
302
309
  */
@@ -521,7 +528,7 @@ var _WorkflowNodeLinesData = class _WorkflowNodeLinesData extends import_core6.E
521
528
  constructor(entity) {
522
529
  super(entity);
523
530
  this.entity = entity;
524
- this.toDispose.push(
531
+ this.entity.preDispose.push(
525
532
  import_utils6.Disposable.create(() => {
526
533
  this.inputLines.slice().forEach((line) => line.dispose());
527
534
  this.outputLines.slice().forEach((line) => line.dispose());
@@ -1748,10 +1755,12 @@ var WorkflowDocument = class extends import_document7.FlowDocument {
1748
1755
  * @param json
1749
1756
  */
1750
1757
  fromJSON(json, fireRender = true) {
1751
- const { flattenJSON, nodeBlocks, nodeEdges } = this.flatJSON(json);
1752
- const nestedJSON = this.nestJSON(flattenJSON, nodeBlocks, nodeEdges);
1758
+ const workflowJSON = {
1759
+ nodes: json.nodes ?? [],
1760
+ edges: json.edges ?? []
1761
+ };
1753
1762
  this.entityManager.changeEntityLocked = true;
1754
- this.renderJSON(nestedJSON);
1763
+ this.renderJSON(workflowJSON);
1755
1764
  this.entityManager.changeEntityLocked = false;
1756
1765
  this.transformer.loading = false;
1757
1766
  if (fireRender) {
@@ -2089,112 +2098,17 @@ var WorkflowDocument = class extends import_document7.FlowDocument {
2089
2098
  this.disposed = true;
2090
2099
  this._onReloadEmitter.dispose();
2091
2100
  }
2092
- getEdgeID(edge) {
2093
- return WorkflowLineEntity.portInfoToLineId({
2094
- from: edge.sourceNodeID,
2095
- to: edge.targetNodeID,
2096
- fromPort: edge.sourcePortID,
2097
- toPort: edge.targetPortID
2098
- });
2099
- }
2100
- /**
2101
- * 拍平树形json结构,将结构信息提取到map
2102
- */
2103
- flatJSON(json = { nodes: [], edges: [] }) {
2104
- const nodeBlocks = /* @__PURE__ */ new Map();
2105
- const nodeEdges = /* @__PURE__ */ new Map();
2106
- const rootNodes = json.nodes ?? [];
2107
- const rootEdges = json.edges ?? [];
2108
- const flattenNodeJSONs = [...rootNodes];
2109
- const flattenEdgeJSONs = [...rootEdges];
2110
- const rootBlockIDs = rootNodes.map((node) => node.id);
2111
- const rootEdgeIDs = rootEdges.map((edge) => this.getEdgeID(edge));
2112
- nodeBlocks.set(import_document7.FlowNodeBaseType.ROOT, rootBlockIDs);
2113
- nodeEdges.set(import_document7.FlowNodeBaseType.ROOT, rootEdgeIDs);
2114
- rootNodes.forEach((nodeJSON) => {
2115
- const { blocks, edges } = nodeJSON;
2116
- if (blocks) {
2117
- flattenNodeJSONs.push(...blocks);
2118
- const blockIDs = [];
2119
- blocks.forEach((block) => {
2120
- blockIDs.push(block.id);
2121
- });
2122
- nodeBlocks.set(nodeJSON.id, blockIDs);
2123
- delete nodeJSON.blocks;
2124
- }
2125
- if (edges) {
2126
- flattenEdgeJSONs.push(...edges);
2127
- const edgeIDs = [];
2128
- edges.forEach((edge) => {
2129
- const edgeID = this.getEdgeID(edge);
2130
- edgeIDs.push(edgeID);
2131
- });
2132
- nodeEdges.set(nodeJSON.id, edgeIDs);
2133
- delete nodeJSON.edges;
2134
- }
2135
- });
2136
- const flattenJSON = {
2137
- nodes: flattenNodeJSONs,
2138
- edges: flattenEdgeJSONs
2139
- };
2140
- return {
2141
- flattenJSON,
2142
- nodeBlocks,
2143
- nodeEdges
2144
- };
2145
- }
2146
- /**
2147
- * 对JSON进行分层
2148
- */
2149
- nestJSON(flattenJSON, nodeBlocks, nodeEdges) {
2150
- const nestJSON = {
2151
- nodes: [],
2152
- edges: []
2153
- };
2154
- const nodeMap = /* @__PURE__ */ new Map();
2155
- const edgeMap = /* @__PURE__ */ new Map();
2156
- const rootBlockSet = new Set(nodeBlocks.get(import_document7.FlowNodeBaseType.ROOT) ?? []);
2157
- const rootEdgeSet = new Set(nodeEdges.get(import_document7.FlowNodeBaseType.ROOT) ?? []);
2158
- flattenJSON.nodes.forEach((nodeJSON) => {
2159
- nodeMap.set(nodeJSON.id, nodeJSON);
2160
- });
2161
- flattenJSON.edges.forEach((edgeJSON) => {
2162
- const edgeID = this.getEdgeID(edgeJSON);
2163
- edgeMap.set(edgeID, edgeJSON);
2164
- });
2165
- flattenJSON.nodes.forEach((nodeJSON) => {
2166
- if (rootBlockSet.has(nodeJSON.id)) {
2167
- nestJSON.nodes.push(nodeJSON);
2168
- }
2169
- if (nodeBlocks.has(nodeJSON.id)) {
2170
- const blockIDs = nodeBlocks.get(nodeJSON.id);
2171
- const blockJSONs = blockIDs.map((blockID) => nodeMap.get(blockID)).filter(Boolean);
2172
- nodeJSON.blocks = blockJSONs;
2173
- }
2174
- if (nodeEdges.has(nodeJSON.id)) {
2175
- const edgeIDs = nodeEdges.get(nodeJSON.id);
2176
- const edgeJSONs = edgeIDs.map((edgeID) => edgeMap.get(edgeID)).filter(Boolean);
2177
- nodeJSON.edges = edgeJSONs;
2178
- }
2179
- });
2180
- flattenJSON.edges.forEach((edgeJSON) => {
2181
- const edgeID = this.getEdgeID(edgeJSON);
2182
- if (rootEdgeSet.has(edgeID)) {
2183
- nestJSON.edges.push(edgeJSON);
2184
- }
2185
- });
2186
- return nestJSON;
2187
- }
2188
2101
  /**
2189
2102
  * 逐层创建节点和线条
2190
2103
  */
2191
2104
  renderJSON(json, options) {
2192
2105
  const { parent = this.root, isClone = false } = options ?? {};
2193
2106
  const containerID = this.getNodeSubCanvas(parent)?.canvasNode.id ?? parent.id;
2194
- json.nodes.forEach((nodeJSON) => {
2195
- this.createWorkflowNode(nodeJSON, isClone, containerID);
2196
- }), // 创建线条
2197
- 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 };
2198
2112
  }
2199
2113
  getNodeSubCanvas(node) {
2200
2114
  if (!node) return;
@@ -2214,7 +2128,7 @@ var WorkflowDocument = class extends import_document7.FlowDocument {
2214
2128
  }
2215
2129
  toLineJSON(line) {
2216
2130
  const lineJSON = line.toJSON();
2217
- if (!line.to || !line.info.to || !line.toPort) {
2131
+ if (!line.from || !line.info.from || !line.fromPort || !line.to || !line.info.to || !line.toPort) {
2218
2132
  return;
2219
2133
  }
2220
2134
  const fromSubCanvas = this.getNodeSubCanvas(line.from);
@@ -2334,7 +2248,7 @@ var WorkflowDragService = class {
2334
2248
  * 拖拽选中节点
2335
2249
  * @param triggerEvent
2336
2250
  */
2337
- startDragSelectedNodes(triggerEvent) {
2251
+ async startDragSelectedNodes(triggerEvent) {
2338
2252
  let { selectedNodes } = this.selectService;
2339
2253
  if (selectedNodes.length === 0 || this.playgroundConfig.readonly || this.playgroundConfig.disabled || this.isDragging) {
2340
2254
  return Promise.resolve(false);
@@ -2344,7 +2258,6 @@ var WorkflowDragService = class {
2344
2258
  if (sameParent && sameParent.flowNodeType !== import_document9.FlowNodeBaseType.ROOT) {
2345
2259
  selectedNodes = [sameParent];
2346
2260
  }
2347
- const { altKey } = triggerEvent;
2348
2261
  let startPosition = this.getNodesPosition(selectedNodes);
2349
2262
  let startPositions = selectedNodes.map((node) => {
2350
2263
  const transform = node.getData(import_core15.TransformData);
@@ -2358,7 +2271,6 @@ var WorkflowDragService = class {
2358
2271
  type: "onDragStart",
2359
2272
  nodes: selectedNodes,
2360
2273
  startPositions,
2361
- altKey,
2362
2274
  dragEvent,
2363
2275
  triggerEvent,
2364
2276
  dragger
@@ -2367,25 +2279,6 @@ var WorkflowDragService = class {
2367
2279
  onDrag: (dragEvent) => {
2368
2280
  if (!dragSuccess && checkDragSuccess(Date.now() - startTime, dragEvent)) {
2369
2281
  dragSuccess = true;
2370
- if (altKey) {
2371
- const tryCopyNodes = selectedNodes;
2372
- if (tryCopyNodes.length > 0) {
2373
- this.selectService.clear();
2374
- this.commandService.executeCommand("PASTE_NODES" /* PASTE_NODES */, tryCopyNodes, true).then((newNodes) => {
2375
- if (newNodes && Array.isArray(newNodes) && newNodes.length > 0) {
2376
- selectedNodes = newNodes;
2377
- startPosition = this.getNodesPosition(tryCopyNodes);
2378
- startPositions = tryCopyNodes.filter((n) => !n.getNodeMeta().copyDisable).map((node) => {
2379
- const transform = node.getData(import_core15.TransformData);
2380
- return {
2381
- x: transform.position.x,
2382
- y: transform.position.y
2383
- };
2384
- });
2385
- }
2386
- });
2387
- }
2388
- }
2389
2282
  }
2390
2283
  const offset = this.getDragPosOffset({
2391
2284
  event: dragEvent,
@@ -2416,7 +2309,6 @@ var WorkflowDragService = class {
2416
2309
  nodes: selectedNodes,
2417
2310
  startPositions,
2418
2311
  positions,
2419
- altKey,
2420
2312
  dragEvent,
2421
2313
  triggerEvent,
2422
2314
  dragger
@@ -2428,7 +2320,6 @@ var WorkflowDragService = class {
2428
2320
  type: "onDragEnd",
2429
2321
  nodes: selectedNodes,
2430
2322
  startPositions,
2431
- altKey,
2432
2323
  dragEvent,
2433
2324
  triggerEvent,
2434
2325
  dragger
@@ -2511,10 +2402,7 @@ var WorkflowDragService = class {
2511
2402
  dragNodeType: type,
2512
2403
  dropNode
2513
2404
  });
2514
- if (!allowDrop) {
2515
- return this.clearDrop();
2516
- }
2517
- const dragNode = await this.dropCard(type, e, data, dropNode);
2405
+ const dragNode = allowDrop ? await this.dropCard(type, e, data, dropNode) : void 0;
2518
2406
  this.clearDrop();
2519
2407
  if (dragNode) {
2520
2408
  domNode.remove();
@@ -2763,7 +2651,10 @@ var WorkflowDragService = class {
2763
2651
  this.setLineColor(line, this.linesManager.lineColor.drawing);
2764
2652
  if (toNode && !this.isContainer(toNode)) {
2765
2653
  const portsData = toNode.getData(WorkflowNodePortsData);
2766
- toPort = portsData.inputPorts[0];
2654
+ const { inputPorts } = portsData;
2655
+ if (inputPorts.length === 1) {
2656
+ toPort = inputPorts[0];
2657
+ }
2767
2658
  const { hasError } = this.handleDragOnNode(toNode, fromPort, line, toPort, originLine);
2768
2659
  lineErrorReset = hasError;
2769
2660
  }