rc-tree-select
Advanced tools
Comparing version 1.2.5 to 1.3.0
# History | ||
--- | ||
## 1.3.0 / 2016-03-14 | ||
- add `showAllChecked`/`showParentChecked` API. | ||
## 1.2.0 / 2016-02-29 | ||
@@ -5,0 +8,0 @@ - change onChange's third parameter, from flat array to tree's hierarchical structure. |
@@ -106,3 +106,6 @@ 'use strict'; | ||
dropdownStyle: _react.PropTypes.object, | ||
drodownPopupAlign: _react.PropTypes.object, | ||
maxTagTextLength: _react.PropTypes.number, | ||
showAllChecked: _react.PropTypes.bool, | ||
showParentChecked: _react.PropTypes.bool, | ||
treeIcon: _react.PropTypes.bool, | ||
@@ -135,2 +138,4 @@ treeLine: _react.PropTypes.bool, | ||
notFoundContent: 'Not Found', | ||
showAllChecked: false, | ||
showParentChecked: false, | ||
treeIcon: false, | ||
@@ -154,3 +159,3 @@ treeLine: false, | ||
if (this.props.treeCheckable) { | ||
value = (0, _util.getTreeNodesStates)(this.renderTreeData() || this.props.children, value).checkedValues; | ||
value = this.getValue((0, _util.getTreeNodesStates)(this.renderTreeData() || this.props.children, value).checkedTreeNodes); | ||
} | ||
@@ -170,3 +175,3 @@ var label = this.getLabelFromProps(props, value, 1); | ||
if (nextProps.treeCheckable) { | ||
value = (0, _util.getTreeNodesStates)(this.renderTreeData(nextProps) || nextProps.children, value).checkedValues; | ||
value = this.getValue((0, _util.getTreeNodesStates)(this.renderTreeData(nextProps) || nextProps.children, value).checkedTreeNodes); | ||
} | ||
@@ -300,5 +305,21 @@ var label = this.getLabelFromProps(nextProps, value); | ||
checkedNodes = checkedNodes.filter(function (n) { | ||
return !n.props.children; | ||
}); | ||
var checkedNodesPositions = info.checkedNodesPositions; | ||
if (props.showAllChecked) { | ||
checkedNodes = checkedNodes; | ||
} else if (props.showParentChecked) { | ||
(function () { | ||
var posArr = (0, _util.filterParentPosition)(checkedNodesPositions.map(function (itemObj) { | ||
return itemObj.pos; | ||
})); | ||
checkedNodes = checkedNodesPositions.filter(function (itemObj) { | ||
return posArr.indexOf(itemObj.pos) !== -1; | ||
}).map(function (itemObj) { | ||
return itemObj.node; | ||
}); | ||
})(); | ||
} else { | ||
checkedNodes = checkedNodes.filter(function (n) { | ||
return !n.props.children; | ||
}); | ||
} | ||
value = checkedNodes.map(function (n) { | ||
@@ -491,2 +512,58 @@ return (0, _util.getValuePropValue)(n); | ||
getValue: function getValue(checkedTreeNodes) { | ||
this.checkedTreeNodes = checkedTreeNodes; | ||
var mapVal = function mapVal(arr) { | ||
return arr.map(function (itemObj) { | ||
return (0, _util.getValuePropValue)(itemObj.node); | ||
}); | ||
}; | ||
var props = this.props; | ||
var checkedValues = []; | ||
if (props.showAllChecked) { | ||
checkedValues = mapVal(checkedTreeNodes); | ||
} else if (props.showParentChecked) { | ||
(function () { | ||
var posArr = (0, _util.filterParentPosition)(checkedTreeNodes.map(function (itemObj) { | ||
return itemObj.pos; | ||
})); | ||
checkedValues = mapVal(checkedTreeNodes.filter(function (itemObj) { | ||
return posArr.indexOf(itemObj.pos) !== -1; | ||
})); | ||
})(); | ||
} else { | ||
checkedValues = mapVal(checkedTreeNodes.filter(function (itemObj) { | ||
return !itemObj.node.props.children; | ||
})); | ||
} | ||
return checkedValues; | ||
}, | ||
getDeselectedValue: function getDeselectedValue(selectedValue) { | ||
var checkedTreeNodes = this.checkedTreeNodes; | ||
var unCheckPos = undefined; | ||
checkedTreeNodes.forEach(function (itemObj) { | ||
if (itemObj.node.props.value === selectedValue) { | ||
unCheckPos = itemObj.pos; | ||
} | ||
}); | ||
var nArr = unCheckPos.split('-'); | ||
var newVals = []; | ||
checkedTreeNodes.forEach(function (itemObj) { | ||
var iArr = itemObj.pos.split('-'); | ||
if (itemObj.pos === unCheckPos || nArr.length > iArr.length && (0, _util.isInclude)(iArr, nArr) || nArr.length < iArr.length && (0, _util.isInclude)(nArr, iArr)) { | ||
// 过滤掉 父级节点 和 所有子节点。 | ||
// 因为 node节点 不选时,其 父级节点 和 所有子节点 都不选。 | ||
return; | ||
} | ||
newVals.push(itemObj.node.props.value); | ||
}); | ||
var label = this.state.label.concat(); | ||
this.state.value.forEach(function (val, index) { | ||
if (newVals.indexOf(val) === -1) { | ||
label.splice(index, 1); | ||
} | ||
}); | ||
this.fireChange(newVals, label, { triggerValue: selectedValue, clear: true }); | ||
}, | ||
setOpenState: function setOpenState(open) { | ||
@@ -517,2 +594,6 @@ var _this4 = this; | ||
} | ||
if (props.showAllChecked || props.showParentChecked) { | ||
this.getDeselectedValue(selectedValue); | ||
return; | ||
} | ||
var label = this.state.label.concat(); | ||
@@ -519,0 +600,0 @@ var index = this.state.value.indexOf(selectedValue); |
@@ -63,2 +63,3 @@ 'use strict'; | ||
dropdownMatchSelectWidth: _react.PropTypes.bool, | ||
dropdownPopupAlign: _react.PropTypes.object, | ||
visible: _react.PropTypes.bool, | ||
@@ -242,2 +243,3 @@ filterTreeNode: _react.PropTypes.any, | ||
builtinPlacements: BUILT_IN_PLACEMENTS, | ||
popupAlign: this.props.dropdownPopupAlign, | ||
prefixCls: dropdownPrefixCls, | ||
@@ -244,0 +246,0 @@ popupTransitionName: this.getDropdownTransitionName(), |
@@ -6,2 +6,5 @@ 'use strict'; | ||
}); | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
exports.getValuePropValue = getValuePropValue; | ||
@@ -14,2 +17,3 @@ exports.getPropValue = getPropValue; | ||
exports.toArray = toArray; | ||
exports.isInclude = isInclude; | ||
exports.getCheckedKeys = getCheckedKeys; | ||
@@ -255,12 +259,13 @@ exports.loopAllChildren = loopAllChildren; | ||
function getCheckValues(treeNodesStates) { | ||
var checkedValues = []; | ||
function getCheck(treeNodesStates) { | ||
var checkedTreeNodes = []; | ||
Object.keys(treeNodesStates).forEach(function (item) { | ||
var itemObj = treeNodesStates[item]; | ||
if (itemObj.checked && !itemObj.node.props.children) { | ||
checkedValues.push(getValuePropValue(itemObj.node)); | ||
if (itemObj.checked) { | ||
// checkedTreeNodes.push(getValuePropValue(itemObj.node)); | ||
checkedTreeNodes.push(_extends({}, itemObj, { pos: item })); | ||
} | ||
}); | ||
return { | ||
checkedValues: checkedValues | ||
checkedTreeNodes: checkedTreeNodes | ||
}; | ||
@@ -287,3 +292,3 @@ } | ||
return getCheckValues(treeNodesStates); | ||
return getCheck(treeNodesStates); | ||
} |
{ | ||
"name": "rc-tree-select", | ||
"version": "1.2.5", | ||
"version": "1.3.0", | ||
"description": "tree-select ui component for react", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -63,2 +63,3 @@ # rc-tree-select | ||
|dropdownStyle | additional style applied to dropdown | Object | {} | | ||
|dropdownPopupAlign | specify alignment for dropdown | Object | - | | ||
|notFoundContent | specify content to show when no result matches. | String | 'Not Found' | | ||
@@ -77,2 +78,4 @@ |showSearch | whether show search input in single mode | bool | true | | ||
|onSearch | called when input changed | function | - | | ||
|showAllChecked | show all checked treeNodes (Include parent treeNode) when set treeCheckable | bool | false | | ||
|showParentChecked | show checked treeNodes (Just show parent treeNode) when set treeCheckable | bool | false | | ||
|treeIcon | show tree icon | bool | false | | ||
@@ -79,0 +82,0 @@ |treeLine | show tree line | bool | false | |
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
91263
2649
112