optimized selection via selectionbox, implemented proper defaultEdge/-NodeOptions

This commit is contained in:
peterkogo
2024-12-19 17:33:16 +01:00
parent 19e233af2d
commit 6349290722
10 changed files with 78 additions and 60 deletions
@@ -27,8 +27,8 @@
targetY,
sourcePosition,
targetPosition,
animated,
selected,
animated = false,
selected = false,
label,
labelStyle,
data = {},
@@ -40,12 +40,12 @@
markerStart,
markerEnd,
selectable: edgeSelectable,
deletable,
deletable = true,
hidden,
zIndex,
class: className,
ariaLabel
} = $derived(edge);
} = $derived(store.defaultEdgeOptions ? { ...store.defaultEdgeOptions, ...edge } : edge);
const { id } = edge;
setContext('svelteflow__edge_id', id);
@@ -64,7 +64,7 @@
const edge = store.edgeLookup.get(id);
if (edge) {
store.handleEdgeSelection(id);
if (selectable) store.handleEdgeSelection(id);
onedgeclick?.({ event, edge });
}
}
@@ -79,6 +79,8 @@
callback({ event, edge });
}
}
$inspect(selected);
</script>
<!-- svelte-ignore a11y_click_events_have_key_events -->
@@ -132,7 +134,7 @@
{style}
{interactionWidth}
{selectable}
deletable={deletable ?? true}
{deletable}
{type}
sourceHandleId={sourceHandle}
targetHandleId={targetHandle}
@@ -40,7 +40,6 @@
);
let store = useStore();
// let { edges } = store;
function onPointerDown(event: MouseEvent | TouchEvent) {
const isMouseTriggered = isMouseEvent(event);
@@ -91,7 +90,6 @@
$effect.pre(() => {
// connectionLookup is not reactive, so we use edges to get notified about updates
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
// $edges;
store.edges;
if (onconnect || ondisconnect) {
let connections = store.connectionLookup.get(`${nodeId}-${type}-${handleId}`);
@@ -50,7 +50,7 @@
z: zIndex = 0,
positionAbsolute: { x: positionX, y: positionY }
}
} = $derived(node);
} = $derived(store.defaultNodeOptions ? { ...store.defaultNodeOptions, ...node } : node);
let { id } = node;
@@ -169,7 +169,7 @@
use:drag={{
nodeId: id,
isSelectable: selectable,
disabled: false,
disabled: !draggable,
handleSelector: dragHandle,
noDragClass: 'nodrag',
nodeClickDistance,
@@ -1,14 +0,0 @@
<script lang="ts">
import { useStore } from '$lib/store';
import { Selection } from '$lib/components/Selection';
const store = useStore();
</script>
<Selection
isVisible={!!(store.selectionRect && store.selectionRectMode === 'user')}
width={store.selectionRect?.width}
height={store.selectionRect?.height}
x={store.selectionRect?.x}
y={store.selectionRect?.y}
/>
@@ -1 +0,0 @@
export { default as UserSelection } from './UserSelection.svelte';