1
1
<script lang="ts" setup>
2
2
import type { NodeChange , NodeDimensionChange , NodePositionChange } from ' @vue-flow/core'
3
- import { NodeIdInjection , clamp , useGetPointerPosition , useVueFlow } from ' @vue-flow/core'
3
+ import { clamp , useGetPointerPosition , useVueFlow } from ' @vue-flow/core'
4
4
import { select } from ' d3-selection'
5
5
import { drag } from ' d3-drag'
6
- import { computed , inject , ref , watchEffect } from ' vue'
6
+ import { computed , ref , watchEffect } from ' vue'
7
7
import type { OnResize , OnResizeStart , ResizeControlProps , ResizeDragEvent } from ' ./types'
8
8
import { ResizeControlVariant } from ' ./types'
9
9
import { getDirection } from ' ./utils'
@@ -36,22 +36,18 @@ const { findNode, emits: triggerEmits } = useVueFlow()
36
36
37
37
const getPointerPosition = useGetPointerPosition ()
38
38
39
- const contextNodeId = inject (NodeIdInjection , null )
40
-
41
39
const resizeControlRef = ref <HTMLDivElement >()
42
40
43
41
let startValues: typeof initStartValues = initStartValues
44
42
45
43
let prevValues: typeof initPrevValues = initPrevValues
46
44
47
- const id = computed (() => (typeof props .nodeId === ' string' ? props .nodeId : contextNodeId ))
48
-
49
45
const defaultPosition = computed (() => (props .variant === ResizeControlVariant .Line ? ' right' : ' bottom-right' ))
50
46
51
47
const controlPosition = computed (() => props .position ?? defaultPosition .value )
52
48
53
49
watchEffect ((onCleanup ) => {
54
- if (! resizeControlRef .value || ! id . value ) {
50
+ if (! resizeControlRef .value || ! props . nodeId ) {
55
51
return
56
52
}
57
53
@@ -64,7 +60,7 @@ watchEffect((onCleanup) => {
64
60
65
61
const dragHandler = drag <HTMLDivElement , unknown >()
66
62
.on (' start' , (event : ResizeDragEvent ) => {
67
- const node = findNode (id . value ! )
63
+ const node = findNode (props . nodeId )
68
64
const { xSnapped, ySnapped } = getPointerPosition (event )
69
65
70
66
prevValues = {
@@ -85,7 +81,7 @@ watchEffect((onCleanup) => {
85
81
})
86
82
.on (' drag' , (event : ResizeDragEvent ) => {
87
83
const { xSnapped, ySnapped } = getPointerPosition (event )
88
- const node = findNode (id . value ! )
84
+ const node = findNode (props . nodeId )
89
85
90
86
if (node ) {
91
87
const changes: NodeChange [] = []
@@ -168,9 +164,9 @@ watchEffect((onCleanup) => {
168
164
}
169
165
}
170
166
171
- if (isWidthChange || isHeightChange ) {
167
+ if (props . nodeId && ( isWidthChange || isHeightChange ) ) {
172
168
const dimensionChange: NodeDimensionChange = {
173
- id: id . value ! ,
169
+ id: props . nodeId ,
174
170
type: ' dimensions' ,
175
171
updateStyle: true ,
176
172
resizing: true ,
@@ -213,15 +209,17 @@ watchEffect((onCleanup) => {
213
209
}
214
210
})
215
211
.on (' end' , (event : ResizeDragEvent ) => {
216
- const dimensionChange: NodeDimensionChange = {
217
- id: id .value ! ,
218
- type: ' dimensions' ,
219
- resizing: false ,
220
- }
212
+ if (props .nodeId ) {
213
+ const dimensionChange: NodeDimensionChange = {
214
+ id: props .nodeId ,
215
+ type: ' dimensions' ,
216
+ resizing: false ,
217
+ }
221
218
222
- emits (' resizeEnd' , { event , params: prevValues })
219
+ emits (' resizeEnd' , { event , params: prevValues })
223
220
224
- triggerEmits .nodesChange ([dimensionChange ])
221
+ triggerEmits .nodesChange ([dimensionChange ])
222
+ }
225
223
})
226
224
227
225
selection .call (dragHandler )
0 commit comments