text: /* Inspire Tree
   * @version 6.0.1
   * 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")):"function"==typeof define&&define.amd?define(["lodash"],t):(e=e||self).InspireTree=t(e._)}(this,function(c){"use strict";function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(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,i.key,i)}}function e(e,t,n){return t&&i(e.prototype,t),n&&i(e,n),e}function t(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}}),t&&n(e,t)}function u(e){return(u=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function n(e,t){return(n=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function l(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function h(e,t){return!t||"object"!=typeof t&&"function"!=typeof t?l(e):t}function r(e,t,n){return(r="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(e,t,n){var i=function(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=u(e)););return e}(e,t);if(i){var r=Object.getOwnPropertyDescriptor(i,t);return r.get?r.get.call(n):r.value}})(e,t,n||e)}function s(e){return function(e){if(Array.isArray(e))return e}(e)||function(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}(e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function o(t,n,i,e,r){return e.state(t)!==n&&(e.context().batch(),e._tree.config.nodes.resetStateOnRestore&&"restored"===i&&function(n){c.each(n._tree.defaultState,function(e,t){n.state(t,e)})}(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){o(t,n,i,e)}),"hidden"!==t&&"removed"!==t||(e.context().indicesDirty=!0,e.context().calculateRenderablePositions()),e.markDirty(),e.context().end()),e}var T="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function d(e,t){return e(t={exports:{}},t.exports),t.exports}var f=d(function(e,t){
  /*!
     * @overview es6-promise - a tiny implementation of Promises/A+.
     * @copyright Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors (Conversion to ES6 API by Jake Archibald)
     * @license   Licensed under MIT license
     *            See https://raw.githubusercontent.com/stefanpenner/es6-promise/master/LICENSE
     * @version   v4.2.8+1e68dce6
     */
  e.exports=function(){function c(e){return"function"==typeof e}var n=Array.isArray?Array.isArray:function(e){return"[object Array]"===Object.prototype.toString.call(e)},i=0,t=void 0,r=void 0,o=function(e,t){d[i]=e,d[i+1]=t,2===(i+=2)&&(r?r(f):v())};var e="undefined"!=typeof window?window:void 0,s=e||{},a=s.MutationObserver||s.WebKitMutationObserver,u="undefined"==typeof self&&"undefined"!=typeof process&&"[object process]"==={}.toString.call(process),l="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel;function h(){var e=setTimeout;return function(){return e(f,1)}}var d=new Array(1e3);function f(){for(var e=0;e<i;e+=2){var t=d[e],n=d[e+1];t(n),d[e]=void 0,d[e+1]=void 0}i=0}var v=void 0;function y(e,t){var n=this,i=new this.constructor(g);void 0===i[k]&&j(i);var r=n._state;if(r){var s=arguments[r-1];o(function(){return O(r,i,s,n._result)})}else C(n,i,e,t);return i}function p(e){if(e&&"object"==typeof e&&e.constructor===this)return e;var t=new this(g);return D(t,e),t}v=u?function(){return process.nextTick(f)}:a?function(){var e=0,t=new a(f),n=document.createTextNode("");return t.observe(n,{characterData:!0}),function(){n.data=e=++e%2}}():l?function(){var e=new MessageChannel;return e.port1.onmessage=f,function(){return e.port2.postMessage(0)}}():void 0===e?function(){try{var e=Function("return this")().require("vertx");return void 0===(t=e.runOnLoop||e.runOnContext)?h():function(){t(f)}}catch(e){return h()}}():h();var k=Math.random().toString(36).substring(2);function g(){}var _=void 0,m=1,b=2;function w(e,t,n,i){try{e.call(t,n,i)}catch(e){return e}}function x(e,t,n){t.constructor===e.constructor&&n===y&&t.constructor.resolve===p?function(t,e){e._state===m?L(t,e._result):e._state===b?P(t,e._result):C(e,void 0,function(e){return D(t,e)},function(e){return P(t,e)})}(e,t):void 0===n?L(e,t):c(n)?function(e,i,r){o(function(t){var n=!1,e=w(r,i,function(e){n||(n=!0,i!==e?D(t,e):L(t,e))},function(e){n||(n=!0,P(t,e))},t._label);!n&&e&&(n=!0,P(t,e))},e)}(e,t,n):L(e,t)}function D(t,e){if(t===e)P(t,new TypeError("You cannot resolve a promise with itself"));else if(function(e){var t=typeof e;return null!==e&&("object"==t||"function"==t)}(e)){var n=void 0;try{n=e.then}catch(e){return void P(t,e)}x(t,e,n)}else L(t,e)}function A(e){e._onerror&&e._onerror(e._result),S(e)}function L(e,t){e._state===_&&(e._result=t,e._state=m,0!==e._subscribers.length&&o(S,e))}function P(e,t){e._state===_&&(e._state=b,e._result=t,o(A,e))}function C(e,t,n,i){var r=e._subscribers,s=r.length;e._onerror=null,r[s]=t,r[s+m]=n,r[s+b]=i,0===s&&e._state&&o(S,e)}function S(e){var t=e._subscribers,n=e._state;if(0!==t.length){for(var i=void 0,r=void 0,s=e._result,o=0;o<t.length;o+=3)i=t[o],r=t[o+n],i?O(n,i,r,s):r(s);e._subscribers.length=0}}function O(e,t,n,i){var r=c(n),s=void 0,o=void 0,a=!0;if(r){try{s=n(i)}catch(e){a=!1,o=e}if(t===s)return void P(t,new TypeError("A promises callback cannot return that same promise."))}else s=i;t._state!==_||(r&&a?D(t,s):!1===a?P(t,o):e===m?L(t,s):e===b&&P(t,s))}var N=0;function j(e){e[k]=N++,e._state=void 0,e._result=void 0,e._subscribers=[]}var E=function(){function e(e,t){this._instanceConstructor=e,this.promise=new e(g),this.promise[k]||j(this.promise),n(t)?(this.length=t.length,this._remaining=t.length,this._result=new Array(this.length),0===this.length?L(this.promise,this._result):(this.length=this.length||0,this._enumerate(t),0===this._remaining&&L(this.promise,this._result))):P(this.promise,new Error("Array Methods must be provided an Array"))}return e.prototype._enumerate=function(e){for(var t=0;this._state===_&&t<e.length;t++)this._eachEntry(e[t],t)},e.prototype._eachEntry=function(t,e){var n=this._instanceConstructor,i=n.resolve;if(i===p){var r=void 0,s=void 0,o=!1;try{r=t.then}catch(e){o=!0,s=e}if(r===y&&t._state!==_)this._settledAt(t._state,e,t._result);else if("function"!=typeof r)this._remaining--,this._result[e]=t;else if(n===R){var a=new n(g);o?P(a,s):x(a,t,r),this._willSettleAt(a,e)}else this._willSettleAt(new n(function(e){return e(t)}),e)}else this._willSettleAt(i(t),e)},e.prototype._settledAt=function(e,t,n){var i=this.promise;i._state===_&&(this._remaining--,e===b?P(i,n):this._result[t]=n),0===this._remaining&&L(i,this._result)},e.prototype._willSettleAt=function(e,t){var n=this;C(e,void 0,function(e){return n._settledAt(m,t,e)},function(e){return n._settledAt(b,t,e)})},e}();var R=function(){function t(e){this[k]=N++,this._result=this._state=void 0,this._subscribers=[],g!==e&&("function"!=typeof e&&function(){throw new TypeError("You must pass a resolver function as the first argument to the promise constructor")}(),this instanceof t?function(t,e){try{e(function(e){D(t,e)},function(e){P(t,e)})}catch(e){P(t,e)}}(this,e):function(){throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.")}())}return t.prototype.catch=function(e){return this.then(null,e)},t.prototype.finally=function(t){var n=this.constructor;return c(t)?this.then(function(e){return n.resolve(t()).then(function(){return e})},function(e){return n.resolve(t()).then(function(){throw e})}):this.then(t,t)},t}();return R.prototype.then=y,R.all=function(e){return new E(this,e).promise},R.race=function(r){var s=this;return n(r)?new s(function(e,t){for(var n=r.length,i=0;i<n;i++)s.resolve(r[i]).then(e,t)}):new s(function(e,t){return t(new TypeError("You must pass an array to race."))})},R.resolve=p,R.reject=function(e){var t=new this(g);return P(t,e),t},R._setScheduler=function(e){r=e},R._setAsap=function(e){o=e},R._asap=o,R.polyfill=function(){var e=void 0;if(void 0!==T)e=T;else if("undefined"!=typeof self)e=self;else try{e=Function("return this")()}catch(e){throw new Error("polyfill failed because global object is unavailable in this environment")}var t=e.Promise;if(t){var n=null;try{n=Object.prototype.toString.call(t.resolve())}catch(e){}if("[object Promise]"===n&&!t.cast)return}e.Promise=R},R.Promise=R}()}).Promise;function v(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 y(e,n,i,t){return n=c.castArray(n),e._tree.batch(),e[t?"recurseDown":"each"](function(t){c.each(n,function(e){c.isFunction(t[e])&&t[e].apply(t,i)})}),e._tree.end(),e}function p(t){var e=t;return c.isString(t)&&(e=function(e){return c.isFunction(e[t])?e[t]():e[t]}),e}function k(t,e){if(e)return this.extract(t);var n=p(t);return this.flatten(function(e){return("removed"===t||!e.removed())&&n(e)})}var g=function(){function s(e,t,n){var i;if(a(this,s),i=h(this,u(s).call(this)),c.isFunction(c.get(e,"isTree"))&&!e.isTree(e))throw new TypeError("Invalid tree instance.");return i._tree=e,i.length=0,i.batching=0,i.indicesDirty=!1,i.config=c.defaultsDeep({},n,{calculateRenderablePositions:!1}),i._pagination={limit:e.config.pagination.limit,total:0},(c.isArray(t)||t instanceof s)&&c.each(t,function(e){e instanceof w?i.push(e.clone()):i.addNode(e)}),i}return t(s,v(Array)),e(s,[{key:"addNode",value:function(e){var t=this.length;return this._tree.config.sort&&(t=c.sortedIndexBy(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 k.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 k.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 k.call(this,"collapsed",e)}},{key:"collapseDeep",value:function(){return this.invokeDeep("collapse")}},{key:"concat",value:function(e){var t=new s(this._tree);t._context=this._context;function n(e){e instanceof w&&t.push(e)}return c.each(this,n),c.each(e,n),t._pagination.limit=this._pagination.limit,t}},{key:"context",value:function(){return this._context||this._tree}},{key:"copy",value:function(t,n,i){var r=new s(this._tree);return c.each(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 c.each(this,e),this}},{key:"editable",value:function(e){return k.call(this,"editable",e)}},{key:"editing",value:function(e){return k.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 k.call(this,"expanded",e)}},{key:"expandDeep",value:function(){var i=this;return new f(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 t=this.flatten(e),n=new s(this._tree);return c.each(t,function(e){return n.addNode(e.copyHierarchy())}),n}},{key:"filterBy",value:function(e){var t=p(e),n=new s(this._tree);return c.each(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=p(e);return this.recurseDown(function(e){n(e)&&t.push(e)}),t}},{key:"focused",value:function(e){return k.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 k.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 k.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(),c.isArrayLike(t.children)?(c.isArrayLike(n.children)||(n.children=new s(this._tree),n.children._context=n),c.each(t.children,function(e){n.children.addNode(e)})):t.children&&c.isBoolean(n.children)&&(n.children=t.children),n.markDirty(),this.applyChanges(),n}var i=this._tree.constructor.isTreeNode(t)?t:C(this._tree,t);return this.splice(e,0,i),this._context&&(i.itree.parent=this._context,this._context.refreshIndeterminateState().markDirty()),this._tree.emit("node.added",i),i.markDirty(),this.length-1!==e&&this.invoke("markDirty"),this.applyChanges(),i}},{key:"invoke",value:function(e,t){return y(this,e,t)}},{key:"invokeDeep",value:function(e,t){return(!c.isArrayLikeObject(t)||2<arguments.length)&&(t=c.tail(arguments)),y(this,e,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 k.call(this,"loading",e)}},{key:"loadMore",value:function(e){var t,n=this;return this._loading?f.reject(new Error("Pending loadMore call must complete before being invoked again.")):this._pagination.limit===this._pagination.total?f.resolve():(this._loading=!0,this.batch(),c.invoke(this._context,"markDirty"),this._pagination.limit+=this._tree.config.pagination.limit,this._tree.emit("node.paginated",this._context||this._tree,this.pagination,e),t=this._tree.config.deferredLoading?this._context?this._context.loadChildren():this._tree.load(this._tree.config.data):(this._loading=!1,f.resolve()),this.end(),this._tree.config.deferredLoading&&t.then(function(){n._loading=!1,n.applyChanges()}).catch(function(){n._loading=!1,n.applyChanges()}),t)}},{key:"matched",value:function(e){return k.call(this,"matched",e)}},{key:"move",value:function(e,t,n){var i=2<arguments.length&&void 0!==n?n:this,r=this[e].remove(),s=i.insertAt(t,r);return this._tree.emit("node.moved",s,this,e,i,t),s}},{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 c.isArray(t)&&(n=new s(this._tree),this.recurseDown(function(e){-1<t.indexOf(e.id)&&n.push(e)})),c.isArray(t)?n:this}},{key:"pagination",value:function(){return this._pagination}},{key:"pop",value:function(){var e=r(u(s.prototype),"pop",this).call(this);return this.indicesDirty=!0,this.calculateRenderablePositions(),e}},{key:"push",value:function(e){var t=r(u(s.prototype),"push",this).call(this,e);return this.indicesDirty=!0,this.calculateRenderablePositions(),t}},{key:"recurseDown",value:function(e){return _(this,e),this}},{key:"remove",value:function(e){return c.remove(this,{id:e.id}),c.invoke(this._context,"markDirty"),this.indicesDirty=!0,this.applyChanges(),this}},{key:"removed",value:function(e){return k.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 k.call(this,"selectable",e)}},{key:"selectDeep",value:function(){return this.invokeDeep("select")}},{key:"selected",value:function(e){return k.call(this,"selected",e)}},{key:"shift",value:function(e){var t=r(u(s.prototype),"shift",this).call(this,e);return this.indicesDirty=!0,this.calculateRenderablePositions(),t}},{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;if(e=e||this._tree.config.sort){this.batch();var n=c.sortBy(this,e);this.length=0,c.each(n,function(e){t.push(e)}),this.indicesDirty=!0,this.end()}return 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=r(u(s.prototype),"splice",this).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 c.each(this,function(e){t.push(e.toObject())}),t}},{key:"unshift",value:function(e){var t=r(u(s.prototype),"unshift",this).call(this,e);return this.indicesDirty=!0,this.calculateRenderablePositions(),t}},{key:"visible",value:function(e){return k.call(this,"visible",e)}}]),s}();function _(e,t){var n;return e instanceof g?c.each(e,function(e){return n=_(e,t)}):e instanceof w&&!1!==(n=t(e))&&e.hasChildren()&&(n=_(e.children,t)),n}function m(n){return new f(function(e,t){if(!c.isObject(n))return t(new Error("Invalid Promise"));c.isFunction(n.then)&&n.then(e),c.isFunction(n.error)?n.error(t):c.isFunction(n.catch)&&n.catch(t)})}function b(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}for(var w=function(){function r(e,t,n){var i=this;a(this,r),this._tree=e,t instanceof r&&((n=c.castArray(n)).push("_tree"),c.each(t,function(e,t){c.includes(n,t)||(c.isObject(e)?i[t]=e instanceof g?e.clone():"itree"===t?function(e,n){var i={};return(n=c.castArray(n)).push("ref"),c.each(e,function(e,t){c.includes(n,t)||(i[t]=c.cloneDeep(e))}),i}(e):c.cloneDeep(e):i[t]=e)}))}return e(r,[{key:"addChild",value:function(e){return!c.isArray(this.children)&&c.isArrayLike(this.children)||(this.children=new g(this._tree),this.children._context=this),this.children.addNode(e)}},{key:"addChildren",value:function(e){var t=this,n=new g(this._tree);return!c.isArray(this.children)&&c.isArrayLike(this.children)||(this.children=new g(this._tree),this.children._context=this),this.children.batch(),c.each(e,function(e){n.push(t.addChild(e))}),this.children.end(),n}},{key:"allowDynamicLoad",value:function(){return this._tree.isDynamic&&(c.isArrayLike(this.children)||!0===this.children)}},{key:"assign",value:function(){return c.assign.apply(c,[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.state("editing",!1),o("focused",!1,"blurred",this)}},{key:"check",value:function(e){return this._tree.batch(),o("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){if(e.hasParent()){var t=e.getParent();t.hasVisibleChildren()||t.hide()}}),this}},{key:"clone",value:function(e){return new r(this._tree,this,e)}},{key:"collapse",value:function(){return o("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){if(!e||!c.isFunction(e.addNode))throw new Error("Destination must be an Inspire Tree instance.");var i=this;return t&&(i=i.copyHierarchy(!1,n)),e.addNode(c.cloneDeep(i.toObject(!1,n)))}},{key:"copyHierarchy",value:function(t,n){var i=[],e=this.getParents();if(c.each(e,function(e){i.push(e.toObject(t,n))}),e=i.reverse(),!t){var r=this.toObject(!0,n);this.hasChildren()&&(r.children=this.children.filterBy(function(e){return!e.state("hidden")}).toArray(),r.children._context=r),i.push(r)}var s=i[0],o=i.length,a=s;return c.each(i,function(e,t){var n=[];t+1<o&&(n.push(i[t+1]),a.children=n,a=a.children[0])}),C(this._tree,s)}},{key:"deselect",value:function(e){this.selected()&&(!this._tree.config.selection.require||1<this._tree.selected().length)&&(this.context().batch(),o("selected",!1,"deselected",this,!e&&this._tree.config.selection.autoSelectChildren),this.context().end());return 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 f(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 g(this._tree)}},{key:"getParent",value:function(){return this.itree.parent}},{key:"getParents",value:function(){var t=new g(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 c.isArrayLike(this.children)&&0<this.children.length}},{key:"hasLoadedChildren",value:function(){return c.isArrayLike(this.children)}},{key:"hasOrWillHaveChildren",value:function(){return c.isArrayLike(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 this.hasChildren()&&(e=0<this.children.filterBy("available").length),e}},{key:"hide",value:function(){var e=o("hidden",!0,"hidden",this);return e.hasChildren()&&e.children.hide(),e}},{key:"hidden",value:function(){return this.state("hidden")}},{key:"indexPath",value:function(){var t=[];return this.recurseUp(function(e){t.push(c.indexOf(e.context(),e))}),t.reverse().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;if(this.hasChildren()&&!this.collapsed()){var t=(e=c.findLast(this.children,function(e){return e.visible()})).lastDeepestVisibleChild();t&&(e=t)}return e}},{key:"loadChildren",value:function(){var o=this;return new f(function(i,r){if(!o.allowDynamicLoad())return r(new Error("Node does not have or support dynamic children."));o.state("loading",!0),o.markDirty(),o.context().applyChanges();function e(e,t){if(!c.isArrayLike(e))return r(new TypeError("Loader requires an array-like `nodes` parameter."));o.context().batch(),o.state("loading",!1);var n=S(o._tree,e,o);c.isArrayLike(o.children)?o.children=o.children.concat(n):o.children=n,c.parseInt(t)>e.length&&(o.children._pagination.total=c.parseInt(t)),"checkbox"===o._tree.config.selection.mode&&o.selected()&&o.children.select(),o.markDirty(),o.context().end(),i(o.children),o._tree.emit("children.loaded",o)}function t(e){o.state("loading",!1),o.children=new g(o._tree),(o.children._context=o).markDirty(),o.context().applyChanges(),r(e),o._tree.emit("tree.loaderror",e)}var n=o._tree.constructor.isTreeNodes(o.children)?o.children.pagination():null,s=o._tree.config.data(o,e,t,n);c.isObject(s)&&m(s).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():f.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;if(this.hasParent()){var t=this.getParent();e=(e=t.nextVisibleSiblingNode())||t.nextVisibleAncestralSiblingNode()}return e}},{key:"nextVisibleChildNode",value:function(){var e;return this.hasChildren()&&(e=c.find(this.children,function(e){return e.visible()})),e}},{key:"nextVisibleNode",value:function(){return this.nextVisibleChildNode()||this.nextVisibleSiblingNode()||this.nextVisibleAncestralSiblingNode()}},{key:"nextVisibleSiblingNode",value:function(){var e=this.hasParent()?this.getParent().children:this._tree.nodes(),t=c.findIndex(e,{id:this.id});return c.find(c.slice(e,t+1),function(e){return e.visible()})}},{key:"pagination",value:function(){return c.get(this,"children._pagination")}},{key:"previousVisibleNode",value:function(){var e;return(e=this.previousVisibleSiblingNode())&&e.hasChildren()&&!e.collapsed()&&(e=e.lastDeepestVisibleChild()),!e&&this.hasParent()&&(e=this.getParent()),e}},{key:"previousVisibleSiblingNode",value:function(){var e=this.hasParent()?this.getParent().children:this._tree.nodes(),t=c.findIndex(e,{id:this.id});return c.findLast(c.slice(e,0,t),function(e){return e.visible()})}},{key:"recurseDown",value:function(e){return _(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=this.indeterminate();if(this.state("indeterminate",!1),this.hasChildren()){var t=this.children.length,n=0,i=0;this.children.each(function(e){e.checked()&&i++,e.indeterminate()&&n++}),i===t?o("checked",!0,"checked",this):o("checked",!1,"unchecked",this),this.checked()||this.state("indeterminate",0<n||0<t&&0<i&&i<t)}return this.hasParent()&&this.getParent().refreshIndeterminateState(),e!==this.state("indeterminate")&&this.markDirty(),this}},{key:"reload",value:function(){var n=this;return new f(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(e){var t=0<arguments.length&&void 0!==e&&e,n=this.getParent();this.context().remove(this),n&&(n.refreshIndeterminateState(),n.markDirty()),(n?n.pagination():this._tree.pagination()).total--;var i=this.toObject(!1,t);return this._tree.emit("node.removed",i,n),this.context().applyChanges(),i}},{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 o("removed",!1,"restored",this)}},{key:"select",value:function(e){if(!this.selected()&&this.selectable()){if(this._tree.batch(),this._tree.canAutoDeselect()){var t=this._tree.config.selection.require;this._tree.config.selection.require=!1,this._tree.deselectDeep(),this._tree.config.selection.require=t}o("selected",!0,"selected",this,!e&&this._tree.config.selection.autoSelectChildren),(this._tree._lastSelectedNode=this).markDirty(),this._tree.end()}return 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 o("hidden",!1,"shown",this)}},{key:"softRemove",value:function(){return o("removed",!0,"softremoved",this,"softRemove")}},{key:"state",value:function(e,t){var n=this;if(c.isString(e))return b(this,e,t);this.context().batch();var i={};return c.each(e,function(e,t){i[t]=b(n,t,e)}),this.context().end(),i}},{key:"states",value:function(e,t){var n=this,i=[];return this.context().batch(),c.each(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(e,t){var n=this,i=0<arguments.length&&void 0!==e&&e,r=1<arguments.length&&void 0!==t&&t,s={},o=c.pull(Object.keys(this),"_tree","children","itree");c.each(o,function(e){s[e]=n[e]});var a=s.itree={};return a.a=this.itree.a,a.icon=this.itree.icon,a.li=this.itree.li,r&&(a.state=this.itree.state),!i&&this.hasChildren()&&c.isFunction(this.children.toArray)&&(s.children=this.children.toArray()),s}},{key:"toString",value:function(){return this.text}},{key:"tree",value:function(){return this.context().tree()}},{key:"uncheck",value:function(e){return this._tree.batch(),o("checked",!1,"unchecked",this,!e&&this._tree.config.checkbox.autoCheckChildren),this.state("indeterminate",!1),this.hasParent()&&this.getParent().refreshIndeterminateState(),this._tree.end(),this}},{key:"visible",value:function(){return!(this.hidden()||this.removed()||this._tree.usesNativeDOM&&!this.rendered())&&(!this.hasParent()||!this.getParent().collapsed()&&this.getParent().visible())}}]),r}(),x=d(function(e){var t="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof window.msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto);if(t){var n=new Uint8Array(16);e.exports=function(){return t(n),n}}else{var i=new Array(16);e.exports=function(){for(var e,t=0;t<16;t++)0==(3&t)&&(e=4294967296*Math.random()),i[t]=e>>>((3&t)<<3)&255;return i}}}),D=[],A=0;A<256;++A)D[A]=(A+256).toString(16).substr(1);var L=function(e,t){var n=t||0,i=D;return[i[e[n++]],i[e[n++]],i[e[n++]],i[e[n++]],"-",i[e[n++]],i[e[n++]],"-",i[e[n++]],i[e[n++]],"-",i[e[n++]],i[e[n++]],"-",i[e[n++]],i[e[n++]],i[e[n++]],i[e[n++]],i[e[n++]],i[e[n++]]].join("")};var P=function(e,t,n){var i=t&&n||0;"string"==typeof e&&(t="binary"===e?new Array(16):null,e=null);var r=(e=e||{}).random||(e.rng||x)();if(r[6]=15&r[6]|64,r[8]=63&r[8]|128,t)for(var s=0;s<16;++s)t[i+s]=r[s];return t||L(r)};function C(t,n,e){n.id=n.id||P(),"string"!=typeof n.id&&"number"!=typeof n.id&&(n.id=n.id.toString());var i=n.itree=n.itree||{};i.icon=i.icon||!1,i.dirty=!1;var r=i.li=i.li||{};r.attributes=r.attributes||{};var s=i.a=i.a||{};s.attributes=s.attributes||{};var o=i.state=i.state||{};return o.collapsed="boolean"==typeof o.collapsed?o.collapsed:t.defaultState.collapsed,o.selectable="boolean"==typeof o.selectable?o.selectable:t.defaultState.selectable,o.draggable="boolean"==typeof o.draggable?o.draggable:t.defaultState.draggable,o["drop-target"]="boolean"==typeof o["drop-target"]?o["drop-target"]:t.defaultState["drop-target"],o.checked="boolean"==typeof o.checked&&o.checked,o.editable="boolean"==typeof o.editable?o.editable:t.defaultState.editable,o.editing="boolean"==typeof o.editing?o.editing:t.defaultState.editing,o.focused=o.focused||t.defaultState.focused,o.hidden=o.hidden||t.defaultState.hidden,o.indeterminate=o.indeterminate||t.defaultState.indeterminate,o.loading=o.loading||t.defaultState.loading,o.removed=o.removed||t.defaultState.removed,o.rendered=o.rendered||t.defaultState.rendered,o.selected=o.selected||t.defaultState.selected,n.itree.parent=e,n=c.assign(new w(t),n),c.isArrayLike(n.children)&&(n.children=S(t,n.children,n)),t.allowsLoadEvents&&c.each(t.config.allowLoadEvents,function(e){o[e]&&t.emit("node."+e,n,!0)}),n}function S(t,e,n){var i=new g(t,null,{calculateRenderablePositions:!0});return i.batch(),t.config.sort&&(e=c.sortBy(e,t.config.sort)),c.each(e,function(e){i.push(C(t,e,n))}),i._context=n,i.end(),i}var O=d(function(e,t){function u(){this._events={},this._conf&&n.call(this,this._conf)}function n(e){e?((this._conf=e).delimiter&&(this.delimiter=e.delimiter),this._maxListeners=e.maxListeners!==l?e.maxListeners:r,e.wildcard&&(this.wildcard=e.wildcard),e.newListener&&(this._newListener=e.newListener),e.removeListener&&(this._removeListener=e.removeListener),e.verboseMemoryLeak&&(this.verboseMemoryLeak=e.verboseMemoryLeak),this.wildcard&&(this.listenerTree={})):this._maxListeners=r}function o(e,t){var n="(node) warning: possible EventEmitter memory leak detected. "+e+" listeners added. Use emitter.setMaxListeners() to increase limit.";if(this.verboseMemoryLeak&&(n+=" Event name: "+t+"."),"undefined"!=typeof process&&process.emitWarning){var i=new Error(n);i.name="MaxListenersExceededWarning",i.emitter=this,i.count=e,process.emitWarning(i)}else console.error(n),console.trace&&console.trace()}function i(e){this._events={},this._newListener=!1,this._removeListener=!1,this.verboseMemoryLeak=!1,n.call(this,e)}function y(e,t,n,i){if(!n)return[];var r,s,o,a,c,u,l,h=[],d=t.length,f=t[i],v=t[i+1];if(i===d&&n._listeners){if("function"==typeof n._listeners)return e&&e.push(n._listeners),[n];for(r=0,s=n._listeners.length;r<s;r++)e&&e.push(n._listeners[r]);return[n]}if("*"===f||"**"===f||n[f]){if("*"===f){for(o in n)"_listeners"!==o&&n.hasOwnProperty(o)&&(h=h.concat(y(e,t,n[o],i+1)));return h}if("**"===f){for(o in(l=i+1===d||i+2===d&&"*"===v)&&n._listeners&&(h=h.concat(y(e,t,n,d))),n)"_listeners"!==o&&n.hasOwnProperty(o)&&(h="*"===o||"**"===o?(n[o]._listeners&&!l&&(h=h.concat(y(e,t,n[o],d))),h.concat(y(e,t,n[o],i))):o===v?h.concat(y(e,t,n[o],i+2)):h.concat(y(e,t,n[o],i)));return h}h=h.concat(y(e,t,n[f],i+1))}if((a=n["*"])&&y(e,t,a,i+1),c=n["**"])if(i<d)for(o in c._listeners&&y(e,t,c,d),c)"_listeners"!==o&&c.hasOwnProperty(o)&&(o===v?y(e,t,c[o],i+2):o===f?y(e,t,c[o],i+1):((u={})[o]=c[o],y(e,t,{"**":u},i+1)));else c._listeners?y(e,t,c,d):c["*"]&&c["*"]._listeners&&y(e,t,c["*"],d);return h}var l,h,r;h=Array.isArray?Array.isArray:function(e){return"[object Array]"===Object.prototype.toString.call(e)},r=10,(i.EventEmitter2=i).prototype.delimiter=".",i.prototype.setMaxListeners=function(e){e!==l&&(this._maxListeners=e,this._conf||(this._conf={}),this._conf.maxListeners=e)},i.prototype.event="",i.prototype.once=function(e,t){return this._once(e,t,!1)},i.prototype.prependOnceListener=function(e,t){return this._once(e,t,!0)},i.prototype._once=function(e,t,n){return this._many(e,1,t,n),this},i.prototype.many=function(e,t,n){return this._many(e,t,n,!1)},i.prototype.prependMany=function(e,t,n){return this._many(e,t,n,!0)},i.prototype._many=function(e,t,n,i){var r=this;if("function"!=typeof n)throw new Error("many only accepts instances of Function");function s(){return 0==--t&&r.off(e,s),n.apply(this,arguments)}return s._origin=n,this._on(e,s,i),r},i.prototype.emit=function(){this._events||u.call(this);var e=arguments[0];if("newListener"===e&&!this._newListener&&!this._events.newListener)return!1;var t,n,i,r,s,o=arguments.length;if(this._all&&this._all.length){if(s=this._all.slice(),3<o)for(t=new Array(o),r=0;r<o;r++)t[r]=arguments[r];for(i=0,n=s.length;i<n;i++)switch(this.event=e,o){case 1:s[i].call(this,e);break;case 2:s[i].call(this,e,arguments[1]);break;case 3:s[i].call(this,e,arguments[1],arguments[2]);break;default:s[i].apply(this,t)}}if(this.wildcard){s=[];var a="string"==typeof e?e.split(this.delimiter):e.slice();y.call(this,s,a,this.listenerTree,0)}else{if("function"==typeof(s=this._events[e])){switch(this.event=e,o){case 1:s.call(this);break;case 2:s.call(this,arguments[1]);break;case 3:s.call(this,arguments[1],arguments[2]);break;default:for(t=new Array(o-1),r=1;r<o;r++)t[r-1]=arguments[r];s.apply(this,t)}return!0}s=s&&s.slice()}if(s&&s.length){if(3<o)for(t=new Array(o-1),r=1;r<o;r++)t[r-1]=arguments[r];for(i=0,n=s.length;i<n;i++)switch(this.event=e,o){case 1:s[i].call(this);break;case 2:s[i].call(this,arguments[1]);break;case 3:s[i].call(this,arguments[1],arguments[2]);break;default:s[i].apply(this,t)}return!0}if(!this._all&&"error"===e)throw arguments[1]instanceof Error?arguments[1]:new Error("Uncaught, unspecified 'error' event.");return!!this._all},i.prototype.emitAsync=function(){this._events||u.call(this);var e=arguments[0];if("newListener"===e&&!this._newListener&&!this._events.newListener)return Promise.resolve([!1]);var t,n,i,r,s,o=[],a=arguments.length;if(this._all){if(3<a)for(t=new Array(a),r=1;r<a;r++)t[r]=arguments[r];for(i=0,n=this._all.length;i<n;i++)switch(this.event=e,a){case 1:o.push(this._all[i].call(this,e));break;case 2:o.push(this._all[i].call(this,e,arguments[1]));break;case 3:o.push(this._all[i].call(this,e,arguments[1],arguments[2]));break;default:o.push(this._all[i].apply(this,t))}}if(this.wildcard){s=[];var c="string"==typeof e?e.split(this.delimiter):e.slice();y.call(this,s,c,this.listenerTree,0)}else s=this._events[e];if("function"==typeof s)switch(this.event=e,a){case 1:o.push(s.call(this));break;case 2:o.push(s.call(this,arguments[1]));break;case 3:o.push(s.call(this,arguments[1],arguments[2]));break;default:for(t=new Array(a-1),r=1;r<a;r++)t[r-1]=arguments[r];o.push(s.apply(this,t))}else if(s&&s.length){if(s=s.slice(),3<a)for(t=new Array(a-1),r=1;r<a;r++)t[r-1]=arguments[r];for(i=0,n=s.length;i<n;i++)switch(this.event=e,a){case 1:o.push(s[i].call(this));break;case 2:o.push(s[i].call(this,arguments[1]));break;case 3:o.push(s[i].call(this,arguments[1],arguments[2]));break;default:o.push(s[i].apply(this,t))}}else if(!this._all&&"error"===e)return arguments[1]instanceof Error?Promise.reject(arguments[1]):Promise.reject("Uncaught, unspecified 'error' event.");return Promise.all(o)},i.prototype.on=function(e,t){return this._on(e,t,!1)},i.prototype.prependListener=function(e,t){return this._on(e,t,!0)},i.prototype.onAny=function(e){return this._onAny(e,!1)},i.prototype.prependAny=function(e){return this._onAny(e,!0)},i.prototype.addListener=i.prototype.on,i.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},i.prototype._on=function(e,t,n){if("function"==typeof e)return this._onAny(e,t),this;if("function"!=typeof t)throw new Error("on only accepts instances of Function");return this._events||u.call(this),this._newListener&&this.emit("newListener",e,t),this.wildcard?function(e,t){for(var n=0,i=(e="string"==typeof e?e.split(this.delimiter):e.slice()).length;n+1<i;n++)if("**"===e[n]&&"**"===e[n+1])return;for(var r=this.listenerTree,s=e.shift();s!==l;){if(r[s]||(r[s]={}),r=r[s],0===e.length)return r._listeners?("function"==typeof r._listeners&&(r._listeners=[r._listeners]),r._listeners.push(t),!r._listeners.warned&&0<this._maxListeners&&r._listeners.length>this._maxListeners&&(r._listeners.warned=!0,o.call(this,r._listeners.length,s))):r._listeners=t,!0;s=e.shift()}return!0}.call(this,e,t):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,o.call(this,this._events[e].length,e))):this._events[e]=t,this},i.prototype.off=function(e,t){if("function"!=typeof t)throw new Error("removeListener only takes instances of Function");var n,i=[];if(this.wildcard){var r="string"==typeof e?e.split(this.delimiter):e.slice();i=y.call(this,null,r,this.listenerTree,0)}else{if(!this._events[e])return this;n=this._events[e],i.push({_listeners:n})}for(var s=0;s<i.length;s++){var o=i[s];if(n=o._listeners,h(n)){for(var a=-1,c=0,u=n.length;c<u;c++)if(n[c]===t||n[c].listener&&n[c].listener===t||n[c]._origin&&n[c]._origin===t){a=c;break}if(a<0)continue;return this.wildcard?o._listeners.splice(a,1):this._events[e].splice(a,1),0===n.length&&(this.wildcard?delete o._listeners:delete this._events[e]),this._removeListener&&this.emit("removeListener",e,t),this}(n===t||n.listener&&n.listener===t||n._origin&&n._origin===t)&&(this.wildcard?delete o._listeners:delete this._events[e],this._removeListener&&this.emit("removeListener",e,t))}return function e(t){if(t!==l){var n=Object.keys(t);for(var i in n){var r=n[i],s=t[r];s instanceof Function||"object"!=typeof s||null===s||(0<Object.keys(s).length&&e(t[r]),0===Object.keys(s).length&&delete t[r])}}}(this.listenerTree),this},i.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},i.prototype.removeListener=i.prototype.off,i.prototype.removeAllListeners=function(e){if(e===l)return this._events&&u.call(this),this;if(this.wildcard)for(var t="string"==typeof e?e.split(this.delimiter):e.slice(),n=y.call(this,null,t,this.listenerTree,0),i=0;i<n.length;i++)n[i]._listeners=null;else this._events&&(this._events[e]=null);return this},i.prototype.listeners=function(e){if(this.wildcard){var t=[],n="string"==typeof e?e.split(this.delimiter):e.slice();return y.call(this,t,n,this.listenerTree,0),t}return this._events||u.call(this),this._events[e]||(this._events[e]=[]),h(this._events[e])||(this._events[e]=[this._events[e]]),this._events[e]},i.prototype.eventNames=function(){return Object.keys(this._events)},i.prototype.listenerCount=function(e){return this.listeners(e).length},i.prototype.listenersAny=function(){return this._all?this._all:[]},"function"==typeof l&&l.amd?l(function(){return i}):e.exports=i}).EventEmitter2;function N(e,t,n){return e.model[t].apply(e.model,n)}return function(){function o(e){var r;a(this,o),(r=h(this,u(o).call(this)))._lastSelectedNode,r._muted=!1,r.allowsLoadEvents=!1,r.id=P(),r.initialized=!1,r.isDynamic=!1,r.opts=e,r.preventDeselection=!1,r.config=c.defaultsDeep({},e,{allowLoadEvents:[],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:c.noop,autoDeselect:!0,autoSelectChildren:!1,disableDirectDeselection:!1,mode:"default",multiple:!1,require:!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),c.isFunction(e.search)&&(r.config.search={matcher:e.search,matchProcessor:!1}),r.defaultState={collapsed:!0,editable:c.get(l(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=c.isArray(r.config.allowLoadEvents)&&0<r.config.allowLoadEvents.length,r.isDynamic=c.isFunction(r.config.data);var s=r.emit;return r.emit=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];if(!r.isEventMuted(t[0])){if(c.isFunction(c.get(t,"[0].preventDefault"))){var i=t[0];i.treeDefaultPrevented=!1,i.preventTreeDefault=function(){i.treeDefaultPrevented=!0}}s.apply(l(r),t)}},r.model=new g(l(r)),r.config.data&&r.load(r.config.data),r.initialized=!0,r}return t(o,O),e(o,[{key:"addNode",value:function(){return N(this,"addNode",arguments)}},{key:"addNodes",value:function(e){var t=this;this.batch();var n=new g(this);return c.each(e,function(e){return n.push(t.addNode(e))}),this.end(),n}},{key:"applyChanges",value:function(){return this.model.applyChanges()}},{key:"available",value:function(){return N(this,"available",arguments)}},{key:"batch",value:function(){return this.model.batch()}},{key:"blur",value:function(){return N(this,"blur",arguments)}},{key:"blurDeep",value:function(){return N(this,"blurDeep",arguments)}},{key:"boundingNodes",value:function(){var e=c.transform(arguments,function(e,t){e[t.indexPath().replace(/\./g,"")]=t},{}),t=s(c.sortBy(Object.keys(e))),n=t[0],i=t.slice(1);return[c.get(e,n),c.get(e,i)]}},{key:"canAutoDeselect",value:function(){return this.config.selection.autoDeselect&&!this.preventDeselection}},{key:"checked",value:function(){return N(this,"checked",arguments)}},{key:"clean",value:function(){return N(this,"clean",arguments)}},{key:"clearSearch",value:function(){return this.batch(),this.recurseDown(function(e){e.show().collapse().state("matched",!1)}),this.end(),this}},{key:"clone",value:function(){return N(this,"clone",arguments)}},{key:"collapse",value:function(){return N(this,"collapse",arguments)}},{key:"collapsed",value:function(){return N(this,"collapsed",arguments)}},{key:"collapseDeep",value:function(){return N(this,"collapseDeep",arguments)}},{key:"concat",value:function(){return N(this,"concat",arguments)}},{key:"copy",value:function(){return N(this,"copy",arguments)}},{key:"createNode",value:function(e){return o.isTreeNode(e)?e:C(this,e)}},{key:"deepest",value:function(){return N(this,"deepest",arguments)}},{key:"deselect",value:function(){return N(this,"deselect",arguments)}},{key:"deselectDeep",value:function(){return N(this,"deselectDeep",arguments)}},{key:"disableDeselection",value:function(){return this.config.selection.multiple&&(this.preventDeselection=!0),this}},{key:"each",value:function(){return N(this,"each",arguments)}},{key:"editable",value:function(){return N(this,"editable",arguments)}},{key:"editing",value:function(){return N(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 N(this,"every",arguments)}},{key:"expand",value:function(){return N(this,"expand",arguments)}},{key:"expandDeep",value:function(){return N(this,"expandDeep",arguments)}},{key:"expanded",value:function(){return N(this,"expanded",arguments)}},{key:"extract",value:function(){return N(this,"extract",arguments)}},{key:"filter",value:function(){return N(this,"filter",arguments)}},{key:"filterBy",value:function(){return N(this,"filterBy",arguments)}},{key:"find",value:function(){return N(this,"find",arguments)}},{key:"first",value:function(){return N(this,"first",arguments)}},{key:"flatten",value:function(){return N(this,"flatten",arguments)}},{key:"focused",value:function(){return N(this,"focused",arguments)}},{key:"forEach",value:function(){return N(this,"each",arguments)}},{key:"get",value:function(){return N(this,"get",arguments)}},{key:"hidden",value:function(){return N(this,"hidden",arguments)}},{key:"hide",value:function(){return N(this,"hide",arguments)}},{key:"hideDeep",value:function(){return N(this,"hideDeep",arguments)}},{key:"indeterminate",value:function(){return N(this,"indeterminate",arguments)}},{key:"indexOf",value:function(){return N(this,"indexOf",arguments)}},{key:"insertAt",value:function(){return N(this,"insertAt",arguments)}},{key:"invoke",value:function(){return N(this,"invoke",arguments)}},{key:"invokeDeep",value:function(){return N(this,"invokeDeep",arguments)}},{key:"isEventMuted",value:function(e){return c.isBoolean(this.muted())?this.muted():c.includes(this.muted(),e)}},{key:"isTree",value:function(e){return e instanceof o}},{key:"join",value:function(){return N(this,"join",arguments)}},{key:"last",value:function(){return N(this,"last",arguments)}},{key:"lastSelectedNode",value:function(){return this._lastSelectedNode}},{key:"load",value:function(n){var o=this,e=new f(function(r,s){function e(e,t){if(!c.isArrayLike(e))return s(new TypeError("Loader requires an array-like `nodes` parameter."));!o.initialized&&c.isArrayLike(e)?setTimeout(function(){o.emit("data.loaded",e)}):o.emit("data.loaded",e);var n=S(o,e);function i(){o.emit("model.loaded",o.model),r(o.model),o.model.applyChanges()}o.config.deferredLoading?o.model=o.model.concat(n):o.model=n,o.model._pagination.total=e.length,c.parseInt(t)>e.length&&(o.model._pagination.total=c.parseInt(t)),t||o.model.recurseDown(function(e){e.hasChildren()&&(e.children._pagination.total=e.children.length)}),o.config.selection.require&&!o.selected().length&&o.selectFirstAvailableNode(),!o.initialized&&c.isArray(e)?setTimeout(i):i()}if(c.isArrayLike(n))e(n);else if(c.isFunction(n)){var t=n(null,e,s,o.pagination());t&&(n=t)}c.isObject(n)?m(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 N(this,"loading",arguments)}},{key:"loadMore",value:function(){return N(this,"loadMore",arguments)}},{key:"map",value:function(){return N(this,"map",arguments)}},{key:"matched",value:function(){return N(this,"matched",arguments)}},{key:"move",value:function(){return N(this,"move",arguments)}},{key:"mute",value:function(e){return c.isString(e)||c.isArray(e)?this._muted=c.castArray(e):this._muted=!0,this}},{key:"muted",value:function(){return this._muted}},{key:"node",value:function(){return N(this,"node",arguments)}},{key:"nodes",value:function(){return N(this,"nodes",arguments)}},{key:"pagination",value:function(){return N(this,"pagination",arguments)}},{key:"pop",value:function(){return N(this,"pop",arguments)}},{key:"push",value:function(){return N(this,"push",arguments)}},{key:"recurseDown",value:function(){return N(this,"recurseDown",arguments)}},{key:"reduce",value:function(){return N(this,"reduce",arguments)}},{key:"reduceRight",value:function(){return N(this,"reduceRight",arguments)}},{key:"reload",value:function(){return this.reset(),this.load(this.opts.data||this.config.data)}},{key:"remove",value:function(){return N(this,"remove",arguments)}},{key:"removeAll",value:function(){return this.reset().applyChanges(),this}},{key:"removed",value:function(){return N(this,"removed",arguments)}},{key:"reset",value:function(){return this.model=new g(this),this}},{key:"restore",value:function(){return N(this,"restore",arguments)}},{key:"restoreDeep",value:function(){return N(this,"restoreDeep",arguments)}},{key:"reverse",value:function(){return N(this,"reverse",arguments)}},{key:"search",value:function(n){var r=this,e=this.config.search,i=e.matcher,s=e.matchProcessor;return!n||c.isString(n)&&c.isEmpty(n)?f.resolve(this.clearSearch()):(this.batch(),this.recurseDown(function(e){e.state("hidden",!0),e.state("matched",!1)}),this.end(),i=c.isFunction(i)?i:function(t,e){var n,i=new g(r);c.isString(t)&&(t=new RegExp(t,"i")),n=c.isRegExp(t)?function(e){return t.test(e.text)}:t,r.model.recurseDown(function(e){e.removed()||n(e)&&i.push(e)}),e(i)},s=c.isFunction(s)?s:function(e){e.each(function(e){e.show().state("matched",!0),e.expandParents().collapse(),e.hasChildren()&&e.children.showDeep()})},new f(function(t,e){i(n,function(e){o.isTreeNodes(e)||(e=r.nodes(c.map(e,"id"))),r.batch(),s(e),r.end(),t(e)},e)}))}},{key:"select",value:function(){return N(this,"select",arguments)}},{key:"selectable",value:function(){return N(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 N(this,"selectDeep",arguments)}},{key:"selected",value:function(){return N(this,"selected",arguments)}},{key:"selectFirstAvailableNode",value:function(){var e=this.model.filterBy("available").get(0);return e&&e.select(),e}},{key:"shift",value:function(){return N(this,"shift",arguments)}},{key:"show",value:function(){return N(this,"show",arguments)}},{key:"showDeep",value:function(){return N(this,"showDeep",arguments)}},{key:"slice",value:function(){return N(this,"slice",arguments)}},{key:"softRemove",value:function(){return N(this,"softRemove",arguments)}},{key:"some",value:function(){return N(this,"some",arguments)}},{key:"sort",value:function(){return N(this,"sort",arguments)}},{key:"sortBy",value:function(){return N(this,"sortBy",arguments)}},{key:"sortDeep",value:function(){return N(this,"sortDeep",arguments)}},{key:"splice",value:function(){return N(this,"slice",arguments)}},{key:"state",value:function(){return N(this,"state",arguments)}},{key:"stateDeep",value:function(){return N(this,"stateDeep",arguments)}},{key:"swap",value:function(){return N(this,"swap",arguments)}},{key:"toArray",value:function(){return N(this,"toArray",arguments)}},{key:"toString",value:function(){return N(this,"toString",arguments)}},{key:"unmute",value:function(e){return c.isString(e)||c.isArray(e)?(this._muted=c.difference(this._muted,c.castArray(e)),this._muted.length||(this._muted=!1)):this._muted=!1,this}},{key:"unshift",value:function(){return N(this,"unshift",arguments)}},{key:"visible",value:function(){return N(this,"visible",arguments)}}],[{key:"isTreeNode",value:function(e){return e instanceof w}},{key:"isTreeNodes",value:function(e){return e instanceof g}}]),o}()});
  