a2bei4-utils 1.0.7 → 1.0.8

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/types/tree.d.ts CHANGED
@@ -64,5 +64,27 @@ declare function extractFullyCheckedKeys(treeData: any[], selectedKeys: any[], i
64
64
  checked: string[];
65
65
  halfChecked: string[];
66
66
  };
67
+ /**
68
+ * 在树形结构中查找目标节点的完整路径(从根节点到目标节点,含目标节点自身)。
69
+ *
70
+ * @template T extends Record<PropertyKey, any>
71
+ * @param {T[]} nodes - 树形结构森林(支持多根)
72
+ * @param {any} targetValue - 目标节点的 key 值
73
+ * @param {string} [key='id'] - 节点唯一标识字段
74
+ * @param {string} [parentKey='pid'] - 父节点标识字段(指向父节点的 key 值)
75
+ * @param {string} [childrenKey='children'] - 子节点数组字段
76
+ * @returns {T[]} 从根到目标节点的路径数组;未找到返回空数组
77
+ *
78
+ * @example
79
+ * const tree = [
80
+ * { id: 1, pid: null, children: [
81
+ * { id: 2, pid: 1, children: [
82
+ * { id: 3, pid: 2 }
83
+ * ]}
84
+ * ]}
85
+ * ];
86
+ * findTreeNodePath(tree, 3); // [{id:1, ...}, {id:2, ...}, {id:3, ...}]
87
+ */
88
+ declare function findTreeNodePath<T>(nodes: T[], targetValue: any, key?: string, parentKey?: string, childrenKey?: string): T[];
67
89
 
68
- export { extractFullyCheckedKeys, findObjAttrValueById, findTreeNodeById, flatCompleteTree2NestedTree, nestedTree2IdMap };
90
+ export { extractFullyCheckedKeys, findObjAttrValueById, findTreeNodeById, findTreeNodePath, flatCompleteTree2NestedTree, nestedTree2IdMap };