@@ -4,19 +4,21 @@ import {
44 BaseNodeInfo ,
55 IThumbNodeComponent ,
66 GetNodeTaskFactory ,
7+ ElementNodeMap ,
78} from '@devhelpr/visual-programming-system' ;
89import { Exporter } from './Exporter' ;
910
1011import { BaseExporter } from './BaseExporter' ;
1112import { OCWGFile , OCWGNode } from './ocwg/ocwg-schema' ;
1213import { ocwgEmptyFile } from './ocwg/ocwg-empty-file' ;
1314import { NodeInfo } from '@devhelpr/web-flow-executor' ;
15+ import { getCurrentOCIF } from '../importers/ocif-importer' ;
1416
1517interface OCWGInfo {
1618 index : number ;
1719}
18- const nodeInfoPropertyName = '@code-flow-canvas/node-properties' ;
19- const connectionNodeInfoPropertyName =
20+ export const nodeInfoPropertyName = '@code-flow-canvas/node-properties' ;
21+ export const connectionNodeInfoPropertyName =
2022 '@code-flow-canvas/connection-properties' ;
2123
2224export class OCWGExporter extends BaseExporter < OCWGFile , OCWGInfo > {
@@ -31,6 +33,67 @@ export class OCWGExporter extends BaseExporter<OCWGFile, OCWGInfo> {
3133 return structuredClone ( ocwgEmptyFile ) ;
3234 }
3335
36+ isValidCodeFlowCanvasNode ( node : any ) : boolean {
37+ if ( node . data && Array . isArray ( node . data ) ) {
38+ return node . data . some (
39+ ( d : any ) =>
40+ d . type === nodeInfoPropertyName ||
41+ d . type === connectionNodeInfoPropertyName
42+ ) ;
43+ }
44+ return false ;
45+ }
46+
47+ doesRootOCIFNodeExistInFlow (
48+ id : string ,
49+ elements : ElementNodeMap < BaseNodeInfo >
50+ ) : boolean {
51+ return elements . has ( `${ id } ` ) ;
52+ }
53+
54+ override mergeWithAdditionalIbfo (
55+ elements : ElementNodeMap < BaseNodeInfo >
56+ ) : void {
57+ const rootOCIF = getCurrentOCIF ( ) ;
58+ if ( ! this . file || ! rootOCIF ) {
59+ return ;
60+ }
61+ if ( rootOCIF . resources ) {
62+ this . file . resources = rootOCIF . resources ;
63+ }
64+ if ( rootOCIF . nodes ) {
65+ rootOCIF . nodes . forEach ( ( node : any ) => {
66+ if (
67+ ! this . isValidCodeFlowCanvasNode ( node ) &&
68+ ! this . doesRootOCIFNodeExistInFlow ( node . id , elements )
69+ ) {
70+ this . file ?. nodes . push ( node ) ;
71+ }
72+ } ) ;
73+ }
74+ if ( rootOCIF . relations ) {
75+ rootOCIF . relations . forEach ( ( relation : any ) => {
76+ if ( ! this . file ?. relations . find ( ( r ) => r . id === relation . id ) ) {
77+ this . file ?. relations . push ( relation ) ;
78+ }
79+ } ) ;
80+ }
81+ if ( rootOCIF . schemas ) {
82+ rootOCIF . schemas . forEach ( ( schema : any ) => {
83+ if ( ! this . file ?. schemas . find ( ( s ) => s . uri === schema . uri ) ) {
84+ this . file ?. schemas . push ( schema ) ;
85+ }
86+ } ) ;
87+ }
88+ if ( rootOCIF . resources ) {
89+ rootOCIF . resources . forEach ( ( resource : any ) => {
90+ if ( ! this . file ?. resources . find ( ( r ) => r . uri === resource . uri ) ) {
91+ this . file ?. resources . push ( resource ) ;
92+ }
93+ } ) ;
94+ }
95+ }
96+
3497 override createExportInfoContext ( ) : OCWGInfo {
3598 return {
3699 index : 1 ,
@@ -70,7 +133,7 @@ export class OCWGExporter extends BaseExporter<OCWGFile, OCWGInfo> {
70133 } ) ;
71134 }
72135 const ocwgNode : OCWGNode = {
73- id : `shape: ${ node . id } ` ,
136+ id : `${ node . id } ` ,
74137 position : [ node . x , node . y ] ,
75138 size : [ node . width ?? 0 , node . height ?? 0 ] ,
76139 data : [
@@ -116,7 +179,7 @@ export class OCWGExporter extends BaseExporter<OCWGFile, OCWGInfo> {
116179 return ;
117180 }
118181 const ocwgNode : OCWGNode = {
119- id : `shape :${ node . id } ` ,
182+ id : `connection :${ node . id } ` ,
120183 position : [ node . x , node . y ] ,
121184 size : [ node . width ?? 0 , node . height ?? 0 ] ,
122185 data : [
@@ -125,11 +188,11 @@ export class OCWGExporter extends BaseExporter<OCWGFile, OCWGInfo> {
125188 type : connectionNodeInfoPropertyName ,
126189 nodeType : nodeInfo . type ,
127190 start : {
128- connected_to : `shape: ${ node . startNode . id } ` ,
191+ connected_to : `${ node . startNode . id } ` ,
129192 port_name : 'output' ,
130193 } ,
131194 end : {
132- connected_to : `shape: ${ node . endNode . id } ` ,
195+ connected_to : `${ node . endNode . id } ` ,
133196 port_name : 'input' ,
134197 } ,
135198 } ,
@@ -143,8 +206,8 @@ export class OCWGExporter extends BaseExporter<OCWGFile, OCWGInfo> {
143206 const relation = {
144207 type : '@ocwg/rel/edge' as const ,
145208 id : `${ node . id } -edge` ,
146- from : `shape: ${ node . startNode . id } ` ,
147- to : `shape: ${ node . endNode . id } ` ,
209+ from : `${ node . startNode . id } ` ,
210+ to : `${ node . endNode . id } ` ,
148211 directed : true ,
149212 } ;
150213 this . file . relations . push ( relation ) ;
@@ -170,11 +233,11 @@ export class OCWGExporter extends BaseExporter<OCWGFile, OCWGInfo> {
170233 type : connectionNodeInfoPropertyName ,
171234 nodeType : nodeInfo . type ,
172235 start : {
173- connected_to : `shape: ${ node . startNode . id } ` ,
236+ connected_to : `${ node . startNode . id } ` ,
174237 port_name : node . startNodeThumb ?. thumbName ,
175238 } ,
176239 end : {
177- connected_to : `shape: ${ node . endNode . id } ` ,
240+ connected_to : `${ node . endNode . id } ` ,
178241 port_name : node . endNodeThumb ?. thumbName ,
179242 } ,
180243 } ,
@@ -189,8 +252,8 @@ export class OCWGExporter extends BaseExporter<OCWGFile, OCWGInfo> {
189252 id : `${ node . id } -edge` ,
190253 type : '@ocwg/rel/edge' as const ,
191254 directed : true ,
192- from : `shape: ${ node . startNode . id } ` ,
193- to : `shape: ${ node . endNode . id } ` ,
255+ from : `${ node . startNode . id } ` ,
256+ to : `${ node . endNode . id } ` ,
194257 } ;
195258 this . file . relations . push ( relation ) ;
196259 }
0 commit comments