amazing-tree 1.3.0 → 1.3.1

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