restrucutred svelte examples

This commit is contained in:
Peter
2023-10-25 13:23:37 +02:00
parent 117b4a4cb6
commit eca85310e1
44 changed files with 104 additions and 6 deletions

View File

@@ -31,7 +31,7 @@
<div class="logo">Svelte Flow</div>
<select on:change={onChange} value={$page.route.id}>
{#each routes as route}
<option value={`/${route}`}>{route}</option>
<option value={`/examples/${route}`}>{route}</option>
{/each}
</select>
</header>

View File

@@ -2,7 +2,7 @@ import { redirect } from '@sveltejs/kit';
/** @type {import('./$types').LayoutServerLoad} */
export function load({ route }) {
if (route.id === '/') {
throw redirect(307, '/overview');
}
if (route.id === '/') {
throw redirect(307, '/examples/overview');
}
}

View File

@@ -1,5 +1,5 @@
<script lang="ts">
import { Header } from '../components/Header';
import { Header } from '$components/Header';
</script>
<div class="app">

View File

@@ -0,0 +1 @@
<div>this redirects to /overview</div>

View File

@@ -0,0 +1,9 @@
<script lang="ts">
import { SvelteFlowProvider } from '@xyflow/svelte';
import Flow from './Flow.svelte';
</script>
<SvelteFlowProvider>
<Flow />
</SvelteFlowProvider>

View File

@@ -0,0 +1,12 @@
<script lang="ts">
import { writable } from 'svelte/store';
import { initialNodes, initialEdges } from './nodesAndEdges';
import { SvelteFlow } from '@xyflow/svelte';
import '@xyflow/svelte/dist/style.css';
const nodes = writable(initialNodes);
const edges = writable(initialEdges);
</script>
<SvelteFlow {nodes} {edges} fitView />

View File

@@ -0,0 +1,73 @@
import type { Edge, Node } from '@xyflow/svelte';
export const initialNodes: Node[] = [
{
id: '1',
data: { label: '1' },
position: { x: 0, y: 0 },
class: 'test-class',
style: 'background-color: red;'
},
{
id: '2',
data: { label: '2' },
position: { x: -100, y: 100 }
},
{
id: '3',
data: { label: '3' },
position: { x: 100, y: 100 }
},
{
id: '4',
data: { label: '4' },
position: { x: 0, y: 200 }
},
{
id: 'notDraggable',
data: { label: 'notDraggable' },
position: { x: 0, y: 300 },
draggable: false
},
{
id: 'notSelectable',
data: { label: 'notSelectable' },
position: { x: 0, y: 400 },
selectable: false
},
{
id: 'notConnectable',
data: { label: 'notConnectable' },
position: { x: 0, y: 500 },
connectable: false
},
{
id: 'notDeletable',
data: { label: 'notDeletable' },
position: { x: 0, y: 600 },
connectable: false
},
{
id: 'hidden',
data: { label: 'hidden' },
position: { x: 0, y: 700 },
hidden: true
}
];
export const initialEdges: Edge[] = [
{
id: '1-2',
type: 'default',
source: '1',
target: '2',
label: 'edge'
},
{
id: '1-3',
type: 'default',
source: '1',
target: '3',
label: 'edge'
}
];

View File

@@ -11,7 +11,10 @@ const config = {
// adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.
// If your environment is not supported or you settled on a specific environment, switch out the adapter.
// See https://kit.svelte.dev/docs/adapters for more information about adapters.
adapter: adapter()
adapter: adapter(),
alias: {
$components: './src/components'
}
}
};