@xyo-network/react-node-renderer 2.47.39 → 2.47.41
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/cjs/hooks/cytoscape/useCytoscapeElements.js +11 -35
- package/dist/cjs/hooks/cytoscape/useCytoscapeElements.js.map +1 -1
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/docs.json +1983 -265
- package/dist/esm/hooks/cytoscape/useCytoscapeElements.js +12 -36
- package/dist/esm/hooks/cytoscape/useCytoscapeElements.js.map +1 -1
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/types/hooks/cytoscape/useCytoscapeElements.d.ts +2 -1
- package/dist/types/hooks/cytoscape/useCytoscapeElements.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +5 -6
- package/src/components/RelationalGraph.stories.tsx +8 -5
- package/src/hooks/cytoscape/useCytoscapeElements.ts +12 -33
- package/src/index.ts +2 -0
|
@@ -1,63 +1,39 @@
|
|
|
1
1
|
import { useAsyncEffect } from '@xylabs/react-shared';
|
|
2
|
-
import {
|
|
3
|
-
import { useModule, useProvidedWrappedNode } from '@xyo-network/react-node';
|
|
4
|
-
import { useEffect, useState } from 'react';
|
|
2
|
+
import { useState } from 'react';
|
|
5
3
|
import { CytoscapeElements } from '../../Cytoscape';
|
|
6
4
|
/**
|
|
7
5
|
* Note: Relies on describe but could eventually be converted to a discover call
|
|
8
6
|
* Logic would be similar to what the bridge does
|
|
9
7
|
*/
|
|
10
|
-
export const useCytoscapeElements = (
|
|
11
|
-
const [node] = useProvidedWrappedNode();
|
|
12
|
-
const [module, moduleError] = useModule(nodeAddressOrName);
|
|
8
|
+
export const useCytoscapeElements = (targetNode) => {
|
|
13
9
|
const [elements, setElements] = useState([]);
|
|
14
|
-
const [refresh, setRefresh] = useState(1);
|
|
15
|
-
useEffect(() => {
|
|
16
|
-
if (moduleError)
|
|
17
|
-
onModuleError?.(moduleError);
|
|
18
|
-
}, [moduleError, onModuleError]);
|
|
19
10
|
useAsyncEffect(
|
|
20
11
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
21
|
-
async (
|
|
22
|
-
if (
|
|
23
|
-
const wrappedNode = nodeAddressOrName ? NodeWrapper.wrap(module) : node;
|
|
24
|
-
if (!wrappedNode) {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
12
|
+
async () => {
|
|
13
|
+
if (targetNode) {
|
|
27
14
|
try {
|
|
28
|
-
const [description, newRootNode] = await CytoscapeElements.buildRootNode(
|
|
29
|
-
|
|
30
|
-
setElements(() => [newRootNode]);
|
|
15
|
+
const [description, newRootNode] = await CytoscapeElements.buildRootNode(targetNode);
|
|
16
|
+
const newElements = [newRootNode];
|
|
31
17
|
const children = description.children;
|
|
32
18
|
await Promise.allSettled((children ?? [])?.map(async (address) => {
|
|
33
19
|
try {
|
|
34
|
-
const newNode = await CytoscapeElements.buildChild(
|
|
35
|
-
|
|
36
|
-
setElements((previous) => [...previous, newNode]);
|
|
20
|
+
const newNode = await CytoscapeElements.buildChild(targetNode, address);
|
|
21
|
+
newElements.push(newNode);
|
|
37
22
|
const newEdge = CytoscapeElements.buildEdge(newRootNode, newNode);
|
|
38
|
-
|
|
39
|
-
setElements((previous) => [...previous, newEdge]);
|
|
23
|
+
newElements.push(newEdge);
|
|
40
24
|
}
|
|
41
25
|
catch (e) {
|
|
42
26
|
console.error('Error parsing children', e);
|
|
43
27
|
}
|
|
44
28
|
}));
|
|
29
|
+
setElements(newElements);
|
|
45
30
|
}
|
|
46
31
|
catch (e) {
|
|
47
32
|
console.error('Error Getting initial description', e);
|
|
48
33
|
}
|
|
49
34
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
let listener;
|
|
53
|
-
if (node) {
|
|
54
|
-
listener = node.onAny((eventName) => {
|
|
55
|
-
if (eventName === 'moduleAttached')
|
|
56
|
-
setRefresh((previous) => previous + 1);
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
return () => listener?.();
|
|
60
|
-
}, [node]);
|
|
35
|
+
return () => console.log('unmounted');
|
|
36
|
+
}, [targetNode]);
|
|
61
37
|
return elements;
|
|
62
38
|
};
|
|
63
39
|
//# sourceMappingURL=useCytoscapeElements.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCytoscapeElements.js","sourceRoot":"","sources":["../../../../src/hooks/cytoscape/useCytoscapeElements.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"useCytoscapeElements.js","sourceRoot":"","sources":["../../../../src/hooks/cytoscape/useCytoscapeElements.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAGrD,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEhC,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAEnD;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,UAAwB,EAAE,EAAE;IAC/D,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAsB,EAAE,CAAC,CAAA;IAEjE,cAAc;IACZ,uDAAuD;IACvD,KAAK,IAAI,EAAE;QACT,IAAI,UAAU,EAAE;YACd,IAAI;gBACF,MAAM,CAAC,WAAW,EAAE,WAAW,CAAC,GAAG,MAAM,iBAAiB,CAAC,aAAa,CAAC,UAAU,CAAC,CAAA;gBACpF,MAAM,WAAW,GAAG,CAAC,WAAW,CAAC,CAAA;gBAEjC,MAAM,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAA;gBACrC,MAAM,OAAO,CAAC,UAAU,CACtB,CAAC,QAAQ,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;oBACtC,IAAI;wBACF,MAAM,OAAO,GAAG,MAAM,iBAAiB,CAAC,UAAU,CAAC,UAAU,EAAE,OAAO,CAAC,CAAA;wBACvE,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;wBAEzB,MAAM,OAAO,GAAG,iBAAiB,CAAC,SAAS,CAAC,WAAW,EAAE,OAAO,CAAC,CAAA;wBACjE,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;qBAC1B;oBAAC,OAAO,CAAC,EAAE;wBACV,OAAO,CAAC,KAAK,CAAC,wBAAwB,EAAE,CAAC,CAAC,CAAA;qBAC3C;gBACH,CAAC,CAAC,CACH,CAAA;gBACD,WAAW,CAAC,WAAW,CAAC,CAAA;aACzB;YAAC,OAAO,CAAC,EAAE;gBACV,OAAO,CAAC,KAAK,CAAC,mCAAmC,EAAE,CAAC,CAAC,CAAA;aACtD;SACF;QACD,OAAO,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAA;IACvC,CAAC,EACD,CAAC,UAAU,CAAC,CACb,CAAA;IAED,OAAO,QAAQ,CAAA;AACjB,CAAC,CAAA"}
|
package/dist/esm/index.js
CHANGED
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,SAAS,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,SAAS,CAAA;AACvB,cAAc,OAAO,CAAA"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { NodeWrapper } from '@xyo-network/node';
|
|
1
2
|
import { ElementDefinition } from 'cytoscape';
|
|
2
3
|
/**
|
|
3
4
|
* Note: Relies on describe but could eventually be converted to a discover call
|
|
4
5
|
* Logic would be similar to what the bridge does
|
|
5
6
|
*/
|
|
6
|
-
export declare const useCytoscapeElements: (
|
|
7
|
+
export declare const useCytoscapeElements: (targetNode?: NodeWrapper) => ElementDefinition[];
|
|
7
8
|
//# sourceMappingURL=useCytoscapeElements.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCytoscapeElements.d.ts","sourceRoot":"","sources":["../../../../src/hooks/cytoscape/useCytoscapeElements.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useCytoscapeElements.d.ts","sourceRoot":"","sources":["../../../../src/hooks/cytoscape/useCytoscapeElements.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAK7C;;;GAGG;AACH,eAAO,MAAM,oBAAoB,gBAAiB,WAAW,wBAoC5D,CAAA"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,SAAS,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,SAAS,CAAA;AACvB,cAAc,OAAO,CAAA"}
|
package/package.json
CHANGED
|
@@ -14,8 +14,7 @@
|
|
|
14
14
|
"@xylabs/react-shared": "^2.16.14",
|
|
15
15
|
"@xyo-network/module": "^2.53.36",
|
|
16
16
|
"@xyo-network/node": "^2.53.36",
|
|
17
|
-
"@xyo-network/react-
|
|
18
|
-
"@xyo-network/react-shared": "^2.47.39",
|
|
17
|
+
"@xyo-network/react-shared": "^2.47.41",
|
|
19
18
|
"cytoscape": "^3.23.0"
|
|
20
19
|
},
|
|
21
20
|
"peerDependencies": {
|
|
@@ -39,9 +38,9 @@
|
|
|
39
38
|
"@xyo-network/id-plugin": "^2.53.34",
|
|
40
39
|
"@xyo-network/module": "^2.53.34",
|
|
41
40
|
"@xyo-network/node": "^2.53.34",
|
|
42
|
-
"@xyo-network/react-node": "^2.47.
|
|
43
|
-
"@xyo-network/react-storybook": "^2.47.
|
|
44
|
-
"@xyo-network/react-wallet": "^2.47.
|
|
41
|
+
"@xyo-network/react-node": "^2.47.41",
|
|
42
|
+
"@xyo-network/react-storybook": "^2.47.41",
|
|
43
|
+
"@xyo-network/react-wallet": "^2.47.41",
|
|
45
44
|
"require-from-string": "^2.0.2",
|
|
46
45
|
"typescript": "^4.9.5"
|
|
47
46
|
},
|
|
@@ -88,5 +87,5 @@
|
|
|
88
87
|
},
|
|
89
88
|
"sideEffects": false,
|
|
90
89
|
"types": "dist/types/index.d.ts",
|
|
91
|
-
"version": "2.47.
|
|
90
|
+
"version": "2.47.41"
|
|
92
91
|
}
|
|
@@ -4,11 +4,11 @@ import { HDWallet } from '@xyo-network/account'
|
|
|
4
4
|
import { ArchivistConfigSchema, MemoryArchivist } from '@xyo-network/archivist'
|
|
5
5
|
import { HttpBridge, HttpBridgeConfigSchema } from '@xyo-network/bridge'
|
|
6
6
|
import { IdWitness, IdWitnessConfigSchema } from '@xyo-network/id-plugin'
|
|
7
|
-
import { MemoryNode, NodeConfigSchema } from '@xyo-network/node'
|
|
8
|
-
import { NodeProvider } from '@xyo-network/react-node'
|
|
7
|
+
import { MemoryNode, NodeConfigSchema, NodeWrapper } from '@xyo-network/node'
|
|
8
|
+
import { NodeProvider, useModule, useProvidedWrappedNode } from '@xyo-network/react-node'
|
|
9
9
|
import { DefaultSeedPhrase } from '@xyo-network/react-storybook'
|
|
10
10
|
import { WalletProvider } from '@xyo-network/react-wallet'
|
|
11
|
-
import { useState } from 'react'
|
|
11
|
+
import { useMemo, useState } from 'react'
|
|
12
12
|
|
|
13
13
|
import { useCytoscapeElements, useCytoscapeOptions } from '../hooks'
|
|
14
14
|
import { NodeRelationalGraph } from './RelationalGraph'
|
|
@@ -69,13 +69,16 @@ export default {
|
|
|
69
69
|
const Template: ComponentStory<typeof NodeRelationalGraph> = (props) => <NodeRelationalGraph {...props} />
|
|
70
70
|
|
|
71
71
|
const TemplateDescribe: ComponentStory<typeof NodeRelationalGraph> = (props) => {
|
|
72
|
-
const
|
|
72
|
+
const [node] = useProvidedWrappedNode()
|
|
73
|
+
const elements = useCytoscapeElements(node)
|
|
73
74
|
const options = useCytoscapeOptions(elements)
|
|
74
75
|
return <NodeRelationalGraph options={options} {...props} />
|
|
75
76
|
}
|
|
76
77
|
|
|
77
78
|
const TemplateCustomAddress: ComponentStory<typeof NodeRelationalGraph> = (props) => {
|
|
78
|
-
const
|
|
79
|
+
const [node] = useModule('ChildNode')
|
|
80
|
+
const wrappedNode = useMemo(() => (node ? NodeWrapper.wrap(node) : undefined), [node])
|
|
81
|
+
const elements = useCytoscapeElements(wrappedNode)
|
|
79
82
|
const options = useCytoscapeOptions(elements)
|
|
80
83
|
return <NodeRelationalGraph options={options} {...props} />
|
|
81
84
|
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { useAsyncEffect } from '@xylabs/react-shared'
|
|
2
|
-
import { EventUnsubscribeFunction } from '@xyo-network/module'
|
|
3
2
|
import { NodeWrapper } from '@xyo-network/node'
|
|
4
|
-
import { useModule, useProvidedWrappedNode } from '@xyo-network/react-node'
|
|
5
3
|
import { ElementDefinition } from 'cytoscape'
|
|
6
|
-
import {
|
|
4
|
+
import { useState } from 'react'
|
|
7
5
|
|
|
8
6
|
import { CytoscapeElements } from '../../Cytoscape'
|
|
9
7
|
|
|
@@ -11,59 +9,40 @@ import { CytoscapeElements } from '../../Cytoscape'
|
|
|
11
9
|
* Note: Relies on describe but could eventually be converted to a discover call
|
|
12
10
|
* Logic would be similar to what the bridge does
|
|
13
11
|
*/
|
|
14
|
-
export const useCytoscapeElements = (
|
|
15
|
-
const [node] = useProvidedWrappedNode()
|
|
16
|
-
const [module, moduleError] = useModule(nodeAddressOrName)
|
|
12
|
+
export const useCytoscapeElements = (targetNode?: NodeWrapper) => {
|
|
17
13
|
const [elements, setElements] = useState<ElementDefinition[]>([])
|
|
18
|
-
const [refresh, setRefresh] = useState(1)
|
|
19
|
-
|
|
20
|
-
useEffect(() => {
|
|
21
|
-
if (moduleError) onModuleError?.(moduleError)
|
|
22
|
-
}, [moduleError, onModuleError])
|
|
23
14
|
|
|
24
15
|
useAsyncEffect(
|
|
25
16
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
26
|
-
async (
|
|
27
|
-
if (
|
|
28
|
-
const wrappedNode = nodeAddressOrName ? NodeWrapper.wrap(module) : node
|
|
29
|
-
if (!wrappedNode) {
|
|
30
|
-
return
|
|
31
|
-
}
|
|
17
|
+
async () => {
|
|
18
|
+
if (targetNode) {
|
|
32
19
|
try {
|
|
33
|
-
const [description, newRootNode] = await CytoscapeElements.buildRootNode(
|
|
34
|
-
|
|
20
|
+
const [description, newRootNode] = await CytoscapeElements.buildRootNode(targetNode)
|
|
21
|
+
const newElements = [newRootNode]
|
|
35
22
|
|
|
36
23
|
const children = description.children
|
|
37
24
|
await Promise.allSettled(
|
|
38
25
|
(children ?? [])?.map(async (address) => {
|
|
39
26
|
try {
|
|
40
|
-
const newNode = await CytoscapeElements.buildChild(
|
|
41
|
-
|
|
27
|
+
const newNode = await CytoscapeElements.buildChild(targetNode, address)
|
|
28
|
+
newElements.push(newNode)
|
|
42
29
|
|
|
43
30
|
const newEdge = CytoscapeElements.buildEdge(newRootNode, newNode)
|
|
44
|
-
|
|
31
|
+
newElements.push(newEdge)
|
|
45
32
|
} catch (e) {
|
|
46
33
|
console.error('Error parsing children', e)
|
|
47
34
|
}
|
|
48
35
|
}),
|
|
49
36
|
)
|
|
37
|
+
setElements(newElements)
|
|
50
38
|
} catch (e) {
|
|
51
39
|
console.error('Error Getting initial description', e)
|
|
52
40
|
}
|
|
53
41
|
}
|
|
42
|
+
return () => console.log('unmounted')
|
|
54
43
|
},
|
|
55
|
-
[
|
|
44
|
+
[targetNode],
|
|
56
45
|
)
|
|
57
46
|
|
|
58
|
-
useEffect(() => {
|
|
59
|
-
let listener: EventUnsubscribeFunction
|
|
60
|
-
if (node) {
|
|
61
|
-
listener = node.onAny((eventName) => {
|
|
62
|
-
if (eventName === 'moduleAttached') setRefresh((previous) => previous + 1)
|
|
63
|
-
})
|
|
64
|
-
}
|
|
65
|
-
return () => listener?.()
|
|
66
|
-
}, [node])
|
|
67
|
-
|
|
68
47
|
return elements
|
|
69
48
|
}
|
package/src/index.ts
CHANGED