Spaces:
Running
Running
Throw out Baklava.js, use SvelteFlow.
Browse files- web/.vscode/extensions.json +1 -1
- web/README.md +23 -5
- web/index.html +3 -3
- web/package-lock.json +0 -0
- web/package.json +14 -13
- web/src/App.svelte +46 -0
- web/src/App.vue +0 -117
- web/src/app.css +5 -0
- web/src/assets/favicon.ico +0 -0
- web/src/assets/vue.svg +0 -1
- web/src/components/GraphViz.vue +0 -19
- web/src/main.ts +9 -4
- web/src/style.css +0 -14
- web/src/vite-env.d.ts +1 -0
- web/svelte.config.js +7 -0
- web/tsconfig.json +12 -17
- web/tsconfig.node.json +1 -3
- web/vite.config.ts +2 -5
web/.vscode/extensions.json
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
{
|
2 |
-
"recommendations": ["
|
3 |
}
|
|
|
1 |
{
|
2 |
+
"recommendations": ["svelte.svelte-vscode"]
|
3 |
}
|
web/README.md
CHANGED
@@ -1,9 +1,27 @@
|
|
1 |
-
#
|
2 |
|
3 |
-
This template
|
4 |
|
5 |
-
##
|
6 |
|
7 |
-
|
|
|
|
|
8 |
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Vite Svelte Flow Template
|
2 |
|
3 |
+
This template creates a very basic [Svelte Flow](https://svelteflow.dev) app with [Vite](https://vite.dev).
|
4 |
|
5 |
+
## Get it!
|
6 |
|
7 |
+
```sh
|
8 |
+
npx degit xyflow/vite-svelte-flow-template app-name
|
9 |
+
```
|
10 |
|
11 |
+
## Installation
|
12 |
+
|
13 |
+
```sh
|
14 |
+
npm install
|
15 |
+
```
|
16 |
+
|
17 |
+
## Development
|
18 |
+
|
19 |
+
```sh
|
20 |
+
npm run dev
|
21 |
+
```
|
22 |
+
|
23 |
+
## Build
|
24 |
+
|
25 |
+
```sh
|
26 |
+
npm run build
|
27 |
+
```
|
web/index.html
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
-
<!
|
2 |
<html lang="en">
|
3 |
<head>
|
4 |
<meta charset="UTF-8" />
|
5 |
-
<link rel="icon"
|
6 |
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
7 |
-
<title>
|
8 |
</head>
|
9 |
<body>
|
10 |
<div id="app"></div>
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
<html lang="en">
|
3 |
<head>
|
4 |
<meta charset="UTF-8" />
|
5 |
+
<link rel="icon" href="/favicon.ico" />
|
6 |
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
7 |
+
<title>Svelte Flow Starter</title>
|
8 |
</head>
|
9 |
<body>
|
10 |
<div id="app"></div>
|
web/package-lock.json
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
web/package.json
CHANGED
@@ -1,23 +1,24 @@
|
|
1 |
{
|
2 |
-
"name": "
|
3 |
"private": true,
|
4 |
"version": "0.0.0",
|
5 |
"type": "module",
|
6 |
"scripts": {
|
7 |
"dev": "vite",
|
8 |
-
"build": "
|
9 |
-
"preview": "vite preview"
|
10 |
-
|
11 |
-
"dependencies": {
|
12 |
-
"baklavajs": "^2.4.3",
|
13 |
-
"graphology": "^0.25.4",
|
14 |
-
"sigma": "^3.0.0-beta.14",
|
15 |
-
"vue": "^3.4.21"
|
16 |
},
|
17 |
"devDependencies": {
|
18 |
-
"@
|
19 |
-
"
|
20 |
-
"
|
21 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
}
|
23 |
}
|
|
|
1 |
{
|
2 |
+
"name": "vite-svelte-flow-template",
|
3 |
"private": true,
|
4 |
"version": "0.0.0",
|
5 |
"type": "module",
|
6 |
"scripts": {
|
7 |
"dev": "vite",
|
8 |
+
"build": "vite build",
|
9 |
+
"preview": "vite preview",
|
10 |
+
"check": "svelte-check --tsconfig ./tsconfig.json"
|
|
|
|
|
|
|
|
|
|
|
11 |
},
|
12 |
"devDependencies": {
|
13 |
+
"@sveltejs/vite-plugin-svelte": "^3.0.2",
|
14 |
+
"@tsconfig/svelte": "^5.0.4",
|
15 |
+
"svelte": "^4.2.12",
|
16 |
+
"svelte-check": "^3.6.9",
|
17 |
+
"tslib": "^2.6.2",
|
18 |
+
"typescript": "^5.4.4",
|
19 |
+
"vite": "^5.2.8"
|
20 |
+
},
|
21 |
+
"dependencies": {
|
22 |
+
"@xyflow/svelte": "^0.0.40"
|
23 |
}
|
24 |
}
|
web/src/App.svelte
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<script lang="ts">
|
2 |
+
import { writable } from 'svelte/store';
|
3 |
+
import {
|
4 |
+
SvelteFlow,
|
5 |
+
Controls,
|
6 |
+
Background,
|
7 |
+
MiniMap,
|
8 |
+
Position,
|
9 |
+
type Node,
|
10 |
+
type Edge,
|
11 |
+
} from '@xyflow/svelte';
|
12 |
+
|
13 |
+
import '@xyflow/svelte/dist/style.css';
|
14 |
+
|
15 |
+
const nodes = writable<Node[]>([
|
16 |
+
{
|
17 |
+
id: '1',
|
18 |
+
data: { label: 'Hello' },
|
19 |
+
position: { x: 0, y: 0 },
|
20 |
+
sourcePosition: Position.Left,
|
21 |
+
targetPosition: Position.Right,
|
22 |
+
},
|
23 |
+
{
|
24 |
+
id: '2',
|
25 |
+
data: { label: 'World' },
|
26 |
+
position: { x: 150, y: 150 },
|
27 |
+
},
|
28 |
+
]);
|
29 |
+
|
30 |
+
const edges = writable<Edge[]>([
|
31 |
+
{
|
32 |
+
id: '1-2',
|
33 |
+
source: '1',
|
34 |
+
target: '2',
|
35 |
+
},
|
36 |
+
]);
|
37 |
+
</script>
|
38 |
+
|
39 |
+
<div style:height="100vh">
|
40 |
+
<SvelteFlow {nodes} {edges} fitView>
|
41 |
+
<Background variant="dots" gap="6" size="1" />
|
42 |
+
<Controls />
|
43 |
+
<Background />
|
44 |
+
<MiniMap />
|
45 |
+
</SvelteFlow>
|
46 |
+
</div>
|
web/src/App.vue
DELETED
@@ -1,117 +0,0 @@
|
|
1 |
-
// Baklava feature requests:
|
2 |
-
// - Node search (https://github.com/newcat/baklavajs/issues/315)
|
3 |
-
// - Check out sidebar
|
4 |
-
// - Collapse node
|
5 |
-
// - Customize toolbar
|
6 |
-
// - Nicer styling for node palette, node categories
|
7 |
-
// - Group nodes, like in Litegraph.
|
8 |
-
// - Show param name for TextInputInterface.
|
9 |
-
// - Resizable nodes. (Horizontally.)
|
10 |
-
// - Put input and output on same line?
|
11 |
-
|
12 |
-
<template>
|
13 |
-
<div style="width: 100vw; height: 100vh">
|
14 |
-
<BaklavaEditor :view-model="baklava" />
|
15 |
-
</div>
|
16 |
-
</template>
|
17 |
-
|
18 |
-
<script setup lang="ts">
|
19 |
-
import { BaklavaEditor, useBaklava } from "@baklavajs/renderer-vue";
|
20 |
-
import { BaklavaInterfaceTypes, NodeInterfaceType, setType } from "@baklavajs/interface-types";
|
21 |
-
import * as BaklavaJS from "baklavajs";
|
22 |
-
import "@baklavajs/themes/dist/syrup-dark.css";
|
23 |
-
import { markRaw } from "vue";
|
24 |
-
import { NodeInterface } from "baklavajs";
|
25 |
-
import GraphViz from "./components/GraphViz.vue";
|
26 |
-
|
27 |
-
const graphType = new NodeInterfaceType<string>("graph");
|
28 |
-
const tableType = new NodeInterfaceType<string>("table");
|
29 |
-
|
30 |
-
const ops = [
|
31 |
-
{ name: 'Create scale-free graph', type: 'Creation', inputs: [], outputs: ['graph'], params: ['Number of nodes'] },
|
32 |
-
{ name: 'Compute PageRank', type: 'Algorithms', inputs: ['graph'], outputs: ['graph'], params: ['Damping factor', 'Max iterations'] },
|
33 |
-
{ name: 'SQL', type: 'Algorithms', inputs: ['graph'], outputs: ['table'], params: ['Query'] },
|
34 |
-
{ name: 'Visualize graph', type: 'Visualization', inputs: ['graph'], outputs: ['graph-viz'],
|
35 |
-
params: ['Color by', 'Size by'],
|
36 |
-
calculate(inputs) {
|
37 |
-
console.log('Visualize graph', inputs);
|
38 |
-
return {
|
39 |
-
'graph-viz': 15,
|
40 |
-
};
|
41 |
-
}
|
42 |
-
},
|
43 |
-
{ name: 'Num', type: 'Visualization', inputs: [], outputs: ['num'], params: [] },
|
44 |
-
];
|
45 |
-
|
46 |
-
function makeParam(param: string): NodeInterface {
|
47 |
-
return new BaklavaJS.TextInputInterface(param, "").setPort(false);
|
48 |
-
}
|
49 |
-
|
50 |
-
function makeOutput(output: string): NodeInterface {
|
51 |
-
if (output === 'graph-viz') {
|
52 |
-
return new NodeInterface(output, "asd").setComponent(markRaw(GraphViz)).setPort(false);
|
53 |
-
} else if (output === 'graph') {
|
54 |
-
return new BaklavaJS.NodeInterface(output, 0).use(setType, graphType);
|
55 |
-
} else if (output === 'table') {
|
56 |
-
return new BaklavaJS.NodeInterface(output, 0).use(setType, tableType);
|
57 |
-
} else {
|
58 |
-
return new BaklavaJS.NodeInterface(output, 0);
|
59 |
-
}
|
60 |
-
}
|
61 |
-
function makeInput(input: string): NodeInterface {
|
62 |
-
if (input === 'graph') {
|
63 |
-
return new BaklavaJS.NodeInterface(input, 0).use(setType, graphType);
|
64 |
-
} else if (input === 'table') {
|
65 |
-
return new BaklavaJS.NodeInterface(input, 0).use(setType, tableType);
|
66 |
-
} else {
|
67 |
-
return new BaklavaJS.NodeInterface(input, 0);
|
68 |
-
}
|
69 |
-
}
|
70 |
-
|
71 |
-
const baklava = useBaklava();
|
72 |
-
const nodeInterfaceTypes = new BaklavaInterfaceTypes(baklava.editor, { viewPlugin: baklava });
|
73 |
-
nodeInterfaceTypes.addTypes(graphType, tableType);
|
74 |
-
|
75 |
-
for (const op of ops) {
|
76 |
-
baklava.editor.registerNodeType(BaklavaJS.defineNode({
|
77 |
-
type: op.name,
|
78 |
-
inputs: {
|
79 |
-
...op.inputs.reduce((acc, input) => ({ ...acc, [input]: () => makeInput(input) }), {}),
|
80 |
-
...op.params.reduce((acc, param) => ({ ...acc, [param]: () => makeParam(param) }), {}),
|
81 |
-
},
|
82 |
-
outputs: op.outputs.reduce((acc, output) => ({ ...acc, [output]: () => makeOutput(output) }), {}),
|
83 |
-
calculate: op.calculate,
|
84 |
-
}), { category: op.type });
|
85 |
-
}
|
86 |
-
|
87 |
-
import { DependencyEngine } from "@baklavajs/engine";
|
88 |
-
// Needed?
|
89 |
-
const engine = new DependencyEngine(baklava.editor);
|
90 |
-
engine.start();
|
91 |
-
|
92 |
-
import { applyResult } from "@baklavajs/engine";
|
93 |
-
// Needed?
|
94 |
-
const token = Symbol();
|
95 |
-
engine.events.afterRun.subscribe(token, (result) => {
|
96 |
-
engine.pause();
|
97 |
-
applyResult(result, baklava.editor);
|
98 |
-
engine.resume();
|
99 |
-
});
|
100 |
-
let lastSave;
|
101 |
-
baklava.editor.nodeEvents.update.subscribe(token, async (result) => {
|
102 |
-
const s = JSON.stringify(baklava.editor.save());
|
103 |
-
if (s !== lastSave) {
|
104 |
-
lastSave = s;
|
105 |
-
console.log('save', JSON.parse(s));
|
106 |
-
const res = await fetch('/api/save', {
|
107 |
-
method: 'POST',
|
108 |
-
headers: {
|
109 |
-
'Content-Type': 'application/json',
|
110 |
-
},
|
111 |
-
body: s,
|
112 |
-
});
|
113 |
-
const j = await res.json();
|
114 |
-
console.log('save response', j);
|
115 |
-
}
|
116 |
-
});
|
117 |
-
</script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
web/src/app.css
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
:root {
|
2 |
+
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
|
3 |
+
line-height: 1.5;
|
4 |
+
font-weight: 400;
|
5 |
+
}
|
web/src/assets/favicon.ico
ADDED
|
web/src/assets/vue.svg
DELETED
web/src/components/GraphViz.vue
DELETED
@@ -1,19 +0,0 @@
|
|
1 |
-
<template>
|
2 |
-
<div ref="container" class="graph-viz"></div>
|
3 |
-
</template>
|
4 |
-
|
5 |
-
<script setup>
|
6 |
-
import { ref, onMounted } from 'vue';
|
7 |
-
import Sigma from 'sigma';
|
8 |
-
import * as graphology from 'graphology';
|
9 |
-
const container = ref(null);
|
10 |
-
onMounted(() => {
|
11 |
-
const sigmaInstance = new Sigma(graph, container.value);
|
12 |
-
console.log(props.modelValue);
|
13 |
-
});
|
14 |
-
const props = defineProps(['modelValue']);
|
15 |
-
const graph = new graphology.Graph();
|
16 |
-
graph.addNode("1", { label: "Node 1", x: 0, y: 0, size: 10, color: "blue" });
|
17 |
-
graph.addNode("2", { label: "Node 2", x: 1, y: 1, size: 20, color: "red" });
|
18 |
-
graph.addEdge("1", "2", { size: 5, color: "purple" });
|
19 |
-
</script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
web/src/main.ts
CHANGED
@@ -1,4 +1,9 @@
|
|
1 |
-
import
|
2 |
-
|
3 |
-
import
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import App from './App.svelte';
|
2 |
+
|
3 |
+
import './app.css';
|
4 |
+
|
5 |
+
const app = new App({
|
6 |
+
target: document.getElementById('app')!,
|
7 |
+
});
|
8 |
+
|
9 |
+
export default app;
|
web/src/style.css
DELETED
@@ -1,14 +0,0 @@
|
|
1 |
-
body {
|
2 |
-
margin: 0;
|
3 |
-
}
|
4 |
-
|
5 |
-
.graph-viz {
|
6 |
-
width: 100%;
|
7 |
-
height: 100px;
|
8 |
-
background: white;
|
9 |
-
text-align: left;
|
10 |
-
}
|
11 |
-
|
12 |
-
.baklava-node-interface[data-interface-type="graph"] .__port {
|
13 |
-
background-color: #39bcf3;
|
14 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
web/src/vite-env.d.ts
CHANGED
@@ -1 +1,2 @@
|
|
|
|
1 |
/// <reference types="vite/client" />
|
|
|
1 |
+
/// <reference types="svelte" />
|
2 |
/// <reference types="vite/client" />
|
web/svelte.config.js
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'
|
2 |
+
|
3 |
+
export default {
|
4 |
+
// Consult https://svelte.dev/docs#compile-time-svelte-preprocess
|
5 |
+
// for more information about preprocessors
|
6 |
+
preprocess: vitePreprocess(),
|
7 |
+
}
|
web/tsconfig.json
CHANGED
@@ -1,25 +1,20 @@
|
|
1 |
{
|
|
|
2 |
"compilerOptions": {
|
3 |
-
"target": "
|
4 |
"useDefineForClassFields": true,
|
5 |
"module": "ESNext",
|
6 |
-
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
7 |
-
"skipLibCheck": true,
|
8 |
-
|
9 |
-
/* Bundler mode */
|
10 |
-
"moduleResolution": "bundler",
|
11 |
-
"allowImportingTsExtensions": true,
|
12 |
"resolveJsonModule": true,
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
"
|
20 |
-
"
|
21 |
-
"
|
22 |
},
|
23 |
-
"include": ["src/**/*.ts", "src/**/*.
|
24 |
"references": [{ "path": "./tsconfig.node.json" }]
|
25 |
}
|
|
|
1 |
{
|
2 |
+
"extends": "@tsconfig/svelte/tsconfig.json",
|
3 |
"compilerOptions": {
|
4 |
+
"target": "ESNext",
|
5 |
"useDefineForClassFields": true,
|
6 |
"module": "ESNext",
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
"resolveJsonModule": true,
|
8 |
+
/**
|
9 |
+
* Typecheck JS in `.svelte` and `.js` files by default.
|
10 |
+
* Disable checkJs if you'd like to use dynamic types in JS.
|
11 |
+
* Note that setting allowJs false does not prevent the use
|
12 |
+
* of JS in `.svelte` files.
|
13 |
+
*/
|
14 |
+
"allowJs": true,
|
15 |
+
"checkJs": true,
|
16 |
+
"isolatedModules": true
|
17 |
},
|
18 |
+
"include": ["src/**/*.d.ts", "src/**/*.ts", "src/**/*.js", "src/**/*.svelte"],
|
19 |
"references": [{ "path": "./tsconfig.node.json" }]
|
20 |
}
|
web/tsconfig.node.json
CHANGED
@@ -3,9 +3,7 @@
|
|
3 |
"composite": true,
|
4 |
"skipLibCheck": true,
|
5 |
"module": "ESNext",
|
6 |
-
"moduleResolution": "bundler"
|
7 |
-
"allowSyntheticDefaultImports": true,
|
8 |
-
"strict": true
|
9 |
},
|
10 |
"include": ["vite.config.ts"]
|
11 |
}
|
|
|
3 |
"composite": true,
|
4 |
"skipLibCheck": true,
|
5 |
"module": "ESNext",
|
6 |
+
"moduleResolution": "bundler"
|
|
|
|
|
7 |
},
|
8 |
"include": ["vite.config.ts"]
|
9 |
}
|
web/vite.config.ts
CHANGED
@@ -1,10 +1,7 @@
|
|
1 |
import { defineConfig } from 'vite'
|
2 |
-
import
|
3 |
|
4 |
// https://vitejs.dev/config/
|
5 |
export default defineConfig({
|
6 |
-
plugins: [
|
7 |
-
server: {
|
8 |
-
proxy: { '/api': 'http://127.0.0.1:8000' },
|
9 |
-
},
|
10 |
})
|
|
|
1 |
import { defineConfig } from 'vite'
|
2 |
+
import { svelte } from '@sveltejs/vite-plugin-svelte'
|
3 |
|
4 |
// https://vitejs.dev/config/
|
5 |
export default defineConfig({
|
6 |
+
plugins: [svelte()],
|
|
|
|
|
|
|
7 |
})
|