@xyflow/system 0.0.53 → 0.0.55
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/dist/esm/index.js +73 -60
- package/dist/esm/index.mjs +73 -60
- package/dist/esm/types/edges.d.ts +13 -16
- package/dist/esm/types/edges.d.ts.map +1 -1
- package/dist/esm/types/general.d.ts +17 -0
- package/dist/esm/types/general.d.ts.map +1 -1
- package/dist/esm/types/handles.d.ts +23 -9
- package/dist/esm/types/handles.d.ts.map +1 -1
- package/dist/esm/types/nodes.d.ts +24 -14
- package/dist/esm/types/nodes.d.ts.map +1 -1
- package/dist/esm/utils/edges/bezier-edge.d.ts +25 -8
- package/dist/esm/utils/edges/bezier-edge.d.ts.map +1 -1
- package/dist/esm/utils/edges/general.d.ts +11 -8
- package/dist/esm/utils/edges/general.d.ts.map +1 -1
- package/dist/esm/utils/edges/smoothstep-edge.d.ts +26 -9
- package/dist/esm/utils/edges/smoothstep-edge.d.ts.map +1 -1
- package/dist/esm/utils/edges/straight-edge.d.ts +14 -5
- package/dist/esm/utils/edges/straight-edge.d.ts.map +1 -1
- package/dist/esm/utils/general.d.ts +8 -8
- package/dist/esm/utils/graph.d.ts +19 -16
- package/dist/esm/utils/graph.d.ts.map +1 -1
- package/dist/esm/xypanzoom/eventhandler.d.ts.map +1 -1
- package/dist/esm/xyresizer/XYResizer.d.ts +1 -1
- package/dist/esm/xyresizer/XYResizer.d.ts.map +1 -1
- package/dist/umd/index.js +1 -1
- package/dist/umd/types/edges.d.ts +13 -16
- package/dist/umd/types/edges.d.ts.map +1 -1
- package/dist/umd/types/general.d.ts +17 -0
- package/dist/umd/types/general.d.ts.map +1 -1
- package/dist/umd/types/handles.d.ts +23 -9
- package/dist/umd/types/handles.d.ts.map +1 -1
- package/dist/umd/types/nodes.d.ts +24 -14
- package/dist/umd/types/nodes.d.ts.map +1 -1
- package/dist/umd/utils/edges/bezier-edge.d.ts +25 -8
- package/dist/umd/utils/edges/bezier-edge.d.ts.map +1 -1
- package/dist/umd/utils/edges/general.d.ts +11 -8
- package/dist/umd/utils/edges/general.d.ts.map +1 -1
- package/dist/umd/utils/edges/smoothstep-edge.d.ts +26 -9
- package/dist/umd/utils/edges/smoothstep-edge.d.ts.map +1 -1
- package/dist/umd/utils/edges/straight-edge.d.ts +14 -5
- package/dist/umd/utils/edges/straight-edge.d.ts.map +1 -1
- package/dist/umd/utils/general.d.ts +8 -8
- package/dist/umd/utils/graph.d.ts +19 -16
- package/dist/umd/utils/graph.d.ts.map +1 -1
- package/dist/umd/xypanzoom/eventhandler.d.ts.map +1 -1
- package/dist/umd/xyresizer/XYResizer.d.ts +1 -1
- package/dist/umd/xyresizer/XYResizer.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/esm/index.js
CHANGED
|
@@ -165,7 +165,7 @@ function getConnectionStatus(isValid) {
|
|
|
165
165
|
|
|
166
166
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
167
167
|
/**
|
|
168
|
-
* Test whether an object is
|
|
168
|
+
* Test whether an object is usable as an Edge
|
|
169
169
|
* @public
|
|
170
170
|
* @remarks In TypeScript this is a type guard that will narrow the type of whatever you pass in to Edge if it returns true
|
|
171
171
|
* @param element - The element to test
|
|
@@ -173,7 +173,7 @@ function getConnectionStatus(isValid) {
|
|
|
173
173
|
*/
|
|
174
174
|
const isEdgeBase = (element) => 'id' in element && 'source' in element && 'target' in element;
|
|
175
175
|
/**
|
|
176
|
-
* Test whether an object is
|
|
176
|
+
* Test whether an object is usable as a Node
|
|
177
177
|
* @public
|
|
178
178
|
* @remarks In TypeScript this is a type guard that will narrow the type of whatever you pass in to Node if it returns true
|
|
179
179
|
* @param element - The element to test
|
|
@@ -185,10 +185,10 @@ const isInternalNodeBase = (element) => 'id' in element && 'internals' in elemen
|
|
|
185
185
|
* This util is used to tell you what nodes, if any, are connected to the given node
|
|
186
186
|
* as the _target_ of an edge.
|
|
187
187
|
* @public
|
|
188
|
-
* @param node - The node to get the connected nodes from
|
|
189
|
-
* @param nodes - The array of all nodes
|
|
190
|
-
* @param edges - The array of all edges
|
|
191
|
-
* @returns An array of nodes that are connected over
|
|
188
|
+
* @param node - The node to get the connected nodes from.
|
|
189
|
+
* @param nodes - The array of all nodes.
|
|
190
|
+
* @param edges - The array of all edges.
|
|
191
|
+
* @returns An array of nodes that are connected over edges where the source is the given node.
|
|
192
192
|
*
|
|
193
193
|
* @example
|
|
194
194
|
* ```ts
|
|
@@ -220,10 +220,10 @@ const getOutgoers = (node, nodes, edges) => {
|
|
|
220
220
|
* This util is used to tell you what nodes, if any, are connected to the given node
|
|
221
221
|
* as the _source_ of an edge.
|
|
222
222
|
* @public
|
|
223
|
-
* @param node - The node to get the connected nodes from
|
|
224
|
-
* @param nodes - The array of all nodes
|
|
225
|
-
* @param edges - The array of all edges
|
|
226
|
-
* @returns An array of nodes that are connected over
|
|
223
|
+
* @param node - The node to get the connected nodes from.
|
|
224
|
+
* @param nodes - The array of all nodes.
|
|
225
|
+
* @param edges - The array of all edges.
|
|
226
|
+
* @returns An array of nodes that are connected over edges where the target is the given node.
|
|
227
227
|
*
|
|
228
228
|
* @example
|
|
229
229
|
* ```ts
|
|
@@ -267,9 +267,8 @@ const getNodePositionWithOrigin = (node, nodeOrigin = [0, 0]) => {
|
|
|
267
267
|
* to calculate the correct transform to fit the given nodes in a viewport.
|
|
268
268
|
* @public
|
|
269
269
|
* @remarks Useful when combined with {@link getViewportForBounds} to calculate the correct transform to fit the given nodes in a viewport.
|
|
270
|
-
* @param nodes - Nodes to calculate the bounds for
|
|
271
|
-
* @
|
|
272
|
-
* @returns Bounding box enclosing all nodes
|
|
270
|
+
* @param nodes - Nodes to calculate the bounds for.
|
|
271
|
+
* @returns Bounding box enclosing all nodes.
|
|
273
272
|
*
|
|
274
273
|
* @remarks This function was previously called `getRectOfNodes`
|
|
275
274
|
*
|
|
@@ -297,7 +296,7 @@ const getNodePositionWithOrigin = (node, nodeOrigin = [0, 0]) => {
|
|
|
297
296
|
*const bounds = getNodesBounds(nodes);
|
|
298
297
|
*```
|
|
299
298
|
*/
|
|
300
|
-
const getNodesBounds = (nodes, params = { nodeOrigin: [0, 0]
|
|
299
|
+
const getNodesBounds = (nodes, params = { nodeOrigin: [0, 0] }) => {
|
|
301
300
|
if (process.env.NODE_ENV === 'development' && !params.nodeLookup) {
|
|
302
301
|
console.warn('Please use `getNodesBounds` from `useReactFlow`/`useSvelteFlow` hook to ensure correct values for sub flows. If not possible, you have to provide a nodeLookup to support sub flows.');
|
|
303
302
|
}
|
|
@@ -367,9 +366,9 @@ excludeNonSelectableNodes = false) => {
|
|
|
367
366
|
* This utility filters an array of edges, keeping only those where either the source or target
|
|
368
367
|
* node is present in the given array of nodes.
|
|
369
368
|
* @public
|
|
370
|
-
* @param nodes - Nodes you want to get the connected edges for
|
|
371
|
-
* @param edges - All edges
|
|
372
|
-
* @returns Array of edges that connect any of the given nodes with each other
|
|
369
|
+
* @param nodes - Nodes you want to get the connected edges for.
|
|
370
|
+
* @param edges - All edges.
|
|
371
|
+
* @returns Array of edges that connect any of the given nodes with each other.
|
|
373
372
|
*
|
|
374
373
|
* @example
|
|
375
374
|
* ```js
|
|
@@ -703,16 +702,16 @@ function calculateAppliedPaddings(bounds, x, y, zoom, width, height) {
|
|
|
703
702
|
};
|
|
704
703
|
}
|
|
705
704
|
/**
|
|
706
|
-
* Returns a viewport that encloses the given bounds with
|
|
705
|
+
* Returns a viewport that encloses the given bounds with padding.
|
|
707
706
|
* @public
|
|
708
707
|
* @remarks You can determine bounds of nodes with {@link getNodesBounds} and {@link getBoundsOfRects}
|
|
709
|
-
* @param bounds - Bounds to fit inside viewport
|
|
710
|
-
* @param width - Width of the viewport
|
|
711
|
-
* @param height - Height of the viewport
|
|
712
|
-
* @param minZoom - Minimum zoom level of the resulting viewport
|
|
713
|
-
* @param maxZoom - Maximum zoom level of the resulting viewport
|
|
714
|
-
* @param padding -
|
|
715
|
-
* @returns A
|
|
708
|
+
* @param bounds - Bounds to fit inside viewport.
|
|
709
|
+
* @param width - Width of the viewport.
|
|
710
|
+
* @param height - Height of the viewport.
|
|
711
|
+
* @param minZoom - Minimum zoom level of the resulting viewport.
|
|
712
|
+
* @param maxZoom - Maximum zoom level of the resulting viewport.
|
|
713
|
+
* @param padding - Padding around the bounds.
|
|
714
|
+
* @returns A transformed {@link Viewport} that encloses the given bounds which you can pass to e.g. {@link setViewport}.
|
|
716
715
|
* @example
|
|
717
716
|
* const { x, y, zoom } = getViewportForBounds(
|
|
718
717
|
* { x: 0, y: 0, width: 100, height: 100},
|
|
@@ -884,14 +883,15 @@ function getControlWithCurvature({ pos, x1, y1, x2, y2, c }) {
|
|
|
884
883
|
* The `getBezierPath` util returns everything you need to render a bezier edge
|
|
885
884
|
*between two nodes.
|
|
886
885
|
* @public
|
|
887
|
-
* @
|
|
888
|
-
*
|
|
889
|
-
*
|
|
890
|
-
*
|
|
891
|
-
*
|
|
892
|
-
*
|
|
893
|
-
*
|
|
894
|
-
*
|
|
886
|
+
* @returns A path string you can use in an SVG, the `labelX` and `labelY` position (center of path)
|
|
887
|
+
* and `offsetX`, `offsetY` between source handle and label.
|
|
888
|
+
* - `path`: the path to use in an SVG `<path>` element.
|
|
889
|
+
* - `labelX`: the `x` position you can use to render a label for this edge.
|
|
890
|
+
* - `labelY`: the `y` position you can use to render a label for this edge.
|
|
891
|
+
* - `offsetX`: the absolute difference between the source `x` position and the `x` position of the
|
|
892
|
+
* middle of this path.
|
|
893
|
+
* - `offsetY`: the absolute difference between the source `y` position and the `y` position of the
|
|
894
|
+
* middle of this path.
|
|
895
895
|
* @example
|
|
896
896
|
* ```js
|
|
897
897
|
* const source = { x: 0, y: 20 };
|
|
@@ -988,9 +988,9 @@ const connectionExists = (edge, edges) => {
|
|
|
988
988
|
/**
|
|
989
989
|
* This util is a convenience function to add a new Edge to an array of edges. It also performs some validation to make sure you don't add an invalid edge or duplicate an existing one.
|
|
990
990
|
* @public
|
|
991
|
-
* @param edgeParams - Either an Edge or a Connection you want to add
|
|
992
|
-
* @param edges -
|
|
993
|
-
* @returns A new array of edges with the new edge added
|
|
991
|
+
* @param edgeParams - Either an `Edge` or a `Connection` you want to add.
|
|
992
|
+
* @param edges - The array of all current edges.
|
|
993
|
+
* @returns A new array of edges with the new edge added.
|
|
994
994
|
*
|
|
995
995
|
* @remarks If an edge with the same `target` and `source` already exists (and the same
|
|
996
996
|
*`targetHandle` and `sourceHandle` if those are set), then this util won't add
|
|
@@ -1028,11 +1028,10 @@ const addEdge = (edgeParams, edges) => {
|
|
|
1028
1028
|
*This searches your edge array for an edge with a matching `id` and updates its
|
|
1029
1029
|
*properties with the connection you provide.
|
|
1030
1030
|
* @public
|
|
1031
|
-
* @param oldEdge - The edge you want to update
|
|
1032
|
-
* @param newConnection - The new connection you want to update the edge with
|
|
1033
|
-
* @param edges - The array of all current edges
|
|
1034
|
-
* @
|
|
1035
|
-
* @returns the updated edges array
|
|
1031
|
+
* @param oldEdge - The edge you want to update.
|
|
1032
|
+
* @param newConnection - The new connection you want to update the edge with.
|
|
1033
|
+
* @param edges - The array of all current edges.
|
|
1034
|
+
* @returns The updated edges array.
|
|
1036
1035
|
*
|
|
1037
1036
|
* @example
|
|
1038
1037
|
* ```js
|
|
@@ -1066,11 +1065,16 @@ const reconnectEdge = (oldEdge, newConnection, edges, options = { shouldReplaceI
|
|
|
1066
1065
|
/**
|
|
1067
1066
|
* Calculates the straight line path between two points.
|
|
1068
1067
|
* @public
|
|
1069
|
-
* @
|
|
1070
|
-
*
|
|
1071
|
-
*
|
|
1072
|
-
*
|
|
1073
|
-
*
|
|
1068
|
+
* @returns A path string you can use in an SVG, the `labelX` and `labelY` position (center of path)
|
|
1069
|
+
* and `offsetX`, `offsetY` between source handle and label.
|
|
1070
|
+
*
|
|
1071
|
+
* - `path`: the path to use in an SVG `<path>` element.
|
|
1072
|
+
* - `labelX`: the `x` position you can use to render a label for this edge.
|
|
1073
|
+
* - `labelY`: the `y` position you can use to render a label for this edge.
|
|
1074
|
+
* - `offsetX`: the absolute difference between the source `x` position and the `x` position of the
|
|
1075
|
+
* middle of this path.
|
|
1076
|
+
* - `offsetY`: the absolute difference between the source `y` position and the `y` position of the
|
|
1077
|
+
* middle of this path.
|
|
1074
1078
|
* @example
|
|
1075
1079
|
* ```js
|
|
1076
1080
|
* const source = { x: 0, y: 20 };
|
|
@@ -1111,8 +1115,8 @@ const getDirection = ({ source, sourcePosition = Position.Bottom, target, }) =>
|
|
|
1111
1115
|
};
|
|
1112
1116
|
const distance = (a, b) => Math.sqrt(Math.pow(b.x - a.x, 2) + Math.pow(b.y - a.y, 2));
|
|
1113
1117
|
/*
|
|
1114
|
-
*
|
|
1115
|
-
* It's not as good as a real orthogonal edge routing but it's faster and good enough as a default for step and smooth step edges
|
|
1118
|
+
* With this function we try to mimic an orthogonal edge routing behaviour
|
|
1119
|
+
* It's not as good as a real orthogonal edge routing, but it's faster and good enough as a default for step and smooth step edges
|
|
1116
1120
|
*/
|
|
1117
1121
|
function getPoints({ source, sourcePosition = Position.Bottom, target, targetPosition = Position.Top, center, offset, }) {
|
|
1118
1122
|
const sourceDir = handleDirections[sourcePosition];
|
|
@@ -1243,16 +1247,19 @@ function getBend(a, b, c, size) {
|
|
|
1243
1247
|
}
|
|
1244
1248
|
/**
|
|
1245
1249
|
* The `getSmoothStepPath` util returns everything you need to render a stepped path
|
|
1246
|
-
*between two nodes. The `borderRadius` property can be used to choose how rounded
|
|
1247
|
-
*the corners of those steps are.
|
|
1250
|
+
* between two nodes. The `borderRadius` property can be used to choose how rounded
|
|
1251
|
+
* the corners of those steps are.
|
|
1248
1252
|
* @public
|
|
1249
|
-
* @
|
|
1250
|
-
*
|
|
1251
|
-
*
|
|
1252
|
-
*
|
|
1253
|
-
*
|
|
1254
|
-
*
|
|
1255
|
-
*
|
|
1253
|
+
* @returns A path string you can use in an SVG, the `labelX` and `labelY` position (center of path)
|
|
1254
|
+
* and `offsetX`, `offsetY` between source handle and label.
|
|
1255
|
+
*
|
|
1256
|
+
* - `path`: the path to use in an SVG `<path>` element.
|
|
1257
|
+
* - `labelX`: the `x` position you can use to render a label for this edge.
|
|
1258
|
+
* - `labelY`: the `y` position you can use to render a label for this edge.
|
|
1259
|
+
* - `offsetX`: the absolute difference between the source `x` position and the `x` position of the
|
|
1260
|
+
* middle of this path.
|
|
1261
|
+
* - `offsetY`: the absolute difference between the source `y` position and the `y` position of the
|
|
1262
|
+
* middle of this path.
|
|
1256
1263
|
* @example
|
|
1257
1264
|
* ```js
|
|
1258
1265
|
* const source = { x: 0, y: 20 };
|
|
@@ -2560,9 +2567,15 @@ function createPanOnScrollHandler({ zoomPanValues, noWheelClassName, d3Selection
|
|
|
2560
2567
|
}
|
|
2561
2568
|
function createZoomOnScrollHandler({ noWheelClassName, preventScrolling, d3ZoomHandler }) {
|
|
2562
2569
|
return function (event, d) {
|
|
2570
|
+
const isWheel = event.type === 'wheel';
|
|
2563
2571
|
// we still want to enable pinch zooming even if preventScrolling is set to false
|
|
2564
|
-
const preventZoom = !preventScrolling &&
|
|
2565
|
-
|
|
2572
|
+
const preventZoom = !preventScrolling && isWheel && !event.ctrlKey;
|
|
2573
|
+
const hasNoWheelClass = isWrappedWithClass(event, noWheelClassName);
|
|
2574
|
+
// if user is pinch zooming above a nowheel element, we don't want the browser to zoom
|
|
2575
|
+
if (event.ctrlKey && isWheel && hasNoWheelClass) {
|
|
2576
|
+
event.preventDefault();
|
|
2577
|
+
}
|
|
2578
|
+
if (preventZoom || hasNoWheelClass) {
|
|
2566
2579
|
return null;
|
|
2567
2580
|
}
|
|
2568
2581
|
event.preventDefault();
|
|
@@ -3275,7 +3288,7 @@ function XYResizer({ domNode, nodeId, getStoreItems, onChange, onEnd }) {
|
|
|
3275
3288
|
})
|
|
3276
3289
|
.on('end', (event) => {
|
|
3277
3290
|
onResizeEnd?.(event, { ...prevValues });
|
|
3278
|
-
onEnd?.();
|
|
3291
|
+
onEnd?.({ ...prevValues });
|
|
3279
3292
|
});
|
|
3280
3293
|
selection.call(dragHandler);
|
|
3281
3294
|
}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -165,7 +165,7 @@ function getConnectionStatus(isValid) {
|
|
|
165
165
|
|
|
166
166
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
167
167
|
/**
|
|
168
|
-
* Test whether an object is
|
|
168
|
+
* Test whether an object is usable as an Edge
|
|
169
169
|
* @public
|
|
170
170
|
* @remarks In TypeScript this is a type guard that will narrow the type of whatever you pass in to Edge if it returns true
|
|
171
171
|
* @param element - The element to test
|
|
@@ -173,7 +173,7 @@ function getConnectionStatus(isValid) {
|
|
|
173
173
|
*/
|
|
174
174
|
const isEdgeBase = (element) => 'id' in element && 'source' in element && 'target' in element;
|
|
175
175
|
/**
|
|
176
|
-
* Test whether an object is
|
|
176
|
+
* Test whether an object is usable as a Node
|
|
177
177
|
* @public
|
|
178
178
|
* @remarks In TypeScript this is a type guard that will narrow the type of whatever you pass in to Node if it returns true
|
|
179
179
|
* @param element - The element to test
|
|
@@ -185,10 +185,10 @@ const isInternalNodeBase = (element) => 'id' in element && 'internals' in elemen
|
|
|
185
185
|
* This util is used to tell you what nodes, if any, are connected to the given node
|
|
186
186
|
* as the _target_ of an edge.
|
|
187
187
|
* @public
|
|
188
|
-
* @param node - The node to get the connected nodes from
|
|
189
|
-
* @param nodes - The array of all nodes
|
|
190
|
-
* @param edges - The array of all edges
|
|
191
|
-
* @returns An array of nodes that are connected over
|
|
188
|
+
* @param node - The node to get the connected nodes from.
|
|
189
|
+
* @param nodes - The array of all nodes.
|
|
190
|
+
* @param edges - The array of all edges.
|
|
191
|
+
* @returns An array of nodes that are connected over edges where the source is the given node.
|
|
192
192
|
*
|
|
193
193
|
* @example
|
|
194
194
|
* ```ts
|
|
@@ -220,10 +220,10 @@ const getOutgoers = (node, nodes, edges) => {
|
|
|
220
220
|
* This util is used to tell you what nodes, if any, are connected to the given node
|
|
221
221
|
* as the _source_ of an edge.
|
|
222
222
|
* @public
|
|
223
|
-
* @param node - The node to get the connected nodes from
|
|
224
|
-
* @param nodes - The array of all nodes
|
|
225
|
-
* @param edges - The array of all edges
|
|
226
|
-
* @returns An array of nodes that are connected over
|
|
223
|
+
* @param node - The node to get the connected nodes from.
|
|
224
|
+
* @param nodes - The array of all nodes.
|
|
225
|
+
* @param edges - The array of all edges.
|
|
226
|
+
* @returns An array of nodes that are connected over edges where the target is the given node.
|
|
227
227
|
*
|
|
228
228
|
* @example
|
|
229
229
|
* ```ts
|
|
@@ -267,9 +267,8 @@ const getNodePositionWithOrigin = (node, nodeOrigin = [0, 0]) => {
|
|
|
267
267
|
* to calculate the correct transform to fit the given nodes in a viewport.
|
|
268
268
|
* @public
|
|
269
269
|
* @remarks Useful when combined with {@link getViewportForBounds} to calculate the correct transform to fit the given nodes in a viewport.
|
|
270
|
-
* @param nodes - Nodes to calculate the bounds for
|
|
271
|
-
* @
|
|
272
|
-
* @returns Bounding box enclosing all nodes
|
|
270
|
+
* @param nodes - Nodes to calculate the bounds for.
|
|
271
|
+
* @returns Bounding box enclosing all nodes.
|
|
273
272
|
*
|
|
274
273
|
* @remarks This function was previously called `getRectOfNodes`
|
|
275
274
|
*
|
|
@@ -297,7 +296,7 @@ const getNodePositionWithOrigin = (node, nodeOrigin = [0, 0]) => {
|
|
|
297
296
|
*const bounds = getNodesBounds(nodes);
|
|
298
297
|
*```
|
|
299
298
|
*/
|
|
300
|
-
const getNodesBounds = (nodes, params = { nodeOrigin: [0, 0]
|
|
299
|
+
const getNodesBounds = (nodes, params = { nodeOrigin: [0, 0] }) => {
|
|
301
300
|
if (process.env.NODE_ENV === 'development' && !params.nodeLookup) {
|
|
302
301
|
console.warn('Please use `getNodesBounds` from `useReactFlow`/`useSvelteFlow` hook to ensure correct values for sub flows. If not possible, you have to provide a nodeLookup to support sub flows.');
|
|
303
302
|
}
|
|
@@ -367,9 +366,9 @@ excludeNonSelectableNodes = false) => {
|
|
|
367
366
|
* This utility filters an array of edges, keeping only those where either the source or target
|
|
368
367
|
* node is present in the given array of nodes.
|
|
369
368
|
* @public
|
|
370
|
-
* @param nodes - Nodes you want to get the connected edges for
|
|
371
|
-
* @param edges - All edges
|
|
372
|
-
* @returns Array of edges that connect any of the given nodes with each other
|
|
369
|
+
* @param nodes - Nodes you want to get the connected edges for.
|
|
370
|
+
* @param edges - All edges.
|
|
371
|
+
* @returns Array of edges that connect any of the given nodes with each other.
|
|
373
372
|
*
|
|
374
373
|
* @example
|
|
375
374
|
* ```js
|
|
@@ -703,16 +702,16 @@ function calculateAppliedPaddings(bounds, x, y, zoom, width, height) {
|
|
|
703
702
|
};
|
|
704
703
|
}
|
|
705
704
|
/**
|
|
706
|
-
* Returns a viewport that encloses the given bounds with
|
|
705
|
+
* Returns a viewport that encloses the given bounds with padding.
|
|
707
706
|
* @public
|
|
708
707
|
* @remarks You can determine bounds of nodes with {@link getNodesBounds} and {@link getBoundsOfRects}
|
|
709
|
-
* @param bounds - Bounds to fit inside viewport
|
|
710
|
-
* @param width - Width of the viewport
|
|
711
|
-
* @param height - Height of the viewport
|
|
712
|
-
* @param minZoom - Minimum zoom level of the resulting viewport
|
|
713
|
-
* @param maxZoom - Maximum zoom level of the resulting viewport
|
|
714
|
-
* @param padding -
|
|
715
|
-
* @returns A
|
|
708
|
+
* @param bounds - Bounds to fit inside viewport.
|
|
709
|
+
* @param width - Width of the viewport.
|
|
710
|
+
* @param height - Height of the viewport.
|
|
711
|
+
* @param minZoom - Minimum zoom level of the resulting viewport.
|
|
712
|
+
* @param maxZoom - Maximum zoom level of the resulting viewport.
|
|
713
|
+
* @param padding - Padding around the bounds.
|
|
714
|
+
* @returns A transformed {@link Viewport} that encloses the given bounds which you can pass to e.g. {@link setViewport}.
|
|
716
715
|
* @example
|
|
717
716
|
* const { x, y, zoom } = getViewportForBounds(
|
|
718
717
|
* { x: 0, y: 0, width: 100, height: 100},
|
|
@@ -884,14 +883,15 @@ function getControlWithCurvature({ pos, x1, y1, x2, y2, c }) {
|
|
|
884
883
|
* The `getBezierPath` util returns everything you need to render a bezier edge
|
|
885
884
|
*between two nodes.
|
|
886
885
|
* @public
|
|
887
|
-
* @
|
|
888
|
-
*
|
|
889
|
-
*
|
|
890
|
-
*
|
|
891
|
-
*
|
|
892
|
-
*
|
|
893
|
-
*
|
|
894
|
-
*
|
|
886
|
+
* @returns A path string you can use in an SVG, the `labelX` and `labelY` position (center of path)
|
|
887
|
+
* and `offsetX`, `offsetY` between source handle and label.
|
|
888
|
+
* - `path`: the path to use in an SVG `<path>` element.
|
|
889
|
+
* - `labelX`: the `x` position you can use to render a label for this edge.
|
|
890
|
+
* - `labelY`: the `y` position you can use to render a label for this edge.
|
|
891
|
+
* - `offsetX`: the absolute difference between the source `x` position and the `x` position of the
|
|
892
|
+
* middle of this path.
|
|
893
|
+
* - `offsetY`: the absolute difference between the source `y` position and the `y` position of the
|
|
894
|
+
* middle of this path.
|
|
895
895
|
* @example
|
|
896
896
|
* ```js
|
|
897
897
|
* const source = { x: 0, y: 20 };
|
|
@@ -988,9 +988,9 @@ const connectionExists = (edge, edges) => {
|
|
|
988
988
|
/**
|
|
989
989
|
* This util is a convenience function to add a new Edge to an array of edges. It also performs some validation to make sure you don't add an invalid edge or duplicate an existing one.
|
|
990
990
|
* @public
|
|
991
|
-
* @param edgeParams - Either an Edge or a Connection you want to add
|
|
992
|
-
* @param edges -
|
|
993
|
-
* @returns A new array of edges with the new edge added
|
|
991
|
+
* @param edgeParams - Either an `Edge` or a `Connection` you want to add.
|
|
992
|
+
* @param edges - The array of all current edges.
|
|
993
|
+
* @returns A new array of edges with the new edge added.
|
|
994
994
|
*
|
|
995
995
|
* @remarks If an edge with the same `target` and `source` already exists (and the same
|
|
996
996
|
*`targetHandle` and `sourceHandle` if those are set), then this util won't add
|
|
@@ -1028,11 +1028,10 @@ const addEdge = (edgeParams, edges) => {
|
|
|
1028
1028
|
*This searches your edge array for an edge with a matching `id` and updates its
|
|
1029
1029
|
*properties with the connection you provide.
|
|
1030
1030
|
* @public
|
|
1031
|
-
* @param oldEdge - The edge you want to update
|
|
1032
|
-
* @param newConnection - The new connection you want to update the edge with
|
|
1033
|
-
* @param edges - The array of all current edges
|
|
1034
|
-
* @
|
|
1035
|
-
* @returns the updated edges array
|
|
1031
|
+
* @param oldEdge - The edge you want to update.
|
|
1032
|
+
* @param newConnection - The new connection you want to update the edge with.
|
|
1033
|
+
* @param edges - The array of all current edges.
|
|
1034
|
+
* @returns The updated edges array.
|
|
1036
1035
|
*
|
|
1037
1036
|
* @example
|
|
1038
1037
|
* ```js
|
|
@@ -1066,11 +1065,16 @@ const reconnectEdge = (oldEdge, newConnection, edges, options = { shouldReplaceI
|
|
|
1066
1065
|
/**
|
|
1067
1066
|
* Calculates the straight line path between two points.
|
|
1068
1067
|
* @public
|
|
1069
|
-
* @
|
|
1070
|
-
*
|
|
1071
|
-
*
|
|
1072
|
-
*
|
|
1073
|
-
*
|
|
1068
|
+
* @returns A path string you can use in an SVG, the `labelX` and `labelY` position (center of path)
|
|
1069
|
+
* and `offsetX`, `offsetY` between source handle and label.
|
|
1070
|
+
*
|
|
1071
|
+
* - `path`: the path to use in an SVG `<path>` element.
|
|
1072
|
+
* - `labelX`: the `x` position you can use to render a label for this edge.
|
|
1073
|
+
* - `labelY`: the `y` position you can use to render a label for this edge.
|
|
1074
|
+
* - `offsetX`: the absolute difference between the source `x` position and the `x` position of the
|
|
1075
|
+
* middle of this path.
|
|
1076
|
+
* - `offsetY`: the absolute difference between the source `y` position and the `y` position of the
|
|
1077
|
+
* middle of this path.
|
|
1074
1078
|
* @example
|
|
1075
1079
|
* ```js
|
|
1076
1080
|
* const source = { x: 0, y: 20 };
|
|
@@ -1111,8 +1115,8 @@ const getDirection = ({ source, sourcePosition = Position.Bottom, target, }) =>
|
|
|
1111
1115
|
};
|
|
1112
1116
|
const distance = (a, b) => Math.sqrt(Math.pow(b.x - a.x, 2) + Math.pow(b.y - a.y, 2));
|
|
1113
1117
|
/*
|
|
1114
|
-
*
|
|
1115
|
-
* It's not as good as a real orthogonal edge routing but it's faster and good enough as a default for step and smooth step edges
|
|
1118
|
+
* With this function we try to mimic an orthogonal edge routing behaviour
|
|
1119
|
+
* It's not as good as a real orthogonal edge routing, but it's faster and good enough as a default for step and smooth step edges
|
|
1116
1120
|
*/
|
|
1117
1121
|
function getPoints({ source, sourcePosition = Position.Bottom, target, targetPosition = Position.Top, center, offset, }) {
|
|
1118
1122
|
const sourceDir = handleDirections[sourcePosition];
|
|
@@ -1243,16 +1247,19 @@ function getBend(a, b, c, size) {
|
|
|
1243
1247
|
}
|
|
1244
1248
|
/**
|
|
1245
1249
|
* The `getSmoothStepPath` util returns everything you need to render a stepped path
|
|
1246
|
-
*between two nodes. The `borderRadius` property can be used to choose how rounded
|
|
1247
|
-
*the corners of those steps are.
|
|
1250
|
+
* between two nodes. The `borderRadius` property can be used to choose how rounded
|
|
1251
|
+
* the corners of those steps are.
|
|
1248
1252
|
* @public
|
|
1249
|
-
* @
|
|
1250
|
-
*
|
|
1251
|
-
*
|
|
1252
|
-
*
|
|
1253
|
-
*
|
|
1254
|
-
*
|
|
1255
|
-
*
|
|
1253
|
+
* @returns A path string you can use in an SVG, the `labelX` and `labelY` position (center of path)
|
|
1254
|
+
* and `offsetX`, `offsetY` between source handle and label.
|
|
1255
|
+
*
|
|
1256
|
+
* - `path`: the path to use in an SVG `<path>` element.
|
|
1257
|
+
* - `labelX`: the `x` position you can use to render a label for this edge.
|
|
1258
|
+
* - `labelY`: the `y` position you can use to render a label for this edge.
|
|
1259
|
+
* - `offsetX`: the absolute difference between the source `x` position and the `x` position of the
|
|
1260
|
+
* middle of this path.
|
|
1261
|
+
* - `offsetY`: the absolute difference between the source `y` position and the `y` position of the
|
|
1262
|
+
* middle of this path.
|
|
1256
1263
|
* @example
|
|
1257
1264
|
* ```js
|
|
1258
1265
|
* const source = { x: 0, y: 20 };
|
|
@@ -2560,9 +2567,15 @@ function createPanOnScrollHandler({ zoomPanValues, noWheelClassName, d3Selection
|
|
|
2560
2567
|
}
|
|
2561
2568
|
function createZoomOnScrollHandler({ noWheelClassName, preventScrolling, d3ZoomHandler }) {
|
|
2562
2569
|
return function (event, d) {
|
|
2570
|
+
const isWheel = event.type === 'wheel';
|
|
2563
2571
|
// we still want to enable pinch zooming even if preventScrolling is set to false
|
|
2564
|
-
const preventZoom = !preventScrolling &&
|
|
2565
|
-
|
|
2572
|
+
const preventZoom = !preventScrolling && isWheel && !event.ctrlKey;
|
|
2573
|
+
const hasNoWheelClass = isWrappedWithClass(event, noWheelClassName);
|
|
2574
|
+
// if user is pinch zooming above a nowheel element, we don't want the browser to zoom
|
|
2575
|
+
if (event.ctrlKey && isWheel && hasNoWheelClass) {
|
|
2576
|
+
event.preventDefault();
|
|
2577
|
+
}
|
|
2578
|
+
if (preventZoom || hasNoWheelClass) {
|
|
2566
2579
|
return null;
|
|
2567
2580
|
}
|
|
2568
2581
|
event.preventDefault();
|
|
@@ -3275,7 +3288,7 @@ function XYResizer({ domNode, nodeId, getStoreItems, onChange, onEnd }) {
|
|
|
3275
3288
|
})
|
|
3276
3289
|
.on('end', (event) => {
|
|
3277
3290
|
onResizeEnd?.(event, { ...prevValues });
|
|
3278
|
-
onEnd?.();
|
|
3291
|
+
onEnd?.({ ...prevValues });
|
|
3279
3292
|
});
|
|
3280
3293
|
selection.call(dragHandler);
|
|
3281
3294
|
}
|
|
@@ -1,43 +1,40 @@
|
|
|
1
1
|
import { Position } from './utils';
|
|
2
2
|
export type EdgeBase<EdgeData extends Record<string, unknown> = Record<string, unknown>, EdgeType extends string | undefined = string | undefined> = {
|
|
3
|
-
/** Unique id of an edge */
|
|
3
|
+
/** Unique id of an edge. */
|
|
4
4
|
id: string;
|
|
5
|
-
/** Type of
|
|
5
|
+
/** Type of edge defined in `edgeTypes`. */
|
|
6
6
|
type?: EdgeType;
|
|
7
|
-
/** Id of source node */
|
|
7
|
+
/** Id of source node. */
|
|
8
8
|
source: string;
|
|
9
|
-
/** Id of target node */
|
|
9
|
+
/** Id of target node. */
|
|
10
10
|
target: string;
|
|
11
|
-
/**
|
|
12
|
-
* Id of source handle
|
|
13
|
-
* only needed if there are multiple handles per node
|
|
14
|
-
*/
|
|
11
|
+
/** Id of source handle, only needed if there are multiple handles per node. */
|
|
15
12
|
sourceHandle?: string | null;
|
|
16
|
-
/**
|
|
17
|
-
* Id of target handle
|
|
18
|
-
* only needed if there are multiple handles per node
|
|
19
|
-
*/
|
|
13
|
+
/** Id of target handle, only needed if there are multiple handles per node. */
|
|
20
14
|
targetHandle?: string | null;
|
|
21
15
|
animated?: boolean;
|
|
22
16
|
hidden?: boolean;
|
|
23
17
|
deletable?: boolean;
|
|
24
18
|
selectable?: boolean;
|
|
25
|
-
/** Arbitrary data passed to an edge */
|
|
19
|
+
/** Arbitrary data passed to an edge. */
|
|
26
20
|
data?: EdgeData;
|
|
27
21
|
selected?: boolean;
|
|
28
22
|
/**
|
|
29
|
-
* Set the marker on the beginning of an edge
|
|
23
|
+
* Set the marker on the beginning of an edge.
|
|
30
24
|
* @example 'arrow', 'arrowclosed' or custom marker
|
|
31
25
|
*/
|
|
32
26
|
markerStart?: EdgeMarkerType;
|
|
33
27
|
/**
|
|
34
|
-
* Set the marker on the end of an edge
|
|
28
|
+
* Set the marker on the end of an edge.
|
|
35
29
|
* @example 'arrow', 'arrowclosed' or custom marker
|
|
36
30
|
*/
|
|
37
31
|
markerEnd?: EdgeMarkerType;
|
|
38
32
|
zIndex?: number;
|
|
39
33
|
ariaLabel?: string;
|
|
40
|
-
/**
|
|
34
|
+
/**
|
|
35
|
+
* ReactFlow renders an invisible path around each edge to make them easier to click or tap on.
|
|
36
|
+
* This property sets the width of that invisible path.
|
|
37
|
+
*/
|
|
41
38
|
interactionWidth?: number;
|
|
42
39
|
};
|
|
43
40
|
export type SmoothStepPathOptions = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edges.d.ts","sourceRoot":"","sources":["../../src/types/edges.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SA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GAAG;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,QAAQ,CAAC;IACzB,cAAc,EAAE,QAAQ,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,UAAU,CAAC,QAAQ,SAAS,QAAQ,GAAG,QAAQ,IAAI,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC"}
|
|
@@ -25,9 +25,13 @@ export type FitBounds = (bounds: Rect, options?: FitBoundsOptions) => Promise<bo
|
|
|
25
25
|
* @public
|
|
26
26
|
*/
|
|
27
27
|
export type Connection = {
|
|
28
|
+
/** The id of the node this connection originates from. */
|
|
28
29
|
source: string;
|
|
30
|
+
/** The id of the node this connection terminates at. */
|
|
29
31
|
target: string;
|
|
32
|
+
/** When not `null`, the id of the handle on the source node that this connection originates from. */
|
|
30
33
|
sourceHandle: string | null;
|
|
34
|
+
/** When not `null`, the id of the handle on the target node that this connection terminates at. */
|
|
31
35
|
targetHandle: string | null;
|
|
32
36
|
};
|
|
33
37
|
/**
|
|
@@ -184,15 +188,28 @@ export type NoConnection = {
|
|
|
184
188
|
toNode: null;
|
|
185
189
|
};
|
|
186
190
|
export type ConnectionInProgress<NodeType extends InternalNodeBase = InternalNodeBase> = {
|
|
191
|
+
/** Indicates whether a connection is currently in progress. */
|
|
187
192
|
inProgress: true;
|
|
193
|
+
/**
|
|
194
|
+
* If an ongoing connection is above a handle or inside the connection radius, this will be `true`
|
|
195
|
+
* or `false`, otherwise `null`.
|
|
196
|
+
*/
|
|
188
197
|
isValid: boolean | null;
|
|
198
|
+
/** Returns the xy start position or `null` if no connection is in progress. */
|
|
189
199
|
from: XYPosition;
|
|
200
|
+
/** Returns the start handle or `null` if no connection is in progress. */
|
|
190
201
|
fromHandle: Handle;
|
|
202
|
+
/** Returns the side (called position) of the start handle or `null` if no connection is in progress. */
|
|
191
203
|
fromPosition: Position;
|
|
204
|
+
/** Returns the start node or `null` if no connection is in progress. */
|
|
192
205
|
fromNode: NodeType;
|
|
206
|
+
/** Returns the xy end position or `null` if no connection is in progress. */
|
|
193
207
|
to: XYPosition;
|
|
208
|
+
/** Returns the end handle or `null` if no connection is in progress. */
|
|
194
209
|
toHandle: Handle | null;
|
|
210
|
+
/** Returns the side (called position) of the end handle or `null` if no connection is in progress. */
|
|
195
211
|
toPosition: Position;
|
|
212
|
+
/** Returns the end node or `null` if no connection is in progress. */
|
|
196
213
|
toNode: NodeType | null;
|
|
197
214
|
};
|
|
198
215
|
/**
|