@@ -71,6 +71,23 @@ function getConnectionInfoFromOCIFNode(node: any): any | false {
7171 return false ;
7272}
7373
74+ export const getResourceById = ( ocif : any , resourceId : string ) => {
75+ if ( ! ocif . resources || ! resourceId ) {
76+ return undefined ;
77+ }
78+ return ocif . resources . find ( ( r : any ) => r . id === resourceId ) ;
79+ } ;
80+
81+ export const getTextRepresentation = ( resource : any ) : string | false => {
82+ if ( ! resource || ! resource . representations ) {
83+ return false ;
84+ }
85+ return (
86+ resource . representations . find ( ( r : any ) => r [ 'mime-type' ] === 'text/plain' )
87+ ?. content ?? false
88+ ) ;
89+ } ;
90+
7491export const importOCIF = ( ocif : any ) => {
7592 rootOCIF = ocif ;
7693 const flow : Flow < NodeInfo > = {
@@ -112,6 +129,14 @@ export const importOCIF = (ocif: any) => {
112129 }
113130 } else if ( node . data && isSupportedOCIFNode ( node ) ) {
114131 const data = getExtenstionData ( node , 'rect-node' ) ;
132+ let text = '' ;
133+ const resource = getResourceById ( ocif , node . resource ) ;
134+ if ( resource ) {
135+ const textRepresentation = getTextRepresentation ( resource ) ;
136+ if ( textRepresentation ) {
137+ text = textRepresentation ;
138+ }
139+ }
115140 flow . flows [ 'flow' ] . nodes . push ( {
116141 id : node . id ,
117142 x : node . position [ 0 ] ,
@@ -124,10 +149,19 @@ export const importOCIF = (ocif: any) => {
124149 strokeColor : data ?. strokeColor ?? 'black' ,
125150 fillColor : data ?. fillColor ?? 'white' ,
126151 strokeWidth : data ?. strokeWidth ?? 2 ,
152+ text : text ,
127153 } as any ,
128154 } ) ;
129155 console . log ( 'ocif node size' , node . size ) ;
130156 } else if ( ! node . data ) {
157+ let text = '' ;
158+ const resource = getResourceById ( ocif , node . resource ) ;
159+ if ( resource ) {
160+ const textRepresentation = getTextRepresentation ( resource ) ;
161+ if ( textRepresentation ) {
162+ text = textRepresentation ;
163+ }
164+ }
131165 flow . flows [ 'flow' ] . nodes . push ( {
132166 id : node . id ,
133167 x : node . position [ 0 ] ,
@@ -140,6 +174,7 @@ export const importOCIF = (ocif: any) => {
140174 strokeColor : 'black' ,
141175 fillColor : 'white' ,
142176 strokeWidth : 2 ,
177+ text : text ,
143178 } as any ,
144179 } ) ;
145180 }
0 commit comments