wip:milestone 0 fixes
Some checks failed
CI/CD Pipeline / unit-tests (push) Failing after 1m16s
CI/CD Pipeline / integration-tests (push) Failing after 2m32s
CI/CD Pipeline / lint (push) Successful in 5m22s
CI/CD Pipeline / e2e-tests (push) Has been skipped
CI/CD Pipeline / build (push) Has been skipped

This commit is contained in:
2026-03-15 12:35:42 +02:00
parent 6708cf28a7
commit cffdf8af86
61266 changed files with 4511646 additions and 1938 deletions

View File

@@ -0,0 +1,294 @@
import _extends from "@babel/runtime/helpers/esm/extends";
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
var _excluded = ["api", "colDef", "id", "hasFocus", "isEditable", "field", "value", "formattedValue", "row", "rowNode", "cellMode", "tabIndex", "position", "focusElementRef"];
import * as React from 'react';
import PropTypes from 'prop-types';
import MenuList from '@mui/material/MenuList';
import { useTheme } from '@mui/material/styles';
import { unstable_useId as useId } from '@mui/utils';
import { gridClasses } from '../../constants/gridClasses';
import { GridMenu } from '../menu/GridMenu';
import { useGridRootProps } from '../../hooks/utils/useGridRootProps';
import { useGridApiContext } from '../../hooks/utils/useGridApiContext';
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
var hasActions = function hasActions(colDef) {
return typeof colDef.getActions === 'function';
};
function GridActionsCell(props) {
var _rootProps$slotProps;
var api = props.api,
colDef = props.colDef,
id = props.id,
hasFocus = props.hasFocus,
isEditable = props.isEditable,
field = props.field,
value = props.value,
formattedValue = props.formattedValue,
row = props.row,
rowNode = props.rowNode,
cellMode = props.cellMode,
tabIndex = props.tabIndex,
_props$position = props.position,
position = _props$position === void 0 ? 'bottom-end' : _props$position,
focusElementRef = props.focusElementRef,
other = _objectWithoutProperties(props, _excluded);
var _React$useState = React.useState(-1),
_React$useState2 = _slicedToArray(_React$useState, 2),
focusedButtonIndex = _React$useState2[0],
setFocusedButtonIndex = _React$useState2[1];
var _React$useState3 = React.useState(false),
_React$useState4 = _slicedToArray(_React$useState3, 2),
open = _React$useState4[0],
setOpen = _React$useState4[1];
var apiRef = useGridApiContext();
var rootRef = React.useRef(null);
var buttonRef = React.useRef(null);
var ignoreCallToFocus = React.useRef(false);
var touchRippleRefs = React.useRef({});
var theme = useTheme();
var menuId = useId();
var buttonId = useId();
var rootProps = useGridRootProps();
if (!hasActions(colDef)) {
throw new Error('MUI: Missing the `getActions` property in the `GridColDef`.');
}
var options = colDef.getActions(apiRef.current.getRowParams(id));
var iconButtons = options.filter(function (option) {
return !option.props.showInMenu;
});
var menuButtons = options.filter(function (option) {
return option.props.showInMenu;
});
var numberOfButtons = iconButtons.length + (menuButtons.length ? 1 : 0);
React.useLayoutEffect(function () {
if (!hasFocus) {
Object.entries(touchRippleRefs.current).forEach(function (_ref) {
var _ref2 = _slicedToArray(_ref, 2),
index = _ref2[0],
ref = _ref2[1];
ref == null || ref.stop({}, function () {
delete touchRippleRefs.current[index];
});
});
}
}, [hasFocus]);
React.useEffect(function () {
if (focusedButtonIndex < 0 || !rootRef.current) {
return;
}
if (focusedButtonIndex >= rootRef.current.children.length) {
return;
}
var child = rootRef.current.children[focusedButtonIndex];
child.focus({
preventScroll: true
});
}, [focusedButtonIndex]);
React.useEffect(function () {
if (!hasFocus) {
setFocusedButtonIndex(-1);
ignoreCallToFocus.current = false;
}
}, [hasFocus]);
React.useImperativeHandle(focusElementRef, function () {
return {
focus: function focus() {
// If ignoreCallToFocus is true, then one of the buttons was clicked and the focus is already set
if (!ignoreCallToFocus.current) {
// find the first focusable button and pass the index to the state
var focusableButtonIndex = options.findIndex(function (o) {
return !o.props.disabled;
});
setFocusedButtonIndex(focusableButtonIndex);
}
}
};
}, [options]);
React.useEffect(function () {
if (focusedButtonIndex >= numberOfButtons) {
setFocusedButtonIndex(numberOfButtons - 1);
}
}, [focusedButtonIndex, numberOfButtons]);
var showMenu = function showMenu() {
setOpen(true);
setFocusedButtonIndex(numberOfButtons - 1);
ignoreCallToFocus.current = true;
};
var hideMenu = function hideMenu() {
setOpen(false);
};
var handleTouchRippleRef = function handleTouchRippleRef(index) {
return function (instance) {
touchRippleRefs.current[index] = instance;
};
};
var handleButtonClick = function handleButtonClick(index, onClick) {
return function (event) {
setFocusedButtonIndex(index);
ignoreCallToFocus.current = true;
if (onClick) {
onClick(event);
}
};
};
var handleRootKeyDown = function handleRootKeyDown(event) {
if (numberOfButtons <= 1) {
return;
}
var getNewIndex = function getNewIndex(index, direction) {
var _options;
if (index < 0 || index > options.length) {
return index;
}
// for rtl mode we need to reverse the direction
var rtlMod = theme.direction === 'rtl' ? -1 : 1;
var indexMod = (direction === 'left' ? -1 : 1) * rtlMod;
// if the button that should receive focus is disabled go one more step
return (_options = options[index + indexMod]) != null && _options.props.disabled ? getNewIndex(index + indexMod, direction) : index + indexMod;
};
var newIndex = focusedButtonIndex;
if (event.key === 'ArrowRight') {
newIndex = getNewIndex(focusedButtonIndex, 'right');
} else if (event.key === 'ArrowLeft') {
newIndex = getNewIndex(focusedButtonIndex, 'left');
}
if (newIndex < 0 || newIndex >= numberOfButtons) {
return; // We're already in the first or last item = do nothing and let the grid listen the event
}
if (newIndex !== focusedButtonIndex) {
event.preventDefault(); // Prevent scrolling
event.stopPropagation(); // Don't stop propagation for other keys, e.g. ArrowUp
setFocusedButtonIndex(newIndex);
}
};
var handleListKeyDown = function handleListKeyDown(event) {
if (event.key === 'Tab') {
event.preventDefault();
}
if (['Tab', 'Escape'].includes(event.key)) {
hideMenu();
}
};
return /*#__PURE__*/_jsxs("div", _extends({
role: "menu",
ref: rootRef,
tabIndex: -1,
className: gridClasses.actionsCell,
onKeyDown: handleRootKeyDown
}, other, {
children: [iconButtons.map(function (button, index) {
return /*#__PURE__*/React.cloneElement(button, {
key: index,
touchRippleRef: handleTouchRippleRef(index),
onClick: handleButtonClick(index, button.props.onClick),
tabIndex: focusedButtonIndex === index ? tabIndex : -1
});
}), menuButtons.length > 0 && buttonId && /*#__PURE__*/_jsx(rootProps.slots.baseIconButton, _extends({
ref: buttonRef,
id: buttonId,
"aria-label": apiRef.current.getLocaleText('actionsCellMore'),
"aria-haspopup": "menu",
"aria-expanded": open,
"aria-controls": open ? menuId : undefined,
role: "menuitem",
size: "small",
onClick: showMenu,
touchRippleRef: handleTouchRippleRef(buttonId),
tabIndex: focusedButtonIndex === iconButtons.length ? tabIndex : -1
}, (_rootProps$slotProps = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps.baseIconButton, {
children: /*#__PURE__*/_jsx(rootProps.slots.moreActionsIcon, {
fontSize: "small"
})
})), menuButtons.length > 0 && /*#__PURE__*/_jsx(GridMenu, {
open: open,
target: buttonRef.current,
position: position,
onClose: hideMenu,
children: /*#__PURE__*/_jsx(MenuList, {
id: menuId,
className: gridClasses.menuList,
onKeyDown: handleListKeyDown,
"aria-labelledby": buttonId,
variant: "menu",
autoFocusItem: true,
children: menuButtons.map(function (button, index) {
return /*#__PURE__*/React.cloneElement(button, {
key: index,
closeMenu: hideMenu
});
})
})
})]
}));
}
process.env.NODE_ENV !== "production" ? GridActionsCell.propTypes = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "yarn proptypes" |
// ----------------------------------------------------------------------
api: PropTypes.object,
/**
* The mode of the cell.
*/
cellMode: PropTypes.oneOf(['edit', 'view']).isRequired,
/**
* The column of the row that the current cell belongs to.
*/
colDef: PropTypes.object.isRequired,
/**
* The column field of the cell that triggered the event.
*/
field: PropTypes.string.isRequired,
/**
* A ref allowing to set imperative focus.
* It can be passed to the element that should receive focus.
* @ignore - do not document.
*/
focusElementRef: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
current: PropTypes.shape({
focus: PropTypes.func.isRequired
})
})]),
/**
* The cell value formatted with the column valueFormatter.
*/
formattedValue: PropTypes.any,
/**
* If true, the cell is the active element.
*/
hasFocus: PropTypes.bool.isRequired,
/**
* The grid row id.
*/
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
/**
* If true, the cell is editable.
*/
isEditable: PropTypes.bool,
position: PropTypes.oneOf(['bottom-end', 'bottom-start', 'bottom', 'left-end', 'left-start', 'left', 'right-end', 'right-start', 'right', 'top-end', 'top-start', 'top']),
/**
* The row model of the row that the current cell belongs to.
*/
row: PropTypes.any.isRequired,
/**
* The node of the row that the current cell belongs to.
*/
rowNode: PropTypes.object.isRequired,
/**
* the tabIndex value.
*/
tabIndex: PropTypes.oneOf([-1, 0]).isRequired,
/**
* The cell value.
* If the column has `valueGetter`, use `params.row` to directly access the fields.
*/
value: PropTypes.any
} : void 0;
export { GridActionsCell };
export var renderActionsCell = function renderActionsCell(params) {
return /*#__PURE__*/_jsx(GridActionsCell, _extends({}, params));
};

