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