@leafer-ui/interaction 1.0.0 → 1.0.2
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 +9 -4
- package/src/Interaction.ts +13 -9
- package/src/InteractionHelper.ts +10 -2
- package/src/Transformer.ts +3 -0
- package/src/config.ts +3 -0
- package/types/index.d.ts +5 -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.2",
|
|
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.2",
|
|
26
|
+
"@leafer-ui/draw": "1.0.2",
|
|
27
|
+
"@leafer-ui/event": "1.0.2"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@leafer/interface": "1.0.
|
|
31
|
-
"@leafer-ui/interface": "1.0.
|
|
30
|
+
"@leafer/interface": "1.0.2",
|
|
31
|
+
"@leafer-ui/interface": "1.0.2"
|
|
32
32
|
}
|
|
33
33
|
}
|
package/src/Dragger.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IPointerEvent, IDragEvent, ILeaf, ILeafList, ITimer, IFunction, IPointDataMap } from '@leafer/interface'
|
|
1
|
+
import { IPointerEvent, IDragEvent, ILeaf, ILeafList, ITimer, IFunction, IPointDataMap, IMoveEvent } from '@leafer/interface'
|
|
2
2
|
import { BoundsHelper, PointHelper, LeafList } from '@leafer/core'
|
|
3
3
|
|
|
4
4
|
import { MoveEvent, DragEvent, DropEvent, PointerButton } from '@leafer-ui/event'
|
|
@@ -58,7 +58,10 @@ export class Dragger {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
if (!this.moving && canDrag) {
|
|
61
|
-
if (this.moving = interaction.canMove(this.downData) || interaction.isHoldRightKey || interaction.isMobileDragEmpty)
|
|
61
|
+
if (this.moving = interaction.canMove(this.downData) || interaction.isHoldRightKey || interaction.isMobileDragEmpty) {
|
|
62
|
+
(this.dragData as IMoveEvent).moveType = 'drag'
|
|
63
|
+
interaction.emit(MoveEvent.START, this.dragData)
|
|
64
|
+
}
|
|
62
65
|
}
|
|
63
66
|
|
|
64
67
|
if (!this.moving) {
|
|
@@ -103,6 +106,7 @@ export class Dragger {
|
|
|
103
106
|
this.dragData.path = path
|
|
104
107
|
|
|
105
108
|
if (this.moving) {
|
|
109
|
+
(this.dragData as IMoveEvent).moveType = 'drag'
|
|
106
110
|
interaction.emit(MoveEvent.BEFORE_MOVE, this.dragData)
|
|
107
111
|
interaction.emit(MoveEvent.MOVE, this.dragData)
|
|
108
112
|
} else if (this.dragging) {
|
|
@@ -174,7 +178,8 @@ export class Dragger {
|
|
|
174
178
|
endDragData.path = path
|
|
175
179
|
|
|
176
180
|
if (this.moving) {
|
|
177
|
-
this.moving = false
|
|
181
|
+
this.moving = false;
|
|
182
|
+
(endDragData as IMoveEvent).moveType = 'drag'
|
|
178
183
|
interaction.emit(MoveEvent.END, endDragData)
|
|
179
184
|
}
|
|
180
185
|
|
|
@@ -248,7 +253,7 @@ export class Dragger {
|
|
|
248
253
|
PointHelper.move(downData, moveX, moveY)
|
|
249
254
|
PointHelper.move(this.dragData, moveX, moveY)
|
|
250
255
|
|
|
251
|
-
interaction.move({ ...data, moveX, moveY, totalX, totalY })
|
|
256
|
+
interaction.move({ ...data, moveX, moveY, totalX, totalY, moveType: 'drag' })
|
|
252
257
|
interaction.pointerMoveReal(data)
|
|
253
258
|
}, 10)
|
|
254
259
|
}
|
package/src/Interaction.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IUIEvent, IPointerEvent, ILeaf, IInteraction, IInteractionConfig, ILeafList, IMoveEvent, IZoomEvent, IRotateEvent, ISelector, IBounds, IEventListenerId, IInteractionCanvas, ITimer, IKeepTouchData, IKeyEvent, IPickOptions, ICursorType, IBooleanMap, IPickBottom, IClientPointData, IPointData } from '@leafer/interface'
|
|
1
|
+
import { IUIEvent, IPointerEvent, ILeaf, IInteraction, IInteractionConfig, ILeafList, IMoveEvent, IZoomEvent, IRotateEvent, ISelector, IBounds, IEventListenerId, IInteractionCanvas, ITimer, IKeepTouchData, IKeyEvent, IPickOptions, ICursorType, IBooleanMap, IPickBottom, IClientPointData, IPointData, ILeaferConfig } from '@leafer/interface'
|
|
2
2
|
import { LeaferEvent, ResizeEvent, LeafList, Bounds, PointHelper, DataHelper } from '@leafer/core'
|
|
3
3
|
|
|
4
4
|
import { IApp } from '@leafer-ui/interface'
|
|
@@ -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
|
|
@@ -22,15 +22,18 @@ export class InteractionBase implements IInteraction {
|
|
|
22
22
|
public running: boolean
|
|
23
23
|
|
|
24
24
|
public get dragging(): boolean { return this.dragger.dragging }
|
|
25
|
-
public get
|
|
25
|
+
public get transforming(): boolean { return this.transformer.transforming }
|
|
26
|
+
|
|
27
|
+
public get moveMode(): boolean { return this.config.move.drag === true || this.isHoldSpaceKey || this.isHoldMiddleKey || (this.isHoldRightKey && this.dragger.moving) || this.isDragEmpty }
|
|
28
|
+
public get canHover(): boolean { return this.config.pointer.hover && !(this.config as ILeaferConfig).mobile }
|
|
26
29
|
|
|
27
30
|
public get isDragEmpty(): boolean { return this.config.move.dragEmpty && this.isRootPath(this.hoverData) && (!this.downData || this.isRootPath(this.downData)) }
|
|
28
|
-
public get isMobileDragEmpty(): boolean { return this.config.move.dragEmpty && !this.
|
|
31
|
+
public get isMobileDragEmpty(): boolean { return this.config.move.dragEmpty && !this.canHover && this.downData && this.isTreePath(this.downData) }
|
|
29
32
|
public get isHoldMiddleKey(): boolean { return this.config.move.holdMiddleKey && this.downData && PointerButton.middle(this.downData) }
|
|
30
33
|
public get isHoldRightKey(): boolean { return this.config.move.holdRightKey && this.downData && PointerButton.right(this.downData) }
|
|
31
34
|
public get isHoldSpaceKey(): boolean { return this.config.move.holdSpaceKey && Keyboard.isHoldSpaceKey() }
|
|
32
35
|
|
|
33
|
-
public config: IInteractionConfig = config
|
|
36
|
+
public config: IInteractionConfig = DataHelper.clone(config)
|
|
34
37
|
|
|
35
38
|
public cursor: ICursorType | ICursorType[]
|
|
36
39
|
public get hitRadius(): number { return this.config.pointer.hitRadius }
|
|
@@ -164,6 +167,7 @@ export class InteractionBase implements IInteraction {
|
|
|
164
167
|
if (!downData) return
|
|
165
168
|
|
|
166
169
|
PointerButton.defaultLeft(data)
|
|
170
|
+
data.multiTouch = downData.multiTouch
|
|
167
171
|
|
|
168
172
|
this.findPath(data)
|
|
169
173
|
const upData = { ...data, path: data.path.clone() }
|
|
@@ -265,7 +269,7 @@ export class InteractionBase implements IInteraction {
|
|
|
265
269
|
|
|
266
270
|
// helper
|
|
267
271
|
protected pointerHover(data: IPointerEvent): void {
|
|
268
|
-
if (this.
|
|
272
|
+
if (this.canHover) {
|
|
269
273
|
this.pointerOverOrOut(data)
|
|
270
274
|
this.pointerEnterOrLeave(data)
|
|
271
275
|
}
|
|
@@ -370,11 +374,11 @@ export class InteractionBase implements IInteraction {
|
|
|
370
374
|
}
|
|
371
375
|
|
|
372
376
|
protected checkPath(data: IPointerEvent, useDefaultPath?: boolean): void {
|
|
373
|
-
if (useDefaultPath || this.
|
|
377
|
+
if (useDefaultPath || (this.moveMode && !pathHasOutside(data.path))) data.path = this.defaultPath
|
|
374
378
|
}
|
|
375
379
|
|
|
376
380
|
public canMove(data: IPointerEvent): boolean { // moveMode and path can move
|
|
377
|
-
return this.moveMode
|
|
381
|
+
return data && (this.moveMode || (this.config.move.drag === 'auto' && !pathCanDrag(data.path))) && !pathHasOutside(data.path)
|
|
378
382
|
}
|
|
379
383
|
|
|
380
384
|
|
|
@@ -421,7 +425,7 @@ export class InteractionBase implements IInteraction {
|
|
|
421
425
|
}
|
|
422
426
|
|
|
423
427
|
public updateCursor(data?: IPointerEvent): void {
|
|
424
|
-
if (!this.config.cursor || !this.
|
|
428
|
+
if (!this.config.cursor || !this.canHover) return
|
|
425
429
|
|
|
426
430
|
if (!data) {
|
|
427
431
|
this.updateHoverData()
|
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/Transformer.ts
CHANGED
|
@@ -6,6 +6,8 @@ import { InteractionBase } from './Interaction'
|
|
|
6
6
|
|
|
7
7
|
export class Transformer {
|
|
8
8
|
|
|
9
|
+
public get transforming(): boolean { return !!(this.moveData || this.zoomData || this.rotateData) }
|
|
10
|
+
|
|
9
11
|
protected interaction: InteractionBase
|
|
10
12
|
protected moveData: IMoveEvent
|
|
11
13
|
protected zoomData: IZoomEvent
|
|
@@ -18,6 +20,7 @@ export class Transformer {
|
|
|
18
20
|
|
|
19
21
|
public move(data: IMoveEvent): void {
|
|
20
22
|
const { interaction } = this
|
|
23
|
+
if (!data.moveType) data.moveType = 'move'
|
|
21
24
|
|
|
22
25
|
if (!this.moveData) {
|
|
23
26
|
const { path } = interaction.selector.getByPoint(data, interaction.hitRadius)
|
package/src/config.ts
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { IMoveEvent, IZoomEvent, IRotateEvent, ITimer, IDragEvent, IPointerEvent
|
|
|
2
2
|
import { LeafList } from '@leafer/core';
|
|
3
3
|
|
|
4
4
|
declare class Transformer {
|
|
5
|
+
get transforming(): boolean;
|
|
5
6
|
protected interaction: InteractionBase;
|
|
6
7
|
protected moveData: IMoveEvent;
|
|
7
8
|
protected zoomData: IZoomEvent;
|
|
@@ -63,7 +64,9 @@ declare class InteractionBase implements IInteraction {
|
|
|
63
64
|
selector: ISelector;
|
|
64
65
|
running: boolean;
|
|
65
66
|
get dragging(): boolean;
|
|
67
|
+
get transforming(): boolean;
|
|
66
68
|
get moveMode(): boolean;
|
|
69
|
+
get canHover(): boolean;
|
|
67
70
|
get isDragEmpty(): boolean;
|
|
68
71
|
get isMobileDragEmpty(): boolean;
|
|
69
72
|
get isHoldMiddleKey(): boolean;
|
|
@@ -155,6 +158,8 @@ declare const InteractionHelper: {
|
|
|
155
158
|
getBase(e: IObject): IUIEvent;
|
|
156
159
|
pathHasEventType(path: ILeafList, type: string): boolean;
|
|
157
160
|
filterPathByEventType(path: ILeafList, type: string): ILeafList;
|
|
161
|
+
pathCanDrag(path: ILeafList): boolean;
|
|
162
|
+
pathHasOutside(path: ILeafList): boolean;
|
|
158
163
|
};
|
|
159
164
|
|
|
160
165
|
declare const MultiTouchHelper: {
|