material-react-table 1.0.0-beta.5 → 1.0.0-beta.6

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.
@@ -1,4 +1,4 @@
1
- import { Dispatch, DragEvent, MutableRefObject, ReactNode, SetStateAction } from 'react';
1
+ import { Dispatch, MutableRefObject, ReactNode, SetStateAction } from 'react';
2
2
  import type { AlertProps, ButtonProps, CheckboxProps, ChipProps, IconButtonProps, LinearProgressProps, PaperProps, SkeletonProps, TableBodyProps, TableCellProps, TableContainerProps, TableFooterProps, TableHeadProps, TablePaginationProps, TableProps, TableRowProps, TextFieldProps, ToolbarProps } from '@mui/material';
3
3
  import type { Cell, Column, ColumnDef, DeepKeys, FilterFn, Header, HeaderGroup, OnChangeFn, Row, SortingFn, Table, TableOptions, TableState } from '@tanstack/react-table';
4
4
  import type { Options as VirtualizerOptions, VirtualItem } from 'react-virtual';
@@ -40,6 +40,7 @@ export declare type MRT_TableInstance<TData extends Record<string, any> = {}> =
40
40
  filterInputRefs: MutableRefObject<Record<string, HTMLInputElement>>;
41
41
  searchInputRef: MutableRefObject<HTMLInputElement>;
42
42
  tableContainerRef: MutableRefObject<HTMLDivElement>;
43
+ tablePaperRef: MutableRefObject<HTMLDivElement>;
43
44
  topToolbarRef: MutableRefObject<HTMLDivElement>;
44
45
  };
