@leafer-ui/interaction 1.0.0-rc.18 → 1.0.0-rc.19
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 +5 -5
- package/src/Dragger.ts +1 -1
- package/src/Interaction.ts +37 -37
- package/types/index.d.ts +4 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-ui/interaction",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.19",
|
|
4
4
|
"description": "@leafer-ui/interaction",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,11 +22,11 @@
|
|
|
22
22
|
"leaferjs"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@leafer/core": "1.0.0-rc.
|
|
26
|
-
"@leafer-ui/draw": "1.0.0-rc.
|
|
27
|
-
"@leafer-ui/event": "1.0.0-rc.
|
|
25
|
+
"@leafer/core": "1.0.0-rc.19",
|
|
26
|
+
"@leafer-ui/draw": "1.0.0-rc.19",
|
|
27
|
+
"@leafer-ui/event": "1.0.0-rc.19"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@leafer/interface": "1.0.0-rc.
|
|
30
|
+
"@leafer/interface": "1.0.0-rc.19"
|
|
31
31
|
}
|
|
32
32
|
}
|
package/src/Dragger.ts
CHANGED
|
@@ -56,7 +56,7 @@ export class Dragger {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
if (!this.moving && canDrag) {
|
|
59
|
-
if (this.moving = interaction.
|
|
59
|
+
if (this.moving = interaction.canMove(this.downData) || interaction.isHoldRightKey) interaction.emit(MoveEvent.START, this.dragData)
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
if (!this.moving) {
|
package/src/Interaction.ts
CHANGED
|
@@ -21,7 +21,7 @@ export class InteractionBase implements IInteraction {
|
|
|
21
21
|
public running: boolean
|
|
22
22
|
|
|
23
23
|
public get dragging(): boolean { return this.dragger.dragging }
|
|
24
|
-
public get isDragEmpty(): boolean { return this.config.move.dragEmpty &&
|
|
24
|
+
public get isDragEmpty(): boolean { return this.config.move.dragEmpty && this.isRootPath(this.hoverData) && (!this.downData || this.isRootPath(this.downData)) }
|
|
25
25
|
public get isHoldRightKey(): boolean { return this.config.move.holdRightKey && this.downData && PointerButton.right(this.downData) }
|
|
26
26
|
public get moveMode(): boolean { return this.config.move.drag || (this.config.move.holdSpaceKey && Keyboard.isHoldSpaceKey()) || (this.downData && ((this.config.move.holdMiddleKey && PointerButton.middle(this.downData)) || (this.isHoldRightKey && this.dragger.moving))) || this.isDragEmpty }
|
|
27
27
|
|
|
@@ -33,12 +33,10 @@ export class InteractionBase implements IInteraction {
|
|
|
33
33
|
public shrinkCanvasBounds: IBounds
|
|
34
34
|
|
|
35
35
|
public downData: IPointerEvent
|
|
36
|
-
protected oldDownData?: IPointerEvent // 通过updateDownData强制更新下来的数据
|
|
37
36
|
public hoverData: IPointerEvent
|
|
38
37
|
public focusData: ILeaf
|
|
39
38
|
|
|
40
39
|
public downTime: number
|
|
41
|
-
protected downed: boolean
|
|
42
40
|
|
|
43
41
|
protected overPath: LeafList
|
|
44
42
|
protected enterPath: LeafList
|
|
@@ -90,20 +88,18 @@ export class InteractionBase implements IInteraction {
|
|
|
90
88
|
PointerButton.defaultLeft(data)
|
|
91
89
|
|
|
92
90
|
this.updateDownData(data)
|
|
93
|
-
|
|
91
|
+
this.checkPath(data, useDefaultPath)
|
|
94
92
|
|
|
95
93
|
this.downTime = Date.now()
|
|
96
94
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
this.emit(PointerEvent.DOWN, data)
|
|
95
|
+
this.emit(PointerEvent.BEFORE_DOWN, data) // downData maybe changed
|
|
96
|
+
this.emit(PointerEvent.DOWN, data)
|
|
100
97
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
98
|
+
if (PointerButton.left(data)) {
|
|
99
|
+
this.tapWait()
|
|
100
|
+
this.longPressWait(data)
|
|
101
|
+
} else if (PointerButton.right(data)) {
|
|
102
|
+
this.waitMenuTap = true
|
|
107
103
|
}
|
|
108
104
|
|
|
109
105
|
this.dragger.setDragData(data) // must after down event
|
|
@@ -119,10 +115,6 @@ export class InteractionBase implements IInteraction {
|
|
|
119
115
|
|
|
120
116
|
const hit = this.canvas.bounds.hitPoint(data)
|
|
121
117
|
if (hit || downData) {
|
|
122
|
-
if (hit && !downData && PointerButton.left(data)) {
|
|
123
|
-
this.pointerDown(data, true) // 从外部拖拽内容进入,需要先模拟down事件
|
|
124
|
-
this.dragger.canDragOut = false
|
|
125
|
-
}
|
|
126
118
|
this.pointerMoveReal(data)
|
|
127
119
|
if (downData) this.dragger.checkDragOut(data)
|
|
128
120
|
}
|
|
@@ -143,7 +135,7 @@ export class InteractionBase implements IInteraction {
|
|
|
143
135
|
|
|
144
136
|
if (!this.dragger.moving) {
|
|
145
137
|
this.updateHoverData(data)
|
|
146
|
-
|
|
138
|
+
this.checkPath(data)
|
|
147
139
|
|
|
148
140
|
this.emit(PointerEvent.MOVE, data)
|
|
149
141
|
|
|
@@ -159,30 +151,27 @@ export class InteractionBase implements IInteraction {
|
|
|
159
151
|
}
|
|
160
152
|
|
|
161
153
|
public pointerUp(data?: IPointerEvent): void {
|
|
162
|
-
const { downData
|
|
154
|
+
const { downData } = this
|
|
163
155
|
if (!data) data = downData
|
|
164
156
|
if (!downData) return
|
|
157
|
+
|
|
165
158
|
PointerButton.defaultLeft(data)
|
|
159
|
+
this.downData = null // must before pointer.up event
|
|
166
160
|
|
|
167
161
|
this.findPath(data)
|
|
162
|
+
data.path.addList(downData.path.list) // downPath必须触发
|
|
163
|
+
this.checkPath(data)
|
|
168
164
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
this.emit(PointerEvent.BEFORE_UP, data)
|
|
172
|
-
this.emit(PointerEvent.UP, data)
|
|
173
|
-
if (oldDownData) this.emit(PointerEvent.UP, oldDownData, undefined, data.path) // oldDownPath必须触发up
|
|
174
|
-
this.emit(PointerEvent.UP, downData, undefined, data.path) // downPath必须触发up
|
|
165
|
+
this.emit(PointerEvent.BEFORE_UP, data)
|
|
166
|
+
this.emit(PointerEvent.UP, data)
|
|
175
167
|
|
|
176
|
-
|
|
168
|
+
this.touchLeave(data)
|
|
177
169
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}
|
|
170
|
+
this.tap(data)
|
|
171
|
+
this.menuTap(data)
|
|
181
172
|
|
|
182
173
|
this.dragger.dragEnd(data)
|
|
183
174
|
|
|
184
|
-
this.downData = this.oldDownData = null
|
|
185
|
-
|
|
186
175
|
this.updateCursor(data)
|
|
187
176
|
}
|
|
188
177
|
|
|
@@ -348,14 +337,25 @@ export class InteractionBase implements IInteraction {
|
|
|
348
337
|
return find.path
|
|
349
338
|
}
|
|
350
339
|
|
|
340
|
+
public isRootPath(data: IPointerEvent): boolean {
|
|
341
|
+
return data && (data.path.list[0] as ILeaf).isLeafer
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
protected checkPath(data: IPointerEvent, useDefaultPath?: boolean): void {
|
|
345
|
+
if (useDefaultPath || this.canMove(data)) data.path = this.defaultPath
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
public canMove(data: IPointerEvent): boolean { // moveMode and path can move
|
|
349
|
+
return this.moveMode && data && data.path.list.every(item => !item.isOutside)
|
|
350
|
+
}
|
|
351
|
+
|
|
351
352
|
|
|
352
353
|
public isDrag(leaf: ILeaf): boolean {
|
|
353
354
|
return this.dragger.getList().has(leaf)
|
|
354
355
|
}
|
|
355
356
|
|
|
356
357
|
public isPress(leaf: ILeaf): boolean {
|
|
357
|
-
|
|
358
|
-
return this.downed && ((downData && downData.path.has(leaf)) || (oldDownData && oldDownData.path.has(leaf)))
|
|
358
|
+
return this.downData && this.downData.path.has(leaf)
|
|
359
359
|
}
|
|
360
360
|
|
|
361
361
|
public isHover(leaf: ILeaf): boolean {
|
|
@@ -376,12 +376,12 @@ export class InteractionBase implements IInteraction {
|
|
|
376
376
|
}
|
|
377
377
|
|
|
378
378
|
|
|
379
|
-
public updateDownData(data?: IPointerEvent, options?: IPickOptions): void {
|
|
379
|
+
public updateDownData(data?: IPointerEvent, options?: IPickOptions, merge?: boolean): void {
|
|
380
380
|
const { downData } = this
|
|
381
|
-
if (!data && downData) data =
|
|
381
|
+
if (!data && downData) data = downData
|
|
382
382
|
if (!data) return
|
|
383
|
-
this.oldDownData = downData
|
|
384
383
|
this.findPath(data, options)
|
|
384
|
+
if (merge && downData) data.path.addList(downData.path.list)
|
|
385
385
|
this.downData = data
|
|
386
386
|
}
|
|
387
387
|
|
|
@@ -402,7 +402,7 @@ export class InteractionBase implements IInteraction {
|
|
|
402
402
|
|
|
403
403
|
if (this.dragger.moving) {
|
|
404
404
|
return this.setCursor('grabbing')
|
|
405
|
-
} else if (this.
|
|
405
|
+
} else if (this.canMove(data)) {
|
|
406
406
|
return this.setCursor(this.downData ? 'grabbing' : 'grab')
|
|
407
407
|
} else if (!data) return
|
|
408
408
|
|
package/types/index.d.ts
CHANGED
|
@@ -68,11 +68,9 @@ declare class InteractionBase implements IInteraction {
|
|
|
68
68
|
get hitRadius(): number;
|
|
69
69
|
shrinkCanvasBounds: IBounds;
|
|
70
70
|
downData: IPointerEvent;
|
|
71
|
-
protected oldDownData?: IPointerEvent;
|
|
72
71
|
hoverData: IPointerEvent;
|
|
73
72
|
focusData: ILeaf;
|
|
74
73
|
downTime: number;
|
|
75
|
-
protected downed: boolean;
|
|
76
74
|
protected overPath: LeafList;
|
|
77
75
|
protected enterPath: LeafList;
|
|
78
76
|
protected waitMenuTap: boolean;
|
|
@@ -110,12 +108,15 @@ declare class InteractionBase implements IInteraction {
|
|
|
110
108
|
protected touchLeave(data: IPointerEvent): void;
|
|
111
109
|
protected tap(data: IPointerEvent): void;
|
|
112
110
|
findPath(data: IPointerEvent, options?: IPickOptions): ILeafList;
|
|
111
|
+
isRootPath(data: IPointerEvent): boolean;
|
|
112
|
+
protected checkPath(data: IPointerEvent, useDefaultPath?: boolean): void;
|
|
113
|
+
canMove(data: IPointerEvent): boolean;
|
|
113
114
|
isDrag(leaf: ILeaf): boolean;
|
|
114
115
|
isPress(leaf: ILeaf): boolean;
|
|
115
116
|
isHover(leaf: ILeaf): boolean;
|
|
116
117
|
isFocus(leaf: ILeaf): boolean;
|
|
117
118
|
cancelHover(): void;
|
|
118
|
-
updateDownData(data?: IPointerEvent, options?: IPickOptions): void;
|
|
119
|
+
updateDownData(data?: IPointerEvent, options?: IPickOptions, merge?: boolean): void;
|
|
119
120
|
updateHoverData(data?: IPointerEvent): void;
|
|
120
121
|
updateCursor(data?: IPointerEvent): void;
|
|
121
122
|
setCursor(cursor: ICursorType | ICursorType[]): void;
|