reactflow-edge-routing 0.1.1 → 0.1.2
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 +1 -1
- package/src/routing-core.ts +14 -6
- package/src/use-edge-routing.ts +3 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "reactflow-edge-routing",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
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",
|
package/src/routing-core.ts
CHANGED
|
@@ -748,7 +748,10 @@ function createConnections(
|
|
|
748
748
|
|
|
749
749
|
if (splitNearHandle) {
|
|
750
750
|
// Pin-based: edges spread out along the node border near handles
|
|
751
|
-
|
|
751
|
+
// When autoBestSide is on, ignore explicit sourceHandle/targetHandle on edges
|
|
752
|
+
// and let the router pick the optimal side. Only use explicit handles when
|
|
753
|
+
// autoBestSide is off (pin-based routing with fixed handle positions).
|
|
754
|
+
const srcHandle = autoBestSide ? null : (edge.sourceHandle ?? findDefaultHandle(src, "source"));
|
|
752
755
|
if (srcShapeRef && srcHandle) {
|
|
753
756
|
const pinId = pinRegistry.getOrCreate(edge.source, srcHandle);
|
|
754
757
|
srcEnd = AvoidConnEnd.fromShapePin(srcShapeRef as any, pinId);
|
|
@@ -759,7 +762,7 @@ function createConnections(
|
|
|
759
762
|
srcEnd = (() => { const pt = Geometry.getHandlePoint(srcBounds, side); return AvoidConnEnd.fromPoint(new AvoidPoint(pt.x, pt.y)); })();
|
|
760
763
|
}
|
|
761
764
|
|
|
762
|
-
const tgtHandle =
|
|
765
|
+
const tgtHandle = autoBestSide ? null : (edge.targetHandle ?? findDefaultHandle(tgt, "target"));
|
|
763
766
|
if (tgtShapeRef && tgtHandle) {
|
|
764
767
|
const pinId = pinRegistry.getOrCreate(edge.target, tgtHandle);
|
|
765
768
|
tgtEnd = AvoidConnEnd.fromShapePin(tgtShapeRef as any, pinId);
|
|
@@ -848,9 +851,14 @@ export class RoutingEngine {
|
|
|
848
851
|
}
|
|
849
852
|
}
|
|
850
853
|
|
|
851
|
-
// Adjust spacing at shared handles (fan-out effect)
|
|
854
|
+
// Adjust spacing at shared handles (fan-out effect).
|
|
855
|
+
// Only for splitNearHandle=false (convergence mode): edges all start from the same center
|
|
856
|
+
// point, libavoid nudges them apart by idealNudgingDistance, and HandleSpacing.adjust scales
|
|
857
|
+
// that spread by handleNudging/idealNudging → final fan-out = handleNudging (clean decoupling).
|
|
858
|
+
// For splitNearHandle=true (pin-based), pins already fix the fan-out; scaling would incorrectly
|
|
859
|
+
// compress or expand existing pin spread, causing edgeToEdgeSpacing to reduce visible spacing.
|
|
852
860
|
const splitNearHandle = opts.shouldSplitEdgesNearHandle ?? true;
|
|
853
|
-
if (splitNearHandle) {
|
|
861
|
+
if (!splitNearHandle) {
|
|
854
862
|
const idealNudging = opts.idealNudgingDistance ?? 10;
|
|
855
863
|
const handleNudging = opts.handleNudgingDistance ?? idealNudging;
|
|
856
864
|
if (handleNudging !== idealNudging && edgePoints.size > 0) {
|
|
@@ -1022,9 +1030,9 @@ export class PersistentRouter {
|
|
|
1022
1030
|
}
|
|
1023
1031
|
}
|
|
1024
1032
|
|
|
1025
|
-
// Adjust spacing at shared handles (fan-out effect) —
|
|
1033
|
+
// Adjust spacing at shared handles (fan-out effect) — only for splitNearHandle=false (convergence mode)
|
|
1026
1034
|
const splitNearHandle = opts.shouldSplitEdgesNearHandle ?? true;
|
|
1027
|
-
if (splitNearHandle && handleNudging !== idealNudging && edgePoints.size > 0) {
|
|
1035
|
+
if (!splitNearHandle && handleNudging !== idealNudging && edgePoints.size > 0) {
|
|
1028
1036
|
HandleSpacing.adjust(this.prevEdges, edgePoints, handleNudging, idealNudging);
|
|
1029
1037
|
}
|
|
1030
1038
|
|
package/src/use-edge-routing.ts
CHANGED
|
@@ -130,7 +130,9 @@ function toRouterOptions(opts?: UseEdgeRoutingOptions): AvoidRouterOptions {
|
|
|
130
130
|
diagramGridSize: opts?.diagramGridSize ?? DEFAULT_OPTIONS.diagramGridSize,
|
|
131
131
|
shouldSplitEdgesNearHandle: opts?.shouldSplitEdgesNearHandle ?? DEFAULT_OPTIONS.shouldSplitEdgesNearHandle,
|
|
132
132
|
stubSize: opts?.stubSize,
|
|
133
|
-
autoBestSideConnection:
|
|
133
|
+
// bezier defaults to autoBestSideConnection: true — explicit handles
|
|
134
|
+
// make no visual sense on curved paths, so auto-side is the right default.
|
|
135
|
+
autoBestSideConnection: opts?.autoBestSideConnection ?? (opts?.connectorType === "bezier" ? true : DEFAULT_OPTIONS.autoBestSideConnection),
|
|
134
136
|
debounceMs: opts?.debounceMs ?? DEFAULT_OPTIONS.debounceMs,
|
|
135
137
|
};
|
|
136
138
|
}
|