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

export default {
    components: { Moveable },
    setup() {
        const onDragGroup = e => {
            e.events.forEach(ev => {
                ev.target.style.cssText += ev.cssText;
            });
        };
        const onResizeGroup = (e) => {
            if (e.direction[0] === -1) {
                e.events.forEach((ev) => {
                    ev.target.style.width = `${ev.width - ev.dist[0] + e.dist[0]}px`;
                    ev.target.style.cssText += `margin-left: ${-e.dist[0]}px`;
                });
            } else if (e.direction[0] === 1) {
                e.events.forEach((ev) => {
                    ev.target.style.width = `${ev.width - ev.dist[0] + e.dist[0]}px`;
                });
            }
        };
        return { onDragGroup, onResizeGroup };
    }
};
</script>
<template>
    <div class="root">
        <div class="container">
            <div
                class="target target1"
                style="transform: translate(0px, 0px) rotate(0deg) scale(1, 1);"
            >Target1</div>
            <div
                class="target target2"
                style="transform: translate(0px, 0px) rotate(0deg) scale(1, 1);"
            >Target2</div>
            <div
                class="target target3"
                style="transform: translate(0px, 0px) rotate(0deg) scale(1, 1);"
            >Target3</div>
            <Moveable
                :target="'.target'"
                :draggable="true"
                :resizable="true"
                :keepRatio="false"
                @dragGroup="onDragGroup"
                @resizeGroup="onResizeGroup"/>
        </div>
    </div>
</template>