@redsift/table 12.5.1 → 12.5.2-alpha.0

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.
@@ -2949,7 +2949,7 @@ const useStatefulTable = props => {
2949
2949
  };
2950
2950
  };
2951
2951
 
2952
- const _excluded = ["apiRef", "autoHeight", "className", "columns", "slots", "slotProps", "filterModel", "columnVisibilityModel", "pinnedColumns", "sortModel", "paginationModel", "height", "hideToolbar", "initialState", "isRowSelectable", "license", "localStorageVersion", "previousLocalStorageVersions", "onFilterModelChange", "rowSelectionModel", "onColumnWidthChange", "onPaginationModelChange", "onRowSelectionModelChange", "onColumnVisibilityModelChange", "onPinnedColumnsChange", "onSortModelChange", "onRowGroupingModelChange", "onAggregationModelChange", "onPivotModelChange", "pagination", "paginationPlacement", "paginationProps", "rows", "pageSizeOptions", "sx", "theme", "useRouter", "paginationMode", "rowCount", "density"];
2952
+ const _excluded = ["apiRef", "autoHeight", "className", "columns", "slots", "slotProps", "filterModel", "columnVisibilityModel", "pinnedColumns", "sortModel", "paginationModel", "height", "hideToolbar", "initialState", "isRowSelectable", "license", "localStorageVersion", "previousLocalStorageVersions", "onFilterModelChange", "rowSelectionModel", "onColumnWidthChange", "onPaginationModelChange", "onRowSelectionModelChange", "onColumnVisibilityModelChange", "onPinnedColumnsChange", "onSortModelChange", "onRowGroupingModelChange", "onAggregationModelChange", "onPivotModelChange", "pagination", "paginationPlacement", "paginationProps", "rows", "pageSizeOptions", "sx", "theme", "useRouter", "paginationMode", "rowCount", "density", "dataSource", "filterMode", "sortingMode"];
2953
2953
  const COMPONENT_NAME = 'DataGrid';
2954
2954
  const CLASSNAME = 'redsift-datagrid';
2955
2955
 
