"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _extends2=require("babel-runtime/helpers/extends"),_extends3=_interopRequireDefault(_extends2),_toConsumableArray2=require("babel-runtime/helpers/toConsumableArray"),_toConsumableArray3=_interopRequireDefault(_toConsumableArray2),_classCallCheck2=require("babel-runtime/helpers/classCallCheck"),_classCallCheck3=_interopRequireDefault(_classCallCheck2),_createClass2=require("babel-runtime/helpers/createClass"),_createClass3=_interopRequireDefault(_createClass2),_possibleConstructorReturn2=require("babel-runtime/helpers/possibleConstructorReturn"),_possibleConstructorReturn3=_interopRequireDefault(_possibleConstructorReturn2),_inherits2=require("babel-runtime/helpers/inherits"),_inherits3=_interopRequireDefault(_inherits2),_react=require("react"),React=_interopRequireWildcard(_react),_classnames=require("classnames"),_classnames2=_interopRequireDefault(_classnames),_omit=require("omit.js"),_omit2=_interopRequireDefault(_omit),_lodash=require("lodash.debounce"),_lodash2=_interopRequireDefault(_lodash),_util=require("rc-tree/lib/util"),_Tree=require("./Tree"),_Tree2=_interopRequireDefault(_Tree),_util2=require("./util"),_icon=require("../icon"),_icon2=_interopRequireDefault(_icon);function _interopRequireWildcard(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t}function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}var __rest=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var l=0;for(n=Object.getOwnPropertySymbols(e);l<n.length;l++)t.indexOf(n[l])<0&&(r[n[l]]=e[n[l]])}return r};function getIcon(e){var t=e.isLeaf,r=e.expanded;return t?React.createElement(_icon2.default,{type:"file"}):React.createElement(_icon2.default,{type:r?"folder-open":"folder"})}var DirectoryTree=function(e){function o(e){(0,_classCallCheck3.default)(this,o);var C=(0,_possibleConstructorReturn3.default)(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,e));C.onExpand=function(e,t){var r=C.props.onExpand;if(C.setUncontrolledState({expandedKeys:e}),r)return r(e,t)},C.onClick=function(e,t){var r=C.props,n=r.onClick;"click"===r.expandAction&&C.onDebounceExpand(e,t),n&&n(e,t)},C.onDoubleClick=function(e,t){var r=C.props,n=r.onDoubleClick;"doubleClick"===r.expandAction&&C.onDebounceExpand(e,t),n&&n(e,t)},C.onSelect=function(e,t){var r=C.props,n=r.onSelect,l=r.multiple,a=r.children,s=C.state,o=s.expandedKeys,i=void 0===o?[]:o,c=s.selectedKeys,u=void 0===c?[]:c,d=t.node,p=t.nativeEvent,_=d.props.eventKey,f=void 0===_?"":_,y={},x=p.ctrlKey||p.metaKey,h=p.shiftKey,b=u.slice();l&&x?(b=e,C.lastSelectedKey=f,C.cachedSelectedKeys=b):l&&h?b=Array.from(new Set([].concat((0,_toConsumableArray3.default)(C.cachedSelectedKeys||[]),(0,_toConsumableArray3.default)((0,_util2.calcRangeKeys)(a,i,f,C.lastSelectedKey))))):(b=[f],C.lastSelectedKey=f,C.cachedSelectedKeys=b),y.selectedKeys=b,n&&n(b,t),C.setUncontrolledState(y)},C.expandFolderNode=function(e,t){var r=C.state.expandedKeys,n=void 0===r?[]:r,l=C.props.onExpand,a=t.props,s=a.eventKey,o=void 0===s?"":s,i=a.expanded;if(!(a.isLeaf||e.shiftKey||e.metaKey||e.ctrlKey)){var c=n.slice(),u=c.indexOf(o);i&&0<=u?c.splice(u,1):i||-1!==u||c.push(o),C.setUncontrolledState({expandedKeys:c}),l&&l(c,{expanded:!i,node:t,nativeEvent:e.nativeEvent})}},C.setUncontrolledState=function(e){var t=(0,_omit2.default)(e,Object.keys(C.props));Object.keys(t).length&&C.setState(t)};var t=e.defaultExpandAll,r=e.defaultExpandParent,n=e.expandedKeys,l=e.defaultExpandedKeys,a=e.children,s=(0,_util.convertTreeToEntities)(a).keyEntities;return C.state={selectedKeys:e.selectedKeys||e.defaultSelectedKeys||[]},C.state.expandedKeys=t?(0,_util2.getFullKeyList)(e.children):r?(0,_util.conductExpandParent)(n||l,s):l,C.onDebounceExpand=(0,_lodash2.default)(C.expandFolderNode,200,{leading:!0}),C}return(0,_inherits3.default)(o,e),(0,_createClass3.default)(o,[{key:"componentWillReceiveProps",value:function(e){"expandedKeys"in e&&this.setState({expandedKeys:e.expandedKeys}),"selectedKeys"in e&&this.setState({selectedKeys:e.selectedKeys})}},{key:"render",value:function(){var e=this.props,t=e.prefixCls,r=e.className,n=__rest(e,["prefixCls","className"]),l=this.state,a=l.expandedKeys,s=l.selectedKeys,o=(0,_classnames2.default)(t+"-directory",r);return React.createElement(_Tree2.default,(0,_extends3.default)({icon:getIcon},n,{prefixCls:t,className:o,expandedKeys:a,selectedKeys:s,onSelect:this.onSelect,onClick:this.onClick,onDoubleClick:this.onDoubleClick,onExpand:this.onExpand}))}}]),o}(React.Component);(exports.default=DirectoryTree).defaultProps={prefixCls:"dt-tree",showIcon:!0,expandAction:"click"},module.exports=exports.default;