@whitesev/utils 2.7.5 → 2.7.7
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 +66 -63
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +66 -63
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +66 -63
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +66 -63
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +66 -63
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +66 -63
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/Dictionary.d.ts +22 -23
- package/dist/types/src/Utils.d.ts +2 -8
- package/dist/types/src/types/React.d.ts +119 -0
- package/package.json +1 -1
- package/src/Dictionary.ts +54 -60
- package/src/Utils.ts +19 -21
- package/src/types/React.d.ts +119 -0
package/dist/index.esm.js
CHANGED
|
@@ -4205,7 +4205,7 @@ class Progress {
|
|
|
4205
4205
|
class UtilsDictionary {
|
|
4206
4206
|
items;
|
|
4207
4207
|
constructor(key, value) {
|
|
4208
|
-
this.items =
|
|
4208
|
+
this.items = new Map();
|
|
4209
4209
|
if (key != null) {
|
|
4210
4210
|
this.set(key, value);
|
|
4211
4211
|
}
|
|
@@ -4242,35 +4242,16 @@ class UtilsDictionary {
|
|
|
4242
4242
|
* @param key 键
|
|
4243
4243
|
*/
|
|
4244
4244
|
has(key) {
|
|
4245
|
-
return
|
|
4245
|
+
return this.items.has(key);
|
|
4246
4246
|
}
|
|
4247
4247
|
/**
|
|
4248
|
-
*
|
|
4249
|
-
*
|
|
4250
|
-
|
|
4251
|
-
|
|
4252
|
-
let allKeys = this.keys();
|
|
4253
|
-
for (const keyName of allKeys) {
|
|
4254
|
-
if (String(keyName).startsWith(String(key))) {
|
|
4255
|
-
return true;
|
|
4256
|
-
}
|
|
4257
|
-
}
|
|
4258
|
-
return false;
|
|
4259
|
-
}
|
|
4260
|
-
/**
|
|
4261
|
-
* 获取以xx开头的键的值
|
|
4262
|
-
* @param key 需要匹配的键
|
|
4248
|
+
* 获取某个键的值
|
|
4249
|
+
* https://github.com/microsoft/TypeScript/issues/9619
|
|
4250
|
+
* 微软到现在都没有实现has和get的联动
|
|
4251
|
+
* @param key 键
|
|
4263
4252
|
*/
|
|
4264
|
-
|
|
4265
|
-
|
|
4266
|
-
let result = void 0;
|
|
4267
|
-
for (const keyName of allKeys) {
|
|
4268
|
-
if (String(keyName).startsWith(String(key))) {
|
|
4269
|
-
result = this.get(keyName);
|
|
4270
|
-
break;
|
|
4271
|
-
}
|
|
4272
|
-
}
|
|
4273
|
-
return result;
|
|
4253
|
+
get(key) {
|
|
4254
|
+
return this.items.get(key);
|
|
4274
4255
|
}
|
|
4275
4256
|
/**
|
|
4276
4257
|
* 为字典添加某一个值
|
|
@@ -4281,57 +4262,44 @@ class UtilsDictionary {
|
|
|
4281
4262
|
if (key === void 0) {
|
|
4282
4263
|
throw new Error("Utils.Dictionary().set 参数 key 不能为空");
|
|
4283
4264
|
}
|
|
4284
|
-
|
|
4265
|
+
this.items.set(key, val);
|
|
4285
4266
|
}
|
|
4286
4267
|
/**
|
|
4287
4268
|
* 删除某一个键
|
|
4288
4269
|
* @param key 键
|
|
4270
|
+
* @returns
|
|
4271
|
+
* + true:键存在且成功删除
|
|
4272
|
+
* + false:键不存在
|
|
4289
4273
|
*/
|
|
4290
4274
|
delete(key) {
|
|
4291
4275
|
if (this.has(key)) {
|
|
4292
|
-
return
|
|
4276
|
+
return this.items.delete(key);
|
|
4293
4277
|
}
|
|
4294
4278
|
return false;
|
|
4295
4279
|
}
|
|
4296
4280
|
/**
|
|
4297
|
-
*
|
|
4298
|
-
* https://github.com/microsoft/TypeScript/issues/9619
|
|
4299
|
-
* 微软到现在都没有修复has和get的联动
|
|
4300
|
-
* @param key 键
|
|
4281
|
+
* 获取字典所有的键
|
|
4301
4282
|
*/
|
|
4302
|
-
|
|
4303
|
-
return
|
|
4283
|
+
keys() {
|
|
4284
|
+
return this.items.keys().toArray();
|
|
4304
4285
|
}
|
|
4305
4286
|
/**
|
|
4306
4287
|
* 返回字典中的所有值
|
|
4307
4288
|
*/
|
|
4308
4289
|
values() {
|
|
4309
|
-
|
|
4310
|
-
for (let prop in this.getItems()) {
|
|
4311
|
-
if (this.has(prop)) {
|
|
4312
|
-
resultList.push(this.get(prop));
|
|
4313
|
-
}
|
|
4314
|
-
}
|
|
4315
|
-
return resultList;
|
|
4290
|
+
return this.items.values().toArray();
|
|
4316
4291
|
}
|
|
4317
4292
|
/**
|
|
4318
4293
|
* 清空字典
|
|
4319
4294
|
*/
|
|
4320
4295
|
clear() {
|
|
4321
|
-
this.items
|
|
4322
|
-
this.items = {};
|
|
4296
|
+
this.items.clear();
|
|
4323
4297
|
}
|
|
4324
4298
|
/**
|
|
4325
4299
|
* 获取字典的长度
|
|
4326
4300
|
*/
|
|
4327
4301
|
size() {
|
|
4328
|
-
return
|
|
4329
|
-
}
|
|
4330
|
-
/**
|
|
4331
|
-
* 获取字典所有的键
|
|
4332
|
-
*/
|
|
4333
|
-
keys() {
|
|
4334
|
-
return Reflect.ownKeys(this.items);
|
|
4302
|
+
return this.items.size;
|
|
4335
4303
|
}
|
|
4336
4304
|
/**
|
|
4337
4305
|
* 返回字典本身
|
|
@@ -4344,16 +4312,46 @@ class UtilsDictionary {
|
|
|
4344
4312
|
* @param data 需要合并的字典
|
|
4345
4313
|
*/
|
|
4346
4314
|
concat(data) {
|
|
4347
|
-
|
|
4315
|
+
data.forEach((value, key) => {
|
|
4316
|
+
this.items.set(key, value);
|
|
4317
|
+
});
|
|
4348
4318
|
}
|
|
4349
4319
|
/**
|
|
4350
4320
|
* 迭代字典
|
|
4351
4321
|
* @param callbackfn 回调函数
|
|
4352
4322
|
*/
|
|
4353
4323
|
forEach(callbackfn) {
|
|
4354
|
-
|
|
4355
|
-
callbackfn(
|
|
4324
|
+
this.items.forEach((value, key, self) => {
|
|
4325
|
+
callbackfn(value, key, this);
|
|
4326
|
+
});
|
|
4327
|
+
}
|
|
4328
|
+
/**
|
|
4329
|
+
* 检查已有的键中是否以xx开头
|
|
4330
|
+
* @param key 需要匹配的键
|
|
4331
|
+
*/
|
|
4332
|
+
startsWith(key) {
|
|
4333
|
+
const keys = this.keys();
|
|
4334
|
+
for (const keyName of keys) {
|
|
4335
|
+
if (String(keyName).startsWith(key)) {
|
|
4336
|
+
return true;
|
|
4337
|
+
}
|
|
4356
4338
|
}
|
|
4339
|
+
return false;
|
|
4340
|
+
}
|
|
4341
|
+
/**
|
|
4342
|
+
* 获取以xx开头的键的值
|
|
4343
|
+
* @param key 需要匹配的键
|
|
4344
|
+
*/
|
|
4345
|
+
getStartsWith(key) {
|
|
4346
|
+
let result = void 0;
|
|
4347
|
+
const keys = this.keys();
|
|
4348
|
+
for (const keyName of keys) {
|
|
4349
|
+
if (String(keyName).startsWith(String(key))) {
|
|
4350
|
+
result = this.get(keyName);
|
|
4351
|
+
break;
|
|
4352
|
+
}
|
|
4353
|
+
}
|
|
4354
|
+
return result;
|
|
4357
4355
|
}
|
|
4358
4356
|
}
|
|
4359
4357
|
|
|
@@ -5475,7 +5473,7 @@ class Utils {
|
|
|
5475
5473
|
this.windowApi = new WindowApi(option);
|
|
5476
5474
|
}
|
|
5477
5475
|
/** 版本号 */
|
|
5478
|
-
version = "2025.8
|
|
5476
|
+
version = "2025.9.8";
|
|
5479
5477
|
addStyle(cssText) {
|
|
5480
5478
|
if (typeof cssText !== "string") {
|
|
5481
5479
|
throw new Error("Utils.addStyle 参数cssText 必须为String类型");
|
|
@@ -5805,19 +5803,19 @@ class Utils {
|
|
|
5805
5803
|
}
|
|
5806
5804
|
else {
|
|
5807
5805
|
let textElement = Array.from(element.childNodes).filter((ele) => ele.nodeType === Node.TEXT_NODE);
|
|
5808
|
-
for (let
|
|
5809
|
-
if (
|
|
5806
|
+
for (let $child of textElement) {
|
|
5807
|
+
if ($child.textContent.includes(text)) {
|
|
5810
5808
|
let filterResult = typeof filter === "function" ? filter(element) : false;
|
|
5811
5809
|
if (!filterResult) {
|
|
5812
|
-
yield
|
|
5810
|
+
yield $child;
|
|
5813
5811
|
}
|
|
5814
5812
|
}
|
|
5815
5813
|
}
|
|
5816
5814
|
}
|
|
5817
5815
|
}
|
|
5818
5816
|
for (let index = 0; index < element.children.length; index++) {
|
|
5819
|
-
let
|
|
5820
|
-
yield* that.findElementsWithText(
|
|
5817
|
+
let $child = element.children[index];
|
|
5818
|
+
yield* that.findElementsWithText($child, text, filter);
|
|
5821
5819
|
}
|
|
5822
5820
|
}
|
|
5823
5821
|
/**
|
|
@@ -6317,12 +6315,17 @@ class Utils {
|
|
|
6317
6315
|
*/
|
|
6318
6316
|
getReactObj(element) {
|
|
6319
6317
|
let result = {};
|
|
6320
|
-
|
|
6318
|
+
if (element == null) {
|
|
6319
|
+
return result;
|
|
6320
|
+
}
|
|
6321
|
+
const keys = Object.keys(element);
|
|
6322
|
+
keys.forEach((domPropsName) => {
|
|
6321
6323
|
if (domPropsName.startsWith("__react")) {
|
|
6322
|
-
|
|
6324
|
+
const propsName = domPropsName.replace(/__(.+)\$.+/i, "$1");
|
|
6325
|
+
const propsValue = Reflect.get(element, domPropsName);
|
|
6323
6326
|
if (propsName in result) ;
|
|
6324
6327
|
else {
|
|
6325
|
-
result
|
|
6328
|
+
Reflect.set(result, propsName, propsValue);
|
|
6326
6329
|
}
|
|
6327
6330
|
}
|
|
6328
6331
|
});
|