@xyo-network/react-node-renderer 2.77.0-rc.1 → 2.77.1

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.
Files changed (32) hide show
  1. package/dist/browser/components/relational/graph/Graph.d.cts +0 -1
  2. package/dist/browser/components/relational/graph/Graph.d.cts.map +1 -1
  3. package/dist/browser/components/relational/graph/Graph.d.mts +0 -1
  4. package/dist/browser/components/relational/graph/Graph.d.mts.map +1 -1
  5. package/dist/browser/components/relational/graph/Graph.d.ts +0 -1
  6. package/dist/browser/components/relational/graph/Graph.d.ts.map +1 -1
  7. package/dist/browser/index.cjs +1 -840
  8. package/dist/browser/index.cjs.map +1 -1
  9. package/dist/browser/index.js +1 -815
  10. package/dist/browser/index.js.map +1 -1
  11. package/dist/neutral/components/relational/graph/Graph.d.cts +0 -1
  12. package/dist/neutral/components/relational/graph/Graph.d.cts.map +1 -1
  13. package/dist/neutral/components/relational/graph/Graph.d.mts +0 -1
  14. package/dist/neutral/components/relational/graph/Graph.d.mts.map +1 -1
  15. package/dist/neutral/components/relational/graph/Graph.d.ts +0 -1
  16. package/dist/neutral/components/relational/graph/Graph.d.ts.map +1 -1
  17. package/dist/neutral/index.cjs +1 -840
  18. package/dist/neutral/index.cjs.map +1 -1
  19. package/dist/neutral/index.js +1 -815
  20. package/dist/neutral/index.js.map +1 -1
  21. package/dist/node/components/relational/graph/Graph.d.cts +0 -1
  22. package/dist/node/components/relational/graph/Graph.d.cts.map +1 -1
  23. package/dist/node/components/relational/graph/Graph.d.mts +0 -1
  24. package/dist/node/components/relational/graph/Graph.d.mts.map +1 -1
  25. package/dist/node/components/relational/graph/Graph.d.ts +0 -1
  26. package/dist/node/components/relational/graph/Graph.d.ts.map +1 -1
  27. package/dist/node/index.cjs +1 -880
  28. package/dist/node/index.cjs.map +1 -1
  29. package/dist/node/index.js +1 -827
  30. package/dist/node/index.js.map +1 -1
  31. package/package.json +27 -27
  32. package/src/Cytoscape/lib/layout/ConcentricLayout.ts +1 -1
