rc-tree-select
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -124,76 +124,16 @@ 'use strict'; | ||
renderFilterOptionsFromChildren: function renderFilterOptionsFromChildren(children) { | ||
renderFilterTreeNodes: function renderFilterTreeNodes(children) { | ||
var _this = this; | ||
var posArr = []; | ||
var filterPos = []; | ||
var props = this.props; | ||
var inputValue = props.inputValue; | ||
var filterNodesPositions = []; | ||
(0, _util.loopAllChildren)(children, function (child, index, pos) { | ||
if (_this.filterTreeNode(inputValue, child)) { | ||
posArr.push(pos); | ||
filterNodesPositions.push({ node: child, pos: pos }); | ||
} | ||
}); | ||
posArr = (0, _util.filterMinPosition)(posArr); | ||
var filterChildren = {}; | ||
(0, _util.loopAllChildren)(children, function (child, index, pos) { | ||
posArr.forEach(function (item) { | ||
if (item.indexOf(pos) === 0 && filterPos.indexOf(pos) === -1) { | ||
filterPos.push(pos); | ||
filterChildren[pos] = child; | ||
} | ||
}); | ||
}); | ||
var level = {}; | ||
filterPos.forEach(function (pos) { | ||
var arr = pos.split('-'); | ||
var key = String(arr.length - 1); | ||
level[key] = level[key] || []; | ||
level[key].push(pos); | ||
}); | ||
var childrenArr = []; | ||
function loop(arr, cur, callback) { | ||
arr.forEach(function (c, index) { | ||
if (cur.indexOf(c.pos) === 0) { | ||
if (c.children) { | ||
if (cur.split('-').length === c.pos.split('-').length + 1) { | ||
callback(arr, index); | ||
} else { | ||
loop(c.children, cur, callback); | ||
} | ||
} else { | ||
callback(arr, index); | ||
} | ||
} | ||
}); | ||
} | ||
var levelArr = Object.keys(level).sort(function (a, b) { | ||
return a - b; | ||
}); | ||
if (levelArr.length > 0) { | ||
level[levelArr[0]].forEach(function (pos, index) { | ||
childrenArr[index] = { | ||
pos: pos, | ||
node: filterChildren[pos] | ||
}; | ||
}); | ||
var loopFn = function loopFn(cur) { | ||
loop(childrenArr, cur, function (arr, index) { | ||
arr[index].children = arr[index].children || []; | ||
arr[index].children.push({ | ||
pos: cur, | ||
node: filterChildren[cur] | ||
}); | ||
}); | ||
}; | ||
for (var i = 1; i < levelArr.length; i++) { | ||
level[levelArr[i]].forEach(loopFn); | ||
} | ||
} | ||
return childrenArr; | ||
return (0, _util.flatToHierarchy)(filterNodesPositions); | ||
}, | ||
@@ -272,3 +212,3 @@ | ||
); | ||
var treeNodes = this.renderFilterOptionsFromChildren(props.treeData || props.treeNodes); | ||
var treeNodes = this.renderFilterTreeNodes(props.treeData || props.treeNodes); | ||
var notFoundContent = undefined; | ||
@@ -275,0 +215,0 @@ if (!treeNodes.length) { |
@@ -16,3 +16,3 @@ 'use strict'; | ||
exports.flatToHierarchy = flatToHierarchy; | ||
exports.filterMinPosition = filterMinPosition; | ||
exports.filterParentPosition = filterParentPosition; | ||
exports.getTreeNodesStates = getTreeNodesStates; | ||
@@ -123,2 +123,5 @@ | ||
function flatToHierarchy(arr) { | ||
if (!arr.length) { | ||
return arr; | ||
} | ||
var hierarchyNodes = []; | ||
@@ -159,17 +162,32 @@ var levelObj = {}; | ||
function filterMinPosition(arr) { | ||
var a = []; | ||
function uniqueArray(arr) { | ||
var obj = {}; | ||
arr.forEach(function (item) { | ||
var b = a.filter(function (i) { | ||
return item.indexOf(i) === 0 && (item[i.length] === '-' || !item[i.length]); | ||
}); | ||
if (!b.length) { | ||
a.push(item); | ||
if (!obj[item]) { | ||
obj[item] = true; | ||
} | ||
}); | ||
return a; | ||
return Object.keys(obj); | ||
} | ||
// console.log(uniqueArray(['11', '2', '2'])); | ||
// console.log(filterMinPosition(['0-1', '0-10', '0-0-1', '0-1-1', '0-10-0'])); | ||
function filterParentPosition(arr) { | ||
var a = [].concat(arr); | ||
arr.forEach(function (item) { | ||
var itemArr = item.split('-'); | ||
a.forEach(function (ii, index) { | ||
var iiArr = ii.split('-'); | ||
if (itemArr.length <= iiArr.length && isInclude(itemArr, iiArr)) { | ||
a[index] = item; | ||
} | ||
if (itemArr.length > iiArr.length && isInclude(iiArr, itemArr)) { | ||
a[index] = ii; | ||
} | ||
}); | ||
}); | ||
return uniqueArray(a); | ||
} | ||
// console.log(filterParentPosition(['0-2', '0-10', '0-0-1', '0-1-1', '0-0','0-1', '0-10-0'])); | ||
function handleCheckState(obj, checkedPosArr, checkIt) { | ||
@@ -264,5 +282,5 @@ var stripTail = function stripTail(str) { | ||
handleCheckState(treeNodesStates, filterMinPosition(checkedPos.sort()), true); | ||
handleCheckState(treeNodesStates, filterParentPosition(checkedPos.sort()), true); | ||
return getCheckValues(treeNodesStates); | ||
} |
{ | ||
"name": "rc-tree-select", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "tree-select ui component for react", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
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
86926
2526