1- import React , { useCallback } from ' react' ;
1+ import React , { useCallback } from " react" ;
22import {
33 ReactFlow ,
4- Background ,
4+ // Background,
55 useNodesState ,
66 useEdgesState ,
77 addEdge ,
88 getIncomers ,
99 getOutgoers ,
1010 getConnectedEdges ,
11- } from ' @xyflow/react' ;
11+ } from " @xyflow/react" ;
1212
1313// style
1414import "@xyflow/react/dist/style.css" ;
@@ -69,40 +69,44 @@ const MindMapComponent = ({ setScripts }: MindMapComponentProps) => {
6969
7070 const initialNodes = [
7171 {
72- id : '1' ,
73- type : ' input' ,
74- data : { label : ' Start here...' } ,
72+ id : "1" ,
73+ type : " input" ,
74+ data : { label : " Start here..." } ,
7575 position : { x : - 150 , y : 0 } ,
7676 } ,
7777 {
78- id : '2' ,
79- type : ' input' ,
80- data : { label : ' ...or here!' } ,
78+ id : "2" ,
79+ type : " input" ,
80+ data : { label : " ...or here!" } ,
8181 position : { x : 150 , y : 0 } ,
8282 } ,
83- { id : '3' , data : { label : ' Delete me.' } , position : { x : 0 , y : 100 } } ,
84- { id : '4' , data : { label : ' Then me!' } , position : { x : 0 , y : 200 } } ,
83+ { id : "3" , data : { label : " Delete me." } , position : { x : 0 , y : 100 } } ,
84+ { id : "4" , data : { label : " Then me!" } , position : { x : 0 , y : 200 } } ,
8585 {
86- id : '5' ,
87- type : ' output' ,
88- data : { label : ' End here!' } ,
86+ id : "5" ,
87+ type : " output" ,
88+ data : { label : " End here!" } ,
8989 position : { x : 0 , y : 300 } ,
9090 } ,
9191 ] ;
9292
9393 const initialEdges = [
94- { id : ' 1->3' , source : '1' , target : '3' } ,
95- { id : ' 2->3' , source : '2' , target : '3' } ,
96- { id : ' 3->4' , source : '3' , target : '4' } ,
97- { id : ' 4->5' , source : '4' , target : '5' } ,
94+ { id : " 1->3" , source : "1" , target : "3" } ,
95+ { id : " 2->3" , source : "2" , target : "3" } ,
96+ { id : " 3->4" , source : "3" , target : "4" } ,
97+ { id : " 4->5" , source : "4" , target : "5" } ,
9898 ] ;
9999
100100 const [ nodes , setNodes , onNodesChange ] = useNodesState ( initialNodes ) ;
101101 const [ edges , setEdges , onEdgesChange ] = useEdgesState ( initialEdges ) ;
102102
103+ useEffect ( ( ) => {
104+ setNodes ( initialNodes ) ;
105+ } , [ ] ) ; // 임시방편으로 만듦
106+
103107 const onConnect = useCallback (
104108 ( params : any ) => setEdges ( addEdge ( params , edges ) ) ,
105- [ edges ] ,
109+ [ edges ]
106110 ) ;
107111
108112 const onNodesDelete = useCallback (
@@ -112,24 +116,25 @@ const MindMapComponent = ({ setScripts }: MindMapComponentProps) => {
112116 const incomers = getIncomers ( node , nodes , edges ) ;
113117 const outgoers = getOutgoers ( node , nodes , edges ) ;
114118 const connectedEdges = getConnectedEdges ( [ node ] , edges ) ;
115-
119+
116120 const remainingEdges = acc . filter (
117- ( edge : { id : string ; source : string ; target : string ; } ) => ! connectedEdges . includes ( edge ) ,
121+ ( edge : { id : string ; source : string ; target : string } ) =>
122+ ! connectedEdges . includes ( edge )
118123 ) ;
119-
124+
120125 const createdEdges = incomers . flatMap ( ( { id : source } ) =>
121126 outgoers . map ( ( { id : target } ) => ( {
122127 id : `${ source } ->${ target } ` ,
123128 source,
124129 target,
125- } ) ) ,
130+ } ) )
126131 ) ;
127-
132+
128133 return [ ...remainingEdges , ...createdEdges ] ;
129- } , edges ) ,
134+ } , edges )
130135 ) ;
131136 } ,
132- [ nodes , edges ] ,
137+ [ nodes , edges ]
133138 ) ;
134139
135140 return (
@@ -160,8 +165,7 @@ const MindMapComponent = ({ setScripts }: MindMapComponentProps) => {
160165 onConnect = { onConnect }
161166 fitView
162167 attributionPosition = "top-right"
163- >
164- </ ReactFlow >
168+ > </ ReactFlow >
165169 </ div >
166170 < div className = "middle-bar" >
167171 < div className = "record-length-wrap" >
0 commit comments