@whitesev/domutils 2.0.3 → 2.0.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 +21 -22
- package/dist/index.amd.js.map +1 -1
- package/dist/index.amd.min.js +1 -1
- package/dist/index.amd.min.js.map +1 -1
- package/dist/index.cjs.js +21 -22
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs.min.js +1 -1
- package/dist/index.cjs.min.js.map +1 -1
- package/dist/index.esm.js +21 -22
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.esm.min.js.map +1 -1
- package/dist/index.iife.js +21 -22
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +1 -1
- package/dist/index.iife.min.js.map +1 -1
- package/dist/index.system.js +21 -22
- package/dist/index.system.js.map +1 -1
- package/dist/index.system.min.js +1 -1
- package/dist/index.system.min.js.map +1 -1
- package/dist/index.umd.js +21 -22
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/index.umd.min.js.map +1 -1
- package/dist/types/src/OriginPrototype.d.ts +1 -0
- package/dist/types/src/types/DOMUtilsEvent.d.ts +9 -2
- package/package.json +5 -5
- package/src/ElementEvent.ts +21 -25
- package/src/OriginPrototype.ts +1 -0
- package/src/types/DOMUtilsEvent.d.ts +9 -2
package/src/ElementEvent.ts
CHANGED
|
@@ -164,7 +164,7 @@ class ElementEvent extends ElementAnimate {
|
|
|
164
164
|
* @param option
|
|
165
165
|
*/
|
|
166
166
|
const getOption = function (args: IArguments, startIndex: number, option: DOMUtilsEventListenerOption) {
|
|
167
|
-
const currentParam = args[startIndex];
|
|
167
|
+
const currentParam: boolean | DOMUtilsEventListenerOption = args[startIndex];
|
|
168
168
|
if (typeof currentParam === "boolean") {
|
|
169
169
|
option.capture = currentParam;
|
|
170
170
|
if (typeof args[startIndex + 1] === "boolean") {
|
|
@@ -173,19 +173,12 @@ class ElementEvent extends ElementAnimate {
|
|
|
173
173
|
if (typeof args[startIndex + 2] === "boolean") {
|
|
174
174
|
option.passive = args[startIndex + 2];
|
|
175
175
|
}
|
|
176
|
-
} else if (
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
"overrideTarget" in currentParam)
|
|
183
|
-
) {
|
|
184
|
-
option.capture = currentParam.capture;
|
|
185
|
-
option.once = currentParam.once;
|
|
186
|
-
option.passive = currentParam.passive;
|
|
187
|
-
option.isComposedPath = currentParam.isComposedPath;
|
|
188
|
-
option.overrideTarget = currentParam.overrideTarget;
|
|
176
|
+
} else if (currentParam && typeof currentParam === "object") {
|
|
177
|
+
for (const key in option) {
|
|
178
|
+
if (Reflect.has(currentParam, key)) {
|
|
179
|
+
Reflect.set(option, key, currentParam[key as keyof typeof currentParam]);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
189
182
|
}
|
|
190
183
|
return option;
|
|
191
184
|
};
|
|
@@ -264,6 +257,9 @@ class ElementEvent extends ElementAnimate {
|
|
|
264
257
|
* @param event
|
|
265
258
|
*/
|
|
266
259
|
const handlerCallBack = function (event: Event) {
|
|
260
|
+
if (listenerOption.isPreventEvent) {
|
|
261
|
+
that.preventEvent(event);
|
|
262
|
+
}
|
|
267
263
|
let call_this: Element | undefined = void 0;
|
|
268
264
|
let call_event: Event | undefined = void 0;
|
|
269
265
|
let call_$selector: HTMLElement | undefined = void 0;
|
|
@@ -302,16 +298,16 @@ class ElementEvent extends ElementAnimate {
|
|
|
302
298
|
// 这里尝试使用defineProperty修改event的target值
|
|
303
299
|
try {
|
|
304
300
|
const originTarget = event.target;
|
|
305
|
-
OriginPrototype.Object.
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
301
|
+
OriginPrototype.Object.defineProperties(event, {
|
|
302
|
+
target: {
|
|
303
|
+
get() {
|
|
304
|
+
return $target;
|
|
305
|
+
},
|
|
309
306
|
},
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
return originTarget;
|
|
307
|
+
originTarget: {
|
|
308
|
+
get() {
|
|
309
|
+
return originTarget;
|
|
310
|
+
},
|
|
315
311
|
},
|
|
316
312
|
});
|
|
317
313
|
// oxlint-disable-next-line no-empty
|
|
@@ -512,10 +508,10 @@ class ElementEvent extends ElementAnimate {
|
|
|
512
508
|
* @param option
|
|
513
509
|
*/
|
|
514
510
|
const getOption = function (args1: IArguments, startIndex: number, option: EventListenerOptions) {
|
|
515
|
-
const currentParam:
|
|
511
|
+
const currentParam: boolean | DOMUtilsEventListenerOption = args1[startIndex];
|
|
516
512
|
if (typeof currentParam === "boolean") {
|
|
517
513
|
option.capture = currentParam;
|
|
518
|
-
} else if (typeof currentParam === "object" &&
|
|
514
|
+
} else if (currentParam && typeof currentParam === "object" && "capture" in currentParam) {
|
|
519
515
|
option.capture = currentParam.capture;
|
|
520
516
|
}
|
|
521
517
|
return option;
|
package/src/OriginPrototype.ts
CHANGED
|
@@ -366,19 +366,26 @@ export declare interface DOMUtilsEventListenerOptionsAttribute {
|
|
|
366
366
|
*/
|
|
367
367
|
export declare type DOMUtilsEventListenerOption = AddEventListenerOptions & {
|
|
368
368
|
/**
|
|
369
|
-
*
|
|
369
|
+
* 前提:传入了`selector`参数
|
|
370
370
|
*
|
|
371
|
-
*
|
|
371
|
+
* 是否使用 event.composedPath() 来代替 event.target
|
|
372
372
|
* @default false
|
|
373
373
|
*/
|
|
374
374
|
isComposedPath?: boolean;
|
|
375
375
|
/**
|
|
376
|
+
* 前提:传入了`selector`参数
|
|
377
|
+
*
|
|
376
378
|
* 是否覆写`target`,仅传入了子元素的`selectorTarget`时才会生效
|
|
377
379
|
*
|
|
378
380
|
* 原始的`target`将命名为`originTarget`
|
|
379
381
|
* @default true
|
|
380
382
|
*/
|
|
381
383
|
overrideTarget?: boolean;
|
|
384
|
+
/**
|
|
385
|
+
* 是否阻止事件传播,包括阻止默认行为
|
|
386
|
+
* @default false
|
|
387
|
+
*/
|
|
388
|
+
isPreventEvent?: boolean;
|
|
382
389
|
};
|
|
383
390
|
export declare type DOMUtilsElementEventType =
|
|
384
391
|
| HTMLElement
|