@octanejs/xyflow 0.1.18 → 0.1.20
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/package.json +6 -6
- package/src/additional-components/Background/Background.tsrx +32 -26
- package/src/additional-components/Background/Patterns.tsrx +15 -11
- package/src/additional-components/Controls/ControlButton.tsrx +5 -5
- package/src/additional-components/Controls/Controls.tsrx +48 -44
- package/src/additional-components/Controls/Icons/FitView.tsrx +5 -5
- package/src/additional-components/Controls/Icons/Lock.tsrx +5 -5
- package/src/additional-components/Controls/Icons/Minus.tsrx +5 -3
- package/src/additional-components/Controls/Icons/Plus.tsrx +5 -3
- package/src/additional-components/Controls/Icons/Unlock.tsrx +5 -5
- package/src/additional-components/EdgeToolbar/EdgeToolbar.tsrx +20 -17
- package/src/additional-components/MiniMap/MiniMap.tsrx +85 -86
- package/src/additional-components/MiniMap/MiniMapNode.tsrx +18 -16
- package/src/additional-components/MiniMap/MiniMapNodes.tsrx +47 -45
- package/src/additional-components/NodeResizer/NodeResizeControl.tsrx +31 -30
- package/src/additional-components/NodeResizer/NodeResizer.tsrx +10 -10
- package/src/additional-components/NodeToolbar/NodeToolbar.tsrx +32 -25
- package/src/components/A11yDescriptions/index.tsrx +23 -18
- package/src/components/Attribution/index.tsrx +11 -9
- package/src/components/BatchProvider/index.tsrx +8 -11
- package/src/components/ConnectionLine/index.tsrx +31 -27
- package/src/components/EdgeWrapper/EdgeUpdateAnchors.tsrx +38 -35
- package/src/components/EdgeWrapper/index.tsrx +155 -146
- package/src/components/Edges/BaseEdge.tsrx +16 -14
- package/src/components/Edges/BezierEdge.tsrx +47 -43
- package/src/components/Edges/EdgeAnchor.tsrx +13 -11
- package/src/components/Edges/EdgeText.tsrx +31 -26
- package/src/components/Edges/SimpleBezierEdge.tsrx +55 -44
- package/src/components/Edges/SmoothStepEdge.tsrx +49 -45
- package/src/components/Edges/StepEdge.tsrx +10 -7
- package/src/components/Edges/StraightEdge.tsrx +40 -36
- package/src/components/Handle/index.tsrx +73 -63
- package/src/components/NodeWrapper/index.tsrx +86 -72
- package/src/components/Nodes/DefaultNode.tsrx +7 -5
- package/src/components/Nodes/InputNode.tsrx +11 -7
- package/src/components/Nodes/OutputNode.tsrx +11 -7
- package/src/components/NodesSelection/index.tsrx +23 -22
- package/src/components/Panel/index.tsrx +17 -14
- package/src/components/ReactFlowProvider/index.tsrx +25 -23
- package/src/components/SelectionListener/index.tsrx +4 -2
- package/src/components/StoreUpdater/index.tsrx +43 -34
- package/src/components/UserSelection/index.tsrx +10 -8
- package/src/container/EdgeRenderer/MarkerDefinitions.tsrx +34 -29
- package/src/container/EdgeRenderer/MarkerSymbols.tsrx +21 -17
- package/src/container/EdgeRenderer/index.tsrx +52 -49
- package/src/container/FlowRenderer/index.tsrx +67 -66
- package/src/container/GraphView/index.tsrx +98 -96
- package/src/container/NodeRenderer/index.tsrx +74 -71
- package/src/container/Pane/index.tsrx +69 -60
- package/src/container/ReactFlow/Wrapper.tsrx +23 -21
- package/src/container/ReactFlow/index.tsrx +158 -153
- package/src/container/Viewport/index.tsrx +13 -7
- package/src/container/ZoomPane/index.tsrx +28 -25
|
@@ -62,12 +62,22 @@ function NodeWrapper<NodeType extends Node>({
|
|
|
62
62
|
NodeComponent = nodeTypes?.['default'] || builtinNodeTypes.default;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
const isDraggable = !!(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
65
|
+
const isDraggable = !!(
|
|
66
|
+
node.draggable ||
|
|
67
|
+
(nodesDraggable && typeof node.draggable === 'undefined')
|
|
68
|
+
);
|
|
69
|
+
const isSelectable = !!(
|
|
70
|
+
node.selectable ||
|
|
71
|
+
(elementsSelectable && typeof node.selectable === 'undefined')
|
|
72
|
+
);
|
|
73
|
+
const isConnectable = !!(
|
|
74
|
+
node.connectable ||
|
|
75
|
+
(nodesConnectable && typeof node.connectable === 'undefined')
|
|
76
|
+
);
|
|
77
|
+
const isFocusable = !!(
|
|
78
|
+
node.focusable ||
|
|
79
|
+
(nodesFocusable && typeof node.focusable === 'undefined')
|
|
80
|
+
);
|
|
71
81
|
|
|
72
82
|
const store = useStoreApi();
|
|
73
83
|
const hasDimensions = nodeHasDimensions(node);
|
|
@@ -114,9 +124,9 @@ function NodeWrapper<NodeType extends Node>({
|
|
|
114
124
|
|
|
115
125
|
if (isSelectable && (!selectNodesOnDrag || !isDraggable || nodeDragThreshold > 0)) {
|
|
116
126
|
/*
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
127
|
+
* this handler gets called by XYDrag on drag start when selectNodesOnDrag=true
|
|
128
|
+
* here we only need to call it when selectNodesOnDrag=false
|
|
129
|
+
*/
|
|
120
130
|
handleNodeClick({
|
|
121
131
|
id,
|
|
122
132
|
store,
|
|
@@ -144,7 +154,9 @@ function NodeWrapper<NodeType extends Node>({
|
|
|
144
154
|
nodeRef,
|
|
145
155
|
});
|
|
146
156
|
} else if (
|
|
147
|
-
isDraggable &&
|
|
157
|
+
isDraggable &&
|
|
158
|
+
node.selected &&
|
|
159
|
+
Object.prototype.hasOwnProperty.call(arrowKeyDiffs, event.key)
|
|
148
160
|
) {
|
|
149
161
|
// prevent default scrolling behavior on arrow key press when node is moved
|
|
150
162
|
event.preventDefault();
|
|
@@ -192,68 +204,70 @@ function NodeWrapper<NodeType extends Node>({
|
|
|
192
204
|
}
|
|
193
205
|
};
|
|
194
206
|
|
|
195
|
-
return
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
<
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
207
|
+
return (
|
|
208
|
+
<div
|
|
209
|
+
className={cc([
|
|
210
|
+
'react-flow__node',
|
|
211
|
+
`react-flow__node-${nodeType}`,
|
|
212
|
+
{ [noPanClassName]: isDraggable },
|
|
213
|
+
node.className,
|
|
214
|
+
{
|
|
215
|
+
selected: node.selected,
|
|
216
|
+
selectable: isSelectable,
|
|
217
|
+
parent: isParent,
|
|
218
|
+
draggable: isDraggable,
|
|
219
|
+
dragging,
|
|
220
|
+
},
|
|
221
|
+
])}
|
|
222
|
+
ref={nodeRef}
|
|
223
|
+
style={{
|
|
224
|
+
zIndex: internals.z,
|
|
225
|
+
transform: `translate(${internals.positionAbsolute.x}px,${internals.positionAbsolute.y}px)`,
|
|
226
|
+
pointerEvents: hasPointerEvents ? 'all' : 'none',
|
|
227
|
+
visibility: hasDimensions ? 'visible' : 'hidden',
|
|
228
|
+
...node.style,
|
|
229
|
+
...inlineDimensions,
|
|
230
|
+
}}
|
|
231
|
+
data-id={id}
|
|
232
|
+
data-testid={`rf__node-${id}`}
|
|
233
|
+
onMouseEnter={onMouseEnterHandler}
|
|
234
|
+
onMouseMove={onMouseMoveHandler}
|
|
235
|
+
onMouseLeave={onMouseLeaveHandler}
|
|
236
|
+
onContextMenu={onContextMenuHandler}
|
|
237
|
+
onClick={onSelectNodeHandler}
|
|
238
|
+
onDoubleClick={onDoubleClickHandler}
|
|
239
|
+
onKeyDown={isFocusable ? onKeyDown : undefined}
|
|
240
|
+
tabIndex={isFocusable ? 0 : undefined}
|
|
241
|
+
onFocus={isFocusable ? onFocus : undefined}
|
|
242
|
+
role={node.ariaRole ?? (isFocusable ? 'group' : undefined)}
|
|
243
|
+
aria-roledescription="node"
|
|
244
|
+
aria-describedby={disableKeyboardA11y ? undefined : `${ARIA_NODE_DESC_KEY}-${rfId}`}
|
|
245
|
+
aria-label={node.ariaLabel}
|
|
246
|
+
{...node.domAttributes}
|
|
247
|
+
>
|
|
248
|
+
<Provider value={id}>
|
|
249
|
+
<NodeComponent
|
|
250
|
+
id={id}
|
|
251
|
+
data={node.data}
|
|
252
|
+
type={nodeType}
|
|
253
|
+
positionAbsoluteX={internals.positionAbsolute.x}
|
|
254
|
+
positionAbsoluteY={internals.positionAbsolute.y}
|
|
255
|
+
selected={node.selected ?? false}
|
|
256
|
+
selectable={isSelectable}
|
|
257
|
+
draggable={isDraggable}
|
|
258
|
+
deletable={node.deletable ?? true}
|
|
259
|
+
isConnectable={isConnectable}
|
|
260
|
+
sourcePosition={node.sourcePosition}
|
|
261
|
+
targetPosition={node.targetPosition}
|
|
262
|
+
dragging={dragging}
|
|
263
|
+
dragHandle={node.dragHandle}
|
|
264
|
+
zIndex={internals.z}
|
|
265
|
+
parentId={node.parentId}
|
|
266
|
+
{...nodeDimensions}
|
|
267
|
+
/>
|
|
268
|
+
</Provider>
|
|
269
|
+
</div>
|
|
270
|
+
);
|
|
257
271
|
}
|
|
258
272
|
|
|
259
273
|
export default memo(NodeWrapper) as typeof NodeWrapper;
|
|
@@ -9,9 +9,11 @@ export function DefaultNode({
|
|
|
9
9
|
targetPosition = Position.Top,
|
|
10
10
|
sourcePosition = Position.Bottom,
|
|
11
11
|
}: NodeProps<BuiltInNode>) {
|
|
12
|
-
return
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
return (
|
|
13
|
+
<>
|
|
14
|
+
<Handle type="target" position={targetPosition} isConnectable={isConnectable} />
|
|
15
|
+
{data?.label}
|
|
16
|
+
<Handle type="source" position={sourcePosition} isConnectable={isConnectable} />
|
|
17
|
+
</>
|
|
18
|
+
);
|
|
17
19
|
}
|
|
@@ -3,11 +3,15 @@ import { Position } from '@xyflow/system';
|
|
|
3
3
|
import { Handle } from '../../components/Handle/index.tsrx';
|
|
4
4
|
import type { BuiltInNode, NodeProps } from '../../types/nodes';
|
|
5
5
|
|
|
6
|
-
export function InputNode({
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
export function InputNode({
|
|
7
|
+
data,
|
|
8
|
+
isConnectable,
|
|
9
|
+
sourcePosition = Position.Bottom,
|
|
10
|
+
}: NodeProps<BuiltInNode>) {
|
|
11
|
+
return (
|
|
12
|
+
<>
|
|
13
|
+
{data?.label}
|
|
14
|
+
<Handle type="source" position={sourcePosition} isConnectable={isConnectable} />
|
|
15
|
+
</>
|
|
16
|
+
);
|
|
13
17
|
}
|
|
@@ -3,11 +3,15 @@ import { Position } from '@xyflow/system';
|
|
|
3
3
|
import { Handle } from '../../components/Handle/index.tsrx';
|
|
4
4
|
import type { BuiltInNode, NodeProps } from '../../types/nodes';
|
|
5
5
|
|
|
6
|
-
export function OutputNode({
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
export function OutputNode({
|
|
7
|
+
data,
|
|
8
|
+
isConnectable,
|
|
9
|
+
targetPosition = Position.Top,
|
|
10
|
+
}: NodeProps<BuiltInNode>) {
|
|
11
|
+
return (
|
|
12
|
+
<>
|
|
13
|
+
<Handle type="target" position={targetPosition} isConnectable={isConnectable} />
|
|
14
|
+
{data?.label}
|
|
15
|
+
</>
|
|
16
|
+
);
|
|
13
17
|
}
|
|
@@ -63,13 +63,12 @@ export function NodesSelection<NodeType extends Node>({
|
|
|
63
63
|
return null;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
const onContextMenu =
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
: undefined;
|
|
66
|
+
const onContextMenu = onSelectionContextMenu
|
|
67
|
+
? (event: MouseEvent) => {
|
|
68
|
+
const selectedNodes = store.getState().nodes.filter((n) => n.selected);
|
|
69
|
+
onSelectionContextMenu(event, selectedNodes);
|
|
70
|
+
}
|
|
71
|
+
: undefined;
|
|
73
72
|
|
|
74
73
|
const onKeyDown = (event: KeyboardEvent) => {
|
|
75
74
|
if (Object.prototype.hasOwnProperty.call(arrowKeyDiffs, event.key)) {
|
|
@@ -82,22 +81,24 @@ export function NodesSelection<NodeType extends Node>({
|
|
|
82
81
|
}
|
|
83
82
|
};
|
|
84
83
|
|
|
85
|
-
return
|
|
86
|
-
className={cc(['react-flow__nodesselection', 'react-flow__container', noPanClassName])}
|
|
87
|
-
style={{
|
|
88
|
-
transform: transformString,
|
|
89
|
-
}}
|
|
90
|
-
>
|
|
84
|
+
return (
|
|
91
85
|
<div
|
|
92
|
-
|
|
93
|
-
className="react-flow__nodesselection-rect"
|
|
94
|
-
onContextMenu={onContextMenu}
|
|
95
|
-
tabIndex={disableKeyboardA11y ? undefined : -1}
|
|
96
|
-
onKeyDown={disableKeyboardA11y ? undefined : onKeyDown}
|
|
86
|
+
className={cc(['react-flow__nodesselection', 'react-flow__container', noPanClassName])}
|
|
97
87
|
style={{
|
|
98
|
-
|
|
99
|
-
height,
|
|
88
|
+
transform: transformString,
|
|
100
89
|
}}
|
|
101
|
-
|
|
102
|
-
|
|
90
|
+
>
|
|
91
|
+
<div
|
|
92
|
+
ref={nodeRef}
|
|
93
|
+
className="react-flow__nodesselection-rect"
|
|
94
|
+
onContextMenu={onContextMenu}
|
|
95
|
+
tabIndex={disableKeyboardA11y ? undefined : -1}
|
|
96
|
+
onKeyDown={disableKeyboardA11y ? undefined : onKeyDown}
|
|
97
|
+
style={{
|
|
98
|
+
width,
|
|
99
|
+
height,
|
|
100
|
+
}}
|
|
101
|
+
/>
|
|
102
|
+
</div>
|
|
103
|
+
);
|
|
103
104
|
}
|
|
@@ -6,14 +6,13 @@ import { fixedForwardRef } from '../../utils/general';
|
|
|
6
6
|
/**
|
|
7
7
|
* @expand
|
|
8
8
|
*/
|
|
9
|
-
export type PanelProps =
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
};
|
|
9
|
+
export type PanelProps = HTMLAttributes<HTMLDivElement> & {
|
|
10
|
+
/**
|
|
11
|
+
* The position of the panel.
|
|
12
|
+
* @default "top-left"
|
|
13
|
+
*/
|
|
14
|
+
position?: PanelPosition;
|
|
15
|
+
};
|
|
17
16
|
|
|
18
17
|
function PanelComponent(
|
|
19
18
|
{ position = 'top-left', children, className, style, ...rest }: PanelProps,
|
|
@@ -21,12 +20,16 @@ function PanelComponent(
|
|
|
21
20
|
) {
|
|
22
21
|
const positionClasses = `${position}`.split('-');
|
|
23
22
|
|
|
24
|
-
return
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
return (
|
|
24
|
+
<div
|
|
25
|
+
className={cc(['react-flow__panel', className, ...positionClasses])}
|
|
26
|
+
style={style}
|
|
27
|
+
ref={ref}
|
|
28
|
+
{...rest}
|
|
29
|
+
>
|
|
30
|
+
{children}
|
|
31
|
+
</div>
|
|
32
|
+
);
|
|
30
33
|
}
|
|
31
34
|
|
|
32
35
|
export const Panel = fixedForwardRef(PanelComponent);
|
|
@@ -23,30 +23,30 @@ export type ReactFlowProviderProps = {
|
|
|
23
23
|
/** When `true`, the flow will be zoomed and panned to fit all the nodes initially provided. */
|
|
24
24
|
fitView?: boolean;
|
|
25
25
|
/**
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
* You can provide an object of options to customize the initial fitView behavior.
|
|
27
|
+
*/
|
|
28
28
|
initialFitViewOptions?: FitViewOptions;
|
|
29
29
|
/** Initial minimum zoom level */
|
|
30
30
|
initialMinZoom?: number;
|
|
31
31
|
/** Initial maximum zoom level */
|
|
32
32
|
initialMaxZoom?: number;
|
|
33
33
|
/**
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
34
|
+
* The origin of the node to use when placing it in the flow or looking up its `x` and `y`
|
|
35
|
+
* position. An origin of `[0, 0]` means that a node's top left corner will be placed at the `x`
|
|
36
|
+
* and `y` position.
|
|
37
|
+
* @default [0, 0]
|
|
38
|
+
* @example
|
|
39
|
+
* [0, 0] // default, top left
|
|
40
|
+
* [0.5, 0.5] // center
|
|
41
|
+
* [1, 1] // bottom right
|
|
42
|
+
*/
|
|
43
43
|
nodeOrigin?: NodeOrigin;
|
|
44
44
|
/**
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
* By default, nodes can be placed on an infinite flow. You can use this prop to set a boundary.
|
|
46
|
+
*
|
|
47
|
+
* The first pair of coordinates is the top left boundary and the second pair is the bottom right.
|
|
48
|
+
* @example [[-1000, -10000], [1000, 1000]]
|
|
49
|
+
*/
|
|
50
50
|
nodeExtent?: CoordinateExtent;
|
|
51
51
|
children: OctaneNode;
|
|
52
52
|
zIndexMode?: ZIndexMode;
|
|
@@ -102,8 +102,8 @@ export function ReactFlowProvider({
|
|
|
102
102
|
zIndexMode,
|
|
103
103
|
children,
|
|
104
104
|
}: ReactFlowProviderProps) {
|
|
105
|
-
const [store] = useState(
|
|
106
|
-
|
|
105
|
+
const [store] = useState(() =>
|
|
106
|
+
createStore({
|
|
107
107
|
nodes,
|
|
108
108
|
edges,
|
|
109
109
|
defaultNodes,
|
|
@@ -120,9 +120,11 @@ export function ReactFlowProvider({
|
|
|
120
120
|
}),
|
|
121
121
|
);
|
|
122
122
|
|
|
123
|
-
return
|
|
124
|
-
<
|
|
125
|
-
<
|
|
126
|
-
|
|
127
|
-
|
|
123
|
+
return (
|
|
124
|
+
<Provider value={store}>
|
|
125
|
+
<BatchProvider>
|
|
126
|
+
<HandleConfigProvider>{children}</HandleConfigProvider>
|
|
127
|
+
</BatchProvider>
|
|
128
|
+
</Provider>
|
|
129
|
+
);
|
|
128
130
|
}
|
|
@@ -38,8 +38,10 @@ type SelectorSlice = ReturnType<typeof selector>;
|
|
|
38
38
|
const selectId = (obj: Node | Edge) => obj.id;
|
|
39
39
|
|
|
40
40
|
function areEqual(a: SelectorSlice, b: SelectorSlice) {
|
|
41
|
-
return
|
|
42
|
-
shallow(a.
|
|
41
|
+
return (
|
|
42
|
+
shallow(a.selectedNodes.map(selectId), b.selectedNodes.map(selectId)) &&
|
|
43
|
+
shallow(a.selectedEdges.map(selectId), b.selectedEdges.map(selectId))
|
|
44
|
+
);
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
function SelectionListenerInner<NodeType extends Node = Node, EdgeType extends Edge = Edge>({
|
|
@@ -79,10 +79,12 @@ const reactFlowFieldsToTrack = [
|
|
|
79
79
|
] as const;
|
|
80
80
|
|
|
81
81
|
type ReactFlowFieldsToTrack = (typeof reactFlowFieldsToTrack)[number];
|
|
82
|
-
type StoreUpdaterProps<NodeType extends Node = Node, EdgeType extends Edge = Edge> =
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
82
|
+
type StoreUpdaterProps<NodeType extends Node = Node, EdgeType extends Edge = Edge> = Pick<
|
|
83
|
+
ReactFlowProps<NodeType, EdgeType>,
|
|
84
|
+
ReactFlowFieldsToTrack
|
|
85
|
+
> & {
|
|
86
|
+
rfId: string;
|
|
87
|
+
};
|
|
86
88
|
|
|
87
89
|
// rfId doesn't exist in ReactFlowProps, but it's one of the fields we want to update
|
|
88
90
|
const fieldsToTrack = [...reactFlowFieldsToTrack, 'rfId'] as const;
|
|
@@ -100,10 +102,10 @@ const selector = (s: ReactFlowState) => ({
|
|
|
100
102
|
|
|
101
103
|
const initPrevValues = {
|
|
102
104
|
/*
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
* these are values that are also passed directly to other components
|
|
106
|
+
* than the StoreUpdater. We can reduce the number of setStore calls
|
|
107
|
+
* by setting the same values here as prev fields.
|
|
108
|
+
*/
|
|
107
109
|
translateExtent: infiniteExtent,
|
|
108
110
|
nodeOrigin: defaultNodeOrigin,
|
|
109
111
|
minZoom: 0.5,
|
|
@@ -140,34 +142,41 @@ export function StoreUpdater<NodeType extends Node = Node, EdgeType extends Edge
|
|
|
140
142
|
|
|
141
143
|
const previousFields = useRef<Partial<StoreUpdaterProps<NodeType, EdgeType>>>(initPrevValues);
|
|
142
144
|
|
|
143
|
-
useEffect(
|
|
144
|
-
|
|
145
|
-
const
|
|
146
|
-
|
|
145
|
+
useEffect(
|
|
146
|
+
() => {
|
|
147
|
+
for (const fieldName of fieldsToTrack) {
|
|
148
|
+
const fieldValue = props[fieldName];
|
|
149
|
+
const previousFieldValue = previousFields.current[fieldName];
|
|
147
150
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
151
|
+
if (fieldValue === previousFieldValue) continue;
|
|
152
|
+
if (typeof props[fieldName] === 'undefined') continue;
|
|
153
|
+
// Custom handling with dedicated setters for some fields
|
|
154
|
+
if (fieldName === 'nodes') setNodes(fieldValue as Node[]);
|
|
155
|
+
else if (fieldName === 'edges') setEdges(fieldValue as Edge[]);
|
|
156
|
+
else if (fieldName === 'minZoom') setMinZoom(fieldValue as number);
|
|
157
|
+
else if (fieldName === 'maxZoom') setMaxZoom(fieldValue as number);
|
|
158
|
+
else if (fieldName === 'translateExtent')
|
|
159
|
+
setTranslateExtent(fieldValue as CoordinateExtent);
|
|
160
|
+
else if (fieldName === 'nodeExtent') setNodeExtent(fieldValue as CoordinateExtent);
|
|
161
|
+
else if (fieldName === 'ariaLabelConfig')
|
|
162
|
+
store.setState({
|
|
163
|
+
ariaLabelConfig: mergeAriaLabelConfig(fieldValue as AriaLabelConfig),
|
|
164
|
+
});
|
|
165
|
+
else // Renamed fields
|
|
166
|
+
if (fieldName === 'fitView') store.setState({ fitViewQueued: fieldValue as boolean });
|
|
167
|
+
else if (fieldName === 'fitViewOptions')
|
|
168
|
+
store.setState({
|
|
169
|
+
fitViewOptions: fieldValue as FitViewOptions,
|
|
170
|
+
});
|
|
171
|
+
else
|
|
172
|
+
// General case
|
|
173
|
+
store.setState({ [fieldName]: fieldValue });
|
|
174
|
+
}
|
|
168
175
|
|
|
169
|
-
|
|
170
|
-
|
|
176
|
+
previousFields.current = props;
|
|
177
|
+
},
|
|
178
|
+
fieldsToTrack.map((fieldName) => props[fieldName]),
|
|
179
|
+
); // Only re-run the effect if one of the fields we track changes
|
|
171
180
|
|
|
172
181
|
return null;
|
|
173
182
|
}
|
|
@@ -16,12 +16,14 @@ export function UserSelection() {
|
|
|
16
16
|
return null;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
return
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
19
|
+
return (
|
|
20
|
+
<div
|
|
21
|
+
className="react-flow__selection react-flow__container"
|
|
22
|
+
style={{
|
|
23
|
+
width: userSelectionRect.width,
|
|
24
|
+
height: userSelectionRect.height,
|
|
25
|
+
transform: `translate(${userSelectionRect.x}px, ${userSelectionRect.y}px)`,
|
|
26
|
+
}}
|
|
27
|
+
/>
|
|
28
|
+
);
|
|
27
29
|
}
|
|
@@ -25,19 +25,21 @@ const Marker = ({
|
|
|
25
25
|
return null;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
return
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
28
|
+
return (
|
|
29
|
+
<marker
|
|
30
|
+
className="react-flow__arrowhead"
|
|
31
|
+
id={id}
|
|
32
|
+
markerWidth={`${width}`}
|
|
33
|
+
markerHeight={`${height}`}
|
|
34
|
+
viewBox="-10 -10 20 20"
|
|
35
|
+
markerUnits={markerUnits}
|
|
36
|
+
orient={orient}
|
|
37
|
+
refX="0"
|
|
38
|
+
refY="0"
|
|
39
|
+
>
|
|
40
|
+
<Symbol color={color} strokeWidth={strokeWidth} />
|
|
41
|
+
</marker>
|
|
42
|
+
);
|
|
41
43
|
};
|
|
42
44
|
|
|
43
45
|
/*
|
|
@@ -64,22 +66,25 @@ const MarkerDefinitions = ({ defaultColor, rfId }: MarkerDefinitionsProps) => {
|
|
|
64
66
|
return null;
|
|
65
67
|
}
|
|
66
68
|
|
|
67
|
-
return
|
|
68
|
-
<
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
69
|
+
return (
|
|
70
|
+
<svg className="react-flow__marker" aria-hidden="true">
|
|
71
|
+
<defs>
|
|
72
|
+
{markers.map((marker: MarkerProps) => (
|
|
73
|
+
<Marker
|
|
74
|
+
id={marker.id}
|
|
75
|
+
key={marker.id}
|
|
76
|
+
type={marker.type}
|
|
77
|
+
color={marker.color}
|
|
78
|
+
width={marker.width}
|
|
79
|
+
height={marker.height}
|
|
80
|
+
markerUnits={marker.markerUnits}
|
|
81
|
+
strokeWidth={marker.strokeWidth}
|
|
82
|
+
orient={marker.orient}
|
|
83
|
+
/>
|
|
84
|
+
))}
|
|
85
|
+
</defs>
|
|
86
|
+
</svg>
|
|
87
|
+
);
|
|
83
88
|
};
|
|
84
89
|
|
|
85
90
|
MarkerDefinitions.displayName = 'MarkerDefinitions';
|