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
package/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ ## [5.33.1](https://github.com/rsuite/rsuite/compare/v5.33.0...v5.33.1) (2023-05-12)
2
+
3
+ ### Bug Fixes
4
+
5
+ - **Carousel:** fix index not being reset when children change ([#3185](https://github.com/rsuite/rsuite/issues/3185)) ([3afb746](https://github.com/rsuite/rsuite/commit/3afb7460f5d12b34eb0e7944fa9f5a461b663028))
6
+ - **CheckPicker:** avoid mutating data when groupBy is specified ([#3173](https://github.com/rsuite/rsuite/issues/3173)) ([1a9805a](https://github.com/rsuite/rsuite/commit/1a9805a00cffcb8e527fbeb1df3a346da9a707f0))
7
+ - **DatePicker:** fix defaultValue not changing month on calendar ([#3183](https://github.com/rsuite/rsuite/issues/3183)) ([b0a2b5f](https://github.com/rsuite/rsuite/commit/b0a2b5f5cfe6ea94c1c13f8e9451c5d60f7f5b80))
8
+ - **pickers:** fix keyboard events still responding when readOnly ([#3184](https://github.com/rsuite/rsuite/issues/3184)) ([56e7563](https://github.com/rsuite/rsuite/commit/56e7563b2035be767f5ed8429cd8c3622708abe8))
9
+
10
+ # [5.33.0](https://github.com/rsuite/rsuite/compare/v5.32.0...v5.33.0) (2023-04-28)
11
+
12
+ ### Features
13
+
14
+ - **Tree,TreePicker,CheckTree,CheckTreePicker:** add onSelectItem prop ([#3172](https://github.com/rsuite/rsuite/issues/3172)) ([9a5618a](https://github.com/rsuite/rsuite/commit/9a5618a3affb13e70330a5aea253e8b54c67b61b))
15
+
1
16
  # [5.32.0](https://github.com/rsuite/rsuite/compare/v5.31.1...v5.32.0) (2023-04-21)
2
17
 
3
18
  ### Bug Fixes
@@ -59,13 +59,23 @@ var Carousel = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
59
59
 
60
60
  var _useControlled = (0, _utils.useControlled)(activeIndexProp, defaultActiveIndex),
61
61
  activeIndex = _useControlled[0],
62
- setActiveIndex = _useControlled[1];
62
+ setActiveIndex = _useControlled[1],
63
+ isControlled = _useControlled[2];
63
64
 
64
65
  var _useState = (0, _react.useState)(0),
65
66
  lastIndex = _useState[0],
66
67
  setLastIndex = _useState[1];
67
68
 
68
- var rootRef = (0, _react.useRef)(null); // Set a timer for automatic playback.
69
+ var rootRef = (0, _react.useRef)(null);
70
+ (0, _utils.useUpdateEffect)(function () {
71
+ // When the index is controlled, the index is not updated when the number of children changes.
72
+ if (isControlled) {
73
+ return;
74
+ } // Reset the index when the number of children changes.
75
+
76
+
77
+ setActiveIndex(0);
78
+ }, [children, isControlled]); // Set a timer for automatic playback.
69
79
  // `autoplay` needs to be cast to boolean type to avoid undefined parameters.
70
80
 
71
81
  var _useTimeout = (0, _utils.useTimeout)(function () {
@@ -111,7 +111,7 @@ var Cascader = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
111
111
  var loadingItemsSet = (0, _reactUseSet.useSet)();
112
112
  var asyncChildrenMap = (0, _useMap.useMap)();
113
113
  var parentMap = (0, _react.useMemo)(function () {
114
- return (0, _utils.getParentMap)(data, function (item) {
114
+ return (0, _treeUtils.getParentMap)(data, function (item) {
115
115
  var _asyncChildrenMap$get;
116
116
 
117
117
  return (_asyncChildrenMap$get = asyncChildrenMap.get(item)) !== null && _asyncChildrenMap$get !== void 0 ? _asyncChildrenMap$get : item[childrenKey];
@@ -365,7 +365,7 @@ var Cascader = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
365
365
 
366
366
  var renderSearchRow = function renderSearchRow(item, key) {
367
367
  var regx = new RegExp((0, _utils2.getSafeRegExpString)(searchKeyword), 'ig');
368
- var nodes = (0, _utils.getPathTowardsItem)(item, function (item) {
368
+ var nodes = (0, _treeUtils.getPathTowardsItem)(item, function (item) {
369
369
  return parentMap.get(item);
370
370
  });
371
371
  var formattedNodes = nodes.map(function (node) {
@@ -46,13 +46,4 @@ export declare function usePaths<T extends Record<string, unknown>>({ data, acti
46
46
  pathTowardsSelectedItem: T[];
47
47
  pathTowardsActiveItem: T[];
48
48
  };
49
- /**
50
- * Returns a WeakMap that maps each item in `items` to its parent
51
- * indicated by `getChildren` function
52
- */
53
- export declare function getParentMap<T extends Record<string, unknown>>(items: readonly T[], getChildren: (item: T) => readonly T[] | undefined): WeakMap<T, T>;
54
- /**
55
- * Returns an array indicating the hirearchy path from root towards `target` item
56
- */
57
- export declare function getPathTowardsItem<T>(target: T | undefined, getParent: (item: T) => T | undefined): T[];
58
49
  export {};
@@ -3,16 +3,10 @@
3
3
  exports.__esModule = true;
4
4
  exports.getColumnsAndPaths = getColumnsAndPaths;
5
5
  exports.usePaths = usePaths;
6
- exports.getParentMap = getParentMap;
7
- exports.getPathTowardsItem = getPathTowardsItem;
8
6
 
9
7
  var _react = require("react");
10
8
 
11
- 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."); }
12
-
13
- 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); }
14
-
15
- 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; }
9
+ var _treeUtils = require("../utils/treeUtils");
16
10
 
17
11
  /**
18
12
  * Calculate columns to be displayed:
@@ -76,7 +70,7 @@ function usePaths(_ref) {
76
70
  getParent = _ref.getParent,
77
71
  getChildren = _ref.getChildren;
78
72
  var pathTowardsSelectedItem = (0, _react.useMemo)(function () {
79
- return getPathTowardsItem(selectedItem, getParent);
73
+ return (0, _treeUtils.getPathTowardsItem)(selectedItem, getParent);
80
74
  }, [getParent, selectedItem]);
81
75
 
82
76
  var _useMemo = (0, _react.useMemo)(function () {
@@ -93,44 +87,4 @@ function usePaths(_ref) {
93
87
  pathTowardsSelectedItem: pathTowardsSelectedItem,
94
88
  pathTowardsActiveItem: pathTowardsActiveItem
95
89
  };
96
- }
97
- /**
98
- * Returns a WeakMap that maps each item in `items` to its parent
99
- * indicated by `getChildren` function
100
- */
101
-
102
-
103
- function getParentMap(items, getChildren) {
104
- var map = new WeakMap();
105
-
106
- for (var queue = [].concat(items); queue.length > 0;) {
107
- var _item = queue.shift();
108
-
109
- var children = getChildren(_item);
110
-
111
- if (children) {
112
- for (var _iterator = _createForOfIteratorHelperLoose(children), _step; !(_step = _iterator()).done;) {
113
- var child = _step.value;
114
- map.set(child, _item);
115
- queue.push(child);
116
- }
117
- }
118
- }
119
-
120
- return map;
121
- }
122
- /**
123
- * Returns an array indicating the hirearchy path from root towards `target` item
124
- */
125
-
126
-
127
- function getPathTowardsItem(target, getParent) {
128
- if (!target) return [];
129
- var path = [target];
130
-
131
- for (var parent = getParent(target); !!parent; parent = getParent(parent)) {
132
- path.unshift(parent);
133
- }
134
-
135
- return path;
136
90
  }
@@ -35,6 +35,8 @@ var _treeUtils = require("../utils/treeUtils");
35
35
 
36
36
  var _utils = require("../utils");
37
37
 
38
+ var _getDataGroupBy = require("../utils/getDataGroupBy");
39
+
38
40
  var _Picker = require("../Picker");
39
41
 
40
42
  var _templateObject;
@@ -323,7 +325,7 @@ var CheckPicker = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
323
325
 
324
326
 
325
327
  if (groupBy) {
326
- items = (0, _utils.getDataGroupBy)(items, groupBy, sort);
328
+ items = (0, _getDataGroupBy.getDataGroupBy)(items, groupBy, sort);
327
329
  } else if (typeof sort === 'function') {
328
330
  items = items.sort(sort(false));
329
331
  }
@@ -342,8 +344,10 @@ var CheckPicker = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
342
344
  dropdownMenuItemAs: _Picker.DropdownMenuCheckItem,
343
345
  activeItemValues: value,
344
346
  focusItemValue: focusItemValue,
345
- data: [].concat(filteredStickyItems, items),
347
+ data: [].concat(filteredStickyItems, items) // `group` is redundant so long as `groupBy` exists
348
+ ,
346
349
  group: !(0, _isUndefined.default)(groupBy),
350
+ groupBy: groupBy,
347
351
  onSelect: handleItemSelect,
348
352
  onGroupTitleClick: onGroupTitleClick,
349
353
  virtualized: virtualized
@@ -117,13 +117,14 @@ var CheckTreePicker = /*#__PURE__*/_react.default.forwardRef(function (props, re
117
117
  onExited = props.onExited,
118
118
  onSearch = props.onSearch,
119
119
  onSelect = props.onSelect,
120
+ onSelectItem = props.onSelectItem,
120
121
  onOpen = props.onOpen,
121
122
  onScroll = props.onScroll,
122
123
  onExpand = props.onExpand,
123
124
  renderValue = props.renderValue,
124
125
  renderTreeIcon = props.renderTreeIcon,
125
126
  renderTreeNode = props.renderTreeNode,
126
- rest = (0, _objectWithoutPropertiesLoose2.default)(props, ["as", "data", "style", "appearance", "cleanable", "countable", "searchBy", "toggleAs", "searchKeyword", "showIndentLine", "locale", "cascade", "disabled", "valueKey", "labelKey", "placement", "childrenKey", "placeholder", "value", "defaultValue", "defaultExpandAll", "disabledItemValues", "expandItemValues", "defaultExpandItemValues", "height", "menuMaxHeight", "menuStyle", "searchable", "virtualized", "className", "classPrefix", "menuClassName", "menuAutoWidth", "uncheckableItemValues", "id", "listProps", "renderMenu", "getChildren", "renderExtraFooter", "onEntered", "onChange", "onClean", "onClose", "onExited", "onSearch", "onSelect", "onOpen", "onScroll", "onExpand", "renderValue", "renderTreeIcon", "renderTreeNode"]);
127
+ rest = (0, _objectWithoutPropertiesLoose2.default)(props, ["as", "data", "style", "appearance", "cleanable", "countable", "searchBy", "toggleAs", "searchKeyword", "showIndentLine", "locale", "cascade", "disabled", "valueKey", "labelKey", "placement", "childrenKey", "placeholder", "value", "defaultValue", "defaultExpandAll", "disabledItemValues", "expandItemValues", "defaultExpandItemValues", "height", "menuMaxHeight", "menuStyle", "searchable", "virtualized", "className", "classPrefix", "menuClassName", "menuAutoWidth", "uncheckableItemValues", "id", "listProps", "renderMenu", "getChildren", "renderExtraFooter", "onEntered", "onChange", "onClean", "onClose", "onExited", "onSearch", "onSelect", "onSelectItem", "onOpen", "onScroll", "onExpand", "renderValue", "renderTreeIcon", "renderTreeNode"]);
127
128
 
128
129
  var _useContext = (0, _react.useContext)(_TreeContext.default),
129
130
  inline = _useContext.inline;
@@ -368,7 +369,16 @@ var CheckTreePicker = /*#__PURE__*/_react.default.forwardRef(function (props, re
368
369
  return values.filter(function (v) {
369
370
  return !uncheckableItemValues.includes(v);
370
371
  });
371
- }, [flattenNodes, uncheckableItemValues, serializeListOnlyParent, toggleDownChecked, toggleUpChecked]);
372
+ }, [flattenNodes, uncheckableItemValues, serializeListOnlyParent, toggleDownChecked, toggleUpChecked]); // TODO-Doma
373
+ // Replace `getKeyParentMap` with `getParentMap`
374
+
375
+ var itemParentMap = (0, _react.useMemo)(function () {
376
+ return (0, _treeUtils.getKeyParentMap)(data, function (node) {
377
+ return node[valueKey];
378
+ }, function (node) {
379
+ return node[childrenKey];
380
+ });
381
+ }, [childrenKey, data, valueKey]);
372
382
  var handleSelect = (0, _react.useCallback)(function (node, event) {
373
383
  var currentNode = node.refKey ? flattenNodes[node.refKey] : null;
374
384
 
@@ -393,7 +403,10 @@ var CheckTreePicker = /*#__PURE__*/_react.default.forwardRef(function (props, re
393
403
  setFocusItemValue(node[valueKey]);
394
404
  onChange === null || onChange === void 0 ? void 0 : onChange(selectedValues, event);
395
405
  onSelect === null || onSelect === void 0 ? void 0 : onSelect(node, selectedValues, event);
396
- }, [cascade, valueKey, flattenNodes, isControlled, uncheckableItemValues, setValue, onChange, onSelect, toggleChecked, unSerializeList]);
406
+ onSelectItem === null || onSelectItem === void 0 ? void 0 : onSelectItem(node, (0, _treeUtils.getPathTowardsItem)(node, function (item) {
407
+ return itemParentMap.get(item[valueKey]);
408
+ }));
409
+ }, [flattenNodes, toggleChecked, isControlled, valueKey, onChange, onSelect, onSelectItem, unSerializeList, cascade, uncheckableItemValues, setValue, itemParentMap]);
397
410
  var handleOpen = (0, _react.useCallback)(function () {
398
411
  var _triggerRef$current, _triggerRef$current$o;
399
412
 
@@ -117,7 +117,7 @@ var DatePicker = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
117
117
  value = _useControlled[0],
118
118
  setValue = _useControlled[1];
119
119
 
120
- var _useCalendarDate = (0, _useCalendarDate2.default)(valueProp, calendarDefaultDate),
120
+ var _useCalendarDate = (0, _useCalendarDate2.default)(value, calendarDefaultDate),
121
121
  calendarDate = _useCalendarDate.calendarDate,
122
122
  setCalendarDate = _useCalendarDate.setCalendarDate,
123
123
  resetCalendarDate = _useCalendarDate.resetCalendarDate;
@@ -43,6 +43,8 @@ var _Plaintext = _interopRequireDefault(require("../Plaintext"));
43
43
 
44
44
  var _utils = require("../utils");
45
45
 
46
+ var _getDataGroupBy = require("../utils/getDataGroupBy");
47
+
46
48
  var _Picker = require("../Picker");
47
49
 
48
50
  var _Tag = _interopRequireDefault(require("../Tag"));
@@ -629,7 +631,7 @@ var InputPicker = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
629
631
 
630
632
 
631
633
  if (groupBy) {
632
- items = (0, _utils.getDataGroupBy)(items, groupBy, sort);
634
+ items = (0, _getDataGroupBy.getDataGroupBy)(items, groupBy, sort);
633
635
  } else if (typeof sort === 'function') {
634
636
  items = items.sort(sort(false));
635
637
  }
@@ -653,8 +655,11 @@ var InputPicker = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
653
655
  activeItemValues: multi ? value : [value],
654
656
  focusItemValue: focusItemValue,
655
657
  maxHeight: menuMaxHeight,
656
- data: items,
658
+ data: items // FIXME-Doma
659
+ // `group` is redundant so long as `groupBy` exists
660
+ ,
657
661
  group: !(0, _isUndefined.default)(groupBy),
662
+ groupBy: groupBy,
658
663
  onSelect: multi ? handleCheckTag : handleSelectItem // fixme don't use any
659
664
  ,
660
665
  renderMenuGroup: renderMenuGroup,
@@ -249,6 +249,7 @@ var MultiCascader = /*#__PURE__*/_react.default.forwardRef(function (props, ref)
249
249
  (_triggerRef$current = triggerRef.current) === null || _triggerRef$current === void 0 ? void 0 : (_triggerRef$current$u = _triggerRef$current.updatePosition) === null || _triggerRef$current$u === void 0 ? void 0 : _triggerRef$current$u.call(_triggerRef$current);
250
250
  }, [onSelect, getChildren, childrenKey, inline, addFlattenData, addColumn, removeColumnByIndex]);
251
251
  var handleCheck = (0, _react.useCallback)(function (node, event, checked) {
252
+ console.log('handleCheck');
252
253
  var nodeValue = node[valueKey];
253
254
  var nextValue = [];
254
255
 
@@ -6,6 +6,7 @@ export interface DropdownMenuProps<Multiple = false> extends StandardProps, Omit
6
6
  classPrefix: string;
7
7
  data?: ItemDataType[];
8
8
  group?: boolean;
9
+ groupBy?: string;
9
10
  disabledItemValues?: any[];
10
11
  activeItemValues?: any[];
11
12
  focusItemValue?: any;
@@ -11,6 +11,8 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
11
11
 
12
12
  var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
13
13
 
14
+ var _get2 = _interopRequireDefault(require("lodash/get"));
15
+
14
16
  var _react = _interopRequireWildcard(require("react"));
15
17
 
16
18
  var _propTypes = _interopRequireDefault(require("prop-types"));
@@ -47,6 +49,7 @@ var DropdownMenu = /*#__PURE__*/_react.default.forwardRef(function (props, ref)
47
49
  var _props$data = props.data,
48
50
  data = _props$data === void 0 ? [] : _props$data,
49
51
  group = props.group,
52
+ groupBy = props.groupBy,
50
53
  _props$maxHeight = props.maxHeight,
51
54
  maxHeight = _props$maxHeight === void 0 ? 320 : _props$maxHeight,
52
55
  _props$activeItemValu = props.activeItemValues,
@@ -75,7 +78,7 @@ var DropdownMenu = /*#__PURE__*/_react.default.forwardRef(function (props, ref)
75
78
  renderMenuItem = props.renderMenuItem,
76
79
  onGroupTitleClick = props.onGroupTitleClick,
77
80
  onSelect = props.onSelect,
78
- rest = (0, _objectWithoutPropertiesLoose2.default)(props, ["data", "group", "maxHeight", "activeItemValues", "disabledItemValues", "classPrefix", "valueKey", "labelKey", "virtualized", "listProps", "listRef", "className", "style", "focusItemValue", "dropdownMenuItemClassPrefix", "dropdownMenuItemAs", "rowHeight", "rowGroupHeight", "renderMenuGroup", "renderMenuItem", "onGroupTitleClick", "onSelect"]);
81
+ rest = (0, _objectWithoutPropertiesLoose2.default)(props, ["data", "group", "groupBy", "maxHeight", "activeItemValues", "disabledItemValues", "classPrefix", "valueKey", "labelKey", "virtualized", "listProps", "listRef", "className", "style", "focusItemValue", "dropdownMenuItemClassPrefix", "dropdownMenuItemAs", "rowHeight", "rowGroupHeight", "renderMenuGroup", "renderMenuItem", "onGroupTitleClick", "onSelect"]);
79
82
 
80
83
  var _useClassNames = (0, _utils.useClassNames)(classPrefix),
81
84
  withClassPrefix = _useClassNames.withClassPrefix,
@@ -205,11 +208,21 @@ var DropdownMenu = /*#__PURE__*/_react.default.forwardRef(function (props, ref)
205
208
  };
206
209
 
207
210
  var filteredItems = group ? data.filter(function (item) {
208
- return !(foldedGroupKeys !== null && foldedGroupKeys !== void 0 && foldedGroupKeys.some(function (key) {
209
- var _item$parent;
210
-
211
- return key === ((_item$parent = item.parent) === null || _item$parent === void 0 ? void 0 : _item$parent[_getDataGroupBy.KEY_GROUP_TITLE]);
212
- }));
211
+ var _item$parent;
212
+
213
+ // Display group title items
214
+ if (item[_getDataGroupBy.KEY_GROUP]) return true; // Display items under the unfolded group
215
+ // FIXME-Doma
216
+ // `groupBy` is bound to be string when `group` is true
217
+ // because `group` is actually redundant as a prop
218
+ // It could simply be derived from `groupBy` value
219
+
220
+ var groupValue = (0, _get2.default)(item, groupBy, '') || ( // FIXME-Doma
221
+ // Usage of `item.parent` is strongly discouraged
222
+ // It's only here for legacy support
223
+ // Remove once `item.parent` is completely removed across related components
224
+ (_item$parent = item.parent) === null || _item$parent === void 0 ? void 0 : _item$parent[_getDataGroupBy.KEY_GROUP_TITLE]);
225
+ return !foldedGroupKeys.includes(groupValue);
213
226
  }) : data;
214
227
  var rowCount = filteredItems.length;
215
228
  (0, _utils.useMount)(function () {
@@ -73,6 +73,8 @@ export interface ToggleKeyDownEventProps {
73
73
  overlayRef?: React.RefObject<any>;
74
74
  searchInputRef?: React.RefObject<any>;
75
75
  active?: boolean;
76
+ readOnly?: boolean;
77
+ disabled?: boolean;
76
78
  onExit?: (event: any) => void;
77
79
  onKeyDown?: (event: any) => void;
78
80
  onOpen?: () => void;
@@ -433,6 +433,8 @@ var useToggleKeyDownEvent = function useToggleKeyDownEvent(props) {
433
433
  overlayRef = props.overlayRef,
434
434
  searchInputRef = props.searchInputRef,
435
435
  active = props.active,
436
+ readOnly = props.readOnly,
437
+ disabled = props.disabled,
436
438
  onExit = props.onExit,
437
439
  onOpen = props.onOpen,
438
440
  onClose = props.onClose,
@@ -461,6 +463,11 @@ var useToggleKeyDownEvent = function useToggleKeyDownEvent(props) {
461
463
  handleOpen();
462
464
  }, [active, handleOpen, handleClose]);
463
465
  var onToggle = (0, _react.useCallback)(function (event) {
466
+ // Keyboard events should not be processed when readOnly and disabled are set.
467
+ if (readOnly || disabled) {
468
+ return;
469
+ }
470
+
464
471
  if (event.target === (targetRef === null || targetRef === void 0 ? void 0 : targetRef.current)) {
465
472
  // enter
466
473
  if (toggle && event.key === _utils.KEY_VALUES.ENTER) {
@@ -510,7 +517,7 @@ var useToggleKeyDownEvent = function useToggleKeyDownEvent(props) {
510
517
 
511
518
 
512
519
  onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(event);
513
- }, [handleClose, handleToggleDropdown, overlayRef, onExit, onKeyDown, onMenuKeyDown, onMenuPressBackspace, onMenuPressEnter, toggle, targetRef, searchInputRef]);
520
+ }, [readOnly, disabled, targetRef, overlayRef, onKeyDown, toggle, handleToggleDropdown, onExit, onMenuKeyDown, searchInputRef, onMenuPressEnter, onMenuPressBackspace, handleClose]);
514
521
  return onToggle;
515
522
  };
516
523
 
@@ -29,6 +29,8 @@ var _omit = _interopRequireDefault(require("lodash/omit"));
29
29
 
30
30
  var _utils = require("../utils");
31
31
 
32
+ var _getDataGroupBy = require("../utils/getDataGroupBy");
33
+
32
34
  var _Picker = require("../Picker");
33
35
 
34
36
  var _templateObject;
@@ -258,7 +260,7 @@ var SelectPicker = /*#__PURE__*/_react.default.forwardRef(function (props, ref)
258
260
  var items = filteredData; // Create a tree structure data when set `groupBy`
259
261
 
260
262
  if (groupBy) {
261
- items = (0, _utils.getDataGroupBy)(items, groupBy, sort);
263
+ items = (0, _getDataGroupBy.getDataGroupBy)(items, groupBy, sort);
262
264
  } else if (typeof sort === 'function') {
263
265
  items = items.sort(sort(false));
264
266
  }
@@ -278,8 +280,11 @@ var SelectPicker = /*#__PURE__*/_react.default.forwardRef(function (props, ref)
278
280
  dropdownMenuItemAs: _Picker.DropdownMenuItem,
279
281
  activeItemValues: [value],
280
282
  focusItemValue: focusItemValue,
281
- data: items,
283
+ data: items // FIXME-Doma
284
+ // `group` is redundant so long as `groupBy` exists
285
+ ,
282
286
  group: !(0, _isUndefined.default)(groupBy),
287
+ groupBy: groupBy,
283
288
  onSelect: handleItemSelect,
284
289
  onGroupTitleClick: onGroupTitleClick,
285
290
  virtualized: virtualized
@@ -60,6 +60,8 @@ export interface TreeBaseProps<ValueType = string | number, ItemDataType = Recor
60
60
  onExpand?: (expandItemValues: ItemDataType[], activeNode: ItemDataType, concat: (data: ItemDataType[], children: ItemDataType[]) => ItemDataType[]) => void;
61
61
  /** Callback function after selecting tree node */
62
62
  onSelect?: (activeNode: ItemDataType, value: ValueType, event: React.SyntheticEvent) => void;
63
+ /** Callback when a tree item is clicked */
64
+ onSelectItem?: (item: ItemDataType, path: ItemDataType[]) => void;
63
65
  /** Custom Render tree Node */
64
66
  renderTreeNode?: (nodeData: ItemDataType) => React.ReactNode;
65
67
  /** Custom Render icon */
@@ -104,6 +104,7 @@ var TreePicker = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
104
104
  onOpen = props.onOpen,
105
105
  onSearch = props.onSearch,
106
106
  onSelect = props.onSelect,
107
+ onSelectItem = props.onSelectItem,
107
108
  onChange = props.onChange,
108
109
  onEntered = props.onEntered,
109
110
  onClose = props.onClose,
@@ -117,7 +118,7 @@ var TreePicker = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
117
118
  renderExtraFooter = props.renderExtraFooter,
118
119
  renderMenu = props.renderMenu,
119
120
  renderValue = props.renderValue,
120
- rest = (0, _objectWithoutPropertiesLoose2.default)(props, ["as", "data", "appearance", "style", "showIndentLine", "value", "locale", "height", "menuMaxHeight", "menuStyle", "className", "disabled", "placement", "cleanable", "searchable", "virtualized", "classPrefix", "defaultValue", "placeholder", "searchKeyword", "menuClassName", "menuAutoWidth", "searchBy", "toggleAs", "labelKey", "valueKey", "childrenKey", "draggable", "defaultExpandAll", "disabledItemValues", "expandItemValues", "defaultExpandItemValues", "id", "listProps", "getChildren", "renderTreeIcon", "renderTreeNode", "onExit", "onExited", "onClean", "onOpen", "onSearch", "onSelect", "onChange", "onEntered", "onClose", "onDragEnd", "onDragStart", "onDragEnter", "onDragLeave", "onDragOver", "onDrop", "onExpand", "renderExtraFooter", "renderMenu", "renderValue"]);
121
+ rest = (0, _objectWithoutPropertiesLoose2.default)(props, ["as", "data", "appearance", "style", "showIndentLine", "value", "locale", "height", "menuMaxHeight", "menuStyle", "className", "disabled", "placement", "cleanable", "searchable", "virtualized", "classPrefix", "defaultValue", "placeholder", "searchKeyword", "menuClassName", "menuAutoWidth", "searchBy", "toggleAs", "labelKey", "valueKey", "childrenKey", "draggable", "defaultExpandAll", "disabledItemValues", "expandItemValues", "defaultExpandItemValues", "id", "listProps", "getChildren", "renderTreeIcon", "renderTreeNode", "onExit", "onExited", "onClean", "onOpen", "onSearch", "onSelect", "onSelectItem", "onChange", "onEntered", "onClose", "onDragEnd", "onDragStart", "onDragEnter", "onDragLeave", "onDragOver", "onDrop", "onExpand", "renderExtraFooter", "renderMenu", "renderValue"]);
121
122
  var triggerRef = (0, _react.useRef)(null);
122
123
  var targetRef = (0, _react.useRef)(null);
123
124
  var listRef = (0, _react.useRef)(null);
@@ -313,8 +314,17 @@ var TreePicker = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
313
314
  onRenderTreeNode: renderTreeNode,
314
315
  onRenderTreeIcon: renderTreeIcon
315
316
  };
316
- };
317
+ }; // TODO-Doma
318
+ // Replace `getKeyParentMap` with `getParentMap`
319
+
317
320
 
321
+ var itemParentMap = (0, _react.useMemo)(function () {
322
+ return (0, _treeUtils.getKeyParentMap)(data, function (node) {
323
+ return node[valueKey];
324
+ }, function (node) {
325
+ return node[childrenKey];
326
+ });
327
+ }, [childrenKey, data, valueKey]);
318
328
  var handleSelect = (0, _react.useCallback)(function (nodeData, event) {
319
329
  var _targetRef$current, _triggerRef$current, _triggerRef$current$c;
320
330
 
@@ -331,9 +341,12 @@ var TreePicker = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
331
341
  setFocusItemValue(nodeData[valueKey]);
332
342
  onChange === null || onChange === void 0 ? void 0 : onChange(nodeValue, event);
333
343
  onSelect === null || onSelect === void 0 ? void 0 : onSelect(nodeData, nodeValue, event);
344
+ onSelectItem === null || onSelectItem === void 0 ? void 0 : onSelectItem(nodeData, (0, _treeUtils.getPathTowardsItem)(nodeData, function (item) {
345
+ return itemParentMap.get(item[valueKey]);
346
+ }));
334
347
  (_targetRef$current = targetRef.current) === null || _targetRef$current === void 0 ? void 0 : _targetRef$current.focus();
335
348
  (_triggerRef$current = triggerRef.current) === null || _triggerRef$current === void 0 ? void 0 : (_triggerRef$current$c = _triggerRef$current.close) === null || _triggerRef$current$c === void 0 ? void 0 : _triggerRef$current$c.call(_triggerRef$current);
336
- }, [valueKey, isControlled, onChange, onSelect, setValue]);
349
+ }, [valueKey, isControlled, onChange, onSelect, onSelectItem, setValue, itemParentMap]);
337
350
  var handleExpand = (0, _react.useCallback)(function (node) {
338
351
  var nextExpandItemValues = (0, _treeUtils.toggleExpand)({
339
352
  node: node,
@@ -1,3 +1,6 @@
1
1
  export declare const KEY_GROUP: string | symbol;
2
2
  export declare const KEY_GROUP_TITLE = "groupTitle";
3
- export default function getDataGroupBy(data: any[] | undefined, key: string, sort?: any): any[];
3
+ export declare function getDataGroupBy<T>(data: readonly T[], key: string, sort?: (isGroup: boolean) => <T>(a: T, b: T) => number): (T | {
4
+ groupTitle: string;
5
+ children: T[];
6
+ })[];
@@ -3,10 +3,10 @@
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
4
 
5
5
  exports.__esModule = true;
6
- exports.default = getDataGroupBy;
6
+ exports.getDataGroupBy = getDataGroupBy;
7
7
  exports.KEY_GROUP_TITLE = exports.KEY_GROUP = void 0;
8
8
 
9
- var _get2 = _interopRequireDefault(require("lodash/get"));
9
+ var _groupBy2 = _interopRequireDefault(require("lodash/groupBy"));
10
10
 
11
11
  var _treeUtils = require("../utils/treeUtils");
12
12
 
@@ -17,26 +17,9 @@ var KEY_GROUP_TITLE = 'groupTitle';
17
17
  exports.KEY_GROUP_TITLE = KEY_GROUP_TITLE;
18
18
 
19
19
  function getDataGroupBy(data, key, sort) {
20
- if (data === void 0) {
21
- data = [];
22
- }
23
-
24
- var tempData = {};
20
+ var groupMap = (0, _groupBy2.default)(data, key);
25
21
  var isSort = typeof sort === 'function';
26
- data.forEach(function (item) {
27
- // this will allow getting data using dot notation
28
- // i.e groupBy="country.name" as country will be a nested object
29
- // to the item and the name will be nested key to the country object
30
- // can be used with values in arrays, i.e groupBy="addresses.0.country.name"
31
- var groupByValue = (0, _get2.default)(item, key, '');
32
-
33
- if (!tempData[groupByValue]) {
34
- tempData[groupByValue] = [];
35
- }
36
-
37
- tempData[groupByValue].push(item);
38
- });
39
- var nextData = Object.entries(tempData).map(function (_ref) {
22
+ var groups = Object.entries(groupMap).map(function (_ref) {
40
23
  var _ref2;
41
24
 
42
25
  var groupTitle = _ref[0],
@@ -47,8 +30,13 @@ function getDataGroupBy(data, key, sort) {
47
30
  });
48
31
 
49
32
  if (isSort) {
50
- nextData = nextData.sort(sort(true));
51
- }
33
+ groups.sort(sort(true));
34
+ } // Use DFS traverse
35
+ // Because I want the result to be [group, child, child, group, child, child]
36
+ // rather than [group, group, child, child, child, child]
37
+
52
38
 
53
- return (0, _treeUtils.UNSAFE_flattenTree)(nextData);
39
+ return (0, _treeUtils.flattenTree)(groups, function (group) {
40
+ return group.children;
41
+ }, _treeUtils.WalkTreeStrategy.DFS);
54
42
  }
@@ -12,7 +12,6 @@ export { default as ReactChildren } from './ReactChildren';
12
12
  export { default as tplTransform } from './tplTransform';
13
13
  export { default as ajaxUpload } from './ajaxUpload';
14
14
  export { default as previewFile } from './previewFile';
15
- export { default as getDataGroupBy } from './getDataGroupBy';
16
15
  export { default as clone } from './clone';
17
16
  export { default as placementPolyfill } from './placementPolyfill';
18
17
  export { default as getDOMNode } from './getDOMNode';
@@ -14,7 +14,6 @@ var _exportNames = {
14
14
  tplTransform: true,
15
15
  ajaxUpload: true,
16
16
  previewFile: true,
17
- getDataGroupBy: true,
18
17
  clone: true,
19
18
  placementPolyfill: true,
20
19
  getDOMNode: true,
@@ -49,7 +48,7 @@ var _exportNames = {
49
48
  DateUtils: true,
50
49
  TypeChecker: true
51
50
  };
52
- exports.TypeChecker = exports.DateUtils = exports.globalKey = exports.getClassNamePrefix = exports.defaultClassPrefix = exports.useMount = exports.useIsMounted = exports.useUpdateEffect = exports.useWillUnmount = exports.useUpdatedRef = exports.useEventCallback = exports.stringToObject = exports.getSafeRegExpString = exports.useRootClose = exports.useControlled = exports.useTimeout = exports.createComponent = exports.usePortal = exports.useCustom = exports.useElementResize = exports.useEventListener = exports.useClassNames = exports.render = exports.appendTooltip = exports.scrollTopAnimation = exports.reactToString = exports.composeFunctions = exports.shallowEqualArray = exports.shallowEqual = exports.mergeRefs = exports.getDOMNode = exports.placementPolyfill = exports.clone = exports.getDataGroupBy = exports.previewFile = exports.ajaxUpload = exports.tplTransform = exports.ReactChildren = exports.isOneOf = exports.createChainedFunction = exports.prefix = exports.guid = void 0;
51
+ exports.TypeChecker = exports.DateUtils = exports.globalKey = exports.getClassNamePrefix = exports.defaultClassPrefix = exports.useMount = exports.useIsMounted = exports.useUpdateEffect = exports.useWillUnmount = exports.useUpdatedRef = exports.useEventCallback = exports.stringToObject = exports.getSafeRegExpString = exports.useRootClose = exports.useControlled = exports.useTimeout = exports.createComponent = exports.usePortal = exports.useCustom = exports.useElementResize = exports.useEventListener = exports.useClassNames = exports.render = exports.appendTooltip = exports.scrollTopAnimation = exports.reactToString = exports.composeFunctions = exports.shallowEqualArray = exports.shallowEqual = exports.mergeRefs = exports.getDOMNode = exports.placementPolyfill = exports.clone = exports.previewFile = exports.ajaxUpload = exports.tplTransform = exports.ReactChildren = exports.isOneOf = exports.createChainedFunction = exports.prefix = exports.guid = void 0;
53
52
 
54
53
  var _BrowserDetection = require("./BrowserDetection");
55
54
 
@@ -130,10 +129,6 @@ var _previewFile = _interopRequireDefault(require("./previewFile"));
130
129
 
131
130
  exports.previewFile = _previewFile.default;
132
131
 
133
- var _getDataGroupBy = _interopRequireDefault(require("./getDataGroupBy"));
134
-
135
- exports.getDataGroupBy = _getDataGroupBy.default;
136
-
137
132
  var _clone = _interopRequireDefault(require("./clone"));
138
133
 
139
134
  exports.clone = _clone.default;
@@ -21,7 +21,13 @@ export declare function shouldShowNodeByParentExpanded<T>(expandItemValues?: T[]
21
21
  * Use {@link flattenTree} instead.
22
22
  */
23
23
  export declare function UNSAFE_flattenTree<TItem>(tree: TItem[], childrenKey?: string, executor?: (node: any, index: number) => any): TItem[];
24
- export declare function flattenTree<T>(rootNodes: readonly T[], getChildren: (node: T) => readonly T[] | undefined): T[];
24
+ export declare enum WalkTreeStrategy {
25
+ DFS = 0,
26
+ BFS = 1
27
+ }
28
+ export declare function flattenTree<T>(rootNodes: readonly T[], getChildren: (node: T) => readonly T[] | undefined, walkStrategy?: WalkTreeStrategy): T[];
29
+ export declare function walkTreeBfs<T>(rootNodes: readonly T[], getChildren: (node: T) => readonly T[] | undefined, callback: (node: T) => void): void;
30
+ export declare function walkTreeDfs<T>(rootNodes: readonly T[], getChildren: (node: T) => readonly T[] | undefined, callback: (node: T) => void): void;
25
31
  /**
26
32
  * get all ancestor nodes of given node
27
33
  * @param {*} node
@@ -278,3 +284,21 @@ export declare function createDragPreview(name: string, className: string): HTML
278
284
  */
279
285
  export declare function removeDragPreview(): void;
280
286
  export declare function stringifyTreeNodeLabel(label: string | React.ReactNode): string;
287
+ /**
288
+ * Returns a WeakMap that maps each item in `items` to its parent
289
+ * indicated by `getChildren` function
290
+ */
291
+ export declare function getParentMap<T extends Record<string, unknown>>(items: readonly T[], getChildren: (item: T) => readonly T[] | undefined): WeakMap<T, T>;
292
+ /**
293
+ * Returns a Map that maps each item's "key", indicated by `getKey` function,
294
+ * to its parent indicated by `getChildren` function
295
+ *
296
+ * NOTICE:
297
+ * Using this function is discouraged.
298
+ * Use {@link getParentMap} whenever possible.
299
+ */
300
+ export declare function getKeyParentMap<T extends Record<string, unknown>, K = React.Key>(items: readonly T[], getKey: (item: T) => K, getChildren: (item: T) => readonly T[] | undefined): Map<K, T>;
301
+ /**
302
+ * Returns an array indicating the hierarchy path from root towards `target` item
303
+ */
304
+ export declare function getPathTowardsItem<T>(target: T | undefined, getParent: (item: T) => T | undefined): T[];