@dooherceg/material-react-table 3.2.9 → 3.2.10

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
@@ -773,7 +773,12 @@ function MRT_DeleteRowButton({ onClick, }) {
773
773
  const iconButtonStyle = {
774
774
  p: 0,
775
775
  };
776
- return (jsxRuntime.jsx(IconButton, { disableRipple: true, color: "error", sx: iconButtonStyle, onClick: onClick, children: jsxRuntime.jsx(DeleteOutlineIcon, {}) }));
776
+ const handleClick = (event) => {
777
+ // Prevent bubbling to muiTableBodyRowProps onClick (row click handlers)
778
+ event.stopPropagation();
779
+ onClick();
780
+ };
781
+ return (jsxRuntime.jsx(IconButton, { disableRipple: true, color: "error", sx: iconButtonStyle, onClick: handleClick, children: jsxRuntime.jsx(DeleteOutlineIcon, {}) }));
777
782
  }
778
783
 
779
784
  const DeleteRowAction = ({ onDeleteConfirm, table, deleteConfirmation, }) => {
@@ -808,7 +813,11 @@ const DeleteRowAction = ({ onDeleteConfirm, table, deleteConfirmation, }) => {
808
813
  const handleClose = () => __awaiter(void 0, void 0, void 0, function* () {
809
814
  setOpen(false);
810
815
  });
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: {
816
+ 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,
817
+ // Dialog renders via a portal, but React still bubbles synthetic events up
818
+ // through the component tree — stop here so clicks inside the confirmation
819
+ // dialog don't reach muiTableBodyRowProps onClick (row click handlers).
820
+ onClick: (event) => event.stopPropagation(), 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
821
  p: '0.7rem',
813
822
  }, 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
823
  };
@@ -874,7 +883,12 @@ const createDeleteAction = (_a = {}) => {
874
883
  };
875
884
 
876
885
  const MRT_EditRowButton = ({ onClick }) => {
877
- return (jsxRuntime.jsx(IconButton, { sx: { p: 0 }, disableRipple: true, color: "primary", onClick: onClick, children: jsxRuntime.jsx(EditNoteIcon, {}) }));
886
+ const handleClick = (event) => {
887
+ // Prevent bubbling to muiTableBodyRowProps onClick (row click handlers)
888
+ event.stopPropagation();
889
+ onClick === null || onClick === void 0 ? void 0 : onClick(event);
890
+ };
891
+ return (jsxRuntime.jsx(IconButton, { sx: { p: 0 }, disableRipple: true, color: "primary", onClick: handleClick, children: jsxRuntime.jsx(EditNoteIcon, {}) }));
878
892
  };
879
893
 
880
894
  const EditRowAction = ({ onEditButtonClick, }) => {
@@ -6310,7 +6324,9 @@ const MRT_NewEntryButton = (_a) => {
6310
6324
  var _b;
6311
6325
  var { table } = _a, rest = __rest(_a, ["table"]);
6312
6326
  const { options: { icons: { AddIcon }, localization, }, setNewEntryModal, } = table;
6313
- const handleOpenNewEntryModal = () => {
6327
+ const handleOpenNewEntryModal = (event) => {
6328
+ // Prevent bubbling to muiTableBodyRowProps onClick (row click handlers)
6329
+ event.stopPropagation();
6314
6330
  setNewEntryModal({ open: true });
6315
6331
  };
6316
6332
  return (jsxRuntime.jsx(Tooltip, { title: (_b = rest === null || rest === void 0 ? void 0 : rest.title) !== null && _b !== void 0 ? _b : localization.newEntry, children: jsxRuntime.jsx(Button, Object.assign({ "aria-label": localization.newEntry, onClick: handleOpenNewEntryModal, size: "small", startIcon: jsxRuntime.jsx(AddIcon, { fontSize: "small" }), variant: "text" }, rest, { title: undefined, children: localization.newEntry })) }));
@@ -8517,6 +8533,9 @@ const useServerTableState = ({ initialState, saveState, saveDebounceMs = 500, })
8517
8533
  const [expanded, setExpanded] = react.useState((_k = initialState === null || initialState === void 0 ? void 0 : initialState.expanded) !== null && _k !== void 0 ? _k : {});
8518
8534
  const [rowSelection, setRowSelection] = react.useState((_l = initialState === null || initialState === void 0 ? void 0 : initialState.rowSelection) !== null && _l !== void 0 ? _l : {});
8519
8535
  const [activeExports, setActiveExports] = react.useState(initialState === null || initialState === void 0 ? void 0 : initialState.activeExports);
8536
+ // Counter that increments on every manual refetch() call, without changing any other state
8537
+ const [refetchIndex, setRefetchIndex] = react.useState(0);
8538
+ const refetch = () => setRefetchIndex((prev) => prev + 1);
8520
8539
  // --- Debounced save ---
8521
8540
  // saveState is optional — if not provided, do nothing
8522
8541
  const debouncedSave = useDebounce.useDebouncedCallback((partial) => {
@@ -8599,7 +8618,9 @@ const useServerTableState = ({ initialState, saveState, saveDebounceMs = 500, })
8599
8618
  pagination,
8600
8619
  sorting,
8601
8620
  columnVisibilityShowTrigger,
8621
+ refetchIndex,
8602
8622
  },
8623
+ refetch,
8603
8624
  };
8604
8625
  };
8605
8626
 
@@ -8643,7 +8664,7 @@ const buildInitialExportState = (availableExports, savedActiveExports) => {
8643
8664
  grouped: false,
8644
8665
  });
8645
8666
  };
8646
- const MaterialReactServerTableInstance = (_a) => {
8667
+ const MaterialReactServerTableInstanceComponent = (_a, ref) => {
8647
8668
  var _b, _c;
8648
8669
  var { config, loadData, saveState, getAllSelectableRowIds, getTotalRows, onSaveFilters, onDeleteSavedFilter, initialSavedFilters, loadExport, exportPermissions, enableNewEntryButton, actions, deleteRowsFn, editRowFn, enableResetState, resetState, extendColumns } = _a,
8649
8670
  // Extra MRT_TableOptions props (e.g. formConfig) passed directly through to useMaterialReactTable
@@ -8671,7 +8692,7 @@ const MaterialReactServerTableInstance = (_a) => {
8671
8692
  });
8672
8693
  return Object.fromEntries(allowedEntries);
8673
8694
  }, [config.availableExports, exportPermissions]);
