feat(connection-line): add status class (valid or invalid) while in connection radius

This commit is contained in:
moklick
2023-02-03 21:10:44 +01:00
parent 4ca10a3ae2
commit 23d1e65a72
8 changed files with 55 additions and 8 deletions
@@ -2,11 +2,12 @@ import type { MouseEvent as ReactMouseEvent, TouchEvent as ReactTouchEvent } fro
import { StoreApi } from 'zustand';
import { getHostForElement, calcAutoPan, getEventPosition } from '../../utils';
import type { OnConnect, HandleType, ReactFlowState, Connection } from '../../types';
import type { OnConnect, HandleType, ReactFlowState, Connection, ConnectionStatus } from '../../types';
import { pointToRendererPoint, rendererPointToPoint } from '../../utils/graph';
import {
ConnectionHandle,
getClosestHandle,
getConnectionStatus,
getHandleLookup,
getHandleType,
isValidHandle,
@@ -91,6 +92,7 @@ export function handlePointerDown({
connectionNodeId: nodeId,
connectionHandleId: handleId,
connectionHandleType: handleType,
connectionStatus: null,
});
onConnectStart?.(event, { nodeId, handleId, handleType });
@@ -123,7 +125,7 @@ export function handlePointerDown({
setState({
connectionPosition:
prevClosestHandle && isValid
prevClosestHandle && result.isValid
? rendererPointToPoint(
{
x: prevClosestHandle.x,
@@ -132,6 +134,7 @@ export function handlePointerDown({
transform
)
: connectionPosition,
connectionStatus: getConnectionStatus(!!prevClosestHandle, result.isValid),
});
if (!prevClosestHandle) {