@leafer-ui/event 1.0.0-rc.21 → 1.0.0-rc.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/DragEvent.ts +25 -1
- package/types/index.d.ts +3 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-ui/event",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.22",
|
|
4
4
|
"description": "@leafer-ui/event",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
"leaferjs"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@leafer/core": "1.0.0-rc.
|
|
25
|
+
"@leafer/core": "1.0.0-rc.22"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@leafer/interface": "1.0.0-rc.
|
|
28
|
+
"@leafer/interface": "1.0.0-rc.22"
|
|
29
29
|
}
|
|
30
30
|
}
|
package/src/DragEvent.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IDragEvent, IPointData, ILeaf, ILeafList, IObject } from '@leafer/interface'
|
|
1
|
+
import { IDragEvent, IPointData, ILeaf, ILeafList, IObject, IBoundsData } from '@leafer/interface'
|
|
2
2
|
import { registerUIEvent, LeafList } from '@leafer/core'
|
|
3
3
|
|
|
4
4
|
import { PointerEvent } from './PointerEvent'
|
|
@@ -36,6 +36,30 @@ export class DragEvent extends PointerEvent implements IDragEvent {
|
|
|
36
36
|
static setData(data: IObject): void {
|
|
37
37
|
this.data = data
|
|
38
38
|
}
|
|
39
|
+
|
|
40
|
+
static getValidMove(leaf: ILeaf, start: IPointData, total: IPointData): IPointData {
|
|
41
|
+
const { draggable, dragBounds, x, y } = leaf
|
|
42
|
+
const move = leaf.getLocalPoint(total, null, true)
|
|
43
|
+
move.x += start.x - x
|
|
44
|
+
move.y += start.y - y
|
|
45
|
+
if (dragBounds) this.getMoveInDragBounds(leaf.__local, dragBounds === 'parent' ? leaf.parent.boxBounds : dragBounds, move, true)
|
|
46
|
+
if (draggable === 'x') move.y = 0
|
|
47
|
+
if (draggable === 'y') move.x = 0
|
|
48
|
+
return move
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
static getMoveInDragBounds(box: IBoundsData, dragBounds: IBoundsData, move: IPointData, change?: boolean): IPointData {
|
|
52
|
+
const x = box.x + move.x, y = box.y + move.y
|
|
53
|
+
const right = x + box.width, bottom = y + box.height
|
|
54
|
+
const boundsRight = dragBounds.x + dragBounds.width, boundsBottom = dragBounds.y + dragBounds.height
|
|
55
|
+
if (!change) move = { ...move }
|
|
56
|
+
if (x < dragBounds.x) move.x += dragBounds.x - x
|
|
57
|
+
else if (right > boundsRight) move.x += boundsRight - right
|
|
58
|
+
if (y < dragBounds.y) move.y += dragBounds.y - y
|
|
59
|
+
else if (bottom > boundsBottom) move.y += boundsBottom - bottom
|
|
60
|
+
return move
|
|
61
|
+
}
|
|
62
|
+
|
|
39
63
|
public getPageMove(total?: boolean): IPointData {
|
|
40
64
|
this.assignMove(total)
|
|
41
65
|
return this.current.getPagePoint(move, null, true)
|
package/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IUIEvent, ILeafList, ILeaf, IPointData, IPointerEvent, PointerType, IDragEvent, IObject, IDropEvent, IMoveEvent, IRotateEvent, ISwipeEvent, IZoomEvent, IKeyEvent } from '@leafer/interface';
|
|
1
|
+
import { IUIEvent, ILeafList, ILeaf, IPointData, IPointerEvent, PointerType, IDragEvent, IObject, IBoundsData, IDropEvent, IMoveEvent, IRotateEvent, ISwipeEvent, IZoomEvent, IKeyEvent } from '@leafer/interface';
|
|
2
2
|
import { Event } from '@leafer/core';
|
|
3
3
|
|
|
4
4
|
declare class UIEvent extends Event implements IUIEvent {
|
|
@@ -72,6 +72,8 @@ declare class DragEvent extends PointerEvent implements IDragEvent {
|
|
|
72
72
|
static data: IObject;
|
|
73
73
|
static setList(data: ILeaf | ILeaf[] | ILeafList): void;
|
|
74
74
|
static setData(data: IObject): void;
|
|
75
|
+
static getValidMove(leaf: ILeaf, start: IPointData, total: IPointData): IPointData;
|
|
76
|
+
static getMoveInDragBounds(box: IBoundsData, dragBounds: IBoundsData, move: IPointData, change?: boolean): IPointData;
|
|
75
77
|
getPageMove(total?: boolean): IPointData;
|
|
76
78
|
getInnerMove(relative?: ILeaf, total?: boolean): IPointData;
|
|
77
79
|
getLocalMove(relative?: ILeaf, total?: boolean): IPointData;
|