@leafer-ui/interaction 1.8.0 → 1.9.1
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 +6 -6
- package/src/Dragger.ts +15 -7
- package/src/Interaction.ts +12 -2
- package/src/InteractionHelper.ts +3 -3
- package/types/index.d.ts +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-ui/interaction",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.1",
|
|
4
4
|
"description": "@leafer-ui/interaction",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,12 +22,12 @@
|
|
|
22
22
|
"leaferjs"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@leafer/core": "1.
|
|
26
|
-
"@leafer-ui/draw": "1.
|
|
27
|
-
"@leafer-ui/event": "1.
|
|
25
|
+
"@leafer/core": "1.9.1",
|
|
26
|
+
"@leafer-ui/draw": "1.9.1",
|
|
27
|
+
"@leafer-ui/event": "1.9.1"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@leafer/interface": "1.
|
|
31
|
-
"@leafer-ui/interface": "1.
|
|
30
|
+
"@leafer/interface": "1.9.1",
|
|
31
|
+
"@leafer-ui/interface": "1.9.1"
|
|
32
32
|
}
|
|
33
33
|
}
|
package/src/Dragger.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IPointerEvent, IDragEvent, ILeaf, ILeafList, ITimer, IFunction, IPointDataMap, IMoveEvent } from '@leafer/interface'
|
|
2
|
-
import { PointHelper, LeafList } from '@leafer/core'
|
|
2
|
+
import { PointHelper, LeafList, LeafHelper, isNumber } from '@leafer/core'
|
|
3
3
|
|
|
4
4
|
import { MoveEvent, DragEvent, DropEvent, PointerButton } from '@leafer-ui/event'
|
|
5
5
|
|
|
@@ -90,7 +90,7 @@ export class Dragger {
|
|
|
90
90
|
let leaf: ILeaf
|
|
91
91
|
for (let i = 0, len = path.length; i < len; i++) {
|
|
92
92
|
leaf = path.list[i]
|
|
93
|
-
if (
|
|
93
|
+
if (LeafHelper.draggable(leaf)) {
|
|
94
94
|
this.draggableList = new LeafList(leaf)
|
|
95
95
|
break
|
|
96
96
|
}
|
|
@@ -115,12 +115,19 @@ export class Dragger {
|
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
protected dragReal(): void {
|
|
119
|
-
const { running } =
|
|
118
|
+
protected dragReal(isDragEnd?: boolean): void {
|
|
119
|
+
const { interaction } = this, { running } = interaction
|
|
120
120
|
const list = this.realDraggableList
|
|
121
121
|
if (list.length && running) {
|
|
122
|
-
const { totalX, totalY } = this.dragData
|
|
123
|
-
|
|
122
|
+
const { totalX, totalY } = this.dragData, { dragLimitAnimate } = interaction.p
|
|
123
|
+
const checkLimitMove = !dragLimitAnimate || !!isDragEnd
|
|
124
|
+
list.forEach(leaf => {
|
|
125
|
+
if (leaf.draggable) {
|
|
126
|
+
const move = DragEvent.getValidMove(leaf, this.dragStartPoints[leaf.innerId], { x: totalX, y: totalY }, checkLimitMove)
|
|
127
|
+
if (dragLimitAnimate && isDragEnd) LeafHelper.animateMove(leaf, move, isNumber(dragLimitAnimate) ? dragLimitAnimate : 0.3)
|
|
128
|
+
else leaf.move(move)
|
|
129
|
+
}
|
|
130
|
+
})
|
|
124
131
|
}
|
|
125
132
|
}
|
|
126
133
|
|
|
@@ -172,6 +179,7 @@ export class Dragger {
|
|
|
172
179
|
const dropList = this.getList()
|
|
173
180
|
|
|
174
181
|
this.dragging = false
|
|
182
|
+
if (interaction.p.dragLimitAnimate) this.dragReal(true)
|
|
175
183
|
interaction.emit(DragEvent.END, endDragData)
|
|
176
184
|
|
|
177
185
|
this.swipe(data, downData, dragData, endDragData)
|
|
@@ -206,7 +214,7 @@ export class Dragger {
|
|
|
206
214
|
|
|
207
215
|
// @leafer-in/viewport will rewrite
|
|
208
216
|
|
|
209
|
-
public checkDragEndAnimate(_data: IPointerEvent, _speed?: number): boolean { return false }
|
|
217
|
+
public checkDragEndAnimate(_data: IPointerEvent, _speed?: number): boolean | number { return false }
|
|
210
218
|
|
|
211
219
|
public animate(_func?: IFunction, _off?: 'off'): void { } // dragEnd animation
|
|
212
220
|
|
package/src/Interaction.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IUIEvent, IPointerEvent, ILeaf, IInteraction, IInteractionConfig, ITransformer, ILeafList, IMoveEvent, IZoomEvent, IRotateEvent, IWheelEvent, ISelector, IBounds, IEventListenerId, IInteractionCanvas, ITimer, IKeepTouchData, IKeyEvent, IPickOptions, ICursorType, IBooleanMap, IPickBottom, IClientPointData, IPointData, ILeaferConfig, IMoveConfig, IPointerConfig } from '@leafer/interface'
|
|
2
|
-
import { LeaferEvent, ResizeEvent, LeafList, Bounds, PointHelper, DataHelper, Platform } from '@leafer/core'
|
|
2
|
+
import { LeaferEvent, ResizeEvent, LeafList, Bounds, PointHelper, DataHelper, Platform, isNumber } from '@leafer/core'
|
|
3
3
|
|
|
4
4
|
import { IApp } from '@leafer-ui/interface'
|
|
5
5
|
import { PointerEvent, DropEvent, KeyEvent, PointerButton, Keyboard } from '@leafer-ui/event'
|
|
@@ -237,6 +237,8 @@ export class InteractionBase implements IInteraction {
|
|
|
237
237
|
public keyDown(data: IKeyEvent): void {
|
|
238
238
|
if (!this.config.keyEvent) return
|
|
239
239
|
|
|
240
|
+
this.emit(KeyEvent.BEFORE_DOWN, data, this.defaultPath) // 键盘按下前出发,还没有setDownCode
|
|
241
|
+
|
|
240
242
|
const { code } = data
|
|
241
243
|
if (!this.downKeyMap[code]) {
|
|
242
244
|
this.downKeyMap[code] = true
|
|
@@ -254,6 +256,8 @@ export class InteractionBase implements IInteraction {
|
|
|
254
256
|
public keyUp(data: IKeyEvent): void {
|
|
255
257
|
if (!this.config.keyEvent) return
|
|
256
258
|
|
|
259
|
+
this.emit(KeyEvent.BEFORE_UP, data, this.defaultPath) // 键盘弹起前出发,还没有setUpCode
|
|
260
|
+
|
|
257
261
|
const { code } = data
|
|
258
262
|
this.downKeyMap[code] = false
|
|
259
263
|
Keyboard.setUpCode(code)
|
|
@@ -455,6 +459,12 @@ export class InteractionBase implements IInteraction {
|
|
|
455
459
|
public getLocal(clientPoint: IClientPointData, updateClient?: boolean): IPointData {
|
|
456
460
|
const clientBounds = this.canvas.getClientBounds(updateClient)
|
|
457
461
|
const point = { x: clientPoint.clientX - clientBounds.x, y: clientPoint.clientY - clientBounds.y }
|
|
462
|
+
|
|
463
|
+
// 兼容clientBounds进行了transform的情况
|
|
464
|
+
const { bounds } = this.canvas
|
|
465
|
+
point.x *= bounds.width / clientBounds.width
|
|
466
|
+
point.y *= bounds.height / clientBounds.height
|
|
467
|
+
|
|
458
468
|
if (this.p.snap) PointHelper.round(point)
|
|
459
469
|
return point
|
|
460
470
|
}
|
|
@@ -516,7 +526,7 @@ export class InteractionBase implements IInteraction {
|
|
|
516
526
|
protected __onResize(): void {
|
|
517
527
|
const { dragOut } = this.m
|
|
518
528
|
this.shrinkCanvasBounds = new Bounds(this.canvas.bounds)
|
|
519
|
-
this.shrinkCanvasBounds.spread(-(
|
|
529
|
+
this.shrinkCanvasBounds.spread(-(isNumber(dragOut) ? dragOut : 2))
|
|
520
530
|
}
|
|
521
531
|
|
|
522
532
|
protected __listenEvents(): void {
|
package/src/InteractionHelper.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IPointerEvent, IDragEvent, ISwipeEvent, IUIEvent, IPointData, ILeafList, IDropEvent, IObject } from '@leafer/interface'
|
|
2
|
-
import { PointHelper, LeafList } from '@leafer/core'
|
|
2
|
+
import { PointHelper, LeafList, isUndefined, LeafHelper } from '@leafer/core'
|
|
3
3
|
|
|
4
4
|
import { SwipeEvent, DragEvent } from '@leafer-ui/event'
|
|
5
5
|
|
|
@@ -52,7 +52,7 @@ export const InteractionHelper = {
|
|
|
52
52
|
ctrlKey: e.ctrlKey,
|
|
53
53
|
shiftKey: e.shiftKey,
|
|
54
54
|
metaKey: e.metaKey,
|
|
55
|
-
buttons: e.buttons
|
|
55
|
+
buttons: isUndefined(e.buttons) ? 1 : (e.buttons === 0 ? pointerUpButtons : e.buttons), // touchEvent no button and buttons, set default
|
|
56
56
|
origin: e
|
|
57
57
|
} as IUIEvent
|
|
58
58
|
},
|
|
@@ -75,7 +75,7 @@ export const InteractionHelper = {
|
|
|
75
75
|
},
|
|
76
76
|
|
|
77
77
|
pathCanDrag(path: ILeafList): boolean {
|
|
78
|
-
return path && path.list.some(item =>
|
|
78
|
+
return path && path.list.some(item => LeafHelper.draggable(item) || (!item.isLeafer && item.hasEvent(DragEvent.DRAG)))
|
|
79
79
|
},
|
|
80
80
|
|
|
81
81
|
pathHasOutside(path: ILeafList): boolean { // 滚动条元素
|
package/types/index.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ declare class Dragger {
|
|
|
24
24
|
protected setDragStartPoints(list: ILeafList | ILeaf[]): void;
|
|
25
25
|
protected getDraggableList(path: ILeafList): void;
|
|
26
26
|
drag(data: IPointerEvent): void;
|
|
27
|
-
protected dragReal(): void;
|
|
27
|
+
protected dragReal(isDragEnd?: boolean): void;
|
|
28
28
|
dragOverOrOut(data: IPointerEvent): void;
|
|
29
29
|
dragEnterOrLeave(data: IPointerEvent): void;
|
|
30
30
|
dragEnd(data: IPointerEvent, speed?: number): void;
|
|
@@ -32,7 +32,7 @@ declare class Dragger {
|
|
|
32
32
|
protected swipe(data: IPointerEvent, downData: IPointerEvent, dragData: IDragEvent, endDragData: IDragEvent): void;
|
|
33
33
|
protected drop(data: IPointerEvent, dropList: ILeafList, dragEnterPath: ILeafList): void;
|
|
34
34
|
protected dragReset(): void;
|
|
35
|
-
checkDragEndAnimate(_data: IPointerEvent, _speed?: number): boolean;
|
|
35
|
+
checkDragEndAnimate(_data: IPointerEvent, _speed?: number): boolean | number;
|
|
36
36
|
animate(_func?: IFunction, _off?: 'off'): void;
|
|
37
37
|
checkDragOut(_data: IPointerEvent): void;
|
|
38
38
|
autoMoveOnDragOut(_data: IPointerEvent): void;
|