Skip to content

Commit 966a8eb

Browse files
committed
mulitple fixes and improvemetns .. ocif support extended, support for debug-info .. improved positioning/pointer handling
1 parent bab184b commit 966a8eb

37 files changed

+1222
-463
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
{
2+
"ocif": "https://canvasprotocol.org/ocif/0.3",
3+
"nodes": [
4+
{
5+
"id": "berlin-node",
6+
"position": [100, 100],
7+
"size": [100, 50],
8+
"resource": "berlin-res",
9+
"data": [
10+
{
11+
"type": "@ocwg/node/rect",
12+
"strokeWidth": 3,
13+
"strokeColor": "#000000",
14+
"fillColor": "#00FF00"
15+
}
16+
]
17+
},
18+
{
19+
"id": "germany-node",
20+
"position": [300, 100],
21+
"size": [100, 60],
22+
"resource": "germany-res",
23+
"data": [
24+
{
25+
"type": "@ocwg/node/oval",
26+
"strokeWidth": 5,
27+
"strokeColor": "#FF0000",
28+
"fillColor": "#FFFFFF"
29+
}
30+
]
31+
},
32+
{
33+
"id": "arrow-1",
34+
"data": [
35+
{
36+
"type": "@ocwg/node/arrow",
37+
"strokeColor": "#000000",
38+
"start": [200, 125],
39+
"end": [350, 130],
40+
"startMarker": "none",
41+
"endMarker": "arrowhead",
42+
"relation": "relation-1"
43+
}
44+
]
45+
}
46+
],
47+
"relations": [
48+
{
49+
"id": "relation-1",
50+
"data": [
51+
{
52+
"type": "@ocwg/rel/edge",
53+
"start": "berlin-node",
54+
"end": "germany-node",
55+
"rel": "https://www.wikidata.org/wiki/Property:P1376",
56+
"node": "arrow-1"
57+
}
58+
]
59+
}
60+
],
61+
"resources": [
62+
{
63+
"id": "berlin-res",
64+
"representations": [{ "mime-type": "text/plain", "content": "Berlin" }]
65+
},
66+
{
67+
"id": "germany-res",
68+
"representations": [
69+
{ "mime-type": "text/plain", "content": "Germany 🇩🇪" }
70+
]
71+
}
72+
]
73+
}

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,42 @@
11
import {
22
createJSXElement,
33
FlowNode,
4+
IComputeResult,
45
} from '@devhelpr/visual-programming-system';
56
import { NodeInfo } from '@devhelpr/web-flow-executor';
67
import { BaseRectNode } from './rect-node-class';
78

9+
import TestWorker from './workers/test-worker?worker';
10+
11+
const testWorker = new TestWorker();
12+
13+
testWorker.addEventListener('message', (event) => {
14+
console.log('Worker response:', event.data);
15+
});
16+
817
export class OvalNode extends BaseRectNode {
918
static readonly nodeTypeName = 'oval-node';
1019
static readonly nodeTitle = 'Oval node';
1120
static readonly category = 'Default test';
1221
static readonly text = 'oval';
1322

23+
override compute = (
24+
input: string,
25+
_loopIndex?: number,
26+
_payload?: any
27+
): Promise<IComputeResult> => {
28+
return new Promise<IComputeResult>((resolve) => {
29+
testWorker.postMessage(input);
30+
testWorker.onmessage = (event) => {
31+
resolve({
32+
result: event.data.payload.processedData,
33+
output: event.data.payload.processedData,
34+
followPath: undefined,
35+
});
36+
};
37+
});
38+
};
39+
1440
childElementSelector = '.child-node-wrapper > *:first-child';
1541
render = (node: FlowNode<NodeInfo>) => {
1642
const nodeInfo = node.nodeInfo as any;
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/// <reference lib="webworker" />
2+
3+
// Worker context type declaration
4+
declare const self: DedicatedWorkerGlobalScope;
5+
6+
// Message event handler
7+
self.addEventListener('message', (event: MessageEvent) => {
8+
const { data } = event;
9+
10+
// Example computation
11+
const result = processData(data);
12+
13+
// Send the result back to the main thread
14+
self.postMessage({
15+
type: 'computation-result',
16+
payload: result,
17+
});
18+
});
19+
20+
// Example processing function
21+
function processData(data: any) {
22+
// Simulate some computation
23+
const startTime = Date.now();
24+
25+
// Simple example: if data is a number, double it
26+
// If it's a string, reverse it
27+
let result;
28+
if (typeof data === 'number') {
29+
result = data * 2;
30+
} else if (typeof data === 'string') {
31+
result = data.split('').reverse().join('');
32+
} else {
33+
result = data;
34+
}
35+
36+
// Add processing time to result
37+
return {
38+
originalData: data,
39+
processedData: result,
40+
processingTime: Date.now() - startTime,
41+
};
42+
}
43+
44+
// Error handling
45+
self.addEventListener('error', (error) => {
46+
console.log('Worker error:', error.message);
47+
self.postMessage({
48+
type: 'error',
49+
payload: error.message,
50+
});
51+
});
52+
53+
export {}; // Add export to make this a module

apps/vps-web/src/app/pages/counter.json

Lines changed: 266 additions & 45 deletions
Large diffs are not rendered by default.

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Flow } from '@devhelpr/visual-programming-system';
22
import { NodeInfo } from '@devhelpr/web-flow-executor';
33
import flowData from './counter.json';
4+
import { registerNodes } from '../custom-nodes/register-nodes';
45

56
export function examplePage() {
67
const appElement = document.getElementById('app-root')!;
@@ -19,7 +20,15 @@ export function examplePage() {
1920
};
2021
appElement.classList.add('hidden');
2122
pageElement.classList.remove('hidden');
22-
new module.FlowAppElement('#page-app-root', storageProvider, true, 20, 32);
23+
new module.FlowAppElement(
24+
'#page-app-root',
25+
storageProvider,
26+
false,
27+
20,
28+
32,
29+
undefined,
30+
registerNodes
31+
);
2332
//result.destroy();
2433
});
2534
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
import '@shoelace-style/shoelace/dist/themes/light.css';
99
import '@shoelace-style/shoelace/dist/components/color-picker/color-picker.js';
1010
import { registerNodes } from '../custom-nodes/register-nodes';
11+
import { ocifVersion } from '@devhelpr/app-canvas';
1112

