@mezzanine-ui/react 0.12.9 → 0.13.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.
- package/Table/Table.d.ts +25 -3
- package/Table/Table.js +51 -5
- package/Table/TableBody.d.ts +1 -1
- package/Table/TableBody.js +2 -12
- package/Table/TableBodyRow.d.ts +1 -1
- package/Table/TableBodyRow.js +31 -9
- package/Table/TableCell.js +2 -2
- package/Table/TableContext.d.ts +6 -2
- package/Table/TableHeader.d.ts +1 -1
- package/Table/TableHeader.js +18 -7
- package/Table/draggable/useTableDraggable.d.ts +14 -0
- package/Table/draggable/useTableDraggable.js +63 -0
- package/Table/index.d.ts +2 -0
- package/Table/index.js +2 -0
- package/Table/sorting/useTableSorting.d.ts +2 -0
- package/Table/sorting/useTableSorting.js +1 -1
- package/Table/useTableScroll.d.ts +296 -7
- package/Table/useTableScroll.js +185 -75
- package/index.d.ts +2 -1
- package/index.js +3 -0
- package/package.json +6 -4
- package/utils/array-move.d.ts +1 -0
- package/utils/array-move.js +13 -0
package/Table/Table.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
import { TableColumn, TableComponents, TableDataSource, TableRowSelection, TableExpandable, TableFetchMore, TablePagination as TablePaginationType, TableRefresh as TableRefreshType, ExpandRowBySources } from '@mezzanine-ui/core/table';
|
|
2
|
+
import { TableColumn, TableComponents, TableDataSource, TableRowSelection, TableExpandable, TableFetchMore, TablePagination as TablePaginationType, TableRefresh as TableRefreshType, ExpandRowBySources, TableScrolling, TableDraggable } from '@mezzanine-ui/core/table';
|
|
3
3
|
import { EmptyProps } from '../Empty';
|
|
4
4
|
import { NativeElementPropsWithoutKeyAndRef } from '../utils/jsx-types';
|
|
5
|
-
export interface TableBaseProps<T> extends Omit<NativeElementPropsWithoutKeyAndRef<'div'>, 'role'> {
|
|
5
|
+
export interface TableBaseProps<T> extends Omit<NativeElementPropsWithoutKeyAndRef<'div'>, 'role' | 'draggable'> {
|
|
6
6
|
/**
|
|
7
7
|
* customized body className
|
|
8
8
|
*/
|
|
@@ -28,6 +28,12 @@ export interface TableBaseProps<T> extends Omit<NativeElementPropsWithoutKeyAndR
|
|
|
28
28
|
* Notice that each source should contain `key` or `id` prop as data primary key.
|
|
29
29
|
*/
|
|
30
30
|
dataSource: TableDataSource[];
|
|
31
|
+
/**
|
|
32
|
+
* Draggable table row. This feature allows sort items by mouse dragging. Not supported when `fetchMore` is enabled and also buggy when use finger touch (mobile device).
|
|
33
|
+
* When `draggable.enabled` is true, draggable will be enabled.
|
|
34
|
+
* `draggable.onDragEnd` return new dataSource for you
|
|
35
|
+
*/
|
|
36
|
+
draggable?: TableDraggable;
|
|
31
37
|
/**
|
|
32
38
|
* props exported from `<Empty />` component.
|
|
33
39
|
*/
|
|
@@ -47,6 +53,11 @@ export interface TableBaseProps<T> extends Omit<NativeElementPropsWithoutKeyAndR
|
|
|
47
53
|
* Whether table is loading or not
|
|
48
54
|
*/
|
|
49
55
|
loading?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* When loading is true, show specific loadingTip
|
|
58
|
+
* @default '資料載入中...'
|
|
59
|
+
*/
|
|
60
|
+
loadingTip?: string;
|
|
50
61
|
/**
|
|
51
62
|
* `refresh.show` is true, refresh button will display at the top-start of table. <br />
|
|
52
63
|
* `refresh.onClick` is the callback of the refresh button.
|
|
@@ -59,6 +70,17 @@ export interface TableBaseProps<T> extends Omit<NativeElementPropsWithoutKeyAndR
|
|
|
59
70
|
* `rowSelection.actions` are the actions that you want to do for selected data.
|
|
60
71
|
*/
|
|
61
72
|
rowSelection?: TableRowSelection;
|
|
73
|
+
/**
|
|
74
|
+
* Enable table scroll feature <br />
|
|
75
|
+
* `scroll.x` set horizontal scrolling, can also be used to specify the width of the scroll area <br />
|
|
76
|
+
* `scroll.y` Set vertical scrolling, can also be used to specify the height of the scroll area <br />
|
|
77
|
+
* `scroll.fixedFirstColumn` set first column fixed when horizontal scrolling.
|
|
78
|
+
*/
|
|
79
|
+
scroll?: TableScrolling;
|
|
80
|
+
/**
|
|
81
|
+
* customize scroll container className
|
|
82
|
+
*/
|
|
83
|
+
scrollContainerClassName?: string;
|
|
62
84
|
}
|
|
63
85
|
export interface TableWithFetchMore<T> extends TableBaseProps<T> {
|
|
64
86
|
/**
|
|
@@ -84,5 +106,5 @@ export interface TableWithPagination<T> extends TableBaseProps<T> {
|
|
|
84
106
|
fetchMore?: undefined;
|
|
85
107
|
}
|
|
86
108
|
export type TableProps<T> = TableWithFetchMore<T> | TableWithPagination<T>;
|
|
87
|
-
declare const Table: import("react").ForwardRefExoticComponent<TableProps<Record<string, unknown>> & import("react").RefAttributes<
|
|
109
|
+
declare const Table: import("react").ForwardRefExoticComponent<TableProps<Record<string, unknown>> & import("react").RefAttributes<HTMLTableElement>>;
|
|
88
110
|
export default Table;
|
package/Table/Table.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
|
-
import { forwardRef, useRef, useMemo } from 'react';
|
|
2
|
+
import { forwardRef, useRef, useMemo, Fragment } from 'react';
|
|
3
|
+
import { DragDropContext, Droppable } from 'react-beautiful-dnd';
|
|
3
4
|
import { tableClasses } from '@mezzanine-ui/core/table';
|
|
4
5
|
import { TableContext, TableDataContext, TableComponentContext } from './TableContext.js';
|
|
5
6
|
import TableHeader from './TableHeader.js';
|
|
@@ -10,12 +11,16 @@ import { useTableRowSelection } from './rowSelection/useTableRowSelection.js';
|
|
|
10
11
|
import { useTableSorting } from './sorting/useTableSorting.js';
|
|
11
12
|
import { useTableLoading } from './useTableLoading.js';
|
|
12
13
|
import { useTableFetchMore } from './useTableFetchMore.js';
|
|
14
|
+
import { useTableDraggable } from './draggable/useTableDraggable.js';
|
|
15
|
+
import useTableScroll from './useTableScroll.js';
|
|
16
|
+
import { useComposeRefs } from '../hooks/useComposeRefs.js';
|
|
17
|
+
import { composeRefs } from '../utils/composeRefs.js';
|
|
13
18
|
import Loading from '../Loading/Loading.js';
|
|
14
19
|
import cx from 'clsx';
|
|
15
20
|
|
|
16
21
|
const Table = forwardRef(function Table(props, ref) {
|
|
17
22
|
var _a;
|
|
18
|
-
const { bodyClassName, bodyRowClassName, className, columns, components, dataSource: dataSourceProp, emptyProps, expandable: expandableProp, fetchMore: fetchMoreProp, headerClassName, loading: loadingProp, pagination: paginationProp, refresh: refreshProp, rowSelection: rowSelectionProp, ...rest } = props;
|
|
23
|
+
const { bodyClassName, bodyRowClassName, className, columns, components, dataSource: dataSourceProp, draggable: draggableProp, emptyProps, expandable: expandableProp, fetchMore: fetchMoreProp, headerClassName, loading: loadingProp, loadingTip = '資料載入中...', pagination: paginationProp, refresh: refreshProp, rowSelection: rowSelectionProp, scroll: scrollProp, scrollContainerClassName, ...rest } = props;
|
|
19
24
|
const bodyRef = useRef(null);
|
|
20
25
|
/** Feature rowSelection */
|
|
21
26
|
const [selectedRowKeys, setSelectedRowKey] = useTableRowSelection({
|
|
@@ -33,7 +38,7 @@ const Table = forwardRef(function Table(props, ref) {
|
|
|
33
38
|
setSelectedRowKey,
|
|
34
39
|
]);
|
|
35
40
|
/** Feature sorting */
|
|
36
|
-
const [dataSource, onSort, { sortedOn, sortedType, onResetAll }] = useTableSorting({
|
|
41
|
+
const [dataSource, onSort, { sortedOn, sortedType, onResetAll, setDataSource, }] = useTableSorting({
|
|
37
42
|
dataSource: dataSourceProp,
|
|
38
43
|
});
|
|
39
44
|
/** Feature loading */
|
|
@@ -56,13 +61,25 @@ const Table = forwardRef(function Table(props, ref) {
|
|
|
56
61
|
/** @default false */
|
|
57
62
|
(_a = refreshProp === null || refreshProp === void 0 ? void 0 : refreshProp.show) !== null && _a !== void 0 ? _a : false);
|
|
58
63
|
}, [refreshProp === null || refreshProp === void 0 ? void 0 : refreshProp.show]);
|
|
64
|
+
/** Feature Scrolling */
|
|
65
|
+
const [scrollBody, scrollElement, isHorizontalScrolling] = useTableScroll({
|
|
66
|
+
onFetchMore,
|
|
67
|
+
loading,
|
|
68
|
+
scrollBarSize: 4,
|
|
69
|
+
});
|
|
70
|
+
/** Feature drag and drop */
|
|
71
|
+
const { draggingId, onBeforeDragStart, onDragEnd, } = useTableDraggable({
|
|
72
|
+
dataSource,
|
|
73
|
+
setDataSource,
|
|
74
|
+
draggable: draggableProp,
|
|
75
|
+
});
|
|
59
76
|
/** context */
|
|
60
77
|
const tableContextValue = useMemo(() => {
|
|
61
78
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
62
79
|
return ({
|
|
63
|
-
scrollBarSize: 4,
|
|
64
80
|
emptyProps,
|
|
65
81
|
rowSelection,
|
|
82
|
+
isHorizontalScrolling,
|
|
66
83
|
sorting: {
|
|
67
84
|
onSort,
|
|
68
85
|
onResetAll,
|
|
@@ -89,6 +106,11 @@ const Table = forwardRef(function Table(props, ref) {
|
|
|
89
106
|
siblingCount: (_j = (_h = paginationProp.options) === null || _h === void 0 ? void 0 : _h.siblingCount) !== null && _j !== void 0 ? _j : 1,
|
|
90
107
|
},
|
|
91
108
|
} : undefined,
|
|
109
|
+
scroll: scrollProp,
|
|
110
|
+
draggable: draggableProp ? {
|
|
111
|
+
...draggableProp,
|
|
112
|
+
draggingId,
|
|
113
|
+
} : undefined,
|
|
92
114
|
});
|
|
93
115
|
}, [
|
|
94
116
|
dataSource,
|
|
@@ -105,6 +127,10 @@ const Table = forwardRef(function Table(props, ref) {
|
|
|
105
127
|
isFetching,
|
|
106
128
|
isReachEnd,
|
|
107
129
|
paginationProp,
|
|
130
|
+
isHorizontalScrolling,
|
|
131
|
+
scrollProp,
|
|
132
|
+
draggableProp,
|
|
133
|
+
draggingId,
|
|
108
134
|
]);
|
|
109
135
|
const tableDataContextValue = useMemo(() => ({
|
|
110
136
|
columns,
|
|
@@ -116,7 +142,27 @@ const Table = forwardRef(function Table(props, ref) {
|
|
|
116
142
|
bodyCell: (_a = components === null || components === void 0 ? void 0 : components.body) === null || _a === void 0 ? void 0 : _a.cell,
|
|
117
143
|
});
|
|
118
144
|
}, [(_a = components === null || components === void 0 ? void 0 : components.body) === null || _a === void 0 ? void 0 : _a.cell]);
|
|
119
|
-
|
|
145
|
+
const tableRefs = useComposeRefs([ref, scrollBody.target]);
|
|
146
|
+
return (jsx(TableContext.Provider, { value: tableContextValue, children: jsx(TableDataContext.Provider, { value: tableDataContextValue, children: jsx(TableComponentContext.Provider, { value: tableComponentContextValue, children: jsx(DragDropContext, { onBeforeDragStart: onBeforeDragStart, onDragEnd: onDragEnd, children: jsx(Loading, { loading: loading, stretch: true, tip: loadingTip, overlayProps: {
|
|
147
|
+
className: tableClasses.loading,
|
|
148
|
+
}, children: jsx(Droppable, { droppableId: "mzn-table-dnd", isDropDisabled: !(draggableProp === null || draggableProp === void 0 ? void 0 : draggableProp.enabled), children: (provided) => (jsxs(Fragment, { children: [jsx("div", { ...provided.droppableProps, ref: composeRefs([scrollBody.ref, provided.innerRef]), className: cx(tableClasses.scrollContainer, scrollContainerClassName), onScroll: scrollBody.onScroll, style: tableContextValue.scroll ? {
|
|
149
|
+
'--table-scroll-x': tableContextValue.scroll.x
|
|
150
|
+
? `${tableContextValue.scroll.x}px`
|
|
151
|
+
: '100%',
|
|
152
|
+
'--table-scroll-y': tableContextValue.scroll.y
|
|
153
|
+
? `${tableContextValue.scroll.y}px`
|
|
154
|
+
: 'unset',
|
|
155
|
+
} : undefined, children: jsxs("table", { ref: tableRefs, ...rest, className: cx(tableClasses.host, className), children: [isRefreshShow ? (jsx("tbody", { children: jsx("tr", { children: jsx("td", { children: jsx(TableRefresh, { onClick: refreshProp.onClick }) }) }) })) : null, jsx(TableHeader, { className: headerClassName }), jsx(TableBody, { ref: bodyRef, className: bodyClassName, rowClassName: bodyRowClassName }), jsx("tbody", { children: provided.placeholder })] }) }), paginationProp ? (jsx(TablePagination, { bodyRef: bodyRef })) : null, jsx("div", { ref: scrollElement.trackRef, style: scrollElement.trackStyle, onMouseDown: scrollElement.onMouseDown, onMouseUp: scrollElement.onMouseUp, role: "button", tabIndex: -1, className: "mzn-table-scroll-bar-track", children: jsx("div", { style: {
|
|
156
|
+
width: '100%',
|
|
157
|
+
height: '100%',
|
|
158
|
+
position: 'relative',
|
|
159
|
+
}, children: jsx("div", { ref: scrollElement.ref, onMouseDown: scrollElement.onMouseDown, onMouseUp: scrollElement.onMouseUp, onMouseEnter: scrollElement.onMouseEnter, onMouseLeave: scrollElement.onMouseLeave, role: "button", style: scrollElement.style, tabIndex: -1, className: "mzn-table-scroll-bar", children: jsx("div", { style: {
|
|
160
|
+
width: `${scrollElement.scrollBarSize}px`,
|
|
161
|
+
height: '100%',
|
|
162
|
+
borderRadius: '10px',
|
|
163
|
+
backgroundColor: '#7d7d7d',
|
|
164
|
+
transition: '0.1s',
|
|
165
|
+
} }) }) }) })] })) }) }) }) }) }) }));
|
|
120
166
|
});
|
|
121
167
|
var Table$1 = Table;
|
|
122
168
|
|
package/Table/TableBody.d.ts
CHANGED
|
@@ -6,5 +6,5 @@ export interface TableBodyProps extends NativeElementPropsWithoutKeyAndRef<'div'
|
|
|
6
6
|
*/
|
|
7
7
|
rowClassName?: string;
|
|
8
8
|
}
|
|
9
|
-
declare const TableBody: import("react").ForwardRefExoticComponent<TableBodyProps & import("react").RefAttributes<
|
|
9
|
+
declare const TableBody: import("react").ForwardRefExoticComponent<TableBodyProps & import("react").RefAttributes<HTMLTableSectionElement>>;
|
|
10
10
|
export default TableBody;
|
package/Table/TableBody.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
2
|
import { forwardRef, useContext } from 'react';
|
|
3
3
|
import { tableClasses } from '@mezzanine-ui/core/table';
|
|
4
|
-
import { useComposeRefs } from '../hooks/useComposeRefs.js';
|
|
5
|
-
import useTableScroll from './useTableScroll.js';
|
|
6
4
|
import { TableDataContext, TableContext } from './TableContext.js';
|
|
7
5
|
import TableBodyRow from './TableBodyRow.js';
|
|
8
6
|
import Loading from '../Loading/Loading.js';
|
|
@@ -12,9 +10,7 @@ import cx from 'clsx';
|
|
|
12
10
|
const TableBody = forwardRef(function TableBody(props, ref) {
|
|
13
11
|
const { className, rowClassName, ...rest } = props;
|
|
14
12
|
const { dataSource = [], } = useContext(TableDataContext) || {};
|
|
15
|
-
const { emptyProps, fetchMore,
|
|
16
|
-
const [tableBody, scrollElement] = useTableScroll();
|
|
17
|
-
const composedRefs = useComposeRefs([ref, tableBody.ref]);
|
|
13
|
+
const { emptyProps, fetchMore, pagination, } = useContext(TableContext) || {};
|
|
18
14
|
/** customizing empty */
|
|
19
15
|
const { className: emptyComponentClassName = '', children: emptyComponentChildren = '查無資料', fullHeight: emptyComponentFullHeight = true, ...restEmptyProps } = emptyProps || {};
|
|
20
16
|
/** pagination feature */
|
|
@@ -22,13 +18,7 @@ const TableBody = forwardRef(function TableBody(props, ref) {
|
|
|
22
18
|
const currentStartCount = (paginationOptions === null || paginationOptions === void 0 ? void 0 : paginationOptions.pageSize) && currentPage ? ((paginationOptions.pageSize) * (currentPage - 1)) : 0;
|
|
23
19
|
const currentEndCount = (paginationOptions === null || paginationOptions === void 0 ? void 0 : paginationOptions.pageSize) && currentPage && total ? (Math.min(((paginationOptions.pageSize) * currentPage), total)) : 0;
|
|
24
20
|
const currentDataSource = pagination && !disableAutoSlicing ? (dataSource.slice(currentStartCount, currentEndCount)) : dataSource;
|
|
25
|
-
return (jsxs("
|
|
26
|
-
width: `${scrollBarSize}px`,
|
|
27
|
-
height: '100%',
|
|
28
|
-
borderRadius: '10px',
|
|
29
|
-
backgroundColor: '#7d7d7d',
|
|
30
|
-
transition: '0.1s',
|
|
31
|
-
} }) })] }));
|
|
21
|
+
return (jsxs("tbody", { ...rest, ref: ref, className: cx(tableClasses.body, className), children: [currentDataSource.length ? currentDataSource.map((rowData, index) => (jsx(TableBodyRow, { className: rowClassName, rowData: rowData, rowIndex: index }, (rowData.key || rowData.id)))) : (jsx("tr", { children: jsx("td", { children: jsx(Empty, { ...restEmptyProps, className: cx(tableClasses.bodyEmpty, emptyComponentClassName), fullHeight: emptyComponentFullHeight, children: emptyComponentChildren }) }) })), (fetchMore === null || fetchMore === void 0 ? void 0 : fetchMore.isFetching) ? (jsx("tr", { className: tableClasses.bodyFetchMore, children: jsx("td", { children: jsx(Loading, { loading: true }) }) })) : null] }));
|
|
32
22
|
});
|
|
33
23
|
var TableBody$1 = TableBody;
|
|
34
24
|
|
package/Table/TableBodyRow.d.ts
CHANGED
|
@@ -8,5 +8,5 @@ export interface TableBodyRowProps extends NativeElementPropsWithoutKeyAndRef<'d
|
|
|
8
8
|
rowData: TableDataSource;
|
|
9
9
|
rowIndex: number;
|
|
10
10
|
}
|
|
11
|
-
declare const TableBodyRow: import("react").ForwardRefExoticComponent<TableBodyRowProps & import("react").RefAttributes<
|
|
11
|
+
declare const TableBodyRow: import("react").ForwardRefExoticComponent<TableBodyRowProps & import("react").RefAttributes<HTMLTableRowElement>>;
|
|
12
12
|
export default TableBodyRow;
|
package/Table/TableBodyRow.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
2
|
import { forwardRef, useContext, useState, useMemo, Fragment } from 'react';
|
|
3
3
|
import { tableClasses, getColumnStyle, getCellStyle } from '@mezzanine-ui/core/table';
|
|
4
|
+
import { Draggable } from 'react-beautiful-dnd';
|
|
4
5
|
import get from 'lodash/get';
|
|
5
6
|
import { TableContext, TableDataContext } from './TableContext.js';
|
|
6
7
|
import TableCell from './TableCell.js';
|
|
@@ -9,11 +10,12 @@ import TableRowSelection from './rowSelection/TableRowSelection.js';
|
|
|
9
10
|
import TableExpandable from './expandable/TableExpandable.js';
|
|
10
11
|
import TableEditRenderWrapper from './editable/TableEditRenderWrapper.js';
|
|
11
12
|
import AccordionDetails from '../Accordion/AccordionDetails.js';
|
|
13
|
+
import { composeRefs } from '../utils/composeRefs.js';
|
|
12
14
|
import cx from 'clsx';
|
|
13
15
|
|
|
14
16
|
const TableBodyRow = forwardRef(function TableBodyRow(props, ref) {
|
|
15
17
|
const { className, rowData, rowIndex, ...rest } = props;
|
|
16
|
-
const { rowSelection, expanding, } = useContext(TableContext) || {};
|
|
18
|
+
const { rowSelection, expanding, isHorizontalScrolling, scroll, draggable, } = useContext(TableContext) || {};
|
|
17
19
|
const { columns, } = useContext(TableDataContext) || {};
|
|
18
20
|
/** Feature rowSelection */
|
|
19
21
|
const [selected, setSelected] = useState(false);
|
|
@@ -27,14 +29,34 @@ const TableBodyRow = forwardRef(function TableBodyRow(props, ref) {
|
|
|
27
29
|
var _a, _b;
|
|
28
30
|
return ((_b = (_a = expanding === null || expanding === void 0 ? void 0 : expanding.expandedRowRender) === null || _a === void 0 ? void 0 : _a.call(expanding, rowData)) !== null && _b !== void 0 ? _b : null);
|
|
29
31
|
}, [expanding, rowData]);
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
/** Feature scrolling */
|
|
33
|
+
const isFirstColumnShouldSticky = useMemo(() => {
|
|
34
|
+
var _a;
|
|
35
|
+
/** 前面有 action 時不可 sticky */
|
|
36
|
+
if (rowSelection || expanding)
|
|
37
|
+
return false;
|
|
38
|
+
return ((_a = scroll === null || scroll === void 0 ? void 0 : scroll.fixedFirstColumn) !== null && _a !== void 0 ? _a : false);
|
|
39
|
+
}, [
|
|
40
|
+
rowSelection,
|
|
41
|
+
expanding,
|
|
42
|
+
scroll === null || scroll === void 0 ? void 0 : scroll.fixedFirstColumn,
|
|
43
|
+
]);
|
|
44
|
+
return (jsxs(Fragment, { children: [jsx(Draggable, { index: rowIndex, draggableId: rowData.key || rowData.id, isDragDisabled: !(draggable === null || draggable === void 0 ? void 0 : draggable.enabled), children: (draggableProvided) => (jsxs("tr", { ...rest, ...draggableProvided.draggableProps, ...draggableProvided.dragHandleProps, ref: composeRefs([ref, draggableProvided.innerRef]), className: cx(tableClasses.bodyRow, {
|
|
45
|
+
[tableClasses.bodyRowHighlight]: selected || expanded,
|
|
46
|
+
[tableClasses.bodyRowDragging]: (draggable === null || draggable === void 0 ? void 0 : draggable.draggingId)
|
|
47
|
+
&& draggable.draggingId === (rowData.key || rowData.id),
|
|
48
|
+
}, className), children: [rowSelection ? (jsx("td", { className: tableClasses.bodyRowCellWrapper, style: {
|
|
49
|
+
flex: 'unset',
|
|
50
|
+
minWidth: 'unset',
|
|
51
|
+
}, children: jsx(TableRowSelection, { rowKey: (rowData.key || rowData.id), setChecked: (status) => setSelected(status), showDropdownIcon: false }) })) : null, expanding ? (jsx("td", { className: tableClasses.bodyRowCellWrapper, style: {
|
|
52
|
+
flex: 'unset',
|
|
53
|
+
minWidth: 'unset',
|
|
54
|
+
}, children: jsx(TableExpandable, { expandable: isExpandable, expanded: expanded, setExpanded: setExpanded, onExpand: (status) => { var _a; return (_a = expanding.onExpand) === null || _a === void 0 ? void 0 : _a.call(expanding, rowData, status); } }) })) : null, (columns !== null && columns !== void 0 ? columns : []).map((column, idx) => {
|
|
55
|
+
var _a, _b, _c, _d;
|
|
56
|
+
const ellipsis = !!(get(rowData, column.dataIndex)) && ((_a = column.ellipsis) !== null && _a !== void 0 ? _a : true);
|
|
57
|
+
const tooltipTitle = ((_c = (_b = column.renderTooltipTitle) === null || _b === void 0 ? void 0 : _b.call(column, rowData)) !== null && _c !== void 0 ? _c : get(rowData, column.dataIndex));
|
|
58
|
+
return (jsx("td", { className: cx(tableClasses.bodyRowCellWrapper, isFirstColumnShouldSticky && idx === 0 && tableClasses.bodyRowCellWrapperFixed, isFirstColumnShouldSticky && idx === 0 && isHorizontalScrolling && tableClasses.bodyRowCellWrapperFixedStuck, column.bodyClassName), style: getColumnStyle(column), children: jsx(TableEditRenderWrapper, { ...column, rowData: rowData, children: jsx(TableCell, { ellipsis: ellipsis, forceShownTooltipWhenHovered: column.forceShownTooltipWhenHovered, style: getCellStyle(column), tooltipTitle: tooltipTitle, children: ((_d = column.render) === null || _d === void 0 ? void 0 : _d.call(column, rowData, rowIndex, column)) || get(rowData, column.dataIndex) }) }) }, `${column.dataIndex}-${column.title}`));
|
|
59
|
+
})] })) }, rowData.key || rowData.id), renderedExpandedContent ? (jsx("tr", { children: jsx("td", { style: { padding: 0 }, children: jsx(AccordionDetails, { className: cx(expanding.className, tableClasses.bodyRowExpandedTableWrapper), expanded: expanded, children: (renderedExpandedContent === null || renderedExpandedContent === void 0 ? void 0 : renderedExpandedContent.dataSource) ? (jsx(TableExpandedTable, { renderedExpandedContent: renderedExpandedContent })) : renderedExpandedContent }) }) })) : null] }));
|
|
38
60
|
});
|
|
39
61
|
var TableBodyRow$1 = TableBodyRow;
|
|
40
62
|
|
package/Table/TableCell.js
CHANGED
|
@@ -5,9 +5,9 @@ import Tooltip from '../Tooltip/Tooltip.js';
|
|
|
5
5
|
import cx from 'clsx';
|
|
6
6
|
|
|
7
7
|
const TableCell = forwardRef(function TableCell(props, ref) {
|
|
8
|
-
const { children, className, ellipsis = true, forceShownTooltipWhenHovered = false,
|
|
8
|
+
const { children, className, ellipsis = true, forceShownTooltipWhenHovered = false, tooltipTitle, ...rest } = props;
|
|
9
9
|
const ellipsisRef = useRef(null);
|
|
10
|
-
return (jsx("div", { ref: ref, ...rest, className: cx(tableClasses.cell, className),
|
|
10
|
+
return (jsx("div", { ref: ref, ...rest, className: cx(tableClasses.cell, className), children: ellipsis || forceShownTooltipWhenHovered ? (jsx(Tooltip, { title: `${tooltipTitle}`, options: {
|
|
11
11
|
placement: 'top-start',
|
|
12
12
|
}, children: ({ onMouseEnter, onMouseLeave }) => (jsx("div", { ref: ellipsisRef, className: ellipsis ? tableClasses.cellEllipsis : '', onMouseEnter: (e) => {
|
|
13
13
|
if (ellipsisRef.current) {
|
package/Table/TableContext.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
import { TableRowSelection, TableColumn, TableExpandable, TablePagination, TableDataSource, TableRecord, ExpandRowBySources } from '@mezzanine-ui/core/table';
|
|
2
|
+
import { TableRowSelection, TableColumn, TableExpandable, TablePagination, TableDataSource, TableRecord, ExpandRowBySources, TableScrolling, TableDraggable } from '@mezzanine-ui/core/table';
|
|
3
3
|
import { EmptyProps } from '../Empty';
|
|
4
4
|
/** typeof rowSelection */
|
|
5
5
|
export interface RowSelectionContext extends Pick<TableRowSelection, 'actions'> {
|
|
@@ -24,7 +24,7 @@ export interface FetchMoreContext {
|
|
|
24
24
|
isReachEnd: boolean;
|
|
25
25
|
}
|
|
26
26
|
export interface TableContextProps {
|
|
27
|
-
|
|
27
|
+
isHorizontalScrolling?: boolean;
|
|
28
28
|
emptyProps?: EmptyProps;
|
|
29
29
|
rowSelection?: RowSelectionContext;
|
|
30
30
|
sorting?: SortingContext;
|
|
@@ -35,6 +35,10 @@ export interface TableContextProps {
|
|
|
35
35
|
};
|
|
36
36
|
fetchMore?: FetchMoreContext;
|
|
37
37
|
pagination?: TablePagination;
|
|
38
|
+
scroll?: TableScrolling;
|
|
39
|
+
draggable?: TableDraggable & {
|
|
40
|
+
draggingId: string;
|
|
41
|
+
};
|
|
38
42
|
}
|
|
39
43
|
export declare const TableContext: import("react").Context<TableContextProps | null>;
|
|
40
44
|
export interface TableDataContextProps {
|
package/Table/TableHeader.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { NativeElementPropsWithoutKeyAndRef } from '../utils/jsx-types';
|
|
3
|
-
declare const TableHeader: import("react").ForwardRefExoticComponent<NativeElementPropsWithoutKeyAndRef<"div"> & import("react").RefAttributes<
|
|
3
|
+
declare const TableHeader: import("react").ForwardRefExoticComponent<NativeElementPropsWithoutKeyAndRef<"div"> & import("react").RefAttributes<HTMLTableRowElement>>;
|
|
4
4
|
export default TableHeader;
|
package/Table/TableHeader.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { forwardRef, useContext } from 'react';
|
|
1
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
|
+
import { forwardRef, useContext, useMemo } from 'react';
|
|
3
3
|
import { tableClasses, getColumnStyle, getCellStyle } from '@mezzanine-ui/core/table';
|
|
4
4
|
import { TableContext, TableDataContext } from './TableContext.js';
|
|
5
5
|
import { SELECTED_ALL_KEY } from './rowSelection/useTableRowSelection.js';
|
|
@@ -11,12 +11,23 @@ import cx from 'clsx';
|
|
|
11
11
|
|
|
12
12
|
const TableHeader = forwardRef(function TableHeader(props, ref) {
|
|
13
13
|
const { className, ...rest } = props;
|
|
14
|
-
const { rowSelection, expanding, } = useContext(TableContext) || {};
|
|
14
|
+
const { rowSelection, isHorizontalScrolling, scroll, expanding, } = useContext(TableContext) || {};
|
|
15
15
|
const { columns, } = useContext(TableDataContext) || {};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
const isFirstColumnShouldSticky = useMemo(() => {
|
|
17
|
+
var _a;
|
|
18
|
+
/** 前面有 action 時不可 sticky */
|
|
19
|
+
if (rowSelection || expanding)
|
|
20
|
+
return false;
|
|
21
|
+
return ((_a = scroll === null || scroll === void 0 ? void 0 : scroll.fixedFirstColumn) !== null && _a !== void 0 ? _a : false);
|
|
22
|
+
}, [
|
|
23
|
+
rowSelection,
|
|
24
|
+
expanding,
|
|
25
|
+
scroll === null || scroll === void 0 ? void 0 : scroll.fixedFirstColumn,
|
|
26
|
+
]);
|
|
27
|
+
return (jsx("thead", { className: tableClasses.headerFixed, children: jsxs("tr", { ref: ref, ...rest, className: cx(tableClasses.header, className), children: [rowSelection ? (jsx("th", { style: { display: 'flex' }, children: jsx(TableRowSelection, { rowKey: SELECTED_ALL_KEY, showDropdownIcon: true }) })) : null, expanding && !rowSelection ? (jsx("th", { style: { display: 'flex' }, children: jsx(TableExpandable, { showIcon: false }) })) : null, (columns !== null && columns !== void 0 ? columns : []).map((column, idx) => {
|
|
28
|
+
var _a;
|
|
29
|
+
return (jsx("th", { className: cx(tableClasses.headerCellWrapper, isFirstColumnShouldSticky && idx === 0 && tableClasses.headerCellWrapperFixed, isFirstColumnShouldSticky && idx === 0 && isHorizontalScrolling && tableClasses.headerCellWrapperFixedStuck, column.headerClassName), style: getColumnStyle(column), children: jsxs(TableCell, { ellipsis: false, style: getCellStyle(column), children: [((_a = column.renderTitle) === null || _a === void 0 ? void 0 : _a.call(column, tableClasses)) || column.title, typeof column.sorter === 'function' || typeof column.onSorted === 'function' ? (jsx(TableSortingIcon, { column: column })) : null] }) }, `${column.dataIndex}-${column.title}`));
|
|
30
|
+
})] }) }));
|
|
20
31
|
});
|
|
21
32
|
var TableHeader$1 = TableHeader;
|
|
22
33
|
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Dispatch, SetStateAction } from 'react';
|
|
2
|
+
import { TableDataSource, TableDraggable } from '@mezzanine-ui/core/table';
|
|
3
|
+
export interface UseTableDraggable {
|
|
4
|
+
dataSource: TableDataSource[];
|
|
5
|
+
setDataSource: Dispatch<SetStateAction<TableDataSource[]>>;
|
|
6
|
+
draggable?: TableDraggable;
|
|
7
|
+
}
|
|
8
|
+
export declare function useTableDraggable(props: UseTableDraggable): {
|
|
9
|
+
draggingId: string;
|
|
10
|
+
onBeforeDragStart: (e: {
|
|
11
|
+
draggableId: SetStateAction<string>;
|
|
12
|
+
}) => void;
|
|
13
|
+
onDragEnd: import("react-beautiful-dnd").OnDragEndResponder;
|
|
14
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { useRef, useState, useEffect, useCallback } from 'react';
|
|
2
|
+
import isEqual from 'lodash/isEqual';
|
|
3
|
+
import debounce from 'lodash/debounce';
|
|
4
|
+
import { arrayMove } from '../../utils/array-move.js';
|
|
5
|
+
import { usePreviousValue } from '../../hooks/usePreviousValue.js';
|
|
6
|
+
|
|
7
|
+
function useTableDraggable(props) {
|
|
8
|
+
const { dataSource, setDataSource, draggable } = props;
|
|
9
|
+
const resultSnapshot = useRef(null);
|
|
10
|
+
const dataSnapShot = useRef(dataSource);
|
|
11
|
+
const isDragging = useRef(false);
|
|
12
|
+
const [draggingId, setDraggingId] = useState('');
|
|
13
|
+
const prevDataSource = usePreviousValue(dataSource);
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
if (!isEqual(prevDataSource, dataSource)) {
|
|
16
|
+
dataSnapShot.current = dataSource;
|
|
17
|
+
}
|
|
18
|
+
}, [prevDataSource, dataSource]);
|
|
19
|
+
const onBeforeDragStart = useCallback((e) => {
|
|
20
|
+
isDragging.current = true;
|
|
21
|
+
setDraggingId(e.draggableId);
|
|
22
|
+
}, []);
|
|
23
|
+
const onDragEnd = useCallback(async (result, id) => {
|
|
24
|
+
var _a, _b;
|
|
25
|
+
resultSnapshot.current = [result, id];
|
|
26
|
+
isDragging.current = false;
|
|
27
|
+
setDraggingId('');
|
|
28
|
+
const temp = [...dataSnapShot.current];
|
|
29
|
+
const from = result.source.index;
|
|
30
|
+
const to = (_b = (_a = result.destination) === null || _a === void 0 ? void 0 : _a.index) !== null && _b !== void 0 ? _b : from;
|
|
31
|
+
const newData = arrayMove(temp, from, to);
|
|
32
|
+
dataSnapShot.current = newData;
|
|
33
|
+
setDataSource(newData);
|
|
34
|
+
}, [setDataSource]);
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
if (!(draggable === null || draggable === void 0 ? void 0 : draggable.enabled))
|
|
37
|
+
return () => { };
|
|
38
|
+
async function onMouseUp() {
|
|
39
|
+
var _a, _b, _c;
|
|
40
|
+
if (isDragging.current)
|
|
41
|
+
return;
|
|
42
|
+
const args = resultSnapshot.current;
|
|
43
|
+
resultSnapshot.current = null;
|
|
44
|
+
if (!(args === null || args === void 0 ? void 0 : args[0]) || ((_a = args === null || args === void 0 ? void 0 : args[0]) === null || _a === void 0 ? void 0 : _a.source.index) === ((_c = (_b = args === null || args === void 0 ? void 0 : args[0]) === null || _b === void 0 ? void 0 : _b.destination) === null || _c === void 0 ? void 0 : _c.index))
|
|
45
|
+
return;
|
|
46
|
+
if ((draggable === null || draggable === void 0 ? void 0 : draggable.onDragEnd) && args) {
|
|
47
|
+
draggable.onDragEnd(Array.from(dataSnapShot.current));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const debouncedOnMouseUp = debounce(onMouseUp, 500);
|
|
51
|
+
window.addEventListener('mouseup', debouncedOnMouseUp, false);
|
|
52
|
+
return () => {
|
|
53
|
+
window.removeEventListener('mouseup', debouncedOnMouseUp, false);
|
|
54
|
+
};
|
|
55
|
+
}, [draggable]);
|
|
56
|
+
return {
|
|
57
|
+
draggingId,
|
|
58
|
+
onBeforeDragStart,
|
|
59
|
+
onDragEnd,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { useTableDraggable };
|
package/Table/index.d.ts
CHANGED
|
@@ -2,3 +2,5 @@ export { TableProps, default, } from './Table';
|
|
|
2
2
|
export { TableRefreshProps, default as TableRefresh, } from './refresh/TableRefresh';
|
|
3
3
|
export { TableCellProps, default as TableCell, } from './TableCell';
|
|
4
4
|
export { EditableBodyCellProps, } from './editable/TableEditRenderWrapper';
|
|
5
|
+
export { useTableDraggable, } from './draggable/useTableDraggable';
|
|
6
|
+
export { default as useTableScroll, } from './useTableScroll';
|
package/Table/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export { default } from './Table.js';
|
|
2
2
|
export { default as TableRefresh } from './refresh/TableRefresh.js';
|
|
3
3
|
export { default as TableCell } from './TableCell.js';
|
|
4
|
+
export { useTableDraggable } from './draggable/useTableDraggable.js';
|
|
5
|
+
export { default as useTableScroll } from './useTableScroll.js';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import { TableDataSource, TableColumn, TableRecord } from '@mezzanine-ui/core/table';
|
|
2
3
|
export interface UseTableSorting {
|
|
3
4
|
dataSource: TableDataSource[];
|
|
@@ -7,4 +8,5 @@ export declare function useTableSorting(props: UseTableSorting): readonly [Table
|
|
|
7
8
|
readonly sortedOn: string;
|
|
8
9
|
readonly sortedType: SortedType;
|
|
9
10
|
readonly onResetAll: () => void;
|
|
11
|
+
readonly setDataSource: import("react").Dispatch<import("react").SetStateAction<TableDataSource[]>>;
|
|
10
12
|
}];
|
|
@@ -107,7 +107,7 @@ function useTableSorting(props) {
|
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
});
|
|
110
|
-
return [dataSource, onChange, { sortedOn, sortedType, onResetAll }];
|
|
110
|
+
return [dataSource, onChange, { sortedOn, sortedType, onResetAll, setDataSource }];
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
export { useTableSorting };
|