<script>
import Moveable from "vue-moveable";

export default {
    components: { Moveable },
    data() {
        const draggable = "$preview_draggable";
        const throttleDrag = "$preview_throttleDrag";
        const edgeDraggable = "$preview_edgeDraggable";
        const startDragRotate = "$preview_startDragRotate";
        const throttleDragRotate = "$preview_throttleDragRotate";
        const scalable = "$preview_scalable";
        const keepRatio = "$preview_keepRatio";
        const throttleScale = "$preview_throttleScale";
        const snappable = "$preview_snappable";
        const bounds = "$preview_bounds";
        const targetRef = null;
        const moveableRef = null;
        return {
            draggable,
            throttleDrag,
            edgeDraggable,
            startDragRotate,
            throttleDragRotate,
            scalable,
            keepRatio,
            throttleScale,
            snappable,
            bounds,
            targetRef,
            moveableRef
        };
    },
    methods: {
        onDrag(e) {
            e.target.style.transform = e.transform;
        },
        onScale(e) {
            e.target.style.transform = e.drag.transform;
        },
        onBound(e) {
            console.log(e);
        }
    },
    mounted() {
        this.targetRef = this.$refs.targetRef;
        this.moveableRef = this.$refs.moveableRef;
    }
};
</script>
<template>
    <div class="root">
        <div
            class="container"
            style="width: 500px;height: 500px;border: 1px solid #ccc;"
        >
            <div
                class="target"
                ref="targetRef"
                style="width: 200px;height: 150px;transform: scale(1.5, 1);"
            >Target</div>
            <Moveable
                ref="moveableRef"
                :target="targetRef"
                :draggable="draggable"
                :throttleDrag="throttleDrag"
                :edgeDraggable="edgeDraggable"
                :startDragRotate="startDragRotate"
                :throttleDragRotate="throttleDragRotate"
                :scalable="scalable"
                :keepRatio="keepRatio"
                :throttleScale="throttleScale"
                :snappable="snappable"
                :bounds="bounds"
                @drag="onDrag"
                @scale="onScale"
                @bound="onBound"/>
        </div>
    </div>
</template>