/* Inspire Tree
 * @version 7.1.0
 * https://github.com/helion3/inspire-tree
 * @copyright Copyright 2015 Helion3, and other contributors
 * @license Licensed under MIT
 *          see https://github.com/helion3/inspire-tree/blob/master/LICENSE
 */
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("lodash/map.js"),require("lodash/castArray.js"),require("lodash/defaultsDeep.js"),require("lodash/difference.js"),require("lodash/each.js"),require("lodash/get.js"),require("lodash/includes.js"),require("lodash/isArray.js"),require("lodash/isArrayLike.js"),require("lodash/isBoolean.js"),require("lodash/isEmpty.js"),require("lodash/isFunction.js"),require("lodash/isObject.js"),require("lodash/isRegExp.js"),require("lodash/isString.js"),require("lodash/noop.js"),require("lodash/tail.js"),require("lodash/sortBy.js"),require("lodash/assign.js"),require("lodash/cloneDeep.js"),require("lodash/find.js"),require("lodash/findIndex.js"),require("lodash/findLast.js"),require("lodash/indexOf.js"),require("lodash/pull.js"),require("lodash/slice.js"),require("lodash/invoke.js"),require("lodash/isArrayLikeObject.js"),require("lodash/remove.js"),require("lodash/sortedIndexBy.js")):"function"==typeof define&&define.amd?define(["lodash/map.js","lodash/castArray.js","lodash/defaultsDeep.js","lodash/difference.js","lodash/each.js","lodash/get.js","lodash/includes.js","lodash/isArray.js","lodash/isArrayLike.js","lodash/isBoolean.js","lodash/isEmpty.js","lodash/isFunction.js","lodash/isObject.js","lodash/isRegExp.js","lodash/isString.js","lodash/noop.js","lodash/tail.js","lodash/sortBy.js","lodash/assign.js","lodash/cloneDeep.js","lodash/find.js","lodash/findIndex.js","lodash/findLast.js","lodash/indexOf.js","lodash/pull.js","lodash/slice.js","lodash/invoke.js","lodash/isArrayLikeObject.js","lodash/remove.js","lodash/sortedIndexBy.js"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).InspireTree=t(e._.map,e._.castArray,e._.defaultsDeep,e._.difference,e._.each,e._.get,e._.includes,e._.isArray,e._.isArrayLike,e._.isBoolean,e._.isEmpty,e._.isFunction,e._.isObject,e._.isRegExp,e._.isString,e._.noop,e._.tail,e._.sortBy,e._.assign,e._.cloneDeep,e._.find,e._.findIndex,e._.findLast,e._.indexOf,e._.pull,e._.slice,e._.invoke,e._.isArrayLikeObject,e._.remove,e._.sortedIndexBy)}(this,function(q,a,l,I,u,c,h,d,f,i,U,v,p,B,y,M,r,o,m,k,s,_,g,V,F,b,n,H,z,W){"use strict";function w(e,t,n){t=D(t);var i=e,t=Q()?Reflect.construct(t,n||[],D(e).constructor):t.apply(e,n);if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");e=i;if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function x(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function K(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,function(e){e=function(e,t){if("object"!=typeof e||!e)return e;var n=e[Symbol.toPrimitive];if(void 0===n)return("string"===t?String:Number)(e);n=n.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}(e,"string");return"symbol"==typeof e?e:e+""}(i.key),i)}}function e(e,t,n){return t&&K(e.prototype,t),n&&K(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function G(){return(G="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,n){var i=function(e,t){for(;!{}.hasOwnProperty.call(e,t)&&null!==(e=D(e)););return e}(e,t);if(i)return(i=Object.getOwnPropertyDescriptor(i,t)).get?i.get.call(arguments.length<3?e:n):i.value}).apply(null,arguments)}function D(e){return(D=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function J(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&X(e,t)}function Q(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(Q=function(){return!!e})()}function X(e,t){return(X=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e})(e,t)}function t(e,t,n,i){var r=G(D(1&i?e.prototype:e),t,n);return 2&i&&"function"==typeof r?function(e){return r.apply(n,e)}:r}function j(t,n,i,e,r){var s;return e.state(t)!==n&&(e.context().batch(),e._tree.config.nodes.resetStateOnRestore&&"restored"===i&&u((s=e)._tree.defaultState,function(e,t){s.state(t,e)}),n&&"checked"===t&&e.state("indeterminate",!1),e.state(t,n),e._tree.emit("node."+i,e,!1),r&&e.hasChildren()&&e.children.recurseDown(function(e){j(t,n,i,e)}),"hidden"!==t&&"removed"!==t||(e.context().indicesDirty=!0,e.context().calculateRenderablePositions()),e.markDirty(),e.context().end()),e}function Y(e){function t(){e.apply(this,arguments)}return t.prototype=Object.create(e.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e,t}function Z(e,n,i,t){return n=a(n),e._tree.batch(),e[t?"recurseDown":"each"](function(t){u(n,function(e){v(t[e])&&t[e].apply(t,i)})}),e._tree.end(),e}function L(t){var e=t;return e=y(t)?function(e){return v(e[t])?e[t]():e[t]}:e}function P(t,e){var n;return e?this.extract(t):(n=L(t),this.flatten(function(e){return("removed"===t||!e.removed())&&n(e)}))}var E=function(){function s(e,t,n){var i;if(x(this,s),i=w(this,s),v(c(e,"isTree"))&&!e.isTree(e))throw new TypeError("Invalid tree instance.");return Object.defineProperty(i,"_tree",{value:e,writable:!0}),i.length=0,i.batching=0,i.indicesDirty=!1,i.config=l({},n,{calculateRenderablePositions:!1}),i._pagination={limit:e.config.pagination.limit,total:0},(d(t)||t instanceof s)&&u(t,function(e){e instanceof N?i.push(e.clone()):i.addNode(e)}),i}return J(s,Y(Array)),e(s,[{key:"addNode",value:function(e){var t=this.length;return this._tree.config.sort&&(t=W(this,e,this._tree.config.sort)),this.insertAt(t,e)}},{key:"applyChanges",value:function(){0===this.batching&&(this.calculateRenderablePositions(),this._tree.emit("changes.applied",this.context()))}},{key:"batch",value:function(){this.batching<0&&(this.batching=0),this.batching++}},{key:"available",value:function(e){return P.call(this,"available",e)}},{key:"blur",value:function(){return this.invoke("blur")}},{key:"blurDeep",value:function(){return this.invokeDeep("blur")}},{key:"calculateRenderablePositions",value:function(){var t,n;!this.indicesDirty||0<this.batching||!this.config.calculateRenderablePositions||(this.each(function(e){e.renderable()&&(t=t||e,n=e)}),this.firstRenderableNode&&this.firstRenderableNode!==t&&this.firstRenderableNode.markDirty(),t&&t!==this.firstRenderableNode&&t.markDirty(),this.lastRenderableNode&&this.lastRenderableNode!==n&&this.lastRenderableNode.markDirty(),n&&n!==this.lastRenderableNode&&n.markDirty(),this.firstRenderableNode=t,this.lastRenderableNode=n,this.indicesDirty=!1)}},{key:"checked",value:function(e){return P.call(this,"checked",e)}},{key:"clean",value:function(){return this.invoke("clean")}},{key:"clone",value:function(){return new s(this._tree,this)}},{key:"collapse",value:function(){return this.invoke("collapse")}},{key:"collapsed",value:function(e){return P.call(this,"collapsed",e)}},{key:"collapseDeep",value:function(){return this.invokeDeep("collapse")}},{key:"concat",value:function(e){function t(e){e instanceof N&&n.push(e)}var n=new s(this._tree);n._context=this._context;return u(this,t),u(e,t),n._pagination.limit=this._pagination.limit,n}},{key:"context",value:function(){return this._context||this._tree}},{key:"copy",value:function(t,n,i){var r=new s(this._tree);return u(this,function(e){r.push(e.copy(t,n,i))}),r}},{key:"deepest",value:function(){var t=new s(this._tree);return this.recurseDown(function(e){e.children||t.push(e)}),t}},{key:"deselect",value:function(){return this.invoke("deselect")}},{key:"deselectDeep",value:function(){return this.invokeDeep("deselect")}},{key:"each",value:function(e){return u(this,e),this}},{key:"editable",value:function(e){return P.call(this,"editable",e)}},{key:"editing",value:function(e){return P.call(this,"editing",e)}},{key:"end",value:function(){this.batching--,0===this.batching&&this.applyChanges()}},{key:"expand",value:function(){return this.invoke("expand")}},{key:"expanded",value:function(e){return P.call(this,"expanded",e)}},{key:"expandDeep",value:function(){var i=this;return new Promise(function(e){function t(){0==--n&&e(i)}var n=0;i.recurseDown(function(e){n++,e.children?e.expand().catch(t).then(function(){e.children.expandDeep().catch(t).then(t)}):t()})})}},{key:"expandParents",value:function(){return this.invoke("expandParents")}},{key:"extract",value:function(e){var e=this.flatten(e),t=new s(this._tree);return u(e,function(e){return t.addNode(e.copyHierarchy())}),t}},{key:"filterBy",value:function(e){var t=L(e),n=new s(this._tree);return u(this,function(e){t(e)&&n.push(e)}),n}},{key:"find",value:function(t){var n;return this.recurseDown(function(e){if(t(e))return n=e,!1}),n}},{key:"first",value:function(e){for(var t=0,n=this.length;t<n;t++)if(e(this[t]))return this[t]}},{key:"flatten",value:function(e){var t=new s(this._tree),n=L(e);return this.recurseDown(function(e){n(e)&&t.push(e)}),t}},{key:"focused",value:function(e){return P.call(this,"focused",e)}},{key:"forEach",value:function(e){return this.each(e)}},{key:"get",value:function(e){return this[e]}},{key:"hidden",value:function(e){return P.call(this,"hidden",e)}},{key:"hide",value:function(){return this.invoke("hide")}},{key:"hideDeep",value:function(){return this.invokeDeep("hide")}},{key:"indeterminate",value:function(e){return P.call(this,"indeterminate",e)}},{key:"insertAt",value:function(e,t){if(t.id){var n=this.node(t.id);if(n)return n.restore().show(),f(t.children)?(f(n.children)||(n.children=new s(this._tree),n.children._context=n),u(t.children,function(e){n.children.addNode(e)})):t.children&&i(n.children)&&(n.children=t.children),n.markDirty(),this.applyChanges(),n}t=this._tree.constructor.isTreeNode(t)?t:A(this._tree,t);return this.splice(e,0,t),this._context&&(t.itree.parent=this._context,this._context.refreshIndeterminateState().markDirty()),this._tree.emit("node.added",t),t.markDirty(),this.length-1!==e&&this.invoke("markDirty"),this.applyChanges(),t}},{key:"invoke",value:function(e,t){return Z(this,e,t)}},{key:"invokeDeep",value:function(e,t){return Z(this,e,t=!H(t)||2<arguments.length?r(arguments):t,!0)}},{key:"last",value:function(e){for(var t=this.length-1;0<=t;t--)if(e(this[t]))return this[t]}},{key:"loading",value:function(e){return P.call(this,"loading",e)}},{key:"loadMore",value:function(e){var t=this;return this._loading?Promise.reject(new Error("Pending loadMore call must complete before being invoked again.")):this._pagination.limit===this._pagination.total?Promise.resolve():(this._loading=!0,this.batch(),n(this._context,"markDirty"),this._pagination.limit+=this._tree.config.pagination.limit,this._tree.emit("node.paginated",this._context||this._tree,this.pagination,e),e=this._tree.config.deferredLoading?this._context?this._context.loadChildren():this._tree.load(this._tree.config.data):(this._loading=!1,Promise.resolve()),this.end(),this._tree.config.deferredLoading&&e.then(function(){t._loading=!1,t.applyChanges()}).catch(function(){t._loading=!1,t.applyChanges()}),e)}},{key:"matched",value:function(e){return P.call(this,"matched",e)}},{key:"move",value:function(e,t){var n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:this,i=this[e].remove(),i=n.insertAt(t,i);return this._tree.emit("node.moved",i,this,e,n,t),i}},{key:"node",value:function(t){var n;return this.recurseDown(function(e){if(e.id===t)return n=e,!1}),n}},{key:"nodes",value:function(t){var n;return d(t)&&(n=new s(this._tree),this.recurseDown(function(e){-1<t.indexOf(e.id)&&n.push(e)})),d(t)?n:this}},{key:"pagination",value:function(){return this._pagination}},{key:"pop",value:function(){var e=t(s,"pop",this,3)([]);return this.indicesDirty=!0,this.calculateRenderablePositions(),e}},{key:"push",value:function(e){e=t(s,"push",this,3)([e]);return this.indicesDirty=!0,this.calculateRenderablePositions(),e}},{key:"recurseDown",value:function(e){return O(this,e),this}},{key:"remove",value:function(e){return z(this,{id:e.id}),n(this._context,"markDirty"),this.indicesDirty=!0,this.applyChanges(),this}},{key:"removed",value:function(e){return P.call(this,"removed",e)}},{key:"restore",value:function(){return this.invoke("restore")}},{key:"restoreDeep",value:function(){return this.invokeDeep("restore")}},{key:"select",value:function(){return this.invoke("select")}},{key:"selectable",value:function(e){return P.call(this,"selectable",e)}},{key:"selectDeep",value:function(){return this.invokeDeep("select")}},{key:"selected",value:function(e){return P.call(this,"selected",e)}},{key:"shift",value:function(e){e=t(s,"shift",this,3)([e]);return this.indicesDirty=!0,this.calculateRenderablePositions(),e}},{key:"show",value:function(){return this.invoke("show")}},{key:"showDeep",value:function(){return this.invokeDeep("show")}},{key:"softRemove",value:function(){return this.invoke("softRemove")}},{key:"sortBy",value:function(e){var t=this;return(e=e||this._tree.config.sort)&&(this.batch(),e=o(this,e),this.length=0,u(e,function(e){t.push(e)}),this.indicesDirty=!0,this.end()),this}},{key:"sortDeep",value:function(t){return this.sort(t),this.each(function(e){e.hasChildren()&&e.children.sortDeep(t)}),this}},{key:"splice",value:function(){var e=t(s,"splice",this,1).apply(this,arguments);return this.indicesDirty=!0,this.calculateRenderablePositions(),e}},{key:"state",value:function(){return this.invoke("state",arguments)}},{key:"stateDeep",value:function(){return this.invokeDeep("state",arguments)}},{key:"swap",value:function(e,t){this._tree.batch();var n=e.context(),i=t.context(),r=n.indexOf(e),s=i.indexOf(t);return n===i?(this[r]=t,this[s]=e,this._tree.emit("node.moved",e,n,r,i,s),this._tree.emit("node.moved",t,i,s,n,r)):(n.move(r,i.indexOf(t),i),i.move(i.indexOf(t),r,n)),this.indicesDirty=!0,this._tree.end(),this._tree.emit("node.swapped",e,n,r,t,i,s),this}},{key:"tree",value:function(){return this._tree}},{key:"toArray",value:function(){var t=[];return u(this,function(e){t.push(e.toObject())}),t}},{key:"unshift",value:function(e){e=t(s,"unshift",this,3)([e]);return this.indicesDirty=!0,this.calculateRenderablePositions(),e}},{key:"visible",value:function(e){return P.call(this,"visible",e)}}])}();function O(e,t){var n;return e instanceof E?u(e,function(e){return n=O(e,t)}):e instanceof N&&!1!==(n=t(e))&&e.hasChildren()&&(n=O(e.children,t)),n}function $(n){return new Promise(function(e,t){if(!p(n))return t(new Error("Invalid Promise"));v(n.then)&&n.then(e),v(n.error)?n.error(t):v(n.catch)&&n.catch(t)})}function ee(e,t,n){var i=e.itree.state[t];return void 0!==n&&i!==n&&(e.itree.state[t]=n,"rendered"!==t&&e.markDirty(),e._tree.emit("node.state.changed",e,t,i,n)),i}var N=function(){function n(e,t,s){var o=this;x(this,n),Object.defineProperty(this,"_tree",{value:e,writable:!0}),t instanceof n&&((s=a(s)).push("_tree"),u(t,function(e,t){var n,i,r;h(s,t)||(p(e)?e instanceof E?o[t]=e.clone():o[t]="itree"===t?(n=e,r={},(i=a(i)).push("ref"),u(n,function(e,t){h(i,t)||(r[t]=k(e))}),i.includes("parent")||Object.defineProperty(r,"parent",{value:n.parent,writable:!0}),r):k(e):o[t]=e)}))}return e(n,[{key:"addChild",value:function(e){return!d(this.children)&&f(this.children)||(this.children=new E(this._tree),this.children._context=this),this.children.addNode(e)}},{key:"addChildren",value:function(e){var t=this,n=new E(this._tree);return!d(this.children)&&f(this.children)||(this.children=new E(this._tree),this.children._context=this),this.children.batch(),u(e,function(e){n.push(t.addChild(e))}),this.children.end(),n}},{key:"allowDynamicLoad",value:function(){return this._tree.isDynamic&&(f(this.children)||!0===this.children)}},{key:"assign",value:function(){return m.apply(void 0,[this].concat(Array.prototype.slice.call(arguments))),this.markDirty(),this.context().applyChanges(),this}},{key:"available",value:function(){return!this.hidden()&&!this.removed()}},{key:"blur",value:function(){return this._tree.config.cancelEditOnBlur&&this.state("editing",!1),j("focused",!1,"blurred",this)}},{key:"check",value:function(e){return this._tree.batch(),j("checked",!0,"checked",this,!e&&this._tree.config.checkbox.autoCheckChildren),this.hasParent()&&this.getParent().refreshIndeterminateState(),this._tree.end(),this}},{key:"checked",value:function(){return this.state("checked")}},{key:"clean",value:function(){return this.recurseUp(function(e){e.hasParent()&&!(e=e.getParent()).hasVisibleChildren()&&e.hide()}),this}},{key:"clone",value:function(e){return new n(this._tree,this,e)}},{key:"collapse",value:function(){return j("collapsed",!0,"collapsed",this)}},{key:"collapsed",value:function(){return this.state("collapsed")}},{key:"context",value:function(){return this.hasParent()?this.getParent().children:this._tree.model}},{key:"copy",value:function(e,t,n){var i;if(e&&v(e.addNode))return i=this,t&&(i=i.copyHierarchy(!1,n)),e.addNode(k(i.toObject(!1,n)));throw new Error("Destination must be an Inspire Tree instance.")}},{key:"copyHierarchy",value:function(t,n){var i=[],e=this.getParents(),e=(u(e,function(e){i.push(e.toObject(t,n))}),i.reverse(),t||(e=this.toObject(!0,n),this.hasChildren()&&(e.children=this.children.filterBy(function(e){return!e.state("hidden")}).toArray(),e.children._context=e),i.push(e)),i[0]),r=i.length,s=e;return u(i,function(e,t){var n=[];t+1<r&&(n.push(i[t+1]),s.children=n,s=s.children[0])}),A(this._tree,e)}},{key:"deselect",value:function(e){return this.selected()&&(!this._tree.config.selection.require||1<this._tree.selected().length)&&(this.context().batch(),j("selected",!1,"deselected",this,!e&&this._tree.config.selection.autoSelectChildren),this._tree._lastSelectedNode===this&&(this._tree._lastSelectedNode=null),this.context().end()),this}},{key:"editable",value:function(){return this._tree.config.editable&&this._tree.config.editing.edit&&this.state("editable")}},{key:"editing",value:function(){return this.state("editing")}},{key:"expand",value:function(){var n=this;return new Promise(function(e,t){(n.hasChildren()||n._tree.isDynamic&&!0===n.children)&&(n.collapsed()||n.hidden())?(n.state("collapsed",!1),n.state("hidden",!1),n._tree.emit("node.expanded",n),n._tree.isDynamic&&!0===n.children?n.loadChildren().then(e).catch(t):(n.context().applyChanges(),e(n))):e(n)})}},{key:"expanded",value:function(){return!this.collapsed()}},{key:"expandParents",value:function(){return this.hasParent()&&this.getParent().recurseUp(function(e){e.expand()}),this}},{key:"focus",value:function(){return this.focused()||(this._tree.batch(),this._tree.blurDeep(),this.state("focused",!0),this._tree.emit("node.focused",this),this.markDirty(),this._tree.end()),this}},{key:"focused",value:function(){return this.state("focused")}},{key:"getChildren",value:function(){return this.hasChildren()?this.children:new E(this._tree)}},{key:"getParent",value:function(){return this.itree.parent}},{key:"getParents",value:function(){var t=new E(this._tree);return this.hasParent()&&this.getParent().recurseUp(function(e){t.push(e)}),t}},{key:"getTextualHierarchy",value:function(){var t=[];return this.recurseUp(function(e){t.unshift(e.text)}),t}},{key:"hasAncestor",value:function(t){var n=!1;return this.recurseUp(function(e){return!(n=e.id===t.id)}),n}},{key:"hasChildren",value:function(){return f(this.children)&&0<this.children.length}},{key:"hasLoadedChildren",value:function(){return f(this.children)}},{key:"hasOrWillHaveChildren",value:function(){return f(this.children)?Boolean(this.children.length):this.allowDynamicLoad()}},{key:"hasParent",value:function(){return Boolean(this.itree.parent)}},{key:"hasVisibleChildren",value:function(){var e=!1;return e=this.hasChildren()?0<this.children.filterBy("available").length:e}},{key:"hide",value:function(){var e=j("hidden",!0,"hidden",this);return e.hasChildren()&&e.children.hide(),e}},{key:"hidden",value:function(){return this.state("hidden")}},{key:"indexList",value:function(){var t=[];return this.recurseUp(function(e){t.push(V(e.context(),e))}),t.reverse()}},{key:"indexPath",value:function(){return this.indexList().join(".")}},{key:"indeterminate",value:function(){return this.state("indeterminate")}},{key:"isFirstRenderable",value:function(){return this===this.context().firstRenderableNode}},{key:"isLastRenderable",value:function(){return this===this.context().lastRenderableNode}},{key:"isOnlyRenderable",value:function(){return this.isFirstRenderable()&&this.isLastRenderable()}},{key:"lastDeepestVisibleChild",value:function(){var e,t;return e=this.hasChildren()&&!this.collapsed()&&(t=(e=g(this.children,function(e){return e.visible()})).lastDeepestVisibleChild())?t:e}},{key:"loadChildren",value:function(){var s=this;return new Promise(function(i,r){if(!s.allowDynamicLoad())return r(new Error("Node does not have or support dynamic children."));s.state("loading",!0),s.markDirty(),s.context().applyChanges();function e(e,t){if(!f(e))return r(new TypeError("Loader requires an array-like `nodes` parameter."));s.context().batch(),s.state("loading",!1);var n=R(s._tree,e,s);f(s.children)?s.children=s.children.concat(n):s.children=n,parseInt(t,10)>e.length&&(s.children._pagination.total=parseInt(t,10)),"checkbox"===s._tree.config.selection.mode&&s.selected()&&s.children.select(),s.markDirty(),s.context().end(),i(s.children),s._tree.emit("children.loaded",s)}function t(e){s.state("loading",!1),s.children=new E(s._tree),(s.children._context=s).markDirty(),s.context().applyChanges(),r(e),s._tree.emit("tree.loaderror",e)}var n=s._tree.constructor.isTreeNodes(s.children)?s.children.pagination():null,n=s._tree.config.data(s,e,t,n);p(n)&&$(n).then(e).catch(t)})}},{key:"loading",value:function(){return this.state("loading")}},{key:"loadMore",value:function(){return this.children&&!0!==this.children?this.children.loadMore():Promise.reject(new Error("Children have not yet been loaded."))}},{key:"markDirty",value:function(){return this.itree.dirty||(this.itree.dirty=!0,this.hasParent()&&this.getParent().markDirty()),this}},{key:"matched",value:function(){return this.state("matched")}},{key:"nextVisibleAncestralSiblingNode",value:function(){var e,t;return t=this.hasParent()?(t=(e=this.getParent()).nextVisibleSiblingNode())||e.nextVisibleAncestralSiblingNode():t}},{key:"nextVisibleChildNode",value:function(){var e;return e=this.hasChildren()?s(this.children,function(e){return e.visible()}):e}},{key:"nextVisibleNode",value:function(){var e=this.nextVisibleChildNode();return e=(e=e||this.nextVisibleSiblingNode())||this.nextVisibleAncestralSiblingNode()}},{key:"nextVisibleSiblingNode",value:function(){var e=this.hasParent()?this.getParent().children:this._tree.nodes(),t=_(e,{id:this.id});return s(b(e,t+1),function(e){return e.visible()})}},{key:"pagination",value:function(){return c(this,"children._pagination")}},{key:"previousVisibleNode",value:function(){var e=this.previousVisibleSiblingNode();return e=!(e=e&&e.hasChildren()&&!e.collapsed()?e.lastDeepestVisibleChild():e)&&this.hasParent()?this.getParent():e}},{key:"previousVisibleSiblingNode",value:function(){var e=this.hasParent()?this.getParent().children:this._tree.nodes(),t=_(e,{id:this.id});return g(b(e,0,t),function(e){return e.visible()})}},{key:"recurseDown",value:function(e){return O(this,e),this}},{key:"recurseUp",value:function(e){return!1!==e(this)&&this.hasParent()&&this.getParent().recurseUp(e),this}},{key:"refreshIndeterminateState",value:function(){var e,t,n,i=this.indeterminate();return this.state("indeterminate",!1),this.hasChildren()&&(e=this.children.length,n=t=0,this.children.each(function(e){e.checked()&&n++,e.indeterminate()&&t++}),n===e?j("checked",!0,"checked",this):j("checked",!1,"unchecked",this),this.checked()||this.state("indeterminate",0<t||0<e&&0<n&&n<e)),this.hasParent()&&this.getParent().refreshIndeterminateState(),i!==this.state("indeterminate")&&this.markDirty(),this}},{key:"reload",value:function(){var n=this;return new Promise(function(e,t){if(!n.allowDynamicLoad())return t(new Error("Node or tree does not support dynamic children."));n.children=!0,n.collapse(),n.loadChildren().then(e).catch(t)})}},{key:"remove",value:function(){var e=0<arguments.length&&void 0!==arguments[0]&&arguments[0],t=this.getParent();this.context().remove(this),t&&(t.refreshIndeterminateState(),t.markDirty()),this.tree().config.selection.autoSelectOnNodeRemoval&&this.selected()&&this.tree().autoSelectNode();(t||this._tree).pagination().total--;e=this.toObject(!1,e);return this._tree.emit("node.removed",e,t),this.context().applyChanges(),e}},{key:"removed",value:function(){return this.state("removed")}},{key:"renderable",value:function(){return!this.hidden()&&!this.removed()}},{key:"rendered",value:function(){return this.state("rendered")}},{key:"restore",value:function(){return j("removed",!1,"restored",this)}},{key:"select",value:function(e){var t;return!this.selected()&&this.selectable()&&(this._tree.batch(),this._tree.cacheSelectedNodes(),this._tree.canAutoDeselect()&&(t=this._tree.config.selection.require,this._tree.config.selection.require=!1,this._tree.deselectDeep(),this._tree.config.selection.require=t),j("selected",!0,"selected",this,!e&&this._tree.config.selection.autoSelectChildren),(this._tree._lastSelectedNode=this).markDirty(),this._tree.end()),this}},{key:"selectable",value:function(){var e=this._tree.config.selection.allow(this);return"boolean"==typeof e?e:this.state("selectable")}},{key:"selected",value:function(){return this.state("selected")}},{key:"set",value:function(e,t){return this[e]=t,this.markDirty(),this.context().applyChanges(),this}},{key:"show",value:function(){return j("hidden",!1,"shown",this)}},{key:"softRemove",value:function(){return j("removed",!0,"softremoved",this,"softRemove")}},{key:"state",value:function(e,t){var n=this;if(y(e))return ee(this,e,t);this.context().batch();var i={};return u(e,function(e,t){i[t]=ee(n,t,e)}),this.context().end(),i}},{key:"states",value:function(e,t){var n=this,i=[];return this.context().batch(),u(e,function(e){i.push(n.state(e,t))}),this.context().end(),i}},{key:"swap",value:function(e){return this.context().swap(this,e),this}},{key:"toggleCheck",value:function(){return this.checked()?this.uncheck():this.check()}},{key:"toggleCollapse",value:function(){return this.collapsed()?this.expand():this.collapse()}},{key:"toggleEditing",value:function(){return this.state("editing",!this.state("editing")),this.markDirty(),this.context().applyChanges(),this}},{key:"toggleSelect",value:function(){return this.selected()?this.deselect():this.select()}},{key:"toObject",value:function(){var t=this,e=0<arguments.length&&void 0!==arguments[0]&&arguments[0],n=1<arguments.length&&void 0!==arguments[1]&&arguments[1],i={},r=F(Object.keys(this),"_tree","children","itree"),r=(u(r,function(e){i[e]=t[e]}),i.itree={});return r.a=this.itree.a,r.icon=this.itree.icon,r.li=this.itree.li,n&&(r.state=this.itree.state),!e&&this.hasChildren()&&v(this.children.toArray)&&(i.children=this.children.toArray()),i}},{key:"toString",value:function(){return this.text}},{key:"tree",value:function(){return this._tree}},{key:"uncheck",value:function(e){return this._tree.batch(),j("checked",!1,"unchecked",this,!e&&this._tree.config.checkbox.autoCheckChildren),this.state("indeterminate",!1),this.hasParent()&&this.getParent().refreshIndeterminateState(),this._tree.end(),this}},{key:"unshiftChild",value:function(e){return!d(this.children)&&f(this.children)||(this.children=new E(this._tree),this.children._context=this),this.children.insertAt(0,e)}},{key:"visible",value:function(){return!(this.hidden()||this.removed()||this._tree.usesNativeDOM&&!this.rendered())&&(!this.hasParent()||!this.getParent().collapsed()&&this.getParent().visible())}}])}();let C;const te=new Uint8Array(16);const S=[];for(let e=0;e<256;++e)S.push((e+256).toString(16).slice(1));var ne={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function ie(e,t,n){if(ne.randomUUID&&!t&&!e)return ne.randomUUID();var i,r=(e=e||{}).random||(e.rng||function(){if(C=C||"undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto))return C(te);throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported")})();if(r[6]=15&r[6]|64,r[8]=63&r[8]|128,t){n=n||0;for(let e=0;e<16;++e)t[n+e]=r[e];return t}return e=r,i=0,S[e[i+0]]+S[e[i+1]]+S[e[i+2]]+S[e[i+3]]+"-"+S[e[i+4]]+S[e[i+5]]+"-"+S[e[i+6]]+S[e[i+7]]+"-"+S[e[i+8]]+S[e[i+9]]+"-"+S[e[i+10]]+S[e[i+11]]+S[e[i+12]]+S[e[i+13]]+S[e[i+14]]+S[e[i+15]]}function A(t,n,e){n.id=n.id||ie(),"string"!=typeof n.id&&"number"!=typeof n.id&&(n.id=n.id.toString());var i=n.itree=n.itree||{},r=(i.icon=i.icon||!1,i.dirty=!1,i.li=i.li||{}),r=(r.attributes=r.attributes||{},i.a=i.a||{}),s=(r.attributes=r.attributes||{},i.state=i.state||{});return s.collapsed=("boolean"==typeof s.collapsed?s:t.defaultState).collapsed,s.selectable=("boolean"==typeof s.selectable?s:t.defaultState).selectable,s.draggable=("boolean"==typeof s.draggable?s:t.defaultState).draggable,s["drop-target"]=("boolean"==typeof s["drop-target"]?s:t.defaultState)["drop-target"],s.checked="boolean"==typeof s.checked&&s.checked,s.editable=("boolean"==typeof s.editable?s:t.defaultState).editable,s.editing=("boolean"==typeof s.editing?s:t.defaultState).editing,s.focused=s.focused||t.defaultState.focused,s.hidden=s.hidden||t.defaultState.hidden,s.indeterminate=s.indeterminate||t.defaultState.indeterminate,s.loading=s.loading||t.defaultState.loading,s.removed=s.removed||t.defaultState.removed,s.rendered=s.rendered||t.defaultState.rendered,s.selected=s.selected||t.defaultState.selected,Object.defineProperty(n.itree,"parent",{value:e,writable:!0}),n=m(new N(t),n),f(n.children)&&(n.children=R(t,n.children,n)),t.allowsLoadEvents&&u(t.config.allowLoadEvents,function(e){s[e]&&t.emit("node."+e,n,!0)}),n}function R(t,e,n){var i=new E(t,null,{calculateRenderablePositions:!0});return i.batch(),t.config.sort&&(e=o(e,t.config.sort)),u(e,function(e){i.push(A(t,e,n))}),Object.defineProperty(i,"_context",{value:n,writable:!0}),i.end(),i}(function(e){function h(){this._events={},this._conf&&t.call(this,this._conf)}function t(e){e&&((this._conf=e).delimiter&&(this.delimiter=e.delimiter),e.maxListeners!==k&&(this._maxListeners=e.maxListeners),e.wildcard&&(this.wildcard=e.wildcard),e.newListener&&(this._newListener=e.newListener),e.removeListener&&(this._removeListener=e.removeListener),e.verboseMemoryLeak&&(this.verboseMemoryLeak=e.verboseMemoryLeak),e.ignoreErrors&&(this.ignoreErrors=e.ignoreErrors),this.wildcard)&&(this.listenerTree={})}function d(e,t){var n="(node) warning: possible EventEmitter memory leak detected. "+e+" listeners added. Use emitter.setMaxListeners() to increase limit.";this.verboseMemoryLeak&&(n+=" Event name: "+t+"."),"undefined"!=typeof process&&process.emitWarning?((t=new Error(n)).name="MaxListenersExceededWarning",t.emitter=this,t.count=e,process.emitWarning(t)):(console.error(n),console.trace&&console.trace())}function u(e,t,n){var i=arguments.length;switch(i){case 0:return[];case 1:return[e];case 2:return[e,t];case 3:return[e,t,n];default:for(var r=new Array(i);i--;)r[i]=arguments[i];return r}}function n(e,t){for(var n={},i=e.length,r=t?t.length:0,s=0;s<i;s++)n[e[s]]=s<r?t[s]:k;return n}function f(e,t,n){var i,r;if(this._emitter=e,this._target=t,this._listeners={},this._listenersCount=0,(n.on||n.off)&&(i=n.on,r=n.off),t.addEventListener?(i=t.addEventListener,r=t.removeEventListener):t.addListener?(i=t.addListener,r=t.removeListener):t.on&&(i=t.on,r=t.off),!i&&!r)throw Error("target does not implement any known event API");if("function"!=typeof i)throw TypeError("on method must be a function");if("function"!=typeof r)throw TypeError("off method must be a function");this._on=i,this._off=r;n=e._observers;n?n.push(this):e._observers=[this]}function v(e,t,n,i){var r=Object.assign({},t);if(e){if("object"!=typeof e)throw TypeError("options must be an object");for(var s,o,a,l=Object.keys(e),u=l.length,c=0;c<u;c++){if(s=l[c],!i&&!_.call(t,s))throw Error('Unknown "'+s+'" option');(o=e[s])!==k&&(a=n[s],r[s]=a?a(o,h):o)}}return r;function h(e){throw Error('Invalid "'+s+'" option value'+(e?". Reason: "+e:""))}}function i(e,t){return"function"==typeof e&&e.hasOwnProperty("prototype")||t("value must be a constructor"),e}function r(r){var s="value must be type of "+r.join("|"),o=r.length,i=r[0],a=r[1];return 1===o?function(e,t){if(typeof e===i)return e;t(s)}:2===o?function(e,t){var n=typeof e;if(n===i||n===a)return e;t(s)}:function(e,t){for(var n=typeof e,i=o;0<i--;)if(n===r[i])return e;t(s)}}function l(o,a,l){var u,c,h,d=0,f=new o(function(t,n,e){function i(){c=c&&null,d&&(clearTimeout(d),d=0)}l=v(l,{timeout:0,overload:!1},{timeout:function(e,t){return("number"!=typeof(e*=1)||e<0||!Number.isFinite(e))&&t("timeout must be a positive number"),e}}),u=!l.overload&&"function"==typeof o.prototype.cancel&&"function"==typeof e;function r(e){i(),t(e)}function s(e){i(),n(e)}u?a(r,s,e):(c=[function(e){s(e||Error("canceled"))}],a(r,s,function(e){if(h)throw Error("Unable to subscribe on cancel event asynchronously");if("function"!=typeof e)throw TypeError("onCancel callback must be a function");c.push(e)}),h=!0),0<l.timeout&&(d=setTimeout(function(){var e=Error("timeout");e.code="ETIMEDOUT",d=0,f.cancel(e),n(e)},l.timeout))});return u||(f.cancel=function(e){if(c){for(var t=c.length,n=1;n<t;n++)c[n](e);c[0](e),c=null}}),f}function p(e){var t=this._observers;if(t)for(var n=t.length,i=0;i<n;i++)if(t[i]._target===e)return i;return-1}function b(e,t,n,i,r){if(!n)return null;if(0===i){var s=typeof t;if("string"==s){var o,a,l=0,u=0,c=this.delimiter,h=c.length;if(-1!==(a=t.indexOf(c))){for(o=new Array(5);o[l++]=t.slice(u,a),-1!==(a=t.indexOf(c,u=a+h)););o[l++]=t.slice(u),t=o,r=l}else t=[t],r=1}else r="object"==s?t.length:(t=[t],1)}var d,f,v,p,y,m,k=null,_=t[i],g=t[i+1];if(i===r)n._listeners&&(k=("function"==typeof n._listeners?e&&e.push(n._listeners):e&&e.push.apply(e,n._listeners),[n]));else{if("*"===_){for(a=(y=j(n)).length;0<a--;)"_listeners"!==(d=y[a])&&(m=b(e,t,n[d],i+1,r))&&(k?k.push.apply(k,m):k=m);return k}if("**"===_){for((p=i+1===r||i+2===r&&"*"===g)&&n._listeners&&(k=b(e,t,n,r,r)),a=(y=j(n)).length;0<a--;)"_listeners"!==(d=y[a])&&(m="*"===d||"**"===d?(n[d]._listeners&&!p&&(m=b(e,t,n[d],r,r))&&(k?k.push.apply(k,m):k=m),b(e,t,n[d],i,r)):b(e,t,n[d],d===g?i+2:i,r))&&(k?k.push.apply(k,m):k=m);return k}n[_]&&(k=b(e,t,n[_],i+1,r))}if((s=n["*"])&&b(e,t,s,i+1,r),f=n["**"])if(i<r)for(f._listeners&&b(e,t,f,r,r),a=(y=j(f)).length;0<a--;)"_listeners"!==(d=y[a])&&(d===g?b(e,t,f[d],i+2,r):d===_?b(e,t,f[d],i+1,r):((v={})[d]=f[d],b(e,t,{"**":v},i+1,r)));else f._listeners?b(e,t,f,r,r):f["*"]&&f["*"]._listeners&&b(e,t,f["*"],r,r);return k}function c(e,t,n,i){for(var r,s,o,a=j(e),l=a.length,u=e._listeners;0<l--;)r=e[o=a[l]],s="_listeners"===o?n:n?n.concat(o):[o],o=i||"symbol"==typeof o,u&&t.push(o?s:s.join(this.delimiter)),"object"==typeof r&&c.call(this,r,t,s,o);return t}function y(e){for(var t,n,i,r=j(e),s=r.length;0<s--;)(t=e[n=r[s]])&&(i=!0,"_listeners"===n||y(t)||delete e[n]);return i}function m(e,t,n){this.emitter=e,this.event=t,this.listener=n}function s(e){this._events={},this._newListener=!1,this._removeListener=!1,this.verboseMemoryLeak=!1,t.call(this,e)}var k,_,g,w,x,o,D,j,a,L,P;_=Object.hasOwnProperty,g=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)},w="object"==typeof process&&"function"==typeof process.nextTick,x="function"==typeof Symbol,o="object"==typeof Reflect,D="function"==typeof setImmediate?setImmediate:setTimeout,j=x?o&&"function"==typeof Reflect.ownKeys?Reflect.ownKeys:function(e){var t=Object.getOwnPropertyNames(e);return t.push.apply(t,Object.getOwnPropertySymbols(e)),t}:Object.keys,Object.assign(f.prototype,{subscribe:function(n,i,r){function t(){var e=u.apply(null,arguments),t={data:e,name:i,original:n};r?!1!==r.call(o,t)&&a.emit.apply(a,[t.name].concat(e)):a.emit.apply(a,[i].concat(e))}var s=this,o=this._target,a=this._emitter,l=this._listeners;if(l[n])throw Error("Event '"+n+"' is already listening");this._listenersCount++,a._newListener&&a._removeListener&&!s._onNewListener?(this._onNewListener=function(e){e===i&&null===l[n]&&(l[n]=t,s._on.call(o,n,t))},a.on("newListener",this._onNewListener),this._onRemoveListener=function(e){e===i&&!a.hasListeners(e)&&l[n]&&(l[n]=null,s._off.call(o,n,t))},l[n]=null,a.on("removeListener",this._onRemoveListener)):(l[n]=t,s._on.call(o,n,t))},unsubscribe:function(e){var t,n,i,r=this,s=this._listeners,o=this._emitter,a=this._off,l=this._target;if(e&&"string"!=typeof e)throw TypeError("event must be a string");function u(){r._onNewListener&&(o.off("newListener",r._onNewListener),o.off("removeListener",r._onRemoveListener),r._onNewListener=null,r._onRemoveListener=null);var e=p.call(o,r);o._observers.splice(e,1)}if(e)(t=s[e])&&(a.call(l,e,t),delete s[e],--this._listenersCount||u());else{for(i=(n=j(s)).length;0<i--;)e=n[i],a.call(l,e,s[e]);this._listeners={},this._listenersCount=0,u()}}}),a=r(["function"]),L=r(["object","function"]),m.prototype.off=function(){return this.emitter.off(this.event,this.listener),this},(s.EventEmitter2=s).prototype.listenTo=function(u,e,c){if("object"!=typeof u)throw TypeError("target musts be an object");var h=this;function t(e){if("object"!=typeof e)throw TypeError("events must be an object");for(var t,n=c.reducers,i=p.call(h,u),r=-1===i?new f(h,u,c):h._observers[i],s=j(e),o=s.length,a="function"==typeof n,l=0;l<o;l++)t=s[l],r.subscribe(t,e[t]||t,a?n:n&&n[t])}return c=v(c,{on:k,off:k,reducers:k},{on:a,off:a,reducers:L}),g(e)?t(n(e)):t("string"==typeof e?n(e.split(/\s+/)):e),this},s.prototype.stopListeningTo=function(e,t){var n=this._observers;if(!n)return!1;var i,r=n.length,s=!1;if(e&&"object"!=typeof e)throw TypeError("target should be an object");for(;0<r--;)i=n[r],e&&i._target!==e||(i.unsubscribe(t),s=!0);return s},s.prototype.delimiter=".",s.prototype.setMaxListeners=function(e){e!==k&&(this._maxListeners=e,this._conf||(this._conf={}),this._conf.maxListeners=e)},s.prototype.getMaxListeners=function(){return this._maxListeners},s.prototype.event="",s.prototype.once=function(e,t,n){return this._once(e,t,!1,n)},s.prototype.prependOnceListener=function(e,t,n){return this._once(e,t,!0,n)},s.prototype._once=function(e,t,n,i){return this._many(e,1,t,n,i)},s.prototype.many=function(e,t,n,i){return this._many(e,t,n,!1,i)},s.prototype.prependMany=function(e,t,n,i){return this._many(e,t,n,!0,i)},s.prototype._many=function(e,t,n,i,r){var s=this;if("function"!=typeof n)throw new Error("many only accepts instances of Function");function o(){return 0==--t&&s.off(e,o),n.apply(this,arguments)}return o._origin=n,this._on(e,o,i,r)},s.prototype.emit=function(){if(!this._events&&!this._all)return!1;this._events||h.call(this);var e,t,n,i,r,s,o=arguments[0],a=this.wildcard;if("newListener"===o&&!this._newListener&&!this._events.newListener)return!1;if(a&&"newListener"!==(e=o)&&"removeListener"!==o&&"object"==typeof o){if(n=o.length,x)for(i=0;i<n;i++)if("symbol"==typeof o[i]){s=!0;break}s||(o=o.join(this.delimiter))}var l,u=arguments.length;if(this._all&&this._all.length)for(i=0,n=(l=this._all.slice()).length;i<n;i++)switch(this.event=o,u){case 1:l[i].call(this,o);break;case 2:l[i].call(this,o,arguments[1]);break;case 3:l[i].call(this,o,arguments[1],arguments[2]);break;default:l[i].apply(this,arguments)}if(a)b.call(this,l=[],e,this.listenerTree,0,n);else{if("function"==typeof(l=this._events[o])){switch(this.event=o,u){case 1:l.call(this);break;case 2:l.call(this,arguments[1]);break;case 3:l.call(this,arguments[1],arguments[2]);break;default:for(t=new Array(u-1),r=1;r<u;r++)t[r-1]=arguments[r];l.apply(this,t)}return!0}l=l&&l.slice()}if(l&&l.length){if(3<u)for(t=new Array(u-1),r=1;r<u;r++)t[r-1]=arguments[r];for(i=0,n=l.length;i<n;i++)switch(this.event=o,u){case 1:l[i].call(this);break;case 2:l[i].call(this,arguments[1]);break;case 3:l[i].call(this,arguments[1],arguments[2]);break;default:l[i].apply(this,t)}return!0}if(this.ignoreErrors||this._all||"error"!==o)return!!this._all;throw arguments[1]instanceof Error?arguments[1]:new Error("Uncaught, unspecified 'error' event.")},s.prototype.emitAsync=function(){if(!this._events&&!this._all)return!1;this._events||h.call(this);var e,t,n,i,r,s,o=arguments[0],a=this.wildcard;if("newListener"===o&&!this._newListener&&!this._events.newListener)return Promise.resolve([!1]);if(a&&"newListener"!==(e=o)&&"removeListener"!==o&&"object"==typeof o){if(i=o.length,x)for(r=0;r<i;r++)if("symbol"==typeof o[r]){t=!0;break}t||(o=o.join(this.delimiter))}var l,u=[],c=arguments.length;if(this._all)for(r=0,i=this._all.length;r<i;r++)switch(this.event=o,c){case 1:u.push(this._all[r].call(this,o));break;case 2:u.push(this._all[r].call(this,o,arguments[1]));break;case 3:u.push(this._all[r].call(this,o,arguments[1],arguments[2]));break;default:u.push(this._all[r].apply(this,arguments))}if(a?b.call(this,l=[],e,this.listenerTree,0):l=this._events[o],"function"==typeof l)switch(this.event=o,c){case 1:u.push(l.call(this));break;case 2:u.push(l.call(this,arguments[1]));break;case 3:u.push(l.call(this,arguments[1],arguments[2]));break;default:for(n=new Array(c-1),s=1;s<c;s++)n[s-1]=arguments[s];u.push(l.apply(this,n))}else if(l&&l.length){if(l=l.slice(),3<c)for(n=new Array(c-1),s=1;s<c;s++)n[s-1]=arguments[s];for(r=0,i=l.length;r<i;r++)switch(this.event=o,c){case 1:u.push(l[r].call(this));break;case 2:u.push(l[r].call(this,arguments[1]));break;case 3:u.push(l[r].call(this,arguments[1],arguments[2]));break;default:u.push(l[r].apply(this,n))}}else if(!this.ignoreErrors&&!this._all&&"error"===o)return arguments[1]instanceof Error?Promise.reject(arguments[1]):Promise.reject("Uncaught, unspecified 'error' event.");return Promise.all(u)},s.prototype.on=function(e,t,n){return this._on(e,t,!1,n)},s.prototype.prependListener=function(e,t,n){return this._on(e,t,!0,n)},s.prototype.onAny=function(e){return this._onAny(e,!1)},s.prototype.prependAny=function(e){return this._onAny(e,!0)},s.prototype.addListener=s.prototype.on,s.prototype._onAny=function(e,t){if("function"!=typeof e)throw new Error("onAny only accepts instances of Function");return this._all||(this._all=[]),t?this._all.unshift(e):this._all.push(e),this},s.prototype._on=function(e,t,n,i){if("function"==typeof e)return this._onAny(e,t),this;if("function"!=typeof t)throw new Error("on only accepts instances of Function");this._events||h.call(this);var r=this;return i!==k&&(t=(i=function(e,t,n){if(!0===n)r=!0;else if(!1===n)i=!0;else{if(!n||"object"!=typeof n)throw TypeError("options should be an object or true");var i=n.async,r=n.promisify,s=n.nextTick,o=n.objectify}if(i||s||r){var a=t,n=t._origin||t;if(s&&!w)throw Error("process.nextTick is not supported");r===k&&(r="AsyncFunction"===t.constructor.name),(t=function(){var e=arguments,t=this,n=this.event;return r?s?Promise.resolve():new Promise(function(e){D(e)}).then(function(){return t.event=n,a.apply(t,e)}):(s?process.nextTick:D)(function(){t.event=n,a.apply(t,e)})})._async=!0,t._origin=n}return[t,o?new m(this,e,t):this]}.call(this,e,t,i))[0],r=i[1]),this._newListener&&this.emit("newListener",e,t),this.wildcard?function(e,t,n){var i,r=0,s=0,o=this.delimiter,a=o.length;if("string"==typeof e)if(-1!==(c=e.indexOf(o))){for(i=new Array(5);i[r++]=e.slice(s,c),-1!==(c=e.indexOf(o,s=c+a)););i[r++]=e.slice(s)}else i=[e],r=1;else r=(i=e).length;if(1<r)for(c=0;c+1<r;c++)if("**"===i[c]&&"**"===i[c+1])return;for(var l,u=this.listenerTree,c=0;c<r;c++)if(u=u[l=i[c]]||(u[l]={}),c===r-1)return u._listeners?("function"==typeof u._listeners&&(u._listeners=[u._listeners]),n?u._listeners.unshift(t):u._listeners.push(t),!u._listeners.warned&&0<this._maxListeners&&u._listeners.length>this._maxListeners&&(u._listeners.warned=!0,d.call(this,u._listeners.length,l))):u._listeners=t,!0;return!0}.call(this,e,t,n):this._events[e]?("function"==typeof this._events[e]&&(this._events[e]=[this._events[e]]),n?this._events[e].unshift(t):this._events[e].push(t),!this._events[e].warned&&0<this._maxListeners&&this._events[e].length>this._maxListeners&&(this._events[e].warned=!0,d.call(this,this._events[e].length,e))):this._events[e]=t,r},s.prototype.off=function(e,t){if("function"!=typeof t)throw new Error("removeListener only takes instances of Function");var n=[];if(this.wildcard){var i="string"==typeof e?e.split(this.delimiter):e.slice();if(!(n=b.call(this,null,i,this.listenerTree,0)))return this}else{if(!this._events[e])return this;o=this._events[e],n.push({_listeners:o})}for(var r=0;r<n.length;r++){var s=n[r],o=s._listeners;if(g(o)){for(var a=-1,l=0,u=o.length;l<u;l++)if(o[l]===t||o[l].listener&&o[l].listener===t||o[l]._origin&&o[l]._origin===t){a=l;break}if(!(a<0))return(this.wildcard?s._listeners:this._events[e]).splice(a,1),0===o.length&&(this.wildcard?delete s._listeners:delete this._events[e]),this._removeListener&&this.emit("removeListener",e,t),this}else(o===t||o.listener&&o.listener===t||o._origin&&o._origin===t)&&(this.wildcard?delete s._listeners:delete this._events[e],this._removeListener)&&this.emit("removeListener",e,t)}return this.listenerTree&&y(this.listenerTree),this},s.prototype.offAny=function(e){var t,n=0,i=0;if(e&&this._all&&0<this._all.length){for(n=0,i=(t=this._all).length;n<i;n++)if(e===t[n])return t.splice(n,1),this._removeListener&&this.emit("removeListenerAny",e),this}else{if(t=this._all,this._removeListener)for(n=0,i=t.length;n<i;n++)this.emit("removeListenerAny",t[n]);this._all=[]}return this},s.prototype.removeListener=s.prototype.off,s.prototype.removeAllListeners=function(e){if(e===k)this._events&&h.call(this);else if(this.wildcard){var t,n=b.call(this,null,e,this.listenerTree,0);if(!n)return this;for(t=0;t<n.length;t++)n[t]._listeners=null;this.listenerTree&&y(this.listenerTree)}else this._events&&(this._events[e]=null);return this},s.prototype.listeners=function(e){var t,n,i,r,s,o,a,l=this._events;if(e!==k)return this.wildcard?(s=this.listenerTree)?(o=[],a="string"==typeof e?e.split(this.delimiter):e.slice(),b.call(this,o,a,s,0),o):[]:l&&(n=l[e])?"function"==typeof n?[n]:n:[];if(this.wildcard)throw Error("event name required for wildcard emitter");if(!l)return[];for(r=(t=j(l)).length,i=[];0<r--;)"function"==typeof(n=l[t[r]])?i.push(n):i.push.apply(i,n);return i},s.prototype.eventNames=function(e){var t=this._events;return this.wildcard?c.call(this,this.listenerTree,[],null,e):t?j(t):[]},s.prototype.listenerCount=function(e){return this.listeners(e).length},s.prototype.hasListeners=function(e){var t,n;return this.wildcard?(n=[],t="string"==typeof e?e.split(this.delimiter):e.slice(),b.call(this,n,t,this.listenerTree,0),0<n.length):(t=this._events,!!((n=this._all)&&n.length||t&&(e===k?j(t).length:t[e])))},s.prototype.listenersAny=function(){return this._all||[]},s.prototype.waitFor=function(r,s){var o=this,e=typeof s;return"number"==e?s={timeout:s}:"function"==e&&(s={filter:s}),l((s=v(s,{timeout:0,filter:k,handleError:!1,Promise:Promise,overload:!1},{filter:a,Promise:i})).Promise,function(t,n,e){function i(){var e=s.filter;e&&!e.apply(o,arguments)||(o.off(r,i),s.handleError?(e=arguments[0])?n(e):t(u.apply(null,arguments).slice(1)):t(u.apply(null,arguments)))}e(function(){o.off(r,i)}),o._on(r,i,!1)},{timeout:s.timeout,overload:s.overload})},P=s.prototype,Object.defineProperties(s,{defaultMaxListeners:{get:function(){return P._maxListeners},set:function(e){if("number"!=typeof e||e<0||Number.isNaN(e))throw TypeError("n must be a non-negative number");P._maxListeners=e},enumerable:!0},once:{value:function(o,a,e){return l((e=v(e,{Promise:Promise,timeout:0,overload:!1},{Promise:i})).Promise,function(e,t,n){var i,r,s;"function"==typeof o.addEventListener?(i=function(){e(u.apply(null,arguments))},n(function(){o.removeEventListener(a,i)}),o.addEventListener(a,i,{once:!0})):(r=function(){s&&o.removeListener("error",s),e(u.apply(null,arguments))},"error"!==a&&(s=function(e){o.removeListener(a,r),t(e)},o.once("error",s)),n(function(){s&&o.removeListener("error",s),o.removeListener(a,r)}),o.once(a,r))},{timeout:e.timeout,overload:e.overload})},writable:!0,configurable:!0}}),Object.defineProperties(P,{_maxListeners:{value:10,writable:!0,configurable:!0},_observers:{value:null,writable:!0,configurable:!0}}),"function"==typeof k&&k.amd?k(function(){return s}):e.exports=s})(re={exports:{}});var re,se=re.exports.EventEmitter2;function T(e,t,n){return e.model[t].apply(e.model,n)}return function(){function o(e){x(this,o),(r=w(this,o))._lastSelectedNode,r._muted=!1,r.allowsLoadEvents=!1,r.id=ie(),r.initialized=!1,r.isDynamic=!1,r.opts=e,r.preventDeselection=!1,r.config=l({},e,{allowLoadEvents:[],cancelEditOnBlur:!0,checkbox:{autoCheckChildren:!0},contextMenu:!1,data:!1,editable:!1,editing:{add:!1,edit:!1,remove:!1},nodes:{resetStateOnRestore:!0},pagination:{limit:-1},search:{matcher:!1,matchProcessor:!1},selection:{allow:M,autoDeselect:!0,autoSelectChildren:!1,autoSelectOnNodeRemoval:!0,disableDirectDeselection:!1,mode:"default",multiple:!1,require:!1,reselectOnSearchClear:!1,selectOnSearch:!1},showCheckboxes:!1,sort:!1}),"checkbox"===r.config.selection.mode&&(r.config.selection.autoSelectChildren=!0,r.on("node.checked",function(e){e.selected()||e.select(!0)}),r.on("node.selected",function(e){e.checked()||e.check(!0)}),r.on("node.unchecked",function(e){e.selected()&&e.deselect(!0)}),r.on("node.deselected",function(e){e.checked()&&e.uncheck(!0)})),r.config.selection.autoSelectChildren&&(r.config.selection.multiple=!0,r.config.selection.autoDeselect=!1),e.editable&&!e.editing&&(r.config.editing.add=!0,r.config.editing.edit=!0,r.config.editing.remove=!0),v(e.search)&&(r.config.search={matcher:e.search,matchProcessor:!1}),r.defaultState={collapsed:!0,editable:c(r,"config.editing.edit"),editing:!1,draggable:!0,"drop-target":!0,focused:!1,hidden:!1,indeterminate:!1,loading:!1,matched:!1,removed:!1,rendered:!1,selectable:!0,selected:!1},r.allowsLoadEvents=d(r.config.allowLoadEvents)&&0<r.config.allowLoadEvents.length,r.isDynamic=v(r.config.data);var r,s=r.emit;return r.emit=function(){for(var e,t=arguments.length,n=new Array(t),i=0;i<t;i++)n[i]=arguments[i];r.isEventMuted(n[0])||(v(c(n,"[0].preventDefault"))&&((e=n[0]).treeDefaultPrevented=!1,e.preventTreeDefault=function(){e.treeDefaultPrevented=!0}),s.apply(r,n))},r.model=new E(r),r._previouslySelectedNodes=new E(r),r.config.data&&r.load(r.config.data),r.initialized=!0,r}return J(o,se),e(o,[{key:"addNode",value:function(){return T(this,"addNode",arguments)}},{key:"addNodes",value:function(e){var t=this,n=(this.batch(),new E(this));return u(e,function(e){return n.push(t.addNode(e))}),this.end(),n}},{key:"applyChanges",value:function(){return this.model.applyChanges()}},{key:"autoSelectNode",value:function(){return this.config.selection.require&&!this.selected().length?this.selectFirstAvailableNode():null}},{key:"available",value:function(){return T(this,"available",arguments)}},{key:"batch",value:function(){return this.model.batch()}},{key:"blur",value:function(){return T(this,"blur",arguments)}},{key:"blurDeep",value:function(){return T(this,"blurDeep",arguments)}},{key:"boundingNodes",value:function(e,t){function n(e,t){return e[0]===t[0]?1<e.length&&1<t.length?n(r(e),r(t)):0:e[0]>t[0]?1:-1}return 1===n(e.indexList(),t.indexList())?[t,e]:[e,t]}},{key:"cacheSelectedNodes",value:function(){this._previouslySelectedNodes=this.selected()}},{key:"canAutoDeselect",value:function(){return this.config.selection.autoDeselect&&!this.preventDeselection}},{key:"checked",value:function(){return T(this,"checked",arguments)}},{key:"clean",value:function(){return T(this,"clean",arguments)}},{key:"clearSearch",value:function(){return this.batch(),this.recurseDown(function(e){e.show().collapse().state("matched",!1)}),this.config.selection.reselectOnSearchClear&&this.previouslySelectedNodes().select(),this.end(),this}},{key:"clone",value:function(){return T(this,"clone",arguments)}},{key:"collapse",value:function(){return T(this,"collapse",arguments)}},{key:"collapsed",value:function(){return T(this,"collapsed",arguments)}},{key:"collapseDeep",value:function(){return T(this,"collapseDeep",arguments)}},{key:"concat",value:function(){return T(this,"concat",arguments)}},{key:"copy",value:function(){return T(this,"copy",arguments)}},{key:"createNode",value:function(e){return o.isTreeNode(e)?e:A(this,e)}},{key:"deepest",value:function(){return T(this,"deepest",arguments)}},{key:"deselect",value:function(){return T(this,"deselect",arguments)}},{key:"deselectDeep",value:function(){return T(this,"deselectDeep",arguments)}},{key:"disableDeselection",value:function(){return this.config.selection.multiple&&(this.preventDeselection=!0),this}},{key:"each",value:function(){return T(this,"each",arguments)}},{key:"editable",value:function(){return T(this,"editable",arguments)}},{key:"editing",value:function(){return T(this,"editing",arguments)}},{key:"enableDeselection",value:function(){return this.preventDeselection=!1,this}},{key:"end",value:function(){return this.model.end()}},{key:"every",value:function(){return T(this,"every",arguments)}},{key:"expand",value:function(){return T(this,"expand",arguments)}},{key:"expandDeep",value:function(){return T(this,"expandDeep",arguments)}},{key:"expanded",value:function(){return T(this,"expanded",arguments)}},{key:"extract",value:function(){return T(this,"extract",arguments)}},{key:"filter",value:function(){return T(this,"filter",arguments)}},{key:"filterBy",value:function(){return T(this,"filterBy",arguments)}},{key:"find",value:function(){return T(this,"find",arguments)}},{key:"first",value:function(){return T(this,"first",arguments)}},{key:"flatten",value:function(){return T(this,"flatten",arguments)}},{key:"focused",value:function(){return T(this,"focused",arguments)}},{key:"forEach",value:function(){return T(this,"each",arguments)}},{key:"get",value:function(){return T(this,"get",arguments)}},{key:"hidden",value:function(){return T(this,"hidden",arguments)}},{key:"hide",value:function(){return T(this,"hide",arguments)}},{key:"hideDeep",value:function(){return T(this,"hideDeep",arguments)}},{key:"indeterminate",value:function(){return T(this,"indeterminate",arguments)}},{key:"indexOf",value:function(){return T(this,"indexOf",arguments)}},{key:"insertAt",value:function(){return T(this,"insertAt",arguments)}},{key:"invoke",value:function(){return T(this,"invoke",arguments)}},{key:"invokeDeep",value:function(){return T(this,"invokeDeep",arguments)}},{key:"isEventMuted",value:function(e){return i(this.muted())?this.muted():h(this.muted(),e)}},{key:"isTree",value:function(e){return e instanceof o}},{key:"join",value:function(){return T(this,"join",arguments)}},{key:"last",value:function(){return T(this,"last",arguments)}},{key:"lastSelectedNode",value:function(){return this._lastSelectedNode}},{key:"load",value:function(n){var o=this,e=new Promise(function(r,s){function e(e,t){if(!f(e))return s(new TypeError("Loader requires an array-like `nodes` parameter."));function n(){o.emit("model.loaded",o.model),r(o.model),o.model.applyChanges()}!o.initialized&&f(e)?setTimeout(function(){o.emit("data.loaded",e)}):o.emit("data.loaded",e);var i=R(o,e);o.config.deferredLoading?o.model=o.model.concat(i):o.model=i,o.model._pagination.total=e.length,parseInt(t,10)>e.length&&(o.model._pagination.total=parseInt(t,10)),t||o.model.recurseDown(function(e){e.hasChildren()&&(e.children._pagination.total=e.children.length)}),o.autoSelectNode(),!o.initialized&&d(e)?setTimeout(n):n()}var t;f(n)?e(n):v(n)&&(t=n(null,e,s,o.pagination()))&&(n=t),p(n)?$(n).then(e).catch(s):s(new Error("Invalid data loader."))});return e.catch(function(e){o.emit("data.loaderror",e)}),this._loader={promise:e},e}},{key:"loading",value:function(){return T(this,"loading",arguments)}},{key:"loadMore",value:function(){return T(this,"loadMore",arguments)}},{key:"map",value:function(){return T(this,"map",arguments)}},{key:"matched",value:function(){return T(this,"matched",arguments)}},{key:"move",value:function(){return T(this,"move",arguments)}},{key:"mute",value:function(e){return y(e)||d(e)?this._muted=a(e):this._muted=!0,this}},{key:"muted",value:function(){return this._muted}},{key:"node",value:function(){return T(this,"node",arguments)}},{key:"nodes",value:function(){return T(this,"nodes",arguments)}},{key:"pagination",value:function(){return T(this,"pagination",arguments)}},{key:"pop",value:function(){return T(this,"pop",arguments)}},{key:"previouslySelectedNodes",value:function(){return this._previouslySelectedNodes}},{key:"push",value:function(){return T(this,"push",arguments)}},{key:"recurseDown",value:function(){return T(this,"recurseDown",arguments)}},{key:"reduce",value:function(){return T(this,"reduce",arguments)}},{key:"reduceRight",value:function(){return T(this,"reduceRight",arguments)}},{key:"reload",value:function(){return this.reset(),this.load(this.opts.data||this.config.data)}},{key:"remove",value:function(){return T(this,"remove",arguments)}},{key:"removeAll",value:function(){return this.reset().applyChanges(),this}},{key:"removed",value:function(){return T(this,"removed",arguments)}},{key:"reset",value:function(){return this.model=new E(this),this}},{key:"restore",value:function(){return T(this,"restore",arguments)}},{key:"restoreDeep",value:function(){return T(this,"restoreDeep",arguments)}},{key:"reverse",value:function(){return T(this,"reverse",arguments)}},{key:"search",value:function(t){var r=this,e=this.config.search,i=e.matcher,s=e.matchProcessor;return!t||y(t)&&U(t)?Promise.resolve(this.clearSearch()):(this.batch(),this.recurseDown(function(e){e.state("hidden",!0),e.state("matched",!1)}),this.end(),i=v(i)?i:function(t,e){var n,i=new E(r);y(t)&&(t=new RegExp(t,"i")),n=B(t)?function(e){return t.test(e.text)}:t,r.model.recurseDown(function(e){e.removed()||n(e)&&i.push(e)}),e(i)},s=v(s)?s:function(e){e.each(function(e){e.show().state("matched",!0),e.expandParents().collapse(),e.hasChildren()&&e.children.showDeep()})},new Promise(function(n,e){i(t,function(e){var t;o.isTreeNodes(e)||(e=r.nodes(q(e,"id"))),r.batch(),s(e),r.config.selection.selectOnSearch&&(t=e.find(function(e){return e.available()&&e.selectable()}))&&t.select(),r.end(),n(e)},e)}))}},{key:"select",value:function(){return T(this,"select",arguments)}},{key:"selectable",value:function(){return T(this,"selectable",arguments)}},{key:"selectBetween",value:function(e,t){this.batch();for(var n=e.nextVisibleNode();n.id!==t.id;)n.select(),n=n.nextVisibleNode();return this.end(),this}},{key:"selectDeep",value:function(){return T(this,"selectDeep",arguments)}},{key:"selected",value:function(){return T(this,"selected",arguments)}},{key:"selectFirstAvailableNode",value:function(){var e=this.model.find(function(e){return e.available()&&e.selectable()});return e&&e.select(),e}},{key:"shift",value:function(){return T(this,"shift",arguments)}},{key:"show",value:function(){return T(this,"show",arguments)}},{key:"showDeep",value:function(){return T(this,"showDeep",arguments)}},{key:"slice",value:function(){return T(this,"slice",arguments)}},{key:"softRemove",value:function(){return T(this,"softRemove",arguments)}},{key:"some",value:function(){return T(this,"some",arguments)}},{key:"sort",value:function(){return T(this,"sort",arguments)}},{key:"sortBy",value:function(){return T(this,"sortBy",arguments)}},{key:"sortDeep",value:function(){return T(this,"sortDeep",arguments)}},{key:"splice",value:function(){return T(this,"splice",arguments)}},{key:"state",value:function(){return T(this,"state",arguments)}},{key:"stateDeep",value:function(){return T(this,"stateDeep",arguments)}},{key:"swap",value:function(){return T(this,"swap",arguments)}},{key:"toArray",value:function(){return T(this,"toArray",arguments)}},{key:"toString",value:function(){return T(this,"toString",arguments)}},{key:"unmute",value:function(e){return(y(e)||d(e))&&(this._muted=I(this._muted,a(e)),this._muted.length)||(this._muted=!1),this}},{key:"unshift",value:function(){return T(this,"unshift",arguments)}},{key:"visible",value:function(){return T(this,"visible",arguments)}}],[{key:"isTreeNode",value:function(e){return e instanceof N}},{key:"isTreeNodes",value:function(e){return e instanceof E}}])}()});
