UNPKG

xeokit-viewer

Version:

BIM viewer built on xeokit and Bootstrap

9 lines (8 loc) 40.3 kB
/* Inspire Tree DOM * @version 4.0.4 * https://github.com/helion3/inspire-tree-dom * @copyright Copyright 2015 Helion3, and other contributors * @license Licensed under MIT * see https://github.com/helion3/inspire-tree-dom/blob/master/LICENSE */ !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",o="a runtime error occured! Use Inferno in development environment to find the error.",r=!("undefined"==typeof window||!window.document),i=Array.isArray;function a(e){var t=typeof e;return"string"===t||"number"===t}function s(e){return f(e)||p(e)}function l(e){return p(e)||!1===e||function(e){return!0===e}(e)||f(e)}function d(e){return"function"==typeof e}function c(e){return"string"==typeof e}function u(e){return"number"==typeof e}function p(e){return null===e}function f(e){return void 0===e}function h(e){return void 0!==e}function v(e,t){var n={};if(e)for(var o in e)n[o]=e[o];if(t)for(var r in t)n[r]=t[r];return n}var g="$";function m(e,t,n,o,r,i,a,s){return{childFlags:e,children:t,className:n,dom:null,flags:o,key:void 0===r?null:r,parentVNode:null,props:void 0===i?null:i,ref:void 0===a?null:a,type:s}}function y(e,t,n,o,r,i,a,s){var l=void 0===r?1:r,d=m(l,o,n,e,a,i,s,t),c=N.createVNode;return"function"==typeof c&&c(d),0===l&&w(d,d.children),d}function b(e,t,n,o,r){(2&e)>0&&(e=h(t.prototype)&&d(t.prototype.render)?4:8);var i=t.defaultProps;if(!s(i))for(var a in n||(n={}),i)f(n[a])&&(n[a]=i[a]);if((8&e)>0){var l=t.defaultHooks;if(!s(l))if(r)for(var c in l)f(r[c])&&(r[c]=l[c]);else r=l}var u=m(1,null,null,e,o,n,r,t),p=N.createVNode;return d(p)&&p(u),u}function k(e,t){return m(1,s(e)?"":e,null,16,t,null,null,null)}function D(e){var t=e.props;if(t){var n=e.flags;481&n&&(h(t.children)&&s(e.children)&&w(e,t.children),h(t.className)&&(e.className=t.className||null,t.className=void 0)),h(t.key)&&(e.key=t.key,t.key=void 0),h(t.ref)&&(e.ref=8&n?v(e.ref,t.ref):t.ref,t.ref=void 0)}return e}function $(e){var t,n=e.flags;if(14&n){var o,r=e.props;if(!p(r))for(var i in o={},r)o[i]=r[i];t=b(n,e.type,o,e.key,e.ref)}else if(481&n){var a=e.children;t=y(n,e.type,e.className,a,0,e.props,e.key,e.ref)}else 16&n?t=k(e.children,e.key):1024&n&&(t=e);return t}function C(){return k("",null)}function x(e,t,n,o){for(var r=e.length;n<r;n++){var s=e[n];if(!l(s)){var d=o+g+n;if(i(s))x(s,t,0,d);else{if(a(s))s=k(s,d);else{var u=s.key,f=c(u)&&u[0]===g;p(s.dom)&&!f||(s=$(s)),p(u)||f?s.key=d:s.key=o+u}t.push(s)}}}}function w(e,t){var n,o=1;if(l(t))n=t;else if(c(t))o=2,n=k(t);else if(u(t))o=2,n=k(t+"");else if(i(t)){var r=t.length;if(0===r)n=null,o=1;else{(Object.isFrozen(t)||!0===t.$)&&(t=t.slice()),o=8;for(var s=0;s<r;s++){var d=t[s];if(l(d)||i(d)){x(t,n=n||t.slice(0,s),s,"");break}if(a(d))(n=n||t.slice(0,s)).push(k(d,g+s));else{var f=d.key,h=p(d.dom),v=p(f),m=!v&&f[0]===g;!h||v||m?(n=n||t.slice(0,s),h&&!m||(d=$(d)),(v||m)&&(d.key=g+s),n.push(d)):n&&n.push(d)}}(n=n||t).$=!0}}else n=t,p(t.dom)||(n=$(t)),o=2;return e.children=n,e.childFlags=o,e}var N={afterMount:null,afterRender:null,afterUpdate:null,beforeRender:null,beforeUnmount:null,createVNode:null,roots:[]},S="http://www.w3.org/1999/xlink",P="http://www.w3.org/XML/1998/namespace",O="http://www.w3.org/2000/svg",T={"xlink:actuate":S,"xlink:arcrole":S,"xlink:href":S,"xlink:role":S,"xlink:show":S,"xlink:title":S,"xlink:type":S,"xml:base":P,"xml:lang":P,"xml:space":P},L={},U=[];function M(e,t){e.appendChild(t)}function E(e,t,n){s(n)?M(e,t):e.insertBefore(t,n)}function F(e,t,n){e.replaceChild(t,n)}function A(e){for(var t;void 0!==(t=e.shift());)t()}var I={},V={};function R(e,t,n){var o=I[e],r=n.$EV;t?(o||(V[e]=function(e){var t=function(t){var n=t.type,o="click"===n||"dblclick"===n;if(o&&0!==t.button)return t.preventDefault(),t.stopPropagation(),!1;t.stopPropagation=B;var r={dom:document};try{Object.defineProperty(t,"currentTarget",{configurable:!0,get:function(){return r.dom}})}catch(e){}!function(e,t,n,o,r){var i=t;for(;!p(i);){if(n&&i.disabled)return;var a=i.$EV;if(a){var s=a[o];if(s&&(r.dom=i,s.event?s.event(s.data,e):s(e),e.cancelBubble))return}i=i.parentNode}}(t,t.target,o,e,r)};return document.addEventListener(j(e),t),t}(e),I[e]=0),r||(r=n.$EV={}),r[e]||I[e]++,r[e]=t):r&&r[e]&&(I[e]--,1===o&&(document.removeEventListener(j(e),V[e]),V[e]=null),r[e]=t)}function j(e){return e.substr(2).toLowerCase()}function B(){this.cancelBubble=!0,this.stopImmediatePropagation()}function W(e,t){var n=document.createElement("i");return n.innerHTML=t,n.innerHTML===e.innerHTML}function H(e,t,n){if(e[t]){var o=e[t];o.event?o.event(o.data,n):o(n)}else{var r=t.toLowerCase();e[r]&&e[r](n)}}function q(e,t){var n=function(n){n.stopPropagation();var o=this.$V;if(o){var r=o.props||L,i=o.dom;if(c(e))H(r,e,n);else for(var a=0;a<e.length;a++)H(r,e[a],n);if(d(t)){var s=this.$V,l=s.props||L;t(l,i,!1,s)}}};return Object.defineProperty(n,"wrapped",{configurable:!1,enumerable:!1,value:!0,writable:!1}),n}function K(e){return"checkbox"===e||"radio"===e}var X=q("onInput",G),Q=q(["onClick","onChange"],G);function z(e){e.stopPropagation()}function G(e,t){var n=e.type,o=e.value,r=e.checked,i=e.multiple,a=e.defaultValue,l=!s(o);n&&n!==t.type&&t.setAttribute("type",n),s(i)||i===t.multiple||(t.multiple=i),s(a)||l||(t.defaultValue=a+""),K(n)?(l&&(t.value=o),s(r)||(t.checked=r)):l&&t.value!==o?(t.defaultValue=o,t.value=o):s(r)||(t.checked=r)}function Y(e,t){if("optgroup"===e.type){var n=e.children,o=e.childFlags;if(12&o)for(var r=0,i=n.length;r<i;r++)J(n[r],t);else 2===o&&J(n,t)}else J(e,t)}function J(e,t){var n=e.props||L,o=e.dom;o.value=n.value,i(t)&&-1!==t.indexOf(n.value)||n.value===t?o.selected=!0:s(t)&&s(n.selected)||(o.selected=n.selected||!1)}z.wrapped=!0;var Z=q("onChange",ee);function ee(e,t,n,o){var r=Boolean(e.multiple);s(e.multiple)||r===t.multiple||(t.multiple=r);var i=o.childFlags;if(0==(1&i)){var a=o.children,l=e.value;if(n&&s(l)&&(l=e.defaultValue),12&i)for(var d=0,c=a.length;d<c;d++)Y(a[d],l);else 2===i&&Y(a,l)}}var te=q("onInput",oe),ne=q("onChange");function oe(e,t,n){var o=e.value,r=t.value;if(s(o)){if(n){var i=e.defaultValue;s(i)||i===r||(t.defaultValue=i,t.value=i)}}else r!==o&&(t.defaultValue=o,t.value=o)}function re(e,t,n,o,r,i){64&e?G(o,n):256&e?ee(o,n,r,t):128&e&&oe(o,n,r),i&&(n.$V=t)}function ie(e,t,n){64&e?function(e,t){K(t.type)?(e.onchange=Q,e.onclick=z):e.oninput=X}(t,n):256&e?function(e){e.onchange=Z}(t):128&e&&function(e,t){e.oninput=te,t.onChange&&(e.onchange=ne)}(t,n)}function ae(e){return e.type&&K(e.type)?!s(e.checked):!s(e.value)}function se(e,t){le(e),p(t)||(!function(e,t){e.removeChild(t)}(t,e.dom),e.dom=null)}function le(e){var t=e.flags;if(481&t){var n=e.ref,o=e.props;d(n)&&n(null);var r=e.children,i=e.childFlags;if(12&i?de(r):2===i&&le(r),!p(o))for(var a in o)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":R(a,null,e.dom)}}else if(14&t){var l=e.children,c=e.ref;4&t?(d(N.beforeUnmount)&&N.beforeUnmount(e),d(l.componentWillUnmount)&&l.componentWillUnmount(),d(c)&&c(null),l.$UN=!0,le(l.$LI)):(!s(c)&&d(c.onComponentWillUnmount)&&c.onComponentWillUnmount(e.dom,e.props||L),le(l))}else if(1024&t){var u=e.children;p(u)||"object"!=typeof u||se(u,e.type)}}function de(e){for(var t=0,n=e.length;t<n;t++)le(e[t])}function ce(e,t){de(t),e.textContent=""}function ue(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 pe(e,t,n,o,r,i,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":R(e,n,o);break;case"children":case"childrenType":case"className":case"defaultValue":case"key":case"multiple":case"ref":return;case"allowfullscreen":case"autoFocus":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":o[e="autoFocus"===e?e.toLowerCase():e]=!!n;break;case"defaultChecked":case"value":case"volume":if(i&&"value"===e)return;var l=s(n)?"":n;o[e]!==l&&(o[e]=l);break;case"dangerouslySetInnerHTML":var f=t&&t.__html||"",h=n&&n.__html||"";f!==h&&(s(h)||W(o,h)||(p(a)||(12&a.childFlags?de(a.children):2===a.childFlags&&le(a.children),a.children=null,a.childFlags=1),o.innerHTML=h));break;default:"o"===e[0]&&"n"===e[1]?function(e,t,n,o){var r=e.toLowerCase();if(d(n)||s(n)){var i=o[r];i&&i.wrapped||(o[r]=n)}else{var a=n.event;a&&d(a)&&(o[r]=function(e,t){return function(n){e(t.data,n)}}(a,n))}}(e,0,n,o):s(n)?o.removeAttribute(e):"style"===e?function(e,t,n){var o,r,i=n.style;if(c(t))i.cssText=t;else if(s(e)||c(e))for(o in t)r=t[o],i[o]=u(r)?ue(o,r):r;else{for(o in t)(r=t[o])!==e[o]&&(i[o]=u(r)?ue(o,r):r);for(o in e)s(t[o])&&(i[o]="")}}(t,n,o):r&&T[e]?o.setAttributeNS(T[e],e,n):o.setAttribute(e,n)}}function fe(e,t,n,o,r){var i=!1,a=(448&t)>0;for(var s in a&&(i=ae(n))&&ie(t,o,n),n)pe(s,null,n[s],o,r,i,null);a&&re(t,e,o,n,!0,i)}function he(e,t,n,o){var r=new t(n,o);if(e.children=r,r.$V=e,r.$BS=!1,r.context=o,r.props===L&&(r.props=n),r.$UN=!1,d(r.componentWillMount)){if(r.$BR=!0,r.componentWillMount(),r.$PSS){var i=r.state,a=r.$PS;if(p(i))r.state=a;else for(var l in a)i[l]=a[l];r.$PSS=!1,r.$PS=null}r.$BR=!1}d(N.beforeRender)&&N.beforeRender(r);var c,u=ve(r.render(n,r.state,o),e);return d(r.getChildContext)&&(c=r.getChildContext()),s(c)?r.$CX=o:r.$CX=v(o,c),d(N.afterRender)&&N.afterRender(r),r.$LI=u,r}function ve(e,t){return l(e)?e=C():a(e)?e=k(e,null):(e.dom&&(e=$(e)),14&e.flags&&(e.parentVNode=t)),e}function ge(e,t,n,o,r){var i=e.flags;return 481&i?ye(e,t,n,o,r):14&i?function(e,t,n,o,r,i){var a,s=e.type,l=e.props||L,d=e.ref;if(i){var c=he(e,s,l,o);e.dom=a=ge(c.$LI,null,n,c.$CX,r),ke(e,d,c,n),c.$UPD=!1}else{var u=ve(s(l,o),e);e.children=u,e.dom=a=ge(u,null,n,o,r),De(l,d,a,n)}p(t)||M(t,a);return a}(e,t,n,o,r,(4&i)>0):512&i||16&i?me(e,t):1024&i?(ge(e.children,e.type,n,o,!1),e.dom=me(C(),t)):void 0}function me(e,t){var n=e.dom=document.createTextNode(e.children);return p(t)||M(t,n),n}function ye(e,t,n,o,r){var i=e.flags,a=e.children,l=e.props,c=e.className,u=e.ref,f=e.childFlags;r=r||(32&i)>0;var h=function(e,t){return!0===t?document.createElementNS(O,e):document.createElement(e)}(e.type,r);if(e.dom=h,s(c)||""===c||(r?h.setAttribute("class",c):h.className=c),p(t)||M(t,h),0==(1&f)){var v=!0===r&&"foreignObject"!==e.type;2===f?ge(a,h,n,o,v):12&f&&be(a,h,n,o,v)}return p(l)||fe(e,i,l,h,r),d(u)&&$e(h,u,n),h}function be(e,t,n,o,r){for(var i=0,a=e.length;i<a;i++){var s=e[i];p(s.dom)||(e[i]=s=$(s)),ge(s,t,n,o,r)}}function ke(e,t,n,o){d(t)&&t(n);var r=d(n.componentDidMount),i=N.afterMount,a=d(i);(r||a)&&o.push(function(e,t,n,o,r){return function(){e.$UPD=!0,t&&n(o),r&&e.componentDidMount(),e.$UPD=!1}}(n,a,i,e,r))}function De(e,t,n,o){s(t)||(d(t.onComponentWillMount)&&t.onComponentWillMount(e),d(t.onComponentDidMount)&&o.push(function(e,t,n){return function(){return e.onComponentDidMount(t,n)}}(t,n,e)))}function $e(e,t,n){n.push(function(){return t(e)})}function _e(e,t,n,o,r){var i=e.children,a=e.props,l=e.className,c=e.flags,u=e.ref;if(r=r||(32&c)>0,1!==t.nodeType||t.tagName.toLowerCase()!==e.type){var f=ye(e,null,n,o,r);e.dom=f,F(t.parentNode,f,t)}else{e.dom=t;var h=t.firstChild,v=e.childFlags;if(0==(1&v)){for(var g=null;h;)g=h.nextSibling,8===h.nodeType&&("!"===h.data?t.replaceChild(document.createTextNode(""),h):t.removeChild(h)),h=g;if(h=t.firstChild,2===v)p(h)?ge(i,t,n,o,r):(g=h.nextSibling,Ce(i,h,n,o,r),h=g);else if(12&v)for(var m=0,y=i.length;m<y;m++){var b=i[m];p(h)?ge(b,t,n,o,r):(g=h.nextSibling,Ce(b,h,n,o,r),h=g)}for(;h;)g=h.nextSibling,t.removeChild(h),h=g}else p(t.firstChild)||function(e,t){return Boolean(t&&t.dangerouslySetInnerHTML&&t.dangerouslySetInnerHTML.__html&&W(e,t.dangerouslySetInnerHTML.__html))}(t,a)||(t.textContent="",448&c&&(t.defaultValue=""));p(a)||fe(e,c,a,t,r),s(l)?""!==t.className&&t.removeAttribute("class"):r?t.setAttribute("class",l):t.className=l,d(u)&&$e(t,u,n)}}function Ce(e,t,n,r,i){var a=e.flags;14&a?function(e,t,n,o,r,i){var a=e.type,s=e.ref,l=e.props||L;if(i){var d=he(e,a,l,o),c=d.$LI;Ce(c,t,n,d.$CX,r),e.dom=c.dom,ke(e,s,d,n),d.$UPD=!1}else{var u=ve(a(l,o),e);Ce(u,t,n,o,r),e.children=u,e.dom=u.dom,De(l,s,t,n)}}(e,t,n,r,i,(4&a)>0):481&a?_e(e,t,n,r,i):16&a?function(e,t){if(3!==t.nodeType){var n=me(e,null);e.dom=n,F(t.parentNode,n,t)}else{var o=e.children;t.nodeValue!==o&&(t.nodeValue=o),e.dom=t}}(e,t):512&a?e.dom=t:function(e){throw e||(e=o),new Error("Inferno Error: "+e)}()}function xe(e,t,n,o,r,i){le(e),F(n,ge(t,null,o,r,i),e.dom)}function we(e,t,o,r,i,a){if(e!==t){var c=0|t.flags;e.flags!==c||2048&c?xe(e,t,o,r,i,a):481&c?function(e,t,n,o,r,i){var a=t.type;if(e.type!==a)xe(e,t,n,o,r,i);else{var l,c=e.dom,u=t.flags,p=e.props,f=t.props,h=!1,v=!1;if(t.dom=c,i=i||(32&u)>0,p!==f){var g=p||L;if((l=f||L)!==L)for(var m in(h=(448&u)>0)&&(v=ae(l)),l){var y=g[m],b=l[m];y!==b&&pe(m,y,b,c,i,v,e)}if(g!==L)for(var k in g)l.hasOwnProperty(k)||s(g[k])||pe(k,g[k],null,c,i,v,e)}var D=e.children,$=t.children,_=t.ref,C=e.className,x=t.className;D!==$&&Ne(e.childFlags,t.childFlags,D,$,c,o,r,i&&"foreignObject"!==a),h&&re(u,t,c,l,!1,v),C!==x&&(s(x)?c.removeAttribute("class"):i?c.setAttribute("class",x):c.className=x),d(_)&&e.ref!==_&&$e(c,_,o)}}(e,t,o,r,i,a):14&c?function(e,t,o,r,i,a,l){var c=t.type,u=e.key,p=t.key;if(e.type!==c||u!==p)xe(e,t,o,r,i,a);else{var f=t.props||L;if(l){var h=e.children;h.$UPD=!0,Se(h,h.state,t,f,o,r,i,a,!1,!1),h.$V=t,h.$UPD=!1}else{var v=!0,g=e.props,m=t.ref,y=!s(m),b=e.children;if(t.dom=e.dom,t.children=b,y&&d(m.onComponentShouldUpdate)&&(v=m.onComponentShouldUpdate(g,f)),!1!==v){y&&d(m.onComponentWillUpdate)&&m.onComponentWillUpdate(g,f);var k=c(f,i);k!==n&&(k=ve(k,t),we(b,k,o,r,i,a),t.children=k,t.dom=k.dom,y&&d(m.onComponentDidUpdate)&&m.onComponentDidUpdate(g,f))}else 14&b.flags&&(b.parentVNode=t)}}}(e,t,o,r,i,a,(4&c)>0):16&c?function(e,t,n){var o,r=t.children;p(n.firstChild)?(n.textContent=r,o=n.firstChild):(o=e.dom,r!==e.children&&(o.nodeValue=r));t.dom=o}(e,t,o):512&c?t.dom=e.dom:function(e,t,n,o){var r=e.type,i=t.type,a=t.children;if(Ne(e.childFlags,t.childFlags,e.children,a,r,n,o,!1),t.dom=e.dom,r!==i&&!l(a)){var s=a.dom;r.removeChild(s),i.appendChild(s)}}(e,t,r,i)}}function Ne(e,t,n,o,r,i,a,s){switch(e){case 2:switch(t){case 2:we(n,o,r,i,a,s);break;case 1:se(n,r);break;default:se(n,r),be(o,r,i,a,s)}break;case 1:switch(t){case 2:ge(o,r,i,a,s);break;case 1:break;default:be(o,r,i,a,s)}break;default:if(12&t){var l=n.length,d=o.length;0===l?d>0&&be(o,r,i,a,s):0===d?ce(r,n):8===t&&8===e?function(e,t,n,o,r,i,a,s){var l,d,c,u,f,v,g,m=a-1,y=s-1,b=0,k=0,D=e[b],_=t[k],C=e[m],x=t[y];_.dom&&(t[k]=_=$(_));x.dom&&(t[y]=x=$(x));e:{for(;D.key===_.key;){if(we(D,_,n,o,r,i),k++,++b>m||k>y)break e;D=e[b],(_=t[k]).dom&&(t[k]=_=$(_))}for(;C.key===x.key;){if(we(C,x,n,o,r,i),y--,b>--m||k>y)break e;C=e[m],(x=t[y]).dom&&(t[y]=x=$(x))}}if(b>m){if(k<=y)for(f=(v=y+1)<s?t[v].dom:null;k<=y;)(g=t[k]).dom&&(t[k]=g=$(g)),k++,E(n,ge(g,null,o,r,i),f)}else if(k>y)for(;b<=m;)se(e[b++],n);else{var w=m-b+1,N=y-k+1,S=new Array(N);for(l=0;l<N;l++)S[l]=-1;var P=!1,O=0,T=0;if(N<=4||w*N<=16){for(l=b;l<=m;l++)if(c=e[l],T<N)for(d=k;d<=y;d++)if(u=t[d],c.key===u.key){S[d-k]=l,O>d?P=!0:O=d,u.dom&&(t[d]=u=$(u)),we(c,u,n,o,r,i),T++,e[l]=null;break}}else{var L={};for(l=k;l<=y;l++)L[t[l].key]=l;for(l=b;l<=m;l++)c=e[l],T<N&&h(d=L[c.key])&&(u=t[d],S[d-k]=l,O>d?P=!0:O=d,u.dom&&(t[d]=u=$(u)),we(c,u,n,o,r,i),T++,e[l]=null)}if(w===a&&0===T)ce(n,e),be(t,n,o,r,i);else{for(l=w-T;l>0;)p(c=e[b++])||(se(c,n),l--);if(P){var U=function(e){var t,n,o,r,i,a=e.slice(),s=[0],l=e.length;for(t=0;t<l;t++){var d=e[t];if(-1!==d){if(n=s[s.length-1],e[n]<d){a[t]=n,s.push(t);continue}for(o=0,r=s.length-1;o<r;)e[s[i=(o+r)/2|0]]<d?o=i+1:r=i;d<e[s[o]]&&(o>0&&(a[t]=s[o-1]),s[o]=t)}}o=s.length,r=s[o-1];for(;o-- >0;)s[o]=r,r=a[r];return s}(S);for(d=U.length-1,l=N-1;l>=0;l--)-1===S[l]?((g=t[O=l+k]).dom&&(t[O]=g=$(g)),v=O+1,E(n,ge(g,null,o,r,i),v<s?t[v].dom:null)):d<0||l!==U[d]?(g=t[O=l+k],v=O+1,E(n,g.dom,v<s?t[v].dom:null)):d--}else if(T!==N)for(l=N-1;l>=0;l--)-1===S[l]&&((g=t[O=l+k]).dom&&(t[O]=g=$(g)),v=O+1,E(n,ge(g,null,o,r,i),v<s?t[v].dom:null))}}}(n,o,r,i,a,s,l,d):function(e,t,n,o,r,i,a,s){for(var l=a>s?s:a,d=0;d<l;d++){var c=t[d];c.dom&&(c=t[d]=$(c)),we(e[d],c,n,o,r,i)}if(a<s)for(d=l;d<s;d++){var u=t[d];u.dom&&(u=t[d]=$(u)),ge(u,n,o,r,i)}else if(a>s)for(d=l;d<a;d++)se(e[d],n)}(n,o,r,i,a,s,l,d)}else 1===t?ce(r,n):(ce(r,n),ge(o,r,i,a,s))}}function Se(e,t,o,r,i,a,l,c,u,p){var f=e.state,h=e.props;o.children=e;var g,m=e.$LI;if(!e.$UN){if(h!==r||r===L){if(!p&&d(e.componentWillReceiveProps)){if(e.$BR=!0,e.componentWillReceiveProps(r,l),e.$UN)return;e.$BR=!1}e.$PSS&&(t=v(t,e.$PS),e.$PSS=!1,e.$PS=null)}var y=d(e.shouldComponentUpdate);if(u||!y||y&&e.shouldComponentUpdate(r,t,l)){d(e.componentWillUpdate)&&(e.$BS=!0,e.componentWillUpdate(r,t,l),e.$BS=!1),e.props=r,e.state=t,e.context=l,d(N.beforeRender)&&N.beforeRender(e),g=e.render(r,t,l),d(N.afterRender)&&N.afterRender(e);var b,k=g!==n;if(d(e.getChildContext)&&(b=e.getChildContext()),b=s(b)?l:v(l,b),e.$CX=b,k)we(m,e.$LI=ve(g,o),i,a,b,c),d(e.componentDidUpdate)&&e.componentDidUpdate(h,f),d(N.afterUpdate)&&N.afterUpdate(o)}else e.props=r,e.state=t,e.context=l;o.dom=e.$LI.dom}}var Pe=N.roots;r&&document.body;function Oe(e,t,o){if(e!==n){var r,i,a=Pe.length;for(i=0;i<a;i++)if(Pe[i]===t){r=t.$V;break}return f(r)?l(e)||(e.dom&&(e=$(e)),p(t.firstChild)?(ge(e,t,U,L,!1),t.$V=e,Pe.push(t)):function(e,t,n){var o=t.firstChild;if(!p(o))for(l(e)||Ce(e,o,U,L,!1),o=t.firstChild;o=o.nextSibling;)t.removeChild(o);U.length>0&&A(U),t.$V||N.roots.push(t),t.$V=e,d(n)&&n()}(e,t),r=e):s(e)?(se(r,t),Pe.splice(i,1)):(e.dom&&(e=$(e)),we(r,e,t,U,L,!1),r=t.$V=e),U.length>0&&A(U),d(o)&&o(),r&&14&r.flags?r.children:void 0}}var Te="undefined"==typeof Promise?null:Promise.resolve(),Le="undefined"==typeof requestAnimationFrame?setTimeout:requestAnimationFrame;function Ue(e,t,n){d(t)&&(t=t(e.state,e.props,e.context));var o,r=e.$PS;if(s(r))e.$PS=t;else for(var i in t)r[i]=t[i];if(e.$PSS||e.$BR)e.$PSS=!0,e.$BR&&d(n)&&U.push(n.bind(e));else if(e.$UPD){var a=e.$QU;p(a)&&(a=e.$QU=[],o=function(e,t){return function(){e.$QU=null,e.$UPD=!0,Me(e,!1,function(){for(var n=0,o=t.length;n<o;n++)t[n].call(e)}),e.$UPD=!1}}(e,a),Te?Te.then(o):Le(o)),d(n)&&a.push(n)}else e.$PSS=!0,e.$UPD=!0,Me(e,!1,n),e.$UPD=!1}function Me(e,t,n){if(!e.$UN){if(t||!e.$BR){e.$PSS=!1;var o=e.$PS,r=v(e.state,o),i=e.props,a=e.context;e.$PS=null;var s=e.$V,l=e.$LI;if(Se(e,r,s,i,l.dom&&l.dom.parentNode,U,a,(32&s.flags)>0,t,!0),e.$UN)return;if(0==(1024&e.$LI.flags))for(var c=e.$LI.dom;!p(s=s.parentVNode);)(14&s.flags)>0&&(s.dom=c);U.length>0&&A(U)}else e.state=e.$PS,e.$PS=null;d(n)&&n.call(e)}}var Ee=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};Ee.prototype.forceUpdate=function(e){this.$UN||Me(this,!0,e)},Ee.prototype.setState=function(e,t){this.$UN||this.$BS||Ue(this,e,t)},Ee.prototype.render=function(e,t,n){},Ee.defaultProps=null;var Fe=12,Ae=37,Ie=38,Ve=39,Re=40;var je=Ee,Be=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},We=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),He=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},qe=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)},Ke=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},Xe=function(e){function t(){return Be(this,t),Ke(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return qe(t,je),We(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:"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"})}}]),t}(),Qe=function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"li",o=t.itree[n].attributes,r=[],i=o.class||o.className;return e.isFunction(i)&&(i=i(t)),e.isEmpty(i)||(e.isString(i)?r=r.concat(i.split(/[\s\.]+/)):e.isArray(i)&&(r=r.concat(i))),r},ze=function(e){function t(){return Be(this,t),Ke(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return qe(t,je),We(t,[{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)}}]),t}(),Ge=function(e){function t(){return Be(this,t),Ke(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return qe(t,je),We(t,[{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)}}]),t}();function Ye(t,n){var o=n.dirty||!1;return o||e.each(Object.keys(n),function(e){if("dirty"!==e&&n[e]!==t[e])return o=!0,!1}),o}var Je=function(e){function t(e){Be(this,t);var n=Ke(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return n.state=n.getStateFromNodes(e.node),n}return qe(t,je),We(t,[{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 Ye(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===Fe)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}})}}]),t}(),Ze=function(e){function t(){return Be(this,t),Ke(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return qe(t,je),We(t,[{key:"blur",value:function(){this.props.node.blur()}},{key:"click",value:function(e){var t=this,n=this.props,o=n.node,r=n.dom,i=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,o))}o.selected()?r._tree.config.selection.disableDirectDeselection||o.deselect():o.select(),r._tree.enableDeselection()}};r._tree.emit("node.click",e,o,i),e.treeDefaultPrevented||i()}},{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,o=t.dom,r=function(){o.clearSelection(),n.toggleCollapse()};o._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 e=this.props.node,t=_.clone(e.itree.a.attributes)||{};t.tabindex=1,t.unselectable="on";var n=Qe(e,"a").concat(["title","icon"]);if(!this.props.dom.config.showCheckboxes){var o=this.props.expanded?"icon-folder-open":"icon-folder";n.push(e.itree.icon||(this.props.hasOrWillHaveChildren?o:"icon-file-empty"))}t.class=t.className=n.join(" ");var r=e.text;return e.editing()&&(r=b(2,Je,{dom:this.props.dom,node:this.props.node})),D(y(1,"a",null,r,0,He({"data-uid":e.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)},t)))}}]),t}(),et=function(e){function t(){return Be(this,t),Ke(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return qe(t,je),We(t,[{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)})}}]),t}(),tt=function(e){function n(e){Be(this,n);var t=Ke(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,e));return t.state=t.stateFromNode(e.node),t}return qe(n,je),We(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 e=this.props.node,t=_.clone(e.itree.li.attributes)||{};return t.class=t.className=this.getClassNames(),t["data-uid"]=e.id,this.props.dom.config.dragAndDrop.enabled&&(t.draggable=e.state("draggable"),t.onDragEnd=this.onDragEnd.bind(this),t.onDragEnter=this.onDragEnter.bind(this),t.onDragLeave=this.onDragLeave.bind(this),t.onDragStart=this.onDragStart.bind(this),e.state("drop-target")?(t.onDragOver=this.onDragOver.bind(this),t.onDrop=this.onDrop.bind(this)):(t.onDragOver=null,t.onDrop=null)),t}},{key:"getClassNames",value:function(){var e=this.props.node,t=e.itree.state,n=Qe(e);return _.each(Object.keys(t),function(e){t[e]&&n.push(e)}),!e.hidden()&&e.removed()&&n.push("hidden"),e.expanded()&&n.push("expanded"),n.push(e.hasOrWillHaveChildren()?"folder":"leaf"),n.join(" ")}},{key:"getTargetDirection",value:function(e,t){var n=e.clientY,o=t.getBoundingClientRect(),r=o.top+o.height/3,i=o.bottom-o.height/3,a=0;return n<=r?a=-1:n>=i&&(a=1),a}},{key:"onDragStart",value:function(e){e.stopPropagation(),e.dataTransfer.effectAllowed="move",e.dataTransfer.dropEffect="move";var n=this.props.node;if(this.props.dom._activeDragNode=n,e.dataTransfer.setData("treeId",n.tree().id),e.dataTransfer.setData("nodeId",n.id),n.state("drop-target",!1),n.hasChildren()&&n.children.stateDeep("drop-target",!1),"dragstart"===this.props.dom.config.dragAndDrop.validateOn){var o=this.props.dom.config.dragAndDrop.validate,r=_.isFunction(o);this.props.dom._tree.batch(),function e(n,o){t.isTreeNodes(n)?_.each(n,function(t){e(t,o)}):t.isTreeNode(n)&&!1!==o(n)&&n.hasChildren()&&e(n.children,o)}(this.props.dom._tree.model,function(e){var t=e.id!==n.id;return t&&(t=!e.hasAncestor(n)),t&&r&&(t=o(n,e)),e.state("drop-target",t),t}),this.props.dom._tree.end()}this.props.dom._tree.emit("node.dragstart",e)}},{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(e){e.preventDefault(),e.stopPropagation();var t=this.props.dom._activeDragNode,n=this.props.node,o=this.getTargetDirection(e,n.itree.ref.querySelector("a"));if("dragover"===this.props.dom.config.dragAndDrop.validateOn){var r=this.props.dom.config.dragAndDrop.validate,i=_.isFunction(r),a=t.id!==n.id;if(a&&(a=!n.hasAncestor(t)),a&&i&&(a=r(t,n,o)),n.state("drop-target",a),this.props.dom._tree.applyChanges(),!a)return}this.props.dom._tree.batch(),n.state("drag-targeting",!0),n.state("drag-targeting-above",-1===o),n.state("drag-targeting-below",1===o),n.state("drag-targeting-insert",0===o),this.props.dom._tree.end(),this.props.dom._tree.emit("node.dragover",e,o)}},{key:"onDrop",value:function(e){e.preventDefault(),e.stopPropagation(),this.unhighlightTarget();var t=e.dataTransfer.getData("treeId"),n=e.dataTransfer.getData("nodeId"),o=this.props.node;this.props.dom._activeDragNode=null;var r=this.getTargetDirection(e,e.target),i=void 0;t===this.props.dom._tree.id?i=this.props.dom._tree:t&&(i=document.querySelector('[data-uid="'+t+'"]').inspireTree);var a=void 0,s=void 0;if(i){var l=i.node(n);l.state("drop-target",!0);var d=l.remove(!0),c=o.context().indexOf(o);0===r?(a=o.addChild(d),s=o.children.indexOf(a),o.expand()):(s=1===r?++c:c,a=o.context().insertAt(s,d))}this.props.dom._tree.emit("node.drop",e,a,o,s)}},{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 b(2,Xe,{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 o=t.children,r=n.loading,i=o.pagination();return b(2,nt,{context:t,dom:n,limit:i.limit,loading:r,nodes:o,total:i.total})}if(this.props.dom.isDynamic&&t.children)return t.hasLoadedChildren()?b(2,Ge,{text:"No Results"}):b(2,Ge,{text:"Loading..."})}},{key:"renderEditToolbar",value:function(){if(this.props.dom._tree.config.editing.edit&&!this.props.node.editing())return b(2,ze,{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 b(2,et,{collapsed:e.collapsed(),node:e})}},{key:"render",value:function(){var e=this,t=this.props.node,n=D(y(1,"li",null,[this.renderEditToolbar(),y(1,"div","title-wrap",[this.renderToggle(),this.renderCheckbox(),b(2,Ze,{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,He({},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}(),nt=function(e){function t(){return Be(this,t),Ke(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return qe(t,je),We(t,[{key:"shouldComponentUpdate",value:function(e){return _.find(e.nodes,"itree.dirty")||Ye(this.props,e)}},{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",k("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",k("Loading..."),2),2)}},{key:"render",value:function(){var e=this,t=this.props.nodes,n=t.pagination();if(this.props.dom.config.deferredRendering){var o=0;t=this.props.nodes.filter(function(e){var t=!(e.hidden()||e.removed());return t&&o++,o<=n.limit&&t})}var r=_.map(t,function(t){return b(2,tt,{dom:e.props.dom,node:t},t.id)});return this.isDeferred()&&n.limit<n.total&&(this.props.loading?r.push(this.renderLoadingTextNode()):r.push(this.renderLoadMoreNode())),y(1,"ol",null,[r,this.props.children],0)}}]),t}(),ot=function(e){function t(){return Be(this,t),Ke(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return qe(t,je),We(t,[{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,o=t.loading,r=n.pagination();return b(2,nt,{dom:t,limit:r.limit,loading:o,nodes:n,total:r.total,children:this.renderAddLink()})}}]),t}();return function(){function n(o,r){var i=this;if(Be(this,n),!(o instanceof t))throw new TypeError("Tree argument is not an InspireTree instance.");if(this._tree=o,this.batching=0,this.dropTargets=[],this.$scrollLayer,!r.target)throw new TypeError("Invalid `target` property - must be a selector, HTMLElement, or jQuery element.");o.usesNativeDOM=!0;var a={enabled:!1,validateOn:"dragstart",validate:null};this.config=e.defaultsDeep({},r,{autoLoadMore:!0,deferredRendering:!1,dragAndDrop:a,nodeHeight:25,showCheckboxes:!1,tabindex:-1,target:!1}),!0===r.dragAndDrop&&(this.config.dragAndDrop=a,this.config.dragAndDrop.enabled=!0),"checkbox"!==o.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 s=!0;o.on("changes.applied",function(){i.renderNodes(),s&&(i.scrollSelectedIntoView(),s=!1)}),this.renderNodes()}return We(n,[{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 o=this._tree.config.pagination.limit;this._tree.config.pagination.limit=o>0?o: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 o=document.querySelector(t);o&&(n=o)}return n}},{key:"getScrollableAncestor",value:function(e){e instanceof Element&&("auto"!==getComputedStyle(e).overflow&&e.parentNode&&(e=this.getScrollableAncestor(e.parentNode)));return e}},{key:"keyboardListener",value:function(e){if(e.stopPropagation(),!([Re,Fe,Ae,Ve,Ie].indexOf(e.which)<0)){var t=this._tree.focused();if(t.length)switch(e.preventDefault(),e.which){case Re:this.moveFocusDownFrom(t[0]);break;case Fe:t[0].toggleSelect();break;case Ae:t[0].collapse();break;case Ve:t[0].expand();break;case Ie: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"),o=e.dataTransfer.getData("nodeId"),r=n.getTreeById(t).node(o);r.state("drop-target",!0);var i=r.remove(!0),a=this._tree.addNode(i),s=this._tree.indexOf(a);this._tree.emit("node.drop",e,a,null,s)}},{key:"renderNodes",value:function(e){Oe(b(2,ot,{dom:this,nodes:e||this._tree.nodes()}),this.$target)}},{key:"scrollListener",value:function(t){var n=this;if(!this.rendering&&!this.loading){var o=this.$scrollLayer.getBoundingClientRect(),r=document.querySelectorAll(".load-more");e.each(r,function(e){var r=e.getBoundingClientRect();if(!(o.right<r.left||o.left>r.right||o.bottom<r.top||o.top>r.bottom)){var i=void 0,a=e.parentNode.parentNode.parentNode;"LI"===a.tagName&&(i=n._tree.node(a.getAttribute("data-uid"))),n._tree.loadMore(i,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}}]),n}()});