probil / vue-moveable

↔️ ↕️ 🔄 Vue.js wrapper for Moveable
https://vue-moveable.netlify.com/
MIT License
966 stars 69 forks source link
draggable moveable resizable rotatable scalable vue vue-moveable warpable

This project is superseded by the official Moveable Vue plugin:

Vue Moveable

npm version github stars license Minified library size React Preact Angular Vue

A Vue Component that create Moveable, Draggable, Resizable, Scalable, Rotatable, Warpable, Pinchable, Groupable, Snappable.

Edit Vue Moveable Demo

Moveable
Draggable Resizable Scalable Rotatable
Warpable Pinchable Groupable Snappable
Clippable Roundable OriginDraggable Selecto

🔥 Features

⚙️ Installation

$ npm i vue-moveable

📄 Documents

🚀 How to use

<template>
  <Moveable
    class="moveable"
    v-bind="moveable"
    @drag="handleDrag"
    @resize="handleResize"
    @scale="handleScale"
    @rotate="handleRotate"
    @warp="handleWarp"
    @pinch="handlePinch"
  >
    <span>Vue Moveable</span>
  </Moveable>
</template>
<script>
import Moveable from 'vue-moveable';

export default {
  name: 'app',
  components: {
    Moveable,
  },
  data: () => ({
    moveable: {
      draggable: true,
      throttleDrag: 0,
      resizable: false,
      throttleResize: 1,
      keepRatio: false,
      scalable: true,
      throttleScale: 0,
      rotatable: true,
      throttleRotate: 0,
      pinchable: true, // ["draggable", "resizable", "scalable", "rotatable"]
      origin: false,
    }
  }),
  methods: {
    handleDrag({ target, transform }) {
      console.log('onDrag left, top', transform);
      target.style.transform = transform;
    },
    handleResize({
      target, width, height, delta,
    }) {
      console.log('onResize', width, height);
      delta[0] && (target.style.width = `${width}px`);
      delta[1] && (target.style.height = `${height}px`);
    },
    handleScale({ target, transform, scale }) {
      console.log('onScale scale', scale);
      target.style.transform = transform;
    },
    handleRotate({ target, dist, transform }) {
      console.log('onRotate', dist);
      target.style.transform = transform;
    },
    handleWarp({ target, transform }) {
      console.log('onWarp', transform);
      target.style.transform = transform;
    },
    handlePinch({ target }) {
      console.log('onPinch', target);
    },
  }
}
</script>

Calling moveable methods

All moveable instance methods are supported. Just use reference to call them.

E.g. this.$refs.<moveable_ref>.<moveable_method>.

Here is an example:

<template>
  <Moveable
    ref="moveable"
    class="moveable"
  >
    <span>Vue Moveable</span>
  </Moveable>
</template>
<script>
import Moveable from 'vue-moveable';

export default {
  name: 'app',
  components: {
    Moveable,
  },
  mounted() {
   console.log("getRect: ", this.$refs.moveable.getRect()); 
   // -> getRect: Object {width: 300, height: 200, left: 127, top: 120.5, pos1: Array[2]…}
   console.log("isMoveableElement: ", this.$refs.moveable.isMoveableElement(document.body));
   // -> isMoveableElement: false

  },
}
</script>

Demo: https://codesandbox.io/s/vue-moveable-issue-84-xzblq

Polyfills

Library use few browser built-ins and doesn't include polyfills for them. This ensures you don't include unnecessary polyfills in your code, as it should be the responsibility of the consuming app to include them.

Vue CLI includes them in babel config by default but here is a list (in case you what to add them manually):

# for core-js@2
es6.array.filter
es6.object.keys
es6.symbol        # optional

# for core-js@3
es.array.filter
es.object.keys
es.symbol         # optional

For direct usage in browser consider using https://polyfill.io/v3/

⚙️ Developments

npm run serve

Runs the app in the development mode.
Open http://localhost:8080 to view it in the browser.

The page will reload if you make edits.
You will also see any lint errors in the console.

⭐️ Show Your Support

Please give a ⭐️ if this project helped you!

👏 Contributing

If you have any questions or requests or want to contribute to vue-moveable or other packages, please write the issue or give me a Pull Request freely.

🐞 Bug Report

If you find a bug, please report to us opening a new Issue on GitHub.

📝 License

This project is MIT licensed.