@flowgram.ai/free-layout-core 0.2.22 → 0.2.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-BuRLWUuf.mjs';
6
- export { J as HoverPosition, 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, K as WorkfloEntityHoverable, s as WorkflowContentChangeEvent, r as WorkflowContentChangeType, Q as WorkflowDocumentOptionsDefault, M as WorkflowDocumentProvider, I as WorkflowEntityHoverable, 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-BuRLWUuf.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-BWrInTFK.mjs';
6
+ export { K as HoverPosition, 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, H as PORT_SIZE, o as WORKFLOW_LINE_ENTITY, M as WorkfloEntityHoverable, s as WorkflowContentChangeEvent, r as WorkflowContentChangeType, R as WorkflowDocumentOptionsDefault, Q as WorkflowDocumentProvider, J as WorkflowEntityHoverable, q as WorkflowJSON, E as WorkflowLineEntityOpts, F as WorkflowLineInfo, D as WorkflowLinePortInfo, x as WorkflowLineRenderContributionFactory, G as WorkflowLineUIState, t as WorkflowNodeMeta, I as WorkflowPortEntityOpts, p as domReactToBounds, n as getPortEntityId, B as onDragLineEndParams } from './workflow-line-entity-BWrInTFK.mjs';
7
7
  import { W as WorkflowNodeEntity } from './workflow-sub-canvas-IQzlYvPD.mjs';
8
8
  export { a as WorkflowSubCanvas } from './workflow-sub-canvas-IQzlYvPD.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-BUokXoMi.js';
6
- export { J as HoverPosition, 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, K as WorkfloEntityHoverable, s as WorkflowContentChangeEvent, r as WorkflowContentChangeType, Q as WorkflowDocumentOptionsDefault, M as WorkflowDocumentProvider, I as WorkflowEntityHoverable, 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-BUokXoMi.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-BvKc5ehl.js';
6
+ export { K as HoverPosition, 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, H as PORT_SIZE, o as WORKFLOW_LINE_ENTITY, M as WorkfloEntityHoverable, s as WorkflowContentChangeEvent, r as WorkflowContentChangeType, R as WorkflowDocumentOptionsDefault, Q as WorkflowDocumentProvider, J as WorkflowEntityHoverable, q as WorkflowJSON, E as WorkflowLineEntityOpts, F as WorkflowLineInfo, D as WorkflowLinePortInfo, x as WorkflowLineRenderContributionFactory, G as WorkflowLineUIState, t as WorkflowNodeMeta, I as WorkflowPortEntityOpts, p as domReactToBounds, n as getPortEntityId, B as onDragLineEndParams } from './workflow-line-entity-BvKc5ehl.js';
7
7
  import { W as WorkflowNodeEntity } from './workflow-sub-canvas-IQzlYvPD.js';
8
8
  export { a as WorkflowSubCanvas } from './workflow-sub-canvas-IQzlYvPD.js';
9
9
  import * as _flowgram_ai_utils from '@flowgram.ai/utils';
package/dist/index.js CHANGED
@@ -229,7 +229,7 @@ var WorkflowPortEntity = class extends import_core4.Entity {
229
229
  this.hasError = anyLineHasError || isPortHasError;
230
230
  }
231
231
  isErrorPort() {
232
- return this.node.document.isErrorPort(this);
232
+ return this.node.document.isErrorPort(this, this.hasError);
233
233
  }
234
234
  get point() {
235
235
  const { targetElement } = this;
@@ -733,8 +733,15 @@ var POINT_RADIUS = 10;
733
733
  var _WorkflowLineEntity = class _WorkflowLineEntity extends import_core8.Entity {
734
734
  constructor(opts) {
735
735
  super(opts);
736
- this._processing = false;
737
- this._hasError = false;
736
+ this._uiState = {
737
+ hasError: false,
738
+ flowing: false,
739
+ disabled: false,
740
+ vertical: false,
741
+ hideArrow: false,
742
+ reverse: false,
743
+ highlightColor: ""
744
+ };
738
745
  this.stackIndex = 0;
739
746
  /**
740
747
  * 线条数据
@@ -763,6 +770,43 @@ var _WorkflowLineEntity = class _WorkflowLineEntity extends import_core8.Entity
763
770
  const { from, to, fromPort, toPort } = info;
764
771
  return `${from}_${fromPort || ""}-${to || ""}_${toPort || ""}`;
765
772
  }
773
+ /**
774
+ * 线条的 UI 状态
775
+ */
776
+ get uiState() {
777
+ return this._uiState;
778
+ }
779
+ /**
780
+ * 更新线条的 ui 状态
781
+ * @param newState
782
+ */
783
+ updateUIState(newState) {
784
+ let changed = false;
785
+ Object.keys(newState).forEach((key) => {
786
+ const value = newState[key];
787
+ if (this._uiState[key] !== value) {
788
+ this._uiState[key] = value;
789
+ changed = true;
790
+ }
791
+ });
792
+ if (changed) {
793
+ this.fireChange();
794
+ }
795
+ }
796
+ /**
797
+ * 线条的扩展数据
798
+ */
799
+ get lineData() {
800
+ return this._lineData;
801
+ }
802
+ /**
803
+ * 更新线条扩展数据
804
+ * @param data
805
+ */
806
+ set lineData(data) {
807
+ this._lineData = data;
808
+ this.fireChange();
809
+ }
766
810
  /**
767
811
  * 获取线条的前置节点
768
812
  */
@@ -784,29 +828,30 @@ var _WorkflowLineEntity = class _WorkflowLineEntity extends import_core8.Entity
784
828
  }
785
829
  /**
786
830
  * 获取是否 testrun processing
831
+ * @deprecated use `uiState.flowing` instead
787
832
  */
788
833
  get processing() {
789
- return this._processing;
834
+ return this._uiState.flowing;
790
835
  }
791
836
  /**
792
837
  * 设置 testrun processing 状态
838
+ * @deprecated use `uiState.flowing` instead
793
839
  */
794
840
  set processing(status) {
795
- if (this._processing !== status) {
796
- this._processing = status;
841
+ if (this._uiState.flowing !== status) {
842
+ this._uiState.flowing = status;
797
843
  this.fireChange();
798
844
  }
799
845
  }
800
846
  // 获取连线是否为错误态
801
847
  get hasError() {
802
- return this._hasError;
848
+ return this.uiState.hasError;
803
849
  }
804
850
  // 设置连线的错误态
805
851
  set hasError(hasError) {
806
- if (this._hasError !== hasError) {
807
- this._hasError = hasError;
808
- this.fireChange();
809
- }
852
+ this.updateUIState({
853
+ hasError
854
+ });
810
855
  if (this._node) {
811
856
  this._node.dataset.hasError = this.hasError ? "true" : "false";
812
857
  }
@@ -859,13 +904,12 @@ var _WorkflowLineEntity = class _WorkflowLineEntity extends import_core8.Entity
859
904
  return this.info.drawingTo;
860
905
  }
861
906
  get highlightColor() {
862
- return this.info.highlightColor || "";
907
+ return this.uiState.highlightColor || "";
863
908
  }
864
- set highlightColor(color) {
865
- if (this.info.highlightColor !== color) {
866
- this.info.highlightColor = color;
867
- this.fireChange();
868
- }
909
+ set highlightColor(highlightColor) {
910
+ this.updateUIState({
911
+ highlightColor
912
+ });
869
913
  }
870
914
  /**
871
915
  * 获取线条的边框位置大小
@@ -896,23 +940,23 @@ var _WorkflowLineEntity = class _WorkflowLineEntity extends import_core8.Entity
896
940
  }
897
941
  /** 是否反转箭头 */
898
942
  get reverse() {
899
- return this.linesManager.isReverseLine(this);
943
+ return this.linesManager.isReverseLine(this, this.uiState.reverse);
900
944
  }
901
945
  /** 是否隐藏箭头 */
902
946
  get hideArrow() {
903
- return this.linesManager.isHideArrowLine(this);
947
+ return this.linesManager.isHideArrowLine(this, this.uiState.hideArrow);
904
948
  }
905
949
  /** 是否流动 */
906
950
  get flowing() {
907
- return this.linesManager.isFlowingLine(this);
951
+ return this.linesManager.isFlowingLine(this, this.uiState.flowing);
908
952
  }
909
953
  /** 是否禁用 */
910
954
  get disabled() {
911
- return this.linesManager.isDisabledLine(this);
955
+ return this.linesManager.isDisabledLine(this, this.uiState.disabled);
912
956
  }
913
957
  /** 是否竖向 */
914
958
  get vertical() {
915
- return this.linesManager.isVerticalLine(this);
959
+ return this.linesManager.isVerticalLine(this, this.uiState.vertical);
916
960
  }
917
961
  /** 获取线条渲染器类型 */
918
962
  get renderType() {
@@ -947,7 +991,7 @@ var _WorkflowLineEntity = class _WorkflowLineEntity extends import_core8.Entity
947
991
  validateSelf() {
948
992
  const { fromPort, toPort } = this;
949
993
  if (fromPort) {
950
- this.hasError = this.linesManager.isErrorLine(fromPort, toPort);
994
+ this.hasError = this.linesManager.isErrorLine(fromPort, toPort, this.uiState.hasError);
951
995
  }
952
996
  }
953
997
  is(line) {
@@ -978,6 +1022,9 @@ var _WorkflowLineEntity = class _WorkflowLineEntity extends import_core8.Entity
978
1022
  sourcePortID: this.info.fromPort,
979
1023
  targetPortID: this.info.toPort
980
1024
  };
1025
+ if (this._lineData !== void 0) {
1026
+ json.data = this._lineData;
1027
+ }
981
1028
  if (!json.sourcePortID) {
982
1029
  delete json.sourcePortID;
983
1030
  }
@@ -1445,41 +1492,41 @@ var WorkflowLinesManager = class {
1445
1492
  get disposed() {
1446
1493
  return this.toDispose.disposed;
1447
1494
  }
1448
- isErrorLine(fromPort, toPort) {
1495
+ isErrorLine(fromPort, toPort, defaultValue) {
1449
1496
  if (this.options.isErrorLine) {
1450
1497
  return this.options.isErrorLine(fromPort, toPort, this);
1451
1498
  }
1452
- return false;
1499
+ return !!defaultValue;
1453
1500
  }
1454
- isReverseLine(line) {
1501
+ isReverseLine(line, defaultValue = false) {
1455
1502
  if (this.options.isReverseLine) {
1456
1503
  return this.options.isReverseLine(line);
1457
1504
  }
1458
- return false;
1505
+ return defaultValue;
1459
1506
  }
1460
- isHideArrowLine(line) {
1507
+ isHideArrowLine(line, defaultValue = false) {
1461
1508
  if (this.options.isHideArrowLine) {
1462
1509
  return this.options.isHideArrowLine(line);
1463
1510
  }
1464
- return false;
1511
+ return defaultValue;
1465
1512
  }
1466
- isFlowingLine(line) {
1513
+ isFlowingLine(line, defaultValue = false) {
1467
1514
  if (this.options.isFlowingLine) {
1468
1515
  return this.options.isFlowingLine(line);
1469
1516
  }
1470
- return false;
1517
+ return defaultValue;
1471
1518
  }
1472
- isDisabledLine(line) {
1519
+ isDisabledLine(line, defaultValue = false) {
1473
1520
  if (this.options.isDisabledLine) {
1474
1521
  return this.options.isDisabledLine(line);
1475
1522
  }
1476
- return false;
1523
+ return defaultValue;
1477
1524
  }
1478
- isVerticalLine(line) {
1525
+ isVerticalLine(line, defaultValue = false) {
1479
1526
  if (this.options.isVerticalLine) {
1480
1527
  return this.options.isVerticalLine(line);
1481
1528
  }
1482
- return false;
1529
+ return defaultValue;
1483
1530
  }
1484
1531
  setLineRenderType(line) {
1485
1532
  if (this.options.setLineRenderType) {
@@ -1549,7 +1596,8 @@ var WorkflowLinesManager = class {
1549
1596
  * @param pos
1550
1597
  */
1551
1598
  getPortFromMousePos(pos) {
1552
- const allPorts = this.entityManager.getEntities(WorkflowPortEntity).filter((port) => port.node.flowNodeType !== "root");
1599
+ const allNodes = this.getSortedNodes().reverse();
1600
+ const allPorts = allNodes.map((node) => node.getData(WorkflowNodePortsData).allPorts).flat();
1553
1601
  const targetPort = allPorts.find((port) => port.isHovered(pos.x, pos.y));
1554
1602
  if (targetPort) {
1555
1603
  const containNodes = this.getContainNodesFromMousePos(pos);
@@ -1584,9 +1632,12 @@ var WorkflowLinesManager = class {
1584
1632
  registerData(line) {
1585
1633
  line.addData(WorkflowLineRenderData);
1586
1634
  }
1635
+ getSortedNodes() {
1636
+ return this.document.getAllNodes().sort((a, b) => this.getNodeIndex(a) - this.getNodeIndex(b));
1637
+ }
1587
1638
  /** 获取鼠标坐标位置的所有节点(stackIndex 从小到大排序) */
1588
1639
  getContainNodesFromMousePos(pos) {
1589
- const allNodes = this.document.getAllNodes().sort((a, b) => this.getNodeIndex(a) - this.getNodeIndex(b));
1640
+ const allNodes = this.getSortedNodes();
1590
1641
  const zoom = this.entityManager.getEntity(import_core12.PlaygroundConfigEntity)?.config?.zoom || 1;
1591
1642
  const containNodes = allNodes.map((node) => {
1592
1643
  const { bounds } = node.getData(import_document5.FlowNodeTransformData);
@@ -2216,11 +2267,11 @@ var WorkflowDocument = class extends import_document7.FlowDocument {
2216
2267
  /**
2217
2268
  * 判断端口是否为错误态
2218
2269
  */
2219
- isErrorPort(port) {
2270
+ isErrorPort(port, defaultValue = false) {
2220
2271
  if (typeof this.options.isErrorPort === "function") {
2221
2272
  return this.options.isErrorPort(port);
2222
2273
  }
2223
- return false;
2274
+ return defaultValue;
2224
2275
  }
2225
2276
  /**
2226
2277
  * 导出数据
@@ -2913,13 +2964,8 @@ var WorkflowDragService = class {
2913
2964
  return true;
2914
2965
  }
2915
2966
  const { padding, bounds } = node.transform;
2916
- const contentRect = new import_utils16.Rectangle(
2917
- bounds.x + padding.left,
2918
- bounds.y,
2919
- bounds.width - padding.left - padding.right,
2920
- bounds.height
2921
- );
2922
- return !contentRect.contains(mousePos.x, mousePos.y);
2967
+ const contentRect = new import_utils16.Rectangle(bounds.x, bounds.y, padding.left * 2 / 3, bounds.height);
2968
+ return contentRect.contains(mousePos.x, mousePos.y);
2923
2969
  }
2924
2970
  /** 获取最近的 port */
2925
2971
  getNearestPort(node, mousePos) {