generated from arvinxx/npm-template
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
jiangchu
committed
Oct 24, 2023
1 parent
2355543
commit 57a7c84
Showing
10 changed files
with
102 additions
and
35 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,10 @@ | ||
import { useContext } from 'react'; | ||
import { FlowViewContext } from '../provider/provider'; | ||
|
||
export const useFlowView = () => { | ||
const { reactFlowInstance } = useContext(FlowViewContext); | ||
|
||
return { | ||
reactFlowInstance, | ||
}; | ||
}; |
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,27 @@ | ||
import { FC, ReactNode } from 'react'; | ||
import { ReactFlowProvider, useReactFlow } from 'reactflow'; | ||
import { FlowViewContext } from './provider'; | ||
|
||
// 数据处理层 | ||
const ProviderInner: FC<{ children: ReactNode }> = ({ children }) => { | ||
const reactFlowInstance = useReactFlow(); | ||
|
||
return ( | ||
<FlowViewContext.Provider | ||
value={{ | ||
isUseProvider: true, | ||
reactFlowInstance, | ||
}} | ||
> | ||
{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,9 @@ | ||
import { createContext } from 'react'; | ||
import { ReactFlowInstance } from 'reactflow'; | ||
|
||
interface FlowViewContextProps { | ||
isUseProvider?: boolean; | ||
reactFlowInstance?: ReactFlowInstance<any, any>; | ||
} | ||
|
||
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