jqtree 1.9.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bower.json +1 -1
- package/js-coverage/coverage-final.json +13 -0
- package/lib/jqtreeOptions.js +1 -0
- package/lib/tree.jquery.d.js +0 -0
- package/lib/tree.jquery.js +394 -0
- package/lib/triggerJQueryEvent.js +68 -0
- package/lib/typings.d.js +1 -0
- package/lib/version.js +2 -0
- package/package.json +34 -29
- package/pnpm-workspace.yaml +3 -3
- package/src/jqtreeOptions.ts +20 -62
- package/src/tree.jquery.d.ts +81 -92
- package/src/tree.jquery.ts +234 -938
- package/src/triggerJQueryEvent.ts +97 -0
- package/src/version.ts +2 -2
- package/tree.jquery.debug.js +4226 -3281
- package/tree.jquery.debug.js.map +1 -1
- package/tree.jquery.js +22 -2
- package/tree.jquery.js.map +1 -1
- package/eslint.config.mjs +0 -112
- package/src/animation.ts +0 -48
- package/src/dataLoader.ts +0 -143
- package/src/dragAndDropHandler/binarySearch.ts +0 -27
- package/src/dragAndDropHandler/dragElement.ts +0 -54
- package/src/dragAndDropHandler/generateHitAreas.ts +0 -195
- package/src/dragAndDropHandler/index.ts +0 -432
- package/src/dragAndDropHandler/iterateVisibleNodes.ts +0 -91
- package/src/dragAndDropHandler/types.ts +0 -12
- package/src/elementsRenderer.ts +0 -359
- package/src/jqtreeMethodTypes.ts +0 -40
- package/src/keyHandler.ts +0 -139
- package/src/mouseHandler.ts +0 -383
- package/src/mouseUtils.ts +0 -23
- package/src/node.ts +0 -653
- package/src/nodeElement/borderDropHint.ts +0 -32
- package/src/nodeElement/folderElement.ts +0 -138
- package/src/nodeElement/ghostDropHint.ts +0 -74
- package/src/nodeElement/index.ts +0 -94
- package/src/nodeUtils.ts +0 -10
- package/src/positionUtils.ts +0 -18
- package/src/saveStateHandler.ts +0 -276
- package/src/scrollHandler/containerScrollParent.ts +0 -71
- package/src/scrollHandler/createScrollParent.ts +0 -51
- package/src/scrollHandler/documentScrollParent.ts +0 -104
- package/src/scrollHandler/scrollParent.ts +0 -117
- package/src/scrollHandler.ts +0 -55
- package/src/selectNodeHandler.ts +0 -111
- package/src/simple.widget.ts +0 -134
- package/src/util.ts +0 -5
package/tree.jquery.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
JqTree
|
|
2
|
+
JqTree 2.0.0
|
|
3
3
|
|
|
4
4
|
Copyright 2026 Marco Braak
|
|
5
5
|
|
|
@@ -17,5 +17,25 @@ limitations under the License.
|
|
|
17
17
|
@license
|
|
18
18
|
|
|
19
19
|
*/
|
|
20
|
-
var jqtree=function(t){"use strict";class e{t;i;o;h;l;u;constructor({dataFilter:t,loadData:e,onLoadFailed:s,onLoading:i,treeElement:o,triggerEvent:n}){this.t=t,this.i=e,this.o=s,this.h=i,this.l=o,this.u=n}loadFromUrl(t,e,s){if(!t)return;const i=this.m(e);this._(i),this.p(!0,e,i);const o=()=>{this.v(i),this.p(!1,e,i)};this.S(t,t=>{o(),this.i(this.N(t),e),s&&"function"==typeof s&&s()},t=>{o(),this.o&&this.o(t)})}_(t){t.classList.add("jqtree-loading")}m(t){return t?.element?t.element:this.l}p(t,e,s){const i=jQuery(s);this.h&&this.h(t,e,i),this.u("tree.loading_data",{$el:i,isLoading:t,node:e})}N(t){return this.t?this.t(t):t}v(t){t.classList.remove("jqtree-loading")}S(t,e,s){const i={cache:!1,dataType:"json",error:s,method:"GET",success:e,..."string"==typeof t?{url:t}:t};i.method=i.method?.toUpperCase()??"GET",jQuery.ajax(i)}}const s=t=>i(t).top,i=t=>{const e=t.getBoundingClientRect();return{left:e.x+window.scrollX,top:e.y+window.scrollY}};class o{j;D;F;constructor({autoEscape:t,nodeName:e,offsetX:s,offsetY:i,treeElement:o}){this.D=s,this.F=i,this.j=this.M(e,t),o.appendChild(this.j)}move(t,e){this.j.style.left=t-this.D+"px",this.j.style.top=e-this.F+"px"}remove(){this.j.remove()}M(t,e){const s=document.createElement("span");return s.classList.add("jqtree-title","jqtree-dragging"),e?s.textContent=t:s.innerHTML=t,s.style.position="absolute",s}}const n=(t,e,s,i)=>{const o=Math.min(e.length,4),n=Math.round((i-s)/o);let r=s;for(let s=0;s<o;s++){const i=e[s];i.position&&t.push({bottom:r+n,node:i.node,position:i.position,top:r}),r+=n}},r=(t,e,i)=>((t,e)=>{if(!t.length)return[];let s=t[0].top,i=[];const o=[];for(const e of t)e.top!==s&&i.length&&(n(o,i,s,e.top),s=e.top,i=[]),i.push(e);return n(o,i,s,e),o})(((t,e)=>{const i=[];let o=0;const n=(t,e,s)=>{i.push({node:t,position:e,top:s}),o=s};return((t,{handleAfterOpenFolder:e,handleClosedFolder:s,handleFirstNode:i,handleNode:o,handleOpenFolder:n})=>{let r=!0;const h=(t,l)=>{let c=(t.is_open||!t.element)&&t.hasChildren(),d=null;if(t.element?.offsetParent&&(d=t.element,r&&(i(t),r=!1),t.hasChildren()?t.is_open?n(t,t.element)||(c=!1):s(t,l,d):o(t,l,t.element)),c){const s=t.children.length;t.children.forEach((e,i)=>{const o=t.children[i];if(o)if(i===s-1)h(o,null);else{const e=t.children[i+1];e&&h(o,e)}}),t.is_open&&d&&e(t,l)}};h(t,null)})(t,{handleAfterOpenFolder:(t,s)=>{n(t,t===e||s===e?null:"after",o)},handleClosedFolder:(t,i,o)=>{const r=s(o);t===e?n(t,null,r):(n(t,"inside",r),i!==e&&n(t,"after",r))},handleFirstNode:t=>{t!==e&&t.element&&n(t,"before",s(t.element))},handleNode:(t,i,o)=>{const r=s(o);n(t,t===e?null:"inside",r),n(t,i===e||t===e?null:"after",r)},handleOpenFolder:(t,i)=>{if(t===e){const e=s(i),o=i.clientHeight;return n(t,null,e),o>5&&n(t,null,e+o-5),!1}return t.children[0]!==e&&n(t,"inside",s(i)),!0}}),i})(t,e),i);class h{currentItem;hitAreas;hoveredArea;isDragging;T;I;C;q;L;k;H;A;B;O;P;U;$;G;V;Y;R;l;u;constructor({autoEscape:t,getNodeElement:e,getNodeElementForNode:s,getScrollLeft:i,getTree:o,onCanMove:n,onCanMoveTo:r,onDragMove:h,onDragStop:l,onIsMoveHandle:c,openFolderDelay:d,openNode:a,refreshElements:u,slide:m,treeElement:f,triggerEvent:g}){this.T=t,this.C=e,this.q=s,this.L=i,this.k=o,this.H=n,this.A=r,this.B=h,this.O=l,this.P=c,this.U=d,this.G=a,this.Y=u,this.R=m,this.l=f,this.u=g,this.hoveredArea=null,this.hitAreas=[],this.isDragging=!1,this.currentItem=null}mouseCapture(t){const e=t.target;if(!this.X(e))return null;if(this.P&&!this.P(jQuery(e)))return null;let s=this.C(e);return s&&this.H&&(this.H(s.node)||(s=null)),this.currentItem=s,null!=this.currentItem}mouseDrag(t){if(!this.currentItem||!this.I)return!1;this.I.move(t.pageX,t.pageY);const e=this.J(t.pageX,t.pageY);return e&&this.K(e,this.currentItem)?(e.node.isFolder()||this.W(),this.hoveredArea!==e&&(this.hoveredArea=e,this.Z(e)?this.tt(e.node):this.W(),this.et())):(this.st(),this.W(),this.hoveredArea=e),e||this.B&&this.B(this.currentItem.node,t.originalEvent),!0}mouseStart(t){if(!this.currentItem)return!1;this.refresh();const{left:e,top:s}=i(t.target),n=this.currentItem.node;return this.I=new o({autoEscape:this.T??!0,nodeName:n.name,offsetX:t.pageX-e,offsetY:t.pageY-s,treeElement:this.l}),this.isDragging=!0,this.currentItem.element.classList.add("jqtree-moving"),!0}mouseStop(t){this.it(t),this.ot(),this.nt(),this.st(),this.rt();const e=this.currentItem;return this.currentItem&&(this.currentItem.element.classList.remove("jqtree-moving"),this.currentItem=null),this.isDragging=!1,!this.hoveredArea&&e&&this.O&&this.O(e.node,t.originalEvent),!1}refresh(){if(this.rt(),this.currentItem){const t=this.currentItem.node;this.ht(t),this.currentItem=this.q(t),this.isDragging&&this.currentItem.element.classList.add("jqtree-moving")}}K(t,e){return!this.A||this.A(e.node,t.node,t.position)}ot(){this.I&&(this.I.remove(),this.I=null)}J(t,e){const s=this.lt();return t<s.left||e<s.top||t>s.right||e>s.bottom?null:function(t,e){let s=0,i=t.length;for(;s<i;){const o=s+i>>1,n=t[o];if(void 0===n)return null;const r=e(n);if(r>0)i=o;else{if(!(r<0))return n;s=o+1}}return null}(this.hitAreas,t=>e<t.top?1:e>t.bottom?-1:0)}ht(t){const e=this.k();this.hitAreas=e?r(e,t,this.lt().bottom):[]}lt(){const t=i(this.l),e=t.left+this.L(),s=t.top;return{bottom:s+this.l.clientHeight+16,left:e,right:e+this.l.clientWidth,top:s}}it(t){if(this.currentItem&&this.hoveredArea?.position&&this.K(this.hoveredArea,this.currentItem)){const e=this.currentItem.node,s=this.hoveredArea.node,i=this.hoveredArea.position,o=e.parent;"inside"===i&&(this.hoveredArea.node.is_open=!0);const n=()=>{const t=this.k();t&&(t.moveNode(e,s,i),this.l.textContent="",this.Y(null))};this.u("tree.move",{move_info:{do_move:n,moved_node:e,original_event:t.originalEvent,position:i,previous_parent:o,target_node:s}})&&n()}}X(t){const e=t.nodeName;return"INPUT"!==e&&"SELECT"!==e&&"TEXTAREA"!==e}Z(t){const e=t.node;return e.isFolder()&&!e.is_open&&"inside"===t.position}st(){this.V&&this.V.remove()}rt(){this.hitAreas=[]}nt(){this.hoveredArea=null}tt(t){const e=()=>{this.G(t,this.R,()=>{this.refresh(),this.et()})};this.W();const s=this.U;!1!==s&&(this.$=window.setTimeout(e,s))}W(){this.$&&(clearTimeout(this.$),this.$=null)}et(){if(!this.hoveredArea)return;this.st();const t=this.q(this.hoveredArea.node);this.V=t.addDropHint(this.hoveredArea.position)}}const l=t=>t?"true":"false";class c{closedIconElement;openedIconElement;T;ct;dt;k;ut;ft;gt;_t;vt;St;constructor({autoEscape:t,buttonLeft:e,closedIcon:s,dragAndDrop:i,getTree:o,htmlElement:n,isNodeSelected:r,onCreateLi:h,openedIcon:l,rtl:c,showEmptyFolder:d,tabIndex:a}){this.T=t,this.ct=e,this.dt=i,this.k=o,this.ut=n,this.ft=r,this.gt=h,this._t=c,this.vt=d,this.St=a,this.openedIconElement=this.Nt(l??"+"),this.closedIconElement=this.Nt(s??"-")}render(t){t?.parent?this.renderFromNode(t):this.renderFromRoot()}renderFromNode(t){if(!t.element)return;const e=t.element,s=this.Et(t,t.getLevel());e.replaceWith(s),this.yt(s,t.children,!1,t.getLevel()+1)}renderFromRoot(){this.ut.textContent="";const t=this.k();t&&this.yt(this.ut,t.children,!0,1)}wt(t,e){t.element=e,jQuery(e).data("node",t)}Nt(t){if("string"==typeof t){const e=document.createElement("div");return e.innerHTML=t,document.createTextNode(e.innerHTML)}return t.nodeType?t:jQuery(t)[0]}yt(t,e,s,i){const o=this.bt(s);t.appendChild(o);for(const t of e){const e=this.Et(t,i);o.appendChild(e),t.hasChildren()&&this.yt(e,t.children,!1,i+1)}}jt(t,e,s){const i=this.Dt(t),o=this.Ft(t,s),n=t.is_open?this.openedIconElement:this.closedIconElement,r=document.createElement("li");r.className=`jqtree_common ${o}`,r.setAttribute("role","none");const h=document.createElement("div");h.className="jqtree-element jqtree_common",h.setAttribute("role","none"),r.appendChild(h);const c=document.createElement("a");c.className=i,n&&c.appendChild(n.cloneNode(!0)),this.ct&&h.appendChild(c);const d=this.Mt(t.name,s,!0,e);return d.setAttribute("aria-expanded",l(t.is_open)),h.appendChild(d),this.ct||h.appendChild(c),r}Et(t,e){const s=this.ft(t),i=t.isFolder()||t.isEmptyFolder&&this.vt?this.jt(t,e,s):this.Tt(t,e,s);return this.wt(t,i),this.gt&&this.gt(t,jQuery(i),s),i}Tt(t,e,s){const i=["jqtree_common"];s&&i.push("jqtree-selected");const o=i.join(" "),n=document.createElement("li");n.className=o,n.setAttribute("role","none");const r=document.createElement("div");r.className="jqtree-element jqtree_common",r.setAttribute("role","none"),n.appendChild(r);const h=this.Mt(t.name,s,!1,e);return r.appendChild(h),n}Mt(t,e,s,i){const o=document.createElement("span");let n="jqtree-title jqtree_common";if(s&&(n+=" jqtree-title-folder"),n+=" jqtree-title-button-"+(this.ct?"left":"right"),o.className=n,e){const t=this.St;void 0!==t&&o.setAttribute("tabindex",`${t}`)}return this.It(o,t,i,e),this.T?o.textContent=t:o.innerHTML=t,o}bt(t){let e,s;t?(e="jqtree-tree",s="tree",this._t&&(e+=" jqtree-rtl")):(e="",s="group"),this.dt&&(e+=" jqtree-dnd");const i=document.createElement("ul");return i.className=`jqtree_common ${e}`,i.setAttribute("role",s),i}Dt(t){const e=["jqtree-toggler","jqtree_common"];return t.is_open||e.push("jqtree-closed"),this.ct?e.push("jqtree-toggler-left"):e.push("jqtree-toggler-right"),e.join(" ")}Ft(t,e){const s=["jqtree-folder"];return t.is_open||s.push("jqtree-closed"),e&&s.push("jqtree-selected"),t.is_loading&&s.push("jqtree-loading"),s.join(" ")}It(t,e,s,i){t.setAttribute("aria-label",e),t.setAttribute("aria-level",`${s}`),t.setAttribute("aria-selected",l(i)),t.setAttribute("role","treeitem")}}class d{Ct;qt;Lt;xt;G;kt;constructor({closeNode:t,getSelectedNode:e,isFocusOnTree:s,keyboardSupport:i,openNode:o,selectNode:n}){this.Ct=t,this.qt=e,this.Lt=s,this.xt=i,this.G=o,this.kt=n,i&&document.addEventListener("keydown",this.Ht)}deinit(){this.xt&&document.removeEventListener("keydown",this.Ht)}moveDown(t){return this.At(t.getNextVisibleNode())}moveUp(t){return this.At(t.getPreviousVisibleNode())}Bt(){return this.xt&&this.Lt()}Ht=t=>{if(!this.Bt())return;let e=!1;const s=this.qt();if(s)switch(t.key){case"ArrowDown":e=this.moveDown(s);break;case"ArrowLeft":e=this.Ot(s);break;case"ArrowRight":e=this.Pt(s);break;case"ArrowUp":e=this.moveUp(s)}e&&t.preventDefault()};Ot(t){return t.isFolder()&&t.is_open?(this.Ct(t),!0):this.At(t.getParent())}Pt(t){return!!t.isFolder()&&(t.is_open?this.At(t.getNextVisibleNode()):(this.G(t),!0))}At(t){return!!t&&(this.kt(t),!0)}}const a=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 m{j;Qt;Ut;$t;Gt;zt;Vt;Yt;Rt;Xt;Jt;Kt;Wt;u;Zt;constructor({element:t,getMouseDelay:e,getNode:s,onClickButton:i,onClickTitle:o,onMouseCapture:n,onMouseDrag:r,onMouseStart:h,onMouseStop:l,triggerEvent:c,useContextMenu:d}){this.j=t,this.Qt=e,this.Ut=s,this.Yt=i,this.Rt=o,this.Xt=n,this.Jt=r,this.Kt=h,this.Wt=l,this.u=c,this.Zt=d,t.addEventListener("click",this.te),t.addEventListener("dblclick",this.ee),t.addEventListener("mousedown",this.se,{passive:!1}),t.addEventListener("touchstart",this.ie,{passive:!1}),d&&t.addEventListener("contextmenu",this.oe),this.Gt=!1,this.zt=null,this.$t=!1,this.Vt=null}deinit(){this.j.removeEventListener("click",this.te),this.j.removeEventListener("dblclick",this.ee),this.Zt&&this.j.removeEventListener("contextmenu",this.oe),this.j.removeEventListener("mousedown",this.se),this.j.removeEventListener("touchstart",this.ie),this.ne()}re(t){const e=t.closest(".jqtree-toggler");if(e){const t=this.Ut(e);if(t)return{node:t,type:"button"}}else{const e=t.closest(".jqtree-element");if(e){const t=this.Ut(e);if(t)return{node:t,type:"label"}}}return null}te=t=>{if(!t.target)return;const e=this.re(t.target);if(e)switch(e.type){case"button":this.Yt(e.node),t.preventDefault(),t.stopPropagation();break;case"label":this.u("tree.click",{click_event:t,node:e.node})&&this.Rt(e.node)}};oe=t=>{if(!t.target)return;const e=t.target.closest("ul.jqtree-tree .jqtree-element");if(e){const s=this.Ut(e);if(s)return t.preventDefault(),t.stopPropagation(),this.u("tree.contextmenu",{click_event:t,node:s}),!1}return null};ee=t=>{if(!t.target)return;const e=this.re(t.target);"label"===e?.type&&this.u("tree.dblclick",{click_event:t,node:e.node})};he(t){return this.Gt&&this.le(t),this.Vt=t,!!this.Xt(t)&&(this.ce(),!0)}de(t,e){if(this.Gt)return this.Jt(e),void(t.cancelable&&t.preventDefault());this.$t&&(this.Vt&&(this.Gt=this.Kt(this.Vt)),this.Gt?(this.Jt(e),t.cancelable&&t.preventDefault()):this.le(e))}le(t){this.ne(),this.$t=!1,this.Vt=null,this.Gt&&(this.Gt=!1,this.Wt(t))}ce(){document.addEventListener("mousemove",this.ae,{passive:!1}),document.addEventListener("touchmove",this.ue,{passive:!1}),document.addEventListener("mouseup",this.me,{passive:!1}),document.addEventListener("touchend",this.fe,{passive:!1});const t=this.Qt();t?this.ge(t):this.$t=!0}se=t=>{if(0!==t.button)return;this.he(a(t))&&t.cancelable&&t.preventDefault()};ae=t=>{this.de(t,a(t))};me=t=>{this.le(a(t))};ne(){document.removeEventListener("mousemove",this.ae),document.removeEventListener("touchmove",this.ue),document.removeEventListener("mouseup",this.me),document.removeEventListener("touchend",this.fe)}ge(t){this.zt&&clearTimeout(this.zt),this.zt=window.setTimeout(()=>{this.Vt&&(this.$t=!0)},t),this.$t=!1}fe=t=>{if(t.touches.length>1)return;const e=t.touches[0];e&&this.le(u(e,t))};ue=t=>{if(t.touches.length>1)return;const e=t.touches[0];e&&this.de(t,u(e,t))};ie=t=>{if(t.touches.length>1)return;const e=t.touches[0];e&&this.he(u(e,t))}}const f=t=>"object"==typeof t&&"children"in t&&t.children instanceof Array;class g{children;element;id;idMapping;is_loading;is_open;isEmptyFolder;load_on_demand;name;nodeClass;parent;tree;constructor(t=null,e=!1,s=g){this.name="",this.load_on_demand=!1,this.isEmptyFolder=null!=t&&f(t)&&0===t.children.length,this.setData(t),this.children=[],this.parent=null,e&&(this.idMapping=new Map,this.tree=this,this.nodeClass=s)}addAfter(t){if(this.parent){const e=this._e(t),s=this.parent.getChildIndex(this);return this.parent.addChildAtPosition(e,s+1),e.pe(t),e}return null}addBefore(t){if(this.parent){const e=this._e(t),s=this.parent.getChildIndex(this);return this.parent.addChildAtPosition(e,s),e.pe(t),e}return null}addChild(t){this.children.push(t),t.ve(this)}addChildAtPosition(t,e){this.children.splice(e,0,t),t.ve(this)}addNodeToIndex(t){null!=t.id&&this.idMapping.set(t.id,t)}addParent(t){if(this.parent){const e=this._e(t);this.tree&&e.ve(this.tree);const s=this.parent;for(const t of s.children)e.addChild(t);return s.children=[],s.addChild(e),e}return null}append(t){const e=this._e(t);return this.addChild(e),e.pe(t),e}filter(t){const e=[];return this.iterate(s=>(t(s)&&e.push(s),!0)),e}getChildIndex(t){return this.children.indexOf(t)}getData(t=!1){const e=t=>t.map(t=>{const s={};for(const e in t)if(-1===["parent","children","element","idMapping","load_on_demand","nodeClass","tree","isEmptyFolder"].indexOf(e)&&Object.prototype.hasOwnProperty.call(t,e)){const i=t[e];s[e]=i}return t.hasChildren()&&(s.children=e(t.children)),s});return e(t?[this]:this.children)}getLastChild(){if(this.hasChildren()){const 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){const t=this.getNextSibling();return t||this.parent.getNextNode(!1)}return null}getNextSibling(){if(this.parent){const 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){const t=this.getNextSibling();return t||this.parent.getNextNode(!1)}return null}getNodeByCallback(t){let e=null;return this.iterate(s=>!e&&(!t(s)||(e=s,!1))),e}getNodeById(t){return this.idMapping.get(t)??null}getNodeByName(t){return this.getNodeByCallback(e=>e.name===t)}getNodeByNameMustExist(t){const 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(s=>s[t]===e)}getParent(){return this.parent&&this.parent.parent?this.parent:null}getPreviousNode(){if(this.parent){const t=this.getPreviousSibling();return t?t.hasChildren()?t.getLastChild():t:this.getParent()}return null}getPreviousSibling(){if(this.parent){const t=this.parent.getChildIndex(this)-1;return t>=0?this.parent.children[t]??null:null}return null}getPreviousVisibleNode(){if(this.parent){const 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){const e=t=>{for(const e of t){const t=this._e();t.initFromData(e),this.addChild(t)}};(t=>{this.setData(t),f(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){const e=(s,i)=>{for(const o of s.children){t(o,i)&&o.hasChildren()&&e(o,i+1)}};e(this,0)}loadFromData(t){this.removeChildren();for(const e of t){const t=this._e(e);this.addChild(t),f(e)&&t.loadFromData(e.children)}return this}moveNode(t,e,s){if(!t.parent||t.isParentOf(e))return!1;switch(t.parent.Se(t),s){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){const e=this._e(t);return this.addChildAtPosition(e,0),e.pe(t),e}remove(){this.parent&&(this.parent.removeChild(this),this.parent=null)}removeChild(t){t.removeChildren(),this.Se(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(const e in t)if(Object.prototype.hasOwnProperty.call(t,e)){const s=t[e];"label"===e||"name"===e?"string"==typeof s&&(this.name=s):"children"!==e&&"parent"!==e&&(this[e]=s)}}_e(t){return new(this.Ne())(t)}Se(t){this.children.splice(this.getChildIndex(t),1),this.tree?.removeNodeFromIndex(t)}Ne(){return this.nodeClass??this.tree?.nodeClass??g}pe(t){f(t)&&t.children.length&&this.loadFromData(t.children)}ve(t){this.parent=t,this.tree=t.tree,this.tree?.addNodeToIndex(this)}}class _{Ee;constructor(t,e){const s=t.querySelector(":scope > .jqtree-element");if(!s)return void(this.Ee=void 0);const i=Math.max(t.offsetWidth+e-4,0),o=Math.max(t.clientHeight-4,0),n=document.createElement("span");n.className="jqtree-border",n.style.width=`${i}px`,n.style.height=`${o}px`,this.Ee=n,s.append(this.Ee)}remove(){this.Ee?.remove()}}class p{j;ye;we;constructor(t,e,s){switch(this.j=e,this.we=t,this.ye=this.be(),s){case"after":this.je();break;case"before":this.De();break;case"inside":t.isFolder()&&t.is_open?this.Fe():this.Me()}}remove(){this.ye.remove()}be(){const t=document.createElement("li");t.className="jqtree_common jqtree-ghost";const e=document.createElement("span");e.className="jqtree_common jqtree-circle",t.append(e);const s=document.createElement("span");return s.className="jqtree_common jqtree-line",t.append(s),t}je(){this.j.after(this.ye)}De(){this.j.before(this.ye)}Me(){this.j.after(this.ye),this.ye.classList.add("jqtree-inside")}Fe(){const t=this.we.children[0]?.element;t&&t.before(this.ye)}}class v{element;node;L;St;l;constructor({getScrollLeft:t,node:e,tabIndex:s,treeElement:i}){this.L=t,this.St=s,this.l=i,this.init(e)}addDropHint(t){return this.mustShowBorderDropHint(t)?new _(this.element,this.L()):new p(this.node,this.element,t)}deselect(){this.element.classList.remove("jqtree-selected");const t=this.getTitleSpan();t.removeAttribute("tabindex"),t.setAttribute("aria-selected","false"),t.blur()}init(t){this.node=t,t.element??=this.l,this.element=t.element}select(t){this.element.classList.add("jqtree-selected");const e=this.getTitleSpan(),s=this.St;null!=s&&e.setAttribute("tabindex",s.toString()),e.setAttribute("aria-selected","true"),t&&e.focus()}getTitleSpan(){return this.element.querySelector(":scope > .jqtree-element > span.jqtree-title")}getUl(){return this.element.querySelector(":scope > ul")}mustShowBorderDropHint(t){return"inside"===t}}const S=t=>"number"==typeof t?t:"slow"===t?600:200;class N extends v{Te;Ie;u;constructor({closedIconElement:t,getScrollLeft:e,node:s,openedIconElement:i,tabIndex:o,treeElement:n,triggerEvent:r}){super({getScrollLeft:e,node:s,tabIndex:o,treeElement:n}),this.Te=t,this.Ie=i,this.u=r}close(t,e){if(!this.node.is_open)return;this.node.is_open=!1;const s=this.Ce();s.classList.add("jqtree-closed"),s.innerHTML="";const i=this.Te;if(i){const t=i.cloneNode(!0);s.appendChild(t)}const o=()=>{this.element.classList.add("jqtree-closed");this.getTitleSpan().setAttribute("aria-expanded","false"),this.u("tree.close",{node:this.node})},n=this.getUl();t?((t,e,s)=>{t.animate([{height:`${t.scrollHeight}px`,overflow:"hidden"},{height:"0",overflow:"hidden"}],{duration:S(e)}).onfinish=()=>{t.style.display="none",s()}})(n,e,o):(n.style.display="none",o())}open(t,e,s){if(this.node.is_open)return;this.node.is_open=!0;const i=this.Ce();i.classList.remove("jqtree-closed"),i.innerHTML="";const o=this.Ie;if(o){const t=o.cloneNode(!0);i.appendChild(t)}const n=()=>{this.element.classList.remove("jqtree-closed");this.getTitleSpan().setAttribute("aria-expanded","true"),t&&t(this.node),this.u("tree.open",{node:this.node})},r=this.getUl();e?((t,e,s)=>{t.style.display="block",t.animate([{height:"0",overflow:"hidden"},{height:`${t.scrollHeight}px`,overflow:"hidden"}],{duration:S(e)}).onfinish=()=>{s()}})(r,s,n):(r.style.display="block",n())}mustShowBorderDropHint(t){return!this.node.is_open&&"inside"===t}Ce(){return this.element.querySelector(":scope > .jqtree-element > a.jqtree-toggler")}}class E{qe;Le;xe;k;ke;He;G;Y;Ae;Be;constructor({addToSelection:t,getNodeById:e,getSelectedNodes:s,getTree:i,onGetStateFromStorage:o,onSetStateFromStorage:n,openNode:r,refreshElements:h,removeFromSelection:l,saveState:c}){this.qe=t,this.Le=e,this.xe=s,this.k=i,this.ke=o,this.He=n,this.G=r,this.Y=h,this.Ae=l,this.Be=c}getNodeIdToBeSelected(){const t=this.getStateFromStorage();return t?.selected_node?t.selected_node[0]??null:null}getState(){return{open_nodes:(()=>{const t=[];return this.k()?.iterate(e=>(e.is_open&&e.id&&e.hasChildren()&&t.push(e.id),!0)),t})(),selected_node:(()=>{const t=[];return this.xe().forEach(e=>{null!=e.id&&t.push(e.id)}),t})()}}getStateFromStorage(){const t=this.Oe();return t?this.Pe(t):null}saveState(){const t=JSON.stringify(this.getState());this.He?this.He(t):localStorage.setItem(this.Qe(),t)}setInitialState(t){let e=!1;return t.open_nodes&&(e=this.Ue(t.open_nodes)),this.$e(),t.selected_node&&this.Ge(t.selected_node),e}setInitialStateOnDemand(t,e){let s=0,i=t.open_nodes;const o=()=>{if(!i)return;const o=[];for(const t of i){const e=this.Le(t);e?e.is_loading||(e.load_on_demand?n(e):this.G(e,!1)):o.push(t)}i=o,t.selected_node&&this.Ge(t.selected_node)&&this.Y(null),0===s&&e()},n=t=>{s+=1,this.G(t,!1,()=>{s-=1,o()})};o()}Qe(){return"string"==typeof this.Be?this.Be:"tree"}Oe(){return this.ke?this.ke():localStorage.getItem(this.Qe())}Ue(t){let e=!1;for(const s of t){const t=this.Le(s);t&&(t.load_on_demand?e=!0:t.is_open=!0)}return e}Pe(t){const e=JSON.parse(t);var s;return e.selected_node&&("number"==typeof(s=e.selected_node)&&s%1==0)&&(e.selected_node=[e.selected_node]),e}$e(){this.xe().forEach(t=>{this.Ae(t)})}Ge(t){let e=0;for(const s of t){const t=this.Le(s);t&&(e+=1,this.qe(t))}return 0!==e}}class y{container;horizontalScrollDirection;horizontalScrollTimeout;refreshHitAreas;verticalScrollDirection;verticalScrollTimeout;constructor({container:t,refreshHitAreas:e}){this.container=t,this.refreshHitAreas=e}checkHorizontalScrolling(t){const e=this.getNewHorizontalScrollDirection(t);this.horizontalScrollDirection!==e&&(this.horizontalScrollDirection=e,null!=this.horizontalScrollTimeout&&window.clearTimeout(this.horizontalScrollTimeout),e&&(this.horizontalScrollTimeout=window.setTimeout(this.scrollHorizontally.bind(this),40)))}checkVerticalScrolling(t){const e=this.getNewVerticalScrollDirection(t);this.verticalScrollDirection!==e&&(this.verticalScrollDirection=e,null!=this.verticalScrollTimeout&&(window.clearTimeout(this.verticalScrollTimeout),this.verticalScrollTimeout=void 0),e&&(this.verticalScrollTimeout=window.setTimeout(this.scrollVertically.bind(this),40)))}getScrollLeft(){return this.container.scrollLeft}scrollToY(t){this.container.scrollTop=t}stopScrolling(){this.horizontalScrollDirection=void 0,this.verticalScrollDirection=void 0}scrollHorizontally(){if(!this.horizontalScrollDirection)return;const t="left"===this.horizontalScrollDirection?-20:20;this.container.scrollBy({behavior:"instant",left:t,top:0}),this.refreshHitAreas(),setTimeout(this.scrollHorizontally.bind(this),40)}scrollVertically(){if(!this.verticalScrollDirection)return;const t="top"===this.verticalScrollDirection?-20:20;this.container.scrollBy({behavior:"instant",left:0,top:t}),this.refreshHitAreas(),setTimeout(this.scrollVertically.bind(this),40)}}class w extends y{ze;Ve;stopScrolling(){super.stopScrolling(),this.horizontalScrollDirection=void 0,this.verticalScrollDirection=void 0}getNewHorizontalScrollDirection(t){const e=i(this.container),s=this.container.getBoundingClientRect().width,o=e.left+s,n=e.left;return t>o-20?"right":t<n+20?"left":void 0}getNewVerticalScrollDirection(t){return t<this.Ye()?"top":t>this.Re()?"bottom":void 0}Re(){if(null==this.ze){const t=this.container.getBoundingClientRect().height;this.ze=this.Ye()+t}return this.ze}Ye(){return this.Ve??=s(this.container),this.Ve}}class b extends y{Xe;Je;l;constructor({refreshHitAreas:t,treeElement:e}){super({container:document.documentElement,refreshHitAreas:t}),this.l=e}scrollToY(t){const e=s(this.l);super.scrollToY(t+e)}stopScrolling(){super.stopScrolling(),this.Xe=void 0,this.Je=void 0}getNewHorizontalScrollDirection(t){const e=t-this.container.scrollLeft<20;return t>window.innerWidth-20&&this.Ke()?"right":e?"left":void 0}getNewVerticalScrollDirection(t){const e=this.container.scrollTop;if(t-e<20)return"top";return window.innerHeight-(t-e)<20&&this.We()?"bottom":void 0}We(){return this.container.scrollTop+this.container.clientHeight<this.Ze()}Ke(){return this.container.scrollLeft+this.container.clientWidth<this.ts()}Ze(){return this.Xe??=this.container.scrollHeight,this.Xe}ts(){return this.Je??=this.container.scrollWidth,this.Je}}const j=t=>"auto"===t||"scroll"===t,D=t=>{const e=getComputedStyle(t);return j(e.overflowX)||j(e.overflowY)},F=(t,e)=>{const s=(t=>{if(D(t))return t;let e=t.parentElement;for(;e;){if(D(e))return e;e=e.parentElement}return null})(t);return s&&"HTML"!==s.tagName?new w({container:s,refreshHitAreas:e}):new b({refreshHitAreas:e,treeElement:t})};class M{es;ss;l;constructor({refreshHitAreas:t,treeElement:e}){this.es=t,this.ss=void 0,this.l=e}checkScrolling(t){this.ns(t),this.rs(t)}getScrollLeft(){return this.hs().getScrollLeft()}scrollToY(t){this.hs().scrollToY(t)}stopScrolling(){this.hs().stopScrolling()}rs(t){this.hs().checkHorizontalScrolling(t.pageX)}ns(t){this.hs().checkVerticalScrolling(t.pageY)}hs(){return this.ss??=F(this.l,this.es),this.ss}}class T{Le;ls;cs;constructor({getNodeById:t}){this.Le=t,this.ls=new Set,this.clear()}addToSelection(t){null!=t.id?this.ls.add(t.id):this.cs=t}clear(){this.ls.clear(),this.cs=null}getSelectedNode(){const t=this.getSelectedNodes();return!!t.length&&(t[0]??!1)}getSelectedNodes(){if(this.cs)return[this.cs];{const t=[];return this.ls.forEach(e=>{const s=this.Le(e);s&&t.push(s)}),t}}getSelectedNodesUnder(t){if(this.cs)return t.isParentOf(this.cs)?[this.cs]:[];{const e=[];return this.ls.forEach(s=>{const i=this.Le(s);i&&t.isParentOf(i)&&e.push(i)}),e}}isNodeSelected(t){return null!=t.id?this.ls.has(t.id):!!this.cs&&this.cs.element===t.element}removeFromSelection(t,e=!1){null==t.id?this.cs&&t.element===this.cs.element&&(this.cs=null):(this.ls.delete(t.id),e&&t.iterate(()=>(null!=t.id&&this.ls.delete(t.id),!0)))}}const I=(t,e)=>{const s=()=>`simple_widget_${e}`,i=(t,e)=>{const s=jQuery.data(t,e);return s&&s instanceof C?s:null},o=(e,o)=>{const n=s();for(const s of e.get()){if(!i(s,n)){const e=new t(s,o);jQuery.data(s,n)||jQuery.data(s,n,e),e.init()}}return e};jQuery.fn[e]=function(t,...e){if(!t)return o(this,null);if("object"==typeof t){return o(this,t)}if("string"==typeof t&&"_"!==t[0]){const o=t;return"destroy"===t?void(t=>{const e=s();for(const s of t.get()){const t=i(s,e);t&&t.destroy(),jQuery.removeData(s,e)}})(this):((t,e,i)=>{let o=null;for(const n of t.get()){const t=jQuery.data(n,s());if(t&&t instanceof C){const s=t[e];s&&"function"==typeof s&&(o=s.apply(t,i))}}return o})(this,o,e)}}};class C{static defaults={};$el;options;constructor(t,e){this.$el=jQuery(t);const s=this.constructor.defaults;this.options={...s,...e}}static register(t,e){I(t,e)}deinit(){}destroy(){this.deinit()}init(){}}const q="Node parameter is empty",L="Parameter is empty: ";class x extends C{static defaults={animationSpeed:"fast",autoEscape:!0,autoOpen:!1,buttonLeft:!0,closedIcon:void 0,data:void 0,dataFilter:void 0,dataUrl:void 0,dragAndDrop:!1,keyboardSupport:!0,nodeClass:g,onCanMove:void 0,onCanMoveTo:void 0,onCanSelectNode:void 0,onCreateLi:void 0,onDragMove:void 0,onDragStop:void 0,onGetStateFromStorage:void 0,onIsMoveHandle:void 0,onLoadFailed:void 0,onLoading:void 0,onSetStateFromStorage:void 0,openedIcon:"▼",openFolderDelay:500,rtl:void 0,saveState:!1,selectable:!0,showEmptyFolder:!1,slide:!0,startDndDelay:300,tabIndex:0,useContextMenu:!0};ds;us;j;ut;fs;gs;_s;ps;vs;Ss;Ns;Es;addNodeAfter(t,e){const s=e.addAfter(t);return s&&this.Y(e.parent),s}addNodeBefore(t,e){if(!e)throw Error(L+"existingNode");const s=e.addBefore(t);return s&&this.Y(e.parent),s}addParentNode(t,e){if(!e)throw Error(L+"existingNode");const s=e.addParent(t);return s&&this.Y(s.parent),s}addToSelection(t,e){if(!t)throw Error(q);return this.Ns.addToSelection(t),this.ys(t),this.q(t).select(e??!0),this.ws(),this.j}appendNode(t,e){const s=e??this.Es,i=s.append(t);return this.Y(s),i}closeNode(t,e){if(!t)throw Error(q);const s=e??this.options.slide;return(t.isFolder()||t.isEmptyFolder)&&(this.bs(t).close(s,this.options.animationSpeed),this.ws()),this.j}deinit(){this.ut.textContent="",this.j.off(),this.gs.deinit(),this._s.deinit(),this.Es=new g({},!0),super.deinit()}getNodeByCallback(t){return this.Es.getNodeByCallback(t)}getNodeByHtmlElement(t){const e=t instanceof HTMLElement?t:t.get(0);return e?this.Ut(e):null}getNodeById(t){return this.Es.getNodeById(t)}getNodeByName(t){return this.Es.getNodeByName(t)}getNodeByNameMustExist(t){return this.Es.getNodeByNameMustExist(t)}getNodesByProperty(t,e){return this.Es.getNodesByProperty(t,e)}getSelectedNode(){return this.Ns.getSelectedNode()}getSelectedNodes(){return this.Ns.getSelectedNodes()}getState(){return this.vs.getState()}getStateFromStorage(){return this.vs.getStateFromStorage()}getTree(){return this.Es}getVersion(){return"1.9.0"}init(){super.init(),this.j=this.$el,this.ut=this.j.get(0),this.fs=!1,this.options.dataUrl??=this.j.data("url");const t=this.j.data("rtl");this.options.rtl??=""===t||Boolean(t),this.options.closedIcon??=this.js(),this.Ds(),this.Fs()}isDragging(){return this.us.isDragging}isNodeSelected(t){if(!t)throw Error(q);return this.Ns.isNodeSelected(t)}loadData(t,e){return this.Ms(t,e),this.j}loadDataFromUrl(t,e,s){return"string"==typeof t?this.Ts(t,e,s??null):this.Ts(null,t,e),this.j}moveDown(){const t=this.getSelectedNode();return t&&this.gs.moveDown(t),this.j}moveNode(t,e,s){if(!t)throw Error(q);if(!e)throw Error(L+"targetNode");if(!s)throw Error(L+"position");return this.Es.moveNode(t,e,s),this.Y(null),this.j}moveUp(){const t=this.getSelectedNode();return t&&this.gs.moveUp(t),this.j}openNode(t,e,s){if(!t)throw Error(q);const[i,o]=(()=>{let t,i;return"function"==typeof e?(t=e,i=null):(i=e,t=s),i??=this.options.slide,[i,t]})();return this.Is(t,i,o),this.j}prependNode(t,e){const s=e??this.Es,i=s.prepend(t);return this.Y(s),i}refresh(){return this.Y(null),this.j}reload(t){return this.Ts(null,null,t),this.j}removeFromSelection(t){if(!t)throw Error(q);return this.Ns.removeFromSelection(t),this.q(t).deselect(),this.ws(),this.j}removeNode(t){if(!t)throw Error(q);if(!t.parent)throw Error("Node has no parent");this.Ns.removeFromSelection(t,!0);const e=t.parent;return t.remove(),this.Y(e),this.j}scrollToNode(t){if(!t)throw Error(q);if(!t.element)return this.j;const e=s(t.element)-s(this.ut);return this.Ss.scrollToY(e),this.j}selectNode(t,e){return this.Cs(t,e),this.j}setOption(t,e){return this.options[t]=e,this.j}setState(t){return t&&(this.vs.setInitialState(t),this.Y(null)),this.j}toggle(t,e=null){if(!t)throw Error(q);const s=e??this.options.slide;return t.is_open?this.closeNode(t,s):this.openNode(t,s),this.j}toJson(){return JSON.stringify(this.Es.getData())}updateNode(t,e){if(!t)throw Error(q);if(!e)return this.j;const s="object"==typeof e&&e.id&&e.id!==t.id;return s&&this.Es.removeNodeFromIndex(t),t.setData(e),s&&this.Es.addNodeToIndex(t),"object"==typeof e&&e.children&&e.children instanceof Array&&(t.removeChildren(),e.children.length&&t.loadFromData(e.children)),this.Y(t),this.j}Ds(){const{autoEscape:t,buttonLeft:s,closedIcon:i,dataFilter:o,dragAndDrop:n,keyboardSupport:r,onCanMove:l,onCanMoveTo:a,onCreateLi:u,onDragMove:f,onDragStop:g,onGetStateFromStorage:_,onIsMoveHandle:p,onLoadFailed:v,onLoading:S,onSetStateFromStorage:N,openedIcon:y,openFolderDelay:w,rtl:b,saveState:j,showEmptyFolder:D,slide:F,tabIndex:I}=this.options,C=this.closeNode.bind(this),q=this.C.bind(this),L=this.q.bind(this),x=this.getNodeById.bind(this),k=this.getSelectedNode.bind(this),H=this.getTree.bind(this),A=this.Lt.bind(this),B=this.loadData.bind(this),O=this.Is.bind(this),P=this.Y.bind(this),Q=this.selectNode.bind(this),U=this.ut,$=this.u.bind(this),G=new T({getNodeById:x}),z=G.addToSelection.bind(G),V=G.getSelectedNodes.bind(G),Y=G.isNodeSelected.bind(G),R=G.removeFromSelection.bind(G),X=new e({dataFilter:o,loadData:B,onLoadFailed:v,onLoading:S,treeElement:U,triggerEvent:$}),J=new E({addToSelection:z,getNodeById:x,getSelectedNodes:V,getTree:H,onGetStateFromStorage:_,onSetStateFromStorage:N,openNode:O,refreshElements:P,removeFromSelection:R,saveState:j}),K=new M({refreshHitAreas:()=>{Z.refresh()},treeElement:U}),W=K.getScrollLeft.bind(K),Z=new h({autoEscape:t,getNodeElement:q,getNodeElementForNode:L,getScrollLeft:W,getTree:H,onCanMove:l,onCanMoveTo:a,onDragMove:f,onDragStop:g,onIsMoveHandle:p,openFolderDelay:w,openNode:O,refreshElements:P,slide:F,treeElement:U,triggerEvent:$}),tt=new d({closeNode:C,getSelectedNode:k,isFocusOnTree:A,keyboardSupport:r,openNode:O,selectNode:Q}),et=new c({autoEscape:t,buttonLeft:s,closedIcon:i,dragAndDrop:n,getTree:H,htmlElement:U,isNodeSelected:Y,onCreateLi:u,openedIcon:y,rtl:b,showEmptyFolder:D,tabIndex:I}),st=this.Ut.bind(this),it=this.qs.bind(this),ot=this.Ls.bind(this),nt=this.xs.bind(this),rt=this.ks.bind(this),ht=new m({element:U,getMouseDelay:()=>this.options.startDndDelay??0,getNode:st,onClickButton:this.toggle.bind(this),onClickTitle:this.Cs.bind(this),onMouseCapture:it,onMouseDrag:ot,onMouseStart:nt,onMouseStop:rt,triggerEvent:$,useContextMenu:this.options.useContextMenu});this.ds=X,this.us=Z,this.gs=tt,this._s=ht,this.ps=et,this.vs=J,this.Ss=K,this.Ns=G}Hs(t){const e=this.Ut(t);return e?.tree===this.Es}bs(t){const e=this.ps.closedIconElement,s=this.Ss.getScrollLeft.bind(this.Ss),i=this.ps.openedIconElement,o=this.options.tabIndex,n=this.u.bind(this);return new N({closedIconElement:e,getScrollLeft:s,node:t,openedIconElement:i,tabIndex:o,treeElement:this.ut,triggerEvent:n})}As(t){const e=this.Ss.getScrollLeft.bind(this.Ss),s=this.options.tabIndex;return new v({getScrollLeft:e,node:t,tabIndex:s,treeElement:this.ut})}Bs(){const t=this.getSelectedNode();t&&this.removeFromSelection(t)}Os(t){const e=this.Ns.getSelectedNodesUnder(t);for(const t of e)this.Ns.removeFromSelection(t)}Ms(t,e){t&&(e?(this.Os(e),this.Ps(t,e)):this.Qs(t),this.isDragging()&&this.us.refresh()),this.u("tree.load_data",{parent_node:e,tree_data:t})}Ts(t,e,s){const i=t??this.Us(e);this.ds.loadFromUrl(i,e,s)}Cs(t,e){const s=()=>{this.options.saveState&&this.vs.saveState()};if(!t)return this.Bs(),void s();const i={mustSetFocus:!0,mustToggle:!0,...e??{}};if((()=>this.options.onCanSelectNode?this.options.selectable&&this.options.onCanSelectNode(t):this.options.selectable)()){if(this.Ns.isNodeSelected(t))i.mustToggle&&(this.Bs(),this.u("tree.select",{node:null,previous_node:t}));else{const e=this.getSelectedNode()||null;this.Bs(),this.addToSelection(t,i.mustSetFocus),this.u("tree.select",{deselected_node:e,node:t}),this.ys(t)}s()}}$s(){return!0===this.options.autoOpen?-1:"number"==typeof this.options.autoOpen?this.options.autoOpen:"string"==typeof this.options.autoOpen?parseInt(this.options.autoOpen,10):0}Us(t){const e=e=>{if(t?.id){const s={node:t.id};e.data=s}else{const t=this.Gs();if(t){const s={selected_node:t};e.data=s}}},s=this.options.dataUrl;return"function"==typeof s?s(t):"string"==typeof s?(t=>{const s={url:t};return e(s),s})(s):s&&"object"==typeof s?(e(s),s):null}js(){return this.options.rtl?"◀":"►"}Ut(t){const e=t.closest("li.jqtree_common");return e?jQuery(e).data("node"):null}C(t){const e=this.Ut(t);return e?this.q(e):null}q(t){return t.isFolder()?this.bs(t):this.As(t)}Gs(){return this.options.saveState?this.vs.getNodeIdToBeSelected():null}Fs(){if(this.options.data)this.Ms(this.options.data,null);else{this.Us(null)?this.Ts(null,null,null):this.Ms([],null)}}Qs(t){const e=()=>{this.fs||(this.fs=!0,this.u("tree.init"))};this.Es=new this.options.nodeClass(null,!0,this.options.nodeClass),this.Ns.clear(),this.Es.loadFromData(t);const s=this.zs();this.Y(null),s?this.Vs(e):e()}Lt(){const t=document.activeElement;return"SPAN"===t?.tagName&&this.Hs(t)}Ys(t){const e=this.getSelectedNode();return!!e&&(t===e||t.isParentOf(e))}Rs(t,e=!0,s){t.is_loading=!0,this.Ts(null,t,()=>{this.Is(t,e,s)})}Ps(t,e){e.loadFromData(t),e.load_on_demand=!1,e.is_loading=!1,this.Y(e)}qs(t){return!!this.options.dragAndDrop&&this.us.mouseCapture(t)}Ls(t){if(this.options.dragAndDrop){const e=this.us.mouseDrag(t);return this.Ss.checkScrolling(t),e}return!1}xs(t){return!!this.options.dragAndDrop&&this.us.mouseStart(t)}ks(t){return!!this.options.dragAndDrop&&(this.Ss.stopScrolling(),this.us.mouseStop(t))}Is(t,e=!0,s){const i=(e,s,i)=>{if(!t.children.length)return;this.bs(e).open(i,s,this.options.animationSpeed)};if(t.isFolder()||t.isEmptyFolder)if(t.load_on_demand)this.Rs(t,e,s);else{let o=t.parent;for(;o;)o.parent&&i(o,!1),o=o.parent;i(t,e,s),this.ws()}}ys(t){const e=t.parent;e?.parent&&!e.is_open&&this.openNode(e,!1)}Y(t){const e=this.Lt(),s=!!t&&this.Ys(t);this.ps.render(t),s&&this.Xs(e),this.u("tree.refresh")}ws(){this.options.saveState&&this.vs.saveState()}Xs(t){const e=this.getSelectedNode();if(e){this.q(e).select(t)}}zs(){const t=()=>{if(!1===this.options.autoOpen)return!1;const t=this.$s();let e=!1;return this.Es.iterate((s,i)=>s.load_on_demand?(e=!0,!1):!!s.hasChildren()&&(s.is_open=!0,i!==t)),e};let[e,s]=(()=>{if(this.options.saveState){const t=this.vs.getStateFromStorage();if(t){return[!0,this.vs.setInitialState(t)]}return[!1,!1]}return[!1,!1]})();return e||(s=t()),s}Vs(t){const e=()=>{const e=this.$s();let s=0;const i=t=>{s+=1,this.Is(t,!1,()=>{s-=1,o()})},o=()=>{this.Es.iterate((t,s)=>t.load_on_demand?(t.is_loading||i(t),!1):(this.Is(t,!1),s!==e)),0===s&&t()};o()};(()=>{if(this.options.saveState){const e=this.vs.getStateFromStorage();return!!e&&(this.vs.setInitialStateOnDemand(e,t),!0)}return!1})()||e()}u(t,e){const s=jQuery.Event(t,e);return this.j.trigger(s),!s.isDefaultPrevented()}}return C.register(x,"tree"),t.JqTreeWidget=x,t}({});
|
|
20
|
+
var jqtree=function(t){"use strict";class e{t;i;o;h;l;u;constructor({classNames:t,dataFilter:e,loadData:s,treeElement:i,triggerEvent:o}){this.t=new AbortController,this.i=t,this.o=e,this.h=s,this.l=i,this.u=o}deinit(){this.t.abort()}async loadFromUrl(t,e){const s=e?.element??this.l;s.classList.add(this.i.loading),this.u("tree.loading_data",{element:s,node:e});const i=()=>{s.classList.remove(this.i.loading),this.u("tree.loaded_data",{element:s,node:e})},o=this.t.signal;return t.setSearchParam("_",Date.now().toString()),fetch(t.toString(),{headers:{"Content-Type":"application/json"},signal:o}).then(async t=>{if(t.ok){const s=await t.json();i(),this.h(this.o?this.o(s):s,e)}else i(),this.u("tree.load_failed",{response:t})}).catch(t=>{this.t.signal.aborted||(i(),this.u("tree.load_failed",{error:t}))})}}const s=t=>i(t).top,i=t=>{const e=t.getBoundingClientRect();return{left:e.x+window.scrollX,top:e.y+window.scrollY}};class o{m;_;p;constructor({autoEscape:t,classNames:e,nodeName:s,offsetX:i,offsetY:o,treeElement:n}){this._=i,this.p=o,this.m=this.v(s,t,e),n.appendChild(this.m)}move(t,e){this.m.style.left=t-this._+"px",this.m.style.top=e-this.p+"px"}remove(){this.m.remove()}v(t,e,s){const i=document.createElement("span");return i.classList.add(s.title,s.dragging),e?i.textContent=t:i.innerHTML=t,i.style.position="absolute",i}}const n=(t,e,s,i)=>{const o=Math.min(e.length,4),n=Math.round((i-s)/o);let r=s;for(let s=0;s<o;s++){const i=e[s];i.position&&t.push({bottom:r+n,node:i.node,position:i.position,top:r}),r+=n}},r=(t,e,i)=>((t,e)=>{if(!t.length)return[];let s=t[0].top,i=[];const o=[];for(const e of t)e.top!==s&&i.length&&(n(o,i,s,e.top),s=e.top,i=[]),i.push(e);return n(o,i,s,e),o})(((t,e)=>{const i=[];let o=0;const n=(t,e,s)=>{i.push({node:t,position:e,top:s}),o=s};return((t,{handleAfterOpenFolder:e,handleClosedFolder:s,handleFirstNode:i,handleNode:o,handleOpenFolder:n})=>{let r=!0;const h=(t,l)=>{let a=(!0===t.is_open||!t.element)&&t.hasChildren(),c=null;if(t.element?.offsetParent&&(c=t.element,r&&(i(t),r=!1),t.hasChildren()?t.is_open?n(t,t.element)||(a=!1):s(t,l,c):o(t,l,t.element)),a){const s=t.children.length;t.children.forEach((e,i)=>{const o=t.children[i];if(o)if(i===s-1)h(o,null);else{const e=t.children[i+1];e&&h(o,e)}}),t.is_open&&c&&e(t,l)}};h(t,null)})(t,{handleAfterOpenFolder:(t,s)=>{n(t,t===e||s===e?null:"after",o)},handleClosedFolder:(t,i,o)=>{const r=s(o);t===e?n(t,null,r):(n(t,"inside",r),i!==e&&n(t,"after",r))},handleFirstNode:t=>{t!==e&&t.element&&n(t,"before",s(t.element))},handleNode:(t,i,o)=>{const r=s(o);n(t,t===e?null:"inside",r),n(t,i===e||t===e?null:"after",r)},handleOpenFolder:(t,i)=>{if(t===e){const e=s(i),o=i.clientHeight;return n(t,null,e),o>5&&n(t,null,e+o-5),!1}return t.children[0]!==e&&n(t,"inside",s(i)),!0}}),i})(t,e),i);class h{currentItem;hitAreas;hoveredArea;isDragging;N;i;S;D;F;C;M;I;T;$;k;L;A;H;B;j;P;O;l;u;constructor({autoEscape:t,classNames:e,getNodeElement:s,getNodeElementForNode:i,getScrollLeft:o,getTree:n,onCanMove:r,onCanMoveTo:h,onDragMove:l,onDragStop:a,onIsMoveHandle:c,openFolderDelay:d,openNode:u,refreshElements:m,slide:g,treeElement:f,triggerEvent:_}){this.N=t,this.i=e,this.D=s,this.F=i,this.C=o,this.M=n,this.I=r,this.T=h,this.$=l,this.k=a,this.L=c,this.A=d,this.B=u,this.P=m,this.O=g,this.l=f,this.u=_,this.hoveredArea=null,this.hitAreas=[],this.isDragging=!1,this.currentItem=null,this.S=null,this.H=null,this.j=null}mouseCapture(t){const e=t.target;if(!this.U(e))return null;if(this.L&&!this.L(e))return null;let s=this.D(e);return s&&this.I&&(this.I(s.node)||(s=null)),this.currentItem=s,null!=this.currentItem}mouseDrag(t){if(!this.currentItem||!this.S)return!1;this.S.move(t.pageX,t.pageY);const e=this.R(t.pageX,t.pageY);return e&&this.q(e,this.currentItem)?(e.node.isFolder()||this.V(),this.hoveredArea!==e&&(this.hoveredArea=e,this.Y(e)?this.G(e.node):this.V(),this.X())):(this.J(),this.V(),this.hoveredArea=e),e||this.$&&this.$(this.currentItem.node,t.originalEvent),!0}mouseStart(t){if(!this.currentItem)return!1;this.refresh();const{left:e,top:s}=i(t.target),n=this.currentItem.node;return this.S=new o({autoEscape:this.N??!0,classNames:this.i,nodeName:n.name,offsetX:t.pageX-e,offsetY:t.pageY-s,treeElement:this.l}),this.isDragging=!0,this.currentItem.element.classList.add(this.i.moving),!0}mouseStop(t){this.K(t),this.W(),this.Z(),this.J(),this.tt();const e=this.currentItem;return this.currentItem&&(this.currentItem.element.classList.remove(this.i.moving),this.currentItem=null),this.isDragging=!1,!this.hoveredArea&&e&&this.k&&this.k(e.node,t.originalEvent),!1}refresh(){if(this.tt(),this.currentItem){const t=this.currentItem.node;this.et(t),this.currentItem=this.F(t),this.isDragging&&this.currentItem.element.classList.add(this.i.moving)}}q(t,e){return!this.T||this.T(e.node,t.node,t.position)}W(){this.S&&(this.S.remove(),this.S=null)}R(t,e){const s=this.st();return t<s.left||e<s.top||t>s.right||e>s.bottom?null:function(t,e){let s=0,i=t.length;for(;s<i;){const o=s+i>>1,n=t[o];if(void 0===n)return null;const r=e(n);if(r>0)i=o;else{if(!(r<0))return n;s=o+1}}return null}(this.hitAreas,t=>e<t.top?1:e>t.bottom?-1:0)}et(t){const e=this.M();this.hitAreas=e?r(e,t,this.st().bottom):[]}st(){const t=i(this.l),e=t.left+this.C(),s=t.top;return{bottom:s+this.l.clientHeight+16,left:e,right:e+this.l.clientWidth,top:s}}K(t){if(this.currentItem&&this.hoveredArea?.position&&this.q(this.hoveredArea,this.currentItem)){const e=this.currentItem.node,s=this.hoveredArea.node,i=this.hoveredArea.position,o=e.parent;"inside"===i&&(this.hoveredArea.node.is_open=!0);const n=()=>{const t=this.M();t&&(t.moveNode(e,s,i),this.l.textContent="",this.P(null))};this.u("tree.move",{moveInfo:{doMove:n,movedNode:e,originalEvent:t.originalEvent,position:i,previousParent:o,targetNode:s}})&&n()}}U(t){const e=t.nodeName;return"INPUT"!==e&&"SELECT"!==e&&"TEXTAREA"!==e}Y(t){const e=t.node;return e.isFolder()&&!e.is_open&&"inside"===t.position}J(){this.j&&this.j.remove()}tt(){this.hitAreas=[]}Z(){this.hoveredArea=null}G(t){const e=()=>{this.B(t,this.O).then(()=>{this.refresh(),this.X()})};this.V();const s=this.A;!1!==s&&(this.H=window.setTimeout(e,s))}V(){this.H&&(clearTimeout(this.H),this.H=null)}X(){if(!this.hoveredArea)return;this.J();const t=this.F(this.hoveredArea.node);this.j=t.addDropHint(this.hoveredArea.position)}}const l=t=>t?"true":"false";class a{closedIconElement;openedIconElement;N;it;i;ot;M;nt;rt;ht;lt;ct;dt;ut;constructor({autoEscape:t,buttonLeft:e,classNames:s,closedIcon:i,dragAndDrop:o,getTree:n,htmlElement:r,isNodeSelected:h,onCreateLi:l,openedIcon:a,rtl:c,setNodeElement:d,showEmptyFolder:u,tabIndex:m}){this.N=t,this.it=e,this.i=s,this.ot=o,this.M=n,this.nt=r,this.rt=h,this.ht=l,this.lt=c,this.ct=d,this.dt=u,this.ut=m,this.openedIconElement=this.gt(a??"+"),this.closedIconElement=this.gt(i??"-")}render(t){t?.parent?this.renderFromNode(t):this.renderFromRoot()}renderFromNode(t){if(!t.element)return;const e=t.element,s=this.ft(t,t.getLevel());e.replaceWith(s),this._t(s,t.children,!1,t.getLevel()+1)}renderFromRoot(){this.nt.textContent="";const t=this.M();t&&this._t(this.nt,t.children,!0,1)}vt(t,e){t.element=e,this.ct(e,t)}gt(t){if("string"==typeof t){const e=document.createElement("div");return e.innerHTML=t,document.createTextNode(e.innerHTML)}return t.nodeType?t:void 0}_t(t,e,s,i){const o=this.Nt(s);t.appendChild(o);for(const t of e){const e=this.ft(t,i);o.appendChild(e),t.hasChildren()&&this._t(e,t.children,!1,i+1)}}St(t,e,s){const i=this.Et(t),o=this.wt(t,s),n=t.is_open?this.openedIconElement:this.closedIconElement,r=document.createElement("li");r.className=`${this.i.common} ${o}`,r.setAttribute("role","none");const h=document.createElement("div");h.className=`${this.i.element} ${this.i.common}`,h.setAttribute("role","none"),r.appendChild(h);const a=document.createElement("a");a.className=i,n&&a.appendChild(n.cloneNode(!0)),this.it&&h.appendChild(a);const c=this.yt(t.name,s,!0,e);return c.setAttribute("aria-expanded",l(t.is_open)),h.appendChild(c),this.it||h.appendChild(a),r}ft(t,e){const s=this.rt(t),i=t.isFolder()||t.isEmptyFolder&&this.dt?this.St(t,e,s):this.bt(t,e,s);return this.vt(t,i),this.ht&&this.ht(t,i,s),i}bt(t,e,s){const i=[this.i.common];s&&i.push(this.i.selected);const o=i.join(" "),n=document.createElement("li");n.className=o,n.setAttribute("role","none");const r=document.createElement("div");r.className=`${this.i.element} ${this.i.common}`,r.setAttribute("role","none"),n.appendChild(r);const h=this.yt(t.name,s,!1,e);return r.appendChild(h),n}yt(t,e,s,i){const o=document.createElement("span");let n=`${this.i.title} ${this.i.common}`;if(s&&(n+=` ${this.i.titleFolder}`),n+=` ${this.it?this.i.titleButtonLeft:this.i.titleButtonRight}`,o.className=n,e){const t=this.ut;void 0!==t&&o.setAttribute("tabindex",`${t}`)}return this.Dt(o,t,i,e),this.N?o.textContent=t:o.innerHTML=t,o}Nt(t){let e,s;t?(e=this.i.tree,s="tree",this.lt&&(e+=` ${this.i.rtl}`)):(e="",s="group"),this.ot&&(e+=` ${this.i.dnd}`);const i=document.createElement("ul");return i.className=`${this.i.common} ${e}`,i.setAttribute("role",s),i}Et(t){const e=[this.i.toggler,this.i.common];return t.is_open||e.push(this.i.closed),this.it?e.push(this.i.togglerLeft):e.push(this.i.togglerRight),e.join(" ")}wt(t,e){const s=[this.i.folder];return t.is_open||s.push(this.i.closed),e&&s.push(this.i.selected),t.is_loading&&s.push(this.i.loading),s.join(" ")}Dt(t,e,s,i){t.setAttribute("aria-label",e),t.setAttribute("aria-level",`${s}`),t.setAttribute("aria-selected",l(i)),t.setAttribute("role","treeitem")}}class c{Ft;Ct;Mt;It;B;Tt;constructor({closeNode:t,getSelectedNode:e,isFocusOnTree:s,keyboardSupport:i,openNode:o,selectNode:n}){this.Ft=t,this.Ct=e,this.Mt=s,this.It=i,this.B=o,this.Tt=n,i&&document.addEventListener("keydown",this.$t)}deinit(){this.It&&document.removeEventListener("keydown",this.$t)}moveDown(t){return this.xt(t.getNextVisibleNode())}moveUp(t){return this.xt(t.getPreviousVisibleNode())}kt(){return this.It&&this.Mt()}$t=t=>{if(!this.kt())return;let e=!1;const s=this.Ct();if(s)switch(t.key){case"ArrowDown":e=this.moveDown(s);break;case"ArrowLeft":e=this.Lt(s);break;case"ArrowRight":e=this.At(s);break;case"ArrowUp":e=this.moveUp(s)}e&&t.preventDefault()};Lt(t){return t.isFolder()&&t.is_open?(this.Ft(t),!0):this.xt(t.getParent())}At(t){return!!t.isFolder()&&(t.is_open?this.xt(t.getNextVisibleNode()):(this.B(t),!0))}xt(t){return!!t&&(this.Tt(t),!0)}}const 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 m{i;m;Ht;Bt;jt;Pt;Ot;Ut;Qt;Rt;qt;Vt;zt;Yt;u;Gt;constructor({classNames:t,element:e,getMouseDelay:s,getNode:i,onClickButton:o,onClickTitle:n,onMouseCapture:r,onMouseDrag:h,onMouseStart:l,onMouseStop:a,triggerEvent:c,useContextMenu:d}){this.i=t,this.m=e,this.Ht=s,this.Bt=i,this.Qt=o,this.Rt=n,this.qt=r,this.Vt=h,this.zt=l,this.Yt=a,this.u=c,this.Gt=d,e.addEventListener("click",this.Xt),e.addEventListener("dblclick",this.Jt),e.addEventListener("mousedown",this.Kt,{passive:!1}),e.addEventListener("touchstart",this.Wt,{passive:!1}),d&&e.addEventListener("contextmenu",this.Zt),this.Pt=!1,this.Ot=null,this.jt=!1,this.Ut=null}deinit(){this.m.removeEventListener("click",this.Xt),this.m.removeEventListener("dblclick",this.Jt),this.Gt&&this.m.removeEventListener("contextmenu",this.Zt),this.m.removeEventListener("mousedown",this.Kt),this.m.removeEventListener("touchstart",this.Wt),this.te()}ee(t){const e=t.closest(`.${this.i.toggler}`);if(e){const t=this.Bt(e);if(t)return{node:t,type:"button"}}else{const e=t.closest(`.${this.i.element}`);if(e){const t=this.Bt(e);if(t)return{node:t,type:"label"}}}return null}Xt=t=>{if(!t.target)return;const e=this.ee(t.target);if(e)switch(e.type){case"button":this.Qt(e.node),t.preventDefault(),t.stopPropagation();break;case"label":this.u("tree.click",{node:e.node,originalEvent:t})&&this.Rt(e.node)}};Zt=t=>{if(!t.target)return;const e=t.target.closest(`ul.${this.i.tree} .${this.i.element}`);if(e){const s=this.Bt(e);if(s)return t.preventDefault(),t.stopPropagation(),this.u("tree.contextmenu",{node:s,originalEvent:t}),!1}return null};Jt=t=>{if(!t.target)return;const e=this.ee(t.target);"label"===e?.type&&this.u("tree.dblclick",{node:e.node,originalEvent:t})};se(t){return this.Pt&&this.ie(t),this.Ut=t,!!this.qt(t)&&(this.oe(),!0)}ne(t,e){if(this.Pt)return this.Vt(e),void(t.cancelable&&t.preventDefault());this.jt&&(this.Ut&&(this.Pt=this.zt(this.Ut)),this.Pt?(this.Vt(e),t.cancelable&&t.preventDefault()):this.ie(e))}ie(t){this.te(),this.jt=!1,this.Ut=null,this.Pt&&(this.Pt=!1,this.Yt(t))}oe(){document.addEventListener("mousemove",this.re,{passive:!1}),document.addEventListener("touchmove",this.he,{passive:!1}),document.addEventListener("mouseup",this.le,{passive:!1}),document.addEventListener("touchend",this.ae,{passive:!1});const t=this.Ht();t?this.ce(t):this.jt=!0}Kt=t=>{if(0!==t.button)return;this.se(d(t))&&t.cancelable&&t.preventDefault()};re=t=>{this.ne(t,d(t))};le=t=>{this.ie(d(t))};te(){document.removeEventListener("mousemove",this.re),document.removeEventListener("touchmove",this.he),document.removeEventListener("mouseup",this.le),document.removeEventListener("touchend",this.ae)}ce(t){this.Ot&&clearTimeout(this.Ot),this.Ot=window.setTimeout(()=>{this.Ut&&(this.jt=!0)},t),this.jt=!1}ae=t=>{if(t.touches.length>1)return;const e=t.touches[0];e&&this.ie(u(e,t))};he=t=>{if(t.touches.length>1)return;const e=t.touches[0];e&&this.ne(t,u(e,t))};Wt=t=>{if(t.touches.length>1)return;const e=t.touches[0];e&&this.se(u(e,t))}}const g=t=>"object"==typeof t&&"children"in t&&t.children instanceof Array;class f{children;element;id;idMapping;is_loading;is_open;isEmptyFolder;load_on_demand;name;nodeClass;parent;tree;constructor(t=null,e=!1,s=f){this.name="",this.load_on_demand=!1,this.isEmptyFolder=null!=t&&g(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=s):this.idMapping=void 0}addAfter(t){if(this.parent){const e=this.de(t),s=this.parent.getChildIndex(this);return this.parent.addChildAtPosition(e,s+1),e.ue(t),e}return null}addBefore(t){if(this.parent){const e=this.de(t),s=this.parent.getChildIndex(this);return this.parent.addChildAtPosition(e,s),e.ue(t),e}return null}addChild(t){this.children.push(t),t.me(this)}addChildAtPosition(t,e){this.children.splice(e,0,t),t.me(this)}addNodeToIndex(t){null!=t.id&&this.idMapping?.set(t.id,t)}addParent(t){if(this.parent){const e=this.de(t);this.tree&&e.me(this.tree);const s=this.parent;for(const t of s.children)e.addChild(t);return s.children=[],s.addChild(e),e}return null}append(t){const e=this.de(t);return this.addChild(e),e.ue(t),e}filter(t){const e=[];return this.iterate(s=>(t(s)&&e.push(s),!0)),e}getChildIndex(t){return this.children.indexOf(t)}getData(t=!1){const e=t=>t.map(t=>{const s={};for(const e in t)if(-1===["parent","children","element","idMapping","load_on_demand","nodeClass","tree","isEmptyFolder"].indexOf(e)&&Object.prototype.hasOwnProperty.call(t,e)){const i=t[e];s[e]=i}return t.hasChildren()&&(s.children=e(t.children)),s});return e(t?[this]:this.children)}getLastChild(){if(this.hasChildren()){const 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){const t=this.getNextSibling();return t||this.parent.getNextNode(!1)}return null}getNextSibling(){if(this.parent){const 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){const t=this.getNextSibling();return t||this.parent.getNextNode(!1)}return null}getNodeByCallback(t){let e=null;return this.iterate(s=>!e&&(!t(s)||(e=s,!1))),e}getNodeById(t){return this.idMapping?.get(t)??null}getNodeByName(t){return this.getNodeByCallback(e=>e.name===t)}getNodeByNameMustExist(t){const 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(s=>s[t]===e)}getParent(){return this.parent&&this.parent.parent?this.parent:null}getPreviousNode(){if(this.parent){const t=this.getPreviousSibling();return t?t.hasChildren()?t.getLastChild():t:this.getParent()}return null}getPreviousSibling(){if(this.parent){const t=this.parent.getChildIndex(this)-1;return t>=0?this.parent.children[t]??null:null}return null}getPreviousVisibleNode(){if(this.parent){const 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){const e=t=>{for(const e of t){const t=this.de();t.initFromData(e),this.addChild(t)}};(t=>{this.setData(t),g(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){const e=(s,i)=>{for(const o of s.children){t(o,i)&&o.hasChildren()&&e(o,i+1)}};e(this,0)}loadFromData(t){this.removeChildren();for(const e of t){const t=this.de(e);this.addChild(t),g(e)&&t.loadFromData(e.children)}return this}moveNode(t,e,s){if(!t.parent||t.isParentOf(e))return!1;switch(t.parent.ge(t),s){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){const e=this.de(t);return this.addChildAtPosition(e,0),e.ue(t),e}remove(){this.parent&&(this.parent.removeChild(this),this.parent=null)}removeChild(t){t.removeChildren(),this.ge(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(const e in t)if(Object.prototype.hasOwnProperty.call(t,e)){const s=t[e];"label"===e||"name"===e?"string"==typeof s&&(this.name=s):"children"!==e&&"parent"!==e&&(this[e]=s)}}de(t){return new(this.fe())(t)}ge(t){this.children.splice(this.getChildIndex(t),1),this.tree?.removeNodeFromIndex(t)}fe(){return this.nodeClass??this.tree?.nodeClass??f}ue(t){g(t)&&t.children.length&&this.loadFromData(t.children)}me(t){this.parent=t,this.tree=t.tree,this.tree?.addNodeToIndex(this)}}class _{_e;constructor(t,e,s){const i=t.querySelector(`:scope > .${s.element}`);if(!i)return void(this._e=void 0);const o=Math.max(t.offsetWidth+e-4,0),n=Math.max(t.clientHeight-4,0),r=document.createElement("span");r.className=s.border,r.style.width=`${o}px`,r.style.height=`${n}px`,this._e=r,i.append(this._e)}remove(){this._e?.remove()}}class p{i;m;pe;ve;constructor(t,e,s,i){switch(this.i=i,this.m=e,this.ve=t,this.pe=this.Ne(),s){case"after":this.Se();break;case"before":this.Ee();break;case"inside":t.isFolder()&&t.is_open?this.we():this.ye()}}remove(){this.pe.remove()}Ne(){const{circle:t,common:e,ghost:s,line:i}=this.i,o=document.createElement("li");o.className=`${e} ${s}`;const n=document.createElement("span");n.className=`${e} ${t}`,o.append(n);const r=document.createElement("span");return r.className=`${e} ${i}`,o.append(r),o}Se(){this.m.after(this.pe)}Ee(){this.m.before(this.pe)}ye(){this.m.after(this.pe),this.pe.classList.add(this.i.inside)}we(){const t=this.ve.children[0]?.element;t&&t.before(this.pe)}}class v{element;node;i;C;ut;l;constructor({classNames:t,getScrollLeft:e,node:s,tabIndex:i,treeElement:o}){this.i=t,this.C=e,this.node=s,this.ut=i,this.l=o,s.element??=this.l,this.element=s.element}addDropHint(t){return this.be(t)?new _(this.element,this.C(),this.i):new p(this.node,this.element,t,this.i)}deselect(){this.element.classList.remove(this.i.selected);const t=this.De();t.removeAttribute("tabindex"),t.setAttribute("aria-selected","false"),t.blur()}select(t){this.element.classList.add(this.i.selected);const e=this.De(),s=this.ut;null!=s&&e.setAttribute("tabindex",s.toString()),e.setAttribute("aria-selected","true"),t&&e.focus()}De(){return this.element.querySelector(`:scope > .${this.i.element} > span.${this.i.title}`)}Fe(){return this.element.querySelector(":scope > ul")}be(t){return"inside"===t}}const N=t=>"number"==typeof t?t:"slow"===t?600:200;class S extends v{Ce;Me;u;constructor({classNames:t,closedIconElement:e,getScrollLeft:s,node:i,openedIconElement:o,tabIndex:n,treeElement:r,triggerEvent:h}){super({classNames:t,getScrollLeft:s,node:i,tabIndex:n,treeElement:r}),this.Ce=e,this.Me=o,this.u=h}close(t,e){if(!this.node.is_open)return;this.node.is_open=!1;const s=this.Ie();s.classList.add(this.i.closed),s.innerHTML="";const i=this.Ce;if(i){const t=i.cloneNode(!0);s.appendChild(t)}const o=()=>{this.element.classList.add(this.i.closed);this.De().setAttribute("aria-expanded","false"),this.u("tree.close",{node:this.node})},n=this.Fe();t?((t,e,s)=>{t.animate([{height:`${t.scrollHeight}px`,overflow:"hidden"},{height:"0",overflow:"hidden"}],{duration:N(e)}).onfinish=()=>{t.style.display="none",s()}})(n,e,o):(n.style.display="none",o())}async open(t,e){return new Promise(s=>{if(this.node.is_open)return void s();this.node.is_open=!0;const i=this.Ie();i.classList.remove(this.i.closed),i.innerHTML="";const o=this.Me;if(o){const t=o.cloneNode(!0);i.appendChild(t)}const n=()=>{this.element.classList.remove(this.i.closed);this.De().setAttribute("aria-expanded","true"),this.u("tree.open",{node:this.node}),s()},r=this.Fe();t?((t,e,s)=>{t.style.display="block",t.animate([{height:"0",overflow:"hidden"},{height:`${t.scrollHeight}px`,overflow:"hidden"}],{duration:N(e)}).onfinish=()=>{s()}})(r,e,n):(r.style.display="block",n())})}be(t){return!this.node.is_open&&"inside"===t}Ie(){return this.element.querySelector(`:scope > .${this.i.element} > a.${this.i.toggler}`)}}const E="http://localhost";class w{Te;$e;constructor(t){(t=>{try{return new URL(t),!0}catch{return!1}})(t)?(this.$e=new URL(t),this.Te=!0):(this.$e=new URL(t,E),this.Te=!1)}setSearchParam(t,e){this.$e.searchParams.set(t,e)}toString(){return this.Te?this.$e.href:this.$e.href.slice(16)}}class y{xe;ke;Le;M;Ae;He;B;P;Be;je;constructor({addToSelection:t,getNodeById:e,getSelectedNodes:s,getTree:i,onGetStateFromStorage:o,onSetStateFromStorage:n,openNode:r,refreshElements:h,removeFromSelection:l,saveState:a}){this.xe=t,this.ke=e,this.Le=s,this.M=i,this.Ae=o,this.He=n,this.B=r,this.P=h,this.Be=l,this.je=a}getNodeIdToBeSelected(){if(!this.je)return null;const t=this.getStateFromStorage();return t?.selected_node?t.selected_node[0]??null:null}getState(){return{open_nodes:(()=>{const t=[];return this.M()?.iterate(e=>(e.is_open&&e.id&&e.hasChildren()&&t.push(e.id),!0)),t})(),selected_node:(()=>{const t=[];return this.Le().forEach(e=>{null!=e.id&&t.push(e.id)}),t})()}}getStateFromStorage(){if(!this.je)return null;const t=this.Pe();return t?this.Oe(t):null}saveState(){if(!this.je)return;const t=JSON.stringify(this.getState());this.He?this.He(t):localStorage.setItem(this.Ue(),t)}setInitialState(t){let e=!1;return t.open_nodes&&(e=this.Qe(t.open_nodes)),this.Re(),t.selected_node&&this.qe(t.selected_node),e}async setInitialStateOnDemand(t){let e=t.open_nodes;const s=async()=>{if(!e)return;const s=[];for(const t of e){const e=this.ke(t);e?e.is_loading||(e.load_on_demand?await i(e):await this.B(e,!1)):s.push(t)}e=s,t.selected_node&&this.qe(t.selected_node)&&this.P(null)},i=async t=>{await this.B(t,!1),await s()};await s()}Ue(){return"string"==typeof this.je?this.je:"tree"}Pe(){return this.Ae?this.Ae():localStorage.getItem(this.Ue())}Qe(t){let e=!1;for(const s of t){const t=this.ke(s);t&&(t.load_on_demand?e=!0:t.is_open=!0)}return e}Oe(t){const e=JSON.parse(t);var s;return e.selected_node&&("number"==typeof(s=e.selected_node)&&s%1==0)&&(e.selected_node=[e.selected_node]),e}Re(){this.Le().forEach(t=>{this.Be(t)})}qe(t){let e=0;for(const s of t){const t=this.ke(s);t&&(e+=1,this.xe(t))}return 0!==e}}class b{Ve;ze;Ye;Ge;Xe;Je;constructor({container:t,refreshHitAreas:e}){this.Ve=t,this.Ge=e}checkHorizontalScrolling(t){const e=this.Ke(t);this.ze!==e&&(this.ze=e,null!=this.Ye&&window.clearTimeout(this.Ye),e&&(this.Ye=window.setTimeout(this.We.bind(this),40)))}checkVerticalScrolling(t){const e=this.Ze(t);this.Xe!==e&&(this.Xe=e,null!=this.Je&&(window.clearTimeout(this.Je),this.Je=void 0),e&&(this.Je=window.setTimeout(this.ts.bind(this),40)))}getScrollLeft(){return this.Ve.scrollLeft}scrollToY(t){this.Ve.scrollTop=t}stopScrolling(){this.ze=void 0,this.Xe=void 0}We(){if(!this.ze)return;const t="left"===this.ze?-20:20;this.Ve.scrollBy({behavior:"instant",left:t,top:0}),this.Ge(),setTimeout(this.We.bind(this),40)}ts(){if(!this.Xe)return;const t="top"===this.Xe?-20:20;this.Ve.scrollBy({behavior:"instant",left:0,top:t}),this.Ge(),setTimeout(this.ts.bind(this),40)}}class D extends b{es;ss;stopScrolling(){super.stopScrolling(),this.ze=void 0,this.Xe=void 0}Ke(t){const e=i(this.Ve),s=this.Ve.getBoundingClientRect().width,o=e.left+s,n=e.left;return t>o-20?"right":t<n+20?"left":void 0}Ze(t){return t<this.ns()?"top":t>this.rs()?"bottom":void 0}rs(){if(null==this.es){const t=this.Ve.getBoundingClientRect().height;this.es=this.ns()+t}return this.es}ns(){return this.ss??=s(this.Ve),this.ss}}class F extends b{hs;ls;l;constructor({refreshHitAreas:t,treeElement:e}){super({container:document.documentElement,refreshHitAreas:t}),this.l=e}scrollToY(t){const e=s(this.l);super.scrollToY(t+e)}stopScrolling(){super.stopScrolling(),this.hs=void 0,this.ls=void 0}Ke(t){const e=t-this.Ve.scrollLeft<20;return t>window.innerWidth-20&&this.cs()?"right":e?"left":void 0}Ze(t){const e=this.Ve.scrollTop;if(t-e<20)return"top";return window.innerHeight-(t-e)<20&&this.ds()?"bottom":void 0}ds(){return this.Ve.scrollTop+this.Ve.clientHeight<this.us()}cs(){return this.Ve.scrollLeft+this.Ve.clientWidth<this.gs()}us(){return this.hs??=this.Ve.scrollHeight,this.hs}gs(){return this.ls??=this.Ve.scrollWidth,this.ls}}const C=t=>"auto"===t||"scroll"===t,M=t=>{const e=getComputedStyle(t);return C(e.overflowX)||C(e.overflowY)},I=(t,e)=>{const s=(t=>{if(M(t))return t;let e=t.parentElement;for(;e;){if(M(e))return e;e=e.parentElement}return null})(t);return s&&"HTML"!==s.tagName?new D({container:s,refreshHitAreas:e}):new F({refreshHitAreas:e,treeElement:t})};class T{Ge;fs;l;constructor({refreshHitAreas:t,treeElement:e}){this.Ge=t,this.fs=void 0,this.l=e}checkScrolling(t){this._s(t),this.ps(t)}getScrollLeft(){return this.vs().getScrollLeft()}scrollToY(t){this.vs().scrollToY(t)}stopScrolling(){this.vs().stopScrolling()}ps(t){this.vs().checkHorizontalScrolling(t.pageX)}_s(t){this.vs().checkVerticalScrolling(t.pageY)}vs(){return this.fs??=I(this.l,this.Ge),this.fs}}class ${ke;F;Ns;Ss;Es;ws;ys;bs;u;constructor({getNodeById:t,getNodeElementForNode:e,getOnCanSelectNode:s,getSelectable:i,openParents:o,saveState:n,triggerEvent:r}){this.ke=t,this.F=e,this.Ns=s,this.Ss=i,this.Es=o,this.ws=n,this.ys=new Set,this.bs=null,this.u=r}addToSelection(t){null!=t.id?this.ys.add(t.id):this.bs=t}clear(){this.ys.clear(),this.bs=null}getSelectedNode(){const t=this.getSelectedNodes();return!!t.length&&(t[0]??!1)}getSelectedNodes(){if(this.bs)return[this.bs];{const t=[];return this.ys.forEach(e=>{const s=this.ke(e);s&&t.push(s)}),t}}getSelectedNodesUnder(t){if(this.bs)return t.isParentOf(this.bs)?[this.bs]:[];{const e=[];return this.ys.forEach(s=>{const i=this.ke(s);i&&t.isParentOf(i)&&e.push(i)}),e}}isNodeSelected(t){return null!=t.id?this.ys.has(t.id):!!this.bs&&this.bs.element===t.element}removeFromSelection(t,e=!1){null==t.id?this.bs&&t.element===this.bs.element&&(this.bs=null):(this.ys.delete(t.id),e&&t.iterate(()=>(null!=t.id&&this.ys.delete(t.id),!0)))}selectSingleNode(t,e){const s={mustSetFocus:!0,mustToggle:!0,...e??{}};if(!(()=>{if(!this.Ss())return!1;const e=this.Ns();return!e||e(t)})())return;const i=t=>{this.removeFromSelection(t),this.F(t).deselect()};if(this.isNodeSelected(t))s.mustToggle&&(i(t),this.u("tree.deselect",{node:t}));else{const e=this.getSelectedNode();e&&i(e),this.addToSelection(t),this.Es(t),this.F(t).select(s.mustSetFocus),this.u("tree.select",{deselectedNode:e||null,node:t})}this.ws()}}const x={animationSpeed:"fast",autoEscape:!0,autoOpen:!1,buttonLeft:!0,classPrefix:"tree-element",closedIcon:void 0,commonClassName:void 0,data:void 0,dataFilter:void 0,dataUrl:void 0,dragAndDrop:!1,keyboardSupport:!0,nodeClass:f,onCanMove:void 0,onCanMoveTo:void 0,onCanSelectNode:void 0,onCreateLi:void 0,onDragMove:void 0,onDragStop:void 0,onGetStateFromStorage:void 0,onIsMoveHandle:void 0,onSetStateFromStorage:void 0,openedIcon:void 0,openFolderDelay:500,rtl:void 0,saveState:!1,selectable:!0,showEmptyFolder:!1,slide:!0,startDndDelay:300,tabIndex:0,treeClassName:void 0,useContextMenu:!0},k=t=>t.rtl?"◀":"►",L=t=>{const e=t.dataset.rtl;return""==e||"false"!==e&&Boolean(e)},A=(t,e,s)=>{const i=new CustomEvent(e,{bubbles:!0,cancelable:!0,detail:s});return t.dispatchEvent(i),!i.defaultPrevented};
|
|
21
|
+
/*
|
|
22
|
+
Html-tree 0.1.1
|
|
23
|
+
|
|
24
|
+
Copyright 2026 Marco Braak
|
|
25
|
+
|
|
26
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
27
|
+
you may not use this file except in compliance with the License.
|
|
28
|
+
You may obtain a copy of the License at
|
|
29
|
+
|
|
30
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
31
|
+
|
|
32
|
+
Unless required by applicable law or agreed to in writing, software
|
|
33
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
34
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
35
|
+
See the License for the specific language governing permissions and
|
|
36
|
+
limitations under the License.
|
|
37
|
+
@license
|
|
38
|
+
|
|
39
|
+
*/
|
|
40
|
+
class H{tree;i;Ds;Fs;nt;Cs;Ms;Is;Ts;$s;xs;ks;Ls;As;Hs;constructor({htmlElement:t,overrideTriggerEventProvider:s,...i}){this.nt=t,this.$s=((t,e)=>{const s={...x,...e};return s.dataUrl??=t.dataset.url,s.rtl??=L(t),s.closedIcon??=k(s),s.openedIcon??="▼",s})(t,i),this.i=(({classPrefix:t,commonClassName:e,treeClassName:s})=>({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:s??t}))(this.$s),this.Hs=s??A,this.Cs=!1,this.tree=new f({},!0),this.Ts=new WeakMap;const{autoEscape:o,buttonLeft:n,closedIcon:r,dataFilter:l,dragAndDrop:d,keyboardSupport:u,onCanMove:g,onCanMoveTo:_,onCreateLi:p,onDragMove:v,onDragStop:N,onGetStateFromStorage:S,onIsMoveHandle:E,onSetStateFromStorage:w,openedIcon:b,openFolderDelay:D,rtl:F,saveState:C,showEmptyFolder:M,slide:I,tabIndex:H}=this.$s,B=this.i,j=this.closeNode.bind(this),P=this.D.bind(this),O=this.F.bind(this),U=this.getNodeById.bind(this),Q=this.getSelectedNode.bind(this),R=this.getTree.bind(this),q=this.Mt.bind(this),V=this.loadData.bind(this),z=this.openNode.bind(this),Y=this.Es.bind(this),G=this.P.bind(this),X=this.refreshHitAreas.bind(this),J=this.ct.bind(this),K=this.nt,W=this.u.bind(this),Z=new $({getNodeById:U,getNodeElementForNode:O,getOnCanSelectNode:()=>this.$s.onCanSelectNode,getSelectable:()=>this.$s.selectable,openParents:Y,saveState:()=>{rt.saveState()},triggerEvent:W}),tt=Z.addToSelection.bind(Z),et=Z.getSelectedNodes.bind(Z),st=Z.isNodeSelected.bind(Z),it=Z.removeFromSelection.bind(Z),ot=Z.selectSingleNode.bind(Z),nt=new e({classNames:B,dataFilter:l,loadData:V,treeElement:K,triggerEvent:W}),rt=new y({addToSelection:tt,getNodeById:U,getSelectedNodes:et,getTree:R,onGetStateFromStorage:S,onSetStateFromStorage:w,openNode:z,refreshElements:G,removeFromSelection:it,saveState:C}),ht=new T({refreshHitAreas:X,treeElement:K}),lt=ht.getScrollLeft.bind(ht),at=new h({autoEscape:o,classNames:B,getNodeElement:P,getNodeElementForNode:O,getScrollLeft:lt,getTree:R,onCanMove:g,onCanMoveTo:_,onDragMove:v,onDragStop:N,onIsMoveHandle:E,openFolderDelay:D,openNode:z,refreshElements:G,slide:I,treeElement:K,triggerEvent:W}),ct=new c({closeNode:j,getSelectedNode:Q,isFocusOnTree:q,keyboardSupport:u,openNode:z,selectNode:ot}),dt=new a({autoEscape:o,buttonLeft:n,classNames:B,closedIcon:r,dragAndDrop:d,getTree:R,htmlElement:K,isNodeSelected:st,onCreateLi:p,openedIcon:b,rtl:F,setNodeElement:J,showEmptyFolder:M,tabIndex:H}),ut=this.getNode.bind(this),mt=this.Bs.bind(this),gt=this.js.bind(this),ft=this.Ps.bind(this),_t=this.Os.bind(this),pt=new m({classNames:B,element:K,getMouseDelay:()=>this.$s.startDndDelay??0,getNode:ut,onClickButton:this.toggle.bind(this),onClickTitle:ot,onMouseCapture:mt,onMouseDrag:gt,onMouseStart:ft,onMouseStop:_t,triggerEvent:W,useContextMenu:this.$s.useContextMenu});this.Ds=nt,this.Fs=at,this.Ms=ct,this.Is=pt,this.xs=dt,this.ks=rt,this.Ls=ht,this.As=Z,this.Us()}addNodeAfter(t,e){const s=e.addAfter(t);return s&&this.P(e.parent),s}addNodeBefore(t,e){const s=e.addBefore(t);return s&&this.P(e.parent),s}addParentNode(t,e){const s=e.addParent(t);return s&&this.P(s.parent),s}addToSelection(t,e){this.As.addToSelection(t),this.Es(t),this.F(t).select(e??!0),this.ws()}appendNode(t,e){const s=e.append(t);return this.P(e),s}closeNode(t,e){(t.isFolder()||t.isEmptyFolder)&&(this.Qs(t).close(e??this.$s.slide,this.$s.animationSpeed),this.ws())}deinit(){this.nt.textContent="",this.Ds.deinit(),this.Ms.deinit(),this.Is.deinit(),this.tree=new f({},!0)}getNode(t){const e=t.closest(`li.${this.i.common}`);return e?this.Ts.get(e)??null:null}getNodeByCallback(t){return this.tree.getNodeByCallback(t)}getNodeById(t){return this.tree.getNodeById(t)}getNodeByName(t){return this.tree.getNodeByName(t)}getNodeByNameMustExist(t){return this.tree.getNodeByNameMustExist(t)}getNodesByProperty(t,e){return this.tree.getNodesByProperty(t,e)}getSelectedNode(){return this.As.getSelectedNode()}getSelectedNodes(){return this.As.getSelectedNodes()}getState(){return this.ks.getState()}getStateFromStorage(){return this.ks.getStateFromStorage()}getTree(){return this.tree}getVersion(){return"0.1.1"}isDragging(){return this.Fs.isDragging}isNodeSelected(t){return this.As.isNodeSelected(t)}loadData(t,e){t&&(e?(this.Rs(e),this.qs(t,e)):this.Vs(t),this.isDragging()&&this.Fs.refresh()),this.u("tree.set_data",{node:e,treeData:t??void 0})}async loadDataFromUrl(t,e){const s=t?new w(t):this.zs(e);s&&await this.Ds.loadFromUrl(s,e)}moveDown(){const t=this.getSelectedNode();t&&this.Ms.moveDown(t)}moveNode(t,e,s){this.tree.moveNode(t,e,s),this.P(null)}moveUp(){const t=this.getSelectedNode();t&&this.Ms.moveUp(t)}async openNode(t,e){const s=e??this.$s.slide,i=async(e,s)=>{if(!t.children.length)return;const i=this.Qs(e);await i.open(s,this.$s.animationSpeed)};if(t.isFolder()||t.isEmptyFolder)if(t.load_on_demand)await this.Ys(t,s);else{let e=t.parent;for(;e;)e.parent&&await i(e,!1),e=e.parent;await i(t,s),this.ws()}}prependNode(t,e){const s=e.prepend(t);return this.P(e),s}refresh(){this.P(null)}refreshHitAreas(){this.Fs.refresh()}removeFromSelection(t){this.As.removeFromSelection(t),this.F(t).deselect(),this.ws()}removeNode(t){this.As.removeFromSelection(t,!0);const e=t.parent;t.remove(),this.P(e)}scrollToNode(t){if(!t.element)return;const e=s(t.element)-s(this.nt);this.Ls.scrollToY(e)}selectNode(t,e){if(!t)return this.Gs(),void this.ks.saveState();this.As.selectSingleNode(t,e)}setOption(t,e){this.$s[t]=e}setState(t){this.ks.setInitialState(t),this.P(null)}toggle(t,e=null){const s=e??this.$s.slide;t.is_open?this.closeNode(t,s):this.openNode(t,s)}toJson(){return JSON.stringify(this.tree.getData())}updateNode(t,e){const s="object"==typeof e&&e.id&&e.id!==t.id;s&&this.tree.removeNodeFromIndex(t),t.setData(e),s&&this.tree.addNodeToIndex(t),"object"==typeof e&&e.children&&e.children instanceof Array&&(t.removeChildren(),e.children.length&&t.loadFromData(e.children)),this.P(t)}Qs(t){const e=this.i,s=this.xs.closedIconElement,i=this.Ls.getScrollLeft.bind(this.Ls),o=this.xs.openedIconElement,n=this.$s.tabIndex,r=this.nt,h=this.u.bind(this);return new S({classNames:e,closedIconElement:s,getScrollLeft:i,node:t,openedIconElement:o,tabIndex:n,treeElement:r,triggerEvent:h})}Xs(t){const e=this.i,s=this.Ls.getScrollLeft.bind(this.Ls),i=this.$s.tabIndex,o=this.nt;return new v({classNames:e,getScrollLeft:s,node:t,tabIndex:i,treeElement:o})}zs(t){const e=this.$s.dataUrl;let s;if(s="function"==typeof e?e(t):e,!s)return null;const i=new w(s);if(t?.id)i.setSearchParam("node",t.id.toString());else{const t=this.Js();t&&i.setSearchParam("selected_node",t.toString())}return i}Gs(){const t=this.getSelectedNode();t&&this.removeFromSelection(t)}Rs(t){const e=this.As.getSelectedNodesUnder(t);for(const t of e)this.As.removeFromSelection(t)}Ks(){return!0===this.$s.autoOpen?-1:"number"==typeof this.$s.autoOpen?this.$s.autoOpen:"string"==typeof this.$s.autoOpen?parseInt(this.$s.autoOpen,10):0}D(t){const e=this.getNode(t);return e?this.F(e):null}F(t){return t.isFolder()?this.Qs(t):this.Xs(t)}Js(){return this.ks.getNodeIdToBeSelected()}Us(){if(this.$s.data)this.loadData(this.$s.data);else{this.zs()?this.loadDataFromUrl():this.loadData([])}}Vs(t){const e=()=>{this.Cs||(this.Cs=!0,this.u("tree.init"))};this.tree=new this.$s.nodeClass(null,!0,this.$s.nodeClass),this.As.clear(),this.tree.loadFromData(t);const s=this.Ws();this.P(null),s?this.Zs().then(e):e()}Mt(){const t=document.activeElement;if(!t)return!1;const e=t.tagName;if("A"!==e&&"SPAN"!==e)return!1;const s=this.getNode(t);return s?.tree===this.tree}ti(t){const e=this.getSelectedNode();return!!e&&(t===e||t.isParentOf(e))}async Ys(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.P(e)}Bs(t){return!!this.$s.dragAndDrop&&this.Fs.mouseCapture(t)}js(t){if(!this.$s.dragAndDrop)return!1;const e=this.Fs.mouseDrag(t);return this.Ls.checkScrolling(t),e}Ps(t){return!!this.$s.dragAndDrop&&this.Fs.mouseStart(t)}Os(t){return!!this.$s.dragAndDrop&&(this.Ls.stopScrolling(),this.Fs.mouseStop(t))}Es(t){const e=t.parent;e?.parent&&!e.is_open&&this.openNode(e,!1)}P(t){const e=this.Mt(),s=!!t&&this.ti(t);this.xs.render(t),s&&this.ei(e),this.u("tree.refresh")}ws(){this.ks.saveState()}ei(t){const e=this.getSelectedNode();if(e){this.F(e).select(t)}}Ws(){const t=()=>{if(!1===this.$s.autoOpen)return!1;const t=this.Ks();let e=!1;return this.tree.iterate((s,i)=>s.load_on_demand?(e=!0,!1):!!s.hasChildren()&&(s.is_open=!0,i!==t)),e};let[e,s]=(()=>{const t=this.ks.getStateFromStorage();if(t){return[!0,this.ks.setInitialState(t)]}return[!1,!1]})();return e||(s=t()),s}async Zs(){return new Promise(t=>{const e=()=>{const e=this.Ks();let s=0;const i=t=>{s+=1,this.openNode(t,!1).then(()=>{s-=1,o()})},o=()=>{this.tree.iterate((t,s)=>t.load_on_demand?(t.is_loading||i(t),!1):(this.openNode(t,!1),s!==e)),0===s&&t()};o()};(()=>{const e=this.ks.getStateFromStorage();return!!e&&(this.ks.setInitialStateOnDemand(e).then(()=>{t()}),!0)})()||e()})}ct(t,e){this.Ts.set(t,e)}u(t,e){return this.Hs(this.nt,t,e)}}const B={deselectedNode:"deselected_node",moveInfo:"move_info",originalEvent:"click_event",parentNode:"parent_node",treeData:"tree_data"},j={doMove:"do_move",movedNode:"moved_node",originalEvent:"original_event",previousParent:"previous_parent",targetNode:"target_node"},P=(t,e)=>Object.fromEntries(Object.entries(t).map(([t,s])=>[e[t]??t,s])),O=(t,e,s)=>{const i=s?(t=>{const e=P(t,B);return e.move_info&&(e.move_info=P(e.move_info,j)),e})(s):{};let o;switch(i.element&&(i.$el=jQuery(i.element),delete i.element),e){case"tree.deselect":o=jQuery.Event("tree.select",{node:null,previous_node:i.node});break;case"tree.loaded_data":o=jQuery.Event("tree.loading_data",{...i,isLoading:!1,node:i.node??null});break;case"tree.loading_data":o=jQuery.Event("tree.loading_data",{...i,isLoading:!0,node:i.node??null});break;case"tree.set_data":i.parent_node=i.node,delete i.node,o=jQuery.Event("tree.load_data",i);break;default:o=jQuery.Event(e,i)}return jQuery(t).trigger(o),!o.isDefaultPrevented()},U="Node parameter is empty",Q="Parameter is empty: ";class R{m;si;l;constructor(t,e){this.m=jQuery(t),this.si=e}addNodeAfter(t,e){return this.l.addNodeAfter(t,e)}addNodeBefore(t,e){if(!e)throw Error(Q+"existingNode");return this.l.addNodeBefore(t,e)}addParentNode(t,e){if(!e)throw Error(Q+"existingNode");return this.l.addParentNode(t,e)}addToSelection(t,e){if(!t)throw Error(U);return this.l.addToSelection(t,e),this.m}appendNode(t,e){const s=e??this.l.tree;return this.l.appendNode(t,s)}closeNode(t,e){if(!t)throw Error(U);return this.l.closeNode(t,e??void 0),this.m}deinit(){this.m.off(),this.l.deinit()}destroy(){this.deinit()}getNodeByCallback(t){return this.l.getNodeByCallback(t)}getNodeByHtmlElement(t){const e=t instanceof HTMLElement?t:t.get(0);return e?this.l.getNode(e):null}getNodeById(t){return this.l.getNodeById(t)}getNodeByName(t){return this.l.getNodeByName(t)}getNodeByNameMustExist(t){return this.l.getNodeByNameMustExist(t)}getNodesByProperty(t,e){return this.l.getNodesByProperty(t,e)}getSelectedNode(){return this.l.getSelectedNode()}getSelectedNodes(){return this.l.getSelectedNodes()}getState(){return this.l.getState()}getStateFromStorage(){return this.l.getStateFromStorage()}getTree(){return this.l.getTree()}getVersion(){return"2.0.0"}init(){const t=this.m.get(0);this.m.on("tree.loading_data",this.ii.bind(this)),this.m.on("tree.load_failed",this.oi.bind(this));const e=this.ni(),s=new H({...e,classPrefix:"jqtree",commonClassName:"jqtree_common",htmlElement:t,overrideTriggerEventProvider:O,treeClassName:"jqtree-tree"});this.l=s}isDragging(){return this.l.isDragging()}isNodeSelected(t){if(!t)throw Error(U);return this.l.isNodeSelected(t)}loadData(t,e){return this.l.loadData(t,e),this.m}loadDataFromUrl(t,e,s){let i,o,n;return"string"==typeof t?(n=t,i=e,o=s):(i=t,o=e),this.l.loadDataFromUrl(n,i).then(()=>{o&&o()}).catch(t=>{throw t}),this.m}moveDown(){return this.l.moveDown(),this.m}moveNode(t,e,s){if(!t)throw Error(U);if(!e)throw Error(Q+"targetNode");if(!s)throw Error(Q+"position");return this.l.moveNode(t,e,s),this.m}moveUp(){return this.l.moveUp(),this.m}openNode(t,e,s){if(!t)throw Error(U);let i,o=null;return"function"==typeof e?(o=e,i=s):i=e,this.l.openNode(t,i).then(()=>{o&&o(t)}),this.m}prependNode(t,e){const s=e??this.l.tree;return this.l.prependNode(t,s)}refresh(){return this.l.refresh(),this.m}reload(t){return this.l.loadDataFromUrl(void 0,void 0).then(()=>{t&&t()}).catch(t=>{throw t}),this.m}removeFromSelection(t){if(!t)throw Error(U);return this.l.removeFromSelection(t),this.m}removeNode(t){if(!t)throw Error(U);if(!t.parent)throw Error("Node has no parent");return this.l.removeNode(t),this.m}scrollToNode(t){if(!t)throw Error(U);return this.l.scrollToNode(t),this.m}selectNode(t,e){return this.l.selectNode(t,e),this.m}setOption(t,e){return this.l.setOption(t,e),this.m}setState(t){return t&&this.l.setState(t),this.m}toggle(t,e=null){if(!t)throw Error(U);return this.l.toggle(t,e),this.m}toJson(){return this.l.toJson()}updateNode(t,e){if(!t)throw Error(U);return e?(this.l.updateNode(t,e),this.m):this.m}oi(t){const e=this.si.onLoadFailed;if(e){const{response:s}=t;e(s)}}ii(t){const e=this.si.onLoading;if(e){const{$el:s,isLoading:i,node:o}=t;e(i,o??void 0,s)}}ni(){function t(t){return t instanceof jQuery?t.get(0):t}const e=t(this.si.closedIcon),s=t(this.si.openedIcon);let i;const o=this.si.onCreateLi;let n;o&&(i=(t,e,s)=>{o(t,jQuery(e),s)});const r=this.si.onIsMoveHandle;return r&&(n=t=>r(jQuery(t))),{...this.si,closedIcon:e,onCreateLi:i,onIsMoveHandle:n,openedIcon:s}}}return(()=>{const t=(t,e)=>{const s=jQuery.data(t,e);return s&&s instanceof R?s:null},e=(e,s)=>{for(const i of e.get()){if(!t(i,"jqtree")){const t=new R(i,s??{});jQuery.data(i,"jqtree")||jQuery.data(i,"jqtree",t),t.init()}}return e};jQuery.fn.tree=function(s,...i){if(!s)return e(this,null);if("object"==typeof s){return e(this,s)}if("string"==typeof s&&"_"!==s[0]){const e=s;return"destroy"===s?void(e=>{for(const s of e.get()){const e=t(s,"jqtree");e&&e.destroy(),jQuery.removeData(s,"jqtree")}})(this):((t,e,s)=>{let i=null;for(const o of t.get()){const t=jQuery.data(o,"jqtree");if(t&&t instanceof R){const o=t[e];o&&"function"==typeof o&&(i=o.apply(t,s))}}return i})(this,e,i)}}})(),t.JqTreeWidget=R,t}({});
|
|
21
41
|
//# sourceMappingURL=tree.jquery.js.map
|