Skip to content

Commit 95fffe9

Browse files
committed
feat: Add Warpable Feature
1 parent 7641b2b commit 95fffe9

File tree

6 files changed

+150
-21
lines changed

6 files changed

+150
-21
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Changelog
2+
All notable changes to this project will be documented in this file.
3+
4+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
5+
6+
## [0.4.0] - 2019-07-29
7+
### Added
8+
- Add Warpable and option, events
9+
- Support SVG Offset (Only SVG Tag)
10+
- Support 3d transform(matrix) (`perspective` is not yet supported.)
11+
12+
### Fixed
13+
- Fix right mouse click issue #7
14+
- Synchronize target's shape. (Previously, it worked independently of target's shape.)

README.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<a href="https://github.com/daybrush/moveable/tree/master/packages/react-moveable" target="_blank"><img alt="React" src="https://img.shields.io/static/v1.svg?label=&message=React&style=flat-square&color=61daeb"></a>
99
<a href="https://github.com/daybrush/moveable/tree/master/packages/preact-moveable" target="_blank"><img alt="Preact" src="https://img.shields.io/static/v1.svg?label=&message=Preact&style=flat-square&color=673ab8"></a>
1010
</p>
11-
<p align="middle">Moveable is Draggable, Resizable, Scalable, Rotatable</p>
11+
<p align="middle">Moveable is Draggable, Resizable, Scalable, Rotatable, Warpable</p>
1212
<p align="middle">
1313
<a href="https://daybrush.com/moveable"><strong>Demo</strong></a> /
1414
<a href="https://github.com/daybrush/moveable/tree/master/packages/react-moveable"><strong>React Moveable</strong></a> /
@@ -40,7 +40,7 @@
4040
</td>
4141
</tr>
4242
<tr>
43-
<td align="center"><strong>Warpable(soon)</strong></td>
43+
<td align="center"><strong>Warpable</strong></td>
4444
<td align="center"><strong></strong></td>
4545
<td align="center"><strong></strong></td>
4646
<td align="center"><strong></strong></td>
@@ -86,6 +86,7 @@ const moveable = new Moveable(document.body, {
8686
resizable: true,
8787
scalable: true,
8888
rotatable: true,
89+
warpable: true,
8990
origin: true,
9091
keepRatio: true,
9192
throttleDrag: 0,
@@ -143,6 +144,32 @@ moveable.on("rotateStart", ({ target, clientX, clientY }) => {
143144
}).on("rotateEnd", ({ target, isDrag, clientX, clientY }) => {
144145
console.log("onRotateEnd", target, isDrag);
145146
});
147+
148+
/* warpable */
149+
this.matrix = [
150+
1, 0, 0, 0,
151+
0, 1, 0, 0,
152+
0, 0, 1, 0,
153+
0, 0, 0, 1,
154+
];
155+
moveable.on("warpStart", ({ target, clientX, clientY }) => {
156+
console.log("onWarpStart", target);
157+
}).on("warp", ({
158+
target,
159+
clientX,
160+
clientY,
161+
delta,
162+
dist,
163+
multiply,
164+
transform,
165+
}) => {
166+
console.log("onWarp", target);
167+
// target.style.transform = transform;
168+
this.matrix = multiply(this.matrix, delta);
169+
target.style.transform = `matrix3d(${this.matrix.join(",")})`;
170+
}).on("warpEnd", ({ target, isDrag, clientX, clientY }) => {
171+
console.log("onWarpEnd", target, isDrag);
172+
});
146173
```
147174

148175

package-lock.json

Lines changed: 51 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "moveable",
3-
"version": "0.3.0",
4-
"description": "Moveable is Draggable, Resizable, Scalable, Rotatable.",
3+
"version": "0.4.0",
4+
"description": "Moveable is Draggable, Resizable, Scalable, Rotatable, Warpable.",
55
"main": "./dist/moveable.cjs.js",
66
"module": "./dist/moveable.esm.js",
77
"sideEffects": false,
@@ -25,11 +25,13 @@
2525
"draggable",
2626
"rotatable",
2727
"movable",
28+
"warpable",
2829
"dom",
2930
"resize",
3031
"scale",
3132
"drag",
3233
"move",
34+
"warp",
3335
"rotate",
3436
"react",
3537
"preact",
@@ -46,11 +48,11 @@
4648
},
4749
"homepage": "https://github.com/daybrush/moveable#readme",
4850
"dependencies": {
49-
"@daybrush/drag": "^0.5.0",
51+
"@daybrush/drag": "^0.6.0",
5052
"@daybrush/utils": "^0.10.0",
5153
"@egjs/component": "^2.1.2",
5254
"framework-utils": "^0.1.0",
53-
"preact-moveable": "^0.5.2"
55+
"preact-moveable": "^0.6.1"
5456
},
5557
"devDependencies": {
5658
"@daybrush/builder": "^0.1.1",
@@ -64,6 +66,7 @@
6466
"print-sizes": "0.0.4",
6567
"rollup-plugin-css-bundle": "^1.0.4",
6668
"rollup-plugin-preact": "^0.4.1",
69+
"scenejs": "^1.1.4",
6770
"tslint": "^5.18.0",
6871
"typescript": "^3.5.2"
6972
}

src/Moveable.tsx

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { MoveableOptions } from "./types";
66
import {
77
OnDragStart, OnDrag, OnResize, OnResizeStart,
88
OnResizeEnd, OnScaleStart, OnScaleEnd, OnRotateStart,
9-
OnRotateEnd, OnDragEnd, OnRotate, OnScale,
9+
OnRotateEnd, OnDragEnd, OnRotate, OnScale, OnWarpStart, OnWarpEnd, OnWarp,
1010
} from "react-moveable/declaration/types";
1111

1212
/**
@@ -40,6 +40,9 @@ class Moveable extends EgComponent {
4040
onRotateStart={this.onRotateStart}
4141
onRotate={this.onRotate}
4242
onRotateEnd={this.onRotateEnd}
43+
onWarpStart={this.onWarpStart}
44+
onWarp={this.onWarp}
45+
onWarpEnd={this.onWarpEnd}
4346
/>,
4447
element,
4548
);
@@ -150,6 +153,23 @@ class Moveable extends EgComponent {
150153
rotatable,
151154
});
152155
}
156+
/**
157+
* Whether or not target can be warped.
158+
* @example
159+
* import Moveable from "moveable";
160+
*
161+
* const moveable = new Moveable(document.body);
162+
*
163+
* moveable.warpable = true;
164+
*/
165+
get warpable(): boolean {
166+
return this.getMoveableProps().warpable;
167+
}
168+
set warpable(warpable: boolean) {
169+
this.innerMoveable.setState({
170+
warpable,
171+
});
172+
}
153173
/**
154174
* When resize or scale, keeps a ratio of the width, height.
155175
* @example
@@ -266,7 +286,7 @@ class Moveable extends EgComponent {
266286
return this.getMoveable().isMoveableElement(target);
267287
}
268288
/**
269-
* If the width, height, left, and top of the target change, update the shape of the moveable.
289+
* If the width, height, left, and top of all elements change, update the shape of the moveable.
270290
* @example
271291
* import Moveable from "moveable";
272292
*
@@ -279,6 +299,19 @@ class Moveable extends EgComponent {
279299
public updateRect() {
280300
this.getMoveable().updateRect();
281301
}
302+
/**
303+
* If the width, height, left, and top of the only target change, update the shape of the moveable.
304+
* @param - the values of x and y to move moveable.
305+
* @example
306+
* import Moveable from "moveable";
307+
*
308+
* const moveable = new Moveable(document.body);
309+
*
310+
* moveable.updateTarget();
311+
*/
312+
public updateTarget(): void {
313+
this.getMoveable().updateTarget();
314+
}
282315
private getMoveable() {
283316
return this.innerMoveable.preactMoveable;
284317
}
@@ -321,6 +354,15 @@ class Moveable extends EgComponent {
321354
private onRotateEnd = (e: OnRotateEnd) => {
322355
this.trigger("rotateEnd", e);
323356
}
357+
private onWarpStart = (e: OnWarpStart) => {
358+
this.trigger("warpStart", e);
359+
}
360+
private onWarp = (e: OnWarp) => {
361+
this.trigger("warp", e);
362+
}
363+
private onWarpEnd = (e: OnWarpEnd) => {
364+
this.trigger("warpEnd", e);
365+
}
324366
}
325367

326368
/**
@@ -495,6 +537,9 @@ declare interface Moveable {
495537
on(eventName: "rotate", handlerToAttach: (event: OnRotate) => any): this;
496538
on(eventName: "rotateStart", handlerToAttach: (event: OnRotateStart) => any): this;
497539
on(eventName: "rotateEnd", handlerToAttach: (event: OnRotateEnd) => any): this;
540+
on(eventName: "warp", handlerToAttach: (event: OnWarp) => any): this;
541+
on(eventName: "warpStart", handlerToAttach: (event: OnWarpStart) => any): this;
542+
on(eventName: "warpEnd", handlerToAttach: (event: OnWarpEnd) => any): this;
498543
on(eventName: string, handlerToAttach: (event: { [key: string]: any }) => any): this;
499544
on(events: { [key: string]: (event: { [key: string]: any }) => any }): this;
500545
}

src/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* @property - Whether or not target can be resized.
66
* @property - Whether or not target can be scaled.
77
* @property - Whether or not target can be rotated.
8+
* @property - Whether or not target can be warped.
89
* @property - Whether or not the origin controlbox will be visible or not
910
* @property - The target to indicate Moveable Control Box.
1011
* @property - Moveable Container.
@@ -13,13 +14,13 @@
1314
* @property - throttle of scaleX, scaleY when scale.
1415
* @property - throttle of angle(degree) when rotate.
1516
* @property - When resize or scale, keeps a ratio of the width, height.
16-
1717
*/
1818
export interface MoveableOptions {
1919
draggable?: boolean;
2020
resizable?: boolean;
2121
scalable?: boolean;
2222
rotatable?: boolean;
23+
warpable?: boolean;
2324
origin?: boolean;
2425
target?: SVGElement | HTMLElement;
2526
container?: SVGElement | HTMLElement | null;

0 commit comments

Comments
 (0)