@dooherceg/material-react-table 3.2.7 → 3.2.9

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.js CHANGED
@@ -4,24 +4,39 @@ var matchSorterUtils = require('@tanstack/match-sorter-utils');
4
4
  var reactTable = require('@tanstack/react-table');
5
5
  var react = require('react');
6
6
  var jsxRuntime = require('react/jsx-runtime');
7
+ var CancelIcon = require('@mui/icons-material/Cancel');
8
+ var Button = require('@mui/material/Button');
9
+ var Dialog = require('@mui/material/Dialog');
10
+ var DialogActions = require('@mui/material/DialogActions');
11
+ var DialogContent = require('@mui/material/DialogContent');
12
+ var DialogTitle = require('@mui/material/DialogTitle');
7
13
  var IconButton = require('@mui/material/IconButton');
8
- var Tooltip = require('@mui/material/Tooltip');
14
+ var Stack = require('@mui/material/Stack');
15
+ var DeleteOutlineIcon = require('@mui/icons-material/DeleteOutline');
16
+ var EditNoteIcon = require('@mui/icons-material/EditNote');
17
+ var FileDownloadIcon = require('@mui/icons-material/FileDownload');
18
+ var PrintIcon = require('@mui/icons-material/Print');
19
+ var Checkbox = require('@mui/material/Checkbox');
20
+ var CircularProgress = require('@mui/material/CircularProgress');
21
+ var Divider = require('@mui/material/Divider');
22
+ var FormControl = require('@mui/material/FormControl');
23
+ var FormControlLabel = require('@mui/material/FormControlLabel');
9
24
  var Menu = require('@mui/material/Menu');
10
- var Box = require('@mui/material/Box');
11
- var ListItemIcon = require('@mui/material/ListItemIcon');
12
25
  var MenuItem = require('@mui/material/MenuItem');
13
- var Button = require('@mui/material/Button');
14
- var CircularProgress = require('@mui/material/CircularProgress');
26
+ var Radio = require('@mui/material/Radio');
27
+ var RadioGroup = require('@mui/material/RadioGroup');
15
28
  var styles = require('@mui/material/styles');
16
- var Stack = require('@mui/material/Stack');
29
+ var Tooltip = require('@mui/material/Tooltip');
30
+ var Typography = require('@mui/material/Typography');
31
+ var printJS = require('print-js');
32
+ var notistack = require('notistack');
33
+ var Box = require('@mui/material/Box');
34
+ var ListItemIcon = require('@mui/material/ListItemIcon');
17
35
  var SubdirectoryArrowLeftIcon = require('@mui/icons-material/SubdirectoryArrowLeft');
18
36
  var VerticalAlignTopIcon = require('@mui/icons-material/VerticalAlignTop');
19
- var Checkbox = require('@mui/material/Checkbox');
20
- var Radio = require('@mui/material/Radio');
21
37
  var AddIcon = require('@mui/icons-material/Add');
22
38
  var ArrowDownwardIcon = require('@mui/icons-material/ArrowDownward');
23
39
  var ArrowRightIcon = require('@mui/icons-material/ArrowRight');
24
- var CancelIcon = require('@mui/icons-material/Cancel');
25
40
  var ChevronLeftIcon = require('@mui/icons-material/ChevronLeft');
26
41
  var ChevronRightIcon = require('@mui/icons-material/ChevronRight');
27
42
  var ClearAllIcon = require('@mui/icons-material/ClearAll');
@@ -53,15 +68,6 @@ var SortIcon = require('@mui/icons-material/Sort');
53
68
  var SyncAltIcon = require('@mui/icons-material/SyncAlt');
54
69
  var ViewColumnIcon = require('@mui/icons-material/ViewColumn');
55
70
  var VisibilityOffIcon = require('@mui/icons-material/VisibilityOff');
56
- var FileDownloadIcon = require('@mui/icons-material/FileDownload');
57
- var PrintIcon = require('@mui/icons-material/Print');
58
- var Divider = require('@mui/material/Divider');
59
- var FormControl = require('@mui/material/FormControl');
60
- var FormControlLabel = require('@mui/material/FormControlLabel');
61
- var RadioGroup = require('@mui/material/RadioGroup');
62
- var Typography = require('@mui/material/Typography');
63
- var printJS = require('print-js');
64
- var notistack = require('notistack');
65
71
  var reactVirtual = require('@tanstack/react-virtual');
66
72
  var Drawer = require('@mui/material/Drawer');
67
73
  var TextField = require('@mui/material/TextField');
@@ -106,10 +112,6 @@ var DeleteForeverIcon = require('@mui/icons-material/DeleteForever');
106
112
  var Switch = require('@mui/material/Switch');
107
113
  var Badge = require('@mui/material/Badge');
108
114
  var TableContainer = require('@mui/material/TableContainer');
109
- var Dialog = require('@mui/material/Dialog');
110
- var DialogActions = require('@mui/material/DialogActions');
111
- var DialogContent = require('@mui/material/DialogContent');
112
- var DialogTitle = require('@mui/material/DialogTitle');
113
115
  var Modal = require('@mui/material/Modal');
114
116
  var Accordion = require('@mui/material/Accordion');
115
117
  var AccordionDetails = require('@mui/material/AccordionDetails');
@@ -723,99 +725,6 @@ const createRow = (table, originalRow, rowIndex = -1, depth = 0, subRows, parent
723
725
  [getColumnId(col)]: '',
724
726
  }))), rowIndex, depth, subRows, parentId);
725
727
 