View File

@@ -0,0 +1,73 @@
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
var _excluded = ["label", "icon", "showInMenu", "onClick"],
_excluded2 = ["label", "icon", "showInMenu", "onClick", "closeMenuOnClick", "closeMenu"];
import * as React from 'react';
import PropTypes from 'prop-types';
import MenuItem from '@mui/material/MenuItem';
import ListItemIcon from '@mui/material/ListItemIcon';
import { useGridRootProps } from '../../hooks/utils/useGridRootProps';
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
var GridActionsCellItem = /*#__PURE__*/React.forwardRef(function (props, ref) {
var rootProps = useGridRootProps();
if (!props.showInMenu) {
var _rootProps$slotProps;
var _label = props.label,
_icon = props.icon,
_showInMenu = props.showInMenu,
_onClick = props.onClick,
_other = _objectWithoutProperties(props, _excluded);
var _handleClick = function _handleClick(event) {
_onClick == null || _onClick(event);
};
return /*#__PURE__*/_jsx(rootProps.slots.baseIconButton, _extends({
ref: ref,
size: "small",
role: "menuitem",
"aria-label": _label
}, _other, {
onClick: _handleClick
}, (_rootProps$slotProps = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps.baseIconButton, {
children: /*#__PURE__*/React.cloneElement(_icon, {
fontSize: 'small'
})
}));
}
var label = props.label,
icon = props.icon,
showInMenu = props.showInMenu,
onClick = props.onClick,
_props$closeMenuOnCli = props.closeMenuOnClick,
closeMenuOnClick = _props$closeMenuOnCli === void 0 ? true : _props$closeMenuOnCli,
closeMenu = props.closeMenu,
other = _objectWithoutProperties(props, _excluded2);
var handleClick = function handleClick(event) {
onClick == null || onClick(event);
if (closeMenuOnClick) {
closeMenu == null || closeMenu();
}
};
return /*#__PURE__*/_jsxs(MenuItem, _extends({
ref: ref
}, other, {
onClick: handleClick,
children: [icon && /*#__PURE__*/_jsx(ListItemIcon, {
children: icon
}), label]
}));
});
process.env.NODE_ENV !== "production" ? GridActionsCellItem.propTypes = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "yarn proptypes" |
// ----------------------------------------------------------------------
/**
* from https://mui.com/material-ui/api/button-base/#ButtonBase-prop-component
*/
component: PropTypes.elementType,
icon: PropTypes.element,
label: PropTypes.string.isRequired,
showInMenu: PropTypes.bool
} : void 0;
export { GridActionsCellItem };

View File

@@ -0,0 +1,121 @@
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
var _excluded = ["id", "value", "formattedValue", "api", "field", "row", "rowNode", "colDef", "cellMode", "isEditable", "hasFocus", "tabIndex"];
import * as React from 'react';
import PropTypes from 'prop-types';
import { unstable_composeClasses as composeClasses } from '@mui/utils';
import { getDataGridUtilityClass } from '../../constants/gridClasses';
import { useGridRootProps } from '../../hooks/utils/useGridRootProps';
import { useGridApiContext } from '../../hooks/utils/useGridApiContext';
import { isAutoGeneratedRow } from '../../hooks/features/rows/gridRowsUtils';
import { jsx as _jsx } from "react/jsx-runtime";
var useUtilityClasses = function useUtilityClasses(ownerState) {
var classes = ownerState.classes;
var slots = {
root: ['booleanCell']
};
return composeClasses(slots, getDataGridUtilityClass, classes);
};
function GridBooleanCellRaw(props) {
var id = props.id,
value = props.value,
formattedValue = props.formattedValue,
api = props.api,
field = props.field,
row = props.row,
rowNode = props.rowNode,
colDef = props.colDef,
cellMode = props.cellMode,
isEditable = props.isEditable,
hasFocus = props.hasFocus,
tabIndex = props.tabIndex,
other = _objectWithoutProperties(props, _excluded);
var apiRef = useGridApiContext();
var rootProps = useGridRootProps();
var ownerState = {
classes: rootProps.classes
};
var classes = useUtilityClasses(ownerState);
var Icon = React.useMemo(function () {
return value ? rootProps.slots.booleanCellTrueIcon : rootProps.slots.booleanCellFalseIcon;
}, [rootProps.slots.booleanCellFalseIcon, rootProps.slots.booleanCellTrueIcon, value]);
return /*#__PURE__*/_jsx(Icon, _extends({
fontSize: "small",
className: classes.root,
titleAccess: apiRef.current.getLocaleText(value ? 'booleanCellTrueLabel' : 'booleanCellFalseLabel'),
"data-value": Boolean(value)
}, other));
}
process.env.NODE_ENV !== "production" ? GridBooleanCellRaw.propTypes = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "yarn proptypes" |
// ----------------------------------------------------------------------
/**
* GridApi that let you manipulate the grid.
*/
api: PropTypes.object.isRequired,
/**
* The mode of the cell.
*/
cellMode: PropTypes.oneOf(['edit', 'view']).isRequired,
/**
* The column of the row that the current cell belongs to.
*/
colDef: PropTypes.object.isRequired,
/**
* The column field of the cell that triggered the event.
*/
field: PropTypes.string.isRequired,
/**
* A ref allowing to set imperative focus.
* It can be passed to the element that should receive focus.
* @ignore - do not document.
*/
focusElementRef: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
current: PropTypes.shape({
focus: PropTypes.func.isRequired
})
})]),
/**
* The cell value formatted with the column valueFormatter.
*/
formattedValue: PropTypes.any,
/**
* If true, the cell is the active element.
*/
hasFocus: PropTypes.bool.isRequired,
/**
* The grid row id.
*/
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
/**
* If true, the cell is editable.
*/
isEditable: PropTypes.bool,
/**
* The row model of the row that the current cell belongs to.
*/
row: PropTypes.any.isRequired,
/**
* The node of the row that the current cell belongs to.
*/
rowNode: PropTypes.object.isRequired,
/**
* the tabIndex value.
*/
tabIndex: PropTypes.oneOf([-1, 0]).isRequired,
/**
* The cell value.
* If the column has `valueGetter`, use `params.row` to directly access the fields.
*/
value: PropTypes.any
} : void 0;
var GridBooleanCell = /*#__PURE__*/React.memo(GridBooleanCellRaw);
export { GridBooleanCell };
export var renderBooleanCell = function renderBooleanCell(params) {
if (isAutoGeneratedRow(params.rowNode)) {
return '';
}
return /*#__PURE__*/_jsx(GridBooleanCell, _extends({}, params));
};

View File

