@leafer-ui/event 1.0.9 → 1.1.0

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.9",
3
+ "version": "1.1.0",
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.9"
25
+ "@leafer/core": "1.1.0"
26
26
  },
27
27
  "devDependencies": {
28
- "@leafer/interface": "1.0.9"
28
+ "@leafer/interface": "1.1.0"
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, BoundsHelper } from '@leafer/core'
2
+ import { registerUIEvent, LeafList, BoundsHelper, PointHelper } from '@leafer/core'
3
3
 
4
4
  import { PointerEvent } from './PointerEvent'
5
5
 
@@ -38,10 +38,9 @@ export class DragEvent extends PointerEvent implements IDragEvent {
38
38
  }
39
39
 
40
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
41
+ const { draggable, dragBounds } = leaf, move = leaf.getLocalPoint(total, null, true)
42
+ PointHelper.move(move, start.x - leaf.x, start.y - leaf.y)
43
+
45
44
  if (dragBounds) this.getMoveInDragBounds(leaf.__local, dragBounds === 'parent' ? leaf.parent.boxBounds : dragBounds, move, true)
46
45
  if (draggable === 'x') move.y = 0
47
46
  if (draggable === 'y') move.x = 0
@@ -49,8 +48,7 @@ export class DragEvent extends PointerEvent implements IDragEvent {
49
48
  }
50
49
 
51
50
  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
51
+ const x = childBox.x + move.x, y = childBox.y + move.y, right = x + childBox.width, bottom = y + childBox.height
54
52
  const boundsRight = dragBounds.x + dragBounds.width, boundsBottom = dragBounds.y + dragBounds.height
55
53
 
56
54
  if (!change) move = { ...move }
@@ -100,9 +98,7 @@ export class DragEvent extends PointerEvent implements IDragEvent {
100
98
  }
101
99
 
102
100
  public getPageBounds(): IBoundsData {
103
- const total = this.getPageTotal()
104
- const start = this.getPagePoint()
105
- const bounds = {} as IBoundsData
101
+ const total = this.getPageTotal(), start = this.getPagePoint(), bounds = {} as IBoundsData
106
102
  BoundsHelper.set(bounds, start.x - total.x, start.y - total.y, total.x, total.y)
107
103
  BoundsHelper.unsign(bounds)
108
104
  return bounds
package/src/UIEvent.ts CHANGED
@@ -34,18 +34,15 @@ export class UIEvent extends Event implements IUIEvent {
34
34
  }
35
35
 
36
36
  public getBoxPoint(relative?: ILeaf): IPointData {
37
- if (!relative) relative = this.current
38
- return relative.getBoxPoint(this)
37
+ return (relative || this.current).getBoxPoint(this)
39
38
  }
40
39
 
41
40
  public getInnerPoint(relative?: ILeaf): IPointData {
42
- if (!relative) relative = this.current
43
- return relative.getInnerPoint(this)
41
+ return (relative || this.current).getInnerPoint(this)
44
42
  }
45
43
 
46
44
  public getLocalPoint(relative?: ILeaf): IPointData {
47
- if (!relative) relative = this.current
48
- return relative.getLocalPoint(this)
45
+ return (relative || this.current).getLocalPoint(this)
49
46
  }
50
47
 
51
48
  public getPagePoint(): IPointData {
@@ -56,6 +53,7 @@ export class UIEvent extends Event implements IUIEvent {
56
53
  public getInner(relative?: ILeaf): IPointData { return this.getInnerPoint(relative) }
57
54
  public getLocal(relative?: ILeaf): IPointData { return this.getLocalPoint(relative) }
58
55
  public getPage(): IPointData { return this.getPagePoint() }
56
+ // ---
59
57
 
60
58
  static changeName(oldName: string, newName: string): void {
61
59
  EventCreator.changeName(oldName, newName)