@zhongguo168a/yxeditor-common 0.0.173 → 0.0.175

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
@@ -1533,7 +1533,7 @@ class MapUtil {
1533
1533
  for (let key in obj) {
1534
1534
  let val = obj[key];
1535
1535
  let type = typeof val;
1536
- let id = path + split + key;
1536
+ let id = path ? path + split + key : key;
1537
1537
  switch (type) {
1538
1538
  case "object":
1539
1539
  this._flat(val, result, id, split);
@@ -1545,8 +1545,15 @@ 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;
1550
+ if (split != "/") {
1551
+ key.replace(split, "/");
1552
+ }
1553
+ else {
1554
+ path = key;
1555
+ }
1556
+ this.setByPath(result, "/" + path, object[key]);
1550
1557
  }
1551
1558
  return result;
1552
1559
  }
@@ -2063,12 +2070,29 @@ class TreeNode {
2063
2070
  }
2064
2071
  return true;
2065
2072
  }
2066
- flat() {
2073
+ /**
2074
+ * 转化成数组
2075
+ * "BFS" 广度优先
2076
+ * "DFS" 深度优先
2077
+ * @param mode
2078
+ * @returns
2079
+ */
2080
+ toArray(mode) {
2067
2081
  let result = [];
2068
- this.walkBFS((node) => {
2069
- result.push(node);
2070
- return true;
2071
- });
2082
+ switch (mode) {
2083
+ case "BFS":
2084
+ this.walkBFS((node) => {
2085
+ result.push(node);
2086
+ return true;
2087
+ });
2088
+ break;
2089
+ case "DFS":
2090
+ this.walk((node) => {
2091
+ result.push(node);
2092
+ return true;
2093
+ });
2094
+ break;
2095
+ }
2072
2096
  return result;
2073
2097
  }
2074
2098
  /**
@@ -2567,6 +2591,29 @@ class TreeRoot extends EventDispatcher {
2567
2591
  node.setRoot(this);
2568
2592
  return node;
2569
2593
  }
2594
+ flat(mode = "BFS") {
2595
+ let result = {};
2596
+ switch (mode) {
2597
+ case "BFS":
2598
+ this.origin.walkBFS((node) => {
2599
+ result[node.getPath()] = node;
2600
+ return true;
2601
+ });
2602
+ break;
2603
+ case "DFS":
2604
+ this.origin.walk((node) => {
2605
+ result[node.getPath()] = node;
2606
+ return true;
2607
+ });
2608
+ break;
2609
+ }
2610
+ return result;
2611
+ }
2612
+ unflag(object) {
2613
+ for (const path in object) {
2614
+ this.addNode(object[path], "/" + path);
2615
+ }
2616
+ }
2570
2617
  /**
2571
2618
  * origin的第一个child
2572
2619
  */