Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

react-moveable-kk

kakajun22MIT0.0.1TypeScript support: included

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

moveable, resizable, scalable, draggable, rotatable, warpable, pinchable, groupable, snappable, scrollable, movable, throttle, scroll, ratio, dom, resize, scale, drag, move, rotate, react, warp, snap, pinch, react

readme

React Moveable

npm version

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

Demo / Storybook / API / Main Project

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 react-moveable

📄 Documents

🚀 How to use

import Moveable from "react-moveable";

render() {
    return (
        <Moveable
            target={document.querySelector(".target")}
            container={null}
            origin={true}

            /* Resize event edges */
            edge={false}

            /* draggable */
            draggable={true}
            throttleDrag={0}
            onDragStart={({ target, clientX, clientY }) => {
                console.log("onDragStart", target);
            }}
            onDrag={({
                target,
                beforeDelta, beforeDist,
                left, top,
                right, bottom,
                delta, dist,
                transform,
                clientX, clientY,
            }: OnDrag) => {
                console.log("onDrag left, top", left, top);
                // target!.style.left = `${left}px`;
                // target!.style.top = `${top}px`;
                console.log("onDrag translate", dist);
                target!.style.transform = transform;
            }}
            onDragEnd={({ target, isDrag, clientX, clientY }) => {
                console.log("onDragEnd", target, isDrag);
            }}

            /* When resize or scale, keeps a ratio of the width, height. */
            keepRatio={true}

            /* resizable*/
            /* Only one of resizable, scalable, warpable can be used. */
            resizable={true}
            throttleResize={0}
            onResizeStart={({ target , clientX, clientY}) => {
                console.log("onResizeStart", target);
            }}
            onResize={({
                target, width, height,
                dist, delta, direction,
                clientX, clientY,
            }: OnResize) => {
                console.log("onResize", target);
                delta[0] && (target!.style.width = `${width}px`);
                delta[1] && (target!.style.height = `${height}px`);
            }}
            onResizeEnd={({ target, isDrag, clientX, clientY }) => {
                console.log("onResizeEnd", target, isDrag);
            }}

            /* scalable */
            /* Only one of resizable, scalable, warpable can be used. */
            scalable={true}
            throttleScale={0}
            onScaleStart={({ target, clientX, clientY }) => {
                console.log("onScaleStart", target);
            }}
            onScale={({
                target, scale, dist, delta, transform,
                clientX, clientY,
            }: OnScale) => {
                console.log("onScale scale", scale);
                target!.style.transform = transform;
            }}
            onScaleEnd={({ target, isDrag, clientX, clientY }) => {
                console.log("onScaleEnd", target, isDrag);
            }}

            /* rotatable */
            rotatable={true}
            throttleRotate={0}
            onRotateStart={({ target, clientX, clientY }) => {
                console.log("onRotateStart", target);
            }}
            onRotate={({
                target,
                delta, dist,
                transform,
                clientX, clientY,
            }: onRotate) => {
                console.log("onRotate", dist);
                target!.style.transform = transform;
            }}
            onRotateEnd={({ target, isDrag, clientX, clientY }) => {
                console.log("onRotateEnd", target, isDrag);
            }}
            // Enabling pinchable lets you use events that
            // can be used in draggable, resizable, scalable, and rotateable.
            pinchable={true}
            onPinchStart={({ target, clientX, clientY, datas }) => {
                // pinchStart event occur before dragStart, rotateStart, scaleStart, resizeStart
                console.log("onPinchStart");
            }}
            onPinch={({ target, clientX, clientY, datas }) => {
                // pinch event occur before drag, rotate, scale, resize
                console.log("onPinch");
            }}
            onPinchEnd={({ isDrag, target, clientX, clientY, datas }) => {
                // pinchEnd event occur before dragEnd, rotateEnd, scaleEnd, resizeEnd
                console.log("onPinchEnd");
            }}
        />
    );
}

React 18 concurrent mode

If you are using React 18's concurrent mode, use flushSync for UI sync.

import React from 'react';
import ReactDOM from 'react-dom/client';
import { flushSync } from "react-dom";

import Moveable from "react-moveable";


function App() {
    return <Moveable flushSync={flushSync} />
}

const root = ReactDOM.createRoot(document.getElementById("root"));

root.render(
    <React.StrictMode>
        <App />
    </React.StrictMode>
);

⚙️ Developments

npm start

The main project was made with react and I used croact to make it lighter with umd.

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

$ yarn
$ npm run packages:build
$ npm run storybook

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

