simplify edgereconnectanchor

This commit is contained in:
peterkogo
2025-04-11 16:05:20 +02:00
parent 3e20c2a0ee
commit eec8d91f95
2 changed files with 9 additions and 38 deletions
@@ -75,18 +75,8 @@
{/if} {/if}
{#if selected} {#if selected}
<EdgeReconnectAnchor <EdgeReconnectAnchor bind:reconnecting type="source" position={{ x: sourceX, y: sourceY }} />
bind:reconnecting <EdgeReconnectAnchor bind:reconnecting type="target" position={{ x: targetX, y: targetY }} />
type="source"
position={{ x: sourceX, y: sourceY }}
asDomNode
/>
<EdgeReconnectAnchor
bind:reconnecting
type="target"
position={{ x: targetX, y: targetY }}
asDomNode
/>
{/if} {/if}
<style> <style>
@@ -13,15 +13,13 @@
class: className, class: className,
size = 25, size = 25,
style, style,
children, children
asDomNode = false
}: { }: {
type: HandleType; type: HandleType;
reconnecting?: boolean; reconnecting?: boolean;
style?: string; style?: string;
class?: ClassValue; class?: ClassValue;
position?: XYPosition; position?: XYPosition;
asDomNode?: boolean;
size?: number; size?: number;
children?: Snippet; children?: Snippet;
} = $props(); } = $props();
@@ -110,36 +108,19 @@
getFromHandle: () => store.connection.fromHandle getFromHandle: () => store.connection.fromHandle
}); });
}; };
let offset = $derived(asDomNode ? '-50%' : `-${size * 0.5}px`);
</script> </script>
<svelte:element <div
this={asDomNode ? 'div' : 'g'} use:portal={'edgelabel'}
use:portal={asDomNode ? 'edgelabel' : undefined}
xmlns={asDomNode ? undefined : 'http://www.w3.org/2000/svg'}
class={['svelte-flow__edgeupdater nopan', `svelte-flow__edgeupdater-${type}`, className]} class={['svelte-flow__edgeupdater nopan', `svelte-flow__edgeupdater-${type}`, className]}
style:position="absolute" style:position="absolute"
style:width={`${size}px`} style:width={`${size}px`}
style:height={`${size}px`} style:height={`${size}px`}
style:transform={position style:transform={`translate(-50%, -50%) ${position ? `translate(${position.x}px, ${position.y}px` : ''}`}
? `translate(calc(${offset} + ${position.x}px), calc(${offset} + ${position.y}px))`
: `translate(${offset}, ${offset})`}
{style} {style}
onpointerdown={onPointerDown} onpointerdown={onPointerDown}
> >
{#if !reconnecting} {#if !reconnecting && children}
{#if children} {@render children()}
{@render children()}
{:else if !asDomNode}
<rect
width={size}
height={size}
x={0}
fill="transparent"
stroke="transparent"
pointer-events="all"
/>
{/if}
{/if} {/if}
</svelte:element> </div>