@zhongguo168a/yxeditor-common 0.0.173 → 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 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
- flat(): TreeNode[];
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
  */
package/dist/index.esm.js CHANGED
@@ -1545,8 +1545,9 @@ class MapUtil {
1545
1545
  }
1546
1546
  unflat(object, split = "/") {
1547
1547
  let result = {};
1548
- for (const path in object) {
1549
- this.setByPath(result, "/" + path, object[path]);
1548
+ for (let key in object) {
1549
+ let path = key.replace(split, "/");
1550
+ this.setByPath(result, "/" + path, object[key]);
1550
1551
  }
1551
1552
  return result;
1552
1553
  }
@@ -2063,12 +2064,29 @@ class TreeNode {
2063
2064
  }
2064
2065
  return true;
2065
2066
  }
2066
- flat() {
2067
+ /**
2068
+ * 转化成数组
2069
+ * "BFS" 广度优先
2070
+ * "DFS" 深度优先
2071
+ * @param mode
2072
+ * @returns
2073
+ */
2074
+ toArray(mode) {
2067
2075
  let result = [];
2068
- this.walkBFS((node) => {
2069
- result.push(node);
2070
- return true;
2071
- });
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
+ }
2072
2090
  return result;
2073
2091
  }
2074
2092
  /**
@@ -2567,6 +2585,29 @@ class TreeRoot extends EventDispatcher {
2567
2585
  node.setRoot(this);
2568
2586
  return node;
2569
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
+ }
2570
2611
  /**
2571
2612
  * origin的第一个child
2572
2613
  */