material-react-table 0.8.12 → 0.8.13

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 React, { useMemo, useState, useCallback, Fragment, forwardRef, useLayoutEffect, useEffect } from 'react';
1
+ import React, { useMemo, forwardRef, useState, useCallback, Fragment, useLayoutEffect, useEffect } from 'react';
2
2
  import { ArrowRight, Cancel, CheckBox, ClearAll, Close, DensityMedium, DensitySmall, KeyboardDoubleArrowDown, DragHandle, DynamicFeed, Edit, ExpandLess, ExpandMore, FilterAlt, FilterAltOff, FilterList, FilterListOff, FullscreenExit, Fullscreen, MoreHoriz, MoreVert, PushPin, RestartAlt, Save, Search, SearchOff, Sort, ViewColumn, VisibilityOff } from '@mui/icons-material';
3
3
  import { createTable, useTableInstance, getCoreRowModel, getExpandedRowModel, getFacetedRowModel, getFilteredRowModel, getGroupedRowModel, getPaginationRowModel, getSortedRowModel } from '@tanstack/react-table';
4
4
  import { Tooltip, IconButton, Menu, MenuItem, Box, FormControlLabel, Switch, Button, Divider, ListItemIcon, Checkbox, debounce, Collapse, TextField, InputAdornment, TablePagination, Chip, Alert, LinearProgress, useMediaQuery, Toolbar, lighten, alpha, TableSortLabel, TableCell, TableRow, TableHead, darken, Skeleton, TableBody, TableFooter, Table, TableContainer, Paper, Dialog, Grow } from '@mui/material';
@@ -503,7 +503,7 @@ var MRT_ColumnPinningButtons = function MRT_ColumnPinningButtons(_ref) {
503
503
 
504
504
  return React.createElement(Box, {
505
505
  sx: {
506
- mr: '8px'
506
+ mr: '4px'
507
507
  }
508
508
  }, column.getIsPinned() ? React.createElement(Tooltip, {
509
509
  arrow: true,
@@ -540,20 +540,89 @@ var MRT_ColumnPinningButtons = function MRT_ColumnPinningButtons(_ref) {
540
540
  })))));
541
541
  };
542
542
 
