forked from n8n-io/n8n
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(editor): Make new canvas connections go underneath node when loo…
…ping backwards (n8n-io#11833)
- Loading branch information
1 parent
459e6aa
commit 91d1bd8
Showing
7 changed files
with
102 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 0 additions & 70 deletions
70
packages/editor-ui/src/components/canvas/elements/edges/utils/edgePath.ts
This file was deleted.
Oops, something went wrong.
63 changes: 63 additions & 0 deletions
63
packages/editor-ui/src/components/canvas/elements/edges/utils/getEdgeRenderData.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import type { EdgeProps } from '@vue-flow/core'; | ||
import { getBezierPath, getSmoothStepPath, Position } from '@vue-flow/core'; | ||
import { NodeConnectionType } from 'n8n-workflow'; | ||
|
||
const EDGE_PADDING_BOTTOM = 130; | ||
const EDGE_PADDING_X = 40; | ||
const EDGE_BORDER_RADIUS = 16; | ||
const HANDLE_SIZE = 20; // Required to avoid connection line glitching when initially interacting with the handle | ||
|
||
const isRightOfSourceHandle = (sourceX: number, targetX: number) => sourceX - HANDLE_SIZE > targetX; | ||
|
||
export function getEdgeRenderData( | ||
props: Pick< | ||
EdgeProps, | ||
'sourceX' | 'sourceY' | 'sourcePosition' | 'targetX' | 'targetY' | 'targetPosition' | ||
>, | ||
{ | ||
connectionType = NodeConnectionType.Main, | ||
}: { | ||
connectionType?: NodeConnectionType; | ||
} = {}, | ||
) { | ||
const { targetX, targetY, sourceX, sourceY, sourcePosition, targetPosition } = props; | ||
|
||
if (!isRightOfSourceHandle(sourceX, targetX) || connectionType !== NodeConnectionType.Main) { | ||
const segment = getBezierPath(props); | ||
return { | ||
segments: [segment], | ||
labelPosition: [segment[1], segment[2]], | ||
}; | ||
} | ||
|
||
// Connection is backwards and the source is on the right side | ||
// -> We need to avoid overlapping the source node | ||
const firstSegmentTargetX = (sourceX + targetX) / 2; | ||
const firstSegmentTargetY = sourceY + EDGE_PADDING_BOTTOM; | ||
const firstSegment = getSmoothStepPath({ | ||
sourceX, | ||
sourceY, | ||
targetX: firstSegmentTargetX, | ||
targetY: firstSegmentTargetY, | ||
sourcePosition, | ||
targetPosition: Position.Right, | ||
borderRadius: EDGE_BORDER_RADIUS, | ||
offset: EDGE_PADDING_X, | ||
}); | ||
|
||
const secondSegment = getSmoothStepPath({ | ||
sourceX: firstSegmentTargetX, | ||
sourceY: firstSegmentTargetY, | ||
targetX, | ||
targetY, | ||
sourcePosition: Position.Left, | ||
targetPosition, | ||
borderRadius: EDGE_BORDER_RADIUS, | ||
offset: EDGE_PADDING_X, | ||
}); | ||
|
||
return { | ||
segments: [firstSegment, secondSegment], | ||
labelPosition: [firstSegmentTargetX, firstSegmentTargetY], | ||
}; | ||
} |
1 change: 1 addition & 0 deletions
1
packages/editor-ui/src/components/canvas/elements/edges/utils/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './getEdgeRenderData'; |