Moveable

Draggable! Resizable! Scalable! Rotatable!

README

src="https://img.shields.io/static/v1.svg?label=&message=Vue&style=flat-square&color=3fb984">    alt="Vue 3"
src="https://img.shields.io/static/v1.svg?label=&message=Vue%203&style=flat-square&color=3fb984">SvelteLit

Moveable is Draggable, Resizable, Scalable, Rotatable, Warpable, Pinchable, Groupable, Snappable

Demo / Storybook / API / Main Project

Moveable
DraggableResizableScalableRotatable
WarpablePinchableGroupableSnappable
ClippableRoundableOriginDraggableSelecto


🔥 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

  1. ```sh
  2. $ npm i moveable
  3. ```

scripts

  1. ``` html
  2. <script src="//daybrush.com/moveable/release/latest/dist/moveable.min.js"></script>
  3. ```

📄 Documents


[Moveable Handbook](https://github.com/daybrush/moveable/blob/master/handbook/handbook.md)
[How to use Group](https://github.com/daybrush/moveable/blob/master/handbook/handbook.md#toc-group)
[How to use custom CSS](https://github.com/daybrush/moveable/blob/master/handbook/handbook.md#toc-custom-css)
[How to make custom able](https://github.com/daybrush/moveable/blob/master/packages/react-moveable/src/react-moveable/ables/README.md)
API Documentation

🚀 How to use

All classes of moveable control box and able elements have a moveable- prefix. So please don't put moveable- class name in target.
  1. ```ts
  2. import Moveable from "moveable";

  3. const moveable = new Moveable(document.body, {
  4.     target: document.querySelector(".target"),
  5.     // If the container is null, the position is fixed. (default: parentElement(document.body))
  6.     container: document.body,
  7.     draggable: true,
  8.     resizable: true,
  9.     scalable: true,
  10.     rotatable: true,
  11.     warpable: true,
  12.     // Enabling pinchable lets you use events that
  13.     // can be used in draggable, resizable, scalable, and rotateable.
  14.     pinchable: true, // ["resizable", "scalable", "rotatable"]
  15.     origin: true,
  16.     keepRatio: true,
  17.     // Resize, Scale Events at edges.
  18.     edge: false,
  19.     throttleDrag: 0,
  20.     throttleResize: 0,
  21.     throttleScale: 0,
  22.     throttleRotate: 0,
  23. });
  24. /* draggable */
  25. moveable.on("dragStart", ({ target, clientX, clientY }) => {
  26.     console.log("onDragStart", target);
  27. }).on("drag", ({
  28.     target, transform,
  29.     left, top, right, bottom,
  30.     beforeDelta, beforeDist, delta, dist,
  31.     clientX, clientY,
  32. }) => {
  33.     console.log("onDrag left, top", left, top);
  34.     target!.style.left = `${left}px`;
  35.     target!.style.top = `${top}px`;
  36.     // console.log("onDrag translate", dist);
  37.     // target!.style.transform = transform;
  38. }).on("dragEnd", ({ target, isDrag, clientX, clientY }) => {
  39.     console.log("onDragEnd", target, isDrag);
  40. });

  41. /* resizable */
  42. moveable.on("resizeStart", ({ target, clientX, clientY }) => {
  43.     console.log("onResizeStart", target);
  44. }).on("resize", ({ target, width, height, dist, delta, clientX, clientY }) => {
  45.     console.log("onResize", target);
  46.     delta[0] && (target!.style.width = `${width}px`);
  47.     delta[1] && (target!.style.height = `${height}px`);
  48. }).on("resizeEnd", ({ target, isDrag, clientX, clientY }) => {
  49.     console.log("onResizeEnd", target, isDrag);
  50. });

  51. /* scalable */
  52. moveable.on("scaleStart", ({ target, clientX, clientY }) => {
  53.     console.log("onScaleStart", target);
  54. }).on("scale", ({
  55.     target, scale, dist, delta, transform, clientX, clientY,
  56. }: OnScale) => {
  57.     console.log("onScale scale", scale);
  58.     target!.style.transform = transform;
  59. }).on("scaleEnd", ({ target, isDrag, clientX, clientY }) => {
  60.     console.log("onScaleEnd", target, isDrag);
  61. });

  62. /* rotatable */
  63. moveable.on("rotateStart", ({ target, clientX, clientY }) => {
  64.     console.log("onRotateStart", target);
  65. }).on("rotate", ({ target, beforeDelta, delta, dist, transform, clientX, clientY }) => {
  66.     console.log("onRotate", dist);
  67.     target!.style.transform = transform;
  68. }).on("rotateEnd", ({ target, isDrag, clientX, clientY }) => {
  69.     console.log("onRotateEnd", target, isDrag);
  70. });

  71. /* warpable */
  72. this.matrix = [
  73.     1, 0, 0, 0,
  74.     0, 1, 0, 0,
  75.     0, 0, 1, 0,
  76.     0, 0, 0, 1,
  77. ];
  78. moveable.on("warpStart", ({ target, clientX, clientY }) => {
  79.     console.log("onWarpStart", target);
  80. }).on("warp", ({
  81.     target,
  82.     clientX,
  83.     clientY,
  84.     delta,
  85.     dist,
  86.     multiply,
  87.     transform,
  88. }) => {
  89.     console.log("onWarp", target);
  90.     // target.style.transform = transform;
  91.     this.matrix = multiply(this.matrix, delta);
  92.     target.style.transform = `matrix3d(${this.matrix.join(",")})`;
  93. }).on("warpEnd", ({ target, isDrag, clientX, clientY }) => {
  94.     console.log("onWarpEnd", target, isDrag);
  95. });

  96. /* pinchable */
  97. // Enabling pinchable lets you use events that
  98. // can be used in draggable, resizable, scalable, and rotateable.
  99. moveable.on("pinchStart", ({ target, clientX, clientY }) => {
  100.     // pinchStart event occur before dragStart, rotateStart, scaleStart, resizeStart
  101.     console.log("onPinchStart");
  102. }).on("pinch", ({ target, clientX, clientY, datas }) => {
  103.     // pinch event occur before drag, rotate, scale, resize
  104.     console.log("onPinch");
  105. }).on("pinchEnd", ({ isDrag, target, clientX, clientY, datas }) => {
  106.     // pinchEnd event occur before dragEnd, rotateEnd, scaleEnd, resizeEnd
  107.     console.log("onPinchEnd");
  108. });
  109. ```


📦 Packages

[moveable](https://github.com/daybrush/moveable/blob/master/packages/moveable): A Vanilla Component that create Moveable, Draggable, Resizable, Scalable, Rotatable, Warpable, Pinchable.
[react-moveable](https://github.com/daybrush/moveable/blob/master/packages/react-moveable): A React Component that create Moveable, Draggable, Resizable, Scalable, Rotatable, Warpable, Pinchable.
[preact-moveable](https://github.com/daybrush/moveable/blob/master/packages/preact-moveable): A Preact Component that create Moveable, Draggable, Resizable, Scalable, Rotatable, Warpable, Pinchable.
[ngx-moveable](https://github.com/daybrush/moveable/blob/master/packages/ngx-moveable): An Angular Component that create Moveable, Draggable, Resizable, Scalable, Rotatable, Warpable, Pinchable.
[svelte-moveable](https://github.com/daybrush/moveable/blob/master/packages/svelte-moveable): A Svelte Component that create Moveable, Draggable, Resizable, Scalable, Rotatable, Warpable, Pinchable.
[lit-moveable](https://github.com/daybrush/moveable/blob/master/packages/lit-moveable): A Lit Component that create Moveable, Draggable, Resizable, Scalable, Rotatable, Warpable, Pinchable.
[vue-moveable](https://github.com/daybrush/moveable/blob/master/packages/vue-moveable): A Vue Component that create Moveable, Draggable, Resizable, Scalable, Rotatable, Warpable, Pinchable.
[vue3-moveable](https://github.com/daybrush/moveable/blob/master/packages/vue-moveable): A Vue 3 Component that create Moveable, Draggable, Resizable, Scalable, Rotatable, Warpable, Pinchable.

⚙️ Developments

The moveable repo is managed as a monorepo withyarn.

  1. ```sh
  2. yarn config set registry https://registry.npmjs.org/
  3. ```

The main project was made with react and I used [react-simple-compat](https://github.com/daybrush/react-simple-compat) to make it lighter with umd.

For development and testing, check in packages/react-moveable.

npm run storybook


  1. ```
  2. $ yarn install
  3. $ npm run bootstrap
  4. $ npm run storybook
  5. ```

Runs the app in the development mode.
Open http://localhost:6006 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 moveable or other packages, please write the issue or give me a Pull Request freely.


Code Contributors


This project exists thanks to all the people who contribute. [Contribute].


🐞 Bug Report


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

Sponsors



Open Collective Financial Contributors


Become a financial contributor and help us sustain our community. [Contribute]

Individuals



Organizations


Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]


📝 License


This project is MIT licensed.

  1. ```
  2. MIT License

  3. Copyright (c) 2019 Daybrush

  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:

  10. The above copyright notice and this permission notice shall be included in all
  11. copies or substantial portions of the Software.

  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  18. SOFTWARE.
  19. ```