@leafer-ui/event 1.0.0-rc.25 → 1.0.0-rc.27

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer-ui/event",
3
- "version": "1.0.0-rc.25",
3
+ "version": "1.0.0-rc.27",
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"
25
+ "@leafer/core": "1.0.0-rc.27"
26
26
  },
27
27
  "devDependencies": {
28
- "@leafer/interface": "1.0.0-rc.25"
28
+ "@leafer/interface": "1.0.0-rc.27"
29
29
  }
30
30
  }
package/src/DragEvent.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { IDragEvent, IPointData, ILeaf, ILeafList, IObject, IBoundsData } from '@leafer/interface'
2
- import { registerUIEvent, LeafList } from '@leafer/core'
2
+ import { registerUIEvent, LeafList, BoundsHelper } from '@leafer/core'
3
3
 
4
4
  import { PointerEvent } from './PointerEvent'
5
5
 
@@ -48,15 +48,25 @@ export class DragEvent extends PointerEvent implements IDragEvent {
48
48
  return move
49
49
  }
50
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
51
+ static getMoveInDragBounds(childBox: IBoundsData, dragBounds: IBoundsData, move: IPointData, change?: boolean): IPointData {
52
+ const x = childBox.x + move.x, y = childBox.y + move.y
53
+ const right = x + childBox.width, bottom = y + childBox.height
54
54
  const boundsRight = dragBounds.x + dragBounds.width, boundsBottom = dragBounds.y + dragBounds.height
55
+
55
56
  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
57
+
58
+ if (BoundsHelper.includes(childBox, dragBounds)) { // childBox > dragBounds
59
+ if (x > dragBounds.x) move.x += dragBounds.x - x
60
+ else if (right < boundsRight) move.x += boundsRight - right
61
+ if (y > dragBounds.y) move.y += dragBounds.y - y
62
+ else if (bottom < boundsBottom) move.y += boundsBottom - bottom
63
+ } else {
64
+ if (x < dragBounds.x) move.x += dragBounds.x - x
65
+ else if (right > boundsRight) move.x += boundsRight - right
66
+ if (y < dragBounds.y) move.y += dragBounds.y - y
67
+ else if (bottom > boundsBottom) move.y += boundsBottom - bottom
68
+ }
69
+
60
70
  return move
61
71
  }
62
72
 
@@ -89,6 +99,15 @@ export class DragEvent extends PointerEvent implements IDragEvent {
89
99
  return this.getLocalMove(relative, true)
90
100
  }
91
101
 
102
+ public getPageBounds(): IBoundsData {
103
+ const total = this.getPageTotal()
104
+ const start = this.getPage()
105
+ const bounds = {} as IBoundsData
106
+ BoundsHelper.set(bounds, start.x - total.x, start.y - total.y, total.x, total.y)
107
+ BoundsHelper.unsign(bounds)
108
+ return bounds
109
+ }
110
+
92
111
  protected assignMove(total: boolean): void {
93
112
  move.x = total ? this.totalX : this.moveX
94
113
  move.y = total ? this.totalY : this.moveY
package/types/index.d.ts CHANGED
@@ -73,13 +73,14 @@ declare class DragEvent extends PointerEvent implements IDragEvent {
73
73
  static setList(data: ILeaf | ILeaf[] | ILeafList): void;
74
74
  static setData(data: IObject): void;
75
75
  static getValidMove(leaf: ILeaf, start: IPointData, total: IPointData): IPointData;
76
- static getMoveInDragBounds(box: IBoundsData, dragBounds: IBoundsData, move: IPointData, change?: boolean): IPointData;
76
+ static getMoveInDragBounds(childBox: IBoundsData, dragBounds: IBoundsData, move: IPointData, change?: boolean): IPointData;
77
77
  getPageMove(total?: boolean): IPointData;
78
78
  getInnerMove(relative?: ILeaf, total?: boolean): IPointData;
79
79
  getLocalMove(relative?: ILeaf, total?: boolean): IPointData;
80
80
  getPageTotal(): IPointData;
81
81
  getInnerTotal(relative?: ILeaf): IPointData;
82
82
  getLocalTotal(relative?: ILeaf): IPointData;
83
+ getPageBounds(): IBoundsData;
83
84
  protected assignMove(total: boolean): void;
84
85
  }
85
86