@hi-ui/table 4.4.0-alpha.3 → 4.4.0-alpha.4

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.
@@ -103,7 +103,10 @@ var useColWidth = function useColWidth(_ref) {
103
103
  }
104
104
  }, [getVirtualWidths, virtual]);
105
105
  useUpdateEffect.useUpdateEffect(function () {
106
- setColWidths(getWidths(measureRowElementRef.current));
106
+ setColWidths(function (prev) {
107
+ var _a;
108
+ return ((_a = measureRowElementRef.current) === null || _a === void 0 ? void 0 : _a.childNodes.length) === prev.length ? getWidths(measureRowElementRef.current) : index.getGroupItemWidth(columns);
109
+ });
107
110
  }, [columns]);
108
111
  /**
109
112
  * 根据实际内容区(table 的第一行)渲染,再次精确收集并设置每列宽度
@@ -85,6 +85,17 @@ function _iterableToArrayLimit(arr, i) {
85
85
  function _arrayWithHoles(arr) {
86
86
  if (Array.isArray(arr)) return arr;
87
87
  }
88
+
89
+ /**
90
+ * To get exact height to avoid scrolling deviation
91
+ */
92
+ function getOuterHeight(el) {
93
+ var height = el.offsetHeight;
94
+ var computedStyle = window.getComputedStyle(el);
95
+ height += parseInt(computedStyle.marginTop, 10);
96
+ height += parseInt(computedStyle.marginBottom, 10);
97
+ return height;
98
+ }
88
99
  function useHeights(getKey, onItemAdd, onItemRemove) {
89
100
  var _React$useState = React__namespace.useState(0),
90
101
  _React$useState2 = _slicedToArray(_React$useState, 2),
@@ -102,9 +113,9 @@ function useHeights(getKey, onItemAdd, onItemRemove) {
102
113
  instanceRef.current.forEach(function (element, key) {
103
114
  if (element && element.offsetParent) {
104
115
  var htmlElement = findDOMNode["default"](element);
105
- var offsetHeight = htmlElement.offsetHeight;
106
- if (heightsRef.current.get(key) !== offsetHeight) {
107
- heightsRef.current.set(key, htmlElement.offsetHeight);
116
+ var outerHeight = getOuterHeight(htmlElement);
117
+ if (heightsRef.current.get(key) !== outerHeight) {
118
+ heightsRef.current.set(key, outerHeight);
108
119
  }
109
120
  }
110
121
  }); // Always trigger update mark to tell parent that should re-calculate heights when resized
@@ -91,7 +91,10 @@ var useColWidth = function useColWidth(_ref) {
91
91
  }
92
92
  }, [getVirtualWidths, virtual]);
93
93
  useUpdateEffect(function () {
94
- setColWidths(getWidths(measureRowElementRef.current));
94
+ setColWidths(function (prev) {
95
+ var _a;
96
+ return ((_a = measureRowElementRef.current) === null || _a === void 0 ? void 0 : _a.childNodes.length) === prev.length ? getWidths(measureRowElementRef.current) : getGroupItemWidth(columns);
97
+ });
95
98
  }, [columns]);
96
99
  /**
97
100
  * 根据实际内容区(table 的第一行)渲染,再次精确收集并设置每列宽度
@@ -60,6 +60,17 @@ function _iterableToArrayLimit(arr, i) {
60
60
  function _arrayWithHoles(arr) {
61
61
  if (Array.isArray(arr)) return arr;
62
62
  }
63
+
64
+ /**
65
+ * To get exact height to avoid scrolling deviation
66
+ */
67
+ function getOuterHeight(el) {
68
+ var height = el.offsetHeight;
69
+ var computedStyle = window.getComputedStyle(el);
70
+ height += parseInt(computedStyle.marginTop, 10);
71
+ height += parseInt(computedStyle.marginBottom, 10);
72
+ return height;
73
+ }
63
74
  function useHeights(getKey, onItemAdd, onItemRemove) {
64
75
  var _React$useState = React.useState(0),
65
76
  _React$useState2 = _slicedToArray(_React$useState, 2),
@@ -77,9 +88,9 @@ function useHeights(getKey, onItemAdd, onItemRemove) {
77
88
  instanceRef.current.forEach(function (element, key) {
78
89
  if (element && element.offsetParent) {
79
90
  var htmlElement = findDOMNode(element);
80
- var offsetHeight = htmlElement.offsetHeight;
81
- if (heightsRef.current.get(key) !== offsetHeight) {
82
- heightsRef.current.set(key, htmlElement.offsetHeight);
91
+ var outerHeight = getOuterHeight(htmlElement);
92
+ if (heightsRef.current.get(key) !== outerHeight) {
93
+ heightsRef.current.set(key, outerHeight);
83
94
  }
84
95
  }
85
96
  }); // Always trigger update mark to tell parent that should re-calculate heights when resized
@@ -41,7 +41,7 @@ export declare const TableProvider: import("react").Provider<(Omit<{
41
41
  showColMenu: boolean | undefined;
42
42
  onLoadChildren: ((item: import("./types").TableRowEventData) => void | Promise<void | any[]>) | undefined;
43
43
  setHeaderTableElement: import("react").Dispatch<import("react").SetStateAction<HTMLTableRowElement | null>>;
44
- scrollbar: boolean | import("@hi-ui/scrollbar").ScrollbarProps | undefined;
44
+ scrollbar: boolean | import("packages/ui/scrollbar/lib/types").ScrollbarProps | undefined;
45
45
  rowClassName: ((record: Record<string, any>, index: number) => string) | undefined;
46
46
  cellClassName: ((record: Record<string, any>, column: Record<string, any>, index: number) => string) | undefined;
47
47
  scrollLeft: number;
@@ -151,7 +151,7 @@ export declare const useTableContext: () => Omit<{
151
151
  showColMenu: boolean | undefined;
152
152
  onLoadChildren: ((item: import("./types").TableRowEventData) => void | Promise<void | any[]>) | undefined;
153
153
  setHeaderTableElement: import("react").Dispatch<import("react").SetStateAction<HTMLTableRowElement | null>>;
154
- scrollbar: boolean | import("@hi-ui/scrollbar").ScrollbarProps | undefined;
154
+ scrollbar: boolean | import("packages/ui/scrollbar/lib/types").ScrollbarProps | undefined;
155
155
  rowClassName: ((record: Record<string, any>, index: number) => string) | undefined;
156
156
  cellClassName: ((record: Record<string, any>, column: Record<string, any>, index: number) => string) | undefined;
157
157
  scrollLeft: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hi-ui/table",
3
- "version": "4.4.0-alpha.3",
3
+ "version": "4.4.0-alpha.4",
4
4
  "description": "A sub-package for @hi-ui/hiui.",
5
5
  "keywords": [],
6
6
  "author": "HiUI <mi-hiui@xiaomi.com>",