Skip to content

Commit c5b5d73

Browse files
committed
Trying high-level tasks
1 parent 9047d80 commit c5b5d73

File tree

17 files changed

+205
-18
lines changed

17 files changed

+205
-18
lines changed

create-network/package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "@cytoscape-web/create-network",
3+
"description": "An example app to create a network in workspace",
4+
"version": "1.0.0",
5+
"private": "true",
6+
"type": "module",
7+
"scripts": {
8+
"build": "webpack --config webpack.config.js",
9+
"dev": "webpack serve --open /remoteEntry.js --mode development"
10+
}
11+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { ComponentType, CyApp } from '@cytoscape-web/types'
2+
3+
export const CreateNetworkApp: CyApp = {
4+
id: 'createNetwork',
5+
name: 'Create Network App',
6+
url: '',
7+
components: [
8+
{
9+
id: 'SimplePanel',
10+
type: ComponentType.Panel,
11+
},
12+
],
13+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { useEffect } from 'react'
2+
3+
// Dynamic import from the host app
4+
import { useWorkspaceStore } from 'cyweb/WorkspaceStore'
5+
6+
import { IdType } from '@cytoscape-web/types'
7+
8+
const CreateNetworkPanel = (): JSX.Element => {
9+
const workspace = useWorkspaceStore((state: any) => state.workspace)
10+
11+
const ids: IdType[] = workspace.networkIds
12+
13+
useEffect(() => {
14+
console.log('Create Network Panel initialized', workspace)
15+
}, [])
16+
17+
return (
18+
<div>
19+
<h4>Create a network</h4>
20+
<p>Current Network ID: {workspace.currentNetworkId}</p>
21+
<h5>Networks:</h5>
22+
</div>
23+
)
24+
}
25+
26+
export default CreateNetworkPanel

create-network/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { CreateNetworkApp as default } from './CreateNetworkApp'

create-network/src/remotes.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
declare module 'cyweb/WorkspaceStore'
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const useNetworkBuilder = (): any => {
2+
3+
}

create-network/tsconfig.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"include": ["src/**/*"],
3+
"compilerOptions": {
4+
"allowSyntheticDefaultImports": true,
5+
"outDir": "./dist/",
6+
"noImplicitAny": true,
7+
"module": "ESNext",
8+
"target": "ESNext",
9+
"jsx": "react-jsx",
10+
"allowJs": true,
11+
"esModuleInterop": true,
12+
"moduleResolution": "node",
13+
"sourceMap": true,
14+
"strictNullChecks": true,
15+
"resolveJsonModule": true,
16+
"baseUrl": "."
17+
}
18+
}

create-network/webpack.config.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import path from 'path'
2+
import url from 'url'
3+
import webpack from 'webpack'
4+
import packageJson from '../package.json' assert { type: 'json' }
5+
6+
const { ModuleFederationPlugin } = webpack.container
7+
8+
// Extract some properties from the package.json file to avoid duplication
9+
const deps = packageJson.peerDependencies
10+
11+
const __filename = url.fileURLToPath(import.meta.url)
12+
const __dirname = path.dirname(__filename)
13+
14+
const DEV_SERVER_PORT = 4001
15+
16+
export default {
17+
mode: 'development',
18+
devtool: false,
19+
target: 'web',
20+
optimization: {
21+
minimize: false,
22+
runtimeChunk: false,
23+
splitChunks: {
24+
chunks: 'async',
25+
name: false,
26+
},
27+
},
28+
entry: './src/index.ts',
29+
output: {
30+
clean: true,
31+
path: path.resolve(__dirname, 'dist'),
32+
publicPath: 'auto',
33+
},
34+
resolve: {
35+
extensions: ['.ts', '.tsx', '.js', '.jsx', '.json'],
36+
},
37+
plugins: [
38+
new ModuleFederationPlugin({
39+
name: 'createNetwork',
40+
filename: 'remoteEntry.js',
41+
remotes: {
42+
// Import some data providers from the host application
43+
cyweb: 'cyweb@http://localhost:5500/remoteEntry.js',
44+
},
45+
exposes: {
46+
'./CreateNetworkApp': './src/CreateNetworkApp',
47+
'./CreateNetworkPanel': './src/components/CreateNetworkPanel.tsx',
48+
},
49+
shared: {
50+
react: { singleton: true, requiredVersion: deps.react },
51+
'react-dom': { singleton: true, requiredVersion: deps['react-dom'] },
52+
},
53+
}),
54+
],
55+
module: {
56+
rules: [
57+
{
58+
test: /\.tsx?$/,
59+
use: 'ts-loader',
60+
exclude: /node_modules/,
61+
},
62+
],
63+
},
64+
devServer: {
65+
hot: true,
66+
port: DEV_SERVER_PORT,
67+
headers: {
68+
'Access-Control-Allow-Origin': '*', // allow access from any origin
69+
},
70+
},
71+
}

hello-world/src/HelloApp.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ComponentType, CyApp } from '@cytoscape-web/types'
33
export const HelloApp: CyApp = {
44
id: 'hello',
55
name: 'Hello Cy World App',
6+
description: 'Hello-world example app for Cytoscape Web',
67
url: '',
78
components: [
89
{
Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
1+
import { Network, NetworkWithView } from '@cytoscape-web/types'
12
import { MenuItem } from '@mui/material'
3+
import {
4+
createEmptyNetwork,
5+
useCreateNetworkWithView,
6+
} from 'cyweb/CreateNetwork'
27

38
const MenuExample = (): JSX.Element => {
9+
// Get the function to create a network with a view
10+
const createNetworkWithView = useCreateNetworkWithView()
11+
412
const handleClick = (): void => {
5-
alert('Hello from the external app!')
13+
// const newNet: Network = createEmptyNetwork()
14+
const newNetwork: NetworkWithView = createNetworkWithView({
15+
name: 'Empty Network1',
16+
})
17+
console.log('Empty network created', newNetwork)
18+
const network: Network = newNetwork.network
19+
alert(`Network Created: ${network.id}`)
620
}
721

8-
return <MenuItem onClick={handleClick}>Example Menu from App</MenuItem>
22+
return <MenuItem onClick={handleClick}>Create empty network</MenuItem>
923
}
1024

1125
export default MenuExample

0 commit comments

Comments
 (0)