UNPKG

22.2 kBJavaScriptView Raw
1/*!
2 * EyzyTree vv0.2.2
3 * (c) 2019 amsik
4 * Released under the MIT License.
5 */
6function __extends(e,t){function n(){this.constructor=e}extendStatics(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}function toArray(e){return isArray(e)?e:[e]}function callFetcher(e,t){if(!isCallable(t))throw new TypeError('"fetcher" it must be either function or promise');var n=isFunction(t)?t(e):t;if(!n||!n.then)throw new TypeError('"fetcher" property must return a Promise');return n}function grapObjProps(e,t){return t.reduce(function(t,n){return n in e&&(t[n]=e[n]),t},{})}function isObject(e){return null!=e&&"object"==typeof e&&!Array.isArray(e)}function isString(e){return"string"==typeof e}function isRegExp(e){return e instanceof RegExp}function isArray(e){return Array.isArray(e)}function isExpandable(e){return!(!e.child||!e.child.length)||!!e.isBatch}function isCheckable(e){return!(e.disabled||e.disabledCheckbox)}function isFunction(e){return"function"==typeof e}function isCallable(e){return isFunction(e)||e&&!!e.then}function isEmpty(e){return isArray(e)?0===e.length:!e}function get(e,t){if(e){isArray(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 has(e,t){return!!~e.indexOf(t)}function copyArray(e){return e.concat([])}function copy(e){var t=isArray(e)?[]:{};for(var n in e)if("parent"!==n&&hasOwnProp.call(e,n)){var r=e[n];t[n]="object"==typeof r?copy(r):r}return t}function copyObject(e){var t={};for(var n in e)hasOwnProp.call(e,n)&&(t[n]=isArray(e[n])?copyArray(e[n]):e[n]);return t}function remove(e,t){var n=e.indexOf(t);~n&&e.splice(n,1)}function isRoot(e){return e&&!e.parent}function isLeaf(e){return!e.child||0===e.child.length&&!e.isBatch}function isNodeIndeterminate(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 cn(e){var t=[];if(isArray(e))return e.join(" ");for(var n in e)hasOwn.call(e,n)&&e[n]&&t.push(n);return t.join(" ")}function shallowEqual(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 parseQuery(e){if(isFunction(e))return e;if(isString(e))return function(t){return testKey(e,t.id)||testKey(e,t.text)};if(e.id)return function(t){return testKey(e.id,t.id)};var t=isRegExp(e)?{text:e}:e;return function(e){var n=Object.keys(t);return!!n.length&&n.every(function(n){return n in specials?toArray(t[n]).some(function(t){return testSpecial(specials[n],t,e)}):toArray(t[n]).some(function(t){return testKey(t,get(e,n))})})}}function testSpecial(e,t,n){return!0===e(n,t)}function testKey(e,t){return isRegExp(e)?new RegExp(e).test(t):e===t}function matchQuery(e,t){return t.some(function(t){return!0===t(e)})}function find(e,t,n,r){if(isEmpty(r))return null;var i=[],a=toArray(r).map(parseQuery);return t(e,function(e){return!matchQuery(e,a)||(i.push(e),n)}),i.length?n?i:i[0]:n?[]:null}function recurseDown(e,t,n,r){void 0===r&&(r=0);var i;return Array.isArray(e)?e.map(function(e){return recurseDown(e,t,!1,r)}):(n||(i=t(e,r)),!1!==i&&e.child&&e.child.length&&(i=recurseDown(e.child,t,!1,r+1)),i)}function rootElement(e){for(var t=e.parent;t;){if(!t.parent)return t;t=t.parent}return null}function traverseUp(e,t){for(var n=e.parent;n;){if(!1===t(n)||!n.parent)return;n=n.parent}}function getFirstChild(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 isRootParentCollapsed(e){var t=rootElement(e);return!!t&&!t.expanded}function flatMap(e,t){var n={nodes:[],ids:[]};return recurseDown(e,function(e){e.disabled||t&&e.parent&&!e.parent.expanded||isRootParentCollapsed(e)||(n.nodes.push(e),n.ids.push(e.id))}),n}function walkBreadth(e,t){var n={};return recurseDown(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 iterable(e,t){if("string"==typeof e)return[[e,t]];if(!t){var n=[];for(var r in e)hasOwnProp.call(e,r)&&n.push([r,e[r]]);return n}return[]}function replace(e){return e&&e.child?(e.child=copyArray(e.child),e.child.forEach(function(t){var n=replace(t);return n.parent=e,n}),e):e}function itemById(e,t){return Object.keys(t).find(function(n){return t[n].id===e})||null}function updateChild(e){return e.child.forEach(function(t){t.parent=e}),e}function s4(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}function uuid(){return s4()+"-"+s4()}function parseNode(e,t){if(!isArray(e))return parseNode([e],t);var n=t||null;return e.reduce(function(e,r){return"number"!=typeof r&&r?("string"==typeof r?e.push({id:uuid(),text:r,parent:n,child:[],data:{}}):isArray(r)?e.push.apply(e,parseNode(r,t)):(r.id=r.id||uuid(),r.child=isArray(r.child)?parseNode(r.child,r):[],r.data||(r.data={}),r.parent=n,e.push(r)),e):e},[]).filter(function(e){return e.text&&isString(e.text)})}function parseOpts(e){try{return Object.assign({},{loading:!0},e)}catch(e){return{loading:!0}}}function linkedNode(e,t,n){var r={current:e},i=flatMap(t.get(),!0).ids,a=i.indexOf(e.id);return~a?{current:e,parent:e.parent,next:t.byId(i[a+1]),prev:t.byId(i[a-1])}:r}import React from"react";var extendStatics=function(e,t){return(extendStatics=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)},__assign=function(){return(__assign=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)},hasOwnProp={}.hasOwnProperty,hasOwn={}.hasOwnProperty,hasChild=function(e){return e.isBatch||e.child.length>0},comparingKeys=["id","checked","selected","child","checked","expanded","hash","loading"],Node=function(e){function t(){var t=null!==e&&e.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 e=t.props.checkboxRenderer;return e?React.createElement("span",{className:"node-checkbox-overrided",onMouseUp:t.handleCheck},React.createElement(e,{node:t.getNode()})):React.createElement("span",{className:"node-checkbox",onMouseUp:t.handleCheck})},t.renderArrow=function(){var e=t.props.arrowRenderer;return hasChild(t.props)?e?React.createElement("span",{className:"node-arrow-extended",onMouseUp:t.handleExpand},React.createElement(e,{node:t.getNode()})):React.createElement("span",{className:"node-arrow",onMouseUp:t.handleExpand}):React.createElement("span",{className:"node-noop"})},t}return __extends(t,e),t.prototype.shouldComponentUpdate=function(e){return 0===e.depth&&this.props.hash!==e.hash||!shallowEqual(this.props,e,comparingKeys)},t.prototype.getNode=function(){return this.props.node},t.prototype.render=function(){var e=this.props,t=e.loading,n=e.checked,r=e.selected,i=e.children,a=e.expanded,o=e.disabled,c=e.disabledCheckbox,s=e.className,d=e.indeterminate,u=e.useIndeterminateState,l=e.textRenderer,p=this.props.text,h=cn({"node-content":!0,"has-child":hasChild(this.props),selected:r,checked:n,expanded:a,disabled:o,loading:t,"disabled-checkbox":c,indeterminate:!n&&d&&!1!==u}),f=["tree-node"];return s&&f.push(s),React.createElement("li",{className:f.join(" ")},React.createElement("div",{className:h},this.renderArrow(),this.renderCheckbox(),React.createElement("span",{className:"node-text",onMouseUp:this.handleSelect,onDoubleClick:this.handleDoubleClick},l?React.createElement(l,{node:this.getNode()}):p)),i&&a&&React.createElement("ul",{className:"node-child"},i))},t}(React.Component),specials={disabledCheckbox:function(e,t){return!t==!e.disabledCheckbox},disabled:function(e,t){return!t==!e.disabled},expandable:function(e,t){return t===isExpandable(e)},expanded:function(e,t){return t?!!e.expanded:isExpandable(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===isCheckable(e)},isLeaf:function(e,t){return t!==isExpandable(e)},$not:function(e,t){var n=toArray(t).map(parseQuery);return isObject(t)&&"expanded"in t&&n.push(parseQuery({expandable:!1})),!1===matchQuery(e,n)}},TreeAPI=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 find(this.state.get(),walkBreadth,!1,e)},e.prototype.findAll=function(e){return find(this.state.get(),walkBreadth,!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(isCheckable)),e){case"LEAF":return r.filter(function(e){return isLeaf(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}(),State=function(){function e(e){this.nodes=e}return e.prototype.updateRoot=function(e,t){var n=itemById(e.id,this.nodes),r=copyObject(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]=updateChild(r),this.nodes[n]},e.prototype.updateLeaf=function(e,t){var n=rootElement(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],a=t[1];e[n]=a,r.child[i][n]=a}),this.updateRoot(replace(n)),e}},e.prototype.set=function(e,t,n){var r=this.byId(e);if(r)return isRoot(r)?this.updateRoot(r,iterable(t,n)):this.updateLeaf(r,iterable(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=copyArray(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=copyArray(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 recurseDown(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 copy(this.nodes)},e}(),CoreTree=function(){function e(e,t){var n=this;this.flatMap=function(e,t){return flatMap(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,a=i.getState(),o=i.checked,c=!0!==i.props.noCascade;t&&t.forEach(function(e){e.selected&&(r=e.id)}),e.forEach(function(e){var t=e.depth||0;recurseDown(e,function(n,a){n.id!==e.id&&(n.depth=t+a),c&&n.parent&&n.parent.checked&&(n.checked=!0),n.checked&&!has(o,n.id)&&o.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&&a.set(e,"selected",!1),e===r})),c&&o.forEach(function(e){var t=a.byId(e);t&&isLeaf(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,a=n.tree.indeterminate;recurseDown(e,function(e){e.selected&&remove(r,e.id),e.checked&&remove(i,e.id),remove(a,e.id)},t)},this.load=function(e,t,r){var i=callFetcher(e,t);return r&&n.set(e,"loading",!0),i.then(function(t){return n.state.set(e.id,{isBatch:!1,loading:!1}),parseNode(t,e)})},this.beside=function(e,t,r){var i=n.state.getIndex(e);if(null===i)return Promise.resolve([]);var a=e.parent,o=function(e){return n.insert(a,e,{expand:!!a&&a.expanded,loading:!1,index:i+r})};return isCallable(t)?n.load(e,t,!1).then(function(e){return o(e)}):o(t)},this.insert=function(e,t,r){r=parseOpts(r);var i=n.tree,a=i.getState(),o=function(t){var o=void 0!==r.index?r.index:e&&e.child?e.child.length:0,c=a.insertAt(e,t,o);if(e){var s=a.set(e.id,{child:c});s&&(n.updateKeys([s],t),r.expand&&!s.expanded&&n.tree.expand(s))}else n.updateKeys(t);return i.$emit("Add",e,t),i.updateState(),t.map(function(e){return a.byId(e.id)}).filter(Boolean)};return e&&isCallable(t)?n.load(e,t,r.loading).then(o):Promise.resolve(o(parseNode(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&&isString(t))return e.data[t];var i;return isString(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 find(e,walkBreadth,t,n)},e.prototype.removeClass=function(e,t){var n=(e.className||"").split(" ").filter(function(e){return!has(toArray(t),e)}).join(" ");return this.set(e,"className",n),e},e.prototype.addClass=function(e,t){var n=e.className?e.className.split(" "):[];return toArray(t).forEach(function(e){has(n,""+e)||n.push(e)}),this.set(e,"className",n.join(" ")),e},e}(),mutatingFields=["checkable","useIndeterminateState","checkboxRenderer","arrowRenderer","textRenderer"],EyzyTree=function(e){function t(t){var n=e.call(this,t)||this;n.silence=!1,n.selected=[],n.checked=[],n.indeterminate=[],n.$emit=function(e,t){for(var r=[],i=2;i<arguments.length;i++)r[i-2]=arguments[i];if(!n.silence){var a=n.props["on"+e];if(a)if(isString(t)){var o=n.getState().byId(t);o&&a.call.apply(a,[null,o].concat(r))}else a.call.apply(a,[null,t].concat(r))}},n.refreshDefinite=function(e,t,r){var i=copyArray(n.checked),a=copyArray(n.indeterminate),o=n.getState(),c=[],s=o.byId(e),d=[];s&&(recurseDown(s,function(e){e.disabled||e.disabledCheckbox||(c.push(e.id),e.checked!==t&&d.push(e.id))},!0),t?i.push.apply(i,c.filter(function(e){return!has(i,e)})):i=i.filter(function(e){return!has(c,e)}),traverseUp(s,function(e){if(e.disabledCheckbox||e.disabled)return!1;var n=isNodeIndeterminate(e,i,a),r=e.id;n?(has(a,r)||a.push(r),i=i.filter(function(e){return e!==r})):(a=a.filter(function(e){return e!==r}),t&&!has(i,r)?i.push(r):i=i.filter(function(e){return e!==r}))}),a=a.filter(function(e){return!has(i,e)}),t?i.forEach(function(e){has(n.checked,e)||o.set(e,"checked",!0)}):(n.checked.forEach(function(e){has(i,e)||o.set(e,"checked",!1)}),c.forEach(function(e){o.set(e,"checked",!1)})),n.indeterminate.forEach(function(e){o.set(e,"indeterminate",!1)}),!1!==n.props.useIndeterminateState&&a.forEach(function(e){return o.set(e,"indeterminate",!0)}),n.checked=i,n.indeterminate=a,!1!==r&&n.updateState(),d.forEach(function(e){n.$emit("Check",e,t)}))},n.getState=function(){return n._state},n.getSelectedNode=function(){var e=n.selected[n.selected.length-1];return e?n.getState().byId(e):null},n.updateState=function(e){void 0===e&&(e=n._state);var t=e.get();n.props.onChange?n.props.onChange(e.toArray()):n.setState({nodes:t})},n.unselect=function(e){if(e.selected){var t=n.getState();t.set(e.id,"selected",!1),n.selected=n.selected.filter(function(r){return r!==e.id||(t.byId(r)&&(t.set(r,"selected",!1),n.$emit("UnSelect",r)),!1)}),n.updateState()}},n.select=function(e,t,r,i){var a=n.getState(),o=e.id,c=[],s=n.props.multiple;if(r&&e.selected)return n.unselect(e);!s&&e.selected||((!s||s&&!r)&&(n.selected=n.selected.filter(function(e){var t=a.byId(e);return t&&(a.set(t.id,"selected",!1),c.push(["UnSelect",t.id])),!1})),a.set(o,"selected",!0),n.focused=o,n.selected.push(o),i||n.updateState(),!0!==t&&(c.push(["Select",o]),c.forEach(function(e){return n.$emit(e[0],e[1])})))},n.selectRange=function(e,t){var r=flatMap(n.state.nodes,!0),i=r.ids,a=r.nodes,o=i.indexOf(e),c=i.indexOf(t);if(~o&&~c){var s=Math.min(o,c),d=Math.max(o,c)+1,u=n.getState(),l=a.slice(s,d).map(function(e){return e.id}),p=[];n.selected.forEach(function(e){has(l,e)||(u.set(e,"selected",!1),p.push(["UnSelect",e]))}),n.selected=l.map(function(e){return has(n.selected,e)||(u.set(e,"selected",!0),p.push(["Select",e])),e}),n.updateState(),p.forEach(function(e){var t=e[0],r=e[1];n.$emit(t,r)})}},n.check=function(e){if(n.props.checkable&&!e.disabled&&!e.disabledCheckbox){var t=n.getState(),r=!e.checked,i=e.id;t.set(i,"checked",r),n.checked=r?n.checked.concat([i]):n.checked.filter(function(e){return i!==e}),n.props.selectOnCheck&&n.select(e),!0!==n.props.noCascade?n.refreshDefinite(e.id,r):n.updateState(),n.$emit("Check",i,r)}},n.expand=function(e,t){if(!e.disabled||t){if(e.isBatch)return n.loadChild(e);if(isExpandable(e)){var r=n.getState(),i=n.props.selectOnExpand;r.set(e.id,"expanded",!e.expanded),i&&!e.selected&&n.select(e),n.updateState(),n.$emit("Expand",e.id,!e.expanded)}}},n.handleDoubleClick=function(e){n.$emit("DoubleClick",e.id),e.disabled||isLeaf(e)||n.props.expandOnSelect||n.expand(e)},n.handleSelect=function(e,t){if(!e.disabled){if(n.props.preventSelectParent&&isExpandable(e))return n.expand(e);var r=n.props,i=r.multiple,a=r.checkOnSelect,o=r.expandOnSelect,c=r.checkable;if(t.shiftKey&&i&&n.focused)return n.selectRange(n.focused,e.id);n.select(e,!1,t.ctrlKey),t.ctrlKey||(c&&a&&!e.disabledCheckbox?n.check(e):o&&n.expand(e))}},n.handleKeyUp=function(e){if(!1!==n.props.keyboardNavigation){var t=e.keyCode,r=n.getSelectedNode();if(r)switch(t){case 32:case 13:!n.props.checkable||r.disabled||r.disabledCheckbox?isLeaf(r)||n.expand(r):n.check(r);break;case 27:n.props.multiple?n.core.unselectAll():n.unselect(r);break;case 39:if(!isLeaf(r))if(r.expanded){var i=getFirstChild(r,!0);i&&n.select(i)}else n.expand(r);break;case 37:if(isLeaf(r)||!r.expanded){var a=r.parent;a&&!a.disabled&&n.select(a)}else r.expanded&&n.expand(r);break;case 40:var o=linkedNode(r,n.getState()).next;o&&n.select(o);break;case 38:var c=linkedNode(r,n.getState()).prev;c&&n.select(c)}}},n.loadChild=function(e){var t=n.props.fetchData;if(t&&!e.loading)return n.core.insert(e,t,{expand:!0})},n.renderNode=function(e){var t=["checkable","arrowRenderer","textRenderer","checkboxRenderer"].reduce(function(e,t){return n.props[t]&&(e[t]=n.props[t]),e},{});return t.hash=n.state.hash,t.useIndeterminateState=n.props.useIndeterminateState,React.createElement(Node,__assign({key:e.id,node:e,onSelect:n.handleSelect,onDoubleClick:n.handleDoubleClick,onCheck:n.check,onExpand:n.expand},t,e),e.expanded?e.child.map(n.renderNode):null)};var r=parseNode(copy(t.data||[]));return recurseDown(r,function(e,t){e.depth=t,e.selected&&n.selected.push(e.id),e.checked&&n.checked.push(e.id)}),n._state=new State(r),n.core=new CoreTree(n,n._state),!0!==n.props.noCascade&&n.checked.forEach(function(e){var t=n._state.byId(e);t&&(!isLeaf(t)&&t.parent||n.refreshDefinite(e,!0,!1))}),n.state={nodes:n._state.get(),hash:uuid(),mutatingFields:grapObjProps(t,mutatingFields)},n}return __extends(t,e),t.getDerivedStateFromProps=function(e,t){return e.onChange?{hash:uuid(),nodes:parseNode(copy(e.data||[]))}:shallowEqual(e,t.mutatingFields,mutatingFields)?null:{hash:uuid(),mutatingFields:grapObjProps(e,mutatingFields)}},t.prototype.isControlled=function(){return!!this.props.onChange},t.prototype.componentDidMount=function(){this.props.onReady&&this.props.onReady(new TreeAPI(this,this._state,this.core))},t.prototype.render=function(){var e=this,t=this.props,n="theme"in t?"eyzy-tree "+t.theme:"eyzy-tree eyzy-theme";return this.isControlled()&&(this._state.nodes=this.state.nodes),React.createElement("ul",{className:n,tabIndex:-1,onKeyDown:this.handleKeyUp},this.state.nodes.map(function(t){return e.renderNode(t)}))},t.TreeNode=Node,t}(React.Component);export default EyzyTree;