Socket
Socket
Sign inDemoInstall

rc-tree-select

Package Overview
Dependencies
Maintainers
2
Versions
259
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rc-tree-select - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

55

lib/Select.js

@@ -119,3 +119,3 @@ 'use strict';

if (this.props.treeCheckable) {
value = (0, _util.getTreeNodesStates)(this.props.children, value).checkedKeys;
value = (0, _util.getTreeNodesStates)(this.props.children, value).checkedValues;
}

@@ -135,3 +135,3 @@ var label = this.getLabelFromProps(props, value, 1);

if (nextProps.treeCheckable) {
value = (0, _util.getTreeNodesStates)(nextProps.children, value).checkedKeys;
value = (0, _util.getTreeNodesStates)(nextProps.children, value).checkedValues;
}

@@ -249,4 +249,5 @@ var label = this.getLabelFromProps(nextProps, value);

var check = info.event === 'check';
if (!check && typeof info.selected === 'boolean' && !info.selected) {
if (info.selected === false) {
this.onDeselect(info);
return;
}

@@ -258,13 +259,28 @@ var item = info.node;

var selectedValue = (0, _util.getValuePropValue)(item);
var selectedLabel = this.getLabelFromOption(item);
var selectedLabel = this.getLabelFromNode(item);
props.onSelect(selectedValue, item);
var selectedNodes = info.checkedNodes || info.selectedNodes;
if ((0, _util.isMultipleOrTags)(props)) {
if (check) {
// TODO treeCheckable does not support tags/dynamic
var checkedNodes = info.checkedNodes;
checkedNodes = checkedNodes.filter(function (n) {
return !n.props.children;
});
value = checkedNodes.map(function (n) {
return (0, _util.getValuePropValue)(n);
});
label = checkedNodes.map(function (n) {
return _this.getLabelFromNode(n);
});
} else {
if (value.indexOf(selectedValue) !== -1) {
return;
}
value = value.concat([selectedValue]);
label = label.concat([selectedLabel]);
}
if (!check && value.indexOf(selectedValue) !== -1) {
return;
}
value = !check ? value.concat([selectedValue]) : [].concat(_toConsumableArray(selectedKeys));
label = !check ? label.concat([selectedLabel]) : selectedNodes.map(function (node) {
return _this.getLabelFromOption(node);
});
} else {

@@ -275,6 +291,4 @@ if (value[0] === selectedValue) {

}
value = !check ? [selectedValue] : [].concat(_toConsumableArray(selectedKeys));
label = !check ? [selectedLabel] : selectedNodes.map(function (node) {
return _this.getLabelFromOption(node);
});
value = [selectedValue];
label = [selectedLabel];
this.setOpenState(false);

@@ -331,8 +345,2 @@ }

var label = null;
// menu option 只有一层,treeNode 是多层嵌套
// React.Children.forEach(children, (child) => {
// if (getValuePropValue(child) === value) {
// label = this.getLabelFromOption(child);
// }
// });
var loop = function loop(childs) {

@@ -344,3 +352,3 @@ _react2['default'].Children.forEach(childs, function (item) {

if ((0, _util.getValuePropValue)(item) === value) {
label = _this2.getLabelFromOption(item);
label = _this2.getLabelFromNode(item);
}

@@ -353,3 +361,3 @@ });

getLabelFromOption: function getLabelFromOption(child) {
getLabelFromNode: function getLabelFromNode(child) {
return (0, _util.getPropValue)(child, this.props.treeNodeLabelProp);

@@ -457,3 +465,3 @@ },

removeSelected: function removeSelected(selectedValue) {
removeSelected: function removeSelected(selectedValue, e) {
var props = this.props;

@@ -463,2 +471,5 @@ if (props.disabled) {

}
if (e) {
e.stopPropagation();
}
var label = this.state.label.concat();

@@ -465,0 +476,0 @@ var index = this.state.value.indexOf(selectedValue);

2

lib/SelectTrigger.js

@@ -233,3 +233,3 @@ 'use strict';

(0, _util.loopAllChildren)(props.treeNodes, function (child) {
if (vals.indexOf(child.props.value) > -1) {
if (vals.indexOf((0, _util.getValuePropValue)(child)) > -1) {
keys.push(child.key);

@@ -236,0 +236,0 @@ }

@@ -49,3 +49,3 @@ 'use strict';

function isMultipleOrTags(props) {
return props.multiple || props.tags;
return props.multiple || props.tags || props.treeCheckable;
}

@@ -115,3 +115,3 @@

}
callback(item, index, pos, item.key || pos);
callback(item, index, pos, getValuePropValue(item));
});

@@ -197,28 +197,21 @@ };

function getCheckKeys(treeNodesStates) {
var checkPartKeys = [];
var checkedKeys = [];
var checkedNodes = [];
var checkedNodesKeys = [];
function getCheckValues(treeNodesStates) {
var checkedValues = [];
Object.keys(treeNodesStates).forEach(function (item) {
var itemObj = treeNodesStates[item];
if (itemObj.checked) {
checkedKeys.push(itemObj.key);
checkedNodes.push(itemObj.node);
checkedNodesKeys.push({ key: itemObj.key, node: itemObj.node, pos: item });
} else if (itemObj.checkPart) {
checkPartKeys.push(itemObj.key);
if (itemObj.checked && !itemObj.node.props.children) {
checkedValues.push(getValuePropValue(itemObj.node));
}
});
return {
checkPartKeys: checkPartKeys, checkedKeys: checkedKeys, checkedNodes: checkedNodes, checkedNodesKeys: checkedNodesKeys, treeNodesStates: treeNodesStates
checkedValues: checkedValues
};
}
function getTreeNodesStates(children, checkedKeys) {
function getTreeNodesStates(children, values) {
var checkedPos = [];
var treeNodesStates = {};
loopAllChildren(children, function (item, index, pos, newKey) {
loopAllChildren(children, function (item, index, pos, value) {
var checked = false;
if (checkedKeys.indexOf(newKey) !== -1) {
if (values.indexOf(value) !== -1) {
checked = true;

@@ -229,3 +222,2 @@ checkedPos.push(pos);

node: item,
key: newKey,
checked: checked,

@@ -238,3 +230,3 @@ checkPart: false

return getCheckKeys(treeNodesStates);
return getCheckValues(treeNodesStates);
}
{
"name": "rc-tree-select",
"version": "1.0.0",
"version": "1.0.1",
"description": "tree-select ui component for react",

@@ -5,0 +5,0 @@ "keywords": [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc