) => {
- const edge = getState().edges.find((e) => e.id === id);
-
- if (edge) {
- handler(event, { ...edge });
- }
- };
-}
diff --git a/packages/react/src/container/EdgeRenderer/index.tsx b/packages/react/src/container/EdgeRenderer/index.tsx
index e1ae6a20..550bb487 100644
--- a/packages/react/src/container/EdgeRenderer/index.tsx
+++ b/packages/react/src/container/EdgeRenderer/index.tsx
@@ -1,9 +1,8 @@
import { memo, ReactNode } from 'react';
import { shallow } from 'zustand/shallow';
-import cc from 'classcat';
import { useStore } from '../../hooks/useStore';
-import useVisibleEdges from '../../hooks/useVisibleEdges';
+import useVisibleEdgeIds from '../../hooks/useVisibleEdges';
import MarkerDefinitions from './MarkerDefinitions';
import { GraphViewProps } from '../GraphView';
import type { ReactFlowState } from '../../types';
@@ -63,7 +62,7 @@ const EdgeRenderer = ({
children,
}: EdgeRendererProps) => {
const { edgesFocusable, edgesUpdatable, elementsSelectable, onError } = useStore(selector, shallow);
- const edges = useVisibleEdges(onlyRenderVisibleElements);
+ const edgeIds = useVisibleEdgeIds(onlyRenderVisibleElements);
return (
@@ -71,38 +70,15 @@ const EdgeRenderer = ({
- {edges.map((edge) => {
- const isFocusable = !!(edge.focusable || (edgesFocusable && typeof edge.focusable === 'undefined'));
- const isUpdatable =
- typeof onEdgeUpdate !== 'undefined' &&
- (edge.updatable || (edgesUpdatable && typeof edge.updatable === 'undefined'));
- const isSelectable = !!(edge.selectable || (elementsSelectable && typeof edge.selectable === 'undefined'));
-
+ {edgeIds.map((id) => {
return (
{
const visibleEdges =
@@ -29,14 +29,14 @@ function useVisibleEdges(onlyRenderVisible: boolean): Edge[] {
})
: s.edges;
- return visibleEdges;
+ return visibleEdges.map((edge) => edge.id);
},
[onlyRenderVisible]
),
shallow
);
- return edges;
+ return edgeIds;
}
-export default useVisibleEdges;
+export default useVisibleEdgeIds;
diff --git a/packages/react/src/index.ts b/packages/react/src/index.ts
index ae82e78b..fdf20c9f 100644
--- a/packages/react/src/index.ts
+++ b/packages/react/src/index.ts
@@ -77,6 +77,7 @@ export {
type CoordinateExtent,
type ColorMode,
type ColorModeClass,
+ type HandleType,
} from '@xyflow/system';
// system utils
diff --git a/packages/react/src/store/index.ts b/packages/react/src/store/index.ts
index 166e9eed..9b163f4e 100644
--- a/packages/react/src/store/index.ts
+++ b/packages/react/src/store/index.ts
@@ -55,10 +55,10 @@ const createRFStore = ({
set({ nodes: nodesWithInternalData });
},
setEdges: (edges: Edge[]) => {
- const { defaultEdgeOptions = {}, connectionLookup } = get();
+ const { defaultEdgeOptions = {}, connectionLookup, edgeLookup } = get();
const nextEdges = edges.map((e) => ({ ...defaultEdgeOptions, ...e }));
- updateConnectionLookup(connectionLookup, nextEdges);
+ updateConnectionLookup(connectionLookup, edgeLookup, nextEdges);
set({ edges: nextEdges });
},
@@ -79,13 +79,16 @@ const createRFStore = ({
};
if (hasDefaultNodes) {
- const { nodeLookup } = get();
+ const { nodeLookup, nodeOrigin, elevateNodesOnSelect } = get();
nextState.nodes = adoptUserProvidedNodes(nodes, nodeLookup, {
- nodeOrigin: get().nodeOrigin,
- elevateNodesOnSelect: get().elevateNodesOnSelect,
+ nodeOrigin,
+ elevateNodesOnSelect,
});
}
if (hasDefaultEdges) {
+ const { connectionLookup, edgeLookup } = get();
+ updateConnectionLookup(connectionLookup, edgeLookup, edges);
+
nextState.edges = edges;
}
diff --git a/packages/react/src/store/initialState.ts b/packages/react/src/store/initialState.ts
index d9b44567..e70d8598 100644
--- a/packages/react/src/store/initialState.ts
+++ b/packages/react/src/store/initialState.ts
@@ -24,7 +24,10 @@ const getInitialState = ({
fitView?: boolean;
} = {}): ReactFlowStore => {
const nodeLookup = new Map();
- const connectionLookup = updateConnectionLookup(new Map(), edges);
+ const connectionLookup = new Map();
+ const edgeLookup = new Map();
+
+ updateConnectionLookup(connectionLookup, edgeLookup, edges);
const nextNodes = adoptUserProvidedNodes(nodes, nodeLookup, {
nodeOrigin: [0, 0],
elevateNodesOnSelect: false,
@@ -47,6 +50,7 @@ const getInitialState = ({
nodes: nextNodes,
nodeLookup,
edges: edges,
+ edgeLookup,
connectionLookup,
onNodesChange: null,
onEdgesChange: null,
diff --git a/packages/react/src/types/edges.ts b/packages/react/src/types/edges.ts
index 2c0d3742..e3e2809a 100644
--- a/packages/react/src/types/edges.ts
+++ b/packages/react/src/types/edges.ts
@@ -58,9 +58,14 @@ export type Edge = DefaultEdge | SmoothStepEdgeType | BezierEdgeT
export type EdgeMouseHandler = (event: ReactMouseEvent, edge: Edge) => void;
-export type EdgeWrapperProps = Omit, 'sourceHandle' | 'targetHandle'> & {
+export type EdgeWrapperProps = {
+ id: string;
+ edgesFocusable: boolean;
+ edgesUpdatable: boolean;
+ elementsSelectable: boolean;
+ noPanClassName: string;
onClick?: EdgeMouseHandler;
- onEdgeDoubleClick?: EdgeMouseHandler;
+ onDoubleClick?: EdgeMouseHandler;
sourceHandleId?: string | null;
targetHandleId?: string | null;
onEdgeUpdate?: OnEdgeUpdateFunc;
@@ -72,10 +77,6 @@ export type EdgeWrapperProps = Omit, 'sourceHandle' | 'targetHa
onEdgeUpdateStart?: (event: ReactMouseEvent, edge: Edge, handleType: HandleType) => void;
onEdgeUpdateEnd?: (event: MouseEvent | TouchEvent, edge: Edge, handleType: HandleType) => void;
rfId?: string;
- isFocusable: boolean;
- isUpdatable: EdgeUpdatable;
- isSelectable: boolean;
- pathOptions?: BezierPathOptions | SmoothStepPathOptions;
edgeTypes?: EdgeTypes;
onError?: OnError;
elevateEdgesOnSelect?: boolean;
@@ -94,13 +95,14 @@ export type EdgeProps = Pick<
Edge,
'id' | 'animated' | 'data' | 'style' | 'selected' | 'source' | 'target'
> &
- Pick &
+ Pick &
EdgePosition &
EdgeLabelOptions & {
markerStart?: string;
markerEnd?: string;
// @TODO: how can we get better types for pathOptions?
pathOptions?: any;
+ interactionWidth?: number;
};
export type BaseEdgeProps = Pick &
diff --git a/packages/react/src/types/store.ts b/packages/react/src/types/store.ts
index 5aebb99d..50bf9618 100644
--- a/packages/react/src/types/store.ts
+++ b/packages/react/src/types/store.ts
@@ -24,7 +24,8 @@ import {
type OnMoveEnd,
type IsValidConnection,
type UpdateConnection,
- Connection,
+ EdgeLookup,
+ ConnectionLookup,
} from '@xyflow/system';
import type {
@@ -50,7 +51,8 @@ export type ReactFlowStore = {
nodes: Node[];
nodeLookup: Map;
edges: Edge[];
- connectionLookup: Map>;
+ edgeLookup: EdgeLookup;
+ connectionLookup: ConnectionLookup;
onNodesChange: OnNodesChange | null;
onEdgesChange: OnEdgesChange | null;
diff --git a/packages/svelte/src/lib/store/initial-store.ts b/packages/svelte/src/lib/store/initial-store.ts
index 8e138c77..addaa0ab 100644
--- a/packages/svelte/src/lib/store/initial-store.ts
+++ b/packages/svelte/src/lib/store/initial-store.ts
@@ -81,7 +81,9 @@ export const getInitialStore = ({
nodeOrigin: [0, 0],
elevateNodesOnSelect: false
});
- const connectionLookup = updateConnectionLookup(new Map(), edges);
+ const connectionLookup = new Map();
+ const edgeLookup = new Map();
+ updateConnectionLookup(connectionLookup, edgeLookup, edges);
let viewport: Viewport = { x: 0, y: 0, zoom: 1 };
@@ -96,7 +98,7 @@ export const getInitialStore = ({
nodes: createNodesStore(nextNodes, nodeLookup),
nodeLookup: readable