amazing-tree 1.2.2 → 1.2.4
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.
- package/README.md +3 -0
- package/dist/amazing-tree.cjs.js +1 -1
- package/dist/amazing-tree.css +1 -1
- package/dist/amazing-tree.es.js +24 -23
- package/dist/amazing-tree.umd.js +1 -1
- package/package.json +7 -2
package/README.md
CHANGED
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
<script setup lang="ts">
|
|
27
27
|
import { ref } from 'vue'
|
|
28
28
|
import { AmazingTree } from 'amazing-tree'
|
|
29
|
+
import 'amazing-tree/style.css'
|
|
29
30
|
|
|
30
31
|
type NodeItem = { uuid: string; name: string; children?: NodeItem[]; [k: string]: unknown }
|
|
31
32
|
const data = ref<NodeItem[]>([])
|
|
@@ -47,6 +48,8 @@ function onDrop(drag: NodeItem, target: NodeItem, type: 'prev' | 'next' | 'inner
|
|
|
47
48
|
</template>
|
|
48
49
|
```
|
|
49
50
|
|
|
51
|
+
> 使用时请显式导入样式:`import 'amazing-tree/style.css'`
|
|
52
|
+
|
|
50
53
|
**Props**
|
|
51
54
|
|
|
52
55
|
- `data: T[]` 树数据源
|
package/dist/amazing-tree.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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
|
+
"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)))},{deep:!0});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-6ef943bb"]]);exports.AmazingTree=se;exports.default=se;
|
package/dist/amazing-tree.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.amazing-tree
|
|
1
|
+
.amazing-tree[data-v-6ef943bb]{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-6ef943bb],.amazing-tree.is-dragging[data-v-6ef943bb] *{-webkit-user-select:none;user-select:none}.amazing-tree[data-v-6ef943bb] *{cursor:pointer}.amazing-tree input[type=checkbox][data-v-6ef943bb]:disabled{cursor:not-allowed}.amazing-tree .amazing-tree-checkbox[data-v-6ef943bb]{-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-6ef943bb]:not(:disabled):hover{border-color:var(--vtree-checkbox-hover-border)}.amazing-tree .amazing-tree-checkbox[data-v-6ef943bb]:focus-visible{box-shadow:0 0 0 2px #409eff33}.amazing-tree .amazing-tree-checkbox[data-v-6ef943bb]:checked{background:var(--vtree-primary);border-color:var(--vtree-primary)}.amazing-tree .amazing-tree-checkbox[data-v-6ef943bb]: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-6ef943bb]:indeterminate{background:var(--vtree-primary);border-color:var(--vtree-primary)}.amazing-tree .amazing-tree-checkbox[data-v-6ef943bb]: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-6ef943bb]:disabled{background:var(--vtree-checkbox-disabled-bg);border-color:var(--vtree-checkbox-disabled-border)}.amazing-tree .amazing-tree-checkbox[data-v-6ef943bb]:disabled:checked:after{border-color:var(--vtree-checkbox-check-disabled)}.amazing-tree .amazing-tree-checkbox[data-v-6ef943bb]:disabled:indeterminate:after{background:var(--vtree-checkbox-check-disabled)}.amazing-tree .amazing-tree-row-wrapper[data-v-6ef943bb]{position:relative}.amazing-tree .amazing-tree-row-wrapper .amazing-tree-drop-line[data-v-6ef943bb]{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-6ef943bb]{top:0}.amazing-tree .amazing-tree-row-wrapper .amazing-tree-drop-line.is-next[data-v-6ef943bb]{bottom:0}.amazing-tree .amazing-tree-row[data-v-6ef943bb]{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-6ef943bb]:hover{background:var(--vtree-hover)}.amazing-tree .amazing-tree-row.is-active[data-v-6ef943bb],.amazing-tree .amazing-tree-row.is-active[data-v-6ef943bb]:hover{background:var(--active-color)}.amazing-tree .amazing-tree-row.is-target-inner[data-v-6ef943bb]{outline:2px dashed #409eff}.amazing-tree .amazing-tree-row .amazing-tree-caret-box[data-v-6ef943bb]{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-6ef943bb]{pointer-events:none}.amazing-tree .amazing-tree-row .amazing-tree-caret[data-v-6ef943bb]{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-6ef943bb]{transform:rotate(0)}.amazing-tree .amazing-tree-row .amazing-tree-label[data-v-6ef943bb]{color:inherit}.amazing-tree .amazing-tree-ghost[data-v-6ef943bb]{position:fixed;left:16px;width:120px;height:24px;background:#409eff33;border:1px solid #409eff;pointer-events:none}.amazing-tree .amazing-tree-empty[data-v-6ef943bb]{width:100%;height:100%;display:flex;align-items:center;justify-content:center}.amazing-tree .amazing-tree-empty[data-v-6ef943bb]>*{width:100%;height:100%;display:flex;align-items:center;justify-content:center}.amazing-tree .amazing-tree-empty .amazing-tree-empty-inner[data-v-6ef943bb]{color:var(--vtree-text)}[data-v-6ef943bb] .amazing-tree::-webkit-scrollbar{width:8px;height:8px}[data-v-6ef943bb] .amazing-tree::-webkit-scrollbar-track{background:transparent}[data-v-6ef943bb] .amazing-tree::-webkit-scrollbar-thumb{background-color:#9093994d;border-radius:4px}[data-v-6ef943bb] .amazing-tree::-webkit-scrollbar-thumb:hover{background-color:#90939980}
|
package/dist/amazing-tree.es.js
CHANGED
|
@@ -25,8 +25,8 @@ 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(
|
|
29
|
-
const l =
|
|
28
|
+
setup(p, { expose: le, emit: j }) {
|
|
29
|
+
const l = p, 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()), g = s(/* @__PURE__ */ new Set());
|
|
30
30
|
function re(e) {
|
|
31
31
|
return w.value.has(e);
|
|
32
32
|
}
|
|
@@ -46,16 +46,16 @@ const qe = ["onMousedown", "onClick", "onContextmenu"], je = ["onClick"], Ge = [
|
|
|
46
46
|
return h.value.has(e);
|
|
47
47
|
}
|
|
48
48
|
function Ke(e) {
|
|
49
|
-
return
|
|
49
|
+
return g.value.has(e);
|
|
50
50
|
}
|
|
51
51
|
function ae(e, t) {
|
|
52
|
-
if (t ? h.value.add(e) : h.value.delete(e),
|
|
52
|
+
if (t ? h.value.add(e) : h.value.delete(e), g.value.delete(e), !l.checkStrictly) {
|
|
53
53
|
const n = ie(e, l.data || []);
|
|
54
54
|
if (n) {
|
|
55
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),
|
|
58
|
+
t ? h.value.add(o) : h.value.delete(o), g.value.delete(o);
|
|
59
59
|
const f = K(c);
|
|
60
60
|
for (const r of f) a.push(r);
|
|
61
61
|
}
|
|
@@ -64,16 +64,16 @@ const qe = ["onMousedown", "onClick", "onContextmenu"], je = ["onClick"], Ge = [
|
|
|
64
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 =
|
|
67
|
+
const te = k(y), xe = h.value.has(te), ye = g.value.has(te);
|
|
68
68
|
(xe || ye) && (d = !0), (!xe || ye) && (r = !1);
|
|
69
69
|
}
|
|
70
|
-
f.length === 0 ? (h.value.has(o),
|
|
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));
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
function de(e) {
|
|
76
|
-
h.value = /* @__PURE__ */ new Set(),
|
|
76
|
+
h.value = /* @__PURE__ */ new Set(), g.value = /* @__PURE__ */ new Set();
|
|
77
77
|
for (const t of e || []) ae(t, !0);
|
|
78
78
|
}
|
|
79
79
|
function Ee(e, t) {
|
|
@@ -193,9 +193,9 @@ const qe = ["onMousedown", "onClick", "onContextmenu"], je = ["onClick"], Ge = [
|
|
|
193
193
|
return fe(n);
|
|
194
194
|
}
|
|
195
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",
|
|
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", pe), window.addEventListener("mouseup", ge));
|
|
197
197
|
}
|
|
198
|
-
function
|
|
198
|
+
function pe(e) {
|
|
199
199
|
if (!M.value) return;
|
|
200
200
|
ce.value = e.clientY;
|
|
201
201
|
const t = Be(e.clientY), n = i.value[Math.min(Math.max(t, 0), i.value.length - 1)];
|
|
@@ -261,8 +261,8 @@ const qe = ["onMousedown", "onClick", "onContextmenu"], je = ["onClick"], Ge = [
|
|
|
261
261
|
l.data.splice(u, 0, e);
|
|
262
262
|
}
|
|
263
263
|
}
|
|
264
|
-
function
|
|
265
|
-
if (window.removeEventListener("mousemove",
|
|
264
|
+
function ge() {
|
|
265
|
+
if (window.removeEventListener("mousemove", pe), window.removeEventListener("mouseup", ge), Q(), !M.value) return;
|
|
266
266
|
const e = X(ue.value), t = X(V.value), n = A.value;
|
|
267
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
268
|
const a = n === "inner" ? t.node : t.parent || null;
|
|
@@ -312,12 +312,13 @@ const qe = ["onMousedown", "onClick", "onContextmenu"], je = ["onClick"], Ge = [
|
|
|
312
312
|
), _(
|
|
313
313
|
() => l.data,
|
|
314
314
|
() => {
|
|
315
|
-
l.defaultExpandAll && (w.value = new Set(ee(l.data || [])), i.value = b(l.data || []), C(() => {
|
|
315
|
+
l.defaultExpandAll && (w.value = new Set(ee(l.data || []))), i.value = b(l.data || []), C(() => {
|
|
316
316
|
I(), x();
|
|
317
|
-
})
|
|
317
|
+
});
|
|
318
318
|
const e = new Set(ee(l.data || []));
|
|
319
|
-
h.value = new Set([...h.value].filter((t) => e.has(t))),
|
|
320
|
-
}
|
|
319
|
+
h.value = new Set([...h.value].filter((t) => e.has(t))), g.value = new Set([...g.value].filter((t) => e.has(t)));
|
|
320
|
+
},
|
|
321
|
+
{ deep: !0 }
|
|
321
322
|
);
|
|
322
323
|
function _e(e) {
|
|
323
324
|
const t = Z(e, l.data || []) || [];
|
|
@@ -354,12 +355,12 @@ const qe = ["onMousedown", "onClick", "onContextmenu"], je = ["onClick"], Ge = [
|
|
|
354
355
|
ref_key: "containerRef",
|
|
355
356
|
ref: v,
|
|
356
357
|
class: $(["amazing-tree", { "is-dragging": M.value }]),
|
|
357
|
-
style: W({ height: typeof
|
|
358
|
+
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
359
|
onScroll: Le
|
|
359
360
|
}, [
|
|
360
361
|
Ae.value ? (T(), z("div", Qe, [
|
|
361
362
|
Ce(e.$slots, "empty", {}, () => [
|
|
362
|
-
Y("div", Xe, be(
|
|
363
|
+
Y("div", Xe, be(p.emptyText), 1)
|
|
363
364
|
], !0)
|
|
364
365
|
])) : (T(), z(ke, { key: 0 }, [
|
|
365
366
|
Y("div", {
|
|
@@ -374,7 +375,7 @@ const qe = ["onMousedown", "onClick", "onContextmenu"], je = ["onClick"], Ge = [
|
|
|
374
375
|
}, [
|
|
375
376
|
Y("div", {
|
|
376
377
|
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":
|
|
378
|
+
style: W({ paddingLeft: n.level * 16 + "px", "--active-color": p.highlightColor }),
|
|
378
379
|
onMousedown: (a) => De(n, a),
|
|
379
380
|
onClick: (a) => Fe(n, a),
|
|
380
381
|
onContextmenu: se((a) => Ne(n, a), ["prevent"]),
|
|
@@ -390,7 +391,7 @@ const qe = ["onMousedown", "onClick", "onContextmenu"], je = ["onClick"], Ge = [
|
|
|
390
391
|
class: $(["amazing-tree-caret", { expanded: re(n.id) }])
|
|
391
392
|
}, null, 2))
|
|
392
393
|
], 10, je),
|
|
393
|
-
|
|
394
|
+
p.showCheckbox ? (T(), z("input", {
|
|
394
395
|
key: 0,
|
|
395
396
|
class: "amazing-tree-checkbox",
|
|
396
397
|
type: "checkbox",
|
|
@@ -426,12 +427,12 @@ const qe = ["onMousedown", "onClick", "onContextmenu"], je = ["onClick"], Ge = [
|
|
|
426
427
|
], 64))
|
|
427
428
|
], 38));
|
|
428
429
|
}
|
|
429
|
-
}), et = (
|
|
430
|
-
const j =
|
|
430
|
+
}), et = (p, le) => {
|
|
431
|
+
const j = p.__vccOpts || p;
|
|
431
432
|
for (const [l, L] of le)
|
|
432
433
|
j[l] = L;
|
|
433
434
|
return j;
|
|
434
|
-
}, nt = /* @__PURE__ */ et(Ze, [["__scopeId", "data-v-
|
|
435
|
+
}, nt = /* @__PURE__ */ et(Ze, [["__scopeId", "data-v-6ef943bb"]]);
|
|
435
436
|
export {
|
|
436
437
|
nt as AmazingTree,
|
|
437
438
|
nt as default
|
package/dist/amazing-tree.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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"}})}));
|
|
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)))},{deep:!0});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-6ef943bb"]]);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.2.
|
|
3
|
+
"version": "1.2.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -47,8 +47,13 @@
|
|
|
47
47
|
".": {
|
|
48
48
|
"import": "./dist/amazing-tree.es.js",
|
|
49
49
|
"require": "./dist/amazing-tree.cjs.js"
|
|
50
|
-
}
|
|
50
|
+
},
|
|
51
|
+
"./style.css": "./dist/amazing-tree.css",
|
|
52
|
+
"./dist/*": "./dist/*"
|
|
51
53
|
},
|
|
54
|
+
"sideEffects": [
|
|
55
|
+
"dist/*.css"
|
|
56
|
+
],
|
|
52
57
|
"author": "maxkang",
|
|
53
58
|
"style": "./dist/amazing-tree.css"
|
|
54
59
|
}
|