import{defineComponent as U,ref as w,shallowRef as S,watch as R,computed as X,createVNode as i,Fragment as Z}from"vue";import ee from"../_util/omit.mjs";import ne from"../vc-virtual-list/List.mjs";import te from"./MotionTreeNode.mjs";import{useInjectKeysState as oe,useInjectTreeContext as ie}from"./contextTypes.mjs";import{nodeListProps as se}from"./props.mjs";import{findExpandedKeys as le,getExpandRange as $}from"./utils/diffUtil.mjs";import{getKey as D}from"./utils/treeUtil.mjs";const A={width:0,height:0,display:"flex",overflow:"hidden",opacity:0,border:0,padding:0,margin:0},ae=()=>{},v=`RC_TREE_MOTION_${Math.random()}`,I={key:v},re={key:v,level:0,index:0,pos:"0",node:I,nodes:[I]},H={parent:null,children:[],pos:re.pos,data:I,title:null,key:v,isStart:[],isEnd:[]};function O(e,o,n,g){return o===!1||!n?e:e.slice(0,Math.ceil(n/g)+1)}function _(e){const{key:o,pos:n}=e;return D(o,n)}function de(e){let o=String(e.key),n=e;for(;n.parent;)n=n.parent,o=`${n.key} > ${o}`;return o}const Ee=U({compatConfig:{MODE:3},name:"NodeList",inheritAttrs:!1,props:se,setup(e,{expose:o,attrs:n}){const g=w(),K=w(),{expandedKeys:F,flattenNodes:y}=oe();o({scrollTo:t=>{g.value.scrollTo(t)},getIndentWidth:()=>K.value.offsetWidth});const f=S(y.value),p=S([]),E=w(null);function b(){f.value=y.value,p.value=[],E.value=null,e.onListChangeEnd()}const P=ie();R([()=>F.value.slice(),y],([t,a],[N,r])=>{const s=le(N,t);if(s.key!==null){const{virtual:k,height:x,itemHeight:M}=e;if(s.add){const u=r.findIndex(({key:m})=>m===s.key),l=O($(r,a,s.key),k,x,M),d=r.slice();d.splice(u+1,0,H),f.value=d,p.value=l,E.value="show"}else{const u=a.findIndex(({key:m})=>m===s.key),l=O($(a,r,s.key),k,x,M),d=a.slice();d.splice(u+1,0,H),f.value=d,p.value=l,E.value="hide"}}else r!==a&&(f.value=a)}),R(()=>P.value.dragging,t=>{t||b()});const j=X(()=>e.motion===void 0?f.value:y.value),B=()=>{e.onActiveChange(null)};return()=>{const{prefixCls:t,selectable:a,checkable:N,disabled:r,motion:s,height:k,itemHeight:x,virtual:M,focusable:u,activeItem:l,focused:d,tabindex:m,onKeydown:V,onFocus:W,onBlur:Y,onListChangeStart:q,onListChangeEnd:ce,...z}={...e,...n};return i(Z,null,[d&&l&&i("span",{style:A,"aria-live":"assertive"},[de(l)]),i("div",null,[i("input",{style:A,disabled:u===!1||r,tabindex:u!==!1?m:null,onKeydown:V,onFocus:W,onBlur:Y,value:"",onChange:ae,"aria-label":"for screen reader"},null)]),i("div",{class:`${t}-treenode`,"aria-hidden":!0,style:{position:"absolute",pointerEvents:"none",visibility:"hidden",height:0,overflow:"hidden"}},[i("div",{class:`${t}-indent`},[i("div",{ref:K,class:`${t}-indent-unit`},null)])]),i(ne,{...ee(z,["onActiveChange"]),data:j.value,itemKey:_,height:k,fullHeight:!1,virtual:M,itemHeight:x,prefixCls:`${t}-list`,ref:g,onVisibleChange:(C,T)=>{const h=new Set(C);T.filter(c=>!h.has(c)).some(c=>_(c)===v)&&b()}},{default:C=>{const{pos:T,data:{...h},title:L,key:c,isStart:G,isEnd:J}=C,Q=D(c,T);return delete h.key,delete h.children,i(te,{...h,eventKey:Q,title:L,active:!!l&&c===l.key,data:C.data,isStart:G,isEnd:J,motion:s,motionNodes:c===v?p.value:null,motionType:E.value,onMotionStart:q,onMotionEnd:b,onMousemove:B},null)}})])}}});export{v as MOTION_KEY,re as MotionEntity,Ee as default,O as getMinimumRangeTransitionRange};
