@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,397 @@
1
+ import { useEffect, useRef, type OctaneNode } from 'octane';
2
+ import type {
3
+ EventHandler,
4
+ RefObject,
5
+ MouseEvent as ReactMouseEvent,
6
+ PointerEvent as ReactPointerEvent,
7
+ WheelEvent as ReactWheelEvent,
8
+ } from '../../react-shim.js';
9
+ import { shallow } from '@octanejs/zustand/shallow';
10
+ import cc from 'classcat';
11
+ import {
12
+ getNodesInside,
13
+ getEventPosition,
14
+ SelectionMode,
15
+ areSetsEqual,
16
+ calcAutoPan,
17
+ pointToRendererPoint,
18
+ rendererPointToPoint,
19
+ XYPosition,
20
+ } from '@xyflow/system';
21
+
22
+ import { UserSelection } from '../../components/UserSelection/index.tsrx';
23
+ import { containerStyle } from '../../styles/utils';
24
+ import { useStore, useStoreApi } from '../../hooks/useStore';
25
+ import { getSelectionChanges } from '../../utils';
26
+ import type { ReactFlowProps, ReactFlowState } from '../../types';
27
+
28
+ type PaneProps =
29
+ {
30
+ isSelecting: boolean;
31
+ selectionKeyPressed: boolean;
32
+ children: OctaneNode;
33
+ paneClickDistance: number;
34
+ } & Partial<
35
+ Pick<
36
+ ReactFlowProps,
37
+ | 'selectionMode'
38
+ | 'panOnDrag'
39
+ | 'autoPanOnSelection'
40
+ | 'onSelectionStart'
41
+ | 'onSelectionEnd'
42
+ | 'onPaneClick'
43
+ | 'onPaneContextMenu'
44
+ | 'onPaneScroll'
45
+ | 'onPaneMouseEnter'
46
+ | 'onPaneMouseMove'
47
+ | 'onPaneMouseLeave'
48
+ | 'selectionOnDrag'
49
+ >
50
+ >;
51
+
52
+ const wrapHandler = <EventType extends Event,>(
53
+ handler: EventHandler<EventType> | undefined,
54
+ containerRef: RefObject<HTMLDivElement | null>,
55
+ ): EventHandler<EventType> => {
56
+ return (event: EventType) => {
57
+ if (event.target !== containerRef.current) {
58
+ return;
59
+ }
60
+ handler?.(event);
61
+ };
62
+ };
63
+
64
+ const selector = (s: ReactFlowState) => ({
65
+ userSelectionActive: s.userSelectionActive,
66
+ elementsSelectable: s.elementsSelectable,
67
+ dragging: s.paneDragging,
68
+ panBy: s.panBy,
69
+ autoPanSpeed: s.autoPanSpeed,
70
+ });
71
+
72
+ export function Pane({
73
+ isSelecting,
74
+ selectionKeyPressed,
75
+ selectionMode = SelectionMode.Full,
76
+ panOnDrag,
77
+ autoPanOnSelection,
78
+ paneClickDistance,
79
+ selectionOnDrag,
80
+ onSelectionStart,
81
+ onSelectionEnd,
82
+ onPaneClick,
83
+ onPaneContextMenu,
84
+ onPaneScroll,
85
+ onPaneMouseEnter,
86
+ onPaneMouseMove,
87
+ onPaneMouseLeave,
88
+ children,
89
+ }: PaneProps) {
90
+ const autoPanId = useRef<number>(0);
91
+ const store = useStoreApi();
92
+ const { userSelectionActive, elementsSelectable, dragging, panBy, autoPanSpeed } = useStore(
93
+ selector,
94
+ shallow,
95
+ );
96
+ const isSelectionEnabled = elementsSelectable && (isSelecting || userSelectionActive);
97
+
98
+ const container = useRef<HTMLDivElement | null>(null);
99
+ const containerBounds = useRef<DOMRect | undefined>(undefined);
100
+ const selectedNodeIds = useRef<Set<string>>(new Set());
101
+ const selectedEdgeIds = useRef<Set<string>>(new Set());
102
+ const connectionEndedOnPane = useRef<boolean>(false);
103
+
104
+ // Used to prevent click events when the user lets go of the selectionKey during a selection
105
+ const selectionInProgress = useRef<boolean>(false);
106
+
107
+ // Used for auto pan when approaching the edges of the container during selection
108
+ const position = useRef<XYPosition>({ x: 0, y: 0 });
109
+ const autoPanStarted = useRef<boolean>(false);
110
+
111
+ const onClick = (event: ReactMouseEvent) => {
112
+ // We prevent click events when the user let go of the selectionKey during a selection
113
+ // We also prevent click events when a connection is in progress
114
+ if (
115
+ selectionInProgress.current || connectionEndedOnPane.current ||
116
+ store.getState().connection.inProgress
117
+ ) {
118
+ selectionInProgress.current = false;
119
+ connectionEndedOnPane.current = false;
120
+ return;
121
+ }
122
+
123
+ onPaneClick?.(event);
124
+ store.getState().resetSelectedElements();
125
+ store.setState({ nodesSelectionActive: false });
126
+ };
127
+
128
+ const onContextMenu = (event: ReactMouseEvent) => {
129
+ if (Array.isArray(panOnDrag) && panOnDrag?.includes(2)) {
130
+ event.preventDefault();
131
+ return;
132
+ }
133
+
134
+ onPaneContextMenu?.(event);
135
+ };
136
+
137
+ const onWheel = onPaneScroll ? (event: ReactWheelEvent) => onPaneScroll(event) : undefined;
138
+
139
+ const onClickCapture = (event: ReactMouseEvent) => {
140
+ if (selectionInProgress.current) {
141
+ event.stopPropagation();
142
+ selectionInProgress.current = false;
143
+ }
144
+ };
145
+
146
+ // We are using capture here in order to prevent other pointer events
147
+ // to be able to create a selection above a node or an edge
148
+ const onPointerDownCapture = (event: ReactPointerEvent): void => {
149
+ // Mouse button arrays only restrict mouse input. Let touch panning handle this gesture
150
+ // unless the user explicitly activated selection with the selection key.
151
+ if (event.pointerType === 'touch' && panOnDrag !== false && !selectionKeyPressed) {
152
+ return;
153
+ }
154
+
155
+ const { domNode, transform } = store.getState();
156
+ containerBounds.current = domNode?.getBoundingClientRect();
157
+ if (!containerBounds.current) return;
158
+
159
+ const eventTargetIsContainer = event.target === container.current;
160
+ // if a child element has the 'nokey' class, we don't want to swallow the event and don't start a selection
161
+ const isNoKeyEvent =
162
+ !eventTargetIsContainer && !!(event.target as HTMLElement).closest('.nokey');
163
+ const isSelectionActive = selectionOnDrag && eventTargetIsContainer || selectionKeyPressed;
164
+
165
+ if (
166
+ isNoKeyEvent || !isSelecting || !isSelectionActive || event.button !== 0 || !event.isPrimary
167
+ ) {
168
+ return;
169
+ }
170
+
171
+ (event.target as Partial<Element>)?.setPointerCapture?.(event.pointerId);
172
+
173
+ selectionInProgress.current = false;
174
+
175
+ const { x, y } = getEventPosition(event, containerBounds.current);
176
+ const userSelectionStartPosition = pointToRendererPoint({ x, y }, transform);
177
+
178
+ store.setState({
179
+ userSelectionRect: {
180
+ width: 0,
181
+ height: 0,
182
+ startX: userSelectionStartPosition.x,
183
+ startY: userSelectionStartPosition.y,
184
+ x,
185
+ y,
186
+ },
187
+ });
188
+
189
+ if (!eventTargetIsContainer) {
190
+ event.stopPropagation();
191
+ event.preventDefault();
192
+ }
193
+ };
194
+
195
+ // We commit the user selection rectangle to the store on auto-panning or pointer move during selection.
196
+ function commitUserSelectionRect(mouseX: number, mouseY: number): void {
197
+ const { userSelectionRect } = store.getState();
198
+ if (!userSelectionRect) {
199
+ return;
200
+ }
201
+
202
+ const {
203
+ transform,
204
+ nodeLookup,
205
+ edgeLookup,
206
+ connectionLookup,
207
+ triggerNodeChanges,
208
+ triggerEdgeChanges,
209
+ defaultEdgeOptions,
210
+ } = store.getState();
211
+
212
+ const userStartPosition = { x: userSelectionRect.startX, y: userSelectionRect.startY };
213
+ const { x: screenStartX, y: screenStartY } = rendererPointToPoint(userStartPosition, transform);
214
+ // This has to be in screen coordinates, not in flow coordinates.
215
+ // We store the selection rectangle in userSelectionStartPosition coordinates to be able to
216
+ // fix the start position of the selection rectangle when we are auto-panning.
217
+ const nextUserSelectRect = {
218
+ startX: userStartPosition.x,
219
+ startY: userStartPosition.y,
220
+ x: mouseX < screenStartX ? mouseX : screenStartX,
221
+ y: mouseY < screenStartY ? mouseY : screenStartY,
222
+ width: Math.abs(mouseX - screenStartX),
223
+ height: Math.abs(mouseY - screenStartY),
224
+ };
225
+
226
+ const prevSelectedNodeIds = selectedNodeIds.current;
227
+ const prevSelectedEdgeIds = selectedEdgeIds.current;
228
+
229
+ selectedNodeIds.current = new Set(getNodesInside(
230
+ nodeLookup,
231
+ nextUserSelectRect,
232
+ transform,
233
+ selectionMode === SelectionMode.Partial,
234
+ true,
235
+ ).map((node) => node.id));
236
+
237
+ selectedEdgeIds.current = new Set();
238
+ const edgesSelectable = defaultEdgeOptions?.selectable ?? true;
239
+
240
+ // We look for all edges connected to the selected nodes
241
+ for (const nodeId of selectedNodeIds.current) {
242
+ const connections = connectionLookup.get(nodeId);
243
+ if (!connections) continue;
244
+ for (const { edgeId } of connections.values()) {
245
+ const edge = edgeLookup.get(edgeId);
246
+ if (edge && (edge.selectable ?? edgesSelectable)) {
247
+ selectedEdgeIds.current.add(edgeId);
248
+ }
249
+ }
250
+ }
251
+
252
+ if (!areSetsEqual(prevSelectedNodeIds, selectedNodeIds.current)) {
253
+ const changes = getSelectionChanges(nodeLookup, selectedNodeIds.current, true);
254
+ triggerNodeChanges(changes);
255
+ }
256
+
257
+ if (!areSetsEqual(prevSelectedEdgeIds, selectedEdgeIds.current)) {
258
+ const changes = getSelectionChanges(edgeLookup, selectedEdgeIds.current);
259
+ triggerEdgeChanges(changes);
260
+ }
261
+
262
+ store.setState({
263
+ userSelectionRect: nextUserSelectRect,
264
+ userSelectionActive: true,
265
+ nodesSelectionActive: false,
266
+ });
267
+ }
268
+
269
+ function autoPan(): void {
270
+ if (!autoPanOnSelection || !containerBounds.current) {
271
+ return;
272
+ }
273
+ const [x, y] = calcAutoPan(position.current, containerBounds.current, autoPanSpeed);
274
+
275
+ panBy({ x, y }).then((panned) => {
276
+ if (!selectionInProgress.current || !panned) {
277
+ autoPanId.current = requestAnimationFrame(autoPan);
278
+ return;
279
+ }
280
+ const { x: mx, y: my } = position.current;
281
+ commitUserSelectionRect(mx, my);
282
+ autoPanId.current = requestAnimationFrame(autoPan);
283
+ });
284
+ }
285
+
286
+ const cleanupAutoPan = (): void => {
287
+ cancelAnimationFrame(autoPanId.current);
288
+ autoPanId.current = 0;
289
+ autoPanStarted.current = false;
290
+ };
291
+
292
+ useEffect(() => {
293
+ return () => cleanupAutoPan();
294
+ }, []);
295
+
296
+ const onPointerMove = (event: ReactPointerEvent): void => {
297
+ const { userSelectionRect, transform, resetSelectedElements } = store.getState();
298
+
299
+ if (!containerBounds.current || !userSelectionRect) {
300
+ return;
301
+ }
302
+
303
+ const { x: mouseX, y: mouseY } = getEventPosition(event, containerBounds.current);
304
+ position.current = { x: mouseX, y: mouseY };
305
+
306
+ const screenStart = rendererPointToPoint(
307
+ { x: userSelectionRect.startX, y: userSelectionRect.startY },
308
+ transform,
309
+ );
310
+
311
+ if (!selectionInProgress.current) {
312
+ const requiredDistance = selectionKeyPressed ? 0 : paneClickDistance;
313
+ const distance = Math.hypot(mouseX - screenStart.x, mouseY - screenStart.y);
314
+ if (distance <= requiredDistance) {
315
+ return;
316
+ }
317
+ resetSelectedElements();
318
+ onSelectionStart?.(event);
319
+ }
320
+
321
+ selectionInProgress.current = true;
322
+
323
+ if (!autoPanStarted.current) {
324
+ autoPan();
325
+ autoPanStarted.current = true;
326
+ }
327
+
328
+ commitUserSelectionRect(mouseX, mouseY);
329
+ };
330
+
331
+ const onPointerUp = (event: ReactPointerEvent) => {
332
+ if (!isSelectionEnabled) {
333
+ if (event.target === container.current && store.getState().connection.inProgress) {
334
+ connectionEndedOnPane.current = true;
335
+ }
336
+ return;
337
+ }
338
+
339
+ if (event.button !== 0) {
340
+ return;
341
+ }
342
+
343
+ (event.target as Partial<Element>)?.releasePointerCapture?.(event.pointerId);
344
+
345
+ /*
346
+ * We only want to trigger click functions when in selection mode if
347
+ * the user did not move the mouse.
348
+ */
349
+ if (
350
+ !userSelectionActive && event.target === container.current &&
351
+ store.getState().userSelectionRect
352
+ ) {
353
+ onClick?.(event);
354
+ }
355
+
356
+ store.setState({
357
+ userSelectionActive: false,
358
+ userSelectionRect: null,
359
+ });
360
+
361
+ if (selectionInProgress.current) {
362
+ onSelectionEnd?.(event);
363
+
364
+ store.setState({
365
+ nodesSelectionActive: selectedNodeIds.current.size > 0,
366
+ });
367
+ }
368
+
369
+ cleanupAutoPan();
370
+ };
371
+
372
+ const onPointerCancel = (event: ReactPointerEvent) => {
373
+ (event.target as Partial<Element>)?.releasePointerCapture?.(event.pointerId);
374
+ cleanupAutoPan();
375
+ };
376
+
377
+ const draggable = panOnDrag === true || Array.isArray(panOnDrag) && panOnDrag.includes(0);
378
+
379
+ return <div
380
+ className={cc(['react-flow__pane', { draggable, dragging, selection: isSelecting }])}
381
+ onClick={isSelectionEnabled ? undefined : wrapHandler(onClick, container)}
382
+ onContextMenu={wrapHandler(onContextMenu, container)}
383
+ onWheel={wrapHandler(onWheel, container)}
384
+ onPointerEnter={isSelectionEnabled ? undefined : onPaneMouseEnter}
385
+ onPointerMove={isSelectionEnabled ? onPointerMove : onPaneMouseMove}
386
+ onPointerUp={onPointerUp}
387
+ onPointerCancel={isSelectionEnabled ? onPointerCancel : undefined}
388
+ onPointerDownCapture={isSelectionEnabled ? onPointerDownCapture : undefined}
389
+ onClickCapture={isSelectionEnabled ? onClickCapture : undefined}
390
+ onPointerLeave={onPaneMouseLeave}
391
+ ref={container}
392
+ style={containerStyle}
393
+ >
394
+ {children}
395
+ <UserSelection />
396
+ </div>;
397
+ }
@@ -0,0 +1,66 @@
1
+ import { useContext, type OctaneNode } from 'octane';
2
+
3
+ import StoreContext from '../../contexts/StoreContext';
4
+ import { ReactFlowProvider } from '../../components/ReactFlowProvider/index.tsrx';
5
+ import type { Node, Edge, FitViewOptions } from '../../types';
6
+ import { CoordinateExtent, NodeOrigin, ZIndexMode } from '@xyflow/system';
7
+
8
+ export function Wrapper({
9
+ children,
10
+ nodes,
11
+ edges,
12
+ defaultNodes,
13
+ defaultEdges,
14
+ width,
15
+ height,
16
+ fitView,
17
+ fitViewOptions,
18
+ minZoom,
19
+ maxZoom,
20
+ nodeOrigin,
21
+ nodeExtent,
22
+ zIndexMode,
23
+ }: {
24
+ children: OctaneNode;
25
+ nodes?: Node[];
26
+ edges?: Edge[];
27
+ defaultNodes?: Node[];
28
+ defaultEdges?: Edge[];
29
+ width?: number;
30
+ height?: number;
31
+ fitView?: boolean;
32
+ fitViewOptions?: FitViewOptions;
33
+ minZoom?: number;
34
+ maxZoom?: number;
35
+ nodeOrigin?: NodeOrigin;
36
+ nodeExtent?: CoordinateExtent;
37
+ zIndexMode?: ZIndexMode;
38
+ }) {
39
+ const isWrapped = useContext(StoreContext);
40
+
41
+ if (isWrapped) {
42
+ /*
43
+ * we need to wrap it with a fragment because it's not allowed for children to be a OctaneNode
44
+ * https://github.com/DefinitelyTyped/DefinitelyTyped/issues/18051
45
+ */
46
+ return <>
47
+ {children}
48
+ </>;
49
+ }
50
+
51
+ return <ReactFlowProvider
52
+ initialNodes={nodes}
53
+ initialEdges={edges}
54
+ defaultNodes={defaultNodes}
55
+ defaultEdges={defaultEdges}
56
+ initialWidth={width}
57
+ initialHeight={height}
58
+ fitView={fitView}
59
+ initialFitViewOptions={fitViewOptions}
60
+ initialMinZoom={minZoom}
61
+ initialMaxZoom={maxZoom}
62
+ nodeOrigin={nodeOrigin}
63
+ nodeExtent={nodeExtent}
64
+ zIndexMode={zIndexMode}
65
+ >{children}</ReactFlowProvider>;
66
+ }