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

export default {
    components: { Moveable },
    data() {
        return {};
    },
    methods: {
        onClick() {
            const left = 50 + Math.floor(50 * Math.random());
            const top = 50 + Math.floor(50 * Math.random());
            document.querySelector(".target").style.cssText += `left: ${left}px;top: ${top}px`;
        },
        onDrag(e) {
            e.target.style.transform = e.transform;
        },
        onResize(e) {
            e.target.style.width = `${e.width}px`;
            e.target.style.height = `${e.height}px`;
            e.target.style.transform = e.drag.transform;
        },
        onRotate(e) {
            e.target.style.transform = e.drag.transform;
        }
    }
};
</script>
<template>
    <div class="root">
        <div class="container">
            <button @click="onClick">Random Position</button>
            <p>
                Changes in css position due to className or attribute selector are not detected.
            </p>
            <p>Use with `useResizeObserver`.</p>
            <div class="target">Target1</div>
            <Moveable
                :target="'.target'"
                :draggable="true"
                :rotatable="true"
                :resizable="true"
                :useResizeObserver="true"
                :useMutationObserver="true"
                @drag="onDrag"
                @resize="onResize"
                @rotate="onRotate"/>
        </div>
    </div>
</template>