@dooherceg/material-react-table 3.2.4 → 3.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -453,6 +453,10 @@ interface MRT_Localization {
453
453
  exportPrintPdf: string;
454
454
  exportDownload: string;
455
455
  exportGrouped: string;
456
+ exportInProgress: string;
457
+ exportSuccess: string;
458
+ exportError: string;
459
+ exportNoExportsSelected: string;
456
460
  deleteConfirmationTitle: string;
457
461
  deleteConfirmationMessage: string;
458
462
  deleteConfirmYes: string;
package/dist/index.esm.js CHANGED
@@ -51,12 +51,19 @@ import SortIcon from '@mui/icons-material/Sort';
51
51
  import SyncAltIcon from '@mui/icons-material/SyncAlt';
52
52
  import ViewColumnIcon from '@mui/icons-material/ViewColumn';
53
53
  import VisibilityOffIcon from '@mui/icons-material/VisibilityOff';
54
+ import FileDownloadIcon from '@mui/icons-material/FileDownload';
55
+ import PrintIcon from '@mui/icons-material/Print';
56
+ import Divider from '@mui/material/Divider';
57
+ import FormControl from '@mui/material/FormControl';
58
+ import FormControlLabel from '@mui/material/FormControlLabel';
59
+ import RadioGroup from '@mui/material/RadioGroup';
60
+ import Typography from '@mui/material/Typography';
61
+ import printJS from 'print-js';
62
+ import { enqueueSnackbar, closeSnackbar, SnackbarProvider, useSnackbar } from 'notistack';
54
63
  import { defaultRangeExtractor, useVirtualizer } from '@tanstack/react-virtual';
55
64
  import Drawer from '@mui/material/Drawer';
56
- import Typography from '@mui/material/Typography';
57
65
  import TextField from '@mui/material/TextField';
58
66
  import { useFormContext, Controller, FormProvider, useForm } from 'react-hook-form';
59
- import FormControl from '@mui/material/FormControl';
60
67
  import FormHelperText from '@mui/material/FormHelperText';
61
68
  import InputLabel from '@mui/material/InputLabel';
62
69
  import Select from '@mui/material/Select';
@@ -93,14 +100,8 @@ import MenuList from '@mui/material/MenuList';
93
100
  import ListItemText from '@mui/material/ListItemText';
94
101
  import BookmarkIcon from '@mui/icons-material/Bookmark';
95
102
  import DeleteForeverIcon from '@mui/icons-material/DeleteForever';
96
- import Divider from '@mui/material/Divider';
97
- import FormControlLabel from '@mui/material/FormControlLabel';
98
103
  import Switch from '@mui/material/Switch';
99
104
  import Badge from '@mui/material/Badge';
100
- import FileDownloadIcon from '@mui/icons-material/FileDownload';
101
- import PrintIcon from '@mui/icons-material/Print';
102
- import RadioGroup from '@mui/material/RadioGroup';
103
- import printJS from 'print-js';
104
105
  import TableContainer from '@mui/material/TableContainer';
105
106
  import Dialog from '@mui/material/Dialog';
106
107
  import DialogActions from '@mui/material/DialogActions';
@@ -1915,6 +1916,10 @@ const MRT_Localization_EN = {
1915
1916
  exportPrintPdf: 'Print PDF',
1916
1917
  exportDownload: 'Download',
1917
1918
  exportGrouped: 'Group files',
1919
+ exportInProgress: 'Export in progress...',
1920
+ exportSuccess: 'Export completed successfully.',
1921
+ exportError: 'Export failed. Please try again.',
1922
+ exportNoExportsSelected: 'No export type selected. Please configure the export first.',
1918
1923
  deleteConfirmationTitle: 'Delete Row',
1919
1924
  deleteConfirmationMessage: 'Are you sure you want to delete the selected row(s)?',
1920
1925
  deleteConfirmYes: 'Delete',
@@ -1924,6 +1929,330 @@ const MRT_Localization_EN = {
1924
1929
  tableOptions: 'Options',
1925
1930
  };
1926
1931
 
1932
+ const downloadExportFiles = (files) => {
1933
+ files.forEach((file) => {
1934
+ const binaryString = atob(file.content);
1935
+ const len = binaryString.length;
1936
+ const bytes = new Uint8Array(len);
1937
+ for (let i = 0; i < len; i++) {
1938
+ bytes[i] = binaryString.charCodeAt(i);
1939
+ }
1940
+ const blob = new Blob([bytes], { type: 'application/octet-stream' });
1941
+ const element = document.createElement('a');
1942
+ element.href = URL.createObjectURL(blob);
1943
+ element.download = file.filename;
1944
+ document.body.appendChild(element);
1945
+ element.click();
1946
+ document.body.removeChild(element);
1947
+ URL.revokeObjectURL(element.href);
1948
+ });
1949
+ };
1950
+
1951
+ const printExportFiles = (files) => {
1952
+ files.forEach((file) => {
1953
+ const binaryString = atob(file.content);
1954
+ const len = binaryString.length;
1955
+ const bytes = new Uint8Array(len);
1956
+ for (let i = 0; i < len; i++) {
1957
+ bytes[i] = binaryString.charCodeAt(i);
1958
+ }
1959
+ const blob = new Blob([bytes], { type: 'application/pdf' });
1960
+ const url = URL.createObjectURL(blob);
1961
+ printJS({
1962
+ printable: url,
1963
+ type: 'pdf',
1964
+ onLoadingEnd: () => URL.revokeObjectURL(url),
1965
+ });
1966
+ });
1967
+ };
1968
+
1969
+ const MRT_ExportsToolbar = ({ table, availableExports, exportState, onExportStateChange, loadExport, }) => {
1970
+ const theme = useTheme();
1971
+ const { localization } = table.options;
1972
+ const { selectedExports, selectedFormat, grouped } = exportState;
1973
+ const [anchorEl, setAnchorEl] = useState(null);
1974
+ const [loadingExportType, setLoadingExportType] = useState(null);
1975
+ const { rowSelection } = table.getState();
1976
+ const selectedRowIds = Object.keys(rowSelection).filter((id) => rowSelection[id]);
1977
+ const isNoRowsSelected = selectedRowIds.length === 0;
1978
+ const availableFormats = useMemo(() => {
1979
+ const allFormats = Object.values(availableExports).flatMap((exp) => exp.formats);
1980
+ return Array.from(new Set(allFormats));
1981
+ }, [availableExports]);
1982
+ const hasPdfFormat = availableFormats.includes('pdf');
1983
+ const exportTypesForSelectedFormat = useMemo(() => {
1984
+ if (!selectedFormat)
1985
+ return [];
1986
+ return Object.values(availableExports).filter((exp) => exp.formats.includes(selectedFormat));
1987
+ }, [availableExports, selectedFormat]);
1988
+ const isPrintDisabled = selectedFormat !== 'pdf' ||
1989
+ !selectedFormat ||
1990
+ selectedExports.length < 1 ||
1991
+ (!grouped && selectedExports.length > 1);
1992
+ const isDownloadDisabled = !selectedFormat || selectedExports.length < 1;
1993
+ const handleOpenMenu = (event) => {
1994
+ setAnchorEl(event.currentTarget);
1995
+ };
1996
+ const handleCloseMenu = () => {
1997
+ setAnchorEl(null);
1998
+ };
1999
+ const handleSelectFormat = (format) => {
2000
+ const newFormat = selectedFormat === format ? null : format;
2001
+ onExportStateChange((prev) => (Object.assign(Object.assign({}, (prev !== null && prev !== void 0 ? prev : { grouped: false })), { selectedExports: [], selectedFormat: newFormat })));
2002
+ };
2003
+ const handleToggleExportType = (exportName) => {
2004
+ const isAlreadySelected = selectedExports.includes(exportName);
2005
+ const newSelectedExports = isAlreadySelected
2006
+ ? selectedExports.filter((name) => name !== exportName)
2007
+ : [...selectedExports, exportName];
2008
+ onExportStateChange((prev) => (Object.assign(Object.assign({}, (prev !== null && prev !== void 0 ? prev : { selectedFormat: null, grouped: false })), { selectedExports: newSelectedExports })));
2009
+ };
2010
+ const handleToggleGrouped = () => {
2011
+ onExportStateChange((prev) => (Object.assign(Object.assign({}, (prev !== null && prev !== void 0 ? prev : { selectedFormat: null, selectedExports: [] })), { grouped: !grouped })));
2012
+ };
2013
+ const handleExportAction = (type) => __awaiter(void 0, void 0, void 0, function* () {
2014
+ setLoadingExportType(type);
2015
+ try {
2016
+ const response = yield loadExport({
2017
+ format: selectedFormat,
2018
+ exports: selectedExports,
2019
+ separated_files: !grouped,
2020
+ download: false,
2021
+ ids: JSON.stringify(selectedRowIds),
2022
+ type,
2023
+ });
2024
+ handleCloseMenu();
2025
+ if (type === 'download') {
2026
+ downloadExportFiles(response);
2027
+ }
2028
+ else {
2029
+ printExportFiles(response);
2030
+ }
2031
+ }
2032
+ finally {
2033
+ setLoadingExportType(null);
2034
+ }
2035
+ });
2036
+ const renderFormatSelector = () => (jsx(Stack, { justifyContent: "flex-start", minWidth: "200px", sx: {
2037
+ borderRight: selectedFormat
2038
+ ? `1px dashed ${theme.palette.divider}`
2039
+ : 'none',
2040
+ }, children: jsx(FormControl, { children: jsx(RadioGroup, { value: selectedFormat !== null && selectedFormat !== void 0 ? selectedFormat : '', children: availableFormats.map((format) => (jsx(FormControlLabel, { sx: { m: 0 }, value: format, control: jsx(Radio, { size: "small", onClick: () => handleSelectFormat(format) }), label: jsx(Typography, { variant: "subtitle2", sx: { fontWeight: 800 }, children: format }) }, format))) }) }) }));
2041
+ const renderExportTypeSelector = () => {
2042
+ if (!selectedFormat || exportTypesForSelectedFormat.length === 0)
2043
+ return null;
2044
+ return (jsx(Stack, { minWidth: "250px", maxHeight: "500px", sx: { overflowY: 'auto' }, children: exportTypesForSelectedFormat.map((exportType) => (jsxs(MenuItem, { onClick: () => handleToggleExportType(exportType.name), value: exportType.name, children: [jsx(Checkbox, { checked: selectedExports.includes(exportType.name), size: "small" }), jsx(Typography, { variant: "body2", children: exportType.label })] }, exportType.name))) }));
2045
+ };
2046
+ const renderActionButtons = () => {
2047
+ const isAnyLoading = loadingExportType !== null;
2048
+ return (jsxs(Stack, { direction: "row", gap: 0.5, mt: 1, mr: 2, children: [hasPdfFormat && (jsx(Button, { sx: { display: 'flex', gap: 0.5 }, disabled: isPrintDisabled || isAnyLoading, onClick: () => handleExportAction('print'), startIcon: loadingExportType === 'print' ? (jsx(CircularProgress, { size: 16, color: "inherit" })) : (jsx(PrintIcon, { fontSize: "small" })), children: localization.exportPrintPdf })), jsx(Button, { sx: { display: 'flex', gap: 0.5 }, disabled: isDownloadDisabled || isAnyLoading, onClick: () => handleExportAction('download'), startIcon: loadingExportType === 'download' ? (jsx(CircularProgress, { size: 16, color: "inherit" })) : (jsx(FileDownloadIcon, { fontSize: "small" })), children: localization.exportDownload })] }));
2049
+ };
2050
+ const renderGroupedCheckbox = () => (jsx(Stack, { mt: "auto", children: jsx(FormControlLabel, { onChange: handleToggleGrouped, sx: { m: 0 }, control: jsx(Checkbox, { checked: grouped, size: "small" }), label: jsx(Typography, { variant: "body2", children: localization.exportGrouped }) }) }));
2051
+ return (jsxs(Stack, { direction: "row", gap: 0.5, alignItems: "center", children: [jsx(Tooltip, { title: isNoRowsSelected
2052
+ ? localization.exportSelectRowsTooltip
2053
+ : localization.exportButton, children: jsx("span", { children: jsx(Button, { "aria-label": localization.exportButton, disabled: isNoRowsSelected, onClick: handleOpenMenu, size: "small", startIcon: jsx(FileDownloadIcon, { fontSize: "small" }), variant: "text", children: localization.exportButton }) }) }), jsxs(Menu, { anchorEl: anchorEl, open: Boolean(anchorEl), onClose: handleCloseMenu, anchorOrigin: { vertical: 'bottom', horizontal: 'left' }, transformOrigin: { vertical: 'top', horizontal: 'left' }, children: [jsxs(Stack, { direction: "row", sx: { px: 1, pt: 1, maxHeight: '320px', overflow: 'auto' }, children: [renderFormatSelector(), selectedFormat &&
2054
+ exportTypesForSelectedFormat.length > 0 &&
2055
+ renderExportTypeSelector()] }), jsx(Divider, { sx: { mt: 1 } }), jsxs(Stack, { direction: "row", alignItems: "center", sx: { px: 1, pb: 1 }, children: [renderActionButtons(), renderGroupedCheckbox()] })] })] }));
2056
+ };
2057
+
2058
+ const MRT_ExportRowButton = ({ onClick }) => {
2059
+ return (jsx(IconButton, { sx: { p: 0 }, disableRipple: true, onClick: onClick, children: jsx(FileDownloadIcon, { fontSize: "small" }) }));
2060
+ };
2061
+
2062
+ const MRT_PrintRowButton = ({ onClick }) => {
2063
+ return (jsx(IconButton, { sx: { p: 0 }, disableRipple: true, onClick: onClick, children: jsx(PrintIcon, { fontSize: "small" }) }));
2064
+ };
2065
+
2066
+ const ExportRowAction = ({ onExport, onPrint }) => {
2067
+ return (jsxs(Fragment, { children: [jsx(MRT_ExportRowButton, { onClick: onExport }), onPrint && jsx(MRT_PrintRowButton, { onClick: onPrint })] }));
2068
+ };
2069
+
2070
+ const hasActiveExports = (table) => {
2071
+ const { activeExports } = table.getState();
2072
+ return !!((activeExports === null || activeExports === void 0 ? void 0 : activeExports.selectedFormat) && activeExports.selectedExports.length > 0);
2073
+ };
2074
+ // Same conditions as MRT_ExportsToolbar: pdf format selected, at least one export type,
2075
+ // and either grouped or exactly one export type selected.
2076
+ const isPrintAvailable = (table) => {
2077
+ var _a;
2078
+ const allFormats = Object.values((_a = table.options.availableExports) !== null && _a !== void 0 ? _a : {}).flatMap((e) => e.formats);
2079
+ if (!allFormats.includes('pdf'))
2080
+ return false;
2081
+ const { activeExports } = table.getState();
2082
+ if (!activeExports)
2083
+ return false;
2084
+ const { selectedFormat, selectedExports, grouped } = activeExports;
2085
+ return (selectedFormat === 'pdf' &&
2086
+ selectedExports.length >= 1 &&
2087
+ (grouped || selectedExports.length === 1));
2088
+ };
2089
+ const createExportAction = (_a = {}) => {
2090
+ var { onExport, renderRow: customRenderRow, renderToolbar: customRenderToolbar } = _a, rest = __rest(_a, ["onExport", "renderRow", "renderToolbar"]);
2091
+ // Pure download logic — no notifications. Throws on failure so callers can handle it.
2092
+ const defaultOnExport = (_a) => __awaiter(void 0, [_a], void 0, function* ({ rowsToExport, table, }) {
2093
+ if (!rowsToExport.length)
2094
+ return;
2095
+ const { loadExport } = table.options;
2096
+ const { activeExports } = table.getState();
2097
+ if (!loadExport || !activeExports)
2098
+ return;
2099
+ const response = yield loadExport({
2100
+ format: activeExports.selectedFormat,
2101
+ exports: activeExports.selectedExports,
2102
+ separated_files: !activeExports.grouped,
2103
+ download: false,
2104
+ ids: JSON.stringify(rowsToExport.map((r) => r.id)),
2105
+ type: 'download',
2106
+ });
2107
+ downloadExportFiles(response);
2108
+ });
2109
+ // Pure print logic — no notifications. Throws on failure so callers can handle it.
2110
+ const defaultOnPrint = (_a) => __awaiter(void 0, [_a], void 0, function* ({ rowsToExport, table, }) {
2111
+ if (!rowsToExport.length)
2112
+ return;
2113
+ const { loadExport } = table.options;
2114
+ const { activeExports } = table.getState();
2115
+ if (!loadExport || !activeExports)
2116
+ return;
2117
+ const response = yield loadExport({
2118
+ format: activeExports.selectedFormat,
2119
+ exports: activeExports.selectedExports,
2120
+ separated_files: !activeExports.grouped,
2121
+ download: false,
2122
+ ids: JSON.stringify(rowsToExport.map((r) => r.id)),
2123
+ type: 'print',
2124
+ });
2125
+ printExportFiles(response);
2126
+ });
2127
+ // Single execution pipeline for every export flow (row or toolbar).
2128
+ // If a custom handler exists, it receives defaultOnExport and decides when to call it.
2129
+ const executeExport = (context) => {
2130
+ const executeDefaultExport = () => defaultOnExport(context);
2131
+ if (onExport) {
2132
+ return onExport(Object.assign(Object.assign({}, context), { defaultOnExport: executeDefaultExport }));
2133
+ }
2134
+ return executeDefaultExport();
2135
+ };
2136
+ // Row download: checks for active exports, then wraps with loading/success/error notifications.
2137
+ const handleSingleRowExport = (_a) => __awaiter(void 0, [_a], void 0, function* ({ table, row, }) {
2138
+ const { localization } = table.options;
2139
+ if (!hasActiveExports(table)) {
2140
+ enqueueSnackbar(localization.exportNoExportsSelected, {
2141
+ variant: 'warning',
2142
+ });
2143
+ return;
2144
+ }
2145
+ const loadingKey = enqueueSnackbar(localization.exportInProgress, {
2146
+ variant: 'info',
2147
+ persist: true,
2148
+ });
2149
+ try {
2150
+ yield executeExport({ table, rowsToExport: [row] });
2151
+ closeSnackbar(loadingKey);
2152
+ enqueueSnackbar(localization.exportSuccess, { variant: 'success' });
2153
+ }
2154
+ catch (_b) {
2155
+ closeSnackbar(loadingKey);
2156
+ enqueueSnackbar(localization.exportError, { variant: 'error' });
2157
+ }
2158
+ });
2159
+ // Row print: same guard + notification pattern as download, but calls defaultOnPrint.
2160
+ const handleSingleRowPrint = (_a) => __awaiter(void 0, [_a], void 0, function* ({ table, row, }) {
2161
+ const { localization } = table.options;
2162
+ if (!hasActiveExports(table)) {
2163
+ enqueueSnackbar(localization.exportNoExportsSelected, {
2164
+ variant: 'warning',
2165
+ });
2166
+ return;
2167
+ }
2168
+ const loadingKey = enqueueSnackbar(localization.exportInProgress, {
2169
+ variant: 'info',
2170
+ persist: true,
2171
+ });
2172
+ try {
2173
+ yield defaultOnPrint({ table, rowsToExport: [row] });
2174
+ closeSnackbar(loadingKey);
2175
+ enqueueSnackbar(localization.exportSuccess, { variant: 'success' });
2176
+ }
2177
+ catch (_b) {
2178
+ closeSnackbar(loadingKey);
2179
+ enqueueSnackbar(localization.exportError, { variant: 'error' });
2180
+ }
2181
+ });
2182
+ // Resolves selected rows from table state for toolbar-triggered export (custom renderToolbar only).
2183
+ const handleMultipleRowExport = ({ table, }) => {
2184
+ const rowsToExport = table.getSelectedRowModel().rows;
2185
+ return executeExport({ table, rowsToExport });
2186
+ };
2187
+ const createRowExportExecutor = (context) => () => {
2188
+ void handleSingleRowExport(context);
2189
+ };
2190
+ const createRowPrintExecutor = (context) => () => {
2191
+ void handleSingleRowPrint(context);
2192
+ };
2193
+ const createToolbarExportExecutor = (context) => () => {
2194
+ void handleMultipleRowExport(context);
2195
+ };
2196
+ // Renders download + optional print button. Print is shown under the same conditions
2197
+ // as in MRT_ExportsToolbar: pdf format selected, active exports, grouped or single type.
2198
+ const renderRowAction = (context) => {
2199
+ const onRowExport = createRowExportExecutor(context);
2200
+ const onRowPrint = isPrintAvailable(context.table)
2201
+ ? createRowPrintExecutor(context)
2202
+ : undefined;
2203
+ if (customRenderRow) {
2204
+ return customRenderRow(Object.assign(Object.assign({}, context), { onExport: onRowExport }));
2205
+ }
2206
+ return jsx(ExportRowAction, { onExport: onRowExport, onPrint: onRowPrint });
2207
+ };
2208
+ // Uses custom toolbar renderer when provided; otherwise renders MRT_ExportsToolbar.
2209
+ // loadExport is always wrapped with notifications so that loading/success/error are shown
2210
+ // regardless of whether a custom onExport handler was provided.
2211
+ // When onExport is provided, it intercepts the call and returns [] so MRT_ExportsToolbar
2212
+ // does not attempt a second download from an empty response.
2213
+ const renderToolbarAction = (context) => {
2214
+ const { table } = context;
2215
+ const { availableExports, loadExport, onActiveExportsChange, localization, } = table.options;
2216
+ const { activeExports } = table.getState();
2217
+ if (customRenderToolbar) {
2218
+ return customRenderToolbar(Object.assign(Object.assign({}, context), { onExport: createToolbarExportExecutor(context) }));
2219
+ }
2220
+ if (!availableExports ||
2221
+ !loadExport ||
2222
+ !onActiveExportsChange ||
2223
+ !activeExports) {
2224
+ return null;
2225
+ }
2226
+ const notifiedLoadExport = (params) => __awaiter(void 0, void 0, void 0, function* () {
2227
+ const loadingKey = enqueueSnackbar(localization.exportInProgress, {
2228
+ variant: 'info',
2229
+ persist: true,
2230
+ });
2231
+ try {
2232
+ let response;
2233
+ if (onExport) {
2234
+ const rowsToExport = table.getSelectedRowModel().rows;
2235
+ yield executeExport({ table, rowsToExport });
2236
+ response = [];
2237
+ }
2238
+ else {
2239
+ response = yield loadExport(params);
2240
+ }
2241
+ closeSnackbar(loadingKey);
2242
+ enqueueSnackbar(localization.exportSuccess, { variant: 'success' });
2243
+ return response;
2244
+ }
2245
+ catch (_a) {
2246
+ closeSnackbar(loadingKey);
2247
+ enqueueSnackbar(localization.exportError, { variant: 'error' });
2248
+ return [];
2249
+ }
2250
+ });
2251
+ return (jsx(MRT_ExportsToolbar, { table: table, availableExports: availableExports, exportState: activeExports, onExportStateChange: onActiveExportsChange, loadExport: notifiedLoadExport }));
2252
+ };
2253
+ return Object.assign({ name: 'export', renderRow: renderRowAction, renderToolbar: renderToolbarAction }, rest);
2254
+ };
2255
+
1927
2256
  const MRT_DefaultColumn = {
1928
2257
  filterVariant: 'text',
1929
2258
  maxSize: 1000,
@@ -1946,8 +2275,18 @@ const MRT_DefaultDisplayColumn = {
1946
2275
  };
1947
2276
  const useMRT_TableOptions = (_a) => {
1948
2277
  var _b;
1949
- var { aggregationFns, autoResetExpanded = false, columnFilterDisplayMode = 'subheader', columnResizeDirection, columnResizeMode = 'onChange', createDisplayMode = 'modal', defaultColumn, defaultDisplayColumn, editDisplayMode = 'modal', enableBatchRowSelection = true, enableBottomToolbar = true, enableColumnActions = true, enableColumnFilters = true, enableColumnOrdering = true, enableColumnPinning = true, enableColumnResizing = true, enableColumnVirtualization, enableDensityToggle = true, enableExpandAll = true, maxDepth, enableExpanding, enableRowReordering, enableFacetedValues = false, enableFilterMatchHighlighting = true, enableFilters = false, enableAdvancedFilters = true, enableGlobalFilter = false, enableGlobalFilterRankedResults = true, enableGrouping = true, enableHiding = true, enableKeyboardShortcuts = true, enableMultiRowSelection = true, enableMultiSort = true, enablePagination = true, enableRowPinning = true, enableRowSelection = true, enableRowVirtualization = false, enableSelectAll = true, enableSorting = true, enableStickyHeader = true, enableTableFooter = true, enableTableHead = true, enableToolbarInternalActions = true, enableTopToolbar = true, filterFns, icons, id = useId(), layoutMode, localization, manualFiltering, manualGrouping, manualPagination, manualSorting, mrtTheme, paginationDisplayMode = 'default', positionActionsColumn = 'first', positionCreatingRow = 'top', positionExpandColumn = 'first', positionGlobalFilter = 'right', positionPagination = 'bottom', positionToolbarAlertBanner = 'top', positionToolbarDropZone = 'top', rowNumberDisplayMode = 'static', rowPinningDisplayMode = 'sticky', selectAllMode = 'page', sortingFns } = _a, rest = __rest(_a, ["aggregationFns", "autoResetExpanded", "columnFilterDisplayMode", "columnResizeDirection", "columnResizeMode", "createDisplayMode", "defaultColumn", "defaultDisplayColumn", "editDisplayMode", "enableBatchRowSelection", "enableBottomToolbar", "enableColumnActions", "enableColumnFilters", "enableColumnOrdering", "enableColumnPinning", "enableColumnResizing", "enableColumnVirtualization", "enableDensityToggle", "enableExpandAll", "maxDepth", "enableExpanding", "enableRowReordering", "enableFacetedValues", "enableFilterMatchHighlighting", "enableFilters", "enableAdvancedFilters", "enableGlobalFilter", "enableGlobalFilterRankedResults", "enableGrouping", "enableHiding", "enableKeyboardShortcuts", "enableMultiRowSelection", "enableMultiSort", "enablePagination", "enableRowPinning", "enableRowSelection", "enableRowVirtualization", "enableSelectAll", "enableSorting", "enableStickyHeader", "enableTableFooter", "enableTableHead", "enableToolbarInternalActions", "enableTopToolbar", "filterFns", "icons", "id", "layoutMode", "localization", "manualFiltering", "manualGrouping", "manualPagination", "manualSorting", "mrtTheme", "paginationDisplayMode", "positionActionsColumn", "positionCreatingRow", "positionExpandColumn", "positionGlobalFilter", "positionPagination", "positionToolbarAlertBanner", "positionToolbarDropZone", "rowNumberDisplayMode", "rowPinningDisplayMode", "selectAllMode", "sortingFns"]);
2278
+ var { aggregationFns, autoResetExpanded = false, columnFilterDisplayMode = 'subheader', columnResizeDirection, columnResizeMode = 'onChange', createDisplayMode = 'modal', defaultColumn, defaultDisplayColumn, editDisplayMode = 'modal', enableBatchRowSelection = true, enableBottomToolbar = true, enableColumnActions = true, enableColumnFilters = true, enableColumnOrdering = true, enableColumnPinning = true, enableColumnResizing = true, enableColumnVirtualization, enableDensityToggle = true, enableExpandAll = true, maxDepth, enableExpanding, enableRowReordering, enableFacetedValues = false, enableFilterMatchHighlighting = true, enableFilters = false, enableAdvancedFilters = true, enableGlobalFilter = false, enableGlobalFilterRankedResults = true, enableGrouping = true, enableHiding = true, enableKeyboardShortcuts = true, enableMultiRowSelection = true, enableMultiSort = true, enablePagination = true, enableRowPinning = true, enableRowSelection = true, enableRowVirtualization = false, enableSelectAll = true, enableSorting = true, enableStickyHeader = true, enableTableFooter = true, enableTableHead = true, enableToolbarInternalActions = true, enableTopToolbar = true, filterFns, icons, id = useId(), layoutMode, localization, manualFiltering, manualGrouping, manualPagination, manualSorting, mrtTheme, paginationDisplayMode = 'default', positionActionsColumn = 'first', positionCreatingRow = 'top', positionExpandColumn = 'first', positionGlobalFilter = 'right', positionPagination = 'bottom', positionToolbarAlertBanner = 'top', positionToolbarDropZone = 'top', rowNumberDisplayMode = 'static', rowPinningDisplayMode = 'sticky', selectAllMode = 'page', sortingFns, actions, availableExports } = _a, rest = __rest(_a, ["aggregationFns", "autoResetExpanded", "columnFilterDisplayMode", "columnResizeDirection", "columnResizeMode", "createDisplayMode", "defaultColumn", "defaultDisplayColumn", "editDisplayMode", "enableBatchRowSelection", "enableBottomToolbar", "enableColumnActions", "enableColumnFilters", "enableColumnOrdering", "enableColumnPinning", "enableColumnResizing", "enableColumnVirtualization", "enableDensityToggle", "enableExpandAll", "maxDepth", "enableExpanding", "enableRowReordering", "enableFacetedValues", "enableFilterMatchHighlighting", "enableFilters", "enableAdvancedFilters", "enableGlobalFilter", "enableGlobalFilterRankedResults", "enableGrouping", "enableHiding", "enableKeyboardShortcuts", "enableMultiRowSelection", "enableMultiSort", "enablePagination", "enableRowPinning", "enableRowSelection", "enableRowVirtualization", "enableSelectAll", "enableSorting", "enableStickyHeader", "enableTableFooter", "enableTableHead", "enableToolbarInternalActions", "enableTopToolbar", "filterFns", "icons", "id", "layoutMode", "localization", "manualFiltering", "manualGrouping", "manualPagination", "manualSorting", "mrtTheme", "paginationDisplayMode", "positionActionsColumn", "positionCreatingRow", "positionExpandColumn", "positionGlobalFilter", "positionPagination", "positionToolbarAlertBanner", "positionToolbarDropZone", "rowNumberDisplayMode", "rowPinningDisplayMode", "selectAllMode", "sortingFns", "actions", "availableExports"]);
1950
2279
  const theme = useTheme();
2280
+ // When availableExports is configured and the user has not supplied their own
2281
+ // 'export' action, inject the default export action automatically.
2282
+ const effectiveActions = useMemo(() => {
2283
+ if (!availableExports)
2284
+ return actions;
2285
+ const hasUserExportAction = actions === null || actions === void 0 ? void 0 : actions.some((a) => a.name === 'export');
2286
+ if (hasUserExportAction)
2287
+ return actions;
2288
+ return [createExportAction(), ...(actions !== null && actions !== void 0 ? actions : [])];
2289
+ }, [actions, availableExports]);
1951
2290
  icons = useMemo(() => (Object.assign(Object.assign({}, MRT_Default_Icons), icons)), [icons]);
1952
2291
  localization = useMemo(() => (Object.assign(Object.assign({}, MRT_Localization_EN), localization)), [localization]);
1953
2292
  mrtTheme = useMemo(() => getMRTTheme(mrtTheme, theme), [mrtTheme, theme]);
@@ -2051,7 +2390,7 @@ const useMRT_TableOptions = (_a) => {
2051
2390
  rowPinningDisplayMode,
2052
2391
  selectAllMode,
2053
2392
  sortingFns,
2054
- enableAdvancedFilters }, rest);
2393
+ enableAdvancedFilters, actions: effectiveActions, availableExports }, rest);
2055
2394
  };