📝 License

This project is MIT licensed.

MIT License

Copyright (c) 2019 Daybrush

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

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

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

changelog

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

0.55.0 (2023-10-28)

:rocket: New Features

  • add snapGridAll prop #990 (7ecd0d0)

:bug: Bug Fix

  • fix line break #1001 (5f68143)
  • fix nested svg #1011 (33366b5)
  • fix throttleDrag for group (5f6d392)
  • fix width scale for keepRatio #1020 (8dd5c36)
  • remove console.log (56f99ea)

:mega: Other

0.54.2 (2023-09-19)

:bug: Bug Fix

  • fix roundable shadow condition (adb09b7)
  • fix scrollable infinite loop #1015 (b725981)
  • support transform-box: fill-box (#1012) (7a0ed4d)

:mega: Other

0.54.1 (2023-07-11)

:bug: Bug Fix

  • fix individual transforms for 2d #969 (7e205f4)

:mega: Other

0.54.0 (2023-07-09)

:rocket: New Features

  • add onBound event #970 (c9db51f)
  • add dragTargetSelf prop #972 (4537dfe)
  • add elementDirection property in guideline #949 (1073ebc)

:bug: Bug Fix

:mega: Other

0.53.2 (2023-07-04)

:bug: Bug Fix

  • support individual transform #969 (1b58541)
  • support react18 strict mode #962 (710f019)

:mega: Other

0.53.1 (2023-07-02)

:rocket: New Features

  • add getMoveables with request #940 (b926985)
  • support dragStart with individualGroupable #967 (d470f64)

:bug: Bug Fix

  • fix choppy reisze #961 (c8f9637)
  • fix group's dragTargetRef #953 (85d17d7)
  • fix translate(-50%, -50%) #963 (6577ee9)
  • individualGroupable request #967 (daf6008)

:mega: Other

0.52.1 (2023-06-28)

:bug: Bug Fix

:house: Code Refactoring

:mega: Other

0.52.0 (2023-06-25)

:rocket: New Features

  • add direciton on snap event #949 (69312fd)
  • export matrixes in getElementInfo (c1aad6a)
  • setMin, setMax scale size in onScaleStart (ea4cd95)
  • support multiple dragTarget type #953 (4a347d2)
  • support snappable in request #954 (863ad42)

:bug: Bug Fix

  • bump react-selecto version (c3eb9c7)
  • fix isRequest naming (fb90fbd)
  • fix max scale size (9cd9761)
  • fix padding for scalized target #951 (70d938f)
  • fix props and event types missing #941 (bd91b08)
  • fix ResizeObserver, MutationObserver contexts (71152cb)
  • fix scalable group's negative scale dist #950 (f4bb504)
  • fix typo (degress => degrees) #928 (835be5b)
  • support useMutationObserver in Group (def4db3)

:mega: Other

0.51.0 (2023-06-04)

:rocket: New Features

  • add hideThrottleDragRotateLine prop #923 (e091d39)
  • add isDisplayGridGuidelines prop #935 (589bb9d)
  • add snapRotationThreshold, snapRotationDegress #928 (d63283c)
  • add transformObject property in render events #933 (317ddde)
  • add useDefaultGroupRotate prop #929 (5846e50)
  • support drag api #920 (8f1a839)

:bug: Bug Fix

  • add defense code for .stopDrag #930 (be743bc)
  • fix bounds keepRatio sign #924 (8ccc8fd)
  • fix keepRatio for zero scale #927 (7b936ac)
  • fix ownerDocument css #932 (76a852a)
  • support iframe #932 (15abedb)
  • support iframe #932 (7b4cbad)
  • support iframe context #932 (3e87cc7)

:mega: Other

0.50.7 (2023-05-16)

:bug: Bug Fix

  • fix css-styled version #916 (875fc19)
  • occur unset for idle state #917 (a9d1de8)

:mega: Other

0.50.6 (2023-05-15)

:rocket: New Features

:bug: Bug Fix

  • add defense logic for added element on dragStart #917 (ef37c3b)
  • fix controlPadding #918 (685c459)
  • fix initial gestos (84afabb)
  • fix line, control padding appearing #919 (63b9ecd)
  • fix not initialized target #917 (f291bf3)
  • unset gesto when target changed #917 (9d6c0d7)
  • update croact, css-styled version #916 (b517b64)

:mega: Other

0.50.5 (2023-05-09)

:bug: Bug Fix

:memo: Documentation

:mega: Other

0.50.4 (2023-05-08)

:bug: Bug Fix

  • add dragFcousedInput prop (e96f9fc)
  • fix dragFocusedInput #896 (94cb92d)
  • fix files filed #910 #909 #907 (a4995ab)

:memo: Documentation

  • fix dragFcousedInput story (2b78a4e)

:mega: Other

0.50.0 (2023-05-01)

:rocket: New Features

  • add dragFocusedInput prop #896 (a29c9de)
  • add svgOrigin prop #894 (619d57d)

:bug: Bug Fix

  • fix element guidelines for group #900 (d42c032)
  • fix fixedOffset (a00ab2a)
  • fix invidualGroup's mount code #905 (d2388e5)
  • fix snapGrid's offset #897 (97d89de)
  • prevent multitouch for target and control #898 (0b4d328)

:mega: Other

0.49.2 (2023-04-16)

:bug: Bug Fix

  • fix 0.2 guideline offset delta #888 (d85c041)
  • fix pinchable's operation #892 (f4d8df3)

:mega: Other

0.49.0 (2023-04-13)

:rocket: New Features

:bug: Bug Fix

  • fix delta offset for element guidelines #888 (526bec1)
  • fix github workflow (0fd81b8)
  • fix Scalable's keepRatio calculation #887 (680c161)
  • fix vertical guidelines (1abcc37)
  • resolve transform matrix (090e1b2)

:mega: Other

0.48.0 (2023-03-26)

:rocket: New Features

  • add useMutationObserver prop #869 (f3a9ee4)

:bug: Bug Fix

  • fix individualGroupable #867 (6d98f76)

:memo: Documentation

:mega: Other

0.47.3 (2023-03-21)

:bug: Bug Fix

  • fix infinite loop (#873) (179f950)

:memo: Documentation

:mega: Other

0.47.2 (2023-03-14)

:bug: Bug Fix

  • fix chromium agent (#864) (04ffe64)
  • fix groupable moveables' calculation (cd9970e)

:memo: Documentation

:mega: Other

0.47.1 (2023-03-10)

:bug: Bug Fix

  • fix chromium agent #847 (f6a703b)

:mega: Other

0.47.0 (2023-03-08)

:rocket: New Features

  • add preventDefault prop #821 (b599e32)
  • add displayAroundControls, controlPadding #837 (9ee0c72)
  • add individualGroupableProps props #848 (079e752)

:bug: Bug Fix

  • custom element offset with chrome 109 or higher #847 (af20f7e)
  • fix requestStyle #856 (88c9ec2)
  • fix zoomed font size #855 (172f6d4)

:memo: Documentation

:mega: Other

0.46.1 (2023-01-29)

:rocket: New Features

  • add linePadding prop #837 (af818ab)
  • add isTrusted event property (256c40c)
  • add scrollOptions #841 (a6dfc21)

:bug: Bug Fix

  • fix changed defaultGroupOrigin (8d0ed9b)
  • fix TargetList (008116c)
  • support able requester types (c26e5a9)

:mega: Other

0.45.1 (2022-12-16)

:bug: Bug Fix

  • fix helper's methods (4bc6ef5)
  • fix snap rendering for first drag #810 (170eaec)
  • fix targetGroups' compare condition (21622f2)
  • fix targetGroups' compare condition (959a9f0)

:mega: Other

0.45.0 (2022-12-10)

:rocket: New Features

  • add checkResizableError prop #808 (cb70b3b)
  • add stopAble property (c05ba1f)
  • add OrginDraggable, Warpable css object #807 (32ba0ce)
  • add useAccuratePosition prop #164 (5c3898f)

:bug: Bug Fix

  • fix request with bounds #809 (43e08d1)
  • fix useAccuratePosition for group (e1b3ae7)

:mega: Other

0.44.1 (2022-12-05)

:bug: Bug Fix

  • fix tangent's tiny x value #806 (e45b92a)
  • move react-moveable path (ec8e162)

:mega: Other

0.44.0 (2022-12-03)

:rocket: New Features

  • add borderRadius style state #804 (57bae32)
  • add groupableProp #798 (58d9d22)
  • add scrollThrottleTime prop (b53924e)
  • Support roundable group #798 (90a9c1a)

:bug: Bug Fix

  • fix first render for individual groupable (74dc11a)
  • fix position relative with zoom #800 (2efdc35)

:mega: Other

0.43.1 (2022-11-28)

:bug: Bug Fix

:mega: Other

0.43.0 (2022-11-27)

:rocket: New Features

  • add isFirstDrag property on drag event #796 (7ade6a2)

:bug: Bug Fix

  • fix snap size for position fixed #791 (b02c82b)
  • support css zoom #800 (fa3de6b)

:memo: Documentation

:mega: Other

0.42.0 (2022-11-13)

:rocket: New Features

  • add stopDrag method #787 (1c1d54d)
  • add cssText on clip event (90e5397)
  • support group persist #780 (40a23db)

:bug: Bug Fix

  • fix edgeDraggable #695 (9ebfae5)
  • fix persist group (d1c9e2c)
  • fix snap bug for rotated group #786 (3ac47da)
  • fix snap for fixed position #791 (05f6f22)
  • fix throttleDrag #789 (8f4659e)
  • update gesto, dragscroll dependencies (0f33358)

:mega: Other

0.41.1 (2022-11-06)

:bug: Bug Fix

  • fix group rotation delta (ef0c591)

:mega: Other

0.41.0 (2022-11-04)

:rocket: New Features

  • add ableName-view-dragging in viewContainer #751 (90c5c34)
  • add persistData prop for restore data #780 #777 (599df9b)
  • add snapThreshold prop #774 (1bf05b3)
  • support rotationPosition array type #783 (80653c3)
  • support stopDrag on drag #775 (d950472)

:bug: Bug Fix

  • fix changing snapContainer #773 (c3ee847)
  • fix document element #782 (b9194d7)
  • fix no relative snapContainer's size #773 (1db881f)
  • fix rotate dist #778 (7ac47ca)

:memo: Documentation

:mega: Other

0.40.0 (2022-10-17)

:rocket: New Features

  • add viewContainer prop #753 (352073c)
  • add getTargets method #751 (16f1061)
  • add roundPadding, isDisplayShadowRoundControls #761 #762 (68be2e8)

:bug: Bug Fix

  • fix border radius for line #761 (803f0b6)
  • fix cache condition #760 (03e2789)
  • fix first visibility #760 (38ba047)
  • fix flash of single, group toggling #760 (5578030)
  • fix max-width percentage #763 (f1ad4af)
  • fix roundable control index #762 (1b29ecd)
  • Fixing bad type causing type conflict (#767) (c63c1d3)
  • support cache for group #760 (4661320)

:mega: Other

0.39.4 (2022-10-10)

:bug: Bug Fix

  • enhance updateSelectors #760 (e72b119)
  • fix click event #746 (41809c1)
  • fix drag start edge #745 (105bb1c)
  • fix index attr for roundable (92932d7)
  • fix onScaleGroupEnd param #755 (ce7d855)
  • fix roundable line index #756 (83d5232)

:mega: Other

0.39.1 (2022-09-19)

:bug: Bug Fix

  • fix updateSelectors method #740 (f9abb0f)

:mega: Other

0.39.0 (2022-09-15)

:rocket: New Features

  • add moveableTarget property in click event (ee3d9f2)
  • add updateSelectors method (90f40e2)
  • support multiple group #566 #731 (0bb7977)

:bug: Bug Fix

  • fix defaultGroupRotate action (1f6709a)
  • fix dragtarget #468 (c662cca)
  • fix multiple group (20af5c1)
  • fix overflow auto target #730 (1e0ae91)
  • fix rotatable throttling (b18f16a)
  • fix rotate group origin #733 (3e9e8e5)
  • fix shadow dom css #729 (7581afc)

:mega: Other

0.38.4 (2022-08-24)

:bug: Bug Fix

  • ignore document for firefox (db0c730)

:mega: Other

0.38.3 (2022-08-23)

:bug: Bug Fix

  • fix custom element offsetPos for firefox (6e05812)
  • fix svg group's offset pos #722 (167d277)
  • fix waitToChangeTarget method #714 (fc9847b)
  • stop event if no use ables #724 (2a90842)

:mega: Other

0.38.1 (2022-08-12)

:bug: Bug Fix

  • export event-emitter (937d83e)
  • fix click event for mobile #720 (ce6bced)
  • fix that dragStart method cannot fire #718 (5ea9fc3)

:mega: Other

0.38.0 (2022-08-06)

:rocket: New Features

  • add maxSnapElementGapDistance prop #707 (5f71c30)
  • add stopDrag event property #665 (70f49ee)
  • add waitToChangeTarget method #714 (8e6c534)

:bug: Bug Fix

  • prevent click when drag & click control #713 (2071c0d)
  • render only shortest gap guidelines #707 (176c1b3)

:mega: Other

0.37.3 (2022-08-03)

:bug: Bug Fix

  • fix click event by gesto update #713 (3a3c762)
  • fix offsetParent with willChange #711 (cd1de86)

:mega: Other

0.37.2 (2022-08-01)

:rocket: New Features

  • add CSSObject on render (e2f462a)
  • add maxSnapElementGuidelineDistance #707 (171b027)
  • add preventClickEventOnDrag prop (281b2b7)
  • add startFixedDirection property on before event (c838c9c)
  • add stopPropagation prop (3ce54e0)

:bug: Bug Fix

  • fix cssText, style on drag (aed807e)
  • fix drag undefined on Rotate Group #710 (db80e7d)
  • fix getElementInfo's NaN type value #709 (e99d94f)
  • fix rotate position #710 (d269d1f)

:memo: Documentation

:mega: Other

0.36.0 (2022-07-25)

:rocket: New Features

  • add cssText, style property on events (7a9012e)
  • add rotateAroundControls prop (d473ffa)
  • add style, cssText, afterTransform properties (68b4a92)
  • support pos guideline info #707 (1cd1b81)
  • Support rotate and resize together #467 (24482a6)
  • use edge at the same tiem #706 (c273703)

:bug: Bug Fix

  • remove wrong react types #703 (25dced4)

:mega: Other

  • publish packages (63e03d1)
  • update dragscroll module version (e9b5864)

0.35.0 (2022-07-21)

:rocket: New Features

  • add keepRatioFinally prop #698 (bf29635)
  • add move cursor style with edgeDraggable #703 (9901deb)
  • support object self type #701 (99967c2)

:bug: Bug Fix

  • calculate size more accurately #698 (4dd4038)
  • enhance bounds accuracy #699 (9aee6bd)
  • support shadow root #684 (8502d07)

:mega: Other

0.34.2 (2022-07-17)

:bug: Bug Fix

  • fix files field in package.json #700 (48ce548)

:mega: Other

0.34.0 (2022-07-17)

:rocket: New Features

  • add hideChildMoveableDefaultLines prop #692 (c691403)
  • add setFixedDirection on rotateStart #670 (093d0b1)
  • support edge prop's object type #695 (699997d)

:bug: Bug Fix

  • fix floating point for min limit size (766561c)
  • fix guidelines for edgeDraggable #694 (80f2b44)
  • fix safari 15 consts (a140e5b)
  • fix transform behavior in safari 15 #696 (eb0a71c)
  • stop propagation for click control #690 (1a8f697)

:memo: Documentation

  • add hideChildMoveableDefaultLines docs (9e02faa)
  • fix typo #685 (c591b1d)

:mega: Other

0.33.0 (2022-06-09)

:rocket: New Features

  • add preventClickDefault option #671 (17da69f)
  • add flushSync prop #668 (068c174)
  • add snap direction foramt (#669) (52406cc)

:bug: Bug Fix

  • fix groups' setMin, setMax and ratio (0e2abf1)
  • prevent wheel drag #674 (e9bea04)
  • remove peerDependencies (0aa9869)

:mega: Other

0.32.9 (2022-06-07)

:rocket: New Features

  • add clippable keepRatio (37da849)

:bug: Bug Fix

  • fix [1, 1] direction's bounds #624 (5108bc3)
  • fix changed target getos #657 (54ef5a0)
  • fix clippable bounds #659 (b3986de)
  • fix group drag condition (35c194a)
  • fix group gestos for strict mode #656 (311c931)
  • fix innerBounds for no width, height (42fe6f3)
  • fix minSize for zero size (c34f298)
  • fix svg matrixes #643 (525ad70)
  • support keepRatio for Clippable (a934512)

:house: Code Refactoring

:mega: Other

0.32.7 (2022-05-01)

:bug: Bug Fix

  • fix coordinate for position: fixed #653 (87ba56c)
  • skip beforeEvent set to lastEvent #654 (5ab31c7)

:mega: Other

  • update packages versions (169c484)

0.32.5 (2022-04-27)

:mega: Other

  • update packages versions (585094f)

0.32.4 (2022-04-27)

:bug: Bug Fix

  • fix clip bug with draggable, snappable (b5477ee)

0.32.4 (2022-04-26)

:bug: Bug Fix

:mega: Other

  • update packages versions (a62ee58)
  • update typescript version (a63ee9f)
  • upgrade storybook and typescript (eff23fd)