|
@@ -9,12 +9,22 @@ import {
|
|
|
FlowNodeBaseType,
|
|
FlowNodeBaseType,
|
|
|
FlowTransitionLabelEnum,
|
|
FlowTransitionLabelEnum,
|
|
|
FlowTransitionLineEnum,
|
|
FlowTransitionLineEnum,
|
|
|
|
|
+ getDefaultSpacing,
|
|
|
|
|
+ Vertex,
|
|
|
} from '@flowgram.ai/document';
|
|
} from '@flowgram.ai/document';
|
|
|
import { FlowNodeTransformData } from '@flowgram.ai/document';
|
|
import { FlowNodeTransformData } from '@flowgram.ai/document';
|
|
|
|
|
|
|
|
import { getPortChildInput, getSlotChildLineStartPoint } from '../utils/transition';
|
|
import { getPortChildInput, getSlotChildLineStartPoint } from '../utils/transition';
|
|
|
import { SlotNodeType } from '../typings';
|
|
import { SlotNodeType } from '../typings';
|
|
|
-import { SLOT_BLOCK_DISTANCE, RENDER_SLOT_ADDER_KEY } from '../constants';
|
|
|
|
|
|
|
+import {
|
|
|
|
|
+ RENDER_SLOT_ADDER_KEY,
|
|
|
|
|
+ SlotSpacingKey,
|
|
|
|
|
+ SLOT_PORT_DISTANCE,
|
|
|
|
|
+ SLOT_RADIUS,
|
|
|
|
|
+ SLOT_LABEL_DISTANCE,
|
|
|
|
|
+ RENDER_SLOT_LABEL_KEY,
|
|
|
|
|
+ SLOT_BLOCK_VERTICAL_SPACING,
|
|
|
|
|
+} from '../constants';
|
|
|
|
|
|
|
|
export const SlotBlockRegistry: FlowNodeRegistry = {
|
|
export const SlotBlockRegistry: FlowNodeRegistry = {
|
|
|
type: SlotNodeType.SlotBlock,
|
|
type: SlotNodeType.SlotBlock,
|
|
@@ -27,7 +37,11 @@ export const SlotBlockRegistry: FlowNodeRegistry = {
|
|
|
if (!transform.entity.isVertical && transform.size.width === 0) {
|
|
if (!transform.entity.isVertical && transform.size.width === 0) {
|
|
|
return 90;
|
|
return 90;
|
|
|
}
|
|
}
|
|
|
- return 30;
|
|
|
|
|
|
|
+ return getDefaultSpacing(
|
|
|
|
|
+ transform.entity,
|
|
|
|
|
+ SlotSpacingKey.SLOT_BLOCK_VERTICAL_SPACING,
|
|
|
|
|
+ SLOT_BLOCK_VERTICAL_SPACING
|
|
|
|
|
+ );
|
|
|
},
|
|
},
|
|
|
isInlineBlocks: (node) => !node.isVertical,
|
|
isInlineBlocks: (node) => !node.isVertical,
|
|
|
},
|
|
},
|
|
@@ -36,23 +50,60 @@ export const SlotBlockRegistry: FlowNodeRegistry = {
|
|
|
const start = getSlotChildLineStartPoint(icon);
|
|
const start = getSlotChildLineStartPoint(icon);
|
|
|
const portPoint = transition.transform.inputPoint;
|
|
const portPoint = transition.transform.inputPoint;
|
|
|
|
|
|
|
|
|
|
+ const radius = getDefaultSpacing(
|
|
|
|
|
+ transition.transform.entity,
|
|
|
|
|
+ SlotSpacingKey.SLOT_RADIUS,
|
|
|
|
|
+ SLOT_RADIUS
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ let startPortVertices: Vertex[] = [{ x: start.x, y: portPoint.y }];
|
|
|
|
|
+
|
|
|
|
|
+ if (transition.entity.isVertical) {
|
|
|
|
|
+ const deltaY = Math.abs(portPoint.y - start.y);
|
|
|
|
|
+ let deltaX = radius;
|
|
|
|
|
+ let isTruncated = false;
|
|
|
|
|
+
|
|
|
|
|
+ if (deltaY < radius * 2) {
|
|
|
|
|
+ isTruncated = true;
|
|
|
|
|
+ if (deltaY < radius) {
|
|
|
|
|
+ // Calculate the x by circle equation
|
|
|
|
|
+ deltaX = Math.sqrt(radius ** 2 - (radius - deltaY) ** 2);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ startPortVertices = [
|
|
|
|
|
+ {
|
|
|
|
|
+ x: start.x + deltaX,
|
|
|
|
|
+ y: start.y,
|
|
|
|
|
+ radiusX: radius,
|
|
|
|
|
+ radiusY: radius,
|
|
|
|
|
+ radiusOverflow: 'truncate',
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ x: start.x + deltaX,
|
|
|
|
|
+ y: portPoint.y,
|
|
|
|
|
+ ...(isTruncated ? { radiusX: 0, radiusY: 0 } : {}),
|
|
|
|
|
+ },
|
|
|
|
|
+ ];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return [
|
|
return [
|
|
|
{
|
|
{
|
|
|
type: FlowTransitionLineEnum.ROUNDED_LINE,
|
|
type: FlowTransitionLineEnum.ROUNDED_LINE,
|
|
|
from: start,
|
|
from: start,
|
|
|
to: portPoint,
|
|
to: portPoint,
|
|
|
- vertices: [{ x: start.x, y: portPoint.y }],
|
|
|
|
|
|
|
+ vertices: startPortVertices,
|
|
|
style: {
|
|
style: {
|
|
|
strokeDasharray: '5 5',
|
|
strokeDasharray: '5 5',
|
|
|
},
|
|
},
|
|
|
- radius: 5,
|
|
|
|
|
|
|
+ radius,
|
|
|
},
|
|
},
|
|
|
...transition.transform.children.map((_child) => {
|
|
...transition.transform.children.map((_child) => {
|
|
|
const childInput = getPortChildInput(_child);
|
|
const childInput = getPortChildInput(_child);
|
|
|
|
|
|
|
|
return {
|
|
return {
|
|
|
type: FlowTransitionLineEnum.ROUNDED_LINE,
|
|
type: FlowTransitionLineEnum.ROUNDED_LINE,
|
|
|
- radius: 5,
|
|
|
|
|
|
|
+ radius,
|
|
|
from: portPoint,
|
|
from: portPoint,
|
|
|
to: childInput,
|
|
to: childInput,
|
|
|
vertices: [{ x: portPoint.x, y: childInput.y }],
|
|
vertices: [{ x: portPoint.x, y: childInput.y }],
|
|
@@ -64,6 +115,8 @@ export const SlotBlockRegistry: FlowNodeRegistry = {
|
|
|
];
|
|
];
|
|
|
},
|
|
},
|
|
|
getLabels(transition) {
|
|
getLabels(transition) {
|
|
|
|
|
+ const icon = transition.transform.parent?.pre;
|
|
|
|
|
+ const start = getSlotChildLineStartPoint(icon);
|
|
|
const portPoint = transition.transform.inputPoint;
|
|
const portPoint = transition.transform.inputPoint;
|
|
|
|
|
|
|
|
return [
|
|
return [
|
|
@@ -75,6 +128,24 @@ export const SlotBlockRegistry: FlowNodeRegistry = {
|
|
|
},
|
|
},
|
|
|
offset: portPoint,
|
|
offset: portPoint,
|
|
|
},
|
|
},
|
|
|
|
|
+ {
|
|
|
|
|
+ type: FlowTransitionLabelEnum.CUSTOM_LABEL,
|
|
|
|
|
+ renderKey: RENDER_SLOT_LABEL_KEY,
|
|
|
|
|
+ props: {
|
|
|
|
|
+ node: transition.entity,
|
|
|
|
|
+ },
|
|
|
|
|
+ offset: {
|
|
|
|
|
+ x:
|
|
|
|
|
+ start.x +
|
|
|
|
|
+ getDefaultSpacing(
|
|
|
|
|
+ transition.entity,
|
|
|
|
|
+ SlotSpacingKey.SLOT_LABEL_DISTANCE,
|
|
|
|
|
+ SLOT_LABEL_DISTANCE
|
|
|
|
|
+ ),
|
|
|
|
|
+ y: portPoint.y,
|
|
|
|
|
+ },
|
|
|
|
|
+ origin: [0, 0.5],
|
|
|
|
|
+ },
|
|
|
];
|
|
];
|
|
|
},
|
|
},
|
|
|
getInputPoint(transform) {
|
|
getInputPoint(transform) {
|
|
@@ -90,7 +161,9 @@ export const SlotBlockRegistry: FlowNodeRegistry = {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
return {
|
|
|
- x: start.x + SLOT_BLOCK_DISTANCE,
|
|
|
|
|
|
|
+ x:
|
|
|
|
|
+ start.x +
|
|
|
|
|
+ getDefaultSpacing(transform.entity, SlotSpacingKey.SLOT_PORT_DISTANCE, SLOT_PORT_DISTANCE),
|
|
|
y: inputY,
|
|
y: inputY,
|
|
|
};
|
|
};
|
|
|
},
|
|
},
|