feat(svelte) added connectionLineComponent
This commit is contained in:
@@ -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>
|
||||
@@ -8,8 +8,10 @@
|
||||
|
||||
{#if $connectionPath}
|
||||
<svg width={$width} height={$height} class="svelte-flow__connectionline">
|
||||
<g class={cc(['svelte-flow__connection', $connection.connectionStatus])}>
|
||||
<path d={$connectionPath} fill="none" class="svelte-flow__connection-path" />
|
||||
</g>
|
||||
<slot name="connectionLineComponent">
|
||||
<g class={cc(['svelte-flow__connection', $connection.connectionStatus])}>
|
||||
<path d={$connectionPath} fill="none" class="svelte-flow__connection-path" />
|
||||
</g>
|
||||
</slot>
|
||||
</svg>
|
||||
{/if}
|
||||
|
||||
@@ -154,7 +154,9 @@
|
||||
<Pane on:paneclick panOnDrag={panOnDrag === undefined ? true : panOnDrag}>
|
||||
<ViewportComponent>
|
||||
<EdgeRenderer on:edgeclick on:edgecontextmenu />
|
||||
<ConnectionLine />
|
||||
<ConnectionLine>
|
||||
<slot name="connectionLineComponent" slot="connectionLineComponent" />
|
||||
</ConnectionLine>
|
||||
<div class="svelte-flow__edgelabel-renderer" />
|
||||
<NodeRenderer
|
||||
on:nodeclick
|
||||
|
||||
Reference in New Issue
Block a user