@octanejs/xyflow 0.1.17 → 0.1.19

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 (53) hide show
  1. package/package.json +6 -6
  2. package/src/additional-components/Background/Background.tsrx +32 -26
  3. package/src/additional-components/Background/Patterns.tsrx +15 -11
  4. package/src/additional-components/Controls/ControlButton.tsrx +5 -5
  5. package/src/additional-components/Controls/Controls.tsrx +48 -44
  6. package/src/additional-components/Controls/Icons/FitView.tsrx +5 -5
  7. package/src/additional-components/Controls/Icons/Lock.tsrx +5 -5
  8. package/src/additional-components/Controls/Icons/Minus.tsrx +5 -3
  9. package/src/additional-components/Controls/Icons/Plus.tsrx +5 -3
  10. package/src/additional-components/Controls/Icons/Unlock.tsrx +5 -5
  11. package/src/additional-components/EdgeToolbar/EdgeToolbar.tsrx +20 -17
  12. package/src/additional-components/MiniMap/MiniMap.tsrx +85 -86
  13. package/src/additional-components/MiniMap/MiniMapNode.tsrx +18 -16
  14. package/src/additional-components/MiniMap/MiniMapNodes.tsrx +47 -45
  15. package/src/additional-components/NodeResizer/NodeResizeControl.tsrx +31 -30
  16. package/src/additional-components/NodeResizer/NodeResizer.tsrx +10 -10
  17. package/src/additional-components/NodeToolbar/NodeToolbar.tsrx +32 -25
  18. package/src/components/A11yDescriptions/index.tsrx +23 -18
  19. package/src/components/Attribution/index.tsrx +11 -9
  20. package/src/components/BatchProvider/index.tsrx +8 -11
  21. package/src/components/ConnectionLine/index.tsrx +31 -27
  22. package/src/components/EdgeWrapper/EdgeUpdateAnchors.tsrx +38 -35
  23. package/src/components/EdgeWrapper/index.tsrx +155 -146
  24. package/src/components/Edges/BaseEdge.tsrx +16 -14
  25. package/src/components/Edges/BezierEdge.tsrx +47 -43
  26. package/src/components/Edges/EdgeAnchor.tsrx +13 -11
  27. package/src/components/Edges/EdgeText.tsrx +31 -26
  28. package/src/components/Edges/SimpleBezierEdge.tsrx +55 -44
  29. package/src/components/Edges/SmoothStepEdge.tsrx +49 -45
  30. package/src/components/Edges/StepEdge.tsrx +10 -7
  31. package/src/components/Edges/StraightEdge.tsrx +40 -36
  32. package/src/components/Handle/index.tsrx +73 -63
  33. package/src/components/NodeWrapper/index.tsrx +86 -72
  34. package/src/components/Nodes/DefaultNode.tsrx +7 -5
  35. package/src/components/Nodes/InputNode.tsrx +11 -7
  36. package/src/components/Nodes/OutputNode.tsrx +11 -7
  37. package/src/components/NodesSelection/index.tsrx +23 -22
  38. package/src/components/Panel/index.tsrx +17 -14
  39. package/src/components/ReactFlowProvider/index.tsrx +25 -23
  40. package/src/components/SelectionListener/index.tsrx +4 -2
  41. package/src/components/StoreUpdater/index.tsrx +43 -34
  42. package/src/components/UserSelection/index.tsrx +10 -8
  43. package/src/container/EdgeRenderer/MarkerDefinitions.tsrx +34 -29
  44. package/src/container/EdgeRenderer/MarkerSymbols.tsrx +21 -17
  45. package/src/container/EdgeRenderer/index.tsrx +52 -49
  46. package/src/container/FlowRenderer/index.tsrx +67 -66
  47. package/src/container/GraphView/index.tsrx +98 -96
  48. package/src/container/NodeRenderer/index.tsrx +74 -71
  49. package/src/container/Pane/index.tsrx +69 -60
  50. package/src/container/ReactFlow/Wrapper.tsrx +23 -21
  51. package/src/container/ReactFlow/index.tsrx +158 -153
  52. package/src/container/Viewport/index.tsrx +13 -7
  53. 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 = !!(node.draggable || nodesDraggable && typeof node.draggable === 'undefined');
