12 |
- import{bA as ee,ac as Ee,aH as De,m as se,t as U,ai as R,by as le,R as fe,ag as H,r as K,bx as Z,bv as Ke,aW as we,w,A as ce,ch as Se,a1 as I,P as te,Q as ne,o as D,b as q,d as oe,c as z,a as V,L as xe,C as S,E as T,e as j,f as _,D as Ae,G as pe,O as ge,ah as ye,av as Te,_ as Be,y as he,B as Ie,aG as Le,q as Oe,z as $e,X as Me}from"./index-312d0758.js";import{_ as ze}from"./index-33c06159.js";import{a as qe}from"./index-da3d4eae.js";import{E as Fe,i as Pe}from"./index-7588b595.js";import{_ as ae}from"./plugin-vue_export-helper-1cff8a04.js";import{u as je,E as B}from"./typescript-c7dac87b.js";import{f as Re}from"./constants-8ece7a3d.js";const F="$treeNodeId",ue=function(t,e){!e||e[F]||Object.defineProperty(e,F,{value:t.id,enumerable:!1,configurable:!1,writable:!1})},ie=function(t,e){return t?e[t]:e[F]},de=(t,e,o)=>{const d=t.value.currentNode;o();const n=t.value.currentNode;d!==n&&e("current-change",n?n.data:null,n)},re=t=>{let e=!0,o=!0,d=!0;for(let n=0,r=t.length;n<r;n++){const a=t[n];(a.checked!==!0||a.indeterminate)&&(e=!1,a.disabled||(d=!1)),(a.checked!==!1||a.indeterminate)&&(o=!1)}return{all:e,none:o,allWithoutDisable:d,half:!e&&!o}},Q=function(t){if(t.childNodes.length===0||t.loading)return;const{all:e,none:o,half:d}=re(t.childNodes);e?(t.checked=!0,t.indeterminate=!1):d?(t.checked=!1,t.indeterminate=!0):o&&(t.checked=!1,t.indeterminate=!1);const n=t.parent;!n||n.level===0||t.store.checkStrictly||Q(n)},Y=function(t,e){const o=t.store.props,d=t.data||{},n=o[e];if(typeof n=="function")return n(d,t);if(typeof n=="string")return d[n];if(typeof n>"u"){const r=d[e];return r===void 0?"":r}};let He=0;class L{constructor(e){this.id=He++,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 o in e)ee(e,o)&&(this[o]=e[o]);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 o=e.props;if(o&&typeof o.isLeaf<"u"){const r=Y(this,"isLeaf");typeof r=="boolean"&&(this.isLeafByUser=r)}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.expand(),Array.isArray(this.data)||ue(this,this.data),!this.data)return;const d=e.defaultExpandedKeys,n=e.key;n&&d&&d.includes(this.key)&&this.expand(null,e.autoExpandParent),n&&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){Array.isArray(e)||ue(this,e),this.data=e,this.childNodes=[];let o;this.level===0&&Array.isArray(this.data)?o=this.data:o=Y(this,"children")||[];for(let d=0,n=o.length;d<n;d++)this.insertChild({data:o[d]})}get label(){return Y(this,"label")}get key(){const e=this.store.key;return this.data?this.data[e]:null}get disabled(){return Y(this,"disabled")}get nextSibling(){const e=this.parent;if(e){const o=e.childNodes.indexOf(this);if(o>-1)return e.childNodes[o+1]}return null}get previousSibling(){const e=this.parent;if(e){const o=e.childNodes.indexOf(this);if(o>-1)return o>0?e.childNodes[o-1]:null}return null}contains(e,o=!0){return(this.childNodes||[]).some(d=>d===e||o&&d.contains(e))}remove(){const e=this.parent;e&&e.removeChild(this)}insertChild(e,o,d){if(!e)throw new Error("InsertChild error: child is required.");if(!(e instanceof L)){if(!d){const n=this.getChildren(!0);n.includes(e.data)||(typeof o>"u"||o<0?n.push(e.data):n.splice(o,0,e.data))}Object.assign(e,{parent:this,store:this.store}),e=Ee(new L(e)),e instanceof L&&e.initialize()}e.level=this.level+1,typeof o>"u"||o<0?this.childNodes.push(e):this.childNodes.splice(o,0,e),this.updateLeafState()}insertBefore(e,o){let d;o&&(d=this.childNodes.indexOf(o)),this.insertChild(e,d)}insertAfter(e,o){let d;o&&(d=this.childNodes.indexOf(o),d!==-1&&(d+=1)),this.insertChild(e,d)}removeChild(e){const o=this.getChildren()||[],d=o.indexOf(e.data);d>-1&&o.splice(d,1);const n=this.childNodes.indexOf(e);n>-1&&(this.store&&this.store.deregisterNode(e),e.parent=null,this.childNodes.splice(n,1)),this.updateLeafState()}removeChildByData(e){let o=null;for(let d=0;d<this.childNodes.length;d++)if(this.childNodes[d].data===e){o=this.childNodes[d];break}o&&this.removeChild(o)}expand(e,o){const d=()=>{if(o){let n=this.parent;for(;n.level>0;)n.expanded=!0,n=n.parent}this.expanded=!0,e&&e(),this.childNodes.forEach(n=>{n.canFocus=!0})};this.shouldLoadData()?this.loadData(n=>{Array.isArray(n)&&(this.checked?this.setChecked(!0,!0):this.store.checkStrictly||Q(this),d())}):d()}doCreateChildren(e,o={}){e.forEach(d=>{this.insertChild(Object.assign({data:d},o),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,o,d,n){if(this.indeterminate=e==="half",this.checked=e===!0,this.store.checkStrictly)return;if(!(this.shouldLoadData()&&!this.store.checkDescendants)){const{all:a,allWithoutDisable:i}=re(this.childNodes);!this.isLeaf&&!a&&i&&(this.checked=!1,e=!1);const f=()=>{if(o){const N=this.childNodes;for(let s=0,p=N.length;s<p;s++){const y=N[s];n=n||e!==!1;const k=y.disabled?y.checked:n;y.setChecked(k,o,!0,n)}const{half:h,all:c}=re(N);c||(this.checked=c,this.indeterminate=h)}};if(this.shouldLoadData()){this.loadData(()=>{f(),Q(this)},{checked:e!==!1});return}else f()}const r=this.parent;!r||r.level===0||d||Q(r)}getChildren(e=!1){if(this.level===0)return this.data;const o=this.data;if(!o)return null;const d=this.store.props;let n="children";return d&&(n=d.children||"children"),o[n]===void 0&&(o[n]=null),e&&!o[n]&&(o[n]=[]),o[n]}updateChildren(){const e=this.getChildren()||[],o=this.childNodes.map(r=>r.data),d={},n=[];e.forEach((r,a)=>{const i=r[F];!!i&&o.findIndex(N=>N[F]===i)>=0?d[i]={index:a,data:r}:n.push({index:a,data:r})}),this.store.lazy||o.forEach(r=>{d[r[F]]||this.removeChildByData(r)}),n.forEach(({index:r,data:a})=>{this.insertChild({data:a},r)}),this.updateLeafState()}loadData(e,o={}){if(this.store.lazy===!0&&this.store.load&&!this.loaded&&(!this.loading||Object.keys(o).length)){this.loading=!0;const d=n=>{this.childNodes=[],this.doCreateChildren(n,o),this.loaded=!0,this.loading=!1,this.updateLeafState(),e&&e.call(this,n)};this.store.load(this,d)}else e&&e.call(this)}}class Ue{constructor(e){this.currentNode=null,this.currentNodeKey=null;for(const o in e)ee(e,o)&&(this[o]=e[o]);this.nodesMap={}}initialize(){if(this.root=new L({data:this.data,store:this}),this.root.initialize(),this.lazy&&this.load){const e=this.load;e(this.root,o=>{this.root.doCreateChildren(o),this._initDefaultCheckedNodes()})}else this._initDefaultCheckedNodes()}filter(e){const o=this.filterNodeMethod,d=this.lazy,n=function(r){const a=r.root?r.root.childNodes:r.childNodes;if(a.forEach(i=>{i.visible=o.call(i,e,i.data,i),n(i)}),!r.visible&&a.length){let i=!0;i=!a.some(f=>f.visible),r.root?r.root.visible=i===!1:r.visible=i===!1}e&&r.visible&&!r.isLeaf&&(!d||r.loaded)&&r.expand()};n(this)}setData(e){e!==this.root.data?(this.root.setData(e),this._initDefaultCheckedNodes()):this.root.updateChildren()}getNode(e){if(e instanceof L)return e;const o=De(e)?ie(this.key,e):e;return this.nodesMap[o]||null}insertBefore(e,o){const d=this.getNode(o);d.parent.insertBefore({data:e},d)}insertAfter(e,o){const d=this.getNode(o);d.parent.insertAfter({data:e},d)}remove(e){const o=this.getNode(e);o&&o.parent&&(o===this.currentNode&&(this.currentNode=null),o.parent.removeChild(o))}append(e,o){const d=o?this.getNode(o):this.root;d&&d.insertChild({data:e})}_initDefaultCheckedNodes(){const e=this.defaultCheckedKeys||[],o=this.nodesMap;e.forEach(d=>{const n=o[d];n&&n.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 o=this.key;!e||!e.data||(o?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,o=!1){const d=[],n=function(r){(r.root?r.root.childNodes:r.childNodes).forEach(i=>{(i.checked||o&&i.indeterminate)&&(!e||e&&i.isLeaf)&&d.push(i.data),n(i)})};return n(this),d}getCheckedKeys(e=!1){return this.getCheckedNodes(e).map(o=>(o||{})[this.key])}getHalfCheckedNodes(){const e=[],o=function(d){(d.root?d.root.childNodes:d.childNodes).forEach(r=>{r.indeterminate&&e.push(r.data),o(r)})};return o(this),e}getHalfCheckedKeys(){return this.getHalfCheckedNodes().map(e=>(e||{})[this.key])}_getAllNodes(){const e=[],o=this.nodesMap;for(const d in o)ee(o,d)&&e.push(o[d]);return e}updateChildren(e,o){const d=this.nodesMap[e];if(!d)return;const n=d.childNodes;for(let r=n.length-1;r>=0;r--){const a=n[r];this.remove(a.data)}for(let r=0,a=o.length;r<a;r++){const i=o[r];this.append(i,d.data)}}_setCheckedKeys(e,o=!1,d){const n=this._getAllNodes().sort((f,N)=>f.level-N.level),r=Object.create(null),a=Object.keys(d);n.forEach(f=>f.setChecked(!1,!1));const i=f=>{f.childNodes.forEach(N=>{var h;r[N.data[e]]=!0,(h=N.childNodes)!=null&&h.length&&i(N)})};for(let f=0,N=n.length;f<N;f++){const h=n[f],c=h.data[e].toString();if(!a.includes(c)){h.checked&&!r[c]&&h.setChecked(!1,!1);continue}if(h.childNodes.length&&i(h),h.isLeaf||this.checkStrictly){h.setChecked(!0,!1);continue}if(h.setChecked(!0,!0),o){h.setChecked(!1,!1);const p=function(y){y.childNodes.forEach(v=>{v.isLeaf||v.setChecked(!1,!1),p(v)})};p(h)}}}setCheckedNodes(e,o=!1){const d=this.key,n={};e.forEach(r=>{n[(r||{})[d]]=!0}),this._setCheckedKeys(d,o,n)}setCheckedKeys(e,o=!1){this.defaultCheckedKeys=e;const d=this.key,n={};e.forEach(r=>{n[r]=!0}),this._setCheckedKeys(d,o,n)}setDefaultExpandedKeys(e){e=e||[],this.defaultExpandedKeys=e,e.forEach(o=>{const d=this.getNode(o);d&&d.expand(null,this.autoExpandParent)})}setChecked(e,o,d){const n=this.getNode(e);n&&n.setChecked(!!o,d)}getCurrentNode(){return this.currentNode}setCurrentNode(e){const o=this.currentNode;o&&(o.isCurrent=!1),this.currentNode=e,this.currentNode.isCurrent=!0}setUserCurrentNode(e,o=!0){const d=e[this.key],n=this.nodesMap[d];this.setCurrentNode(n),o&&this.currentNode.level>1&&this.currentNode.parent.expand(null,!0)}setCurrentNodeKey(e,o=!0){if(e==null){this.currentNode&&(this.currentNode.isCurrent=!1),this.currentNode=null;return}const d=this.getNode(e);d&&(this.setCurrentNode(d),o&&this.currentNode.level>1&&this.currentNode.parent.expand(null,!0))}}const We=se({name:"ElTreeNodeContent",props:{node:{type:Object,required:!0},renderContent:Function},setup(t){const e=U("tree"),o=R("NodeInstance"),d=R("RootTree");return()=>{const n=t.node,{data:r,store:a}=n;return t.renderContent?t.renderContent(le,{_self:o,node:n,data:r,store:a}):fe(d.ctx.slots,"default",{node:n,data:r},()=>[le("span",{class:e.be("node","label")},[n.label])])}}});var Ge=ae(We,[["__file","tree-node-content.vue"]]);function Ne(t){const e=R("TreeNodeMap",null),o={treeNodeExpand:d=>{t.node!==d&&t.node.collapse()},children:[]};return e&&e.children.push(o),H("TreeNodeMap",o),{broadcastExpanded:d=>{if(t.accordion)for(const n of o.children)n.treeNodeExpand(d)}}}const Ce=Symbol("dragEvents");function Ye({props:t,ctx:e,el$:o,dropIndicator$:d,store:n}){const r=U("tree"),a=K({showDropIndicator:!1,draggingNode:null,dropNode:null,allowDrop:!0,dropType:null});return H(Ce,{treeNodeDragStart:({event:h,treeNode:c})=>{if(typeof t.allowDrag=="function"&&!t.allowDrag(c.node))return h.preventDefault(),!1;h.dataTransfer.effectAllowed="move";try{h.dataTransfer.setData("text/plain","")}catch{}a.value.draggingNode=c,e.emit("node-drag-start",c.node,h)},treeNodeDragOver:({event:h,treeNode:c})=>{const s=c,p=a.value.dropNode;p&&p.node.id!==s.node.id&&Z(p.$el,r.is("drop-inner"));const y=a.value.draggingNode;if(!y||!s)return;let k=!0,v=!0,b=!0,A=!0;typeof t.allowDrop=="function"&&(k=t.allowDrop(y.node,s.node,"prev"),A=v=t.allowDrop(y.node,s.node,"inner"),b=t.allowDrop(y.node,s.node,"next")),h.dataTransfer.dropEffect=v||k||b?"move":"none",(k||v||b)&&(p==null?void 0:p.node.id)!==s.node.id&&(p&&e.emit("node-drag-leave",y.node,p.node,h),e.emit("node-drag-enter",y.node,s.node,h)),k||v||b?a.value.dropNode=s:a.value.dropNode=null,s.node.nextSibling===y.node&&(b=!1),s.node.previousSibling===y.node&&(k=!1),s.node.contains(y.node,!1)&&(v=!1),(y.node===s.node||y.node.contains(s.node))&&(k=!1,v=!1,b=!1);const x=s.$el.querySelector(`.${r.be("node","content")}`).getBoundingClientRect(),O=o.value.getBoundingClientRect();let E;const W=k?v?.25:b?.45:1:-1,G=b?v?.75:k?.55:0:1;let $=-9999;const u=h.clientY-x.top;u<x.height*W?E="before":u>x.height*G?E="after":v?E="inner":E="none";const C=s.$el.querySelector(`.${r.be("node","expand-icon")}`).getBoundingClientRect(),m=d.value;E==="before"?$=C.top-O.top:E==="after"&&($=C.bottom-O.top),m.style.top=`${$}px`,m.style.left=`${C.right-O.left}px`,E==="inner"?Ke(s.$el,r.is("drop-inner")):Z(s.$el,r.is("drop-inner")),a.value.showDropIndicator=E==="before"||E==="after",a.value.allowDrop=a.value.showDropIndicator||A,a.value.dropType=E,e.emit("node-drag-over",y.node,s.node,h)},treeNodeDragEnd:h=>{const{draggingNode:c,dropType:s,dropNode:p}=a.value;if(h.preventDefault(),h.dataTransfer.dropEffect="move",c&&p){const y={data:c.node.data};s!=="none"&&c.node.remove(),s==="before"?p.node.parent.insertBefore(y,p.node):s==="after"?p.node.parent.insertAfter(y,p.node):s==="inner"&&p.node.insertChild(y),s!=="none"&&n.value.registerNode(y),Z(p.$el,r.is("drop-inner")),e.emit("node-drag-end",c.node,p.node,s,h),s!=="none"&&e.emit("node-drop",c.node,p.node,s,h)}c&&!p&&e.emit("node-drag-end",c.node,null,s,h),a.value.showDropIndicator=!1,a.value.draggingNode=null,a.value.dropNode=null,a.value.allowDrop=!0}}),{dragState:a}}const Qe=se({name:"ElTreeNode",components:{ElCollapseTransition:ze,ElCheckbox:qe,NodeContent:Ge,ElIcon:Fe,Loading:we},props:{node:{type:L,default:()=>({})},props:{type:Object,default:()=>({})},accordion:Boolean,renderContent:Function,renderAfterExpand:Boolean,showCheckbox:{type:Boolean,default:!1}},emits:["node-expand"],setup(t,e){const o=U("tree"),{broadcastExpanded:d}=Ne(t),n=R("RootTree"),r=K(!1),a=K(!1),i=K(null),f=K(null),N=K(null),h=R(Ce),c=ye();H("NodeInstance",c),t.node.expanded&&(r.value=!0,a.value=!0);const s=n.props.props.children||"children";w(()=>{const u=t.node.data[s];return u&&[...u]},()=>{t.node.updateChildren()}),w(()=>t.node.indeterminate,u=>{k(t.node.checked,u)}),w(()=>t.node.checked,u=>{k(u,t.node.indeterminate)}),w(()=>t.node.expanded,u=>{ce(()=>r.value=u),u&&(a.value=!0)});const p=u=>ie(n.props.nodeKey,u.data),y=u=>{const C=t.props.class;if(!C)return{};let m;if(Te(C)){const{data:J}=u;m=C(J,u)}else m=C;return Be(m)?{[m]:!0}:m},k=(u,C)=>{(i.value!==u||f.value!==C)&&n.ctx.emit("check-change",t.node.data,u,C),i.value=u,f.value=C},v=u=>{de(n.store,n.ctx.emit,()=>n.store.value.setCurrentNode(t.node)),n.currentNode.value=t.node,n.props.expandOnClickNode&&A(),n.props.checkOnClickNode&&!t.node.disabled&&x(null,{target:{checked:!t.node.checked}}),n.ctx.emit("node-click",t.node.data,t.node,c,u)},b=u=>{n.instance.vnode.props.onNodeContextmenu&&(u.stopPropagation(),u.preventDefault()),n.ctx.emit("node-contextmenu",u,t.node.data,t.node,c)},A=()=>{t.node.isLeaf||(r.value?(n.ctx.emit("node-collapse",t.node.data,t.node,c),t.node.collapse()):(t.node.expand(),e.emit("node-expand",t.node.data,t.node,c)))},x=(u,C)=>{t.node.setChecked(C.target.checked,!n.props.checkStrictly),ce(()=>{const m=n.store.value;n.ctx.emit("check",t.node.data,{checkedNodes:m.getCheckedNodes(),checkedKeys:m.getCheckedKeys(),halfCheckedNodes:m.getHalfCheckedNodes(),halfCheckedKeys:m.getHalfCheckedKeys()})})};return{ns:o,node$:N,tree:n,expanded:r,childNodeRendered:a,oldChecked:i,oldIndeterminate:f,getNodeKey:p,getNodeClass:y,handleSelectChange:k,handleClick:v,handleContextMenu:b,handleExpandIconClick:A,handleCheckChange:x,handleChildNodeExpand:(u,C,m)=>{d(C),n.ctx.emit("node-expand",u,C,m)},handleDragStart:u=>{n.props.draggable&&h.treeNodeDragStart({event:u,treeNode:t})},handleDragOver:u=>{u.preventDefault(),n.props.draggable&&h.treeNodeDragOver({event:u,treeNode:{$el:N.value,node:t.node}})},handleDrop:u=>{u.preventDefault()},handleDragEnd:u=>{n.props.draggable&&h.treeNodeDragEnd(u)},CaretRight:Se}}}),Xe=["aria-expanded","aria-disabled","aria-checked","draggable","data-key"],Je=["aria-expanded"];function Ze(t,e,o,d,n,r){const a=I("el-icon"),i=I("el-checkbox"),f=I("loading"),N=I("node-content"),h=I("el-tree-node"),c=I("el-collapse-transition");return te((D(),q("div",{ref:"node$",class:S([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:e[1]||(e[1]=T((...s)=>t.handleClick&&t.handleClick(...s),["stop"])),onContextmenu:e[2]||(e[2]=(...s)=>t.handleContextMenu&&t.handleContextMenu(...s)),onDragstart:e[3]||(e[3]=T((...s)=>t.handleDragStart&&t.handleDragStart(...s),["stop"])),onDragover:e[4]||(e[4]=T((...s)=>t.handleDragOver&&t.handleDragOver(...s),["stop"])),onDragend:e[5]||(e[5]=T((...s)=>t.handleDragEnd&&t.handleDragEnd(...s),["stop"])),onDrop:e[6]||(e[6]=T((...s)=>t.handleDrop&&t.handleDrop(...s),["stop"]))},[oe("div",{class:S(t.ns.be("node","content")),style:Ae({paddingLeft:(t.node.level-1)*t.tree.props.indent+"px"})},[t.tree.props.icon||t.CaretRight?(D(),z(a,{key:0,class:S([t.ns.be("node","expand-icon"),t.ns.is("leaf",t.node.isLeaf),{expanded:!t.node.isLeaf&&t.expanded}]),onClick:T(t.handleExpandIconClick,["stop"])},{default:V(()=>[(D(),z(xe(t.tree.props.icon||t.CaretRight)))]),_:1},8,["class","onClick"])):j("v-if",!0),t.showCheckbox?(D(),z(i,{key:1,"model-value":t.node.checked,indeterminate:t.node.indeterminate,disabled:!!t.node.disabled,onClick:e[0]||(e[0]=T(()=>{},["stop"])),onChange:t.handleCheckChange},null,8,["model-value","indeterminate","disabled","onChange"])):j("v-if",!0),t.node.loading?(D(),z(a,{key:2,class:S([t.ns.be("node","loading-icon"),t.ns.is("loading")])},{default:V(()=>[_(f)]),_:1},8,["class"])):j("v-if",!0),_(N,{node:t.node,"render-content":t.renderContent},null,8,["node","render-content"])],6),_(c,null,{default:V(()=>[!t.renderAfterExpand||t.childNodeRendered?te((D(),q("div",{key:0,class:S(t.ns.be("node","children")),role:"group","aria-expanded":t.expanded},[(D(!0),q(pe,null,ge(t.node.childNodes,s=>(D(),z(h,{key:t.getNodeKey(s),"render-content":t.renderContent,"render-after-expand":t.renderAfterExpand,"show-checkbox":t.showCheckbox,node:s,accordion:t.accordion,props:t.props,onNodeExpand:t.handleChildNodeExpand},null,8,["render-content","render-after-expand","show-checkbox","node","accordion","props","onNodeExpand"]))),128))],10,Je)),[[ne,t.expanded]]):j("v-if",!0)]),_:1})],42,Xe)),[[ne,t.node.visible]])}var Ve=ae(Qe,[["render",Ze],["__file","tree-node.vue"]]);function _e({el$:t},e){const o=U("tree"),d=he([]),n=he([]);Ie(()=>{a()}),Le(()=>{d.value=Array.from(t.value.querySelectorAll("[role=treeitem]")),n.value=Array.from(t.value.querySelectorAll("input[type=checkbox]"))}),w(n,i=>{i.forEach(f=>{f.setAttribute("tabindex","-1")})}),je(t,"keydown",i=>{const f=i.target;if(!f.className.includes(o.b("node")))return;const N=i.code;d.value=Array.from(t.value.querySelectorAll(`.${o.is("focusable")}[role=treeitem]`));const h=d.value.indexOf(f);let c;if([B.up,B.down].includes(N)){if(i.preventDefault(),N===B.up){c=h===-1?0:h!==0?h-1:d.value.length-1;const p=c;for(;!e.value.getNode(d.value[c].dataset.key).canFocus;){if(c--,c===p){c=-1;break}c<0&&(c=d.value.length-1)}}else{c=h===-1?0:h<d.value.length-1?h+1:0;const p=c;for(;!e.value.getNode(d.value[c].dataset.key).canFocus;){if(c++,c===p){c=-1;break}c>=d.value.length&&(c=0)}}c!==-1&&d.value[c].focus()}[B.left,B.right].includes(N)&&(i.preventDefault(),f.click());const s=f.querySelector('[type="checkbox"]');[B.enter,B.space].includes(N)&&s&&(i.preventDefault(),s.click())});const a=()=>{var i;d.value=Array.from(t.value.querySelectorAll(`.${o.is("focusable")}[role=treeitem]`)),n.value=Array.from(t.value.querySelectorAll("input[type=checkbox]"));const f=t.value.querySelectorAll(`.${o.is("checked")}[role=treeitem]`);if(f.length){f[0].setAttribute("tabindex","0");return}(i=d.value[0])==null||i.setAttribute("tabindex","0")}}const et=se({name:"ElTree",components:{ElTreeNode:Ve},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,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:Pe}},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:o}=Oe(),d=U("tree"),n=K(new Ue({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}));n.value.initialize();const r=K(n.value.root),a=K(null),i=K(null),f=K(null),{broadcastExpanded:N}=Ne(t),{dragState:h}=Ye({props:t,ctx:e,el$:i,dropIndicator$:f,store:n});_e({el$:i},n);const c=$e(()=>{const{childNodes:l}=r.value;return!l||l.length===0||l.every(({visible:g})=>!g)});w(()=>t.currentNodeKey,l=>{n.value.setCurrentNodeKey(l)}),w(()=>t.defaultCheckedKeys,l=>{n.value.setDefaultCheckedKey(l)}),w(()=>t.defaultExpandedKeys,l=>{n.value.setDefaultExpandedKeys(l)}),w(()=>t.data,l=>{n.value.setData(l)},{deep:!0}),w(()=>t.checkStrictly,l=>{n.value.checkStrictly=l});const s=l=>{if(!t.filterNodeMethod)throw new Error("[Tree] filterNodeMethod is required when filter");n.value.filter(l)},p=l=>ie(t.nodeKey,l.data),y=l=>{if(!t.nodeKey)throw new Error("[Tree] nodeKey is required in getNodePath");const g=n.value.getNode(l);if(!g)return[];const M=[g.data];let P=g.parent;for(;P&&P!==r.value;)M.push(P.data),P=P.parent;return M.reverse()},k=(l,g)=>n.value.getCheckedNodes(l,g),v=l=>n.value.getCheckedKeys(l),b=()=>{const l=n.value.getCurrentNode();return l?l.data:null},A=()=>{if(!t.nodeKey)throw new Error("[Tree] nodeKey is required in getCurrentKey");const l=b();return l?l[t.nodeKey]:null},x=(l,g)=>{if(!t.nodeKey)throw new Error("[Tree] nodeKey is required in setCheckedNodes");n.value.setCheckedNodes(l,g)},O=(l,g)=>{if(!t.nodeKey)throw new Error("[Tree] nodeKey is required in setCheckedKeys");n.value.setCheckedKeys(l,g)},E=(l,g,M)=>{n.value.setChecked(l,g,M)},W=()=>n.value.getHalfCheckedNodes(),G=()=>n.value.getHalfCheckedKeys(),$=(l,g=!0)=>{if(!t.nodeKey)throw new Error("[Tree] nodeKey is required in setCurrentNode");de(n,e.emit,()=>n.value.setUserCurrentNode(l,g))},u=(l,g=!0)=>{if(!t.nodeKey)throw new Error("[Tree] nodeKey is required in setCurrentKey");de(n,e.emit,()=>n.value.setCurrentNodeKey(l,g))},C=l=>n.value.getNode(l),m=l=>{n.value.remove(l)},J=(l,g)=>{n.value.append(l,g)},ke=(l,g)=>{n.value.insertBefore(l,g)},ve=(l,g)=>{n.value.insertAfter(l,g)},me=(l,g,M)=>{N(g),e.emit("node-expand",l,g,M)},be=(l,g)=>{if(!t.nodeKey)throw new Error("[Tree] nodeKey is required in updateKeyChild");n.value.updateChildren(l,g)};return H("RootTree",{ctx:e,props:t,store:n,root:r,currentNode:a,instance:ye()}),H(Re,void 0),{ns:d,store:n,root:r,currentNode:a,dragState:h,el$:i,dropIndicator$:f,isEmpty:c,filter:s,getNodeKey:p,getNodePath:y,getCheckedNodes:k,getCheckedKeys:v,getCurrentNode:b,getCurrentKey:A,setCheckedNodes:x,setCheckedKeys:O,setChecked:E,getHalfCheckedNodes:W,getHalfCheckedKeys:G,setCurrentNode:$,setCurrentKey:u,t:o,getNode:C,remove:m,append:J,insertBefore:ke,insertAfter:ve,handleNodeExpand:me,updateKeyChildren:be}}});function tt(t,e,o,d,n,r){const a=I("el-tree-node");return D(),q("div",{ref:"el$",class:S([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"},[(D(!0),q(pe,null,ge(t.root.childNodes,i=>(D(),z(a,{key:t.getNodeKey(i),node:i,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?(D(),q("div",{key:0,class:S(t.ns.e("empty-block"))},[fe(t.$slots,"empty",{},()=>{var i;return[oe("span",{class:S(t.ns.e("empty-text"))},Me((i=t.emptyText)!=null?i:t.t("el.tree.emptyText")),3)]})],2)):j("v-if",!0),te(oe("div",{ref:"dropIndicator$",class:S(t.ns.e("drop-indicator"))},null,2),[[ne,t.dragState.showDropIndicator]])],2)}var X=ae(et,[["render",tt],["__file","tree.vue"]]);X.install=t=>{t.component(X.name,X)};const nt=X,ct=nt;export{ct as E,nt as _};
|