@@ -0,0 +1,660 @@
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
var _excluded = ["changeReason", "unstable_updateValueOnRender"],
_excluded2 = ["align", "children", "editCellState", "colIndex", "column", "cellMode", "field", "formattedValue", "hasFocus", "height", "isEditable", "isSelected", "rowId", "tabIndex", "style", "value", "width", "className", "showRightBorder", "extendRowFullWidth", "row", "colSpan", "disableDragEvents", "isNotVisible", "onClick", "onDoubleClick", "onMouseDown", "onMouseUp", "onMouseOver", "onKeyDown", "onKeyUp", "onDragEnter", "onDragOver"],
_excluded3 = ["column", "rowId", "editCellState", "align", "children", "colIndex", "height", "width", "className", "showRightBorder", "extendRowFullWidth", "row", "colSpan", "disableDragEvents", "isNotVisible", "onClick", "onDoubleClick", "onMouseDown", "onMouseUp", "onMouseOver", "onKeyDown", "onKeyUp", "onDragEnter", "onDragOver", "style"],
_excluded4 = ["changeReason", "unstable_updateValueOnRender"];
import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import { unstable_useForkRef as useForkRef, unstable_composeClasses as composeClasses, unstable_ownerDocument as ownerDocument, unstable_capitalize as capitalize } from '@mui/utils';
import { fastMemo } from '../../utils/fastMemo';
import { doesSupportPreventScroll } from '../../utils/doesSupportPreventScroll';
import { getDataGridUtilityClass, gridClasses } from '../../constants/gridClasses';
import { GridCellModes } from '../../models';
import { useGridSelector, objectShallowCompare } from '../../hooks/utils/useGridSelector';
import { useGridApiContext } from '../../hooks/utils/useGridApiContext';
import { useGridRootProps } from '../../hooks/utils/useGridRootProps';
import { gridFocusCellSelector } from '../../hooks/features/focus/gridFocusStateSelector';
import { MissingRowIdError } from '../../hooks/features/rows/useGridParamsApi';
import { jsx as _jsx } from "react/jsx-runtime";
var EMPTY_CELL_PARAMS = {
id: -1,
field: '__unset__',
row: {},
rowNode: {
id: -1,
depth: 0,
type: 'leaf',
parent: -1,
groupingKey: null
},
colDef: {
type: 'string',
field: '__unset__',
computedWidth: 0
},
cellMode: GridCellModes.View,
hasFocus: false,
tabIndex: -1,
value: null,
formattedValue: '__unset__',
isEditable: false,
api: {}
};
var useUtilityClasses = function useUtilityClasses(ownerState) {
var align = ownerState.align,
showRightBorder = ownerState.showRightBorder,
isEditable = ownerState.isEditable,
isSelected = ownerState.isSelected,
isSelectionMode = ownerState.isSelectionMode,
classes = ownerState.classes;
var slots = {
root: ['cell', "cell--text".concat(capitalize(align)), isEditable && 'cell--editable', isSelected && 'selected', showRightBorder && 'cell--withRightBorder', isSelectionMode && !isEditable && 'cell--selectionMode', 'withBorderColor'],
content: ['cellContent']
};
return composeClasses(slots, getDataGridUtilityClass, classes);
};
var warnedOnce = false;
// GridCellWrapper is a compatibility layer for the V6 cell slot. If we can use the more efficient
// `GridCellV7`, we should. That component is a merge of `GridCellWrapper` and `GridCell`.
// TODO(v7): Remove the wrapper & cellV6 and use the cellV7 exclusively.
// TODO(v7): Removing the wrapper will break the docs performance visualization demo.
var GridCellWrapper = /*#__PURE__*/React.forwardRef(function (props, ref) {
var column = props.column,
rowId = props.rowId,
editCellState = props.editCellState;
var apiRef = useGridApiContext();
var rootProps = useGridRootProps();
var field = column.field;
var cellParamsWithAPI = useGridSelector(apiRef, function () {
// This is required because `.getCellParams` tries to get the `state.rows.tree` entry
// associated with `rowId`/`fieldId`, but this selector runs after the state has been
// updated, while `rowId`/`fieldId` reference an entry in the old state.
try {
var cellParams = apiRef.current.getCellParams(rowId, field);
var result = cellParams;
result.api = apiRef.current;
return result;
} catch (e) {
if (e instanceof MissingRowIdError) {
return EMPTY_CELL_PARAMS;
}
throw e;
}
}, objectShallowCompare);
var isSelected = useGridSelector(apiRef, function () {
return apiRef.current.unstable_applyPipeProcessors('isCellSelected', false, {
id: rowId,
field: field
});
});
if (cellParamsWithAPI === EMPTY_CELL_PARAMS) {
return null;
}
var cellMode = cellParamsWithAPI.cellMode,
hasFocus = cellParamsWithAPI.hasFocus,
isEditable = cellParamsWithAPI.isEditable,
value = cellParamsWithAPI.value,
formattedValue = cellParamsWithAPI.formattedValue;
var managesOwnFocus = column.type === 'actions';
var tabIndex = (cellMode === 'view' || !isEditable) && !managesOwnFocus ? cellParamsWithAPI.tabIndex : -1;
var rootClasses = rootProps.classes,
getCellClassName = rootProps.getCellClassName;
var classNames = apiRef.current.unstable_applyPipeProcessors('cellClassName', [], {
id: rowId,
field: field
});
if (column.cellClassName) {
classNames.push(typeof column.cellClassName === 'function' ? column.cellClassName(cellParamsWithAPI) : column.cellClassName);
}
if (getCellClassName) {
classNames.push(getCellClassName(cellParamsWithAPI));
}
var children;
if (editCellState == null && column.renderCell) {
children = column.renderCell(cellParamsWithAPI);
classNames.push(gridClasses['cell--withRenderer']);
classNames.push(rootClasses == null ? void 0 : rootClasses['cell--withRenderer']);
}
if (editCellState != null && column.renderEditCell) {
var updatedRow = apiRef.current.getRowWithUpdatedValues(rowId, column.field);
// eslint-disable-next-line @typescript-eslint/naming-convention
var changeReason = editCellState.changeReason,
unstable_updateValueOnRender = editCellState.unstable_updateValueOnRender,
editCellStateRest = _objectWithoutProperties(editCellState, _excluded);
var params = _extends({}, cellParamsWithAPI, {
row: updatedRow
}, editCellStateRest);
children = column.renderEditCell(params);
classNames.push(gridClasses['cell--editing']);
classNames.push(rootClasses == null ? void 0 : rootClasses['cell--editing']);
}
var slots = rootProps.slots;
var CellComponent = slots.cell;
var cellProps = _extends({}, props, {
ref: ref,
field: field,
formattedValue: formattedValue,
hasFocus: hasFocus,
isEditable: isEditable,
isSelected: isSelected,
value: value,
cellMode: cellMode,
children: children,
tabIndex: tabIndex,
className: clsx(classNames)
});
return /*#__PURE__*/React.createElement(CellComponent, cellProps);
});
var GridCell = /*#__PURE__*/React.forwardRef(function (props, ref) {
var _rootProps$experiment, _rootProps$experiment2;
var align = props.align,
childrenProp = props.children,
editCellState = props.editCellState,
colIndex = props.colIndex,
column = props.column,
cellMode = props.cellMode,
field = props.field,
formattedValue = props.formattedValue,
hasFocus = props.hasFocus,
height = props.height,
isEditable = props.isEditable,
isSelected = props.isSelected,
rowId = props.rowId,
tabIndex = props.tabIndex,
styleProp = props.style,
value = props.value,
width = props.width,
className = props.className,
showRightBorder = props.showRightBorder,
extendRowFullWidth = props.extendRowFullWidth,
row = props.row,
colSpan = props.colSpan,
disableDragEvents = props.disableDragEvents,
isNotVisible = props.isNotVisible,
onClick = props.onClick,
onDoubleClick = props.onDoubleClick,
onMouseDown = props.onMouseDown,
onMouseUp = props.onMouseUp,
onMouseOver = props.onMouseOver,
onKeyDown = props.onKeyDown,
onKeyUp = props.onKeyUp,
onDragEnter = props.onDragEnter,
onDragOver = props.onDragOver,
other = _objectWithoutProperties(props, _excluded2);
var valueToRender = formattedValue == null ? value : formattedValue;
var cellRef = React.useRef(null);
var handleRef = useForkRef(ref, cellRef);
var focusElementRef = React.useRef(null);
var apiRef = useGridApiContext();
var rootProps = useGridRootProps();
var ownerState = {
align: align,
showRightBorder: showRightBorder,
isEditable: isEditable,
classes: rootProps.classes,
isSelected: isSelected
};
var classes = useUtilityClasses(ownerState);
var publishMouseUp = React.useCallback(function (eventName) {
return function (event) {
var params = apiRef.current.getCellParams(rowId, field || '');
apiRef.current.publishEvent(eventName, params, event);
if (onMouseUp) {
onMouseUp(event);
}
};
}, [apiRef, field, onMouseUp, rowId]);
var publishMouseDown = React.useCallback(function (eventName) {
return function (event) {
var params = apiRef.current.getCellParams(rowId, field || '');
apiRef.current.publishEvent(eventName, params, event);
if (onMouseDown) {
onMouseDown(event);
}
};
}, [apiRef, field, onMouseDown, rowId]);
var publish = React.useCallback(function (eventName, propHandler) {
return function (event) {
// The row might have been deleted during the click
if (!apiRef.current.getRow(rowId)) {
return;
}
var params = apiRef.current.getCellParams(rowId, field || '');
apiRef.current.publishEvent(eventName, params, event);
if (propHandler) {
propHandler(event);
}
};
}, [apiRef, field, rowId]);
var style = React.useMemo(function () {
if (isNotVisible) {
return {
padding: 0,
opacity: 0,
width: 0,
border: 0
};
}
var cellStyle = _extends({
minWidth: width,
maxWidth: width,
minHeight: height,
maxHeight: height === 'auto' ? 'none' : height
}, styleProp);
return cellStyle;
}, [width, height, isNotVisible, styleProp]);
React.useEffect(function () {
if (!hasFocus || cellMode === GridCellModes.Edit) {
return;
}
var doc = ownerDocument(apiRef.current.rootElementRef.current);
if (cellRef.current && !cellRef.current.contains(doc.activeElement)) {
var focusableElement = cellRef.current.querySelector('[tabindex="0"]');
var elementToFocus = focusElementRef.current || focusableElement || cellRef.current;
if (doesSupportPreventScroll()) {
elementToFocus.focus({
preventScroll: true
});
} else {
var scrollPosition = apiRef.current.getScrollPosition();
elementToFocus.focus();
apiRef.current.scroll(scrollPosition);
}
}
}, [hasFocus, cellMode, apiRef]);
var handleFocus = other.onFocus;
if (process.env.NODE_ENV === 'test' && (_rootProps$experiment = rootProps.experimentalFeatures) != null && _rootProps$experiment.warnIfFocusStateIsNotSynced) {
handleFocus = function handleFocus(event) {
var focusedCell = gridFocusCellSelector(apiRef);
if ((focusedCell == null ? void 0 : focusedCell.id) === rowId && focusedCell.field === field) {
if (typeof other.onFocus === 'function') {
other.onFocus(event);
}
return;
}
if (!warnedOnce) {
console.warn(["MUI: The cell with id=".concat(rowId, " and field=").concat(field, " received focus."), "According to the state, the focus should be at id=".concat(focusedCell == null ? void 0 : focusedCell.id, ", field=").concat(focusedCell == null ? void 0 : focusedCell.field, "."), "Not syncing the state may cause unwanted behaviors since the `cellFocusIn` event won't be fired.", 'Call `fireEvent.mouseUp` before the `fireEvent.click` to sync the focus with the state.'].join('\n'));
warnedOnce = true;
}
};
}
var managesOwnFocus = column.type === 'actions';
var children = childrenProp;
if (children === undefined) {
var valueString = valueToRender == null ? void 0 : valueToRender.toString();
children = /*#__PURE__*/_jsx("div", {
className: classes.content,
title: valueString,
role: "presentation",
children: valueString
});
}
if ( /*#__PURE__*/React.isValidElement(children) && managesOwnFocus) {
children = /*#__PURE__*/React.cloneElement(children, {
focusElementRef: focusElementRef
});
}
var draggableEventHandlers = disableDragEvents ? null : {
onDragEnter: publish('cellDragEnter', onDragEnter),
onDragOver: publish('cellDragOver', onDragOver)
};
var ariaV7 = (_rootProps$experiment2 = rootProps.experimentalFeatures) == null ? void 0 : _rootProps$experiment2.ariaV7;
return (
/*#__PURE__*/
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
_jsx("div", _extends({
ref: handleRef,
className: clsx(className, classes.root),
role: ariaV7 ? 'gridcell' : 'cell',
"data-field": field,
"data-colindex": colIndex,
"aria-colindex": colIndex + 1,
"aria-colspan": colSpan,
style: style,
tabIndex: tabIndex,
onClick: publish('cellClick', onClick),
onDoubleClick: publish('cellDoubleClick', onDoubleClick),
onMouseOver: publish('cellMouseOver', onMouseOver),
onMouseDown: publishMouseDown('cellMouseDown'),
onMouseUp: publishMouseUp('cellMouseUp'),
onKeyDown: publish('cellKeyDown', onKeyDown),
onKeyUp: publish('cellKeyUp', onKeyUp)
}, draggableEventHandlers, other, {
onFocus: handleFocus,
children: children
}))
);
});
var MemoizedCellWrapper = fastMemo(GridCellWrapper);
process.env.NODE_ENV !== "production" ? GridCellWrapper.propTypes = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "yarn proptypes" |
// ----------------------------------------------------------------------
align: PropTypes.oneOf(['center', 'left', 'right']),
className: PropTypes.string,
colIndex: PropTypes.number,
colSpan: PropTypes.number,
column: PropTypes.object,
disableDragEvents: PropTypes.bool,
height: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]),
onClick: PropTypes.func,
onDoubleClick: PropTypes.func,
onDragEnter: PropTypes.func,
onDragOver: PropTypes.func,
onKeyDown: PropTypes.func,
onMouseDown: PropTypes.func,
onMouseUp: PropTypes.func,
rowId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
showRightBorder: PropTypes.bool,
width: PropTypes.number
} : void 0;
process.env.NODE_ENV !== "production" ? GridCell.propTypes = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "yarn proptypes" |
// ----------------------------------------------------------------------
align: PropTypes.oneOf(['center', 'left', 'right']),
cellMode: PropTypes.oneOf(['edit', 'view']),
children: PropTypes.node,
className: PropTypes.string,
colIndex: PropTypes.number,
colSpan: PropTypes.number,
column: PropTypes.object,
disableDragEvents: PropTypes.bool,
editCellState: PropTypes.shape({
changeReason: PropTypes.oneOf(['debouncedSetEditCellValue', 'setEditCellValue']),
isProcessingProps: PropTypes.bool,
isValidating: PropTypes.bool,
value: PropTypes.any
}),
isNotVisible: PropTypes.bool,
height: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]),
onClick: PropTypes.func,
onDoubleClick: PropTypes.func,
onDragEnter: PropTypes.func,
onDragOver: PropTypes.func,
onKeyDown: PropTypes.func,
onMouseDown: PropTypes.func,
onMouseUp: PropTypes.func,
rowId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
showRightBorder: PropTypes.bool,
width: PropTypes.number
} : void 0;
export { MemoizedCellWrapper as GridCellWrapper, GridCell };
var GridCellV7 = /*#__PURE__*/React.forwardRef(function (props, ref) {
var _getActions, _ref, _rootProps$unstable_c, _rootProps$experiment3, _rootProps$experiment4;
var column = props.column,
rowId = props.rowId,
editCellState = props.editCellState,
align = props.align,
childrenProp = props.children,
colIndex = props.colIndex,
height = props.height,
width = props.width,
className = props.className,
showRightBorder = props.showRightBorder,
extendRowFullWidth = props.extendRowFullWidth,
row = props.row,
colSpan = props.colSpan,
disableDragEvents = props.disableDragEvents,
isNotVisible = props.isNotVisible,
onClick = props.onClick,
onDoubleClick = props.onDoubleClick,
onMouseDown = props.onMouseDown,
onMouseUp = props.onMouseUp,
onMouseOver = props.onMouseOver,
onKeyDown = props.onKeyDown,
onKeyUp = props.onKeyUp,
onDragEnter = props.onDragEnter,
onDragOver = props.onDragOver,
styleProp = props.style,
other = _objectWithoutProperties(props, _excluded3);
var apiRef = useGridApiContext();
var rootProps = useGridRootProps();
var field = column.field;
var cellParamsWithAPI = useGridSelector(apiRef, function () {
// This is required because `.getCellParams` tries to get the `state.rows.tree` entry
// associated with `rowId`/`fieldId`, but this selector runs after the state has been
// updated, while `rowId`/`fieldId` reference an entry in the old state.
try {
var cellParams = apiRef.current.getCellParams(rowId, field);
var result = cellParams;
result.api = apiRef.current;
return result;
} catch (e) {
if (e instanceof MissingRowIdError) {
return EMPTY_CELL_PARAMS;
}
throw e;
}
}, objectShallowCompare);
var isSelected = useGridSelector(apiRef, function () {
return apiRef.current.unstable_applyPipeProcessors('isCellSelected', false, {
id: rowId,
field: field
});
});
var cellMode = cellParamsWithAPI.cellMode,
hasFocus = cellParamsWithAPI.hasFocus,
isEditable = cellParamsWithAPI.isEditable,
value = cellParamsWithAPI.value,
formattedValue = cellParamsWithAPI.formattedValue;
var canManageOwnFocus = column.type === 'actions' && ((_getActions = (_ref = column).getActions) == null ? void 0 : _getActions.call(_ref, apiRef.current.getRowParams(rowId)).some(function (action) {
return !action.props.disabled;
}));
var tabIndex = (cellMode === 'view' || !isEditable) && !canManageOwnFocus ? cellParamsWithAPI.tabIndex : -1;
var rootClasses = rootProps.classes,
getCellClassName = rootProps.getCellClassName;
var classNames = apiRef.current.unstable_applyPipeProcessors('cellClassName', [], {
id: rowId,
field: field
});
if (column.cellClassName) {
classNames.push(typeof column.cellClassName === 'function' ? column.cellClassName(cellParamsWithAPI) : column.cellClassName);
}
if (getCellClassName) {
classNames.push(getCellClassName(cellParamsWithAPI));
}
var valueToRender = formattedValue == null ? value : formattedValue;
var cellRef = React.useRef(null);
var handleRef = useForkRef(ref, cellRef);
var focusElementRef = React.useRef(null);
// @ts-expect-error To access `unstable_cellSelection` flag as it's a `premium` feature
var isSelectionMode = (_rootProps$unstable_c = rootProps.unstable_cellSelection) != null ? _rootProps$unstable_c : false;
var ownerState = {
align: align,
showRightBorder: showRightBorder,
isEditable: isEditable,
classes: rootProps.classes,
isSelected: isSelected,
isSelectionMode: isSelectionMode
};
var classes = useUtilityClasses(ownerState);
var publishMouseUp = React.useCallback(function (eventName) {
return function (event) {
var params = apiRef.current.getCellParams(rowId, field || '');
apiRef.current.publishEvent(eventName, params, event);
if (onMouseUp) {
onMouseUp(event);
}
};
}, [apiRef, field, onMouseUp, rowId]);
var publishMouseDown = React.useCallback(function (eventName) {
return function (event) {
var params = apiRef.current.getCellParams(rowId, field || '');
apiRef.current.publishEvent(eventName, params, event);
if (onMouseDown) {
onMouseDown(event);
}
};
}, [apiRef, field, onMouseDown, rowId]);
var publish = React.useCallback(function (eventName, propHandler) {
return function (event) {
// The row might have been deleted during the click
if (!apiRef.current.getRow(rowId)) {
return;
}
var params = apiRef.current.getCellParams(rowId, field || '');
apiRef.current.publishEvent(eventName, params, event);
if (propHandler) {
propHandler(event);
}
};
}, [apiRef, field, rowId]);
var style = React.useMemo(function () {
if (isNotVisible) {
return _extends({
padding: 0,
opacity: 0,
width: 0,
border: 0
}, styleProp);
}
var cellStyle = _extends({
minWidth: width,
maxWidth: width,
minHeight: height,
maxHeight: height === 'auto' ? 'none' : height
}, styleProp);
return cellStyle;
}, [width, height, isNotVisible, styleProp]);
React.useEffect(function () {
if (!hasFocus || cellMode === GridCellModes.Edit) {
return;
}
var doc = ownerDocument(apiRef.current.rootElementRef.current);
if (cellRef.current && !cellRef.current.contains(doc.activeElement)) {
var focusableElement = cellRef.current.querySelector('[tabindex="0"]');
var elementToFocus = focusElementRef.current || focusableElement || cellRef.current;
if (doesSupportPreventScroll()) {
elementToFocus.focus({
preventScroll: true
});
} else {
var scrollPosition = apiRef.current.getScrollPosition();
elementToFocus.focus();
apiRef.current.scroll(scrollPosition);
}
}
}, [hasFocus, cellMode, apiRef]);
if (cellParamsWithAPI === EMPTY_CELL_PARAMS) {
return null;
}
var handleFocus = other.onFocus;
if (process.env.NODE_ENV === 'test' && (_rootProps$experiment3 = rootProps.experimentalFeatures) != null && _rootProps$experiment3.warnIfFocusStateIsNotSynced) {
handleFocus = function handleFocus(event) {
var focusedCell = gridFocusCellSelector(apiRef);
if ((focusedCell == null ? void 0 : focusedCell.id) === rowId && focusedCell.field === field) {
if (typeof other.onFocus === 'function') {
other.onFocus(event);
}
return;
}
if (!warnedOnce) {
console.warn(["MUI: The cell with id=".concat(rowId, " and field=").concat(field, " received focus."), "According to the state, the focus should be at id=".concat(focusedCell == null ? void 0 : focusedCell.id, ", field=").concat(focusedCell == null ? void 0 : focusedCell.field, "."), "Not syncing the state may cause unwanted behaviors since the `cellFocusIn` event won't be fired.", 'Call `fireEvent.mouseUp` before the `fireEvent.click` to sync the focus with the state.'].join('\n'));
warnedOnce = true;
}
};
}
var children;
if (editCellState == null && column.renderCell) {
children = column.renderCell(cellParamsWithAPI);
classNames.push(gridClasses['cell--withRenderer']);
classNames.push(rootClasses == null ? void 0 : rootClasses['cell--withRenderer']);
}
if (editCellState != null && column.renderEditCell) {
var updatedRow = apiRef.current.getRowWithUpdatedValues(rowId, column.field);
// eslint-disable-next-line @typescript-eslint/naming-convention
var changeReason = editCellState.changeReason,
unstable_updateValueOnRender = editCellState.unstable_updateValueOnRender,
editCellStateRest = _objectWithoutProperties(editCellState, _excluded4);
var params = _extends({}, cellParamsWithAPI, {
row: updatedRow
}, editCellStateRest);
children = column.renderEditCell(params);
classNames.push(gridClasses['cell--editing']);
classNames.push(rootClasses == null ? void 0 : rootClasses['cell--editing']);
}
if (children === undefined) {
var valueString = valueToRender == null ? void 0 : valueToRender.toString();
children = /*#__PURE__*/_jsx("div", {
className: classes.content,
title: valueString,
role: "presentation",
children: valueString
});
}
if ( /*#__PURE__*/React.isValidElement(children) && canManageOwnFocus) {
children = /*#__PURE__*/React.cloneElement(children, {
focusElementRef: focusElementRef
});
}
var draggableEventHandlers = disableDragEvents ? null : {
onDragEnter: publish('cellDragEnter', onDragEnter),
onDragOver: publish('cellDragOver', onDragOver)
};
var ariaV7 = (_rootProps$experiment4 = rootProps.experimentalFeatures) == null ? void 0 : _rootProps$experiment4.ariaV7;
return (
/*#__PURE__*/
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
_jsx("div", _extends({
ref: handleRef,
className: clsx(className, classNames, classes.root),
role: ariaV7 ? 'gridcell' : 'cell',
"data-field": field,
"data-colindex": colIndex,
"aria-colindex": colIndex + 1,
"aria-colspan": colSpan,
style: style,
tabIndex: tabIndex,
onClick: publish('cellClick', onClick),
onDoubleClick: publish('cellDoubleClick', onDoubleClick),
onMouseOver: publish('cellMouseOver', onMouseOver),
onMouseDown: publishMouseDown('cellMouseDown'),
onMouseUp: publishMouseUp('cellMouseUp'),
onKeyDown: publish('cellKeyDown', onKeyDown),
onKeyUp: publish('cellKeyUp', onKeyUp)
}, draggableEventHandlers, other, {
onFocus: handleFocus,
children: children
}))
);
});
process.env.NODE_ENV !== "production" ? GridCellV7.propTypes = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "yarn proptypes" |
// ----------------------------------------------------------------------
align: PropTypes.oneOf(['center', 'left', 'right']).isRequired,
className: PropTypes.string,
colIndex: PropTypes.number.isRequired,
colSpan: PropTypes.number,
column: PropTypes.object.isRequired,
disableDragEvents: PropTypes.bool,
editCellState: PropTypes.shape({
changeReason: PropTypes.oneOf(['debouncedSetEditCellValue', 'setEditCellValue']),
isProcessingProps: PropTypes.bool,
isValidating: PropTypes.bool,
value: PropTypes.any
}),
height: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]).isRequired,
isNotVisible: PropTypes.bool,
onClick: PropTypes.func,
onDoubleClick: PropTypes.func,
onDragEnter: PropTypes.func,
onDragOver: PropTypes.func,
onKeyDown: PropTypes.func,
onMouseDown: PropTypes.func,
onMouseUp: PropTypes.func,
rowId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
showRightBorder: PropTypes.bool,
width: PropTypes.number.isRequired
} : void 0;
var MemoizedGridCellV7 = fastMemo(GridCellV7);
export { MemoizedGridCellV7 as GridCellV7 };

