diff --git a/examples/react/src/examples/UseHandleConnections/MultiHandleNode.tsx b/examples/react/src/examples/UseHandleConnections/MultiHandleNode.tsx index 4301e647..4b8fd2c1 100644 --- a/examples/react/src/examples/UseHandleConnections/MultiHandleNode.tsx +++ b/examples/react/src/examples/UseHandleConnections/MultiHandleNode.tsx @@ -1,7 +1,7 @@ import { memo, FC, useEffect, useCallback } from 'react'; -import { Handle, Position, NodeProps, useHandleConnections, Connection, HandleComponentProps } from '@xyflow/react'; +import { Handle, Position, NodeProps, useHandleConnections, Connection, HandleProps } from '@xyflow/react'; -function CustomHandle({ nodeId, ...handleProps }: HandleComponentProps & { nodeId: string }) { +function CustomHandle({ nodeId, ...handleProps }: HandleProps & { nodeId: string }) { const onConnect = useCallback( (connections: Connection[]) => console.log('onConnect handler, node id:', nodeId, connections), [nodeId] diff --git a/examples/react/src/examples/UseHandleConnections/SingleHandleNode.tsx b/examples/react/src/examples/UseHandleConnections/SingleHandleNode.tsx index 6163f108..1c13dcb0 100644 --- a/examples/react/src/examples/UseHandleConnections/SingleHandleNode.tsx +++ b/examples/react/src/examples/UseHandleConnections/SingleHandleNode.tsx @@ -1,7 +1,7 @@ import { memo, FC, useEffect, useCallback } from 'react'; -import { Handle, Position, NodeProps, useHandleConnections, Connection, HandleComponentProps } from '@xyflow/react'; +import { Handle, Position, NodeProps, useHandleConnections, Connection, HandleProps } from '@xyflow/react'; -function CustomHandle({ nodeId, ...handleProps }: HandleComponentProps & { nodeId: string }) { +function CustomHandle({ nodeId, ...handleProps }: HandleProps & { nodeId: string }) { const onConnect = useCallback( (connections: Connection[]) => { console.log('onConnect handler, node id:', nodeId, connections); diff --git a/packages/react/src/components/Handle/index.tsx b/packages/react/src/components/Handle/index.tsx index 977a5c5b..760733a0 100644 --- a/packages/react/src/components/Handle/index.tsx +++ b/packages/react/src/components/Handle/index.tsx @@ -14,10 +14,11 @@ import { getHostForElement, isMouseEvent, addEdge, - type HandleProps, + type HandleProps as HandlePropsSystem, type Connection, type HandleType, ConnectionMode, + OnConnect, } from '@xyflow/system'; import { useStore, useStoreApi } from '../../hooks/useStore'; @@ -25,7 +26,10 @@ import { useNodeId } from '../../contexts/NodeIdContext'; import { type ReactFlowState } from '../../types'; import { fixedForwardRef } from '../../utils'; -export interface HandleComponentProps extends HandleProps, Omit, 'id'> {} +export interface HandleProps extends HandlePropsSystem, Omit, 'id'> { + /** Callback called when connection is made */ + onConnect?: OnConnect; +} const selector = (s: ReactFlowState) => ({ connectOnClick: s.connectOnClick, @@ -75,7 +79,7 @@ function HandleComponent( onMouseDown, onTouchStart, ...rest - }: HandleComponentProps, + }: HandleProps, ref: ForwardedRef ) { const handleId = id || null; diff --git a/packages/react/src/index.ts b/packages/react/src/index.ts index f8ba9ea6..85b582d6 100644 --- a/packages/react/src/index.ts +++ b/packages/react/src/index.ts @@ -1,5 +1,5 @@ export { default as ReactFlow } from './container/ReactFlow'; -export { Handle, type HandleComponentProps } from './components/Handle'; +export { Handle, type HandleProps } from './components/Handle'; export { EdgeText } from './components/Edges/EdgeText'; export { StraightEdge } from './components/Edges/StraightEdge'; export { StepEdge } from './components/Edges/StepEdge'; diff --git a/packages/svelte/src/lib/components/Handle/Handle.svelte b/packages/svelte/src/lib/components/Handle/Handle.svelte index a7b5493c..472ca2c2 100644 --- a/packages/svelte/src/lib/components/Handle/Handle.svelte +++ b/packages/svelte/src/lib/components/Handle/Handle.svelte @@ -13,9 +13,9 @@ } from '@xyflow/system'; import { useStore } from '$lib/store'; - import type { HandleComponentProps } from '$lib/types'; + import type { HandleProps } from '$lib/types'; - type $$Props = HandleComponentProps; + type $$Props = HandleProps; export let id: $$Props['id'] = undefined; export let type: $$Props['type'] = 'source'; diff --git a/packages/svelte/src/lib/index.ts b/packages/svelte/src/lib/index.ts index 714016ce..5b62f371 100644 --- a/packages/svelte/src/lib/index.ts +++ b/packages/svelte/src/lib/index.ts @@ -46,7 +46,7 @@ export type { EdgeTypes, DefaultEdgeOptions } from '$lib/types/edges'; -export type { HandleComponentProps, FitViewOptions } from '$lib/types/general'; +export type { HandleProps, FitViewOptions } from '$lib/types/general'; export type { Node, NodeTypes, diff --git a/packages/svelte/src/lib/types/general.ts b/packages/svelte/src/lib/types/general.ts index 8aaa9a0a..e69c83db 100644 --- a/packages/svelte/src/lib/types/general.ts +++ b/packages/svelte/src/lib/types/general.ts @@ -1,12 +1,11 @@ import type { ShortcutModifierDefinition } from '@svelte-put/shortcut'; import type { FitViewOptionsBase, - HandleType, - Position, XYPosition, ConnectingHandle, Connection, - OnBeforeDeleteBase + OnBeforeDeleteBase, + HandleProps as HandlePropsSystem } from '@xyflow/system'; import type { Node } from './nodes'; @@ -23,32 +22,9 @@ export type ConnectionData = { connectionStatus: string | null; }; -export type HandleComponentProps = { - /** Type of the handle - * @example HandleType.Source, HandleType.Target - */ - type: HandleType; - /** Position of the handle - * @example Position.TopLeft, Position.TopRight, - * Position.BottomLeft, Position.BottomRight - */ - position?: Position; - /** Id of the handle - * @remarks optional if there is only one handle of this type - */ - id?: string; +export type HandleProps = HandlePropsSystem & { class?: string; style?: string; - /** Should you be able to connect from/to this handle */ - isConnectable?: boolean; - /** Shoould you be able to connect from this handle */ - isConnectableStart?: boolean; - /** Should you be able to connect to this handle */ - isConnectableEnd?: boolean; - /** Function that is called when checking if connection is valid. - * Overrides the isValidConnection on the Flow component. - */ - isValidConnection?: IsValidConnection; onconnect?: (connections: Connection[]) => void; ondisconnect?: (connections: Connection[]) => void; }; diff --git a/packages/system/src/types/handles.ts b/packages/system/src/types/handles.ts index 32732935..b75de4c5 100644 --- a/packages/system/src/types/handles.ts +++ b/packages/system/src/types/handles.ts @@ -1,4 +1,4 @@ -import type { Position, OnConnect, IsValidConnection } from '.'; +import type { Position, IsValidConnection } from '.'; export type HandleType = 'source' | 'target'; @@ -42,8 +42,6 @@ export type HandleProps = { isConnectableStart?: boolean; /** Should you be able to connect to this handle */ isConnectableEnd?: boolean; - /** Callback called when connection is made */ - onConnect?: OnConnect; /** Callback if connection is valid * @remarks connection becomes an edge if isValidConnection returns true */