blob: 0be7f5b404859909f61f1721808341e9bd2a460b [file] [log] [blame]
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* Inspire Tree DOM
* @version 4.0.6
* 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(l,i){"use strict";i=i&&i.hasOwnProperty("default")?i.default:i;var m="$NO_OP",a="a runtime error occured! Use Inferno in development environment to find the error.",e=!("undefined"==typeof window||!window.document),u=Array.isArray;function p(e){var t=typeof e;return"string"===t||"number"===t}function D(e){return g(e)||y(e)}function f(e){return y(e)||!1===e||!0===e||g(e)}function _(e){return"function"==typeof e}function h(e){return"string"==typeof e}function v(e){return"number"==typeof e}function y(e){return null===e}function g(e){return void 0===e}function b(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 k="$";function C(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 s(e,t,n,o,r,i,a,s){var l=void 0===r?1:r,d=C(l,o,n,e,a,i,s,t);return 0===l&&S(d,d.children),d}function d(e,t,n,o,r){0<(2&e)&&(e=t.prototype&&_(t.prototype.render)?4:8);var i=t.defaultProps;if(!D(i))for(var a in n||(n={}),i)g(n[a])&&(n[a]=i[a]);if(0<(8&e)){var s=t.defaultHooks;if(!D(s))if(r)for(var l in s)g(r[l])&&(r[l]=s[l]);else r=s}var d=C(1,null,null,e,o,n,r,t),c=P.createVNode;return _(c)&&c(d),d}function $(e,t){return C(1,D(e)?"":e,null,16,t,null,null,null)}function c(e){var t=e.props;if(t){var n=e.flags;481&n&&(void 0!==t.children&&D(e.children)&&S(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?b(e.ref,t.ref):t.ref,t.ref=void 0)}return e}function w(e){var t,n=e.flags;if(14&n){var o,r=e.props;if(!y(r))for(var i in o={},r)o[i]=r[i];t=d(n,e.type,o,e.key,e.ref)}else 481&n?t=s(n,e.type,e.className,e.children,e.childFlags,e.props,e.key,e.ref):16&n?t=$(e.children,e.key):1024&n&&(t=e);return t}function x(){return $("",null)}function N(e,t,n,o){for(var r=e.length;n<r;n++){var i=e[n];if(!f(i)){var a=o+k+n;if(u(i))N(i,t,0,a);else{if(p(i))i=$(i,a);else{var s=i.key,l=h(s)&&s[0]===k;y(i.dom)&&!l||(i=w(i)),y(s)||l?i.key=a:i.key=o+s}t.push(i)}}}}function S(e,t){var n,o=1;if(f(t))n=t;else if(h(t))o=2,n=$(t);else if(v(t))o=2,n=$(t+"");else if(u(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 i=0;i<r;i++){var a=t[i];if(f(a)||u(a)){N(t,n=n||t.slice(0,i),i,"");break}if(p(a))(n=n||t.slice(0,i)).push($(a,k+i));else{var s=a.key,l=y(a.dom),d=y(s),c=!d&&s[0]===k;!l||d||c?(n=n||t.slice(0,i),l&&!c||(a=w(a)),(d||c)&&(a.key=k+i),n.push(a)):n&&n.push(a)}}(n=n||t).$=!0}}else y((n=t).dom)||(n=w(t)),o=2;return e.children=n,e.childFlags=o,e}var P={afterRender:null,beforeRender:null,createVNode:null,renderComplete:null},t="http://www.w3.org/1999/xlink",n="http://www.w3.org/XML/1998/namespace",O="http://www.w3.org/2000/svg",T={"xlink:actuate":t,"xlink:arcrole":t,"xlink:href":t,"xlink:role":t,"xlink:show":t,"xlink:title":t,"xlink:type":t,"xml:base":n,"xml:lang":n,"xml:space":n},L={},U=[];function M(e,t){e.appendChild(t)}function E(e,t,n){D(n)?M(e,t):e.insertBefore(t,n)}function F(e,t,n){e.replaceChild(t,n)}function I(e){for(var t;void 0!==(t=e.shift());)t()}var A={},V={};function R(e,t,n){var r,o,i=A[e],a=n.$EV;t?(i||(V[e]=(r=e,o=function(e){var t=e.type,n="click"===t||"dblclick"===t;if(n&&0!==e.button)return e.stopPropagation(),!1;e.stopPropagation=B;var o={dom:document};Object.defineProperty(e,"currentTarget",{configurable:!0,get:function(){return o.dom}}),function(e,t,n,o,r){var i=t;for(;!y(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}}(e,e.target,n,r,o)},document.addEventListener(j(r),o),o),A[e]=0),a||(a=n.$EV={}),a[e]||A[e]++,a[e]=t):a&&a[e]&&(A[e]--,1===i&&(document.removeEventListener(j(e),V[e]),V[e]=null),a[e]=t)}function j(e){return e.substr(2).toLowerCase()}function B(){this.cancelBubble=!0,this.immediatePropagationStopped||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 o(s,l){var e=function(e){e.stopPropagation();var t=this.$V;if(t){var n=t.props||L,o=t.dom;if(h(s))H(n,s,e);else for(var r=0;r<s.length;r++)H(n,s[r],e);if(_(l)){var i=this.$V,a=i.props||L;l(a,o,!1,i)}}};return Object.defineProperty(e,"wrapped",{configurable:!1,enumerable:!1,value:!0,writable:!1}),e}function q(e){return"checkbox"===e||"radio"===e}var K=o("onInput",z),X=o(["onClick","onChange"],z);function Q(e){e.stopPropagation()}function z(e,t){var n=e.type,o=e.value,r=e.checked,i=e.multiple,a=e.defaultValue,s=!D(o);n&&n!==t.type&&t.setAttribute("type",n),D(i)||i===t.multiple||(t.multiple=i),D(a)||s||(t.defaultValue=a+""),q(n)?(s&&(t.value=o),D(r)||(t.checked=r)):s&&t.value!==o?(t.defaultValue=o,t.value=o):D(r)||(t.checked=r)}function G(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++)Y(n[r],t);else 2===o&&Y(n,t)}else Y(e,t)}function Y(e,t){var n=e.props||L,o=e.dom;o.value=n.value,u(t)&&-1!==t.indexOf(n.value)||n.value===t?o.selected=!0:D(t)&&D(n.selected)||(o.selected=n.selected||!1)}Q.wrapped=!0;var J=o("onChange",Z);function Z(e,t,n,o){var r=Boolean(e.multiple);D(e.multiple)||r===t.multiple||(t.multiple=r);var i=o.childFlags;if(0==(1&i)){var a=o.children,s=e.value;if(n&&D(s)&&(s=e.defaultValue),12&i)for(var l=0,d=a.length;l<d;l++)G(a[l],s);else 2===i&&G(a,s)}}var ee=o("onInput",ne),te=o("onChange");function ne(e,t,n){var o=e.value,r=t.value;if(D(o)){if(n){var i=e.defaultValue;D(i)||i===r||(t.defaultValue=i,t.value=i)}}else r!==o&&(t.defaultValue=o,t.value=o)}function oe(e,t,n,o,r,i){64&e?z(o,n):256&e?Z(o,n,r,t):128&e&&ne(o,n,r),i&&(n.$V=t)}function re(e,t,n){var o,r,i;64&e?(i=t,q(n.type)?(i.onchange=X,i.onclick=Q):i.oninput=K):256&e?t.onchange=J:128&e&&(r=n,(o=t).oninput=ee,r.onChange&&(o.onchange=te))}function ie(e){return e.type&&q(e.type)?!D(e.checked):!D(e.value)}function ae(e,t){var n,o;se(e),t&&e.dom&&(n=t,o=e.dom,n.removeChild(o),e.dom=null)}function se(e){var t=e.flags;if(481&t){var n=e.ref,o=e.props;_(n)&&n(null);var r=e.children,i=e.childFlags;if(12&i?le(r):2===i&&se(r),!y(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{var s=e.children;if(s)if(14&t){var l=e.ref;4&t?(_(s.componentWillUnmount)&&s.componentWillUnmount(),_(l)&&l(null),s.$UN=!0,s.$LI&&se(s.$LI)):(!D(l)&&_(l.onComponentWillUnmount)&&l.onComponentWillUnmount(e.dom,e.props||L),se(s))}else 1024&t&&ae(s,e.type)}}function le(e){for(var t=0,n=e.length;t<n;t++)se(e[t])}function de(e,t){le(t),e.textContent=""}function ce(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 ue(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":break;case"autoFocus":o.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":o[e]=!!n;break;case"defaultChecked":case"value":case"volume":if(i&&"value"===e)return;var s=D(n)?"":n;o[e]!==s&&(o[e]=s);break;case"dangerouslySetInnerHTML":var l=t&&t.__html||"",d=n&&n.__html||"";l!==d&&(D(d)||W(o,d)||(y(a)||(12&a.childFlags?le(a.children):2===a.childFlags&&se(a.children),a.children=null,a.childFlags=1),o.innerHTML=d));break;default:"o"===e[0]&&"n"===e[1]?function(e,t,n,o){var r,i,a=e.toLowerCase();if(_(n)||D(n)){var s=o[a];s&&s.wrapped||(o[a]=n)}else{var l=n.event;l&&_(l)&&(o[a]=(r=l,i=n,function(e){r(i.data,e)}))}}(e,0,n,o):D(n)?o.removeAttribute(e):"style"===e?function(e,t,n){var o,r,i=n.style;if(h(t))i.cssText=t;else if(D(e)||h(e))for(o in t)r=t[o],i[o]=v(r)?ce(o,r):r;else{for(o in t)(r=t[o])!==e[o]&&(i[o]=v(r)?ce(o,r):r);for(o in e)D(t[o])&&(i[o]="")}}(t,n,o):r&&T[e]?o.setAttributeNS(T[e],e,n):o.setAttribute(e,n)}}function pe(e,t,n,o,r){var i=!1,a=0<(448&t);for(var s in a&&(i=ie(n))&&re(t,o,n),n)ue(s,null,n[s],o,r,i,null);a&&oe(t,e,o,n,!0,i)}function fe(e,t,n,o){var r=new t(n,o);if((e.children=r).$V=e,r.$BS=!1,r.context=o,r.props===L&&(r.props=n),r.$UN=!1,_(r.componentWillMount)){if(r.$BR=!0,r.componentWillMount(),r.$PSS){var i=r.state,a=r.$PS;if(y(i))r.state=a;else for(var s in a)i[s]=a[s];r.$PSS=!1,r.$PS=null}r.$BR=!1}_(P.beforeRender)&&P.beforeRender(r);var l,d=he(r.render(n,r.state,o),e);return _(r.getChildContext)&&(l=r.getChildContext()),D(l)?r.$CX=o:r.$CX=b(o,l),_(P.afterRender)&&P.afterRender(r),r.$LI=d,r}function he(e,t){return f(e)?e=x():p(e)?e=$(e,null):(e.dom&&(e=w(e)),14&e.flags&&(e.parentVNode=t)),e}function ve(e,t,n,o){var r=e.flags;return 481&r?me(e,t,n,o):14&r?function(e,t,n,o,r){var i,a=e.type,s=e.props||L,l=e.ref;if(r){var d=fe(e,a,s,n);e.dom=i=ve(d.$LI,null,d.$CX,o),be(e,l,d),d.$UPD=!1}else{var c=he(a(s,n),e);e.children=c,e.dom=i=ve(c,null,n,o),ke(s,l,i)}y(t)||M(t,i);return i}(e,t,n,o,0<(4&r)):512&r||16&r?ge(e,t):1024&r?(ve(e.children,e.type,n,!1),e.dom=ge(x(),t)):void 0}function ge(e,t){var n=e.dom=document.createTextNode(e.children);return y(t)||M(t,n),n}function me(e,t,n,o){var r=e.flags,i=e.children,a=e.props,s=e.className,l=e.ref,d=e.childFlags;o=o||0<(32&r);var c,u=(c=e.type,!0===o?document.createElementNS(O,c):document.createElement(c));if(e.dom=u,D(s)||""===s||(o?u.setAttribute("class",s):u.className=s),y(t)||M(t,u),0==(1&d)){var p=!0===o&&"foreignObject"!==e.type;2===d?ve(i,u,n,p):12&d&&ye(i,u,n,p)}return y(a)||pe(e,r,a,u,o),_(l)&&Ce(u,l),u}function ye(e,t,n,o){for(var r=0,i=e.length;r<i;r++){var a=e[r];y(a.dom)||(e[r]=a=w(a)),ve(a,t,n,o)}}function be(e,t,n){var o;_(t)&&t(n),_(n.componentDidMount)&&U.push((o=n,function(){o.componentDidMount()}))}function ke(e,t,n){var o,r,i;D(t)||(_(t.onComponentWillMount)&&t.onComponentWillMount(e),_(t.onComponentDidMount)&&U.push((o=t,r=n,i=e,function(){return o.onComponentDidMount(r,i)})))}function Ce(e,t){U.push(function(){return t(e)})}function $e(e,t,n,o){var r,i,a=e.children,s=e.props,l=e.className,d=e.flags,c=e.ref;if(o=o||0<(32&d),1!==t.nodeType||t.tagName.toLowerCase()!==e.type){var u=me(e,null,n,o);e.dom=u,F(t.parentNode,u,t)}else{var p=(e.dom=t).firstChild,f=e.childFlags;if(0==(1&f)){for(var h=null;p;)h=p.nextSibling,8===p.nodeType&&("!"===p.data?t.replaceChild(document.createTextNode(""),p):t.removeChild(p)),p=h;if(p=t.firstChild,2===f)y(p)?ve(a,t,n,o):(h=p.nextSibling,De(a,p,n,o),p=h);else if(12&f)for(var v=0,g=a.length;v<g;v++){var m=a[v];y(p)?ve(m,t,n,o):(h=p.nextSibling,De(m,p,n,o),p=h)}for(;p;)h=p.nextSibling,t.removeChild(p),p=h}else y(t.firstChild)||(r=t,i=s,Boolean(i&&i.dangerouslySetInnerHTML&&i.dangerouslySetInnerHTML.__html&&W(r,i.dangerouslySetInnerHTML.__html)))||(t.textContent="",448&d&&(t.defaultValue=""));y(s)||pe(e,d,s,t,o),D(l)?""!==t.className&&t.removeAttribute("class"):o?t.setAttribute("class",l):t.className=l,_(c)&&Ce(t,c)}}function De(e,t,n,o){var r=e.flags;14&r?function(e,t,n,o,r){var i=e.type,a=e.ref,s=e.props||L;if(r){var l=fe(e,i,s,n),d=l.$LI;De(d,t,l.$CX,o),e.dom=d.dom,be(0,a,l),l.$UPD=!1}else{var c=he(i(s,n),e);De(c,t,n,o),e.children=c,e.dom=c.dom,ke(s,a,t)}}(e,t,n,o,0<(4&r)):481&r?$e(e,t,n,o):16&r?function(e,t){if(3!==t.nodeType){var n=ge(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&r?e.dom=t:function(e){throw e||(e=a),new Error("Inferno Error: "+e)}()}function _e(e,t,n,o,r){se(e),F(n,ve(t,null,o,r),e.dom)}function xe(e,t,n,o,r){if(e!==t){var i=0|t.flags;e.flags!==i||2048&i?_e(e,t,n,o,r):481&i?function(e,t,n,o,r){var i=t.type;if(e.type!==i)_e(e,t,n,o,r);else{var a,s=e.dom,l=t.flags,d=e.props,c=t.props,u=!1,p=!1;if(t.dom=s,r=r||0<(32&l),d!==c){var f=d||L;if((a=c||L)!==L)for(var h in(u=0<(448&l))&&(p=ie(a)),a){var v=f[h],g=a[h];v!==g&&ue(h,v,g,s,r,p,e)}if(f!==L)for(var m in f)a.hasOwnProperty(m)||D(f[m])||ue(m,f[m],null,s,r,p,e)}var y=e.children,b=t.children,k=t.ref,C=e.className,$=t.className;y!==b&&we(e.childFlags,t.childFlags,y,b,s,o,r&&"foreignObject"!==i),u&&oe(l,t,s,a,!1,p),C!==$&&(D($)?s.removeAttribute("class"):r?s.setAttribute("class",$):s.className=$),_(k)&&e.ref!==k&&Ce(s,k)}}(e,t,n,o,r):14&i?function(e,t,n,o,r,i){var a=t.type,s=e.key,l=t.key;if(e.type!==a||s!==l)_e(e,t,n,o,r);else{var d=t.props||L;if(i){var c=e.children;c.$UPD=!0,c.$V=t,Ne(c,c.state,t,d,n,o,r,!1,!1),c.$UPD=!1}else{var u=!0,p=e.props,f=t.ref,h=!D(f),v=e.children;if(t.dom=e.dom,t.children=v,h&&_(f.onComponentShouldUpdate)&&(u=f.onComponentShouldUpdate(p,d)),!1!==u){h&&_(f.onComponentWillUpdate)&&f.onComponentWillUpdate(p,d);var g=a(d,o);g!==m&&(g=he(g,t),xe(v,g,n,o,r),t.children=g,t.dom=g.dom,h&&_(f.onComponentDidUpdate)&&f.onComponentDidUpdate(p,d))}else 14&v.flags&&(v.parentVNode=t)}}}(e,t,n,o,r,0<(4&i)):16&i?function(e,t,n){var o,r=t.children;y(n.firstChild)?(n.textContent=r,o=n.firstChild):(o=e.dom,r!==e.children&&(o.nodeValue=r));t.dom=o}(e,t,n):512&i?t.dom=e.dom:function(e,t,n){var o=e.type,r=t.type,i=t.children;if(we(e.childFlags,t.childFlags,e.children,i,o,n,!1),t.dom=e.dom,o!==r&&!f(i)){var a=i.dom;o.removeChild(a),r.appendChild(a)}}(e,t,o)}}function we(e,t,n,o,r,i,a){switch(e){case 2:switch(t){case 2:xe(n,o,r,i,a);break;case 1:ae(n,r);break;default:ae(n,r),ye(o,r,i,a)}break;case 1:switch(t){case 2:ve(o,r,i,a);break;case 1:break;default:ye(o,r,i,a)}break;default:if(12&t){var s=n.length,l=o.length;0===s?0<l&&ye(o,r,i,a):0===l?de(r,n):8===t&&8===e?function(e,t,n,o,r,i,a){var s,l,d=i-1,c=a-1,u=0,p=e[u],f=t[u];e:{for(;p.key===f.key;){if(f.dom&&(t[u]=f=w(f)),xe(p,f,n,o,r),e[u]=f,d<++u||c<u)break e;p=e[u],f=t[u]}for(p=e[d],f=t[c];p.key===f.key;){if(f.dom&&(t[c]=f=w(f)),xe(p,f,n,o,r),e[d]=f,c--,--d<u||c<u)break e;p=e[d],f=t[c]}}if(d<u){if(u<=c)for(var h=(l=c+1)<a?t[l].dom:null;u<=c;)(f=t[u]).dom&&(t[u]=f=w(f)),u++,E(n,ve(f,null,o,r),h)}else if(c<u)for(;u<=d;)ae(e[u++],n);else{var v=u,g=u,m=d-u+1,y=c-u+1,b=[];for(s=0;s<y;s++)b.push(0);var k=m===i,C=!1,$=0,D=0;if(a<4||(m|y)<32)for(s=v;s<=d;s++)if(p=e[s],D<y){for(u=g;u<=c;u++)if(f=t[u],p.key===f.key){if(b[u-g]=s+1,k)for(k=!1;v<s;)ae(e[v++],n);u<$?C=!0:$=u,f.dom&&(t[u]=f=w(f)),xe(p,f,n,o,r),D++;break}!k&&c<u&&ae(p,n)}else k||ae(p,n);else{var _={};for(s=g;s<=c;s++)_[t[s].key]=s;for(s=v;s<=d;s++)if(p=e[s],D<y)if(void 0!==(u=_[p.key])){if(k)for(k=!1;v<s;)ae(e[v++],n);f=t[u],b[u-g]=s+1,u<$?C=!0:$=u,f.dom&&(t[u]=f=w(f)),xe(p,f,n,o,r),D++}else k||ae(p,n);else k||ae(p,n)}if(k)de(n,e),ye(t,n,o,r);else if(C){var x=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(0!==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]]&&(0<o&&(a[t]=s[o-1]),s[o]=t)}}o=s.length,r=s[o-1];for(;0<o--;)s[o]=r,r=a[r];return s}(b);for(u=x.length-1,s=y-1;0<=s;s--)0===b[s]?((f=t[$=s+g]).dom&&(t[$]=f=w(f)),l=$+1,E(n,ve(f,null,o,r),l<a?t[l].dom:null)):u<0||s!==x[u]?(f=t[$=s+g],l=$+1,E(n,f.dom,l<a?t[l].dom:null)):u--}else if(D!==y)for(s=y-1;0<=s;s--)0===b[s]&&((f=t[$=s+g]).dom&&(t[$]=f=w(f)),l=$+1,E(n,ve(f,null,o,r),l<a?t[l].dom:null))}}(n,o,r,i,a,s,l):function(e,t,n,o,r,i,a){for(var s,l,d=a<i?a:i,c=0;c<d;c++)s=t[c],l=e[c],s.dom&&(s=t[c]=w(s)),xe(l,s,n,o,r),e[c]=s;if(i<a)for(c=d;c<a;c++)(s=t[c]).dom&&(s=t[c]=w(s)),ve(s,n,o,r);else if(a<i)for(c=d;c<i;c++)ae(e[c],n)}(n,o,r,i,a,s,l)}else 1===t?de(r,n):(de(r,n),ve(o,r,i,a))}}function Ne(e,t,n,o,r,i,a,s,l){var d,c=e.state,u=e.props;if(!(n.children=e).$UN){if(u!==o||o===L){if(!l&&_(e.componentWillReceiveProps)){if(e.$BR=!0,e.componentWillReceiveProps(o,i),e.$UN)return;e.$BR=!1}e.$PSS&&(t=b(t,e.$PS),e.$PSS=!1,e.$PS=null)}var p=Boolean(e.shouldComponentUpdate);if(s||!p||p&&e.shouldComponentUpdate(o,t,i)){_(e.componentWillUpdate)&&(e.$BS=!0,e.componentWillUpdate(o,t,i),e.$BS=!1),e.props=o,e.state=t,e.context=i,_(P.beforeRender)&&P.beforeRender(e),d=e.render(o,t,i),_(P.afterRender)&&P.afterRender(e);var f,h=d!==m;if(_(e.getChildContext)&&(f=e.getChildContext()),f=D(f)?i:b(i,f),e.$CX=f,h)xe(e.$LI,e.$LI=he(d,n),r,f,a),_(e.componentDidUpdate)&&e.componentDidUpdate(u,c)}else e.props=o,e.state=t,e.context=i;n.dom=e.$LI.dom}}e&&document.body;function r(e,t,n){if(e!==m){var o=t.$V;return D(o)?f(e)||(e.dom&&(e=w(e)),y(t.firstChild)?(ve(e,t,L,!1),t.$V=e):function(e,t,n){var o=t.firstChild;if(!y(o))for(f(e)||De(e,o,L,!1),o=t.firstChild;o=o.nextSibling;)t.removeChild(o);0<U.length&&I(U),t.$V=e,_(n)&&n()}(e,t),o=e):D(e)?(ae(o,t),t.$V=null):(e.dom&&(e=w(e)),xe(o,e,t,L,!1),o=t.$V=e),0<U.length&&I(U),_(n)&&n(),_(P.renderComplete)&&P.renderComplete(o),o&&14&o.flags?o.children:void 0}}var Se="undefined"==typeof Promise?null:Promise.resolve(),Pe="undefined"==typeof requestAnimationFrame?setTimeout:requestAnimationFrame.bind(window);function Oe(e,t,n,o){_(t)&&(t=t(e.state,e.props,e.context));var r,i,a,s=e.$PS;if(D(s))e.$PS=t;else for(var l in t)s[l]=t[l];if(e.$PSS||e.$BR)e.$PSS=!0,e.$BR&&_(n)&&U.push(n.bind(e));else if(e.$UPD){var d=e.$QU;y(d)&&(d=e.$QU=[],i=e,a=d,r=function(){i.$QU=null,i.$UPD=!0,Te(i,!1,function(){for(var e=0,t=a.length;e<t;e++)a[e].call(i)}),i.$UPD=!1},Se?Se.then(r):Pe(r)),_(n)&&d.push(n)}else e.$PSS=!0,e.$UPD=!0,Te(e,o,n),e.$UPD=!1}function Te(e,t,n){if(!e.$UN){if(t||!e.$BR){e.$PSS=!1;var o=e.$PS,r=b(e.state,o),i=e.props,a=e.context;e.$PS=null;var s=e.$V,l=e.$LI;if(Ne(e,r,s,i,l.dom&&l.dom.parentNode,a,0<(32&s.flags),t,!0),e.$UN)return;if(0==(1024&e.$LI.flags))for(var d=e.$LI.dom;!y(s=s.parentVNode);)0<(14&s.flags)&&(s.dom=d);0<U.length&&I(U)}else e.state=e.$PS,e.$PS=null;_(n)&&n.call(e)}}var Le=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};Le.prototype.forceUpdate=function(e){this.$UN||Oe(this,{},e,!0)},Le.prototype.setState=function(e,t){this.$UN||this.$BS||Oe(this,e,t,!1)},Le.prototype.render=function(e,t,n){};var Ue=12,Me=37,Ee=38,Fe=39,Ie=40;var Ae=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},Ve=function(){function o(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(e,t,n){return t&&o(e.prototype,t),n&&o(e,n),e}}(),Re=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},je=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)},Be=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},We=function(e){function t(){return Ae(this,t),Be(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return je(t,Le),Ve(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 s(64,"input",null,null,1,{checked:this.props.checked,indeterminate:this.props.indeterminate,onClick:this.click.bind(this),type:"checkbox"})}}]),t}(),He=function(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"li",n=e.itree[t].attributes,o=[],r=n.class||n.className;return l.isFunction(r)&&(r=r(e)),l.isEmpty(r)||(l.isString(r)?o=o.concat(r.split(/[\s\.]+/)):l.isArray(r)&&(o=o.concat(r))),o},qe=function(e){function t(){return Ae(this,t),Be(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return je(t,Le),Ve(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(s(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(s(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(s(1,"a","btn icon icon-minus",null,1,{onclick:this.remove.bind(this),title:"Remove this node"})),s(1,"span","btn-group",e,0)}}]),t}(),Ke=function(e){function t(){return Ae(this,t),Be(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return je(t,Le),Ve(t,[{key:"render",value:function(){return s(1,"ol",null,s(1,"li","leaf",s(1,"span","title icon icon-file-empty empty",this.props.text,0),2),2)}}]),t}();function Xe(t,n){var o=n.dirty||!1;return o||l.each(Object.keys(n),function(e){if("dirty"!==e&&n[e]!==t[e])return!(o=!0)}),o}var Qe=function(e){function n(e){Ae(this,n);var t=Be(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,e));return t.state=t.getStateFromNodes(e.node),t}return je(n,Le),Ve(n,[{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 Xe(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===Ue)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 t=this;return s(1,"form",null,[s(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(e){return t.ref=e}),s(1,"span","btn-group",[s(1,"button","btn icon icon-check",null,1,{onClick:this.save.bind(this),title:"Save",type:"button"}),s(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}})}}]),n}(),ze=function(e){function t(){return Ae(this,t),Be(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return je(t,Le),Ve(t,[{key:"blur",value:function(){this.props.node.blur()}},{key:"click",value:function(t){var n=this,e=this.props,o=e.node,r=e.dom,i=function(){if(t.preventDefault(),!n.props.editing){if((t.metaKey||t.ctrlKey||t.shiftKey)&&r._tree.disableDeselection(),t.shiftKey){r.clearSelection();var e=r._tree.lastSelectedNode();e&&r._tree.selectBetween.apply(r._tree,r._tree.boundingNodes(e,o))}o.selected()?r._tree.config.selection.disableDirectDeselection||o.deselect():o.select(),r._tree.enableDeselection()}};r._tree.emit("node.click",t,o,i),t.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=l.clone(e.itree.a.attributes)||{};t.tabindex=1,t.unselectable="on";var n=He(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=d(2,Qe,{dom:this.props.dom,node:this.props.node})),c(s(1,"a",null,r,0,Re({"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}(),Ge=function(e){function t(){return Ae(this,t),Be(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return je(t,Le),Ve(t,[{key:"className",value:function(){return"toggle icon "+(this.props.collapsed?"icon-expand":"icon-collapse")}},{key:"render",value:function(){return s(1,"a",this.className(),null,1,{onClick:this.props.node.toggleCollapse.bind(this.props.node)})}}]),t}(),Ye=function(e){function n(e){Ae(this,n);var t=Be(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,e));return t.state=t.stateFromNode(e.node),t}return je(n,Le),Ve(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=l.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=He(e);return l.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:i<=n&&(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=l.isFunction(o);this.props.dom._tree.batch(),function t(e,n){i.isTreeNodes(e)?l.each(e,function(e){t(e,n)}):i.isTreeNode(e)&&!1!==n(e)&&e.hasChildren()&&t(e.children,n)}(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=l.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 d(2,We,{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 d(2,Je,{context:t,dom:n,limit:i.limit,loading:r,nodes:o,total:i.total})}if(this.props.dom.isDynamic&&t.children)return t.hasLoadedChildren()?d(2,Ke,{text:"No Results"}):d(2,Ke,{text:"Loading..."})}},{key:"renderEditToolbar",value:function(){if(this.props.dom._tree.config.editing.edit&&!this.props.node.editing())return d(2,qe,{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 d(2,Ge,{collapsed:e.collapsed(),node:e})}},{key:"render",value:function(){var t=this,e=this.props.node,n=c(s(1,"li",null,[this.renderEditToolbar(),s(1,"div","title-wrap",[this.renderToggle(),this.renderCheckbox(),d(2,ze,{dom:this.props.dom,editing:e.editing(),expanded:e.expanded(),hasOrWillHaveChildren:e.hasOrWillHaveChildren(),node:e,text:e.text})],0),s(1,"div","wholerow"),this.renderChildren()],0,Re({},this.getAttributes()),null,function(e){return t.node=t.props.node.itree.ref=e}));return this.props.node.state("rendered",!0),this.props.node.itree.dirty=!1,n}}]),n}(),Je=function(e){function t(){return Ae(this,t),Be(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return je(t,Le),Ve(t,[{key:"shouldComponentUpdate",value:function(e){return l.find(e.nodes,"itree.dirty")||Xe(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 s(1,"li","leaf detached",s(1,"a","title icon icon-more load-more",$("Load More"),2,{onClick:this.loadMore.bind(this)}),2)}},{key:"renderLoadingTextNode",value:function(){return s(1,"li","leaf",s(1,"span","title icon icon-more",$("Loading..."),2),2)}},{key:"render",value:function(){var t=this,e=this.props.nodes,n=e.pagination();if(this.props.dom.config.deferredRendering){var o=0;e=this.props.nodes.filter(function(e){var t=!(e.hidden()||e.removed());return t&&o++,o<=n.limit&&t})}var r=l.map(e,function(e){return d(2,Ye,{dom:t.props.dom,node:e},e.id)});return this.isDeferred()&&n.limit<n.total&&(this.props.loading?r.push(this.renderLoadingTextNode()):r.push(this.renderLoadMoreNode())),s(1,"ol",null,[r,this.props.children],0)}}]),t}(),Ze=function(e){function t(){return Ae(this,t),Be(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return je(t,Le),Ve(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 s(1,"li",null,s(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 d(2,Je,{dom:t,limit:r.limit,loading:o,nodes:n,total:r.total,children:this.renderAddLink()})}}]),t}();return function(){function s(e,t){var n=this;if(Ae(this,s),!(e instanceof i))throw new TypeError("Tree argument is not an InspireTree instance.");if(this._tree=e,this.batching=0,this.dropTargets=[],this.$scrollLayer,!t.target)throw new TypeError("Invalid `target` property - must be a selector, HTMLElement, or jQuery element.");var o={enabled:!(e.usesNativeDOM=!0),validateOn:"dragstart",validate:null};this.config=l.defaultsDeep({},t,{autoLoadMore:!0,deferredRendering:!1,dragAndDrop:o,nodeHeight:25,showCheckboxes:!1,tabindex:-1,target:!1}),!0===t.dragAndDrop&&(this.config.dragAndDrop=o,this.config.dragAndDrop.enabled=!0),"checkbox"!==e.config.selection.mode||l.isBoolean(l.get(t,"showCheckboxes"))||(this.config.showCheckboxes=!0),this.isDynamic=l.isFunction(this._tree.config.data),this.attach(this.config.target);var r=!0;e.on("changes.applied",function(){n.renderNodes(),r&&(n.scrollSelectedIntoView(),r=!1)}),this.renderNodes()}return Ve(s,[{key:"attach",value:function(e){if(this.$target=this.getElement(e),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"),l.each(l.pickBy(this._tree.config.editing,l.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 t=this._tree.config.pagination.limit;this._tree.config.pagination.limit=0<t?t:l.ceil(this.$scrollLayer.clientHeight/this.config.nodeHeight),this.config.autoLoadMore&&this.$target.addEventListener("scroll",l.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(e){var t=void 0;if(e instanceof HTMLElement)t=e;else if(l.isObject(e)&&l.isObject(e[0]))t=e[0];else if(l.isString(e)){var n=document.querySelector(e);n&&(t=n)}return t}},{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(),!([Ie,Ue,Me,Fe,Ee].indexOf(e.which)<0)){var t=this._tree.focused();if(t.length)switch(e.preventDefault(),e.which){case Ie:this.moveFocusDownFrom(t[0]);break;case Ue:t[0].toggleSelect();break;case Me:t[0].collapse();break;case Fe:t[0].expand();break;case Ee: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"),o=s.getTreeById(t).node(n);o.state("drop-target",!0);var r=o.remove(!0),i=this._tree.addNode(r),a=this._tree.indexOf(i);this._tree.emit("node.drop",e,i,null,a)}},{key:"renderNodes",value:function(e){r(d(2,Ze,{dom:this,nodes:e||this._tree.nodes()}),this.$target)}},{key:"scrollListener",value:function(r){var i=this;if(!this.rendering&&!this.loading){var a=this.$scrollLayer.getBoundingClientRect(),e=document.querySelectorAll(".load-more");l.each(e,function(e){var t=e.getBoundingClientRect();if(!(a.right<t.left||a.left>t.right||a.bottom<t.top||a.top>t.bottom)){var n=void 0,o=e.parentNode.parentNode.parentNode;"LI"===o.tagName&&(n=i._tree.node(o.getAttribute("data-uid"))),i._tree.loadMore(n,r)}})}}},{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}}]),s}()});