View File

@@ -0,0 +1,174 @@
import _extends from "@babel/runtime/helpers/esm/extends";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
var _excluded = ["id", "value", "formattedValue", "api", "field", "row", "rowNode", "colDef", "cellMode", "isEditable", "tabIndex", "className", "hasFocus", "isValidating", "isProcessingProps", "error", "onValueChange"];
import _regeneratorRuntime from "@babel/runtime/regenerator";
import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import { unstable_composeClasses as composeClasses, unstable_useId as useId, unstable_useEnhancedEffect as useEnhancedEffect } from '@mui/utils';
import { getDataGridUtilityClass } from '../../constants/gridClasses';
import { useGridRootProps } from '../../hooks/utils/useGridRootProps';
import { useGridApiContext } from '../../hooks/utils/useGridApiContext';
import { jsx as _jsx } from "react/jsx-runtime";
var useUtilityClasses = function useUtilityClasses(ownerState) {
var classes = ownerState.classes;
var slots = {
root: ['editBooleanCell']
};
return composeClasses(slots, getDataGridUtilityClass, classes);
};
function GridEditBooleanCell(props) {
var _rootProps$slotProps;
var idProp = props.id,
value = props.value,
formattedValue = props.formattedValue,
api = props.api,
field = props.field,
row = props.row,
rowNode = props.rowNode,
colDef = props.colDef,
cellMode = props.cellMode,
isEditable = props.isEditable,
tabIndex = props.tabIndex,
className = props.className,
hasFocus = props.hasFocus,
isValidating = props.isValidating,
isProcessingProps = props.isProcessingProps,
error = props.error,
onValueChange = props.onValueChange,
other = _objectWithoutProperties(props, _excluded);
var apiRef = useGridApiContext();
var inputRef = React.useRef(null);
var id = useId();
var _React$useState = React.useState(value),
_React$useState2 = _slicedToArray(_React$useState, 2),
valueState = _React$useState2[0],
setValueState = _React$useState2[1];
var rootProps = useGridRootProps();
var ownerState = {
classes: rootProps.classes
};
var classes = useUtilityClasses(ownerState);
var handleChange = React.useCallback( /*#__PURE__*/function () {
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(event) {
var newValue;
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
newValue = event.target.checked;
if (!onValueChange) {
_context.next = 4;
break;
}
_context.next = 4;
return onValueChange(event, newValue);
case 4:
setValueState(newValue);
_context.next = 7;
return apiRef.current.setEditCellValue({
id: idProp,
field: field,
value: newValue
}, event);
case 7:
case "end":
return _context.stop();
}
}, _callee);
}));
return function (_x) {
return _ref.apply(this, arguments);
};
}(), [apiRef, field, idProp, onValueChange]);
React.useEffect(function () {
setValueState(value);
}, [value]);
useEnhancedEffect(function () {
if (hasFocus) {
inputRef.current.focus();
}
}, [hasFocus]);
return /*#__PURE__*/_jsx("label", _extends({
htmlFor: id,
className: clsx(classes.root, className)
}, other, {
children: /*#__PURE__*/_jsx(rootProps.slots.baseCheckbox, _extends({
id: id,
inputRef: inputRef,
checked: Boolean(valueState),
onChange: handleChange,
size: "small"
}, (_rootProps$slotProps = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps.baseCheckbox))
}));
}
process.env.NODE_ENV !== "production" ? GridEditBooleanCell.propTypes = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "yarn proptypes" |
// ----------------------------------------------------------------------
/**
* GridApi that let you manipulate the grid.
*/
api: PropTypes.object.isRequired,
/**
* The mode of the cell.
*/
cellMode: PropTypes.oneOf(['edit', 'view']).isRequired,
changeReason: PropTypes.oneOf(['debouncedSetEditCellValue', 'setEditCellValue']),
/**
* The column of the row that the current cell belongs to.
*/
colDef: PropTypes.object.isRequired,
/**
* The column field of the cell that triggered the event.
*/
field: PropTypes.string.isRequired,
/**
* The cell value formatted with the column valueFormatter.
*/
formattedValue: PropTypes.any,
/**
* If true, the cell is the active element.
*/
hasFocus: PropTypes.bool.isRequired,
/**
* The grid row id.
*/
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
/**
* If true, the cell is editable.
*/
isEditable: PropTypes.bool,
isProcessingProps: PropTypes.bool,
isValidating: PropTypes.bool,
/**
* Callback called when the value is changed by the user.
* @param {React.ChangeEvent<HTMLInputElement>} event The event source of the callback.
* @param {boolean} newValue The value that is going to be passed to `apiRef.current.setEditCellValue`.
* @returns {Promise<void> | void} A promise to be awaited before calling `apiRef.current.setEditCellValue`
*/
onValueChange: PropTypes.func,
/**
* The row model of the row that the current cell belongs to.
*/
row: PropTypes.any.isRequired,
/**
* The node of the row that the current cell belongs to.
*/
rowNode: PropTypes.object.isRequired,
/**
* the tabIndex value.
*/
tabIndex: PropTypes.oneOf([-1, 0]).isRequired,
/**
* The cell value.
* If the column has `valueGetter`, use `params.row` to directly access the fields.
*/
value: PropTypes.any
} : void 0;
export { GridEditBooleanCell };
export var renderEditBooleanCell = function renderEditBooleanCell(params) {
return /*#__PURE__*/_jsx(GridEditBooleanCell, _extends({}, params));
};

