@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'@xyflow/svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Remove `edgeId` from `EdgeToolbar` props
|
||||||
@@ -6,5 +6,9 @@ import type { EdgeToolbarBaseProps } from '@xyflow/system';
|
|||||||
*/
|
*/
|
||||||
export type EdgeToolbarProps = EdgeToolbarBaseProps &
|
export type EdgeToolbarProps = EdgeToolbarBaseProps &
|
||||||
HTMLAttributes<HTMLDivElement> & {
|
HTMLAttributes<HTMLDivElement> & {
|
||||||
|
/**
|
||||||
|
* An edge toolbar must be attached to an edge.
|
||||||
|
*/
|
||||||
|
edgeId: string;
|
||||||
children?: ReactNode;
|
children?: ReactNode;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { getContext } from 'svelte';
|
import { getContext } from 'svelte';
|
||||||
import { hideOnSSR, portal } from '$lib/actions/portal';
|
|
||||||
|
|
||||||
|
import { hideOnSSR, portal } from '$lib/actions/portal';
|
||||||
import { useStore } from '$lib/store';
|
import { useStore } from '$lib/store';
|
||||||
import type { EdgeLabelProps } from './types';
|
import type { EdgeLabelProps } from './types';
|
||||||
import { toPxString } from '$lib/utils';
|
import { toPxString } from '$lib/utils';
|
||||||
@@ -19,12 +19,13 @@
|
|||||||
}: EdgeLabelProps = $props();
|
}: EdgeLabelProps = $props();
|
||||||
|
|
||||||
const store = useStore();
|
const store = useStore();
|
||||||
|
const edgeId = getContext<string>('svelteflow__edge_id');
|
||||||
|
|
||||||
const id = getContext<string>('svelteflow__edge_id');
|
if (!edgeId) {
|
||||||
|
throw new Error('EdgeLabel must be used within an edge');
|
||||||
|
}
|
||||||
|
|
||||||
let z = $derived.by(() => {
|
let z = $derived(store.visible.edges.get(edgeId)?.zIndex);
|
||||||
return store.visible.edges.get(id)?.zIndex;
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
@@ -39,7 +40,7 @@
|
|||||||
style:z-index={z}
|
style:z-index={z}
|
||||||
tabindex="-1"
|
tabindex="-1"
|
||||||
onclick={() => {
|
onclick={() => {
|
||||||
if (selectEdgeOnClick && id) store.handleEdgeSelection(id);
|
if (selectEdgeOnClick) store.handleEdgeSelection(edgeId);
|
||||||
}}
|
}}
|
||||||
{...rest}
|
{...rest}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -4,35 +4,42 @@
|
|||||||
import { useStore } from '$lib/store';
|
import { useStore } from '$lib/store';
|
||||||
import { EdgeLabel } from '$lib/components/EdgeLabel';
|
import { EdgeLabel } from '$lib/components/EdgeLabel';
|
||||||
import type { EdgeToolbarProps } from './types';
|
import type { EdgeToolbarProps } from './types';
|
||||||
|
import { getContext } from 'svelte';
|
||||||
|
|
||||||
let {
|
let {
|
||||||
edgeId,
|
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
alignX = 'center',
|
alignX = 'center',
|
||||||
alignY = 'center',
|
alignY = 'center',
|
||||||
isVisible,
|
isVisible,
|
||||||
|
selectEdgeOnClick,
|
||||||
|
class: className,
|
||||||
children,
|
children,
|
||||||
...rest
|
...rest
|
||||||
}: EdgeToolbarProps = $props();
|
}: EdgeToolbarProps = $props();
|
||||||
|
|
||||||
const store = useStore();
|
const store = useStore();
|
||||||
const edge = $derived(store.edgeLookup.get(edgeId));
|
const edgeId = getContext<string>('svelteflow__edge_id');
|
||||||
const isActive = $derived(typeof isVisible === 'boolean' ? isVisible : edge?.selected);
|
|
||||||
|
if (!edgeId) {
|
||||||
|
throw new Error('EdgeToolbar must be used within an edge');
|
||||||
|
}
|
||||||
|
|
||||||
|
const isActive = $derived(
|
||||||
|
typeof isVisible === 'boolean' ? isVisible : store.edgeLookup.get(edgeId)?.selected
|
||||||
|
);
|
||||||
const transform = $derived(getEdgeToolbarTransform(x, y, store.viewport.zoom, alignX, alignY));
|
const transform = $derived(getEdgeToolbarTransform(x, y, store.viewport.zoom, alignX, alignY));
|
||||||
const zIndex = $derived((edge?.zIndex ?? 0) + 1);
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if store.domNode && isActive}
|
{#if isActive}
|
||||||
<EdgeLabel>
|
<EdgeLabel {selectEdgeOnClick} transparent>
|
||||||
<div
|
<div
|
||||||
style:position="absolute"
|
style:position="absolute"
|
||||||
style:transform
|
style:transform
|
||||||
style:z-index={zIndex}
|
|
||||||
style:transform-origin="0 0"
|
style:transform-origin="0 0"
|
||||||
|
class={['svelte-flow__edge-toolbar', className]}
|
||||||
|
data-id={edgeId}
|
||||||
{...rest}
|
{...rest}
|
||||||
class="svelte-flow__edge-toolbar"
|
|
||||||
data-id={edgeId ?? ''}
|
|
||||||
>
|
>
|
||||||
{@render children?.()}
|
{@render children?.()}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import type { EdgeToolbarBaseProps } from '@xyflow/system';
|
|||||||
import type { Snippet } from 'svelte';
|
import type { Snippet } from 'svelte';
|
||||||
import type { HTMLAttributes } from 'svelte/elements';
|
import type { HTMLAttributes } from 'svelte/elements';
|
||||||
|
|
||||||
export type EdgeToolbarProps = EdgeToolbarBaseProps & {
|
export type EdgeToolbarProps = Omit<EdgeToolbarBaseProps, 'edgeId'> & {
|
||||||
|
selectEdgeOnClick?: boolean;
|
||||||
children?: Snippet;
|
children?: Snippet;
|
||||||
} & HTMLAttributes<HTMLDivElement>;
|
} & HTMLAttributes<HTMLDivElement>;
|
||||||
|
|||||||
@@ -131,10 +131,6 @@ export type EdgePosition = {
|
|||||||
export type EdgeLookup<EdgeType extends EdgeBase = EdgeBase> = Map<string, EdgeType>;
|
export type EdgeLookup<EdgeType extends EdgeBase = EdgeBase> = Map<string, EdgeType>;
|
||||||
|
|
||||||
export type EdgeToolbarBaseProps = {
|
export type EdgeToolbarBaseProps = {
|
||||||
/**
|
|
||||||
* An edge toolbar must be attached to an edge.
|
|
||||||
*/
|
|
||||||
edgeId: string;
|
|
||||||
/**
|
/**
|
||||||
* The `x` position of the edge label.
|
* The `x` position of the edge label.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user