fix(handle-on-connect): use correct HandleConnection type #5447

This commit is contained in:
moklick
2025-08-12 14:36:06 +02:00
parent 91e5e302d5
commit 4e588b2c23
6 changed files with 18 additions and 15 deletions
@@ -1,11 +1,11 @@
import { useEffect, useMemo, useRef } from 'react'; import { useEffect, useMemo, useRef } from 'react';
import { import {
Connection,
NodeConnection,
HandleType,
areConnectionMapsEqual, areConnectionMapsEqual,
handleConnectionChange,
errorMessages, errorMessages,
handleConnectionChange,
type NodeConnection,
type HandleType,
type HandleConnection,
} from '@xyflow/system'; } from '@xyflow/system';
import { useStore } from './useStore'; import { useStore } from './useStore';
@@ -21,9 +21,9 @@ type UseNodeConnectionsParams = {
/** Filter by handle id (this is only needed if the node has multiple handles of the same type). */ /** Filter by handle id (this is only needed if the node has multiple handles of the same type). */
handleId?: string; handleId?: string;
/** Gets called when a connection is established. */ /** Gets called when a connection is established. */
onConnect?: (connections: Connection[]) => void; onConnect?: (connections: HandleConnection[]) => void;
/** Gets called when a connection is removed. */ /** Gets called when a connection is removed. */
onDisconnect?: (connections: Connection[]) => void; onDisconnect?: (connections: HandleConnection[]) => void;
}; };
/** /**
+1
View File
@@ -112,6 +112,7 @@ export {
type SetCenter, type SetCenter,
type SetViewport, type SetViewport,
type FitBounds, type FitBounds,
type HandleConnection,
} from '@xyflow/system'; } from '@xyflow/system';
// we need this workaround to prevent a duplicate identifier error // we need this workaround to prevent a duplicate identifier error
@@ -1,10 +1,10 @@
import type { Connection, HandleProps as HandlePropsSystem } from '@xyflow/system'; import type { HandleConnection, HandleProps as HandlePropsSystem } from '@xyflow/system';
import type { Snippet } from 'svelte'; import type { Snippet } from 'svelte';
import type { ClassValue, HTMLAttributes } from 'svelte/elements'; import type { ClassValue, HTMLAttributes } from 'svelte/elements';
export type HandleProps = HandlePropsSystem & { export type HandleProps = HandlePropsSystem & {
class?: ClassValue; class?: ClassValue;
onconnect?: (connections: Connection[]) => void; onconnect?: (connections: HandleConnection[]) => void;
ondisconnect?: (connections: Connection[]) => void; ondisconnect?: (connections: HandleConnection[]) => void;
children?: Snippet; children?: Snippet;
} & HTMLAttributes<HTMLDivElement>; } & HTMLAttributes<HTMLDivElement>;
@@ -1,9 +1,9 @@
import { import {
areConnectionMapsEqual, areConnectionMapsEqual,
handleConnectionChange,
type NodeConnection, type NodeConnection,
type HandleType, type HandleType,
type Connection, type HandleConnection
handleConnectionChange
} from '@xyflow/system'; } from '@xyflow/system';
import { useStore } from '$lib/store'; import { useStore } from '$lib/store';
@@ -13,8 +13,8 @@ type UseNodeConnectionsParams = {
id?: string; id?: string;
handleType?: HandleType; handleType?: HandleType;
handleId?: string; handleId?: string;
onConnect?: (connections: Connection[]) => void; onConnect?: (connections: HandleConnection[]) => void;
onDisconnect?: (connections: Connection[]) => void; onDisconnect?: (connections: HandleConnection[]) => void;
}; };
type ConnectionMap = Map<string, NodeConnection>; type ConnectionMap = Map<string, NodeConnection>;
+3 -2
View File
@@ -54,7 +54,7 @@ export type {
StraightEdgeProps, StraightEdgeProps,
EdgeTypes, EdgeTypes,
DefaultEdgeOptions, DefaultEdgeOptions,
BuiltInEdge, BuiltInEdge
} from '$lib/types/edges'; } from '$lib/types/edges';
export type * from '$lib/types/general'; export type * from '$lib/types/general';
export type { Node, NodeTypes, BuiltInNode, NodeProps, InternalNode } from '$lib/types/nodes'; export type { Node, NodeTypes, BuiltInNode, NodeProps, InternalNode } from '$lib/types/nodes';
@@ -120,7 +120,8 @@ export {
type AriaLabelConfig, type AriaLabelConfig,
type SetCenter, type SetCenter,
type SetViewport, type SetViewport,
type FitBounds type FitBounds,
type HandleConnection
} from '@xyflow/system'; } from '@xyflow/system';
// system utils // system utils
+1
View File
@@ -209,6 +209,7 @@ function onPointerDown(
function onPointerUp(event: MouseEvent | TouchEvent) { function onPointerUp(event: MouseEvent | TouchEvent) {
if (connectionStarted) { if (connectionStarted) {
if ((closestHandle || resultHandleDomNode) && connection && isValid) { if ((closestHandle || resultHandleDomNode) && connection && isValid) {
console.log(connection);
onConnect?.(connection); onConnect?.(connection);
} }