generated from arvinxx/npm-template
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat: 新增FlowViewProvider,新增miniMapHook (#20)
* 🐛 fix: readme * ✨ feat: 新增FlowViewProvider * ✨ feat: 新增minimap的控制钩子 * ✨ feat: 删除console --------- Co-authored-by: jiangchu <[email protected]>
- Loading branch information
Showing
11 changed files
with
158 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { ProFlowProps } from '@/constants'; | ||
import { FC, useContext } from 'react'; | ||
import FlowView from '.'; | ||
import { FlowViewProvider } from './provider/FlowViewProvider'; | ||
import { FlowViewContext } from './provider/provider'; | ||
|
||
const ProFlow: FC<ProFlowProps> = (props) => { | ||
const { isUseProvider } = useContext(FlowViewContext); | ||
|
||
if (isUseProvider) { | ||
return <FlowView {...props} />; | ||
} | ||
|
||
return ( | ||
<FlowViewProvider> | ||
<FlowView {...props} /> | ||
</FlowViewProvider> | ||
); | ||
}; | ||
|
||
export default ProFlow; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { useContext } from 'react'; | ||
import { FlowViewContext } from '../provider/provider'; | ||
|
||
export const useFlowView = () => { | ||
const { reactFlowInstance } = useContext(FlowViewContext); | ||
|
||
return { | ||
reactFlowInstance, | ||
}; | ||
}; | ||
|
||
export const useMiniMap = () => { | ||
const { setMiniMapPosition: setPosition } = useContext(FlowViewContext); | ||
|
||
const setMiniMapPosition = (x: number, y: number) => { | ||
setPosition!([x, y]); | ||
}; | ||
|
||
return { | ||
setMiniMapPosition, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { FC, ReactNode, useState } from 'react'; | ||
import { ReactFlowProvider, useReactFlow } from 'reactflow'; | ||
import { FlowViewContext } from './provider'; | ||
|
||
// 数据处理层 | ||
const ProviderInner: FC<{ children: ReactNode }> = ({ children }) => { | ||
const [miniMapPosition, setMiniMapPosition] = useState<[number, number]>([0, 0]); | ||
const reactFlowInstance = useReactFlow(); | ||
|
||
return ( | ||
<FlowViewContext.Provider | ||
value={{ | ||
isUseProvider: true, | ||
reactFlowInstance, | ||
miniMapPosition, | ||
setMiniMapPosition, | ||
}} | ||
> | ||
{children} | ||
</FlowViewContext.Provider> | ||
); | ||
}; | ||
|
||
export const FlowViewProvider: FC<{ children: ReactNode }> = ({ children }) => { | ||
return ( | ||
<ReactFlowProvider> | ||
<ProviderInner>{children}</ProviderInner> | ||
</ReactFlowProvider> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { createContext } from 'react'; | ||
import { ReactFlowInstance } from 'reactflow'; | ||
|
||
interface FlowViewContextProps { | ||
isUseProvider?: boolean; | ||
reactFlowInstance?: ReactFlowInstance<any, any>; | ||
miniMapPosition?: [number, number]; | ||
setMiniMapPosition?: React.Dispatch<React.SetStateAction<[number, number]>>; | ||
} | ||
|
||
export const FlowViewContext = createContext<FlowViewContextProps>({}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters