@zhongguo168a/yxeditor-common 0.0.172 → 0.0.174
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 +21 -1
- package/dist/index.esm.js +68 -7
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -455,7 +455,14 @@ declare class TreeNode<T = any> {
|
|
|
455
455
|
*/
|
|
456
456
|
walkRemove(f: (node: TreeNode) => boolean): void;
|
|
457
457
|
private _walkRemove;
|
|
458
|
-
|
|
458
|
+
/**
|
|
459
|
+
* 转化成数组
|
|
460
|
+
* "BFS" 广度优先
|
|
461
|
+
* "DFS" 深度优先
|
|
462
|
+
* @param mode
|
|
463
|
+
* @returns
|
|
464
|
+
*/
|
|
465
|
+
toArray(mode: "BFS" | "DFS"): TreeNode[];
|
|
459
466
|
/**
|
|
460
467
|
* 广度优先遍历(BFS):从当前节点开始,逐层遍历子树
|
|
461
468
|
* @param f - 节点处理函数,返回 false 表示停止遍历
|
|
@@ -585,6 +592,12 @@ declare class TreeRoot<NODE = any> extends EventDispatcher {
|
|
|
585
592
|
clone(): TreeRoot;
|
|
586
593
|
toString(): string;
|
|
587
594
|
createNode(id: string, isLeaf?: boolean): TreeNode;
|
|
595
|
+
flat(mode: "BFS" | "DFS"): {
|
|
596
|
+
[key: string]: any;
|
|
597
|
+
};
|
|
598
|
+
unflag(object: {
|
|
599
|
+
[key: string]: TreeNode;
|
|
600
|
+
}): void;
|
|
588
601
|
/**
|
|
589
602
|
* origin的第一个child
|
|
590
603
|
*/
|
|
@@ -1141,6 +1154,13 @@ declare class MapUtil {
|
|
|
1141
1154
|
unflat(object: {
|
|
1142
1155
|
[key: string]: any;
|
|
1143
1156
|
}, split?: string): any;
|
|
1157
|
+
/**
|
|
1158
|
+
* 返回键值相同的对象,只遍历一层,比较前使用flag展开
|
|
1159
|
+
* @param a
|
|
1160
|
+
* @param b
|
|
1161
|
+
* @returns
|
|
1162
|
+
*/
|
|
1163
|
+
sample(a: any, b: any): any;
|
|
1144
1164
|
/**
|
|
1145
1165
|
* 比较两个对象,包括基础类型
|
|
1146
1166
|
* @param a
|
package/dist/index.esm.js
CHANGED
|
@@ -1545,8 +1545,29 @@ class MapUtil {
|
|
|
1545
1545
|
}
|
|
1546
1546
|
unflat(object, split = "/") {
|
|
1547
1547
|
let result = {};
|
|
1548
|
-
for (
|
|
1549
|
-
|
|
1548
|
+
for (let key in object) {
|
|
1549
|
+
let path = key.replace(split, "/");
|
|
1550
|
+
this.setByPath(result, "/" + path, object[key]);
|
|
1551
|
+
}
|
|
1552
|
+
return result;
|
|
1553
|
+
}
|
|
1554
|
+
/**
|
|
1555
|
+
* 返回键值相同的对象,只遍历一层,比较前使用flag展开
|
|
1556
|
+
* @param a
|
|
1557
|
+
* @param b
|
|
1558
|
+
* @returns
|
|
1559
|
+
*/
|
|
1560
|
+
sample(a, b) {
|
|
1561
|
+
let result = {};
|
|
1562
|
+
for (const key in a) {
|
|
1563
|
+
let bval = b[key];
|
|
1564
|
+
if (bval == undefined) {
|
|
1565
|
+
continue;
|
|
1566
|
+
}
|
|
1567
|
+
let aval = a[key];
|
|
1568
|
+
if (aval == bval) {
|
|
1569
|
+
result[key] = aval;
|
|
1570
|
+
}
|
|
1550
1571
|
}
|
|
1551
1572
|
return result;
|
|
1552
1573
|
}
|
|
@@ -2043,12 +2064,29 @@ class TreeNode {
|
|
|
2043
2064
|
}
|
|
2044
2065
|
return true;
|
|
2045
2066
|
}
|
|
2046
|
-
|
|
2067
|
+
/**
|
|
2068
|
+
* 转化成数组
|
|
2069
|
+
* "BFS" 广度优先
|
|
2070
|
+
* "DFS" 深度优先
|
|
2071
|
+
* @param mode
|
|
2072
|
+
* @returns
|
|
2073
|
+
*/
|
|
2074
|
+
toArray(mode) {
|
|
2047
2075
|
let result = [];
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2076
|
+
switch (mode) {
|
|
2077
|
+
case "BFS":
|
|
2078
|
+
this.walkBFS((node) => {
|
|
2079
|
+
result.push(node);
|
|
2080
|
+
return true;
|
|
2081
|
+
});
|
|
2082
|
+
break;
|
|
2083
|
+
case "DFS":
|
|
2084
|
+
this.walk((node) => {
|
|
2085
|
+
result.push(node);
|
|
2086
|
+
return true;
|
|
2087
|
+
});
|
|
2088
|
+
break;
|
|
2089
|
+
}
|
|
2052
2090
|
return result;
|
|
2053
2091
|
}
|
|
2054
2092
|
/**
|
|
@@ -2547,6 +2585,29 @@ class TreeRoot extends EventDispatcher {
|
|
|
2547
2585
|
node.setRoot(this);
|
|
2548
2586
|
return node;
|
|
2549
2587
|
}
|
|
2588
|
+
flat(mode) {
|
|
2589
|
+
let result = {};
|
|
2590
|
+
switch (mode) {
|
|
2591
|
+
case "BFS":
|
|
2592
|
+
this.origin.walkBFS((node) => {
|
|
2593
|
+
result[node.getPath()] = node;
|
|
2594
|
+
return true;
|
|
2595
|
+
});
|
|
2596
|
+
break;
|
|
2597
|
+
case "DFS":
|
|
2598
|
+
this.origin.walk((node) => {
|
|
2599
|
+
result[node.getPath()] = node;
|
|
2600
|
+
return true;
|
|
2601
|
+
});
|
|
2602
|
+
break;
|
|
2603
|
+
}
|
|
2604
|
+
return result;
|
|
2605
|
+
}
|
|
2606
|
+
unflag(object) {
|
|
2607
|
+
for (const path in object) {
|
|
2608
|
+
this.addNode(object[path], "/" + path);
|
|
2609
|
+
}
|
|
2610
|
+
}
|
|
2550
2611
|
/**
|
|
2551
2612
|
* origin的第一个child
|
|
2552
2613
|
*/
|