rsuite 5.68.0 → 5.68.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## [5.68.1](https://github.com/rsuite/rsuite/compare/v5.68.0...v5.68.1) (2024-08-02)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **CheckTree:** fix uncontrolled component default value ([#3906](https://github.com/rsuite/rsuite/issues/3906)) ([01aab7d](https://github.com/rsuite/rsuite/commit/01aab7df14661743e5dfae7fd3f612fc227816c7))
7
+
8
+
9
+
1
10
  # [5.68.0](https://github.com/rsuite/rsuite/compare/v5.67.0...v5.68.0) (2024-07-26)
2
11
 
3
12
 
@@ -36,7 +36,7 @@ export declare function getDisabledState(nodes: TreeNodeMap, node: TreeNode, pro
36
36
  /**
37
37
  * Returns the default value for the check tree.
38
38
  */
39
- export declare function getCheckTreeDefaultValue<T = any>(value: T, uncheckableItemValues: T): any[];
39
+ export declare function getCheckTreeDefaultValue<T = any>(value: T, uncheckableItemValues: T): any[] | T;
40
40
  /**
41
41
  * Retrieves the selected items from the given nodes.
42
42
  */
@@ -188,7 +188,7 @@ function getCheckTreeDefaultValue(value, uncheckableItemValues) {
188
188
  return !uncheckableItemValues.includes(v);
189
189
  });
190
190
  }
191
- return [];
191
+ return value;
192
192
  }
193
193
 