2056
2395
 
2057
2396
  const blankColProps = {
@@ -4712,6 +5051,24 @@ function RowActionsCell({ row, table, }) {
4712
5051
  }) }));
4713
5052
  }
4714
5053
 
5054
+ // Detects whether a real SnackbarProvider exists in the tree.
5055
+ // In notistack's default context both enqueueSnackbar and closeSnackbar point to
5056
+ // the same no-op reference. A real provider binds them to different functions.
5057
+ const useHasSnackbarProvider = () => {
5058
+ const { enqueueSnackbar, closeSnackbar } = useSnackbar();
5059
+ return enqueueSnackbar !== closeSnackbar;
5060
+ };
5061
+ const Inner = ({ children }) => {
5062
+ const hasProvider = useHasSnackbarProvider();
5063
+ if (hasProvider)
5064
+ return jsx(Fragment, { children: children });
5065
+ return (jsx(SnackbarProvider, { maxSnack: 5, anchorOrigin: { vertical: 'bottom', horizontal: 'right' }, children: children }));
5066
+ };
5067
+ // Wraps children with SnackbarProvider only when no provider exists in the tree.
5068
+ // When the user's app already has a SnackbarProvider, notifications from MRT
5069
+ // will appear there — inheriting its position and styling.
5070
+ const MaybeSnackbarProvider = ({ children, }) => jsx(Inner, { children: children });
5071
+
4715
5072
  const MRT_ActiveFilterItem = ({ table, rule, }) => {
4716
5073
  var _a;
4717
5074
  const column = getFilterColumn(table, rule.columnId);
@@ -5642,147 +5999,17 @@ const MRT_ToggleGlobalFilterButton = (_a) => {
5642
5999
  return (jsx(Tooltip, { title: (_b = rest === null || rest === void 0 ? void 0 : rest.title) !== null && _b !== void 0 ? _b : localization.showHideSearch, children: jsx("span", { children: jsx(IconButton, Object.assign({ "aria-label": (_c = rest === null || rest === void 0 ? void 0 : rest.title) !== null && _c !== void 0 ? _c : localization.showHideSearch, disabled: !!globalFilter && showGlobalFilter, onClick: handleToggleSearch }, rest, { title: undefined, children: showGlobalFilter ? jsx(SearchOffIcon, {}) : jsx(SearchIcon, {}) })) }) }));
5643
6000
  };
5644
6001
 
5645
- const downloadExportFiles = (files) => {
5646
- files.forEach((file) => {
5647
- const binaryString = atob(file.content);
5648
- const len = binaryString.length;
5649
- const bytes = new Uint8Array(len);
5650
- for (let i = 0; i < len; i++) {
5651
- bytes[i] = binaryString.charCodeAt(i);
5652
- }
5653
- const blob = new Blob([bytes], { type: 'application/octet-stream' });
5654
- const element = document.createElement('a');
5655
- element.href = URL.createObjectURL(blob);
5656
- element.download = file.filename;
5657
- document.body.appendChild(element);
5658
- element.click();
5659
- document.body.removeChild(element);
5660
- URL.revokeObjectURL(element.href);
5661
- });
5662
- };
5663
-
5664
- const printExportFiles = (files) => {
5665
- files.forEach((file) => {
5666
- const binaryString = atob(file.content);
5667
- const len = binaryString.length;
5668
- const bytes = new Uint8Array(len);
5669
- for (let i = 0; i < len; i++) {
5670
- bytes[i] = binaryString.charCodeAt(i);
5671
- }
5672
- const blob = new Blob([bytes], { type: 'application/pdf' });
5673
- const url = URL.createObjectURL(blob);
5674
- printJS({
5675
- printable: url,
5676
- type: 'pdf',
5677
- onLoadingEnd: () => URL.revokeObjectURL(url),
5678
- });
5679
- });
5680
- };
5681
-
5682
- const MRT_ExportsToolbar = ({ table, availableExports, exportState, onExportStateChange, loadExport, }) => {
5683
- const theme = useTheme();
5684
- const { localization } = table.options;
5685
- const { selectedExports, selectedFormat, grouped } = exportState;
5686
- const [anchorEl, setAnchorEl] = useState(null);
5687
- const [loadingExportType, setLoadingExportType] = useState(null);
5688
- const { rowSelection } = table.getState();
5689
- const selectedRowIds = Object.keys(rowSelection).filter((id) => rowSelection[id]);
5690
- const isNoRowsSelected = selectedRowIds.length === 0;
5691
- const availableFormats = useMemo(() => {
5692
- const allFormats = Object.values(availableExports).flatMap((exp) => exp.formats);
5693
- return Array.from(new Set(allFormats));
5694
- }, [availableExports]);
5695
- const hasPdfFormat = availableFormats.includes('pdf');
5696
- const exportTypesForSelectedFormat = useMemo(() => {
5697
- if (!selectedFormat)
5698
- return [];
5699
- return Object.values(availableExports).filter((exp) => exp.formats.includes(selectedFormat));
5700
- }, [availableExports, selectedFormat]);
5701
- const isPrintDisabled = selectedFormat !== 'pdf' ||
5702
- !selectedFormat ||
5703
- selectedExports.length < 1 ||
5704
- (!grouped && selectedExports.length > 1);
5705
- const isDownloadDisabled = !selectedFormat || selectedExports.length < 1;
5706
- const handleOpenMenu = (event) => {
5707
- setAnchorEl(event.currentTarget);
5708
- };
5709
- const handleCloseMenu = () => {
5710
- setAnchorEl(null);
5711
- };
5712
- const handleSelectFormat = (format) => {
5713
- const newFormat = selectedFormat === format ? null : format;
5714
- onExportStateChange((prev) => (Object.assign(Object.assign({}, (prev !== null && prev !== void 0 ? prev : { grouped: false })), { selectedExports: [], selectedFormat: newFormat })));
5715
- };
5716
- const handleToggleExportType = (exportName) => {
5717
- const isAlreadySelected = selectedExports.includes(exportName);
5718
- const newSelectedExports = isAlreadySelected
5719
- ? selectedExports.filter((name) => name !== exportName)
5720
- : [...selectedExports, exportName];
5721
- onExportStateChange((prev) => (Object.assign(Object.assign({}, (prev !== null && prev !== void 0 ? prev : { selectedFormat: null, grouped: false })), { selectedExports: newSelectedExports })));
5722
- };
5723
- const handleToggleGrouped = () => {
5724
- onExportStateChange((prev) => (Object.assign(Object.assign({}, (prev !== null && prev !== void 0 ? prev : { selectedFormat: null, selectedExports: [] })), { grouped: !grouped })));
5725
- };
5726
- const handleExportAction = (type) => __awaiter(void 0, void 0, void 0, function* () {
5727
- setLoadingExportType(type);
5728
- try {
5729
- const response = yield loadExport({
5730
- format: selectedFormat,
5731
- exports: selectedExports,
5732
- separated_files: !grouped,
5733
- download: false,
5734
- ids: JSON.stringify(selectedRowIds),
5735
- type,
5736
- });
5737
- handleCloseMenu();
5738
- if (type === 'download') {
5739
- downloadExportFiles(response);
5740
- }
5741
- else {
5742
- printExportFiles(response);
5743
- }
5744
- }
5745
- finally {
5746
- setLoadingExportType(null);
5747
- }
5748
- });
5749
- const renderFormatSelector = () => (jsx(Stack, { justifyContent: "flex-start", minWidth: "200px", sx: {
5750
- borderRight: selectedFormat
5751
- ? `1px dashed ${theme.palette.divider}`
5752
- : 'none',
5753
- }, children: jsx(FormControl, { children: jsx(RadioGroup, { value: selectedFormat !== null && selectedFormat !== void 0 ? selectedFormat : '', children: availableFormats.map((format) => (jsx(FormControlLabel, { sx: { m: 0 }, value: format, control: jsx(Radio, { size: "small", onClick: () => handleSelectFormat(format) }), label: jsx(Typography, { variant: "subtitle2", sx: { fontWeight: 800 }, children: format }) }, format))) }) }) }));
5754
- const renderExportTypeSelector = () => {
5755
- if (!selectedFormat || exportTypesForSelectedFormat.length === 0)
5756
- return null;
5757
- return (jsx(Stack, { minWidth: "250px", maxHeight: "500px", sx: { overflowY: 'auto' }, children: exportTypesForSelectedFormat.map((exportType) => (jsxs(MenuItem, { onClick: () => handleToggleExportType(exportType.name), value: exportType.name, children: [jsx(Checkbox, { checked: selectedExports.includes(exportType.name), size: "small" }), jsx(Typography, { variant: "body2", children: exportType.label })] }, exportType.name))) }));
5758
- };
5759
- const renderActionButtons = () => {
5760
- const isAnyLoading = loadingExportType !== null;
5761
- return (jsxs(Stack, { direction: "row", gap: 0.5, mt: 1, mr: 2, children: [hasPdfFormat && (jsx(Button, { sx: { display: 'flex', gap: 0.5 }, disabled: isPrintDisabled || isAnyLoading, onClick: () => handleExportAction('print'), startIcon: loadingExportType === 'print' ? (jsx(CircularProgress, { size: 16, color: "inherit" })) : (jsx(PrintIcon, { fontSize: "small" })), children: localization.exportPrintPdf })), jsx(Button, { sx: { display: 'flex', gap: 0.5 }, disabled: isDownloadDisabled || isAnyLoading, onClick: () => handleExportAction('download'), startIcon: loadingExportType === 'download' ? (jsx(CircularProgress, { size: 16, color: "inherit" })) : (jsx(FileDownloadIcon, { fontSize: "small" })), children: localization.exportDownload })] }));
5762
- };
5763
- const renderGroupedCheckbox = () => (jsx(Stack, { mt: "auto", children: jsx(FormControlLabel, { onChange: handleToggleGrouped, sx: { m: 0 }, control: jsx(Checkbox, { checked: grouped, size: "small" }), label: jsx(Typography, { variant: "body2", children: localization.exportGrouped }) }) }));
5764
- return (jsxs(Stack, { direction: "row", gap: 0.5, alignItems: "center", children: [jsx(Tooltip, { title: isNoRowsSelected
5765
- ? localization.exportSelectRowsTooltip
5766
- : localization.exportButton, children: jsx("span", { children: jsx(Button, { "aria-label": localization.exportButton, disabled: isNoRowsSelected, onClick: handleOpenMenu, size: "small", startIcon: jsx(FileDownloadIcon, { fontSize: "small" }), variant: "text", children: localization.exportButton }) }) }), jsxs(Menu, { anchorEl: anchorEl, open: Boolean(anchorEl), onClose: handleCloseMenu, anchorOrigin: { vertical: 'bottom', horizontal: 'left' }, transformOrigin: { vertical: 'top', horizontal: 'left' }, children: [jsxs(Stack, { direction: "row", sx: { px: 1, pt: 1, maxHeight: '320px', overflow: 'auto' }, children: [renderFormatSelector(), selectedFormat &&
5767
- exportTypesForSelectedFormat.length > 0 &&
5768
- renderExportTypeSelector()] }), jsx(Divider, { sx: { mt: 1 } }), jsxs(Stack, { direction: "row", alignItems: "center", sx: { px: 1, pb: 1 }, children: [renderActionButtons(), renderGroupedCheckbox()] })] })] }));
5769
- };
5770
-
5771
6002
  const MRT_ToolbarInternalButtons = (_a) => {
5772
6003
  var _b;
5773
6004
  var { table } = _a, rest = __rest(_a, ["table"]);
5774
- const { options: { availableExports, columnFilterDisplayMode, enableColumnFilters, enableColumnOrdering, enableColumnPinning, enableDensityToggle, enableFilters, enableGlobalFilter, enableHiding, initialState, enableAdvancedFilters, loadExport, onActiveExportsChange, renderToolbarInternalActions, enableNewEntryButton, }, } = table;
5775
- const { activeExports } = table.getState();
6005
+ const { options: { columnFilterDisplayMode, enableColumnFilters, enableColumnOrdering, enableColumnPinning, enableDensityToggle, enableFilters, enableGlobalFilter, enableHiding, initialState, enableAdvancedFilters, renderToolbarInternalActions, enableNewEntryButton, }, } = table;
5776
6006
  return (jsx(Box, Object.assign({}, rest, { sx: (theme) => (Object.assign({ alignItems: 'center', display: 'flex', zIndex: 3, gap: 1 }, parseFromValuesOrFunc(rest === null || rest === void 0 ? void 0 : rest.sx, theme))), children: (_b = renderToolbarInternalActions === null || renderToolbarInternalActions === void 0 ? void 0 : renderToolbarInternalActions({
5777
6007
  table,
5778
6008
  })) !== null && _b !== void 0 ? _b : (jsxs(Fragment, { children: [enableFilters &&
5779
6009
  enableGlobalFilter &&
5780
6010
  !(initialState === null || initialState === void 0 ? void 0 : initialState.showGlobalFilter) && (jsx(MRT_ToggleGlobalFilterButton, { table: table })), enableFilters &&
5781
6011
  enableColumnFilters &&
5782
- columnFilterDisplayMode !== 'popover' && (jsx(MRT_ToggleFiltersButton, { table: table })), (enableHiding || enableColumnOrdering || enableColumnPinning) && (jsx(MRT_ShowHideColumnsButton, { table: table })), enableDensityToggle && (jsx(MRT_ToggleDensePaddingButton, { table: table })), enableAdvancedFilters && (jsx(MRT_ToggleAdvancedFiltersButton, { table: table })), enableAdvancedFilters && jsx(MRT_SavedFiltersButton, { table: table }), availableExports &&
5783
- loadExport &&
5784
- onActiveExportsChange &&
5785
- activeExports && (jsx(MRT_ExportsToolbar, { table: table, availableExports: availableExports, exportState: activeExports, onExportStateChange: onActiveExportsChange, loadExport: loadExport })), enableNewEntryButton && jsx(MRT_NewEntryButton, { table: table })] })) })));
6012
+ columnFilterDisplayMode !== 'popover' && (jsx(MRT_ToggleFiltersButton, { table: table })), (enableHiding || enableColumnOrdering || enableColumnPinning) && (jsx(MRT_ShowHideColumnsButton, { table: table })), enableDensityToggle && (jsx(MRT_ToggleDensePaddingButton, { table: table })), enableAdvancedFilters && (jsx(MRT_ToggleAdvancedFiltersButton, { table: table })), enableAdvancedFilters && jsx(MRT_SavedFiltersButton, { table: table }), enableNewEntryButton && jsx(MRT_NewEntryButton, { table: table })] })) })));
5786
6013
  };
