Repository navigation
Expand file tree
/
Copy pathtree.jquery.js
More file actions
41 lines (31 loc) · 39.6 KB
/
Copy pathtree.jquery.js
File metadata and controls
41 lines (31 loc) · 39.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
JqTree 2.0.2
Copyright 2026 Marco Braak
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
@license
*/
var jqtree=function(t){"use strict";class e{constructor({t:t,i:e,h:i,o:s,l:r}){this.u=new AbortController,this.t=t,this.i=e,this.h=i,this.o=s,this.l=r}_(){this.u.abort()}async m(t,e){let i=e?.element??this.o;i.classList.add(this.t.loading),this.l("tree.loading_data",{element:i,node:e});let s=()=>{i.classList.remove(this.t.loading),this.l("tree.loaded_data",{element:i,node:e})},r=this.u.signal;return t.p("_",Date.now().toString()),fetch(t.N(),{headers:{"Content-Type":"application/json"},signal:r}).then(async t=>{if(t.ok){let i=await t.json();s(),this.h(this.i?this.i(i):i,e)}else s(),this.l("tree.load_failed",{response:t})}).catch(t=>{this.u.signal.aborted||(s(),this.l("tree.load_failed",{error:t}))})}}let i=t=>s(t).top,s=t=>{let e=t.getBoundingClientRect();return{left:e.x+window.scrollX,top:e.y+window.scrollY}};class r{constructor({v:t,t:e,S:i,D:s,F:r,o:h}){this.D=s,this.F=r,this.C=this.T(i,t,e),h.appendChild(this.C)}$(t,e){this.C.style.left=t-this.D+"px",this.C.style.top=e-this.F+"px"}M(){this.C.remove()}T(t,e,i){let s=document.createElement("span");return s.classList.add(i.title,i.dragging),e?s.textContent=t:s.innerHTML=t,s.style.position="absolute",s}}let h=(t,e,i,s)=>{let r=Math.min(e.length,4),h=Math.round((s-i)/r),n=i;for(let i=0;i<r;i++){let s=e[i];s.position&&t.push({bottom:n+h,node:s.node,position:s.position,top:n}),n+=h}},n=(t,e,s)=>((t,e)=>{if(!t.length)return[];let i=t[0].top,s=[],r=[];for(let e of t)e.top!==i&&s.length&&(h(r,s,i,e.top),i=e.top,s=[]),s.push(e);return h(r,s,i,e),r})(((t,e)=>{let s=[],r=0,h=(t,e,i)=>{s.push({node:t,position:e,top:i}),r=i};return((t,{I:e,k:i,L:s,B:r,j:h})=>{let n=!0,o=(t,l)=>{let a=(!0===t.is_open||!t.element)&&t.hasChildren(),d=null;if(t.element?.offsetParent&&(d=t.element,n&&(s(t),n=!1),t.hasChildren()?t.is_open?h(t,t.element)||(a=!1):i(t,l,d):r(t,l,t.element)),a){let i=t.children.length;t.children.forEach((e,s)=>{let r=t.children[s];if(r)if(s===i-1)o(r,null);else{let e=t.children[s+1];e&&o(r,e)}}),t.is_open&&d&&e(t,l)}};o(t,null)})(t,{I:(t,i)=>{h(t,t===e||i===e?null:"after",r)},k:(t,s,r)=>{let n=i(r);t===e?h(t,null,n):(h(t,"inside",n),s!==e&&h(t,"after",n))},L:t=>{t!==e&&t.element&&h(t,"before",i(t.element))},B:(t,s,r)=>{let n=i(r);h(t,t===e?null:"inside",n),h(t,s===e||t===e?null:"after",n)},j:(t,s)=>{if(t===e){let e=i(s),r=s.clientHeight;return h(t,null,e),r>5&&h(t,null,e+r-5),!1}return t.children[0]!==e&&h(t,"inside",i(s)),!0}}),s})(t,e),s);class o{constructor({v:t,t:e,H:i,A:s,P:r,O:h,U:n,R:o,q:l,V:a,Y:d,J:u,X:c,G:_,K:m,o:f,l:g}){this.v=t,this.t=e,this.H=i,this.A=s,this.P=r,this.O=h,this.U=n,this.R=o,this.q=l,this.V=a,this.Y=d,this.J=u,this.X=c,this.G=_,this.K=m,this.o=f,this.l=g,this.W=null,this.Z=[],this.tt=!1,this.et=null,this.it=null,this.st=null,this.rt=null}ht(t){let e=t.target;if(!this.nt(e))return null;if(this.Y&&!this.Y(e))return null;let i=this.H(e);return i&&this.U&&(this.U(i.ot)||(i=null)),this.et=i,null!=this.et}lt(t){if(!this.et||!this.it)return!1;this.it.$(t.pageX,t.pageY);let e=this.dt(t.pageX,t.pageY);return e&&this.ut(e,this.et)?(e.node.isFolder()||this.ct(),this.W!==e&&(this.W=e,this._t(e)?this.ft(e.node):this.ct(),this.gt())):(this.Nt(),this.ct(),this.W=e),e||this.q&&this.q(this.et.ot,t.originalEvent),!0}vt(t){if(!this.et)return!1;this.St();let{left:e,top:i}=s(t.target),h=this.et.ot;return this.it=new r({v:this.v??!0,t:this.t,S:h.name,D:t.pageX-e,F:t.pageY-i,o:this.o}),this.tt=!0,this.et.C.classList.add(this.t.moving),!0}wt(t){this.Et(t),this.yt(),this.bt(),this.Nt(),this.Dt();let e=this.et;return this.et&&(this.et.C.classList.remove(this.t.moving),this.et=null),this.tt=!1,!this.W&&e&&this.V&&this.V(e.ot,t.originalEvent),!1}St(){if(this.Dt(),this.et){let t=this.et.ot;this.Ft(t),this.et=this.A(t),this.tt&&this.et.C.classList.add(this.t.moving)}}ut(t,e){return!this.R||this.R(e.ot,t.node,t.position)}yt(){this.it&&(this.it.M(),this.it=null)}dt(t,e){let i=this.Ct();return t<i.left||e<i.top||t>i.right||e>i.bottom?null:function(t,e){let i=0,s=t.length;for(;i<s;){let r=i+s>>1,h=t[r];if(void 0===h)return null;let n=e(h);if(n>0)s=r;else{if(!(n<0))return h;i=r+1}}return null}(this.Z,t=>e<t.top?1:e>t.bottom?-1:0)}Ft(t){let e=this.O();this.Z=e?n(e,t,this.Ct().bottom):[]}Ct(){let t=s(this.o),e=t.left+this.P(),i=t.top;return{bottom:i+this.o.clientHeight+16,left:e,right:e+this.o.clientWidth,top:i}}Et(t){if(this.et&&this.W?.position&&this.ut(this.W,this.et)){let e=this.et.ot,i=this.W.node,s=this.W.position,r=e.parent;"inside"===s&&(this.W.node.is_open=!0);let h=()=>{let t=this.O();t&&(t.moveNode(e,i,s),this.o.textContent="",this.G(null))};this.l("tree.move",{moveInfo:{doMove:h,movedNode:e,originalEvent:t.originalEvent,position:s,previousParent:r,targetNode:i}})&&h()}}nt(t){let e=t.nodeName;return"INPUT"!==e&&"SELECT"!==e&&"TEXTAREA"!==e}_t(t){let e=t.node;return e.isFolder()&&!e.is_open&&"inside"===t.position}Nt(){this.rt&&this.rt.remove()}Dt(){this.Z=[]}bt(){this.W=null}ft(t){let e=()=>{this.X(t,this.K).then(()=>{this.St(),this.gt()})};this.ct();let i=this.J;!1!==i&&(this.st=window.setTimeout(e,i))}ct(){this.st&&(clearTimeout(this.st),this.st=null)}gt(){if(!this.W)return;this.Nt();let t=this.A(this.W.node);this.rt=t.Tt(this.W.position)}}class l{constructor({v:t,$t:e,t:i,Mt:s,It:r,O:h,xt:n,kt:o,Lt:l,Bt:a,jt:d,Ht:u,At:c,Pt:_}){this.v=t,this.$t=e,this.t=i,this.It=r,this.O=h,this.xt=n,this.kt=o,this.Lt=l,this.jt=d,this.Ht=u,this.At=c,this.Pt=_,this.Ot=this.Qt(a??"+"),this.Ut=this.Qt(s??"-"),this.Rt=this.qt(!0),this.Vt=this.qt(!1),this.Yt=this.zt(),this.Jt=this.Xt(!0),this.Gt=this.Xt(!1)}Kt(t){t?.parent?this.Wt(t):this.Zt()}te(t){return t.element&&t.hasChildren()?this.ee(t.element,t.children,!1,t.getLevel()+1):null}Wt(t){if(!t.element)return;let e=t.element,i=this.ie(t,t.getLevel());e.replaceWith(i),this.se(t)&&this.ee(i,t.children,!1,t.getLevel()+1)}Zt(){this.xt.textContent="";let t=this.O();t&&this.ee(this.xt,t.children,!0,1)}re(t,e){t.element=e,this.Ht(e,t)}Qt(t){if("string"==typeof t){let e=document.createElement("template");return e.innerHTML=t,e.content}return t.nodeType?t:void 0}ee(t,e,i,s){let r=(i?this.Rt:this.Vt).cloneNode();t.appendChild(r);for(let t of e){let e=this.ie(t,s);r.appendChild(e),this.se(t)&&this.ee(e,t.children,!1,s+1)}return r}he(t,e,i){let s=(t.is_open?this.Jt:this.Gt).cloneNode(!0);i&&s.classList.add(this.t.selected),t.is_loading&&s.classList.add(this.t.loading);let r=s.firstChild.childNodes[this.$t?1:0];return this.ne(r,t.name,i,e),s}Xt(t){let e=[this.t.common,this.t.folder];t||e.push(this.t.closed);let i=this.oe(e.join(" ")),s=i.firstChild,r=document.createElement("a");r.className=this.le(t);let h=t?this.Ot:this.Ut;h&&r.appendChild(h.cloneNode(!0)),this.$t&&s.appendChild(r);let n=this.ae(!0);return n.setAttribute("aria-expanded",t?"true":"false"),s.appendChild(n),this.$t||s.appendChild(r),i}ie(t,e){let i=this.kt(t),s=t.isFolder()||t.isEmptyFolder&&this.At?this.he(t,e,i):this.de(t,e,i);return this.re(t,s),this.Lt&&this.Lt(t,s,i),s}oe(t){let e=document.createElement("li");e.className=t,e.setAttribute("role","none");let i=document.createElement("div");return i.className=`${this.t.element} ${this.t.common}`,i.setAttribute("role","none"),e.appendChild(i),e}de(t,e,i){let s=this.Yt.cloneNode(!0);i&&s.classList.add(this.t.selected);let r=s.firstChild.firstChild;return this.ne(r,t.name,i,e),s}zt(){let t=this.oe(this.t.common);return t.firstChild.appendChild(this.ae(!1)),t}ae(t){let e=document.createElement("span"),i=`${this.t.title} ${this.t.common}`;return t&&(i+=` ${this.t.titleFolder}`),i+=` ${this.$t?this.t.titleButtonLeft:this.t.titleButtonRight}`,e.className=i,e.setAttribute("role","treeitem"),e.setAttribute("aria-selected","false"),e}qt(t){let e,i;t?(e=this.t.tree,i="tree",this.jt&&(e+=` ${this.t.rtl}`)):(e="",i="group"),this.It&&(e+=` ${this.t.dnd}`);let s=document.createElement("ul");return s.className=`${this.t.common} ${e}`,s.setAttribute("role",i),s}ne(t,e,i,s){if(t.setAttribute("aria-label",e),t.setAttribute("aria-level",`${s}`),i){t.setAttribute("aria-selected","true");let e=this.Pt;void 0!==e&&t.setAttribute("tabindex",`${e}`)}this.v?t.textContent=e:t.innerHTML=e}le(t){let e=[this.t.toggler,this.t.common];return t||e.push(this.t.closed),this.$t?e.push(this.t.togglerLeft):e.push(this.t.togglerRight),e.join(" ")}se(t){return t.hasChildren()&&!0===t.is_open}}class a{constructor({ue:t,ce:e,_e:i,me:s,X:r,fe:h}){this.ue=t,this.ce=e,this._e=i,this.me=s,this.X=r,this.ge=h,s&&document.addEventListener("keydown",this.pe)}_(){this.me&&document.removeEventListener("keydown",this.pe)}Ne(){return this.fe(this.ce()?.getNextVisibleNode())}ve(){return this.fe(this.ce()?.getPreviousVisibleNode())}Se(){return this.me&&this._e()}pe=t=>{if(!this.Se())return;let e=!1;if(this.ce())switch(t.key){case"ArrowDown":e=this.Ne();break;case"ArrowLeft":e=this.we();break;case"ArrowRight":e=this.Ee();break;case"ArrowUp":e=this.ve()}e&&t.preventDefault()};we(){let t=this.ce();return!!t&&(t.isFolder()&&t.is_open?(this.ue(t),!0):this.fe(t.getParent()))}Ee(){let t=this.ce();return!!t?.isFolder()&&(t.is_open?this.fe(t.getNextVisibleNode()):(this.X(t),!0))}fe(t){return!!t&&(this.ge(t),!0)}}let d=t=>({originalEvent:t,pageX:t.pageX,pageY:t.pageY,target:t.target}),u=(t,e)=>({originalEvent:e,pageX:t.pageX,pageY:t.pageY,target:t.target});class c{constructor({t:t,C:e,ye:i,be:s,De:r,Fe:h,Ce:n,Te:o,$e:l,Me:a,l:d,Ie:u}){this.t=t,this.C=e,this.ye=i,this.be=s,this.De=r,this.Fe=h,this.Ce=n,this.Te=o,this.$e=l,this.Me=a,this.l=d,this.Ie=u,e.addEventListener("click",this.xe),e.addEventListener("dblclick",this.ke),e.addEventListener("mousedown",this.Le,{passive:!1}),e.addEventListener("touchstart",this.Be,{passive:!1}),u&&e.addEventListener("contextmenu",this.je),this.He=!1,this.Ae=null,this.Pe=!1,this.Oe=null}_(){this.C.removeEventListener("click",this.xe),this.C.removeEventListener("dblclick",this.ke),this.Ie&&this.C.removeEventListener("contextmenu",this.je),this.C.removeEventListener("mousedown",this.Le),this.C.removeEventListener("touchstart",this.Be),this.Qe()}Ue(t){let e=t.closest(`.${this.t.toggler}`);if(e){let t=this.be(e);if(t)return{node:t,type:"button"}}else{let e=t.closest(`.${this.t.element}`);if(e){let t=this.be(e);if(t)return{node:t,type:"label"}}}return null}xe=t=>{if(!t.target)return;let e=this.Ue(t.target);if(e)switch(e.type){case"button":this.De(e.node),t.preventDefault(),t.stopPropagation();break;case"label":this.l("tree.click",{node:e.node,originalEvent:t})&&this.Fe(e.node)}};je=t=>{if(!t.target)return;let e=t.target.closest(`ul.${this.t.tree} .${this.t.element}`);if(e){let i=this.be(e);if(i)return t.preventDefault(),t.stopPropagation(),this.l("tree.contextmenu",{node:i,originalEvent:t}),!1}return null};ke=t=>{if(!t.target)return;let e=this.Ue(t.target);"label"===e?.type&&this.l("tree.dblclick",{node:e.node,originalEvent:t})};Re(t){return this.He&&this.qe(t),this.Oe=t,!!this.Ce(t)&&(this.Ve(),!0)}Ye(t,e){if(this.He)return this.Te(e),void(t.cancelable&&t.preventDefault());this.Pe&&(this.Oe&&(this.He=this.$e(this.Oe)),this.He?(this.Te(e),t.cancelable&&t.preventDefault()):this.qe(e))}qe(t){this.Qe(),this.Pe=!1,this.Oe=null,this.He&&(this.He=!1,this.Me(t))}Ve(){document.addEventListener("mousemove",this.ze,{passive:!1}),document.addEventListener("touchmove",this.Je,{passive:!1}),document.addEventListener("mouseup",this.Xe,{passive:!1}),document.addEventListener("touchend",this.Ge,{passive:!1});let t=this.ye();t?this.Ke(t):this.Pe=!0}Le=t=>{if(0!==t.button)return;this.Re(d(t))&&t.cancelable&&t.preventDefault()};ze=t=>{this.Ye(t,d(t))};Xe=t=>{this.qe(d(t))};Qe(){document.removeEventListener("mousemove",this.ze),document.removeEventListener("touchmove",this.Je),document.removeEventListener("mouseup",this.Xe),document.removeEventListener("touchend",this.Ge)}Ke(t){this.Ae&&clearTimeout(this.Ae),this.Ae=window.setTimeout(()=>{this.Oe&&(this.Pe=!0)},t),this.Pe=!1}Ge=t=>{if(t.touches.length>1)return;let e=t.touches[0];e&&this.qe(u(e,t))};Je=t=>{if(t.touches.length>1)return;let e=t.touches[0];e&&this.Ye(t,u(e,t))};Be=t=>{if(t.touches.length>1)return;let e=t.touches[0];e&&this.Re(u(e,t))}}let _=t=>"object"==typeof t&&"children"in t&&t.children instanceof Array;class m{children;element;id;idMapping;is_loading;is_open;isEmptyFolder;load_on_demand;name;nodeClass;parent;tree;constructor(t=null,e=!1,i=m){this.name="",this.load_on_demand=!1,this.isEmptyFolder=null!=t&&_(t)&&0===t.children.length,this.setData(t),this.children=[],this.parent=null,this.is_loading=void 0,this.is_open??=void 0,e?(this.idMapping=new Map,this.tree=this,this.nodeClass=i):this.idMapping=void 0}addAfter(t){if(this.parent){let e=this.We(t),i=this.parent.getChildIndex(this);return this.parent.addChildAtPosition(e,i+1),e.Ze(t),e}return null}addBefore(t){if(this.parent){let e=this.We(t),i=this.parent.getChildIndex(this);return this.parent.addChildAtPosition(e,i),e.Ze(t),e}return null}addChild(t){this.children.push(t),t.ti(this)}addChildAtPosition(t,e){this.children.splice(e,0,t),t.ti(this)}addNodeToIndex(t){null!=t.id&&this.idMapping?.set(t.id,t)}addParent(t){if(this.parent){let e=this.We(t);this.tree&&e.ti(this.tree);let i=this.parent;for(let t of i.children)e.addChild(t);return i.children=[],i.addChild(e),e}return null}append(t){let e=this.We(t);return this.addChild(e),e.Ze(t),e}filter(t){let e=[];return this.iterate(i=>(t(i)&&e.push(i),!0)),e}getChildIndex(t){return this.children.indexOf(t)}getData(t=!1){let e=t=>t.map(t=>{let i={};for(let e in t)if(-1===["parent","children","element","idMapping","load_on_demand","nodeClass","tree","isEmptyFolder"].indexOf(e)&&Object.prototype.hasOwnProperty.call(t,e)){let s=t[e];i[e]=s}return t.hasChildren()&&(i.children=e(t.children)),i});return e(t?[this]:this.children)}getLastChild(){if(this.hasChildren()){let t=this.children[this.children.length-1];return t.hasChildren()&&t.is_open?t.getLastChild():t}return null}getLevel(){let t=0,e=this;for(;e.parent;)t+=1,e=e.parent;return t}getNextNode(t=!0){if(t&&this.hasChildren())return this.children[0]??null;if(this.parent){let t=this.getNextSibling();return t||this.parent.getNextNode(!1)}return null}getNextSibling(){if(this.parent){let t=this.parent.getChildIndex(this)+1;return t<this.parent.children.length?this.parent.children[t]??null:null}return null}getNextVisibleNode(){if(this.hasChildren()&&this.is_open)return this.children[0]??null;if(this.parent){let t=this.getNextSibling();return t||this.parent.getNextNode(!1)}return null}getNodeByCallback(t){let e=null;return this.iterate(i=>!e&&(!t(i)||(e=i,!1))),e}getNodeById(t){return this.idMapping?.get(t)??null}getNodeByName(t){return this.getNodeByCallback(e=>e.name===t)}getNodeByNameMustExist(t){let e=this.getNodeByCallback(e=>e.name===t);if(!e)throw new Error(`Node with name ${t} not found`);return e}getNodesByProperty(t,e){return this.filter(i=>i[t]===e)}getParent(){return this.parent&&this.parent.parent?this.parent:null}getPreviousNode(){if(this.parent){let t=this.getPreviousSibling();return t?t.hasChildren()?t.getLastChild():t:this.getParent()}return null}getPreviousSibling(){if(this.parent){let t=this.parent.getChildIndex(this)-1;return t>=0?this.parent.children[t]??null:null}return null}getPreviousVisibleNode(){if(this.parent){let t=this.getPreviousSibling();return t?t.hasChildren()&&t.is_open?t.getLastChild():t:this.getParent()}return null}hasChildren(){return 0!==this.children.length}initFromData(t){let e=t=>{for(let e of t){let t=this.We();t.initFromData(e),this.addChild(t)}};(t=>{this.setData(t),_(t)&&t.children.length&&e(t.children)})(t)}isFolder(){return this.hasChildren()||this.load_on_demand}isParentOf(t){let e=t.parent;for(;e;){if(e===this)return!0;e=e.parent}return!1}iterate(t){let e=(i,s)=>{for(let r of i.children){t(r,s)&&r.hasChildren()&&e(r,s+1)}};e(this,0)}loadFromData(t){this.removeChildren();for(let e of t){let t=this.We(e);this.addChild(t),_(e)&&t.loadFromData(e.children)}return this}moveNode(t,e,i){if(!t.parent||t.isParentOf(e))return!1;switch(t.parent.ei(t),i){case"after":return!!e.parent&&(e.parent.addChildAtPosition(t,e.parent.getChildIndex(e)+1),!0);case"before":return!!e.parent&&(e.parent.addChildAtPosition(t,e.parent.getChildIndex(e)),!0);case"inside":return e.addChildAtPosition(t,0),!0}}prepend(t){let e=this.We(t);return this.addChildAtPosition(e,0),e.Ze(t),e}remove(){this.parent&&(this.parent.removeChild(this),this.parent=null)}removeChild(t){t.removeChildren(),this.ei(t)}removeChildren(){this.iterate(t=>(this.tree?.removeNodeFromIndex(t),!0)),this.children=[]}removeNodeFromIndex(t){null!=t.id&&this.idMapping?.delete(t.id)}setData(t){if(t)if("string"==typeof t)this.name=t;else if("object"==typeof t)for(let e in t)if(Object.prototype.hasOwnProperty.call(t,e)){let i=t[e];"label"===e||"name"===e?"string"==typeof i&&(this.name=i):"children"!==e&&"parent"!==e&&(this[e]=i)}}We(t){return new(this.ii())(t)}ei(t){this.children.splice(this.getChildIndex(t),1),this.tree?.removeNodeFromIndex(t)}ii(){return this.nodeClass??this.tree?.nodeClass??m}Ze(t){_(t)&&t.children.length&&this.loadFromData(t.children)}ti(t){this.parent=t,this.tree=t.tree,this.tree?.addNodeToIndex(this)}}class f{constructor(t,e,i){let s=t.querySelector(`:scope > .${i.element}`);if(!s)return void(this.si=void 0);let r=Math.max(t.offsetWidth+e-4,0),h=Math.max(t.clientHeight-4,0),n=document.createElement("span");n.className=i.border,n.style.width=`${r}px`,n.style.height=`${h}px`,this.si=n,s.append(this.si)}remove(){this.si?.remove()}}class g{constructor(t,e,i,s){switch(this.t=s,this.C=e,this.ot=t,this.ri=this.hi(),i){case"after":this.ni();break;case"before":this.oi();break;case"inside":t.isFolder()&&t.is_open?this.li():this.ai()}}remove(){this.ri.remove()}hi(){let{circle:t,common:e,ghost:i,line:s}=this.t,r=document.createElement("li");r.className=`${e} ${i}`;let h=document.createElement("span");h.className=`${e} ${t}`,r.append(h);let n=document.createElement("span");return n.className=`${e} ${s}`,r.append(n),r}ni(){this.C.after(this.ri)}oi(){this.C.before(this.ri)}ai(){this.C.after(this.ri),this.ri.classList.add(this.t.inside)}li(){let t=this.ot.children[0]?.element;t&&t.before(this.ri)}}class p{constructor({t:t,P:e,ot:i,Pt:s,o:r}){this.t=t,this.P=e,this.ot=i,this.Pt=s,this.o=r,this.C=i.element??this.o}Tt(t){return this.di(t)?new f(this.C,this.P(),this.t):new g(this.ot,this.C,t,this.t)}ui(){if(!this.ci())return;this.C.classList.remove(this.t.selected);let t=this._i();t.removeAttribute("tabindex"),t.setAttribute("aria-selected","false"),t.blur()}mi(t){if(!this.ci())return;this.C.classList.add(this.t.selected);let e=this._i(),i=this.Pt;null!=i&&e.setAttribute("tabindex",i.toString()),e.setAttribute("aria-selected","true"),t&&e.focus()}_i(){return this.C.querySelector(`:scope > .${this.t.element} > span.${this.t.title}`)}fi(){return this.C.querySelector(":scope > ul")}ci(){return Boolean(this.ot.element)}di(t){return"inside"===t}}let N=t=>"number"==typeof t?t:"slow"===t?600:200;class v extends p{constructor({t:t,Ut:e,P:i,ot:s,Ot:r,te:h,Pt:n,o:o,l:l}){super({t:t,P:i,ot:s,Pt:n,o:o}),this.Ut=e,this.Ot=r,this.te=h,this.l=l}gi(t,e){if(!this.ot.is_open)return;if(this.ot.is_open=!1,!this.ci())return void this.l("tree.close",{node:this.ot});let i=this.pi();i.classList.add(this.t.closed),i.innerHTML="";let s=this.Ut;if(s){let t=s.cloneNode(!0);i.appendChild(t)}let r=()=>{this.C.classList.add(this.t.closed),this._i().setAttribute("aria-expanded","false"),this.l("tree.close",{node:this.ot})},h=this.fi();h?t?((t,e,i)=>{t.animate([{height:`${t.scrollHeight}px`,overflow:"hidden"},{height:"0",overflow:"hidden"}],{duration:N(e)}).onfinish=()=>{t.style.display="none",i()}})(h,e,r):(h.style.display="none",r()):r()}async Ni(t,e){return new Promise(i=>{if(this.ot.is_open)return void i();if(this.ot.is_open=!0,!this.ci())return this.l("tree.open",{node:this.ot}),void i();let s=this.pi();s.classList.remove(this.t.closed),s.innerHTML="";let r=this.Ot;if(r){let t=r.cloneNode(!0);s.appendChild(t)}let h=()=>{this.C.classList.remove(this.t.closed),this._i().setAttribute("aria-expanded","true"),this.l("tree.open",{node:this.ot}),i()},n=this.fi()??this.te(this.ot);n?t?((t,e,i)=>{t.style.display="block",t.animate([{height:"0",overflow:"hidden"},{height:`${t.scrollHeight}px`,overflow:"hidden"}],{duration:N(e)}).onfinish=()=>{i()}})(n,e,h):(n.style.display="block",h()):h()})}di(t){return!this.ot.is_open&&"inside"===t}pi(){return this.C.querySelector(`:scope > .${this.t.element} > a.${this.t.toggler}`)}}let S="http://localhost";class w{constructor(t){(t=>{try{return new URL(t),!0}catch{return!1}})(t)?(this.Si=new URL(t),this.wi=!0):(this.Si=new URL(t,S),this.wi=!1)}p(t,e){this.Si.searchParams.set(t,e)}N(){return this.wi?this.Si.href:this.Si.href.slice(16)}}class E{constructor({Ei:t,yi:e,bi:i,O:s,Di:r,Fi:h,X:n,G:o,Ci:l,Ti:a}){this.Ei=t,this.yi=e,this.bi=i,this.O=s,this.Di=r,this.Fi=h,this.X=n,this.G=o,this.Ci=l,this.$i=a}Mi(){if(!this.$i)return null;let t=this.Ii();return t?.selected_node?t.selected_node[0]??null:null}xi(){return{open_nodes:(()=>{let t=[];return this.O()?.iterate(e=>(e.is_open&&e.id&&e.hasChildren()&&t.push(e.id),!0)),t})(),selected_node:(()=>{let t=[];return this.bi().forEach(e=>{null!=e.id&&t.push(e.id)}),t})()}}Ii(){if(!this.$i)return null;let t=this.ki();return t?this.Li(t):null}Ti(){if(!this.$i)return;let t=JSON.stringify(this.xi());this.Fi?this.Fi(t):localStorage.setItem(this.Bi(),t)}ji(t){let e=!1;return t.open_nodes&&(e=this.Hi(t.open_nodes)),this.Ai(),t.selected_node&&this.Pi(t.selected_node),e}async Oi(t){let e=t.open_nodes,i=async()=>{if(!e)return;let i=[];for(let t of e){let e=this.yi(t);e?e.is_loading||(e.load_on_demand?await s(e):await this.X(e,!1)):i.push(t)}e=i,t.selected_node&&this.Pi(t.selected_node)&&this.G(null)},s=async t=>{await this.X(t,!1),await i()};await i()}Bi(){return"string"==typeof this.$i?this.$i:"tree"}ki(){return this.Di?this.Di():localStorage.getItem(this.Bi())}Hi(t){let e=!1;for(let i of t){let t=this.yi(i);t&&(t.load_on_demand?e=!0:t.is_open=!0)}return e}Li(t){let e=JSON.parse(t);var i;return e.selected_node&&("number"==typeof(i=e.selected_node)&&i%1==0)&&(e.selected_node=[e.selected_node]),e}Ai(){this.bi().forEach(t=>{this.Ci(t)})}Pi(t){let e=0;for(let i of t){let t=this.yi(i);t&&(e+=1,this.Ei(t))}return 0!==e}}class y{constructor({Qi:t,Ui:e}){this.Qi=t,this.Ui=e}Ri(t){let e=this.qi(t);this.Vi!==e&&(this.Vi=e,null!=this.Yi&&window.clearTimeout(this.Yi),e&&(this.Yi=window.setTimeout(this.zi.bind(this),40)))}Ji(t){let e=this.Xi(t);this.Gi!==e&&(this.Gi=e,null!=this.Ki&&(window.clearTimeout(this.Ki),this.Ki=void 0),e&&(this.Ki=window.setTimeout(this.Wi.bind(this),40)))}P(){return this.Qi.scrollLeft}Zi(t){this.Qi.scrollTop=t}ts(){this.Vi=void 0,this.Gi=void 0}zi(){if(!this.Vi)return;let t="left"===this.Vi?-20:20;this.Qi.scrollBy({behavior:"instant",left:t,top:0}),this.Ui(),setTimeout(this.zi.bind(this),40)}Wi(){if(!this.Gi)return;let t="top"===this.Gi?-20:20;this.Qi.scrollBy({behavior:"instant",left:0,top:t}),this.Ui(),setTimeout(this.Wi.bind(this),40)}}class b extends y{ts(){super.ts(),this.Vi=void 0,this.Gi=void 0}qi(t){let e=s(this.Qi),i=this.Qi.getBoundingClientRect().width,r=e.left+i,h=e.left;return t>r-20?"right":t<h+20?"left":void 0}Xi(t){return t<this.es()?"top":t>this.ss()?"bottom":void 0}ss(){if(null==this.rs){let t=this.Qi.getBoundingClientRect().height;this.rs=this.es()+t}return this.rs}es(){return this.hs??=i(this.Qi),this.hs}}class D extends y{constructor({Ui:t,o:e}){super({Qi:document.documentElement,Ui:t}),this.o=e}Zi(t){let e=i(this.o);super.Zi(t+e)}ts(){super.ts(),this.ns=void 0,this.ls=void 0}qi(t){let e=t-this.Qi.scrollLeft<20;return t>window.innerWidth-20&&this.ds()?"right":e?"left":void 0}Xi(t){let e=this.Qi.scrollTop;return t-e<20?"top":window.innerHeight-(t-e)<20&&this.us()?"bottom":void 0}us(){return this.Qi.scrollTop+this.Qi.clientHeight<this.cs()}ds(){return this.Qi.scrollLeft+this.Qi.clientWidth<this._s()}cs(){return this.ns??=this.Qi.scrollHeight,this.ns}_s(){return this.ls??=this.Qi.scrollWidth,this.ls}}let F=t=>"auto"===t||"scroll"===t,C=t=>{let e=getComputedStyle(t);return F(e.overflowX)||F(e.overflowY)},T=(t,e)=>{let i=(t=>{if(C(t))return t;let e=t.parentElement;for(;e;){if(C(e))return e;e=e.parentElement}return null})(t);return i&&"HTML"!==i.tagName?new b({Qi:i,Ui:e}):new D({Ui:e,o:t})};class ${constructor({Ui:t,o:e}){this.Ui=t,this.fs=void 0,this.o=e}gs(t){this.Ji(t),this.Ri(t)}P(){return this.ps().P()}Zi(t){this.ps().Zi(t)}ts(){this.ps().ts()}Ri(t){this.ps().Ri(t.pageX)}Ji(t){this.ps().Ji(t.pageY)}ps(){return this.fs??=T(this.o,this.Ui),this.fs}}class M{constructor({yi:t,A:e,Ns:i,vs:s,Ss:r,Ti:h,l:n}){this.yi=t,this.A=e,this.Ns=i,this.vs=s,this.Ss=r,this.Ti=h,this.ws=new Set,this.Es=null,this.l=n}Ei(t){null!=t.id?this.ws.add(t.id):this.Es=t}yt(){this.ws.clear(),this.Es=null}ce(){let t=this.bi();return t.length?t[0]??null:null}bi(){if(this.Es)return[this.Es];{let t=[];return this.ws.forEach(e=>{let i=this.yi(e);i&&t.push(i)}),t}}ys(t){if(this.Es)return t.isParentOf(this.Es)?[this.Es]:[];{let e=[];return this.ws.forEach(i=>{let s=this.yi(i);s&&t.isParentOf(s)&&e.push(s)}),e}}kt(t){return null!=t.id?this.ws.has(t.id):!!this.Es&&this.Es===t}Ci(t,e=!1){null==t.id?this.Es===t&&(this.Es=null):(this.ws.delete(t.id),e&&t.iterate(()=>(null!=t.id&&this.ws.delete(t.id),!0)))}bs(t,e){let i={mustSetFocus:!0,mustToggle:!0,...e??{}};if(!(()=>{if(!this.vs())return!1;let e=this.Ns();return!e||e(t)})())return;let s=t=>{this.Ci(t),this.A(t).ui()};if(this.kt(t))i.mustToggle&&(s(t),this.l("tree.deselect",{node:t}));else{let e=this.ce();e&&s(e),this.Ei(t),this.Ss(t),this.A(t).mi(i.mustSetFocus),this.l("tree.select",{deselectedNode:e,node:t})}this.Ti()}}let I={animationSpeed:"fast",autoEscape:!0,autoOpen:!1,buttonLeft:!0,classPrefix:"tree-element",dragAndDrop:!1,keyboardSupport:!0,nodeClass:m,openFolderDelay:500,saveState:!1,selectable:!0,showEmptyFolder:!1,slide:!0,startDndDelay:300,tabIndex:0,useContextMenu:!0},x=t=>t.rtl?"◀":"►",k=t=>{let e=t.dataset.rtl;return""==e||"false"!==e&&Boolean(e)},L=(t,e,i)=>{let s=new CustomEvent(e,{bubbles:!0,cancelable:!0,detail:i});return t.dispatchEvent(s),!s.defaultPrevented};
/*
Tree-element 0.2.0
Copyright 2026 Marco Braak
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
@license
*/
class B{t;Ds;Fs;xt;Cs;Ts;$s;Ms;Is;xs;ks;Ls;Bs;js;Hs;constructor({htmlElement:t,overrideTriggerEventProvider:i,...s}){this.xt=t,this.Is=((t,e)=>{let i={...I,...e};return i.dataUrl??=t.dataset.url,i.rtl??=k(t),i.closedIcon??=x(i),i.openedIcon??="▼",i})(t,s),this.t=(({classPrefix:t,commonClassName:e,treeClassName:i})=>({border:`${t}-border`,circle:`${t}-circle`,closed:`${t}-closed`,common:e??`${t}-common`,dnd:`${t}-dnd`,dragging:`${t}-dragging`,element:`${t}-element`,folder:`${t}-folder`,ghost:`${t}-ghost`,inside:`${t}-inside`,line:`${t}-line`,loading:`${t}-loading`,moving:`${t}-moving`,rtl:`${t}-rtl`,selected:`${t}-selected`,title:`${t}-title`,titleButtonLeft:`${t}-title-button-left`,titleButtonRight:`${t}-title-button-right`,titleFolder:`${t}-title-folder`,toggler:`${t}-toggler`,togglerLeft:`${t}-toggler-left`,togglerRight:`${t}-toggler-right`,tree:i??t}))(this.Is),this.Hs=i??L,this.Cs=!1,this.js=new m({},!0),this.Ms=new WeakMap;let{autoEscape:r,buttonLeft:h,closedIcon:n,dataFilter:d,dragAndDrop:u,keyboardSupport:_,onCanMove:f,onCanMoveTo:g,onCreateLi:p,onDragMove:N,onDragStop:v,onGetStateFromStorage:S,onIsMoveHandle:w,onSetStateFromStorage:y,openedIcon:b,openFolderDelay:D,rtl:F,saveState:C,showEmptyFolder:T,slide:B,tabIndex:j}=this.Is,H=this.t,A=this.closeNode.bind(this),P=this.H.bind(this),O=this.A.bind(this),Q=this.getNodeById.bind(this),U=this.getSelectedNode.bind(this),R=this.getTree.bind(this),q=this._e.bind(this),V=this.loadData.bind(this),Y=this.openNode.bind(this),z=this.Ss.bind(this),J=this.G.bind(this),X=this.refreshHitAreas.bind(this),G=this.Ht.bind(this),K=this.xt,W=this.l.bind(this),Z=new M({yi:Q,A:O,Ns:()=>this.Is.onCanSelectNode,vs:()=>this.Is.selectable,Ss:z,Ti:()=>{nt.Ti()},l:W}),tt=Z.Ei.bind(Z),et=Z.bi.bind(Z),it=Z.kt.bind(Z),st=Z.Ci.bind(Z),rt=Z.bs.bind(Z),ht=new e({t:H,i:d,h:V,o:K,l:W}),nt=new E({Ei:tt,yi:Q,bi:et,O:R,Di:S,Fi:y,X:Y,G:J,Ci:st,Ti:C}),ot=new $({Ui:X,o:K}),lt=ot.P.bind(ot),at=new o({v:r,t:H,H:P,A:O,P:lt,O:R,U:f,R:g,q:N,V:v,Y:w,J:D,X:Y,G:J,K:B,o:K,l:W}),dt=new a({ue:A,ce:U,_e:q,me:_,X:Y,fe:rt}),ut=new l({v:r,$t:h,t:H,Mt:n,It:u,O:R,xt:K,kt:it,Lt:p,Bt:b,jt:F,Ht:G,At:T,Pt:j}),ct=this.getNode.bind(this),_t=this.ht.bind(this),mt=this.lt.bind(this),ft=this.vt.bind(this),gt=this.wt.bind(this),pt=new c({t:H,C:K,ye:()=>this.Is.startDndDelay??0,be:ct,De:this.toggle.bind(this),Fe:rt,Ce:_t,Te:mt,$e:ft,Me:gt,l:W,Ie:this.Is.useContextMenu});this.Ds=ht,this.Fs=at,this.Ts=dt,this.$s=pt,this.xs=ut,this.ks=nt,this.Ls=ot,this.Bs=Z,this.As()}addNodeAfter(t,e){let i=e.addAfter(t);return i&&this.G(e.parent),i}addNodeBefore(t,e){let i=e.addBefore(t);return i&&this.G(e.parent),i}addParentNode(t,e){let i=e.addParent(t);return i&&this.G(i.parent),i}addToSelection(t,e){this.Bs.Ei(t),this.Ss(t),this.A(t).mi(e??!0),this.Ti()}appendNode(t,e){let i=e.append(t);return this.G(e),i}closeNode(t,e){(t.isFolder()||t.isEmptyFolder)&&(this.Ps(t).gi(e??this.Is.slide,this.Is.animationSpeed),this.Ti())}deinit(){this.xt.textContent="",this.Ds._(),this.Ts._(),this.$s._(),this.js=new m({},!0)}getNode(t){let e=t.closest(`li.${this.t.common}`);return e?this.Ms.get(e)??null:null}getNodeByCallback(t){return this.js.getNodeByCallback(t)}getNodeById(t){return this.js.getNodeById(t)}getNodeByName(t){return this.js.getNodeByName(t)}getNodeByNameMustExist(t){return this.js.getNodeByNameMustExist(t)}getNodesByProperty(t,e){return this.js.getNodesByProperty(t,e)}getSelectedNode(){return this.Bs.ce()}getSelectedNodes(){return this.Bs.bi()}getState(){return this.ks.xi()}getStateFromStorage(){return this.ks.Ii()}getTree(){return this.js}getVersion(){return"0.2.0"}isDragging(){return this.Fs.tt}isNodeSelected(t){return this.Bs.kt(t)}loadData(t,e){t&&(e?(this.Os(e),this.Qs(t,e)):this.Us(t),this.isDragging()&&this.Fs.St()),this.l("tree.set_data",{node:e,treeData:t??void 0})}async loadDataFromUrl(t,e){let i=t?new w(t):this.Rs(e);i&&await this.Ds.m(i,e)}moveDown(){this.Ts.Ne()}moveNode(t,e,i){this.js.moveNode(t,e,i),this.G(null)}moveUp(){this.Ts.ve()}async openNode(t,e){let i=e??this.Is.slide,s=async(e,i)=>{if(!t.children.length)return;let s=this.Ps(e);await s.Ni(i,this.Is.animationSpeed)};if(t.isFolder()||t.isEmptyFolder)if(t.load_on_demand)await this.qs(t,i);else{let e=t.parent;for(;e;)e.parent&&await s(e,!1),e=e.parent;await s(t,i),this.Ti()}}prependNode(t,e){let i=e.prepend(t);return this.G(e),i}refresh(){this.G(null)}refreshHitAreas(){this.Fs.St()}removeFromSelection(t){this.Bs.Ci(t),this.A(t).ui(),this.Ti()}removeNode(t){this.Bs.Ci(t,!0);let e=t.parent;t.remove(),this.G(e)}scrollToNode(t){if(!t.element)return;let e=i(t.element)-i(this.xt);this.Ls.Zi(e)}selectNode(t,e){if(!t)return this.Vs(),void this.ks.Ti();this.Bs.bs(t,e)}setOption(t,e){this.Is[t]=e}setState(t){this.ks.ji(t),this.G(null),this.Ti()}toggle(t,e=null){let i=e??this.Is.slide;t.is_open?this.closeNode(t,i):this.openNode(t,i)}toJson(){return JSON.stringify(this.js.getData())}updateNode(t,e){let i="object"==typeof e&&e.id&&e.id!==t.id;i&&this.js.removeNodeFromIndex(t),t.setData(e),i&&this.js.addNodeToIndex(t),"object"==typeof e&&e.children&&e.children instanceof Array&&(t.removeChildren(),e.children.length&&t.loadFromData(e.children)),this.G(t)}Ps(t){let e=this.t,i=this.xs.Ut,s=this.Ls.P.bind(this.Ls),r=this.xs.Ot,h=this.xs.te.bind(this.xs),n=this.Is.tabIndex,o=this.xt,l=this.l.bind(this);return new v({t:e,Ut:i,P:s,ot:t,Ot:r,te:h,Pt:n,o:o,l:l})}Ys(t){let e=this.t,i=this.Ls.P.bind(this.Ls),s=this.Is.tabIndex,r=this.xt;return new p({t:e,P:i,ot:t,Pt:s,o:r})}Rs(t){let e,i=this.Is.dataUrl;if(e="function"==typeof i?i(t):i,!e)return null;let s=new w(e);if(t?.id)s.p("node",t.id.toString());else{let t=this.Mi();t&&s.p("selected_node",t.toString())}return s}Vs(){let t=this.getSelectedNode();t&&this.removeFromSelection(t)}Os(t){let e=this.Bs.ys(t);for(let t of e)this.Bs.Ci(t)}zs(){return!0===this.Is.autoOpen?-1:"number"==typeof this.Is.autoOpen?this.Is.autoOpen:"string"==typeof this.Is.autoOpen?parseInt(this.Is.autoOpen,10):0}H(t){let e=this.getNode(t);return e?this.A(e):null}A(t){return t.isFolder()?this.Ps(t):this.Ys(t)}Mi(){return this.ks.Mi()}As(){if(this.Is.data)this.loadData(this.Is.data);else{this.Rs()?this.loadDataFromUrl():this.loadData([])}}Us(t){let e=()=>{this.Cs||(this.Cs=!0,this.l("tree.init"))};this.js=new this.Is.nodeClass(null,!0,this.Is.nodeClass),this.Bs.yt(),this.js.loadFromData(t);let i=this.ji();this.G(null),i?this.Oi().then(e):e()}_e(){let t=document.activeElement;if(!t)return!1;let e=t.tagName;if("A"!==e&&"SPAN"!==e)return!1;let i=this.getNode(t);return i?.tree===this.js}Js(t){let e=this.getSelectedNode();return!!e&&(t===e||t.isParentOf(e))}async qs(t,e){t.is_loading=!0,await this.loadDataFromUrl(void 0,t),await this.openNode(t,e)}Qs(t,e){e.loadFromData(t),e.load_on_demand=!1,e.is_loading=!1,this.G(e)}ht(t){return!!this.Is.dragAndDrop&&this.Fs.ht(t)}lt(t){if(!this.Is.dragAndDrop)return!1;let e=this.Fs.lt(t);return this.Ls.gs(t),e}vt(t){return!!this.Is.dragAndDrop&&this.Fs.vt(t)}wt(t){return!!this.Is.dragAndDrop&&(this.Ls.ts(),this.Fs.wt(t))}Ss(t){let e=t.parent;e?.parent&&!e.is_open&&this.openNode(e,!1)}G(t){let e=this._e(),i=!!t&&this.Js(t);this.xs.Kt(t),i&&this.Xs(e),this.l("tree.refresh")}Ti(){this.ks.Ti()}Xs(t){let e=this.getSelectedNode();if(e){this.A(e).mi(t)}}ji(){let t=()=>{if(!1===this.Is.autoOpen)return!1;let t=this.zs(),e=!1;return this.js.iterate((i,s)=>i.load_on_demand?(e=!0,!1):!!i.hasChildren()&&(i.is_open=!0,s!==t)),e},[e,i]=(()=>{let t=this.ks.Ii();if(t){return[!0,this.ks.ji(t)]}return[!1,!1]})();return e||(i=t()),i}async Oi(){return new Promise(t=>{let e=()=>{let e=this.zs(),i=0,s=t=>{i+=1,this.openNode(t,!1).then(()=>{i-=1,r()})},r=()=>{this.js.iterate((t,i)=>t.load_on_demand?(t.is_loading||s(t),!1):(this.openNode(t,!1),i!==e)),0===i&&t()};r()};(()=>{let e=this.ks.Ii();return!!e&&(this.ks.Oi(e).then(()=>{t()}),!0)})()||e()})}Ht(t,e){this.Ms.set(t,e)}l(t,e){return this.Hs(this.xt,t,e)}}const j={deselectedNode:"deselected_node",moveInfo:"move_info",originalEvent:"click_event",parentNode:"parent_node",treeData:"tree_data"},H={doMove:"do_move",movedNode:"moved_node",originalEvent:"original_event",previousParent:"previous_parent",targetNode:"target_node"},A=(t,e)=>Object.fromEntries(Object.entries(t).map(([t,i])=>[e[t]??t,i])),P=(t,e,i)=>{const s=i?(t=>{const e=A(t,j);return e.move_info&&(e.move_info=A(e.move_info,H)),e})(i):{};let r;switch(s.element&&(s.$el=jQuery(s.element),delete s.element),e){case"tree.deselect":r=jQuery.Event("tree.select",{node:null,previous_node:s.node});break;case"tree.loaded_data":r=jQuery.Event("tree.loading_data",{...s,isLoading:!1,node:s.node??null});break;case"tree.loading_data":r=jQuery.Event("tree.loading_data",{...s,isLoading:!0,node:s.node??null});break;case"tree.set_data":s.parent_node=s.node,delete s.node,r=jQuery.Event("tree.load_data",s);break;default:r=jQuery.Event(e,s)}return jQuery(t).trigger(r),!r.isDefaultPrevented()},O="Node parameter is empty",Q="Parameter is empty: ";class U{C;Gs;o;constructor(t,e){this.C=jQuery(t),this.Gs=e}addNodeAfter(t,e){return this.o.addNodeAfter(t,e)}addNodeBefore(t,e){if(!e)throw Error(Q+"existingNode");return this.o.addNodeBefore(t,e)}addParentNode(t,e){if(!e)throw Error(Q+"existingNode");return this.o.addParentNode(t,e)}addToSelection(t,e){if(!t)throw Error(O);return this.o.addToSelection(t,e),this.C}appendNode(t,e){const i=e??this.o.getTree();return this.o.appendNode(t,i)}closeNode(t,e){if(!t)throw Error(O);return this.o.closeNode(t,e??void 0),this.C}deinit(){this.C.off(),this.o.deinit()}destroy(){this.deinit()}getNodeByCallback(t){return this.o.getNodeByCallback(t)}getNodeByHtmlElement(t){const e=t instanceof HTMLElement?t:t.get(0);return e?this.o.getNode(e):null}getNodeById(t){return this.o.getNodeById(t)}getNodeByName(t){return this.o.getNodeByName(t)}getNodeByNameMustExist(t){return this.o.getNodeByNameMustExist(t)}getNodesByProperty(t,e){return this.o.getNodesByProperty(t,e)}getSelectedNode(){return this.o.getSelectedNode()??!1}getSelectedNodes(){return this.o.getSelectedNodes()}getState(){return this.o.getState()}getStateFromStorage(){return this.o.getStateFromStorage()}getTree(){return this.o.getTree()}getVersion(){return"2.0.2"}init(){const t=this.C.get(0);this.C.on("tree.loading_data",this.Ks.bind(this)),this.C.on("tree.load_failed",this.Ws.bind(this));const e=this.Zs(),i=new B({...e,classPrefix:"jqtree",commonClassName:"jqtree_common",htmlElement:t,overrideTriggerEventProvider:P,treeClassName:"jqtree-tree"});this.o=i}isDragging(){return this.o.isDragging()}isNodeSelected(t){if(!t)throw Error(O);return this.o.isNodeSelected(t)}loadData(t,e){return this.o.loadData(t,e),this.C}loadDataFromUrl(t,e,i){let s,r,h;return"string"==typeof t?(h=t,s=e,r=i):(s=t,r=e),this.o.loadDataFromUrl(h,s).then(()=>{r&&r()}).catch(t=>{throw t}),this.C}moveDown(){return this.o.moveDown(),this.C}moveNode(t,e,i){if(!t)throw Error(O);if(!e)throw Error(Q+"targetNode");if(!i)throw Error(Q+"position");return this.o.moveNode(t,e,i),this.C}moveUp(){return this.o.moveUp(),this.C}openNode(t,e,i){if(!t)throw Error(O);let s,r=null;return"function"==typeof e?(r=e,s=i):s=e,this.o.openNode(t,s).then(()=>{r&&r(t)}),this.C}prependNode(t,e){const i=e??this.o.getTree();return this.o.prependNode(t,i)}refresh(){return this.o.refresh(),this.C}reload(t){return this.o.loadDataFromUrl(void 0,void 0).then(()=>{t&&t()}).catch(t=>{throw t}),this.C}removeFromSelection(t){if(!t)throw Error(O);return this.o.removeFromSelection(t),this.C}removeNode(t){if(!t)throw Error(O);if(!t.parent)throw Error("Node has no parent");return this.o.removeNode(t),this.C}scrollToNode(t){if(!t)throw Error(O);return this.o.scrollToNode(t),this.C}selectNode(t,e){return this.o.selectNode(t,e),this.C}setOption(t,e){return this.o.setOption(t,e),this.C}setState(t){return t&&this.o.setState(t),this.C}toggle(t,e=null){if(!t)throw Error(O);return this.o.toggle(t,e),this.C}toJson(){return this.o.toJson()}updateNode(t,e){if(!t)throw Error(O);return e?(this.o.updateNode(t,e),this.C):this.C}Ws(t){const e=this.Gs.onLoadFailed;if(e){const{error:i,response:s}=t;e({error:i,response:s})}}Ks(t){const e=this.Gs.onLoading;if(e){const{$el:i,isLoading:s,node:r}=t;e(s,r??void 0,i)}}Zs(){function t(t){return t instanceof jQuery?t.get(0):t}const e=t(this.Gs.closedIcon),i=t(this.Gs.openedIcon);let s;const r=this.Gs.onCreateLi;let h;r&&(s=(t,e,i)=>{r(t,jQuery(e),i)});const n=this.Gs.onIsMoveHandle;return n&&(h=t=>n(jQuery(t))),{...this.Gs,closedIcon:e,onCreateLi:s,onIsMoveHandle:h,openedIcon:i}}}return(()=>{const t=(t,e)=>{const i=jQuery.data(t,e);return i&&i instanceof U?i:null},e=(e,i)=>{for(const s of e.get()){if(!t(s,"jqtree")){const t=new U(s,i??{});jQuery.data(s,"jqtree")||jQuery.data(s,"jqtree",t),t.init()}}return e};jQuery.fn.tree=function(i,...s){if(!i)return e(this,null);if("object"==typeof i){return e(this,i)}if("string"==typeof i&&"_"!==i[0]){const e=i;return"destroy"===i?void(e=>{for(const i of e.get()){const e=t(i,"jqtree");e&&e.destroy(),jQuery.removeData(i,"jqtree")}})(this):((t,e,i)=>{let s=null;for(const r of t.get()){const t=jQuery.data(r,"jqtree");if(t&&t instanceof U){const r=t[e];r&&"function"==typeof r&&(s=r.apply(t,i))}}return s})(this,e,s)}}})(),t.JqTreeWidget=U,t}({});
//# sourceMappingURL=tree.jquery.js.map