View File

@@ -0,0 +1,230 @@
import _extends from "@babel/runtime/helpers/esm/extends";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
var _excluded = ["id", "value", "formattedValue", "api", "field", "row", "rowNode", "colDef", "cellMode", "isEditable", "tabIndex", "hasFocus", "inputProps", "isValidating", "isProcessingProps", "onValueChange"];
import _regeneratorRuntime from "@babel/runtime/regenerator";
import * as React from 'react';
import PropTypes from 'prop-types';
import { unstable_composeClasses as composeClasses, unstable_useEnhancedEffect as useEnhancedEffect } from '@mui/utils';
import InputBase from '@mui/material/InputBase';
import { styled } from '@mui/material/styles';
import { getDataGridUtilityClass } from '../../constants/gridClasses';
import { useGridRootProps } from '../../hooks/utils/useGridRootProps';
import { useGridApiContext } from '../../hooks/utils/useGridApiContext';
import { jsx as _jsx } from "react/jsx-runtime";
var StyledInputBase = styled(InputBase)({
fontSize: 'inherit'
});
var useUtilityClasses = function useUtilityClasses(ownerState) {
var classes = ownerState.classes;
var slots = {
root: ['editInputCell']
};
return composeClasses(slots, getDataGridUtilityClass, classes);
};
function GridEditDateCell(props) {
var id = props.id,
valueProp = props.value,
formattedValue = props.formattedValue,
api = props.api,
field = props.field,
row = props.row,
rowNode = props.rowNode,
colDef = props.colDef,
cellMode = props.cellMode,
isEditable = props.isEditable,
tabIndex = props.tabIndex,
hasFocus = props.hasFocus,
inputProps = props.inputProps,
isValidating = props.isValidating,
isProcessingProps = props.isProcessingProps,
onValueChange = props.onValueChange,
other = _objectWithoutProperties(props, _excluded);
var isDateTime = colDef.type === 'dateTime';
var apiRef = useGridApiContext();
var inputRef = React.useRef();
var valueTransformed = React.useMemo(function () {
var parsedDate;
if (valueProp == null) {
parsedDate = null;
} else if (valueProp instanceof Date) {
parsedDate = valueProp;
} else {
parsedDate = new Date((valueProp != null ? valueProp : '').toString());
}
var formattedDate;
if (parsedDate == null || Number.isNaN(parsedDate.getTime())) {
formattedDate = '';
} else {
var localDate = new Date(parsedDate.getTime() - parsedDate.getTimezoneOffset() * 60 * 1000);
formattedDate = localDate.toISOString().substr(0, isDateTime ? 16 : 10);
}
return {
parsed: parsedDate,
formatted: formattedDate
};
}, [valueProp, isDateTime]);
var _React$useState = React.useState(valueTransformed),
_React$useState2 = _slicedToArray(_React$useState, 2),
valueState = _React$useState2[0],
setValueState = _React$useState2[1];
var rootProps = useGridRootProps();
var ownerState = {
classes: rootProps.classes
};
var classes = useUtilityClasses(ownerState);
var parseValueToDate = React.useCallback(function (value) {
if (value === '') {
return null;
}
var _value$split = value.split('T'),
_value$split2 = _slicedToArray(_value$split, 2),
date = _value$split2[0],
time = _value$split2[1];
var _date$split = date.split('-'),
_date$split2 = _slicedToArray(_date$split, 3),
year = _date$split2[0],
month = _date$split2[1],
day = _date$split2[2];
var parsedDate = new Date();
parsedDate.setFullYear(Number(year), Number(month) - 1, Number(day));
parsedDate.setHours(0, 0, 0, 0);
if (time) {
var _time$split = time.split(':'),
_time$split2 = _slicedToArray(_time$split, 2),
hours = _time$split2[0],
minutes = _time$split2[1];
parsedDate.setHours(Number(hours), Number(minutes), 0, 0);
}
return parsedDate;
}, []);
var handleChange = React.useCallback( /*#__PURE__*/function () {
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(event) {
var newFormattedDate, newParsedDate;
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
newFormattedDate = event.target.value;
newParsedDate = parseValueToDate(newFormattedDate);
if (!onValueChange) {
_context.next = 5;
break;
}
_context.next = 5;
return onValueChange(event, newParsedDate);
case 5:
setValueState({
parsed: newParsedDate,
formatted: newFormattedDate
});
apiRef.current.setEditCellValue({
id: id,
field: field,
value: newParsedDate
}, event);
case 7:
case "end":
return _context.stop();
}
}, _callee);
}));
return function (_x) {
return _ref.apply(this, arguments);
};
}(), [apiRef, field, id, onValueChange, parseValueToDate]);
React.useEffect(function () {
setValueState(function (state) {
var _valueTransformed$par, _state$parsed;
if (valueTransformed.parsed !== state.parsed && ((_valueTransformed$par = valueTransformed.parsed) == null ? void 0 : _valueTransformed$par.getTime()) !== ((_state$parsed = state.parsed) == null ? void 0 : _state$parsed.getTime())) {
return valueTransformed;
}
return state;
});
}, [valueTransformed]);
useEnhancedEffect(function () {
if (hasFocus) {
inputRef.current.focus();
}
}, [hasFocus]);
return /*#__PURE__*/_jsx(StyledInputBase, _extends({
inputRef: inputRef,
fullWidth: true,
className: classes.root,
type: isDateTime ? 'datetime-local' : 'date',
inputProps: _extends({
max: isDateTime ? '9999-12-31T23:59' : '9999-12-31'
}, inputProps),
value: valueState.formatted,
onChange: handleChange
}, other));
}
process.env.NODE_ENV !== "production" ? GridEditDateCell.propTypes = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "yarn proptypes" |
// ----------------------------------------------------------------------
/**
* GridApi that let you manipulate the grid.
*/
api: PropTypes.object.isRequired,
/**
* The mode of the cell.
*/
cellMode: PropTypes.oneOf(['edit', 'view']).isRequired,
changeReason: PropTypes.oneOf(['debouncedSetEditCellValue', 'setEditCellValue']),
/**
* The column of the row that the current cell belongs to.
*/
colDef: PropTypes.object.isRequired,
/**
* The column field of the cell that triggered the event.
*/
field: PropTypes.string.isRequired,
/**
* The cell value formatted with the column valueFormatter.
*/
formattedValue: PropTypes.any,
/**
* If true, the cell is the active element.
*/
hasFocus: PropTypes.bool.isRequired,
/**
* The grid row id.
*/
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
/**
* If true, the cell is editable.
*/
isEditable: PropTypes.bool,
isProcessingProps: PropTypes.bool,
isValidating: PropTypes.bool,
/**
* Callback called when the value is changed by the user.
* @param {React.ChangeEvent<HTMLInputElement>} event The event source of the callback.
* @param {Date | null} newValue The value that is going to be passed to `apiRef.current.setEditCellValue`.
* @returns {Promise<void> | void} A promise to be awaited before calling `apiRef.current.setEditCellValue`
*/
onValueChange: PropTypes.func,
/**
* The row model of the row that the current cell belongs to.
*/
row: PropTypes.any.isRequired,
/**
* The node of the row that the current cell belongs to.
*/
rowNode: PropTypes.object.isRequired,
/**
* the tabIndex value.
*/
tabIndex: PropTypes.oneOf([-1, 0]).isRequired,
/**
* The cell value.
* If the column has `valueGetter`, use `params.row` to directly access the fields.
*/
value: PropTypes.any
} : void 0;
export { GridEditDateCell };
export var renderEditDateCell = function renderEditDateCell(params) {
return /*#__PURE__*/_jsx(GridEditDateCell, _extends({}, params));
};

