11<script lang="ts" setup>
22import 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'
44import { select } from ' d3-selection'
55import { drag } from ' d3-drag'
6- import { computed , inject , ref , watchEffect } from ' vue'
6+ import { computed , ref , watchEffect } from ' vue'
77import type { OnResize , OnResizeStart , ResizeControlProps , ResizeDragEvent } from ' ./types'
88import { ResizeControlVariant } from ' ./types'
99import { getDirection } from ' ./utils'
@@ -36,22 +36,18 @@ const { findNode, emits: triggerEmits } = useVueFlow()
3636
3737const getPointerPosition = useGetPointerPosition ()
3838
39- const contextNodeId = inject (NodeIdInjection , null )
40-
4139const resizeControlRef = ref <HTMLDivElement >()
4240
4341let startValues: typeof initStartValues = initStartValues
4442
4543let prevValues: typeof initPrevValues = initPrevValues
4644
47- const id = computed (() => (typeof props .nodeId === ' string' ? props .nodeId : contextNodeId ))
48-
4945const defaultPosition = computed (() => (props .variant === ResizeControlVariant .Line ? ' right' : ' bottom-right' ))
5046
5147const controlPosition = computed (() => props .position ?? defaultPosition .value )
5248
5349watchEffect ((onCleanup ) => {
54- if (! resizeControlRef .value || ! id . value ) {
50+ if (! resizeControlRef .value || ! props . nodeId ) {
5551 return
5652 }
5753
@@ -64,7 +60,7 @@ watchEffect((onCleanup) => {
6460
6561 const dragHandler = drag <HTMLDivElement , unknown >()
6662 .on (' start' , (event : ResizeDragEvent ) => {
67- const node = findNode (id . value ! )
63+ const node = findNode (props . nodeId )
6864 const { xSnapped, ySnapped } = getPointerPosition (event )
6965
7066 prevValues = {
@@ -85,7 +81,7 @@ watchEffect((onCleanup) => {
8581 })
8682 .on (' drag' , (event : ResizeDragEvent ) => {
8783 const { xSnapped, ySnapped } = getPointerPosition (event )
88- const node = findNode (id . value ! )
84+ const node = findNode (props . nodeId )
8985
9086 if (node ) {
9187 const changes: NodeChange [] = []
@@ -168,9 +164,9 @@ watchEffect((onCleanup) => {
168164 }
169165 }
170166
171- if (isWidthChange || isHeightChange ) {
167+ if (props . nodeId && ( isWidthChange || isHeightChange ) ) {
172168 const dimensionChange: NodeDimensionChange = {
173- id: id . value ! ,
169+ id: props . nodeId ,
174170 type: ' dimensions' ,
175171 updateStyle: true ,
176172 resizing: true ,
@@ -213,15 +209,17 @@ watchEffect((onCleanup) => {
213209 }
214210 })
215211 .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+ }
221218
222- emits (' resizeEnd' , { event , params: prevValues })
219+ emits (' resizeEnd' , { event , params: prevValues })
223220
224- triggerEmits .nodesChange ([dimensionChange ])
221+ triggerEmits .nodesChange ([dimensionChange ])
222+ }
225223 })
226224
227225 selection .call (dragHandler )
0 commit comments