@mui/x-data-grid 8.0.0-alpha.3 → 8.0.0-alpha.4
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/CHANGELOG.md +274 -0
- package/DataGrid/DataGrid.js +5 -5
- package/README.md +1 -1
- package/components/GridRow.js +1 -1
- package/components/cell/GridActionsCell.js +8 -1
- package/components/cell/GridCell.js +1 -1
- package/components/panel/GridColumnsPanel.js +1 -2
- package/components/panel/GridPanelContent.js +7 -3
- package/components/panel/GridPanelFooter.d.ts +1 -1
- package/components/panel/GridPanelFooter.js +4 -3
- package/components/panel/filterPanel/GridFilterForm.js +15 -15
- package/constants/dataGridPropsDefaultValues.js +1 -1
- package/hooks/core/useGridStateInitialization.js +3 -3
- package/hooks/features/columnGrouping/gridColumnGroupsSelector.d.ts +4 -4
- package/hooks/features/columnResize/columnResizeSelector.d.ts +1 -1
- package/hooks/features/columns/gridColumnsSelector.d.ts +12 -12
- package/hooks/features/density/densitySelector.d.ts +1 -1
- package/hooks/features/filter/gridFilterSelector.d.ts +17 -17
- package/hooks/features/filter/useGridFilter.js +1 -1
- package/hooks/features/focus/gridFocusStateSelector.d.ts +8 -8
- package/hooks/features/headerFiltering/gridHeaderFilteringSelectors.d.ts +3 -3
- package/hooks/features/overlays/useGridOverlays.js +3 -1
- package/hooks/features/pagination/gridPaginationSelector.d.ts +15 -9
- package/hooks/features/rowSelection/gridRowSelectionSelector.d.ts +3 -3
- package/hooks/features/rowSelection/useGridRowSelection.js +5 -4
- package/hooks/features/rowSelection/utils.d.ts +1 -1
- package/hooks/features/rows/gridRowSpanningSelectors.d.ts +3 -3
- package/hooks/features/rows/gridRowsSelector.d.ts +23 -12
- package/hooks/features/rows/useGridRowSpanning.d.ts +1 -1
- package/hooks/features/rows/useGridRowSpanning.js +16 -8
- package/hooks/features/rows/useGridRows.js +5 -5
- package/hooks/features/sorting/gridSortingSelector.d.ts +10 -5
- package/hooks/features/sorting/gridSortingSelector.js +11 -0
- package/hooks/features/sorting/index.d.ts +2 -1
- package/hooks/features/sorting/index.js +1 -1
- package/hooks/features/sorting/useGridSorting.js +1 -1
- package/hooks/features/virtualization/gridVirtualizationSelectors.d.ts +5 -5
- package/hooks/features/virtualization/useGridVirtualScroller.js +11 -8
- package/hooks/utils/useGridSelector.d.ts +4 -6
- package/hooks/utils/useGridSelector.js +6 -44
- package/index.js +1 -1
- package/internals/index.d.ts +2 -2
- package/internals/index.js +2 -2
- package/locales/roRO.js +18 -20
- package/models/api/gridStateApi.d.ts +1 -1
- package/models/controlStateItem.d.ts +2 -2
- package/models/props/DataGridProps.d.ts +1 -1
- package/modern/DataGrid/DataGrid.js +5 -5
- package/modern/components/GridRow.js +1 -1
- package/modern/components/cell/GridActionsCell.js +8 -1
- package/modern/components/cell/GridCell.js +1 -1
- package/modern/components/panel/GridColumnsPanel.js +1 -2
- package/modern/components/panel/GridPanelContent.js +7 -3
- package/modern/components/panel/GridPanelFooter.js +4 -3
- package/modern/components/panel/filterPanel/GridFilterForm.js +15 -15
- package/modern/constants/dataGridPropsDefaultValues.js +1 -1
- package/modern/hooks/core/useGridStateInitialization.js +3 -3
- package/modern/hooks/features/filter/useGridFilter.js +1 -1
- package/modern/hooks/features/overlays/useGridOverlays.js +3 -1
- package/modern/hooks/features/rowSelection/useGridRowSelection.js +5 -4
- package/modern/hooks/features/rows/useGridRowSpanning.js +16 -8
- package/modern/hooks/features/rows/useGridRows.js +5 -5
- package/modern/hooks/features/sorting/gridSortingSelector.js +11 -0
- package/modern/hooks/features/sorting/index.js +1 -1
- package/modern/hooks/features/sorting/useGridSorting.js +1 -1
- package/modern/hooks/features/virtualization/useGridVirtualScroller.js +11 -8
- package/modern/hooks/utils/useGridSelector.js +6 -44
- package/modern/index.js +1 -1
- package/modern/internals/index.js +2 -2
- package/modern/locales/roRO.js +18 -20
- package/modern/utils/createSelector.js +1 -120
- package/node/DataGrid/DataGrid.js +5 -5
- package/node/components/GridRow.js +1 -1
- package/node/components/cell/GridActionsCell.js +8 -1
- package/node/components/cell/GridCell.js +1 -1
- package/node/components/panel/GridColumnsPanel.js +1 -2
- package/node/components/panel/GridPanelContent.js +7 -3
- package/node/components/panel/GridPanelFooter.js +5 -4
- package/node/components/panel/filterPanel/GridFilterForm.js +15 -15
- package/node/constants/dataGridPropsDefaultValues.js +1 -1
- package/node/hooks/core/useGridStateInitialization.js +3 -3
- package/node/hooks/features/filter/useGridFilter.js +1 -1
- package/node/hooks/features/overlays/useGridOverlays.js +3 -1
- package/node/hooks/features/rowSelection/useGridRowSelection.js +5 -4
- package/node/hooks/features/rows/useGridRowSpanning.js +16 -8
- package/node/hooks/features/rows/useGridRows.js +5 -5
- package/node/hooks/features/sorting/gridSortingSelector.js +12 -1
- package/node/hooks/features/sorting/index.js +24 -16
- package/node/hooks/features/sorting/useGridSorting.js +1 -1
- package/node/hooks/features/virtualization/useGridVirtualScroller.js +11 -8
- package/node/hooks/utils/useGridSelector.js +8 -47
- package/node/index.js +1 -1
- package/node/internals/index.js +8 -22
- package/node/locales/roRO.js +18 -20
- package/node/utils/createSelector.js +4 -125
- package/package.json +1 -1
- package/utils/createSelector.d.ts +4 -16
- package/utils/createSelector.js +1 -120
package/node/locales/roRO.js
CHANGED
|
@@ -30,16 +30,15 @@ const roROGrid = {
|
|
|
30
30
|
toolbarQuickFilterLabel: 'Căutare',
|
|
31
31
|
toolbarQuickFilterDeleteIconLabel: 'Ștergere',
|
|
32
32
|
// Prompt toolbar field
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
33
|
+
toolbarPromptControlPlaceholder: 'Scrie un prompt…',
|
|
34
|
+
toolbarPromptControlWithRecordingPlaceholder: 'Scrie sau înregistrează un prompt…',
|
|
35
|
+
toolbarPromptControlRecordingPlaceholder: 'Ascultare prompt…',
|
|
36
|
+
toolbarPromptControlLabel: 'Introducere prompt',
|
|
37
|
+
toolbarPromptControlRecordButtonDefaultLabel: 'Înregistrează',
|
|
38
|
+
toolbarPromptControlRecordButtonActiveLabel: 'Oprește înregistrare',
|
|
39
|
+
toolbarPromptControlSendActionLabel: 'Trimite',
|
|
40
|
+
toolbarPromptControlSendActionAriaLabel: 'Trimite prompt',
|
|
41
|
+
toolbarPromptControlErrorMessage: 'A apărut o eroare la procesare. Încercați din nou cu un alt prompt.',
|
|
43
42
|
// Export selector toolbar button text
|
|
44
43
|
toolbarExport: 'Export',
|
|
45
44
|
toolbarExportLabel: 'Export',
|
|
@@ -47,12 +46,11 @@ const roROGrid = {
|
|
|
47
46
|
toolbarExportPrint: 'Printare',
|
|
48
47
|
toolbarExportExcel: 'Download în format Excel',
|
|
49
48
|
// Columns management text
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
49
|
+
columnsManagementSearchTitle: 'Caută',
|
|
50
|
+
columnsManagementNoColumns: 'Nicio coloană',
|
|
51
|
+
columnsManagementShowHideAllText: 'Arată/Ascunde tot',
|
|
52
|
+
columnsManagementReset: 'Resetează',
|
|
53
|
+
columnsManagementDeleteIconLabel: 'Șterge',
|
|
56
54
|
// Filter panel text
|
|
57
55
|
filterPanelAddFilter: 'Adăugare filtru',
|
|
58
56
|
filterPanelRemoveAll: 'Șterge tot',
|
|
@@ -66,9 +64,9 @@ const roROGrid = {
|
|
|
66
64
|
filterPanelInputPlaceholder: 'Filtrare valoare',
|
|
67
65
|
// Filter operators text
|
|
68
66
|
filterOperatorContains: 'conține',
|
|
69
|
-
|
|
67
|
+
filterOperatorDoesNotContain: 'nu conține',
|
|
70
68
|
filterOperatorEquals: 'este egal cu',
|
|
71
|
-
|
|
69
|
+
filterOperatorDoesNotEqual: 'nu este egal cu',
|
|
72
70
|
filterOperatorStartsWith: 'începe cu',
|
|
73
71
|
filterOperatorEndsWith: 'se termină cu',
|
|
74
72
|
filterOperatorIs: 'este',
|
|
@@ -88,9 +86,9 @@ const roROGrid = {
|
|
|
88
86
|
'filterOperator<=': '<=',
|
|
89
87
|
// Header filter operators text
|
|
90
88
|
headerFilterOperatorContains: 'Conține',
|
|
91
|
-
|
|
89
|
+
headerFilterOperatorDoesNotContain: 'Nu conține',
|
|
92
90
|
headerFilterOperatorEquals: 'Egal cu',
|
|
93
|
-
|
|
91
|
+
headerFilterOperatorDoesNotEqual: 'Nu este egal cu',
|
|
94
92
|
headerFilterOperatorStartsWith: 'Începe cu',
|
|
95
93
|
headerFilterOperatorEndsWith: 'Se termină cu',
|
|
96
94
|
headerFilterOperatorIs: 'Este',
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.createSelectorMemoized = exports.createSelector = void 0;
|
|
7
7
|
var _reselect = require("reselect");
|
|
8
8
|
var _warning = require("@mui/x-internals/warning");
|
|
9
9
|
var _useGridSelector = require("../hooks/utils/useGridSelector");
|
|
@@ -14,19 +14,6 @@ const reselectCreateSelector = (0, _reselect.createSelectorCreator)({
|
|
|
14
14
|
equalityCheck: Object.is
|
|
15
15
|
}
|
|
16
16
|
});
|
|
17
|
-
|
|
18
|
-
// TODO v8: Remove this type
|
|
19
|
-
|
|
20
|
-
// TODO v8: Rename this type to `OutputSelector`
|
|
21
|
-
|
|
22
|
-
// TODO v8: Remove this type
|
|
23
|
-
|
|
24
|
-
// TODO v8: Rename this type to `SelectorArgs`
|
|
25
|
-
|
|
26
|
-
// TODO v8: Remove this type
|
|
27
|
-
|
|
28
|
-
// TODO v8: Rename this type to `CreateSelectorFunction`
|
|
29
|
-
|
|
30
17
|
const cache = new WeakMap();
|
|
31
18
|
function checkIsAPIRef(value) {
|
|
32
19
|
return 'current' in value && 'instanceId' in value.current;
|
|
@@ -34,84 +21,12 @@ function checkIsAPIRef(value) {
|
|
|
34
21
|
const DEFAULT_INSTANCE_ID = {
|
|
35
22
|
id: 'default'
|
|
36
23
|
};
|
|
37
|
-
|
|
38
|
-
// TODO v8: Remove this function
|
|
39
24
|
const createSelector = (a, b, c, d, e, f, ...other) => {
|
|
40
25
|
if (other.length > 0) {
|
|
41
26
|
throw new Error('Unsupported number of selectors');
|
|
42
27
|
}
|
|
43
28
|
let selector;
|
|
44
29
|
|
|
45
|
-
// eslint-disable-next-line id-denylist
|
|
46
|
-
if (a && b && c && d && e && f) {
|
|
47
|
-
selector = (stateOrApiRef, instanceIdParam) => {
|
|
48
|
-
const isAPIRef = checkIsAPIRef(stateOrApiRef);
|
|
49
|
-
const instanceId = instanceIdParam ?? (isAPIRef ? stateOrApiRef.current.instanceId : DEFAULT_INSTANCE_ID);
|
|
50
|
-
const state = isAPIRef ? stateOrApiRef.current.state : stateOrApiRef;
|
|
51
|
-
const va = a(state, instanceId);
|
|
52
|
-
const vb = b(state, instanceId);
|
|
53
|
-
const vc = c(state, instanceId);
|
|
54
|
-
const vd = d(state, instanceId);
|
|
55
|
-
const ve = e(state, instanceId);
|
|
56
|
-
return f(va, vb, vc, vd, ve);
|
|
57
|
-
};
|
|
58
|
-
// eslint-disable-next-line id-denylist
|
|
59
|
-
} else if (a && b && c && d && e) {
|
|
60
|
-
selector = (stateOrApiRef, instanceIdParam) => {
|
|
61
|
-
const isAPIRef = checkIsAPIRef(stateOrApiRef);
|
|
62
|
-
const instanceId = instanceIdParam ?? (isAPIRef ? stateOrApiRef.current.instanceId : DEFAULT_INSTANCE_ID);
|
|
63
|
-
const state = isAPIRef ? stateOrApiRef.current.state : stateOrApiRef;
|
|
64
|
-
const va = a(state, instanceId);
|
|
65
|
-
const vb = b(state, instanceId);
|
|
66
|
-
const vc = c(state, instanceId);
|
|
67
|
-
const vd = d(state, instanceId);
|
|
68
|
-
return e(va, vb, vc, vd);
|
|
69
|
-
};
|
|
70
|
-
} else if (a && b && c && d) {
|
|
71
|
-
selector = (stateOrApiRef, instanceIdParam) => {
|
|
72
|
-
const isAPIRef = checkIsAPIRef(stateOrApiRef);
|
|
73
|
-
const instanceId = instanceIdParam ?? (isAPIRef ? stateOrApiRef.current.instanceId : DEFAULT_INSTANCE_ID);
|
|
74
|
-
const state = isAPIRef ? stateOrApiRef.current.state : stateOrApiRef;
|
|
75
|
-
const va = a(state, instanceId);
|
|
76
|
-
const vb = b(state, instanceId);
|
|
77
|
-
const vc = c(state, instanceId);
|
|
78
|
-
return d(va, vb, vc);
|
|
79
|
-
};
|
|
80
|
-
} else if (a && b && c) {
|
|
81
|
-
selector = (stateOrApiRef, instanceIdParam) => {
|
|
82
|
-
const isAPIRef = checkIsAPIRef(stateOrApiRef);
|
|
83
|
-
const instanceId = instanceIdParam ?? (isAPIRef ? stateOrApiRef.current.instanceId : DEFAULT_INSTANCE_ID);
|
|
84
|
-
const state = isAPIRef ? stateOrApiRef.current.state : stateOrApiRef;
|
|
85
|
-
const va = a(state, instanceId);
|
|
86
|
-
const vb = b(state, instanceId);
|
|
87
|
-
return c(va, vb);
|
|
88
|
-
};
|
|
89
|
-
} else if (a && b) {
|
|
90
|
-
selector = (stateOrApiRef, instanceIdParam) => {
|
|
91
|
-
const isAPIRef = checkIsAPIRef(stateOrApiRef);
|
|
92
|
-
const instanceId = instanceIdParam ?? (isAPIRef ? stateOrApiRef.current.instanceId : DEFAULT_INSTANCE_ID);
|
|
93
|
-
const state = isAPIRef ? stateOrApiRef.current.state : stateOrApiRef;
|
|
94
|
-
const va = a(state, instanceId);
|
|
95
|
-
return b(va);
|
|
96
|
-
};
|
|
97
|
-
} else {
|
|
98
|
-
throw new Error('Missing arguments');
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// We use this property to detect if the selector was created with createSelector
|
|
102
|
-
// or it's only a simple function the receives the state and returns part of it.
|
|
103
|
-
selector.acceptsApiRef = true;
|
|
104
|
-
return selector;
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
// TODO v8: Rename this function to `createSelector`
|
|
108
|
-
exports.createSelector = createSelector;
|
|
109
|
-
const createSelectorV8 = (a, b, c, d, e, f, ...other) => {
|
|
110
|
-
if (other.length > 0) {
|
|
111
|
-
throw new Error('Unsupported number of selectors');
|
|
112
|
-
}
|
|
113
|
-
let selector;
|
|
114
|
-
|
|
115
30
|
// eslint-disable-next-line id-denylist
|
|
116
31
|
if (a && b && c && d && e && f) {
|
|
117
32
|
selector = (stateOrApiRef, args, instanceIdParam) => {
|
|
@@ -173,51 +88,15 @@ const createSelectorV8 = (a, b, c, d, e, f, ...other) => {
|
|
|
173
88
|
selector.acceptsApiRef = true;
|
|
174
89
|
return selector;
|
|
175
90
|
};
|
|
176
|
-
|
|
177
|
-
// TODO v8: Remove this function
|
|
178
|
-
exports.createSelectorV8 = createSelectorV8;
|
|
91
|
+
exports.createSelector = createSelector;
|
|
179
92
|
const createSelectorMemoized = (...args) => {
|
|
180
|
-
const selector = (stateOrApiRef, instanceId) => {
|
|
181
|
-
const isAPIRef = checkIsAPIRef(stateOrApiRef);
|
|
182
|
-
const cacheKey = isAPIRef ? stateOrApiRef.current.instanceId : instanceId ?? DEFAULT_INSTANCE_ID;
|
|
183
|
-
const state = isAPIRef ? stateOrApiRef.current.state : stateOrApiRef;
|
|
184
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
185
|
-
if (cacheKey.id === 'default') {
|
|
186
|
-
(0, _warning.warnOnce)(['MUI X: A selector was called without passing the instance ID, which may impact the performance of the grid.', 'To fix, call it with `apiRef`, for example `mySelector(apiRef)`, or pass the instance ID explicitly, for example `mySelector(state, apiRef.current.instanceId)`.']);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
const cacheArgsInit = cache.get(cacheKey);
|
|
190
|
-
const cacheArgs = cacheArgsInit ?? new Map();
|
|
191
|
-
const cacheFn = cacheArgs?.get(args);
|
|
192
|
-
if (cacheArgs && cacheFn) {
|
|
193
|
-
// We pass the cache key because the called selector might have as
|
|
194
|
-
// dependency another selector created with this `createSelector`.
|
|
195
|
-
return cacheFn(state, cacheKey);
|
|
196
|
-
}
|
|
197
|
-
const fn = reselectCreateSelector(...args);
|
|
198
|
-
if (!cacheArgsInit) {
|
|
199
|
-
cache.set(cacheKey, cacheArgs);
|
|
200
|
-
}
|
|
201
|
-
cacheArgs.set(args, fn);
|
|
202
|
-
return fn(state, cacheKey);
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
// We use this property to detect if the selector was created with createSelector
|
|
206
|
-
// or it's only a simple function the receives the state and returns part of it.
|
|
207
|
-
selector.acceptsApiRef = true;
|
|
208
|
-
return selector;
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
// TODO v8: Rename this function to `createSelectorMemoized`
|
|
212
|
-
exports.createSelectorMemoized = createSelectorMemoized;
|
|
213
|
-
const createSelectorMemoizedV8 = (...args) => {
|
|
214
93
|
const selector = (stateOrApiRef, selectorArgs, instanceId) => {
|
|
215
94
|
const isAPIRef = checkIsAPIRef(stateOrApiRef);
|
|
216
95
|
const cacheKey = isAPIRef ? stateOrApiRef.current.instanceId : instanceId ?? DEFAULT_INSTANCE_ID;
|
|
217
96
|
const state = isAPIRef ? stateOrApiRef.current.state : stateOrApiRef;
|
|
218
97
|
if (process.env.NODE_ENV !== 'production') {
|
|
219
98
|
if (cacheKey.id === 'default') {
|
|
220
|
-
(0, _warning.warnOnce)(['MUI X: A selector was called without passing the instance ID, which may impact the performance of the grid.', 'To fix, call it with `apiRef`, for example `mySelector(apiRef)`, or pass the instance ID explicitly, for example `mySelector(state, apiRef.current.instanceId)`.']);
|
|
99
|
+
(0, _warning.warnOnce)(['MUI X: A selector was called without passing the instance ID, which may impact the performance of the grid.', 'To fix, call it with `apiRef`, for example `mySelector(apiRef)`, or pass the instance ID explicitly, for example `mySelector(state, args, apiRef.current.instanceId)`.']);
|
|
221
100
|
}
|
|
222
101
|
}
|
|
223
102
|
const cacheArgsInit = cache.get(cacheKey);
|
|
@@ -250,4 +129,4 @@ const createSelectorMemoizedV8 = (...args) => {
|
|
|
250
129
|
selector.acceptsApiRef = true;
|
|
251
130
|
return selector;
|
|
252
131
|
};
|
|
253
|
-
exports.
|
|
132
|
+
exports.createSelectorMemoized = createSelectorMemoized;
|
package/package.json
CHANGED
|
@@ -1,20 +1,12 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { Selector, SelectorResultArray } from 'reselect';
|
|
3
3
|
import type { GridCoreApi } from '../models/api/gridCoreApi';
|
|
4
|
-
export interface OutputSelector<State, Result> {
|
|
5
|
-
(apiRef: React.MutableRefObject<{
|
|
6
|
-
state: State;
|
|
7
|
-
instanceId: GridCoreApi['instanceId'];
|
|
8
|
-
}>): Result;
|
|
9
|
-
(state: State, instanceId: GridCoreApi['instanceId']): Result;
|
|
10
|
-
acceptsApiRef: boolean;
|
|
11
|
-
}
|
|
12
|
-
export interface OutputSelectorV8<State, Args, Result> {
|
|
4
|
+
export interface OutputSelector<State, Args, Result> {
|
|
13
5
|
(apiRef: React.MutableRefObject<{
|
|
14
6
|
state: State;
|
|
15
7
|
instanceId: GridCoreApi['instanceId'];
|
|
16
8
|
}>, args?: Args): Result;
|
|
17
|
-
(state: State, instanceId
|
|
9
|
+
(state: State, args?: Args, instanceId?: GridCoreApi['instanceId']): Result;
|
|
18
10
|
acceptsApiRef: boolean;
|
|
19
11
|
}
|
|
20
12
|
type StateFromSelector<T> = T extends (first: infer F, ...args: any[]) => any ? F extends {
|
|
@@ -24,19 +16,15 @@ type StateFromSelectorList<Selectors extends readonly any[]> = Selectors extends
|
|
|
24
16
|
f: infer F,
|
|
25
17
|
...other: infer R
|
|
26
18
|
] ? StateFromSelector<F> extends StateFromSelectorList<R> ? StateFromSelector<F> : StateFromSelectorList<R> : {};
|
|
27
|
-
type SelectorArgs<Selectors extends ReadonlyArray<Selector<any>>, Result> = [selectors: [...Selectors], combiner: (...args: SelectorResultArray<Selectors>) => Result] | [...Selectors, (...args: SelectorResultArray<Selectors>) => Result];
|
|
28
19
|
type SelectorResultArrayWithArgs<Selectors extends ReadonlyArray<Selector<any>>, Args> = [
|
|
29
20
|
...SelectorResultArray<Selectors>,
|
|
30
21
|
Args
|
|
31
22
|
];
|
|
32
|
-
type
|
|
23
|
+
type SelectorArgs<Selectors extends ReadonlyArray<Selector<any>>, Args, Result> = [
|
|
33
24
|
selectors: [...Selectors],
|
|
34
25
|
combiner: (...args: SelectorResultArrayWithArgs<Selectors, Args>) => Result
|
|
35
26
|
] | [...Selectors, (...args: SelectorResultArrayWithArgs<Selectors, Args>) => Result];
|
|
36
|
-
type CreateSelectorFunction = <Selectors extends ReadonlyArray<Selector<any>>, Result>(...items: SelectorArgs<Selectors, Result>) => OutputSelector<StateFromSelectorList<Selectors>, Result>;
|
|
37
|
-
type CreateSelectorFunctionV8 = <Selectors extends ReadonlyArray<Selector<any>>, Args, Result>(...items: SelectorArgsV8<Selectors, Args, Result>) => OutputSelectorV8<StateFromSelectorList<Selectors>, Args, Result>;
|
|
27
|
+
type CreateSelectorFunction = <Selectors extends ReadonlyArray<Selector<any>>, Args, Result>(...items: SelectorArgs<Selectors, Args, Result>) => OutputSelector<StateFromSelectorList<Selectors>, Args, Result>;
|
|
38
28
|
export declare const createSelector: CreateSelectorFunction;
|
|
39
|
-
export declare const createSelectorV8: CreateSelectorFunctionV8;
|
|
40
29
|
export declare const createSelectorMemoized: CreateSelectorFunction;
|
|
41
|
-
export declare const createSelectorMemoizedV8: CreateSelectorFunctionV8;
|
|
42
30
|
export {};
|
package/utils/createSelector.js
CHANGED
|
@@ -8,19 +8,6 @@ const reselectCreateSelector = createSelectorCreator({
|
|
|
8
8
|
equalityCheck: Object.is
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
|
|
12
|
-
// TODO v8: Remove this type
|
|
13
|
-
|
|
14
|
-
// TODO v8: Rename this type to `OutputSelector`
|
|
15
|
-
|
|
16
|
-
// TODO v8: Remove this type
|
|
17
|
-
|
|
18
|
-
// TODO v8: Rename this type to `SelectorArgs`
|
|
19
|
-
|
|
20
|
-
// TODO v8: Remove this type
|
|
21
|
-
|
|
22
|
-
// TODO v8: Rename this type to `CreateSelectorFunction`
|
|
23
|
-
|
|
24
11
|
const cache = new WeakMap();
|
|
25
12
|
function checkIsAPIRef(value) {
|
|
26
13
|
return 'current' in value && 'instanceId' in value.current;
|
|
@@ -28,83 +15,12 @@ function checkIsAPIRef(value) {
|
|
|
28
15
|
const DEFAULT_INSTANCE_ID = {
|
|
29
16
|
id: 'default'
|
|
30
17
|
};
|
|
31
|
-
|
|
32
|
-
// TODO v8: Remove this function
|
|
33
18
|
export const createSelector = (a, b, c, d, e, f, ...other) => {
|
|
34
19
|
if (other.length > 0) {
|
|
35
20
|
throw new Error('Unsupported number of selectors');
|
|
36
21
|
}
|
|
37
22
|
let selector;
|
|
38
23
|
|
|
39
|
-
// eslint-disable-next-line id-denylist
|
|
40
|
-
if (a && b && c && d && e && f) {
|
|
41
|
-
selector = (stateOrApiRef, instanceIdParam) => {
|
|
42
|
-
const isAPIRef = checkIsAPIRef(stateOrApiRef);
|
|
43
|
-
const instanceId = instanceIdParam ?? (isAPIRef ? stateOrApiRef.current.instanceId : DEFAULT_INSTANCE_ID);
|
|
44
|
-
const state = isAPIRef ? stateOrApiRef.current.state : stateOrApiRef;
|
|
45
|
-
const va = a(state, instanceId);
|
|
46
|
-
const vb = b(state, instanceId);
|
|
47
|
-
const vc = c(state, instanceId);
|
|
48
|
-
const vd = d(state, instanceId);
|
|
49
|
-
const ve = e(state, instanceId);
|
|
50
|
-
return f(va, vb, vc, vd, ve);
|
|
51
|
-
};
|
|
52
|
-
// eslint-disable-next-line id-denylist
|
|
53
|
-
} else if (a && b && c && d && e) {
|
|
54
|
-
selector = (stateOrApiRef, instanceIdParam) => {
|
|
55
|
-
const isAPIRef = checkIsAPIRef(stateOrApiRef);
|
|
56
|
-
const instanceId = instanceIdParam ?? (isAPIRef ? stateOrApiRef.current.instanceId : DEFAULT_INSTANCE_ID);
|
|
57
|
-
const state = isAPIRef ? stateOrApiRef.current.state : stateOrApiRef;
|
|
58
|
-
const va = a(state, instanceId);
|
|
59
|
-
const vb = b(state, instanceId);
|
|
60
|
-
const vc = c(state, instanceId);
|
|
61
|
-
const vd = d(state, instanceId);
|
|
62
|
-
return e(va, vb, vc, vd);
|
|
63
|
-
};
|
|
64
|
-
} else if (a && b && c && d) {
|
|
65
|
-
selector = (stateOrApiRef, instanceIdParam) => {
|
|
66
|
-
const isAPIRef = checkIsAPIRef(stateOrApiRef);
|
|
67
|
-
const instanceId = instanceIdParam ?? (isAPIRef ? stateOrApiRef.current.instanceId : DEFAULT_INSTANCE_ID);
|
|
68
|
-
const state = isAPIRef ? stateOrApiRef.current.state : stateOrApiRef;
|
|
69
|
-
const va = a(state, instanceId);
|
|
70
|
-
const vb = b(state, instanceId);
|
|
71
|
-
const vc = c(state, instanceId);
|
|
72
|
-
return d(va, vb, vc);
|
|
73
|
-
};
|
|
74
|
-
} else if (a && b && c) {
|
|
75
|
-
selector = (stateOrApiRef, instanceIdParam) => {
|
|
76
|
-
const isAPIRef = checkIsAPIRef(stateOrApiRef);
|
|
77
|
-
const instanceId = instanceIdParam ?? (isAPIRef ? stateOrApiRef.current.instanceId : DEFAULT_INSTANCE_ID);
|
|
78
|
-
const state = isAPIRef ? stateOrApiRef.current.state : stateOrApiRef;
|
|
79
|
-
const va = a(state, instanceId);
|
|
80
|
-
const vb = b(state, instanceId);
|
|
81
|
-
return c(va, vb);
|
|
82
|
-
};
|
|
83
|
-
} else if (a && b) {
|
|
84
|
-
selector = (stateOrApiRef, instanceIdParam) => {
|
|
85
|
-
const isAPIRef = checkIsAPIRef(stateOrApiRef);
|
|
86
|
-
const instanceId = instanceIdParam ?? (isAPIRef ? stateOrApiRef.current.instanceId : DEFAULT_INSTANCE_ID);
|
|
87
|
-
const state = isAPIRef ? stateOrApiRef.current.state : stateOrApiRef;
|
|
88
|
-
const va = a(state, instanceId);
|
|
89
|
-
return b(va);
|
|
90
|
-
};
|
|
91
|
-
} else {
|
|
92
|
-
throw new Error('Missing arguments');
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// We use this property to detect if the selector was created with createSelector
|
|
96
|
-
// or it's only a simple function the receives the state and returns part of it.
|
|
97
|
-
selector.acceptsApiRef = true;
|
|
98
|
-
return selector;
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
// TODO v8: Rename this function to `createSelector`
|
|
102
|
-
export const createSelectorV8 = (a, b, c, d, e, f, ...other) => {
|
|
103
|
-
if (other.length > 0) {
|
|
104
|
-
throw new Error('Unsupported number of selectors');
|
|
105
|
-
}
|
|
106
|
-
let selector;
|
|
107
|
-
|
|
108
24
|
// eslint-disable-next-line id-denylist
|
|
109
25
|
if (a && b && c && d && e && f) {
|
|
110
26
|
selector = (stateOrApiRef, args, instanceIdParam) => {
|
|
@@ -166,49 +82,14 @@ export const createSelectorV8 = (a, b, c, d, e, f, ...other) => {
|
|
|
166
82
|
selector.acceptsApiRef = true;
|
|
167
83
|
return selector;
|
|
168
84
|
};
|
|
169
|
-
|
|
170
|
-
// TODO v8: Remove this function
|
|
171
85
|
export const createSelectorMemoized = (...args) => {
|
|
172
|
-
const selector = (stateOrApiRef, instanceId) => {
|
|
173
|
-
const isAPIRef = checkIsAPIRef(stateOrApiRef);
|
|
174
|
-
const cacheKey = isAPIRef ? stateOrApiRef.current.instanceId : instanceId ?? DEFAULT_INSTANCE_ID;
|
|
175
|
-
const state = isAPIRef ? stateOrApiRef.current.state : stateOrApiRef;
|
|
176
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
177
|
-
if (cacheKey.id === 'default') {
|
|
178
|
-
warnOnce(['MUI X: A selector was called without passing the instance ID, which may impact the performance of the grid.', 'To fix, call it with `apiRef`, for example `mySelector(apiRef)`, or pass the instance ID explicitly, for example `mySelector(state, apiRef.current.instanceId)`.']);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
const cacheArgsInit = cache.get(cacheKey);
|
|
182
|
-
const cacheArgs = cacheArgsInit ?? new Map();
|
|
183
|
-
const cacheFn = cacheArgs?.get(args);
|
|
184
|
-
if (cacheArgs && cacheFn) {
|
|
185
|
-
// We pass the cache key because the called selector might have as
|
|
186
|
-
// dependency another selector created with this `createSelector`.
|
|
187
|
-
return cacheFn(state, cacheKey);
|
|
188
|
-
}
|
|
189
|
-
const fn = reselectCreateSelector(...args);
|
|
190
|
-
if (!cacheArgsInit) {
|
|
191
|
-
cache.set(cacheKey, cacheArgs);
|
|
192
|
-
}
|
|
193
|
-
cacheArgs.set(args, fn);
|
|
194
|
-
return fn(state, cacheKey);
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
// We use this property to detect if the selector was created with createSelector
|
|
198
|
-
// or it's only a simple function the receives the state and returns part of it.
|
|
199
|
-
selector.acceptsApiRef = true;
|
|
200
|
-
return selector;
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
// TODO v8: Rename this function to `createSelectorMemoized`
|
|
204
|
-
export const createSelectorMemoizedV8 = (...args) => {
|
|
205
86
|
const selector = (stateOrApiRef, selectorArgs, instanceId) => {
|
|
206
87
|
const isAPIRef = checkIsAPIRef(stateOrApiRef);
|
|
207
88
|
const cacheKey = isAPIRef ? stateOrApiRef.current.instanceId : instanceId ?? DEFAULT_INSTANCE_ID;
|
|
208
89
|
const state = isAPIRef ? stateOrApiRef.current.state : stateOrApiRef;
|
|
209
90
|
if (process.env.NODE_ENV !== 'production') {
|
|
210
91
|
if (cacheKey.id === 'default') {
|
|
211
|
-
warnOnce(['MUI X: A selector was called without passing the instance ID, which may impact the performance of the grid.', 'To fix, call it with `apiRef`, for example `mySelector(apiRef)`, or pass the instance ID explicitly, for example `mySelector(state, apiRef.current.instanceId)`.']);
|
|
92
|
+
warnOnce(['MUI X: A selector was called without passing the instance ID, which may impact the performance of the grid.', 'To fix, call it with `apiRef`, for example `mySelector(apiRef)`, or pass the instance ID explicitly, for example `mySelector(state, args, apiRef.current.instanceId)`.']);
|
|
212
93
|
}
|
|
213
94
|
}
|
|
214
95
|
const cacheArgsInit = cache.get(cacheKey);
|