refactor(connections): allow graphs with nodes that have only source handles
This commit is contained in:
@@ -10,21 +10,23 @@ import {
|
|||||||
Edge,
|
Edge,
|
||||||
Node,
|
Node,
|
||||||
Elements,
|
Elements,
|
||||||
|
Connection,
|
||||||
ConnectionLineType,
|
ConnectionLineType,
|
||||||
ConnectionLineComponent,
|
ConnectionLineComponent,
|
||||||
|
ConnectionMode,
|
||||||
Transform,
|
Transform,
|
||||||
OnEdgeUpdateFunc,
|
OnEdgeUpdateFunc,
|
||||||
Connection,
|
|
||||||
} from '../../types';
|
} from '../../types';
|
||||||
|
|
||||||
interface EdgeRendererProps {
|
interface EdgeRendererProps {
|
||||||
edgeTypes: any;
|
edgeTypes: any;
|
||||||
connectionLineType: ConnectionLineType;
|
connectionLineType: ConnectionLineType;
|
||||||
connectionLineStyle?: CSSProperties;
|
connectionLineStyle?: CSSProperties;
|
||||||
|
connectionLineComponent?: ConnectionLineComponent;
|
||||||
|
connectionMode?: ConnectionMode;
|
||||||
onElementClick?: (event: React.MouseEvent, element: Node | Edge) => void;
|
onElementClick?: (event: React.MouseEvent, element: Node | Edge) => void;
|
||||||
arrowHeadColor: string;
|
arrowHeadColor: string;
|
||||||
markerEndId?: string;
|
markerEndId?: string;
|
||||||
connectionLineComponent?: ConnectionLineComponent;
|
|
||||||
onlyRenderVisibleElements: boolean;
|
onlyRenderVisibleElements: boolean;
|
||||||
onEdgeUpdate?: OnEdgeUpdateFunc;
|
onEdgeUpdate?: OnEdgeUpdateFunc;
|
||||||
}
|
}
|
||||||
@@ -39,6 +41,7 @@ interface EdgeWrapperProps {
|
|||||||
width: number;
|
width: number;
|
||||||
height: number;
|
height: number;
|
||||||
onlyRenderVisibleElements: boolean;
|
onlyRenderVisibleElements: boolean;
|
||||||
|
connectionMode?: ConnectionMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Edge = ({
|
const Edge = ({
|
||||||
@@ -51,6 +54,7 @@ const Edge = ({
|
|||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
onlyRenderVisibleElements,
|
onlyRenderVisibleElements,
|
||||||
|
connectionMode,
|
||||||
}: EdgeWrapperProps) => {
|
}: EdgeWrapperProps) => {
|
||||||
const sourceHandleId = edge.sourceHandle || null;
|
const sourceHandleId = edge.sourceHandle || null;
|
||||||
const targetHandleId = edge.targetHandle || null;
|
const targetHandleId = edge.targetHandle || null;
|
||||||
@@ -79,8 +83,14 @@ const Edge = ({
|
|||||||
|
|
||||||
const edgeType = edge.type || 'default';
|
const edgeType = edge.type || 'default';
|
||||||
const EdgeComponent = props.edgeTypes[edgeType] || props.edgeTypes.default;
|
const EdgeComponent = props.edgeTypes[edgeType] || props.edgeTypes.default;
|
||||||
|
const targetNodeBounds = targetNode.__rf.handleBounds;
|
||||||
|
// when connection type is loose we can define all handles as sources
|
||||||
|
const targetNodeHandles =
|
||||||
|
connectionMode === ConnectionMode.Strict
|
||||||
|
? targetNodeBounds.target
|
||||||
|
: targetNodeBounds.target || targetNodeBounds.source;
|
||||||
const sourceHandle = getHandle(sourceNode.__rf.handleBounds.source, sourceHandleId);
|
const sourceHandle = getHandle(sourceNode.__rf.handleBounds.source, sourceHandleId);
|
||||||
const targetHandle = getHandle(targetNode.__rf.handleBounds.target, targetHandleId);
|
const targetHandle = getHandle(targetNodeHandles, targetHandleId);
|
||||||
const sourcePosition = sourceHandle ? sourceHandle.position : Position.Bottom;
|
const sourcePosition = sourceHandle ? sourceHandle.position : Position.Bottom;
|
||||||
const targetPosition = targetHandle ? targetHandle.position : Position.Top;
|
const targetPosition = targetHandle ? targetHandle.position : Position.Top;
|
||||||
|
|
||||||
|
|||||||
@@ -242,9 +242,10 @@ const GraphView = ({
|
|||||||
onElementClick={onElementClick}
|
onElementClick={onElementClick}
|
||||||
connectionLineType={connectionLineType}
|
connectionLineType={connectionLineType}
|
||||||
connectionLineStyle={connectionLineStyle}
|
connectionLineStyle={connectionLineStyle}
|
||||||
|
connectionLineComponent={connectionLineComponent}
|
||||||
|
connectionMode={connectionMode}
|
||||||
arrowHeadColor={arrowHeadColor}
|
arrowHeadColor={arrowHeadColor}
|
||||||
markerEndId={markerEndId}
|
markerEndId={markerEndId}
|
||||||
connectionLineComponent={connectionLineComponent}
|
|
||||||
onEdgeUpdate={onEdgeUpdate}
|
onEdgeUpdate={onEdgeUpdate}
|
||||||
onlyRenderVisibleElements={onlyRenderVisibleElements}
|
onlyRenderVisibleElements={onlyRenderVisibleElements}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ const ReactFlow = ({
|
|||||||
onSelectionDrag,
|
onSelectionDrag,
|
||||||
onSelectionDragStop,
|
onSelectionDragStop,
|
||||||
onSelectionContextMenu,
|
onSelectionContextMenu,
|
||||||
connectionMode,
|
connectionMode = ConnectionMode.Strict,
|
||||||
connectionLineType = ConnectionLineType.Bezier,
|
connectionLineType = ConnectionLineType.Bezier,
|
||||||
connectionLineStyle,
|
connectionLineStyle,
|
||||||
connectionLineComponent,
|
connectionLineComponent,
|
||||||
|
|||||||
Reference in New Issue
Block a user