rsuite 5.32.0 → 5.33.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.
Files changed (50) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/cjs/Carousel/Carousel.js +12 -2
  3. package/cjs/Cascader/Cascader.js +2 -2
  4. package/cjs/Cascader/utils.d.ts +0 -9
  5. package/cjs/Cascader/utils.js +2 -48
  6. package/cjs/CheckPicker/CheckPicker.js +6 -2
  7. package/cjs/CheckTreePicker/CheckTreePicker.js +16 -3
  8. package/cjs/DatePicker/DatePicker.js +1 -1
  9. package/cjs/InputPicker/InputPicker.js +7 -2
  10. package/cjs/MultiCascader/MultiCascader.js +1 -0
  11. package/cjs/Picker/DropdownMenu.d.ts +1 -0
  12. package/cjs/Picker/DropdownMenu.js +19 -6
  13. package/cjs/Picker/utils.d.ts +2 -0
  14. package/cjs/Picker/utils.js +8 -1
  15. package/cjs/SelectPicker/SelectPicker.js +7 -2
  16. package/cjs/Tree/Tree.d.ts +2 -0
  17. package/cjs/TreePicker/TreePicker.js +16 -3
  18. package/cjs/utils/getDataGroupBy.d.ts +4 -1
  19. package/cjs/utils/getDataGroupBy.js +12 -24
  20. package/cjs/utils/index.d.ts +0 -1
  21. package/cjs/utils/index.js +1 -6
  22. package/cjs/utils/treeUtils.d.ts +25 -1
  23. package/cjs/utils/treeUtils.js +121 -9
  24. package/dist/rsuite.js +61 -21
  25. package/dist/rsuite.js.map +1 -1
  26. package/dist/rsuite.min.js +1 -1
  27. package/dist/rsuite.min.js.map +1 -1
  28. package/esm/Carousel/Carousel.js +13 -3
  29. package/esm/Cascader/Cascader.js +2 -2
  30. package/esm/Cascader/utils.d.ts +0 -9
  31. package/esm/Cascader/utils.js +1 -44
  32. package/esm/CheckPicker/CheckPicker.js +5 -2
  33. package/esm/CheckTreePicker/CheckTreePicker.js +17 -4
  34. package/esm/DatePicker/DatePicker.js +1 -1
  35. package/esm/InputPicker/InputPicker.js +6 -2
  36. package/esm/MultiCascader/MultiCascader.js +1 -0
  37. package/esm/Picker/DropdownMenu.d.ts +1 -0
  38. package/esm/Picker/DropdownMenu.js +17 -5
  39. package/esm/Picker/utils.d.ts +2 -0
  40. package/esm/Picker/utils.js +8 -1
  41. package/esm/SelectPicker/SelectPicker.js +6 -2
  42. package/esm/Tree/Tree.d.ts +2 -0
  43. package/esm/TreePicker/TreePicker.js +18 -5
  44. package/esm/utils/getDataGroupBy.d.ts +4 -1
  45. package/esm/utils/getDataGroupBy.js +13 -24
  46. package/esm/utils/index.d.ts +0 -1
  47. package/esm/utils/index.js +0 -1
  48. package/esm/utils/treeUtils.d.ts +25 -1
  49. package/esm/utils/treeUtils.js +111 -10
  50. package/package.json +3 -3
@@ -6,6 +6,13 @@ import _isArray from "lodash/isArray";
6
6
  import _omit from "lodash/omit";
7
7
  import _isUndefined from "lodash/isUndefined";
8
8
  import _intersection from "lodash/intersection";
9
+
10
+ function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
11
+
12
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
13
+
14
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
15
+
9
16
  import React, { useRef, useState, useEffect, useCallback } from 'react';
10
17
  import shallowEqualArray from '../utils/shallowEqualArray';
11
18
  import { getNodeCheckState } from '../CheckTreePicker/utils';
@@ -74,15 +81,33 @@ export function UNSAFE_flattenTree(tree, childrenKey, executor) {
74
81
  traverse(tree, null);
75
82
  return flattenData;
76
83
  }
