@mui/x-data-grid-premium 8.0.0-alpha.0 → 8.0.0-alpha.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.
- package/CHANGELOG.md +651 -6
- package/DataGridPremium/DataGridPremium.js +10 -10
- package/README.md +2 -2
- package/components/index.d.ts +1 -0
- package/components/index.js +12 -0
- package/components/promptControl/GridToolbarPromptControl.d.ts +26 -0
- package/components/promptControl/GridToolbarPromptControl.js +209 -0
- package/components/promptControl/RecordButton.d.ts +16 -0
- package/components/promptControl/RecordButton.js +119 -0
- package/components/promptControl/index.d.ts +1 -0
- package/components/promptControl/index.js +12 -0
- package/esm/DataGridPremium/DataGridPremium.js +10 -10
- package/esm/components/index.js +1 -0
- package/esm/components/promptControl/GridToolbarPromptControl.js +202 -0
- package/esm/components/promptControl/RecordButton.js +111 -0
- package/esm/components/promptControl/index.js +1 -0
- package/esm/hooks/features/index.js +2 -1
- package/esm/hooks/features/promptControl/api.js +22 -0
- package/esm/hooks/features/promptControl/index.js +1 -0
- package/esm/hooks/features/promptControl/types.js +1 -0
- package/esm/material/icons.js +7 -1
- package/esm/material/index.js +4 -2
- package/esm/utils/releaseInfo.js +1 -1
- package/hooks/features/aggregation/wrapColumnWithAggregation.d.ts +1 -0
- package/hooks/features/index.d.ts +1 -0
- package/hooks/features/index.js +11 -0
- package/hooks/features/promptControl/api.d.ts +2 -0
- package/hooks/features/promptControl/api.js +28 -0
- package/hooks/features/promptControl/index.d.ts +2 -0
- package/hooks/features/promptControl/index.js +12 -0
- package/hooks/features/promptControl/types.d.ts +25 -0
- package/hooks/features/promptControl/types.js +5 -0
- package/index.js +1 -1
- package/material/icons.d.ts +6 -0
- package/material/icons.js +8 -2
- package/material/index.d.ts +2 -0
- package/material/index.js +3 -1
- package/models/gridPremiumIconSlotsComponent.d.ts +10 -0
- package/modern/DataGridPremium/DataGridPremium.js +10 -10
- package/modern/components/index.js +1 -0
- package/modern/components/promptControl/GridToolbarPromptControl.js +202 -0
- package/modern/components/promptControl/RecordButton.js +111 -0
- package/modern/components/promptControl/index.js +1 -0
- package/modern/hooks/features/index.js +2 -1
- package/modern/hooks/features/promptControl/api.js +22 -0
- package/modern/hooks/features/promptControl/index.js +1 -0
- package/modern/hooks/features/promptControl/types.js +1 -0
- package/modern/index.js +1 -1
- package/modern/material/icons.js +7 -1
- package/modern/material/index.js +4 -2
- package/modern/utils/releaseInfo.js +1 -1
- package/package.json +7 -7
- package/utils/releaseInfo.js +1 -1
|
@@ -459,14 +459,6 @@ process.env.NODE_ENV !== "production" ? DataGridPremiumRaw.propTypes = {
|
|
|
459
459
|
clipboardExport: _propTypes.default.bool,
|
|
460
460
|
csvExport: _propTypes.default.bool
|
|
461
461
|
}), _propTypes.default.bool]),
|
|
462
|
-
/**
|
|
463
|
-
* If `select`, a group header checkbox in indeterminate state (like "Select All" checkbox)
|
|
464
|
-
* will select all the rows under it.
|
|
465
|
-
* If `deselect`, it will deselect all the rows under it.
|
|
466
|
-
* Works only if `checkboxSelection` is enabled.
|
|
467
|
-
* @default "deselect"
|
|
468
|
-
*/
|
|
469
|
-
indeterminateCheckboxAction: _propTypes.default.oneOf(['deselect', 'select']),
|
|
470
462
|
/**
|
|
471
463
|
* The initial state of the DataGridPremium.
|
|
472
464
|
* The data in it is set in the state on initialization but isn't controlled.
|
|
@@ -971,7 +963,7 @@ process.env.NODE_ENV !== "production" ? DataGridPremiumRaw.propTypes = {
|
|
|
971
963
|
* - Deselecting a descendant of a selected parent deselects the parent automatically.
|
|
972
964
|
*
|
|
973
965
|
* Works with tree data and row grouping on the client-side only.
|
|
974
|
-
* @default { parents:
|
|
966
|
+
* @default { parents: true, descendants: true }
|
|
975
967
|
*/
|
|
976
968
|
rowSelectionPropagation: _propTypes.default.shape({
|
|
977
969
|
descendants: _propTypes.default.bool,
|
|
@@ -1088,7 +1080,15 @@ process.env.NODE_ENV !== "production" ? DataGridPremiumRaw.propTypes = {
|
|
|
1088
1080
|
* If `true`, the Data Grid will auto span the cells over the rows having the same value.
|
|
1089
1081
|
* @default false
|
|
1090
1082
|
*/
|
|
1091
|
-
unstable_rowSpanning: _propTypes.default.bool
|
|
1083
|
+
unstable_rowSpanning: _propTypes.default.bool,
|
|
1084
|
+
/**
|
|
1085
|
+
* If `true`, the Data Grid enables column virtualization when `getRowHeight` is set to `() => 'auto'`.
|
|
1086
|
+
* By default, column virtualization is disabled when dynamic row height is enabled to measure the row height correctly.
|
|
1087
|
+
* For datasets with a large number of columns, this can cause performance issues.
|
|
1088
|
+
* The downside of enabling this prop is that the row height will be estimated based the cells that are currently rendered, which can cause row height change when scrolling horizontally.
|
|
1089
|
+
* @default false
|
|
1090
|
+
*/
|
|
1091
|
+
virtualizeColumnsWithAutoRowHeight: _propTypes.default.bool
|
|
1092
1092
|
} : void 0;
|
|
1093
1093
|
/**
|
|
1094
1094
|
* Demos:
|
package/README.md
CHANGED
|
@@ -16,8 +16,8 @@ This component has the following peer dependencies that you need to install as w
|
|
|
16
16
|
```json
|
|
17
17
|
"peerDependencies": {
|
|
18
18
|
"@mui/material": "^5.15.14 || ^6.0.0",
|
|
19
|
-
"react": "^17.0.0 || ^18.0.0",
|
|
20
|
-
"react-dom": "^17.0.0 || ^18.0.0"
|
|
19
|
+
"react": "^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
20
|
+
"react-dom": "^17.0.0 || ^18.0.0 || ^19.0.0"
|
|
21
21
|
},
|
|
22
22
|
```
|
|
23
23
|
|
package/components/index.d.ts
CHANGED
package/components/index.js
CHANGED
|
@@ -48,4 +48,16 @@ Object.keys(_GridColumnMenuAggregationItem).forEach(function (key) {
|
|
|
48
48
|
}
|
|
49
49
|
});
|
|
50
50
|
});
|
|
51
|
+
var _promptControl = require("./promptControl");
|
|
52
|
+
Object.keys(_promptControl).forEach(function (key) {
|
|
53
|
+
if (key === "default" || key === "__esModule") return;
|
|
54
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
55
|
+
if (key in exports && exports[key] === _promptControl[key]) return;
|
|
56
|
+
Object.defineProperty(exports, key, {
|
|
57
|
+
enumerable: true,
|
|
58
|
+
get: function () {
|
|
59
|
+
return _promptControl[key];
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
});
|
|
51
63
|
var _GridPremiumColumnMenu = require("./GridPremiumColumnMenu");
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { PromptResponse } from '../../hooks/features/promptControl/types';
|
|
3
|
+
type GridToolbarPromptControlProps = {
|
|
4
|
+
/**
|
|
5
|
+
* Called when the new prompt is ready to be processed.
|
|
6
|
+
* Provides the prompt and the data context and expects the grid state updates to be returned.
|
|
7
|
+
* @param {string} context The context of the prompt
|
|
8
|
+
* @param {string} query The query to process
|
|
9
|
+
* @returns {Promise<PromptResponse>} The grid state updates
|
|
10
|
+
*/
|
|
11
|
+
onPrompt: (context: string, query: string) => Promise<PromptResponse>;
|
|
12
|
+
/**
|
|
13
|
+
* Allow taking couple of random cell values from each column to improve the prompt context.
|
|
14
|
+
* If allowed, samples are taken from different rows.
|
|
15
|
+
* If not allowed, the column examples are used.
|
|
16
|
+
* @default false
|
|
17
|
+
*/
|
|
18
|
+
allowDataSampling?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* The BCP 47 language tag to use for the speech recognition.
|
|
21
|
+
* @default HTML lang attribute value or the user agent's language setting
|
|
22
|
+
*/
|
|
23
|
+
lang?: string;
|
|
24
|
+
};
|
|
25
|
+
declare function GridToolbarPromptControl(props: GridToolbarPromptControlProps): React.JSX.Element;
|
|
26
|
+
export { GridToolbarPromptControl };
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.GridToolbarPromptControl = GridToolbarPromptControl;
|
|
9
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
10
|
+
var React = _interopRequireWildcard(require("react"));
|
|
11
|
+
var _styles = require("@mui/material/styles");
|
|
12
|
+
var _composeClasses = _interopRequireDefault(require("@mui/utils/composeClasses"));
|
|
13
|
+
var _useEventCallback = _interopRequireDefault(require("@mui/utils/useEventCallback"));
|
|
14
|
+
var _xDataGrid = require("@mui/x-data-grid");
|
|
15
|
+
var _internals = require("@mui/x-data-grid/internals");
|
|
16
|
+
var _useGridApiContext = require("../../hooks/utils/useGridApiContext");
|
|
17
|
+
var _useGridRootProps = require("../../hooks/utils/useGridRootProps");
|
|
18
|
+
var _RecordButton = require("./RecordButton");
|
|
19
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
20
|
+
const supportsSpeechRecognition = !!_RecordButton.BrowserSpeechRecognition;
|
|
21
|
+
const useUtilityClasses = (ownerState, recording) => {
|
|
22
|
+
const {
|
|
23
|
+
classes
|
|
24
|
+
} = ownerState;
|
|
25
|
+
const slots = {
|
|
26
|
+
root: ['toolbarPromptControl', recording && 'toolbarPromptControl--recording'],
|
|
27
|
+
recordingIndicator: ['toolbarPromptControlRecordingIndicator'],
|
|
28
|
+
recordButton: ['toolbarPromptControlRecordButton'],
|
|
29
|
+
sendButton: ['toolbarPromptControlSendButton']
|
|
30
|
+
};
|
|
31
|
+
return (0, _composeClasses.default)(slots, _xDataGrid.getDataGridUtilityClass, classes);
|
|
32
|
+
};
|
|
33
|
+
const GridToolbarPromptControlRoot = (0, _styles.styled)('div', {
|
|
34
|
+
name: 'MuiDataGrid',
|
|
35
|
+
slot: 'ToolbarPromptControl',
|
|
36
|
+
overridesResolver: (_, styles) => styles.toolbarPromptControl
|
|
37
|
+
})({
|
|
38
|
+
flex: 1,
|
|
39
|
+
display: 'flex',
|
|
40
|
+
flexDirection: 'row'
|
|
41
|
+
});
|
|
42
|
+
function sampleData(apiRef) {
|
|
43
|
+
const columns = (0, _xDataGrid.gridColumnDefinitionsSelector)(apiRef);
|
|
44
|
+
const rows = Object.values((0, _xDataGrid.gridRowsLookupSelector)(apiRef));
|
|
45
|
+
const columnExamples = {};
|
|
46
|
+
columns.forEach(column => {
|
|
47
|
+
columnExamples[column.field] = Array.from({
|
|
48
|
+
length: Math.min(5, rows.length)
|
|
49
|
+
}).map(() => {
|
|
50
|
+
const row = rows[Math.floor(Math.random() * rows.length)];
|
|
51
|
+
if (column.valueGetter) {
|
|
52
|
+
return column.valueGetter(row[column.field], row, column, apiRef);
|
|
53
|
+
}
|
|
54
|
+
return row[column.field];
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
return columnExamples;
|
|
58
|
+
}
|
|
59
|
+
function generateContext(apiRef, examples) {
|
|
60
|
+
const columns = (0, _xDataGrid.gridColumnDefinitionsSelector)(apiRef);
|
|
61
|
+
const columnsContext = columns.map(column => ({
|
|
62
|
+
field: column.field,
|
|
63
|
+
description: column.description ?? null,
|
|
64
|
+
examples: examples?.[column.field] ?? column.unstable_examples ?? [],
|
|
65
|
+
type: column.type ?? 'string',
|
|
66
|
+
allowedOperators: column.filterOperators?.map(operator => operator.value) ?? []
|
|
67
|
+
}));
|
|
68
|
+
return `The columns are described by the following JSON:\n${JSON.stringify(columnsContext)}`;
|
|
69
|
+
}
|
|
70
|
+
function GridToolbarPromptControl(props) {
|
|
71
|
+
const apiRef = (0, _useGridApiContext.useGridApiContext)();
|
|
72
|
+
const rootProps = (0, _useGridRootProps.useGridRootProps)();
|
|
73
|
+
const {
|
|
74
|
+
onPrompt,
|
|
75
|
+
lang,
|
|
76
|
+
allowDataSampling = false
|
|
77
|
+
} = props;
|
|
78
|
+
const [isLoading, setLoading] = React.useState(false);
|
|
79
|
+
const [error, setError] = React.useState(null);
|
|
80
|
+
const [isRecording, setRecording] = React.useState(false);
|
|
81
|
+
const [query, setQuery] = React.useState('');
|
|
82
|
+
const classes = useUtilityClasses(rootProps, isRecording);
|
|
83
|
+
const examplesFromData = React.useMemo(() => allowDataSampling ? sampleData(apiRef) : undefined, [apiRef, allowDataSampling]);
|
|
84
|
+
const processPrompt = React.useCallback(() => {
|
|
85
|
+
const context = generateContext(apiRef, examplesFromData);
|
|
86
|
+
const columnsByField = (0, _xDataGrid.gridColumnLookupSelector)(apiRef);
|
|
87
|
+
setLoading(true);
|
|
88
|
+
setError(null);
|
|
89
|
+
apiRef.current.setLoading(true);
|
|
90
|
+
onPrompt(context, query).then(result => {
|
|
91
|
+
const interestColumns = [];
|
|
92
|
+
apiRef.current.setFilterModel({
|
|
93
|
+
items: result.filters.map((filter, index) => {
|
|
94
|
+
const item = {
|
|
95
|
+
id: index,
|
|
96
|
+
field: filter.column,
|
|
97
|
+
operator: filter.operator,
|
|
98
|
+
value: filter.value
|
|
99
|
+
};
|
|
100
|
+
const column = columnsByField[filter.column];
|
|
101
|
+
if (column.type === 'singleSelect') {
|
|
102
|
+
const options = (0, _internals.getValueOptions)(column) ?? [];
|
|
103
|
+
const found = options.find(option => typeof option === 'object' && option.label === filter.value);
|
|
104
|
+
if (found) {
|
|
105
|
+
item.value = found.value;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return item;
|
|
109
|
+
}),
|
|
110
|
+
logicOperator: result.filterOperator ?? _xDataGrid.GridLogicOperator.And,
|
|
111
|
+
quickFilterValues: []
|
|
112
|
+
});
|
|
113
|
+
apiRef.current.setRowGroupingModel(result.grouping.map(g => g.column));
|
|
114
|
+
apiRef.current.setAggregationModel(result.aggregation);
|
|
115
|
+
apiRef.current.setSortModel(result.sorting.map(s => ({
|
|
116
|
+
field: s.column,
|
|
117
|
+
sort: s.direction
|
|
118
|
+
})));
|
|
119
|
+
const rows = (0, _internals.getVisibleRows)(apiRef, rootProps);
|
|
120
|
+
const selectedRowIds = result.select === -1 ? [] : rows.rows.slice(0, result.select).map(r => {
|
|
121
|
+
return apiRef.current.getRowId(r);
|
|
122
|
+
});
|
|
123
|
+
apiRef.current.setRowSelectionModel(selectedRowIds);
|
|
124
|
+
const columns = apiRef.current.getAllColumns();
|
|
125
|
+
const targetIndex = Number(columns.find(c => c.field === _xDataGrid.GRID_CHECKBOX_SELECTION_FIELD) !== undefined) + Number(result.grouping.length);
|
|
126
|
+
interestColumns.push(...Object.keys(result.aggregation));
|
|
127
|
+
interestColumns.push(...result.filters.map(f => f.column));
|
|
128
|
+
interestColumns.reverse().forEach(c => apiRef.current.setColumnIndex(c, targetIndex));
|
|
129
|
+
}).catch(_ => {
|
|
130
|
+
setError(apiRef.current.getLocaleText('toolbarPromptControlErrorMessage'));
|
|
131
|
+
}).finally(() => {
|
|
132
|
+
setLoading(false);
|
|
133
|
+
apiRef.current.setState(state => (0, _extends2.default)({}, state, {
|
|
134
|
+
rows: (0, _extends2.default)({}, state.rows, {
|
|
135
|
+
loading: false
|
|
136
|
+
})
|
|
137
|
+
}));
|
|
138
|
+
});
|
|
139
|
+
}, [apiRef, rootProps, onPrompt, examplesFromData, query]);
|
|
140
|
+
const handleChange = (0, _useEventCallback.default)(event => {
|
|
141
|
+
setQuery(event.target.value);
|
|
142
|
+
});
|
|
143
|
+
const handleKeyDown = (0, _useEventCallback.default)(event => {
|
|
144
|
+
if (event.code === 'Enter') {
|
|
145
|
+
processPrompt();
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
const handleDone = (0, _useEventCallback.default)(value => {
|
|
149
|
+
setQuery(value);
|
|
150
|
+
if (value) {
|
|
151
|
+
processPrompt();
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
const placeholder = supportsSpeechRecognition ? apiRef.current.getLocaleText('toolbarPromptControlWithRecordingPlaceholder') : apiRef.current.getLocaleText('toolbarPromptControlPlaceholder');
|
|
155
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(GridToolbarPromptControlRoot, {
|
|
156
|
+
ownerState: rootProps,
|
|
157
|
+
className: classes.root,
|
|
158
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(rootProps.slots.baseTextField, {
|
|
159
|
+
variant: "outlined",
|
|
160
|
+
placeholder: isRecording ? apiRef.current.getLocaleText('toolbarPromptControlRecordingPlaceholder') : placeholder,
|
|
161
|
+
"aria-label": apiRef.current.getLocaleText('toolbarPromptControlLabel'),
|
|
162
|
+
disabled: isLoading,
|
|
163
|
+
value: query,
|
|
164
|
+
style: {
|
|
165
|
+
flex: 1
|
|
166
|
+
},
|
|
167
|
+
onChange: handleChange,
|
|
168
|
+
size: "small",
|
|
169
|
+
onKeyDown: handleKeyDown,
|
|
170
|
+
error: !!error,
|
|
171
|
+
helperText: error,
|
|
172
|
+
InputProps: {
|
|
173
|
+
startAdornment: supportsSpeechRecognition && /*#__PURE__*/(0, _jsxRuntime.jsx)(rootProps.slots.baseInputAdornment, {
|
|
174
|
+
position: "start",
|
|
175
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_RecordButton.RecordButton, {
|
|
176
|
+
className: classes.recordButton,
|
|
177
|
+
lang: lang,
|
|
178
|
+
recording: isRecording,
|
|
179
|
+
setRecording: setRecording,
|
|
180
|
+
disabled: isLoading,
|
|
181
|
+
onUpdate: setQuery,
|
|
182
|
+
onDone: handleDone,
|
|
183
|
+
onError: setError
|
|
184
|
+
})
|
|
185
|
+
}),
|
|
186
|
+
endAdornment: /*#__PURE__*/(0, _jsxRuntime.jsx)(rootProps.slots.baseInputAdornment, {
|
|
187
|
+
position: "end",
|
|
188
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(rootProps.slots.baseTooltip, {
|
|
189
|
+
title: apiRef.current.getLocaleText('toolbarPromptControlSendActionLabel'),
|
|
190
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
191
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(rootProps.slots.baseIconButton, {
|
|
192
|
+
className: classes.sendButton,
|
|
193
|
+
disabled: isLoading || isRecording || query === '',
|
|
194
|
+
color: "primary",
|
|
195
|
+
onClick: processPrompt,
|
|
196
|
+
size: "small",
|
|
197
|
+
"aria-label": apiRef.current.getLocaleText('toolbarPromptControlSendActionAriaLabel'),
|
|
198
|
+
edge: "end",
|
|
199
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(rootProps.slots.toolbarPromptSendIcon, {
|
|
200
|
+
fontSize: "small"
|
|
201
|
+
})
|
|
202
|
+
})
|
|
203
|
+
})
|
|
204
|
+
})
|
|
205
|
+
})
|
|
206
|
+
}
|
|
207
|
+
})
|
|
208
|
+
});
|
|
209
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export declare const BrowserSpeechRecognition: any;
|
|
3
|
+
type SpeechRecognitionOptions = {
|
|
4
|
+
onUpdate: (value: string) => void;
|
|
5
|
+
onDone: (value: string) => void;
|
|
6
|
+
onError: (error: string) => void;
|
|
7
|
+
};
|
|
8
|
+
interface RecordButtonProps extends SpeechRecognitionOptions {
|
|
9
|
+
disabled: boolean;
|
|
10
|
+
lang?: string;
|
|
11
|
+
recording: boolean;
|
|
12
|
+
setRecording: (value: boolean) => void;
|
|
13
|
+
className: string;
|
|
14
|
+
}
|
|
15
|
+
declare function RecordButton(props: RecordButtonProps): React.JSX.Element;
|
|
16
|
+
export { RecordButton };
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.BrowserSpeechRecognition = void 0;
|
|
9
|
+
exports.RecordButton = RecordButton;
|
|
10
|
+
var React = _interopRequireWildcard(require("react"));
|
|
11
|
+
var _useTimeout = require("@mui/utils/useTimeout");
|
|
12
|
+
var _useLazyRef = _interopRequireDefault(require("@mui/utils/useLazyRef"));
|
|
13
|
+
var _useGridApiContext = require("../../hooks/utils/useGridApiContext");
|
|
14
|
+
var _useGridRootProps = require("../../hooks/utils/useGridRootProps");
|
|
15
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
16
|
+
const BrowserSpeechRecognition = exports.BrowserSpeechRecognition = globalThis.SpeechRecognition || globalThis.webkitSpeechRecognition;
|
|
17
|
+
function RecordButton(props) {
|
|
18
|
+
const apiRef = (0, _useGridApiContext.useGridApiContext)();
|
|
19
|
+
const rootProps = (0, _useGridRootProps.useGridRootProps)();
|
|
20
|
+
const {
|
|
21
|
+
lang,
|
|
22
|
+
recording,
|
|
23
|
+
setRecording,
|
|
24
|
+
disabled,
|
|
25
|
+
className,
|
|
26
|
+
onDone,
|
|
27
|
+
onUpdate,
|
|
28
|
+
onError
|
|
29
|
+
} = props;
|
|
30
|
+
const buttonRef = React.useRef(null);
|
|
31
|
+
const recognition = (0, _useLazyRef.default)(() => {
|
|
32
|
+
if (!BrowserSpeechRecognition) {
|
|
33
|
+
return {
|
|
34
|
+
start: () => {},
|
|
35
|
+
abort: () => {}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const timeout = new _useTimeout.Timeout();
|
|
39
|
+
const instance = new BrowserSpeechRecognition();
|
|
40
|
+
instance.continuous = true;
|
|
41
|
+
instance.interimResults = true;
|
|
42
|
+
instance.lang = lang;
|
|
43
|
+
let finalResult = '';
|
|
44
|
+
let interimResult = '';
|
|
45
|
+
function start(options) {
|
|
46
|
+
if (recording) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
setRecording(true);
|
|
50
|
+
instance.onresult = event => {
|
|
51
|
+
finalResult = '';
|
|
52
|
+
interimResult = '';
|
|
53
|
+
if (typeof event.results === 'undefined') {
|
|
54
|
+
instance.stop();
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
for (let i = event.resultIndex; i < event.results.length; i += 1) {
|
|
58
|
+
if (event.results[i].isFinal) {
|
|
59
|
+
finalResult += event.results[i][0].transcript;
|
|
60
|
+
} else {
|
|
61
|
+
interimResult += event.results[i][0].transcript;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (finalResult === '') {
|
|
65
|
+
options.onUpdate(interimResult);
|
|
66
|
+
}
|
|
67
|
+
timeout.start(1000, () => instance.stop());
|
|
68
|
+
};
|
|
69
|
+
instance.onsoundend = () => {
|
|
70
|
+
instance.stop();
|
|
71
|
+
};
|
|
72
|
+
instance.onend = () => {
|
|
73
|
+
options.onDone(finalResult);
|
|
74
|
+
setRecording(false);
|
|
75
|
+
};
|
|
76
|
+
instance.onerror = error => {
|
|
77
|
+
options.onError(error.message);
|
|
78
|
+
instance.stop();
|
|
79
|
+
setRecording(false);
|
|
80
|
+
};
|
|
81
|
+
instance.start();
|
|
82
|
+
}
|
|
83
|
+
function abort() {
|
|
84
|
+
instance.abort();
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
start,
|
|
88
|
+
abort
|
|
89
|
+
};
|
|
90
|
+
}).current;
|
|
91
|
+
const handleClick = () => {
|
|
92
|
+
if (!recording) {
|
|
93
|
+
recognition.start({
|
|
94
|
+
onDone,
|
|
95
|
+
onUpdate,
|
|
96
|
+
onError
|
|
97
|
+
});
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
recognition.abort();
|
|
101
|
+
};
|
|
102
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(rootProps.slots.baseTooltip, {
|
|
103
|
+
title: recording ? apiRef.current.getLocaleText('toolbarPromptControlRecordButtonActiveLabel') : apiRef.current.getLocaleText('toolbarPromptControlRecordButtonDefaultLabel'),
|
|
104
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
105
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(rootProps.slots.baseIconButton, {
|
|
106
|
+
color: recording ? 'primary' : 'default',
|
|
107
|
+
className: className,
|
|
108
|
+
disabled: disabled,
|
|
109
|
+
onClick: handleClick,
|
|
110
|
+
ref: buttonRef,
|
|
111
|
+
size: "small",
|
|
112
|
+
edge: "start",
|
|
113
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(rootProps.slots.toolbarPromptRecordIcon, {
|
|
114
|
+
fontSize: "small"
|
|
115
|
+
})
|
|
116
|
+
})
|
|
117
|
+
})
|
|
118
|
+
});
|
|
119
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { GridToolbarPromptControl as Unstable_GridToolbarPromptControl } from './GridToolbarPromptControl';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "Unstable_GridToolbarPromptControl", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _GridToolbarPromptControl.GridToolbarPromptControl;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _GridToolbarPromptControl = require("./GridToolbarPromptControl");
|
|
@@ -452,14 +452,6 @@ process.env.NODE_ENV !== "production" ? DataGridPremiumRaw.propTypes = {
|
|
|
452
452
|
clipboardExport: PropTypes.bool,
|
|
453
453
|
csvExport: PropTypes.bool
|
|
454
454
|
}), PropTypes.bool]),
|
|
455
|
-
/**
|
|
456
|
-
* If `select`, a group header checkbox in indeterminate state (like "Select All" checkbox)
|
|
457
|
-
* will select all the rows under it.
|
|
458
|
-
* If `deselect`, it will deselect all the rows under it.
|
|
459
|
-
* Works only if `checkboxSelection` is enabled.
|
|
460
|
-
* @default "deselect"
|
|
461
|
-
*/
|
|
462
|
-
indeterminateCheckboxAction: PropTypes.oneOf(['deselect', 'select']),
|
|
463
455
|
/**
|
|
464
456
|
* The initial state of the DataGridPremium.
|
|
465
457
|
* The data in it is set in the state on initialization but isn't controlled.
|
|
@@ -964,7 +956,7 @@ process.env.NODE_ENV !== "production" ? DataGridPremiumRaw.propTypes = {
|
|
|
964
956
|
* - Deselecting a descendant of a selected parent deselects the parent automatically.
|
|
965
957
|
*
|
|
966
958
|
* Works with tree data and row grouping on the client-side only.
|
|
967
|
-
* @default { parents:
|
|
959
|
+
* @default { parents: true, descendants: true }
|
|
968
960
|
*/
|
|
969
961
|
rowSelectionPropagation: PropTypes.shape({
|
|
970
962
|
descendants: PropTypes.bool,
|
|
@@ -1081,7 +1073,15 @@ process.env.NODE_ENV !== "production" ? DataGridPremiumRaw.propTypes = {
|
|
|
1081
1073
|
* If `true`, the Data Grid will auto span the cells over the rows having the same value.
|
|
1082
1074
|
* @default false
|
|
1083
1075
|
*/
|
|
1084
|
-
unstable_rowSpanning: PropTypes.bool
|
|
1076
|
+
unstable_rowSpanning: PropTypes.bool,
|
|
1077
|
+
/**
|
|
1078
|
+
* If `true`, the Data Grid enables column virtualization when `getRowHeight` is set to `() => 'auto'`.
|
|
1079
|
+
* By default, column virtualization is disabled when dynamic row height is enabled to measure the row height correctly.
|
|
1080
|
+
* For datasets with a large number of columns, this can cause performance issues.
|
|
1081
|
+
* The downside of enabling this prop is that the row height will be estimated based the cells that are currently rendered, which can cause row height change when scrolling horizontally.
|
|
1082
|
+
* @default false
|
|
1083
|
+
*/
|
|
1084
|
+
virtualizeColumnsWithAutoRowHeight: PropTypes.bool
|
|
1085
1085
|
} : void 0;
|
|
1086
1086
|
/**
|
|
1087
1087
|
* Demos:
|
package/esm/components/index.js
CHANGED