@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/README.md +4 -4
- package/dist/index.amd.js +249 -136
- 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 +249 -136
- 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 +249 -136
- 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 +249 -136
- 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 +249 -136
- 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 +249 -136
- 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/eslint.config.d.mts +2 -0
- package/dist/types/src/ElementEvent.d.ts +123 -105
- package/dist/types/src/types/DOMUtilsEvent.d.ts +2 -2
- package/package.json +10 -10
- package/src/ElementEvent.ts +270 -135
- package/src/Utils.ts +28 -26
- package/src/types/DOMUtilsEvent.d.ts +2 -2
package/src/Utils.ts
CHANGED
|
@@ -211,36 +211,38 @@ class Utils {
|
|
|
211
211
|
if (target == null) {
|
|
212
212
|
target = {};
|
|
213
213
|
}
|
|
214
|
+
// 当前遍历的目标对象
|
|
215
|
+
let iteratorTarget;
|
|
214
216
|
if (isAdd) {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
const targetValue = Reflect.get(target, targetKeyName);
|
|
218
|
-
const sourceValue = Reflect.get(source, sourceKeyName);
|
|
219
|
-
if (typeof sourceValue === "object" && sourceValue != null && sourceKeyName in target && !isDOM(sourceValue)) {
|
|
220
|
-
/* 源端的值是object类型,且不是元素节点 */
|
|
221
|
-
Reflect.set(target, sourceKeyName, UtilsContext.assign(targetValue, sourceValue, isAdd));
|
|
222
|
-
continue;
|
|
223
|
-
}
|
|
224
|
-
Reflect.set(target, sourceKeyName, sourceValue);
|
|
225
|
-
}
|
|
217
|
+
// 追加并覆盖是以source为准
|
|
218
|
+
iteratorTarget = source;
|
|
226
219
|
} else {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
220
|
+
// 覆盖以target为准
|
|
221
|
+
iteratorTarget = target;
|
|
222
|
+
}
|
|
223
|
+
for (const keyName in iteratorTarget) {
|
|
224
|
+
if (!isAdd && !(keyName in source)) {
|
|
225
|
+
// 仅替换 但是源端没有此键
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
const targetValue = Reflect.get(target, keyName);
|
|
229
|
+
const sourceValue = Reflect.get(source, keyName);
|
|
230
|
+
if (typeof sourceValue === "object" && sourceValue != null && keyName in target && !isDOM(sourceValue)) {
|
|
231
|
+
// 源端的值是object类型,且不是元素节点
|
|
232
|
+
// 如果是数组,那此数组中有值,清空旧的数组再赋值
|
|
233
|
+
let childObjectValue;
|
|
234
|
+
if (Array.isArray(sourceValue)) {
|
|
235
|
+
if (Array.isArray(targetValue)) {
|
|
236
|
+
targetValue.length = 0;
|
|
240
237
|
}
|
|
241
|
-
|
|
242
|
-
|
|
238
|
+
childObjectValue = sourceValue;
|
|
239
|
+
} else {
|
|
240
|
+
childObjectValue = UtilsContext.assign(targetValue, sourceValue, isAdd);
|
|
243
241
|
}
|
|
242
|
+
Reflect.set(target, keyName, childObjectValue);
|
|
243
|
+
} else {
|
|
244
|
+
/* 直接赋值 */
|
|
245
|
+
Reflect.set(target, keyName, sourceValue);
|
|
244
246
|
}
|
|
245
247
|
}
|
|
246
248
|
|
|
@@ -268,7 +268,7 @@ export declare interface DOMUtilsAddEventListenerResult {
|
|
|
268
268
|
/**
|
|
269
269
|
* 主动触发事件
|
|
270
270
|
* @param details 赋予触发的Event的额外属性,如果是Event类型,那么将自动代替默认new的Event对象
|
|
271
|
-
* @param
|
|
271
|
+
* @param useDispatchToEmit 是否使用dispatchEvent来触发事件,默认true,如果为false,则直接调用callback,但是这种会让使用了selectorTarget的没有值
|
|
272
272
|
*/
|
|
273
|
-
|
|
273
|
+
emit(details?: object, useDispatchToEmit?: boolean): void;
|
|
274
274
|
}
|