@whitesev/domutils 1.7.4 → 1.8.0

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.umd.js CHANGED
@@ -527,13 +527,7 @@
527
527
  },
528
528
  };
529
529
 
530
- const version = "1.7.4";
531
-
532
- /* 数据 */
533
- const GlobalData = {
534
- /** .on添加在元素存储的事件 */
535
- domEventSymbol: Symbol("events_" + (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1)),
536
- };
530
+ const version = "1.8.0";
537
531
 
538
532
  class ElementSelector {
539
533
  windowApi;
@@ -905,35 +899,41 @@
905
899
  if (target == null) {
906
900
  target = {};
907
901
  }
902
+ // 当前遍历的目标对象
903
+ let iteratorTarget;
908
904
  if (isAdd) {
909
- for (const sourceKeyName in source) {
910
- const targetKeyName = sourceKeyName;
911
- const targetValue = Reflect.get(target, targetKeyName);
912
- const sourceValue = Reflect.get(source, sourceKeyName);
913
- if (typeof sourceValue === "object" && sourceValue != null && sourceKeyName in target && !isDOM(sourceValue)) {
914
- /* 源端的值是object类型,且不是元素节点 */
915
- Reflect.set(target, sourceKeyName, UtilsContext.assign(targetValue, sourceValue, isAdd));
916
- continue;
917
- }
918
- Reflect.set(target, sourceKeyName, sourceValue);
919
- }
905
+ // 追加并覆盖是以source为准
906
+ iteratorTarget = source;
920
907
  }
921
908
  else {
922
- for (const targetKeyName in target) {
923
- if (targetKeyName in source) {
924
- const targetValue = Reflect.get(target, targetKeyName);
925
- const sourceValue = Reflect.get(source, targetKeyName);
926
- if (typeof sourceValue === "object" &&
927
- sourceValue != null &&
928
- !isDOM(sourceValue) &&
929
- Object.keys(sourceValue).length) {
930
- /* 源端的值是object类型,且不是元素节点 */
931
- Reflect.set(target, targetKeyName, UtilsContext.assign(targetValue, sourceValue, isAdd));
932
- continue;
909
+ // 覆盖以target为准
910
+ iteratorTarget = target;
911
+ }
912
+ for (const keyName in iteratorTarget) {
913
+ if (!isAdd && !(keyName in source)) {
914
+ // 仅替换 但是源端没有此键
915
+ continue;
916
+ }
917
+ const targetValue = Reflect.get(target, keyName);
918
+ const sourceValue = Reflect.get(source, keyName);
919
+ if (typeof sourceValue === "object" && sourceValue != null && keyName in target && !isDOM(sourceValue)) {
920
+ // 源端的值是object类型,且不是元素节点
921
+ // 如果是数组,那此数组中有值,清空旧的数组再赋值
922
+ let childObjectValue;
923
+ if (Array.isArray(sourceValue)) {
924
+ if (Array.isArray(targetValue)) {
925
+ targetValue.length = 0;
933
926
  }
934
- /* 直接赋值 */
935
- Reflect.set(target, targetKeyName, sourceValue);
927
+ childObjectValue = sourceValue;
928
+ }
929
+ else {
930
+ childObjectValue = UtilsContext.assign(targetValue, sourceValue, isAdd);
936
931
  }
932
+ Reflect.set(target, keyName, childObjectValue);
933
+ }
934
+ else {
935
+ /* 直接赋值 */
936
+ Reflect.set(target, keyName, sourceValue);
937
937
  }
938
938
  }
939
939
  return target;
@@ -1620,6 +1620,12 @@
1620
1620
  }
1621
1621
  new ElementAnimate();
1622
1622
 
1623
+ /* 数据 */
1624
+ const GlobalData = {
1625
+ /** .on添加在元素存储的事件 */
1626
+ domEventSymbol: Symbol("events_" + (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1)),
1627
+ };
1628
+
1623
1629
  const OriginPrototype = {
1624
1630
  Object: {
1625
1631
  defineProperty: Object.defineProperty,
@@ -1679,7 +1685,7 @@
1679
1685
  if (element == null) {
1680
1686
  return {
1681
1687
  off() { },
1682
- trigger() { },
1688
+ emit() { },
1683
1689
  };
1684
1690
  }
1685
1691
  let $elList = [];
@@ -1814,10 +1820,10 @@
1814
1820
  /**
1815
1821
  * 主动触发事件
1816
1822
  * @param details 赋予触发的Event的额外属性,如果是Event类型,那么将自动代替默认new的Event对象
1817
- * @param useDispatchToTriggerEvent 是否使用dispatchEvent来触发事件,默认true,如果为false,则直接调用callback,但是这种会让使用了selectorTarget的没有值
1823
+ * @param useDispatchToEmit 是否使用dispatchEvent来触发事件,默认true,如果为false,则直接调用callback,但是这种会让使用了selectorTarget的没有值
1818
1824
  */
1819
- trigger: (details, useDispatchToTriggerEvent) => {
1820
- that.trigger($elList, eventTypeList, details, useDispatchToTriggerEvent);
1825
+ emit: (details, useDispatchToEmit) => {
1826
+ that.emit($elList, eventTypeList, details, useDispatchToEmit);
1821
1827
  },
1822
1828
  };
1823
1829
  }
@@ -1996,7 +2002,7 @@
1996
2002
  });
1997
2003
  });
