@hi-ui/table 4.6.0 → 4.7.0-alpha.0

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.
@@ -25,7 +25,8 @@ var React__default = /*#__PURE__*/_interopDefaultCompat(React);
25
25
  var useColWidth = function useColWidth(_ref) {
26
26
  var resizable = _ref.resizable,
27
27
  columns = _ref.columns,
28
- virtual = _ref.virtual;
28
+ virtual = _ref.virtual,
29
+ onResize = _ref.onResize;
29
30
  var measureRowElementRef = React__default["default"].useRef(null);
30
31
  // 是否重新设置过表格每列宽度
31
32
  var hasResetWidths = React__default["default"].useRef(false);
@@ -194,7 +195,7 @@ var useColWidth = function useColWidth(_ref) {
194
195
  /**
195
196
  * 列宽拖拽 resize,只处理拖拽线两边的列宽度
196
197
  */
197
- var onColumnResizable = React__default["default"].useCallback(function (_, _ref3, index) {
198
+ var onColumnResizable = React__default["default"].useCallback(function (evt, _ref3, index) {
198
199
  var size = _ref3.size;
199
200
  var minWidth = minColWidth[index];
200
201
  var anotherMinWidth = minColWidth[index + 1];
@@ -208,9 +209,10 @@ var useColWidth = function useColWidth(_ref) {
208
209
  }
209
210
  nextColWidths[index] = nextWidth;
210
211
  nextColWidths[index + 1] = anotherWidth;
212
+ onResize === null || onResize === void 0 ? void 0 : onResize(evt, size, index, nextColWidths);
211
213
  return nextColWidths;
212
214
  });
213
- }, [minColWidth]);
215
+ }, [minColWidth, onResize]);
214
216
  var getColgroupProps = React__default["default"].useCallback(function (column, index) {
215
217
  var width = colWidths[index] || undefined;
216
218
  return {
@@ -91,7 +91,8 @@ var useTable = function useTable(_a) {
91
91
  scrollbar = _a.scrollbar,
92
92
  rowClassName = _a.rowClassName,
93
93
  cellClassName = _a.cellClassName,
94
- rootProps = tslib.__rest(_a, ["data", "columns", "defaultFixedToColumn", "fixedToColumn", "onFixedToColumn", "scrollWidth", "resizable", "errorRowKeys", "highlightedColKeys", "highlightedRowKeys", "showColHighlight", "showRowHighlight", "highlightRowOnDoubleClick", "defaultExpandedRowKeys", "expandedRowKeys", "onExpand", "defaultExpandAll", "onLoadChildren", "maxHeight", "sticky", "stickyTop", "draggable", "onDragStart", "onDrop", "onDropEnd", "showColMenu", "rowSelection", "cellRender", "footerRender", "fieldKey", "virtual", "scrollbar", "rowClassName", "cellClassName"]);
94
+ onResize = _a.onResize,
95
+ rootProps = tslib.__rest(_a, ["data", "columns", "defaultFixedToColumn", "fixedToColumn", "onFixedToColumn", "scrollWidth", "resizable", "errorRowKeys", "highlightedColKeys", "highlightedRowKeys", "showColHighlight", "showRowHighlight", "highlightRowOnDoubleClick", "defaultExpandedRowKeys", "expandedRowKeys", "onExpand", "defaultExpandAll", "onLoadChildren", "maxHeight", "sticky", "stickyTop", "draggable", "onDragStart", "onDrop", "onDropEnd", "showColMenu", "rowSelection", "cellRender", "footerRender", "fieldKey", "virtual", "scrollbar", "rowClassName", "cellClassName", "onResize"]);
95
96
  /**
96
97
  * 获取 key 字段值
97
98
  */
@@ -183,7 +184,8 @@ var useTable = function useTable(_a) {
183
184
  data: data,
184
185
  columns: columns,
185
186
  resizable: resizable,
186
- virtual: virtual
187
+ virtual: virtual,
188
+ onResize: onResize
187
189
  }),
188
190
  measureRowElementRef = _useColWidth.measureRowElementRef,
189
191
  getColgroupProps = _useColWidth.getColgroupProps,
@@ -13,7 +13,8 @@ import { useUpdateEffect } from '@hi-ui/use-update-effect';
13
13
  var useColWidth = function useColWidth(_ref) {
14
14
  var resizable = _ref.resizable,
15
15
  columns = _ref.columns,
16
- virtual = _ref.virtual;
16
+ virtual = _ref.virtual,
17
+ onResize = _ref.onResize;
17
18
  var measureRowElementRef = React__default.useRef(null);
18
19
  // 是否重新设置过表格每列宽度
19
20
  var hasResetWidths = React__default.useRef(false);
@@ -182,7 +183,7 @@ var useColWidth = function useColWidth(_ref) {
182
183
  /**
183
184
  * 列宽拖拽 resize,只处理拖拽线两边的列宽度
184
185
  */
185
- var onColumnResizable = React__default.useCallback(function (_, _ref3, index) {
186
+ var onColumnResizable = React__default.useCallback(function (evt, _ref3, index) {
186
187
  var size = _ref3.size;
187
188
  var minWidth = minColWidth[index];
188
189
  var anotherMinWidth = minColWidth[index + 1];
@@ -196,9 +197,10 @@ var useColWidth = function useColWidth(_ref) {
196
197
  }
197
198
  nextColWidths[index] = nextWidth;
198
199
  nextColWidths[index + 1] = anotherWidth;
200
+ onResize === null || onResize === void 0 ? void 0 : onResize(evt, size, index, nextColWidths);
199
201
  return nextColWidths;
200
202
  });
201
- }, [minColWidth]);
203
+ }, [minColWidth, onResize]);
202
204
  var getColgroupProps = React__default.useCallback(function (column, index) {
203
205
  var width = colWidths[index] || undefined;
204
206
  return {
@@ -79,7 +79,8 @@ var useTable = function useTable(_a) {
79
79
  scrollbar = _a.scrollbar,
80
80
  rowClassName = _a.rowClassName,
81
81
  cellClassName = _a.cellClassName,
82
- rootProps = __rest(_a, ["data", "columns", "defaultFixedToColumn", "fixedToColumn", "onFixedToColumn", "scrollWidth", "resizable", "errorRowKeys", "highlightedColKeys", "highlightedRowKeys", "showColHighlight", "showRowHighlight", "highlightRowOnDoubleClick", "defaultExpandedRowKeys", "expandedRowKeys", "onExpand", "defaultExpandAll", "onLoadChildren", "maxHeight", "sticky", "stickyTop", "draggable", "onDragStart", "onDrop", "onDropEnd", "showColMenu", "rowSelection", "cellRender", "footerRender", "fieldKey", "virtual", "scrollbar", "rowClassName", "cellClassName"]);
82
+ onResize = _a.onResize,
83
+ rootProps = __rest(_a, ["data", "columns", "defaultFixedToColumn", "fixedToColumn", "onFixedToColumn", "scrollWidth", "resizable", "errorRowKeys", "highlightedColKeys", "highlightedRowKeys", "showColHighlight", "showRowHighlight", "highlightRowOnDoubleClick", "defaultExpandedRowKeys", "expandedRowKeys", "onExpand", "defaultExpandAll", "onLoadChildren", "maxHeight", "sticky", "stickyTop", "draggable", "onDragStart", "onDrop", "onDropEnd", "showColMenu", "rowSelection", "cellRender", "footerRender", "fieldKey", "virtual", "scrollbar", "rowClassName", "cellClassName", "onResize"]);
83
84
  /**
84
85
  * 获取 key 字段值
85
86
  */
@@ -171,7 +172,8 @@ var useTable = function useTable(_a) {
171
172
  data: data,
172
173
  columns: columns,
173
174
  resizable: resizable,
174
- virtual: virtual
175
+ virtual: virtual,
176
+ onResize: onResize
175
177
  }),
176
178
  measureRowElementRef = _useColWidth.measureRowElementRef,
177
179
  getColgroupProps = _useColWidth.getColgroupProps,
@@ -37,7 +37,7 @@ export declare const TableProvider: import("react").Provider<(Omit<{
37
37
  onTreeNodeSwitch: (node: import("./types").TableRowEventData, onlyExpand?: any) => Promise<void>;
38
38
  resizable: boolean;
39
39
  colWidths: number[];
40
- onColumnResizable: (_: any, { size }: any, index: number) => void;
40
+ onColumnResizable: (evt: any, { size }: any, index: number) => void;
41
41
  isTree: boolean;
42
42
  cellRender: ((text: any) => import("react").ReactNode) | undefined;
43
43
  footerRender: ((...nodes: import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>[]) => import("react").ReactNode) | undefined;
@@ -152,7 +152,7 @@ export declare const useTableContext: () => Omit<{
152
152
  onTreeNodeSwitch: (node: import("./types").TableRowEventData, onlyExpand?: any) => Promise<void>;
153
153
  resizable: boolean;
154
154
  colWidths: number[];
155
- onColumnResizable: (_: any, { size }: any, index: number) => void;
155
+ onColumnResizable: (evt: any, { size }: any, index: number) => void;
156
156
  isTree: boolean;
157
157
  cellRender: ((text: any) => import("react").ReactNode) | undefined;
158
158
  footerRender: ((...nodes: import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>[]) => import("react").ReactNode) | undefined;
@@ -1,13 +1,15 @@
1
1
  import React from 'react';
2
2
  import { FlattedTableColumnItemData, TableColumnItem, TableRowRecord } from '../types';
3
- export declare const useColWidth: ({ resizable, data, columns, virtual, }: {
3
+ import { ResizeCallbackData } from 'react-resizable';
4
+ export declare const useColWidth: ({ resizable, data, columns, virtual, onResize, }: {
4
5
  resizable: boolean;
5
6
  data: TableRowRecord[];
6
7
  columns: TableColumnItem[];
7
8
  virtual?: boolean | undefined;
9
+ onResize?: ((e: React.SyntheticEvent, data: ResizeCallbackData, index: number, columnsWidth: number[]) => void) | undefined;
8
10
  }) => {
9
11
  measureRowElementRef: React.MutableRefObject<HTMLTableRowElement | null>;
10
- onColumnResizable: (_: any, { size }: any, index: number) => void;
12
+ onColumnResizable: (evt: any, { size }: any, index: number) => void;
11
13
  getColgroupProps: (column: FlattedTableColumnItemData, index: number) => {
12
14
  style: {
13
15
  width: number | undefined;
@@ -2,7 +2,8 @@ import React from 'react';
2
2
  import { PaginationProps } from '@hi-ui/pagination';
3
3
  import { ScrollbarProps } from '@hi-ui/scrollbar';
4
4
  import { TableColumnItem, TableFrozenColumnOptions, TableRowEventData, TableRowSelection, FlattedTableColumnItemData, FlattedTableRowData } from './types';
5
- export declare const useTable: ({ data, columns: columnsProp, defaultFixedToColumn, fixedToColumn: fixedToColumnProp, onFixedToColumn, scrollWidth, resizable, errorRowKeys, highlightedColKeys: highlightedColKeysProp, highlightedRowKeys: highlightedRowKeysProp, showColHighlight, showRowHighlight, highlightRowOnDoubleClick, defaultExpandedRowKeys, expandedRowKeys: expandRowKeysProp, onExpand, defaultExpandAll, onLoadChildren, maxHeight, sticky, stickyTop, draggable, onDragStart, onDrop: onDropProp, onDropEnd, showColMenu, rowSelection, cellRender, footerRender, fieldKey, virtual, scrollbar, rowClassName, cellClassName, ...rootProps }: UseTableProps) => {
5
+ import { ResizeCallbackData } from 'react-resizable';
6
+ export declare const useTable: ({ data, columns: columnsProp, defaultFixedToColumn, fixedToColumn: fixedToColumnProp, onFixedToColumn, scrollWidth, resizable, errorRowKeys, highlightedColKeys: highlightedColKeysProp, highlightedRowKeys: highlightedRowKeysProp, showColHighlight, showRowHighlight, highlightRowOnDoubleClick, defaultExpandedRowKeys, expandedRowKeys: expandRowKeysProp, onExpand, defaultExpandAll, onLoadChildren, maxHeight, sticky, stickyTop, draggable, onDragStart, onDrop: onDropProp, onDropEnd, showColMenu, rowSelection, cellRender, footerRender, fieldKey, virtual, scrollbar, rowClassName, cellClassName, onResize, ...rootProps }: UseTableProps) => {
6
7
  getColgroupProps: (column: FlattedTableColumnItemData, index: number) => {
7
8
  style: {
8
9
  width: number | undefined;
@@ -39,7 +40,7 @@ export declare const useTable: ({ data, columns: columnsProp, defaultFixedToColu
39
40
  onTreeNodeSwitch: (node: TableRowEventData, onlyExpand?: any) => Promise<void>;
40
41
  resizable: boolean;
41
42
  colWidths: number[];
42
- onColumnResizable: (_: any, { size }: any, index: number) => void;
43
+ onColumnResizable: (evt: any, { size }: any, index: number) => void;
43
44
  isTree: boolean;
44
45
  cellRender: ((text: any) => React.ReactNode) | undefined;
45
46
  footerRender: ((...nodes: React.ReactElement[]) => React.ReactNode) | undefined;
@@ -296,5 +297,9 @@ export interface UseTableProps {
296
297
  * 设置单元格类名
297
298
  */
298
299
  cellClassName?: (record: Record<string, any>, column: Record<string, any>, index: number) => string;
300
+ /**
301
+ * resizable 模式下,设置列宽变化时触发的回调
302
+ */
303
+ onResize?: (e: React.SyntheticEvent, data: ResizeCallbackData, index: number, columnsWidth: number[]) => void;
299
304
  }
300
305
  export declare type UseTableReturn = ReturnType<typeof useTable>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hi-ui/table",
3
- "version": "4.6.0",
3
+ "version": "4.7.0-alpha.0",
4
4
  "description": "A sub-package for @hi-ui/hiui.",
5
5
  "keywords": [],
6
6
  "author": "HiUI <mi-hiui@xiaomi.com>",