@mui/x-data-grid
Version:
The Community plan edition of the MUI X Data Grid components.
34 lines (32 loc) • 1.91 kB
JavaScript
import { GRID_STRING_COL_DEF } from "./gridStringColDef.mjs";
import { GRID_NUMERIC_COL_DEF } from "./gridNumericColDef.mjs";
import { GRID_DATE_COL_DEF, GRID_DATETIME_COL_DEF } from "./gridDateColDef.mjs";
import { GRID_BOOLEAN_COL_DEF } from "./gridBooleanColDef.mjs";
import { GRID_SINGLE_SELECT_COL_DEF } from "./gridSingleSelectColDef.mjs";
import { GRID_ACTIONS_COL_DEF, GRID_ACTIONS_COLUMN_TYPE } from "./gridActionsColDef.mjs";
import { GRID_LONG_TEXT_COL_DEF } from "./gridLongTextColDef.mjs";
export const DEFAULT_GRID_COL_TYPE_KEY = 'string';
// Mutable registry seeded with the community column types. Pro/Premium packages append
// their own types at module load via `registerGridColumnTypes`, so a community-only bundle
// never references them at runtime.
const columnTypesRegistry = {
string: GRID_STRING_COL_DEF,
number: GRID_NUMERIC_COL_DEF,
date: GRID_DATE_COL_DEF,
dateTime: GRID_DATETIME_COL_DEF,
boolean: GRID_BOOLEAN_COL_DEF,
singleSelect: GRID_SINGLE_SELECT_COL_DEF,
[GRID_ACTIONS_COLUMN_TYPE]: GRID_ACTIONS_COL_DEF,
custom: GRID_STRING_COL_DEF,
longText: GRID_LONG_TEXT_COL_DEF
};
// Captured before any `registerGridColumnTypes` call, so it reflects the community-native types
// only. Used to keep Pro/Premium-registered types (e.g. `multiSelect`) from resolving in a
// community `DataGrid` even when a Pro grid registered them globally in the same bundle.
const COMMUNITY_COLUMN_TYPE_KEYS = new Set(Object.keys(columnTypesRegistry));
export const isCommunityColumnType = type => type == null || COMMUNITY_COLUMN_TYPE_KEYS.has(type);
export const registerGridColumnTypes = columnTypes => {
Object.assign(columnTypesRegistry, columnTypes);
};
export const getGridColumnTypesRegistry = () => columnTypesRegistry;
export const getRegisteredColumnTypeDef = type => (type ? columnTypesRegistry[type] : undefined) ?? columnTypesRegistry[DEFAULT_GRID_COL_TYPE_KEY];