reactflow-edge-routing 0.1.9 → 0.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reactflow-edge-routing",
3
- "version": "0.1.9",
3
+ "version": "0.1.12",
4
4
  "description": "Orthogonal edge routing for React Flow using obstacle-router. Edges route around nodes while pins stay fixed at their anchor points.",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -5,11 +5,14 @@ export interface EdgeRoutingState {
5
5
  loaded: boolean;
6
6
  routes: Record<string, AvoidRoute>;
7
7
  connectorType: ConnectorType;
8
+ /** Length (px) of the perpendicular stub exit segment from the node border */
9
+ stubSize: number;
8
10
  /** Node IDs currently being dragged — edges connected to these show fallback */
9
11
  draggingNodeIds: Set<string>;
10
12
  setLoaded: (loaded: boolean) => void;
11
13
  setRoutes: (routes: Record<string, AvoidRoute>) => void;
12
14
  setConnectorType: (type: ConnectorType) => void;
15
+ setStubSize: (size: number) => void;
13
16
  setDraggingNodeIds: (ids: Set<string>) => void;
14
17
  }
15
18
 
@@ -17,10 +20,12 @@ export const useEdgeRoutingStore = create<EdgeRoutingState>((set) => ({
17
20
  loaded: false,
18
21
  routes: {},
19
22
  connectorType: "orthogonal",
23
+ stubSize: 20,
20
24
  draggingNodeIds: new Set(),
21
25
  setLoaded: (loaded) => set({ loaded }),
22
26
  setRoutes: (routes) => set({ routes }),
23
27
  setConnectorType: (connectorType) => set({ connectorType }),
28
+ setStubSize: (stubSize) => set({ stubSize }),
24
29
  setDraggingNodeIds: (draggingNodeIds) => set({ draggingNodeIds }),
25
30
  }));
26
31
 
@@ -200,7 +200,7 @@ function getConnType(connectorType: ConnectorType | undefined): number {
200
200
  /** Get the Router flags for the connector type. */
201
201
  function getRouterFlags(connectorType: ConnectorType | undefined): number {
202
202
  switch (connectorType) {
203
- case "polyline": return PolyLineRouting | OrthogonalRouting;
203
+ case "polyline": return PolyLineRouting;
204
204
  default: return OrthogonalRouting;
205
205
  }
206
206
  }
@@ -737,13 +737,16 @@ function configureRouter(router: AvoidRouter, options: AvoidRouterOptions): void
737
737
  }
738
738
 
739
739
  // --- Routing options ---
740
- router.setRoutingOption(nudgeOrthogonalSegmentsConnectedToShapesOpt, options.nudgeOrthogonalSegmentsConnectedToShapes ?? true);
741
- router.setRoutingOption(nudgeSharedPathsWithCommonEndPointOpt, options.nudgeSharedPathsWithCommonEndPoint ?? true);
742
- router.setRoutingOption(performUnifyingNudgingPreprocessingStepOpt, options.performUnifyingNudgingPreprocessingStep ?? true);
743
- router.setRoutingOption(nudgeOrthogonalTouchingColinearSegmentsOpt, options.nudgeOrthogonalTouchingColinearSegments ?? false);
744
- router.setRoutingOption(improveHyperedgeRoutesMovingJunctionsOpt, options.improveHyperedgeRoutesMovingJunctions ?? true);
745
- router.setRoutingOption(penaliseOrthogonalSharedPathsAtConnEndsOpt, options.penaliseOrthogonalSharedPathsAtConnEnds ?? false);
746
- router.setRoutingOption(improveHyperedgeRoutesMovingAddingAndDeletingJunctionsOpt, options.improveHyperedgeRoutesMovingAddingAndDeletingJunctions ?? false);
740
+ // Orthogonal nudging options only apply to orthogonal/bezier routing.
741
+ // Enabling them for polyline connectors corrupts the routed paths.
742
+ const isPolyline = options.connectorType === "polyline";
743
+ router.setRoutingOption(nudgeOrthogonalSegmentsConnectedToShapesOpt, isPolyline ? false : (options.nudgeOrthogonalSegmentsConnectedToShapes ?? true));
744
+ router.setRoutingOption(nudgeSharedPathsWithCommonEndPointOpt, isPolyline ? false : (options.nudgeSharedPathsWithCommonEndPoint ?? true));
745
+ router.setRoutingOption(performUnifyingNudgingPreprocessingStepOpt, isPolyline ? false : (options.performUnifyingNudgingPreprocessingStep ?? true));
746
+ router.setRoutingOption(nudgeOrthogonalTouchingColinearSegmentsOpt, isPolyline ? false : (options.nudgeOrthogonalTouchingColinearSegments ?? false));
747
+ router.setRoutingOption(improveHyperedgeRoutesMovingJunctionsOpt, isPolyline ? false : (options.improveHyperedgeRoutesMovingJunctions ?? true));
748
+ router.setRoutingOption(penaliseOrthogonalSharedPathsAtConnEndsOpt, isPolyline ? false : (options.penaliseOrthogonalSharedPathsAtConnEnds ?? false));
749
+ router.setRoutingOption(improveHyperedgeRoutesMovingAddingAndDeletingJunctionsOpt, isPolyline ? false : (options.improveHyperedgeRoutesMovingAddingAndDeletingJunctions ?? false));
747
750
  }
748
751
 
749
752
  // ---- Routing helpers ----
@@ -159,12 +159,14 @@ export function useEdgeRouting(
159
159
 
160
160
  const setRoutes = useEdgeRoutingStore((s) => s.setRoutes);
161
161
  const setConnectorType = useEdgeRoutingStore((s) => s.setConnectorType);
162
+ const setStubSize = useEdgeRoutingStore((s) => s.setStubSize);
162
163
  const setDraggingNodeIds = useEdgeRoutingStore((s) => s.setDraggingNodeIds);
163
164
  const setActions = useEdgeRoutingActionsStore((s) => s.setActions);
164
165
 
165
- // Keep store in sync with current connector type
166
+ // Keep store in sync with current connector type and stub size
166
167
  const connType = opts.connectorType ?? "orthogonal";
167
168
  if (connType) setConnectorType(connType);
169
+ setStubSize(opts.stubSize ?? 20);
168
170
 
169
171
  const { post, workerLoaded } = useRoutingWorker({ create: true });
170
172