diff --git a/examples/react/src/examples/Validation/index.tsx b/examples/react/src/examples/Validation/index.tsx index 9cdad621..25ed4eff 100644 --- a/examples/react/src/examples/Validation/index.tsx +++ b/examples/react/src/examples/Validation/index.tsx @@ -41,7 +41,7 @@ const CustomInput: FC = () => ( const CustomNode: FC = ({ id }) => ( <> - +
{id}
diff --git a/examples/svelte/src/routes/examples/validation/+page.svelte b/examples/svelte/src/routes/examples/validation/+page.svelte index c973e193..d2a7cd2e 100644 --- a/examples/svelte/src/routes/examples/validation/+page.svelte +++ b/examples/svelte/src/routes/examples/validation/+page.svelte @@ -24,8 +24,8 @@ data: { label: 'only connectable with B' }, ...nodeDefaults }, - { id: 'A', position: { x: 250, y: 0 }, data: { label: 'A' }, ...nodeDefaults }, - { id: 'B', position: { x: 250, y: 150 }, data: { label: 'B' }, ...nodeDefaults }, + { id: 'A', position: { x: 250, y: 0 }, data: { label: 'A' } }, + { id: 'B', position: { x: 250, y: 150 }, data: { label: 'B' } }, { id: 'C', position: { x: 250, y: 300 }, data: { label: 'C' }, ...nodeDefaults } ]); diff --git a/packages/react/src/components/ConnectionLine/index.tsx b/packages/react/src/components/ConnectionLine/index.tsx index 4ca5c106..33b1ca50 100644 --- a/packages/react/src/components/ConnectionLine/index.tsx +++ b/packages/react/src/components/ConnectionLine/index.tsx @@ -39,7 +39,7 @@ const ConnectionLine = ({ CustomComponent, connectionStatus, }: ConnectionLineProps) => { - const { fromNode, handleId, toX, toY, connectionMode } = useStore( + const { fromNode, handleId, toX, toY, connectionMode, endPosition, isValid } = useStore( useCallback( (s: ReactFlowStore) => ({ fromNode: s.nodeLookup.get(nodeId), @@ -47,11 +47,14 @@ const ConnectionLine = ({ toX: (s.connectionPosition.x - s.transform[0]) / s.transform[2], toY: (s.connectionPosition.y - s.transform[1]) / s.transform[2], connectionMode: s.connectionMode, + endPosition: s.connectionEndHandle?.position, + isValid: s.connectionStatus === 'valid', }), [nodeId] ), shallow ); + const fromHandleBounds = fromNode?.internals.handleBounds; let handleBounds = fromHandleBounds?.[handleType]; @@ -69,7 +72,7 @@ const ConnectionLine = ({ const fromX = fromNode.internals.positionAbsolute.x + fromHandleX; const fromY = fromNode.internals.positionAbsolute.y + fromHandleY; const fromPosition = fromHandle?.position; - const toPosition = fromPosition ? oppositePosition[fromPosition] : null; + const toPosition = isValid && endPosition ? endPosition : fromPosition ? oppositePosition[fromPosition] : null; if (!fromPosition || !toPosition) { return null; diff --git a/packages/svelte/src/lib/store/derived-connection-props.ts b/packages/svelte/src/lib/store/derived-connection-props.ts index fc98366e..f81c5e37 100644 --- a/packages/svelte/src/lib/store/derived-connection-props.ts +++ b/packages/svelte/src/lib/store/derived-connection-props.ts @@ -88,7 +88,9 @@ export function getDerivedConnectionProps( const fromX = (fromNode?.internals.positionAbsolute.x ?? 0) + fromHandleX; const fromY = (fromNode?.internals.positionAbsolute.y ?? 0) + fromHandleY; const fromPosition = fromHandle?.position; - const toPosition = fromPosition ? oppositePosition[fromPosition] : undefined; + const toPosition = + connection.connectionEndHandle?.position ?? + (fromPosition ? oppositePosition[fromPosition] : undefined); const pathParams = { sourceX: fromX, diff --git a/packages/system/src/types/handles.ts b/packages/system/src/types/handles.ts index b75de4c5..c5b54154 100644 --- a/packages/system/src/types/handles.ts +++ b/packages/system/src/types/handles.ts @@ -16,6 +16,7 @@ export type ConnectingHandle = { nodeId: string; type: HandleType; handleId?: string | null; + position?: Position | null; }; export type ConnectionHandle = { diff --git a/packages/system/src/xyhandle/XYHandle.ts b/packages/system/src/xyhandle/XYHandle.ts index aba77305..c2dca7fe 100644 --- a/packages/system/src/xyhandle/XYHandle.ts +++ b/packages/system/src/xyhandle/XYHandle.ts @@ -13,6 +13,7 @@ import { type IsValidConnection, type ConnectionHandle, NodeLookup, + Position, } from '../types'; import { getClosestHandle, getConnectionStatus, getHandleLookup, getHandleType } from './utils'; @@ -138,12 +139,12 @@ function onPointerDown( nodeId, handleId, type: handleType, + position: (clickedHandle?.getAttribute('data-handlepos') as Position) || Position.Top, }; updateConnection({ connectionPosition, connectionStatus: null, - // connectionNodeId etc will be removed in the next major in favor of connectionStartHandle connectionStartHandle, connectionEndHandle: null, }); @@ -297,15 +298,14 @@ function isValidHandle( ? (isTarget && handleType === 'source') || (!isTarget && handleType === 'target') : handleNodeId !== fromNodeId || handleId !== fromHandleId); - if (isValid) { - result.endHandle = { - nodeId: handleNodeId as string, - handleId, - type: handleType as HandleType, - }; + result.isValid = isValid && isValidConnection(connection); - result.isValid = isValidConnection(connection); - } + result.endHandle = { + nodeId: handleNodeId as string, + handleId, + type: handleType as HandleType, + position: handleToCheck.getAttribute('data-handlepos') as Position, + }; } return result;