@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.
Files changed (135) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +26 -0
  3. package/package.json +69 -0
  4. package/src/additional-components/Background/Background.tsrx +144 -0
  5. package/src/additional-components/Background/Patterns.tsrx +32 -0
  6. package/src/additional-components/Background/index.tsrx +2 -0
  7. package/src/additional-components/Background/types.ts +60 -0
  8. package/src/additional-components/Controls/ControlButton.tsrx +34 -0
  9. package/src/additional-components/Controls/Controls.tsrx +148 -0
  10. package/src/additional-components/Controls/Icons/FitView.tsrx +7 -0
  11. package/src/additional-components/Controls/Icons/Lock.tsrx +7 -0
  12. package/src/additional-components/Controls/Icons/Minus.tsrx +5 -0
  13. package/src/additional-components/Controls/Icons/Plus.tsrx +5 -0
  14. package/src/additional-components/Controls/Icons/Unlock.tsrx +7 -0
  15. package/src/additional-components/Controls/index.tsrx +3 -0
  16. package/src/additional-components/Controls/types.ts +68 -0
  17. package/src/additional-components/EdgeToolbar/EdgeToolbar.tsrx +79 -0
  18. package/src/additional-components/EdgeToolbar/index.tsrx +2 -0
  19. package/src/additional-components/EdgeToolbar/types.ts +14 -0
  20. package/src/additional-components/MiniMap/MiniMap.tsrx +249 -0
  21. package/src/additional-components/MiniMap/MiniMapNode.tsrx +43 -0
  22. package/src/additional-components/MiniMap/MiniMapNodes.tsrx +136 -0
  23. package/src/additional-components/MiniMap/index.ts +3 -0
  24. package/src/additional-components/MiniMap/types.ts +139 -0
  25. package/src/additional-components/NodeResizer/NodeResizeControl.tsrx +250 -0
  26. package/src/additional-components/NodeResizer/NodeResizer.tsrx +102 -0
  27. package/src/additional-components/NodeResizer/index.ts +4 -0
  28. package/src/additional-components/NodeResizer/types.ts +122 -0
  29. package/src/additional-components/NodeToolbar/NodeToolbar.tsrx +141 -0
  30. package/src/additional-components/NodeToolbar/NodeToolbarPortal.tsrx +17 -0
  31. package/src/additional-components/NodeToolbar/index.tsrx +2 -0
  32. package/src/additional-components/NodeToolbar/types.ts +32 -0
  33. package/src/additional-components/index.ts +6 -0
  34. package/src/components/A11yDescriptions/index.tsrx +58 -0
  35. package/src/components/Attribution/index.tsrx +31 -0
  36. package/src/components/BatchProvider/index.tsrx +122 -0
  37. package/src/components/BatchProvider/types.ts +7 -0
  38. package/src/components/BatchProvider/useQueue.ts +62 -0
  39. package/src/components/ConnectionLine/index.tsrx +140 -0
  40. package/src/components/EdgeLabelRenderer/index.tsrx +62 -0
  41. package/src/components/EdgeWrapper/EdgeUpdateAnchors.tsrx +151 -0
  42. package/src/components/EdgeWrapper/index.tsrx +274 -0
  43. package/src/components/EdgeWrapper/utils.ts +26 -0
  44. package/src/components/Edges/BaseEdge.tsrx +76 -0
  45. package/src/components/Edges/BezierEdge.tsrx +94 -0
  46. package/src/components/Edges/EdgeAnchor.tsrx +54 -0
  47. package/src/components/Edges/EdgeText.tsrx +97 -0
  48. package/src/components/Edges/SimpleBezierEdge.tsrx +150 -0
  49. package/src/components/Edges/SmoothStepEdge.tsrx +96 -0
  50. package/src/components/Edges/StepEdge.tsrx +55 -0
  51. package/src/components/Edges/StraightEdge.tsrx +81 -0
  52. package/src/components/Edges/index.ts +11 -0
  53. package/src/components/Handle/index.tsrx +314 -0
  54. package/src/components/NodeWrapper/index.tsrx +259 -0
  55. package/src/components/NodeWrapper/useNodeObserver.ts +79 -0
  56. package/src/components/NodeWrapper/utils.tsrx +40 -0
  57. package/src/components/Nodes/DefaultNode.tsrx +17 -0
  58. package/src/components/Nodes/GroupNode.tsrx +3 -0
  59. package/src/components/Nodes/InputNode.tsrx +13 -0
  60. package/src/components/Nodes/OutputNode.tsrx +13 -0
  61. package/src/components/Nodes/utils.ts +45 -0
  62. package/src/components/NodesSelection/index.tsrx +103 -0
  63. package/src/components/Panel/index.tsrx +34 -0
  64. package/src/components/ReactFlowProvider/index.tsrx +128 -0
  65. package/src/components/SelectionListener/index.tsrx +73 -0
  66. package/src/components/StoreUpdater/index.tsrx +173 -0
  67. package/src/components/UserSelection/index.tsrx +27 -0
  68. package/src/components/ViewportPortal/index.tsrx +42 -0
  69. package/src/container/EdgeRenderer/MarkerDefinitions.tsrx +87 -0
  70. package/src/container/EdgeRenderer/MarkerSymbols.tsrx +60 -0
  71. package/src/container/EdgeRenderer/index.tsrx +98 -0
  72. package/src/container/FlowRenderer/index.tsrx +146 -0
  73. package/src/container/GraphView/index.tsrx +212 -0
  74. package/src/container/GraphView/useNodeOrEdgeTypesWarning.ts +39 -0
  75. package/src/container/GraphView/useStylesLoadedWarning.ts +26 -0
  76. package/src/container/NodeRenderer/index.tsrx +103 -0
  77. package/src/container/NodeRenderer/useResizeObserver.ts +38 -0
  78. package/src/container/Pane/index.tsrx +397 -0
  79. package/src/container/ReactFlow/Wrapper.tsrx +66 -0
  80. package/src/container/ReactFlow/index.tsrx +352 -0
  81. package/src/container/ReactFlow/init-values.ts +4 -0
  82. package/src/container/Viewport/index.tsrx +52 -0
  83. package/src/container/ZoomPane/index.tsrx +159 -0
  84. package/src/contexts/HandleConfigContext.tsrx +38 -0
  85. package/src/contexts/NodeIdContext.ts +39 -0
  86. package/src/contexts/StoreContext.ts +8 -0
  87. package/src/custom.d.ts +13 -0
  88. package/src/hooks/slot.ts +22 -0
  89. package/src/hooks/useColorModeClass.ts +50 -0
  90. package/src/hooks/useConnection.ts +69 -0
  91. package/src/hooks/useDrag.ts +95 -0
  92. package/src/hooks/useEdges.ts +32 -0
  93. package/src/hooks/useGlobalKeyHandler.ts +55 -0
  94. package/src/hooks/useHandleConnections.ts +77 -0
  95. package/src/hooks/useInternalNode.ts +47 -0
  96. package/src/hooks/useIsomorphicLayoutEffect.ts +5 -0
  97. package/src/hooks/useKeyPress.ts +217 -0
  98. package/src/hooks/useMoveSelectedNodes.ts +82 -0
  99. package/src/hooks/useNodeConnections.ts +86 -0
  100. package/src/hooks/useNodes.ts +33 -0
  101. package/src/hooks/useNodesData.ts +66 -0
  102. package/src/hooks/useNodesEdgesState.ts +138 -0
  103. package/src/hooks/useNodesInitialized.ts +74 -0
  104. package/src/hooks/useOnEdgesChangeMiddleware.ts +46 -0
  105. package/src/hooks/useOnInitHandler.ts +27 -0
  106. package/src/hooks/useOnNodesChangeMiddleware.ts +46 -0
  107. package/src/hooks/useOnSelectionChange.ts +78 -0
  108. package/src/hooks/useOnViewportChange.ts +68 -0
  109. package/src/hooks/useReactFlow.ts +347 -0
  110. package/src/hooks/useResizeHandler.ts +54 -0
  111. package/src/hooks/useStore.ts +58 -0
  112. package/src/hooks/useUpdateNodeInternals.ts +73 -0
  113. package/src/hooks/useViewport.ts +48 -0
  114. package/src/hooks/useViewportHelper.ts +103 -0
  115. package/src/hooks/useViewportSync.ts +33 -0
  116. package/src/hooks/useVisibleEdgeIds.ts +52 -0
  117. package/src/hooks/useVisibleNodeIds.ts +36 -0
  118. package/src/index.ts +151 -0
  119. package/src/react-shim.ts +93 -0
  120. package/src/store/index.ts +516 -0
  121. package/src/store/initialState.ts +162 -0
  122. package/src/styles/base.css +516 -0
  123. package/src/styles/style.css +648 -0
  124. package/src/styles/utils.ts +9 -0
  125. package/src/types/component-props.ts +716 -0
  126. package/src/types/edges.ts +312 -0
  127. package/src/types/general.ts +239 -0
  128. package/src/types/index.ts +6 -0
  129. package/src/types/instance.ts +265 -0
  130. package/src/types/nodes.ts +144 -0
  131. package/src/types/store.ts +198 -0
  132. package/src/utils/changes.ts +329 -0
  133. package/src/utils/edges.ts +34 -0
  134. package/src/utils/general.ts +72 -0
  135. package/src/utils/index.ts +3 -0
