<script>
import Moveable, { MoveableManagerInterface, Renderer } from "vue-moveable";

const DimensionViewable = {
    name: "dimensionViewable",
    props: [],
    events: [],
    render(moveable, React) {
        const rect = moveable.getRect();
        return React.createElement("div", {
            key: "dimension-viewer",
            className: "moveable-dimension",
            style: {
                position: "absolute",
                left: `${rect.width / 2}px`,
                top: `${rect.height + 20}px`,
                background: "#4af",
                borderRadius: "2px",
                padding: "2px 4px",
                color: "white",
                fontSize: "13px",
                whiteSpace: "nowrap",
                fontWeight: "bold",
                willChange: "transform",
                transform: `translate(-50%, 0px)`
            }
        }, [
            "\r\n            Target\r\n        "
        ]);
    }
};
export default {
    components: { Moveable },
    data() {
        const targetRef = null;
        const dragTarget = undefiend;
        return { targetRef, dragTarget };
    },
    methods: {
        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;
        }
    },
    mounted() {
        this.dragTarget = document.querySelector(".moveable-dimension");
        this.targetRef = this.$refs.targetRef;
    }
};
</script>
<template>
    <div class="container">
        <div
            class="target"
            ref="targetRef"
        ></div>
        <Moveable
            :target="targetRef"
            :ables="[DimensionViewable]"
            :draggable="true"
            :resizable="true"
            :rotatable="true"
            :dragTarget="dragTarget"
            :props="({ dimensionViewable: true })"
            @drag="onDrag"
            @resize="onResize"
            @rotate="onRotate"/>
    </div>
</template>