1998
2004
  }
1999
- ready(...args) {
2005
+ onReady(...args) {
2000
2006
  const callback = args[0];
2001
2007
  // 异步回调
2002
2008
  let resolve = void 0;
@@ -2090,16 +2096,16 @@
2090
2096
  * @param element 需要触发的元素|元素数组|window
2091
2097
  * @param eventType 需要触发的事件
2092
2098
  * @param details 赋予触发的Event的额外属性,如果是Event类型,那么将自动代替默认new的Event对象
2093
- * @param useDispatchToTriggerEvent 是否使用dispatchEvent来触发事件,默认true,如果为false,则直接调用callback,但是这种会让使用了selectorTarget的没有值
2099
+ * @param useDispatchToEmit 是否使用dispatchEvent来触发事件,默认true,如果为false,则直接调用callback,但是这种会让使用了selectorTarget的没有值
2094
2100
  * @example
2095
2101
  * // 触发元素a.xx的click事件
2096
- * DOMUtils.trigger(document.querySelector("a.xx"),"click")
2097
- * DOMUtils.trigger("a.xx","click")
2102
+ * DOMUtils.emit(document.querySelector("a.xx"),"click")
2103
+ * DOMUtils.emit("a.xx","click")
2098
2104
  * // 触发元素a.xx的click、tap、hover事件
2099
- * DOMUtils.trigger(document.querySelector("a.xx"),"click tap hover")
2100
- * DOMUtils.trigger("a.xx",["click","tap","hover"])
2105
+ * DOMUtils.emit(document.querySelector("a.xx"),"click tap hover")
2106
+ * DOMUtils.emit("a.xx",["click","tap","hover"])
2101
2107
  */
2102
- trigger(element, eventType, details, useDispatchToTriggerEvent = true) {
2108
+ emit(element, eventType, details, useDispatchToEmit = true) {
2103
2109
  const that = this;
2104
2110
  if (typeof element === "string") {
2105
2111
  element = that.selectorAll(element);
@@ -2141,7 +2147,7 @@
2141
2147
  });
2142
2148
  }
2143
2149
  }
2144
- if (useDispatchToTriggerEvent == false && eventTypeItem in elementEvents) {
2150
+ if (useDispatchToEmit == false && eventTypeItem in elementEvents) {
2145
2151
  // 直接调用监听的事件
2146
2152
  elementEvents[eventTypeItem].forEach((eventsItem) => {
2147
2153
  eventsItem.callback(event);
@@ -2154,11 +2160,11 @@
2154
2160
  });
2155
2161
  }
2156
2162
  /**
2157
- * 绑定或触发元素的click事件
2163
+ * 监听或触发元素的click事件
2158
2164
  * @param element 目标元素
2159
2165
  * @param handler (可选)事件处理函数
2160
2166
  * @param details (可选)赋予触发的Event的额外属性
2161
- * @param useDispatchToTriggerEvent (可选)是否使用dispatchEvent来触发事件,默认true
2167
+ * @param useDispatchToEmit (可选)是否使用dispatchEvent来触发事件,默认true
2162
2168
  * @example
2163
2169
  * // 触发元素a.xx的click事件
2164
2170
  * DOMUtils.click(document.querySelector("a.xx"))
@@ -2167,7 +2173,7 @@
2167
2173
  * console.log("触发click事件成功")
2168
2174
  * })
2169
2175
  * */
2170
- click(element, handler, details, useDispatchToTriggerEvent) {
2176
+ click(element, handler, details, useDispatchToEmit) {
2171
2177
  const that = this;
2172
2178
  if (typeof element === "string") {
2173
2179
  element = that.selectorAll(element);
@@ -2178,23 +2184,23 @@
2178
2184
  if (CommonUtils.isNodeList(element)) {
2179
2185
  // 设置
2180
2186
  element.forEach(($ele) => {
2181
- that.click($ele, handler, details, useDispatchToTriggerEvent);
2187
+ that.click($ele, handler, details, useDispatchToEmit);
2182
2188
  });
2183
2189
  return;
2184
2190
  }
2185
2191
  if (handler == null) {
2186
- that.trigger(element, "click", details, useDispatchToTriggerEvent);
2192
+ that.emit(element, "click", details, useDispatchToEmit);
2187
2193
  }
2188
2194
  else {
2189
2195
  that.on(element, "click", null, handler);
2190
2196
  }
2191
2197
  }
2192
2198
  /**
2193
- * 绑定或触发元素的blur事件
2199
+ * 监听或触发元素的blur事件
2194
2200
  * @param element 目标元素
2195
2201
  * @param handler (可选)事件处理函数
2196
2202
  * @param details (可选)赋予触发的Event的额外属性
2197
- * @param useDispatchToTriggerEvent (可选)是否使用dispatchEvent来触发事件,默认true
2203
+ * @param useDispatchToEmit (可选)是否使用dispatchEvent来触发事件,默认true
2198
2204
  * @example
2199
2205
  * // 触发元素a.xx的blur事件
2200
2206
  * DOMUtils.blur(document.querySelector("a.xx"))
@@ -2203,7 +2209,7 @@
2203
2209
  * console.log("触发blur事件成功")
2204
2210
  * })
2205
2211
  * */
2206
- blur(element, handler, details, useDispatchToTriggerEvent) {
2212
+ blur(element, handler, details, useDispatchToEmit) {
2207
2213
  const that = this;
2208
2214
  if (typeof element === "string") {
2209
2215
  element = that.selectorAll(element);
@@ -2214,23 +2220,23 @@
2214
2220
  if (CommonUtils.isNodeList(element)) {
2215
2221
  // 设置
2216
2222
  element.forEach(($ele) => {
2217
- that.focus($ele, handler, details, useDispatchToTriggerEvent);
2223
+ that.focus($ele, handler, details, useDispatchToEmit);
2218
2224
  });
2219
2225
  return;
2220
2226
  }
2221
2227
  if (handler === null) {
2222
- that.trigger(element, "blur", details, useDispatchToTriggerEvent);
2228
+ that.emit(element, "blur", details, useDispatchToEmit);
2223
2229
  }
2224
2230
  else {
2225
2231
  that.on(element, "blur", null, handler);
2226
2232
  }
2227
2233
  }
2228
2234
  /**
2229
- * 绑定或触发元素的focus事件
2235
+ * 监听或触发元素的focus事件
2230
2236
  * @param element 目标元素
2231
2237
  * @param handler (可选)事件处理函数
2232
2238
  * @param details (可选)赋予触发的Event的额外属性
2233
- * @param useDispatchToTriggerEvent (可选)是否使用dispatchEvent来触发事件,默认true
2239
+ * @param useDispatchToEmit (可选)是否使用dispatchEvent来触发事件,默认true
2234
2240
  * @example
2235
2241
  * // 触发元素a.xx的focus事件
2236
2242
  * DOMUtils.focus(document.querySelector("a.xx"))
@@ -2239,7 +2245,7 @@
2239
2245
  * console.log("触发focus事件成功")
2240
2246
  * })
2241
2247
  * */
2242
- focus(element, handler, details, useDispatchToTriggerEvent) {
2248
+ focus(element, handler, details, useDispatchToEmit) {
2243
2249
  const that = this;
2244
2250
  if (typeof element === "string") {
2245
2251
  element = that.selectorAll(element);
@@ -2250,12 +2256,12 @@
2250
2256
  if (CommonUtils.isNodeList(element)) {
2251
2257
  // 设置
2252
2258
  element.forEach(($ele) => {
2253
- that.focus($ele, handler, details, useDispatchToTriggerEvent);
2259
+ that.focus($ele, handler, details, useDispatchToEmit);
2254
2260
  });
2255
2261
  return;
2256
2262
  }
2257
2263
  if (handler == null) {
2258
- that.trigger(element, "focus", details, useDispatchToTriggerEvent);
2264
+ that.emit(element, "focus", details, useDispatchToEmit);
2259
2265
  }
2260
2266
  else {
2261
2267
  that.on(element, "focus", null, handler);
@@ -2268,14 +2274,14 @@
2268
2274
  * @param option 配置
2269
2275
  * @example
2270
2276
  * // 监听a.xx元素的移入或移出
2271
- * DOMUtils.hover(document.querySelector("a.xx"),()=>{
2277
+ * DOMUtils.onHover(document.querySelector("a.xx"),()=>{
2272
2278
  * console.log("移入/移除");
2273
2279
  * })
2274
- * DOMUtils.hover("a.xx",()=>{
2280
+ * DOMUtils.onHover("a.xx",()=>{
2275
2281
  * console.log("移入/移除");
2276
2282
  * })
2277
2283
  */
2278
- hover(element, handler, option) {
2284
+ onHover(element, handler, option) {
2279
2285
  const that = this;
2280
2286
  if (typeof element === "string") {
2281
2287
  element = that.selectorAll(element);
@@ -2286,7 +2292,7 @@
2286
2292
  if (CommonUtils.isNodeList(element)) {
2287
2293
  // 设置
2288
2294
  element.forEach(($ele) => {
2289
- that.hover($ele, handler, option);
2295
+ that.onHover($ele, handler, option);
2290
2296
  });
2291
2297
  return;
2292
2298
  }
@@ -2294,12 +2300,12 @@
2294
2300
  that.on(element, "mouseleave", null, handler, option);
2295
2301
  }
2296
2302
  /**
2297
- * 当动画结束时触发事件
2303
+ * 监听动画结束
2298
2304
  * @param element 监听的元素
2299
2305
  * @param handler 触发的回调函数
2300
2306
  * @param option 配置项,这里默认配置once为true
2301
2307
  */
2302
- animationend(element, handler, option) {
2308
+ onAnimationend(element, handler, option) {
2303
2309
  const that = this;
2304
2310
  if (typeof element === "string") {
2305
2311
  element = that.selector(element);
@@ -2322,12 +2328,12 @@
2322
2328
  }
2323
2329
  }
2324
2330
  /**
2325
- * 当过渡结束时触发事件
2331
+ * 监听过渡结束
2326
2332
  * @param element 监听的元素
2327
2333
  * @param handler 触发的回调函数
2328
2334
  * @param option 配置项,这里默认配置once为true
2329
2335
  */
2330
- transitionend(element, handler, option) {
2336
+ onTransitionend(element, handler, option) {
2331
2337
  const that = this;
2332
2338
  if (typeof element === "string") {
2333
2339
  element = that.selector(element);
@@ -2364,7 +2370,7 @@
2364
2370
  * console.log("按键松开");
2365
2371
  * })
2366
2372
  */
2367
- keyup(element, handler, option) {
2373
+ onKeyup(element, handler, option) {
2368
2374
  const that = this;
2369
2375
  if (element == null) {
2370
2376
  return;
@@ -2375,7 +2381,7 @@
2375
2381
  if (CommonUtils.isNodeList(element)) {
2376
2382
  // 设置
2377
2383
  element.forEach(($ele) => {
2378
- that.keyup($ele, handler, option);
2384
+ that.onKeyup($ele, handler, option);
2379
2385
  });
2380
2386
  return;
2381
2387
  }
@@ -2396,7 +2402,7 @@
2396
2402
  * console.log("按键按下");
2397
2403
  * })
2398
2404
  */
2399
- keydown(element, handler, option) {
2405
+ onKeydown(element, handler, option) {
2400
2406
  const that = this;
2401
2407
  if (element == null) {
2402
2408
  return;
@@ -2407,7 +2413,7 @@
2407
2413
  if (CommonUtils.isNodeList(element)) {
2408
2414
  // 设置
2409
2415
  element.forEach(($ele) => {
2410
- that.keydown($ele, handler, option);
2416
+ that.onKeydown($ele, handler, option);
2411
2417
  });
2412
2418
  return;
2413
2419
  }
@@ -2428,7 +2434,7 @@
2428
2434
  * console.log("按键按下");
2429
2435
  * })
2430
2436
  */
2431
- keypress(element, handler, option) {
2437
+ onKeypress(element, handler, option) {
2432
2438
  const that = this;
2433
2439
  if (element == null) {
2434
2440
  return;
@@ -2439,76 +2445,76 @@
2439
2445
  if (CommonUtils.isNodeList(element)) {
2440
2446
  // 设置
2441
2447
  element.forEach(($ele) => {
2442
- that.keypress($ele, handler, option);
2448
+ that.onKeypress($ele, handler, option);
2443
2449
  });
2444
2450
  return;
2445
2451
  }
2446
2452
  that.on(element, "keypress", null, handler, option);
2447
2453
  }
2448
2454
  /**
2449
- * 监听某个元素键盘按键事件或window全局按键事件
2450
- * 按下有值的键时触发,按下Ctrl\Alt\Shift\Meta是无值键。按下先触发keydown事件,再触发keypress事件。
2451
- * @param element 需要监听的对象,可以是全局Window或者某个元素
2452
- * @param eventName 事件名,默认keypress
2453
- * @param callback 自己定义的回调事件,参数1为当前的key,参数2为组合按键,数组类型,包含ctrl、shift、alt和meta(win键或mac的cmd键)
2455
+ * 监听某个元素键盘按键事件或window全局按键事件
2456
+ * 按下有值的键时触发,按下Ctrl\Alt\Shift\Meta是无值键。按下先触发keydown事件,再触发keypress事件。
2457
+ * @param element 需要监听的对象,可以是全局Window或者某个元素
2458
+ * @param eventName 事件名,默认keypress,keydown - > keypress - > keyup
2459
+ * @param handler 自己定义的回调事件,参数1为当前的key,参数2为组合按键,数组类型,包含ctrl、shift、alt和meta(win键或mac的cmd键)
2454
2460
  * @param options 监听事件的配置
2455
- * @example
2456
- Utils.listenKeyboard(window,(keyName,keyValue,otherKey,event)=>{
2457
- if(keyName === "Enter"){
2458
- console.log("回车按键的值是:"+keyValue)
2459
- }
2460
- if(otherKey.indexOf("ctrl") && keyName === "Enter" ){
2461
- console.log("Ctrl和回车键");
2462
- }
2463
- })
2464
- * @example
2465
- 字母和数字键的键码值(keyCode)
2466
- 按键 键码 按键 键码 按键 键码 按键 键码
2467
- A 65 J 74 S 83 1 49
2468
- B 66 K 75 T 84 2 50
2469
- C 67 L 76 U 85 3 51
2470
- D 68 M 77 V 86 4 52
2471
- E 69 N 78 W 87 5 53
2472
- F 70 O 79 X 88 6 54
2473
- G 71 P 80 Y 89 7 55
2474
- H 72 Q 81 Z 90 8 56
2475
- I 73 R 82 0 48 9 57
2476
-
2477
- 数字键盘上的键的键码值(keyCode)
2478
- 功能键键码值(keyCode)
2479
- 按键 键码 按键 键码 按键 键码 按键 键码
2480
- 0 96 8 104 F1 112 F7 118
2481
- 1 97 9 105 F2 113 F8 119
2482
- 2 98 * 106 F3 114 F9 120
2483
- 3 99 + 107 F4 115 F10 121
2484
- 4 100 Enter 108 F5 116 F11 122
2485
- 5 101 - 109 F6 117 F12 123
2486
- 6 102 . 110
2487
- 7 103 / 111
2488
-
2489
- 控制键键码值(keyCode)
2490
- 按键 键码 按键 键码 按键 键码 按键 键码
2491
- BackSpace 8 Esc 27 → 39 -_ 189
2492
- Tab 9 Spacebar 32 ↓ 40 .> 190
2493
- Clear 12 Page Up 33 Insert 45 /? 191
2494
- Enter 13 Page Down 34 Delete 46 `~ 192
2495
- Shift 16 End 35 Num Lock 144 [{ 219
2496
- Control 17 Home 36 ;: 186 \| 220
2497
- Alt 18 ← 37 =+ 187 ]} 221
2498
- Cape Lock 20 ↑ 38 ,< 188 '" 222
2499
-
2500
- 多媒体键码值(keyCode)
2501
- 按键 键码
2502
- 音量加 175
2503
- 音量减 174
2504
- 停止 179
2505
- 静音 173
2506
- 浏览器 172
2507
- 邮件 180
2508
- 搜索 170
2509
- 收藏 171
2510
- **/
2511
- listenKeyboard(element, eventName = "keypress", callback, options) {
2461
+ * @example
2462
+ Utils.onKeyboard(window,(keyName,keyValue,otherKey,event)=>{
2463
+ if(keyName === "Enter"){
2464
+ console.log("回车按键的值是:"+keyValue)
2465
+ }
2466
+ if(otherKey.indexOf("ctrl") && keyName === "Enter" ){
2467
+ console.log("Ctrl和回车键");
2468
+ }
2469
+ })
2470
+ * @example
2471
+ 字母和数字键的键码值(keyCode)
2472
+ 按键 键码 按键 键码 按键 键码 按键 键码
2473
+ A 65 J 74 S 83 1 49
2474
+ B 66 K 75 T 84 2 50
2475
+ C 67 L 76 U 85 3 51
2476
+ D 68 M 77 V 86 4 52
2477
+ E 69 N 78 W 87 5 53
2478
+ F 70 O 79 X 88 6 54
2479
+ G 71 P 80 Y 89 7 55
2480
+ H 72 Q 81 Z 90 8 56
2481
+ I 73 R 82 0 48 9 57
2482
+
2483
+ 数字键盘上的键的键码值(keyCode)
2484
+ 功能键键码值(keyCode)
2485
+ 按键 键码 按键 键码 按键 键码 按键 键码
2486
+ 0 96 8 104 F1 112 F7 118
2487
+ 1 97 9 105 F2 113 F8 119
2488
+ 2 98 * 106 F3 114 F9 120
2489
+ 3 99 + 107 F4 115 F10 121
2490
+ 4 100 Enter 108 F5 116 F11 122
2491
+ 5 101 - 109 F6 117 F12 123
2492
+ 6 102 . 110
2493
+ 7 103 / 111
2494
+
2495
+ 控制键键码值(keyCode)
2496
+ 按键 键码 按键 键码 按键 键码 按键 键码
2497
+ BackSpace 8 Esc 27 → 39 -_ 189
2498
+ Tab 9 Spacebar 32 ↓ 40 .> 190
2499
+ Clear 12 Page Up 33 Insert 45 /? 191
2500
+ Enter 13 Page Down 34 Delete 46 `~ 192
2501
+ Shift 16 End 35 Num Lock 144 [{ 219
2502
+ Control 17 Home 36 ;: 186 \| 220
2503
+ Alt 18 ← 37 =+ 187 ]} 221
2504
+ Cape Lock 20 ↑ 38 ,< 188 '" 222
2505
+
2506
+ 多媒体键码值(keyCode)
2507
+ 按键 键码
2508
+ 音量加 175
2509
+ 音量减 174
2510
+ 停止 179
2511
+ 静音 173
2512
+ 浏览器 172
2513
+ 邮件 180
2514
+ 搜索 170
2515
+ 收藏 171
2516
+ **/
2517
+ onKeyboard(element, eventName = "keypress", handler, options) {
2512
2518
  const that = this;
2513
2519
  if (typeof element === "string") {
2514
2520
  element = that.selectorAll(element);
@@ -2532,8 +2538,8 @@
2532
2538
  if (event.shiftKey) {
2533
2539
  otherCodeList.push("shift");
2534
2540
  }
2535
- if (typeof callback === "function") {
2536
- callback(keyName, keyValue, otherCodeList, event);
2541
+ if (typeof handler === "function") {
2542
+ handler(keyName, keyValue, otherCodeList, event);
2537
2543
  }
2538
2544
  };
2539
2545
  that.on(element, eventName, keyboardEventCallBack, options);
@@ -2543,6 +2549,113 @@
2543
2549
  },
2544
2550
  };
2545
2551
  }
2552
+ /**
2553
+ * 监input、textarea的输入框值改变的事件(当输入法输入时,不会触发该监听)
2554
+ * @param $el 输入框元素
2555
+ * @param handler 回调函数
2556
+ * @param option 配置
2557
+ */
2558
+ onInput($el, handler, option) {
2559
+ /**
2560
+ * 是否正在输入中
2561
+ */
2562
+ let isComposite = false;
2563
+ const __callback = async (event) => {
2564
+ if (isComposite)
2565
+ return;
2566
+ await handler(event);
2567
+ };
2568
+ const __composition_start_callback = () => {
2569
+ isComposite = true;
2570
+ };
2571
+ const __composition_end_callback = () => {
2572
+ isComposite = false;
2573
+ this.emit($el, "input", {
2574
+ isComposite,
2575
+ });
2576
+ };
2577
+ const inputListener = this.on($el, "input", __callback, option);
2578
+ const compositionStartListener = this.on($el, "compositionstart", __composition_start_callback, option);
2579
+ const compositionEndListener = this.on($el, "compositionend", __composition_end_callback, option);
2580
+ return {
2581
+ off: () => {
2582
+ inputListener.off();
2583
+ compositionStartListener.off();
2584
+ compositionEndListener.off();
2585
+ },
2586
+ };
2587
+ }
2588
+ onDoubleClick(...args) {
2589
+ const $el = args[0];
2590
+ let selector = void 0;
2591
+ let handler;
2592
+ let options;
2593
+ if (args.length === 2) {
2594
+ if (typeof args[1] === "function") {
2595
+ handler = args[1];
2596
+ }
2597
+ else {
2598
+ throw new TypeError("handler is not a function");
2599
+ }
2600
+ }
2601
+ else if (args.length === 3) {
2602
+ if (typeof args[1] === "function") {
2603
+ handler = args[1];
2604
+ options = args[2];
2605
+ }
2606
+ else {
2607
+ selector = args[1];
2608
+ handler = args[2];
2609
+ }
2610
+ }
2611
+ else if (args.length === 4) {
2612
+ selector = args[1];
2613
+ handler = args[2];
2614
+ options = args[3];
2615
+ }
2616
+ else {
2617
+ throw new Error("args length error");
2618
+ }
2619
+ let $click = null;
2620
+ let isDoubleClick = false;
2621
+ let timer = void 0;
2622
+ /** 是否是移动端点击 */
2623
+ let isMobileTouch = false;
2624
+ const dblclick_handler = async (evt) => {
2625
+ if (evt.type === "dblclick" && isMobileTouch) {
2626
+ // 禁止在移动端触发dblclick事件
2627
+ return;
2628
+ }
2629
+ await handler(evt);
2630
+ };
2631
+ const dblClickListener = this.on($el, "dblclick", dblclick_handler, options);
2632
+ const touchEndListener = this.on($el, "touchend", selector, (evt, selectorTarget) => {
2633
+ isMobileTouch = true;
2634
+ CommonUtils.clearTimeout(timer);
2635
+ timer = void 0;
2636
+ if (isDoubleClick && $click === selectorTarget) {
2637
+ isDoubleClick = false;
2638
+ $click = null;
2639
+ /* 判定为双击 */
2640
+ dblclick_handler(evt);
2641
+ }
2642
+ else {
2643
+ timer = CommonUtils.setTimeout(() => {
2644
+ isDoubleClick = false;
2645
+ // 判断为单击
2646
+ }, 200);
2647
+ isDoubleClick = true;
2648
+ $click = selectorTarget;
2649
+ }
2650
+ }, options);
2651
+ return {
2652
+ off() {
2653
+ $click = null;
2654
+ dblClickListener.off();
2655
+ touchEndListener.off();
2656
+ },
2657
+ };
2658
+ }
2546
2659
  preventEvent(...args) {
2547
2660
  /**
2548
2661
  * 阻止事件的默认行为发生,并阻止事件传播