Skip to content

Commit c382d88

Browse files
Congyuwangbcakmakoglu
authored andcommitted
sync node position after resizing
1 parent af699d3 commit c382d88

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

packages/resize-rotate-node/src/node/ResizeRotateNode.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const el = ref()
2525
2626
const visible = ref(false)
2727
28-
const { onRotateStart, onRotate, onResizeStart, onResize } = useMoveable(props.id, emits)
28+
const { onRotateStart, onRotate, onResizeStart, onResize, onResizeEnd } = useMoveable(props.id, emits)
2929
3030
const toggleVisibility = (val?: boolean) => {
3131
visible.value = val ?? !visible.value
@@ -110,6 +110,7 @@ export default {
110110
:zoom="1"
111111
@resize-start="onResizeStart"
112112
@resize="onResize"
113+
@resize-end="onResizeEnd"
113114
@rotate-start="onRotateStart"
114115
@rotate="onRotate"
115116
/>

packages/resize-rotate-node/src/node/utils.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ export function useMoveable(id: string, emits: ResizeRotateNodeEmits) {
4040
emits('resize', { width: e.width, height: e.height })
4141
}
4242

43+
const onResizeEnd = (e: MoveableEvents['resizeEnd']) => {
44+
const oldPosition = node.computedPosition
45+
e.target.style.transform = `rotate(${node.data!.rotate}deg)`
46+
node.position = { x: oldPosition.x + node.data!.translate[0]!, y: oldPosition.y + node.data!.translate[1]! }
47+
node.data!.translate = [0, 0]
48+
49+
emits('updateNodeInternals')
50+
}
51+
4352
const onRotateStart = (e: MoveableEvents['rotateStart']) => {
4453
e.set(node.data!.rotate)
4554
}
@@ -57,6 +66,7 @@ export function useMoveable(id: string, emits: ResizeRotateNodeEmits) {
5766
return {
5867
onResizeStart,
5968
onResize,
69+
onResizeEnd,
6070
onRotateStart,
6171
onRotate,
6272
}

0 commit comments

Comments
 (0)