Skip to content

Commit bb99555

Browse files
committed
export ports to ocwg/ocif
1 parent af173f4 commit bb99555

File tree

6 files changed

+77
-23
lines changed

6 files changed

+77
-23
lines changed

apps/vps-web/src/app/pages/ocwg.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,16 @@ export function ocwgPage() {
169169
}
170170
});
171171

172-
app.onStoreFlow = (_flow, canvasApp, _getNodeTaskFactory) => {
173-
const ocwg = new module.OCWGExporter({
174-
canvasApp: canvasApp,
175-
downloadFile: (_data: any, _name: string, _dataType: string) => {
176-
//
172+
app.onStoreFlow = (_flow, canvasApp, getNodeTaskFactory) => {
173+
const ocwg = new module.OCWGExporter(
174+
{
175+
canvasApp: canvasApp,
176+
downloadFile: (_data: any, _name: string, _dataType: string) => {
177+
//
178+
},
177179
},
178-
});
180+
getNodeTaskFactory
181+
);
179182
const file = ocwg.convertToExportFile();
180183
currentOcwgExport = JSON.stringify(file, null, 2);
181184
ocwgExport.innerHTML = '';

libs/app-canvas/src/app/exporters/BaseExporter.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,17 @@ import {
77
cleanupNodeInfoForSerializing,
88
BaseNodeInfo,
99
IThumbNodeComponent,
10+
GetNodeTaskFactory,
1011
} from '@devhelpr/visual-programming-system';
1112
import { Exporter } from './Exporter';
1213
import { ExportFile } from './export-interface/core-export';
14+
import { NodeInfo } from '@devhelpr/web-flow-executor';
1315

1416
export abstract class BaseExporter<T extends ExportFile, X> {
15-
constructor(readonly exportInfo: Exporter) {
17+
constructor(
18+
readonly exportInfo: Exporter,
19+
readonly getNodeTaskFactory: GetNodeTaskFactory<NodeInfo>
20+
) {
1621
//
1722
}
1823
file?: T;

libs/app-canvas/src/app/exporters/export-ocwg.ts

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,26 @@ import {
33
INodeComponent,
44
BaseNodeInfo,
55
IThumbNodeComponent,
6+
GetNodeTaskFactory,
67
} from '@devhelpr/visual-programming-system';
78
import { Exporter } from './Exporter';
89

910
import { BaseExporter } from './BaseExporter';
1011
import { OCWGFile, OCWGNode } from './ocwg/ocwg-schema';
1112
import { ocwgEmptyFile } from './ocwg/ocwg-empty-file';
13+
import { NodeInfo } from '@devhelpr/web-flow-executor';
1214

1315
interface OCWGInfo {
1416
index: number;
1517
}
1618
const nodeInfoPropertyName = '@code-flow-canvas/node-properties';
1719

1820
export class OCWGExporter extends BaseExporter<OCWGFile, OCWGInfo> {
19-
constructor(exportInfo: Exporter) {
20-
super(exportInfo);
21+
constructor(
22+
exportInfo: Exporter,
23+
getNodeTaskFactory: GetNodeTaskFactory<NodeInfo>
24+
) {
25+
super(exportInfo, getNodeTaskFactory);
2126
}
2227

2328
override createExportFile(): OCWGFile {
@@ -39,6 +44,29 @@ export class OCWGExporter extends BaseExporter<OCWGFile, OCWGInfo> {
3944
_isRectThumb: boolean,
4045
parentId?: string
4146
): string {
47+
const ports: string[] = [];
48+
if (nodeInfo.type) {
49+
const factory = this.getNodeTaskFactory(nodeInfo.type);
50+
if (factory) {
51+
const nodeTask = factory(() => {
52+
//
53+
});
54+
if (nodeTask) {
55+
nodeTask.thumbs?.forEach((thumb) => {
56+
if (thumb.name) {
57+
ports.push(thumb.name);
58+
}
59+
});
60+
}
61+
}
62+
}
63+
const portsNode: any[] = [];
64+
if (ports.length > 0) {
65+
portsNode.push({
66+
type: '@ocwg/node/ports',
67+
ports: ports,
68+
});
69+
}
4270
const ocwgNode: OCWGNode = {
4371
id: `shape:${node.id}`,
4472
position: [node.x, node.y],
@@ -49,6 +77,7 @@ export class OCWGExporter extends BaseExporter<OCWGFile, OCWGInfo> {
4977
type: nodeInfoPropertyName,
5078
nodeType: nodeInfo.type,
5179
},
80+
...portsNode,
5281
],
5382
};
5483
if (this.file?.nodes) {
@@ -168,8 +197,11 @@ export class OCWGExporter extends BaseExporter<OCWGFile, OCWGInfo> {
168197
}
169198
}
170199

171-
export const exportOCWG = (exportInfo: Exporter) => {
172-
const tldrawExporter = new OCWGExporter(exportInfo);
200+
export const exportOCWG = (
201+
exportInfo: Exporter,
202+
getNodeTaskFactory: GetNodeTaskFactory<NodeInfo>
203+
) => {
204+
const tldrawExporter = new OCWGExporter(exportInfo, getNodeTaskFactory);
173205
const file = tldrawExporter.convertToExportFile();
174206
exportInfo.downloadFile(
175207
JSON.stringify(file),

libs/app-canvas/src/app/exporters/export-tldraw.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
cleanupNodeInfoForSerializing,
55
BaseNodeInfo,
66
IThumbNodeComponent,
7+
GetNodeTaskFactory,
78
} from '@devhelpr/visual-programming-system';
89
import { Exporter } from './Exporter';
910
import {
@@ -16,14 +17,18 @@ import {
1617
} from './tldraw/tldraw-emtpy-file';
1718
import { TlDrawFile } from './tldraw/tldraw-schema';
1819
import { BaseExporter } from './BaseExporter';
20+
import { NodeInfo } from '@devhelpr/web-flow-executor';
1921

2022
interface TLDrawInfo {
2123
index: number;
2224
}
2325

2426
export class TLDrawExporter extends BaseExporter<TlDrawFile, TLDrawInfo> {
25-
constructor(exportInfo: Exporter) {
26-
super(exportInfo);
27+
constructor(
28+
exportInfo: Exporter,
29+
getNodeTaskFactory: GetNodeTaskFactory<NodeInfo>
30+
) {
31+
super(exportInfo, getNodeTaskFactory);
2732
}
2833

2934
override createExportFile(): TlDrawFile {
@@ -194,8 +199,11 @@ export class TLDrawExporter extends BaseExporter<TlDrawFile, TLDrawInfo> {
194199
}
195200
}
196201

197-
export const exportTldraw = (exportInfo: Exporter) => {
198-
const tldrawExporter = new TLDrawExporter(exportInfo);
202+
export const exportTldraw = (
203+
exportInfo: Exporter,
204+
getNodeTaskFactory: GetNodeTaskFactory<NodeInfo>
205+
) => {
206+
const tldrawExporter = new TLDrawExporter(exportInfo, getNodeTaskFactory);
199207
const file = tldrawExporter.convertToExportFile();
200208
exportInfo.downloadFile(
201209
JSON.stringify(file),

libs/app-canvas/src/app/flow-app.element.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -835,10 +835,13 @@ export class FlowAppElement extends AppElement<NodeInfo> {
835835
if (!this.canvasApp) {
836836
return;
837837
}
838-
exportTldraw({
839-
canvasApp: this.canvasApp,
840-
downloadFile,
841-
});
838+
exportTldraw(
839+
{
840+
canvasApp: this.canvasApp,
841+
downloadFile,
842+
},
843+
getNodeTaskFactory
844+
);
842845
}}
843846
getElement={(element: HTMLElement) => {
844847
this.exportCodeButton = element;

libs/app-canvas/src/app/gl-app.element.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -629,10 +629,13 @@ export class GLAppElement extends AppElement<GLNodeInfo> {
629629
if (!this.canvasApp) {
630630
return;
631631
}
632-
exportTldraw({
633-
canvasApp: this.canvasApp,
634-
downloadFile,
635-
});
632+
exportTldraw(
633+
{
634+
canvasApp: this.canvasApp,
635+
downloadFile,
636+
},
637+
getGLNodeTaskFactory
638+
);
636639
}}
637640
getElement={(element: HTMLElement) => {
638641
this.exportExternalButton = element;

0 commit comments

Comments
 (0)