1213
export function ocwgPage() {
1314
// Add color picker popup
@@ -52,7 +53,7 @@ export function ocwgPage() {
5253
class="hidden bg-white z-[50000] overflow-hidden fixed w-[384px] h-[384px] max-w-[calc(100vw-80px)] bottom-[80px] right-[40px] grid grid-rows-[auto_1fr]"
5354
>
5455
<div class="flex flex-wrap">
55-
<h1 class="font-bold text-xl p-2">OpenCanvas OCIF 0.2 (WiP)</h1>
56+
<h1 class="font-bold text-xl p-2">{`OpenCanvas OCIF ${ocifVersion} (WiP)`}</h1>
5657
<button
5758
id="ocwg-copy-to-clipboard"
5859
title="Copy to clipboard"

apps/vps-web/vite.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ export default defineConfig({
1515
transformMixedEsModules: true,
1616
},
1717
},
18+
worker: {
19+
format: 'es',
20+
},
1821
server: {
1922
port: 4200,
2023
host: 'localhost',
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import {
2+
createJSXElement,
3+
renderElement,
4+
} from '@devhelpr/visual-programming-system';
5+
6+
// export const DebugInfo = () => {
7+
// return <div></div>;
8+
// };
9+
10+
export class DebugInfoController {
11+
debugElement: HTMLElement | undefined;
12+
constructor(rootElement: HTMLElement) {
13+
renderElement(
14+
<div
15+
class={`fixed top-0 right-0 z-[50000] bg-white text-black p-2 border border-gray-300`}
16+
getElement={(element: HTMLElement) => {
17+
this.debugElement = element;
18+
}}
19+
></div>,
20+
rootElement
21+
);
22+
}
23+
24+
sendDebugInfo(debugInfo: Record<string, boolean | number | string>) {
25+
if (this.debugElement) {
26+
this.debugElement.innerHTML = '';
27+
renderElement(
28+
<div>
29+
{Object.keys(debugInfo).map((key) => {
30+
return (
31+
<div>
32+
{key}: {debugInfo[key]}
33+
</div>
34+
);
35+
})}
36+
</div>,
37+
this.debugElement
38+
);
39+
}
40+
}
41+
}

libs/app-canvas/src/app/components/gl-navbar-components.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ export class GLNavbarComponent extends Component<
420420
this.props.initializeNodes();
421421
}
422422
});
423-
reader.readAsBinaryString(files[0]);
423+
reader.readAsText(files[0]);
424424
}
425425
};
426426
input.click();

libs/app-canvas/src/app/components/navbar-components.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ export class NavbarComponent extends Component<
202202
}, 0);
203203
}
204204
});
205-
reader.readAsBinaryString(files[0]);
205+
reader.readAsText(files[0]);
206206
}
207207
};
208208
input.click();
@@ -681,7 +681,7 @@ export class NavbarComponent extends Component<
681681
}, 0);
682682
}
683683
});
684-
reader.readAsBinaryString(files[0]);
684+
reader.readAsText(files[0]);
685685
}
686686
};
687687
input.click();
@@ -736,7 +736,7 @@ export class NavbarComponent extends Component<
736736
}
737737
}
738738
});
739-
reader.readAsBinaryString(files[0]);
739+
reader.readAsText(files[0]);
740740
}
741741
};
742742
input.click();

0 commit comments

Comments
 (0)