Browse Source

fix(container): drag line inside container shouldn't snapping to container itself (#491)

Louis Young 6 tháng trước cách đây
mục cha
commit
d1c5b2ad5f

+ 17 - 1
packages/canvas-engine/free-layout-core/src/service/workflow-drag-service.ts

@@ -646,7 +646,7 @@ export class WorkflowDragService {
         });
 
         this.setLineColor(line, this.linesManager.lineColor.drawing);
-        if (toNode) {
+        if (toNode && this.canBuildContainerLine(toNode, dragPos)) {
           // 如果鼠标 hover 在 node 中的时候,默认连线到这个 node 的初始位置
           toPort = this.getNearestPort(toNode, dragPos);
           const { hasError } = this.handleDragOnNode(toNode, fromPort, line, toPort, originLine);
@@ -780,6 +780,22 @@ export class WorkflowDragService {
     };
   }
 
+  /** 能否建立容器连线 */
+  private canBuildContainerLine(node: WorkflowNodeEntity, mousePos: IPoint): boolean {
+    const isContainer = this.isContainer(node);
+    if (!isContainer) {
+      return true;
+    }
+    const { padding, bounds } = node.transform;
+    const contentRect = new Rectangle(
+      bounds.x + padding.left,
+      bounds.y,
+      bounds.width - padding.left - padding.right,
+      bounds.height
+    );
+    return !contentRect.contains(mousePos.x, mousePos.y);
+  }
+
   /** 获取最近的 port */
   private getNearestPort(node: WorkflowNodeEntity, mousePos: IPoint): WorkflowPortEntity {
     const portsData = node.getData(WorkflowNodePortsData)!;