@@ -1,828 +1,2 @@
1
- // src/components/module/CardParser.tsx
2
- import { asArchivistInstance, isArchivistInstance } from "@xyo-network/archivist-model";
3
- import { asDivinerInstance, isDivinerInstance } from "@xyo-network/diviner-model";
4
- import { ArchivistCard } from "@xyo-network/react-archivist";
5
- import { DivinerCard, ModuleCard } from "@xyo-network/react-module";
6
- import { jsx } from "react/jsx-runtime";
7
- var ModuleCardParser = ({ mod }) => {
8
- switch (true) {
9
- case isArchivistInstance(mod): {
10
- return /* @__PURE__ */ jsx(ArchivistCard, { mod: asArchivistInstance(mod) });
11
- }
12
- case isDivinerInstance(mod): {
13
- return /* @__PURE__ */ jsx(DivinerCard, { mod: asDivinerInstance(mod) });
14
- }
15
- default: {
16
- return /* @__PURE__ */ jsx(ModuleCard, { mod });
17
- }
18
- }
19
- };
20
-
21
- // src/components/module/graph/GraphFlexBox.tsx
22
- import { Button as Button3 } from "@mui/material";
23
- import { useRef as useRef3 } from "react";
24
-
25
- // src/contexts/CytoscapeInstance/Context.ts
26
- import { createContextEx } from "@xyo-network/react-shared";
27
- var CytoscapeInstanceContext = createContextEx();
28
-
29
- // src/contexts/CytoscapeInstance/Provider.tsx
30
- import { useEffect, useState } from "react";
31
- import { jsx as jsx2 } from "react/jsx-runtime";
32
- var CytoscapeInstanceProvider = ({ children, defaultInstance }) => {
33
- const [cy, setCy] = useState(defaultInstance);
34
- useEffect(() => {
35
- setCy(defaultInstance);
36
- }, [defaultInstance]);
37
- return /* @__PURE__ */ jsx2(CytoscapeInstanceContext.Provider, { value: { cy, provided: true, setCy }, children });
38
- };
39
-
40
- // src/contexts/CytoscapeInstance/use.ts
41
- import { useContextEx } from "@xyo-network/react-shared";
42
- var useCytoscapeInstance = (required = false) => useContextEx(CytoscapeInstanceContext, "CytoscapeInstance", required);
43
-
44
- // src/hooks/cytoscape/elements/useCytoscapeElements.ts
45
- import { useAsyncEffect } from "@xylabs/react-async-effect";
46
- import { isNodeInstance as isNodeInstance2 } from "@xyo-network/node-model";
47
- import { useEffect as useEffect2, useState as useState2 } from "react";
48
-
49
- // src/Cytoscape/CytoscapeElements.ts
50
- import { exists } from "@xylabs/exists";
51
-
52
- // src/Cytoscape/lib/encodeSvg.ts
53
- import { renderToStaticMarkup } from "react-dom/server";
54
- var dataUri = "data:image/svg+xml,";
55
- var encodeSvg = (reactElement, color) => {
56
- const svgString = renderToStaticMarkup(reactElement);
57
- const doc = new DOMParser().parseFromString(svgString, "text/html");
58
- const svgElement = doc.querySelectorAll("svg")[0];
59
- if (svgElement) {
60
- svgElement.setAttribute("xmlns", "http://www.w3.org/2000/svg");
61
- svgElement.setAttribute("height", "100");
62
- svgElement.style.fill = color ?? "black";
63
- }
64
- return `${dataUri}${window.encodeURIComponent(svgElement.outerHTML)}`;
65
- };
66
-
67
- // src/Cytoscape/lib/iconMap.ts
68
- var generateIconMap = () => ({
69
- archivist: "",
70
- bridge: "",
71
- diviner: "",
72
- // eslint-disable-next-line id-denylist
73
- module: "",
74
- node: "",
75
- sentinel: "",
76
- witness: ""
77
- });
78
-
79
- // src/Cytoscape/lib/layout/ColaLayout.ts
80
- var ColaLayout = {
81
- centerGraph: false,
82
- convergenceThreshold: 0.01,
83
- name: "cola"
84
- };
85
-
86
- // src/Cytoscape/lib/layout/ConcentricLayout.ts
87
- var ConcentricLayout = {
88
- concentric: function(node) {
89
- return node.degree();
90
- },
91
- levelWidth: function() {
92
- return 2;
93
- },
94
- minNodeSpacing: 75,
95
- name: "concentric"
96
- };
97
-
98
- // src/Cytoscape/lib/parseModuleType.ts
99
- import { isArchivistInstance as isArchivistInstance2 } from "@xyo-network/archivist-model";
100
- import { isBridgeInstance } from "@xyo-network/bridge-model";
101
- import { isDivinerInstance as isDivinerInstance2 } from "@xyo-network/diviner-model";
102
- import { isNodeInstance } from "@xyo-network/node-model";
103
- import { isSentinelInstance } from "@xyo-network/sentinel-model";
104
- import { isWitnessModule } from "@xyo-network/witness-model";
105
- var parseModuleType = (mod) => {
106
- let type = "module";
107
- if (mod) {
108
- if (isArchivistInstance2(mod)) {
109
- type = "archivist";
110
- } else if (isBridgeInstance(mod)) {
111
- type = "bridge";
112
- } else if (isDivinerInstance2(mod)) {
113
- type = "diviner";
114
- } else if (isNodeInstance(mod)) {
115
- type = "node";
116
- } else if (isSentinelInstance(mod)) {
117
- type = "sentinel";
118
- } else if (isWitnessModule(mod)) {
119
- type = "witness";
120
- } else {
121
- type = "module";
122
- }
123
- }
124
- return type;
125
- };
126
-
127
- // src/Cytoscape/CytoscapeElements.ts
128
- var CytoscapeElements = {
129
- MaxNameLength: 20,
130
- buildEdge(rootNode, newNode, properties) {
131
- return {
132
- data: {
133
- id: `${rootNode.data.id}/${newNode.data.id}`,
134
- source: rootNode.data.id,
135
- target: newNode.data.id,
136
- ...properties
137
- }
138
- };
139
- },
140
- async buildElements(mod) {
141
- const info = await CytoscapeElements.recurseNodes(mod);
142
- const newElements = await this.buildElementsFromInfo(info, void 0, ["activeNode"]);
143
- return newElements;
144
- },
145
- async buildElementsFromInfo(info, root, classes = []) {
146
- const newNode = CytoscapeElements.buildNode(info.mod, { childCount: info.children.length, depth: info.depth }, classes);
147
- const newEdge = root ? CytoscapeElements.buildEdge(root, newNode, { depth: info.depth, siblingCount: info.children.length }) : void 0;
148
- const newElements = [newNode];
149
- if (newEdge) {
150
- newElements.push(newEdge);
151
- }
152
- for (const childInfo of info.children) {
153
- newElements.push(...await this.buildElementsFromInfo(childInfo, newNode));
154
- }
155
- return newElements;
156
- },
157
- buildNode(mod, properties, classes) {
158
- const { address, id } = mod;
159
- return {
160
- classes,
161
- data: {
162
- address,
163
- id: address,
164
- name: id,
165
- type: parseModuleType(mod),
166
- ...properties
167
- }
168
- };
169
- },
170
- buildRootNode: (mod) => {
171
- return CytoscapeElements.buildNode(mod, {}, ["activeNode"]);
172
- },
173
- normalizeName(name) {
174
- if (!name)
175
- return;
176
- if (name.length > this.MaxNameLength)
177
- return `${name.slice(0, 20)}...`;
178
- return name;
179
- },
180
- async recurseNodes(root, maxDepth = 10, depth = 1) {
181
- const info = { children: [], depth, mod: root };
182
- if (maxDepth > 0) {
183
- const children = await root.resolve("*", { direction: "down", maxDepth: 1 });
184
- info.children = (await Promise.all(
185
- children.map(async (child) => {
186
- if (child.address !== root.address) {
187
- return await this.recurseNodes(child, maxDepth - 1, depth + 1);
188
- }
189
- })
190
- )).filter(exists);
191
- }
192
- return info;
193
- }
194
- };
195
-
196
- // src/Cytoscape/CytoscapeIcons.tsx
197
- import {
198
- BubbleChartRounded as BubbleChartRoundedIcon,
199
- Hub as HubIcon,
200
- InsertLinkRounded as InsertLinkRoundedIcon,
201
- Inventory2Rounded as Inventory2RoundedIcon,
202
- QuestionMarkRounded as QuestionMarkRoundedIcon,
203
- TimerRounded as TimerRoundedIcon,
204
- VisibilityRounded as VisibilityRoundedIcon
205
- } from "@mui/icons-material";
206
- var CyIconSet = {
207
- archivist: Inventory2RoundedIcon,
208
- bridge: InsertLinkRoundedIcon,
209
- diviner: BubbleChartRoundedIcon,
210
- // eslint-disable-next-line id-denylist
211
- module: QuestionMarkRoundedIcon,
212
- node: HubIcon,
213
- sentinel: TimerRoundedIcon,
214
- witness: VisibilityRoundedIcon
215
- };
216
-
217
- // src/Cytoscape/CytoscapeStyles.ts
218
- var NodeWithName = (color, outlineColor) => ({
219
- selector: "node[name]",
220
- style: {
221
- color,
222
- "font-family": "Lexend Deca, Helvetica, sans-serif",
223
- "font-size": 12,
224
- "overlay-padding": "6px",
225
- "text-halign": "center",
226
- "text-outline-color": outlineColor,
227
- "text-outline-width": "1px",
228
- "text-valign": "top"
229
- }
230
- });
231
- var Node = (icons, bgColor, hideLabels = false) => ({
232
- selector: "node",
233
- style: {
234
- "background-color": bgColor,
235
- "background-height": "75%",
236
- "background-image": (elem) => icons[elem.data("type")],
237
- "background-width": "24",
238
- label: hideLabels ? void 0 : "data(name)",
239
- shape: "round-rectangle"
240
- }
241
- });
242
- var NodeAsRoot = (bgColor) => ({
243
- selector: ".activeNode",
244
- style: {
245
- "background-color": bgColor
246
- }
247
- });
248
- var EdgeStyled = (lineColor, targetArrowColor) => ({
249
- selector: "edge",
250
- style: {
251
- "curve-style": "bezier",
252
- "line-color": lineColor,
253
- "line-opacity": 0.1,
254
- "target-arrow-color": targetArrowColor,
255
- "target-arrow-shape": "triangle",
256
- width: 3
257
- }
258
- });
259
-
260
- // src/hooks/cytoscape/elements/useCytoscapeElements.ts
261
- var useCytoscapeElements = (mod) => {
262
- const [elements, setElements] = useState2([]);
263
- useAsyncEffect(
264
- // eslint-disable-next-line react-hooks/exhaustive-deps
265
- async () => {
266
- const moduleInstance = mod == null ? void 0 : mod.deref();
267
- if (moduleInstance) {
268
- const newElements = await CytoscapeElements.buildElements(moduleInstance) ?? [];
269
- setElements(newElements);
270
- }
271
- },
272
- [mod]
273
- );
274
- useEffect2(() => {
275
- let attachedListener;
276
- let detachedListener;
277
- if (mod && isNodeInstance2(mod)) {
278
- attachedListener = mod.on("moduleAttached", async () => {
279
- const newElements = await CytoscapeElements.buildElements(mod) ?? [];
280
- setElements(newElements);
281
- });
282
- detachedListener = mod.on("moduleDetached", async () => {
283
- const newElements = await CytoscapeElements.buildElements(mod) ?? [];
284
- setElements(newElements);
285
- });
286
- }
287
- return () => {
288
- attachedListener == null ? void 0 : attachedListener();
289
- detachedListener == null ? void 0 : detachedListener();
290
- };
291
- }, [mod]);
292
- return elements;
293
- };
294
-
295
- // src/hooks/cytoscape/elements/useHoveredNode.tsx
296
- import { useCallback, useEffect as useEffect3, useState as useState3 } from "react";
297
- var useHoveredNode = (renderedElements) => {
298
- const { cy } = useCytoscapeInstance(true);
299
- const [hoveredNode, setHoveredNode] = useState3();
300
- const nodeListener = useCallback((node) => {
301
- node.on("mouseover tap", () => {
302
- setHoveredNode(node);
303
- });
304
- }, []);
305
- useEffect3(() => {
306
- if (renderedElements) {
307
- renderedElements.nodes().forEach(nodeListener);
308
- }
309
- }, [nodeListener, renderedElements]);
310
- useEffect3(() => {
311
- var _a;
312
- (_a = cy == null ? void 0 : cy.deref()) == null ? void 0 : _a.ready(() => {
313
- var _a2;
314
- (_a2 = cy == null ? void 0 : cy.deref()) == null ? void 0 : _a2.nodes().forEach(nodeListener);
315
- });
316
- }, [cy, nodeListener]);
317
- return [hoveredNode, setHoveredNode];
318
- };
319
-
320
- // src/hooks/cytoscape/elements/useNewElements.tsx
321
- import { useWeakModuleFromNode } from "@xyo-network/react-node";
322
- import { useMemo } from "react";
323
- var useNewElements = (selectedElement) => {
324
- const selectedAddress = useMemo(() => {
325
- const { address: selectedAddress2 } = (selectedElement == null ? void 0 : selectedElement.data()) ?? {};
326
- return selectedAddress2;
327
- }, [selectedElement]);
328
- const [mod] = useWeakModuleFromNode(selectedAddress);
329
- const newElements = useCytoscapeElements(mod);
330
- return newElements;
331
- };
332
-
333
- // src/hooks/cytoscape/elements/useRenderNewElements.tsx
334
- import { useEffect as useEffect4, useState as useState4 } from "react";
335
- var useRenderNewElements = (newElements = [], hideLabels) => {
336
- const { cy } = useCytoscapeInstance(true);
337
- const [renderedElements, setRenderedElements] = useState4();
338
- useEffect4(() => {
339
- var _a, _b;
340
- if (newElements.length > 1) {
341
- const renderedElements2 = (_a = cy == null ? void 0 : cy.deref()) == null ? void 0 : _a.add(newElements);
342
- setRenderedElements(renderedElements2);
343
- (_b = cy == null ? void 0 : cy.deref()) == null ? void 0 : _b.layout(ColaLayout).run();
344
- }
345
- }, [cy, hideLabels, newElements]);
346
- return renderedElements;
347
- };
348
-
349
- // src/hooks/cytoscape/elements/useSelectedElement.tsx
350
- import { useState as useState5 } from "react";
351
- var useSelectedElement = () => {
352
- const [selectedElement, setSelectedElement] = useState5();
353
- const { cy } = useCytoscapeInstance(true);
354
- const updateStyles = (element) => {
355
- var _a;
356
- const nodes = (_a = cy == null ? void 0 : cy.deref()) == null ? void 0 : _a.nodes();
357
- nodes == null ? void 0 : nodes.toggleClass("activeNode", false);
358
- element.toggleClass("activeNode", true);
359
- };
360
- const toggleSelectedElement = (address) => {
361
- var _a, _b;
362
- const selectedNode = (_b = (_a = cy == null ? void 0 : cy.deref()) == null ? void 0 : _a.nodes(`[id="${address}"]`)) == null ? void 0 : _b[0];
363
- if (selectedNode) {
364
- setSelectedElement(selectedNode);
365
- updateStyles(selectedNode);
366
- }
367
- };
368
- return { selectedElement, toggleSelectedElement };
369
- };
370
-
371
- // src/hooks/cytoscape/elements/useElements.tsx
372
- var useElements = (hideLabels) => {
373
- const { selectedElement, toggleSelectedElement } = useSelectedElement();
374
- const newElements = useNewElements(selectedElement);
375
- const renderedElements = useRenderNewElements(newElements, hideLabels);
376
- const [hoveredNode, setHoveredNode] = useHoveredNode(renderedElements);
377
- return { hoveredNode, setHoveredNode, toggleSelectedElement };
378
- };
379
-
380
- // src/hooks/cytoscape/useCytoscapeOptions.ts
381
- import { useMemo as useMemo4 } from "react";
382
-
383
- // src/hooks/cytoscape/useCytoscapeStyle.tsx
384
- import { useTheme as useTheme2 } from "@mui/material";
385
- import { useMemo as useMemo3 } from "react";
386
-
387
- // src/hooks/cytoscape/useIcons.tsx
388
- import { useTheme } from "@mui/material";
389
- import { useMemo as useMemo2 } from "react";
390
- import { jsx as jsx3 } from "react/jsx-runtime";
391
- var useIcons = () => {
392
- const theme = useTheme();
393
- const icons = useMemo2(() => {
394
- const iconMap = generateIconMap();
395
- return Object.entries(CyIconSet).reduce((acc, [name, IconComponent]) => {
396
- const icon = /* @__PURE__ */ jsx3(IconComponent, { fontSize: "small" });
397
- acc[name] = encodeSvg(icon, theme.palette.getContrastText(theme.palette.text.primary));
398
- return acc;
399
- }, iconMap);
400
- }, [theme.palette]);
401
- return icons;
402
- };
403
-
404
- // src/hooks/cytoscape/useCytoscapeStyle.tsx
405
- var useCytoscapeStyle = (hideLabels = false) => {
406
- const theme = useTheme2();
407
- const icons = useIcons();
408
- const style = useMemo3(
409
- () => [
410
- Node(icons, theme.palette.primary.main, hideLabels),
411
- NodeWithName(theme.palette.text.primary, theme.palette.getContrastText(theme.palette.text.primary)),
412
- NodeAsRoot(theme.palette.secondary.main),
413
- EdgeStyled(theme.palette.divider, theme.palette.divider)
414
- ],
415
- [icons, hideLabels, theme]
416
- );
417
- return style;
418
- };
419
-
420
- // src/hooks/cytoscape/useCytoscapeOptions.ts
421
- var useCytoscapeOptions = (elements, style, layout) => {
422
- const defaultStyle = useCytoscapeStyle();
423
- const resolvedLayout = layout ?? ConcentricLayout;
424
- const resolvedStyle = style ?? defaultStyle;
425
- const options = useMemo4(() => {
426
- if (elements && resolvedLayout && resolvedStyle) {
427
- return {
428
- elements,
429
- layout: resolvedLayout,
430
- style: resolvedStyle
431
- };
432
- }
433
- }, [elements, layout, style]);
434
- return options;
435
- };
436
-
437
- // src/hooks/cytoscape/useModuleDetails.tsx
438
- import { usePromise } from "@xylabs/react-promise";
439
- import { useEffect as useEffect5, useState as useState6 } from "react";
440
- var useModuleDetails = (rootModule, onFoundModule) => {
441
- const { cy } = useCytoscapeInstance();
442
- const [moduleAddress, setModuleAddress] = useState6();
443
- const [foundModule] = usePromise(async () => {
444
- if (moduleAddress === null)
445
- return null;
446
- const rootModuleInstance = rootModule == null ? void 0 : rootModule.deref();
447
- if (moduleAddress && rootModuleInstance) {
448
- const foundModule2 = await rootModuleInstance.resolve(moduleAddress);
449
- return foundModule2 ?? null;
450
- }
451
- }, [moduleAddress, rootModule]);
452
- useEffect5(() => {
453
- var _a;
454
- const resizeObserver = new ResizeObserver(() => {
455
- var _a2, _b;
456
- if (moduleAddress === null) {
457
- setTimeout(() => {
458
- var _a3;
459
- (_a3 = cy == null ? void 0 : cy.deref()) == null ? void 0 : _a3.center();
460
- }, 100);
461
- } else if (foundModule && cy) {
462
- const node = (_b = (_a2 = cy == null ? void 0 : cy.deref()) == null ? void 0 : _a2.nodes(`[id="${moduleAddress}"]`)) == null ? void 0 : _b[0];
463
- setTimeout(() => {
464
- var _a3;
465
- (_a3 = cy == null ? void 0 : cy.deref()) == null ? void 0 : _a3.center(node);
466
- }, 100);
467
- }
468
- });
469
- const container = (_a = cy == null ? void 0 : cy.deref()) == null ? void 0 : _a.container();
470
- if (container) {
471
- resizeObserver.observe(container);
472
- }
473
- return () => {
474
- if (container)
475
- resizeObserver.unobserve(container);
476
- };
477
- }, [cy, moduleAddress, foundModule, rootModule]);
478
- useEffect5(() => {
479
- if (foundModule) {
480
- onFoundModule == null ? void 0 : onFoundModule();
481
- }
482
- }, [cy, moduleAddress, foundModule, onFoundModule]);
483
- const onModuleDetails = (address) => {
484
- var _a, _b, _c, _d, _e;
485
- const moduleNode = (_a = cy == null ? void 0 : cy.deref()) == null ? void 0 : _a.nodes(`[id="${address}"]`);
486
- const rootModuleNode = (_c = cy == null ? void 0 : cy.deref()) == null ? void 0 : _c.nodes(`[id="${(_b = rootModule == null ? void 0 : rootModule.deref()) == null ? void 0 : _b.address}"]`);
487
- const foundModuleNode = (_d = cy == null ? void 0 : cy.deref()) == null ? void 0 : _d.nodes(`[id="${foundModule == null ? void 0 : foundModule.address}"]`);
488
- const notModuleNode = (_e = cy == null ? void 0 : cy.deref()) == null ? void 0 : _e.nodes(`[id != "${address}"]`);
489
- if (address) {
490
- moduleNode == null ? void 0 : moduleNode.toggleClass("activeNode", true);
491
- notModuleNode == null ? void 0 : notModuleNode.toggleClass("activeNode", false);
492
- } else {
493
- notModuleNode == null ? void 0 : notModuleNode.toggleClass("activeNode", false);
494
- const activeNode = (foundModuleNode == null ? void 0 : foundModuleNode.length) ? foundModuleNode : rootModuleNode;
495
- activeNode == null ? void 0 : activeNode.toggleClass("activeNode", true);
496
- }
497
- setModuleAddress(address);
498
- };
499
- return { mod: foundModule, onModuleDetails };
500
- };
501
-
502
- // src/hooks/cytoscape/useRelationalGraphOptions.tsx
503
- import { useState as useState7 } from "react";
504
- var useRelationalGraphOptions = (mod) => {
505
- const [hideLabels, setHideLabels] = useState7(true);
506
- const handleToggleLabels = () => {
507
- setHideLabels((oldValue) => !oldValue);
508
- };
509
- const elements = useCytoscapeElements(mod);
510
- const style = useCytoscapeStyle(hideLabels);
511
- const options = useCytoscapeOptions(elements, style, ConcentricLayout);
512
- return { handleToggleLabels, hideLabels, options };
513
- };
514
-
515
- // src/components/cytoscape-extensions/WithExtensions.tsx
516
- import cytoscape from "cytoscape";
517
- import cola from "cytoscape-cola";
518
- import coseBilkent from "cytoscape-cose-bilkent";
519
- import dagre from "cytoscape-dagre";
520
- import euler from "cytoscape-euler";
521
- import { useEffect as useEffect6, useState as useState8 } from "react";
522
- import { Fragment, jsx as jsx4 } from "react/jsx-runtime";
523
- var WithExtensions = ({ children }) => {
524
- const [initialized, setInitialized] = useState8(false);
525
- useEffect6(() => {
526
- cytoscape.use(cola);
527
- cytoscape.use(dagre);
528
- cytoscape.use(coseBilkent);
529
- cytoscape.use(euler);
530
- setInitialized(true);
531
- }, []);
532
- return /* @__PURE__ */ jsx4(Fragment, { children: initialized ? children : void 0 });
533
- };
534
-
535
- // src/components/relational/graph/Graph.tsx
536
- import { Box, Button, ButtonGroup, Card, CardHeader, Paper, useTheme as useTheme3 } from "@mui/material";
537
- import { asAddress } from "@xylabs/hex";
538
- import { FlexCol, FlexGrowRow, FlexRow } from "@xylabs/react-flexbox";
539
- import { Identicon } from "@xylabs/react-identicon";
540
- import { useWeakModuleFromNode as useWeakModuleFromNode2 } from "@xyo-network/react-node";
541
- import cytoscape2 from "cytoscape";
542
- import cola2 from "cytoscape-cola";
543
- import coseBilkentLayout from "cytoscape-cose-bilkent";
544
- import dagre2 from "cytoscape-dagre";
545
- import eulerLayout from "cytoscape-euler";
546
- import { forwardRef, useEffect as useEffect7, useRef, useState as useState9 } from "react";
547
- import { jsx as jsx5, jsxs } from "react/jsx-runtime";
548
- var applyLayout = (cy, name = "cola", options) => {
549
- cy == null ? void 0 : cy.layout({ name, ...options }).run();
550
- };
551
- var loadLayout = (layout = "cola") => {
552
- switch (layout) {
553
- case "dagre": {
554
- cytoscape2.use(dagre2);
555
- break;
556
- }
557
- case "euler": {
558
- cytoscape2.use(eulerLayout);
559
- break;
560
- }
561
- case "cose-bilkent": {
562
- cytoscape2.use(coseBilkentLayout);
563
- break;
564
- }
565
- case "cola": {
566
- cytoscape2.use(cola2);
567
- break;
568
- }
569
- }
570
- };
571
- var ModuleHoverDetails = ({ name, address, ...props }) => {
572
- return /* @__PURE__ */ jsx5(Card, { elevation: 3, ...props, children: /* @__PURE__ */ jsx5(
573
- CardHeader,
574
- {
575
- avatar: /* @__PURE__ */ jsx5(Paper, { elevation: 6, sx: { bgcolor: "#fff", p: 1 }, children: /* @__PURE__ */ jsx5(Identicon, { value: address, size: 24 }) }),
576
- title: name,
577
- subheader: address
578
- }
579
- ) });
580
- };
581
- var NodeRelationalGraphFlexBox = forwardRef(
582
- ({ actions, children, node, layout, layoutOptions, showDetails, detail, options, onHover, ...props }, ref) => {
583
- var _a;
584
- const theme = useTheme3();
585
- const [cy, setCy] = useState9();
586
- const cytoscapeRef = useRef();
587
- const [hoverPosition, setHoverBoundingBox] = useState9();
588
- const [hoverAddress, setHoverAddress] = useState9();
589
- const [moduleInstance] = useWeakModuleFromNode2(hoverAddress, { node });
590
- useEffect7(() => {
591
- cy == null ? void 0 : cy.on("mouseover tap", ({ target }) => {
592
- var _a2, _b;
593
- const cyNode = target;
594
- const bb = (_a2 = cyNode == null ? void 0 : cyNode.renderedBoundingBox) == null ? void 0 : _a2.call(cyNode);
595
- setHoverBoundingBox(bb);
596
- const id = (_b = cyNode.id) == null ? void 0 : _b.call(cyNode);
597
- if (id) {
598
- if (id.includes("/")) {
599
- setHoverAddress(void 0);
600
- onHover == null ? void 0 : onHover();
601
- } else {
602
- setHoverAddress(asAddress(id));
603
- onHover == null ? void 0 : onHover(asAddress(id));
604
- }
605
- }
606
- });
607
- }, [onHover, cy]);
608
- const handleReset = () => {
609
- cy == null ? void 0 : cy.reset();
610
- applyLayout(cy, layout ?? "euler", layoutOptions);
611
- };
612
- useEffect7(() => {
613
- let newCy;
614
- const container = cytoscapeRef.current;
615
- if (container) {
616
- newCy = cytoscape2({
617
- container,
618
- ...options
619
- });
620
- setCy(newCy);
621
- }
622
- return () => {
623
- newCy == null ? void 0 : newCy.destroy();
624
- setCy(void 0);
625
- };
626
- }, [options, cytoscapeRef, layoutOptions]);
627
- useEffect7(() => {
628
- if (cy) {
629
- loadLayout(layout);
630
- applyLayout(cy, layout ?? "euler", layoutOptions);
631
- }
632
- }, [cy, layoutOptions, layout]);
633
- return /* @__PURE__ */ jsxs(FlexCol, { id: "relational-graph-wrapper", ref, ...props, children: [
634
- hoverAddress && hoverPosition ? /* @__PURE__ */ jsx5(Box, { position: "absolute", top: hoverPosition.y1, left: hoverPosition.x1, zIndex: 100, children: /* @__PURE__ */ jsx5(ModuleHoverDetails, { address: hoverAddress, name: ((_a = moduleInstance == null ? void 0 : moduleInstance.deref()) == null ? void 0 : _a.id) ?? "Unknown" }) }) : null,
635
- /* @__PURE__ */ jsx5(FlexRow, { justifyContent: "start", width: "100%", children: actions === null ? null : actions ? /* @__PURE__ */ jsxs(ButtonGroup, { children: [
636
- actions,
637
- /* @__PURE__ */ jsx5(Button, { size: "small", variant: "contained", onClick: handleReset, children: "Reset View" })
638
- ] }) : /* @__PURE__ */ jsx5(Button, { size: "small", variant: "contained", onClick: handleReset, children: "Reset" }) }),
639
- /* @__PURE__ */ jsxs(FlexGrowRow, { width: "100%", alignItems: "start", children: [
640
- showDetails ? /* @__PURE__ */ jsx5(FlexCol, { height: "100%", width: "85%", children: detail }) : null,
641
- /* @__PURE__ */ jsxs(
642
- FlexCol,
643
- {
644
- justifyContent: "start",
645
- classes: "cytoscape-wrap",
646
- width: showDetails ? "15%" : "100%",
647
- height: showDetails ? "50%" : "100%",
648
- border: showDetails ? `1px solid ${theme.palette.divider}` : void 0,
649
- children: [
650
- /* @__PURE__ */ jsx5(FlexCol, { alignItems: "stretch", position: "absolute", width: "100%", height: "100%", ref: cytoscapeRef }),
651
- children
652
- ]
653
- }
654
- )
655
- ] })
656
- ] });
657
- }
658
- );
659
- NodeRelationalGraphFlexBox.displayName = "NodeRelationalGraph";
660
- var NodeRelationalGraph = NodeRelationalGraphFlexBox;
661
-
662
- // src/components/relational/graph/ProvidedNodeRenderer.tsx
663
- import { useWeakProvidedNode } from "@xyo-network/react-node";
664
- import { jsx as jsx6 } from "react/jsx-runtime";
665
- var ProvidedNodeRenderer = ({ node, ...props }) => {
666
- const [providedNode] = useWeakProvidedNode();
667
- const elements = useCytoscapeElements(node ?? providedNode);
668
- const options = useCytoscapeOptions(elements);
669
- return /* @__PURE__ */ jsx6(NodeRelationalGraphFlexBox, { alignItems: "stretch", flexGrow: 1, height: "100%", options, ...props });
670
- };
671
-
672
- // src/components/module/graph/DetailsFlexbox.tsx
673
- import { CancelRounded } from "@mui/icons-material";
674
- import { IconButton } from "@mui/material";
675
- import { FlexGrowCol, FlexRow as FlexRow2 } from "@xylabs/react-flexbox";
676
- import { jsx as jsx7, jsxs as jsxs2 } from "react/jsx-runtime";
677
- var DetailsFlexbox = ({ children, onClose }) => {
678
- return /* @__PURE__ */ jsxs2(FlexGrowCol, { alignItems: "end", justifyContent: "start", id: "module-detail", width: "100%", p: 2, gap: 2, children: [
679
- /* @__PURE__ */ jsx7(FlexRow2, { justifyContent: "end", children: /* @__PURE__ */ jsx7(IconButton, { onClick: onClose, size: "small", children: /* @__PURE__ */ jsx7(CancelRounded, {}) }) }),
680
- children
681
- ] });
682
- };
683
-
684
- // src/components/module/graph/node/Hover.tsx
685
- import { styled } from "@mui/material";
686
- import { FlexCol as FlexCol2 } from "@xylabs/react-flexbox";
687
-
688
- // src/components/module/graph/node/hooks/useNodeElement.tsx
689
- import { useEffect as useEffect8, useRef as useRef2, useState as useState10 } from "react";
690
- var useNodeElement = (node) => {
691
- const ref = useRef2(null);
692
- const [currentElement, setCurrentElement] = useState10(null);
693
- const [boundingBox, setBoundingBox] = useState10(node == null ? void 0 : node.renderedBoundingBox());
694
- useEffect8(() => {
695
- setCurrentElement(null);
696
- }, [node]);
697
- useEffect8(() => {
698
- if (node) {
699
- setBoundingBox(node.renderedBoundingBox());
700
- }
701
- const listener = () => {
702
- setBoundingBox(node == null ? void 0 : node.renderedBoundingBox());
703
- };
704
- node == null ? void 0 : node.on("position", listener);
705
- return () => {
706
- node == null ? void 0 : node.off("position", void 0, listener);
707
- };
708
- }, [node]);
709
- useEffect8(() => {
710
- setCurrentElement(ref.current);
711
- }, [boundingBox]);
712
- return { boundingBox, currentElement, ref };
713
- };
714
-
715
- // src/components/module/graph/node/Hover.tsx
716
- import { Fragment as Fragment2, jsx as jsx8, jsxs as jsxs3 } from "react/jsx-runtime";
717
- var ModuleGraphNodeHover = ({ children, node }) => {
718
- const { boundingBox, ref, currentElement } = useNodeElement(node);
719
- return /* @__PURE__ */ jsxs3(Fragment2, { children: [
720
- /* @__PURE__ */ jsx8(StyledNodeGhostElementFlexCol, { ref, left: boundingBox == null ? void 0 : boundingBox.x1, height: boundingBox == null ? void 0 : boundingBox.h, top: boundingBox == null ? void 0 : boundingBox.y1, width: boundingBox == null ? void 0 : boundingBox.w }),
721
- node ? /* @__PURE__ */ jsx8(Fragment2, { children: children == null ? void 0 : children(currentElement) }) : null
722
- ] });
723
- };
724
- var StyledNodeGhostElementFlexCol = styled(FlexCol2, { name: "StyledNodeGhostElementFlexCol" })(() => ({
725
- // For easier debugging of the 'ghost' element that matches the hovered cytoscape node
726
- // backgroundColor: '#fff',
727
- // opacity: 0.25,
728
- // eslint-disable-next-line sort-keys-fix/sort-keys-fix
729
- cursor: "pointer",
730
- pointerEvents: "none",
731
- position: "absolute"
732
- }));
733
-
734
- // src/components/module/graph/Popper.tsx
735
- import { CancelRounded as CancelRounded2 } from "@mui/icons-material";
736
- import { Button as Button2, Card as Card2, CardActions, CardHeader as CardHeader2, IconButton as IconButton2, Paper as Paper2, Popper, styled as styled2 } from "@mui/material";
737
- import { Identicon as Identicon2 } from "@xylabs/react-identicon";
738
- import { Fragment as Fragment3, jsx as jsx9, jsxs as jsxs4 } from "react/jsx-runtime";
739
- var ModuleHoverPopper = ({ anchorEl, onClose, onModuleDetails, onModuleExplore, node, ...props }) => {
740
- const { address, name } = (node == null ? void 0 : node.data()) ?? {};
741
- return /* @__PURE__ */ jsx9(Fragment3, { children: anchorEl ? /* @__PURE__ */ jsx9(Popper, { anchorEl, ...props, children: /* @__PURE__ */ jsxs4(Card2, { elevation: 3, children: [
742
- /* @__PURE__ */ jsx9(
743
- CardHeader2,
744
- {
745
- action: onClose ? /* @__PURE__ */ jsx9(IconButton2, { size: "small", onClick: onClose, children: /* @__PURE__ */ jsx9(CancelRounded2, {}) }) : null,
746
- avatar: /* @__PURE__ */ jsx9(Paper2, { elevation: 6, sx: { bgcolor: "#fff", p: 1 }, children: /* @__PURE__ */ jsx9(Identicon2, { value: address, size: 24 }) }),
747
- title: name,
748
- subheader: address
749
- }
750
- ),
751
- /* @__PURE__ */ jsxs4(StyledCardActions, { children: [
752
- onModuleDetails ? /* @__PURE__ */ jsx9(Button2, { onClick: () => onModuleDetails == null ? void 0 : onModuleDetails(address), size: "small", variant: "contained", children: "Details" }) : null,
753
- onModuleExplore ? /* @__PURE__ */ jsx9(Button2, { onClick: () => onModuleExplore == null ? void 0 : onModuleExplore(address), size: "small", variant: "contained", children: "Explore" }) : null
754
- ] })
755
- ] }) }) : null });
756
- };
757
- var StyledModuleHoverPopper = styled2(ModuleHoverPopper, { name: "StyledComponents" })(() => ({
758
- zIndex: 2
759
- }));
760
- var StyledCardActions = styled2(CardActions, { name: "StyledCardActions" })(() => ({
761
- display: "flex",
762
- justifyContent: "center"
763
- }));
764
-
765
- // src/components/module/graph/GraphFlexBox.tsx
766
- import { jsx as jsx10 } from "react/jsx-runtime";
767
- var ModuleGraphFlexBox = ({ hideActions, rootModule, disableModuleDetails, ...props }) => {
768
- const cytoscapeRef = useRef3(null);
769
- const { handleToggleLabels, hideLabels, options } = useRelationalGraphOptions(rootModule ?? void 0);
770
- const { hoveredNode, setHoveredNode, toggleSelectedElement } = useElements(hideLabels);
771
- const { mod, onModuleDetails } = useModuleDetails(rootModule, () => setHoveredNode(void 0));
772
- return /* @__PURE__ */ jsx10(WithExtensions, { children: /* @__PURE__ */ jsx10(
773
- NodeRelationalGraphFlexBox,
774
- {
775
- actions: mod ? null : hideActions ? null : /* @__PURE__ */ jsx10(Button3, { size: "small", onClick: handleToggleLabels, variant: "contained", children: "Toggle Labels" }),
776
- showDetails: !!mod,
777
- detail: /* @__PURE__ */ jsx10(DetailsFlexbox, { onClose: () => onModuleDetails(null) }),
778
- options,
779
- ref: cytoscapeRef,
780
- width: "100%",
781
- ...props,
782
- children: /* @__PURE__ */ jsx10(ModuleGraphNodeHover, { node: hoveredNode, children: (element) => /* @__PURE__ */ jsx10(
783
- StyledModuleHoverPopper,
784
- {
785
- anchorEl: element,
786
- container: cytoscapeRef.current,
787
- node: hoveredNode,
788
- onClose: () => setHoveredNode(void 0),
789
- onModuleExplore: toggleSelectedElement,
790
- onModuleDetails: disableModuleDetails ? void 0 : onModuleDetails,
791
- placement: "top",
792
- open: true
793
- }
794
- ) })
795
- }
796
- ) });
797
- };
798
- var ModuleGraphFlexBoxWithProvider = (props) => {
799
- return /* @__PURE__ */ jsx10(CytoscapeInstanceProvider, { children: /* @__PURE__ */ jsx10(ModuleGraphFlexBox, { ...props }) });
800
- };
801
- export {
802
- ColaLayout,
803
- ConcentricLayout,
804
- CyIconSet,
805
- CytoscapeElements,
806
- CytoscapeInstanceContext,
807
- CytoscapeInstanceProvider,
808
- EdgeStyled,
809
- ModuleCardParser,
810
- ModuleGraphFlexBox,
811
- ModuleGraphFlexBoxWithProvider,
812
- Node,
813
- NodeAsRoot,
814
- NodeRelationalGraph,
815
- NodeRelationalGraphFlexBox,
816
- NodeWithName,
817
- ProvidedNodeRenderer,
818
- encodeSvg,
819
- generateIconMap,
820
- parseModuleType,
821
- useCytoscapeElements,
822
- useCytoscapeInstance,
823
- useCytoscapeOptions,
824
- useElements,
825
- useModuleDetails,
826
- useRelationalGraphOptions
827
- };
1
+ import{asArchivistInstance as Me,isArchivistInstance as we}from"@xyo-network/archivist-model";import{asDivinerInstance as Fe,isDivinerInstance as ke}from"@xyo-network/diviner-model";import{ArchivistCard as Be}from"@xyo-network/react-archivist";import{DivinerCard as De,ModuleCard as Te}from"@xyo-network/react-module";import{jsx as L}from"react/jsx-runtime";var Ro=({mod:e})=>{switch(!0){case we(e):return L(Be,{mod:Me(e)});case ke(e):return L(De,{mod:Fe(e)});default:return L(Te,{mod:e})}};import{Button as xo}from"@mui/material";import{useRef as yo}from"react";import{createContextEx as Ae}from"@xyo-network/react-shared";var w=Ae();import{useEffect as Ge,useState as Le}from"react";import{jsx as We}from"react/jsx-runtime";var J=({children:e,defaultInstance:o})=>{let[t,r]=Le(o);return Ge(()=>{r(o)},[o]),We(w.Provider,{value:{cy:t,provided:!0,setCy:r},children:e})};import{useContextEx as He}from"@xyo-network/react-shared";var h=(e=!1)=>He(w,"CytoscapeInstance",e);import{useAsyncEffect as ot}from"@xylabs/react-async-effect";import{isNodeInstance as rt}from"@xyo-network/node-model";import{useEffect as nt,useState as st}from"react";import{exists as Ke}from"@xylabs/exists";import{renderToStaticMarkup as ze}from"react-dom/server";var Oe="data:image/svg+xml,",K=(e,o)=>{let t=ze(e),n=new DOMParser().parseFromString(t,"text/html").querySelectorAll("svg")[0];return n&&(n.setAttribute("xmlns","http://www.w3.org/2000/svg"),n.setAttribute("height","100"),n.style.fill=o??"black"),`${Oe}${window.encodeURIComponent(n.outerHTML)}`};var X=()=>({archivist:"",bridge:"",diviner:"",module:"",node:"",sentinel:"",witness:""});var Y={centerGraph:!1,convergenceThreshold:.01,name:"cola"};var F={concentric:function(e){return e.degree(!1)},levelWidth:function(){return 2},minNodeSpacing:75,name:"concentric"};import{isArchivistInstance as $e}from"@xyo-network/archivist-model";import{isBridgeInstance as Ue}from"@xyo-network/bridge-model";import{isDivinerInstance as Ve}from"@xyo-network/diviner-model";import{isNodeInstance as Qe}from"@xyo-network/node-model";import{isSentinelInstance as qe}from"@xyo-network/sentinel-model";import{isWitnessModule as Je}from"@xyo-network/witness-model";var Z=e=>{let o="module";return e&&($e(e)?o="archivist":Ue(e)?o="bridge":Ve(e)?o="diviner":Qe(e)?o="node":qe(e)?o="sentinel":Je(e)?o="witness":o="module"),o};var x={MaxNameLength:20,buildEdge(e,o,t){return{data:{id:`${e.data.id}/${o.data.id}`,source:e.data.id,target:o.data.id,...t}}},async buildElements(e){let o=await x.recurseNodes(e);return await this.buildElementsFromInfo(o,void 0,["activeNode"])},async buildElementsFromInfo(e,o,t=[]){let r=x.buildNode(e.mod,{childCount:e.children.length,depth:e.depth},t),n=o?x.buildEdge(o,r,{depth:e.depth,siblingCount:e.children.length}):void 0,s=[r];n&&s.push(n);for(let i of e.children)s.push(...await this.buildElementsFromInfo(i,r));return s},buildNode(e,o,t){let{address:r,id:n}=e;return{classes:t,data:{address:r,id:r,name:n,type:Z(e),...o}}},buildRootNode:e=>x.buildNode(e,{},["activeNode"]),normalizeName(e){if(e)return e.length>this.MaxNameLength?`${e.slice(0,20)}...`:e},async recurseNodes(e,o=10,t=1){let r={children:[],depth:t,mod:e};if(o>0){let n=await e.resolve("*",{direction:"down",maxDepth:1});r.children=(await Promise.all(n.map(async s=>{if(s.address!==e.address)return await this.recurseNodes(s,o-1,t+1)}))).filter(Ke)}return r}};import{BubbleChartRounded as Xe,Hub as Ye,InsertLinkRounded as Ze,Inventory2Rounded as _e,QuestionMarkRounded as je,TimerRounded as et,VisibilityRounded as tt}from"@mui/icons-material";var _={archivist:_e,bridge:Ze,diviner:Xe,module:je,node:Ye,sentinel:et,witness:tt};var j=(e,o)=>({selector:"node[name]",style:{color:e,"font-family":"Lexend Deca, Helvetica, sans-serif","font-size":12,"overlay-padding":"6px","text-halign":"center","text-outline-color":o,"text-outline-width":"1px","text-valign":"top"}}),ee=(e,o,t=!1)=>({selector:"node",style:{"background-color":o,"background-height":"75%","background-image":r=>e[r.data("type")],"background-width":"24",label:t?void 0:"data(name)",shape:"round-rectangle"}}),te=e=>({selector:".activeNode",style:{"background-color":e}}),oe=(e,o)=>({selector:"edge",style:{"curve-style":"bezier","line-color":e,"line-opacity":.1,"target-arrow-color":o,"target-arrow-shape":"triangle",width:3}});var b=e=>{let[o,t]=st([]);return ot(async()=>{let r=e==null?void 0:e.deref();if(r){let n=await x.buildElements(r)??[];t(n)}},[e]),nt(()=>{let r,n;return e&&rt(e)&&(r=e.on("moduleAttached",async()=>{let s=await x.buildElements(e)??[];t(s)}),n=e.on("moduleDetached",async()=>{let s=await x.buildElements(e)??[];t(s)})),()=>{r==null||r(),n==null||n()}},[e]),o};import{useCallback as it,useEffect as re,useState as at}from"react";var ne=e=>{let{cy:o}=h(!0),[t,r]=at(),n=it(s=>{s.on("mouseover tap",()=>{r(s)})},[]);return re(()=>{e&&e.nodes().forEach(n)},[n,e]),re(()=>{var s;(s=o==null?void 0:o.deref())==null||s.ready(()=>{var i;(i=o==null?void 0:o.deref())==null||i.nodes().forEach(n)})},[o,n]),[t,r]};import{useWeakModuleFromNode as lt}from"@xyo-network/react-node";import{useMemo as dt}from"react";var se=e=>{let o=dt(()=>{let{address:n}=(e==null?void 0:e.data())??{};return n},[e]),[t]=lt(o);return b(t)};import{useEffect as ct,useState as pt}from"react";var ie=(e=[],o)=>{let{cy:t}=h(!0),[r,n]=pt();return ct(()=>{var s,i;if(e.length>1){let a=(s=t==null?void 0:t.deref())==null?void 0:s.add(e);n(a),(i=t==null?void 0:t.deref())==null||i.layout(Y).run()}},[t,o,e]),r};import{useState as mt}from"react";var ae=()=>{let[e,o]=mt(),{cy:t}=h(!0),r=s=>{var a;let i=(a=t==null?void 0:t.deref())==null?void 0:a.nodes();i==null||i.toggleClass("activeNode",!1),s.toggleClass("activeNode",!0)};return{selectedElement:e,toggleSelectedElement:s=>{var a,l;let i=(l=(a=t==null?void 0:t.deref())==null?void 0:a.nodes(`[id="${s}"]`))==null?void 0:l[0];i&&(o(i),r(i))}}};var le=e=>{let{selectedElement:o,toggleSelectedElement:t}=ae(),r=se(o),n=ie(r,e),[s,i]=ne(n);return{hoveredNode:s,setHoveredNode:i,toggleSelectedElement:t}};import{useMemo as xt}from"react";import{useTheme as gt}from"@mui/material";import{useMemo as ht}from"react";import{useTheme as ut}from"@mui/material";import{useMemo as ft}from"react";import{jsx as Ct}from"react/jsx-runtime";var de=()=>{let e=ut();return ft(()=>{let t=X();return Object.entries(_).reduce((r,[n,s])=>{let i=Ct(s,{fontSize:"small"});return r[n]=K(i,e.palette.getContrastText(e.palette.text.primary)),r},t)},[e.palette])};var k=(e=!1)=>{let o=gt(),t=de();return ht(()=>[ee(t,o.palette.primary.main,e),j(o.palette.text.primary,o.palette.getContrastText(o.palette.text.primary)),te(o.palette.secondary.main),oe(o.palette.divider,o.palette.divider)],[t,e,o])};var B=(e,o,t)=>{let r=k(),n=t??F,s=o??r;return xt(()=>{if(e&&n&&s)return{elements:e,layout:n,style:s}},[e,t,o])};import{usePromise as yt}from"@xylabs/react-promise";import{useEffect as ce,useState as vt}from"react";var pe=(e,o)=>{let{cy:t}=h(),[r,n]=vt(),[s]=yt(async()=>{if(r===null)return null;let a=e==null?void 0:e.deref();if(r&&a)return await a.resolve(r)??null},[r,e]);return ce(()=>{var C;let a=new ResizeObserver(()=>{var p,c;if(r===null)setTimeout(()=>{var d;(d=t==null?void 0:t.deref())==null||d.center()},100);else if(s&&t){let d=(c=(p=t==null?void 0:t.deref())==null?void 0:p.nodes(`[id="${r}"]`))==null?void 0:c[0];setTimeout(()=>{var f;(f=t==null?void 0:t.deref())==null||f.center(d)},100)}}),l=(C=t==null?void 0:t.deref())==null?void 0:C.container();return l&&a.observe(l),()=>{l&&a.unobserve(l)}},[t,r,s,e]),ce(()=>{s&&(o==null||o())},[t,r,s,o]),{mod:s,onModuleDetails:a=>{var d,f,N,E,S;let l=(d=t==null?void 0:t.deref())==null?void 0:d.nodes(`[id="${a}"]`),C=(N=t==null?void 0:t.deref())==null?void 0:N.nodes(`[id="${(f=e==null?void 0:e.deref())==null?void 0:f.address}"]`),p=(E=t==null?void 0:t.deref())==null?void 0:E.nodes(`[id="${s==null?void 0:s.address}"]`),c=(S=t==null?void 0:t.deref())==null?void 0:S.nodes(`[id != "${a}"]`);if(a)l==null||l.toggleClass("activeNode",!0),c==null||c.toggleClass("activeNode",!1);else{c==null||c.toggleClass("activeNode",!1);let v=p!=null&&p.length?p:C;v==null||v.toggleClass("activeNode",!0)}n(a)}}};import{useState as It}from"react";var me=e=>{let[o,t]=It(!0),r=()=>{t(a=>!a)},n=b(e),s=k(o),i=B(n,s,F);return{handleToggleLabels:r,hideLabels:o,options:i}};import D from"cytoscape";import Nt from"cytoscape-cola";import Et from"cytoscape-cose-bilkent";import bt from"cytoscape-dagre";import Rt from"cytoscape-euler";import{useEffect as Pt,useState as St}from"react";import{Fragment as Mt,jsx as wt}from"react/jsx-runtime";var ue=({children:e})=>{let[o,t]=St(!1);return Pt(()=>{D.use(Nt),D.use(bt),D.use(Et),D.use(Rt),t(!0)},[]),wt(Mt,{children:o?e:void 0})};import{Box as Ft,Button as fe,ButtonGroup as kt,Card as Bt,CardHeader as Dt,Paper as Tt,useTheme as At}from"@mui/material";import{asAddress as Ce}from"@xylabs/hex";import{FlexCol as T,FlexGrowRow as Gt,FlexRow as Lt}from"@xylabs/react-flexbox";import{Identicon as Wt}from"@xylabs/react-identicon";import{useWeakModuleFromNode as Ht}from"@xyo-network/react-node";import P from"cytoscape";import zt from"cytoscape-cola";import Ot from"cytoscape-cose-bilkent";import $t from"cytoscape-dagre";import Ut from"cytoscape-euler";import{forwardRef as Vt,useEffect as W,useRef as Qt,useState as H}from"react";import{jsx as u,jsxs as A}from"react/jsx-runtime";var ge=(e,o="cola",t)=>{e==null||e.layout({name:o,...t}).run()},qt=(e="cola")=>{switch(e){case"dagre":{P.use($t);break}case"euler":{P.use(Ut);break}case"cose-bilkent":{P.use(Ot);break}case"cola":{P.use(zt);break}}},Jt=({name:e,address:o,...t})=>u(Bt,{elevation:3,...t,children:u(Dt,{avatar:u(Tt,{elevation:6,sx:{bgcolor:"#fff",p:1},children:u(Wt,{value:o,size:24})}),title:e,subheader:o})}),R=Vt(({actions:e,children:o,node:t,layout:r,layoutOptions:n,showDetails:s,detail:i,options:a,onHover:l,...C},p)=>{var V;let c=At(),[d,f]=H(),N=Qt(),[E,S]=H(),[v,$]=H(),[G]=Ht(v,{node:t});W(()=>{d==null||d.on("mouseover tap",({target:I})=>{var Q,q;let m=I,Se=(Q=m==null?void 0:m.renderedBoundingBox)==null?void 0:Q.call(m);S(Se);let M=(q=m.id)==null?void 0:q.call(m);M&&(M.includes("/")?($(void 0),l==null||l()):($(Ce(M)),l==null||l(Ce(M))))})},[l,d]);let U=()=>{d==null||d.reset(),ge(d,r??"euler",n)};return W(()=>{let I,m=N.current;return m&&(I=P({container:m,...a}),f(I)),()=>{I==null||I.destroy(),f(void 0)}},[a,N,n]),W(()=>{d&&(qt(r),ge(d,r??"euler",n))},[d,n,r]),A(T,{id:"relational-graph-wrapper",ref:p,...C,children:[v&&E?u(Ft,{position:"absolute",top:E.y1,left:E.x1,zIndex:100,children:u(Jt,{address:v,name:((V=G==null?void 0:G.deref())==null?void 0:V.id)??"Unknown"})}):null,u(Lt,{justifyContent:"start",width:"100%",children:e===null?null:e?A(kt,{children:[e,u(fe,{size:"small",variant:"contained",onClick:U,children:"Reset View"})]}):u(fe,{size:"small",variant:"contained",onClick:U,children:"Reset"})}),A(Gt,{width:"100%",alignItems:"start",children:[s?u(T,{height:"100%",width:"85%",children:i}):null,A(T,{justifyContent:"start",classes:"cytoscape-wrap",width:s?"15%":"100%",height:s?"50%":"100%",border:s?`1px solid ${c.palette.divider}`:void 0,children:[u(T,{alignItems:"stretch",position:"absolute",width:"100%",height:"100%",ref:N}),o]})]})]})});R.displayName="NodeRelationalGraph";var En=R;import{useWeakProvidedNode as Kt}from"@xyo-network/react-node";import{jsx as Xt}from"react/jsx-runtime";var wn=({node:e,...o})=>{let[t]=Kt(),r=b(e??t),n=B(r);return Xt(R,{alignItems:"stretch",flexGrow:1,height:"100%",options:n,...o})};import{CancelRounded as Yt}from"@mui/icons-material";import{IconButton as Zt}from"@mui/material";import{FlexGrowCol as _t,FlexRow as jt}from"@xylabs/react-flexbox";import{jsx as z,jsxs as eo}from"react/jsx-runtime";var he=({children:e,onClose:o})=>eo(_t,{alignItems:"end",justifyContent:"start",id:"module-detail",width:"100%",p:2,gap:2,children:[z(jt,{justifyContent:"end",children:z(Zt,{onClick:o,size:"small",children:z(Yt,{})})}),e]});import{styled as oo}from"@mui/material";import{FlexCol as ro}from"@xylabs/react-flexbox";import{useEffect as O,useRef as to,useState as xe}from"react";var ye=e=>{let o=to(null),[t,r]=xe(null),[n,s]=xe(e==null?void 0:e.renderedBoundingBox());return O(()=>{r(null)},[e]),O(()=>{e&&s(e.renderedBoundingBox());let i=()=>{s(e==null?void 0:e.renderedBoundingBox())};return e==null||e.on("position",i),()=>{e==null||e.off("position",void 0,i)}},[e]),O(()=>{r(o.current)},[n]),{boundingBox:n,currentElement:t,ref:o}};import{Fragment as Ie,jsx as ve,jsxs as so}from"react/jsx-runtime";var Ne=({children:e,node:o})=>{let{boundingBox:t,ref:r,currentElement:n}=ye(o);return so(Ie,{children:[ve(no,{ref:r,left:t==null?void 0:t.x1,height:t==null?void 0:t.h,top:t==null?void 0:t.y1,width:t==null?void 0:t.w}),o?ve(Ie,{children:e==null?void 0:e(n)}):null]})},no=oo(ro,{name:"StyledNodeGhostElementFlexCol"})(()=>({cursor:"pointer",pointerEvents:"none",position:"absolute"}));import{CancelRounded as io}from"@mui/icons-material";import{Button as Ee,Card as ao,CardActions as lo,CardHeader as co,IconButton as po,Paper as mo,Popper as uo,styled as Re}from"@mui/material";import{Identicon as fo}from"@xylabs/react-identicon";import{Fragment as ho,jsx as g,jsxs as be}from"react/jsx-runtime";var Co=({anchorEl:e,onClose:o,onModuleDetails:t,onModuleExplore:r,node:n,...s})=>{let{address:i,name:a}=(n==null?void 0:n.data())??{};return g(ho,{children:e?g(uo,{anchorEl:e,...s,children:be(ao,{elevation:3,children:[g(co,{action:o?g(po,{size:"small",onClick:o,children:g(io,{})}):null,avatar:g(mo,{elevation:6,sx:{bgcolor:"#fff",p:1},children:g(fo,{value:i,size:24})}),title:a,subheader:i}),be(go,{children:[t?g(Ee,{onClick:()=>t==null?void 0:t(i),size:"small",variant:"contained",children:"Details"}):null,r?g(Ee,{onClick:()=>r==null?void 0:r(i),size:"small",variant:"contained",children:"Explore"}):null]})]})}):null})},Pe=Re(Co,{name:"StyledComponents"})(()=>({zIndex:2})),go=Re(lo,{name:"StyledCardActions"})(()=>({display:"flex",justifyContent:"center"}));import{jsx as y}from"react/jsx-runtime";var vo=({hideActions:e,rootModule:o,disableModuleDetails:t,...r})=>{let n=yo(null),{handleToggleLabels:s,hideLabels:i,options:a}=me(o??void 0),{hoveredNode:l,setHoveredNode:C,toggleSelectedElement:p}=le(i),{mod:c,onModuleDetails:d}=pe(o,()=>C(void 0));return y(ue,{children:y(R,{actions:c||e?null:y(xo,{size:"small",onClick:s,variant:"contained",children:"Toggle Labels"}),showDetails:!!c,detail:y(he,{onClose:()=>d(null)}),options:a,ref:n,width:"100%",...r,children:y(Ne,{node:l,children:f=>y(Pe,{anchorEl:f,container:n.current,node:l,onClose:()=>C(void 0),onModuleExplore:p,onModuleDetails:t?void 0:d,placement:"top",open:!0})})})})},as=e=>y(J,{children:y(vo,{...e})});export{Y as ColaLayout,F as ConcentricLayout,_ as CyIconSet,x as CytoscapeElements,w as CytoscapeInstanceContext,J as CytoscapeInstanceProvider,oe as EdgeStyled,Ro as ModuleCardParser,vo as ModuleGraphFlexBox,as as ModuleGraphFlexBoxWithProvider,ee as Node,te as NodeAsRoot,En as NodeRelationalGraph,R as NodeRelationalGraphFlexBox,j as NodeWithName,wn as ProvidedNodeRenderer,K as encodeSvg,X as generateIconMap,Z as parseModuleType,b as useCytoscapeElements,h as useCytoscapeInstance,B as useCytoscapeOptions,le as useElements,pe as useModuleDetails,me as useRelationalGraphOptions};
828
2
  //# sourceMappingURL=index.js.map