fix intersections for svelte flow

This commit is contained in:
peterkogo
2024-08-19 14:05:37 +02:00
parent aaf130f6cb
commit e1f6b74389
3 changed files with 34 additions and 14 deletions

View File

@@ -13,12 +13,14 @@
const { getIntersectingNodes } = useSvelteFlow();
function onNodeDrag({ detail: { targetNode } }) {
const intersections = getIntersectingNodes(targetNode).map((n) => n.id);
if (targetNode) {
const intersections = getIntersectingNodes(targetNode).map((n) => n.id);
$nodes.forEach((n) => {
n.class = intersections.includes(n.id) ? 'highlight' : '';
});
$nodes = $nodes;
$nodes.forEach((n) => {
n.class = intersections.includes(n.id) ? 'highlight' : '';
});
$nodes = $nodes;
}
}
</script>

View File

@@ -10,7 +10,8 @@ export const initialNodes: Node[] = [
{
id: '2',
data: { label: 'Node 2' },
position: { x: 0, y: 150 }
position: { x: 0, y: 150 },
parentId: '1'
},
{
id: '3',