diff --git a/index.html b/index.html index 5a085b0..005161d 100644 --- a/index.html +++ b/index.html @@ -7,7 +7,11 @@ -
{i(),Ii(this)},{checked:t!==!1});return}else i()}const l=this.parent;!l||l.level===0||o||Ii(l)}getChildren(t=!1){if(this.level===0)return this.data;const n=this.data;if(!n)return null;const o=this.store.props;let s="children";return o&&(s=o.children||"children"),n[s]===void 0&&(n[s]=null),t&&!n[s]&&(n[s]=[]),n[s]}updateChildren(){const t=this.getChildren()||[],n=this.childNodes.map(l=>l.data),o={},s=[];t.forEach((l,r)=>{const a=l[Bl];!!a&&n.findIndex(u=>u[Bl]===a)>=0?o[a]={index:r,data:l}:s.push({index:r,data:l})}),this.store.lazy||n.forEach(l=>{o[l[Bl]]||this.removeChildByData(l)}),s.forEach(({index:l,data:r})=>{this.insertChild({data:r},l)}),this.updateLeafState()}loadData(t,n={}){if(this.store.lazy===!0&&this.store.load&&!this.loaded&&(!this.loading||Object.keys(n).length)){this.loading=!0;const o=s=>{this.loaded=!0,this.loading=!1,this.childNodes=[],this.doCreateChildren(s,n),this.updateLeafState(),t&&t.call(this,s)};this.store.load(this,o)}else t&&t.call(this)}}class lJ{constructor(t){this.currentNode=null,this.currentNodeKey=null;for(const n in t)at(t,n)&&(this[n]=t[n]);this.nodesMap={}}initialize(){this.root=new Js({data:this.data,store:this}),this.root.initialize(),this.lazy&&this.load?this.load(this.root,n=>{this.root.doCreateChildren(n),this._initDefaultCheckedNodes()}):this._initDefaultCheckedNodes()}filter(t){const n=this.filterNodeMethod,o=this.lazy,s=function(l){const r=l.root?l.root.childNodes:l.childNodes;if(r.forEach(a=>{a.visible=n.call(a,t,a.data,a),s(a)}),!l.visible&&r.length){let a=!0;a=!r.some(i=>i.visible),l.root?l.root.visible=a===!1:l.visible=a===!1}!t||l.visible&&!l.isLeaf&&!o&&l.expand()};s(this)}setData(t){t!==this.root.data?(this.root.setData(t),this._initDefaultCheckedNodes()):this.root.updateChildren()}getNode(t){if(t instanceof Js)return t;const n=typeof t!="object"?t:Bp(this.key,t);return this.nodesMap[n]||null}insertBefore(t,n){const o=this.getNode(n);o.parent.insertBefore({data:t},o)}insertAfter(t,n){const o=this.getNode(n);o.parent.insertAfter({data:t},o)}remove(t){const n=this.getNode(t);n&&n.parent&&(n===this.currentNode&&(this.currentNode=null),n.parent.removeChild(n))}append(t,n){const o=n?this.getNode(n):this.root;o&&o.insertChild({data:t})}_initDefaultCheckedNodes(){const t=this.defaultCheckedKeys||[],n=this.nodesMap;t.forEach(o=>{const s=n[o];s&&s.setChecked(!0,!this.checkStrictly)})}_initDefaultCheckedNode(t){(this.defaultCheckedKeys||[]).includes(t.key)&&t.setChecked(!0,!this.checkStrictly)}setDefaultCheckedKey(t){t!==this.defaultCheckedKeys&&(this.defaultCheckedKeys=t,this._initDefaultCheckedNodes())}registerNode(t){const n=this.key;!t||!t.data||(n?t.key!==void 0&&(this.nodesMap[t.key]=t):this.nodesMap[t.id]=t)}deregisterNode(t){!this.key||!t||!t.data||(t.childNodes.forEach(o=>{this.deregisterNode(o)}),delete this.nodesMap[t.key])}getCheckedNodes(t=!1,n=!1){const o=[],s=function(l){(l.root?l.root.childNodes:l.childNodes).forEach(a=>{(a.checked||n&&a.indeterminate)&&(!t||t&&a.isLeaf)&&o.push(a.data),s(a)})};return s(this),o}getCheckedKeys(t=!1){return this.getCheckedNodes(t).map(n=>(n||{})[this.key])}getHalfCheckedNodes(){const t=[],n=function(o){(o.root?o.root.childNodes:o.childNodes).forEach(l=>{l.indeterminate&&t.push(l.data),n(l)})};return n(this),t}getHalfCheckedKeys(){return this.getHalfCheckedNodes().map(t=>(t||{})[this.key])}_getAllNodes(){const t=[],n=this.nodesMap;for(const o in n)at(n,o)&&t.push(n[o]);return t}updateChildren(t,n){const o=this.nodesMap[t];if(!o)return;const s=o.childNodes;for(let l=s.length-1;l>=0;l--){const r=s[l];this.remove(r.data)}for(let l=0,r=n.length;l {i(),Ii(this)},{checked:t!==!1});return}else i()}const l=this.parent;!l||l.level===0||o||Ii(l)}getChildren(t=!1){if(this.level===0)return this.data;const n=this.data;if(!n)return null;const o=this.store.props;let s="children";return o&&(s=o.children||"children"),n[s]===void 0&&(n[s]=null),t&&!n[s]&&(n[s]=[]),n[s]}updateChildren(){const t=this.getChildren()||[],n=this.childNodes.map(l=>l.data),o={},s=[];t.forEach((l,r)=>{const a=l[Bl];!!a&&n.findIndex(u=>u[Bl]===a)>=0?o[a]={index:r,data:l}:s.push({index:r,data:l})}),this.store.lazy||n.forEach(l=>{o[l[Bl]]||this.removeChildByData(l)}),s.forEach(({index:l,data:r})=>{this.insertChild({data:r},l)}),this.updateLeafState()}loadData(t,n={}){if(this.store.lazy===!0&&this.store.load&&!this.loaded&&(!this.loading||Object.keys(n).length)){this.loading=!0;const o=s=>{this.loaded=!0,this.loading=!1,this.childNodes=[],this.doCreateChildren(s,n),this.updateLeafState(),t&&t.call(this,s)};this.store.load(this,o)}else t&&t.call(this)}}class lJ{constructor(t){this.currentNode=null,this.currentNodeKey=null;for(const n in t)at(t,n)&&(this[n]=t[n]);this.nodesMap={}}initialize(){this.root=new Js({data:this.data,store:this}),this.root.initialize(),this.lazy&&this.load?this.load(this.root,n=>{this.root.doCreateChildren(n),this._initDefaultCheckedNodes()}):this._initDefaultCheckedNodes()}filter(t){const n=this.filterNodeMethod,o=this.lazy,s=function(l){const r=l.root?l.root.childNodes:l.childNodes;if(r.forEach(a=>{a.visible=n.call(a,t,a.data,a),s(a)}),!l.visible&&r.length){let a=!0;a=!r.some(i=>i.visible),l.root?l.root.visible=a===!1:l.visible=a===!1}!t||l.visible&&!l.isLeaf&&!o&&l.expand()};s(this)}setData(t){t!==this.root.data?(this.root.setData(t),this._initDefaultCheckedNodes()):this.root.updateChildren()}getNode(t){if(t instanceof Js)return t;const n=typeof t!="object"?t:Bp(this.key,t);return this.nodesMap[n]||null}insertBefore(t,n){const o=this.getNode(n);o.parent.insertBefore({data:t},o)}insertAfter(t,n){const o=this.getNode(n);o.parent.insertAfter({data:t},o)}remove(t){const n=this.getNode(t);n&&n.parent&&(n===this.currentNode&&(this.currentNode=null),n.parent.removeChild(n))}append(t,n){const o=n?this.getNode(n):this.root;o&&o.insertChild({data:t})}_initDefaultCheckedNodes(){const t=this.defaultCheckedKeys||[],n=this.nodesMap;t.forEach(o=>{const s=n[o];s&&s.setChecked(!0,!this.checkStrictly)})}_initDefaultCheckedNode(t){(this.defaultCheckedKeys||[]).includes(t.key)&&t.setChecked(!0,!this.checkStrictly)}setDefaultCheckedKey(t){t!==this.defaultCheckedKeys&&(this.defaultCheckedKeys=t,this._initDefaultCheckedNodes())}registerNode(t){const n=this.key;!t||!t.data||(n?t.key!==void 0&&(this.nodesMap[t.key]=t):this.nodesMap[t.id]=t)}deregisterNode(t){!this.key||!t||!t.data||(t.childNodes.forEach(o=>{this.deregisterNode(o)}),delete this.nodesMap[t.key])}getCheckedNodes(t=!1,n=!1){const o=[],s=function(l){(l.root?l.root.childNodes:l.childNodes).forEach(a=>{(a.checked||n&&a.indeterminate)&&(!t||t&&a.isLeaf)&&o.push(a.data),s(a)})};return s(this),o}getCheckedKeys(t=!1){return this.getCheckedNodes(t).map(n=>(n||{})[this.key])}getHalfCheckedNodes(){const t=[],n=function(o){(o.root?o.root.childNodes:o.childNodes).forEach(l=>{l.indeterminate&&t.push(l.data),n(l)})};return n(this),t}getHalfCheckedKeys(){return this.getHalfCheckedNodes().map(t=>(t||{})[this.key])}_getAllNodes(){const t=[],n=this.nodesMap;for(const o in n)at(n,o)&&t.push(n[o]);return t}updateChildren(t,n){const o=this.nodesMap[t];if(!o)return;const s=o.childNodes;for(let l=s.length-1;l>=0;l--){const r=s[l];this.remove(r.data)}for(let l=0,r=n.length;l-1)return t.childNodes[n+1]}return null}get previousSibling(){const t=this.parent;if(t){const n=t.childNodes.indexOf(this);if(n>-1)return n>0?t.childNodes[n-1]:null}return null}contains(t,n=!0){return(this.childNodes||[]).some(o=>o===t||n&&o.contains(t))}remove(){const t=this.parent;t&&t.removeChild(this)}insertChild(t,n,o){if(!t)throw new Error("InsertChild error: child is required.");if(!(t instanceof Js)){if(!o){const s=this.getChildren(!0);s.includes(t.data)||(typeof n=="undefined"||n<0?s.push(t.data):s.splice(n,0,t.data))}Object.assign(t,{parent:this,store:this.store}),t=yt(new Js(t)),t instanceof Js&&t.initialize()}t.level=this.level+1,typeof n=="undefined"||n<0?this.childNodes.push(t):this.childNodes.splice(n,0,t),this.updateLeafState()}insertBefore(t,n){let o;n&&(o=this.childNodes.indexOf(n)),this.insertChild(t,o)}insertAfter(t,n){let o;n&&(o=this.childNodes.indexOf(n),o!==-1&&(o+=1)),this.insertChild(t,o)}removeChild(t){const n=this.getChildren()||[],o=n.indexOf(t.data);o>-1&&n.splice(o,1);const s=this.childNodes.indexOf(t);s>-1&&(this.store&&this.store.deregisterNode(t),t.parent=null,this.childNodes.splice(s,1)),this.updateLeafState()}removeChildByData(t){let n=null;for(let o=0;o
- {{ Title }}
-
-
-
-
-
-
-
-
- 名稱
- Host
- Port
- 狀態
-