jqtree 2.0.0 → 2.0.2
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 +4 -4
- package/lib/tree.jquery.js +5 -1
- package/lib/version.js +1 -1
- package/package.json +2 -2
- package/src/jqtreeOptions.ts +1 -1
- package/src/tree.jquery.ts +4 -3
- package/src/version.ts +1 -1
- package/tree.jquery.debug.js +7 -3
- package/tree.jquery.debug.js.map +1 -1
- package/tree.jquery.js +2 -2
- package/tree.jquery.js.map +1 -1
package/tree.jquery.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
JqTree 2.0.
|
|
2
|
+
JqTree 2.0.2
|
|
3
3
|
|
|
4
4
|
Copyright 2026 Marco Braak
|
|
5
5
|
|
|
@@ -37,5 +37,5 @@ var jqtree=function(t){"use strict";class e{t;i;o;h;l;u;constructor({classNames:
|
|
|
37
37
|
@license
|
|
38
38
|
|
|
39
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}({});
|
|
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.2"}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{error:s,response:i}=t;e({error:s,response:i})}}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}({});
|
|
41
41
|
//# sourceMappingURL=tree.jquery.js.map
|