@xyo-network/react-node-renderer 7.5.8 → 7.5.12

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 (77) hide show
  1. package/dist/browser/Cytoscape/CytoscapeElements.d.ts +2 -6
  2. package/dist/browser/Cytoscape/CytoscapeElements.d.ts.map +1 -1
  3. package/dist/browser/components/module/graph/Popper.d.ts +3 -2
  4. package/dist/browser/components/module/graph/Popper.d.ts.map +1 -1
  5. package/dist/browser/components/module/graph/node/hooks/useNodeElement.d.ts +8 -5
  6. package/dist/browser/components/module/graph/node/hooks/useNodeElement.d.ts.map +1 -1
  7. package/dist/browser/components/relational/graph/Graph.d.ts.map +1 -1
  8. package/dist/browser/hooks/cytoscape/elements/useRenderNewElements.d.ts +1 -1
  9. package/dist/browser/hooks/cytoscape/elements/useRenderNewElements.d.ts.map +1 -1
  10. package/dist/browser/index.mjs +362 -423
  11. package/dist/browser/index.mjs.map +1 -1
  12. package/package.json +188 -59
  13. package/src/Cytoscape/CytoscapeElements.ts +0 -96
  14. package/src/Cytoscape/CytoscapeIcons.tsx +0 -23
  15. package/src/Cytoscape/CytoscapeStyles.ts +0 -46
  16. package/src/Cytoscape/index.ts +0 -4
  17. package/src/Cytoscape/lib/CyNodeModuleTypes.ts +0 -1
  18. package/src/Cytoscape/lib/encodeSvg.ts +0 -19
  19. package/src/Cytoscape/lib/iconMap.ts +0 -12
  20. package/src/Cytoscape/lib/index.ts +0 -5
  21. package/src/Cytoscape/lib/layout/ColaLayout.ts +0 -5
  22. package/src/Cytoscape/lib/layout/ConcentricLayout.ts +0 -12
  23. package/src/Cytoscape/lib/layout/index.ts +0 -2
  24. package/src/Cytoscape/lib/parseModuleType.ts +0 -29
  25. package/src/components/cytoscape-extensions/WithExtensions.tsx +0 -16
  26. package/src/components/cytoscape-extensions/index.ts +0 -1
  27. package/src/components/index.ts +0 -3
  28. package/src/components/lib/RelationalGraphProps.ts +0 -16
  29. package/src/components/lib/index.ts +0 -1
  30. package/src/components/module/CardParser.stories.tsx +0 -36
  31. package/src/components/module/CardParser.tsx +0 -24
  32. package/src/components/module/graph/DetailsFlexbox.tsx +0 -22
  33. package/src/components/module/graph/GraphFlexBox.stories.tsx +0 -118
  34. package/src/components/module/graph/GraphFlexBox.tsx +0 -84
  35. package/src/components/module/graph/Popper.tsx +0 -77
  36. package/src/components/module/graph/index.ts +0 -1
  37. package/src/components/module/graph/node/Hover.tsx +0 -38
  38. package/src/components/module/graph/node/hooks/index.ts +0 -1
  39. package/src/components/module/graph/node/hooks/useNodeElement.tsx +0 -41
  40. package/src/components/module/graph/node/index.ts +0 -1
  41. package/src/components/module/index.ts +0 -2
  42. package/src/components/relational/graph/Graph.stories.tsx +0 -201
  43. package/src/components/relational/graph/Graph.tsx +0 -200
  44. package/src/components/relational/graph/GraphCola.stories.tsx +0 -187
  45. package/src/components/relational/graph/GraphCoseBilkent.stories.tsx +0 -186
  46. package/src/components/relational/graph/GraphDagre.stories.tsx +0 -186
  47. package/src/components/relational/graph/GraphEuler.stories.tsx +0 -187
  48. package/src/components/relational/graph/GraphEvents.stories.tsx +0 -82
  49. package/src/components/relational/graph/ProvidedNodeRenderer.tsx +0 -23
  50. package/src/components/relational/graph/index.ts +0 -2
  51. package/src/components/relational/graph/story/TestData.tsx +0 -51
  52. package/src/components/relational/graph/story/index.ts +0 -1
  53. package/src/components/relational/index.ts +0 -1
  54. package/src/contexts/CytoscapeInstance/Context.ts +0 -5
  55. package/src/contexts/CytoscapeInstance/Provider.tsx +0 -24
  56. package/src/contexts/CytoscapeInstance/State.ts +0 -8
  57. package/src/contexts/CytoscapeInstance/index.ts +0 -4
  58. package/src/contexts/CytoscapeInstance/use.ts +0 -5
  59. package/src/contexts/index.ts +0 -1
  60. package/src/hooks/cytoscape/elements/index.ts +0 -2
  61. package/src/hooks/cytoscape/elements/useCytoscapeElements.ts +0 -47
  62. package/src/hooks/cytoscape/elements/useElements.tsx +0 -15
  63. package/src/hooks/cytoscape/elements/useHoveredNode.tsx +0 -34
  64. package/src/hooks/cytoscape/elements/useNewElements.tsx +0 -17
  65. package/src/hooks/cytoscape/elements/useRenderNewElements.tsx +0 -17
  66. package/src/hooks/cytoscape/elements/useSelectedElement.tsx +0 -25
  67. package/src/hooks/cytoscape/index.ts +0 -4
  68. package/src/hooks/cytoscape/useCytoscapeOptions.ts +0 -29
  69. package/src/hooks/cytoscape/useCytoscapeStyle.tsx +0 -34
  70. package/src/hooks/cytoscape/useIcons.tsx +0 -22
  71. package/src/hooks/cytoscape/useModuleDetails.tsx +0 -83
  72. package/src/hooks/cytoscape/useRelationalGraphOptions.tsx +0 -23
  73. package/src/hooks/index.ts +0 -1
  74. package/src/index.ts +0 -4
  75. package/src/types/global.d.ts +0 -19
  76. package/src/types/images.d.ts +0 -5
  77. package/src/types/theme.d.ts +0 -1
