@dxyl/utils 1.1.1 → 1.1.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/dist/index.es.js +4082 -4093
- package/dist/index.umd.js +10 -10
- package/package.json +1 -1
- package/types/events/eventTarget.d.ts +47 -80
package/package.json
CHANGED
|
@@ -1,93 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
(evt: Event<T>): void;
|
|
3
|
-
}
|
|
4
|
-
interface EventListenerObject<T = any> {
|
|
5
|
-
handleEvent(object: Event<T>): void;
|
|
6
|
-
}
|
|
7
|
-
interface EventInit {
|
|
8
|
-
bubbles?: boolean;
|
|
9
|
-
cancelable?: boolean;
|
|
10
|
-
composed?: boolean;
|
|
11
|
-
}
|
|
12
|
-
interface EventListenerOptions {
|
|
13
|
-
capture?: boolean;
|
|
14
|
-
}
|
|
15
|
-
type EventListenerOrEventListenerObject<T = any> = EventListener<T> | EventListenerObject<T>;
|
|
16
|
-
interface AddEventListenerOptions extends EventListenerOptions {
|
|
1
|
+
interface EventOptions {
|
|
17
2
|
once?: boolean;
|
|
18
|
-
|
|
19
|
-
signal?: AbortSignal;
|
|
3
|
+
capture?: boolean;
|
|
20
4
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
readonly
|
|
24
|
-
readonly
|
|
25
|
-
readonly
|
|
5
|
+
type EventCallback<T> = (event: Event<T>) => void;
|
|
6
|
+
export declare const EventPhase: {
|
|
7
|
+
readonly NONE: 0;
|
|
8
|
+
readonly CAPTURING_PHASE: 1;
|
|
9
|
+
readonly AT_TARGET: 2;
|
|
10
|
+
readonly BUBBLING_PHASE: 3;
|
|
11
|
+
};
|
|
12
|
+
export type EventPhase = typeof EventPhase[keyof typeof EventPhase];
|
|
13
|
+
export declare const NONE: 0;
|
|
14
|
+
export declare const CAPTURING_PHASE: 1;
|
|
15
|
+
export declare const AT_TARGET: 2;
|
|
16
|
+
export declare const BUBBLING_PHASE: 3;
|
|
17
|
+
export declare class Event<T = any, E extends Extract<keyof Record<string, any>, string> = ''> {
|
|
18
|
+
static create<T = any, E extends Extract<keyof Record<string, any>, string> = ''>(type: E, bubbles?: boolean, cancelable?: boolean): Event<T, E>;
|
|
19
|
+
type: E;
|
|
20
|
+
parentNode: null;
|
|
21
|
+
target: EventTarget | null;
|
|
22
|
+
currentTarget: EventTarget | null;
|
|
26
23
|
data: T | null;
|
|
27
|
-
|
|
28
|
-
type: string;
|
|
29
|
-
/** 事件是否冒泡 */
|
|
24
|
+
eventPhase: number;
|
|
30
25
|
bubbles: boolean;
|
|
31
|
-
/** 阻止事件冒泡的标志 */
|
|
32
|
-
cancelBubble: boolean;
|
|
33
|
-
/** 事件是否可以取消 */
|
|
34
26
|
cancelable: boolean;
|
|
35
|
-
/** 事件是否支持跨文档冒泡 */
|
|
36
|
-
composed: boolean;
|
|
37
|
-
/** 事件是否被默认行为阻止 */
|
|
38
27
|
defaultPrevented: boolean;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
currentTarget: EventTarget | null;
|
|
45
|
-
/** 事件阶段 */
|
|
46
|
-
eventPhase: number;
|
|
47
|
-
/** 事件的时间戳 */
|
|
48
|
-
timeStamp: number;
|
|
49
|
-
/**
|
|
50
|
-
* 标记事件是否应该立即停止传播
|
|
51
|
-
*/
|
|
52
|
-
stopImmediatePropagationInternal: boolean;
|
|
53
|
-
/**
|
|
54
|
-
* 构造函数
|
|
55
|
-
* @param type 事件类型
|
|
56
|
-
* @param eventInitDict 可选的事件初始化字典
|
|
57
|
-
*/
|
|
58
|
-
constructor(type: string, eventInitDict?: EventInit);
|
|
59
|
-
setData(data: T): this;
|
|
60
|
-
/**
|
|
61
|
-
* 初始化事件对象的属性
|
|
62
|
-
* @param type 事件类型
|
|
63
|
-
* @param bubbles 是否冒泡
|
|
64
|
-
* @param cancelable 是否可以取消
|
|
65
|
-
*/
|
|
66
|
-
initEvent(type: string, bubbles?: boolean, cancelable?: boolean): void;
|
|
67
|
-
/**
|
|
68
|
-
* 阻止事件冒泡
|
|
69
|
-
*/
|
|
70
|
-
stopPropagation(): void;
|
|
28
|
+
cancelBubble: boolean;
|
|
29
|
+
immediateCancelBubble: boolean;
|
|
30
|
+
constructor(type: E, bubbles?: boolean, cancelable?: boolean);
|
|
31
|
+
setData(data: T | null): this;
|
|
32
|
+
initEvent(type: E, bubbles?: boolean, cancelable?: boolean): void;
|
|
71
33
|
/**
|
|
72
|
-
*
|
|
34
|
+
*
|
|
35
|
+
* @returns {EventTarget[]}
|
|
73
36
|
*/
|
|
37
|
+
composedPath(): EventTarget<{}>[];
|
|
74
38
|
preventDefault(): void;
|
|
75
|
-
|
|
76
|
-
* 阻止事件冒泡并停止调用事件监听器
|
|
77
|
-
*/
|
|
39
|
+
stopPropagation(): void;
|
|
78
40
|
stopImmediatePropagation(): void;
|
|
79
|
-
/**
|
|
80
|
-
* 返回事件的目标对象及其祖先对象的路径
|
|
81
|
-
* @returns 事件路径的数组
|
|
82
|
-
*/
|
|
83
|
-
composedPath(): EventTarget[];
|
|
84
41
|
}
|
|
85
|
-
export
|
|
86
|
-
|
|
42
|
+
export interface EventTarget<Events extends Record<string, any> = {}> {
|
|
43
|
+
on<K extends keyof Events>(type: K, fn: EventCallback<Events[K]>, options?: EventOptions | boolean): void;
|
|
44
|
+
off<K extends keyof Events>(type: K, fn: EventCallback<Events[K]>, options?: EventOptions | boolean): void;
|
|
45
|
+
emit<K extends Extract<keyof Events, string>>(e: Event<Events[K], K>): void;
|
|
46
|
+
}
|
|
47
|
+
export declare class EventTarget<Events extends Record<string, any> = {}> {
|
|
87
48
|
parentNode: EventTarget | null;
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
removeEventListener(type:
|
|
49
|
+
private _bubble_emitter;
|
|
50
|
+
private _capture_emitter;
|
|
51
|
+
addEventListener<K extends keyof Events>(type: K, fn: EventCallback<Events[K]>, options?: EventOptions | boolean): void;
|
|
52
|
+
removeEventListener<K extends keyof Events>(type: K, fn: EventCallback<Events[K]>, options?: EventOptions | boolean): void;
|
|
53
|
+
/**
|
|
54
|
+
*
|
|
55
|
+
* @param {Event} e
|
|
56
|
+
*/
|
|
57
|
+
dispatchEvent<K extends Extract<keyof Events, string>>(e: Event<Events[K], K>): boolean;
|
|
58
|
+
removeAllListeners(): void;
|
|
92
59
|
}
|
|
93
|
-
export {};
|
|
60
|
+
export { EventTarget as EventPropagation };
|