knt-shared 1.5.2 → 1.5.3

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.esm.js CHANGED
@@ -8665,6 +8665,44 @@ function arrayToMap(array, options) {
8665
8665
  });
8666
8666
  return map;
8667
8667
  }
8668
+ function transformTree(tree, transform, options) {
8669
+ if (!tree || !Array.isArray(tree) || tree.length === 0) {
8670
+ return [];
8671
+ }
8672
+ const { childrenField = "children" } = options || {};
8673
+ function transformNodes(nodes, level = 0, parent = null, parentPath = [], ancestors = []) {
8674
+ return nodes.map((node, index) => {
8675
+ const currentPath = [...parentPath, index];
8676
+ const children = node[childrenField];
8677
+ const hasChildren = children && Array.isArray(children) && children.length > 0;
8678
+ const context = {
8679
+ level,
8680
+ index,
8681
+ parent,
8682
+ path: currentPath,
8683
+ ancestors,
8684
+ isLeaf: !hasChildren
8685
+ };
8686
+ const transformedNode = transform(node, context);
8687
+ if (hasChildren) {
8688
+ const newAncestors = [...ancestors, node];
8689
+ const transformedChildren = transformNodes(
8690
+ children,
8691
+ level + 1,
8692
+ node,
8693
+ currentPath,
8694
+ newAncestors
8695
+ );
8696
+ return {
8697
+ ...transformedNode,
8698
+ [childrenField]: transformedChildren
8699
+ };
8700
+ }
8701
+ return transformedNode;
8702
+ });
8703
+ }
8704
+ return transformNodes(tree);
8705
+ }
8668
8706
  function isNullOrUnDef(value) {
8669
8707
  return value === null || value === void 0;
8670
8708
  }
@@ -8855,6 +8893,7 @@ export {
8855
8893
  throttle,
8856
8894
  transFormUrlPath,
8857
8895
  transformBackUrl,
8896
+ transformTree,
8858
8897
  transformUploadUrl,
8859
8898
  useApiRequest,
8860
8899
  useDebounce,