@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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octanejs/xyflow",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.20",
|
|
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.
|
|
46
|
+
"@octanejs/zustand": "0.1.64",
|
|
47
47
|
"@xyflow/system": "0.0.79",
|
|
48
48
|
"classcat": "5.0.5"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"octane": "^0.
|
|
51
|
+
"octane": "^0.12.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@octanejs/zustand": "0.1.
|
|
55
|
-
"@tsrx/react": "^0.
|
|
54
|
+
"@octanejs/zustand": "0.1.64",
|
|
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.
|
|
61
|
+
"octane": "0.12.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
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
|
30
|
-
type="button"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
-
|
|
86
|
-
|
|
87
|
-
title={ariaLabelConfig['controls.
|
|
88
|
-
aria-label={ariaLabelConfig['controls.
|
|
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
|
-
<
|
|
111
|
+
<FitViewIcon />
|
|
92
112
|
</ControlButton>
|
|
113
|
+
)}
|
|
114
|
+
{showInteractive && (
|
|
93
115
|
<ControlButton
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
title={ariaLabelConfig['controls.
|
|
97
|
-
aria-label={ariaLabelConfig['controls.
|
|
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
|
-
<
|
|
121
|
+
{isInteractive ? <UnlockIcon /> : <LockIcon />}
|
|
101
122
|
</ControlButton>
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
|
3
|
-
<
|
|
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
|
-
|
|
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
|
|
3
|
-
<
|
|
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
|
-
|
|
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 PlusIcon() {
|
|
2
|
-
return
|
|
3
|
-
<
|
|
4
|
-
|
|
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
|
|
3
|
-
<
|
|
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
|
-
|
|
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
|
|
65
|
-
<
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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:
|
|
37
|
-
|
|
38
|
-
|
|
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) &&
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
74
|
-
|
|
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
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
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
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
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
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
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
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
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
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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);
|