el-text-DAeYvMBn.js 27 KB

1
  1. import{av as Le,aC as Oe,ao as te,d as J,i as D,al as $e,aq as H,c as ye,ab as $,bE as Me,k as Ne,aJ as ke,z as O,o as K,w as _,X as he,au as Ce,a0 as w,e as ze,at as ve,aA as me,bF as se,a6 as Fe,ah as V,j as Pe,aF as ee,a4 as be,aj as qe,ai as fe,G as de,aa as j,bG as pe,ax as Y,bH as ne,bI as je,S as L,C as ae,U as re,a as P,b as ie,m as oe,B as W,ar as A,F as Ke,r as Ee,bJ as He,V as Re,bK as Ue,Y as x,bL as We,ae as De,bM as Ge,bp as B,t as Ye,bu as Je,bf as Xe,aG as Qe}from"./index-VgExUtlc.js";import{s as Ve}from"./token-DI9FKtlJ.js";import{E as Ze}from"./el-checkbox-BVoYWbHd.js";const _e=Le({type:{type:String,values:["primary","success","info","warning","danger",""],default:""},size:{type:String,values:Oe,default:""},truncated:Boolean,lineClamp:{type:[String,Number]},tag:{type:String,default:"span"}}),et=J({name:"ElText"}),tt=J({...et,props:_e,setup(t){const e=t,n=D(),d=$e(),o=H("text"),s=ye(()=>[o.b(),o.m(e.type),o.m(d.value),o.is("truncated",e.truncated),o.is("line-clamp",!$(e.lineClamp))]),a=Me().title,c=()=>{var l,p,r,f,h;if(a)return;let g=!1;const N=((l=n.value)==null?void 0:l.textContent)||"";if(e.truncated){const C=(p=n.value)==null?void 0:p.offsetWidth,v=(r=n.value)==null?void 0:r.scrollWidth;C&&v&&v>C&&(g=!0)}else if(!$(e.lineClamp)){const C=(f=n.value)==null?void 0:f.offsetHeight,v=(h=n.value)==null?void 0:h.scrollHeight;C&&v&&v>C&&(g=!0)}g?n.value.setAttribute("title",N):n.value.removeAttribute("title")};return Ne(c),ke(c),(l,p)=>(K(),O(ve(l.tag),{ref_key:"textRef",ref:n,class:w(ze(s)),style:Ce({"-webkit-line-clamp":l.lineClamp})},{default:_(()=>[he(l.$slots,"default")]),_:3},8,["class","style"]))}});var nt=te(tt,[["__file","text.vue"]]);const ot=me(nt),q="$treeNodeId",ge=function(t,e){!e||e[q]||Object.defineProperty(e,q,{value:t.id,enumerable:!1,configurable:!1,writable:!1})},ue=(t,e)=>e==null?void 0:e[t||q],le=(t,e,n)=>{const d=t.value.currentNode;n();const o=t.value.currentNode;d!==o&&e("current-change",o?o.data:null,o)},ce=t=>{let e=!0,n=!0,d=!0;for(let o=0,s=t.length;o<s;o++){const a=t[o];(a.checked!==!0||a.indeterminate)&&(e=!1,a.disabled||(d=!1)),(a.checked!==!1||a.indeterminate)&&(n=!1)}return{all:e,none:n,allWithoutDisable:d,half:!e&&!n}},G=function(t){if(t.childNodes.length===0||t.loading)return;const{all:e,none:n,half:d}=ce(t.childNodes);e?(t.checked=!0,t.indeterminate=!1):d?(t.checked=!1,t.indeterminate=!0):n&&(t.checked=!1,t.indeterminate=!1);const o=t.parent;!o||o.level===0||t.store.checkStrictly||G(o)},Z=function(t,e){const n=t.store.props,d=t.data||{},o=n[e];if(ee(o))return o(d,t);if(be(o))return d[o];if($(o)){const s=d[e];return $(s)?"":s}};let st=0;class M{constructor(e){this.id=st++,this.text=null,this.checked=!1,this.indeterminate=!1,this.data=null,this.expanded=!1,this.parent=null,this.visible=!0,this.isCurrent=!1,this.canFocus=!1;for(const n in e)se(e,n)&&(this[n]=e[n]);this.level=0,this.loaded=!1,this.childNodes=[],this.loading=!1,this.parent&&(this.level=this.parent.level+1)}initialize(){const e=this.store;if(!e)throw new Error("[Node]store is required!");e.registerNode(this);const n=e.props;if(n&&typeof n.isLeaf<"u"){const s=Z(this,"isLeaf");Fe(s)&&(this.isLeafByUser=s)}if(e.lazy!==!0&&this.data?(this.setData(this.data),e.defaultExpandAll&&(this.expanded=!0,this.canFocus=!0)):this.level>0&&e.lazy&&e.defaultExpandAll&&!this.isLeafByUser&&this.expand(),V(this.data)||ge(this,this.data),!this.data)return;const d=e.defaultExpandedKeys,o=e.key;o&&d&&d.includes(this.key)&&this.expand(null,e.autoExpandParent),o&&e.currentNodeKey!==void 0&&this.key===e.currentNodeKey&&(e.currentNode=this,e.currentNode.isCurrent=!0),e.lazy&&e._initDefaultCheckedNode(this),this.updateLeafState(),this.parent&&(this.level===1||this.parent.expanded===!0)&&(this.canFocus=!0)}setData(e){V(e)||ge(this,e),this.data=e,this.childNodes=[];let n;this.level===0&&V(this.data)?n=this.data:n=Z(this,"children")||[];for(let d=0,o=n.length;d<o;d++)this.insertChild({data:n[d]})}get label(){return Z(this,"label")}get key(){const e=this.store.key;return this.data?this.data[e]:null}get disabled(){return Z(this,"disabled")}get nextSibling(){const e=this.parent;if(e){const n=e.childNodes.indexOf(this);if(n>-1)return e.childNodes[n+1]}return null}get previousSibling(){const e=this.parent;if(e){const n=e.childNodes.indexOf(this);if(n>-1)return n>0?e.childNodes[n-1]:null}return null}contains(e,n=!0){return(this.childNodes||[]).some(d=>d===e||n&&d.contains(e))}remove(){const e=this.parent;e&&e.removeChild(this)}insertChild(e,n,d){if(!e)throw new Error("InsertChild error: child is required.");if(!(e instanceof M)){if(!d){const o=this.getChildren(!0);o.includes(e.data)||($(n)||n<0?o.push(e.data):o.splice(n,0,e.data))}Object.assign(e,{parent:this,store:this.store}),e=Pe(new M(e)),e instanceof M&&e.initialize()}e.level=this.level+1,$(n)||n<0?this.childNodes.push(e):this.childNodes.splice(n,0,e),this.updateLeafState()}insertBefore(e,n){let d;n&&(d=this.childNodes.indexOf(n)),this.insertChild(e,d)}insertAfter(e,n){let d;n&&(d=this.childNodes.indexOf(n),d!==-1&&(d+=1)),this.insertChild(e,d)}removeChild(e){const n=this.getChildren()||[],d=n.indexOf(e.data);d>-1&&n.splice(d,1);const o=this.childNodes.indexOf(e);o>-1&&(this.store&&this.store.deregisterNode(e),e.parent=null,this.childNodes.splice(o,1)),this.updateLeafState()}removeChildByData(e){let n=null;for(let d=0;d<this.childNodes.length;d++)if(this.childNodes[d].data===e){n=this.childNodes[d];break}n&&this.removeChild(n)}expand(e,n){const d=()=>{if(n){let o=this.parent;for(;o.level>0;)o.expanded=!0,o=o.parent}this.expanded=!0,e&&e(),this.childNodes.forEach(o=>{o.canFocus=!0})};this.shouldLoadData()?this.loadData(o=>{V(o)&&(this.checked?this.setChecked(!0,!0):this.store.checkStrictly||G(this),d())}):d()}doCreateChildren(e,n={}){e.forEach(d=>{this.insertChild(Object.assign({data:d},n),void 0,!0)})}collapse(){this.expanded=!1,this.childNodes.forEach(e=>{e.canFocus=!1})}shouldLoadData(){return this.store.lazy===!0&&this.store.load&&!this.loaded}updateLeafState(){if(this.store.lazy===!0&&this.loaded!==!0&&typeof this.isLeafByUser<"u"){this.isLeaf=this.isLeafByUser;return}const e=this.childNodes;if(!this.store.lazy||this.store.lazy===!0&&this.loaded===!0){this.isLeaf=!e||e.length===0;return}this.isLeaf=!1}setChecked(e,n,d,o){if(this.indeterminate=e==="half",this.checked=e===!0,this.store.checkStrictly)return;if(!(this.shouldLoadData()&&!this.store.checkDescendants)){const{all:a,allWithoutDisable:c}=ce(this.childNodes);!this.isLeaf&&!a&&c&&(this.checked=!1,e=!1);const l=()=>{if(n){const p=this.childNodes;for(let h=0,g=p.length;h<g;h++){const N=p[h];o=o||e!==!1;const C=N.disabled?N.checked:o;N.setChecked(C,n,!0,o)}const{half:r,all:f}=ce(p);f||(this.checked=f,this.indeterminate=r)}};if(this.shouldLoadData()){this.loadData(()=>{l(),G(this)},{checked:e!==!1});return}else l()}const s=this.parent;!s||s.level===0||d||G(s)}getChildren(e=!1){if(this.level===0)return this.data;const n=this.data;if(!n)return null;const d=this.store.props;let o="children";return d&&(o=d.children||"children"),$(n[o])&&(n[o]=null),e&&!n[o]&&(n[o]=[]),n[o]}updateChildren(){const e=this.getChildren()||[],n=this.childNodes.map(s=>s.data),d={},o=[];e.forEach((s,a)=>{const c=s[q];!!c&&n.findIndex(p=>p[q]===c)>=0?d[c]={index:a,data:s}:o.push({index:a,data:s})}),this.store.lazy||n.forEach(s=>{d[s[q]]||this.removeChildByData(s)}),o.forEach(({index:s,data:a})=>{this.insertChild({data:a},s)}),this.updateLeafState()}loadData(e,n={}){if(this.store.lazy===!0&&this.store.load&&!this.loaded&&(!this.loading||Object.keys(n).length)){this.loading=!0;const d=s=>{this.childNodes=[],this.doCreateChildren(s,n),this.loaded=!0,this.loading=!1,this.updateLeafState(),e&&e.call(this,s)},o=()=>{this.loading=!1};this.store.load(this,d,o)}else e&&e.call(this)}eachNode(e){const n=[this];for(;n.length;){const d=n.shift();n.unshift(...d.childNodes),e(d)}}reInitChecked(){this.store.checkStrictly||G(this)}}class dt{constructor(e){this.currentNode=null,this.currentNodeKey=null;for(const n in e)se(e,n)&&(this[n]=e[n]);this.nodesMap={}}initialize(){if(this.root=new M({data:this.data,store:this}),this.root.initialize(),this.lazy&&this.load){const e=this.load;e(this.root,n=>{this.root.doCreateChildren(n),this._initDefaultCheckedNodes()})}else this._initDefaultCheckedNodes()}filter(e){const n=this.filterNodeMethod,d=this.lazy,o=async function(s){const a=s.root?s.root.childNodes:s.childNodes;for(const[c,l]of a.entries())l.visible=n.call(l,e,l.data,l),c%80===0&&c>0&&await de(),await o(l);if(!s.visible&&a.length){let c=!0;c=!a.some(l=>l.visible),s.root?s.root.visible=c===!1:s.visible=c===!1}e&&s.visible&&!s.isLeaf&&(!d||s.loaded)&&s.expand()};o(this)}setData(e){e!==this.root.data?(this.nodesMap={},this.root.setData(e),this._initDefaultCheckedNodes(),this.setCurrentNodeKey(this.currentNodeKey)):this.root.updateChildren()}getNode(e){if(e instanceof M)return e;const n=qe(e)?ue(this.key,e):e;return this.nodesMap[n]||null}insertBefore(e,n){const d=this.getNode(n);d.parent.insertBefore({data:e},d)}insertAfter(e,n){const d=this.getNode(n);d.parent.insertAfter({data:e},d)}remove(e){const n=this.getNode(e);n&&n.parent&&(n===this.currentNode&&(this.currentNode=null),n.parent.removeChild(n))}append(e,n){const d=fe(n)?this.root:this.getNode(n);d&&d.insertChild({data:e})}_initDefaultCheckedNodes(){const e=this.defaultCheckedKeys||[],n=this.nodesMap;e.forEach(d=>{const o=n[d];o&&o.setChecked(!0,!this.checkStrictly)})}_initDefaultCheckedNode(e){(this.defaultCheckedKeys||[]).includes(e.key)&&e.setChecked(!0,!this.checkStrictly)}setDefaultCheckedKey(e){e!==this.defaultCheckedKeys&&(this.defaultCheckedKeys=e,this._initDefaultCheckedNodes())}registerNode(e){const n=this.key;!e||!e.data||(n?e.key!==void 0&&(this.nodesMap[e.key]=e):this.nodesMap[e.id]=e)}deregisterNode(e){!this.key||!e||!e.data||(e.childNodes.forEach(d=>{this.deregisterNode(d)}),delete this.nodesMap[e.key])}getCheckedNodes(e=!1,n=!1){const d=[],o=function(s){(s.root?s.root.childNodes:s.childNodes).forEach(c=>{(c.checked||n&&c.indeterminate)&&(!e||e&&c.isLeaf)&&d.push(c.data),o(c)})};return o(this),d}getCheckedKeys(e=!1){return this.getCheckedNodes(e).map(n=>(n||{})[this.key])}getHalfCheckedNodes(){const e=[],n=function(d){(d.root?d.root.childNodes:d.childNodes).forEach(s=>{s.indeterminate&&e.push(s.data),n(s)})};return n(this),e}getHalfCheckedKeys(){return this.getHalfCheckedNodes().map(e=>(e||{})[this.key])}_getAllNodes(){const e=[],n=this.nodesMap;for(const d in n)se(n,d)&&e.push(n[d]);return e}updateChildren(e,n){const d=this.nodesMap[e];if(!d)return;const o=d.childNodes;for(let s=o.length-1;s>=0;s--){const a=o[s];this.remove(a.data)}for(let s=0,a=n.length;s<a;s++){const c=n[s];this.append(c,d.data)}}_setCheckedKeys(e,n=!1,d){const o=this._getAllNodes().sort((l,p)=>l.level-p.level),s=Object.create(null),a=Object.keys(d);o.forEach(l=>l.setChecked(!1,!1));const c=l=>{l.childNodes.forEach(p=>{var r;s[p.data[e]]=!0,(r=p.childNodes)!=null&&r.length&&c(p)})};for(let l=0,p=o.length;l<p;l++){const r=o[l],f=r.data[e].toString();if(!a.includes(f)){r.checked&&!s[f]&&r.setChecked(!1,!1);continue}if(r.childNodes.length&&c(r),r.isLeaf||this.checkStrictly){r.setChecked(!0,!1);continue}if(r.setChecked(!0,!0),n){r.setChecked(!1,!1);const g=function(N){N.childNodes.forEach(v=>{v.isLeaf||v.setChecked(!1,!1),g(v)})};g(r)}}}setCheckedNodes(e,n=!1){const d=this.key,o={};e.forEach(s=>{o[(s||{})[d]]=!0}),this._setCheckedKeys(d,n,o)}setCheckedKeys(e,n=!1){this.defaultCheckedKeys=e;const d=this.key,o={};e.forEach(s=>{o[s]=!0}),this._setCheckedKeys(d,n,o)}setDefaultExpandedKeys(e){e=e||[],this.defaultExpandedKeys=e,e.forEach(n=>{const d=this.getNode(n);d&&d.expand(null,this.autoExpandParent)})}setChecked(e,n,d){const o=this.getNode(e);o&&o.setChecked(!!n,d)}getCurrentNode(){return this.currentNode}setCurrentNode(e){const n=this.currentNode;n&&(n.isCurrent=!1),this.currentNode=e,this.currentNode.isCurrent=!0}setUserCurrentNode(e,n=!0){const d=e[this.key],o=this.nodesMap[d];this.setCurrentNode(o),n&&this.currentNode.level>1&&this.currentNode.parent.expand(null,!0)}setCurrentNodeKey(e,n=!0){if(this.currentNodeKey=e,fe(e)){this.currentNode&&(this.currentNode.isCurrent=!1),this.currentNode=null;return}const d=this.getNode(e);d&&(this.setCurrentNode(d),n&&this.currentNode.level>1&&this.currentNode.parent.expand(null,!0))}}const at=J({name:"ElTreeNodeContent",props:{node:{type:Object,required:!0},renderContent:Function},setup(t){const e=H("tree"),n=j("NodeInstance"),d=j("RootTree");return()=>{const o=t.node,{data:s,store:a}=o;return t.renderContent?t.renderContent(pe,{_self:n,node:o,data:s,store:a}):he(d.ctx.slots,"default",{node:o,data:s},()=>[pe(ot,{tag:"span",truncated:!0,class:e.be("node","label")},()=>[o.label])])}}});var rt=te(at,[["__file","tree-node-content.vue"]]);function we(t){const e=j("TreeNodeMap",null),n={treeNodeExpand:d=>{t.node!==d&&t.node.collapse()},children:[]};return e&&e.children.push(n),Y("TreeNodeMap",n),{broadcastExpanded:d=>{if(t.accordion)for(const o of n.children)o.treeNodeExpand(d)}}}const xe=Symbol("dragEvents");function it({props:t,ctx:e,el$:n,dropIndicator$:d,store:o}){const s=H("tree"),a=D({showDropIndicator:!1,draggingNode:null,dropNode:null,allowDrop:!0,dropType:null});return Y(xe,{treeNodeDragStart:({event:r,treeNode:f})=>{if(ee(t.allowDrag)&&!t.allowDrag(f.node))return r.preventDefault(),!1;r.dataTransfer.effectAllowed="move";try{r.dataTransfer.setData("text/plain","")}catch{}a.value.draggingNode=f,e.emit("node-drag-start",f.node,r)},treeNodeDragOver:({event:r,treeNode:f})=>{const h=f,g=a.value.dropNode;g&&g.node.id!==h.node.id&&ne(g.$el,s.is("drop-inner"));const N=a.value.draggingNode;if(!N||!h)return;let C=!0,v=!0,E=!0,S=!0;ee(t.allowDrop)&&(C=t.allowDrop(N.node,h.node,"prev"),S=v=t.allowDrop(N.node,h.node,"inner"),E=t.allowDrop(N.node,h.node,"next")),r.dataTransfer.dropEffect=v||C||E?"move":"none",(C||v||E)&&(g==null?void 0:g.node.id)!==h.node.id&&(g&&e.emit("node-drag-leave",N.node,g.node,r),e.emit("node-drag-enter",N.node,h.node,r)),C||v||E?a.value.dropNode=h:a.value.dropNode=null,h.node.nextSibling===N.node&&(E=!1),h.node.previousSibling===N.node&&(C=!1),h.node.contains(N.node,!1)&&(v=!1),(N.node===h.node||N.node.contains(h.node))&&(C=!1,v=!1,E=!1);const T=h.$el.querySelector(`.${s.be("node","content")}`).getBoundingClientRect(),z=n.value.getBoundingClientRect();let m;const X=C?v?.25:E?.45:1:-1,Q=E?v?.75:C?.55:0:1;let F=-9999;const u=r.clientY-T.top;u<T.height*X?m="before":u>T.height*Q?m="after":v?m="inner":m="none";const y=h.$el.querySelector(`.${s.be("node","expand-icon")}`).getBoundingClientRect(),b=d.value;m==="before"?F=y.top-z.top:m==="after"&&(F=y.bottom-z.top),b.style.top=`${F}px`,b.style.left=`${y.right-z.left}px`,m==="inner"?je(h.$el,s.is("drop-inner")):ne(h.$el,s.is("drop-inner")),a.value.showDropIndicator=m==="before"||m==="after",a.value.allowDrop=a.value.showDropIndicator||S,a.value.dropType=m,e.emit("node-drag-over",N.node,h.node,r)},treeNodeDragEnd:r=>{const{draggingNode:f,dropType:h,dropNode:g}=a.value;if(r.preventDefault(),r.dataTransfer&&(r.dataTransfer.dropEffect="move"),f&&g){const N={data:f.node.data};h!=="none"&&f.node.remove(),h==="before"?g.node.parent.insertBefore(N,g.node):h==="after"?g.node.parent.insertAfter(N,g.node):h==="inner"&&g.node.insertChild(N),h!=="none"&&(o.value.registerNode(N),o.value.key&&f.node.eachNode(C=>{var v;(v=o.value.nodesMap[C.data[o.value.key]])==null||v.setChecked(C.checked,!o.value.checkStrictly)})),ne(g.$el,s.is("drop-inner")),e.emit("node-drag-end",f.node,g.node,h,r),h!=="none"&&e.emit("node-drop",f.node,g.node,h,r)}f&&!g&&e.emit("node-drag-end",f.node,null,h,r),a.value.showDropIndicator=!1,a.value.draggingNode=null,a.value.dropNode=null,a.value.allowDrop=!0}}),{dragState:a}}const lt=J({name:"ElTreeNode",components:{ElCollapseTransition:Ue,ElCheckbox:Ze,NodeContent:rt,ElIcon:Re,Loading:He},props:{node:{type:M,default:()=>({})},props:{type:Object,default:()=>({})},accordion:Boolean,renderContent:Function,renderAfterExpand:Boolean,showCheckbox:{type:Boolean,default:!1}},emits:["node-expand"],setup(t,e){const n=H("tree"),{broadcastExpanded:d}=we(t),o=j("RootTree"),s=D(!1),a=D(!1),c=D(),l=D(),p=D(),r=j(xe),f=De();Y("NodeInstance",f),t.node.expanded&&(s.value=!0,a.value=!0);const h=o.props.props.children||"children";x(()=>{var u;const y=(u=t.node.data)==null?void 0:u[h];return y&&[...y]},()=>{t.node.updateChildren()}),x(()=>t.node.indeterminate,u=>{C(t.node.checked,u)}),x(()=>t.node.checked,u=>{C(u,t.node.indeterminate)}),x(()=>t.node.childNodes.length,()=>t.node.reInitChecked()),x(()=>t.node.expanded,u=>{de(()=>s.value=u),u&&(a.value=!0)});const g=u=>ue(o.props.nodeKey,u.data),N=u=>{const y=t.props.class;if(!y)return{};let b;if(ee(y)){const{data:R}=u;b=y(R,u)}else b=y;return be(b)?{[b]:!0}:b},C=(u,y)=>{(c.value!==u||l.value!==y)&&o.ctx.emit("check-change",t.node.data,u,y),c.value=u,l.value=y},v=u=>{le(o.store,o.ctx.emit,()=>{var y;if((y=o==null?void 0:o.props)==null?void 0:y.nodeKey){const R=g(t.node);o.store.value.setCurrentNodeKey(R)}else o.store.value.setCurrentNode(t.node)}),o.currentNode.value=t.node,o.props.expandOnClickNode&&S(),(o.props.checkOnClickNode||t.node.isLeaf&&o.props.checkOnClickLeaf&&t.showCheckbox)&&!t.node.disabled&&T(!t.node.checked),o.ctx.emit("node-click",t.node.data,t.node,f,u)},E=u=>{var y;(y=o.instance.vnode.props)!=null&&y.onNodeContextmenu&&(u.stopPropagation(),u.preventDefault()),o.ctx.emit("node-contextmenu",u,t.node.data,t.node,f)},S=()=>{t.node.isLeaf||(s.value?(o.ctx.emit("node-collapse",t.node.data,t.node,f),t.node.collapse()):t.node.expand(()=>{e.emit("node-expand",t.node.data,t.node,f)}))},T=u=>{t.node.setChecked(u,!(o!=null&&o.props.checkStrictly)),de(()=>{const y=o.store.value;o.ctx.emit("check",t.node.data,{checkedNodes:y.getCheckedNodes(),checkedKeys:y.getCheckedKeys(),halfCheckedNodes:y.getHalfCheckedNodes(),halfCheckedKeys:y.getHalfCheckedKeys()})})};return{ns:n,node$:p,tree:o,expanded:s,childNodeRendered:a,oldChecked:c,oldIndeterminate:l,getNodeKey:g,getNodeClass:N,handleSelectChange:C,handleClick:v,handleContextMenu:E,handleExpandIconClick:S,handleCheckChange:T,handleChildNodeExpand:(u,y,b)=>{d(y),o.ctx.emit("node-expand",u,y,b)},handleDragStart:u=>{o.props.draggable&&r.treeNodeDragStart({event:u,treeNode:t})},handleDragOver:u=>{u.preventDefault(),o.props.draggable&&r.treeNodeDragOver({event:u,treeNode:{$el:p.value,node:t.node}})},handleDrop:u=>{u.preventDefault()},handleDragEnd:u=>{o.props.draggable&&r.treeNodeDragEnd(u)},CaretRight:We}}});function ct(t,e,n,d,o,s){const a=L("el-icon"),c=L("el-checkbox"),l=L("loading"),p=L("node-content"),r=L("el-tree-node"),f=L("el-collapse-transition");return ae((K(),P("div",{ref:"node$",class:w([t.ns.b("node"),t.ns.is("expanded",t.expanded),t.ns.is("current",t.node.isCurrent),t.ns.is("hidden",!t.node.visible),t.ns.is("focusable",!t.node.disabled),t.ns.is("checked",!t.node.disabled&&t.node.checked),t.getNodeClass(t.node)]),role:"treeitem",tabindex:"-1","aria-expanded":t.expanded,"aria-disabled":t.node.disabled,"aria-checked":t.node.checked,draggable:t.tree.props.draggable,"data-key":t.getNodeKey(t.node),onClick:A(t.handleClick,["stop"]),onContextmenu:t.handleContextMenu,onDragstart:A(t.handleDragStart,["stop"]),onDragover:A(t.handleDragOver,["stop"]),onDragend:A(t.handleDragEnd,["stop"]),onDrop:A(t.handleDrop,["stop"])},[ie("div",{class:w(t.ns.be("node","content")),style:Ce({paddingLeft:(t.node.level-1)*t.tree.props.indent+"px"})},[t.tree.props.icon||t.CaretRight?(K(),O(a,{key:0,class:w([t.ns.be("node","expand-icon"),t.ns.is("leaf",t.node.isLeaf),{expanded:!t.node.isLeaf&&t.expanded}]),onClick:A(t.handleExpandIconClick,["stop"])},{default:_(()=>[(K(),O(ve(t.tree.props.icon||t.CaretRight)))]),_:1},8,["class","onClick"])):W("v-if",!0),t.showCheckbox?(K(),O(c,{key:1,"model-value":t.node.checked,indeterminate:t.node.indeterminate,disabled:!!t.node.disabled,onClick:A(()=>{},["stop"]),onChange:t.handleCheckChange},null,8,["model-value","indeterminate","disabled","onClick","onChange"])):W("v-if",!0),t.node.loading?(K(),O(a,{key:2,class:w([t.ns.be("node","loading-icon"),t.ns.is("loading")])},{default:_(()=>[oe(l)]),_:1},8,["class"])):W("v-if",!0),oe(p,{node:t.node,"render-content":t.renderContent},null,8,["node","render-content"])],6),oe(f,null,{default:_(()=>[!t.renderAfterExpand||t.childNodeRendered?ae((K(),P("div",{key:0,class:w(t.ns.be("node","children")),role:"group","aria-expanded":t.expanded,onClick:A(()=>{},["stop"])},[(K(!0),P(Ke,null,Ee(t.node.childNodes,h=>(K(),O(r,{key:t.getNodeKey(h),"render-content":t.renderContent,"render-after-expand":t.renderAfterExpand,"show-checkbox":t.showCheckbox,node:h,accordion:t.accordion,props:t.props,onNodeExpand:t.handleChildNodeExpand},null,8,["render-content","render-after-expand","show-checkbox","node","accordion","props","onNodeExpand"]))),128))],10,["aria-expanded","onClick"])),[[re,t.expanded]]):W("v-if",!0)]),_:1})],42,["aria-expanded","aria-disabled","aria-checked","draggable","data-key","onClick","onContextmenu","onDragstart","onDragover","onDragend","onDrop"])),[[re,t.node.visible]])}var ht=te(lt,[["render",ct],["__file","tree-node.vue"]]);function ut({el$:t},e){const n=H("tree");Ne(()=>{o()}),ke(()=>{Array.from(t.value.querySelectorAll("input[type=checkbox]")).forEach(a=>{a.setAttribute("tabindex","-1")})}),Ge(t,"keydown",s=>{const a=s.target;if(!a.className.includes(n.b("node")))return;const c=s.code,l=Array.from(t.value.querySelectorAll(`.${n.is("focusable")}[role=treeitem]`)),p=l.indexOf(a);let r;if([B.up,B.down].includes(c)){if(s.preventDefault(),c===B.up){r=p===-1?0:p!==0?p-1:l.length-1;const h=r;for(;!e.value.getNode(l[r].dataset.key).canFocus;){if(r--,r===h){r=-1;break}r<0&&(r=l.length-1)}}else{r=p===-1?0:p<l.length-1?p+1:0;const h=r;for(;!e.value.getNode(l[r].dataset.key).canFocus;){if(r++,r===h){r=-1;break}r>=l.length&&(r=0)}}r!==-1&&l[r].focus()}[B.left,B.right].includes(c)&&(s.preventDefault(),a.click());const f=a.querySelector('[type="checkbox"]');[B.enter,B.numpadEnter,B.space].includes(c)&&f&&(s.preventDefault(),f.click())});const o=()=>{var s;const a=Array.from(t.value.querySelectorAll(`.${n.is("focusable")}[role=treeitem]`));Array.from(t.value.querySelectorAll("input[type=checkbox]")).forEach(p=>{p.setAttribute("tabindex","-1")});const l=t.value.querySelectorAll(`.${n.is("checked")}[role=treeitem]`);if(l.length){l[0].setAttribute("tabindex","0");return}(s=a[0])==null||s.setAttribute("tabindex","0")}}const ft=J({name:"ElTree",components:{ElTreeNode:ht},props:{data:{type:Array,default:()=>[]},emptyText:{type:String},renderAfterExpand:{type:Boolean,default:!0},nodeKey:String,checkStrictly:Boolean,defaultExpandAll:Boolean,expandOnClickNode:{type:Boolean,default:!0},checkOnClickNode:Boolean,checkOnClickLeaf:{type:Boolean,default:!0},checkDescendants:{type:Boolean,default:!1},autoExpandParent:{type:Boolean,default:!0},defaultCheckedKeys:Array,defaultExpandedKeys:Array,currentNodeKey:[String,Number],renderContent:Function,showCheckbox:{type:Boolean,default:!1},draggable:{type:Boolean,default:!1},allowDrag:Function,allowDrop:Function,props:{type:Object,default:()=>({children:"children",label:"label",disabled:"disabled"})},lazy:{type:Boolean,default:!1},highlightCurrent:Boolean,load:Function,filterNodeMethod:Function,accordion:Boolean,indent:{type:Number,default:18},icon:{type:Je}},emits:["check-change","current-change","node-click","node-contextmenu","node-collapse","node-expand","check","node-drag-start","node-drag-end","node-drop","node-drag-leave","node-drag-enter","node-drag-over"],setup(t,e){const{t:n}=Xe(),d=H("tree"),o=j(Ve,null),s=D(new dt({key:t.nodeKey,data:t.data,lazy:t.lazy,props:t.props,load:t.load,currentNodeKey:t.currentNodeKey,checkStrictly:t.checkStrictly,checkDescendants:t.checkDescendants,defaultCheckedKeys:t.defaultCheckedKeys,defaultExpandedKeys:t.defaultExpandedKeys,autoExpandParent:t.autoExpandParent,defaultExpandAll:t.defaultExpandAll,filterNodeMethod:t.filterNodeMethod}));s.value.initialize();const a=D(s.value.root),c=D(null),l=D(null),p=D(null),{broadcastExpanded:r}=we(t),{dragState:f}=it({props:t,ctx:e,el$:l,dropIndicator$:p,store:s});ut({el$:l},s);const h=ye(()=>{const{childNodes:i}=a.value,k=o?o.hasFilteredOptions!==0:!1;return(!i||i.length===0||i.every(({visible:I})=>!I))&&!k});x(()=>t.currentNodeKey,i=>{s.value.setCurrentNodeKey(i)}),x(()=>t.defaultCheckedKeys,i=>{s.value.setDefaultCheckedKey(i)}),x(()=>t.defaultExpandedKeys,i=>{s.value.setDefaultExpandedKeys(i)}),x(()=>t.data,i=>{s.value.setData(i)},{deep:!0}),x(()=>t.checkStrictly,i=>{s.value.checkStrictly=i});const g=i=>{if(!t.filterNodeMethod)throw new Error("[Tree] filterNodeMethod is required when filter");s.value.filter(i)},N=i=>ue(t.nodeKey,i.data),C=i=>{if(!t.nodeKey)throw new Error("[Tree] nodeKey is required in getNodePath");const k=s.value.getNode(i);if(!k)return[];const I=[k.data];let U=k.parent;for(;U&&U!==a.value;)I.push(U.data),U=U.parent;return I.reverse()},v=(i,k)=>s.value.getCheckedNodes(i,k),E=i=>s.value.getCheckedKeys(i),S=()=>{const i=s.value.getCurrentNode();return i?i.data:null},T=()=>{if(!t.nodeKey)throw new Error("[Tree] nodeKey is required in getCurrentKey");const i=S();return i?i[t.nodeKey]:null},z=(i,k)=>{if(!t.nodeKey)throw new Error("[Tree] nodeKey is required in setCheckedNodes");s.value.setCheckedNodes(i,k)},m=(i,k)=>{if(!t.nodeKey)throw new Error("[Tree] nodeKey is required in setCheckedKeys");s.value.setCheckedKeys(i,k)},X=(i,k,I)=>{s.value.setChecked(i,k,I)},Q=()=>s.value.getHalfCheckedNodes(),F=()=>s.value.getHalfCheckedKeys(),u=(i,k=!0)=>{if(!t.nodeKey)throw new Error("[Tree] nodeKey is required in setCurrentNode");le(s,e.emit,()=>{r(i),s.value.setUserCurrentNode(i,k)})},y=(i,k=!0)=>{if(!t.nodeKey)throw new Error("[Tree] nodeKey is required in setCurrentKey");le(s,e.emit,()=>{r(),s.value.setCurrentNodeKey(i,k)})},b=i=>s.value.getNode(i),R=i=>{s.value.remove(i)},Se=(i,k)=>{s.value.append(i,k)},Te=(i,k)=>{s.value.insertBefore(i,k)},Ie=(i,k)=>{s.value.insertAfter(i,k)},Ae=(i,k,I)=>{r(k),e.emit("node-expand",i,k,I)},Be=(i,k)=>{if(!t.nodeKey)throw new Error("[Tree] nodeKey is required in updateKeyChild");s.value.updateChildren(i,k)};return Y("RootTree",{ctx:e,props:t,store:s,root:a,currentNode:c,instance:De()}),Y(Qe,void 0),{ns:d,store:s,root:a,currentNode:c,dragState:f,el$:l,dropIndicator$:p,isEmpty:h,filter:g,getNodeKey:N,getNodePath:C,getCheckedNodes:v,getCheckedKeys:E,getCurrentNode:S,getCurrentKey:T,setCheckedNodes:z,setCheckedKeys:m,setChecked:X,getHalfCheckedNodes:Q,getHalfCheckedKeys:F,setCurrentNode:u,setCurrentKey:y,t:n,getNode:b,remove:R,append:Se,insertBefore:Te,insertAfter:Ie,handleNodeExpand:Ae,updateKeyChildren:Be}}});function pt(t,e,n,d,o,s){const a=L("el-tree-node");return K(),P("div",{ref:"el$",class:w([t.ns.b(),t.ns.is("dragging",!!t.dragState.draggingNode),t.ns.is("drop-not-allow",!t.dragState.allowDrop),t.ns.is("drop-inner",t.dragState.dropType==="inner"),{[t.ns.m("highlight-current")]:t.highlightCurrent}]),role:"tree"},[(K(!0),P(Ke,null,Ee(t.root.childNodes,c=>(K(),O(a,{key:t.getNodeKey(c),node:c,props:t.props,accordion:t.accordion,"render-after-expand":t.renderAfterExpand,"show-checkbox":t.showCheckbox,"render-content":t.renderContent,onNodeExpand:t.handleNodeExpand},null,8,["node","props","accordion","render-after-expand","show-checkbox","render-content","onNodeExpand"]))),128)),t.isEmpty?(K(),P("div",{key:0,class:w(t.ns.e("empty-block"))},[he(t.$slots,"empty",{},()=>{var c;return[ie("span",{class:w(t.ns.e("empty-text"))},Ye((c=t.emptyText)!=null?c:t.t("el.tree.emptyText")),3)]})],2)):W("v-if",!0),ae(ie("div",{ref:"dropIndicator$",class:w(t.ns.e("drop-indicator"))},null,2),[[re,t.dragState.showDropIndicator]])],2)}var gt=te(ft,[["render",pt],["__file","tree.vue"]]);const Ct=me(gt);export{Ct as E};