1- import { type ReactNode , useCallback , useMemo , useRef , useState } from "react" ;
1+ import {
2+ type ReactNode ,
3+ useCallback ,
4+ useEffect ,
5+ useMemo ,
6+ useRef ,
7+ useState ,
8+ } from "react" ;
29
310import { type UndoRedo , useUndoRedo } from "@/hooks/useUndoRedo" ;
11+ import { NodeManager } from "@/nodeManager" ;
412import { loadPipelineByName } from "@/services/pipelineService" ;
513import { USER_PIPELINES_LIST_NAME } from "@/utils/constants" ;
614import { prepareComponentRefForEditor } from "@/utils/prepareComponentRefForEditor" ;
@@ -56,6 +64,8 @@ interface ComponentSpecContextType {
5664 navigateBack : ( ) => void ;
5765 navigateToPath : ( targetPath : string [ ] ) => void ;
5866 canNavigateBack : boolean ;
67+
68+ nodeManager : NodeManager ;
5969}
6070
6171const ComponentSpecContext = createRequiredContext < ComponentSpecContextType > (
@@ -71,6 +81,7 @@ export const ComponentSpecProvider = ({
7181 readOnly ?: boolean ;
7282 children : ReactNode ;
7383} ) => {
84+ const [ nodeManager ] = useState ( ( ) => new NodeManager ( ) ) ;
7485 const [ componentSpec , setComponentSpec ] = useState < ComponentSpec > (
7586 spec ?? EMPTY_GRAPH_COMPONENT_SPEC ,
7687 ) ;
@@ -214,6 +225,10 @@ export const ComponentSpecProvider = ({
214225
215226 const canNavigateBack = currentSubgraphPath . length > 1 ;
216227
228+ useEffect ( ( ) => {
229+ nodeManager . syncWithComponentSpec ( componentSpec ) ;
230+ } , [ componentSpec , nodeManager ] ) ;
231+
217232 const value = useMemo (
218233 ( ) => ( {
219234 componentSpec,
@@ -237,6 +252,8 @@ export const ComponentSpecProvider = ({
237252 navigateBack,
238253 navigateToPath,
239254 canNavigateBack,
255+
256+ nodeManager,
240257 } ) ,
241258 [
242259 componentSpec ,
@@ -260,6 +277,8 @@ export const ComponentSpecProvider = ({
260277 navigateBack ,
261278 navigateToPath ,
262279 canNavigateBack ,
280+
281+ nodeManager ,
263282 ] ,
264283 ) ;
265284
0 commit comments