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