tree-fd3a041e.js 1.5 KB

1
  1. const m={id:"id",children:"children",pid:"pid"},y={children:"children",label:"name",value:"id",isLeaf:"leaf",emitPath:!1},f=t=>Object.assign({},m,t),A=(t,i={})=>{i=f(i);const{children:e}=i,n=[...t];for(let r=0;r<n.length;r++)n[r][e]&&n.splice(r+1,0,...n[r][e]);return n},b=(t,i,e={})=>{e=f(e);const n=[],r=[...t],o=new Set,{children:s}=e;for(;r.length;){const c=r[0];if(o.has(c))n.pop(),r.shift();else if(o.add(c),c[s]&&r.unshift(...c[s]),n.push(c),i(c))return n}return null},v=(t,i,e={})=>{const n=(e=f(e)).children;return function r(o){return o.map(s=>({...s})).filter(s=>(s[n]=s[n]&&r(s[n]),i(s)||s[n]&&s[n].length))}(t)},O=(t,i)=>t.map(e=>p(e,i)),p=(t,{children:i="children",conversion:e})=>{const n=Array.isArray(t[i])&&t[i].length>0,r=e(t)||{};return n?{...r,[i]:t[i].map(o=>p(o,{children:i,conversion:e}))}:{...r}},g=(t,i,e={})=>{t.forEach(n=>{const r=i(n,e)||n;n.children&&g(n.children,i,r)})},S=(t,i,e,n)=>{if(!Array.isArray(t))return[];const r=i||"id",o=e||"parentId",s=n||"children",c={},a={},h=[];for(const l of t){const d=l[o];c[d]==null&&(c[d]=[]),a[l[r]]=l,c[d].push(l)}for(const l of t)a[l[o]]==null&&h.push(l);for(const l of h)u(l);function u(l){if(c[l[r]]!==null&&(l[s]=c[l[r]]),l[s])for(const d of l[s])u(d)}return h},I=(t,i,e,n,r)=>{i=i||"id",e=e||"parentId",r=r||Math.min(...t.map(c=>c[e]))||0;const o=JSON.parse(JSON.stringify(t)),s=o.filter(c=>{const a=o.filter(h=>c[i]===h[e]);return a.length>0&&(c.children=a),c[e]===r});return s!==""?s:t};export{I as a,b,A as c,y as d,g as e,v as f,S as h,O as t};