import{$ as e,o as t,d as s,w as i,e as d,H as h,X as r,h as o}from"./index-C0ioWTxp.js";import{_ as n}from"./_plugin-vue_export-helper.BCo6x5W8.js";const a="$treeNodeId",l=function(e,t){t&&!t[a]&&Object.defineProperty(t,a,{value:e.id,enumerable:!1,configurable:!1,writable:!1})},c=function(e,t){return t?e?t[e]:t[a]:null},u=function(e){for(let t=1,s=arguments.length;t<s;t++){let s=arguments[t]||{};for(let t in s)if(s.hasOwnProperty(t)){let i=s[t];void 0!==i&&(e[t]=i)}}return e},f=function(e){let t=!0,s=!0,i=!0;for(let d=0,h=e.length;d<h;d++){const h=e[d];(!0!==h.checked||h.indeterminate)&&(t=!1,h.disabled||(i=!1)),(!1!==h.checked||h.indeterminate)&&(s=!1)}return{all:t,none:s,allWithoutDisable:i,half:!t&&!s}},p=function(e){if(!e||0===e.childNodesId.length)return;let t=e.getChildNodes(e.childNodesId);const{all:s,none:i,half:d}=f(t);s?(e.checked=!0,e.indeterminate=!1):d?(e.checked=!1,e.indeterminate=!0):i&&(e.checked=!1,e.indeterminate=!1);let h=e.getParent(e.parentId);h&&0!==h.level&&(e.store().checkStrictly||p(h))},y=function(e,t){const s=e.store().props,i=e.data||{},d=s[t];if("function"==typeof d)return d(i,e);if("string"==typeof d)return i[d];if(void 0===d){const e=i[t];return void 0===e?"":e}},k=function(e){let t=e;return function(){return t}};let N=0;class C{constructor(e){this.time=(new Date).getTime(),this.id=N++,this.text=null,this.checked=!1,this.indeterminate=!1,this.data=null,this.expanded=!1,this.parentId=null,this.visible=!0,this.isCurrent=!1;for(let t in e)e.hasOwnProperty(t)&&("store"===t?this.store=k(e[t]):this[t]=e[t]);if(!this.store())throw new Error("[Node]store is required!");this.level=0,this.loaded=!1,this.childNodesId=[],this.loading=!1,this.label=y(this,"label"),this.key=this._getKey(),this.disabled=y(this,"disabled"),this.nextSibling=null,this.previousSibling=null,this.icon="",this._handleParentAndLevel(),this._handleProps(),this._handleExpand(),this._handleCurrent(),this.store().lazy&&this.store()._initDefaultCheckedNode(this),this.updateLeafState()}_getKey(){if(!this.data||Array.isArray(this.data))return null;if("object"==typeof this.data){const e=this.store().key,t=this.data[e];if(void 0===t)throw new Error(`您配置的node-key为"${e}",但数据中并未找到对应"${e}"属性的值,请检查node-key的配置是否合理`);return t}throw new Error("不合法的data数据")}_handleParentAndLevel(){if(null!==this.parentId){let e=this.getParent(this.parentId);if(this.store().isInjectParentInNode&&(this.parent=e),e){const t=e.getChildNodes(e.childNodesId),s=e.childNodesId.indexOf(this.key);this.nextSibling=s>-1?t[s+1]:null,this.previousSibling=s>0?t[s-1]:null}else e={level:0};this.level=e.level+1}}_handleProps(){const e=this.store().props;if(this.store().showNodeIcon&&(e&&void 0!==e.icon?this.icon=y(this,"icon"):console.warn('请配置props属性中的"icon"字段')),this.store().registerNode(this),e&&void 0!==e.isLeaf){const e=y(this,"isLeaf");"boolean"==typeof e&&(this.isLeafByUser=e)}}_handleExpand(){if(!0!==this.store().lazy&&this.data?(this.setData(this.data),this.store().defaultExpandAll&&(this.expanded=!0)):this.level>0&&this.store().lazy&&this.store().defaultExpandAll&&this.expand(),Array.isArray(this.data)||l(this,this.data),!this.data)return;const e=this.store().defaultExpandedKeys;this.store().key&&e&&-1!==e.indexOf(this.key)&&this.expand(null,this.store().autoExpandparent)}_handleCurrent(){this.store().key&&void 0!==this.store().currentNodeKey&&this.key===this.store().currentNodeKey&&(this.store().currentNode=this,this.store().currentNode.isCurrent=!0)}destroyStore(){}setData(e){let t;Array.isArray(e)||l(this,e),this.data=e,this.childNodesId=[],t=0===this.level&&Array.isArray(this.data)?this.data:y(this,"children")||[];for(let s=0,i=t.length;s<i;s++)this.insertChild({data:t[s]})}contains(e,t=!0){const s=function(i){const d=i.getChildNodes(i.childNodesId)||[];let h=!1;for(let r=0,o=d.length;r<o;r++){const i=d[r];if(i===e||t&&s(i)){h=!0;break}}return h};return s(this)}remove(){if(null!==this.parentId){this.getParent(this.parentId).removeChild(this)}}insertChild(e,t,s){if(!e)throw new Error("insertChild error: child is required.");if(!(e instanceof C)){if(!s){const s=this.getChildren(!0);-1===s.indexOf(e.data)&&(void 0===t||t<0?s.push(e.data):s.splice(t,0,e.data))}u(e,{parentId:(i=this.key,null==i||""===i?"":this.key),store:this.store()}),e=new C(e)}var i;e.level=this.level+1,void 0===t||t<0?this.childNodesId.push(e.key):this.childNodesId.splice(t,0,e.key),this.updateLeafState()}insertBefore(e,t){let s;t&&(s=this.childNodesId.indexOf(t.id)),this.insertChild(e,s)}insertAfter(e,t){let s;t&&(s=this.childNodesId.indexOf(t.id),-1!==s&&(s+=1)),this.insertChild(e,s)}removeChild(e){const t=this.getChildren()||[],s=t.indexOf(e.data);s>-1&&t.splice(s,1);const i=this.childNodesId.indexOf(e.key);i>-1&&(this.store()&&this.store().deregisterNode(e),e.parentId=null,this.childNodesId.splice(i,1)),this.updateLeafState()}removeChildByData(e){let t=null;for(let s=0;s<this.childNodesId.length;s++){let i=this.getChildNodes(this.childNodesId);if(i[s].data===e){t=i[s];break}}t&&this.removeChild(t)}getParent(e){try{return e.toString()?this.store().nodesMap[e]:null}catch(t){return null}}getChildNodes(e){let t=[];return 0===e.length||e.forEach((e=>{t.push(this.store().nodesMap[e])})),t}expand(e,t){const s=()=>{if(t){let e=this.getParent(this.parentId);for(;e&&e.level>0;)e.expanded=!0,e=this.getParent(e.parentId)}this.expanded=!0,e&&e()};this.shouldLoadData()?this.loadData((function(e){Array.isArray(e)&&(this.checked?this.setChecked(!0,!0):this.store().checkStrictly||p(this),s())})):s()}doCreateChildren(e,t={}){e.forEach((e=>{this.insertChild(u({data:e},t),void 0,!0)}))}collapse(){this.expanded=!1}shouldLoadData(){return!0===this.store().lazy&&this.store().load&&!this.loaded}updateLeafState(){if(!0===this.store().lazy&&!0!==this.loaded&&void 0!==this.isLeafByUser)return void(this.isLeaf=this.isLeafByUser);const e=this.childNodesId;!this.store().lazy||!0===this.store().lazy&&!0===this.loaded?this.isLeaf=!e||0===e.length:this.isLeaf=!1}setChecked(e,t,s,i){if(this.indeterminate="half"===e,this.checked=!0===e,this.checked&&this.store().expandOnCheckNode&&this.expand(null,!0),this.store().checkStrictly)return;if(this.store().showRadio)return;if(!this.shouldLoadData()||this.store().checkDescendants){let s=this.getChildNodes(this.childNodesId),{all:d,allWithoutDisable:h}=f(s);this.isLeaf||d||!h||(this.checked=!1,e=!1);const r=()=>{if(t){let s=this.getChildNodes(this.childNodesId);for(let r=0,o=s.length;r<o;r++){const d=s[r];i=i||!1!==e;const h=d.disabled?d.checked:i;d.setChecked(h,t,!0,i)}const{half:d,all:h}=f(s);h||(this.checked=h,this.indeterminate=d)}};if(this.shouldLoadData())return void this.loadData((()=>{r(),p(this)}),{checked:!1!==e});r()}if(!this.parentId)return;let d=this.getParent(this.parentId);d&&0===d.level||s||p(d)}setRadioChecked(e){this.store()._getAllNodes().sort(((e,t)=>t.level-e.level)).forEach((e=>e.setChecked(!1,!1))),this.checked=!0===e}getChildren(e=!1){if(0===this.level)return this.data;const t=this.data;if(!t)return null;const s=this.store().props;let i="children";return s&&(i=s.children||"children"),void 0===t[i]&&(t[i]=null),e&&!t[i]&&(t[i]=[]),t[i]}updateChildren(){let e=this.getChildNodes(this.childNodesId);const t=this.getChildren()||[],s=e.map((e=>e.data)),i={},d=[];t.forEach(((e,t)=>{const h=e[a];!!h&&function(e,t){for(let s=0;s!==e.length;++s)if(t(e[s]))return s;return-1}(s,(e=>e[a]===h))>=0?i[h]={index:t,data:e}:d.push({index:t,data:e})})),this.store().lazy||s.forEach((e=>{i[e[a]]||this.removeChildByData(e)})),d.forEach((({index:e,data:t})=>{this.insertChild({data:t},e)})),this.updateLeafState()}loadData(e,t={}){if(!0!==this.store().lazy||!this.store().load||this.loaded||this.loading&&!Object.keys(t).length)e&&e.call(this);else{this.loading=!0;const s=s=>{this.loaded=!0,this.loading=!1,this.childNodesId=[],this.doCreateChildren(s,t),this.updateLeafState(),e&&e.call(this,s)};this.store().load(this,s)}}}class g{constructor(t){if(this.ready=!1,this.currentNode=null,this.currentNodeKey=null,Object.assign(this,t),!this.key)throw new Error("[Tree] nodeKey is required");if(this.nodesMap={},this.root=new C({data:this.data,store:this}),this.lazy&&this.load){(0,this.load)(this.root,(t=>{this.root.doCreateChildren(t),this._initDefaultCheckedNodes(),this.ready=!0,e("updateKey")}))}else this._initDefaultCheckedNodes(),this.ready=!0}getReady(){return this.ready}filter(e,t){const s=this.filterNodeMethod,i=this.lazy,d=this,h=function(r){const o=r.root?r.root.getChildNodes(r.root.childNodesId):r.getChildNodes(r.childNodesId);if(o.forEach((i=>{if(t&&"object"==typeof t){if(!d.getNodePath(i.data).some((e=>e[d.key]===t[d.key])))return i.visible=!1,void h(i)}if(d.childVisibleForFilterNode){let t=i.getParent(i.parentId);i.visible=s.call(i,e,i.data,i)||t&&t.visible}else i.visible=s.call(i,e,i.data,i);h(i)})),!r.visible&&o.length){let e=!0;e=!o.some((e=>e.visible)),r.root?r.root.visible=!1===e:r.visible=!1===e}e&&(!r.visible||r.isLeaf||i||r.expand())};h(this)}setData(e){e!==this.root.data?(this.root.setData(e),this._initDefaultCheckedNodes()):this.root.updateChildren()}getNode(e){if(e instanceof C)return e;const t="object"!=typeof e?e:c(this.key,e);return t&&this.nodesMap[t]||null}insertBefore(e,t){const s=this.getNode(t);s.getParent(s.parentId).insertBefore({data:e},s)}insertAfter(e,t){const s=this.getNode(t);s.getParent(s.parentId).insertAfter({data:e},s)}remove(e){const t=this.getNode(e);if(t&&null!==t.parentId){let e=t.getParent(t.parentId);t===this.currentNode&&(this.currentNode=null),e.removeChild(t)}}append(e,t){const s=t?this.getNode(t):this.root;s&&s.insertChild({data:e})}_initDefaultCheckedNodes(){const e=this.defaultCheckedKeys||[],t=this.nodesMap;let s=[],i=[];for(let d in t){(y(t[d],"checked")||!1)&&s.push(d)}i=Array.from(new Set([...e,...s])),i.forEach((e=>{const s=t[e];s&&s.setChecked(!0,!this.checkStrictly)}))}_initDefaultCheckedNode(e){-1!==(this.defaultCheckedKeys||[]).indexOf(e.key)&&e.setChecked(!0,!this.checkStrictly)}toggleExpendAll(e){this._getAllNodes().forEach((t=>{const s=this.getNode(t.key);s&&(e?s.expand():s.collapse())}))}setCheckAll(e){this._getAllNodes().forEach((t=>{t.setChecked(e,!1)}))}setDefaultCheckedKey(e){e!==this.defaultCheckedKeys&&(this.defaultCheckedKeys=e,this._initDefaultCheckedNodes())}registerNode(e){if(!this.key||!e||!e.data)return;void 0!==e.key&&(this.nodesMap[e.key]=e)}deregisterNode(e){if(!this.key||!e||!e.data)return;e.getChildNodes(e.childNodesId).forEach((e=>{this.deregisterNode(e)})),delete this.nodesMap[e.key]}getNodePath(e){if(!this.key)throw new Error("[Tree] nodeKey is required in getNodePath");const t=this.getNode(e);if(!t)return[];const s=[t.data];let i=t.getParent(t.parentId);for(;i&&i!==this.root;)s.push(i.data),i=i.getParent(i.parentId);return s.reverse()}getCheckedNodes(e=!1,t=!1){const s=[],i=function(d){(d.root?d.root.getChildNodes(d.root.childNodesId):d.getChildNodes(d.childNodesId)).forEach((d=>{(d.checked||t&&d.indeterminate)&&(!e||e&&d.isLeaf)&&s.push(d.data),i(d)}))};return i(this),s}getCheckedKeys(e=!1,t=!1){return this.getCheckedNodes(e,t).map((e=>(e||{})[this.key]))}getHalfCheckedNodes(){const e=[],t=function(s){(s.root?s.root.getChildNodes(s.root.childNodesId):s.getChildNodes(s.childNodesId)).forEach((s=>{s.indeterminate&&e.push(s.data),t(s)}))};return t(this),e}getHalfCheckedKeys(){return this.getHalfCheckedNodes().map((e=>(e||{})[this.key]))}_getAllNodes(){const e=[],t=this.nodesMap;for(let s in t)t.hasOwnProperty(s)&&e.push(t[s]);return e}updateChildren(e,t){const s=this.nodesMap[e];if(!s)return;const i=s.getChildNodes(s.childNodesId);for(let d=i.length-1;d>=0;d--){const e=i[d];this.remove(e.data)}for(let d=0,h=t.length;d<h;d++){const e=t[d];this.append(e,s.data)}}_setCheckedKeys(e,t=!1,s){const i=this._getAllNodes().sort(((e,t)=>t.level-e.level)),d=Object.create(null),h=Object.keys(s);i.forEach((e=>e.setChecked(!1,!1)));for(let r=0,o=i.length;r<o;r++){const s=i[r];let o=s.data[e];if(void 0===o)continue;if(o=o.toString(),!(h.indexOf(o)>-1)){s.checked&&!d[o]&&s.setChecked(!1,!1);continue}let n=s.getParent(s.parentId);for(;n&&n.level>0;)d[n.data[e]]=!0,n=n.getParent(n.parentId);if(s.isLeaf||this.checkStrictly)s.setChecked(!0,!1);else if(s.setChecked(!0,!0),t){s.setChecked(!1,!1);const e=function(t){t.getChildNodes(t.childNodesId).forEach((t=>{t.isLeaf||t.setChecked(!1,!1),e(t)}))};e(s)}}}setCheckedNodes(e,t=!1){const s=this.key,i={};e.forEach((e=>{i[(e||{})[s]]=!0})),this._setCheckedKeys(s,t,i)}setCheckedKeys(e,t=!1){this.defaultCheckedKeys=e;const s=this.key,i={};e.forEach((e=>{i[e]=!0})),this._setCheckedKeys(s,t,i)}setDefaultExpandedKeys(e){e=e||[],this.defaultExpandedKeys=e,e.forEach((e=>{const t=this.getNode(e);t&&t.expand(null,this.autoExpandParent)}))}setChecked(e,t,s){const i=this.getNode(e);i&&i.setChecked(!!t,s)}getCurrentNode(){return this.currentNode}setCurrentNode(e){const t=this.currentNode;t&&(t.isCurrent=!1),this.currentNode=e,this.currentNode.isCurrent=!0,this.expandCurrentNodeParent&&this.currentNode.expand(null,!0)}setUserCurrentNode(e){const t=e[this.key],s=this.nodesMap[t];this.setCurrentNode(s)}setCurrentNodeKey(e){if(null==e)return this.currentNode&&(this.currentNode.isCurrent=!1),void(this.currentNode=null);const t=this.getNode(e);t&&this.setCurrentNode(t)}}const v=n({data:()=>({classObj:{}}),props:{type:{type:String,validator:e=>"radio"===e||"checkbox"===e},checked:Boolean,disabled:Boolean,indeterminate:Boolean},created(){this.classObj={wrapper:`ly-${this.type}`,input:`ly-${this.type}__input`,inner:`ly-${this.type}__inner`}},methods:{handleClick(){this.$emit("check",this.checked)}}},[["render",function(e,n,a,l,c,u){const f=o;return t(),s(f,{class:h(c.classObj.wrapper),onClick:r(u.handleClick,["stop"])},{default:i((()=>[d(f,{class:h([c.classObj.input,{"is-indeterminate":a.indeterminate,"is-checked":a.checked,"is-disabled":a.disabled}])},{default:i((()=>[d(f,{class:h(c.classObj.inner)},null,8,["class"])])),_:1},8,["class"])])),_:1},8,["class","onClick"])}],["__scopeId","data-v-2d06287c"]]);export{g as T,c as g,v as l};