726
- const MRT_AggregationFns = Object.assign({}, reactTable.aggregationFns);
727
-
728
- const fuzzy = (row, columnId, filterValue, addMeta) => {
729
- const itemRank = matchSorterUtils.rankItem(row.getValue(columnId), filterValue, {
730
- threshold: matchSorterUtils.rankings.MATCHES,
731
- });
732
- addMeta(itemRank);
733
- return itemRank.passed;
734
- };
735
- fuzzy.autoRemove = (val) => !val;
736
- const contains = (row, id, filterValue) => {
737
- var _a;
738
- return !!((_a = row
739
- .getValue(id)) === null || _a === void 0 ? void 0 : _a.toString().toLowerCase().trim().includes(filterValue.toString().toLowerCase().trim()));
740
- };
741
- contains.autoRemove = (val) => !val;
742
- const startsWith = (row, id, filterValue) => {
743
- var _a;
744
- return !!((_a = row
745
- .getValue(id)) === null || _a === void 0 ? void 0 : _a.toString().toLowerCase().trim().startsWith(filterValue.toString().toLowerCase().trim()));
746
- };
747
- startsWith.autoRemove = (val) => !val;
748
- const endsWith = (row, id, filterValue) => {
749
- var _a;
750
- return !!((_a = row
751
- .getValue(id)) === null || _a === void 0 ? void 0 : _a.toString().toLowerCase().trim().endsWith(filterValue.toString().toLowerCase().trim()));
752
- };
753
- endsWith.autoRemove = (val) => !val;
754
- const equals = (row, id, filterValue) => {
755
- var _a;
756
- return ((_a = row.getValue(id)) === null || _a === void 0 ? void 0 : _a.toString().toLowerCase().trim()) ===
757
- filterValue.toString().toLowerCase().trim();
758
- };
759
- equals.autoRemove = (val) => !val;
760
- const notEquals = (row, id, filterValue) => {
761
- var _a;
762
- return ((_a = row.getValue(id)) === null || _a === void 0 ? void 0 : _a.toString().toLowerCase().trim()) !==
763
- filterValue.toString().toLowerCase().trim();
764
- };
765
- notEquals.autoRemove = (val) => !val;
766
- const greaterThan = (row, id, filterValue) => {
767
- var _a, _b, _c;
768
- return !isNaN(+filterValue) && !isNaN(+row.getValue(id))
769
- ? +((_a = row.getValue(id)) !== null && _a !== void 0 ? _a : 0) > +filterValue
770
- : ((_c = ((_b = row.getValue(id)) !== null && _b !== void 0 ? _b : '')) === null || _c === void 0 ? void 0 : _c.toString().toLowerCase().trim()) > filterValue.toString().toLowerCase().trim();
771
- };
772
- greaterThan.autoRemove = (val) => !val;
773
- const greaterThanOrEqualTo = (row, id, filterValue) => equals(row, id, filterValue) || greaterThan(row, id, filterValue);
774
- greaterThanOrEqualTo.autoRemove = (val) => !val;
775
- const lessThan = (row, id, filterValue) => {
776
- var _a, _b, _c;
777
- return !isNaN(+filterValue) && !isNaN(+row.getValue(id))
778
- ? +((_a = row.getValue(id)) !== null && _a !== void 0 ? _a : 0) < +filterValue
779
- : ((_c = ((_b = row.getValue(id)) !== null && _b !== void 0 ? _b : '')) === null || _c === void 0 ? void 0 : _c.toString().toLowerCase().trim()) < filterValue.toString().toLowerCase().trim();
780
- };
781
- lessThan.autoRemove = (val) => !val;
782
- const lessThanOrEqualTo = (row, id, filterValue) => equals(row, id, filterValue) || lessThan(row, id, filterValue);
783
- lessThanOrEqualTo.autoRemove = (val) => !val;
784
- const between = (row, id, filterValues) => (['', undefined].includes(filterValues[0]) ||
785
- greaterThan(row, id, filterValues[0])) &&
786
- ((!isNaN(+filterValues[0]) &&
787
- !isNaN(+filterValues[1]) &&
788
- +filterValues[0] > +filterValues[1]) ||
789
- ['', undefined].includes(filterValues[1]) ||
790
- lessThan(row, id, filterValues[1]));
791
- between.autoRemove = (val) => !val;
792
- const betweenInclusive = (row, id, filterValues) => (['', undefined].includes(filterValues[0]) ||
793
- greaterThanOrEqualTo(row, id, filterValues[0])) &&
794
- ((!isNaN(+filterValues[0]) &&
795
- !isNaN(+filterValues[1]) &&
796
- +filterValues[0] > +filterValues[1]) ||
797
- ['', undefined].includes(filterValues[1]) ||
798
- lessThanOrEqualTo(row, id, filterValues[1]));
799
- betweenInclusive.autoRemove = (val) => !val;
800
- const empty = (row, id, _filterValue) => { var _a; return !((_a = row.getValue(id)) === null || _a === void 0 ? void 0 : _a.toString().trim()); };
801
- empty.autoRemove = (val) => !val;
802
- const notEmpty = (row, id, _filterValue) => { var _a; return !!((_a = row.getValue(id)) === null || _a === void 0 ? void 0 : _a.toString().trim()); };
803
- notEmpty.autoRemove = (val) => !val;
804
- const MRT_FilterFns = Object.assign(Object.assign({}, reactTable.filterFns), { between,
805
- betweenInclusive,
806
- contains,
807
- empty,
808
- endsWith,
809
- equals,
810
- fuzzy,
811
- greaterThan,
812
- greaterThanOrEqualTo,
813
- lessThan,
814
- lessThanOrEqualTo,
815
- notEmpty,
816
- notEquals,
817
- startsWith });
818
-
819
728
  /******************************************************************************
820
729
  Copyright (c) Microsoft Corporation.
821
730
 
@@ -860,1413 +769,1665 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
860
769
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
861
770
  };
862
771
 
863
- const useMRT_SliceValue = (store, selector) => {
864
- const getSnapshot = () => selector(store.get());
865
- return react.useSyncExternalStore(store.subscribe, getSnapshot, getSnapshot);
772
+ function MRT_DeleteRowButton({ onClick, }) {
773
+ const iconButtonStyle = {
774
+ p: 0,
775
+ };
776
+ return (jsxRuntime.jsx(IconButton, { disableRipple: true, color: "error", sx: iconButtonStyle, onClick: onClick, children: jsxRuntime.jsx(DeleteOutlineIcon, {}) }));
777
+ }
778
+
779
+ const DeleteRowAction = ({ onDeleteConfirm, table, deleteConfirmation, }) => {
780
+ // Toolbar context — no specific row is targeted
781
+ const [open, setOpen] = react.useState(false);
782
+ const [deleting, setDeleting] = react.useState(false);
783
+ // Resolve deleteConfirmation — plain object, defaults to empty object.
784
+ const resolvedDeleteConfirmation = deleteConfirmation !== null && deleteConfirmation !== void 0 ? deleteConfirmation : {};
785
+ const { title: titleOverride, message: messageOverride, confirmButtonText: confirmButtonTextOverride, cancelButtonText: cancelButtonTextOverride, dialogSx, contentContainerSx, headerSx, titleSx, bodySx, footerSx, closeButtonProps, cancelButtonProps, confirmButtonProps, } = resolvedDeleteConfirmation;
786
+ // Consumer override takes priority over localization fallback.
787
+ const deleteConfirmationTitle = titleOverride !== null && titleOverride !== void 0 ? titleOverride : table.options.localization.deleteConfirmationTitle;
788
+ const deleteConfirmationMessage = messageOverride !== null && messageOverride !== void 0 ? messageOverride : table.options.localization.deleteConfirmationMessage;
789
+ const confirmButtonLabel = confirmButtonTextOverride !== null && confirmButtonTextOverride !== void 0 ? confirmButtonTextOverride : table.options.localization.deleteConfirmYes;
790
+ const cancelButtonLabel = cancelButtonTextOverride !== null && cancelButtonTextOverride !== void 0 ? cancelButtonTextOverride : table.options.localization.deleteConfirmNo;
791
+ const deletingLabel = table.options.localization.deleteConfirmDeleting;
792
+ const handleDeleteRowButtonClick = () => {
793
+ setOpen(true);
794
+ };
795
+ const handleConfirmDelete = () => __awaiter(void 0, void 0, void 0, function* () {
796
+ setDeleting(true);
797
+ try {
798
+ yield onDeleteConfirm();
799
+ setOpen(false);
800
+ }
801
+ catch (error) {
802
+ console.error('[MRT] Error while deleting row(s):', error);
803
+ }
804
+ finally {
805
+ setDeleting(false);
806
+ }
807
+ });
808
+ const handleClose = () => __awaiter(void 0, void 0, void 0, function* () {
809
+ setOpen(false);
810
+ });
811
+ return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(Dialog, { open: open, onClose: () => setOpen(false), keepMounted: true, "aria-describedby": "alert-dialog-slide-description", role: "alertdialog", sx: dialogSx, children: jsxRuntime.jsxs(Stack, { flexDirection: "column", height: "min-content", sx: contentContainerSx, children: [jsxRuntime.jsxs(Stack, { flexDirection: "row", alignItems: "center", justifyContent: "space-between", sx: Object.assign({ width: '100%' }, headerSx), children: [jsxRuntime.jsx(DialogTitle, { sx: Object.assign({ p: '0.7rem' }, titleSx), children: deleteConfirmationTitle }), jsxRuntime.jsx(DialogActions, { sx: {
812
+ p: '0.7rem',
813
+ }, children: jsxRuntime.jsx(IconButton, Object.assign({ color: "error", "aria-label": "close", onClick: handleClose }, closeButtonProps, { children: jsxRuntime.jsx(CancelIcon, {}) })) })] }), jsxRuntime.jsxs(Stack, { children: [jsxRuntime.jsx(DialogContent, { sx: Object.assign({ pr: '6rem' }, bodySx), children: deleteConfirmationMessage }), jsxRuntime.jsxs(DialogActions, { sx: footerSx, children: [jsxRuntime.jsx(Button, Object.assign({ onClick: () => setOpen(false), disabled: deleting, autoFocus: true, variant: "soft" }, cancelButtonProps, { children: cancelButtonLabel })), jsxRuntime.jsx(Button, Object.assign({ onClick: handleConfirmDelete, disabled: deleting, variant: "contained", color: "error" }, confirmButtonProps, { children: deleting ? deletingLabel : confirmButtonLabel }))] })] })] }) }), jsxRuntime.jsx(MRT_DeleteRowButton, { onClick: handleDeleteRowButtonClick })] }));
814
+ };
815
+
816
+ const createDeleteAction = (_a = {}) => {
817
+ var { onDelete, renderRow: customRenderRow, renderToolbar: customRenderToolbar, deleteConfirmation } = _a, rest = __rest(_a, ["onDelete", "renderRow", "renderToolbar", "deleteConfirmation"]);
818
+ // Default delete behavior used when the consumer does not provide a custom onDelete.
819
+ // Also exposed to custom onDelete through context.defaultOnDelete for composition.
820
+ const defaultOnDelete = (_a) => __awaiter(void 0, [_a], void 0, function* ({ rowsToDelete, table, }) {
821
+ var _b, _c;
822
+ // Nothing to delete, so exit early.
823
+ if (!rowsToDelete.length) {
824
+ return;
825
+ }
826
+ yield ((_c = (_b = table.options).deleteRowsFn) === null || _c === void 0 ? void 0 : _c.call(_b, { rowsToDelete, table }));
827
+ });
828
+ // Single execution pipeline for every delete flow (row or toolbar).
829
+ // If a custom handler exists, it receives defaultOnDelete and decides when to call it.
830
+ const executeDelete = (context) => {
831
+ const executeDefaultDelete = () => defaultOnDelete(context);
832
+ if (onDelete) {
833
+ return onDelete(Object.assign(Object.assign({}, context), { defaultOnDelete: executeDefaultDelete }));
834
+ }
835
+ return executeDefaultDelete();
836
+ };
837
+ // Resolves selected rows from table state for toolbar-triggered delete.
838
+ const handleMultipleRowDelete = ({ table, }) => {
839
+ const rowsToDelete = table.getSelectedRowModel().rows;
840
+ return executeDelete({ table, rowsToDelete });
841
+ };
842
+ // Resolves only the active row for row-triggered delete.
843
+ const handleSingleRowDelete = ({ table, row, }) => {
844
+ return executeDelete({ table, rowsToDelete: [row] });
845
+ };
846
+ // Wraps row context into a zero-argument callback expected by row action UI.
847
+ // Must return the promise (not fire-and-forget it) so callers like DeleteRowAction
848
+ // can `await` it and keep the confirmation modal open until delete actually finishes.
849
+ const createRowDeleteExecutor = (context) => {
850
+ return () => handleSingleRowDelete(context);
851
+ };
852
+ // Wraps toolbar context into a zero-argument callback expected by toolbar action UI.
853
+ // Same reasoning as createRowDeleteExecutor — the returned promise must propagate.
854
+ const createToolbarDeleteExecutor = (context) => {
855
+ return () => handleMultipleRowDelete(context);
856
+ };
857
+ // Uses custom row renderer when provided; otherwise renders default delete action UI.
858
+ const renderRowAction = (context) => {
859
+ const onRowDelete = createRowDeleteExecutor(context);
860
+ if (customRenderRow) {
861
+ return customRenderRow(Object.assign(Object.assign({}, context), { onDelete: onRowDelete }));
862
+ }
863
+ return (jsxRuntime.jsx(DeleteRowAction, { onDeleteConfirm: onRowDelete, table: context.table, deleteConfirmation: deleteConfirmation }));
864
+ };
865
+ // Uses custom toolbar renderer when provided; otherwise renders default delete action UI.
866
+ const renderToolbarAction = (context) => {
867
+ const onToolbarDelete = createToolbarDeleteExecutor(context);
868
+ if (customRenderToolbar) {
869
+ return customRenderToolbar(Object.assign(Object.assign({}, context), { onDelete: onToolbarDelete }));
870
+ }
871
+ return (jsxRuntime.jsx(DeleteRowAction, { onDeleteConfirm: onToolbarDelete, table: context.table }));
872
+ };
873
+ return Object.assign({ name: 'delete', renderRow: renderRowAction, renderToolbar: renderToolbarAction }, rest);
866
874
  };
867
875
 
868
- const MRT_ActionMenuItem = (_a) => {
869
- var { icon, label, onOpenSubMenu, table } = _a, rest = __rest(_a, ["icon", "label", "onOpenSubMenu", "table"]);
870
- const { options: { icons: { ArrowRightIcon }, }, } = table;
871
- return (jsxRuntime.jsxs(MenuItem, Object.assign({ sx: {
872
- alignItems: 'center',
873
- justifyContent: 'space-between',
874
- minWidth: '120px',
875
- my: 0,
876
- py: '6px',
877
- }, tabIndex: 0 }, rest, { children: [jsxRuntime.jsxs(Box, { sx: {
878
- alignItems: 'center',
879
- display: 'flex',
880
- }, children: [jsxRuntime.jsx(ListItemIcon, { children: icon }), label] }), onOpenSubMenu && (jsxRuntime.jsx(IconButton, { onClick: (e) => onOpenSubMenu(e), onMouseEnter: (e) => onOpenSubMenu(e), size: "small", sx: { p: 0 }, children: jsxRuntime.jsx(ArrowRightIcon, {}) }))] })));
876
+ const MRT_EditRowButton = ({ onClick }) => {
877
+ return (jsxRuntime.jsx(IconButton, { sx: { p: 0 }, disableRipple: true, color: "primary", onClick: onClick, children: jsxRuntime.jsx(EditNoteIcon, {}) }));
881
878
  };
882
879
 
883
- const MRT_RowActionMenu = (_a) => {
884
- var { anchorEl, handleEdit, row, setAnchorEl, staticRowIndex, table } = _a, rest = __rest(_a, ["anchorEl", "handleEdit", "row", "setAnchorEl", "staticRowIndex", "table"]);
885
- const { options: { editDisplayMode, enableEditing, icons: { EditIcon }, localization, mrtTheme: { menuBackgroundColor }, renderRowActionMenuItems, }, } = table;
886
- const density = useMRT_SliceValue(table._uiStore, (s) => s.density);
887
- const menuItems = react.useMemo(() => {
888
- const items = [];
889
- const editItem = parseFromValuesOrFunc(enableEditing, row) &&
890
- ['modal', 'row'].includes(editDisplayMode) && (jsxRuntime.jsx(MRT_ActionMenuItem, { icon: jsxRuntime.jsx(EditIcon, {}), label: localization.edit, onClick: handleEdit, table: table }, 'edit'));
891
- if (editItem)
892
- items.push(editItem);
893
- const rowActionMenuItems = renderRowActionMenuItems === null || renderRowActionMenuItems === void 0 ? void 0 : renderRowActionMenuItems({
894
- closeMenu: () => setAnchorEl(null),
895
- row,
896
- staticRowIndex,
897
- table,
898
- });
899
- if (rowActionMenuItems === null || rowActionMenuItems === void 0 ? void 0 : rowActionMenuItems.length)
900
- items.push(...rowActionMenuItems);
901
- return items;
902
- }, [renderRowActionMenuItems, row, staticRowIndex, table]);
903
- if (!menuItems.length)
904
- return null;
905
- return (jsxRuntime.jsx(Menu, Object.assign({ MenuListProps: {
906
- dense: density === 'compact',
907
- sx: {
908
- backgroundColor: menuBackgroundColor,
909
- },
910
- }, anchorEl: anchorEl, disableScrollLock: true, onClick: (event) => event.stopPropagation(), onClose: () => setAnchorEl(null), open: !!anchorEl }, rest, { children: menuItems })));
880
+ const EditRowAction = ({ onEditButtonClick, }) => {
881
+ return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(MRT_EditRowButton, { onClick: onEditButtonClick }) }));
911
882
  };
912
883
 
913
- const MRT_EditActionButtons = (_a) => {
914
- var { row, table, variant = 'icon' } = _a, rest = __rest(_a, ["row", "table", "variant"]);
915
- const { getState, options: { icons: { CancelIcon, SaveIcon }, localization, onCreatingRowCancel, onCreatingRowSave, onEditingRowCancel, onEditingRowSave, }, refs: { editInputRefs }, setCreatingRow, setEditingRow, } = table;
916
- const { creatingRow, isSaving } = getState();
917
- const isCreating = (creatingRow === null || creatingRow === void 0 ? void 0 : creatingRow.id) === row.id;
918
- const isEditing = useMRT_SliceValue(table._uiStore, (s) => { var _a; return ((_a = s.editingRow) === null || _a === void 0 ? void 0 : _a.id) === row.id; });
919
- const handleCancel = () => {
920
- if (isCreating) {
921
- onCreatingRowCancel === null || onCreatingRowCancel === void 0 ? void 0 : onCreatingRowCancel({ row, table });
922
- setCreatingRow(null);
884
+ const createEditAction = ({ onEdit, renderRow: customRenderRow, } = {}) => {
885
+ const defaultOnEdit = (_a) => __awaiter(void 0, [_a], void 0, function* ({ rowToEdit, table, }) {
886
+ // Nothing to edit, so exit early.
887
+ if (!rowToEdit) {
888
+ return;
923
889
  }
924
- else if (isEditing) {
925
- onEditingRowCancel === null || onEditingRowCancel === void 0 ? void 0 : onEditingRowCancel({ row, table });
926
- setEditingRow(null);
890
+ const { setNewEntryModal } = table;
891
+ const handleOpenEditModal = () => {
892
+ setNewEntryModal({
893
+ open: true,
894
+ mode: 'edit',
895
+ });
896
+ };
897
+ if (table.options.editRowFn) {
898
+ yield table.options.editRowFn({ rowToEdit, table });
899
+ return;
927
900
  }
928
- row._valuesCache = {}; //reset values cache
901
+ handleOpenEditModal();
902
+ });
903
+ const executeEdit = (context) => {
904
+ const executeDefaultEdit = () => defaultOnEdit(context);
905
+ if (onEdit) {
906
+ return onEdit(Object.assign(Object.assign({}, context), { defaultOnEdit: executeDefaultEdit }));
907
+ }
908
+ return executeDefaultEdit();
929
909
  };
930
- const handleSubmitRow = () => {
931
- var _a, _b;
932
- //look for auto-filled input values
933
- (_b = Object.values((_a = editInputRefs.current) !== null && _a !== void 0 ? _a : {})
934
- .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) => {
935
- if (input.value !== undefined &&
936
- Object.hasOwn(row === null || row === void 0 ? void 0 : row._valuesCache, input.name)) {
937
- // @ts-expect-error
938
- row._valuesCache[input.name] = input.value;
939
- }
940
- });
941
- if (isCreating)
942
- onCreatingRowSave === null || onCreatingRowSave === void 0 ? void 0 : onCreatingRowSave({
943
- exitCreatingMode: () => setCreatingRow(null),
944
- row,
945
- table,
946
- values: row._valuesCache,
947
- });
948
- else if (isEditing) {
949
- onEditingRowSave === null || onEditingRowSave === void 0 ? void 0 : onEditingRowSave({
950
- exitEditingMode: () => setEditingRow(null),
951
- row,
952
- table,
953
- values: row === null || row === void 0 ? void 0 : row._valuesCache,
954
- });
910
+ const handleEditRow = ({ table, row }) => {
911
+ return executeEdit({ table, rowToEdit: row });
912
+ };
913
+ const createEditRowExecutor = (context) => {
914
+ return () => {
915
+ void handleEditRow(context);
916
+ };
917
+ };
918
+ const renderRowAction = (context) => {
919
+ const onRowEdit = createEditRowExecutor(context);
920
+ if (customRenderRow) {
921
+ return customRenderRow(Object.assign(Object.assign({}, context), { onEdit: onRowEdit }));
955
922
  }
923
+ return jsxRuntime.jsx(EditRowAction, { onEditButtonClick: onRowEdit });
956
924
  };
957
- return (jsxRuntime.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' ? (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(Tooltip, { title: localization.cancel, children: jsxRuntime.jsx(IconButton, { "aria-label": localization.cancel, onClick: handleCancel, children: jsxRuntime.jsx(CancelIcon, {}) }) }), ((isCreating && onCreatingRowSave) ||
958
- (isEditing && onEditingRowSave)) && (jsxRuntime.jsx(Tooltip, { title: localization.save, children: jsxRuntime.jsx(IconButton, { "aria-label": localization.save, color: "info", disabled: isSaving, onClick: handleSubmitRow, children: isSaving ? jsxRuntime.jsx(CircularProgress, { size: 18 }) : jsxRuntime.jsx(SaveIcon, {}) }) }))] })) : (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(Button, { onClick: handleCancel, sx: { minWidth: '100px' }, children: localization.cancel }), jsxRuntime.jsxs(Button, { disabled: isSaving, onClick: handleSubmitRow, sx: { minWidth: '100px' }, variant: "contained", children: [isSaving && jsxRuntime.jsx(CircularProgress, { color: "inherit", size: 18 }), localization.save] })] })) }));
959
- };
960
-
961
- const parseCSSVarId = (id) => id.replace(/[^a-zA-Z0-9]/g, '_');
962
- const getMRTTheme = (mrtTheme, muiTheme) => {
963
- const mrtThemeOverrides = parseFromValuesOrFunc(mrtTheme, muiTheme);
964
- const baseBackgroundColor = muiTheme.palette.background.default;
965
- return Object.assign({ baseBackgroundColor, cellNavigationOutlineColor: muiTheme.palette.primary.main, draggingBorderColor: muiTheme.palette.primary.main, matchHighlightColor: muiTheme.palette.mode === 'dark'
966
- ? styles.darken(muiTheme.palette.warning.dark, 0.25)
967
- : styles.lighten(muiTheme.palette.warning.light, 0.5), menuBackgroundColor: styles.lighten(baseBackgroundColor, 0.07), pinnedRowBackgroundColor: styles.alpha(muiTheme.palette.primary.main, 0.1), selectedRowBackgroundColor: styles.alpha(muiTheme.palette.primary.main, 0.2) }, mrtThemeOverrides);
968
- };
969
- const commonCellBeforeAfterStyles = {
970
- content: '""',
971
- height: '100%',
972
- left: 0,
973
- position: 'absolute',
974
- top: 0,
975
- width: '100%',
976
- zIndex: -1,
977
- };
978
- const getCommonPinnedCellStyles = ({ table, theme, }) => {
979
- const { baseBackgroundColor } = table.options.mrtTheme;
980
925
  return {
981
- '&[data-pinned="true"]': {
982
- '&:before': Object.assign({ backgroundColor: styles.alpha(styles.darken(baseBackgroundColor, theme.palette.mode === 'dark' ? 0.05 : 0.01), 0.97) }, commonCellBeforeAfterStyles),
983
- },
926
+ name: 'edit',
927
+ renderRow: renderRowAction,
984
928
  };
985
929
  };
986
- const getCommonMRTCellStyles = ({ column, header, isDraggingColumn, isHoveredColumn, table, tableCellProps, theme, }) => {
987
- var _a, _b, _c, _d, _e, _f;
988
- const { options: { enableColumnVirtualization, layoutMode }, } = table;
989
- const { columnDef } = column;
990
- const { columnDefType } = columnDef;
991
- const isColumnPinned = columnDef.columnDefType !== 'group' && column.getIsPinned();
992
- const widthStyles = {
993
- 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)`,
994
- 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)`,
995
- };
996
- if (layoutMode === 'grid') {
997
- widthStyles.flex = `${[0, false].includes(columnDef.grow)
998
- ? 0
999
- : `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`;
1000
- }
1001
- else if (layoutMode === 'grid-no-grow') {
1002
- widthStyles.flex = `${+(columnDef.grow || 0)} 0 auto`;
1003
- }
1004
- // The checkbox column is technically pinned (for sticky positioning) but
1005
- // should look like a regular center column — no background overlay or shadow.
1006
- const isCheckboxColumn = column.id === CHECKBOX_DISPLAY_COLUMN_ID;
1007
- // Count all currently pinned column IDs across both sides.
1008
- // Checkbox is always pinned (counts as 1), so > 1 means the user has
1009
- // explicitly pinned at least one additional column.
1010
- const totalPinnedColumnCount = [
1011
- ...((_e = table.getState().columnPinning.left) !== null && _e !== void 0 ? _e : []),
1012
- ...((_f = table.getState().columnPinning.right) !== null && _f !== void 0 ? _f : []),
1013
- ].length;
1014
- const hasNoPinnedColumns = totalPinnedColumnCount === 0;
1015
- const pinnedStyles = isColumnPinned
1016
- ? Object.assign(Object.assign({}, (isCheckboxColumn
1017
- ? hasNoPinnedColumns
1018
- ? {
1019
- // Use doubled class selector (&&) to beat the row-level
1020
- // td[data-pinned="true"]:before specificity from MRT_TableBodyRow.
1021
- '&&[data-pinned="true"]': {
1022
- '&:before': {
1023
- backgroundColor: 'transparent',
1024
- boxShadow: 'none',
1025
- },
1026
- },
1027
- }
1028
- : // Other columns are also pinned — apply standard pinned background
1029
- // so the checkbox header matches the pinned row cells below it.
1030
- getCommonPinnedCellStyles({ column, table, theme })
1031
- : getCommonPinnedCellStyles({ column, table, theme }))), { left: isColumnPinned === 'left'
1032
- ? `${column.getStart('left')}px`
1033
- : undefined,
1034
- // Skip opacity reduction for checkbox — keep it fully opaque like center columns
1035
- opacity: isCheckboxColumn ? undefined : 0.97, position: 'sticky', right: isColumnPinned === 'right'
1036
- ? `${column.getAfter('right')}px`
1037
- : undefined }) : {};
1038
- 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'
1039
- ? 'center'
1040
- : (layoutMode === null || layoutMode === void 0 ? void 0 : layoutMode.startsWith('grid'))
1041
- ? tableCellProps.align
1042
- : undefined, opacity: isDraggingColumn || isHoveredColumn ? 0.5 : 1, position: 'relative', transition: enableColumnVirtualization
1043
- ? 'none'
1044
- : `padding 150ms ease-in-out`, zIndex: column.getIsResizing() || isDraggingColumn
1045
- ? 2
1046
- : columnDefType !== 'group' && isColumnPinned
1047
- ? 1
1048
- : 0, '&:focus-visible': {
1049
- outline: `2px solid ${table.options.mrtTheme.cellNavigationOutlineColor}`,
1050
- outlineOffset: '-2px',
1051
- } }, pinnedStyles), widthStyles), parseFromValuesOrFunc(tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.sx, theme));
930
+
931
+ const downloadExportFiles = (files) => {
932
+ files.forEach((file) => {
933
+ const binaryString = atob(file.content);
934
+ const len = binaryString.length;
935
+ const bytes = new Uint8Array(len);
936
+ for (let i = 0; i < len; i++) {
937
+ bytes[i] = binaryString.charCodeAt(i);
938
+ }
939
+ const blob = new Blob([bytes], { type: 'application/octet-stream' });
940
+ const element = document.createElement('a');
941
+ element.href = URL.createObjectURL(blob);
942
+ element.download = file.filename;
943
+ document.body.appendChild(element);
944
+ element.click();
945
+ document.body.removeChild(element);
946
+ URL.revokeObjectURL(element.href);
947
+ });
1052
948
  };
1053
- const getCommonToolbarStyles = ({ table, }) => ({
1054
- alignItems: 'flex-start',
1055
- backgroundColor: table.options.mrtTheme.baseBackgroundColor,
1056
- display: 'grid',
1057
- flexWrap: 'wrap-reverse',
1058
- position: 'relative',
1059
- transition: 'all 150ms ease-in-out',
1060
- zIndex: 1,
1061
- });
1062
- const flipIconStyles = (theme) => theme.direction === 'rtl'
1063
- ? { style: { transform: 'scaleX(-1)' } }
1064
- : undefined;
1065
- const getCommonTooltipProps = (placement) => ({
1066
- disableInteractive: true,
1067
- enterDelay: 1000,
1068
- enterNextDelay: 1000,
1069
- placement,
1070
- });
1071
949
 
1072
- const commonIconButtonStyles = {
1073
- '&:hover': {
1074
- opacity: 1,
1075
- },
1076
- height: '2rem',
1077
- ml: '10px',
1078
- opacity: 0.5,
1079
- transition: 'opacity 150ms',
1080
- width: '2rem',
950
+ const printExportFiles = (files) => {
951
+ files.forEach((file) => {
952
+ const binaryString = atob(file.content);
953
+ const len = binaryString.length;
954
+ const bytes = new Uint8Array(len);
955
+ for (let i = 0; i < len; i++) {
956
+ bytes[i] = binaryString.charCodeAt(i);
957
+ }
958
+ const blob = new Blob([bytes], { type: 'application/pdf' });
959
+ const url = URL.createObjectURL(blob);
960
+ printJS({
961
+ printable: url,
962
+ type: 'pdf',
963
+ onLoadingEnd: () => URL.revokeObjectURL(url),
964
+ });
965
+ });
1081
966
  };
1082
- const MRT_ToggleRowActionMenuButton = (_a) => {
1083
- var _b;
1084
- var { cell, row, staticRowIndex, table } = _a, rest = __rest(_a, ["cell", "row", "staticRowIndex", "table"]);
1085
- const { getState, options: { createDisplayMode, editDisplayMode, enableEditing, icons: { EditIcon, MoreHorizIcon }, localization, renderRowActionMenuItems, renderRowActions, }, setEditingRow, } = table;
1086
- const { creatingRow } = getState();
1087
- const isCreating = (creatingRow === null || creatingRow === void 0 ? void 0 : creatingRow.id) === row.id;
1088
- const isEditing = useMRT_SliceValue(table._uiStore, (s) => { var _a; return ((_a = s.editingRow) === null || _a === void 0 ? void 0 : _a.id) === row.id; });
1089
- const showEditActionButtons = (isCreating && createDisplayMode === 'row') ||
1090
- (isEditing && editDisplayMode === 'row');
967
+
968
+ const MRT_ExportsToolbar = ({ table, availableExports, exportState, onExportStateChange, loadExport, }) => {
969
+ const theme = styles.useTheme();
970
+ const { localization } = table.options;
971
+ const { selectedExports, selectedFormat, grouped } = exportState;
1091
972
  const [anchorEl, setAnchorEl] = react.useState(null);
1092
- const handleOpenRowActionMenu = (event) => {
1093
- event.stopPropagation();
1094
- event.preventDefault();
973
+ const [loadingExportType, setLoadingExportType] = react.useState(null);
974
+ const { rowSelection } = table.getState();
975
+ const selectedRowIds = Object.keys(rowSelection).filter((id) => rowSelection[id]);
976
+ const isNoRowsSelected = selectedRowIds.length === 0;
977
+ const availableFormats = react.useMemo(() => {
978
+ const allFormats = Object.values(availableExports).flatMap((exp) => exp.formats);
979
+ return Array.from(new Set(allFormats));
980
+ }, [availableExports]);
981
+ const hasPdfFormat = availableFormats.includes('pdf');
982
+ const exportTypesForSelectedFormat = react.useMemo(() => {
983
+ if (!selectedFormat)
984
+ return [];
985
+ return Object.values(availableExports).filter((exp) => exp.formats.includes(selectedFormat));
986
+ }, [availableExports, selectedFormat]);
987
+ const isPrintDisabled = selectedFormat !== 'pdf' ||
988
+ !selectedFormat ||
989
+ selectedExports.length < 1 ||
990
+ (!grouped && selectedExports.length > 1);
991
+ const isDownloadDisabled = !selectedFormat || selectedExports.length < 1;
992
+ const handleOpenMenu = (event) => {
1095
993
  setAnchorEl(event.currentTarget);
1096
994
  };
1097
- const handleStartEditMode = (event) => {
1098
- event.stopPropagation();
1099
- setEditingRow(Object.assign({}, row));
995
+ const handleCloseMenu = () => {
1100
996
  setAnchorEl(null);
1101
997
  };
1102
- return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: renderRowActions && !showEditActionButtons ? (renderRowActions({ cell, row, staticRowIndex, table })) : showEditActionButtons ? (jsxRuntime.jsx(MRT_EditActionButtons, { row: row, table: table })) : !renderRowActionMenuItems &&
1103
- parseFromValuesOrFunc(enableEditing, row) &&
1104
- ['modal', 'row'].includes(editDisplayMode) ? (jsxRuntime.jsx(Tooltip, { placement: "right", title: localization.edit, children: jsxRuntime.jsx(IconButton, Object.assign({ "aria-label": localization.edit, onClick: handleStartEditMode, sx: commonIconButtonStyles }, rest, { children: jsxRuntime.jsx(EditIcon, {}) })) })) : ((_b = renderRowActionMenuItems === null || renderRowActionMenuItems === void 0 ? void 0 : renderRowActionMenuItems({
1105
- closeMenu: () => { },
1106
- row,
1107
- staticRowIndex,
1108
- table,
1109
- })) === null || _b === void 0 ? void 0 : _b.length) ? (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(Tooltip, Object.assign({}, getCommonTooltipProps(), { title: localization.rowActions, children: jsxRuntime.jsx(IconButton, Object.assign({ "aria-label": localization.rowActions, onClick: handleOpenRowActionMenu, size: "small", sx: commonIconButtonStyles }, rest, { children: jsxRuntime.jsx(MoreHorizIcon, {}) })) })), jsxRuntime.jsx(MRT_RowActionMenu, { anchorEl: anchorEl, handleEdit: handleStartEditMode, row: row, setAnchorEl: setAnchorEl, staticRowIndex: staticRowIndex, table: table })] })) : null }));
1110
- };
1111
-
1112
- const getMRT_RowActionsColumnDef = (tableOptions) => {
1113
- return Object.assign({ Cell: ({ cell, row, staticRowIndex, table }) => (jsxRuntime.jsx(MRT_ToggleRowActionMenuButton, { cell: cell, row: row, staticRowIndex: staticRowIndex, table: table })) }, defaultDisplayColumnProps({
1114
- header: 'actions',
1115
- id: 'mrt-row-actions',
1116
- size: 70,
1117
- tableOptions,
1118
- }));
1119
- };
1120
-
1121
- const MRT_GrabHandleButton = (_a) => {
1122
- var _b, _c;
1123
- var { location, table } = _a, rest = __rest(_a, ["location", "table"]);
1124
- const { options: { icons: { DragHandleIcon }, localization, }, } = table;
1125
- return (jsxRuntime.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: jsxRuntime.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) => {
1126
- var _a;
1127
- e.stopPropagation();
1128
- (_a = rest === null || rest === void 0 ? void 0 : rest.onClick) === null || _a === void 0 ? void 0 : _a.call(rest, e);
1129
- }, sx: (theme) => (Object.assign({ '&:active': {
1130
- cursor: 'grabbing',
1131
- }, '&:hover': {
1132
- backgroundColor: 'transparent',
1133
- opacity: 1,
1134
- }, 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: jsxRuntime.jsx(DragHandleIcon, {}) })) })));
1135
- };
1136
-
1137
- const MRT_TableBodyRowGrabHandle = (_a) => {
1138
- var { row, rowRef, table } = _a, rest = __rest(_a, ["row", "rowRef", "table"]);
1139
- const { options: { muiRowDragHandleProps }, } = table;
1140
- const iconButtonProps = Object.assign(Object.assign({}, parseFromValuesOrFunc(muiRowDragHandleProps, {
1141
- row,
1142
- table,
1143
- })), rest);
1144
- const handleDragStart = (event) => {
1145
- var _a;
1146
- (_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.onDragStart) === null || _a === void 0 ? void 0 : _a.call(iconButtonProps, event);
1147
- try {
1148
- event.dataTransfer.setDragImage(rowRef.current, 0, 0);
1149
- }
1150
- catch (e) {
1151
- console.error(e);
1152
- }
1153
- table.setDraggingRow(row);
1154
- };
1155
- const handleDragEnd = (event) => {
1156
- var _a;
1157
- (_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.onDragEnd) === null || _a === void 0 ? void 0 : _a.call(iconButtonProps, event);
1158
- table.setDraggingRow(null);
1159
- table.setHoveredRow(null);
998
+ const handleSelectFormat = (format) => {
999
+ const newFormat = selectedFormat === format ? null : format;
1000
+ onExportStateChange((prev) => (Object.assign(Object.assign({}, (prev !== null && prev !== void 0 ? prev : { grouped: false })), { selectedExports: [], selectedFormat: newFormat })));
1160
1001
  };
1161
- return (jsxRuntime.jsx(MRT_GrabHandleButton, Object.assign({}, iconButtonProps, { location: "row", onDragEnd: handleDragEnd, onDragStart: handleDragStart, table: table })));
1162
- };
1163
-
1164
- const getMRT_RowDragColumnDef = (tableOptions) => {
1165
- return Object.assign({ Cell: ({ row, rowRef, table }) => (jsxRuntime.jsx(MRT_TableBodyRowGrabHandle, { row: row, rowRef: rowRef, table: table })), grow: false }, defaultDisplayColumnProps({
1166
- header: 'move',
1167
- id: 'mrt-row-drag',
1168
- size: 60,
1169
- tableOptions,
1170
- }));
1171
- };
1172
-
1173
- const MRT_ExpandAllButton = (_a) => {
1174
- var _b, _c;
1175
- var { table } = _a, rest = __rest(_a, ["table"]);
1176
- const { getCanSomeRowsExpand, getIsAllRowsExpanded, getIsSomeRowsExpanded, getState, options: { icons: { KeyboardDoubleArrowDownIcon }, localization, muiExpandAllButtonProps, renderDetailPanel, }, toggleAllRowsExpanded, } = table;
1177
- const { isLoading } = getState();
1178
- const density = useMRT_SliceValue(table._uiStore, (s) => s.density);
1179
- const iconButtonProps = Object.assign(Object.assign({}, parseFromValuesOrFunc(muiExpandAllButtonProps, {
1180
- table,
1181
- })), rest);
1182
- const isAllRowsExpanded = getIsAllRowsExpanded();
1183
- return (jsxRuntime.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: jsxRuntime.jsx("span", { children: jsxRuntime.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 : (jsxRuntime.jsx(KeyboardDoubleArrowDownIcon, { style: {
1184
- transform: `rotate(${isAllRowsExpanded ? -180 : getIsSomeRowsExpanded() ? -90 : 0}deg)`,
1185
- transition: 'transform 150ms',
1186
- } })) })) }) })));
1187
- };
1188
-
1189
- const MRT_ExpandButton = ({ row, staticRowIndex, table, }) => {
1190
- var _a, _b;
1191
- const theme = styles.useTheme();
1192
- const { options: { icons: { ExpandMoreIcon }, localization, maxDepth, muiExpandButtonProps, positionExpandColumn, renderDetailPanel, }, } = table;
1193
- const density = useMRT_SliceValue(table._uiStore, (s) => s.density);
1194
- const iconButtonProps = parseFromValuesOrFunc(muiExpandButtonProps, {
1195
- row,
1196
- staticRowIndex,
1197
- table,
1002
+ const handleToggleExportType = (exportName) => {
1003
+ const isAlreadySelected = selectedExports.includes(exportName);
1004
+ const newSelectedExports = isAlreadySelected
1005
+ ? selectedExports.filter((name) => name !== exportName)
1006
+ : [...selectedExports, exportName];
1007
+ onExportStateChange((prev) => (Object.assign(Object.assign({}, (prev !== null && prev !== void 0 ? prev : { selectedFormat: null, grouped: false })), { selectedExports: newSelectedExports })));
1008
+ };
1009
+ const handleToggleGrouped = () => {
1010
+ onExportStateChange((prev) => (Object.assign(Object.assign({}, (prev !== null && prev !== void 0 ? prev : { selectedFormat: null, selectedExports: [] })), { grouped: !grouped })));
1011
+ };
1012
+ const handleExportAction = (type) => __awaiter(void 0, void 0, void 0, function* () {
1013
+ setLoadingExportType(type);
1014
+ try {
1015
+ const response = yield loadExport({
1016
+ format: selectedFormat,
1017
+ exports: selectedExports,
1018
+ separated_files: !grouped,
1019
+ download: false,
1020
+ ids: JSON.stringify(selectedRowIds),
1021
+ type,
1022
+ });
1023
+ handleCloseMenu();
1024
+ if (type === 'download') {
1025
+ downloadExportFiles(response);
1026
+ }
1027
+ else {
1028
+ printExportFiles(response);
1029
+ }
1030
+ }
1031
+ finally {
1032
+ setLoadingExportType(null);
1033
+ }
1198
1034
  });
1199
- const canExpand = row.getCanExpand() && (maxDepth === undefined || row.depth < maxDepth - 1);
1200
- const isExpanded = row.getIsExpanded();
1201
- const handleToggleExpand = (event) => {
1202
- var _a;
1203
- event.stopPropagation();
1204
- row.toggleExpanded();
1205
- (_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.onClick) === null || _a === void 0 ? void 0 : _a.call(iconButtonProps, event);
1035
+ const renderFormatSelector = () => (jsxRuntime.jsx(Stack, { justifyContent: "flex-start", minWidth: "200px", sx: {
1036
+ borderRight: selectedFormat
1037
+ ? `1px dashed ${theme.palette.divider}`
1038
+ : 'none',
1039
+ }, children: jsxRuntime.jsx(FormControl, { children: jsxRuntime.jsx(RadioGroup, { value: selectedFormat !== null && selectedFormat !== void 0 ? selectedFormat : '', children: availableFormats.map((format) => (jsxRuntime.jsx(FormControlLabel, { sx: { m: 0 }, value: format, control: jsxRuntime.jsx(Radio, { size: "small", onClick: () => handleSelectFormat(format) }), label: jsxRuntime.jsx(Typography, { variant: "subtitle2", sx: { fontWeight: 800 }, children: format }) }, format))) }) }) }));
1040
+ const renderExportTypeSelector = () => {
1041
+ if (!selectedFormat || exportTypesForSelectedFormat.length === 0)
1042
+ return null;
1043
+ return (jsxRuntime.jsx(Stack, { minWidth: "250px", maxHeight: "500px", sx: { overflowY: 'auto' }, children: exportTypesForSelectedFormat.map((exportType) => (jsxRuntime.jsxs(MenuItem, { onClick: () => handleToggleExportType(exportType.name), value: exportType.name, children: [jsxRuntime.jsx(Checkbox, { checked: selectedExports.includes(exportType.name), size: "small" }), jsxRuntime.jsx(Typography, { variant: "body2", children: exportType.label })] }, exportType.name))) }));
1206
1044
  };
1207
- const detailPanel = !!(renderDetailPanel === null || renderDetailPanel === void 0 ? void 0 : renderDetailPanel({ row, table }));
1208
- return (jsxRuntime.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: jsxRuntime.jsx("span", { children: jsxRuntime.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'
1209
- ? 'mr'
1210
- : '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 : (jsxRuntime.jsx(ExpandMoreIcon, { style: {
1211
- transform: `rotate(${!canExpand && !renderDetailPanel
1212
- ? positionExpandColumn === 'last' ||
1213
- theme.direction === 'rtl'
1214
- ? 90
1215
- : -90
1216
- : isExpanded
1217
- ? -180
1218
- : 0}deg)`,
1219
- transition: 'transform 150ms',
1220
- } })) })) }) })));
1045
+ const renderActionButtons = () => {
1046
+ const isAnyLoading = loadingExportType !== null;
1047
+ return (jsxRuntime.jsxs(Stack, { direction: "row", gap: 0.5, mt: 1, mr: 2, children: [hasPdfFormat && (jsxRuntime.jsx(Button, { sx: { display: 'flex', gap: 0.5 }, disabled: isPrintDisabled || isAnyLoading, onClick: () => handleExportAction('print'), startIcon: loadingExportType === 'print' ? (jsxRuntime.jsx(CircularProgress, { size: 16, color: "inherit" })) : (jsxRuntime.jsx(PrintIcon, { fontSize: "small" })), children: localization.exportPrintPdf })), jsxRuntime.jsx(Button, { sx: { display: 'flex', gap: 0.5 }, disabled: isDownloadDisabled || isAnyLoading, onClick: () => handleExportAction('download'), startIcon: loadingExportType === 'download' ? (jsxRuntime.jsx(CircularProgress, { size: 16, color: "inherit" })) : (jsxRuntime.jsx(FileDownloadIcon, { fontSize: "small" })), children: localization.exportDownload })] }));
1048
+ };
1049
+ const renderGroupedCheckbox = () => (jsxRuntime.jsx(Stack, { mt: "auto", children: jsxRuntime.jsx(FormControlLabel, { onChange: handleToggleGrouped, sx: { m: 0 }, control: jsxRuntime.jsx(Checkbox, { checked: grouped, size: "small" }), label: jsxRuntime.jsx(Typography, { variant: "body2", children: localization.exportGrouped }) }) }));
1050
+ return (jsxRuntime.jsxs(Stack, { direction: "row", gap: 0.5, alignItems: "center", children: [jsxRuntime.jsx(Tooltip, { title: isNoRowsSelected
1051
+ ? localization.exportSelectRowsTooltip
1052
+ : localization.exportButton, children: jsxRuntime.jsx("span", { children: jsxRuntime.jsx(Button, { "aria-label": localization.exportButton, disabled: isNoRowsSelected, onClick: handleOpenMenu, size: "small", startIcon: jsxRuntime.jsx(FileDownloadIcon, { fontSize: "small" }), variant: "text", children: localization.exportButton }) }) }), jsxRuntime.jsxs(Menu, { anchorEl: anchorEl, open: Boolean(anchorEl), onClose: handleCloseMenu, anchorOrigin: { vertical: 'bottom', horizontal: 'left' }, transformOrigin: { vertical: 'top', horizontal: 'left' }, children: [jsxRuntime.jsxs(Stack, { direction: "row", sx: { px: 1, pt: 1, maxHeight: '320px', overflow: 'auto' }, children: [renderFormatSelector(), selectedFormat &&
1053
+ exportTypesForSelectedFormat.length > 0 &&
1054
+ renderExportTypeSelector()] }), jsxRuntime.jsx(Divider, { sx: { mt: 1 } }), jsxRuntime.jsxs(Stack, { direction: "row", alignItems: "center", sx: { px: 1, pb: 1 }, children: [renderActionButtons(), renderGroupedCheckbox()] })] })] }));
1221
1055
  };
1222
1056
 
1223
- const INSERT_HERE_TOOLTIP = 'Insert here';
1224
- const ACTION_ICON_SIZE$1 = 'small';
1225
- const MRT_InsertHereAction = ({ onClick, }) => {
1226
- return (jsxRuntime.jsx(Tooltip, { title: INSERT_HERE_TOOLTIP, disableInteractive: true, children: jsxRuntime.jsx(IconButton, { onClick: onClick, size: ACTION_ICON_SIZE$1, children: jsxRuntime.jsx(SubdirectoryArrowLeftIcon, { color: "warning" }) }) }));
1057
+ const MRT_ExportRowButton = ({ onClick }) => {
1058
+ return (jsxRuntime.jsx(IconButton, { sx: { p: 0 }, disableRipple: true, onClick: onClick, children: jsxRuntime.jsx(FileDownloadIcon, { fontSize: "small" }) }));
1227
1059
  };
1228
1060
 
1229
- const MOVE_TO_TOP_TOOLTIP = 'Move to top level';
1230
- const ACTION_ICON_SIZE = 'small';
1231
- const ACTION_BUTTON_HEIGHT = '1.75rem';
1232
- const MRT_MoveToTopAction = ({ onClick }) => {
1233
- return (jsxRuntime.jsx(Tooltip, { title: MOVE_TO_TOP_TOOLTIP, disableInteractive: true, children: jsxRuntime.jsx(IconButton, { onClick: onClick, size: ACTION_ICON_SIZE, sx: { height: ACTION_BUTTON_HEIGHT }, children: jsxRuntime.jsx(VerticalAlignTopIcon, { fontSize: "small" }) }) }));
1061
+ const MRT_PrintRowButton = ({ onClick }) => {
1062
+ return (jsxRuntime.jsx(IconButton, { sx: { p: 0 }, disableRipple: true, onClick: onClick, children: jsxRuntime.jsx(PrintIcon, { fontSize: "small" }) }));
1234
1063
  };
1235
1064
 
1236
- const MRT_ReorderRowCheckbox = ({ onChange, isSelected, }) => {
1237
- return (jsxRuntime.jsx(Checkbox, { checked: isSelected, color: "warning", disableRipple: true, onChange: onChange, sx: {
1238
- color: (theme) => theme.palette.warning.main,
1239
- '&.Mui-checked': {
1240
- color: (theme) => theme.palette.warning.main,
1241
- },
1242
- } }));
1065
+ const ExportRowAction = ({ onExport, onPrint }) => {
1066
+ return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(MRT_ExportRowButton, { onClick: onExport }), onPrint && jsxRuntime.jsx(MRT_PrintRowButton, { onClick: onPrint })] }));
1243
1067
  };
1244
1068
 
1245
- /**
1246
- * Finds the maximum depth in the hierarchy of a given row (recursively searches all descendants).
1247
- * Used to determine the "size" of the tree being moved.
1248
- * Example: Row at depth 1 with a child at depth 3 → returns 3
1249
- */
1250
- const getDeepestSubRowDepth = (row) => {
1251
- var _a;
1252
- if (!((_a = row.subRows) === null || _a === void 0 ? void 0 : _a.length)) {
1253
- return row.depth;
1254
- }
1255
- return row.subRows.reduce((maxDepth, subRow) => Math.max(maxDepth, getDeepestSubRowDepth(subRow)), row.depth);
1256
- };
1257
- /**
1258
- * Extracts an array of IDs of only the selected rows from the selection object.
1259
- * Filters the record where the value is true and maps only the keys (IDs).
1260
- * Example: { row1: true, row2: false, row3: true } → ['row1', 'row3']
1261
- */
1262
- const getSelectedReorderRowIds = (rowReorderingSelection) => {
1263
- return Object.entries(rowReorderingSelection !== null && rowReorderingSelection !== void 0 ? rowReorderingSelection : {})
1264
- .filter(([, isSelected]) => isSelected)
1265
- .map(([rowId]) => rowId);
1266
- };
1267
- /**
1268
- * Checks WHETHER we can move selected rows as children of target row
1269
- * without exceeding the maximum allowed depth.
1270
- * Directly calculates the final maximum depth after the move.
1271
- * Example: selectedRows at depth 1-2 with descendants to depth 4, target depth 1, maxDepth 5
1272
- * → new max depth = 1 + 1 + (4 - 1) = 5, which equals maxDepth, so returns false
1273
- */
1274
- const canInsertSelectedRowsWithoutExceedingMaxDepth = ({ maxDepth, selectedRows, targetRowDepth, }) => {
1275
- // Cannot insert if there are no selected rows to move
1276
- if (selectedRows.length === 0) {
1277
- return false;
1278
- }
1279
- // No depth restriction - can insert anywhere
1280
- if (maxDepth === undefined) {
1281
- return true;
1282
- }
1283
- // Find the deepest descendant among all selected rows
1284
- const maxDeepestDescendantDepth = selectedRows.reduce((max, row) => {
1285
- return Math.max(max, getDeepestSubRowDepth(row));
1286
- }, 0);
1287
- // Find the minimum depth of selected rows (to calculate relative depth)
1288
- const minSelectedRowDepth = Math.min(...selectedRows.map((r) => r.depth));
1289
- // Calculate the maximum depth after moving rows as children of target
1290
- // newMaxDepth = target.depth + 1 (as children) + relative depth of selected rows
1291
- const newMaxDepth = targetRowDepth + 1 + (maxDeepestDescendantDepth - minSelectedRowDepth);
1292
- return newMaxDepth < maxDepth;
1293
- };
1294
- /**
1295
- * Finds the depth of the FIRST selected row in the selection object.
1296
- * Used to enforce constraint: can only select rows at the SAME depth.
1297
- * Example: If I select a row at depth 2, I cannot select a row at depth 3
1298
- */
1299
- const getFirstSelectedReorderRowDepth = ({ rowReorderingSelection, table, }) => {
1300
- var _a, _b;
1301
- const firstSelectedRowId = (_a = Object.entries(rowReorderingSelection !== null && rowReorderingSelection !== void 0 ? rowReorderingSelection : {}).find(([, isSelected]) => isSelected)) === null || _a === void 0 ? void 0 : _a[0];
1302
- if (!firstSelectedRowId) {
1303
- return undefined;
1304
- }
1305
- return (_b = table.getRow(firstSelectedRowId, true)) === null || _b === void 0 ? void 0 : _b.depth;
1306
- };
1307
- /**
1308
- * Checks WHETHER we can select a specific row.
1309
- * Rule: If a selection already exists, new row MUST be at the SAME depth as the first selected.
1310
- * Without this, you could move rows from different levels which would break the hierarchy.
1311
- */
1312
- const canSelectRowForReorder = ({ rowId, rowDepth, rowReorderingSelection, firstSelectedReorderRowDepth, }) => {
1313
- const isCurrentRowSelected = !!(rowReorderingSelection === null || rowReorderingSelection === void 0 ? void 0 : rowReorderingSelection[rowId]);
1314
- if (isCurrentRowSelected) {
1315
- return true;
1316
- }
1317
- const hasAnySelection = Object.values(rowReorderingSelection !== null && rowReorderingSelection !== void 0 ? rowReorderingSelection : {}).some(Boolean);
1318
- if (!hasAnySelection) {
1319
- return true;
1320
- }
1321
- return rowDepth === firstSelectedReorderRowDepth;
1322
- };
1323
- /**
1324
- * Creates an array of MRT_Row objects from an array of IDs.
1325
- * Finds each row from the table and collects it in the result.
1326
- * Used to prepare data for the onTreeRowReorder callback.
1327
- */
1328
- const buildSelectedRowsArray = (selectedRowIds, table) => {
1329
- return selectedRowIds.reduce((selectedRows, selectedRowId) => {
1330
- const selectedRow = table.getRow(selectedRowId, true);
1331
- if (selectedRow) {
1332
- selectedRows.push(selectedRow);
1333
- }
1334
- return selectedRows;
1335
- }, []);
1069
+ const hasActiveExports = (table) => {
1070
+ const { activeExports } = table.getState();
1071
+ return !!((activeExports === null || activeExports === void 0 ? void 0 : activeExports.selectedFormat) && activeExports.selectedExports.length > 0);
1336
1072
  };
1337
- /**
1338
- * Helper function to check if a row is a descendant of another row.
1339
- * Recursively searches through all subRows to find if targetRowId exists.
1340
- * Used to prevent circular references (parent cannot become child of its own child).
1341
- */
1342
- const isRowInSubtreeOf = (targetRowId, parentRow) => {
1073
+ // Same conditions as MRT_ExportsToolbar: pdf format selected, at least one export type,
1074
+ // and either grouped or exactly one export type selected.
1075
+ const isPrintAvailable = (table) => {
1343
1076
  var _a;
1344
- if (!((_a = parentRow.subRows) === null || _a === void 0 ? void 0 : _a.length)) {
1077
+ const allFormats = Object.values((_a = table.options.availableExports) !== null && _a !== void 0 ? _a : {}).flatMap((e) => e.formats);
1078
+ if (!allFormats.includes('pdf'))
1345
1079
  return false;
1346
- }
1347
- for (const subRow of parentRow.subRows) {
1348
- if (subRow.id === targetRowId) {
1349
- return true;
1350
- }
1351
- if (isRowInSubtreeOf(targetRowId, subRow)) {
1352
- return true;
1353
- }
1354
- }
1355
- return false;
1080
+ const { activeExports } = table.getState();
1081
+ if (!activeExports)
1082
+ return false;
1083
+ const { selectedFormat, selectedExports, grouped } = activeExports;
1084
+ return (selectedFormat === 'pdf' &&
1085
+ selectedExports.length >= 1 &&
1086
+ (grouped || selectedExports.length === 1));
1356
1087
  };
1357
- /**
1358
- * Checks if a row can be used as a valid insert target for selected rows.
1359
- * Rules: Target row must NOT be already selected AND must NOT be a descendant of any selected row.
1360
- * This prevents circular references where a parent becomes a child of its own descendants.
1361
- * Example: If you select "Department", you cannot insert it under "Project" (which is its descendant)
1362
- */
1363
- const isValidInsertTarget = ({ targetRowId, selectedRowIds, table, }) => {
1364
- // Rule 1: Target row cannot be already selected
1365
- if (selectedRowIds.includes(targetRowId) || selectedRowIds.length === 0) {
1366
- return false;
1367
- }
1368
- // Rule 2: Target row cannot be a descendant of any selected row
1369
- // (prevents parent from becoming child of its own descendants)
1370
- for (const selectedRowId of selectedRowIds) {
1371
- const selectedRow = table.getRow(selectedRowId, true);
1372
- if (selectedRow &&
1373
- isRowInSubtreeOf(targetRowId, selectedRow)) {
1374
- return false;
1375
- }
1376
- }
1377
- return true;
1378
- };
1379
-
1380
- const useTreeRowReorderingCell = ({ row, table, rowReorderingSelection, maxDepth, onTreeRowReorder, }) => {
1381
- const [isRowHovered, setIsRowHovered] = react.useState(false);
1382
- const firstSelectedReorderRowDepth = getFirstSelectedReorderRowDepth({
1383
- rowReorderingSelection,
1384
- table,
1385
- });
1386
- const canSelectForReorder = canSelectRowForReorder({
1387
- rowId: row.id,
1388
- rowDepth: row.depth,
1389
- rowReorderingSelection,
1390
- firstSelectedReorderRowDepth,
1088
+ const createExportAction = (_a = {}) => {
1089
+ var { onExport, renderRow: customRenderRow, renderToolbar: customRenderToolbar } = _a, rest = __rest(_a, ["onExport", "renderRow", "renderToolbar"]);
1090
+ // Pure download logic — no notifications. Throws on failure so callers can handle it.
1091
+ const defaultOnExport = (_a) => __awaiter(void 0, [_a], void 0, function* ({ rowsToExport, table, }) {
1092
+ if (!rowsToExport.length)
1093
+ return;
1094
+ const { loadExport } = table.options;
1095
+ const { activeExports } = table.getState();
1096
+ if (!loadExport || !activeExports)
1097
+ return;
1098
+ const response = yield loadExport({
1099
+ format: activeExports.selectedFormat,
1100
+ exports: activeExports.selectedExports,
1101
+ separated_files: !activeExports.grouped,
1102
+ download: false,
1103
+ ids: JSON.stringify(rowsToExport.map((r) => r.id)),
1104
+ type: 'download',
1105
+ });
1106
+ downloadExportFiles(response);
1391
1107
  });
1392
- const hasAnyReorderSelection = Object.values(rowReorderingSelection !== null && rowReorderingSelection !== void 0 ? rowReorderingSelection : {}).some(Boolean);
1393
- const selectedReorderRowIds = getSelectedReorderRowIds(rowReorderingSelection);
1394
- const selectedRowsForReorder = buildSelectedRowsArray(selectedReorderRowIds, table);
1395
- const shouldShowReorderCheckbox = canSelectForReorder && (isRowHovered || hasAnyReorderSelection);
1396
- const shouldShowInsertHereAction = selectedReorderRowIds.length > 0 &&
1397
- isValidInsertTarget({
1398
- targetRowId: row.id,
1399
- selectedRowIds: selectedReorderRowIds,
1400
- table,
1401
- }) &&
1402
- canInsertSelectedRowsWithoutExceedingMaxDepth({
1403
- maxDepth,
1404
- selectedRows: selectedRowsForReorder,
1405
- targetRowDepth: row.depth,
1108
+ // Pure print logic — no notifications. Throws on failure so callers can handle it.
1109
+ const defaultOnPrint = (_a) => __awaiter(void 0, [_a], void 0, function* ({ rowsToExport, table, }) {
1110
+ if (!rowsToExport.length)
1111
+ return;
1112
+ const { loadExport } = table.options;
1113
+ const { activeExports } = table.getState();
1114
+ if (!loadExport || !activeExports)
1115
+ return;
1116
+ const response = yield loadExport({
1117
+ format: activeExports.selectedFormat,
1118
+ exports: activeExports.selectedExports,
1119
+ separated_files: !activeExports.grouped,
1120
+ download: false,
1121
+ ids: JSON.stringify(rowsToExport.map((r) => r.id)),
1122
+ type: 'print',
1406
1123
  });
1407
- const handleReorderCheckboxChange = react.useCallback((event) => {
1408
- const checked = event.target.checked;
1409
- table.setRowReorderingSelection((prev) => (Object.assign(Object.assign({}, prev), { [row.id]: checked })));
1410
- }, [row.id, table]);
1411
- const handleInsertHereActionClick = react.useCallback(() => {
1412
- if (!onTreeRowReorder) {
1413
- console.warn('[MRT] onTreeRowReorder callback is not defined');
1124
+ printExportFiles(response);
1125
+ });
1126
+ // Single execution pipeline for every export flow (row or toolbar).
1127
+ // If a custom handler exists, it receives defaultOnExport and decides when to call it.
1128
+ const executeExport = (context) => {
1129
+ const executeDefaultExport = () => defaultOnExport(context);
1130
+ if (onExport) {
1131
+ return onExport(Object.assign(Object.assign({}, context), { defaultOnExport: executeDefaultExport }));
1132
+ }
1133
+ return executeDefaultExport();
1134
+ };
1135
+ // Row download: checks for active exports, then wraps with loading/success/error notifications.
1136
+ const handleSingleRowExport = (_a) => __awaiter(void 0, [_a], void 0, function* ({ table, row, }) {
1137
+ const { localization } = table.options;
1138
+ if (!hasActiveExports(table)) {
1139
+ notistack.enqueueSnackbar(localization.exportNoExportsSelected, {
1140
+ variant: 'warning',
1141
+ });
1414
1142
  return;
1415
1143
  }
1144
+ const loadingKey = notistack.enqueueSnackbar(localization.exportInProgress, {
1145
+ variant: 'info',
1146
+ persist: true,
1147
+ });
1416
1148
  try {
1417
- const treeRowReorderEvent = {
1418
- selectedRowIds: selectedReorderRowIds,
1419
- selectedRows: selectedRowsForReorder,
1420
- table,
1421
- targetRow: row,
1422
- };
1423
- onTreeRowReorder(treeRowReorderEvent);
1149
+ yield executeExport({ table, rowsToExport: [row] });
1150
+ notistack.closeSnackbar(loadingKey);
1151
+ notistack.enqueueSnackbar(localization.exportSuccess, { variant: 'success' });
1424
1152
  }
1425
- catch (error) {
1426
- console.error('[MRT] Error during tree row reorder:', error);
1153
+ catch (_b) {
1154
+ notistack.closeSnackbar(loadingKey);
1155
+ notistack.enqueueSnackbar(localization.exportError, { variant: 'error' });
1427
1156
  }
1428
- }, [
1429
- onTreeRowReorder,
1430
- selectedReorderRowIds,
1431
- selectedRowsForReorder,
1432
- table,
1433
- row,
1434
- ]);
1435
- return {
1436
- isRowHovered,
1437
- shouldShowReorderCheckbox,
1438
- shouldShowInsertHereAction,
1439
- handleRowHoverEnter: () => setIsRowHovered(true),
1440
- handleRowHoverLeave: () => setIsRowHovered(false),
1441
- handleReorderCheckboxChange,
1442
- handleInsertHereActionClick,
1443
- isReorderCheckboxSelected: !!(rowReorderingSelection === null || rowReorderingSelection === void 0 ? void 0 : rowReorderingSelection[row.id]),
1444
- };
1445
- };
1446
-
1447
- const useTreeRowReorderingHeader = ({ table, enableRowReordering, onTreeRowReorder, }) => {
1448
- const rowReorderingSelection = useMRT_SliceValue(table._uiStore, (s) => s.rowReorderingSelection);
1449
- const selectedReorderRowIds = getSelectedReorderRowIds(rowReorderingSelection);
1450
- const selectedRowsForReorder = buildSelectedRowsArray(selectedReorderRowIds, table);
1451
- const shouldShowMoveToTopLevelAction = !!enableRowReordering &&
1452
- selectedRowsForReorder.length > 0 &&
1453
- selectedRowsForReorder.some((selectedRow) => selectedRow.depth > 0);
1454
- const handleMoveToTopLevelActionClick = react.useCallback(() => {
1455
- if (!onTreeRowReorder) {
1456
- console.warn('[MRT] onTreeRowReorder callback is not defined');
1157
+ });
1158
+ // Row print: same guard + notification pattern as download, but calls defaultOnPrint.
1159
+ const handleSingleRowPrint = (_a) => __awaiter(void 0, [_a], void 0, function* ({ table, row, }) {
1160
+ const { localization } = table.options;
1161
+ if (!hasActiveExports(table)) {
1162
+ notistack.enqueueSnackbar(localization.exportNoExportsSelected, {
1163
+ variant: 'warning',
1164
+ });
1457
1165
  return;
1458
1166
  }
1167
+ const loadingKey = notistack.enqueueSnackbar(localization.exportInProgress, {
1168
+ variant: 'info',
1169
+ persist: true,
1170
+ });
1459
1171
  try {
1460
- const treeRowReorderEvent = {
1461
- selectedRowIds: selectedReorderRowIds,
1462
- selectedRows: selectedRowsForReorder,
1463
- table,
1464
- targetRow: null,
1465
- };
1466
- onTreeRowReorder(treeRowReorderEvent);
1172
+ yield defaultOnPrint({ table, rowsToExport: [row] });
1173
+ notistack.closeSnackbar(loadingKey);
1174
+ notistack.enqueueSnackbar(localization.exportSuccess, { variant: 'success' });
1467
1175
  }
1468
- catch (error) {
1469
- console.error('[MRT] Error during tree row reorder to top level:', error);
1176
+ catch (_b) {
1177
+ notistack.closeSnackbar(loadingKey);
1178
+ notistack.enqueueSnackbar(localization.exportError, { variant: 'error' });
1470
1179
  }
1471
- }, [onTreeRowReorder, selectedReorderRowIds, selectedRowsForReorder, table]);
1472
- return {
1473
- shouldShowMoveToTopLevelAction,
1474
- handleMoveToTopLevelActionClick,
1180
+ });
1181
+ // Resolves selected rows from table state for toolbar-triggered export (custom renderToolbar only).
1182
+ const handleMultipleRowExport = ({ table, }) => {
1183
+ const rowsToExport = table.getSelectedRowModel().rows;
1184
+ return executeExport({ table, rowsToExport });
1475
1185
  };
1476
- };
1477
-
1478
- const TREE_REORDER_ICON_SPACING = '0.25rem';
1479
- const getMRT_RowExpandColumnDef = (tableOptions) => {
1480
- var _a;
1481
- const { defaultColumn, enableRowReordering, enableExpandAll, groupedColumnMode, maxDepth, onTreeRowReorder, positionExpandColumn, renderDetailPanel, state: { grouping }, } = tableOptions;
1482
- const alignProps = positionExpandColumn === 'last'
1483
- ? {
1484
- align: 'right',
1186
+ const createRowExportExecutor = (context) => () => {
1187
+ void handleSingleRowExport(context);
1188
+ };
1189
+ const createRowPrintExecutor = (context) => () => {
1190
+ void handleSingleRowPrint(context);
1191
+ };
1192
+ const createToolbarExportExecutor = (context) => () => {
1193
+ void handleMultipleRowExport(context);
1194
+ };
1195
+ // Renders download + optional print button. Print is shown under the same conditions
1196
+ // as in MRT_ExportsToolbar: pdf format selected, active exports, grouped or single type.
1197
+ const renderRowAction = (context) => {
1198
+ const onRowExport = createRowExportExecutor(context);
1199
+ const onRowPrint = isPrintAvailable(context.table)
1200
+ ? createRowPrintExecutor(context)
1201
+ : undefined;
1202
+ if (customRenderRow) {
1203
+ return customRenderRow(Object.assign(Object.assign({}, context), { onExport: onRowExport }));
1485
1204
  }
1486
- : undefined;
1487
- return Object.assign(Object.assign({ Cell: ({ cell, column, row, staticRowIndex, table }) => {
1488
- var _a, _b, _c;
1489
- const rowReorderingSelection = useMRT_SliceValue(table._uiStore, (s) => s.rowReorderingSelection);
1490
- const cellLogic = useTreeRowReorderingCell({
1491
- row,
1492
- table,
1493
- rowReorderingSelection,
1494
- maxDepth,
1495
- onTreeRowReorder,
1205
+ return jsxRuntime.jsx(ExportRowAction, { onExport: onRowExport, onPrint: onRowPrint });
1206
+ };
1207
+ // Uses custom toolbar renderer when provided; otherwise renders MRT_ExportsToolbar.
1208
+ // loadExport is always wrapped with notifications so that loading/success/error are shown
1209
+ // regardless of whether a custom onExport handler was provided.
1210
+ // When onExport is provided, it intercepts the call and returns [] so MRT_ExportsToolbar
1211
+ // does not attempt a second download from an empty response.
1212
+ const renderToolbarAction = (context) => {
1213
+ const { table } = context;
1214
+ const { availableExports, loadExport, onActiveExportsChange, localization, } = table.options;
1215
+ const { activeExports } = table.getState();
1216
+ if (customRenderToolbar) {
1217
+ return customRenderToolbar(Object.assign(Object.assign({}, context), { onExport: createToolbarExportExecutor(context) }));
1218
+ }
1219
+ if (!availableExports ||
1220
+ !loadExport ||
1221
+ !onActiveExportsChange ||
1222
+ !activeExports) {
1223
+ return null;
1224
+ }
1225
+ const notifiedLoadExport = (params) => __awaiter(void 0, void 0, void 0, function* () {
1226
+ const loadingKey = notistack.enqueueSnackbar(localization.exportInProgress, {
1227
+ variant: 'info',
1228
+ persist: true,
1496
1229
  });
1497
- const expandButtonProps = { row, staticRowIndex, table };
1498
- const subRowsLength = (_a = row.subRows) === null || _a === void 0 ? void 0 : _a.length;
1499
- const customGroupedCell = (_c = (_b = column.columnDef).GroupedCell) === null || _c === void 0 ? void 0 : _c.call(_b, {
1500
- cell,
1501
- column,
1502
- row,
1503
- table,
1504
- staticRowIndex,
1505
- });
1506
- if (groupedColumnMode === 'remove' && row.groupingColumnId) {
1507
- const defaultGroupedCell = (jsxRuntime.jsx(Tooltip, Object.assign({}, getCommonTooltipProps('right'), { title: table.getColumn(row.groupingColumnId).columnDef.header, children: jsxRuntime.jsx("span", { children: row.groupingValue }) })));
1508
- return (jsxRuntime.jsxs(Stack, { alignItems: "center", flexDirection: "row", gap: TREE_REORDER_ICON_SPACING, onMouseEnter: cellLogic.handleRowHoverEnter, onMouseLeave: cellLogic.handleRowHoverLeave, width: "100%", children: [jsxRuntime.jsx(MRT_ExpandButton, Object.assign({}, expandButtonProps)), column.columnDef.GroupedCell
1509
- ? customGroupedCell
1510
- : defaultGroupedCell, cellLogic.shouldShowReorderCheckbox && (jsxRuntime.jsx(MRT_ReorderRowCheckbox, { isSelected: cellLogic.isReorderCheckboxSelected, onChange: cellLogic.handleReorderCheckboxChange })), cellLogic.shouldShowInsertHereAction && (jsxRuntime.jsx(MRT_InsertHereAction, { onClick: cellLogic.handleInsertHereActionClick })), !!subRowsLength && jsxRuntime.jsxs("span", { children: ["(", subRowsLength, ")"] })] }));
1230
+ try {
1231
+ let response;
1232
+ if (onExport) {
1233
+ const rowsToExport = table.getSelectedRowModel().rows;
1234
+ yield executeExport({ table, rowsToExport });
1235
+ response = [];
1236
+ }
1237
+ else {
1238
+ response = yield loadExport(params);
1239
+ }
1240
+ notistack.closeSnackbar(loadingKey);
1241
+ notistack.enqueueSnackbar(localization.exportSuccess, { variant: 'success' });
1242
+ return response;
1511
1243
  }
1512
- return (jsxRuntime.jsxs(Stack, { alignItems: "center", flexDirection: "row", gap: TREE_REORDER_ICON_SPACING, onMouseEnter: cellLogic.handleRowHoverEnter, onMouseLeave: cellLogic.handleRowHoverLeave, width: "100%", children: [jsxRuntime.jsx(MRT_ExpandButton, Object.assign({}, expandButtonProps)), customGroupedCell, cellLogic.shouldShowReorderCheckbox && (jsxRuntime.jsx(MRT_ReorderRowCheckbox, { isSelected: cellLogic.isReorderCheckboxSelected, onChange: cellLogic.handleReorderCheckboxChange })), cellLogic.shouldShowInsertHereAction && (jsxRuntime.jsx(MRT_InsertHereAction, { onClick: cellLogic.handleInsertHereActionClick }))] }));
1513
- }, Header: enableExpandAll
1514
- ? ({ table }) => {
1515
- var _a;
1516
- const headerLogic = useTreeRowReorderingHeader({
1517
- table,
1518
- enableRowReordering,
1519
- onTreeRowReorder,
1520
- });
1521
- return (jsxRuntime.jsxs(Stack, { alignItems: "center", flexDirection: "row", gap: TREE_REORDER_ICON_SPACING, children: [jsxRuntime.jsx(MRT_ExpandAllButton, { table: table }), headerLogic.shouldShowMoveToTopLevelAction && (jsxRuntime.jsx(MRT_MoveToTopAction, { onClick: headerLogic.handleMoveToTopLevelActionClick })), groupedColumnMode === 'remove' &&
1522
- ((_a = grouping === null || grouping === void 0 ? void 0 : grouping.map((groupedColumnId) => table.getColumn(groupedColumnId).columnDef.header)) === null || _a === void 0 ? void 0 : _a.join(', '))] }));
1244
+ catch (_a) {
1245
+ notistack.closeSnackbar(loadingKey);
1246
+ notistack.enqueueSnackbar(localization.exportError, { variant: 'error' });
1247
+ return [];
1523
1248
  }
1524
- : undefined, muiTableBodyCellProps: alignProps, muiTableHeadCellProps: alignProps }, defaultDisplayColumnProps({
1525
- header: 'expand',
1526
- id: 'mrt-row-expand',
1527
- size: groupedColumnMode === 'remove'
1528
- ? ((_a = defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.size) !== null && _a !== void 0 ? _a : 180)
1529
- : renderDetailPanel
1530
- ? enableExpandAll
1531
- ? 60
1532
- : 70
1533
- : 100,
1534
- tableOptions,
1535
- })), { enableResizing: true });
1249
+ });
1250
+ return (jsxRuntime.jsx(MRT_ExportsToolbar, { table: table, availableExports: availableExports, exportState: activeExports, onExportStateChange: onActiveExportsChange, loadExport: notifiedLoadExport }));
1251
+ };
1252
+ return Object.assign({ name: 'export', renderRow: renderRowAction, renderToolbar: renderToolbarAction }, rest);
1536
1253
  };
1537
1254
 
1538
- const getMRT_RowNumbersColumnDef = (tableOptions) => {
1539
- const { localization, rowNumberDisplayMode } = tableOptions;
1540
- const { pagination: { pageIndex, pageSize }, } = tableOptions.state;
1541
- return Object.assign({ Cell: ({ row, staticRowIndex }) => {
1542
- var _a;
1543
- return ((_a = (rowNumberDisplayMode === 'static'
1544
- ? (staticRowIndex || 0) + (pageSize || 0) * (pageIndex || 0)
1545
- : row.index)) !== null && _a !== void 0 ? _a : 0) + 1;
1546
- }, Header: () => localization.rowNumber, grow: false }, defaultDisplayColumnProps({
1547
- header: 'rowNumbers',
1548
- id: 'mrt-row-numbers',
1549
- size: 50,
1550
- tableOptions,
1551
- }));
1255
+ const MRT_AggregationFns = Object.assign({}, reactTable.aggregationFns);
1256
+
1257
+ const fuzzy = (row, columnId, filterValue, addMeta) => {
1258
+ const itemRank = matchSorterUtils.rankItem(row.getValue(columnId), filterValue, {
1259
+ threshold: matchSorterUtils.rankings.MATCHES,
1260
+ });
1261
+ addMeta(itemRank);
1262
+ return itemRank.passed;
1263
+ };
1264
+ fuzzy.autoRemove = (val) => !val;
1265
+ const contains = (row, id, filterValue) => {
1266
+ var _a;
1267
+ return !!((_a = row
1268
+ .getValue(id)) === null || _a === void 0 ? void 0 : _a.toString().toLowerCase().trim().includes(filterValue.toString().toLowerCase().trim()));
1269
+ };
1270
+ contains.autoRemove = (val) => !val;
1271
+ const startsWith = (row, id, filterValue) => {
1272
+ var _a;
1273
+ return !!((_a = row
1274
+ .getValue(id)) === null || _a === void 0 ? void 0 : _a.toString().toLowerCase().trim().startsWith(filterValue.toString().toLowerCase().trim()));
1275
+ };
1276
+ startsWith.autoRemove = (val) => !val;
1277
+ const endsWith = (row, id, filterValue) => {
1278
+ var _a;
1279
+ return !!((_a = row
1280
+ .getValue(id)) === null || _a === void 0 ? void 0 : _a.toString().toLowerCase().trim().endsWith(filterValue.toString().toLowerCase().trim()));
1281
+ };
1282
+ endsWith.autoRemove = (val) => !val;
1283
+ const equals = (row, id, filterValue) => {
1284
+ var _a;
1285
+ return ((_a = row.getValue(id)) === null || _a === void 0 ? void 0 : _a.toString().toLowerCase().trim()) ===
1286
+ filterValue.toString().toLowerCase().trim();
1287
+ };
1288
+ equals.autoRemove = (val) => !val;
1289
+ const notEquals = (row, id, filterValue) => {
1290
+ var _a;
1291
+ return ((_a = row.getValue(id)) === null || _a === void 0 ? void 0 : _a.toString().toLowerCase().trim()) !==
1292
+ filterValue.toString().toLowerCase().trim();
1293
+ };
1294
+ notEquals.autoRemove = (val) => !val;
1295
+ const greaterThan = (row, id, filterValue) => {
1296
+ var _a, _b, _c;
1297
+ return !isNaN(+filterValue) && !isNaN(+row.getValue(id))
1298
+ ? +((_a = row.getValue(id)) !== null && _a !== void 0 ? _a : 0) > +filterValue
1299
+ : ((_c = ((_b = row.getValue(id)) !== null && _b !== void 0 ? _b : '')) === null || _c === void 0 ? void 0 : _c.toString().toLowerCase().trim()) > filterValue.toString().toLowerCase().trim();
1300
+ };
1301
+ greaterThan.autoRemove = (val) => !val;
1302
+ const greaterThanOrEqualTo = (row, id, filterValue) => equals(row, id, filterValue) || greaterThan(row, id, filterValue);
1303
+ greaterThanOrEqualTo.autoRemove = (val) => !val;
1304
+ const lessThan = (row, id, filterValue) => {
1305
+ var _a, _b, _c;
1306
+ return !isNaN(+filterValue) && !isNaN(+row.getValue(id))
1307
+ ? +((_a = row.getValue(id)) !== null && _a !== void 0 ? _a : 0) < +filterValue
1308
+ : ((_c = ((_b = row.getValue(id)) !== null && _b !== void 0 ? _b : '')) === null || _c === void 0 ? void 0 : _c.toString().toLowerCase().trim()) < filterValue.toString().toLowerCase().trim();
1309
+ };
1310
+ lessThan.autoRemove = (val) => !val;
1311
+ const lessThanOrEqualTo = (row, id, filterValue) => equals(row, id, filterValue) || lessThan(row, id, filterValue);
1312
+ lessThanOrEqualTo.autoRemove = (val) => !val;
1313
+ const between = (row, id, filterValues) => (['', undefined].includes(filterValues[0]) ||
1314
+ greaterThan(row, id, filterValues[0])) &&
1315
+ ((!isNaN(+filterValues[0]) &&
1316
+ !isNaN(+filterValues[1]) &&
1317
+ +filterValues[0] > +filterValues[1]) ||
1318
+ ['', undefined].includes(filterValues[1]) ||
1319
+ lessThan(row, id, filterValues[1]));
1320
+ between.autoRemove = (val) => !val;
1321
+ const betweenInclusive = (row, id, filterValues) => (['', undefined].includes(filterValues[0]) ||
1322
+ greaterThanOrEqualTo(row, id, filterValues[0])) &&
1323
+ ((!isNaN(+filterValues[0]) &&
1324
+ !isNaN(+filterValues[1]) &&
1325
+ +filterValues[0] > +filterValues[1]) ||
1326
+ ['', undefined].includes(filterValues[1]) ||
1327
+ lessThanOrEqualTo(row, id, filterValues[1]));
1328
+ betweenInclusive.autoRemove = (val) => !val;
1329
+ const empty = (row, id, _filterValue) => { var _a; return !((_a = row.getValue(id)) === null || _a === void 0 ? void 0 : _a.toString().trim()); };
1330
+ empty.autoRemove = (val) => !val;
1331
+ const notEmpty = (row, id, _filterValue) => { var _a; return !!((_a = row.getValue(id)) === null || _a === void 0 ? void 0 : _a.toString().trim()); };
1332
+ notEmpty.autoRemove = (val) => !val;
1333
+ const MRT_FilterFns = Object.assign(Object.assign({}, reactTable.filterFns), { between,
1334
+ betweenInclusive,
1335
+ contains,
1336
+ empty,
1337
+ endsWith,
1338
+ equals,
1339
+ fuzzy,
1340
+ greaterThan,
1341
+ greaterThanOrEqualTo,
1342
+ lessThan,
1343
+ lessThanOrEqualTo,
1344
+ notEmpty,
1345
+ notEquals,
1346
+ startsWith });
1347
+
1348
+ const useMRT_SliceValue = (store, selector) => {
1349
+ const getSnapshot = () => selector(store.get());
1350
+ return react.useSyncExternalStore(store.subscribe, getSnapshot, getSnapshot);
1552
1351
  };
1553
1352
 
1554
- const MRT_RowPinButton = (_a) => {
1555
- var { pinningPosition, row, table } = _a, rest = __rest(_a, ["pinningPosition", "row", "table"]);
1556
- const { options: { icons: { CloseIcon, PushPinIcon }, localization, rowPinningDisplayMode, }, } = table;
1557
- const isPinned = row.getIsPinned();
1558
- const [tooltipOpened, setTooltipOpened] = react.useState(false);
1559
- const handleTogglePin = (event) => {
1560
- setTooltipOpened(false);
1561
- event.stopPropagation();
1562
- row.pin(isPinned ? false : pinningPosition);
1563
- };
1564
- return (jsxRuntime.jsx(Tooltip, Object.assign({}, getCommonTooltipProps(), { open: tooltipOpened, title: isPinned ? localization.unpin : localization.pin, children: jsxRuntime.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 ? (jsxRuntime.jsx(CloseIcon, {})) : (jsxRuntime.jsx(PushPinIcon, { fontSize: "small", style: {
1565
- transform: `rotate(${rowPinningDisplayMode === 'sticky'
1566
- ? 135
1567
- : pinningPosition === 'top'
1568
- ? 180
1569
- : 0}deg)`,
1570
- } })) })) })));
1353
+ const MRT_ActionMenuItem = (_a) => {
1354
+ var { icon, label, onOpenSubMenu, table } = _a, rest = __rest(_a, ["icon", "label", "onOpenSubMenu", "table"]);
1355
+ const { options: { icons: { ArrowRightIcon }, }, } = table;
1356
+ return (jsxRuntime.jsxs(MenuItem, Object.assign({ sx: {
1357
+ alignItems: 'center',
1358
+ justifyContent: 'space-between',
1359
+ minWidth: '120px',
1360
+ my: 0,
1361
+ py: '6px',
1362
+ }, tabIndex: 0 }, rest, { children: [jsxRuntime.jsxs(Box, { sx: {
1363
+ alignItems: 'center',
1364
+ display: 'flex',
1365
+ }, children: [jsxRuntime.jsx(ListItemIcon, { children: icon }), label] }), onOpenSubMenu && (jsxRuntime.jsx(IconButton, { onClick: (e) => onOpenSubMenu(e), onMouseEnter: (e) => onOpenSubMenu(e), size: "small", sx: { p: 0 }, children: jsxRuntime.jsx(ArrowRightIcon, {}) }))] })));
1571
1366
  };
1572
1367
 
1573
- const MRT_TableBodyRowPinButton = (_a) => {
1574
- var { row, table } = _a, rest = __rest(_a, ["row", "table"]);
1575
- const { options: { enableRowPinning, rowPinningDisplayMode }, } = table;
1368
+ const MRT_RowActionMenu = (_a) => {
1369
+ var { anchorEl, handleEdit, row, setAnchorEl, staticRowIndex, table } = _a, rest = __rest(_a, ["anchorEl", "handleEdit", "row", "setAnchorEl", "staticRowIndex", "table"]);
1370
+ const { options: { editDisplayMode, enableEditing, icons: { EditIcon }, localization, mrtTheme: { menuBackgroundColor }, renderRowActionMenuItems, }, } = table;
1576
1371
  const density = useMRT_SliceValue(table._uiStore, (s) => s.density);
1577
- const canPin = parseFromValuesOrFunc(enableRowPinning, row);
1578
- if (!canPin)
1372
+ const menuItems = react.useMemo(() => {
1373
+ const items = [];
1374
+ const editItem = parseFromValuesOrFunc(enableEditing, row) &&
1375
+ ['modal', 'row'].includes(editDisplayMode) && (jsxRuntime.jsx(MRT_ActionMenuItem, { icon: jsxRuntime.jsx(EditIcon, {}), label: localization.edit, onClick: handleEdit, table: table }, 'edit'));
1376
+ if (editItem)
1377
+ items.push(editItem);
1378
+ const rowActionMenuItems = renderRowActionMenuItems === null || renderRowActionMenuItems === void 0 ? void 0 : renderRowActionMenuItems({
1379
+ closeMenu: () => setAnchorEl(null),
1380
+ row,
1381
+ staticRowIndex,
1382
+ table,
1383
+ });
1384
+ if (rowActionMenuItems === null || rowActionMenuItems === void 0 ? void 0 : rowActionMenuItems.length)
1385
+ items.push(...rowActionMenuItems);
1386
+ return items;
1387
+ }, [renderRowActionMenuItems, row, staticRowIndex, table]);
1388
+ if (!menuItems.length)
1579
1389
  return null;
1580
- const rowPinButtonProps = Object.assign({ row,
1581
- table }, rest);
1582
- if (rowPinningDisplayMode === 'top-and-bottom' && !row.getIsPinned()) {
1583
- return (jsxRuntime.jsxs(Box, { sx: {
1584
- display: 'flex',
1585
- flexDirection: density === 'compact' ? 'row' : 'column',
1586
- }, children: [jsxRuntime.jsx(MRT_RowPinButton, Object.assign({ pinningPosition: "top" }, rowPinButtonProps)), jsxRuntime.jsx(MRT_RowPinButton, Object.assign({ pinningPosition: "bottom" }, rowPinButtonProps))] }));
1587
- }
1588
- return (jsxRuntime.jsx(MRT_RowPinButton, Object.assign({ pinningPosition: rowPinningDisplayMode === 'bottom' ? 'bottom' : 'top' }, rowPinButtonProps)));
1589
- };
1590
-
1591
- const getMRT_RowPinningColumnDef = (tableOptions) => {
1592
- return Object.assign({ Cell: ({ row, table }) => (jsxRuntime.jsx(MRT_TableBodyRowPinButton, { row: row, table: table })), grow: false }, defaultDisplayColumnProps({
1593
- header: 'pin',
1594
- id: 'mrt-row-pin',
1595
- size: 60,
1596
- tableOptions,
1597
- }));
1390
+ return (jsxRuntime.jsx(Menu, Object.assign({ MenuListProps: {
1391
+ dense: density === 'compact',
1392
+ sx: {
1393
+ backgroundColor: menuBackgroundColor,
1394
+ },
1395
+ }, anchorEl: anchorEl, disableScrollLock: true, onClick: (event) => event.stopPropagation(), onClose: () => setAnchorEl(null), open: !!anchorEl }, rest, { children: menuItems })));
1598
1396
  };
1599
1397
 
1600
- const MRT_SelectAllMenu = ({ table, }) => {
1601
- const [anchorEl, setAnchorEl] = react.useState(null);
1602
- const [isSelectingAllPages, setIsSelectingAllPages] = react.useState(false);
1603
- const { getState, options: { enableRowPinning, getAllSelectableRowIds, localization, rowPinningDisplayMode, }, refs: { allSelectableRowIdsRef }, } = table;
1604
- // rowSelection is read here so that any change to selection will trigger a re-render and update the menu options accordingly
1605
- const { isLoading, rowSelection } = getState();
1606
- const isAllCurrentPageSelected = table.getIsAllPageRowsSelected();
1607
- const isAllPagesActive = getIsAllPagesSelectionActive(table, rowSelection);
1608
- const handleOpen = (event) => {
1609
- setAnchorEl(event.currentTarget);
1610
- };
1611
- const handleClose = () => {
1612
- setAnchorEl(null);
1613
- };
1614
- // Clears row pinning on every bulk selection/deselection
1615
- const clearPinning = () => {
1616
- if (enableRowPinning && (rowPinningDisplayMode === null || rowPinningDisplayMode === void 0 ? void 0 : rowPinningDisplayMode.includes('select'))) {
1617
- table.setRowPinning({ bottom: [], top: [] });
1618
- }
1619
- };
1620
- // ── Current-page actions ────────────────────────────────────────────────────
1621
- const handleSelectCurrentPage = () => {
1622
- table.toggleAllPageRowsSelected(true);
1623
- clearPinning();
1624
- handleClose();
1625
- };
1626
- const handleDeselectCurrentPage = () => {
1627
- if (allSelectableRowIdsRef.current.length > 0) {
1628
- // 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.
1629
- table.setRowSelection({});
1630
- allSelectableRowIdsRef.current = [];
1398
+ const MRT_EditActionButtons = (_a) => {
1399
+ var { row, table, variant = 'icon' } = _a, rest = __rest(_a, ["row", "table", "variant"]);
1400
+ const { getState, options: { icons: { CancelIcon, SaveIcon }, localization, onCreatingRowCancel, onCreatingRowSave, onEditingRowCancel, onEditingRowSave, }, refs: { editInputRefs }, setCreatingRow, setEditingRow, } = table;
1401
+ const { creatingRow, isSaving } = getState();
1402
+ const isCreating = (creatingRow === null || creatingRow === void 0 ? void 0 : creatingRow.id) === row.id;
1403
+ const isEditing = useMRT_SliceValue(table._uiStore, (s) => { var _a; return ((_a = s.editingRow) === null || _a === void 0 ? void 0 : _a.id) === row.id; });
1404
+ const handleCancel = () => {
1405
+ if (isCreating) {
1406
+ onCreatingRowCancel === null || onCreatingRowCancel === void 0 ? void 0 : onCreatingRowCancel({ row, table });
1407
+ setCreatingRow(null);
1631
1408
  }
1632
- else {
1633
- table.toggleAllPageRowsSelected(false);
1409
+ else if (isEditing) {
1410
+ onEditingRowCancel === null || onEditingRowCancel === void 0 ? void 0 : onEditingRowCancel({ row, table });
1411
+ setEditingRow(null);
1634
1412
  }
1635
- clearPinning();
1636
- handleClose();
1413
+ row._valuesCache = {}; //reset values cache
1637
1414
  };
1638
- // ── All-pages actions ───────────────────────────────────────────────────────
1639
- const handleSelectAllPages = () => __awaiter(void 0, void 0, void 0, function* () {
1640
- handleClose();
1641
- if (getAllSelectableRowIds) {
1642
- // Server-side: IDs are not available locally, fetch them from the API
1643
- setIsSelectingAllPages(true);
1644
- table.setShowProgressBars(true);
1645
- try {
1646
- const ids = yield getAllSelectableRowIds({ table });
1647
- allSelectableRowIdsRef.current = ids;
1648
- const newSelection = {};
1649
- ids.forEach((id) => {
1650
- newSelection[id] = true;
1651
- });
1652
- table.setRowSelection(newSelection);
1653
- clearPinning();
1654
- }
1655
- finally {
1656
- setIsSelectingAllPages(false);
1657
- table.setShowProgressBars(false);
1415
+ const handleSubmitRow = () => {
1416
+ var _a, _b;
1417
+ //look for auto-filled input values
1418
+ (_b = Object.values((_a = editInputRefs.current) !== null && _a !== void 0 ? _a : {})
1419
+ .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) => {
1420
+ if (input.value !== undefined &&
1421
+ Object.hasOwn(row === null || row === void 0 ? void 0 : row._valuesCache, input.name)) {
1422
+ // @ts-expect-error
1423
+ row._valuesCache[input.name] = input.value;
1658
1424
  }
1425
+ });
1426
+ if (isCreating)
1427
+ onCreatingRowSave === null || onCreatingRowSave === void 0 ? void 0 : onCreatingRowSave({
1428
+ exitCreatingMode: () => setCreatingRow(null),
1429
+ row,
1430
+ table,
1431
+ values: row._valuesCache,
1432
+ });
1433
+ else if (isEditing) {
1434
+ onEditingRowSave === null || onEditingRowSave === void 0 ? void 0 : onEditingRowSave({
1435
+ exitEditingMode: () => setEditingRow(null),
1436
+ row,
1437
+ table,
1438
+ values: row === null || row === void 0 ? void 0 : row._valuesCache,
1439
+ });
1659
1440
  }
1660
- else {
1661
- // Client-side: all data is available locally
1662
- table.toggleAllRowsSelected(true);
1663
- clearPinning();
1664
- }
1665
- });
1666
- const handleDeselectAllPages = () => {
1667
- if (getAllSelectableRowIds) {
1668
- table.setRowSelection({});
1669
- }
1670
- else {
1671
- table.toggleAllRowsSelected(false);
1672
- }
1673
- allSelectableRowIdsRef.current = [];
1674
- clearPinning();
1675
- handleClose();
1676
1441
  };
1677
- const isDisabled = isLoading || isSelectingAllPages;
1678
- return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(Tooltip, Object.assign({}, getCommonTooltipProps(), { title: localization.toggleSelectAll, children: jsxRuntime.jsx("span", { children: jsxRuntime.jsx(IconButton, { "aria-label": localization.toggleSelectAll, disabled: isDisabled, onClick: handleOpen, size: "small", sx: { height: '1.5rem', width: '1.5rem' }, children: jsxRuntime.jsx(table.options.icons.MoreVertIcon, { style: { transform: 'scale(0.85)' } }) }) }) })), jsxRuntime.jsxs(Menu, { anchorEl: anchorEl, onClose: handleClose, open: Boolean(anchorEl), children: [isAllCurrentPageSelected ? (jsxRuntime.jsx(MenuItem, { onClick: handleDeselectCurrentPage, children: localization.deselectAllOnCurrentPage })) : (jsxRuntime.jsx(MenuItem, { onClick: handleSelectCurrentPage, children: localization.selectAllOnCurrentPage })), isAllPagesActive ? (jsxRuntime.jsx(MenuItem, { onClick: handleDeselectAllPages, children: localization.deselectAllOnAllPages })) : (jsxRuntime.jsxs(MenuItem, { disabled: isSelectingAllPages, onClick: handleSelectAllPages, children: [isSelectingAllPages && (jsxRuntime.jsx(CircularProgress, { "aria-label": "Loading", size: 14, sx: { mr: 1 } })), localization.selectAllOnAllPages] }))] })] }));
1442
+ return (jsxRuntime.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' ? (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(Tooltip, { title: localization.cancel, children: jsxRuntime.jsx(IconButton, { "aria-label": localization.cancel, onClick: handleCancel, children: jsxRuntime.jsx(CancelIcon, {}) }) }), ((isCreating && onCreatingRowSave) ||
1443
+ (isEditing && onEditingRowSave)) && (jsxRuntime.jsx(Tooltip, { title: localization.save, children: jsxRuntime.jsx(IconButton, { "aria-label": localization.save, color: "info", disabled: isSaving, onClick: handleSubmitRow, children: isSaving ? jsxRuntime.jsx(CircularProgress, { size: 18 }) : jsxRuntime.jsx(SaveIcon, {}) }) }))] })) : (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(Button, { onClick: handleCancel, sx: { minWidth: '100px' }, children: localization.cancel }), jsxRuntime.jsxs(Button, { disabled: isSaving, onClick: handleSubmitRow, sx: { minWidth: '100px' }, variant: "contained", children: [isSaving && jsxRuntime.jsx(CircularProgress, { color: "inherit", size: 18 }), localization.save] })] })) }));
1679
1444
  };
1680
1445
 
1681
- const MRT_SelectCheckbox = (_a) => {
1682
- var _b;
1683
- var { row, staticRowIndex, table } = _a, rest = __rest(_a, ["row", "staticRowIndex", "table"]);
1684
- const { getState, options: { enableMultiRowSelection, localization, muiSelectAllCheckboxProps, muiSelectCheckboxProps, selectAllMode, }, } = table;
1685
- const { isLoading } = getState();
1686
- const density = useMRT_SliceValue(table._uiStore, (s) => s.density);
1687
- const selectAll = !row;
1688
- const allRowsSelected = selectAll
1689
- ? selectAllMode === 'page'
1690
- ? table.getIsAllPageRowsSelected()
1691
- : table.getIsAllRowsSelected()
1692
- : undefined;
1693
- const isChecked = selectAll
1694
- ? allRowsSelected
1695
- : getIsRowSelected({ row, table });
1696
- const checkboxProps = Object.assign(Object.assign({}, (selectAll
1697
- ? parseFromValuesOrFunc(muiSelectAllCheckboxProps, { table })
1698
- : parseFromValuesOrFunc(muiSelectCheckboxProps, {
1699
- row,
1700
- staticRowIndex,
1701
- table,
1702
- }))), rest);
1703
- const onSelectionChange = row
1704
- ? getMRT_RowSelectionHandler({
1705
- row,
1706
- staticRowIndex,
1707
- table,
1708
- })
1709
- : undefined;
1710
- const onSelectAllChange = getMRT_SelectAllHandler({ table });
1711
- const commonProps = Object.assign(Object.assign({ 'aria-label': selectAll
1712
- ? localization.toggleSelectAll
1713
- : localization.toggleSelectRow, checked: isChecked, disabled: isLoading || (row && !row.getCanSelect()) || (row === null || row === void 0 ? void 0 : row.id) === 'mrt-row-create', inputProps: {
1714
- 'aria-label': selectAll
1715
- ? localization.toggleSelectAll
1716
- : localization.toggleSelectRow,
1717
- }, onChange: (event) => {
1718
- event.stopPropagation();
1719
- selectAll ? onSelectAllChange(event) : onSelectionChange(event);
1720
- }, size: (density === 'compact' ? 'small' : 'medium') }, checkboxProps), { onClick: (e) => {
1721
- var _a;
1722
- e.stopPropagation();
1723
- (_a = checkboxProps === null || checkboxProps === void 0 ? void 0 : checkboxProps.onClick) === null || _a === void 0 ? void 0 : _a.call(checkboxProps, e);
1724
- }, 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 });
1725
- return (jsxRuntime.jsx(Tooltip, Object.assign({}, getCommonTooltipProps(), { title: (_b = checkboxProps === null || checkboxProps === void 0 ? void 0 : checkboxProps.title) !== null && _b !== void 0 ? _b : (selectAll
1726
- ? localization.toggleSelectAll
1727
- : localization.toggleSelectRow), children: enableMultiRowSelection === false ? (jsxRuntime.jsx(Radio, Object.assign({}, commonProps))) : (jsxRuntime.jsx(Checkbox, Object.assign({ disableRipple: true, indeterminate: !isChecked && selectAll
1728
- ? table.getIsSomeRowsSelected()
1729
- : (row === null || row === void 0 ? void 0 : row.getIsSomeSelected()) && row.getCanSelectSubRows() }, commonProps))) })));
1446
+ const parseCSSVarId = (id) => id.replace(/[^a-zA-Z0-9]/g, '_');
1447
+ const getMRTTheme = (mrtTheme, muiTheme) => {
1448
+ const mrtThemeOverrides = parseFromValuesOrFunc(mrtTheme, muiTheme);
1449
+ const baseBackgroundColor = muiTheme.palette.background.default;
1450
+ return Object.assign({ baseBackgroundColor, cellNavigationOutlineColor: muiTheme.palette.primary.main, draggingBorderColor: muiTheme.palette.primary.main, matchHighlightColor: muiTheme.palette.mode === 'dark'
1451
+ ? styles.darken(muiTheme.palette.warning.dark, 0.25)
1452
+ : styles.lighten(muiTheme.palette.warning.light, 0.5), menuBackgroundColor: styles.lighten(baseBackgroundColor, 0.07), pinnedRowBackgroundColor: styles.alpha(muiTheme.palette.primary.main, 0.1), selectedRowBackgroundColor: styles.alpha(muiTheme.palette.primary.main, 0.2) }, mrtThemeOverrides);
1730
1453
  };
1731
-
1732
- const getMRT_RowSelectColumnDef = (tableOptions) => {
1733
- const { enableMultiRowSelection, enableSelectAll } = tableOptions;
1734
- return Object.assign({ Cell: ({ row, staticRowIndex, table }) => (jsxRuntime.jsx(MRT_SelectCheckbox, { row: row, staticRowIndex: staticRowIndex, table: table })), Header: enableSelectAll && enableMultiRowSelection
1735
- ? ({ table }) => (jsxRuntime.jsxs(Box, { sx: { alignItems: 'center', display: 'flex' }, children: [jsxRuntime.jsx(MRT_SelectCheckbox, { table: table }), jsxRuntime.jsx(MRT_SelectAllMenu, { table: table })] }))
1736
- : undefined, grow: false }, defaultDisplayColumnProps({
1737
- header: 'select',
1738
- id: '__check__',
1739
- size: enableSelectAll ? 90 : 70, // widened from 60 to accommodate both the checkbox and the menu button
1740
- tableOptions,
1741
- }));
1454
+ const commonCellBeforeAfterStyles = {
1455
+ content: '""',
1456
+ height: '100%',
1457
+ left: 0,
1458
+ position: 'absolute',
1459
+ top: 0,
1460
+ width: '100%',
1461
+ zIndex: -1,
1742
1462
  };
1743
-
1744
- const MRT_Default_Icons = {
1745
- AddIcon,
1746
- ArrowDownwardIcon,
1747
- ArrowRightIcon,
1748
- CancelIcon,
1749
- ChevronLeftIcon,
1750
- ChevronRightIcon,
1751
- ClearAllIcon,
1752
- CloseIcon,
1753
- ContentCopy,
1754
- DensityLargeIcon,
1755
- DensityMediumIcon,
1756
- DensitySmallIcon,
1757
- DragHandleIcon,
1758
- DynamicFeedIcon,
1759
- EditIcon,
1760
- ExpandMoreIcon,
1761
- FilterAltIcon,
1762
- FilterListIcon,
1763
- FilterListOffIcon,
1764
- FirstPageIcon,
1765
- FullscreenExitIcon,
1766
- FullscreenIcon,
1767
- KeyboardDoubleArrowDownIcon,
1768
- LastPageIcon,
1769
- MoreHorizIcon,
1770
- MoreVertIcon,
1771
- PushPinIcon,
1772
- RestartAltIcon,
1773
- SaveIcon,
1774
- SearchIcon,
1775
- SearchOffIcon,
1776
- SortIcon,
1777
- SyncAltIcon,
1778
- ViewColumnIcon,
1779
- VisibilityOffIcon,
1463
+ const getCommonPinnedCellStyles = ({ table, theme, }) => {
1464
+ const { baseBackgroundColor } = table.options.mrtTheme;
1465
+ return {
1466
+ '&[data-pinned="true"]': {
1467
+ '&:before': Object.assign({ backgroundColor: styles.alpha(styles.darken(baseBackgroundColor, theme.palette.mode === 'dark' ? 0.05 : 0.01), 0.97) }, commonCellBeforeAfterStyles),
1468
+ },
1469
+ };
1780
1470
  };
1781
-
1782
- const MRT_Localization_EN = {
1783
- language: 'en',
1784
- actions: 'Actions',
1785
- and: 'and',
1786
- booleanFalse: 'False',
1787
- booleanTrue: 'True',
1788
- cancel: 'Cancel',
1789
- close: 'Close',
1790
- changeFilterMode: 'Change filter mode',
1791
- changeSearchMode: 'Change search mode',
1792
- clearFilter: 'Clear filter',
1793
- clearSearch: 'Clear search',
1794
- clearSelection: 'Clear selection',
1795
- clearSort: 'Clear sort',
1796
- deselectAllOnAllPages: 'Deselect all on all pages',
1797
- deselectAllOnCurrentPage: 'Deselect all on current page',
1798
- clickToCopy: 'Click to copy',
1799
- copy: 'Copy',
1800
- collapse: 'Collapse',
1801
- collapseAll: 'Collapse all',
1802
- columnActions: 'Column Actions',
1803
- columns: 'Columns',
1804
- copiedToClipboard: 'Copied to clipboard',
1805
- dropToGroupBy: 'Drop to group by {column}',
1806
- edit: 'Edit',
1807
- expand: 'Expand',
1808
- expandAll: 'Expand all',
1809
- filterArrIncludes: 'Includes',
1810
- filterArrIncludesAll: 'Includes all',
1811
- filterArrIncludesSome: 'Includes',
1812
- filterBetween: 'Between',
1813
- filterBetweenInclusive: 'Between Inclusive',
1814
- filterByColumn: 'Filter by {column}',
1815
- filterFrom: 'From',
1816
- filterTo: 'To',
1817
- filterContains: 'Contains',
1818
- filterEmpty: 'Empty',
1819
- filterEndsWith: 'Ends With',
1820
- filterEquals: 'Equals',
1821
- filterEqualsString: 'Equals',
1822
- filterFuzzy: 'Fuzzy',
1823
- filterGreaterThan: 'Greater Than',
1824
- filterGreaterThanOrEqualTo: 'Greater Than Or Equal To',
1825
- filterInArray: 'Is any of',
1826
- filterIsAnyOf: 'Is any of',
1827
- filterInNumberRange: 'Between',
1828
- filterIncludesString: 'Contains',
1829
- filterIncludesStringSensitive: 'Contains',
1830
- filterLessThan: 'Less Than',
1831
- filterLessThanOrEqualTo: 'Less Than Or Equal To',
1832
- filterMode: 'Filter Mode: {filterType}',
1833
- filterNoOptions: 'No filter options available',
1834
- filterNotEmpty: 'Not Empty',
1835
- filterNotEquals: 'Not Equals',
1836
- filterNotContains: 'Does Not Contain',
1837
- filterLogic: 'Logic',
1838
- filterOperator: 'Operator',
1839
- filterStartsWith: 'Starts With',
1840
- filterWeakEquals: 'Equals',
1841
- filterCurrentWeek: 'Current Week',
1842
- filterCurrentMonth: 'Current Month',
1843
- filterLast7Days: 'Last 7 Days',
1844
- filterLastWeek: 'Last Week',
1845
- filterLastMonth: 'Last Month',
1846
- filterFromToday: 'From Today',
1847
- filterToToday: 'To Today',
1848
- filteringByColumn: 'Filtering by {column} - {filterType} {filterValue}',
1849
- goToFirstPage: 'Go to first page',
1850
- goToLastPage: 'Go to last page',
1851
- goToNextPage: 'Go to next page',
1852
- goToPreviousPage: 'Go to previous page',
1853
- grab: 'Grab',
1854
- groupByColumn: 'Group by {column}',
1855
- groupedBy: 'Grouped by ',
1856
- hideAll: 'Hide all',
1857
- hideColumn: 'Hide {column} column',
1858
- max: 'Max',
1859
- min: 'Min',
1860
- move: 'Move',
1861
- noRecordsToDisplay: 'No records to display',
1862
- noResultsFound: 'No results found',
1863
- moreThan: 'more than',
1864
- of: 'of',
1865
- or: 'or',
1866
- pin: 'Pin',
1867
- pinToLeft: 'Pin to left',
1868
- pinToRight: 'Pin to right',
1869
- resetColumnSize: 'Reset column size',
1870
- resetOrder: 'Reset order',
1871
- rowActions: 'Row Actions',
1872
- rowNumber: '#',
1873
- rowNumbers: 'Row Numbers',
1874
- rowsPerPage: 'Rows per page',
1875
- countRows: 'Count Rows',
1876
- countRowsTooltip: 'Count total rows for current filters',
1877
- rowCount: 'Row Count',
1878
- rowsSelected: '{count} row(s) selected',
1879
- save: 'Save',
1880
- search: 'Search',
1881
- selectedCountOfRowCountRowsSelected: '{selectedCount} of {rowCount} row(s) selected',
1882
- select: 'Select',
1883
- selectAllOnAllPages: 'Select all on all pages',
1884
- selectAllOnCurrentPage: 'Select all on current page',
1885
- showAll: 'Show all',
1886
- showAllColumns: 'Show all columns',
1887
- showHideColumns: 'Columns',
1888
- showHideFilters: 'Show/Hide filters',
1889
- showHideSearch: 'Show/Hide search',
1890
- showAdvancedFilters: 'Show advanced filters',
1891
- advancedFilters: 'Advanced Filters',
1892
- filters: 'Filters',
1893
- add: 'Add',
1894
- newEntry: 'New Entry',
1895
- clear: 'Clear',
1896
- discardChanges: 'Discard changes',
1897
- saveFilters: 'Save filters',
1898
- savedFilters: 'Saved filters',
1899
- noSavedFilters: 'No saved filters',
1900
- filterName: 'Filter name',
1901
- apply: 'Apply',
1902
- sortByColumnAsc: 'Sort by {column} ascending',
1903
- sortByColumnDesc: 'Sort by {column} descending',
1904
- sortedByColumnAsc: 'Sorted by {column} ascending',
1905
- sortedByColumnDesc: 'Sorted by {column} descending',
1906
- thenBy: ', then by ',
1907
- toggleDensity: 'Density',
1908
- densityCompact: 'Compact',
1909
- densityStandard: 'Standard',
1910
- densityComfortable: 'Comfortable',
1911
- toggleFullScreen: 'Toggle full screen',
1912
- toggleSelectAll: 'Toggle select all',
1913
- toggleSelectRow: 'Toggle select row',
1914
- toggleVisibility: 'Toggle visibility',
1915
- ungroupByColumn: 'Ungroup by {column}',
1916
- unpin: 'Unpin',
1917
- unpinAll: 'Unpin all',
1918
- dimensionRotationEnabled: 'Rotation enabled',
1919
- dimensionRotationDisabled: 'Rotation disabled',
1920
- length: 'Length',
1921
- width: 'Width',
1922
- height: 'Height',
1923
- depth: 'Depth',
1924
- tolerance: 'Tolerance',
1925
- exportButton: 'Export',
1926
- exportSelectRowsTooltip: 'Select rows to export',
1927
- exportPrintPdf: 'Print PDF',
1928
- exportDownload: 'Download',
1929
- exportGrouped: 'Group files',
1930
- exportInProgress: 'Export in progress...',
1931
- exportSuccess: 'Export completed successfully.',
1932
- exportError: 'Export failed. Please try again.',
1933
- exportNoExportsSelected: 'No export type selected. Please configure the export first.',
1934
- deleteConfirmationTitle: 'Delete Row',
1935
- deleteConfirmationMessage: 'Are you sure you want to delete the selected row(s)?',
1936
- deleteConfirmYes: 'Delete',
1937
- deleteConfirmNo: 'Cancel',
1938
- deleteConfirmDeleting: 'Deleting...',
1939
- errorTitle: 'Unexpected error',
1940
- errorMessage: 'An unexpected error occurred. Please try again.',
1941
- serverTableErrorTitle: 'Unable to load table',
1942
- serverTableErrorMessage: 'Something went wrong while loading the table configuration. Please try again.',
1943
- serverTableErrorRetry: 'Try again',
1944
- resetState: 'Reset State',
1945
- tableOptions: 'Options',
1946
- };
1947
-
1948
- const downloadExportFiles = (files) => {
1949
- files.forEach((file) => {
1950
- const binaryString = atob(file.content);
1951
- const len = binaryString.length;
1952
- const bytes = new Uint8Array(len);
1953
- for (let i = 0; i < len; i++) {
1954
- bytes[i] = binaryString.charCodeAt(i);
1955
- }
1956
- const blob = new Blob([bytes], { type: 'application/octet-stream' });
1957
- const element = document.createElement('a');
1958
- element.href = URL.createObjectURL(blob);
1959
- element.download = file.filename;
1960
- document.body.appendChild(element);
1961
- element.click();
1962
- document.body.removeChild(element);
1963
- URL.revokeObjectURL(element.href);
1964
- });
1471
+ const getCommonMRTCellStyles = ({ column, header, isDraggingColumn, isHoveredColumn, table, tableCellProps, theme, }) => {
1472
+ var _a, _b, _c, _d, _e, _f;
1473
+ const { options: { enableColumnVirtualization, layoutMode }, } = table;
1474
+ const { columnDef } = column;
1475
+ const { columnDefType } = columnDef;
1476
+ const isColumnPinned = columnDef.columnDefType !== 'group' && column.getIsPinned();
1477
+ const widthStyles = {
1478
+ 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)`,
1479
+ 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)`,
1480
+ };
1481
+ if (layoutMode === 'grid') {
1482
+ widthStyles.flex = `${[0, false].includes(columnDef.grow)
1483
+ ? 0
1484
+ : `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`;
1485
+ }
1486
+ else if (layoutMode === 'grid-no-grow') {
1487
+ widthStyles.flex = `${+(columnDef.grow || 0)} 0 auto`;
1488
+ }
1489
+ // The checkbox column is technically pinned (for sticky positioning) but
1490
+ // should look like a regular center column — no background overlay or shadow.
1491
+ const isCheckboxColumn = column.id === CHECKBOX_DISPLAY_COLUMN_ID;
1492
+ // Count all currently pinned column IDs across both sides.
1493
+ // Checkbox is always pinned (counts as 1), so > 1 means the user has
1494
+ // explicitly pinned at least one additional column.
1495
+ const totalPinnedColumnCount = [
1496
+ ...((_e = table.getState().columnPinning.left) !== null && _e !== void 0 ? _e : []),
1497
+ ...((_f = table.getState().columnPinning.right) !== null && _f !== void 0 ? _f : []),
1498
+ ].length;
1499
+ const hasNoPinnedColumns = totalPinnedColumnCount === 0;
1500
+ const pinnedStyles = isColumnPinned
1501
+ ? Object.assign(Object.assign({}, (isCheckboxColumn
1502
+ ? hasNoPinnedColumns
1503
+ ? {
1504
+ // Use doubled class selector (&&) to beat the row-level
1505
+ // td[data-pinned="true"]:before specificity from MRT_TableBodyRow.
1506
+ '&&[data-pinned="true"]': {
1507
+ '&:before': {
1508
+ backgroundColor: 'transparent',
1509
+ boxShadow: 'none',
1510
+ },
1511
+ },
1512
+ }
1513
+ : // Other columns are also pinned — apply standard pinned background
1514
+ // so the checkbox header matches the pinned row cells below it.
1515
+ getCommonPinnedCellStyles({ column, table, theme })
1516
+ : getCommonPinnedCellStyles({ column, table, theme }))), { left: isColumnPinned === 'left'
1517
+ ? `${column.getStart('left')}px`
1518
+ : undefined,
1519
+ // Skip opacity reduction for checkbox — keep it fully opaque like center columns
1520
+ opacity: isCheckboxColumn ? undefined : 0.97, position: 'sticky', right: isColumnPinned === 'right'
1521
+ ? `${column.getAfter('right')}px`
1522
+ : undefined }) : {};
1523
+ 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'
1524
+ ? 'center'
1525
+ : (layoutMode === null || layoutMode === void 0 ? void 0 : layoutMode.startsWith('grid'))
1526
+ ? tableCellProps.align
1527
+ : undefined, opacity: isDraggingColumn || isHoveredColumn ? 0.5 : 1, position: 'relative', transition: enableColumnVirtualization
1528
+ ? 'none'
1529
+ : `padding 150ms ease-in-out`, zIndex: column.getIsResizing() || isDraggingColumn
1530
+ ? 2
1531
+ : columnDefType !== 'group' && isColumnPinned
1532
+ ? 1
1533
+ : 0, '&:focus-visible': {
1534
+ outline: `2px solid ${table.options.mrtTheme.cellNavigationOutlineColor}`,
1535
+ outlineOffset: '-2px',
1536
+ } }, pinnedStyles), widthStyles), parseFromValuesOrFunc(tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.sx, theme));
1965
1537
  };
1538
+ const getCommonToolbarStyles = ({ table, }) => ({
1539
+ alignItems: 'flex-start',
1540
+ backgroundColor: table.options.mrtTheme.baseBackgroundColor,
1541
+ display: 'grid',
1542
+ flexWrap: 'wrap-reverse',
1543
+ position: 'relative',
1544
+ transition: 'all 150ms ease-in-out',
1545
+ zIndex: 1,
1546
+ });
1547
+ const flipIconStyles = (theme) => theme.direction === 'rtl'
1548
+ ? { style: { transform: 'scaleX(-1)' } }
1549
+ : undefined;
1550
+ const getCommonTooltipProps = (placement) => ({
1551
+ disableInteractive: true,
1552
+ enterDelay: 1000,
1553
+ enterNextDelay: 1000,
1554
+ placement,
1555
+ });
1966
1556
 
1967
- const printExportFiles = (files) => {
1968
- files.forEach((file) => {
1969
- const binaryString = atob(file.content);
1970
- const len = binaryString.length;
1971
- const bytes = new Uint8Array(len);
1972
- for (let i = 0; i < len; i++) {
1973
- bytes[i] = binaryString.charCodeAt(i);
1974
- }
1975
- const blob = new Blob([bytes], { type: 'application/pdf' });
1976
- const url = URL.createObjectURL(blob);
1977
- printJS({
1978
- printable: url,
1979
- type: 'pdf',
1980
- onLoadingEnd: () => URL.revokeObjectURL(url),
1981
- });
1982
- });
1557
+ const commonIconButtonStyles = {
1558
+ '&:hover': {
1559
+ opacity: 1,
1560
+ },
1561
+ height: '2rem',
1562
+ ml: '10px',
1563
+ opacity: 0.5,
1564
+ transition: 'opacity 150ms',
1565
+ width: '2rem',
1983
1566
  };
1984
-
1985
- const MRT_ExportsToolbar = ({ table, availableExports, exportState, onExportStateChange, loadExport, }) => {
1986
- const theme = styles.useTheme();
1987
- const { localization } = table.options;
1988
- const { selectedExports, selectedFormat, grouped } = exportState;
1567
+ const MRT_ToggleRowActionMenuButton = (_a) => {
1568
+ var _b;
1569
+ var { cell, row, staticRowIndex, table } = _a, rest = __rest(_a, ["cell", "row", "staticRowIndex", "table"]);
1570
+ const { getState, options: { createDisplayMode, editDisplayMode, enableEditing, icons: { EditIcon, MoreHorizIcon }, localization, renderRowActionMenuItems, renderRowActions, }, setEditingRow, } = table;
1571
+ const { creatingRow } = getState();
1572
+ const isCreating = (creatingRow === null || creatingRow === void 0 ? void 0 : creatingRow.id) === row.id;
1573
+ const isEditing = useMRT_SliceValue(table._uiStore, (s) => { var _a; return ((_a = s.editingRow) === null || _a === void 0 ? void 0 : _a.id) === row.id; });
1574
+ const showEditActionButtons = (isCreating && createDisplayMode === 'row') ||
1575
+ (isEditing && editDisplayMode === 'row');
1989
1576
  const [anchorEl, setAnchorEl] = react.useState(null);
1990
- const [loadingExportType, setLoadingExportType] = react.useState(null);
1991
- const { rowSelection } = table.getState();
1992
- const selectedRowIds = Object.keys(rowSelection).filter((id) => rowSelection[id]);
1993
- const isNoRowsSelected = selectedRowIds.length === 0;
1994
- const availableFormats = react.useMemo(() => {
1995
- const allFormats = Object.values(availableExports).flatMap((exp) => exp.formats);
1996
- return Array.from(new Set(allFormats));
1997
- }, [availableExports]);
1998
- const hasPdfFormat = availableFormats.includes('pdf');
1999
- const exportTypesForSelectedFormat = react.useMemo(() => {
2000
- if (!selectedFormat)
2001
- return [];
2002
- return Object.values(availableExports).filter((exp) => exp.formats.includes(selectedFormat));
2003
- }, [availableExports, selectedFormat]);
2004
- const isPrintDisabled = selectedFormat !== 'pdf' ||
2005
- !selectedFormat ||
2006
- selectedExports.length < 1 ||
2007
- (!grouped && selectedExports.length > 1);
2008
- const isDownloadDisabled = !selectedFormat || selectedExports.length < 1;
2009
- const handleOpenMenu = (event) => {
1577
+ const handleOpenRowActionMenu = (event) => {
1578
+ event.stopPropagation();
1579
+ event.preventDefault();
2010
1580
  setAnchorEl(event.currentTarget);
2011
1581
  };
2012
- const handleCloseMenu = () => {
1582
+ const handleStartEditMode = (event) => {
1583
+ event.stopPropagation();
1584
+ setEditingRow(Object.assign({}, row));
2013
1585
  setAnchorEl(null);
2014
1586
  };
2015
- const handleSelectFormat = (format) => {
2016
- const newFormat = selectedFormat === format ? null : format;
2017
- onExportStateChange((prev) => (Object.assign(Object.assign({}, (prev !== null && prev !== void 0 ? prev : { grouped: false })), { selectedExports: [], selectedFormat: newFormat })));
2018
- };
2019
- const handleToggleExportType = (exportName) => {
2020
- const isAlreadySelected = selectedExports.includes(exportName);
2021
- const newSelectedExports = isAlreadySelected
2022
- ? selectedExports.filter((name) => name !== exportName)
2023
- : [...selectedExports, exportName];
2024
- onExportStateChange((prev) => (Object.assign(Object.assign({}, (prev !== null && prev !== void 0 ? prev : { selectedFormat: null, grouped: false })), { selectedExports: newSelectedExports })));
2025
- };
2026
- const handleToggleGrouped = () => {
2027
- onExportStateChange((prev) => (Object.assign(Object.assign({}, (prev !== null && prev !== void 0 ? prev : { selectedFormat: null, selectedExports: [] })), { grouped: !grouped })));
2028
- };
2029
- const handleExportAction = (type) => __awaiter(void 0, void 0, void 0, function* () {
2030
- setLoadingExportType(type);
1587
+ return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: renderRowActions && !showEditActionButtons ? (renderRowActions({ cell, row, staticRowIndex, table })) : showEditActionButtons ? (jsxRuntime.jsx(MRT_EditActionButtons, { row: row, table: table })) : !renderRowActionMenuItems &&
1588
+ parseFromValuesOrFunc(enableEditing, row) &&
1589
+ ['modal', 'row'].includes(editDisplayMode) ? (jsxRuntime.jsx(Tooltip, { placement: "right", title: localization.edit, children: jsxRuntime.jsx(IconButton, Object.assign({ "aria-label": localization.edit, onClick: handleStartEditMode, sx: commonIconButtonStyles }, rest, { children: jsxRuntime.jsx(EditIcon, {}) })) })) : ((_b = renderRowActionMenuItems === null || renderRowActionMenuItems === void 0 ? void 0 : renderRowActionMenuItems({
1590
+ closeMenu: () => { },
1591
+ row,
1592
+ staticRowIndex,
1593
+ table,
1594
+ })) === null || _b === void 0 ? void 0 : _b.length) ? (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(Tooltip, Object.assign({}, getCommonTooltipProps(), { title: localization.rowActions, children: jsxRuntime.jsx(IconButton, Object.assign({ "aria-label": localization.rowActions, onClick: handleOpenRowActionMenu, size: "small", sx: commonIconButtonStyles }, rest, { children: jsxRuntime.jsx(MoreHorizIcon, {}) })) })), jsxRuntime.jsx(MRT_RowActionMenu, { anchorEl: anchorEl, handleEdit: handleStartEditMode, row: row, setAnchorEl: setAnchorEl, staticRowIndex: staticRowIndex, table: table })] })) : null }));
1595
+ };
1596
+
1597
+ const getMRT_RowActionsColumnDef = (tableOptions) => {
1598
+ return Object.assign({ Cell: ({ cell, row, staticRowIndex, table }) => (jsxRuntime.jsx(MRT_ToggleRowActionMenuButton, { cell: cell, row: row, staticRowIndex: staticRowIndex, table: table })) }, defaultDisplayColumnProps({
1599
+ header: 'actions',
1600
+ id: 'mrt-row-actions',
1601
+ size: 70,
1602
+ tableOptions,
1603
+ }));
1604
+ };
1605
+
1606
+ const MRT_GrabHandleButton = (_a) => {
1607
+ var _b, _c;
1608
+ var { location, table } = _a, rest = __rest(_a, ["location", "table"]);
1609
+ const { options: { icons: { DragHandleIcon }, localization, }, } = table;
1610
+ return (jsxRuntime.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: jsxRuntime.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) => {
1611
+ var _a;
1612
+ e.stopPropagation();
1613
+ (_a = rest === null || rest === void 0 ? void 0 : rest.onClick) === null || _a === void 0 ? void 0 : _a.call(rest, e);
1614
+ }, sx: (theme) => (Object.assign({ '&:active': {
1615
+ cursor: 'grabbing',
1616
+ }, '&:hover': {
1617
+ backgroundColor: 'transparent',
1618
+ opacity: 1,
1619
+ }, 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: jsxRuntime.jsx(DragHandleIcon, {}) })) })));
1620
+ };
1621
+
1622
+ const MRT_TableBodyRowGrabHandle = (_a) => {
1623
+ var { row, rowRef, table } = _a, rest = __rest(_a, ["row", "rowRef", "table"]);
1624
+ const { options: { muiRowDragHandleProps }, } = table;
1625
+ const iconButtonProps = Object.assign(Object.assign({}, parseFromValuesOrFunc(muiRowDragHandleProps, {
1626
+ row,
1627
+ table,
1628
+ })), rest);
1629
+ const handleDragStart = (event) => {
1630
+ var _a;
1631
+ (_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.onDragStart) === null || _a === void 0 ? void 0 : _a.call(iconButtonProps, event);
2031
1632
  try {
2032
- const response = yield loadExport({
2033
- format: selectedFormat,
2034
- exports: selectedExports,
2035
- separated_files: !grouped,
2036
- download: false,
2037
- ids: JSON.stringify(selectedRowIds),
2038
- type,
2039
- });
2040
- handleCloseMenu();
2041
- if (type === 'download') {
2042
- downloadExportFiles(response);
2043
- }
2044
- else {
2045
- printExportFiles(response);
2046
- }
1633
+ event.dataTransfer.setDragImage(rowRef.current, 0, 0);
2047
1634
  }
2048
- finally {
2049
- setLoadingExportType(null);
1635
+ catch (e) {
1636
+ console.error(e);
2050
1637
  }
2051
- });
2052
- const renderFormatSelector = () => (jsxRuntime.jsx(Stack, { justifyContent: "flex-start", minWidth: "200px", sx: {
2053
- borderRight: selectedFormat
2054
- ? `1px dashed ${theme.palette.divider}`
2055
- : 'none',
2056
- }, children: jsxRuntime.jsx(FormControl, { children: jsxRuntime.jsx(RadioGroup, { value: selectedFormat !== null && selectedFormat !== void 0 ? selectedFormat : '', children: availableFormats.map((format) => (jsxRuntime.jsx(FormControlLabel, { sx: { m: 0 }, value: format, control: jsxRuntime.jsx(Radio, { size: "small", onClick: () => handleSelectFormat(format) }), label: jsxRuntime.jsx(Typography, { variant: "subtitle2", sx: { fontWeight: 800 }, children: format }) }, format))) }) }) }));
2057
- const renderExportTypeSelector = () => {
2058
- if (!selectedFormat || exportTypesForSelectedFormat.length === 0)
2059
- return null;
2060
- return (jsxRuntime.jsx(Stack, { minWidth: "250px", maxHeight: "500px", sx: { overflowY: 'auto' }, children: exportTypesForSelectedFormat.map((exportType) => (jsxRuntime.jsxs(MenuItem, { onClick: () => handleToggleExportType(exportType.name), value: exportType.name, children: [jsxRuntime.jsx(Checkbox, { checked: selectedExports.includes(exportType.name), size: "small" }), jsxRuntime.jsx(Typography, { variant: "body2", children: exportType.label })] }, exportType.name))) }));
1638
+ table.setDraggingRow(row);
2061
1639
  };
2062
- const renderActionButtons = () => {
2063
- const isAnyLoading = loadingExportType !== null;
2064
- return (jsxRuntime.jsxs(Stack, { direction: "row", gap: 0.5, mt: 1, mr: 2, children: [hasPdfFormat && (jsxRuntime.jsx(Button, { sx: { display: 'flex', gap: 0.5 }, disabled: isPrintDisabled || isAnyLoading, onClick: () => handleExportAction('print'), startIcon: loadingExportType === 'print' ? (jsxRuntime.jsx(CircularProgress, { size: 16, color: "inherit" })) : (jsxRuntime.jsx(PrintIcon, { fontSize: "small" })), children: localization.exportPrintPdf })), jsxRuntime.jsx(Button, { sx: { display: 'flex', gap: 0.5 }, disabled: isDownloadDisabled || isAnyLoading, onClick: () => handleExportAction('download'), startIcon: loadingExportType === 'download' ? (jsxRuntime.jsx(CircularProgress, { size: 16, color: "inherit" })) : (jsxRuntime.jsx(FileDownloadIcon, { fontSize: "small" })), children: localization.exportDownload })] }));
1640
+ const handleDragEnd = (event) => {
1641
+ var _a;
1642
+ (_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.onDragEnd) === null || _a === void 0 ? void 0 : _a.call(iconButtonProps, event);
1643
+ table.setDraggingRow(null);
1644
+ table.setHoveredRow(null);
2065
1645
  };
2066
- const renderGroupedCheckbox = () => (jsxRuntime.jsx(Stack, { mt: "auto", children: jsxRuntime.jsx(FormControlLabel, { onChange: handleToggleGrouped, sx: { m: 0 }, control: jsxRuntime.jsx(Checkbox, { checked: grouped, size: "small" }), label: jsxRuntime.jsx(Typography, { variant: "body2", children: localization.exportGrouped }) }) }));
2067
- return (jsxRuntime.jsxs(Stack, { direction: "row", gap: 0.5, alignItems: "center", children: [jsxRuntime.jsx(Tooltip, { title: isNoRowsSelected
2068
- ? localization.exportSelectRowsTooltip
2069
- : localization.exportButton, children: jsxRuntime.jsx("span", { children: jsxRuntime.jsx(Button, { "aria-label": localization.exportButton, disabled: isNoRowsSelected, onClick: handleOpenMenu, size: "small", startIcon: jsxRuntime.jsx(FileDownloadIcon, { fontSize: "small" }), variant: "text", children: localization.exportButton }) }) }), jsxRuntime.jsxs(Menu, { anchorEl: anchorEl, open: Boolean(anchorEl), onClose: handleCloseMenu, anchorOrigin: { vertical: 'bottom', horizontal: 'left' }, transformOrigin: { vertical: 'top', horizontal: 'left' }, children: [jsxRuntime.jsxs(Stack, { direction: "row", sx: { px: 1, pt: 1, maxHeight: '320px', overflow: 'auto' }, children: [renderFormatSelector(), selectedFormat &&
2070
- exportTypesForSelectedFormat.length > 0 &&
2071
- renderExportTypeSelector()] }), jsxRuntime.jsx(Divider, { sx: { mt: 1 } }), jsxRuntime.jsxs(Stack, { direction: "row", alignItems: "center", sx: { px: 1, pb: 1 }, children: [renderActionButtons(), renderGroupedCheckbox()] })] })] }));
1646
+ return (jsxRuntime.jsx(MRT_GrabHandleButton, Object.assign({}, iconButtonProps, { location: "row", onDragEnd: handleDragEnd, onDragStart: handleDragStart, table: table })));
2072
1647
  };
2073
1648
 
2074
- const MRT_ExportRowButton = ({ onClick }) => {
2075
- return (jsxRuntime.jsx(IconButton, { sx: { p: 0 }, disableRipple: true, onClick: onClick, children: jsxRuntime.jsx(FileDownloadIcon, { fontSize: "small" }) }));
1649
+ const getMRT_RowDragColumnDef = (tableOptions) => {
1650
+ return Object.assign({ Cell: ({ row, rowRef, table }) => (jsxRuntime.jsx(MRT_TableBodyRowGrabHandle, { row: row, rowRef: rowRef, table: table })), grow: false }, defaultDisplayColumnProps({
1651
+ header: 'move',
1652
+ id: 'mrt-row-drag',
1653
+ size: 60,
1654
+ tableOptions,
1655
+ }));
2076
1656
  };
2077
1657
 
2078
- const MRT_PrintRowButton = ({ onClick }) => {
2079
- return (jsxRuntime.jsx(IconButton, { sx: { p: 0 }, disableRipple: true, onClick: onClick, children: jsxRuntime.jsx(PrintIcon, { fontSize: "small" }) }));
1658
+ const MRT_ExpandAllButton = (_a) => {
1659
+ var _b, _c;
1660
+ var { table } = _a, rest = __rest(_a, ["table"]);
1661
+ const { getCanSomeRowsExpand, getIsAllRowsExpanded, getIsSomeRowsExpanded, getState, options: { icons: { KeyboardDoubleArrowDownIcon }, localization, muiExpandAllButtonProps, renderDetailPanel, }, toggleAllRowsExpanded, } = table;
1662
+ const { isLoading } = getState();
1663
+ const density = useMRT_SliceValue(table._uiStore, (s) => s.density);
1664
+ const iconButtonProps = Object.assign(Object.assign({}, parseFromValuesOrFunc(muiExpandAllButtonProps, {
1665
+ table,
1666
+ })), rest);
1667
+ const isAllRowsExpanded = getIsAllRowsExpanded();
1668
+ return (jsxRuntime.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: jsxRuntime.jsx("span", { children: jsxRuntime.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 : (jsxRuntime.jsx(KeyboardDoubleArrowDownIcon, { style: {
1669
+ transform: `rotate(${isAllRowsExpanded ? -180 : getIsSomeRowsExpanded() ? -90 : 0}deg)`,
1670
+ transition: 'transform 150ms',
1671
+ } })) })) }) })));
2080
1672
  };
2081
1673
 
2082
- const ExportRowAction = ({ onExport, onPrint }) => {
2083
- return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(MRT_ExportRowButton, { onClick: onExport }), onPrint && jsxRuntime.jsx(MRT_PrintRowButton, { onClick: onPrint })] }));
1674
+ const MRT_ExpandButton = ({ row, staticRowIndex, table, }) => {
1675
+ var _a, _b;
1676
+ const theme = styles.useTheme();
1677
+ const { options: { icons: { ExpandMoreIcon }, localization, maxDepth, muiExpandButtonProps, positionExpandColumn, renderDetailPanel, }, } = table;
1678
+ const density = useMRT_SliceValue(table._uiStore, (s) => s.density);
1679
+ const iconButtonProps = parseFromValuesOrFunc(muiExpandButtonProps, {
1680
+ row,
1681
+ staticRowIndex,
1682
+ table,
1683
+ });
1684
+ const canExpand = row.getCanExpand() && (maxDepth === undefined || row.depth < maxDepth - 1);
1685
+ const isExpanded = row.getIsExpanded();
1686
+ const handleToggleExpand = (event) => {
1687
+ var _a;
1688
+ event.stopPropagation();
1689
+ row.toggleExpanded();
1690
+ (_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.onClick) === null || _a === void 0 ? void 0 : _a.call(iconButtonProps, event);
1691
+ };
1692
+ const detailPanel = !!(renderDetailPanel === null || renderDetailPanel === void 0 ? void 0 : renderDetailPanel({ row, table }));
1693
+ return (jsxRuntime.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: jsxRuntime.jsx("span", { children: jsxRuntime.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'
1694
+ ? 'mr'
1695
+ : '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 : (jsxRuntime.jsx(ExpandMoreIcon, { style: {
1696
+ transform: `rotate(${!canExpand && !renderDetailPanel
1697
+ ? positionExpandColumn === 'last' ||
1698
+ theme.direction === 'rtl'
1699
+ ? 90
1700
+ : -90
1701
+ : isExpanded
1702
+ ? -180
1703
+ : 0}deg)`,
1704
+ transition: 'transform 150ms',
1705
+ } })) })) }) })));
1706
+ };
1707
+
1708
+ const INSERT_HERE_TOOLTIP = 'Insert here';
1709
+ const ACTION_ICON_SIZE$1 = 'small';
1710
+ const MRT_InsertHereAction = ({ onClick, }) => {
1711
+ return (jsxRuntime.jsx(Tooltip, { title: INSERT_HERE_TOOLTIP, disableInteractive: true, children: jsxRuntime.jsx(IconButton, { onClick: onClick, size: ACTION_ICON_SIZE$1, children: jsxRuntime.jsx(SubdirectoryArrowLeftIcon, { color: "warning" }) }) }));
1712
+ };
1713
+
1714
+ const MOVE_TO_TOP_TOOLTIP = 'Move to top level';
1715
+ const ACTION_ICON_SIZE = 'small';
1716
+ const ACTION_BUTTON_HEIGHT = '1.75rem';
1717
+ const MRT_MoveToTopAction = ({ onClick }) => {
1718
+ return (jsxRuntime.jsx(Tooltip, { title: MOVE_TO_TOP_TOOLTIP, disableInteractive: true, children: jsxRuntime.jsx(IconButton, { onClick: onClick, size: ACTION_ICON_SIZE, sx: { height: ACTION_BUTTON_HEIGHT }, children: jsxRuntime.jsx(VerticalAlignTopIcon, { fontSize: "small" }) }) }));
1719
+ };
1720
+
1721
+ const MRT_ReorderRowCheckbox = ({ onChange, isSelected, }) => {
1722
+ return (jsxRuntime.jsx(Checkbox, { checked: isSelected, color: "warning", disableRipple: true, onChange: onChange, sx: {
1723
+ color: (theme) => theme.palette.warning.main,
1724
+ '&.Mui-checked': {
1725
+ color: (theme) => theme.palette.warning.main,
1726
+ },
1727
+ } }));
1728
+ };
1729
+
1730
+ /**
1731
+ * Finds the maximum depth in the hierarchy of a given row (recursively searches all descendants).
1732
+ * Used to determine the "size" of the tree being moved.
1733
+ * Example: Row at depth 1 with a child at depth 3 → returns 3
1734
+ */
1735
+ const getDeepestSubRowDepth = (row) => {
1736
+ var _a;
1737
+ if (!((_a = row.subRows) === null || _a === void 0 ? void 0 : _a.length)) {
1738
+ return row.depth;
1739
+ }
1740
+ return row.subRows.reduce((maxDepth, subRow) => Math.max(maxDepth, getDeepestSubRowDepth(subRow)), row.depth);
1741
+ };
1742
+ /**
1743
+ * Extracts an array of IDs of only the selected rows from the selection object.
1744
+ * Filters the record where the value is true and maps only the keys (IDs).
1745
+ * Example: { row1: true, row2: false, row3: true } → ['row1', 'row3']
1746
+ */
1747
+ const getSelectedReorderRowIds = (rowReorderingSelection) => {
1748
+ return Object.entries(rowReorderingSelection !== null && rowReorderingSelection !== void 0 ? rowReorderingSelection : {})
1749
+ .filter(([, isSelected]) => isSelected)
1750
+ .map(([rowId]) => rowId);
1751
+ };
1752
+ /**
1753
+ * Checks WHETHER we can move selected rows as children of target row
1754
+ * without exceeding the maximum allowed depth.
1755
+ * Directly calculates the final maximum depth after the move.
1756
+ * Example: selectedRows at depth 1-2 with descendants to depth 4, target depth 1, maxDepth 5
1757
+ * → new max depth = 1 + 1 + (4 - 1) = 5, which equals maxDepth, so returns false
1758
+ */
1759
+ const canInsertSelectedRowsWithoutExceedingMaxDepth = ({ maxDepth, selectedRows, targetRowDepth, }) => {
1760
+ // Cannot insert if there are no selected rows to move
1761
+ if (selectedRows.length === 0) {
1762
+ return false;
1763
+ }
1764
+ // No depth restriction - can insert anywhere
1765
+ if (maxDepth === undefined) {
1766
+ return true;
1767
+ }
1768
+ // Find the deepest descendant among all selected rows
1769
+ const maxDeepestDescendantDepth = selectedRows.reduce((max, row) => {
1770
+ return Math.max(max, getDeepestSubRowDepth(row));
1771
+ }, 0);
1772
+ // Find the minimum depth of selected rows (to calculate relative depth)
1773
+ const minSelectedRowDepth = Math.min(...selectedRows.map((r) => r.depth));
1774
+ // Calculate the maximum depth after moving rows as children of target
1775
+ // newMaxDepth = target.depth + 1 (as children) + relative depth of selected rows
1776
+ const newMaxDepth = targetRowDepth + 1 + (maxDeepestDescendantDepth - minSelectedRowDepth);
1777
+ return newMaxDepth < maxDepth;
1778
+ };
1779
+ /**
1780
+ * Finds the depth of the FIRST selected row in the selection object.
1781
+ * Used to enforce constraint: can only select rows at the SAME depth.
1782
+ * Example: If I select a row at depth 2, I cannot select a row at depth 3
1783
+ */
1784
+ const getFirstSelectedReorderRowDepth = ({ rowReorderingSelection, table, }) => {
1785
+ var _a, _b;
1786
+ const firstSelectedRowId = (_a = Object.entries(rowReorderingSelection !== null && rowReorderingSelection !== void 0 ? rowReorderingSelection : {}).find(([, isSelected]) => isSelected)) === null || _a === void 0 ? void 0 : _a[0];
1787
+ if (!firstSelectedRowId) {
1788
+ return undefined;
1789
+ }
1790
+ return (_b = table.getRow(firstSelectedRowId, true)) === null || _b === void 0 ? void 0 : _b.depth;
1791
+ };
1792
+ /**
1793
+ * Checks WHETHER we can select a specific row.
1794
+ * Rule: If a selection already exists, new row MUST be at the SAME depth as the first selected.
1795
+ * Without this, you could move rows from different levels which would break the hierarchy.
1796
+ */
1797
+ const canSelectRowForReorder = ({ rowId, rowDepth, rowReorderingSelection, firstSelectedReorderRowDepth, }) => {
1798
+ const isCurrentRowSelected = !!(rowReorderingSelection === null || rowReorderingSelection === void 0 ? void 0 : rowReorderingSelection[rowId]);
1799
+ if (isCurrentRowSelected) {
1800
+ return true;
1801
+ }
1802
+ const hasAnySelection = Object.values(rowReorderingSelection !== null && rowReorderingSelection !== void 0 ? rowReorderingSelection : {}).some(Boolean);
1803
+ if (!hasAnySelection) {
1804
+ return true;
1805
+ }
1806
+ return rowDepth === firstSelectedReorderRowDepth;
2084
1807
  };
2085
-
2086
- const hasActiveExports = (table) => {
2087
- const { activeExports } = table.getState();
2088
- return !!((activeExports === null || activeExports === void 0 ? void 0 : activeExports.selectedFormat) && activeExports.selectedExports.length > 0);
1808
+ /**
1809
+ * Creates an array of MRT_Row objects from an array of IDs.
1810
+ * Finds each row from the table and collects it in the result.
1811
+ * Used to prepare data for the onTreeRowReorder callback.
1812
+ */
1813
+ const buildSelectedRowsArray = (selectedRowIds, table) => {
1814
+ return selectedRowIds.reduce((selectedRows, selectedRowId) => {
1815
+ const selectedRow = table.getRow(selectedRowId, true);
1816
+ if (selectedRow) {
1817
+ selectedRows.push(selectedRow);
1818
+ }
1819
+ return selectedRows;
1820
+ }, []);
2089
1821
  };
2090
- // Same conditions as MRT_ExportsToolbar: pdf format selected, at least one export type,
2091
- // and either grouped or exactly one export type selected.
2092
- const isPrintAvailable = (table) => {
1822
+ /**
1823
+ * Helper function to check if a row is a descendant of another row.
1824
+ * Recursively searches through all subRows to find if targetRowId exists.
1825
+ * Used to prevent circular references (parent cannot become child of its own child).
1826
+ */
1827
+ const isRowInSubtreeOf = (targetRowId, parentRow) => {
2093
1828
  var _a;
2094
- const allFormats = Object.values((_a = table.options.availableExports) !== null && _a !== void 0 ? _a : {}).flatMap((e) => e.formats);
2095
- if (!allFormats.includes('pdf'))
1829
+ if (!((_a = parentRow.subRows) === null || _a === void 0 ? void 0 : _a.length)) {
2096
1830
  return false;
2097
- const { activeExports } = table.getState();
2098
- if (!activeExports)
1831
+ }
1832
+ for (const subRow of parentRow.subRows) {
1833
+ if (subRow.id === targetRowId) {
1834
+ return true;
1835
+ }
1836
+ if (isRowInSubtreeOf(targetRowId, subRow)) {
1837
+ return true;
1838
+ }
1839
+ }
1840
+ return false;
1841
+ };
1842
+ /**
1843
+ * Checks if a row can be used as a valid insert target for selected rows.
1844
+ * Rules: Target row must NOT be already selected AND must NOT be a descendant of any selected row.
1845
+ * This prevents circular references where a parent becomes a child of its own descendants.
1846
+ * Example: If you select "Department", you cannot insert it under "Project" (which is its descendant)
1847
+ */
1848
+ const isValidInsertTarget = ({ targetRowId, selectedRowIds, table, }) => {
1849
+ // Rule 1: Target row cannot be already selected
1850
+ if (selectedRowIds.includes(targetRowId) || selectedRowIds.length === 0) {
2099
1851
  return false;
2100
- const { selectedFormat, selectedExports, grouped } = activeExports;
2101
- return (selectedFormat === 'pdf' &&
2102
- selectedExports.length >= 1 &&
2103
- (grouped || selectedExports.length === 1));
1852
+ }
1853
+ // Rule 2: Target row cannot be a descendant of any selected row
1854
+ // (prevents parent from becoming child of its own descendants)
1855
+ for (const selectedRowId of selectedRowIds) {
1856
+ const selectedRow = table.getRow(selectedRowId, true);
1857
+ if (selectedRow &&
1858
+ isRowInSubtreeOf(targetRowId, selectedRow)) {
1859
+ return false;
1860
+ }
1861
+ }
1862
+ return true;
2104
1863
  };
2105
- const createExportAction = (_a = {}) => {
2106
- var { onExport, renderRow: customRenderRow, renderToolbar: customRenderToolbar } = _a, rest = __rest(_a, ["onExport", "renderRow", "renderToolbar"]);
2107
- // Pure download logic — no notifications. Throws on failure so callers can handle it.
2108
- const defaultOnExport = (_a) => __awaiter(void 0, [_a], void 0, function* ({ rowsToExport, table, }) {
2109
- if (!rowsToExport.length)
2110
- return;
2111
- const { loadExport } = table.options;
2112
- const { activeExports } = table.getState();
2113
- if (!loadExport || !activeExports)
2114
- return;
2115
- const response = yield loadExport({
2116
- format: activeExports.selectedFormat,
2117
- exports: activeExports.selectedExports,
2118
- separated_files: !activeExports.grouped,
2119
- download: false,
2120
- ids: JSON.stringify(rowsToExport.map((r) => r.id)),
2121
- type: 'download',
2122
- });
2123
- downloadExportFiles(response);
1864
+
1865
+ const useTreeRowReorderingCell = ({ row, table, rowReorderingSelection, maxDepth, onTreeRowReorder, }) => {
1866
+ const [isRowHovered, setIsRowHovered] = react.useState(false);
1867
+ const firstSelectedReorderRowDepth = getFirstSelectedReorderRowDepth({
1868
+ rowReorderingSelection,
1869
+ table,
2124
1870
  });
2125
- // Pure print logic — no notifications. Throws on failure so callers can handle it.
2126
- const defaultOnPrint = (_a) => __awaiter(void 0, [_a], void 0, function* ({ rowsToExport, table, }) {
2127
- if (!rowsToExport.length)
2128
- return;
2129
- const { loadExport } = table.options;
2130
- const { activeExports } = table.getState();
2131
- if (!loadExport || !activeExports)
2132
- return;
2133
- const response = yield loadExport({
2134
- format: activeExports.selectedFormat,
2135
- exports: activeExports.selectedExports,
2136
- separated_files: !activeExports.grouped,
2137
- download: false,
2138
- ids: JSON.stringify(rowsToExport.map((r) => r.id)),
2139
- type: 'print',
2140
- });
2141
- printExportFiles(response);
1871
+ const canSelectForReorder = canSelectRowForReorder({
1872
+ rowId: row.id,
1873
+ rowDepth: row.depth,
1874
+ rowReorderingSelection,
1875
+ firstSelectedReorderRowDepth,
2142
1876
  });
2143
- // Single execution pipeline for every export flow (row or toolbar).
2144
- // If a custom handler exists, it receives defaultOnExport and decides when to call it.
2145
- const executeExport = (context) => {
2146
- const executeDefaultExport = () => defaultOnExport(context);
2147
- if (onExport) {
2148
- return onExport(Object.assign(Object.assign({}, context), { defaultOnExport: executeDefaultExport }));
2149
- }
2150
- return executeDefaultExport();
2151
- };
2152
- // Row download: checks for active exports, then wraps with loading/success/error notifications.
2153
- const handleSingleRowExport = (_a) => __awaiter(void 0, [_a], void 0, function* ({ table, row, }) {
2154
- const { localization } = table.options;
2155
- if (!hasActiveExports(table)) {
2156
- notistack.enqueueSnackbar(localization.exportNoExportsSelected, {
2157
- variant: 'warning',
2158
- });
1877
+ const hasAnyReorderSelection = Object.values(rowReorderingSelection !== null && rowReorderingSelection !== void 0 ? rowReorderingSelection : {}).some(Boolean);
1878
+ const selectedReorderRowIds = getSelectedReorderRowIds(rowReorderingSelection);
1879
+ const selectedRowsForReorder = buildSelectedRowsArray(selectedReorderRowIds, table);
1880
+ const shouldShowReorderCheckbox = canSelectForReorder && (isRowHovered || hasAnyReorderSelection);
1881
+ const shouldShowInsertHereAction = selectedReorderRowIds.length > 0 &&
1882
+ isValidInsertTarget({
1883
+ targetRowId: row.id,
1884
+ selectedRowIds: selectedReorderRowIds,
1885
+ table,
1886
+ }) &&
1887
+ canInsertSelectedRowsWithoutExceedingMaxDepth({
1888
+ maxDepth,
1889
+ selectedRows: selectedRowsForReorder,
1890
+ targetRowDepth: row.depth,
1891
+ });
1892
+ const handleReorderCheckboxChange = react.useCallback((event) => {
1893
+ const checked = event.target.checked;
1894
+ table.setRowReorderingSelection((prev) => (Object.assign(Object.assign({}, prev), { [row.id]: checked })));
1895
+ }, [row.id, table]);
1896
+ const handleInsertHereActionClick = react.useCallback(() => {
1897
+ if (!onTreeRowReorder) {
1898
+ console.warn('[MRT] onTreeRowReorder callback is not defined');
2159
1899
  return;
2160
1900
  }
2161
- const loadingKey = notistack.enqueueSnackbar(localization.exportInProgress, {
2162
- variant: 'info',
2163
- persist: true,
2164
- });
2165
1901
  try {
2166
- yield executeExport({ table, rowsToExport: [row] });
2167
- notistack.closeSnackbar(loadingKey);
2168
- notistack.enqueueSnackbar(localization.exportSuccess, { variant: 'success' });
1902
+ const treeRowReorderEvent = {
1903
+ selectedRowIds: selectedReorderRowIds,
1904
+ selectedRows: selectedRowsForReorder,
1905
+ table,
1906
+ targetRow: row,
1907
+ };
1908
+ onTreeRowReorder(treeRowReorderEvent);
2169
1909
  }
2170
- catch (_b) {
2171
- notistack.closeSnackbar(loadingKey);
2172
- notistack.enqueueSnackbar(localization.exportError, { variant: 'error' });
1910
+ catch (error) {
1911
+ console.error('[MRT] Error during tree row reorder:', error);
2173
1912
  }
2174
- });
2175
- // Row print: same guard + notification pattern as download, but calls defaultOnPrint.
2176
- const handleSingleRowPrint = (_a) => __awaiter(void 0, [_a], void 0, function* ({ table, row, }) {
2177
- const { localization } = table.options;
2178
- if (!hasActiveExports(table)) {
2179
- notistack.enqueueSnackbar(localization.exportNoExportsSelected, {
2180
- variant: 'warning',
2181
- });
1913
+ }, [
1914
+ onTreeRowReorder,
1915
+ selectedReorderRowIds,
1916
+ selectedRowsForReorder,
1917
+ table,
1918
+ row,
1919
+ ]);
1920
+ return {
1921
+ isRowHovered,
1922
+ shouldShowReorderCheckbox,
1923
+ shouldShowInsertHereAction,
1924
+ handleRowHoverEnter: () => setIsRowHovered(true),
1925
+ handleRowHoverLeave: () => setIsRowHovered(false),
1926
+ handleReorderCheckboxChange,
1927
+ handleInsertHereActionClick,
1928
+ isReorderCheckboxSelected: !!(rowReorderingSelection === null || rowReorderingSelection === void 0 ? void 0 : rowReorderingSelection[row.id]),
1929
+ };
1930
+ };
1931
+
1932
+ const useTreeRowReorderingHeader = ({ table, enableRowReordering, onTreeRowReorder, }) => {
1933
+ const rowReorderingSelection = useMRT_SliceValue(table._uiStore, (s) => s.rowReorderingSelection);
1934
+ const selectedReorderRowIds = getSelectedReorderRowIds(rowReorderingSelection);
1935
+ const selectedRowsForReorder = buildSelectedRowsArray(selectedReorderRowIds, table);
1936
+ const shouldShowMoveToTopLevelAction = !!enableRowReordering &&
1937
+ selectedRowsForReorder.length > 0 &&
1938
+ selectedRowsForReorder.some((selectedRow) => selectedRow.depth > 0);
1939
+ const handleMoveToTopLevelActionClick = react.useCallback(() => {
1940
+ if (!onTreeRowReorder) {
1941
+ console.warn('[MRT] onTreeRowReorder callback is not defined');
2182
1942
  return;
2183
1943
  }
2184
- const loadingKey = notistack.enqueueSnackbar(localization.exportInProgress, {
2185
- variant: 'info',
2186
- persist: true,
2187
- });
2188
1944
  try {
2189
- yield defaultOnPrint({ table, rowsToExport: [row] });
2190
- notistack.closeSnackbar(loadingKey);
2191
- notistack.enqueueSnackbar(localization.exportSuccess, { variant: 'success' });
1945
+ const treeRowReorderEvent = {
1946
+ selectedRowIds: selectedReorderRowIds,
1947
+ selectedRows: selectedRowsForReorder,
1948
+ table,
1949
+ targetRow: null,
1950
+ };
1951
+ onTreeRowReorder(treeRowReorderEvent);
2192
1952
  }
2193
- catch (_b) {
2194
- notistack.closeSnackbar(loadingKey);
2195
- notistack.enqueueSnackbar(localization.exportError, { variant: 'error' });
1953
+ catch (error) {
1954
+ console.error('[MRT] Error during tree row reorder to top level:', error);
1955
+ }
1956
+ }, [onTreeRowReorder, selectedReorderRowIds, selectedRowsForReorder, table]);
1957
+ return {
1958
+ shouldShowMoveToTopLevelAction,
1959
+ handleMoveToTopLevelActionClick,
1960
+ };
1961
+ };
1962
+
1963
+ const TREE_REORDER_ICON_SPACING = '0.25rem';
1964
+ const getMRT_RowExpandColumnDef = (tableOptions) => {
1965
+ var _a;
1966
+ const { defaultColumn, enableRowReordering, enableExpandAll, groupedColumnMode, maxDepth, onTreeRowReorder, positionExpandColumn, renderDetailPanel, state: { grouping }, } = tableOptions;
1967
+ const alignProps = positionExpandColumn === 'last'
1968
+ ? {
1969
+ align: 'right',
2196
1970
  }
2197
- });
2198
- // Resolves selected rows from table state for toolbar-triggered export (custom renderToolbar only).
2199
- const handleMultipleRowExport = ({ table, }) => {
2200
- const rowsToExport = table.getSelectedRowModel().rows;
2201
- return executeExport({ table, rowsToExport });
2202
- };
2203
- const createRowExportExecutor = (context) => () => {
2204
- void handleSingleRowExport(context);
1971
+ : undefined;
1972
+ return Object.assign(Object.assign({ Cell: ({ cell, column, row, staticRowIndex, table }) => {
1973
+ var _a, _b, _c;
1974
+ const rowReorderingSelection = useMRT_SliceValue(table._uiStore, (s) => s.rowReorderingSelection);
1975
+ const cellLogic = useTreeRowReorderingCell({
1976
+ row,
1977
+ table,
1978
+ rowReorderingSelection,
1979
+ maxDepth,
1980
+ onTreeRowReorder,
1981
+ });
1982
+ const expandButtonProps = { row, staticRowIndex, table };
1983
+ const subRowsLength = (_a = row.subRows) === null || _a === void 0 ? void 0 : _a.length;
1984
+ const customGroupedCell = (_c = (_b = column.columnDef).GroupedCell) === null || _c === void 0 ? void 0 : _c.call(_b, {
1985
+ cell,
1986
+ column,
1987
+ row,
1988
+ table,
1989
+ staticRowIndex,
1990
+ });
1991
+ if (groupedColumnMode === 'remove' && row.groupingColumnId) {
1992
+ const defaultGroupedCell = (jsxRuntime.jsx(Tooltip, Object.assign({}, getCommonTooltipProps('right'), { title: table.getColumn(row.groupingColumnId).columnDef.header, children: jsxRuntime.jsx("span", { children: row.groupingValue }) })));
1993
+ return (jsxRuntime.jsxs(Stack, { alignItems: "center", flexDirection: "row", gap: TREE_REORDER_ICON_SPACING, onMouseEnter: cellLogic.handleRowHoverEnter, onMouseLeave: cellLogic.handleRowHoverLeave, width: "100%", children: [jsxRuntime.jsx(MRT_ExpandButton, Object.assign({}, expandButtonProps)), column.columnDef.GroupedCell
1994
+ ? customGroupedCell
1995
+ : defaultGroupedCell, cellLogic.shouldShowReorderCheckbox && (jsxRuntime.jsx(MRT_ReorderRowCheckbox, { isSelected: cellLogic.isReorderCheckboxSelected, onChange: cellLogic.handleReorderCheckboxChange })), cellLogic.shouldShowInsertHereAction && (jsxRuntime.jsx(MRT_InsertHereAction, { onClick: cellLogic.handleInsertHereActionClick })), !!subRowsLength && jsxRuntime.jsxs("span", { children: ["(", subRowsLength, ")"] })] }));
1996
+ }
1997
+ return (jsxRuntime.jsxs(Stack, { alignItems: "center", flexDirection: "row", gap: TREE_REORDER_ICON_SPACING, onMouseEnter: cellLogic.handleRowHoverEnter, onMouseLeave: cellLogic.handleRowHoverLeave, width: "100%", children: [jsxRuntime.jsx(MRT_ExpandButton, Object.assign({}, expandButtonProps)), customGroupedCell, cellLogic.shouldShowReorderCheckbox && (jsxRuntime.jsx(MRT_ReorderRowCheckbox, { isSelected: cellLogic.isReorderCheckboxSelected, onChange: cellLogic.handleReorderCheckboxChange })), cellLogic.shouldShowInsertHereAction && (jsxRuntime.jsx(MRT_InsertHereAction, { onClick: cellLogic.handleInsertHereActionClick }))] }));
1998
+ }, Header: enableExpandAll
1999
+ ? ({ table }) => {
2000
+ var _a;
2001
+ const headerLogic = useTreeRowReorderingHeader({
2002
+ table,
2003
+ enableRowReordering,
2004
+ onTreeRowReorder,
2005
+ });
2006
+ return (jsxRuntime.jsxs(Stack, { alignItems: "center", flexDirection: "row", gap: TREE_REORDER_ICON_SPACING, children: [jsxRuntime.jsx(MRT_ExpandAllButton, { table: table }), headerLogic.shouldShowMoveToTopLevelAction && (jsxRuntime.jsx(MRT_MoveToTopAction, { onClick: headerLogic.handleMoveToTopLevelActionClick })), groupedColumnMode === 'remove' &&
2007
+ ((_a = grouping === null || grouping === void 0 ? void 0 : grouping.map((groupedColumnId) => table.getColumn(groupedColumnId).columnDef.header)) === null || _a === void 0 ? void 0 : _a.join(', '))] }));
2008
+ }
2009
+ : undefined, muiTableBodyCellProps: alignProps, muiTableHeadCellProps: alignProps }, defaultDisplayColumnProps({
2010
+ header: 'expand',
2011
+ id: 'mrt-row-expand',
2012
+ size: groupedColumnMode === 'remove'
2013
+ ? ((_a = defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.size) !== null && _a !== void 0 ? _a : 180)
2014
+ : renderDetailPanel
2015
+ ? enableExpandAll
2016
+ ? 60
2017
+ : 70
2018
+ : 100,
2019
+ tableOptions,
2020
+ })), { enableResizing: true });
2021
+ };
2022
+
2023
+ const getMRT_RowNumbersColumnDef = (tableOptions) => {
2024
+ const { localization, rowNumberDisplayMode } = tableOptions;
2025
+ const { pagination: { pageIndex, pageSize }, } = tableOptions.state;
2026
+ return Object.assign({ Cell: ({ row, staticRowIndex }) => {
2027
+ var _a;
2028
+ return ((_a = (rowNumberDisplayMode === 'static'
2029
+ ? (staticRowIndex || 0) + (pageSize || 0) * (pageIndex || 0)
2030
+ : row.index)) !== null && _a !== void 0 ? _a : 0) + 1;
2031
+ }, Header: () => localization.rowNumber, grow: false }, defaultDisplayColumnProps({
2032
+ header: 'rowNumbers',
2033
+ id: 'mrt-row-numbers',
2034
+ size: 50,
2035
+ tableOptions,
2036
+ }));
2037
+ };
2038
+
2039
+ const MRT_RowPinButton = (_a) => {
2040
+ var { pinningPosition, row, table } = _a, rest = __rest(_a, ["pinningPosition", "row", "table"]);
2041
+ const { options: { icons: { CloseIcon, PushPinIcon }, localization, rowPinningDisplayMode, }, } = table;
2042
+ const isPinned = row.getIsPinned();
2043
+ const [tooltipOpened, setTooltipOpened] = react.useState(false);
2044
+ const handleTogglePin = (event) => {
2045
+ setTooltipOpened(false);
2046
+ event.stopPropagation();
2047
+ row.pin(isPinned ? false : pinningPosition);
2205
2048
  };
2206
- const createRowPrintExecutor = (context) => () => {
2207
- void handleSingleRowPrint(context);
2049
+ return (jsxRuntime.jsx(Tooltip, Object.assign({}, getCommonTooltipProps(), { open: tooltipOpened, title: isPinned ? localization.unpin : localization.pin, children: jsxRuntime.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 ? (jsxRuntime.jsx(CloseIcon, {})) : (jsxRuntime.jsx(PushPinIcon, { fontSize: "small", style: {
2050
+ transform: `rotate(${rowPinningDisplayMode === 'sticky'
2051
+ ? 135
2052
+ : pinningPosition === 'top'
2053
+ ? 180
2054
+ : 0}deg)`,
2055
+ } })) })) })));
2056
+ };
2057
+
2058
+ const MRT_TableBodyRowPinButton = (_a) => {
2059
+ var { row, table } = _a, rest = __rest(_a, ["row", "table"]);
2060
+ const { options: { enableRowPinning, rowPinningDisplayMode }, } = table;
2061
+ const density = useMRT_SliceValue(table._uiStore, (s) => s.density);
2062
+ const canPin = parseFromValuesOrFunc(enableRowPinning, row);
2063
+ if (!canPin)
2064
+ return null;
2065
+ const rowPinButtonProps = Object.assign({ row,
2066
+ table }, rest);
2067
+ if (rowPinningDisplayMode === 'top-and-bottom' && !row.getIsPinned()) {
2068
+ return (jsxRuntime.jsxs(Box, { sx: {
2069
+ display: 'flex',
2070
+ flexDirection: density === 'compact' ? 'row' : 'column',
2071
+ }, children: [jsxRuntime.jsx(MRT_RowPinButton, Object.assign({ pinningPosition: "top" }, rowPinButtonProps)), jsxRuntime.jsx(MRT_RowPinButton, Object.assign({ pinningPosition: "bottom" }, rowPinButtonProps))] }));
2072
+ }
2073
+ return (jsxRuntime.jsx(MRT_RowPinButton, Object.assign({ pinningPosition: rowPinningDisplayMode === 'bottom' ? 'bottom' : 'top' }, rowPinButtonProps)));
2074
+ };
2075
+
2076
+ const getMRT_RowPinningColumnDef = (tableOptions) => {
2077
+ return Object.assign({ Cell: ({ row, table }) => (jsxRuntime.jsx(MRT_TableBodyRowPinButton, { row: row, table: table })), grow: false }, defaultDisplayColumnProps({
2078
+ header: 'pin',
2079
+ id: 'mrt-row-pin',
2080
+ size: 60,
2081
+ tableOptions,
2082
+ }));
2083
+ };
2084
+
2085
+ const MRT_SelectAllMenu = ({ table, }) => {
2086
+ const [anchorEl, setAnchorEl] = react.useState(null);
2087
+ const [isSelectingAllPages, setIsSelectingAllPages] = react.useState(false);
2088
+ const { getState, options: { enableRowPinning, getAllSelectableRowIds, localization, rowPinningDisplayMode, }, refs: { allSelectableRowIdsRef }, } = table;
2089
+ // rowSelection is read here so that any change to selection will trigger a re-render and update the menu options accordingly
2090
+ const { isLoading, rowSelection } = getState();
2091
+ const isAllCurrentPageSelected = table.getIsAllPageRowsSelected();
2092
+ const isAllPagesActive = getIsAllPagesSelectionActive(table, rowSelection);
2093
+ const handleOpen = (event) => {
2094
+ setAnchorEl(event.currentTarget);
2208
2095
  };
2209
- const createToolbarExportExecutor = (context) => () => {
2210
- void handleMultipleRowExport(context);
2096
+ const handleClose = () => {
2097
+ setAnchorEl(null);
2211
2098
  };
2212
- // Renders download + optional print button. Print is shown under the same conditions
2213
- // as in MRT_ExportsToolbar: pdf format selected, active exports, grouped or single type.
2214
- const renderRowAction = (context) => {
2215
- const onRowExport = createRowExportExecutor(context);
2216
- const onRowPrint = isPrintAvailable(context.table)
2217
- ? createRowPrintExecutor(context)
2218
- : undefined;
2219
- if (customRenderRow) {
2220
- return customRenderRow(Object.assign(Object.assign({}, context), { onExport: onRowExport }));
2099
+ // Clears row pinning on every bulk selection/deselection
2100
+ const clearPinning = () => {
2101
+ if (enableRowPinning && (rowPinningDisplayMode === null || rowPinningDisplayMode === void 0 ? void 0 : rowPinningDisplayMode.includes('select'))) {
2102
+ table.setRowPinning({ bottom: [], top: [] });
2221
2103
  }
2222
- return jsxRuntime.jsx(ExportRowAction, { onExport: onRowExport, onPrint: onRowPrint });
2223
2104
  };
2224
- // Uses custom toolbar renderer when provided; otherwise renders MRT_ExportsToolbar.
2225
- // loadExport is always wrapped with notifications so that loading/success/error are shown
2226
- // regardless of whether a custom onExport handler was provided.
2227
- // When onExport is provided, it intercepts the call and returns [] so MRT_ExportsToolbar
2228
- // does not attempt a second download from an empty response.
2229
- const renderToolbarAction = (context) => {
2230
- const { table } = context;
2231
- const { availableExports, loadExport, onActiveExportsChange, localization, } = table.options;
2232
- const { activeExports } = table.getState();
2233
- if (customRenderToolbar) {
2234
- return customRenderToolbar(Object.assign(Object.assign({}, context), { onExport: createToolbarExportExecutor(context) }));
2105
+ // ── Current-page actions ────────────────────────────────────────────────────
2106
+ const handleSelectCurrentPage = () => {
2107
+ table.toggleAllPageRowsSelected(true);
2108
+ clearPinning();
2109
+ handleClose();
2110
+ };
2111
+ const handleDeselectCurrentPage = () => {
2112
+ if (allSelectableRowIdsRef.current.length > 0) {
2113
+ // 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.
2114
+ table.setRowSelection({});
2115
+ allSelectableRowIdsRef.current = [];
2235
2116
  }
2236
- if (!availableExports ||
2237
- !loadExport ||
2238
- !onActiveExportsChange ||
2239
- !activeExports) {
2240
- return null;
2117
+ else {
2118
+ table.toggleAllPageRowsSelected(false);
2241
2119
  }
2242
- const notifiedLoadExport = (params) => __awaiter(void 0, void 0, void 0, function* () {
2243
- const loadingKey = notistack.enqueueSnackbar(localization.exportInProgress, {
2244
- variant: 'info',
2245
- persist: true,
2246
- });
2120
+ clearPinning();
2121
+ handleClose();
2122
+ };
2123
+ // ── All-pages actions ───────────────────────────────────────────────────────
2124
+ const handleSelectAllPages = () => __awaiter(void 0, void 0, void 0, function* () {
2125
+ handleClose();
2126
+ if (getAllSelectableRowIds) {
2127
+ // Server-side: IDs are not available locally, fetch them from the API
2128
+ setIsSelectingAllPages(true);
2129
+ table.setShowProgressBars(true);
2247
2130
  try {
2248
- let response;
2249
- if (onExport) {
2250
- const rowsToExport = table.getSelectedRowModel().rows;
2251
- yield executeExport({ table, rowsToExport });
2252
- response = [];
2253
- }
2254
- else {
2255
- response = yield loadExport(params);
2256
- }
2257
- notistack.closeSnackbar(loadingKey);
2258
- notistack.enqueueSnackbar(localization.exportSuccess, { variant: 'success' });
2259
- return response;
2131
+ const ids = yield getAllSelectableRowIds({ table });
2132
+ allSelectableRowIdsRef.current = ids;
2133
+ const newSelection = {};
2134
+ ids.forEach((id) => {
2135
+ newSelection[id] = true;
2136
+ });
2137
+ table.setRowSelection(newSelection);
2138
+ clearPinning();
2260
2139
  }
2261
- catch (_a) {
2262
- notistack.closeSnackbar(loadingKey);
2263
- notistack.enqueueSnackbar(localization.exportError, { variant: 'error' });
2264
- return [];
2140
+ finally {
2141
+ setIsSelectingAllPages(false);
2142
+ table.setShowProgressBars(false);
2265
2143
  }
2266
- });
2267
- return (jsxRuntime.jsx(MRT_ExportsToolbar, { table: table, availableExports: availableExports, exportState: activeExports, onExportStateChange: onActiveExportsChange, loadExport: notifiedLoadExport }));
2144
+ }
2145
+ else {
2146
+ // Client-side: all data is available locally
2147
+ table.toggleAllRowsSelected(true);
2148
+ clearPinning();
2149
+ }
2150
+ });
2151
+ const handleDeselectAllPages = () => {
2152
+ if (getAllSelectableRowIds) {
2153
+ table.setRowSelection({});
2154
+ }
2155
+ else {
2156
+ table.toggleAllRowsSelected(false);
2157
+ }
2158
+ allSelectableRowIdsRef.current = [];
2159
+ clearPinning();
2160
+ handleClose();
2268
2161
  };
2269
- return Object.assign({ name: 'export', renderRow: renderRowAction, renderToolbar: renderToolbarAction }, rest);
2162
+ const isDisabled = isLoading || isSelectingAllPages;
2163
+ return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(Tooltip, Object.assign({}, getCommonTooltipProps(), { title: localization.toggleSelectAll, children: jsxRuntime.jsx("span", { children: jsxRuntime.jsx(IconButton, { "aria-label": localization.toggleSelectAll, disabled: isDisabled, onClick: handleOpen, size: "small", sx: { height: '1.5rem', width: '1.5rem' }, children: jsxRuntime.jsx(table.options.icons.MoreVertIcon, { style: { transform: 'scale(0.85)' } }) }) }) })), jsxRuntime.jsxs(Menu, { anchorEl: anchorEl, onClose: handleClose, open: Boolean(anchorEl), children: [isAllCurrentPageSelected ? (jsxRuntime.jsx(MenuItem, { onClick: handleDeselectCurrentPage, children: localization.deselectAllOnCurrentPage })) : (jsxRuntime.jsx(MenuItem, { onClick: handleSelectCurrentPage, children: localization.selectAllOnCurrentPage })), isAllPagesActive ? (jsxRuntime.jsx(MenuItem, { onClick: handleDeselectAllPages, children: localization.deselectAllOnAllPages })) : (jsxRuntime.jsxs(MenuItem, { disabled: isSelectingAllPages, onClick: handleSelectAllPages, children: [isSelectingAllPages && (jsxRuntime.jsx(CircularProgress, { "aria-label": "Loading", size: 14, sx: { mr: 1 } })), localization.selectAllOnAllPages] }))] })] }));
2164
+ };
2165
+
2166
+ const MRT_SelectCheckbox = (_a) => {
2167
+ var _b;
2168
+ var { row, staticRowIndex, table } = _a, rest = __rest(_a, ["row", "staticRowIndex", "table"]);
2169
+ const { getState, options: { enableMultiRowSelection, localization, muiSelectAllCheckboxProps, muiSelectCheckboxProps, selectAllMode, }, } = table;
2170
+ const { isLoading } = getState();
2171
+ const density = useMRT_SliceValue(table._uiStore, (s) => s.density);
2172
+ const selectAll = !row;
2173
+ const allRowsSelected = selectAll
2174
+ ? selectAllMode === 'page'
2175
+ ? table.getIsAllPageRowsSelected()
2176
+ : table.getIsAllRowsSelected()
2177
+ : undefined;
2178
+ const isChecked = selectAll
2179
+ ? allRowsSelected
2180
+ : getIsRowSelected({ row, table });
2181
+ const checkboxProps = Object.assign(Object.assign({}, (selectAll
2182
+ ? parseFromValuesOrFunc(muiSelectAllCheckboxProps, { table })
2183
+ : parseFromValuesOrFunc(muiSelectCheckboxProps, {
2184
+ row,
2185
+ staticRowIndex,
2186
+ table,
2187
+ }))), rest);
2188
+ const onSelectionChange = row
2189
+ ? getMRT_RowSelectionHandler({
2190
+ row,
2191
+ staticRowIndex,
2192
+ table,
2193
+ })
2194
+ : undefined;
2195
+ const onSelectAllChange = getMRT_SelectAllHandler({ table });
2196
+ const commonProps = Object.assign(Object.assign({ 'aria-label': selectAll
2197
+ ? localization.toggleSelectAll
2198
+ : localization.toggleSelectRow, checked: isChecked, disabled: isLoading || (row && !row.getCanSelect()) || (row === null || row === void 0 ? void 0 : row.id) === 'mrt-row-create', inputProps: {
2199
+ 'aria-label': selectAll
2200
+ ? localization.toggleSelectAll
2201
+ : localization.toggleSelectRow,
2202
+ }, onChange: (event) => {
2203
+ event.stopPropagation();
2204
+ selectAll ? onSelectAllChange(event) : onSelectionChange(event);
2205
+ }, size: (density === 'compact' ? 'small' : 'medium') }, checkboxProps), { onClick: (e) => {
2206
+ var _a;
2207
+ e.stopPropagation();
2208
+ (_a = checkboxProps === null || checkboxProps === void 0 ? void 0 : checkboxProps.onClick) === null || _a === void 0 ? void 0 : _a.call(checkboxProps, e);
2209
+ }, 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 });
2210
+ return (jsxRuntime.jsx(Tooltip, Object.assign({}, getCommonTooltipProps(), { title: (_b = checkboxProps === null || checkboxProps === void 0 ? void 0 : checkboxProps.title) !== null && _b !== void 0 ? _b : (selectAll
2211
+ ? localization.toggleSelectAll
2212
+ : localization.toggleSelectRow), children: enableMultiRowSelection === false ? (jsxRuntime.jsx(Radio, Object.assign({}, commonProps))) : (jsxRuntime.jsx(Checkbox, Object.assign({ disableRipple: true, indeterminate: !isChecked && selectAll
2213
+ ? table.getIsSomeRowsSelected()
2214
+ : (row === null || row === void 0 ? void 0 : row.getIsSomeSelected()) && row.getCanSelectSubRows() }, commonProps))) })));
2215
+ };
2216
+
2217
+ const getMRT_RowSelectColumnDef = (tableOptions) => {
2218
+ const { enableMultiRowSelection, enableSelectAll } = tableOptions;
2219
+ return Object.assign({ Cell: ({ row, staticRowIndex, table }) => (jsxRuntime.jsx(MRT_SelectCheckbox, { row: row, staticRowIndex: staticRowIndex, table: table })), Header: enableSelectAll && enableMultiRowSelection
2220
+ ? ({ table }) => (jsxRuntime.jsxs(Box, { sx: { alignItems: 'center', display: 'flex' }, children: [jsxRuntime.jsx(MRT_SelectCheckbox, { table: table }), jsxRuntime.jsx(MRT_SelectAllMenu, { table: table })] }))
2221
+ : undefined, grow: false }, defaultDisplayColumnProps({
2222
+ header: 'select',
2223
+ id: '__check__',
2224
+ size: enableSelectAll ? 90 : 70, // widened from 60 to accommodate both the checkbox and the menu button
2225
+ tableOptions,
2226
+ }));
2227
+ };
2228
+
2229
+ const MRT_Default_Icons = {
2230
+ AddIcon,
2231
+ ArrowDownwardIcon,
2232
+ ArrowRightIcon,
2233
+ CancelIcon,
2234
+ ChevronLeftIcon,
2235
+ ChevronRightIcon,
2236
+ ClearAllIcon,
2237
+ CloseIcon,
2238
+ ContentCopy,
2239
+ DensityLargeIcon,
2240
+ DensityMediumIcon,
2241
+ DensitySmallIcon,
2242
+ DragHandleIcon,
2243
+ DynamicFeedIcon,
2244
+ EditIcon,
2245
+ ExpandMoreIcon,
2246
+ FilterAltIcon,
2247
+ FilterListIcon,
2248
+ FilterListOffIcon,
2249
+ FirstPageIcon,
2250
+ FullscreenExitIcon,
2251
+ FullscreenIcon,
2252
+ KeyboardDoubleArrowDownIcon,
2253
+ LastPageIcon,
2254
+ MoreHorizIcon,
2255
+ MoreVertIcon,
2256
+ PushPinIcon,
2257
+ RestartAltIcon,
2258
+ SaveIcon,
2259
+ SearchIcon,
2260
+ SearchOffIcon,
2261
+ SortIcon,
2262
+ SyncAltIcon,
2263
+ ViewColumnIcon,
2264
+ VisibilityOffIcon,
2265
+ };
2266
+
2267
+ const MRT_Localization_EN = {
2268
+ language: 'en',
2269
+ actions: 'Actions',
2270
+ and: 'and',
2271
+ booleanFalse: 'False',
2272
+ booleanTrue: 'True',
2273
+ cancel: 'Cancel',
2274
+ close: 'Close',
2275
+ changeFilterMode: 'Change filter mode',
2276
+ changeSearchMode: 'Change search mode',
2277
+ clearFilter: 'Clear filter',
2278
+ clearSearch: 'Clear search',
2279
+ clearSelection: 'Clear selection',
2280
+ clearSort: 'Clear sort',
2281
+ deselectAllOnAllPages: 'Deselect all on all pages',
2282
+ deselectAllOnCurrentPage: 'Deselect all on current page',
2283
+ clickToCopy: 'Click to copy',
2284
+ copy: 'Copy',
2285
+ collapse: 'Collapse',
2286
+ collapseAll: 'Collapse all',
2287
+ columnActions: 'Column Actions',
2288
+ columns: 'Columns',
2289
+ copiedToClipboard: 'Copied to clipboard',
2290
+ dropToGroupBy: 'Drop to group by {column}',
2291
+ edit: 'Edit',
2292
+ expand: 'Expand',
2293
+ expandAll: 'Expand all',
2294
+ filterArrIncludes: 'Includes',
2295
+ filterArrIncludesAll: 'Includes all',
2296
+ filterArrIncludesSome: 'Includes',
2297
+ filterBetween: 'Between',
2298
+ filterBetweenInclusive: 'Between Inclusive',
2299
+ filterByColumn: 'Filter by {column}',
2300
+ filterFrom: 'From',
2301
+ filterTo: 'To',
2302
+ filterContains: 'Contains',
2303
+ filterEmpty: 'Empty',
2304
+ filterEndsWith: 'Ends With',
2305
+ filterEquals: 'Equals',
2306
+ filterEqualsString: 'Equals',
2307
+ filterFuzzy: 'Fuzzy',
2308
+ filterGreaterThan: 'Greater Than',
2309
+ filterGreaterThanOrEqualTo: 'Greater Than Or Equal To',
2310
+ filterInArray: 'Is any of',
2311
+ filterIsAnyOf: 'Is any of',
2312
+ filterInNumberRange: 'Between',
2313
+ filterIncludesString: 'Contains',
2314
+ filterIncludesStringSensitive: 'Contains',
2315
+ filterLessThan: 'Less Than',
2316
+ filterLessThanOrEqualTo: 'Less Than Or Equal To',
2317
+ filterMode: 'Filter Mode: {filterType}',
2318
+ filterNoOptions: 'No filter options available',
2319
+ filterNotEmpty: 'Not Empty',
2320
+ filterNotEquals: 'Not Equals',
2321
+ filterNotContains: 'Does Not Contain',
2322
+ filterLogic: 'Logic',
2323
+ filterOperator: 'Operator',
2324
+ filterStartsWith: 'Starts With',
2325
+ filterWeakEquals: 'Equals',
2326
+ filterCurrentWeek: 'Current Week',
2327
+ filterCurrentMonth: 'Current Month',
2328
+ filterLast7Days: 'Last 7 Days',
2329
+ filterLastWeek: 'Last Week',
2330
+ filterLastMonth: 'Last Month',
2331
+ filterFromToday: 'From Today',
2332
+ filterToToday: 'To Today',
2333
+ filteringByColumn: 'Filtering by {column} - {filterType} {filterValue}',
2334
+ goToFirstPage: 'Go to first page',
2335
+ goToLastPage: 'Go to last page',
2336
+ goToNextPage: 'Go to next page',
2337
+ goToPreviousPage: 'Go to previous page',
2338
+ grab: 'Grab',
2339
+ groupByColumn: 'Group by {column}',
2340
+ groupedBy: 'Grouped by ',
2341
+ hideAll: 'Hide all',
2342
+ hideColumn: 'Hide {column} column',
2343
+ max: 'Max',
2344
+ min: 'Min',
2345
+ move: 'Move',
2346
+ noRecordsToDisplay: 'No records to display',
2347
+ noResultsFound: 'No results found',
2348
+ moreThan: 'more than',
2349
+ of: 'of',
2350
+ or: 'or',
2351
+ pin: 'Pin',
2352
+ pinToLeft: 'Pin to left',
2353
+ pinToRight: 'Pin to right',
2354
+ resetColumnSize: 'Reset column size',
2355
+ resetOrder: 'Reset order',
2356
+ rowActions: 'Row Actions',
2357
+ rowNumber: '#',
2358
+ rowNumbers: 'Row Numbers',
2359
+ rowsPerPage: 'Rows per page',
2360
+ countRows: 'Count Rows',
2361
+ countRowsTooltip: 'Count total rows for current filters',
2362
+ rowCount: 'Row Count',
2363
+ rowsSelected: '{count} row(s) selected',
2364
+ save: 'Save',
2365
+ search: 'Search',
2366
+ selectedCountOfRowCountRowsSelected: '{selectedCount} of {rowCount} row(s) selected',
2367
+ select: 'Select',
2368
+ selectAllOnAllPages: 'Select all on all pages',
2369
+ selectAllOnCurrentPage: 'Select all on current page',
2370
+ showAll: 'Show all',
2371
+ showAllColumns: 'Show all columns',
2372
+ showHideColumns: 'Columns',
2373
+ showHideFilters: 'Show/Hide filters',
2374
+ showHideSearch: 'Show/Hide search',
2375
+ showAdvancedFilters: 'Show advanced filters',
2376
+ advancedFilters: 'Advanced Filters',
2377
+ filters: 'Filters',
2378
+ add: 'Add',
2379
+ newEntry: 'New Entry',
2380
+ clear: 'Clear',
2381
+ discardChanges: 'Discard changes',
2382
+ saveFilters: 'Save filters',
2383
+ savedFilters: 'Saved filters',
2384
+ noSavedFilters: 'No saved filters',
2385
+ filterName: 'Filter name',
2386
+ apply: 'Apply',
2387
+ sortByColumnAsc: 'Sort by {column} ascending',
2388
+ sortByColumnDesc: 'Sort by {column} descending',
2389
+ sortedByColumnAsc: 'Sorted by {column} ascending',
2390
+ sortedByColumnDesc: 'Sorted by {column} descending',
2391
+ thenBy: ', then by ',
2392
+ toggleDensity: 'Density',
2393
+ densityCompact: 'Compact',
2394
+ densityStandard: 'Standard',
2395
+ densityComfortable: 'Comfortable',
2396
+ toggleFullScreen: 'Toggle full screen',
2397
+ toggleSelectAll: 'Toggle select all',
2398
+ toggleSelectRow: 'Toggle select row',
2399
+ toggleVisibility: 'Toggle visibility',
2400
+ ungroupByColumn: 'Ungroup by {column}',
2401
+ unpin: 'Unpin',
2402
+ unpinAll: 'Unpin all',
2403
+ dimensionRotationEnabled: 'Rotation enabled',
2404
+ dimensionRotationDisabled: 'Rotation disabled',
2405
+ length: 'Length',
2406
+ width: 'Width',
2407
+ height: 'Height',
2408
+ depth: 'Depth',
2409
+ tolerance: 'Tolerance',
2410
+ exportButton: 'Export',
2411
+ exportSelectRowsTooltip: 'Select rows to export',
2412
+ exportPrintPdf: 'Print PDF',
2413
+ exportDownload: 'Download',
2414
+ exportGrouped: 'Group files',
2415
+ exportInProgress: 'Export in progress...',
2416
+ exportSuccess: 'Export completed successfully.',
2417
+ exportError: 'Export failed. Please try again.',
2418
+ exportNoExportsSelected: 'No export type selected. Please configure the export first.',
2419
+ deleteConfirmationTitle: 'Delete Row',
2420
+ deleteConfirmationMessage: 'Are you sure you want to delete the selected row(s)?',
2421
+ deleteConfirmYes: 'Delete',
2422
+ deleteConfirmNo: 'Cancel',
2423
+ deleteConfirmDeleting: 'Deleting...',
2424
+ errorTitle: 'Unexpected error',
2425
+ errorMessage: 'An unexpected error occurred. Please try again.',
2426
+ serverTableErrorTitle: 'Unable to load table',
2427
+ serverTableErrorMessage: 'Something went wrong while loading the table configuration. Please try again.',
2428
+ serverTableErrorRetry: 'Try again',
2429
+ resetState: 'Reset State',
2430
+ tableOptions: 'Options',
2270
2431
  };
2271
2432
 
2272
2433
  const MRT_DefaultColumn = {
@@ -2475,6 +2636,11 @@ const useMRT_Effects = (table) => {
2475
2636
  }, [density]);
2476
2637
  };
2477
2638
 
2639
+ // Keeps the local rows array from growing past the current page size. New rows are
2640
+ // inserted at the front, so overflow is trimmed off the tail (the oldest existing
2641
+ // rows), since the local state is expected to be reconciled with the source of
2642
+ // truth on the next fetch.
2643
+ const capRowsToPageSize = (rows, pageSize) => pageSize && rows.length > pageSize ? rows.slice(0, pageSize) : rows;
2478
2644
  const normalizeRowInput = (rowInput) => (Array.isArray(rowInput) ? rowInput : [rowInput]);
2479
2645
  const getResolvedRowId = (row, index, parentRow, getRowId) => {
2480
2646
  const customRowId = getRowId === null || getRowId === void 0 ? void 0 : getRowId(row, index, parentRow);
@@ -2485,7 +2651,7 @@ const getResolvedRowId = (row, index, parentRow, getRowId) => {
2485
2651
  return String(row.id);
2486
2652
  return undefined;
2487
2653
  };
2488
- const handleAddRow = ({ setRowsState, }) => {
2654
+ const handleAddRow = ({ pageSize, setRowsState, }) => {
2489
2655
  return (rowInput) => {
2490
2656
  const rowsToAdd = normalizeRowInput(rowInput);
2491
2657
  const hasValidRowIds = rowsToAdd.every((row, index) => {
@@ -2495,7 +2661,7 @@ const handleAddRow = ({ setRowsState, }) => {
2495
2661
  if (!hasValidRowIds) {
2496
2662
  throw new Error('Each row must have a valid `id` property or a `getRowId` function must be provided to generate unique IDs.');
2497
2663
  }
2498
- setRowsState((previousRows) => [...previousRows, ...rowsToAdd]);
2664
+ setRowsState((previousRows) => capRowsToPageSize([...rowsToAdd, ...previousRows], pageSize));
2499
2665
  };
2500
2666
  };
2501
2667
  const handleUpdateRow = ({ getRowId, setRowsState, }) => {
@@ -2525,7 +2691,7 @@ const handleSetRows = ({ setRowsState, }) => {
2525
2691
  setRowsState(normalizeRowInput(rowInput));
2526
2692
  };
2527
2693
  };
2528
- const handleUpsertRow = ({ getRowId, setRowsState, }) => {
2694
+ const handleUpsertRow = ({ getRowId, pageSize, setRowsState, }) => {
2529
2695
  return (rowInput) => {
2530
2696
  const rowsToUpsert = normalizeRowInput(rowInput);
2531
2697
  setRowsState((previousRows) => {
@@ -2539,19 +2705,17 @@ const handleUpsertRow = ({ getRowId, setRowsState, }) => {
2539
2705
  indexByRowId.set(rowId, index);
2540
2706
  }
2541
2707
  });
2708
+ const rowsToInsert = [];
2542
2709
  rowsToUpsert.forEach((row, index) => {
2543
2710
  const rowId = getResolvedRowId(row, index, undefined, getRowId);
2544
2711
  const existingIndex = rowId !== undefined ? indexByRowId.get(rowId) : undefined;
2545
2712
  if (existingIndex === undefined) {
2546
- if (rowId !== undefined) {
2547
- indexByRowId.set(rowId, nextRows.length);
2548
- }
2549
- nextRows.push(row);
2713
+ rowsToInsert.push(row);
2550
2714
  return;
2551
2715
  }
2552
2716
  nextRows[existingIndex] = row;
2553
2717
  });
2554
- return nextRows;
2718
+ return capRowsToPageSize([...rowsToInsert, ...nextRows], pageSize);
2555
2719
  });
2556
2720
  };
2557
2721
  };
@@ -2981,6 +3145,7 @@ const useMRT_TableInstance = (definedTableOptions) => {
2981
3145
  table.addRow = handleAddRow({
2982
3146
  setRowsState,
2983
3147
  getRowId: resolveRowId,
3148
+ pageSize: statefulTableOptions.state.pagination.pageSize,
2984
3149
  });
2985
3150
  table.updateRow = handleUpdateRow({
2986
3151
  setRowsState,
@@ -2993,6 +3158,7 @@ const useMRT_TableInstance = (definedTableOptions) => {
2993
3158
  table.upsertRow = handleUpsertRow({
2994
3159
  setRowsState,
2995
3160
  getRowId: resolveRowId,
3161
+ pageSize: statefulTableOptions.state.pagination.pageSize,
2996
3162
  });
2997
3163
  table.removeRow = handleRemoveRow({
2998
3164
  setRowsState,
@@ -7465,7 +7631,6 @@ const MRT_TableFooterCell = (_a) => {
7465
7631
  var { footer, staticColumnIndex, table } = _a, rest = __rest(_a, ["footer", "staticColumnIndex", "table"]);
7466
7632
  const theme = styles.useTheme();
7467
7633
  const { options: { enableColumnPinning, muiTableFooterCellProps, enableKeyboardShortcuts, }, } = table;
7468
- useMRT_SliceValue(table._uiStore, (s) => s.density);
7469
7634
  const { column } = footer;
7470
7635
  const { columnDef } = column;
7471
7636
  const { columnDefType } = columnDef;
@@ -7966,7 +8131,6 @@ const MRT_TableHeadCell = (_a) => {
7966
8131
  const { getState, options: { columnResizeDirection, columnResizeMode, enableKeyboardShortcuts, enableColumnActions, enableColumnDragging, enableColumnOrdering, enableColumnPinning, enableGrouping, enableMultiSort, layoutMode, mrtTheme: { draggingBorderColor }, muiTableHeadCellProps, }, refs: { isResizingRef, tableHeadCellRefs }, setHoveredColumn, } = table;
7967
8132
  const [isColumnCellHovered, setIsColumnCellHovered] = react.useState(false);
7968
8133
  const { grouping } = getState();
7969
- useMRT_SliceValue(table._uiStore, (s) => s.density);
7970
8134
  const showColumnFilters = useMRT_SliceValue(table._uiStore, (s) => s.showColumnFilters);
7971
8135
  const { column } = header;
7972
8136
  const { columnDef } = column;
@@ -8751,6 +8915,9 @@ exports.Memo_MRT_TableBodyRow = Memo_MRT_TableBodyRow;
8751
8915
  exports.RHF_FormProvider = RHF_FormProvider;
8752
8916
  exports.buildDefaultValues = buildDefaultValues;
8753
8917
  exports.cellKeyboardShortcuts = cellKeyboardShortcuts;
8918
+ exports.createDeleteAction = createDeleteAction;
8919
+ exports.createEditAction = createEditAction;
8920
+ exports.createExportAction = createExportAction;
8754
8921
  exports.createMRTColumnHelper = createMRTColumnHelper;
8755
8922
  exports.createRow = createRow;
8756
8923
  exports.defaultDisplayColumnProps = defaultDisplayColumnProps;