View File

@@ -0,0 +1,198 @@
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _extends from "@babel/runtime/helpers/esm/extends";
var _excluded = ["id", "value", "formattedValue", "api", "field", "row", "rowNode", "colDef", "cellMode", "isEditable", "tabIndex", "hasFocus", "isValidating", "debounceMs", "isProcessingProps", "onValueChange"];
import _regeneratorRuntime from "@babel/runtime/regenerator";
import * as React from 'react';
import PropTypes from 'prop-types';
import { unstable_composeClasses as composeClasses, unstable_useEnhancedEffect as useEnhancedEffect } from '@mui/utils';
import { styled } from '@mui/material/styles';
import InputBase from '@mui/material/InputBase';
import { getDataGridUtilityClass } from '../../constants/gridClasses';
import { useGridRootProps } from '../../hooks/utils/useGridRootProps';
import { useGridApiContext } from '../../hooks/utils/useGridApiContext';
import { jsx as _jsx } from "react/jsx-runtime";
var useUtilityClasses = function useUtilityClasses(ownerState) {
var classes = ownerState.classes;
var slots = {
root: ['editInputCell']
};
return composeClasses(slots, getDataGridUtilityClass, classes);
};
var GridEditInputCellRoot = styled(InputBase, {
name: 'MuiDataGrid',
slot: 'EditInputCell',
overridesResolver: function overridesResolver(props, styles) {
return styles.editInputCell;
}
})(function (_ref) {
var theme = _ref.theme;
return _extends({}, theme.typography.body2, {
padding: '1px 0',
'& input': {
padding: '0 16px',
height: '100%'
}
});
});
var GridEditInputCell = /*#__PURE__*/React.forwardRef(function (props, ref) {
var rootProps = useGridRootProps();
var id = props.id,
value = props.value,
formattedValue = props.formattedValue,
api = props.api,
field = props.field,
row = props.row,
rowNode = props.rowNode,
colDef = props.colDef,
cellMode = props.cellMode,
isEditable = props.isEditable,
tabIndex = props.tabIndex,
hasFocus = props.hasFocus,
isValidating = props.isValidating,
_props$debounceMs = props.debounceMs,
debounceMs = _props$debounceMs === void 0 ? 200 : _props$debounceMs,
isProcessingProps = props.isProcessingProps,
onValueChange = props.onValueChange,
other = _objectWithoutProperties(props, _excluded);
var apiRef = useGridApiContext();
var inputRef = React.useRef();
var _React$useState = React.useState(value),
_React$useState2 = _slicedToArray(_React$useState, 2),
valueState = _React$useState2[0],
setValueState = _React$useState2[1];
var classes = useUtilityClasses(rootProps);
var handleChange = React.useCallback( /*#__PURE__*/function () {
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(event) {
var newValue, column, parsedValue;
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
newValue = event.target.value;
if (!onValueChange) {
_context.next = 4;
break;
}
_context.next = 4;
return onValueChange(event, newValue);
case 4:
column = apiRef.current.getColumn(field);
parsedValue = newValue;
if (column.valueParser) {
parsedValue = column.valueParser(newValue, apiRef.current.getCellParams(id, field));
}
setValueState(parsedValue);
apiRef.current.setEditCellValue({
id: id,
field: field,
value: parsedValue,
debounceMs: debounceMs,
unstable_skipValueParser: true
}, event);
case 9:
case "end":
return _context.stop();
}
}, _callee);
}));
return function (_x) {
return _ref2.apply(this, arguments);
};
}(), [apiRef, debounceMs, field, id, onValueChange]);
var meta = apiRef.current.unstable_getEditCellMeta(id, field);
React.useEffect(function () {
if ((meta == null ? void 0 : meta.changeReason) !== 'debouncedSetEditCellValue') {
setValueState(value);
}
}, [meta, value]);
useEnhancedEffect(function () {
if (hasFocus) {
inputRef.current.focus();
}
}, [hasFocus]);
return /*#__PURE__*/_jsx(GridEditInputCellRoot, _extends({
ref: ref,
inputRef: inputRef,
className: classes.root,
ownerState: rootProps,
fullWidth: true,
type: colDef.type === 'number' ? colDef.type : 'text',
value: valueState != null ? valueState : '',
onChange: handleChange,
endAdornment: isProcessingProps ? /*#__PURE__*/_jsx(rootProps.slots.loadIcon, {
fontSize: "small",
color: "action"
}) : undefined
}, other));
});
process.env.NODE_ENV !== "production" ? GridEditInputCell.propTypes = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "yarn proptypes" |
// ----------------------------------------------------------------------
/**
* GridApi that let you manipulate the grid.
*/
api: PropTypes.object.isRequired,
/**
* The mode of the cell.
*/
cellMode: PropTypes.oneOf(['edit', 'view']).isRequired,
changeReason: PropTypes.oneOf(['debouncedSetEditCellValue', 'setEditCellValue']),
/**
* The column of the row that the current cell belongs to.
*/
colDef: PropTypes.object.isRequired,
debounceMs: PropTypes.number,
/**
* The column field of the cell that triggered the event.
*/
field: PropTypes.string.isRequired,
/**
* The cell value formatted with the column valueFormatter.
*/
formattedValue: PropTypes.any,
/**
* If true, the cell is the active element.
*/
hasFocus: PropTypes.bool.isRequired,
/**
* The grid row id.
*/
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
/**
* If true, the cell is editable.
*/
isEditable: PropTypes.bool,
isProcessingProps: PropTypes.bool,
isValidating: PropTypes.bool,
/**
* Callback called when the value is changed by the user.
* @param {React.ChangeEvent<HTMLInputElement>} event The event source of the callback.
* @param {Date | null} newValue The value that is going to be passed to `apiRef.current.setEditCellValue`.
* @returns {Promise<void> | void} A promise to be awaited before calling `apiRef.current.setEditCellValue`
*/
onValueChange: PropTypes.func,
/**
* The row model of the row that the current cell belongs to.
*/
row: PropTypes.any.isRequired,
/**
* The node of the row that the current cell belongs to.
*/
rowNode: PropTypes.object.isRequired,
/**
* the tabIndex value.
*/
tabIndex: PropTypes.oneOf([-1, 0]).isRequired,
/**
* The cell value.
* If the column has `valueGetter`, use `params.row` to directly access the fields.
*/
value: PropTypes.any
} : void 0;
export { GridEditInputCell };
export var renderEditInputCell = function renderEditInputCell(params) {
return /*#__PURE__*/_jsx(GridEditInputCell, _extends({}, params));
};

