Comparing version 0.21.3 to 0.22.0
@@ -31,2 +31,6 @@ 'use strict'; | ||
var _TreeNode = require('./TreeNode'); | ||
var _TreeNode2 = _interopRequireDefault(_TreeNode); | ||
var _util = require('./util'); | ||
@@ -65,7 +69,6 @@ | ||
}); | ||
this.defaultExpandAll = props.defaultExpandAll; | ||
this.contextmenuKeys = []; | ||
this.state = { | ||
expandedKeys: props.defaultExpandedKeys, | ||
expandedKeys: this.getDefaultExpandedKeys(props), | ||
checkedKeys: this.getDefaultCheckedKeys(props), | ||
@@ -84,5 +87,6 @@ selectedKeys: this.getDefaultSelectedKeys(props), | ||
var expandedKeys = this.getDefaultExpandedKeys(nextProps, true); | ||
var checkedKeys = this.getDefaultCheckedKeys(nextProps, true); | ||
var selectedKeys = this.getDefaultSelectedKeys(nextProps, true); | ||
this.setState((_setState = {}, _defineProperty(_setState, checkedKeys && 'checkedKeys', checkedKeys), _defineProperty(_setState, selectedKeys && 'selectedKeys', selectedKeys), _setState)); | ||
this.setState((_setState = {}, _defineProperty(_setState, expandedKeys && 'expandedKeys', expandedKeys), _defineProperty(_setState, checkedKeys && 'checkedKeys', checkedKeys), _defineProperty(_setState, selectedKeys && 'selectedKeys', selectedKeys), _setState)); | ||
} | ||
@@ -127,2 +131,7 @@ | ||
if (expandedKeys) { | ||
// Controlled expand, save and then reset | ||
this.getOriginExpandedKeys(); | ||
// if ('expandedKeys' in this.props) { | ||
// this._originExpandedKeys = [...this.state.expandedKeys]; | ||
// } | ||
st.expandedKeys = expandedKeys; | ||
@@ -174,2 +183,3 @@ } | ||
if (expandedKeys) { | ||
this.getOriginExpandedKeys(); | ||
st.expandedKeys = expandedKeys; | ||
@@ -201,6 +211,7 @@ } | ||
} | ||
this.setState({ | ||
var st = { | ||
dragOverNodeKey: '', | ||
dropNodeKey: key | ||
}); | ||
}; | ||
this.setState(st); | ||
@@ -218,2 +229,5 @@ var posArr = treeNode.props.pos.split('-'); | ||
} | ||
if ('expandedKeys' in this.props) { | ||
res.originExpandedKeys = this._originExpandedKeys || [].concat(_toConsumableArray(this.state.expandedKeys)); | ||
} | ||
this.props.onTreeDrop(res); | ||
@@ -228,13 +242,4 @@ } | ||
var tnProps = treeNode.props; | ||
var expandedKeys = this.state.expandedKeys.concat([]); | ||
var expandedKeys = [].concat(_toConsumableArray(this.state.expandedKeys)); | ||
var expanded = !tnProps.expanded; | ||
if (this.defaultExpandAll) { | ||
this.loopAllChildren(thisProps.children, function (item, index, pos) { | ||
var key = item.key || pos; | ||
if (expandedKeys.indexOf(key) === -1) { | ||
expandedKeys.push(key); | ||
} | ||
}); | ||
this.defaultExpandAll = false; | ||
} | ||
var index = expandedKeys.indexOf(tnProps.eventKey); | ||
@@ -257,5 +262,5 @@ if (expanded) { | ||
} | ||
this.setState({ | ||
expandedKeys: expandedKeys | ||
}); | ||
if (!('expandedKeys' in this.props)) { | ||
this.setState({ expandedKeys: expandedKeys }); | ||
} | ||
} | ||
@@ -380,2 +385,19 @@ }, { | ||
}, { | ||
key: 'getDefaultExpandedKeys', | ||
value: function getDefaultExpandedKeys(props, willReceiveProps) { | ||
var defaultExpandedKeys = props.defaultExpandedKeys; | ||
if (props.defaultExpandAll) { | ||
defaultExpandedKeys = []; | ||
this.loopAllChildren(props.children, function (item, index, pos) { | ||
var key = item.key || pos; | ||
defaultExpandedKeys.push(key); | ||
}); | ||
} | ||
var expandedKeys = willReceiveProps ? undefined : defaultExpandedKeys; | ||
if ('expandedKeys' in props) { | ||
expandedKeys = props.expandedKeys || []; | ||
} | ||
return expandedKeys; | ||
} | ||
}, { | ||
key: 'getDefaultCheckedKeys', | ||
@@ -421,2 +443,9 @@ value: function getDefaultCheckedKeys(props, willReceiveProps) { | ||
}, { | ||
key: 'getOriginExpandedKeys', | ||
value: function getOriginExpandedKeys() { | ||
if (!this._originExpandedKeys && 'expandedKeys' in this.props) { | ||
this._originExpandedKeys = [].concat(_toConsumableArray(this.state.expandedKeys)); | ||
} | ||
} | ||
}, { | ||
key: 'getOpenTransitionName', | ||
@@ -462,2 +491,11 @@ value: function getOpenTransitionName() { | ||
}, { | ||
key: 'filterTreeNode', | ||
value: function filterTreeNode(treeNode) { | ||
var filterTreeNode = this.props.filterTreeNode; | ||
if (typeof filterTreeNode !== 'function' || treeNode.props.disabled) { | ||
return false; | ||
} | ||
return filterTreeNode.call(this, treeNode); | ||
} | ||
}, { | ||
key: 'handleCheckState', | ||
@@ -535,8 +573,4 @@ value: function handleCheckState(obj, checkedArr, unCheckEvent) { | ||
var pos = level + '-' + index; | ||
var newChildren = item.props.children; | ||
if (newChildren) { | ||
if (!Array.isArray(newChildren)) { | ||
newChildren = [newChildren]; | ||
} | ||
loop(newChildren, pos); | ||
if (item.props.children && item.type === _TreeNode2['default']) { | ||
loop(item.props.children, pos); | ||
} | ||
@@ -553,3 +587,4 @@ callback(item, index, pos); | ||
var key = child.key || level + '-' + index; | ||
var pos = level + '-' + index; | ||
var key = child.key || pos; | ||
var state = this.state; | ||
@@ -561,3 +596,3 @@ var props = this.props; | ||
eventKey: key, | ||
pos: level + '-' + index, | ||
pos: pos, | ||
onDataLoaded: props.onDataLoaded, | ||
@@ -575,3 +610,3 @@ onMouseEnter: props.onMouseEnter, | ||
dragOverGapBottom: state.dragOverNodeKey === key && this.dropPos === 1, | ||
expanded: this.defaultExpandAll || state.expandedKeys.indexOf(key) !== -1, | ||
expanded: state.expandedKeys.indexOf(key) !== -1, | ||
selected: state.selectedKeys.indexOf(key) !== -1, | ||
@@ -581,3 +616,4 @@ checked: this.checkedKeys.indexOf(key) !== -1, | ||
openTransitionName: this.getOpenTransitionName(), | ||
openAnimation: props.openAnimation | ||
openAnimation: props.openAnimation, | ||
filterTreeNode: this.filterTreeNode.bind(this) | ||
}; | ||
@@ -600,2 +636,3 @@ return _react2['default'].cloneElement(child, cloneProps); | ||
} | ||
// console.log(this.state.expandedKeys, this._originExpandedKeys, props.children); | ||
var checkedKeys = this.state.checkedKeys; | ||
@@ -622,7 +659,7 @@ var checkedPos = []; | ||
this.checkedKeys = checkKeys.checkedKeys; | ||
this.newChildren = _react2['default'].Children.map(props.children, this.renderTreeNode, this); | ||
return _react2['default'].createElement( | ||
'ul', | ||
_extends({}, domProps, { unselectable: true, ref: 'tree' }), | ||
this.newChildren | ||
_react2['default'].Children.map(props.children, this.renderTreeNode, this) | ||
); | ||
@@ -658,2 +695,3 @@ } | ||
onTreeDrop: _react.PropTypes.func, | ||
filterTreeNode: _react.PropTypes.func, | ||
openTransitionName: _react.PropTypes.string, | ||
@@ -660,0 +698,0 @@ openAnimation: _react.PropTypes.oneOfType([_react.PropTypes.string, _react.PropTypes.object]) |
@@ -268,3 +268,3 @@ 'use strict'; | ||
} | ||
newChildren = this.newChildren = _react2['default'].createElement( | ||
newChildren = _react2['default'].createElement( | ||
_rcAnimate2['default'], | ||
@@ -375,5 +375,7 @@ _extends({}, animProps, { | ||
var filterCls = props.filterTreeNode(this) ? 'filter-node' : ''; | ||
return _react2['default'].createElement( | ||
'li', | ||
_extends({}, liProps, { ref: 'li', className: (0, _classnames2['default'])(props.className, disabledCls, dragOverCls) }), | ||
_extends({}, liProps, { ref: 'li', className: (0, _classnames2['default'])(props.className, disabledCls, dragOverCls, filterCls) }), | ||
canRenderSwitcher ? this.renderSwitcher(props, expandedState) : _react2['default'].createElement('span', { className: prefixCls + '-switcher-noop' }), | ||
@@ -380,0 +382,0 @@ props.checkable ? this.renderCheckbox(props) : null, |
{ | ||
"name": "rc-tree", | ||
"version": "0.21.3", | ||
"version": "0.22.0", | ||
"description": "tree ui component for react", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -67,3 +67,4 @@ # rc-tree | ||
|defaultExpandAll | expand all treeNodes | bool | false | | ||
|defaultExpandedKeys | expand specific treeNodes | String[] | false | | ||
|defaultExpandedKeys | expand specific treeNodes | String[] | - | | ||
|expandedKeys | Controlled expand specific treeNodes | String[] | - | | ||
|checkedKeys | Controlled checked treeNodes(After setting, defaultCheckedKeys will not work) | String[] | [] | | ||
@@ -75,2 +76,3 @@ |defaultCheckedKeys | default checked treeNodes | String[] | [] | | ||
|onSelect | click the treeNode to fire | function(e:{selected:bool,node,selectedKeys,event}) | - | | ||
|filterTreeNode | filter some treeNodes as you need. it should return true | function(treeNode) | - | | ||
|onDataLoaded | load data asynchronously and the return value should be a promise | function(node) | - | | ||
@@ -77,0 +79,0 @@ |onRightClick | select current treeNode and show customized contextmenu | function({event,node}) | - | |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
58631
1483
121