pipicar/public/lib/inspire-tree/js/inspire-tree.js

2 lines
89 KiB
JavaScript

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("lodash")):"function"==typeof define&&define.amd?define(["lodash"],t):e.InspireTree=t(e._)}(this,(function(e){"use strict";function t(){throw new Error("Dynamic requires are not currently supported by rollup-plugin-commonjs")}function n(e,t){return e(t={exports:{}},t.exports),t.exports}function i(t){return e.each(t._tree.defaultState,(function(e,n){t.state(n,e)})),t}function r(e,t,n,o,s){return o.state(e)!==t&&(o._tree.batch(),o._tree.config.nodes.resetStateOnRestore&&"restored"===n&&i(o),o.state(e,t),o._tree.emit("node."+n,o,!1),s&&o.hasChildren()&&o.children.recurseDown((function(i){r(e,t,n,i)})),o.markDirty(),o._tree.end()),o}function o(e,t){if(t)return this.extract(e);var n=a(e);return this.flatten((function(t){return("removed"===e||!t.removed())&&n(t)}))}function s(t,n,i,r){return n=e.castArray(n),t._tree.batch(),t[r?"recurseDown":"each"]((function(t){e.each(n,(function(n){e.isFunction(t[n])&&t[n].apply(t,i)}))})),t._tree.end(),t}function a(t){var n=t;return e.isString(t)&&(n=function(n){return e.isFunction(n[t])?n[t]():n[t]}),n}function l(t,n){var i=void 0;return t instanceof x?e.each(t,(function(e){return i=l(e,n)})):t instanceof C&&!1!==(i=n(t))&&t.hasChildren()&&(i=l(t.children,n)),i}function c(t){return new k((function(n,i){if(!e.isObject(t))return i(new Error("Invalid Promise"));e.isFunction(t.then)&&t.then(n),e.isFunction(t.error)?t.error(i):e.isFunction(t.catch)&&t.catch(i)}))}function u(t,n,i){n.id=n.id||m(),"string"!=typeof n.id&&"number"!=typeof n.id&&(n.id=n.id.toString());var r=n.itree=n.itree||{};r.icon=r.icon||!1,r.dirty=!1;var o=r.li=r.li||{};o.attributes=o.attributes||{};var s=r.a=r.a||{};s.attributes=s.attributes||{};var a=r.state=r.state||{};return a.collapsed="boolean"==typeof a.collapsed?a.collapsed:t.defaultState.collapsed,a.selectable="boolean"==typeof a.selectable?a.selectable:t.defaultState.selectable,a.draggable="boolean"==typeof a.draggable?a.draggable:t.defaultState.draggable,a["drop-target"]="boolean"==typeof a["drop-target"]?a["drop-target"]:t.defaultState["drop-target"],a.checked="boolean"==typeof a.checked&&a.checked,a.editable="boolean"==typeof a.editable?a.editable:t.defaultState.editable,a.editing="boolean"==typeof a.editing?a.editing:t.defaultState.editing,a.focused=a.focused||t.defaultState.focused,a.hidden=a.hidden||t.defaultState.hidden,a.indeterminate=a.indeterminate||t.defaultState.indeterminate,a.loading=a.loading||t.defaultState.loading,a.removed=a.removed||t.defaultState.removed,a.rendered=a.rendered||t.defaultState.rendered,a.selected=a.selected||t.defaultState.selected,n.itree.parent=i,n=e.assign(new C(t),n),e.isArrayLike(n.children)&&(n.children=h(t,n.children,n)),t.allowsLoadEvents&&e.each(t.config.allowLoadEvents,(function(e){a[e]&&t.emit("node."+e,n,!0)})),n}function h(t,n,i){var r=new x(t);return t.config.sort&&(n=e.sortBy(n,t.config.sort)),e.each(n,(function(e){r.push(u(t,e,i))})),r._context=i,r}function d(e,t,n){return e.model[t].apply(e.model,n)}for(var f="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},p=n((function(e){var t="undefined"!=typeof crypto&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&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++)!(3&t)&&(e=4294967296*Math.random()),i[t]=e>>>((3&t)<<3)&255;return i}}})),v=[],y=0;y<256;++y)v[y]=(y+256).toString(16).substr(1);var g=function(e,t){var n=t||0,i=v;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++]]},m=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||p)();if(r[6]=15&r[6]|64,r[8]=63&r[8]|128,t)for(var o=0;o<16;++o)t[i+o]=r[o];return t||g(r)},k=n((function(e,n){e.exports=function(){function e(e){return"function"==typeof e}function n(){var e=setTimeout;return function(){return e(i,1)}}function i(){for(var e=0;e<_;e+=2)(0,A[e])(A[e+1]),A[e]=void 0,A[e+1]=void 0;_=0}function r(e,t){var n=this,i=new this.constructor(s);void 0===i[O]&&m(i);var r=n._state;if(r){var o=arguments[r-1];D((function(){return g(r,i,o,n._result)}))}else p(n,i,e,t);return i}function o(e){if(e&&"object"==typeof e&&e.constructor===this)return e;var t=new this(s);return c(t,e),t}function s(){}function a(e){try{return e.then}catch(e){return j.error=e,j}}function l(t,n,i){n.constructor===t.constructor&&i===r&&n.constructor.resolve===o?function(e,t){t._state===T?h(e,t._result):t._state===E?d(e,t._result):p(t,void 0,(function(t){return c(e,t)}),(function(t){return d(e,t)}))}(t,n):i===j?(d(t,j.error),j.error=null):void 0===i?h(t,n):e(i)?function(e,t,n){D((function(e){var i=!1,r=function(e,t,n,i){try{e.call(t,n,i)}catch(e){return e}}(n,t,(function(n){i||(i=!0,t!==n?c(e,n):h(e,n))}),(function(t){i||(i=!0,d(e,t))}),e._label);!i&&r&&(i=!0,d(e,r))}),e)}(t,n,i):h(t,n)}function c(e,t){e===t?d(e,new TypeError("You cannot resolve a promise with itself")):function(e){var t=typeof e;return null!==e&&("object"===t||"function"===t)}(t)?l(e,t,a(t)):h(e,t)}function u(e){e._onerror&&e._onerror(e._result),v(e)}function h(e,t){e._state===$&&(e._result=t,e._state=T,0!==e._subscribers.length&&D(v,e))}function d(e,t){e._state===$&&(e._state=E,e._result=t,D(u,e))}function p(e,t,n,i){var r=e._subscribers,o=r.length;e._onerror=null,r[o]=t,r[o+T]=n,r[o+E]=i,0===o&&e._state&&D(v,e)}function v(e){var t=e._subscribers,n=e._state;if(0!==t.length){for(var i=void 0,r=void 0,o=e._result,s=0;s<t.length;s+=3)i=t[s],r=t[s+n],i?g(n,i,r,o):r(o);e._subscribers.length=0}}function y(){this.error=null}function g(t,n,i,r){var o=e(i),s=void 0,a=void 0,l=void 0,u=void 0;if(o){if(s=function(e,t){try{return e(t)}catch(e){return M.error=e,M}}(i,r),s===M?(u=!0,a=s.error,s.error=null):l=!0,n===s)return void d(n,new TypeError("A promises callback cannot return that same promise."))}else s=r,l=!0;n._state!==$||(o&&l?c(n,s):u?d(n,a):t===T?h(n,s):t===E&&d(n,s))}function m(e){e[O]=F++,e._state=void 0,e._result=void 0,e._subscribers=[]}var k=Array.isArray?Array.isArray:function(e){return"[object Array]"===Object.prototype.toString.call(e)},_=0,b=void 0,w=void 0,D=function(e,t){A[_]=e,A[_+1]=t,2===(_+=2)&&(w?w(i):N())},x="undefined"!=typeof window?window:void 0,C=x||{},S=C.MutationObserver||C.WebKitMutationObserver,P="undefined"==typeof self&&"undefined"!=typeof process&&"[object process]"==={}.toString.call(process),L="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel,A=new Array(1e3),N=void 0;N=P?function(){return process.nextTick(i)}:S?function(){var e=0,t=new S(i),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=i,function(){return e.port2.postMessage(0)}}():void 0===x?function(){try{var e=t();return void 0!==(b=e.runOnLoop||e.runOnContext)?function(){b(i)}:n()}catch(e){return n()}}():n();var O=Math.random().toString(36).substring(16),$=void 0,T=1,E=2,j=new y,M=new y,F=0,U=function(){function e(e,t){this._instanceConstructor=e,this.promise=new e(s),this.promise[O]||m(this.promise),k(t)?(this.length=t.length,this._remaining=t.length,this._result=new Array(this.length),0===this.length?h(this.promise,this._result):(this.length=this.length||0,this._enumerate(t),0===this._remaining&&h(this.promise,this._result))):d(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(e,t){var n=this._instanceConstructor,i=n.resolve;if(i===o){var c=a(e);if(c===r&&e._state!==$)this._settledAt(e._state,t,e._result);else if("function"!=typeof c)this._remaining--,this._result[t]=e;else if(n===I){var u=new n(s);l(u,e,c),this._willSettleAt(u,t)}else this._willSettleAt(new n((function(t){return t(e)})),t)}else this._willSettleAt(i(e),t)},e.prototype._settledAt=function(e,t,n){var i=this.promise;i._state===$&&(this._remaining--,e===E?d(i,n):this._result[t]=n),0===this._remaining&&h(i,this._result)},e.prototype._willSettleAt=function(e,t){var n=this;p(e,void 0,(function(e){return n._settledAt(T,t,e)}),(function(e){return n._settledAt(E,t,e)}))},e}(),I=function(){function e(t){this[O]=F++,this._result=this._state=void 0,this._subscribers=[],s!==t&&("function"!=typeof t&&function(){throw new TypeError("You must pass a resolver function as the first argument to the promise constructor")}(),this instanceof e?function(e,t){try{t((function(t){c(e,t)}),(function(t){d(e,t)}))}catch(t){d(e,t)}}(this,t):function(){throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.")}())}return e.prototype.catch=function(e){return this.then(null,e)},e.prototype.finally=function(e){var t=this.constructor;return this.then((function(n){return t.resolve(e()).then((function(){return n}))}),(function(n){return t.resolve(e()).then((function(){throw n}))}))},e}();return I.prototype.then=r,I.all=function(e){return new U(this,e).promise},I.race=function(e){var t=this;return new t(k(e)?function(n,i){for(var r=e.length,o=0;o<r;o++)t.resolve(e[o]).then(n,i)}:function(e,t){return t(new TypeError("You must pass an array to race."))})},I.resolve=o,I.reject=function(e){var t=new this(s);return d(t,e),t},I._setScheduler=function(e){w=e},I._setAsap=function(e){D=e},I._asap=D,I.polyfill=function(){var e=void 0;if(void 0!==f)e=f;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=I},I.Promise=I,I}()})).Promise,_=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},b=function(){function e(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)}}return function(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}}(),w=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)},D=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t},x=function(t){function n(t,i){_(this,n);var r=D(this,(n.__proto__||Object.getPrototypeOf(n)).call(this));if(e.isFunction(e.get(t,"isTree"))&&!t.isTree(t))throw new TypeError("Invalid tree instance.");return r._tree=t,r.length=0,r._pagination={limit:t.config.pagination.limit,total:0},(e.isArray(i)||i instanceof n)&&e.each(i,(function(e){e instanceof C?r.push(e.clone()):r.addNode(e)})),r}return w(n,t),b(n,[{key:"addNode",value:function(t){var n=this.length;return this._tree.config.sort&&(n=e.sortedIndexBy(this,t,this._tree.config.sort)),this.insertAt(n,t)}},{key:"available",value:function(e){return o.call(this,"available",e)}},{key:"blur",value:function(){return this.invoke("blur")}},{key:"blurDeep",value:function(){return this.invokeDeep("blur")}},{key:"checked",value:function(e){return o.call(this,"checked",e)}},{key:"clean",value:function(){return this.invoke("clean")}},{key:"clone",value:function(){return new n(this._tree,this)}},{key:"collapse",value:function(){return this.invoke("collapse")}},{key:"collapsed",value:function(e){return o.call(this,"collapsed",e)}},{key:"collapseDeep",value:function(){return this.invokeDeep("collapse")}},{key:"concat",value:function(t){var i=new n(this._tree);i._context=this._context;var r=function(e){e instanceof C&&i.push(e)};return e.each(this,r),e.each(t,r),i._pagination.limit=this._pagination.limit,i}},{key:"context",value:function(){return this._context||this._tree}},{key:"copy",value:function(t){var i=this;return{to:function(r){if(!e.isFunction(r.addNodes))throw new Error("Destination must be an Inspire Tree instance.");var o=new n(i._tree);return e.each(i,(function(e){o.push(e.copy(t).to(r))})),o}}}},{key:"deepest",value:function(){var e=new n(this._tree);return this.recurseDown((function(t){t.children||e.push(t)})),e}},{key:"deselect",value:function(){return this.invoke("deselect")}},{key:"deselectDeep",value:function(){return this.invokeDeep("deselect")}},{key:"each",value:function(t){return e.each(this,t),this}},{key:"editable",value:function(e){return o.call(this,"editable",e)}},{key:"editing",value:function(e){return o.call(this,"editing",e)}},{key:"expand",value:function(){return this.invoke("expand")}},{key:"expanded",value:function(e){return o.call(this,"expanded",e)}},{key:"expandDeep",value:function(){var e=this;return new k((function(t){var n=0,i=function(){0==--n&&t(e)};e.recurseDown((function(e){n++,e.children?e.expand().catch(i).then((function(){e.children.expandDeep().catch(i).then(i)})):i()}))}))}},{key:"expandParents",value:function(){return this.invoke("expandParents")}},{key:"extract",value:function(t){var i=this.flatten(t),r=new n(this._tree);return e.each(i,(function(e){r.addNode(e.copyHierarchy())})),r}},{key:"filterBy",value:function(t){var i=a(t),r=new n(this._tree);return e.each(this,(function(e){i(e)&&r.push(e)})),r}},{key:"flatten",value:function(e){var t=new n(this._tree),i=a(e);return this.recurseDown((function(e){i(e)&&t.push(e)})),t}},{key:"focused",value:function(e){return o.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 o.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 o.call(this,"indeterminate",e)}},{key:"insertAt",value:function(t,i){if(i.id){var r=this.node(i.id);if(r)return r.restore().show(),e.isArrayLike(i.children)?(e.isArrayLike(r.children)||(r.children=new n(this._tree),r.children._context=r),e.each(i.children,(function(e){r.children.addNode(e)}))):i.children&&e.isBoolean(r.children)&&(r.children=i.children),r.markDirty(),this._tree.applyChanges(),r}var o=this._tree.constructor.isTreeNode(i)?i:u(this._tree,i);return this.splice(t,0,o),this._context&&(o.itree.parent=this._context,this._context.refreshIndeterminateState().markDirty()),this._tree.emit("node.added",o),o.markDirty(),this.length-1!==t&&this.invoke("markDirty"),this._tree.applyChanges(),o}},{key:"invoke",value:function(e,t){return s(this,e,t)}},{key:"invokeDeep",value:function(e,t){return s(this,e,t,!0)}},{key:"loading",value:function(e){return o.call(this,"loading",e)}},{key:"loadMore",value:function(t){var n=this;if(this._loading)return k.reject(new Error("Pending loadMore call must complete before being invoked again."));var i=void 0;return this._pagination.limit===this._pagination.total?k.resolve():(this._loading=!0,this._tree.batch(),e.invoke(this._context,"markDirty"),this._pagination.limit+=this._tree.config.pagination.limit,this._tree.emit("node.paginated",this._context||this._tree,this.pagination,t),this._tree.config.deferredLoading?i=this._context?this._context.loadChildren():this._tree.load(this._tree.config.data):(this._loading=!1,i=k.resolve()),this._tree.end(),this._tree.config.deferredLoading&&i.then((function(){n._loading=!1,n._tree.applyChanges()})).catch((function(){n._loading=!1,n._tree.applyChanges()})),i)}},{key:"matched",value:function(e){return o.call(this,"matched",e)}},{key:"move",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this;this._tree.batch();var i=this[e].remove(),r=n.insertAt(t,i);return this._tree.emit("node.moved",r,this,e,n,t),this._tree.end(),r}},{key:"node",value:function(e){var t=void 0;return this.recurseDown((function(n){if(n.id===e)return t=n,!1})),t}},{key:"nodes",value:function(t){var i=void 0;return e.isArray(t)&&(i=new n(this._tree),this.recurseDown((function(e){t.indexOf(e.id)>-1&&i.push(e)}))),e.isArray(t)?i:this}},{key:"pagination",value:function(){return this._pagination}},{key:"recurseDown",value:function(e){return l(this,e),this}},{key:"remove",value:function(t){return e.remove(this,{id:t.id}),e.invoke(this._context,"markDirty"),this._tree.applyChanges(),this}},{key:"removed",value:function(e){return o.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 o.call(this,"selectable",e)}},{key:"selectDeep",value:function(){return this.invokeDeep("select")}},{key:"selected",value:function(e){return o.call(this,"selected",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(t){var n=this;if(t=t||this._tree.config.sort){var i=e.sortBy(this,t);this.length=0,e.each(i,(function(e){n.push(e)}))}return this}},{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),o=i.indexOf(t);return n===i?(this[r]=t,this[o]=e,this._tree.emit("node.moved",e,n,r,i,o),this._tree.emit("node.moved",t,i,o,n,r)):(n.move(r,i.indexOf(t),i),i.move(i.indexOf(t),r,n)),this._tree.end(),this._tree.emit("node.swapped",e,n,r,t,i,o),this}},{key:"tree",value:function(){return this._tree}},{key:"toArray",value:function(){var t=[];return e.each(this,(function(e){t.push(e.toObject())})),t}},{key:"visible",value:function(e){return o.call(this,"visible",e)}}]),n}(function(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}(Array)),C=function(){function t(n,i,r){var o=this;_(this,t),this._tree=n,i instanceof t&&((r=e.castArray(r)).push("_tree"),e.each(i,(function(t,n){e.includes(r,n)||(e.isObject(t)?o[n]=t instanceof x?t.clone():"itree"===n?function(t,n){var i={};return(n=e.castArray(n)).push("ref"),e.each(t,(function(t,r){e.includes(n,r)||(i[r]=e.cloneDeep(t))})),i}(t):e.cloneDeep(t):o[n]=t)})))}return b(t,[{key:"addChild",value:function(t){return!e.isArray(this.children)&&e.isArrayLike(this.children)||(this.children=new x(this._tree),this.children._context=this),this.children.addNode(t)}},{key:"addChildren",value:function(t){var n=this,i=new x(this._tree);return this._tree.batch(),e.each(t,(function(e){i.push(n.addChild(e))})),this._tree.end(),i}},{key:"allowDynamicLoad",value:function(){return this._tree.isDynamic&&(e.isArrayLike(this.children)||!0===this.children)}},{key:"available",value:function(){return!this.hidden()&&!this.removed()}},{key:"blur",value:function(){return this.state("editing",!1),r("focused",!1,"blurred",this)}},{key:"check",value:function(e){return this._tree.batch(),r("checked",!0,"checked",this,!e&&this._tree.config.checkbox.autoCheckChildren),this.state("indeterminate",!1),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 t(this._tree,this,e)}},{key:"collapse",value:function(){return r("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(t){var n=this;return t&&(n=n.copyHierarchy()),{to:function(t){if(!e.isFunction(t.addNode))throw new Error("Destination must be an Inspire Tree instance.");return t.addNode(n.toObject())}}}},{key:"copyHierarchy",value:function(t){var n=[],i=this.getParents();if(e.each(i,(function(e){n.push(e.toObject(t))})),i=n.reverse(),!t){var r=this.toObject(!0);this.hasChildren()&&(r.children=this.children.filterBy((function(e){return!e.state("hidden")})).toArray(),r.children._context=r),n.push(r)}var o=n[0],s=o,a=n.length;return e.each(n,(function(e,t){var i=[];t+1<a&&(i.push(n[t+1]),s.children=i,s=s.children[0])})),u(this._tree,o)}},{key:"deselect",value:function(e){return this.selected()&&(!this._tree.config.selection.require||this._tree.selected().length>1)&&(this._tree.batch(),r("selected",!1,"deselected",this,!e&&this._tree.config.selection.autoSelectChildren),this._tree.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 e=this;return new k((function(t,n){(e.hasChildren()||e._tree.isDynamic&&!0===e.children)&&(e.collapsed()||e.hidden())?(e.state("collapsed",!1),e.state("hidden",!1),e._tree.emit("node.expanded",e),e._tree.isDynamic&&!0===e.children?e.loadChildren().then(t).catch(n):(e.markDirty(),e._tree.applyChanges(),t(e))):t(e)}))}},{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 x(this._tree)}},{key:"getParent",value:function(){return this.itree.parent}},{key:"getParents",value:function(){var e=new x(this._tree);return this.hasParent()&&this.getParent().recurseUp((function(t){e.push(t)})),e}},{key:"getTextualHierarchy",value:function(){var e=[];return this.recurseUp((function(t){e.unshift(t.text)})),e}},{key:"hasAncestor",value:function(e){var t=!1;return this.recurseUp((function(n){return!(t=n.id===e.id)})),t}},{key:"hasChildren",value:function(){return e.isArrayLike(this.children)&&this.children.length>0}},{key:"hasLoadedChildren",value:function(){return e.isArrayLike(this.children)}},{key:"hasOrWillHaveChildren",value:function(){return e.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=this.children.filterBy("available").length>0),e}},{key:"hide",value:function(){var e=r("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(n){t.push(e.indexOf(n.context(),n))})),t.reverse().join(".")}},{key:"indeterminate",value:function(){return this.state("indeterminate")}},{key:"lastDeepestVisibleChild",value:function(){var t=void 0;if(this.hasChildren()&&!this.collapsed()){var n=(t=e.findLast(this.children,(function(e){return e.visible()}))).lastDeepestVisibleChild();n&&(t=n)}return t}},{key:"loadChildren",value:function(){var t=this;return new k((function(n,i){if(!t.allowDynamicLoad())return i(new Error("Node does not have or support dynamic children."));t.state("loading",!0),t.markDirty(),t._tree.applyChanges();var r=function(r,o){if(!e.isArrayLike(r))return i(new TypeError("Loader requires an array-like `nodes` parameter."));t._tree.batch(),t.state("loading",!1);var s=h(t._tree,r,t);e.isArrayLike(t.children)?t.children=t.children.concat(s):t.children=s,e.parseInt(o)>r.length&&(t.children._pagination.total=e.parseInt(o)),"checkbox"===t._tree.config.selection.mode&&t.selected()&&t.children.select(),t.markDirty(),t._tree.end(),n(t.children),t._tree.emit("children.loaded",t)},o=function(e){t.state("loading",!1),t.children=new x(t._tree),t.children._context=t,t.markDirty(),t._tree.applyChanges(),i(e),t._tree.emit("tree.loaderror",e)},s=t._tree.constructor.isTreeNodes(t.children)?t.children.pagination():null,a=t._tree.config.data(t,r,o,s);e.isObject(a)&&c(a).then(r).catch(o)}))}},{key:"loading",value:function(){return this.state("loading")}},{key:"loadMore",value:function(){return this.children&&!0!==this.children?this.children.loadMore():k.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=void 0;if(this.hasParent()){var t=this.getParent();(e=t.nextVisibleSiblingNode())||(e=t.nextVisibleAncestralSiblingNode())}return e}},{key:"nextVisibleChildNode",value:function(){var t=void 0;return this.hasChildren()&&(t=e.find(this.children,(function(e){return e.visible()}))),t}},{key:"nextVisibleNode",value:function(){var e=void 0;return(e=this.nextVisibleChildNode())||(e=this.nextVisibleSiblingNode()),e||(e=this.nextVisibleAncestralSiblingNode()),e}},{key:"nextVisibleSiblingNode",value:function(){var t=this.hasParent()?this.getParent().children:this._tree.nodes(),n=e.findIndex(t,{id:this.id});return e.find(e.slice(t,n+1),(function(e){return e.visible()}))}},{key:"pagination",value:function(){return e.get(this,"children._pagination")}},{key:"previousVisibleNode",value:function(){var e=void 0;return(e=this.previousVisibleSiblingNode())&&e.hasChildren()&&!e.collapsed()&&(e=e.lastDeepestVisibleChild()),!e&&this.hasParent()&&(e=this.getParent()),e}},{key:"previousVisibleSiblingNode",value:function(){var t=this.hasParent()?this.getParent().children:this._tree.nodes(),n=e.findIndex(t,{id:this.id});return e.findLast(e.slice(t,0,n),(function(e){return e.visible()}))}},{key:"recurseDown",value:function(e){return l(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?r("checked",!0,"checked",this):r("checked",!1,"unchecked",this),this.checked()||this.state("indeterminate",n>0||t>0&&i>0&&i<t)}return this.hasParent()&&this.getParent().refreshIndeterminateState(),e!==this.state("indeterminate")&&this.markDirty(),this}},{key:"reload",value:function(){var e=this;return new k((function(t,n){if(!e.allowDynamicLoad())return n(new Error("Node or tree does not support dynamic children."));e.children=!0,e.collapse(),e.loadChildren().then(t).catch(n)}))}},{key:"remove",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],t=this.getParent();this.context().remove(this),t&&(t.refreshIndeterminateState(),t.markDirty()),(t?t.pagination():this._tree.pagination()).total--;var n=this.toObject(!1,e);return this._tree.emit("node.removed",n,t),this._tree.applyChanges(),n}},{key:"removed",value:function(){return this.state("removed")}},{key:"rendered",value:function(){return this.state("rendered")}},{key:"restore",value:function(){return r("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}r("selected",!0,"selected",this,!e&&this._tree.config.selection.autoSelectChildren),this._tree._lastSelectedNode=this,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._tree.applyChanges(),this}},{key:"show",value:function(){return r("hidden",!1,"shown",this)}},{key:"state",value:function(e,t){var n=this.itree.state[e];return void 0!==t&&n!==t&&(this.itree.state[e]=t,"rendered"!==e&&this.markDirty(),this._tree.emit("node.state.changed",this,e,n,t)),n}},{key:"states",value:function(t,n){var i=this,r=[];return this._tree.batch(),e.each(t,(function(e){r.push(i.state(e,n))})),this._tree.end(),r}},{key:"swap",value:function(e){return this.context().swap(this,e),this}},{key:"softRemove",value:function(){return r("removed",!0,"softremoved",this,"softRemove")}},{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._tree.applyChanges(),this}},{key:"toggleSelect",value:function(){return this.selected()?this.deselect():this.select()}},{key:"toObject",value:function(){var t=this,n=arguments.length>0&&void 0!==arguments[0]&&arguments[0],i=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r={},o=e.pull(Object.keys(this),"_tree","children","itree");e.each(o,(function(e){r[e]=t[e]}));var s=r.itree={};return s.a=this.itree.a,s.icon=this.itree.icon,s.li=this.itree.li,i&&(s.state=this.itree.state),!n&&this.hasChildren()&&e.isFunction(this.children.toArray)&&(r.children=this.children.toArray()),r}},{key:"toString",value:function(){return this.text}},{key:"tree",value:function(){return this.context().tree()}},{key:"uncheck",value:function(e){return this._tree.batch(),r("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())}}]),t}();return function(t){function n(t){_(this,n);var i=D(this,(n.__proto__||Object.getPrototypeOf(n)).call(this)),r=i;r._lastSelectedNode,r._muted=!1,r.allowsLoadEvents=!1,r.batching=0,r.id=m(),r.initialized=!1,r.isDynamic=!1,r.opts=t,r.preventDeselection=!1,r.config=e.defaultsDeep({},t,{allowLoadEvents:[],checkbox:{autoCheckChildren:!0},contextMenu:!1,data:!1,editable:!1,editing:{add:!1,edit:!1,remove:!1},nodes:{resetStateOnRestore:!0},pagination:{limit:-1},renderer:!1,search:{matcher:!1,matchProcessor:!1},selection:{allow:e.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),t.editable&&!t.editing&&(r.config.editing.add=!0,r.config.editing.edit=!0,r.config.editing.remove=!0),e.isFunction(t.search)&&(r.config.search={matcher:t.search,matchProcessor:!1}),r.defaultState={collapsed:!0,editable:e.get(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=e.isArray(r.config.allowLoadEvents)&&r.config.allowLoadEvents.length>0,r.isDynamic=e.isFunction(r.config.data);var o=r.emit;return r.emit=function(t){if(!r.isEventMuted(t)){if(e.isFunction(e.get(arguments,"[1].preventDefault"))){var n=arguments[1];n.treeDefaultPrevented=!1,n.preventTreeDefault=function(){n.treeDefaultPrevented=!0}}o.apply(r,arguments)}},r.model=new x(r),r.config.data&&r.load(r.config.data),r.initialized=!0,i}return w(n,t),b(n,[{key:"addNode",value:function(){return d(this,"addNode",arguments)}},{key:"addNodes",value:function(t){var n=this;this.batch();var i=new x(this);return e.each(t,(function(e){i.push(n.addNode(e))})),this.end(),i}},{key:"applyChanges",value:function(){this.batching>0||this.emit("changes.applied")}},{key:"available",value:function(){return d(this,"available",arguments)}},{key:"batch",value:function(){this.batching<0&&(this.batching=0),this.batching++}},{key:"blur",value:function(){return d(this,"blur",arguments)}},{key:"blurDeep",value:function(){return d(this,"blurDeep",arguments)}},{key:"boundingNodes",value:function(){var t=e.transform(arguments,(function(e,t){e[t.indexPath().replace(/\./g,"")]=t}),{}),n=function(e){return Array.isArray(e)?e:Array.from(e)}(e.sortBy(Object.keys(t))),i=n[0],r=n.slice(1);return[e.get(t,i),e.get(t,r)]}},{key:"canAutoDeselect",value:function(){return this.config.selection.autoDeselect&&!this.preventDeselection}},{key:"checked",value:function(){return d(this,"checked",arguments)}},{key:"clean",value:function(){return d(this,"clean",arguments)}},{key:"clearSearch",value:function(){return this.matched().state("matched",!1),this.showDeep().collapseDeep().tree()}},{key:"clone",value:function(){return d(this,"clone",arguments)}},{key:"collapse",value:function(){return d(this,"collapse",arguments)}},{key:"collapsed",value:function(){return d(this,"collapsed",arguments)}},{key:"collapseDeep",value:function(){return d(this,"collapseDeep",arguments)}},{key:"concat",value:function(){return d(this,"concat",arguments)}},{key:"copy",value:function(){return d(this,"copy",arguments)}},{key:"createNode",value:function(e){return n.isTreeNode(e)?e:u(this,e)}},{key:"deepest",value:function(){return d(this,"deepest",arguments)}},{key:"deselect",value:function(){return d(this,"deselect",arguments)}},{key:"deselectDeep",value:function(){return d(this,"deselectDeep",arguments)}},{key:"disableDeselection",value:function(){return this.config.selection.multiple&&(this.preventDeselection=!0),this}},{key:"each",value:function(){return d(this,"each",arguments)}},{key:"every",value:function(){return d(this,"every",arguments)}},{key:"editable",value:function(){return d(this,"editable",arguments)}},{key:"editing",value:function(){return d(this,"editing",arguments)}},{key:"enableDeselection",value:function(){return this.preventDeselection=!1,this}},{key:"end",value:function(){0==--this.batching&&this.applyChanges()}},{key:"expand",value:function(){return d(this,"expand",arguments)}},{key:"expandDeep",value:function(){return d(this,"expandDeep",arguments)}},{key:"expanded",value:function(){return d(this,"expanded",arguments)}},{key:"extract",value:function(){return d(this,"extract",arguments)}},{key:"filter",value:function(){return d(this,"filter",arguments)}},{key:"filterBy",value:function(){return d(this,"filterBy",arguments)}},{key:"flatten",value:function(){return d(this,"flatten",arguments)}},{key:"focused",value:function(){return d(this,"focused",arguments)}},{key:"forEach",value:function(){return d(this,"each",arguments)}},{key:"get",value:function(){return d(this,"get",arguments)}},{key:"hidden",value:function(){return d(this,"hidden",arguments)}},{key:"hide",value:function(){return d(this,"hide",arguments)}},{key:"hideDeep",value:function(){return d(this,"hideDeep",arguments)}},{key:"indeterminate",value:function(){return d(this,"indeterminate",arguments)}},{key:"indexOf",value:function(){return d(this,"indexOf",arguments)}},{key:"insertAt",value:function(){return d(this,"insertAt",arguments)}},{key:"invoke",value:function(){return d(this,"invoke",arguments)}},{key:"invokeDeep",value:function(){return d(this,"invokeDeep",arguments)}},{key:"isEventMuted",value:function(t){return e.isBoolean(this.muted())?this.muted():e.includes(this.muted(),t)}},{key:"isTree",value:function(e){return e instanceof n}},{key:"join",value:function(){return d(this,"join",arguments)}},{key:"lastSelectedNode",value:function(){return this._lastSelectedNode}},{key:"load",value:function(t){var n=this,i=new k((function(i,r){var o=function(t,o){if(!e.isArrayLike(t))return r(new TypeError("Loader requires an array-like `nodes` parameter."));!n.initialized&&e.isArrayLike(t)?setTimeout((function(){n.emit("data.loaded",t)})):n.emit("data.loaded",t);var s=h(n,t);n.config.deferredLoading?n.model=n.model.concat(s):n.model=s,n.model._pagination.total=t.length,e.parseInt(o)>t.length&&(n.model._pagination.total=e.parseInt(o)),o||n.model.recurseDown((function(e){e.hasChildren()&&(e.children._pagination.total=e.children.length)})),n.config.selection.require&&!n.selected().length&&n.selectFirstAvailableNode();var a=function(){n.emit("model.loaded",n.model),i(n.model),n.applyChanges()};!n.initialized&&e.isArray(t)?setTimeout(a):a()};if(e.isArrayLike(t))o(t);else if(e.isFunction(t)){var s=t(null,o,r,n.pagination());s&&(t=s)}e.isObject(t)?c(t).then(o).catch(r):error(new Error("Invalid data loader."))}));return i.catch((function(e){n.emit("data.loaderror",e)})),this._loader={promise:i},i}},{key:"loading",value:function(){return d(this,"loading",arguments)}},{key:"loadMore",value:function(){return d(this,"loadMore",arguments)}},{key:"map",value:function(){return d(this,"map",arguments)}},{key:"matched",value:function(){return d(this,"matched",arguments)}},{key:"move",value:function(){return d(this,"move",arguments)}},{key:"mute",value:function(t){return e.isString(t)||e.isArray(t)?this._muted=e.castArray(t):this._muted=!0,this}},{key:"muted",value:function(){return this._muted}},{key:"node",value:function(){return d(this,"node",arguments)}},{key:"nodes",value:function(){return d(this,"nodes",arguments)}},{key:"pagination",value:function(){return d(this,"pagination",arguments)}},{key:"pop",value:function(){return d(this,"pop",arguments)}},{key:"push",value:function(){return d(this,"push",arguments)}},{key:"recurseDown",value:function(){return d(this,"recurseDown",arguments)}},{key:"reduce",value:function(){return d(this,"reduce",arguments)}},{key:"reduceRight",value:function(){return d(this,"reduceRight",arguments)}},{key:"reload",value:function(){return this.removeAll(),this.load(this.opts.data||this.config.data)}},{key:"remove",value:function(){return d(this,"remove",arguments)}},{key:"removeAll",value:function(){return this.model=new x(this),this.applyChanges(),this}},{key:"removed",value:function(){return d(this,"removed",arguments)}},{key:"restore",value:function(){return d(this,"restore",arguments)}},{key:"restoreDeep",value:function(){return d(this,"restoreDeep",arguments)}},{key:"reverse",value:function(){return d(this,"reverse",arguments)}},{key:"search",value:function(t){var i=this,r=this.config.search,o=r.matcher,s=r.matchProcessor;return!t||e.isString(t)&&e.isEmpty(t)?k.resolve(this.clearSearch()):(this.batch(),this.recurseDown((function(e){e.state("hidden",!0),e.state("matched",!1)})),this.end(),o=e.isFunction(o)?o:function(t,n){var r=new x(i);e.isString(t)&&(t=new RegExp(t,"i"));var o=void 0;o=e.isRegExp(t)?function(e){return t.test(e.text)}:t,i.model.recurseDown((function(e){e.removed()||o(e)&&r.push(e)})),n(r)},s=e.isFunction(s)?s:function(e){e.each((function(e){e.show().state("matched",!0),e.expandParents().collapse(),e.hasChildren()&&e.children.showDeep()}))},new k((function(r,a){o(t,(function(t){n.isTreeNodes(t)||(t=i.nodes(e.map(t,"id"))),i.batch(),s(t),i.end(),r(t)}),a)})))}},{key:"select",value:function(){return d(this,"select",arguments)}},{key:"selectable",value:function(){return d(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 d(this,"selectDeep",arguments)}},{key:"selected",value:function(){return d(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 d(this,"shift",arguments)}},{key:"show",value:function(){return d(this,"show",arguments)}},{key:"showDeep",value:function(){return d(this,"showDeep",arguments)}},{key:"slice",value:function(){return d(this,"slice",arguments)}},{key:"softRemove",value:function(){return d(this,"softRemove",arguments)}},{key:"some",value:function(){return d(this,"some",arguments)}},{key:"sort",value:function(){return d(this,"sort",arguments)}},{key:"sortBy",value:function(){return d(this,"sortBy",arguments)}},{key:"splice",value:function(){return d(this,"slice",arguments)}},{key:"state",value:function(){return d(this,"state",arguments)}},{key:"stateDeep",value:function(){return d(this,"stateDeep",arguments)}},{key:"swap",value:function(){return d(this,"swap",arguments)}},{key:"toArray",value:function(){return d(this,"toArray",arguments)}},{key:"toString",value:function(){return d(this,"toString",arguments)}},{key:"unmute",value:function(t){return e.isString(t)||e.isArray(t)?(this._muted=e.difference(this._muted,e.castArray(t)),this._muted.length||(this._muted=!1)):this._muted=!1,this}},{key:"unshift",value:function(){return d(this,"unshift",arguments)}},{key:"visible",value:function(){return d(this,"visible",arguments)}}],[{key:"isTreeNode",value:function(e){return e instanceof C}},{key:"isTreeNodes",value:function(e){return e instanceof x}}]),n}(n((function(e,t){!function(t){function n(){this._events={},this._conf&&i.call(this,this._conf)}function i(e){e?(this._conf=e,e.delimiter&&(this.delimiter=e.delimiter),this._maxListeners=e.maxListeners!==t?e.maxListeners:c,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=c}function r(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 o(e){this._events={},this._newListener=!1,this._removeListener=!1,this.verboseMemoryLeak=!1,i.call(this,e)}function s(e,t,n,i){if(!n)return[];var r,o,a,l,c,u,h,d=[],f=t.length,p=t[i],v=t[i+1];if(i===f&&n._listeners){if("function"==typeof n._listeners)return e&&e.push(n._listeners),[n];for(r=0,o=n._listeners.length;r<o;r++)e&&e.push(n._listeners[r]);return[n]}if("*"===p||"**"===p||n[p]){if("*"===p){for(a in n)"_listeners"!==a&&n.hasOwnProperty(a)&&(d=d.concat(s(e,t,n[a],i+1)));return d}if("**"===p){for(a in(h=i+1===f||i+2===f&&"*"===v)&&n._listeners&&(d=d.concat(s(e,t,n,f))),n)"_listeners"!==a&&n.hasOwnProperty(a)&&("*"===a||"**"===a?(n[a]._listeners&&!h&&(d=d.concat(s(e,t,n[a],f))),d=d.concat(s(e,t,n[a],i))):d=a===v?d.concat(s(e,t,n[a],i+2)):d.concat(s(e,t,n[a],i)));return d}d=d.concat(s(e,t,n[p],i+1))}if((l=n["*"])&&s(e,t,l,i+1),c=n["**"])if(i<f)for(a in c._listeners&&s(e,t,c,f),c)"_listeners"!==a&&c.hasOwnProperty(a)&&(a===v?s(e,t,c[a],i+2):a===p?s(e,t,c[a],i+1):((u={})[a]=c[a],s(e,t,{"**":u},i+1)));else c._listeners?s(e,t,c,f):c["*"]&&c["*"]._listeners&&s(e,t,c["*"],f);return d}function a(e,n){for(var i=0,o=(e="string"==typeof e?e.split(this.delimiter):e.slice()).length;i+1<o;i++)if("**"===e[i]&&"**"===e[i+1])return;for(var s=this.listenerTree,a=e.shift();a!==t;){if(s[a]||(s[a]={}),s=s[a],0===e.length)return s._listeners?("function"==typeof s._listeners&&(s._listeners=[s._listeners]),s._listeners.push(n),!s._listeners.warned&&this._maxListeners>0&&s._listeners.length>this._maxListeners&&(s._listeners.warned=!0,r.call(this,s._listeners.length,a))):s._listeners=n,!0;a=e.shift()}return!0}var l=Array.isArray?Array.isArray:function(e){return"[object Array]"===Object.prototype.toString.call(e)},c=10;o.EventEmitter2=o,o.prototype.delimiter=".",o.prototype.setMaxListeners=function(e){e!==t&&(this._maxListeners=e,this._conf||(this._conf={}),this._conf.maxListeners=e)},o.prototype.event="",o.prototype.once=function(e,t){return this._once(e,t,!1)},o.prototype.prependOnceListener=function(e,t){return this._once(e,t,!0)},o.prototype._once=function(e,t,n){return this._many(e,1,t,n),this},o.prototype.many=function(e,t,n){return this._many(e,t,n,!1)},o.prototype.prependMany=function(e,t,n){return this._many(e,t,n,!0)},o.prototype._many=function(e,t,n,i){function r(){return 0==--t&&o.off(e,r),n.apply(this,arguments)}var o=this;if("function"!=typeof n)throw new Error("many only accepts instances of Function");return r._origin=n,this._on(e,r,i),o},o.prototype.emit=function(){this._events||n.call(this);var e=arguments[0];if("newListener"===e&&!this._newListener&&!this._events.newListener)return!1;var t,i,r,o,a,l=arguments.length;if(this._all&&this._all.length){if(a=this._all.slice(),l>3)for(t=new Array(l),o=0;o<l;o++)t[o]=arguments[o];for(r=0,i=a.length;r<i;r++)switch(this.event=e,l){case 1:a[r].call(this,e);break;case 2:a[r].call(this,e,arguments[1]);break;case 3:a[r].call(this,e,arguments[1],arguments[2]);break;default:a[r].apply(this,t)}}if(this.wildcard){a=[];var c="string"==typeof e?e.split(this.delimiter):e.slice();s.call(this,a,c,this.listenerTree,0)}else{if("function"==typeof(a=this._events[e])){switch(this.event=e,l){case 1:a.call(this);break;case 2:a.call(this,arguments[1]);break;case 3:a.call(this,arguments[1],arguments[2]);break;default:for(t=new Array(l-1),o=1;o<l;o++)t[o-1]=arguments[o];a.apply(this,t)}return!0}a&&(a=a.slice())}if(a&&a.length){if(l>3)for(t=new Array(l-1),o=1;o<l;o++)t[o-1]=arguments[o];for(r=0,i=a.length;r<i;r++)switch(this.event=e,l){case 1:a[r].call(this);break;case 2:a[r].call(this,arguments[1]);break;case 3:a[r].call(this,arguments[1],arguments[2]);break;default:a[r].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},o.prototype.emitAsync=function(){this._events||n.call(this);var e=arguments[0];if("newListener"===e&&!this._newListener&&!this._events.newListener)return Promise.resolve([!1]);var t,i,r,o,a,l=[],c=arguments.length;if(this._all){if(c>3)for(t=new Array(c),o=1;o<c;o++)t[o]=arguments[o];for(r=0,i=this._all.length;r<i;r++)switch(this.event=e,c){case 1:l.push(this._all[r].call(this,e));break;case 2:l.push(this._all[r].call(this,e,arguments[1]));break;case 3:l.push(this._all[r].call(this,e,arguments[1],arguments[2]));break;default:l.push(this._all[r].apply(this,t))}}if(this.wildcard){a=[];var u="string"==typeof e?e.split(this.delimiter):e.slice();s.call(this,a,u,this.listenerTree,0)}else a=this._events[e];if("function"==typeof a)switch(this.event=e,c){case 1:l.push(a.call(this));break;case 2:l.push(a.call(this,arguments[1]));break;case 3:l.push(a.call(this,arguments[1],arguments[2]));break;default:for(t=new Array(c-1),o=1;o<c;o++)t[o-1]=arguments[o];l.push(a.apply(this,t))}else if(a&&a.length){if(a=a.slice(),c>3)for(t=new Array(c-1),o=1;o<c;o++)t[o-1]=arguments[o];for(r=0,i=a.length;r<i;r++)switch(this.event=e,c){case 1:l.push(a[r].call(this));break;case 2:l.push(a[r].call(this,arguments[1]));break;case 3:l.push(a[r].call(this,arguments[1],arguments[2]));break;default:l.push(a[r].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(l)},o.prototype.on=function(e,t){return this._on(e,t,!1)},o.prototype.prependListener=function(e,t){return this._on(e,t,!0)},o.prototype.onAny=function(e){return this._onAny(e,!1)},o.prototype.prependAny=function(e){return this._onAny(e,!0)},o.prototype.addListener=o.prototype.on,o.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},o.prototype._on=function(e,t,i){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||n.call(this),this._newListener&&this.emit("newListener",e,t),this.wildcard?(a.call(this,e,t),this):(this._events[e]?("function"==typeof this._events[e]&&(this._events[e]=[this._events[e]]),i?this._events[e].unshift(t):this._events[e].push(t),!this._events[e].warned&&this._maxListeners>0&&this._events[e].length>this._maxListeners&&(this._events[e].warned=!0,r.call(this,this._events[e].length,e))):this._events[e]=t,this)},o.prototype.off=function(e,n){if("function"!=typeof n)throw new Error("removeListener only takes instances of Function");var i,r=[];if(this.wildcard){var o="string"==typeof e?e.split(this.delimiter):e.slice();r=s.call(this,null,o,this.listenerTree,0)}else{if(!this._events[e])return this;i=this._events[e],r.push({_listeners:i})}for(var a=0;a<r.length;a++){var c=r[a];if(i=c._listeners,l(i)){for(var u=-1,h=0,d=i.length;h<d;h++)if(i[h]===n||i[h].listener&&i[h].listener===n||i[h]._origin&&i[h]._origin===n){u=h;break}if(u<0)continue;return this.wildcard?c._listeners.splice(u,1):this._events[e].splice(u,1),0===i.length&&(this.wildcard?delete c._listeners:delete this._events[e]),this._removeListener&&this.emit("removeListener",e,n),this}(i===n||i.listener&&i.listener===n||i._origin&&i._origin===n)&&(this.wildcard?delete c._listeners:delete this._events[e],this._removeListener&&this.emit("removeListener",e,n))}return function e(n){if(n!==t){var i=Object.keys(n);for(var r in i){var o=i[r],s=n[o];s instanceof Function||"object"!=typeof s||null===s||(Object.keys(s).length>0&&e(n[o]),0===Object.keys(s).length&&delete n[o])}}}(this.listenerTree),this},o.prototype.offAny=function(e){var t,n=0,i=0;if(e&&this._all&&this._all.length>0){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},o.prototype.removeListener=o.prototype.off,o.prototype.removeAllListeners=function(e){if(e===t)return!this._events||n.call(this),this;if(this.wildcard)for(var i="string"==typeof e?e.split(this.delimiter):e.slice(),r=s.call(this,null,i,this.listenerTree,0),o=0;o<r.length;o++)r[o]._listeners=null;else this._events&&(this._events[e]=null);return this},o.prototype.listeners=function(e){if(this.wildcard){var t=[],i="string"==typeof e?e.split(this.delimiter):e.slice();return s.call(this,t,i,this.listenerTree,0),t}return this._events||n.call(this),this._events[e]||(this._events[e]=[]),l(this._events[e])||(this._events[e]=[this._events[e]]),this._events[e]},o.prototype.eventNames=function(){return Object.keys(this._events)},o.prototype.listenerCount=function(e){return this.listeners(e).length},o.prototype.listenersAny=function(){return this._all?this._all:[]},e.exports=o}()})).EventEmitter2)})),function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("lodash"),require("inspire-tree")):"function"==typeof define&&define.amd?define(["lodash","inspire-tree"],t):e.InspireTreeDOM=t(e._,e.InspireTree)}(this,(function(e,t){"use strict";t=t&&t.hasOwnProperty("default")?t.default:t;var n="$NO_OP",i=!("undefined"==typeof window||!window.document),r=Array.isArray;function o(e){var t=typeof e;return"string"===t||"number"===t}function s(e){return d(e)||h(e)}function a(e){return h(e)||!1===e||!0===e||d(e)}function l(e){return"function"==typeof e}function c(e){return"string"==typeof e}function u(e){return"number"==typeof e}function h(e){return null===e}function d(e){return void 0===e}function f(e,t){var n={};if(e)for(var i in e)n[i]=e[i];if(t)for(var r in t)n[r]=t[r];return n}var p="$";function v(e,t,n,i,r,o,s,a){return{childFlags:e,children:t,className:n,dom:null,flags:i,key:void 0===r?null:r,parentVNode:null,props:void 0===o?null:o,ref:void 0===s?null:s,type:a}}function y(e,t,n,i,r,o,s,a){var l=void 0===r?1:r,c=v(l,i,n,e,s,o,a,t);return 0===l&&D(c,c.children),c}function g(e,t,n,i,r){0<(2&e)&&(e=t.prototype&&l(t.prototype.render)?4:8);var o=t.defaultProps;if(!s(o))for(var a in n||(n={}),o)d(n[a])&&(n[a]=o[a]);if(0<(8&e)){var c=t.defaultHooks;if(!s(c))if(r)for(var u in c)d(r[u])&&(r[u]=c[u]);else r=c}var h=v(1,null,null,e,i,n,r,t),f=x.createVNode;return l(f)&&f(h),h}function m(e,t){return v(1,s(e)?"":e,null,16,t,null,null,null)}function k(e){var t=e.props;if(t){var n=e.flags;481&n&&(void 0!==t.children&&s(e.children)&&D(e,t.children),void 0!==t.className&&(e.className=t.className||null,t.className=void 0)),void 0!==t.key&&(e.key=t.key,t.key=void 0),void 0!==t.ref&&(e.ref=8&n?f(e.ref,t.ref):t.ref,t.ref=void 0)}return e}function _(e){var t,n=e.flags;if(14&n){var i,r=e.props;if(!h(r))for(var o in i={},r)i[o]=r[o];t=g(n,e.type,i,e.key,e.ref)}else 481&n?t=y(n,e.type,e.className,e.children,e.childFlags,e.props,e.key,e.ref):16&n?t=m(e.children,e.key):1024&n&&(t=e);return t}function b(){return m("",null)}function w(e,t,n,i){for(var s=e.length;n<s;n++){var l=e[n];if(!a(l)){var u=i+p+n;if(r(l))w(l,t,0,u);else{if(o(l))l=m(l,u);else{var d=l.key,f=c(d)&&d[0]===p;h(l.dom)&&!f||(l=_(l)),h(d)||f?l.key=u:l.key=i+d}t.push(l)}}}}function D(e,t){var n,i=1;if(a(t))n=t;else if(c(t))i=2,n=m(t);else if(u(t))i=2,n=m(t+"");else if(r(t)){var s=t.length;if(0===s)n=null,i=1;else{(Object.isFrozen(t)||!0===t.$)&&(t=t.slice()),i=8;for(var l=0;l<s;l++){var d=t[l];if(a(d)||r(d)){w(t,n=n||t.slice(0,l),l,"");break}if(o(d))(n=n||t.slice(0,l)).push(m(d,p+l));else{var f=d.key,v=h(d.dom),y=h(f),g=!y&&f[0]===p;!v||y||g?(n=n||t.slice(0,l),v&&!g||(d=_(d)),(y||g)&&(d.key=p+l),n.push(d)):n&&n.push(d)}}(n=n||t).$=!0}}else h((n=t).dom)||(n=_(t)),i=2;return e.children=n,e.childFlags=i,e}var x={afterRender:null,beforeRender:null,createVNode:null,renderComplete:null},C="http://www.w3.org/1999/xlink",S="http://www.w3.org/XML/1998/namespace",P={"xlink:actuate":C,"xlink:arcrole":C,"xlink:href":C,"xlink:role":C,"xlink:show":C,"xlink:title":C,"xlink:type":C,"xml:base":S,"xml:lang":S,"xml:space":S},L={},A=[];function N(e,t){e.appendChild(t)}function O(e,t,n){s(n)?N(e,t):e.insertBefore(t,n)}function $(e,t,n){e.replaceChild(t,n)}function T(e){for(var t;void 0!==(t=e.shift());)t()}var E={},j={};function M(e,t,n){var i,r,o=E[e],s=n.$EV;t?(o||(j[e]=(i=e,r=function(e){var t=e.type,n="click"===t||"dblclick"===t;if(n&&0!==e.button)return e.stopPropagation(),!1;e.stopPropagation=U;var r={dom:document};Object.defineProperty(e,"currentTarget",{configurable:!0,get:function(){return r.dom}}),function(e,t,n,i,r){for(var o=t;!h(o);){if(n&&o.disabled)return;var s=o.$EV;if(s){var a=s[i];if(a&&(r.dom=o,a.event?a.event(a.data,e):a(e),e.cancelBubble))return}o=o.parentNode}}(e,e.target,n,i,r)},document.addEventListener(F(i),r),r),E[e]=0),s||(s=n.$EV={}),s[e]||E[e]++,s[e]=t):s&&s[e]&&(E[e]--,1===o&&(document.removeEventListener(F(e),j[e]),j[e]=null),s[e]=t)}function F(e){return e.substr(2).toLowerCase()}function U(){this.cancelBubble=!0,this.immediatePropagationStopped||this.stopImmediatePropagation()}function I(e,t){var n=document.createElement("i");return n.innerHTML=t,n.innerHTML===e.innerHTML}function V(e,t,n){if(e[t]){var i=e[t];i.event?i.event(i.data,n):i(n)}else{var r=t.toLowerCase();e[r]&&e[r](n)}}function R(e,t){var n=function(n){n.stopPropagation();var i=this.$V;if(i){var r=i.props||L,o=i.dom;if(c(e))V(r,e,n);else for(var s=0;s<e.length;s++)V(r,e[s],n);if(l(t)){var a=this.$V,u=a.props||L;t(u,o,!1,a)}}};return Object.defineProperty(n,"wrapped",{configurable:!1,enumerable:!1,value:!0,writable:!1}),n}function B(e){return"checkbox"===e||"radio"===e}var W=R("onInput",K),H=R(["onClick","onChange"],K);function q(e){e.stopPropagation()}function K(e,t){var n=e.type,i=e.value,r=e.checked,o=e.multiple,a=e.defaultValue,l=!s(i);n&&n!==t.type&&t.setAttribute("type",n),s(o)||o===t.multiple||(t.multiple=o),s(a)||l||(t.defaultValue=a+""),B(n)?(l&&(t.value=i),s(r)||(t.checked=r)):l&&t.value!==i?(t.defaultValue=i,t.value=i):s(r)||(t.checked=r)}function z(e,t){if("optgroup"===e.type){var n=e.children,i=e.childFlags;if(12&i)for(var r=0,o=n.length;r<o;r++)X(n[r],t);else 2===i&&X(n,t)}else X(e,t)}function X(e,t){var n=e.props||L,i=e.dom;i.value=n.value,r(t)&&-1!==t.indexOf(n.value)||n.value===t?i.selected=!0:s(t)&&s(n.selected)||(i.selected=n.selected||!1)}q.wrapped=!0;var Q=R("onChange",Y);function Y(e,t,n,i){var r=Boolean(e.multiple);s(e.multiple)||r===t.multiple||(t.multiple=r);var o=i.childFlags;if(!(1&o)){var a=i.children,l=e.value;if(n&&s(l)&&(l=e.defaultValue),12&o)for(var c=0,u=a.length;c<u;c++)z(a[c],l);else 2===o&&z(a,l)}}var G=R("onInput",Z),J=R("onChange");function Z(e,t,n){var i=e.value,r=t.value;if(s(i)){if(n){var o=e.defaultValue;s(o)||o===r||(t.defaultValue=o,t.value=o)}}else r!==i&&(t.defaultValue=i,t.value=i)}function ee(e,t,n,i,r,o){64&e?K(i,n):256&e?Y(i,n,r,t):128&e&&Z(i,n,r),o&&(n.$V=t)}function te(e){return e.type&&B(e.type)?!s(e.checked):!s(e.value)}function ne(e,t){var n,i;ie(e),t&&e.dom&&(n=t,i=e.dom,n.removeChild(i),e.dom=null)}function ie(e){var t=e.flags;if(481&t){var n=e.ref,i=e.props;l(n)&&n(null);var r=e.children,o=e.childFlags;if(12&o?re(r):2===o&&ie(r),!h(i))for(var a in i)switch(a){case"onClick":case"onDblClick":case"onFocusIn":case"onFocusOut":case"onKeyDown":case"onKeyPress":case"onKeyUp":case"onMouseDown":case"onMouseMove":case"onMouseUp":case"onSubmit":case"onTouchEnd":case"onTouchMove":case"onTouchStart":M(a,null,e.dom)}}else{var c=e.children;if(c)if(14&t){var u=e.ref;4&t?(l(c.componentWillUnmount)&&c.componentWillUnmount(),l(u)&&u(null),c.$UN=!0,c.$LI&&ie(c.$LI)):(!s(u)&&l(u.onComponentWillUnmount)&&u.onComponentWillUnmount(e.dom,e.props||L),ie(c))}else 1024&t&&ne(c,e.type)}}function re(e){for(var t=0,n=e.length;t<n;t++)ie(e[t])}function oe(e,t){re(t),e.textContent=""}function se(e,t){switch(e){case"animationIterationCount":case"borderImageOutset":case"borderImageSlice":case"borderImageWidth":case"boxFlex":case"boxFlexGroup":case"boxOrdinalGroup":case"columnCount":case"fillOpacity":case"flex":case"flexGrow":case"flexNegative":case"flexOrder":case"flexPositive":case"flexShrink":case"floodOpacity":case"fontWeight":case"gridColumn":case"gridRow":case"lineClamp":case"lineHeight":case"opacity":case"order":case"orphans":case"stopOpacity":case"strokeDasharray":case"strokeDashoffset":case"strokeMiterlimit":case"strokeOpacity":case"strokeWidth":case"tabSize":case"widows":case"zIndex":case"zoom":return t;default:return t+"px"}}function ae(e,t,n,i,r,o,a){switch(e){case"onClick":case"onDblClick":case"onFocusIn":case"onFocusOut":case"onKeyDown":case"onKeyPress":case"onKeyUp":case"onMouseDown":case"onMouseMove":case"onMouseUp":case"onSubmit":case"onTouchEnd":case"onTouchMove":case"onTouchStart":M(e,n,i);break;case"children":case"childrenType":case"className":case"defaultValue":case"key":case"multiple":case"ref":break;case"autoFocus":i.autofocus=!!n;break;case"allowfullscreen":case"autoplay":case"capture":case"checked":case"controls":case"default":case"disabled":case"hidden":case"indeterminate":case"loop":case"muted":case"novalidate":case"open":case"readOnly":case"required":case"reversed":case"scoped":case"seamless":case"selected":i[e]=!!n;break;case"defaultChecked":case"value":case"volume":if(o&&"value"===e)return;var d=s(n)?"":n;i[e]!==d&&(i[e]=d);break;case"dangerouslySetInnerHTML":var f=t&&t.__html||"",p=n&&n.__html||"";f!==p&&(s(p)||I(i,p)||(h(a)||(12&a.childFlags?re(a.children):2===a.childFlags&&ie(a.children),a.children=null,a.childFlags=1),i.innerHTML=p));break;default:"o"===e[0]&&"n"===e[1]?function(e,t,n,i){var r,o,a=e.toLowerCase();if(l(n)||s(n)){var c=i[a];c&&c.wrapped||(i[a]=n)}else{var u=n.event;u&&l(u)&&(i[a]=(r=u,o=n,function(e){r(o.data,e)}))}}(e,0,n,i):s(n)?i.removeAttribute(e):"style"===e?function(e,t,n){var i,r,o=n.style;if(c(t))o.cssText=t;else if(s(e)||c(e))for(i in t)r=t[i],o[i]=u(r)?se(i,r):r;else{for(i in t)(r=t[i])!==e[i]&&(o[i]=u(r)?se(i,r):r);for(i in e)s(t[i])&&(o[i]="")}}(t,n,i):r&&P[e]?i.setAttributeNS(P[e],e,n):i.setAttribute(e,n)}}function le(e,t,n,i,r){var o=!1,s=0<(448&t);for(var a in s&&(o=te(n))&&function(e,t,n){var i,r,o;64&e?(o=t,B(n.type)?(o.onchange=H,o.onclick=q):o.oninput=W):256&e?t.onchange=Q:128&e&&(r=n,(i=t).oninput=G,r.onChange&&(i.onchange=J))}(t,i,n),n)ae(a,null,n[a],i,r,o,null);s&&ee(t,e,i,n,!0,o)}function ce(e,t,n,i){var r=new t(n,i);if((e.children=r).$V=e,r.$BS=!1,r.context=i,r.props===L&&(r.props=n),r.$UN=!1,l(r.componentWillMount)){if(r.$BR=!0,r.componentWillMount(),r.$PSS){var o=r.state,a=r.$PS;if(h(o))r.state=a;else for(var c in a)o[c]=a[c];r.$PSS=!1,r.$PS=null}r.$BR=!1}l(x.beforeRender)&&x.beforeRender(r);var u,d=ue(r.render(n,r.state,i),e);return l(r.getChildContext)&&(u=r.getChildContext()),s(u)?r.$CX=i:r.$CX=f(i,u),l(x.afterRender)&&x.afterRender(r),r.$LI=d,r}function ue(e,t){return a(e)?e=b():o(e)?e=m(e,null):(e.dom&&(e=_(e)),14&e.flags&&(e.parentVNode=t)),e}function he(e,t,n,i){var r=e.flags;return 481&r?fe(e,t,n,i):14&r?function(e,t,n,i,r){var o,s=e.type,a=e.props||L,l=e.ref;if(r){var c=ce(e,s,a,n);e.dom=o=he(c.$LI,null,c.$CX,i),ve(e,l,c),c.$UPD=!1}else{var u=ue(s(a,n),e);e.children=u,e.dom=o=he(u,null,n,i),ye(a,l,o)}return h(t)||N(t,o),o}(e,t,n,i,0<(4&r)):512&r||16&r?de(e,t):1024&r?(he(e.children,e.type,n,!1),e.dom=de(b(),t)):void 0}function de(e,t){var n=e.dom=document.createTextNode(e.children);return h(t)||N(t,n),n}function fe(e,t,n,i){var r=e.flags,o=e.children,a=e.props,c=e.className,u=e.ref,d=e.childFlags;i=i||0<(32&r);var f,p=(f=e.type,!0===i?document.createElementNS("http://www.w3.org/2000/svg",f):document.createElement(f));if(e.dom=p,s(c)||""===c||(i?p.setAttribute("class",c):p.className=c),h(t)||N(t,p),!(1&d)){var v=!0===i&&"foreignObject"!==e.type;2===d?he(o,p,n,v):12&d&&pe(o,p,n,v)}return h(a)||le(e,r,a,p,i),l(u)&&ge(p,u),p}function pe(e,t,n,i){for(var r=0,o=e.length;r<o;r++){var s=e[r];h(s.dom)||(e[r]=s=_(s)),he(s,t,n,i)}}function ve(e,t,n){var i;l(t)&&t(n),l(n.componentDidMount)&&A.push((i=n,function(){i.componentDidMount()}))}function ye(e,t,n){var i,r,o;s(t)||(l(t.onComponentWillMount)&&t.onComponentWillMount(e),l(t.onComponentDidMount)&&A.push((i=t,r=n,o=e,function(){return i.onComponentDidMount(r,o)})))}function ge(e,t){A.push((function(){return t(e)}))}function me(e,t,n,i){var r=e.flags;14&r?function(e,t,n,i,r){var o=e.type,s=e.ref,a=e.props||L;if(r){var l=ce(e,o,a,n),c=l.$LI;me(c,t,l.$CX,i),e.dom=c.dom,ve(0,s,l),l.$UPD=!1}else{var u=ue(o(a,n),e);me(u,t,n,i),e.children=u,e.dom=u.dom,ye(a,s,t)}}(e,t,n,i,0<(4&r)):481&r?function(e,t,n,i){var r,o,a=e.children,c=e.props,u=e.className,d=e.flags,f=e.ref;if(i=i||0<(32&d),1!==t.nodeType||t.tagName.toLowerCase()!==e.type){var p=fe(e,null,n,i);e.dom=p,$(t.parentNode,p,t)}else{var v=(e.dom=t).firstChild,y=e.childFlags;if(1&y)h(t.firstChild)||(r=t,o=c,Boolean(o&&o.dangerouslySetInnerHTML&&o.dangerouslySetInnerHTML.__html&&I(r,o.dangerouslySetInnerHTML.__html)))||(t.textContent="",448&d&&(t.defaultValue=""));else{for(var g=null;v;)g=v.nextSibling,8===v.nodeType&&("!"===v.data?t.replaceChild(document.createTextNode(""),v):t.removeChild(v)),v=g;if(v=t.firstChild,2===y)h(v)?he(a,t,n,i):(g=v.nextSibling,me(a,v,n,i),v=g);else if(12&y)for(var m=0,k=a.length;m<k;m++){var _=a[m];h(v)?he(_,t,n,i):(g=v.nextSibling,me(_,v,n,i),v=g)}for(;v;)g=v.nextSibling,t.removeChild(v),v=g}h(c)||le(e,d,c,t,i),s(u)?""!==t.className&&t.removeAttribute("class"):i?t.setAttribute("class",u):t.className=u,l(f)&&ge(t,f)}}(e,t,n,i):16&r?function(e,t){if(3!==t.nodeType){var n=de(e,null);e.dom=n,$(t.parentNode,n,t)}else{var i=e.children;t.nodeValue!==i&&(t.nodeValue=i),e.dom=t}}(e,t):512&r?e.dom=t:function(e){throw e||(e="a runtime error occured! Use Inferno in development environment to find the error."),new Error("Inferno Error: "+e)}()}function ke(e,t,n,i,r){ie(e),$(n,he(t,null,i,r),e.dom)}function _e(e,t,i,r,o){if(e!==t){var c=0|t.flags;e.flags!==c||2048&c?ke(e,t,i,r,o):481&c?function(e,t,n,i,r){var o=t.type;if(e.type!==o)ke(e,t,n,i,r);else{var a,c=e.dom,u=t.flags,h=e.props,d=t.props,f=!1,p=!1;if(t.dom=c,r=r||0<(32&u),h!==d){var v=h||L;if((a=d||L)!==L)for(var y in(f=0<(448&u))&&(p=te(a)),a){var g=v[y],m=a[y];g!==m&&ae(y,g,m,c,r,p,e)}if(v!==L)for(var k in v)a.hasOwnProperty(k)||s(v[k])||ae(k,v[k],null,c,r,p,e)}var _=e.children,b=t.children,w=t.ref,D=e.className,x=t.className;_!==b&&be(e.childFlags,t.childFlags,_,b,c,i,r&&"foreignObject"!==o),f&&ee(u,t,c,a,!1,p),D!==x&&(s(x)?c.removeAttribute("class"):r?c.setAttribute("class",x):c.className=x),l(w)&&e.ref!==w&&ge(c,w)}}(e,t,i,r,o):14&c?function(e,t,i,r,o,a){var c=t.type,u=e.key,h=t.key;if(e.type!==c||u!==h)ke(e,t,i,r,o);else{var d=t.props||L;if(a){var f=e.children;f.$UPD=!0,f.$V=t,we(f,f.state,t,d,i,r,o,!1,!1),f.$UPD=!1}else{var p=!0,v=e.props,y=t.ref,g=!s(y),m=e.children;if(t.dom=e.dom,t.children=m,g&&l(y.onComponentShouldUpdate)&&(p=y.onComponentShouldUpdate(v,d)),!1!==p){g&&l(y.onComponentWillUpdate)&&y.onComponentWillUpdate(v,d);var k=c(d,r);k!==n&&(_e(m,k=ue(k,t),i,r,o),t.children=k,t.dom=k.dom,g&&l(y.onComponentDidUpdate)&&y.onComponentDidUpdate(v,d))}else 14&m.flags&&(m.parentVNode=t)}}}(e,t,i,r,o,0<(4&c)):16&c?function(e,t,n){var i,r=t.children;h(n.firstChild)?(n.textContent=r,i=n.firstChild):(i=e.dom,r!==e.children&&(i.nodeValue=r)),t.dom=i}(e,t,i):512&c?t.dom=e.dom:function(e,t,n){var i=e.type,r=t.type,o=t.children;if(be(e.childFlags,t.childFlags,e.children,o,i,n,!1),t.dom=e.dom,i!==r&&!a(o)){var s=o.dom;i.removeChild(s),r.appendChild(s)}}(e,t,r)}}function be(e,t,n,i,r,o,s){switch(e){case 2:switch(t){case 2:_e(n,i,r,o,s);break;case 1:ne(n,r);break;default:ne(n,r),pe(i,r,o,s)}break;case 1:switch(t){case 2:he(i,r,o,s);break;case 1:break;default:pe(i,r,o,s)}break;default:if(12&t){var a=n.length,l=i.length;0===a?0<l&&pe(i,r,o,s):0===l?oe(r,n):8===t&&8===e?function(e,t,n,i,r,o,s){var a,l,c=o-1,u=s-1,h=0,d=e[h],f=t[h];e:{for(;d.key===f.key;){if(f.dom&&(t[h]=f=_(f)),_e(d,f,n,i,r),e[h]=f,c<++h||u<h)break e;d=e[h],f=t[h]}for(d=e[c],f=t[u];d.key===f.key;){if(f.dom&&(t[u]=f=_(f)),_e(d,f,n,i,r),e[c]=f,u--,--c<h||u<h)break e;d=e[c],f=t[u]}}if(c<h){if(h<=u)for(var p=(l=u+1)<s?t[l].dom:null;h<=u;)(f=t[h]).dom&&(t[h]=f=_(f)),h++,O(n,he(f,null,i,r),p)}else if(u<h)for(;h<=c;)ne(e[h++],n);else{var v=h,y=h,g=c-h+1,m=u-h+1,k=[];for(a=0;a<m;a++)k.push(0);var b=g===o,w=!1,D=0,x=0;if(s<4||(g|m)<32)for(a=v;a<=c;a++)if(d=e[a],x<m){for(h=y;h<=u;h++)if(f=t[h],d.key===f.key){if(k[h-y]=a+1,b)for(b=!1;v<a;)ne(e[v++],n);h<D?w=!0:D=h,f.dom&&(t[h]=f=_(f)),_e(d,f,n,i,r),x++;break}!b&&u<h&&ne(d,n)}else b||ne(d,n);else{var C={};for(a=y;a<=u;a++)C[t[a].key]=a;for(a=v;a<=c;a++)if(d=e[a],x<m)if(void 0!==(h=C[d.key])){if(b)for(b=!1;v<a;)ne(e[v++],n);f=t[h],k[h-y]=a+1,h<D?w=!0:D=h,f.dom&&(t[h]=f=_(f)),_e(d,f,n,i,r),x++}else b||ne(d,n);else b||ne(d,n)}if(b)oe(n,e),pe(t,n,i,r);else if(w){var S=function(e){var t,n,i,r,o,s=e.slice(),a=[0],l=e.length;for(t=0;t<l;t++){var c=e[t];if(0!==c){if(e[n=a[a.length-1]]<c){s[t]=n,a.push(t);continue}for(i=0,r=a.length-1;i<r;)e[a[o=(i+r)/2|0]]<c?i=o+1:r=o;c<e[a[i]]&&(0<i&&(s[t]=a[i-1]),a[i]=t)}}for(r=a[(i=a.length)-1];0<i--;)a[i]=r,r=s[r];return a}(k);for(h=S.length-1,a=m-1;0<=a;a--)0===k[a]?((f=t[D=a+y]).dom&&(t[D]=f=_(f)),l=D+1,O(n,he(f,null,i,r),l<s?t[l].dom:null)):h<0||a!==S[h]?(f=t[D=a+y],l=D+1,O(n,f.dom,l<s?t[l].dom:null)):h--}else if(x!==m)for(a=m-1;0<=a;a--)0===k[a]&&((f=t[D=a+y]).dom&&(t[D]=f=_(f)),l=D+1,O(n,he(f,null,i,r),l<s?t[l].dom:null))}}(n,i,r,o,s,a,l):function(e,t,n,i,r,o,s){for(var a,l,c=s<o?s:o,u=0;u<c;u++)a=t[u],l=e[u],a.dom&&(a=t[u]=_(a)),_e(l,a,n,i,r),e[u]=a;if(o<s)for(u=c;u<s;u++)(a=t[u]).dom&&(a=t[u]=_(a)),he(a,n,i,r);else if(s<o)for(u=c;u<o;u++)ne(e[u],n)}(n,i,r,o,s,a,l)}else 1===t?oe(r,n):(oe(r,n),he(i,r,o,s))}}function we(e,t,i,r,o,a,c,u,h){var d,p=e.state,v=e.props;if(!(i.children=e).$UN){if(v!==r||r===L){if(!h&&l(e.componentWillReceiveProps)){if(e.$BR=!0,e.componentWillReceiveProps(r,a),e.$UN)return;e.$BR=!1}e.$PSS&&(t=f(t,e.$PS),e.$PSS=!1,e.$PS=null)}var y=Boolean(e.shouldComponentUpdate);if(u||!y||y&&e.shouldComponentUpdate(r,t,a)){l(e.componentWillUpdate)&&(e.$BS=!0,e.componentWillUpdate(r,t,a),e.$BS=!1),e.props=r,e.state=t,e.context=a,l(x.beforeRender)&&x.beforeRender(e),d=e.render(r,t,a),l(x.afterRender)&&x.afterRender(e);var g,m=d!==n;l(e.getChildContext)&&(g=e.getChildContext()),g=s(g)?a:f(a,g),e.$CX=g,m&&(_e(e.$LI,e.$LI=ue(d,i),o,g,c),l(e.componentDidUpdate)&&e.componentDidUpdate(v,p))}else e.props=r,e.state=t,e.context=a;i.dom=e.$LI.dom}}i&&document.body;var De="undefined"==typeof Promise?null:Promise.resolve(),xe="undefined"==typeof requestAnimationFrame?setTimeout:requestAnimationFrame.bind(window);function Ce(e,t,n,i){l(t)&&(t=t(e.state,e.props,e.context));var r,o,a,c=e.$PS;if(s(c))e.$PS=t;else for(var u in t)c[u]=t[u];if(e.$PSS||e.$BR)e.$PSS=!0,e.$BR&&l(n)&&A.push(n.bind(e));else if(e.$UPD){var d=e.$QU;h(d)&&(d=e.$QU=[],o=e,a=d,r=function(){o.$QU=null,o.$UPD=!0,Se(o,!1,(function(){for(var e=0,t=a.length;e<t;e++)a[e].call(o)})),o.$UPD=!1},De?De.then(r):xe(r)),l(n)&&d.push(n)}else e.$PSS=!0,e.$UPD=!0,Se(e,i,n),e.$UPD=!1}function Se(e,t,n){if(!e.$UN){if(t||!e.$BR){e.$PSS=!1;var i=e.$PS,r=f(e.state,i),o=e.props,s=e.context;e.$PS=null;var a=e.$V,c=e.$LI;if(we(e,r,a,o,c.dom&&c.dom.parentNode,s,0<(32&a.flags),t,!0),e.$UN)return;if(!(1024&e.$LI.flags))for(var u=e.$LI.dom;!h(a=a.parentVNode);)0<(14&a.flags)&&(a.dom=u);0<A.length&&T(A)}else e.state=e.$PS,e.$PS=null;l(n)&&n.call(e)}}var Pe=function(e,t){this.state=null,this.$BR=!1,this.$BS=!0,this.$PSS=!1,this.$PS=null,this.$LI=null,this.$V=null,this.$UN=!1,this.$CX=null,this.$UPD=!0,this.$QU=null,this.props=e||L,this.context=t||L};Pe.prototype.forceUpdate=function(e){this.$UN||Ce(this,{},e,!0)},Pe.prototype.setState=function(e,t){this.$UN||this.$BS||Ce(this,e,t,!1)},Pe.prototype.render=function(e,t,n){};var Le=12,Ae=37,Ne=38,Oe=39,$e=40,Te=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},Ee=function(){function e(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)}}return function(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}}(),je=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e},Me=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)},Fe=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t},Ue=function(){function e(){return Te(this,e),Fe(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return Me(e,Pe),Ee(e,[{key:"click",value:function(e){var t=this,n=function(){t.props.node.toggleCheck()};this.props.dom._tree.emit("node.click",e,this.props.node,n),e.treeDefaultPrevented||n()}},{key:"render",value:function(){return y(64,"input",null,null,1,{checked:this.props.checked,indeterminate:this.props.indeterminate,onClick:this.click.bind(this),type:"checkbox"})}}]),e}(),Ie=function(t){var n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"li",i=t.itree[n].attributes,r=[],o=i.class||i.className;return e.isFunction(o)&&(o=o(t)),e.isEmpty(o)||(e.isString(o)?r=r.concat(o.split(/[\s\.]+/)):e.isArray(o)&&(r=r.concat(o))),r},Ve=function(){function e(){return Te(this,e),Fe(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return Me(e,Pe),Ee(e,[{key:"shouldComponentUpdate",value:function(){return!1}},{key:"add",value:function(e){e.stopPropagation(),this.props.node.addChild({text:"New Node",itree:{state:{editing:!0,focused:!0}}}),this.props.node.expand()}},{key:"edit",value:function(e){e.stopPropagation(),this.props.node.toggleEditing()}},{key:"remove",value:function(e){e.stopPropagation(),this.props.node.remove()}},{key:"render",value:function(){var e=[];return this.props.dom._tree.config.editing.edit&&e.push(y(1,"a","btn icon icon-pencil",null,1,{onclick:this.edit.bind(this),title:"Edit this node"})),this.props.dom._tree.config.editing.add&&e.push(y(1,"a","btn icon icon-plus",null,1,{onclick:this.add.bind(this),title:"Add a child node"})),this.props.dom._tree.config.editing.remove&&e.push(y(1,"a","btn icon icon-minus",null,1,{onclick:this.remove.bind(this),title:"Remove this node"})),y(1,"span","btn-group",e,0)}}]),e}(),Re=function(){function e(){return Te(this,e),Fe(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return Me(e,Pe),Ee(e,[{key:"render",value:function(){return y(1,"ol",null,y(1,"li","leaf",y(1,"span","title icon icon-file-empty empty",this.props.text,0),2),2)}}]),e}();function Be(t,n){var i=n.dirty||!1;return i||e.each(Object.keys(n),(function(e){if("dirty"!==e&&n[e]!==t[e])return!(i=!0)})),i}var We=function(){function e(t){Te(this,e);var n=Fe(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return n.state=n.getStateFromNodes(t.node),n}return Me(e,Pe),Ee(e,[{key:"getStateFromNodes",value:function(e){return{text:e.text}}},{key:"componentWillReceiveProps",value:function(e){this.setState(this.getStateFromNodes(e.node))}},{key:"shouldComponentUpdate",value:function(e,t){return Be(this.state,t)}},{key:"click",value:function(e){var t=this,n=function(){t.props.node.toggleCheck()};this.props.dom._tree.emit("node.click",e,this.props.node,n),e.treeDefaultPrevented||n()}},{key:"keypress",value:function(e){if(e.which===Le)return this.save()}},{key:"input",value:function(e){this.setState({text:e.target.value})}},{key:"cancel",value:function(e){e&&e.stopPropagation(),this.props.node.toggleEditing()}},{key:"save",value:function(e){e&&e.stopPropagation();var t=this.props.node.text,n=this.ref.value;this.props.node.set("text",n),this.props.node.state("editing",!1),this.props.node.markDirty(),this.props.dom._tree.applyChanges(),t!==n&&this.props.dom._tree.emit("node.edited",this.props.node,t,n)}},{key:"render",value:function(){var e=this;return y(1,"form",null,[y(64,"input",null,null,1,{onClick:function(e){return e.stopPropagation},onInput:this.input.bind(this),onKeyPress:this.keypress.bind(this),value:this.state.text},null,(function(t){return e.ref=t})),y(1,"span","btn-group",[y(1,"button","btn icon icon-check",null,1,{onClick:this.save.bind(this),title:"Save",type:"button"}),y(1,"button","btn icon icon-cross",null,1,{onClick:this.cancel.bind(this),title:"Cancel",type:"button"})],4)],4,{onsubmit:function(e){return e.preventDefault}})}}]),e}(),He=function(){function t(){return Te(this,t),Fe(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return Me(t,Pe),Ee(t,[{key:"blur",value:function(){this.props.node.blur()}},{key:"click",value:function(e){var t=this,n=this.props,i=n.node,r=n.dom,o=function(){if(e.preventDefault(),!t.props.editing){if((e.metaKey||e.ctrlKey||e.shiftKey)&&r._tree.disableDeselection(),e.shiftKey){r.clearSelection();var n=r._tree.lastSelectedNode();n&&r._tree.selectBetween.apply(r._tree,r._tree.boundingNodes(n,i))}i.selected()?r._tree.config.selection.disableDirectDeselection||i.deselect():i.select(),r._tree.enableDeselection()}};r._tree.emit("node.click",e,i,o),e.treeDefaultPrevented||o()}},{key:"contextMenu",value:function(e){var t=this.props,n=t.node;t.dom._tree.emit("node.contextmenu",e,n)}},{key:"dblclick",value:function(e){var t=this.props,n=t.node,i=t.dom,r=function(){i.clearSelection(),n.toggleCollapse()};i._tree.emit("node.dblclick",e,n,r),e.treeDefaultPrevented||r()}},{key:"focus",value:function(e){this.props.node.focus(e)}},{key:"mousedown",value:function(){this.props.dom.isDragDropEnabled&&(this.props.dom.isMouseHeld=!0)}},{key:"render",value:function(){var t=this.props.node,n=e.clone(t.itree.a.attributes)||{};n.tabindex=1,n.unselectable="on";var i=Ie(t,"a").concat(["title","icon"]);if(!this.props.dom.config.showCheckboxes){var r=this.props.expanded?"icon-folder-open":"icon-folder";i.push(t.itree.icon||(this.props.hasOrWillHaveChildren?r:"icon-file-empty"))}n.class=n.className=i.join(" ");var o=t.text;return t.editing()&&(o=g(2,We,{dom:this.props.dom,node:this.props.node})),k(y(1,"a",null,o,0,je({"data-uid":t.id,onBlur:this.blur.bind(this),onClick:this.click.bind(this),onContextMenu:this.contextMenu.bind(this),onDblClick:this.dblclick.bind(this),onFocus:this.focus.bind(this),onMouseDown:this.mousedown.bind(this)},n)))}}]),t}(),qe=function(){function e(){return Te(this,e),Fe(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return Me(e,Pe),Ee(e,[{key:"className",value:function(){return"toggle icon "+(this.props.collapsed?"icon-expand":"icon-collapse")}},{key:"render",value:function(){return y(1,"a",this.className(),null,1,{onClick:this.props.node.toggleCollapse.bind(this.props.node)})}}]),e}(),Ke=function(){function n(e){Te(this,n);var t=Fe(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,e));return t.state=t.stateFromNode(e.node),t}return Me(n,Pe),Ee(n,[{key:"stateFromNode",value:function(e){return{dirty:e.itree.dirty}}},{key:"componentWillReceiveProps",value:function(e){this.setState(this.stateFromNode(e.node))}},{key:"shouldComponentUpdate",value:function(e,t){return t.dirty}},{key:"getAttributes",value:function(){var t=this.props.node,n=e.clone(t.itree.li.attributes)||{};return n.class=n.className=this.getClassNames(),n["data-uid"]=t.id,this.props.dom.config.dragAndDrop.enabled&&(n.draggable=t.state("draggable"),n.onDragEnd=this.onDragEnd.bind(this),n.onDragEnter=this.onDragEnter.bind(this),n.onDragLeave=this.onDragLeave.bind(this),n.onDragStart=this.onDragStart.bind(this),t.state("drop-target")?(n.onDragOver=this.onDragOver.bind(this),n.onDrop=this.onDrop.bind(this)):(n.onDragOver=null,n.onDrop=null)),n}},{key:"getClassNames",value:function(){var t=this.props.node,n=t.itree.state,i=Ie(t);return e.each(Object.keys(n),(function(e){n[e]&&i.push(e)})),!t.hidden()&&t.removed()&&i.push("hidden"),t.expanded()&&i.push("expanded"),i.push(t.hasOrWillHaveChildren()?"folder":"leaf"),i.join(" ")}},{key:"getTargetDirection",value:function(e,t){var n=e.clientY,i=t.getBoundingClientRect(),r=i.top+i.height/3,o=i.bottom-i.height/3,s=0;return n<=r?s=-1:o<=n&&(s=1),s}},{key:"onDragStart",value:function(n){n.stopPropagation(),n.dataTransfer.effectAllowed="move",n.dataTransfer.dropEffect="move";var i=this.props.node;if(this.props.dom._activeDragNode=i,n.dataTransfer.setData("treeId",i.tree().id),n.dataTransfer.setData("nodeId",i.id),i.state("drop-target",!1),i.hasChildren()&&i.children.stateDeep("drop-target",!1),"dragstart"===this.props.dom.config.dragAndDrop.validateOn){var r=this.props.dom.config.dragAndDrop.validate,o=e.isFunction(r);this.props.dom._tree.batch(),function n(i,r){t.isTreeNodes(i)?e.each(i,(function(e){n(e,r)})):t.isTreeNode(i)&&!1!==r(i)&&i.hasChildren()&&n(i.children,r)}(this.props.dom._tree.model,(function(e){var t=e.id!==i.id;return t&&(t=!e.hasAncestor(i)),t&&o&&(t=r(i,e)),e.state("drop-target",t),t})),this.props.dom._tree.end()}this.props.dom._tree.emit("node.dragstart",n)}},{key:"onDragEnd",value:function(e){e.preventDefault(),e.stopPropagation(),this.unhighlightTarget(),this.props.dom._tree.emit("node.dragend",e)}},{key:"onDragEnter",value:function(e){e.preventDefault(),e.stopPropagation(),this.props.node.recurseUp(this.unhighlightTarget),this.props.node.state("drag-targeting",!0),this.props.dom._tree.emit("node.dragenter",e)}},{key:"onDragLeave",value:function(e){e.preventDefault(),e.stopPropagation(),this.unhighlightTarget(),this.props.dom._tree.emit("node.dragleave",e)}},{key:"onDragOver",value:function(t){t.preventDefault(),t.stopPropagation();var n=this.props.dom._activeDragNode,i=this.props.node,r=this.getTargetDirection(t,i.itree.ref.querySelector("a"));if("dragover"===this.props.dom.config.dragAndDrop.validateOn){var o=this.props.dom.config.dragAndDrop.validate,s=e.isFunction(o),a=n.id!==i.id;if(a&&(a=!i.hasAncestor(n)),a&&s&&(a=o(n,i,r)),i.state("drop-target",a),this.props.dom._tree.applyChanges(),!a)return}this.props.dom._tree.batch(),i.state("drag-targeting",!0),i.state("drag-targeting-above",-1===r),i.state("drag-targeting-below",1===r),i.state("drag-targeting-insert",0===r),this.props.dom._tree.end(),this.props.dom._tree.emit("node.dragover",t,r)}},{key:"onDrop",value:function(e){e.preventDefault(),e.stopPropagation(),this.unhighlightTarget();var t=e.dataTransfer.getData("treeId"),n=e.dataTransfer.getData("nodeId"),i=this.props.node;this.props.dom._activeDragNode=null;var r=this.getTargetDirection(e,e.target),o=void 0;t===this.props.dom._tree.id?o=this.props.dom._tree:t&&(o=document.querySelector('[data-uid="'+t+'"]').inspireTree);var s=void 0,a=void 0;if(o){var l=o.node(n);l.state("drop-target",!0);var c=l.remove(!0),u=i.context().indexOf(i);0===r?(s=i.addChild(c),a=i.children.indexOf(s),i.expand()):(a=1===r?++u:u,s=i.context().insertAt(a,c))}this.props.dom._tree.emit("node.drop",e,s,i,a)}},{key:"unhighlightTarget",value:function(e){(e||this.props.node).states(["drag-targeting","drag-targeting-above","drag-targeting-below","drag-targeting-insert"],!1)}},{key:"renderCheckbox",value:function(){var e=this.props.node;if(this.props.dom.config.showCheckboxes)return g(2,Ue,{checked:e.checked(),dom:this.props.dom,indeterminate:e.indeterminate(),node:e})}},{key:"renderChildren",value:function(){var e=this.props,t=e.node,n=e.dom;if(t.hasChildren()){var i=t.children,r=n.loading,o=i.pagination();return g(2,ze,{context:t,dom:n,limit:o.limit,loading:r,nodes:i,total:o.total})}if(this.props.dom.isDynamic&&t.children)return t.hasLoadedChildren()?g(2,Re,{text:"No Results"}):g(2,Re,{text:"Loading..."})}},{key:"renderEditToolbar",value:function(){if(this.props.dom._tree.config.editing.edit&&!this.props.node.editing())return g(2,Ve,{dom:this.props.dom,node:this.props.node})}},{key:"renderToggle",value:function(){var e=this.props.node;if(this.props.dom.isDynamic?Boolean(e.children):e.hasVisibleChildren())return g(2,qe,{collapsed:e.collapsed(),node:e})}},{key:"render",value:function(){var e=this,t=this.props.node,n=k(y(1,"li",null,[this.renderEditToolbar(),y(1,"div","title-wrap",[this.renderToggle(),this.renderCheckbox(),g(2,He,{dom:this.props.dom,editing:t.editing(),expanded:t.expanded(),hasOrWillHaveChildren:t.hasOrWillHaveChildren(),node:t,text:t.text})],0),y(1,"div","wholerow"),this.renderChildren()],0,je({},this.getAttributes()),null,(function(t){return e.node=e.props.node.itree.ref=t})));return this.props.node.state("rendered",!0),this.props.node.itree.dirty=!1,n}}]),n}(),ze=function(){function t(){return Te(this,t),Fe(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return Me(t,Pe),Ee(t,[{key:"shouldComponentUpdate",value:function(t){return e.find(t.nodes,"itree.dirty")||Be(this.props,t)}},{key:"isDeferred",value:function(){return this.props.dom.config.deferredRendering||this.props.dom._tree.config.deferredLoading}},{key:"loadMore",value:function(e){e.preventDefault(),this.props.context?this.props.context.loadMore(e):this.props.dom._tree.loadMore(e)}},{key:"renderLoadMoreNode",value:function(){return y(1,"li","leaf detached",y(1,"a","title icon icon-more load-more",m("Load More"),2,{onClick:this.loadMore.bind(this)}),2)}},{key:"renderLoadingTextNode",value:function(){return y(1,"li","leaf",y(1,"span","title icon icon-more",m("Loading..."),2),2)}},{key:"render",value:function(){var t=this,n=this.props.nodes,i=n.pagination();if(this.props.dom.config.deferredRendering){var r=0;n=this.props.nodes.filter((function(e){var t=!(e.hidden()||e.removed());return t&&r++,r<=i.limit&&t}))}var o=e.map(n,(function(e){return g(2,Ke,{dom:t.props.dom,node:e},e.id)}));return this.isDeferred()&&i.limit<i.total&&(this.props.loading?o.push(this.renderLoadingTextNode()):o.push(this.renderLoadMoreNode())),y(1,"ol",null,[o,this.props.children],0)}}]),t}(),Xe=function(){function e(){return Te(this,e),Fe(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return Me(e,Pe),Ee(e,[{key:"add",value:function(){this.props.dom._tree.focused().blur(),this.props.dom._tree.addNode({text:"New Node",itree:{state:{editing:!0,focused:!0}}})}},{key:"renderAddLink",value:function(){if(this.props.dom._tree.config.editing.add)return y(1,"li",null,y(1,"a","btn icon icon-plus",null,1,{onClick:this.add.bind(this),title:"Add a new root node"}),2)}},{key:"render",value:function(){var e=this.props,t=e.dom,n=e.nodes,i=t.loading,r=n.pagination();return g(2,ze,{dom:t,limit:r.limit,loading:i,nodes:n,total:r.total,children:this.renderAddLink()})}}]),e}();return function(){function i(n,r){var o=this;if(Te(this,i),!(n instanceof t))throw new TypeError("Tree argument is not an InspireTree instance.");if(this._tree=n,this.batching=0,this.dropTargets=[],this.$scrollLayer,!r.target)throw new TypeError("Invalid `target` property - must be a selector, HTMLElement, or jQuery element.");var s={enabled:!(n.usesNativeDOM=!0),validateOn:"dragstart",validate:null};this.config=e.defaultsDeep({},r,{autoLoadMore:!0,deferredRendering:!1,dragAndDrop:s,nodeHeight:25,showCheckboxes:!1,tabindex:-1,target:!1}),!0===r.dragAndDrop&&(this.config.dragAndDrop=s,this.config.dragAndDrop.enabled=!0),"checkbox"!==n.config.selection.mode||e.isBoolean(e.get(r,"showCheckboxes"))||(this.config.showCheckboxes=!0),this.isDynamic=e.isFunction(this._tree.config.data),this.attach(this.config.target);var a=!0;n.on("changes.applied",(function(){o.renderNodes(),a&&(o.scrollSelectedIntoView(),a=!1)})),this.renderNodes()}return Ee(i,[{key:"attach",value:function(t){if(this.$target=this.getElement(t),this.$scrollLayer=this.getScrollableAncestor(this.$target),!this.$target)throw new Error("No valid element to attach to.");this.$target.setAttribute("data-uid",this._tree.id);var n=this.$target.className.split(" ");if(n.push("inspire-tree"),this._tree.config.editable&&(n.push("editable"),e.each(e.pickBy(this._tree.config.editing,e.identity),(function(e,t){n.push("editable-"+t)}))),this.$target.className=n.join(" "),this.$target.setAttribute("tabindex",this.config.tabindex||0),this.$target.addEventListener("keydown",this.keyboardListener.bind(this)),this.config.dragAndDrop.enabled&&(this.$target.addEventListener("dragenter",this.onDragEnter.bind(this),!1),this.$target.addEventListener("dragleave",this.onDragLeave.bind(this),!1),this.$target.addEventListener("dragover",this.onDragOver.bind(this),!1),this.$target.addEventListener("drop",this.onDrop.bind(this),!1),this.$target.classList.add("drag-and-drop")),this._tree.on("node.focused",(function(e){var t=e.itree.ref.querySelector(".title");t!==document.activeElement&&t.focus()})),this.config.deferredRendering||this._tree.config.deferredLoading){var i=this._tree.config.pagination.limit;this._tree.config.pagination.limit=0<i?i:e.ceil(this.$scrollLayer.clientHeight/this.config.nodeHeight),this.config.autoLoadMore&&this.$target.addEventListener("scroll",e.throttle(this.scrollListener.bind(this),20))}this.$target.inspireTree=this._tree}},{key:"clearSelection",value:function(){document.selection&&document.selection.empty?document.selection.empty():window.getSelection&&window.getSelection().removeAllRanges()}},{key:"getElement",value:function(t){var n=void 0;if(t instanceof HTMLElement)n=t;else if(e.isObject(t)&&e.isObject(t[0]))n=t[0];else if(e.isString(t)){var i=document.querySelector(t);i&&(n=i)}return n}},{key:"getScrollableAncestor",value:function(e){return e instanceof Element&&"auto"!==getComputedStyle(e).overflow&&e.parentNode&&(e=this.getScrollableAncestor(e.parentNode)),e}},{key:"keyboardListener",value:function(e){if(e.stopPropagation(),!([$e,Le,Ae,Oe,Ne].indexOf(e.which)<0)){var t=this._tree.focused();if(t.length)switch(e.preventDefault(),e.which){case $e:this.moveFocusDownFrom(t[0]);break;case Le:t[0].toggleSelect();break;case Ae:t[0].collapse();break;case Oe:t[0].expand();break;case Ne:this.moveFocusUpFrom(t[0])}}}},{key:"moveFocusDownFrom",value:function(e){var t=e.nextVisibleNode();t&&t.focus()}},{key:"moveFocusUpFrom",value:function(e){var t=e.previousVisibleNode();t&&t.focus()}},{key:"nodeFromTitleDOMElement",value:function(e){var t=e.parentNode.parentNode.getAttribute("data-uid");return this._tree.node(t)}},{key:"onDragEnter",value:function(e){e.preventDefault(),e.target.classList.add("drag-targeting","drag-targeting-insert")}},{key:"onDragLeave",value:function(e){e.preventDefault(),this.unhighlightTarget(e.target)}},{key:"onDragOver",value:function(e){e.preventDefault()}},{key:"onDrop",value:function(e){e.preventDefault(),this.unhighlightTarget(e.target);var t=e.dataTransfer.getData("treeId"),n=e.dataTransfer.getData("nodeId"),r=i.getTreeById(t).node(n);r.state("drop-target",!0);var o=r.remove(!0),s=this._tree.addNode(o),a=this._tree.indexOf(s);this._tree.emit("node.drop",e,s,null,a)}},{key:"renderNodes",value:function(e){!function(e,t,i){if(e!==n){var r=t.$V;s(r)?a(e)||(e.dom&&(e=_(e)),h(t.firstChild)?(he(e,t,L,!1),t.$V=e):function(e,t,n){var i=t.firstChild;if(!h(i))for(a(e)||me(e,i,L,!1),i=t.firstChild;i=i.nextSibling;)t.removeChild(i);0<A.length&&T(A),t.$V=e,l(n)&&n()}(e,t),r=e):s(e)?(ne(r,t),t.$V=null):(e.dom&&(e=_(e)),_e(r,e,t,L,!1),r=t.$V=e),0<A.length&&T(A),l(i)&&i(),l(x.renderComplete)&&x.renderComplete(r),r&&14&r.flags&&r.children}}(g(2,Xe,{dom:this,nodes:e||this._tree.nodes()}),this.$target)}},{key:"scrollListener",value:function(t){var n=this;if(!this.rendering&&!this.loading){var i=this.$scrollLayer.getBoundingClientRect(),r=document.querySelectorAll(".load-more");e.each(r,(function(e){var r=e.getBoundingClientRect();if(!(i.right<r.left||i.left>r.right||i.bottom<r.top||i.top>r.bottom)){var o=void 0,s=e.parentNode.parentNode.parentNode;"LI"===s.tagName&&(o=n._tree.node(s.getAttribute("data-uid"))),n._tree.loadMore(o,t)}}))}}},{key:"scrollSelectedIntoView",value:function(){var e=this.$target.querySelector(".selected");e&&this.$scrollLayer&&(this.$scrollLayer.scrollTop=e.offsetTop)}},{key:"unhighlightTarget",value:function(e){e&&e.classList.remove("drag-targeting","drag-targeting-insert")}}],[{key:"getTreeById",value:function(e){var t=document.querySelector('[data-uid="'+e+'"]');if(t)return t.inspireTree}}]),i}()}));