@mui/x-data-grid 6.3.1 → 6.4.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 +57 -0
- package/DataGrid/DataGrid.js +20 -1
- package/DataGrid/useDataGridComponent.js +2 -2
- package/DataGrid/useDataGridProps.js +3 -1
- package/colDef/gridBooleanColDef.js +19 -1
- package/colDef/gridDateColDef.js +6 -2
- package/colDef/gridSingleSelectColDef.js +21 -1
- package/components/base/GridBody.js +2 -1
- package/components/containers/GridRootStyles.js +1 -0
- package/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.js +1 -2
- package/components/panel/filterPanel/GridFilterInputMultipleValue.js +1 -2
- package/hooks/core/pipeProcessing/gridPipeProcessingApi.d.ts +12 -1
- package/hooks/features/clipboard/useGridClipboard.d.ts +2 -1
- package/hooks/features/clipboard/useGridClipboard.js +43 -26
- package/hooks/features/dimensions/useGridDimensions.js +2 -4
- package/hooks/features/editing/useGridCellEditing.js +7 -3
- package/hooks/features/editing/useGridRowEditing.js +7 -3
- package/hooks/features/export/serializers/csvSerializer.d.ts +5 -0
- package/hooks/features/export/serializers/csvSerializer.js +46 -6
- package/hooks/features/export/useGridCsvExport.d.ts +2 -1
- package/hooks/features/export/useGridCsvExport.js +7 -5
- package/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +11 -0
- package/index.js +1 -1
- package/internals/index.d.ts +3 -2
- package/internals/index.js +3 -2
- package/joy/icons.d.ts +33 -0
- package/joy/icons.js +433 -0
- package/joy/joySlots.js +114 -4
- package/legacy/DataGrid/DataGrid.js +20 -1
- package/legacy/DataGrid/useDataGridComponent.js +2 -2
- package/legacy/DataGrid/useDataGridProps.js +3 -1
- package/legacy/colDef/gridBooleanColDef.js +21 -1
- package/legacy/colDef/gridDateColDef.js +10 -2
- package/legacy/colDef/gridSingleSelectColDef.js +21 -1
- package/legacy/components/base/GridBody.js +2 -1
- package/legacy/components/containers/GridRootStyles.js +1 -0
- package/legacy/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.js +1 -2
- package/legacy/components/panel/filterPanel/GridFilterInputMultipleValue.js +1 -2
- package/legacy/hooks/features/clipboard/useGridClipboard.js +44 -26
- package/legacy/hooks/features/dimensions/useGridDimensions.js +2 -4
- package/legacy/hooks/features/editing/useGridCellEditing.js +7 -3
- package/legacy/hooks/features/editing/useGridRowEditing.js +7 -3
- package/legacy/hooks/features/export/serializers/csvSerializer.js +43 -6
- package/legacy/hooks/features/export/useGridCsvExport.js +8 -5
- package/legacy/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +10 -0
- package/legacy/index.js +1 -1
- package/legacy/internals/index.js +3 -2
- package/legacy/joy/icons.js +432 -0
- package/legacy/joy/joySlots.js +118 -4
- package/legacy/locales/deDE.js +2 -2
- package/legacy/locales/frFR.js +6 -6
- package/legacy/locales/ptBR.js +1 -1
- package/legacy/locales/ukUA.js +8 -9
- package/legacy/material/index.js +3 -1
- package/legacy/models/api/index.js +0 -1
- package/legacy/utils/domUtils.js +14 -1
- package/locales/deDE.js +2 -2
- package/locales/frFR.js +6 -6
- package/locales/ptBR.js +1 -1
- package/locales/ukUA.js +8 -9
- package/material/index.d.ts +1 -0
- package/material/index.js +3 -1
- package/models/api/gridApiCommon.d.ts +1 -2
- package/models/api/gridCoreApi.d.ts +4 -0
- package/models/api/index.d.ts +0 -1
- package/models/api/index.js +0 -1
- package/models/events/gridEventLookup.d.ts +6 -0
- package/models/gridSlotsComponent.d.ts +5 -0
- package/models/gridSlotsComponentsProps.d.ts +4 -0
- package/models/props/DataGridProps.d.ts +19 -0
- package/modern/DataGrid/DataGrid.js +20 -1
- package/modern/DataGrid/useDataGridComponent.js +2 -2
- package/modern/DataGrid/useDataGridProps.js +3 -1
- package/modern/colDef/gridBooleanColDef.js +19 -1
- package/modern/colDef/gridDateColDef.js +6 -2
- package/modern/colDef/gridSingleSelectColDef.js +21 -1
- package/modern/components/base/GridBody.js +2 -1
- package/modern/components/containers/GridRootStyles.js +1 -0
- package/modern/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.js +1 -2
- package/modern/components/panel/filterPanel/GridFilterInputMultipleValue.js +1 -2
- package/modern/hooks/features/clipboard/useGridClipboard.js +43 -26
- package/modern/hooks/features/dimensions/useGridDimensions.js +1 -3
- package/modern/hooks/features/editing/useGridCellEditing.js +7 -3
- package/modern/hooks/features/editing/useGridRowEditing.js +7 -3
- package/modern/hooks/features/export/serializers/csvSerializer.js +44 -6
- package/modern/hooks/features/export/useGridCsvExport.js +7 -5
- package/modern/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +11 -0
- package/modern/index.js +1 -1
- package/modern/internals/index.js +3 -2
- package/modern/joy/icons.js +433 -0
- package/modern/joy/joySlots.js +110 -4
- package/modern/locales/deDE.js +2 -2
- package/modern/locales/frFR.js +6 -6
- package/modern/locales/ptBR.js +1 -1
- package/modern/locales/ukUA.js +8 -9
- package/modern/material/index.js +3 -1
- package/modern/models/api/index.js +0 -1
- package/modern/utils/domUtils.js +13 -1
- package/node/DataGrid/DataGrid.js +20 -1
- package/node/DataGrid/useDataGridComponent.js +2 -2
- package/node/DataGrid/useDataGridProps.js +3 -1
- package/node/colDef/gridBooleanColDef.js +19 -1
- package/node/colDef/gridDateColDef.js +6 -2
- package/node/colDef/gridSingleSelectColDef.js +21 -1
- package/node/components/base/GridBody.js +2 -1
- package/node/components/containers/GridRootStyles.js +1 -0
- package/node/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.js +1 -2
- package/node/components/panel/filterPanel/GridFilterInputMultipleValue.js +1 -2
- package/node/hooks/features/clipboard/useGridClipboard.js +42 -25
- package/node/hooks/features/dimensions/useGridDimensions.js +1 -3
- package/node/hooks/features/editing/useGridCellEditing.js +7 -3
- package/node/hooks/features/editing/useGridRowEditing.js +7 -3
- package/node/hooks/features/export/serializers/csvSerializer.js +46 -6
- package/node/hooks/features/export/useGridCsvExport.js +6 -3
- package/node/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +11 -0
- package/node/index.js +1 -1
- package/node/internals/index.js +23 -1
- package/node/joy/icons.js +471 -0
- package/node/joy/joySlots.js +110 -3
- package/node/locales/deDE.js +2 -2
- package/node/locales/frFR.js +6 -6
- package/node/locales/ptBR.js +1 -1
- package/node/locales/ukUA.js +8 -9
- package/node/material/index.js +3 -1
- package/node/models/api/index.js +0 -11
- package/node/utils/domUtils.js +15 -1
- package/package.json +1 -1
- package/utils/domUtils.d.ts +1 -0
- package/utils/domUtils.js +13 -1
- package/legacy/models/api/gridClipboardApi.js +0 -1
- package/models/api/gridClipboardApi.d.ts +0 -11
- package/models/api/gridClipboardApi.js +0 -1
- package/modern/models/api/gridClipboardApi.js +0 -1
- package/node/models/api/gridClipboardApi.js +0 -5
|
@@ -68,6 +68,11 @@ DataGridRaw.propTypes = {
|
|
|
68
68
|
* Override or extend the styles applied to the component.
|
|
69
69
|
*/
|
|
70
70
|
classes: PropTypes.object,
|
|
71
|
+
/**
|
|
72
|
+
* The character used to separate cell values when copying to the clipboard.
|
|
73
|
+
* @default '\t'
|
|
74
|
+
*/
|
|
75
|
+
clipboardCopyCellDelimiter: PropTypes.string,
|
|
71
76
|
/**
|
|
72
77
|
* Number of extra columns to be rendered before/after the visible slice.
|
|
73
78
|
* @default 3
|
|
@@ -328,6 +333,11 @@ DataGridRaw.propTypes = {
|
|
|
328
333
|
* @param {GridCallbackDetails} details Additional details for this callback.
|
|
329
334
|
*/
|
|
330
335
|
onCellModesModelChange: PropTypes.func,
|
|
336
|
+
/**
|
|
337
|
+
* Callback called when the data is copied to the clipboard.
|
|
338
|
+
* @param {string} data The data copied to the clipboard.
|
|
339
|
+
*/
|
|
340
|
+
onClipboardCopy: PropTypes.func,
|
|
331
341
|
/**
|
|
332
342
|
* Callback fired when a click event comes from a column header element.
|
|
333
343
|
* @param {GridColumnHeaderParams} params With all properties from [[GridColumnHeaderParams]].
|
|
@@ -613,5 +623,14 @@ DataGridRaw.propTypes = {
|
|
|
613
623
|
/**
|
|
614
624
|
* The system prop that allows defining system overrides as well as additional CSS styles.
|
|
615
625
|
*/
|
|
616
|
-
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
|
|
626
|
+
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
|
627
|
+
/**
|
|
628
|
+
* If `true`, the grid will not use `valueFormatter` when exporting to CSV or copying to clipboard.
|
|
629
|
+
* If an object is provided, you can choose to ignore the `valueFormatter` for CSV export or clipboard export.
|
|
630
|
+
* @default: false
|
|
631
|
+
*/
|
|
632
|
+
unstable_ignoreValueFormatterDuringExport: PropTypes.oneOfType([PropTypes.shape({
|
|
633
|
+
clipboardExport: PropTypes.bool,
|
|
634
|
+
csvExport: PropTypes.bool
|
|
635
|
+
}), PropTypes.bool])
|
|
617
636
|
};
|
|
@@ -67,9 +67,9 @@ export var useDataGridComponent = function useDataGridComponent(inputApiRef, pro
|
|
|
67
67
|
useGridRowsMeta(privateApiRef, props);
|
|
68
68
|
useGridScroll(privateApiRef, props);
|
|
69
69
|
useGridColumnMenu(privateApiRef);
|
|
70
|
-
useGridCsvExport(privateApiRef);
|
|
70
|
+
useGridCsvExport(privateApiRef, props);
|
|
71
71
|
useGridPrintExport(privateApiRef, props);
|
|
72
|
-
useGridClipboard(privateApiRef);
|
|
72
|
+
useGridClipboard(privateApiRef, props);
|
|
73
73
|
useGridDimensions(privateApiRef, props);
|
|
74
74
|
useGridEvents(privateApiRef, props);
|
|
75
75
|
useGridStatePersistence(privateApiRef);
|
|
@@ -66,7 +66,9 @@ export var DATA_GRID_PROPS_DEFAULT_VALUES = {
|
|
|
66
66
|
disableColumnReorder: false,
|
|
67
67
|
disableColumnResize: false,
|
|
68
68
|
keepNonExistentRowsSelected: false,
|
|
69
|
-
keepColumnPositionIfDraggedOutside: false
|
|
69
|
+
keepColumnPositionIfDraggedOutside: false,
|
|
70
|
+
unstable_ignoreValueFormatterDuringExport: false,
|
|
71
|
+
clipboardCopyCellDelimiter: '\t'
|
|
70
72
|
};
|
|
71
73
|
var defaultSlots = uncapitalizeObjectKeys(DATA_GRID_DEFAULT_SLOTS_COMPONENTS);
|
|
72
74
|
export var useDataGridProps = function useDataGridProps(inProps) {
|
|
@@ -9,6 +9,22 @@ function gridBooleanFormatter(_ref) {
|
|
|
9
9
|
api = _ref.api;
|
|
10
10
|
return value ? api.getLocaleText('booleanCellTrueLabel') : api.getLocaleText('booleanCellFalseLabel');
|
|
11
11
|
}
|
|
12
|
+
var stringToBoolean = function stringToBoolean(value) {
|
|
13
|
+
switch (value.toLowerCase().trim()) {
|
|
14
|
+
case 'true':
|
|
15
|
+
case 'yes':
|
|
16
|
+
case '1':
|
|
17
|
+
return true;
|
|
18
|
+
case 'false':
|
|
19
|
+
case 'no':
|
|
20
|
+
case '0':
|
|
21
|
+
case 'null':
|
|
22
|
+
case 'undefined':
|
|
23
|
+
return false;
|
|
24
|
+
default:
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
12
28
|
export var GRID_BOOLEAN_COL_DEF = _extends({}, GRID_STRING_COL_DEF, {
|
|
13
29
|
type: 'boolean',
|
|
14
30
|
align: 'center',
|
|
@@ -20,5 +36,9 @@ export var GRID_BOOLEAN_COL_DEF = _extends({}, GRID_STRING_COL_DEF, {
|
|
|
20
36
|
filterOperators: getGridBooleanOperators(),
|
|
21
37
|
getApplyQuickFilterFn: undefined,
|
|
22
38
|
// @ts-ignore
|
|
23
|
-
aggregable: false
|
|
39
|
+
aggregable: false,
|
|
40
|
+
// @ts-ignore
|
|
41
|
+
pastedValueParser: function pastedValueParser(value) {
|
|
42
|
+
return stringToBoolean(value);
|
|
43
|
+
}
|
|
24
44
|
});
|
|
@@ -48,7 +48,11 @@ export var GRID_DATE_COL_DEF = _extends({}, GRID_STRING_COL_DEF, {
|
|
|
48
48
|
valueFormatter: gridDateFormatter,
|
|
49
49
|
filterOperators: getGridDateOperators(),
|
|
50
50
|
renderEditCell: renderEditDateCell,
|
|
51
|
-
getApplyQuickFilterFn: undefined
|
|
51
|
+
getApplyQuickFilterFn: undefined,
|
|
52
|
+
// @ts-ignore
|
|
53
|
+
pastedValueParser: function pastedValueParser(value) {
|
|
54
|
+
return new Date(value);
|
|
55
|
+
}
|
|
52
56
|
});
|
|
53
57
|
export var GRID_DATETIME_COL_DEF = _extends({}, GRID_STRING_COL_DEF, {
|
|
54
58
|
type: 'dateTime',
|
|
@@ -56,5 +60,9 @@ export var GRID_DATETIME_COL_DEF = _extends({}, GRID_STRING_COL_DEF, {
|
|
|
56
60
|
valueFormatter: gridDateTimeFormatter,
|
|
57
61
|
filterOperators: getGridDateOperators(true),
|
|
58
62
|
renderEditCell: renderEditDateCell,
|
|
59
|
-
getApplyQuickFilterFn: undefined
|
|
63
|
+
getApplyQuickFilterFn: undefined,
|
|
64
|
+
// @ts-ignore
|
|
65
|
+
pastedValueParser: function pastedValueParser(value) {
|
|
66
|
+
return new Date(value);
|
|
67
|
+
}
|
|
60
68
|
});
|
|
@@ -52,5 +52,25 @@ export var GRID_SINGLE_SELECT_COL_DEF = _extends({}, GRID_STRING_COL_DEF, {
|
|
|
52
52
|
return valueOption ? colDef.getOptionLabel(valueOption) : '';
|
|
53
53
|
},
|
|
54
54
|
renderEditCell: renderEditSingleSelectCell,
|
|
55
|
-
filterOperators: getGridSingleSelectOperators()
|
|
55
|
+
filterOperators: getGridSingleSelectOperators(),
|
|
56
|
+
// @ts-ignore
|
|
57
|
+
pastedValueParser: function pastedValueParser(value, params) {
|
|
58
|
+
var colDef = params.colDef;
|
|
59
|
+
var colDefValueOptions = colDef.valueOptions;
|
|
60
|
+
var valueOptions = typeof colDefValueOptions === 'function' ? colDefValueOptions({
|
|
61
|
+
field: colDef.field
|
|
62
|
+
}) : colDefValueOptions || [];
|
|
63
|
+
var getOptionValue = colDef.getOptionValue;
|
|
64
|
+
var valueOption = valueOptions.find(function (option) {
|
|
65
|
+
if (getOptionValue(option) === value) {
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
return false;
|
|
69
|
+
});
|
|
70
|
+
if (valueOption) {
|
|
71
|
+
return value;
|
|
72
|
+
}
|
|
73
|
+
// do not paste the value if it is not in the valueOptions
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
56
76
|
});
|
|
@@ -91,7 +91,8 @@ function GridBody(props) {
|
|
|
91
91
|
apiRef.current.register('private', {
|
|
92
92
|
columnHeadersContainerElementRef: columnsContainerRef,
|
|
93
93
|
columnHeadersElementRef: columnHeadersRef,
|
|
94
|
-
virtualScrollerRef: virtualScrollerRef
|
|
94
|
+
virtualScrollerRef: virtualScrollerRef,
|
|
95
|
+
mainElementRef: rootRef
|
|
95
96
|
});
|
|
96
97
|
var hasDimensions = !!apiRef.current.getRootDimensions();
|
|
97
98
|
return /*#__PURE__*/_jsxs(GridMainContainer, {
|
|
@@ -39,6 +39,7 @@ export var GridRootStyles = styled('div', {
|
|
|
39
39
|
outline: 'none',
|
|
40
40
|
height: '100%',
|
|
41
41
|
display: 'flex',
|
|
42
|
+
overflow: 'hidden',
|
|
42
43
|
flexDirection: 'column',
|
|
43
44
|
overflowAnchor: 'none'
|
|
44
45
|
}, _defineProperty(_extends2, "&.".concat(gridClasses.autoHeight), _defineProperty({
|
|
@@ -4,7 +4,6 @@ var _excluded = ["item", "applyValue", "type", "apiRef", "focusElementRef", "col
|
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
6
|
import Autocomplete, { createFilterOptions } from '@mui/material/Autocomplete';
|
|
7
|
-
import Chip from '@mui/material/Chip';
|
|
8
7
|
import { unstable_useId as useId } from '@mui/utils';
|
|
9
8
|
import { isSingleSelectColDef } from './filterPanelUtils';
|
|
10
9
|
import { useGridRootProps } from '../../../hooks/utils/useGridRootProps';
|
|
@@ -108,7 +107,7 @@ function GridFilterInputMultipleSingleSelect(props) {
|
|
|
108
107
|
getOptionLabel: getOptionLabel,
|
|
109
108
|
renderTags: function renderTags(value, getTagProps) {
|
|
110
109
|
return value.map(function (option, index) {
|
|
111
|
-
return /*#__PURE__*/_jsx(
|
|
110
|
+
return /*#__PURE__*/_jsx(rootProps.slots.baseChip, _extends({
|
|
112
111
|
variant: "outlined",
|
|
113
112
|
size: "small",
|
|
114
113
|
label: getOptionLabel(option)
|
|
@@ -6,7 +6,6 @@ var _excluded = ["item", "applyValue", "type", "apiRef", "focusElementRef", "col
|
|
|
6
6
|
import * as React from 'react';
|
|
7
7
|
import PropTypes from 'prop-types';
|
|
8
8
|
import Autocomplete from '@mui/material/Autocomplete';
|
|
9
|
-
import Chip from '@mui/material/Chip';
|
|
10
9
|
import { unstable_useId as useId } from '@mui/utils';
|
|
11
10
|
import { useGridRootProps } from '../../../hooks/utils/useGridRootProps';
|
|
12
11
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
@@ -59,7 +58,7 @@ function GridFilterInputMultipleValue(props) {
|
|
|
59
58
|
onChange: handleChange,
|
|
60
59
|
renderTags: function renderTags(value, getTagProps) {
|
|
61
60
|
return value.map(function (option, index) {
|
|
62
|
-
return /*#__PURE__*/_jsx(
|
|
61
|
+
return /*#__PURE__*/_jsx(rootProps.slots.baseChip, _extends({
|
|
63
62
|
variant: "outlined",
|
|
64
63
|
size: "small",
|
|
65
64
|
label: option
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
1
2
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
3
|
+
import { useGridApiOptionHandler, useGridNativeEventListener } from '../../utils';
|
|
4
|
+
import { gridFocusCellSelector } from '../focus/gridFocusStateSelector';
|
|
5
|
+
import { serializeCellValue } from '../export/serializers/csvSerializer';
|
|
3
6
|
function writeToClipboardPolyfill(data) {
|
|
4
7
|
var span = document.createElement('span');
|
|
5
8
|
span.style.whiteSpace = 'pre';
|
|
@@ -18,6 +21,15 @@ function writeToClipboardPolyfill(data) {
|
|
|
18
21
|
document.body.removeChild(span);
|
|
19
22
|
}
|
|
20
23
|
}
|
|
24
|
+
function copyToClipboard(data) {
|
|
25
|
+
if (navigator.clipboard) {
|
|
26
|
+
navigator.clipboard.writeText(data).catch(function () {
|
|
27
|
+
writeToClipboardPolyfill(data);
|
|
28
|
+
});
|
|
29
|
+
} else {
|
|
30
|
+
writeToClipboardPolyfill(data);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
21
33
|
function hasNativeSelection(element) {
|
|
22
34
|
var _window$getSelection;
|
|
23
35
|
// When getSelection is called on an <iframe> that is not displayed Firefox will return null.
|
|
@@ -38,24 +50,11 @@ function hasNativeSelection(element) {
|
|
|
38
50
|
* @requires useGridCsvExport (method)
|
|
39
51
|
* @requires useGridSelection (method)
|
|
40
52
|
*/
|
|
41
|
-
export var useGridClipboard = function useGridClipboard(apiRef) {
|
|
42
|
-
var
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
var data = apiRef.current.getDataAsCsv({
|
|
47
|
-
includeHeaders: false,
|
|
48
|
-
delimiter: '\t'
|
|
49
|
-
});
|
|
50
|
-
if (navigator.clipboard) {
|
|
51
|
-
navigator.clipboard.writeText(data).catch(function () {
|
|
52
|
-
writeToClipboardPolyfill(data);
|
|
53
|
-
});
|
|
54
|
-
} else {
|
|
55
|
-
writeToClipboardPolyfill(data);
|
|
56
|
-
}
|
|
57
|
-
}, [apiRef]);
|
|
58
|
-
var handleKeydown = React.useCallback(function (event) {
|
|
53
|
+
export var useGridClipboard = function useGridClipboard(apiRef, props) {
|
|
54
|
+
var ignoreValueFormatterProp = props.unstable_ignoreValueFormatterDuringExport;
|
|
55
|
+
var ignoreValueFormatter = (_typeof(ignoreValueFormatterProp) === 'object' ? ignoreValueFormatterProp == null ? void 0 : ignoreValueFormatterProp.clipboardExport : ignoreValueFormatterProp) || false;
|
|
56
|
+
var clipboardCopyCellDelimiter = props.clipboardCopyCellDelimiter;
|
|
57
|
+
var handleCopy = React.useCallback(function (event) {
|
|
59
58
|
var isModifierKeyPressed = event.ctrlKey || event.metaKey;
|
|
60
59
|
// event.code === 'KeyC' is not enough as event.code assume a QWERTY keyboard layout which would
|
|
61
60
|
// be wrong with a Dvorak keyboard (as if pressing J).
|
|
@@ -67,11 +66,30 @@ export var useGridClipboard = function useGridClipboard(apiRef) {
|
|
|
67
66
|
if (hasNativeSelection(event.target)) {
|
|
68
67
|
return;
|
|
69
68
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
69
|
+
var textToCopy = '';
|
|
70
|
+
var selectedRows = apiRef.current.getSelectedRows();
|
|
71
|
+
if (selectedRows.size > 0) {
|
|
72
|
+
textToCopy = apiRef.current.getDataAsCsv({
|
|
73
|
+
includeHeaders: false,
|
|
74
|
+
// TODO: make it configurable
|
|
75
|
+
delimiter: clipboardCopyCellDelimiter
|
|
76
|
+
});
|
|
77
|
+
} else {
|
|
78
|
+
var focusedCell = gridFocusCellSelector(apiRef);
|
|
79
|
+
if (focusedCell) {
|
|
80
|
+
var cellParams = apiRef.current.getCellParams(focusedCell.id, focusedCell.field);
|
|
81
|
+
textToCopy = serializeCellValue(cellParams, {
|
|
82
|
+
delimiterCharacter: clipboardCopyCellDelimiter,
|
|
83
|
+
ignoreValueFormatter: ignoreValueFormatter
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
textToCopy = apiRef.current.unstable_applyPipeProcessors('clipboardCopy', textToCopy);
|
|
88
|
+
if (textToCopy) {
|
|
89
|
+
copyToClipboard(textToCopy);
|
|
90
|
+
apiRef.current.publishEvent('clipboardCopy', textToCopy);
|
|
91
|
+
}
|
|
92
|
+
}, [apiRef, ignoreValueFormatter, clipboardCopyCellDelimiter]);
|
|
93
|
+
useGridNativeEventListener(apiRef, apiRef.current.rootElementRef, 'keydown', handleCopy);
|
|
94
|
+
useGridApiOptionHandler(apiRef, 'clipboardCopy', props.onClipboardCopy);
|
|
77
95
|
};
|
|
@@ -11,7 +11,6 @@ import { getVisibleRows } from '../../utils/useGridVisibleRows';
|
|
|
11
11
|
import { gridRowsMetaSelector } from '../rows/gridRowsMetaSelector';
|
|
12
12
|
import { calculatePinnedRowsHeight } from '../rows/gridRowsUtils';
|
|
13
13
|
import { getTotalHeaderHeight } from '../columns/gridColumnsUtils';
|
|
14
|
-
import { gridClasses } from '../../../constants/gridClasses';
|
|
15
14
|
var isTestEnvironment = process.env.NODE_ENV === 'test';
|
|
16
15
|
var hasScroll = function hasScroll(_ref) {
|
|
17
16
|
var content = _ref.content,
|
|
@@ -158,9 +157,8 @@ export function useGridDimensions(apiRef, props) {
|
|
|
158
157
|
return Math.min(maximumPageSizeWithoutScrollBar, currentPage.rows.length);
|
|
159
158
|
}, [apiRef, props.pagination, props.paginationMode, props.getRowHeight, rowHeight]);
|
|
160
159
|
var computeSizeAndPublishResizeEvent = React.useCallback(function () {
|
|
161
|
-
var _apiRef$current$
|
|
162
|
-
var
|
|
163
|
-
var mainEl = rootEl == null ? void 0 : rootEl.querySelector(".".concat(gridClasses.main));
|
|
160
|
+
var _apiRef$current$mainE, _previousSize$current, _previousSize$current2;
|
|
161
|
+
var mainEl = (_apiRef$current$mainE = apiRef.current.mainElementRef) == null ? void 0 : _apiRef$current$mainE.current;
|
|
164
162
|
if (!mainEl) {
|
|
165
163
|
return;
|
|
166
164
|
}
|
|
@@ -97,10 +97,14 @@ export var useGridCellEditing = function useGridCellEditing(apiRef, props) {
|
|
|
97
97
|
}
|
|
98
98
|
} else if (params.isEditable) {
|
|
99
99
|
var _reason;
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
var canStartEditing = apiRef.current.unstable_applyPipeProcessors('canStartEditing', true, {
|
|
101
|
+
event: event,
|
|
102
|
+
cellParams: params,
|
|
103
|
+
editMode: 'cell'
|
|
104
|
+
});
|
|
105
|
+
if (!canStartEditing) {
|
|
106
|
+
return;
|
|
102
107
|
}
|
|
103
|
-
|
|
104
108
|
if (isPrintableKey(event)) {
|
|
105
109
|
_reason = GridCellEditStartReasons.printableKeyDown;
|
|
106
110
|
} else if ((event.ctrlKey || event.metaKey) && event.key === 'v') {
|
|
@@ -153,10 +153,14 @@ export var useGridRowEditing = function useGridRowEditing(apiRef, props) {
|
|
|
153
153
|
}
|
|
154
154
|
} else if (params.isEditable) {
|
|
155
155
|
var _reason;
|
|
156
|
-
|
|
157
|
-
|
|
156
|
+
var canStartEditing = apiRef.current.unstable_applyPipeProcessors('canStartEditing', true, {
|
|
157
|
+
event: event,
|
|
158
|
+
cellParams: params,
|
|
159
|
+
editMode: 'row'
|
|
160
|
+
});
|
|
161
|
+
if (!canStartEditing) {
|
|
162
|
+
return;
|
|
158
163
|
}
|
|
159
|
-
|
|
160
164
|
if (isPrintableKey(event)) {
|
|
161
165
|
_reason = GridRowEditStartReasons.printableKeyDown;
|
|
162
166
|
} else if ((event.ctrlKey || event.metaKey) && event.key === 'v') {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GRID_CHECKBOX_SELECTION_COL_DEF } from '../../../../colDef';
|
|
2
2
|
import { buildWarning } from '../../../../utils/warning';
|
|
3
|
-
|
|
3
|
+
function sanitizeCellValue(value, delimiterCharacter) {
|
|
4
4
|
if (typeof value === 'string') {
|
|
5
5
|
var formattedValue = value.replace(/"/g, '""');
|
|
6
6
|
|
|
@@ -13,9 +13,36 @@ var serializeCellValue = function serializeCellValue(value, delimiterCharacter)
|
|
|
13
13
|
return formattedValue;
|
|
14
14
|
}
|
|
15
15
|
return value;
|
|
16
|
+
}
|
|
17
|
+
export var serializeCellValue = function serializeCellValue(cellParams, options) {
|
|
18
|
+
var delimiterCharacter = options.delimiterCharacter,
|
|
19
|
+
ignoreValueFormatter = options.ignoreValueFormatter;
|
|
20
|
+
var value;
|
|
21
|
+
if (ignoreValueFormatter) {
|
|
22
|
+
var _cellParams$value2;
|
|
23
|
+
var columnType = cellParams.colDef.type;
|
|
24
|
+
if (columnType === 'number') {
|
|
25
|
+
value = String(cellParams.value);
|
|
26
|
+
} else if (columnType === 'date' || columnType === 'dateTime') {
|
|
27
|
+
var _cellParams$value;
|
|
28
|
+
value = (_cellParams$value = cellParams.value) == null ? void 0 : _cellParams$value.toISOString();
|
|
29
|
+
} else if (typeof ((_cellParams$value2 = cellParams.value) == null ? void 0 : _cellParams$value2.toString) === 'function') {
|
|
30
|
+
value = cellParams.value.toString();
|
|
31
|
+
} else {
|
|
32
|
+
value = cellParams.value;
|
|
33
|
+
}
|
|
34
|
+
} else {
|
|
35
|
+
value = cellParams.formattedValue;
|
|
36
|
+
}
|
|
37
|
+
return sanitizeCellValue(value, delimiterCharacter);
|
|
16
38
|
};
|
|
17
39
|
var objectFormattedValueWarning = buildWarning(['MUI: When the value of a field is an object or a `renderCell` is provided, the CSV export might not display the value correctly.', 'You can provide a `valueFormatter` with a string representation to be used.']);
|
|
18
|
-
var serializeRow = function serializeRow(
|
|
40
|
+
var serializeRow = function serializeRow(_ref) {
|
|
41
|
+
var id = _ref.id,
|
|
42
|
+
columns = _ref.columns,
|
|
43
|
+
getCellParams = _ref.getCellParams,
|
|
44
|
+
delimiterCharacter = _ref.delimiterCharacter,
|
|
45
|
+
ignoreValueFormatter = _ref.ignoreValueFormatter;
|
|
19
46
|
return columns.map(function (column) {
|
|
20
47
|
var cellParams = getCellParams(id, column.field);
|
|
21
48
|
if (process.env.NODE_ENV !== 'production') {
|
|
@@ -23,7 +50,10 @@ var serializeRow = function serializeRow(id, columns, getCellParams, delimiterCh
|
|
|
23
50
|
objectFormattedValueWarning();
|
|
24
51
|
}
|
|
25
52
|
}
|
|
26
|
-
return serializeCellValue(cellParams
|
|
53
|
+
return serializeCellValue(cellParams, {
|
|
54
|
+
delimiterCharacter: delimiterCharacter,
|
|
55
|
+
ignoreValueFormatter: ignoreValueFormatter
|
|
56
|
+
});
|
|
27
57
|
});
|
|
28
58
|
};
|
|
29
59
|
export function buildCSV(options) {
|
|
@@ -31,9 +61,16 @@ export function buildCSV(options) {
|
|
|
31
61
|
rowIds = options.rowIds,
|
|
32
62
|
getCellParams = options.getCellParams,
|
|
33
63
|
delimiterCharacter = options.delimiterCharacter,
|
|
34
|
-
includeHeaders = options.includeHeaders
|
|
64
|
+
includeHeaders = options.includeHeaders,
|
|
65
|
+
ignoreValueFormatter = options.ignoreValueFormatter;
|
|
35
66
|
var CSVBody = rowIds.reduce(function (acc, id) {
|
|
36
|
-
return "".concat(acc).concat(serializeRow(
|
|
67
|
+
return "".concat(acc).concat(serializeRow({
|
|
68
|
+
id: id,
|
|
69
|
+
columns: columns,
|
|
70
|
+
getCellParams: getCellParams,
|
|
71
|
+
delimiterCharacter: delimiterCharacter,
|
|
72
|
+
ignoreValueFormatter: ignoreValueFormatter
|
|
73
|
+
}).join(delimiterCharacter), "\r\n");
|
|
37
74
|
}, '').trim();
|
|
38
75
|
if (!includeHeaders) {
|
|
39
76
|
return CSVBody;
|
|
@@ -41,7 +78,7 @@ export function buildCSV(options) {
|
|
|
41
78
|
var CSVHead = "".concat(columns.filter(function (column) {
|
|
42
79
|
return column.field !== GRID_CHECKBOX_SELECTION_COL_DEF.field;
|
|
43
80
|
}).map(function (column) {
|
|
44
|
-
return
|
|
81
|
+
return sanitizeCellValue(column.headerName || column.field, delimiterCharacter);
|
|
45
82
|
}).join(delimiterCharacter), "\r\n");
|
|
46
83
|
return "".concat(CSVHead).concat(CSVBody).trim();
|
|
47
84
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
|
+
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
2
3
|
import * as React from 'react';
|
|
3
4
|
import { useGridApiMethod } from '../../utils/useGridApiMethod';
|
|
4
5
|
import { useGridLogger } from '../../utils/useGridLogger';
|
|
@@ -7,7 +8,7 @@ import { buildCSV } from './serializers/csvSerializer';
|
|
|
7
8
|
import { getColumnsToExport, defaultGetRowsToExport } from './utils';
|
|
8
9
|
import { useGridRegisterPipeProcessor } from '../../core/pipeProcessing';
|
|
9
10
|
import { GridCsvExportMenuItem } from '../../../components/toolbar/GridToolbarExport';
|
|
10
|
-
|
|
11
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
12
|
/**
|
|
12
13
|
* @requires useGridColumns (state)
|
|
13
14
|
* @requires useGridFilter (state)
|
|
@@ -15,9 +16,10 @@ import { GridCsvExportMenuItem } from '../../../components/toolbar/GridToolbarEx
|
|
|
15
16
|
* @requires useGridSelection (state)
|
|
16
17
|
* @requires useGridParamsApi (method)
|
|
17
18
|
*/
|
|
18
|
-
|
|
19
|
-
export var useGridCsvExport = function useGridCsvExport(apiRef) {
|
|
19
|
+
export var useGridCsvExport = function useGridCsvExport(apiRef, props) {
|
|
20
20
|
var logger = useGridLogger(apiRef, 'useGridCsvExport');
|
|
21
|
+
var ignoreValueFormatterProp = props.unstable_ignoreValueFormatterDuringExport;
|
|
22
|
+
var ignoreValueFormatter = (_typeof(ignoreValueFormatterProp) === 'object' ? ignoreValueFormatterProp == null ? void 0 : ignoreValueFormatterProp.csvExport : ignoreValueFormatterProp) || false;
|
|
21
23
|
var getDataAsCsv = React.useCallback(function () {
|
|
22
24
|
var _options$getRowsToExp, _options$includeHeade;
|
|
23
25
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
@@ -35,9 +37,10 @@ export var useGridCsvExport = function useGridCsvExport(apiRef) {
|
|
|
35
37
|
rowIds: exportedRowIds,
|
|
36
38
|
getCellParams: apiRef.current.getCellParams,
|
|
37
39
|
delimiterCharacter: options.delimiter || ',',
|
|
38
|
-
includeHeaders: (_options$includeHeade = options.includeHeaders) != null ? _options$includeHeade : true
|
|
40
|
+
includeHeaders: (_options$includeHeade = options.includeHeaders) != null ? _options$includeHeade : true,
|
|
41
|
+
ignoreValueFormatter: ignoreValueFormatter
|
|
39
42
|
});
|
|
40
|
-
}, [logger, apiRef]);
|
|
43
|
+
}, [logger, apiRef, ignoreValueFormatter]);
|
|
41
44
|
var exportDataAsCsv = React.useCallback(function (options) {
|
|
42
45
|
logger.debug("Export data as CSV");
|
|
43
46
|
var csv = getDataAsCsv(options);
|
|
@@ -15,6 +15,7 @@ import { gridPinnedRowsSelector } from '../rows/gridRowsSelector';
|
|
|
15
15
|
import { unstable_gridFocusColumnGroupHeaderSelector } from '../focus';
|
|
16
16
|
import { gridColumnGroupsHeaderMaxDepthSelector } from '../columnGrouping/gridColumnGroupsSelector';
|
|
17
17
|
import { useGridSelector } from '../../utils/useGridSelector';
|
|
18
|
+
import { useGridRegisterPipeProcessor } from '../../core/pipeProcessing';
|
|
18
19
|
function enrichPageRowsWithPinnedRows(apiRef, rows) {
|
|
19
20
|
var pinnedRows = gridPinnedRowsSelector(apiRef) || {};
|
|
20
21
|
return [].concat(_toConsumableArray(pinnedRows.top || []), _toConsumableArray(rows), _toConsumableArray(pinnedRows.bottom || []));
|
|
@@ -450,6 +451,15 @@ export var useGridKeyboardNavigation = function useGridKeyboardNavigation(apiRef
|
|
|
450
451
|
event.preventDefault();
|
|
451
452
|
}
|
|
452
453
|
}, [apiRef, currentPageRows, theme.direction, getRowIdFromIndex, goToCell, goToHeader]);
|
|
454
|
+
var checkIfCanStartEditing = React.useCallback(function (initialValue, _ref3) {
|
|
455
|
+
var event = _ref3.event;
|
|
456
|
+
if (event.key === ' ') {
|
|
457
|
+
// Space scrolls to the last row
|
|
458
|
+
return false;
|
|
459
|
+
}
|
|
460
|
+
return initialValue;
|
|
461
|
+
}, []);
|
|
462
|
+
useGridRegisterPipeProcessor(apiRef, 'canStartEditing', checkIfCanStartEditing);
|
|
453
463
|
useGridApiEventHandler(apiRef, 'columnHeaderKeyDown', handleColumnHeaderKeyDown);
|
|
454
464
|
useGridApiEventHandler(apiRef, 'columnGroupHeaderKeyDown', handleColumnGroupHeaderKeyDown);
|
|
455
465
|
useGridApiEventHandler(apiRef, 'cellKeyDown', handleCellKeyDown);
|
package/legacy/index.js
CHANGED
|
@@ -41,14 +41,15 @@ export { useGridEvents } from '../hooks/features/events/useGridEvents';
|
|
|
41
41
|
export { useGridDimensions } from '../hooks/features/dimensions/useGridDimensions';
|
|
42
42
|
export { useGridStatePersistence } from '../hooks/features/statePersistence/useGridStatePersistence';
|
|
43
43
|
export { useGridVirtualScroller, getRenderableIndexes } from '../hooks/features/virtualization/useGridVirtualScroller';
|
|
44
|
-
export { useGridVisibleRows } from '../hooks/utils/useGridVisibleRows';
|
|
44
|
+
export { useGridVisibleRows, getVisibleRows } from '../hooks/utils/useGridVisibleRows';
|
|
45
45
|
export { useGridInitializeState } from '../hooks/utils/useGridInitializeState';
|
|
46
46
|
export { getColumnsToExport, defaultGetRowsToExport } from '../hooks/features/export/utils';
|
|
47
47
|
export { createSelector, unstable_resetCreateSelectorCache } from '../utils/createSelector';
|
|
48
|
-
export { findParentElementFromClassName } from '../utils/domUtils';
|
|
48
|
+
export { findParentElementFromClassName, getActiveElement } from '../utils/domUtils';
|
|
49
49
|
export { isNavigationKey } from '../utils/keyboardUtils';
|
|
50
50
|
export { clamp, isDeepEqual, isNumber, isFunction, isObject } from '../utils/utils';
|
|
51
51
|
export { buildWarning } from '../utils/warning';
|
|
52
52
|
export { exportAs } from '../utils/exportAs';
|
|
53
53
|
export { useGridPrivateApiContext } from '../hooks/utils/useGridPrivateApiContext';
|
|
54
|
+
export { serializeCellValue } from '../hooks/features/export/serializers/csvSerializer';
|
|
54
55
|
export * from './utils';
|