45
46
  setColumnFilterFns: Dispatch<SetStateAction<{
@@ -439,13 +440,6 @@ export declare type MaterialReactTableProps<TData extends Record<string, any> =
439
440
  muiTopToolbarProps?: ToolbarProps | (({ table }: {
440
441
  table: MRT_TableInstance<TData>;
441
442
  }) => ToolbarProps);
442
- onColumnDrop?: ({ event, draggedColumn, targetColumn, }: {
443
- event: DragEvent<HTMLButtonElement>;
444
- draggedColumn: MRT_Column<TData>;
445
- targetColumn: MRT_Column<TData> | {
446
- id: string;
447
- } | null;
448
- }) => void;
449
443
  onDensityChange?: OnChangeFn<boolean>;
450
444
  onDraggingColumnChange?: OnChangeFn<MRT_Column<TData> | null>;
451
445
  onDraggingRowChange?: OnChangeFn<MRT_Row<TData> | null>;
@@ -464,13 +458,6 @@ export declare type MaterialReactTableProps<TData extends Record<string, any> =
464
458
  onHoveredColumnChange?: OnChangeFn<MRT_Column<TData> | null>;
465
459
  onHoveredRowChange?: OnChangeFn<MRT_Row<TData> | null>;
466
460
  onIsFullScreenChange?: OnChangeFn<boolean>;
467
- onRowDrop?: ({ event, draggedRow, targetRow, }: {
468
- event: DragEvent<HTMLButtonElement>;
469
- draggedRow: MRT_Row<TData>;
470
- targetRow: MRT_Row<TData> | {
471
- id: string;
472
- } | null;
473
- }) => void;
474
461
  onShowAlertBannerChange?: OnChangeFn<boolean>;
475
462
  onShowFiltersChange?: OnChangeFn<boolean>;
476
463
  onShowGlobalFilterChange?: OnChangeFn<boolean>;
@@ -471,11 +471,11 @@ const MRT_GrabHandleButton = ({ iconButtonProps, onDragEnd, onDragStart, table,
471
471
  var _a;
472
472
  const { options: { icons: { DragHandleIcon }, localization, }, } = table;
473
473
  return (React.createElement(Tooltip, { arrow: true, enterDelay: 1000, enterNextDelay: 1000, placement: "top", title: (_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.title) !== null && _a !== void 0 ? _a : localization.move },
474
- React.createElement(IconButton, Object.assign({ disableRipple: true, draggable: "true", onDragStart: onDragStart, onDragEnd: onDragEnd, size: "small" }, iconButtonProps, { onClick: (e) => {
474
+ React.createElement(IconButton, Object.assign({ disableRipple: true, draggable: "true", size: "small" }, iconButtonProps, { onClick: (e) => {
475
475
  var _a;
476
476
  e.stopPropagation();
477
477
  (_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.onClick) === null || _a === void 0 ? void 0 : _a.call(iconButtonProps, e);
478
- }, sx: (theme) => (Object.assign({ cursor: 'grab', m: 0, opacity: 0.5, p: '2px', transition: 'all 0.2s ease-in-out', '&:hover': {
478
+ }, onDragStart: onDragStart, onDragEnd: onDragEnd, sx: (theme) => (Object.assign({ cursor: 'grab', m: 0, opacity: 0.5, p: '2px', transition: 'all 0.2s ease-in-out', '&:hover': {
479
479
  backgroundColor: 'transparent',
480
480
  opacity: 1,
481
481
  }, '&:active': {
@@ -1304,7 +1304,11 @@ const MRT_TopToolbar = ({ table }) => {
1304
1304
  width: '100%',
1305
1305
  } },
1306
1306
  enableGlobalFilter && positionGlobalFilter === 'left' && (React.createElement(MRT_GlobalFilterTextField, { table: table })), (_a = renderTopToolbarCustomActions === null || renderTopToolbarCustomActions === void 0 ? void 0 : renderTopToolbarCustomActions({ table })) !== null && _a !== void 0 ? _a : React.createElement("span", null),
1307
- enableToolbarInternalActions ? (React.createElement(Box, { sx: { display: 'flex', flexWrap: 'wrap' } },
1307
+ enableToolbarInternalActions ? (React.createElement(Box, { sx: {
1308
+ display: 'flex',
1309
+ flexWrap: 'wrap-reverse',
1310
+ justifyContent: 'flex-end',
1311
+ } },
1308
1312
  enableGlobalFilter && positionGlobalFilter === 'right' && (React.createElement(MRT_GlobalFilterTextField, { table: table })),
1309
1313
  React.createElement(MRT_ToolbarInternalButtons, { table: table }))) : (enableGlobalFilter &&
1310
1314
  positionGlobalFilter === 'right' && (React.createElement(MRT_GlobalFilterTextField, { table: table })))),
@@ -1630,7 +1634,7 @@ const MRT_TableHeadCellFilterLabel = ({ header, table }) => {
1630
1634
  };
1631
1635
 
1632
1636
  const MRT_TableHeadCellGrabHandle = ({ column, table, tableHeadCellRef, }) => {
1633
- const { getState, options: { enableColumnOrdering, muiTableHeadCellDragHandleProps, onColumnDrop, }, setColumnOrder, setDraggingColumn, setHoveredColumn, } = table;
1637
+ const { getState, options: { enableColumnOrdering, muiTableHeadCellDragHandleProps }, setColumnOrder, setDraggingColumn, setHoveredColumn, } = table;
1634
1638
  const { columnDef } = column;
1635
1639
  const { hoveredColumn, draggingColumn, columnOrder } = getState();
1636
1640
  const mIconButtonProps = muiTableHeadCellDragHandleProps instanceof Function
@@ -1640,16 +1644,15 @@ const MRT_TableHeadCellGrabHandle = ({ column, table, tableHeadCellRef, }) => {
1640
1644
  ? columnDef.muiTableHeadCellDragHandleProps({ column, table })
1641
1645
  : columnDef.muiTableHeadCellDragHandleProps;
1642
1646
  const iconButtonProps = Object.assign(Object.assign({}, mIconButtonProps), mcIconButtonProps);
1643
- const handleDragStart = (e) => {
1647
+ const handleDragStart = (event) => {
1648
+ var _a;
1649
+ (_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.onDragStart) === null || _a === void 0 ? void 0 : _a.call(iconButtonProps, event);
1644
1650
  setDraggingColumn(column);
1645
- e.dataTransfer.setDragImage(tableHeadCellRef.current, 0, 0);
1651
+ event.dataTransfer.setDragImage(tableHeadCellRef.current, 0, 0);
1646
1652
  };
1647
1653
  const handleDragEnd = (event) => {
1648
- onColumnDrop === null || onColumnDrop === void 0 ? void 0 : onColumnDrop({
1649
- event,
1650
- draggedColumn: column,
1651
- targetColumn: hoveredColumn,
1652
- });
1654
+ var _a;
1655
+ (_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.onDragEnd) === null || _a === void 0 ? void 0 : _a.call(iconButtonProps, event);
1653
1656
  if ((hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === 'drop-zone') {
1654
1657
  column.toggleGrouping();
1655
1658
  }
@@ -1938,21 +1941,20 @@ const MRT_CopyButton = ({ cell, children, table, }) => {
1938
1941
  };
1939
1942
 
1940
1943
  const MRT_TableBodyRowGrabHandle = ({ cell, rowRef, table, }) => {
1941
- const { options: { muiTableBodyRowDragHandleProps, onRowDrop }, } = table;
1944
+ const { options: { muiTableBodyRowDragHandleProps }, } = table;
1942
1945
  const { row } = cell;
1943
1946
  const iconButtonProps = muiTableBodyRowDragHandleProps instanceof Function
1944
1947
  ? muiTableBodyRowDragHandleProps({ row, table })
1945
1948
  : muiTableBodyRowDragHandleProps;
1946
- const handleDragStart = (e) => {
1947
- e.dataTransfer.setDragImage(rowRef.current, 0, 0);
1949
+ const handleDragStart = (event) => {
1950
+ var _a;
1951
+ (_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.onDragStart) === null || _a === void 0 ? void 0 : _a.call(iconButtonProps, event);
1952
+ event.dataTransfer.setDragImage(rowRef.current, 0, 0);
1948
1953
  table.setDraggingRow(row);
1949
1954
  };
1950
1955
  const handleDragEnd = (event) => {
1951
- onRowDrop === null || onRowDrop === void 0 ? void 0 : onRowDrop({
1952
- event,
1953
- draggedRow: table.getState().draggingRow,
1954
- targetRow: table.getState().hoveredRow,
1955
- });
1956
+ var _a;
1957
+ (_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.onDragEnd) === null || _a === void 0 ? void 0 : _a.call(iconButtonProps, event);
1956
1958
  table.setDraggingRow(null);
1957
1959
  table.setHoveredRow(null);
1958
1960
  };
@@ -2157,7 +2159,8 @@ const MRT_TableBodyRow = ({ row, rowIndex, table, virtualRow, }) => {
2157
2159
  };
2158
2160
 
2159
2161
  const MRT_TableBody = ({ table }) => {
2160
- const { getRowModel, getPrePaginationRowModel, getState, options: { enableGlobalFilterRankedResults, enablePagination, enableRowVirtualization, localization, manualFiltering, manualSorting, muiTableBodyProps, virtualizerInstanceRef, virtualizerProps, }, refs: { tableContainerRef }, } = table;
2162
+ var _a;
2163
+ const { getRowModel, getPrePaginationRowModel, getState, options: { enableGlobalFilterRankedResults, enablePagination, enableRowVirtualization, localization, manualFiltering, manualSorting, muiTableBodyProps, virtualizerInstanceRef, virtualizerProps, }, refs: { tableContainerRef, tablePaperRef }, } = table;
2161
2164
  const { columnFilters, globalFilter, pagination, sorting } = getState();
2162
2165
  const tableBodyProps = muiTableBodyProps instanceof Function
2163
2166
  ? muiTableBodyProps({ table })
@@ -2223,10 +2226,12 @@ const MRT_TableBody = ({ table }) => {
2223
2226
  // ? virtualizer.getTotalSize() - virtualRows[virtualRows.length - 1].end
2224
2227
  // : 0;
2225
2228
  // }
2226
- return (React.createElement(TableBody, Object.assign({}, tableBodyProps), !rows.length ? (React.createElement(TableRow, null,
2227
- React.createElement(TableCell, { colSpan: table.getVisibleLeafColumns().length },
2228
- React.createElement(Box, { sx: {
2229
- maxWidth: '100vw',
2229
+ return (React.createElement(TableBody, Object.assign({}, tableBodyProps), !rows.length ? (React.createElement("tr", null,
2230
+ React.createElement("td", { colSpan: table.getVisibleLeafColumns().length },
2231
+ React.createElement(Typography, { sx: {
2232
+ color: 'text.secondary',
2233
+ fontStyle: 'italic',
2234
+ maxWidth: `min(100vw, ${(_a = tablePaperRef.current) === null || _a === void 0 ? void 0 : _a.clientWidth}px)`,
2230
2235
  py: '2rem',
2231
2236
  textAlign: 'center',
2232
2237
  width: '100%',
@@ -2354,7 +2359,7 @@ const MRT_TableContainer = ({ table }) => {
2354
2359
  };
2355
2360
 
2356
2361
  const MRT_TablePaper = ({ table }) => {
2357
- const { getState, options: { enableBottomToolbar, enableTopToolbar, muiTablePaperProps }, } = table;
2362
+ const { getState, options: { enableBottomToolbar, enableTopToolbar, muiTablePaperProps }, refs: { tablePaperRef }, } = table;
2358
2363
  const { isFullScreen } = getState();
2359
2364
  useEffect(() => {
2360
2365
  if (typeof window !== 'undefined') {
@@ -2369,7 +2374,13 @@ const MRT_TablePaper = ({ table }) => {
2369
2374
  const tablePaperProps = muiTablePaperProps instanceof Function
2370
2375
  ? muiTablePaperProps({ table })
2371
2376
  : muiTablePaperProps;
2372
- return (React.createElement(Paper, Object.assign({ elevation: 2 }, tablePaperProps, { sx: (theme) => (Object.assign({ transition: 'all 0.2s ease-in-out' }, ((tablePaperProps === null || tablePaperProps === void 0 ? void 0 : tablePaperProps.sx) instanceof Function
2377
+ return (React.createElement(Paper, Object.assign({ elevation: 2 }, tablePaperProps, { ref: (ref) => {
2378
+ tablePaperRef.current = ref;
2379
+ if (tablePaperProps === null || tablePaperProps === void 0 ? void 0 : tablePaperProps.ref) {
2380
+ //@ts-ignore
2381
+ tablePaperProps.ref.current = ref;
2382
+ }
2383
+ }, sx: (theme) => (Object.assign({ transition: 'all 0.2s ease-in-out' }, ((tablePaperProps === null || tablePaperProps === void 0 ? void 0 : tablePaperProps.sx) instanceof Function
2373
2384
  ? tablePaperProps === null || tablePaperProps === void 0 ? void 0 : tablePaperProps.sx(theme)
2374
2385
  : tablePaperProps === null || tablePaperProps === void 0 ? void 0 : tablePaperProps.sx))), style: Object.assign(Object.assign({}, tablePaperProps === null || tablePaperProps === void 0 ? void 0 : tablePaperProps.style), { height: isFullScreen ? '100vh' : undefined, margin: isFullScreen ? '0' : undefined, maxHeight: isFullScreen ? '100vh' : undefined, maxWidth: isFullScreen ? '100vw' : undefined, padding: isFullScreen ? '0' : undefined, width: isFullScreen ? '100vw' : undefined }) }),
2375
2386
  enableTopToolbar && React.createElement(MRT_TopToolbar, { table: table }),
@@ -2402,6 +2413,7 @@ const MRT_TableRoot = (props) => {
2402
2413
  const filterInputRefs = useRef({});
2403
2414
  const searchInputRef = useRef(null);
2404
2415
  const tableContainerRef = useRef(null);
2416
+ const tablePaperRef = useRef(null);
2405
2417
  const topToolbarRef = useRef(null);
2406
2418
  const initialState = useMemo(() => {
2407
2419
  var _a, _b;
@@ -2522,6 +2534,7 @@ const MRT_TableRoot = (props) => {
2522
2534
  filterInputRefs,
2523
2535
  searchInputRef,
2524
2536
  tableContainerRef,
2537
+ tablePaperRef,
2525
2538
  topToolbarRef,
2526
2539
  }, setColumnFilterFns: (_x = props.onFilterFnsChange) !== null && _x !== void 0 ? _x : setColumnFilterFns, setDensity: (_y = props.onDensityChange) !== null && _y !== void 0 ? _y : setDensity, setDraggingColumn: (_z = props.onDraggingColumnChange) !== null && _z !== void 0 ? _z : setDraggingColumn, setDraggingRow: (_0 = props.onDraggingRowChange) !== null && _0 !== void 0 ? _0 : setDraggingRow, setEditingCell: (_1 = props.onEditingCellChange) !== null && _1 !== void 0 ? _1 : setEditingCell, setEditingRow: (_2 = props.onEditingRowChange) !== null && _2 !== void 0 ? _2 : setEditingRow, setGlobalFilterFn: (_3 = props.onGlobalFilterFnChange) !== null && _3 !== void 0 ? _3 : setGlobalFilterFn, setHoveredColumn: (_4 = props.onHoveredColumnChange) !== null && _4 !== void 0 ? _4 : setHoveredColumn, setHoveredRow: (_5 = props.onHoveredRowChange) !== null && _5 !== void 0 ? _5 : setHoveredRow, setIsFullScreen: (_6 = props.onIsFullScreenChange) !== null && _6 !== void 0 ? _6 : setIsFullScreen, setShowAlertBanner: (_7 = props.onShowAlertBannerChange) !== null && _7 !== void 0 ? _7 : setShowAlertBanner, setShowFilters: (_8 = props.onShowFiltersChange) !== null && _8 !== void 0 ? _8 : setShowFilters, setShowGlobalFilter: (_9 = props.onShowGlobalFilterChange) !== null && _9 !== void 0 ? _9 : setShowGlobalFilter });
2527
2540
  if (props.tableInstanceRef) {