You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2 lines
2.5 KiB

var _=Object.defineProperty;var B=Object.getOwnPropertySymbols;var j=Object.prototype.hasOwnProperty,q=Object.prototype.propertyIsEnumerable;var K=(e,o,s)=>o in e?_(e,o,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[o]=s,k=(e,o)=>{for(var s in o||(o={}))j.call(o,s)&&K(e,s,o[s]);if(B)for(var s of B(o))q.call(o,s)&&K(e,s,o[s]);return e};import{u as f,ah as E,b_ as A}from"./index-f4658ae7.js";function z(e,o){function s(h){const t=[],n=h||f(e),{key:c,children:r}=f(o);if(!r||!c)return t;for(let l=0;l<n.length;l++){const i=n[l];t.push(i[c]);const u=i[r];u&&u.length&&t.push(...s(u))}return t}function g(h){const t=[],n=h||f(e),{key:c,children:r}=f(o);if(!r||!c)return t;for(let l=0;l<n.length;l++){const i=n[l];i.disabled!==!0&&i.selectable!==!1&&t.push(i[c]);const u=i[r];u&&u.length&&t.push(...g(u))}return t}function p(h,t){const n=[],c=t||f(e),{key:r,children:l}=f(o);if(!l||!r)return n;for(let i=0;i<c.length;i++){const u=c[i],d=u[l];h===u[r]?(n.push(u[r]),d&&d.length&&n.push(...s(d))):d&&d.length&&n.push(...p(h,d))}return n}function F(h,t,n){if(!h)return;const c=n||f(e),{key:r,children:l}=f(o);if(!(!l||!r))for(let i=0;i<c.length;i++){const u=c[i],d=u[l];if(u[r]===h){c[i]=k(k({},c[i]),t);break}else d&&d.length&&F(h,t,u[l])}}function x(h=1,t,n=1){if(!h)return[];const c=[],r=t||f(e)||[];for(let l=0;l<r.length;l++){const i=r[l],{key:u,children:d}=f(o),T=u?i[u]:"",y=d?i[d]:[];c.push(T),y&&y.length&&n<h&&(n+=1,c.push(...x(h,y,n)))}return c}function C({parentKey:h=null,node:t,push:n="push"}){const c=E(f(e));if(!h){c[n](t),e.value=c;return}const{key:r,children:l}=f(o);!l||!r||(A(c,i=>{if(i[r]===h)return i[l]=i[l]||[],i[l][n](t),!0}),e.value=c)}function S({parentKey:h=null,list:t,push:n="push"}){const c=E(f(e));if(!(!t||t.length<1))if(h){const{key:r,children:l}=f(o);if(!l||!r)return;A(c,i=>{if(i[r]===h){i[l]=i[l]||[];for(let u=0;u<t.length;u++)i[l][n](t[u]);return e.value=c,!0}})}else for(let r=0;r<t.length;r++)c[n](t[r])}function b(h,t){if(!h)return;const n=t||f(e),{key:c,children:r}=f(o);if(!(!r||!c))for(let l=0;l<n.length;l++){const i=n[l],u=i[r];if(i[c]===h){n.splice(l,1);break}else u&&u.length&&b(h,i[r])}}function a(h,t,n){return!h&&h!==0?null:((t||f(e)).forEach(r=>{if(n!=null&&n.key||(n==null?void 0:n.key)===0)return n;if(r.key===h){n=r;return}r.children&&r.children.length&&(n=a(h,r.children,n))}),n||null)}return{deleteNodeByKey:b,insertNodeByKey:C,insertNodesByKey:S,filterByLevel:x,updateNodeByKey:F,getAllKeys:s,getChildrenKeys:p,getEnabledKeys:g,getSelectedNode:a}}export{z as useTree};