@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.
@@ -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
- typeof currentParam === "object" &&
178
- ("capture" in currentParam ||
179
- "once" in currentParam ||
180
- "passive" in currentParam ||
181
- "isComposedPath" in currentParam ||
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.defineProperty(event, "target", {
306
- value: $target,
307
- get() {
308
- return $target;
301
+ OriginPrototype.Object.defineProperties(event, {
302
+ target: {
303
+ get() {
304
+ return $target;
305
+ },
309
306
  },
310
- });
311
- OriginPrototype.Object.defineProperty(event, "originTarget", {
312
- value: $target,
313
- get() {
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: EventListenerOptions | boolean = args1[startIndex];
511
+ const currentParam: boolean | DOMUtilsEventListenerOption = args1[startIndex];
516
512
  if (typeof currentParam === "boolean") {
517
513
  option.capture = currentParam;
518
- } else if (typeof currentParam === "object" && currentParam != null && "capture" in currentParam) {
514
+ } else if (currentParam && typeof currentParam === "object" && "capture" in currentParam) {
519
515
  option.capture = currentParam.capture;
520
516
  }
521
517
  return option;
@@ -1,5 +1,6 @@
1
1
  export const OriginPrototype = {
2
2
  Object: {
3
3
  defineProperty: Object.defineProperty,
4
+ defineProperties: Object.defineProperties,
4
5
  },
5
6
  };
@@ -366,19 +366,26 @@ export declare interface DOMUtilsEventListenerOptionsAttribute {
366
366
  */
367
367
  export declare type DOMUtilsEventListenerOption = AddEventListenerOptions & {
368
368
  /**
369
- * 是否使用 event.composedPath() 来代替 event.target
369
+ * 前提:传入了`selector`参数
370
370
  *
371
- * 一般用于设置了selector参数
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