rc-tree-select
Advanced tools
Comparing version 1.5.4 to 1.5.5
@@ -67,2 +67,3 @@ 'use strict'; | ||
treeNodes: _react.PropTypes.any, | ||
inputValue: _react.PropTypes.string, | ||
prefixCls: _react.PropTypes.string, | ||
@@ -103,5 +104,9 @@ popupClassName: _react.PropTypes.string, | ||
filterTree: function filterTree(treeNode) { | ||
highlightTreeNode: function highlightTreeNode(treeNode) { | ||
var props = this.props; | ||
return props.inputValue && treeNode.props[(0, _util.labelCompatible)(props.treeNodeFilterProp)].indexOf(props.inputValue) > -1; | ||
var filterVal = treeNode.props[(0, _util.labelCompatible)(props.treeNodeFilterProp)]; | ||
if (typeof filterVal === 'string') { | ||
return props.inputValue && filterVal.indexOf(props.inputValue) > -1; | ||
} | ||
return false; | ||
}, | ||
@@ -127,2 +132,43 @@ | ||
processTreeNode: function processTreeNode(treeNodes) { | ||
var _this = this; | ||
var filterPoss = []; | ||
(0, _util.loopAllChildren)(treeNodes, function (child, index, pos) { | ||
if (_this.filterTreeNode(_this.props.inputValue, child)) { | ||
filterPoss.push(pos); | ||
} | ||
}); | ||
// 把筛选节点的父节点(如果未筛选到)包含进来 | ||
var processedPoss = []; | ||
filterPoss.forEach(function (pos) { | ||
var arr = pos.split('-'); | ||
arr.reduce(function (pre, cur) { | ||
var res = pre + '-' + cur; | ||
if (processedPoss.indexOf(res) < 0) { | ||
processedPoss.push(res); | ||
} | ||
return res; | ||
}); | ||
}); | ||
var filterNodesPositions = []; | ||
(0, _util.loopAllChildren)(treeNodes, function (child, index, pos) { | ||
if (processedPoss.indexOf(pos) > -1) { | ||
filterNodesPositions.push({ node: child, pos: pos }); | ||
} | ||
}); | ||
var hierarchyNodes = (0, _util.flatToHierarchy)(filterNodesPositions); | ||
var recursive = function recursive(children) { | ||
return children.map(function (child) { | ||
if (child.children) { | ||
return _react2['default'].cloneElement(child.node, {}, recursive(child.children)); | ||
} | ||
return child.node; | ||
}); | ||
}; | ||
return recursive(hierarchyNodes); | ||
}, | ||
renderTree: function renderTree(keys, halfCheckedKeys, newTreeNodes, multiple) { | ||
@@ -137,3 +183,3 @@ var props = this.props; | ||
defaultExpandAll: props.treeDefaultExpandAll, | ||
filterTreeNode: this.filterTree, | ||
filterTreeNode: this.highlightTreeNode, | ||
_treeNodesStates: props._treeNodesStates | ||
@@ -172,4 +218,3 @@ }; | ||
render: function render() { | ||
var _popupClassName, | ||
_this = this; | ||
var _popupClassName; | ||
@@ -202,3 +247,2 @@ var props = this.props; | ||
// const s = Date.now(); | ||
// let treeNodes = recursive(props.treeData || props.treeNodes); | ||
var treeNodes = undefined; | ||
@@ -212,35 +256,5 @@ if (props._cachetreeData && this.treeNodes) { | ||
// console.log(Date.now()-s); | ||
var recursive1 = function recursive1(children) { | ||
var cb = arguments.length <= 1 || arguments[1] === undefined ? function (ch) { | ||
return ch; | ||
} : arguments[1]; | ||
var cb1 = arguments.length <= 2 || arguments[2] === undefined ? function (childs) { | ||
return childs; | ||
} : arguments[2]; | ||
return children.map(function (child) { | ||
if (child && child.props.children) { | ||
return _react2['default'].cloneElement(child, {}, recursive1(cb1(child.props.children), cb, cb1)); | ||
} | ||
return cb(child); | ||
}); | ||
}; | ||
if (props.inputValue) { | ||
treeNodes = recursive1(treeNodes, function (child) { | ||
if (_this.filterTreeNode(props.inputValue, child)) { | ||
return child; | ||
} | ||
return null; | ||
}); | ||
treeNodes = recursive1(treeNodes, undefined, function (childs) { | ||
// 过滤掉 children array 里的 null | ||
// ref: https://github.com/facebook/react/issues/4867 | ||
// 可以用 React.Children.toArray(childs),但会把 key 修改掉 | ||
return Array.from(childs).filter(function (i) { | ||
return i; | ||
}); | ||
}).filter(function (i) { | ||
return i; | ||
}); | ||
treeNodes = this.processTreeNode(treeNodes); | ||
} | ||
@@ -247,0 +261,0 @@ |
@@ -22,2 +22,3 @@ /* eslint no-loop-func: 0*/ | ||
exports.loopAllChildren = loopAllChildren; | ||
exports.recursiveCloneChildren = recursiveCloneChildren; | ||
exports.flatToHierarchy = flatToHierarchy; | ||
@@ -176,6 +177,8 @@ exports.filterParentPosition = filterParentPosition; | ||
var pos = level + '-' + index; | ||
if (item.props.children && item.type) { | ||
if (item && item.props.children && item.type) { | ||
loop(item.props.children, pos, { node: item, pos: pos }); | ||
} | ||
callback(item, index, pos, item.key || pos, getSiblingPosition(index, len, {}), _parent); | ||
if (item) { | ||
callback(item, index, pos, item.key || pos, getSiblingPosition(index, len, {}), _parent); | ||
} | ||
}); | ||
@@ -201,2 +204,25 @@ }; | ||
// 给每一个 children 节点,增加 prop | ||
function recursiveCloneChildren(children) { | ||
var cb = arguments.length <= 1 || arguments[1] === undefined ? function (ch) { | ||
return ch; | ||
} : arguments[1]; | ||
return Array.from(children).map(function (child) { | ||
var newChild = cb(child); | ||
if (newChild && newChild.props.children) { | ||
return _react2['default'].cloneElement(newChild, {}, recursiveCloneChildren(newChild.props.children, cb)); | ||
} | ||
return newChild; | ||
}); | ||
} | ||
// const newChildren = recursiveCloneChildren(children, child => { | ||
// const extraProps = { | ||
// _prop: true, | ||
// }; | ||
// return React.cloneElement(child, extraProps); | ||
// }); | ||
function flatToHierarchy(arr) { | ||
@@ -203,0 +229,0 @@ if (!arr.length) { |
{ | ||
"name": "rc-tree-select", | ||
"version": "1.5.4", | ||
"version": "1.5.5", | ||
"description": "tree-select ui component for react", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -84,3 +84,3 @@ # rc-tree-select | ||
|treeCheckStrictly | check node precisely, parent and children nodes are not associated| bool | false | | ||
|filterTreeNode | filter some treeNodes as you need. it should return true | function(treeNode) | - | | ||
|filterTreeNode | whether filter treeNodes by input value. default filter by treeNode's treeNodeFilterProp prop's value | bool | true/Function(inputValue:string, treeNode:TreeNode) | | ||
|treeNodeFilterProp | which prop value of treeNode will be used for filter if filterTreeNode return true | String | 'value' | | ||
@@ -87,0 +87,0 @@ |treeNodeLabelProp | which prop value of treeNode will render as content of select | String | 'title' | |
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
103188
3004