sync node position after resizing

This commit is contained in:
Congyu Wang
2022-12-06 17:50:51 +01:00
committed by Braks
parent af699d384c
commit c382d881e4
2 changed files with 12 additions and 1 deletions
@@ -25,7 +25,7 @@ const el = ref()
const visible = ref(false)
const { onRotateStart, onRotate, onResizeStart, onResize } = useMoveable(props.id, emits)
const { onRotateStart, onRotate, onResizeStart, onResize, onResizeEnd } = useMoveable(props.id, emits)
const toggleVisibility = (val?: boolean) => {
visible.value = val ?? !visible.value
@@ -110,6 +110,7 @@ export default {
:zoom="1"
@resize-start="onResizeStart"
@resize="onResize"
@resize-end="onResizeEnd"
@rotate-start="onRotateStart"
@rotate="onRotate"
/>
@@ -40,6 +40,15 @@ export function useMoveable(id: string, emits: ResizeRotateNodeEmits) {
emits('resize', { width: e.width, height: e.height })
}
const onResizeEnd = (e: MoveableEvents['resizeEnd']) => {
const oldPosition = node.computedPosition
e.target.style.transform = `rotate(${node.data!.rotate}deg)`
node.position = { x: oldPosition.x + node.data!.translate[0]!, y: oldPosition.y + node.data!.translate[1]! }
node.data!.translate = [0, 0]
emits('updateNodeInternals')
}
const onRotateStart = (e: MoveableEvents['rotateStart']) => {
e.set(node.data!.rotate)
}
@@ -57,6 +66,7 @@ export function useMoveable(id: string, emits: ResizeRotateNodeEmits) {
return {
onResizeStart,
onResize,
onResizeEnd,
onRotateStart,
onRotate,
}