@@ -1,187 +0,0 @@
1
- import { Button, ButtonGroup } from '@mui/material'
2
- import type {
3
- Decorator, Meta, StoryFn,
4
- } from '@storybook/react-vite'
5
- import { useAsyncEffect } from '@xylabs/react-async-effect'
6
- import { MemoryArchivist, MemoryArchivistConfigSchema } from '@xyo-network/archivist-memory'
7
- import { HttpBridge, HttpBridgeConfigSchema } from '@xyo-network/bridge-http'
8
- import { IdWitness, IdWitnessConfigSchema } from '@xyo-network/id-plugin'
9
- import type { AttachableModuleInstance } from '@xyo-network/module-model'
10
- import { MemoryNode } from '@xyo-network/node-memory'
11
- import { NodeConfigSchema } from '@xyo-network/node-model'
12
- import {
13
- NodeProvider, useWeakNodeFromNode, useWeakProvidedNode,
14
- } from '@xyo-network/react-node'
15
- import { DefaultSeedPhrase } from '@xyo-network/react-storybook'
16
- import { useWallet, WalletProvider } from '@xyo-network/react-wallet'
17
- import { SentinelConfigSchema } from '@xyo-network/sentinel'
18
- import { MemorySentinel } from '@xyo-network/sentinel-memory'
19
- import React, { useState } from 'react'
20
-
21
- import { CytoscapeInstanceProvider } from '../../../contexts/index.ts'
22
- import { useCytoscapeElements, useCytoscapeOptions } from '../../../hooks/index.ts'
23
- import { WithExtensions } from '../../cytoscape-extensions/index.ts'
24
- import { NodeRelationalGraphFlexBox } from './Graph.tsx'
25
- import { ProvidedNodeRenderer } from './ProvidedNodeRenderer.tsx'
26
- import { options } from './story/index.ts'
27
-
28
- const client = { url: 'http://localhost:8080/node' }
29
-
30
- const MemoryNodeDecorator: Decorator = (Story, args) => {
31
- const [node, setNode] = useState<MemoryNode>()
32
-
33
- useAsyncEffect(
34
-
35
- async () => {
36
- try {
37
- const node = await MemoryNode.create({ config: { name: 'GlobalNode', schema: NodeConfigSchema } })
38
- const node1 = await MemoryNode.create({ config: { name: 'ChildNode', schema: NodeConfigSchema } })
39
- const bridge = await HttpBridge.create({
40
- config: {
41
- name: 'Bridge', client, schema: HttpBridgeConfigSchema, security: { allowAnonymous: true },
42
- },
43
- })
44
- await node.register(bridge)
45
- await node.attach(bridge.address, true)
46
-
47
- const archivist = await MemoryArchivist.create({ config: { name: 'RootStorageArchivist', schema: MemoryArchivistConfigSchema } })
48
- await node.register(archivist)
49
- await node.attach(archivist.address, true)
50
-
51
- const sentinel = await MemorySentinel.create({
52
- config: {
53
- name: 'MemorySentinel', schema: SentinelConfigSchema, synchronous: true, tasks: [],
54
- },
55
- })
56
- await node.register(sentinel)
57
- await node.attach(sentinel.address, true)
58
-
59
- const archivist1 = await MemoryArchivist.create({ config: { name: 'RootStorageArchivist1', schema: MemoryArchivistConfigSchema } })
60
- await node1.register(archivist1)
61
- await node1.attach(archivist1.address, true)
62
-
63
- await node.register(node1)
64
- await node.attach(node1.address, true)
65
-
66
- setNode(node)
67
- } catch (e) {
68
- console.error('Error Creating MemoryNode', e)
69
- }
70
- },
71
- [],
72
- )
73
-
74
- const [wallet] = useWallet({ mnemonic: DefaultSeedPhrase })
75
-
76
- return (
77
- <WalletProvider rootWallet={wallet}>
78
- <NodeProvider node={node}>
79
- <CytoscapeInstanceProvider>
80
- <Story {...args} />
81
- </CytoscapeInstanceProvider>
82
- </NodeProvider>
83
- </WalletProvider>
84
- )
85
- }
86
-
87
- export default {
88
- component: NodeRelationalGraphFlexBox,
89
- title: 'node/renderer/euler/NodeRelationalGraph',
90
- } as Meta
91
-
92
- const Template: StoryFn<typeof NodeRelationalGraphFlexBox> = props => <NodeRelationalGraphFlexBox layout="euler" {...props} />
93
-
94
- const TemplateDescribe: StoryFn<typeof NodeRelationalGraphFlexBox> = (props) => {
95
- const [node] = useWeakProvidedNode()
96
- const elements = useCytoscapeElements(node)
97
- const options = useCytoscapeOptions(elements)
98
- return <NodeRelationalGraphFlexBox layout="euler" options={options} {...props} />
99
- }
100
-
101
- const TemplateCustomAddress: StoryFn<typeof NodeRelationalGraphFlexBox> = (props) => {
102
- const [node] = useWeakNodeFromNode('ChildNode')
103
- const elements = useCytoscapeElements(node)
104
- const options = useCytoscapeOptions(elements)
105
- return <NodeRelationalGraphFlexBox layout="euler" options={options} {...props} />
106
- }
107
-
108
- const TemplateProvidedNodeRenderer: StoryFn<typeof ProvidedNodeRenderer> = props => <ProvidedNodeRenderer layout="euler" {...props} />
109
-
110
- const TemplateAttachDetach: StoryFn<typeof NodeRelationalGraphFlexBox> = (props) => {
111
- const [node] = useWeakNodeFromNode('ChildNode')
112
- const elements = useCytoscapeElements(node)
113
- const options = useCytoscapeOptions(elements)
114
- const [idWitness, setIdWitness] = useState<IdWitness>()
115
-
116
- useAsyncEffect(
117
- async () => {
118
- const witnessModule = await IdWitness.create({
119
- config: {
120
- name: 'IdWitness', salt: 'test', schema: IdWitnessConfigSchema,
121
- },
122
- })
123
- setIdWitness(witnessModule)
124
- },
125
- [],
126
- )
127
-
128
- const handleAddWitness = async () => {
129
- if (node && idWitness) {
130
- const memoryNode = node.deref() as MemoryNode | undefined
131
- await memoryNode?.register(idWitness as unknown as AttachableModuleInstance)
132
- await memoryNode?.attach(idWitness.address, true)
133
- }
134
- }
135
-
136
- const handleRemoveWitness = async () => {
137
- if (node && idWitness) {
138
- const memoryNode = node.deref() as MemoryNode | undefined
139
- if (((await memoryNode?.registered()) ?? []).includes(idWitness.address)) {
140
- await memoryNode?.unregister(idWitness as unknown as AttachableModuleInstance)
141
- }
142
- }
143
- }
144
-
145
- return (
146
- <>
147
- <ButtonGroup>
148
- <Button onClick={handleAddWitness}>Add Witness</Button>
149
- <Button onClick={handleRemoveWitness}>Remove Witness</Button>
150
- </ButtonGroup>
151
- <WithExtensions>
152
- <NodeRelationalGraphFlexBox layout="euler" options={options} {...props} />
153
- </WithExtensions>
154
- </>
155
- )
156
- }
157
-
158
- const defaultProps = {
159
- height: 'calc(100vh - 20px)',
160
- width: '100%',
161
- }
162
-
163
- const Default = Template.bind({})
164
- Default.args = {}
165
-
166
- const WithData = Template.bind({})
167
- WithData.args = { options, ...defaultProps }
168
-
169
- const WithDescribe = TemplateDescribe.bind({})
170
- WithDescribe.args = { ...defaultProps }
171
- WithDescribe.decorators = [MemoryNodeDecorator]
172
-
173
- const WithCustomAddress = TemplateCustomAddress.bind({})
174
- WithCustomAddress.args = { ...defaultProps }
175
- WithCustomAddress.decorators = [MemoryNodeDecorator]
176
-
177
- const WithAttachDetach = TemplateAttachDetach.bind({})
178
- WithAttachDetach.args = { ...defaultProps }
179
- WithAttachDetach.decorators = [MemoryNodeDecorator]
180
-
181
- const WithProvidedNodeRenderer = TemplateProvidedNodeRenderer.bind({})
182
- WithProvidedNodeRenderer.args = { ...defaultProps }
183
- WithProvidedNodeRenderer.decorators = [MemoryNodeDecorator]
184
-
185
- export {
186
- Default, WithAttachDetach, WithCustomAddress, WithData, WithDescribe, WithProvidedNodeRenderer,
187
- }
@@ -1,82 +0,0 @@
1
- import type {
2
- Decorator, Meta, StoryFn,
3
- } from '@storybook/react-vite'
4
- import { useAsyncEffect } from '@xylabs/react-async-effect'
5
- import { MemoryArchivist, MemoryArchivistConfigSchema } from '@xyo-network/archivist-memory'
6
- import { MemoryNode } from '@xyo-network/node-memory'
7
- import { NodeConfigSchema } from '@xyo-network/node-model'
8
- import { NodeProvider, useWeakProvidedNode } from '@xyo-network/react-node'
9
- import { DefaultSeedPhrase } from '@xyo-network/react-storybook'
10
- import { useWallet, WalletProvider } from '@xyo-network/react-wallet'
11
- import type { EventObject } from 'cytoscape'
12
- import React, { useEffect, useState } from 'react'
13
-
14
- import { CytoscapeInstanceProvider, useCytoscapeInstance } from '../../../contexts/index.ts'
15
- import { useCytoscapeElements, useCytoscapeOptions } from '../../../hooks/index.ts'
16
- import { NodeRelationalGraphFlexBox } from './Graph.tsx'
17
-
18
- const MemoryNodeDecorator: Decorator = (Story, args) => {
19
- const [node, setNode] = useState<MemoryNode>()
20
-
21
- useAsyncEffect(
22
- async () => {
23
- const node = await MemoryNode.create({ config: { name: 'GlobalNode', schema: NodeConfigSchema } })
24
-
25
- const archivist = await MemoryArchivist.create({ config: { name: 'RootStorageArchivist', schema: MemoryArchivistConfigSchema } })
26
- await node.register(archivist)
27
- await node.attach(archivist.address, true)
28
-
29
- setNode(node)
30
- },
31
- [],
32
- )
33
-
34
- const [wallet] = useWallet({ mnemonic: DefaultSeedPhrase })
35
-
36
- return (
37
- <WalletProvider rootWallet={wallet}>
38
- <NodeProvider node={node}>
39
- <CytoscapeInstanceProvider>
40
- <Story {...args} />
41
- </CytoscapeInstanceProvider>
42
- </NodeProvider>
43
- </WalletProvider>
44
- )
45
- }
46
-
47
- export default {
48
- component: NodeRelationalGraphFlexBox,
49
- title: 'node/renderer/NodeRelationalGraphEvents',
50
- } as Meta
51
-
52
- const Template: StoryFn<typeof NodeRelationalGraphFlexBox> = (props) => {
53
- const [node] = useWeakProvidedNode()
54
- const elements = useCytoscapeElements(node)
55
- const options = useCytoscapeOptions(elements)
56
-
57
- const { cy } = useCytoscapeInstance(true)
58
-
59
- useEffect(() => {
60
- const listener = (event: EventObject) => {
61
- const element = event.target[0]
62
- console.log(element.data().address)
63
- }
64
- cy?.deref()?.on('select', listener)
65
-
66
- return () => {
67
- cy?.deref()?.off('select', listener)
68
- }
69
- }, [cy])
70
- return <NodeRelationalGraphFlexBox options={options} {...props} />
71
- }
72
-
73
- const defaultProps = {
74
- height: 'calc(100vh - 20px)',
75
- width: '100%',
76
- }
77
-
78
- const Default = Template.bind({})
79
- Default.args = { ...defaultProps }
80
- Default.decorators = [MemoryNodeDecorator]
81
-
82
- export { Default }
@@ -1,23 +0,0 @@
1
- import type { AccountInstance } from '@xyo-network/account-model'
2
- import type { NodeInstance } from '@xyo-network/node-model'
3
- import { useWeakProvidedNode } from '@xyo-network/react-node'
4
- import React from 'react'
5
-
6
- import { useCytoscapeElements, useCytoscapeOptions } from '../../../hooks/index.ts'
7
- import type { NodeRelationalGraphProps } from '../../lib/index.ts'
8
- import { NodeRelationalGraphFlexBox } from './Graph.tsx'
9
-
10
- export interface ProvidedNodeRendererProps extends NodeRelationalGraphProps {
11
- account?: AccountInstance
12
- layout?: 'dagre' | 'euler' | 'cose-bilkent' | 'cola'
13
- layoutOptions?: object
14
- node?: WeakRef<NodeInstance>
15
- }
16
-
17
- export const ProvidedNodeRenderer: React.FC<ProvidedNodeRendererProps> = ({ node, ...props }) => {
18
- const [providedNode] = useWeakProvidedNode()
19
- const elements = useCytoscapeElements(node ?? providedNode)
20
- const options = useCytoscapeOptions(elements)
21
-
22
- return <NodeRelationalGraphFlexBox alignItems="stretch" flexGrow={1} height="100%" options={options} {...props} />
23
- }
@@ -1,2 +0,0 @@
1
- export * from './Graph.tsx'
2
- export * from './ProvidedNodeRenderer.tsx'
@@ -1,51 +0,0 @@
1
- import type { CytoscapeOptions } from 'cytoscape'
2
-
3
- const elements: CytoscapeOptions['elements'] = [
4
- {
5
- // node a
6
- data: { id: 'a', name: 'element a' },
7
- },
8
- {
9
- // node b
10
- data: { id: 'b', name: 'element b' },
11
- },
12
- {
13
- // node c
14
- data: { id: 'c', name: 'element c' },
15
- },
16
- {
17
- // edge ab
18
- data: {
19
- id: 'ab', source: 'a', target: 'b',
20
- },
21
- },
22
- {
23
- // edge ac
24
- data: {
25
- id: 'ac', source: 'a', target: 'c',
26
- },
27
- },
28
- ]
29
-
30
- const style: CytoscapeOptions['style'] = [
31
- {
32
- selector: 'node',
33
- style: { label: 'data(id)' },
34
- },
35
-
36
- {
37
- selector: 'edge',
38
- style: {
39
- 'curve-style': 'bezier',
40
- 'line-color': '#ccc',
41
- 'target-arrow-color': '#ccc',
42
- 'target-arrow-shape': 'triangle',
43
- 'width': 3,
44
- },
45
- },
46
- ]
47
-
48
- export const options: CytoscapeOptions = {
49
- elements,
50
- style,
51
- }
@@ -1 +0,0 @@
1
- export * from './TestData.tsx'
@@ -1 +0,0 @@
1
- export * from './graph/index.ts'
@@ -1,5 +0,0 @@
1
- import { createContextEx } from '@xylabs/react-shared'
2
-
3
- import type { CytoscapeInstanceState } from './State.ts'
4
-
5
- export const CytoscapeInstanceContext = createContextEx<CytoscapeInstanceState>()
@@ -1,24 +0,0 @@
1
- import type { Core } from 'cytoscape'
2
- import type { PropsWithChildren } from 'react'
3
- import React, { useMemo, useState } from 'react'
4
-
5
- import { CytoscapeInstanceContext } from './Context.ts'
6
- import type { CytoscapeInstanceState } from './State.ts'
7
-
8
- export interface CytoscapeInstanceProviderProps extends PropsWithChildren {
9
- defaultInstance?: WeakRef<Core>
10
- }
11
-
12
- export const CytoscapeInstanceProvider: React.FC<CytoscapeInstanceProviderProps> = ({ children, defaultInstance }) => {
13
- const [cy, setCy] = useState<WeakRef<Core> | undefined>(() => defaultInstance)
14
-
15
- const value: CytoscapeInstanceState = useMemo(() => ({
16
- cy, provided: true, setCy,
17
- }), [cy, setCy])
18
-
19
- return (
20
- <CytoscapeInstanceContext value={value}>
21
- {children}
22
- </CytoscapeInstanceContext>
23
- )
24
- }
@@ -1,8 +0,0 @@
1
- import type { ContextExState } from '@xylabs/react-shared'
2
- import type { Core } from 'cytoscape'
3
- import type { Dispatch, SetStateAction } from 'react'
4
-
5
- export type CytoscapeInstanceState = ContextExState<{
6
- cy?: WeakRef<Core>
7
- setCy?: Dispatch<SetStateAction<WeakRef<Core> | undefined>>
8
- }>
@@ -1,4 +0,0 @@
1
- export * from './Context.ts'
2
- export * from './Provider.tsx'
3
- export * from './State.ts'
4
- export * from './use.ts'
@@ -1,5 +0,0 @@
1
- import { useContextEx } from '@xylabs/react-shared'
2
-
3
- import { CytoscapeInstanceContext } from './Context.ts'
4
-
5
- export const useCytoscapeInstance = (required = false) => useContextEx(CytoscapeInstanceContext, 'CytoscapeInstance', required)
@@ -1 +0,0 @@
1
- export * from './CytoscapeInstance/index.ts'
@@ -1,2 +0,0 @@
1
- export * from './useCytoscapeElements.ts'
2
- export * from './useElements.tsx'
@@ -1,47 +0,0 @@
1
- import type { EventUnsubscribeFunction } from '@xylabs/events'
2
- import { useAsyncEffect } from '@xylabs/react-async-effect'
3
- import type { ModuleInstance } from '@xyo-network/module-model'
4
- import { isNodeInstance } from '@xyo-network/node-model'
5
- import type { ElementDefinition } from 'cytoscape'
6
- import { useEffect, useState } from 'react'
7
-
8
- import { CytoscapeElements } from '../../../Cytoscape/index.ts'
9
-
10
- export const useCytoscapeElements = (mod?: WeakRef<ModuleInstance> | null) => {
11
- const [elements, setElements] = useState<ElementDefinition[]>([])
12
-
13
- useAsyncEffect(
14
-
15
- async () => {
16
- const moduleInstance = mod?.deref()
17
- if (moduleInstance) {
18
- const newElements = (await CytoscapeElements.buildElements(moduleInstance)) ?? []
19
- setElements(newElements)
20
- }
21
- },
22
- [mod],
23
- )
24
-
25
- useEffect(() => {
26
- let attachedListener: EventUnsubscribeFunction | undefined
27
- let detachedListener: EventUnsubscribeFunction | undefined
28
-
29
- if (mod && isNodeInstance(mod)) {
30
- attachedListener = mod.on('moduleAttached', async () => {
31
- const newElements = (await CytoscapeElements.buildElements(mod)) ?? []
32
- setElements(newElements)
33
- })
34
- detachedListener = mod.on('moduleDetached', async () => {
35
- const newElements = (await CytoscapeElements.buildElements(mod)) ?? []
36
- setElements(newElements)
37
- })
38
- }
39
-
40
- return () => {
41
- attachedListener?.()
42
- detachedListener?.()
43
- }
44
- }, [mod])
45
-
46
- return elements
47
- }
@@ -1,15 +0,0 @@
1
- import { useHoveredNode } from './useHoveredNode.tsx'
2
- import { useNewElements } from './useNewElements.tsx'
3
- import { useRenderNewElements } from './useRenderNewElements.tsx'
4
- import { useSelectedElement } from './useSelectedElement.tsx'
5
-
6
- export const useElements = (hideLabels: boolean) => {
7
- const { selectedElement, toggleSelectedElement } = useSelectedElement()
8
- const newElements = useNewElements(selectedElement)
9
- const renderedElements = useRenderNewElements(newElements, hideLabels)
10
- const [hoveredNode, setHoveredNode] = useHoveredNode(renderedElements)
11
-
12
- return {
13
- hoveredNode, setHoveredNode, toggleSelectedElement,
14
- }
15
- }
@@ -1,34 +0,0 @@
1
- import type { NodeCollection, NodeSingular } from 'cytoscape'
2
- import type { Dispatch, SetStateAction } from 'react'
3
- import {
4
- useCallback, useEffect, useState,
5
- } from 'react'
6
-
7
- import { useCytoscapeInstance } from '../../../contexts/index.ts'
8
-
9
- export const useHoveredNode = (renderedElements?: NodeCollection): [NodeSingular | undefined, Dispatch<SetStateAction<NodeSingular | undefined>>] => {
10
- const { cy } = useCytoscapeInstance(true)
11
- const [hoveredNode, setHoveredNode] = useState<NodeSingular>()
12
-
13
- const nodeListener = useCallback((node: NodeSingular) => {
14
- node.on('mouseover tap', () => {
15
- setHoveredNode(node)
16
- })
17
- }, [])
18
-
19
- useEffect(() => {
20
- if (renderedElements) {
21
- // eslint-disable-next-line unicorn/no-array-for-each
22
- renderedElements.nodes().forEach(nodeListener)
23
- }
24
- }, [nodeListener, renderedElements])
25
-
26
- useEffect(() => {
27
- cy?.deref()?.ready(() => {
28
- // eslint-disable-next-line unicorn/no-array-for-each
29
- cy?.deref()?.nodes().forEach(nodeListener)
30
- })
31
- }, [cy, nodeListener])
32
-
33
- return [hoveredNode, setHoveredNode]
34
- }
@@ -1,17 +0,0 @@
1
- import { useWeakModuleFromNode } from '@xyo-network/react-node'
2
- import type { NodeSingular } from 'cytoscape'
3
- import { useMemo } from 'react'
4
-
5
- import { useCytoscapeElements } from './useCytoscapeElements.ts'
6
-
7
- export const useNewElements = (selectedElement?: NodeSingular) => {
8
- const selectedAddress = useMemo(() => {
9
- const { address: selectedAddress } = selectedElement?.data() ?? {}
10
- return selectedAddress
11
- }, [selectedElement])
12
-
13
- const [mod] = useWeakModuleFromNode(selectedAddress)
14
- const newElements = useCytoscapeElements(mod)
15
-
16
- return newElements
17
- }
@@ -1,17 +0,0 @@
1
- import type { ElementDefinition } from 'cytoscape'
2
- import { useMemo } from 'react'
3
-
4
- import { useCytoscapeInstance } from '../../../contexts/index.ts'
5
- import { ColaLayout } from '../../../Cytoscape/index.ts'
6
-
7
- export const useRenderNewElements = (newElements: ElementDefinition[] = [], hideLabels?: boolean) => {
8
- const { cy } = useCytoscapeInstance(true)
9
-
10
- return useMemo(() => {
11
- if (newElements.length > 1) {
12
- const renderedElements = cy?.deref()?.add(newElements)
13
- cy?.deref()?.layout(ColaLayout).run()
14
- return renderedElements
15
- }
16
- }, [cy, hideLabels, newElements])
17
- }
@@ -1,25 +0,0 @@
1
- import type { NodeSingular } from 'cytoscape'
2
- import { useState } from 'react'
3
-
4
- import { useCytoscapeInstance } from '../../../contexts/index.ts'
5
-
6
- export const useSelectedElement = () => {
7
- const [selectedElement, setSelectedElement] = useState<NodeSingular>()
8
- const { cy } = useCytoscapeInstance(true)
9
-
10
- const updateStyles = (element: NodeSingular) => {
11
- const nodes = cy?.deref()?.nodes()
12
- nodes?.toggleClass('activeNode', false)
13
- element.toggleClass('activeNode', true)
14
- }
15
-
16
- const toggleSelectedElement = (address?: string) => {
17
- const selectedNode = cy?.deref()?.nodes(`[id="${address}"]`)?.[0]
18
- if (selectedNode) {
19
- setSelectedElement(selectedNode)
20
- updateStyles(selectedNode)
21
- }
22
- }
23
-
24
- return { selectedElement, toggleSelectedElement }
25
- }
@@ -1,4 +0,0 @@
1
- export * from './elements/index.ts'
2
- export * from './useCytoscapeOptions.ts'
3
- export * from './useModuleDetails.tsx'
4
- export * from './useRelationalGraphOptions.tsx'
@@ -1,29 +0,0 @@
1
- import { isDefined } from '@xylabs/sdk-js'
2
- import type { CytoscapeOptions } from 'cytoscape'
3
- import { useMemo } from 'react'
4
-
5
- import { ConcentricLayout } from '../../Cytoscape/index.ts'
6
- import { useCytoscapeStyle } from './useCytoscapeStyle.tsx'
7
-
8
- export const useCytoscapeOptions = (
9
- elements: CytoscapeOptions['elements'],
10
- style?: CytoscapeOptions['style'],
11
- layout?: CytoscapeOptions['layout'],
12
- ) => {
13
- const defaultStyle = useCytoscapeStyle()
14
-
15
- const resolvedLayout = layout ?? ConcentricLayout
16
- const resolvedStyle = style ?? defaultStyle
17
-
18
- const options = useMemo<CytoscapeOptions | undefined>(() => {
19
- if (elements && isDefined(resolvedLayout) && isDefined(resolvedStyle)) {
20
- return {
21
- elements,
22
- layout: resolvedLayout,
23
- style: resolvedStyle,
24
- }
25
- }
26
- }, [elements, resolvedLayout, resolvedStyle])
27
-
28
- return options
29
- }
@@ -1,34 +0,0 @@
1
- import { useTheme } from '@mui/material'
2
- import { useIsDark } from '@xylabs/react-theme'
3
- import type { CytoscapeOptions } from 'cytoscape'
4
- import { useMemo } from 'react'
5
-
6
- import {
7
- EdgeStyled, Node, NodeAsRoot, NodeWithName,
8
- } from '../../Cytoscape/index.ts'
9
- import { useIcons } from './useIcons.tsx'
10
-
11
- export const useCytoscapeStyle = (hideLabels = false) => {
12
- const theme = useTheme()
13
- const dark = useIsDark()
14
- const icons = useIcons()
15
-
16
- const style: CytoscapeOptions['style'] = useMemo(
17
- // eslint-disable-next-line complexity
18
- () => [
19
- Node(icons, dark ? theme.colorSchemes.dark?.palette.primary.main : theme.colorSchemes.light?.palette.primary.main, hideLabels),
20
- NodeWithName(
21
- dark ? theme.colorSchemes.dark?.palette.primary.contrastText : theme.colorSchemes.light?.palette.primary.contrastText,
22
- dark ? theme.colorSchemes.dark?.palette.text.primary : theme.colorSchemes.light?.palette.text.primary,
23
- ),
24
- NodeAsRoot(dark ? theme.colorSchemes.dark?.palette.secondary.main : theme.colorSchemes.light?.palette.secondary.main),
25
- EdgeStyled(
26
- dark ? theme.colorSchemes.dark?.palette.divider : theme.colorSchemes.light?.palette.divider,
27
- dark ? theme.colorSchemes.dark?.palette.divider : theme.colorSchemes.light?.palette.divider,
28
- ),
29
- ],
30
- [icons, hideLabels, theme],
31
- )
32
-
33
- return style
34
- }
@@ -1,22 +0,0 @@
1
- import { useTheme } from '@mui/material'
2
- import React, { useMemo } from 'react'
3
-
4
- import type { CyNodeModuleTypes } from '../../Cytoscape/index.ts'
5
- import {
6
- CyIconSet, encodeSvg, generateIconMap,
7
- } from '../../Cytoscape/index.ts'
8
-
9
- export const useIcons = () => {
10
- const theme = useTheme()
11
- const icons = useMemo(() => {
12
- const iconMap = generateIconMap()
13
- // eslint-disable-next-line unicorn/no-array-reduce
14
- return Object.entries(CyIconSet).reduce((acc, [name, IconComponent]) => {
15
- const icon = <IconComponent fontSize="small" />
16
- acc[name as CyNodeModuleTypes] = encodeSvg(icon, theme.vars.palette.primary.contrastText)
17
- return acc
18
- }, iconMap)
19
- }, [theme.vars.palette.primary.contrastText])
20
-
21
- return icons
22
- }