amazing-tree 1.1.0 → 1.2.2

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.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("vue"),Me=["onMousedown","onClick","onContextmenu"],Ae=["onClick"],ze=["checked","indeterminate","disabled","onClick"],Ke={class:"vtree-label"},Ie={key:1,class:"vtree-empty"},Le={class:"vtree-empty-inner"},H=28,Ne=t.defineComponent({__name:"AmazingTree",props:{data:{},props:{default:()=>({value:"value",label:"label",children:"children"})},allowDrag:{},allowDrop:{},height:{default:void 0},highlightColor:{default:"#1e71ff"},backgroundColor:{default:"#1d1d24"},textColor:{default:"#c8d3de"},hoverColor:{default:"#5d90e5"},currentNodeKey:{},defaultExpandedKeys:{},defaultExpandAll:{type:Boolean,default:!1},draggable:{type:Boolean,default:!1},emptyText:{default:"暂无数据"},showCheckbox:{type:Boolean,default:!1},checkStrictly:{type:Boolean,default:!1},defaultCheckedKeys:{default:()=>[]},disabledChecked:{}},emits:["node-click","node-contextmenu","node-drop","current-change","check-change"],setup(m,{expose:j,emit:Y}){const a=m,A=Y,se=t.computed(()=>a.props.value||"value"),de=t.computed(()=>a.props.label||"label"),_=t.computed(()=>a.props.children||"children"),ve=t.computed(()=>Array.isArray(a.data)?a.data.length===0:!0),y=t.ref(new Set),h=t.ref(new Set),p=t.ref(new Set);function ee(e){return y.value.has(e)}function fe(e){y.value.has(e)?y.value.delete(e):y.value.add(e),i.value=C(a.data||[]),t.nextTick(()=>{M(),k()})}function w(e){return e[se.value]}function E(e){const l=e[_.value];return Array.isArray(l)?l:[]}function he(e){return h.value.has(e)}function me(e){return p.value.has(e)}function G(e,l){if(l?h.value.add(e):h.value.delete(e),p.value.delete(e),!a.checkStrictly){const n=Z(e,a.data||[]);if(n){const o=[n];for(;o.length;){const r=o.pop(),c=w(r);l?h.value.add(c):h.value.delete(c),p.value.delete(c);const f=E(r);for(const s of f)o.push(s)}const u=q(e,a.data||[])||[];for(const r of u){const c=w(r),f=E(r);let s=!0,d=!1;for(const x of f){const $=w(x),re=h.value.has($),ie=p.value.has($);(re||ie)&&(d=!0),(!re||ie)&&(s=!1)}f.length===0?(h.value.has(c),p.value.delete(c)):s?(h.value.add(c),p.value.delete(c)):d?(h.value.delete(c),p.value.add(c)):(h.value.delete(c),p.value.delete(c))}}}}function te(e){h.value=new Set,p.value=new Set;for(const l of e||[])G(l,!0)}function pe(e,l){const n=l.target;a.disabledChecked&&a.disabledChecked(e.node)||(A("check-change",e.node,!!n.checked),G(e.id,!!n.checked))}function C(e){const l=[];function n(o,u,r){for(let c=0;c<o.length;c++){const f=o[c],s=w(f),d=E(f),x=d.length===0;l.push({id:s,node:f,parent:u,level:r,index:c,isLeaf:x}),!x&&y.value.has(s)&&n(d,f,r+1)}}return n(e,null,0),l}const v=t.ref(null),B=t.ref(0),R=t.ref(0),i=t.ref([]),z=t.reactive(new Map),g=t.computed(()=>{let e=0;const l=[];for(const n of i.value){const o=z.get(n.id)||H;e+=o,l.push(e)}return l}),le=t.computed(()=>{const e=g.value;return e.length?e[e.length-1]:0});function ne(e){let l=0,n=g.value.length-1,o=0;for(;l<=n;){const u=l+n>>1;g.value[u]!==void 0&&g.value[u]>=e?(o=u,n=u-1):l=u+1}return o}const K=t.ref(0),b=t.ref(0),I=t.ref(0),J=t.ref(0);function k(){if(R.value=v.value?.clientHeight||0,g.value.length===0||i.value.length===0){K.value=0,b.value=0,I.value=0,J.value=0;return}const e=ne(B.value);K.value=Math.max(0,e-3);const l=i.value[K.value],n=l?z.get(l.id)||H:0,u=(g.value[K.value]??0)-n;I.value=Math.max(0,u);let r=K.value;const c=B.value+R.value+3*H;for(;r<i.value.length&&(g.value[r]??0)<c;)r++;b.value=Math.min(i.value.length,r+1);const s=(g.value[b.value-1]??0)-I.value;if(s<R.value&&b.value<i.value.length){let d=b.value,x=s;for(;x<R.value&&d<i.value.length;)d++,x=(g.value[d-1]??0)-I.value;b.value=d}J.value=Math.max(0,le.value-I.value-((g.value[b.value-1]??0)-I.value))}t.watch([B,()=>a.data,y],()=>{i.value=C(a.data||[]),t.nextTick(M),k()}),t.onMounted(()=>{i.value=C(a.data||[]),t.nextTick(M),k(),a.defaultCheckedKeys&&a.defaultCheckedKeys.length&&te(a.defaultCheckedKeys),v.value&&(V=new ResizeObserver(()=>{R.value=v.value?.clientHeight||0,k()}),V.observe(v.value))});let V=null;t.onUnmounted(()=>{V&&(V.disconnect(),V=null)});const O=t.reactive(new Map);function ge(e,l){l?O.set(e,l):O.delete(e)}function M(){let e=!1;for(const l of i.value.slice(K.value,b.value)){const n=O.get(l.id);if(n){const o=n.offsetHeight;(!z.has(l.id)||z.get(l.id)!==o)&&(z.set(l.id,o),e=!0)}}e&&k()}function ke(){B.value=v.value?.scrollTop||0,k()}const S=t.ref(!1),Q=t.ref(null),D=t.ref(null),T=t.ref(null),X=t.ref(0),L=t.ref(null),F=t.ref(0);let N=null;function P(){N!=null&&(cancelAnimationFrame(N),N=null)}function ae(){if(!S.value||F.value===0){P();return}const e=v.value;if(!e){P();return}const l=e.scrollHeight-e.clientHeight,n=12;e.scrollTop=Math.max(0,Math.min(l,e.scrollTop+F.value*n)),B.value=e.scrollTop,k(),N=requestAnimationFrame(ae)}function xe(){F.value!==0&&N==null&&(N=requestAnimationFrame(ae)),F.value===0&&P()}function W(e){if(e==null)return null;for(const l of i.value)if(l.id===e)return l;return null}function ye(e){const l=v.value.getBoundingClientRect(),n=e-l.top+B.value;return ne(n)}function we(e,l){!a.draggable||l.button!==0||!(!a.allowDrag||a.allowDrag(e.node))||(S.value=!0,Q.value=e.id,X.value=l.clientY,l.preventDefault(),window.addEventListener("mousemove",oe),window.addEventListener("mouseup",ce))}function oe(e){if(!S.value)return;X.value=e.clientY;const l=ye(e.clientY),n=i.value[Math.min(Math.max(l,0),i.value.length-1)];if(D.value=n?.id??null,!n){T.value=null;return}const o=g.value[l]??0,u=z.get(n.id)??H,r=o-u,c=v.value.getBoundingClientRect(),s=(e.clientY-c.top+B.value-r)/u;let d="inner";s<.25?d="prev":s>.75&&(d="next");const x=W(Q.value),$=a.allowDrop?!!(x&&a.allowDrop(x.node,n.node,d)):!0;T.value=$?d:null,F.value=e.clientY>c.bottom?1:e.clientY<c.top?-1:0,xe()}function q(e,l,n=[]){for(const o of l){if(w(o)===e)return n;const u=E(o);if(u.length){const r=q(e,u,[...n,o]);if(r)return r}}return null}function Z(e,l){if(e==null)return null;for(const n of l){if(w(n)===e)return n;const o=E(n),u=Z(e,o);if(u)return u}return null}function U(e){const l=[];for(const n of e){l.push(w(n));const o=E(n);o.length&&l.push(...U(o))}return l}function Ce(e){const l=e.parent;if(l)E(l).splice(e.index,1);else{const n=a.data.findIndex(o=>w(o)===e.id);n>=0&&a.data.splice(n,1)}}function be(e,l,n){if(n==="inner"){Array.isArray(l.node[_.value])||(l.node[_.value]=[]),l.node[_.value].push(e),y.value.add(l.id);return}const o=l.parent;if(o){const u=E(o),r=l.index+(n==="next"?1:0);u.splice(r,0,e)}else{const u=l.index+(n==="next"?1:0);a.data.splice(u,0,e)}}function ce(){if(window.removeEventListener("mousemove",oe),window.removeEventListener("mouseup",ce),P(),!S.value)return;const e=W(Q.value),l=W(D.value),n=T.value;if(S.value=!1,T.value=null,D.value=null,!e||!l||!n||a.allowDrop&&!a.allowDrop(e.node,l.node,n)||e.id===l.id)return;const o=n==="inner"?l.node:l.parent||null;if(o){const f=q(w(o),a.data||[])||[];for(const s of f)if(w(s)===e.id)return}const u=e.node;Ce(e);const r=C(a.data||[]);i.value=r;const c=W(l.id)||l;be(u,c,n),i.value=C(a.data||[]),t.nextTick(()=>{M(),k()}),A("node-drop",u,c.node,n)}function Se(e,l){L.value=e.id,A("node-click",e.node,l)}function Te(e,l){A("node-contextmenu",e.node,l)}t.watchEffect(()=>{t.nextTick(M)}),t.watch(()=>a.currentNodeKey,e=>{L.value=e??null},{immediate:!0}),t.watch(()=>a.defaultExpandedKeys,e=>{y.value=new Set(e||[]),i.value=C(a.data||[]),t.nextTick(()=>{M(),k()})},{immediate:!0}),t.watch(()=>a.defaultExpandAll,e=>{e&&(y.value=new Set(U(a.data||[])),i.value=C(a.data||[]),t.nextTick(()=>{M(),k()}))},{immediate:!0}),t.watch(()=>a.data,()=>{a.defaultExpandAll&&(y.value=new Set(U(a.data||[])),i.value=C(a.data||[]),t.nextTick(()=>{M(),k()}));const e=new Set(U(a.data||[]));h.value=new Set([...h.value].filter(l=>e.has(l))),p.value=new Set([...p.value].filter(l=>e.has(l)))});function Ee(e){const l=q(e,a.data||[])||[];for(const n of l)y.value.add(w(n));i.value=C(a.data||[])}function ue(e){e!=null&&(Ee(e),t.nextTick(()=>{const l=i.value.findIndex(c=>c.id===e);if(l<0||!v.value)return;const n=z.get(e)||H,o=(g.value[l]??0)-n,u=v.value.clientHeight,r=Math.max(0,o-Math.max(0,(u-n)/2));v.value.scrollTop=r,B.value=r,k(),t.nextTick(()=>{const c=O.get(e);if(!c||!v.value)return;const f=c.offsetLeft,s=c.offsetWidth,d=v.value.clientWidth,x=Math.max(0,f+Math.max(0,s/2)-Math.max(0,d/2));v.value.scrollLeft=x})}))}function Be(e){L.value=e??null,ue(L.value)}return j({getCurrentKey:()=>L.value,setCurrentKey:Be,scrollTo:ue,getCheckedKeys:()=>Array.from(h.value),setCheckedKeys:te,setChecked:(e,l)=>G(e,l)}),t.watch(L,e=>{const l=Z(e,a.data||[]);l&&A("current-change",l)}),(e,l)=>(t.openBlock(),t.createElementBlock("div",{ref_key:"containerRef",ref:v,class:t.normalizeClass(["vtree",{"is-dragging":S.value}]),style:t.normalizeStyle({height:typeof m.height=="number"?m.height+"px":m.height||"100%","--vtree-bg":m.backgroundColor,"--vtree-text":m.textColor,"--vtree-hover":m.hoverColor}),onScroll:ke},[ve.value?(t.openBlock(),t.createElementBlock("div",Ie,[t.renderSlot(e.$slots,"empty",{},()=>[t.createElementVNode("div",Le,t.toDisplayString(m.emptyText),1)],!0)])):(t.openBlock(),t.createElementBlock(t.Fragment,{key:0},[t.createElementVNode("div",{style:t.normalizeStyle({height:le.value+"px",position:"relative",minWidth:"100%",width:"max-content"})},[t.createElementVNode("div",{style:t.normalizeStyle({height:I.value+"px"})},null,4),(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(i.value.slice(K.value,b.value),n=>(t.openBlock(),t.createElementBlock("div",{key:n.id,class:"vtree-row-wrapper"},[t.createElementVNode("div",{class:t.normalizeClass(["vtree-row",{"is-target-inner":S.value&&D.value===n.id&&T.value==="inner","is-active":L.value===n.id}]),style:t.normalizeStyle({paddingLeft:n.level*16+"px","--active-color":m.highlightColor}),onMousedown:o=>we(n,o),onClick:o=>Se(n,o),onContextmenu:t.withModifiers(o=>Te(n,o),["prevent"]),ref_for:!0,ref:o=>ge(n.id,o)},[t.createElementVNode("span",{class:t.normalizeClass(["vtree-caret-box",{"is-leaf":n.isLeaf}]),onClick:t.withModifiers(o=>!n.isLeaf&&fe(n.id),["stop"])},[n.isLeaf?t.createCommentVNode("",!0):(t.openBlock(),t.createElementBlock("span",{key:0,class:t.normalizeClass(["vtree-caret",{expanded:ee(n.id)}])},null,2))],10,Ae),m.showCheckbox?(t.openBlock(),t.createElementBlock("input",{key:0,class:"vtree-checkbox",type:"checkbox",checked:he(n.id),indeterminate:me(n.id),disabled:a.disabledChecked?a.disabledChecked(n.node):!1,onClick:t.withModifiers(o=>pe(n,o),["stop"])},null,8,ze)):t.createCommentVNode("",!0),t.renderSlot(e.$slots,"default",{node:n.node,data:n.node,level:n.level,expanded:ee(n.id),isLeaf:n.isLeaf},()=>[t.createElementVNode("span",Ke,t.toDisplayString(n.node[de.value]),1)],!0)],46,Me),S.value&&D.value===n.id&&(T.value==="prev"||T.value==="next")?(t.openBlock(),t.createElementBlock("div",{key:0,class:t.normalizeClass(["vtree-drop-line",{"is-prev":T.value==="prev","is-next":T.value==="next"}])},null,2)):t.createCommentVNode("",!0)]))),128)),t.createElementVNode("div",{style:t.normalizeStyle({height:J.value+"px"})},null,4)],4),S.value?(t.openBlock(),t.createElementBlock("div",{key:0,class:"vtree-ghost",style:t.normalizeStyle({top:X.value+"px"})},null,4)):t.createCommentVNode("",!0)],64))],38))}}),Re=(m,j)=>{const Y=m.__vccOpts||m;for(const[a,A]of j)Y[a]=A;return Y},Ve=Re(Ne,[["__scopeId","data-v-d2996104"]]);exports.AmazingTree=Ve;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("vue"),Me=["onMousedown","onClick","onContextmenu"],Ae=["onClick"],Ke=["checked","indeterminate","disabled","onClick"],Ie={class:"amazing-tree-label"},Le={key:1,class:"amazing-tree-empty"},Ne={class:"amazing-tree-empty-inner"},H=28,Re=t.defineComponent({__name:"AmazingTree",props:{data:{},props:{default:()=>({value:"value",label:"label",children:"children"})},allowDrag:{},allowDrop:{},height:{default:void 0},highlightColor:{default:"#1e71ff"},backgroundColor:{default:"#1d1d24"},textColor:{default:"#c8d3de"},hoverColor:{default:"#5d90e5"},currentNodeKey:{},defaultExpandedKeys:{},defaultExpandAll:{type:Boolean,default:!1},draggable:{type:Boolean,default:!1},emptyText:{default:"暂无数据"},showCheckbox:{type:Boolean,default:!1},checkStrictly:{type:Boolean,default:!1},defaultCheckedKeys:{default:()=>[]},disabledChecked:{}},emits:["node-click","node-contextmenu","node-drop","current-change","check-change"],setup(m,{expose:j,emit:Y}){const a=m,M=Y,de=t.computed(()=>a.props.value||"value"),ve=t.computed(()=>a.props.label||"label"),_=t.computed(()=>a.props.children||"children"),fe=t.computed(()=>Array.isArray(a.data)?a.data.length===0:!0),y=t.ref(new Set),h=t.ref(new Set),p=t.ref(new Set);function ee(e){return y.value.has(e)}function he(e){y.value.has(e)?y.value.delete(e):y.value.add(e),i.value=C(a.data||[]),t.nextTick(()=>{B(),k()})}function w(e){return e[de.value]}function z(e){const n=e[_.value];return Array.isArray(n)?n:[]}function me(e){return h.value.has(e)}function pe(e){return p.value.has(e)}function G(e,n){if(n?h.value.add(e):h.value.delete(e),p.value.delete(e),!a.checkStrictly){const l=Z(e,a.data||[]);if(l){const o=[l];for(;o.length;){const r=o.pop(),c=w(r);n?h.value.add(c):h.value.delete(c),p.value.delete(c);const f=z(r);for(const s of f)o.push(s)}const u=q(e,a.data||[])||[];for(const r of u){const c=w(r),f=z(r);let s=!0,d=!1;for(const x of f){const $=w(x),re=h.value.has($),ie=p.value.has($);(re||ie)&&(d=!0),(!re||ie)&&(s=!1)}f.length===0?(h.value.has(c),p.value.delete(c)):s?(h.value.add(c),p.value.delete(c)):d?(h.value.delete(c),p.value.add(c)):(h.value.delete(c),p.value.delete(c))}}}}function te(e){h.value=new Set,p.value=new Set;for(const n of e||[])G(n,!0)}function ge(e,n){const l=n.target;a.disabledChecked&&a.disabledChecked(e.node)||(M("check-change",e.node,!!l.checked),G(e.id,!!l.checked))}function C(e){const n=[];function l(o,u,r){for(let c=0;c<o.length;c++){const f=o[c],s=w(f),d=z(f),x=d.length===0;n.push({id:s,node:f,parent:u,level:r,index:c,isLeaf:x}),!x&&y.value.has(s)&&l(d,f,r+1)}}return l(e,null,0),n}const v=t.ref(null),E=t.ref(0),R=t.ref(0),i=t.ref([]),A=t.reactive(new Map),g=t.computed(()=>{let e=0;const n=[];for(const l of i.value){const o=A.get(l.id)||H;e+=o,n.push(e)}return n}),ne=t.computed(()=>{const e=g.value;return e.length?e[e.length-1]:0});function le(e){let n=0,l=g.value.length-1,o=0;for(;n<=l;){const u=n+l>>1;g.value[u]!==void 0&&g.value[u]>=e?(o=u,l=u-1):n=u+1}return o}const K=t.ref(0),b=t.ref(0),I=t.ref(0),J=t.ref(0);function k(){if(R.value=v.value?.clientHeight||0,g.value.length===0||i.value.length===0){K.value=0,b.value=0,I.value=0,J.value=0;return}const e=le(E.value);K.value=Math.max(0,e-3);const n=i.value[K.value],l=n?A.get(n.id)||H:0,u=(g.value[K.value]??0)-l;I.value=Math.max(0,u);let r=K.value;const c=E.value+R.value+3*H;for(;r<i.value.length&&(g.value[r]??0)<c;)r++;b.value=Math.min(i.value.length,r+1);const s=(g.value[b.value-1]??0)-I.value;if(s<R.value&&b.value<i.value.length){let d=b.value,x=s;for(;x<R.value&&d<i.value.length;)d++,x=(g.value[d-1]??0)-I.value;b.value=d}J.value=Math.max(0,ne.value-I.value-((g.value[b.value-1]??0)-I.value))}t.watch([E,()=>a.data,y],()=>{i.value=C(a.data||[]),t.nextTick(B),k()}),t.onMounted(()=>{i.value=C(a.data||[]),t.nextTick(B),k(),a.defaultCheckedKeys&&a.defaultCheckedKeys.length&&te(a.defaultCheckedKeys),v.value&&(V=new ResizeObserver(()=>{R.value=v.value?.clientHeight||0,k()}),V.observe(v.value))});let V=null;t.onUnmounted(()=>{V&&(V.disconnect(),V=null)});const O=t.reactive(new Map);function ke(e,n){n?O.set(e,n):O.delete(e)}function B(){let e=!1;for(const n of i.value.slice(K.value,b.value)){const l=O.get(n.id);if(l){const o=l.offsetHeight;(!A.has(n.id)||A.get(n.id)!==o)&&(A.set(n.id,o),e=!0)}}e&&k()}function xe(){E.value=v.value?.scrollTop||0,k()}const S=t.ref(!1),Q=t.ref(null),D=t.ref(null),T=t.ref(null),X=t.ref(0),L=t.ref(null),F=t.ref(0);let N=null;function P(){N!=null&&(cancelAnimationFrame(N),N=null)}function ae(){if(!S.value||F.value===0){P();return}const e=v.value;if(!e){P();return}const n=e.scrollHeight-e.clientHeight,l=12;e.scrollTop=Math.max(0,Math.min(n,e.scrollTop+F.value*l)),E.value=e.scrollTop,k(),N=requestAnimationFrame(ae)}function ye(){F.value!==0&&N==null&&(N=requestAnimationFrame(ae)),F.value===0&&P()}function W(e){if(e==null)return null;for(const n of i.value)if(n.id===e)return n;return null}function we(e){const n=v.value.getBoundingClientRect(),l=e-n.top+E.value;return le(l)}function Ce(e,n){!a.draggable||n.button!==0||!(!a.allowDrag||a.allowDrag(e.node))||(S.value=!0,Q.value=e.id,X.value=n.clientY,n.preventDefault(),window.addEventListener("mousemove",oe),window.addEventListener("mouseup",ce))}function oe(e){if(!S.value)return;X.value=e.clientY;const n=we(e.clientY),l=i.value[Math.min(Math.max(n,0),i.value.length-1)];if(D.value=l?.id??null,!l){T.value=null;return}const o=g.value[n]??0,u=A.get(l.id)??H,r=o-u,c=v.value.getBoundingClientRect(),s=(e.clientY-c.top+E.value-r)/u;let d="inner";s<.25?d="prev":s>.75&&(d="next");const x=W(Q.value),$=a.allowDrop?!!(x&&a.allowDrop(x.node,l.node,d)):!0;T.value=$?d:null,F.value=e.clientY>c.bottom?1:e.clientY<c.top?-1:0,ye()}function q(e,n,l=[]){for(const o of n){if(w(o)===e)return l;const u=z(o);if(u.length){const r=q(e,u,[...l,o]);if(r)return r}}return null}function Z(e,n){if(e==null)return null;for(const l of n){if(w(l)===e)return l;const o=z(l),u=Z(e,o);if(u)return u}return null}function U(e){const n=[];for(const l of e){n.push(w(l));const o=z(l);o.length&&n.push(...U(o))}return n}function be(e){const n=e.parent;if(n)z(n).splice(e.index,1);else{const l=a.data.findIndex(o=>w(o)===e.id);l>=0&&a.data.splice(l,1)}}function Se(e,n,l){if(l==="inner"){Array.isArray(n.node[_.value])||(n.node[_.value]=[]),n.node[_.value].push(e),y.value.add(n.id);return}const o=n.parent;if(o){const u=z(o),r=n.index+(l==="next"?1:0);u.splice(r,0,e)}else{const u=n.index+(l==="next"?1:0);a.data.splice(u,0,e)}}function ce(){if(window.removeEventListener("mousemove",oe),window.removeEventListener("mouseup",ce),P(),!S.value)return;const e=W(Q.value),n=W(D.value),l=T.value;if(S.value=!1,T.value=null,D.value=null,!e||!n||!l||a.allowDrop&&!a.allowDrop(e.node,n.node,l)||e.id===n.id)return;const o=l==="inner"?n.node:n.parent||null;if(o){const f=q(w(o),a.data||[])||[];for(const s of f)if(w(s)===e.id)return}const u=e.node;be(e);const r=C(a.data||[]);i.value=r;const c=W(n.id)||n;Se(u,c,l),i.value=C(a.data||[]),t.nextTick(()=>{B(),k()}),M("node-drop",u,c.node,l)}function Te(e,n){L.value=e.id,M("node-click",e.node,n)}function ze(e,n){M("node-contextmenu",e.node,n)}t.watchEffect(()=>{t.nextTick(B)}),t.watch(()=>a.currentNodeKey,e=>{L.value=e??null},{immediate:!0}),t.watch(()=>a.defaultExpandedKeys,e=>{y.value=new Set(e||[]),i.value=C(a.data||[]),t.nextTick(()=>{B(),k()})},{immediate:!0}),t.watch(()=>a.defaultExpandAll,e=>{e&&(y.value=new Set(U(a.data||[])),i.value=C(a.data||[]),t.nextTick(()=>{B(),k()}))},{immediate:!0}),t.watch(()=>a.data,()=>{a.defaultExpandAll&&(y.value=new Set(U(a.data||[])),i.value=C(a.data||[]),t.nextTick(()=>{B(),k()}));const e=new Set(U(a.data||[]));h.value=new Set([...h.value].filter(n=>e.has(n))),p.value=new Set([...p.value].filter(n=>e.has(n)))});function Ee(e){const n=q(e,a.data||[])||[];for(const l of n)y.value.add(w(l));i.value=C(a.data||[])}function ue(e){e!=null&&(Ee(e),t.nextTick(()=>{const n=i.value.findIndex(c=>c.id===e);if(n<0||!v.value)return;const l=A.get(e)||H,o=(g.value[n]??0)-l,u=v.value.clientHeight,r=Math.max(0,o-Math.max(0,(u-l)/2));v.value.scrollTop=r,E.value=r,k(),t.nextTick(()=>{const c=O.get(e);if(!c||!v.value)return;const f=c.offsetLeft,s=c.offsetWidth,d=v.value.clientWidth,x=Math.max(0,f+Math.max(0,s/2)-Math.max(0,d/2));v.value.scrollLeft=x})}))}function Be(e){L.value=e??null,ue(L.value)}return j({getCurrentKey:()=>L.value,setCurrentKey:Be,scrollTo:ue,getCheckedKeys:()=>Array.from(h.value),setCheckedKeys:te,setChecked:(e,n)=>G(e,n)}),t.watch(L,e=>{const n=Z(e,a.data||[]);n&&M("current-change",n)}),(e,n)=>(t.openBlock(),t.createElementBlock("div",{ref_key:"containerRef",ref:v,class:t.normalizeClass(["amazing-tree",{"is-dragging":S.value}]),style:t.normalizeStyle({height:typeof m.height=="number"?m.height+"px":m.height||"100%","--vtree-bg":m.backgroundColor,"--vtree-text":m.textColor,"--vtree-hover":m.hoverColor}),onScroll:xe},[fe.value?(t.openBlock(),t.createElementBlock("div",Le,[t.renderSlot(e.$slots,"empty",{},()=>[t.createElementVNode("div",Ne,t.toDisplayString(m.emptyText),1)],!0)])):(t.openBlock(),t.createElementBlock(t.Fragment,{key:0},[t.createElementVNode("div",{style:t.normalizeStyle({height:ne.value+"px",position:"relative",minWidth:"100%",width:"max-content"})},[t.createElementVNode("div",{style:t.normalizeStyle({height:I.value+"px"})},null,4),(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(i.value.slice(K.value,b.value),l=>(t.openBlock(),t.createElementBlock("div",{key:l.id,class:"amazing-tree-row-wrapper"},[t.createElementVNode("div",{class:t.normalizeClass(["amazing-tree-row",{"is-target-inner":S.value&&D.value===l.id&&T.value==="inner","is-active":L.value===l.id}]),style:t.normalizeStyle({paddingLeft:l.level*16+"px","--active-color":m.highlightColor}),onMousedown:o=>Ce(l,o),onClick:o=>Te(l,o),onContextmenu:t.withModifiers(o=>ze(l,o),["prevent"]),ref_for:!0,ref:o=>ke(l.id,o)},[t.createElementVNode("span",{class:t.normalizeClass(["amazing-tree-caret-box",{"is-leaf":l.isLeaf}]),onClick:t.withModifiers(o=>!l.isLeaf&&he(l.id),["stop"])},[l.isLeaf?t.createCommentVNode("",!0):(t.openBlock(),t.createElementBlock("span",{key:0,class:t.normalizeClass(["amazing-tree-caret",{expanded:ee(l.id)}])},null,2))],10,Ae),m.showCheckbox?(t.openBlock(),t.createElementBlock("input",{key:0,class:"amazing-tree-checkbox",type:"checkbox",checked:me(l.id),indeterminate:pe(l.id),disabled:a.disabledChecked?a.disabledChecked(l.node):!1,onClick:t.withModifiers(o=>ge(l,o),["stop"])},null,8,Ke)):t.createCommentVNode("",!0),t.renderSlot(e.$slots,"default",{node:l.node,data:l.node,level:l.level,expanded:ee(l.id),isLeaf:l.isLeaf},()=>[t.createElementVNode("span",Ie,t.toDisplayString(l.node[ve.value]),1)],!0)],46,Me),S.value&&D.value===l.id&&(T.value==="prev"||T.value==="next")?(t.openBlock(),t.createElementBlock("div",{key:0,class:t.normalizeClass(["amazing-tree-drop-line",{"is-prev":T.value==="prev","is-next":T.value==="next"}])},null,2)):t.createCommentVNode("",!0)]))),128)),t.createElementVNode("div",{style:t.normalizeStyle({height:J.value+"px"})},null,4)],4),S.value?(t.openBlock(),t.createElementBlock("div",{key:0,class:"amazing-tree-ghost",style:t.normalizeStyle({top:X.value+"px"})},null,4)):t.createCommentVNode("",!0)],64))],38))}}),Ve=(m,j)=>{const Y=m.__vccOpts||m;for(const[a,M]of j)Y[a]=M;return Y},se=Ve(Re,[["__scopeId","data-v-2da931e7"]]);exports.AmazingTree=se;exports.default=se;
@@ -1 +1 @@
1
- .vtree[data-v-d2996104]{width:100%;overflow:auto;position:relative;background:var(--vtree-bg);color:var(--vtree-text);scrollbar-width:thin;scrollbar-color:rgba(144,147,153,.3) transparent;cursor:pointer;--vtree-primary: #409eff;--vtree-checkbox-bg: #1d1d24;--vtree-checkbox-border: #4c4d4f;--vtree-checkbox-hover-border: #8d8e91;--vtree-checkbox-disabled-bg: #2c2f33;--vtree-checkbox-disabled-border: #5c5f63;--vtree-checkbox-check: #ffffff;--vtree-checkbox-check-disabled: #cfd3dc}.vtree.is-dragging[data-v-d2996104],.vtree.is-dragging[data-v-d2996104] *{-webkit-user-select:none;user-select:none}.vtree[data-v-d2996104] *{cursor:pointer}.vtree input[type=checkbox][data-v-d2996104]:disabled{cursor:not-allowed}.vtree .vtree-checkbox[data-v-d2996104]{-webkit-appearance:none;appearance:none;position:relative;width:14px;height:14px;border:1px solid var(--vtree-checkbox-border);background:var(--vtree-checkbox-bg);border-radius:2px;outline:none;transition:border-color .12s ease,background-color .12s ease,box-shadow .12s ease;vertical-align:middle;margin-right:6px}.vtree .vtree-checkbox[data-v-d2996104]:not(:disabled):hover{border-color:var(--vtree-checkbox-hover-border)}.vtree .vtree-checkbox[data-v-d2996104]:focus-visible{box-shadow:0 0 0 2px #409eff33}.vtree .vtree-checkbox[data-v-d2996104]:checked{background:var(--vtree-primary);border-color:var(--vtree-primary)}.vtree .vtree-checkbox[data-v-d2996104]:checked:after{content:"";position:absolute;left:3px;top:0;width:4px;height:8px;border:2px solid var(--vtree-checkbox-check);border-top:0;border-left:0;transform:rotate(45deg)}.vtree .vtree-checkbox[data-v-d2996104]:indeterminate{background:var(--vtree-primary);border-color:var(--vtree-primary)}.vtree .vtree-checkbox[data-v-d2996104]:indeterminate:after{content:"";position:absolute;left:2px;top:5px;width:10px;height:2px;background:var(--vtree-checkbox-check);border-radius:1px}.vtree .vtree-checkbox[data-v-d2996104]:disabled{background:var(--vtree-checkbox-disabled-bg);border-color:var(--vtree-checkbox-disabled-border)}.vtree .vtree-checkbox[data-v-d2996104]:disabled:checked:after{border-color:var(--vtree-checkbox-check-disabled)}.vtree .vtree-checkbox[data-v-d2996104]:disabled:indeterminate:after{background:var(--vtree-checkbox-check-disabled)}.vtree .vtree-row-wrapper[data-v-d2996104]{position:relative}.vtree .vtree-row-wrapper .vtree-drop-line[data-v-d2996104]{position:absolute;left:0;right:0;height:0;border-top:2px solid #409eff}.vtree .vtree-row-wrapper .vtree-drop-line.is-prev[data-v-d2996104]{top:0}.vtree .vtree-row-wrapper .vtree-drop-line.is-next[data-v-d2996104]{bottom:0}.vtree .vtree-row[data-v-d2996104]{display:flex;align-items:center;gap:4px;box-sizing:border-box;min-height:24px;padding:2px 8px;white-space:nowrap}.vtree .vtree-row[data-v-d2996104]:hover{background:var(--vtree-hover)}.vtree .vtree-row.is-active[data-v-d2996104],.vtree .vtree-row.is-active[data-v-d2996104]:hover{background:var(--active-color)}.vtree .vtree-row.is-target-inner[data-v-d2996104]{outline:2px dashed #409eff}.vtree .vtree-row .vtree-caret-box[data-v-d2996104]{display:inline-flex;align-items:center;justify-content:center;height:100%;aspect-ratio:1/1;min-width:16px;margin-right:4px;cursor:pointer}.vtree .vtree-row .vtree-caret-box.is-leaf[data-v-d2996104]{pointer-events:none}.vtree .vtree-row .vtree-caret[data-v-d2996104]{display:block;width:0;height:0;border-left:5px solid transparent;border-right:5px solid transparent;border-top:6px solid #909399;transform:rotate(-90deg);transition:transform .1s linear}.vtree .vtree-row .vtree-caret.expanded[data-v-d2996104]{transform:rotate(0)}.vtree .vtree-row .vtree-label[data-v-d2996104]{color:inherit}.vtree .vtree-ghost[data-v-d2996104]{position:fixed;left:16px;width:120px;height:24px;background:#409eff33;border:1px solid #409eff;pointer-events:none}.vtree .vtree-empty[data-v-d2996104]{width:100%;height:100%;display:flex;align-items:center;justify-content:center}.vtree .vtree-empty[data-v-d2996104]>*{width:100%;height:100%;display:flex;align-items:center;justify-content:center}.vtree .vtree-empty .vtree-empty-inner[data-v-d2996104]{color:var(--vtree-text)}[data-v-d2996104] .vtree::-webkit-scrollbar{width:8px;height:8px}[data-v-d2996104] .vtree::-webkit-scrollbar-track{background:transparent}[data-v-d2996104] .vtree::-webkit-scrollbar-thumb{background-color:#9093994d;border-radius:4px}[data-v-d2996104] .vtree::-webkit-scrollbar-thumb:hover{background-color:#90939980}
1
+ .amazing-tree{width:100%;overflow:auto;position:relative;background:var(--vtree-bg);color:var(--vtree-text);scrollbar-width:thin;scrollbar-color:rgba(144,147,153,.3) transparent;cursor:pointer;--vtree-primary: #409eff;--vtree-checkbox-bg: #1d1d24;--vtree-checkbox-border: #4c4d4f;--vtree-checkbox-hover-border: #8d8e91;--vtree-checkbox-disabled-bg: #2c2f33;--vtree-checkbox-disabled-border: #5c5f63;--vtree-checkbox-check: #ffffff;--vtree-checkbox-check-disabled: #cfd3dc}.amazing-tree.is-dragging,.amazing-tree.is-dragging *{-webkit-user-select:none;user-select:none}.amazing-tree *{cursor:pointer}.amazing-tree input[type=checkbox]:disabled{cursor:not-allowed}.amazing-tree .amazing-tree-checkbox{-webkit-appearance:none;appearance:none;position:relative;width:14px;height:14px;border:1px solid var(--vtree-checkbox-border);background:var(--vtree-checkbox-bg);border-radius:2px;outline:none;transition:border-color .12s ease,background-color .12s ease,box-shadow .12s ease;vertical-align:middle;margin-right:6px}.amazing-tree .amazing-tree-checkbox:not(:disabled):hover{border-color:var(--vtree-checkbox-hover-border)}.amazing-tree .amazing-tree-checkbox:focus-visible{box-shadow:0 0 0 2px #409eff33}.amazing-tree .amazing-tree-checkbox:checked{background:var(--vtree-primary);border-color:var(--vtree-primary)}.amazing-tree .amazing-tree-checkbox:checked:after{content:"";position:absolute;left:3px;top:0;width:4px;height:8px;border:2px solid var(--vtree-checkbox-check);border-top:0;border-left:0;transform:rotate(45deg)}.amazing-tree .amazing-tree-checkbox:indeterminate{background:var(--vtree-primary);border-color:var(--vtree-primary)}.amazing-tree .amazing-tree-checkbox:indeterminate:after{content:"";position:absolute;left:2px;top:5px;width:10px;height:2px;background:var(--vtree-checkbox-check);border-radius:1px}.amazing-tree .amazing-tree-checkbox:disabled{background:var(--vtree-checkbox-disabled-bg);border-color:var(--vtree-checkbox-disabled-border)}.amazing-tree .amazing-tree-checkbox:disabled:checked:after{border-color:var(--vtree-checkbox-check-disabled)}.amazing-tree .amazing-tree-checkbox:disabled:indeterminate:after{background:var(--vtree-checkbox-check-disabled)}.amazing-tree .amazing-tree-row-wrapper{position:relative}.amazing-tree .amazing-tree-row-wrapper .amazing-tree-drop-line{position:absolute;left:0;right:0;height:0;border-top:2px solid #409eff}.amazing-tree .amazing-tree-row-wrapper .amazing-tree-drop-line.is-prev{top:0}.amazing-tree .amazing-tree-row-wrapper .amazing-tree-drop-line.is-next{bottom:0}.amazing-tree .amazing-tree-row{display:flex;align-items:center;gap:4px;box-sizing:border-box;min-height:24px;padding:0 8px;white-space:nowrap}.amazing-tree .amazing-tree-row:hover{background:var(--vtree-hover)}.amazing-tree .amazing-tree-row.is-active,.amazing-tree .amazing-tree-row.is-active:hover{background:var(--active-color)}.amazing-tree .amazing-tree-row.is-target-inner{outline:2px dashed #409eff}.amazing-tree .amazing-tree-row .amazing-tree-caret-box{display:inline-flex;align-items:center;justify-content:center;height:100%;aspect-ratio:1/1;min-width:16px;margin-right:4px;cursor:pointer}.amazing-tree .amazing-tree-row .amazing-tree-caret-box.is-leaf{pointer-events:none}.amazing-tree .amazing-tree-row .amazing-tree-caret{display:block;width:0;height:0;border-left:5px solid transparent;border-right:5px solid transparent;border-top:6px solid #909399;transform:rotate(-90deg);transition:transform .1s linear}.amazing-tree .amazing-tree-row .amazing-tree-caret.expanded{transform:rotate(0)}.amazing-tree .amazing-tree-row .amazing-tree-label{color:inherit}.amazing-tree .amazing-tree-ghost{position:fixed;left:16px;width:120px;height:24px;background:#409eff33;border:1px solid #409eff;pointer-events:none}.amazing-tree .amazing-tree-empty{width:100%;height:100%;display:flex;align-items:center;justify-content:center}.amazing-tree .amazing-tree-empty>*{width:100%;height:100%;display:flex;align-items:center;justify-content:center}.amazing-tree .amazing-tree-empty .amazing-tree-empty-inner{color:var(--vtree-text)}:deep(.amazing-tree)::-webkit-scrollbar{width:8px;height:8px}:deep(.amazing-tree)::-webkit-scrollbar-track{background:transparent}:deep(.amazing-tree)::-webkit-scrollbar-thumb{background-color:#9093994d;border-radius:4px}:deep(.amazing-tree)::-webkit-scrollbar-thumb:hover{background-color:#90939980}.amazing-tree[data-v-2da931e7]{width:100%;overflow:auto;position:relative;background:var(--vtree-bg);color:var(--vtree-text);scrollbar-width:thin;scrollbar-color:rgba(144,147,153,.3) transparent;cursor:pointer;--vtree-primary: #409eff;--vtree-checkbox-bg: #1d1d24;--vtree-checkbox-border: #4c4d4f;--vtree-checkbox-hover-border: #8d8e91;--vtree-checkbox-disabled-bg: #2c2f33;--vtree-checkbox-disabled-border: #5c5f63;--vtree-checkbox-check: #ffffff;--vtree-checkbox-check-disabled: #cfd3dc}.amazing-tree.is-dragging[data-v-2da931e7],.amazing-tree.is-dragging[data-v-2da931e7] *{-webkit-user-select:none;user-select:none}.amazing-tree[data-v-2da931e7] *{cursor:pointer}.amazing-tree input[type=checkbox][data-v-2da931e7]:disabled{cursor:not-allowed}.amazing-tree .amazing-tree-checkbox[data-v-2da931e7]{-webkit-appearance:none;appearance:none;position:relative;width:14px;height:14px;border:1px solid var(--vtree-checkbox-border);background:var(--vtree-checkbox-bg);border-radius:2px;outline:none;transition:border-color .12s ease,background-color .12s ease,box-shadow .12s ease;vertical-align:middle;margin-right:6px}.amazing-tree .amazing-tree-checkbox[data-v-2da931e7]:not(:disabled):hover{border-color:var(--vtree-checkbox-hover-border)}.amazing-tree .amazing-tree-checkbox[data-v-2da931e7]:focus-visible{box-shadow:0 0 0 2px #409eff33}.amazing-tree .amazing-tree-checkbox[data-v-2da931e7]:checked{background:var(--vtree-primary);border-color:var(--vtree-primary)}.amazing-tree .amazing-tree-checkbox[data-v-2da931e7]:checked:after{content:"";position:absolute;left:3px;top:0;width:4px;height:8px;border:2px solid var(--vtree-checkbox-check);border-top:0;border-left:0;transform:rotate(45deg)}.amazing-tree .amazing-tree-checkbox[data-v-2da931e7]:indeterminate{background:var(--vtree-primary);border-color:var(--vtree-primary)}.amazing-tree .amazing-tree-checkbox[data-v-2da931e7]:indeterminate:after{content:"";position:absolute;left:2px;top:5px;width:10px;height:2px;background:var(--vtree-checkbox-check);border-radius:1px}.amazing-tree .amazing-tree-checkbox[data-v-2da931e7]:disabled{background:var(--vtree-checkbox-disabled-bg);border-color:var(--vtree-checkbox-disabled-border)}.amazing-tree .amazing-tree-checkbox[data-v-2da931e7]:disabled:checked:after{border-color:var(--vtree-checkbox-check-disabled)}.amazing-tree .amazing-tree-checkbox[data-v-2da931e7]:disabled:indeterminate:after{background:var(--vtree-checkbox-check-disabled)}.amazing-tree .amazing-tree-row-wrapper[data-v-2da931e7]{position:relative}.amazing-tree .amazing-tree-row-wrapper .amazing-tree-drop-line[data-v-2da931e7]{position:absolute;left:0;right:0;height:0;border-top:2px solid #409eff}.amazing-tree .amazing-tree-row-wrapper .amazing-tree-drop-line.is-prev[data-v-2da931e7]{top:0}.amazing-tree .amazing-tree-row-wrapper .amazing-tree-drop-line.is-next[data-v-2da931e7]{bottom:0}.amazing-tree .amazing-tree-row[data-v-2da931e7]{display:flex;align-items:center;gap:4px;box-sizing:border-box;min-height:24px;padding:0 8px;white-space:nowrap}.amazing-tree .amazing-tree-row[data-v-2da931e7]:hover{background:var(--vtree-hover)}.amazing-tree .amazing-tree-row.is-active[data-v-2da931e7],.amazing-tree .amazing-tree-row.is-active[data-v-2da931e7]:hover{background:var(--active-color)}.amazing-tree .amazing-tree-row.is-target-inner[data-v-2da931e7]{outline:2px dashed #409eff}.amazing-tree .amazing-tree-row .amazing-tree-caret-box[data-v-2da931e7]{display:inline-flex;align-items:center;justify-content:center;height:100%;aspect-ratio:1/1;min-width:16px;margin-right:4px;cursor:pointer}.amazing-tree .amazing-tree-row .amazing-tree-caret-box.is-leaf[data-v-2da931e7]{pointer-events:none}.amazing-tree .amazing-tree-row .amazing-tree-caret[data-v-2da931e7]{display:block;width:0;height:0;border-left:5px solid transparent;border-right:5px solid transparent;border-top:6px solid #909399;transform:rotate(-90deg);transition:transform .1s linear}.amazing-tree .amazing-tree-row .amazing-tree-caret.expanded[data-v-2da931e7]{transform:rotate(0)}.amazing-tree .amazing-tree-row .amazing-tree-label[data-v-2da931e7]{color:inherit}.amazing-tree .amazing-tree-ghost[data-v-2da931e7]{position:fixed;left:16px;width:120px;height:24px;background:#409eff33;border:1px solid #409eff;pointer-events:none}.amazing-tree .amazing-tree-empty[data-v-2da931e7]{width:100%;height:100%;display:flex;align-items:center;justify-content:center}.amazing-tree .amazing-tree-empty[data-v-2da931e7]>*{width:100%;height:100%;display:flex;align-items:center;justify-content:center}.amazing-tree .amazing-tree-empty .amazing-tree-empty-inner[data-v-2da931e7]{color:var(--vtree-text)}[data-v-2da931e7] .amazing-tree::-webkit-scrollbar{width:8px;height:8px}[data-v-2da931e7] .amazing-tree::-webkit-scrollbar-track{background:transparent}[data-v-2da931e7] .amazing-tree::-webkit-scrollbar-thumb{background-color:#9093994d;border-radius:4px}[data-v-2da931e7] .amazing-tree::-webkit-scrollbar-thumb:hover{background-color:#90939980}
@@ -1,8 +1,8 @@
1
- import { defineComponent as Oe, computed as N, ref as i, reactive as we, watch as _, nextTick as C, onMounted as Pe, onUnmounted as Ve, watchEffect as Ue, createElementBlock as T, openBlock as K, normalizeStyle as W, normalizeClass as $, Fragment as ke, createElementVNode as z, createCommentVNode as le, renderList as $e, withModifiers as ie, renderSlot as Ce, toDisplayString as be } from "vue";
2
- const qe = ["onMousedown", "onClick", "onContextmenu"], je = ["onClick"], Ge = ["checked", "indeterminate", "disabled", "onClick"], Je = { class: "vtree-label" }, Qe = {
1
+ import { defineComponent as Oe, computed as N, ref as s, reactive as we, watch as _, nextTick as C, onMounted as Pe, onUnmounted as Ve, watchEffect as Ue, createElementBlock as z, openBlock as T, normalizeStyle as W, normalizeClass as $, Fragment as ke, createElementVNode as Y, createCommentVNode as ne, renderList as $e, withModifiers as se, renderSlot as Ce, toDisplayString as be } from "vue";
2
+ const qe = ["onMousedown", "onClick", "onContextmenu"], je = ["onClick"], Ge = ["checked", "indeterminate", "disabled", "onClick"], Je = { class: "amazing-tree-label" }, Qe = {
3
3
  key: 1,
4
- class: "vtree-empty"
5
- }, Xe = { class: "vtree-empty-inner" }, q = 28, Ze = /* @__PURE__ */ Oe({
4
+ class: "amazing-tree-empty"
5
+ }, Xe = { class: "amazing-tree-empty-inner" }, q = 28, Ze = /* @__PURE__ */ Oe({
6
6
  __name: "AmazingTree",
7
7
  props: {
8
8
  data: {},
@@ -25,76 +25,76 @@ const qe = ["onMousedown", "onClick", "onContextmenu"], je = ["onClick"], Ge = [
25
25
  disabledChecked: {}
26
26
  },
27
27
  emits: ["node-click", "node-contextmenu", "node-drop", "current-change", "check-change"],
28
- setup(p, { expose: ne, emit: j }) {
29
- const n = p, R = j, Se = N(() => n.props.value || "value"), Me = N(() => n.props.label || "label"), G = N(() => n.props.children || "children"), Ae = N(() => Array.isArray(n.data) ? n.data.length === 0 : !0), w = i(/* @__PURE__ */ new Set()), h = i(/* @__PURE__ */ new Set()), g = i(/* @__PURE__ */ new Set());
28
+ setup(g, { expose: le, emit: j }) {
29
+ const l = g, L = j, Se = N(() => l.props.value || "value"), Me = N(() => l.props.label || "label"), G = N(() => l.props.children || "children"), Ae = N(() => Array.isArray(l.data) ? l.data.length === 0 : !0), w = s(/* @__PURE__ */ new Set()), h = s(/* @__PURE__ */ new Set()), p = s(/* @__PURE__ */ new Set());
30
30
  function re(e) {
31
31
  return w.value.has(e);
32
32
  }
33
- function Te(e) {
34
- w.value.has(e) ? w.value.delete(e) : w.value.add(e), s.value = b(n.data || []), C(() => {
35
- L(), x();
33
+ function ze(e) {
34
+ w.value.has(e) ? w.value.delete(e) : w.value.add(e), i.value = b(l.data || []), C(() => {
35
+ I(), x();
36
36
  });
37
37
  }
38
38
  function k(e) {
39
39
  return e[Se.value];
40
40
  }
41
- function E(e) {
41
+ function K(e) {
42
42
  const t = e[G.value];
43
43
  return Array.isArray(t) ? t : [];
44
44
  }
45
- function Ke(e) {
45
+ function Te(e) {
46
46
  return h.value.has(e);
47
47
  }
48
- function Ee(e) {
49
- return g.value.has(e);
48
+ function Ke(e) {
49
+ return p.value.has(e);
50
50
  }
51
51
  function ae(e, t) {
52
- if (t ? h.value.add(e) : h.value.delete(e), g.value.delete(e), !n.checkStrictly) {
53
- const l = se(e, n.data || []);
54
- if (l) {
55
- const a = [l];
52
+ if (t ? h.value.add(e) : h.value.delete(e), p.value.delete(e), !l.checkStrictly) {
53
+ const n = ie(e, l.data || []);
54
+ if (n) {
55
+ const a = [n];
56
56
  for (; a.length; ) {
57
57
  const c = a.pop(), o = k(c);
58
- t ? h.value.add(o) : h.value.delete(o), g.value.delete(o);
59
- const f = E(c);
58
+ t ? h.value.add(o) : h.value.delete(o), p.value.delete(o);
59
+ const f = K(c);
60
60
  for (const r of f) a.push(r);
61
61
  }
62
- const u = Z(e, n.data || []) || [];
62
+ const u = Z(e, l.data || []) || [];
63
63
  for (const c of u) {
64
- const o = k(c), f = E(c);
64
+ const o = k(c), f = K(c);
65
65
  let r = !0, d = !1;
66
66
  for (const y of f) {
67
- const te = k(y), xe = h.value.has(te), ye = g.value.has(te);
67
+ const te = k(y), xe = h.value.has(te), ye = p.value.has(te);
68
68
  (xe || ye) && (d = !0), (!xe || ye) && (r = !1);
69
69
  }
70
- f.length === 0 ? (h.value.has(o), g.value.delete(o)) : r ? (h.value.add(o), g.value.delete(o)) : d ? (h.value.delete(o), g.value.add(o)) : (h.value.delete(o), g.value.delete(o));
70
+ f.length === 0 ? (h.value.has(o), p.value.delete(o)) : r ? (h.value.add(o), p.value.delete(o)) : d ? (h.value.delete(o), p.value.add(o)) : (h.value.delete(o), p.value.delete(o));
71
71
  }
72
72
  }
73
73
  }
74
74
  }
75
75
  function de(e) {
76
- h.value = /* @__PURE__ */ new Set(), g.value = /* @__PURE__ */ new Set();
76
+ h.value = /* @__PURE__ */ new Set(), p.value = /* @__PURE__ */ new Set();
77
77
  for (const t of e || []) ae(t, !0);
78
78
  }
79
- function Ie(e, t) {
80
- const l = t.target;
81
- n.disabledChecked && n.disabledChecked(e.node) || (R("check-change", e.node, !!l.checked), ae(e.id, !!l.checked));
79
+ function Ee(e, t) {
80
+ const n = t.target;
81
+ l.disabledChecked && l.disabledChecked(e.node) || (L("check-change", e.node, !!n.checked), ae(e.id, !!n.checked));
82
82
  }
83
83
  function b(e) {
84
84
  const t = [];
85
- function l(a, u, c) {
85
+ function n(a, u, c) {
86
86
  for (let o = 0; o < a.length; o++) {
87
- const f = a[o], r = k(f), d = E(f), y = d.length === 0;
88
- t.push({ id: r, node: f, parent: u, level: c, index: o, isLeaf: y }), !y && w.value.has(r) && l(d, f, c + 1);
87
+ const f = a[o], r = k(f), d = K(f), y = d.length === 0;
88
+ t.push({ id: r, node: f, parent: u, level: c, index: o, isLeaf: y }), !y && w.value.has(r) && n(d, f, c + 1);
89
89
  }
90
90
  }
91
- return l(e, null, 0), t;
91
+ return n(e, null, 0), t;
92
92
  }
93
- const v = i(null), I = i(0), O = i(0), s = i([]), B = we(/* @__PURE__ */ new Map()), m = N(() => {
93
+ const v = s(null), E = s(0), O = s(0), i = s([]), R = we(/* @__PURE__ */ new Map()), m = N(() => {
94
94
  let e = 0;
95
95
  const t = [];
96
- for (const l of s.value) {
97
- const a = B.get(l.id) || q;
96
+ for (const n of i.value) {
97
+ const a = R.get(n.id) || q;
98
98
  e += a, t.push(e);
99
99
  }
100
100
  return t;
@@ -103,40 +103,40 @@ const qe = ["onMousedown", "onClick", "onContextmenu"], je = ["onClick"], Ge = [
103
103
  return e.length ? e[e.length - 1] : 0;
104
104
  });
105
105
  function fe(e) {
106
- let t = 0, l = m.value.length - 1, a = 0;
107
- for (; t <= l; ) {
108
- const u = t + l >> 1;
109
- m.value[u] !== void 0 && m.value[u] >= e ? (a = u, l = u - 1) : t = u + 1;
106
+ let t = 0, n = m.value.length - 1, a = 0;
107
+ for (; t <= n; ) {
108
+ const u = t + n >> 1;
109
+ m.value[u] !== void 0 && m.value[u] >= e ? (a = u, n = u - 1) : t = u + 1;
110
110
  }
111
111
  return a;
112
112
  }
113
- const D = i(0), S = i(0), H = i(0), oe = i(0);
113
+ const B = s(0), S = s(0), D = s(0), oe = s(0);
114
114
  function x() {
115
- if (O.value = v.value?.clientHeight || 0, m.value.length === 0 || s.value.length === 0) {
116
- D.value = 0, S.value = 0, H.value = 0, oe.value = 0;
115
+ if (O.value = v.value?.clientHeight || 0, m.value.length === 0 || i.value.length === 0) {
116
+ B.value = 0, S.value = 0, D.value = 0, oe.value = 0;
117
117
  return;
118
118
  }
119
- const e = fe(I.value);
120
- D.value = Math.max(0, e - 3);
121
- const t = s.value[D.value], l = t ? B.get(t.id) || q : 0, u = (m.value[D.value] ?? 0) - l;
122
- H.value = Math.max(0, u);
123
- let c = D.value;
124
- const o = I.value + O.value + 3 * q;
125
- for (; c < s.value.length && (m.value[c] ?? 0) < o; ) c++;
126
- S.value = Math.min(s.value.length, c + 1);
127
- const r = (m.value[S.value - 1] ?? 0) - H.value;
128
- if (r < O.value && S.value < s.value.length) {
119
+ const e = fe(E.value);
120
+ B.value = Math.max(0, e - 3);
121
+ const t = i.value[B.value], n = t ? R.get(t.id) || q : 0, u = (m.value[B.value] ?? 0) - n;
122
+ D.value = Math.max(0, u);
123
+ let c = B.value;
124
+ const o = E.value + O.value + 3 * q;
125
+ for (; c < i.value.length && (m.value[c] ?? 0) < o; ) c++;
126
+ S.value = Math.min(i.value.length, c + 1);
127
+ const r = (m.value[S.value - 1] ?? 0) - D.value;
128
+ if (r < O.value && S.value < i.value.length) {
129
129
  let d = S.value, y = r;
130
- for (; y < O.value && d < s.value.length; )
131
- d++, y = (m.value[d - 1] ?? 0) - H.value;
130
+ for (; y < O.value && d < i.value.length; )
131
+ d++, y = (m.value[d - 1] ?? 0) - D.value;
132
132
  S.value = d;
133
133
  }
134
- oe.value = Math.max(0, ve.value - H.value - ((m.value[S.value - 1] ?? 0) - H.value));
134
+ oe.value = Math.max(0, ve.value - D.value - ((m.value[S.value - 1] ?? 0) - D.value));
135
135
  }
136
- _([I, () => n.data, w], () => {
137
- s.value = b(n.data || []), C(L), x();
136
+ _([E, () => l.data, w], () => {
137
+ i.value = b(l.data || []), C(I), x();
138
138
  }), Pe(() => {
139
- s.value = b(n.data || []), C(L), x(), n.defaultCheckedKeys && n.defaultCheckedKeys.length && de(n.defaultCheckedKeys), v.value && (P = new ResizeObserver(() => {
139
+ i.value = b(l.data || []), C(I), x(), l.defaultCheckedKeys && l.defaultCheckedKeys.length && de(l.defaultCheckedKeys), v.value && (P = new ResizeObserver(() => {
140
140
  O.value = v.value?.clientHeight || 0, x();
141
141
  }), P.observe(v.value));
142
142
  });
@@ -145,24 +145,24 @@ const qe = ["onMousedown", "onClick", "onContextmenu"], je = ["onClick"], Ge = [
145
145
  P && (P.disconnect(), P = null);
146
146
  });
147
147
  const J = we(/* @__PURE__ */ new Map());
148
- function Le(e, t) {
148
+ function Ie(e, t) {
149
149
  t ? J.set(e, t) : J.delete(e);
150
150
  }
151
- function L() {
151
+ function I() {
152
152
  let e = !1;
153
- for (const t of s.value.slice(D.value, S.value)) {
154
- const l = J.get(t.id);
155
- if (l) {
156
- const a = l.offsetHeight;
157
- (!B.has(t.id) || B.get(t.id) !== a) && (B.set(t.id, a), e = !0);
153
+ for (const t of i.value.slice(B.value, S.value)) {
154
+ const n = J.get(t.id);
155
+ if (n) {
156
+ const a = n.offsetHeight;
157
+ (!R.has(t.id) || R.get(t.id) !== a) && (R.set(t.id, a), e = !0);
158
158
  }
159
159
  }
160
160
  e && x();
161
161
  }
162
- function Re() {
163
- I.value = v.value?.scrollTop || 0, x();
162
+ function Le() {
163
+ E.value = v.value?.scrollTop || 0, x();
164
164
  }
165
- const M = i(!1), ue = i(null), V = i(null), A = i(null), ce = i(0), Y = i(null), U = i(0);
165
+ const M = s(!1), ue = s(null), V = s(null), A = s(null), ce = s(0), H = s(null), U = s(0);
166
166
  let F = null;
167
167
  function Q() {
168
168
  F != null && (cancelAnimationFrame(F), F = null);
@@ -177,159 +177,159 @@ const qe = ["onMousedown", "onClick", "onContextmenu"], je = ["onClick"], Ge = [
177
177
  Q();
178
178
  return;
179
179
  }
180
- const t = e.scrollHeight - e.clientHeight, l = 12;
181
- e.scrollTop = Math.max(0, Math.min(t, e.scrollTop + U.value * l)), I.value = e.scrollTop, x(), F = requestAnimationFrame(he);
180
+ const t = e.scrollHeight - e.clientHeight, n = 12;
181
+ e.scrollTop = Math.max(0, Math.min(t, e.scrollTop + U.value * n)), E.value = e.scrollTop, x(), F = requestAnimationFrame(he);
182
182
  }
183
- function Be() {
183
+ function Re() {
184
184
  U.value !== 0 && F == null && (F = requestAnimationFrame(he)), U.value === 0 && Q();
185
185
  }
186
186
  function X(e) {
187
187
  if (e == null) return null;
188
- for (const t of s.value) if (t.id === e) return t;
188
+ for (const t of i.value) if (t.id === e) return t;
189
189
  return null;
190
190
  }
191
- function De(e) {
192
- const t = v.value.getBoundingClientRect(), l = e - t.top + I.value;
193
- return fe(l);
191
+ function Be(e) {
192
+ const t = v.value.getBoundingClientRect(), n = e - t.top + E.value;
193
+ return fe(n);
194
194
  }
195
- function He(e, t) {
196
- !n.draggable || t.button !== 0 || !(!n.allowDrag || n.allowDrag(e.node)) || (M.value = !0, ue.value = e.id, ce.value = t.clientY, t.preventDefault(), window.addEventListener("mousemove", pe), window.addEventListener("mouseup", ge));
195
+ function De(e, t) {
196
+ !l.draggable || t.button !== 0 || !(!l.allowDrag || l.allowDrag(e.node)) || (M.value = !0, ue.value = e.id, ce.value = t.clientY, t.preventDefault(), window.addEventListener("mousemove", ge), window.addEventListener("mouseup", pe));
197
197
  }
198
- function pe(e) {
198
+ function ge(e) {
199
199
  if (!M.value) return;
200
200
  ce.value = e.clientY;
201
- const t = De(e.clientY), l = s.value[Math.min(Math.max(t, 0), s.value.length - 1)];
202
- if (V.value = l?.id ?? null, !l) {
201
+ const t = Be(e.clientY), n = i.value[Math.min(Math.max(t, 0), i.value.length - 1)];
202
+ if (V.value = n?.id ?? null, !n) {
203
203
  A.value = null;
204
204
  return;
205
205
  }
206
- const a = m.value[t] ?? 0, u = B.get(l.id) ?? q, c = a - u, o = v.value.getBoundingClientRect(), r = (e.clientY - o.top + I.value - c) / u;
206
+ const a = m.value[t] ?? 0, u = R.get(n.id) ?? q, c = a - u, o = v.value.getBoundingClientRect(), r = (e.clientY - o.top + E.value - c) / u;
207
207
  let d = "inner";
208
208
  r < 0.25 ? d = "prev" : r > 0.75 && (d = "next");
209
- const y = X(ue.value), te = n.allowDrop ? !!(y && n.allowDrop(y.node, l.node, d)) : !0;
210
- A.value = te ? d : null, U.value = e.clientY > o.bottom ? 1 : e.clientY < o.top ? -1 : 0, Be();
209
+ const y = X(ue.value), te = l.allowDrop ? !!(y && l.allowDrop(y.node, n.node, d)) : !0;
210
+ A.value = te ? d : null, U.value = e.clientY > o.bottom ? 1 : e.clientY < o.top ? -1 : 0, Re();
211
211
  }
212
- function Z(e, t, l = []) {
212
+ function Z(e, t, n = []) {
213
213
  for (const a of t) {
214
- if (k(a) === e) return l;
215
- const u = E(a);
214
+ if (k(a) === e) return n;
215
+ const u = K(a);
216
216
  if (u.length) {
217
- const c = Z(e, u, [...l, a]);
217
+ const c = Z(e, u, [...n, a]);
218
218
  if (c) return c;
219
219
  }
220
220
  }
221
221
  return null;
222
222
  }
223
- function se(e, t) {
223
+ function ie(e, t) {
224
224
  if (e == null) return null;
225
- for (const l of t) {
226
- if (k(l) === e) return l;
227
- const a = E(l), u = se(e, a);
225
+ for (const n of t) {
226
+ if (k(n) === e) return n;
227
+ const a = K(n), u = ie(e, a);
228
228
  if (u) return u;
229
229
  }
230
230
  return null;
231
231
  }
232
232
  function ee(e) {
233
233
  const t = [];
234
- for (const l of e) {
235
- t.push(k(l));
236
- const a = E(l);
234
+ for (const n of e) {
235
+ t.push(k(n));
236
+ const a = K(n);
237
237
  a.length && t.push(...ee(a));
238
238
  }
239
239
  return t;
240
240
  }
241
- function Ye(e) {
241
+ function He(e) {
242
242
  const t = e.parent;
243
243
  if (t)
244
- E(t).splice(e.index, 1);
244
+ K(t).splice(e.index, 1);
245
245
  else {
246
- const l = n.data.findIndex((a) => k(a) === e.id);
247
- l >= 0 && n.data.splice(l, 1);
246
+ const n = l.data.findIndex((a) => k(a) === e.id);
247
+ n >= 0 && l.data.splice(n, 1);
248
248
  }
249
249
  }
250
- function ze(e, t, l) {
251
- if (l === "inner") {
250
+ function Ye(e, t, n) {
251
+ if (n === "inner") {
252
252
  Array.isArray(t.node[G.value]) || (t.node[G.value] = []), t.node[G.value].push(e), w.value.add(t.id);
253
253
  return;
254
254
  }
255
255
  const a = t.parent;
256
256
  if (a) {
257
- const u = E(a), c = t.index + (l === "next" ? 1 : 0);
257
+ const u = K(a), c = t.index + (n === "next" ? 1 : 0);
258
258
  u.splice(c, 0, e);
259
259
  } else {
260
- const u = t.index + (l === "next" ? 1 : 0);
261
- n.data.splice(u, 0, e);
260
+ const u = t.index + (n === "next" ? 1 : 0);
261
+ l.data.splice(u, 0, e);
262
262
  }
263
263
  }
264
- function ge() {
265
- if (window.removeEventListener("mousemove", pe), window.removeEventListener("mouseup", ge), Q(), !M.value) return;
266
- const e = X(ue.value), t = X(V.value), l = A.value;
267
- if (M.value = !1, A.value = null, V.value = null, !e || !t || !l || n.allowDrop && !n.allowDrop(e.node, t.node, l) || e.id === t.id) return;
268
- const a = l === "inner" ? t.node : t.parent || null;
264
+ function pe() {
265
+ if (window.removeEventListener("mousemove", ge), window.removeEventListener("mouseup", pe), Q(), !M.value) return;
266
+ const e = X(ue.value), t = X(V.value), n = A.value;
267
+ if (M.value = !1, A.value = null, V.value = null, !e || !t || !n || l.allowDrop && !l.allowDrop(e.node, t.node, n) || e.id === t.id) return;
268
+ const a = n === "inner" ? t.node : t.parent || null;
269
269
  if (a) {
270
- const f = Z(k(a), n.data || []) || [];
270
+ const f = Z(k(a), l.data || []) || [];
271
271
  for (const r of f) if (k(r) === e.id) return;
272
272
  }
273
273
  const u = e.node;
274
- Ye(e);
275
- const c = b(n.data || []);
276
- s.value = c;
274
+ He(e);
275
+ const c = b(l.data || []);
276
+ i.value = c;
277
277
  const o = X(t.id) || t;
278
- ze(u, o, l), s.value = b(n.data || []), C(() => {
279
- L(), x();
280
- }), R("node-drop", u, o.node, l);
278
+ Ye(u, o, n), i.value = b(l.data || []), C(() => {
279
+ I(), x();
280
+ }), L("node-drop", u, o.node, n);
281
281
  }
282
282
  function Fe(e, t) {
283
- Y.value = e.id, R("node-click", e.node, t);
283
+ H.value = e.id, L("node-click", e.node, t);
284
284
  }
285
285
  function Ne(e, t) {
286
- R("node-contextmenu", e.node, t);
286
+ L("node-contextmenu", e.node, t);
287
287
  }
288
288
  Ue(() => {
289
- C(L);
289
+ C(I);
290
290
  }), _(
291
- () => n.currentNodeKey,
291
+ () => l.currentNodeKey,
292
292
  (e) => {
293
- Y.value = e ?? null;
293
+ H.value = e ?? null;
294
294
  },
295
295
  { immediate: !0 }
296
296
  ), _(
297
- () => n.defaultExpandedKeys,
297
+ () => l.defaultExpandedKeys,
298
298
  (e) => {
299
- w.value = new Set(e || []), s.value = b(n.data || []), C(() => {
300
- L(), x();
299
+ w.value = new Set(e || []), i.value = b(l.data || []), C(() => {
300
+ I(), x();
301
301
  });
302
302
  },
303
303
  { immediate: !0 }
304
304
  ), _(
305
- () => n.defaultExpandAll,
305
+ () => l.defaultExpandAll,
306
306
  (e) => {
307
- e && (w.value = new Set(ee(n.data || [])), s.value = b(n.data || []), C(() => {
308
- L(), x();
307
+ e && (w.value = new Set(ee(l.data || [])), i.value = b(l.data || []), C(() => {
308
+ I(), x();
309
309
  }));
310
310
  },
311
311
  { immediate: !0 }
312
312
  ), _(
313
- () => n.data,
313
+ () => l.data,
314
314
  () => {
315
- n.defaultExpandAll && (w.value = new Set(ee(n.data || [])), s.value = b(n.data || []), C(() => {
316
- L(), x();
315
+ l.defaultExpandAll && (w.value = new Set(ee(l.data || [])), i.value = b(l.data || []), C(() => {
316
+ I(), x();
317
317
  }));
318
- const e = new Set(ee(n.data || []));
319
- h.value = new Set([...h.value].filter((t) => e.has(t))), g.value = new Set([...g.value].filter((t) => e.has(t)));
318
+ const e = new Set(ee(l.data || []));
319
+ h.value = new Set([...h.value].filter((t) => e.has(t))), p.value = new Set([...p.value].filter((t) => e.has(t)));
320
320
  }
321
321
  );
322
322
  function _e(e) {
323
- const t = Z(e, n.data || []) || [];
324
- for (const l of t) w.value.add(k(l));
325
- s.value = b(n.data || []);
323
+ const t = Z(e, l.data || []) || [];
324
+ for (const n of t) w.value.add(k(n));
325
+ i.value = b(l.data || []);
326
326
  }
327
327
  function me(e) {
328
328
  e != null && (_e(e), C(() => {
329
- const t = s.value.findIndex((o) => o.id === e);
329
+ const t = i.value.findIndex((o) => o.id === e);
330
330
  if (t < 0 || !v.value) return;
331
- const l = B.get(e) || q, a = (m.value[t] ?? 0) - l, u = v.value.clientHeight, c = Math.max(0, a - Math.max(0, (u - l) / 2));
332
- v.value.scrollTop = c, I.value = c, x(), C(() => {
331
+ const n = R.get(e) || q, a = (m.value[t] ?? 0) - n, u = v.value.clientHeight, c = Math.max(0, a - Math.max(0, (u - n) / 2));
332
+ v.value.scrollTop = c, E.value = c, x(), C(() => {
333
333
  const o = J.get(e);
334
334
  if (!o || !v.value) return;
335
335
  const f = o.offsetLeft, r = o.offsetWidth, d = v.value.clientWidth, y = Math.max(0, f + Math.max(0, r / 2) - Math.max(0, d / 2));
@@ -338,100 +338,101 @@ const qe = ["onMousedown", "onClick", "onContextmenu"], je = ["onClick"], Ge = [
338
338
  }));
339
339
  }
340
340
  function We(e) {
341
- Y.value = e ?? null, me(Y.value);
341
+ H.value = e ?? null, me(H.value);
342
342
  }
343
- return ne({
344
- getCurrentKey: () => Y.value,
343
+ return le({
344
+ getCurrentKey: () => H.value,
345
345
  setCurrentKey: We,
346
346
  scrollTo: me,
347
347
  getCheckedKeys: () => Array.from(h.value),
348
348
  setCheckedKeys: de,
349
349
  setChecked: (e, t) => ae(e, t)
350
- }), _(Y, (e) => {
351
- const t = se(e, n.data || []);
352
- t && R("current-change", t);
353
- }), (e, t) => (K(), T("div", {
350
+ }), _(H, (e) => {
351
+ const t = ie(e, l.data || []);
352
+ t && L("current-change", t);
353
+ }), (e, t) => (T(), z("div", {
354
354
  ref_key: "containerRef",
355
355
  ref: v,
356
- class: $(["vtree", { "is-dragging": M.value }]),
357
- style: W({ height: typeof p.height == "number" ? p.height + "px" : p.height || "100%", "--vtree-bg": p.backgroundColor, "--vtree-text": p.textColor, "--vtree-hover": p.hoverColor }),
358
- onScroll: Re
356
+ class: $(["amazing-tree", { "is-dragging": M.value }]),
357
+ style: W({ height: typeof g.height == "number" ? g.height + "px" : g.height || "100%", "--vtree-bg": g.backgroundColor, "--vtree-text": g.textColor, "--vtree-hover": g.hoverColor }),
358
+ onScroll: Le
359
359
  }, [
360
- Ae.value ? (K(), T("div", Qe, [
360
+ Ae.value ? (T(), z("div", Qe, [
361
361
  Ce(e.$slots, "empty", {}, () => [
362
- z("div", Xe, be(p.emptyText), 1)
362
+ Y("div", Xe, be(g.emptyText), 1)
363
363
  ], !0)
364
- ])) : (K(), T(ke, { key: 0 }, [
365
- z("div", {
364
+ ])) : (T(), z(ke, { key: 0 }, [
365
+ Y("div", {
366
366
  style: W({ height: ve.value + "px", position: "relative", minWidth: "100%", width: "max-content" })
367
367
  }, [
368
- z("div", {
369
- style: W({ height: H.value + "px" })
368
+ Y("div", {
369
+ style: W({ height: D.value + "px" })
370
370
  }, null, 4),
371
- (K(!0), T(ke, null, $e(s.value.slice(D.value, S.value), (l) => (K(), T("div", {
372
- key: l.id,
373
- class: "vtree-row-wrapper"
371
+ (T(!0), z(ke, null, $e(i.value.slice(B.value, S.value), (n) => (T(), z("div", {
372
+ key: n.id,
373
+ class: "amazing-tree-row-wrapper"
374
374
  }, [
375
- z("div", {
376
- class: $(["vtree-row", { "is-target-inner": M.value && V.value === l.id && A.value === "inner", "is-active": Y.value === l.id }]),
377
- style: W({ paddingLeft: l.level * 16 + "px", "--active-color": p.highlightColor }),
378
- onMousedown: (a) => He(l, a),
379
- onClick: (a) => Fe(l, a),
380
- onContextmenu: ie((a) => Ne(l, a), ["prevent"]),
375
+ Y("div", {
376
+ class: $(["amazing-tree-row", { "is-target-inner": M.value && V.value === n.id && A.value === "inner", "is-active": H.value === n.id }]),
377
+ style: W({ paddingLeft: n.level * 16 + "px", "--active-color": g.highlightColor }),
378
+ onMousedown: (a) => De(n, a),
379
+ onClick: (a) => Fe(n, a),
380
+ onContextmenu: se((a) => Ne(n, a), ["prevent"]),
381
381
  ref_for: !0,
382
- ref: (a) => Le(l.id, a)
382
+ ref: (a) => Ie(n.id, a)
383
383
  }, [
384
- z("span", {
385
- class: $(["vtree-caret-box", { "is-leaf": l.isLeaf }]),
386
- onClick: ie((a) => !l.isLeaf && Te(l.id), ["stop"])
384
+ Y("span", {
385
+ class: $(["amazing-tree-caret-box", { "is-leaf": n.isLeaf }]),
386
+ onClick: se((a) => !n.isLeaf && ze(n.id), ["stop"])
387
387
  }, [
388
- l.isLeaf ? le("", !0) : (K(), T("span", {
388
+ n.isLeaf ? ne("", !0) : (T(), z("span", {
389
389
  key: 0,
390
- class: $(["vtree-caret", { expanded: re(l.id) }])
390
+ class: $(["amazing-tree-caret", { expanded: re(n.id) }])
391
391
  }, null, 2))
392
392
  ], 10, je),
393
- p.showCheckbox ? (K(), T("input", {
393
+ g.showCheckbox ? (T(), z("input", {
394
394
  key: 0,
395
- class: "vtree-checkbox",
395
+ class: "amazing-tree-checkbox",
396
396
  type: "checkbox",
397
- checked: Ke(l.id),
398
- indeterminate: Ee(l.id),
399
- disabled: n.disabledChecked ? n.disabledChecked(l.node) : !1,
400
- onClick: ie((a) => Ie(l, a), ["stop"])
401
- }, null, 8, Ge)) : le("", !0),
397
+ checked: Te(n.id),
398
+ indeterminate: Ke(n.id),
399
+ disabled: l.disabledChecked ? l.disabledChecked(n.node) : !1,
400
+ onClick: se((a) => Ee(n, a), ["stop"])
401
+ }, null, 8, Ge)) : ne("", !0),
402
402
  Ce(e.$slots, "default", {
403
- node: l.node,
404
- data: l.node,
405
- level: l.level,
406
- expanded: re(l.id),
407
- isLeaf: l.isLeaf
403
+ node: n.node,
404
+ data: n.node,
405
+ level: n.level,
406
+ expanded: re(n.id),
407
+ isLeaf: n.isLeaf
408
408
  }, () => [
409
- z("span", Je, be(l.node[Me.value]), 1)
409
+ Y("span", Je, be(n.node[Me.value]), 1)
410
410
  ], !0)
411
411
  ], 46, qe),
412
- M.value && V.value === l.id && (A.value === "prev" || A.value === "next") ? (K(), T("div", {
412
+ M.value && V.value === n.id && (A.value === "prev" || A.value === "next") ? (T(), z("div", {
413
413
  key: 0,
414
- class: $(["vtree-drop-line", { "is-prev": A.value === "prev", "is-next": A.value === "next" }])
415
- }, null, 2)) : le("", !0)
414
+ class: $(["amazing-tree-drop-line", { "is-prev": A.value === "prev", "is-next": A.value === "next" }])
415
+ }, null, 2)) : ne("", !0)
416
416
  ]))), 128)),
417
- z("div", {
417
+ Y("div", {
418
418
  style: W({ height: oe.value + "px" })
419
419
  }, null, 4)
420
420
  ], 4),
421
- M.value ? (K(), T("div", {
421
+ M.value ? (T(), z("div", {
422
422
  key: 0,
423
- class: "vtree-ghost",
423
+ class: "amazing-tree-ghost",
424
424
  style: W({ top: ce.value + "px" })
425
- }, null, 4)) : le("", !0)
425
+ }, null, 4)) : ne("", !0)
426
426
  ], 64))
427
427
  ], 38));
428
428
  }
429
- }), et = (p, ne) => {
430
- const j = p.__vccOpts || p;
431
- for (const [n, R] of ne)
432
- j[n] = R;
429
+ }), et = (g, le) => {
430
+ const j = g.__vccOpts || g;
431
+ for (const [l, L] of le)
432
+ j[l] = L;
433
433
  return j;
434
- }, lt = /* @__PURE__ */ et(Ze, [["__scopeId", "data-v-d2996104"]]);
434
+ }, nt = /* @__PURE__ */ et(Ze, [["__scopeId", "data-v-2da931e7"]]);
435
435
  export {
436
- lt as AmazingTree
436
+ nt as AmazingTree,
437
+ nt as default
437
438
  };
@@ -1 +1 @@
1
- (function(A,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],t):(A=typeof globalThis<"u"?globalThis:A||self,t(A.AmazingTree={},A.Vue))})(this,(function(A,t){"use strict";const ue=["onMousedown","onClick","onContextmenu"],fe=["onClick"],he=["checked","indeterminate","disabled","onClick"],ve={class:"vtree-label"},pe={key:1,class:"vtree-empty"},me={class:"vtree-empty-inner"},V=28,ge=((p,G)=>{const _=p.__vccOpts||p;for(const[a,z]of G)_[a]=z;return _})(t.defineComponent({__name:"AmazingTree",props:{data:{},props:{default:()=>({value:"value",label:"label",children:"children"})},allowDrag:{},allowDrop:{},height:{default:void 0},highlightColor:{default:"#1e71ff"},backgroundColor:{default:"#1d1d24"},textColor:{default:"#c8d3de"},hoverColor:{default:"#5d90e5"},currentNodeKey:{},defaultExpandedKeys:{},defaultExpandAll:{type:Boolean,default:!1},draggable:{type:Boolean,default:!1},emptyText:{default:"暂无数据"},showCheckbox:{type:Boolean,default:!1},checkStrictly:{type:Boolean,default:!1},defaultCheckedKeys:{default:()=>[]},disabledChecked:{}},emits:["node-click","node-contextmenu","node-drop","current-change","check-change"],setup(p,{expose:G,emit:_}){const a=p,z=_,ke=t.computed(()=>a.props.value||"value"),xe=t.computed(()=>a.props.label||"label"),O=t.computed(()=>a.props.children||"children"),ye=t.computed(()=>Array.isArray(a.data)?a.data.length===0:!0),y=t.ref(new Set),v=t.ref(new Set),m=t.ref(new Set);function te(e){return y.value.has(e)}function we(e){y.value.has(e)?y.value.delete(e):y.value.add(e),s.value=C(a.data||[]),t.nextTick(()=>{M(),k()})}function w(e){return e[ke.value]}function E(e){const n=e[O.value];return Array.isArray(n)?n:[]}function Ce(e){return v.value.has(e)}function be(e){return m.value.has(e)}function J(e,n){if(n?v.value.add(e):v.value.delete(e),m.value.delete(e),!a.checkStrictly){const l=ee(e,a.data||[]);if(l){const o=[l];for(;o.length;){const i=o.pop(),c=w(i);n?v.value.add(c):v.value.delete(c),m.value.delete(c);const h=E(i);for(const d of h)o.push(d)}const r=U(e,a.data||[])||[];for(const i of r){const c=w(i),h=E(i);let d=!0,u=!1;for(const x of h){const j=w(x),se=v.value.has(j),de=m.value.has(j);(se||de)&&(u=!0),(!se||de)&&(d=!1)}h.length===0?(v.value.has(c),m.value.delete(c)):d?(v.value.add(c),m.value.delete(c)):u?(v.value.delete(c),m.value.add(c)):(v.value.delete(c),m.value.delete(c))}}}}function ne(e){v.value=new Set,m.value=new Set;for(const n of e||[])J(n,!0)}function Se(e,n){const l=n.target;a.disabledChecked&&a.disabledChecked(e.node)||(z("check-change",e.node,!!l.checked),J(e.id,!!l.checked))}function C(e){const n=[];function l(o,r,i){for(let c=0;c<o.length;c++){const h=o[c],d=w(h),u=E(h),x=u.length===0;n.push({id:d,node:h,parent:r,level:i,index:c,isLeaf:x}),!x&&y.value.has(d)&&l(u,h,i+1)}}return l(e,null,0),n}const f=t.ref(null),B=t.ref(0),D=t.ref(0),s=t.ref([]),K=t.reactive(new Map),g=t.computed(()=>{let e=0;const n=[];for(const l of s.value){const o=K.get(l.id)||V;e+=o,n.push(e)}return n}),le=t.computed(()=>{const e=g.value;return e.length?e[e.length-1]:0});function ae(e){let n=0,l=g.value.length-1,o=0;for(;n<=l;){const r=n+l>>1;g.value[r]!==void 0&&g.value[r]>=e?(o=r,l=r-1):n=r+1}return o}const I=t.ref(0),b=t.ref(0),L=t.ref(0),Q=t.ref(0);function k(){if(D.value=f.value?.clientHeight||0,g.value.length===0||s.value.length===0){I.value=0,b.value=0,L.value=0,Q.value=0;return}const e=ae(B.value);I.value=Math.max(0,e-3);const n=s.value[I.value],l=n?K.get(n.id)||V:0,r=(g.value[I.value]??0)-l;L.value=Math.max(0,r);let i=I.value;const c=B.value+D.value+3*V;for(;i<s.value.length&&(g.value[i]??0)<c;)i++;b.value=Math.min(s.value.length,i+1);const d=(g.value[b.value-1]??0)-L.value;if(d<D.value&&b.value<s.value.length){let u=b.value,x=d;for(;x<D.value&&u<s.value.length;)u++,x=(g.value[u-1]??0)-L.value;b.value=u}Q.value=Math.max(0,le.value-L.value-((g.value[b.value-1]??0)-L.value))}t.watch([B,()=>a.data,y],()=>{s.value=C(a.data||[]),t.nextTick(M),k()}),t.onMounted(()=>{s.value=C(a.data||[]),t.nextTick(M),k(),a.defaultCheckedKeys&&a.defaultCheckedKeys.length&&ne(a.defaultCheckedKeys),f.value&&(F=new ResizeObserver(()=>{D.value=f.value?.clientHeight||0,k()}),F.observe(f.value))});let F=null;t.onUnmounted(()=>{F&&(F.disconnect(),F=null)});const P=t.reactive(new Map);function Te(e,n){n?P.set(e,n):P.delete(e)}function M(){let e=!1;for(const n of s.value.slice(I.value,b.value)){const l=P.get(n.id);if(l){const o=l.offsetHeight;(!K.has(n.id)||K.get(n.id)!==o)&&(K.set(n.id,o),e=!0)}}e&&k()}function Ee(){B.value=f.value?.scrollTop||0,k()}const S=t.ref(!1),X=t.ref(null),H=t.ref(null),T=t.ref(null),Z=t.ref(0),N=t.ref(null),Y=t.ref(0);let R=null;function W(){R!=null&&(cancelAnimationFrame(R),R=null)}function oe(){if(!S.value||Y.value===0){W();return}const e=f.value;if(!e){W();return}const n=e.scrollHeight-e.clientHeight,l=12;e.scrollTop=Math.max(0,Math.min(n,e.scrollTop+Y.value*l)),B.value=e.scrollTop,k(),R=requestAnimationFrame(oe)}function Be(){Y.value!==0&&R==null&&(R=requestAnimationFrame(oe)),Y.value===0&&W()}function q(e){if(e==null)return null;for(const n of s.value)if(n.id===e)return n;return null}function Me(e){const n=f.value.getBoundingClientRect(),l=e-n.top+B.value;return ae(l)}function Ae(e,n){!a.draggable||n.button!==0||!(!a.allowDrag||a.allowDrag(e.node))||(S.value=!0,X.value=e.id,Z.value=n.clientY,n.preventDefault(),window.addEventListener("mousemove",ce),window.addEventListener("mouseup",re))}function ce(e){if(!S.value)return;Z.value=e.clientY;const n=Me(e.clientY),l=s.value[Math.min(Math.max(n,0),s.value.length-1)];if(H.value=l?.id??null,!l){T.value=null;return}const o=g.value[n]??0,r=K.get(l.id)??V,i=o-r,c=f.value.getBoundingClientRect(),d=(e.clientY-c.top+B.value-i)/r;let u="inner";d<.25?u="prev":d>.75&&(u="next");const x=q(X.value),j=a.allowDrop?!!(x&&a.allowDrop(x.node,l.node,u)):!0;T.value=j?u:null,Y.value=e.clientY>c.bottom?1:e.clientY<c.top?-1:0,Be()}function U(e,n,l=[]){for(const o of n){if(w(o)===e)return l;const r=E(o);if(r.length){const i=U(e,r,[...l,o]);if(i)return i}}return null}function ee(e,n){if(e==null)return null;for(const l of n){if(w(l)===e)return l;const o=E(l),r=ee(e,o);if(r)return r}return null}function $(e){const n=[];for(const l of e){n.push(w(l));const o=E(l);o.length&&n.push(...$(o))}return n}function ze(e){const n=e.parent;if(n)E(n).splice(e.index,1);else{const l=a.data.findIndex(o=>w(o)===e.id);l>=0&&a.data.splice(l,1)}}function Ke(e,n,l){if(l==="inner"){Array.isArray(n.node[O.value])||(n.node[O.value]=[]),n.node[O.value].push(e),y.value.add(n.id);return}const o=n.parent;if(o){const r=E(o),i=n.index+(l==="next"?1:0);r.splice(i,0,e)}else{const r=n.index+(l==="next"?1:0);a.data.splice(r,0,e)}}function re(){if(window.removeEventListener("mousemove",ce),window.removeEventListener("mouseup",re),W(),!S.value)return;const e=q(X.value),n=q(H.value),l=T.value;if(S.value=!1,T.value=null,H.value=null,!e||!n||!l||a.allowDrop&&!a.allowDrop(e.node,n.node,l)||e.id===n.id)return;const o=l==="inner"?n.node:n.parent||null;if(o){const h=U(w(o),a.data||[])||[];for(const d of h)if(w(d)===e.id)return}const r=e.node;ze(e);const i=C(a.data||[]);s.value=i;const c=q(n.id)||n;Ke(r,c,l),s.value=C(a.data||[]),t.nextTick(()=>{M(),k()}),z("node-drop",r,c.node,l)}function Ie(e,n){N.value=e.id,z("node-click",e.node,n)}function Le(e,n){z("node-contextmenu",e.node,n)}t.watchEffect(()=>{t.nextTick(M)}),t.watch(()=>a.currentNodeKey,e=>{N.value=e??null},{immediate:!0}),t.watch(()=>a.defaultExpandedKeys,e=>{y.value=new Set(e||[]),s.value=C(a.data||[]),t.nextTick(()=>{M(),k()})},{immediate:!0}),t.watch(()=>a.defaultExpandAll,e=>{e&&(y.value=new Set($(a.data||[])),s.value=C(a.data||[]),t.nextTick(()=>{M(),k()}))},{immediate:!0}),t.watch(()=>a.data,()=>{a.defaultExpandAll&&(y.value=new Set($(a.data||[])),s.value=C(a.data||[]),t.nextTick(()=>{M(),k()}));const e=new Set($(a.data||[]));v.value=new Set([...v.value].filter(n=>e.has(n))),m.value=new Set([...m.value].filter(n=>e.has(n)))});function Ne(e){const n=U(e,a.data||[])||[];for(const l of n)y.value.add(w(l));s.value=C(a.data||[])}function ie(e){e!=null&&(Ne(e),t.nextTick(()=>{const n=s.value.findIndex(c=>c.id===e);if(n<0||!f.value)return;const l=K.get(e)||V,o=(g.value[n]??0)-l,r=f.value.clientHeight,i=Math.max(0,o-Math.max(0,(r-l)/2));f.value.scrollTop=i,B.value=i,k(),t.nextTick(()=>{const c=P.get(e);if(!c||!f.value)return;const h=c.offsetLeft,d=c.offsetWidth,u=f.value.clientWidth,x=Math.max(0,h+Math.max(0,d/2)-Math.max(0,u/2));f.value.scrollLeft=x})}))}function Re(e){N.value=e??null,ie(N.value)}return G({getCurrentKey:()=>N.value,setCurrentKey:Re,scrollTo:ie,getCheckedKeys:()=>Array.from(v.value),setCheckedKeys:ne,setChecked:(e,n)=>J(e,n)}),t.watch(N,e=>{const n=ee(e,a.data||[]);n&&z("current-change",n)}),(e,n)=>(t.openBlock(),t.createElementBlock("div",{ref_key:"containerRef",ref:f,class:t.normalizeClass(["vtree",{"is-dragging":S.value}]),style:t.normalizeStyle({height:typeof p.height=="number"?p.height+"px":p.height||"100%","--vtree-bg":p.backgroundColor,"--vtree-text":p.textColor,"--vtree-hover":p.hoverColor}),onScroll:Ee},[ye.value?(t.openBlock(),t.createElementBlock("div",pe,[t.renderSlot(e.$slots,"empty",{},()=>[t.createElementVNode("div",me,t.toDisplayString(p.emptyText),1)],!0)])):(t.openBlock(),t.createElementBlock(t.Fragment,{key:0},[t.createElementVNode("div",{style:t.normalizeStyle({height:le.value+"px",position:"relative",minWidth:"100%",width:"max-content"})},[t.createElementVNode("div",{style:t.normalizeStyle({height:L.value+"px"})},null,4),(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(s.value.slice(I.value,b.value),l=>(t.openBlock(),t.createElementBlock("div",{key:l.id,class:"vtree-row-wrapper"},[t.createElementVNode("div",{class:t.normalizeClass(["vtree-row",{"is-target-inner":S.value&&H.value===l.id&&T.value==="inner","is-active":N.value===l.id}]),style:t.normalizeStyle({paddingLeft:l.level*16+"px","--active-color":p.highlightColor}),onMousedown:o=>Ae(l,o),onClick:o=>Ie(l,o),onContextmenu:t.withModifiers(o=>Le(l,o),["prevent"]),ref_for:!0,ref:o=>Te(l.id,o)},[t.createElementVNode("span",{class:t.normalizeClass(["vtree-caret-box",{"is-leaf":l.isLeaf}]),onClick:t.withModifiers(o=>!l.isLeaf&&we(l.id),["stop"])},[l.isLeaf?t.createCommentVNode("",!0):(t.openBlock(),t.createElementBlock("span",{key:0,class:t.normalizeClass(["vtree-caret",{expanded:te(l.id)}])},null,2))],10,fe),p.showCheckbox?(t.openBlock(),t.createElementBlock("input",{key:0,class:"vtree-checkbox",type:"checkbox",checked:Ce(l.id),indeterminate:be(l.id),disabled:a.disabledChecked?a.disabledChecked(l.node):!1,onClick:t.withModifiers(o=>Se(l,o),["stop"])},null,8,he)):t.createCommentVNode("",!0),t.renderSlot(e.$slots,"default",{node:l.node,data:l.node,level:l.level,expanded:te(l.id),isLeaf:l.isLeaf},()=>[t.createElementVNode("span",ve,t.toDisplayString(l.node[xe.value]),1)],!0)],46,ue),S.value&&H.value===l.id&&(T.value==="prev"||T.value==="next")?(t.openBlock(),t.createElementBlock("div",{key:0,class:t.normalizeClass(["vtree-drop-line",{"is-prev":T.value==="prev","is-next":T.value==="next"}])},null,2)):t.createCommentVNode("",!0)]))),128)),t.createElementVNode("div",{style:t.normalizeStyle({height:Q.value+"px"})},null,4)],4),S.value?(t.openBlock(),t.createElementBlock("div",{key:0,class:"vtree-ghost",style:t.normalizeStyle({top:Z.value+"px"})},null,4)):t.createCommentVNode("",!0)],64))],38))}}),[["__scopeId","data-v-d2996104"]]);A.AmazingTree=ge,Object.defineProperty(A,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(z,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],t):(z=typeof globalThis<"u"?globalThis:z||self,t(z.AmazingTree={},z.Vue))})(this,(function(z,t){"use strict";const fe=["onMousedown","onClick","onContextmenu"],he=["onClick"],ve=["checked","indeterminate","disabled","onClick"],me={class:"amazing-tree-label"},pe={key:1,class:"amazing-tree-empty"},ge={class:"amazing-tree-empty-inner"},V=28,te=((m,G)=>{const Y=m.__vccOpts||m;for(const[a,A]of G)Y[a]=A;return Y})(t.defineComponent({__name:"AmazingTree",props:{data:{},props:{default:()=>({value:"value",label:"label",children:"children"})},allowDrag:{},allowDrop:{},height:{default:void 0},highlightColor:{default:"#1e71ff"},backgroundColor:{default:"#1d1d24"},textColor:{default:"#c8d3de"},hoverColor:{default:"#5d90e5"},currentNodeKey:{},defaultExpandedKeys:{},defaultExpandAll:{type:Boolean,default:!1},draggable:{type:Boolean,default:!1},emptyText:{default:"暂无数据"},showCheckbox:{type:Boolean,default:!1},checkStrictly:{type:Boolean,default:!1},defaultCheckedKeys:{default:()=>[]},disabledChecked:{}},emits:["node-click","node-contextmenu","node-drop","current-change","check-change"],setup(m,{expose:G,emit:Y}){const a=m,A=Y,ke=t.computed(()=>a.props.value||"value"),xe=t.computed(()=>a.props.label||"label"),O=t.computed(()=>a.props.children||"children"),ye=t.computed(()=>Array.isArray(a.data)?a.data.length===0:!0),y=t.ref(new Set),v=t.ref(new Set),p=t.ref(new Set);function ne(e){return y.value.has(e)}function we(e){y.value.has(e)?y.value.delete(e):y.value.add(e),s.value=C(a.data||[]),t.nextTick(()=>{M(),k()})}function w(e){return e[ke.value]}function E(e){const n=e[O.value];return Array.isArray(n)?n:[]}function Ce(e){return v.value.has(e)}function be(e){return p.value.has(e)}function J(e,n){if(n?v.value.add(e):v.value.delete(e),p.value.delete(e),!a.checkStrictly){const l=ee(e,a.data||[]);if(l){const o=[l];for(;o.length;){const r=o.pop(),c=w(r);n?v.value.add(c):v.value.delete(c),p.value.delete(c);const h=E(r);for(const d of h)o.push(d)}const i=U(e,a.data||[])||[];for(const r of i){const c=w(r),h=E(r);let d=!0,u=!1;for(const x of h){const j=w(x),de=v.value.has(j),ue=p.value.has(j);(de||ue)&&(u=!0),(!de||ue)&&(d=!1)}h.length===0?(v.value.has(c),p.value.delete(c)):d?(v.value.add(c),p.value.delete(c)):u?(v.value.delete(c),p.value.add(c)):(v.value.delete(c),p.value.delete(c))}}}}function le(e){v.value=new Set,p.value=new Set;for(const n of e||[])J(n,!0)}function Se(e,n){const l=n.target;a.disabledChecked&&a.disabledChecked(e.node)||(A("check-change",e.node,!!l.checked),J(e.id,!!l.checked))}function C(e){const n=[];function l(o,i,r){for(let c=0;c<o.length;c++){const h=o[c],d=w(h),u=E(h),x=u.length===0;n.push({id:d,node:h,parent:i,level:r,index:c,isLeaf:x}),!x&&y.value.has(d)&&l(u,h,r+1)}}return l(e,null,0),n}const f=t.ref(null),B=t.ref(0),D=t.ref(0),s=t.ref([]),K=t.reactive(new Map),g=t.computed(()=>{let e=0;const n=[];for(const l of s.value){const o=K.get(l.id)||V;e+=o,n.push(e)}return n}),ae=t.computed(()=>{const e=g.value;return e.length?e[e.length-1]:0});function oe(e){let n=0,l=g.value.length-1,o=0;for(;n<=l;){const i=n+l>>1;g.value[i]!==void 0&&g.value[i]>=e?(o=i,l=i-1):n=i+1}return o}const I=t.ref(0),b=t.ref(0),L=t.ref(0),Q=t.ref(0);function k(){if(D.value=f.value?.clientHeight||0,g.value.length===0||s.value.length===0){I.value=0,b.value=0,L.value=0,Q.value=0;return}const e=oe(B.value);I.value=Math.max(0,e-3);const n=s.value[I.value],l=n?K.get(n.id)||V:0,i=(g.value[I.value]??0)-l;L.value=Math.max(0,i);let r=I.value;const c=B.value+D.value+3*V;for(;r<s.value.length&&(g.value[r]??0)<c;)r++;b.value=Math.min(s.value.length,r+1);const d=(g.value[b.value-1]??0)-L.value;if(d<D.value&&b.value<s.value.length){let u=b.value,x=d;for(;x<D.value&&u<s.value.length;)u++,x=(g.value[u-1]??0)-L.value;b.value=u}Q.value=Math.max(0,ae.value-L.value-((g.value[b.value-1]??0)-L.value))}t.watch([B,()=>a.data,y],()=>{s.value=C(a.data||[]),t.nextTick(M),k()}),t.onMounted(()=>{s.value=C(a.data||[]),t.nextTick(M),k(),a.defaultCheckedKeys&&a.defaultCheckedKeys.length&&le(a.defaultCheckedKeys),f.value&&(_=new ResizeObserver(()=>{D.value=f.value?.clientHeight||0,k()}),_.observe(f.value))});let _=null;t.onUnmounted(()=>{_&&(_.disconnect(),_=null)});const P=t.reactive(new Map);function Te(e,n){n?P.set(e,n):P.delete(e)}function M(){let e=!1;for(const n of s.value.slice(I.value,b.value)){const l=P.get(n.id);if(l){const o=l.offsetHeight;(!K.has(n.id)||K.get(n.id)!==o)&&(K.set(n.id,o),e=!0)}}e&&k()}function ze(){B.value=f.value?.scrollTop||0,k()}const S=t.ref(!1),X=t.ref(null),F=t.ref(null),T=t.ref(null),Z=t.ref(0),N=t.ref(null),H=t.ref(0);let R=null;function W(){R!=null&&(cancelAnimationFrame(R),R=null)}function ce(){if(!S.value||H.value===0){W();return}const e=f.value;if(!e){W();return}const n=e.scrollHeight-e.clientHeight,l=12;e.scrollTop=Math.max(0,Math.min(n,e.scrollTop+H.value*l)),B.value=e.scrollTop,k(),R=requestAnimationFrame(ce)}function Ee(){H.value!==0&&R==null&&(R=requestAnimationFrame(ce)),H.value===0&&W()}function q(e){if(e==null)return null;for(const n of s.value)if(n.id===e)return n;return null}function Be(e){const n=f.value.getBoundingClientRect(),l=e-n.top+B.value;return oe(l)}function Me(e,n){!a.draggable||n.button!==0||!(!a.allowDrag||a.allowDrag(e.node))||(S.value=!0,X.value=e.id,Z.value=n.clientY,n.preventDefault(),window.addEventListener("mousemove",ie),window.addEventListener("mouseup",re))}function ie(e){if(!S.value)return;Z.value=e.clientY;const n=Be(e.clientY),l=s.value[Math.min(Math.max(n,0),s.value.length-1)];if(F.value=l?.id??null,!l){T.value=null;return}const o=g.value[n]??0,i=K.get(l.id)??V,r=o-i,c=f.value.getBoundingClientRect(),d=(e.clientY-c.top+B.value-r)/i;let u="inner";d<.25?u="prev":d>.75&&(u="next");const x=q(X.value),j=a.allowDrop?!!(x&&a.allowDrop(x.node,l.node,u)):!0;T.value=j?u:null,H.value=e.clientY>c.bottom?1:e.clientY<c.top?-1:0,Ee()}function U(e,n,l=[]){for(const o of n){if(w(o)===e)return l;const i=E(o);if(i.length){const r=U(e,i,[...l,o]);if(r)return r}}return null}function ee(e,n){if(e==null)return null;for(const l of n){if(w(l)===e)return l;const o=E(l),i=ee(e,o);if(i)return i}return null}function $(e){const n=[];for(const l of e){n.push(w(l));const o=E(l);o.length&&n.push(...$(o))}return n}function Ae(e){const n=e.parent;if(n)E(n).splice(e.index,1);else{const l=a.data.findIndex(o=>w(o)===e.id);l>=0&&a.data.splice(l,1)}}function Ke(e,n,l){if(l==="inner"){Array.isArray(n.node[O.value])||(n.node[O.value]=[]),n.node[O.value].push(e),y.value.add(n.id);return}const o=n.parent;if(o){const i=E(o),r=n.index+(l==="next"?1:0);i.splice(r,0,e)}else{const i=n.index+(l==="next"?1:0);a.data.splice(i,0,e)}}function re(){if(window.removeEventListener("mousemove",ie),window.removeEventListener("mouseup",re),W(),!S.value)return;const e=q(X.value),n=q(F.value),l=T.value;if(S.value=!1,T.value=null,F.value=null,!e||!n||!l||a.allowDrop&&!a.allowDrop(e.node,n.node,l)||e.id===n.id)return;const o=l==="inner"?n.node:n.parent||null;if(o){const h=U(w(o),a.data||[])||[];for(const d of h)if(w(d)===e.id)return}const i=e.node;Ae(e);const r=C(a.data||[]);s.value=r;const c=q(n.id)||n;Ke(i,c,l),s.value=C(a.data||[]),t.nextTick(()=>{M(),k()}),A("node-drop",i,c.node,l)}function Ie(e,n){N.value=e.id,A("node-click",e.node,n)}function Le(e,n){A("node-contextmenu",e.node,n)}t.watchEffect(()=>{t.nextTick(M)}),t.watch(()=>a.currentNodeKey,e=>{N.value=e??null},{immediate:!0}),t.watch(()=>a.defaultExpandedKeys,e=>{y.value=new Set(e||[]),s.value=C(a.data||[]),t.nextTick(()=>{M(),k()})},{immediate:!0}),t.watch(()=>a.defaultExpandAll,e=>{e&&(y.value=new Set($(a.data||[])),s.value=C(a.data||[]),t.nextTick(()=>{M(),k()}))},{immediate:!0}),t.watch(()=>a.data,()=>{a.defaultExpandAll&&(y.value=new Set($(a.data||[])),s.value=C(a.data||[]),t.nextTick(()=>{M(),k()}));const e=new Set($(a.data||[]));v.value=new Set([...v.value].filter(n=>e.has(n))),p.value=new Set([...p.value].filter(n=>e.has(n)))});function Ne(e){const n=U(e,a.data||[])||[];for(const l of n)y.value.add(w(l));s.value=C(a.data||[])}function se(e){e!=null&&(Ne(e),t.nextTick(()=>{const n=s.value.findIndex(c=>c.id===e);if(n<0||!f.value)return;const l=K.get(e)||V,o=(g.value[n]??0)-l,i=f.value.clientHeight,r=Math.max(0,o-Math.max(0,(i-l)/2));f.value.scrollTop=r,B.value=r,k(),t.nextTick(()=>{const c=P.get(e);if(!c||!f.value)return;const h=c.offsetLeft,d=c.offsetWidth,u=f.value.clientWidth,x=Math.max(0,h+Math.max(0,d/2)-Math.max(0,u/2));f.value.scrollLeft=x})}))}function Re(e){N.value=e??null,se(N.value)}return G({getCurrentKey:()=>N.value,setCurrentKey:Re,scrollTo:se,getCheckedKeys:()=>Array.from(v.value),setCheckedKeys:le,setChecked:(e,n)=>J(e,n)}),t.watch(N,e=>{const n=ee(e,a.data||[]);n&&A("current-change",n)}),(e,n)=>(t.openBlock(),t.createElementBlock("div",{ref_key:"containerRef",ref:f,class:t.normalizeClass(["amazing-tree",{"is-dragging":S.value}]),style:t.normalizeStyle({height:typeof m.height=="number"?m.height+"px":m.height||"100%","--vtree-bg":m.backgroundColor,"--vtree-text":m.textColor,"--vtree-hover":m.hoverColor}),onScroll:ze},[ye.value?(t.openBlock(),t.createElementBlock("div",pe,[t.renderSlot(e.$slots,"empty",{},()=>[t.createElementVNode("div",ge,t.toDisplayString(m.emptyText),1)],!0)])):(t.openBlock(),t.createElementBlock(t.Fragment,{key:0},[t.createElementVNode("div",{style:t.normalizeStyle({height:ae.value+"px",position:"relative",minWidth:"100%",width:"max-content"})},[t.createElementVNode("div",{style:t.normalizeStyle({height:L.value+"px"})},null,4),(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(s.value.slice(I.value,b.value),l=>(t.openBlock(),t.createElementBlock("div",{key:l.id,class:"amazing-tree-row-wrapper"},[t.createElementVNode("div",{class:t.normalizeClass(["amazing-tree-row",{"is-target-inner":S.value&&F.value===l.id&&T.value==="inner","is-active":N.value===l.id}]),style:t.normalizeStyle({paddingLeft:l.level*16+"px","--active-color":m.highlightColor}),onMousedown:o=>Me(l,o),onClick:o=>Ie(l,o),onContextmenu:t.withModifiers(o=>Le(l,o),["prevent"]),ref_for:!0,ref:o=>Te(l.id,o)},[t.createElementVNode("span",{class:t.normalizeClass(["amazing-tree-caret-box",{"is-leaf":l.isLeaf}]),onClick:t.withModifiers(o=>!l.isLeaf&&we(l.id),["stop"])},[l.isLeaf?t.createCommentVNode("",!0):(t.openBlock(),t.createElementBlock("span",{key:0,class:t.normalizeClass(["amazing-tree-caret",{expanded:ne(l.id)}])},null,2))],10,he),m.showCheckbox?(t.openBlock(),t.createElementBlock("input",{key:0,class:"amazing-tree-checkbox",type:"checkbox",checked:Ce(l.id),indeterminate:be(l.id),disabled:a.disabledChecked?a.disabledChecked(l.node):!1,onClick:t.withModifiers(o=>Se(l,o),["stop"])},null,8,ve)):t.createCommentVNode("",!0),t.renderSlot(e.$slots,"default",{node:l.node,data:l.node,level:l.level,expanded:ne(l.id),isLeaf:l.isLeaf},()=>[t.createElementVNode("span",me,t.toDisplayString(l.node[xe.value]),1)],!0)],46,fe),S.value&&F.value===l.id&&(T.value==="prev"||T.value==="next")?(t.openBlock(),t.createElementBlock("div",{key:0,class:t.normalizeClass(["amazing-tree-drop-line",{"is-prev":T.value==="prev","is-next":T.value==="next"}])},null,2)):t.createCommentVNode("",!0)]))),128)),t.createElementVNode("div",{style:t.normalizeStyle({height:Q.value+"px"})},null,4)],4),S.value?(t.openBlock(),t.createElementBlock("div",{key:0,class:"amazing-tree-ghost",style:t.normalizeStyle({top:Z.value+"px"})},null,4)):t.createCommentVNode("",!0)],64))],38))}}),[["__scopeId","data-v-2da931e7"]]);z.AmazingTree=te,z.default=te,Object.defineProperties(z,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "amazing-tree",
3
- "version": "1.1.0",
3
+ "version": "1.2.2",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "engines": {
@@ -49,5 +49,6 @@
49
49
  "require": "./dist/amazing-tree.cjs.js"
50
50
  }
51
51
  },
52
- "author": "maxkang"
52
+ "author": "maxkang",
53
+ "style": "./dist/amazing-tree.css"
53
54
  }