@whitesev/domutils 2.0.3 → 2.0.4

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") {
@@ -174,18 +174,21 @@ class ElementEvent extends ElementAnimate {
174
174
  option.passive = args[startIndex + 2];
175
175
  }
176
176
  } else if (
177
+ currentParam &&
177
178
  typeof currentParam === "object" &&
178
179
  ("capture" in currentParam ||
179
180
  "once" in currentParam ||
180
181
  "passive" in currentParam ||
181
182
  "isComposedPath" in currentParam ||
182
- "overrideTarget" in currentParam)
183
+ "overrideTarget" in currentParam ||
184
+ "isPreventEvent" in currentParam)
183
185
  ) {
184
186
  option.capture = currentParam.capture;
185
187
  option.once = currentParam.once;
186
188
  option.passive = currentParam.passive;
187
189
  option.isComposedPath = currentParam.isComposedPath;
188
190
  option.overrideTarget = currentParam.overrideTarget;
191
+ option.isPreventEvent = currentParam.isPreventEvent;
189
192
  }
190
193
  return option;
191
194
  };
@@ -264,6 +267,9 @@ class ElementEvent extends ElementAnimate {
264
267
  * @param event
265
268
  */
266
269
  const handlerCallBack = function (event: Event) {
270
+ if (listenerOption.isPreventEvent) {
271
+ that.preventEvent(event);
272
+ }
267
273
  let call_this: Element | undefined = void 0;
268
274
  let call_event: Event | undefined = void 0;
269
275
  let call_$selector: HTMLElement | undefined = void 0;
@@ -512,10 +518,15 @@ class ElementEvent extends ElementAnimate {
512
518
  * @param option
513
519
  */
514
520
  const getOption = function (args1: IArguments, startIndex: number, option: EventListenerOptions) {
515
- const currentParam: EventListenerOptions | boolean = args1[startIndex];
521
+ const currentParam: boolean | DOMUtilsEventListenerOption = args1[startIndex];
516
522
  if (typeof currentParam === "boolean") {
517
523
  option.capture = currentParam;
518
- } else if (typeof currentParam === "object" && currentParam != null && "capture" in currentParam) {
524
+ } else if (
525
+ currentParam &&
526
+ typeof currentParam === "object" &&
527
+ currentParam != null &&
528
+ "capture" in currentParam
529
+ ) {
519
530
  option.capture = currentParam.capture;
520
531
  }
521
532
  return option;
@@ -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