11import React , { memo , useEffect } from "react" ;
2- import { MiniMap as ReactFlowMiniMap , MiniMapProps as ReactFlowMiniMapProps , OnLoadParams } from "react-flow-renderer" ;
2+ import {
3+ MiniMap as ReactFlowMiniMapV9 ,
4+ MiniMapProps as ReactFlowMiniMapV9Props ,
5+ OnLoadParams
6+ } from "react-flow-renderer" ;
37import { FlowTransform } from "react-flow-renderer/dist/types" ;
48
5- import { miniMapUtils } from "../minimap/utils" ;
9+ import { miniMapUtils } from "./utils" ;
10+ import { ReacFlowVersionSupportProps , ReactFlowVersions , useReactFlowVersion } from "../versionsupport" ;
11+ import { MiniMapV12 , MiniMapV12Props } from "./MiniMapV12" ;
612
7- export interface MiniMapProps extends ReactFlowMiniMapProps {
8- /**
9- * React-Flow instance
10- */
11- flowInstance ?: OnLoadParams ;
13+ export interface MiniMapBasicProps {
1214 /**
1315 * Enable navigating the react-flow canvas by dragging and clicking on the mini-map.
1416 */
@@ -23,6 +25,15 @@ export interface MiniMapProps extends ReactFlowMiniMapProps {
2325 > ;
2426}
2527
28+ export interface MiniMapV9Props extends MiniMapBasicProps , ReactFlowMiniMapV9Props {
29+ /**
30+ * React-Flow instance
31+ */
32+ flowInstance ?: OnLoadParams ;
33+ }
34+
35+ export type MiniMapProps = ( ReacFlowVersionSupportProps & MiniMapV9Props ) | ( ReacFlowVersionSupportProps & MiniMapV12Props ) ;
36+
2637interface configParams {
2738 // Key has been pressed down over the mini-map and navigation mode has thus started
2839 navigationOn : boolean ;
@@ -40,6 +51,28 @@ let minimapCalcConf: configParams = {
4051
4152/** An improved mini-map for react-flow that supports navigation via the mini-map. */
4253export const MiniMap = memo (
54+ ( {
55+ flowVersion,
56+ ...otherProps
57+ } : MiniMapProps ) => {
58+ const flowVersionCheck = flowVersion || useReactFlowVersion ( ) ;
59+
60+ switch ( flowVersionCheck ) {
61+ case ReactFlowVersions . V9 :
62+ return < MiniMapV9 { ...otherProps as MiniMapV9Props } /> ;
63+ case ReactFlowVersions . V12 :
64+ return < MiniMapV12 { ...otherProps as MiniMapV12Props } /> ;
65+ default :
66+ return < > </ > ; // cannot exit on its own
67+ }
68+ }
69+ ) ;
70+
71+ /**
72+ * Mini-map support for for React Flow v9.
73+ * @deprecated (v26) will be removed, use when `MiniMap` directly
74+ */
75+ export const MiniMapV9 = memo (
4376 ( {
4477 flowInstance,
4578 enableNavigation = false ,
@@ -49,7 +82,7 @@ export const MiniMap = memo(
4982 nodeStrokeColor = miniMapUtils . borderColor ,
5083 wrapperProps,
5184 ...minimapProps
52- } : MiniMapProps ) => {
85+ } : MiniMapV9Props ) => {
5386 const minimapWrapper = React . useRef < HTMLDivElement | null > ( null ) ;
5487
5588 useEffect ( ( ) => {
@@ -130,7 +163,7 @@ export const MiniMap = memo(
130163 : wrapperProps ?. style
131164 }
132165 >
133- < ReactFlowMiniMap
166+ < ReactFlowMiniMapV9
134167 maskColor = { maskColor }
135168 nodeClassName = { nodeClassName }
136169 nodeColor = { nodeColor }
@@ -141,3 +174,5 @@ export const MiniMap = memo(
141174 ) ;
142175 }
143176) ;
177+
178+ export default MiniMap ;
0 commit comments