Giter Site home page Giter Site logo

probil / vue-moveable Goto Github PK

View Code? Open in Web Editor NEW
966.0 9.0 69.0 5.43 MB

↔️ ↕️ 🔄 Vue.js wrapper for Moveable

Home Page: https://vue-moveable.netlify.com/

License: MIT License

JavaScript 6.08% HTML 14.95% Vue 78.96%
moveable vue-moveable scalable resizable rotatable draggable warpable vue

vue-moveable's Introduction

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

  • Draggable refers to the ability to drag and move targets.
  • Resizable indicates whether the target's width and height can be increased or decreased.
  • Scalable indicates whether the target's x and y can be scale of transform.
  • Rotatable indicates whether the target can be rotated.
  • Warpable indicates whether the target can be warped (distorted, bented).
  • Pinchable indicates whether the target can be pinched with draggable, resizable, scalable, rotatable.
  • Groupable indicates Whether the targets can be moved in group with draggable, resizable, scalable, rotatable.
  • Snappable indicates whether to snap to the guideline.
  • OriginDraggable* indicates Whether to drag origin.
  • Clippable indicates Whether to clip the target.
  • Roundable indicates Whether to show and drag or double click border-radius.
  • Support SVG Elements (svg, path, line, ellipse, g, rect, ...etc)
  • Support Major Browsers
  • Support 3d Transform

⚙️ 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.

vue-moveable's People

Contributors

chonsser avatar daybrush avatar dependabot[bot] avatar keimeno avatar probil avatar renovate-bot avatar romansp avatar russ avatar sliterok avatar yuttie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vue-moveable's Issues

Stop propagation when Movable inside Movable?

Hi, I have this structure in one of my components, with one moveable inside another one:

<template>
  <Moveable> // moveable #1
    <div>
      <Moveable> // moveable #2
        <div>
        </div>
      </Moveable>
    </div>
  </Moveable>
</template>

Both moveables have draggable enabled and methods that handle drag as specified in vue example in this project's README.
When I am dragging moevable#2, moveable#1 also receives drag event and is moving as well. Is there any way I can easily stop drag event propagation from moveable#2 to not trigger on moveable#1?

I am using verison 1.8.9

How to use methods in vue-moveable

I would like to get information about width and height od my moveable element after scaling. I tried to use method getRect(), like showed here: daybrush/moveable#94, but in console I got TypeError: e.currentTarget.getRect() is not a function

My code:

<template>
  <Moveable
    @scale="handleScale"
    @scaleEnd="(e) => {handleScaleEnd(e)}"
    ref="moveable"
  >
</template>

<script>
export default {
  methods: {
    handleScale({ target, transform, scale }) {
      target.style.transform = transform;
    },
    handleScaleEnd(e) {
      console.log(e.currentTarget.getRect());
    },
  }
}

How can I use methods, defined in Moveable documentation, like getRect, destroy, setState etc.

Access to moveable object by ref ?

@ibadass You need to pass container ref as a prop to <Moveable>:

     <div class="container" ref="container"> <!-- here -->
            <Moveable
              class="moveable"
              v-model="row.key"
              v-bind="moveable"
              :container="$refs.container" <!-- here -->
              @drag="handleDrag"
              @resize="handleResize"
              @scale="handleScale"
              @rotate="handleRotate"
              @warp="handleWarp"
              v-for="(row, index) in rows"
              :key="index"
            >
              <span>Vue Moveable</span>
            </Moveable>
          </div>

https://codesandbox.io/s/vue-material-also-works-on-the-right-side-j5psx

Originally posted by @probil in #28 (comment)

Hi @probil,
I had save a moveable object in my db, and I want display this object when I'm on my component.
But I can't access to a moveable object by her ref after I created a new one, I need to access to getRect() could you help me ?

Thanks
ibadass

How to set initial position for a warpable component

