@xyo-network/react-node-renderer 2.71.4 → 2.71.5

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 (51) hide show
  1. package/dist/browser/components/cytoscape-extensions/WithExtensions.d.cts.map +1 -1
  2. package/dist/browser/components/cytoscape-extensions/WithExtensions.d.mts.map +1 -1
  3. package/dist/browser/components/cytoscape-extensions/WithExtensions.d.ts.map +1 -1
  4. package/dist/browser/components/lib/RelationalGraphProps.d.cts +1 -0
  5. package/dist/browser/components/lib/RelationalGraphProps.d.cts.map +1 -1
  6. package/dist/browser/components/lib/RelationalGraphProps.d.mts +1 -0
  7. package/dist/browser/components/lib/RelationalGraphProps.d.mts.map +1 -1
  8. package/dist/browser/components/lib/RelationalGraphProps.d.ts +1 -0
  9. package/dist/browser/components/lib/RelationalGraphProps.d.ts.map +1 -1
  10. package/dist/browser/components/relational/graph/Graph.d.cts.map +1 -1
  11. package/dist/browser/components/relational/graph/Graph.d.mts.map +1 -1
  12. package/dist/browser/components/relational/graph/Graph.d.ts.map +1 -1
  13. package/dist/browser/components/relational/graph/ProvidedNodeRenderer.d.cts +1 -0
  14. package/dist/browser/components/relational/graph/ProvidedNodeRenderer.d.cts.map +1 -1
  15. package/dist/browser/components/relational/graph/ProvidedNodeRenderer.d.mts +1 -0
  16. package/dist/browser/components/relational/graph/ProvidedNodeRenderer.d.mts.map +1 -1
  17. package/dist/browser/components/relational/graph/ProvidedNodeRenderer.d.ts +1 -0
  18. package/dist/browser/components/relational/graph/ProvidedNodeRenderer.d.ts.map +1 -1
  19. package/dist/browser/index.cjs +14 -2
  20. package/dist/browser/index.cjs.map +1 -1
  21. package/dist/browser/index.js +14 -2
  22. package/dist/browser/index.js.map +1 -1
  23. package/dist/node/components/cytoscape-extensions/WithExtensions.d.cts.map +1 -1
  24. package/dist/node/components/cytoscape-extensions/WithExtensions.d.mts.map +1 -1
  25. package/dist/node/components/cytoscape-extensions/WithExtensions.d.ts.map +1 -1
  26. package/dist/node/components/lib/RelationalGraphProps.d.cts +1 -0
  27. package/dist/node/components/lib/RelationalGraphProps.d.cts.map +1 -1
  28. package/dist/node/components/lib/RelationalGraphProps.d.mts +1 -0
  29. package/dist/node/components/lib/RelationalGraphProps.d.mts.map +1 -1
  30. package/dist/node/components/lib/RelationalGraphProps.d.ts +1 -0
  31. package/dist/node/components/lib/RelationalGraphProps.d.ts.map +1 -1
  32. package/dist/node/components/relational/graph/Graph.d.cts.map +1 -1
  33. package/dist/node/components/relational/graph/Graph.d.mts.map +1 -1
  34. package/dist/node/components/relational/graph/Graph.d.ts.map +1 -1
  35. package/dist/node/components/relational/graph/ProvidedNodeRenderer.d.cts +1 -0
  36. package/dist/node/components/relational/graph/ProvidedNodeRenderer.d.cts.map +1 -1
  37. package/dist/node/components/relational/graph/ProvidedNodeRenderer.d.mts +1 -0
  38. package/dist/node/components/relational/graph/ProvidedNodeRenderer.d.mts.map +1 -1
  39. package/dist/node/components/relational/graph/ProvidedNodeRenderer.d.ts +1 -0
  40. package/dist/node/components/relational/graph/ProvidedNodeRenderer.d.ts.map +1 -1
  41. package/dist/node/index.cjs +14 -2
  42. package/dist/node/index.cjs.map +1 -1
  43. package/dist/node/index.js +14 -2
  44. package/dist/node/index.js.map +1 -1
  45. package/package.json +9 -8
  46. package/src/components/cytoscape-extensions/WithExtensions.tsx +2 -0
  47. package/src/components/lib/RelationalGraphProps.ts +1 -0
  48. package/src/components/relational/graph/Graph.tsx +12 -2
  49. package/src/components/relational/graph/GraphSpread.stories.tsx +173 -0
  50. package/src/components/relational/graph/ProvidedNodeRenderer.tsx +1 -0
  51. package/src/types/global.d.ts +5 -0
package/package.json CHANGED
@@ -22,14 +22,15 @@
22
22
  "@xyo-network/module-events": "^2.94.9",
23
23
  "@xyo-network/module-model": "^2.94.9",
24
24
  "@xyo-network/node-model": "^2.94.9",
