feat(svelte) added connectionLineComponent

This commit is contained in:
Peter
2023-09-26 15:45:06 +02:00
parent c251b9ee29
commit bba97aa01a
6 changed files with 90 additions and 5 deletions
@@ -13,7 +13,8 @@
'subflows',
'usesvelteflow',
'useupdatenodeinternals',
'validation'
'validation',
'custom-connection-line'
];
const onChange = (event: Event) => {
@@ -0,0 +1,35 @@
<script lang="ts">
import { SvelteFlow } from '@xyflow/svelte';
import { Background, BackgroundVariant, type Edge, type Node } from '@xyflow/svelte';
import { writable } from 'svelte/store';
import CustomNode from './CustomNode.svelte';
import ConnectionLine from './ConnectionLine.svelte';
import '@xyflow/svelte/dist/style.css';
const nodeTypes = {
custom: CustomNode
};
const nodes = writable<Node[]>([
{
id: 'connectionline-1',
type: 'custom',
data: { label: 'Node 1' },
position: { x: 250, y: 5 }
}
]);
const edges = writable<Edge[]>([]);
</script>
<div style="height:100vh;">
<SvelteFlow {nodeTypes} {nodes} {edges} fitView>
<ConnectionLine slot="connectionLineComponent" />
<Background variant={BackgroundVariant.Lines} />
</SvelteFlow>
</div>
<style>
</style>
@@ -0,0 +1,11 @@
<script lang="ts">
import { useStore } from '@xyflow/svelte';
const { connectionPath, connection } = useStore();
</script>
{#if $connectionPath}
<g class={$connection.connectionStatus}>
<path d={$connectionPath} fill="none" stroke="red" />
</g>
{/if}
@@ -0,0 +1,34 @@
<script lang="ts">
import { Handle, Position, type NodeProps } from '@xyflow/svelte';
type $$Props = NodeProps;
export let isConnectable: $$Props['isConnectable'];
const DEFAULT_HANDLE_STYLE = 'width: 10px; height: 10px; bottom: -5px;';
</script>
<div style="background: #DDD; padding: 25px">
<div>Node</div>
<Handle
type="source"
id="red"
position={Position.Bottom}
style={DEFAULT_HANDLE_STYLE + 'left: 15%; background: red;'}
{isConnectable}
/>
<Handle
type="source"
position={Position.Bottom}
id="blue"
style={DEFAULT_HANDLE_STYLE + 'left: 50%; background: blue;'}
{isConnectable}
/>
<Handle
type="source"
position={Position.Bottom}
id="orange"
style={DEFAULT_HANDLE_STYLE + 'left: 85%; background: orange;'}
{isConnectable}
/>
</div>