@@ -0,0 +1,312 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+
3
+ import type {
4
+ CSSProperties,
5
+ SVGAttributes,
6
+ OctaneNode,
7
+ MouseEvent as ReactMouseEvent,
8
+ ComponentType,
9
+ AriaRole,
10
+ } from '../react-shim.js';
11
+ import type {
12
+ EdgeBase,
13
+ BezierPathOptions,
14
+ Position,
15
+ SmoothStepPathOptions,
16
+ DefaultEdgeOptionsBase,
17
+ HandleType,
18
+ ConnectionLineType,
19
+ Handle,
20
+ EdgePosition,
21
+ StepPathOptions,
22
+ OnError,
23
+ OnReconnect,
24
+ FinalConnectionState,
25
+ XYPosition,
26
+ } from '@xyflow/system';
27
+
28
+ import { EdgeTypes, InternalNode, Node } from '.';
29
+
30
+ /**
31
+ * @inline
32
+ */
33
+ export type EdgeLabelOptions = {
34
+ /**
35
+ * The label or custom element to render along the edge. This is commonly a text label or some
36
+ * custom controls.
37
+ */
38
+ label?: OctaneNode;
39
+ /**
40
+ * Custom styles to apply to the label.
41
+ */
42
+ labelStyle?: CSSProperties;
43
+ labelShowBg?: boolean;
44
+ labelBgStyle?: CSSProperties;
45
+ labelBgPadding?: [number, number];
46
+ labelBgBorderRadius?: number;
47
+ };
48
+
49
+ /**
50
+ * An `Edge` is the complete description with everything React Flow needs
51
+ * to know in order to render it.
52
+ * @public
53
+ */
54
+ export type Edge<
55
+ EdgeData extends Record<string, unknown> = Record<string, unknown>,
56
+ EdgeType extends string | undefined = string | undefined,
57
+ > = EdgeBase<EdgeData, EdgeType> &
58
+ EdgeLabelOptions & {
59
+ style?: CSSProperties;
60
+ className?: string;
61
+ /**
62
+ * Determines whether the edge can be updated by dragging the source or target to a new node.
63
+ * This property will override the default set by the `edgesReconnectable` prop on the
64
+ * `<ReactFlow />` component.
65
+ */
66
+ reconnectable?: boolean | HandleType;
67
+ focusable?: boolean;
68
+ /**
69
+ * The ARIA role attribute for the edge, used for accessibility.
70
+ * @default "group"
71
+ */
72
+ ariaRole?: AriaRole;
73
+ /**
74
+ * General escape hatch for adding custom attributes to the edge's DOM element.
75
+ */
76
+ domAttributes?: Omit<
77
+ SVGAttributes<SVGGElement>,
78
+ 'id' | 'style' | 'className' | 'role' | 'aria-label' | 'dangerouslySetInnerHTML'
79
+ >;
80
+ };
81
+
82
+ type SmoothStepEdge<EdgeData extends Record<string, unknown> = Record<string, unknown>> = Edge<
83
+ EdgeData,
84
+ 'smoothstep'
85
+ > & {
86
+ pathOptions?: SmoothStepPathOptions;
87
+ };
88
+
89
+ type BezierEdge<EdgeData extends Record<string, unknown> = Record<string, unknown>> = Edge<
90
+ EdgeData,
91
+ 'default'
92
+ > & {
93
+ pathOptions?: BezierPathOptions;
94
+ };
95
+
96
+ type StepEdge<EdgeData extends Record<string, unknown> = Record<string, unknown>> = Edge<
97
+ EdgeData,
98
+ 'step'
99
+ > & {
100
+ pathOptions?: StepPathOptions;
101
+ };
102
+
103
+ type StraightEdge<EdgeData extends Record<string, unknown> = Record<string, unknown>> = Edge<
104
+ EdgeData,
105
+ 'straight'
106
+ >;
107
+
108
+ export type BuiltInEdge = SmoothStepEdge | BezierEdge | StepEdge | StraightEdge;
109
+
110
+ export type EdgeMouseHandler<EdgeType extends Edge = Edge> = (
111
+ event: ReactMouseEvent,
112
+ edge: EdgeType,
113
+ ) => void;
114
+
115
+ export type EdgeWrapperProps<EdgeType extends Edge = Edge> = {
116
+ id: string;
117
+ edgesFocusable: boolean;
118
+ edgesReconnectable: boolean;
119
+ elementsSelectable: boolean;
120
+ noPanClassName: string;
121
+ onClick?: EdgeMouseHandler<EdgeType>;
122
+ onDoubleClick?: EdgeMouseHandler<EdgeType>;
123
+ onReconnect?: OnReconnect<EdgeType>;
124
+ onContextMenu?: EdgeMouseHandler<EdgeType>;
125
+ onMouseEnter?: EdgeMouseHandler<EdgeType>;
126
+ onMouseMove?: EdgeMouseHandler<EdgeType>;
127
+ onMouseLeave?: EdgeMouseHandler<EdgeType>;
128
+ reconnectRadius?: number;
129
+ onReconnectStart?: (event: ReactMouseEvent, edge: EdgeType, handleType: HandleType) => void;
130
+ onReconnectEnd?: (
131
+ event: MouseEvent | TouchEvent,
132
+ edge: EdgeType,
133
+ handleType: HandleType,
134
+ connectionState: FinalConnectionState,
135
+ ) => void;
136
+ rfId?: string;
137
+ edgeTypes?: EdgeTypes;
138
+ onError?: OnError;
139
+ disableKeyboardA11y?: boolean;
140
+ };
141
+
142
+ /**
143
+ * Many properties on an [`Edge`](/api-reference/types/edge) are optional. When a new edge is created,
144
+ * the properties that are not provided will be filled in with the default values
145
+ * passed to the `defaultEdgeOptions` prop of the [`<ReactFlow />`](/api-reference/react-flow#defaultedgeoptions) component.
146
+ */
147
+ export type DefaultEdgeOptions = DefaultEdgeOptionsBase<Edge>;
148
+
149
+ export type EdgeTextProps = Omit<SVGAttributes<SVGElement>, 'x' | 'y'> &
150
+ EdgeLabelOptions & {
151
+ /** The x position where the label should be rendered. */
152
+ x: number;
153
+ /** The y position where the label should be rendered. */
154
+ y: number;
155
+ };
156
+
157
+ /**
158
+ * When you implement a custom edge it is wrapped in a component that enables some
159
+ * basic functionality. The `EdgeProps` type is the props that are passed to this.
160
+ * @public
161
+ * @expand
162
+ */
163
+ export type EdgeProps<EdgeType extends Edge = Edge> = Pick<
164
+ EdgeType,
165
+ | 'id'
166
+ | 'type'
167
+ | 'animated'
168
+ | 'data'
169
+ | 'style'
170
+ | 'selected'
171
+ | 'source'
172
+ | 'target'
173
+ | 'selectable'
174
+ | 'deletable'
175
+ > &
176
+ EdgePosition &
177
+ EdgeLabelOptions & {
178
+ sourceHandleId?: string | null;
179
+ targetHandleId?: string | null;
180
+ markerStart?: string;
181
+ markerEnd?: string;
182
+ // @TODO: how can we get better types for pathOptions?
183
+ pathOptions?: any;
184
+ interactionWidth?: number;
185
+ };
186
+
187
+ /**
188
+ * BaseEdge component props
189
+ * @public
190
+ * @expand
191
+ */
192
+ export type BaseEdgeProps = Omit<
193
+ SVGAttributes<SVGPathElement>,
194
+ 'd' | 'path' | 'markerStart' | 'markerEnd'
195
+ > &
196
+ EdgeLabelOptions & {
197
+ /**
198
+ * The width of the invisible area around the edge that the user can interact with. This is
199
+ * useful for making the edge easier to click or hover over.
200
+ * @default 20
201
+ */
202
+ interactionWidth?: number;
203
+ /** The x position of edge label */
204
+ labelX?: number;
205
+ /** The y position of edge label */
206
+ labelY?: number;
207
+ /**
208
+ * The SVG path string that defines the edge. This should look something like
209
+ * `'M 0 0 L 100 100'` for a simple line. The utility functions like `getSimpleBezierEdge` can
210
+ * be used to generate this string for you.
211
+ */
212
+ path: string;
213
+ /**
214
+ * The id of the SVG marker to use at the start of the edge. This should be defined in a
215
+ * `<defs>` element in a separate SVG document or element. Use the format "url(#markerId)" where markerId is the id of your marker definition.
216
+ */
217
+ markerStart?: string;
218
+ /**
219
+ * The id of the SVG marker to use at the end of the edge. This should be defined in a `<defs>`
220
+ * element in a separate SVG document or element. Use the format "url(#markerId)" where markerId is the id of your marker definition.
221
+ */
222
+ markerEnd?: string;
223
+ };
224
+
225
+ /**
226
+ * Helper type for edge components that get exported by the library
227
+ * @public
228
+ * @expand
229
+ */
230
+ export type EdgeComponentProps = EdgePosition &
231
+ EdgeLabelOptions & {
232
+ id?: EdgeProps['id'];
233
+ markerStart?: EdgeProps['markerStart'];
234
+ markerEnd?: EdgeProps['markerEnd'];
235
+ interactionWidth?: EdgeProps['interactionWidth'];
236
+ style?: EdgeProps['style'];
237
+ sourceHandleId?: EdgeProps['sourceHandleId'];
238
+ targetHandleId?: EdgeProps['targetHandleId'];
239
+ };
240
+
241
+ export type EdgeComponentWithPathOptions<PathOptions> = EdgeComponentProps & {
242
+ pathOptions?: PathOptions;
243
+ };
244
+
245
+ /**
246
+ * BezierEdge component props
247
+ * @public
248
+ * @expand
249
+ */
250
+ export type BezierEdgeProps = EdgeComponentWithPathOptions<BezierPathOptions>;
251
+
252
+ /**
253
+ * SmoothStepEdge component props
254
+ * @public
255
+ * @expand
256
+ */
257
+ export type SmoothStepEdgeProps = EdgeComponentWithPathOptions<SmoothStepPathOptions>;
258
+
259
+ /**
260
+ * StepEdge component props
261
+ * @public
262
+ * @expand
263
+ */
264
+ export type StepEdgeProps = EdgeComponentWithPathOptions<StepPathOptions>;
265
+
266
+ /**
267
+ * StraightEdge component props
268
+ * @public
269
+ * @expand
270
+ */
271
+ export type StraightEdgeProps = Omit<EdgeComponentProps, 'sourcePosition' | 'targetPosition'>;
272
+
273
+ /**
274
+ * SimpleBezier component props
275
+ * @public
276
+ * @expand
277
+ */
278
+ export type SimpleBezierEdgeProps = EdgeComponentProps;
279
+
280
+ /**
281
+ * If you want to render a custom component for connection lines, you can set the
282
+ * `connectionLineComponent` prop on the [`<ReactFlow />`](/api-reference/react-flow#connection-connectionLineComponent)
283
+ * component. The `ConnectionLineComponentProps` are passed to your custom component.
284
+ *
285
+ * @public
286
+ */
287
+ export type ConnectionLineComponentProps<NodeType extends Node = Node> = {
288
+ connectionLineStyle?: CSSProperties;
289
+ connectionLineType: ConnectionLineType;
290
+ /** The node the connection line originates from. */
291
+ fromNode: InternalNode<NodeType>;
292
+ /** The handle on the `fromNode` that the connection line originates from. */
293
+ fromHandle: Handle;
294
+ fromX: number;
295
+ fromY: number;
296
+ toX: number;
297
+ toY: number;
298
+ fromPosition: Position;
299
+ toPosition: Position;
300
+ /**
301
+ * If there is an `isValidConnection` callback, this prop will be set to `"valid"` or `"invalid"`
302
+ * based on the return value of that callback. Otherwise, it will be `null`.
303
+ */
304
+ connectionStatus: 'valid' | 'invalid' | null;
305
+ toNode: InternalNode<NodeType> | null;
306
+ toHandle: Handle | null;
307
+ pointer: XYPosition;
308
+ };
309
+
310
+ export type ConnectionLineComponent<NodeType extends Node = Node> = ComponentType<
311
+ ConnectionLineComponentProps<NodeType>
312
+ >;
@@ -0,0 +1,239 @@
1
+ import type { ComponentType } from '../react-shim.js';
2
+ import {
3
+ FitViewParamsBase,
4
+ FitViewOptionsBase,
5
+ ZoomInOut,
6
+ ZoomTo,
7
+ SetViewport,
8
+ GetZoom,
9
+ GetViewport,
10
+ SetCenter,
11
+ FitBounds,
12
+ XYPosition,
13
+ OnBeforeDeleteBase,
14
+ Connection,
15
+ NodeChange,
16
+ EdgeChange,
17
+ SnapGrid,
18
+ } from '@xyflow/system';
19
+
20
+ import type { Node, Edge, ReactFlowInstance, EdgeProps, NodeProps } from '.';
21
+
22
+ /**
23
+ * This type can be used to type the `onNodesChange` function with a custom node type.
24
+ *
25
+ * @public
26
+ *
27
+ * @example
28
+ *
29
+ * ```ts
30
+ * const onNodesChange: OnNodesChange<MyNodeType> = useCallback((changes) => {
31
+ * setNodes((nodes) => applyNodeChanges(nodes, changes));
32
+ * },[]);
33
+ * ```
34
+ */
35
+ export type OnNodesChange<NodeType extends Node = Node> = (changes: NodeChange<NodeType>[]) => void;
36
+
37
+ /**
38
+ * This type can be used to type the `onEdgesChange` function with a custom edge type.
39
+ *
40
+ * @public
41
+ *
42
+ * @example
43
+ *
44
+ * ```ts
45
+ * const onEdgesChange: OnEdgesChange<MyEdgeType> = useCallback((changes) => {
46
+ * setEdges((edges) => applyEdgeChanges(edges, changes));
47
+ * },[]);
48
+ * ```
49
+ */
50
+ export type OnEdgesChange<EdgeType extends Edge = Edge> = (changes: EdgeChange<EdgeType>[]) => void;
51
+
52
+ export type OnNodesDelete<NodeType extends Node = Node> = (nodes: NodeType[]) => void;
53
+ export type OnEdgesDelete<EdgeType extends Edge = Edge> = (edges: EdgeType[]) => void;
54
+
55
+ /**
56
+ * This type can be used to type the `onDelete` function with a custom node and edge type.
57
+ *
58
+ * @public
59
+ */
60
+ export type OnDelete<NodeType extends Node = Node, EdgeType extends Edge = Edge> = (params: {
61
+ nodes: NodeType[];
62
+ edges: EdgeType[];
63
+ }) => void;
64
+
65
+ export type NodeTypes = Record<
66
+ string,
67
+ ComponentType<
68
+ NodeProps & {
69
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
70
+ data: any;
71
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
72
+ type: any;
73
+ }
74
+ >
75
+ >;
76
+
77
+ export type EdgeTypes = Record<
78
+ string,
79
+ ComponentType<
80
+ EdgeProps & {
81
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
82
+ data: any;
83
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
84
+ type: any;
85
+ }
86
+ >
87
+ >;
88
+
89
+ export type UnselectNodesAndEdgesParams<
90
+ NodeType extends Node = Node,
91
+ EdgeType extends Edge = Edge,
92
+ > = {
93
+ nodes?: NodeType[];
94
+ edges?: EdgeType[];
95
+ };
96
+
97
+ export type OnSelectionChangeParams<NodeType extends Node = Node, EdgeType extends Edge = Edge> = {
98
+ nodes: NodeType[];
99
+ edges: EdgeType[];
100
+ };
101
+
102
+ export type OnSelectionChangeFunc<NodeType extends Node = Node, EdgeType extends Edge = Edge> = (
103
+ params: OnSelectionChangeParams<NodeType, EdgeType>,
104
+ ) => void;
105
+
106
+ /**
107
+ * @inline
108
+ */
109
+ export type FitViewParams<NodeType extends Node = Node> = FitViewParamsBase<NodeType>;
110
+
111
+ /**
112
+ * When calling [`fitView`](/api-reference/types/react-flow-instance#fitview) these options
113
+ * can be used to customize the behaviour. For example, the `duration` option can be used to
114
+ * transform the viewport smoothly over a given amount of time.
115
+ *
116
+ * @public
117
+ * @inline
118
+ */
119
+ export type FitViewOptions<NodeType extends Node = Node> = FitViewOptionsBase<NodeType>;
120
+
121
+ /**
122
+ * @inline
123
+ */
124
+ export type FitView<NodeType extends Node = Node> = (
125
+ fitViewOptions?: FitViewOptions<NodeType>,
126
+ ) => Promise<boolean>;
127
+
128
+ /**
129
+ * @inline
130
+ */
131
+ export type OnInit<NodeType extends Node = Node, EdgeType extends Edge = Edge> = (
132
+ reactFlowInstance: ReactFlowInstance<NodeType, EdgeType>,
133
+ ) => void;
134
+
135
+ /**
136
+ * @inline
137
+ */
138
+ export type ViewportHelperFunctions = {
139
+ /**
140
+ * Zooms viewport in by 1.2.
141
+ *
142
+ * @param options.duration - optional duration. If set, a transition will be applied
143
+ */
144
+ zoomIn: ZoomInOut;
145
+ /**
146
+ * Zooms viewport out by 1 / 1.2.
147
+ *
148
+ * @param options.duration - optional duration. If set, a transition will be applied
149
+ */
150
+ zoomOut: ZoomInOut;
151
+ /**
152
+ * Zoom the viewport to a given zoom level. Passing in a `duration` will animate the viewport to
153
+ * the new zoom level.
154
+ *
155
+ * @param zoomLevel - the zoom level to set
156
+ * @param options.duration - optional duration. If set, a transition will be applied
157
+ */
158
+ zoomTo: ZoomTo;
159
+ /**
160
+ * Get the current zoom level of the viewport.
161
+ *
162
+ * @returns current zoom as a number
163
+ */
164
+ getZoom: GetZoom;
165
+ /**
166
+ * Sets the current viewport.
167
+ *
168
+ * @param viewport - the viewport to set
169
+ * @param options.duration - optional duration. If set, a transition will be applied
170
+ * @param options.ease - optional ease function.
171
+ */
172
+ setViewport: SetViewport;
173
+ /**
174
+ * Returns the current viewport.
175
+ *
176
+ * @returns Viewport
177
+ */
178
+ getViewport: GetViewport;
179
+ /**
180
+ * Center the viewport on a given position. Passing in a `duration` will animate the viewport to
181
+ * the new position.
182
+ *
183
+ * @param x - x position
184
+ * @param y - y position
185
+ * @param options.zoom - optional zoom
186
+ * @param options.duration - optional duration. If set, a transition will be applied
187
+ * @param options.ease - optional ease function.
188
+ */
189
+ setCenter: SetCenter;
190
+ /**
191
+ * A low-level utility function to fit the viewport to a given rectangle. By passing in a
192
+ * `duration`, the viewport will animate from its current position to the new position. The
193
+ * `padding` option can be used to add space around the bounds.
194
+ *
195
+ * @param bounds - the bounds ({ x: number, y: number, width: number, height: number }) to fit the view to
196
+ * @param options.padding - optional padding
197
+ * @param options.duration - optional duration. If set, a transition will be applied
198
+ * @param options.ease - optional ease function.
199
+ */
200
+ fitBounds: FitBounds;
201
+ /**
202
+ * With this function you can translate a screen pixel position to a flow position. It is useful
203
+ * for implementing drag and drop from a sidebar for example.
204
+ *
205
+ * @param clientPosition - the screen / client position. When you are working with events you can use event.clientX and event.clientY
206
+ * @param options.snapToGrid - if true, the converted position will be snapped to the grid
207
+ * @returns position as { x: number, y: number }
208
+ *
209
+ * @example
210
+ * const flowPosition = screenToFlowPosition({ x: event.clientX, y: event.clientY })
211
+ */
212
+ screenToFlowPosition: (
213
+ clientPosition: XYPosition,
214
+ options?: { snapToGrid?: boolean; snapGrid?: SnapGrid },
215
+ ) => XYPosition;
216
+ /**
217
+ * Translate a position inside the flow's canvas to a screen pixel position.
218
+ *
219
+ * @param flowPosition - the screen / client position. When you are working with events you can use event.clientX and event.clientY
220
+ * @returns position as { x: number, y: number }
221
+ *
222
+ * @example
223
+ * const clientPosition = flowToScreenPosition({ x: node.position.x, y: node.position.y })
224
+ */
225
+ flowToScreenPosition: (flowPosition: XYPosition) => XYPosition;
226
+ };
227
+
228
+ export type OnBeforeDelete<
229
+ NodeType extends Node = Node,
230
+ EdgeType extends Edge = Edge,
231
+ > = OnBeforeDeleteBase<NodeType, EdgeType>;
232
+
233
+ /**
234
+ * This type can be used to type the `isValidConnection` function.
235
+ * If the function returns `true`, the connection is valid and can be created.
236
+ */
237
+ export type IsValidConnection<EdgeType extends Edge = Edge> = (
238
+ edge: EdgeType | Connection,
239
+ ) => boolean;
@@ -0,0 +1,6 @@
1
+ export * from './nodes';
2
+ export * from './edges';
3
+ export * from './component-props';
4
+ export * from './general';
5
+ export * from './store';
6
+ export * from './instance';