@leafer-ui/event 1.7.0 → 1.9.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 +3 -3
- package/src/DragEvent.ts +7 -3
- package/src/KeyEvent.ts +5 -2
- package/src/Keyboard.ts +7 -2
- package/src/UIEvent.ts +6 -1
- package/types/index.d.ts +9 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-ui/event",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.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.
|
|
25
|
+
"@leafer/core": "1.9.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@leafer/interface": "1.
|
|
28
|
+
"@leafer/interface": "1.9.0"
|
|
29
29
|
}
|
|
30
30
|
}
|
package/src/DragEvent.ts
CHANGED
|
@@ -37,14 +37,18 @@ export class DragEvent extends PointerEvent implements IDragEvent {
|
|
|
37
37
|
this.data = data
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
static getValidMove(leaf: ILeaf, start: IPointData, total: IPointData): IPointData {
|
|
41
|
-
const
|
|
40
|
+
static getValidMove(leaf: ILeaf, start: IPointData, total: IPointData, checkLimit = true): IPointData {
|
|
41
|
+
const move = leaf.getLocalPoint(total, null, true)
|
|
42
42
|
PointHelper.move(move, start.x - leaf.x, start.y - leaf.y)
|
|
43
|
+
if (checkLimit) this.limitMove(leaf, move) // 检查拖拽限制
|
|
44
|
+
return move
|
|
45
|
+
}
|
|
43
46
|
|
|
47
|
+
static limitMove(leaf: ILeaf, move: IPointData): void {
|
|
48
|
+
const { draggable, dragBounds } = leaf
|
|
44
49
|
if (dragBounds) this.getMoveInDragBounds(leaf.__localBoxBounds, dragBounds === 'parent' ? leaf.parent.boxBounds : dragBounds, move, true)
|
|
45
50
|
if (draggable === 'x') move.y = 0
|
|
46
51
|
if (draggable === 'y') move.x = 0
|
|
47
|
-
return move
|
|
48
52
|
}
|
|
49
53
|
|
|
50
54
|
static getMoveInDragBounds(childBox: IBoundsData, dragBounds: IBoundsData, move: IPointData, change?: boolean): IPointData {
|
package/src/KeyEvent.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IKeyEvent } from '@leafer/interface'
|
|
1
|
+
import { IKeyCodes, IKeyEvent } from '@leafer/interface'
|
|
2
2
|
import { registerUIEvent } from '@leafer/core'
|
|
3
3
|
|
|
4
4
|
import { UIEvent } from './UIEvent'
|
|
@@ -7,11 +7,14 @@ import { UIEvent } from './UIEvent'
|
|
|
7
7
|
@registerUIEvent()
|
|
8
8
|
export class KeyEvent extends UIEvent implements IKeyEvent {
|
|
9
9
|
|
|
10
|
+
static BEFORE_DOWN = 'key.before_down'
|
|
11
|
+
static BEFORE_UP = 'key.before_up'
|
|
12
|
+
|
|
10
13
|
static DOWN = 'key.down'
|
|
11
14
|
static HOLD = 'key.hold'
|
|
12
15
|
static UP = 'key.up'
|
|
13
16
|
|
|
14
|
-
public readonly code:
|
|
17
|
+
public readonly code: IKeyCodes
|
|
15
18
|
public readonly key: string
|
|
16
19
|
|
|
17
20
|
}
|
package/src/Keyboard.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IBooleanMap } from '@leafer/interface'
|
|
1
|
+
import { IBooleanMap, IShortcutKeyCodes, IShortcutKeys, IShortcutKeysCheck, IUIEvent } from '@leafer/interface'
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
const downKeyMap: IBooleanMap = {}
|
|
@@ -9,10 +9,15 @@ export const Keyboard = {
|
|
|
9
9
|
return Keyboard.isHold('Space')
|
|
10
10
|
},
|
|
11
11
|
|
|
12
|
-
isHold(code:
|
|
12
|
+
isHold(code: IShortcutKeyCodes): boolean {
|
|
13
13
|
return downKeyMap[code]
|
|
14
14
|
},
|
|
15
15
|
|
|
16
|
+
// 是否按住快捷键,可扩展语义化快捷键组合 ctrl + F || shift + F
|
|
17
|
+
isHoldKeys(shortcutKeys: IShortcutKeysCheck | IShortcutKeys, e?: IUIEvent): boolean {
|
|
18
|
+
return e ? (shortcutKeys as IShortcutKeysCheck)(e) : undefined
|
|
19
|
+
},
|
|
20
|
+
|
|
16
21
|
setDownCode(code: string): void {
|
|
17
22
|
if (!downKeyMap[code]) downKeyMap[code] = true
|
|
18
23
|
},
|
package/src/UIEvent.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ILeaf, ILeafList, IPointData, IUIEvent } from '@leafer/interface'
|
|
1
|
+
import { ILeaf, ILeafList, IPointData, IUIEvent, IShortcutKeys, IShortcutKeysCheck } from '@leafer/interface'
|
|
2
2
|
import { Event, EventCreator } from '@leafer/core'
|
|
3
3
|
|
|
4
4
|
import { Keyboard } from './Keyboard'
|
|
@@ -33,6 +33,11 @@ export class UIEvent extends Event implements IUIEvent {
|
|
|
33
33
|
Object.assign(this, params)
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
|
|
37
|
+
public isHoldKeys(shortcutKeys?: IShortcutKeysCheck | IShortcutKeys): boolean {
|
|
38
|
+
return Keyboard.isHoldKeys(shortcutKeys, this)
|
|
39
|
+
}
|
|
40
|
+
|
|
36
41
|
public getBoxPoint(relative?: ILeaf): IPointData {
|
|
37
42
|
return (relative || this.current).getBoxPoint(this)
|
|
38
43
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IUIEvent, ILeafList, ILeaf, IPointData, IPointerEvent, PointerType, IDragEvent, IObject, IBoundsData, IDropEvent, IMoveEvent, IRotateEvent, ISwipeEvent, IZoomEvent, IKeyEvent } from '@leafer/interface';
|
|
1
|
+
import { IUIEvent, ILeafList, ILeaf, IShortcutKeysCheck, IShortcutKeys, IPointData, IPointerEvent, PointerType, IDragEvent, IObject, IBoundsData, IDropEvent, IMoveEvent, IRotateEvent, ISwipeEvent, IZoomEvent, IKeyEvent, IKeyCodes, IShortcutKeyCodes } from '@leafer/interface';
|
|
2
2
|
import { Event } from '@leafer/core';
|
|
3
3
|
|
|
4
4
|
declare class UIEvent extends Event implements IUIEvent {
|
|
@@ -19,6 +19,7 @@ declare class UIEvent extends Event implements IUIEvent {
|
|
|
19
19
|
readonly current: ILeaf;
|
|
20
20
|
readonly bubbles: boolean;
|
|
21
21
|
constructor(params: IUIEvent);
|
|
22
|
+
isHoldKeys(shortcutKeys?: IShortcutKeysCheck | IShortcutKeys): boolean;
|
|
22
23
|
getBoxPoint(relative?: ILeaf): IPointData;
|
|
23
24
|
getInnerPoint(relative?: ILeaf): IPointData;
|
|
24
25
|
getLocalPoint(relative?: ILeaf): IPointData;
|
|
@@ -78,7 +79,8 @@ declare class DragEvent extends PointerEvent implements IDragEvent {
|
|
|
78
79
|
static data: IObject;
|
|
79
80
|
static setList(data: ILeaf | ILeaf[] | ILeafList): void;
|
|
80
81
|
static setData(data: IObject): void;
|
|
81
|
-
static getValidMove(leaf: ILeaf, start: IPointData, total: IPointData): IPointData;
|
|
82
|
+
static getValidMove(leaf: ILeaf, start: IPointData, total: IPointData, checkLimit?: boolean): IPointData;
|
|
83
|
+
static limitMove(leaf: ILeaf, move: IPointData): void;
|
|
82
84
|
static getMoveInDragBounds(childBox: IBoundsData, dragBounds: IBoundsData, move: IPointData, change?: boolean): IPointData;
|
|
83
85
|
getPageMove(total?: boolean): IPointData;
|
|
84
86
|
getInnerMove(relative?: ILeaf, total?: boolean): IPointData;
|
|
@@ -134,16 +136,19 @@ declare class ZoomEvent extends PointerEvent implements IZoomEvent {
|
|
|
134
136
|
}
|
|
135
137
|
|
|
136
138
|
declare class KeyEvent extends UIEvent implements IKeyEvent {
|
|
139
|
+
static BEFORE_DOWN: string;
|
|
140
|
+
static BEFORE_UP: string;
|
|
137
141
|
static DOWN: string;
|
|
138
142
|
static HOLD: string;
|
|
139
143
|
static UP: string;
|
|
140
|
-
readonly code:
|
|
144
|
+
readonly code: IKeyCodes;
|
|
141
145
|
readonly key: string;
|
|
142
146
|
}
|
|
143
147
|
|
|
144
148
|
declare const Keyboard: {
|
|
145
149
|
isHoldSpaceKey(): boolean;
|
|
146
|
-
isHold(code:
|
|
150
|
+
isHold(code: IShortcutKeyCodes): boolean;
|
|
151
|
+
isHoldKeys(shortcutKeys: IShortcutKeysCheck | IShortcutKeys, e?: IUIEvent): boolean;
|
|
147
152
|
setDownCode(code: string): void;
|
|
148
153
|
setUpCode(code: string): void;
|
|
149
154
|
};
|