Skip to content

Commit 7abb6f0

Browse files
committed
Add Svelte pane cancellation and merge latest main
2 parents 7813eeb + bb63f4c commit 7abb6f0

20 files changed

Lines changed: 384 additions & 24 deletions

File tree

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
'@xyflow/react': patch
3+
'@xyflow/svelte': patch
34
---
45

5-
Cancel pending click connections when clicking the pane and call `onClickConnectEnd`.
6+
Cancel pending click connections when clicking the pane and call the click-connection end callback.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@xyflow/react': patch
3+
'@xyflow/svelte': patch
4+
---
5+
6+
Respect `nodeOrigin` in `isNodeIntersecting` and `getIntersectingNodes` when you pass a node object instead of `{ id }`
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@xyflow/react": patch
3+
"@xyflow/system": patch
4+
"@xyflow/svelte": patch
5+
---
6+
7+
Disconnect the `ResizeObserver`s when a flow unmounts
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@xyflow/system": patch
3+
---
4+
5+
Fix `getSmoothStepPath` bends that render sharper than `borderRadius` when nodes are close to each other
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { useState } from 'react';
2+
import { useReactFlow } from '@xyflow/react';
3+
4+
export default function IntersectionOriginNode() {
5+
const { getNode, getIntersectingNodes, isNodeIntersecting } = useReactFlow();
6+
const [result, setResult] = useState('');
7+
8+
const checkIntersections = () => {
9+
const root = getNode('root')!;
10+
const area = { x: 55, y: 55, width: 5, height: 5 };
11+
12+
setResult(
13+
JSON.stringify({
14+
rootObject: isNodeIntersecting(root, area),
15+
rootId: isNodeIntersecting({ id: root.id }, area),
16+
explicitTargets: getIntersectingNodes(area, true, [root]).map((node) => node.id),
17+
implicitTargets: getIntersectingNodes(area).map((node) => node.id),
18+
ownOrigin: isNodeIntersecting(getNode('own-origin')!, { x: 295, y: 295, width: 2, height: 2 }),
19+
child: isNodeIntersecting(getNode('child')!, { x: 426, y: 426, width: 5, height: 5 }),
20+
})
21+
);
22+
};
23+
24+
return (
25+
<div>
26+
<button className="nodrag" data-testid="check-intersections" onClick={checkIntersections}>
27+
Check intersections
28+
</button>
29+
<output data-testid="intersection-result">{result}</output>
30+
</div>
31+
);
32+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import IntersectionOriginNode from './components/IntersectionOriginNode';
2+
3+
export default {
4+
flowProps: {
5+
fitView: true,
6+
nodeOrigin: [0.5, 0.5],
7+
nodeTypes: { intersectionOrigin: IntersectionOriginNode },
8+
nodes: [
9+
{ id: 'root', position: { x: 100, y: 100 }, width: 100, height: 100, data: { label: 'root' } },
10+
{
11+
id: 'own-origin',
12+
position: { x: 300, y: 300 },
13+
width: 100,
14+
height: 100,
15+
origin: [0, 0],
16+
data: { label: 'own origin' },
17+
},
18+
{ id: 'parent', position: { x: 500, y: 500 }, width: 200, height: 200, data: { label: 'parent' } },
19+
{
20+
id: 'child',
21+
parentId: 'parent',
22+
position: { x: 50, y: 50 },
23+
width: 50,
24+
height: 50,
25+
data: { label: 'child' },
26+
},
27+
{
28+
id: 'probe',
29+
type: 'intersectionOrigin',
30+
position: { x: 0, y: 700 },
31+
width: 300,
32+
data: {},
33+
},
34+
],
35+
edges: [],
36+
},
37+
} satisfies FlowConfig;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<script lang="ts">
2+
import { useSvelteFlow } from '@xyflow/svelte';
3+
4+
const { getNode, getIntersectingNodes, isNodeIntersecting } = useSvelteFlow();
5+
let result = $state('');
6+
7+
function checkIntersections() {
8+
const root = getNode('root')!;
9+
const area = { x: 55, y: 55, width: 5, height: 5 };
10+
11+
result = JSON.stringify({
12+
rootObject: isNodeIntersecting(root, area),
13+
rootId: isNodeIntersecting({ id: root.id }, area),
14+
explicitTargets: getIntersectingNodes(area, true, [root]).map((node) => node.id),
15+
implicitTargets: getIntersectingNodes(area).map((node) => node.id),
16+
ownOrigin: isNodeIntersecting(getNode('own-origin')!, {
17+
x: 295,
18+
y: 295,
19+
width: 2,
20+
height: 2
21+
}),
22+
child: isNodeIntersecting(getNode('child')!, { x: 426, y: 426, width: 5, height: 5 })
23+
});
24+
}
25+
</script>
26+
27+
<div>
28+
<button class="nodrag" data-testid="check-intersections" onclick={checkIntersections}>
29+
Check intersections
30+
</button>
31+
<output data-testid="intersection-result">{result}</output>
32+
</div>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import IntersectionOriginNode from './components/IntersectionOriginNode.svelte';
2+
3+
export default {
4+
flowProps: {
5+
fitView: true,
6+
nodeOrigin: [0.5, 0.5],
7+
nodeTypes: { intersectionOrigin: IntersectionOriginNode },
8+
nodes: [
9+
{
10+
id: 'root',
11+
position: { x: 100, y: 100 },
12+
width: 100,
13+
height: 100,
14+
data: { label: 'root' }
15+
},
16+
{
17+
id: 'own-origin',
18+
position: { x: 300, y: 300 },
19+
width: 100,
20+
height: 100,
21+
origin: [0, 0],
22+
data: { label: 'own origin' }
23+
},
24+
{
25+
id: 'parent',
26+
position: { x: 500, y: 500 },
27+
width: 200,
28+
height: 200,
29+
data: { label: 'parent' }
30+
},
31+
{
32+
id: 'child',
33+
parentId: 'parent',
34+
position: { x: 50, y: 50 },
35+
width: 50,
36+
height: 50,
37+
data: { label: 'child' }
38+
},
39+
{
40+
id: 'probe',
41+
type: 'intersectionOrigin',
42+
position: { x: 0, y: 700 },
43+
width: 300,
44+
data: {}
45+
}
46+
],
47+
edges: []
48+
}
49+
} satisfies FlowConfig;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import config from './click-connect';
2+
3+
export default {
4+
...config,
5+
flowProps: { ...config.flowProps, selectionOnDrag: true, panOnDrag: [1, 2] }
6+
} satisfies FlowConfig;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export default {
2+
flowProps: {
3+
fitView: true,
4+
nodes: [
5+
{ id: '1', type: 'input', position: { x: 0, y: 0 }, data: { label: 'Source' } },
6+
{ id: '2', position: { x: 0, y: 150 }, data: { label: 'Target' } }
7+
],
8+
edges: [],
9+
onpaneclick: () => console.log('pane-click'),
10+
onclickconnectstart: () => console.log('click-connect-start'),
11+
onclickconnectend: (_event, connection) =>
12+
console.log('click-connect-end', JSON.stringify(connection))
13+
}
14+
} satisfies FlowConfig;

0 commit comments

Comments
 (0)