@redsift/table-pro 12.6.0 → 12.6.2

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.
@@ -750,16 +750,40 @@ const clearAllVersionStorage = (id, maxVersion) => {
750
750
  clearPreviousVersionStorage(id, versions);
751
751
  };
752
752
 
753
+ /** Options for `resetStatefulDataGridState` and `resetColumnVisibility`. */
754
+
755
+ /**
756
+ * The query string a reset strips: `getSearch()` when given, otherwise the
757
+ * browser's live URL, otherwise the `search` fallback.
758
+ */
759
+ const readLiveSearch = _ref2 => {
760
+ let {
761
+ search,
762
+ getSearch
763
+ } = _ref2;
764
+ if (getSearch) {
765
+ return getSearch();
766
+ }
767
+ if (typeof window !== 'undefined' && window.location) {
768
+ return window.location.search;
769
+ }
770
+ return search !== null && search !== void 0 ? search : '';
771
+ };
772
+
753
773
  /**
754
774
  * Fully reset a `StatefulDataGrid` — clear localStorage for the given versions
755
775
  * and strip all grid-owned URL params (`_*` and `v=`), preserving any non-grid params.
756
776
  *
757
- * The function reads `window.location.search` directly so the strip always
758
- * operates on the live URL. This matters because consumers typically call this
759
- * from a component whose captured `search` snapshot may be stale — for example
760
- * when the grid has just written its own keys to the URL via the router adapter
761
- * but the parent hasn't re-rendered yet. Falling back to the supplied `search`
762
- * is only used in non-browser environments (SSR, unit tests without jsdom).
777
+ * The strip always operates on the live URL, because consumers typically call
778
+ * this from a component whose captured `search` snapshot may be stale — for
779
+ * example when the grid has just written its own keys to the URL via the
780
+ * router adapter but the parent hasn't re-rendered yet. The live URL is
781
+ * `getSearch()` when given, otherwise `window.location.search`. The supplied
782
+ * `search` is only used in non-browser environments (SSR, unit tests without
783
+ * jsdom).
784
+ *
785
+ * Under a browser router `window.location` is the router's URL. Under a memory
786
+ * history it is not, so pass `getSearch` (see `StatefulDataGridResetOptions`).
763
787
  *
764
788
  * The write is performed via `historyReplace(newSearch, { authoritative: true })`.
765
789
  * Adapters with delta/coalescing logic (e.g. `createReactRouterV5Adapter`)
@@ -772,17 +796,26 @@ const clearAllVersionStorage = (id, maxVersion) => {
772
796
  * const { search, historyReplace } = useMyRouter();
773
797
  * resetStatefulDataGridState({ id: 'myGrid', versions: [0, 1, 2], search, historyReplace });
774
798
  * ```
799
+ *
800
+ * Under a memory history, with `createReactRouterV5Adapter`:
801
+ * ```ts
802
+ * const { pathname, getSearch, historyReplace } = useRouter();
803
+ * resetStatefulDataGridState({ id: pathname, versions: [0, 1], getSearch, historyReplace });
804
+ * ```
775
805
  */