8674
- const { tableState, handlers, fetchTrigger } = useServerTableState({
8695
+ const { tableState, handlers, fetchTrigger, refetch } = useServerTableState({
8675
8696
  initialState: Object.assign(Object.assign({}, config.initialState), { activeExports: buildInitialExportState(allowedExports, (_b = config.initialState) === null || _b === void 0 ? void 0 : _b.activeExports) }),
8676
8697
  saveState,
8677
8698
  });
@@ -8691,6 +8712,9 @@ const MaterialReactServerTableInstance = (_a) => {
8691
8712
  editRowFn,
8692
8713
  onSaveFilters,
8693
8714
  onDeleteSavedFilter, initialSavedFilters: initialSavedFilters !== null && initialSavedFilters !== void 0 ? initialSavedFilters : (_c = config.initialState) === null || _c === void 0 ? void 0 : _c.savedFilters, availableExports: hasAvailableExports ? allowedExports : undefined, loadExport: hasAvailableExports ? loadExport : undefined, enableNewEntryButton }, tableOptionsOverrides), handlers));
8715
+ // Lets any code that already has `table` (row actions, deleteRowsFn/editRowFn,
8716
+ // custom cell renderers, etc.) trigger a manual reload without needing a ref.
8717
+ table.refetch = refetch;
8694
8718
  const fetchData = react.useCallback((tableInstance) => __awaiter(void 0, void 0, void 0, function* () {
8695
8719
  setIsLoading(true);
8696
8720
  try {
@@ -8718,9 +8742,12 @@ const MaterialReactServerTableInstance = (_a) => {
8718
8742
  fetchTrigger.pagination,
8719
8743
  fetchTrigger.sorting,
8720
8744
  fetchTrigger.columnVisibilityShowTrigger,
8745
+ fetchTrigger.refetchIndex,
8721
8746
  ]);
8747
+ react.useImperativeHandle(ref, () => ({ refetch, table }), [refetch, table]);
8722
8748
  return jsxRuntime.jsx(MaterialReactTable, { table: table });
8723
8749
  };
8750
+ const MaterialReactServerTableInstance = react.forwardRef(MaterialReactServerTableInstanceComponent);
8724
8751
 
8725
8752
  const MaterialReactServerTableSkeleton = () => (jsxRuntime.jsxs(Paper, { "data-testid": "server-table-skeleton", sx: {
8726
8753
  display: 'flex',
@@ -8743,7 +8770,7 @@ const MaterialReactServerTableSkeleton = () => (jsxRuntime.jsxs(Paper, { "data-t
8743
8770
  px: '1.3rem',
8744
8771
  }), children: jsxRuntime.jsxs(Box, { sx: { alignItems: 'center', display: 'flex', gap: '1rem' }, children: [jsxRuntime.jsx(Skeleton, { animation: "wave", height: 36, variant: "rounded", width: 136 }), jsxRuntime.jsx(Skeleton, { animation: "wave", height: 31, variant: "text", width: 176 }), jsxRuntime.jsx(Skeleton, { animation: "wave", height: 22, variant: "text", width: 70 }), jsxRuntime.jsx(Skeleton, { animation: "wave", height: 24, variant: "circular", width: 24 }), jsxRuntime.jsx(Skeleton, { animation: "wave", height: 24, variant: "circular", width: 24 })] }) })] }));
8745
8772
 
8746
- const MaterialReactServerTable = (_a) => {
8773
+ const MaterialReactServerTableComponent = (_a, ref) => {
8747
8774
  var { loadConfig, saveState, localization } = _a, instanceProps = __rest(_a, ["loadConfig", "saveState", "localization"]);
8748
8775
  const mergedLocalization = Object.assign(Object.assign({}, MRT_Localization_HR), localization);
8749
8776
  const [configLoading, setConfigLoading] = react.useState(true);
@@ -8779,8 +8806,9 @@ const MaterialReactServerTable = (_a) => {
8779
8806
  if (!config) {
8780
8807
  return (jsxRuntime.jsx(MaterialReactServerTableError, { description: mergedLocalization.serverTableErrorMessage }));
8781
8808
  }
8782
- return (jsxRuntime.jsx(MaterialReactServerTableInstance, Object.assign({ config: config, saveState: saveState }, instanceProps)));
8809
+ return (jsxRuntime.jsx(MaterialReactServerTableInstance, Object.assign({ ref: ref, config: config, saveState: saveState }, instanceProps)));
8783
8810
  };
8811
+ const MaterialReactServerTable = react.forwardRef(MaterialReactServerTableComponent);
8784
8812
 
8785
8813
  const MRT_ColumnPinningButtons = (_a) => {
8786
8814
  var { column, table } = _a, rest = __rest(_a, ["column", "table"]);