194
194
  /**
package/dist/rsuite.js CHANGED
@@ -6681,7 +6681,7 @@ eval("\n\nvar _interopRequireDefault = __webpack_require__(/*! @babel/runtime/he
6681
6681
  /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
6682
6682
 
6683
6683
  "use strict";
6684
- eval("\n\nvar _interopRequireDefault = __webpack_require__(/*! @babel/runtime/helpers/interopRequireDefault */ \"./node_modules/@babel/runtime/helpers/interopRequireDefault.js\");\nexports.__esModule = true;\nexports.getCheckTreeDefaultValue = getCheckTreeDefaultValue;\nexports.getDisabledState = getDisabledState;\nexports.getFormattedTree = getFormattedTree;\nexports.getNodeCheckState = getNodeCheckState;\nexports.getSelectedItems = getSelectedItems;\nexports.hasGrandchild = hasGrandchild;\nexports.isAllSiblingNodeUncheckable = isAllSiblingNodeUncheckable;\nexports.isEveryChildChecked = isEveryChildChecked;\nexports.isEveryFirstLevelNodeUncheckable = isEveryFirstLevelNodeUncheckable;\nexports.isNodeUncheckable = isNodeUncheckable;\nexports.isSomeChildChecked = isSomeChildChecked;\nvar _extends2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/extends */ \"./node_modules/@babel/runtime/helpers/extends.js\"));\nvar _isUndefined2 = _interopRequireDefault(__webpack_require__(/*! lodash/isUndefined */ \"./node_modules/lodash/isUndefined.js\"));\nvar _isNil2 = _interopRequireDefault(__webpack_require__(/*! lodash/isNil */ \"./node_modules/lodash/isNil.js\"));\nvar _constants = __webpack_require__(/*! ../internals/constants */ \"./src/internals/constants/index.ts\");\nvar _utils = __webpack_require__(/*! ../internals/utils */ \"./src/internals/utils/index.ts\");\nvar _utils2 = __webpack_require__(/*! ../Tree/utils */ \"./src/Tree/utils/index.ts\");\n/**\n * Retrieves the children of a given parent node from a flattened node map.\n */\nfunction getChildrenByFlattenNodes(nodes, parent) {\n if (!(0, _isNil2.default)(parent.refKey) && (0, _isNil2.default)(nodes[parent.refKey])) {\n return [];\n }\n return Object.values(nodes).filter(function (item) {\n var _item$parent;\n return (item === null || item === void 0 ? void 0 : (_item$parent = item.parent) === null || _item$parent === void 0 ? void 0 : _item$parent.refKey) === parent.refKey && item.refKey && !nodes[item.refKey].uncheckable;\n });\n}\n\n/**\n * Checks if every child of a given parent node is checked.\n */\nfunction isEveryChildChecked(parent, options) {\n var nodes = options.nodes,\n childrenKey = options.childrenKey;\n if ((0, _isNil2.default)(parent.refKey) || (0, _isNil2.default)(nodes[parent.refKey])) {\n return false;\n }\n var children = getChildrenByFlattenNodes(nodes, parent);\n if (!children.length) {\n var _nodes$parent$refKey$;\n return (_nodes$parent$refKey$ = nodes[parent.refKey].check) !== null && _nodes$parent$refKey$ !== void 0 ? _nodes$parent$refKey$ : false;\n }\n return children.every(function (child) {\n var _child$childrenKey;\n if ((child === null || child === void 0 ? void 0 : (_child$childrenKey = child[childrenKey]) === null || _child$childrenKey === void 0 ? void 0 : _child$childrenKey.length) > 0) {\n // fix: #3559\n return isEveryChildChecked(child, {\n nodes: nodes,\n childrenKey: childrenKey\n });\n }\n return !(0, _isNil2.default)(child.refKey) && nodes[child.refKey].check;\n });\n}\n\n/**\n * Checks if any child node is checked.\n */\nfunction isSomeChildChecked(nodes, parent, childrenKey) {\n if (!(0, _isNil2.default)(parent.refKey) && (0, _isNil2.default)(nodes[parent.refKey])) {\n return false;\n }\n var children = getChildrenByFlattenNodes(nodes, parent);\n return children.some(function (child) {\n var _child$childrenKey2;\n if ((child === null || child === void 0 ? void 0 : (_child$childrenKey2 = child[childrenKey]) === null || _child$childrenKey2 === void 0 ? void 0 : _child$childrenKey2.length) > 0) {\n return isSomeChildChecked(nodes, child, childrenKey);\n }\n return !(0, _isNil2.default)(child.refKey) && nodes[child.refKey].check;\n });\n}\n\n/**\n * Checks if any node in the data has a grandchild.\n */\nfunction hasGrandchild(data, childrenKey) {\n return data.some(function (node) {\n return Array.isArray(node[childrenKey]);\n });\n}\n\n/**\n * Checks if all sibling nodes of a given node are uncheckable.\n */\nfunction isAllSiblingNodeUncheckable(node, nodes, uncheckableItemValues, valueKey) {\n var list = [];\n var parentNodeRefKey = node.parent ? node.parent.refKey : '';\n Object.keys(nodes).forEach(function (refKey) {\n var _curNode$parent;\n var curNode = nodes[refKey];\n if ((0, _isNil2.default)(node.parent) && (0, _isNil2.default)(curNode.parent)) {\n list.push(curNode);\n } else if (((_curNode$parent = curNode.parent) === null || _curNode$parent === void 0 ? void 0 : _curNode$parent.refKey) === parentNodeRefKey) {\n list.push(curNode);\n }\n });\n return list.every(function (node) {\n return isNodeUncheckable(node, {\n uncheckableItemValues: uncheckableItemValues,\n valueKey: valueKey\n });\n });\n}\n\n/**\n * Checks if every first-level node is uncheckable based on the provided criteria.\n */\nfunction isEveryFirstLevelNodeUncheckable(nodes, uncheckableItemValues, valueKey) {\n var list = [];\n Object.keys(nodes).forEach(function (refKey) {\n var curNode = nodes[refKey];\n if (!curNode.parent) {\n list.push(curNode);\n }\n });\n return list.every(function (node) {\n return isNodeUncheckable(node, {\n uncheckableItemValues: uncheckableItemValues,\n valueKey: valueKey\n });\n });\n}\n\n/**\n * Checks if a node is uncheckable.\n */\nfunction isNodeUncheckable(node, props) {\n var _props$uncheckableIte = props.uncheckableItemValues,\n uncheckableItemValues = _props$uncheckableIte === void 0 ? [] : _props$uncheckableIte,\n valueKey = props.valueKey;\n return uncheckableItemValues.some(function (value) {\n return node[valueKey] === value;\n });\n}\nfunction getFormattedTree(nodes, data, props) {\n var childrenKey = props.childrenKey,\n cascade = props.cascade;\n return data.map(function (node) {\n var formatted = (0, _extends2.default)({}, node);\n var curNode = nodes[node.refKey];\n if (curNode) {\n var _node$childrenKey;\n var checkState = !(0, _isUndefined2.default)(cascade) ? getNodeCheckState(curNode, {\n cascade: cascade,\n nodes: nodes,\n childrenKey: childrenKey\n }) : undefined;\n formatted.check = curNode.check;\n formatted.uncheckable = curNode.uncheckable;\n (0, _utils.attachParent)(formatted, curNode.parent);\n formatted.checkState = checkState;\n if (((_node$childrenKey = node[childrenKey]) === null || _node$childrenKey === void 0 ? void 0 : _node$childrenKey.length) > 0) {\n formatted[childrenKey] = getFormattedTree(nodes, formatted[childrenKey], props);\n }\n }\n return formatted;\n });\n}\n\n/**\n * Determines the disabled state of a tree node.\n */\nfunction getDisabledState(nodes, node, props) {\n var _props$disabledItemVa = props.disabledItemValues,\n disabledItemValues = _props$disabledItemVa === void 0 ? [] : _props$disabledItemVa,\n valueKey = props.valueKey;\n if (!(0, _isNil2.default)(node.refKey) && (0, _isNil2.default)(nodes[node.refKey])) {\n return false;\n }\n return disabledItemValues.some(function (value) {\n return node.refKey && nodes[node.refKey][valueKey] === value;\n });\n}\n\n/**\n * Returns the default value for the check tree.\n */\nfunction getCheckTreeDefaultValue(value, uncheckableItemValues) {\n if (Array.isArray(value) && Array.isArray(uncheckableItemValues)) {\n return value.filter(function (v) {\n return !uncheckableItemValues.includes(v);\n });\n }\n return [];\n}\n\n/**\n * Retrieves the selected items from the given nodes.\n */\nfunction getSelectedItems(nodes, values) {\n var checkedItems = [];\n values.forEach(function (value) {\n var refKey = (0, _utils2.formatNodeRefKey)(value);\n var node = nodes[refKey];\n if (!(0, _isNil2.default)(node)) {\n checkedItems.push(node);\n }\n });\n return checkedItems;\n}\n/**\n * Calculates the check state of a node in a check tree.\n */\nfunction getNodeCheckState(node, options) {\n var nodes = options.nodes,\n cascade = options.cascade,\n childrenKey = options.childrenKey;\n if (node.refKey === undefined) {\n return _constants.CHECK_STATE.UNCHECK;\n }\n if ((0, _isNil2.default)(nodes[node.refKey])) {\n return _constants.CHECK_STATE.UNCHECK;\n }\n if (!node[childrenKey] || !node[childrenKey].length || !cascade) {\n nodes[node.refKey].checkAll = false;\n return node.check ? _constants.CHECK_STATE.CHECK : _constants.CHECK_STATE.UNCHECK;\n }\n if (isEveryChildChecked(node, {\n nodes: nodes,\n childrenKey: childrenKey\n })) {\n nodes[node.refKey].checkAll = true;\n nodes[node.refKey].check = true;\n return _constants.CHECK_STATE.CHECK;\n }\n if (isSomeChildChecked(nodes, node, childrenKey)) {\n nodes[node.refKey].checkAll = false;\n return _constants.CHECK_STATE.INDETERMINATE;\n }\n return _constants.CHECK_STATE.UNCHECK;\n}\n\n//# sourceURL=webpack://rsuite/./src/CheckTree/utils.ts?");
6684
+ eval("\n\nvar _interopRequireDefault = __webpack_require__(/*! @babel/runtime/helpers/interopRequireDefault */ \"./node_modules/@babel/runtime/helpers/interopRequireDefault.js\");\nexports.__esModule = true;\nexports.getCheckTreeDefaultValue = getCheckTreeDefaultValue;\nexports.getDisabledState = getDisabledState;\nexports.getFormattedTree = getFormattedTree;\nexports.getNodeCheckState = getNodeCheckState;\nexports.getSelectedItems = getSelectedItems;\nexports.hasGrandchild = hasGrandchild;\nexports.isAllSiblingNodeUncheckable = isAllSiblingNodeUncheckable;\nexports.isEveryChildChecked = isEveryChildChecked;\nexports.isEveryFirstLevelNodeUncheckable = isEveryFirstLevelNodeUncheckable;\nexports.isNodeUncheckable = isNodeUncheckable;\nexports.isSomeChildChecked = isSomeChildChecked;\nvar _extends2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/extends */ \"./node_modules/@babel/runtime/helpers/extends.js\"));\nvar _isUndefined2 = _interopRequireDefault(__webpack_require__(/*! lodash/isUndefined */ \"./node_modules/lodash/isUndefined.js\"));\nvar _isNil2 = _interopRequireDefault(__webpack_require__(/*! lodash/isNil */ \"./node_modules/lodash/isNil.js\"));\nvar _constants = __webpack_require__(/*! ../internals/constants */ \"./src/internals/constants/index.ts\");\nvar _utils = __webpack_require__(/*! ../internals/utils */ \"./src/internals/utils/index.ts\");\nvar _utils2 = __webpack_require__(/*! ../Tree/utils */ \"./src/Tree/utils/index.ts\");\n/**\n * Retrieves the children of a given parent node from a flattened node map.\n */\nfunction getChildrenByFlattenNodes(nodes, parent) {\n if (!(0, _isNil2.default)(parent.refKey) && (0, _isNil2.default)(nodes[parent.refKey])) {\n return [];\n }\n return Object.values(nodes).filter(function (item) {\n var _item$parent;\n return (item === null || item === void 0 ? void 0 : (_item$parent = item.parent) === null || _item$parent === void 0 ? void 0 : _item$parent.refKey) === parent.refKey && item.refKey && !nodes[item.refKey].uncheckable;\n });\n}\n\n/**\n * Checks if every child of a given parent node is checked.\n */\nfunction isEveryChildChecked(parent, options) {\n var nodes = options.nodes,\n childrenKey = options.childrenKey;\n if ((0, _isNil2.default)(parent.refKey) || (0, _isNil2.default)(nodes[parent.refKey])) {\n return false;\n }\n var children = getChildrenByFlattenNodes(nodes, parent);\n if (!children.length) {\n var _nodes$parent$refKey$;\n return (_nodes$parent$refKey$ = nodes[parent.refKey].check) !== null && _nodes$parent$refKey$ !== void 0 ? _nodes$parent$refKey$ : false;\n }\n return children.every(function (child) {\n var _child$childrenKey;\n if ((child === null || child === void 0 ? void 0 : (_child$childrenKey = child[childrenKey]) === null || _child$childrenKey === void 0 ? void 0 : _child$childrenKey.length) > 0) {\n // fix: #3559\n return isEveryChildChecked(child, {\n nodes: nodes,\n childrenKey: childrenKey\n });\n }\n return !(0, _isNil2.default)(child.refKey) && nodes[child.refKey].check;\n });\n}\n\n/**\n * Checks if any child node is checked.\n */\nfunction isSomeChildChecked(nodes, parent, childrenKey) {\n if (!(0, _isNil2.default)(parent.refKey) && (0, _isNil2.default)(nodes[parent.refKey])) {\n return false;\n }\n var children = getChildrenByFlattenNodes(nodes, parent);\n return children.some(function (child) {\n var _child$childrenKey2;\n if ((child === null || child === void 0 ? void 0 : (_child$childrenKey2 = child[childrenKey]) === null || _child$childrenKey2 === void 0 ? void 0 : _child$childrenKey2.length) > 0) {\n return isSomeChildChecked(nodes, child, childrenKey);\n }\n return !(0, _isNil2.default)(child.refKey) && nodes[child.refKey].check;\n });\n}\n\n/**\n * Checks if any node in the data has a grandchild.\n */\nfunction hasGrandchild(data, childrenKey) {\n return data.some(function (node) {\n return Array.isArray(node[childrenKey]);\n });\n}\n\n/**\n * Checks if all sibling nodes of a given node are uncheckable.\n */\nfunction isAllSiblingNodeUncheckable(node, nodes, uncheckableItemValues, valueKey) {\n var list = [];\n var parentNodeRefKey = node.parent ? node.parent.refKey : '';\n Object.keys(nodes).forEach(function (refKey) {\n var _curNode$parent;\n var curNode = nodes[refKey];\n if ((0, _isNil2.default)(node.parent) && (0, _isNil2.default)(curNode.parent)) {\n list.push(curNode);\n } else if (((_curNode$parent = curNode.parent) === null || _curNode$parent === void 0 ? void 0 : _curNode$parent.refKey) === parentNodeRefKey) {\n list.push(curNode);\n }\n });\n return list.every(function (node) {\n return isNodeUncheckable(node, {\n uncheckableItemValues: uncheckableItemValues,\n valueKey: valueKey\n });\n });\n}\n\n/**\n * Checks if every first-level node is uncheckable based on the provided criteria.\n */\nfunction isEveryFirstLevelNodeUncheckable(nodes, uncheckableItemValues, valueKey) {\n var list = [];\n Object.keys(nodes).forEach(function (refKey) {\n var curNode = nodes[refKey];\n if (!curNode.parent) {\n list.push(curNode);\n }\n });\n return list.every(function (node) {\n return isNodeUncheckable(node, {\n uncheckableItemValues: uncheckableItemValues,\n valueKey: valueKey\n });\n });\n}\n\n/**\n * Checks if a node is uncheckable.\n */\nfunction isNodeUncheckable(node, props) {\n var _props$uncheckableIte = props.uncheckableItemValues,\n uncheckableItemValues = _props$uncheckableIte === void 0 ? [] : _props$uncheckableIte,\n valueKey = props.valueKey;\n return uncheckableItemValues.some(function (value) {\n return node[valueKey] === value;\n });\n}\nfunction getFormattedTree(nodes, data, props) {\n var childrenKey = props.childrenKey,\n cascade = props.cascade;\n return data.map(function (node) {\n var formatted = (0, _extends2.default)({}, node);\n var curNode = nodes[node.refKey];\n if (curNode) {\n var _node$childrenKey;\n var checkState = !(0, _isUndefined2.default)(cascade) ? getNodeCheckState(curNode, {\n cascade: cascade,\n nodes: nodes,\n childrenKey: childrenKey\n }) : undefined;\n formatted.check = curNode.check;\n formatted.uncheckable = curNode.uncheckable;\n (0, _utils.attachParent)(formatted, curNode.parent);\n formatted.checkState = checkState;\n if (((_node$childrenKey = node[childrenKey]) === null || _node$childrenKey === void 0 ? void 0 : _node$childrenKey.length) > 0) {\n formatted[childrenKey] = getFormattedTree(nodes, formatted[childrenKey], props);\n }\n }\n return formatted;\n });\n}\n\n/**\n * Determines the disabled state of a tree node.\n */\nfunction getDisabledState(nodes, node, props) {\n var _props$disabledItemVa = props.disabledItemValues,\n disabledItemValues = _props$disabledItemVa === void 0 ? [] : _props$disabledItemVa,\n valueKey = props.valueKey;\n if (!(0, _isNil2.default)(node.refKey) && (0, _isNil2.default)(nodes[node.refKey])) {\n return false;\n }\n return disabledItemValues.some(function (value) {\n return node.refKey && nodes[node.refKey][valueKey] === value;\n });\n}\n\n/**\n * Returns the default value for the check tree.\n */\nfunction getCheckTreeDefaultValue(value, uncheckableItemValues) {\n if (Array.isArray(value) && Array.isArray(uncheckableItemValues)) {\n return value.filter(function (v) {\n return !uncheckableItemValues.includes(v);\n });\n }\n return value;\n}\n\n/**\n * Retrieves the selected items from the given nodes.\n */\nfunction getSelectedItems(nodes, values) {\n var checkedItems = [];\n values.forEach(function (value) {\n var refKey = (0, _utils2.formatNodeRefKey)(value);\n var node = nodes[refKey];\n if (!(0, _isNil2.default)(node)) {\n checkedItems.push(node);\n }\n });\n return checkedItems;\n}\n/**\n * Calculates the check state of a node in a check tree.\n */\nfunction getNodeCheckState(node, options) {\n var nodes = options.nodes,\n cascade = options.cascade,\n childrenKey = options.childrenKey;\n if (node.refKey === undefined) {\n return _constants.CHECK_STATE.UNCHECK;\n }\n if ((0, _isNil2.default)(nodes[node.refKey])) {\n return _constants.CHECK_STATE.UNCHECK;\n }\n if (!node[childrenKey] || !node[childrenKey].length || !cascade) {\n nodes[node.refKey].checkAll = false;\n return node.check ? _constants.CHECK_STATE.CHECK : _constants.CHECK_STATE.UNCHECK;\n }\n if (isEveryChildChecked(node, {\n nodes: nodes,\n childrenKey: childrenKey\n })) {\n nodes[node.refKey].checkAll = true;\n nodes[node.refKey].check = true;\n return _constants.CHECK_STATE.CHECK;\n }\n if (isSomeChildChecked(nodes, node, childrenKey)) {\n nodes[node.refKey].checkAll = false;\n return _constants.CHECK_STATE.INDETERMINATE;\n }\n return _constants.CHECK_STATE.UNCHECK;\n}\n\n//# sourceURL=webpack://rsuite/./src/CheckTree/utils.ts?");
6685
6685
 
6686
6686
  /***/ }),
6687
6687