@antscorp/antsomi-ui 1.3.5-beta.416 → 1.3.5-beta.418
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.
- package/es/components/molecules/ImageEditor/index.d.ts +1 -1
- package/es/components/organism/DataTable/components/Table/ResizableCell.d.ts +1 -0
- package/es/components/organism/DataTable/components/Table/ResizableCell.js +3 -3
- package/es/components/organism/DataTable/components/Table/index.js +22 -16
- package/es/components/organism/DataTable/hooks/useDataTableListing/types.d.ts +2 -1
- package/es/components/organism/DataTable/hooks/useDataTableListing/useDataTableListing.js +22 -6
- package/es/components/organism/DataTable/types/index.d.ts +5 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
export { ImageEditor, ImageResizeHandle } from './ImageEditor';
|
|
1
|
+
export { ImageEditor, type ImageResizeHandle } from './ImageEditor';
|
|
@@ -4,6 +4,7 @@ interface HandleProps extends React.HTMLAttributes<HTMLSpanElement> {
|
|
|
4
4
|
}
|
|
5
5
|
interface ResizableCellProps extends Omit<React.ThHTMLAttributes<HTMLTableCellElement>, 'onResize'> {
|
|
6
6
|
onResize?: (e: React.SyntheticEvent<Element, Event>, data: ResizeCallbackData) => void;
|
|
7
|
+
onResizeStop?: (e: React.SyntheticEvent<Element, Event>, data: ResizeCallbackData) => void;
|
|
7
8
|
width?: number;
|
|
8
9
|
handleProps?: HandleProps;
|
|
9
10
|
disableResize?: boolean;
|
|
@@ -17,7 +17,7 @@ import { MIN_COLUMN_WIDTH } from '../../constants';
|
|
|
17
17
|
import { Typography } from '@antscorp/antsomi-ui/es/components/atoms';
|
|
18
18
|
export const ResizableCell = props => {
|
|
19
19
|
var _a;
|
|
20
|
-
const { width, handleProps, disableResize,
|
|
20
|
+
const { width, handleProps, disableResize, children, style, fixed, index, tableRef, onResize, onResizeStop } = props, restProps = __rest(props, ["width", "handleProps", "disableResize", "children", "style", "fixed", "index", "tableRef", "onResize", "onResizeStop"]);
|
|
21
21
|
// Memos
|
|
22
22
|
const columnStyle = useMemo(() => (Object.assign(Object.assign({}, style), { zIndex: fixed ? 100 - (index || 0) : undefined })), [style, fixed, index]);
|
|
23
23
|
const isRowSelectionCol = (_a = props === null || props === void 0 ? void 0 : props.className) === null || _a === void 0 ? void 0 : _a.includes('antsomi-table-selection-column');
|
|
@@ -37,8 +37,8 @@ export const ResizableCell = props => {
|
|
|
37
37
|
};
|
|
38
38
|
return (React.createElement(Resizable, { width: width || 0, height: 0, minConstraints: [MIN_COLUMN_WIDTH, 0], handle: React.createElement("div", { className: "resizable-handle-wrapper", onClick: e => {
|
|
39
39
|
e.stopPropagation();
|
|
40
|
-
}
|
|
41
|
-
React.createElement("span", Object.assign({ className: "resizable-handle" }, handleProps))), onResize: (...args) => onResize && onResize(...args), draggableOpts: { enableUserSelectHack: true } },
|
|
40
|
+
} },
|
|
41
|
+
React.createElement("span", Object.assign({ className: "resizable-handle" }, handleProps))), onResize: (...args) => onResize && onResize(...args), onResizeStop: (...args) => onResizeStop && onResizeStop(...args), draggableOpts: { enableUserSelectHack: true } },
|
|
42
42
|
React.createElement("th", Object.assign({}, restProps, { style: columnStyle }),
|
|
43
43
|
React.createElement(Typography.Text, { ellipsis: { tooltip: true } }, children))));
|
|
44
44
|
};
|
|
@@ -14,7 +14,7 @@ import { useDataTableContext } from '../../contexts/DataTableContext';
|
|
|
14
14
|
// Constants
|
|
15
15
|
import { DEFAULT_COLUMN_WIDTH, DEFAULT_COLUMN_WIDTHS, DEFAULT_ROW_SELECTION_WIDTH, } from '../../constants';
|
|
16
16
|
export const Table = memo(() => {
|
|
17
|
-
var _a;
|
|
17
|
+
var _a, _b;
|
|
18
18
|
// Store
|
|
19
19
|
const tableProps = useDataTableContext(useShallow(store => store.table));
|
|
20
20
|
const setTable = useDataTableContext(useShallow(store => store.setTable));
|
|
@@ -28,13 +28,17 @@ export const Table = memo(() => {
|
|
|
28
28
|
// Ref
|
|
29
29
|
const tableRef = useRef(null);
|
|
30
30
|
// Variables
|
|
31
|
-
const { scroll } = tableProps;
|
|
31
|
+
const { scroll, columnWidths } = tableProps;
|
|
32
32
|
// Handles
|
|
33
|
-
const
|
|
33
|
+
const onResize = useCallback((index) => (e, { size }) => {
|
|
34
34
|
const nextColumns = cloneDeep(columns || []);
|
|
35
35
|
nextColumns[index] = Object.assign(Object.assign({}, nextColumns[index]), { width: size.width });
|
|
36
36
|
setState(prev => (Object.assign(Object.assign({}, prev), { columns: nextColumns })));
|
|
37
37
|
}, [columns]);
|
|
38
|
+
const onResizeStop = useCallback((index) => (e, { size }) => {
|
|
39
|
+
var _a;
|
|
40
|
+
(_a = tableProps.onColumnResize) === null || _a === void 0 ? void 0 : _a.call(tableProps, { index, width: size.width });
|
|
41
|
+
}, [tableProps]);
|
|
38
42
|
const calculateLastColWidth = (col) => {
|
|
39
43
|
var _a, _b;
|
|
40
44
|
// If last column is fixed then return full rest of width
|
|
@@ -51,19 +55,25 @@ export const Table = memo(() => {
|
|
|
51
55
|
setState(prev => {
|
|
52
56
|
var _a;
|
|
53
57
|
return (Object.assign(Object.assign({}, prev), { columns: (_a = tableProps.columns) === null || _a === void 0 ? void 0 : _a.map((col, index) => {
|
|
54
|
-
var _a
|
|
55
|
-
return (Object.assign(Object.assign({}, col), {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
+
var _a;
|
|
59
|
+
return (Object.assign(Object.assign({}, col), {
|
|
60
|
+
// width:
|
|
61
|
+
// index === (tableProps.columns?.length || 1) - 1
|
|
62
|
+
// ? calculateLastColWidth(col)
|
|
63
|
+
// : columnWidths?.[index] ||
|
|
64
|
+
// (col.width ?? (DEFAULT_COLUMN_WIDTHS[index] || DEFAULT_COLUMN_WIDTH)),
|
|
65
|
+
width: (columnWidths === null || columnWidths === void 0 ? void 0 : columnWidths[index]) ||
|
|
66
|
+
((_a = col.width) !== null && _a !== void 0 ? _a : (DEFAULT_COLUMN_WIDTHS[index] || DEFAULT_COLUMN_WIDTH)) }));
|
|
58
67
|
}) }));
|
|
59
68
|
});
|
|
60
69
|
}
|
|
61
|
-
}, [tableProps.columns]);
|
|
70
|
+
}, [(_a = tableProps.columns) === null || _a === void 0 ? void 0 : _a.map(col => col.width), columnWidths]);
|
|
62
71
|
return (React.createElement(StyledTable, Object.assign({}, tableProps, { virtual: true, ref: ref => {
|
|
63
72
|
tableRef.current = ref === null || ref === void 0 ? void 0 : ref.nativeElement;
|
|
64
73
|
}, scroll: Object.assign(Object.assign({}, scroll), { y: (scroll === null || scroll === void 0 ? void 0 : scroll.y) || '500px', x: (scroll === null || scroll === void 0 ? void 0 : scroll.x) || '100%' }), components: {
|
|
65
|
-
header: Object.assign({ cell: ResizableCell }, (
|
|
66
|
-
} }, (!!(tableProps === null || tableProps === void 0 ? void 0 : tableProps.dataSource) &&
|
|
74
|
+
header: Object.assign({ cell: ResizableCell }, (_b = tableProps === null || tableProps === void 0 ? void 0 : tableProps.components) === null || _b === void 0 ? void 0 : _b.header),
|
|
75
|
+
} }, (!!(tableProps === null || tableProps === void 0 ? void 0 : tableProps.dataSource) &&
|
|
76
|
+
!!(tableProps === null || tableProps === void 0 ? void 0 : tableProps.rowSelection) && {
|
|
67
77
|
rowSelection: Object.assign(Object.assign({ fixed: true, columnWidth: DEFAULT_ROW_SELECTION_WIDTH }, tableProps === null || tableProps === void 0 ? void 0 : tableProps.rowSelection), { onChange(selectedRowKeys, selectedRows, info) {
|
|
68
78
|
var _a, _b;
|
|
69
79
|
setTable({
|
|
@@ -77,12 +87,8 @@ export const Table = memo(() => {
|
|
|
77
87
|
fixed: column.fixed,
|
|
78
88
|
width: column.width,
|
|
79
89
|
index,
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
// height: tableRef?.current?.clientHeight,
|
|
83
|
-
// },
|
|
84
|
-
// },
|
|
85
|
-
onResize: handleResize(index),
|
|
90
|
+
onResize: onResize(index),
|
|
91
|
+
onResizeStop: onResizeStop(index),
|
|
86
92
|
}) }))), bordered: true, pagination: false, loading: {
|
|
87
93
|
indicator: React.createElement(Spin, null),
|
|
88
94
|
spinning: !!tableProps.loading,
|
|
@@ -51,11 +51,12 @@ export interface UseDataTableListingProps<TTableType = any, TSearchType = any> {
|
|
|
51
51
|
externalFilters?: FilterItem[];
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
|
-
export interface DataTableLocalStorage {
|
|
54
|
+
export interface DataTableLocalStorage<TTableType = any> {
|
|
55
55
|
filter?: {
|
|
56
56
|
selectedFilterId?: string;
|
|
57
57
|
filters?: FilterItem[];
|
|
58
58
|
};
|
|
59
|
+
table?: TableProps<TTableType>;
|
|
59
60
|
pagination?: PaginationProps;
|
|
60
61
|
}
|
|
61
62
|
export {};
|
|
@@ -48,6 +48,7 @@ const initialState = {
|
|
|
48
48
|
},
|
|
49
49
|
table: {
|
|
50
50
|
loading: false,
|
|
51
|
+
columnWidths: {},
|
|
51
52
|
},
|
|
52
53
|
selectedRowKeys: [],
|
|
53
54
|
searchValue: '',
|
|
@@ -66,7 +67,7 @@ export function useDataTableListing(props) {
|
|
|
66
67
|
const _b = apiFilter || {}, { url: filterUrl = `${COLUMN_DOMAIN[env || 'development']}/api/filter`, enabled: enabledApiFilter = true } = _b, restOfApiFilterRequest = __rest(_b, ["url", "enabled"]);
|
|
67
68
|
const _c = apiListing || {}, { url: listingUrl = '', enabled: enabledApiListing = true } = _c, restOfApiListingRequest = __rest(_c, ["url", "enabled"]);
|
|
68
69
|
const _d = apiSearch || {}, { url: searchUrl = '', enabled: enabledApiSearch = true } = _d, restOfApiSearchRequest = __rest(_d, ["url", "enabled"]);
|
|
69
|
-
const { filters, selectedFilterId, pagination, selectedRowKeys, searchValue } = state;
|
|
70
|
+
const { filters, selectedFilterId, pagination, selectedRowKeys, searchValue, table } = state;
|
|
70
71
|
const { externalFilters } = filterProps || {};
|
|
71
72
|
const modifyColumnAuth = Object.assign(Object.assign({}, auth), { url: columnUrl });
|
|
72
73
|
const filterAuth = Object.assign(Object.assign({}, auth), { url: filterUrl });
|
|
@@ -249,19 +250,19 @@ export function useDataTableListing(props) {
|
|
|
249
250
|
return Object.assign(Object.assign({ key: name, dataIndex: name, title: label, fixed: fixColumn ? 'left' : undefined }, columns === null || columns === void 0 ? void 0 : columns[name]), { render(value, record, index) {
|
|
250
251
|
var _a;
|
|
251
252
|
const { link } = (columns === null || columns === void 0 ? void 0 : columns[name]) || {};
|
|
252
|
-
const
|
|
253
|
+
const RenderComponent = (React.createElement(Text, { ellipsis: { tooltip: true }, style: Object.assign({}, (link
|
|
253
254
|
? {
|
|
254
255
|
fontWeight: globalToken === null || globalToken === void 0 ? void 0 : globalToken.fontWeightStrong,
|
|
255
256
|
color: globalToken === null || globalToken === void 0 ? void 0 : globalToken.colorPrimary,
|
|
256
257
|
}
|
|
257
258
|
: {})) }, typeof value !== 'object' ? value || DEFAULT_CELL_EMPTY : DEFAULT_CELL_EMPTY));
|
|
258
259
|
if ((_a = columns === null || columns === void 0 ? void 0 : columns[name]) === null || _a === void 0 ? void 0 : _a.render) {
|
|
259
|
-
return columns[name].render(value, record, index,
|
|
260
|
+
return columns[name].render(value, record, index, RenderComponent);
|
|
260
261
|
}
|
|
261
262
|
if (link) {
|
|
262
|
-
return (React.createElement(Link, { to: typeof link === 'function' ? link(record) : link },
|
|
263
|
+
return (React.createElement(Link, { to: typeof link === 'function' ? link(record) : link }, RenderComponent));
|
|
263
264
|
}
|
|
264
|
-
return
|
|
265
|
+
return RenderComponent;
|
|
265
266
|
} });
|
|
266
267
|
})) || []);
|
|
267
268
|
return data;
|
|
@@ -276,7 +277,7 @@ export function useDataTableListing(props) {
|
|
|
276
277
|
* Update values from local storage to state
|
|
277
278
|
*/
|
|
278
279
|
useDeepCompareEffect(() => {
|
|
279
|
-
const { filter, pagination } = localStorageValues || {};
|
|
280
|
+
const { filter, pagination, table } = localStorageValues || {};
|
|
280
281
|
if (!isEmpty(filter)) {
|
|
281
282
|
const { filters, selectedFilterId } = filter || {};
|
|
282
283
|
setState(prev => (Object.assign(Object.assign({}, prev), { selectedFilterId,
|
|
@@ -285,6 +286,9 @@ export function useDataTableListing(props) {
|
|
|
285
286
|
if (!isEmpty(pagination)) {
|
|
286
287
|
setState(prev => (Object.assign(Object.assign({}, prev), { pagination })));
|
|
287
288
|
}
|
|
289
|
+
if (!isEmpty(table)) {
|
|
290
|
+
setState(prev => (Object.assign(Object.assign({}, prev), { table })));
|
|
291
|
+
}
|
|
288
292
|
}, [localStorageValues]);
|
|
289
293
|
// /** Update filters from external filters */
|
|
290
294
|
// useDeepCompareEffect(() => {
|
|
@@ -376,6 +380,11 @@ export function useDataTableListing(props) {
|
|
|
376
380
|
// Set Local Storage
|
|
377
381
|
localStorage.setItem(localStorageKey, JSON.stringify(Object.assign(Object.assign({}, localStorageValues), { filter: Object.assign(Object.assign({}, localStorageValues === null || localStorageValues === void 0 ? void 0 : localStorageValues.filter), filter) })));
|
|
378
382
|
}, [localStorageKey, localStorageValues]);
|
|
383
|
+
const handleUpdateTable = useCallback((table) => {
|
|
384
|
+
setState(prev => (Object.assign(Object.assign({}, prev), { table: Object.assign(Object.assign({}, prev.table), table) })));
|
|
385
|
+
// Set Local Storage
|
|
386
|
+
localStorage.setItem(localStorageKey, JSON.stringify(Object.assign(Object.assign({}, localStorageValues), { table: Object.assign(Object.assign({}, localStorageValues === null || localStorageValues === void 0 ? void 0 : localStorageValues.table), table) })));
|
|
387
|
+
}, [localStorageKey, localStorageValues]);
|
|
379
388
|
const onChangeFilters = useCallback((filters) => {
|
|
380
389
|
handleUpdateFilter({
|
|
381
390
|
filters,
|
|
@@ -470,12 +479,19 @@ export function useDataTableListing(props) {
|
|
|
470
479
|
loading: isTableListingLoading || isTableListingRefetching,
|
|
471
480
|
columns: tableColumns,
|
|
472
481
|
dataSource: tableData,
|
|
482
|
+
columnWidths: table.columnWidths || {},
|
|
473
483
|
rowSelection: {
|
|
474
484
|
selectedRowKeys,
|
|
475
485
|
onChange(selectedRowKeys) {
|
|
476
486
|
setState(prev => (Object.assign(Object.assign({}, prev), { selectedRowKeys })));
|
|
477
487
|
},
|
|
478
488
|
},
|
|
489
|
+
onColumnResize(data) {
|
|
490
|
+
const { index, width } = data;
|
|
491
|
+
handleUpdateTable({
|
|
492
|
+
columnWidths: Object.assign(Object.assign({}, table.columnWidths), { [index]: width }),
|
|
493
|
+
});
|
|
494
|
+
},
|
|
479
495
|
},
|
|
480
496
|
selectedRowKeys,
|
|
481
497
|
/* Search */
|
|
@@ -4,6 +4,11 @@ import { ToolbarProps } from './toolbar';
|
|
|
4
4
|
import { FilterProps } from './filter';
|
|
5
5
|
import { PaginationProps } from '../components';
|
|
6
6
|
export interface TableProps<T> extends AntdTableProps<T> {
|
|
7
|
+
columnWidths?: Record<number, number>;
|
|
8
|
+
onColumnResize?: (data: {
|
|
9
|
+
index: number;
|
|
10
|
+
width: number;
|
|
11
|
+
}) => void;
|
|
7
12
|
}
|
|
8
13
|
export interface ModifyColumnProps {
|
|
9
14
|
}
|