66
- const isSelectable = !!(node.selectable ||
67
- elementsSelectable && typeof node.selectable === 'undefined');
68
- const isConnectable = !!(node.connectable ||
69
- nodesConnectable && typeof node.connectable === 'undefined');
70
- const isFocusable = !!(node.focusable || nodesFocusable && typeof node.focusable === 'undefined');
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
- * this handler gets called by XYDrag on drag start when selectNodesOnDrag=true
118
- * here we only need to call it when selectNodesOnDrag=false
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 && node.selected && Object.prototype.hasOwnProperty.call(arrowKeyDiffs, event.key)
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 <div
196
- className={cc([
197
- 'react-flow__node',
198
- `react-flow__node-${nodeType}`,
199
- { [noPanClassName]: isDraggable },
200
- node.className,
201
- {
202
- selected: node.selected,
203
- selectable: isSelectable,
204
- parent: isParent,
205
- draggable: isDraggable,
206
- dragging,
207
- },
208
- ])}
209
- ref={nodeRef}
210
- style={{
211
- zIndex: internals.z,
212
- transform: `translate(${internals.positionAbsolute.x}px,${internals.positionAbsolute.y}px)`,
213
- pointerEvents: hasPointerEvents ? 'all' : 'none',
214
- visibility: hasDimensions ? 'visible' : 'hidden',
215
- ...node.style,
216
- ...inlineDimensions,
217
- }}
218
- data-id={id}
219
- data-testid={`rf__node-${id}`}
220
- onMouseEnter={onMouseEnterHandler}
221
- onMouseMove={onMouseMoveHandler}
222
- onMouseLeave={onMouseLeaveHandler}
223
- onContextMenu={onContextMenuHandler}
224
- onClick={onSelectNodeHandler}
225
- onDoubleClick={onDoubleClickHandler}
226
- onKeyDown={isFocusable ? onKeyDown : undefined}
227
- tabIndex={isFocusable ? 0 : undefined}
228
- onFocus={isFocusable ? onFocus : undefined}
229
- role={node.ariaRole ?? (isFocusable ? 'group' : undefined)}
230
- aria-roledescription="node"
231
- aria-describedby={disableKeyboardA11y ? undefined : `${ARIA_NODE_DESC_KEY}-${rfId}`}
232
- aria-label={node.ariaLabel}
233
- {...node.domAttributes}
234
- >
235
- <Provider value={id}>
236
- <NodeComponent
237
- id={id}
238
- data={node.data}
239
- type={nodeType}
240
- positionAbsoluteX={internals.positionAbsolute.x}
241
- positionAbsoluteY={internals.positionAbsolute.y}
242
- selected={node.selected ?? false}
243
- selectable={isSelectable}
244
- draggable={isDraggable}
245
- deletable={node.deletable ?? true}
246
- isConnectable={isConnectable}
247
- sourcePosition={node.sourcePosition}
248
- targetPosition={node.targetPosition}
249
- dragging={dragging}
250
- dragHandle={node.dragHandle}
251
- zIndex={internals.z}
252
- parentId={node.parentId}
253
- {...nodeDimensions}
254
- />
255
- </Provider>
256
- </div>;
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
- <Handle type="target" position={targetPosition} isConnectable={isConnectable} />
14
- {data?.label}
15
- <Handle type="source" position={sourcePosition} isConnectable={isConnectable} />
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({ data, isConnectable, sourcePosition = Position.Bottom }: NodeProps<
7
- BuiltInNode
8
- >) {
9
- return <>
10
- {data?.label}
11
- <Handle type="source" position={sourcePosition} isConnectable={isConnectable} />
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({ data, isConnectable, targetPosition = Position.Top }: NodeProps<
7
- BuiltInNode
8
- >) {
9
- return <>
10
- <Handle type="target" position={targetPosition} isConnectable={isConnectable} />
11
- {data?.label}
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
- onSelectionContextMenu
68
- ? (event: MouseEvent) => {
69
- const selectedNodes = store.getState().nodes.filter((n) => n.selected);
70
- onSelectionContextMenu(event, selectedNodes);
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 <div
86
- className={cc(['react-flow__nodesselection', 'react-flow__container', noPanClassName])}
87
- style={{
88
- transform: transformString,
89
- }}
90
- >
84
+ return (
91
85
  <div
92
- ref={nodeRef}
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
- width,
99
- height,
88
+ transform: transformString,
100
89
  }}
101
- />
102
- </div>;
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
- HTMLAttributes<HTMLDivElement> & {
11
- /**
12
- * The position of the panel.
13
- * @default "top-left"
14
- */
15
- position?: PanelPosition;
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 <div
25
- className={cc(['react-flow__panel', className, ...positionClasses])}
26
- style={style}
27
- ref={ref}
28
- {...rest}
29
- >{children}</div>;
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
- * You can provide an object of options to customize the initial fitView behavior.
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
- * 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
- */
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
- * 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
- */
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
- () => createStore({
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 <Provider value={store}>
124
- <BatchProvider>
125
- <HandleConfigProvider>{children}</HandleConfigProvider>
126
- </BatchProvider>
127
- </Provider>;
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 shallow(a.selectedNodes.map(selectId), b.selectedNodes.map(selectId)) &&
42
- shallow(a.selectedEdges.map(selectId), b.selectedEdges.map(selectId));
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
- Pick<ReactFlowProps<NodeType, EdgeType>, ReactFlowFieldsToTrack> & {
84
- rfId: string;
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
- * these are values that are also passed directly to other components
104
- * than the StoreUpdater. We can reduce the number of setStore calls
105
- * by setting the same values here as prev fields.
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
- for (const fieldName of fieldsToTrack) {
145
- const fieldValue = props[fieldName];
146
- const previousFieldValue = previousFields.current[fieldName];
145
+ useEffect(
146
+ () => {
147
+ for (const fieldName of fieldsToTrack) {
148
+ const fieldValue = props[fieldName];
149
+ const previousFieldValue = previousFields.current[fieldName];
147
150
 
148
- if (fieldValue === previousFieldValue) continue;
149
- if (typeof props[fieldName] === 'undefined') continue;
150
- // Custom handling with dedicated setters for some fields
151
- if (fieldName === 'nodes') setNodes(fieldValue as Node[]);
152
- else if (fieldName === 'edges') setEdges(fieldValue as Edge[]);
153
- else if (fieldName === 'minZoom') setMinZoom(fieldValue as number);
154
- else if (fieldName === 'maxZoom') setMaxZoom(fieldValue as number);
155
- else if (fieldName === 'translateExtent') setTranslateExtent(fieldValue as CoordinateExtent);
156
- else if (fieldName === 'nodeExtent') setNodeExtent(fieldValue as CoordinateExtent);
157
- else if (fieldName === 'ariaLabelConfig') store.setState({
158
- ariaLabelConfig: mergeAriaLabelConfig(fieldValue as AriaLabelConfig),
159
- });
160
- else // Renamed fields
161
- if (fieldName === 'fitView') store.setState({ fitViewQueued: fieldValue as boolean });
162
- else if (fieldName === 'fitViewOptions') store.setState({
163
- fitViewOptions: fieldValue as FitViewOptions,
164
- });
165
- else // General case
166
- store.setState({ [fieldName]: fieldValue });
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
- previousFields.current = props;
170
- }, fieldsToTrack.map((fieldName) => props[fieldName])); // Only re-run the effect if one of the fields we track changes
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 <div
20
- className="react-flow__selection react-flow__container"
21
- style={{
22
- width: userSelectionRect.width,
23
- height: userSelectionRect.height,
24
- transform: `translate(${userSelectionRect.x}px, ${userSelectionRect.y}px)`,
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 <marker
29
- className="react-flow__arrowhead"
30
- id={id}
31
- markerWidth={`${width}`}
32
- markerHeight={`${height}`}
33
- viewBox="-10 -10 20 20"
34
- markerUnits={markerUnits}
35
- orient={orient}
36
- refX="0"
37
- refY="0"
38
- >
39
- <Symbol color={color} strokeWidth={strokeWidth} />
40
- </marker>;
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 <svg className="react-flow__marker" aria-hidden="true">
68
- <defs>{markers.map(
69
- (marker: MarkerProps) =>
70
- <Marker
71
- id={marker.id}
72
- key={marker.id}
73
- type={marker.type}
74
- color={marker.color}
75
- width={marker.width}
76
- height={marker.height}
77
- markerUnits={marker.markerUnits}
78
- strokeWidth={marker.strokeWidth}
79
- orient={marker.orient}
80
- />,
81
- )}</defs>
82
- </svg>;
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';