@mui/x-data-grid 6.11.1 → 6.12.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/CHANGELOG.md +154 -31
- package/DataGrid/DataGrid.d.ts +10 -0
- package/DataGrid/DataGrid.js +24 -1
- package/DataGrid/useDataGridProps.js +2 -0
- package/README.md +1 -1
- package/components/cell/GridActionsCell.js +1 -1
- package/components/cell/GridEditSingleSelectCell.js +1 -1
- package/components/columnHeaders/GridColumnGroupHeader.js +1 -1
- package/components/columnHeaders/GridColumnHeaderItem.js +1 -1
- package/components/columnHeaders/GridGenericColumnHeaderItem.js +1 -1
- package/components/columnSelection/GridCellCheckboxRenderer.js +1 -1
- package/components/panel/GridPanel.d.ts +1 -1
- package/components/panel/filterPanel/GridFilterForm.js +1 -1
- package/components/panel/filterPanel/GridFilterInputDate.d.ts +0 -1
- package/components/panel/filterPanel/GridFilterInputDate.js +5 -11
- package/components/panel/filterPanel/GridFilterInputValue.d.ts +0 -1
- package/components/panel/filterPanel/GridFilterInputValue.js +16 -18
- package/components/panel/filterPanel/GridFilterPanel.js +1 -3
- package/components/toolbar/GridToolbarColumnsButton.js +1 -1
- package/components/toolbar/GridToolbarDensitySelector.js +1 -1
- package/components/toolbar/GridToolbarExport.js +2 -2
- package/components/toolbar/GridToolbarExportContainer.js +1 -1
- package/components/toolbar/GridToolbarFilterButton.js +1 -1
- package/components/toolbar/GridToolbarQuickFilter.d.ts +1 -1
- package/components/toolbar/GridToolbarQuickFilter.js +5 -5
- package/hooks/features/export/useGridPrintExport.js +11 -8
- package/hooks/features/export/utils.js +7 -1
- package/hooks/features/filter/gridFilterUtils.d.ts +2 -2
- package/hooks/features/filter/gridFilterUtils.js +23 -19
- package/hooks/features/filter/useGridFilter.d.ts +1 -1
- package/hooks/features/filter/useGridFilter.js +2 -2
- package/hooks/features/pagination/useGridPagination.d.ts +5 -0
- package/hooks/features/pagination/useGridPagination.js +1 -1
- package/hooks/features/rowSelection/useGridRowSelection.js +1 -1
- package/hooks/features/rows/useGridRows.js +11 -0
- package/hooks/features/rows/useGridRowsMeta.js +2 -2
- package/hooks/utils/useGridApiEventHandler.js +5 -5
- package/hooks/utils/useLazyRef.js +2 -0
- package/hooks/utils/useTimeout.d.ts +9 -0
- package/hooks/utils/useTimeout.js +28 -0
- package/index.js +1 -1
- package/joy/joySlots.js +2 -2
- package/legacy/DataGrid/DataGrid.js +24 -1
- package/legacy/DataGrid/useDataGridProps.js +2 -0
- package/legacy/components/cell/GridActionsCell.js +1 -1
- package/legacy/components/cell/GridEditSingleSelectCell.js +1 -1
- package/legacy/components/columnHeaders/GridColumnGroupHeader.js +1 -1
- package/legacy/components/columnHeaders/GridColumnHeaderItem.js +1 -1
- package/legacy/components/columnHeaders/GridGenericColumnHeaderItem.js +1 -1
- package/legacy/components/columnSelection/GridCellCheckboxRenderer.js +1 -1
- package/legacy/components/panel/filterPanel/GridFilterForm.js +1 -1
- package/legacy/components/panel/filterPanel/GridFilterInputDate.js +5 -11
- package/legacy/components/panel/filterPanel/GridFilterInputValue.js +16 -18
- package/legacy/components/panel/filterPanel/GridFilterPanel.js +1 -3
- package/legacy/components/toolbar/GridToolbarColumnsButton.js +1 -1
- package/legacy/components/toolbar/GridToolbarDensitySelector.js +1 -1
- package/legacy/components/toolbar/GridToolbarExport.js +2 -2
- package/legacy/components/toolbar/GridToolbarExportContainer.js +1 -1
- package/legacy/components/toolbar/GridToolbarFilterButton.js +1 -1
- package/legacy/components/toolbar/GridToolbarQuickFilter.js +5 -5
- package/legacy/hooks/features/export/useGridPrintExport.js +12 -9
- package/legacy/hooks/features/export/utils.js +8 -6
- package/legacy/hooks/features/filter/gridFilterUtils.js +23 -19
- package/legacy/hooks/features/filter/useGridFilter.js +2 -2
- package/legacy/hooks/features/pagination/useGridPagination.js +1 -1
- package/legacy/hooks/features/rowSelection/useGridRowSelection.js +1 -1
- package/legacy/hooks/features/rows/useGridRows.js +11 -0
- package/legacy/hooks/features/rows/useGridRowsMeta.js +2 -2
- package/legacy/hooks/utils/useGridApiEventHandler.js +5 -5
- package/legacy/hooks/utils/useLazyRef.js +2 -0
- package/legacy/hooks/utils/useTimeout.js +38 -0
- package/legacy/index.js +1 -1
- package/legacy/joy/joySlots.js +2 -2
- package/legacy/locales/esES.js +26 -28
- package/legacy/locales/ukUA.js +25 -27
- package/legacy/locales/zhCN.js +25 -27
- package/legacy/locales/zhTW.js +34 -38
- package/legacy/utils/createSelector.js +1 -1
- package/locales/esES.js +26 -28
- package/locales/ukUA.js +25 -27
- package/locales/zhCN.js +25 -27
- package/locales/zhTW.js +34 -38
- package/models/api/gridRowApi.d.ts +6 -0
- package/models/props/DataGridProps.d.ts +11 -0
- package/modern/DataGrid/DataGrid.js +24 -1
- package/modern/DataGrid/useDataGridProps.js +2 -0
- package/modern/components/panel/filterPanel/GridFilterInputDate.js +5 -11
- package/modern/components/panel/filterPanel/GridFilterInputValue.js +15 -17
- package/modern/components/panel/filterPanel/GridFilterPanel.js +1 -3
- package/modern/components/toolbar/GridToolbarQuickFilter.js +5 -5
- package/modern/hooks/features/export/useGridPrintExport.js +9 -6
- package/modern/hooks/features/export/utils.js +7 -1
- package/modern/hooks/features/filter/gridFilterUtils.js +23 -19
- package/modern/hooks/features/filter/useGridFilter.js +2 -2
- package/modern/hooks/features/pagination/useGridPagination.js +1 -1
- package/modern/hooks/features/rows/useGridRows.js +11 -0
- package/modern/hooks/utils/useLazyRef.js +2 -0
- package/modern/hooks/utils/useTimeout.js +28 -0
- package/modern/index.js +1 -1
- package/modern/locales/esES.js +26 -28
- package/modern/locales/ukUA.js +25 -27
- package/modern/locales/zhCN.js +25 -27
- package/modern/locales/zhTW.js +34 -38
- package/node/DataGrid/DataGrid.js +26 -1
- package/node/DataGrid/useDataGridProps.js +2 -0
- package/node/components/panel/filterPanel/GridFilterInputDate.js +5 -13
- package/node/components/panel/filterPanel/GridFilterInputValue.js +15 -19
- package/node/components/panel/filterPanel/GridFilterPanel.js +1 -3
- package/node/components/toolbar/GridToolbarQuickFilter.js +5 -5
- package/node/hooks/features/export/useGridPrintExport.js +9 -6
- package/node/hooks/features/export/utils.js +7 -1
- package/node/hooks/features/filter/gridFilterUtils.js +23 -19
- package/node/hooks/features/filter/useGridFilter.js +2 -2
- package/node/hooks/features/pagination/useGridPagination.js +2 -1
- package/node/hooks/features/rows/useGridRows.js +11 -0
- package/node/hooks/utils/useLazyRef.js +2 -0
- package/node/hooks/utils/useTimeout.js +34 -0
- package/node/index.js +1 -1
- package/node/locales/esES.js +26 -28
- package/node/locales/ukUA.js +25 -27
- package/node/locales/zhCN.js +25 -27
- package/node/locales/zhTW.js +34 -38
- package/package.json +3 -3
- package/utils/createSelector.js +1 -1
package/modern/locales/zhCN.js
CHANGED
|
@@ -60,34 +60,32 @@ const zhCNGrid = {
|
|
|
60
60
|
filterOperatorIsEmpty: '为空',
|
|
61
61
|
filterOperatorIsNotEmpty: '不为空',
|
|
62
62
|
filterOperatorIsAnyOf: '属于',
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
63
|
+
'filterOperator=': '=',
|
|
64
|
+
'filterOperator!=': '!=',
|
|
65
|
+
'filterOperator>': '>',
|
|
66
|
+
'filterOperator>=': '>=',
|
|
67
|
+
'filterOperator<': '<',
|
|
68
|
+
'filterOperator<=': '<=',
|
|
70
69
|
// Header filter operators text
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
70
|
+
headerFilterOperatorContains: '包含',
|
|
71
|
+
headerFilterOperatorEquals: '等于',
|
|
72
|
+
headerFilterOperatorStartsWith: '开始于',
|
|
73
|
+
headerFilterOperatorEndsWith: '结束于',
|
|
74
|
+
headerFilterOperatorIs: '是',
|
|
75
|
+
headerFilterOperatorNot: '不是',
|
|
76
|
+
headerFilterOperatorAfter: '在后面',
|
|
77
|
+
headerFilterOperatorOnOrAfter: '在当前或后面',
|
|
78
|
+
headerFilterOperatorBefore: '在前面',
|
|
79
|
+
headerFilterOperatorOnOrBefore: '在当前或前面',
|
|
80
|
+
headerFilterOperatorIsEmpty: '为空',
|
|
81
|
+
headerFilterOperatorIsNotEmpty: '不为空',
|
|
82
|
+
headerFilterOperatorIsAnyOf: '属于',
|
|
83
|
+
'headerFilterOperator=': '等于',
|
|
84
|
+
'headerFilterOperator!=': '不等于',
|
|
85
|
+
'headerFilterOperator>': '大于',
|
|
86
|
+
'headerFilterOperator>=': '大于或等于',
|
|
87
|
+
'headerFilterOperator<': '小雨',
|
|
88
|
+
'headerFilterOperator<=': '小于或等于',
|
|
91
89
|
// Filter values text
|
|
92
90
|
filterValueAny: '任何',
|
|
93
91
|
filterValueTrue: '真',
|
package/modern/locales/zhTW.js
CHANGED
|
@@ -37,7 +37,7 @@ const zhTWGrid = {
|
|
|
37
37
|
columnsPanelHideAllButton: '隱藏所有',
|
|
38
38
|
// Filter panel text
|
|
39
39
|
filterPanelAddFilter: '增加篩選器',
|
|
40
|
-
|
|
40
|
+
filterPanelRemoveAll: '清除所有',
|
|
41
41
|
filterPanelDeleteIconLabel: '刪除',
|
|
42
42
|
filterPanelLogicOperator: '邏輯運算子',
|
|
43
43
|
filterPanelOperator: '運算子',
|
|
@@ -60,34 +60,32 @@ const zhTWGrid = {
|
|
|
60
60
|
filterOperatorIsEmpty: '為空',
|
|
61
61
|
filterOperatorIsNotEmpty: '不為空',
|
|
62
62
|
filterOperatorIsAnyOf: '是其中之一',
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
63
|
+
'filterOperator=': '=',
|
|
64
|
+
'filterOperator!=': '!=',
|
|
65
|
+
'filterOperator>': '>',
|
|
66
|
+
'filterOperator>=': '>=',
|
|
67
|
+
'filterOperator<': '<',
|
|
68
|
+
'filterOperator<=': '<=',
|
|
70
69
|
// Header filter operators text
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
70
|
+
headerFilterOperatorContains: '包含',
|
|
71
|
+
headerFilterOperatorEquals: '等於',
|
|
72
|
+
headerFilterOperatorStartsWith: '以...開頭',
|
|
73
|
+
headerFilterOperatorEndsWith: '以...結束',
|
|
74
|
+
headerFilterOperatorIs: '為',
|
|
75
|
+
headerFilterOperatorNot: '不為',
|
|
76
|
+
headerFilterOperatorAfter: '...之後',
|
|
77
|
+
headerFilterOperatorOnOrAfter: '...(含)之後',
|
|
78
|
+
headerFilterOperatorBefore: '...之前',
|
|
79
|
+
headerFilterOperatorOnOrBefore: '...(含)之前',
|
|
80
|
+
headerFilterOperatorIsEmpty: '為空',
|
|
81
|
+
headerFilterOperatorIsNotEmpty: '不為空',
|
|
82
|
+
headerFilterOperatorIsAnyOf: '是其中之一',
|
|
83
|
+
'headerFilterOperator=': '等於',
|
|
84
|
+
'headerFilterOperator!=': '不等於',
|
|
85
|
+
'headerFilterOperator>': '大於',
|
|
86
|
+
'headerFilterOperator>=': '大於或等於',
|
|
87
|
+
'headerFilterOperator<': '小於',
|
|
88
|
+
'headerFilterOperator<=': '小於或等於',
|
|
91
89
|
// Filter values text
|
|
92
90
|
filterValueAny: '任何值',
|
|
93
91
|
filterValueTrue: '真',
|
|
@@ -95,7 +93,7 @@ const zhTWGrid = {
|
|
|
95
93
|
// Column menu text
|
|
96
94
|
columnMenuLabel: '選單',
|
|
97
95
|
columnMenuShowColumns: '顯示欄位',
|
|
98
|
-
|
|
96
|
+
columnMenuManageColumns: '管理欄位',
|
|
99
97
|
columnMenuFilter: '篩選器',
|
|
100
98
|
columnMenuHideColumn: '隱藏',
|
|
101
99
|
columnMenuUnsort: '預設排序',
|
|
@@ -139,15 +137,13 @@ const zhTWGrid = {
|
|
|
139
137
|
expandDetailPanel: '展開',
|
|
140
138
|
collapseDetailPanel: '摺疊',
|
|
141
139
|
// Row reordering text
|
|
142
|
-
rowReorderingHeaderName: '排序'
|
|
143
|
-
|
|
140
|
+
rowReorderingHeaderName: '排序',
|
|
144
141
|
// Aggregation
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
142
|
+
aggregationMenuItemHeader: '集合',
|
|
143
|
+
aggregationFunctionLabelSum: '總數',
|
|
144
|
+
aggregationFunctionLabelAvg: '平均數',
|
|
145
|
+
aggregationFunctionLabelMin: '最小',
|
|
146
|
+
aggregationFunctionLabelMax: '最大',
|
|
147
|
+
aggregationFunctionLabelSize: '尺寸'
|
|
151
148
|
};
|
|
152
|
-
|
|
153
149
|
export const zhTW = getGridLocalization(zhTWGrid, zhTWCore);
|
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.DataGrid = void 0;
|
|
7
|
+
exports.SUBMIT_FILTER_STROKE_TIME = exports.SUBMIT_FILTER_DATE_STROKE_TIME = exports.DataGrid = void 0;
|
|
8
8
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
9
|
var React = _interopRequireWildcard(require("react"));
|
|
10
10
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
@@ -36,7 +36,21 @@ const DataGridRaw = /*#__PURE__*/React.forwardRef(function DataGrid(inProps, ref
|
|
|
36
36
|
});
|
|
37
37
|
});
|
|
38
38
|
const DataGrid = /*#__PURE__*/React.memo(DataGridRaw);
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Remove at v7
|
|
42
|
+
* @deprecated
|
|
43
|
+
*/
|
|
39
44
|
exports.DataGrid = DataGrid;
|
|
45
|
+
const SUBMIT_FILTER_STROKE_TIME = _useDataGridProps.DATA_GRID_PROPS_DEFAULT_VALUES.filterDebounceMs;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Remove at v7
|
|
49
|
+
* @deprecated
|
|
50
|
+
*/
|
|
51
|
+
exports.SUBMIT_FILTER_STROKE_TIME = SUBMIT_FILTER_STROKE_TIME;
|
|
52
|
+
const SUBMIT_FILTER_DATE_STROKE_TIME = _useDataGridProps.DATA_GRID_PROPS_DEFAULT_VALUES.filterDebounceMs;
|
|
53
|
+
exports.SUBMIT_FILTER_DATE_STROKE_TIME = SUBMIT_FILTER_DATE_STROKE_TIME;
|
|
40
54
|
DataGridRaw.propTypes = {
|
|
41
55
|
// ----------------------------- Warning --------------------------------
|
|
42
56
|
// | These PropTypes are generated from the TypeScript type definitions |
|
|
@@ -150,6 +164,12 @@ DataGridRaw.propTypes = {
|
|
|
150
164
|
* @default false
|
|
151
165
|
*/
|
|
152
166
|
disableDensitySelector: _propTypes.default.bool,
|
|
167
|
+
/**
|
|
168
|
+
* If `true`, `eval()` is not used for performance optimization.
|
|
169
|
+
* @default false
|
|
170
|
+
* @ignore - do not document
|
|
171
|
+
*/
|
|
172
|
+
disableEval: _propTypes.default.bool,
|
|
153
173
|
/**
|
|
154
174
|
* If `true`, the selection on click on a row or cell is disabled.
|
|
155
175
|
* @default false
|
|
@@ -174,6 +194,11 @@ DataGridRaw.propTypes = {
|
|
|
174
194
|
columnGrouping: _propTypes.default.bool,
|
|
175
195
|
warnIfFocusStateIsNotSynced: _propTypes.default.bool
|
|
176
196
|
}),
|
|
197
|
+
/**
|
|
198
|
+
* The milliseconds delay to wait after a keystroke before triggering filtering.
|
|
199
|
+
* @default 150
|
|
200
|
+
*/
|
|
201
|
+
filterDebounceMs: _propTypes.default.number,
|
|
177
202
|
/**
|
|
178
203
|
* Filtering can be processed on the server or client-side.
|
|
179
204
|
* Set it to 'server' if you would like to handle filtering on the server-side.
|
|
@@ -46,6 +46,7 @@ const DATA_GRID_PROPS_DEFAULT_VALUES = {
|
|
|
46
46
|
disableColumnMenu: false,
|
|
47
47
|
disableColumnSelector: false,
|
|
48
48
|
disableDensitySelector: false,
|
|
49
|
+
disableEval: false,
|
|
49
50
|
disableMultipleColumnsFiltering: false,
|
|
50
51
|
disableMultipleRowSelection: false,
|
|
51
52
|
disableMultipleColumnsSorting: false,
|
|
@@ -53,6 +54,7 @@ const DATA_GRID_PROPS_DEFAULT_VALUES = {
|
|
|
53
54
|
disableVirtualization: false,
|
|
54
55
|
editMode: _models.GridEditModes.Cell,
|
|
55
56
|
filterMode: 'client',
|
|
57
|
+
filterDebounceMs: 150,
|
|
56
58
|
columnHeaderHeight: 56,
|
|
57
59
|
hideFooter: false,
|
|
58
60
|
hideFooterPagination: false,
|
|
@@ -5,19 +5,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.GridFilterInputDate = GridFilterInputDate;
|
|
8
|
-
exports.SUBMIT_FILTER_DATE_STROKE_TIME = void 0;
|
|
9
8
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
10
9
|
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
|
11
10
|
var React = _interopRequireWildcard(require("react"));
|
|
12
11
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
13
12
|
var _utils = require("@mui/utils");
|
|
13
|
+
var _useTimeout = require("../../../hooks/utils/useTimeout");
|
|
14
14
|
var _useGridRootProps = require("../../../hooks/utils/useGridRootProps");
|
|
15
15
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
16
16
|
const _excluded = ["item", "applyValue", "type", "apiRef", "focusElementRef", "InputProps", "isFilterActive", "clearButton", "tabIndex", "disabled"];
|
|
17
17
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
18
18
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
19
|
-
const SUBMIT_FILTER_DATE_STROKE_TIME = 500;
|
|
20
|
-
exports.SUBMIT_FILTER_DATE_STROKE_TIME = SUBMIT_FILTER_DATE_STROKE_TIME;
|
|
21
19
|
function GridFilterInputDate(props) {
|
|
22
20
|
const {
|
|
23
21
|
item,
|
|
@@ -31,28 +29,22 @@ function GridFilterInputDate(props) {
|
|
|
31
29
|
disabled
|
|
32
30
|
} = props,
|
|
33
31
|
other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
|
|
34
|
-
const filterTimeout =
|
|
32
|
+
const filterTimeout = (0, _useTimeout.useTimeout)();
|
|
35
33
|
const [filterValueState, setFilterValueState] = React.useState(item.value ?? '');
|
|
36
34
|
const [applying, setIsApplying] = React.useState(false);
|
|
37
35
|
const id = (0, _utils.unstable_useId)();
|
|
38
36
|
const rootProps = (0, _useGridRootProps.useGridRootProps)();
|
|
39
37
|
const onFilterChange = React.useCallback(event => {
|
|
40
38
|
const value = event.target.value;
|
|
41
|
-
clearTimeout(filterTimeout.current);
|
|
42
39
|
setFilterValueState(String(value));
|
|
43
40
|
setIsApplying(true);
|
|
44
|
-
filterTimeout.
|
|
41
|
+
filterTimeout.start(rootProps.filterDebounceMs, () => {
|
|
45
42
|
applyValue((0, _extends2.default)({}, item, {
|
|
46
43
|
value
|
|
47
44
|
}));
|
|
48
45
|
setIsApplying(false);
|
|
49
|
-
}
|
|
50
|
-
}, [applyValue, item]);
|
|
51
|
-
React.useEffect(() => {
|
|
52
|
-
return () => {
|
|
53
|
-
clearTimeout(filterTimeout.current);
|
|
54
|
-
};
|
|
55
|
-
}, []);
|
|
46
|
+
});
|
|
47
|
+
}, [applyValue, item, rootProps.filterDebounceMs, filterTimeout]);
|
|
56
48
|
React.useEffect(() => {
|
|
57
49
|
const itemValue = item.value ?? '';
|
|
58
50
|
setFilterValueState(String(itemValue));
|
|
@@ -5,19 +5,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.GridFilterInputValue = GridFilterInputValue;
|
|
8
|
-
exports.SUBMIT_FILTER_STROKE_TIME = void 0;
|
|
9
8
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
10
9
|
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
|
11
10
|
var React = _interopRequireWildcard(require("react"));
|
|
12
11
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
13
12
|
var _utils = require("@mui/utils");
|
|
13
|
+
var _useTimeout = require("../../../hooks/utils/useTimeout");
|
|
14
14
|
var _useGridRootProps = require("../../../hooks/utils/useGridRootProps");
|
|
15
15
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
16
16
|
const _excluded = ["item", "applyValue", "type", "apiRef", "focusElementRef", "tabIndex", "disabled", "isFilterActive", "clearButton", "InputProps"];
|
|
17
17
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
18
18
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
19
|
-
const SUBMIT_FILTER_STROKE_TIME = 500;
|
|
20
|
-
exports.SUBMIT_FILTER_STROKE_TIME = SUBMIT_FILTER_STROKE_TIME;
|
|
21
19
|
function GridFilterInputValue(props) {
|
|
22
20
|
const {
|
|
23
21
|
item,
|
|
@@ -31,7 +29,7 @@ function GridFilterInputValue(props) {
|
|
|
31
29
|
InputProps
|
|
32
30
|
} = props,
|
|
33
31
|
others = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
|
|
34
|
-
const filterTimeout =
|
|
32
|
+
const filterTimeout = (0, _useTimeout.useTimeout)();
|
|
35
33
|
const [filterValueState, setFilterValueState] = React.useState(item.value ?? '');
|
|
36
34
|
const [applying, setIsApplying] = React.useState(false);
|
|
37
35
|
const id = (0, _utils.unstable_useId)();
|
|
@@ -40,25 +38,23 @@ function GridFilterInputValue(props) {
|
|
|
40
38
|
const {
|
|
41
39
|
value
|
|
42
40
|
} = event.target;
|
|
43
|
-
clearTimeout(filterTimeout.current);
|
|
44
41
|
setFilterValueState(String(value));
|
|
45
42
|
setIsApplying(true);
|
|
46
|
-
filterTimeout.
|
|
47
|
-
|
|
48
|
-
value
|
|
49
|
-
|
|
43
|
+
filterTimeout.start(rootProps.filterDebounceMs, () => {
|
|
44
|
+
const newItem = (0, _extends2.default)({}, item, {
|
|
45
|
+
value,
|
|
46
|
+
fromInput: id
|
|
47
|
+
});
|
|
48
|
+
applyValue(newItem);
|
|
50
49
|
setIsApplying(false);
|
|
51
|
-
}
|
|
52
|
-
}, [applyValue, item]);
|
|
50
|
+
});
|
|
51
|
+
}, [id, applyValue, item, rootProps.filterDebounceMs, filterTimeout]);
|
|
53
52
|
React.useEffect(() => {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const itemValue = item.value ?? '';
|
|
60
|
-
setFilterValueState(String(itemValue));
|
|
61
|
-
}, [item.value]);
|
|
53
|
+
const itemPlusTag = item;
|
|
54
|
+
if (itemPlusTag.fromInput !== id) {
|
|
55
|
+
setFilterValueState(String(item.value ?? ''));
|
|
56
|
+
}
|
|
57
|
+
}, [id, item]);
|
|
62
58
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(rootProps.slots.baseTextField, (0, _extends2.default)({
|
|
63
59
|
id: id,
|
|
64
60
|
label: apiRef.current.getLocaleText('filterPanelInputLabel'),
|
|
@@ -45,9 +45,7 @@ const GridFilterPanel = /*#__PURE__*/React.forwardRef(function GridFilterPanel(p
|
|
|
45
45
|
disableRemoveAllButton = false
|
|
46
46
|
} = props,
|
|
47
47
|
other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
|
|
48
|
-
const applyFilter =
|
|
49
|
-
apiRef.current.upsertFilterItem(item);
|
|
50
|
-
}, [apiRef]);
|
|
48
|
+
const applyFilter = apiRef.current.upsertFilterItem;
|
|
51
49
|
const applyFilterLogicOperator = React.useCallback(operator => {
|
|
52
50
|
apiRef.current.setFilterLogicOperator(operator);
|
|
53
51
|
}, [apiRef]);
|
|
@@ -54,15 +54,15 @@ const GridToolbarQuickFilterRoot = (0, _styles.styled)(_TextField.default, {
|
|
|
54
54
|
const defaultSearchValueParser = searchText => searchText.split(' ').filter(word => word !== '');
|
|
55
55
|
const defaultSearchValueFormatter = values => values.join(' ');
|
|
56
56
|
function GridToolbarQuickFilter(props) {
|
|
57
|
+
const apiRef = (0, _useGridApiContext.useGridApiContext)();
|
|
58
|
+
const rootProps = (0, _useGridRootProps.useGridRootProps)();
|
|
59
|
+
const quickFilterValues = (0, _useGridSelector.useGridSelector)(apiRef, _filter.gridQuickFilterValuesSelector);
|
|
57
60
|
const {
|
|
58
61
|
quickFilterParser = defaultSearchValueParser,
|
|
59
62
|
quickFilterFormatter = defaultSearchValueFormatter,
|
|
60
|
-
debounceMs =
|
|
63
|
+
debounceMs = rootProps.filterDebounceMs
|
|
61
64
|
} = props,
|
|
62
65
|
other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
|
|
63
|
-
const apiRef = (0, _useGridApiContext.useGridApiContext)();
|
|
64
|
-
const rootProps = (0, _useGridRootProps.useGridRootProps)();
|
|
65
|
-
const quickFilterValues = (0, _useGridSelector.useGridSelector)(apiRef, _filter.gridQuickFilterValuesSelector);
|
|
66
66
|
const [searchValue, setSearchValue] = React.useState(() => quickFilterFormatter(quickFilterValues ?? []));
|
|
67
67
|
const prevQuickFilterValuesRef = React.useRef(quickFilterValues);
|
|
68
68
|
React.useEffect(() => {
|
|
@@ -125,7 +125,7 @@ process.env.NODE_ENV !== "production" ? GridToolbarQuickFilter.propTypes = {
|
|
|
125
125
|
// ----------------------------------------------------------------------
|
|
126
126
|
/**
|
|
127
127
|
* The debounce time in milliseconds.
|
|
128
|
-
* @default
|
|
128
|
+
* @default 150
|
|
129
129
|
*/
|
|
130
130
|
debounceMs: _propTypes.default.number,
|
|
131
131
|
/**
|
|
@@ -15,6 +15,7 @@ var _gridClasses = require("../../../constants/gridClasses");
|
|
|
15
15
|
var _useGridApiMethod = require("../../utils/useGridApiMethod");
|
|
16
16
|
var _gridRowsMetaSelector = require("../rows/gridRowsMetaSelector");
|
|
17
17
|
var _utils2 = require("./utils");
|
|
18
|
+
var _useGridPagination = require("../pagination/useGridPagination");
|
|
18
19
|
var _pipeProcessing = require("../../core/pipeProcessing");
|
|
19
20
|
var _GridToolbarExport = require("../../../components/toolbar/GridToolbarExport");
|
|
20
21
|
var _gridColumnsUtils = require("../columns/gridColumnsUtils");
|
|
@@ -55,11 +56,6 @@ const useGridPrintExport = (apiRef, props) => {
|
|
|
55
56
|
// Returns a promise because updateColumns triggers state update and
|
|
56
57
|
// the new state needs to be in place before the grid can be sized correctly
|
|
57
58
|
const updateGridColumnsForPrint = React.useCallback((fields, allColumns) => new Promise(resolve => {
|
|
58
|
-
// TODO remove unused Promise
|
|
59
|
-
if (!fields && !allColumns) {
|
|
60
|
-
resolve();
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
59
|
const exportedColumnFields = (0, _utils2.getColumnsToExport)({
|
|
64
60
|
apiRef,
|
|
65
61
|
options: {
|
|
@@ -202,7 +198,14 @@ const useGridPrintExport = (apiRef, props) => {
|
|
|
202
198
|
previousColumnVisibility.current = (0, _gridColumnsSelector.gridColumnVisibilityModelSelector)(apiRef);
|
|
203
199
|
if (props.pagination) {
|
|
204
200
|
const visibleRowCount = (0, _gridFilterSelector.gridExpandedRowCountSelector)(apiRef);
|
|
205
|
-
|
|
201
|
+
const paginationModel = {
|
|
202
|
+
page: 0,
|
|
203
|
+
pageSize: visibleRowCount
|
|
204
|
+
};
|
|
205
|
+
apiRef.current.updateControlState('pagination',
|
|
206
|
+
// Using signature `DataGridPro` to allow more than 100 rows in the print export
|
|
207
|
+
(0, _useGridPagination.mergeStateWithPaginationModel)(visibleRowCount, 'DataGridPro', paginationModel));
|
|
208
|
+
apiRef.current.forceUpdate();
|
|
206
209
|
}
|
|
207
210
|
await updateGridColumnsForPrint(options?.fields, options?.allColumns);
|
|
208
211
|
apiRef.current.unstable_disableVirtualization();
|
|
@@ -13,7 +13,13 @@ const getColumnsToExport = ({
|
|
|
13
13
|
}) => {
|
|
14
14
|
const columns = (0, _columns.gridColumnDefinitionsSelector)(apiRef);
|
|
15
15
|
if (options.fields) {
|
|
16
|
-
return options.fields.
|
|
16
|
+
return options.fields.reduce((currentColumns, field) => {
|
|
17
|
+
const column = columns.find(col => col.field === field);
|
|
18
|
+
if (column) {
|
|
19
|
+
currentColumns.push(column);
|
|
20
|
+
}
|
|
21
|
+
return currentColumns;
|
|
22
|
+
}, []);
|
|
17
23
|
}
|
|
18
24
|
const validColumns = options.allColumns ? columns : (0, _columns.gridVisibleColumnDefinitionsSelector)(apiRef);
|
|
19
25
|
return validColumns.filter(column => !column.disableExport);
|
|
@@ -11,6 +11,13 @@ var _utils = require("../../../colDef/utils");
|
|
|
11
11
|
var _gridFilterState = require("./gridFilterState");
|
|
12
12
|
var _warning = require("../../../utils/warning");
|
|
13
13
|
var _columns = require("../columns");
|
|
14
|
+
let hasEval;
|
|
15
|
+
try {
|
|
16
|
+
// eslint-disable-next-line no-eval
|
|
17
|
+
hasEval = eval('true');
|
|
18
|
+
} catch (_) {
|
|
19
|
+
hasEval = false;
|
|
20
|
+
}
|
|
14
21
|
/**
|
|
15
22
|
* Adds default values to the optional fields of a filter items.
|
|
16
23
|
* @param {GridFilterItem} item The raw filter item.
|
|
@@ -136,7 +143,7 @@ let filterItemsApplierId = 1;
|
|
|
136
143
|
* @param {React.MutableRefObject<GridApiCommunity>} apiRef The API of the grid.
|
|
137
144
|
* @returns {GridAggregatedFilterItemApplier | null} A method that checks if a row is matching the current filter model. If `null`, we consider that all the rows are matching the filters.
|
|
138
145
|
*/
|
|
139
|
-
const buildAggregatedFilterItemsApplier = (getRowId, filterModel, apiRef) => {
|
|
146
|
+
const buildAggregatedFilterItemsApplier = (getRowId, filterModel, apiRef, disableEval) => {
|
|
140
147
|
const {
|
|
141
148
|
items
|
|
142
149
|
} = filterModel;
|
|
@@ -144,22 +151,19 @@ const buildAggregatedFilterItemsApplier = (getRowId, filterModel, apiRef) => {
|
|
|
144
151
|
if (appliers.length === 0) {
|
|
145
152
|
return null;
|
|
146
153
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
//
|
|
161
|
-
// return resultPerItemId;
|
|
162
|
-
// };
|
|
154
|
+
if (!hasEval || disableEval) {
|
|
155
|
+
// This is the original logic, which is used if `eval()` is not supported (aka prevented by CSP).
|
|
156
|
+
return (row, shouldApplyFilter) => {
|
|
157
|
+
const resultPerItemId = {};
|
|
158
|
+
for (let i = 0; i < appliers.length; i += 1) {
|
|
159
|
+
const applier = appliers[i];
|
|
160
|
+
if (!shouldApplyFilter || shouldApplyFilter(applier.item.field)) {
|
|
161
|
+
resultPerItemId[applier.item.id] = applier.v7 ? applier.fn(row) : applier.fn(getRowId ? getRowId(row) : row.id);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return resultPerItemId;
|
|
165
|
+
};
|
|
166
|
+
}
|
|
163
167
|
|
|
164
168
|
// We generate a new function with `eval()` to avoid expensive patterns for JS engines
|
|
165
169
|
// such as a dynamic object assignment, e.g. `{ [dynamicKey]: value }`.
|
|
@@ -269,8 +273,8 @@ const buildAggregatedQuickFilterApplier = (getRowId, filterModel, apiRef) => {
|
|
|
269
273
|
};
|
|
270
274
|
};
|
|
271
275
|
exports.buildAggregatedQuickFilterApplier = buildAggregatedQuickFilterApplier;
|
|
272
|
-
const buildAggregatedFilterApplier = (getRowId, filterModel, apiRef) => {
|
|
273
|
-
const isRowMatchingFilterItems = buildAggregatedFilterItemsApplier(getRowId, filterModel, apiRef);
|
|
276
|
+
const buildAggregatedFilterApplier = (getRowId, filterModel, apiRef, disableEval) => {
|
|
277
|
+
const isRowMatchingFilterItems = buildAggregatedFilterItemsApplier(getRowId, filterModel, apiRef, disableEval);
|
|
274
278
|
const isRowMatchingQuickFilter = buildAggregatedQuickFilterApplier(getRowId, filterModel, apiRef);
|
|
275
279
|
return function isRowMatchingFilters(row, shouldApplyFilter, result) {
|
|
276
280
|
result.passingFilterItems = isRowMatchingFilterItems?.(row, shouldApplyFilter) ?? null;
|
|
@@ -69,7 +69,7 @@ const useGridFilter = (apiRef, props) => {
|
|
|
69
69
|
const updateFilteredRows = React.useCallback(() => {
|
|
70
70
|
apiRef.current.setState(state => {
|
|
71
71
|
const filterModel = (0, _gridFilterSelector.gridFilterModelSelector)(state, apiRef.current.instanceId);
|
|
72
|
-
const isRowMatchingFilters = props.filterMode === 'client' ? (0, _gridFilterUtils.buildAggregatedFilterApplier)(props.getRowId, filterModel, apiRef) : null;
|
|
72
|
+
const isRowMatchingFilters = props.filterMode === 'client' ? (0, _gridFilterUtils.buildAggregatedFilterApplier)(props.getRowId, filterModel, apiRef, props.disableEval) : null;
|
|
73
73
|
const filteringResult = apiRef.current.applyStrategyProcessor('filtering', {
|
|
74
74
|
isRowMatchingFilters,
|
|
75
75
|
filterModel: filterModel ?? (0, _gridFilterState.getDefaultGridFilterModel)()
|
|
@@ -83,7 +83,7 @@ const useGridFilter = (apiRef, props) => {
|
|
|
83
83
|
});
|
|
84
84
|
});
|
|
85
85
|
apiRef.current.publishEvent('filteredRowsSet');
|
|
86
|
-
}, [apiRef, props.filterMode, props.getRowId]);
|
|
86
|
+
}, [apiRef, props.filterMode, props.getRowId, props.disableEval]);
|
|
87
87
|
const addColumnMenuItem = React.useCallback((columnMenuItems, colDef) => {
|
|
88
88
|
if (colDef == null || colDef.filterable === false || props.disableColumnFilter) {
|
|
89
89
|
return columnMenuItems;
|
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.useGridPagination = exports.paginationStateInitializer = void 0;
|
|
7
|
+
exports.useGridPagination = exports.paginationStateInitializer = exports.mergeStateWithPaginationModel = void 0;
|
|
8
8
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
9
|
var React = _interopRequireWildcard(require("react"));
|
|
10
10
|
var _filter = require("../filter");
|
|
@@ -49,6 +49,7 @@ const mergeStateWithPaginationModel = (rowCount, signature, paginationModelProp)
|
|
|
49
49
|
* @requires useGridFilter (state)
|
|
50
50
|
* @requires useGridDimensions (event) - can be after
|
|
51
51
|
*/
|
|
52
|
+
exports.mergeStateWithPaginationModel = mergeStateWithPaginationModel;
|
|
52
53
|
const useGridPagination = (apiRef, props) => {
|
|
53
54
|
const logger = (0, _utils.useGridLogger)(apiRef, 'useGridPagination');
|
|
54
55
|
const visibleTopLevelRowCount = (0, _utils.useGridSelector)(apiRef, _filter.gridFilteredTopLevelRowCountSelector);
|
|
@@ -62,6 +62,16 @@ const useGridRows = (apiRef, props) => {
|
|
|
62
62
|
}
|
|
63
63
|
return null;
|
|
64
64
|
}, [apiRef]);
|
|
65
|
+
const getRowIdProp = props.getRowId;
|
|
66
|
+
const getRowId = React.useCallback(row => {
|
|
67
|
+
if (_gridRowsUtils.GRID_ID_AUTOGENERATED in row) {
|
|
68
|
+
return row[_gridRowsUtils.GRID_ID_AUTOGENERATED];
|
|
69
|
+
}
|
|
70
|
+
if (getRowIdProp) {
|
|
71
|
+
return getRowIdProp(row);
|
|
72
|
+
}
|
|
73
|
+
return row.id;
|
|
74
|
+
}, [getRowIdProp]);
|
|
65
75
|
const lookup = React.useMemo(() => currentPage.rows.reduce((acc, {
|
|
66
76
|
id
|
|
67
77
|
}, index) => {
|
|
@@ -301,6 +311,7 @@ const useGridRows = (apiRef, props) => {
|
|
|
301
311
|
}, [apiRef, props.signature, props.getRowId]);
|
|
302
312
|
const rowApi = {
|
|
303
313
|
getRow,
|
|
314
|
+
getRowId,
|
|
304
315
|
getRowModels,
|
|
305
316
|
getRowsCount,
|
|
306
317
|
getAllRowIds,
|
|
@@ -8,6 +8,8 @@ var React = _interopRequireWildcard(require("react"));
|
|
|
8
8
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
9
9
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
10
10
|
const UNINITIALIZED = {};
|
|
11
|
+
|
|
12
|
+
// See https://github.com/facebook/react/issues/14490 for when to use this.
|
|
11
13
|
function useLazyRef(init, initArg) {
|
|
12
14
|
const ref = React.useRef(UNINITIALIZED);
|
|
13
15
|
if (ref.current === UNINITIALIZED) {
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useTimeout = useTimeout;
|
|
7
|
+
var _useLazyRef = require("./useLazyRef");
|
|
8
|
+
var _useOnMount = require("./useOnMount");
|
|
9
|
+
class Timeout {
|
|
10
|
+
constructor() {
|
|
11
|
+
this.currentId = 0;
|
|
12
|
+
this.clear = () => {
|
|
13
|
+
if (this.currentId !== 0) {
|
|
14
|
+
clearTimeout(this.currentId);
|
|
15
|
+
this.currentId = 0;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
this.disposeEffect = () => {
|
|
19
|
+
return this.clear;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
static create() {
|
|
23
|
+
return new Timeout();
|
|
24
|
+
}
|
|
25
|
+
start(delay, fn) {
|
|
26
|
+
this.clear();
|
|
27
|
+
this.currentId = setTimeout(fn, delay);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function useTimeout() {
|
|
31
|
+
const timeout = (0, _useLazyRef.useLazyRef)(Timeout.create).current;
|
|
32
|
+
(0, _useOnMount.useOnMount)(timeout.disposeEffect);
|
|
33
|
+
return timeout;
|
|
34
|
+
}
|
package/node/index.js
CHANGED