@vope/utils 1.7.3 → 1.7.5
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/flat-tree.d.ts +6 -0
- package/dist/flat-tree.js +17 -0
- package/dist/index.cjs.js +17 -0
- package/package.json +1 -1
package/dist/flat-tree.d.ts
CHANGED
|
@@ -77,6 +77,11 @@ export declare class FlatTree<K extends string, T extends {
|
|
|
77
77
|
* 获取上级节点
|
|
78
78
|
*/
|
|
79
79
|
getSup(value: Value): T | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* 获取子级节点
|
|
82
|
+
* @description 当value === null时则获取所有顶级节点
|
|
83
|
+
*/
|
|
84
|
+
getSub(value: Value | null, callback?: (data: T) => void): T[] | undefined;
|
|
80
85
|
/**
|
|
81
86
|
* 是否含有节点
|
|
82
87
|
*/
|
|
@@ -88,6 +93,7 @@ export declare class FlatTree<K extends string, T extends {
|
|
|
88
93
|
forEach(callback: (data: T) => void, mode?: FlatTree.Mode): void;
|
|
89
94
|
/**
|
|
90
95
|
* 查询节点
|
|
96
|
+
* @param callback 节点回调,返回false则停止查询
|
|
91
97
|
* @param mode 遍历模式
|
|
92
98
|
*/
|
|
93
99
|
some(callback: (data: T) => boolean, mode?: FlatTree.Mode): boolean;
|
package/dist/flat-tree.js
CHANGED
|
@@ -132,6 +132,22 @@ class FlatTree {
|
|
|
132
132
|
const pid = this.ups.get(value);
|
|
133
133
|
return isNull(pid) ? void 0 : this.memory.get(pid);
|
|
134
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* 获取子级节点
|
|
137
|
+
* @description 当value === null时则获取所有顶级节点
|
|
138
|
+
*/
|
|
139
|
+
getSub(value, callback) {
|
|
140
|
+
const { memory } = this;
|
|
141
|
+
const tmp = value === null ? this.list : this.downs.get(value);
|
|
142
|
+
if (!tmp) return;
|
|
143
|
+
const list = [];
|
|
144
|
+
for (const id of tmp) {
|
|
145
|
+
const data = memory.get(id);
|
|
146
|
+
callback?.(data);
|
|
147
|
+
list.push(data);
|
|
148
|
+
}
|
|
149
|
+
return list;
|
|
150
|
+
}
|
|
135
151
|
/**
|
|
136
152
|
* 是否含有节点
|
|
137
153
|
*/
|
|
@@ -155,6 +171,7 @@ class FlatTree {
|
|
|
155
171
|
}
|
|
156
172
|
/**
|
|
157
173
|
* 查询节点
|
|
174
|
+
* @param callback 节点回调,返回false则停止查询
|
|
158
175
|
* @param mode 遍历模式
|
|
159
176
|
*/
|
|
160
177
|
some(callback, mode) {
|
package/dist/index.cjs.js
CHANGED
|
@@ -1387,6 +1387,22 @@ var FlatTree = class {
|
|
|
1387
1387
|
const pid = this.ups.get(value);
|
|
1388
1388
|
return isNull(pid) ? void 0 : this.memory.get(pid);
|
|
1389
1389
|
}
|
|
1390
|
+
/**
|
|
1391
|
+
* 获取子级节点
|
|
1392
|
+
* @description 当value === null时则获取所有顶级节点
|
|
1393
|
+
*/
|
|
1394
|
+
getSub(value, callback) {
|
|
1395
|
+
const { memory } = this;
|
|
1396
|
+
const tmp = value === null ? this.list : this.downs.get(value);
|
|
1397
|
+
if (!tmp) return;
|
|
1398
|
+
const list = [];
|
|
1399
|
+
for (const id of tmp) {
|
|
1400
|
+
const data = memory.get(id);
|
|
1401
|
+
callback?.(data);
|
|
1402
|
+
list.push(data);
|
|
1403
|
+
}
|
|
1404
|
+
return list;
|
|
1405
|
+
}
|
|
1390
1406
|
/**
|
|
1391
1407
|
* 是否含有节点
|
|
1392
1408
|
*/
|
|
@@ -1410,6 +1426,7 @@ var FlatTree = class {
|
|
|
1410
1426
|
}
|
|
1411
1427
|
/**
|
|
1412
1428
|
* 查询节点
|
|
1429
|
+
* @param callback 节点回调,返回false则停止查询
|
|
1413
1430
|
* @param mode 遍历模式
|
|
1414
1431
|
*/
|
|
1415
1432
|
some(callback, mode) {
|