rsuite 5.5.2 → 5.6.2

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 (105) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +4 -2
  3. package/cjs/@types/common.d.ts +4 -4
  4. package/cjs/Affix/Affix.js +0 -1
  5. package/cjs/Animation/Transition.d.ts +1 -1
  6. package/cjs/Animation/Transition.js +10 -4
  7. package/cjs/Calendar/TimeDropdown.js +7 -4
  8. package/cjs/Carousel/Carousel.d.ts +5 -1
  9. package/cjs/Carousel/Carousel.js +22 -16
  10. package/cjs/Cascader/DropdownMenu.js +1 -1
  11. package/cjs/CheckTreePicker/CheckTreePicker.js +29 -17
  12. package/cjs/CheckTreePicker/utils.d.ts +3 -3
  13. package/cjs/CheckTreePicker/utils.js +3 -3
  14. package/cjs/DOMHelper/index.d.ts +4 -4
  15. package/cjs/DatePicker/DatePicker.d.ts +2 -1
  16. package/cjs/DatePicker/DatePicker.js +19 -12
  17. package/cjs/DateRangePicker/DateRangePicker.d.ts +2 -2
  18. package/cjs/DateRangePicker/DateRangePicker.js +5 -4
  19. package/cjs/IconButton/IconButton.d.ts +5 -2
  20. package/cjs/IconButton/IconButton.js +2 -2
  21. package/cjs/IconButton/test/IconButton.test.d.ts +1 -0
  22. package/cjs/IconButton/test/IconButton.test.js +24 -0
  23. package/cjs/InputPicker/InputAutosize.js +3 -1
  24. package/cjs/InputPicker/InputPicker.js +6 -2
  25. package/cjs/List/ListItem.js +13 -11
  26. package/cjs/List/helper/AutoScroller.d.ts +2 -3
  27. package/cjs/List/helper/useManager.d.ts +2 -2
  28. package/cjs/List/helper/useSortHelper.js +23 -9
  29. package/cjs/List/helper/utils.d.ts +4 -3
  30. package/cjs/List/helper/utils.js +2 -2
  31. package/cjs/MaskedInput/conformToMask.js +1 -0
  32. package/cjs/Menu/MenuItem.js +14 -11
  33. package/cjs/MultiCascader/DropdownMenu.js +2 -1
  34. package/cjs/MultiCascader/utils.js +7 -7
  35. package/cjs/Overlay/Position.js +1 -2
  36. package/cjs/Pagination/PaginationGroup.js +3 -3
  37. package/cjs/Picker/PickerOverlay.js +4 -1
  38. package/cjs/Picker/SelectedElement.js +1 -1
  39. package/cjs/Picker/index.d.ts +2 -1
  40. package/cjs/Ripple/Ripple.js +17 -9
  41. package/cjs/TreePicker/TreePicker.js +16 -12
  42. package/cjs/Uploader/UploadTrigger.js +3 -1
  43. package/cjs/Uploader/Uploader.js +8 -2
  44. package/cjs/toaster/toaster.d.ts +1 -1
  45. package/cjs/toaster/toaster.js +9 -3
  46. package/cjs/utils/treeUtils.d.ts +3 -3
  47. package/cjs/utils/treeUtils.js +6 -4
  48. package/cjs/utils/useElementResize.d.ts +1 -1
  49. package/cjs/utils/useElementResize.js +5 -2
  50. package/cjs/utils/useTimeout.d.ts +2 -2
  51. package/cjs/utils/useTimeout.js +17 -8
  52. package/dist/rsuite.js +381 -62
  53. package/dist/rsuite.js.map +1 -1
  54. package/dist/rsuite.min.js +1 -1
  55. package/dist/rsuite.min.js.map +1 -1
  56. package/esm/@types/common.d.ts +4 -4
  57. package/esm/Affix/Affix.js +0 -1
  58. package/esm/Animation/Transition.d.ts +1 -1
  59. package/esm/Animation/Transition.js +10 -4
  60. package/esm/Calendar/TimeDropdown.js +7 -4
  61. package/esm/Carousel/Carousel.d.ts +5 -1
  62. package/esm/Carousel/Carousel.js +23 -17
  63. package/esm/Cascader/DropdownMenu.js +1 -1
  64. package/esm/CheckTreePicker/CheckTreePicker.js +29 -17
  65. package/esm/CheckTreePicker/utils.d.ts +3 -3
  66. package/esm/CheckTreePicker/utils.js +3 -3
  67. package/esm/DOMHelper/index.d.ts +4 -4
  68. package/esm/DatePicker/DatePicker.d.ts +2 -1
  69. package/esm/DatePicker/DatePicker.js +19 -12
  70. package/esm/DateRangePicker/DateRangePicker.d.ts +2 -2
  71. package/esm/DateRangePicker/DateRangePicker.js +5 -4
  72. package/esm/IconButton/IconButton.d.ts +5 -2
  73. package/esm/IconButton/IconButton.js +1 -1
  74. package/esm/IconButton/test/IconButton.test.d.ts +1 -0
  75. package/esm/IconButton/test/IconButton.test.js +18 -0
  76. package/esm/InputPicker/InputAutosize.js +3 -1
  77. package/esm/InputPicker/InputPicker.js +6 -2
  78. package/esm/List/ListItem.js +13 -11
  79. package/esm/List/helper/AutoScroller.d.ts +2 -3
  80. package/esm/List/helper/useManager.d.ts +2 -2
  81. package/esm/List/helper/useSortHelper.js +23 -9
  82. package/esm/List/helper/utils.d.ts +4 -3
  83. package/esm/List/helper/utils.js +2 -2
  84. package/esm/MaskedInput/conformToMask.js +1 -0
  85. package/esm/Menu/MenuItem.js +14 -11
  86. package/esm/MultiCascader/DropdownMenu.js +2 -1
  87. package/esm/MultiCascader/utils.js +7 -7
  88. package/esm/Overlay/Position.js +1 -2
  89. package/esm/Pagination/PaginationGroup.js +3 -3
  90. package/esm/Picker/PickerOverlay.js +4 -1
  91. package/esm/Picker/SelectedElement.js +1 -1
  92. package/esm/Picker/index.d.ts +2 -1
  93. package/esm/Ripple/Ripple.js +17 -9
  94. package/esm/TreePicker/TreePicker.js +16 -12
  95. package/esm/Uploader/UploadTrigger.js +3 -1
  96. package/esm/Uploader/Uploader.js +8 -2
  97. package/esm/toaster/toaster.d.ts +1 -1
  98. package/esm/toaster/toaster.js +9 -3
  99. package/esm/utils/treeUtils.d.ts +3 -3
  100. package/esm/utils/treeUtils.js +6 -4
  101. package/esm/utils/useElementResize.d.ts +1 -1
  102. package/esm/utils/useElementResize.js +5 -2
  103. package/esm/utils/useTimeout.d.ts +2 -2
  104. package/esm/utils/useTimeout.js +17 -8
  105. package/package.json +3 -3
