@leafer-ui/interaction 1.0.1 → 1.0.3
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/Interaction.ts +14 -9
- package/src/InteractionHelper.ts +10 -2
- package/src/config.ts +3 -0
- package/src/emit.ts +1 -1
- package/types/index.d.ts +3 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-ui/interaction",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
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.0.
|
|
26
|
-
"@leafer-ui/draw": "1.0.
|
|
27
|
-
"@leafer-ui/event": "1.0.
|
|
25
|
+
"@leafer/core": "1.0.3",
|
|
26
|
+
"@leafer-ui/draw": "1.0.3",
|
|
27
|
+
"@leafer-ui/event": "1.0.3"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@leafer/interface": "1.0.
|
|
31
|
-
"@leafer-ui/interface": "1.0.
|
|
30
|
+
"@leafer/interface": "1.0.3",
|
|
31
|
+
"@leafer-ui/interface": "1.0.3"
|
|
32
32
|
}
|
|
33
33
|
}
|
package/src/Interaction.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { MultiTouchHelper } from './MultiTouchHelper'
|
|
|
12
12
|
import { config } from './config'
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
const { pathHasEventType, getMoveEventData, getZoomEventData, getRotateEventData } = InteractionHelper
|
|
15
|
+
const { pathHasEventType, getMoveEventData, getZoomEventData, getRotateEventData, pathCanDrag, pathHasOutside } = InteractionHelper
|
|
16
16
|
export class InteractionBase implements IInteraction {
|
|
17
17
|
|
|
18
18
|
public target: ILeaf
|
|
@@ -24,7 +24,7 @@ export class InteractionBase implements IInteraction {
|
|
|
24
24
|
public get dragging(): boolean { return this.dragger.dragging }
|
|
25
25
|
public get transforming(): boolean { return this.transformer.transforming }
|
|
26
26
|
|
|
27
|
-
public get moveMode(): boolean { return this.config.move.drag || this.isHoldSpaceKey || this.isHoldMiddleKey || (this.isHoldRightKey && this.dragger.moving) || this.isDragEmpty }
|
|
27
|
+
public get moveMode(): boolean { return this.config.move.drag === true || this.isHoldSpaceKey || this.isHoldMiddleKey || (this.isHoldRightKey && this.dragger.moving) || this.isDragEmpty }
|
|
28
28
|
public get canHover(): boolean { return this.config.pointer.hover && !(this.config as ILeaferConfig).mobile }
|
|
29
29
|
|
|
30
30
|
public get isDragEmpty(): boolean { return this.config.move.dragEmpty && this.isRootPath(this.hoverData) && (!this.downData || this.isRootPath(this.downData)) }
|
|
@@ -33,7 +33,7 @@ export class InteractionBase implements IInteraction {
|
|
|
33
33
|
public get isHoldRightKey(): boolean { return this.config.move.holdRightKey && this.downData && PointerButton.right(this.downData) }
|
|
34
34
|
public get isHoldSpaceKey(): boolean { return this.config.move.holdSpaceKey && Keyboard.isHoldSpaceKey() }
|
|
35
35
|
|
|
36
|
-
public config: IInteractionConfig = config
|
|
36
|
+
public config: IInteractionConfig = DataHelper.clone(config)
|
|
37
37
|
|
|
38
38
|
public cursor: ICursorType | ICursorType[]
|
|
39
39
|
public get hitRadius(): number { return this.config.pointer.hitRadius }
|
|
@@ -52,6 +52,7 @@ export class InteractionBase implements IInteraction {
|
|
|
52
52
|
protected enterPath: LeafList
|
|
53
53
|
|
|
54
54
|
protected waitMenuTap: boolean
|
|
55
|
+
protected waitRightTap: boolean
|
|
55
56
|
protected waitTap: boolean
|
|
56
57
|
protected longPressTimer: ITimer
|
|
57
58
|
protected longPressed: boolean
|
|
@@ -110,7 +111,7 @@ export class InteractionBase implements IInteraction {
|
|
|
110
111
|
this.longPressWait(data)
|
|
111
112
|
}
|
|
112
113
|
|
|
113
|
-
this.
|
|
114
|
+
this.waitRightTap = PointerButton.right(data)
|
|
114
115
|
|
|
115
116
|
this.dragger.setDragData(data) // must after down event
|
|
116
117
|
if (!this.isHoldRightKey) this.updateCursor(data)
|
|
@@ -138,7 +139,7 @@ export class InteractionBase implements IInteraction {
|
|
|
138
139
|
const canDrag = PointHelper.getDistance(this.downData, data) > dragDistance
|
|
139
140
|
if (canDrag) {
|
|
140
141
|
if (this.waitTap) this.pointerWaitCancel()
|
|
141
|
-
this.
|
|
142
|
+
this.waitRightTap = false
|
|
142
143
|
}
|
|
143
144
|
|
|
144
145
|
this.dragger.checkDrag(data, canDrag)
|
|
@@ -207,14 +208,18 @@ export class InteractionBase implements IInteraction {
|
|
|
207
208
|
}
|
|
208
209
|
|
|
209
210
|
// context menu
|
|
210
|
-
|
|
211
211
|
public menu(data: IPointerEvent): void {
|
|
212
212
|
this.findPath(data)
|
|
213
213
|
this.emit(PointerEvent.MENU, data)
|
|
214
|
+
this.waitMenuTap = true
|
|
215
|
+
if (!this.downData && this.waitRightTap) this.menuTap(data) // fix: Windows 触摸屏双击右键菜单事件会在pointer.up之后触发
|
|
214
216
|
}
|
|
215
217
|
|
|
216
218
|
public menuTap(data: IPointerEvent): void {
|
|
217
|
-
if (this.
|
|
219
|
+
if (this.waitRightTap && this.waitMenuTap) {
|
|
220
|
+
this.emit(PointerEvent.MENU_TAP, data)
|
|
221
|
+
this.waitRightTap = this.waitMenuTap = false
|
|
222
|
+
}
|
|
218
223
|
}
|
|
219
224
|
|
|
220
225
|
// window transform
|
|
@@ -374,11 +379,11 @@ export class InteractionBase implements IInteraction {
|
|
|
374
379
|
}
|
|
375
380
|
|
|
376
381
|
protected checkPath(data: IPointerEvent, useDefaultPath?: boolean): void {
|
|
377
|
-
if (useDefaultPath || this.
|
|
382
|
+
if (useDefaultPath || (this.moveMode && !pathHasOutside(data.path))) data.path = this.defaultPath
|
|
378
383
|
}
|
|
379
384
|
|
|
380
385
|
public canMove(data: IPointerEvent): boolean { // moveMode and path can move
|
|
381
|
-
return this.moveMode
|
|
386
|
+
return data && (this.moveMode || (this.config.move.drag === 'auto' && !pathCanDrag(data.path))) && !pathHasOutside(data.path)
|
|
382
387
|
}
|
|
383
388
|
|
|
384
389
|
|
package/src/InteractionHelper.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { IEvent, IPointerEvent, IMoveEvent, IZoomEvent, IRotateEvent, IDragEvent, ISwipeEvent, IUIEvent, IPointData, ILeafList, IDropEvent, IObject } from '@leafer/interface'
|
|
2
2
|
import { PointHelper, LeafList } from '@leafer/core'
|
|
3
3
|
|
|
4
|
-
import { SwipeEvent } from '@leafer-ui/event'
|
|
4
|
+
import { SwipeEvent, DragEvent } from '@leafer-ui/event'
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
export const InteractionHelper = {
|
|
@@ -105,7 +105,15 @@ export const InteractionHelper = {
|
|
|
105
105
|
if (list[i].hasEvent(type)) find.add(list[i])
|
|
106
106
|
}
|
|
107
107
|
return find
|
|
108
|
-
}
|
|
108
|
+
},
|
|
109
|
+
|
|
110
|
+
pathCanDrag(path: ILeafList): boolean {
|
|
111
|
+
return path && path.list.some(item => item.draggable || item.editable || (!item.isLeafer && item.hasEvent(DragEvent.DRAG)))
|
|
112
|
+
},
|
|
113
|
+
|
|
114
|
+
pathHasOutside(path: ILeafList): boolean { // 滚动条元素
|
|
115
|
+
return path && path.list.some(item => item.isOutside)
|
|
116
|
+
},
|
|
109
117
|
}
|
|
110
118
|
|
|
111
119
|
const I = InteractionHelper
|
package/src/config.ts
CHANGED
package/src/emit.ts
CHANGED
|
@@ -54,7 +54,7 @@ function emitEvent(leaf: ILeaf, type: string, data: IUIEvent, capture?: boolean,
|
|
|
54
54
|
if (leaf.destroyed) return false
|
|
55
55
|
if (leaf.__.hitSelf && !exclude(leaf, excludePath)) {
|
|
56
56
|
|
|
57
|
-
if (State.updateEventStyle) State.updateEventStyle(leaf, type) // hoverStyle / pressStyle
|
|
57
|
+
if (State.updateEventStyle && !capture) State.updateEventStyle(leaf, type) // hoverStyle / pressStyle
|
|
58
58
|
|
|
59
59
|
if (leaf.hasEvent(type, capture)) {
|
|
60
60
|
data.phase = capture ? 1 : ((leaf === data.target) ? 2 : 3)
|
package/types/index.d.ts
CHANGED
|
@@ -84,6 +84,7 @@ declare class InteractionBase implements IInteraction {
|
|
|
84
84
|
protected overPath: LeafList;
|
|
85
85
|
protected enterPath: LeafList;
|
|
86
86
|
protected waitMenuTap: boolean;
|
|
87
|
+
protected waitRightTap: boolean;
|
|
87
88
|
protected waitTap: boolean;
|
|
88
89
|
protected longPressTimer: ITimer;
|
|
89
90
|
protected longPressed: boolean;
|
|
@@ -158,6 +159,8 @@ declare const InteractionHelper: {
|
|
|
158
159
|
getBase(e: IObject): IUIEvent;
|
|
159
160
|
pathHasEventType(path: ILeafList, type: string): boolean;
|
|
160
161
|
filterPathByEventType(path: ILeafList, type: string): ILeafList;
|
|
162
|
+
pathCanDrag(path: ILeafList): boolean;
|
|
163
|
+
pathHasOutside(path: ILeafList): boolean;
|
|
161
164
|
};
|
|
162
165
|
|
|
163
166
|
declare const MultiTouchHelper: {
|