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" ;
@@ -44,6 +52,7 @@ interface ComponentSpecContextType {
4452 taskStatusMap : Map < string , string > ;
4553 setTaskStatusMap : ( taskStatusMap : Map < string , string > ) => void ;
4654 undoRedo : UndoRedo ;
55+ nodeManager : NodeManager ;
4756}
4857
4958const ComponentSpecContext = createRequiredContext < ComponentSpecContextType > (
@@ -59,6 +68,7 @@ export const ComponentSpecProvider = ({
5968 readOnly ?: boolean ;
6069 children : ReactNode ;
6170} ) => {
71+ const [ nodeManager ] = useState ( ( ) => new NodeManager ( ) ) ;
6272 const [ componentSpec , setComponentSpec ] = useState < ComponentSpec > (
6373 spec ?? EMPTY_GRAPH_COMPONENT_SPEC ,
6474 ) ;
@@ -152,6 +162,10 @@ export const ComponentSpecProvider = ({
152162 } ) ) ;
153163 } , [ ] ) ;
154164
165+ useEffect ( ( ) => {
166+ nodeManager . syncWithComponentSpec ( componentSpec ) ;
167+ } , [ componentSpec , nodeManager ] ) ;
168+
155169 const value = useMemo (
156170 ( ) => ( {
157171 componentSpec,
@@ -167,6 +181,7 @@ export const ComponentSpecProvider = ({
167181 updateGraphSpec,
168182 setTaskStatusMap,
169183 undoRedo,
184+ nodeManager,
170185 } ) ,
171186 [
172187 componentSpec ,
@@ -182,6 +197,7 @@ export const ComponentSpecProvider = ({
182197 updateGraphSpec ,
183198 setTaskStatusMap ,
184199 undoRedo ,
200+ nodeManager ,
185201 ] ,
186202 ) ;
187203
0 commit comments