import{$ as e,o as t,c as s,w as i,t as d,G as h,a0 as r,H as o}from"./index-v_Wqmvb-.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-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-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{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{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;dt.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-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};