View File

@@ -0,0 +1,251 @@
import _extends from "@babel/runtime/helpers/esm/extends";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
var _excluded = ["id", "value", "formattedValue", "api", "field", "row", "rowNode", "colDef", "cellMode", "isEditable", "tabIndex", "className", "hasFocus", "isValidating", "isProcessingProps", "error", "onValueChange", "initialOpen", "getOptionLabel", "getOptionValue"],
_excluded2 = ["MenuProps"];
import _regeneratorRuntime from "@babel/runtime/regenerator";
import * as React from 'react';
import PropTypes from 'prop-types';
import { unstable_useEnhancedEffect as useEnhancedEffect } from '@mui/utils';
import { GridCellEditStopReasons } from '../../models/params/gridEditCellParams';
import { isEscapeKey } from '../../utils/keyboardUtils';
import { useGridRootProps } from '../../hooks/utils/useGridRootProps';
import { GridEditModes } from '../../models/gridEditRowModel';
import { getValueFromValueOptions, isSingleSelectColDef } from '../panel/filterPanel/filterPanelUtils';
import { useGridApiContext } from '../../hooks/utils/useGridApiContext';
import { createElement as _createElement } from "react";
import { jsx as _jsx } from "react/jsx-runtime";
function isKeyboardEvent(event) {
return !!event.key;
}
function GridEditSingleSelectCell(props) {
var _rootProps$slotProps, _baseSelectProps$nati, _rootProps$slotProps2;
var rootProps = useGridRootProps();
var id = props.id,
valueProp = props.value,
formattedValue = props.formattedValue,
api = props.api,
field = props.field,
row = props.row,
rowNode = props.rowNode,
colDef = props.colDef,
cellMode = props.cellMode,
isEditable = props.isEditable,
tabIndex = props.tabIndex,
className = props.className,
hasFocus = props.hasFocus,
isValidating = props.isValidating,
isProcessingProps = props.isProcessingProps,
error = props.error,
onValueChange = props.onValueChange,
_props$initialOpen = props.initialOpen,
initialOpen = _props$initialOpen === void 0 ? rootProps.editMode === GridEditModes.Cell : _props$initialOpen,
getOptionLabelProp = props.getOptionLabel,
getOptionValueProp = props.getOptionValue,
other = _objectWithoutProperties(props, _excluded);
var apiRef = useGridApiContext();
var ref = React.useRef();
var inputRef = React.useRef();
var _React$useState = React.useState(initialOpen),
_React$useState2 = _slicedToArray(_React$useState, 2),
open = _React$useState2[0],
setOpen = _React$useState2[1];
var baseSelectProps = ((_rootProps$slotProps = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps.baseSelect) || {};
var isSelectNative = (_baseSelectProps$nati = baseSelectProps.native) != null ? _baseSelectProps$nati : false;
var _ref = ((_rootProps$slotProps2 = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps2.baseSelect) || {},
MenuProps = _ref.MenuProps,
otherBaseSelectProps = _objectWithoutProperties(_ref, _excluded2);
useEnhancedEffect(function () {
if (hasFocus) {
var _inputRef$current;
(_inputRef$current = inputRef.current) == null || _inputRef$current.focus();
}
}, [hasFocus]);
if (!isSingleSelectColDef(colDef)) {
return null;
}
var valueOptions;
if (typeof (colDef == null ? void 0 : colDef.valueOptions) === 'function') {
valueOptions = colDef == null ? void 0 : colDef.valueOptions({
id: id,
row: row,
field: field
});
} else {
valueOptions = colDef == null ? void 0 : colDef.valueOptions;
}
if (!valueOptions) {
return null;
}
var getOptionValue = getOptionValueProp || colDef.getOptionValue;
var getOptionLabel = getOptionLabelProp || colDef.getOptionLabel;
var handleChange = /*#__PURE__*/function () {
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(event) {
var target, formattedTargetValue;
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
if (!(!isSingleSelectColDef(colDef) || !valueOptions)) {
_context.next = 2;
break;
}
return _context.abrupt("return");
case 2:
setOpen(false);
target = event.target; // NativeSelect casts the value to a string.
formattedTargetValue = getValueFromValueOptions(target.value, valueOptions, getOptionValue);
if (!onValueChange) {
_context.next = 8;
break;
}
_context.next = 8;
return onValueChange(event, formattedTargetValue);
case 8:
_context.next = 10;
return apiRef.current.setEditCellValue({
id: id,
field: field,
value: formattedTargetValue
}, event);
case 10:
case "end":
return _context.stop();
}
}, _callee);
}));
return function handleChange(_x) {
return _ref2.apply(this, arguments);
};
}();
var handleClose = function handleClose(event, reason) {
if (rootProps.editMode === GridEditModes.Row) {
setOpen(false);
return;
}
if (reason === 'backdropClick' || isEscapeKey(event.key)) {
var params = apiRef.current.getCellParams(id, field);
apiRef.current.publishEvent('cellEditStop', _extends({}, params, {
reason: isEscapeKey(event.key) ? GridCellEditStopReasons.escapeKeyDown : GridCellEditStopReasons.cellFocusOut
}));
}
};
var handleOpen = function handleOpen(event) {
if (isKeyboardEvent(event) && event.key === 'Enter') {
return;
}
setOpen(true);
};
if (!valueOptions || !colDef) {
return null;
}
return /*#__PURE__*/_jsx(rootProps.slots.baseSelect, _extends({
ref: ref,
inputRef: inputRef,
value: valueProp,
onChange: handleChange,
open: open,
onOpen: handleOpen,
MenuProps: _extends({
onClose: handleClose
}, MenuProps),
error: error,
native: isSelectNative,
fullWidth: true
}, other, otherBaseSelectProps, {
children: valueOptions.map(function (valueOption) {
var _rootProps$slotProps3;
var value = getOptionValue(valueOption);
return /*#__PURE__*/_createElement(rootProps.slots.baseSelectOption, _extends({}, ((_rootProps$slotProps3 = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps3.baseSelectOption) || {}, {
native: isSelectNative,
key: value,
value: value
}), getOptionLabel(valueOption));
})
}));
}
process.env.NODE_ENV !== "production" ? GridEditSingleSelectCell.propTypes = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "yarn proptypes" |
// ----------------------------------------------------------------------
/**
* GridApi that let you manipulate the grid.
*/
api: PropTypes.object.isRequired,
/**
* The mode of the cell.
*/
cellMode: PropTypes.oneOf(['edit', 'view']).isRequired,
changeReason: PropTypes.oneOf(['debouncedSetEditCellValue', 'setEditCellValue']),
/**
* The column of the row that the current cell belongs to.
*/
colDef: PropTypes.object.isRequired,
/**
* The column field of the cell that triggered the event.
*/
field: PropTypes.string.isRequired,
/**
* The cell value formatted with the column valueFormatter.
*/
formattedValue: PropTypes.any,
/**
* Used to determine the label displayed for a given value option.
* @param {ValueOptions} value The current value option.
* @returns {string} The text to be displayed.
*/
getOptionLabel: PropTypes.func,
/**
* Used to determine the value used for a value option.
* @param {ValueOptions} value The current value option.
* @returns {string} The value to be used.
*/
getOptionValue: PropTypes.func,
/**
* If true, the cell is the active element.
*/
hasFocus: PropTypes.bool.isRequired,
/**
* The grid row id.
*/
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
/**
* If true, the select opens by default.
*/
initialOpen: PropTypes.bool,
/**
* If true, the cell is editable.
*/
isEditable: PropTypes.bool,
isProcessingProps: PropTypes.bool,
isValidating: PropTypes.bool,
/**
* Callback called when the value is changed by the user.
* @param {SelectChangeEvent<any>} event The event source of the callback.
* @param {any} newValue The value that is going to be passed to `apiRef.current.setEditCellValue`.
* @returns {Promise<void> | void} A promise to be awaited before calling `apiRef.current.setEditCellValue`
*/
onValueChange: PropTypes.func,
/**
* The row model of the row that the current cell belongs to.
*/
row: PropTypes.any.isRequired,
/**
* The node of the row that the current cell belongs to.
*/
rowNode: PropTypes.object.isRequired,
/**
* the tabIndex value.
*/
tabIndex: PropTypes.oneOf([-1, 0]).isRequired,
/**
* The cell value.
* If the column has `valueGetter`, use `params.row` to directly access the fields.
*/
value: PropTypes.any
} : void 0;
export { GridEditSingleSelectCell };
export var renderEditSingleSelectCell = function renderEditSingleSelectCell(params) {
return /*#__PURE__*/_jsx(GridEditSingleSelectCell, _extends({}, params));
};

