chore(edge-toolbar): cleanup

This commit is contained in:
moklick
2025-10-21 12:16:54 +02:00
parent dca0a30f27
commit e6b0d12f6f
4 changed files with 11 additions and 12 deletions

View File

@@ -6,5 +6,9 @@ import type { EdgeToolbarBaseProps } from '@xyflow/system';
*/
export type EdgeToolbarProps = EdgeToolbarBaseProps &
HTMLAttributes<HTMLDivElement> & {
/**
* An edge toolbar must be attached to an edge.
*/
edgeId: string;
children?: ReactNode;
};

View File

@@ -1,7 +1,7 @@
<script lang="ts">
import { getContext } from 'svelte';
import { hideOnSSR, portal } from '$lib/actions/portal';
import { hideOnSSR, portal } from '$lib/actions/portal';
import { useStore } from '$lib/store';
import type { EdgeLabelProps } from './types';
import { toPxString } from '$lib/utils';
@@ -19,15 +19,13 @@
}: EdgeLabelProps = $props();
const store = useStore();
const edgeId = getContext<string>('svelteflow__edge_id');
if (!edgeId) {
throw new Error('EdgeLabel must be used within an edge');
}
let z = $derived.by(() => {
return store.visible.edges.get(edgeId)?.zIndex;
});
let z = $derived(store.visible.edges.get(edgeId)?.zIndex);
</script>
<div

View File

@@ -19,14 +19,15 @@
}: EdgeToolbarProps = $props();
const store = useStore();
const edgeId = getContext<string>('svelteflow__edge_id');
if (!edgeId) {
throw new Error('EdgeToolbar must be used within an edge');
}
const edge = $derived(store.edgeLookup.get(edgeId));
const isActive = $derived(typeof isVisible === 'boolean' ? isVisible : edge?.selected);
const isActive = $derived(
typeof isVisible === 'boolean' ? isVisible : store.edgeLookup.get(edgeId)?.selected
);
const transform = $derived(getEdgeToolbarTransform(x, y, store.viewport.zoom, alignX, alignY));
</script>

View File

@@ -131,10 +131,6 @@ export type EdgePosition = {
export type EdgeLookup<EdgeType extends EdgeBase = EdgeBase> = Map<string, EdgeType>;
export type EdgeToolbarBaseProps = {
/**
* An edge toolbar must be attached to an edge.
*/
edgeId: string;
/**
* The `x` position of the edge label.
*/