@@ -1,8 +1,8 @@
1
- import { Offset } from '../../@types/common';
1
+ import type { EdgeOffset } from './utils';
2
2
  export declare type Collection = string | number;
3
3
  export interface ManagedItem {
4
4
  node: HTMLElement;
5
- edgeOffset: Offset | null;
5
+ edgeOffset: Partial<EdgeOffset> | null;
6
6
  info: {
7
7
  collection: Collection;
8
8
  index?: number;
@@ -112,11 +112,17 @@ var useSortHelper = function useSortHelper(config) {
112
112
  x: offset.x - mouseDownEvent.pageX,
113
113
  y: offset.y - mouseDownEvent.pageY
114
114
  };
115
- setTranslate3d(activeNodeHelper, activeNodeHolderTranslate); // animate
115
+
116
+ if (activeNodeHelper) {
117
+ setTranslate3d(activeNodeHelper, activeNodeHolderTranslate);
118
+ } // animate
119
+
116
120
 
117
121
  activeNodeNextIndex = -1;
118
122
  var listItemManagerRefs = getOrderedItems(curManagedItem.info.collection);
119
- var sortingOffsetY = activeNodeOffsetEdge.top + activeNodeHolderTranslate.y + containerScrollDelta.top;
123
+ var aTop = activeNodeOffsetEdge.top || 0;
124
+ var cTop = containerScrollDelta.top || 0;
125
+ var sortingOffsetY = aTop + activeNodeHolderTranslate.y + cTop;
120
126
  var activeNodeHeight = parseFloat(activeNodeStyle.height) || 0;
121
127
 
122
128
  for (var i = 0, len = listItemManagerRefs.length; i < len; i++) {
@@ -149,14 +155,16 @@ var useSortHelper = function useSortHelper(config) {
149
155
  continue;
150
156
  }
151
157
 
152
- if (prvNode && currentNodeIndex > activeNodeOldIndex && sortingOffsetY + offsetY >= curEdgeOffset.top) {
158
+ var curEdgeOffsetTop = curEdgeOffset.top || 0;
159
+
160
+ if (prvNode && currentNodeIndex > activeNodeOldIndex && sortingOffsetY + offsetY >= curEdgeOffsetTop) {
153
161
  translate.y = -activeNodeHeight;
154
162
  animatedNodesOffset[currentNodeIndex] = {
155
163
  x: 0,
156
164
  y: currentNode.offsetHeight
157
165
  };
158
166
  activeNodeNextIndex = currentNodeIndex;
159
- } else if (nextNode && currentNodeIndex < activeNodeOldIndex && sortingOffsetY <= curEdgeOffset.top + offsetY) {
167
+ } else if (nextNode && currentNodeIndex < activeNodeOldIndex && sortingOffsetY <= curEdgeOffsetTop + offsetY) {
160
168
  translate.y = activeNodeHeight;
161
169
  animatedNodesOffset[currentNodeIndex] = {
162
170
  x: 0,
@@ -190,9 +198,11 @@ var useSortHelper = function useSortHelper(config) {
190
198
  height: activeNodeBoundingClientRect.height,
191
199
  translate: activeNodeHolderTranslate,
192
200
  maxTranslate: {
201
+ x: 0,
193
202
  y: containerBoundingRect.top + containerBoundingRect.height - activeNodeBoundingClientRect.top - activeNodeBoundingClientRect.height / 2
194
203
  },
195
204
  minTranslate: {
205
+ x: 0,
196
206
  y: containerBoundingRect.top - activeNodeBoundingClientRect.top - activeNodeBoundingClientRect.height / 2
197
207
  }
198
208
  });
@@ -213,11 +223,15 @@ var useSortHelper = function useSortHelper(config) {
213
223
  sortMouseEndListener.off();
214
224
  var holderTranslate = getHolderTranslate();
215
225
  var containerScrollDelta = getContainerScrollDelta();
216
- setTranslate3d(activeNodeHelper, {
217
- x: holderTranslate.x - containerScrollDelta.left,
218
- y: holderTranslate.y - containerScrollDelta.top
219
- });
220
- setTransitionDuration(activeNodeHelper, transitionDuration); // wait for animation
226
+
227
+ if (activeNodeHelper) {
228
+ setTranslate3d(activeNodeHelper, {
229
+ x: holderTranslate.x - (containerScrollDelta.left || 0),
230
+ y: holderTranslate.y - (containerScrollDelta.top || 0)
231
+ });
232
+ setTransitionDuration(activeNodeHelper, transitionDuration);
233
+ } // wait for animation
234
+
221
235
 
222
236
  setTimeout(function () {
223
237
  var _activeNodeHelper2, _activeNodeHelper2$pa;
@@ -1,9 +1,10 @@
1
1
  import { CSSProperties } from 'react';
2
2
  import { Offset } from '../../@types/common';
3
3
  export interface Axis {
4
- x?: number;
5
- y?: number;
4
+ x: number;
5
+ y: number;
6
6
  }
7
+ export declare type EdgeOffset = Omit<Offset, 'width' | 'height'>;
7
8
  export declare function isContainInteractiveElement(targetNode: HTMLElement): boolean;
8
9
  export declare function setInlineStyles(node: HTMLElement, styles: CSSProperties): void;
9
10
  export declare function setTranslate3d(node: HTMLElement, translate: Axis | null): void;
@@ -12,5 +13,5 @@ export declare function setTransitionDuration(node: HTMLElement, duration?: numb
12
13
  * find closest target node from source node
13
14
  * */
14
15
  export declare function closestNode(sourceNode: HTMLElement, judge: (target: HTMLElement) => boolean): HTMLElement | null;
15
- export declare function getEdgeOffset(node: HTMLElement, parent: HTMLElement, offset?: Offset): Offset;
16
+ export declare function getEdgeOffset(node: HTMLElement, parent: HTMLElement, offset?: EdgeOffset): Partial<EdgeOffset>;
16
17
  export declare function getScrollingParent(el: HTMLElement): HTMLElement | null;
@@ -56,8 +56,8 @@ export function getEdgeOffset(node, parent, offset) {
56
56
 
57
57
 
58
58
  var nodeOffset = {
59
- left: offset.left + node.offsetLeft,
60
- top: offset.top + node.offsetTop
59
+ left: (offset.left || 0) + node.offsetLeft,
60
+ top: (offset.top || 0) + node.offsetTop
61
61
  };
62
62
 
63
63
  if (node.parentNode === parent) {
@@ -123,6 +123,7 @@ export default function conformToMask(rawValue, mask, config) {
123
123
  // or we find at least one character that we can map.
124
124
  while (rawValueArr.length > 0) {
125
125
  // Let's retrieve the first user character in the queue of characters we have left
126
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
126
127
  var _ref = rawValueArr.shift(),
127
128
  rawValueChar = _ref.char,
128
129
  isNew = _ref.isNew; // If the character we got from the user input is a placeholder character (which happens
@@ -61,19 +61,22 @@ function MenuItem(props) {
61
61
  }, [dispatch]);
62
62
  useEffect(function () {
63
63
  var menuitemElement = menuitemRef.current;
64
- dispatch({
65
- type: MenuActionTypes.RegisterItem,
66
- element: menuitemElement,
67
- props: {
68
- disabled: disabled
69
- }
70
- });
71
- return function () {
64
+
65
+ if (menuitemElement) {
72
66
  dispatch({
73
- type: MenuActionTypes.UnregisterItem,
74
- id: menuitemElement.id
67
+ type: MenuActionTypes.RegisterItem,
68
+ element: menuitemElement,
69
+ props: {
70
+ disabled: disabled
71
+ }
75
72
  });
76
- };
73
+ return function () {
74
+ dispatch({
75
+ type: MenuActionTypes.UnregisterItem,
76
+ id: menuitemElement.id
77
+ });
78
+ };
79
+ }
77
80
  }, [menuitemRef, disabled, dispatch]);
78
81
  var menuitemProps = {
79
82
  id: menuitemId,
@@ -16,7 +16,8 @@ var emptyArray = [];
16
16
  var DropdownMenu = /*#__PURE__*/React.forwardRef(function (props, ref) {
17
17
  var _props$as = props.as,
18
18
  Component = _props$as === void 0 ? 'div' : _props$as,
19
- classPrefix = props.classPrefix,
19
+ _props$classPrefix = props.classPrefix,
20
+ classPrefix = _props$classPrefix === void 0 ? 'menu' : _props$classPrefix,
20
21
  className = props.className,
21
22
  cascade = props.cascade,
22
23
  _props$cascadeData = props.cascadeData,
@@ -265,21 +265,21 @@ export function useCascadeValue(props, flattenData) {
265
265
  removedValue = removedValue.concat(removeAllChildrenValue(nextValue, item, {
266
266
  valueKey: valueKey,
267
267
  childrenKey: childrenKey
268
- })); // Traverse all ancestor nodes of the current node
268
+ }) || []); // Traverse all ancestor nodes of the current node
269
269
  // Then determine whether all the child nodes of these nodes are selected, and then they themselves must be selected
270
270
 
271
271
  var _loop = function _loop(i) {
272
272
  // Whether the parent node can be selected
273
- var isCheckableParent = !uncheckableItemValues.some(function (v) {
273
+ var isCheckableParent = !(uncheckableItemValues !== null && uncheckableItemValues !== void 0 && uncheckableItemValues.some(function (v) {
274
274
  return v === parents[i][valueKey];
275
- });
275
+ }));
276
276
 
277
277
  if (isCheckableParent) {
278
278
  var isCheckAll = parents[i][childrenKey] // Filter out options that are marked as not selectable
279
279
  .filter(function (n) {
280
- return !uncheckableItemValues.some(function (v) {
280
+ return !(uncheckableItemValues !== null && uncheckableItemValues !== void 0 && uncheckableItemValues.some(function (v) {
281
281
  return v === n[valueKey];
282
- });
282
+ }));
283
283
  }) // Check if all nodes are selected
284
284
  .every(function (n) {
285
285
  return nextValue.some(function (v) {
@@ -294,7 +294,7 @@ export function useCascadeValue(props, flattenData) {
294
294
  removedValue = removedValue.concat(removeAllChildrenValue(nextValue, parents[i], {
295
295
  valueKey: valueKey,
296
296
  childrenKey: childrenKey
297
- }));
297
+ }) || []);
298
298
  }
299
299
  }
300
300
  };
@@ -377,7 +377,7 @@ export function useCascadeValue(props, flattenData) {
377
377
  });
378
378
 
379
379
  if (item !== null && item !== void 0 && item.parent && nextValue.some(function (v) {
380
- return v === item.parent[valueKey];
380
+ return v === item.parent && item.parent[valueKey];
381
381
  })) {
382
382
  return false;
383
383
  }
@@ -69,8 +69,7 @@ var usePosition = function usePosition(props, ref) {
69
69
  return;
70
70
  }
71
71
 
72
- var overlay = getDOMNode(ref.current); // fixme dom-lib getContainer incorrect type
73
-
72
+ var overlay = getDOMNode(ref.current);
74
73
  var containerElement = getContainer(typeof container === 'function' ? container() : container !== null && container !== void 0 ? container : null, ownerDocument(ref.current).body);
75
74
  var posi = utils.calcOverlayPosition(overlay, targetElement, containerElement);
76
75
 
@@ -21,7 +21,7 @@ var LimitPicker = function LimitPicker(props) {
21
21
  var formatlimitOptions = limitOptions.map(function (item) {
22
22
  return {
23
23
  value: item,
24
- label: tplTransform(locale.limit, item)
24
+ label: locale.limit && tplTransform(locale.limit, item)
25
25
  };
26
26
  });
27
27
  return /*#__PURE__*/React.createElement("div", {
@@ -143,12 +143,12 @@ var PaginationGroup = /*#__PURE__*/React.forwardRef(function (props, ref) {
143
143
  return /*#__PURE__*/React.createElement("div", {
144
144
  key: onlyKey,
145
145
  className: prefix('total')
146
- }, tplTransform(locale.total, total));
146
+ }, locale.total && tplTransform(locale.total, total));
147
147
  } else if (key === 'skip') {
148
148
  return /*#__PURE__*/React.createElement("div", {
149
149
  key: onlyKey,
150
150
  className: classNames(prefix('skip'))
151
- }, tplTransform(locale.skip, /*#__PURE__*/React.createElement(Input, {
151
+ }, locale.skip && tplTransform(locale.skip, /*#__PURE__*/React.createElement(Input, {
152
152
  size: size,
153
153
  onBlur: handleInputBlur,
154
154
  onPressEnter: handleInputPressEnter
@@ -37,7 +37,10 @@ var PickerOverlay = /*#__PURE__*/React.forwardRef(function (props, ref) {
37
37
  // Get the width value of the button,
38
38
  // and then set it to the menu to make their width consistent.
39
39
  var width = getWidth(getDOMNode(toggle.root));
40
- addStyle(overlayRef.current, 'min-width', width + "px");
40
+
41
+ if (overlayRef.current) {
42
+ addStyle(overlayRef.current, 'min-width', width + "px");
43
+ }
41
44
  }
42
45
  }, [autoWidth, target, overlayRef]);
43
46
 
@@ -37,7 +37,7 @@ var SelectedElement = function SelectedElement(props) {
37
37
  key: item[valueKey]
38
38
  }, /*#__PURE__*/React.createElement("span", {
39
39
  className: prefix('value-item')
40
- }, item[labelKey], checkAll ? " (" + locale.checkAll + ")" : ''), index === count - 1 ? null : /*#__PURE__*/React.createElement("span", {
40
+ }, item[labelKey], checkAll && locale !== null && locale !== void 0 && locale.checkAll ? " (" + locale.checkAll + ")" : ''), index === count - 1 ? null : /*#__PURE__*/React.createElement("span", {
41
41
  className: prefix('value-separator')
42
42
  }, ","));
43
43
  })), countable ? /*#__PURE__*/React.createElement("span", {
@@ -1,4 +1,5 @@
1
1
  import { pickTriggerPropKeys, omitTriggerPropKeys, OverlayTriggerInstance, PositionChildProps } from './PickerToggleTrigger';
2
+ import { PickerToggleProps } from './PickerToggle';
2
3
  import { PickerInstance, PickerComponent } from './types';
3
4
  export { default as DropdownMenu } from './DropdownMenu';
4
5
  export { default as DropdownMenuCheckItem } from './DropdownMenuCheckItem';
@@ -10,6 +11,6 @@ export { default as PickerToggleTrigger } from './PickerToggleTrigger';
10
11
  export { default as SearchBar } from './SearchBar';
11
12
  export { default as SelectedElement } from './SelectedElement';
12
13
  export { pickTriggerPropKeys, omitTriggerPropKeys };
13
- export type { OverlayTriggerInstance, PositionChildProps, PickerInstance, PickerComponent };
14
+ export type { OverlayTriggerInstance, PositionChildProps, PickerInstance, PickerComponent, PickerToggleProps };
14
15
  export * from './utils';
15
16
  export * from './propTypes';
@@ -52,17 +52,25 @@ var Ripple = /*#__PURE__*/React.forwardRef(function (props, ref) {
52
52
  };
53
53
 
54
54
  var handleMouseDown = useCallback(function (event) {
55
- var position = getPosition(triggerRef.current, event);
56
- setRippling(true);
57
- setPosition(position);
58
- onMouseDown === null || onMouseDown === void 0 ? void 0 : onMouseDown(position, event);
55
+ if (triggerRef.current) {
56
+ var _position = getPosition(triggerRef.current, event);
57
+
58
+ setRippling(true);
59
+ setPosition(_position);
60
+ onMouseDown === null || onMouseDown === void 0 ? void 0 : onMouseDown(_position, event);
61
+ }
59
62
  }, [onMouseDown]);
60
63
  useEffect(function () {
61
- var parentNode = triggerRef.current.parentNode;
62
- var mousedownListener = on(parentNode, 'mousedown', handleMouseDown);
63
- return function () {
64
- mousedownListener === null || mousedownListener === void 0 ? void 0 : mousedownListener.off();
65
- };
64
+ var _triggerRef$current;
65
+
66
+ var parentNode = (_triggerRef$current = triggerRef.current) === null || _triggerRef$current === void 0 ? void 0 : _triggerRef$current.parentNode;
67
+
68
+ if (parentNode) {
69
+ var mousedownListener = on(parentNode, 'mousedown', handleMouseDown);
70
+ return function () {
71
+ mousedownListener === null || mousedownListener === void 0 ? void 0 : mousedownListener.off();
72
+ };
73
+ }
66
74
  }, [handleMouseDown]);
67
75
  return /*#__PURE__*/React.createElement(Component, _extends({}, rest, {
68
76
  className: classes,
@@ -58,11 +58,13 @@ var TreePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
58
58
  _props$childrenKey = props.childrenKey,
59
59
  childrenKey = _props$childrenKey === void 0 ? 'children' : _props$childrenKey,
60
60
  draggable = props.draggable,
61
- defaultExpandAll = props.defaultExpandAll,
61
+ _props$defaultExpandA = props.defaultExpandAll,
62
+ defaultExpandAll = _props$defaultExpandA === void 0 ? false : _props$defaultExpandA,
62
63
  _props$disabledItemVa = props.disabledItemValues,
63
64
  disabledItemValues = _props$disabledItemVa === void 0 ? emptyArray : _props$disabledItemVa,
64
65
  controlledExpandItemValues = props.expandItemValues,
65
- defaultExpandItemValues = props.defaultExpandItemValues,
66
+ _props$defaultExpandI = props.defaultExpandItemValues,
67
+ defaultExpandItemValues = _props$defaultExpandI === void 0 ? emptyArray : _props$defaultExpandI,
66
68
  id = props.id,
67
69
  listProps = props.listProps,
68
70
  getChildren = props.getChildren,
@@ -198,15 +200,17 @@ var TreePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
198
200
  });
199
201
  }, [searchKeywordState, expandItemValues, filteredData, flattenNodes, formatVirtualizedTreeData, virtualized]);
200
202
  var focusActiveNode = useCallback(function () {
201
- focusToActiveTreeNode({
202
- list: listRef.current,
203
- valueKey: valueKey,
204
- selector: "." + treePrefix('node-active'),
205
- activeNode: activeNode,
206
- virtualized: virtualized,
207
- container: treeViewRef.current,
208
- formattedNodes: getFormattedNodes()
209
- });
203
+ if (listRef.current) {
204
+ focusToActiveTreeNode({
205
+ list: listRef.current,
206
+ valueKey: valueKey,
207
+ selector: "." + treePrefix('node-active'),
208
+ activeNode: activeNode,
209
+ virtualized: virtualized,
210
+ container: treeViewRef.current,
211
+ formattedNodes: getFormattedNodes()
212
+ });
213
+ }
210
214
  }, [treePrefix, activeNode, getFormattedNodes, valueKey, virtualized]);
211
215
  useEffect(function () {
212
216
  setFilteredData(data, searchKeywordState);
@@ -680,7 +684,7 @@ var TreePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
680
684
  var node = activeNode !== null && activeNode !== void 0 ? activeNode : {};
681
685
  selectedElement = node[labelKey];
682
686
 
683
- if (_isFunction(renderValue)) {
687
+ if (_isFunction(renderValue) && value) {
684
688
  selectedElement = renderValue(value, node, selectedElement);
685
689
 
686
690
  if (_isNil(selectedElement)) {
@@ -56,7 +56,9 @@ var UploadTrigger = /*#__PURE__*/React.forwardRef(function (props, ref) {
56
56
  (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.click();
57
57
  }, []);
58
58
  var handleClearInput = useCallback(function () {
59
- inputRef.current.value = '';
59
+ if (inputRef.current) {
60
+ inputRef.current.value = '';
61
+ }
60
62
  }, []);
61
63
  var handleDragEnter = useCallback(function (event) {
62
64
  if (draggable) {
@@ -188,7 +188,9 @@ var Uploader = /*#__PURE__*/React.forwardRef(function (props, ref) {
188
188
  */
189
189
 
190
190
  var cleanInputValue = useCallback(function () {
191
- trigger.current.clearInput();
191
+ var _trigger$current;
192
+
193
+ (_trigger$current = trigger.current) === null || _trigger$current === void 0 ? void 0 : _trigger$current.clearInput();
192
194
  }, []);
193
195
  /**
194
196
  * Callback for successful file upload.
@@ -265,7 +267,11 @@ var Uploader = /*#__PURE__*/React.forwardRef(function (props, ref) {
265
267
  updateFileStatus(_extends({}, file, {
266
268
  status: 'uploading'
267
269
  }));
268
- xhrs.current[file.fileKey] = xhr;
270
+
271
+ if (file.fileKey) {
272
+ xhrs.current[file.fileKey] = xhr;
273
+ }
274
+
269
275
  onUpload === null || onUpload === void 0 ? void 0 : onUpload(file, uploadData, xhr);
270
276
  }, [action, data, handleAjaxUploadError, handleAjaxUploadProgress, handleAjaxUploadSuccess, headers, name, onUpload, timeout, updateFileStatus, withCredentials, disableMultipart]);
271
277
  var handleAjaxUpload = useCallback(function () {
@@ -8,7 +8,7 @@ export interface Toaster {
8
8
  * @param message
9
9
  * @param options
10
10
  */
11
- push(message: React.ReactNode, options?: ToastContainerProps): string;
11
+ push(message: React.ReactNode, options?: ToastContainerProps): string | undefined;
12
12
  /**
13
13
  * Remove a message by key
14
14
  * @param key
@@ -33,6 +33,8 @@ var toaster = function toaster(message) {
33
33
  };
34
34
 
35
35
  toaster.push = function (message, options) {
36
+ var _container$current;
37
+
36
38
  if (options === void 0) {
37
39
  options = {};
38
40
  }
@@ -45,18 +47,22 @@ toaster.push = function (message, options) {
45
47
  container = createContainer((_options$placement = options.placement) !== null && _options$placement !== void 0 ? _options$placement : '', options);
46
48
  }
47
49
 
48
- return container.current.push(message);
50
+ return (_container$current = container.current) === null || _container$current === void 0 ? void 0 : _container$current.push(message);
49
51
  };
50
52
 
51
53
  toaster.remove = function (key) {
52
54
  containers.forEach(function (c) {
53
- return c.current.remove(key);
55
+ var _c$current;
56
+
57
+ return (_c$current = c.current) === null || _c$current === void 0 ? void 0 : _c$current.remove(key);
54
58
  });
55
59
  };
56
60
 
57
61
  toaster.clear = function () {
58
62
  containers.forEach(function (c) {
59
- return c.current.clear();
63
+ var _c$current2;
64
+
65
+ return (_c$current2 = c.current) === null || _c$current2 === void 0 ? void 0 : _c$current2.clear();
60
66
  });
61
67
  };
62
68
 
@@ -38,7 +38,7 @@ export declare function hasVisibleChildren(node: TreeNodeType, childrenKey: stri
38
38
  * @param b
39
39
  */
40
40
  export declare function compareArray(a: any[], b: any[]): boolean;
41
- export declare function getDefaultExpandItemValues(data: ItemDataType[], props: Pick<TreePickerProps, 'defaultExpandAll' | 'valueKey' | 'childrenKey' | 'defaultExpandItemValues'>): any[];
41
+ export declare function getDefaultExpandItemValues(data: ItemDataType[], props: Required<Pick<TreePickerProps, 'defaultExpandAll' | 'valueKey' | 'childrenKey' | 'defaultExpandItemValues'>>): any[];
42
42
  /**
43
43
  * 获取 expandItemValues 的 value
44
44
  * @param props
@@ -70,7 +70,7 @@ export declare function filterNodesOfTree(data: any, check: any): TreeNodeType[]
70
70
  * @param isSearching - component is in Searching
71
71
  * @returns
72
72
  */
73
- export declare const getFocusableItems: (filteredData: ItemDataType[], props: PartialTreeProps, isSearching?: boolean | undefined) => TreeNodeType[];
73
+ export declare const getFocusableItems: (filteredData: ItemDataType[], props: Required<Pick<PartialTreeProps, 'disabledItemValues' | 'valueKey' | 'childrenKey' | 'expandItemValues'>>, isSearching?: boolean | undefined) => TreeNodeType[];
74
74
  /**
75
75
  * return all focusable Item and active Element index
76
76
  * @param focusItemValue
@@ -235,7 +235,7 @@ export interface FocusToTreeNodeProps {
235
235
  valueKey: string;
236
236
  activeNode: any;
237
237
  virtualized: boolean;
238
- container: HTMLDivElement;
238
+ container: HTMLElement | null;
239
239
  list: ListInstance;
240
240
  formattedNodes: TreeNodeType[];
241
241
  }
@@ -109,11 +109,13 @@ export function getNodeParentKeys(nodes, node, valueKey) {
109
109
  var parentKeys = [];
110
110
 
111
111
  var traverse = function traverse(node) {
112
- if (node !== null && node !== void 0 && node.parent) {
113
- var _node$parent;
112
+ var _node$parent;
113
+
114
+ if (node !== null && node !== void 0 && (_node$parent = node.parent) !== null && _node$parent !== void 0 && _node$parent.refKey) {
115
+ var _node$parent2;
114
116
 
115
117
  traverse(nodes[node.parent.refKey]);
116
- parentKeys.push(node === null || node === void 0 ? void 0 : (_node$parent = node.parent) === null || _node$parent === void 0 ? void 0 : _node$parent[valueKey]);
118
+ parentKeys.push(node === null || node === void 0 ? void 0 : (_node$parent2 = node.parent) === null || _node$parent2 === void 0 ? void 0 : _node$parent2[valueKey]);
117
119
  }
118
120
  };
119
121
 
@@ -629,7 +631,7 @@ export function getChildrenByFlattenNodes(nodes, parent) {
629
631
  return Object.values(nodes).filter(function (item) {
630
632
  var _item$parent;
631
633
 
632
- return (item === null || item === void 0 ? void 0 : (_item$parent = item.parent) === null || _item$parent === void 0 ? void 0 : _item$parent.refKey) === parent.refKey && !nodes[item.refKey].uncheckable;
634
+ 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;
633
635
  });
634
636
  }
635
637
  export function useTreeDrag() {
@@ -5,4 +5,4 @@
5
5
  * @param eventTarget The target to listen for events on
6
6
  * @param listener An event handler
7
7
  */
8
- export default function useElementResize(eventTarget: Element | (() => Element), listener: ResizeObserverCallback): void;
8
+ export default function useElementResize(eventTarget: Element | null | (() => Element | null), listener: ResizeObserverCallback): void;
@@ -13,8 +13,11 @@ export default function useElementResize(eventTarget, listener) {
13
13
  useEffect(function () {
14
14
  if (!resizeObserver.current) {
15
15
  var target = typeof eventTarget === 'function' ? eventTarget() : eventTarget;
16
- resizeObserver.current = new ResizeObserver(listener);
17
- resizeObserver.current.observe(target);
16
+
17
+ if (target) {
18
+ resizeObserver.current = new ResizeObserver(listener);
19
+ resizeObserver.current.observe(target);
20
+ }
18
21
  }
19
22
 
20
23
  return function () {
@@ -6,7 +6,7 @@ export interface UseTimeoutFnReturn {
6
6
  * A timer hook
7
7
  * @param fn Timer callback function
8
8
  * @param ms Milliseconds of the timer
9
- * @param open Whether to open the timer
9
+ * @param enabled Whether to open the timer
10
10
  */
11
- declare function useTimeout(fn: (() => void) | undefined, ms?: number, open?: boolean): UseTimeoutFnReturn;
11
+ declare function useTimeout(fn: (() => void) | undefined, ms?: number, enabled?: boolean): UseTimeoutFnReturn;
12
12
  export default useTimeout;
@@ -4,32 +4,41 @@ import { useEffect, useRef, useCallback } from 'react';
4
4
  * A timer hook
5
5
  * @param fn Timer callback function
6
6
  * @param ms Milliseconds of the timer
7
- * @param open Whether to open the timer
7
+ * @param enabled Whether to open the timer
8
8
  */
9
- function useTimeout(fn, ms, open) {
9
+ function useTimeout(fn, ms, enabled) {
10
10
  if (ms === void 0) {
11
11
  ms = 0;
12
12
  }
13
13
 
14
- if (open === void 0) {
15
- open = true;
14
+ if (enabled === void 0) {
15
+ enabled = true;
16
16
  }
17
17
 
18
18
  var timeout = useRef();
19
+ var callback = useRef(fn);
19
20
  var clear = useCallback(function () {
20
21
  timeout.current && clearTimeout(timeout.current);
21
22
  }, []);
22
23
  var set = useCallback(function () {
23
- if (open) {
24
+ timeout.current && clearTimeout(timeout.current);
25
+
26
+ if (enabled) {
24
27
  timeout.current = setTimeout(function () {
25
- return fn === null || fn === void 0 ? void 0 : fn();
28
+ var _callback$current;
29
+
30
+ (_callback$current = callback.current) === null || _callback$current === void 0 ? void 0 : _callback$current.call(callback);
26
31
  }, ms);
27
32
  }
28
- }, [ms, fn, open]);
33
+ }, [ms, enabled]); // update ref when function changes
34
+
35
+ useEffect(function () {
36
+ callback.current = fn;
37
+ }, [fn]);
29
38
  useEffect(function () {
30
39
  set();
31
40
  return clear;
32
- }, [fn, ms, open, clear, set]);
41
+ }, [ms, enabled, set, clear]);
33
42
  return {
34
43
  clear: clear,
35
44
  reset: set
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rsuite",
3
- "version": "5.5.2",
3
+ "version": "5.6.2",
4
4
  "description": "A suite of react components",
5
5
  "main": "cjs/index.js",
6
6
  "module": "esm/index.js",
@@ -33,11 +33,11 @@
33
33
  "@types/react-virtualized": "^9.21.11",
34
34
  "classnames": "^2.3.1",
35
35
  "date-fns": "^2.13.0",
36
- "dom-lib": "^3.0.0",
36
+ "dom-lib": "^3.1.2",
37
37
  "lodash": "^4.17.11",
38
38
  "prop-types": "^15.7.2",
39
39
  "react-virtualized": "^9.22.3",
40
- "rsuite-table": "^5.3.2",
40
+ "rsuite-table": "^5.3.3",
41
41
  "schema-typed": "^2.0.2"
42
42
  },
43
43
  "peerDependencies": {