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" ;
@@ -50,6 +58,8 @@ interface ComponentSpecContextType {
5058 navigateBack : ( ) => void ;
5159 navigateToPath : ( targetPath : string [ ] ) => void ;
5260 canNavigateBack : boolean ;
61+
62+ nodeManager : NodeManager ;
5363}
5464
5565const ComponentSpecContext = createRequiredContext < ComponentSpecContextType > (
@@ -65,6 +75,7 @@ export const ComponentSpecProvider = ({
6575 readOnly ?: boolean ;
6676 children : ReactNode ;
6777} ) => {
78+ const [ nodeManager ] = useState ( ( ) => new NodeManager ( ) ) ;
6879 const [ componentSpec , setComponentSpec ] = useState < ComponentSpec > (
6980 spec ?? EMPTY_GRAPH_COMPONENT_SPEC ,
7081 ) ;
@@ -177,6 +188,10 @@ export const ComponentSpecProvider = ({
177188
178189 const canNavigateBack = currentSubgraphPath . length > 1 ;
179190
191+ useEffect ( ( ) => {
192+ nodeManager . syncWithComponentSpec ( componentSpec ) ;
193+ } , [ componentSpec , nodeManager ] ) ;
194+
180195 const value = useMemo (
181196 ( ) => ( {
182197 componentSpec,
@@ -198,6 +213,8 @@ export const ComponentSpecProvider = ({
198213 navigateBack,
199214 navigateToPath,
200215 canNavigateBack,
216+
217+ nodeManager,
201218 } ) ,
202219 [
203220 componentSpec ,
@@ -219,6 +236,8 @@ export const ComponentSpecProvider = ({
219236 navigateBack ,
220237 navigateToPath ,
221238 canNavigateBack ,
239+
240+ nodeManager ,
222241 ] ,
223242 ) ;
224243
0 commit comments