@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,96 +0,0 @@
1
- import { exists, isFalsy } from '@xylabs/sdk-js'
2
- import type { ModuleInstance } from '@xyo-network/module-model'
3
- import type { ElementDefinition } from 'cytoscape'
4
-
5
- import { parseModuleType } from './lib/index.ts'
6
-
7
- interface ModuleInfo {
8
- children: ModuleInfo[]
9
- depth: number
10
- mod: ModuleInstance
11
- }
12
-
13
- export const CytoscapeElements = {
14
- MaxNameLength: 20,
15
-
16
- buildEdge(rootNode: ElementDefinition, newNode: ElementDefinition, properties?: { [key: string]: unknown }) {
17
- return {
18
- data: {
19
- id: `${rootNode.data.id}/${newNode.data.id}`,
20
- source: rootNode.data.id,
21
- target: newNode.data.id,
22
- ...properties,
23
- },
24
- }
25
- },
26
-
27
- async buildElements(mod: ModuleInstance): Promise<ElementDefinition[]> {
28
- const info = await CytoscapeElements.recurseNodes(mod)
29
- const newElements: ElementDefinition[] = await this.buildElementsFromInfo(info, undefined, ['activeNode'])
30
-
31
- return newElements
32
- },
33
-
34
- async buildElementsFromInfo(info: ModuleInfo, root?: ElementDefinition, classes: string[] = []): Promise<ElementDefinition[]> {
35
- const newNode = CytoscapeElements.buildNode(info.mod, { childCount: info.children.length, depth: info.depth }, classes)
36
- const newEdge = root
37
- ? CytoscapeElements.buildEdge(root, newNode, { depth: info.depth, siblingCount: info.children.length })
38
- : undefined
39
- const newElements: ElementDefinition[] = [newNode]
40
- if (newEdge) {
41
- newElements.push(newEdge)
42
- }
43
-
44
- for (const childInfo of info.children) {
45
- newElements.push(...(await this.buildElementsFromInfo(childInfo, newNode)))
46
- }
47
-
48
- return newElements
49
- },
50
-
51
- buildNode(mod: ModuleInstance, properties?: { [key: string]: unknown }, classes?: string[]): ElementDefinition {
52
- const { address, id } = mod
53
- return {
54
- classes,
55
- data: {
56
- address,
57
- id: address,
58
- name: id,
59
- type: parseModuleType(mod),
60
- ...properties,
61
- },
62
- }
63
- },
64
-
65
- buildRootNode: (mod: ModuleInstance): ElementDefinition => {
66
- return CytoscapeElements.buildNode(mod, {}, ['activeNode'])
67
- },
68
-
69
- normalizeName(name?: string) {
70
- if (isFalsy(name)) return
71
- if (name.length > this.MaxNameLength) return `${name.slice(0, 20)}...`
72
- return name
73
- },
74
-
75
- async recurseNodes(root: ModuleInstance, maxDepth = 10, depth = 1): Promise<ModuleInfo> {
76
- const info: ModuleInfo = {
77
- children: [], depth, mod: root,
78
- }
79
-
80
- if (maxDepth > 0) {
81
- const children = await root.resolve('*', { direction: 'down', maxDepth: 1 })
82
- info.children = (
83
- await Promise.all(
84
- children.map(async (child) => {
85
- // don't re add the root module that was passed in
86
- if (child.address !== root.address) {
87
- return await this.recurseNodes(child, maxDepth - 1, depth + 1)
88
- }
89
- }),
90
- )
91
- ).filter(exists)
92
- }
93
-
94
- return info
95
- },
96
- }
@@ -1,23 +0,0 @@
1
- import type { SvgIconComponent } from '@mui/icons-material'
2
- import {
3
- BubbleChartRounded as BubbleChartRoundedIcon,
4
- Hub as HubIcon,
5
- InsertLinkRounded as InsertLinkRoundedIcon,
6
- Inventory2Rounded as Inventory2RoundedIcon,
7
- QuestionMarkRounded as QuestionMarkRoundedIcon,
8
- TimerRounded as TimerRoundedIcon,
9
- VisibilityRounded as VisibilityRoundedIcon,
10
- } from '@mui/icons-material'
11
-
12
- import type { CyNodeModuleTypes } from './lib/index.ts'
13
-
14
- export const CyIconSet: Record<CyNodeModuleTypes, SvgIconComponent> = {
15
- archivist: Inventory2RoundedIcon,
16
- bridge: InsertLinkRoundedIcon,
17
- diviner: BubbleChartRoundedIcon,
18
-
19
- module: QuestionMarkRoundedIcon,
20
- node: HubIcon,
21
- sentinel: TimerRoundedIcon,
22
- witness: VisibilityRoundedIcon,
23
- }
@@ -1,46 +0,0 @@
1
- import type { StylesheetCSS } from 'cytoscape'
2
-
3
- import type { CyNodeModuleTypes } from './lib/index.ts'
4
-
5
- export const NodeWithName = (color?: string, outlineColor?: string): StylesheetCSS => ({
6
- selector: 'node[name]',
7
- css: {
8
- color,
9
- 'font-family': 'Lexend Deca, Helvetica, sans-serif',
10
- 'font-size': 12,
11
- 'overlay-padding': '6px',
12
- 'text-halign': 'center',
13
- 'text-outline-color': outlineColor,
14
- 'text-outline-width': '1px',
15
- 'text-valign': 'top',
16
- },
17
- })
18
-
19
- export const Node = (icons: Record<CyNodeModuleTypes, string>, bgColor?: string, hideLabels = false): StylesheetCSS => ({
20
- selector: 'node',
21
- css: {
22
- 'background-color': bgColor,
23
- 'background-height': '75%',
24
- 'background-image': elem => icons[elem.data('type') as CyNodeModuleTypes],
25
- 'background-width': '24',
26
- 'label': hideLabels ? undefined : 'data(name)',
27
- 'shape': 'round-rectangle',
28
- },
29
- })
30
-
31
- export const NodeAsRoot = (bgColor?: string): StylesheetCSS => ({
32
- selector: '.activeNode',
33
- css: { 'background-color': bgColor },
34
- })
35
-
36
- export const EdgeStyled = (lineColor?: string, targetArrowColor?: string): StylesheetCSS => ({
37
- selector: 'edge',
38
- css: {
39
- 'curve-style': 'bezier',
40
- 'line-color': lineColor,
41
- 'line-opacity': 0.1,
42
- 'target-arrow-color': targetArrowColor,
43
- 'target-arrow-shape': 'triangle',
44
- 'width': 3,
45
- },
46
- })
@@ -1,4 +0,0 @@
1
- export * from './CytoscapeElements.ts'
2
- export * from './CytoscapeIcons.tsx'
3
- export * from './CytoscapeStyles.ts'
4
- export * from './lib/index.ts'
@@ -1 +0,0 @@
1
- export type CyNodeModuleTypes = 'archivist' | 'bridge' | 'diviner' | 'module' | 'node' | 'witness' | 'sentinel'
@@ -1,19 +0,0 @@
1
- import { isDefined } from '@xylabs/sdk-js'
2
- import type { ReactElement } from 'react'
3
- import { renderToStaticMarkup } from 'react-dom/server'
4
-
5
- const dataUri = 'data:image/svg+xml,'
6
-
7
- export const encodeSvg = (reactElement: ReactElement, color?: string) => {
8
- const svgString = renderToStaticMarkup(reactElement)
9
-
10
- const doc = new DOMParser().parseFromString(svgString, 'text/html')
11
- const svgElement = doc.querySelectorAll('svg')[0]
12
- if (isDefined(svgElement)) {
13
- svgElement.setAttribute('xmlns', 'http://www.w3.org/2000/svg')
14
- svgElement.setAttribute('height', '100')
15
- svgElement.style.fill = color ?? 'black'
16
- }
17
-
18
- return `${dataUri}${globalThis.encodeURIComponent(svgElement.outerHTML)}`
19
- }
@@ -1,12 +0,0 @@
1
- import type { CyNodeModuleTypes } from './CyNodeModuleTypes.ts'
2
-
3
- export const generateIconMap: () => Record<CyNodeModuleTypes, string> = () => ({
4
- archivist: '',
5
- bridge: '',
6
- diviner: '',
7
-
8
- module: '',
9
- node: '',
10
- sentinel: '',
11
- witness: '',
12
- })
@@ -1,5 +0,0 @@
1
- export * from './CyNodeModuleTypes.ts'
2
- export * from './encodeSvg.ts'
3
- export * from './iconMap.ts'
4
- export * from './layout/index.ts'
5
- export * from './parseModuleType.ts'
@@ -1,5 +0,0 @@
1
- export const ColaLayout = {
2
- centerGraph: false,
3
- convergenceThreshold: 0.01,
4
- name: 'cola',
5
- }
@@ -1,12 +0,0 @@
1
- import type { LayoutOptions } from 'cytoscape'
2
-
3
- export const ConcentricLayout: LayoutOptions = {
4
- concentric: function (node) {
5
- return node.degree(false)
6
- },
7
- levelWidth: function () {
8
- return 2
9
- },
10
- minNodeSpacing: 75,
11
- name: 'concentric',
12
- }
@@ -1,2 +0,0 @@
1
- export * from './ColaLayout.ts'
2
- export * from './ConcentricLayout.ts'
@@ -1,29 +0,0 @@
1
- import { isArchivistInstance } from '@xyo-network/archivist-model'
2
- import { isBridgeInstance } from '@xyo-network/bridge-model'
3
- import { isDivinerInstance } from '@xyo-network/diviner-model'
4
- import type { ModuleInstance } from '@xyo-network/module-model'
5
- import { isNodeInstance } from '@xyo-network/node-model'
6
- import { isSentinelInstance } from '@xyo-network/sentinel-model'
7
- import { isWitnessModule } from '@xyo-network/witness-model'
8
-
9
- import type { CyNodeModuleTypes } from './CyNodeModuleTypes.ts'
10
-
11
- export const parseModuleType = (mod?: ModuleInstance): CyNodeModuleTypes => {
12
- let type: CyNodeModuleTypes = 'module'
13
- if (mod) {
14
- if (isArchivistInstance(mod)) {
15
- type = 'archivist'
16
- } else if (isBridgeInstance(mod)) {
17
- type = 'bridge'
18
- } else if (isDivinerInstance(mod)) {
19
- type = 'diviner'
20
- } else if (isNodeInstance(mod)) {
21
- type = 'node'
22
- } else if (isSentinelInstance(mod)) {
23
- type = 'sentinel'
24
- } else if (isWitnessModule(mod)) {
25
- type = 'witness'
26
- }
27
- }
28
- return type
29
- }
@@ -1,16 +0,0 @@
1
- import cytoscape from 'cytoscape'
2
- import cola from 'cytoscape-cola'
3
- import coseBilkent from 'cytoscape-cose-bilkent'
4
- import type { PropsWithChildren } from 'react'
5
- import React, { useMemo } from 'react'
6
-
7
- export const WithExtensions: React.FC<PropsWithChildren> = ({ children }) => {
8
- // eslint-disable-next-line react-x/no-unnecessary-use-memo
9
- const initialized = useMemo(() => {
10
- cytoscape.use(cola)
11
- cytoscape.use(coseBilkent)
12
- return true
13
- }, [])
14
-
15
- return <>{initialized ? children : undefined}</>
16
- }
@@ -1 +0,0 @@
1
- export * from './WithExtensions.tsx'
@@ -1,3 +0,0 @@
1
- export * from './lib/index.ts'
2
- export * from './module/index.ts'
3
- export * from './relational/index.ts'
@@ -1,16 +0,0 @@
1
- import type { FlexBoxProps } from '@xylabs/react-flexbox'
2
- import type { Address } from '@xylabs/sdk-js'
3
- import type { NodeInstance } from '@xyo-network/node-model'
4
- import type { CytoscapeOptions } from 'cytoscape'
5
- import type { PropsWithChildren, ReactNode } from 'react'
6
-
7
- export interface NodeRelationalGraphProps extends PropsWithChildren<FlexBoxProps> {
8
- actions?: ReactNode
9
- detail?: ReactNode
10
- layout?: 'dagre' | 'euler' | 'cose-bilkent' | 'cola'
11
- layoutOptions?: object
12
- node?: WeakRef<NodeInstance>
13
- onHover?: (address?: Address) => void
14
- options?: CytoscapeOptions
15
- showDetails?: boolean
16
- }
@@ -1 +0,0 @@
1
- export * from './RelationalGraphProps.ts'
@@ -1,36 +0,0 @@
1
- import type { Meta, StoryObj } from '@storybook/react-vite'
2
- import { MemoryArchivist, MemoryArchivistConfigSchema } from '@xyo-network/archivist-memory'
3
- import { IdWitness, IdWitnessConfigSchema } from '@xyo-network/id-plugin'
4
- import React from 'react'
5
-
6
- import { ModuleCardParser } from './CardParser.tsx'
7
-
8
- const meta: Meta<typeof ModuleCardParser> = {
9
- component: ModuleCardParser,
10
- render: (props, { loaded }) => <ModuleCardParser {...props} {...loaded} />,
11
- title: 'node/renderer/ModuleCardParser',
12
- }
13
-
14
- export default meta
15
- type Story = StoryObj<typeof ModuleCardParser>
16
-
17
- export const WithArchivist: Story = {
18
- loaders: [
19
- async () => {
20
- const ParentArchivist = await MemoryArchivist.create({ config: { name: 'ParentArchivist', schema: MemoryArchivistConfigSchema } })
21
- return {
22
- mod: await MemoryArchivist.create({
23
- config: {
24
- name: 'MemoryArchivist', parents: { write: [ParentArchivist.address] }, schema: MemoryArchivistConfigSchema,
25
- },
26
- }),
27
- }
28
- },
29
- ],
30
- }
31
-
32
- export const WithWitness: Story = {
33
- loaders: [
34
- async () => ({ mod: await IdWitness.create({ config: { name: 'IdWitness', schema: IdWitnessConfigSchema } }) }),
35
- ],
36
- }
@@ -1,24 +0,0 @@
1
- import { asArchivistInstance, isArchivistInstance } from '@xyo-network/archivist-model'
2
- import { asDivinerInstance, isDivinerInstance } from '@xyo-network/diviner-model'
3
- import type { ModuleInstance } from '@xyo-network/module-model'
4
- import { ArchivistCard } from '@xyo-network/react-archivist'
5
- import { DivinerCard, ModuleCard } from '@xyo-network/react-module'
6
- import React from 'react'
7
-
8
- export interface ModuleCardParserProps {
9
- mod?: ModuleInstance
10
- }
11
-
12
- export const ModuleCardParser: React.FC<ModuleCardParserProps> = ({ mod }) => {
13
- switch (true) {
14
- case isArchivistInstance(mod): {
15
- return <ArchivistCard mod={asArchivistInstance(mod)} />
16
- }
17
- case isDivinerInstance(mod): {
18
- return <DivinerCard mod={asDivinerInstance(mod)} />
19
- }
20
- default: {
21
- return <ModuleCard mod={mod} />
22
- }
23
- }
24
- }
@@ -1,22 +0,0 @@
1
- import { CancelRounded } from '@mui/icons-material'
2
- import { IconButton } from '@mui/material'
3
- import type { FlexBoxProps } from '@xylabs/react-flexbox'
4
- import { FlexGrowCol, FlexRow } from '@xylabs/react-flexbox'
5
- import React from 'react'
6
-
7
- export interface DetailsFlexboxProps extends FlexBoxProps {
8
- onClose?: () => void
9
- }
10
-
11
- export const DetailsFlexbox: React.FC<DetailsFlexboxProps> = ({ children, onClose }) => {
12
- return (
13
- <FlexGrowCol alignItems="end" justifyContent="start" id="module-detail" width="100%" p={2} gap={2}>
14
- <FlexRow justifyContent="end">
15
- <IconButton onClick={onClose} size="small">
16
- <CancelRounded />
17
- </IconButton>
18
- </FlexRow>
19
- {children}
20
- </FlexGrowCol>
21
- )
22
- }
@@ -1,118 +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 { MemoryNode } from '@xyo-network/node-memory'
9
- import { NodeConfigSchema } from '@xyo-network/node-model'
10
- import { NodeProvider, useWeakProvidedNode } from '@xyo-network/react-node'
11
- import { DefaultSeedPhrase } from '@xyo-network/react-storybook'
12
- import { useWallet, WalletProvider } from '@xyo-network/react-wallet'
13
- import { SentinelConfigSchema } from '@xyo-network/sentinel'
14
- import { MemorySentinel } from '@xyo-network/sentinel-memory'
15
- import React, { useState } from 'react'
16
-
17
- import { ModuleGraphFlexBoxWithProvider } from './GraphFlexBox.tsx'
18
-
19
- const client = { url: 'http://localhost:8080/node' }
20
-
21
- const MemoryNodeDecorator: Decorator = (Story, args) => {
22
- const [node, setNode] = useState<MemoryNode>()
23
-
24
- useAsyncEffect(
25
-
26
- async () => {
27
- try {
28
- const node = await MemoryNode.create({ config: { name: 'GlobalNode', schema: NodeConfigSchema } })
29
- const node1 = await MemoryNode.create({ config: { name: 'ChildNode', schema: NodeConfigSchema } })
30
- const bridge = await HttpBridge.create({
31
- config: {
32
- name: 'Bridge', client, schema: HttpBridgeConfigSchema, security: { allowAnonymous: true },
33
- },
34
- })
35
- await node.register(bridge)
36
- await node.attach(bridge.address, true)
37
-
38
- const archivist = await MemoryArchivist.create({ config: { name: 'RootStorageArchivist', schema: MemoryArchivistConfigSchema } })
39
- await node.register(archivist)
40
- await node.attach(archivist.address, true)
41
-
42
- const sentinel = await MemorySentinel.create({
43
- config: {
44
- name: 'MemorySentinel', schema: SentinelConfigSchema, synchronous: true, tasks: [],
45
- },
46
- })
47
- await node.register(sentinel)
48
- await node.attach(sentinel.address, true)
49
-
50
- const archivist1 = await MemoryArchivist.create({ config: { name: 'RootStorageArchivist1', schema: MemoryArchivistConfigSchema } })
51
- await node1.register(archivist1)
52
- await node1.attach(archivist1.address, true)
53
-
54
- await node.register(node1)
55
- await node.attach(node1.address, true)
56
-
57
- setNode(node)
58
- } catch (e) {
59
- console.error('Error Creating MemoryNode', e)
60
- }
61
- },
62
- [],
63
- )
64
-
65
- const [wallet] = useWallet({ mnemonic: DefaultSeedPhrase })
66
-
67
- return (
68
- <WalletProvider rootWallet={wallet}>
69
- <NodeProvider node={node}>
70
- <Story {...args} />
71
- </NodeProvider>
72
- </WalletProvider>
73
- )
74
- }
75
-
76
- export default {
77
- component: ModuleGraphFlexBoxWithProvider,
78
- title: 'node/renderer/ModuleGraphFlexBoxWithProvider',
79
- } as Meta
80
-
81
- const Template: StoryFn<typeof ModuleGraphFlexBoxWithProvider> = props => <ModuleGraphFlexBoxWithProvider {...props} />
82
-
83
- const TemplateWithProvidedModule: StoryFn<typeof ModuleGraphFlexBoxWithProvider> = (props) => {
84
- const [node] = useWeakProvidedNode()
85
- const [layout, setLayout] = useState<'dagre' | 'euler' | 'cose-bilkent' | 'cola'>('euler')
86
- return (
87
- <div>
88
- <ButtonGroup>
89
- <Button onClick={() => setLayout('dagre')}>Dagre</Button>
90
- <Button onClick={() => setLayout('euler')}>Euler</Button>
91
- <Button onClick={() => setLayout('cose-bilkent')}>CoseBilkent</Button>
92
- <Button onClick={() => setLayout('cola')}>Cola</Button>
93
- </ButtonGroup>
94
- <ModuleGraphFlexBoxWithProvider rootModule={node} {...props} layout={layout} />
95
- </div>
96
- )
97
- }
98
-
99
- const defaultProps = {
100
- height: 'calc(100vh - 20px)',
101
- width: '100%',
102
- }
103
-
104
- const Default = Template.bind({})
105
- Default.args = {}
106
- Default.decorators = [MemoryNodeDecorator]
107
-
108
- const WithProvidedNode = TemplateWithProvidedModule.bind({})
109
- WithProvidedNode.args = { ...defaultProps }
110
- WithProvidedNode.decorators = [MemoryNodeDecorator]
111
-
112
- const WithDisabledDetails = TemplateWithProvidedModule.bind({})
113
- WithDisabledDetails.args = { ...defaultProps, disableModuleDetails: true }
114
- WithDisabledDetails.decorators = [MemoryNodeDecorator]
115
-
116
- export {
117
- Default, WithDisabledDetails, WithProvidedNode,
118
- }
@@ -1,84 +0,0 @@
1
- import { Button } from '@mui/material'
2
- import type { FlexBoxProps } from '@xylabs/react-flexbox'
3
- import type { ModuleInstance } from '@xyo-network/module-model'
4
- import React, { useRef } from 'react'
5
-
6
- import { CytoscapeInstanceProvider } from '../../../contexts/index.ts'
7
- import {
8
- useElements, useModuleDetails, useRelationalGraphOptions,
9
- } from '../../../hooks/index.ts'
10
- import { WithExtensions } from '../../cytoscape-extensions/index.ts'
11
- import { NodeRelationalGraphFlexBox } from '../../relational/index.ts'
12
- import { DetailsFlexbox } from './DetailsFlexbox.tsx'
13
- import { ModuleGraphNodeHover } from './node/index.ts'
14
- import { StyledModuleHoverPopper } from './Popper.tsx'
15
-
16
- export interface ModuleGraphFlexBoxProps extends FlexBoxProps {
17
- disableModuleDetails?: boolean
18
- hideActions?: boolean
19
- layout?: 'dagre' | 'euler' | 'cose-bilkent' | 'cola'
20
- layoutOptions?: object
21
- rootModule?: WeakRef<ModuleInstance> | null
22
- }
23
-
24
- export const ModuleGraphFlexBox: React.FC<ModuleGraphFlexBoxProps> = ({
25
- hideActions, rootModule, disableModuleDetails, ...props
26
- }) => {
27
- const cytoscapeRef = useRef<HTMLDivElement>(null)
28
- const {
29
- handleToggleLabels, hideLabels, options,
30
- } = useRelationalGraphOptions(rootModule ?? undefined)
31
- const {
32
- hoveredNode, setHoveredNode, toggleSelectedElement,
33
- } = useElements(hideLabels)
34
-
35
- const { mod, onModuleDetails } = useModuleDetails(rootModule, () => setHoveredNode(undefined))
36
-
37
- return (
38
- <WithExtensions>
39
- <NodeRelationalGraphFlexBox
40
- actions={
41
- mod
42
- ? null
43
- : hideActions
44
- ? null
45
- : (
46
- <Button size="small" onClick={handleToggleLabels} variant="contained">
47
- Toggle Labels
48
- </Button>
49
- )
50
-
51
- }
52
- showDetails={!!mod}
53
- detail={<DetailsFlexbox onClose={() => onModuleDetails(null)} />}
54
- options={options}
55
- ref={cytoscapeRef}
56
- width="100%"
57
- {...props}
58
- >
59
- <ModuleGraphNodeHover node={hoveredNode}>
60
- {element => (
61
- <StyledModuleHoverPopper
62
- anchorEl={element}
63
- container={cytoscapeRef.current}
64
- node={hoveredNode}
65
- onClose={() => setHoveredNode(undefined)}
66
- onModuleExplore={toggleSelectedElement}
67
- onModuleDetails={disableModuleDetails ? undefined : onModuleDetails}
68
- placement="top"
69
- open
70
- />
71
- )}
72
- </ModuleGraphNodeHover>
73
- </NodeRelationalGraphFlexBox>
74
- </WithExtensions>
75
- )
76
- }
77
-
78
- export const ModuleGraphFlexBoxWithProvider: React.FC<ModuleGraphFlexBoxProps> = (props) => {
79
- return (
80
- <CytoscapeInstanceProvider>
81
- <ModuleGraphFlexBox {...props} />
82
- </CytoscapeInstanceProvider>
83
- )
84
- }