!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;s2&&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+11)&&(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&&i0&&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;r0&&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;o3)for(t=new Array(l-1),o=1;o3)for(t=new Array(c),o=1;o3)for(t=new Array(c-1),o=1;o0&&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;a0&&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;nr.right||i.bottomr.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}()}));