25
- "@xyo-network/react-archivist": "~2.71.4",
26
- "@xyo-network/react-module": "~2.71.4",
27
- "@xyo-network/react-node": "~2.71.4",
28
- "@xyo-network/react-shared": "~2.71.4",
25
+ "@xyo-network/react-archivist": "~2.71.5",
26
+ "@xyo-network/react-module": "~2.71.5",
27
+ "@xyo-network/react-node": "~2.71.5",
28
+ "@xyo-network/react-shared": "~2.71.5",
29
29
  "@xyo-network/sentinel-model": "^2.94.9",
30
30
  "@xyo-network/witness-model": "^2.94.9",
31
31
  "cytoscape": "^3.28.1",
32
- "cytoscape-cola": "^2.5.1"
32
+ "cytoscape-cola": "^2.5.1",
33
+ "cytoscape-fcose": "^2.2.0"
33
34
  },
34
35
  "peerDependencies": {
35
36
  "@mui/icons-material": "^5",
@@ -49,8 +50,8 @@
49
50
  "@xyo-network/http-bridge": "^2.94.9",
50
51
  "@xyo-network/id-plugin": "^2.91.4",
51
52
  "@xyo-network/node-memory": "^2.94.9",
52
- "@xyo-network/react-storybook": "~2.71.4",
53
- "@xyo-network/react-wallet": "~2.71.4",
53
+ "@xyo-network/react-storybook": "~2.71.5",
54
+ "@xyo-network/react-wallet": "~2.71.5",
54
55
  "@xyo-network/sentinel": "^2.94.9",
55
56
  "typescript": "^5.4.3"
56
57
  },
@@ -105,6 +106,6 @@
105
106
  },
106
107
  "sideEffects": false,
107
108
  "types": "dist/browser/index.d.ts",
108
- "version": "2.71.4",
109
+ "version": "2.71.5",
109
110
  "type": "module"
110
111
  }
@@ -1,11 +1,13 @@
1
1
  import { use } from 'cytoscape'
2
2
  import cola from 'cytoscape-cola'
3
+ import fcose from 'cytoscape-fcose'
3
4
  import { PropsWithChildren, useEffect, useState } from 'react'
4
5
 
5
6
  export const WithExtensions: React.FC<PropsWithChildren> = ({ children }) => {
6
7
  const [initialized, setInitialized] = useState(false)
7
8
  useEffect(() => {
8
9
  use(cola)
10
+ use(fcose)
9
11
  setInitialized(true)
10
12
  }, [])
11
13
 
@@ -7,4 +7,5 @@ export interface NodeRelationalGraphProps extends PropsWithChildren<FlexBoxProps
7
7
  detail?: ReactNode
8
8
  options?: CytoscapeOptions
9
9
  showDetails?: boolean
10
+ spread?: boolean
10
11
  }
@@ -2,13 +2,14 @@ import { Button, ButtonGroup, useTheme } from '@mui/material'
2
2
  import { FlexCol, FlexGrowRow, FlexRow } from '@xylabs/react-flexbox'
3
3
  import { useShareForwardedRef } from '@xyo-network/react-shared'
4
4
  import cytoscape, { Core } from 'cytoscape'
5
+ import fcoseLayout from 'cytoscape-fcose'
5
6
  import { forwardRef, useEffect, useState } from 'react'
6
7
 
7
8
  import { useCytoscapeInstance } from '../../../contexts'
8
9
  import { NodeRelationalGraphProps } from '../../lib'
9
10
 
