<script>
import Moveable from "vue3-moveable";
import { ref } from "vue";

export default {
    components: { Moveable },
    setup() {
        const draggable = "$preview_draggable";
        const throttleDrag = "$preview_throttleDrag";
        const edgeDraggable = "$preview_edgeDraggable";
        const startDragRotate = "$preview_startDragRotate";
        const throttleDragRotate = "$preview_throttleDragRotate";
        const rotatable = "$preview_rotatable";
        const snappable = "$preview_snappable";
        const bounds = "$preview_bounds";
        const edge = "$preview_edge";
        const moveableRef = ref(null);
        const onDrag = e => {
            e.target.style.transform = e.transform;
        };
        const onRotate = e => {
            e.target.style.transform = e.afterTransform;
        };
        const onBound = e => {
            console.log(e);
        };
        return {
            moveableRef,
            draggable,
            throttleDrag,
            edgeDraggable,
            startDragRotate,
            throttleDragRotate,
            rotatable,
            snappable,
            bounds,
            edge,
            onDrag,
            onRotate,
            onBound
        };
    }
};
</script>
<template>
    <div class="root">
        <div
            class="container"
            style="width: 500px;height: 500px;border: 1px solid #ccc;"
        >
            <div
                class="target"
                style="width: 280px;height: 230px;"
            >Target</div>
            <Moveable
                ref="moveableRef"
                :target="'.target'"
                :draggable="draggable"
                :throttleDrag="throttleDrag"
                :edgeDraggable="edgeDraggable"
                :startDragRotate="startDragRotate"
                :throttleDragRotate="throttleDragRotate"
                :rotatable="rotatable"
                :snappable="snappable"
                :bounds="bounds"
                :edge="edge"
                @drag="onDrag"
                @rotate="onRotate"
                @bound="onBound"/>
        </div>
    </div>
</template>