@octanejs/xyflow 0.1.18 → 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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@octanejs/xyflow",
3
- "version": "0.1.18",
3
+ "version": "0.1.19",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "engines": {
@@ -43,22 +43,22 @@
43
43
  "./dist/style.css": "./src/styles/style.css"
44
44
  },
45
45
  "dependencies": {
46
- "@octanejs/zustand": "0.1.62",
46
+ "@octanejs/zustand": "0.1.63",
47
47
  "@xyflow/system": "0.0.79",
48
48
  "classcat": "5.0.5"
49
49
  },
50
50
  "peerDependencies": {
51
- "octane": "^0.10.0"
51
+ "octane": "^0.11.0"
52
52
  },
53
53
  "devDependencies": {
54
- "@octanejs/zustand": "0.1.62",
55
- "@tsrx/react": "^0.3.7",
54
+ "@octanejs/zustand": "0.1.63",
55
+ "@tsrx/react": "^0.4.5",
56
56
  "@types/jsdom": "30.0.0",
57
57
  "@types/react": "^19.2.17",
58
58
  "@types/react-dom": "^19.2.3",
59
59
  "@xyflow/react": "12.11.2",
60
60
  "esbuild": "^0.28.1",
61
- "octane": "0.10.2",
61
+ "octane": "0.11.0",
62
62
  "react": "19.2.7",
63
63
  "react-dom": "19.2.7",
64
64
  "vitest": "^4.1.10"
@@ -53,37 +53,43 @@ function BackgroundComponent({
53
53
 
54
54
  const _patternId = `${patternId}${id ? id : ''}`;
55
55
 
56
- return <svg
57
- className={cc(['react-flow__background', className])}
58
- style={{
59
- ...style,
60
- ...containerStyle,
61
- '--xy-background-color-props': bgColor,
62
- '--xy-background-pattern-color-props': color,
63
- } as CSSProperties}
64
- ref={ref}
65
- data-testid="rf__background"
66
- >
67
- <pattern
68
- id={_patternId}
69
- x={transform[0] % scaledGap[0]}
70
- y={transform[1] % scaledGap[1]}
71
- width={scaledGap[0]}
72
- height={scaledGap[1]}
73
- patternUnits="userSpaceOnUse"
74
- patternTransform={`translate(-${scaledOffset[0]},-${scaledOffset[1]})`}
56
+ return (
57
+ <svg
58
+ className={cc(['react-flow__background', className])}
59
+ style={
60
+ {
61
+ ...style,
62
+ ...containerStyle,
63
+ '--xy-background-color-props': bgColor,
64
+ '--xy-background-pattern-color-props': color,
65
+ } as CSSProperties
66
+ }
67
+ ref={ref}
68
+ data-testid="rf__background"
75
69
  >
76
- {isDots
77
- ? <DotPattern radius={scaledSize / 2} className={patternClassName} />
78
- : <LinePattern
70
+ <pattern
71
+ id={_patternId}
72
+ x={transform[0] % scaledGap[0]}
73
+ y={transform[1] % scaledGap[1]}
74
+ width={scaledGap[0]}
75
+ height={scaledGap[1]}
76
+ patternUnits="userSpaceOnUse"
77
+ patternTransform={`translate(-${scaledOffset[0]},-${scaledOffset[1]})`}
78
+ >
79
+ {isDots ? (
80
+ <DotPattern radius={scaledSize / 2} className={patternClassName} />
81
+ ) : (
82
+ <LinePattern
79
83
  dimensions={patternDimensions}
80
84
  lineWidth={lineWidth}
81
85
  variant={variant}
82
86
  className={patternClassName}
83
- />}
84
- </pattern>
85
- <rect x="0" y="0" width="100%" height="100%" fill={`url(#${_patternId})`} />
86
- </svg>;
87
+ />
88
+ )}
89
+ </pattern>
90
+ <rect x="0" y="0" width="100%" height="100%" fill={`url(#${_patternId})`} />
91
+ </svg>
92
+ );
87
93
  }
88
94
 
89
95
  BackgroundComponent.displayName = 'Background';
@@ -10,11 +10,13 @@ type LinePatternProps = {
10
10
  };
11
11
 
12
12
  export function LinePattern({ dimensions, lineWidth, variant, className }: LinePatternProps) {
13
- return <path
14
- strokeWidth={lineWidth}
15
- d={`M${dimensions[0] / 2} 0 V${dimensions[1]} M0 ${dimensions[1] / 2} H${dimensions[0]}`}
16
- className={cc(['react-flow__background-pattern', variant, className])}
17
- />;
13
+ return (
14
+ <path
15
+ strokeWidth={lineWidth}
16
+ d={`M${dimensions[0] / 2} 0 V${dimensions[1]} M0 ${dimensions[1] / 2} H${dimensions[0]}`}
17
+ className={cc(['react-flow__background-pattern', variant, className])}
18
+ />
19
+ );
18
20
  }
19
21
 
20
22
  type DotPatternProps = {
@@ -23,10 +25,12 @@ type DotPatternProps = {
23
25
  };
24
26
 
25
27
  export function DotPattern({ radius, className }: DotPatternProps) {
26
- return <circle
27
- cx={radius}
28
- cy={radius}
29
- r={radius}
30
- className={cc(['react-flow__background-pattern', 'dots', className])}
31
- />;
28
+ return (
29
+ <circle
30
+ cx={radius}
31
+ cy={radius}
32
+ r={radius}
33
+ className={cc(['react-flow__background-pattern', 'dots', className])}
34
+ />
35
+ );
32
36
  }
@@ -26,9 +26,9 @@ import type { ControlButtonProps } from './types';
26
26
  *```
27
27
  */
28
28
  export function ControlButton({ children, className, ...rest }: ControlButtonProps) {
29
- return <button
30
- type="button"
31
- className={cc(['react-flow__controls-button', className])}
32
- {...rest}
33
- >{children}</button>;
29
+ return (
30
+ <button type="button" className={cc(['react-flow__controls-button', className])} {...rest}>
31
+ {children}
32
+ </button>
33
+ );
34
34
  }
@@ -70,56 +70,60 @@ function ControlsComponent({
70
70
  onInteractiveChange?.(!isInteractive);
71
71
  };
72
72
 
73
- const orientationClass =
74
- orientation === 'horizontal' ? 'horizontal' : 'vertical';
75
- return <Panel
76
- className={cc(['react-flow__controls', orientationClass, className])}
77
- position={position}
78
- style={style}
79
- data-testid="rf__controls"
80
- aria-label={ariaLabel ?? ariaLabelConfig['controls.ariaLabel']}
81
- >
82
- {showZoom &&
83
- <>
73
+ const orientationClass = orientation === 'horizontal' ? 'horizontal' : 'vertical';
74
+ return (
75
+ <Panel
76
+ className={cc(['react-flow__controls', orientationClass, className])}
77
+ position={position}
78
+ style={style}
79
+ data-testid="rf__controls"
80
+ aria-label={ariaLabel ?? ariaLabelConfig['controls.ariaLabel']}
81
+ >
82
+ {showZoom && (
83
+ <>
84
+ <ControlButton
85
+ onClick={onZoomInHandler}
86
+ className="react-flow__controls-zoomin"
87
+ title={ariaLabelConfig['controls.zoomIn.ariaLabel']}
88
+ aria-label={ariaLabelConfig['controls.zoomIn.ariaLabel']}
89
+ disabled={maxZoomReached}
90
+ >
91
+ <PlusIcon />
92
+ </ControlButton>
93
+ <ControlButton
94
+ onClick={onZoomOutHandler}
95
+ className="react-flow__controls-zoomout"
96
+ title={ariaLabelConfig['controls.zoomOut.ariaLabel']}
97
+ aria-label={ariaLabelConfig['controls.zoomOut.ariaLabel']}
98
+ disabled={minZoomReached}
99
+ >
100
+ <MinusIcon />
101
+ </ControlButton>
102
+ </>
103
+ )}
104
+ {showFitView && (
84
105
  <ControlButton
85
- onClick={onZoomInHandler}
86
- className="react-flow__controls-zoomin"
87
- title={ariaLabelConfig['controls.zoomIn.ariaLabel']}
88
- aria-label={ariaLabelConfig['controls.zoomIn.ariaLabel']}
89
- disabled={maxZoomReached}
106
+ className="react-flow__controls-fitview"
107
+ onClick={onFitViewHandler}
108
+ title={ariaLabelConfig['controls.fitView.ariaLabel']}
109
+ aria-label={ariaLabelConfig['controls.fitView.ariaLabel']}
90
110
  >
91
- <PlusIcon />
111
+ <FitViewIcon />
92
112
  </ControlButton>
113
+ )}
114
+ {showInteractive && (
93
115
  <ControlButton
94
- onClick={onZoomOutHandler}
95
- className="react-flow__controls-zoomout"
96
- title={ariaLabelConfig['controls.zoomOut.ariaLabel']}
97
- aria-label={ariaLabelConfig['controls.zoomOut.ariaLabel']}
98
- disabled={minZoomReached}
116
+ className="react-flow__controls-interactive"
117
+ onClick={onToggleInteractivity}
118
+ title={ariaLabelConfig['controls.interactive.ariaLabel']}
119
+ aria-label={ariaLabelConfig['controls.interactive.ariaLabel']}
99
120
  >
100
- <MinusIcon />
121
+ {isInteractive ? <UnlockIcon /> : <LockIcon />}
101
122
  </ControlButton>
102
- </>}
103
- {showFitView &&
104
- <ControlButton
105
- className="react-flow__controls-fitview"
106
- onClick={onFitViewHandler}
107
- title={ariaLabelConfig['controls.fitView.ariaLabel']}
108
- aria-label={ariaLabelConfig['controls.fitView.ariaLabel']}
109
- >
110
- <FitViewIcon />
111
- </ControlButton>}
112
- {showInteractive &&
113
- <ControlButton
114
- className="react-flow__controls-interactive"
115
- onClick={onToggleInteractivity}
116
- title={ariaLabelConfig['controls.interactive.ariaLabel']}
117
- aria-label={ariaLabelConfig['controls.interactive.ariaLabel']}
118
- >
119
- {isInteractive ? <UnlockIcon /> : <LockIcon />}
120
- </ControlButton>}
121
- {children}
122
- </Panel>;
123
+ )}
124
+ {children}
125
+ </Panel>
126
+ );
123
127
  }
124
128
 
125
129
  ControlsComponent.displayName = 'Controls';
@@ -1,7 +1,7 @@
1
1
  export function FitViewIcon() {
2
- return <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 30">
3
- <path
4
- d="M3.692 4.63c0-.53.4-.938.939-.938h5.215V0H4.708C2.13 0 0 2.054 0 4.63v5.216h3.692V4.631zM27.354 0h-5.2v3.692h5.17c.53 0 .984.4.984.939v5.215H32V4.631A4.624 4.624 0 0027.354 0zm.954 24.83c0 .532-.4.94-.939.94h-5.215v3.768h5.215c2.577 0 4.631-2.13 4.631-4.707v-5.139h-3.692v5.139zm-23.677.94c-.531 0-.939-.4-.939-.94v-5.138H0v5.139c0 2.577 2.13 4.707 4.708 4.707h5.138V25.77H4.631z"
5
- />
6
- </svg>;
2
+ return (
3
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 30">
4
+ <path d="M3.692 4.63c0-.53.4-.938.939-.938h5.215V0H4.708C2.13 0 0 2.054 0 4.63v5.216h3.692V4.631zM27.354 0h-5.2v3.692h5.17c.53 0 .984.4.984.939v5.215H32V4.631A4.624 4.624 0 0027.354 0zm.954 24.83c0 .532-.4.94-.939.94h-5.215v3.768h5.215c2.577 0 4.631-2.13 4.631-4.707v-5.139h-3.692v5.139zm-23.677.94c-.531 0-.939-.4-.939-.94v-5.138H0v5.139c0 2.577 2.13 4.707 4.708 4.707h5.138V25.77H4.631z" />
5
+ </svg>
6
+ );
7
7
  }
@@ -1,7 +1,7 @@
1
1
  export function LockIcon() {
2
- return <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 25 32">
3
- <path
4
- d="M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0 8 0 4.571 3.429 4.571 7.619v3.048H3.048A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047zm4.724-13.866H7.467V7.619c0-2.59 2.133-4.724 4.723-4.724 2.591 0 4.724 2.133 4.724 4.724v3.048z"
5
- />
6
- </svg>;
2
+ return (
3
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 25 32">
4
+ <path d="M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0 8 0 4.571 3.429 4.571 7.619v3.048H3.048A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047zm4.724-13.866H7.467V7.619c0-2.59 2.133-4.724 4.723-4.724 2.591 0 4.724 2.133 4.724 4.724v3.048z" />
5
+ </svg>
6
+ );
7
7
  }
@@ -1,5 +1,7 @@
1
1
  export function MinusIcon() {
2
- return <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 5">
3
- <path d="M0 0h32v4.2H0z" />
4
- </svg>;
2
+ return (
3
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 5">
4
+ <path d="M0 0h32v4.2H0z" />
5
+ </svg>
6
+ );
5
7
  }
@@ -1,5 +1,7 @@
1
1
  export function PlusIcon() {
2
- return <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
3
- <path d="M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z" />
4
- </svg>;
2
+ return (
3
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
4
+ <path d="M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z" />
5
+ </svg>
6
+ );
5
7
  }
@@ -1,7 +1,7 @@
1
1
  export function UnlockIcon() {
2
- return <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 25 32">
3
- <path
4
- d="M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0c-4.114 1.828-1.37 2.133.305 2.438 1.676.305 4.42 2.59 4.42 5.181v3.048H3.047A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047z"
5
- />
6
- </svg>;
2
+ return (
3
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 25 32">
4
+ <path d="M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0c-4.114 1.828-1.37 2.133.305 2.438 1.676.305 4.42 2.59 4.42 5.181v3.048H3.047A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047z" />
5
+ </svg>
6
+ );
7
7
  }
@@ -50,8 +50,7 @@ export function EdgeToolbar({
50
50
  [edgeId],
51
51
  );
52
52
  const edge = useStore(edgeSelector, shallow);
53
- const isActive =
54
- typeof isVisible === 'boolean' ? isVisible : edge?.selected;
53
+ const isActive = typeof isVisible === 'boolean' ? isVisible : edge?.selected;
55
54
  const zoom = useStore(zoomSelector);
56
55
 
57
56
  if (!isActive) {
@@ -61,19 +60,23 @@ export function EdgeToolbar({
61
60
  const zIndex = (edge?.zIndex ?? 0) + 1;
62
61
  const transform = getEdgeToolbarTransform(x, y, zoom, alignX, alignY);
63
62
 
64
- return <EdgeLabelRenderer>
65
- <div
66
- style={{
67
- position: 'absolute',
68
- transform,
69
- zIndex,
70
- pointerEvents: 'all',
71
- transformOrigin: '0 0',
72
- ...style,
73
- }}
74
- className={cc(['react-flow__edge-toolbar', className])}
75
- data-id={edge?.id ?? ''}
76
- {...rest}
77
- >{children}</div>
78
- </EdgeLabelRenderer>;
63
+ return (
64
+ <EdgeLabelRenderer>
65
+ <div
66
+ style={{
67
+ position: 'absolute',
68
+ transform,
69
+ zIndex,
70
+ pointerEvents: 'all',
71
+ transformOrigin: '0 0',
72
+ ...style,
73
+ }}
74
+ className={cc(['react-flow__edge-toolbar', className])}
75
+ data-id={edge?.id ?? ''}
76
+ {...rest}
77
+ >
78
+ {children}
79
+ </div>
80
+ </EdgeLabelRenderer>
81
+ );
79
82
  }
@@ -33,9 +33,10 @@ const selector = (s: ReactFlowState) => {
33
33
 
34
34
  return {
35
35
  viewBB,
36
- boundingRect: s.nodeLookup.size > 0
37
- ? getBoundsOfRects(getInternalNodesBounds(s.nodeLookup, { filter: filterHidden }), viewBB)
38
- : viewBB,
36
+ boundingRect:
37
+ s.nodeLookup.size > 0
38
+ ? getBoundsOfRects(getInternalNodesBounds(s.nodeLookup, { filter: filterHidden }), viewBB)
39
+ : viewBB,
39
40
  rfId: s.rfId,
40
41
  panZoom: s.panZoom,
41
42
  translateExtent: s.translateExtent,
@@ -53,12 +54,14 @@ const rectEqual = (a: Rect, b: Rect) =>
53
54
  // the selector builds new viewBB/boundingRect objects every call, so the default shallow equality always
54
55
  // treats them as changed; comparing the rects by value lets the minimap skip re-renders when nothing moved
55
56
  const areEqual = (a: MiniMapSlice, b: MiniMapSlice) =>
56
- rectEqual(a.viewBB, b.viewBB) && rectEqual(a.boundingRect, b.boundingRect) && a.rfId === b.rfId &&
57
- a.panZoom === b.panZoom &&
58
- a.translateExtent === b.translateExtent &&
59
- a.flowWidth === b.flowWidth &&
60
- a.flowHeight === b.flowHeight &&
61
- a.ariaLabelConfig === b.ariaLabelConfig;
57
+ rectEqual(a.viewBB, b.viewBB) &&
58
+ rectEqual(a.boundingRect, b.boundingRect) &&
59
+ a.rfId === b.rfId &&
60
+ a.panZoom === b.panZoom &&
61
+ a.translateExtent === b.translateExtent &&
62
+ a.flowWidth === b.flowWidth &&
63
+ a.flowHeight === b.flowHeight &&
64
+ a.ariaLabelConfig === b.ariaLabelConfig;
62
65
 
63
66
  const ARIA_LABEL_KEY = 'react-flow__minimap-desc';
64
67
  function MiniMapComponent<NodeType extends Node = Node>({
@@ -70,9 +73,9 @@ function MiniMapComponent<NodeType extends Node = Node>({
70
73
  nodeBorderRadius = 5,
71
74
  nodeStrokeWidth,
72
75
  /*
73
- * We need to rename the prop to be `CapitalCase` so that JSX will render it as
74
- * a component properly.
75
- */
76
+ * We need to rename the prop to be `CapitalCase` so that JSX will render it as
77
+ * a component properly.
78
+ */
76
79
  nodeComponent,
77
80
  bgColor,
78
81
  maskColor,
@@ -100,8 +103,8 @@ function MiniMapComponent<NodeType extends Node = Node>({
100
103
  flowHeight,
101
104
  ariaLabelConfig,
102
105
  } = useStore(selector, areEqual);
103
- const elementWidth = style?.width as number ?? defaultWidth;
104
- const elementHeight = style?.height as number ?? defaultHeight;
106
+ const elementWidth = (style?.width as number) ?? defaultWidth;
107
+ const elementHeight = (style?.height as number) ?? defaultHeight;
105
108
  const scaledWidth = boundingRect.width / elementWidth;
106
109
  const scaledHeight = boundingRect.height / elementHeight;
107
110
  const viewScale = Math.max(scaledWidth, scaledHeight);
@@ -145,83 +148,79 @@ function MiniMapComponent<NodeType extends Node = Node>({
145
148
  });
146
149
  }, [pannable, zoomable, inversePan, zoomStep, translateExtent, flowWidth, flowHeight]);
147
150
 
148
- const onSvgClick =
149
- onClick
150
- ? (event: MouseEvent) => {
151
- const [x, y] = minimapInstance.current?.pointer(event) || [0, 0];
152
- onClick(event, { x, y });
153
- }
154
- : undefined;
155
-
156
- const onSvgNodeClick =
157
- onNodeClick
158
- ? useCallback((event: MouseEvent, nodeId: string) => {
159
- const node: NodeType = store.getState().nodeLookup.get(nodeId)!.internals.userNode;
160
- onNodeClick(event, node);
161
- }, [])
162
- : undefined;
151
+ const onSvgClick = onClick
152
+ ? (event: MouseEvent) => {
153
+ const [x, y] = minimapInstance.current?.pointer(event) || [0, 0];
154
+ onClick(event, { x, y });
155
+ }
156
+ : undefined;
157
+
158
+ const onSvgNodeClick = onNodeClick
159
+ ? useCallback((event: MouseEvent, nodeId: string) => {
160
+ const node: NodeType = store.getState().nodeLookup.get(nodeId)!.internals.userNode;
161
+ onNodeClick(event, node);
162
+ }, [])
163
+ : undefined;
163
164
 
164
165
  const _ariaLabel = ariaLabel ?? ariaLabelConfig['minimap.ariaLabel'];
165
166
 
166
- return <Panel
167
- position={position}
168
- style={{
169
- ...style,
170
- '--xy-minimap-background-color-props': typeof bgColor === 'string' ? bgColor : undefined,
171
- '--xy-minimap-mask-background-color-props': typeof maskColor === 'string'
172
- ? maskColor
173
- : undefined,
174
- '--xy-minimap-mask-stroke-color-props': typeof maskStrokeColor === 'string'
175
- ? maskStrokeColor
176
- : undefined,
177
- '--xy-minimap-mask-stroke-width-props': typeof maskStrokeWidth === 'number'
178
- ? maskStrokeWidth * viewScale
179
- : undefined,
180
- '--xy-minimap-node-background-color-props': typeof nodeColor === 'string'
181
- ? nodeColor
182
- : undefined,
183
- '--xy-minimap-node-stroke-color-props': typeof nodeStrokeColor === 'string'
184
- ? nodeStrokeColor
185
- : undefined,
186
- '--xy-minimap-node-stroke-width-props': typeof nodeStrokeWidth === 'number'
187
- ? nodeStrokeWidth
188
- : undefined,
189
- } as CSSProperties}
190
- className={cc(['react-flow__minimap', className])}
191
- data-testid="rf__minimap"
192
- >
193
- <svg
194
- width={elementWidth}
195
- height={elementHeight}
196
- viewBox={`${x} ${y} ${width} ${height}`}
197
- className="react-flow__minimap-svg"
198
- role="img"
199
- aria-labelledby={labelledBy}
200
- ref={svg}
201
- onClick={onSvgClick}
167
+ return (
168
+ <Panel
169
+ position={position}
170
+ style={
171
+ {
172
+ ...style,
173
+ '--xy-minimap-background-color-props': typeof bgColor === 'string' ? bgColor : undefined,
174
+ '--xy-minimap-mask-background-color-props':
175
+ typeof maskColor === 'string' ? maskColor : undefined,
176
+ '--xy-minimap-mask-stroke-color-props':
177
+ typeof maskStrokeColor === 'string' ? maskStrokeColor : undefined,
178
+ '--xy-minimap-mask-stroke-width-props':
179
+ typeof maskStrokeWidth === 'number' ? maskStrokeWidth * viewScale : undefined,
180
+ '--xy-minimap-node-background-color-props':
181
+ typeof nodeColor === 'string' ? nodeColor : undefined,
182
+ '--xy-minimap-node-stroke-color-props':
183
+ typeof nodeStrokeColor === 'string' ? nodeStrokeColor : undefined,
184
+ '--xy-minimap-node-stroke-width-props':
185
+ typeof nodeStrokeWidth === 'number' ? nodeStrokeWidth : undefined,
186
+ } as CSSProperties
187
+ }
188
+ className={cc(['react-flow__minimap', className])}
189
+ data-testid="rf__minimap"
202
190
  >
203
- {_ariaLabel && <title id={labelledBy}>{_ariaLabel}</title>}
204
-
205
- <MiniMapNodes
206
- onClick={onSvgNodeClick}
207
- nodeColor={nodeColor}
208
- nodeStrokeColor={nodeStrokeColor}
209
- nodeBorderRadius={nodeBorderRadius}
210
- nodeClassName={nodeClassName}
211
- nodeStrokeWidth={nodeStrokeWidth}
212
- nodeComponent={nodeComponent}
213
- />
214
- <path
215
- className="react-flow__minimap-mask"
216
- d={`M${x - offset},${y - offset}h${width + offset * 2}v${height + offset * 2}h${
217
- -width - offset * 2
218
- }z
191
+ <svg
192
+ width={elementWidth}
193
+ height={elementHeight}
194
+ viewBox={`${x} ${y} ${width} ${height}`}
195
+ className="react-flow__minimap-svg"
196
+ role="img"
197
+ aria-labelledby={labelledBy}
198
+ ref={svg}
199
+ onClick={onSvgClick}
200
+ >
201
+ {_ariaLabel && <title id={labelledBy}>{_ariaLabel}</title>}
202
+
203
+ <MiniMapNodes
204
+ onClick={onSvgNodeClick}
205
+ nodeColor={nodeColor}
206
+ nodeStrokeColor={nodeStrokeColor}
207
+ nodeBorderRadius={nodeBorderRadius}
208
+ nodeClassName={nodeClassName}
209
+ nodeStrokeWidth={nodeStrokeWidth}
210
+ nodeComponent={nodeComponent}
211
+ />
212
+ <path
213
+ className="react-flow__minimap-mask"
214
+ d={`M${x - offset},${y - offset}h${width + offset * 2}v${height + offset * 2}h${
215
+ -width - offset * 2
216
+ }z
219
217
  M${viewBB.x},${viewBB.y}h${viewBB.width}v${viewBB.height}h${-viewBB.width}z`}
220
- fillRule="evenodd"
221
- pointerEvents="none"
222
- />
223
- </svg>
224
- </Panel>;
218
+ fillRule="evenodd"
219
+ pointerEvents="none"
220
+ />
221
+ </svg>
222
+ </Panel>
223
+ );
225
224
  }
226
225
 
227
226
  MiniMapComponent.displayName = 'MiniMap';
@@ -22,22 +22,24 @@ function MiniMapNodeComponent({
22
22
  const { background, backgroundColor } = style || {};
23
23
  const fill = (color || background || backgroundColor) as string;
24
24
 
25
- return <rect
26
- className={cc(['react-flow__minimap-node', { selected }, className])}
27
- x={x}
28
- y={y}
29
- rx={borderRadius}
30
- ry={borderRadius}
31
- width={width}
32
- height={height}
33
- style={{
34
- fill,
35
- stroke: strokeColor,
36
- strokeWidth,
37
- }}
38
- shapeRendering={shapeRendering}
39
- onClick={onClick ? (event) => onClick(event, id) : undefined}
40
- />;
25
+ return (
26
+ <rect
27
+ className={cc(['react-flow__minimap-node', { selected }, className])}
28
+ x={x}
29
+ y={y}
30
+ rx={borderRadius}
31
+ ry={borderRadius}
32
+ width={width}
33
+ height={height}
34
+ style={{
35
+ fill,
36
+ stroke: strokeColor,
37
+ strokeWidth,
38
+ }}
39
+ shapeRendering={shapeRendering}
40
+ onClick={onClick ? (event) => onClick(event, id) : undefined}
41
+ />
42
+ );
41
43
  }
42
44
 
43
45
  export const MiniMapNode = memo(MiniMapNodeComponent);