UNPKG

wunderbaum

Version:

JavaScript tree/grid/treegrid control.

67 lines 99.2 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).mar10={})}(this,(function(e){"use strict"; /*! * Wunderbaum - debounce.ts * Copyright (c) 2021-2025, Martin Wendt. Released under the MIT license. * v0.13.0, Sat, 08 Mar 2025 14:16:31 GMT (https://github.com/mar10/wunderbaum) */const t="object"==typeof global&&null!==global&&global.Object===Object&&global,i="object"==typeof globalThis&&null!==globalThis&&globalThis.Object==Object&&globalThis,s="object"==typeof self&&null!==self&&self.Object===Object&&self,n=i||t||s||Function("return this")();function o(e){const t=typeof e;return null!=e&&("object"===t||"function"===t)}function r(e,t=0,i={}){let s,r,l,a,d,c,h=0,u=!1,p=!1,f=!0;const g=!t&&0!==t&&"function"==typeof n.requestAnimationFrame;if("function"!=typeof e)throw new TypeError("Expected a function");function v(t){const i=s,n=r;return s=r=void 0,h=t,a=e.apply(n,i),a}function m(e,t){return g?(n.cancelAnimationFrame(d),n.requestAnimationFrame(e)):setTimeout(e,t)}function b(e){const i=e-c;return void 0===c||i>=t||i<0||p&&e-h>=l}function y(){const e=Date.now();if(b(e))return w(e);d=m(y,function(e){const i=e-h,s=t-(e-c);return p?Math.min(s,l-i):s}(e))}function w(e){return d=void 0,f&&s?v(e):(s=r=void 0,a)}function E(...e){const i=Date.now(),n=b(i);if(s=e,r=this,c=i,n){if(void 0===d)return function(e){return h=e,d=m(y,t),u?v(e):a}(c);if(p)return d=m(y,t),v(c)}return void 0===d&&(d=m(y,t)),a}return t=+t||0,o(i)&&(u=!!i.leading,p="maxWait"in i,l=p?Math.max(+i.maxWait||0,t):l,f="trailing"in i?!!i.trailing:f),E.cancel=function(){void 0!==d&&function(e){if(g)return n.cancelAnimationFrame(e);clearTimeout(e)}(d),h=0,s=c=r=d=void 0},E.flush=function(){return void 0===d?a:w(Date.now())},E.pending=function(){return void 0!==d},E}function l(e,t=0,i={}){let s=!0,n=!0;if("function"!=typeof e)throw new TypeError("Expected a function");return o(i)&&(s="leading"in i?!!i.leading:s,n="trailing"in i?!!i.trailing:n),r(e,t,{leading:s,trailing:n,maxWait:t})} /*! * Wunderbaum - util * Copyright (c) 2021-2025, Martin Wendt. Released under the MIT license. * v0.13.0, Sat, 08 Mar 2025 14:16:31 GMT (https://github.com/mar10/wunderbaum) */const a={0:"",1:"left",2:"middle",3:"right",4:"back",5:"forward"},d=function(){const e=navigator;return{isMac:/Mac/.test(e.platform)}}().isMac,c=/[&<>"'/]/g,h=/[<>"'/]/g,u={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;","/":"&#x2F;"};class p extends Error{constructor(e){super(e),this.name="ValidationError"}}function f(e,t){if(!e)throw t=t||"Assertion failed.",new Error(t)}function g(e){"loading"===document.readyState?document.addEventListener("DOMContentLoaded",e):e()}function v(e){throw new Error(e)}function m(e){return(""+e).replace(c,(function(e){return u[e]}))}function b(e){return(""+e).replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}function y(e){return(""+e).replace(h,(function(e){return u[e]}))}function w(e,t=!1){const i=e.tagName;let s=null;if("SPAN"===i&&e.classList.contains("wb-col")){const i=e,n=i.querySelector("input,select");if(n)return w(n,t);i.innerText=""+s}else if("INPUT"===i){const i=e;switch(i.type){case"button":case"reset":case"submit":case"image":break;case"checkbox":s=i.indeterminate?null:i.checked;break;case"date":case"datetime":case"datetime-local":case"month":case"time":case"week":s=t?i.valueAsDate:i.value;break;case"number":case"range":s=i.valueAsNumber;break;case"radio":{const e=i.name,t=i.parentElement.querySelector(`input[name="${e}"]:checked`);s=t?t.value:void 0}break;default:s=i.value}}else if("SELECT"===i){s=e.value}return s}function E(e,t){const i=C(e).style;t?"none"===i.display&&(i.display=""):""===i.display&&(i.display="none")}function x(e){const t=document.createElement("template");return t.innerHTML=e.trim(),t.content.firstElementChild}const _=new Set(["Alt","Control","Meta","Shift"]);function C(e){return e?"string"==typeof e?document.querySelector(e):e:null}function k(e){const t=e.key,i=e.type,s=[];return e.altKey&&s.push("Alt"),e.ctrlKey&&s.push("Control"),e.metaKey&&s.push("Meta"),e.shiftKey&&s.push("Shift"),"click"===i||"dblclick"===i?s.push(a[e.button]+i):"wheel"===i?s.push(i):_.has(t)||s.push(t),s.join("+")}function N(...e){for(let t=1;t<e.length;t++){const i=e[t];if(null!=i)for(const t in i)Object.prototype.hasOwnProperty.call(i,t)&&(e[0][t]=i[t])}return e[0]}function S(e){return Array.isArray(e)}function D(e){return 0===Object.keys(e).length&&e.constructor===Object}function I(e){return"[object Object]"===Object.prototype.toString.call(e)}function L(e,t,i,s){let n,o;e=C(e),s?(n=i,o=s):(n="",o=i),t.split(" ").forEach((t=>{e.addEventListener(t,(function(e){if(!n)return o(e);if(e.target){let t=e.target;if(t.matches(n))return o(e);if(t=t.closest(n),t)return o(e)}}))}))}function M(e,t,i,s){let n,o;const r=s||e,l=e[t],a=(...e)=>l.apply(r,e),d=e=>l.apply(r,e);e[t]=(...e)=>{try{return n=r._super,o=r._superApply,r._super=a,r._superApply=d,i.apply(r,e)}finally{r._super=n,r._superApply=o}}}function T(e,t,i=void 0){let s;e&&t.indexOf(".")>=0&&([s,t]=t.split("."),e=e[s]);const n=e?e[t]:null;return null!=n?n:i}function $(e,t){const i=t.indexOf(e);return t[(i+1)%t.length]}function O(e){if(e instanceof Set)return e;if("string"==typeof e){const t=new Set;for(const i of e.split(" "))t.add(i.trim());return t}if(Array.isArray(e))return new Set(e);throw new Error("Cannot convert to Set<string>: "+e)}function A(...e){for(const t of e){if("number"==typeof t)return t;if("string"==typeof t&&t.endsWith("px"))return parseInt(t,10);f(null==t,`Expected a number or string like '123px': ${t}`)}throw new Error(`Expected a string like '123px': ${e}`)}function P(...e){for(const t of e)if(null!=t)return!!t;throw new Error("No default boolean value provided")}function F(e){return"number"==typeof e?!!e:e}function R(e,t){const i=Object.assign({minDelay:16,defaultDelay:200,maxDelay:5e3,delayFactor:2},t),s=Math.max(16,+i.minDelay),n=+i.maxDelay;let o=0,r=null,l=null;const a=(...t)=>{if(o)r=t,o+=1;else{o=1;const d=t;r=null;const c=Date.now();try{e.apply(this,d)}catch(e){console.error(e)}const h=Date.now()-c,u=Math.min(Math.max(s,h*i.delayFactor),n),p=Math.max(s,u-h);l=setTimeout((()=>{l=null,o=0,null!=r&&a.apply(this,r)}),p)}};return a.cancel=()=>{l&&(clearTimeout(l),l=null),r=null,o=0},a.pending=()=>!!l,a.flush=()=>{throw new Error("Not implemented")},a}var z,q,U,K,V,B=Object.freeze({__proto__:null,Deferred:class{constructor(){this.thens=[],this.catches=[],this.status=""}resolve(e){if(this.status)throw new Error("already settled");this.status="resolved",this.resolvedValue=e,this.thens.forEach((t=>t(e))),this.thens=[]}reject(e){if(this.status)throw new Error("already settled");this.status="rejected",this.rejectedError=e,this.catches.forEach((t=>t(e))),this.catches=[]}then(e){"resolved"===status?e(this.resolvedValue):this.thens.unshift(e)}catch(e){"rejected"===this.status?e(this.rejectedError):this.catches.unshift(e)}promise(){return{then:this.then,catch:this.catch}}},MAX_INT:9007199254740991,MOUSE_BUTTONS:a,ValidationError:p,adaptiveThrottle:R,assert:f,debounce:r,documentReady:g,documentReadyPromise:function(){return new Promise((e=>{g(e)}))},each:function(e,t){if(null==e)return e;const i=e.length;let s=0;if("number"==typeof i)for(;s<i&&!1!==t.call(e[s],s,e[s]);s++);else for(const i in e)if(!1===t.call(e[s],i,e[i]))break;return e},elemFromHtml:x,elemFromSelector:C,error:v,escapeHtml:m,escapeRegex:b,escapeTooltip:y,eventToString:k,extend:N,extractHtmlText:function(e){return e.indexOf(">")>=0&&v("Not implemented"),e},getOption:T,getValueFromElem:w,intToBool:F,isArray:S,isEmptyObject:D,isFunction:function(e){return"function"==typeof e},isMac:d,isPlainObject:I,noop:function(...e){},onEvent:L,overrideMethod:M,rotate:$,setElemDisplay:E,setTimeoutPromise:function(e,t){return new Promise(((i,s)=>{setTimeout((()=>{try{i(e.apply(this))}catch(e){s(e)}}),t)}))},setValueToElem:function e(t,i){const s=t.tagName;if("SPAN"===s&&t.classList.contains("wb-col")){const s=t,n=s.querySelector("input,select");if(n)return e(n,i);s.innerText=""+i}else if("INPUT"===s){const e=t,s=e.type;switch(s){case"checkbox":e.indeterminate=null===i,e.checked=!!i;break;case"date":case"month":case"time":case"week":case"datetime":case"datetime-local":e.valueAsDate=new Date(i);break;case"number":case"range":null==i?e.value=i:e.valueAsNumber=i;break;case"radio":v(`Not yet implemented: ${s}`);break;case"button":case"reset":case"submit":case"image":break;default:e.value=null!=i?i:""}}else if("SELECT"===s){const e=t;null==i?e.selectedIndex=-1:e.value=i}},sleep:async function(e){return new Promise((t=>setTimeout(t,e)))},throttle:l,toBool:P,toPixel:A,toSet:O,toggleCheckbox:function(e,t,i){const s=C(e);if(f("checkbox"===s.type,`Expected a checkbox: ${s.type}`),null!=i||(i=s.classList.contains("wb-tristate")||s.indeterminate),void 0===t){switch(s.indeterminate?null:s.checked){case!0:t=!1;break;case!1:t=!i||null;break;case null:t=!0}}s.indeterminate=null==t,s.checked=!!t},type:function(e){return Object.prototype.toString.call(e).replace(/^\[object (.+)\]$/,"$1").toLowerCase()}}); /*! * Wunderbaum - types * Copyright (c) 2021-2025, Martin Wendt. Released under the MIT license. * v0.13.0, Sat, 08 Mar 2025 14:16:31 GMT (https://github.com/mar10/wunderbaum) */!function(e){e.any="any",e.data="data",e.colStructure="colStructure",e.resize="resize",e.row="row",e.structure="structure",e.status="status",e.scroll="scroll"}(z||(z={})),function(e){e.clearMarkup="clearMarkup",e.header="header",e.redraw="redraw",e.scroll="scroll"}(q||(q={})),function(e){e.ok="ok",e.loading="loading",e.error="error",e.noData="noData",e.paging="paging"}(U||(U={})),function(e){e.unknown="",e.checkbox="checkbox",e.column="column",e.expander="expander",e.icon="icon",e.prefix="prefix",e.title="title"}(K||(K={})),function(e){e.startRow="startRow",e.cell="cell",e.startCell="startCell",e.row="row"}(V||(V={})); /*! * Wunderbaum - wb_extension_base * Copyright (c) 2021-2025, Martin Wendt. Released under the MIT license. * v0.13.0, Sat, 08 Mar 2025 14:16:31 GMT (https://github.com/mar10/wunderbaum) */ class H{constructor(e,t,i){this.enabled=!0,this.tree=e,this.id=t,this.treeOpts=e.options;const s=e.options;void 0===this.treeOpts[t]?s[t]=this.extensionOpts=N({},i):(this.extensionOpts=N({},i,s[t]),s[t]=this.extensionOpts),this.enabled=this.getPluginOption("enabled",!0)}init(){this.tree.element.classList.add("wb-ext-"+this.id)}getPluginOption(e,t){var i;return null!==(i=this.extensionOpts[e])&&void 0!==i?i:t}setPluginOption(e,t){this.extensionOpts[e]=t}setEnabled(e=!0){return this.setPluginOption("enabled",!!e)}onKeyEvent(e){}onRender(e){}} /*! * Wunderbaum - ext-filter * Copyright (c) 2021-2025, Martin Wendt. Released under the MIT license. * v0.13.0, Sat, 08 Mar 2025 14:16:31 GMT (https://github.com/mar10/wunderbaum) */const j="￷",W="￸",G=new RegExp(b("￷"),"g"),Q=new RegExp(b("￸"),"g");class Y extends H{constructor(e){super(e,"filter",{autoApply:!0,autoExpand:!1,matchBranch:!1,connect:null,fuzzy:!1,hideExpanders:!1,highlight:!0,leavesOnly:!1,mode:"dim",noData:!0}),this.queryInput=null,this.prevButton=null,this.nextButton=null,this.modeButton=null,this.matchInfoElem=null,this.lastFilterArgs=null}init(){super.init();this.getPluginOption("connect")&&this._connectControls()}setPluginOption(e,t){if(super.setPluginOption(e,t),"mode"===e)this.tree.filterMode="hide"===t?"hide":"mark"===t?"mark":"dim",this.tree.updateFilter()}_updatedConnectedControls(){var e;const t=null!==this.tree.filterMode,i=this.tree.getActiveNode(),s=t?this.countMatches():0,n=this.treeOpts.strings;let o="?";if(this.matchInfoElem)if(t){let t;0===s?t=n.noMatch:i&&i.match>=1?(o=null!==(e=i.match)&&void 0!==e?e:"?",t=n.matchIndex):t=n.queryResult,t=t.replace("${count}",this.tree.count().toLocaleString()).replace("${match}",""+o).replace("${matches}",s.toLocaleString()),this.matchInfoElem.textContent=t}else this.matchInfoElem.textContent="";this.nextButton instanceof HTMLButtonElement&&(this.nextButton.disabled=!s),this.prevButton instanceof HTMLButtonElement&&(this.prevButton.disabled=!s),this.modeButton&&(this.modeButton.disabled=!t,this.modeButton.classList.toggle("wb-filter-hide","hide"===this.tree.filterMode))}_connectControls(){const e=this.tree,t=this.getPluginOption("connect");if(t){if(this.queryInput=C(t.inputElem),!this.queryInput)throw new Error(`Invalid 'filter.connect' option: ${t.inputElem}.`);this.prevButton=C(t.prevButton),this.nextButton=C(t.nextButton),this.modeButton=C(t.modeButton),this.matchInfoElem=C(t.matchInfoElem),this.prevButton&&L(this.prevButton,"click",(()=>{e.findRelatedNode(e.getActiveNode()||e.getFirstChild(),"prevMatch"),this._updatedConnectedControls()})),this.nextButton&&L(this.nextButton,"click",(()=>{e.findRelatedNode(e.getActiveNode()||e.getFirstChild(),"nextMatch"),this._updatedConnectedControls()})),this.modeButton&&L(this.modeButton,"click",(t=>{this.tree.filterMode&&this.setPluginOption("mode","dim"===e.filterMode?"hide":"dim")})),L(this.queryInput,"input",r((e=>{this.filterNodes(this.queryInput.value.trim(),{})}),700)),this._updatedConnectedControls()}}_applyFilterNoUpdate(e,t){return this.tree.runWithDeferredUpdate((()=>this._applyFilterImpl(e,t)))}_applyFilterImpl(e,t){var i;let s=0;const n=Date.now(),o=this.tree,r=o.options,l=r.autoCollapse,a=N({},r.filter,t),d="hide"===a.mode,c=!!a.matchBranch,h=!!a.leavesOnly&&!c;let u,p;if("string"==typeof e||e instanceof RegExp){if(""===e)return o.logInfo("Passing an empty string as a filter is handled as clearFilter()."),this.clearFilter(),0;if(a.fuzzy){f("string"==typeof e,"fuzzy filter must be a string");const t=e.split("").map(b).reduce((function(e,t){return e+"([^"+t+"]*)"+t}),"");u=new RegExp(t,"i")}else if(e instanceof RegExp)u=e,p=e;else{const t=b(e);u=new RegExp(t,"i"),p=new RegExp(t,"gi")}o.logDebug(`Filtering nodes by '${u}'`),e=e=>{if(!e.title)return!1;const t=e.title,i=u.exec(t);if(i&&a.highlight){let s;s=a.fuzzy?function(e,t,i=!0){const s=[];for(let e=1;e<t.length;e++){const i=t[e].length+(1===e?0:1)+(s[s.length-1]||0);s.push(i)}const n=e.split("");i?s.forEach((function(e){n[e]=j+n[e]+W})):s.forEach((function(e){n[e]="<mark>"+n[e]+"</mark>"}));return n.join("")} /*! * Wunderbaum - ext-keynav * Copyright (c) 2021-2025, Martin Wendt. Released under the MIT license. * v0.13.0, Sat, 08 Mar 2025 14:16:31 GMT (https://github.com/mar10/wunderbaum) */(t,i,!0):t.replace(p,(function(e){return j+e+W})),e.titleWithHighlight=m(s).replace(G,"<mark>").replace(Q,"</mark>")}return!!i}}return o.filterMode=null!==(i=a.mode)&&void 0!==i?i:"dim",this.lastFilterArgs=arguments,o.element.classList.toggle("wb-ext-filter-hide",!!d),o.element.classList.toggle("wb-ext-filter-dim","dim"===a.mode),o.element.classList.toggle("wb-ext-filter-hide-expanders",!!a.hideExpanders),o.root.subMatchCount=0,o.visit((e=>{delete e.match,delete e.titleWithHighlight,e.subMatchCount=0})),o.setStatus(U.ok),r.autoCollapse=!1,o.visit((t=>{if(h&&null!=t.children)return;let i=e(t);if("skip"===i)return t.visit((function(e){e.match=void 0}),!0),"skip";let n=!1;(c||"branch"===i)&&t.parent.match&&(i=!0,n=!0),i&&(s++,t.match=s,t.visitParents((e=>{e!==t&&(e.subMatchCount+=1),!a.autoExpand||n||e.expanded||(e.setExpanded(!0,{noAnimation:!0,noEvents:!0}),e._filterAutoExpanded=!0)}),!0))})),r.autoCollapse=l,0===s&&a.noData&&d&&("string"==typeof a.noData?o.root.setStatus(U.noData,{message:a.noData}):o.root.setStatus(U.noData)),o.logDebug(`Filter '${e}' found ${s} nodes in ${Date.now()-n} ms.`),this._updatedConnectedControls(),s}filterNodes(e,t){return this._applyFilterNoUpdate(e,t)}filterBranches(e,t){return f(void 0===t.matchBranch,"filterBranches() is deprecated."),t.matchBranch=!0,this._applyFilterNoUpdate(e,t)}countMatches(){let e=0;return this.tree.visit((t=>{t.match&&!t.statusNodeType&&e++})),e}updateFilter(){var e;const t=this.tree;t.filterMode&&this.lastFilterArgs&&(null===(e=t.options.filter)||void 0===e?void 0:e.autoApply)?this._applyFilterNoUpdate.apply(this,this.lastFilterArgs):t.logWarn("updateFilter(): no filter active."),this._updatedConnectedControls()}clearFilter(){const e=this.tree;e.enableUpdate(!1),e.setStatus(U.ok),delete e.root.match,delete e.root.subMatchCount,e.visit((e=>{delete e.match,delete e.subMatchCount,delete e.titleWithHighlight,e._filterAutoExpanded&&e.expanded&&e.setExpanded(!1,{noAnimation:!0,noEvents:!0}),delete e._filterAutoExpanded})),e.filterMode=null,this.lastFilterArgs=null,e.element.classList.remove("wb-ext-filter-dim","wb-ext-filter-hide"),this._updatedConnectedControls(),e.enableUpdate(!0)}}class J extends H{constructor(e){super(e,"keynav",{})}_getEmbeddedInputElem(e){var t;let i=null;if(e&&null!=e.type)i=e;else{const e=null===(t=this.tree.getActiveColElem())||void 0===t?void 0:t.querySelector("input,select");e&&(i=e)}return i}_isCurInputFocused(){var e;return!!(null===(e=this.tree.getActiveColElem())||void 0===e?void 0:e.querySelector("input:focus,select:focus"))}onKeyEvent(e){const t=e.event,i=this.tree,s=e.options,n=!t.ctrlKey||s.autoActivate,o=this._getEmbeddedInputElem(t.target),r=o&&this._isCurInputFocused(),l=s.navigationModeOption;let a,d=k(t),c=e.node,h=!0;if(!i.isEnabled())return!1;if(!1===i._callEvent("keydown",e))return!1;if(!1===i._callMethod("edit._preprocessKeyEvent",e))return!1;if(!c){const e=i.getFocusNode()||i.getActiveNode(),t=i.getFirstChild();if(!e&&t&&"ArrowDown"===d)return t.logInfo("Keydown: activate first node."),void t.setActive();a=e||t,a&&(a.setFocus(),c=i.getFocusNode(),c.logInfo("Keydown: force focus on active node."))}const u=c.isColspan();if(i.isRowNav()){if(r){switch(d){case"Enter":o.blur(),i.setFocus();break;case"Escape":c._render(),i.setFocus()}return}if(s.quicksearch&&1===d.length&&/^\w$/.test(d)&&!o){const e=Date.now();e-i.lastQuicksearchTime>500&&(i.lastQuicksearchTerm=""),i.lastQuicksearchTime=e,i.lastQuicksearchTerm+=d;const s=i.findNextNode(i.lastQuicksearchTerm,i.getActiveNode());return s&&s.setActive(!0,{event:t}),void t.preventDefault()}switch(d){case"Enter":c.isActive()&&(c.isExpanded()?d="Subtract":c.isExpandable(!0)&&(d="Add"));break;case"ArrowLeft":c.expanded&&(d="Subtract");break;case"ArrowRight":if(!c.expanded&&c.isExpandable(!0))d="Add";else if(l===V.startCell||l===V.startRow)return t.preventDefault(),i.setCellNav(),!1}switch(d){case"+":case"Add":c.setExpanded(!0);break;case"-":case"Subtract":c.setExpanded(!1);break;case" ":c.getOption("checkbox")?c.toggleSelected():c.setActive(!0,{event:t});break;case"Enter":c.setActive(!0,{event:t});break;case"ArrowDown":case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"Backspace":case"End":case"Home":case"Control+End":case"Control+Home":case"Meta+ArrowDown":case"Meta+ArrowUp":case"PageDown":case"PageUp":c.navigate(d,{activate:n,event:t});break;default:h=!1}}else{const e=o?o.type||o.tagName:"",s=o&&"checkbox"!==e;if(r){if("Escape"===d)return c.logDebug("Reset focused input on Escape"),o.setCustomValidity(""),c._render(),i.setFocus(),void i.setColumn(i.activeColIdx);if("Enter"!==d)return o&&o.checkValidity&&!o.checkValidity()?(c.logDebug(`Ignored ${d} inside invalid input`),!1):void c.logDebug(`Ignored ${d} inside focused input`)}else if(o&&1===d.length&&s)return o.focus(),o.value="",c.logDebug(`Focus input: ${d}`),!1;switch("Tab"===d?(d="ArrowRight",h=!0):"Shift+Tab"===d&&(d=i.activeColIdx>0?"ArrowLeft":"",h=!0),d){case"+":case"Add":c.setExpanded(!0);break;case"-":case"Subtract":c.setExpanded(!1);break;case" ":0===i.activeColIdx&&c.getOption("checkbox")?(c.toggleSelected(),h=!0):o&&"checkbox"===e&&(o.click(),h=!0);break;case"F2":o&&!r&&s&&(o.focus(),h=!0);break;case"Enter":i.setFocus(),(0===i.activeColIdx||u)&&c.isExpandable()?(c.setExpanded(!c.isExpanded()),h=!0):o&&!r&&s&&(o.focus(),h=!0);break;case"Escape":i.setFocus(),c.log("keynav: focus tree..."),i.isCellNav()&&l!==V.cell&&(c.log("keynav: setCellNav(false)"),i.setCellNav(!1),i.setFocus(),h=!0);break;case"ArrowLeft":i.setFocus(),u&&c.isExpanded()?c.setExpanded(!1):!u&&i.activeColIdx>0?i.setColumn(i.activeColIdx-1):l!==V.cell&&i.setCellNav(!1),h=!0;break;case"ArrowRight":i.setFocus(),u&&!c.isExpanded()?c.setExpanded():!u&&i.activeColIdx<i.columns.length-1&&i.setColumn(i.activeColIdx+1),h=!0;break;case"Home":i.setFocus(),!u&&i.activeColIdx>0&&i.setColumn(0),h=!0;break;case"End":i.setFocus(),!u&&i.activeColIdx<i.columns.length-1&&i.setColumn(i.columns.length-1),h=!0;break;case"ArrowDown":case"ArrowUp":case"Backspace":case"Control+End":case"Control+Home":case"Meta+ArrowDown":case"Meta+ArrowUp":case"PageDown":case"PageUp":c.navigate(d,{activate:n,event:t}),h=!0;break;default:h=!1}}h&&t.preventDefault()}} /*! * Wunderbaum - ext-logger * Copyright (c) 2021-2025, Martin Wendt. Released under the MIT license. * v0.13.0, Sat, 08 Mar 2025 14:16:31 GMT (https://github.com/mar10/wunderbaum) */class X extends H{constructor(e){super(e,"logger",{}),this.ignoreEvents=new Set(["iconBadge","render","discard"]),this.prefix=e+".ext-logger"}init(){const e=this.tree;if(e.getOption("debugLevel")>=4){const t=this.ignoreEvents,i=this.prefix;M(e,"callEvent",(function(s,n){if(t.has(s))return e._superApply(arguments);const o=Date.now(),r=e._superApply(arguments);return e.logDebug(`${i}: callEvent('${s}') took ${Date.now()-o} ms.`,arguments[1]),r}))}}onKeyEvent(e){this.tree.logDebug(`${this.prefix}: onKeyEvent()`,e)}} /*! * Wunderbaum - ext-dnd * Copyright (c) 2021-2025, Martin Wendt. Released under the MIT license. * v0.13.0, Sat, 08 Mar 2025 14:16:31 GMT (https://github.com/mar10/wunderbaum) */const Z="application/x-wunderbaum-node";class ee extends H{constructor(e){super(e,"dnd",{autoExpandMS:1500,multiSource:!1,effectAllowed:"all",dropEffectDefault:"move",guessDropEffect:!0,preventForeignNodes:!1,preventLazyParents:!0,preventNonNodes:!1,preventRecursion:!0,preventSameParent:!1,preventVoidMoves:!0,serializeClipboardData:!0,scroll:!0,scrollSensitivity:20,scrollSpeed:5,sourceCopyHook:null,dragStart:null,drag:null,dragEnd:null,dragEnter:null,dragOver:null,dragExpand:null,drop:null,dragLeave:null}),this.srcNode=null,this.lastTargetNode=null,this.lastEnterStamp=0,this.lastAllowedDropRegions=null,this.lastDropEffect=null,this.lastDropRegion=!1,this.currentScrollDir=0,this.applyScrollDirThrottled=l(this._applyScrollDir,50)}init(){super.init();const e=this.tree,t=e.options.dnd;t.dragStart&&L(e.element,"dragstart drag dragend",this.onDragEvent.bind(this)),t.dragEnter&&L(e.element,"dragenter dragover dragleave drop",this.onDropEvent.bind(this))}_leaveNode(){const e=this.lastTargetNode;this.lastEnterStamp=0,e&&(e.setClass("wb-drop-target wb-drop-over wb-drop-after wb-drop-before",!1),this.lastTargetNode=null)}unifyDragover(e){if(!1===e)return!1;if(e instanceof Set)return e.size>0&&e;if(!0===e)return new Set(["over","before","after"]);if("string"==typeof e||S(e))return(e=O(e)).size>0&&e;throw new Error("Unsupported drop region definition: "+e)}_calcDropRegion(e,t){const i=this.tree.options.rowHeightPx,s=e.offsetY;return!!t&&(3===t.size?s<.25*i?"before":s>.75*i?"after":"over":1===t.size&&t.has("over")?"over":s>i/2?"after":"before")}_guessDropEffect(e){var t;const i=this.treeOpts.dnd,s=null!==(t=i.effectAllowed)&&void 0!==t?t:"all",n=["all","copy","copyLink","copyMove"].includes(s),o=["all","link","copyLink","linkMove"].includes(s),r=["all","move","copyMove","linkMove"].includes(s);let l=i.dropEffectDefault;return i.guessDropEffect&&(d?(e.altKey&&n&&(l="copy"),e.metaKey&&r&&(l="move"),e.altKey&&e.metaKey&&o&&(l="link")):(e.ctrlKey&&n&&(l="copy"),e.shiftKey&&r&&(l="move"),e.altKey&&o&&(l="link"))),l}_isVoidDrop(e,t,i){return!(!this.treeOpts.dnd.preventVoidMoves||!t)&&("before"===i&&e===t.getNextSibling()||"after"===i&&e===t.getPrevSibling()||(t===e||t.parent===e))}_applyScrollDir(){if(this.isDragging()&&this.currentScrollDir){const e=this.tree.options.dnd,t=this.tree.element,i=t.scrollTop;this.currentScrollDir<0?t.scrollTop=Math.max(0,i-e.scrollSpeed):this.currentScrollDir>0&&(t.scrollTop=i+e.scrollSpeed)}}_autoScroll(e){const t=this.tree,i=t.options.dnd.scrollSensitivity,s=t.element,n=t.headerElement.clientHeight,o=s.offsetHeight,r=s.scrollTop;return this.currentScrollDir=0,r>0&&e>0&&e<=i+n?this.currentScrollDir=-1:r<s.scrollHeight-o&&e>=o-i&&(this.currentScrollDir=1),this.currentScrollDir&&this.applyScrollDirThrottled(),s.scrollTop-r}isDragging(){return!!this.srcNode}onDragEvent(e){var t;const i=this.treeOpts.dnd,s=ve.getNode(e);if(s){if(["dragstart","dragend"].includes(e.type)&&this.tree.logDebug(`onDragEvent.${e.type} srcNode: ${s}`,e),"dragstart"===e.type){if(e.dataTransfer.effectAllowed=i.effectAllowed,s.isEditingTitle())return s.logDebug("Prevented dragging node in edit mode."),e.preventDefault(),!1;if(!s._callEvent("dnd.dragStart",{event:e}))return e.preventDefault(),!1;const n=s.toDict(!0,(e=>{e._orgKey=e.key,delete e.key}));n._treeId=s.tree.id,i.serializeClipboardData&&("function"==typeof i.serializeClipboardData?e.dataTransfer.setData(Z,i.serializeClipboardData(n,s)):e.dataTransfer.setData(Z,JSON.stringify(n))),(null===(t=e.dataTransfer)||void 0===t?void 0:t.types.includes("text/plain"))||e.dataTransfer.setData("text/plain",s.title),this.srcNode=s,setTimeout((()=>{s.setClass("wb-drag-source")}),0)}else"drag"===e.type?i.drag&&s._callEvent("dnd.drag",{event:e}):"dragend"===e.type&&(s.setClass("wb-drag-source",!1),this.srcNode=null,this.lastTargetNode&&this._leaveNode(),s._callEvent("dnd.dragEnd",{event:e}));return!0}this.tree.logWarn(`onDragEvent.${e.type}: no node`)}onDropEvent(e){var t;const i=this.srcNode,s=i?i.tree:null,n=ve.getNode(e),o=this.treeOpts.dnd,r=e.dataTransfer,l=this._calcDropRegion(e,this.lastAllowedDropRegions),a=(e,t)=>(e&&this.tree.log(`Prevented drop operation (${t}).`),e);if(n){if(["drop"].includes(e.type)&&this.tree.logDebug(`onDropEvent.${e.type} targetNode: ${n}, ea: ${null==r?void 0:r.effectAllowed}, de: ${null==r?void 0:r.dropEffect}, cy: ${e.offsetY}, r: ${l}, srcNode: ${i}`,e),"dragenter"===e.type){if(this.lastAllowedDropRegions=null,this.lastTargetNode&&this.lastTargetNode!==n&&this._leaveNode(),this.lastTargetNode=n,this.lastEnterStamp=Date.now(),a(n.isStatusNode(),"is status node")||a(o.preventForeignNodes&&n.tree!==s,"preventForeignNodes")||a(o.preventLazyParents&&!n.isLoaded(),"preventLazyParents")||a(o.preventNonNodes&&!i,"preventNonNodes")||a(o.preventRecursion&&(null==i?void 0:i.isAncestorOf(n)),"preventRecursion")||a(o.preventSameParent&&i&&n.parent===i.parent,"preventSameParent")||a(o.preventVoidMoves&&n===i,"preventVoidMoves"))return r.dropEffect="none",!0;r.dropEffect=this._guessDropEffect(e)||"none";let t=n._callEvent("dnd.dragEnter",{event:e,sourceNode:i});if(t=this.unifyDragover(t),!t)return r.dropEffect="none",!0;this.lastAllowedDropRegions=t,this.lastDropEffect=r.dropEffect;const l=this._calcDropRegion(e,this.lastAllowedDropRegions);return n.setClass("wb-drop-target"),n.setClass("wb-drop-over","over"===l),n.setClass("wb-drop-before","before"===l),n.setClass("wb-drop-after","after"===l),e.preventDefault(),!1}if("dragover"===e.type){const t=e.clientY-this.tree.element.offsetTop;this._autoScroll(t),r.dropEffect=this._guessDropEffect(e)||"none",n._callEvent("dnd.dragOver",{event:e,sourceNode:i});const s=this._calcDropRegion(e,this.lastAllowedDropRegions);if(this.lastDropRegion=s,this.lastDropEffect=r.dropEffect,o.autoExpandMS>0&&n.isExpandable(!0)&&!n._isLoading&&Date.now()-this.lastEnterStamp>o.autoExpandMS&&!1!==n._callEvent("dnd.dragExpand",{event:e,sourceNode:i})&&n.setExpanded(),!s||this._isVoidDrop(n,i,s))return;return n.setClass("wb-drop-over","over"===s),n.setClass("wb-drop-before","before"===s),n.setClass("wb-drop-after","after"===s),e.preventDefault(),!1}if("dragleave"===e.type)n._callEvent("dnd.dragLeave",{event:e,sourceNode:i});else if("drop"===e.type){e.stopPropagation(),e.preventDefault(),this._leaveNode();const i=this.lastDropRegion;let s=null===(t=e.dataTransfer)||void 0===t?void 0:t.getData(Z);s=s?JSON.parse(s):null;const o=this.srcNode,r=this.lastDropEffect;setTimeout((()=>{n._callEvent("dnd.drop",{event:e,region:i,suggestedDropMode:"over"===i?"appendChild":i,suggestedDropEffect:r,sourceNode:o,sourceNodeData:s})}),10)}return!1}this._leaveNode()}} /*! * Wunderbaum - drag_observer * Copyright (c) 2021-2025, Martin Wendt. Released under the MIT license. * v0.13.0, Sat, 08 Mar 2025 14:16:31 GMT (https://github.com/mar10/wunderbaum) */class te{constructor(e){if(this.start={event:null,x:0,y:0,altKey:!1,ctrlKey:!1,metaKey:!1,shiftKey:!1},this.dragElem=null,this.dragging=!1,this.customData={},this.events=["mousedown","mouseup","mousemove","keydown"],!e.root)throw new Error("Missing `root` option.");this.opts=Object.assign({thresh:5},e),this.root=e.root,this._handler=this.handleEvent.bind(this),this.events.forEach((e=>{this.root.addEventListener(e,this._handler)}))}disconnect(){this.events.forEach((e=>{this.root.removeEventListener(e,this._handler)}))}getDragElem(){return this.dragElem}isDragging(){return this.dragging}stopDrag(e){if(this.dragging&&this.opts.dragstop&&e){e.type="dragstop";try{this.opts.dragstop(e)}catch(e){console.error("dragstop error",e)}}this.dragElem=null,this.dragging=!1,this.start.event=null,this.customData={}}handleEvent(e){const t=e.type,i=this.opts,s={type:e.type,startEvent:"mousedown"===t?e:this.start.event,event:e,customData:this.customData,dragElem:this.dragElem,dx:e.pageX-this.start.x,dy:e.pageY-this.start.y,apply:void 0};switch(t){case"keydown":this.stopDrag(s);break;case"mousedown":if(this.dragElem){this.stopDrag(s);break}if(i.selector){let t=e.target;if(t.matches(i.selector))this.dragElem=t;else{if(t=t.closest(i.selector),!t)break;this.dragElem=t}}this.start.event=e,this.start.x=e.pageX,this.start.y=e.pageY,this.start.altKey=e.altKey,this.start.ctrlKey=e.ctrlKey,this.start.metaKey=e.metaKey,this.start.shiftKey=e.shiftKey;break;case"mousemove":if(!this.dragElem)break;if(!this.dragging){if(i.thresh){if(s.dx*s.dx+s.dy*s.dy<i.thresh*i.thresh)break}if(s.type="dragstart",!1===i.dragstart(s)){this.stopDrag(s);break}this.dragging=!0}this.dragging&&this.opts.drag&&(s.type="drag",this.opts.drag(s));break;case"mouseup":if(!this.dragging){this.stopDrag(s);break}0===e.button?s.apply=!0:s.apply=!1,this.stopDrag(s)}}} /*! * Wunderbaum - common * Copyright (c) 2021-2025, Martin Wendt. Released under the MIT license. * v0.13.0, Sat, 08 Mar 2025 14:16:31 GMT (https://github.com/mar10/wunderbaum) */const ie=new RegExp(/\.|\//),se={bootstrap:{error:"bi bi-exclamation-triangle",loading:"bi bi-chevron-right wb-busy",noData:"bi bi-question-circle",expanderExpanded:"bi bi-chevron-down",expanderCollapsed:"bi bi-chevron-right",expanderLazy:"bi bi-chevron-right wb-helper-lazy-expander",checkChecked:"bi bi-check-square",checkUnchecked:"bi bi-square",checkUnknown:"bi bi-dash-square-dotted",radioChecked:"bi bi-circle-fill",radioUnchecked:"bi bi-circle",radioUnknown:"bi bi-record-circle",folder:"bi bi-folder2",folderOpen:"bi bi-folder2-open",folderLazy:"bi bi-folder-symlink",doc:"bi bi-file-earmark",colSortable:"bi bi-chevron-expand",colSortAsc:"bi bi-arrow-down",colSortDesc:"bi bi-arrow-up",colFilter:"bi bi-filter-circle",colFilterActive:"bi bi-filter-circle-fill wb-helper-invalid",colMenu:"bi bi-three-dots-vertical"},fontawesome6:{error:"fa-solid fa-triangle-exclamation",loading:"fa-solid fa-chevron-right fa-beat",noData:"fa-solid fa-circle-question",expanderExpanded:"fa-solid fa-chevron-down",expanderCollapsed:"fa-solid fa-chevron-right",expanderLazy:"fa-solid fa-chevron-right wb-helper-lazy-expander",checkChecked:"fa-regular fa-square-check",checkUnchecked:"fa-regular fa-square",checkUnknown:"fa-regular fa-square-minus",radioChecked:"fa-solid fa-circle",radioUnchecked:"fa-regular fa-circle",radioUnknown:"fa-regular fa-circle-question",folder:"fa-solid fa-folder-closed",folderOpen:"fa-regular fa-folder-open",folderLazy:"fa-solid fa-folder-plus",doc:"fa-regular fa-file",colSortable:"fa-solid fa-fw fa-sort",colSortAsc:"fa-solid fa-fw fa-sort-up",colSortDesc:"fa-solid fa-fw fa-sort-down",colFilter:"fa-solid fa-fw fa-filter",colFilterActive:"fa-solid fa-fw fa-filter wb-helper-invalid",colMenu:"fa-solid fa-fw fa-ellipsis-v"}},ne=new Set(["_format","_keyMap","_positional","_typeList","_valueMap","_version","children","columns","types"]),oe={ArrowDown:"down",ArrowLeft:"left",ArrowRight:"right",ArrowUp:"up",Backspace:"parent",End:"lastCol",Home:"firstCol","Control+End":"last","Control+Home":"first","Meta+ArrowDown":"last","Meta+ArrowUp":"first",PageDown:"pageDown",PageUp:"pageUp"};function re(e){return e instanceof RegExp?function(t){return e.test(t.title)}:(f("string"==typeof e,`Expected a string or RegExp: ${e}`),function(t){return t.title===e})}function le(e,t){const i=e.title.toLowerCase(),s=t.title.toLowerCase();return i===s?0:i>s?1:-1}function ae(e){let{_format:t,_version:i=1,_keyMap:s,_valueMap:n}=e;f(1===i,`Expected file version 1 instead of ${i}`);let o=s,r={};if(o)for(const[e,t]of Object.entries(o))r[t]=e;if(o&&o.t){const e="source._keyMap maps from long to short since v0.7.0. Flip key/value!";console.warn(e),[o,r]=[r,o]}if(null!=e._typeList){const t='source._typeList is deprecated since v0.7.0: use source._valueMap: {"type": [...]} instead.';if(null!=n)throw new Error(t);console.warn(t),n={type:e._typeList},delete e._typeList}"flat"===t&&function(e){var t,i,s;const{_format:n,_keyMap:o={},_positional:r=[],children:l}=e,a=r.length;if("flat"!==n)throw new Error(`Expected source._format: "flat", but got ${n}`);if(a&&r.includes("children"))throw new Error(`source._positional must not include "children": ${r}`);let d=o;if(o.t){const e="source._keyMap maps from long to short since v0.7.0. Flip key/value!";console.warn(e),d={};for(const[e,t]of Object.entries(o))d[t]=e}const c=r.map((e=>{var t;return null!==(t=d[e])&&void 0!==t?t:e})),h=[],u={},p={},f=null!==(t=d.key)&&void 0!==t?t:"key",g=null!==(i=d.children)&&void 0!==i?i:"children";for(const[e,t]of l.entries()){let i;const[n,...o]=t;if(o.length===a)i={};else{if(o.length!==a+1)throw new Error(`unflattenSource: unexpected tuple length: ${t}`);if(i=o.pop(),"object"!=typeof i)throw new Error(`unflattenSource: Expected dict as last tuple element: ${t}`)}t[1]=null,null!=t[2]&&(t[2]=null),o.forEach(((e,t)=>{i[c[t]]=e})),o.length=0,p[e]=i;const r=i[f];null!=r&&(u[r]=i);let l=null;if(null===n);else if("number"==typeof n){if(l=p[n],void 0===l)throw new Error(`unflattenSource: Could not find parent node by index: ${n}.`)}else if(l=u[n],void 0===l)throw new Error(`unflattenSource: Could not find parent node by key: ${n}`);l?(null!==(s=l[g])&&void 0!==s||(l[g]=[]),l[g].push(i)):h.push(i)}e.children=h}(e),delete e._format,delete e._version,delete e._keyMap,delete e._valueMap,delete e._positional,(s||n)&&function e(t){for(const i of t)Object.getOwnPropertyNames(i).forEach((e=>{const t=i[e];let o=e;if(s&&null!=r[e]&&(o=r[e],o!==e&&(i[o]=t,delete i[e])),n&&"number"==typeof t&&null!=n[o]){const e=n[o][t];if(null==e)throw new Error(`Expected valueMap[${o}][${t}] entry in [${n[o]}]`);i[o]=e}})),i.children&&e(i.children)}(e.children)} /*! * Wunderbaum - ext-grid * Copyright (c) 2021-2025, Martin Wendt. Released under the MIT license. * v0.13.0, Sat, 08 Mar 2025 14:16:31 GMT (https://github.com/mar10/wunderbaum) */class de extends H{constructor(e){super(e,"grid",{}),this.observer=new te({root:window.document,selector:"span.wb-col-resizer-active",thresh:4,dragstart:t=>{const i=ve.getEventInfo(t.startEvent),s=i.colDef,n=s&&this.tree.element.contains(t.dragElem)&&P(s.resizable,e.options.columnsResizable,!1);if(this.tree.element.classList.toggle("wb-col-resizing",!!n),i.colElem.classList.toggle("wb-col-resizing",!!n),n){t.customData.colDef=s,t.customData.orgCustomWidthPx=s.customWidthPx;const e=Number.parseInt(i.colElem.style.width,10);t.customData.orgWidthPx=e,s.customWidthPx=e,this.tree.update(z.colStructure)}return n},drag:e=>this.handleDrag(e),dragstop:e=>this.handleDrag(e)})}init(){super.init()}handleDrag(e){const t=e.customData,i=t.colDef;if("dragstop"===e.type||"drag"===e.type){if(this.tree.element.classList.remove("wb-col-resizing"),e.apply||"drag"===e.type){const s=A(i.minWidth,4),n=Math.max(s,t.orgWidthPx+e.dx);i.customWidthPx=n}else this.tree.log("Column resize cancelled",e),i.customWidthPx=t.orgCustomWidthPx;this.tree.update(z.colStructure)}}} /*! * Wunderbaum - deferred * Copyright (c) 2021-2025, Martin Wendt. Released under the MIT license. * v0.13.0, Sat, 08 Mar 2025 14:16:31 GMT (https://github.com/mar10/wunderbaum) */class ce{constructor(){this._promise=new Promise(((e,t)=>{this._resolve=e,this._reject=t}))}resolve(e){this._resolve(e)}reject(e){this._reject(e)}promise(){return this._promise}then(e){return this._promise.then(e)}catch(e){return this._promise.catch(e)}finally(e){return this._promise.finally(e)}} /*! * Wunderbaum - wunderbaum_node * Copyright (c) 2021-2025, Martin Wendt. Released under the MIT license. * v0.13.0, Sat, 08 Mar 2025 14:16:31 GMT (https://github.com/mar10/wunderbaum) */const he=new Set(["checkbox","classes","expanded","icon","iconTooltip","key","lazy","_partsel","radiogroup","refKey","selected","statusNodeType","title","tooltip","type","unselectable"]),ue=new Set(he);ue.delete("_partsel"),ue.delete("unselectable");class pe{constructor(e,t,i){var s,n;this.refKey=void 0,this.children=null,this.classes=null,this.data={},this._isLoading=!1,this._requestId=0,this._errorInfo=null,this._partsel=!1,this._partload=!1,this.subMatchCount=0,this._rowIdx=0,this._rowElem=void 0,f(!t||t.tree===e,`Invalid parent: ${t}`),f(!i.children,"'children' not allowed here"),this.tree=e,this.parent=t,this.key=""+(null!==(s=i.key)&&void 0!==s?s:++pe.sequence),this.title=""+(null!==(n=i.title)&&void 0!==n?n:"<"+this.key+">"),this.expanded=!!i.expanded,this.lazy=!!i.lazy,null!=i.refKey&&(this.refKey=""+i.refKey),null!=i.type&&(this.type=""+i.type),null!=i.icon&&(this.icon=F(i.icon)),null!=i.tooltip&&(this.tooltip=F(i.tooltip)),null!=i.iconTooltip&&(this.iconTooltip=F(i.iconTooltip)),null!=i.statusNodeType&&(this.statusNodeType=""+i.statusNodeType),null!=i.colspan&&(this.colspan=!!i.colspan),null!=i.checkbox&&F(i.checkbox),null!=i.radiogroup&&(this.radiogroup=!!i.radiogroup),null!=i.selected&&(this.selected=!!i.selected),null!=i.unselectable&&(this.unselectable=!!i.unselectable),i.classes&&this.setClass(i.classes);for(const[e,t]of Object.entries(i))he.has(e)||(this.data[e]=t);t&&!this.statusNodeType&&e._registerNode(this)}toString(){return`WunderbaumNode@${this.key}<'${this.title}'>`}*[Symbol.iterator](){const e=this.children;if(e)for(let t=0,i=e.length;t<i;t++){const i=e[t];yield i,i.children&&(yield*i)}}_callEvent(e,t){var i;return null===(i=this.tree)||void 0===i?void 0:i._callEvent(e,N({node:this,typeInfo:this.type?this.tree.types[this.type]:{}},t))}addChildren(e,t){const i=this.tree;let{before:s=null,applyMinExpanLevel:n=!0,_level:o}=null!=t?t:{};null!=o||(o=this.getLevel());const r=[];try{i.enableUpdate(!1),I(e)&&(e=[e]);const t=n&&o<i.options.minExpandLevel;for(const s of e){const e=s.children;delete s.children;const n=new pe(i,this,s);t&&!n.isUnloaded()&&(n.expanded=!0),r.push(n),e&&n.addChildren(e,{_level:o+1})}if(this.children)if(null==s||0===this.children.length)this.children=this.children.concat(r);else{s=this.findDirectChild(s);const e=this.children.indexOf(s);f(e>=0,`options.before must be a direct child of ${this}`),this.children.splice(e,0,...r)}else this.children=r;i.update(z.structure)}finally{i.enableUpdate(!0)}return r[0]}addNode(e,t="appendChild"){switch("over"===t&&(t="appendChild"),t){case"after":return this.parent.addChildren(e,{before:this.getNextSibling()});case"before":return this.parent.addChildren(e,{before:this});case"prependChild":return this.addChildren(e,{before:0});case"appendChild":return this.addChildren(e)}f(!1,`Invalid mode: ${t}`)}applyCommand(e,t){return this.tree.applyCommand(e,this,t)}collapseSiblings(e){for(const t of this.parent.children)t!==this&&t.expanded&&t.setExpanded(!1,e)}setClass(e,t=!0){const i=O(e);if(t)null===this.classes&&(this.classes=new Set),i.forEach((e=>{var i;this.classes.add(e),null===(i=this._rowElem)||void 0===i||i.classList.toggle(e,t)}));else{if(null===this.classes)return;i.forEach((e=>{var i;this.classes.delete(e),null===(i=this._rowElem)||void 0===i||i.classList.toggle(e,t)})),0===this.classes.size&&(this.classes=null)}}startEditTitle(){this.tree._callMethod("edit.startEditTitle",this)}async expandAll(e=!0,t){const i=this.tree,{collapseOthers:s,deep:n,depth:o,force:r,keepActiveNodeVisible:l=!0,loadLazy:a,resetLazy:d}=null!=t?t:{},c=this.tree.options.minExpandLevel||null,h=null!=o?o:r?null:c,u={deep:n,force:r,loadLazy:a,resetLazy:d,scrollIntoView:!1};this.logInfo(`expandAll(${e}, depth=${o}, minLevel=${h})`),f(!(e&&null!=n&&!s),"Expanding with `deep` option is not supported (implied by the `depth` option).");const p=i.logTime(`${this}.expandAll(${e}, depth=${o})`);try{i.enableUpdate(!1),await async function t(i,s){var r;const l=[];return null===(r=i.children)||void 0===r||r.forEach((i=>{if(e)if(!i.expanded&&(null==h||s<h)&&(i.children||a&&i.lazy)){const e=i.setExpanded(!0,u);l.push(e),null==o&&e.then((async()=>{await t(i,s+1)}))}else l.push(t(i,s+1));else(null==h||s>=h)&&i.setExpanded(!1,u),(null!=h&&s<h||n)&&t(i,s+1)})),new Promise((e=>{Promise.all(l).then((()=>{e(!0)}))}))}(this,0),s&&(f(e,"Option `collapseOthers` requires flag=true"),f(null!=h,"Option `collapseOthers` requires `depth` or `minExpandLevel`"),this.expandAll(!1,{depth:h}))}finally{i.enableUpdate(!0),i.logTimeEnd(p)}i.activeNode&&l&&i.activeNode.scrollIntoView()}findAll(e){const t="function"==typeof e?e:re(e),i=[];return this.visit((e=>{t(e)&&i.push(e)})),i}findDirectChild(e){const t=this.children;if(!t)return null;if("string"==typeof e){for(let i=0,s=t.length;i<s;i++)if(t[i].key===e)return t[i]}else{if("number"==typeof e)return t[e];if(e.parent===this)return e}return null}findFirst(e){const t="function"==typeof e?e:re(e);let i=null;return this.visit((e=>{if(t(e))return i=e,!1})),i}findRelatedNode(e,t=!1){return this.tree.findRelatedNode(this,e,t)}*format_iter(e,t){function i(e){const t=e.parent.children;return e===t[t.length-1]}null!=t||(t=[" "," | "," ╰─ "," ├─ "]),null!=e||(e=e=>""+e);const s=s=>{const n=[e(s)];n.unshift(t[i(s)?2:3]);let o=s.parent;for(;o&&o!==this;)n.unshift(t[i(o)?0:1]),o=o.parent;return n.join("")};yield e(this);for(const e of this)yield s(e)}format(e,t){const i=[];for(const s of this.format_iter(e,t))i.push(s);return i.join("\n")}getColElem(e){var t;"string"==typeof e&&(e=this.tree.columns.findIndex((t=>t.id===e)));const i=null===(t=this._rowElem)||void 0===t?void 0:t.querySelectorAll("span.wb-col");return i?i[e]:null}getCloneList(e=!1){if(!this.refKey)return[];const t=this.tree.findByRefKey(this.refKey);return e?t:[...t].filter((e=>e!==this))}getFirstChild(){return this.children?this.children[0]:null}getLastChild(){return this.children?this.children[this.children.length-1]:null}getLevel(){let e=0,t=this.parent;for(;t;)e++,t=t.parent;return e}getNextSibling(){const e=this.parent.children,t=e.indexOf(this);return e[t+1]||null}getParent(){return this.parent}getParentList(e=!1,t=!1){const i=[];let s=t?this:this.parent;for(;s;)(e||s.parent)&&i.unshift(s),s=s.parent;return i}getPath(e=!0,t="title",i="/"){let s;const n=[],o="function"==typeof t;return this.visitParents((e=>{e.parent&&(s=o?t(e):e[t],n.unshift(s))}),e),n.join(i)}getPrevSibling(){const e=this.parent.children,t=e.indexOf(this);return e[t-1]||null}hasChildren(){if(this.lazy){if(null==this.children)return;if(0===this.children.length)return!1;if(1===this.children.length&&this.children[0].isStatusNode())return;return!0}return!(!this.children||!this.children.length)}hasClass(e){return!!this.classes&&this.classes.has(e)}hasFocus(){return this.tree.focusNode===this}isActive(){return this.tree.activeNode===this}isAncestorOf(e){return e&&e.isDescendantOf(this)}isChildOf(e){return e&&this.parent===e}isClone(){return!!this.refKey&&this.tree.findByRefKey(this.refKey).length>1}isColspan(){return!!this.getOption("colspan")}isDescendantOf(e){if(!e||e.tree!==this.tree)return!1;let t=this.parent;for(;t;){if(t===e)return!0;t===t.parent&&v(`Recursive parent link: ${t}`),t=t.parent}return!1}isExpandable(e=!1){return!(e&&this.expanded||!1===this.children)&&(null==this.children?!!this.lazy:0!==this.children.length||!!this.tree.options.emptyChildListExpandable)}isEditingTitle(){return this.tree._callMethod("edit.isEditingTitle",this)}isExpanded(){return!!this.expanded}isFirstSibling(){const e=this.parent;return!e||e.children[0]===this}isLastSibling(){const e=this.parent;return!e||e.children[e.children.length-1]===this}isLazy(){return!!this.lazy}isLoaded(){return!this.lazy||void 0!==this.hasChildren()}isLoading(){return this._isLoading}isPagingNode(){return"paging"===this.statusNodeType}isParentOf(e){return e&&e.parent===this}isPartload(){return!!this._partload}isPartsel(){return!this.selected&&!!this._partsel}isRadio(){return!!this.parent.radiogroup||"radio"===this.getOption("checkbox")}isRendered(){return!!this._rowElem}isRootNode(){return this.tree.root===this}isSelected(){return!!this.selected||!!this._partsel&&void 0}isStatusNode(){return!!this.statusNodeType}isTopLevel(){return this.tree.root===this.parent}isUnloaded(){return void 0===this.hasChildren()}isVisible(){const e="hide"===this.tree.filterMode,t=this.getParentList(!1,!1);if(e&&!this.match&&!this.subMatchCount)return!1;for(let e=0,i=t.length;e<i;e++){if(!t[e].expanded)return!1}return!0}_loadSourceObject(e,t){var i;const s=this.tree;null!=t||(t=this.getLevel());const n=this._callEvent("receive",{response:e});null!=n&&(e=n),S(e)&&(e={children:e}),f(I(e),`Expected an array or plain object: ${e}`);const o=null!==(i=e.format)&&void 0!==i?i:"nested";f("nested"===o||"flat"===o,`Expected source.format = 'nested' or 'flat': ${o}`),ae(e),f(e.children,"If `source` is an object, it must have a `children` property"),e.types&&(s.logInfo("Redefine types",e.columns),s.setTypes(e.types,!1),delete e.types),e.columns&&(s.logInfo("Redefine columns",e.columns),s.columns=e.columns,delete e.columns,s.update(z.colStructure)),this.addChildren(e.children);for(const[t,i]of Object.entries(e))ne.has(t)||(s.data[t]=i);"hier"===s.options.selectMode&&this.fixSelection3FromEndNodes(),this.resetNativeChildOrder(),this._callEvent("load")}async _fetchWithOptions(e){var t,i;let s,n,o,r,l,a={};"string"==typeof e?(s=e,a.method="GET"):I(e)?(({url:s,params:n,body:o,options:r,...l}=e),f(!l||0===Object.keys(l).length,`Unexpected source properties: ${Object.keys(l)}. Use 'options' instead.`),f("string"==typeof s,"expected source.url as string"),I(r)&&(a=r),I(o)&&(f(!a.body,"options.body should be passed as source.body"),a.body=JSON.stringify(a.body),null!==(t=a.method)&&void 0!==t||(a.method="POST")),I(n)&&(s+="?"+new URLSearchParams(n),null!==(i=a.method)&&void 0!==i||(a.method="GET"))):(s="",v(`Unsupported source format: ${e}`)),this.setStatus(U.loading);const d=await fetch(s,a);return d.ok||v(`GET ${s} returned ${d.status}, ${d}`),await d.json()}async load(e){const t=this.tree,i=Date.now(),s=this.parent,n=Date.now();let o=0,r=0,l=0;this._requestId&&this.logWarn(`Recursive load request #${i} while #${this._requestId} is pending. The previous request will be ignored.`),this._requestId=i;try{if("string"==typeof e?e:e.url){const t=await this._fetchWithOptions(e);if(r=Date.now()-n,this._requestId&&this._requestId>i)return void this.logWarn(`Ignored load response #${i} because #${this._requestId} is pending.`);if(this.logDebug(`Received response for load request #${i}`),null===this.parent&&null!==s)return void this.logWarn("Lazy parent node was removed while loading: discarding response.");this.setStatus(U.ok);const o=Date.now();this._loadSourceObject(t),l=Date.now()-o}else{if("function"==typeof e.then){const i=t.logTime(`Resolve thenable ${e}`);e=await Promise.resolve(e),t.logTimeEnd(i)}this._loadSourceObject(e),l=Date.now()-n}}catch(t){throw this.logError("Error during load()",e,t),this._callEvent("error",{error:t}),this.setStatus(U.error,{message:""+t}),t}finally{this._requestId=0,o=Date.now()-n,t.options.debugLevel>=3&&t.logInfo(`Load source took ${o/1e3} seconds (transfer: ${r/1e3}s, processing: ${l/1e3}s)`)}}async loadLazy(e=!1){const t=this.expanded;if(f(this.lazy,"load() requires a lazy node"),e||this.isUnloaded())if(this.isLoading())this.logWarn("loadLazy() called while already loading: ignored.");else{this.isLoaded()&&this.resetLazy(),this.setStatus(U.loading);try{const e=await this._callEvent("lazyLoad");if(!1===e)return void this.setStatus(U.ok);f(S(e)||e&&e.url,"The lazyLoad event must return a node list, `{url: ...}`, or false."),await this.load(e),this.setStatus(U.ok),t?(this.expanded=!0,this.tree.update(z.structure)):this.update()}catch(e){this.logError("Error during loadLazy()",e),this._callEvent("error",{error:e}),this.setStatus(U.error,{message:""+e})}}}log(...e){this.tree.options.debugLevel>=4&&console.log(this.toString(),...e)}logDebug(...e){this.tree.options.debugLevel>=4&&console.debug(this.toString(),...e)}logError(...e){this.tree.options.debugLevel>=1&&console.error(this.toString(),...e)}logInfo(...e){this.tree.options.debugLevel>=3&&console.info(this.toString(),...e)}logWarn(...e){this.tree.options.debugLevel>=2&&console.warn(this.toString(),...e)}async makeVisible(e){let t;const i=new ce,s=[],n=this.getParentList(!1,!1),o=n.length,r=T(e,"noAnimation",!1),l=T(e,"scrollIntoView",!0);for(t=o-1;t>=0;t--){const e={noAnimation:r};s.push(n[t].setExpanded(!0,e))}return Promise.all(s).then((()=>{l&&this.tree?(this.tree.updatePendingModifications(),this.scrollIntoView().then((()=>{i.resolve()}))):i.resolve()})),i.promise()}moveTo(e,t="appendChild",i){let s;"over"===t&&(t="appendChild"),"prependChild"===t&&(e.children&&e.children.length?(t="before",e=e