@whitesev/domutils 1.9.5 → 1.9.6
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 +116 -36
- 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 +116 -36
- 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 +116 -36
- 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 +116 -36
- 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 +116 -36
- 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 +116 -36
- 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/ElementEvent.d.ts +70 -18
- package/package.json +1 -1
- package/src/ElementEvent.ts +200 -45
- package/src/Utils.ts +0 -3
package/dist/index.umd.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.DOMUtils = factory());
|
|
5
5
|
})(this, (function () { 'use strict';
|
|
6
6
|
|
|
7
|
-
const version = "1.9.
|
|
7
|
+
const version = "1.9.6";
|
|
8
8
|
|
|
9
9
|
class WindowApi {
|
|
10
10
|
/** 默认的配置 */
|
|
@@ -1935,7 +1935,8 @@
|
|
|
1935
1935
|
that.emit(element, "click", details, useDispatchToEmit);
|
|
1936
1936
|
}
|
|
1937
1937
|
else {
|
|
1938
|
-
that.on(element, "click", null, handler);
|
|
1938
|
+
const listener = that.on(element, "click", null, handler);
|
|
1939
|
+
return listener;
|
|
1939
1940
|
}
|
|
1940
1941
|
}
|
|
1941
1942
|
/**
|
|
@@ -1971,7 +1972,8 @@
|
|
|
1971
1972
|
that.emit(element, "blur", details, useDispatchToEmit);
|
|
1972
1973
|
}
|
|
1973
1974
|
else {
|
|
1974
|
-
that.on(element, "blur", null, handler);
|
|
1975
|
+
const listener = that.on(element, "blur", null, handler);
|
|
1976
|
+
return listener;
|
|
1975
1977
|
}
|
|
1976
1978
|
}
|
|
1977
1979
|
/**
|
|
@@ -2007,7 +2009,8 @@
|
|
|
2007
2009
|
that.emit(element, "focus", details, useDispatchToEmit);
|
|
2008
2010
|
}
|
|
2009
2011
|
else {
|
|
2010
|
-
that.on(element, "focus", null, handler);
|
|
2012
|
+
const listener = that.on(element, "focus", null, handler);
|
|
2013
|
+
return listener;
|
|
2011
2014
|
}
|
|
2012
2015
|
}
|
|
2013
2016
|
/**
|
|
@@ -2034,13 +2037,30 @@
|
|
|
2034
2037
|
}
|
|
2035
2038
|
if (CommonUtils.isNodeList(element)) {
|
|
2036
2039
|
// 设置
|
|
2040
|
+
const listenerList = [];
|
|
2037
2041
|
element.forEach(($ele) => {
|
|
2038
|
-
that.onHover($ele, handler, option);
|
|
2042
|
+
const listener = that.onHover($ele, handler, option);
|
|
2043
|
+
listenerList.push(listener);
|
|
2039
2044
|
});
|
|
2040
|
-
return
|
|
2045
|
+
return {
|
|
2046
|
+
off() {
|
|
2047
|
+
listenerList.forEach((listener) => {
|
|
2048
|
+
if (!listener) {
|
|
2049
|
+
return;
|
|
2050
|
+
}
|
|
2051
|
+
listener.off();
|
|
2052
|
+
});
|
|
2053
|
+
},
|
|
2054
|
+
};
|
|
2041
2055
|
}
|
|
2042
|
-
that.on(element, "mouseenter", null, handler, option);
|
|
2043
|
-
that.on(element, "mouseleave", null, handler, option);
|
|
2056
|
+
const mouseenter_listener = that.on(element, "mouseenter", null, handler, option);
|
|
2057
|
+
const mouseleave_listener = that.on(element, "mouseleave", null, handler, option);
|
|
2058
|
+
return {
|
|
2059
|
+
off() {
|
|
2060
|
+
mouseenter_listener.off();
|
|
2061
|
+
mouseleave_listener.off();
|
|
2062
|
+
},
|
|
2063
|
+
};
|
|
2044
2064
|
}
|
|
2045
2065
|
/**
|
|
2046
2066
|
* 监听动画结束
|
|
@@ -2123,12 +2143,23 @@
|
|
|
2123
2143
|
}
|
|
2124
2144
|
if (CommonUtils.isNodeList(element)) {
|
|
2125
2145
|
// 设置
|
|
2146
|
+
const listenerList = [];
|
|
2126
2147
|
element.forEach(($ele) => {
|
|
2127
|
-
that.onKeyup($ele, handler, option);
|
|
2148
|
+
const listener = that.onKeyup($ele, handler, option);
|
|
2149
|
+
listenerList.push(listener);
|
|
2128
2150
|
});
|
|
2129
|
-
return
|
|
2151
|
+
return {
|
|
2152
|
+
off() {
|
|
2153
|
+
listenerList.forEach((listener) => {
|
|
2154
|
+
if (!listener) {
|
|
2155
|
+
return;
|
|
2156
|
+
}
|
|
2157
|
+
listener.off();
|
|
2158
|
+
});
|
|
2159
|
+
},
|
|
2160
|
+
};
|
|
2130
2161
|
}
|
|
2131
|
-
that.on(element, "keyup", null, handler, option);
|
|
2162
|
+
return that.on(element, "keyup", null, handler, option);
|
|
2132
2163
|
}
|
|
2133
2164
|
/**
|
|
2134
2165
|
* 当按键按下时触发事件
|
|
@@ -2155,12 +2186,23 @@
|
|
|
2155
2186
|
}
|
|
2156
2187
|
if (CommonUtils.isNodeList(element)) {
|
|
2157
2188
|
// 设置
|
|
2189
|
+
const listenerList = [];
|
|
2158
2190
|
element.forEach(($ele) => {
|
|
2159
|
-
that.onKeydown($ele, handler, option);
|
|
2191
|
+
const listener = that.onKeydown($ele, handler, option);
|
|
2192
|
+
listenerList.push(listener);
|
|
2160
2193
|
});
|
|
2161
|
-
return
|
|
2194
|
+
return {
|
|
2195
|
+
off() {
|
|
2196
|
+
listenerList.forEach((listener) => {
|
|
2197
|
+
if (!listener) {
|
|
2198
|
+
return;
|
|
2199
|
+
}
|
|
2200
|
+
listener.off();
|
|
2201
|
+
});
|
|
2202
|
+
},
|
|
2203
|
+
};
|
|
2162
2204
|
}
|
|
2163
|
-
that.on(element, "keydown", null, handler, option);
|
|
2205
|
+
return that.on(element, "keydown", null, handler, option);
|
|
2164
2206
|
}
|
|
2165
2207
|
/**
|
|
2166
2208
|
* 当按键按下时触发事件
|
|
@@ -2187,12 +2229,23 @@
|
|
|
2187
2229
|
}
|
|
2188
2230
|
if (CommonUtils.isNodeList(element)) {
|
|
2189
2231
|
// 设置
|
|
2232
|
+
const listenerList = [];
|
|
2190
2233
|
element.forEach(($ele) => {
|
|
2191
|
-
that.onKeypress($ele, handler, option);
|
|
2234
|
+
const listener = that.onKeypress($ele, handler, option);
|
|
2235
|
+
listenerList.push(listener);
|
|
2192
2236
|
});
|
|
2193
|
-
return
|
|
2237
|
+
return {
|
|
2238
|
+
off() {
|
|
2239
|
+
listenerList.forEach((listener) => {
|
|
2240
|
+
if (!listener) {
|
|
2241
|
+
return;
|
|
2242
|
+
}
|
|
2243
|
+
listener.off();
|
|
2244
|
+
});
|
|
2245
|
+
},
|
|
2246
|
+
};
|
|
2194
2247
|
}
|
|
2195
|
-
that.on(element, "keypress", null, handler, option);
|
|
2248
|
+
return that.on(element, "keypress", null, handler, option);
|
|
2196
2249
|
}
|
|
2197
2250
|
/**
|
|
2198
2251
|
* 监听某个元素键盘按键事件或window全局按键事件
|
|
@@ -2285,12 +2338,8 @@
|
|
|
2285
2338
|
handler(keyName, keyValue, otherCodeList, event);
|
|
2286
2339
|
}
|
|
2287
2340
|
};
|
|
2288
|
-
that.on(element, eventName, keyboardEventCallBack, options);
|
|
2289
|
-
return
|
|
2290
|
-
removeListen: () => {
|
|
2291
|
-
that.off(element, eventName, keyboardEventCallBack, options);
|
|
2292
|
-
},
|
|
2293
|
-
};
|
|
2341
|
+
const listener = that.on(element, eventName, keyboardEventCallBack, options);
|
|
2342
|
+
return listener;
|
|
2294
2343
|
}
|
|
2295
2344
|
/**
|
|
2296
2345
|
* 监input、textarea的输入框值改变的事件(当输入法输入时,不会触发该监听)
|
|
@@ -2321,11 +2370,14 @@
|
|
|
2321
2370
|
const compositionStartListener = this.on($el, "compositionstart", __composition_start_callback, option);
|
|
2322
2371
|
const compositionEndListener = this.on($el, "compositionend", __composition_end_callback, option);
|
|
2323
2372
|
return {
|
|
2324
|
-
off
|
|
2373
|
+
off() {
|
|
2325
2374
|
inputListener.off();
|
|
2326
2375
|
compositionStartListener.off();
|
|
2327
2376
|
compositionEndListener.off();
|
|
2328
2377
|
},
|
|
2378
|
+
emit(details, useDispatchToEmit) {
|
|
2379
|
+
inputListener.emit(details, useDispatchToEmit);
|
|
2380
|
+
},
|
|
2329
2381
|
};
|
|
2330
2382
|
}
|
|
2331
2383
|
onDoubleClick(...args) {
|
|
@@ -2408,28 +2460,56 @@
|
|
|
2408
2460
|
/**
|
|
2409
2461
|
* 阻止事件的默认行为发生,并阻止事件传播
|
|
2410
2462
|
*/
|
|
2411
|
-
const stopEvent = (event) => {
|
|
2412
|
-
|
|
2463
|
+
const stopEvent = (event, onlyStopPropagation) => {
|
|
2464
|
+
if (typeof onlyStopPropagation === "boolean" && onlyStopPropagation) {
|
|
2465
|
+
// 停止事件的传播,阻止它继续向更上层的元素冒泡,事件将不会再传播给其他的元素
|
|
2466
|
+
event?.stopPropagation();
|
|
2467
|
+
// 阻止事件传播,并且还能阻止元素上的其他事件处理程序被触发
|
|
2468
|
+
event?.stopImmediatePropagation();
|
|
2469
|
+
return;
|
|
2470
|
+
}
|
|
2471
|
+
// 阻止事件的默认行为发生。例如,当点击一个链接时,浏览器会默认打开链接的URL,或者在输入框内输入文字
|
|
2413
2472
|
event?.preventDefault();
|
|
2414
|
-
/* 停止事件的传播,阻止它继续向更上层的元素冒泡,事件将不会再传播给其他的元素 */
|
|
2415
|
-
event?.stopPropagation();
|
|
2416
|
-
/* 阻止事件传播,并且还能阻止元素上的其他事件处理程序被触发 */
|
|
2417
|
-
event?.stopImmediatePropagation();
|
|
2418
2473
|
return false;
|
|
2419
2474
|
};
|
|
2420
|
-
if (args
|
|
2421
|
-
|
|
2422
|
-
|
|
2475
|
+
if (args[0] instanceof Event) {
|
|
2476
|
+
// 直接阻止事件
|
|
2477
|
+
const onlyStopPropagation = args[1];
|
|
2478
|
+
return stopEvent(args[0], onlyStopPropagation);
|
|
2423
2479
|
}
|
|
2424
2480
|
else {
|
|
2425
2481
|
const $el = args[0];
|
|
2426
2482
|
let eventNameList = args[1];
|
|
2427
|
-
|
|
2428
|
-
|
|
2483
|
+
let selector = void 0;
|
|
2484
|
+
let capture = false;
|
|
2485
|
+
let onlyStopPropagation = false;
|
|
2486
|
+
// 添加对应的事件来阻止触发
|
|
2429
2487
|
if (typeof eventNameList === "string") {
|
|
2430
2488
|
eventNameList = [eventNameList];
|
|
2431
2489
|
}
|
|
2432
|
-
|
|
2490
|
+
let option = void 0;
|
|
2491
|
+
if (typeof args[2] === "string" || Array.isArray(args[2])) {
|
|
2492
|
+
// selector
|
|
2493
|
+
selector = args[2];
|
|
2494
|
+
if (typeof args[3] === "object" && args[3] != null) {
|
|
2495
|
+
option = args[3];
|
|
2496
|
+
}
|
|
2497
|
+
}
|
|
2498
|
+
else if (typeof args[2] === "object" && args[2] != null && !Array.isArray(args[2])) {
|
|
2499
|
+
// option
|
|
2500
|
+
option = args[2];
|
|
2501
|
+
}
|
|
2502
|
+
else {
|
|
2503
|
+
throw new TypeError("Invalid argument");
|
|
2504
|
+
}
|
|
2505
|
+
if (option) {
|
|
2506
|
+
capture = Boolean(option.capture);
|
|
2507
|
+
onlyStopPropagation = Boolean(option.onlyStopPropagation);
|
|
2508
|
+
}
|
|
2509
|
+
const listener = this.on($el, eventNameList, selector, (evt) => {
|
|
2510
|
+
return stopEvent(evt, onlyStopPropagation);
|
|
2511
|
+
}, { capture: capture });
|
|
2512
|
+
return listener;
|
|
2433
2513
|
}
|
|
2434
2514
|
}
|
|
2435
2515
|
}
|