5787
6014
 
5788
6015
  function ToolbarActions({ table, }) {
@@ -7599,7 +7826,7 @@ const MaterialReactTableComponent = (props, ref) => {
7599
7826
  ? props.table
7600
7827
  : useMaterialReactTable(props);
7601
7828
  useImperativeHandle(ref, () => table, [table]);
7602
- return jsx(MRT_TablePaper, { table: table });
7829
+ return (jsx(MaybeSnackbarProvider, { children: jsx(MRT_TablePaper, { table: table }) }));
7603
7830
  };
7604
7831
  const MaterialReactTable = forwardRef(MaterialReactTableComponent);
7605
7832
 
@@ -7856,6 +8083,10 @@ const MRT_Localization_HR = {
7856
8083
  exportPrintPdf: 'Ispis PDF',
7857
8084
  exportDownload: 'Preuzmi',
7858
8085
  exportGrouped: 'Grupirati datoteke',
8086
+ exportInProgress: 'Izvoz u toku...',
8087
+ exportSuccess: 'Izvoz je uspješno završen.',
8088
+ exportError: 'Izvoz nije uspio. Pokušajte ponovo.',
8089
+ exportNoExportsSelected: 'Nije odabran tip izvoza. Molimo odaberite izvoz iz gornje trake.',
7859
8090
  deleteConfirmationTitle: 'Brisanje reda',
7860
8091
  deleteConfirmationMessage: 'Da li ste sigurni da želite izbrisati ovaj red?',
7861
8092
  deleteConfirmYes: 'Izbriši',