@@ -3046,7 +3046,10 @@ const StatefulDataGrid = /*#__PURE__*/forwardRef((props, ref) => {
3046
3046
  useRouter,
3047
3047
  paginationMode = 'client',
3048
3048
  rowCount,
3049
- density: _density
3049
+ density: _density,
3050
+ dataSource,
3051
+ filterMode: propsFilterMode,
3052
+ sortingMode: propsSortingMode
3050
3053
  } = props,
3051
3054
  forwardedProps = _objectWithoutProperties(props, _excluded);
3052
3055
  const theme = useTheme(propsTheme);
@@ -3054,6 +3057,14 @@ const StatefulDataGrid = /*#__PURE__*/forwardRef((props, ref) => {
3054
3057
  const apiRef = propsApiRef !== null && propsApiRef !== void 0 ? propsApiRef : _apiRef;
3055
3058
  LicenseInfo.setLicenseKey(license);
3056
3059
  const height = propsHeight !== null && propsHeight !== void 0 ? propsHeight : autoHeight ? undefined : '500px';
3060
+
3061
+ // When dataSource is present, MUI manages filter/sort/pagination internally.
3062
+ // We must not pass controlled models — only initialState (one-time) and
3063
+ // write-only onChange handlers for URL/localStorage persistence.
3064
+ const isDataSourceMode = Boolean(dataSource);
3065
+ const effectivePaginationMode = isDataSourceMode ? 'server' : paginationMode;
3066
+ const effectiveFilterMode = isDataSourceMode ? 'server' : propsFilterMode;
3067
+ const effectiveSortingMode = isDataSourceMode ? 'server' : propsSortingMode;
3057
3068
  const {
3058
3069
  onColumnVisibilityModelChange: controlledOnColumnVisibilityModelChange,
3059
3070
  onFilterModelChange: controlledOnFilterModelChange,
@@ -3111,6 +3122,29 @@ const StatefulDataGrid = /*#__PURE__*/forwardRef((props, ref) => {
3111
3122
  localStorageVersion,
3112
3123
  previousLocalStorageVersions
3113
3124
  });
3125
+
3126
+ // In dataSource mode, track pagination locally for the custom pagination slots
3127
+ // (rendered outside DataGridPremium). MUI owns the actual pagination state internally.
3128
+ const [dataSourcePaginationModel, setDataSourcePaginationModel] = useState(paginationModel);
3129
+
3130
+ // The pagination model to use for display in pagination slots
3131
+ const activePaginationModel = isDataSourceMode ? dataSourcePaginationModel : paginationModel;
3132
+
3133
+ // In dataSource mode, the top pagination (outside DataGridPremium) must go through
3134
+ // apiRef to change MUI's internal page. MUI then fires onPaginationModelChange
3135
+ // which updates URL and local state.
3136
+ const dataSourceTopPaginationChange = useCallback(model => {
3137
+ var _apiRef$current;
3138
+ (_apiRef$current = apiRef.current) === null || _apiRef$current === void 0 ? void 0 : _apiRef$current.setPaginationModel(model);
3139
+ }, [apiRef]);
3140
+
3141
+ // Wrap onPaginationModelChange to also track state locally in dataSource mode
3142
+ const wrappedOnPaginationModelChange = useCallback((model, details) => {
3143
+ if (isDataSourceMode) {
3144
+ setDataSourcePaginationModel(model);
3145
+ }
3146
+ onPaginationModelChange(model, details);
3147
+ }, [isDataSourceMode, onPaginationModelChange]);
3114
3148
  const [rowSelectionModel, setRowSelectionModel] = useState(() => normalizeRowSelectionModel(propsRowSelectionModel));
3115
3149
  useEffect(() => {
3116
3150
  setRowSelectionModel(normalizeRowSelectionModel(propsRowSelectionModel));
@@ -3132,7 +3166,7 @@ const StatefulDataGrid = /*#__PURE__*/forwardRef((props, ref) => {
3132
3166
 
3133
3167
  // The checkboxSelectionVisibleOnly should only be applied to client-side pagination,
3134
3168
  // for server-side pagination it produces inconsistent behavior when selecting all rows in pages 2 and beyond
3135
- const checkboxSelectionVisibleOnly = Boolean(pagination) && Boolean(paginationMode != 'server');
3169
+ const checkboxSelectionVisibleOnly = Boolean(pagination) && Boolean(effectivePaginationMode != 'server');
3136
3170
 
3137
3171
  // Track when the grid API is ready to ensure top pagination renders correctly
3138
3172
  const [gridReady, setGridReady] = useState(false);
@@ -3155,11 +3189,13 @@ const StatefulDataGrid = /*#__PURE__*/forwardRef((props, ref) => {
3155
3189
  // in server-side pagination we want to update the selection status
3156
3190
  // every time we navigate between pages, resize our page or select something
3157
3191
  useEffect(() => {
3158
- if (paginationMode == 'server') {
3159
- onServerSideSelectionStatusChange(rowSelectionModel, apiRef, selectionStatusRef, forceSelectionUpdate, isRowSelectable, paginationModel.page, paginationModel.pageSize);
3192
+ if (effectivePaginationMode == 'server') {
3193
+ onServerSideSelectionStatusChange(rowSelectionModel, apiRef, selectionStatusRef, forceSelectionUpdate, isRowSelectable, activePaginationModel.page, activePaginationModel.pageSize);
3160
3194
  }
3161
- }, [rowSelectionModel, paginationModel.page, paginationModel.pageSize, rows]);
3162
- if (!Array.isArray(rows)) {
3195
+ }, [rowSelectionModel, activePaginationModel.page, activePaginationModel.pageSize, rows]);
3196
+
3197
+ // In dataSource mode MUI provides rows internally; skip the guard.
3198
+ if (!isDataSourceMode && !Array.isArray(rows)) {
3163
3199
  return null;
3164
3200
  }
3165
3201
 
@@ -3168,14 +3204,14 @@ const StatefulDataGrid = /*#__PURE__*/forwardRef((props, ref) => {
3168
3204
  // receive the fresh value in the same render cycle — no extra re-render needed.
3169
3205
  // The ref is kept in sync for the onRowSelectionModelChange callback's deselect logic.
3170
3206
  let selectionStatus = selectionStatusRef.current;
3171
- if (pagination && paginationMode !== 'server' && getSelectionCount(rowSelectionModel) > 0) {
3207
+ if (pagination && effectivePaginationMode !== 'server' && getSelectionCount(rowSelectionModel) > 0) {
3172
3208
  try {
3173
3209
  // Use manual page slicing instead of gridPaginatedVisibleSorted* selectors.
3174
3210
  // MUI's paginated selectors use apiRef internal state which may be stale when
3175
3211
  // paginationModel prop changes — our React state is always up to date.
3176
3212
  const allFilteredEntries = gridFilteredSortedRowEntriesSelector(apiRef);
3177
- const pageStart = paginationModel.page * paginationModel.pageSize;
3178
- const pageEntries = allFilteredEntries.slice(pageStart, pageStart + paginationModel.pageSize);
3213
+ const pageStart = activePaginationModel.page * activePaginationModel.pageSize;
3214
+ const pageEntries = allFilteredEntries.slice(pageStart, pageStart + activePaginationModel.pageSize);
3179
3215
  const selectableRowsInPage = isRowSelectable ? pageEntries.filter(_ref => {
3180
3216
  let {
3181
3217
  model
@@ -3235,7 +3271,7 @@ const StatefulDataGrid = /*#__PURE__*/forwardRef((props, ref) => {
3235
3271
  } catch {
3236
3272
  // apiRef may not be initialized on first render
3237
3273
  }
3238
- } else if (pagination && paginationMode !== 'server') {
3274
+ } else if (pagination && effectivePaginationMode !== 'server') {
3239
3275
  selectionStatus = {
3240
3276
  type: 'none',
3241
3277
  numberOfSelectedRows: 0
@@ -3264,13 +3300,13 @@ const StatefulDataGrid = /*#__PURE__*/forwardRef((props, ref) => {
3264
3300
  ref: datagridRef,
3265
3301
  className: classNames(StatefulDataGrid.className, className),
3266
3302
  $height: height
3267
- }, pagination && ['top', 'both'].includes(paginationPlacement) && gridReady ? paginationMode == 'server' ? /*#__PURE__*/React__default.createElement(ServerSideControlledPagination, {
3303
+ }, pagination && ['top', 'both'].includes(paginationPlacement) && gridReady ? effectivePaginationMode == 'server' ? /*#__PURE__*/React__default.createElement(ServerSideControlledPagination, {
3268
3304
  displaySelection: true,
3269
3305
  displayRowsPerPage: ['top', 'both'].includes(paginationPlacement),
3270
3306
  displayPagination: ['top', 'both'].includes(paginationPlacement),
3271
3307
  selectionStatus: selectionStatus,
3272
- paginationModel: paginationModel,
3273
- onPaginationModelChange: onPaginationModelChange,
3308
+ paginationModel: activePaginationModel,
3309
+ onPaginationModelChange: isDataSourceMode ? dataSourceTopPaginationChange : onPaginationModelChange,
3274
3310
  pageSizeOptions: pageSizeOptions,
3275
3311
  paginationProps: paginationProps,
3276
3312
  rowCount: rowCount
@@ -3281,23 +3317,18 @@ const StatefulDataGrid = /*#__PURE__*/forwardRef((props, ref) => {
3281
3317
  selectionStatus: selectionStatus,
3282
3318
  apiRef: apiRef,
3283
3319
  isRowSelectable: isRowSelectable,
3284
- paginationModel: paginationModel,
3320
+ paginationModel: activePaginationModel,
3285
3321
  onPaginationModelChange: onPaginationModelChange,
3286
3322
  pageSizeOptions: pageSizeOptions,
3287
3323
  paginationProps: paginationProps
3288
3324
  }) : null, /*#__PURE__*/React__default.createElement(DataGridPremium, _extends({}, forwardedProps, {
3289
3325
  apiRef: apiRef,
3326
+ dataSource: dataSource,
3290
3327
  columns: columns,
3291
3328
  columnVisibilityModel: columnVisibilityModel,
3292
- filterModel: filterModel,
3293
3329
  onColumnVisibilityModelChange: onColumnVisibilityModelChange,
3294
- onFilterModelChange: onFilterModelChange,
3295
- onPaginationModelChange: onPaginationModelChange,
3296
3330
  onPinnedColumnsChange: onPinnedColumnsChange,
3297
- onSortModelChange: onSortModelChange,
3298
- paginationModel: paginationModel,
3299
3331
  pinnedColumns: pinnedColumns,
3300
- sortModel: sortModel,
3301
3332
  pageSizeOptions: pageSizeOptions,
3302
3333
  onColumnWidthChange: onColumnWidthChange,
3303
3334
  rowGroupingModel: rowGroupingModel,
@@ -3305,18 +3336,50 @@ const StatefulDataGrid = /*#__PURE__*/forwardRef((props, ref) => {
3305
3336
  aggregationModel: aggregationModel,
3306
3337
  onAggregationModelChange: onAggregationModelChange,
3307
3338
  pivotModel: pivotModel,
3308
- onPivotModelChange: onPivotModelChange,
3339
+ onPivotModelChange: onPivotModelChange
3340
+ // In dataSource mode: models are uncontrolled (MUI owns them),
3341
+ // onChange handlers are write-only for URL/localStorage persistence,
3342
+ // and initialState seeds MUI on mount from the persisted URL state.
3343
+ }, isDataSourceMode ? {
3344
+ onFilterModelChange: onFilterModelChange,
3345
+ onSortModelChange: onSortModelChange,
3346
+ onPaginationModelChange: wrappedOnPaginationModelChange,
3347
+ initialState: _objectSpread2(_objectSpread2({}, initialState), {}, {
3348
+ density: controlledDensity,
3349
+ columns: _objectSpread2(_objectSpread2({}, initialState === null || initialState === void 0 ? void 0 : initialState.columns), {}, {
3350
+ orderedFields: columnOrderModel
3351
+ }),
3352
+ filter: {
3353
+ filterModel
3354
+ },
3355
+ sorting: {
3356
+ sortModel
3357
+ },
3358
+ pagination: {
3359
+ paginationModel
3360
+ }
3361
+ })
3362
+ } : {
3363
+ filterModel,
3364
+ sortModel,
3365
+ paginationModel,
3366
+ onFilterModelChange: onFilterModelChange,
3367
+ onSortModelChange: onSortModelChange,
3368
+ onPaginationModelChange: wrappedOnPaginationModelChange,
3309
3369
  initialState: _objectSpread2(_objectSpread2({}, initialState), {}, {
3310
3370
  density: controlledDensity,
3311
3371
  columns: _objectSpread2(_objectSpread2({}, initialState === null || initialState === void 0 ? void 0 : initialState.columns), {}, {
3312
3372
  orderedFields: columnOrderModel
3313
3373
  })
3314
- }),
3374
+ })
3375
+ }, {
3315
3376
  isRowSelectable: isRowSelectable,
3316
3377
  pagination: pagination,
3317
- paginationMode: paginationMode,
3318
- keepNonExistentRowsSelected: paginationMode == 'server',
3319
- rows: rows,
3378
+ paginationMode: effectivePaginationMode,
3379
+ filterMode: effectiveFilterMode,
3380
+ sortingMode: effectiveSortingMode,
3381
+ keepNonExistentRowsSelected: effectivePaginationMode == 'server',
3382
+ rows: isDataSourceMode ? [] : rows,
3320
3383
  rowCount: rowCount,
3321
3384
  autoHeight: autoHeight,
3322
3385
  checkboxSelectionVisibleOnly: checkboxSelectionVisibleOnly,
@@ -3361,13 +3424,13 @@ const StatefulDataGrid = /*#__PURE__*/forwardRef((props, ref) => {
3361
3424
  }))
3362
3425
  }, slots), {}, {
3363
3426
  pagination: props => {
3364
- return pagination ? paginationMode == 'server' ? /*#__PURE__*/React__default.createElement(ServerSideControlledPagination, _extends({}, props, {
3427
+ return pagination ? effectivePaginationMode == 'server' ? /*#__PURE__*/React__default.createElement(ServerSideControlledPagination, _extends({}, props, {
3365
3428
  displaySelection: false,
3366
3429
  displayRowsPerPage: ['bottom', 'both'].includes(paginationPlacement),
3367
3430
  displayPagination: ['bottom', 'both'].includes(paginationPlacement),
3368
3431
  selectionStatus: selectionStatus,
3369
- paginationModel: paginationModel,
3370
- onPaginationModelChange: onPaginationModelChange,
3432
+ paginationModel: activePaginationModel,
3433
+ onPaginationModelChange: wrappedOnPaginationModelChange,
3371
3434
  pageSizeOptions: pageSizeOptions,
3372
3435
  paginationProps: paginationProps,
3373
3436
  rowCount: rowCount
@@ -3378,8 +3441,8 @@ const StatefulDataGrid = /*#__PURE__*/forwardRef((props, ref) => {
3378
3441
  selectionStatus: selectionStatus,
3379
3442
  apiRef: apiRef,
3380
3443
  isRowSelectable: isRowSelectable,
3381
- paginationModel: paginationModel,
3382
- onPaginationModelChange: onPaginationModelChange,
3444
+ paginationModel: activePaginationModel,
3445
+ onPaginationModelChange: wrappedOnPaginationModelChange,
3383
3446
  pageSizeOptions: pageSizeOptions,
3384
3447
  paginationProps: paginationProps
3385
3448
  })) : null;
@@ -3388,12 +3451,12 @@ const StatefulDataGrid = /*#__PURE__*/forwardRef((props, ref) => {
3388
3451
  slotProps: _objectSpread2({}, slotProps),
3389
3452
  rowSelectionModel: rowSelectionModel,
3390
3453
  onRowSelectionModelChange: (newSelectionModel, details) => {
3391
- if (pagination && paginationMode != 'server') {
3454
+ if (pagination && effectivePaginationMode != 'server') {
3392
3455
  // Use manual page slicing instead of gridPaginatedVisibleSorted* selectors
3393
3456
  // to avoid stale apiRef pagination state.
3394
3457
  const allFilteredEntries = gridFilteredSortedRowEntriesSelector(apiRef);
3395
- const pageStart = paginationModel.page * paginationModel.pageSize;
3396
- const pageEntries = allFilteredEntries.slice(pageStart, pageStart + paginationModel.pageSize);
3458
+ const pageStart = activePaginationModel.page * activePaginationModel.pageSize;
3459
+ const pageEntries = allFilteredEntries.slice(pageStart, pageStart + activePaginationModel.pageSize);
3397
3460
  const selectableRowsInPage = isRowSelectable ? pageEntries.filter(_ref6 => {
3398
3461
  let {
3399
3462
  model
@@ -3430,8 +3493,8 @@ const StatefulDataGrid = /*#__PURE__*/forwardRef((props, ref) => {
3430
3493
  const numberOfSelectedRows = getSelectionCount(newSelectionModel);
3431
3494
  if (selectionStatusRef.current.type === 'table' && numberOfSelectedRows === numberOfSelectableRowsInTable - numberOfSelectableRowsInPage || selectionStatusRef.current.type === 'table' && numberOfSelectedRows === numberOfSelectableRowsInTable || selectionStatusRef.current.type === 'page' && numberOfSelectedRows === numberOfSelectableRowsInPage) {
3432
3495
  setTimeout(() => {
3433
- var _apiRef$current;
3434
- (_apiRef$current = apiRef.current) === null || _apiRef$current === void 0 ? void 0 : _apiRef$current.selectRows([], true, true);
3496
+ var _apiRef$current2;
3497
+ (_apiRef$current2 = apiRef.current) === null || _apiRef$current2 === void 0 ? void 0 : _apiRef$current2.selectRows([], true, true);
3435
3498
  }, 0);
3436
3499
  }
3437
3500
  if (numberOfSelectedRows === numberOfSelectableRowsInPage && numberOfSelectableRowsInPage < numberOfSelectableRowsInTable) {