Socket
Socket
Sign inDemoInstall

@uiw/react-tree

Package Overview
Dependencies
Maintainers
2
Versions
172
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@uiw/react-tree - npm Package Compare versions

Comparing version 4.21.19 to 4.21.20

125

cjs/index.js
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];
Object.defineProperty(exports, "__esModule", {

@@ -12,21 +10,11 @@ value: true

exports.getChildKeys = void 0;
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _react = _interopRequireWildcard(require("react"));
var _utils = require("@uiw/utils");
var _TreeNode = _interopRequireDefault(require("./TreeNode"));
var _jsxRuntime = require("react/jsx-runtime");
var _excluded = ["prefixCls", "icon", "data", "openKeys", "selectedKeys", "defaultExpandAll", "showLine", "iconAnimation", "isSelected", "checkStrictly", "multiple", "onExpand", "onSelected", "className", "autoExpandParent", "renderTitle", "onChange", "value"];
/**

@@ -41,10 +29,7 @@ * a contains b

var aStr = a.toString();
for (var i = 0, len = b.length; i < len; i += 1) {
if (aStr.indexOf(b[i]) === -1) return false;
}
return true;
};
var getChildKeys = function getChildKeys() {

@@ -58,5 +43,3 @@ var childs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];

}
if (typeof depth === 'number' && !(depth - 1)) return;
if (item.children && item.children.length > 0) {

@@ -68,20 +51,14 @@ result = result.concat(getChildKeys(item.children, undefined, depth ? depth - 1 : undefined));

};
exports.getChildKeys = getChildKeys;
var getParentKeys = function getParentKeys() {
var childs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
if (childs.key) {
result.push(childs.key);
}
if (childs.parent) {
result = getParentKeys(childs.parent, result);
}
return result;
};
var getParentSelectKeys = function getParentSelectKeys() {

@@ -91,6 +68,4 @@ var childs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};

var result = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
if (childs.key && childs.children && isContained(selectedKeys, getChildKeys(childs.children, undefined, 1))) {
result.push(childs.key);
if (childs.parent && !childs.parent.parent) {

@@ -100,3 +75,2 @@ if (isContained(selectedKeys, getChildKeys(childs.children))) {

}
if (isContained(selectedKeys, getChildKeys(childs.parent.children))) {

@@ -107,55 +81,49 @@ result.push(childs.parent.key);

}
if (childs.parent) {
result = getParentSelectKeys(childs.parent, selectedKeys, result);
}
return result;
};
function Tree(props) {
var _props$prefixCls = props.prefixCls,
prefixCls = _props$prefixCls === void 0 ? 'w-tree' : _props$prefixCls,
_props$icon = props.icon,
icon = _props$icon === void 0 ? 'caret-right' : _props$icon,
_props$data = props.data,
data = _props$data === void 0 ? [] : _props$data,
_props$openKeys = props.openKeys,
openKeys = _props$openKeys === void 0 ? [] : _props$openKeys,
_props$selectedKeys = props.selectedKeys,
selectedKeys = _props$selectedKeys === void 0 ? [] : _props$selectedKeys,
_props$defaultExpandA = props.defaultExpandAll,
defaultExpandAll = _props$defaultExpandA === void 0 ? false : _props$defaultExpandA,
_props$showLine = props.showLine,
showLine = _props$showLine === void 0 ? false : _props$showLine,
_props$iconAnimation = props.iconAnimation,
iconAnimation = _props$iconAnimation === void 0 ? true : _props$iconAnimation,
_props$isSelected = props.isSelected,
isSelected = _props$isSelected === void 0 ? true : _props$isSelected,
_props$checkStrictly = props.checkStrictly,
checkStrictly = _props$checkStrictly === void 0 ? false : _props$checkStrictly,
_props$multiple = props.multiple,
multiple = _props$multiple === void 0 ? false : _props$multiple,
_props$onExpand = props.onExpand,
onExpand = _props$onExpand === void 0 ? _utils.noop : _props$onExpand,
_props$onSelected = props.onSelected,
onSelected = _props$onSelected === void 0 ? _utils.noop : _props$onSelected,
className = props.className,
_props$autoExpandPare = props.autoExpandParent,
autoExpandParent = _props$autoExpandPare === void 0 ? true : _props$autoExpandPare,
renderTitle = props.renderTitle,
onChange = props.onChange,
value = props.value,
elementProps = (0, _objectWithoutProperties2["default"])(props, _excluded);
prefixCls = _props$prefixCls === void 0 ? 'w-tree' : _props$prefixCls,
_props$icon = props.icon,
icon = _props$icon === void 0 ? 'caret-right' : _props$icon,
_props$data = props.data,
data = _props$data === void 0 ? [] : _props$data,
_props$openKeys = props.openKeys,
openKeys = _props$openKeys === void 0 ? [] : _props$openKeys,
_props$selectedKeys = props.selectedKeys,
selectedKeys = _props$selectedKeys === void 0 ? [] : _props$selectedKeys,
_props$defaultExpandA = props.defaultExpandAll,
defaultExpandAll = _props$defaultExpandA === void 0 ? false : _props$defaultExpandA,
_props$showLine = props.showLine,
showLine = _props$showLine === void 0 ? false : _props$showLine,
_props$iconAnimation = props.iconAnimation,
iconAnimation = _props$iconAnimation === void 0 ? true : _props$iconAnimation,
_props$isSelected = props.isSelected,
isSelected = _props$isSelected === void 0 ? true : _props$isSelected,
_props$checkStrictly = props.checkStrictly,
checkStrictly = _props$checkStrictly === void 0 ? false : _props$checkStrictly,
_props$multiple = props.multiple,
multiple = _props$multiple === void 0 ? false : _props$multiple,
_props$onExpand = props.onExpand,
onExpand = _props$onExpand === void 0 ? _utils.noop : _props$onExpand,
_props$onSelected = props.onSelected,
onSelected = _props$onSelected === void 0 ? _utils.noop : _props$onSelected,
className = props.className,
_props$autoExpandPare = props.autoExpandParent,
autoExpandParent = _props$autoExpandPare === void 0 ? true : _props$autoExpandPare,
renderTitle = props.renderTitle,
onChange = props.onChange,
value = props.value,
elementProps = (0, _objectWithoutProperties2["default"])(props, _excluded);
var _useState = (0, _react.useState)(openKeys),
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
curOpenKeys = _useState2[0],
setCurOpenKeys = _useState2[1];
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
curOpenKeys = _useState2[0],
setCurOpenKeys = _useState2[1];
var _useState3 = (0, _react.useState)(value || selectedKeys),
_useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
curSelectedKeys = _useState4[0],
setCurSelectedKeys = _useState4[1];
_useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
curSelectedKeys = _useState4[0],
setCurSelectedKeys = _useState4[1];
(0, _react.useEffect)(function () {

@@ -166,3 +134,2 @@ setCurSelectedKeys(props.value || props.selectedKeys || []);

var arrOpenKeys = (0, _toConsumableArray2["default"])(curOpenKeys);
if (defaultExpandAll) {

@@ -172,17 +139,13 @@ arrOpenKeys = getChildKeys(data);

var _arrOpenKeys;
(_arrOpenKeys = arrOpenKeys).push.apply(_arrOpenKeys, (0, _toConsumableArray2["default"])(getChildKeys(data || [], undefined, 1)));
}
setCurOpenKeys(arrOpenKeys);
}, []);
var cls = [className, prefixCls, showLine ? "".concat(prefixCls, "-line") : null].filter(Boolean).join(' ').trim();
function onItemClick(item, evn) {
if (!item.children) {
return;
} // const { onExpand } = this.props;
}
// const { onExpand } = this.props;
// const { openKeys } = this.state;
var currentKeys = (0, _toConsumableArray2["default"])(curOpenKeys);

@@ -194,3 +157,2 @@ var key = currentKeys.find(function (v) {

var expanded = false;
if (!key && item.key) {

@@ -206,7 +168,5 @@ currentKeys.push(item.key);

}
setCurOpenKeys(currentKeys);
onExpand && onExpand(item.key, expanded, item, evn);
}
function onItemSelected(item, evn) {

@@ -219,3 +179,2 @@ // const { onSelected, multiple, checkStrictly } = this.props;

var selected = false;
if (!findKey && findKey !== 0) {

@@ -229,3 +188,2 @@ selected = true;

}
if (checkStrictly) {

@@ -247,7 +205,5 @@ if (!findKey) {

}
if (!multiple) {
selKeys = !findKey ? [item.key] : [];
}
setCurSelectedKeys(selKeys);

@@ -257,3 +213,2 @@ onSelected && onSelected(selKeys, item.key, selected, item, evn);

}
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", (0, _objectSpread2["default"])((0, _objectSpread2["default"])({

@@ -260,0 +215,0 @@ className: cls

"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];
Object.defineProperty(exports, "__esModule", {

@@ -11,26 +9,15 @@ value: true

exports["default"] = TreeNode;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _objectSpread3 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _react = _interopRequireWildcard(require("react"));
var _reactTransitionGroup = require("react-transition-group");
var _reactIcon = _interopRequireDefault(require("@uiw/react-icon"));
var _utils = require("@uiw/utils");
var _ = require("./");
var _jsxRuntime = require("react/jsx-runtime");
var _excluded = ["prefixCls", "renderTitle", "icon", "iconAnimation", "isSelected", "openKeys", "selectedKeys", "data", "level", "parent", "onItemClick", "onItemSelected"];
var Label = function Label(_ref) {
var label = _ref.label,
className = _ref.className;
className = _ref.className;
return (0, _react.useMemo)(function () {

@@ -43,27 +30,23 @@ return /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {

};
function TreeNode(props) {
var prefixCls = props.prefixCls,
renderTitle = props.renderTitle,
icon = props.icon,
iconAnimation = props.iconAnimation,
isSelected = props.isSelected,
openKeys = props.openKeys,
selectedKeys = props.selectedKeys,
data = props.data,
level = props.level,
parent = props.parent,
_props$onItemClick = props.onItemClick,
onItemClick = _props$onItemClick === void 0 ? _utils.noop : _props$onItemClick,
_props$onItemSelected = props.onItemSelected,
onItemSelected = _props$onItemSelected === void 0 ? _utils.noop : _props$onItemSelected,
other = (0, _objectWithoutProperties2["default"])(props, _excluded);
renderTitle = props.renderTitle,
icon = props.icon,
iconAnimation = props.iconAnimation,
isSelected = props.isSelected,
openKeys = props.openKeys,
selectedKeys = props.selectedKeys,
data = props.data,
level = props.level,
parent = props.parent,
_props$onItemClick = props.onItemClick,
onItemClick = _props$onItemClick === void 0 ? _utils.noop : _props$onItemClick,
_props$onItemSelected = props.onItemSelected,
onItemSelected = _props$onItemSelected === void 0 ? _utils.noop : _props$onItemSelected,
other = (0, _objectWithoutProperties2["default"])(props, _excluded);
var isOpen = false;
var node = _react["default"].useRef(null);
if (parent && (parent.key || parent.key === 0)) {
isOpen = !!(openKeys && openKeys.indexOf(parent.key) > -1);
}
var onExit = (0, _react.useCallback)(function () {

@@ -99,3 +82,2 @@ node.current.style.height = "".concat(node.current.scrollHeight, "px");

var _objectSpread2;
item.parent = parent;

@@ -123,3 +105,2 @@ var selected = !!(selectedKeys && selectedKeys.indexOf(item.key) > -1);

};
if (item.disabled) {

@@ -134,3 +115,2 @@ disabledObj.onClick = undefined;

}
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("li", {

@@ -157,3 +137,2 @@ style: {

var _disabledObj$onClick;
return (_disabledObj$onClick = disabledObj.onClick) === null || _disabledObj$onClick === void 0 ? void 0 : _disabledObj$onClick.call(disabledObj, item, evn);

@@ -192,4 +171,3 @@ },

}
module.exports = exports.default;
//# sourceMappingURL=TreeNode.js.map

@@ -9,3 +9,2 @@ import _extends from "@babel/runtime/helpers/extends";

import { jsx as _jsx } from "react/jsx-runtime";
/**

@@ -20,10 +19,7 @@ * a contains b

var aStr = a.toString();
for (var i = 0, len = b.length; i < len; i += 1) {
if (aStr.indexOf(b[i]) === -1) return false;
}
return true;
};
export var getChildKeys = function getChildKeys(childs, result, depth) {

@@ -33,7 +29,5 @@ if (childs === void 0) {

}
if (result === void 0) {
result = [];
}
childs.forEach(item => {

@@ -43,5 +37,3 @@ if (!item.hideNode) {

}
if (typeof depth === 'number' && !(depth - 1)) return;
if (item.children && item.children.length > 0) {

@@ -53,3 +45,2 @@ result = result.concat(getChildKeys(item.children, undefined, depth ? depth - 1 : undefined));

};
var getParentKeys = function getParentKeys(childs, result) {

@@ -59,18 +50,13 @@ if (childs === void 0) {

}
if (result === void 0) {
result = [];
}
if (childs.key) {
result.push(childs.key);
}
if (childs.parent) {
result = getParentKeys(childs.parent, result);
}
return result;
};
var getParentSelectKeys = function getParentSelectKeys(childs, selectedKeys, result) {

@@ -80,14 +66,10 @@ if (childs === void 0) {

}
if (selectedKeys === void 0) {
selectedKeys = [];
}
if (result === void 0) {
result = [];
}
if (childs.key && childs.children && isContained(selectedKeys, getChildKeys(childs.children, undefined, 1))) {
result.push(childs.key);
if (childs.parent && !childs.parent.parent) {

@@ -97,3 +79,2 @@ if (isContained(selectedKeys, getChildKeys(childs.children))) {

}
if (isContained(selectedKeys, getChildKeys(childs.parent.children))) {

@@ -104,33 +85,29 @@ result.push(childs.parent.key);

}
if (childs.parent) {
result = getParentSelectKeys(childs.parent, selectedKeys, result);
}
return result;
};
export default function Tree(props) {
var {
prefixCls = 'w-tree',
icon = 'caret-right',
data = [],
openKeys = [],
selectedKeys = [],
defaultExpandAll = false,
showLine = false,
iconAnimation = true,
isSelected = true,
checkStrictly = false,
multiple = false,
onExpand = noop,
onSelected = noop,
className,
autoExpandParent = true,
renderTitle,
onChange,
value
} = props,
elementProps = _objectWithoutPropertiesLoose(props, _excluded);
prefixCls = 'w-tree',
icon = 'caret-right',
data = [],
openKeys = [],
selectedKeys = [],
defaultExpandAll = false,
showLine = false,
iconAnimation = true,
isSelected = true,
checkStrictly = false,
multiple = false,
onExpand = noop,
onSelected = noop,
className,
autoExpandParent = true,
renderTitle,
onChange,
value
} = props,
elementProps = _objectWithoutPropertiesLoose(props, _excluded);
var [curOpenKeys, setCurOpenKeys] = useState(openKeys);

@@ -143,3 +120,2 @@ var [curSelectedKeys, setCurSelectedKeys] = useState(value || selectedKeys);

var arrOpenKeys = [...curOpenKeys];
if (defaultExpandAll) {

@@ -150,14 +126,11 @@ arrOpenKeys = getChildKeys(data);

}
setCurOpenKeys(arrOpenKeys);
}, []);
var cls = [className, prefixCls, showLine ? prefixCls + "-line" : null].filter(Boolean).join(' ').trim();
function onItemClick(item, evn) {
if (!item.children) {
return;
} // const { onExpand } = this.props;
}
// const { onExpand } = this.props;
// const { openKeys } = this.state;
var currentKeys = [...curOpenKeys];

@@ -167,3 +140,2 @@ var key = currentKeys.find(v => v === item.key);

var expanded = false;
if (!key && item.key) {

@@ -177,7 +149,5 @@ currentKeys.push(item.key);

}
setCurOpenKeys(currentKeys);
onExpand && onExpand(item.key, expanded, item, evn);
}
function onItemSelected(item, evn) {

@@ -188,3 +158,2 @@ // const { onSelected, multiple, checkStrictly } = this.props;

var selected = false;
if (!findKey && findKey !== 0) {

@@ -196,3 +165,2 @@ selected = true;

}
if (checkStrictly) {

@@ -208,7 +176,5 @@ if (!findKey) {

}
if (!multiple) {
selKeys = !findKey ? [item.key] : [];
}
setCurSelectedKeys(selKeys);

@@ -218,3 +184,2 @@ onSelected && onSelected(selKeys, item.key, selected, item, evn);

}
return /*#__PURE__*/_jsx("div", _extends({

@@ -221,0 +186,0 @@ className: cls

@@ -11,3 +11,2 @@ import _extends from "@babel/runtime/helpers/extends";

import { jsxs as _jsxs } from "react/jsx-runtime";
var Label = _ref => {

@@ -23,27 +22,23 @@ var {

};
export default function TreeNode(props) {
var {
prefixCls,
renderTitle,
icon,
iconAnimation,
isSelected,
openKeys,
selectedKeys,
data,
level,
parent,
onItemClick = noop,
onItemSelected = noop
} = props,
other = _objectWithoutPropertiesLoose(props, _excluded);
prefixCls,
renderTitle,
icon,
iconAnimation,
isSelected,
openKeys,
selectedKeys,
data,
level,
parent,
onItemClick = noop,
onItemSelected = noop
} = props,
other = _objectWithoutPropertiesLoose(props, _excluded);
var isOpen = false;
var node = React.useRef(null);
if (parent && (parent.key || parent.key === 0)) {
isOpen = !!(openKeys && openKeys.indexOf(parent.key) > -1);
}
var onExit = useCallback(() => {

@@ -98,3 +93,2 @@ node.current.style.height = node.current.scrollHeight + "px";

};
if (item.disabled) {

@@ -109,3 +103,2 @@ disabledObj.onClick = undefined;

}
return /*#__PURE__*/_jsxs("li", {

@@ -112,0 +105,0 @@ style: {

{
"name": "@uiw/react-tree",
"version": "4.21.19",
"version": "4.21.20",
"description": "Tree component",

@@ -47,6 +47,6 @@ "author": "Kenny Wong <wowohoo@qq.com>",

"dependencies": {
"@uiw/react-icon": "^4.21.19",
"@uiw/utils": "^4.21.19",
"@uiw/react-icon": "^4.21.20",
"@uiw/utils": "^4.21.20",
"react-transition-group": "~4.4.2"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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