@linkdlab/funcnodes_react_flow 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/frontend/datarenderer/images.d.ts +11 -0
- package/dist/frontend/datarenderer/images.js +13 -0
- package/dist/frontend/datarenderer/images.js.map +1 -0
- package/dist/frontend/datarenderer/index.d.ts +16 -0
- package/dist/frontend/datarenderer/index.js +26 -0
- package/dist/frontend/datarenderer/index.js.map +1 -0
- package/dist/frontend/datarenderer/plotly.d.ts +14 -0
- package/dist/frontend/datarenderer/plotly.js +53 -0
- package/dist/frontend/datarenderer/plotly.js.map +1 -0
- package/dist/frontend/dialog.d.ts +17 -0
- package/dist/frontend/dialog.js +26 -0
- package/dist/frontend/dialog.js.map +1 -0
- package/dist/frontend/edge.d.ts +5 -0
- package/dist/frontend/edge.js +40 -0
- package/dist/frontend/edge.js.map +1 -0
- package/dist/frontend/funcnodesreactflow/index.d.ts +6 -0
- package/dist/frontend/funcnodesreactflow/index.js +94 -0
- package/dist/frontend/funcnodesreactflow/index.js.map +1 -0
- package/dist/frontend/funcnodesreactflow/react_flow_layer.d.ts +5 -0
- package/dist/frontend/funcnodesreactflow/react_flow_layer.js +149 -0
- package/dist/frontend/funcnodesreactflow/react_flow_layer.js.map +1 -0
- package/dist/frontend/header/index.d.ts +4 -0
- package/dist/frontend/header/index.js +227 -0
- package/dist/frontend/header/index.js.map +1 -0
- package/{src/frontend/index.tsx → dist/frontend/index.d.ts} +0 -1
- package/dist/frontend/index.js +4 -0
- package/dist/frontend/index.js.map +1 -0
- package/dist/frontend/lib.d.ts +10 -0
- package/dist/frontend/lib.js +107 -0
- package/dist/frontend/lib.js.map +1 -0
- package/{src/frontend/node/index.tsx → dist/frontend/node/index.d.ts} +0 -1
- package/dist/frontend/node/index.js +3 -0
- package/dist/frontend/node/index.js.map +1 -0
- package/dist/frontend/node/io/default_input_renderer.d.ts +11 -0
- package/dist/frontend/node/io/default_input_renderer.js +235 -0
- package/dist/frontend/node/io/default_input_renderer.js.map +1 -0
- package/dist/frontend/node/io/default_output_render.d.ts +6 -0
- package/dist/frontend/node/io/default_output_render.js +23 -0
- package/dist/frontend/node/io/default_output_render.js.map +1 -0
- package/dist/frontend/node/io/handle_renderer.d.ts +6 -0
- package/dist/frontend/node/io/handle_renderer.js +70 -0
- package/dist/frontend/node/io/handle_renderer.js.map +1 -0
- package/{src/frontend/node/io/index.tsx → dist/frontend/node/io/index.d.ts} +0 -1
- package/dist/frontend/node/io/index.js +4 -0
- package/dist/frontend/node/io/index.js.map +1 -0
- package/dist/frontend/node/io/io.d.ts +16 -0
- package/dist/frontend/node/io/io.js +98 -0
- package/dist/frontend/node/io/io.js.map +1 -0
- package/dist/frontend/node/io/nodeinput.d.ts +6 -0
- package/dist/frontend/node/io/nodeinput.js +74 -0
- package/dist/frontend/node/io/nodeinput.js.map +1 -0
- package/dist/frontend/node/io/nodeoutput.d.ts +6 -0
- package/dist/frontend/node/io/nodeoutput.js +19 -0
- package/dist/frontend/node/io/nodeoutput.js.map +1 -0
- package/dist/frontend/node/node.d.ts +20 -0
- package/dist/frontend/node/node.js +118 -0
- package/dist/frontend/node/node.js.map +1 -0
- package/dist/frontend/utils/colorpicker.d.ts +19 -0
- package/dist/frontend/utils/colorpicker.js +209 -0
- package/dist/frontend/utils/colorpicker.js.map +1 -0
- package/dist/frontend/utils/jsondata.d.ts +6 -0
- package/dist/frontend/utils/jsondata.js +8 -0
- package/dist/frontend/utils/jsondata.js.map +1 -0
- package/dist/frontend/utils/table.d.ts +11 -0
- package/dist/frontend/utils/table.js +108 -0
- package/dist/frontend/utils/table.js.map +1 -0
- package/dist/funcnodes/funcnodesworker.d.ts +72 -0
- package/dist/funcnodes/funcnodesworker.js +532 -0
- package/dist/funcnodes/funcnodesworker.js.map +1 -0
- package/dist/funcnodes/index.js +5 -0
- package/dist/funcnodes/index.js.map +1 -0
- package/dist/funcnodes/websocketworker.d.ts +27 -0
- package/dist/funcnodes/websocketworker.js +224 -0
- package/dist/funcnodes/websocketworker.js.map +1 -0
- package/dist/funcnodes/workermanager.d.ts +32 -0
- package/dist/funcnodes/workermanager.js +241 -0
- package/dist/funcnodes/workermanager.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/states/edge.d.ts +7 -0
- package/dist/states/edge.js +6 -0
- package/dist/states/edge.js.map +1 -0
- package/dist/states/edge.t.d.ts +16 -0
- package/dist/states/edge.t.js +2 -0
- package/dist/states/edge.t.js.map +1 -0
- package/dist/states/fnrfzst.d.ts +10 -0
- package/dist/states/fnrfzst.js +378 -0
- package/dist/states/fnrfzst.js.map +1 -0
- package/dist/states/fnrfzst.t.d.ts +100 -0
- package/dist/states/fnrfzst.t.js +2 -0
- package/dist/states/fnrfzst.t.js.map +1 -0
- package/dist/states/index.d.ts +7 -0
- package/dist/states/index.js +6 -0
- package/dist/states/index.js.map +1 -0
- package/dist/states/lib.d.ts +3 -0
- package/dist/states/lib.js +14 -0
- package/dist/states/lib.js.map +1 -0
- package/dist/states/lib.t.d.ts +24 -0
- package/dist/states/lib.t.js +2 -0
- package/dist/states/lib.t.js.map +1 -0
- package/dist/states/node.d.ts +4 -0
- package/dist/states/node.js +43 -0
- package/dist/states/node.js.map +1 -0
- package/dist/states/node.t.d.ts +73 -0
- package/dist/states/node.t.js +2 -0
- package/dist/states/node.t.js.map +1 -0
- package/dist/states/nodeio.t.d.ts +67 -0
- package/dist/states/nodeio.t.js +2 -0
- package/dist/states/nodeio.t.js.map +1 -0
- package/dist/states/nodespace.d.ts +3 -0
- package/dist/states/nodespace.js +77 -0
- package/dist/states/nodespace.js.map +1 -0
- package/dist/states/nodespace.t.d.ts +16 -0
- package/dist/states/nodespace.t.js +2 -0
- package/dist/states/nodespace.t.js.map +1 -0
- package/dist/states/reactflow.d.ts +8 -0
- package/dist/states/reactflow.js +33 -0
- package/dist/states/reactflow.js.map +1 -0
- package/dist/states/reactflow.t.d.ts +11 -0
- package/dist/states/reactflow.t.js +2 -0
- package/dist/states/reactflow.t.js.map +1 -0
- package/dist/types/rendering.t.d.ts +10 -0
- package/dist/types/rendering.t.js +2 -0
- package/dist/types/rendering.t.js.map +1 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.js +3 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/objects.d.ts +19 -0
- package/dist/utils/objects.js +118 -0
- package/dist/utils/objects.js.map +1 -0
- package/package.json +52 -21
- package/package copy.json +0 -63
- package/public/favicon.ico +0 -0
- package/public/index.html +0 -43
- package/public/logo192.png +0 -0
- package/public/logo512.png +0 -0
- package/public/manifest.json +0 -25
- package/public/robots.txt +0 -3
- package/public/worker_manager +0 -1
- package/src/App.css +0 -38
- package/src/App.test.tsx +0 -9
- package/src/App.tsx +0 -22
- package/src/frontend/datarenderer/images.tsx +0 -28
- package/src/frontend/datarenderer/index.tsx +0 -53
- package/src/frontend/datarenderer/plotly.tsx +0 -82
- package/src/frontend/dialog.scss +0 -88
- package/src/frontend/dialog.tsx +0 -70
- package/src/frontend/edge.scss +0 -15
- package/src/frontend/edge.tsx +0 -31
- package/src/frontend/funcnodesreactflow.scss +0 -63
- package/src/frontend/funcnodesreactflow.tsx +0 -283
- package/src/frontend/header/header.scss +0 -48
- package/src/frontend/header/index.tsx +0 -268
- package/src/frontend/layout/htmlelements.scss +0 -63
- package/src/frontend/lib.scss +0 -157
- package/src/frontend/lib.tsx +0 -198
- package/src/frontend/node/io/default_input_renderer.tsx +0 -327
- package/src/frontend/node/io/default_output_render.tsx +0 -26
- package/src/frontend/node/io/handle_renderer.tsx +0 -89
- package/src/frontend/node/io/io.scss +0 -91
- package/src/frontend/node/io/io.tsx +0 -114
- package/src/frontend/node/io/nodeinput.tsx +0 -125
- package/src/frontend/node/io/nodeoutput.tsx +0 -37
- package/src/frontend/node/node.scss +0 -265
- package/src/frontend/node/node.tsx +0 -208
- package/src/frontend/nodecontextmenu.scss +0 -18
- package/src/frontend/utils/colorpicker.scss +0 -37
- package/src/frontend/utils/colorpicker.tsx +0 -342
- package/src/frontend/utils/jsondata.tsx +0 -19
- package/src/frontend/utils/table.scss +0 -22
- package/src/frontend/utils/table.tsx +0 -159
- package/src/funcnodes/funcnodesworker.ts +0 -455
- package/src/funcnodes/websocketworker.ts +0 -153
- package/src/funcnodes/workermanager.ts +0 -229
- package/src/index.css +0 -13
- package/src/index.tsx +0 -19
- package/src/logo.svg +0 -1
- package/src/react-app-env.d.ts +0 -1
- package/src/reportWebVitals.ts +0 -15
- package/src/setupTests.ts +0 -5
- package/src/state/edge.ts +0 -35
- package/src/state/fnrfzst.ts +0 -440
- package/src/state/index.ts +0 -139
- package/src/state/lib.ts +0 -26
- package/src/state/node.ts +0 -118
- package/src/state/nodespace.ts +0 -151
- package/src/state/reactflow.ts +0 -65
- package/src/types/lib.d.ts +0 -16
- package/src/types/node.d.ts +0 -29
- package/src/types/nodeio.d.ts +0 -82
- package/src/types/worker.d.ts +0 -56
- package/tsconfig.json +0 -20
- /package/{src/funcnodes/index.ts → dist/funcnodes/index.d.ts} +0 -0
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
import Table from "@mui/material/Table";
|
|
2
|
-
import TableBody from "@mui/material/TableBody";
|
|
3
|
-
import TableCell, { SortDirection } from "@mui/material/TableCell";
|
|
4
|
-
import TableContainer from "@mui/material/TableContainer";
|
|
5
|
-
import TableHead from "@mui/material/TableHead";
|
|
6
|
-
import TableRow from "@mui/material/TableRow";
|
|
7
|
-
import TableSortLabel from "@mui/material/TableSortLabel";
|
|
8
|
-
|
|
9
|
-
import { useMemo, useState } from "react";
|
|
10
|
-
|
|
11
|
-
import "./table.scss";
|
|
12
|
-
|
|
13
|
-
interface TableData {
|
|
14
|
-
columns: string[];
|
|
15
|
-
index: string[];
|
|
16
|
-
data: any[][];
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
type comparertype = (a: any, b: any) => 1 | -1 | 0;
|
|
20
|
-
type _SD = "asc" | "desc";
|
|
21
|
-
|
|
22
|
-
interface TransFormedTableData {
|
|
23
|
-
header: string[];
|
|
24
|
-
rows: any[][];
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const transform_table_data = (data: TableData): TransFormedTableData => {
|
|
28
|
-
const rows = [];
|
|
29
|
-
if (data === undefined) {
|
|
30
|
-
// return empty table if data is undefined
|
|
31
|
-
return {
|
|
32
|
-
header: [],
|
|
33
|
-
rows: [],
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
if (data.data === undefined) {
|
|
37
|
-
// if data.data is undefined, make it empty
|
|
38
|
-
data.data = [];
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (data.columns === undefined) {
|
|
42
|
-
// if np columns are defined, create columns based on the first row
|
|
43
|
-
|
|
44
|
-
// if data is empty, there are no columns
|
|
45
|
-
if (data.data.length === 0) {
|
|
46
|
-
data.columns = [];
|
|
47
|
-
} else {
|
|
48
|
-
// create columns based on the first row
|
|
49
|
-
data.columns = data.data[0].map((_, i) => `col${i}`);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
if (data.index === undefined) {
|
|
53
|
-
// if no index is defined, create index based on the number of rows
|
|
54
|
-
data.index = data.data.map((_, i) => `row${i}`);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
for (let i = 0; i < data.index.length; i++) {
|
|
58
|
-
const row = [data.index[i]];
|
|
59
|
-
for (let j = 0; j < data.columns.length; j++) {
|
|
60
|
-
row.push(data.data[i][j]);
|
|
61
|
-
}
|
|
62
|
-
rows.push(row);
|
|
63
|
-
}
|
|
64
|
-
return {
|
|
65
|
-
header: ["index", ...data.columns],
|
|
66
|
-
rows: rows,
|
|
67
|
-
};
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
function SortableTable({ tabledata }: { tabledata: TableData }) {
|
|
71
|
-
// State to manage the sorted column and direction
|
|
72
|
-
const transformed_table_data: TransFormedTableData = useMemo(
|
|
73
|
-
() => transform_table_data(tabledata),
|
|
74
|
-
[tabledata]
|
|
75
|
-
);
|
|
76
|
-
const [orderDirection, setOrderDirection] = useState<_SD>("asc");
|
|
77
|
-
const [orderBy, setOrderBy] = useState("index");
|
|
78
|
-
|
|
79
|
-
let order_by_index = transformed_table_data.header.indexOf(orderBy);
|
|
80
|
-
if (order_by_index === -1) {
|
|
81
|
-
order_by_index = 0;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// Function to handle sorting
|
|
85
|
-
const handleSort = (column: string) => {
|
|
86
|
-
const isAsc = orderBy === column && orderDirection === "asc";
|
|
87
|
-
setOrderDirection(isAsc ? "desc" : "asc");
|
|
88
|
-
setOrderBy(column);
|
|
89
|
-
};
|
|
90
|
-
// Function to sort data
|
|
91
|
-
const sortData = (data: any[][], comparator: comparertype) => {
|
|
92
|
-
const stabilizedThis: [any[], number][] = data.map((el, index) => [
|
|
93
|
-
el,
|
|
94
|
-
index,
|
|
95
|
-
]);
|
|
96
|
-
stabilizedThis.sort((a, b) => {
|
|
97
|
-
const order = comparator(a[0], b[0]);
|
|
98
|
-
return order;
|
|
99
|
-
});
|
|
100
|
-
return stabilizedThis.map((el) => el[0]);
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
// Comparator function for sorting
|
|
104
|
-
const getComparator = (order: _SD, orderBy: string): comparertype => {
|
|
105
|
-
return order === "desc"
|
|
106
|
-
? (a, b) => (b[order_by_index] < a[order_by_index] ? -1 : 1)
|
|
107
|
-
: (a, b) => (a[order_by_index] < b[order_by_index] ? -1 : 1);
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
// Sort the rows
|
|
111
|
-
const sortedRows = sortData(
|
|
112
|
-
transformed_table_data.rows,
|
|
113
|
-
getComparator(orderDirection, orderBy)
|
|
114
|
-
);
|
|
115
|
-
return (
|
|
116
|
-
<TableContainer className="tablecontainer">
|
|
117
|
-
<Table size="small">
|
|
118
|
-
<TableHead className="tableHead">
|
|
119
|
-
<TableRow className="tableheadercolor">
|
|
120
|
-
{transformed_table_data.header.map((column) => (
|
|
121
|
-
<TableCell
|
|
122
|
-
key={column}
|
|
123
|
-
sortDirection={orderBy === column ? orderDirection : false}
|
|
124
|
-
className="tableheadercolor"
|
|
125
|
-
>
|
|
126
|
-
<TableSortLabel
|
|
127
|
-
active={orderBy === column}
|
|
128
|
-
direction={orderBy === column ? orderDirection : "asc"}
|
|
129
|
-
onClick={() => handleSort(column)}
|
|
130
|
-
className="tableheadercolor"
|
|
131
|
-
sx={{
|
|
132
|
-
"& .MuiTableSortLabel-icon": {
|
|
133
|
-
color: "inherit !important",
|
|
134
|
-
},
|
|
135
|
-
}}
|
|
136
|
-
>
|
|
137
|
-
{column}
|
|
138
|
-
</TableSortLabel>
|
|
139
|
-
</TableCell>
|
|
140
|
-
))}
|
|
141
|
-
</TableRow>
|
|
142
|
-
</TableHead>
|
|
143
|
-
<TableBody>
|
|
144
|
-
{sortedRows.map((row, index) => (
|
|
145
|
-
<TableRow key={tabledata.index[index]}>
|
|
146
|
-
{row.map((cell, i) => (
|
|
147
|
-
<TableCell key={i} className={i == 0 ? "indexcol" : "datacol"}>
|
|
148
|
-
{cell}
|
|
149
|
-
</TableCell>
|
|
150
|
-
))}
|
|
151
|
-
</TableRow>
|
|
152
|
-
))}
|
|
153
|
-
</TableBody>
|
|
154
|
-
</Table>
|
|
155
|
-
</TableContainer>
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
export { SortableTable };
|
|
@@ -1,455 +0,0 @@
|
|
|
1
|
-
import { v4 as uuidv4 } from "uuid";
|
|
2
|
-
import {
|
|
3
|
-
FuncNodesReactFlowZustandInterface,
|
|
4
|
-
NodeSpaceZustand,
|
|
5
|
-
deep_merge,
|
|
6
|
-
} from "../state";
|
|
7
|
-
import { NodeActionUpdate } from "../state/node"; // Import the missing type
|
|
8
|
-
import { wait } from "@testing-library/user-event/dist/utils";
|
|
9
|
-
type CmdMessage = {
|
|
10
|
-
type: string;
|
|
11
|
-
cmd: string;
|
|
12
|
-
kwargs: any;
|
|
13
|
-
id?: string;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
interface WorkerProps {
|
|
17
|
-
zustand: FuncNodesReactFlowZustandInterface;
|
|
18
|
-
uuid: string;
|
|
19
|
-
on_error?: (error: string | Error) => void;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
class FuncNodesWorker {
|
|
23
|
-
messagePromises: Map<string, any>;
|
|
24
|
-
_zustand: FuncNodesReactFlowZustandInterface;
|
|
25
|
-
_nodeupdates: Map<string, PartialNodeType>;
|
|
26
|
-
_nodeupdatetimer: NodeJS.Timeout;
|
|
27
|
-
uuid: string;
|
|
28
|
-
is_open: boolean;
|
|
29
|
-
on_error: (error: any) => void;
|
|
30
|
-
constructor(data: WorkerProps) {
|
|
31
|
-
this.uuid = data.uuid;
|
|
32
|
-
this.on_error = data.on_error || console.error;
|
|
33
|
-
this.messagePromises = new Map();
|
|
34
|
-
this._zustand = data.zustand;
|
|
35
|
-
this._nodeupdates = new Map();
|
|
36
|
-
this._nodeupdatetimer = setTimeout(() => {
|
|
37
|
-
this.perform_update();
|
|
38
|
-
}, 1000);
|
|
39
|
-
this.is_open = true;
|
|
40
|
-
}
|
|
41
|
-
async fullsync() {
|
|
42
|
-
const resp = (await this._send_cmd({ cmd: "full_state" })) as FullState;
|
|
43
|
-
console.log("Full state", resp);
|
|
44
|
-
this._zustand.lib.libstate.getState().set(resp.backend.lib);
|
|
45
|
-
if (resp.view.renderoptions)
|
|
46
|
-
this._zustand.update_render_options(resp.view.renderoptions);
|
|
47
|
-
const nodeview = resp.view.nodes;
|
|
48
|
-
for (const node of resp.backend.nodes) {
|
|
49
|
-
if (nodeview[node.id] !== undefined) {
|
|
50
|
-
node.frontend = nodeview[node.id];
|
|
51
|
-
}
|
|
52
|
-
this._recieve_node_added(node);
|
|
53
|
-
}
|
|
54
|
-
for (const edge of resp.backend.edges) {
|
|
55
|
-
this._recieve_edge_added(...edge);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
async _recieve_edge_added(
|
|
60
|
-
src_nid: string,
|
|
61
|
-
src_ioid: string,
|
|
62
|
-
trg_nid: string,
|
|
63
|
-
trg_ioid: string
|
|
64
|
-
) {
|
|
65
|
-
this._zustand.on_edge_action({
|
|
66
|
-
type: "add",
|
|
67
|
-
from_remote: true,
|
|
68
|
-
...{ src_nid, src_ioid, trg_nid, trg_ioid },
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
async trigger_node(node_id: string) {
|
|
73
|
-
await this._send_cmd({
|
|
74
|
-
cmd: "trigger_node",
|
|
75
|
-
kwargs: { nid: node_id },
|
|
76
|
-
wait_for_response: false,
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
async add_node(node_id: string) {
|
|
81
|
-
const resp = await this._send_cmd({
|
|
82
|
-
cmd: "add_node",
|
|
83
|
-
kwargs: { id: node_id },
|
|
84
|
-
});
|
|
85
|
-
this._recieve_node_added(resp as NodeType);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
async remove_node(node_id: string) {
|
|
89
|
-
const resp = await this._send_cmd({
|
|
90
|
-
cmd: "remove_node",
|
|
91
|
-
kwargs: { id: node_id },
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
async _recieve_node_added(data: NodeType) {
|
|
96
|
-
this._zustand.on_node_action({
|
|
97
|
-
type: "add",
|
|
98
|
-
node: data,
|
|
99
|
-
id: data.id,
|
|
100
|
-
from_remote: true,
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
add_edge({
|
|
105
|
-
src_nid,
|
|
106
|
-
src_ioid,
|
|
107
|
-
trg_nid,
|
|
108
|
-
trg_ioid,
|
|
109
|
-
replace = false,
|
|
110
|
-
}: {
|
|
111
|
-
src_nid: string;
|
|
112
|
-
src_ioid: string;
|
|
113
|
-
trg_nid: string;
|
|
114
|
-
trg_ioid: string;
|
|
115
|
-
replace?: boolean;
|
|
116
|
-
}) {
|
|
117
|
-
return this._send_cmd({
|
|
118
|
-
cmd: "add_edge",
|
|
119
|
-
kwargs: { src_nid, src_ioid, trg_nid, trg_ioid, replace },
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
remove_edge({
|
|
124
|
-
src_nid,
|
|
125
|
-
src_ioid,
|
|
126
|
-
trg_nid,
|
|
127
|
-
trg_ioid,
|
|
128
|
-
}: {
|
|
129
|
-
src_nid: string;
|
|
130
|
-
src_ioid: string;
|
|
131
|
-
trg_nid: string;
|
|
132
|
-
trg_ioid: string;
|
|
133
|
-
}) {
|
|
134
|
-
return this._send_cmd({
|
|
135
|
-
cmd: "remove_edge",
|
|
136
|
-
kwargs: { src_nid, src_ioid, trg_nid, trg_ioid },
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
perform_update() {
|
|
141
|
-
clearTimeout(this._nodeupdatetimer);
|
|
142
|
-
this._nodeupdates.forEach(async (node, id) => {
|
|
143
|
-
const ans = await this._send_cmd({
|
|
144
|
-
cmd: "update_node",
|
|
145
|
-
kwargs: { nid: id, data: node },
|
|
146
|
-
wait_for_response: true,
|
|
147
|
-
});
|
|
148
|
-
this._zustand.on_node_action({
|
|
149
|
-
type: "update",
|
|
150
|
-
node: ans,
|
|
151
|
-
id: id,
|
|
152
|
-
from_remote: true,
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
this._nodeupdates.clear();
|
|
156
|
-
this._nodeupdatetimer = setTimeout(() => {
|
|
157
|
-
this.perform_update();
|
|
158
|
-
}, 1000);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
update_node(action: NodeActionUpdate) {
|
|
162
|
-
// Add the type to the parameter
|
|
163
|
-
const currentstate = this._nodeupdates.get(action.id);
|
|
164
|
-
if (currentstate) {
|
|
165
|
-
const { new_obj, change } = deep_merge(currentstate, action.node);
|
|
166
|
-
if (change) {
|
|
167
|
-
this._nodeupdates.set(action.id, new_obj);
|
|
168
|
-
}
|
|
169
|
-
} else {
|
|
170
|
-
this._nodeupdates.set(action.id, action.node);
|
|
171
|
-
}
|
|
172
|
-
if (action.immediate) {
|
|
173
|
-
this.perform_update();
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
set_io_value({
|
|
178
|
-
nid,
|
|
179
|
-
ioid,
|
|
180
|
-
value,
|
|
181
|
-
set_default,
|
|
182
|
-
}: {
|
|
183
|
-
nid: string;
|
|
184
|
-
ioid: string;
|
|
185
|
-
value: any;
|
|
186
|
-
set_default?: boolean;
|
|
187
|
-
}) {
|
|
188
|
-
return this._send_cmd({
|
|
189
|
-
cmd: "set_io_value",
|
|
190
|
-
kwargs: { nid, ioid, value, set_default },
|
|
191
|
-
wait_for_response: true,
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
clear() {
|
|
196
|
-
return this._send_cmd({ cmd: "clear" });
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
save() {
|
|
200
|
-
return this._send_cmd({ cmd: "save", wait_for_response: true });
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
load(data: any) {
|
|
204
|
-
return this._send_cmd({
|
|
205
|
-
cmd: "load_data",
|
|
206
|
-
kwargs: { data },
|
|
207
|
-
wait_for_response: true,
|
|
208
|
-
}).then(() => {
|
|
209
|
-
this.fullsync();
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
get_io_value({ nid, ioid }: { nid: string; ioid: string }) {
|
|
214
|
-
return this._send_cmd({
|
|
215
|
-
cmd: "get_io_value",
|
|
216
|
-
kwargs: { nid, ioid },
|
|
217
|
-
wait_for_response: true,
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
async _send_cmd({
|
|
222
|
-
cmd,
|
|
223
|
-
kwargs,
|
|
224
|
-
wait_for_response = true,
|
|
225
|
-
response_timeout = 5000,
|
|
226
|
-
}: {
|
|
227
|
-
cmd: string;
|
|
228
|
-
kwargs?: any;
|
|
229
|
-
wait_for_response?: boolean;
|
|
230
|
-
response_timeout?: number;
|
|
231
|
-
}) {
|
|
232
|
-
const msg: CmdMessage = {
|
|
233
|
-
type: "cmd",
|
|
234
|
-
cmd,
|
|
235
|
-
kwargs: kwargs || {},
|
|
236
|
-
};
|
|
237
|
-
|
|
238
|
-
// await self.assert_connection()
|
|
239
|
-
if (wait_for_response) {
|
|
240
|
-
const msid = msg.id || uuidv4();
|
|
241
|
-
msg.id = msid;
|
|
242
|
-
const promise = new Promise<any>((resolve, reject) => {
|
|
243
|
-
const timeout = setTimeout(() => {
|
|
244
|
-
reject("Timeout");
|
|
245
|
-
}, response_timeout);
|
|
246
|
-
this.messagePromises.set(msid, {
|
|
247
|
-
resolve: (data: any) => {
|
|
248
|
-
clearTimeout(timeout);
|
|
249
|
-
resolve(data);
|
|
250
|
-
this.messagePromises.delete(msid);
|
|
251
|
-
},
|
|
252
|
-
reject: (err: any) => {
|
|
253
|
-
clearTimeout(timeout);
|
|
254
|
-
reject(err);
|
|
255
|
-
this.messagePromises.delete(msid);
|
|
256
|
-
},
|
|
257
|
-
});
|
|
258
|
-
});
|
|
259
|
-
await this.send(msg);
|
|
260
|
-
return promise;
|
|
261
|
-
}
|
|
262
|
-
return this.send(msg);
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
async send(data: any) {
|
|
266
|
-
// this is the abstract method that should be implemented by subclasses
|
|
267
|
-
throw new Error("Not implemented");
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
async recieve_nodespace_event({ event, data }: NodeSpaceEvent) {
|
|
271
|
-
switch (event) {
|
|
272
|
-
case "after_set_value":
|
|
273
|
-
return this._zustand.on_node_action({
|
|
274
|
-
type: "update",
|
|
275
|
-
node: {
|
|
276
|
-
id: data.node,
|
|
277
|
-
io: {
|
|
278
|
-
[data.io]: {
|
|
279
|
-
value: data.result,
|
|
280
|
-
},
|
|
281
|
-
},
|
|
282
|
-
},
|
|
283
|
-
id: data.node,
|
|
284
|
-
from_remote: true,
|
|
285
|
-
});
|
|
286
|
-
case "after_update_value_options":
|
|
287
|
-
return this._zustand.on_node_action({
|
|
288
|
-
type: "update",
|
|
289
|
-
node: {
|
|
290
|
-
id: data.node,
|
|
291
|
-
io: {
|
|
292
|
-
[data.io]: {
|
|
293
|
-
value_options: data.result,
|
|
294
|
-
},
|
|
295
|
-
},
|
|
296
|
-
},
|
|
297
|
-
id: data.node,
|
|
298
|
-
from_remote: true,
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
case "triggerstart":
|
|
302
|
-
return this._zustand.on_node_action({
|
|
303
|
-
type: "update",
|
|
304
|
-
node: {
|
|
305
|
-
id: data.node,
|
|
306
|
-
in_trigger: true,
|
|
307
|
-
},
|
|
308
|
-
id: data.node,
|
|
309
|
-
from_remote: true,
|
|
310
|
-
});
|
|
311
|
-
|
|
312
|
-
case "triggerdone":
|
|
313
|
-
return this._zustand.on_node_action({
|
|
314
|
-
type: "update",
|
|
315
|
-
node: {
|
|
316
|
-
id: data.node,
|
|
317
|
-
in_trigger: false,
|
|
318
|
-
},
|
|
319
|
-
id: data.node,
|
|
320
|
-
from_remote: true,
|
|
321
|
-
});
|
|
322
|
-
|
|
323
|
-
case "node_trigger_error":
|
|
324
|
-
return this._zustand.on_node_action({
|
|
325
|
-
type: "error",
|
|
326
|
-
errortype: "trigger",
|
|
327
|
-
error: data.error,
|
|
328
|
-
id: data.node,
|
|
329
|
-
from_remote: true,
|
|
330
|
-
});
|
|
331
|
-
|
|
332
|
-
case "node_removed":
|
|
333
|
-
return this._zustand.on_node_action({
|
|
334
|
-
type: "delete",
|
|
335
|
-
id: data.node,
|
|
336
|
-
from_remote: true,
|
|
337
|
-
});
|
|
338
|
-
|
|
339
|
-
case "node_added":
|
|
340
|
-
return this._recieve_node_added(data.node as NodeType);
|
|
341
|
-
|
|
342
|
-
case "after_disconnect":
|
|
343
|
-
if (!data.result) return;
|
|
344
|
-
if (!Array.isArray(data.result)) return;
|
|
345
|
-
if (data.result.length !== 4) return;
|
|
346
|
-
return this._zustand.on_edge_action({
|
|
347
|
-
type: "delete",
|
|
348
|
-
from_remote: true,
|
|
349
|
-
src_nid: data.result[0],
|
|
350
|
-
src_ioid: data.result[1],
|
|
351
|
-
trg_nid: data.result[2],
|
|
352
|
-
trg_ioid: data.result[3],
|
|
353
|
-
});
|
|
354
|
-
|
|
355
|
-
case "after_connect":
|
|
356
|
-
if (!data.result) return;
|
|
357
|
-
if (!Array.isArray(data.result)) return;
|
|
358
|
-
if (data.result.length !== 4) return;
|
|
359
|
-
return this._recieve_edge_added(
|
|
360
|
-
...(data.result as [string, string, string, string])
|
|
361
|
-
);
|
|
362
|
-
|
|
363
|
-
case "after_add_shelf":
|
|
364
|
-
if (!data.result) return;
|
|
365
|
-
return this._zustand.lib.libstate.getState().set(data.result);
|
|
366
|
-
|
|
367
|
-
default:
|
|
368
|
-
console.warn("Unhandled nodepsace event", event, data);
|
|
369
|
-
break;
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
async add_lib(lib: string) {
|
|
374
|
-
const ans = await this._send_cmd({
|
|
375
|
-
cmd: "add_shelf",
|
|
376
|
-
kwargs: { src: lib },
|
|
377
|
-
wait_for_response: false,
|
|
378
|
-
});
|
|
379
|
-
return ans;
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
async recieve(data: JSONMessage) {
|
|
383
|
-
let promise;
|
|
384
|
-
switch (data.type) {
|
|
385
|
-
case "nsevent":
|
|
386
|
-
return await this.recieve_nodespace_event(data);
|
|
387
|
-
case "result":
|
|
388
|
-
promise = data.id && this.messagePromises.get(data.id);
|
|
389
|
-
if (promise) {
|
|
390
|
-
return promise.resolve(data.result);
|
|
391
|
-
}
|
|
392
|
-
break;
|
|
393
|
-
case "error":
|
|
394
|
-
this.on_error(data.tb + "\n" + data.error);
|
|
395
|
-
promise = data.id && this.messagePromises.get(data.id);
|
|
396
|
-
if (promise) {
|
|
397
|
-
return promise.reject(data.error);
|
|
398
|
-
}
|
|
399
|
-
break;
|
|
400
|
-
case "progress":
|
|
401
|
-
this._zustand.set_progress(data);
|
|
402
|
-
break;
|
|
403
|
-
default:
|
|
404
|
-
console.warn("Unhandled message", data);
|
|
405
|
-
break;
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
disconnect() {}
|
|
410
|
-
|
|
411
|
-
onclose() {
|
|
412
|
-
this.is_open = false;
|
|
413
|
-
this._zustand.auto_progress();
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
async reconnect() {}
|
|
417
|
-
|
|
418
|
-
async stop() {
|
|
419
|
-
await this._send_cmd({ cmd: "stop_worker", wait_for_response: false });
|
|
420
|
-
const oldonclose = this.onclose.bind(this);
|
|
421
|
-
this.onclose = () => {
|
|
422
|
-
oldonclose();
|
|
423
|
-
if (this._zustand.worker === this) {
|
|
424
|
-
this._zustand.clear_all();
|
|
425
|
-
}
|
|
426
|
-
this.onclose = oldonclose;
|
|
427
|
-
};
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
async get_io_full_value({ nid, ioid }: { nid: string; ioid: string }) {
|
|
431
|
-
const res = await this._send_cmd({
|
|
432
|
-
cmd: "get_io_full_value",
|
|
433
|
-
kwargs: { nid, ioid },
|
|
434
|
-
wait_for_response: true,
|
|
435
|
-
});
|
|
436
|
-
//console.log("Full value", res);
|
|
437
|
-
|
|
438
|
-
this._zustand.on_node_action({
|
|
439
|
-
type: "update",
|
|
440
|
-
node: {
|
|
441
|
-
io: {
|
|
442
|
-
[ioid]: {
|
|
443
|
-
fullvalue: res,
|
|
444
|
-
},
|
|
445
|
-
},
|
|
446
|
-
},
|
|
447
|
-
id: nid,
|
|
448
|
-
from_remote: true,
|
|
449
|
-
});
|
|
450
|
-
return res;
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
export default FuncNodesWorker;
|
|
455
|
-
export type { WorkerProps };
|