@xyo-network/react-node 2.78.0 → 2.78.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/browser/index.cjs +464 -1
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.js +440 -1
- package/dist/browser/index.js.map +1 -1
- package/dist/neutral/index.cjs +464 -1
- package/dist/neutral/index.cjs.map +1 -1
- package/dist/neutral/index.js +440 -1
- package/dist/neutral/index.js.map +1 -1
- package/dist/node/index.cjs +495 -1
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.js +446 -1
- package/dist/node/index.js.map +1 -1
- package/package.json +20 -20
package/dist/node/index.js
CHANGED
|
@@ -1,2 +1,447 @@
|
|
|
1
|
-
|
|
1
|
+
// src/components/NodeDescriptionBox.tsx
|
|
2
|
+
import { FlexCol } from "@xylabs/react-flexbox";
|
|
3
|
+
|
|
4
|
+
// src/hooks/ModuleFromNodeConfig.ts
|
|
5
|
+
var useModuleFromNodeConfigLogger = (config) => {
|
|
6
|
+
return config == null ? void 0 : config.logger;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
// src/hooks/provided/useProvidedNode.tsx
|
|
10
|
+
import { NodeContext } from "@xyo-network/react-node-context";
|
|
11
|
+
import { useContext } from "react";
|
|
12
|
+
var useProvidedNode = () => {
|
|
13
|
+
const { node } = useContext(NodeContext);
|
|
14
|
+
return [node];
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// src/hooks/provided/useWeakProvidedNode.tsx
|
|
18
|
+
import { NodeContext as NodeContext2 } from "@xyo-network/react-node-context";
|
|
19
|
+
import { useContext as useContext2, useMemo } from "react";
|
|
20
|
+
var useWeakProvidedNode = () => {
|
|
21
|
+
const { node } = useContext2(NodeContext2);
|
|
22
|
+
const weakNode = useMemo(() => node ? new WeakRef(node) : null, [node]);
|
|
23
|
+
return [weakNode];
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// src/hooks/useModuleFilterOptions.ts
|
|
27
|
+
var useModuleFilterOptions = (config) => {
|
|
28
|
+
const { direction, identity, maxDepth } = config ?? {};
|
|
29
|
+
return { direction, identity, maxDepth };
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// src/hooks/useModuleFromNode.ts
|
|
33
|
+
import { usePromise as usePromise2 } from "@xylabs/react-promise";
|
|
34
|
+
import { isModuleInstance } from "@xyo-network/module-model";
|
|
35
|
+
import { useState } from "react";
|
|
36
|
+
|
|
37
|
+
// src/hooks/useNode.ts
|
|
38
|
+
import { usePromise } from "@xylabs/react-promise";
|
|
39
|
+
import { asNodeInstance } from "@xyo-network/node-model";
|
|
40
|
+
|
|
41
|
+
// src/hooks/useNodeConfigNodeField.ts
|
|
42
|
+
import { useMemo as useMemo2 } from "react";
|
|
43
|
+
var useNodeConfigNodeField = (config) => {
|
|
44
|
+
const nodeAddress = useMemo2(() => typeof (config == null ? void 0 : config.node) === "string" ? config == null ? void 0 : config.node : void 0, [config == null ? void 0 : config.node]);
|
|
45
|
+
const nodeInstance = useMemo2(() => typeof (config == null ? void 0 : config.node) === "object" ? config == null ? void 0 : config.node : void 0, [config == null ? void 0 : config.node]);
|
|
46
|
+
return [nodeAddress, nodeInstance];
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// src/hooks/useNode.ts
|
|
50
|
+
var useNode = (config) => {
|
|
51
|
+
const [nodeAddress, nodeInstance] = useNodeConfigNodeField(config);
|
|
52
|
+
const [providedNode] = useProvidedNode();
|
|
53
|
+
const [nodeAddressNode, error] = usePromise(async () => {
|
|
54
|
+
if (providedNode && nodeAddress) {
|
|
55
|
+
return asNodeInstance(await providedNode.resolve(nodeAddress), "Module is not a node");
|
|
56
|
+
}
|
|
57
|
+
}, [providedNode, nodeAddress]);
|
|
58
|
+
return [nodeAddressNode ?? nodeInstance ?? providedNode ?? void 0, error];
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
// src/hooks/useModuleFromNode.ts
|
|
62
|
+
var useModuleFromNode = (nameOrAddressOrInstance = void 0, config) => {
|
|
63
|
+
const [node, nodeError] = useNode(config);
|
|
64
|
+
const logger = useModuleFromNodeConfigLogger(config);
|
|
65
|
+
const filterOptions = useModuleFilterOptions(config);
|
|
66
|
+
const [result, setResult] = useState();
|
|
67
|
+
const [, error] = usePromise2(async () => {
|
|
68
|
+
logger == null ? void 0 : logger.debug("useModuleFromNode: resolving");
|
|
69
|
+
const identity = (config == null ? void 0 : config.identity) ?? isModuleInstance;
|
|
70
|
+
if (node && nameOrAddressOrInstance) {
|
|
71
|
+
node.on("moduleAttached", ({ module: mod }) => {
|
|
72
|
+
var _a;
|
|
73
|
+
logger == null ? void 0 : logger.debug(`useModuleFromNode: moduleAttached [${mod.config.name ?? mod.address}]`);
|
|
74
|
+
if (mod.address === nameOrAddressOrInstance || ((_a = mod.config) == null ? void 0 : _a.name) === nameOrAddressOrInstance) {
|
|
75
|
+
setResult(identity(mod) ? mod : void 0);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
node.on("moduleDetached", ({ module: mod }) => {
|
|
79
|
+
var _a;
|
|
80
|
+
logger == null ? void 0 : logger.debug(`useModuleFromNode: moduleDetached [${mod.config.name ?? mod.address}]`);
|
|
81
|
+
if (mod.address === nameOrAddressOrInstance || ((_a = mod.config) == null ? void 0 : _a.name) === nameOrAddressOrInstance) {
|
|
82
|
+
setResult(void 0);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
if (identity(nameOrAddressOrInstance)) {
|
|
86
|
+
setResult(nameOrAddressOrInstance);
|
|
87
|
+
} else {
|
|
88
|
+
const result2 = await node.resolve(nameOrAddressOrInstance, filterOptions);
|
|
89
|
+
logger == null ? void 0 : logger.debug(`Result: ${result2 == null ? void 0 : result2.address}`);
|
|
90
|
+
setResult(identity(result2) ? result2 : void 0);
|
|
91
|
+
}
|
|
92
|
+
return result;
|
|
93
|
+
}
|
|
94
|
+
logger == null ? void 0 : logger.debug("Result: No Node");
|
|
95
|
+
return;
|
|
96
|
+
}, [node, nameOrAddressOrInstance]);
|
|
97
|
+
return [result, nodeError ?? error];
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
// src/hooks/useModulesFromNode.ts
|
|
101
|
+
import { usePromise as usePromise3 } from "@xylabs/react-promise";
|
|
102
|
+
import { useState as useState2 } from "react";
|
|
103
|
+
var useModulesFromNode = (filter, config) => {
|
|
104
|
+
const [node, nodeError] = useNode(config);
|
|
105
|
+
const logger = config == null ? void 0 : config.logger;
|
|
106
|
+
const filterOptions = useModuleFilterOptions();
|
|
107
|
+
const [result, setResult] = useState2();
|
|
108
|
+
const [, error] = usePromise3(async () => {
|
|
109
|
+
logger == null ? void 0 : logger.debug("useModuleFromNode: resolving");
|
|
110
|
+
if (node) {
|
|
111
|
+
node.on("moduleAttached", async ({ module: mod }) => {
|
|
112
|
+
logger == null ? void 0 : logger.debug(`useModuleFromNode: moduleAttached [${mod.config.name ?? mod.address}]`);
|
|
113
|
+
const moduleInstances2 = filter ? await node.resolve(filter, filterOptions) : await node.resolve("*", filterOptions);
|
|
114
|
+
setResult(moduleInstances2);
|
|
115
|
+
});
|
|
116
|
+
node.on("moduleDetached", async ({ module: mod }) => {
|
|
117
|
+
logger == null ? void 0 : logger.debug(`useModuleFromNode: moduleDetached [${mod.config.name ?? mod.address}]`);
|
|
118
|
+
const moduleInstances2 = filter ? await node.resolve(filter, filterOptions) : await node.resolve("*", filterOptions);
|
|
119
|
+
setResult(moduleInstances2);
|
|
120
|
+
});
|
|
121
|
+
const moduleInstances = filter ? await node.resolve(filter, filterOptions) : await node.resolve("*", filterOptions);
|
|
122
|
+
setResult(moduleInstances);
|
|
123
|
+
return moduleInstances;
|
|
124
|
+
}
|
|
125
|
+
console.log("Result: No Node");
|
|
126
|
+
return;
|
|
127
|
+
}, [node, filter]);
|
|
128
|
+
return [result, nodeError ?? error];
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// src/hooks/useNodeDescription.ts
|
|
132
|
+
import { usePromise as usePromise4 } from "@xylabs/react-promise";
|
|
133
|
+
import { ModuleDescriptionSchema } from "@xyo-network/module-model";
|
|
134
|
+
import { isPayloadOfSchemaType } from "@xyo-network/payload-model";
|
|
135
|
+
var useNodeDescription = (config) => {
|
|
136
|
+
const [activeNode, nodeError] = useNode(config);
|
|
137
|
+
const [description, error] = usePromise4(async () => {
|
|
138
|
+
const state = await (activeNode == null ? void 0 : activeNode.state());
|
|
139
|
+
return state == null ? void 0 : state.find(isPayloadOfSchemaType(ModuleDescriptionSchema));
|
|
140
|
+
}, [activeNode]);
|
|
141
|
+
return [description, nodeError ?? error];
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
// src/hooks/useNodeFromNode.tsx
|
|
145
|
+
import { asNodeInstance as asNodeInstance2 } from "@xyo-network/node-model";
|
|
146
|
+
var useNodeFromNode = (nameOrAddressOrInstance, config) => {
|
|
147
|
+
var _a, _b;
|
|
148
|
+
const [mod, error] = useModuleFromNode(nameOrAddressOrInstance, config);
|
|
149
|
+
const instance = asNodeInstance2(mod);
|
|
150
|
+
if (mod && !instance) {
|
|
151
|
+
const error2 = new Error(`Resolved module is not a NodeInstance [${(_a = mod.config) == null ? void 0 : _a.schema}:${(_b = mod.config) == null ? void 0 : _b.name}:${mod.address}]`);
|
|
152
|
+
console.error(error2.message);
|
|
153
|
+
return [void 0, error2];
|
|
154
|
+
}
|
|
155
|
+
return [instance, error];
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
// src/hooks/useNodesFromNode.tsx
|
|
159
|
+
import { isNodeInstance } from "@xyo-network/node-model";
|
|
160
|
+
var useNodesFromNode = (filter, config) => {
|
|
161
|
+
const [modules, error] = useModulesFromNode(filter, config);
|
|
162
|
+
if (error) {
|
|
163
|
+
return [null, error];
|
|
164
|
+
}
|
|
165
|
+
return modules ? [
|
|
166
|
+
// eslint-disable-next-line unicorn/no-array-reduce
|
|
167
|
+
modules.reduce((prev, mod) => {
|
|
168
|
+
if (isNodeInstance(mod)) {
|
|
169
|
+
prev.push(mod);
|
|
170
|
+
}
|
|
171
|
+
return prev;
|
|
172
|
+
}, []),
|
|
173
|
+
void 0
|
|
174
|
+
] : [modules, error];
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
// src/hooks/useWeakModuleFilterOptions.ts
|
|
178
|
+
var useWeakModuleFilterOptions = (config) => {
|
|
179
|
+
const { direction, identity, maxDepth } = config ?? {};
|
|
180
|
+
return { direction, identity, maxDepth };
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
// src/hooks/useWeakModuleFromNode.ts
|
|
184
|
+
import { usePromise as usePromise6 } from "@xylabs/react-promise";
|
|
185
|
+
import { isModuleInstance as isModuleInstance2 } from "@xyo-network/module-model";
|
|
186
|
+
import { useState as useState3 } from "react";
|
|
187
|
+
|
|
188
|
+
// src/hooks/useWeakNode.ts
|
|
189
|
+
import { usePromise as usePromise5 } from "@xylabs/react-promise";
|
|
190
|
+
import { asNodeInstance as asNodeInstance3 } from "@xyo-network/node-model";
|
|
191
|
+
|
|
192
|
+
// src/hooks/useWeakNodeConfigNodeField.ts
|
|
193
|
+
import { useMemo as useMemo3 } from "react";
|
|
194
|
+
var useWeakNodeConfigNodeField = (config) => {
|
|
195
|
+
const nodeAddress = useMemo3(() => typeof (config == null ? void 0 : config.node) === "string" ? config == null ? void 0 : config.node : void 0, [config == null ? void 0 : config.node]);
|
|
196
|
+
const nodeInstance = useMemo3(() => typeof (config == null ? void 0 : config.node) === "object" ? config == null ? void 0 : config.node : void 0, [config == null ? void 0 : config.node]);
|
|
197
|
+
return [nodeAddress, nodeInstance];
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
// src/hooks/useWeakNode.ts
|
|
201
|
+
var useWeakNode = (config) => {
|
|
202
|
+
const [nodeAddress, nodeInstance] = useWeakNodeConfigNodeField(config);
|
|
203
|
+
const [providedNode] = useWeakProvidedNode();
|
|
204
|
+
const [nodeAddressNode, error] = usePromise5(async () => {
|
|
205
|
+
const providedNodeInstance = providedNode == null ? void 0 : providedNode.deref();
|
|
206
|
+
if (providedNodeInstance && nodeAddress) {
|
|
207
|
+
return new WeakRef(asNodeInstance3(await providedNodeInstance.resolve(nodeAddress), "Module is not a node"));
|
|
208
|
+
}
|
|
209
|
+
}, [providedNode, nodeAddress]);
|
|
210
|
+
return [nodeAddressNode ?? nodeInstance ?? providedNode ?? void 0, error];
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
// src/hooks/WeakModuleFromNodeConfig.ts
|
|
214
|
+
var useWeakModuleFromNodeConfigLogger = (config) => {
|
|
215
|
+
return config == null ? void 0 : config.logger;
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
// src/hooks/useWeakModuleFromNode.ts
|
|
219
|
+
var useWeakModuleFromNode = (nameOrAddressOrInstance = void 0, config) => {
|
|
220
|
+
const [node, nodeError] = useWeakNode(config);
|
|
221
|
+
const logger = useWeakModuleFromNodeConfigLogger(config);
|
|
222
|
+
const filterOptions = useWeakModuleFilterOptions(config);
|
|
223
|
+
const [result, setResult] = useState3();
|
|
224
|
+
const [, error] = usePromise6(async () => {
|
|
225
|
+
logger == null ? void 0 : logger.debug("useModuleFromNode: resolving");
|
|
226
|
+
const identity = (config == null ? void 0 : config.identity) ?? isModuleInstance2;
|
|
227
|
+
const nodeInstance = node == null ? void 0 : node.deref();
|
|
228
|
+
if (nodeInstance && nameOrAddressOrInstance) {
|
|
229
|
+
nodeInstance.on("moduleAttached", ({ module: mod }) => {
|
|
230
|
+
var _a;
|
|
231
|
+
logger == null ? void 0 : logger.debug(`useModuleFromNode: moduleAttached [${mod.config.name ?? mod.address}]`);
|
|
232
|
+
if (mod.address === nameOrAddressOrInstance || ((_a = mod.config) == null ? void 0 : _a.name) === nameOrAddressOrInstance) {
|
|
233
|
+
setResult(identity(mod) ? new WeakRef(mod) : void 0);
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
nodeInstance.on("moduleDetached", ({ module: mod }) => {
|
|
237
|
+
var _a;
|
|
238
|
+
logger == null ? void 0 : logger.debug(`useModuleFromNode: moduleDetached [${mod.config.name ?? mod.address}]`);
|
|
239
|
+
if (mod.address === nameOrAddressOrInstance || ((_a = mod.config) == null ? void 0 : _a.name) === nameOrAddressOrInstance) {
|
|
240
|
+
setResult(void 0);
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
if (identity(nameOrAddressOrInstance)) {
|
|
244
|
+
setResult(new WeakRef(nameOrAddressOrInstance));
|
|
245
|
+
} else {
|
|
246
|
+
const result2 = await nodeInstance.resolve(nameOrAddressOrInstance, filterOptions);
|
|
247
|
+
logger == null ? void 0 : logger.debug(`Result: ${result2 == null ? void 0 : result2.address}`);
|
|
248
|
+
setResult(identity(result2) ? new WeakRef(result2) : void 0);
|
|
249
|
+
}
|
|
250
|
+
return result;
|
|
251
|
+
}
|
|
252
|
+
logger == null ? void 0 : logger.debug("Result: No Node");
|
|
253
|
+
return;
|
|
254
|
+
}, [node, nameOrAddressOrInstance]);
|
|
255
|
+
return [result, nodeError ?? error];
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
// src/hooks/useWeakModulesFromNode.ts
|
|
259
|
+
import { usePromise as usePromise7 } from "@xylabs/react-promise";
|
|
260
|
+
import { useState as useState4 } from "react";
|
|
261
|
+
var useWeakModulesFromNode = (filter, config) => {
|
|
262
|
+
const [node, nodeError] = useNode(config);
|
|
263
|
+
const logger = config == null ? void 0 : config.logger;
|
|
264
|
+
const filterOptions = useModuleFilterOptions();
|
|
265
|
+
const [result, setResult] = useState4();
|
|
266
|
+
const [, error] = usePromise7(async () => {
|
|
267
|
+
logger == null ? void 0 : logger.debug("useModuleFromNode: resolving");
|
|
268
|
+
const nodeInstance = node;
|
|
269
|
+
if (nodeInstance) {
|
|
270
|
+
nodeInstance.on("moduleAttached", async ({ module: mod }) => {
|
|
271
|
+
const nodeInstance2 = node;
|
|
272
|
+
logger == null ? void 0 : logger.debug(`useModuleFromNode: moduleAttached [${mod.config.name ?? mod.address}]`);
|
|
273
|
+
const moduleInstances2 = filter ? await (nodeInstance2 == null ? void 0 : nodeInstance2.resolve(filter, filterOptions)) : await (nodeInstance2 == null ? void 0 : nodeInstance2.resolve("*", filterOptions));
|
|
274
|
+
setResult(moduleInstances2 == null ? void 0 : moduleInstances2.map((mod2) => new WeakRef(mod2)));
|
|
275
|
+
});
|
|
276
|
+
nodeInstance.on("moduleDetached", async ({ module: mod }) => {
|
|
277
|
+
const nodeInstance2 = node;
|
|
278
|
+
logger == null ? void 0 : logger.debug(`useModuleFromNode: moduleDetached [${mod.config.name ?? mod.address}]`);
|
|
279
|
+
const moduleInstances2 = filter ? await (nodeInstance2 == null ? void 0 : nodeInstance2.resolve(filter, filterOptions)) : await (nodeInstance2 == null ? void 0 : nodeInstance2.resolve("*", filterOptions));
|
|
280
|
+
setResult(moduleInstances2 == null ? void 0 : moduleInstances2.map((mod2) => new WeakRef(mod2)));
|
|
281
|
+
});
|
|
282
|
+
const moduleInstances = filter ? await nodeInstance.resolve(filter, filterOptions) : await nodeInstance.resolve("*", filterOptions);
|
|
283
|
+
setResult(moduleInstances == null ? void 0 : moduleInstances.map((mod) => new WeakRef(mod)));
|
|
284
|
+
return moduleInstances;
|
|
285
|
+
}
|
|
286
|
+
console.log("Result: No Node");
|
|
287
|
+
return;
|
|
288
|
+
}, [node, filter]);
|
|
289
|
+
return [result, nodeError ?? error];
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
// src/hooks/useWeakNodeDescription.ts
|
|
293
|
+
import { usePromise as usePromise8 } from "@xylabs/react-promise";
|
|
294
|
+
import { ModuleDescriptionSchema as ModuleDescriptionSchema2 } from "@xyo-network/module-model";
|
|
295
|
+
import { isPayloadOfSchemaType as isPayloadOfSchemaType2 } from "@xyo-network/payload-model";
|
|
296
|
+
var useWeakNodeDescription = (config) => {
|
|
297
|
+
const [activeNode, nodeError] = useWeakNode(config);
|
|
298
|
+
const [description, error] = usePromise8(async () => {
|
|
299
|
+
var _a;
|
|
300
|
+
const state = await ((_a = activeNode == null ? void 0 : activeNode.deref()) == null ? void 0 : _a.state());
|
|
301
|
+
return state == null ? void 0 : state.find(isPayloadOfSchemaType2(ModuleDescriptionSchema2));
|
|
302
|
+
}, [activeNode]);
|
|
303
|
+
return [description, nodeError ?? error];
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
// src/hooks/useWeakNodeFromNode.tsx
|
|
307
|
+
import { isNodeInstance as isNodeInstance2 } from "@xyo-network/node-model";
|
|
308
|
+
var useWeakNodeFromNode = (nameOrAddressOrInstance, config) => {
|
|
309
|
+
return useWeakModuleFromNode(nameOrAddressOrInstance, { identity: isNodeInstance2, ...config });
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
// src/components/NodeDescriptionBox.tsx
|
|
313
|
+
import { jsx } from "react/jsx-runtime";
|
|
314
|
+
var NodeDescriptionBox = ({ node, ...props }) => {
|
|
315
|
+
const [description, error] = useWeakNodeDescription({ node });
|
|
316
|
+
return /* @__PURE__ */ jsx(FlexCol, { ...props, children: /* @__PURE__ */ jsx("code", { color: error ? "red" : void 0, children: error ? error.message : JSON.stringify(description, null, 2) }) });
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
// src/components/Node.tsx
|
|
320
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
321
|
+
var NodeBox = ({ variant, ...props }) => {
|
|
322
|
+
switch (variant) {
|
|
323
|
+
case "description":
|
|
324
|
+
default: {
|
|
325
|
+
return /* @__PURE__ */ jsx2(NodeDescriptionBox, { ...props });
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
// src/components/NodeDrawer.tsx
|
|
331
|
+
import { Close as CloseIcon } from "@mui/icons-material";
|
|
332
|
+
import { ClickAwayListener, Drawer, IconButton } from "@mui/material";
|
|
333
|
+
import { FlexGrowCol, FlexRow } from "@xylabs/react-flexbox";
|
|
334
|
+
import { useNodeDrawer } from "@xyo-network/react-node-provider";
|
|
335
|
+
|
|
336
|
+
// src/components/render/ModuleDescriptionBox.tsx
|
|
337
|
+
import { ChevronRight as ChevronRightIcon, ExpandMore as ExpandMoreIcon } from "@mui/icons-material";
|
|
338
|
+
import { styled as styled2, Typography } from "@mui/material";
|
|
339
|
+
import { TreeView } from "@mui/x-tree-view";
|
|
340
|
+
import { useRef } from "react";
|
|
341
|
+
|
|
342
|
+
// src/components/render/RenderModule.tsx
|
|
343
|
+
import { styled } from "@mui/material";
|
|
344
|
+
import { TreeItem } from "@mui/x-tree-view";
|
|
345
|
+
import { useAsyncEffect } from "@xylabs/react-async-effect";
|
|
346
|
+
import { useState as useState5 } from "react";
|
|
347
|
+
import { jsx as jsx3, jsxs } from "react/jsx-runtime";
|
|
348
|
+
var RenderModule = ({ mod, idRef }) => {
|
|
349
|
+
const [childModules, setChildModules] = useState5();
|
|
350
|
+
useAsyncEffect(
|
|
351
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
352
|
+
async (mounted) => {
|
|
353
|
+
const moduleInstance2 = mod.deref();
|
|
354
|
+
const { address: address2 } = moduleInstance2 ?? {};
|
|
355
|
+
if (moduleInstance2) {
|
|
356
|
+
const children = (await moduleInstance2.resolve("*")).filter((childModule) => childModule.address !== address2);
|
|
357
|
+
if (mounted()) {
|
|
358
|
+
setChildModules(children.map((childModule) => new WeakRef(childModule)));
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
},
|
|
362
|
+
[mod]
|
|
363
|
+
);
|
|
364
|
+
const increment = () => {
|
|
365
|
+
const newId = (idRef.current.idIncrementor++).toString();
|
|
366
|
+
idRef.current.ids.push(newId);
|
|
367
|
+
return newId;
|
|
368
|
+
};
|
|
369
|
+
const moduleInstance = mod.deref();
|
|
370
|
+
const { queries, address } = moduleInstance ?? {};
|
|
371
|
+
return /* @__PURE__ */ jsxs(StyledAddressTreeItem, { nodeId: increment(), label: `address: ${address}`, children: [
|
|
372
|
+
queries == null ? void 0 : queries.map((query, index) => {
|
|
373
|
+
return /* @__PURE__ */ jsx3(TreeItem, { nodeId: increment(), label: `query : ${query}`, sx: { mb: index === queries.length - 1 ? 1.5 : 0.5 } }, query);
|
|
374
|
+
}),
|
|
375
|
+
childModules && childModules.length > 0 ? /* @__PURE__ */ jsx3(TreeItem, { nodeId: increment(), label: "children", sx: { mb: 0.5 }, children: childModules.map((childModuleRef) => {
|
|
376
|
+
const childModule = childModuleRef.deref();
|
|
377
|
+
return childModule ? /* @__PURE__ */ jsx3(RenderModule, { mod: childModuleRef, idRef }, childModule == null ? void 0 : childModule.address) : null;
|
|
378
|
+
}) }) : null
|
|
379
|
+
] });
|
|
380
|
+
};
|
|
381
|
+
var StyledAddressTreeItem = styled(TreeItem, { name: "StyledAddressTreeItem" })(({ theme }) => ({
|
|
382
|
+
"& .MuiTreeItem-content": {
|
|
383
|
+
marginBottom: theme.spacing(0.25)
|
|
384
|
+
}
|
|
385
|
+
}));
|
|
386
|
+
|
|
387
|
+
// src/components/render/ModuleDescriptionBox.tsx
|
|
388
|
+
import { Fragment, jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
389
|
+
var ModuleDescriptionBox = ({ mod }) => {
|
|
390
|
+
const idRef = useRef({ idIncrementor: 0, ids: [] });
|
|
391
|
+
return /* @__PURE__ */ jsx4(Fragment, { children: mod ? /* @__PURE__ */ jsxs2(Fragment, { children: [
|
|
392
|
+
/* @__PURE__ */ jsx4(Typography, { variant: "h4", children: "Node Configuration" }),
|
|
393
|
+
/* @__PURE__ */ jsx4(
|
|
394
|
+
StyledTreeView,
|
|
395
|
+
{
|
|
396
|
+
"aria-label": "file system navigator",
|
|
397
|
+
defaultCollapseIcon: /* @__PURE__ */ jsx4(ExpandMoreIcon, {}),
|
|
398
|
+
defaultExpandIcon: /* @__PURE__ */ jsx4(ChevronRightIcon, {}),
|
|
399
|
+
sx: { flexGrow: 1 },
|
|
400
|
+
children: /* @__PURE__ */ jsx4(RenderModule, { mod, idRef })
|
|
401
|
+
}
|
|
402
|
+
)
|
|
403
|
+
] }) : mod === null ? /* @__PURE__ */ jsx4(Typography, { variant: "h4", children: "Node loading..." }) : /* @__PURE__ */ jsx4(Typography, { variant: "h4", children: "Node not found" }) });
|
|
404
|
+
};
|
|
405
|
+
var StyledTreeView = styled2(TreeView, { name: "StyledTreeView" })(() => ({
|
|
406
|
+
height: "auto",
|
|
407
|
+
maxWidth: "auto"
|
|
408
|
+
}));
|
|
409
|
+
|
|
410
|
+
// src/components/NodeDrawer.tsx
|
|
411
|
+
import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
412
|
+
var NodeDrawer = ({ children, ...props }) => {
|
|
413
|
+
const { open, setOpen } = useNodeDrawer();
|
|
414
|
+
const [node] = useWeakProvidedNode();
|
|
415
|
+
return /* @__PURE__ */ jsx5(Drawer, { open: open ?? false, anchor: "right", ...props, children: /* @__PURE__ */ jsx5(ClickAwayListener, { onClickAway: () => setOpen == null ? void 0 : setOpen(false), children: /* @__PURE__ */ jsxs3(FlexGrowCol, { role: "presentation", justifyContent: "start", p: 2, rowGap: 2, minWidth: "33vw", children: [
|
|
416
|
+
/* @__PURE__ */ jsx5(FlexRow, { alignContent: "start", justifyContent: "start", width: "100%", children: /* @__PURE__ */ jsx5(IconButton, { onClick: () => setOpen == null ? void 0 : setOpen(false), children: /* @__PURE__ */ jsx5(CloseIcon, {}) }) }),
|
|
417
|
+
/* @__PURE__ */ jsx5(ModuleDescriptionBox, { mod: node }),
|
|
418
|
+
children
|
|
419
|
+
] }) }) });
|
|
420
|
+
};
|
|
421
|
+
|
|
422
|
+
// src/index.ts
|
|
423
|
+
export * from "@xyo-network/react-node-context";
|
|
424
|
+
export * from "@xyo-network/react-node-provider";
|
|
425
|
+
export {
|
|
426
|
+
NodeBox,
|
|
427
|
+
NodeDrawer,
|
|
428
|
+
useModuleFilterOptions,
|
|
429
|
+
useModuleFromNode,
|
|
430
|
+
useModuleFromNodeConfigLogger,
|
|
431
|
+
useModulesFromNode,
|
|
432
|
+
useNode,
|
|
433
|
+
useNodeConfigNodeField,
|
|
434
|
+
useNodeDescription,
|
|
435
|
+
useNodeFromNode,
|
|
436
|
+
useNodesFromNode,
|
|
437
|
+
useProvidedNode,
|
|
438
|
+
useWeakModuleFilterOptions,
|
|
439
|
+
useWeakModuleFromNode,
|
|
440
|
+
useWeakModuleFromNodeConfigLogger,
|
|
441
|
+
useWeakModulesFromNode,
|
|
442
|
+
useWeakNodeConfigNodeField,
|
|
443
|
+
useWeakNodeDescription,
|
|
444
|
+
useWeakNodeFromNode,
|
|
445
|
+
useWeakProvidedNode
|
|
446
|
+
};
|
|
2
447
|
//# sourceMappingURL=index.js.map
|