UNPKG

@idcpj/vue-tree

Version:

A vue tree component using virtual list.

2 lines (1 loc) 45.6 kB
(function(B,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("vue-demi"),require("vue")):typeof define=="function"&&define.amd?define(["exports","vue-demi","vue"],o):(B=typeof globalThis<"u"?globalThis:B||self,o(B.Vtree={},B.VueDemi,B.Vue))})(this,function(B,o,l){"use strict";var wt=Object.defineProperty;var _t=(B,o,l)=>o in B?wt(B,o,{enumerable:!0,configurable:!0,writable:!0,value:l}):B[o]=l;var A=(B,o,l)=>(_t(B,typeof o!="symbol"?o+"":o,l),l);const nt=["_level","_filterVisible","_parent","_loading","_loaded","_remote","_keyField","children","setChildren"];class X{constructor(t,n=null,a="id",s=!1){A(this,"_level",0);A(this,"checked",!1);A(this,"selected",!1);A(this,"indeterminate",!1);A(this,"disabled",!1);A(this,"expand",!1);A(this,"visible",!0);A(this,"_filterVisible",!0);A(this,"_parent",null);A(this,"children",[]);A(this,"isLeaf",!1);A(this,"type","");A(this,"_loading",!1);A(this,"_loaded",!1);this._keyField=a,this._remote=s;for(let r in t)nt.indexOf(r)===-1&&(this[r]=t[r]);this[a]==null&&(this[a]=Math.random().toString(36).substring(2)),this._parent=n,this._parent&&(this._level=this._parent._level+1),this.visible=this._parent===null||this._parent.expand&&this._parent.visible,Array.isArray(t.children)&&this.setChildren(t.children),this.children.length&&(this._loaded=!0),this._remote||(this.isLeaf=!this.children.length)}setChildren(t){this.children=t.map(n=>new X(Object.assign({},n),this,this._keyField,this._remote))}}var se=(e=>(e.none="none",e.parents="parents",e.children="children",e))(se||{});const at=["setData","setChecked","setCheckedKeys","checkAll","clearChecked","setSelected","clearSelected","setExpand","setExpandKeys","setExpandAll","getCheckedNodes","getCheckedKeys","getIndeterminateNodes","getSelectedNode","getSelectedKey","getExpandNodes","getExpandKeys","getCurrentVisibleNodes","getNode","getTreeData","getFlatData","getNodesCount","insertBefore","insertAfter","append","prepend","remove","filter","showCheckedNodes","loadRootNodes","scrollTo"];var Ne=(e=>(e["bottom-start"]="bottom-start",e["bottom-end"]="bottom-end",e.bottom="bottom",e["top-start"]="top-start",e["top-end"]="top-end",e.top="top",e))(Ne||{}),re=(e=>(e.top="top",e.center="center",e.bottom="bottom",e))(re||{}),U=(e=>(e.before="before",e.body="body",e.after="after",e))(U||{});const he=["expand","check","click","select","node-dblclick","node-right-click","node-dragstart","node-dragenter","node-dragover","node-dragleave","node-drop"];class we{constructor(t){A(this,"data",[]);A(this,"flatData",[]);A(this,"mapData",Object.create(null));A(this,"unloadCheckedKeys",[]);A(this,"unloadSelectedKey",null);A(this,"currentSelectedKey",null);A(this,"listenersMap",{});this.options=t}setData(t,n=null,a=null){this.data=t.map(s=>new X(s,null,this.options.keyField,!!this.options.load));for(let s in this.mapData)delete this.mapData[s];this.currentSelectedKey=null,this.flatData=this.flattenData(this.data),this.setUnloadCheckedKeys(a||[]),n&&(this.currentSelectedKey=null,this.setUnloadSelectedKey(n)),this.emit("visible-data-change"),this.emit("set-data")}setChecked(t,n,a=!0,s=!0,r=!1){const i=this.mapData[t];if(!i)return this.setUnloadChecked(t,n,a,s);i.disabled||i.checked&&n||!i.checked&&!i.indeterminate&&!n||(this.options.cascade?(this.checkNodeDownward(i,n,r),this.checkNodeUpward(i)):i.checked=n,a&&(i.checked?this.emit("check",i):this.emit("uncheck",i)),this.triggerCheckedChange(a,s))}setUnloadChecked(t,n,a=!0,s=!0){const r=this.findIndex(t,this.unloadCheckedKeys);n?r===-1&&this.unloadCheckedKeys.push(t):r!==-1&&this.unloadCheckedKeys.splice(r,1),this.triggerCheckedChange(a,s)}setCheckedKeys(t,n,a=!0,s=!0){t.forEach(r=>{this.setChecked(r,n,!1,!1)}),this.triggerCheckedChange(a,s)}checkAll(t=!0,n=!0){if(this.options.cascade){const a=s=>{s.forEach(r=>{r.disabled?a(r.children):this.setChecked(r[this.options.keyField],!0,!1,!1)})};a(this.data)}else{const a=this.flatData.length;for(let s=0;s<a;s++){const r=this.flatData[s];this.setChecked(r[this.options.keyField],!0,!1,!1)}}this.triggerCheckedChange(t,n)}clearChecked(t=!0,n=!0){this.getCheckedNodes().forEach(s=>{this.setChecked(s[this.options.keyField],!1,!1,!1)}),this.unloadCheckedKeys=[],this.triggerCheckedChange(t,n)}triggerCheckedChange(t=!0,n=!0){t&&this.emit("checked-change",this.getCheckedNodes(),this.getCheckedKeys()),n&&this.emit("render-data-change")}setSelected(t,n,a=!0,s=!0){const r=this.mapData[t];if(!r)return this.setUnloadSelected(t,n,a,s);r.disabled||r.selected!==n&&(t===this.currentSelectedKey?n||(r.selected=n,this.currentSelectedKey=null):n&&(this.currentSelectedKey===null?(r.selected=n,this.currentSelectedKey=r[this.options.keyField]):(this.mapData[this.currentSelectedKey]&&(this.mapData[this.currentSelectedKey].selected=!1),r.selected=n,this.currentSelectedKey=r[this.options.keyField])),a&&(r.selected?this.emit("select",r):this.emit("unselect",r),this.emit("selected-change",this.getSelectedNode(),this.getSelectedKey())),s&&this.emit("render-data-change"))}setUnloadSelected(t,n,a=!0,s=!0){n?(this.currentSelectedKey&&this.setSelected(this.currentSelectedKey,!1,!1,!1),this.unloadSelectedKey=t):this.unloadSelectedKey===t&&(this.unloadSelectedKey=null),a&&this.emit("selected-change",this.getSelectedNode(),this.getSelectedKey()),s&&this.emit("render-data-change")}clearSelected(t=!0,n=!0){this.currentSelectedKey&&this.mapData[this.currentSelectedKey]?this.setSelected(this.currentSelectedKey,!1,t,n):this.unloadSelectedKey!==null&&(this.unloadSelectedKey=null,t&&this.emit("selected-change",this.getSelectedNode(),this.getSelectedKey()),n&&this.emit("render-data-change"))}setExpand(t,n,a=!1,s=!0,r=!0){const i=this.mapData[t];if(!(!i||!a&&i.isLeaf)&&i.expand!==n){if(!i.isLeaf){if(typeof this.options.load=="function"){if(!i._loaded&&!i._loading&&n){i._loading=!0,r&&this.emit("visible-data-change"),new Promise((p,g)=>{const w=this.options.load;w(i,p,g)}).then(p=>{if(Array.isArray(p)){const g=this.findIndex(i);if(g===-1)return;i._loaded=!0,i.expand=n,i.setChildren(p);const w=this.getCheckedKeys(),b=this.flattenData(i.children,this.getSelectedKey===null);this.flatData.splice(g+1,0,...b),this.setUnloadCheckedKeys(w),this.unloadSelectedKey!==null&&this.setUnloadSelectedKey(this.unloadSelectedKey),this.emit("set-data")}}).catch(p=>{}).then(()=>{i._loading=!1,s&&this.emit("expand",i),r&&this.emit("visible-data-change")});return}else if(i._loading)return}i.expand=n;const c=[...i.children];for(;c.length;)c[0].expand&&c[0].children.length&&c.push(...c[0].children),c[0]._filterVisible===!1?c[0].visible=!1:c[0].visible=c[0]._parent===null||c[0]._parent.expand&&c[0]._parent.visible,c.shift();s&&this.emit("expand",i),r&&this.emit("visible-data-change")}a&&i._parent&&n&&this.setExpand(i._parent[this.options.keyField],n,a,!1,r)}}setExpandKeys(t,n,a=!0){t.forEach(s=>{this.setExpand(s,n,!1,!1,!1)}),a&&this.emit("visible-data-change")}setExpandAll(t,n=!0){this.flatData.forEach(a=>{(!this.options.load||a._loaded)&&this.setExpand(a[this.options.keyField],t,!1,!1,!1)}),n&&this.emit("visible-data-change")}getCheckedNodes(t=this.options.ignoreMode){if(t===se.children){const n=[],a=s=>{s.forEach(r=>{r.checked?n.push(r):!r.isLeaf&&r.indeterminate&&a(r.children)})};return a(this.data),n}else return this.flatData.filter(n=>t===se.parents?n.checked&&n.isLeaf:n.checked)}getCheckedKeys(t=this.options.ignoreMode){return this.getCheckedNodes(t).map(n=>n[this.options.keyField]).concat(this.unloadCheckedKeys)}getIndeterminateNodes(){return this.flatData.filter(t=>t.indeterminate)}getSelectedNode(){return this.currentSelectedKey===null?null:this.mapData[this.currentSelectedKey]||null}getSelectedKey(){return this.currentSelectedKey||this.unloadSelectedKey||null}getUnloadCheckedKeys(){return this.unloadCheckedKeys}getExpandNodes(){return this.flatData.filter(t=>!t.isLeaf&&t.expand)}getExpandKeys(){return this.getExpandNodes().map(t=>t[this.options.keyField])}getNode(t){return this.mapData[t]||null}insertBefore(t,n){const a=this.getInsertedNode(t,n);if(!a)return null;this.remove(a[this.options.keyField],!1);const r=this.mapData[n]._parent,i=this.findIndex(n,r&&r.children),c=this.findIndex(n),p=r&&-1||this.findIndex(n,this.data);return this.insertIntoStore(a,r,i,c,p),this.emit("visible-data-change"),a}insertAfter(t,n){const a=this.getInsertedNode(t,n);if(!a)return null;this.remove(a[this.options.keyField],!1);const s=this.mapData[n],r=s._parent,i=this.findIndex(n,r&&r.children)+1,c=this.flatData.length,p=this.findIndex(n);let g=p+1;for(let b=p+1;b<=c;b++){if(b===c){g=b;break}if(this.flatData[b]._level<=s._level){g=b;break}}const w=r&&-1||this.findIndex(n,this.data)+1;return this.insertIntoStore(a,r,i,g,w),this.emit("visible-data-change"),a}append(t,n){const a=this.mapData[n];if(!a.isLeaf){const i=a.children.length;return this.insertAfter(t,a.children[i-1][this.options.keyField])}const s=this.getInsertedNode(t,n,!0);if(!s)return null;this.remove(s[this.options.keyField],!1);const r=this.findIndex(n)+1;return this.insertIntoStore(s,a,0,r),this.emit("visible-data-change"),s}prepend(t,n){const a=this.mapData[n];if(!a.isLeaf)return this.insertBefore(t,a.children[0][this.options.keyField]);const s=this.getInsertedNode(t,n,!0);if(!s)return null;this.remove(s[this.options.keyField],!1);const r=this.findIndex(n)+1;return this.insertIntoStore(s,a,0,r),this.emit("visible-data-change"),s}remove(t,n=!0){const a=this.mapData[t];if(!a)return null;const s=this.findIndex(a);if(s===-1)return null;let r=1;const i=this.flatData.length;for(let p=s+1;p<i&&this.flatData[p]._level>a._level;p++)r++;this.flatData.splice(s,r);const c=p=>{const g=this.mapData[p];delete this.mapData[p],g.children.forEach(w=>c(w[this.options.keyField]))};if(c(t),!a._parent){const p=this.findIndex(a,this.data);p>-1&&this.data.splice(p,1)}if(a._parent){const p=this.findIndex(a,a._parent.children);p!==-1&&a._parent.children.splice(p,1),a._parent.isLeaf=!a._parent.children.length,a._parent.isLeaf&&(a._parent.expand=!1,a._parent.indeterminate=!1),this.updateMovingNodeStatus(a)}return n&&this.emit("visible-data-change"),a}getInsertedNode(t,n,a=!1){const s=this.mapData[n];if(!s)return null;const r=a?s:s._parent;if(t instanceof X)return t[this.options.keyField]===n?null:t;if(typeof t=="object"){if(t[this.options.keyField]===n)return null;const i=this.mapData[t[this.options.keyField]];return i||new X(t,r,this.options.keyField,!!this.options.load)}else return!this.mapData[t]||t===n?null:this.mapData[t]}insertIntoStore(t,n,a,s,r){if(s===-1)return;a!==-1&&n&&n.children.splice(a,0,t),t._parent=n,n?(n.isLeaf=!1,this.setExpand(n[this.options.keyField],!0,!1,!1,!1)):typeof r=="number"&&r>-1&&this.data.splice(r,0,t);const i=this.flattenData([t]);t._level=n?n._level+1:0,i.forEach(c=>c._level=c._parent?c._parent._level+1:0),this.flatData.splice(s,0,...i),this.updateMovingNodeStatus(t)}updateMovingNodeStatus(t){this.checkNodeUpward(t),this.triggerCheckedChange(),t.selected&&this.setSelected(t[this.options.keyField],!0)}filter(t,n){const a=[];this.flatData.forEach(s=>{s._filterVisible=s._parent&&s._parent._filterVisible||n(t,s),s.visible=s._filterVisible,s._filterVisible&&a.push(s)}),a.forEach(s=>{const r=[];let i=s._parent;for(;i;)r.unshift(i),i=i._parent;r.forEach(c=>{c._filterVisible=!0,c.visible=(c._parent===null||c._parent.expand&&c._parent.visible)&&c._filterVisible,this.options.expandOnFilter&&this.setExpand(c[this.options.keyField],!0,!1,!1,!1)}),s.visible=s._parent===null||s._parent.expand&&s._parent.visible}),this.emit("visible-data-change")}setUnloadCheckedKeys(t){this.unloadCheckedKeys=t;const n=t.concat(),a=this.unloadCheckedKeys.length;for(let r=a-1;r>=0;r--){const i=this.unloadCheckedKeys[r];this.mapData[i]&&(this.setChecked(i,!0,!1,!1),this.unloadCheckedKeys.splice(r,1))}const s=this.getCheckedKeys();s.length===n.length&&s.every(r=>n.some(i=>i===r))||this.emit("checked-change",this.getCheckedNodes(),s)}setUnloadSelectedKey(t){const n=this.getSelectedKey();this.mapData[t]?(this.setSelected(t,!0,!1),this.unloadSelectedKey=null):(this.currentSelectedKey&&this.setSelected(this.currentSelectedKey,!1,!1),this.unloadSelectedKey=t);const a=this.getSelectedKey();a!==n&&this.emit("selected-change",this.getSelectedNode(),a)}flattenData(t,n=!0,a=[]){const s=t.length;for(let r=0;r<s;r++){const i=t[r],c=i[this.options.keyField];if(a.push(i),this.mapData[c])throw new Error("[CTree] Duplicate tree node key.");this.mapData[c]=i,i.checked&&this.options.cascade&&(this.checkNodeDownward(i,!0),this.checkNodeUpward(i)),i.selected&&n&&(this.clearSelected(!1,!1),this.currentSelectedKey=i[this.options.keyField],this.emit("selected-change",i,this.currentSelectedKey)),(this.options.defaultExpandAll||i.expand)&&!this.options.load&&!i.isLeaf&&(i.expand=!1,this.setExpand(i[this.options.keyField],!0,!1,!1,!1)),i.children.length&&this.flattenData(i.children,n,a)}return a}checkNodeDownward(t,n,a=!1){if(t.children.forEach(s=>{this.checkNodeDownward(s,n,a)}),t.isLeaf||this.options.load&&!t.children.length){if(!t.disabled){if(a&&!this.options.filteredNodeCheckable&&!t._filterVisible)return;t.checked=n,t.indeterminate=!1}}else this.checkParentNode(t)}checkNodeUpward(t){let n=t._parent;for(;n;)this.checkParentNode(n),n=n._parent}checkParentNode(t){const n=t.children.length;if(!n)return;let a=!1,s=!1,r=!1;for(let i=0;i<n;i++){const c=t.children[i];if(c.checked?a=!0:s=!0,a&&s||c.indeterminate){r=!0,t.checked=!1,t.indeterminate=!0;break}}r||(t.checked=a,t.indeterminate=!1)}findIndex(t,n=this.flatData){if(n!==null){let a=t instanceof X?t[this.options.keyField]:t;const s=n.length;for(let r=0;r<s;r++)if(n[0]instanceof X){if(a===n[r][this.options.keyField])return r}else if(a===n[r])return r}return-1}on(t,n){this.listenersMap[t]||(this.listenersMap[t]=[]);let a=[];Array.isArray(n)?a=n:a=[n],a.forEach(s=>{this.listenersMap[t].indexOf(s)===-1&&this.listenersMap[t].push(s)})}off(t,n){if(this.listenersMap[t])if(!n)this.listenersMap[t]=[];else{const a=this.listenersMap[t].indexOf(n);a>-1&&this.listenersMap[t].splice(a,1)}}emit(t,...n){if(!this.listenersMap[t])return;const a=this.listenersMap[t].length;for(let s=0;s<a;s++)this.listenersMap[t][s](...n)}disposeListeners(){for(const t in this.listenersMap)this.listenersMap[t]=[]}}const st=o.defineComponent({name:"CLoadingIcon"}),ne=(e,t)=>{const n=e.__vccOpts||e;for(const[a,s]of t)n[a]=s;return n},rt={viewBox:"0 0 50 50"},ot=[l.createElementVNode("circle",{class:"ctree-loading-icon__circle",cx:"25",cy:"25",r:"20",fill:"none","stroke-width":"5","stroke-miterlimit":"10"},null,-1)];function dt(e,t,n,a,s,r){return l.openBlock(),l.createElementBlock("svg",rt,ot)}const _e=ne(st,[["render",dt]]),N="ctree-tree-node",it=o.defineComponent({name:"CTreeNode",components:{LoadingIcon:_e},props:{data:Object,titleField:{type:String,default:""},keyField:String,render:Function,checkable:Boolean,selectable:Boolean,unselectOnClick:Boolean,disableAll:Boolean,draggable:Boolean,droppable:Boolean,getNode:Function},emits:[...he],setup(e,{emit:t}){var _;const n=o.ref(!1),a=o.ref(!1),s=o.ref(!1),r=e.keyField,i=e.getNode,c=o.computed(()=>{var h,k,$,S,V;return[`${N}__wrapper`,{[`${N}__wrapper_is-leaf`]:(h=e.data)==null?void 0:h.isLeaf,[`${N}_disabled`]:e.disableAll||((k=e.data)==null?void 0:k.disabled)},{[`${N}_checked`]:e.checkable&&(($=e.data)==null?void 0:$.checked),[`${N}_indeterminate`]:e.checkable&&((S=e.data)==null?void 0:S.indeterminate)},{[`${N}_selected`]:(V=e.data)==null?void 0:V.selected}]}),p=o.computed(()=>[`${N}__node-body`,{[`${N}__drop_active`]:n.value}]),g=o.computed(()=>[`${N}__drop`,{[`${N}__drop_active`]:a.value}]),w=o.computed(()=>[`${N}__drop`,{[`${N}__drop_active`]:s.value}]),b=o.computed(()=>[`${N}__square`,`${N}__checkbox_wrapper`]),M=o.computed(()=>{var h;return[`${N}__square`,`${N}__expand`,{[`${N}__expand_active`]:(h=e.data)==null?void 0:h.expand}]}),Y=o.computed(()=>[`${N}__loading-icon`]),q=o.computed(()=>{var h,k,$;return[`${N}__checkbox`,{[`${N}__checkbox_checked`]:(h=e.data)==null?void 0:h.checked,[`${N}__checkbox_indeterminate`]:(k=e.data)==null?void 0:k.indeterminate,[`${N}__checkbox_disabled`]:e.disableAll||(($=e.data)==null?void 0:$.disabled)}]}),D=o.computed(()=>{var h,k;return[`${N}__title`,{[`${N}__title_selected`]:(h=e.data)==null?void 0:h.selected,[`${N}__title_disabled`]:e.disableAll||((k=e.data)==null?void 0:k.disabled)}]}),E=o.computed(()=>i(e.data?e.data[r]:"")||e.data||{}),L=o.computed(()=>e.checkable),T=((_=e.data)==null?void 0:_.render)||e.render||null,x=o.computed(()=>o.defineComponent({name:"Render",functional:!0,render(){return typeof T!="function"?o.h("div"):T(E.value)}})),v=o.computed(()=>{var k;let h={};return e.draggable&&!e.disableAll&&!((k=e.data)!=null&&k.disabled)&&(h={dragstart:m}),h}),ee=o.computed(()=>{let h={};return e.droppable&&(h={dragenter:I.bind(o.getCurrentInstance()),dragover:u.bind(o.getCurrentInstance()),dragleave:z.bind(o.getCurrentInstance()),drop:j.bind(o.getCurrentInstance())}),h});function H(){var h;(h=e.data)!=null&&h.isLeaf||t("expand",E.value)}function J(){var h;e.disableAll||(h=e.data)!=null&&h.disabled||!e.checkable||t("check",E.value)}function Q(h){var k,$;if(t("click",E.value,h),e.selectable){if(e.disableAll||(k=e.data)!=null&&k.disabled||($=e.data)!=null&&$.selected&&!e.unselectOnClick)return;t("select",E.value)}else e.checkable?J():H()}function G(h){t("node-dblclick",E.value,h)}function te(h){t("node-right-click",E.value,h)}const Z=o.ref();function P(h){const k=Z.value.getBoundingClientRect(),$=k.height,S=h.clientY-k.top;return S<=$*.3?U.before:S<=$*(.3+.4)?U.body:U.after}function C(h,k=!1){a.value=!1,n.value=!1,s.value=!1,k||(h===U.before?a.value=!0:h===U.body?n.value=!0:h===U.after&&(s.value=!0))}function m(h){var k;h.dataTransfer&&h.dataTransfer.setData("node",JSON.stringify(e.data)),(k=e.data)!=null&&k.expand&&H(),t("node-dragstart",E.value,h)}function I(h){h.preventDefault();const k=P(h);C(k),t("node-dragenter",E.value,h,k)}function u(h){h.preventDefault();const k=P(h);C(k),t("node-dragover",E.value,h,k)}function z(h){const k=P(h);C(k,!0),t("node-dragleave",E.value,h,k)}function j(h){const k=P(h);C(k,!0),t("node-drop",E.value,h,k)}return{dragoverBody:n,dragoverBefore:a,dragoverAfter:s,wrapperCls:c,nodeBodyCls:p,dropBeforeCls:g,dropAfterCls:w,checkboxWrapperCls:b,expandCls:M,loadingIconCls:Y,checkboxCls:q,titleCls:D,fullData:E,showCheckbox:L,renderFunction:T,renderComponent:x,dragListeners:v,dropListeners:ee,handleExpand:H,handleCheck:J,handleSelect:Q,handleDblclick:G,handleRightClick:te,nodeBody:Z}}}),ct=["draggable"];function ht(e,t,n,a,s,r){var c,p,g,w;const i=l.resolveComponent("LoadingIcon");return l.openBlock(),l.createElementBlock("div",{class:l.normalizeClass(e.wrapperCls)},[l.createElementVNode("div",{class:l.normalizeClass(e.dropBeforeCls)},null,2),l.createElementVNode("div",l.mergeProps({ref:"nodeBody",class:e.nodeBodyCls},l.toHandlers(e.dropListeners,!0)),[l.createElementVNode("div",{class:l.normalizeClass(e.expandCls)},[l.withDirectives(l.createElementVNode("i",{onClick:t[0]||(t[0]=(...b)=>e.handleExpand&&e.handleExpand(...b))},null,512),[[l.vShow,!((c=e.data)!=null&&c.isLeaf)&&!((p=e.data)!=null&&p._loading)]]),(g=e.data)!=null&&g._loading?(l.openBlock(),l.createBlock(i,{key:0,class:l.normalizeClass(e.loadingIconCls)},null,8,["class"])):l.createCommentVNode("",!0)],2),e.showCheckbox?(l.openBlock(),l.createElementBlock("div",{key:0,class:l.normalizeClass(e.checkboxWrapperCls)},[l.createElementVNode("div",{class:l.normalizeClass(e.checkboxCls),onClick:t[1]||(t[1]=(...b)=>e.handleCheck&&e.handleCheck(...b))},null,2)],2)):l.createCommentVNode("",!0),l.createElementVNode("div",l.mergeProps({class:e.titleCls,onClick:t[2]||(t[2]=(...b)=>e.handleSelect&&e.handleSelect(...b)),onDblclick:t[3]||(t[3]=(...b)=>e.handleDblclick&&e.handleDblclick(...b)),onContextmenu:t[4]||(t[4]=(...b)=>e.handleRightClick&&e.handleRightClick(...b))},l.toHandlers(e.dragListeners,!0),{draggable:e.draggable&&!e.disableAll&&!((w=e.data)!=null&&w.disabled)}),[e.renderFunction?(l.openBlock(),l.createBlock(l.resolveDynamicComponent(e.renderComponent),{key:0})):l.renderSlot(e.$slots,"default",{key:1,title:e.data?e.data[e.titleField]:"",node:e.data},()=>[l.createTextVNode(l.toDisplayString(e.data?e.data[e.titleField]:""),1)])],16,ct)],16),l.createElementVNode("div",{class:l.normalizeClass(e.dropAfterCls)},null,2)],2)}const $e=ne(it,[["render",ht]]),Ee=["expand","select","unselect","selected-change","check","uncheck","checked-change","set-data"],ft=["node-drop","check","select","expand"],ut=o.defineComponent({name:"CTree",components:{CTreeNode:$e,LoadingIcon:_e},emits:["update:modelValue",...he,...Ee],props:{modelValue:[String,Number,Array],data:{type:Array,default:()=>[]},unloadDataList:{type:Array,default:()=>[]},showUnloadCheckedNodes:{type:Boolean,default:!0},emptyText:{type:String,default:"暂无数据"},titleField:{type:String,default:"title"},keyField:{type:String,default:"id"},separator:{type:String,default:","},checkable:{type:Boolean,default:!1},selectable:{type:Boolean,default:!1},filteredNodeCheckable:{type:Boolean,default:!1},cascade:{type:Boolean,default:!0},enableLeafOnly:{type:Boolean,default:!1},disableAll:{type:Boolean,default:!1},defaultExpandAll:{type:Boolean,default:!1},defaultExpandedKeys:{type:Array,default:()=>[]},expandedKeys:{type:Array,default:()=>[]},draggable:{type:Boolean,default:!1},droppable:{type:Boolean,default:!1},beforeDropMethod:{type:Function,default:()=>()=>!0},ignoreMode:{type:String,default:se.none},autoLoad:{type:Boolean,default:!0},load:Function,render:Function,filterMethod:Function,expandOnFilter:{type:Boolean,default:!0},unselectOnClick:{type:Boolean,default:!0},loading:{type:Boolean,default:!1},nodeMinHeight:{type:Number,default:30},nodeIndent:{type:Number,default:20},renderNodeAmount:{type:Number,default:100},bufferNodeAmount:{type:Number,default:20},nodeClassName:{type:[String,Object,Array,Function]}},setup(e,t){const n="ctree-tree",a=(d,f)=>{if(Array.isArray(d)&&Array.isArray(f)){if(d.length===f.length&&d.every(y=>f.some(R=>R===y)))return!0}else if(d===f)return!0;return!1};let s=o.reactive([]),r=o.ref([]);const i=o.ref(0),c=o.ref(0),p=o.ref(0),g=o.ref(0),w=o.ref(0),b=o.ref(0),M=o.ref(0),Y=o.ref(0),q=o.ref(!1),D=o.ref(Array.isArray(e.modelValue)?e.modelValue.concat():e.modelValue),E=o.ref(void 0),L=o.ref(),T=o.ref(),x=o.computed(()=>({height:`${p.value}px`})),v=o.computed(()=>({height:`${g.value}px`})),ee=o.computed(()=>[`${n}__wrapper`]),H=o.computed(()=>[`${n}__scroll-area`]),J=o.computed(()=>[`${n}__block-area`]),Q=o.computed(()=>[`${n}__empty`]),G=o.computed(()=>[`${n}__empty-text_default`]),te=o.computed(()=>[`${n}__loading`]),Z=o.computed(()=>[`${n}__loading-wrapper`]),P=o.computed(()=>[`${n}__loading-icon`]),C=o.computed(()=>[`${n}__iframe`]),m=he.reduce((d,f)=>(ft.indexOf(f)<0&&(d[f]=(...y)=>{t.emit.apply(t,[f,...y])}),d),{}),I=()=>({store:new we({keyField:e.keyField,ignoreMode:e.ignoreMode,filteredNodeCheckable:e.filteredNodeCheckable,cascade:e.cascade,defaultExpandAll:e.defaultExpandAll,load:e.load,expandOnFilter:e.expandOnFilter}),blockNodes:[]});let u=I();o.watch(()=>e.modelValue,d=>{if(e.checkable){if(a(d,D.value))return;let f=[];Array.isArray(d)?f=d.concat():typeof d=="string"&&(f=d===""?[]:d.split(e.separator)),u.store.clearChecked(!1,!1),u.store.setCheckedKeys(f,!0)}else if(e.selectable){if(d===D.value)return;const f=u.store.getSelectedKey();d!==""&&d!=null?u.store.setSelected(d,!0):(d===""||d==null)&&f&&u.store.setSelected(f,!1)}}),o.watch(()=>e.data,d=>{z(d)}),o.watch(()=>e.expandedKeys,()=>{de()});function z(d){Ce();let f=null,y=null;e.checkable?Array.isArray(e.modelValue)?f=e.modelValue.concat():typeof e.modelValue=="string"&&(f=e.modelValue===""?[]:e.modelValue.split(e.separator)):e.selectable&&!Array.isArray(e.modelValue)&&(y=e.modelValue),u.store.setData(d,y,f),de()}function j(d,f){u.store.setChecked(d,f)}function _(d,f){u.store.setCheckedKeys(d,f)}function h(){u.store.checkAll()}function k(){u.store.clearChecked()}function $(d,f){u.store.setSelected(d,f)}function S(){u.store.clearSelected()}function V(d,f,y=!0){u.store.setExpand(d,f,y)}function ae(d,f){u.store.setExpandKeys(d,f)}function Be(d){u.store.setExpandAll(d)}function Ie(d){return d=d||e.ignoreMode,u.store.getCheckedNodes(d)}function Te(d){return d=d||e.ignoreMode,u.store.getCheckedKeys(d)}function Le(){return u.store.getIndeterminateNodes()}function Me(){return u.store.getSelectedNode()}function Re(){return u.store.getSelectedKey()}function ze(){return u.store.getExpandNodes()}function Oe(){return u.store.getExpandKeys()}function De(){return u.store.flatData.filter(d=>d._filterVisible)}function fe(d){return u.store.getNode(d)}function xe(){return u.store.data}function He(){return u.store.flatData}function Pe(){return u.store.flatData.length}function Ue(d,f){return u.store.insertBefore(d,f)}function We(d,f){return u.store.insertAfter(d,f)}function je(d,f){return u.store.append(d,f)}function Xe(d,f){return u.store.prepend(d,f)}function Ye(d){return u.store.remove(d)}function qe(d,f){const y=(R,K)=>{const F=K[e.titleField];return F==null||!F.toString?!1:F.toString().toLowerCase().indexOf(R.toLowerCase())>-1};f=f||e.filterMethod||y,u.store.filter(d,f)}function Je(d){if(!e.checkable)return;d=d??e.showUnloadCheckedNodes;const f=u.store.getCheckedNodes();if(u.store.filter("",(R,K)=>K.checked),!d)return;const y=u.store.getUnloadCheckedKeys();if(y.length){const R=y.map(K=>{const F=e.unloadDataList.concat(f);let be=K;return F.some(Se=>Se[e.keyField]===K&&Se[e.titleField]!=null?(be=Se[e.titleField],!0):!1),new X({[e.keyField]:K,[e.titleField]:be,checked:!0,isLeaf:!0},null,e.keyField,!!e.load)});s=R,u.blockNodes.push(...R),ie(),le()}}function ue(){return q.value=!0,new Promise((d,f)=>{e.load&&e.load(null,d,f)}).then(d=>{Array.isArray(d)&&z(d)}).catch(()=>{}).then(()=>{q.value=!1})}function Ge(d,f=re.top){const y=u.store.mapData[d];if(!y||!y.visible)return;let R=-1;for(let F=0;F<i.value;F++)if(u.blockNodes[F][e.keyField]===d){R=F;break}if(R===-1)return;let K=R*e.nodeMinHeight;if(f===re.center){const F=L.value.clientHeight;K=K-(F-e.nodeMinHeight)/2}else if(f===re.bottom){const F=L.value.clientHeight;K=K-(F-e.nodeMinHeight)}else typeof f=="number"&&(K=K-f);L.value&&(L.value.scrollTop=K)}function de(){e.expandedKeys.length&&(u.store.setExpandAll(!1,!1),u.store.setExpandKeys(e.expandedKeys,!0))}function pe(){if(s.length){const d=u.store.getUnloadCheckedKeys();s.forEach(f=>{f.checked=d.indexOf(f[e.keyField])>-1})}}function Qe(d){!e.cascade&&e.enableLeafOnly&&!d.isLeaf||u.store.setChecked(d[e.keyField],d.indeterminate?!0:!d.checked,!0,!0,!0)}function Ze(d){e.enableLeafOnly&&!d.isLeaf||u.store.setSelected(d[e.keyField],!d.selected)}function ve(d){u.store.setExpand(d[e.keyField],!d.expand)}function et(d,f,y){if(e.droppable&&f.dataTransfer)try{const K=JSON.parse(f.dataTransfer.getData("node"))[e.keyField],F=d[e.keyField];if(e.beforeDropMethod(K,F,y)){if(K===F)return;y===U.before?u.store.insertBefore(K,F):y===U.body||!d.isLeaf&&d.expand?u.store.prepend(K,F):y===U.after&&u.store.insertAfter(K,F),t.emit("node-drop",d,f,y,fe(K))}}catch(R){throw new Error(R)}}function ke(d,f){if(e.checkable){let y=f;Array.isArray(e.modelValue)||(y=y.join(e.separator)),Array.isArray(y)?D.value=y.concat():D.value=y,t.emit("update:modelValue",y)}}function ge(d,f){if(e.selectable&&!e.checkable){const y=f||"";D.value=y,t.emit("update:modelValue",y)}}function tt(){Ee.forEach(d=>{u.store.on(d,(...f)=>{t.emit.apply(t,[d,...f])})})}function Ce(){p.value=0,g.value=0,L.value&&(L.value.scrollTop=0)}function ye(){u.blockNodes=u.store.flatData.filter(d=>d.visible),ie(),le()}function ie(){i.value=u.blockNodes.length,c.value=e.nodeMinHeight*i.value}function le(){me(),ce()}function me(){const d=L.value.clientHeight;w.value=Math.max(e.renderNodeAmount,Math.ceil(d/e.nodeMinHeight)+e.bufferNodeAmount)}function ce(d=!1){if(i.value>w.value){const f=L.value.scrollTop,y=Math.floor(f/e.nodeMinHeight);M.value=Math.floor(y/e.bufferNodeAmount)*e.bufferNodeAmount}else M.value=0;d&&b.value===w.value&&Y.value===M.value||(r.value=u.blockNodes.slice(M.value,M.value+w.value).map(f=>Object.assign({},f,{_parent:null,children:[]})),p.value=M.value*e.nodeMinHeight,g.value=c.value-(p.value+r.value.length*e.nodeMinHeight))}function lt(){E.value&&window.cancelAnimationFrame(E.value),b.value=w.value,Y.value=M.value,E.value=window.requestAnimationFrame(ce.bind(null,!0))}const Nt={setData:z,setChecked:j,setCheckedKeys:_,checkAll:h,clearChecked:k,setSelected:$,clearSelected:S,setExpand:V,setExpandKeys:ae,setExpandAll:Be,getCheckedNodes:Ie,getCheckedKeys:Te,getIndeterminateNodes:Le,getSelectedNode:Me,getSelectedKey:Re,getExpandNodes:ze,getExpandKeys:Oe,getCurrentVisibleNodes:De,getTreeData:xe,getFlatData:He,getNodesCount:Pe,insertBefore:Ue,insertAfter:We,append:je,prepend:Xe,remove:Ye,filter:qe,showCheckedNodes:Je,loadRootNodes:ue,scrollTo:Ge,updateExpandedKeys:de,updateUnloadStatus:pe,handleTreeScroll:lt,handleNodeCheck:Qe,handleNodeSelect:Ze,handleNodeExpand:ve,handleNodeDrop:et,emitCheckableInput:ke,emitSelectableInput:ge,resetSpaceHeights:Ce,updateBlockNodes:ye,updateBlockData:ie,updateRender:le,updateRenderAmount:me,updateRenderNodes:ce,getNode:fe};return o.onMounted(()=>{u.store.on("visible-data-change",ye),u.store.on("render-data-change",le),u.store.on("checked-change",(f,y)=>{ke(f,y),pe()}),u.store.on("selected-change",ge),e.data.length?(z(e.data),e.defaultExpandedKeys.length&&u.store.setExpandKeys(e.defaultExpandedKeys,!0)):typeof e.load=="function"&&e.autoLoad&&((e.modelValue||e.unloadDataList)&&z([]),ue());const d=T.value;d!=null&&d.contentWindow&&d.contentWindow.addEventListener("resize",le)}),o.onBeforeUnmount(()=>{const d=T.value;d!=null&&d.contentWindow&&d.contentWindow.removeEventListener("resize",le),u.store.disposeListeners();const f=I();u.store=f.store,u.blockNodes=f.blockNodes}),tt(),{nonReactive:u,unloadCheckedNodes:s,blockLength:i,blockAreaHeight:c,topSpaceHeight:p,bottomSpaceHeight:g,renderAmount:w,renderAmountCache:b,renderNodes:r,renderStart:M,renderStartCache:Y,isRootLoading:q,valueCache:D,debounceTimer:E,topSpaceStyles:x,bottomSpaceStyles:v,wrapperCls:ee,scrollAreaCls:H,blockAreaCls:J,emptyCls:Q,emptyTextDefaultCls:G,loadingCls:te,loadingWrapperCls:Z,loadingIconCls:P,iframeCls:C,treeNodeListeners:m,setData:z,setChecked:j,setCheckedKeys:_,checkAll:h,clearChecked:k,setSelected:$,clearSelected:S,setExpand:V,setExpandKeys:ae,setExpandAll:Be,getCheckedNodes:Ie,getCheckedKeys:Te,getIndeterminateNodes:Le,getSelectedNode:Me,getSelectedKey:Re,getExpandNodes:ze,getExpandKeys:Oe,getCurrentVisibleNodes:De,getTreeData:xe,getFlatData:He,getNodesCount:Pe,insertBefore:Ue,insertAfter:We,append:je,prepend:Xe,remove:Ye,filter:qe,showCheckedNodes:Je,loadRootNodes:ue,scrollTo:Ge,updateExpandedKeys:de,updateUnloadStatus:pe,handleTreeScroll:lt,handleNodeCheck:Qe,handleNodeSelect:Ze,handleNodeExpand:ve,handleNodeDrop:et,emitCheckableInput:ke,emitSelectableInput:ge,attachStoreEvents:tt,resetSpaceHeights:Ce,updateBlockNodes:ye,updateBlockData:ie,updateRender:le,updateRenderAmount:me,updateRenderNodes:ce,getNode:fe,scrollArea:L,iframe:T,methods:Nt}}});function pt(e,t,n,a,s,r){const i=l.resolveComponent("CTreeNode"),c=l.resolveComponent("LoadingIcon");return l.openBlock(),l.createElementBlock("div",{class:l.normalizeClass(e.wrapperCls)},[l.createElementVNode("div",{ref:"scrollArea",class:l.normalizeClass(e.scrollAreaCls),onScrollPassive:t[0]||(t[0]=l.withModifiers((...p)=>e.handleTreeScroll&&e.handleTreeScroll(...p),["stop"]))},[l.createElementVNode("div",{class:l.normalizeClass(e.blockAreaCls)},[l.createElementVNode("div",{style:l.normalizeStyle(e.topSpaceStyles)},null,4),(l.openBlock(!0),l.createElementBlock(l.Fragment,null,l.renderList(e.renderNodes,p=>(l.openBlock(),l.createBlock(i,l.mergeProps(e.$props,{key:p[e.keyField],data:p,getNode:e.getNode},l.toHandlers(e.treeNodeListeners),{class:typeof e.nodeClassName=="function"?e.nodeClassName(p):e.nodeClassName,style:{minHeight:`${e.nodeMinHeight}px`,paddingLeft:`${p._level*e.nodeIndent}px`},onCheck:e.handleNodeCheck,onSelect:e.handleNodeSelect,onExpand:e.handleNodeExpand,onNodeDrop:e.handleNodeDrop}),{default:l.withCtx(({title:g,node:w})=>[l.renderSlot(e.$slots,"node",{title:g,node:w},()=>[l.createTextVNode(l.toDisplayString(g),1)])]),_:2},1040,["data","getNode","class","style","onCheck","onSelect","onExpand","onNodeDrop"]))),128)),l.createElementVNode("div",{style:l.normalizeStyle(e.bottomSpaceStyles)},null,4)],2)],34),l.withDirectives(l.createElementVNode("div",{class:l.normalizeClass(e.emptyCls)},[l.createElementVNode("span",{class:l.normalizeClass(e.emptyTextDefaultCls)},[l.renderSlot(e.$slots,"empty",{},()=>[l.createTextVNode(l.toDisplayString(e.emptyText),1)])],2)],2),[[l.vShow,!e.blockLength]]),l.withDirectives(l.createElementVNode("div",{class:l.normalizeClass(e.loadingCls)},[l.createElementVNode("div",{class:l.normalizeClass(e.loadingWrapperCls)},[l.renderSlot(e.$slots,"loading",{},()=>[l.createVNode(c,{class:l.normalizeClass(e.loadingIconCls)},null,8,["class"])])],2)],2),[[l.vShow,e.loading||e.isRootLoading]]),l.createElementVNode("iframe",{ref:"iframe",class:l.normalizeClass(e.iframeCls)},null,2)],2)}const Ve=ne(ut,[["render",pt]]);function Ke(e){return at.reduce((t,n)=>(t[n]=function(...a){return e.value[n].apply(e.value,a)},t),{})}const O="ctree-tree-search",oe="ctree-tree-node",kt=o.defineComponent({name:"CTreeSearch",inheritAttrs:!1,emits:["checked-change","search","set-data","update:modelValue"],components:{CTree:Ve},props:{modelValue:[String,Number,Array],searchPlaceholder:{type:String,default:"搜索关键字"},showCheckAll:{type:Boolean,default:!0},showCheckedButton:{type:Boolean,default:!0},checkedButtonText:{type:String,default:"已选"},showFooter:{type:Boolean,default:!0},searchMethod:Function,searchLength:{type:Number,default:1},searchDisabled:{type:Boolean,default:!1},searchRemote:{type:Boolean,default:!1},searchDebounceTime:{type:Number,default:300}},setup(e,{emit:t,attrs:n,expose:a}){const s=o.reactive({checked:!1,indeterminate:!1,disabled:!1}),r=o.ref(!1),i=o.ref(""),c=o.ref(void 0),p=o.ref(0),g=o.ref();let w=Ke(g);const b=o.computed({get:()=>e.modelValue,set:_=>{I(),t("update:modelValue",_)}}),M=o.computed(()=>[`${O}__wrapper`]),Y=o.computed(()=>[`${O}__search`]),q=o.computed(()=>[`${O}__check-all-wrapper`]),D=o.computed(()=>[`${O}__check-all`,`${oe}__checkbox`,{[`${oe}__checkbox_checked`]:s.checked,[`${oe}__checkbox_indeterminate`]:s.indeterminate,[`${oe}__checkbox_disabled`]:e.searchDisabled||s.disabled}]),E=o.computed(()=>[`${O}__input-wrapper`]),L=o.computed(()=>[`${O}__input`,{[`${O}__input_disabled`]:e.searchDisabled}]),T=o.computed(()=>[`${O}__action-wrapper`]),x=o.computed(()=>[`${O}__checked-button`,{[`${O}__checked-button_active`]:r.value}]),v=o.computed(()=>[`${O}__tree-wrapper`]),ee=o.computed(()=>[`${O}__footer`]),H=o.computed(()=>"checkable"in n&&n.checkable!==!1);function J(){i.value=""}function Q(){return i.value}function G(_){let h=_;return typeof _!="string"&&(h=i.value),new Promise((k,$)=>{clearTimeout(c.value),c.value=setTimeout(()=>{if(!(h.length>0&&h.length<e.searchLength))if(r.value=!1,t("search",h),typeof e.searchMethod=="function"){const S=e.searchMethod(h);Promise.resolve(S).then(()=>{m(),k()})}else e.searchRemote?g.value.loadRootNodes().then(()=>{m(),k()}):(g.value.filter(h),m(),k())},e.searchDebounceTime)})}function te(){if(e.searchDisabled||s.disabled)return;const _=g.value.getCurrentVisibleNodes().map(h=>h[g.value.keyField]);s.checked||s.indeterminate?g.value.setCheckedKeys(_,!1):g.value.setCheckedKeys(_,!0),m()}function Z(){G()}function P(){const _=()=>{r.value=!r.value,r.value?g.value.showCheckedNodes():g.value.filter(i.value,()=>!0),m()};i.value?(J(),G().then(()=>{_()})):_()}function C(){I(),m()}function m(){const _=g.value.getCurrentVisibleNodes(),h=_.length;let k=!1,$=!1,S=!1;for(let V=0;V<h;V++){const ae=_[V];if(ae.checked?k=!0:$=!0,k&&$||ae.indeterminate){S=!0,s.checked=!1,s.indeterminate=!0;break}}S||(s.checked=k,s.indeterminate=!1)}function I(){p.value=g.value.getCheckedKeys().length}function u(_,h){m(),t("checked-change",_,h)}function z(){t("set-data"),C()}return o.onMounted(()=>{H.value&&!p.value&&C()}),{...w,treeModelValue:b,setChecked:(_,h)=>{g.value.setChecked(_,h)},checkAllStatus:s,isShowingChecked:r,keyword:i,debounceTimer:c,checkedCount:p,wrapperCls:M,searchCls:Y,checkAllWrapperCls:q,checkboxCls:D,inputWrapperCls:E,inputCls:L,actionWrapperCls:T,checkedButtonCls:x,treeWrapperCls:v,footerCls:ee,checkable:H,treeRef:g,handleCheckAll:te,handleSearch:Z,handleShowChecked:P,updateCheckedCount:I,handleSetData:C,updateCheckAllStatus:m,getKeyword:Q,checkedChange:u,onSetData:z,clearKeyword:J,search:G}}}),gt=["placeholder","disabled"],Ct={style:{float:"right"}};function yt(e,t,n,a,s,r){const i=l.resolveComponent("CTree");return l.openBlock(),l.createElementBlock("div",{class:l.normalizeClass(e.wrapperCls)},[l.createElementVNode("div",{class:l.normalizeClass(e.searchCls)},[e.showCheckAll&&e.checkable?(l.openBlock(),l.createElementBlock("div",{key:0,class:l.normalizeClass(e.checkAllWrapperCls)},[l.createElementVNode("div",{class:l.normalizeClass(e.checkboxCls),onClick:t[0]||(t[0]=(...c)=>e.handleCheckAll&&e.handleCheckAll(...c))},null,2)],2)):l.createCommentVNode("",!0),l.createElementVNode("div",{class:l.normalizeClass(e.inputWrapperCls)},[l.renderSlot(e.$slots,"search-input",{},()=>[l.withDirectives(l.createElementVNode("input",{"onUpdate:modelValue":t[1]||(t[1]=c=>e.keyword=c),type:"text",class:l.normalizeClass(e.inputCls),placeholder:e.searchPlaceholder,disabled:e.searchDisabled,onInput:t[2]||(t[2]=(...c)=>e.handleSearch&&e.handleSearch(...c))},null,42,gt),[[l.vModelText,e.keyword]])])],2),l.createElementVNode("div",{class:l.normalizeClass(e.actionWrapperCls)},[e.showCheckedButton&&e.checkable?(l.openBlock(),l.createElementBlock("span",{key:0,class:l.normalizeClass(e.checkedButtonCls),onClick:t[3]||(t[3]=(...c)=>e.handleShowChecked&&e.handleShowChecked(...c))},l.toDisplayString(e.checkedButtonText),3)):l.createCommentVNode("",!0),l.renderSlot(e.$slots,"actions")],2)],2),l.createElementVNode("div",{class:l.normalizeClass(e.treeWrapperCls)},[l.createVNode(i,l.mergeProps({ref:"treeRef"},e.$attrs,{modelValue:e.treeModelValue,"onUpdate:modelValue":t[4]||(t[4]=c=>e.treeModelValue=c),onSetData:e.onSetData,onCheckedChange:e.checkedChange}),l.createSlots({_:2},[l.renderList(e.$slots,(c,p)=>({name:"default",fn:l.withCtx(g=>[l.renderSlot(e.$slots,p,l.normalizeProps(l.guardReactiveProps(g)))])}))]),1040,["modelValue","onSetData","onCheckedChange"])],2),e.showFooter&&e.checkable?(l.openBlock(),l.createElementBlock("div",{key:0,class:l.normalizeClass(e.footerCls)},[l.renderSlot(e.$slots,"footer",{},()=>[l.createElementVNode("span",Ct,"已选 "+l.toDisplayString(e.checkedCount)+" 个",1)])],2)):l.createCommentVNode("",!0)],2)}const Ae=ne(kt,[["render",yt]]),W="ctree-tree-drop",Fe="ctree-tree-search",mt=o.defineComponent({name:"CTreeDrop",inheritAttrs:!1,emits:["clear","checked-change","dropdown-visible-change","update:modelValue"],components:{CTreeSearch:Ae},props:{modelValue:[String,Number,Array],dropHeight:{type:Number,default:300},dropPlaceholder:{type:String},dropDisabled:{type:Boolean,default:!1},clearable:{type:Boolean,default:!1},placement:{type:String,default:Ne["bottom-start"]},transfer:{type:Boolean,default:!1},dropdownClassName:[String,Array],dropdownMinWidth:{type:Number},dropdownWidthFixed:{type:Boolean,default:!1}},setup(e,{attrs:t,emit:n}){const a=o.ref(!1),s=o.ref(0),r=o.ref(""),i=o.ref(),c=o.ref(),p=o.ref(),g=o.reactive({checkedNodes:[],checkedKeys:[],selectedNode:void 0,selectedKey:void 0}),w=o.computed({get:()=>e.modelValue,set:C=>{n("update:modelValue",C)}}),b=o.computed(()=>[`${W}__wrapper`]),M=o.computed(()=>[`${W}__reference`]),Y=o.computed(()=>[`${Fe}__input`,`${W}__display-input`,{[`${W}__display-input_focus`]:a.value,[`${Fe}__input_disabled`]:e.dropDisabled}]),q=o.computed(()=>{let C=!1;return typeof e.dropPlaceholder=="string"&&(T.value?C=s.value===0:x.value&&(C=r.value==="")),[`${W}__display-input-text`,{[`${W}__display-input-placeholder`]:C}]}),D=o.computed(()=>[`${W}__display-icon-drop`,{[`${W}__display-icon-drop_active`]:a.value}]),E=o.computed(()=>[`${W}__display-icon-clear`]),L=o.computed(()=>{const C=Array.isArray(e.dropdownClassName)?e.dropdownClassName:[e.dropdownClassName];return[`${W}__dropdown`,...C]}),T=o.computed(()=>"checkable"in t&&t.checkable!==!1),x=o.computed(()=>"selectable"in t&&t.selectable!==!1),v=o.computed(()=>T.value?s.value===0&&typeof e.dropPlaceholder=="string"?e.dropPlaceholder:`已选 ${s.value} 个`:x.value?r.value===""&&typeof e.dropPlaceholder=="string"?e.dropPlaceholder:r.value:e.dropPlaceholder||""),ee=o.computed(()=>T.value?s.value!==0:x.value?r.value!=="":!1);function H(){const C=i.value.getBoundingClientRect(),m=C.width,I=C.height,u=`${typeof e.dropdownMinWidth=="number"?e.dropdownMinWidth:m}px`;c.value.style.minWidth=u,c.value.style.width=e.dropdownWidthFixed?u:"auto";const z=c.value.getBoundingClientRect(),j=window.getComputedStyle(c.value),_=parseFloat(j.marginLeft)+parseFloat(j.marginRight),h=parseFloat(j.marginTop)+parseFloat(j.marginBottom),k=z.width+_,$=z.height/.8+h;let S=0,V=0;switch(e.transfer&&(S=-999,V=-999),e.placement){case"bottom-start":e.transfer?(S=window.pageYOffset+C.bottom,V=window.pageXOffset+C.left):S=I;break;case"bottom-end":e.transfer?(S=window.pageYOffset+C.bottom,V=window.pageXOffset+C.right-k):(S=I,V=m-k);break;case"bottom":e.transfer?(S=window.pageYOffset+C.bottom,V=window.pageXOffset+C.left+(m-k)/2):(S=I,V=(m-k)/2);break;case"top-start":e.transfer?(S=window.pageYOffset+C.top-$,V=window.pageXOffset+C.left):S=-$;break;case"top-end":e.transfer?(S=window.pageYOffset+C.top-$,V=window.pageXOffset+C.right-k):(S=-$,V=m-k);break;case"top":e.transfer?(S=window.pageYOffset+C.top-$,V=window.pageXOffset+C.left+(m-k)/2):(S=-$,V=(m-k)/2);break}c.value.style.top=`${S}px`,c.value.style.left=`${V}px`}function J(){e.dropDisabled||(a.value=!a.value)}function Q(C){var m,I;!((m=i.value)!=null&&m.contains(C.target))&&!((I=c.value)!=null&&I.contains(C.target))&&(a.value=!1)}function G(){n("clear"),T.value?p.value.clearChecked():x.value&&p.value.clearSelected()}function te(C,m){g.checkedNodes=C,g.checkedKeys=m,s.value=m.length,n("checked-change",C,m)}function Z(C,m){if(g.selectedNode=C,g.selectedKey=m,C){const I=p.value.$refs.treeRef.titleField;r.value=C[I]}else m?r.value=m:r.value="";a.value=!1}function P(){const C=p.value.$refs.treeRef;if(g.checkedNodes=p.value.getCheckedNodes(),g.checkedKeys=p.value.getCheckedKeys(),g.selectedNode=p.value.getSelectedNode(),g.selectedKey=p.value.getSelectedKey(),T.value&&(s.value=g.checkedKeys.length),x.value&&e.modelValue!=null){const m=p.value.getNode(e.modelValue);if(m){const I=C.titleField;r.value=m[I]}else r.value=e.modelValue}}return o.onMounted(()=>{document.addEventListener("click",Q),e.transfer&&document.body.appendChild(c.value),P()}),o.watch(()=>a.value,C=>{n("dropdown-visible-change",C),C?o.nextTick(()=>{H()}):p.value.getKeyword()&&(p.value.clearKeyword(),p.value.search())}),{...Ke(p),treeSearchValue:w,dropdownVisible:a,checkedCount:s,selectedTitle:r,slotProps:g,wrapperCls:b,referenceCls:M,displayInputCls:Y,displayInputTextCls:q,dropIconCls:D,clearIconCls:E,dropdownCls:L,checkable:T,selectable:x,displayValue:v,showClearIcon:ee,referenceRef:i,dropdownRef:c,treeSearchRef:p,locateDropdown:H,handleRefClick:J,handleDocumentClick:Q,handleClear:G,handleCheckedChange:te,handleSelectedChange:Z,handleSetData:P}}});function bt(e,t,n,a,s,r){const i=l.resolveComponent("CTreeSearch");return l.openBlock(),l.createElementBlock("div",{class:l.normalizeClass(e.wrapperCls)},[l.createElementVNode("div",{ref:"referenceRef",class:l.normalizeClass(e.referenceCls),onClick:t[1]||(t[1]=(...c)=>e.handleRefClick&&e.handleRefClick(...c))},[l.renderSlot(e.$slots,"default",l.normalizeProps(l.guardReactiveProps(e.slotProps)),()=>[l.createElementVNode("div",{class:l.normalizeClass(e.displayInputCls)},[l.createElementVNode("span",{class:l.normalizeClass(e.displayInputTextCls)},[l.renderSlot(e.$slots,"display",l.normalizeProps(l.guardReactiveProps(e.slotProps)),()=>[l.createTextVNode(l.toDisplayString(e.displayValue),1)])],2),e.dropDisabled?l.createCommentVNode("",!0):(l.openBlock(),l.createElementBlock(l.Fragment,{key:0},[l.createElementVNode("i",{class:l.normalizeClass(e.dropIconCls)},null,2),e.clearable&&e.showClearIcon?l.renderSlot(e.$slots,"clear",{key:0},()=>[l.createElementVNode("i",{class:l.normalizeClass(e.clearIconCls),onClick:t[0]||(t[0]=l.withModifiers((...c)=>e.handleClear&&e.handleClear(...c),["stop"]))},null,2)]):l.createCommentVNode("",!0)],64))],2)])],2),l.createVNode(l.Transition,{name:"ctree-dropdown"},{default:l.withCtx(()=>[l.withDirectives(l.createElementVNode("div",{ref:"dropdownRef",class:l.normalizeClass(e.dropdownCls),style:l.normalizeStyle({height:`${e.dropHeight}px`})},[l.createVNode(i,l.mergeProps({ref:"treeSearchRef",modelValue:e.treeSearchValue,"onUpdate:modelValue":t[2]||(t[2]=c=>e.treeSearchValue=c)},e.$attrs,{onSetData:e.handleSetData,onCheckedChange:e.handleCheckedChange,onSelectedChange:e.handleSelectedChange}),l.createSlots({_:2},[l.renderList(e.$slots,(c,p)=>({name:p,fn:l.withCtx(g=>[l.renderSlot(e.$slots,p,l.normalizeProps(l.guardReactiveProps(g)))])}))]),1040,["modelValue","onSetData","onCheckedChange","onSelectedChange"])],6),[[l.vShow,e.dropdownVisible]])]),_:3})],2)}const St=ne(mt,[["render",bt]]),Et="";B.TreeNode=X,B.TreeStore=we,B.VTreeDrop=St,B.VTreeNode=$e,B.VTreeSearch=Ae,B.default=Ve,Object.defineProperties(B,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});