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
|
@@ -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);
|
package/dist/cjs/index.js
CHANGED
|
@@ -1760,19 +1760,11 @@ const MRT_TableHeadCell = ({ header, table }) => {
|
|
|
1760
1760
|
? columnDef.muiTableHeadCellProps({ column, table })
|
|
1761
1761
|
: columnDef.muiTableHeadCellProps;
|
|
1762
1762
|
const tableCellProps = Object.assign(Object.assign({}, mTableHeadCellProps), mcTableHeadCellProps);
|
|
1763
|
-
const
|
|
1764
|
-
if (enableGrouping && (hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === 'drop-zone') {
|
|
1765
|
-
setHoveredColumn(null);
|
|
1766
|
-
}
|
|
1767
|
-
if (enableColumnOrdering && draggingColumn && columnDefType !== 'group') {
|
|
1768
|
-
setHoveredColumn(columnDef.enableColumnOrdering !== false ? column : null);
|
|
1769
|
-
}
|
|
1770
|
-
};
|
|
1771
|
-
const draggingBorder = (draggingColumn === null || draggingColumn === void 0 ? void 0 : draggingColumn.id) === column.id
|
|
1763
|
+
const draggingBorder = React.useMemo(() => (draggingColumn === null || draggingColumn === void 0 ? void 0 : draggingColumn.id) === column.id
|
|
1772
1764
|
? `1px dashed ${theme.palette.text.secondary}`
|
|
1773
1765
|
: (hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === column.id
|
|
1774
1766
|
? `2px dashed ${theme.palette.primary.main}`
|
|
1775
|
-
: undefined;
|
|
1767
|
+
: undefined, [draggingColumn, hoveredColumn]);
|
|
1776
1768
|
const draggingBorders = draggingBorder
|
|
1777
1769
|
? {
|
|
1778
1770
|
borderLeft: draggingBorder,
|
|
@@ -1780,6 +1772,14 @@ const MRT_TableHeadCell = ({ header, table }) => {
|
|
|
1780
1772
|
borderTop: draggingBorder,
|
|
1781
1773
|
}
|
|
1782
1774
|
: undefined;
|
|
1775
|
+
const handleDragEnter = (_e) => {
|
|
1776
|
+
if (enableGrouping && (hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === 'drop-zone') {
|
|
1777
|
+
setHoveredColumn(null);
|
|
1778
|
+
}
|
|
1779
|
+
if (enableColumnOrdering && draggingColumn && columnDefType !== 'group') {
|
|
1780
|
+
setHoveredColumn(columnDef.enableColumnOrdering !== false ? column : null);
|
|
1781
|
+
}
|
|
1782
|
+
};
|
|
1783
1783
|
const headerElement = ((_b = ((columnDef === null || columnDef === void 0 ? void 0 : columnDef.Header) instanceof Function
|
|
1784
1784
|
? (_a = columnDef === null || columnDef === void 0 ? void 0 : columnDef.Header) === null || _a === void 0 ? void 0 : _a.call(columnDef, {
|
|
1785
1785
|
column,
|
|
@@ -2018,10 +2018,10 @@ const MRT_TableBodyCellValue = ({ cell, table }) => {
|
|
|
2018
2018
|
: (_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()));
|
|
2019
2019
|
};
|
|
2020
2020
|
|
|
2021
|
-
const MRT_TableBodyCell = ({ cell, enableHover, rowIndex, rowRef, table, }) => {
|
|
2021
|
+
const MRT_TableBodyCell = ({ cell, enableHover, numRows, rowIndex, rowRef, table, }) => {
|
|
2022
2022
|
var _a, _b;
|
|
2023
2023
|
const theme = material.useTheme();
|
|
2024
|
-
const { getState, options: { editingMode, enableClickToCopy, enableColumnOrdering, enableEditing, enableGrouping,
|
|
2024
|
+
const { getState, options: { editingMode, enableClickToCopy, enableColumnOrdering, enableEditing, enableGrouping, enableRowNumbers, muiTableBodyCellProps, muiTableBodyCellSkeletonProps, rowNumberMode, }, refs: { editInputRefs }, setEditingCell, setHoveredColumn, } = table;
|
|
2025
2025
|
const { draggingColumn, editingCell, editingRow, hoveredColumn, density, isLoading, showSkeletons, } = getState();
|
|
2026
2026
|
const { column, row } = cell;
|
|
2027
2027
|
const { columnDef } = column;
|
|
@@ -2036,6 +2036,25 @@ const MRT_TableBodyCell = ({ cell, enableHover, rowIndex, rowRef, table, }) => {
|
|
|
2036
2036
|
const skeletonProps = muiTableBodyCellSkeletonProps instanceof Function
|
|
2037
2037
|
? muiTableBodyCellSkeletonProps({ cell, column, row, table })
|
|
2038
2038
|
: muiTableBodyCellSkeletonProps;
|
|
2039
|
+
const [skeletonWidth, setSkeletonWidth] = React.useState(0);
|
|
2040
|
+
React.useEffect(() => setSkeletonWidth(isLoading || showSkeletons
|
|
2041
|
+
? columnDefType === 'display'
|
|
2042
|
+
? column.getSize() / 2
|
|
2043
|
+
: Math.round(Math.random() * (column.getSize() - column.getSize() / 3) +
|
|
2044
|
+
column.getSize() / 3)
|
|
2045
|
+
: 100), []);
|
|
2046
|
+
const draggingBorder = React.useMemo(() => (draggingColumn === null || draggingColumn === void 0 ? void 0 : draggingColumn.id) === column.id
|
|
2047
|
+
? `1px dashed ${theme.palette.text.secondary}`
|
|
2048
|
+
: (hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === column.id
|
|
2049
|
+
? `2px dashed ${theme.palette.primary.main}`
|
|
2050
|
+
: undefined, [draggingColumn, hoveredColumn]);
|
|
2051
|
+
const draggingBorders = React.useMemo(() => draggingBorder
|
|
2052
|
+
? {
|
|
2053
|
+
borderLeft: draggingBorder,
|
|
2054
|
+
borderRight: draggingBorder,
|
|
2055
|
+
borderBottom: rowIndex === numRows - 1 ? draggingBorder : undefined,
|
|
2056
|
+
}
|
|
2057
|
+
: undefined, [draggingBorder, numRows]);
|
|
2039
2058
|
const isEditable = (enableEditing || columnDef.enableEditing) &&
|
|
2040
2059
|
columnDef.enableEditing !== false;
|
|
2041
2060
|
const isEditing = isEditable &&
|
|
@@ -2043,13 +2062,6 @@ const MRT_TableBodyCell = ({ cell, enableHover, rowIndex, rowRef, table, }) => {
|
|
|
2043
2062
|
(editingMode === 'table' ||
|
|
2044
2063
|
(editingRow === null || editingRow === void 0 ? void 0 : editingRow.id) === row.id ||
|
|
2045
2064
|
(editingCell === null || editingCell === void 0 ? void 0 : editingCell.id) === cell.id);
|
|
2046
|
-
const [skeletonWidth, setSkeletonWidth] = React.useState(0);
|
|
2047
|
-
React.useEffect(() => setSkeletonWidth(isLoading || showSkeletons
|
|
2048
|
-
? columnDefType === 'display'
|
|
2049
|
-
? column.getSize() / 2
|
|
2050
|
-
: Math.round(Math.random() * (column.getSize() - column.getSize() / 3) +
|
|
2051
|
-
column.getSize() / 3)
|
|
2052
|
-
: 100), [isLoading, showSkeletons]);
|
|
2053
2065
|
const handleDoubleClick = (event) => {
|
|
2054
2066
|
var _a;
|
|
2055
2067
|
(_a = tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.onDoubleClick) === null || _a === void 0 ? void 0 : _a.call(tableCellProps, event);
|
|
@@ -2076,24 +2088,6 @@ const MRT_TableBodyCell = ({ cell, enableHover, rowIndex, rowRef, table, }) => {
|
|
|
2076
2088
|
setHoveredColumn(columnDef.enableColumnOrdering !== false ? column : null);
|
|
2077
2089
|
}
|
|
2078
2090
|
};
|
|
2079
|
-
const draggingBorder = (draggingColumn === null || draggingColumn === void 0 ? void 0 : draggingColumn.id) === column.id
|
|
2080
|
-
? `1px dashed ${theme.palette.text.secondary}`
|
|
2081
|
-
: (hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === column.id
|
|
2082
|
-
? `2px dashed ${theme.palette.primary.main}`
|
|
2083
|
-
: undefined;
|
|
2084
|
-
const draggingBorders = draggingBorder
|
|
2085
|
-
? {
|
|
2086
|
-
borderLeft: draggingBorder,
|
|
2087
|
-
borderRight: draggingBorder,
|
|
2088
|
-
borderBottom: row.index ===
|
|
2089
|
-
(enablePagination
|
|
2090
|
-
? table.getRowModel()
|
|
2091
|
-
: table.getPrePaginationRowModel()).rows.length -
|
|
2092
|
-
1
|
|
2093
|
-
? draggingBorder
|
|
2094
|
-
: undefined,
|
|
2095
|
-
}
|
|
2096
|
-
: undefined;
|
|
2097
2091
|
return (React__default["default"].createElement(material.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'
|
|
2098
2092
|
? columnDefType === 'display'
|
|
2099
2093
|
? '0 0.5rem'
|
|
@@ -2150,8 +2144,7 @@ const MRT_TableDetailPanel = ({ row, table }) => {
|
|
|
2150
2144
|
: tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.sx))) }), renderDetailPanel && (React__default["default"].createElement(material.Collapse, { in: row.getIsExpanded() }, renderDetailPanel({ row, table }))))));
|
|
2151
2145
|
};
|
|
2152
2146
|
|
|
2153
|
-
const MRT_TableBodyRow = ({ row, rowIndex, table, virtualRow, }) => {
|
|
2154
|
-
var _a, _b;
|
|
2147
|
+
const MRT_TableBodyRow = ({ numRows, row, rowIndex, table, virtualRow, }) => {
|
|
2155
2148
|
const theme = material.useTheme();
|
|
2156
2149
|
const { getIsSomeColumnsPinned, getState, options: { enableRowOrdering, memoMode, muiTableBodyRowProps, renderDetailPanel, }, setHoveredRow, } = table;
|
|
2157
2150
|
const { draggingColumn, draggingRow, editingCell, editingRow, hoveredRow } = getState();
|
|
@@ -2164,11 +2157,11 @@ const MRT_TableBodyRow = ({ row, rowIndex, table, virtualRow, }) => {
|
|
|
2164
2157
|
}
|
|
2165
2158
|
};
|
|
2166
2159
|
const rowRef = React.useRef(null);
|
|
2167
|
-
const draggingBorder = (draggingRow === null || draggingRow === void 0 ? void 0 : draggingRow.id) === row.id
|
|
2160
|
+
const draggingBorder = React.useMemo(() => (draggingRow === null || draggingRow === void 0 ? void 0 : draggingRow.id) === row.id
|
|
2168
2161
|
? `1px dashed ${theme.palette.text.secondary}`
|
|
2169
2162
|
: (hoveredRow === null || hoveredRow === void 0 ? void 0 : hoveredRow.id) === row.id
|
|
2170
2163
|
? `2px dashed ${theme.palette.primary.main}`
|
|
2171
|
-
: undefined;
|
|
2164
|
+
: undefined, [draggingRow, hoveredRow]);
|
|
2172
2165
|
const draggingBorders = draggingBorder
|
|
2173
2166
|
? {
|
|
2174
2167
|
border: draggingBorder,
|
|
@@ -2188,16 +2181,17 @@ const MRT_TableBodyRow = ({ row, rowIndex, table, virtualRow, }) => {
|
|
|
2188
2181
|
: undefined,
|
|
2189
2182
|
} }, ((tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.sx) instanceof Function
|
|
2190
2183
|
? tableRowProps.sx(theme)
|
|
2191
|
-
: tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.sx)), draggingBorders)) }),
|
|
2184
|
+
: tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.sx)), draggingBorders)) }), row.getVisibleCells().map((cell) => {
|
|
2192
2185
|
const props = {
|
|
2193
2186
|
cell,
|
|
2194
2187
|
enableHover: (tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.hover) !== false,
|
|
2195
2188
|
key: cell.id,
|
|
2189
|
+
numRows,
|
|
2196
2190
|
rowIndex,
|
|
2197
2191
|
rowRef,
|
|
2198
2192
|
table,
|
|
2199
2193
|
};
|
|
2200
|
-
return memoMode === '
|
|
2194
|
+
return memoMode === 'cells' &&
|
|
2201
2195
|
cell.column.columnDef.columnDefType === 'data' &&
|
|
2202
2196
|
!draggingColumn &&
|
|
2203
2197
|
!draggingRow &&
|
|
@@ -2296,6 +2290,7 @@ const MRT_TableBody = ({ table }) => {
|
|
|
2296
2290
|
: rowOrVirtualRow;
|
|
2297
2291
|
const props = {
|
|
2298
2292
|
key: row.id,
|
|
2293
|
+
numRows: rows.length,
|
|
2299
2294
|
row,
|
|
2300
2295
|
rowIndex: enableRowVirtualization
|
|
2301
2296
|
? rowOrVirtualRow.index
|
|
@@ -2303,12 +2298,12 @@ const MRT_TableBody = ({ table }) => {
|
|
|
2303
2298
|
table,
|
|
2304
2299
|
virtualRow: enableRowVirtualization ? rowOrVirtualRow : null,
|
|
2305
2300
|
};
|
|
2306
|
-
return memoMode === '
|
|
2301
|
+
return memoMode === 'rows' ? (React__default["default"].createElement(Memo_MRT_TableBodyRow, Object.assign({}, props))) : (React__default["default"].createElement(MRT_TableBodyRow, Object.assign({}, props)));
|
|
2307
2302
|
}),
|
|
2308
2303
|
enableRowVirtualization && paddingBottom > 0 && (React__default["default"].createElement("tr", null,
|
|
2309
2304
|
React__default["default"].createElement("td", { style: { height: `${paddingBottom}px` } })))))));
|
|
2310
2305
|
};
|
|
2311
|
-
const Memo_MRT_TableBody = React.memo(MRT_TableBody, () =>
|
|
2306
|
+
const Memo_MRT_TableBody = React.memo(MRT_TableBody, (prev, next) => prev.table.options.data === next.table.options.data);
|
|
2312
2307
|
|
|
2313
2308
|
const MRT_TableFooterCell = ({ footer, table }) => {
|
|
2314
2309
|
var _a, _b, _c;
|