@whitesev/domutils 1.9.7 → 1.9.9

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.
@@ -533,15 +533,6 @@ class ElementEvent extends ElementAnimate {
533
533
  // 这是存在selector的情况
534
534
  listenerOption = getOption(args, 4, listenerOption);
535
535
  }
536
- // 是否移除所有事件
537
- let isRemoveAll = false;
538
- if (args.length === 2) {
539
- // 目标函数、事件名
540
- isRemoveAll = true;
541
- } else if ((args.length === 3 && typeof args[2] === "string") || Array.isArray(args[2])) {
542
- // 目标函数、事件名、子元素选择器
543
- isRemoveAll = true;
544
- }
545
536
  if (args.length === 5 && typeof args[4] === "function" && typeof filter !== "function") {
546
537
  // 目标函数、事件名、回调函数、事件配置、过滤函数
547
538
  filter = option as (
@@ -579,7 +570,7 @@ class ElementEvent extends ElementAnimate {
579
570
  // 事件的配置项不同
580
571
  flag = false;
581
572
  }
582
- if (flag || isRemoveAll) {
573
+ if (flag) {
583
574
  $elItem.removeEventListener(eventName, handler.handlerCallBack, handler.option);
584
575
  const findIndex = handlers.findIndex((item) => item === handler);
585
576
  if (findIndex !== -1) {
@@ -1283,53 +1274,6 @@ class ElementEvent extends ElementAnimate {
1283
1274
  }
1284
1275
  return that.on(element, "keydown", null, handler, option);
1285
1276
  }
1286
- /**
1287
- * 当按键按下时触发事件
1288
- * keydown - > keypress - > keyup
1289
- * @param element 目标
1290
- * @param handler 事件处理函数
1291
- * @param option 配置
1292
- * @example
1293
- * // 监听a.xx元素的按键按下
1294
- * DOMUtils.keypress(document.querySelector("a.xx"),()=>{
1295
- * console.log("按键按下");
1296
- * })
1297
- * DOMUtils.keypress("a.xx",()=>{
1298
- * console.log("按键按下");
1299
- * })
1300
- */
1301
- onKeypress(
1302
- element: DOMUtilsTargetElementType | Element | DocumentFragment | Window | Node | typeof globalThis,
1303
- handler: (this: HTMLElement, event: DOMUtils_Event["keypress"]) => void,
1304
- option?: boolean | DOMUtilsEventListenerOption
1305
- ) {
1306
- const that = this;
1307
- if (element == null) {
1308
- return;
1309
- }
1310
- if (typeof element === "string") {
1311
- element = that.selectorAll(element);
1312
- }
1313
- if (CommonUtils.isNodeList(element)) {
1314
- // 设置
1315
- const listenerList: (DOMUtilsAddEventListenerResult | undefined)[] = [];
1316
- element.forEach(($ele) => {
1317
- const listener = that.onKeypress($ele as HTMLElement, handler, option);
1318
- listenerList.push(listener);
1319
- });
1320
- return {
1321
- off() {
1322
- listenerList.forEach((listener) => {
1323
- if (!listener) {
1324
- return;
1325
- }
1326
- listener.off();
1327
- });
1328
- },
1329
- } as DOMUtilsAddEventListenerResult;
1330
- }
1331
- return that.on(element, "keypress", null, handler, option);
1332
- }
1333
1277
  /**
1334
1278
  * 监听某个元素键盘按键事件或window全局按键事件
1335
1279
  * 按下有值的键时触发,按下Ctrl\Alt\Shift\Meta是无值键。按下先触发keydown事件,再触发keypress事件。
@@ -1395,7 +1339,7 @@ class ElementEvent extends ElementAnimate {
1395
1339
  **/
1396
1340
  onKeyboard(
1397
1341
  element: DOMUtilsTargetElementType | Element | DocumentFragment | Window | Node | typeof globalThis,
1398
- eventName: "keydown" | "keypress" | "keyup" = "keypress",
1342
+ eventName: "keydown" | "keyup" = "keydown",
1399
1343
  handler: (keyName: string, keyValue: number, otherCodeList: string[], event: KeyboardEvent) => void,
1400
1344
  options?: DOMUtilsEventListenerOption | boolean
1401
1345
  ): DOMUtilsAddEventListenerResult {
@@ -1715,7 +1659,9 @@ class ElementEvent extends ElementAnimate {
1715
1659
  onlyStopPropagation?: boolean;
1716
1660
  }
1717
1661
  | undefined = void 0;
1718
- if (typeof args[2] === "string" || Array.isArray(args[2])) {
1662
+ if (args.length === 2) {
1663
+ // ignore
1664
+ } else if (typeof args[2] === "string" || Array.isArray(args[2])) {
1719
1665
  // selector
1720
1666
  selector = args[2];
1721
1667
  if (typeof args[3] === "object" && args[3] != null) {
package/src/Utils.ts CHANGED
@@ -103,7 +103,6 @@ class Utils {
103
103
  "is",
104
104
  "jquery",
105
105
  "keydown",
106
- "keypress",
107
106
  "keyup",
108
107
  "last",
109
108
  "load",
@@ -47,7 +47,12 @@ export type DOMUtils_MouseEventType = keyof DOMUtils_MouseEvent;
47
47
  export interface DOMUtils_KeyboardEvent {
48
48
  /** 键盘按下事件 */
49
49
  keydown: KeyboardEvent;
50
- /** 键盘按压事件(字符键) */
50
+ /**
51
+ * 键盘按压事件(字符键)
52
+ *
53
+ * @link https://developer.mozilla.org/zh-CN/docs/Web/API/Element/keypress_event
54
+ * @deprecated
55
+ */
51
56
  keypress: KeyboardEvent;
52
57
  /** 键盘释放事件 */
53
58
  keyup: KeyboardEvent;