make custom connection line component a normal prop instead of a snippet
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import cc from 'classcat';
|
import cc from 'classcat';
|
||||||
import type { Snippet } from 'svelte';
|
import type { Component } from 'svelte';
|
||||||
import {
|
import {
|
||||||
ConnectionLineType,
|
ConnectionLineType,
|
||||||
getBezierPath,
|
getBezierPath,
|
||||||
@@ -13,14 +13,16 @@
|
|||||||
|
|
||||||
let {
|
let {
|
||||||
store,
|
store,
|
||||||
|
type,
|
||||||
containerStyle = '',
|
containerStyle = '',
|
||||||
style = '',
|
style = '',
|
||||||
connectionLine
|
LineComponent
|
||||||
}: {
|
}: {
|
||||||
store: SvelteFlowStore;
|
store: SvelteFlowStore;
|
||||||
|
type: ConnectionLineType;
|
||||||
containerStyle: string;
|
containerStyle: string;
|
||||||
style: string;
|
style: string;
|
||||||
connectionLine?: Snippet;
|
LineComponent?: Component;
|
||||||
} = $props();
|
} = $props();
|
||||||
|
|
||||||
let path = $derived.by(() => {
|
let path = $derived.by(() => {
|
||||||
@@ -37,7 +39,7 @@
|
|||||||
targetPosition: store.connection.toPosition
|
targetPosition: store.connection.toPosition
|
||||||
};
|
};
|
||||||
|
|
||||||
switch (store.connectionLineType) {
|
switch (type) {
|
||||||
case ConnectionLineType.Bezier: {
|
case ConnectionLineType.Bezier: {
|
||||||
const [path] = getBezierPath(pathParams);
|
const [path] = getBezierPath(pathParams);
|
||||||
return path;
|
return path;
|
||||||
@@ -50,7 +52,7 @@
|
|||||||
case ConnectionLineType.SmoothStep: {
|
case ConnectionLineType.SmoothStep: {
|
||||||
const [path] = getSmoothStepPath({
|
const [path] = getSmoothStepPath({
|
||||||
...pathParams,
|
...pathParams,
|
||||||
borderRadius: store.connectionLineType === ConnectionLineType.Step ? 0 : undefined
|
borderRadius: type === ConnectionLineType.Step ? 0 : undefined
|
||||||
});
|
});
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
@@ -66,8 +68,8 @@
|
|||||||
style={containerStyle}
|
style={containerStyle}
|
||||||
>
|
>
|
||||||
<g class={cc(['svelte-flow__connection', getConnectionStatus(store.connection.isValid)])}>
|
<g class={cc(['svelte-flow__connection', getConnectionStatus(store.connection.isValid)])}>
|
||||||
{#if connectionLine}
|
{#if LineComponent}
|
||||||
{@render connectionLine()}
|
<LineComponent></LineComponent>
|
||||||
{:else}
|
{:else}
|
||||||
<path d={path} {style} fill="none" class="svelte-flow__connection-path" />
|
<path d={path} {style} fill="none" class="svelte-flow__connection-path" />
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { getContext, setContext, onDestroy } from 'svelte';
|
import { getContext, setContext, onDestroy } from 'svelte';
|
||||||
import cc from 'classcat';
|
import cc from 'classcat';
|
||||||
import { PanOnScrollMode } from '@xyflow/system';
|
import { ConnectionLineType, PanOnScrollMode } from '@xyflow/system';
|
||||||
|
|
||||||
import { key, createStore } from '$lib/store';
|
import { key, createStore } from '$lib/store';
|
||||||
import { Zoom } from '$lib/container/Zoom';
|
import { Zoom } from '$lib/container/Zoom';
|
||||||
@@ -33,7 +33,6 @@
|
|||||||
onMoveStart,
|
onMoveStart,
|
||||||
onMoveEnd,
|
onMoveEnd,
|
||||||
onMove,
|
onMove,
|
||||||
connectionLine,
|
|
||||||
onnodeclick,
|
onnodeclick,
|
||||||
onnodecontextmenu,
|
onnodecontextmenu,
|
||||||
onnodedrag,
|
onnodedrag,
|
||||||
@@ -58,8 +57,10 @@
|
|||||||
panOnScroll = false,
|
panOnScroll = false,
|
||||||
panOnDrag = true,
|
panOnDrag = true,
|
||||||
selectionOnDrag = true,
|
selectionOnDrag = true,
|
||||||
connectionLineContainerStyle = '',
|
connectionLineComponent,
|
||||||
connectionLineStyle = '',
|
connectionLineStyle = '',
|
||||||
|
connectionLineContainerStyle = '',
|
||||||
|
connectionLineType = ConnectionLineType.Bezier,
|
||||||
attributionPosition,
|
attributionPosition,
|
||||||
children,
|
children,
|
||||||
nodes = $bindable([]),
|
nodes = $bindable([]),
|
||||||
@@ -167,9 +168,10 @@
|
|||||||
/>
|
/>
|
||||||
<ConnectionLine
|
<ConnectionLine
|
||||||
{store}
|
{store}
|
||||||
|
type={connectionLineType}
|
||||||
|
LineComponent={connectionLineComponent}
|
||||||
containerStyle={connectionLineContainerStyle}
|
containerStyle={connectionLineContainerStyle}
|
||||||
style={connectionLineStyle}
|
style={connectionLineStyle}
|
||||||
{connectionLine}
|
|
||||||
/>
|
/>
|
||||||
<div class="svelte-flow__edgelabel-renderer"></div>
|
<div class="svelte-flow__edgelabel-renderer"></div>
|
||||||
<div class="svelte-flow__viewport-portal"></div>
|
<div class="svelte-flow__viewport-portal"></div>
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ import type {
|
|||||||
IsValidConnection
|
IsValidConnection
|
||||||
} from '$lib/types';
|
} from '$lib/types';
|
||||||
|
|
||||||
import type { Snippet } from 'svelte';
|
import type { Component } from 'svelte';
|
||||||
import type { EdgeEvents, NodeEvents, NodeSelectionEvents, PaneEvents } from '$lib/types/events';
|
import type { EdgeEvents, NodeEvents, NodeSelectionEvents, PaneEvents } from '$lib/types/events';
|
||||||
|
|
||||||
export type SvelteFlowProps = NodeEvents &
|
export type SvelteFlowProps = NodeEvents &
|
||||||
@@ -180,7 +180,7 @@ export type SvelteFlowProps = NodeEvents &
|
|||||||
*/
|
*/
|
||||||
connectionMode?: ConnectionMode;
|
connectionMode?: ConnectionMode;
|
||||||
/** Provide a custom snippet to be used insted of the default connection line */
|
/** Provide a custom snippet to be used insted of the default connection line */
|
||||||
connectionLine?: Snippet;
|
connectionLineComponent?: Component;
|
||||||
/** Styles to be applied to the connection line */
|
/** Styles to be applied to the connection line */
|
||||||
connectionLineStyle?: string;
|
connectionLineStyle?: string;
|
||||||
/** Styles to be applied to the container of the connection line */
|
/** Styles to be applied to the container of the connection line */
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import {
|
|||||||
infiniteExtent,
|
infiniteExtent,
|
||||||
SelectionMode,
|
SelectionMode,
|
||||||
ConnectionMode,
|
ConnectionMode,
|
||||||
ConnectionLineType,
|
|
||||||
devWarn,
|
devWarn,
|
||||||
adoptUserNodes,
|
adoptUserNodes,
|
||||||
getViewportForBounds,
|
getViewportForBounds,
|
||||||
@@ -225,9 +224,6 @@ export const getInitialStore = (signals: StoreSignals) => {
|
|||||||
return this._connection;
|
return this._connection;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
connectionLineType: ConnectionLineType = $derived(
|
|
||||||
signals.props.connectionLineType ?? ConnectionLineType.Bezier
|
|
||||||
);
|
|
||||||
connectionMode: ConnectionMode = $derived(
|
connectionMode: ConnectionMode = $derived(
|
||||||
signals.props.connectionMode ?? ConnectionMode.Strict
|
signals.props.connectionMode ?? ConnectionMode.Strict
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user