@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
package/src/state/fnrfzst.ts
DELETED
|
@@ -1,440 +0,0 @@
|
|
|
1
|
-
import LibZustand, { LibZustandInterface } from "./lib";
|
|
2
|
-
import { FuncNodesWorker } from "../funcnodes";
|
|
3
|
-
import NodeSpaceZustand, { NodeSpaceZustandInterface } from "./nodespace";
|
|
4
|
-
import { NodeStore, createNodeStore } from "./node";
|
|
5
|
-
import { PartialIOType } from "./node";
|
|
6
|
-
import reactflowstore, { RFStore } from "./reactflow";
|
|
7
|
-
import {
|
|
8
|
-
Node as RFNode,
|
|
9
|
-
NodeChange,
|
|
10
|
-
useReactFlow,
|
|
11
|
-
EdgeChange,
|
|
12
|
-
Edge as RFEdge,
|
|
13
|
-
Connection as RFConnection,
|
|
14
|
-
} from "reactflow";
|
|
15
|
-
import { NodeAction } from "./node";
|
|
16
|
-
import { deep_merge } from ".";
|
|
17
|
-
import { EdgeAction, generate_edge_id } from "./edge";
|
|
18
|
-
import WorkerManager from "../funcnodes/workermanager";
|
|
19
|
-
import { UseBoundStore, StoreApi, create } from "zustand";
|
|
20
|
-
|
|
21
|
-
interface WorkerRepresentation {
|
|
22
|
-
uuid: string;
|
|
23
|
-
host: string;
|
|
24
|
-
port: number;
|
|
25
|
-
ssl: boolean;
|
|
26
|
-
active: boolean;
|
|
27
|
-
name: string | null;
|
|
28
|
-
}
|
|
29
|
-
interface WorkersState {
|
|
30
|
-
[key: string]: WorkerRepresentation;
|
|
31
|
-
}
|
|
32
|
-
interface FuncNodesReactFlowZustandInterface {
|
|
33
|
-
lib: LibZustandInterface;
|
|
34
|
-
workermanager: WorkerManager | undefined;
|
|
35
|
-
workers: UseBoundStore<StoreApi<WorkersState>>;
|
|
36
|
-
worker: FuncNodesWorker | undefined;
|
|
37
|
-
nodespace: NodeSpaceZustandInterface;
|
|
38
|
-
useReactFlowStore: RFStore;
|
|
39
|
-
render_options: UseBoundStore<StoreApi<RenderOptions>>;
|
|
40
|
-
progress_state: UseBoundStore<StoreApi<ProgressState>>;
|
|
41
|
-
update_render_options: (options: RenderOptions) => void;
|
|
42
|
-
rf_instance?: ReturnType<typeof useReactFlow>;
|
|
43
|
-
on_node_action: (action: NodeAction) => void;
|
|
44
|
-
on_edge_action: (edge: EdgeAction) => void;
|
|
45
|
-
set_progress: (progress: ProgressState) => void;
|
|
46
|
-
auto_progress: () => void;
|
|
47
|
-
reactflowRef: HTMLDivElement | null;
|
|
48
|
-
clear_all: () => void;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const _fill_node_frontend = (
|
|
52
|
-
node: NodeType,
|
|
53
|
-
fnrf_instance?: FuncNodesReactFlowZustandInterface
|
|
54
|
-
) => {
|
|
55
|
-
const frontend = node.frontend || {};
|
|
56
|
-
if (!frontend.pos) {
|
|
57
|
-
if (
|
|
58
|
-
!fnrf_instance ||
|
|
59
|
-
!fnrf_instance.rf_instance ||
|
|
60
|
-
fnrf_instance.reactflowRef === null
|
|
61
|
-
) {
|
|
62
|
-
frontend.pos = [0, 0];
|
|
63
|
-
} else {
|
|
64
|
-
const ref = fnrf_instance.reactflowRef;
|
|
65
|
-
const rect = ref.getBoundingClientRect(); // Step 2: Get bounding rectangle
|
|
66
|
-
const centerX = rect.left + rect.width / 2; // Calculate center X
|
|
67
|
-
const centerY = rect.top + rect.height / 2; // Calculate center Y
|
|
68
|
-
const calcpos = fnrf_instance.rf_instance.screenToFlowPosition({
|
|
69
|
-
x: centerX,
|
|
70
|
-
y: centerY,
|
|
71
|
-
});
|
|
72
|
-
frontend.pos = [calcpos.x, calcpos.y];
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
if (!frontend.size) {
|
|
76
|
-
frontend.size = [200, 100];
|
|
77
|
-
}
|
|
78
|
-
if (!frontend.collapsed) {
|
|
79
|
-
frontend.collapsed = false;
|
|
80
|
-
}
|
|
81
|
-
node.frontend = frontend;
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const assert_react_flow_io = (
|
|
85
|
-
io: PartialIOType,
|
|
86
|
-
fnrf_instance?: FuncNodesReactFlowZustandInterface
|
|
87
|
-
): PartialIOType => {
|
|
88
|
-
if (io.value === "<NoValue>") {
|
|
89
|
-
io.value = undefined;
|
|
90
|
-
}
|
|
91
|
-
if (io.fullvalue === "<NoValue>") {
|
|
92
|
-
io.fullvalue = undefined;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
if (io.try_get_full_value === undefined) {
|
|
96
|
-
io.try_get_full_value = () => {
|
|
97
|
-
if (!fnrf_instance) {
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
if (io.node === undefined || io.id === undefined) {
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
fnrf_instance.worker?.get_io_full_value({ nid: io.node, ioid: io.id });
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return io;
|
|
108
|
-
};
|
|
109
|
-
const assert_reactflow_node = (
|
|
110
|
-
node: NodeType,
|
|
111
|
-
store: NodeStore,
|
|
112
|
-
fnrf_instance?: FuncNodesReactFlowZustandInterface
|
|
113
|
-
): NodeType & RFNode => {
|
|
114
|
-
_fill_node_frontend(node, fnrf_instance);
|
|
115
|
-
|
|
116
|
-
if (node.id === undefined) {
|
|
117
|
-
throw new Error("Node must have an id");
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
for (const io in node.io) {
|
|
121
|
-
node.io[io].node = node.id;
|
|
122
|
-
assert_react_flow_io(node.io[io], fnrf_instance);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const extendedNode: NodeType & RFNode = {
|
|
126
|
-
position: {
|
|
127
|
-
x: node.frontend.pos[0],
|
|
128
|
-
y: node.frontend.pos[1],
|
|
129
|
-
},
|
|
130
|
-
data: {
|
|
131
|
-
UseNodeStore: store,
|
|
132
|
-
},
|
|
133
|
-
type: "default",
|
|
134
|
-
...node,
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
return extendedNode;
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
const FuncNodesReactFlowZustand = (): FuncNodesReactFlowZustandInterface => {
|
|
141
|
-
/*
|
|
142
|
-
function that should be called when the remote node, e.g. in the python worker is performing an action
|
|
143
|
-
*/
|
|
144
|
-
const on_node_action = (action: NodeAction) => {
|
|
145
|
-
const rfstate = rfstore.getState();
|
|
146
|
-
|
|
147
|
-
switch (action.type) {
|
|
148
|
-
case "add":
|
|
149
|
-
if (action.from_remote) {
|
|
150
|
-
let store = ns.get_node(action.node.id, false);
|
|
151
|
-
|
|
152
|
-
if (!store) {
|
|
153
|
-
try {
|
|
154
|
-
store = createNodeStore(action.node);
|
|
155
|
-
ns.nodesstates.set(action.node.id, store);
|
|
156
|
-
} catch (e) {
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
const new_ndoes = [
|
|
162
|
-
...rfstate.nodes,
|
|
163
|
-
assert_reactflow_node(action.node, store, iterf),
|
|
164
|
-
];
|
|
165
|
-
rfstore.setState({ nodes: new_ndoes });
|
|
166
|
-
}
|
|
167
|
-
break;
|
|
168
|
-
case "update":
|
|
169
|
-
// some action reset the error, so far trigger does, so errors should remove the in_trigger flag
|
|
170
|
-
if (action.node.in_trigger) {
|
|
171
|
-
action.node.error = undefined;
|
|
172
|
-
}
|
|
173
|
-
if (action.from_remote) {
|
|
174
|
-
const store = ns.get_node(action.id) as NodeStore;
|
|
175
|
-
|
|
176
|
-
if (action.node.io) {
|
|
177
|
-
for (const io in action.node.io) {
|
|
178
|
-
const ioobj = action.node.io[io] as PartialIOType;
|
|
179
|
-
// check if value in io, undefined is a valid value
|
|
180
|
-
if (ioobj.hasOwnProperty("value")) {
|
|
181
|
-
if (ioobj.value === undefined) {
|
|
182
|
-
ioobj.value = null;
|
|
183
|
-
} else if (ioobj.value === "<NoValue>") {
|
|
184
|
-
ioobj.value = undefined;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
const state = store.getState();
|
|
191
|
-
const { new_obj, change } = deep_merge(state, action.node);
|
|
192
|
-
|
|
193
|
-
if (change) {
|
|
194
|
-
if (action.node.io) {
|
|
195
|
-
for (const io in action.node.io) {
|
|
196
|
-
// if fullvalue is in the update data, set to fullvalue otherwise set to undefined
|
|
197
|
-
new_obj.io[io].fullvalue = action.node.io[io].fullvalue;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
assert_reactflow_node(new_obj, store, iterf);
|
|
202
|
-
|
|
203
|
-
store.setState(new_obj);
|
|
204
|
-
}
|
|
205
|
-
} else {
|
|
206
|
-
if (iterf.worker) {
|
|
207
|
-
iterf.worker.update_node(action);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
break;
|
|
211
|
-
case "delete":
|
|
212
|
-
if (action.from_remote) {
|
|
213
|
-
rfstore.getState().onNodesChange([
|
|
214
|
-
{
|
|
215
|
-
type: "remove",
|
|
216
|
-
id: action.id,
|
|
217
|
-
},
|
|
218
|
-
]);
|
|
219
|
-
} else {
|
|
220
|
-
iterf.worker?.remove_node(action.id);
|
|
221
|
-
}
|
|
222
|
-
break;
|
|
223
|
-
case "error":
|
|
224
|
-
console.error("Error", action);
|
|
225
|
-
on_node_action({
|
|
226
|
-
type: "update",
|
|
227
|
-
id: action.id,
|
|
228
|
-
node: {
|
|
229
|
-
in_trigger: false,
|
|
230
|
-
error: action.error,
|
|
231
|
-
},
|
|
232
|
-
from_remote: true,
|
|
233
|
-
});
|
|
234
|
-
break;
|
|
235
|
-
|
|
236
|
-
case "trigger":
|
|
237
|
-
if (action.from_remote) {
|
|
238
|
-
on_node_action({
|
|
239
|
-
type: "update",
|
|
240
|
-
id: action.id,
|
|
241
|
-
node: {
|
|
242
|
-
in_trigger: true,
|
|
243
|
-
error: undefined,
|
|
244
|
-
},
|
|
245
|
-
from_remote: true,
|
|
246
|
-
});
|
|
247
|
-
} else {
|
|
248
|
-
iterf.worker?.trigger_node(action.id);
|
|
249
|
-
}
|
|
250
|
-
break;
|
|
251
|
-
default:
|
|
252
|
-
console.error("Unknown node action", action);
|
|
253
|
-
}
|
|
254
|
-
};
|
|
255
|
-
|
|
256
|
-
const on_edge_action = (action: EdgeAction) => {
|
|
257
|
-
const rfstate = rfstore.getState();
|
|
258
|
-
|
|
259
|
-
switch (action.type) {
|
|
260
|
-
case "add":
|
|
261
|
-
if (action.from_remote) {
|
|
262
|
-
const edges = rfstate.edges;
|
|
263
|
-
const new_edge_id = generate_edge_id(action);
|
|
264
|
-
|
|
265
|
-
//cehck if edge already exists including reversed
|
|
266
|
-
if (edges.some((e) => e.id === new_edge_id)) {
|
|
267
|
-
return;
|
|
268
|
-
}
|
|
269
|
-
const new_edge: RFEdge = {
|
|
270
|
-
id: new_edge_id,
|
|
271
|
-
source: action.src_nid,
|
|
272
|
-
target: action.trg_nid,
|
|
273
|
-
sourceHandle: action.src_ioid,
|
|
274
|
-
targetHandle: action.trg_ioid,
|
|
275
|
-
className: "funcnodes-edge animated",
|
|
276
|
-
};
|
|
277
|
-
|
|
278
|
-
rfstore.setState({ edges: [...edges, new_edge] });
|
|
279
|
-
} else {
|
|
280
|
-
}
|
|
281
|
-
break;
|
|
282
|
-
|
|
283
|
-
case "delete":
|
|
284
|
-
if (action.from_remote) {
|
|
285
|
-
const edges = rfstate.edges;
|
|
286
|
-
const del_edge_id = generate_edge_id(action);
|
|
287
|
-
const new_edges = edges.filter((edge) => edge.id !== del_edge_id);
|
|
288
|
-
rfstore.setState({ edges: new_edges });
|
|
289
|
-
} else {
|
|
290
|
-
}
|
|
291
|
-
break;
|
|
292
|
-
default:
|
|
293
|
-
console.error("Unknown edge action", action);
|
|
294
|
-
}
|
|
295
|
-
};
|
|
296
|
-
/*
|
|
297
|
-
on_node_cahnge is called by react flow when a note change event is fired
|
|
298
|
-
should update the local state if something changed
|
|
299
|
-
*/
|
|
300
|
-
const on_node_change = (nodechange: NodeChange[]) => {
|
|
301
|
-
for (const change of nodechange) {
|
|
302
|
-
switch (change.type) {
|
|
303
|
-
case "position":
|
|
304
|
-
if (change.position) {
|
|
305
|
-
on_node_action({
|
|
306
|
-
type: "update",
|
|
307
|
-
id: change.id,
|
|
308
|
-
node: {
|
|
309
|
-
frontend: { pos: [change.position.x, change.position.y] },
|
|
310
|
-
},
|
|
311
|
-
from_remote: false,
|
|
312
|
-
});
|
|
313
|
-
}
|
|
314
|
-
break;
|
|
315
|
-
case "dimensions":
|
|
316
|
-
if (change.dimensions) {
|
|
317
|
-
on_node_action({
|
|
318
|
-
type: "update",
|
|
319
|
-
id: change.id,
|
|
320
|
-
node: {
|
|
321
|
-
frontend: {
|
|
322
|
-
size: [change.dimensions.width, change.dimensions.height],
|
|
323
|
-
},
|
|
324
|
-
},
|
|
325
|
-
from_remote: false,
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
break;
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
};
|
|
332
|
-
|
|
333
|
-
const on_edge_change = (edgechange: EdgeChange[]) => {};
|
|
334
|
-
|
|
335
|
-
const on_connect = (connection: RFConnection) => {
|
|
336
|
-
if (
|
|
337
|
-
connection.source === null ||
|
|
338
|
-
connection.target === null ||
|
|
339
|
-
connection.sourceHandle === null ||
|
|
340
|
-
connection.targetHandle === null ||
|
|
341
|
-
!iterf.worker
|
|
342
|
-
) {
|
|
343
|
-
return;
|
|
344
|
-
}
|
|
345
|
-
iterf.worker.add_edge({
|
|
346
|
-
src_nid: connection.source,
|
|
347
|
-
src_ioid: connection.sourceHandle,
|
|
348
|
-
trg_nid: connection.target,
|
|
349
|
-
trg_ioid: connection.targetHandle,
|
|
350
|
-
replace: true,
|
|
351
|
-
});
|
|
352
|
-
};
|
|
353
|
-
|
|
354
|
-
const rfstore = reactflowstore({
|
|
355
|
-
on_node_change,
|
|
356
|
-
on_edge_change,
|
|
357
|
-
on_connect,
|
|
358
|
-
});
|
|
359
|
-
const ns = NodeSpaceZustand({});
|
|
360
|
-
const lib = LibZustand();
|
|
361
|
-
|
|
362
|
-
const clear_all = () => {
|
|
363
|
-
iterf.worker?.disconnect();
|
|
364
|
-
iterf.worker = undefined;
|
|
365
|
-
iterf.workermanager?.setWorker(undefined);
|
|
366
|
-
iterf.lib.libstate.getState().set({ shelves: [] });
|
|
367
|
-
iterf.nodespace.nodesstates.clear();
|
|
368
|
-
iterf.useReactFlowStore.setState({ nodes: [], edges: [] });
|
|
369
|
-
iterf.auto_progress();
|
|
370
|
-
};
|
|
371
|
-
const iterf: FuncNodesReactFlowZustandInterface = {
|
|
372
|
-
lib: lib,
|
|
373
|
-
workermanager: undefined,
|
|
374
|
-
workers: create<WorkersState>((set, get) => ({})),
|
|
375
|
-
render_options: create<RenderOptions>((set, get) => ({})),
|
|
376
|
-
progress_state: create<ProgressState>((set, get) => ({
|
|
377
|
-
message: "please select worker",
|
|
378
|
-
status: "info",
|
|
379
|
-
progress: 0,
|
|
380
|
-
blocking: false,
|
|
381
|
-
})),
|
|
382
|
-
update_render_options: (options: RenderOptions) => {
|
|
383
|
-
const current = iterf.render_options.getState();
|
|
384
|
-
const { new_obj, change } = deep_merge(current, options);
|
|
385
|
-
if (change) {
|
|
386
|
-
iterf.render_options.setState(new_obj);
|
|
387
|
-
}
|
|
388
|
-
},
|
|
389
|
-
worker: undefined,
|
|
390
|
-
nodespace: ns,
|
|
391
|
-
useReactFlowStore: rfstore,
|
|
392
|
-
on_node_action: on_node_action,
|
|
393
|
-
on_edge_action: on_edge_action,
|
|
394
|
-
reactflowRef: null,
|
|
395
|
-
clear_all: clear_all,
|
|
396
|
-
set_progress: (progress: ProgressState) => {
|
|
397
|
-
if (progress.message === "") {
|
|
398
|
-
return iterf.auto_progress();
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
const prev_state = iterf.progress_state.getState();
|
|
402
|
-
const { new_obj, change } = deep_merge<ProgressState>(
|
|
403
|
-
prev_state,
|
|
404
|
-
progress
|
|
405
|
-
);
|
|
406
|
-
if (change) {
|
|
407
|
-
iterf.progress_state.setState(new_obj);
|
|
408
|
-
}
|
|
409
|
-
},
|
|
410
|
-
auto_progress: () => {
|
|
411
|
-
if (iterf.worker === undefined) {
|
|
412
|
-
return iterf.set_progress({
|
|
413
|
-
progress: 0,
|
|
414
|
-
message: "please select worker",
|
|
415
|
-
status: "error",
|
|
416
|
-
blocking: false,
|
|
417
|
-
});
|
|
418
|
-
}
|
|
419
|
-
if (!iterf.worker.is_open) {
|
|
420
|
-
return iterf.set_progress({
|
|
421
|
-
progress: 0,
|
|
422
|
-
message: "connecting to worker",
|
|
423
|
-
status: "info",
|
|
424
|
-
blocking: true,
|
|
425
|
-
});
|
|
426
|
-
}
|
|
427
|
-
iterf.set_progress({
|
|
428
|
-
progress: 1,
|
|
429
|
-
message: "running",
|
|
430
|
-
status: "info",
|
|
431
|
-
blocking: false,
|
|
432
|
-
});
|
|
433
|
-
},
|
|
434
|
-
};
|
|
435
|
-
return iterf;
|
|
436
|
-
};
|
|
437
|
-
|
|
438
|
-
export default FuncNodesReactFlowZustand;
|
|
439
|
-
export { LibZustand, NodeSpaceZustand };
|
|
440
|
-
export type { FuncNodesReactFlowZustandInterface, WorkersState };
|
package/src/state/index.ts
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import LibZustand, { LibZustandInterface } from "./lib";
|
|
2
|
-
import NodeSpaceZustand, { NodeSpaceZustandInterface } from "./nodespace";
|
|
3
|
-
import { FuncNodesReactFlowZustandInterface, WorkersState } from "./fnrfzst";
|
|
4
|
-
import FuncNodesReactFlowZustand from "./fnrfzst";
|
|
5
|
-
export default FuncNodesReactFlowZustand;
|
|
6
|
-
export { LibZustand, NodeSpaceZustand };
|
|
7
|
-
export type { FuncNodesReactFlowZustandInterface, WorkersState };
|
|
8
|
-
|
|
9
|
-
// Type alias for DeepPartial. It makes all properties of T optional and recursive.
|
|
10
|
-
type DeepPartial<T> = T extends object
|
|
11
|
-
? {
|
|
12
|
-
[P in keyof T]?: DeepPartial<T[P]>;
|
|
13
|
-
}
|
|
14
|
-
: T;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Checks if the given item is a plain object.
|
|
18
|
-
* @param item The item to check.
|
|
19
|
-
* @returns true if the item is a plain object, false otherwise.
|
|
20
|
-
*/
|
|
21
|
-
function isPlainObject(item: any): boolean {
|
|
22
|
-
return Object.prototype.toString.call(item) === "[object Object]";
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function deep_compare_objects(a: any, b: any): boolean {
|
|
26
|
-
// Check for strict equality first
|
|
27
|
-
if (a === b) return true;
|
|
28
|
-
|
|
29
|
-
// If either is null or not an object, they're not equal (strict equality would have caught `a === b` if both were null)
|
|
30
|
-
if (
|
|
31
|
-
typeof a !== "object" ||
|
|
32
|
-
a === null ||
|
|
33
|
-
typeof b !== "object" ||
|
|
34
|
-
b === null
|
|
35
|
-
)
|
|
36
|
-
return false;
|
|
37
|
-
|
|
38
|
-
// If they're not the same type of object, they're not equal
|
|
39
|
-
if (a.constructor !== b.constructor) return false;
|
|
40
|
-
|
|
41
|
-
if (a.constructor === Object || a.constructor === Array) {
|
|
42
|
-
const keysA = Object.keys(a);
|
|
43
|
-
const keysB = Object.keys(b);
|
|
44
|
-
|
|
45
|
-
// If their property lengths are different, they're different objects
|
|
46
|
-
if (keysA.length !== keysB.length) return false;
|
|
47
|
-
|
|
48
|
-
// Check each key in 'a' to ensure it exists in 'b' and is equal; recurse if value is an object
|
|
49
|
-
for (const key of keysA) {
|
|
50
|
-
if (!keysB.includes(key)) return false;
|
|
51
|
-
if (!deep_compare_objects(a[key], b[key])) return false;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// Dates comparison
|
|
56
|
-
if (a instanceof Date && b instanceof Date)
|
|
57
|
-
return a.getTime() === b.getTime();
|
|
58
|
-
|
|
59
|
-
// If we've made it this far, objects must be considered equal
|
|
60
|
-
return true;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
*
|
|
65
|
-
* function to deeply merge two objects of type T.
|
|
66
|
-
*
|
|
67
|
-
* @param {T} target - The target object to be merged.
|
|
68
|
-
* @param {DeepPartial<T>} source - The source object to merge into the target. All properties of this object are optional.
|
|
69
|
-
*
|
|
70
|
-
* @returns {T} An object containing the merged object (new_obj) and a boolean indicating if there was a change (change).
|
|
71
|
-
*/
|
|
72
|
-
const deep_merge = <T extends {}>(
|
|
73
|
-
target: T,
|
|
74
|
-
source: DeepPartial<T>
|
|
75
|
-
): {
|
|
76
|
-
new_obj: T;
|
|
77
|
-
change: boolean;
|
|
78
|
-
} => {
|
|
79
|
-
let change = false;
|
|
80
|
-
if (!isPlainObject(target)) {
|
|
81
|
-
throw new Error("Target must be a plain object");
|
|
82
|
-
}
|
|
83
|
-
if (!isPlainObject(source)) {
|
|
84
|
-
throw new Error("Source must be a plain object");
|
|
85
|
-
}
|
|
86
|
-
const new_obj: T = { ...target };
|
|
87
|
-
|
|
88
|
-
Object.keys(source).forEach((key) => {
|
|
89
|
-
// @ts-ignore: Type 'string' cannot be used to index type 'T
|
|
90
|
-
const sourceValue = source[key];
|
|
91
|
-
// @ts-ignore: Type 'string' cannot be used to index type 'T
|
|
92
|
-
const targetValue = target[key];
|
|
93
|
-
|
|
94
|
-
if (isPlainObject(sourceValue) && isPlainObject(targetValue)) {
|
|
95
|
-
// If both the target and source values are plain objects, merge them
|
|
96
|
-
const { new_obj: mergedObj, change: didChange } = deep_merge(
|
|
97
|
-
targetValue,
|
|
98
|
-
sourceValue
|
|
99
|
-
);
|
|
100
|
-
if (didChange) {
|
|
101
|
-
change = true;
|
|
102
|
-
// @ts-ignore: Type 'string' cannot be used to index type 'T
|
|
103
|
-
new_obj[key] = mergedObj;
|
|
104
|
-
}
|
|
105
|
-
} else if (!deep_compare_objects(targetValue, sourceValue)) {
|
|
106
|
-
change = true;
|
|
107
|
-
// @ts-ignore: Type 'string' cannot be used to index type 'T
|
|
108
|
-
new_obj[key] = sourceValue;
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
return { new_obj, change };
|
|
113
|
-
|
|
114
|
-
// for (const key in source) {
|
|
115
|
-
// // @ts-ignore: Type 'string' cannot be used to index type 'T
|
|
116
|
-
// if (typeof source[key] === "object" && target[key]) {
|
|
117
|
-
// const { new_obj: new_obj2, change: change2 } = deep_merge(
|
|
118
|
-
// // @ts-ignore: Type 'string' cannot be used to index type 'T
|
|
119
|
-
// target[key],
|
|
120
|
-
// source[key]
|
|
121
|
-
// );
|
|
122
|
-
// if (change2) {
|
|
123
|
-
// change = true;
|
|
124
|
-
// // @ts-ignore: Type 'string' cannot be used to index type 'T
|
|
125
|
-
// new_obj[key] = new_obj2;
|
|
126
|
-
// }
|
|
127
|
-
// } else {
|
|
128
|
-
// // @ts-ignore: Type 'string' cannot be used to index type 'T'
|
|
129
|
-
// if (target[key] !== source[key]) {
|
|
130
|
-
// change = true;
|
|
131
|
-
// }
|
|
132
|
-
// // @ts-ignore: Type 'string' cannot be used to index type 'T'
|
|
133
|
-
// new_obj[key] = source[key];
|
|
134
|
-
// }
|
|
135
|
-
// }
|
|
136
|
-
// return { new_obj, change };
|
|
137
|
-
};
|
|
138
|
-
export { deep_merge, deep_compare_objects };
|
|
139
|
-
export type { DeepPartial };
|
package/src/state/lib.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { useStore, create, UseBoundStore, StoreApi } from "zustand";
|
|
2
|
-
|
|
3
|
-
interface LibState {
|
|
4
|
-
state: LibType;
|
|
5
|
-
set: (state: LibType) => void;
|
|
6
|
-
get: () => LibType;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
interface LibZustandInterface {
|
|
10
|
-
libstate: UseBoundStore<StoreApi<LibState>>;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const LibZustand = (): LibZustandInterface => {
|
|
14
|
-
return {
|
|
15
|
-
libstate: create<LibState>((set, get) => ({
|
|
16
|
-
state: {
|
|
17
|
-
shelves: [],
|
|
18
|
-
},
|
|
19
|
-
set: (state: LibType) => set({ state: state }),
|
|
20
|
-
get: () => get().state,
|
|
21
|
-
})),
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export default LibZustand;
|
|
26
|
-
export type { LibZustandInterface, LibState };
|