776
- const resetStatefulDataGridState = _ref2 => {
806
+ const resetStatefulDataGridState = _ref3 => {
777
807
  let {
778
808
  id,
779
809
  versions,
780
810
  search,
811
+ getSearch,
781
812
  historyReplace
782
- } = _ref2;
813
+ } = _ref3;
783
814
  clearPreviousVersionStorage(id, versions);
784
- const liveSearch = typeof window !== 'undefined' && window.location ? window.location.search : search;
785
- const params = new URLSearchParams(liveSearch);
815
+ const params = new URLSearchParams(readLiveSearch({
816
+ search,
817
+ getSearch
818
+ }));
786
819
  const keysToDelete = [];
787
820
  params.forEach((_value, key) => {
788
821
  if (key.startsWith('_') || key === 'v') {
@@ -810,9 +843,10 @@ const resetStatefulDataGridState = _ref2 => {
810
843
  * params alone it will not clobber a filter the caller is writing in the same
811
844
  * transition.
812
845
  *
813
- * Like `resetStatefulDataGridState`, the URL strip reads `window.location.search`
814
- * directly so it operates on the live URL (the caller's captured snapshot may
815
- * be stale), and writes via `historyReplace(newSearch, { authoritative: true })`.
846
+ * Like `resetStatefulDataGridState`, the URL strip operates on the live URL
847
+ * (the caller's captured snapshot may be stale): `getSearch()` when given,
848
+ * otherwise `window.location.search`. Pass `getSearch` under a memory history.
849
+ * It writes via `historyReplace(newSearch, { authoritative: true })`.
816
850
  *
817
851
  * This clears the *persisted* state only. The caller is responsible for
818
852
  * resetting the *live* grid in the same tick:
@@ -821,13 +855,14 @@ const resetStatefulDataGridState = _ref2 => {
821
855
  * apiRef.current?.setColumnVisibilityModel?.({});
822
856
  * ```
823
857
  */
824
- const resetColumnVisibility = _ref3 => {
858
+ const resetColumnVisibility = _ref4 => {
825
859
  let {
826
860
  id,
827
861
  versions,
828
862
  search,
863
+ getSearch,
829
864
  historyReplace
830
- } = _ref3;
865
+ } = _ref4;
831
866
  for (const version of versions) {
832
867
  try {
833
868
  window.localStorage.removeItem(buildStorageKey({
@@ -839,8 +874,10 @@ const resetColumnVisibility = _ref3 => {
839
874
  // Ignore — storage may be unavailable (SSR, Safari private mode).
840
875
  }
841
876
  }
842
- const liveSearch = typeof window !== 'undefined' && window.location ? window.location.search : search;
843
- const params = new URLSearchParams(liveSearch);
877
+ const params = new URLSearchParams(readLiveSearch({
878
+ search,
879
+ getSearch
880
+ }));
844
881
  params.delete('_columnVisibility');
845
882
  historyReplace(params.toString(), {
846
883
  authoritative: true
@@ -2914,16 +2951,25 @@ const COMPONENT_NAME = 'DataGrid';
2914
2951
  const CLASSNAME = 'redsift-datagrid';
2915
2952
 
2916
2953
  /**
2917
- * StatefulDataGrid extends DataGrid with automatic state persistence to localStorage.
2918
- * Preserves filters, sorting, pagination, column visibility, and column widths
2919
- * across page refreshes.
2954
+ * StatefulDataGrid extends DataGrid with automatic state persistence to the URL and localStorage.
2955
+ * Filters, sorting, pagination, column visibility, column order, pinned
2956
+ * columns and density are written to the URL query string and to localStorage;
2957
+ * column widths are kept in localStorage only. On load the URL wins, then
2958
+ * localStorage, then `initialState`, so state survives page refreshes and a
2959
+ * copied URL reopens the same view.
2920
2960
  *
2921
- * Use when users need persistent table preferences. Requires unique `localStorageKey`.
2961
+ * Use when users need persistent table preferences or shareable filtered views.
2962
+ * Requires a `useRouter` hook returning `{ pathname, search, historyReplace }`
2963
+ * (`createReactRouterV5Adapter` builds one from a React Router v5 `history`).
2964
+ * State is stored in localStorage under the `pathname` it returns, and
2965
+ * versioned by `localStorageVersion` (a number, default `1`).
2922
2966
  *
2923
2967
  * @example
2924
- * // Basic stateful grid (persists to localStorage)
2968
+ * // Basic stateful grid (URL + localStorage)
2969
+ * const useRouter = createReactRouterV5Adapter(history);
2970
+ *
2925
2971
  * <StatefulDataGrid
2926
- * localStorageKey="users-table"
2972
+ * useRouter={useRouter}
2927
2973
  * columns={columns}
2928
2974
  * rows={users}
2929
2975
  * pagination
@@ -2932,34 +2978,24 @@ const CLASSNAME = 'redsift-datagrid';
2932
2978
  * @example
2933
2979
  * // With version migration (clears old preferences)
2934
2980
  * <StatefulDataGrid
2935
- * localStorageKey="reports-table"
2936
- * localStorageVersion="v2"
2937
- * previousLocalStorageVersions={['v1']}
2981
+ * useRouter={useRouter}
2982
+ * localStorageVersion={2}
2983
+ * previousLocalStorageVersions={[1]}
2938
2984
  * columns={columns}
2939
2985
  * rows={reports}
2940
2986
  * />
2941
2987
  *
2942
2988
  * @example
2943
- * // With URL state sync (shareable filtered views)
2944
- * <StatefulDataGrid
2945
- * localStorageKey="domains-table"
2946
- * useRouter={true}
2947
- * columns={columns}
2948
- * rows={domains}
2949
- * pagination
2950
- * />
2951
- *
2952
- * @example
2953
2989
  * // All features combined
2954
2990
  * <StatefulDataGrid
2955
- * localStorageKey="audit-log"
2956
- * localStorageVersion="v3"
2957
- * previousLocalStorageVersions={['v1', 'v2']}
2958
- * useRouter={true}
2991
+ * useRouter={useRouter}
2992
+ * localStorageVersion={3}
2993
+ * previousLocalStorageVersions={[1, 2]}
2959
2994
  * columns={columns}
2960
2995
  * rows={logs}
2961
2996
  * pagination
2962
- * pageSize={50}
2997
+ * pageSizeOptions={[25, 50, 100]}
2998
+ * initialState={{ pagination: { paginationModel: { page: 0, pageSize: 50 } } }}
2963
2999
  * checkboxSelection
2964
3000
  * />
2965
3001
  */