10
11
  export const NodeRelationalGraphFlexBox = forwardRef<HTMLDivElement, NodeRelationalGraphProps>(
11
- ({ actions, children, showDetails, detail, options, ...props }, ref) => {
12
+ ({ actions, children, showDetails, detail, spread, options, ...props }, ref) => {
12
13
  const theme = useTheme()
13
14
  const [cy, setCy] = useState<Core>()
14
15
  const { setCy: setCyContext } = useCytoscapeInstance()
@@ -16,18 +17,27 @@ export const NodeRelationalGraphFlexBox = forwardRef<HTMLDivElement, NodeRelatio
16
17
 
17
18
  const handleReset = () => {
18
19
  cy?.reset()
20
+ if (spread) {
21
+ cy?.layout({ name: 'fcose' }).run()
22
+ }
19
23
  cy?.fit(undefined, 20)
20
24
  }
21
25
 
22
26
  useEffect(() => {
23
27
  if (sharedRef) {
28
+ if (spread) {
29
+ cytoscape.use(fcoseLayout)
30
+ }
24
31
  const newCy = cytoscape({
25
32
  container: sharedRef.current,
26
33
  ...options,
27
34
  })
35
+ if (spread) {
36
+ newCy.layout({ name: 'fcose' }).run()
37
+ }
28
38
  setCy(newCy)
29
39
  }
30
- }, [options, sharedRef])
40
+ }, [options, sharedRef, spread])
31
41
 
32
42
  useEffect(() => {
33
43
  setCyContext?.(cy)
@@ -0,0 +1,173 @@
1
+ import { Button, ButtonGroup } from '@mui/material'
2
+ import { Decorator, Meta, StoryFn } from '@storybook/react'
3
+ import { useAsyncEffect } from '@xylabs/react-async-effect'
4
+ import { MemoryArchivist, MemoryArchivistConfigSchema } from '@xyo-network/archivist'
5
+ import { HttpBridge, HttpBridgeConfigSchema } from '@xyo-network/http-bridge'
6
+ import { IdWitness, IdWitnessConfigSchema } from '@xyo-network/id-plugin'
7
+ import { MemoryNode } from '@xyo-network/node-memory'
8
+ import { NodeConfigSchema } from '@xyo-network/node-model'
9
+ import { NodeProvider, useNodeFromNode, useProvidedNode } from '@xyo-network/react-node'
10
+ import { DefaultSeedPhrase } from '@xyo-network/react-storybook'
11
+ import { useWallet, WalletProvider } from '@xyo-network/react-wallet'
12
+ import { MemorySentinel, SentinelConfigSchema } from '@xyo-network/sentinel'
13
+ import { useState } from 'react'
14
+
15
+ import { CytoscapeInstanceProvider } from '../../../contexts'
16
+ import { useCytoscapeElements, useCytoscapeOptions } from '../../../hooks'
17
+ import { NodeRelationalGraphFlexBox } from './Graph'
18
+ import { ProvidedNodeRenderer } from './ProvidedNodeRenderer'
19
+ import { options } from './story'
20
+ import { WithExtensions } from '../../cytoscape-extensions'
21
+
22
+ const nodeUrl = 'http://localhost:8080/node'
23
+
24
+ const MemoryNodeDecorator: Decorator = (Story, args) => {
25
+ const [node, setNode] = useState<MemoryNode>()
26
+
27
+ useAsyncEffect(
28
+ // eslint-disable-next-line react-hooks/exhaustive-deps
29
+ async () => {
30
+ try {
31
+ const node = await MemoryNode.create({ config: { name: 'GlobalNode', schema: NodeConfigSchema } })
32
+ const node1 = await MemoryNode.create({ config: { name: 'ChildNode', schema: NodeConfigSchema } })
33
+ const bridge = await HttpBridge.create({
34
+ config: { name: 'Bridge', nodeUrl, schema: HttpBridgeConfigSchema, security: { allowAnonymous: true } },
35
+ })
36
+ await node.register(bridge)
37
+ await node.attach(bridge.address, true)
38
+
39
+ const archivist = await MemoryArchivist.create({ config: { name: 'RootStorageArchivist', schema: MemoryArchivistConfigSchema } })
40
+ await node.register(archivist)
41
+ await node.attach(archivist.address, true)
42
+
43
+ const sentinel = await MemorySentinel.create({
44
+ config: { name: 'MemorySentinel', schema: SentinelConfigSchema, synchronous: true, tasks: [] },
45
+ })
46
+ await node.register(sentinel)
47
+ await node.attach(sentinel.address, true)
48
+
49
+ const archivist1 = await MemoryArchivist.create({ config: { name: 'RootStorageArchivist1', schema: MemoryArchivistConfigSchema } })
50
+ await node1.register(archivist1)
51
+ await node1.attach(archivist1.address, true)
52
+
53
+ await node.register(node1)
54
+ await node.attach(node1.address, true)
55
+
56
+ setNode(node)
57
+ } catch (e) {
58
+ console.error('Error Creating MemoryNode', e)
59
+ }
60
+ },
61
+ [],
62
+ )
63
+
64
+ const [wallet] = useWallet({ mnemonic: DefaultSeedPhrase })
65
+
66
+ return (
67
+ <WalletProvider rootWallet={wallet}>
68
+ <NodeProvider node={node}>
69
+ <CytoscapeInstanceProvider>
70
+ <Story {...args} />
71
+ </CytoscapeInstanceProvider>
72
+ </NodeProvider>
73
+ </WalletProvider>
74
+ )
75
+ }
76
+
77
+ // eslint-disable-next-line import/no-default-export
78
+ export default {
79
+ component: NodeRelationalGraphFlexBox,
80
+ title: 'node/renderer/NodeSpreadRelationalGraph',
81
+ } as Meta
82
+
83
+ const Template: StoryFn<typeof NodeRelationalGraphFlexBox> = (props) => <NodeRelationalGraphFlexBox {...props} />
84
+
85
+ const TemplateDescribe: StoryFn<typeof NodeRelationalGraphFlexBox> = (props) => {
86
+ const [node] = useProvidedNode()
87
+ const elements = useCytoscapeElements(node)
88
+ const options = useCytoscapeOptions(elements)
89
+ return <NodeRelationalGraphFlexBox spread options={options} {...props} />
90
+ }
91
+
92
+ const TemplateCustomAddress: StoryFn<typeof NodeRelationalGraphFlexBox> = (props) => {
93
+ const [node] = useNodeFromNode('ChildNode')
94
+ const elements = useCytoscapeElements(node)
95
+ const options = useCytoscapeOptions(elements)
96
+ return <NodeRelationalGraphFlexBox spread options={options} {...props} />
97
+ }
98
+
99
+ const TemplateProvidedNodeRenderer: StoryFn<typeof ProvidedNodeRenderer> = (props) => <ProvidedNodeRenderer spread {...props} />
100
+
101
+ const TemplateAttachDetach: StoryFn<typeof NodeRelationalGraphFlexBox> = (props) => {
102
+ const [node] = useNodeFromNode('ChildNode')
103
+ const elements = useCytoscapeElements(node)
104
+ const options = useCytoscapeOptions(elements)
105
+ const [idWitness, setIdWitness] = useState<IdWitness>()
106
+
107
+ useAsyncEffect(
108
+ // eslint-disable-next-line react-hooks/exhaustive-deps
109
+ async () => {
110
+ const witnessModule = await IdWitness.create({ config: { name: 'IdWitness', salt: 'test', schema: IdWitnessConfigSchema } })
111
+ setIdWitness(witnessModule)
112
+ },
113
+ [],
114
+ )
115
+
116
+ const handleAddWitness = async () => {
117
+ if (node && idWitness) {
118
+ const memoryNode = node as MemoryNode
119
+ await memoryNode.register(idWitness)
120
+ await memoryNode.attach(idWitness.address, true)
121
+ }
122
+ }
123
+
124
+ const handleRemoveWitness = async () => {
125
+ if (node && idWitness) {
126
+ const memoryNode = node as MemoryNode
127
+ if (memoryNode.registered().includes(idWitness.address)) {
128
+ await memoryNode.unregister(idWitness)
129
+ }
130
+ }
131
+ }
132
+
133
+ return (
134
+ <>
135
+ <ButtonGroup>
136
+ <Button onClick={handleAddWitness}>Add Witness</Button>
137
+ <Button onClick={handleRemoveWitness}>Remove Witness</Button>
138
+ </ButtonGroup>
139
+ <WithExtensions>
140
+ <NodeRelationalGraphFlexBox spread options={options} {...props} />
141
+ </WithExtensions>
142
+ </>
143
+ )
144
+ }
145
+
146
+ const defaultProps = {
147
+ height: 'calc(100vh - 20px)',
148
+ width: '100%',
149
+ }
150
+
151
+ const Default = Template.bind({})
152
+ Default.args = {}
153
+
154
+ const WithData = Template.bind({})
155
+ WithData.args = { options, ...defaultProps }
156
+
157
+ const WithDescribe = TemplateDescribe.bind({})
158
+ WithDescribe.args = { ...defaultProps }
159
+ WithDescribe.decorators = [MemoryNodeDecorator]
160
+
161
+ const WithCustomAddress = TemplateCustomAddress.bind({})
162
+ WithCustomAddress.args = { ...defaultProps }
163
+ WithCustomAddress.decorators = [MemoryNodeDecorator]
164
+
165
+ const WithAttachDetach = TemplateAttachDetach.bind({})
166
+ WithAttachDetach.args = { ...defaultProps }
167
+ WithAttachDetach.decorators = [MemoryNodeDecorator]
168
+
169
+ const WithProvidedNodeRenderer = TemplateProvidedNodeRenderer.bind({})
170
+ WithProvidedNodeRenderer.args = { ...defaultProps }
171
+ WithProvidedNodeRenderer.decorators = [MemoryNodeDecorator]
172
+
173
+ export { Default, WithAttachDetach, WithCustomAddress, WithData, WithDescribe, WithProvidedNodeRenderer }
@@ -9,6 +9,7 @@ import { NodeRelationalGraphFlexBox } from './Graph'
9
9
  export interface ProvidedNodeRendererProps extends NodeRelationalGraphProps {
10
10
  account?: AccountInstance
11
11
  node?: NodeInstance
12
+ spread?: boolean
12
13
  }
13
14
 
14
15
  export const ProvidedNodeRenderer: React.FC<ProvidedNodeRendererProps> = ({ node, ...props }) => {
@@ -2,3 +2,8 @@ declare module 'cytoscape-cola' {
2
2
  const ext: cytoscape.Ext
3
3
  export = ext
4
4
  }
5
+
6
+ declare module 'cytoscape-fcose' {
7
+ const ext: cytoscape.Ext
8
+ export = ext
9
+ }