I want to create polygon like moveable under specific div given that I have 4 x-y coordinates where the moveable needs to be placed. And also need new position (if changed by user) w.r.t. that specific div. Please guide.

Issues after update to version 1.5.0.

Hello, I've updated vue-moveable to version 1.5.0. and I can not reference to setState() method.
I used (for example)
this.$refs.moveable.moveable.setState(() => this.moveable.draggable = true)

Now i can't set moveable values andI don't see my renderDirections.

Access to moveable-control-box also changed, from this.$refs.moveable.moveable.innerMoveable.preactMoveable.base.style to this.$refs.moveable.moveable.innerMoveable.moveable.moveable.controlBox.element.style - is that correct?

hide / show / hide blue line helpers.

How could I with Vue hide and show line helpers?

I have a few elements, and want sometimes remove all moveable functionality. Like it will be not draggable, not resiazable, not wrapable and so... I can do that just added moveable.draggable="false", moveable.scalable="false" ... But, blue line-helpers are still there.

My problem is that div with class name "moveable-control-box" which contains all line/point helpers to drag/resize/wrap element is added directly into the body tag. And I do not know how can I access and style correct "moveable-control-box" element within Vue.

Do you have some ideas?

keepRatio, for all resize circles?

Is it possible to apply keepRatio for all resize circles, currently it does work only for the corner circles.
Or is it possible to hide some of the resize circles?

Moveable Stuck when hitting bounds

Hi there,
my setup works well, i just implemented bounds setting like this :

bounds: { left: 0, right: 780, top: 0, bottom: 400},
dragArea : true,
snappable: true,

now IF the moveable touch a bound when dragging THEN when drag is released it becomes undraggable and stay stucked.
I am not ure this is the expected behavior, am i missing an option ?
Thanks.

Multiple moveable issues

Excuse me for my poor english.
vue 2,moveable-vue version:1.4.0
1.I didn't set the initialization style. I expected the width of the moveable-box to be the default target width. But when there are multiple moveables, it becomes the widest target width.

1582707726482

2.I did not use moveable-vue 1.5.0, because only one of them can be used normally when there are multiple moveable instances in version 1.5.0

pinch stops

hello,

I checked ou component, looks nice but I got 2-3 issues. when doing pinh, it work for a few times. the it stops. when doing pinch rotate it flickers between the rotated view and the normal rotation. after this the scale is also gone.

Single moveable control box

It has props of target in moveable.
Each time the target changes, the moveable box changes.

But only vue is different.

  • vanilla
moveable.target = document.querySelector("'target');
  • react
<Moveable target={document.querySelector(".target")} />
  • Angular
<ngx-moveable [target]="document.querySelector("'target')"/>
  • vue
<vue-moveable>
<div class="target"></div>
</vue-moveable>

daybrush/moveable#55

How to change default container for controls?

Hello I'm new to vue and I'm using vue-moveable in a subcomponent and but controls are moving all over the page. I want them in that component only. I tried using the container prop mentioned in API documentation. like this

data: function () {
            return {
                moveable: {
                    container: document.getElementById('html-container'),
                    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,
                }
            }
        },

in vue dev tools it shows null, I'm assuming it is running before the component is rendered or etc.
any way to achieve the required functionality?

setState method not working in 1.8.2 version

I just updated to 1.8.2 version of this plugin and I cannot set values for my state;

#84 (comment)

I removed additional moveable instance from this.$refs.moveable.setState(); but it still do not work.

I have got something like this in mounted function:

this.$refs.moveable.setState(() => {
  this.moveable.scalable = true;
  this.moveable.resizable = false;
  this.moveable.keepRatio = true;
  this.moveable.draggable = true;
  this.moveable.rotatable = true;
 });

And my data:

data() {
    return {
       moveable: {
         draggable: false,
         resizable: false,
         scalable: false,
         rotatable: false,
         keepRatio: true,
         pinchable: true,
         snappable: true,
         verticalGuidelines: [100, 200, 300],
         horizontalGuidelines: [0, 100, 200],
         renderDirections: ["nw", "ne", "sw", "se"],
         container: document.getElementById(`${this.parentId}`),
         className: `moveable-box moveable-${this.el.id}`,
         target: '.target'
      }
   }
}

