@whitesev/domutils 1.4.3 → 1.4.5
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.amd.js +84 -62
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +84 -62
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +84 -62
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +84 -62
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +84 -62
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +84 -62
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/DOMUtilsEvent.d.ts +18 -18
- package/dist/types/src/types/DOMUtilsEvent.d.ts +12 -1
- package/package.json +1 -1
- package/src/DOMUtils.ts +1 -1
- package/src/DOMUtilsEvent.ts +138 -103
- package/src/types/DOMUtilsEvent.d.ts +12 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DOMUtils_Event, DOMUtils_EventType, DOMUtilsElementEventType, DOMUtilsEventListenerOptionsAttribute } from "./types/DOMUtilsEvent";
|
|
1
|
+
import type { DOMUtils_Event, DOMUtils_EventType, DOMUtilsElementEventType, DOMUtilsEventListenerOption, DOMUtilsEventListenerOptionsAttribute } from "./types/DOMUtilsEvent";
|
|
2
2
|
import type { DOMUtilsTargetElementType } from "./types/global";
|
|
3
3
|
import type { WindowApiOption } from "./types/WindowApi";
|
|
4
4
|
import { WindowApi } from "./WindowApi";
|
|
@@ -23,7 +23,7 @@ export declare class DOMUtilsEvent {
|
|
|
23
23
|
* console.log("事件触发",event)
|
|
24
24
|
* })
|
|
25
25
|
*/
|
|
26
|
-
on<T extends DOMUtils_EventType>(element: DOMUtilsElementEventType, eventType: T | T[], callback: (event: DOMUtils_Event[T]) => void, option?:
|
|
26
|
+
on<T extends DOMUtils_EventType>(element: DOMUtilsElementEventType, eventType: T | T[], callback: (this: HTMLElement, event: DOMUtils_Event[T]) => void, option?: DOMUtilsEventListenerOption | boolean): void;
|
|
27
27
|
/**
|
|
28
28
|
* 绑定事件
|
|
29
29
|
* @param element 需要绑定的元素|元素数组|window
|
|
@@ -42,7 +42,7 @@ export declare class DOMUtilsEvent {
|
|
|
42
42
|
* console.log("事件触发",event)
|
|
43
43
|
* })
|
|
44
44
|
*/
|
|
45
|
-
on<T extends Event>(element: DOMUtilsElementEventType, eventType: string, callback: (event: T) => void, option?:
|
|
45
|
+
on<T extends Event>(element: DOMUtilsElementEventType, eventType: string, callback: (this: HTMLElement, event: T) => void, option?: DOMUtilsEventListenerOption | boolean): void;
|
|
46
46
|
/**
|
|
47
47
|
* 绑定事件
|
|
48
48
|
* @param element 需要绑定的元素|元素数组|window
|
|
@@ -67,7 +67,7 @@ export declare class DOMUtilsEvent {
|
|
|
67
67
|
* console.log("事件触发",event)
|
|
68
68
|
* })
|
|
69
69
|
*/
|
|
70
|
-
on<T extends DOMUtils_EventType>(element: DOMUtilsElementEventType, eventType: T | T[], selector: string | string[] | undefined | null, callback: (event: DOMUtils_Event[T]) => void, option?:
|
|
70
|
+
on<T extends DOMUtils_EventType>(element: DOMUtilsElementEventType, eventType: T | T[], selector: string | string[] | undefined | null, callback: (this: HTMLElement, event: DOMUtils_Event[T]) => void, option?: DOMUtilsEventListenerOption | boolean): void;
|
|
71
71
|
/**
|
|
72
72
|
* 绑定事件
|
|
73
73
|
* @param element 需要绑定的元素|元素数组|window
|
|
@@ -92,7 +92,7 @@ export declare class DOMUtilsEvent {
|
|
|
92
92
|
* console.log("事件触发",event)
|
|
93
93
|
* })
|
|
94
94
|
*/
|
|
95
|
-
on<T extends Event>(element: DOMUtilsElementEventType, eventType: string, selector: string | string[] | (() => string | string[]) | undefined | null, callback: (event: T) => void, option?:
|
|
95
|
+
on<T extends Event>(element: DOMUtilsElementEventType, eventType: string, selector: string | string[] | (() => string | string[]) | undefined | null, callback: (this: HTMLElement, event: T) => void, option?: DOMUtilsEventListenerOption | boolean): void;
|
|
96
96
|
/**
|
|
97
97
|
* 取消绑定事件
|
|
98
98
|
* @param element 需要取消绑定的元素|元素数组
|
|
@@ -102,11 +102,11 @@ export declare class DOMUtilsEvent {
|
|
|
102
102
|
* + capture 如果在添加事件监听器时指定了useCapture为true,则在移除事件监听器时也必须指定为true
|
|
103
103
|
* @param filter (可选)过滤函数,对元素属性上的事件进行过滤出想要删除的事件
|
|
104
104
|
* @example
|
|
105
|
-
* // 取消监听元素a.xx
|
|
105
|
+
* // 取消监听元素a.xx所有的click事件
|
|
106
106
|
* DOMUtils.off(document.querySelector("a.xx"),"click")
|
|
107
107
|
* DOMUtils.off("a.xx","click")
|
|
108
108
|
*/
|
|
109
|
-
off<T extends DOMUtils_EventType>(element: DOMUtilsElementEventType, eventType: T | T[], callback?: (event: DOMUtils_Event[T]) => void, option?: boolean |
|
|
109
|
+
off<T extends DOMUtils_EventType>(element: DOMUtilsElementEventType, eventType: T | T[], callback?: (this: HTMLElement, event: DOMUtils_Event[T]) => void, option?: boolean | EventListenerOptions, filter?: (value: DOMUtilsEventListenerOptionsAttribute, index: number, array: DOMUtilsEventListenerOptionsAttribute[]) => boolean): void;
|
|
110
110
|
/**
|
|
111
111
|
* 取消绑定事件
|
|
112
112
|
* @param element 需要取消绑定的元素|元素数组
|
|
@@ -120,7 +120,7 @@ export declare class DOMUtilsEvent {
|
|
|
120
120
|
* DOMUtils.off(document.querySelector("a.xx"),"click")
|
|
121
121
|
* DOMUtils.off("a.xx","click")
|
|
122
122
|
*/
|
|
123
|
-
off<T extends Event>(element: DOMUtilsElementEventType, eventType: string, callback?: (event: T) => void, option?: boolean |
|
|
123
|
+
off<T extends Event>(element: DOMUtilsElementEventType, eventType: string, callback?: (this: HTMLElement, event: T) => void, option?: boolean | EventListenerOptions, filter?: (value: DOMUtilsEventListenerOptionsAttribute, index: number, array: DOMUtilsEventListenerOptionsAttribute[]) => boolean): void;
|
|
124
124
|
/**
|
|
125
125
|
* 取消绑定事件
|
|
126
126
|
* @param element 需要取消绑定的元素|元素数组
|
|
@@ -135,7 +135,7 @@ export declare class DOMUtilsEvent {
|
|
|
135
135
|
* DOMUtils.off(document.querySelector("a.xx"),"click tap hover")
|
|
136
136
|
* DOMUtils.off("a.xx",["click","tap","hover"])
|
|
137
137
|
*/
|
|
138
|
-
off<T extends DOMUtils_EventType>(element: DOMUtilsElementEventType, eventType: T | T[], selector?: DOMUtilsEventListenerOptionsAttribute["selector"] | undefined, callback?: (event: DOMUtils_Event[T]) => void, option?: boolean |
|
|
138
|
+
off<T extends DOMUtils_EventType>(element: DOMUtilsElementEventType, eventType: T | T[], selector?: DOMUtilsEventListenerOptionsAttribute["selector"] | undefined, callback?: (this: HTMLElement, event: DOMUtils_Event[T]) => void, option?: boolean | EventListenerOptions, filter?: (value: DOMUtilsEventListenerOptionsAttribute, index: number, array: DOMUtilsEventListenerOptionsAttribute[]) => boolean): void;
|
|
139
139
|
/**
|
|
140
140
|
* 取消绑定事件
|
|
141
141
|
* @param element 需要取消绑定的元素|元素数组
|
|
@@ -150,7 +150,7 @@ export declare class DOMUtilsEvent {
|
|
|
150
150
|
* DOMUtils.off(document.querySelector("a.xx"),"click tap hover")
|
|
151
151
|
* DOMUtils.off("a.xx",["click","tap","hover"])
|
|
152
152
|
*/
|
|
153
|
-
off<T extends Event>(element: DOMUtilsElementEventType, eventType: string, selector?: DOMUtilsEventListenerOptionsAttribute["selector"] | undefined, callback?: (event: T) => void, option?: boolean |
|
|
153
|
+
off<T extends Event>(element: DOMUtilsElementEventType, eventType: string, selector?: DOMUtilsEventListenerOptionsAttribute["selector"] | undefined, callback?: (this: HTMLElement, event: T) => void, option?: boolean | EventListenerOptions, filter?: (value: DOMUtilsEventListenerOptionsAttribute, index: number, array: DOMUtilsEventListenerOptionsAttribute[]) => boolean): void;
|
|
154
154
|
/**
|
|
155
155
|
* 取消绑定所有的事件
|
|
156
156
|
* @param element 需要取消绑定的元素|元素数组
|
|
@@ -216,7 +216,7 @@ export declare class DOMUtilsEvent {
|
|
|
216
216
|
* console.log("触发click事件成功")
|
|
217
217
|
* })
|
|
218
218
|
* */
|
|
219
|
-
click(element: DOMUtilsTargetElementType | typeof globalThis | Window, handler?: (event: DOMUtils_Event["click"]) => void, details?: any, useDispatchToTriggerEvent?: boolean): void;
|
|
219
|
+
click(element: DOMUtilsTargetElementType | typeof globalThis | Window, handler?: (this: HTMLElement, event: DOMUtils_Event["click"]) => void, details?: any, useDispatchToTriggerEvent?: boolean): void;
|
|
220
220
|
/**
|
|
221
221
|
* 绑定或触发元素的blur事件
|
|
222
222
|
* @param element 目标元素
|
|
@@ -231,7 +231,7 @@ export declare class DOMUtilsEvent {
|
|
|
231
231
|
* console.log("触发blur事件成功")
|
|
232
232
|
* })
|
|
233
233
|
* */
|
|
234
|
-
blur(element: DOMUtilsTargetElementType | typeof globalThis | Window, handler?: (event: DOMUtils_Event["blur"]) => void, details?: object, useDispatchToTriggerEvent?: boolean): void;
|
|
234
|
+
blur(element: DOMUtilsTargetElementType | typeof globalThis | Window, handler?: (this: HTMLElement, event: DOMUtils_Event["blur"]) => void, details?: object, useDispatchToTriggerEvent?: boolean): void;
|
|
235
235
|
/**
|
|
236
236
|
* 绑定或触发元素的focus事件
|
|
237
237
|
* @param element 目标元素
|
|
@@ -246,7 +246,7 @@ export declare class DOMUtilsEvent {
|
|
|
246
246
|
* console.log("触发focus事件成功")
|
|
247
247
|
* })
|
|
248
248
|
* */
|
|
249
|
-
focus(element: DOMUtilsTargetElementType | typeof globalThis | Window, handler?: (event: DOMUtils_Event["focus"]) => void, details?: object, useDispatchToTriggerEvent?: boolean): void;
|
|
249
|
+
focus(element: DOMUtilsTargetElementType | typeof globalThis | Window, handler?: (this: HTMLElement, event: DOMUtils_Event["focus"]) => void, details?: object, useDispatchToTriggerEvent?: boolean): void;
|
|
250
250
|
/**
|
|
251
251
|
* 当鼠标移入或移出元素时触发事件
|
|
252
252
|
* @param element 当前元素
|
|
@@ -261,7 +261,7 @@ export declare class DOMUtilsEvent {
|
|
|
261
261
|
* console.log("移入/移除");
|
|
262
262
|
* })
|
|
263
263
|
*/
|
|
264
|
-
hover(element: DOMUtilsTargetElementType, handler: (event: DOMUtils_Event["hover"]) => void, option?: boolean |
|
|
264
|
+
hover(element: DOMUtilsTargetElementType, handler: (this: HTMLElement, event: DOMUtils_Event["hover"]) => void, option?: boolean | DOMUtilsEventListenerOption): void;
|
|
265
265
|
/**
|
|
266
266
|
* 当按键松开时触发事件
|
|
267
267
|
* keydown - > keypress - > keyup
|
|
@@ -277,7 +277,7 @@ export declare class DOMUtilsEvent {
|
|
|
277
277
|
* console.log("按键松开");
|
|
278
278
|
* })
|
|
279
279
|
*/
|
|
280
|
-
keyup(element: DOMUtilsTargetElementType | Window | typeof globalThis, handler: (event: DOMUtils_Event["keyup"]) => void, option?: boolean |
|
|
280
|
+
keyup(element: DOMUtilsTargetElementType | Window | typeof globalThis, handler: (this: HTMLElement, event: DOMUtils_Event["keyup"]) => void, option?: boolean | DOMUtilsEventListenerOption): void;
|
|
281
281
|
/**
|
|
282
282
|
* 当按键按下时触发事件
|
|
283
283
|
* keydown - > keypress - > keyup
|
|
@@ -293,7 +293,7 @@ export declare class DOMUtilsEvent {
|
|
|
293
293
|
* console.log("按键按下");
|
|
294
294
|
* })
|
|
295
295
|
*/
|
|
296
|
-
keydown(element: DOMUtilsTargetElementType | Window | typeof globalThis, handler: (event: DOMUtils_Event["keydown"]) => void, option?: boolean |
|
|
296
|
+
keydown(element: DOMUtilsTargetElementType | Window | typeof globalThis, handler: (this: HTMLElement, event: DOMUtils_Event["keydown"]) => void, option?: boolean | DOMUtilsEventListenerOption): void;
|
|
297
297
|
/**
|
|
298
298
|
* 当按键按下时触发事件
|
|
299
299
|
* keydown - > keypress - > keyup
|
|
@@ -309,7 +309,7 @@ export declare class DOMUtilsEvent {
|
|
|
309
309
|
* console.log("按键按下");
|
|
310
310
|
* })
|
|
311
311
|
*/
|
|
312
|
-
keypress(element: DOMUtilsTargetElementType | Window | typeof globalThis, handler: (event: DOMUtils_Event["keypress"]) => void, option?: boolean |
|
|
312
|
+
keypress(element: DOMUtilsTargetElementType | Window | typeof globalThis, handler: (this: HTMLElement, event: DOMUtils_Event["keypress"]) => void, option?: boolean | DOMUtilsEventListenerOption): void;
|
|
313
313
|
/**
|
|
314
314
|
* 监听某个元素键盘按键事件或window全局按键事件
|
|
315
315
|
* 按下有值的键时触发,按下Ctrl\Alt\Shift\Meta是无值键。按下先触发keydown事件,再触发keypress事件。
|
|
@@ -373,7 +373,7 @@ export declare class DOMUtilsEvent {
|
|
|
373
373
|
搜索 170
|
|
374
374
|
收藏 171
|
|
375
375
|
**/
|
|
376
|
-
listenKeyboard(element: DOMUtilsTargetElementType | Window | Node | typeof globalThis, eventName:
|
|
376
|
+
listenKeyboard(element: DOMUtilsTargetElementType | Window | Node | typeof globalThis, eventName: "keyup" | "keypress" | "keydown" | undefined, callback: (keyName: string, keyValue: number, otherCodeList: string[], event: KeyboardEvent) => void, options?: DOMUtilsEventListenerOption | boolean): {
|
|
377
377
|
removeListen(): void;
|
|
378
378
|
};
|
|
379
379
|
/**
|
|
@@ -211,7 +211,7 @@ export declare interface DOMUtilsEventListenerOptionsAttribute {
|
|
|
211
211
|
/**
|
|
212
212
|
* 属性配置
|
|
213
213
|
*/
|
|
214
|
-
option:
|
|
214
|
+
option: DOMUtilsEventListenerOption;
|
|
215
215
|
/**
|
|
216
216
|
* 用户添加的事件
|
|
217
217
|
*/
|
|
@@ -222,6 +222,17 @@ export declare interface DOMUtilsEventListenerOptionsAttribute {
|
|
|
222
222
|
selector?: string[];
|
|
223
223
|
}
|
|
224
224
|
|
|
225
|
+
/**
|
|
226
|
+
* 事件的额外配置
|
|
227
|
+
*/
|
|
228
|
+
export declare type DOMUtilsEventListenerOption = AddEventListenerOptions & {
|
|
229
|
+
/**
|
|
230
|
+
* 是否使用 event.composedPath() 来代替 event.target
|
|
231
|
+
*
|
|
232
|
+
* 一般用于设置了selector参数
|
|
233
|
+
*/
|
|
234
|
+
isComposedPath?: boolean;
|
|
235
|
+
};
|
|
225
236
|
export declare type DOMUtilsElementEventType =
|
|
226
237
|
| HTMLElement
|
|
227
238
|
| string
|
package/package.json
CHANGED