@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,352 @@
|
|
|
1
|
+
import { useCallback } from 'octane';
|
|
2
|
+
import type { CSSProperties, ForwardedRef, UIEvent as ReactUIEvent } from '../../react-shim.js';
|
|
3
|
+
import cc from 'classcat';
|
|
4
|
+
import {
|
|
5
|
+
ConnectionLineType,
|
|
6
|
+
PanOnScrollMode,
|
|
7
|
+
SelectionMode,
|
|
8
|
+
infiniteExtent,
|
|
9
|
+
isMacOs,
|
|
10
|
+
} from '@xyflow/system';
|
|
11
|
+
|
|
12
|
+
import { A11yDescriptions } from '../../components/A11yDescriptions/index.tsrx';
|
|
13
|
+
import { Attribution } from '../../components/Attribution/index.tsrx';
|
|
14
|
+
import { SelectionListener } from '../../components/SelectionListener/index.tsrx';
|
|
15
|
+
import { StoreUpdater } from '../../components/StoreUpdater/index.tsrx';
|
|
16
|
+
import { useColorModeClass } from '../../hooks/useColorModeClass';
|
|
17
|
+
import { GraphView } from '../GraphView/index.tsrx';
|
|
18
|
+
import { Wrapper } from './Wrapper.tsrx';
|
|
19
|
+
import type { Edge, Node, ReactFlowProps } from '../../types';
|
|
20
|
+
import { defaultViewport as initViewport, defaultNodeOrigin } from './init-values';
|
|
21
|
+
import { fixedForwardRef } from '../../utils/general';
|
|
22
|
+
|
|
23
|
+
const wrapperStyle: CSSProperties = {
|
|
24
|
+
width: '100%',
|
|
25
|
+
height: '100%',
|
|
26
|
+
overflow: 'hidden',
|
|
27
|
+
position: 'relative',
|
|
28
|
+
zIndex: 0,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
function ReactFlow<NodeType extends Node = Node, EdgeType extends Edge = Edge>(
|
|
32
|
+
{
|
|
33
|
+
nodes,
|
|
34
|
+
edges,
|
|
35
|
+
defaultNodes,
|
|
36
|
+
defaultEdges,
|
|
37
|
+
className,
|
|
38
|
+
nodeTypes,
|
|
39
|
+
edgeTypes,
|
|
40
|
+
onNodeClick,
|
|
41
|
+
onEdgeClick,
|
|
42
|
+
onInit,
|
|
43
|
+
onMove,
|
|
44
|
+
onMoveStart,
|
|
45
|
+
onMoveEnd,
|
|
46
|
+
onConnect,
|
|
47
|
+
onConnectStart,
|
|
48
|
+
onConnectEnd,
|
|
49
|
+
onClickConnectStart,
|
|
50
|
+
onClickConnectEnd,
|
|
51
|
+
onNodeMouseEnter,
|
|
52
|
+
onNodeMouseMove,
|
|
53
|
+
onNodeMouseLeave,
|
|
54
|
+
onNodeContextMenu,
|
|
55
|
+
onNodeDoubleClick,
|
|
56
|
+
onNodeDragStart,
|
|
57
|
+
onNodeDrag,
|
|
58
|
+
onNodeDragStop,
|
|
59
|
+
onNodesDelete,
|
|
60
|
+
onEdgesDelete,
|
|
61
|
+
onDelete,
|
|
62
|
+
onSelectionChange,
|
|
63
|
+
onSelectionDragStart,
|
|
64
|
+
onSelectionDrag,
|
|
65
|
+
onSelectionDragStop,
|
|
66
|
+
onSelectionContextMenu,
|
|
67
|
+
onSelectionStart,
|
|
68
|
+
onSelectionEnd,
|
|
69
|
+
onBeforeDelete,
|
|
70
|
+
connectionMode,
|
|
71
|
+
connectionLineType = ConnectionLineType.Bezier,
|
|
72
|
+
connectionLineStyle,
|
|
73
|
+
connectionLineComponent,
|
|
74
|
+
connectionLineContainerStyle,
|
|
75
|
+
deleteKeyCode = 'Backspace',
|
|
76
|
+
selectionKeyCode = 'Shift',
|
|
77
|
+
selectionOnDrag = false,
|
|
78
|
+
selectionMode = SelectionMode.Full,
|
|
79
|
+
panActivationKeyCode = 'Space',
|
|
80
|
+
multiSelectionKeyCode = isMacOs() ? 'Meta' : 'Control',
|
|
81
|
+
zoomActivationKeyCode = isMacOs() ? 'Meta' : 'Control',
|
|
82
|
+
snapToGrid,
|
|
83
|
+
snapGrid,
|
|
84
|
+
onlyRenderVisibleElements = false,
|
|
85
|
+
selectNodesOnDrag,
|
|
86
|
+
nodesDraggable,
|
|
87
|
+
autoPanOnNodeFocus,
|
|
88
|
+
nodesConnectable,
|
|
89
|
+
nodesFocusable,
|
|
90
|
+
nodeOrigin = defaultNodeOrigin,
|
|
91
|
+
edgesFocusable,
|
|
92
|
+
edgesReconnectable,
|
|
93
|
+
elementsSelectable = true,
|
|
94
|
+
defaultViewport = initViewport,
|
|
95
|
+
minZoom = 0.5,
|
|
96
|
+
maxZoom = 2,
|
|
97
|
+
translateExtent = infiniteExtent,
|
|
98
|
+
preventScrolling = true,
|
|
99
|
+
nodeExtent,
|
|
100
|
+
defaultMarkerColor = '#b1b1b7',
|
|
101
|
+
zoomOnScroll = true,
|
|
102
|
+
zoomOnPinch = true,
|
|
103
|
+
panOnScroll = false,
|
|
104
|
+
panOnScrollSpeed = 0.5,
|
|
105
|
+
panOnScrollMode = PanOnScrollMode.Free,
|
|
106
|
+
zoomOnDoubleClick = true,
|
|
107
|
+
panOnDrag = true,
|
|
108
|
+
onPaneClick,
|
|
109
|
+
onPaneMouseEnter,
|
|
110
|
+
onPaneMouseMove,
|
|
111
|
+
onPaneMouseLeave,
|
|
112
|
+
onPaneScroll,
|
|
113
|
+
onPaneContextMenu,
|
|
114
|
+
paneClickDistance = 1,
|
|
115
|
+
nodeClickDistance = 0,
|
|
116
|
+
children,
|
|
117
|
+
onReconnect,
|
|
118
|
+
onReconnectStart,
|
|
119
|
+
onReconnectEnd,
|
|
120
|
+
onEdgeContextMenu,
|
|
121
|
+
onEdgeDoubleClick,
|
|
122
|
+
onEdgeMouseEnter,
|
|
123
|
+
onEdgeMouseMove,
|
|
124
|
+
onEdgeMouseLeave,
|
|
125
|
+
reconnectRadius = 10,
|
|
126
|
+
onNodesChange,
|
|
127
|
+
onEdgesChange,
|
|
128
|
+
noDragClassName = 'nodrag',
|
|
129
|
+
noWheelClassName = 'nowheel',
|
|
130
|
+
noPanClassName = 'nopan',
|
|
131
|
+
fitView,
|
|
132
|
+
fitViewOptions,
|
|
133
|
+
connectOnClick,
|
|
134
|
+
attributionPosition,
|
|
135
|
+
proOptions,
|
|
136
|
+
defaultEdgeOptions,
|
|
137
|
+
elevateNodesOnSelect = true,
|
|
138
|
+
elevateEdgesOnSelect = false,
|
|
139
|
+
disableKeyboardA11y = false,
|
|
140
|
+
autoPanOnConnect,
|
|
141
|
+
autoPanOnNodeDrag,
|
|
142
|
+
autoPanOnSelection = true,
|
|
143
|
+
autoPanSpeed,
|
|
144
|
+
connectionRadius,
|
|
145
|
+
isValidConnection,
|
|
146
|
+
onError,
|
|
147
|
+
style,
|
|
148
|
+
id,
|
|
149
|
+
nodeDragThreshold,
|
|
150
|
+
connectionDragThreshold,
|
|
151
|
+
viewport,
|
|
152
|
+
onViewportChange,
|
|
153
|
+
width,
|
|
154
|
+
height,
|
|
155
|
+
colorMode = 'light',
|
|
156
|
+
debug,
|
|
157
|
+
onScroll,
|
|
158
|
+
ariaLabelConfig,
|
|
159
|
+
zIndexMode = 'basic',
|
|
160
|
+
...rest
|
|
161
|
+
}: ReactFlowProps<NodeType, EdgeType>,
|
|
162
|
+
ref: ForwardedRef<HTMLDivElement>,
|
|
163
|
+
) {
|
|
164
|
+
const rfId = id || '1';
|
|
165
|
+
const colorModeClassName = useColorModeClass(colorMode);
|
|
166
|
+
|
|
167
|
+
// Undo scroll events, preventing viewport from shifting when nodes outside of it are focused
|
|
168
|
+
const wrapperOnScroll = useCallback((e: ReactUIEvent<HTMLDivElement>) => {
|
|
169
|
+
e.currentTarget.scrollTo({ top: 0, left: 0, behavior: 'instant' });
|
|
170
|
+
onScroll?.(e);
|
|
171
|
+
}, [onScroll]);
|
|
172
|
+
|
|
173
|
+
return <div
|
|
174
|
+
data-testid="rf__wrapper"
|
|
175
|
+
{...rest}
|
|
176
|
+
onScroll={wrapperOnScroll}
|
|
177
|
+
style={{ ...style, ...wrapperStyle }}
|
|
178
|
+
ref={ref}
|
|
179
|
+
className={cc(['react-flow', className, colorModeClassName])}
|
|
180
|
+
id={id}
|
|
181
|
+
role="application"
|
|
182
|
+
>
|
|
183
|
+
<Wrapper
|
|
184
|
+
nodes={nodes}
|
|
185
|
+
edges={edges}
|
|
186
|
+
width={width}
|
|
187
|
+
height={height}
|
|
188
|
+
fitView={fitView}
|
|
189
|
+
fitViewOptions={fitViewOptions}
|
|
190
|
+
minZoom={minZoom}
|
|
191
|
+
maxZoom={maxZoom}
|
|
192
|
+
nodeOrigin={nodeOrigin}
|
|
193
|
+
nodeExtent={nodeExtent}
|
|
194
|
+
zIndexMode={zIndexMode}
|
|
195
|
+
>
|
|
196
|
+
<StoreUpdater
|
|
197
|
+
nodes={nodes}
|
|
198
|
+
edges={edges}
|
|
199
|
+
defaultNodes={defaultNodes}
|
|
200
|
+
defaultEdges={defaultEdges}
|
|
201
|
+
onConnect={onConnect}
|
|
202
|
+
onConnectStart={onConnectStart}
|
|
203
|
+
onConnectEnd={onConnectEnd}
|
|
204
|
+
onClickConnectStart={onClickConnectStart}
|
|
205
|
+
onClickConnectEnd={onClickConnectEnd}
|
|
206
|
+
nodesDraggable={nodesDraggable}
|
|
207
|
+
autoPanOnNodeFocus={autoPanOnNodeFocus}
|
|
208
|
+
nodesConnectable={nodesConnectable}
|
|
209
|
+
nodesFocusable={nodesFocusable}
|
|
210
|
+
edgesFocusable={edgesFocusable}
|
|
211
|
+
edgesReconnectable={edgesReconnectable}
|
|
212
|
+
elementsSelectable={elementsSelectable}
|
|
213
|
+
elevateNodesOnSelect={elevateNodesOnSelect}
|
|
214
|
+
elevateEdgesOnSelect={elevateEdgesOnSelect}
|
|
215
|
+
minZoom={minZoom}
|
|
216
|
+
maxZoom={maxZoom}
|
|
217
|
+
nodeExtent={nodeExtent}
|
|
218
|
+
onNodesChange={onNodesChange}
|
|
219
|
+
onEdgesChange={onEdgesChange}
|
|
220
|
+
snapToGrid={snapToGrid}
|
|
221
|
+
snapGrid={snapGrid}
|
|
222
|
+
connectionMode={connectionMode}
|
|
223
|
+
translateExtent={translateExtent}
|
|
224
|
+
connectOnClick={connectOnClick}
|
|
225
|
+
defaultEdgeOptions={defaultEdgeOptions}
|
|
226
|
+
fitView={fitView}
|
|
227
|
+
fitViewOptions={fitViewOptions}
|
|
228
|
+
onNodesDelete={onNodesDelete}
|
|
229
|
+
onEdgesDelete={onEdgesDelete}
|
|
230
|
+
onDelete={onDelete}
|
|
231
|
+
onNodeDragStart={onNodeDragStart}
|
|
232
|
+
onNodeDrag={onNodeDrag}
|
|
233
|
+
onNodeDragStop={onNodeDragStop}
|
|
234
|
+
onSelectionDrag={onSelectionDrag}
|
|
235
|
+
onSelectionDragStart={onSelectionDragStart}
|
|
236
|
+
onSelectionDragStop={onSelectionDragStop}
|
|
237
|
+
onMove={onMove}
|
|
238
|
+
onMoveStart={onMoveStart}
|
|
239
|
+
onMoveEnd={onMoveEnd}
|
|
240
|
+
noPanClassName={noPanClassName}
|
|
241
|
+
nodeOrigin={nodeOrigin}
|
|
242
|
+
rfId={rfId}
|
|
243
|
+
autoPanOnConnect={autoPanOnConnect}
|
|
244
|
+
autoPanOnNodeDrag={autoPanOnNodeDrag}
|
|
245
|
+
autoPanSpeed={autoPanSpeed}
|
|
246
|
+
onError={onError}
|
|
247
|
+
connectionRadius={connectionRadius}
|
|
248
|
+
isValidConnection={isValidConnection}
|
|
249
|
+
selectNodesOnDrag={selectNodesOnDrag}
|
|
250
|
+
nodeDragThreshold={nodeDragThreshold}
|
|
251
|
+
connectionDragThreshold={connectionDragThreshold}
|
|
252
|
+
onBeforeDelete={onBeforeDelete}
|
|
253
|
+
debug={debug}
|
|
254
|
+
ariaLabelConfig={ariaLabelConfig}
|
|
255
|
+
zIndexMode={zIndexMode}
|
|
256
|
+
/>
|
|
257
|
+
<GraphView
|
|
258
|
+
onInit={onInit}
|
|
259
|
+
onNodeClick={onNodeClick}
|
|
260
|
+
onEdgeClick={onEdgeClick}
|
|
261
|
+
onNodeMouseEnter={onNodeMouseEnter}
|
|
262
|
+
onNodeMouseMove={onNodeMouseMove}
|
|
263
|
+
onNodeMouseLeave={onNodeMouseLeave}
|
|
264
|
+
onNodeContextMenu={onNodeContextMenu}
|
|
265
|
+
onNodeDoubleClick={onNodeDoubleClick}
|
|
266
|
+
nodeTypes={nodeTypes}
|
|
267
|
+
edgeTypes={edgeTypes}
|
|
268
|
+
connectionLineType={connectionLineType}
|
|
269
|
+
connectionLineStyle={connectionLineStyle}
|
|
270
|
+
connectionLineComponent={connectionLineComponent}
|
|
271
|
+
connectionLineContainerStyle={connectionLineContainerStyle}
|
|
272
|
+
selectionKeyCode={selectionKeyCode}
|
|
273
|
+
selectionOnDrag={selectionOnDrag}
|
|
274
|
+
selectionMode={selectionMode}
|
|
275
|
+
deleteKeyCode={deleteKeyCode}
|
|
276
|
+
multiSelectionKeyCode={multiSelectionKeyCode}
|
|
277
|
+
panActivationKeyCode={panActivationKeyCode}
|
|
278
|
+
zoomActivationKeyCode={zoomActivationKeyCode}
|
|
279
|
+
onlyRenderVisibleElements={onlyRenderVisibleElements}
|
|
280
|
+
defaultViewport={defaultViewport}
|
|
281
|
+
translateExtent={translateExtent}
|
|
282
|
+
minZoom={minZoom}
|
|
283
|
+
maxZoom={maxZoom}
|
|
284
|
+
preventScrolling={preventScrolling}
|
|
285
|
+
zoomOnScroll={zoomOnScroll}
|
|
286
|
+
zoomOnPinch={zoomOnPinch}
|
|
287
|
+
zoomOnDoubleClick={zoomOnDoubleClick}
|
|
288
|
+
panOnScroll={panOnScroll}
|
|
289
|
+
panOnScrollSpeed={panOnScrollSpeed}
|
|
290
|
+
panOnScrollMode={panOnScrollMode}
|
|
291
|
+
panOnDrag={panOnDrag}
|
|
292
|
+
autoPanOnSelection={autoPanOnSelection}
|
|
293
|
+
onPaneClick={onPaneClick}
|
|
294
|
+
onPaneMouseEnter={onPaneMouseEnter}
|
|
295
|
+
onPaneMouseMove={onPaneMouseMove}
|
|
296
|
+
onPaneMouseLeave={onPaneMouseLeave}
|
|
297
|
+
onPaneScroll={onPaneScroll}
|
|
298
|
+
onPaneContextMenu={onPaneContextMenu}
|
|
299
|
+
paneClickDistance={paneClickDistance}
|
|
300
|
+
nodeClickDistance={nodeClickDistance}
|
|
301
|
+
onSelectionContextMenu={onSelectionContextMenu}
|
|
302
|
+
onSelectionStart={onSelectionStart}
|
|
303
|
+
onSelectionEnd={onSelectionEnd}
|
|
304
|
+
onReconnect={onReconnect}
|
|
305
|
+
onReconnectStart={onReconnectStart}
|
|
306
|
+
onReconnectEnd={onReconnectEnd}
|
|
307
|
+
onEdgeContextMenu={onEdgeContextMenu}
|
|
308
|
+
onEdgeDoubleClick={onEdgeDoubleClick}
|
|
309
|
+
onEdgeMouseEnter={onEdgeMouseEnter}
|
|
310
|
+
onEdgeMouseMove={onEdgeMouseMove}
|
|
311
|
+
onEdgeMouseLeave={onEdgeMouseLeave}
|
|
312
|
+
reconnectRadius={reconnectRadius}
|
|
313
|
+
defaultMarkerColor={defaultMarkerColor}
|
|
314
|
+
noDragClassName={noDragClassName}
|
|
315
|
+
noWheelClassName={noWheelClassName}
|
|
316
|
+
noPanClassName={noPanClassName}
|
|
317
|
+
rfId={rfId}
|
|
318
|
+
disableKeyboardA11y={disableKeyboardA11y}
|
|
319
|
+
nodeExtent={nodeExtent}
|
|
320
|
+
viewport={viewport}
|
|
321
|
+
onViewportChange={onViewportChange}
|
|
322
|
+
nodesDraggable={nodesDraggable}
|
|
323
|
+
/>
|
|
324
|
+
<SelectionListener onSelectionChange={onSelectionChange} />
|
|
325
|
+
{children}
|
|
326
|
+
<Attribution proOptions={proOptions} position={attributionPosition} />
|
|
327
|
+
<A11yDescriptions rfId={rfId} disableKeyboardA11y={disableKeyboardA11y} />
|
|
328
|
+
</Wrapper>
|
|
329
|
+
</div>;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* The `<ReactFlow />` component is the heart of your React Flow application.
|
|
334
|
+
* It renders your nodes and edges and handles user interaction
|
|
335
|
+
*
|
|
336
|
+
* @public
|
|
337
|
+
*
|
|
338
|
+
* @example
|
|
339
|
+
* ```tsx
|
|
340
|
+
*import { ReactFlow } from '@xyflow/react'
|
|
341
|
+
*
|
|
342
|
+
*export default function Flow() {
|
|
343
|
+
* return (<ReactFlow
|
|
344
|
+
* nodes={...}
|
|
345
|
+
* edges={...}
|
|
346
|
+
* onNodesChange={...}
|
|
347
|
+
* ...
|
|
348
|
+
* />);
|
|
349
|
+
*}
|
|
350
|
+
*```
|
|
351
|
+
*/
|
|
352
|
+
export default fixedForwardRef<HTMLDivElement, ReactFlowProps>(ReactFlow);
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { useRef, useState, type OctaneNode } from 'octane';
|
|
2
|
+
import type { Transform } from '@xyflow/system';
|
|
3
|
+
|
|
4
|
+
import { useStoreApi } from '../../hooks/useStore';
|
|
5
|
+
import { useIsomorphicLayoutEffect } from '../../hooks/useIsomorphicLayoutEffect';
|
|
6
|
+
|
|
7
|
+
const toTransformString = (transform: Transform) =>
|
|
8
|
+
`translate(${transform[0]}px,${transform[1]}px) scale(${transform[2]})`;
|
|
9
|
+
|
|
10
|
+
type ViewportProps = {
|
|
11
|
+
children: OctaneNode;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export function Viewport({ children }: ViewportProps) {
|
|
15
|
+
const store = useStoreApi();
|
|
16
|
+
const viewportRef = useRef<HTMLDivElement | null>(null);
|
|
17
|
+
// seed the transform for first paint and SSR without subscribing, so we don't re-render on pan/zoom
|
|
18
|
+
const [initialTransform] = useState(() => store.getState().transform);
|
|
19
|
+
|
|
20
|
+
// transform changes every pan/zoom frame, so write it to the DOM directly to keep React out of the hot path
|
|
21
|
+
useIsomorphicLayoutEffect(() => {
|
|
22
|
+
let prevTransform: Transform | null = null;
|
|
23
|
+
|
|
24
|
+
const applyTransform = () => {
|
|
25
|
+
const transform = store.getState().transform;
|
|
26
|
+
|
|
27
|
+
// store.subscribe fires on every update, so only touch the DOM when x, y or zoom actually changed
|
|
28
|
+
if (
|
|
29
|
+
prevTransform && transform[0] === prevTransform[0] && transform[1] === prevTransform[1] &&
|
|
30
|
+
transform[2] === prevTransform[2]
|
|
31
|
+
) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
prevTransform = transform;
|
|
36
|
+
|
|
37
|
+
if (viewportRef.current) {
|
|
38
|
+
viewportRef.current.style.transform = toTransformString(transform);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
applyTransform();
|
|
43
|
+
|
|
44
|
+
return store.subscribe(applyTransform);
|
|
45
|
+
}, [store]);
|
|
46
|
+
|
|
47
|
+
return <div
|
|
48
|
+
ref={viewportRef}
|
|
49
|
+
className="react-flow__viewport xyflow__viewport react-flow__container"
|
|
50
|
+
style={{ transform: toTransformString(initialTransform) }}
|
|
51
|
+
>{children}</div>;
|
|
52
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import { useCallback, useEffect, useRef } from 'octane';
|
|
3
|
+
import { shallow } from '@octanejs/zustand/shallow';
|
|
4
|
+
import { XYPanZoom, PanOnScrollMode, type Transform, type PanZoomInstance } from '@xyflow/system';
|
|
5
|
+
|
|
6
|
+
import { useKeyPress } from '../../hooks/useKeyPress';
|
|
7
|
+
import { useResizeHandler } from '../../hooks/useResizeHandler';
|
|
8
|
+
import { useStore, useStoreApi } from '../../hooks/useStore';
|
|
9
|
+
import { containerStyle } from '../../styles/utils';
|
|
10
|
+
import type { FlowRendererProps } from '../FlowRenderer/index.tsrx';
|
|
11
|
+
import type { ReactFlowState } from '../../types';
|
|
12
|
+
|
|
13
|
+
type ZoomPaneProps =
|
|
14
|
+
Omit<
|
|
15
|
+
FlowRendererProps,
|
|
16
|
+
| 'deleteKeyCode'
|
|
17
|
+
| 'selectionKeyCode'
|
|
18
|
+
| 'multiSelectionKeyCode'
|
|
19
|
+
| 'noDragClassName'
|
|
20
|
+
| 'disableKeyboardA11y'
|
|
21
|
+
> & {
|
|
22
|
+
isControlledViewport: boolean;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const selector = (s: ReactFlowState) => ({
|
|
26
|
+
userSelectionActive: s.userSelectionActive,
|
|
27
|
+
lib: s.lib,
|
|
28
|
+
connectionInProgress: s.connection.inProgress,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export function ZoomPane({
|
|
32
|
+
onPaneContextMenu,
|
|
33
|
+
zoomOnScroll = true,
|
|
34
|
+
zoomOnPinch = true,
|
|
35
|
+
panOnScroll = false,
|
|
36
|
+
panOnScrollSpeed = 0.5,
|
|
37
|
+
panOnScrollMode = PanOnScrollMode.Free,
|
|
38
|
+
zoomOnDoubleClick = true,
|
|
39
|
+
panOnDrag = true,
|
|
40
|
+
defaultViewport,
|
|
41
|
+
translateExtent,
|
|
42
|
+
minZoom,
|
|
43
|
+
maxZoom,
|
|
44
|
+
zoomActivationKeyCode,
|
|
45
|
+
preventScrolling = true,
|
|
46
|
+
children,
|
|
47
|
+
noWheelClassName,
|
|
48
|
+
noPanClassName,
|
|
49
|
+
onViewportChange,
|
|
50
|
+
isControlledViewport,
|
|
51
|
+
paneClickDistance,
|
|
52
|
+
selectionOnDrag,
|
|
53
|
+
}: ZoomPaneProps) {
|
|
54
|
+
const store = useStoreApi();
|
|
55
|
+
const zoomPane = useRef<HTMLDivElement | null>(null);
|
|
56
|
+
const { userSelectionActive, lib, connectionInProgress } = useStore(selector, shallow);
|
|
57
|
+
const zoomActivationKeyPressed = useKeyPress(zoomActivationKeyCode);
|
|
58
|
+
const panZoom = useRef<PanZoomInstance | undefined>(undefined);
|
|
59
|
+
|
|
60
|
+
useResizeHandler(zoomPane);
|
|
61
|
+
|
|
62
|
+
const onTransformChange = useCallback((transform: Transform) => {
|
|
63
|
+
onViewportChange?.({ x: transform[0], y: transform[1], zoom: transform[2] });
|
|
64
|
+
|
|
65
|
+
if (!isControlledViewport) {
|
|
66
|
+
store.setState({ transform });
|
|
67
|
+
}
|
|
68
|
+
}, [onViewportChange, isControlledViewport]);
|
|
69
|
+
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
if (zoomPane.current) {
|
|
72
|
+
panZoom.current = XYPanZoom({
|
|
73
|
+
domNode: zoomPane.current,
|
|
74
|
+
minZoom,
|
|
75
|
+
maxZoom,
|
|
76
|
+
translateExtent,
|
|
77
|
+
viewport: defaultViewport,
|
|
78
|
+
onDraggingChange: (paneDragging) => store.setState(
|
|
79
|
+
(prevState) => (prevState.paneDragging === paneDragging ? prevState : { paneDragging }),
|
|
80
|
+
),
|
|
81
|
+
onPanZoomStart: (event, vp) => {
|
|
82
|
+
const { onViewportChangeStart, onMoveStart } = store.getState();
|
|
83
|
+
onMoveStart?.(event, vp);
|
|
84
|
+
onViewportChangeStart?.(vp);
|
|
85
|
+
},
|
|
86
|
+
onPanZoom: (event, vp) => {
|
|
87
|
+
const { onViewportChange, onMove } = store.getState();
|
|
88
|
+
onMove?.(event, vp);
|
|
89
|
+
onViewportChange?.(vp);
|
|
90
|
+
},
|
|
91
|
+
onPanZoomEnd: (event, vp) => {
|
|
92
|
+
const { onViewportChangeEnd, onMoveEnd } = store.getState();
|
|
93
|
+
onMoveEnd?.(event, vp);
|
|
94
|
+
onViewportChangeEnd?.(vp);
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const { x, y, zoom } = panZoom.current.getViewport();
|
|
99
|
+
|
|
100
|
+
store.setState({
|
|
101
|
+
panZoom: panZoom.current,
|
|
102
|
+
transform: [x, y, zoom],
|
|
103
|
+
domNode: zoomPane.current.closest('.react-flow') as HTMLDivElement,
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
return () => {
|
|
107
|
+
panZoom.current?.destroy();
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
}, []);
|
|
111
|
+
|
|
112
|
+
useEffect(() => {
|
|
113
|
+
panZoom.current?.update({
|
|
114
|
+
onPaneContextMenu,
|
|
115
|
+
zoomOnScroll,
|
|
116
|
+
zoomOnPinch,
|
|
117
|
+
panOnScroll,
|
|
118
|
+
panOnScrollSpeed,
|
|
119
|
+
panOnScrollMode,
|
|
120
|
+
zoomOnDoubleClick,
|
|
121
|
+
panOnDrag,
|
|
122
|
+
zoomActivationKeyPressed,
|
|
123
|
+
preventScrolling,
|
|
124
|
+
noPanClassName,
|
|
125
|
+
userSelectionActive,
|
|
126
|
+
noWheelClassName,
|
|
127
|
+
lib,
|
|
128
|
+
onTransformChange,
|
|
129
|
+
connectionInProgress,
|
|
130
|
+
selectionOnDrag,
|
|
131
|
+
paneClickDistance,
|
|
132
|
+
});
|
|
133
|
+
}, [
|
|
134
|
+
onPaneContextMenu,
|
|
135
|
+
zoomOnScroll,
|
|
136
|
+
zoomOnPinch,
|
|
137
|
+
panOnScroll,
|
|
138
|
+
panOnScrollSpeed,
|
|
139
|
+
panOnScrollMode,
|
|
140
|
+
zoomOnDoubleClick,
|
|
141
|
+
panOnDrag,
|
|
142
|
+
zoomActivationKeyPressed,
|
|
143
|
+
preventScrolling,
|
|
144
|
+
noPanClassName,
|
|
145
|
+
userSelectionActive,
|
|
146
|
+
noWheelClassName,
|
|
147
|
+
lib,
|
|
148
|
+
onTransformChange,
|
|
149
|
+
connectionInProgress,
|
|
150
|
+
selectionOnDrag,
|
|
151
|
+
paneClickDistance,
|
|
152
|
+
]);
|
|
153
|
+
|
|
154
|
+
return <div
|
|
155
|
+
className="react-flow__renderer"
|
|
156
|
+
ref={zoomPane}
|
|
157
|
+
style={containerStyle}
|
|
158
|
+
>{children}</div>;
|
|
159
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { createContext, useContext, type OctaneNode } from 'octane';
|
|
2
|
+
import { shallow } from '@octanejs/zustand/shallow';
|
|
3
|
+
|
|
4
|
+
import { useStore } from '../hooks/useStore';
|
|
5
|
+
import type { ReactFlowState } from '../types';
|
|
6
|
+
|
|
7
|
+
type HandleConfig = {
|
|
8
|
+
connectOnClick: boolean;
|
|
9
|
+
noPanClassName: string;
|
|
10
|
+
rfId: string;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const selector = (s: ReactFlowState): HandleConfig => ({
|
|
14
|
+
connectOnClick: s.connectOnClick,
|
|
15
|
+
noPanClassName: s.noPanClassName,
|
|
16
|
+
rfId: s.rfId,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const HandleConfigContext = createContext<HandleConfig | null>(null);
|
|
20
|
+
|
|
21
|
+
/*
|
|
22
|
+
* `connectOnClick`, `noPanClassName` and `rfId` are the same for every handle, so they are
|
|
23
|
+
* shared through context from a single store subscription.
|
|
24
|
+
*/
|
|
25
|
+
export function HandleConfigProvider({ children }: { children: OctaneNode }) {
|
|
26
|
+
const config = useStore(selector, shallow);
|
|
27
|
+
return <HandleConfigContext.Provider value={config}>{children}</HandleConfigContext.Provider>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function useHandleConfig() {
|
|
31
|
+
const config = useContext(HandleConfigContext);
|
|
32
|
+
|
|
33
|
+
if (!config) {
|
|
34
|
+
throw new Error('useHandleConfig must be used within a HandleConfigProvider');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return config;
|
|
38
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { createContext, useContext } from 'octane';
|
|
2
|
+
|
|
3
|
+
export const NodeIdContext = createContext<string | null>(null);
|
|
4
|
+
export const Provider = NodeIdContext.Provider;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* You can use this hook to get the id of the node it is used inside. It is useful
|
|
8
|
+
* if you need the node's id deeper in the render tree but don't want to manually
|
|
9
|
+
* drill down the id as a prop.
|
|
10
|
+
*
|
|
11
|
+
* @public
|
|
12
|
+
* @returns The id for a node in the flow.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
*```jsx
|
|
16
|
+
*import { useNodeId } from '@xyflow/react';
|
|
17
|
+
*
|
|
18
|
+
*export default function CustomNode() {
|
|
19
|
+
* return (
|
|
20
|
+
* <div>
|
|
21
|
+
* <span>This node has an id of </span>
|
|
22
|
+
* <NodeIdDisplay />
|
|
23
|
+
* </div>
|
|
24
|
+
* );
|
|
25
|
+
*}
|
|
26
|
+
*
|
|
27
|
+
*function NodeIdDisplay() {
|
|
28
|
+
* const nodeId = useNodeId();
|
|
29
|
+
*
|
|
30
|
+
* return <span>{nodeId}</span>;
|
|
31
|
+
*}
|
|
32
|
+
*```
|
|
33
|
+
*/
|
|
34
|
+
export const useNodeId = (): string | null => {
|
|
35
|
+
const nodeId = useContext(NodeIdContext);
|
|
36
|
+
return nodeId;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export default NodeIdContext;
|
package/src/custom.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
declare module '*.css' {
|
|
2
|
+
const content: { [className: string]: string };
|
|
3
|
+
export default content;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
type SvgrComponent = React.FunctionComponent<React.SVGAttributes<SVGElement>>;
|
|
7
|
+
|
|
8
|
+
declare module '*.svg' {
|
|
9
|
+
const svgUrl: string;
|
|
10
|
+
const svgComponent: SvgrComponent;
|
|
11
|
+
export default svgUrl;
|
|
12
|
+
export { svgComponent as ReactComponent };
|
|
13
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const subSlotCache = new Map<symbol, Map<string, symbol>>();
|
|
2
|
+
|
|
3
|
+
export function resolveHookSlot(rest: unknown[]): symbol | undefined {
|
|
4
|
+
const tail = rest[rest.length - 1];
|
|
5
|
+
return typeof tail === 'symbol' ? (tail as symbol) : undefined;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function subSlot(slot: symbol | undefined, tag: string): symbol | undefined {
|
|
9
|
+
if (slot === undefined) return undefined;
|
|
10
|
+
let byTag = subSlotCache.get(slot);
|
|
11
|
+
if (byTag === undefined) subSlotCache.set(slot, (byTag = new Map()));
|
|
12
|
+
let derived = byTag.get(tag);
|
|
13
|
+
if (derived === undefined) {
|
|
14
|
+
derived = Symbol((slot.description ?? '') + ':' + tag);
|
|
15
|
+
byTag.set(tag, derived);
|
|
16
|
+
}
|
|
17
|
+
return derived;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function withoutSlot<T>(value: T | symbol | undefined): T | undefined {
|
|
21
|
+
return typeof value === 'symbol' ? undefined : value;
|
|
22
|
+
}
|