"use strict";var c=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var I=(e,r)=>{for(var d in r)c(e,d,{get:r[d],enumerable:!0})},x=(e,r,d,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of A(r))!E.call(e,i)&&i!==d&&c(e,i,{get:()=>r[i],enumerable:!(n=y(r,i))||n.enumerable});return e};var L=e=>x(c({},"__esModule",{value:!0}),e);var M={};I(M,{breadthFirstTraverse:()=>m,buildTreeFromList:()=>_,deepFirstTraverse:()=>D,flattenTree:()=>O,treeFilterNode:()=>b,treeFindNode:()=>v,treeFindPath:()=>w});module.exports=L(M);var u=require("@utopia-utils/share");var N={id:"id",children:"children",parentId:"parentId"};function m(e,r,d){if(!(0,u.isFunction)(r))throw new Error("traverse action should be a function");let{fieldNames:n}=d||{},{children:i}={...N,...n},o=Array.isArray(e)?[...e]:[e];for(;o.length;){let t=o.shift();if(t){if(r(t)===!1)break;t[i]&&o.push(...t[i])}}}function _(e,r){let{listFieldNames:d,treeFieldNames:n}=r||{},{id:i,parentId:o}={...N,...d},{id:t,parentId:s,children:f}={...N,...n},p=new Map,l=[];return e.forEach(a=>{n&&(a[t]=a[i],a[s]=a[o]),a[f]=[],p.set(a[i],a)}),e.forEach(a=>{let T=p.get(a[o]);T?T[f].push(a):l.push(a)}),l}var F=require("@utopia-utils/share");function D(e,r,d){if(!(0,F.isFunction)(r))throw new Error("traverse action should be a function");let{fieldNames:n,order:i="pre"}=d||{},{children:o}={...N,...n},t=(s,f,p)=>{for(let l of s)if(i==="pre"&&r(l,f,p)===!1||l[o]&&t(l[o],l,p+1)===!1||i==="post"&&r(l,f,p)===!1)return!1};t(Array.isArray(e)?e:[e],null,0)}function O(e,r){let{fieldNames:d,onEachTraverse:n}=r||{},{children:i}={...N,...d},o=Array.isArray(e)?[...e]:[e];for(let t=0;t({...l})).filter(l=>{var a;return l[o]&&(l[o]=s(l[o])),i==null||i(l),r(l)||!!((a=l[o])!=null&&a.length)})}return s(t)}var h=require("@utopia-utils/share");function v(e,r,d){let{isFindAll:n,fieldNames:i,onEachTraverse:o}=d||{};if(!(0,h.isFunction)(r))throw new Error("predicate should be a function");let t=[];return m(e,s=>{if(o==null||o(s),r(s)&&(t.push(s),!n))return!1},{fieldNames:i}),t}function w(e,r,d){let{fieldNames:n}=d||{},{children:i}={...N,...n},o=[],t=Array.isArray(e)?[...e]:[e],s=new Set;for(;t.length;){let f=t[0];if(s.has(f))o.pop(),t.shift();else if(s.add(f),f[i]&&t.unshift(...f[i]),o.push(f),r(f))return o}return null}0&&(module.exports={breadthFirstTraverse,buildTreeFromList,deepFirstTraverse,flattenTree,treeFilterNode,treeFindNode,treeFindPath}); //# sourceMappingURL=index.cjs.map