From 2b0f83b72e1c75a1b30797a47b3853467a2aa0fe Mon Sep 17 00:00:00 2001 From: peterkogo Date: Thu, 27 Jun 2024 10:31:30 +0200 Subject: [PATCH] cleanup --- packages/system/src/xyhandle/XYHandle.ts | 72 ++---------------------- packages/system/src/xyhandle/types.ts | 63 +++++++++++++++++++++ 2 files changed, 68 insertions(+), 67 deletions(-) create mode 100644 packages/system/src/xyhandle/types.ts diff --git a/packages/system/src/xyhandle/XYHandle.ts b/packages/system/src/xyhandle/XYHandle.ts index f3797393..cc6fddba 100644 --- a/packages/system/src/xyhandle/XYHandle.ts +++ b/packages/system/src/xyhandle/XYHandle.ts @@ -1,72 +1,15 @@ import { pointToRendererPoint, getHostForElement, calcAutoPan, getEventPosition, getHandlePosition } from '../utils'; import { ConnectionMode, - type OnConnect, - type OnConnectStart, - type HandleType, - type Connection, - type PanBy, - type Transform, - type Handle, - type OnConnectEnd, - type UpdateConnection, - type IsValidConnection, - NodeLookup, Position, oppositePosition, ConnectionInProgress, + type Handle, + type Connection, } from '../types'; import { getClosestHandle, isConnectionValid, getHandleLookup, getHandleType } from './utils'; - -export type OnPointerDownParams = { - autoPanOnConnect: boolean; - connectionMode: ConnectionMode; - connectionRadius: number; - domNode: HTMLDivElement | null; - handleId: string | null; - nodeId: string; - isTarget: boolean; - nodeLookup: NodeLookup; - lib: string; - flowId: string | null; - edgeUpdaterType?: HandleType; - updateConnection: UpdateConnection; - panBy: PanBy; - cancelConnection: () => void; - onConnectStart?: OnConnectStart; - onConnect?: OnConnect; - onConnectEnd?: OnConnectEnd; - isValidConnection?: IsValidConnection; - onReconnectEnd?: (evt: MouseEvent | TouchEvent) => void; - getTransform: () => Transform; - getFromHandle: () => Handle | null; -}; - -export type IsValidParams = { - handle: Pick | null; - connectionMode: ConnectionMode; - fromNodeId: string; - fromHandleId: string | null; - fromType: HandleType; - isValidConnection?: IsValidConnection; - doc: Document | ShadowRoot; - lib: string; - flowId: string | null; - handleLookup?: Handle[]; -}; - -export type XYHandleInstance = { - onPointerDown: (event: MouseEvent | TouchEvent, params: OnPointerDownParams) => void; - isValid: (event: MouseEvent | TouchEvent, params: IsValidParams) => Result; -}; - -type Result = { - handleDomNode: Element | null; - isValid: boolean; - connection: Connection | null; - toHandle: Handle | null; -}; +import { IsValidParams, OnPointerDownParams, Result, XYHandleInstance } from './types'; const alwaysValid = () => true; @@ -203,14 +146,9 @@ function onPointerDown( isValid = isConnectionValid(!!closestHandle, result.isValid); const newConnection: ConnectionInProgress = { - inProgress: true, + // from stays the same + ...previousConnection, isValid, - - from, - fromHandle, - fromPosition: fromHandle.position, - fromNode: fromNodeInternal.internals.userNode, - to: closestHandle && isValid ? { x: closestHandle.x, y: closestHandle.y } diff --git a/packages/system/src/xyhandle/types.ts b/packages/system/src/xyhandle/types.ts new file mode 100644 index 00000000..7c7543a1 --- /dev/null +++ b/packages/system/src/xyhandle/types.ts @@ -0,0 +1,63 @@ +import { + ConnectionMode, + type Connection, + type OnConnect, + type OnConnectStart, + type HandleType, + type PanBy, + type Transform, + type Handle, + type OnConnectEnd, + type UpdateConnection, + type IsValidConnection, + NodeLookup, +} from '../types'; + +export type OnPointerDownParams = { + autoPanOnConnect: boolean; + connectionMode: ConnectionMode; + connectionRadius: number; + domNode: HTMLDivElement | null; + handleId: string | null; + nodeId: string; + isTarget: boolean; + nodeLookup: NodeLookup; + lib: string; + flowId: string | null; + edgeUpdaterType?: HandleType; + updateConnection: UpdateConnection; + panBy: PanBy; + cancelConnection: () => void; + onConnectStart?: OnConnectStart; + onConnect?: OnConnect; + onConnectEnd?: OnConnectEnd; + isValidConnection?: IsValidConnection; + onReconnectEnd?: (evt: MouseEvent | TouchEvent) => void; + getTransform: () => Transform; + getFromHandle: () => Handle | null; +}; + +export type IsValidParams = { + handle: Pick | null; + connectionMode: ConnectionMode; + fromNodeId: string; + fromHandleId: string | null; + fromType: HandleType; + isValidConnection?: IsValidConnection; + doc: Document | ShadowRoot; + lib: string; + flowId: string | null; + handleLookup?: Handle[]; +}; + +export type XYHandleInstance = { + onPointerDown: (event: MouseEvent | TouchEvent, params: OnPointerDownParams) => void; + isValid: (event: MouseEvent | TouchEvent, params: IsValidParams) => Result; +}; + +export type Result = { + handleDomNode: Element | null; + isValid: boolean; + connection: Connection | null; + toHandle: Handle | null; +};