Multiple vue-moveable objects on a page

When there are multiple moveable objects on the document.body, only one can be active at a time. You also have to wire up a button in-order to re-activate the non-active items. Is there a way to assign an ID and/or key so that each moveable object can be moved all the time without having to re-activate?? Seems like (from issue #35) that it should be possible to have multiple active objects.

Container boundaries

@probil How to handle bounds, I want my moveable object can't get out of the parent container, is that possible ?

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this 💪.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


No npm token specified.

An npm token must be created and set in the NPM_TOKEN environment variable on your CI environment.

Please make sure to create an npm token and to set it in the NPM_TOKEN environment variable on your CI environment. The token must allow to publish to the registry https://registry.npmjs.org/.


Good luck with your project ✨

Your semantic-release bot 📦🚀

moveable controls don't align properly when used as a vue component build.

So I used this package and really loved the features offered but when I try to build my own vue component into html file, the moveable controls don't align properly and they go in the top left corner of the screen.

This is the command I use to build component into /dist folder

npx vue-cli-service build --target wc --name my-component 'src/components/MyComponent.vue' --inline-vue

Cannot dynamically resize the moveable

Hi - I have a codesandbox demo here of the problem I'm seeing.

I want to be able to move the box you see on screen by dragging the "Move" in the top-left, and that works fine.

I want to be able to "close" the box, by which I mean just reduce it to the banner at the top with the "Move" and "Close" controls. This almost works... the problem is that, although the height for the containing "div" (which is, I believe, the Moveable) changes, the blue edge rectangle stays the same size, so although the content goes away, the bounding box remains.

I've tried a lot of things such as trying to trigger "resize" events, etc., but gotten nowhere.

Thanks!

vue-moveable with TS

I got:
Error TS7016 (TS) Could not find a declaration file for module 'vue-moveable'. 'E:/project/node_modules/vue-moveable/dist/lib/VueMoveable.common.js' implicitly has an 'any' type.
Try npm install @types/vue-moveable if it exists or add a new declaration (.d.ts) file containing declare module 'vue-moveable'; E:\projec (tsconfig or jsconfig project)

when I try import vue-moveable at project with typescipt.

I just try:
import Moveable from 'vue-moveable';

...
How I should do this on project with type script?

Unable to use groups after initialization

Based on the Moveable documentation (found here: https://github.com/daybrush/moveable/blob/0.13.4/handbook/handbook.md#toc-group), you can create a group of moveable elements by passing an array to the target property. However, doing so in vue-moveable after initialization throws the following error:

Uncaught (in promise) TypeError: Cannot read property 'addEventListener' of undefined

I've confirmed that this occurs no matter the type of elements. It's present with both div and svg. Additionally, if the array has only a single element in it, this error does not occur.

Demo:
https://codesandbox.io/s/vue-moveable-group-problem-9r6sf?fontsize=14&hidenavigation=1&theme=dark

Vue-Moveable version: 1.4.0

How to hide blue lines?

I want to make the page an edit page. Thus, when on edit page there is a blue line and everything is draggable and such but when you press save everything is "saved" and i want to hide the blue lines.

Is there a way to hide the blue lines surrounding your html elements?

Unit tests

Add some basic unit tests to make sure library works fine after moveable upgrade and component changes

Fonts scale

I have a problem with scalling texts - i would like to have defined moveable box and in there some text. When scalling, I want box scalling, not text. Now Text is scalling to, which breaks font-size.
Can I get this with Moveable?

Control box height & position is off

This is how the control box gets rendered for me. The width seems to be correct, but the height and position are off. I'll also try and create a codesandbox to replicate this as soon as I get a chance. I'd don't see as an issue under moveable nor for vue-moveable so it's most-likely something small on my side, but I just can't seem to figure it out 😞

This is my code:

<moveable
  v-bind="moveableOptions"
  @drag="handleDrag"
  @resize="handleResize"
  @rotate="handleRotate"
>
  <img ref="avatar" class="avatar" :src="avatar" :style="avatarConfig" />
</moveable>
moveableOptions: {
  draggable: true,
  resizable: true,
  keepRatio: true,
  rotatable: true,
  pinchable: true
}

Screenshot 2019-12-09 at 22 40 26

Remove global polyfills

Currently library includes polyfill for built-ins like Promise, Symbol or Object.assign.

But according to the Vue CLI docs:

When using Vue CLI to build a library or Web Components, it is recommended to pass useBuiltIns: false to @vue/babel-preset-app to disable automatic polyfill injection. This ensures you don't include unnecessary polyfills in your code, as it should be the responsibility of the consuming app to include polyfills.

We can cut up to 20kb of JS from the bundle

TODO:

  • PR
  • Remove polyfills
  • Describe needed polyfills in docs
  • Release

Bind style to <Moveable> component

I would like to bind height and width to moveable component, because then moveable-control-box will be that width and height too.
However, when i use :width="el.width" on my it does not render; data attributes does not render too.
How to add style to component? It can not be in <style> tag, because it is dynamic and different, depending on element values.

Position/Alignment of movable box

When I setup this to work with a list of image thumbnails on my page, the movable blue box is below the images. Attached is a screenshot of what it looks like.
Screen Shot 2019-08-29 at 8 33 07 AM

re-drawing on resize

#8
I have same problem,
version: 1.5.0
container have full width,
when i change width of side element programmatically that happens again

Events doesn't seem to be bound correctly

Hello,
I am having an issue with events:

 @drag-end="console.log('end')"
 @dragstart="console.log('start')"

Gives me an error:
"dragend" is emitted in component but the handler is registered for "dragEnd". Note that HTML attributes are case-insensitive and you cannot use v-on to listen to camelCase events when using in-DOM templates. You should probably use "drag-end" instead of "dragEnd".

And no callback is executed.
BTW: thank you for the library!

Custom Drag button instead all element

Hello,
I have a comment box like image below, I can not focus to textarea to type some text. I'd like to add 1 button (icon drag) instead hold and move any position inside element.

Screen Shot 0002-06-22 at 17 54 08

This is my code

<Moveable
    class="moveable"
    v-bind="moveable"
    :container="container"
    ref="moveable"
    @drag="handleDrag"
    @resize="handleResize"
    :style="{ 'left': comment.left, 'top': comment.top, 'width': comment.width, 'height': comment.height, 'position': 'absolute' }"
  >
    <section
      class="heatmap-comment--item p-3"
    >
      <TextareaAutosize
        @click="handleClick"
        ref="textarea"
        :placeholder="$t('comment')"
        v-model="comment.message"
        :min-height="30"
        :max-height="150"
      />
      <div class="buttons">
        <b-button class="button is-primary" @click="handleSaveComment()">{{ $t('button.save') }}</b-button>
        <b-button class="button" @click="handleDeleteComment()">{{ $t('button.delete') }}</b-button>
      </div>

    </section>

  </Moveable>

Any help!

Bounds in container doesn't seem to apply

Hi, I'm starting to play with Vue Moveable and I'm trying to get the moveable to stay inside its container. I've set, draggable, dragArea, and snappable to the demo sandbox according to the docs. I have added a :container="$refs.container" to specify the container and set styles on the container and then try to set bounds.

The object can still be moved outside the container and the bounds seem to only apply to the document body and not the container. Shouldn't the bounds apply to the reference container or am I misunderstanding how this should work?

Here is a CodeSandbox with the issue. If the container is set, shouldn't the bounds apply to the container so that the moveable should be kept within the green box container?

Thank you for any help!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.