@dooherceg/material-react-table 3.2.6 → 3.2.8

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/index.esm.js CHANGED
@@ -1,25 +1,40 @@
1
1
  import { compareItems, rankItem, rankings } from '@tanstack/match-sorter-utils';
2
2
  import { sortingFns, flexRender as flexRender$1, createRow as createRow$1, aggregationFns, filterFns, getCoreRowModel, getExpandedRowModel, getFacetedMinMaxValues, getFacetedRowModel, getFacetedUniqueValues, getFilteredRowModel, getGroupedRowModel, getPaginationRowModel, getSortedRowModel, useReactTable, functionalUpdate } from '@tanstack/react-table';
3
- import { useMemo, useState, useCallback, useId, useReducer, useRef, useEffect, createContext, useContext, forwardRef, Fragment as Fragment$1, memo, useImperativeHandle } from 'react';
4
- import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
3
+ import { useMemo, useState, useSyncExternalStore, useCallback, useId, useReducer, useRef, useEffect, createContext, useContext, forwardRef, Fragment as Fragment$1, memo, useImperativeHandle } from 'react';
4
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
5
+ import CancelIcon from '@mui/icons-material/Cancel';
6
+ import Button from '@mui/material/Button';
7
+ import Dialog from '@mui/material/Dialog';
8
+ import DialogActions from '@mui/material/DialogActions';
9
+ import DialogContent from '@mui/material/DialogContent';
10
+ import DialogTitle from '@mui/material/DialogTitle';
5
11
  import IconButton from '@mui/material/IconButton';
6
- import Tooltip from '@mui/material/Tooltip';
12
+ import Stack from '@mui/material/Stack';
13
+ import DeleteOutlineIcon from '@mui/icons-material/DeleteOutline';
14
+ import EditNoteIcon from '@mui/icons-material/EditNote';
15
+ import FileDownloadIcon from '@mui/icons-material/FileDownload';
16
+ import PrintIcon from '@mui/icons-material/Print';
17
+ import Checkbox from '@mui/material/Checkbox';
18
+ import CircularProgress from '@mui/material/CircularProgress';
19
+ import Divider from '@mui/material/Divider';
20
+ import FormControl from '@mui/material/FormControl';
21
+ import FormControlLabel from '@mui/material/FormControlLabel';
7
22
  import Menu from '@mui/material/Menu';
23
+ import MenuItem from '@mui/material/MenuItem';
24
+ import Radio from '@mui/material/Radio';
25
+ import RadioGroup from '@mui/material/RadioGroup';
26
+ import { useTheme, darken, lighten, alpha } from '@mui/material/styles';
27
+ import Tooltip from '@mui/material/Tooltip';
28
+ import Typography from '@mui/material/Typography';
29
+ import printJS from 'print-js';
30
+ import { enqueueSnackbar, closeSnackbar, SnackbarProvider, useSnackbar } from 'notistack';
8
31
  import Box from '@mui/material/Box';
9
32
  import ListItemIcon from '@mui/material/ListItemIcon';
10
- import MenuItem from '@mui/material/MenuItem';
11
- import Button from '@mui/material/Button';
12
- import CircularProgress from '@mui/material/CircularProgress';
13
- import { darken, lighten, alpha, useTheme } from '@mui/material/styles';
14
- import Stack from '@mui/material/Stack';
15
33
  import SubdirectoryArrowLeftIcon from '@mui/icons-material/SubdirectoryArrowLeft';
16
34
  import VerticalAlignTopIcon from '@mui/icons-material/VerticalAlignTop';
17
- import Checkbox from '@mui/material/Checkbox';
18
- import Radio from '@mui/material/Radio';
19
35
  import AddIcon from '@mui/icons-material/Add';
20
36
  import ArrowDownwardIcon from '@mui/icons-material/ArrowDownward';
21
37
  import ArrowRightIcon from '@mui/icons-material/ArrowRight';
22
- import CancelIcon from '@mui/icons-material/Cancel';
23
38
  import ChevronLeftIcon from '@mui/icons-material/ChevronLeft';
24
39
  import ChevronRightIcon from '@mui/icons-material/ChevronRight';
25
40
  import ClearAllIcon from '@mui/icons-material/ClearAll';
@@ -51,15 +66,6 @@ import SortIcon from '@mui/icons-material/Sort';
51
66
  import SyncAltIcon from '@mui/icons-material/SyncAlt';
52
67
  import ViewColumnIcon from '@mui/icons-material/ViewColumn';
53
68
  import VisibilityOffIcon from '@mui/icons-material/VisibilityOff';
54
- import FileDownloadIcon from '@mui/icons-material/FileDownload';
55
- import PrintIcon from '@mui/icons-material/Print';
56
- import Divider from '@mui/material/Divider';
57
- import FormControl from '@mui/material/FormControl';
58
- import FormControlLabel from '@mui/material/FormControlLabel';
59
- import RadioGroup from '@mui/material/RadioGroup';
60
- import Typography from '@mui/material/Typography';
61
- import printJS from 'print-js';
62
- import { enqueueSnackbar, closeSnackbar, SnackbarProvider, useSnackbar } from 'notistack';
63
69
  import { defaultRangeExtractor, useVirtualizer } from '@tanstack/react-virtual';
64
70
  import Drawer from '@mui/material/Drawer';
65
71
  import TextField from '@mui/material/TextField';
@@ -104,10 +110,6 @@ import DeleteForeverIcon from '@mui/icons-material/DeleteForever';
104
110
  import Switch from '@mui/material/Switch';
105
111
  import Badge from '@mui/material/Badge';
106
112
  import TableContainer from '@mui/material/TableContainer';
107
- import Dialog from '@mui/material/Dialog';
108
- import DialogActions from '@mui/material/DialogActions';
109
- import DialogContent from '@mui/material/DialogContent';
110
- import DialogTitle from '@mui/material/DialogTitle';
111
113
  import Modal from '@mui/material/Modal';
112
114
  import Accordion from '@mui/material/Accordion';
113
115
  import AccordionDetails from '@mui/material/AccordionDetails';
@@ -721,99 +723,6 @@ const createRow = (table, originalRow, rowIndex = -1, depth = 0, subRows, parent
721
723
  [getColumnId(col)]: '',
722
724
  }))), rowIndex, depth, subRows, parentId);
723
725
 
724
- const MRT_AggregationFns = Object.assign({}, aggregationFns);
725
-
726
- const fuzzy = (row, columnId, filterValue, addMeta) => {
727
- const itemRank = rankItem(row.getValue(columnId), filterValue, {
728
- threshold: rankings.MATCHES,
729
- });
730
- addMeta(itemRank);
731
- return itemRank.passed;
732
- };
733
- fuzzy.autoRemove = (val) => !val;
734
- const contains = (row, id, filterValue) => {
735
- var _a;
736
- return !!((_a = row
737
- .getValue(id)) === null || _a === void 0 ? void 0 : _a.toString().toLowerCase().trim().includes(filterValue.toString().toLowerCase().trim()));
738
- };
739
- contains.autoRemove = (val) => !val;
740
- const startsWith = (row, id, filterValue) => {
741
- var _a;
742
- return !!((_a = row
743
- .getValue(id)) === null || _a === void 0 ? void 0 : _a.toString().toLowerCase().trim().startsWith(filterValue.toString().toLowerCase().trim()));
744
- };
745
- startsWith.autoRemove = (val) => !val;
746
- const endsWith = (row, id, filterValue) => {
747
- var _a;
748
- return !!((_a = row
749
- .getValue(id)) === null || _a === void 0 ? void 0 : _a.toString().toLowerCase().trim().endsWith(filterValue.toString().toLowerCase().trim()));
750
- };
751
- endsWith.autoRemove = (val) => !val;
752
- const equals = (row, id, filterValue) => {
753
- var _a;
754
- return ((_a = row.getValue(id)) === null || _a === void 0 ? void 0 : _a.toString().toLowerCase().trim()) ===
755
- filterValue.toString().toLowerCase().trim();
756
- };
757
- equals.autoRemove = (val) => !val;
758
- const notEquals = (row, id, filterValue) => {
759
- var _a;
760
- return ((_a = row.getValue(id)) === null || _a === void 0 ? void 0 : _a.toString().toLowerCase().trim()) !==
761
- filterValue.toString().toLowerCase().trim();
762
- };
763
- notEquals.autoRemove = (val) => !val;
764
- const greaterThan = (row, id, filterValue) => {
765
- var _a, _b, _c;
766
- return !isNaN(+filterValue) && !isNaN(+row.getValue(id))
767
- ? +((_a = row.getValue(id)) !== null && _a !== void 0 ? _a : 0) > +filterValue
768
- : ((_c = ((_b = row.getValue(id)) !== null && _b !== void 0 ? _b : '')) === null || _c === void 0 ? void 0 : _c.toString().toLowerCase().trim()) > filterValue.toString().toLowerCase().trim();
769
- };
770
- greaterThan.autoRemove = (val) => !val;
771
- const greaterThanOrEqualTo = (row, id, filterValue) => equals(row, id, filterValue) || greaterThan(row, id, filterValue);
772
- greaterThanOrEqualTo.autoRemove = (val) => !val;
773
- const lessThan = (row, id, filterValue) => {
774
- var _a, _b, _c;
775
- return !isNaN(+filterValue) && !isNaN(+row.getValue(id))
776
- ? +((_a = row.getValue(id)) !== null && _a !== void 0 ? _a : 0) < +filterValue
777
- : ((_c = ((_b = row.getValue(id)) !== null && _b !== void 0 ? _b : '')) === null || _c === void 0 ? void 0 : _c.toString().toLowerCase().trim()) < filterValue.toString().toLowerCase().trim();
778
- };
779
- lessThan.autoRemove = (val) => !val;
780
- const lessThanOrEqualTo = (row, id, filterValue) => equals(row, id, filterValue) || lessThan(row, id, filterValue);
781
- lessThanOrEqualTo.autoRemove = (val) => !val;
782
- const between = (row, id, filterValues) => (['', undefined].includes(filterValues[0]) ||
783
- greaterThan(row, id, filterValues[0])) &&
784
- ((!isNaN(+filterValues[0]) &&
785
- !isNaN(+filterValues[1]) &&
786
- +filterValues[0] > +filterValues[1]) ||
787
- ['', undefined].includes(filterValues[1]) ||
788
- lessThan(row, id, filterValues[1]));
789
- between.autoRemove = (val) => !val;
790
- const betweenInclusive = (row, id, filterValues) => (['', undefined].includes(filterValues[0]) ||
791
- greaterThanOrEqualTo(row, id, filterValues[0])) &&
792
- ((!isNaN(+filterValues[0]) &&
793
- !isNaN(+filterValues[1]) &&
794
- +filterValues[0] > +filterValues[1]) ||
795
- ['', undefined].includes(filterValues[1]) ||
796
- lessThanOrEqualTo(row, id, filterValues[1]));
797
- betweenInclusive.autoRemove = (val) => !val;
798
- const empty = (row, id, _filterValue) => { var _a; return !((_a = row.getValue(id)) === null || _a === void 0 ? void 0 : _a.toString().trim()); };
799
- empty.autoRemove = (val) => !val;
800
- const notEmpty = (row, id, _filterValue) => { var _a; return !!((_a = row.getValue(id)) === null || _a === void 0 ? void 0 : _a.toString().trim()); };
801
- notEmpty.autoRemove = (val) => !val;
802
- const MRT_FilterFns = Object.assign(Object.assign({}, filterFns), { between,
803
- betweenInclusive,
804
- contains,
805
- empty,
806
- endsWith,
807
- equals,
808
- fuzzy,
809
- greaterThan,
810
- greaterThanOrEqualTo,
811
- lessThan,
812
- lessThanOrEqualTo,
813
- notEmpty,
814
- notEquals,
815
- startsWith });
816
-
817
726
  /******************************************************************************
818
727
  Copyright (c) Microsoft Corporation.
819
728
 
@@ -858,1408 +767,1659 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
858
767
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
859
768
  };
860
769
 
861
- const MRT_ActionMenuItem = (_a) => {
862
- var { icon, label, onOpenSubMenu, table } = _a, rest = __rest(_a, ["icon", "label", "onOpenSubMenu", "table"]);
863
- const { options: { icons: { ArrowRightIcon }, }, } = table;
864
- return (jsxs(MenuItem, Object.assign({ sx: {
865
- alignItems: 'center',
866
- justifyContent: 'space-between',
867
- minWidth: '120px',
868
- my: 0,
869
- py: '6px',
870
- }, tabIndex: 0 }, rest, { children: [jsxs(Box, { sx: {
871
- alignItems: 'center',
872
- display: 'flex',
873
- }, children: [jsx(ListItemIcon, { children: icon }), label] }), onOpenSubMenu && (jsx(IconButton, { onClick: (e) => onOpenSubMenu(e), onMouseEnter: (e) => onOpenSubMenu(e), size: "small", sx: { p: 0 }, children: jsx(ArrowRightIcon, {}) }))] })));
770
+ function MRT_DeleteRowButton({ onClick, }) {
771
+ const iconButtonStyle = {
772
+ p: 0,
773
+ };
774
+ return (jsx(IconButton, { disableRipple: true, color: "error", sx: iconButtonStyle, onClick: onClick, children: jsx(DeleteOutlineIcon, {}) }));
775
+ }
776
+
777
+ const DeleteRowAction = ({ onDeleteConfirm, table, deleteConfirmation, }) => {
778
+ // Toolbar context — no specific row is targeted
779
+ const [open, setOpen] = useState(false);
780
+ const [deleting, setDeleting] = useState(false);
781
+ // Resolve deleteConfirmation — plain object, defaults to empty object.
782
+ const resolvedDeleteConfirmation = deleteConfirmation !== null && deleteConfirmation !== void 0 ? deleteConfirmation : {};
783
+ const { title: titleOverride, message: messageOverride, confirmButtonText: confirmButtonTextOverride, cancelButtonText: cancelButtonTextOverride, dialogSx, contentContainerSx, headerSx, titleSx, bodySx, footerSx, closeButtonProps, cancelButtonProps, confirmButtonProps, } = resolvedDeleteConfirmation;
784
+ // Consumer override takes priority over localization fallback.
785
+ const deleteConfirmationTitle = titleOverride !== null && titleOverride !== void 0 ? titleOverride : table.options.localization.deleteConfirmationTitle;
786
+ const deleteConfirmationMessage = messageOverride !== null && messageOverride !== void 0 ? messageOverride : table.options.localization.deleteConfirmationMessage;
787
+ const confirmButtonLabel = confirmButtonTextOverride !== null && confirmButtonTextOverride !== void 0 ? confirmButtonTextOverride : table.options.localization.deleteConfirmYes;
788
+ const cancelButtonLabel = cancelButtonTextOverride !== null && cancelButtonTextOverride !== void 0 ? cancelButtonTextOverride : table.options.localization.deleteConfirmNo;
789
+ const deletingLabel = table.options.localization.deleteConfirmDeleting;
790
+ const handleDeleteRowButtonClick = () => {
791
+ setOpen(true);
792
+ };
793
+ const handleConfirmDelete = () => __awaiter(void 0, void 0, void 0, function* () {
794
+ setDeleting(true);
795
+ yield onDeleteConfirm();
796
+ setDeleting(false);
797
+ setOpen(false);
798
+ });
799
+ const handleClose = () => __awaiter(void 0, void 0, void 0, function* () {
800
+ setOpen(false);
801
+ });
802
+ return (jsxs(Fragment, { children: [jsx(Dialog, { open: open, onClose: () => setOpen(false), keepMounted: true, "aria-describedby": "alert-dialog-slide-description", role: "alertdialog", sx: dialogSx, children: jsxs(Stack, { flexDirection: "column", height: "min-content", sx: contentContainerSx, children: [jsxs(Stack, { flexDirection: "row", alignItems: "center", justifyContent: "space-between", sx: Object.assign({ width: '100%' }, headerSx), children: [jsx(DialogTitle, { sx: Object.assign({ p: '0.7rem' }, titleSx), children: deleteConfirmationTitle }), jsx(DialogActions, { sx: {
803
+ p: '0.7rem',
804
+ }, children: jsx(IconButton, Object.assign({ color: "error", "aria-label": "close", onClick: handleClose }, closeButtonProps, { children: jsx(CancelIcon, {}) })) })] }), jsxs(Stack, { children: [jsx(DialogContent, { sx: Object.assign({ pr: '6rem' }, bodySx), children: deleteConfirmationMessage }), jsxs(DialogActions, { sx: footerSx, children: [jsx(Button, Object.assign({ onClick: () => setOpen(false), disabled: deleting, autoFocus: true, variant: "soft" }, cancelButtonProps, { children: cancelButtonLabel })), jsx(Button, Object.assign({ onClick: handleConfirmDelete, disabled: deleting, variant: "contained", color: "error" }, confirmButtonProps, { children: deleting ? deletingLabel : confirmButtonLabel }))] })] })] }) }), jsx(MRT_DeleteRowButton, { onClick: handleDeleteRowButtonClick })] }));
805
+ };
806
+
807
+ const createDeleteAction = (_a = {}) => {
808
+ var { onDelete, renderRow: customRenderRow, renderToolbar: customRenderToolbar, deleteConfirmation } = _a, rest = __rest(_a, ["onDelete", "renderRow", "renderToolbar", "deleteConfirmation"]);
809
+ // Default delete behavior used when the consumer does not provide a custom onDelete.
810
+ // Also exposed to custom onDelete through context.defaultOnDelete for composition.
811
+ const defaultOnDelete = (_a) => __awaiter(void 0, [_a], void 0, function* ({ rowsToDelete, table, }) {
812
+ var _b, _c;
813
+ // Nothing to delete, so exit early.
814
+ if (!rowsToDelete.length) {
815
+ return;
816
+ }
817
+ yield ((_c = (_b = table.options).deleteRowsFn) === null || _c === void 0 ? void 0 : _c.call(_b, { rowsToDelete, table }));
818
+ });
819
+ // Single execution pipeline for every delete flow (row or toolbar).
820
+ // If a custom handler exists, it receives defaultOnDelete and decides when to call it.
821
+ const executeDelete = (context) => {
822
+ const executeDefaultDelete = () => defaultOnDelete(context);
823
+ if (onDelete) {
824
+ return onDelete(Object.assign(Object.assign({}, context), { defaultOnDelete: executeDefaultDelete }));
825
+ }
826
+ return executeDefaultDelete();
827
+ };
828
+ // Resolves selected rows from table state for toolbar-triggered delete.
829
+ const handleMultipleRowDelete = ({ table, }) => {
830
+ const rowsToDelete = table.getSelectedRowModel().rows;
831
+ return executeDelete({ table, rowsToDelete });
832
+ };
833
+ // Resolves only the active row for row-triggered delete.
834
+ const handleSingleRowDelete = ({ table, row, }) => {
835
+ return executeDelete({ table, rowsToDelete: [row] });
836
+ };
837
+ // Wraps row context into a zero-argument callback expected by row action UI.
838
+ const createRowDeleteExecutor = (context) => {
839
+ return () => {
840
+ void handleSingleRowDelete(context);
841
+ };
842
+ };
843
+ // Wraps toolbar context into a zero-argument callback expected by toolbar action UI.
844
+ const createToolbarDeleteExecutor = (context) => {
845
+ return () => {
846
+ void handleMultipleRowDelete(context);
847
+ };
848
+ };
849
+ // Uses custom row renderer when provided; otherwise renders default delete action UI.
850
+ const renderRowAction = (context) => {
851
+ const onRowDelete = createRowDeleteExecutor(context);
852
+ if (customRenderRow) {
853
+ return customRenderRow(Object.assign(Object.assign({}, context), { onDelete: onRowDelete }));
854
+ }
855
+ return (jsx(DeleteRowAction, { onDeleteConfirm: onRowDelete, table: context.table, deleteConfirmation: deleteConfirmation }));
856
+ };
857
+ // Uses custom toolbar renderer when provided; otherwise renders default delete action UI.
858
+ const renderToolbarAction = (context) => {
859
+ const onToolbarDelete = createToolbarDeleteExecutor(context);
860
+ if (customRenderToolbar) {
861
+ return customRenderToolbar(Object.assign(Object.assign({}, context), { onDelete: onToolbarDelete }));
862
+ }
863
+ return (jsx(DeleteRowAction, { onDeleteConfirm: onToolbarDelete, table: context.table }));
864
+ };
865
+ return Object.assign({ name: 'delete', renderRow: renderRowAction, renderToolbar: renderToolbarAction }, rest);
874
866
  };
875
867
 
876
- const MRT_RowActionMenu = (_a) => {
877
- var { anchorEl, handleEdit, row, setAnchorEl, staticRowIndex, table } = _a, rest = __rest(_a, ["anchorEl", "handleEdit", "row", "setAnchorEl", "staticRowIndex", "table"]);
878
- const { getState, options: { editDisplayMode, enableEditing, icons: { EditIcon }, localization, mrtTheme: { menuBackgroundColor }, renderRowActionMenuItems, }, } = table;
879
- const { density } = getState();
880
- const menuItems = useMemo(() => {
881
- const items = [];
882
- const editItem = parseFromValuesOrFunc(enableEditing, row) &&
883
- ['modal', 'row'].includes(editDisplayMode) && (jsx(MRT_ActionMenuItem, { icon: jsx(EditIcon, {}), label: localization.edit, onClick: handleEdit, table: table }, 'edit'));
884
- if (editItem)
885
- items.push(editItem);
886
- const rowActionMenuItems = renderRowActionMenuItems === null || renderRowActionMenuItems === void 0 ? void 0 : renderRowActionMenuItems({
887
- closeMenu: () => setAnchorEl(null),
888
- row,
889
- staticRowIndex,
890
- table,
891
- });
892
- if (rowActionMenuItems === null || rowActionMenuItems === void 0 ? void 0 : rowActionMenuItems.length)
893
- items.push(...rowActionMenuItems);
894
- return items;
895
- }, [renderRowActionMenuItems, row, staticRowIndex, table]);
896
- if (!menuItems.length)
897
- return null;
898
- return (jsx(Menu, Object.assign({ MenuListProps: {
899
- dense: density === 'compact',
900
- sx: {
901
- backgroundColor: menuBackgroundColor,
902
- },
903
- }, anchorEl: anchorEl, disableScrollLock: true, onClick: (event) => event.stopPropagation(), onClose: () => setAnchorEl(null), open: !!anchorEl }, rest, { children: menuItems })));
868
+ const MRT_EditRowButton = ({ onClick }) => {
869
+ return (jsx(IconButton, { sx: { p: 0 }, disableRipple: true, color: "primary", onClick: onClick, children: jsx(EditNoteIcon, {}) }));
904
870
  };
905
871
 
906
- const MRT_EditActionButtons = (_a) => {
907
- var { row, table, variant = 'icon' } = _a, rest = __rest(_a, ["row", "table", "variant"]);
908
- const { getState, options: { icons: { CancelIcon, SaveIcon }, localization, onCreatingRowCancel, onCreatingRowSave, onEditingRowCancel, onEditingRowSave, }, refs: { editInputRefs }, setCreatingRow, setEditingRow, } = table;
909
- const { creatingRow, editingRow, isSaving } = getState();
910
- const isCreating = (creatingRow === null || creatingRow === void 0 ? void 0 : creatingRow.id) === row.id;
911
- const isEditing = (editingRow === null || editingRow === void 0 ? void 0 : editingRow.id) === row.id;
912
- const handleCancel = () => {
913
- if (isCreating) {
914
- onCreatingRowCancel === null || onCreatingRowCancel === void 0 ? void 0 : onCreatingRowCancel({ row, table });
915
- setCreatingRow(null);
872
+ const EditRowAction = ({ onEditButtonClick, }) => {
873
+ return (jsx(Fragment, { children: jsx(MRT_EditRowButton, { onClick: onEditButtonClick }) }));
874
+ };
875
+
876
+ const createEditAction = ({ onEdit, renderRow: customRenderRow, } = {}) => {
877
+ const defaultOnEdit = (_a) => __awaiter(void 0, [_a], void 0, function* ({ rowToEdit, table, }) {
878
+ // Nothing to edit, so exit early.
879
+ if (!rowToEdit) {
880
+ return;
916
881
  }
917
- else if (isEditing) {
918
- onEditingRowCancel === null || onEditingRowCancel === void 0 ? void 0 : onEditingRowCancel({ row, table });
919
- setEditingRow(null);
882
+ const { setNewEntryModal } = table;
883
+ const handleOpenEditModal = () => {
884
+ setNewEntryModal({
885
+ open: true,
886
+ mode: 'edit',
887
+ });
888
+ };
889
+ if (table.options.editRowFn) {
890
+ yield table.options.editRowFn({ rowToEdit, table });
891
+ return;
920
892
  }
921
- row._valuesCache = {}; //reset values cache
893
+ handleOpenEditModal();
894
+ });
895
+ const executeEdit = (context) => {
896
+ const executeDefaultEdit = () => defaultOnEdit(context);
897
+ if (onEdit) {
898
+ return onEdit(Object.assign(Object.assign({}, context), { defaultOnEdit: executeDefaultEdit }));
899
+ }
900
+ return executeDefaultEdit();
922
901
  };
923
- const handleSubmitRow = () => {
924
- var _a, _b;
925
- //look for auto-filled input values
926
- (_b = Object.values((_a = editInputRefs.current) !== null && _a !== void 0 ? _a : {})
927
- .filter((inputRef) => { var _a, _b; return row.id === ((_b = (_a = inputRef === null || inputRef === void 0 ? void 0 : inputRef.name) === null || _a === void 0 ? void 0 : _a.split('_')) === null || _b === void 0 ? void 0 : _b[0]); })) === null || _b === void 0 ? void 0 : _b.forEach((input) => {
928
- if (input.value !== undefined &&
929
- Object.hasOwn(row === null || row === void 0 ? void 0 : row._valuesCache, input.name)) {
930
- // @ts-expect-error
931
- row._valuesCache[input.name] = input.value;
932
- }
933
- });
934
- if (isCreating)
935
- onCreatingRowSave === null || onCreatingRowSave === void 0 ? void 0 : onCreatingRowSave({
936
- exitCreatingMode: () => setCreatingRow(null),
937
- row,
938
- table,
939
- values: row._valuesCache,
940
- });
941
- else if (isEditing) {
942
- onEditingRowSave === null || onEditingRowSave === void 0 ? void 0 : onEditingRowSave({
943
- exitEditingMode: () => setEditingRow(null),
944
- row,
945
- table,
946
- values: row === null || row === void 0 ? void 0 : row._valuesCache,
947
- });
902
+ const handleEditRow = ({ table, row }) => {
903
+ return executeEdit({ table, rowToEdit: row });
904
+ };
905
+ const createEditRowExecutor = (context) => {
906
+ return () => {
907
+ void handleEditRow(context);
908
+ };
909
+ };
910
+ const renderRowAction = (context) => {
911
+ const onRowEdit = createEditRowExecutor(context);
912
+ if (customRenderRow) {
913
+ return customRenderRow(Object.assign(Object.assign({}, context), { onEdit: onRowEdit }));
948
914
  }
915
+ return jsx(EditRowAction, { onEditButtonClick: onRowEdit });
916
+ };
917
+ return {
918
+ name: 'edit',
919
+ renderRow: renderRowAction,
949
920
  };
950
- return (jsx(Box, { onClick: (e) => e.stopPropagation(), sx: (theme) => (Object.assign({ display: 'flex', gap: '0.75rem' }, parseFromValuesOrFunc(rest === null || rest === void 0 ? void 0 : rest.sx, theme))), children: variant === 'icon' ? (jsxs(Fragment, { children: [jsx(Tooltip, { title: localization.cancel, children: jsx(IconButton, { "aria-label": localization.cancel, onClick: handleCancel, children: jsx(CancelIcon, {}) }) }), ((isCreating && onCreatingRowSave) ||
951
- (isEditing && onEditingRowSave)) && (jsx(Tooltip, { title: localization.save, children: jsx(IconButton, { "aria-label": localization.save, color: "info", disabled: isSaving, onClick: handleSubmitRow, children: isSaving ? jsx(CircularProgress, { size: 18 }) : jsx(SaveIcon, {}) }) }))] })) : (jsxs(Fragment, { children: [jsx(Button, { onClick: handleCancel, sx: { minWidth: '100px' }, children: localization.cancel }), jsxs(Button, { disabled: isSaving, onClick: handleSubmitRow, sx: { minWidth: '100px' }, variant: "contained", children: [isSaving && jsx(CircularProgress, { color: "inherit", size: 18 }), localization.save] })] })) }));
952
921
  };
953
922
 
954
- const parseCSSVarId = (id) => id.replace(/[^a-zA-Z0-9]/g, '_');
955
- const getMRTTheme = (mrtTheme, muiTheme) => {
956
- const mrtThemeOverrides = parseFromValuesOrFunc(mrtTheme, muiTheme);
957
- const baseBackgroundColor = muiTheme.palette.background.default;
958
- return Object.assign({ baseBackgroundColor, cellNavigationOutlineColor: muiTheme.palette.primary.main, draggingBorderColor: muiTheme.palette.primary.main, matchHighlightColor: muiTheme.palette.mode === 'dark'
959
- ? darken(muiTheme.palette.warning.dark, 0.25)
960
- : lighten(muiTheme.palette.warning.light, 0.5), menuBackgroundColor: lighten(baseBackgroundColor, 0.07), pinnedRowBackgroundColor: alpha(muiTheme.palette.primary.main, 0.1), selectedRowBackgroundColor: alpha(muiTheme.palette.primary.main, 0.2) }, mrtThemeOverrides);
961
- };
962
- const commonCellBeforeAfterStyles = {
963
- content: '""',
964
- height: '100%',
965
- left: 0,
966
- position: 'absolute',
967
- top: 0,
968
- width: '100%',
969
- zIndex: -1,
970
- };
971
- const getCommonPinnedCellStyles = ({ table, theme, }) => {
972
- const { baseBackgroundColor } = table.options.mrtTheme;
973
- return {
974
- '&[data-pinned="true"]': {
975
- '&:before': Object.assign({ backgroundColor: alpha(darken(baseBackgroundColor, theme.palette.mode === 'dark' ? 0.05 : 0.01), 0.97) }, commonCellBeforeAfterStyles),
976
- },
977
- };
978
- };
979
- const getCommonMRTCellStyles = ({ column, header, table, tableCellProps, theme, }) => {
980
- var _a, _b, _c, _d, _e, _f, _g, _h;
981
- const { getState, options: { enableColumnVirtualization, layoutMode }, } = table;
982
- const { draggingColumn } = getState();
983
- const { columnDef } = column;
984
- const { columnDefType } = columnDef;
985
- const isColumnPinned = columnDef.columnDefType !== 'group' && column.getIsPinned();
986
- const widthStyles = {
987
- minWidth: `max(calc(var(--${header ? 'header' : 'col'}-${parseCSSVarId((_a = header === null || header === void 0 ? void 0 : header.id) !== null && _a !== void 0 ? _a : column.id)}-size) * 1px), ${(_b = columnDef.minSize) !== null && _b !== void 0 ? _b : 30}px)`,
988
- width: `calc(var(--${header ? 'header' : 'col'}-${parseCSSVarId((_c = header === null || header === void 0 ? void 0 : header.id) !== null && _c !== void 0 ? _c : column.id)}-size) * 1px)`,
989
- };
990
- if (layoutMode === 'grid') {
991
- widthStyles.flex = `${[0, false].includes(columnDef.grow)
992
- ? 0
993
- : `var(--${header ? 'header' : 'col'}-${parseCSSVarId((_d = header === null || header === void 0 ? void 0 : header.id) !== null && _d !== void 0 ? _d : column.id)}-size)`} 0 auto`;
994
- }
995
- else if (layoutMode === 'grid-no-grow') {
996
- widthStyles.flex = `${+(columnDef.grow || 0)} 0 auto`;
997
- }
998
- // The checkbox column is technically pinned (for sticky positioning) but
999
- // should look like a regular center column — no background overlay or shadow.
1000
- const isCheckboxColumn = column.id === CHECKBOX_DISPLAY_COLUMN_ID;
1001
- // Count all currently pinned column IDs across both sides.
1002
- // Checkbox is always pinned (counts as 1), so > 1 means the user has
1003
- // explicitly pinned at least one additional column.
1004
- const totalPinnedColumnCount = [
1005
- ...((_e = table.getState().columnPinning.left) !== null && _e !== void 0 ? _e : []),
1006
- ...((_f = table.getState().columnPinning.right) !== null && _f !== void 0 ? _f : []),
1007
- ].length;
1008
- const hasNoPinnedColumns = totalPinnedColumnCount === 0;
1009
- const pinnedStyles = isColumnPinned
1010
- ? Object.assign(Object.assign({}, (isCheckboxColumn
1011
- ? hasNoPinnedColumns
1012
- ? {
1013
- // Use doubled class selector (&&) to beat the row-level
1014
- // td[data-pinned="true"]:before specificity from MRT_TableBodyRow.
1015
- '&&[data-pinned="true"]': {
1016
- '&:before': {
1017
- backgroundColor: 'transparent',
1018
- boxShadow: 'none',
1019
- },
1020
- },
1021
- }
1022
- : // Other columns are also pinned — apply standard pinned background
1023
- // so the checkbox header matches the pinned row cells below it.
1024
- getCommonPinnedCellStyles({ column, table, theme })
1025
- : getCommonPinnedCellStyles({ column, table, theme }))), { left: isColumnPinned === 'left'
1026
- ? `${column.getStart('left')}px`
1027
- : undefined,
1028
- // Skip opacity reduction for checkbox — keep it fully opaque like center columns
1029
- opacity: isCheckboxColumn ? undefined : 0.97, position: 'sticky', right: isColumnPinned === 'right'
1030
- ? `${column.getAfter('right')}px`
1031
- : undefined }) : {};
1032
- return Object.assign(Object.assign(Object.assign({ backgroundColor: 'inherit', backgroundImage: 'inherit', display: (layoutMode === null || layoutMode === void 0 ? void 0 : layoutMode.startsWith('grid')) ? 'flex' : undefined, justifyContent: columnDefType === 'group'
1033
- ? 'center'
1034
- : (layoutMode === null || layoutMode === void 0 ? void 0 : layoutMode.startsWith('grid'))
1035
- ? tableCellProps.align
1036
- : undefined, opacity: ((_g = table.getState().draggingColumn) === null || _g === void 0 ? void 0 : _g.id) === column.id ||
1037
- ((_h = table.getState().hoveredColumn) === null || _h === void 0 ? void 0 : _h.id) === column.id
1038
- ? 0.5
1039
- : 1, position: 'relative', transition: enableColumnVirtualization
1040
- ? 'none'
1041
- : `padding 150ms ease-in-out`, zIndex: column.getIsResizing() || (draggingColumn === null || draggingColumn === void 0 ? void 0 : draggingColumn.id) === column.id
1042
- ? 2
1043
- : columnDefType !== 'group' && isColumnPinned
1044
- ? 1
1045
- : 0, '&:focus-visible': {
1046
- outline: `2px solid ${table.options.mrtTheme.cellNavigationOutlineColor}`,
1047
- outlineOffset: '-2px',
1048
- } }, pinnedStyles), widthStyles), parseFromValuesOrFunc(tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.sx, theme));
923
+ const downloadExportFiles = (files) => {
924
+ files.forEach((file) => {
925
+ const binaryString = atob(file.content);
926
+ const len = binaryString.length;
927
+ const bytes = new Uint8Array(len);
928
+ for (let i = 0; i < len; i++) {
929
+ bytes[i] = binaryString.charCodeAt(i);
930
+ }
931
+ const blob = new Blob([bytes], { type: 'application/octet-stream' });
932
+ const element = document.createElement('a');
933
+ element.href = URL.createObjectURL(blob);
934
+ element.download = file.filename;
935
+ document.body.appendChild(element);
936
+ element.click();
937
+ document.body.removeChild(element);
938
+ URL.revokeObjectURL(element.href);
939
+ });
1049
940
  };
1050
- const getCommonToolbarStyles = ({ table, }) => ({
1051
- alignItems: 'flex-start',
1052
- backgroundColor: table.options.mrtTheme.baseBackgroundColor,
1053
- display: 'grid',
1054
- flexWrap: 'wrap-reverse',
1055
- position: 'relative',
1056
- transition: 'all 150ms ease-in-out',
1057
- zIndex: 1,
1058
- });
1059
- const flipIconStyles = (theme) => theme.direction === 'rtl'
1060
- ? { style: { transform: 'scaleX(-1)' } }
1061
- : undefined;
1062
- const getCommonTooltipProps = (placement) => ({
1063
- disableInteractive: true,
1064
- enterDelay: 1000,
1065
- enterNextDelay: 1000,
1066
- placement,
1067
- });
1068
941
 
1069
- const commonIconButtonStyles = {
1070
- '&:hover': {
1071
- opacity: 1,
1072
- },
1073
- height: '2rem',
1074
- ml: '10px',
1075
- opacity: 0.5,
1076
- transition: 'opacity 150ms',
1077
- width: '2rem',
942
+ const printExportFiles = (files) => {
943
+ files.forEach((file) => {
944
+ const binaryString = atob(file.content);
945
+ const len = binaryString.length;
946
+ const bytes = new Uint8Array(len);
947
+ for (let i = 0; i < len; i++) {
948
+ bytes[i] = binaryString.charCodeAt(i);
949
+ }
950
+ const blob = new Blob([bytes], { type: 'application/pdf' });
951
+ const url = URL.createObjectURL(blob);
952
+ printJS({
953
+ printable: url,
954
+ type: 'pdf',
955
+ onLoadingEnd: () => URL.revokeObjectURL(url),
956
+ });
957
+ });
1078
958
  };
1079
- const MRT_ToggleRowActionMenuButton = (_a) => {
1080
- var _b;
1081
- var { cell, row, staticRowIndex, table } = _a, rest = __rest(_a, ["cell", "row", "staticRowIndex", "table"]);
1082
- const { getState, options: { createDisplayMode, editDisplayMode, enableEditing, icons: { EditIcon, MoreHorizIcon }, localization, renderRowActionMenuItems, renderRowActions, }, setEditingRow, } = table;
1083
- const { creatingRow, editingRow } = getState();
1084
- const isCreating = (creatingRow === null || creatingRow === void 0 ? void 0 : creatingRow.id) === row.id;
1085
- const isEditing = (editingRow === null || editingRow === void 0 ? void 0 : editingRow.id) === row.id;
1086
- const showEditActionButtons = (isCreating && createDisplayMode === 'row') ||
1087
- (isEditing && editDisplayMode === 'row');
959
+
960
+ const MRT_ExportsToolbar = ({ table, availableExports, exportState, onExportStateChange, loadExport, }) => {
961
+ const theme = useTheme();
962
+ const { localization } = table.options;
963
+ const { selectedExports, selectedFormat, grouped } = exportState;
1088
964
  const [anchorEl, setAnchorEl] = useState(null);
1089
- const handleOpenRowActionMenu = (event) => {
1090
- event.stopPropagation();
1091
- event.preventDefault();
965
+ const [loadingExportType, setLoadingExportType] = useState(null);
966
+ const { rowSelection } = table.getState();
967
+ const selectedRowIds = Object.keys(rowSelection).filter((id) => rowSelection[id]);
968
+ const isNoRowsSelected = selectedRowIds.length === 0;
969
+ const availableFormats = useMemo(() => {
970
+ const allFormats = Object.values(availableExports).flatMap((exp) => exp.formats);
971
+ return Array.from(new Set(allFormats));
972
+ }, [availableExports]);
973
+ const hasPdfFormat = availableFormats.includes('pdf');
974
+ const exportTypesForSelectedFormat = useMemo(() => {
975
+ if (!selectedFormat)
976
+ return [];
977
+ return Object.values(availableExports).filter((exp) => exp.formats.includes(selectedFormat));
978
+ }, [availableExports, selectedFormat]);
979
+ const isPrintDisabled = selectedFormat !== 'pdf' ||
980
+ !selectedFormat ||
981
+ selectedExports.length < 1 ||
982
+ (!grouped && selectedExports.length > 1);
983
+ const isDownloadDisabled = !selectedFormat || selectedExports.length < 1;
984
+ const handleOpenMenu = (event) => {
1092
985
  setAnchorEl(event.currentTarget);
1093
986
  };
1094
- const handleStartEditMode = (event) => {
1095
- event.stopPropagation();
1096
- setEditingRow(Object.assign({}, row));
987
+ const handleCloseMenu = () => {
1097
988
  setAnchorEl(null);
1098
989
  };
1099
- return (jsx(Fragment, { children: renderRowActions && !showEditActionButtons ? (renderRowActions({ cell, row, staticRowIndex, table })) : showEditActionButtons ? (jsx(MRT_EditActionButtons, { row: row, table: table })) : !renderRowActionMenuItems &&
1100
- parseFromValuesOrFunc(enableEditing, row) &&
1101
- ['modal', 'row'].includes(editDisplayMode) ? (jsx(Tooltip, { placement: "right", title: localization.edit, children: jsx(IconButton, Object.assign({ "aria-label": localization.edit, onClick: handleStartEditMode, sx: commonIconButtonStyles }, rest, { children: jsx(EditIcon, {}) })) })) : ((_b = renderRowActionMenuItems === null || renderRowActionMenuItems === void 0 ? void 0 : renderRowActionMenuItems({
1102
- closeMenu: () => { },
1103
- row,
1104
- staticRowIndex,
1105
- table,
1106
- })) === null || _b === void 0 ? void 0 : _b.length) ? (jsxs(Fragment, { children: [jsx(Tooltip, Object.assign({}, getCommonTooltipProps(), { title: localization.rowActions, children: jsx(IconButton, Object.assign({ "aria-label": localization.rowActions, onClick: handleOpenRowActionMenu, size: "small", sx: commonIconButtonStyles }, rest, { children: jsx(MoreHorizIcon, {}) })) })), jsx(MRT_RowActionMenu, { anchorEl: anchorEl, handleEdit: handleStartEditMode, row: row, setAnchorEl: setAnchorEl, staticRowIndex: staticRowIndex, table: table })] })) : null }));
1107
- };
1108
-
1109
- const getMRT_RowActionsColumnDef = (tableOptions) => {
1110
- return Object.assign({ Cell: ({ cell, row, staticRowIndex, table }) => (jsx(MRT_ToggleRowActionMenuButton, { cell: cell, row: row, staticRowIndex: staticRowIndex, table: table })) }, defaultDisplayColumnProps({
1111
- header: 'actions',
1112
- id: 'mrt-row-actions',
1113
- size: 70,
1114
- tableOptions,
1115
- }));
1116
- };
1117
-
1118
- const MRT_GrabHandleButton = (_a) => {
1119
- var _b, _c;
1120
- var { location, table } = _a, rest = __rest(_a, ["location", "table"]);
1121
- const { options: { icons: { DragHandleIcon }, localization, }, } = table;
1122
- return (jsx(Tooltip, Object.assign({}, getCommonTooltipProps('top'), { title: (_b = rest === null || rest === void 0 ? void 0 : rest.title) !== null && _b !== void 0 ? _b : localization.move, children: jsx(IconButton, Object.assign({ "aria-label": (_c = rest.title) !== null && _c !== void 0 ? _c : localization.move, disableRipple: true, draggable: "true", size: "small" }, rest, { onClick: (e) => {
1123
- var _a;
1124
- e.stopPropagation();
1125
- (_a = rest === null || rest === void 0 ? void 0 : rest.onClick) === null || _a === void 0 ? void 0 : _a.call(rest, e);
1126
- }, sx: (theme) => (Object.assign({ '&:active': {
1127
- cursor: 'grabbing',
1128
- }, '&:hover': {
1129
- backgroundColor: 'transparent',
1130
- opacity: 1,
1131
- }, cursor: 'grab', m: '0 -0.1rem', opacity: location === 'row' ? 1 : 0.5, p: '2px', transition: 'all 150ms ease-in-out' }, parseFromValuesOrFunc(rest === null || rest === void 0 ? void 0 : rest.sx, theme))), title: undefined, children: jsx(DragHandleIcon, {}) })) })));
1132
- };
1133
-
1134
- const MRT_TableBodyRowGrabHandle = (_a) => {
1135
- var { row, rowRef, table } = _a, rest = __rest(_a, ["row", "rowRef", "table"]);
1136
- const { options: { muiRowDragHandleProps }, } = table;
1137
- const iconButtonProps = Object.assign(Object.assign({}, parseFromValuesOrFunc(muiRowDragHandleProps, {
1138
- row,
1139
- table,
1140
- })), rest);
1141
- const handleDragStart = (event) => {
1142
- var _a;
1143
- (_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.onDragStart) === null || _a === void 0 ? void 0 : _a.call(iconButtonProps, event);
1144
- try {
1145
- event.dataTransfer.setDragImage(rowRef.current, 0, 0);
1146
- }
1147
- catch (e) {
1148
- console.error(e);
1149
- }
1150
- table.setDraggingRow(row);
990
+ const handleSelectFormat = (format) => {
991
+ const newFormat = selectedFormat === format ? null : format;
992
+ onExportStateChange((prev) => (Object.assign(Object.assign({}, (prev !== null && prev !== void 0 ? prev : { grouped: false })), { selectedExports: [], selectedFormat: newFormat })));
1151
993
  };
1152
- const handleDragEnd = (event) => {
1153
- var _a;
1154
- (_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.onDragEnd) === null || _a === void 0 ? void 0 : _a.call(iconButtonProps, event);
1155
- table.setDraggingRow(null);
1156
- table.setHoveredRow(null);
994
+ const handleToggleExportType = (exportName) => {
995
+ const isAlreadySelected = selectedExports.includes(exportName);
996
+ const newSelectedExports = isAlreadySelected
997
+ ? selectedExports.filter((name) => name !== exportName)
998
+ : [...selectedExports, exportName];
999
+ onExportStateChange((prev) => (Object.assign(Object.assign({}, (prev !== null && prev !== void 0 ? prev : { selectedFormat: null, grouped: false })), { selectedExports: newSelectedExports })));
1157
1000
  };
1158
- return (jsx(MRT_GrabHandleButton, Object.assign({}, iconButtonProps, { location: "row", onDragEnd: handleDragEnd, onDragStart: handleDragStart, table: table })));
1159
- };
1160
-
1161
- const getMRT_RowDragColumnDef = (tableOptions) => {
1162
- return Object.assign({ Cell: ({ row, rowRef, table }) => (jsx(MRT_TableBodyRowGrabHandle, { row: row, rowRef: rowRef, table: table })), grow: false }, defaultDisplayColumnProps({
1163
- header: 'move',
1164
- id: 'mrt-row-drag',
1165
- size: 60,
1166
- tableOptions,
1167
- }));
1168
- };
1169
-
1170
- const MRT_ExpandAllButton = (_a) => {
1171
- var _b, _c;
1172
- var { table } = _a, rest = __rest(_a, ["table"]);
1173
- const { getCanSomeRowsExpand, getIsAllRowsExpanded, getIsSomeRowsExpanded, getState, options: { icons: { KeyboardDoubleArrowDownIcon }, localization, muiExpandAllButtonProps, renderDetailPanel, }, toggleAllRowsExpanded, } = table;
1174
- const { density, isLoading } = getState();
1175
- const iconButtonProps = Object.assign(Object.assign({}, parseFromValuesOrFunc(muiExpandAllButtonProps, {
1176
- table,
1177
- })), rest);
1178
- const isAllRowsExpanded = getIsAllRowsExpanded();
1179
- return (jsx(Tooltip, Object.assign({}, getCommonTooltipProps(), { title: (_b = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.title) !== null && _b !== void 0 ? _b : (isAllRowsExpanded ? localization.collapseAll : localization.expandAll), children: jsx("span", { children: jsx(IconButton, Object.assign({ "aria-label": localization.expandAll, disabled: isLoading || (!renderDetailPanel && !getCanSomeRowsExpand()), onClick: () => toggleAllRowsExpanded(!isAllRowsExpanded) }, iconButtonProps, { sx: (theme) => (Object.assign({ height: density === 'compact' ? '1.75rem' : '2.25rem', mt: density !== 'compact' ? '-0.25rem' : undefined, width: density === 'compact' ? '1.75rem' : '2.25rem' }, parseFromValuesOrFunc(iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.sx, theme))), title: undefined, children: (_c = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.children) !== null && _c !== void 0 ? _c : (jsx(KeyboardDoubleArrowDownIcon, { style: {
1180
- transform: `rotate(${isAllRowsExpanded ? -180 : getIsSomeRowsExpanded() ? -90 : 0}deg)`,
1181
- transition: 'transform 150ms',
1182
- } })) })) }) })));
1183
- };
1184
-
1185
- const MRT_ExpandButton = ({ row, staticRowIndex, table, }) => {
1186
- var _a, _b;
1187
- const theme = useTheme();
1188
- const { getState, options: { icons: { ExpandMoreIcon }, localization, maxDepth, muiExpandButtonProps, positionExpandColumn, renderDetailPanel, }, } = table;
1189
- const { density } = getState();
1190
- const iconButtonProps = parseFromValuesOrFunc(muiExpandButtonProps, {
1191
- row,
1192
- staticRowIndex,
1193
- table,
1001
+ const handleToggleGrouped = () => {
1002
+ onExportStateChange((prev) => (Object.assign(Object.assign({}, (prev !== null && prev !== void 0 ? prev : { selectedFormat: null, selectedExports: [] })), { grouped: !grouped })));
1003
+ };
1004
+ const handleExportAction = (type) => __awaiter(void 0, void 0, void 0, function* () {
1005
+ setLoadingExportType(type);
1006
+ try {
1007
+ const response = yield loadExport({
1008
+ format: selectedFormat,
1009
+ exports: selectedExports,
1010
+ separated_files: !grouped,
1011
+ download: false,
1012
+ ids: JSON.stringify(selectedRowIds),
1013
+ type,
1014
+ });
1015
+ handleCloseMenu();
1016
+ if (type === 'download') {
1017
+ downloadExportFiles(response);
1018
+ }
1019
+ else {
1020
+ printExportFiles(response);
1021
+ }
1022
+ }
1023
+ finally {
1024
+ setLoadingExportType(null);
1025
+ }
1194
1026
  });
1195
- const canExpand = row.getCanExpand() && (maxDepth === undefined || row.depth < maxDepth - 1);
1196
- const isExpanded = row.getIsExpanded();
1197
- const handleToggleExpand = (event) => {
1198
- var _a;
1199
- event.stopPropagation();
1200
- row.toggleExpanded();
1201
- (_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.onClick) === null || _a === void 0 ? void 0 : _a.call(iconButtonProps, event);
1027
+ const renderFormatSelector = () => (jsx(Stack, { justifyContent: "flex-start", minWidth: "200px", sx: {
1028
+ borderRight: selectedFormat
1029
+ ? `1px dashed ${theme.palette.divider}`
1030
+ : 'none',
1031
+ }, children: jsx(FormControl, { children: jsx(RadioGroup, { value: selectedFormat !== null && selectedFormat !== void 0 ? selectedFormat : '', children: availableFormats.map((format) => (jsx(FormControlLabel, { sx: { m: 0 }, value: format, control: jsx(Radio, { size: "small", onClick: () => handleSelectFormat(format) }), label: jsx(Typography, { variant: "subtitle2", sx: { fontWeight: 800 }, children: format }) }, format))) }) }) }));
1032
+ const renderExportTypeSelector = () => {
1033
+ if (!selectedFormat || exportTypesForSelectedFormat.length === 0)
1034
+ return null;
1035
+ return (jsx(Stack, { minWidth: "250px", maxHeight: "500px", sx: { overflowY: 'auto' }, children: exportTypesForSelectedFormat.map((exportType) => (jsxs(MenuItem, { onClick: () => handleToggleExportType(exportType.name), value: exportType.name, children: [jsx(Checkbox, { checked: selectedExports.includes(exportType.name), size: "small" }), jsx(Typography, { variant: "body2", children: exportType.label })] }, exportType.name))) }));
1202
1036
  };
1203
- const detailPanel = !!(renderDetailPanel === null || renderDetailPanel === void 0 ? void 0 : renderDetailPanel({ row, table }));
1204
- return (jsx(Tooltip, Object.assign({ disableHoverListener: !canExpand && !detailPanel }, getCommonTooltipProps(), { title: (_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.title) !== null && _a !== void 0 ? _a : (isExpanded ? localization.collapse : localization.expand), children: jsx("span", { children: jsx(IconButton, Object.assign({ "aria-label": localization.expand, disabled: !canExpand && !detailPanel }, iconButtonProps, { onClick: handleToggleExpand, sx: (theme) => (Object.assign({ opacity: !canExpand && !detailPanel ? 0.3 : 1, [theme.direction === 'rtl' || positionExpandColumn === 'last'
1205
- ? 'mr'
1206
- : 'ml']: `${row.depth * 16}px`, width: density === 'compact' ? '1.75rem' : '2.25rem' }, parseFromValuesOrFunc(iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.sx, theme))), size: "small", title: undefined, children: (_b = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.children) !== null && _b !== void 0 ? _b : (jsx(ExpandMoreIcon, { style: {
1207
- transform: `rotate(${!canExpand && !renderDetailPanel
1208
- ? positionExpandColumn === 'last' ||
1209
- theme.direction === 'rtl'
1210
- ? 90
1211
- : -90
1212
- : isExpanded
1213
- ? -180
1214
- : 0}deg)`,
1215
- transition: 'transform 150ms',
1216
- } })) })) }) })));
1037
+ const renderActionButtons = () => {
1038
+ const isAnyLoading = loadingExportType !== null;
1039
+ return (jsxs(Stack, { direction: "row", gap: 0.5, mt: 1, mr: 2, children: [hasPdfFormat && (jsx(Button, { sx: { display: 'flex', gap: 0.5 }, disabled: isPrintDisabled || isAnyLoading, onClick: () => handleExportAction('print'), startIcon: loadingExportType === 'print' ? (jsx(CircularProgress, { size: 16, color: "inherit" })) : (jsx(PrintIcon, { fontSize: "small" })), children: localization.exportPrintPdf })), jsx(Button, { sx: { display: 'flex', gap: 0.5 }, disabled: isDownloadDisabled || isAnyLoading, onClick: () => handleExportAction('download'), startIcon: loadingExportType === 'download' ? (jsx(CircularProgress, { size: 16, color: "inherit" })) : (jsx(FileDownloadIcon, { fontSize: "small" })), children: localization.exportDownload })] }));
1040
+ };
1041
+ const renderGroupedCheckbox = () => (jsx(Stack, { mt: "auto", children: jsx(FormControlLabel, { onChange: handleToggleGrouped, sx: { m: 0 }, control: jsx(Checkbox, { checked: grouped, size: "small" }), label: jsx(Typography, { variant: "body2", children: localization.exportGrouped }) }) }));
1042
+ return (jsxs(Stack, { direction: "row", gap: 0.5, alignItems: "center", children: [jsx(Tooltip, { title: isNoRowsSelected
1043
+ ? localization.exportSelectRowsTooltip
1044
+ : localization.exportButton, children: jsx("span", { children: jsx(Button, { "aria-label": localization.exportButton, disabled: isNoRowsSelected, onClick: handleOpenMenu, size: "small", startIcon: jsx(FileDownloadIcon, { fontSize: "small" }), variant: "text", children: localization.exportButton }) }) }), jsxs(Menu, { anchorEl: anchorEl, open: Boolean(anchorEl), onClose: handleCloseMenu, anchorOrigin: { vertical: 'bottom', horizontal: 'left' }, transformOrigin: { vertical: 'top', horizontal: 'left' }, children: [jsxs(Stack, { direction: "row", sx: { px: 1, pt: 1, maxHeight: '320px', overflow: 'auto' }, children: [renderFormatSelector(), selectedFormat &&
1045
+ exportTypesForSelectedFormat.length > 0 &&
1046
+ renderExportTypeSelector()] }), jsx(Divider, { sx: { mt: 1 } }), jsxs(Stack, { direction: "row", alignItems: "center", sx: { px: 1, pb: 1 }, children: [renderActionButtons(), renderGroupedCheckbox()] })] })] }));
1217
1047
  };
1218
1048
 
1219
- const INSERT_HERE_TOOLTIP = 'Insert here';
1220
- const ACTION_ICON_SIZE$1 = 'small';
1221
- const MRT_InsertHereAction = ({ onClick, }) => {
1222
- return (jsx(Tooltip, { title: INSERT_HERE_TOOLTIP, disableInteractive: true, children: jsx(IconButton, { onClick: onClick, size: ACTION_ICON_SIZE$1, children: jsx(SubdirectoryArrowLeftIcon, { color: "warning" }) }) }));
1049
+ const MRT_ExportRowButton = ({ onClick }) => {
1050
+ return (jsx(IconButton, { sx: { p: 0 }, disableRipple: true, onClick: onClick, children: jsx(FileDownloadIcon, { fontSize: "small" }) }));
1223
1051
  };
1224
1052
 
1225
- const MOVE_TO_TOP_TOOLTIP = 'Move to top level';
1226
- const ACTION_ICON_SIZE = 'small';
1227
- const ACTION_BUTTON_HEIGHT = '1.75rem';
1228
- const MRT_MoveToTopAction = ({ onClick }) => {
1229
- return (jsx(Tooltip, { title: MOVE_TO_TOP_TOOLTIP, disableInteractive: true, children: jsx(IconButton, { onClick: onClick, size: ACTION_ICON_SIZE, sx: { height: ACTION_BUTTON_HEIGHT }, children: jsx(VerticalAlignTopIcon, { fontSize: "small" }) }) }));
1053
+ const MRT_PrintRowButton = ({ onClick }) => {
1054
+ return (jsx(IconButton, { sx: { p: 0 }, disableRipple: true, onClick: onClick, children: jsx(PrintIcon, { fontSize: "small" }) }));
1230
1055
  };
1231
1056
 
1232
- const MRT_ReorderRowCheckbox = ({ onChange, isSelected, }) => {
1233
- return (jsx(Checkbox, { checked: isSelected, color: "warning", disableRipple: true, onChange: onChange, sx: {
1234
- color: (theme) => theme.palette.warning.main,
1235
- '&.Mui-checked': {
1236
- color: (theme) => theme.palette.warning.main,
1237
- },
1238
- } }));
1057
+ const ExportRowAction = ({ onExport, onPrint }) => {
1058
+ return (jsxs(Fragment, { children: [jsx(MRT_ExportRowButton, { onClick: onExport }), onPrint && jsx(MRT_PrintRowButton, { onClick: onPrint })] }));
1239
1059
  };
1240
1060
 
1241
- /**
1242
- * Finds the maximum depth in the hierarchy of a given row (recursively searches all descendants).
1243
- * Used to determine the "size" of the tree being moved.
1244
- * Example: Row at depth 1 with a child at depth 3 → returns 3
1245
- */
1246
- const getDeepestSubRowDepth = (row) => {
1247
- var _a;
1248
- if (!((_a = row.subRows) === null || _a === void 0 ? void 0 : _a.length)) {
1249
- return row.depth;
1250
- }
1251
- return row.subRows.reduce((maxDepth, subRow) => Math.max(maxDepth, getDeepestSubRowDepth(subRow)), row.depth);
1252
- };
1253
- /**
1254
- * Extracts an array of IDs of only the selected rows from the selection object.
1255
- * Filters the record where the value is true and maps only the keys (IDs).
1256
- * Example: { row1: true, row2: false, row3: true } → ['row1', 'row3']
1257
- */
1258
- const getSelectedReorderRowIds = (rowReorderingSelection) => {
1259
- return Object.entries(rowReorderingSelection !== null && rowReorderingSelection !== void 0 ? rowReorderingSelection : {})
1260
- .filter(([, isSelected]) => isSelected)
1261
- .map(([rowId]) => rowId);
1262
- };
1263
- /**
1264
- * Checks WHETHER we can move selected rows as children of target row
1265
- * without exceeding the maximum allowed depth.
1266
- * Directly calculates the final maximum depth after the move.
1267
- * Example: selectedRows at depth 1-2 with descendants to depth 4, target depth 1, maxDepth 5
1268
- * → new max depth = 1 + 1 + (4 - 1) = 5, which equals maxDepth, so returns false
1269
- */
1270
- const canInsertSelectedRowsWithoutExceedingMaxDepth = ({ maxDepth, selectedRows, targetRowDepth, }) => {
1271
- // Cannot insert if there are no selected rows to move
1272
- if (selectedRows.length === 0) {
1273
- return false;
1274
- }
1275
- // No depth restriction - can insert anywhere
1276
- if (maxDepth === undefined) {
1277
- return true;
1278
- }
1279
- // Find the deepest descendant among all selected rows
1280
- const maxDeepestDescendantDepth = selectedRows.reduce((max, row) => {
1281
- return Math.max(max, getDeepestSubRowDepth(row));
1282
- }, 0);
1283
- // Find the minimum depth of selected rows (to calculate relative depth)
1284
- const minSelectedRowDepth = Math.min(...selectedRows.map((r) => r.depth));
1285
- // Calculate the maximum depth after moving rows as children of target
1286
- // newMaxDepth = target.depth + 1 (as children) + relative depth of selected rows
1287
- const newMaxDepth = targetRowDepth + 1 + (maxDeepestDescendantDepth - minSelectedRowDepth);
1288
- return newMaxDepth < maxDepth;
1289
- };
1290
- /**
1291
- * Finds the depth of the FIRST selected row in the selection object.
1292
- * Used to enforce constraint: can only select rows at the SAME depth.
1293
- * Example: If I select a row at depth 2, I cannot select a row at depth 3
1294
- */
1295
- const getFirstSelectedReorderRowDepth = ({ rowReorderingSelection, table, }) => {
1296
- var _a, _b;
1297
- const firstSelectedRowId = (_a = Object.entries(rowReorderingSelection !== null && rowReorderingSelection !== void 0 ? rowReorderingSelection : {}).find(([, isSelected]) => isSelected)) === null || _a === void 0 ? void 0 : _a[0];
1298
- if (!firstSelectedRowId) {
1299
- return undefined;
1300
- }
1301
- return (_b = table.getRow(firstSelectedRowId, true)) === null || _b === void 0 ? void 0 : _b.depth;
1302
- };
1303
- /**
1304
- * Checks WHETHER we can select a specific row.
1305
- * Rule: If a selection already exists, new row MUST be at the SAME depth as the first selected.
1306
- * Without this, you could move rows from different levels which would break the hierarchy.
1307
- */
1308
- const canSelectRowForReorder = ({ rowId, rowDepth, rowReorderingSelection, firstSelectedReorderRowDepth, }) => {
1309
- const isCurrentRowSelected = !!(rowReorderingSelection === null || rowReorderingSelection === void 0 ? void 0 : rowReorderingSelection[rowId]);
1310
- if (isCurrentRowSelected) {
1311
- return true;
1312
- }
1313
- const hasAnySelection = Object.values(rowReorderingSelection !== null && rowReorderingSelection !== void 0 ? rowReorderingSelection : {}).some(Boolean);
1314
- if (!hasAnySelection) {
1315
- return true;
1316
- }
1317
- return rowDepth === firstSelectedReorderRowDepth;
1318
- };
1319
- /**
1320
- * Creates an array of MRT_Row objects from an array of IDs.
1321
- * Finds each row from the table and collects it in the result.
1322
- * Used to prepare data for the onTreeRowReorder callback.
1323
- */
1324
- const buildSelectedRowsArray = (selectedRowIds, table) => {
1325
- return selectedRowIds.reduce((selectedRows, selectedRowId) => {
1326
- const selectedRow = table.getRow(selectedRowId, true);
1327
- if (selectedRow) {
1328
- selectedRows.push(selectedRow);
1329
- }
1330
- return selectedRows;
1331
- }, []);
1061
+ const hasActiveExports = (table) => {
1062
+ const { activeExports } = table.getState();
1063
+ return !!((activeExports === null || activeExports === void 0 ? void 0 : activeExports.selectedFormat) && activeExports.selectedExports.length > 0);
1332
1064
  };
1333
- /**
1334
- * Helper function to check if a row is a descendant of another row.
1335
- * Recursively searches through all subRows to find if targetRowId exists.
1336
- * Used to prevent circular references (parent cannot become child of its own child).
1337
- */
1338
- const isRowInSubtreeOf = (targetRowId, parentRow) => {
1065
+ // Same conditions as MRT_ExportsToolbar: pdf format selected, at least one export type,
1066
+ // and either grouped or exactly one export type selected.
1067
+ const isPrintAvailable = (table) => {
1339
1068
  var _a;
1340
- if (!((_a = parentRow.subRows) === null || _a === void 0 ? void 0 : _a.length)) {
1069
+ const allFormats = Object.values((_a = table.options.availableExports) !== null && _a !== void 0 ? _a : {}).flatMap((e) => e.formats);
1070
+ if (!allFormats.includes('pdf'))
1341
1071
  return false;
1342
- }
1343
- for (const subRow of parentRow.subRows) {
1344
- if (subRow.id === targetRowId) {
1345
- return true;
1346
- }
1347
- if (isRowInSubtreeOf(targetRowId, subRow)) {
1348
- return true;
1349
- }
1350
- }
1351
- return false;
1352
- };
1353
- /**
1354
- * Checks if a row can be used as a valid insert target for selected rows.
1355
- * Rules: Target row must NOT be already selected AND must NOT be a descendant of any selected row.
1356
- * This prevents circular references where a parent becomes a child of its own descendants.
1357
- * Example: If you select "Department", you cannot insert it under "Project" (which is its descendant)
1358
- */
1359
- const isValidInsertTarget = ({ targetRowId, selectedRowIds, table, }) => {
1360
- // Rule 1: Target row cannot be already selected
1361
- if (selectedRowIds.includes(targetRowId) || selectedRowIds.length === 0) {
1072
+ const { activeExports } = table.getState();
1073
+ if (!activeExports)
1362
1074
  return false;
1363
- }
1364
- // Rule 2: Target row cannot be a descendant of any selected row
1365
- // (prevents parent from becoming child of its own descendants)
1366
- for (const selectedRowId of selectedRowIds) {
1367
- const selectedRow = table.getRow(selectedRowId, true);
1368
- if (selectedRow &&
1369
- isRowInSubtreeOf(targetRowId, selectedRow)) {
1370
- return false;
1371
- }
1372
- }
1373
- return true;
1374
- };
1375
-
1376
- const useTreeRowReorderingCell = ({ row, table, rowReorderingSelection, maxDepth, onTreeRowReorder, }) => {
1377
- const [isRowHovered, setIsRowHovered] = useState(false);
1378
- const firstSelectedReorderRowDepth = getFirstSelectedReorderRowDepth({
1379
- rowReorderingSelection,
1380
- table,
1381
- });
1382
- const canSelectForReorder = canSelectRowForReorder({
1383
- rowId: row.id,
1384
- rowDepth: row.depth,
1385
- rowReorderingSelection,
1386
- firstSelectedReorderRowDepth,
1075
+ const { selectedFormat, selectedExports, grouped } = activeExports;
1076
+ return (selectedFormat === 'pdf' &&
1077
+ selectedExports.length >= 1 &&
1078
+ (grouped || selectedExports.length === 1));
1079
+ };
1080
+ const createExportAction = (_a = {}) => {
1081
+ var { onExport, renderRow: customRenderRow, renderToolbar: customRenderToolbar } = _a, rest = __rest(_a, ["onExport", "renderRow", "renderToolbar"]);
1082
+ // Pure download logic — no notifications. Throws on failure so callers can handle it.
1083
+ const defaultOnExport = (_a) => __awaiter(void 0, [_a], void 0, function* ({ rowsToExport, table, }) {
1084
+ if (!rowsToExport.length)
1085
+ return;
1086
+ const { loadExport } = table.options;
1087
+ const { activeExports } = table.getState();
1088
+ if (!loadExport || !activeExports)
1089
+ return;
1090
+ const response = yield loadExport({
1091
+ format: activeExports.selectedFormat,
1092
+ exports: activeExports.selectedExports,
1093
+ separated_files: !activeExports.grouped,
1094
+ download: false,
1095
+ ids: JSON.stringify(rowsToExport.map((r) => r.id)),
1096
+ type: 'download',
1097
+ });
1098
+ downloadExportFiles(response);
1387
1099
  });
1388
- const hasAnyReorderSelection = Object.values(rowReorderingSelection !== null && rowReorderingSelection !== void 0 ? rowReorderingSelection : {}).some(Boolean);
1389
- const selectedReorderRowIds = getSelectedReorderRowIds(rowReorderingSelection);
1390
- const selectedRowsForReorder = buildSelectedRowsArray(selectedReorderRowIds, table);
1391
- const shouldShowReorderCheckbox = canSelectForReorder && (isRowHovered || hasAnyReorderSelection);
1392
- const shouldShowInsertHereAction = selectedReorderRowIds.length > 0 &&
1393
- isValidInsertTarget({
1394
- targetRowId: row.id,
1395
- selectedRowIds: selectedReorderRowIds,
1396
- table,
1397
- }) &&
1398
- canInsertSelectedRowsWithoutExceedingMaxDepth({
1399
- maxDepth,
1400
- selectedRows: selectedRowsForReorder,
1401
- targetRowDepth: row.depth,
1100
+ // Pure print logic — no notifications. Throws on failure so callers can handle it.
1101
+ const defaultOnPrint = (_a) => __awaiter(void 0, [_a], void 0, function* ({ rowsToExport, table, }) {
1102
+ if (!rowsToExport.length)
1103
+ return;
1104
+ const { loadExport } = table.options;
1105
+ const { activeExports } = table.getState();
1106
+ if (!loadExport || !activeExports)
1107
+ return;
1108
+ const response = yield loadExport({
1109
+ format: activeExports.selectedFormat,
1110
+ exports: activeExports.selectedExports,
1111
+ separated_files: !activeExports.grouped,
1112
+ download: false,
1113
+ ids: JSON.stringify(rowsToExport.map((r) => r.id)),
1114
+ type: 'print',
1402
1115
  });
1403
- const handleReorderCheckboxChange = useCallback((event) => {
1404
- const checked = event.target.checked;
1405
- table.setRowReorderingSelection((prev) => (Object.assign(Object.assign({}, prev), { [row.id]: checked })));
1406
- }, [row.id, table]);
1407
- const handleInsertHereActionClick = useCallback(() => {
1408
- if (!onTreeRowReorder) {
1409
- console.warn('[MRT] onTreeRowReorder callback is not defined');
1116
+ printExportFiles(response);
1117
+ });
1118
+ // Single execution pipeline for every export flow (row or toolbar).
1119
+ // If a custom handler exists, it receives defaultOnExport and decides when to call it.
1120
+ const executeExport = (context) => {
1121
+ const executeDefaultExport = () => defaultOnExport(context);
1122
+ if (onExport) {
1123
+ return onExport(Object.assign(Object.assign({}, context), { defaultOnExport: executeDefaultExport }));
1124
+ }
1125
+ return executeDefaultExport();
1126
+ };
1127
+ // Row download: checks for active exports, then wraps with loading/success/error notifications.
1128
+ const handleSingleRowExport = (_a) => __awaiter(void 0, [_a], void 0, function* ({ table, row, }) {
1129
+ const { localization } = table.options;
1130
+ if (!hasActiveExports(table)) {
1131
+ enqueueSnackbar(localization.exportNoExportsSelected, {
1132
+ variant: 'warning',
1133
+ });
1410
1134
  return;
1411
1135
  }
1136
+ const loadingKey = enqueueSnackbar(localization.exportInProgress, {
1137
+ variant: 'info',
1138
+ persist: true,
1139
+ });
1412
1140
  try {
1413
- const treeRowReorderEvent = {
1414
- selectedRowIds: selectedReorderRowIds,
1415
- selectedRows: selectedRowsForReorder,
1416
- table,
1417
- targetRow: row,
1418
- };
1419
- onTreeRowReorder(treeRowReorderEvent);
1141
+ yield executeExport({ table, rowsToExport: [row] });
1142
+ closeSnackbar(loadingKey);
1143
+ enqueueSnackbar(localization.exportSuccess, { variant: 'success' });
1420
1144
  }
1421
- catch (error) {
1422
- console.error('[MRT] Error during tree row reorder:', error);
1145
+ catch (_b) {
1146
+ closeSnackbar(loadingKey);
1147
+ enqueueSnackbar(localization.exportError, { variant: 'error' });
1423
1148
  }
1424
- }, [
1425
- onTreeRowReorder,
1426
- selectedReorderRowIds,
1427
- selectedRowsForReorder,
1428
- table,
1429
- row,
1430
- ]);
1431
- return {
1432
- isRowHovered,
1433
- shouldShowReorderCheckbox,
1434
- shouldShowInsertHereAction,
1435
- handleRowHoverEnter: () => setIsRowHovered(true),
1436
- handleRowHoverLeave: () => setIsRowHovered(false),
1437
- handleReorderCheckboxChange,
1438
- handleInsertHereActionClick,
1439
- isReorderCheckboxSelected: !!(rowReorderingSelection === null || rowReorderingSelection === void 0 ? void 0 : rowReorderingSelection[row.id]),
1440
- };
1441
- };
1442
-
1443
- const useTreeRowReorderingHeader = ({ table, enableRowReordering, onTreeRowReorder, }) => {
1444
- const selectedReorderRowIds = getSelectedReorderRowIds(table.getState().rowReorderingSelection);
1445
- const selectedRowsForReorder = buildSelectedRowsArray(selectedReorderRowIds, table);
1446
- const shouldShowMoveToTopLevelAction = !!enableRowReordering &&
1447
- selectedRowsForReorder.length > 0 &&
1448
- selectedRowsForReorder.some((selectedRow) => selectedRow.depth > 0);
1449
- const handleMoveToTopLevelActionClick = useCallback(() => {
1450
- if (!onTreeRowReorder) {
1451
- console.warn('[MRT] onTreeRowReorder callback is not defined');
1149
+ });
1150
+ // Row print: same guard + notification pattern as download, but calls defaultOnPrint.
1151
+ const handleSingleRowPrint = (_a) => __awaiter(void 0, [_a], void 0, function* ({ table, row, }) {
1152
+ const { localization } = table.options;
1153
+ if (!hasActiveExports(table)) {
1154
+ enqueueSnackbar(localization.exportNoExportsSelected, {
1155
+ variant: 'warning',
1156
+ });
1452
1157
  return;
1453
1158
  }
1159
+ const loadingKey = enqueueSnackbar(localization.exportInProgress, {
1160
+ variant: 'info',
1161
+ persist: true,
1162
+ });
1454
1163
  try {
1455
- const treeRowReorderEvent = {
1456
- selectedRowIds: selectedReorderRowIds,
1457
- selectedRows: selectedRowsForReorder,
1458
- table,
1459
- targetRow: null,
1460
- };
1461
- onTreeRowReorder(treeRowReorderEvent);
1164
+ yield defaultOnPrint({ table, rowsToExport: [row] });
1165
+ closeSnackbar(loadingKey);
1166
+ enqueueSnackbar(localization.exportSuccess, { variant: 'success' });
1462
1167
  }
1463
- catch (error) {
1464
- console.error('[MRT] Error during tree row reorder to top level:', error);
1168
+ catch (_b) {
1169
+ closeSnackbar(loadingKey);
1170
+ enqueueSnackbar(localization.exportError, { variant: 'error' });
1465
1171
  }
1466
- }, [onTreeRowReorder, selectedReorderRowIds, selectedRowsForReorder, table]);
1467
- return {
1468
- shouldShowMoveToTopLevelAction,
1469
- handleMoveToTopLevelActionClick,
1172
+ });
1173
+ // Resolves selected rows from table state for toolbar-triggered export (custom renderToolbar only).
1174
+ const handleMultipleRowExport = ({ table, }) => {
1175
+ const rowsToExport = table.getSelectedRowModel().rows;
1176
+ return executeExport({ table, rowsToExport });
1177
+ };
1178
+ const createRowExportExecutor = (context) => () => {
1179
+ void handleSingleRowExport(context);
1180
+ };
1181
+ const createRowPrintExecutor = (context) => () => {
1182
+ void handleSingleRowPrint(context);
1183
+ };
1184
+ const createToolbarExportExecutor = (context) => () => {
1185
+ void handleMultipleRowExport(context);
1186
+ };
1187
+ // Renders download + optional print button. Print is shown under the same conditions
1188
+ // as in MRT_ExportsToolbar: pdf format selected, active exports, grouped or single type.
1189
+ const renderRowAction = (context) => {
1190
+ const onRowExport = createRowExportExecutor(context);
1191
+ const onRowPrint = isPrintAvailable(context.table)
1192
+ ? createRowPrintExecutor(context)
1193
+ : undefined;
1194
+ if (customRenderRow) {
1195
+ return customRenderRow(Object.assign(Object.assign({}, context), { onExport: onRowExport }));
1196
+ }
1197
+ return jsx(ExportRowAction, { onExport: onRowExport, onPrint: onRowPrint });
1198
+ };
1199
+ // Uses custom toolbar renderer when provided; otherwise renders MRT_ExportsToolbar.
1200
+ // loadExport is always wrapped with notifications so that loading/success/error are shown
1201
+ // regardless of whether a custom onExport handler was provided.
1202
+ // When onExport is provided, it intercepts the call and returns [] so MRT_ExportsToolbar
1203
+ // does not attempt a second download from an empty response.
1204
+ const renderToolbarAction = (context) => {
1205
+ const { table } = context;
1206
+ const { availableExports, loadExport, onActiveExportsChange, localization, } = table.options;
1207
+ const { activeExports } = table.getState();
1208
+ if (customRenderToolbar) {
1209
+ return customRenderToolbar(Object.assign(Object.assign({}, context), { onExport: createToolbarExportExecutor(context) }));
1210
+ }
1211
+ if (!availableExports ||
1212
+ !loadExport ||
1213
+ !onActiveExportsChange ||
1214
+ !activeExports) {
1215
+ return null;
1216
+ }
1217
+ const notifiedLoadExport = (params) => __awaiter(void 0, void 0, void 0, function* () {
1218
+ const loadingKey = enqueueSnackbar(localization.exportInProgress, {
1219
+ variant: 'info',
1220
+ persist: true,
1221
+ });
1222
+ try {
1223
+ let response;
1224
+ if (onExport) {
1225
+ const rowsToExport = table.getSelectedRowModel().rows;
1226
+ yield executeExport({ table, rowsToExport });
1227
+ response = [];
1228
+ }
1229
+ else {
1230
+ response = yield loadExport(params);
1231
+ }
1232
+ closeSnackbar(loadingKey);
1233
+ enqueueSnackbar(localization.exportSuccess, { variant: 'success' });
1234
+ return response;
1235
+ }
1236
+ catch (_a) {
1237
+ closeSnackbar(loadingKey);
1238
+ enqueueSnackbar(localization.exportError, { variant: 'error' });
1239
+ return [];
1240
+ }
1241
+ });
1242
+ return (jsx(MRT_ExportsToolbar, { table: table, availableExports: availableExports, exportState: activeExports, onExportStateChange: onActiveExportsChange, loadExport: notifiedLoadExport }));
1470
1243
  };
1244
+ return Object.assign({ name: 'export', renderRow: renderRowAction, renderToolbar: renderToolbarAction }, rest);
1471
1245
  };
1472
1246
 
1473
- const TREE_REORDER_ICON_SPACING = '0.25rem';
1474
- const getMRT_RowExpandColumnDef = (tableOptions) => {
1247
+ const MRT_AggregationFns = Object.assign({}, aggregationFns);
1248
+
1249
+ const fuzzy = (row, columnId, filterValue, addMeta) => {
1250
+ const itemRank = rankItem(row.getValue(columnId), filterValue, {
1251
+ threshold: rankings.MATCHES,
1252
+ });
1253
+ addMeta(itemRank);
1254
+ return itemRank.passed;
1255
+ };
1256
+ fuzzy.autoRemove = (val) => !val;
1257
+ const contains = (row, id, filterValue) => {
1475
1258
  var _a;
1476
- const { defaultColumn, enableRowReordering, enableExpandAll, groupedColumnMode, maxDepth, onTreeRowReorder, positionExpandColumn, renderDetailPanel, state: { grouping, rowReorderingSelection }, } = tableOptions;
1477
- const alignProps = positionExpandColumn === 'last'
1478
- ? {
1479
- align: 'right',
1480
- }
1481
- : undefined;
1482
- return Object.assign(Object.assign({ Cell: ({ cell, column, row, staticRowIndex, table }) => {
1483
- var _a, _b, _c;
1484
- const cellLogic = useTreeRowReorderingCell({
1485
- row,
1486
- table,
1487
- rowReorderingSelection,
1488
- maxDepth,
1489
- onTreeRowReorder,
1490
- });
1491
- const expandButtonProps = { row, staticRowIndex, table };
1492
- const subRowsLength = (_a = row.subRows) === null || _a === void 0 ? void 0 : _a.length;
1493
- const customGroupedCell = (_c = (_b = column.columnDef).GroupedCell) === null || _c === void 0 ? void 0 : _c.call(_b, {
1494
- cell,
1495
- column,
1496
- row,
1497
- table,
1498
- staticRowIndex,
1499
- });
1500
- if (groupedColumnMode === 'remove' && row.groupingColumnId) {
1501
- const defaultGroupedCell = (jsx(Tooltip, Object.assign({}, getCommonTooltipProps('right'), { title: table.getColumn(row.groupingColumnId).columnDef.header, children: jsx("span", { children: row.groupingValue }) })));
1502
- return (jsxs(Stack, { alignItems: "center", flexDirection: "row", gap: TREE_REORDER_ICON_SPACING, onMouseEnter: cellLogic.handleRowHoverEnter, onMouseLeave: cellLogic.handleRowHoverLeave, width: "100%", children: [jsx(MRT_ExpandButton, Object.assign({}, expandButtonProps)), column.columnDef.GroupedCell
1503
- ? customGroupedCell
1504
- : defaultGroupedCell, cellLogic.shouldShowReorderCheckbox && (jsx(MRT_ReorderRowCheckbox, { isSelected: cellLogic.isReorderCheckboxSelected, onChange: cellLogic.handleReorderCheckboxChange })), cellLogic.shouldShowInsertHereAction && (jsx(MRT_InsertHereAction, { onClick: cellLogic.handleInsertHereActionClick })), !!subRowsLength && jsxs("span", { children: ["(", subRowsLength, ")"] })] }));
1505
- }
1506
- return (jsxs(Stack, { alignItems: "center", flexDirection: "row", gap: TREE_REORDER_ICON_SPACING, onMouseEnter: cellLogic.handleRowHoverEnter, onMouseLeave: cellLogic.handleRowHoverLeave, width: "100%", children: [jsx(MRT_ExpandButton, Object.assign({}, expandButtonProps)), customGroupedCell, cellLogic.shouldShowReorderCheckbox && (jsx(MRT_ReorderRowCheckbox, { isSelected: cellLogic.isReorderCheckboxSelected, onChange: cellLogic.handleReorderCheckboxChange })), cellLogic.shouldShowInsertHereAction && (jsx(MRT_InsertHereAction, { onClick: cellLogic.handleInsertHereActionClick }))] }));
1507
- }, Header: enableExpandAll
1508
- ? ({ table }) => {
1509
- var _a;
1510
- const headerLogic = useTreeRowReorderingHeader({
1511
- table,
1512
- enableRowReordering,
1513
- onTreeRowReorder,
1514
- });
1515
- return (jsxs(Stack, { alignItems: "center", flexDirection: "row", gap: TREE_REORDER_ICON_SPACING, children: [jsx(MRT_ExpandAllButton, { table: table }), headerLogic.shouldShowMoveToTopLevelAction && (jsx(MRT_MoveToTopAction, { onClick: headerLogic.handleMoveToTopLevelActionClick })), groupedColumnMode === 'remove' &&
1516
- ((_a = grouping === null || grouping === void 0 ? void 0 : grouping.map((groupedColumnId) => table.getColumn(groupedColumnId).columnDef.header)) === null || _a === void 0 ? void 0 : _a.join(', '))] }));
1517
- }
1518
- : undefined, muiTableBodyCellProps: alignProps, muiTableHeadCellProps: alignProps }, defaultDisplayColumnProps({
1519
- header: 'expand',
1520
- id: 'mrt-row-expand',
1521
- size: groupedColumnMode === 'remove'
1522
- ? ((_a = defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.size) !== null && _a !== void 0 ? _a : 180)
1523
- : renderDetailPanel
1524
- ? enableExpandAll
1525
- ? 60
1526
- : 70
1527
- : 100,
1528
- tableOptions,
1529
- })), { enableResizing: true });
1259
+ return !!((_a = row
1260
+ .getValue(id)) === null || _a === void 0 ? void 0 : _a.toString().toLowerCase().trim().includes(filterValue.toString().toLowerCase().trim()));
1530
1261
  };
1531
-
1532
- const getMRT_RowNumbersColumnDef = (tableOptions) => {
1533
- const { localization, rowNumberDisplayMode } = tableOptions;
1534
- const { pagination: { pageIndex, pageSize }, } = tableOptions.state;
1535
- return Object.assign({ Cell: ({ row, staticRowIndex }) => {
1536
- var _a;
1537
- return ((_a = (rowNumberDisplayMode === 'static'
1538
- ? (staticRowIndex || 0) + (pageSize || 0) * (pageIndex || 0)
1539
- : row.index)) !== null && _a !== void 0 ? _a : 0) + 1;
1540
- }, Header: () => localization.rowNumber, grow: false }, defaultDisplayColumnProps({
1541
- header: 'rowNumbers',
1542
- id: 'mrt-row-numbers',
1543
- size: 50,
1544
- tableOptions,
1545
- }));
1262
+ contains.autoRemove = (val) => !val;
1263
+ const startsWith = (row, id, filterValue) => {
1264
+ var _a;
1265
+ return !!((_a = row
1266
+ .getValue(id)) === null || _a === void 0 ? void 0 : _a.toString().toLowerCase().trim().startsWith(filterValue.toString().toLowerCase().trim()));
1267
+ };
1268
+ startsWith.autoRemove = (val) => !val;
1269
+ const endsWith = (row, id, filterValue) => {
1270
+ var _a;
1271
+ return !!((_a = row
1272
+ .getValue(id)) === null || _a === void 0 ? void 0 : _a.toString().toLowerCase().trim().endsWith(filterValue.toString().toLowerCase().trim()));
1273
+ };
1274
+ endsWith.autoRemove = (val) => !val;
1275
+ const equals = (row, id, filterValue) => {
1276
+ var _a;
1277
+ return ((_a = row.getValue(id)) === null || _a === void 0 ? void 0 : _a.toString().toLowerCase().trim()) ===
1278
+ filterValue.toString().toLowerCase().trim();
1279
+ };
1280
+ equals.autoRemove = (val) => !val;
1281
+ const notEquals = (row, id, filterValue) => {
1282
+ var _a;
1283
+ return ((_a = row.getValue(id)) === null || _a === void 0 ? void 0 : _a.toString().toLowerCase().trim()) !==
1284
+ filterValue.toString().toLowerCase().trim();
1285
+ };
1286
+ notEquals.autoRemove = (val) => !val;
1287
+ const greaterThan = (row, id, filterValue) => {
1288
+ var _a, _b, _c;
1289
+ return !isNaN(+filterValue) && !isNaN(+row.getValue(id))
1290
+ ? +((_a = row.getValue(id)) !== null && _a !== void 0 ? _a : 0) > +filterValue
1291
+ : ((_c = ((_b = row.getValue(id)) !== null && _b !== void 0 ? _b : '')) === null || _c === void 0 ? void 0 : _c.toString().toLowerCase().trim()) > filterValue.toString().toLowerCase().trim();
1546
1292
  };
1293
+ greaterThan.autoRemove = (val) => !val;
1294
+ const greaterThanOrEqualTo = (row, id, filterValue) => equals(row, id, filterValue) || greaterThan(row, id, filterValue);
1295
+ greaterThanOrEqualTo.autoRemove = (val) => !val;
1296
+ const lessThan = (row, id, filterValue) => {
1297
+ var _a, _b, _c;
1298
+ return !isNaN(+filterValue) && !isNaN(+row.getValue(id))
1299
+ ? +((_a = row.getValue(id)) !== null && _a !== void 0 ? _a : 0) < +filterValue
1300
+ : ((_c = ((_b = row.getValue(id)) !== null && _b !== void 0 ? _b : '')) === null || _c === void 0 ? void 0 : _c.toString().toLowerCase().trim()) < filterValue.toString().toLowerCase().trim();
1301
+ };
1302
+ lessThan.autoRemove = (val) => !val;
1303
+ const lessThanOrEqualTo = (row, id, filterValue) => equals(row, id, filterValue) || lessThan(row, id, filterValue);
1304
+ lessThanOrEqualTo.autoRemove = (val) => !val;
1305
+ const between = (row, id, filterValues) => (['', undefined].includes(filterValues[0]) ||
1306
+ greaterThan(row, id, filterValues[0])) &&
1307
+ ((!isNaN(+filterValues[0]) &&
1308
+ !isNaN(+filterValues[1]) &&
1309
+ +filterValues[0] > +filterValues[1]) ||
1310
+ ['', undefined].includes(filterValues[1]) ||
1311
+ lessThan(row, id, filterValues[1]));
1312
+ between.autoRemove = (val) => !val;
1313
+ const betweenInclusive = (row, id, filterValues) => (['', undefined].includes(filterValues[0]) ||
1314
+ greaterThanOrEqualTo(row, id, filterValues[0])) &&
1315
+ ((!isNaN(+filterValues[0]) &&
1316
+ !isNaN(+filterValues[1]) &&
1317
+ +filterValues[0] > +filterValues[1]) ||
1318
+ ['', undefined].includes(filterValues[1]) ||
1319
+ lessThanOrEqualTo(row, id, filterValues[1]));
1320
+ betweenInclusive.autoRemove = (val) => !val;
1321
+ const empty = (row, id, _filterValue) => { var _a; return !((_a = row.getValue(id)) === null || _a === void 0 ? void 0 : _a.toString().trim()); };
1322
+ empty.autoRemove = (val) => !val;
1323
+ const notEmpty = (row, id, _filterValue) => { var _a; return !!((_a = row.getValue(id)) === null || _a === void 0 ? void 0 : _a.toString().trim()); };
1324
+ notEmpty.autoRemove = (val) => !val;
1325
+ const MRT_FilterFns = Object.assign(Object.assign({}, filterFns), { between,
1326
+ betweenInclusive,
1327
+ contains,
1328
+ empty,
1329
+ endsWith,
1330
+ equals,
1331
+ fuzzy,
1332
+ greaterThan,
1333
+ greaterThanOrEqualTo,
1334
+ lessThan,
1335
+ lessThanOrEqualTo,
1336
+ notEmpty,
1337
+ notEquals,
1338
+ startsWith });
1547
1339
 
1548
- const MRT_RowPinButton = (_a) => {
1549
- var { pinningPosition, row, table } = _a, rest = __rest(_a, ["pinningPosition", "row", "table"]);
1550
- const { options: { icons: { CloseIcon, PushPinIcon }, localization, rowPinningDisplayMode, }, } = table;
1551
- const isPinned = row.getIsPinned();
1552
- const [tooltipOpened, setTooltipOpened] = useState(false);
1553
- const handleTogglePin = (event) => {
1554
- setTooltipOpened(false);
1555
- event.stopPropagation();
1556
- row.pin(isPinned ? false : pinningPosition);
1557
- };
1558
- return (jsx(Tooltip, Object.assign({}, getCommonTooltipProps(), { open: tooltipOpened, title: isPinned ? localization.unpin : localization.pin, children: jsx(IconButton, Object.assign({ "aria-label": localization.pin, onBlur: () => setTooltipOpened(false), onClick: handleTogglePin, onFocus: () => setTooltipOpened(true), onMouseEnter: () => setTooltipOpened(true), onMouseLeave: () => setTooltipOpened(false), size: "small" }, rest, { sx: (theme) => (Object.assign({ height: '24px', width: '24px' }, parseFromValuesOrFunc(rest === null || rest === void 0 ? void 0 : rest.sx, theme))), children: isPinned ? (jsx(CloseIcon, {})) : (jsx(PushPinIcon, { fontSize: "small", style: {
1559
- transform: `rotate(${rowPinningDisplayMode === 'sticky'
1560
- ? 135
1561
- : pinningPosition === 'top'
1562
- ? 180
1563
- : 0}deg)`,
1564
- } })) })) })));
1340
+ const useMRT_SliceValue = (store, selector) => {
1341
+ const getSnapshot = () => selector(store.get());
1342
+ return useSyncExternalStore(store.subscribe, getSnapshot, getSnapshot);
1565
1343
  };
1566
1344
 
1567
- const MRT_TableBodyRowPinButton = (_a) => {
1568
- var { row, table } = _a, rest = __rest(_a, ["row", "table"]);
1569
- const { getState, options: { enableRowPinning, rowPinningDisplayMode }, } = table;
1570
- const { density } = getState();
1571
- const canPin = parseFromValuesOrFunc(enableRowPinning, row);
1572
- if (!canPin)
1573
- return null;
1574
- const rowPinButtonProps = Object.assign({ row,
1575
- table }, rest);
1576
- if (rowPinningDisplayMode === 'top-and-bottom' && !row.getIsPinned()) {
1577
- return (jsxs(Box, { sx: {
1578
- display: 'flex',
1579
- flexDirection: density === 'compact' ? 'row' : 'column',
1580
- }, children: [jsx(MRT_RowPinButton, Object.assign({ pinningPosition: "top" }, rowPinButtonProps)), jsx(MRT_RowPinButton, Object.assign({ pinningPosition: "bottom" }, rowPinButtonProps))] }));
1581
- }
1582
- return (jsx(MRT_RowPinButton, Object.assign({ pinningPosition: rowPinningDisplayMode === 'bottom' ? 'bottom' : 'top' }, rowPinButtonProps)));
1345
+ const MRT_ActionMenuItem = (_a) => {
1346
+ var { icon, label, onOpenSubMenu, table } = _a, rest = __rest(_a, ["icon", "label", "onOpenSubMenu", "table"]);
1347
+ const { options: { icons: { ArrowRightIcon }, }, } = table;
1348
+ return (jsxs(MenuItem, Object.assign({ sx: {
1349
+ alignItems: 'center',
1350
+ justifyContent: 'space-between',
1351
+ minWidth: '120px',
1352
+ my: 0,
1353
+ py: '6px',
1354
+ }, tabIndex: 0 }, rest, { children: [jsxs(Box, { sx: {
1355
+ alignItems: 'center',
1356
+ display: 'flex',
1357
+ }, children: [jsx(ListItemIcon, { children: icon }), label] }), onOpenSubMenu && (jsx(IconButton, { onClick: (e) => onOpenSubMenu(e), onMouseEnter: (e) => onOpenSubMenu(e), size: "small", sx: { p: 0 }, children: jsx(ArrowRightIcon, {}) }))] })));
1583
1358
  };
1584
1359
 
1585
- const getMRT_RowPinningColumnDef = (tableOptions) => {
1586
- return Object.assign({ Cell: ({ row, table }) => (jsx(MRT_TableBodyRowPinButton, { row: row, table: table })), grow: false }, defaultDisplayColumnProps({
1587
- header: 'pin',
1588
- id: 'mrt-row-pin',
1589
- size: 60,
1590
- tableOptions,
1591
- }));
1360
+ const MRT_RowActionMenu = (_a) => {
1361
+ var { anchorEl, handleEdit, row, setAnchorEl, staticRowIndex, table } = _a, rest = __rest(_a, ["anchorEl", "handleEdit", "row", "setAnchorEl", "staticRowIndex", "table"]);
1362
+ const { options: { editDisplayMode, enableEditing, icons: { EditIcon }, localization, mrtTheme: { menuBackgroundColor }, renderRowActionMenuItems, }, } = table;
1363
+ const density = useMRT_SliceValue(table._uiStore, (s) => s.density);
1364
+ const menuItems = useMemo(() => {
1365
+ const items = [];
1366
+ const editItem = parseFromValuesOrFunc(enableEditing, row) &&
1367
+ ['modal', 'row'].includes(editDisplayMode) && (jsx(MRT_ActionMenuItem, { icon: jsx(EditIcon, {}), label: localization.edit, onClick: handleEdit, table: table }, 'edit'));
1368
+ if (editItem)
1369
+ items.push(editItem);
1370
+ const rowActionMenuItems = renderRowActionMenuItems === null || renderRowActionMenuItems === void 0 ? void 0 : renderRowActionMenuItems({
1371
+ closeMenu: () => setAnchorEl(null),
1372
+ row,
1373
+ staticRowIndex,
1374
+ table,
1375
+ });
1376
+ if (rowActionMenuItems === null || rowActionMenuItems === void 0 ? void 0 : rowActionMenuItems.length)
1377
+ items.push(...rowActionMenuItems);
1378
+ return items;
1379
+ }, [renderRowActionMenuItems, row, staticRowIndex, table]);
1380
+ if (!menuItems.length)
1381
+ return null;
1382
+ return (jsx(Menu, Object.assign({ MenuListProps: {
1383
+ dense: density === 'compact',
1384
+ sx: {
1385
+ backgroundColor: menuBackgroundColor,
1386
+ },
1387
+ }, anchorEl: anchorEl, disableScrollLock: true, onClick: (event) => event.stopPropagation(), onClose: () => setAnchorEl(null), open: !!anchorEl }, rest, { children: menuItems })));
1592
1388
  };
1593
1389
 
1594
- const MRT_SelectAllMenu = ({ table, }) => {
1595
- const [anchorEl, setAnchorEl] = useState(null);
1596
- const [isSelectingAllPages, setIsSelectingAllPages] = useState(false);
1597
- const { getState, options: { enableRowPinning, getAllSelectableRowIds, localization, rowPinningDisplayMode, }, refs: { allSelectableRowIdsRef }, } = table;
1598
- // rowSelection is read here so that any change to selection will trigger a re-render and update the menu options accordingly
1599
- const { isLoading, rowSelection } = getState();
1600
- const isAllCurrentPageSelected = table.getIsAllPageRowsSelected();
1601
- const isAllPagesActive = getIsAllPagesSelectionActive(table, rowSelection);
1602
- const handleOpen = (event) => {
1603
- setAnchorEl(event.currentTarget);
1604
- };
1605
- const handleClose = () => {
1606
- setAnchorEl(null);
1607
- };
1608
- // Clears row pinning on every bulk selection/deselection
1609
- const clearPinning = () => {
1610
- if (enableRowPinning && (rowPinningDisplayMode === null || rowPinningDisplayMode === void 0 ? void 0 : rowPinningDisplayMode.includes('select'))) {
1611
- table.setRowPinning({ bottom: [], top: [] });
1390
+ const MRT_EditActionButtons = (_a) => {
1391
+ var { row, table, variant = 'icon' } = _a, rest = __rest(_a, ["row", "table", "variant"]);
1392
+ const { getState, options: { icons: { CancelIcon, SaveIcon }, localization, onCreatingRowCancel, onCreatingRowSave, onEditingRowCancel, onEditingRowSave, }, refs: { editInputRefs }, setCreatingRow, setEditingRow, } = table;
1393
+ const { creatingRow, isSaving } = getState();
1394
+ const isCreating = (creatingRow === null || creatingRow === void 0 ? void 0 : creatingRow.id) === row.id;
1395
+ const isEditing = useMRT_SliceValue(table._uiStore, (s) => { var _a; return ((_a = s.editingRow) === null || _a === void 0 ? void 0 : _a.id) === row.id; });
1396
+ const handleCancel = () => {
1397
+ if (isCreating) {
1398
+ onCreatingRowCancel === null || onCreatingRowCancel === void 0 ? void 0 : onCreatingRowCancel({ row, table });
1399
+ setCreatingRow(null);
1612
1400
  }
1401
+ else if (isEditing) {
1402
+ onEditingRowCancel === null || onEditingRowCancel === void 0 ? void 0 : onEditingRowCancel({ row, table });
1403
+ setEditingRow(null);
1404
+ }
1405
+ row._valuesCache = {}; //reset values cache
1613
1406
  };
1614
- // ── Current-page actions ────────────────────────────────────────────────────
1615
- const handleSelectCurrentPage = () => {
1616
- table.toggleAllPageRowsSelected(true);
1617
- clearPinning();
1618
- handleClose();
1619
- };
1620
- const handleDeselectCurrentPage = () => {
1621
- if (allSelectableRowIdsRef.current.length > 0) {
1622
- // When all pages are selected, deselecting the current page must clear the entire selection — otherwise rows on other pages remain "ghost-selected" but the user can't see them.
1623
- table.setRowSelection({});
1624
- allSelectableRowIdsRef.current = [];
1625
- }
1626
- else {
1627
- table.toggleAllPageRowsSelected(false);
1628
- }
1629
- clearPinning();
1630
- handleClose();
1631
- };
1632
- // ── All-pages actions ───────────────────────────────────────────────────────
1633
- const handleSelectAllPages = () => __awaiter(void 0, void 0, void 0, function* () {
1634
- handleClose();
1635
- if (getAllSelectableRowIds) {
1636
- // Server-side: IDs are not available locally, fetch them from the API
1637
- setIsSelectingAllPages(true);
1638
- table.setShowProgressBars(true);
1639
- try {
1640
- const ids = yield getAllSelectableRowIds({ table });
1641
- allSelectableRowIdsRef.current = ids;
1642
- const newSelection = {};
1643
- ids.forEach((id) => {
1644
- newSelection[id] = true;
1645
- });
1646
- table.setRowSelection(newSelection);
1647
- clearPinning();
1648
- }
1649
- finally {
1650
- setIsSelectingAllPages(false);
1651
- table.setShowProgressBars(false);
1407
+ const handleSubmitRow = () => {
1408
+ var _a, _b;
1409
+ //look for auto-filled input values
1410
+ (_b = Object.values((_a = editInputRefs.current) !== null && _a !== void 0 ? _a : {})
1411
+ .filter((inputRef) => { var _a, _b; return row.id === ((_b = (_a = inputRef === null || inputRef === void 0 ? void 0 : inputRef.name) === null || _a === void 0 ? void 0 : _a.split('_')) === null || _b === void 0 ? void 0 : _b[0]); })) === null || _b === void 0 ? void 0 : _b.forEach((input) => {
1412
+ if (input.value !== undefined &&
1413
+ Object.hasOwn(row === null || row === void 0 ? void 0 : row._valuesCache, input.name)) {
1414
+ // @ts-expect-error
1415
+ row._valuesCache[input.name] = input.value;
1652
1416
  }
1417
+ });
1418
+ if (isCreating)
1419
+ onCreatingRowSave === null || onCreatingRowSave === void 0 ? void 0 : onCreatingRowSave({
1420
+ exitCreatingMode: () => setCreatingRow(null),
1421
+ row,
1422
+ table,
1423
+ values: row._valuesCache,
1424
+ });
1425
+ else if (isEditing) {
1426
+ onEditingRowSave === null || onEditingRowSave === void 0 ? void 0 : onEditingRowSave({
1427
+ exitEditingMode: () => setEditingRow(null),
1428
+ row,
1429
+ table,
1430
+ values: row === null || row === void 0 ? void 0 : row._valuesCache,
1431
+ });
1653
1432
  }
1654
- else {
1655
- // Client-side: all data is available locally
1656
- table.toggleAllRowsSelected(true);
1657
- clearPinning();
1658
- }
1659
- });
1660
- const handleDeselectAllPages = () => {
1661
- if (getAllSelectableRowIds) {
1662
- table.setRowSelection({});
1663
- }
1664
- else {
1665
- table.toggleAllRowsSelected(false);
1666
- }
1667
- allSelectableRowIdsRef.current = [];
1668
- clearPinning();
1669
- handleClose();
1670
1433
  };
1671
- const isDisabled = isLoading || isSelectingAllPages;
1672
- return (jsxs(Fragment, { children: [jsx(Tooltip, Object.assign({}, getCommonTooltipProps(), { title: localization.toggleSelectAll, children: jsx("span", { children: jsx(IconButton, { "aria-label": localization.toggleSelectAll, disabled: isDisabled, onClick: handleOpen, size: "small", sx: { height: '1.5rem', width: '1.5rem' }, children: jsx(table.options.icons.MoreVertIcon, { style: { transform: 'scale(0.85)' } }) }) }) })), jsxs(Menu, { anchorEl: anchorEl, onClose: handleClose, open: Boolean(anchorEl), children: [isAllCurrentPageSelected ? (jsx(MenuItem, { onClick: handleDeselectCurrentPage, children: localization.deselectAllOnCurrentPage })) : (jsx(MenuItem, { onClick: handleSelectCurrentPage, children: localization.selectAllOnCurrentPage })), isAllPagesActive ? (jsx(MenuItem, { onClick: handleDeselectAllPages, children: localization.deselectAllOnAllPages })) : (jsxs(MenuItem, { disabled: isSelectingAllPages, onClick: handleSelectAllPages, children: [isSelectingAllPages && (jsx(CircularProgress, { "aria-label": "Loading", size: 14, sx: { mr: 1 } })), localization.selectAllOnAllPages] }))] })] }));
1434
+ return (jsx(Box, { onClick: (e) => e.stopPropagation(), sx: (theme) => (Object.assign({ display: 'flex', gap: '0.75rem' }, parseFromValuesOrFunc(rest === null || rest === void 0 ? void 0 : rest.sx, theme))), children: variant === 'icon' ? (jsxs(Fragment, { children: [jsx(Tooltip, { title: localization.cancel, children: jsx(IconButton, { "aria-label": localization.cancel, onClick: handleCancel, children: jsx(CancelIcon, {}) }) }), ((isCreating && onCreatingRowSave) ||
1435
+ (isEditing && onEditingRowSave)) && (jsx(Tooltip, { title: localization.save, children: jsx(IconButton, { "aria-label": localization.save, color: "info", disabled: isSaving, onClick: handleSubmitRow, children: isSaving ? jsx(CircularProgress, { size: 18 }) : jsx(SaveIcon, {}) }) }))] })) : (jsxs(Fragment, { children: [jsx(Button, { onClick: handleCancel, sx: { minWidth: '100px' }, children: localization.cancel }), jsxs(Button, { disabled: isSaving, onClick: handleSubmitRow, sx: { minWidth: '100px' }, variant: "contained", children: [isSaving && jsx(CircularProgress, { color: "inherit", size: 18 }), localization.save] })] })) }));
1673
1436
  };
1674
1437
 
1675
- const MRT_SelectCheckbox = (_a) => {
1438
+ const parseCSSVarId = (id) => id.replace(/[^a-zA-Z0-9]/g, '_');
1439
+ const getMRTTheme = (mrtTheme, muiTheme) => {
1440
+ const mrtThemeOverrides = parseFromValuesOrFunc(mrtTheme, muiTheme);
1441
+ const baseBackgroundColor = muiTheme.palette.background.default;
1442
+ return Object.assign({ baseBackgroundColor, cellNavigationOutlineColor: muiTheme.palette.primary.main, draggingBorderColor: muiTheme.palette.primary.main, matchHighlightColor: muiTheme.palette.mode === 'dark'
1443
+ ? darken(muiTheme.palette.warning.dark, 0.25)
1444
+ : lighten(muiTheme.palette.warning.light, 0.5), menuBackgroundColor: lighten(baseBackgroundColor, 0.07), pinnedRowBackgroundColor: alpha(muiTheme.palette.primary.main, 0.1), selectedRowBackgroundColor: alpha(muiTheme.palette.primary.main, 0.2) }, mrtThemeOverrides);
1445
+ };
1446
+ const commonCellBeforeAfterStyles = {
1447
+ content: '""',
1448
+ height: '100%',
1449
+ left: 0,
1450
+ position: 'absolute',
1451
+ top: 0,
1452
+ width: '100%',
1453
+ zIndex: -1,
1454
+ };
1455
+ const getCommonPinnedCellStyles = ({ table, theme, }) => {
1456
+ const { baseBackgroundColor } = table.options.mrtTheme;
1457
+ return {
1458
+ '&[data-pinned="true"]': {
1459
+ '&:before': Object.assign({ backgroundColor: alpha(darken(baseBackgroundColor, theme.palette.mode === 'dark' ? 0.05 : 0.01), 0.97) }, commonCellBeforeAfterStyles),
1460
+ },
1461
+ };
1462
+ };
1463
+ const getCommonMRTCellStyles = ({ column, header, isDraggingColumn, isHoveredColumn, table, tableCellProps, theme, }) => {
1464
+ var _a, _b, _c, _d, _e, _f;
1465
+ const { options: { enableColumnVirtualization, layoutMode }, } = table;
1466
+ const { columnDef } = column;
1467
+ const { columnDefType } = columnDef;
1468
+ const isColumnPinned = columnDef.columnDefType !== 'group' && column.getIsPinned();
1469
+ const widthStyles = {
1470
+ minWidth: `max(calc(var(--${header ? 'header' : 'col'}-${parseCSSVarId((_a = header === null || header === void 0 ? void 0 : header.id) !== null && _a !== void 0 ? _a : column.id)}-size) * 1px), ${(_b = columnDef.minSize) !== null && _b !== void 0 ? _b : 30}px)`,
1471
+ width: `calc(var(--${header ? 'header' : 'col'}-${parseCSSVarId((_c = header === null || header === void 0 ? void 0 : header.id) !== null && _c !== void 0 ? _c : column.id)}-size) * 1px)`,
1472
+ };
1473
+ if (layoutMode === 'grid') {
1474
+ widthStyles.flex = `${[0, false].includes(columnDef.grow)
1475
+ ? 0
1476
+ : `var(--${header ? 'header' : 'col'}-${parseCSSVarId((_d = header === null || header === void 0 ? void 0 : header.id) !== null && _d !== void 0 ? _d : column.id)}-size)`} 0 auto`;
1477
+ }
1478
+ else if (layoutMode === 'grid-no-grow') {
1479
+ widthStyles.flex = `${+(columnDef.grow || 0)} 0 auto`;
1480
+ }
1481
+ // The checkbox column is technically pinned (for sticky positioning) but
1482
+ // should look like a regular center column — no background overlay or shadow.
1483
+ const isCheckboxColumn = column.id === CHECKBOX_DISPLAY_COLUMN_ID;
1484
+ // Count all currently pinned column IDs across both sides.
1485
+ // Checkbox is always pinned (counts as 1), so > 1 means the user has
1486
+ // explicitly pinned at least one additional column.
1487
+ const totalPinnedColumnCount = [
1488
+ ...((_e = table.getState().columnPinning.left) !== null && _e !== void 0 ? _e : []),
1489
+ ...((_f = table.getState().columnPinning.right) !== null && _f !== void 0 ? _f : []),
1490
+ ].length;
1491
+ const hasNoPinnedColumns = totalPinnedColumnCount === 0;
1492
+ const pinnedStyles = isColumnPinned
1493
+ ? Object.assign(Object.assign({}, (isCheckboxColumn
1494
+ ? hasNoPinnedColumns
1495
+ ? {
1496
+ // Use doubled class selector (&&) to beat the row-level
1497
+ // td[data-pinned="true"]:before specificity from MRT_TableBodyRow.
1498
+ '&&[data-pinned="true"]': {
1499
+ '&:before': {
1500
+ backgroundColor: 'transparent',
1501
+ boxShadow: 'none',
1502
+ },
1503
+ },
1504
+ }
1505
+ : // Other columns are also pinned — apply standard pinned background
1506
+ // so the checkbox header matches the pinned row cells below it.
1507
+ getCommonPinnedCellStyles({ column, table, theme })
1508
+ : getCommonPinnedCellStyles({ column, table, theme }))), { left: isColumnPinned === 'left'
1509
+ ? `${column.getStart('left')}px`
1510
+ : undefined,
1511
+ // Skip opacity reduction for checkbox — keep it fully opaque like center columns
1512
+ opacity: isCheckboxColumn ? undefined : 0.97, position: 'sticky', right: isColumnPinned === 'right'
1513
+ ? `${column.getAfter('right')}px`
1514
+ : undefined }) : {};
1515
+ return Object.assign(Object.assign(Object.assign({ backgroundColor: 'inherit', backgroundImage: 'inherit', display: (layoutMode === null || layoutMode === void 0 ? void 0 : layoutMode.startsWith('grid')) ? 'flex' : undefined, justifyContent: columnDefType === 'group'
1516
+ ? 'center'
1517
+ : (layoutMode === null || layoutMode === void 0 ? void 0 : layoutMode.startsWith('grid'))
1518
+ ? tableCellProps.align
1519
+ : undefined, opacity: isDraggingColumn || isHoveredColumn ? 0.5 : 1, position: 'relative', transition: enableColumnVirtualization
1520
+ ? 'none'
1521
+ : `padding 150ms ease-in-out`, zIndex: column.getIsResizing() || isDraggingColumn
1522
+ ? 2
1523
+ : columnDefType !== 'group' && isColumnPinned
1524
+ ? 1
1525
+ : 0, '&:focus-visible': {
1526
+ outline: `2px solid ${table.options.mrtTheme.cellNavigationOutlineColor}`,
1527
+ outlineOffset: '-2px',
1528
+ } }, pinnedStyles), widthStyles), parseFromValuesOrFunc(tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.sx, theme));
1529
+ };
1530
+ const getCommonToolbarStyles = ({ table, }) => ({
1531
+ alignItems: 'flex-start',
1532
+ backgroundColor: table.options.mrtTheme.baseBackgroundColor,
1533
+ display: 'grid',
1534
+ flexWrap: 'wrap-reverse',
1535
+ position: 'relative',
1536
+ transition: 'all 150ms ease-in-out',
1537
+ zIndex: 1,
1538
+ });
1539
+ const flipIconStyles = (theme) => theme.direction === 'rtl'
1540
+ ? { style: { transform: 'scaleX(-1)' } }
1541
+ : undefined;
1542
+ const getCommonTooltipProps = (placement) => ({
1543
+ disableInteractive: true,
1544
+ enterDelay: 1000,
1545
+ enterNextDelay: 1000,
1546
+ placement,
1547
+ });
1548
+
1549
+ const commonIconButtonStyles = {
1550
+ '&:hover': {
1551
+ opacity: 1,
1552
+ },
1553
+ height: '2rem',
1554
+ ml: '10px',
1555
+ opacity: 0.5,
1556
+ transition: 'opacity 150ms',
1557
+ width: '2rem',
1558
+ };
1559
+ const MRT_ToggleRowActionMenuButton = (_a) => {
1676
1560
  var _b;
1677
- var { row, staticRowIndex, table } = _a, rest = __rest(_a, ["row", "staticRowIndex", "table"]);
1678
- const { getState, options: { enableMultiRowSelection, localization, muiSelectAllCheckboxProps, muiSelectCheckboxProps, selectAllMode, }, } = table;
1679
- const { density, isLoading } = getState();
1680
- const selectAll = !row;
1681
- const allRowsSelected = selectAll
1682
- ? selectAllMode === 'page'
1683
- ? table.getIsAllPageRowsSelected()
1684
- : table.getIsAllRowsSelected()
1685
- : undefined;
1686
- const isChecked = selectAll
1687
- ? allRowsSelected
1688
- : getIsRowSelected({ row, table });
1689
- const checkboxProps = Object.assign(Object.assign({}, (selectAll
1690
- ? parseFromValuesOrFunc(muiSelectAllCheckboxProps, { table })
1691
- : parseFromValuesOrFunc(muiSelectCheckboxProps, {
1692
- row,
1693
- staticRowIndex,
1694
- table,
1695
- }))), rest);
1696
- const onSelectionChange = row
1697
- ? getMRT_RowSelectionHandler({
1561
+ var { cell, row, staticRowIndex, table } = _a, rest = __rest(_a, ["cell", "row", "staticRowIndex", "table"]);
1562
+ const { getState, options: { createDisplayMode, editDisplayMode, enableEditing, icons: { EditIcon, MoreHorizIcon }, localization, renderRowActionMenuItems, renderRowActions, }, setEditingRow, } = table;
1563
+ const { creatingRow } = getState();
1564
+ const isCreating = (creatingRow === null || creatingRow === void 0 ? void 0 : creatingRow.id) === row.id;
1565
+ const isEditing = useMRT_SliceValue(table._uiStore, (s) => { var _a; return ((_a = s.editingRow) === null || _a === void 0 ? void 0 : _a.id) === row.id; });
1566
+ const showEditActionButtons = (isCreating && createDisplayMode === 'row') ||
1567
+ (isEditing && editDisplayMode === 'row');
1568
+ const [anchorEl, setAnchorEl] = useState(null);
1569
+ const handleOpenRowActionMenu = (event) => {
1570
+ event.stopPropagation();
1571
+ event.preventDefault();
1572
+ setAnchorEl(event.currentTarget);
1573
+ };
1574
+ const handleStartEditMode = (event) => {
1575
+ event.stopPropagation();
1576
+ setEditingRow(Object.assign({}, row));
1577
+ setAnchorEl(null);
1578
+ };
1579
+ return (jsx(Fragment, { children: renderRowActions && !showEditActionButtons ? (renderRowActions({ cell, row, staticRowIndex, table })) : showEditActionButtons ? (jsx(MRT_EditActionButtons, { row: row, table: table })) : !renderRowActionMenuItems &&
1580
+ parseFromValuesOrFunc(enableEditing, row) &&
1581
+ ['modal', 'row'].includes(editDisplayMode) ? (jsx(Tooltip, { placement: "right", title: localization.edit, children: jsx(IconButton, Object.assign({ "aria-label": localization.edit, onClick: handleStartEditMode, sx: commonIconButtonStyles }, rest, { children: jsx(EditIcon, {}) })) })) : ((_b = renderRowActionMenuItems === null || renderRowActionMenuItems === void 0 ? void 0 : renderRowActionMenuItems({
1582
+ closeMenu: () => { },
1698
1583
  row,
1699
1584
  staticRowIndex,
1700
1585
  table,
1701
- })
1702
- : undefined;
1703
- const onSelectAllChange = getMRT_SelectAllHandler({ table });
1704
- const commonProps = Object.assign(Object.assign({ 'aria-label': selectAll
1705
- ? localization.toggleSelectAll
1706
- : localization.toggleSelectRow, checked: isChecked, disabled: isLoading || (row && !row.getCanSelect()) || (row === null || row === void 0 ? void 0 : row.id) === 'mrt-row-create', inputProps: {
1707
- 'aria-label': selectAll
1708
- ? localization.toggleSelectAll
1709
- : localization.toggleSelectRow,
1710
- }, onChange: (event) => {
1711
- event.stopPropagation();
1712
- selectAll ? onSelectAllChange(event) : onSelectionChange(event);
1713
- }, size: (density === 'compact' ? 'small' : 'medium') }, checkboxProps), { onClick: (e) => {
1714
- var _a;
1715
- e.stopPropagation();
1716
- (_a = checkboxProps === null || checkboxProps === void 0 ? void 0 : checkboxProps.onClick) === null || _a === void 0 ? void 0 : _a.call(checkboxProps, e);
1717
- }, sx: (theme) => (Object.assign({ height: density === 'compact' ? '1.75rem' : '2.5rem', m: density !== 'compact' ? '-0.4rem' : undefined, width: density === 'compact' ? '1.75rem' : '2.5rem', zIndex: 0 }, parseFromValuesOrFunc(checkboxProps === null || checkboxProps === void 0 ? void 0 : checkboxProps.sx, theme))), title: undefined });
1718
- return (jsx(Tooltip, Object.assign({}, getCommonTooltipProps(), { title: (_b = checkboxProps === null || checkboxProps === void 0 ? void 0 : checkboxProps.title) !== null && _b !== void 0 ? _b : (selectAll
1719
- ? localization.toggleSelectAll
1720
- : localization.toggleSelectRow), children: enableMultiRowSelection === false ? (jsx(Radio, Object.assign({}, commonProps))) : (jsx(Checkbox, Object.assign({ disableRipple: true, indeterminate: !isChecked && selectAll
1721
- ? table.getIsSomeRowsSelected()
1722
- : (row === null || row === void 0 ? void 0 : row.getIsSomeSelected()) && row.getCanSelectSubRows() }, commonProps))) })));
1586
+ })) === null || _b === void 0 ? void 0 : _b.length) ? (jsxs(Fragment, { children: [jsx(Tooltip, Object.assign({}, getCommonTooltipProps(), { title: localization.rowActions, children: jsx(IconButton, Object.assign({ "aria-label": localization.rowActions, onClick: handleOpenRowActionMenu, size: "small", sx: commonIconButtonStyles }, rest, { children: jsx(MoreHorizIcon, {}) })) })), jsx(MRT_RowActionMenu, { anchorEl: anchorEl, handleEdit: handleStartEditMode, row: row, setAnchorEl: setAnchorEl, staticRowIndex: staticRowIndex, table: table })] })) : null }));
1723
1587
  };
1724
1588
 
1725
- const getMRT_RowSelectColumnDef = (tableOptions) => {
1726
- const { enableMultiRowSelection, enableSelectAll } = tableOptions;
1727
- return Object.assign({ Cell: ({ row, staticRowIndex, table }) => (jsx(MRT_SelectCheckbox, { row: row, staticRowIndex: staticRowIndex, table: table })), Header: enableSelectAll && enableMultiRowSelection
1728
- ? ({ table }) => (jsxs(Box, { sx: { alignItems: 'center', display: 'flex' }, children: [jsx(MRT_SelectCheckbox, { table: table }), jsx(MRT_SelectAllMenu, { table: table })] }))
1729
- : undefined, grow: false }, defaultDisplayColumnProps({
1730
- header: 'select',
1731
- id: '__check__',
1732
- size: enableSelectAll ? 90 : 70, // widened from 60 to accommodate both the checkbox and the menu button
1589
+ const getMRT_RowActionsColumnDef = (tableOptions) => {
1590
+ return Object.assign({ Cell: ({ cell, row, staticRowIndex, table }) => (jsx(MRT_ToggleRowActionMenuButton, { cell: cell, row: row, staticRowIndex: staticRowIndex, table: table })) }, defaultDisplayColumnProps({
1591
+ header: 'actions',
1592
+ id: 'mrt-row-actions',
1593
+ size: 70,
1733
1594
  tableOptions,
1734
1595
  }));
1735
1596
  };
1736
1597
 
1737
- const MRT_Default_Icons = {
1738
- AddIcon,
1739
- ArrowDownwardIcon,
1740
- ArrowRightIcon,
1741
- CancelIcon,
1742
- ChevronLeftIcon,
1743
- ChevronRightIcon,
1744
- ClearAllIcon,
1745
- CloseIcon,
1746
- ContentCopy,
1747
- DensityLargeIcon,
1748
- DensityMediumIcon,
1749
- DensitySmallIcon,
1750
- DragHandleIcon,
1751
- DynamicFeedIcon,
1752
- EditIcon,
1753
- ExpandMoreIcon,
1754
- FilterAltIcon,
1755
- FilterListIcon,
1756
- FilterListOffIcon,
1757
- FirstPageIcon,
1758
- FullscreenExitIcon,
1759
- FullscreenIcon,
1760
- KeyboardDoubleArrowDownIcon,
1761
- LastPageIcon,
1762
- MoreHorizIcon,
1763
- MoreVertIcon,
1764
- PushPinIcon,
1765
- RestartAltIcon,
1766
- SaveIcon,
1767
- SearchIcon,
1768
- SearchOffIcon,
1769
- SortIcon,
1770
- SyncAltIcon,
1771
- ViewColumnIcon,
1772
- VisibilityOffIcon,
1598
+ const MRT_GrabHandleButton = (_a) => {
1599
+ var _b, _c;
1600
+ var { location, table } = _a, rest = __rest(_a, ["location", "table"]);
1601
+ const { options: { icons: { DragHandleIcon }, localization, }, } = table;
1602
+ return (jsx(Tooltip, Object.assign({}, getCommonTooltipProps('top'), { title: (_b = rest === null || rest === void 0 ? void 0 : rest.title) !== null && _b !== void 0 ? _b : localization.move, children: jsx(IconButton, Object.assign({ "aria-label": (_c = rest.title) !== null && _c !== void 0 ? _c : localization.move, disableRipple: true, draggable: "true", size: "small" }, rest, { onClick: (e) => {
1603
+ var _a;
1604
+ e.stopPropagation();
1605
+ (_a = rest === null || rest === void 0 ? void 0 : rest.onClick) === null || _a === void 0 ? void 0 : _a.call(rest, e);
1606
+ }, sx: (theme) => (Object.assign({ '&:active': {
1607
+ cursor: 'grabbing',
1608
+ }, '&:hover': {
1609
+ backgroundColor: 'transparent',
1610
+ opacity: 1,
1611
+ }, cursor: 'grab', m: '0 -0.1rem', opacity: location === 'row' ? 1 : 0.5, p: '2px', transition: 'all 150ms ease-in-out' }, parseFromValuesOrFunc(rest === null || rest === void 0 ? void 0 : rest.sx, theme))), title: undefined, children: jsx(DragHandleIcon, {}) })) })));
1773
1612
  };
1774
1613
 
1775
- const MRT_Localization_EN = {
1776
- language: 'en',
1777
- actions: 'Actions',
1778
- and: 'and',
1779
- booleanFalse: 'False',
1780
- booleanTrue: 'True',
1781
- cancel: 'Cancel',
1782
- close: 'Close',
1783
- changeFilterMode: 'Change filter mode',
1784
- changeSearchMode: 'Change search mode',
1785
- clearFilter: 'Clear filter',
1786
- clearSearch: 'Clear search',
1787
- clearSelection: 'Clear selection',
1788
- clearSort: 'Clear sort',
1789
- deselectAllOnAllPages: 'Deselect all on all pages',
1790
- deselectAllOnCurrentPage: 'Deselect all on current page',
1791
- clickToCopy: 'Click to copy',
1792
- copy: 'Copy',
1793
- collapse: 'Collapse',
1794
- collapseAll: 'Collapse all',
1795
- columnActions: 'Column Actions',
1796
- columns: 'Columns',
1797
- copiedToClipboard: 'Copied to clipboard',
1798
- dropToGroupBy: 'Drop to group by {column}',
1799
- edit: 'Edit',
1800
- expand: 'Expand',
1801
- expandAll: 'Expand all',
1802
- filterArrIncludes: 'Includes',
1803
- filterArrIncludesAll: 'Includes all',
1804
- filterArrIncludesSome: 'Includes',
1805
- filterBetween: 'Between',
1806
- filterBetweenInclusive: 'Between Inclusive',
1807
- filterByColumn: 'Filter by {column}',
1808
- filterFrom: 'From',
1809
- filterTo: 'To',
1810
- filterContains: 'Contains',
1811
- filterEmpty: 'Empty',
1812
- filterEndsWith: 'Ends With',
1813
- filterEquals: 'Equals',
1814
- filterEqualsString: 'Equals',
1815
- filterFuzzy: 'Fuzzy',
1816
- filterGreaterThan: 'Greater Than',
1817
- filterGreaterThanOrEqualTo: 'Greater Than Or Equal To',
1818
- filterInArray: 'Is any of',
1819
- filterIsAnyOf: 'Is any of',
1820
- filterInNumberRange: 'Between',
1821
- filterIncludesString: 'Contains',
1822
- filterIncludesStringSensitive: 'Contains',
1823
- filterLessThan: 'Less Than',
1824
- filterLessThanOrEqualTo: 'Less Than Or Equal To',
1825
- filterMode: 'Filter Mode: {filterType}',
1826
- filterNoOptions: 'No filter options available',
1827
- filterNotEmpty: 'Not Empty',
1828
- filterNotEquals: 'Not Equals',
1829
- filterNotContains: 'Does Not Contain',
1830
- filterLogic: 'Logic',
1831
- filterOperator: 'Operator',
1832
- filterStartsWith: 'Starts With',
1833
- filterWeakEquals: 'Equals',
1834
- filterCurrentWeek: 'Current Week',
1835
- filterCurrentMonth: 'Current Month',
1836
- filterLast7Days: 'Last 7 Days',
1837
- filterLastWeek: 'Last Week',
1838
- filterLastMonth: 'Last Month',
1839
- filterFromToday: 'From Today',
1840
- filterToToday: 'To Today',
1841
- filteringByColumn: 'Filtering by {column} - {filterType} {filterValue}',
1842
- goToFirstPage: 'Go to first page',
1843
- goToLastPage: 'Go to last page',
1844
- goToNextPage: 'Go to next page',
1845
- goToPreviousPage: 'Go to previous page',
1846
- grab: 'Grab',
1847
- groupByColumn: 'Group by {column}',
1848
- groupedBy: 'Grouped by ',
1849
- hideAll: 'Hide all',
1850
- hideColumn: 'Hide {column} column',
1851
- max: 'Max',
1852
- min: 'Min',
1853
- move: 'Move',
1854
- noRecordsToDisplay: 'No records to display',
1855
- noResultsFound: 'No results found',
1856
- moreThan: 'more than',
1857
- of: 'of',
1858
- or: 'or',
1859
- pin: 'Pin',
1860
- pinToLeft: 'Pin to left',
1861
- pinToRight: 'Pin to right',
1862
- resetColumnSize: 'Reset column size',
1863
- resetOrder: 'Reset order',
1864
- rowActions: 'Row Actions',
1865
- rowNumber: '#',
1866
- rowNumbers: 'Row Numbers',
1867
- rowsPerPage: 'Rows per page',
1868
- countRows: 'Count Rows',
1869
- countRowsTooltip: 'Count total rows for current filters',
1870
- rowCount: 'Row Count',
1871
- rowsSelected: '{count} row(s) selected',
1872
- save: 'Save',
1873
- search: 'Search',
1874
- selectedCountOfRowCountRowsSelected: '{selectedCount} of {rowCount} row(s) selected',
1875
- select: 'Select',
1876
- selectAllOnAllPages: 'Select all on all pages',
1877
- selectAllOnCurrentPage: 'Select all on current page',
1878
- showAll: 'Show all',
1879
- showAllColumns: 'Show all columns',
1880
- showHideColumns: 'Columns',
1881
- showHideFilters: 'Show/Hide filters',
1882
- showHideSearch: 'Show/Hide search',
1883
- showAdvancedFilters: 'Show advanced filters',
1884
- advancedFilters: 'Advanced Filters',
1885
- filters: 'Filters',
1886
- add: 'Add',
1887
- newEntry: 'New Entry',
1888
- clear: 'Clear',
1889
- discardChanges: 'Discard changes',
1890
- saveFilters: 'Save filters',
1891
- savedFilters: 'Saved filters',
1892
- noSavedFilters: 'No saved filters',
1893
- filterName: 'Filter name',
1894
- apply: 'Apply',
1895
- sortByColumnAsc: 'Sort by {column} ascending',
1896
- sortByColumnDesc: 'Sort by {column} descending',
1897
- sortedByColumnAsc: 'Sorted by {column} ascending',
1898
- sortedByColumnDesc: 'Sorted by {column} descending',
1899
- thenBy: ', then by ',
1900
- toggleDensity: 'Density',
1901
- densityCompact: 'Compact',
1902
- densityStandard: 'Standard',
1903
- densityComfortable: 'Comfortable',
1904
- toggleFullScreen: 'Toggle full screen',
1905
- toggleSelectAll: 'Toggle select all',
1906
- toggleSelectRow: 'Toggle select row',
1907
- toggleVisibility: 'Toggle visibility',
1908
- ungroupByColumn: 'Ungroup by {column}',
1909
- unpin: 'Unpin',
1910
- unpinAll: 'Unpin all',
1911
- dimensionRotationEnabled: 'Rotation enabled',
1912
- dimensionRotationDisabled: 'Rotation disabled',
1913
- length: 'Length',
1914
- width: 'Width',
1915
- height: 'Height',
1916
- depth: 'Depth',
1917
- tolerance: 'Tolerance',
1918
- exportButton: 'Export',
1919
- exportSelectRowsTooltip: 'Select rows to export',
1920
- exportPrintPdf: 'Print PDF',
1921
- exportDownload: 'Download',
1922
- exportGrouped: 'Group files',
1923
- exportInProgress: 'Export in progress...',
1924
- exportSuccess: 'Export completed successfully.',
1925
- exportError: 'Export failed. Please try again.',
1926
- exportNoExportsSelected: 'No export type selected. Please configure the export first.',
1927
- deleteConfirmationTitle: 'Delete Row',
1928
- deleteConfirmationMessage: 'Are you sure you want to delete the selected row(s)?',
1929
- deleteConfirmYes: 'Delete',
1930
- deleteConfirmNo: 'Cancel',
1931
- deleteConfirmDeleting: 'Deleting...',
1932
- errorTitle: 'Unexpected error',
1933
- errorMessage: 'An unexpected error occurred. Please try again.',
1934
- serverTableErrorTitle: 'Unable to load table',
1935
- serverTableErrorMessage: 'Something went wrong while loading the table configuration. Please try again.',
1936
- serverTableErrorRetry: 'Try again',
1937
- resetState: 'Reset State',
1938
- tableOptions: 'Options',
1614
+ const MRT_TableBodyRowGrabHandle = (_a) => {
1615
+ var { row, rowRef, table } = _a, rest = __rest(_a, ["row", "rowRef", "table"]);
1616
+ const { options: { muiRowDragHandleProps }, } = table;
1617
+ const iconButtonProps = Object.assign(Object.assign({}, parseFromValuesOrFunc(muiRowDragHandleProps, {
1618
+ row,
1619
+ table,
1620
+ })), rest);
1621
+ const handleDragStart = (event) => {
1622
+ var _a;
1623
+ (_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.onDragStart) === null || _a === void 0 ? void 0 : _a.call(iconButtonProps, event);
1624
+ try {
1625
+ event.dataTransfer.setDragImage(rowRef.current, 0, 0);
1626
+ }
1627
+ catch (e) {
1628
+ console.error(e);
1629
+ }
1630
+ table.setDraggingRow(row);
1631
+ };
1632
+ const handleDragEnd = (event) => {
1633
+ var _a;
1634
+ (_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.onDragEnd) === null || _a === void 0 ? void 0 : _a.call(iconButtonProps, event);
1635
+ table.setDraggingRow(null);
1636
+ table.setHoveredRow(null);
1637
+ };
1638
+ return (jsx(MRT_GrabHandleButton, Object.assign({}, iconButtonProps, { location: "row", onDragEnd: handleDragEnd, onDragStart: handleDragStart, table: table })));
1939
1639
  };
1940
1640
 
1941
- const downloadExportFiles = (files) => {
1942
- files.forEach((file) => {
1943
- const binaryString = atob(file.content);
1944
- const len = binaryString.length;
1945
- const bytes = new Uint8Array(len);
1946
- for (let i = 0; i < len; i++) {
1947
- bytes[i] = binaryString.charCodeAt(i);
1948
- }
1949
- const blob = new Blob([bytes], { type: 'application/octet-stream' });
1950
- const element = document.createElement('a');
1951
- element.href = URL.createObjectURL(blob);
1952
- element.download = file.filename;
1953
- document.body.appendChild(element);
1954
- element.click();
1955
- document.body.removeChild(element);
1956
- URL.revokeObjectURL(element.href);
1957
- });
1641
+ const getMRT_RowDragColumnDef = (tableOptions) => {
1642
+ return Object.assign({ Cell: ({ row, rowRef, table }) => (jsx(MRT_TableBodyRowGrabHandle, { row: row, rowRef: rowRef, table: table })), grow: false }, defaultDisplayColumnProps({
1643
+ header: 'move',
1644
+ id: 'mrt-row-drag',
1645
+ size: 60,
1646
+ tableOptions,
1647
+ }));
1958
1648
  };
1959
1649
 
1960
- const printExportFiles = (files) => {
1961
- files.forEach((file) => {
1962
- const binaryString = atob(file.content);
1963
- const len = binaryString.length;
1964
- const bytes = new Uint8Array(len);
1965
- for (let i = 0; i < len; i++) {
1966
- bytes[i] = binaryString.charCodeAt(i);
1967
- }
1968
- const blob = new Blob([bytes], { type: 'application/pdf' });
1969
- const url = URL.createObjectURL(blob);
1970
- printJS({
1971
- printable: url,
1972
- type: 'pdf',
1973
- onLoadingEnd: () => URL.revokeObjectURL(url),
1974
- });
1975
- });
1650
+ const MRT_ExpandAllButton = (_a) => {
1651
+ var _b, _c;
1652
+ var { table } = _a, rest = __rest(_a, ["table"]);
1653
+ const { getCanSomeRowsExpand, getIsAllRowsExpanded, getIsSomeRowsExpanded, getState, options: { icons: { KeyboardDoubleArrowDownIcon }, localization, muiExpandAllButtonProps, renderDetailPanel, }, toggleAllRowsExpanded, } = table;
1654
+ const { isLoading } = getState();
1655
+ const density = useMRT_SliceValue(table._uiStore, (s) => s.density);
1656
+ const iconButtonProps = Object.assign(Object.assign({}, parseFromValuesOrFunc(muiExpandAllButtonProps, {
1657
+ table,
1658
+ })), rest);
1659
+ const isAllRowsExpanded = getIsAllRowsExpanded();
1660
+ return (jsx(Tooltip, Object.assign({}, getCommonTooltipProps(), { title: (_b = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.title) !== null && _b !== void 0 ? _b : (isAllRowsExpanded ? localization.collapseAll : localization.expandAll), children: jsx("span", { children: jsx(IconButton, Object.assign({ "aria-label": localization.expandAll, disabled: isLoading || (!renderDetailPanel && !getCanSomeRowsExpand()), onClick: () => toggleAllRowsExpanded(!isAllRowsExpanded) }, iconButtonProps, { sx: (theme) => (Object.assign({ height: density === 'compact' ? '1.75rem' : '2.25rem', mt: density !== 'compact' ? '-0.25rem' : undefined, width: density === 'compact' ? '1.75rem' : '2.25rem' }, parseFromValuesOrFunc(iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.sx, theme))), title: undefined, children: (_c = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.children) !== null && _c !== void 0 ? _c : (jsx(KeyboardDoubleArrowDownIcon, { style: {
1661
+ transform: `rotate(${isAllRowsExpanded ? -180 : getIsSomeRowsExpanded() ? -90 : 0}deg)`,
1662
+ transition: 'transform 150ms',
1663
+ } })) })) }) })));
1976
1664
  };
1977
1665
 
1978
- const MRT_ExportsToolbar = ({ table, availableExports, exportState, onExportStateChange, loadExport, }) => {
1666
+ const MRT_ExpandButton = ({ row, staticRowIndex, table, }) => {
1667
+ var _a, _b;
1979
1668
  const theme = useTheme();
1980
- const { localization } = table.options;
1981
- const { selectedExports, selectedFormat, grouped } = exportState;
1982
- const [anchorEl, setAnchorEl] = useState(null);
1983
- const [loadingExportType, setLoadingExportType] = useState(null);
1984
- const { rowSelection } = table.getState();
1985
- const selectedRowIds = Object.keys(rowSelection).filter((id) => rowSelection[id]);
1986
- const isNoRowsSelected = selectedRowIds.length === 0;
1987
- const availableFormats = useMemo(() => {
1988
- const allFormats = Object.values(availableExports).flatMap((exp) => exp.formats);
1989
- return Array.from(new Set(allFormats));
1990
- }, [availableExports]);
1991
- const hasPdfFormat = availableFormats.includes('pdf');
1992
- const exportTypesForSelectedFormat = useMemo(() => {
1993
- if (!selectedFormat)
1994
- return [];
1995
- return Object.values(availableExports).filter((exp) => exp.formats.includes(selectedFormat));
1996
- }, [availableExports, selectedFormat]);
1997
- const isPrintDisabled = selectedFormat !== 'pdf' ||
1998
- !selectedFormat ||
1999
- selectedExports.length < 1 ||
2000
- (!grouped && selectedExports.length > 1);
2001
- const isDownloadDisabled = !selectedFormat || selectedExports.length < 1;
2002
- const handleOpenMenu = (event) => {
2003
- setAnchorEl(event.currentTarget);
2004
- };
2005
- const handleCloseMenu = () => {
2006
- setAnchorEl(null);
2007
- };
2008
- const handleSelectFormat = (format) => {
2009
- const newFormat = selectedFormat === format ? null : format;
2010
- onExportStateChange((prev) => (Object.assign(Object.assign({}, (prev !== null && prev !== void 0 ? prev : { grouped: false })), { selectedExports: [], selectedFormat: newFormat })));
2011
- };
2012
- const handleToggleExportType = (exportName) => {
2013
- const isAlreadySelected = selectedExports.includes(exportName);
2014
- const newSelectedExports = isAlreadySelected
2015
- ? selectedExports.filter((name) => name !== exportName)
2016
- : [...selectedExports, exportName];
2017
- onExportStateChange((prev) => (Object.assign(Object.assign({}, (prev !== null && prev !== void 0 ? prev : { selectedFormat: null, grouped: false })), { selectedExports: newSelectedExports })));
2018
- };
2019
- const handleToggleGrouped = () => {
2020
- onExportStateChange((prev) => (Object.assign(Object.assign({}, (prev !== null && prev !== void 0 ? prev : { selectedFormat: null, selectedExports: [] })), { grouped: !grouped })));
2021
- };
2022
- const handleExportAction = (type) => __awaiter(void 0, void 0, void 0, function* () {
2023
- setLoadingExportType(type);
2024
- try {
2025
- const response = yield loadExport({
2026
- format: selectedFormat,
2027
- exports: selectedExports,
2028
- separated_files: !grouped,
2029
- download: false,
2030
- ids: JSON.stringify(selectedRowIds),
2031
- type,
2032
- });
2033
- handleCloseMenu();
2034
- if (type === 'download') {
2035
- downloadExportFiles(response);
2036
- }
2037
- else {
2038
- printExportFiles(response);
2039
- }
2040
- }
2041
- finally {
2042
- setLoadingExportType(null);
2043
- }
1669
+ const { options: { icons: { ExpandMoreIcon }, localization, maxDepth, muiExpandButtonProps, positionExpandColumn, renderDetailPanel, }, } = table;
1670
+ const density = useMRT_SliceValue(table._uiStore, (s) => s.density);
1671
+ const iconButtonProps = parseFromValuesOrFunc(muiExpandButtonProps, {
1672
+ row,
1673
+ staticRowIndex,
1674
+ table,
2044
1675
  });
2045
- const renderFormatSelector = () => (jsx(Stack, { justifyContent: "flex-start", minWidth: "200px", sx: {
2046
- borderRight: selectedFormat
2047
- ? `1px dashed ${theme.palette.divider}`
2048
- : 'none',
2049
- }, children: jsx(FormControl, { children: jsx(RadioGroup, { value: selectedFormat !== null && selectedFormat !== void 0 ? selectedFormat : '', children: availableFormats.map((format) => (jsx(FormControlLabel, { sx: { m: 0 }, value: format, control: jsx(Radio, { size: "small", onClick: () => handleSelectFormat(format) }), label: jsx(Typography, { variant: "subtitle2", sx: { fontWeight: 800 }, children: format }) }, format))) }) }) }));
2050
- const renderExportTypeSelector = () => {
2051
- if (!selectedFormat || exportTypesForSelectedFormat.length === 0)
2052
- return null;
2053
- return (jsx(Stack, { minWidth: "250px", maxHeight: "500px", sx: { overflowY: 'auto' }, children: exportTypesForSelectedFormat.map((exportType) => (jsxs(MenuItem, { onClick: () => handleToggleExportType(exportType.name), value: exportType.name, children: [jsx(Checkbox, { checked: selectedExports.includes(exportType.name), size: "small" }), jsx(Typography, { variant: "body2", children: exportType.label })] }, exportType.name))) }));
2054
- };
2055
- const renderActionButtons = () => {
2056
- const isAnyLoading = loadingExportType !== null;
2057
- return (jsxs(Stack, { direction: "row", gap: 0.5, mt: 1, mr: 2, children: [hasPdfFormat && (jsx(Button, { sx: { display: 'flex', gap: 0.5 }, disabled: isPrintDisabled || isAnyLoading, onClick: () => handleExportAction('print'), startIcon: loadingExportType === 'print' ? (jsx(CircularProgress, { size: 16, color: "inherit" })) : (jsx(PrintIcon, { fontSize: "small" })), children: localization.exportPrintPdf })), jsx(Button, { sx: { display: 'flex', gap: 0.5 }, disabled: isDownloadDisabled || isAnyLoading, onClick: () => handleExportAction('download'), startIcon: loadingExportType === 'download' ? (jsx(CircularProgress, { size: 16, color: "inherit" })) : (jsx(FileDownloadIcon, { fontSize: "small" })), children: localization.exportDownload })] }));
1676
+ const canExpand = row.getCanExpand() && (maxDepth === undefined || row.depth < maxDepth - 1);
1677
+ const isExpanded = row.getIsExpanded();
1678
+ const handleToggleExpand = (event) => {
1679
+ var _a;
1680
+ event.stopPropagation();
1681
+ row.toggleExpanded();
1682
+ (_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.onClick) === null || _a === void 0 ? void 0 : _a.call(iconButtonProps, event);
2058
1683
  };
2059
- const renderGroupedCheckbox = () => (jsx(Stack, { mt: "auto", children: jsx(FormControlLabel, { onChange: handleToggleGrouped, sx: { m: 0 }, control: jsx(Checkbox, { checked: grouped, size: "small" }), label: jsx(Typography, { variant: "body2", children: localization.exportGrouped }) }) }));
2060
- return (jsxs(Stack, { direction: "row", gap: 0.5, alignItems: "center", children: [jsx(Tooltip, { title: isNoRowsSelected
2061
- ? localization.exportSelectRowsTooltip
2062
- : localization.exportButton, children: jsx("span", { children: jsx(Button, { "aria-label": localization.exportButton, disabled: isNoRowsSelected, onClick: handleOpenMenu, size: "small", startIcon: jsx(FileDownloadIcon, { fontSize: "small" }), variant: "text", children: localization.exportButton }) }) }), jsxs(Menu, { anchorEl: anchorEl, open: Boolean(anchorEl), onClose: handleCloseMenu, anchorOrigin: { vertical: 'bottom', horizontal: 'left' }, transformOrigin: { vertical: 'top', horizontal: 'left' }, children: [jsxs(Stack, { direction: "row", sx: { px: 1, pt: 1, maxHeight: '320px', overflow: 'auto' }, children: [renderFormatSelector(), selectedFormat &&
2063
- exportTypesForSelectedFormat.length > 0 &&
2064
- renderExportTypeSelector()] }), jsx(Divider, { sx: { mt: 1 } }), jsxs(Stack, { direction: "row", alignItems: "center", sx: { px: 1, pb: 1 }, children: [renderActionButtons(), renderGroupedCheckbox()] })] })] }));
1684
+ const detailPanel = !!(renderDetailPanel === null || renderDetailPanel === void 0 ? void 0 : renderDetailPanel({ row, table }));
1685
+ return (jsx(Tooltip, Object.assign({ disableHoverListener: !canExpand && !detailPanel }, getCommonTooltipProps(), { title: (_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.title) !== null && _a !== void 0 ? _a : (isExpanded ? localization.collapse : localization.expand), children: jsx("span", { children: jsx(IconButton, Object.assign({ "aria-label": localization.expand, disabled: !canExpand && !detailPanel }, iconButtonProps, { onClick: handleToggleExpand, sx: (theme) => (Object.assign({ opacity: !canExpand && !detailPanel ? 0.3 : 1, [theme.direction === 'rtl' || positionExpandColumn === 'last'
1686
+ ? 'mr'
1687
+ : 'ml']: `${row.depth * 16}px`, width: density === 'compact' ? '1.75rem' : '2.25rem' }, parseFromValuesOrFunc(iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.sx, theme))), size: "small", title: undefined, children: (_b = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.children) !== null && _b !== void 0 ? _b : (jsx(ExpandMoreIcon, { style: {
1688
+ transform: `rotate(${!canExpand && !renderDetailPanel
1689
+ ? positionExpandColumn === 'last' ||
1690
+ theme.direction === 'rtl'
1691
+ ? 90
1692
+ : -90
1693
+ : isExpanded
1694
+ ? -180
1695
+ : 0}deg)`,
1696
+ transition: 'transform 150ms',
1697
+ } })) })) }) })));
2065
1698
  };
2066
1699
 
2067
- const MRT_ExportRowButton = ({ onClick }) => {
2068
- return (jsx(IconButton, { sx: { p: 0 }, disableRipple: true, onClick: onClick, children: jsx(FileDownloadIcon, { fontSize: "small" }) }));
1700
+ const INSERT_HERE_TOOLTIP = 'Insert here';
1701
+ const ACTION_ICON_SIZE$1 = 'small';
1702
+ const MRT_InsertHereAction = ({ onClick, }) => {
1703
+ return (jsx(Tooltip, { title: INSERT_HERE_TOOLTIP, disableInteractive: true, children: jsx(IconButton, { onClick: onClick, size: ACTION_ICON_SIZE$1, children: jsx(SubdirectoryArrowLeftIcon, { color: "warning" }) }) }));
2069
1704
  };
2070
1705
 
2071
- const MRT_PrintRowButton = ({ onClick }) => {
2072
- return (jsx(IconButton, { sx: { p: 0 }, disableRipple: true, onClick: onClick, children: jsx(PrintIcon, { fontSize: "small" }) }));
1706
+ const MOVE_TO_TOP_TOOLTIP = 'Move to top level';
1707
+ const ACTION_ICON_SIZE = 'small';
1708
+ const ACTION_BUTTON_HEIGHT = '1.75rem';
1709
+ const MRT_MoveToTopAction = ({ onClick }) => {
1710
+ return (jsx(Tooltip, { title: MOVE_TO_TOP_TOOLTIP, disableInteractive: true, children: jsx(IconButton, { onClick: onClick, size: ACTION_ICON_SIZE, sx: { height: ACTION_BUTTON_HEIGHT }, children: jsx(VerticalAlignTopIcon, { fontSize: "small" }) }) }));
2073
1711
  };
2074
1712
 
2075
- const ExportRowAction = ({ onExport, onPrint }) => {
2076
- return (jsxs(Fragment, { children: [jsx(MRT_ExportRowButton, { onClick: onExport }), onPrint && jsx(MRT_PrintRowButton, { onClick: onPrint })] }));
1713
+ const MRT_ReorderRowCheckbox = ({ onChange, isSelected, }) => {
1714
+ return (jsx(Checkbox, { checked: isSelected, color: "warning", disableRipple: true, onChange: onChange, sx: {
1715
+ color: (theme) => theme.palette.warning.main,
1716
+ '&.Mui-checked': {
1717
+ color: (theme) => theme.palette.warning.main,
1718
+ },
1719
+ } }));
2077
1720
  };
2078
1721
 
2079
- const hasActiveExports = (table) => {
2080
- const { activeExports } = table.getState();
2081
- return !!((activeExports === null || activeExports === void 0 ? void 0 : activeExports.selectedFormat) && activeExports.selectedExports.length > 0);
2082
- };
2083
- // Same conditions as MRT_ExportsToolbar: pdf format selected, at least one export type,
2084
- // and either grouped or exactly one export type selected.
2085
- const isPrintAvailable = (table) => {
1722
+ /**
1723
+ * Finds the maximum depth in the hierarchy of a given row (recursively searches all descendants).
1724
+ * Used to determine the "size" of the tree being moved.
1725
+ * Example: Row at depth 1 with a child at depth 3 → returns 3
1726
+ */
1727
+ const getDeepestSubRowDepth = (row) => {
2086
1728
  var _a;
2087
- const allFormats = Object.values((_a = table.options.availableExports) !== null && _a !== void 0 ? _a : {}).flatMap((e) => e.formats);
2088
- if (!allFormats.includes('pdf'))
2089
- return false;
2090
- const { activeExports } = table.getState();
2091
- if (!activeExports)
1729
+ if (!((_a = row.subRows) === null || _a === void 0 ? void 0 : _a.length)) {
1730
+ return row.depth;
1731
+ }
1732
+ return row.subRows.reduce((maxDepth, subRow) => Math.max(maxDepth, getDeepestSubRowDepth(subRow)), row.depth);
1733
+ };
1734
+ /**
1735
+ * Extracts an array of IDs of only the selected rows from the selection object.
1736
+ * Filters the record where the value is true and maps only the keys (IDs).
1737
+ * Example: { row1: true, row2: false, row3: true } → ['row1', 'row3']
1738
+ */
1739
+ const getSelectedReorderRowIds = (rowReorderingSelection) => {
1740
+ return Object.entries(rowReorderingSelection !== null && rowReorderingSelection !== void 0 ? rowReorderingSelection : {})
1741
+ .filter(([, isSelected]) => isSelected)
1742
+ .map(([rowId]) => rowId);
1743
+ };
1744
+ /**
1745
+ * Checks WHETHER we can move selected rows as children of target row
1746
+ * without exceeding the maximum allowed depth.
1747
+ * Directly calculates the final maximum depth after the move.
1748
+ * Example: selectedRows at depth 1-2 with descendants to depth 4, target depth 1, maxDepth 5
1749
+ * → new max depth = 1 + 1 + (4 - 1) = 5, which equals maxDepth, so returns false
1750
+ */
1751
+ const canInsertSelectedRowsWithoutExceedingMaxDepth = ({ maxDepth, selectedRows, targetRowDepth, }) => {
1752
+ // Cannot insert if there are no selected rows to move
1753
+ if (selectedRows.length === 0) {
2092
1754
  return false;
2093
- const { selectedFormat, selectedExports, grouped } = activeExports;
2094
- return (selectedFormat === 'pdf' &&
2095
- selectedExports.length >= 1 &&
2096
- (grouped || selectedExports.length === 1));
1755
+ }
1756
+ // No depth restriction - can insert anywhere
1757
+ if (maxDepth === undefined) {
1758
+ return true;
1759
+ }
1760
+ // Find the deepest descendant among all selected rows
1761
+ const maxDeepestDescendantDepth = selectedRows.reduce((max, row) => {
1762
+ return Math.max(max, getDeepestSubRowDepth(row));
1763
+ }, 0);
1764
+ // Find the minimum depth of selected rows (to calculate relative depth)
1765
+ const minSelectedRowDepth = Math.min(...selectedRows.map((r) => r.depth));
1766
+ // Calculate the maximum depth after moving rows as children of target
1767
+ // newMaxDepth = target.depth + 1 (as children) + relative depth of selected rows
1768
+ const newMaxDepth = targetRowDepth + 1 + (maxDeepestDescendantDepth - minSelectedRowDepth);
1769
+ return newMaxDepth < maxDepth;
2097
1770
  };
2098
- const createExportAction = (_a = {}) => {
2099
- var { onExport, renderRow: customRenderRow, renderToolbar: customRenderToolbar } = _a, rest = __rest(_a, ["onExport", "renderRow", "renderToolbar"]);
2100
- // Pure download logic — no notifications. Throws on failure so callers can handle it.
2101
- const defaultOnExport = (_a) => __awaiter(void 0, [_a], void 0, function* ({ rowsToExport, table, }) {
2102
- if (!rowsToExport.length)
2103
- return;
2104
- const { loadExport } = table.options;
2105
- const { activeExports } = table.getState();
2106
- if (!loadExport || !activeExports)
2107
- return;
2108
- const response = yield loadExport({
2109
- format: activeExports.selectedFormat,
2110
- exports: activeExports.selectedExports,
2111
- separated_files: !activeExports.grouped,
2112
- download: false,
2113
- ids: JSON.stringify(rowsToExport.map((r) => r.id)),
2114
- type: 'download',
2115
- });
2116
- downloadExportFiles(response);
1771
+ /**
1772
+ * Finds the depth of the FIRST selected row in the selection object.
1773
+ * Used to enforce constraint: can only select rows at the SAME depth.
1774
+ * Example: If I select a row at depth 2, I cannot select a row at depth 3
1775
+ */
1776
+ const getFirstSelectedReorderRowDepth = ({ rowReorderingSelection, table, }) => {
1777
+ var _a, _b;
1778
+ const firstSelectedRowId = (_a = Object.entries(rowReorderingSelection !== null && rowReorderingSelection !== void 0 ? rowReorderingSelection : {}).find(([, isSelected]) => isSelected)) === null || _a === void 0 ? void 0 : _a[0];
1779
+ if (!firstSelectedRowId) {
1780
+ return undefined;
1781
+ }
1782
+ return (_b = table.getRow(firstSelectedRowId, true)) === null || _b === void 0 ? void 0 : _b.depth;
1783
+ };
1784
+ /**
1785
+ * Checks WHETHER we can select a specific row.
1786
+ * Rule: If a selection already exists, new row MUST be at the SAME depth as the first selected.
1787
+ * Without this, you could move rows from different levels which would break the hierarchy.
1788
+ */
1789
+ const canSelectRowForReorder = ({ rowId, rowDepth, rowReorderingSelection, firstSelectedReorderRowDepth, }) => {
1790
+ const isCurrentRowSelected = !!(rowReorderingSelection === null || rowReorderingSelection === void 0 ? void 0 : rowReorderingSelection[rowId]);
1791
+ if (isCurrentRowSelected) {
1792
+ return true;
1793
+ }
1794
+ const hasAnySelection = Object.values(rowReorderingSelection !== null && rowReorderingSelection !== void 0 ? rowReorderingSelection : {}).some(Boolean);
1795
+ if (!hasAnySelection) {
1796
+ return true;
1797
+ }
1798
+ return rowDepth === firstSelectedReorderRowDepth;
1799
+ };
1800
+ /**
1801
+ * Creates an array of MRT_Row objects from an array of IDs.
1802
+ * Finds each row from the table and collects it in the result.
1803
+ * Used to prepare data for the onTreeRowReorder callback.
1804
+ */
1805
+ const buildSelectedRowsArray = (selectedRowIds, table) => {
1806
+ return selectedRowIds.reduce((selectedRows, selectedRowId) => {
1807
+ const selectedRow = table.getRow(selectedRowId, true);
1808
+ if (selectedRow) {
1809
+ selectedRows.push(selectedRow);
1810
+ }
1811
+ return selectedRows;
1812
+ }, []);
1813
+ };
1814
+ /**
1815
+ * Helper function to check if a row is a descendant of another row.
1816
+ * Recursively searches through all subRows to find if targetRowId exists.
1817
+ * Used to prevent circular references (parent cannot become child of its own child).
1818
+ */
1819
+ const isRowInSubtreeOf = (targetRowId, parentRow) => {
1820
+ var _a;
1821
+ if (!((_a = parentRow.subRows) === null || _a === void 0 ? void 0 : _a.length)) {
1822
+ return false;
1823
+ }
1824
+ for (const subRow of parentRow.subRows) {
1825
+ if (subRow.id === targetRowId) {
1826
+ return true;
1827
+ }
1828
+ if (isRowInSubtreeOf(targetRowId, subRow)) {
1829
+ return true;
1830
+ }
1831
+ }
1832
+ return false;
1833
+ };
1834
+ /**
1835
+ * Checks if a row can be used as a valid insert target for selected rows.
1836
+ * Rules: Target row must NOT be already selected AND must NOT be a descendant of any selected row.
1837
+ * This prevents circular references where a parent becomes a child of its own descendants.
1838
+ * Example: If you select "Department", you cannot insert it under "Project" (which is its descendant)
1839
+ */
1840
+ const isValidInsertTarget = ({ targetRowId, selectedRowIds, table, }) => {
1841
+ // Rule 1: Target row cannot be already selected
1842
+ if (selectedRowIds.includes(targetRowId) || selectedRowIds.length === 0) {
1843
+ return false;
1844
+ }
1845
+ // Rule 2: Target row cannot be a descendant of any selected row
1846
+ // (prevents parent from becoming child of its own descendants)
1847
+ for (const selectedRowId of selectedRowIds) {
1848
+ const selectedRow = table.getRow(selectedRowId, true);
1849
+ if (selectedRow &&
1850
+ isRowInSubtreeOf(targetRowId, selectedRow)) {
1851
+ return false;
1852
+ }
1853
+ }
1854
+ return true;
1855
+ };
1856
+
1857
+ const useTreeRowReorderingCell = ({ row, table, rowReorderingSelection, maxDepth, onTreeRowReorder, }) => {
1858
+ const [isRowHovered, setIsRowHovered] = useState(false);
1859
+ const firstSelectedReorderRowDepth = getFirstSelectedReorderRowDepth({
1860
+ rowReorderingSelection,
1861
+ table,
2117
1862
  });
2118
- // Pure print logic — no notifications. Throws on failure so callers can handle it.
2119
- const defaultOnPrint = (_a) => __awaiter(void 0, [_a], void 0, function* ({ rowsToExport, table, }) {
2120
- if (!rowsToExport.length)
2121
- return;
2122
- const { loadExport } = table.options;
2123
- const { activeExports } = table.getState();
2124
- if (!loadExport || !activeExports)
2125
- return;
2126
- const response = yield loadExport({
2127
- format: activeExports.selectedFormat,
2128
- exports: activeExports.selectedExports,
2129
- separated_files: !activeExports.grouped,
2130
- download: false,
2131
- ids: JSON.stringify(rowsToExport.map((r) => r.id)),
2132
- type: 'print',
2133
- });
2134
- printExportFiles(response);
1863
+ const canSelectForReorder = canSelectRowForReorder({
1864
+ rowId: row.id,
1865
+ rowDepth: row.depth,
1866
+ rowReorderingSelection,
1867
+ firstSelectedReorderRowDepth,
2135
1868
  });
2136
- // Single execution pipeline for every export flow (row or toolbar).
2137
- // If a custom handler exists, it receives defaultOnExport and decides when to call it.
2138
- const executeExport = (context) => {
2139
- const executeDefaultExport = () => defaultOnExport(context);
2140
- if (onExport) {
2141
- return onExport(Object.assign(Object.assign({}, context), { defaultOnExport: executeDefaultExport }));
2142
- }
2143
- return executeDefaultExport();
2144
- };
2145
- // Row download: checks for active exports, then wraps with loading/success/error notifications.
2146
- const handleSingleRowExport = (_a) => __awaiter(void 0, [_a], void 0, function* ({ table, row, }) {
2147
- const { localization } = table.options;
2148
- if (!hasActiveExports(table)) {
2149
- enqueueSnackbar(localization.exportNoExportsSelected, {
2150
- variant: 'warning',
2151
- });
1869
+ const hasAnyReorderSelection = Object.values(rowReorderingSelection !== null && rowReorderingSelection !== void 0 ? rowReorderingSelection : {}).some(Boolean);
1870
+ const selectedReorderRowIds = getSelectedReorderRowIds(rowReorderingSelection);
1871
+ const selectedRowsForReorder = buildSelectedRowsArray(selectedReorderRowIds, table);
1872
+ const shouldShowReorderCheckbox = canSelectForReorder && (isRowHovered || hasAnyReorderSelection);
1873
+ const shouldShowInsertHereAction = selectedReorderRowIds.length > 0 &&
1874
+ isValidInsertTarget({
1875
+ targetRowId: row.id,
1876
+ selectedRowIds: selectedReorderRowIds,
1877
+ table,
1878
+ }) &&
1879
+ canInsertSelectedRowsWithoutExceedingMaxDepth({
1880
+ maxDepth,
1881
+ selectedRows: selectedRowsForReorder,
1882
+ targetRowDepth: row.depth,
1883
+ });
1884
+ const handleReorderCheckboxChange = useCallback((event) => {
1885
+ const checked = event.target.checked;
1886
+ table.setRowReorderingSelection((prev) => (Object.assign(Object.assign({}, prev), { [row.id]: checked })));
1887
+ }, [row.id, table]);
1888
+ const handleInsertHereActionClick = useCallback(() => {
1889
+ if (!onTreeRowReorder) {
1890
+ console.warn('[MRT] onTreeRowReorder callback is not defined');
2152
1891
  return;
2153
1892
  }
2154
- const loadingKey = enqueueSnackbar(localization.exportInProgress, {
2155
- variant: 'info',
2156
- persist: true,
2157
- });
2158
1893
  try {
2159
- yield executeExport({ table, rowsToExport: [row] });
2160
- closeSnackbar(loadingKey);
2161
- enqueueSnackbar(localization.exportSuccess, { variant: 'success' });
1894
+ const treeRowReorderEvent = {
1895
+ selectedRowIds: selectedReorderRowIds,
1896
+ selectedRows: selectedRowsForReorder,
1897
+ table,
1898
+ targetRow: row,
1899
+ };
1900
+ onTreeRowReorder(treeRowReorderEvent);
2162
1901
  }
2163
- catch (_b) {
2164
- closeSnackbar(loadingKey);
2165
- enqueueSnackbar(localization.exportError, { variant: 'error' });
1902
+ catch (error) {
1903
+ console.error('[MRT] Error during tree row reorder:', error);
2166
1904
  }
2167
- });
2168
- // Row print: same guard + notification pattern as download, but calls defaultOnPrint.
2169
- const handleSingleRowPrint = (_a) => __awaiter(void 0, [_a], void 0, function* ({ table, row, }) {
2170
- const { localization } = table.options;
2171
- if (!hasActiveExports(table)) {
2172
- enqueueSnackbar(localization.exportNoExportsSelected, {
2173
- variant: 'warning',
2174
- });
1905
+ }, [
1906
+ onTreeRowReorder,
1907
+ selectedReorderRowIds,
1908
+ selectedRowsForReorder,
1909
+ table,
1910
+ row,
1911
+ ]);
1912
+ return {
1913
+ isRowHovered,
1914
+ shouldShowReorderCheckbox,
1915
+ shouldShowInsertHereAction,
1916
+ handleRowHoverEnter: () => setIsRowHovered(true),
1917
+ handleRowHoverLeave: () => setIsRowHovered(false),
1918
+ handleReorderCheckboxChange,
1919
+ handleInsertHereActionClick,
1920
+ isReorderCheckboxSelected: !!(rowReorderingSelection === null || rowReorderingSelection === void 0 ? void 0 : rowReorderingSelection[row.id]),
1921
+ };
1922
+ };
1923
+
1924
+ const useTreeRowReorderingHeader = ({ table, enableRowReordering, onTreeRowReorder, }) => {
1925
+ const rowReorderingSelection = useMRT_SliceValue(table._uiStore, (s) => s.rowReorderingSelection);
1926
+ const selectedReorderRowIds = getSelectedReorderRowIds(rowReorderingSelection);
1927
+ const selectedRowsForReorder = buildSelectedRowsArray(selectedReorderRowIds, table);
1928
+ const shouldShowMoveToTopLevelAction = !!enableRowReordering &&
1929
+ selectedRowsForReorder.length > 0 &&
1930
+ selectedRowsForReorder.some((selectedRow) => selectedRow.depth > 0);
1931
+ const handleMoveToTopLevelActionClick = useCallback(() => {
1932
+ if (!onTreeRowReorder) {
1933
+ console.warn('[MRT] onTreeRowReorder callback is not defined');
2175
1934
  return;
2176
1935
  }
2177
- const loadingKey = enqueueSnackbar(localization.exportInProgress, {
2178
- variant: 'info',
2179
- persist: true,
2180
- });
2181
1936
  try {
2182
- yield defaultOnPrint({ table, rowsToExport: [row] });
2183
- closeSnackbar(loadingKey);
2184
- enqueueSnackbar(localization.exportSuccess, { variant: 'success' });
1937
+ const treeRowReorderEvent = {
1938
+ selectedRowIds: selectedReorderRowIds,
1939
+ selectedRows: selectedRowsForReorder,
1940
+ table,
1941
+ targetRow: null,
1942
+ };
1943
+ onTreeRowReorder(treeRowReorderEvent);
2185
1944
  }
2186
- catch (_b) {
2187
- closeSnackbar(loadingKey);
2188
- enqueueSnackbar(localization.exportError, { variant: 'error' });
1945
+ catch (error) {
1946
+ console.error('[MRT] Error during tree row reorder to top level:', error);
2189
1947
  }
2190
- });
2191
- // Resolves selected rows from table state for toolbar-triggered export (custom renderToolbar only).
2192
- const handleMultipleRowExport = ({ table, }) => {
2193
- const rowsToExport = table.getSelectedRowModel().rows;
2194
- return executeExport({ table, rowsToExport });
2195
- };
2196
- const createRowExportExecutor = (context) => () => {
2197
- void handleSingleRowExport(context);
2198
- };
2199
- const createRowPrintExecutor = (context) => () => {
2200
- void handleSingleRowPrint(context);
2201
- };
2202
- const createToolbarExportExecutor = (context) => () => {
2203
- void handleMultipleRowExport(context);
1948
+ }, [onTreeRowReorder, selectedReorderRowIds, selectedRowsForReorder, table]);
1949
+ return {
1950
+ shouldShowMoveToTopLevelAction,
1951
+ handleMoveToTopLevelActionClick,
2204
1952
  };
2205
- // Renders download + optional print button. Print is shown under the same conditions
2206
- // as in MRT_ExportsToolbar: pdf format selected, active exports, grouped or single type.
2207
- const renderRowAction = (context) => {
2208
- const onRowExport = createRowExportExecutor(context);
2209
- const onRowPrint = isPrintAvailable(context.table)
2210
- ? createRowPrintExecutor(context)
2211
- : undefined;
2212
- if (customRenderRow) {
2213
- return customRenderRow(Object.assign(Object.assign({}, context), { onExport: onRowExport }));
1953
+ };
1954
+
1955
+ const TREE_REORDER_ICON_SPACING = '0.25rem';
1956
+ const getMRT_RowExpandColumnDef = (tableOptions) => {
1957
+ var _a;
1958
+ const { defaultColumn, enableRowReordering, enableExpandAll, groupedColumnMode, maxDepth, onTreeRowReorder, positionExpandColumn, renderDetailPanel, state: { grouping }, } = tableOptions;
1959
+ const alignProps = positionExpandColumn === 'last'
1960
+ ? {
1961
+ align: 'right',
2214
1962
  }
2215
- return jsx(ExportRowAction, { onExport: onRowExport, onPrint: onRowPrint });
1963
+ : undefined;
1964
+ return Object.assign(Object.assign({ Cell: ({ cell, column, row, staticRowIndex, table }) => {
1965
+ var _a, _b, _c;
1966
+ const rowReorderingSelection = useMRT_SliceValue(table._uiStore, (s) => s.rowReorderingSelection);
1967
+ const cellLogic = useTreeRowReorderingCell({
1968
+ row,
1969
+ table,
1970
+ rowReorderingSelection,
1971
+ maxDepth,
1972
+ onTreeRowReorder,
1973
+ });
1974
+ const expandButtonProps = { row, staticRowIndex, table };
1975
+ const subRowsLength = (_a = row.subRows) === null || _a === void 0 ? void 0 : _a.length;
1976
+ const customGroupedCell = (_c = (_b = column.columnDef).GroupedCell) === null || _c === void 0 ? void 0 : _c.call(_b, {
1977
+ cell,
1978
+ column,
1979
+ row,
1980
+ table,
1981
+ staticRowIndex,
1982
+ });
1983
+ if (groupedColumnMode === 'remove' && row.groupingColumnId) {
1984
+ const defaultGroupedCell = (jsx(Tooltip, Object.assign({}, getCommonTooltipProps('right'), { title: table.getColumn(row.groupingColumnId).columnDef.header, children: jsx("span", { children: row.groupingValue }) })));
1985
+ return (jsxs(Stack, { alignItems: "center", flexDirection: "row", gap: TREE_REORDER_ICON_SPACING, onMouseEnter: cellLogic.handleRowHoverEnter, onMouseLeave: cellLogic.handleRowHoverLeave, width: "100%", children: [jsx(MRT_ExpandButton, Object.assign({}, expandButtonProps)), column.columnDef.GroupedCell
1986
+ ? customGroupedCell
1987
+ : defaultGroupedCell, cellLogic.shouldShowReorderCheckbox && (jsx(MRT_ReorderRowCheckbox, { isSelected: cellLogic.isReorderCheckboxSelected, onChange: cellLogic.handleReorderCheckboxChange })), cellLogic.shouldShowInsertHereAction && (jsx(MRT_InsertHereAction, { onClick: cellLogic.handleInsertHereActionClick })), !!subRowsLength && jsxs("span", { children: ["(", subRowsLength, ")"] })] }));
1988
+ }
1989
+ return (jsxs(Stack, { alignItems: "center", flexDirection: "row", gap: TREE_REORDER_ICON_SPACING, onMouseEnter: cellLogic.handleRowHoverEnter, onMouseLeave: cellLogic.handleRowHoverLeave, width: "100%", children: [jsx(MRT_ExpandButton, Object.assign({}, expandButtonProps)), customGroupedCell, cellLogic.shouldShowReorderCheckbox && (jsx(MRT_ReorderRowCheckbox, { isSelected: cellLogic.isReorderCheckboxSelected, onChange: cellLogic.handleReorderCheckboxChange })), cellLogic.shouldShowInsertHereAction && (jsx(MRT_InsertHereAction, { onClick: cellLogic.handleInsertHereActionClick }))] }));
1990
+ }, Header: enableExpandAll
1991
+ ? ({ table }) => {
1992
+ var _a;
1993
+ const headerLogic = useTreeRowReorderingHeader({
1994
+ table,
1995
+ enableRowReordering,
1996
+ onTreeRowReorder,
1997
+ });
1998
+ return (jsxs(Stack, { alignItems: "center", flexDirection: "row", gap: TREE_REORDER_ICON_SPACING, children: [jsx(MRT_ExpandAllButton, { table: table }), headerLogic.shouldShowMoveToTopLevelAction && (jsx(MRT_MoveToTopAction, { onClick: headerLogic.handleMoveToTopLevelActionClick })), groupedColumnMode === 'remove' &&
1999
+ ((_a = grouping === null || grouping === void 0 ? void 0 : grouping.map((groupedColumnId) => table.getColumn(groupedColumnId).columnDef.header)) === null || _a === void 0 ? void 0 : _a.join(', '))] }));
2000
+ }
2001
+ : undefined, muiTableBodyCellProps: alignProps, muiTableHeadCellProps: alignProps }, defaultDisplayColumnProps({
2002
+ header: 'expand',
2003
+ id: 'mrt-row-expand',
2004
+ size: groupedColumnMode === 'remove'
2005
+ ? ((_a = defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.size) !== null && _a !== void 0 ? _a : 180)
2006
+ : renderDetailPanel
2007
+ ? enableExpandAll
2008
+ ? 60
2009
+ : 70
2010
+ : 100,
2011
+ tableOptions,
2012
+ })), { enableResizing: true });
2013
+ };
2014
+
2015
+ const getMRT_RowNumbersColumnDef = (tableOptions) => {
2016
+ const { localization, rowNumberDisplayMode } = tableOptions;
2017
+ const { pagination: { pageIndex, pageSize }, } = tableOptions.state;
2018
+ return Object.assign({ Cell: ({ row, staticRowIndex }) => {
2019
+ var _a;
2020
+ return ((_a = (rowNumberDisplayMode === 'static'
2021
+ ? (staticRowIndex || 0) + (pageSize || 0) * (pageIndex || 0)
2022
+ : row.index)) !== null && _a !== void 0 ? _a : 0) + 1;
2023
+ }, Header: () => localization.rowNumber, grow: false }, defaultDisplayColumnProps({
2024
+ header: 'rowNumbers',
2025
+ id: 'mrt-row-numbers',
2026
+ size: 50,
2027
+ tableOptions,
2028
+ }));
2029
+ };
2030
+
2031
+ const MRT_RowPinButton = (_a) => {
2032
+ var { pinningPosition, row, table } = _a, rest = __rest(_a, ["pinningPosition", "row", "table"]);
2033
+ const { options: { icons: { CloseIcon, PushPinIcon }, localization, rowPinningDisplayMode, }, } = table;
2034
+ const isPinned = row.getIsPinned();
2035
+ const [tooltipOpened, setTooltipOpened] = useState(false);
2036
+ const handleTogglePin = (event) => {
2037
+ setTooltipOpened(false);
2038
+ event.stopPropagation();
2039
+ row.pin(isPinned ? false : pinningPosition);
2216
2040
  };
2217
- // Uses custom toolbar renderer when provided; otherwise renders MRT_ExportsToolbar.
2218
- // loadExport is always wrapped with notifications so that loading/success/error are shown
2219
- // regardless of whether a custom onExport handler was provided.
2220
- // When onExport is provided, it intercepts the call and returns [] so MRT_ExportsToolbar
2221
- // does not attempt a second download from an empty response.
2222
- const renderToolbarAction = (context) => {
2223
- const { table } = context;
2224
- const { availableExports, loadExport, onActiveExportsChange, localization, } = table.options;
2225
- const { activeExports } = table.getState();
2226
- if (customRenderToolbar) {
2227
- return customRenderToolbar(Object.assign(Object.assign({}, context), { onExport: createToolbarExportExecutor(context) }));
2041
+ return (jsx(Tooltip, Object.assign({}, getCommonTooltipProps(), { open: tooltipOpened, title: isPinned ? localization.unpin : localization.pin, children: jsx(IconButton, Object.assign({ "aria-label": localization.pin, onBlur: () => setTooltipOpened(false), onClick: handleTogglePin, onFocus: () => setTooltipOpened(true), onMouseEnter: () => setTooltipOpened(true), onMouseLeave: () => setTooltipOpened(false), size: "small" }, rest, { sx: (theme) => (Object.assign({ height: '24px', width: '24px' }, parseFromValuesOrFunc(rest === null || rest === void 0 ? void 0 : rest.sx, theme))), children: isPinned ? (jsx(CloseIcon, {})) : (jsx(PushPinIcon, { fontSize: "small", style: {
2042
+ transform: `rotate(${rowPinningDisplayMode === 'sticky'
2043
+ ? 135
2044
+ : pinningPosition === 'top'
2045
+ ? 180
2046
+ : 0}deg)`,
2047
+ } })) })) })));
2048
+ };
2049
+
2050
+ const MRT_TableBodyRowPinButton = (_a) => {
2051
+ var { row, table } = _a, rest = __rest(_a, ["row", "table"]);
2052
+ const { options: { enableRowPinning, rowPinningDisplayMode }, } = table;
2053
+ const density = useMRT_SliceValue(table._uiStore, (s) => s.density);
2054
+ const canPin = parseFromValuesOrFunc(enableRowPinning, row);
2055
+ if (!canPin)
2056
+ return null;
2057
+ const rowPinButtonProps = Object.assign({ row,
2058
+ table }, rest);
2059
+ if (rowPinningDisplayMode === 'top-and-bottom' && !row.getIsPinned()) {
2060
+ return (jsxs(Box, { sx: {
2061
+ display: 'flex',
2062
+ flexDirection: density === 'compact' ? 'row' : 'column',
2063
+ }, children: [jsx(MRT_RowPinButton, Object.assign({ pinningPosition: "top" }, rowPinButtonProps)), jsx(MRT_RowPinButton, Object.assign({ pinningPosition: "bottom" }, rowPinButtonProps))] }));
2064
+ }
2065
+ return (jsx(MRT_RowPinButton, Object.assign({ pinningPosition: rowPinningDisplayMode === 'bottom' ? 'bottom' : 'top' }, rowPinButtonProps)));
2066
+ };
2067
+
2068
+ const getMRT_RowPinningColumnDef = (tableOptions) => {
2069
+ return Object.assign({ Cell: ({ row, table }) => (jsx(MRT_TableBodyRowPinButton, { row: row, table: table })), grow: false }, defaultDisplayColumnProps({
2070
+ header: 'pin',
2071
+ id: 'mrt-row-pin',
2072
+ size: 60,
2073
+ tableOptions,
2074
+ }));
2075
+ };
2076
+
2077
+ const MRT_SelectAllMenu = ({ table, }) => {
2078
+ const [anchorEl, setAnchorEl] = useState(null);
2079
+ const [isSelectingAllPages, setIsSelectingAllPages] = useState(false);
2080
+ const { getState, options: { enableRowPinning, getAllSelectableRowIds, localization, rowPinningDisplayMode, }, refs: { allSelectableRowIdsRef }, } = table;
2081
+ // rowSelection is read here so that any change to selection will trigger a re-render and update the menu options accordingly
2082
+ const { isLoading, rowSelection } = getState();
2083
+ const isAllCurrentPageSelected = table.getIsAllPageRowsSelected();
2084
+ const isAllPagesActive = getIsAllPagesSelectionActive(table, rowSelection);
2085
+ const handleOpen = (event) => {
2086
+ setAnchorEl(event.currentTarget);
2087
+ };
2088
+ const handleClose = () => {
2089
+ setAnchorEl(null);
2090
+ };
2091
+ // Clears row pinning on every bulk selection/deselection
2092
+ const clearPinning = () => {
2093
+ if (enableRowPinning && (rowPinningDisplayMode === null || rowPinningDisplayMode === void 0 ? void 0 : rowPinningDisplayMode.includes('select'))) {
2094
+ table.setRowPinning({ bottom: [], top: [] });
2228
2095
  }
2229
- if (!availableExports ||
2230
- !loadExport ||
2231
- !onActiveExportsChange ||
2232
- !activeExports) {
2233
- return null;
2096
+ };
2097
+ // ── Current-page actions ────────────────────────────────────────────────────
2098
+ const handleSelectCurrentPage = () => {
2099
+ table.toggleAllPageRowsSelected(true);
2100
+ clearPinning();
2101
+ handleClose();
2102
+ };
2103
+ const handleDeselectCurrentPage = () => {
2104
+ if (allSelectableRowIdsRef.current.length > 0) {
2105
+ // When all pages are selected, deselecting the current page must clear the entire selection — otherwise rows on other pages remain "ghost-selected" but the user can't see them.
2106
+ table.setRowSelection({});
2107
+ allSelectableRowIdsRef.current = [];
2234
2108
  }
2235
- const notifiedLoadExport = (params) => __awaiter(void 0, void 0, void 0, function* () {
2236
- const loadingKey = enqueueSnackbar(localization.exportInProgress, {
2237
- variant: 'info',
2238
- persist: true,
2239
- });
2109
+ else {
2110
+ table.toggleAllPageRowsSelected(false);
2111
+ }
2112
+ clearPinning();
2113
+ handleClose();
2114
+ };
2115
+ // ── All-pages actions ───────────────────────────────────────────────────────
2116
+ const handleSelectAllPages = () => __awaiter(void 0, void 0, void 0, function* () {
2117
+ handleClose();
2118
+ if (getAllSelectableRowIds) {
2119
+ // Server-side: IDs are not available locally, fetch them from the API
2120
+ setIsSelectingAllPages(true);
2121
+ table.setShowProgressBars(true);
2240
2122
  try {
2241
- let response;
2242
- if (onExport) {
2243
- const rowsToExport = table.getSelectedRowModel().rows;
2244
- yield executeExport({ table, rowsToExport });
2245
- response = [];
2246
- }
2247
- else {
2248
- response = yield loadExport(params);
2249
- }
2250
- closeSnackbar(loadingKey);
2251
- enqueueSnackbar(localization.exportSuccess, { variant: 'success' });
2252
- return response;
2123
+ const ids = yield getAllSelectableRowIds({ table });
2124
+ allSelectableRowIdsRef.current = ids;
2125
+ const newSelection = {};
2126
+ ids.forEach((id) => {
2127
+ newSelection[id] = true;
2128
+ });
2129
+ table.setRowSelection(newSelection);
2130
+ clearPinning();
2253
2131
  }
2254
- catch (_a) {
2255
- closeSnackbar(loadingKey);
2256
- enqueueSnackbar(localization.exportError, { variant: 'error' });
2257
- return [];
2132
+ finally {
2133
+ setIsSelectingAllPages(false);
2134
+ table.setShowProgressBars(false);
2258
2135
  }
2259
- });
2260
- return (jsx(MRT_ExportsToolbar, { table: table, availableExports: availableExports, exportState: activeExports, onExportStateChange: onActiveExportsChange, loadExport: notifiedLoadExport }));
2136
+ }
2137
+ else {
2138
+ // Client-side: all data is available locally
2139
+ table.toggleAllRowsSelected(true);
2140
+ clearPinning();
2141
+ }
2142
+ });
2143
+ const handleDeselectAllPages = () => {
2144
+ if (getAllSelectableRowIds) {
2145
+ table.setRowSelection({});
2146
+ }
2147
+ else {
2148
+ table.toggleAllRowsSelected(false);
2149
+ }
2150
+ allSelectableRowIdsRef.current = [];
2151
+ clearPinning();
2152
+ handleClose();
2261
2153
  };
2262
- return Object.assign({ name: 'export', renderRow: renderRowAction, renderToolbar: renderToolbarAction }, rest);
2154
+ const isDisabled = isLoading || isSelectingAllPages;
2155
+ return (jsxs(Fragment, { children: [jsx(Tooltip, Object.assign({}, getCommonTooltipProps(), { title: localization.toggleSelectAll, children: jsx("span", { children: jsx(IconButton, { "aria-label": localization.toggleSelectAll, disabled: isDisabled, onClick: handleOpen, size: "small", sx: { height: '1.5rem', width: '1.5rem' }, children: jsx(table.options.icons.MoreVertIcon, { style: { transform: 'scale(0.85)' } }) }) }) })), jsxs(Menu, { anchorEl: anchorEl, onClose: handleClose, open: Boolean(anchorEl), children: [isAllCurrentPageSelected ? (jsx(MenuItem, { onClick: handleDeselectCurrentPage, children: localization.deselectAllOnCurrentPage })) : (jsx(MenuItem, { onClick: handleSelectCurrentPage, children: localization.selectAllOnCurrentPage })), isAllPagesActive ? (jsx(MenuItem, { onClick: handleDeselectAllPages, children: localization.deselectAllOnAllPages })) : (jsxs(MenuItem, { disabled: isSelectingAllPages, onClick: handleSelectAllPages, children: [isSelectingAllPages && (jsx(CircularProgress, { "aria-label": "Loading", size: 14, sx: { mr: 1 } })), localization.selectAllOnAllPages] }))] })] }));
2156
+ };
2157
+
2158
+ const MRT_SelectCheckbox = (_a) => {
2159
+ var _b;
2160
+ var { row, staticRowIndex, table } = _a, rest = __rest(_a, ["row", "staticRowIndex", "table"]);
2161
+ const { getState, options: { enableMultiRowSelection, localization, muiSelectAllCheckboxProps, muiSelectCheckboxProps, selectAllMode, }, } = table;
2162
+ const { isLoading } = getState();
2163
+ const density = useMRT_SliceValue(table._uiStore, (s) => s.density);
2164
+ const selectAll = !row;
2165
+ const allRowsSelected = selectAll
2166
+ ? selectAllMode === 'page'
2167
+ ? table.getIsAllPageRowsSelected()
2168
+ : table.getIsAllRowsSelected()
2169
+ : undefined;
2170
+ const isChecked = selectAll
2171
+ ? allRowsSelected
2172
+ : getIsRowSelected({ row, table });
2173
+ const checkboxProps = Object.assign(Object.assign({}, (selectAll
2174
+ ? parseFromValuesOrFunc(muiSelectAllCheckboxProps, { table })
2175
+ : parseFromValuesOrFunc(muiSelectCheckboxProps, {
2176
+ row,
2177
+ staticRowIndex,
2178
+ table,
2179
+ }))), rest);
2180
+ const onSelectionChange = row
2181
+ ? getMRT_RowSelectionHandler({
2182
+ row,
2183
+ staticRowIndex,
2184
+ table,
2185
+ })
2186
+ : undefined;
2187
+ const onSelectAllChange = getMRT_SelectAllHandler({ table });
2188
+ const commonProps = Object.assign(Object.assign({ 'aria-label': selectAll
2189
+ ? localization.toggleSelectAll
2190
+ : localization.toggleSelectRow, checked: isChecked, disabled: isLoading || (row && !row.getCanSelect()) || (row === null || row === void 0 ? void 0 : row.id) === 'mrt-row-create', inputProps: {
2191
+ 'aria-label': selectAll
2192
+ ? localization.toggleSelectAll
2193
+ : localization.toggleSelectRow,
2194
+ }, onChange: (event) => {
2195
+ event.stopPropagation();
2196
+ selectAll ? onSelectAllChange(event) : onSelectionChange(event);
2197
+ }, size: (density === 'compact' ? 'small' : 'medium') }, checkboxProps), { onClick: (e) => {
2198
+ var _a;
2199
+ e.stopPropagation();
2200
+ (_a = checkboxProps === null || checkboxProps === void 0 ? void 0 : checkboxProps.onClick) === null || _a === void 0 ? void 0 : _a.call(checkboxProps, e);
2201
+ }, sx: (theme) => (Object.assign({ height: density === 'compact' ? '1.75rem' : '2.5rem', m: density !== 'compact' ? '-0.4rem' : undefined, width: density === 'compact' ? '1.75rem' : '2.5rem', zIndex: 0 }, parseFromValuesOrFunc(checkboxProps === null || checkboxProps === void 0 ? void 0 : checkboxProps.sx, theme))), title: undefined });
2202
+ return (jsx(Tooltip, Object.assign({}, getCommonTooltipProps(), { title: (_b = checkboxProps === null || checkboxProps === void 0 ? void 0 : checkboxProps.title) !== null && _b !== void 0 ? _b : (selectAll
2203
+ ? localization.toggleSelectAll
2204
+ : localization.toggleSelectRow), children: enableMultiRowSelection === false ? (jsx(Radio, Object.assign({}, commonProps))) : (jsx(Checkbox, Object.assign({ disableRipple: true, indeterminate: !isChecked && selectAll
2205
+ ? table.getIsSomeRowsSelected()
2206
+ : (row === null || row === void 0 ? void 0 : row.getIsSomeSelected()) && row.getCanSelectSubRows() }, commonProps))) })));
2207
+ };
2208
+
2209
+ const getMRT_RowSelectColumnDef = (tableOptions) => {
2210
+ const { enableMultiRowSelection, enableSelectAll } = tableOptions;
2211
+ return Object.assign({ Cell: ({ row, staticRowIndex, table }) => (jsx(MRT_SelectCheckbox, { row: row, staticRowIndex: staticRowIndex, table: table })), Header: enableSelectAll && enableMultiRowSelection
2212
+ ? ({ table }) => (jsxs(Box, { sx: { alignItems: 'center', display: 'flex' }, children: [jsx(MRT_SelectCheckbox, { table: table }), jsx(MRT_SelectAllMenu, { table: table })] }))
2213
+ : undefined, grow: false }, defaultDisplayColumnProps({
2214
+ header: 'select',
2215
+ id: '__check__',
2216
+ size: enableSelectAll ? 90 : 70, // widened from 60 to accommodate both the checkbox and the menu button
2217
+ tableOptions,
2218
+ }));
2219
+ };
2220
+
2221
+ const MRT_Default_Icons = {
2222
+ AddIcon,
2223
+ ArrowDownwardIcon,
2224
+ ArrowRightIcon,
2225
+ CancelIcon,
2226
+ ChevronLeftIcon,
2227
+ ChevronRightIcon,
2228
+ ClearAllIcon,
2229
+ CloseIcon,
2230
+ ContentCopy,
2231
+ DensityLargeIcon,
2232
+ DensityMediumIcon,
2233
+ DensitySmallIcon,
2234
+ DragHandleIcon,
2235
+ DynamicFeedIcon,
2236
+ EditIcon,
2237
+ ExpandMoreIcon,
2238
+ FilterAltIcon,
2239
+ FilterListIcon,
2240
+ FilterListOffIcon,
2241
+ FirstPageIcon,
2242
+ FullscreenExitIcon,
2243
+ FullscreenIcon,
2244
+ KeyboardDoubleArrowDownIcon,
2245
+ LastPageIcon,
2246
+ MoreHorizIcon,
2247
+ MoreVertIcon,
2248
+ PushPinIcon,
2249
+ RestartAltIcon,
2250
+ SaveIcon,
2251
+ SearchIcon,
2252
+ SearchOffIcon,
2253
+ SortIcon,
2254
+ SyncAltIcon,
2255
+ ViewColumnIcon,
2256
+ VisibilityOffIcon,
2257
+ };
2258
+
2259
+ const MRT_Localization_EN = {
2260
+ language: 'en',
2261
+ actions: 'Actions',
2262
+ and: 'and',
2263
+ booleanFalse: 'False',
2264
+ booleanTrue: 'True',
2265
+ cancel: 'Cancel',
2266
+ close: 'Close',
2267
+ changeFilterMode: 'Change filter mode',
2268
+ changeSearchMode: 'Change search mode',
2269
+ clearFilter: 'Clear filter',
2270
+ clearSearch: 'Clear search',
2271
+ clearSelection: 'Clear selection',
2272
+ clearSort: 'Clear sort',
2273
+ deselectAllOnAllPages: 'Deselect all on all pages',
2274
+ deselectAllOnCurrentPage: 'Deselect all on current page',
2275
+ clickToCopy: 'Click to copy',
2276
+ copy: 'Copy',
2277
+ collapse: 'Collapse',
2278
+ collapseAll: 'Collapse all',
2279
+ columnActions: 'Column Actions',
2280
+ columns: 'Columns',
2281
+ copiedToClipboard: 'Copied to clipboard',
2282
+ dropToGroupBy: 'Drop to group by {column}',
2283
+ edit: 'Edit',
2284
+ expand: 'Expand',
2285
+ expandAll: 'Expand all',
2286
+ filterArrIncludes: 'Includes',
2287
+ filterArrIncludesAll: 'Includes all',
2288
+ filterArrIncludesSome: 'Includes',
2289
+ filterBetween: 'Between',
2290
+ filterBetweenInclusive: 'Between Inclusive',
2291
+ filterByColumn: 'Filter by {column}',
2292
+ filterFrom: 'From',
2293
+ filterTo: 'To',
2294
+ filterContains: 'Contains',
2295
+ filterEmpty: 'Empty',
2296
+ filterEndsWith: 'Ends With',
2297
+ filterEquals: 'Equals',
2298
+ filterEqualsString: 'Equals',
2299
+ filterFuzzy: 'Fuzzy',
2300
+ filterGreaterThan: 'Greater Than',
2301
+ filterGreaterThanOrEqualTo: 'Greater Than Or Equal To',
2302
+ filterInArray: 'Is any of',
2303
+ filterIsAnyOf: 'Is any of',
2304
+ filterInNumberRange: 'Between',
2305
+ filterIncludesString: 'Contains',
2306
+ filterIncludesStringSensitive: 'Contains',
2307
+ filterLessThan: 'Less Than',
2308
+ filterLessThanOrEqualTo: 'Less Than Or Equal To',
2309
+ filterMode: 'Filter Mode: {filterType}',
2310
+ filterNoOptions: 'No filter options available',
2311
+ filterNotEmpty: 'Not Empty',
2312
+ filterNotEquals: 'Not Equals',
2313
+ filterNotContains: 'Does Not Contain',
2314
+ filterLogic: 'Logic',
2315
+ filterOperator: 'Operator',
2316
+ filterStartsWith: 'Starts With',
2317
+ filterWeakEquals: 'Equals',
2318
+ filterCurrentWeek: 'Current Week',
2319
+ filterCurrentMonth: 'Current Month',
2320
+ filterLast7Days: 'Last 7 Days',
2321
+ filterLastWeek: 'Last Week',
2322
+ filterLastMonth: 'Last Month',
2323
+ filterFromToday: 'From Today',
2324
+ filterToToday: 'To Today',
2325
+ filteringByColumn: 'Filtering by {column} - {filterType} {filterValue}',
2326
+ goToFirstPage: 'Go to first page',
2327
+ goToLastPage: 'Go to last page',
2328
+ goToNextPage: 'Go to next page',
2329
+ goToPreviousPage: 'Go to previous page',
2330
+ grab: 'Grab',
2331
+ groupByColumn: 'Group by {column}',
2332
+ groupedBy: 'Grouped by ',
2333
+ hideAll: 'Hide all',
2334
+ hideColumn: 'Hide {column} column',
2335
+ max: 'Max',
2336
+ min: 'Min',
2337
+ move: 'Move',
2338
+ noRecordsToDisplay: 'No records to display',
2339
+ noResultsFound: 'No results found',
2340
+ moreThan: 'more than',
2341
+ of: 'of',
2342
+ or: 'or',
2343
+ pin: 'Pin',
2344
+ pinToLeft: 'Pin to left',
2345
+ pinToRight: 'Pin to right',
2346
+ resetColumnSize: 'Reset column size',
2347
+ resetOrder: 'Reset order',
2348
+ rowActions: 'Row Actions',
2349
+ rowNumber: '#',
2350
+ rowNumbers: 'Row Numbers',
2351
+ rowsPerPage: 'Rows per page',
2352
+ countRows: 'Count Rows',
2353
+ countRowsTooltip: 'Count total rows for current filters',
2354
+ rowCount: 'Row Count',
2355
+ rowsSelected: '{count} row(s) selected',
2356
+ save: 'Save',
2357
+ search: 'Search',
2358
+ selectedCountOfRowCountRowsSelected: '{selectedCount} of {rowCount} row(s) selected',
2359
+ select: 'Select',
2360
+ selectAllOnAllPages: 'Select all on all pages',
2361
+ selectAllOnCurrentPage: 'Select all on current page',
2362
+ showAll: 'Show all',
2363
+ showAllColumns: 'Show all columns',
2364
+ showHideColumns: 'Columns',
2365
+ showHideFilters: 'Show/Hide filters',
2366
+ showHideSearch: 'Show/Hide search',
2367
+ showAdvancedFilters: 'Show advanced filters',
2368
+ advancedFilters: 'Advanced Filters',
2369
+ filters: 'Filters',
2370
+ add: 'Add',
2371
+ newEntry: 'New Entry',
2372
+ clear: 'Clear',
2373
+ discardChanges: 'Discard changes',
2374
+ saveFilters: 'Save filters',
2375
+ savedFilters: 'Saved filters',
2376
+ noSavedFilters: 'No saved filters',
2377
+ filterName: 'Filter name',
2378
+ apply: 'Apply',
2379
+ sortByColumnAsc: 'Sort by {column} ascending',
2380
+ sortByColumnDesc: 'Sort by {column} descending',
2381
+ sortedByColumnAsc: 'Sorted by {column} ascending',
2382
+ sortedByColumnDesc: 'Sorted by {column} descending',
2383
+ thenBy: ', then by ',
2384
+ toggleDensity: 'Density',
2385
+ densityCompact: 'Compact',
2386
+ densityStandard: 'Standard',
2387
+ densityComfortable: 'Comfortable',
2388
+ toggleFullScreen: 'Toggle full screen',
2389
+ toggleSelectAll: 'Toggle select all',
2390
+ toggleSelectRow: 'Toggle select row',
2391
+ toggleVisibility: 'Toggle visibility',
2392
+ ungroupByColumn: 'Ungroup by {column}',
2393
+ unpin: 'Unpin',
2394
+ unpinAll: 'Unpin all',
2395
+ dimensionRotationEnabled: 'Rotation enabled',
2396
+ dimensionRotationDisabled: 'Rotation disabled',
2397
+ length: 'Length',
2398
+ width: 'Width',
2399
+ height: 'Height',
2400
+ depth: 'Depth',
2401
+ tolerance: 'Tolerance',
2402
+ exportButton: 'Export',
2403
+ exportSelectRowsTooltip: 'Select rows to export',
2404
+ exportPrintPdf: 'Print PDF',
2405
+ exportDownload: 'Download',
2406
+ exportGrouped: 'Group files',
2407
+ exportInProgress: 'Export in progress...',
2408
+ exportSuccess: 'Export completed successfully.',
2409
+ exportError: 'Export failed. Please try again.',
2410
+ exportNoExportsSelected: 'No export type selected. Please configure the export first.',
2411
+ deleteConfirmationTitle: 'Delete Row',
2412
+ deleteConfirmationMessage: 'Are you sure you want to delete the selected row(s)?',
2413
+ deleteConfirmYes: 'Delete',
2414
+ deleteConfirmNo: 'Cancel',
2415
+ deleteConfirmDeleting: 'Deleting...',
2416
+ errorTitle: 'Unexpected error',
2417
+ errorMessage: 'An unexpected error occurred. Please try again.',
2418
+ serverTableErrorTitle: 'Unable to load table',
2419
+ serverTableErrorMessage: 'Something went wrong while loading the table configuration. Please try again.',
2420
+ serverTableErrorRetry: 'Try again',
2421
+ resetState: 'Reset State',
2422
+ tableOptions: 'Options',
2263
2423
  };
2264
2424
 
2265
2425
  const MRT_DefaultColumn = {
@@ -2420,7 +2580,8 @@ const getMRT_RowSpacerColumnDef = (tableOptions) => {
2420
2580
 
2421
2581
  const useMRT_Effects = (table) => {
2422
2582
  const { getIsSomeRowsPinned, getPrePaginationRowModel, getState, options: { enablePagination, enableRowPinning, rowCount }, } = table;
2423
- const { density, globalFilter, isLoading, pagination, showSkeletons, sorting, } = getState();
2583
+ const { globalFilter, isLoading, pagination, showSkeletons, sorting } = getState();
2584
+ const density = useMRT_SliceValue(table._uiStore, (s) => s.density);
2424
2585
  const totalRowCount = rowCount !== null && rowCount !== void 0 ? rowCount : getPrePaginationRowModel().rows.length;
2425
2586
  const rerender = useReducer(() => ({}), {})[1];
2426
2587
  const initialBodyHeight = useRef(null);
@@ -2567,13 +2728,29 @@ const handleRemoveRow = ({ getRowId, setRowsState, }) => {
2567
2728
  };
2568
2729
  };
2569
2730
 
2731
+ const createSliceStore = (initial) => {
2732
+ let value = initial;
2733
+ const listeners = new Set();
2734
+ return {
2735
+ get: () => value,
2736
+ set: (next) => {
2737
+ value = next instanceof Function ? next(value) : next;
2738
+ listeners.forEach((listener) => listener());
2739
+ },
2740
+ subscribe: (listener) => {
2741
+ listeners.add(listener);
2742
+ return () => listeners.delete(listener);
2743
+ },
2744
+ };
2745
+ };
2746
+
2570
2747
  /**
2571
2748
  * The MRT hook that wraps the TanStack useReactTable hook and adds additional functionality
2572
2749
  * @param definedTableOptions - table options with proper defaults set
2573
2750
  * @returns the MRT table instance
2574
2751
  */
2575
2752
  const useMRT_TableInstance = (definedTableOptions) => {
2576
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18;
2753
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17;
2577
2754
  const lastSelectedRowId = useRef(null);
2578
2755
  const allSelectableRowIdsRef = useRef([]);
2579
2756
  const actionCellRef = useRef(null);
@@ -2587,6 +2764,9 @@ const useMRT_TableInstance = (definedTableOptions) => {
2587
2764
  const topToolbarRef = useRef(null);
2588
2765
  const tableHeadRef = useRef(null);
2589
2766
  const tableFooterRef = useRef(null);
2767
+ const tableRef = useRef(null);
2768
+ const isResizingRef = useRef(false);
2769
+ const resizeIndicatorRef = useRef(null);
2590
2770
  //transform initial state with proper column order
2591
2771
  const initialState = useMemo(() => {
2592
2772
  var _a, _b, _c, _d, _e;
@@ -2605,8 +2785,7 @@ const useMRT_TableInstance = (definedTableOptions) => {
2605
2785
  return initState;
2606
2786
  }, []);
2607
2787
  definedTableOptions.initialState = initialState;
2608
- const [actionCell, setActionCell] = useState((_a = initialState.actionCell) !== null && _a !== void 0 ? _a : null);
2609
- const [creatingRow, _setCreatingRow] = useState((_b = initialState.creatingRow) !== null && _b !== void 0 ? _b : null);
2788
+ const [creatingRow, _setCreatingRow] = useState((_a = initialState.creatingRow) !== null && _a !== void 0 ? _a : null);
2610
2789
  const [columnFilterFns, setColumnFilterFns] = useState(() => Object.assign({}, ...getAllLeafColumnDefs(definedTableOptions.columns).map((col) => {
2611
2790
  var _a, _b, _c, _d;
2612
2791
  return ({
@@ -2615,60 +2794,176 @@ const useMRT_TableInstance = (definedTableOptions) => {
2615
2794
  : ((_d = (_b = col.filterFn) !== null && _b !== void 0 ? _b : (_c = initialState === null || initialState === void 0 ? void 0 : initialState.columnFilterFns) === null || _c === void 0 ? void 0 : _c[getColumnId(col)]) !== null && _d !== void 0 ? _d : getDefaultColumnFilterFn(col)),
2616
2795
  });
2617
2796
  })));
2618
- const [columnOrder, onColumnOrderChange] = useState((_c = initialState.columnOrder) !== null && _c !== void 0 ? _c : []);
2619
- const [columnSizingInfo, onColumnSizingInfoChange] = useState((_d = initialState.columnSizingInfo) !== null && _d !== void 0 ? _d : {});
2620
- const [density, setDensity] = useState((_e = initialState === null || initialState === void 0 ? void 0 : initialState.density) !== null && _e !== void 0 ? _e : 'compact');
2621
- const [draggingColumn, setDraggingColumn] = useState((_f = initialState.draggingColumn) !== null && _f !== void 0 ? _f : null);
2622
- const [draggingRow, setDraggingRow] = useState((_g = initialState.draggingRow) !== null && _g !== void 0 ? _g : null);
2623
- const [editingCell, setEditingCell] = useState((_h = initialState.editingCell) !== null && _h !== void 0 ? _h : null);
2624
- const [editingRow, setEditingRow] = useState((_j = initialState.editingRow) !== null && _j !== void 0 ? _j : null);
2625
- const [filters, setFilters] = useState((_k = initialState.filters) !== null && _k !== void 0 ? _k : {
2797
+ const [columnOrder, onColumnOrderChange] = useState((_b = initialState.columnOrder) !== null && _b !== void 0 ? _b : []);
2798
+ // Hover/drag are UI-feedback-only and change at very high frequency during a drag
2799
+ // gesture (every cell crossed) — kept in slice stores instead of useState so
2800
+ // subscribers can select just the boolean they need instead of re-rendering the tree.
2801
+ const [dragStore] = useState(() => {
2802
+ var _a, _b;
2803
+ return createSliceStore({
2804
+ draggingColumn: ((_a = initialState.draggingColumn) !== null && _a !== void 0 ? _a : null),
2805
+ draggingRow: ((_b = initialState.draggingRow) !== null && _b !== void 0 ? _b : null),
2806
+ });
2807
+ });
2808
+ const [filters, setFilters] = useState((_c = initialState.filters) !== null && _c !== void 0 ? _c : {
2626
2809
  logicOperator: 'and',
2627
2810
  rules: [],
2628
2811
  pinnedFilters: [],
2629
2812
  });
2630
- const [globalFilterFn, setGlobalFilterFn] = useState((_l = initialState.globalFilterFn) !== null && _l !== void 0 ? _l : 'fuzzy');
2631
- const [grouping, onGroupingChange] = useState((_m = initialState.grouping) !== null && _m !== void 0 ? _m : []);
2632
- const [hoveredColumn, setHoveredColumn] = useState((_o = initialState.hoveredColumn) !== null && _o !== void 0 ? _o : null);
2633
- const [hoveredRow, setHoveredRow] = useState((_p = initialState.hoveredRow) !== null && _p !== void 0 ? _p : null);
2634
- const [pagination, onPaginationChange] = useState((_q = initialState === null || initialState === void 0 ? void 0 : initialState.pagination) !== null && _q !== void 0 ? _q : { pageIndex: 0, pageSize: 10 });
2635
- const [showAlertBanner, setShowAlertBanner] = useState((_r = initialState === null || initialState === void 0 ? void 0 : initialState.showAlertBanner) !== null && _r !== void 0 ? _r : false);
2636
- const [showColumnFilters, setShowColumnFilters] = useState((_s = initialState === null || initialState === void 0 ? void 0 : initialState.showColumnFilters) !== null && _s !== void 0 ? _s : false);
2637
- const [showGlobalFilter, setShowGlobalFilter] = useState((_t = initialState === null || initialState === void 0 ? void 0 : initialState.showGlobalFilter) !== null && _t !== void 0 ? _t : false);
2813
+ const [globalFilterFn, setGlobalFilterFn] = useState((_d = initialState.globalFilterFn) !== null && _d !== void 0 ? _d : 'fuzzy');
2814
+ const [grouping, onGroupingChange] = useState((_e = initialState.grouping) !== null && _e !== void 0 ? _e : []);
2815
+ const [hoverStore] = useState(() => {
2816
+ var _a, _b;
2817
+ return createSliceStore({
2818
+ hoveredColumn: ((_a = initialState.hoveredColumn) !== null && _a !== void 0 ? _a : null),
2819
+ hoveredRow: ((_b = initialState.hoveredRow) !== null && _b !== void 0 ? _b : null),
2820
+ });
2821
+ });
2822
+ // Everything below is UI-only feedback state that never influences the TanStack row/
2823
+ // column model (unlike filters/pagination/grouping/columnOrder/creatingRow/rows) —
2824
+ // kept in one combined store instead of 13 separate useState hooks so none of it
2825
+ // triggers a root re-render; consumers select just the field(s) they need via
2826
+ // useMRT_SliceValue.
2827
+ const [uiStore] = useState(() => {
2828
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
2829
+ return createSliceStore({
2830
+ actionCell: ((_a = initialState.actionCell) !== null && _a !== void 0 ? _a : null),
2831
+ columnSizingInfo: ((_b = initialState.columnSizingInfo) !== null && _b !== void 0 ? _b : {}),
2832
+ density: ((_c = initialState === null || initialState === void 0 ? void 0 : initialState.density) !== null && _c !== void 0 ? _c : 'compact'),
2833
+ editingCell: ((_d = initialState.editingCell) !== null && _d !== void 0 ? _d : null),
2834
+ editingRow: ((_e = initialState.editingRow) !== null && _e !== void 0 ? _e : null),
2835
+ newEntryModal: ((_f = initialState === null || initialState === void 0 ? void 0 : initialState.newEntryModal) !== null && _f !== void 0 ? _f : {
2836
+ open: false,
2837
+ }),
2838
+ rowReorderingSelection: ((_g = initialState === null || initialState === void 0 ? void 0 : initialState.rowReorderingSelection) !== null && _g !== void 0 ? _g : {}),
2839
+ // Saved filter presets — initialised from the dedicated option so the consumer
2840
+ // can hydrate them from the server response before rendering.
2841
+ savedFilters: ((_h = definedTableOptions.initialSavedFilters) !== null && _h !== void 0 ? _h : {}),
2842
+ showAlertBanner: ((_j = initialState === null || initialState === void 0 ? void 0 : initialState.showAlertBanner) !== null && _j !== void 0 ? _j : false),
2843
+ showColumnFilters: ((_k = initialState === null || initialState === void 0 ? void 0 : initialState.showColumnFilters) !== null && _k !== void 0 ? _k : false),
2844
+ showGlobalFilter: ((_l = initialState === null || initialState === void 0 ? void 0 : initialState.showGlobalFilter) !== null && _l !== void 0 ? _l : false),
2845
+ showProgressBars: ((_m = initialState === null || initialState === void 0 ? void 0 : initialState.showProgressBars) !== null && _m !== void 0 ? _m : false),
2846
+ showToolbarDropZone: ((_o = initialState === null || initialState === void 0 ? void 0 : initialState.showToolbarDropZone) !== null && _o !== void 0 ? _o : false),
2847
+ });
2848
+ });
2849
+ // columnSizingInfo isn't an MRT-level `table.setX` wrapper — TanStack auto-generates
2850
+ // `table.setColumnSizingInfo` bound to whatever `onColumnSizingInfoChange` we pass into
2851
+ // useReactTable below, so redirecting it here is enough for every internal call
2852
+ // (column.resetSize(), the resize-handle double-click reset, etc.) to land in the store.
2853
+ const onColumnSizingInfoChange = (updater) => uiStore.set((prev) => (Object.assign(Object.assign({}, prev), { columnSizingInfo: updater instanceof Function ? updater(prev.columnSizingInfo) : updater })));
2854
+ const [pagination, onPaginationChange] = useState((_f = initialState === null || initialState === void 0 ? void 0 : initialState.pagination) !== null && _f !== void 0 ? _f : { pageIndex: 0, pageSize: 10 });
2638
2855
  const showAdvancedFiltersSetterRef = useRef(null);
2639
- const [showToolbarDropZone, setShowToolbarDropZone] = useState((_u = initialState === null || initialState === void 0 ? void 0 : initialState.showToolbarDropZone) !== null && _u !== void 0 ? _u : false);
2640
- const [newEntryModal, setNewEntryModal] = useState((_v = initialState === null || initialState === void 0 ? void 0 : initialState.newEntryModal) !== null && _v !== void 0 ? _v : { open: false });
2641
- const [showProgressBars, setShowProgressBars] = useState((_w = initialState === null || initialState === void 0 ? void 0 : initialState.showProgressBars) !== null && _w !== void 0 ? _w : false);
2642
- // Saved filter presets — initialised from the dedicated option so the consumer
2643
- // can hydrate them from the server response before rendering.
2644
- const [savedFilters, setSavedFilters] = useState((_x = definedTableOptions.initialSavedFilters) !== null && _x !== void 0 ? _x : {});
2645
- // Row reordering selection state
2646
- const [rowReorderingSelection, setRowReorderingSelection] = useState((_y = initialState === null || initialState === void 0 ? void 0 : initialState.rowReorderingSelection) !== null && _y !== void 0 ? _y : {});
2647
- const [rows, setRowsState] = useState((_z = definedTableOptions.data) !== null && _z !== void 0 ? _z : []);
2648
- definedTableOptions.state = Object.assign({ actionCell,
2649
- columnFilterFns,
2856
+ const [rows, setRowsState] = useState((_g = definedTableOptions.data) !== null && _g !== void 0 ? _g : []);
2857
+ definedTableOptions.state = Object.assign({ columnFilterFns,
2650
2858
  columnOrder,
2651
- columnSizingInfo,
2652
2859
  creatingRow,
2653
- density,
2654
- draggingColumn,
2655
- draggingRow,
2656
- editingCell,
2657
- editingRow,
2658
2860
  filters,
2659
2861
  globalFilterFn,
2660
2862
  grouping,
2661
- hoveredColumn,
2662
- hoveredRow,
2663
- pagination,
2664
- rowReorderingSelection,
2665
- savedFilters,
2666
- showAlertBanner,
2667
- showColumnFilters,
2668
- showGlobalFilter,
2669
- showProgressBars,
2670
- showToolbarDropZone,
2671
- newEntryModal }, definedTableOptions.state);
2863
+ pagination }, definedTableOptions.state);
2864
+ // Sync a controlled consumer's state.draggingColumn/draggingRow/hoveredColumn/
2865
+ // hoveredRow into the slice stores — rare (these are usually left uncontrolled), but
2866
+ // since they no longer flow through definedTableOptions.state -> useReactTable, an
2867
+ // externally-controlled value needs an explicit bridge into the store.
2868
+ useEffect(() => {
2869
+ var _a;
2870
+ if (((_a = definedTableOptions.state) === null || _a === void 0 ? void 0 : _a.draggingColumn) !== undefined) {
2871
+ dragStore.set((prev) => (Object.assign(Object.assign({}, prev), { draggingColumn: definedTableOptions.state.draggingColumn })));
2872
+ }
2873
+ }, [(_h = definedTableOptions.state) === null || _h === void 0 ? void 0 : _h.draggingColumn]);
2874
+ useEffect(() => {
2875
+ var _a;
2876
+ if (((_a = definedTableOptions.state) === null || _a === void 0 ? void 0 : _a.draggingRow) !== undefined) {
2877
+ dragStore.set((prev) => (Object.assign(Object.assign({}, prev), { draggingRow: definedTableOptions.state.draggingRow })));
2878
+ }
2879
+ }, [(_j = definedTableOptions.state) === null || _j === void 0 ? void 0 : _j.draggingRow]);
2880
+ useEffect(() => {
2881
+ var _a;
2882
+ if (((_a = definedTableOptions.state) === null || _a === void 0 ? void 0 : _a.hoveredColumn) !== undefined) {
2883
+ hoverStore.set((prev) => (Object.assign(Object.assign({}, prev), { hoveredColumn: definedTableOptions.state.hoveredColumn })));
2884
+ }
2885
+ }, [(_k = definedTableOptions.state) === null || _k === void 0 ? void 0 : _k.hoveredColumn]);
2886
+ useEffect(() => {
2887
+ var _a;
2888
+ if (((_a = definedTableOptions.state) === null || _a === void 0 ? void 0 : _a.hoveredRow) !== undefined) {
2889
+ hoverStore.set((prev) => (Object.assign(Object.assign({}, prev), { hoveredRow: definedTableOptions.state.hoveredRow })));
2890
+ }
2891
+ }, [(_l = definedTableOptions.state) === null || _l === void 0 ? void 0 : _l.hoveredRow]);
2892
+ // Same bridge as above, for the 12 UI-only fields in uiStore (columnSizingInfo is
2893
+ // deliberately excluded — it isn't part of the table.setX = onXChange ?? ... pattern,
2894
+ // see onColumnSizingInfoChange above).
2895
+ useEffect(() => {
2896
+ var _a;
2897
+ if (((_a = definedTableOptions.state) === null || _a === void 0 ? void 0 : _a.actionCell) !== undefined) {
2898
+ uiStore.set((prev) => (Object.assign(Object.assign({}, prev), { actionCell: definedTableOptions.state.actionCell })));
2899
+ }
2900
+ }, [(_m = definedTableOptions.state) === null || _m === void 0 ? void 0 : _m.actionCell]);
2901
+ useEffect(() => {
2902
+ var _a;
2903
+ if (((_a = definedTableOptions.state) === null || _a === void 0 ? void 0 : _a.density) !== undefined) {
2904
+ uiStore.set((prev) => (Object.assign(Object.assign({}, prev), { density: definedTableOptions.state.density })));
2905
+ }
2906
+ }, [(_o = definedTableOptions.state) === null || _o === void 0 ? void 0 : _o.density]);
2907
+ useEffect(() => {
2908
+ var _a;
2909
+ if (((_a = definedTableOptions.state) === null || _a === void 0 ? void 0 : _a.editingCell) !== undefined) {
2910
+ uiStore.set((prev) => (Object.assign(Object.assign({}, prev), { editingCell: definedTableOptions.state.editingCell })));
2911
+ }
2912
+ }, [(_p = definedTableOptions.state) === null || _p === void 0 ? void 0 : _p.editingCell]);
2913
+ useEffect(() => {
2914
+ var _a;
2915
+ if (((_a = definedTableOptions.state) === null || _a === void 0 ? void 0 : _a.editingRow) !== undefined) {
2916
+ uiStore.set((prev) => (Object.assign(Object.assign({}, prev), { editingRow: definedTableOptions.state.editingRow })));
2917
+ }
2918
+ }, [(_q = definedTableOptions.state) === null || _q === void 0 ? void 0 : _q.editingRow]);
2919
+ useEffect(() => {
2920
+ var _a;
2921
+ if (((_a = definedTableOptions.state) === null || _a === void 0 ? void 0 : _a.newEntryModal) !== undefined) {
2922
+ uiStore.set((prev) => (Object.assign(Object.assign({}, prev), { newEntryModal: definedTableOptions.state.newEntryModal })));
2923
+ }
2924
+ }, [(_r = definedTableOptions.state) === null || _r === void 0 ? void 0 : _r.newEntryModal]);
2925
+ useEffect(() => {
2926
+ var _a;
2927
+ if (((_a = definedTableOptions.state) === null || _a === void 0 ? void 0 : _a.rowReorderingSelection) !== undefined) {
2928
+ uiStore.set((prev) => (Object.assign(Object.assign({}, prev), { rowReorderingSelection: definedTableOptions.state.rowReorderingSelection })));
2929
+ }
2930
+ }, [(_s = definedTableOptions.state) === null || _s === void 0 ? void 0 : _s.rowReorderingSelection]);
2931
+ useEffect(() => {
2932
+ var _a;
2933
+ if (((_a = definedTableOptions.state) === null || _a === void 0 ? void 0 : _a.savedFilters) !== undefined) {
2934
+ uiStore.set((prev) => (Object.assign(Object.assign({}, prev), { savedFilters: definedTableOptions.state.savedFilters })));
2935
+ }
2936
+ }, [(_t = definedTableOptions.state) === null || _t === void 0 ? void 0 : _t.savedFilters]);
2937
+ useEffect(() => {
2938
+ var _a;
2939
+ if (((_a = definedTableOptions.state) === null || _a === void 0 ? void 0 : _a.showAlertBanner) !== undefined) {
2940
+ uiStore.set((prev) => (Object.assign(Object.assign({}, prev), { showAlertBanner: definedTableOptions.state.showAlertBanner })));
2941
+ }
2942
+ }, [(_u = definedTableOptions.state) === null || _u === void 0 ? void 0 : _u.showAlertBanner]);
2943
+ useEffect(() => {
2944
+ var _a;
2945
+ if (((_a = definedTableOptions.state) === null || _a === void 0 ? void 0 : _a.showColumnFilters) !== undefined) {
2946
+ uiStore.set((prev) => (Object.assign(Object.assign({}, prev), { showColumnFilters: definedTableOptions.state.showColumnFilters })));
2947
+ }
2948
+ }, [(_v = definedTableOptions.state) === null || _v === void 0 ? void 0 : _v.showColumnFilters]);
2949
+ useEffect(() => {
2950
+ var _a;
2951
+ if (((_a = definedTableOptions.state) === null || _a === void 0 ? void 0 : _a.showGlobalFilter) !== undefined) {
2952
+ uiStore.set((prev) => (Object.assign(Object.assign({}, prev), { showGlobalFilter: definedTableOptions.state.showGlobalFilter })));
2953
+ }
2954
+ }, [(_w = definedTableOptions.state) === null || _w === void 0 ? void 0 : _w.showGlobalFilter]);
2955
+ useEffect(() => {
2956
+ var _a;
2957
+ if (((_a = definedTableOptions.state) === null || _a === void 0 ? void 0 : _a.showProgressBars) !== undefined) {
2958
+ uiStore.set((prev) => (Object.assign(Object.assign({}, prev), { showProgressBars: definedTableOptions.state.showProgressBars })));
2959
+ }
2960
+ }, [(_x = definedTableOptions.state) === null || _x === void 0 ? void 0 : _x.showProgressBars]);
2961
+ useEffect(() => {
2962
+ var _a;
2963
+ if (((_a = definedTableOptions.state) === null || _a === void 0 ? void 0 : _a.showToolbarDropZone) !== undefined) {
2964
+ uiStore.set((prev) => (Object.assign(Object.assign({}, prev), { showToolbarDropZone: definedTableOptions.state.showToolbarDropZone })));
2965
+ }
2966
+ }, [(_y = definedTableOptions.state) === null || _y === void 0 ? void 0 : _y.showToolbarDropZone]);
2672
2967
  // Normalize controlled columnPinning state: if the user passes state.columnPinning
2673
2968
  // directly (controlled mode), we still need to ensure that the checkbox column
2674
2969
  // is always at the front of the left-pinned group, just like we do for initialState.
@@ -2678,7 +2973,7 @@ const useMRT_TableInstance = (definedTableOptions) => {
2678
2973
  }
2679
2974
  //The table options now include all state needed to help determine column visibility and order logic
2680
2975
  const statefulTableOptions = definedTableOptions;
2681
- const resolveRowId = (_0 = statefulTableOptions.getRowId) !== null && _0 !== void 0 ? _0 : ((_originalRow, index, _parentRow) => String(index));
2976
+ const resolveRowId = (_z = statefulTableOptions.getRowId) !== null && _z !== void 0 ? _z : ((_originalRow, index, _parentRow) => String(index));
2682
2977
  //keep the prepared column tree referentially stable so TanStack's
2683
2978
  //getAllColumns/getAllLeafColumns/row.getAllCells memo chain doesn't
2684
2979
  //recompute (and recreate every cell of every row) on unrelated renders
@@ -2757,24 +3052,34 @@ const useMRT_TableInstance = (definedTableOptions) => {
2757
3052
  const table = useReactTable(Object.assign(Object.assign({ onColumnOrderChange,
2758
3053
  onColumnSizingInfoChange,
2759
3054
  onGroupingChange,
2760
- onPaginationChange }, statefulTableOptions), { globalFilterFn: (_1 = statefulTableOptions.filterFns) === null || _1 === void 0 ? void 0 : _1[globalFilterFn !== null && globalFilterFn !== void 0 ? globalFilterFn : 'fuzzy'] }));
3055
+ onPaginationChange }, statefulTableOptions), { globalFilterFn: (_0 = statefulTableOptions.filterFns) === null || _0 === void 0 ? void 0 : _0[globalFilterFn !== null && globalFilterFn !== void 0 ? globalFilterFn : 'fuzzy'] }));
2761
3056
  table.refs = {
2762
3057
  actionCellRef,
2763
3058
  allSelectableRowIdsRef,
2764
3059
  bottomToolbarRef,
2765
3060
  editInputRefs,
2766
3061
  filterInputRefs,
3062
+ isResizingRef,
2767
3063
  lastSelectedRowId,
3064
+ resizeIndicatorRef,
2768
3065
  searchInputRef,
2769
3066
  tableContainerRef,
2770
3067
  tableFooterRef,
2771
3068
  tableHeadCellRefs,
2772
3069
  tableHeadRef,
2773
3070
  tablePaperRef,
3071
+ tableRef,
2774
3072
  topToolbarRef,
2775
3073
  };
3074
+ table._dragStore = dragStore;
3075
+ table._hoverStore = hoverStore;
3076
+ table._uiStore = uiStore;
3077
+ // Merge the slice stores back into getState() so every existing/external
3078
+ // `table.getState().hoveredColumn`-style read keeps working unchanged.
3079
+ const originalGetState = table.getState;
3080
+ table.getState = () => (Object.assign(Object.assign(Object.assign(Object.assign({}, originalGetState()), dragStore.get()), hoverStore.get()), uiStore.get()));
2776
3081
  table.setActionCell =
2777
- (_2 = statefulTableOptions.onActionCellChange) !== null && _2 !== void 0 ? _2 : setActionCell;
3082
+ (_1 = statefulTableOptions.onActionCellChange) !== null && _1 !== void 0 ? _1 : ((updater) => uiStore.set((prev) => (Object.assign(Object.assign({}, prev), { actionCell: updater instanceof Function ? updater(prev.actionCell) : updater }))));
2778
3083
  table.setCreatingRow = (row) => {
2779
3084
  var _a, _b;
2780
3085
  let _row = row;
@@ -2784,39 +3089,48 @@ const useMRT_TableInstance = (definedTableOptions) => {
2784
3089
  (_b = (_a = statefulTableOptions === null || statefulTableOptions === void 0 ? void 0 : statefulTableOptions.onCreatingRowChange) === null || _a === void 0 ? void 0 : _a.call(statefulTableOptions, _row)) !== null && _b !== void 0 ? _b : _setCreatingRow(_row);
2785
3090
  };
2786
3091
  table.setColumnFilterFns =
2787
- (_3 = statefulTableOptions.onColumnFilterFnsChange) !== null && _3 !== void 0 ? _3 : setColumnFilterFns;
2788
- table.setDensity = (_4 = statefulTableOptions.onDensityChange) !== null && _4 !== void 0 ? _4 : setDensity;
3092
+ (_2 = statefulTableOptions.onColumnFilterFnsChange) !== null && _2 !== void 0 ? _2 : setColumnFilterFns;
3093
+ table.setDensity =
3094
+ (_3 = statefulTableOptions.onDensityChange) !== null && _3 !== void 0 ? _3 : ((updater) => uiStore.set((prev) => (Object.assign(Object.assign({}, prev), { density: updater instanceof Function ? updater(prev.density) : updater }))));
2789
3095
  table.setDraggingColumn =
2790
- (_5 = statefulTableOptions.onDraggingColumnChange) !== null && _5 !== void 0 ? _5 : setDraggingColumn;
3096
+ (_4 = statefulTableOptions.onDraggingColumnChange) !== null && _4 !== void 0 ? _4 : ((updater) => dragStore.set((prev) => (Object.assign(Object.assign({}, prev), { draggingColumn: updater instanceof Function ? updater(prev.draggingColumn) : updater }))));
2791
3097
  table.setDraggingRow =
2792
- (_6 = statefulTableOptions.onDraggingRowChange) !== null && _6 !== void 0 ? _6 : setDraggingRow;
3098
+ (_5 = statefulTableOptions.onDraggingRowChange) !== null && _5 !== void 0 ? _5 : ((updater) => dragStore.set((prev) => (Object.assign(Object.assign({}, prev), { draggingRow: updater instanceof Function ? updater(prev.draggingRow) : updater }))));
2793
3099
  table.setEditingCell =
2794
- (_7 = statefulTableOptions.onEditingCellChange) !== null && _7 !== void 0 ? _7 : setEditingCell;
3100
+ (_6 = statefulTableOptions.onEditingCellChange) !== null && _6 !== void 0 ? _6 : ((updater) => uiStore.set((prev) => (Object.assign(Object.assign({}, prev), { editingCell: updater instanceof Function ? updater(prev.editingCell) : updater }))));
2795
3101
  table.setEditingRow =
2796
- (_8 = statefulTableOptions.onEditingRowChange) !== null && _8 !== void 0 ? _8 : setEditingRow;
2797
- table.setFilters = (_9 = statefulTableOptions.onFiltersChange) !== null && _9 !== void 0 ? _9 : setFilters;
3102
+ (_7 = statefulTableOptions.onEditingRowChange) !== null && _7 !== void 0 ? _7 : ((updater) => uiStore.set((prev) => (Object.assign(Object.assign({}, prev), { editingRow: updater instanceof Function ? updater(prev.editingRow) : updater }))));
3103
+ table.setFilters = (_8 = statefulTableOptions.onFiltersChange) !== null && _8 !== void 0 ? _8 : setFilters;
2798
3104
  table.setGlobalFilterFn =
2799
- (_10 = statefulTableOptions.onGlobalFilterFnChange) !== null && _10 !== void 0 ? _10 : setGlobalFilterFn;
3105
+ (_9 = statefulTableOptions.onGlobalFilterFnChange) !== null && _9 !== void 0 ? _9 : setGlobalFilterFn;
2800
3106
  table.setHoveredColumn =
2801
- (_11 = statefulTableOptions.onHoveredColumnChange) !== null && _11 !== void 0 ? _11 : setHoveredColumn;
3107
+ (_10 = statefulTableOptions.onHoveredColumnChange) !== null && _10 !== void 0 ? _10 : ((updater) => hoverStore.set((prev) => (Object.assign(Object.assign({}, prev), { hoveredColumn: updater instanceof Function ? updater(prev.hoveredColumn) : updater }))));
2802
3108
  table.setHoveredRow =
2803
- (_12 = statefulTableOptions.onHoveredRowChange) !== null && _12 !== void 0 ? _12 : setHoveredRow;
2804
- table.setSavedFilters = setSavedFilters;
3109
+ (_11 = statefulTableOptions.onHoveredRowChange) !== null && _11 !== void 0 ? _11 : ((updater) => hoverStore.set((prev) => (Object.assign(Object.assign({}, prev), { hoveredRow: updater instanceof Function ? updater(prev.hoveredRow) : updater }))));
3110
+ table.setSavedFilters = (updater) => uiStore.set((prev) => (Object.assign(Object.assign({}, prev), { savedFilters: updater instanceof Function ? updater(prev.savedFilters) : updater })));
2805
3111
  table.setShowAlertBanner =
2806
- (_13 = statefulTableOptions.onShowAlertBannerChange) !== null && _13 !== void 0 ? _13 : setShowAlertBanner;
3112
+ (_12 = statefulTableOptions.onShowAlertBannerChange) !== null && _12 !== void 0 ? _12 : ((updater) => uiStore.set((prev) => (Object.assign(Object.assign({}, prev), { showAlertBanner: updater instanceof Function ? updater(prev.showAlertBanner) : updater }))));
2807
3113
  table._showAdvancedFiltersSetterRef = showAdvancedFiltersSetterRef;
2808
3114
  table.setShowAdvancedFilters =
2809
- (_14 = statefulTableOptions.onShowAdvancedFiltersChange) !== null && _14 !== void 0 ? _14 : ((updater) => { var _a; return (_a = showAdvancedFiltersSetterRef.current) === null || _a === void 0 ? void 0 : _a.call(showAdvancedFiltersSetterRef, updater); });
3115
+ (_13 = statefulTableOptions.onShowAdvancedFiltersChange) !== null && _13 !== void 0 ? _13 : ((updater) => { var _a; return (_a = showAdvancedFiltersSetterRef.current) === null || _a === void 0 ? void 0 : _a.call(showAdvancedFiltersSetterRef, updater); });
2810
3116
  table.setShowColumnFilters =
2811
- (_15 = statefulTableOptions.onShowColumnFiltersChange) !== null && _15 !== void 0 ? _15 : setShowColumnFilters;
3117
+ (_14 = statefulTableOptions.onShowColumnFiltersChange) !== null && _14 !== void 0 ? _14 : ((updater) => uiStore.set((prev) => (Object.assign(Object.assign({}, prev), { showColumnFilters: updater instanceof Function
3118
+ ? updater(prev.showColumnFilters)
3119
+ : updater }))));
2812
3120
  table.setShowGlobalFilter =
2813
- (_16 = statefulTableOptions.onShowGlobalFilterChange) !== null && _16 !== void 0 ? _16 : setShowGlobalFilter;
2814
- table.setShowProgressBars = setShowProgressBars;
3121
+ (_15 = statefulTableOptions.onShowGlobalFilterChange) !== null && _15 !== void 0 ? _15 : ((updater) => uiStore.set((prev) => (Object.assign(Object.assign({}, prev), { showGlobalFilter: updater instanceof Function
3122
+ ? updater(prev.showGlobalFilter)
3123
+ : updater }))));
3124
+ table.setShowProgressBars = (updater) => uiStore.set((prev) => (Object.assign(Object.assign({}, prev), { showProgressBars: updater instanceof Function ? updater(prev.showProgressBars) : updater })));
2815
3125
  table.setShowToolbarDropZone =
2816
- (_17 = statefulTableOptions.onShowToolbarDropZoneChange) !== null && _17 !== void 0 ? _17 : setShowToolbarDropZone;
2817
- table.setNewEntryModal = setNewEntryModal;
3126
+ (_16 = statefulTableOptions.onShowToolbarDropZoneChange) !== null && _16 !== void 0 ? _16 : ((updater) => uiStore.set((prev) => (Object.assign(Object.assign({}, prev), { showToolbarDropZone: updater instanceof Function
3127
+ ? updater(prev.showToolbarDropZone)
3128
+ : updater }))));
3129
+ table.setNewEntryModal = (updater) => uiStore.set((prev) => (Object.assign(Object.assign({}, prev), { newEntryModal: updater instanceof Function ? updater(prev.newEntryModal) : updater })));
2818
3130
  table.setRowReorderingSelection =
2819
- (_18 = statefulTableOptions.onRowReorderingSelectionChange) !== null && _18 !== void 0 ? _18 : setRowReorderingSelection;
3131
+ (_17 = statefulTableOptions.onRowReorderingSelectionChange) !== null && _17 !== void 0 ? _17 : ((updater) => uiStore.set((prev) => (Object.assign(Object.assign({}, prev), { rowReorderingSelection: updater instanceof Function
3132
+ ? updater(prev.rowReorderingSelection)
3133
+ : updater }))));
2820
3134
  table.addRow = handleAddRow({
2821
3135
  setRowsState,
2822
3136
  getRowId: resolveRowId,
@@ -2865,7 +3179,8 @@ const extraIndexRangeExtractor = (range, draggingIndex) => {
2865
3179
  const useMRT_ColumnVirtualizer = (table) => {
2866
3180
  var _a, _b, _c, _d;
2867
3181
  const { getState, options: { columnVirtualizerInstanceRef, columnVirtualizerOptions, enableColumnPinning, enableColumnVirtualization, }, refs: { tableContainerRef }, } = table;
2868
- const { columnPinning, columnVisibility, draggingColumn } = getState();
3182
+ const { columnPinning, columnVisibility } = getState();
3183
+ const draggingColumnId = useMRT_SliceValue(table._dragStore, (s) => { var _a; return (_a = s.draggingColumn) === null || _a === void 0 ? void 0 : _a.id; });
2869
3184
  if (!enableColumnVirtualization)
2870
3185
  return undefined;
2871
3186
  const columnVirtualizerProps = parseFromValuesOrFunc(columnVirtualizerOptions, {
@@ -2883,9 +3198,9 @@ const useMRT_ColumnVirtualizer = (table) => {
2883
3198
  : [[], []], [columnPinning, columnVisibility, enableColumnPinning]);
2884
3199
  const numPinnedLeft = leftPinnedIndexes.length;
2885
3200
  const numPinnedRight = rightPinnedIndexes.length;
2886
- const draggingColumnIndex = useMemo(() => (draggingColumn === null || draggingColumn === void 0 ? void 0 : draggingColumn.id)
2887
- ? visibleColumns.findIndex((c) => c.id === (draggingColumn === null || draggingColumn === void 0 ? void 0 : draggingColumn.id))
2888
- : undefined, [draggingColumn === null || draggingColumn === void 0 ? void 0 : draggingColumn.id]);
3201
+ const draggingColumnIndex = useMemo(() => draggingColumnId
3202
+ ? visibleColumns.findIndex((c) => c.id === draggingColumnId)
3203
+ : undefined, [draggingColumnId]);
2889
3204
  const columnVirtualizer = useVirtualizer(Object.assign({ count: visibleColumns.length, estimateSize: (index) => visibleColumns[index].getSize(), getScrollElement: () => tableContainerRef.current, horizontal: true, overscan: 3, rangeExtractor: useCallback((range) => {
2890
3205
  const newIndexes = extraIndexRangeExtractor(range, draggingColumnIndex);
2891
3206
  if (!numPinnedLeft && !numPinnedRight) {
@@ -2943,7 +3258,9 @@ const useMRT_Rows = (table) => {
2943
3258
 
2944
3259
  const useMRT_RowVirtualizer = (table, rows) => {
2945
3260
  const { getRowModel, getState, options: { enableRowVirtualization, renderDetailPanel, rowVirtualizerInstanceRef, rowVirtualizerOptions, }, refs: { tableContainerRef }, } = table;
2946
- const { density, draggingRow, expanded } = getState();
3261
+ const { expanded } = getState();
3262
+ const density = useMRT_SliceValue(table._uiStore, (s) => s.density);
3263
+ const draggingRowId = useMRT_SliceValue(table._dragStore, (s) => { var _a; return (_a = s.draggingRow) === null || _a === void 0 ? void 0 : _a.id; });
2947
3264
  if (!enableRowVirtualization)
2948
3265
  return undefined;
2949
3266
  const rowVirtualizerProps = parseFromValuesOrFunc(rowVirtualizerOptions, {
@@ -2953,9 +3270,9 @@ const useMRT_RowVirtualizer = (table, rows) => {
2953
3270
  /**
2954
3271
  * when filtering, should find the correct index in filtered rows
2955
3272
  */
2956
- const draggingRowIndex = useMemo(() => (draggingRow === null || draggingRow === void 0 ? void 0 : draggingRow.id)
2957
- ? realRows.findIndex((r) => r.id === (draggingRow === null || draggingRow === void 0 ? void 0 : draggingRow.id))
2958
- : undefined, [realRows, draggingRow === null || draggingRow === void 0 ? void 0 : draggingRow.id]);
3273
+ const draggingRowIndex = useMemo(() => draggingRowId
3274
+ ? realRows.findIndex((r) => r.id === draggingRowId)
3275
+ : undefined, [realRows, draggingRowId]);
2959
3276
  const rowCount = realRows.length;
2960
3277
  //matches the defaultRowHeight assumption in MRT_TableBodyRow so the
2961
3278
  //initial estimate (before measureElement corrects it for dynamic content)
@@ -3951,26 +4268,6 @@ const DimensionColumnResolver = {
3951
4268
  activeFilterRenderer: DimensionActiveFilterItem,
3952
4269
  };
3953
4270
 
3954
- const getEnumLabelByValue = (value, enumOptions) => {
3955
- var _a;
3956
- const normalizedValue = String(value !== null && value !== void 0 ? value : '');
3957
- const matchingOption = enumOptions.find((option) => option.value === normalizedValue);
3958
- return (_a = matchingOption === null || matchingOption === void 0 ? void 0 : matchingOption.label) !== null && _a !== void 0 ? _a : normalizedValue;
3959
- };
3960
- const EnumActiveFilterItem = (table, rule) => {
3961
- var _a, _b;
3962
- if (typeof rule.value !== 'string' && !Array.isArray(rule.value))
3963
- return null;
3964
- const column = getFilterColumn(table, rule.columnId);
3965
- const enumOptions = (_b = (_a = column === null || column === void 0 ? void 0 : column.columnDef.meta) === null || _a === void 0 ? void 0 : _a.enumValues) !== null && _b !== void 0 ? _b : [];
3966
- if (rule.operator === 'isAnyOf' && Array.isArray(rule.value)) {
3967
- return (jsx(MRT_ActiveFilterItemContainer, { table: table, rule: rule, children: jsx(Typography, { variant: "body2", children: rule.value
3968
- .map((value) => getEnumLabelByValue(value, enumOptions))
3969
- .join(', ') }) }));
3970
- }
3971
- return (jsx(MRT_ActiveFilterItemContainer, { table: table, rule: rule, children: jsx(Typography, { variant: "body2", children: getEnumLabelByValue(rule.value, enumOptions) }) }));
3972
- };
3973
-
3974
4271
  const DEFAULT_FIELD_SIZE$4 = 'small';
3975
4272
  const MRT_FormEnumInput = ({ name, columnDef, fieldConfig, }) => {
3976
4273
  var _a, _b, _c;
@@ -4003,6 +4300,26 @@ const MRT_FormEnumInput = ({ name, columnDef, fieldConfig, }) => {
4003
4300
  } }));
4004
4301
  };
4005
4302
 
4303
+ const getEnumLabelByValue = (value, enumOptions) => {
4304
+ var _a;
4305
+ const normalizedValue = String(value !== null && value !== void 0 ? value : '');
4306
+ const matchingOption = enumOptions.find((option) => option.value === normalizedValue);
4307
+ return (_a = matchingOption === null || matchingOption === void 0 ? void 0 : matchingOption.label) !== null && _a !== void 0 ? _a : normalizedValue;
4308
+ };
4309
+ const EnumActiveFilterItem = (table, rule) => {
4310
+ var _a, _b;
4311
+ if (typeof rule.value !== 'string' && !Array.isArray(rule.value))
4312
+ return null;
4313
+ const column = getFilterColumn(table, rule.columnId);
4314
+ const enumOptions = (_b = (_a = column === null || column === void 0 ? void 0 : column.columnDef.meta) === null || _a === void 0 ? void 0 : _a.enumValues) !== null && _b !== void 0 ? _b : [];
4315
+ if (rule.operator === 'isAnyOf' && Array.isArray(rule.value)) {
4316
+ return (jsx(MRT_ActiveFilterItemContainer, { table: table, rule: rule, children: jsx(Typography, { variant: "body2", children: rule.value
4317
+ .map((value) => getEnumLabelByValue(value, enumOptions))
4318
+ .join(', ') }) }));
4319
+ }
4320
+ return (jsx(MRT_ActiveFilterItemContainer, { table: table, rule: rule, children: jsx(Typography, { variant: "body2", children: getEnumLabelByValue(rule.value, enumOptions) }) }));
4321
+ };
4322
+
4006
4323
  // Resolver for enum column type.
4007
4324
  // Renders only the human-readable label and provides select/multi-select filters.
4008
4325
  const EnumColumnResolver = {
@@ -5289,7 +5606,8 @@ const MRT_ActiveFilters = ({ table, }) => {
5289
5606
  const MRT_LinearProgressBar = (_a) => {
5290
5607
  var { isTopToolbar, table } = _a, rest = __rest(_a, ["isTopToolbar", "table"]);
5291
5608
  const { getState, options: { muiLinearProgressProps }, } = table;
5292
- const { isSaving, showProgressBars } = getState();
5609
+ const { isSaving } = getState();
5610
+ const showProgressBars = useMRT_SliceValue(table._uiStore, (s) => s.showProgressBars);
5293
5611
  const linearProgressProps = Object.assign(Object.assign({}, parseFromValuesOrFunc(muiLinearProgressProps, {
5294
5612
  isTopToolbar,
5295
5613
  table,
@@ -5390,7 +5708,10 @@ const MRT_ToolbarDropZone = (_a) => {
5390
5708
  var _b, _c;
5391
5709
  var { table } = _a, rest = __rest(_a, ["table"]);
5392
5710
  const { getState, options: { enableGrouping, localization }, setHoveredColumn, setShowToolbarDropZone, } = table;
5393
- const { draggingColumn, grouping, hoveredColumn, showToolbarDropZone } = getState();
5711
+ const { grouping } = getState();
5712
+ const showToolbarDropZone = useMRT_SliceValue(table._uiStore, (s) => s.showToolbarDropZone);
5713
+ const draggingColumn = useMRT_SliceValue(table._dragStore, (s) => s.draggingColumn);
5714
+ const hoveredColumn = useMRT_SliceValue(table._hoverStore, (s) => s.hoveredColumn);
5394
5715
  const handleDragEnter = (_event) => {
5395
5716
  setHoveredColumn({ id: 'drop-zone' });
5396
5717
  };
@@ -5701,7 +6022,8 @@ const MRT_FilterOptionMenu = (_a) => {
5701
6022
  var _b, _c, _d, _e;
5702
6023
  var { anchorEl, header, onSelect, setAnchorEl, setFilterValue, table } = _a, rest = __rest(_a, ["anchorEl", "header", "onSelect", "setAnchorEl", "setFilterValue", "table"]);
5703
6024
  const { getState, options: { columnFilterModeOptions, globalFilterModeOptions, localization, mrtTheme: { menuBackgroundColor }, renderColumnFilterModeMenuItems, renderGlobalFilterModeMenuItems, }, setColumnFilterFns, setGlobalFilterFn, } = table;
5704
- const { density, globalFilterFn } = getState();
6025
+ const { globalFilterFn } = getState();
6026
+ const density = useMRT_SliceValue(table._uiStore, (s) => s.density);
5705
6027
  const { column } = header !== null && header !== void 0 ? header : {};
5706
6028
  const { columnDef } = column !== null && column !== void 0 ? column : {};
5707
6029
  const currentFilterValue = column === null || column === void 0 ? void 0 : column.getFilterValue();
@@ -5811,7 +6133,8 @@ const MRT_GlobalFilterTextField = (_a) => {
5811
6133
  var _b;
5812
6134
  var { table } = _a, rest = __rest(_a, ["table"]);
5813
6135
  const { getState, options: { enableGlobalFilterModes, icons: { CloseIcon, SearchIcon }, localization, manualFiltering, muiSearchTextFieldProps, }, refs: { searchInputRef }, setGlobalFilter, } = table;
5814
- const { globalFilter, showGlobalFilter } = getState();
6136
+ const { globalFilter } = getState();
6137
+ const showGlobalFilter = useMRT_SliceValue(table._uiStore, (s) => s.showGlobalFilter);
5815
6138
  const textFieldProps = Object.assign(Object.assign({}, parseFromValuesOrFunc(muiSearchTextFieldProps, {
5816
6139
  table,
5817
6140
  })), rest);
@@ -5927,8 +6250,8 @@ function MRT_TableOptions(_a) {
5927
6250
  }
5928
6251
 
5929
6252
  const MRT_SavedFiltersButton = ({ onSelectFilter, table, }) => {
5930
- const { getState, options: { localization, onDeleteSavedFilter, onSaveFilters }, setFilters, setSavedFilters, } = table;
5931
- const { savedFilters } = getState();
6253
+ const { options: { localization, onDeleteSavedFilter, onSaveFilters }, setFilters, setSavedFilters, } = table;
6254
+ const savedFilters = useMRT_SliceValue(table._uiStore, (s) => s.savedFilters);
5932
6255
  const savedFiltersList = Object.values(savedFilters);
5933
6256
  const buttonRef = useRef(null);
5934
6257
  const [menuOpen, setMenuOpen] = useState(false);
@@ -5980,24 +6303,10 @@ const MRT_NewEntryButton = (_a) => {
5980
6303
  return (jsx(Tooltip, { title: (_b = rest === null || rest === void 0 ? void 0 : rest.title) !== null && _b !== void 0 ? _b : localization.newEntry, children: jsx(Button, Object.assign({ "aria-label": localization.newEntry, onClick: handleOpenNewEntryModal, size: "small", startIcon: jsx(AddIcon, { fontSize: "small" }), variant: "text" }, rest, { title: undefined, children: localization.newEntry })) }));
5981
6304
  };
5982
6305
 
5983
- const MRT_ColumnPinningButtons = (_a) => {
5984
- var { column, table } = _a, rest = __rest(_a, ["column", "table"]);
5985
- const { options: { icons: { PushPinIcon }, localization, }, } = table;
5986
- const handlePinColumn = (pinDirection) => {
5987
- column.pin(pinDirection);
5988
- };
5989
- return (jsx(Box, Object.assign({}, rest, { sx: (theme) => (Object.assign({ minWidth: '70px', textAlign: 'center' }, parseFromValuesOrFunc(rest === null || rest === void 0 ? void 0 : rest.sx, theme))), children: column.getIsPinned() ? (jsx(Tooltip, { title: localization.unpin, children: jsx(IconButton, { onClick: () => handlePinColumn(false), size: "small", children: jsx(PushPinIcon, {}) }) })) : (jsxs(Fragment, { children: [jsx(Tooltip, { title: localization.pinToLeft, children: jsx(IconButton, { onClick: () => handlePinColumn('left'), size: "small", children: jsx(PushPinIcon, { style: {
5990
- transform: 'rotate(90deg)',
5991
- } }) }) }), jsx(Tooltip, { title: localization.pinToRight, children: jsx(IconButton, { onClick: () => handlePinColumn('right'), size: "small", children: jsx(PushPinIcon, { style: {
5992
- transform: 'rotate(-90deg)',
5993
- } }) }) })] })) })));
5994
- };
5995
-
5996
6306
  const MRT_ShowHideColumnsMenuItems = (_a) => {
5997
6307
  var _b;
5998
6308
  var { allColumns, column, hoveredColumn, isNestedColumns, setHoveredColumn, table } = _a, rest = __rest(_a, ["allColumns", "column", "hoveredColumn", "isNestedColumns", "setHoveredColumn", "table"]);
5999
- const { getState, options: { enableColumnOrdering, enableColumnPinning, enableHiding, localization, mrtTheme: { draggingBorderColor }, }, setColumnOrder, setColumnPinning, } = table;
6000
- const { columnOrder } = getState();
6309
+ const { options: { enableHiding, localization, mrtTheme: { draggingBorderColor }, }, } = table;
6001
6310
  const { columnDef } = column;
6002
6311
  const { columnDefType } = columnDef;
6003
6312
  const switchChecked = column.getIsVisible();
@@ -6012,63 +6321,30 @@ const MRT_ShowHideColumnsMenuItems = (_a) => {
6012
6321
  column.toggleVisibility();
6013
6322
  }
6014
6323
  };
6015
- const menuItemRef = useRef(null);
6016
- const [isDragging, setIsDragging] = useState(false);
6017
- const handleDragStart = (e) => {
6018
- setIsDragging(true);
6019
- try {
6020
- e.dataTransfer.setDragImage(menuItemRef.current, 0, 0);
6021
- }
6022
- catch (e) {
6023
- console.error(e);
6024
- }
6025
- };
6026
- const handleDragEnd = (_e) => {
6027
- setIsDragging(false);
6028
- setHoveredColumn(null);
6029
- if (hoveredColumn) {
6030
- const reorderedColumns = reorderColumn(column, hoveredColumn, columnOrder);
6031
- setColumnOrder(reorderedColumns);
6032
- setColumnPinning(({ left = [], right = [] }) => ({
6033
- left: reorderedColumns.filter((header) => left.includes(header)),
6034
- right: reorderedColumns.filter((header) => right.includes(header)),
6035
- }));
6036
- }
6037
- };
6038
- const handleDragEnter = (_e) => {
6039
- if (!isDragging && columnDef.enableColumnOrdering !== false) {
6040
- setHoveredColumn(column);
6041
- }
6042
- };
6043
6324
  if (!columnDef.header || columnDef.visibleInShowHideMenu === false) {
6044
6325
  return null;
6045
6326
  }
6046
- return (jsxs(Fragment, { children: [jsx(MenuItem, Object.assign({ disableRipple: true, onDragEnter: handleDragEnter, ref: menuItemRef }, rest, { sx: (theme) => (Object.assign({ alignItems: 'center', justifyContent: 'flex-start', my: 0, opacity: isDragging ? 0.5 : 1, outline: isDragging
6047
- ? `2px dashed ${theme.palette.grey[500]}`
6048
- : (hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === column.id
6049
- ? `2px dashed ${draggingBorderColor}`
6050
- : 'none', outlineOffset: '-2px', pl: `${(column.depth + 0.5) * 2}rem`, py: '6px' }, parseFromValuesOrFunc(rest === null || rest === void 0 ? void 0 : rest.sx, theme))), children: jsxs(Box, { "data-testid": `column-show-hide-row-${column.id}`, sx: {
6327
+ return (jsxs(Fragment, { children: [jsx(MenuItem, Object.assign({ disableRipple: true }, rest, { sx: (theme) => (Object.assign({ alignItems: 'center', justifyContent: 'flex-start', my: 0, outline: (hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === column.id
6328
+ ? `2px dashed ${draggingBorderColor}`
6329
+ : 'none', outlineOffset: '-2px', pl: `${(column.depth + 0.5) * 2}rem`, py: '6px' }, parseFromValuesOrFunc(rest === null || rest === void 0 ? void 0 : rest.sx, theme))), children: jsx(Box, { "data-testid": `column-show-hide-row-${column.id}`, sx: {
6051
6330
  display: 'flex',
6052
6331
  flexWrap: 'nowrap',
6053
6332
  gap: '8px',
6054
- }, children: [columnDefType !== 'group' &&
6055
- enableColumnOrdering &&
6056
- !isNestedColumns &&
6057
- (columnDef.enableColumnOrdering !== false ? (jsx(MRT_GrabHandleButton, { onDragEnd: handleDragEnd, onDragStart: handleDragStart, table: table })) : (jsx(Box, { sx: { width: '28px' } }))), enableColumnPinning &&
6058
- (column.getCanPin() ? (jsx(MRT_ColumnPinningButtons, { column: column, table: table })) : (jsx(Box, { sx: { width: '70px' } }))), enableHiding ? (jsx(FormControlLabel, { checked: switchChecked, componentsProps: {
6059
- typography: {
6060
- sx: {
6061
- mb: 0,
6062
- opacity: columnDefType !== 'display' ? 1 : 0.5,
6063
- },
6333
+ }, children: enableHiding ? (jsx(FormControlLabel, { checked: switchChecked, componentsProps: {
6334
+ typography: {
6335
+ sx: {
6336
+ mb: 0,
6337
+ opacity: columnDefType !== 'display' ? 1 : 0.5,
6064
6338
  },
6065
- }, control: jsx(Tooltip, Object.assign({}, getCommonTooltipProps(), { title: localization.toggleVisibility, children: jsx(Switch, { size: "small" }) })), disabled: !column.getCanHide(), label: columnDef.header, onChange: () => handleToggleColumnHidden(column) })) : (jsx(Typography, { sx: { alignSelf: 'center' }, children: columnDef.header }))] }) })), (_b = column.columns) === null || _b === void 0 ? void 0 : _b.map((c, i) => (jsx(MRT_ShowHideColumnsMenuItems, { allColumns: allColumns, column: c, hoveredColumn: hoveredColumn, isNestedColumns: isNestedColumns, setHoveredColumn: setHoveredColumn, table: table }, `${i}-${c.id}`)))] }));
6339
+ },
6340
+ }, control: jsx(Tooltip, Object.assign({}, getCommonTooltipProps(), { title: localization.toggleVisibility, children: jsx(Switch, { size: "small" }) })), disabled: !column.getCanHide(), label: columnDef.header, onChange: () => handleToggleColumnHidden(column) })) : (jsx(Typography, { sx: { alignSelf: 'center' }, children: columnDef.header })) }) })), (_b = column.columns) === null || _b === void 0 ? void 0 : _b.map((c, i) => (jsx(MRT_ShowHideColumnsMenuItems, { allColumns: allColumns, column: c, hoveredColumn: hoveredColumn, isNestedColumns: isNestedColumns, setHoveredColumn: setHoveredColumn, table: table }, `${i}-${c.id}`)))] }));
6066
6341
  };
6067
6342
 
6068
6343
  const MRT_ShowHideColumnsMenu = (_a) => {
6069
6344
  var { anchorEl, setAnchorEl, table } = _a, rest = __rest(_a, ["anchorEl", "setAnchorEl", "table"]);
6070
- const { getAllColumns, getAllLeafColumns, getCenterLeafColumns, getIsAllColumnsVisible, getIsSomeColumnsPinned, getIsSomeColumnsVisible, getLeftLeafColumns, getRightLeafColumns, getState, initialState, options: { enableColumnOrdering, enableColumnPinning, enableHiding, localization, mrtTheme: { menuBackgroundColor }, }, } = table;
6071
- const { columnOrder, columnPinning, density } = getState();
6345
+ const { getAllColumns, getAllLeafColumns, getCenterLeafColumns, getIsAllColumnsVisible, getIsSomeColumnsVisible, getLeftLeafColumns, getRightLeafColumns, getState, options: { enableHiding, localization, mrtTheme: { menuBackgroundColor }, }, } = table;
6346
+ const { columnOrder, columnPinning } = getState();
6347
+ const density = useMRT_SliceValue(table._uiStore, (s) => s.density);
6072
6348
  const handleToggleAllColumns = (value) => {
6073
6349
  const updates = getAllLeafColumns()
6074
6350
  .filter((column) => column.columnDef.enableHiding !== false)
@@ -6098,8 +6374,6 @@ const MRT_ShowHideColumnsMenu = (_a) => {
6098
6374
  getRightLeafColumns(),
6099
6375
  ]);
6100
6376
  const isNestedColumns = allColumns.some((col) => col.columnDef.columnDefType === 'group');
6101
- const hasColumnOrderChanged = useMemo(() => columnOrder.length !== initialState.columnOrder.length ||
6102
- !columnOrder.every((column, index) => column === initialState.columnOrder[index]), [columnOrder, initialState.columnOrder]);
6103
6377
  const [hoveredColumn, setHoveredColumn] = useState(null);
6104
6378
  return (jsxs(Menu, Object.assign({ MenuListProps: {
6105
6379
  dense: density === 'compact',
@@ -6111,7 +6385,7 @@ const MRT_ShowHideColumnsMenu = (_a) => {
6111
6385
  justifyContent: 'space-between',
6112
6386
  p: '0.5rem',
6113
6387
  pt: 0,
6114
- }, children: [enableHiding && (jsx(Button, { disabled: !getIsSomeColumnsVisible(), onClick: () => handleToggleAllColumns(false), children: localization.hideAll })), enableColumnOrdering && (jsx(Button, { onClick: () => table.setColumnOrder(getDefaultColumnOrderIds(table.options, true)), disabled: !hasColumnOrderChanged, children: localization.resetOrder })), enableColumnPinning && (jsx(Button, { disabled: !getIsSomeColumnsPinned(), onClick: () => table.resetColumnPinning(true), children: localization.unpinAll })), enableHiding && (jsx(Button, { disabled: getIsAllColumnsVisible(), onClick: () => handleToggleAllColumns(true), children: localization.showAll }))] }), jsx(Divider, {}), allColumns.map((column, index) => (jsx(MRT_ShowHideColumnsMenuItems, { allColumns: allColumns, column: column, hoveredColumn: hoveredColumn, isNestedColumns: isNestedColumns, setHoveredColumn: setHoveredColumn, table: table }, `${index}-${column.id}`)))] })));
6388
+ }, children: [enableHiding && (jsx(Button, { disabled: !getIsSomeColumnsVisible(), onClick: () => handleToggleAllColumns(false), children: localization.hideAll })), enableHiding && (jsx(Button, { disabled: getIsAllColumnsVisible(), onClick: () => handleToggleAllColumns(true), children: localization.showAll }))] }), jsx(Divider, {}), allColumns.map((column, index) => (jsx(MRT_ShowHideColumnsMenuItems, { allColumns: allColumns, column: column, hoveredColumn: hoveredColumn, isNestedColumns: isNestedColumns, setHoveredColumn: setHoveredColumn, table: table }, `${index}-${column.id}`)))] })));
6115
6389
  };
6116
6390
 
6117
6391
  const MRT_ShowHideColumnsButton = (_a) => {
@@ -6165,8 +6439,8 @@ const getDensityOptions = ({ icons: { DensityLargeIcon, DensityMediumIcon, Densi
6165
6439
 
6166
6440
  const MRT_ToggleDensePaddingMenu = (_a) => {
6167
6441
  var { anchorEl, setAnchorEl, table } = _a, rest = __rest(_a, ["anchorEl", "setAnchorEl", "table"]);
6168
- const { getState, options: { icons, localization }, setDensity, } = table;
6169
- const { density } = getState();
6442
+ const { options: { icons, localization }, setDensity, } = table;
6443
+ const density = useMRT_SliceValue(table._uiStore, (s) => s.density);
6170
6444
  const handleCloseMenu = () => {
6171
6445
  setAnchorEl(null);
6172
6446
  };
@@ -6194,8 +6468,8 @@ const MRT_ToggleDensePaddingMenu = (_a) => {
6194
6468
  const MRT_ToggleDensePaddingButton = (_a) => {
6195
6469
  var _b;
6196
6470
  var { table } = _a, rest = __rest(_a, ["table"]);
6197
- const { getState, options: { icons: { DensityLargeIcon, DensityMediumIcon, DensitySmallIcon }, localization, }, } = table;
6198
- const { density } = getState();
6471
+ const { options: { icons: { DensityLargeIcon, DensityMediumIcon, DensitySmallIcon }, localization, }, } = table;
6472
+ const density = useMRT_SliceValue(table._uiStore, (s) => s.density);
6199
6473
  const [anchorEl, setAnchorEl] = useState(null);
6200
6474
  const handleOpenMenu = (event) => {
6201
6475
  setAnchorEl(event.currentTarget);
@@ -6211,8 +6485,8 @@ const MRT_ToggleDensePaddingButton = (_a) => {
6211
6485
  const MRT_ToggleFiltersButton = (_a) => {
6212
6486
  var _b;
6213
6487
  var { table } = _a, rest = __rest(_a, ["table"]);
6214
- const { getState, options: { icons: { FilterListIcon, FilterListOffIcon }, localization, }, setShowColumnFilters, } = table;
6215
- const { showColumnFilters } = getState();
6488
+ const { options: { icons: { FilterListIcon, FilterListOffIcon }, localization, }, setShowColumnFilters, } = table;
6489
+ const showColumnFilters = useMRT_SliceValue(table._uiStore, (s) => s.showColumnFilters);
6216
6490
  const handleToggleShowFilters = () => {
6217
6491
  setShowColumnFilters(!showColumnFilters);
6218
6492
  };
@@ -6223,7 +6497,8 @@ const MRT_ToggleGlobalFilterButton = (_a) => {
6223
6497
  var _b, _c;
6224
6498
  var { table } = _a, rest = __rest(_a, ["table"]);
6225
6499
  const { getState, options: { icons: { SearchIcon, SearchOffIcon }, localization, }, refs: { searchInputRef }, setShowGlobalFilter, } = table;
6226
- const { globalFilter, showGlobalFilter } = getState();
6500
+ const { globalFilter } = getState();
6501
+ const showGlobalFilter = useMRT_SliceValue(table._uiStore, (s) => s.showGlobalFilter);
6227
6502
  const handleToggleSearch = () => {
6228
6503
  setShowGlobalFilter(!showGlobalFilter);
6229
6504
  queueMicrotask(() => { var _a; return (_a = searchInputRef.current) === null || _a === void 0 ? void 0 : _a.focus(); });
@@ -6278,7 +6553,7 @@ const MRT_TopToolbar = ({ table, }) => {
6278
6553
  : undefined,
6279
6554
  table,
6280
6555
  };
6281
- return (jsxs(Box, Object.assign({}, toolbarProps, { ref: (ref) => {
6556
+ return (jsxs(Box, Object.assign({ "data-testid": "top-toolbar" }, toolbarProps, { ref: (ref) => {
6282
6557
  topToolbarRef.current = ref;
6283
6558
  if (toolbarProps === null || toolbarProps === void 0 ? void 0 : toolbarProps.ref) {
6284
6559
  // @ts-expect-error
@@ -6294,23 +6569,30 @@ const MRT_TopToolbar = ({ table, }) => {
6294
6569
  px: '0.5rem',
6295
6570
  width: '100%',
6296
6571
  position: 'relative',
6297
- }, children: [enableGlobalFilter && positionGlobalFilter === 'left' && (jsx(MRT_GlobalFilterTextField, Object.assign({}, globalFilterProps))), jsxs(Fragment, { children: [enableGlobalFilter && positionGlobalFilter === 'left' && (jsx(MRT_GlobalFilterTextField, Object.assign({}, globalFilterProps))), enableToolbarInternalActions ? (jsxs(Box, { sx: {
6572
+ }, children: [jsxs(Fragment, { children: [enableGlobalFilter && positionGlobalFilter === 'left' && (jsx(MRT_GlobalFilterTextField, Object.assign({}, globalFilterProps))), enableToolbarInternalActions ? (jsxs(Box, { sx: {
6298
6573
  alignItems: 'center',
6299
6574
  display: 'flex',
6300
6575
  flexWrap: 'wrap-reverse',
6301
6576
  gap: '0.5rem',
6302
- justifyContent: 'flex-start',
6303
- width: '100%',
6304
- }, children: [enableGlobalFilter && positionGlobalFilter === 'right' && (jsx(MRT_GlobalFilterTextField, Object.assign({}, globalFilterProps))), (_a = renderTopToolbarCustomActions === null || renderTopToolbarCustomActions === void 0 ? void 0 : renderTopToolbarCustomActions({ table })) !== null && _a !== void 0 ? _a : jsx("span", {}), jsx(MRT_ToolbarInternalButtons, { table: table })] })) : (enableGlobalFilter &&
6305
- positionGlobalFilter === 'right' && (jsx(MRT_GlobalFilterTextField, Object.assign({}, globalFilterProps))))] }), jsx(ToolbarActions, { table: table }), jsx(MRT_TableOptions, { table: table })] }), ['both', 'top'].includes(positionToolbarDropZone !== null && positionToolbarDropZone !== void 0 ? positionToolbarDropZone : '') && (jsx(MRT_ToolbarDropZone, { table: table })), enablePagination &&
6577
+ }, children: [enableGlobalFilter && positionGlobalFilter === 'right' && (jsx(MRT_GlobalFilterTextField, Object.assign({}, globalFilterProps))), jsx(MRT_ToolbarInternalButtons, { table: table })] })) : (enableGlobalFilter &&
6578
+ positionGlobalFilter === 'right' && (jsx(MRT_GlobalFilterTextField, Object.assign({}, globalFilterProps))))] }), jsx(ToolbarActions, { table: table }), jsxs(Box, { sx: {
6579
+ alignItems: 'center',
6580
+ display: 'flex',
6581
+ gap: '0.5rem',
6582
+ marginLeft: 'auto',
6583
+ }, children: [(_a = (enableToolbarInternalActions &&
6584
+ (renderTopToolbarCustomActions === null || renderTopToolbarCustomActions === void 0 ? void 0 : renderTopToolbarCustomActions({
6585
+ table,
6586
+ })))) !== null && _a !== void 0 ? _a : jsx("span", {}), jsx(MRT_TableOptions, { table: table })] })] }), ['both', 'top'].includes(positionToolbarDropZone !== null && positionToolbarDropZone !== void 0 ? positionToolbarDropZone : '') && (jsx(MRT_ToolbarDropZone, { table: table })), enablePagination &&
6306
6587
  ['both', 'top'].includes(positionPagination !== null && positionPagination !== void 0 ? positionPagination : '') && (jsx(MRT_TablePagination, { position: "top", table: table })), jsx(MRT_LinearProgressBar, { isTopToolbar: true, table: table })] })));
6307
6588
  };
6308
6589
 
6309
6590
  const MRT_CellActionMenu = (_a) => {
6310
6591
  var _b, _c;
6311
6592
  var { table } = _a, rest = __rest(_a, ["table"]);
6312
- const { getState, options: { editDisplayMode, enableClickToCopy, enableEditing, icons: { ContentCopy, EditIcon }, localization, mrtTheme: { menuBackgroundColor }, renderCellActionMenuItems, }, refs: { actionCellRef }, } = table;
6313
- const { actionCell, density } = getState();
6593
+ const { options: { editDisplayMode, enableClickToCopy, enableEditing, icons: { ContentCopy, EditIcon }, localization, mrtTheme: { menuBackgroundColor }, renderCellActionMenuItems, }, refs: { actionCellRef }, } = table;
6594
+ const density = useMRT_SliceValue(table._uiStore, (s) => s.density);
6595
+ const actionCell = useMRT_SliceValue(table._uiStore, (s) => s.actionCell);
6314
6596
  const cell = actionCell;
6315
6597
  const { row } = cell;
6316
6598
  const { column } = cell;
@@ -6357,10 +6639,10 @@ const MRT_EditCellTextField = (_a) => {
6357
6639
  const { getState, options: { createDisplayMode, editDisplayMode, muiEditTextFieldProps }, refs: { editInputRefs }, setCreatingRow, setEditingCell, setEditingRow, } = table;
6358
6640
  const { column, row } = cell;
6359
6641
  const { columnDef } = column;
6360
- const { creatingRow, editingRow } = getState();
6642
+ const { creatingRow } = getState();
6361
6643
  const { editSelectOptions, editVariant } = columnDef;
6362
6644
  const isCreating = (creatingRow === null || creatingRow === void 0 ? void 0 : creatingRow.id) === row.id;
6363
- const isEditing = (editingRow === null || editingRow === void 0 ? void 0 : editingRow.id) === row.id;
6645
+ const isEditing = useMRT_SliceValue(table._uiStore, (s) => { var _a; return ((_a = s.editingRow) === null || _a === void 0 ? void 0 : _a.id) === row.id; });
6364
6646
  const [value, setValue] = useState(() => cell.getValue());
6365
6647
  const [completesComposition, setCompletesComposition] = useState(true);
6366
6648
  const textFieldProps = Object.assign(Object.assign(Object.assign({}, parseFromValuesOrFunc(muiEditTextFieldProps, {
@@ -6453,7 +6735,8 @@ const MRT_EditRowModal = (_a) => {
6453
6735
  var _b;
6454
6736
  var { open, table } = _a, rest = __rest(_a, ["open", "table"]);
6455
6737
  const { getState, options: { localization, muiCreateRowModalProps, muiEditRowDialogProps, onCreatingRowCancel, onEditingRowCancel, renderCreateRowDialogContent, renderEditRowDialogContent, }, setCreatingRow, setEditingRow, } = table;
6456
- const { creatingRow, editingRow } = getState();
6738
+ const { creatingRow } = getState();
6739
+ const editingRow = useMRT_SliceValue(table._uiStore, (s) => s.editingRow);
6457
6740
  const row = (creatingRow !== null && creatingRow !== void 0 ? creatingRow : editingRow);
6458
6741
  const dialogProps = Object.assign(Object.assign(Object.assign({}, parseFromValuesOrFunc(muiEditRowDialogProps, { row, table })), (creatingRow &&
6459
6742
  parseFromValuesOrFunc(muiCreateRowModalProps, { row, table }))), rest);
@@ -6666,8 +6949,8 @@ const FormFieldControl = ({ columnId, columnDef, fieldConfig, table, }) => {
6666
6949
  const MRT_NewEntryForm = ({ table, }) => {
6667
6950
  var _a, _b, _c;
6668
6951
  const methods = useFormContext();
6669
- const { getState, options: { formConfig, icons: { ExpandMoreIcon }, }, } = table;
6670
- const { newEntryModal } = getState();
6952
+ const { options: { formConfig, icons: { ExpandMoreIcon }, }, } = table;
6953
+ const newEntryModal = useMRT_SliceValue(table._uiStore, (s) => s.newEntryModal);
6671
6954
  const mode = (_a = newEntryModal.mode) !== null && _a !== void 0 ? _a : 'create';
6672
6955
  // Consumer controls the entire form body — skip all field calculations.
6673
6956
  if (formConfig === null || formConfig === void 0 ? void 0 : formConfig.renderForm) {
@@ -6716,8 +6999,8 @@ const MRT_NewEntryFormActions = ({ table, }) => {
6716
6999
  var _a, _b;
6717
7000
  const methods = useFormContext();
6718
7001
  const { handleCancel, handleSave } = useMRT_NewEntryFormActions();
6719
- const { getState, options: { formConfig, localization, muiNewEntryModalProps }, } = table;
6720
- const { newEntryModal } = getState();
7002
+ const { options: { formConfig, localization, muiNewEntryModalProps }, } = table;
7003
+ const newEntryModal = useMRT_SliceValue(table._uiStore, (s) => s.newEntryModal);
6721
7004
  const mode = (_a = newEntryModal.mode) !== null && _a !== void 0 ? _a : 'create';
6722
7005
  const resolvedModalProps = muiNewEntryModalProps !== null && muiNewEntryModalProps !== void 0 ? muiNewEntryModalProps : {};
6723
7006
  const { footerProps, footerSx } = resolvedModalProps;
@@ -6738,8 +7021,8 @@ const RHF_FormProvider = (_a) => {
6738
7021
  // Place this above any component that needs form state (fields body or actions footer).
6739
7022
  const MRT_NewEntryFormProvider = ({ table, children, }) => {
6740
7023
  var _a;
6741
- const { getState, options: { formConfig }, setNewEntryModal, } = table;
6742
- const { newEntryModal } = getState();
7024
+ const { options: { formConfig }, setNewEntryModal, } = table;
7025
+ const newEntryModal = useMRT_SliceValue(table._uiStore, (s) => s.newEntryModal);
6743
7026
  // Default to 'create' when mode is not explicitly provided.
6744
7027
  const mode = (_a = newEntryModal.mode) !== null && _a !== void 0 ? _a : 'create';
6745
7028
  const defaultValues = buildDefaultValues(table, newEntryModal.initialValues, mode);
@@ -6789,11 +7072,11 @@ const clampOffset = (value, fallback) => {
6789
7072
  };
6790
7073
  const MRT_NewEntryModal = ({ table, }) => {
6791
7074
  const theme = useTheme();
6792
- const { getState, options: { formConfig, icons: { CancelIcon }, localization, muiNewEntryModalProps, }, setNewEntryModal, } = table;
7075
+ const { options: { formConfig, icons: { CancelIcon }, localization, muiNewEntryModalProps, }, setNewEntryModal, } = table;
6793
7076
  // Resolve muiNewEntryModalProps — plain object, defaults to empty object.
6794
7077
  const resolvedModalProps = muiNewEntryModalProps !== null && muiNewEntryModalProps !== void 0 ? muiNewEntryModalProps : {};
6795
7078
  const { title: titleOverride, contentContainerSx, headerSx, headerProps, bodySx, bodyProps, modalSx, modalProps, closeButtonProps, disableHeader, position, headerComponents, } = resolvedModalProps;
6796
- const { newEntryModal } = getState();
7079
+ const newEntryModal = useMRT_SliceValue(table._uiStore, (s) => s.newEntryModal);
6797
7080
  // Whether the modal was opened in edit mode — determines the title.
6798
7081
  const isEditMode = newEntryModal.mode === 'edit';
6799
7082
  const handleClose = () => {
@@ -6943,10 +7226,19 @@ const MRT_TableBodyCell = (_a) => {
6943
7226
  var _b, _c, _d, _e;
6944
7227
  var { cell, numRows, rowRef, staticColumnIndex, staticRowIndex, table, theme } = _a, rest = __rest(_a, ["cell", "numRows", "rowRef", "staticColumnIndex", "staticRowIndex", "table", "theme"]);
6945
7228
  const { getState, options: { columnResizeDirection, columnResizeMode, createDisplayMode, editDisplayMode, enableCellActions, enableClickToCopy, enableColumnOrdering, enableColumnPinning, enableGrouping, enableKeyboardShortcuts, layoutMode, mrtTheme: { draggingBorderColor }, muiSkeletonProps, muiTableBodyCellProps, }, setHoveredColumn, } = table;
6946
- const { actionCell, columnSizingInfo, creatingRow, density, draggingColumn, draggingRow, editingCell, editingRow, hoveredColumn, hoveredRow, isLoading, showSkeletons, } = getState();
7229
+ const { creatingRow, isLoading, showSkeletons } = getState();
7230
+ const density = useMRT_SliceValue(table._uiStore, (s) => s.density);
6947
7231
  const { column, row } = cell;
6948
7232
  const { columnDef } = column;
6949
7233
  const { columnDefType } = columnDef;
7234
+ const isResizingThisColumn = useMRT_SliceValue(table._uiStore, (s) => s.columnSizingInfo.isResizingColumn === column.id);
7235
+ const isEditingRow = useMRT_SliceValue(table._uiStore, (s) => { var _a; return ((_a = s.editingRow) === null || _a === void 0 ? void 0 : _a.id) === row.id; });
7236
+ const isActionCell = useMRT_SliceValue(table._uiStore, (s) => { var _a; return ((_a = s.actionCell) === null || _a === void 0 ? void 0 : _a.id) === cell.id; });
7237
+ const isEditingCell = useMRT_SliceValue(table._uiStore, (s) => { var _a; return ((_a = s.editingCell) === null || _a === void 0 ? void 0 : _a.id) === cell.id; });
7238
+ const isDraggingColumn = useMRT_SliceValue(table._dragStore, (s) => { var _a; return ((_a = s.draggingColumn) === null || _a === void 0 ? void 0 : _a.id) === column.id; });
7239
+ const isDraggingRow = useMRT_SliceValue(table._dragStore, (s) => { var _a; return ((_a = s.draggingRow) === null || _a === void 0 ? void 0 : _a.id) === row.id; });
7240
+ const isHoveredColumn = useMRT_SliceValue(table._hoverStore, (s) => { var _a; return ((_a = s.hoveredColumn) === null || _a === void 0 ? void 0 : _a.id) === column.id; });
7241
+ const isHoveredRow = useMRT_SliceValue(table._hoverStore, (s) => { var _a; return ((_a = s.hoveredRow) === null || _a === void 0 ? void 0 : _a.id) === row.id; });
6950
7242
  const args = { cell, column, row, table };
6951
7243
  const tableCellProps = Object.assign(Object.assign(Object.assign({}, parseFromValuesOrFunc(muiTableBodyCellProps, args)), parseFromValuesOrFunc(columnDef.muiTableBodyCellProps, args)), rest);
6952
7244
  const skeletonProps = parseFromValuesOrFunc(muiSkeletonProps, {
@@ -6965,14 +7257,10 @@ const MRT_TableBodyCell = (_a) => {
6965
7257
  : Math.round(Math.random() * (size - size / 3) + size / 3));
6966
7258
  }, [isLoading, showSkeletons]);
6967
7259
  const draggingBorders = useMemo(() => {
6968
- const isDraggingColumn = (draggingColumn === null || draggingColumn === void 0 ? void 0 : draggingColumn.id) === column.id;
6969
- const isHoveredColumn = (hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === column.id;
6970
- const isDraggingRow = (draggingRow === null || draggingRow === void 0 ? void 0 : draggingRow.id) === row.id;
6971
- const isHoveredRow = (hoveredRow === null || hoveredRow === void 0 ? void 0 : hoveredRow.id) === row.id;
6972
7260
  const isFirstColumn = column.getIsFirstColumn();
6973
7261
  const isLastColumn = column.getIsLastColumn();
6974
7262
  const isLastRow = numRows && staticRowIndex === numRows - 1;
6975
- const isResizingColumn = columnSizingInfo.isResizingColumn === column.id;
7263
+ const isResizingColumn = isResizingThisColumn;
6976
7264
  const showResizeBorder = isResizingColumn && columnResizeMode === 'onChange';
6977
7265
  const borderStyle = showResizeBorder
6978
7266
  ? `2px solid ${draggingBorderColor} !important`
@@ -7005,11 +7293,11 @@ const MRT_TableBodyCell = (_a) => {
7005
7293
  }
7006
7294
  : undefined;
7007
7295
  }, [
7008
- columnSizingInfo.isResizingColumn,
7009
- draggingColumn,
7010
- draggingRow,
7011
- hoveredColumn,
7012
- hoveredRow,
7296
+ isResizingThisColumn,
7297
+ isDraggingColumn,
7298
+ isDraggingRow,
7299
+ isHoveredColumn,
7300
+ isHoveredRow,
7013
7301
  staticRowIndex,
7014
7302
  ]);
7015
7303
  const isColumnPinned = enableColumnPinning &&
@@ -7018,9 +7306,7 @@ const MRT_TableBodyCell = (_a) => {
7018
7306
  const isEditable = isCellEditable({ cell, table });
7019
7307
  const isEditing = isEditable &&
7020
7308
  !['custom', 'modal'].includes(editDisplayMode) &&
7021
- (editDisplayMode === 'table' ||
7022
- (editingRow === null || editingRow === void 0 ? void 0 : editingRow.id) === row.id ||
7023
- (editingCell === null || editingCell === void 0 ? void 0 : editingCell.id) === cell.id) &&
7309
+ (editDisplayMode === 'table' || isEditingRow || isEditingCell) &&
7024
7310
  !row.getIsGrouped();
7025
7311
  const isCreating = isEditable && createDisplayMode === 'row' && (creatingRow === null || creatingRow === void 0 ? void 0 : creatingRow.id) === row.id;
7026
7312
  const showClickToCopyButton = (parseFromValuesOrFunc(enableClickToCopy, cell) === true ||
@@ -7041,12 +7327,13 @@ const MRT_TableBodyCell = (_a) => {
7041
7327
  openEditingCell({ cell, table });
7042
7328
  };
7043
7329
  const handleDragEnter = (e) => {
7044
- var _a;
7330
+ var _a, _b;
7045
7331
  (_a = tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.onDragEnter) === null || _a === void 0 ? void 0 : _a.call(tableCellProps, e);
7046
- if (enableGrouping && (hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === 'drop-zone') {
7332
+ if (enableGrouping &&
7333
+ ((_b = table._hoverStore.get().hoveredColumn) === null || _b === void 0 ? void 0 : _b.id) === 'drop-zone') {
7047
7334
  setHoveredColumn(null);
7048
7335
  }
7049
- if (enableColumnOrdering && draggingColumn) {
7336
+ if (enableColumnOrdering && table._dragStore.get().draggingColumn) {
7050
7337
  setHoveredColumn(columnDef.enableColumnOrdering !== false ? column : null);
7051
7338
  }
7052
7339
  };
@@ -7075,7 +7362,7 @@ const MRT_TableBodyCell = (_a) => {
7075
7362
  });
7076
7363
  };
7077
7364
  return (jsx(TableCell, Object.assign({ align: theme.direction === 'rtl' ? 'right' : 'left', "data-index": staticColumnIndex, "data-pinned": !!isColumnPinned || undefined, tabIndex: enableKeyboardShortcuts ? 0 : undefined }, tableCellProps, { onKeyDown: handleKeyDown, onContextMenu: handleContextMenu, onDoubleClick: handleDoubleClick, onDragEnter: handleDragEnter, onDragOver: handleDragOver, sx: (theme) => (Object.assign(Object.assign({ '&:hover': {
7078
- outline: (actionCell === null || actionCell === void 0 ? void 0 : actionCell.id) === cell.id ||
7365
+ outline: isActionCell ||
7079
7366
  (editDisplayMode === 'cell' && isEditable) ||
7080
7367
  (editDisplayMode === 'table' && (isCreating || isEditing))
7081
7368
  ? `1px solid ${theme.palette.grey[500]}`
@@ -7085,20 +7372,14 @@ const MRT_TableBodyCell = (_a) => {
7085
7372
  ? 'context-menu'
7086
7373
  : isEditable && editDisplayMode === 'cell'
7087
7374
  ? 'pointer'
7088
- : 'inherit', outline: (actionCell === null || actionCell === void 0 ? void 0 : actionCell.id) === cell.id
7375
+ : 'inherit', outline: isActionCell
7089
7376
  ? `1px solid ${theme.palette.grey[500]}`
7090
- : undefined, outlineOffset: '-1px', overflow: 'hidden', p: density === 'compact'
7091
- ? columnDefType === 'display'
7092
- ? '0 0.5rem'
7093
- : '0.5rem'
7094
- : density === 'comfortable'
7095
- ? columnDefType === 'display'
7096
- ? '0.5rem 0.75rem'
7097
- : '1rem'
7098
- : columnDefType === 'display'
7099
- ? '1rem 1.25rem'
7100
- : '1.5rem', textOverflow: columnDefType !== 'display' ? 'ellipsis' : undefined, whiteSpace: row.getIsPinned() || density === 'compact' ? 'nowrap' : 'normal' }, getCommonMRTCellStyles({
7377
+ : undefined, outlineOffset: '-1px', overflow: 'hidden', p: columnDefType === 'display'
7378
+ ? 'var(--mrt-display-cell-p)'
7379
+ : 'var(--mrt-cell-p)', textOverflow: columnDefType !== 'display' ? 'ellipsis' : undefined, whiteSpace: row.getIsPinned() || density === 'compact' ? 'nowrap' : 'normal' }, getCommonMRTCellStyles({
7101
7380
  column,
7381
+ isDraggingColumn,
7382
+ isHoveredColumn,
7102
7383
  table,
7103
7384
  tableCellProps,
7104
7385
  theme,
@@ -7142,13 +7423,17 @@ const MRT_TableBodyRow = (_a) => {
7142
7423
  var _b, _c, _d, _f;
7143
7424
  var { columnVirtualizer, numRows, pinnedRowIds, row, rowVirtualizer, staticRowIndex, table, theme, virtualRow } = _a, rest = __rest(_a, ["columnVirtualizer", "numRows", "pinnedRowIds", "row", "rowVirtualizer", "staticRowIndex", "table", "theme", "virtualRow"]);
7144
7425
  const { getState, options: { enableRowOrdering, enableRowPinning, enableStickyFooter, enableStickyHeader, layoutMode, memoMode, mrtTheme: { baseBackgroundColor, pinnedRowBackgroundColor, selectedRowBackgroundColor, }, muiTableBodyRowProps, renderDetailPanel, rowPinningDisplayMode, }, refs: { tableFooterRef, tableHeadRef }, setHoveredRow, } = table;
7145
- const { density, draggingColumn, draggingRow, editingCell, editingRow, hoveredRow, rowPinning, } = getState();
7426
+ const { rowPinning } = getState();
7427
+ const density = useMRT_SliceValue(table._uiStore, (s) => s.density);
7428
+ const editingCell = useMRT_SliceValue(table._uiStore, (s) => s.editingCell);
7429
+ const isEditingRow = useMRT_SliceValue(table._uiStore, (s) => { var _a; return ((_a = s.editingRow) === null || _a === void 0 ? void 0 : _a.id) === row.id; });
7430
+ const isDraggingRow = useMRT_SliceValue(table._dragStore, (s) => { var _a; return ((_a = s.draggingRow) === null || _a === void 0 ? void 0 : _a.id) === row.id; });
7431
+ const isHoveredRow = useMRT_SliceValue(table._hoverStore, (s) => { var _a; return ((_a = s.hoveredRow) === null || _a === void 0 ? void 0 : _a.id) === row.id; });
7432
+ const isAnyDragging = useMRT_SliceValue(table._dragStore, (s) => !!s.draggingColumn || !!s.draggingRow);
7146
7433
  const visibleCells = row.getVisibleCells();
7147
7434
  const { virtualColumns, virtualPaddingLeft, virtualPaddingRight } = columnVirtualizer !== null && columnVirtualizer !== void 0 ? columnVirtualizer : {};
7148
7435
  const isRowSelected = getIsRowSelected({ row, table });
7149
7436
  const isRowPinned = enableRowPinning && row.getIsPinned();
7150
- const isDraggingRow = (draggingRow === null || draggingRow === void 0 ? void 0 : draggingRow.id) === row.id;
7151
- const isHoveredRow = (hoveredRow === null || hoveredRow === void 0 ? void 0 : hoveredRow.id) === row.id;
7152
7437
  const tableRowProps = Object.assign(Object.assign({}, parseFromValuesOrFunc(muiTableBodyRowProps, {
7153
7438
  row,
7154
7439
  staticRowIndex,
@@ -7174,7 +7459,7 @@ const MRT_TableBodyRow = (_a) => {
7174
7459
  parseInt((_f = (_d = tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.style) === null || _d === void 0 ? void 0 : _d.height) !== null && _f !== void 0 ? _f : sx === null || sx === void 0 ? void 0 : sx.height, 10) || undefined;
7175
7460
  const rowHeight = customRowHeight || defaultRowHeight;
7176
7461
  const handleDragEnter = (_e) => {
7177
- if (enableRowOrdering && draggingRow) {
7462
+ if (enableRowOrdering && table._dragStore.get().draggingRow) {
7178
7463
  setHoveredRow(row);
7179
7464
  }
7180
7465
  };
@@ -7234,13 +7519,12 @@ const MRT_TableBodyRow = (_a) => {
7234
7519
  table,
7235
7520
  theme,
7236
7521
  };
7237
- const key = `${cell.id}-${staticRowIndex}`;
7522
+ const key = cell.id;
7238
7523
  return cell ? (memoMode === 'cells' &&
7239
7524
  cell.column.columnDef.columnDefType === 'data' &&
7240
- !draggingColumn &&
7241
- !draggingRow &&
7525
+ !isAnyDragging &&
7242
7526
  (editingCell === null || editingCell === void 0 ? void 0 : editingCell.id) !== cell.id &&
7243
- (editingRow === null || editingRow === void 0 ? void 0 : editingRow.id) !== row.id ? (jsx(Memo_MRT_TableBodyCell, Object.assign({}, props), key)) : (jsx(MRT_TableBodyCell, Object.assign({}, props), key))) : null;
7527
+ !isEditingRow ? (jsx(Memo_MRT_TableBodyCell, Object.assign({}, props), key)) : (jsx(MRT_TableBodyCell, Object.assign({}, props), key))) : null;
7244
7528
  }), virtualPaddingRight ? (jsx("td", { style: { display: 'flex', width: virtualPaddingRight } })) : null] })), renderDetailPanel && !row.getIsGrouped() && (jsx(MRT_TableDetailPanel, { parentRowRef: rowRef, row: row, rowVirtualizer: rowVirtualizer, staticRowIndex: staticRowIndex, table: table, virtualRow: virtualRow }))] }));
7245
7529
  };
7246
7530
  const Memo_MRT_TableBodyRow = memo(MRT_TableBodyRow, (prev, next) => prev.row === next.row && prev.staticRowIndex === next.staticRowIndex);
@@ -7318,7 +7602,7 @@ const MRT_TableBody = (_a) => {
7318
7602
  staticRowIndex, virtualRow: rowVirtualizer
7319
7603
  ? rowOrVirtualRow
7320
7604
  : undefined });
7321
- const key = `${row.id}-${row.index}`;
7605
+ const key = row.id;
7322
7606
  return memoMode === 'rows' ? (jsx(Memo_MRT_TableBodyRow, Object.assign({}, props), key)) : (jsx(MRT_TableBodyRow, Object.assign({}, props), key));
7323
7607
  }) }))) })), !(rowPinningDisplayMode === null || rowPinningDisplayMode === void 0 ? void 0 : rowPinningDisplayMode.includes('sticky')) &&
7324
7608
  getIsSomeRowsPinned('bottom') && (jsx(TableBody, Object.assign({}, tableBodyProps, { sx: (theme) => (Object.assign({ bottom: tableFooterHeight - 1, display: (layoutMode === null || layoutMode === void 0 ? void 0 : layoutMode.startsWith('grid')) ? 'grid' : undefined, position: 'sticky', zIndex: 1 }, parseFromValuesOrFunc(tableBodyProps === null || tableBodyProps === void 0 ? void 0 : tableBodyProps.sx, theme))), children: getBottomRows().map((row, staticRowIndex) => {
@@ -7333,11 +7617,12 @@ const MRT_TableFooterCell = (_a) => {
7333
7617
  var _b, _c, _d;
7334
7618
  var { footer, staticColumnIndex, table } = _a, rest = __rest(_a, ["footer", "staticColumnIndex", "table"]);
7335
7619
  const theme = useTheme();
7336
- const { getState, options: { enableColumnPinning, muiTableFooterCellProps, enableKeyboardShortcuts, }, } = table;
7337
- const { density } = getState();
7620
+ const { options: { enableColumnPinning, muiTableFooterCellProps, enableKeyboardShortcuts, }, } = table;
7338
7621
  const { column } = footer;
7339
7622
  const { columnDef } = column;
7340
7623
  const { columnDefType } = columnDef;
7624
+ const isDraggingColumn = useMRT_SliceValue(table._dragStore, (s) => { var _a; return ((_a = s.draggingColumn) === null || _a === void 0 ? void 0 : _a.id) === column.id; });
7625
+ const isHoveredColumn = useMRT_SliceValue(table._hoverStore, (s) => { var _a; return ((_a = s.hoveredColumn) === null || _a === void 0 ? void 0 : _a.id) === column.id; });
7341
7626
  const isColumnPinned = enableColumnPinning &&
7342
7627
  columnDef.columnDefType !== 'group' &&
7343
7628
  column.getIsPinned();
@@ -7356,13 +7641,11 @@ const MRT_TableFooterCell = (_a) => {
7356
7641
  ? 'center'
7357
7642
  : theme.direction === 'rtl'
7358
7643
  ? 'right'
7359
- : 'left', colSpan: footer.colSpan, "data-index": staticColumnIndex, "data-pinned": !!isColumnPinned || undefined, tabIndex: enableKeyboardShortcuts ? 0 : undefined, variant: "footer" }, tableCellProps, { onKeyDown: handleKeyDown, sx: (theme) => (Object.assign(Object.assign({ fontWeight: 'bold', p: density === 'compact'
7360
- ? '0.5rem'
7361
- : density === 'comfortable'
7362
- ? '1rem'
7363
- : '1.5rem', verticalAlign: 'top' }, getCommonMRTCellStyles({
7644
+ : 'left', colSpan: footer.colSpan, "data-index": staticColumnIndex, "data-pinned": !!isColumnPinned || undefined, tabIndex: enableKeyboardShortcuts ? 0 : undefined, variant: "footer" }, tableCellProps, { onKeyDown: handleKeyDown, sx: (theme) => (Object.assign(Object.assign({ fontWeight: 'bold', p: 'var(--mrt-cell-p)', verticalAlign: 'top' }, getCommonMRTCellStyles({
7364
7645
  column,
7365
7646
  header: footer,
7647
+ isDraggingColumn,
7648
+ isHoveredColumn,
7366
7649
  table,
7367
7650
  tableCellProps,
7368
7651
  theme,
@@ -7437,7 +7720,9 @@ const MRT_ColumnActionMenu = (_a) => {
7437
7720
  const { getAllLeafColumns, getState, options: { columnFilterDisplayMode, columnFilterModeOptions, enableColumnFilterModes, enableColumnFilters, enableColumnPinning, enableColumnResizing, enableGrouping, enableHiding, enableSorting, enableSortingRemoval, icons: { ClearAllIcon, DynamicFeedIcon, FilterListIcon, FilterListOffIcon, PushPinIcon, RestartAltIcon, SortIcon, ViewColumnIcon, VisibilityOffIcon, }, localization, mrtTheme: { menuBackgroundColor }, renderColumnActionsMenuItems, }, refs: { filterInputRefs }, setColumnFilterFns, setColumnOrder, setColumnSizingInfo, setShowColumnFilters, } = table;
7438
7721
  const { column } = header;
7439
7722
  const { columnDef } = column;
7440
- const { columnSizing, columnVisibility, density, showColumnFilters } = getState();
7723
+ const { columnSizing, columnVisibility } = getState();
7724
+ const density = useMRT_SliceValue(table._uiStore, (s) => s.density);
7725
+ const showColumnFilters = useMRT_SliceValue(table._uiStore, (s) => s.showColumnFilters);
7441
7726
  const columnFilterValue = column.getFilterValue();
7442
7727
  const [filterMenuAnchorEl, setFilterMenuAnchorEl] = useState(null);
7443
7728
  const handleClearSort = () => {
@@ -7634,7 +7919,7 @@ const MRT_TableHeadCellGrabHandle = (_a) => {
7634
7919
  var { column, table, tableHeadCellRef } = _a, rest = __rest(_a, ["column", "table", "tableHeadCellRef"]);
7635
7920
  const { getState, options: { enableColumnOrdering, muiColumnDragHandleProps }, setColumnOrder, setColumnPinning, setDraggingColumn, setHoveredColumn, } = table;
7636
7921
  const { columnDef } = column;
7637
- const { columnOrder, draggingColumn, hoveredColumn } = getState();
7922
+ const { columnOrder } = getState();
7638
7923
  const iconButtonProps = Object.assign(Object.assign(Object.assign({}, parseFromValuesOrFunc(muiColumnDragHandleProps, { column, table })), parseFromValuesOrFunc(columnDef.muiColumnDragHandleProps, {
7639
7924
  column,
7640
7925
  table,
@@ -7653,6 +7938,8 @@ const MRT_TableHeadCellGrabHandle = (_a) => {
7653
7938
  const handleDragEnd = (event) => {
7654
7939
  var _a;
7655
7940
  (_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.onDragEnd) === null || _a === void 0 ? void 0 : _a.call(iconButtonProps, event);
7941
+ const { hoveredColumn } = table._hoverStore.get();
7942
+ const { draggingColumn } = table._dragStore.get();
7656
7943
  if ((hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === 'drop-zone') {
7657
7944
  column.toggleGrouping();
7658
7945
  }
@@ -7673,30 +7960,110 @@ const MRT_TableHeadCellGrabHandle = (_a) => {
7673
7960
  };
7674
7961
 
7675
7962
  const MRT_TableHeadCellResizeHandle = (_a) => {
7676
- var _b;
7677
7963
  var { header, table } = _a, rest = __rest(_a, ["header", "table"]);
7678
- const { getState, options: { columnResizeDirection, columnResizeMode }, setColumnSizingInfo, } = table;
7679
- const { density } = getState();
7964
+ const { options: { columnResizeDirection }, refs: { isResizingRef, resizeIndicatorRef, tableContainerRef, tableHeadCellRefs, tableRef, }, setColumnSizing, setColumnSizingInfo, } = table;
7965
+ const density = useMRT_SliceValue(table._uiStore, (s) => s.density);
7680
7966
  const { column } = header;
7681
- const handler = header.getResizeHandler();
7682
7967
  const mx = density === 'compact'
7683
7968
  ? '-8px'
7684
7969
  : density === 'comfortable'
7685
7970
  ? '-16px'
7686
7971
  : '-24px';
7687
7972
  const lr = column.columnDef.columnDefType === 'display' ? '4px' : '0';
7973
+ // Drives the resize purely through refs/DOM writes (CSS vars + the indicator line) so
7974
+ // dragging causes zero React renders; the only state write is the commit on release.
7975
+ const startResize = useCallback((startX) => {
7976
+ var _a, _b;
7977
+ const tableEl = tableRef.current;
7978
+ const containerEl = tableContainerRef.current;
7979
+ const indicatorEl = resizeIndicatorRef.current;
7980
+ const startSize = column.getSize();
7981
+ const dir = columnResizeDirection === 'rtl' ? -1 : 1;
7982
+ const minSize = (_a = column.columnDef.minSize) !== null && _a !== void 0 ? _a : 40;
7983
+ const maxSize = (_b = column.columnDef.maxSize) !== null && _b !== void 0 ? _b : 1000;
7984
+ let size = startSize;
7985
+ // Read the header cell's own rendered edge (rather than deriving a position from
7986
+ // clientX/scrollLeft) so the indicator always matches the real column border, even
7987
+ // if the browser clamps scrollLeft mid-drag because the table's scrollWidth shrank.
7988
+ const updateIndicator = () => {
7989
+ var _a;
7990
+ const cellEl = (_a = tableHeadCellRefs.current) === null || _a === void 0 ? void 0 : _a[column.id];
7991
+ if (!indicatorEl || !containerEl || !cellEl)
7992
+ return;
7993
+ const containerRect = containerEl.getBoundingClientRect();
7994
+ const cellRect = cellEl.getBoundingClientRect();
7995
+ const edge = columnResizeDirection === 'rtl' ? cellRect.left : cellRect.right;
7996
+ const x = edge - containerRect.left + containerEl.scrollLeft;
7997
+ indicatorEl.style.display = 'block';
7998
+ indicatorEl.style.transform = `translateX(${x}px)`;
7999
+ };
8000
+ isResizingRef.current = column.id;
8001
+ containerEl === null || containerEl === void 0 ? void 0 : containerEl.setAttribute('data-mrt-resizing', 'true');
8002
+ document.body.style.cursor = 'col-resize';
8003
+ document.body.style.userSelect = 'none';
8004
+ updateIndicator();
8005
+ const handleMove = (clientX) => {
8006
+ size = Math.min(Math.max(startSize + dir * (clientX - startX), minSize), maxSize);
8007
+ if (tableEl) {
8008
+ tableEl.style.setProperty(`--header-${parseCSSVarId(header.id)}-size`, `${size}`);
8009
+ tableEl.style.setProperty(`--col-${parseCSSVarId(column.id)}-size`, `${size}`);
8010
+ }
8011
+ updateIndicator();
8012
+ };
8013
+ const handleMouseMove = (e) => handleMove(e.clientX);
8014
+ const handleTouchMove = (e) => {
8015
+ var _a;
8016
+ const touchX = (_a = e.touches[0]) === null || _a === void 0 ? void 0 : _a.clientX;
8017
+ if (touchX == null)
8018
+ return;
8019
+ e.preventDefault();
8020
+ handleMove(touchX);
8021
+ };
8022
+ const handleEnd = () => {
8023
+ document.removeEventListener('mousemove', handleMouseMove);
8024
+ document.removeEventListener('mouseup', handleEnd);
8025
+ document.removeEventListener('touchmove', handleTouchMove);
8026
+ document.removeEventListener('touchend', handleEnd);
8027
+ isResizingRef.current = false;
8028
+ containerEl === null || containerEl === void 0 ? void 0 : containerEl.removeAttribute('data-mrt-resizing');
8029
+ document.body.style.cursor = '';
8030
+ document.body.style.userSelect = '';
8031
+ if (indicatorEl)
8032
+ indicatorEl.style.display = 'none';
8033
+ setColumnSizing((old) => (Object.assign(Object.assign({}, old), { [column.id]: size })));
8034
+ };
8035
+ document.addEventListener('mousemove', handleMouseMove);
8036
+ document.addEventListener('mouseup', handleEnd);
8037
+ document.addEventListener('touchmove', handleTouchMove, {
8038
+ passive: false,
8039
+ });
8040
+ document.addEventListener('touchend', handleEnd);
8041
+ }, [
8042
+ column,
8043
+ columnResizeDirection,
8044
+ header.id,
8045
+ isResizingRef,
8046
+ resizeIndicatorRef,
8047
+ setColumnSizing,
8048
+ tableContainerRef,
8049
+ tableHeadCellRefs,
8050
+ tableRef,
8051
+ ]);
7688
8052
  return (jsx(Box, { className: "Mui-TableHeadCell-ResizeHandle-Wrapper", onDoubleClick: () => {
7689
8053
  setColumnSizingInfo((old) => (Object.assign(Object.assign({}, old), { isResizingColumn: false })));
7690
8054
  column.resetSize();
7691
- }, onMouseDown: handler, onTouchStart: handler, style: {
7692
- transform: column.getIsResizing() && columnResizeMode === 'onEnd'
7693
- ? `translateX(${(columnResizeDirection === 'rtl' ? -1 : 1) *
7694
- ((_b = getState().columnSizingInfo.deltaOffset) !== null && _b !== void 0 ? _b : 0)}px)`
7695
- : undefined,
8055
+ }, onMouseDown: (e) => {
8056
+ e.preventDefault();
8057
+ startResize(e.clientX);
8058
+ }, onTouchStart: (e) => {
8059
+ var _a;
8060
+ const touchX = (_a = e.touches[0]) === null || _a === void 0 ? void 0 : _a.clientX;
8061
+ if (touchX != null)
8062
+ startResize(touchX);
7696
8063
  }, sx: (theme) => ({
7697
8064
  '&:active > hr': {
7698
8065
  backgroundColor: theme.palette.info.main,
7699
- opacity: header.subHeaders.length || columnResizeMode === 'onEnd' ? 1 : 0,
8066
+ opacity: 1,
7700
8067
  },
7701
8068
  cursor: 'col-resize',
7702
8069
  left: columnResizeDirection === 'rtl' ? lr : undefined,
@@ -7748,12 +8115,16 @@ const MRT_TableHeadCell = (_a) => {
7748
8115
  var _b, _c, _d;
7749
8116
  var { columnVirtualizer, header, staticColumnIndex, table } = _a, rest = __rest(_a, ["columnVirtualizer", "header", "staticColumnIndex", "table"]);
7750
8117
  const theme = useTheme();
7751
- const { getState, options: { columnResizeDirection, columnResizeMode, enableKeyboardShortcuts, enableColumnActions, enableColumnDragging, enableColumnOrdering, enableColumnPinning, enableGrouping, enableMultiSort, layoutMode, mrtTheme: { draggingBorderColor }, muiTableHeadCellProps, }, refs: { tableHeadCellRefs }, setHoveredColumn, } = table;
8118
+ const { getState, options: { columnResizeDirection, columnResizeMode, enableKeyboardShortcuts, enableColumnActions, enableColumnDragging, enableColumnOrdering, enableColumnPinning, enableGrouping, enableMultiSort, layoutMode, mrtTheme: { draggingBorderColor }, muiTableHeadCellProps, }, refs: { isResizingRef, tableHeadCellRefs }, setHoveredColumn, } = table;
7752
8119
  const [isColumnCellHovered, setIsColumnCellHovered] = useState(false);
7753
- const { columnSizingInfo, density, draggingColumn, grouping, hoveredColumn, showColumnFilters, } = getState();
8120
+ const { grouping } = getState();
8121
+ const showColumnFilters = useMRT_SliceValue(table._uiStore, (s) => s.showColumnFilters);
7754
8122
  const { column } = header;
7755
8123
  const { columnDef } = column;
7756
8124
  const { columnDefType } = columnDef;
8125
+ const isResizingThisColumn = useMRT_SliceValue(table._uiStore, (s) => s.columnSizingInfo.isResizingColumn === column.id);
8126
+ const isDraggingColumn = useMRT_SliceValue(table._dragStore, (s) => { var _a; return ((_a = s.draggingColumn) === null || _a === void 0 ? void 0 : _a.id) === column.id; });
8127
+ const isHoveredColumn = useMRT_SliceValue(table._hoverStore, (s) => { var _a; return ((_a = s.hoveredColumn) === null || _a === void 0 ? void 0 : _a.id) === column.id; });
7757
8128
  const tableCellProps = Object.assign(Object.assign(Object.assign({}, parseFromValuesOrFunc(muiTableHeadCellProps, { column, table })), parseFromValuesOrFunc(columnDef.muiTableHeadCellProps, {
7758
8129
  column,
7759
8130
  table,
@@ -7781,14 +8152,14 @@ const MRT_TableHeadCell = (_a) => {
7781
8152
  return pl;
7782
8153
  }, [showColumnActions, showDragHandle]);
7783
8154
  const draggingBorders = useMemo(() => {
7784
- const showResizeBorder = columnSizingInfo.isResizingColumn === column.id &&
8155
+ const showResizeBorder = isResizingThisColumn &&
7785
8156
  columnResizeMode === 'onChange' &&
7786
8157
  !header.subHeaders.length;
7787
8158
  const borderStyle = showResizeBorder
7788
8159
  ? `2px solid ${draggingBorderColor} !important`
7789
- : (draggingColumn === null || draggingColumn === void 0 ? void 0 : draggingColumn.id) === column.id
8160
+ : isDraggingColumn
7790
8161
  ? `1px dashed ${theme.palette.grey[500]}`
7791
- : (hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === column.id
8162
+ : isHoveredColumn
7792
8163
  ? `2px dashed ${draggingBorderColor}`
7793
8164
  : undefined;
7794
8165
  if (showResizeBorder) {
@@ -7803,12 +8174,16 @@ const MRT_TableHeadCell = (_a) => {
7803
8174
  borderTop: borderStyle,
7804
8175
  }
7805
8176
  : undefined;
7806
- }, [draggingColumn, hoveredColumn, columnSizingInfo.isResizingColumn]);
8177
+ }, [isDraggingColumn, isHoveredColumn, isResizingThisColumn]);
7807
8178
  const handleDragEnter = (_e) => {
7808
- if (enableGrouping && (hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === 'drop-zone') {
8179
+ var _a;
8180
+ if (enableGrouping &&
8181
+ ((_a = table._hoverStore.get().hoveredColumn) === null || _a === void 0 ? void 0 : _a.id) === 'drop-zone') {
7809
8182
  setHoveredColumn(null);
7810
8183
  }
7811
- if (enableColumnOrdering && draggingColumn && columnDefType !== 'group') {
8184
+ if (enableColumnOrdering &&
8185
+ table._dragStore.get().draggingColumn &&
8186
+ columnDefType !== 'group') {
7812
8187
  setHoveredColumn(columnDef.enableColumnOrdering !== false ? column : null);
7813
8188
  }
7814
8189
  };
@@ -7829,7 +8204,7 @@ const MRT_TableHeadCell = (_a) => {
7829
8204
  };
7830
8205
  // Toggle the column cell hover state, but only when not actively resizing a column
7831
8206
  const handleColumnCellHoverToggle = (isHovered) => {
7832
- if (!columnSizingInfo.isResizingColumn) {
8207
+ if (!isResizingRef.current) {
7833
8208
  setIsColumnCellHovered(isHovered);
7834
8209
  }
7835
8210
  };
@@ -7857,25 +8232,17 @@ const MRT_TableHeadCell = (_a) => {
7857
8232
  ? column.getIsSorted() === 'asc'
7858
8233
  ? 'ascending'
7859
8234
  : 'descending'
7860
- : 'none', colSpan: header.colSpan, "data-can-sort": column.getCanSort() || undefined, "data-index": staticColumnIndex, "data-pinned": !!isColumnPinned || undefined, "data-testid": `header-cell-${column.id}`, "data-sort": column.getIsSorted() || undefined, onDragEnter: handleDragEnter, onDragOver: handleDragOver, onMouseEnter: () => handleColumnCellHoverToggle(true), onMouseLeave: () => handleColumnCellHoverToggle(false), ref: handleRef, tabIndex: enableKeyboardShortcuts ? 0 : undefined }, tableCellProps, { onKeyDown: handleKeyDown, sx: (theme) => (Object.assign(Object.assign({ flexDirection: (layoutMode === null || layoutMode === void 0 ? void 0 : layoutMode.startsWith('grid')) ? 'column' : undefined, fontWeight: 'bold', overflow: 'hidden', color: theme.palette.text.primary, p: density === 'compact'
7861
- ? '0.5rem'
7862
- : density === 'comfortable'
7863
- ? columnDefType === 'display'
7864
- ? '0.75rem'
7865
- : '1rem'
7866
- : columnDefType === 'display'
7867
- ? '1rem 1.25rem'
7868
- : '1.5rem', pb: columnDefType === 'display'
8235
+ : 'none', colSpan: header.colSpan, "data-can-sort": column.getCanSort() || undefined, "data-index": staticColumnIndex, "data-pinned": !!isColumnPinned || undefined, "data-testid": `header-cell-${column.id}`, "data-sort": column.getIsSorted() || undefined, onDragEnter: handleDragEnter, onDragOver: handleDragOver, onMouseEnter: () => handleColumnCellHoverToggle(true), onMouseLeave: () => handleColumnCellHoverToggle(false), ref: handleRef, tabIndex: enableKeyboardShortcuts ? 0 : undefined }, tableCellProps, { onKeyDown: handleKeyDown, sx: (theme) => (Object.assign(Object.assign({ flexDirection: (layoutMode === null || layoutMode === void 0 ? void 0 : layoutMode.startsWith('grid')) ? 'column' : undefined, fontWeight: 'bold', overflow: 'hidden', color: theme.palette.text.primary, p: columnDefType === 'display'
8236
+ ? 'var(--mrt-head-display-cell-p)'
8237
+ : 'var(--mrt-cell-p)', pb: columnDefType === 'display'
7869
8238
  ? 0
7870
- : showColumnFilters || density === 'compact'
8239
+ : showColumnFilters
7871
8240
  ? '0.4rem'
7872
- : '0.6rem', pt: columnDefType === 'group' || density === 'compact'
7873
- ? '0.25rem'
7874
- : density === 'comfortable'
7875
- ? '.75rem'
7876
- : '1.25rem', userSelect: enableMultiSort && column.getCanSort() ? 'none' : undefined, verticalAlign: 'top', borderBottom: 'none', paddingBottom: 'none' }, getCommonMRTCellStyles({
8241
+ : 'var(--mrt-head-cell-pb)', pt: columnDefType === 'group' ? '0.25rem' : 'var(--mrt-head-cell-pt)', userSelect: enableMultiSort && column.getCanSort() ? 'none' : undefined, verticalAlign: 'top', borderBottom: 'none', paddingBottom: 'none' }, getCommonMRTCellStyles({
7877
8242
  column,
7878
8243
  header,
8244
+ isDraggingColumn,
8245
+ isHoveredColumn,
7879
8246
  table,
7880
8247
  tableCellProps,
7881
8248
  theme,
@@ -7969,8 +8336,8 @@ const MRT_TableHead = (_a) => {
7969
8336
 
7970
8337
  const MRT_Table = (_a) => {
7971
8338
  var { table } = _a, rest = __rest(_a, ["table"]);
7972
- const { getFlatHeaders, getState, options: { columns, enableStickyHeader, enableTableFooter, enableTableHead, layoutMode, memoMode, muiTableProps, renderCaption, }, } = table;
7973
- const { columnSizing, columnSizingInfo, columnVisibility } = getState();
8339
+ const { getFlatHeaders, getState, options: { columns, enableStickyHeader, enableTableFooter, enableTableHead, layoutMode, memoMode, muiTableProps, renderCaption, }, refs: { tableRef }, } = table;
8340
+ const { columnSizing, columnVisibility, density } = getState();
7974
8341
  const tableProps = Object.assign(Object.assign({}, parseFromValuesOrFunc(muiTableProps, { table })), rest);
7975
8342
  const Caption = parseFromValuesOrFunc(renderCaption, { table });
7976
8343
  const columnSizeVars = useMemo(() => {
@@ -7983,13 +8350,49 @@ const MRT_Table = (_a) => {
7983
8350
  colSizes[`--col-${parseCSSVarId(header.column.id)}-size`] = colSize;
7984
8351
  }
7985
8352
  return colSizes;
7986
- }, [columns, columnSizing, columnSizingInfo, columnVisibility]);
8353
+ }, [columns, columnSizing, columnVisibility]);
8354
+ // Padding values keyed off density, read by cell/header/footer sx so density toggles
8355
+ // reuse existing emotion classes instead of generating new ones per cell.
8356
+ const densityVars = useMemo(() => ({
8357
+ '--mrt-cell-p': density === 'compact'
8358
+ ? '0.5rem'
8359
+ : density === 'comfortable'
8360
+ ? '1rem'
8361
+ : '1.5rem',
8362
+ '--mrt-display-cell-p': density === 'compact'
8363
+ ? '0 0.5rem'
8364
+ : density === 'comfortable'
8365
+ ? '0.5rem 0.75rem'
8366
+ : '1rem 1.25rem',
8367
+ '--mrt-head-display-cell-p': density === 'compact'
8368
+ ? '0.5rem'
8369
+ : density === 'comfortable'
8370
+ ? '0.75rem'
8371
+ : '1rem 1.25rem',
8372
+ '--mrt-head-cell-pb': density === 'compact' ? '0.4rem' : '0.6rem',
8373
+ '--mrt-head-cell-pt': density === 'compact'
8374
+ ? '0.25rem'
8375
+ : density === 'comfortable'
8376
+ ? '.75rem'
8377
+ : '1.25rem',
8378
+ }), [density]);
7987
8379
  const columnVirtualizer = useMRT_ColumnVirtualizer(table);
7988
8380
  const commonTableGroupProps = {
7989
8381
  columnVirtualizer,
7990
8382
  table,
7991
8383
  };
7992
- return (jsxs(Table, Object.assign({ stickyHeader: enableStickyHeader }, tableProps, { style: Object.assign(Object.assign({}, columnSizeVars), tableProps === null || tableProps === void 0 ? void 0 : tableProps.style), sx: (theme) => (Object.assign({ borderCollapse: 'separate', display: (layoutMode === null || layoutMode === void 0 ? void 0 : layoutMode.startsWith('grid')) ? 'grid' : undefined, position: 'relative' }, parseFromValuesOrFunc(tableProps === null || tableProps === void 0 ? void 0 : tableProps.sx, theme))), children: [!!Caption && jsx("caption", { children: Caption }), enableTableHead && jsx(MRT_TableHead, Object.assign({}, commonTableGroupProps)), memoMode === 'table-body' || columnSizingInfo.isResizingColumn ? (jsx(Memo_MRT_TableBody, Object.assign({}, commonTableGroupProps))) : (jsx(MRT_TableBody, Object.assign({}, commonTableGroupProps))), enableTableFooter && jsx(MRT_TableFooter, Object.assign({}, commonTableGroupProps))] })));
8384
+ return (jsxs(Table, Object.assign({ stickyHeader: enableStickyHeader }, tableProps, { ref: (node) => {
8385
+ if (node) {
8386
+ tableRef.current = node;
8387
+ const userRef = tableProps === null || tableProps === void 0 ? void 0 : tableProps.ref;
8388
+ if (typeof userRef === 'function') {
8389
+ userRef(node);
8390
+ }
8391
+ else if (userRef) {
8392
+ userRef.current = node;
8393
+ }
8394
+ }
8395
+ }, style: Object.assign(Object.assign(Object.assign({}, columnSizeVars), densityVars), tableProps === null || tableProps === void 0 ? void 0 : tableProps.style), sx: (theme) => (Object.assign({ borderCollapse: 'separate', display: (layoutMode === null || layoutMode === void 0 ? void 0 : layoutMode.startsWith('grid')) ? 'grid' : undefined, overflow: 'visible', position: 'relative' }, parseFromValuesOrFunc(tableProps === null || tableProps === void 0 ? void 0 : tableProps.sx, theme))), children: [!!Caption && jsx("caption", { children: Caption }), enableTableHead && jsx(MRT_TableHead, Object.assign({}, commonTableGroupProps)), memoMode === 'table-body' ? (jsx(Memo_MRT_TableBody, Object.assign({}, commonTableGroupProps))) : (jsx(MRT_TableBody, Object.assign({}, commonTableGroupProps))), enableTableFooter && jsx(MRT_TableFooter, Object.assign({}, commonTableGroupProps))] })));
7993
8396
  };
7994
8397
 
7995
8398
  const MRT_TableLoadingOverlay = (_a) => {
@@ -8015,8 +8418,11 @@ const MRT_TableLoadingOverlay = (_a) => {
8015
8418
 
8016
8419
  const MRT_TableContainer = (_a) => {
8017
8420
  var { table } = _a, rest = __rest(_a, ["table"]);
8018
- const { getState, options: { createDisplayMode, editDisplayMode, enableCellActions, enableRowVirtualization, muiTableContainerProps, }, refs: { tableContainerRef }, } = table;
8019
- const { actionCell, creatingRow, editingRow, isLoading, showLoadingOverlay, newEntryModal, } = getState();
8421
+ const { getState, options: { createDisplayMode, editDisplayMode, enableCellActions, enableRowVirtualization, muiTableContainerProps, }, refs: { resizeIndicatorRef, tableContainerRef }, } = table;
8422
+ const { creatingRow, isLoading, showLoadingOverlay } = getState();
8423
+ const actionCell = useMRT_SliceValue(table._uiStore, (s) => s.actionCell);
8424
+ const editingRow = useMRT_SliceValue(table._uiStore, (s) => s.editingRow);
8425
+ const newEntryModal = useMRT_SliceValue(table._uiStore, (s) => s.newEntryModal);
8020
8426
  const loading = showLoadingOverlay !== false && (isLoading || showLoadingOverlay);
8021
8427
  const tableContainerProps = Object.assign(Object.assign({}, parseFromValuesOrFunc(muiTableContainerProps, {
8022
8428
  table,
@@ -8031,9 +8437,23 @@ const MRT_TableContainer = (_a) => {
8031
8437
  tableContainerProps.ref.current = node;
8032
8438
  }
8033
8439
  }
8034
- }, style: Object.assign({}, tableContainerProps === null || tableContainerProps === void 0 ? void 0 : tableContainerProps.style), sx: (theme) => (Object.assign(Object.assign({ flex: '1 1 auto', height: '100%', display: 'flex', flexDirection: 'column', maxWidth: '100%', overflow: 'auto', position: 'relative' }, (enableRowVirtualization
8440
+ }, style: Object.assign({}, tableContainerProps === null || tableContainerProps === void 0 ? void 0 : tableContainerProps.style), sx: (theme) => (Object.assign(Object.assign(Object.assign({ flex: '1 1 auto', height: '100%', display: 'flex', flexDirection: 'column', maxWidth: '100%', overflow: 'auto', position: 'relative' }, (enableRowVirtualization
8035
8441
  ? { contain: 'paint', willChange: 'transform' }
8036
- : null)), parseFromValuesOrFunc(tableContainerProps === null || tableContainerProps === void 0 ? void 0 : tableContainerProps.sx, theme))), children: [loading ? jsx(MRT_TableLoadingOverlay, { table: table }) : null, jsx(MRT_Table, { table: table }), (createModalOpen || editModalOpen) && (jsx(MRT_EditRowModal, { open: true, table: table })), newEntryModal.open && jsx(MRT_NewEntryModal, { table: table }), enableCellActions && actionCell && jsx(MRT_CellActionMenu, { table: table })] })));
8442
+ : null)), { '&[data-mrt-resizing]': {
8443
+ userSelect: 'none',
8444
+ }, '&[data-mrt-resizing] .Mui-TableHeadCell-Content-Actions': {
8445
+ visibility: 'hidden',
8446
+ } }), parseFromValuesOrFunc(tableContainerProps === null || tableContainerProps === void 0 ? void 0 : tableContainerProps.sx, theme))), children: [loading ? jsx(MRT_TableLoadingOverlay, { table: table }) : null, jsx(Box, { ref: resizeIndicatorRef, sx: {
8447
+ bgcolor: 'primary.main',
8448
+ bottom: 0,
8449
+ display: 'none',
8450
+ left: 0,
8451
+ pointerEvents: 'none',
8452
+ position: 'absolute',
8453
+ top: 0,
8454
+ width: '2px',
8455
+ zIndex: 3,
8456
+ } }), jsx(MRT_Table, { table: table }), (createModalOpen || editModalOpen) && (jsx(MRT_EditRowModal, { open: true, table: table })), newEntryModal.open && jsx(MRT_NewEntryModal, { table: table }), enableCellActions && actionCell && jsx(MRT_CellActionMenu, { table: table })] })));
8037
8457
  };
8038
8458
 
8039
8459
  const MRT_TablePaper = (_a) => {
@@ -8349,11 +8769,26 @@ const MaterialReactServerTable = (_a) => {
8349
8769
  return (jsx(MaterialReactServerTableInstance, Object.assign({ config: config, saveState: saveState }, instanceProps)));
8350
8770
  };
8351
8771
 
8772
+ const MRT_ColumnPinningButtons = (_a) => {
8773
+ var { column, table } = _a, rest = __rest(_a, ["column", "table"]);
8774
+ const { options: { icons: { PushPinIcon }, localization, }, } = table;
8775
+ const handlePinColumn = (pinDirection) => {
8776
+ column.pin(pinDirection);
8777
+ };
8778
+ return (jsx(Box, Object.assign({}, rest, { sx: (theme) => (Object.assign({ minWidth: '70px', textAlign: 'center' }, parseFromValuesOrFunc(rest === null || rest === void 0 ? void 0 : rest.sx, theme))), children: column.getIsPinned() ? (jsx(Tooltip, { title: localization.unpin, children: jsx(IconButton, { onClick: () => handlePinColumn(false), size: "small", children: jsx(PushPinIcon, {}) }) })) : (jsxs(Fragment, { children: [jsx(Tooltip, { title: localization.pinToLeft, children: jsx(IconButton, { onClick: () => handlePinColumn('left'), size: "small", children: jsx(PushPinIcon, { style: {
8779
+ transform: 'rotate(90deg)',
8780
+ } }) }) }), jsx(Tooltip, { title: localization.pinToRight, children: jsx(IconButton, { onClick: () => handlePinColumn('right'), size: "small", children: jsx(PushPinIcon, { style: {
8781
+ transform: 'rotate(-90deg)',
8782
+ } }) }) })] })) })));
8783
+ };
8784
+
8352
8785
  const MRT_ToolbarAlertBanner = (_a) => {
8353
8786
  var _b, _c, _d;
8354
8787
  var { stackAlertBanner, table } = _a, rest = __rest(_a, ["stackAlertBanner", "table"]);
8355
8788
  const { getFilteredSelectedRowModel, getCoreRowModel, getState, options: { enableRowSelection, enableSelectAll, localization, manualPagination, muiToolbarAlertBannerChipProps, muiToolbarAlertBannerProps, positionToolbarAlertBanner, renderToolbarAlertBannerContent, rowCount, }, refs: { tablePaperRef }, } = table;
8356
- const { density, grouping, rowSelection, showAlertBanner } = getState();
8789
+ const { grouping, rowSelection } = getState();
8790
+ const density = useMRT_SliceValue(table._uiStore, (s) => s.density);
8791
+ const showAlertBanner = useMRT_SliceValue(table._uiStore, (s) => s.showAlertBanner);
8357
8792
  const alertProps = Object.assign(Object.assign({}, parseFromValuesOrFunc(muiToolbarAlertBannerProps, {
8358
8793
  table,
8359
8794
  })), rest);
@@ -8394,5 +8829,5 @@ const MRT_ToolbarAlertBanner = (_a) => {
8394
8829
  positionToolbarAlertBanner === 'head-overlay' && (jsx(MRT_SelectCheckbox, { table: table })), ' ', selectedAlert] }), selectedAlert && groupedAlert && jsx("br", {}), groupedAlert] })] })) })) }));
8395
8830
  };
8396
8831
 
8397
- export { CHECKBOX_DISPLAY_COLUMN_ID, MRT_ActionMenuItem, MRT_AdvancedFilters, MRT_AggregationFns, MRT_BottomToolbar, MRT_ColumnActionMenu, MRT_ColumnPinningButtons, MRT_CopyButton, MRT_DefaultColumn, MRT_DefaultDisplayColumn, MRT_EditActionButtons, MRT_EditCellTextField, MRT_EditRowModal, MRT_ExpandAllButton, MRT_ExpandButton, MRT_ExportsToolbar, MRT_FilterFns, MRT_FilterOptionMenu, MRT_GrabHandleButton, MRT_LinearProgressBar, MRT_NewEntryForm, MRT_NewEntryFormActions, MRT_NewEntryFormActionsContext, MRT_NewEntryFormProvider, MRT_NewEntryModal, MRT_RowActionMenu, MRT_RowPinButton, MRT_SelectAllMenu, MRT_SelectCheckbox, MRT_SelectionCountBadge, MRT_ShowHideColumnsButton, MRT_ShowHideColumnsMenu, MRT_ShowHideColumnsMenuItems, MRT_SortingFns, MRT_Table, MRT_TableBody, MRT_TableBodyCell, MRT_TableBodyCellValue, MRT_TableBodyRow, MRT_TableBodyRowGrabHandle, MRT_TableBodyRowPinButton, MRT_TableContainer, MRT_TableDetailPanel, MRT_TableFooter, MRT_TableFooterCell, MRT_TableFooterRow, MRT_TableHead, MRT_TableHeadCell, MRT_TableHeadCellColumnActionsButton, MRT_TableHeadCellFilterLabel, MRT_TableHeadCellGrabHandle, MRT_TableHeadCellResizeHandle, MRT_TableHeadCellSortLabel, MRT_TableHeadRow, MRT_TableLoadingOverlay, MRT_TablePagination, MRT_TablePaper, MRT_ToggleDensePaddingButton, MRT_ToggleFiltersButton, MRT_ToggleGlobalFilterButton, MRT_ToggleRowActionMenuButton, MRT_ToolbarAlertBanner, MRT_ToolbarDropZone, MRT_ToolbarInternalButtons, MRT_TopToolbar, MaterialReactServerTable, MaterialReactTable, Memo_MRT_TableBody, Memo_MRT_TableBodyCell, Memo_MRT_TableBodyRow, RHF_FormProvider, buildDefaultValues, cellKeyboardShortcuts, createMRTColumnHelper, createRow, defaultDisplayColumnProps, flexRender, getAllLeafColumnDefs, getCanRankRows, getColumnFilterInfo, getColumnId, getDefaultColumnFilterFn, getDefaultColumnOrderIds, getDefaultColumnPinningState, getIsAllPagesSelectionActive, getIsRankingRows, getIsRowSelected, getLeadingDisplayColumnIds, getMRT_RowSelectionHandler, getMRT_Rows, getMRT_SelectAllHandler, getTrailingDisplayColumnIds, groupFieldsBySection, isCellEditable, mrtFilterOptions, openEditingCell, prepareColumns, rankGlobalFuzzy, reorderColumn, resolveFormFields, showRowActionsColumn, showRowDragColumn, showRowExpandColumn, showRowNumbersColumn, showRowPinningColumn, showRowSelectionColumn, showRowSpacerColumn, sortByOrder, useDropdownOptions, useMRT_ColumnVirtualizer, useMRT_Effects, useMRT_NewEntryFormActions, useMRT_RowVirtualizer, useMRT_Rows, useMRT_TableInstance, useMRT_TableOptions, useMaterialReactTable };
8832
+ export { CHECKBOX_DISPLAY_COLUMN_ID, MRT_ActionMenuItem, MRT_AdvancedFilters, MRT_AggregationFns, MRT_BottomToolbar, MRT_ColumnActionMenu, MRT_ColumnPinningButtons, MRT_CopyButton, MRT_DefaultColumn, MRT_DefaultDisplayColumn, MRT_EditActionButtons, MRT_EditCellTextField, MRT_EditRowModal, MRT_ExpandAllButton, MRT_ExpandButton, MRT_ExportsToolbar, MRT_FilterFns, MRT_FilterOptionMenu, MRT_GrabHandleButton, MRT_LinearProgressBar, MRT_NewEntryForm, MRT_NewEntryFormActions, MRT_NewEntryFormActionsContext, MRT_NewEntryFormProvider, MRT_NewEntryModal, MRT_RowActionMenu, MRT_RowPinButton, MRT_SelectAllMenu, MRT_SelectCheckbox, MRT_SelectionCountBadge, MRT_ShowHideColumnsButton, MRT_ShowHideColumnsMenu, MRT_ShowHideColumnsMenuItems, MRT_SortingFns, MRT_Table, MRT_TableBody, MRT_TableBodyCell, MRT_TableBodyCellValue, MRT_TableBodyRow, MRT_TableBodyRowGrabHandle, MRT_TableBodyRowPinButton, MRT_TableContainer, MRT_TableDetailPanel, MRT_TableFooter, MRT_TableFooterCell, MRT_TableFooterRow, MRT_TableHead, MRT_TableHeadCell, MRT_TableHeadCellColumnActionsButton, MRT_TableHeadCellFilterLabel, MRT_TableHeadCellGrabHandle, MRT_TableHeadCellResizeHandle, MRT_TableHeadCellSortLabel, MRT_TableHeadRow, MRT_TableLoadingOverlay, MRT_TablePagination, MRT_TablePaper, MRT_ToggleDensePaddingButton, MRT_ToggleFiltersButton, MRT_ToggleGlobalFilterButton, MRT_ToggleRowActionMenuButton, MRT_ToolbarAlertBanner, MRT_ToolbarDropZone, MRT_ToolbarInternalButtons, MRT_TopToolbar, MaterialReactServerTable, MaterialReactTable, Memo_MRT_TableBody, Memo_MRT_TableBodyCell, Memo_MRT_TableBodyRow, RHF_FormProvider, buildDefaultValues, cellKeyboardShortcuts, createDeleteAction, createEditAction, createExportAction, createMRTColumnHelper, createRow, defaultDisplayColumnProps, flexRender, getAllLeafColumnDefs, getCanRankRows, getColumnFilterInfo, getColumnId, getDefaultColumnFilterFn, getDefaultColumnOrderIds, getDefaultColumnPinningState, getIsAllPagesSelectionActive, getIsRankingRows, getIsRowSelected, getLeadingDisplayColumnIds, getMRT_RowSelectionHandler, getMRT_Rows, getMRT_SelectAllHandler, getTrailingDisplayColumnIds, groupFieldsBySection, isCellEditable, mrtFilterOptions, openEditingCell, prepareColumns, rankGlobalFuzzy, reorderColumn, resolveFormFields, showRowActionsColumn, showRowDragColumn, showRowExpandColumn, showRowNumbersColumn, showRowPinningColumn, showRowSelectionColumn, showRowSpacerColumn, sortByOrder, useDropdownOptions, useMRT_ColumnVirtualizer, useMRT_Effects, useMRT_NewEntryFormActions, useMRT_RowVirtualizer, useMRT_Rows, useMRT_TableInstance, useMRT_TableOptions, useMaterialReactTable };
8398
8833
  //# sourceMappingURL=index.esm.js.map