77
- export function flattenTree(rootNodes, getChildren) {
84
+ export var WalkTreeStrategy;
85
+
86
+ (function (WalkTreeStrategy) {
87
+ WalkTreeStrategy[WalkTreeStrategy["DFS"] = 0] = "DFS";
88
+ WalkTreeStrategy[WalkTreeStrategy["BFS"] = 1] = "BFS";
89
+ })(WalkTreeStrategy || (WalkTreeStrategy = {}));
90
+
91
+ export function flattenTree(rootNodes, getChildren, walkStrategy) {
92
+ if (walkStrategy === void 0) {
93
+ walkStrategy = WalkTreeStrategy.BFS;
94
+ }
95
+
78
96
  var result = [];
79
- walkTree(rootNodes, getChildren, function (node) {
80
- return result.push(node);
81
- });
97
+
98
+ if (walkStrategy === WalkTreeStrategy.BFS) {
99
+ walkTreeBfs(rootNodes, getChildren, function (node) {
100
+ return result.push(node);
101
+ });
102
+ } else if (walkStrategy === WalkTreeStrategy.DFS) {
103
+ walkTreeDfs(rootNodes, getChildren, function (node) {
104
+ return result.push(node);
105
+ });
106
+ }
107
+
82
108
  return result;
83
109
  }
84
-
85
- function walkTree(rootNodes, getChildren, callback) {
110
+ export function walkTreeBfs(rootNodes, getChildren, callback) {
86
111
  for (var queue = [].concat(rootNodes); queue.length > 0;) {
87
112
  var _node = queue.shift();
88
113
 
@@ -94,12 +119,22 @@ function walkTree(rootNodes, getChildren, callback) {
94
119
  }
95
120
  }
96
121
  }
122
+ export function walkTreeDfs(rootNodes, getChildren, callback) {
123
+ for (var _iterator = _createForOfIteratorHelperLoose(rootNodes), _step; !(_step = _iterator()).done;) {
124
+ var _node2 = _step.value;
125
+ callback(_node2);
126
+ var children = getChildren(_node2);
127
+
128
+ if (children) {
129
+ walkTreeDfs(children, getChildren, callback);
130
+ }
131
+ }
132
+ }
97
133
  /**
98
134
  * get all ancestor nodes of given node
99
135
  * @param {*} node
100
136
  */
101
137
 
102
-
103
138
  export function getNodeParents(node, parentKey, valueKey) {
104
139
  if (parentKey === void 0) {
105
140
  parentKey = 'parent';
@@ -335,10 +370,10 @@ export function findNodeOfTree(data, check) {
335
370
  var _item3 = nodes[i];
336
371
 
337
372
  if (_isArray(_item3.children)) {
338
- var _node2 = findNode(_item3.children);
373
+ var _node3 = findNode(_item3.children);
339
374
 
340
- if (_node2) {
341
- return _node2;
375
+ if (_node3) {
376
+ return _node3;
342
377
  }
343
378
  }
344
379
 
@@ -1091,4 +1126,70 @@ export function stringifyTreeNodeLabel(label) {
1091
1126
  }
1092
1127
 
1093
1128
  return '';
1129
+ }
1130
+ /**
1131
+ * Returns a WeakMap that maps each item in `items` to its parent
1132
+ * indicated by `getChildren` function
1133
+ */
1134
+
1135
+ export function getParentMap(items, getChildren) {
1136
+ var map = new WeakMap();
1137
+
1138
+ for (var queue = [].concat(items); queue.length > 0;) {
1139
+ var _item5 = queue.shift();
1140
+
1141
+ var children = getChildren(_item5);
1142
+
1143
+ if (children) {
1144
+ for (var _iterator2 = _createForOfIteratorHelperLoose(children), _step2; !(_step2 = _iterator2()).done;) {
1145
+ var child = _step2.value;
1146
+ map.set(child, _item5);
1147
+ queue.push(child);
1148
+ }
1149
+ }
1150
+ }
1151
+
1152
+ return map;
1153
+ }
1154
+ /**
1155
+ * Returns a Map that maps each item's "key", indicated by `getKey` function,
1156
+ * to its parent indicated by `getChildren` function
1157
+ *
1158
+ * NOTICE:
1159
+ * Using this function is discouraged.
1160
+ * Use {@link getParentMap} whenever possible.
1161
+ */
1162
+
1163
+ export function getKeyParentMap(items, getKey, getChildren) {
1164
+ var map = new Map();
1165
+
1166
+ for (var queue = [].concat(items); queue.length > 0;) {
1167
+ var _item6 = queue.shift();
1168
+
1169
+ var children = getChildren(_item6);
1170
+
1171
+ if (children) {
1172
+ for (var _iterator3 = _createForOfIteratorHelperLoose(children), _step3; !(_step3 = _iterator3()).done;) {
1173
+ var child = _step3.value;
1174
+ map.set(getKey(child), _item6);
1175
+ queue.push(child);
1176
+ }
1177
+ }
1178
+ }
1179
+
1180
+ return map;
1181
+ }
1182
+ /**
1183
+ * Returns an array indicating the hierarchy path from root towards `target` item
1184
+ */
1185
+
1186
+ export function getPathTowardsItem(target, getParent) {
1187
+ if (!target) return [];
1188
+ var path = [target];
1189
+
1190
+ for (var parent = getParent(target); !!parent; parent = getParent(parent)) {
1191
+ path.unshift(parent);
1192
+ }
1193
+
1194
+ return path;
1094
1195
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rsuite",
3
- "version": "5.32.0",
3
+ "version": "5.33.1",
4
4
  "description": "A suite of react components",
5
5
  "main": "cjs/index.js",
6
6
  "module": "esm/index.js",
@@ -38,8 +38,8 @@
38
38
  "prop-types": "^15.8.1",
39
39
  "react-use-set": "^1.0.0",
40
40
  "react-window": "^1.8.8",
41
- "rsuite-table": "^5.10.3",
42
- "schema-typed": "^2.1.2"
41
+ "rsuite-table": "^5.10.5",
42
+ "schema-typed": "^2.1.3"
43
43
  },
44
44
  "peerDependencies": {
45
45
  "react": ">=16.8.0",