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

export default {
    components: { Moveable },
    data() {
        return {};
    },
    methods: {
        onClick() {
            const width = 50 + Math.floor(50 * Math.random());
            const height = 50 + Math.floor(50 * Math.random());
            document.querySelectorAll(".target")[Math.floor(Math.random() * 3)].style.cssText += `width: ${width}px;height: ${height}px`;
        },
        onDragGroup(e) {
            e.events.forEach(ev => {
                ev.target.style.transform = ev.transform;
            });
        },
        onResizeGroup(e) {
            e.events.forEach(ev => {
                ev.target.style.width = `${ev.width}px`;
                ev.target.style.height = `${ev.height}px`;
                ev.target.style.transform = ev.drag.transform;
            });
        },
        onRotateGroup(e) {
            e.events.forEach(ev => {
                ev.target.style.transform = ev.drag.transform;
            });
        }
    }
};
</script>
<template>
    <div class="root">
        <div class="container">
            <button @click="onClick">Random Resize</button>
            <div class="target target1">Target1</div>
            <div class="target target2">Target2</div>
            <div class="target target3">Target3</div>
            <Moveable
                :target="'.target'"
                :draggable="true"
                :rotatable="true"
                :resizable="true"
                :useResizeObserver="true"
                @dragGroup="onDragGroup"
                @resizeGroup="onResizeGroup"
                @rotateGroup="onRotateGroup"/>
        </div>
    </div>
</template>