@xyflow/react 12.5.3 → 12.5.5
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/base.css +2 -2
- package/dist/esm/additional-components/Background/types.d.ts +9 -9
- package/dist/esm/additional-components/Background/types.d.ts.map +1 -1
- package/dist/esm/additional-components/MiniMap/MiniMapNodes.d.ts.map +1 -1
- package/dist/esm/additional-components/MiniMap/types.d.ts +65 -19
- package/dist/esm/additional-components/MiniMap/types.d.ts.map +1 -1
- package/dist/esm/additional-components/NodeResizer/NodeResizeControl.d.ts.map +1 -1
- package/dist/esm/additional-components/NodeResizer/types.d.ts +37 -18
- package/dist/esm/additional-components/NodeResizer/types.d.ts.map +1 -1
- package/dist/esm/additional-components/NodeToolbar/types.d.ts +6 -5
- package/dist/esm/additional-components/NodeToolbar/types.d.ts.map +1 -1
- package/dist/esm/components/Edges/SimpleBezierEdge.d.ts +10 -0
- package/dist/esm/components/Edges/SimpleBezierEdge.d.ts.map +1 -1
- package/dist/esm/components/Panel/index.d.ts +5 -5
- package/dist/esm/components/Panel/index.d.ts.map +1 -1
- package/dist/esm/contexts/NodeIdContext.d.ts +1 -1
- package/dist/esm/hooks/useConnection.d.ts +4 -0
- package/dist/esm/hooks/useConnection.d.ts.map +1 -1
- package/dist/esm/hooks/useEdges.d.ts +1 -1
- package/dist/esm/hooks/useHandleConnections.d.ts +8 -8
- package/dist/esm/hooks/useHandleConnections.d.ts.map +1 -1
- package/dist/esm/hooks/useInternalNode.d.ts +2 -2
- package/dist/esm/hooks/useKeyPress.d.ts +23 -4
- package/dist/esm/hooks/useKeyPress.d.ts.map +1 -1
- package/dist/esm/hooks/useNodeConnections.d.ts +6 -6
- package/dist/esm/hooks/useNodeConnections.d.ts.map +1 -1
- package/dist/esm/hooks/useNodes.d.ts +1 -1
- package/dist/esm/hooks/useNodesData.d.ts +7 -5
- package/dist/esm/hooks/useNodesData.d.ts.map +1 -1
- package/dist/esm/hooks/useNodesEdgesState.d.ts +32 -6
- package/dist/esm/hooks/useNodesEdgesState.d.ts.map +1 -1
- package/dist/esm/hooks/useNodesInitialized.d.ts +3 -2
- package/dist/esm/hooks/useNodesInitialized.d.ts.map +1 -1
- package/dist/esm/hooks/useOnSelectionChange.d.ts +1 -2
- package/dist/esm/hooks/useOnSelectionChange.d.ts.map +1 -1
- package/dist/esm/hooks/useOnViewportChange.d.ts +5 -6
- package/dist/esm/hooks/useOnViewportChange.d.ts.map +1 -1
- package/dist/esm/hooks/useReactFlow.d.ts +0 -2
- package/dist/esm/hooks/useReactFlow.d.ts.map +1 -1
- package/dist/esm/hooks/useStore.d.ts +8 -5
- package/dist/esm/hooks/useStore.d.ts.map +1 -1
- package/dist/esm/hooks/useUpdateNodeInternals.d.ts +5 -4
- package/dist/esm/hooks/useUpdateNodeInternals.d.ts.map +1 -1
- package/dist/esm/hooks/useViewport.d.ts +3 -3
- package/dist/esm/index.js +103 -74
- package/dist/esm/index.mjs +103 -74
- package/dist/esm/types/component-props.d.ts +234 -116
- package/dist/esm/types/component-props.d.ts.map +1 -1
- package/dist/esm/types/edges.d.ts +26 -8
- package/dist/esm/types/edges.d.ts.map +1 -1
- package/dist/esm/types/general.d.ts +11 -6
- package/dist/esm/types/general.d.ts.map +1 -1
- package/dist/esm/types/instance.d.ts +23 -8
- package/dist/esm/types/instance.d.ts.map +1 -1
- package/dist/esm/utils/changes.d.ts +6 -6
- package/dist/esm/utils/general.d.ts +11 -7
- package/dist/esm/utils/general.d.ts.map +1 -1
- package/dist/style.css +2 -2
- package/dist/umd/additional-components/Background/types.d.ts +9 -9
- package/dist/umd/additional-components/Background/types.d.ts.map +1 -1
- package/dist/umd/additional-components/MiniMap/MiniMapNodes.d.ts.map +1 -1
- package/dist/umd/additional-components/MiniMap/types.d.ts +65 -19
- package/dist/umd/additional-components/MiniMap/types.d.ts.map +1 -1
- package/dist/umd/additional-components/NodeResizer/NodeResizeControl.d.ts.map +1 -1
- package/dist/umd/additional-components/NodeResizer/types.d.ts +37 -18
- package/dist/umd/additional-components/NodeResizer/types.d.ts.map +1 -1
- package/dist/umd/additional-components/NodeToolbar/types.d.ts +6 -5
- package/dist/umd/additional-components/NodeToolbar/types.d.ts.map +1 -1
- package/dist/umd/components/Edges/SimpleBezierEdge.d.ts +10 -0
- package/dist/umd/components/Edges/SimpleBezierEdge.d.ts.map +1 -1
- package/dist/umd/components/Panel/index.d.ts +5 -5
- package/dist/umd/components/Panel/index.d.ts.map +1 -1
- package/dist/umd/contexts/NodeIdContext.d.ts +1 -1
- package/dist/umd/hooks/useConnection.d.ts +4 -0
- package/dist/umd/hooks/useConnection.d.ts.map +1 -1
- package/dist/umd/hooks/useEdges.d.ts +1 -1
- package/dist/umd/hooks/useHandleConnections.d.ts +8 -8
- package/dist/umd/hooks/useHandleConnections.d.ts.map +1 -1
- package/dist/umd/hooks/useInternalNode.d.ts +2 -2
- package/dist/umd/hooks/useKeyPress.d.ts +23 -4
- package/dist/umd/hooks/useKeyPress.d.ts.map +1 -1
- package/dist/umd/hooks/useNodeConnections.d.ts +6 -6
- package/dist/umd/hooks/useNodeConnections.d.ts.map +1 -1
- package/dist/umd/hooks/useNodes.d.ts +1 -1
- package/dist/umd/hooks/useNodesData.d.ts +7 -5
- package/dist/umd/hooks/useNodesData.d.ts.map +1 -1
- package/dist/umd/hooks/useNodesEdgesState.d.ts +32 -6
- package/dist/umd/hooks/useNodesEdgesState.d.ts.map +1 -1
- package/dist/umd/hooks/useNodesInitialized.d.ts +3 -2
- package/dist/umd/hooks/useNodesInitialized.d.ts.map +1 -1
- package/dist/umd/hooks/useOnSelectionChange.d.ts +1 -2
- package/dist/umd/hooks/useOnSelectionChange.d.ts.map +1 -1
- package/dist/umd/hooks/useOnViewportChange.d.ts +5 -6
- package/dist/umd/hooks/useOnViewportChange.d.ts.map +1 -1
- package/dist/umd/hooks/useReactFlow.d.ts +0 -2
- package/dist/umd/hooks/useReactFlow.d.ts.map +1 -1
- package/dist/umd/hooks/useStore.d.ts +8 -5
- package/dist/umd/hooks/useStore.d.ts.map +1 -1
- package/dist/umd/hooks/useUpdateNodeInternals.d.ts +5 -4
- package/dist/umd/hooks/useUpdateNodeInternals.d.ts.map +1 -1
- package/dist/umd/hooks/useViewport.d.ts +3 -3
- package/dist/umd/index.js +2 -2
- package/dist/umd/types/component-props.d.ts +234 -116
- package/dist/umd/types/component-props.d.ts.map +1 -1
- package/dist/umd/types/edges.d.ts +26 -8
- package/dist/umd/types/edges.d.ts.map +1 -1
- package/dist/umd/types/general.d.ts +11 -6
- package/dist/umd/types/general.d.ts.map +1 -1
- package/dist/umd/types/instance.d.ts +23 -8
- package/dist/umd/types/instance.d.ts.map +1 -1
- package/dist/umd/utils/changes.d.ts +6 -6
- package/dist/umd/utils/general.d.ts +11 -7
- package/dist/umd/utils/general.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/esm/index.js
CHANGED
|
@@ -18,9 +18,13 @@ const zustandErrorMessage = errorMessages['error001']();
|
|
|
18
18
|
* state management library, so you should check out their docs for more details.
|
|
19
19
|
*
|
|
20
20
|
* @public
|
|
21
|
-
* @param selector
|
|
22
|
-
*
|
|
23
|
-
*
|
|
21
|
+
* @param selector - A selector function that returns a slice of the flow's internal state.
|
|
22
|
+
* Extracting or transforming just the state you need is a good practice to avoid unnecessary
|
|
23
|
+
* re-renders.
|
|
24
|
+
* @param equalityFn - A function to compare the previous and next value. This is incredibly useful
|
|
25
|
+
* for preventing unnecessary re-renders. Good sensible defaults are using `Object.is` or importing
|
|
26
|
+
* `zustand/shallow`, but you can be as granular as you like.
|
|
27
|
+
* @returns The selected state slice.
|
|
24
28
|
*
|
|
25
29
|
* @example
|
|
26
30
|
* ```ts
|
|
@@ -41,8 +45,7 @@ function useStore(selector, equalityFn) {
|
|
|
41
45
|
/**
|
|
42
46
|
* In some cases, you might need to access the store directly. This hook returns the store object which can be used on demand to access the state or dispatch actions.
|
|
43
47
|
*
|
|
44
|
-
* @returns The store object
|
|
45
|
-
*
|
|
48
|
+
* @returns The store object.
|
|
46
49
|
* @example
|
|
47
50
|
* ```ts
|
|
48
51
|
* const store = useStoreApi();
|
|
@@ -175,7 +178,7 @@ const defaultViewport = { x: 0, y: 0, zoom: 1 };
|
|
|
175
178
|
* We distinguish between values we can update directly with `useDirectStoreUpdater` (like `snapGrid`)
|
|
176
179
|
* and values that have a dedicated setter function in the store (like `setNodes`).
|
|
177
180
|
*/
|
|
178
|
-
//
|
|
181
|
+
// These fields exist in the global store, and we need to keep them up to date
|
|
179
182
|
const reactFlowFieldsToTrack = [
|
|
180
183
|
'nodes',
|
|
181
184
|
'edges',
|
|
@@ -348,9 +351,7 @@ const defaultDoc = typeof document !== 'undefined' ? document : null;
|
|
|
348
351
|
* currently pressed or not.
|
|
349
352
|
*
|
|
350
353
|
* @public
|
|
351
|
-
* @param
|
|
352
|
-
* @param param.options - Options
|
|
353
|
-
* @returns boolean
|
|
354
|
+
* @param options - Options
|
|
354
355
|
*
|
|
355
356
|
* @example
|
|
356
357
|
* ```tsx
|
|
@@ -370,11 +371,17 @@ const defaultDoc = typeof document !== 'undefined' ? document : null;
|
|
|
370
371
|
*```
|
|
371
372
|
*/
|
|
372
373
|
function useKeyPress(
|
|
373
|
-
|
|
374
|
-
*
|
|
375
|
-
*
|
|
376
|
-
*
|
|
377
|
-
*
|
|
374
|
+
/**
|
|
375
|
+
* The key code (string or array of strings) specifies which key(s) should trigger
|
|
376
|
+
* an action.
|
|
377
|
+
*
|
|
378
|
+
* A **string** can represent:
|
|
379
|
+
* - A **single key**, e.g. `'a'`
|
|
380
|
+
* - A **key combination**, using `'+'` to separate keys, e.g. `'a+d'`
|
|
381
|
+
*
|
|
382
|
+
* An **array of strings** represents **multiple possible key inputs**. For example, `['a', 'd+s']`
|
|
383
|
+
* means the user can press either the single key `'a'` or the combination of `'d'` and `'s'`.
|
|
384
|
+
* @default null
|
|
378
385
|
*/
|
|
379
386
|
keyCode = null, options = { target: defaultDoc, actInsideInputWithModifier: true }) {
|
|
380
387
|
const [keyPressed, setKeyPressed] = useState(false);
|
|
@@ -692,9 +699,9 @@ function applyChange(change, element) {
|
|
|
692
699
|
/**
|
|
693
700
|
* Drop in function that applies node changes to an array of nodes.
|
|
694
701
|
* @public
|
|
695
|
-
* @param changes - Array of changes to apply
|
|
696
|
-
* @param nodes - Array of nodes to apply the changes to
|
|
697
|
-
* @returns Array of updated nodes
|
|
702
|
+
* @param changes - Array of changes to apply.
|
|
703
|
+
* @param nodes - Array of nodes to apply the changes to.
|
|
704
|
+
* @returns Array of updated nodes.
|
|
698
705
|
* @example
|
|
699
706
|
*```tsx
|
|
700
707
|
*import { useState, useCallback } from 'react';
|
|
@@ -726,9 +733,9 @@ function applyNodeChanges(changes, nodes) {
|
|
|
726
733
|
/**
|
|
727
734
|
* Drop in function that applies edge changes to an array of edges.
|
|
728
735
|
* @public
|
|
729
|
-
* @param changes - Array of changes to apply
|
|
730
|
-
* @param edges - Array of edge to apply the changes to
|
|
731
|
-
* @returns Array of updated edges
|
|
736
|
+
* @param changes - Array of changes to apply.
|
|
737
|
+
* @param edges - Array of edge to apply the changes to.
|
|
738
|
+
* @returns Array of updated edges.
|
|
732
739
|
* @example
|
|
733
740
|
* ```tsx
|
|
734
741
|
*import { useState, useCallback } from 'react';
|
|
@@ -812,41 +819,45 @@ function elementToRemoveChange(item) {
|
|
|
812
819
|
}
|
|
813
820
|
|
|
814
821
|
/**
|
|
815
|
-
* Test whether an object is
|
|
822
|
+
* Test whether an object is usable as an [`Node`](/api-reference/types/node).
|
|
816
823
|
* In TypeScript this is a type guard that will narrow the type of whatever you pass in to
|
|
817
824
|
* [`Node`](/api-reference/types/node) if it returns `true`.
|
|
818
825
|
*
|
|
819
826
|
* @public
|
|
820
827
|
* @remarks In TypeScript this is a type guard that will narrow the type of whatever you pass in to Node if it returns true
|
|
821
|
-
* @param element - The element to test
|
|
822
|
-
* @returns
|
|
828
|
+
* @param element - The element to test.
|
|
829
|
+
* @returns Tests whether the provided value can be used as a `Node`. If you're using TypeScript,
|
|
830
|
+
* this function acts as a type guard and will narrow the type of the value to `Node` if it returns
|
|
831
|
+
* `true`.
|
|
823
832
|
*
|
|
824
833
|
* @example
|
|
825
834
|
* ```js
|
|
826
835
|
*import { isNode } from '@xyflow/react';
|
|
827
836
|
*
|
|
828
837
|
*if (isNode(node)) {
|
|
829
|
-
* //
|
|
838
|
+
* // ...
|
|
830
839
|
*}
|
|
831
840
|
*```
|
|
832
841
|
*/
|
|
833
842
|
const isNode = (element) => isNodeBase(element);
|
|
834
843
|
/**
|
|
835
|
-
* Test whether an object is
|
|
844
|
+
* Test whether an object is usable as an [`Edge`](/api-reference/types/edge).
|
|
836
845
|
* In TypeScript this is a type guard that will narrow the type of whatever you pass in to
|
|
837
846
|
* [`Edge`](/api-reference/types/edge) if it returns `true`.
|
|
838
847
|
*
|
|
839
848
|
* @public
|
|
840
849
|
* @remarks In TypeScript this is a type guard that will narrow the type of whatever you pass in to Edge if it returns true
|
|
841
850
|
* @param element - The element to test
|
|
842
|
-
* @returns
|
|
851
|
+
* @returns Tests whether the provided value can be used as an `Edge`. If you're using TypeScript,
|
|
852
|
+
* this function acts as a type guard and will narrow the type of the value to `Edge` if it returns
|
|
853
|
+
* `true`.
|
|
843
854
|
*
|
|
844
855
|
* @example
|
|
845
856
|
* ```js
|
|
846
857
|
*import { isEdge } from '@xyflow/react';
|
|
847
858
|
*
|
|
848
859
|
*if (isEdge(edge)) {
|
|
849
|
-
* //
|
|
860
|
+
* // ...
|
|
850
861
|
*}
|
|
851
862
|
*```
|
|
852
863
|
*/
|
|
@@ -990,8 +1001,6 @@ const selector$k = (s) => !!s.panZoom;
|
|
|
990
1001
|
* This hook returns a ReactFlowInstance that can be used to update nodes and edges, manipulate the viewport, or query the current state of the flow.
|
|
991
1002
|
*
|
|
992
1003
|
* @public
|
|
993
|
-
* @returns ReactFlowInstance
|
|
994
|
-
*
|
|
995
1004
|
* @example
|
|
996
1005
|
* ```jsx
|
|
997
1006
|
*import { useCallback, useState } from 'react';
|
|
@@ -1646,7 +1655,7 @@ NodeIdContext.Consumer;
|
|
|
1646
1655
|
* drill down the id as a prop.
|
|
1647
1656
|
*
|
|
1648
1657
|
* @public
|
|
1649
|
-
* @returns id
|
|
1658
|
+
* @returns The id for a node in the flow.
|
|
1650
1659
|
*
|
|
1651
1660
|
* @example
|
|
1652
1661
|
*```jsx
|
|
@@ -2409,6 +2418,14 @@ function getControl({ pos, x1, y1, x2, y2 }) {
|
|
|
2409
2418
|
* The `getSimpleBezierPath` util returns everything you need to render a simple
|
|
2410
2419
|
* bezier edge between two nodes.
|
|
2411
2420
|
* @public
|
|
2421
|
+
* @returns
|
|
2422
|
+
* - `path`: the path to use in an SVG `<path>` element.
|
|
2423
|
+
* - `labelX`: the `x` position you can use to render a label for this edge.
|
|
2424
|
+
* - `labelY`: the `y` position you can use to render a label for this edge.
|
|
2425
|
+
* - `offsetX`: the absolute difference between the source `x` position and the `x` position of the
|
|
2426
|
+
* middle of this path.
|
|
2427
|
+
* - `offsetY`: the absolute difference between the source `y` position and the `y` position of the
|
|
2428
|
+
* middle of this path.
|
|
2412
2429
|
*/
|
|
2413
2430
|
function getSimpleBezierPath({ sourceX, sourceY, sourcePosition = Position.Bottom, targetX, targetY, targetPosition = Position.Top, }) {
|
|
2414
2431
|
const [sourceControlX, sourceControlY] = getControl({
|
|
@@ -2445,7 +2462,7 @@ function getSimpleBezierPath({ sourceX, sourceY, sourcePosition = Position.Botto
|
|
|
2445
2462
|
}
|
|
2446
2463
|
function createSimpleBezierEdge(params) {
|
|
2447
2464
|
// eslint-disable-next-line react/display-name
|
|
2448
|
-
return memo(({ id, sourceX, sourceY, targetX, targetY, sourcePosition
|
|
2465
|
+
return memo(({ id, sourceX, sourceY, targetX, targetY, sourcePosition, targetPosition, label, labelStyle, labelShowBg, labelBgStyle, labelBgPadding, labelBgBorderRadius, style, markerEnd, markerStart, interactionWidth, }) => {
|
|
2449
2466
|
const [path, labelX, labelY] = getSimpleBezierPath({
|
|
2450
2467
|
sourceX,
|
|
2451
2468
|
sourceY,
|
|
@@ -2921,6 +2938,10 @@ function getSelector(connectionSelector) {
|
|
|
2921
2938
|
* based on a certain condition (e.g. if the connection is valid or not).
|
|
2922
2939
|
*
|
|
2923
2940
|
* @public
|
|
2941
|
+
* @param connectionSelector - An optional selector function used to extract a slice of the
|
|
2942
|
+
* `ConnectionState` data. Using a selector can prevent component re-renders where data you don't
|
|
2943
|
+
* otherwise care about might change. If a selector is not provided, the entire `ConnectionState`
|
|
2944
|
+
* object is returned unchanged.
|
|
2924
2945
|
* @example
|
|
2925
2946
|
*
|
|
2926
2947
|
* ```tsx
|
|
@@ -3565,12 +3586,13 @@ function ViewportPortal({ children }) {
|
|
|
3565
3586
|
|
|
3566
3587
|
/**
|
|
3567
3588
|
* When you programmatically add or remove handles to a node or update a node's
|
|
3568
|
-
*handle position, you need to let React Flow know about it using this hook. This
|
|
3569
|
-
*will update the internal dimensions of the node and properly reposition handles
|
|
3570
|
-
*on the canvas if necessary.
|
|
3589
|
+
* handle position, you need to let React Flow know about it using this hook. This
|
|
3590
|
+
* will update the internal dimensions of the node and properly reposition handles
|
|
3591
|
+
* on the canvas if necessary.
|
|
3571
3592
|
*
|
|
3572
3593
|
* @public
|
|
3573
|
-
* @returns function
|
|
3594
|
+
* @returns Use this function to tell React Flow to update the internal state of one or more nodes
|
|
3595
|
+
* that you have changed programmatically.
|
|
3574
3596
|
*
|
|
3575
3597
|
* @example
|
|
3576
3598
|
* ```jsx
|
|
@@ -3630,7 +3652,7 @@ const nodesSelector = (state) => state.nodes;
|
|
|
3630
3652
|
* or moved.
|
|
3631
3653
|
*
|
|
3632
3654
|
* @public
|
|
3633
|
-
* @returns An array of nodes
|
|
3655
|
+
* @returns An array of all nodes currently in the flow.
|
|
3634
3656
|
*
|
|
3635
3657
|
* @example
|
|
3636
3658
|
* ```jsx
|
|
@@ -3654,7 +3676,7 @@ const edgesSelector = (state) => state.edges;
|
|
|
3654
3676
|
* will re-render **whenever any edge changes**.
|
|
3655
3677
|
*
|
|
3656
3678
|
* @public
|
|
3657
|
-
* @returns An array of edges
|
|
3679
|
+
* @returns An array of all edges currently in the flow.
|
|
3658
3680
|
*
|
|
3659
3681
|
* @example
|
|
3660
3682
|
* ```tsx
|
|
@@ -3679,11 +3701,11 @@ const viewportSelector = (state) => ({
|
|
|
3679
3701
|
});
|
|
3680
3702
|
/**
|
|
3681
3703
|
* The `useViewport` hook is a convenient way to read the current state of the
|
|
3682
|
-
*{@link Viewport} in a component. Components that use this hook
|
|
3683
|
-
*will re-render **whenever the viewport changes**.
|
|
3704
|
+
* {@link Viewport} in a component. Components that use this hook
|
|
3705
|
+
* will re-render **whenever the viewport changes**.
|
|
3684
3706
|
*
|
|
3685
3707
|
* @public
|
|
3686
|
-
* @returns The current viewport
|
|
3708
|
+
* @returns The current viewport.
|
|
3687
3709
|
*
|
|
3688
3710
|
* @example
|
|
3689
3711
|
*
|
|
@@ -3717,8 +3739,16 @@ function useViewport() {
|
|
|
3717
3739
|
* like React's `useState` hook with an additional helper callback.
|
|
3718
3740
|
*
|
|
3719
3741
|
* @public
|
|
3720
|
-
* @
|
|
3721
|
-
*
|
|
3742
|
+
* @returns
|
|
3743
|
+
* - `nodes`: The current array of nodes. You might pass this directly to the `nodes` prop of your
|
|
3744
|
+
* `<ReactFlow />` component, or you may want to manipulate it first to perform some layouting,
|
|
3745
|
+
* for example.
|
|
3746
|
+
* - `setNodes`: A function that you can use to update the nodes. You can pass it a new array of
|
|
3747
|
+
* nodes or a callback that receives the current array of nodes and returns a new array of nodes.
|
|
3748
|
+
* This is the same as the second element of the tuple returned by React's `useState` hook.
|
|
3749
|
+
* - `onNodesChange`: A handy callback that can take an array of `NodeChanges` and update the nodes
|
|
3750
|
+
* state accordingly. You'll typically pass this directly to the `onNodesChange` prop of your
|
|
3751
|
+
* `<ReactFlow />` component.
|
|
3722
3752
|
* @example
|
|
3723
3753
|
*
|
|
3724
3754
|
*```tsx
|
|
@@ -3759,8 +3789,18 @@ function useNodesState(initialNodes) {
|
|
|
3759
3789
|
* like React's `useState` hook with an additional helper callback.
|
|
3760
3790
|
*
|
|
3761
3791
|
* @public
|
|
3762
|
-
* @
|
|
3763
|
-
*
|
|
3792
|
+
* @returns
|
|
3793
|
+
* - `edges`: The current array of edges. You might pass this directly to the `edges` prop of your
|
|
3794
|
+
* `<ReactFlow />` component, or you may want to manipulate it first to perform some layouting,
|
|
3795
|
+
* for example.
|
|
3796
|
+
*
|
|
3797
|
+
* - `setEdges`: A function that you can use to update the edges. You can pass it a new array of
|
|
3798
|
+
* edges or a callback that receives the current array of edges and returns a new array of edges.
|
|
3799
|
+
* This is the same as the second element of the tuple returned by React's `useState` hook.
|
|
3800
|
+
*
|
|
3801
|
+
* - `onEdgesChange`: A handy callback that can take an array of `EdgeChanges` and update the edges
|
|
3802
|
+
* state accordingly. You'll typically pass this directly to the `onEdgesChange` prop of your
|
|
3803
|
+
* `<ReactFlow />` component.
|
|
3764
3804
|
* @example
|
|
3765
3805
|
*
|
|
3766
3806
|
*```tsx
|
|
@@ -3798,14 +3838,10 @@ function useEdgesState(initialEdges) {
|
|
|
3798
3838
|
|
|
3799
3839
|
/**
|
|
3800
3840
|
* The `useOnViewportChange` hook lets you listen for changes to the viewport such
|
|
3801
|
-
*as panning and zooming. You can provide a callback for each phase of a viewport
|
|
3802
|
-
*change: `onStart`, `onChange`, and `onEnd`.
|
|
3841
|
+
* as panning and zooming. You can provide a callback for each phase of a viewport
|
|
3842
|
+
* change: `onStart`, `onChange`, and `onEnd`.
|
|
3803
3843
|
*
|
|
3804
3844
|
* @public
|
|
3805
|
-
* @param params.onStart - gets called when the viewport starts changing
|
|
3806
|
-
* @param params.onChange - gets called when the viewport changes
|
|
3807
|
-
* @param params.onEnd - gets called when the viewport stops changing
|
|
3808
|
-
*
|
|
3809
3845
|
* @example
|
|
3810
3846
|
* ```jsx
|
|
3811
3847
|
*import { useCallback } from 'react';
|
|
@@ -3841,8 +3877,6 @@ function useOnViewportChange({ onStart, onChange, onEnd }) {
|
|
|
3841
3877
|
*_either_ nodes or edges changes.
|
|
3842
3878
|
*
|
|
3843
3879
|
* @public
|
|
3844
|
-
* @param params.onChange - The handler to register
|
|
3845
|
-
*
|
|
3846
3880
|
* @example
|
|
3847
3881
|
* ```jsx
|
|
3848
3882
|
*import { useState } from 'react';
|
|
@@ -3904,8 +3938,8 @@ const selector$4 = (options) => (s) => {
|
|
|
3904
3938
|
*`false` and then `true` again once the node has been measured.
|
|
3905
3939
|
*
|
|
3906
3940
|
* @public
|
|
3907
|
-
* @
|
|
3908
|
-
*
|
|
3941
|
+
* @returns Whether or not the nodes have been initialized by the `<ReactFlow />` component and
|
|
3942
|
+
* given a width and height.
|
|
3909
3943
|
*
|
|
3910
3944
|
* @example
|
|
3911
3945
|
* ```jsx
|
|
@@ -3943,12 +3977,7 @@ function useNodesInitialized(options = {
|
|
|
3943
3977
|
*
|
|
3944
3978
|
* @public
|
|
3945
3979
|
* @deprecated Use `useNodeConnections` instead.
|
|
3946
|
-
* @
|
|
3947
|
-
* @param param.nodeId - node id - if not provided, the node id from the NodeIdContext is used
|
|
3948
|
-
* @param param.id - the handle id (this is only needed if the node has multiple handles of the same type)
|
|
3949
|
-
* @param param.onConnect - gets called when a connection is established
|
|
3950
|
-
* @param param.onDisconnect - gets called when a connection is removed
|
|
3951
|
-
* @returns an array with handle connections
|
|
3980
|
+
* @returns An array with handle connections.
|
|
3952
3981
|
*/
|
|
3953
3982
|
function useHandleConnections({ type, id, nodeId, onConnect, onDisconnect, }) {
|
|
3954
3983
|
console.warn('[DEPRECATED] `useHandleConnections` is deprecated. Instead use `useNodeConnections` https://reactflow.dev/api-reference/hooks/useNodeConnections');
|
|
@@ -3973,12 +4002,7 @@ const error014 = errorMessages['error014']();
|
|
|
3973
4002
|
* This hook returns an array of connections on a specific node, handle type ('source', 'target') or handle ID.
|
|
3974
4003
|
*
|
|
3975
4004
|
* @public
|
|
3976
|
-
* @
|
|
3977
|
-
* @param param.handleType - filter by handle type 'source' or 'target'
|
|
3978
|
-
* @param param.handleId - filter by handle id (this is only needed if the node has multiple handles of the same type)
|
|
3979
|
-
* @param param.onConnect - gets called when a connection is established
|
|
3980
|
-
* @param param.onDisconnect - gets called when a connection is removed
|
|
3981
|
-
* @returns an array with connections
|
|
4005
|
+
* @returns An array with connections.
|
|
3982
4006
|
*
|
|
3983
4007
|
* @example
|
|
3984
4008
|
* ```jsx
|
|
@@ -4005,7 +4029,7 @@ function useNodeConnections({ id, handleType, handleId, onConnect, onDisconnect,
|
|
|
4005
4029
|
const prevConnections = useRef(null);
|
|
4006
4030
|
const connections = useStore((state) => state.connectionLookup.get(`${currentNodeId}${handleType ? (handleId ? `-${handleType}-${handleId}` : `-${handleType}`) : ''}`), areConnectionMapsEqual);
|
|
4007
4031
|
useEffect(() => {
|
|
4008
|
-
// @todo
|
|
4032
|
+
// @todo discuss if onConnect/onDisconnect should be called when the component mounts/unmounts
|
|
4009
4033
|
if (prevConnections.current && prevConnections.current !== connections) {
|
|
4010
4034
|
const _connections = connections ?? new Map();
|
|
4011
4035
|
handleConnectionChange(prevConnections.current, _connections, onDisconnect);
|
|
@@ -4043,8 +4067,8 @@ function useNodesData(nodeIds) {
|
|
|
4043
4067
|
* including when a node is selected or moved.
|
|
4044
4068
|
*
|
|
4045
4069
|
* @public
|
|
4046
|
-
* @param id -
|
|
4047
|
-
* @returns
|
|
4070
|
+
* @param id - The ID of a node you want to observe.
|
|
4071
|
+
* @returns The `InternalNode` object for the node with the given ID.
|
|
4048
4072
|
*
|
|
4049
4073
|
* @example
|
|
4050
4074
|
* ```tsx
|
|
@@ -4317,8 +4341,9 @@ nodeComponent: NodeComponent = MiniMapNode, onClick, }) {
|
|
|
4317
4341
|
}
|
|
4318
4342
|
function NodeComponentWrapperInner({ id, nodeColorFunc, nodeStrokeColorFunc, nodeClassNameFunc, nodeBorderRadius, nodeStrokeWidth, shapeRendering, NodeComponent, onClick, }) {
|
|
4319
4343
|
const { node, x, y, width, height } = useStore((s) => {
|
|
4320
|
-
const
|
|
4321
|
-
const
|
|
4344
|
+
const { internals } = s.nodeLookup.get(id);
|
|
4345
|
+
const node = internals.userNode;
|
|
4346
|
+
const { x, y } = internals.positionAbsolute;
|
|
4322
4347
|
const { width, height } = getNodeDimensions(node);
|
|
4323
4348
|
return {
|
|
4324
4349
|
node,
|
|
@@ -4416,7 +4441,7 @@ nodeComponent, bgColor, maskColor, maskStrokeColor, maskStrokeWidth, position =
|
|
|
4416
4441
|
: undefined;
|
|
4417
4442
|
const onSvgNodeClick = onNodeClick
|
|
4418
4443
|
? useCallback((event, nodeId) => {
|
|
4419
|
-
const node = store.getState().nodeLookup.get(nodeId);
|
|
4444
|
+
const node = store.getState().nodeLookup.get(nodeId).internals.userNode;
|
|
4420
4445
|
onNodeClick(event, node);
|
|
4421
4446
|
}, [])
|
|
4422
4447
|
: undefined;
|
|
@@ -4428,7 +4453,7 @@ nodeComponent, bgColor, maskColor, maskStrokeColor, maskStrokeWidth, position =
|
|
|
4428
4453
|
'--xy-minimap-mask-stroke-width-props': typeof maskStrokeWidth === 'number' ? maskStrokeWidth * viewScale : undefined,
|
|
4429
4454
|
'--xy-minimap-node-background-color-props': typeof nodeColor === 'string' ? nodeColor : undefined,
|
|
4430
4455
|
'--xy-minimap-node-stroke-color-props': typeof nodeStrokeColor === 'string' ? nodeStrokeColor : undefined,
|
|
4431
|
-
'--xy-minimap-node-stroke-width-props': typeof nodeStrokeWidth === '
|
|
4456
|
+
'--xy-minimap-node-stroke-width-props': typeof nodeStrokeWidth === 'number' ? nodeStrokeWidth : undefined,
|
|
4432
4457
|
}, className: cc(['react-flow__minimap', className]), "data-testid": "rf__minimap", children: jsxs("svg", { width: elementWidth, height: elementHeight, viewBox: `${x} ${y} ${width} ${height}`, className: "react-flow__minimap-svg", role: "img", "aria-labelledby": labelledBy, ref: svg, onClick: onSvgClick, children: [ariaLabel && jsx("title", { id: labelledBy, children: ariaLabel }), jsx(MiniMapNodes$1, { onClick: onSvgNodeClick, nodeColor: nodeColor, nodeStrokeColor: nodeStrokeColor, nodeBorderRadius: nodeBorderRadius, nodeClassName: nodeClassName, nodeStrokeWidth: nodeStrokeWidth, nodeComponent: nodeComponent }), jsx("path", { className: "react-flow__minimap-mask", d: `M${x - offset},${y - offset}h${width + offset * 2}v${height + offset * 2}h${-width - offset * 2}z
|
|
4433
4458
|
M${viewBB.x},${viewBB.y}h${viewBB.width}v${viewBB.height}h${-viewBB.width}z`, fillRule: "evenodd", pointerEvents: "none" })] }) }));
|
|
4434
4459
|
}
|
|
@@ -4542,11 +4567,15 @@ function ResizeControl({ nodeId, position, variant = ResizeControlVariant.Handle
|
|
|
4542
4567
|
}
|
|
4543
4568
|
triggerNodeChanges(changes);
|
|
4544
4569
|
},
|
|
4545
|
-
onEnd: () => {
|
|
4570
|
+
onEnd: ({ width, height }) => {
|
|
4546
4571
|
const dimensionChange = {
|
|
4547
4572
|
id: id,
|
|
4548
4573
|
type: 'dimensions',
|
|
4549
4574
|
resizing: false,
|
|
4575
|
+
dimensions: {
|
|
4576
|
+
width,
|
|
4577
|
+
height,
|
|
4578
|
+
},
|
|
4550
4579
|
};
|
|
4551
4580
|
store.getState().triggerNodeChanges([dimensionChange]);
|
|
4552
4581
|
},
|