Skip to content

Commit d732597

Browse files
committed
chore(docs): update intersection example
1 parent 11f92f4 commit d732597

File tree

4 files changed

+16
-19
lines changed

4 files changed

+16
-19
lines changed

docs/examples/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { InteractionApp, InteractionCSS, InteractionControls } from './interacti
1414
import { MultiApp, MultiCSS, MultiFlow } from './multi'
1515
import { TeleportApp, TeleportCSS, TeleportSidebar, TeleportableNode, TeleportableUseTransition } from './teleport'
1616
import { TransitionApp, TransitionCSS, TransitionEdge } from './transition'
17-
import { IntersectionApp, IntersectionCSS, IntersectionElements } from './intersection'
17+
import { IntersectionApp, IntersectionCSS } from './intersection'
1818
import { SnapToHandleApp, SnappableConnectionLine } from './connection-radius'
1919
import { NodeResizerApp, ResizableNode } from './node-resizer'
2020
import { ToolbarApp, ToolbarNode } from './node-toolbar'
@@ -109,7 +109,6 @@ export const exampleImports = {
109109
},
110110
intersection: {
111111
'App.vue': IntersectionApp,
112-
'initial-elements.js': IntersectionElements,
113112
'style.css': IntersectionCSS,
114113
},
115114
snappable: {

docs/examples/intersection/App.vue

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
11
<script setup>
2-
import { VueFlow, useVueFlow } from '@vue-flow/core'
32
import { ref } from 'vue'
4-
import { initialElements } from './initial-elements.js'
3+
import { VueFlow, useVueFlow } from '@vue-flow/core'
54
65
/**
76
* You can either use `getIntersectingNodes` to check if a given node intersects with others
87
* or `isNodeIntersecting` to check if a node is intersecting with a given area
98
*/
109
// eslint-disable-next-line @typescript-eslint/no-unused-vars
11-
const { onNodeDrag, getIntersectingNodes, isNodeIntersecting, getNodes } = useVueFlow()
10+
const { onNodeDrag, getIntersectingNodes, isNodeIntersecting, getNodes, updateNode } = useVueFlow()
1211
13-
const elements = ref(initialElements)
12+
const nodes = ref([
13+
{ id: '1', label: 'Node 1', position: { x: 0, y: 0 } },
14+
{ id: '2', label: 'Node 2', position: { x: 400, y: 400 } },
15+
{ id: '3', label: 'Node 3', position: { x: 400, y: 0 } },
16+
{ id: '4', label: 'Node 4', position: { x: 0, y: 400 } },
17+
{ id: '5', style: { borderColor: 'red' }, label: 'Drag me over another node', position: { x: 200, y: 200 } },
18+
])
1419
1520
onNodeDrag(({ intersections }) => {
1621
const intersectionIds = intersections.map((intersection) => intersection.id)
1722
18-
getNodes.value.forEach((n) => {
19-
const isIntersecting = intersectionIds.includes(n.id)
20-
n.class = isIntersecting ? 'intersecting' : ''
21-
})
23+
for (const node of getNodes.value) {
24+
const isIntersecting = intersectionIds.includes(node.id)
25+
26+
updateNode(node.id, { class: isIntersecting ? 'intersecting' : '' })
27+
}
2228
})
2329
</script>
2430

2531
<template>
26-
<VueFlow v-model="elements" fit-view-on-init :default-viewport="{ zoom: 1.5 }" :min-zoom="0.2" :max-zoom="4" />
32+
<VueFlow :nodes="nodes" fit-view-on-init />
2733
</template>

docs/examples/intersection/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
export { default as IntersectionApp } from './App.vue?raw'
2-
export { default as IntersectionElements } from './initial-elements.js?raw'
32
export { default as IntersectionCSS } from './style.css?inline'

docs/examples/intersection/initial-elements.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)