@zhongguo168a/yxeditor-common 0.0.98 → 0.0.100
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.d.ts +7 -0
- package/dist/index.esm.js +21 -0
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -900,6 +900,13 @@ declare class List<T = any> {
|
|
|
900
900
|
* @param target
|
|
901
901
|
*/
|
|
902
902
|
random(count: number, enableRepeat?: boolean, target?: List<T>): List<T>;
|
|
903
|
+
/**
|
|
904
|
+
* 随机获取【count】个项,并返回【target】对象
|
|
905
|
+
* @param count
|
|
906
|
+
* @param enableRepeat 允许重复
|
|
907
|
+
* @param target
|
|
908
|
+
*/
|
|
909
|
+
randomOne(): T;
|
|
903
910
|
protected callPush(value: any): void;
|
|
904
911
|
protected callRemove(value: any): void;
|
|
905
912
|
protected _data: any[];
|
package/dist/index.esm.js
CHANGED
|
@@ -2476,6 +2476,9 @@ class TreeRoot extends EventDispatcher {
|
|
|
2476
2476
|
node.parent = null;
|
|
2477
2477
|
}
|
|
2478
2478
|
removeChildren(node) {
|
|
2479
|
+
if (!node.children || node.children.length == 0) {
|
|
2480
|
+
return;
|
|
2481
|
+
}
|
|
2479
2482
|
let children = node.children.concat();
|
|
2480
2483
|
for (let item of children) {
|
|
2481
2484
|
this.removeNode(item);
|
|
@@ -3427,6 +3430,10 @@ class List {
|
|
|
3427
3430
|
if (!target) {
|
|
3428
3431
|
target = new List();
|
|
3429
3432
|
}
|
|
3433
|
+
let data = this._data;
|
|
3434
|
+
if (data.length <= 0) {
|
|
3435
|
+
return target;
|
|
3436
|
+
}
|
|
3430
3437
|
const copyItems = [...this._data]; // 创建副本以避免修改原数组
|
|
3431
3438
|
for (let i = 0; i < count && copyItems.length > 0; i++) {
|
|
3432
3439
|
const randomIndex = Math.floor(Math.random() * copyItems.length);
|
|
@@ -3437,6 +3444,20 @@ class List {
|
|
|
3437
3444
|
}
|
|
3438
3445
|
return target;
|
|
3439
3446
|
}
|
|
3447
|
+
/**
|
|
3448
|
+
* 随机获取【count】个项,并返回【target】对象
|
|
3449
|
+
* @param count
|
|
3450
|
+
* @param enableRepeat 允许重复
|
|
3451
|
+
* @param target
|
|
3452
|
+
*/
|
|
3453
|
+
randomOne() {
|
|
3454
|
+
let data = this._data;
|
|
3455
|
+
if (data.length <= 0) {
|
|
3456
|
+
return null;
|
|
3457
|
+
}
|
|
3458
|
+
const randomIndex = Math.floor(Math.random() * data.length);
|
|
3459
|
+
return data[randomIndex];
|
|
3460
|
+
}
|
|
3440
3461
|
callPush(value) {
|
|
3441
3462
|
if (this._onSet !== null) {
|
|
3442
3463
|
this._onSet.call(this._onSetCaller, value);
|