File tree Expand file tree Collapse file tree 4 files changed +33
-3
lines changed
Expand file tree Collapse file tree 4 files changed +33
-3
lines changed Original file line number Diff line number Diff line change @@ -18,9 +18,13 @@ import {
1818 Graph ,
1919 GraphModel ,
2020 GraphToolbar ,
21+ initializeCytoscape ,
2122 ModelNode ,
2223 NodeViewer ,
2324} from '../dist/committed-components-graph.cjs.js'
25+ import { use } from 'cytoscape'
26+
27+ initializeCytoscape ( use )
2428
2529const App : React . FC = ( ) => {
2630 const [ model , setModel ] = React . useState (
Original file line number Diff line number Diff line change 1+ /* eslint-disable @typescript-eslint/no-unsafe-member-access */
2+ /* eslint-disable @typescript-eslint/no-unsafe-assignment */
3+ /* eslint-disable @typescript-eslint/no-unsafe-call */
14import { useTheme } from '@committed/components'
25import {
36 Css ,
@@ -45,6 +48,26 @@ import {
4548} from './CytoscapeGraphLayoutAdapter'
4649import { useCyListener } from './useCyListener'
4750
51+ /**
52+ * Call to initialize the additional modules.
53+ */
54+ /*
55+ * This is a work-around - the modules do not seem to be registered when using as a library so must be called by the lib user.
56+ * Should be able to remove but may be a bundling issue.
57+ */
58+ export function initializeCytoscape (
59+ cyuse : ( module : cytoscape . Ext ) => void
60+ ) : void {
61+ try {
62+ cyuse ( CytoscapeGraphLayoutAdapter . register )
63+ cyuse ( ccola )
64+ } catch {
65+ // Ignore multiple attempts to initialize
66+ }
67+ }
68+
69+ initializeCytoscape ( use )
70+
4871export interface CyGraphRendererOptions extends GraphRendererOptions {
4972 renderOptions : Pick <
5073 React . ComponentProps < typeof CytoscapeComponent > ,
@@ -61,9 +84,6 @@ export interface CyGraphRendererOptions extends GraphRendererOptions {
6184 >
6285}
6386
64- use ( CytoscapeGraphLayoutAdapter . register )
65- use ( ccola )
66-
6787const dblClick = ( ) => {
6888 // eslint-disable-next-line @typescript-eslint/no-explicit-any
6989 let clicked : any | null = null
Original file line number Diff line number Diff line change 11export * from './CytoscapeRenderer'
2+ export * from './CytoscapeGraphLayoutAdapter'
Original file line number Diff line number Diff line change @@ -81,9 +81,14 @@ import {
8181 GraphModel ,
8282 GraphToolbar ,
8383 cytoscapeRenderer ,
84+ initializeCytoscape ,
8485} from ' @committed/components-graph'
8586import { Row , ThemeProvider } from ' @committed/components'
8687
88+ // If using the cytoscape renderer, just once in your application add
89+ import { use } from ' cytoscape'
90+ initializeCytoscape (use )
91+
8792const App: React .FC = () => {
8893 const [model, setModel] = React .useState (
8994 addRandomEdge (addRandomNode (GraphModel .createEmpty (), 20 ), 15 )
You can’t perform that action at this time.
0 commit comments