543
+ var MRT_GrabHandleButton = /*#__PURE__*/forwardRef(function (_ref, ref) {
544
+ var tableInstance = _ref.tableInstance;
545
+ var _tableInstance$option = tableInstance.options,
546
+ DragHandleIcon = _tableInstance$option.icons.DragHandleIcon,
547
+ localization = _tableInstance$option.localization;
548
+ return React.createElement(Tooltip, {
549
+ arrow: true,
550
+ enterDelay: 1000,
551
+ enterNextDelay: 1000,
552
+ placement: "top",
553
+ title: localization.grab
554
+ }, React.createElement(IconButton, {
555
+ disableRipple: true,
556
+ ref: ref,
557
+ size: "small",
558
+ sx: {
559
+ cursor: 'grab',
560
+ m: 0,
561
+ opacity: 0.5,
562
+ p: '2px',
563
+ transition: 'all 0.2s ease-in-out',
564
+ '&:hover': {
565
+ backgroundColor: 'transparent',
566
+ opacity: 1
567
+ },
568
+ '&:active': {
569
+ cursor: 'grabbing'
570
+ }
571
+ }
572
+ }, React.createElement(DragHandleIcon, null)));
573
+ });
574
+
543
575
  var MRT_ShowHideColumnsMenuItems = function MRT_ShowHideColumnsMenuItems(_ref) {
544
576
  var _column$columns2;
545
577
 
546
- var column = _ref.column,
578
+ var allColumns = _ref.allColumns,
579
+ column = _ref.column,
547
580
  isSubMenu = _ref.isSubMenu,
548
581
  tableInstance = _ref.tableInstance;
549
582
  var getState = tableInstance.getState,
550
- onToggleColumnVisibility = tableInstance.options.onToggleColumnVisibility;
583
+ _tableInstance$option = tableInstance.options,
584
+ enableColumnOrdering = _tableInstance$option.enableColumnOrdering,
585
+ onToggleColumnVisibility = _tableInstance$option.onToggleColumnVisibility,
586
+ setColumnOrder = tableInstance.setColumnOrder;
551
587
 
552
588
  var _getState = getState(),
589
+ columnOrder = _getState.columnOrder,
553
590
  columnVisibility = _getState.columnVisibility;
554
591
 
555
592
  var columnDef = column.columnDef,
556
593
  columnDefType = column.columnDefType;
594
+
595
+ var reorder = function reorder(movingColumn, receivingColumn) {
596
+ if (movingColumn.getCanPin()) {
597
+ movingColumn.pin(receivingColumn.getIsPinned());
598
+ }
599
+
600
+ columnOrder.splice(columnOrder.indexOf(receivingColumn.id), 0, columnOrder.splice(columnOrder.indexOf(movingColumn.id), 1)[0]);
601
+ setColumnOrder([].concat(columnOrder));
602
+ };
603
+
604
+ var _useDrop = useDrop({
605
+ accept: 'column',
606
+ drop: function drop(movingColumn) {
607
+ return reorder(movingColumn, column);
608
+ }
609
+ }),
610
+ dropRef = _useDrop[1];
611
+
612
+ var _useDrag = useDrag({
613
+ collect: function collect(monitor) {
614
+ return {
615
+ isDragging: monitor.isDragging()
616
+ };
617
+ },
618
+ item: function item() {
619
+ return column;
620
+ },
621
+ type: 'column'
622
+ }),
623
+ dragRef = _useDrag[1],
624
+ previewRef = _useDrag[2];
625
+
557
626
  var switchChecked = columnDefType !== 'group' && column.getIsVisible() || columnDefType === 'group' && column.getLeafColumns().some(function (col) {
558
627
  return col.getIsVisible();
559
628
  });
@@ -577,6 +646,7 @@ var MRT_ShowHideColumnsMenuItems = function MRT_ShowHideColumnsMenuItems(_ref) {
577
646
  };
578
647
 
579
648
  return React.createElement(React.Fragment, null, React.createElement(MenuItem, {
649
+ ref: columnDefType === 'data' ? dropRef : undefined,
580
650
  sx: {
581
651
  alignItems: 'center',
582
652
  justifyContent: 'flex-start',
@@ -584,14 +654,25 @@ var MRT_ShowHideColumnsMenuItems = function MRT_ShowHideColumnsMenuItems(_ref) {
584
654
  pl: (column.depth + 0.5) * 2 + "rem",
585
655
  py: '6px'
586
656
  }
587
- }, !isSubMenu && column.getCanPin() && React.createElement(MRT_ColumnPinningButtons, {
657
+ }, React.createElement(Box, {
658
+ ref: previewRef,
659
+ sx: {
660
+ display: 'flex',
661
+ flexWrap: 'nowrap'
662
+ }
663
+ }, columnDefType !== 'group' && enableColumnOrdering && columnDef.enableColumnOrdering !== false && !allColumns.some(function (col) {
664
+ return col.columnDefType === 'group';
665
+ }) && React.createElement(MRT_GrabHandleButton, {
666
+ ref: dragRef,
667
+ tableInstance: tableInstance
668
+ }), !isSubMenu && column.getCanPin() && React.createElement(MRT_ColumnPinningButtons, {
588
669
  column: column,
589
670
  tableInstance: tableInstance
590
671
  }), React.createElement(FormControlLabel, {
591
672
  componentsProps: {
592
673
  typography: {
593
674
  sx: {
594
- marginBottom: 0,
675
+ mb: 0,
595
676
  opacity: columnDefType !== 'display' ? 1 : 0.5
596
677
  }
597
678
  }
@@ -602,9 +683,13 @@ var MRT_ShowHideColumnsMenuItems = function MRT_ShowHideColumnsMenuItems(_ref) {
602
683
  label: columnDef.header,
603
684
  onChange: function onChange() {
604
685
  return handleToggleColumnHidden(column);
686
+ },
687
+ sx: {
688
+ ml: '4px'
605
689
  }
606
- })), (_column$columns2 = column.columns) == null ? void 0 : _column$columns2.map(function (c, i) {
690
+ }))), (_column$columns2 = column.columns) == null ? void 0 : _column$columns2.map(function (c, i) {
607
691
  return React.createElement(MRT_ShowHideColumnsMenuItems, {
692
+ allColumns: allColumns,
608
693
  key: i + "-" + c.id,
609
694
  column: c,
610
695
  isSubMenu: isSubMenu,
@@ -695,6 +780,7 @@ var MRT_ShowHideColumnsMenu = function MRT_ShowHideColumnsMenu(_ref) {
695
780
  }
696
781
  }, localization.showAll)), React.createElement(Divider, null), allColumns.map(function (column, index) {
697
782
  return React.createElement(MRT_ShowHideColumnsMenuItems, {
783
+ allColumns: allColumns,
698
784
  column: column,
699
785
  isSubMenu: isSubMenu,
700
786
  key: index + "-" + column.id,
@@ -2074,38 +2160,6 @@ var MRT_TableHeadCellFilterLabel = function MRT_TableHeadCellFilterLabel(_ref) {
2074
2160
  }, showFilters && !column.getFilterValue() ? React.createElement(FilterAltOffIcon, null) : React.createElement(FilterAltIcon, null)));
2075
2161
  };
2076
2162
 
2077
- var MRT_TableHeadCellGrabHandle = /*#__PURE__*/forwardRef(function (_ref, ref) {
2078
- var tableInstance = _ref.tableInstance;
2079
- var _tableInstance$option = tableInstance.options,
2080
- DragHandleIcon = _tableInstance$option.icons.DragHandleIcon,
2081
- localization = _tableInstance$option.localization;
2082
- return React.createElement(Tooltip, {
2083
- arrow: true,
2084
- enterDelay: 1000,
2085
- enterNextDelay: 1000,
2086
- placement: "top",
2087
- title: localization.grab
2088
- }, React.createElement(IconButton, {
2089
- disableRipple: true,
2090
- ref: ref,
2091
- size: "small",
2092
- sx: {
2093
- cursor: 'grab',
2094
- m: 0,
2095
- opacity: 0.5,
2096
- p: '2px',
2097
- transition: 'all 0.2s ease-in-out',
2098
- '&:hover': {
2099
- backgroundColor: 'transparent',
2100
- opacity: 1
2101
- },
2102
- '&:active': {
2103
- cursor: 'grabbing'
2104
- }
2105
- }
2106
- }, React.createElement(DragHandleIcon, null)));
2107
- });
2108
-
2109
2163
  var MRT_TableHeadCellResizeHandle = function MRT_TableHeadCellResizeHandle(_ref) {
2110
2164
  var header = _ref.header,
2111
2165
  tableInstance = _ref.tableInstance;
@@ -2339,8 +2393,7 @@ var MRT_TableHeadCell = function MRT_TableHeadCell(_ref) {
2339
2393
  sx: {
2340
2394
  whiteSpace: 'nowrap'
2341
2395
  }
2342
- }, columnDefType === 'data' && (enableColumnOrdering && columnDef.enableColumnOrdering !== false || enableGrouping && columnDef.enableGrouping !== false) && React.createElement(MRT_TableHeadCellGrabHandle, {
2343
- header: header,
2396
+ }, columnDefType === 'data' && (enableColumnOrdering && columnDef.enableColumnOrdering !== false || enableGrouping && columnDef.enableGrouping !== false) && React.createElement(MRT_GrabHandleButton, {
2344
2397
  ref: dragRef,
2345
2398
  tableInstance: tableInstance
2346
2399
  }), (enableColumnActions || columnDef.enableColumnActions) && columnDef.enableColumnActions !== false && columnDefType !== 'group' && React.createElement(MRT_ToggleColumnActionMenuButton, {
@@ -2372,8 +2425,7 @@ var MRT_DraggableTableHeadCell = function MRT_DraggableTableHeadCell(_ref) {
2372
2425
  movingHeader.column.pin(receivingHeader.column.getIsPinned());
2373
2426
  }
2374
2427
 
2375
- var currentIndex = movingHeader.index;
2376
- columnOrder.splice(receivingHeader.index, 0, columnOrder.splice(currentIndex, 1)[0]);
2428
+ columnOrder.splice(receivingHeader.index, 0, columnOrder.splice(movingHeader.index, 1)[0]);
2377
2429
  setColumnOrder([].concat(columnOrder));
2378
2430
  };
2379
2431