material-react-table 1.6.3 → 1.6.5

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/index.js CHANGED
@@ -295,6 +295,13 @@ const getDefaultColumnFilterFn = (columnDef) => {
295
295
  return 'equals';
296
296
  return 'fuzzy';
297
297
  };
298
+ const getIsFirstColumn = (column, table) => {
299
+ return table.getVisibleLeafColumns()[0].id === column.id;
300
+ };
301
+ const getIsLastColumn = (column, table) => {
302
+ const columns = table.getVisibleLeafColumns();
303
+ return columns[columns.length - 1].id === column.id;
304
+ };
298
305
  const getIsLastLeftPinnedColumn = (table, column) => {
299
306
  return (column.getIsPinned() === 'left' &&
300
307
  table.getLeftLeafHeaders().length - 1 === column.getPinnedIndex());
@@ -2281,7 +2288,7 @@ const MRT_TableBodyCell = ({ cell, enableHover, measureElement, numRows, rowInde
2281
2288
  var _a, _b;
2282
2289
  const theme = styles.useTheme();
2283
2290
  const { getState, options: { editingMode, enableClickToCopy, enableColumnOrdering, enableEditing, enableGrouping, enableRowNumbers, layoutMode, muiTableBodyCellProps, muiTableBodyCellSkeletonProps, rowNumberMode, }, refs: { editInputRefs }, setEditingCell, setHoveredColumn, } = table;
2284
- const { draggingColumn, editingCell, editingRow, hoveredColumn, density, isLoading, showSkeletons, } = getState();
2291
+ const { draggingColumn, draggingRow, editingCell, editingRow, hoveredColumn, hoveredRow, density, isLoading, showSkeletons, } = getState();
2285
2292
  const { column, row } = cell;
2286
2293
  const { columnDef } = column;
2287
2294
  const { columnDefType } = columnDef;
@@ -2302,18 +2309,38 @@ const MRT_TableBodyCell = ({ cell, enableHover, measureElement, numRows, rowInde
2302
2309
  : Math.round(Math.random() * (column.getSize() - column.getSize() / 3) +
2303
2310
  column.getSize() / 3)
2304
2311
  : 100), []);
2305
- const draggingBorder = React.useMemo(() => (draggingColumn === null || draggingColumn === void 0 ? void 0 : draggingColumn.id) === column.id
2306
- ? `1px dashed ${theme.palette.text.secondary}`
2307
- : (hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === column.id
2308
- ? `2px dashed ${theme.palette.primary.main}`
2309
- : undefined, [draggingColumn, hoveredColumn]);
2310
- const draggingBorders = React.useMemo(() => draggingBorder
2311
- ? {
2312
- borderLeft: draggingBorder,
2313
- borderRight: draggingBorder,
2314
- borderBottom: rowIndex === numRows - 1 ? draggingBorder : undefined,
2315
- }
2316
- : undefined, [draggingBorder, numRows]);
2312
+ const draggingBorders = React.useMemo(() => {
2313
+ const isDraggingColumn = (draggingColumn === null || draggingColumn === void 0 ? void 0 : draggingColumn.id) === column.id;
2314
+ const isHoveredColumn = (hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === column.id;
2315
+ const isDraggingRow = (draggingRow === null || draggingRow === void 0 ? void 0 : draggingRow.id) === row.id;
2316
+ const isHoveredRow = (hoveredRow === null || hoveredRow === void 0 ? void 0 : hoveredRow.id) === row.id;
2317
+ const isFirstColumn = getIsFirstColumn(column, table);
2318
+ const isLastColumn = getIsLastColumn(column, table);
2319
+ const isLastRow = rowIndex === numRows - 1;
2320
+ const borderStyle = isDraggingColumn || isDraggingRow
2321
+ ? `1px dashed ${theme.palette.text.secondary} !important`
2322
+ : isHoveredColumn || isHoveredRow
2323
+ ? `2px dashed ${theme.palette.primary.main} !important`
2324
+ : undefined;
2325
+ return borderStyle
2326
+ ? {
2327
+ borderLeft: isDraggingColumn ||
2328
+ isHoveredColumn ||
2329
+ ((isDraggingRow || isHoveredRow) && isFirstColumn)
2330
+ ? borderStyle
2331
+ : undefined,
2332
+ borderRight: isDraggingColumn ||
2333
+ isHoveredColumn ||
2334
+ ((isDraggingRow || isHoveredRow) && isLastColumn)
2335
+ ? borderStyle
2336
+ : undefined,
2337
+ borderBottom: isDraggingRow || isHoveredRow || isLastRow
2338
+ ? borderStyle
2339
+ : undefined,
2340
+ borderTop: isDraggingRow || isHoveredRow ? borderStyle : undefined,
2341
+ }
2342
+ : undefined;
2343
+ }, [draggingColumn, draggingRow, hoveredColumn, hoveredRow, rowIndex]);
2317
2344
  const isEditable = (enableEditing || columnDef.enableEditing) &&
2318
2345
  columnDef.enableEditing !== false;
2319
2346
  const isEditing = isEditable &&
@@ -2433,7 +2460,6 @@ const MRT_TableDetailPanel = ({ parentRowRef, row, table, virtualRow, }) => {
2433
2460
  };
2434
2461
 
2435
2462
  const MRT_TableBodyRow = ({ columnVirtualizer, measureElement, numRows, row, rowIndex, table, virtualColumns, virtualPaddingLeft, virtualPaddingRight, virtualRow, }) => {
2436
- const theme = styles.useTheme();
2437
2463
  const { getIsSomeColumnsPinned, getState, options: { enableRowOrdering, layoutMode, memoMode, muiTableBodyRowProps, renderDetailPanel, }, setHoveredRow, } = table;
2438
2464
  const { draggingColumn, draggingRow, editingCell, editingRow, hoveredRow } = getState();
2439
2465
  const tableRowProps = muiTableBodyRowProps instanceof Function
@@ -2445,23 +2471,13 @@ const MRT_TableBodyRow = ({ columnVirtualizer, measureElement, numRows, row, row
2445
2471
  }
2446
2472
  };
2447
2473
  const rowRef = React.useRef(null);
2448
- const draggingBorder = React.useMemo(() => (draggingRow === null || draggingRow === void 0 ? void 0 : draggingRow.id) === row.id
2449
- ? `1px dashed ${theme.palette.text.secondary}`
2450
- : (hoveredRow === null || hoveredRow === void 0 ? void 0 : hoveredRow.id) === row.id
2451
- ? `2px dashed ${theme.palette.primary.main}`
2452
- : undefined, [draggingRow, hoveredRow]);
2453
- const draggingBorders = draggingBorder
2454
- ? {
2455
- border: draggingBorder,
2456
- }
2457
- : undefined;
2458
2474
  return (React__default["default"].createElement(React__default["default"].Fragment, null,
2459
2475
  React__default["default"].createElement(TableRow__default["default"], Object.assign({ "data-index": virtualRow === null || virtualRow === void 0 ? void 0 : virtualRow.index, hover: true, onDragEnter: handleDragEnter, selected: row.getIsSelected(), ref: (node) => {
2460
2476
  if (node) {
2461
2477
  rowRef.current = node;
2462
2478
  measureElement === null || measureElement === void 0 ? void 0 : measureElement(node);
2463
2479
  }
2464
- } }, tableRowProps, { sx: (theme) => (Object.assign(Object.assign({ backgroundColor: styles.lighten(theme.palette.background.default, 0.06), display: layoutMode === 'grid' ? 'flex' : 'table-row', opacity: (draggingRow === null || draggingRow === void 0 ? void 0 : draggingRow.id) === row.id || (hoveredRow === null || hoveredRow === void 0 ? void 0 : hoveredRow.id) === row.id ? 0.5 : 1, position: virtualRow ? 'absolute' : undefined, top: virtualRow ? 0 : undefined, transform: virtualRow
2480
+ } }, tableRowProps, { sx: (theme) => (Object.assign({ backgroundColor: styles.lighten(theme.palette.background.default, 0.06), display: layoutMode === 'grid' ? 'flex' : 'table-row', opacity: (draggingRow === null || draggingRow === void 0 ? void 0 : draggingRow.id) === row.id || (hoveredRow === null || hoveredRow === void 0 ? void 0 : hoveredRow.id) === row.id ? 0.5 : 1, position: virtualRow ? 'absolute' : undefined, top: virtualRow ? 0 : undefined, transform: virtualRow
2465
2481
  ? `translateY(${virtualRow === null || virtualRow === void 0 ? void 0 : virtualRow.start}px)`
2466
2482
  : undefined, transition: virtualRow ? 'none' : 'all 150ms ease-in-out', width: '100%', '&:hover td': {
2467
2483
  backgroundColor: (tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.hover) !== false && getIsSomeColumnsPinned()
@@ -2471,7 +2487,7 @@ const MRT_TableBodyRow = ({ columnVirtualizer, measureElement, numRows, row, row
2471
2487
  : undefined,
2472
2488
  } }, ((tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.sx) instanceof Function
2473
2489
  ? tableRowProps.sx(theme)
2474
- : tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.sx)), draggingBorders)) }),
2490
+ : tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.sx))) }),
2475
2491
  virtualPaddingLeft ? (React__default["default"].createElement("td", { style: { display: 'flex', width: virtualPaddingLeft } })) : null,
2476
2492
  (virtualColumns !== null && virtualColumns !== void 0 ? virtualColumns : row.getVisibleCells()).map((cellOrVirtualCell) => {
2477
2493
  const cell = columnVirtualizer