@redsift/table-pro 12.6.6-alpha.2 → 13.0.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.
- package/CONTRIBUTING.md +20 -8
- package/_internal/BaseIconButton.js +1 -3
- package/_internal/BaseIconButton.js.map +1 -1
- package/_internal/BaseTextField.js +3 -1
- package/_internal/BaseTextField.js.map +1 -1
- package/_internal/DataGrid2.js +1 -1
- package/_internal/DataGrid2.js.map +1 -1
- package/_internal/GridToolbarFilterSemanticField2.js +18 -1354
- package/_internal/GridToolbarFilterSemanticField2.js.map +1 -1
- package/_internal/StatefulDataGrid2.js +77 -51
- package/_internal/StatefulDataGrid2.js.map +1 -1
- package/_internal/TextCell2.js +1 -1
- package/_internal/TextCell2.js.map +1 -1
- package/_internal/Toolbar2.js.map +1 -1
- package/index.d.ts +11 -6
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/package.json +17 -20
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { _ as _objectSpread2, a as _objectWithoutProperties, b as _extends } from './_rollupPluginBabelHelpers.js';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
import React__default, { useCallback,
|
|
3
|
+
import React__default, { useCallback, useRef, useEffect, useMemo, forwardRef, useState } from 'react';
|
|
4
4
|
import { createTheme, ThemeProvider as ThemeProvider$1 } from '@mui/material/styles';
|
|
5
5
|
import classNames from 'classnames';
|
|
6
6
|
import { LicenseInfo } from '@mui/x-license';
|
|
@@ -22,7 +22,7 @@ const InputNumberInterval = props => {
|
|
|
22
22
|
applyValue,
|
|
23
23
|
focusElementRef = null
|
|
24
24
|
} = props;
|
|
25
|
-
const filterTimeout = React.useRef();
|
|
25
|
+
const filterTimeout = React.useRef(undefined);
|
|
26
26
|
const [filterValueState, setFilterValueState] = React.useState((_item$value = item.value) !== null && _item$value !== void 0 ? _item$value : '');
|
|
27
27
|
const [applying, setIsApplying] = React.useState(false);
|
|
28
28
|
React.useEffect(() => {
|
|
@@ -2666,6 +2666,11 @@ function isDeepEqual(a, b) {
|
|
|
2666
2666
|
if (aKeys.length !== bKeys.length) return false;
|
|
2667
2667
|
return aKeys.every(key => isDeepEqual(aObj[key], bObj[key]));
|
|
2668
2668
|
}
|
|
2669
|
+
|
|
2670
|
+
/** The models one change writes to the URL; everything else comes from the current state. */
|
|
2671
|
+
|
|
2672
|
+
/** What this hook has written to the URL since the router last reported a new `search`. */
|
|
2673
|
+
|
|
2669
2674
|
const useStatefulTable = props => {
|
|
2670
2675
|
var _initialState$columns, _initialState$columns2;
|
|
2671
2676
|
const {
|
|
@@ -2687,6 +2692,19 @@ const useStatefulTable = props => {
|
|
|
2687
2692
|
pathname,
|
|
2688
2693
|
historyReplace
|
|
2689
2694
|
} = useRouter();
|
|
2695
|
+
|
|
2696
|
+
// What this hook has written to the URL since the router last reported a new `search`. Every write
|
|
2697
|
+
// rebuilds the whole URL, so a second change in the same tick, before the router re-renders the grid
|
|
2698
|
+
// with the first, would otherwise start again from the models parsed at this render and drop the
|
|
2699
|
+
// first: `apiRef.setSortModel(m)` then `setFilterModel(f)` kept the filter and lost the sort.
|
|
2700
|
+
// `written` is the URL of the last write: the router has not reported it yet, so it is what the next write
|
|
2701
|
+
// compares itself with (`updateUrl` skips a write that equals the URL it is given), not the `search` this
|
|
2702
|
+
// render saw. A new `search` means the parse below already reflects those writes: `writeUrl` starts over.
|
|
2703
|
+
const pendingWritesRef = useRef({
|
|
2704
|
+
search,
|
|
2705
|
+
overrides: {},
|
|
2706
|
+
written: null
|
|
2707
|
+
});
|
|
2690
2708
|
const id = pathname;
|
|
2691
2709
|
|
|
2692
2710
|
// States and setters persisted in the local storage for this table
|
|
@@ -2802,6 +2820,42 @@ const useStatefulTable = props => {
|
|
|
2802
2820
|
}
|
|
2803
2821
|
const defaultColumnOrder = (_initialState$columns = initialState === null || initialState === void 0 ? void 0 : (_initialState$columns2 = initialState.columns) === null || _initialState$columns2 === void 0 ? void 0 : _initialState$columns2.orderedFields) !== null && _initialState$columns !== void 0 ? _initialState$columns : propsColumns.map(c => c.field);
|
|
2804
2822
|
|
|
2823
|
+
// Helper to build the current DataGridModel for updateUrl calls
|
|
2824
|
+
const buildModel = function () {
|
|
2825
|
+
var _apiRef$current$state, _apiRef$current2;
|
|
2826
|
+
let overrides = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2827
|
+
return _objectSpread2({
|
|
2828
|
+
filterModel: filterParsed,
|
|
2829
|
+
sortModel: sortModelParsed,
|
|
2830
|
+
paginationModel: paginationModelParsed,
|
|
2831
|
+
columnsModel: (_apiRef$current$state = (_apiRef$current2 = apiRef.current) === null || _apiRef$current2 === void 0 ? void 0 : _apiRef$current2.state.columns.columnVisibilityModel) !== null && _apiRef$current$state !== void 0 ? _apiRef$current$state : {},
|
|
2832
|
+
pinnedColumnsModel: pinnedColumnsModel,
|
|
2833
|
+
density: densityParsed,
|
|
2834
|
+
columnOrderModel: columnOrderParsed,
|
|
2835
|
+
defaultColumnOrder
|
|
2836
|
+
}, overrides);
|
|
2837
|
+
};
|
|
2838
|
+
|
|
2839
|
+
// Writes the URL: the current models, what this hook has written since the last new `search`, then
|
|
2840
|
+
// this change (see pendingWritesRef).
|
|
2841
|
+
const writeUrl = overrides => {
|
|
2842
|
+
var _pending$written;
|
|
2843
|
+
// Decided here, when a change happens, not while rendering: a render React discards must not reset it.
|
|
2844
|
+
if (pendingWritesRef.current.search !== search) {
|
|
2845
|
+
pendingWritesRef.current = {
|
|
2846
|
+
search,
|
|
2847
|
+
overrides: {},
|
|
2848
|
+
written: null
|
|
2849
|
+
};
|
|
2850
|
+
}
|
|
2851
|
+
const pending = pendingWritesRef.current;
|
|
2852
|
+
pending.overrides = _objectSpread2(_objectSpread2({}, pending.overrides), overrides);
|
|
2853
|
+
updateUrl(buildModel(pending.overrides), (_pending$written = pending.written) !== null && _pending$written !== void 0 ? _pending$written : search, localStorageVersion, newSearch => {
|
|
2854
|
+
pending.written = newSearch;
|
|
2855
|
+
historyReplace(newSearch);
|
|
2856
|
+
}, columns);
|
|
2857
|
+
};
|
|
2858
|
+
|
|
2805
2859
|
// Subscribe to density changes via stateChange event (MUI v6 has no densityChange event)
|
|
2806
2860
|
useEffect(() => {
|
|
2807
2861
|
const api = apiRef.current;
|
|
@@ -2811,16 +2865,9 @@ const useStatefulTable = props => {
|
|
|
2811
2865
|
const currentDensity = api.state.density;
|
|
2812
2866
|
if (currentDensity !== prevDensity) {
|
|
2813
2867
|
prevDensity = currentDensity;
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
paginationModel: paginationModelParsed,
|
|
2818
|
-
columnsModel: api.state.columns.columnVisibilityModel,
|
|
2819
|
-
pinnedColumnsModel: pinnedColumnsModel,
|
|
2820
|
-
density: currentDensity,
|
|
2821
|
-
columnOrderModel: columnOrderParsed,
|
|
2822
|
-
defaultColumnOrder
|
|
2823
|
-
}, search, localStorageVersion, historyReplace, columns);
|
|
2868
|
+
writeUrl({
|
|
2869
|
+
density: currentDensity
|
|
2870
|
+
});
|
|
2824
2871
|
}
|
|
2825
2872
|
});
|
|
2826
2873
|
return unsub;
|
|
@@ -2833,16 +2880,9 @@ const useStatefulTable = props => {
|
|
|
2833
2880
|
const handleColumnOrderChange = () => {
|
|
2834
2881
|
const orderedFields = api.state.columns.orderedFields;
|
|
2835
2882
|
if (orderedFields && !isDeepEqual(orderedFields, columnOrderParsed)) {
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
paginationModel: paginationModelParsed,
|
|
2840
|
-
columnsModel: api.state.columns.columnVisibilityModel,
|
|
2841
|
-
pinnedColumnsModel,
|
|
2842
|
-
density: densityParsed,
|
|
2843
|
-
columnOrderModel: orderedFields,
|
|
2844
|
-
defaultColumnOrder
|
|
2845
|
-
}, search, localStorageVersion, historyReplace, columns);
|
|
2883
|
+
writeUrl({
|
|
2884
|
+
columnOrderModel: orderedFields
|
|
2885
|
+
});
|
|
2846
2886
|
}
|
|
2847
2887
|
};
|
|
2848
2888
|
const unsub1 = api.subscribeEvent('columnOrderChange', handleColumnOrderChange);
|
|
@@ -2853,22 +2893,6 @@ const useStatefulTable = props => {
|
|
|
2853
2893
|
};
|
|
2854
2894
|
}, [apiRef, columnOrderParsed, defaultColumnOrder, filterParsed, sortModelParsed, paginationModelParsed, pinnedColumnsModel, densityParsed, search, localStorageVersion, historyReplace, columns]);
|
|
2855
2895
|
|
|
2856
|
-
// Helper to build the current DataGridModel for updateUrl calls
|
|
2857
|
-
const buildModel = function () {
|
|
2858
|
-
var _apiRef$current$state, _apiRef$current2;
|
|
2859
|
-
let overrides = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2860
|
-
return _objectSpread2({
|
|
2861
|
-
filterModel: filterParsed,
|
|
2862
|
-
sortModel: sortModelParsed,
|
|
2863
|
-
paginationModel: paginationModelParsed,
|
|
2864
|
-
columnsModel: (_apiRef$current$state = (_apiRef$current2 = apiRef.current) === null || _apiRef$current2 === void 0 ? void 0 : _apiRef$current2.state.columns.columnVisibilityModel) !== null && _apiRef$current$state !== void 0 ? _apiRef$current$state : {},
|
|
2865
|
-
pinnedColumnsModel: pinnedColumnsModel,
|
|
2866
|
-
density: densityParsed,
|
|
2867
|
-
columnOrderModel: columnOrderParsed,
|
|
2868
|
-
defaultColumnOrder
|
|
2869
|
-
}, overrides);
|
|
2870
|
-
};
|
|
2871
|
-
|
|
2872
2896
|
// Track last emitted values for deep-equal guards to avoid feedback loops.
|
|
2873
2897
|
// Initialised from the current parsed values; updated only when we actually fire.
|
|
2874
2898
|
const lastEmittedFilterRef = useRef(filterParsed);
|
|
@@ -2895,25 +2919,25 @@ const useStatefulTable = props => {
|
|
|
2895
2919
|
// next render's URL re-parse reuses that id and the GridFilterForm key — and thus
|
|
2896
2920
|
// the value input's focus — survives the write→parse roundtrip (DS-81).
|
|
2897
2921
|
filterIdSourceRef.current = filterModel;
|
|
2898
|
-
|
|
2922
|
+
writeUrl({
|
|
2899
2923
|
filterModel
|
|
2900
|
-
})
|
|
2924
|
+
});
|
|
2901
2925
|
propsOnFilterModelChange === null || propsOnFilterModelChange === void 0 ? void 0 : propsOnFilterModelChange(filterModel, details);
|
|
2902
2926
|
},
|
|
2903
2927
|
filterModel: filterParsedRef.current,
|
|
2904
2928
|
onSortModelChange: (model, details) => {
|
|
2905
2929
|
if (isDeepEqual(model, lastEmittedSortRef.current)) return;
|
|
2906
2930
|
lastEmittedSortRef.current = model;
|
|
2907
|
-
|
|
2931
|
+
writeUrl({
|
|
2908
2932
|
sortModel: model
|
|
2909
|
-
})
|
|
2933
|
+
});
|
|
2910
2934
|
propsOnSortModelChange === null || propsOnSortModelChange === void 0 ? void 0 : propsOnSortModelChange(model, details);
|
|
2911
2935
|
},
|
|
2912
2936
|
sortModel: sortModelParsedRef.current,
|
|
2913
2937
|
onPinnedColumnsChange: (pinnedColumns, details) => {
|
|
2914
|
-
|
|
2938
|
+
writeUrl({
|
|
2915
2939
|
pinnedColumnsModel: pinnedColumns
|
|
2916
|
-
})
|
|
2940
|
+
});
|
|
2917
2941
|
propsOnPinnedColumnsChange === null || propsOnPinnedColumnsChange === void 0 ? void 0 : propsOnPinnedColumnsChange(pinnedColumns, details);
|
|
2918
2942
|
},
|
|
2919
2943
|
pinnedColumns: pinnedColumnsModelRef.current,
|
|
@@ -2924,16 +2948,16 @@ const useStatefulTable = props => {
|
|
|
2924
2948
|
});
|
|
2925
2949
|
if (isDeepEqual(paginationModel, lastEmittedPaginationRef.current)) return;
|
|
2926
2950
|
lastEmittedPaginationRef.current = paginationModel;
|
|
2927
|
-
|
|
2951
|
+
writeUrl({
|
|
2928
2952
|
paginationModel
|
|
2929
|
-
})
|
|
2953
|
+
});
|
|
2930
2954
|
propsOnPaginationModelChange === null || propsOnPaginationModelChange === void 0 ? void 0 : propsOnPaginationModelChange(paginationModel, details);
|
|
2931
2955
|
},
|
|
2932
2956
|
columnVisibilityModel: visibilityModelRef.current,
|
|
2933
2957
|
onColumnVisibilityModelChange: (columnsVisibilityModel, details) => {
|
|
2934
|
-
|
|
2958
|
+
writeUrl({
|
|
2935
2959
|
columnsModel: columnsVisibilityModel
|
|
2936
|
-
})
|
|
2960
|
+
});
|
|
2937
2961
|
propsOnColumnVisibilityModelChange === null || propsOnColumnVisibilityModelChange === void 0 ? void 0 : propsOnColumnVisibilityModelChange(columnsVisibilityModel, details);
|
|
2938
2962
|
},
|
|
2939
2963
|
onColumnWidthChange: (params, event, details) => {
|
|
@@ -3002,7 +3026,7 @@ const CLASSNAME = 'redsift-datagrid';
|
|
|
3002
3026
|
|
|
3003
3027
|
const StatefulDataGrid = /*#__PURE__*/forwardRef((props, ref) => {
|
|
3004
3028
|
var _ref7;
|
|
3005
|
-
const datagridRef = ref || useRef();
|
|
3029
|
+
const datagridRef = ref || useRef(undefined);
|
|
3006
3030
|
const {
|
|
3007
3031
|
apiRef: propsApiRef,
|
|
3008
3032
|
autoHeight,
|
|
@@ -3058,8 +3082,10 @@ const StatefulDataGrid = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
3058
3082
|
// write-only onChange handlers for URL/localStorage persistence.
|
|
3059
3083
|
const isDataSourceMode = Boolean(dataSource);
|
|
3060
3084
|
const effectivePaginationMode = isDataSourceMode ? 'server' : paginationMode;
|
|
3061
|
-
|
|
3062
|
-
|
|
3085
|
+
// Default to 'client' rather than pass `undefined`: an explicit undefined replaces MUI's own default,
|
|
3086
|
+
// and MUI filters rows only when `filterMode === 'client'`, so no client-side filter ever applied.
|
|
3087
|
+
const effectiveFilterMode = isDataSourceMode ? 'server' : propsFilterMode !== null && propsFilterMode !== void 0 ? propsFilterMode : 'client';
|
|
3088
|
+
const effectiveSortingMode = isDataSourceMode ? 'server' : propsSortingMode !== null && propsSortingMode !== void 0 ? propsSortingMode : 'client';
|
|
3063
3089
|
const {
|
|
3064
3090
|
onColumnVisibilityModelChange: controlledOnColumnVisibilityModelChange,
|
|
3065
3091
|
onFilterModelChange: controlledOnFilterModelChange,
|