Merge branch 'handle-lookup' of github.com:xyflow/xyflow into handle-lookup

This commit is contained in:
moklick
2024-08-14 16:31:06 +02:00
7 changed files with 36 additions and 6 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@xyflow/react': patch
---
chore(react): re-export Handle type
+7
View File
@@ -0,0 +1,7 @@
---
'@xyflow/react': patch
'@xyflow/svelte': patch
'@xyflow/system': patch
---
feat(onConnectEnd): pass connectionState param
@@ -19,6 +19,8 @@ import {
type HandleType, type HandleType,
ConnectionMode, ConnectionMode,
OnConnect, OnConnect,
ConnectionState,
Optional,
} from '@xyflow/system'; } from '@xyflow/system';
import { useStore, useStoreApi } from '../../hooks/useStore'; import { useStore, useStoreApi } from '../../hooks/useStore';
@@ -160,6 +162,7 @@ function HandleComponent(
lib, lib,
rfId: flowId, rfId: flowId,
nodeLookup, nodeLookup,
connection: connectionState,
} = store.getState(); } = store.getState();
if (!nodeId || (!connectionClickStartHandle && !isConnectableStart)) { if (!nodeId || (!connectionClickStartHandle && !isConnectableStart)) {
@@ -195,7 +198,10 @@ function HandleComponent(
onConnectExtended(connection); onConnectExtended(connection);
} }
onClickConnectEnd?.(event as unknown as MouseEvent); const connectionClone = structuredClone(connectionState) as Optional<ConnectionState, 'inProgress'>;
delete connectionClone.inProgress;
connectionClone.toPosition = connectionClone.toHandle ? connectionClone.toHandle.position : null;
onClickConnectEnd?.(event as unknown as MouseEvent, connectionClone);
store.setState({ connectionClickStartHandle: null }); store.setState({ connectionClickStartHandle: null });
}; };
+4
View File
@@ -103,6 +103,10 @@ export {
type KeyCode, type KeyCode,
} from '@xyflow/system'; } from '@xyflow/system';
// we need this workaround to prevent a duplicate identifier error
import { type Handle as HandleBound } from '@xyflow/system';
export type Handle = HandleBound;
// system utils // system utils
export { export {
type GetBezierPathParams, type GetBezierPathParams,
@@ -29,7 +29,7 @@
// export let isConnectableEnd: $$Props['isConnectableEnd'] = undefined; // export let isConnectableEnd: $$Props['isConnectableEnd'] = undefined;
let isConnectableProp: $$Props['isConnectable'] = undefined; let isConnectableProp: $$Props['isConnectable'] = undefined;
export { isConnectableProp as isConnectable } export { isConnectableProp as isConnectable };
let className: $$Props['class'] = undefined; let className: $$Props['class'] = undefined;
export { className as class }; export { className as class };
@@ -101,8 +101,8 @@
handleType: startParams.handleType handleType: startParams.handleType
}); });
}, },
onConnectEnd: (event) => { onConnectEnd: (event, connectionState) => {
$onConnectEndAction?.(event); $onConnectEndAction?.(event, connectionState);
}, },
getTransform: () => [$viewport.x, $viewport.y, $viewport.zoom], getTransform: () => [$viewport.x, $viewport.y, $viewport.zoom],
getFromHandle: () => $connection.fromHandle getFromHandle: () => $connection.fromHandle
+4 -1
View File
@@ -50,7 +50,10 @@ export type OnConnectStartParams = {
export type OnConnectStart = (event: MouseEvent | TouchEvent, params: OnConnectStartParams) => void; export type OnConnectStart = (event: MouseEvent | TouchEvent, params: OnConnectStartParams) => void;
export type OnConnect = (connection: Connection) => void; export type OnConnect = (connection: Connection) => void;
export type OnConnectEnd = (event: MouseEvent | TouchEvent) => void; export type OnConnectEnd = (
event: MouseEvent | TouchEvent,
connectionState: Omit<ConnectionState, 'inProgress'>
) => void;
export type IsValidConnection = (edge: EdgeBase | Connection) => boolean; export type IsValidConnection = (edge: EdgeBase | Connection) => boolean;
+6 -1
View File
@@ -192,7 +192,12 @@ function onPointerDown(
// it's important to get a fresh reference from the store here // it's important to get a fresh reference from the store here
// in order to get the latest state of onConnectEnd // in order to get the latest state of onConnectEnd
onConnectEnd?.(event); // eslint-disable-next-line @typescript-eslint/no-unused-vars
const { inProgress, ...connectionState } = previousConnection;
onConnectEnd?.(event, {
...connectionState,
toPosition: previousConnection.toHandle ? previousConnection.toPosition : null,
});
if (edgeUpdaterType) { if (edgeUpdaterType) {
onReconnectEnd?.(event); onReconnectEnd?.(event);