@mui/x-data-grid-premium
Version:
The Premium plan edition of the MUI X Data Grid Components.
66 lines (65 loc) • 2.98 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import * as React from 'react';
import { useTheme } from '@mui/material/styles';
import { getThemeProps } from '@mui/system';
import { DATA_GRID_PRO_PROPS_DEFAULT_VALUES, GRID_DEFAULT_LOCALE_TEXT, GridSignature } from '@mui/x-data-grid-pro';
import { computeSlots } from '@mui/x-data-grid-pro/internals';
import { GRID_AGGREGATION_FUNCTIONS } from "../hooks/features/aggregation/index.js";
import { DATA_GRID_PREMIUM_DEFAULT_SLOTS_COMPONENTS } from "../constants/dataGridPremiumDefaultSlotsComponents.js";
import { defaultGetPivotDerivedColumns } from "../hooks/features/pivoting/utils.js";
import { defaultGetAggregationPosition } from "../hooks/features/aggregation/gridAggregationUtils.js";
import { DEFAULT_HISTORY_VALIDATION_EVENTS } from "../hooks/features/history/constants.js";
const getDataGridPremiumForcedProps = themedProps => _extends({
signature: GridSignature.DataGridPremium
}, themedProps.dataSource ? {
filterMode: 'server',
sortingMode: 'server',
paginationMode: 'server'
} : {});
/**
* The default values of `DataGridPremiumPropsWithDefaultValue` to inject in the props of DataGridPremium.
*/
export const DATA_GRID_PREMIUM_PROPS_DEFAULT_VALUES = _extends({}, DATA_GRID_PRO_PROPS_DEFAULT_VALUES, {
cellSelection: false,
disableAggregation: false,
disableRowGrouping: false,
rowGroupingColumnMode: 'single',
aggregationFunctions: GRID_AGGREGATION_FUNCTIONS,
aggregationRowsScope: 'filtered',
getAggregationPosition: defaultGetAggregationPosition,
disableClipboardPaste: false,
splitClipboardPastedText: (pastedText, delimiter = '\t') => {
// Excel on Windows adds an empty line break at the end of the copied text.
// See https://github.com/mui/mui-x/issues/9103
const text = pastedText.replace(/\r?\n$/, '');
return text.split(/\r\n|\n|\r/).map(row => row.split(delimiter));
},
disablePivoting: false,
aiAssistant: false,
chartsIntegration: false,
historyStackSize: 30,
historyEventHandlers: {},
historyValidationEvents: DEFAULT_HISTORY_VALIDATION_EVENTS
});
const defaultSlots = DATA_GRID_PREMIUM_DEFAULT_SLOTS_COMPONENTS;
export const useDataGridPremiumProps = inProps => {
const theme = useTheme();
const themedProps = React.useMemo(() => getThemeProps({
props: inProps,
theme,
name: 'MuiDataGrid'
}), [theme, inProps]);
const localeText = React.useMemo(() => _extends({}, GRID_DEFAULT_LOCALE_TEXT, themedProps.localeText), [themedProps.localeText]);
const slots = React.useMemo(() => computeSlots({
defaultSlots,
slots: themedProps.slots
}), [themedProps.slots]);
return React.useMemo(() => _extends({}, DATA_GRID_PREMIUM_PROPS_DEFAULT_VALUES, themedProps.dataSource ? {
aggregationFunctions: {}
} : {
getPivotDerivedColumns: defaultGetPivotDerivedColumns
}, themedProps, {
localeText,
slots
}, getDataGridPremiumForcedProps(themedProps)), [themedProps, localeText, slots]);
};