@octanejs/xyflow 0.1.0
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/LICENSE +21 -0
- package/README.md +26 -0
- package/package.json +69 -0
- package/src/additional-components/Background/Background.tsrx +144 -0
- package/src/additional-components/Background/Patterns.tsrx +32 -0
- package/src/additional-components/Background/index.tsrx +2 -0
- package/src/additional-components/Background/types.ts +60 -0
- package/src/additional-components/Controls/ControlButton.tsrx +34 -0
- package/src/additional-components/Controls/Controls.tsrx +148 -0
- package/src/additional-components/Controls/Icons/FitView.tsrx +7 -0
- package/src/additional-components/Controls/Icons/Lock.tsrx +7 -0
- package/src/additional-components/Controls/Icons/Minus.tsrx +5 -0
- package/src/additional-components/Controls/Icons/Plus.tsrx +5 -0
- package/src/additional-components/Controls/Icons/Unlock.tsrx +7 -0
- package/src/additional-components/Controls/index.tsrx +3 -0
- package/src/additional-components/Controls/types.ts +68 -0
- package/src/additional-components/EdgeToolbar/EdgeToolbar.tsrx +79 -0
- package/src/additional-components/EdgeToolbar/index.tsrx +2 -0
- package/src/additional-components/EdgeToolbar/types.ts +14 -0
- package/src/additional-components/MiniMap/MiniMap.tsrx +249 -0
- package/src/additional-components/MiniMap/MiniMapNode.tsrx +43 -0
- package/src/additional-components/MiniMap/MiniMapNodes.tsrx +136 -0
- package/src/additional-components/MiniMap/index.ts +3 -0
- package/src/additional-components/MiniMap/types.ts +139 -0
- package/src/additional-components/NodeResizer/NodeResizeControl.tsrx +250 -0
- package/src/additional-components/NodeResizer/NodeResizer.tsrx +102 -0
- package/src/additional-components/NodeResizer/index.ts +4 -0
- package/src/additional-components/NodeResizer/types.ts +122 -0
- package/src/additional-components/NodeToolbar/NodeToolbar.tsrx +141 -0
- package/src/additional-components/NodeToolbar/NodeToolbarPortal.tsrx +17 -0
- package/src/additional-components/NodeToolbar/index.tsrx +2 -0
- package/src/additional-components/NodeToolbar/types.ts +32 -0
- package/src/additional-components/index.ts +6 -0
- package/src/components/A11yDescriptions/index.tsrx +58 -0
- package/src/components/Attribution/index.tsrx +31 -0
- package/src/components/BatchProvider/index.tsrx +122 -0
- package/src/components/BatchProvider/types.ts +7 -0
- package/src/components/BatchProvider/useQueue.ts +62 -0
- package/src/components/ConnectionLine/index.tsrx +140 -0
- package/src/components/EdgeLabelRenderer/index.tsrx +62 -0
- package/src/components/EdgeWrapper/EdgeUpdateAnchors.tsrx +151 -0
- package/src/components/EdgeWrapper/index.tsrx +274 -0
- package/src/components/EdgeWrapper/utils.ts +26 -0
- package/src/components/Edges/BaseEdge.tsrx +76 -0
- package/src/components/Edges/BezierEdge.tsrx +94 -0
- package/src/components/Edges/EdgeAnchor.tsrx +54 -0
- package/src/components/Edges/EdgeText.tsrx +97 -0
- package/src/components/Edges/SimpleBezierEdge.tsrx +150 -0
- package/src/components/Edges/SmoothStepEdge.tsrx +96 -0
- package/src/components/Edges/StepEdge.tsrx +55 -0
- package/src/components/Edges/StraightEdge.tsrx +81 -0
- package/src/components/Edges/index.ts +11 -0
- package/src/components/Handle/index.tsrx +314 -0
- package/src/components/NodeWrapper/index.tsrx +259 -0
- package/src/components/NodeWrapper/useNodeObserver.ts +79 -0
- package/src/components/NodeWrapper/utils.tsrx +40 -0
- package/src/components/Nodes/DefaultNode.tsrx +17 -0
- package/src/components/Nodes/GroupNode.tsrx +3 -0
- package/src/components/Nodes/InputNode.tsrx +13 -0
- package/src/components/Nodes/OutputNode.tsrx +13 -0
- package/src/components/Nodes/utils.ts +45 -0
- package/src/components/NodesSelection/index.tsrx +103 -0
- package/src/components/Panel/index.tsrx +34 -0
- package/src/components/ReactFlowProvider/index.tsrx +128 -0
- package/src/components/SelectionListener/index.tsrx +73 -0
- package/src/components/StoreUpdater/index.tsrx +173 -0
- package/src/components/UserSelection/index.tsrx +27 -0
- package/src/components/ViewportPortal/index.tsrx +42 -0
- package/src/container/EdgeRenderer/MarkerDefinitions.tsrx +87 -0
- package/src/container/EdgeRenderer/MarkerSymbols.tsrx +60 -0
- package/src/container/EdgeRenderer/index.tsrx +98 -0
- package/src/container/FlowRenderer/index.tsrx +146 -0
- package/src/container/GraphView/index.tsrx +212 -0
- package/src/container/GraphView/useNodeOrEdgeTypesWarning.ts +39 -0
- package/src/container/GraphView/useStylesLoadedWarning.ts +26 -0
- package/src/container/NodeRenderer/index.tsrx +103 -0
- package/src/container/NodeRenderer/useResizeObserver.ts +38 -0
- package/src/container/Pane/index.tsrx +397 -0
- package/src/container/ReactFlow/Wrapper.tsrx +66 -0
- package/src/container/ReactFlow/index.tsrx +352 -0
- package/src/container/ReactFlow/init-values.ts +4 -0
- package/src/container/Viewport/index.tsrx +52 -0
- package/src/container/ZoomPane/index.tsrx +159 -0
- package/src/contexts/HandleConfigContext.tsrx +38 -0
- package/src/contexts/NodeIdContext.ts +39 -0
- package/src/contexts/StoreContext.ts +8 -0
- package/src/custom.d.ts +13 -0
- package/src/hooks/slot.ts +22 -0
- package/src/hooks/useColorModeClass.ts +50 -0
- package/src/hooks/useConnection.ts +69 -0
- package/src/hooks/useDrag.ts +95 -0
- package/src/hooks/useEdges.ts +32 -0
- package/src/hooks/useGlobalKeyHandler.ts +55 -0
- package/src/hooks/useHandleConnections.ts +77 -0
- package/src/hooks/useInternalNode.ts +47 -0
- package/src/hooks/useIsomorphicLayoutEffect.ts +5 -0
- package/src/hooks/useKeyPress.ts +217 -0
- package/src/hooks/useMoveSelectedNodes.ts +82 -0
- package/src/hooks/useNodeConnections.ts +86 -0
- package/src/hooks/useNodes.ts +33 -0
- package/src/hooks/useNodesData.ts +66 -0
- package/src/hooks/useNodesEdgesState.ts +138 -0
- package/src/hooks/useNodesInitialized.ts +74 -0
- package/src/hooks/useOnEdgesChangeMiddleware.ts +46 -0
- package/src/hooks/useOnInitHandler.ts +27 -0
- package/src/hooks/useOnNodesChangeMiddleware.ts +46 -0
- package/src/hooks/useOnSelectionChange.ts +78 -0
- package/src/hooks/useOnViewportChange.ts +68 -0
- package/src/hooks/useReactFlow.ts +347 -0
- package/src/hooks/useResizeHandler.ts +54 -0
- package/src/hooks/useStore.ts +58 -0
- package/src/hooks/useUpdateNodeInternals.ts +73 -0
- package/src/hooks/useViewport.ts +48 -0
- package/src/hooks/useViewportHelper.ts +103 -0
- package/src/hooks/useViewportSync.ts +33 -0
- package/src/hooks/useVisibleEdgeIds.ts +52 -0
- package/src/hooks/useVisibleNodeIds.ts +36 -0
- package/src/index.ts +151 -0
- package/src/react-shim.ts +93 -0
- package/src/store/index.ts +516 -0
- package/src/store/initialState.ts +162 -0
- package/src/styles/base.css +516 -0
- package/src/styles/style.css +648 -0
- package/src/styles/utils.ts +9 -0
- package/src/types/component-props.ts +716 -0
- package/src/types/edges.ts +312 -0
- package/src/types/general.ts +239 -0
- package/src/types/index.ts +6 -0
- package/src/types/instance.ts +265 -0
- package/src/types/nodes.ts +144 -0
- package/src/types/store.ts +198 -0
- package/src/utils/changes.ts +329 -0
- package/src/utils/edges.ts +34 -0
- package/src/utils/general.ts +72 -0
- package/src/utils/index.ts +3 -0
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-namespace */
|
|
2
|
+
import type { HandleConnection, HandleType, NodeConnection, Rect, Viewport } from '@xyflow/system';
|
|
3
|
+
import type { Node, Edge, ViewportHelperFunctions, InternalNode, FitView } from '.';
|
|
4
|
+
|
|
5
|
+
export type ReactFlowJsonObject<NodeType extends Node = Node, EdgeType extends Edge = Edge> = {
|
|
6
|
+
nodes: NodeType[];
|
|
7
|
+
edges: EdgeType[];
|
|
8
|
+
viewport: Viewport;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type DeleteElementsOptions = {
|
|
12
|
+
nodes?: (Node | { id: Node['id'] })[];
|
|
13
|
+
edges?: (Edge | { id: Edge['id'] })[];
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @inline
|
|
18
|
+
*/
|
|
19
|
+
export type GeneralHelpers<NodeType extends Node = Node, EdgeType extends Edge = Edge> = {
|
|
20
|
+
/**
|
|
21
|
+
* Returns nodes.
|
|
22
|
+
*
|
|
23
|
+
* @returns nodes array
|
|
24
|
+
*/
|
|
25
|
+
getNodes: () => NodeType[];
|
|
26
|
+
/**
|
|
27
|
+
* Set your nodes array to something else by either overwriting it with a new array or by passing
|
|
28
|
+
* in a function to update the existing array. If using a function, it is important to make sure a
|
|
29
|
+
* new array is returned instead of mutating the existing array. Calling this function will
|
|
30
|
+
* trigger the `onNodesChange` handler in a controlled flow.
|
|
31
|
+
*
|
|
32
|
+
* @param payload - the nodes to set or a function that receives the current nodes and returns the new nodes
|
|
33
|
+
*/
|
|
34
|
+
setNodes: (payload: NodeType[] | ((nodes: NodeType[]) => NodeType[])) => void;
|
|
35
|
+
/**
|
|
36
|
+
* Add one or many nodes to your existing nodes array. Calling this function will trigger the
|
|
37
|
+
* `onNodesChange` handler in a controlled flow.
|
|
38
|
+
*
|
|
39
|
+
* @param payload - the nodes to add
|
|
40
|
+
*/
|
|
41
|
+
addNodes: (payload: NodeType[] | NodeType) => void;
|
|
42
|
+
/**
|
|
43
|
+
* Returns a node by id.
|
|
44
|
+
*
|
|
45
|
+
* @param id - the node id
|
|
46
|
+
* @returns the node or undefined if no node was found
|
|
47
|
+
*/
|
|
48
|
+
getNode: (id: string) => NodeType | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Returns an internal node by id.
|
|
51
|
+
*
|
|
52
|
+
* @param id - the node id
|
|
53
|
+
* @returns the internal node or undefined if no node was found
|
|
54
|
+
*/
|
|
55
|
+
getInternalNode: (id: string) => InternalNode<NodeType> | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Returns edges.
|
|
58
|
+
*
|
|
59
|
+
* @returns edges array
|
|
60
|
+
*/
|
|
61
|
+
getEdges: () => EdgeType[];
|
|
62
|
+
/**
|
|
63
|
+
* Set your edges array to something else by either overwriting it with a new array or by passing
|
|
64
|
+
* in a function to update the existing array. If using a function, it is important to make sure a
|
|
65
|
+
* new array is returned instead of mutating the existing array. Calling this function will
|
|
66
|
+
* trigger the `onEdgesChange` handler in a controlled flow.
|
|
67
|
+
*
|
|
68
|
+
* @param payload - the edges to set or a function that receives the current edges and returns the new edges
|
|
69
|
+
*/
|
|
70
|
+
setEdges: (payload: EdgeType[] | ((edges: EdgeType[]) => EdgeType[])) => void;
|
|
71
|
+
/**
|
|
72
|
+
* Add one or many edges to your existing edges array. Calling this function will trigger the
|
|
73
|
+
* `onEdgesChange` handler in a controlled flow.
|
|
74
|
+
*
|
|
75
|
+
* @param payload - the edges to add
|
|
76
|
+
*/
|
|
77
|
+
addEdges: (payload: EdgeType[] | EdgeType) => void;
|
|
78
|
+
/**
|
|
79
|
+
* Returns an edge by id.
|
|
80
|
+
*
|
|
81
|
+
* @param id - the edge id
|
|
82
|
+
* @returns the edge or undefined if no edge was found
|
|
83
|
+
*/
|
|
84
|
+
getEdge: (id: string) => EdgeType | undefined;
|
|
85
|
+
/**
|
|
86
|
+
* Returns the nodes, edges and the viewport as a JSON object.
|
|
87
|
+
*
|
|
88
|
+
* @returns the nodes, edges and the viewport as a JSON object
|
|
89
|
+
*/
|
|
90
|
+
toObject: () => ReactFlowJsonObject<NodeType, EdgeType>;
|
|
91
|
+
/**
|
|
92
|
+
* Deletes nodes and edges.
|
|
93
|
+
*
|
|
94
|
+
* @param params.nodes - optional nodes array to delete
|
|
95
|
+
* @param params.edges - optional edges array to delete
|
|
96
|
+
*
|
|
97
|
+
* @returns a promise that resolves with the deleted nodes and edges
|
|
98
|
+
*/
|
|
99
|
+
deleteElements: (params: DeleteElementsOptions) => Promise<{
|
|
100
|
+
deletedNodes: Node[];
|
|
101
|
+
deletedEdges: Edge[];
|
|
102
|
+
}>;
|
|
103
|
+
/**
|
|
104
|
+
* Find all the nodes currently intersecting with a given node or rectangle. The `partially`
|
|
105
|
+
* parameter can be set to `true` to include nodes that are only partially intersecting.
|
|
106
|
+
*
|
|
107
|
+
* @param node - the node or rect to check for intersections
|
|
108
|
+
* @param partially - true by default, if set to false, only nodes that are fully intersecting will be returned
|
|
109
|
+
* @param nodes - optional nodes array to check for intersections
|
|
110
|
+
*
|
|
111
|
+
* @returns an array of intersecting nodes
|
|
112
|
+
*/
|
|
113
|
+
getIntersectingNodes: (
|
|
114
|
+
node: NodeType | { id: Node['id'] } | Rect,
|
|
115
|
+
partially?: boolean,
|
|
116
|
+
nodes?: NodeType[],
|
|
117
|
+
) => NodeType[];
|
|
118
|
+
/**
|
|
119
|
+
* Determine if a given node or rectangle is intersecting with another rectangle. The `partially`
|
|
120
|
+
* parameter can be set to true return `true` even if the node is only partially intersecting.
|
|
121
|
+
*
|
|
122
|
+
* @param node - the node or rect to check for intersections
|
|
123
|
+
* @param area - the rect to check for intersections
|
|
124
|
+
* @param partially - if true, the node is considered to be intersecting if it partially overlaps with the passed react
|
|
125
|
+
*
|
|
126
|
+
* @returns true if the node or rect intersects with the given area
|
|
127
|
+
*/
|
|
128
|
+
isNodeIntersecting: (
|
|
129
|
+
node: NodeType | { id: Node['id'] } | Rect,
|
|
130
|
+
area: Rect,
|
|
131
|
+
partially?: boolean,
|
|
132
|
+
) => boolean;
|
|
133
|
+
/**
|
|
134
|
+
* Updates a node.
|
|
135
|
+
*
|
|
136
|
+
* @param id - id of the node to update
|
|
137
|
+
* @param nodeUpdate - the node update as an object or a function that receives the current node and returns the node update
|
|
138
|
+
* @param options.replace - if true, the node is replaced with the node update, otherwise the changes get merged
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* updateNode('node-1', (node) => ({ position: { x: node.position.x + 10, y: node.position.y } }));
|
|
142
|
+
*/
|
|
143
|
+
updateNode: (
|
|
144
|
+
id: string,
|
|
145
|
+
nodeUpdate: Partial<NodeType> | ((node: NodeType) => Partial<NodeType>),
|
|
146
|
+
options?: { replace: boolean },
|
|
147
|
+
) => void;
|
|
148
|
+
/**
|
|
149
|
+
* Updates the data attribute of a node.
|
|
150
|
+
*
|
|
151
|
+
* @param id - id of the node to update
|
|
152
|
+
* @param dataUpdate - the data update as an object or a function that receives the current data and returns the data update
|
|
153
|
+
* @param options.replace - if true, the data is replaced with the data update, otherwise the changes get merged
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* updateNodeData('node-1', { label: 'A new label' });
|
|
157
|
+
*/
|
|
158
|
+
updateNodeData: (
|
|
159
|
+
id: string,
|
|
160
|
+
dataUpdate: Partial<NodeType['data']> | ((node: NodeType) => Partial<NodeType['data']>),
|
|
161
|
+
options?: { replace: boolean },
|
|
162
|
+
) => void;
|
|
163
|
+
/**
|
|
164
|
+
* Updates an edge.
|
|
165
|
+
*
|
|
166
|
+
* @param id - id of the edge to update
|
|
167
|
+
* @param edgeUpdate - the edge update as an object or a function that receives the current edge and returns the edge update
|
|
168
|
+
* @param options.replace - if true, the edge is replaced with the edge update, otherwise the changes get merged
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* updateEdge('edge-1', (edge) => ({ label: 'A new label' }));
|
|
172
|
+
*/
|
|
173
|
+
updateEdge: (
|
|
174
|
+
id: string,
|
|
175
|
+
edgeUpdate: Partial<EdgeType> | ((edge: EdgeType) => Partial<EdgeType>),
|
|
176
|
+
options?: { replace: boolean },
|
|
177
|
+
) => void;
|
|
178
|
+
/**
|
|
179
|
+
* Updates the data attribute of a edge.
|
|
180
|
+
*
|
|
181
|
+
* @param id - id of the edge to update
|
|
182
|
+
* @param dataUpdate - the data update as an object or a function that receives the current data and returns the data update
|
|
183
|
+
* @param options.replace - if true, the data is replaced with the data update, otherwise the changes get merged
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* updateEdgeData('edge-1', { label: 'A new label' });
|
|
187
|
+
*/
|
|
188
|
+
updateEdgeData: (
|
|
189
|
+
id: string,
|
|
190
|
+
dataUpdate: Partial<EdgeType['data']> | ((edge: EdgeType) => Partial<EdgeType['data']>),
|
|
191
|
+
options?: { replace: boolean },
|
|
192
|
+
) => void;
|
|
193
|
+
/**
|
|
194
|
+
* Returns the bounds of the given nodes or node ids.
|
|
195
|
+
*
|
|
196
|
+
* @param nodes - the nodes or node ids to calculate the bounds for
|
|
197
|
+
*
|
|
198
|
+
* @returns the bounds of the given nodes
|
|
199
|
+
*/
|
|
200
|
+
getNodesBounds: (nodes: (NodeType | InternalNode | string)[]) => Rect;
|
|
201
|
+
/**
|
|
202
|
+
* Get all the connections of a handle belonging to a specific node. The type parameter be either
|
|
203
|
+
* `'source'` or `'target'`.
|
|
204
|
+
* @deprecated
|
|
205
|
+
* @param type - handle type 'source' or 'target'
|
|
206
|
+
* @param id - the handle id (this is only needed if you have multiple handles of the same type, meaning you have to provide a unique id for each handle)
|
|
207
|
+
* @param nodeId - the node id the handle belongs to
|
|
208
|
+
* @returns an array with handle connections
|
|
209
|
+
*/
|
|
210
|
+
getHandleConnections: ({
|
|
211
|
+
type,
|
|
212
|
+
id,
|
|
213
|
+
nodeId,
|
|
214
|
+
}: {
|
|
215
|
+
type: HandleType;
|
|
216
|
+
nodeId: string;
|
|
217
|
+
id?: string | null;
|
|
218
|
+
}) => HandleConnection[];
|
|
219
|
+
/**
|
|
220
|
+
* Gets all connections to a node. Can be filtered by handle type and id.
|
|
221
|
+
* @param type - handle type 'source' or 'target'
|
|
222
|
+
* @param handleId - the handle id (this is only needed if you have multiple handles of the same type, meaning you have to provide a unique id for each handle)
|
|
223
|
+
* @param nodeId - the node id the handle belongs to
|
|
224
|
+
* @returns an array with handle connections
|
|
225
|
+
*/
|
|
226
|
+
getNodeConnections: ({
|
|
227
|
+
type,
|
|
228
|
+
handleId,
|
|
229
|
+
nodeId,
|
|
230
|
+
}: {
|
|
231
|
+
type?: HandleType;
|
|
232
|
+
nodeId: string;
|
|
233
|
+
handleId?: string | null;
|
|
234
|
+
}) => NodeConnection[];
|
|
235
|
+
/**
|
|
236
|
+
* Fits the view based on the passed params. By default it fits the view to all nodes.
|
|
237
|
+
*
|
|
238
|
+
* @param options.padding - optional padding
|
|
239
|
+
* @param options.nodes - optional nodes to fit the view to
|
|
240
|
+
* @param options.minZoom - optional minZoom
|
|
241
|
+
* @param options.maxZoom - optional maxZoom
|
|
242
|
+
* @param options.duration - optional duration. If set, a transition will be applied
|
|
243
|
+
* @param options.includeHiddenNodes - optional includeHiddenNodes
|
|
244
|
+
*/
|
|
245
|
+
fitView: FitView<NodeType>;
|
|
246
|
+
};
|
|
247
|
+
/**
|
|
248
|
+
* The `ReactFlowInstance` provides a collection of methods to query and manipulate
|
|
249
|
+
* the internal state of your flow. You can get an instance by using the
|
|
250
|
+
* [`useReactFlow`](/api-reference/hooks/use-react-flow) hook or attaching a listener
|
|
251
|
+
* to the [`onInit`](/api-reference/react-flow#event-oninit) event.
|
|
252
|
+
*
|
|
253
|
+
* @public
|
|
254
|
+
*/
|
|
255
|
+
export type ReactFlowInstance<
|
|
256
|
+
NodeType extends Node = Node,
|
|
257
|
+
EdgeType extends Edge = Edge,
|
|
258
|
+
> = GeneralHelpers<NodeType, EdgeType> &
|
|
259
|
+
ViewportHelperFunctions & {
|
|
260
|
+
/**
|
|
261
|
+
* React Flow needs to mount the viewport to the DOM and initialize its zoom and pan behavior.
|
|
262
|
+
* This property tells you when viewport is initialized.
|
|
263
|
+
*/
|
|
264
|
+
viewportInitialized: boolean;
|
|
265
|
+
};
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
CSSProperties,
|
|
3
|
+
MouseEvent as ReactMouseEvent,
|
|
4
|
+
AriaRole,
|
|
5
|
+
HTMLAttributes,
|
|
6
|
+
DOMAttributes,
|
|
7
|
+
} from '../react-shim.js';
|
|
8
|
+
import type {
|
|
9
|
+
CoordinateExtent,
|
|
10
|
+
NodeBase,
|
|
11
|
+
OnError,
|
|
12
|
+
NodeProps as NodePropsBase,
|
|
13
|
+
InternalNodeBase,
|
|
14
|
+
} from '@xyflow/system';
|
|
15
|
+
|
|
16
|
+
import { NodeTypes } from './general';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The `Node` type represents everything React Flow needs to know about a given node.
|
|
20
|
+
* Whenever you want to update a certain attribute of a node, you need to create a new
|
|
21
|
+
* node object.
|
|
22
|
+
*
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
export type Node<
|
|
26
|
+
NodeData extends Record<string, unknown> = Record<string, unknown>,
|
|
27
|
+
NodeType extends string | undefined = string | undefined,
|
|
28
|
+
> = NodeBase<NodeData, NodeType> & {
|
|
29
|
+
style?: CSSProperties;
|
|
30
|
+
className?: string;
|
|
31
|
+
resizing?: boolean;
|
|
32
|
+
focusable?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* The ARIA role attribute for the node element, used for accessibility.
|
|
35
|
+
* @default "group"
|
|
36
|
+
*/
|
|
37
|
+
ariaRole?: AriaRole;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* General escape hatch for adding custom attributes to the node's DOM element.
|
|
41
|
+
*/
|
|
42
|
+
domAttributes?: Omit<
|
|
43
|
+
HTMLAttributes<HTMLDivElement>,
|
|
44
|
+
| 'id'
|
|
45
|
+
| 'style'
|
|
46
|
+
| 'className'
|
|
47
|
+
| 'draggable'
|
|
48
|
+
| 'role'
|
|
49
|
+
| 'aria-label'
|
|
50
|
+
| 'defaultValue'
|
|
51
|
+
| 'dangerouslySetInnerHTML'
|
|
52
|
+
| keyof DOMAttributes<HTMLDivElement>
|
|
53
|
+
>;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The `InternalNode` type is identical to the base [`Node`](/api-references/types/node)
|
|
58
|
+
* type but is extended with some additional properties used internally.
|
|
59
|
+
* Some functions and callbacks that return nodes may return an `InternalNode`.
|
|
60
|
+
*
|
|
61
|
+
* @public
|
|
62
|
+
*/
|
|
63
|
+
export type InternalNode<NodeType extends Node = Node> = InternalNodeBase<NodeType>;
|
|
64
|
+
|
|
65
|
+
export type NodeMouseHandler<NodeType extends Node = Node> = (
|
|
66
|
+
event: ReactMouseEvent,
|
|
67
|
+
node: NodeType,
|
|
68
|
+
) => void;
|
|
69
|
+
export type SelectionDragHandler<NodeType extends Node = Node> = (
|
|
70
|
+
event: ReactMouseEvent,
|
|
71
|
+
nodes: NodeType[],
|
|
72
|
+
) => void;
|
|
73
|
+
export type OnNodeDrag<NodeType extends Node = Node> = (
|
|
74
|
+
event: MouseEvent | TouchEvent,
|
|
75
|
+
node: NodeType,
|
|
76
|
+
nodes: NodeType[],
|
|
77
|
+
) => void;
|
|
78
|
+
|
|
79
|
+
export type NodeWrapperProps<NodeType extends Node> = {
|
|
80
|
+
id: string;
|
|
81
|
+
nodesConnectable: boolean;
|
|
82
|
+
elementsSelectable: boolean;
|
|
83
|
+
nodesDraggable: boolean;
|
|
84
|
+
nodesFocusable: boolean;
|
|
85
|
+
onClick?: NodeMouseHandler<NodeType>;
|
|
86
|
+
onDoubleClick?: NodeMouseHandler<NodeType>;
|
|
87
|
+
onMouseEnter?: NodeMouseHandler<NodeType>;
|
|
88
|
+
onMouseMove?: NodeMouseHandler<NodeType>;
|
|
89
|
+
onMouseLeave?: NodeMouseHandler<NodeType>;
|
|
90
|
+
onContextMenu?: NodeMouseHandler<NodeType>;
|
|
91
|
+
resizeObserver: ResizeObserver | null;
|
|
92
|
+
noDragClassName: string;
|
|
93
|
+
noPanClassName: string;
|
|
94
|
+
rfId: string;
|
|
95
|
+
disableKeyboardA11y: boolean;
|
|
96
|
+
nodeTypes?: NodeTypes;
|
|
97
|
+
nodeExtent?: CoordinateExtent;
|
|
98
|
+
onError?: OnError;
|
|
99
|
+
nodeClickDistance?: number;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* The `BuiltInNode` type represents the built-in node types that are available in React Flow.
|
|
104
|
+
* You can use this type to extend your custom node type if you still want to use the built-in ones.
|
|
105
|
+
*
|
|
106
|
+
* @public
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* type CustomNode = Node<{ value: number }, 'custom'>;
|
|
110
|
+
* type MyAppNode = CustomNode | BuiltInNode;
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
export type BuiltInNode =
|
|
114
|
+
| Node<{ label: string }, 'input' | 'output' | 'default' | undefined>
|
|
115
|
+
| Node<Record<string, never>, 'group'>;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* When you implement a [custom node](/learn/customization/custom-nodes) it is
|
|
119
|
+
* wrapped in a component that enables basic functionality like selection and
|
|
120
|
+
* dragging. Your custom node receives `NodeProps` as props.
|
|
121
|
+
*
|
|
122
|
+
* @public
|
|
123
|
+
* @example
|
|
124
|
+
* ```tsx
|
|
125
|
+
*import { useState } from 'octane';
|
|
126
|
+
*import { NodeProps, Node } from '@xyflow/react';
|
|
127
|
+
*
|
|
128
|
+
*export type CounterNode = Node<{ initialCount?: number }, 'counter'>;
|
|
129
|
+
*
|
|
130
|
+
*export default function CounterNode(props: NodeProps<CounterNode>) {
|
|
131
|
+
* const [count, setCount] = useState(props.data?.initialCount ?? 0);
|
|
132
|
+
*
|
|
133
|
+
* return (
|
|
134
|
+
* <div>
|
|
135
|
+
* <p>Count: {count}</p>
|
|
136
|
+
* <button className="nodrag" onClick={() => setCount(count + 1)}>
|
|
137
|
+
* Increment
|
|
138
|
+
* </button>
|
|
139
|
+
* </div>
|
|
140
|
+
* );
|
|
141
|
+
*}
|
|
142
|
+
*```
|
|
143
|
+
*/
|
|
144
|
+
export type NodeProps<NodeType extends Node = Node> = NodePropsBase<NodeType>;
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ConnectionMode,
|
|
3
|
+
withResolvers,
|
|
4
|
+
type ConnectionState,
|
|
5
|
+
type CoordinateExtent,
|
|
6
|
+
type InternalNodeUpdate,
|
|
7
|
+
type UpdateNodePositions,
|
|
8
|
+
type NodeOrigin,
|
|
9
|
+
type OnConnect,
|
|
10
|
+
type OnError,
|
|
11
|
+
type OnViewportChange,
|
|
12
|
+
type SelectionRect,
|
|
13
|
+
type SnapGrid,
|
|
14
|
+
type Handle,
|
|
15
|
+
type Transform,
|
|
16
|
+
type PanZoomInstance,
|
|
17
|
+
type PanBy,
|
|
18
|
+
type OnConnectStart,
|
|
19
|
+
type OnConnectEnd,
|
|
20
|
+
type OnSelectionDrag,
|
|
21
|
+
type OnMoveStart,
|
|
22
|
+
type OnMove,
|
|
23
|
+
type OnMoveEnd,
|
|
24
|
+
type UpdateConnection,
|
|
25
|
+
type EdgeLookup,
|
|
26
|
+
type ConnectionLookup,
|
|
27
|
+
type NodeLookup,
|
|
28
|
+
type NodeChange,
|
|
29
|
+
type EdgeChange,
|
|
30
|
+
type ParentLookup,
|
|
31
|
+
type AriaLabelConfig,
|
|
32
|
+
type SetCenter,
|
|
33
|
+
type ZIndexMode,
|
|
34
|
+
} from '@xyflow/system';
|
|
35
|
+
|
|
36
|
+
import type {
|
|
37
|
+
Edge,
|
|
38
|
+
Node,
|
|
39
|
+
OnNodesChange,
|
|
40
|
+
OnEdgesChange,
|
|
41
|
+
DefaultEdgeOptions,
|
|
42
|
+
FitViewOptions,
|
|
43
|
+
OnNodesDelete,
|
|
44
|
+
OnEdgesDelete,
|
|
45
|
+
OnSelectionChangeFunc,
|
|
46
|
+
UnselectNodesAndEdgesParams,
|
|
47
|
+
OnDelete,
|
|
48
|
+
OnNodeDrag,
|
|
49
|
+
OnBeforeDelete,
|
|
50
|
+
IsValidConnection,
|
|
51
|
+
InternalNode,
|
|
52
|
+
} from '.';
|
|
53
|
+
|
|
54
|
+
export type ReactFlowStore<NodeType extends Node = Node, EdgeType extends Edge = Edge> = {
|
|
55
|
+
rfId: string;
|
|
56
|
+
width: number;
|
|
57
|
+
height: number;
|
|
58
|
+
transform: Transform;
|
|
59
|
+
nodes: NodeType[];
|
|
60
|
+
nodesInitialized: boolean;
|
|
61
|
+
nodeLookup: NodeLookup<InternalNode<NodeType>>;
|
|
62
|
+
parentLookup: ParentLookup<InternalNode<NodeType>>;
|
|
63
|
+
edges: EdgeType[];
|
|
64
|
+
edgeLookup: EdgeLookup<EdgeType>;
|
|
65
|
+
connectionLookup: ConnectionLookup;
|
|
66
|
+
onNodesChange: OnNodesChange<NodeType> | null;
|
|
67
|
+
onEdgesChange: OnEdgesChange<EdgeType> | null;
|
|
68
|
+
hasDefaultNodes: boolean;
|
|
69
|
+
hasDefaultEdges: boolean;
|
|
70
|
+
domNode: HTMLDivElement | null;
|
|
71
|
+
paneDragging: boolean;
|
|
72
|
+
noPanClassName: string;
|
|
73
|
+
panZoom: PanZoomInstance | null;
|
|
74
|
+
minZoom: number;
|
|
75
|
+
maxZoom: number;
|
|
76
|
+
translateExtent: CoordinateExtent;
|
|
77
|
+
nodeExtent: CoordinateExtent;
|
|
78
|
+
nodeOrigin: NodeOrigin;
|
|
79
|
+
nodeDragThreshold: number;
|
|
80
|
+
connectionDragThreshold: number;
|
|
81
|
+
|
|
82
|
+
nodesSelectionActive: boolean;
|
|
83
|
+
userSelectionActive: boolean;
|
|
84
|
+
userSelectionRect: SelectionRect | null;
|
|
85
|
+
|
|
86
|
+
connection: ConnectionState<InternalNode<NodeType>>;
|
|
87
|
+
connectionMode: ConnectionMode;
|
|
88
|
+
connectionClickStartHandle:
|
|
89
|
+
(Pick<Handle, 'nodeId' | 'id'> & Required<Pick<Handle, 'type'>>) | null;
|
|
90
|
+
|
|
91
|
+
snapToGrid: boolean;
|
|
92
|
+
snapGrid: SnapGrid;
|
|
93
|
+
|
|
94
|
+
nodesDraggable: boolean;
|
|
95
|
+
autoPanOnNodeFocus: boolean;
|
|
96
|
+
nodesConnectable: boolean;
|
|
97
|
+
nodesFocusable: boolean;
|
|
98
|
+
edgesFocusable: boolean;
|
|
99
|
+
edgesReconnectable: boolean;
|
|
100
|
+
elementsSelectable: boolean;
|
|
101
|
+
elevateNodesOnSelect: boolean;
|
|
102
|
+
elevateEdgesOnSelect: boolean;
|
|
103
|
+
selectNodesOnDrag: boolean;
|
|
104
|
+
|
|
105
|
+
multiSelectionActive: boolean;
|
|
106
|
+
|
|
107
|
+
onNodeDragStart?: OnNodeDrag<NodeType>;
|
|
108
|
+
onNodeDrag?: OnNodeDrag<NodeType>;
|
|
109
|
+
onNodeDragStop?: OnNodeDrag<NodeType>;
|
|
110
|
+
|
|
111
|
+
onSelectionDragStart?: OnSelectionDrag;
|
|
112
|
+
onSelectionDrag?: OnSelectionDrag;
|
|
113
|
+
onSelectionDragStop?: OnSelectionDrag;
|
|
114
|
+
|
|
115
|
+
onMoveStart?: OnMoveStart;
|
|
116
|
+
onMove?: OnMove;
|
|
117
|
+
onMoveEnd?: OnMoveEnd;
|
|
118
|
+
|
|
119
|
+
onConnect?: OnConnect;
|
|
120
|
+
onConnectStart?: OnConnectStart;
|
|
121
|
+
onConnectEnd?: OnConnectEnd;
|
|
122
|
+
|
|
123
|
+
onClickConnectStart?: OnConnectStart;
|
|
124
|
+
onClickConnectEnd?: OnConnectEnd;
|
|
125
|
+
|
|
126
|
+
connectOnClick: boolean;
|
|
127
|
+
defaultEdgeOptions?: DefaultEdgeOptions;
|
|
128
|
+
|
|
129
|
+
fitViewQueued: boolean;
|
|
130
|
+
fitViewOptions: FitViewOptions | undefined;
|
|
131
|
+
fitViewResolver: ReturnType<typeof withResolvers<boolean>> | null;
|
|
132
|
+
|
|
133
|
+
onNodesDelete?: OnNodesDelete<NodeType>;
|
|
134
|
+
onEdgesDelete?: OnEdgesDelete<EdgeType>;
|
|
135
|
+
onDelete?: OnDelete;
|
|
136
|
+
onError?: OnError;
|
|
137
|
+
|
|
138
|
+
// event handlers
|
|
139
|
+
onViewportChangeStart?: OnViewportChange;
|
|
140
|
+
onViewportChange?: OnViewportChange;
|
|
141
|
+
onViewportChangeEnd?: OnViewportChange;
|
|
142
|
+
onBeforeDelete?: OnBeforeDelete<NodeType, EdgeType>;
|
|
143
|
+
|
|
144
|
+
onSelectionChangeHandlers: OnSelectionChangeFunc<NodeType, EdgeType>[];
|
|
145
|
+
|
|
146
|
+
ariaLiveMessage: string;
|
|
147
|
+
autoPanOnConnect: boolean;
|
|
148
|
+
autoPanOnNodeDrag: boolean;
|
|
149
|
+
autoPanSpeed: number;
|
|
150
|
+
connectionRadius: number;
|
|
151
|
+
|
|
152
|
+
isValidConnection?: IsValidConnection<EdgeType>;
|
|
153
|
+
|
|
154
|
+
lib: string;
|
|
155
|
+
debug: boolean;
|
|
156
|
+
ariaLabelConfig: AriaLabelConfig;
|
|
157
|
+
|
|
158
|
+
zIndexMode: ZIndexMode;
|
|
159
|
+
onNodesChangeMiddlewareMap: Map<
|
|
160
|
+
symbol,
|
|
161
|
+
(changes: NodeChange<NodeType>[]) => NodeChange<NodeType>[]
|
|
162
|
+
>;
|
|
163
|
+
onEdgesChangeMiddlewareMap: Map<
|
|
164
|
+
symbol,
|
|
165
|
+
(changes: EdgeChange<EdgeType>[]) => EdgeChange<EdgeType>[]
|
|
166
|
+
>;
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
export type ReactFlowActions<NodeType extends Node, EdgeType extends Edge> = {
|
|
170
|
+
setNodes: (nodes: NodeType[]) => void;
|
|
171
|
+
setEdges: (edges: EdgeType[]) => void;
|
|
172
|
+
setDefaultNodesAndEdges: (nodes?: NodeType[], edges?: EdgeType[]) => void;
|
|
173
|
+
updateNodeInternals: (
|
|
174
|
+
updates: Map<string, InternalNodeUpdate>,
|
|
175
|
+
params?: { triggerFitView: boolean },
|
|
176
|
+
) => void;
|
|
177
|
+
updateNodePositions: UpdateNodePositions;
|
|
178
|
+
resetSelectedElements: () => void;
|
|
179
|
+
unselectNodesAndEdges: (params?: UnselectNodesAndEdgesParams<NodeType, EdgeType>) => void;
|
|
180
|
+
addSelectedNodes: (nodeIds: string[]) => void;
|
|
181
|
+
addSelectedEdges: (edgeIds: string[]) => void;
|
|
182
|
+
setMinZoom: (minZoom: number) => void;
|
|
183
|
+
setMaxZoom: (maxZoom: number) => void;
|
|
184
|
+
setTranslateExtent: (translateExtent: CoordinateExtent) => void;
|
|
185
|
+
setNodeExtent: (nodeExtent: CoordinateExtent) => void;
|
|
186
|
+
cancelConnection: () => void;
|
|
187
|
+
updateConnection: UpdateConnection<InternalNode<NodeType>>;
|
|
188
|
+
reset: () => void;
|
|
189
|
+
triggerNodeChanges: (changes: NodeChange<NodeType>[]) => void;
|
|
190
|
+
triggerEdgeChanges: (changes: EdgeChange<EdgeType>[]) => void;
|
|
191
|
+
panBy: PanBy;
|
|
192
|
+
setCenter: SetCenter;
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
export type ReactFlowState<
|
|
196
|
+
NodeType extends Node = Node,
|
|
197
|
+
EdgeType extends Edge = Edge,
|
|
198
|
+
> = ReactFlowStore<NodeType, EdgeType> & ReactFlowActions<NodeType, EdgeType>;
|