View File

@@ -0,0 +1,52 @@
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
var _excluded = ["field", "align", "width", "contentWidth"];
import * as React from 'react';
import PropTypes from 'prop-types';
import Skeleton from '@mui/material/Skeleton';
import { unstable_composeClasses as composeClasses, unstable_capitalize as capitalize } from '@mui/utils';
import { useGridRootProps } from '../../hooks/utils/useGridRootProps';
import { getDataGridUtilityClass } from '../../constants/gridClasses';
import { jsx as _jsx } from "react/jsx-runtime";
var useUtilityClasses = function useUtilityClasses(ownerState) {
var align = ownerState.align,
classes = ownerState.classes;
var slots = {
root: ['cell', 'cellSkeleton', "cell--text".concat(capitalize(align)), 'withBorderColor']
};
return composeClasses(slots, getDataGridUtilityClass, classes);
};
function GridSkeletonCell(props) {
var field = props.field,
align = props.align,
width = props.width,
contentWidth = props.contentWidth,
other = _objectWithoutProperties(props, _excluded);
var rootProps = useGridRootProps();
var ownerState = {
classes: rootProps.classes,
align: align
};
var classes = useUtilityClasses(ownerState);
return /*#__PURE__*/_jsx("div", _extends({
className: classes.root,
style: {
width: width
}
}, other, {
children: /*#__PURE__*/_jsx(Skeleton, {
width: "".concat(contentWidth, "%")
})
}));
}
process.env.NODE_ENV !== "production" ? GridSkeletonCell.propTypes = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "yarn proptypes" |
// ----------------------------------------------------------------------
align: PropTypes.string.isRequired,
contentWidth: PropTypes.number.isRequired,
field: PropTypes.string.isRequired,
width: PropTypes.number.isRequired
} : void 0;
export { GridSkeletonCell };

View File

@@ -0,0 +1,9 @@
export { GridCell } from './GridCell';
export * from './GridBooleanCell';
export * from './GridEditBooleanCell';
export * from './GridEditDateCell';
export * from './GridEditInputCell';
export * from './GridEditSingleSelectCell';
export * from './GridActionsCell';
export * from './GridActionsCellItem';
export * from './GridSkeletonCell';