material-react-table 1.1.0-beta.1 → 1.1.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.
- package/dist/cjs/MaterialReactTable.d.ts +1 -1
- package/dist/cjs/body/MRT_TableBodyCell.d.ts +1 -0
- package/dist/cjs/body/MRT_TableBodyRow.d.ts +1 -0
- package/dist/cjs/index.js +40 -45
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/table/MRT_TableRoot.d.ts +1 -1
- package/dist/esm/MaterialReactTable.d.ts +1 -1
- package/dist/esm/body/MRT_TableBodyCell.d.ts +1 -0
- package/dist/esm/body/MRT_TableBodyRow.d.ts +1 -0
- package/dist/esm/material-react-table.esm.js +40 -45
- package/dist/esm/material-react-table.esm.js.map +1 -1
- package/dist/esm/table/MRT_TableRoot.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/package.json +1 -1
- package/src/MaterialReactTable.tsx +1 -1
- package/src/body/MRT_TableBody.tsx +6 -2
- package/src/body/MRT_TableBodyCell.tsx +37 -36
- package/src/body/MRT_TableBodyRow.tsx +15 -9
- package/src/head/MRT_TableHeadCell.tsx +19 -16
|
@@ -45,7 +45,7 @@ export declare const MRT_TableRoot: <TData extends Record<string, any> = {}>(pro
|
|
|
45
45
|
icons?: Partial<import("..").MRT_Icons> | undefined;
|
|
46
46
|
initialState?: Partial<MRT_TableState<TData>> | undefined;
|
|
47
47
|
localization?: Partial<MRT_Localization> | undefined;
|
|
48
|
-
memoMode?: "
|
|
48
|
+
memoMode?: "rows" | "cells" | "table-body" | undefined;
|
|
49
49
|
muiBottomToolbarProps?: import("@mui/material").ToolbarProps<"div", {}> | (({ table }: {
|
|
50
50
|
table: MRT_TableInstance<TData>;
|
|
51
51
|
}) => import("@mui/material").ToolbarProps<"div", {}>) | undefined;
|
|
@@ -454,7 +454,7 @@ export declare type MaterialReactTableProps<TData extends Record<string, any> =
|
|
|
454
454
|
* @warning This will break some dynamic rendering features. See the memoization guide for more info:
|
|
455
455
|
* @link https://www.material-react-table.com/docs/guides/memoize-components
|
|
456
456
|
*/
|
|
457
|
-
memoMode?: '
|
|
457
|
+
memoMode?: 'cells' | 'rows' | 'table-body';
|
|
458
458
|
muiBottomToolbarProps?: ToolbarProps | (({ table }: {
|
|
459
459
|
table: MRT_TableInstance<TData>;
|
|
460
460
|
}) => ToolbarProps);
|
|
@@ -1752,19 +1752,11 @@ const MRT_TableHeadCell = ({ header, table }) => {
|
|
|
1752
1752
|
? columnDef.muiTableHeadCellProps({ column, table })
|
|
1753
1753
|
: columnDef.muiTableHeadCellProps;
|
|
1754
1754
|
const tableCellProps = Object.assign(Object.assign({}, mTableHeadCellProps), mcTableHeadCellProps);
|
|
1755
|
-
const
|
|
1756
|
-
if (enableGrouping && (hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === 'drop-zone') {
|
|
1757
|
-
setHoveredColumn(null);
|
|
1758
|
-
}
|
|
1759
|
-
if (enableColumnOrdering && draggingColumn && columnDefType !== 'group') {
|
|
1760
|
-
setHoveredColumn(columnDef.enableColumnOrdering !== false ? column : null);
|
|
1761
|
-
}
|
|
1762
|
-
};
|
|
1763
|
-
const draggingBorder = (draggingColumn === null || draggingColumn === void 0 ? void 0 : draggingColumn.id) === column.id
|
|
1755
|
+
const draggingBorder = useMemo(() => (draggingColumn === null || draggingColumn === void 0 ? void 0 : draggingColumn.id) === column.id
|
|
1764
1756
|
? `1px dashed ${theme.palette.text.secondary}`
|
|
1765
1757
|
: (hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === column.id
|
|
1766
1758
|
? `2px dashed ${theme.palette.primary.main}`
|
|
1767
|
-
: undefined;
|
|
1759
|
+
: undefined, [draggingColumn, hoveredColumn]);
|
|
1768
1760
|
const draggingBorders = draggingBorder
|
|
1769
1761
|
? {
|
|
1770
1762
|
borderLeft: draggingBorder,
|
|
@@ -1772,6 +1764,14 @@ const MRT_TableHeadCell = ({ header, table }) => {
|
|
|
1772
1764
|
borderTop: draggingBorder,
|
|
1773
1765
|
}
|
|
1774
1766
|
: undefined;
|
|
1767
|
+
const handleDragEnter = (_e) => {
|
|
1768
|
+
if (enableGrouping && (hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === 'drop-zone') {
|
|
1769
|
+
setHoveredColumn(null);
|
|
1770
|
+
}
|
|
1771
|
+
if (enableColumnOrdering && draggingColumn && columnDefType !== 'group') {
|
|
1772
|
+
setHoveredColumn(columnDef.enableColumnOrdering !== false ? column : null);
|
|
1773
|
+
}
|
|
1774
|
+
};
|
|
1775
1775
|
const headerElement = ((_b = ((columnDef === null || columnDef === void 0 ? void 0 : columnDef.Header) instanceof Function
|
|
1776
1776
|
? (_a = columnDef === null || columnDef === void 0 ? void 0 : columnDef.Header) === null || _a === void 0 ? void 0 : _a.call(columnDef, {
|
|
1777
1777
|
column,
|
|
@@ -2010,10 +2010,10 @@ const MRT_TableBodyCellValue = ({ cell, table }) => {
|
|
|
2010
2010
|
: (_b = (_a = columnDef === null || columnDef === void 0 ? void 0 : columnDef.Cell) === null || _a === void 0 ? void 0 : _a.call(columnDef, { cell, column, row, table })) !== null && _b !== void 0 ? _b : cell.renderValue()));
|
|
2011
2011
|
};
|
|
2012
2012
|
|
|
2013
|
-
const MRT_TableBodyCell = ({ cell, enableHover, rowIndex, rowRef, table, }) => {
|
|
2013
|
+
const MRT_TableBodyCell = ({ cell, enableHover, numRows, rowIndex, rowRef, table, }) => {
|
|
2014
2014
|
var _a, _b;
|
|
2015
2015
|
const theme = useTheme();
|
|
2016
|
-
const { getState, options: { editingMode, enableClickToCopy, enableColumnOrdering, enableEditing, enableGrouping,
|
|
2016
|
+
const { getState, options: { editingMode, enableClickToCopy, enableColumnOrdering, enableEditing, enableGrouping, enableRowNumbers, muiTableBodyCellProps, muiTableBodyCellSkeletonProps, rowNumberMode, }, refs: { editInputRefs }, setEditingCell, setHoveredColumn, } = table;
|
|
2017
2017
|
const { draggingColumn, editingCell, editingRow, hoveredColumn, density, isLoading, showSkeletons, } = getState();
|
|
2018
2018
|
const { column, row } = cell;
|
|
2019
2019
|
const { columnDef } = column;
|
|
@@ -2028,6 +2028,25 @@ const MRT_TableBodyCell = ({ cell, enableHover, rowIndex, rowRef, table, }) => {
|
|
|
2028
2028
|
const skeletonProps = muiTableBodyCellSkeletonProps instanceof Function
|
|
2029
2029
|
? muiTableBodyCellSkeletonProps({ cell, column, row, table })
|
|
2030
2030
|
: muiTableBodyCellSkeletonProps;
|
|
2031
|
+
const [skeletonWidth, setSkeletonWidth] = useState(0);
|
|
2032
|
+
useEffect(() => setSkeletonWidth(isLoading || showSkeletons
|
|
2033
|
+
? columnDefType === 'display'
|
|
2034
|
+
? column.getSize() / 2
|
|
2035
|
+
: Math.round(Math.random() * (column.getSize() - column.getSize() / 3) +
|
|
2036
|
+
column.getSize() / 3)
|
|
2037
|
+
: 100), []);
|
|
2038
|
+
const draggingBorder = useMemo(() => (draggingColumn === null || draggingColumn === void 0 ? void 0 : draggingColumn.id) === column.id
|
|
2039
|
+
? `1px dashed ${theme.palette.text.secondary}`
|
|
2040
|
+
: (hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === column.id
|
|
2041
|
+
? `2px dashed ${theme.palette.primary.main}`
|
|
2042
|
+
: undefined, [draggingColumn, hoveredColumn]);
|
|
2043
|
+
const draggingBorders = useMemo(() => draggingBorder
|
|
2044
|
+
? {
|
|
2045
|
+
borderLeft: draggingBorder,
|
|
2046
|
+
borderRight: draggingBorder,
|
|
2047
|
+
borderBottom: rowIndex === numRows - 1 ? draggingBorder : undefined,
|
|
2048
|
+
}
|
|
2049
|
+
: undefined, [draggingBorder, numRows]);
|
|
2031
2050
|
const isEditable = (enableEditing || columnDef.enableEditing) &&
|
|
2032
2051
|
columnDef.enableEditing !== false;
|
|
2033
2052
|
const isEditing = isEditable &&
|
|
@@ -2035,13 +2054,6 @@ const MRT_TableBodyCell = ({ cell, enableHover, rowIndex, rowRef, table, }) => {
|
|
|
2035
2054
|
(editingMode === 'table' ||
|
|
2036
2055
|
(editingRow === null || editingRow === void 0 ? void 0 : editingRow.id) === row.id ||
|
|
2037
2056
|
(editingCell === null || editingCell === void 0 ? void 0 : editingCell.id) === cell.id);
|
|
2038
|
-
const [skeletonWidth, setSkeletonWidth] = useState(0);
|
|
2039
|
-
useEffect(() => setSkeletonWidth(isLoading || showSkeletons
|
|
2040
|
-
? columnDefType === 'display'
|
|
2041
|
-
? column.getSize() / 2
|
|
2042
|
-
: Math.round(Math.random() * (column.getSize() - column.getSize() / 3) +
|
|
2043
|
-
column.getSize() / 3)
|
|
2044
|
-
: 100), [isLoading, showSkeletons]);
|
|
2045
2057
|
const handleDoubleClick = (event) => {
|
|
2046
2058
|
var _a;
|
|
2047
2059
|
(_a = tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.onDoubleClick) === null || _a === void 0 ? void 0 : _a.call(tableCellProps, event);
|
|
@@ -2068,24 +2080,6 @@ const MRT_TableBodyCell = ({ cell, enableHover, rowIndex, rowRef, table, }) => {
|
|
|
2068
2080
|
setHoveredColumn(columnDef.enableColumnOrdering !== false ? column : null);
|
|
2069
2081
|
}
|
|
2070
2082
|
};
|
|
2071
|
-
const draggingBorder = (draggingColumn === null || draggingColumn === void 0 ? void 0 : draggingColumn.id) === column.id
|
|
2072
|
-
? `1px dashed ${theme.palette.text.secondary}`
|
|
2073
|
-
: (hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === column.id
|
|
2074
|
-
? `2px dashed ${theme.palette.primary.main}`
|
|
2075
|
-
: undefined;
|
|
2076
|
-
const draggingBorders = draggingBorder
|
|
2077
|
-
? {
|
|
2078
|
-
borderLeft: draggingBorder,
|
|
2079
|
-
borderRight: draggingBorder,
|
|
2080
|
-
borderBottom: row.index ===
|
|
2081
|
-
(enablePagination
|
|
2082
|
-
? table.getRowModel()
|
|
2083
|
-
: table.getPrePaginationRowModel()).rows.length -
|
|
2084
|
-
1
|
|
2085
|
-
? draggingBorder
|
|
2086
|
-
: undefined,
|
|
2087
|
-
}
|
|
2088
|
-
: undefined;
|
|
2089
2083
|
return (React.createElement(TableCell, Object.assign({}, tableCellProps, { onDragEnter: handleDragEnter, onDoubleClick: handleDoubleClick, sx: (theme) => (Object.assign(Object.assign({ cursor: isEditable && editingMode === 'cell' ? 'pointer' : 'inherit', overflow: 'hidden', p: density === 'compact'
|
|
2090
2084
|
? columnDefType === 'display'
|
|
2091
2085
|
? '0 0.5rem'
|
|
@@ -2142,8 +2136,7 @@ const MRT_TableDetailPanel = ({ row, table }) => {
|
|
|
2142
2136
|
: tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.sx))) }), renderDetailPanel && (React.createElement(Collapse, { in: row.getIsExpanded() }, renderDetailPanel({ row, table }))))));
|
|
2143
2137
|
};
|
|
2144
2138
|
|
|
2145
|
-
const MRT_TableBodyRow = ({ row, rowIndex, table, virtualRow, }) => {
|
|
2146
|
-
var _a, _b;
|
|
2139
|
+
const MRT_TableBodyRow = ({ numRows, row, rowIndex, table, virtualRow, }) => {
|
|
2147
2140
|
const theme = useTheme();
|
|
2148
2141
|
const { getIsSomeColumnsPinned, getState, options: { enableRowOrdering, memoMode, muiTableBodyRowProps, renderDetailPanel, }, setHoveredRow, } = table;
|
|
2149
2142
|
const { draggingColumn, draggingRow, editingCell, editingRow, hoveredRow } = getState();
|
|
@@ -2156,11 +2149,11 @@ const MRT_TableBodyRow = ({ row, rowIndex, table, virtualRow, }) => {
|
|
|
2156
2149
|
}
|
|
2157
2150
|
};
|
|
2158
2151
|
const rowRef = useRef(null);
|
|
2159
|
-
const draggingBorder = (draggingRow === null || draggingRow === void 0 ? void 0 : draggingRow.id) === row.id
|
|
2152
|
+
const draggingBorder = useMemo(() => (draggingRow === null || draggingRow === void 0 ? void 0 : draggingRow.id) === row.id
|
|
2160
2153
|
? `1px dashed ${theme.palette.text.secondary}`
|
|
2161
2154
|
: (hoveredRow === null || hoveredRow === void 0 ? void 0 : hoveredRow.id) === row.id
|
|
2162
2155
|
? `2px dashed ${theme.palette.primary.main}`
|
|
2163
|
-
: undefined;
|
|
2156
|
+
: undefined, [draggingRow, hoveredRow]);
|
|
2164
2157
|
const draggingBorders = draggingBorder
|
|
2165
2158
|
? {
|
|
2166
2159
|
border: draggingBorder,
|
|
@@ -2180,16 +2173,17 @@ const MRT_TableBodyRow = ({ row, rowIndex, table, virtualRow, }) => {
|
|
|
2180
2173
|
: undefined,
|
|
2181
2174
|
} }, ((tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.sx) instanceof Function
|
|
2182
2175
|
? tableRowProps.sx(theme)
|
|
2183
|
-
: tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.sx)), draggingBorders)) }),
|
|
2176
|
+
: tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.sx)), draggingBorders)) }), row.getVisibleCells().map((cell) => {
|
|
2184
2177
|
const props = {
|
|
2185
2178
|
cell,
|
|
2186
2179
|
enableHover: (tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.hover) !== false,
|
|
2187
2180
|
key: cell.id,
|
|
2181
|
+
numRows,
|
|
2188
2182
|
rowIndex,
|
|
2189
2183
|
rowRef,
|
|
2190
2184
|
table,
|
|
2191
2185
|
};
|
|
2192
|
-
return memoMode === '
|
|
2186
|
+
return memoMode === 'cells' &&
|
|
2193
2187
|
cell.column.columnDef.columnDefType === 'data' &&
|
|
2194
2188
|
!draggingColumn &&
|
|
2195
2189
|
!draggingRow &&
|
|
@@ -2288,6 +2282,7 @@ const MRT_TableBody = ({ table }) => {
|
|
|
2288
2282
|
: rowOrVirtualRow;
|
|
2289
2283
|
const props = {
|
|
2290
2284
|
key: row.id,
|
|
2285
|
+
numRows: rows.length,
|
|
2291
2286
|
row,
|
|
2292
2287
|
rowIndex: enableRowVirtualization
|
|
2293
2288
|
? rowOrVirtualRow.index
|
|
@@ -2295,12 +2290,12 @@ const MRT_TableBody = ({ table }) => {
|
|
|
2295
2290
|
table,
|
|
2296
2291
|
virtualRow: enableRowVirtualization ? rowOrVirtualRow : null,
|
|
2297
2292
|
};
|
|
2298
|
-
return memoMode === '
|
|
2293
|
+
return memoMode === 'rows' ? (React.createElement(Memo_MRT_TableBodyRow, Object.assign({}, props))) : (React.createElement(MRT_TableBodyRow, Object.assign({}, props)));
|
|
2299
2294
|
}),
|
|
2300
2295
|
enableRowVirtualization && paddingBottom > 0 && (React.createElement("tr", null,
|
|
2301
2296
|
React.createElement("td", { style: { height: `${paddingBottom}px` } })))))));
|
|
2302
2297
|
};
|
|
2303
|
-
const Memo_MRT_TableBody = memo(MRT_TableBody, () =>
|
|
2298
|
+
const Memo_MRT_TableBody = memo(MRT_TableBody, (prev, next) => prev.table.options.data === next.table.options.data);
|
|
2304
2299
|
|
|
2305
2300
|
const MRT_TableFooterCell = ({ footer, table }) => {
|
|
2306
2301
|
var _a, _b, _c;
|