@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.
@@ -1,63 +1,39 @@
1
1
  import { useAsyncEffect } from '@xylabs/react-shared';
2
- import { NodeWrapper } from '@xyo-network/node';
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 = (nodeAddressOrName, onModuleError) => {
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 (mounted) => {
22
- if ((node || module) && refresh) {
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(wrappedNode);
29
- if (mounted())
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(wrappedNode, address);
35
- if (mounted())
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
- if (mounted())
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
- }, [module, node, nodeAddressOrName, refresh]);
51
- useEffect(() => {
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;AAErD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,SAAS,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAA;AAE3E,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAE3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAEnD;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,iBAA0B,EAAE,aAAsC,EAAE,EAAE;IACzG,MAAM,CAAC,IAAI,CAAC,GAAG,sBAAsB,EAAE,CAAA;IACvC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,SAAS,CAAC,iBAAiB,CAAC,CAAA;IAC1D,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAsB,EAAE,CAAC,CAAA;IACjE,MAAM,CAAC,OAAO,EAAE,UAAU,CA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,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
@@ -1,3 +1,5 @@
1
1
  export * from './components';
2
+ export * from './Cytoscape';
2
3
  export * from './hooks';
4
+ export * from './lib';
3
5
  //# sourceMappingURL=index.js.map
@@ -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: (nodeAddressOrName?: string, onModuleError?: ((error: Error) => void) | undefined) => ElementDefinition[];
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":"AAIA,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAK7C;;;GAGG;AACH,eAAO,MAAM,oBAAoB,uBAAwB,MAAM,2BAA0B,KAAK,KAAK,IAAI,qCAuDtG,CAAA"}
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"}
@@ -1,3 +1,5 @@
1
1
  export * from './components';
2
+ export * from './Cytoscape';
2
3
  export * from './hooks';
4
+ export * from './lib';
3
5
  //# sourceMappingURL=index.d.ts.map
@@ -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-node": "^2.47.39",
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.39",
43
- "@xyo-network/react-storybook": "^2.47.39",
44
- "@xyo-network/react-wallet": "^2.47.39",
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.39"
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 elements = useCytoscapeElements()
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 elements = useCytoscapeElements('ChildNode')
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 { useEffect, useState } from 'react'
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 = (nodeAddressOrName?: string, onModuleError?: (error: Error) => void) => {
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 (mounted) => {
27
- if ((node || module) && refresh) {
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(wrappedNode)
34
- if (mounted()) setElements(() => [newRootNode])
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(wrappedNode, address)
41
- if (mounted()) setElements((previous) => [...previous, newNode])
27
+ const newNode = await CytoscapeElements.buildChild(targetNode, address)
28
+ newElements.push(newNode)
42
29
 
43
30
  const newEdge = CytoscapeElements.buildEdge(newRootNode, newNode)
44
- if (mounted()) setElements((previous) => [...previous, newEdge])
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
- [module, node, nodeAddressOrName, refresh],
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
@@ -1,2 +1,4 @@
1
1
  export * from './components'
2
+ export * from './Cytoscape'
2
3
  export * from './hooks'
4
+ export * from './lib'