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