@xyo-network/react-node-renderer 2.47.35 → 2.47.37
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/dist/cjs/Cytoscape/CytoscapeElements.js +48 -0
- package/dist/cjs/Cytoscape/CytoscapeElements.js.map +1 -0
- package/dist/cjs/Cytoscape/CytoscapeIcons.js +18 -0
- package/dist/cjs/Cytoscape/CytoscapeIcons.js.map +1 -0
- package/dist/cjs/Cytoscape/CytoscapeStyles.js +39 -0
- package/dist/cjs/Cytoscape/CytoscapeStyles.js.map +1 -0
- package/dist/cjs/Cytoscape/index.js +7 -0
- package/dist/cjs/Cytoscape/index.js.map +1 -0
- package/dist/cjs/components/RelationalGraph.js +9 -4
- package/dist/cjs/components/RelationalGraph.js.map +1 -1
- package/dist/cjs/hooks/cytoscape/index.js +6 -0
- package/dist/cjs/hooks/cytoscape/index.js.map +1 -0
- package/dist/cjs/hooks/cytoscape/useCytoscapeElements.js +59 -0
- package/dist/cjs/hooks/cytoscape/useCytoscapeElements.js.map +1 -0
- package/dist/cjs/hooks/cytoscape/useCytoscapeLayout.js +13 -0
- package/dist/cjs/hooks/cytoscape/useCytoscapeLayout.js.map +1 -0
- package/dist/cjs/hooks/cytoscape/useCytoscapeOptions.js +18 -0
- package/dist/cjs/hooks/cytoscape/useCytoscapeOptions.js.map +1 -0
- package/dist/cjs/hooks/cytoscape/useCytoscapeStyle.js +19 -0
- package/dist/cjs/hooks/cytoscape/useCytoscapeStyle.js.map +1 -0
- package/dist/cjs/hooks/cytoscape/useIcons.js +22 -0
- package/dist/cjs/hooks/cytoscape/useIcons.js.map +1 -0
- package/dist/cjs/hooks/index.js +1 -2
- package/dist/cjs/hooks/index.js.map +1 -1
- package/dist/cjs/lib/utils.js +4 -0
- package/dist/cjs/lib/utils.js.map +1 -1
- package/dist/docs.json +221 -220
- package/dist/esm/Cytoscape/CytoscapeElements.js +40 -0
- package/dist/esm/Cytoscape/CytoscapeElements.js.map +1 -0
- package/dist/esm/Cytoscape/CytoscapeIcons.js +14 -0
- package/dist/esm/Cytoscape/CytoscapeIcons.js.map +1 -0
- package/dist/esm/Cytoscape/CytoscapeStyles.js +33 -0
- package/dist/esm/Cytoscape/CytoscapeStyles.js.map +1 -0
- package/dist/esm/Cytoscape/index.js +4 -0
- package/dist/esm/Cytoscape/index.js.map +1 -0
- package/dist/esm/components/RelationalGraph.js +10 -5
- package/dist/esm/components/RelationalGraph.js.map +1 -1
- package/dist/esm/hooks/cytoscape/index.js +3 -0
- package/dist/esm/hooks/cytoscape/index.js.map +1 -0
- package/dist/esm/hooks/cytoscape/useCytoscapeElements.js +53 -0
- package/dist/esm/hooks/cytoscape/useCytoscapeElements.js.map +1 -0
- package/dist/esm/hooks/cytoscape/useCytoscapeLayout.js +9 -0
- package/dist/esm/hooks/cytoscape/useCytoscapeLayout.js.map +1 -0
- package/dist/esm/hooks/cytoscape/useCytoscapeOptions.js +14 -0
- package/dist/esm/hooks/cytoscape/useCytoscapeOptions.js.map +1 -0
- package/dist/esm/hooks/cytoscape/useCytoscapeStyle.js +15 -0
- package/dist/esm/hooks/cytoscape/useCytoscapeStyle.js.map +1 -0
- package/dist/esm/hooks/{useIcons.js → cytoscape/useIcons.js} +3 -13
- package/dist/esm/hooks/cytoscape/useIcons.js.map +1 -0
- package/dist/esm/hooks/index.js +1 -2
- package/dist/esm/hooks/index.js.map +1 -1
- package/dist/esm/lib/utils.js +4 -0
- package/dist/esm/lib/utils.js.map +1 -1
- package/dist/types/Cytoscape/CytoscapeElements.d.ts +18 -0
- package/dist/types/Cytoscape/CytoscapeElements.d.ts.map +1 -0
- package/dist/types/Cytoscape/CytoscapeIcons.d.ts +5 -0
- package/dist/types/Cytoscape/CytoscapeIcons.d.ts.map +1 -0
- package/dist/types/Cytoscape/CytoscapeStyles.d.ts +16 -0
- package/dist/types/Cytoscape/CytoscapeStyles.d.ts.map +1 -0
- package/dist/types/Cytoscape/index.d.ts +4 -0
- package/dist/types/Cytoscape/index.d.ts.map +1 -0
- package/dist/types/components/RelationalGraph.d.ts +1 -2
- package/dist/types/components/RelationalGraph.d.ts.map +1 -1
- package/dist/types/hooks/cytoscape/index.d.ts +3 -0
- package/dist/types/hooks/cytoscape/index.d.ts.map +1 -0
- package/dist/types/hooks/cytoscape/useCytoscapeElements.d.ts +7 -0
- package/dist/types/hooks/cytoscape/useCytoscapeElements.d.ts.map +1 -0
- package/dist/types/hooks/cytoscape/useCytoscapeLayout.d.ts +2 -0
- package/dist/types/hooks/cytoscape/useCytoscapeLayout.d.ts.map +1 -0
- package/dist/types/hooks/cytoscape/useCytoscapeOptions.d.ts +3 -0
- package/dist/types/hooks/cytoscape/useCytoscapeOptions.d.ts.map +1 -0
- package/dist/types/hooks/cytoscape/useCytoscapeStyle.d.ts +2 -0
- package/dist/types/hooks/cytoscape/useCytoscapeStyle.d.ts.map +1 -0
- package/dist/types/hooks/cytoscape/useIcons.d.ts +3 -0
- package/dist/types/hooks/cytoscape/useIcons.d.ts.map +1 -0
- package/dist/types/hooks/index.d.ts +1 -2
- package/dist/types/hooks/index.d.ts.map +1 -1
- package/dist/types/lib/utils.d.ts.map +1 -1
- package/package.json +7 -6
- package/src/Cytoscape/CytoscapeElements.ts +46 -0
- package/src/Cytoscape/CytoscapeIcons.tsx +18 -0
- package/src/Cytoscape/CytoscapeStyles.ts +38 -0
- package/src/Cytoscape/index.ts +3 -0
- package/src/components/RelationalGraph.stories.tsx +5 -0
- package/src/components/RelationalGraph.tsx +15 -7
- package/src/hooks/cytoscape/index.ts +2 -0
- package/src/hooks/cytoscape/useCytoscapeElements.ts +59 -0
- package/src/hooks/cytoscape/useCytoscapeLayout.ts +14 -0
- package/src/hooks/cytoscape/useCytoscapeOptions.ts +25 -0
- package/src/hooks/cytoscape/useCytoscapeStyle.ts +22 -0
- package/src/hooks/cytoscape/useIcons.tsx +19 -0
- package/src/hooks/index.ts +1 -2
- package/src/lib/utils.ts +4 -0
- package/dist/cjs/hooks/useCytoscapeElements.js +0 -68
- package/dist/cjs/hooks/useCytoscapeElements.js.map +0 -1
- package/dist/cjs/hooks/useCytoscapeOptions.js +0 -54
- package/dist/cjs/hooks/useCytoscapeOptions.js.map +0 -1
- package/dist/cjs/hooks/useIcons.js +0 -33
- package/dist/cjs/hooks/useIcons.js.map +0 -1
- package/dist/esm/hooks/useCytoscapeElements.js +0 -61
- package/dist/esm/hooks/useCytoscapeElements.js.map +0 -1
- package/dist/esm/hooks/useCytoscapeOptions.js +0 -50
- package/dist/esm/hooks/useCytoscapeOptions.js.map +0 -1
- package/dist/esm/hooks/useIcons.js.map +0 -1
- package/dist/types/hooks/useCytoscapeElements.d.ts +0 -6
- package/dist/types/hooks/useCytoscapeElements.d.ts.map +0 -1
- package/dist/types/hooks/useCytoscapeOptions.d.ts +0 -3
- package/dist/types/hooks/useCytoscapeOptions.d.ts.map +0 -1
- package/dist/types/hooks/useIcons.d.ts +0 -3
- package/dist/types/hooks/useIcons.d.ts.map +0 -1
- package/src/hooks/useCytoscapeElements.ts +0 -67
- package/src/hooks/useCytoscapeOptions.ts +0 -57
- package/src/hooks/useIcons.tsx +0 -33
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { useAsyncEffect } from '@xylabs/react-shared'
|
|
2
|
-
import { ModuleWrapper } from '@xyo-network/module'
|
|
3
|
-
import { NodeWrapper } from '@xyo-network/node'
|
|
4
|
-
import { useProvidedWrappedNode } from '@xyo-network/react-node'
|
|
5
|
-
import { CytoscapeOptions } from 'cytoscape'
|
|
6
|
-
import { useState } from 'react'
|
|
7
|
-
|
|
8
|
-
import { parseModuleType } from '../lib'
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Note: Relies on describe but could eventually be converted to a discover call
|
|
12
|
-
* Logic would be similar to what the bridge does
|
|
13
|
-
*/
|
|
14
|
-
export const useCytoscapeElements = () => {
|
|
15
|
-
const [node] = useProvidedWrappedNode()
|
|
16
|
-
const [elements, setElements] = useState<CytoscapeOptions['elements']>()
|
|
17
|
-
|
|
18
|
-
useAsyncEffect(
|
|
19
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
20
|
-
async () => {
|
|
21
|
-
if (node) {
|
|
22
|
-
try {
|
|
23
|
-
const newElements = []
|
|
24
|
-
const wrapper = NodeWrapper.wrap(node)
|
|
25
|
-
const description = await wrapper?.describe()
|
|
26
|
-
const rootNodeId = description.name ?? description.address.substring(0, 6)
|
|
27
|
-
newElements.push({
|
|
28
|
-
data: { id: rootNodeId, type: parseModuleType(description.queries) },
|
|
29
|
-
})
|
|
30
|
-
const children = description.children
|
|
31
|
-
await Promise.all(
|
|
32
|
-
(children ?? [])?.map(async (address) => {
|
|
33
|
-
const [result] = await wrapper.resolveWrapped(ModuleWrapper, { address: [address] })
|
|
34
|
-
try {
|
|
35
|
-
const description = await result.describe()
|
|
36
|
-
const newNodeId = description.name ?? description.address.substring(0, 6)
|
|
37
|
-
const newNode = {
|
|
38
|
-
data: {
|
|
39
|
-
id: newNodeId,
|
|
40
|
-
type: parseModuleType(description.queries),
|
|
41
|
-
},
|
|
42
|
-
}
|
|
43
|
-
newElements.push(newNode)
|
|
44
|
-
const newEdge = {
|
|
45
|
-
data: {
|
|
46
|
-
id: `${rootNodeId}/${newNodeId}`,
|
|
47
|
-
source: rootNodeId,
|
|
48
|
-
target: newNodeId,
|
|
49
|
-
},
|
|
50
|
-
}
|
|
51
|
-
newElements.push(newEdge)
|
|
52
|
-
} catch (e) {
|
|
53
|
-
console.error(e, result)
|
|
54
|
-
}
|
|
55
|
-
}),
|
|
56
|
-
)
|
|
57
|
-
setElements(newElements)
|
|
58
|
-
} catch (e) {
|
|
59
|
-
console.error(e)
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
[node],
|
|
64
|
-
)
|
|
65
|
-
|
|
66
|
-
return elements
|
|
67
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { useTheme } from '@mui/material'
|
|
2
|
-
import { CytoscapeOptions } from 'cytoscape'
|
|
3
|
-
import { useMemo } from 'react'
|
|
4
|
-
|
|
5
|
-
import { CyNodeIcons, useIcons } from './useIcons'
|
|
6
|
-
|
|
7
|
-
export const useCytoscapeOptions = (elements: CytoscapeOptions['elements']) => {
|
|
8
|
-
const theme = useTheme()
|
|
9
|
-
const icons = useIcons()
|
|
10
|
-
|
|
11
|
-
const options = useMemo<CytoscapeOptions>(
|
|
12
|
-
() => ({
|
|
13
|
-
elements,
|
|
14
|
-
layout: {
|
|
15
|
-
minNodeSpacing: 75,
|
|
16
|
-
name: 'concentric',
|
|
17
|
-
},
|
|
18
|
-
style: [
|
|
19
|
-
{
|
|
20
|
-
selector: 'node[id]',
|
|
21
|
-
style: {
|
|
22
|
-
color: theme.palette.text.primary,
|
|
23
|
-
'font-family': 'Lexend Deca, Helvetica, sans-serif',
|
|
24
|
-
'font-size': 14,
|
|
25
|
-
'text-margin-y': -5,
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
selector: 'node',
|
|
30
|
-
style: {
|
|
31
|
-
'background-color': theme.palette.primary.main,
|
|
32
|
-
'background-height': '75%',
|
|
33
|
-
// TODO - make dynamic
|
|
34
|
-
'background-image': (elem) => icons[elem.data('type') as CyNodeIcons],
|
|
35
|
-
'background-image-smoothing': 'yes',
|
|
36
|
-
'background-width': '75%',
|
|
37
|
-
label: 'data(id)',
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
selector: 'edge',
|
|
42
|
-
style: {
|
|
43
|
-
'curve-style': 'bezier',
|
|
44
|
-
'line-color': theme.palette.divider,
|
|
45
|
-
'line-opacity': 0.1,
|
|
46
|
-
'target-arrow-color': theme.palette.divider,
|
|
47
|
-
'target-arrow-shape': 'triangle',
|
|
48
|
-
width: 3,
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
],
|
|
52
|
-
}),
|
|
53
|
-
[elements, icons, theme.palette.divider, theme.palette.primary.main, theme.palette.text.primary],
|
|
54
|
-
)
|
|
55
|
-
|
|
56
|
-
return options
|
|
57
|
-
}
|
package/src/hooks/useIcons.tsx
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import GridViewRoundedIcon from '@mui/icons-material/GridViewRounded'
|
|
2
|
-
import HubIcon from '@mui/icons-material/Hub'
|
|
3
|
-
import QuestionMarkRoundedIcon from '@mui/icons-material/QuestionMarkRounded'
|
|
4
|
-
import VisibilityRoundedIcon from '@mui/icons-material/VisibilityRounded'
|
|
5
|
-
import { SvgIconTypeMap, useTheme } from '@mui/material'
|
|
6
|
-
import { OverridableComponent } from '@mui/material/OverridableComponent'
|
|
7
|
-
import { useMemo } from 'react'
|
|
8
|
-
|
|
9
|
-
import { encodeSvg } from '../lib'
|
|
10
|
-
|
|
11
|
-
export type CyNodeIcons = 'node' | 'archivist' | 'diviner' | 'module'
|
|
12
|
-
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
14
|
-
const CyIconSet: Record<CyNodeIcons, OverridableComponent<SvgIconTypeMap<{}, 'svg'>>> = {
|
|
15
|
-
archivist: GridViewRoundedIcon,
|
|
16
|
-
diviner: VisibilityRoundedIcon,
|
|
17
|
-
module: QuestionMarkRoundedIcon,
|
|
18
|
-
node: HubIcon,
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export const useIcons = () => {
|
|
22
|
-
const theme = useTheme()
|
|
23
|
-
const icons = useMemo(() => {
|
|
24
|
-
const iconMap: Record<CyNodeIcons, string> = { archivist: '', diviner: '', module: '', node: '' }
|
|
25
|
-
return Object.entries(CyIconSet).reduce((acc, [name, IconComponent]) => {
|
|
26
|
-
const icon = <IconComponent fontSize="small" />
|
|
27
|
-
acc[name as CyNodeIcons] = encodeSvg(icon, theme.palette.getContrastText(theme.palette.text.primary))
|
|
28
|
-
return acc
|
|
29
|
-
}, iconMap)
|
|
30
|
-
}, [theme.palette])
|
|
31
|
-
|
|
32
|
-
return icons
|
|
33
|
-
}
|