Skip to content

Commit e6951f2

Browse files
authored
feat(free-layout): auto create line from bottom port (#737)
1 parent b2c2cd0 commit e6951f2

4 files changed

Lines changed: 32 additions & 10 deletions

File tree

apps/demo-free-layout/src/hooks/use-port-click.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,16 @@ export const usePortClick = () => {
5555
// calculate position for the new node - 计算新节点的位置
5656
const nodePosition = WorkflowNodePanelUtils.adjustNodePosition({
5757
nodeType,
58-
position: {
59-
x: mousePos.x + 100,
60-
y: mousePos.y,
61-
},
58+
position:
59+
port.location === 'bottom'
60+
? {
61+
x: mousePos.x,
62+
y: mousePos.y + 100,
63+
}
64+
: {
65+
x: mousePos.x + 100,
66+
y: mousePos.y,
67+
},
6268
fromPort: port,
6369
containerNode,
6470
document,

apps/demo-free-layout/src/utils/on-drag-line-end.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,16 @@ export const onDragLineEnd = async (ctx: FreeLayoutPluginContext, params: onDrag
4343

4444
// get container node for the new node - 获取新节点的容器节点
4545
const containerNode = fromPort.node.parent;
46+
const isVertical = fromPort.location === 'bottom';
4647

4748
// open node selection panel - 打开节点选择面板
4849
const result = await nodePanelService.singleSelectNodePanel({
49-
position: mousePos,
50+
position: isVertical
51+
? {
52+
x: mousePos.x - 165,
53+
y: mousePos.y + 60,
54+
}
55+
: mousePos,
5056
containerNode,
5157
panelProps: {
5258
enableNodePlaceholder: true,

packages/plugins/free-node-panel-plugin/src/utils/adjust-node-position.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,17 @@ export const adjustNodePosition: IAdjustNodePosition = (params) => {
3939
};
4040
} else if (fromPort && !toPort) {
4141
// 仅输入
42-
adjustedPosition = {
43-
x: position.x + size.width / 2,
44-
y: position.y - size.height / 2,
45-
};
42+
if (fromPort.location === 'bottom') {
43+
adjustedPosition = {
44+
x: position.x,
45+
y: position.y,
46+
};
47+
} else {
48+
adjustedPosition = {
49+
x: position.x + size.width / 2,
50+
y: position.y - size.height / 2,
51+
};
52+
}
4653
} else if (!fromPort && toPort) {
4754
// 仅输出
4855
adjustedPosition = {

packages/plugins/free-node-panel-plugin/src/utils/build-line.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ export const buildLine: IBuildLine = (params) => {
2727

2828
const shouldBuildFromLine = portsData.inputPorts?.length > 0;
2929
if (fromPort && shouldBuildFromLine) {
30-
const toTargetPort = portsData.inputPorts[0];
30+
const isVertical = fromPort.location === 'bottom';
31+
const toTargetPort =
32+
portsData.inputPorts.find((port) => (isVertical ? port.location === 'top' : true)) ||
33+
portsData.inputPorts[0];
3134
linesManager.createLine({
3235
from: fromPort.node.id,
3336
fromPort: fromPort.portID,

0 commit comments

Comments
 (0)