UNPKG

eyzy-tree

Version:
7 lines (6 loc) 20.8 kB
/*! * EyzyTree vv0.2.2 * (c) 2019 amsik * Released under the MIT License. */ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):e.EyzyTree=t(e.React)}(this,function(e){"use strict";function t(e,t){function n(){this.constructor=e}W(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}function n(e){return u(e)?e:[e]}function r(e,t){if(!p(t))throw new TypeError('"fetcher" it must be either function or promise');var n=l(t)?t(e):t;if(!n||!n.then)throw new TypeError('"fetcher" property must return a Promise');return n}function i(e,t){return t.reduce(function(t,n){return n in e&&(t[n]=e[n]),t},{})}function o(e){return null!=e&&"object"==typeof e&&!Array.isArray(e)}function c(e){return"string"==typeof e}function a(e){return e instanceof RegExp}function u(e){return Array.isArray(e)}function d(e){return!(!e.child||!e.child.length)||!!e.isBatch}function s(e){return!(e.disabled||e.disabledCheckbox)}function l(e){return"function"==typeof e}function p(e){return l(e)||e&&!!e.then}function f(e){return u(e)?0===e.length:!e}function h(e,t){if(e){u(t)||(t=t.split("."));for(var n=t.length,r=0;null!=e&&r<n;)e=e[t[r++]];return r&&r===n?e:void 0}}function v(e,t){return!!~e.indexOf(t)}function y(e){return e.concat([])}function m(e){var t=u(e)?[]:{};for(var n in e)if("parent"!==n&&J.call(e,n)){var r=e[n];t[n]="object"==typeof r?m(r):r}return t}function b(e){var t={};for(var n in e)J.call(e,n)&&(t[n]=u(e[n])?y(e[n]):e[n]);return t}function k(e,t){var n=e.indexOf(t);~n&&e.splice(n,1)}function x(e){return e&&!e.parent}function g(e){return!e.child||0===e.child.length&&!e.isBatch}function C(e,t,n){if(!e.child.length)return!1;if(e.child.some(function(e){return!e.disabled&&!e.disabledCheckbox&&-1!==n.indexOf(e.id)}))return!0;var r=e.child.reduce(function(e,n){return!0!==n.disabled&&!0!==n.disabledCheckbox&&-1===t.indexOf(n.id)&&e++,e},0);return r>0&&r<e.child.length}function S(e){var t=[];if(u(e))return e.join(" ");for(var n in e)Q.call(e,n)&&e[n]&&t.push(n);return t.join(" ")}function E(e,t,n){if(e===t)return!0;for(var r=0;r<n.length;r++){var i=n[r];if(e[i]!==t[i])return!1}return!0}function N(e){if(l(e))return e;if(c(e))return function(t){return O(e,t.id)||O(e,t.text)};if(e.id)return function(t){return O(e.id,t.id)};var t=a(e)?{text:e}:e;return function(e){var r=Object.keys(t);return!!r.length&&r.every(function(r){return r in Z?n(t[r]).some(function(t){return I(Z[r],t,e)}):n(t[r]).some(function(t){return O(t,h(e,r))})})}}function I(e,t,n){return!0===e(n,t)}function O(e,t){return a(e)?new RegExp(e).test(t):e===t}function _(e,t){return t.some(function(t){return!0===t(e)})}function A(e,t,r,i){if(f(i))return null;var o=[],c=n(i).map(N);return t(e,function(e){return!_(e,c)||(o.push(e),r)}),o.length?r?o:o[0]:r?[]:null}function w(e,t,n,r){void 0===r&&(r=0);var i;return Array.isArray(e)?e.map(function(e){return w(e,t,!1,r)}):(n||(i=t(e,r)),!1!==i&&e.child&&e.child.length&&(i=w(e.child,t,!1,r+1)),i)}function R(e){for(var t=e.parent;t;){if(!t.parent)return t;t=t.parent}return null}function D(e,t){for(var n=e.parent;n;){if(!1===t(n)||!n.parent)return;n=n.parent}}function j(e,t){if(t){var n=e.child.filter(function(e){return!e.disabled});return n.length?n[0]:null}return e.child[0]||null}function U(e){var t=R(e);return!!t&&!t.expanded}function $(e,t){var n={nodes:[],ids:[]};return w(e,function(e){e.disabled||t&&e.parent&&!e.parent.expanded||U(e)||(n.nodes.push(e),n.ids.push(e.id))}),n}function M(e,t){var n={};return w(e,function(e){var t=e.depth||0;n[t]||(n[t]=[]),n[t].push(e)}),Object.keys(n).reduce(function(e,t){return e.push.apply(e,n[t]),e},[]).some(function(e){return!1===t(e)})}function K(e,t){if("string"==typeof e)return[[e,t]];if(!t){var n=[];for(var r in e)J.call(e,r)&&n.push([r,e[r]]);return n}return[]}function P(e){return e&&e.child?(e.child=y(e.child),e.child.forEach(function(t){var n=P(t);return n.parent=e,n}),e):e}function B(e,t){return Object.keys(t).find(function(n){return t[n].id===e})||null}function T(e){return e.child.forEach(function(t){t.parent=e}),e}function F(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}function z(){return F()+"-"+F()}function L(e,t){if(!u(e))return L([e],t);var n=t||null;return e.reduce(function(e,r){return"number"!=typeof r&&r?("string"==typeof r?e.push({id:z(),text:r,parent:n,child:[],data:{}}):u(r)?e.push.apply(e,L(r,t)):(r.id=r.id||z(),r.child=u(r.child)?L(r.child,r):[],r.data||(r.data={}),r.parent=n,e.push(r)),e):e},[]).filter(function(e){return e.text&&c(e.text)})}function H(e){try{return Object.assign({},{loading:!0},e)}catch(e){return{loading:!0}}}function q(e,t,n){var r={current:e},i=$(t.get(),!0).ids,o=i.indexOf(e.id);return~o?{current:e,parent:e.parent,next:t.byId(i[o+1]),prev:t.byId(i[o-1])}:r}e=e&&e.hasOwnProperty("default")?e.default:e;var W=function(e,t){return(W=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},G=function(){return(G=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++){t=arguments[n];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])}return e}).apply(this,arguments)},J={}.hasOwnProperty,Q={}.hasOwnProperty,V=function(e){return e.isBatch||e.child.length>0},X=["id","checked","selected","child","checked","expanded","hash","loading"],Y=function(n){function r(){var t=null!==n&&n.apply(this,arguments)||this;return t.handleSelect=function(e){t.props.onSelect&&t.props.onSelect(t.getNode(),e)},t.handleCheck=function(){t.props.onCheck&&t.props.onCheck(t.getNode())},t.handleExpand=function(){t.props.onExpand&&t.props.onExpand(t.getNode())},t.handleDoubleClick=function(e){t.props.onDoubleClick&&t.props.onDoubleClick(t.getNode())},t.renderCheckbox=function(){if(!t.props.checkable)return null;var n=t.props.checkboxRenderer;return n?e.createElement("span",{className:"node-checkbox-overrided",onMouseUp:t.handleCheck},e.createElement(n,{node:t.getNode()})):e.createElement("span",{className:"node-checkbox",onMouseUp:t.handleCheck})},t.renderArrow=function(){var n=t.props.arrowRenderer;return V(t.props)?n?e.createElement("span",{className:"node-arrow-extended",onMouseUp:t.handleExpand},e.createElement(n,{node:t.getNode()})):e.createElement("span",{className:"node-arrow",onMouseUp:t.handleExpand}):e.createElement("span",{className:"node-noop"})},t}return t(r,n),r.prototype.shouldComponentUpdate=function(e){return 0===e.depth&&this.props.hash!==e.hash||!E(this.props,e,X)},r.prototype.getNode=function(){return this.props.node},r.prototype.render=function(){var t=this.props,n=t.loading,r=t.checked,i=t.selected,o=t.children,c=t.expanded,a=t.disabled,u=t.disabledCheckbox,d=t.className,s=t.indeterminate,l=t.useIndeterminateState,p=t.textRenderer,f=this.props.text,h=S({"node-content":!0,"has-child":V(this.props),selected:i,checked:r,expanded:c,disabled:a,loading:n,"disabled-checkbox":u,indeterminate:!r&&s&&!1!==l}),v=["tree-node"];return d&&v.push(d),e.createElement("li",{className:v.join(" ")},e.createElement("div",{className:h},this.renderArrow(),this.renderCheckbox(),e.createElement("span",{className:"node-text",onMouseUp:this.handleSelect,onDoubleClick:this.handleDoubleClick},p?e.createElement(p,{node:this.getNode()}):f)),o&&c&&e.createElement("ul",{className:"node-child"},o))},r}(e.Component),Z={disabledCheckbox:function(e,t){return!t==!e.disabledCheckbox},disabled:function(e,t){return!t==!e.disabled},expandable:function(e,t){return t===d(e)},expanded:function(e,t){return t?!!e.expanded:d(e)&&!e.expanded},selected:function(e,t){return!t==!e.selected},checked:function(e,t){return!t==!e.checked},checkable:function(e,t){return t===s(e)},isLeaf:function(e,t){return t!==d(e)},$not:function(e,t){var r=n(t).map(N);return o(t)&&"expanded"in t&&r.push(N({expandable:!1})),!1===_(e,r)}},ee=function(){function e(e,t,n){this.tree=e,this.state=t,this.core=n}return e.prototype._operate=function(e,t){var n=this.find(e);return n?t(n):null},e.prototype.find=function(e){return A(this.state.get(),M,!1,e)},e.prototype.findAll=function(e){return A(this.state.get(),M,!0,e)},e.prototype.selected=function(){var e=this.state,t=this.tree.selected.map(function(t){return e.byId(t)});return!0!==this.tree.props.multiple?t.length?t[0]:null:t.filter(function(e){return null!==e})},e.prototype.checked=function(e,t){var n=this.state,r=[];switch(this.tree.checked.forEach(function(e){var t=n.byId(e);t&&r.push(t)}),"WITH_INDETERMINATE"===e&&this.tree.indeterminate.forEach(function(e){var t=n.byId(e);t&&r.push(t)}),t||(r=r.filter(s)),e){case"LEAF":return r.filter(function(e){return g(e)});case"BRANCH":return r.filter(function(e){return!e.parent||!e.parent.checked})}return r},e.prototype.set=function(e,t,n){var r=this.find(e);return!!r&&(this.state.set(r.id,t,n),this.tree.updateState(),!0)},e.prototype.data=function(e,t,n){var r=this;return this._operate(e,function(e){return r.core.data(e,t,n)})},e.prototype.addClass=function(e,t){var n=this;return this._operate(e,function(e){return n.core.addClass(e,t)})},e.prototype.removeClass=function(e,t){var n=this;return this._operate(e,function(e){return n.core.removeClass(e,t)})},e.prototype.hasClass=function(e,t){var n=this;return this._operate(e,function(e){return n.core.hasClass(e,t)})},e.prototype.append=function(e,t,n){var r=this;return this._operate(e,function(e){return r.core.insert(e,t,n)})},e.prototype.prepend=function(e,t,n){var r=this;return this._operate(e,function(e){return r.core.insert(e,t,Object.assign({},n,{index:0}))})},e.prototype.before=function(e,t){var n=this;return this._operate(e,function(e){return n.core.beside(e,t,0)})},e.prototype.after=function(e,t){var n=this;return this._operate(e,function(e){return n.core.beside(e,t,1)})},e.prototype.remove=function(e){var t=this;return this._operate(e,function(e){return t.core.remove(e)})},e.prototype.uncheckAll=function(){return this.core.uncheckAll()},e.prototype.unselectAll=function(){return this.core.unselectAll()},e.prototype.toArray=function(){return this.state.get()},e}(),te=function(){function e(e){this.nodes=e}return e.prototype.updateRoot=function(e,t){var n=B(e.id,this.nodes),r=b(e);if(t&&t.forEach(function(t){var n=t[0],i=t[1];e[n]=i,r[n]=i}),null!==n)return this.nodes[n]=T(r),this.nodes[n]},e.prototype.updateLeaf=function(e,t){var n=R(e),r=e.parent;if(r&&n&&r.child){var i=this.getIndex(e);if(null!==i)return t&&t.forEach(function(t){var n=t[0],o=t[1];e[n]=o,r.child[i][n]=o}),this.updateRoot(P(n)),e}},e.prototype.set=function(e,t,n){var r=this.byId(e);if(r)return x(r)?this.updateRoot(r,K(t,n)):this.updateLeaf(r,K(t,n))},e.prototype.getIndex=function(e){var t=e.parent,n=e.id;if(t&&t.child){var r=null;return t.child.some(function(e,t){return n===e.id&&(r=t,!0)}),r}for(var i=0;i<this.nodes.length;i++)if(this.nodes[i].id===n)return i;return null},e.prototype.insertAt=function(e,t,n){var r;if(e&&e.child){var i=y(e.child);return i.splice.apply(i,[n,0].concat(t)),i}return(r=this.nodes).splice.apply(r,[n,0].concat(t)),t},e.prototype.remove=function(e){var t=this.byId(e);if(!t)return null;var n=this.getIndex(t);if(null===n||!~n)return null;var r=t.parent;if(r){var i=y(r.child);i.splice(n,1),this.set(r.id,"child",i)}else this.nodes.splice(n,1);return t},e.prototype.byId=function(e){var t=null;return w(this.nodes,function(n){if(n.id===e)return t=n,!1}),t},e.prototype.get=function(){return this.nodes},e.prototype.toArray=function(){return m(this.nodes)},e}(),ne=function(){function e(e,t){var n=this;this.flatMap=function(e,t){return $(e,t)},this.set=function(e,t,r){n.state.set(e.id,t,r),n.tree.updateState()},this.updateKeys=function(e,t){var r,i=n.tree,o=i.getState(),c=i.checked,a=!0!==i.props.noCascade;t&&t.forEach(function(e){e.selected&&(r=e.id)}),e.forEach(function(e){var t=e.depth||0;w(e,function(n,o){n.id!==e.id&&(n.depth=t+o),a&&n.parent&&n.parent.checked&&(n.checked=!0),n.checked&&!v(c,n.id)&&c.push(n.id),n.selected&&(i.selected.push(n.id),r||(r=n.id))}),r&&(i.selected=i.selected.filter(function(e){return e!==r&&o.set(e,"selected",!1),e===r})),a&&c.forEach(function(e){var t=o.byId(e);t&&g(t)&&i.refreshDefinite(e,!0,!1)})})},this.clearKeys=function(e,t){void 0===t&&(t=!1);var r=n.tree.selected,i=n.tree.checked,o=n.tree.indeterminate;w(e,function(e){e.selected&&k(r,e.id),e.checked&&k(i,e.id),k(o,e.id)},t)},this.load=function(e,t,i){var o=r(e,t);return i&&n.set(e,"loading",!0),o.then(function(t){return n.state.set(e.id,{isBatch:!1,loading:!1}),L(t,e)})},this.beside=function(e,t,r){var i=n.state.getIndex(e);if(null===i)return Promise.resolve([]);var o=e.parent,c=function(e){return n.insert(o,e,{expand:!!o&&o.expanded,loading:!1,index:i+r})};return p(t)?n.load(e,t,!1).then(function(e){return c(e)}):c(t)},this.insert=function(e,t,r){r=H(r);var i=n.tree,o=i.getState(),c=function(t){var c=void 0!==r.index?r.index:e&&e.child?e.child.length:0,a=o.insertAt(e,t,c);if(e){var u=o.set(e.id,{child:a});u&&(n.updateKeys([u],t),r.expand&&!u.expanded&&n.tree.expand(u))}else n.updateKeys(t);return i.$emit("Add",e,t),i.updateState(),t.map(function(e){return o.byId(e.id)}).filter(Boolean)};return e&&p(t)?n.load(e,t,r.loading).then(c):Promise.resolve(c(L(t)))},this.remove=function(e){var t=n.tree,r=e.id;t.props.checkable&&e.checked&&(n.state.set(r,"checked",!1),t.checked=t.checked.filter(function(e){return r!==e}),t.refreshDefinite(r,!1,!1));var i=n.state.remove(r);return i&&(i.parent=null,n.clearKeys(i),t.updateState(),t.$emit("Remove",i)),i},this.data=function(e,t,r){if(!t&&!r)return e.data;if(void 0===r&&c(t))return e.data[t];var i;return c(t)?(e.data[t]=r,i=e.data):i=Object.assign({},e.data,t),n.state.set(e.id,"data",i),n.tree.updateState(),e},this.hasClass=function(e,t){return!!e.className&&new RegExp(t).test(e.className)},this.uncheckAll=function(){var e=n.tree;if(e.props.checkable){var t=e.getState(),r=n.find(t.get(),!0,[{checked:!0},{indeterminate:!0}]);r&&r.forEach(function(e){n.tree.$emit("UnCheck",t.set(e.id,{checked:!1,indeterminate:!1}))}),e.updateState(),e.checked=[],e.indeterminate=[]}},this.unselectAll=function(){var e=n.tree,t=e.getState(),r=n.find(t.get(),!0,{selected:!0});r&&r.forEach(function(e){n.tree.$emit("UnSelect",t.set(e.id,{selected:!1}))}),e.updateState(),e.selected=[]},this.state=t,this.tree=e}return e.prototype.find=function(e,t,n){return A(e,M,t,n)},e.prototype.removeClass=function(e,t){var r=(e.className||"").split(" ").filter(function(e){return!v(n(t),e)}).join(" ");return this.set(e,"className",r),e},e.prototype.addClass=function(e,t){var r=e.className?e.className.split(" "):[];return n(t).forEach(function(e){v(r,""+e)||r.push(e)}),this.set(e,"className",r.join(" ")),e},e}(),re=["checkable","useIndeterminateState","checkboxRenderer","arrowRenderer","textRenderer"];return function(n){function r(t){var r=n.call(this,t)||this;r.silence=!1,r.selected=[],r.checked=[],r.indeterminate=[],r.$emit=function(e,t){for(var n=[],i=2;i<arguments.length;i++)n[i-2]=arguments[i];if(!r.silence){var o=r.props["on"+e];if(o)if(c(t)){var a=r.getState().byId(t);a&&o.call.apply(o,[null,a].concat(n))}else o.call.apply(o,[null,t].concat(n))}},r.refreshDefinite=function(e,t,n){var i=y(r.checked),o=y(r.indeterminate),c=r.getState(),a=[],u=c.byId(e),d=[];u&&(w(u,function(e){e.disabled||e.disabledCheckbox||(a.push(e.id),e.checked!==t&&d.push(e.id))},!0),t?i.push.apply(i,a.filter(function(e){return!v(i,e)})):i=i.filter(function(e){return!v(a,e)}),D(u,function(e){if(e.disabledCheckbox||e.disabled)return!1;var n=C(e,i,o),r=e.id;n?(v(o,r)||o.push(r),i=i.filter(function(e){return e!==r})):(o=o.filter(function(e){return e!==r}),t&&!v(i,r)?i.push(r):i=i.filter(function(e){return e!==r}))}),o=o.filter(function(e){return!v(i,e)}),t?i.forEach(function(e){v(r.checked,e)||c.set(e,"checked",!0)}):(r.checked.forEach(function(e){v(i,e)||c.set(e,"checked",!1)}),a.forEach(function(e){c.set(e,"checked",!1)})),r.indeterminate.forEach(function(e){c.set(e,"indeterminate",!1)}),!1!==r.props.useIndeterminateState&&o.forEach(function(e){return c.set(e,"indeterminate",!0)}),r.checked=i,r.indeterminate=o,!1!==n&&r.updateState(),d.forEach(function(e){r.$emit("Check",e,t)}))},r.getState=function(){return r._state},r.getSelectedNode=function(){var e=r.selected[r.selected.length-1];return e?r.getState().byId(e):null},r.updateState=function(e){void 0===e&&(e=r._state);var t=e.get();r.props.onChange?r.props.onChange(e.toArray()):r.setState({nodes:t})},r.unselect=function(e){if(e.selected){var t=r.getState();t.set(e.id,"selected",!1),r.selected=r.selected.filter(function(n){return n!==e.id||(t.byId(n)&&(t.set(n,"selected",!1),r.$emit("UnSelect",n)),!1)}),r.updateState()}},r.select=function(e,t,n,i){var o=r.getState(),c=e.id,a=[],u=r.props.multiple;if(n&&e.selected)return r.unselect(e);!u&&e.selected||((!u||u&&!n)&&(r.selected=r.selected.filter(function(e){var t=o.byId(e);return t&&(o.set(t.id,"selected",!1),a.push(["UnSelect",t.id])),!1})),o.set(c,"selected",!0),r.focused=c,r.selected.push(c),i||r.updateState(),!0!==t&&(a.push(["Select",c]),a.forEach(function(e){return r.$emit(e[0],e[1])})))},r.selectRange=function(e,t){var n=$(r.state.nodes,!0),i=n.ids,o=n.nodes,c=i.indexOf(e),a=i.indexOf(t);if(~c&&~a){var u=Math.min(c,a),d=Math.max(c,a)+1,s=r.getState(),l=o.slice(u,d).map(function(e){return e.id}),p=[];r.selected.forEach(function(e){v(l,e)||(s.set(e,"selected",!1),p.push(["UnSelect",e]))}),r.selected=l.map(function(e){return v(r.selected,e)||(s.set(e,"selected",!0),p.push(["Select",e])),e}),r.updateState(),p.forEach(function(e){var t=e[0],n=e[1];r.$emit(t,n)})}},r.check=function(e){if(r.props.checkable&&!e.disabled&&!e.disabledCheckbox){var t=r.getState(),n=!e.checked,i=e.id;t.set(i,"checked",n),r.checked=n?r.checked.concat([i]):r.checked.filter(function(e){return i!==e}),r.props.selectOnCheck&&r.select(e),!0!==r.props.noCascade?r.refreshDefinite(e.id,n):r.updateState(),r.$emit("Check",i,n)}},r.expand=function(e,t){if(!e.disabled||t){if(e.isBatch)return r.loadChild(e);if(d(e)){var n=r.getState(),i=r.props.selectOnExpand;n.set(e.id,"expanded",!e.expanded),i&&!e.selected&&r.select(e),r.updateState(),r.$emit("Expand",e.id,!e.expanded)}}},r.handleDoubleClick=function(e){r.$emit("DoubleClick",e.id),e.disabled||g(e)||r.props.expandOnSelect||r.expand(e)},r.handleSelect=function(e,t){if(!e.disabled){if(r.props.preventSelectParent&&d(e))return r.expand(e);var n=r.props,i=n.multiple,o=n.checkOnSelect,c=n.expandOnSelect,a=n.checkable;if(t.shiftKey&&i&&r.focused)return r.selectRange(r.focused,e.id);r.select(e,!1,t.ctrlKey),t.ctrlKey||(a&&o&&!e.disabledCheckbox?r.check(e):c&&r.expand(e))}},r.handleKeyUp=function(e){if(!1!==r.props.keyboardNavigation){var t=e.keyCode,n=r.getSelectedNode();if(n)switch(t){case 32:case 13:!r.props.checkable||n.disabled||n.disabledCheckbox?g(n)||r.expand(n):r.check(n);break;case 27:r.props.multiple?r.core.unselectAll():r.unselect(n);break;case 39:if(!g(n))if(n.expanded){var i=j(n,!0);i&&r.select(i)}else r.expand(n);break;case 37:if(g(n)||!n.expanded){var o=n.parent;o&&!o.disabled&&r.select(o)}else n.expanded&&r.expand(n);break;case 40:var c=q(n,r.getState()).next;c&&r.select(c);break;case 38:var a=q(n,r.getState()).prev;a&&r.select(a)}}},r.loadChild=function(e){var t=r.props.fetchData;if(t&&!e.loading)return r.core.insert(e,t,{expand:!0})},r.renderNode=function(t){var n=["checkable","arrowRenderer","textRenderer","checkboxRenderer"].reduce(function(e,t){return r.props[t]&&(e[t]=r.props[t]),e},{});return n.hash=r.state.hash,n.useIndeterminateState=r.props.useIndeterminateState,e.createElement(Y,G({key:t.id,node:t,onSelect:r.handleSelect,onDoubleClick:r.handleDoubleClick,onCheck:r.check,onExpand:r.expand},n,t),t.expanded?t.child.map(r.renderNode):null)};var o=L(m(t.data||[]));return w(o,function(e,t){e.depth=t,e.selected&&r.selected.push(e.id),e.checked&&r.checked.push(e.id)}),r._state=new te(o),r.core=new ne(r,r._state),!0!==r.props.noCascade&&r.checked.forEach(function(e){var t=r._state.byId(e);t&&(!g(t)&&t.parent||r.refreshDefinite(e,!0,!1))}),r.state={nodes:r._state.get(),hash:z(),mutatingFields:i(t,re)},r}return t(r,n),r.getDerivedStateFromProps=function(e,t){return e.onChange?{hash:z(),nodes:L(m(e.data||[]))}:E(e,t.mutatingFields,re)?null:{hash:z(),mutatingFields:i(e,re)}},r.prototype.isControlled=function(){return!!this.props.onChange},r.prototype.componentDidMount=function(){this.props.onReady&&this.props.onReady(new ee(this,this._state,this.core))},r.prototype.render=function(){var t=this,n=this.props,r="theme"in n?"eyzy-tree "+n.theme:"eyzy-tree eyzy-theme";return this.isControlled()&&(this._state.nodes=this.state.nodes),e.createElement("ul",{className:r,tabIndex:-1,onKeyDown:this.handleKeyUp},this.state.nodes.map(function(e){return t.renderNode(e)}))},r.TreeNode=Y,r}(e.Component)});