Skip to content

Commit 3f89bac

Browse files
committed
improve storing some default properties and retaining original ocif flow after refresing
1 parent 287e907 commit 3f89bac

File tree

6 files changed

+63
-15
lines changed

6 files changed

+63
-15
lines changed

apps/vps-web/src/app/custom-nodes/classes/rect-node-class.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ w-min h-min
5959
}`}
6060
spellcheck="false"
6161
blur={() => {
62+
if (this.rectElement) {
63+
if (this.rectElement.innerHTML.toString().length == 0) {
64+
// hacky solution to prevent caret being aligned to top
65+
this.rectElement.innerHTML = ' ';
66+
}
67+
}
6268
console.log('blur', this.rectElement?.textContent);
6369
if (this.node?.nodeInfo) {
6470
(this.node.nodeInfo as any).text = this.rectElement?.textContent;
@@ -71,7 +77,7 @@ w-min h-min
7177
this.rectElement.contentEditable = 'false';
7278
}
7379
}}
74-
pointerup={(e: PointerEvent) => {
80+
pointerup={() => {
7581
if (this.rectElement) {
7682
this.rectElement.contentEditable = 'true';
7783
}

apps/vps-web/src/app/custom-nodes/rect-node.tsx

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,24 +75,37 @@ export const getRectNode =
7575
return [];
7676
},
7777
(nodeInstance) => {
78-
console.log('before rect-node !flowNod', flowNode);
78+
const fillColorDefault = 'black';
79+
const strokeColorDefault = 'white';
80+
const strokeWidthDefault = 2;
81+
7982
const flowNodeInstance: FlowNode<NodeInfo> = flowNode ?? {
8083
id: nodeInstance.node.id,
8184
x: 0,
8285
y: 0,
8386
width: 200,
8487
height: 100,
8588
nodeInfo: {
86-
fillColor: 'black',
87-
strokeColor: 'white',
88-
strokeWidth: 2,
89+
fillColor: fillColorDefault,
90+
strokeColor: strokeColorDefault,
91+
strokeWidth: strokeWidthDefault,
92+
text: 'rect',
8993
} as any,
9094
};
9195
if (!flowNodeInstance) {
9296
return;
9397
}
9498
rect = nodeInstance.rect;
9599
node = nodeInstance.node as IRectNodeComponent<NodeInfo>;
100+
if (!flowNode) {
101+
if (!node.nodeInfo) {
102+
node.nodeInfo = {} as any;
103+
}
104+
(node.nodeInfo as any).fillColor = fillColorDefault;
105+
(node.nodeInfo as any).strokeColor = strokeColorDefault;
106+
(node.nodeInfo as any).strokeWidth = strokeWidthDefault;
107+
(node.nodeInfo as any).text = 'rect';
108+
}
96109

97110
rectNode = new RectNode(node.id, updated, node);
98111

@@ -105,11 +118,6 @@ export const getRectNode =
105118
childNodeInstance.remove();
106119
}
107120

108-
console.log(
109-
'render rect-node',
110-
flowNodeInstance.width,
111-
flowNodeInstance.height
112-
);
113121
renderElement(rectNode.render(flowNodeInstance), childNodeWrapper);
114122
nodeRenderElement = (
115123
rect?.nodeComponent?.domElement as HTMLElement

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export abstract class BaseExporter<T extends ExportFile, X> {
2525
protected createExportFile(): T {
2626
throw new Error('Method not implemented.');
2727
}
28-
protected mergeWithAdditionalIbfo(
28+
protected mergeWithAdditionalInfo(
2929
_elements: ElementNodeMap<BaseNodeInfo>
3030
): void {
3131
//
@@ -144,7 +144,7 @@ export abstract class BaseExporter<T extends ExportFile, X> {
144144
this.exportMultiPortConnection(connectionContextInfo, nodeInfo, node);
145145
});
146146

147-
this.mergeWithAdditionalIbfo(elements);
147+
this.mergeWithAdditionalInfo(elements);
148148
}
149149
protected exportConnection(
150150
_contextInfo: X,

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

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,14 @@ export class OCWGExporter extends BaseExporter<OCWGFile, OCWGInfo> {
7474
return elements.has(`${id}`);
7575
}
7676

77-
override mergeWithAdditionalIbfo(
77+
getNodeFromElements = (
78+
id: string,
79+
elements: ElementNodeMap<BaseNodeInfo>
80+
) => {
81+
return elements.get(id);
82+
};
83+
84+
override mergeWithAdditionalInfo(
7885
elements: ElementNodeMap<BaseNodeInfo>
7986
): void {
8087
const rootOCIF = getCurrentOCIF();
@@ -97,13 +104,27 @@ export class OCWGExporter extends BaseExporter<OCWGFile, OCWGInfo> {
97104
console.log('export ocif node', codeFlowCanvasNode);
98105
node.data?.forEach((d: any) => {
99106
if (!codeFlowCanvasNode.data) {
107+
// purely for typescript
100108
return;
101109
}
102110
if (
103111
d.type !== nodeInfoPropertyName &&
104112
d.type !== connectionNodeInfoPropertyName &&
105113
d.type !== '@ocwg/node/ports'
106114
) {
115+
if (d.type === 'rect-node') {
116+
const canvasNode = this.getNodeFromElements(
117+
node.id,
118+
elements
119+
);
120+
if (canvasNode) {
121+
const nodeInfo = canvasNode.nodeInfo as any;
122+
123+
d.fillColor = nodeInfo?.fillColor ?? d.fillColor;
124+
d.strokeColor = nodeInfo?.strokeColor ?? d.strokeColor;
125+
d.strokeWidth = nodeInfo?.strokeWidth ?? d.strokeWidth;
126+
}
127+
}
107128
codeFlowCanvasNode.data.push(d);
108129
}
109130
});
@@ -181,13 +202,17 @@ export class OCWGExporter extends BaseExporter<OCWGFile, OCWGInfo> {
181202
ports: ports,
182203
});
183204
}
205+
const clonedNodeInfo = structuredClone(nodeInfo) as any;
206+
delete clonedNodeInfo.fillColor;
207+
delete clonedNodeInfo.strokeColor;
208+
delete clonedNodeInfo.strokeWidth;
184209
const ocwgNode: OCWGNode = {
185210
id: `${node.id}`,
186211
position: [node.x, node.y],
187212
size: [node.width ?? 0, node.height ?? 0],
188213
data: [
189214
{
190-
...nodeInfo,
215+
...clonedNodeInfo,
191216
type: nodeInfoPropertyName,
192217
nodeType: nodeInfo.type,
193218
},

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ import {
129129
setupCanvasNodeTaskRegistry,
130130
} from '@devhelpr/web-flow-executor';
131131
import { PasteNodeCommand } from './command-handlers/paste-node-command/paste-node-command';
132+
import { clearOCIF, getCurrentOCIF, setOCIF } from './importers/ocif-importer';
132133

133134
export class CodeFlowWebAppCanvas {
134135
appRootSelector?: string;
@@ -1042,7 +1043,10 @@ export class FlowAppElement extends AppElement<NodeInfo> {
10421043
if (!this.canvasApp) {
10431044
throw new Error('canvasApp not defined');
10441045
}
1045-
1046+
clearOCIF();
1047+
if (flow.ocif) {
1048+
setOCIF(flow.ocif);
1049+
}
10461050
removeAllCompositions();
10471051
importCompositions<NodeInfo>(flow.compositions, this.canvasApp);
10481052
registerCompositionNodes(
@@ -1093,6 +1097,7 @@ export class FlowAppElement extends AppElement<NodeInfo> {
10931097
schemaType: 'flow',
10941098
schemaVersion: '0.0.1',
10951099
id: this.flowId,
1100+
ocif: getCurrentOCIF(),
10961101
flows: {
10971102
flow: {
10981103
flowType: 'flow',

libs/app-canvas/src/app/importers/ocif-importer.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,7 @@ export const clearOCIF = () => {
211211
export const getCurrentOCIF = () => {
212212
return rootOCIF;
213213
};
214+
215+
export const setOCIF = (ocif: any) => {
216+
rootOCIF = ocif;
217+
};

0 commit comments

Comments
 (0)