@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/esm/index.js CHANGED
@@ -188,7 +188,7 @@ var WorkflowPortEntity = class extends Entity {
188
188
  this.hasError = anyLineHasError || isPortHasError;
189
189
  }
190
190
  isErrorPort() {
191
- return this.node.document.isErrorPort(this);
191
+ return this.node.document.isErrorPort(this, this.hasError);
192
192
  }
193
193
  get point() {
194
194
  const { targetElement } = this;
@@ -692,8 +692,15 @@ var POINT_RADIUS = 10;
692
692
  var _WorkflowLineEntity = class _WorkflowLineEntity extends Entity2 {
693
693
  constructor(opts) {
694
694
  super(opts);
695
- this._processing = false;
696
- this._hasError = false;
695
+ this._uiState = {
696
+ hasError: false,
697
+ flowing: false,
698
+ disabled: false,
699
+ vertical: false,
700
+ hideArrow: false,
701
+ reverse: false,
702
+ highlightColor: ""
703
+ };
697
704
  this.stackIndex = 0;
698
705
  /**
699
706
  * 线条数据
@@ -722,6 +729,43 @@ var _WorkflowLineEntity = class _WorkflowLineEntity extends Entity2 {
722
729
  const { from, to, fromPort, toPort } = info;
723
730
  return `${from}_${fromPort || ""}-${to || ""}_${toPort || ""}`;
724
731
  }
732
+ /**
733
+ * 线条的 UI 状态
734
+ */
735
+ get uiState() {
736
+ return this._uiState;
737
+ }
738
+ /**
739
+ * 更新线条的 ui 状态
740
+ * @param newState
741
+ */
742
+ updateUIState(newState) {
743
+ let changed = false;
744
+ Object.keys(newState).forEach((key) => {
745
+ const value = newState[key];
746
+ if (this._uiState[key] !== value) {
747
+ this._uiState[key] = value;
748
+ changed = true;
749
+ }
750
+ });
751
+ if (changed) {
752
+ this.fireChange();
753
+ }
754
+ }
755
+ /**
756
+ * 线条的扩展数据
757
+ */
758
+ get lineData() {
759
+ return this._lineData;
760
+ }
761
+ /**
762
+ * 更新线条扩展数据
763
+ * @param data
764
+ */
765
+ set lineData(data) {
766
+ this._lineData = data;
767
+ this.fireChange();
768
+ }
725
769
  /**
726
770
  * 获取线条的前置节点
727
771
  */
@@ -743,29 +787,30 @@ var _WorkflowLineEntity = class _WorkflowLineEntity extends Entity2 {
743
787
  }
744
788
  /**
745
789
  * 获取是否 testrun processing
790
+ * @deprecated use `uiState.flowing` instead
746
791
  */
747
792
  get processing() {
748
- return this._processing;
793
+ return this._uiState.flowing;
749
794
  }
750
795
  /**
751
796
  * 设置 testrun processing 状态
797
+ * @deprecated use `uiState.flowing` instead
752
798
  */
753
799
  set processing(status) {
754
- if (this._processing !== status) {
755
- this._processing = status;
800
+ if (this._uiState.flowing !== status) {
801
+ this._uiState.flowing = status;
756
802
  this.fireChange();
757
803
  }
758
804
  }
759
805
  // 获取连线是否为错误态
760
806
  get hasError() {
761
- return this._hasError;
807
+ return this.uiState.hasError;
762
808
  }
763
809
  // 设置连线的错误态
764
810
  set hasError(hasError) {
765
- if (this._hasError !== hasError) {
766
- this._hasError = hasError;
767
- this.fireChange();
768
- }
811
+ this.updateUIState({
812
+ hasError
813
+ });
769
814
  if (this._node) {
770
815
  this._node.dataset.hasError = this.hasError ? "true" : "false";
771
816
  }
@@ -818,13 +863,12 @@ var _WorkflowLineEntity = class _WorkflowLineEntity extends Entity2 {
818
863
  return this.info.drawingTo;
819
864
  }
820
865
  get highlightColor() {
821
- return this.info.highlightColor || "";
866
+ return this.uiState.highlightColor || "";
822
867
  }
823
- set highlightColor(color) {
824
- if (this.info.highlightColor !== color) {
825
- this.info.highlightColor = color;
826
- this.fireChange();
827
- }
868
+ set highlightColor(highlightColor) {
869
+ this.updateUIState({
870
+ highlightColor
871
+ });
828
872
  }
829
873
  /**
830
874
  * 获取线条的边框位置大小
@@ -855,23 +899,23 @@ var _WorkflowLineEntity = class _WorkflowLineEntity extends Entity2 {
855
899
  }
856
900
  /** 是否反转箭头 */
857
901
  get reverse() {
858
- return this.linesManager.isReverseLine(this);
902
+ return this.linesManager.isReverseLine(this, this.uiState.reverse);
859
903
  }
860
904
  /** 是否隐藏箭头 */
861
905
  get hideArrow() {
862
- return this.linesManager.isHideArrowLine(this);
906
+ return this.linesManager.isHideArrowLine(this, this.uiState.hideArrow);
863
907
  }
864
908
  /** 是否流动 */
865
909
  get flowing() {
866
- return this.linesManager.isFlowingLine(this);
910
+ return this.linesManager.isFlowingLine(this, this.uiState.flowing);
867
911
  }
868
912
  /** 是否禁用 */
869
913
  get disabled() {
870
- return this.linesManager.isDisabledLine(this);
914
+ return this.linesManager.isDisabledLine(this, this.uiState.disabled);
871
915
  }
872
916
  /** 是否竖向 */
873
917
  get vertical() {
874
- return this.linesManager.isVerticalLine(this);
918
+ return this.linesManager.isVerticalLine(this, this.uiState.vertical);
875
919
  }
876
920
  /** 获取线条渲染器类型 */
877
921
  get renderType() {
@@ -906,7 +950,7 @@ var _WorkflowLineEntity = class _WorkflowLineEntity extends Entity2 {
906
950
  validateSelf() {
907
951
  const { fromPort, toPort } = this;
908
952
  if (fromPort) {
909
- this.hasError = this.linesManager.isErrorLine(fromPort, toPort);
953
+ this.hasError = this.linesManager.isErrorLine(fromPort, toPort, this.uiState.hasError);
910
954
  }
911
955
  }
912
956
  is(line) {
@@ -937,6 +981,9 @@ var _WorkflowLineEntity = class _WorkflowLineEntity extends Entity2 {
937
981
  sourcePortID: this.info.fromPort,
938
982
  targetPortID: this.info.toPort
939
983
  };
984
+ if (this._lineData !== void 0) {
985
+ json.data = this._lineData;
986
+ }
940
987
  if (!json.sourcePortID) {
941
988
  delete json.sourcePortID;
942
989
  }
@@ -1383,41 +1430,41 @@ var WorkflowLinesManager = class {
1383
1430
  get disposed() {
1384
1431
  return this.toDispose.disposed;
1385
1432
  }
1386
- isErrorLine(fromPort, toPort) {
1433
+ isErrorLine(fromPort, toPort, defaultValue) {
1387
1434
  if (this.options.isErrorLine) {
1388
1435
  return this.options.isErrorLine(fromPort, toPort, this);
1389
1436
  }
1390
- return false;
1437
+ return !!defaultValue;
1391
1438
  }
1392
- isReverseLine(line) {
1439
+ isReverseLine(line, defaultValue = false) {
1393
1440
  if (this.options.isReverseLine) {
1394
1441
  return this.options.isReverseLine(line);
1395
1442
  }
1396
- return false;
1443
+ return defaultValue;
1397
1444
  }
1398
- isHideArrowLine(line) {
1445
+ isHideArrowLine(line, defaultValue = false) {
1399
1446
  if (this.options.isHideArrowLine) {
1400
1447
  return this.options.isHideArrowLine(line);
1401
1448
  }
1402
- return false;
1449
+ return defaultValue;
1403
1450
  }
1404
- isFlowingLine(line) {
1451
+ isFlowingLine(line, defaultValue = false) {
1405
1452
  if (this.options.isFlowingLine) {
1406
1453
  return this.options.isFlowingLine(line);
1407
1454
  }
1408
- return false;
1455
+ return defaultValue;
1409
1456
  }
1410
- isDisabledLine(line) {
1457
+ isDisabledLine(line, defaultValue = false) {
1411
1458
  if (this.options.isDisabledLine) {
1412
1459
  return this.options.isDisabledLine(line);
1413
1460
  }
1414
- return false;
1461
+ return defaultValue;
1415
1462
  }
1416
- isVerticalLine(line) {
1463
+ isVerticalLine(line, defaultValue = false) {
1417
1464
  if (this.options.isVerticalLine) {
1418
1465
  return this.options.isVerticalLine(line);
1419
1466
  }
1420
- return false;
1467
+ return defaultValue;
1421
1468
  }
1422
1469
  setLineRenderType(line) {
1423
1470
  if (this.options.setLineRenderType) {
@@ -1487,7 +1534,8 @@ var WorkflowLinesManager = class {
1487
1534
  * @param pos
1488
1535
  */
1489
1536
  getPortFromMousePos(pos) {
1490
- const allPorts = this.entityManager.getEntities(WorkflowPortEntity).filter((port) => port.node.flowNodeType !== "root");
1537
+ const allNodes = this.getSortedNodes().reverse();
1538
+ const allPorts = allNodes.map((node) => node.getData(WorkflowNodePortsData).allPorts).flat();
1491
1539
  const targetPort = allPorts.find((port) => port.isHovered(pos.x, pos.y));
1492
1540
  if (targetPort) {
1493
1541
  const containNodes = this.getContainNodesFromMousePos(pos);
@@ -1522,9 +1570,12 @@ var WorkflowLinesManager = class {
1522
1570
  registerData(line) {
1523
1571
  line.addData(WorkflowLineRenderData);
1524
1572
  }
1573
+ getSortedNodes() {
1574
+ return this.document.getAllNodes().sort((a, b) => this.getNodeIndex(a) - this.getNodeIndex(b));
1575
+ }
1525
1576
  /** 获取鼠标坐标位置的所有节点(stackIndex 从小到大排序) */
1526
1577
  getContainNodesFromMousePos(pos) {
1527
- const allNodes = this.document.getAllNodes().sort((a, b) => this.getNodeIndex(a) - this.getNodeIndex(b));
1578
+ const allNodes = this.getSortedNodes();
1528
1579
  const zoom = this.entityManager.getEntity(PlaygroundConfigEntity2)?.config?.zoom || 1;
1529
1580
  const containNodes = allNodes.map((node) => {
1530
1581
  const { bounds } = node.getData(FlowNodeTransformData3);
@@ -2170,11 +2221,11 @@ var WorkflowDocument = class extends FlowDocument {
2170
2221
  /**
2171
2222
  * 判断端口是否为错误态
2172
2223
  */
2173
- isErrorPort(port) {
2224
+ isErrorPort(port, defaultValue = false) {
2174
2225
  if (typeof this.options.isErrorPort === "function") {
2175
2226
  return this.options.isErrorPort(port);
2176
2227
  }
2177
- return false;
2228
+ return defaultValue;
2178
2229
  }
2179
2230
  /**
2180
2231
  * 导出数据
@@ -2867,13 +2918,8 @@ var WorkflowDragService = class {
2867
2918
  return true;
2868
2919
  }
2869
2920
  const { padding, bounds } = node.transform;
2870
- const contentRect = new Rectangle8(
2871
- bounds.x + padding.left,
2872
- bounds.y,
2873
- bounds.width - padding.left - padding.right,
2874
- bounds.height
2875
- );
2876
- return !contentRect.contains(mousePos.x, mousePos.y);
2921
+ const contentRect = new Rectangle8(bounds.x, bounds.y, padding.left * 2 / 3, bounds.height);
2922
+ return contentRect.contains(mousePos.x, mousePos.y);
2877
2923
  }
2878
2924
  /** 获取最近的 port */
2879
2925
  getNearestPort(node, mousePos) {