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