@xyo-network/react-node-renderer 2.71.8 → 2.71.10

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/package.json CHANGED
@@ -23,10 +23,10 @@
23
23
  "@xyo-network/module-events": "^2.94.9",
24
24
  "@xyo-network/module-model": "^2.94.9",
25
25
  "@xyo-network/node-model": "^2.94.9",
26
- "@xyo-network/react-archivist": "~2.71.8",
27
- "@xyo-network/react-module": "~2.71.8",
28
- "@xyo-network/react-node": "~2.71.8",
29
- "@xyo-network/react-shared": "~2.71.8",
26
+ "@xyo-network/react-archivist": "~2.71.10",
27
+ "@xyo-network/react-module": "~2.71.10",
28
+ "@xyo-network/react-node": "~2.71.10",
29
+ "@xyo-network/react-shared": "~2.71.10",
30
30
  "@xyo-network/sentinel-model": "^2.94.9",
31
31
  "@xyo-network/witness-model": "^2.94.9",
32
32
  "cytoscape": "^3.28.1",
@@ -52,8 +52,8 @@
52
52
  "@xyo-network/http-bridge": "^2.94.9",
53
53
  "@xyo-network/id-plugin": "^2.91.4",
54
54
  "@xyo-network/node-memory": "^2.94.9",
55
- "@xyo-network/react-storybook": "~2.71.8",
56
- "@xyo-network/react-wallet": "~2.71.8",
55
+ "@xyo-network/react-storybook": "~2.71.10",
56
+ "@xyo-network/react-wallet": "~2.71.10",
57
57
  "@xyo-network/sentinel": "^2.94.9",
58
58
  "typescript": "^5.4.3"
59
59
  },
@@ -108,6 +108,6 @@
108
108
  },
109
109
  "sideEffects": false,
110
110
  "types": "dist/browser/index.d.ts",
111
- "version": "2.71.8",
111
+ "version": "2.71.10",
112
112
  "type": "module"
113
113
  }
@@ -6,37 +6,34 @@ import { parseModuleType } from './lib'
6
6
 
7
7
  interface ModuleInfo {
8
8
  children: ModuleInfo[]
9
+ depth: number
9
10
  module: ModuleInstance
10
11
  }
11
12
 
12
13
  export const CytoscapeElements = {
13
14
  MaxNameLength: 20,
14
15
 
15
- buildEdge(rootNode: ElementDefinition, newNode: ElementDefinition) {
16
+ buildEdge(rootNode: ElementDefinition, newNode: ElementDefinition, properties?: { [key: string]: unknown }) {
16
17
  return {
17
18
  data: {
18
19
  id: `${rootNode.data.id}/${newNode.data.id}`,
19
20
  source: rootNode.data.id,
20
21
  target: newNode.data.id,
22
+ ...properties,
21
23
  },
22
24
  }
23
25
  },
24
26
 
25
27
  async buildElements(module: ModuleInstance): Promise<ElementDefinition[]> {
26
28
  const info = await CytoscapeElements.recurseNodes(module)
27
- const newElements: ElementDefinition[] = await this.buildElementsFromInfo(info, undefined, undefined, ['activeNode'])
29
+ const newElements: ElementDefinition[] = await this.buildElementsFromInfo(info, undefined, ['activeNode'])
28
30
 
29
31
  return newElements
30
32
  },
31
33
 
32
- async buildElementsFromInfo(
33
- info: ModuleInfo,
34
- root?: ElementDefinition,
35
- properties: { [key: string]: unknown } = {},
36
- classes: string[] = [],
37
- ): Promise<ElementDefinition[]> {
38
- const newNode = CytoscapeElements.buildNode(info.module, properties, classes)
39
- const newEdge = root ? CytoscapeElements.buildEdge(root, newNode) : undefined
34
+ async buildElementsFromInfo(info: ModuleInfo, root?: ElementDefinition, classes: string[] = []): Promise<ElementDefinition[]> {
35
+ const newNode = CytoscapeElements.buildNode(info.module, { childCount: info.children.length, depth: info.depth }, classes)
36
+ const newEdge = root ? CytoscapeElements.buildEdge(root, newNode, { depth: info.depth, siblingCount: info.children.length }) : undefined
40
37
  const newElements: ElementDefinition[] = [newNode]
41
38
  if (newEdge) {
42
39
  newElements.push(newEdge)
@@ -73,8 +70,8 @@ export const CytoscapeElements = {
73
70
  return name
74
71
  },
75
72
 
76
- async recurseNodes(root: ModuleInstance, maxDepth = 10): Promise<ModuleInfo> {
77
- const info: ModuleInfo = { children: [], module: root }
73
+ async recurseNodes(root: ModuleInstance, maxDepth = 10, depth = 1): Promise<ModuleInfo> {
74
+ const info: ModuleInfo = { children: [], depth, module: root }
78
75
 
79
76
  if (maxDepth > 0) {
80
77
  const children = await root.resolve('*', { direction: 'down', maxDepth: 1 })
@@ -82,7 +79,7 @@ export const CytoscapeElements = {
82
79
  await Promise.all(
83
80
  children.map(async (child) => {
84
81
  if (child.address !== root.address) {
85
- return await this.recurseNodes(child, maxDepth - 1)
82
+ return await this.recurseNodes(child, maxDepth - 1, depth + 1)
86
83
  // don't re add the root module that was passed in
87
84
  }
88
85
  }),