neue Homepage auf react basis

This commit is contained in:
2026-08-07 21:39:30 +02:00
parent 164bdd19ad
commit ee89442c04
52191 changed files with 1230242 additions and 58 deletions
@@ -0,0 +1,41 @@
import * as React from 'react';
import type { GridRowParams } from "../../models/params/gridRowParams.mjs";
import type { GridRenderCellParams } from "../../models/params/gridCellParams.mjs";
import type { GridMenuProps } from "../menu/GridMenu.mjs";
import type { GridValidRowModel, GridTreeNodeWithRender } from "../../models/gridRows.mjs";
interface GridActionsCellProps<R extends GridValidRowModel = any, V = any, F = V, N extends GridTreeNodeWithRender = GridTreeNodeWithRender> extends Omit<GridRenderCellParams<R, V, F, N>, 'api'> {
api?: GridRenderCellParams['api'];
position?: GridMenuProps['position'];
children: React.ReactNode;
/**
* If true, the children passed to the component will not be validated.
* If false, only `GridActionsCellItem` and `React.Fragment` are allowed as children.
* Only use this prop if you know what you are doing.
* @default false
*/
suppressChildrenValidation?: boolean;
/**
* Callback to fire before the menu gets opened.
* Use this callback to prevent the menu from opening.
*
* @param {GridRowParams<R>} params Row parameters.
* @param {React.MouseEvent<HTMLElement>} event The event triggering this callback.
* @returns {boolean} if the menu should be opened.
*/
onMenuOpen?: (params: GridRowParams<R>, event: React.MouseEvent<HTMLElement>) => boolean;
/**
* Callback to fire before the menu gets closed.
* Use this callback to prevent the menu from closing.
*
* @param {GridRowParams<R>} params Row parameters.
* @param {React.MouseEvent<HTMLElement> | React.KeyboardEvent | MouseEvent | TouchEvent | undefined} event The event triggering this callback.
* @returns {boolean} if the menu should be closed.
*/
onMenuClose?: (params: GridRowParams<R>, event: React.MouseEvent<HTMLElement> | React.KeyboardEvent | MouseEvent | TouchEvent | undefined) => boolean;
}
declare function GridActionsCell<R extends GridValidRowModel = any, V = any, F = V, N extends GridTreeNodeWithRender = GridTreeNodeWithRender>(props: GridActionsCellProps<R, V, F, N>): React.JSX.Element;
declare namespace GridActionsCell {
var propTypes: any;
}
export { GridActionsCell };
export declare const renderActionsCell: (params: GridRenderCellParams) => React.JSX.Element;
@@ -0,0 +1,41 @@
import * as React from 'react';
import type { GridRowParams } from "../../models/params/gridRowParams.js";
import type { GridRenderCellParams } from "../../models/params/gridCellParams.js";
import type { GridMenuProps } from "../menu/GridMenu.js";
import type { GridValidRowModel, GridTreeNodeWithRender } from "../../models/gridRows.js";
interface GridActionsCellProps<R extends GridValidRowModel = any, V = any, F = V, N extends GridTreeNodeWithRender = GridTreeNodeWithRender> extends Omit<GridRenderCellParams<R, V, F, N>, 'api'> {
api?: GridRenderCellParams['api'];
position?: GridMenuProps['position'];
children: React.ReactNode;
/**
* If true, the children passed to the component will not be validated.
* If false, only `GridActionsCellItem` and `React.Fragment` are allowed as children.
* Only use this prop if you know what you are doing.
* @default false
*/
suppressChildrenValidation?: boolean;
/**
* Callback to fire before the menu gets opened.
* Use this callback to prevent the menu from opening.
*
* @param {GridRowParams<R>} params Row parameters.
* @param {React.MouseEvent<HTMLElement>} event The event triggering this callback.
* @returns {boolean} if the menu should be opened.
*/
onMenuOpen?: (params: GridRowParams<R>, event: React.MouseEvent<HTMLElement>) => boolean;
/**
* Callback to fire before the menu gets closed.
* Use this callback to prevent the menu from closing.
*
* @param {GridRowParams<R>} params Row parameters.
* @param {React.MouseEvent<HTMLElement> | React.KeyboardEvent | MouseEvent | TouchEvent | undefined} event The event triggering this callback.
* @returns {boolean} if the menu should be closed.
*/
onMenuClose?: (params: GridRowParams<R>, event: React.MouseEvent<HTMLElement> | React.KeyboardEvent | MouseEvent | TouchEvent | undefined) => boolean;
}
declare function GridActionsCell<R extends GridValidRowModel = any, V = any, F = V, N extends GridTreeNodeWithRender = GridTreeNodeWithRender>(props: GridActionsCellProps<R, V, F, N>): React.JSX.Element;
declare namespace GridActionsCell {
var propTypes: any;
}
export { GridActionsCell };
export declare const renderActionsCell: (params: GridRenderCellParams) => React.JSX.Element;
@@ -0,0 +1,378 @@
"use strict";
'use client';
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.GridActionsCell = GridActionsCell;
exports.renderActionsCell = void 0;
var _formatErrorMessage2 = _interopRequireDefault(require("@mui/x-internals/formatErrorMessage"));
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var React = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _RtlProvider = require("@mui/system/RtlProvider");
var _useId = _interopRequireDefault(require("@mui/utils/useId"));
var _warning = require("@mui/x-internals/warning");
var _gridClasses = require("../../constants/gridClasses");
var _GridMenu = require("../menu/GridMenu");
var _useGridRootProps = require("../../hooks/utils/useGridRootProps");
var _useGridApiContext = require("../../hooks/utils/useGridApiContext");
var _GridActionsCellItem = require("./GridActionsCellItem");
var _jsxRuntime = require("react/jsx-runtime");
const _excluded = ["api", "colDef", "id", "hasFocus", "isEditable", "field", "value", "formattedValue", "row", "rowNode", "cellMode", "tabIndex", "position", "onMenuOpen", "onMenuClose", "children", "suppressChildrenValidation"];
const hasActions = colDef => typeof colDef.getActions === 'function';
function GridActionsCell(props) {
const {
id,
hasFocus,
tabIndex,
position = 'bottom-end',
onMenuOpen,
onMenuClose,
children,
suppressChildrenValidation
} = props,
other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
const [focusedButtonIndex, setFocusedButtonIndex] = React.useState(-1);
const [open, setOpen] = React.useState(false);
const apiRef = (0, _useGridApiContext.useGridApiContext)();
const rootRef = React.useRef(null);
const buttonRef = React.useRef(null);
const ignoreCallToFocus = React.useRef(false);
const touchRippleRefs = React.useRef({});
const isRtl = (0, _RtlProvider.useRtl)();
const menuId = (0, _useId.default)();
const buttonId = (0, _useId.default)();
const rootProps = (0, _useGridRootProps.useGridRootProps)();
const rowParams = apiRef.current.getRowParams(id);
const actions = [];
React.Children.forEach(children, child => {
// Unwrap React.Fragment
if (/*#__PURE__*/React.isValidElement(child)) {
if (child.type === React.Fragment) {
React.Children.forEach(child.props.children, fragChild => {
if (/*#__PURE__*/React.isValidElement(fragChild)) {
actions.push(fragChild);
}
});
} else if (child.type === _GridActionsCellItem.GridActionsCellItem || suppressChildrenValidation) {
actions.push(child);
} else if (process.env.NODE_ENV !== 'production') {
const childType = typeof child.type === 'function' ? child.type.name : child.type;
(0, _warning.warnOnce)(`MUI X: Invalid child type in \`GridActionsCell\`. Expected \`GridActionsCellItem\` or \`React.Fragment\`, got \`${childType}\`.
If this is intentional, you can suppress this warning by passing the \`suppressChildrenValidation\` prop to \`GridActionsCell\`.`, 'error');
}
}
});
const iconButtons = actions.filter(option => !option.props.showInMenu);
const menuButtons = actions.filter(option => option.props.showInMenu);
const numberOfButtons = iconButtons.length + (menuButtons.length ? 1 : 0);
React.useLayoutEffect(() => {
if (!hasFocus) {
Object.entries(touchRippleRefs.current).forEach(([index, ref]) => {
ref?.stop({}, () => {
delete touchRippleRefs.current[index];
});
});
}
}, [hasFocus]);
React.useEffect(() => {
if (focusedButtonIndex < 0 || !rootRef.current) {
return;
}
if (focusedButtonIndex >= rootRef.current.children.length) {
return;
}
const child = rootRef.current.children[focusedButtonIndex];
child.focus({
preventScroll: true
});
}, [focusedButtonIndex]);
const firstFocusableButtonIndex = actions.findIndex(o => !o.props.disabled);
React.useEffect(() => {
if (hasFocus && focusedButtonIndex === -1) {
setFocusedButtonIndex(firstFocusableButtonIndex);
}
if (!hasFocus) {
setFocusedButtonIndex(-1);
ignoreCallToFocus.current = false;
}
}, [hasFocus, focusedButtonIndex, firstFocusableButtonIndex]);
React.useEffect(() => {
if (focusedButtonIndex >= numberOfButtons) {
setFocusedButtonIndex(numberOfButtons - 1);
}
}, [focusedButtonIndex, numberOfButtons]);
const showMenu = event => {
if (onMenuOpen && !onMenuOpen(rowParams, event)) {
return;
}
setOpen(true);
setFocusedButtonIndex(numberOfButtons - 1);
ignoreCallToFocus.current = true;
};
const hideMenu = event => {
if (onMenuClose && !onMenuClose(rowParams, event)) {
return;
}
setOpen(false);
};
const toggleMenu = event => {
event.stopPropagation();
event.preventDefault();
if (open) {
hideMenu(event);
} else {
showMenu(event);
}
};
const handleTouchRippleRef = index => instance => {
touchRippleRefs.current[index] = instance;
};
const handleButtonClick = (index, onClick) => event => {
setFocusedButtonIndex(index);
ignoreCallToFocus.current = true;
if (onClick) {
onClick(event);
}
};
const handleRootKeyDown = event => {
if (numberOfButtons <= 1) {
return;
}
const getNewIndex = (index, direction) => {
if (index < 0 || index > actions.length) {
return index;
}
// for rtl mode we need to reverse the direction
const rtlMod = isRtl ? -1 : 1;
const indexMod = (direction === 'left' ? -1 : 1) * rtlMod;
// if the button that should receive focus is disabled go one more step
return actions[index + indexMod]?.props.disabled ? getNewIndex(index + indexMod, direction) : index + indexMod;
};
let 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, for example ArrowUp
setFocusedButtonIndex(newIndex);
}
};
// role="menu" requires at least one child element
const attributes = numberOfButtons > 0 ? {
role: 'menu',
onKeyDown: handleRootKeyDown
} : undefined;
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", (0, _extends2.default)({
ref: rootRef,
tabIndex: -1,
className: _gridClasses.gridClasses.actionsCell
}, attributes, other, {
children: [iconButtons.map((button, index) => /*#__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__*/(0, _jsxRuntime.jsx)(rootProps.slots.baseIconButton, (0, _extends2.default)({
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: toggleMenu,
touchRippleRef: handleTouchRippleRef(buttonId),
tabIndex: focusedButtonIndex === iconButtons.length ? tabIndex : -1
}, rootProps.slotProps?.baseIconButton, {
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(rootProps.slots.moreActionsIcon, {
fontSize: "small"
})
})), menuButtons.length > 0 && /*#__PURE__*/(0, _jsxRuntime.jsx)(_GridMenu.GridMenu, {
open: open,
target: buttonRef.current,
position: position,
onClose: hideMenu,
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(rootProps.slots.baseMenuList, {
id: menuId,
className: _gridClasses.gridClasses.menuList,
"aria-labelledby": buttonId,
autoFocusItem: true,
children: menuButtons.map((button, index) => /*#__PURE__*/React.cloneElement(button, {
key: index,
closeMenu: hideMenu
}))
})
})]
}));
}
process.env.NODE_ENV !== "production" ? GridActionsCell.propTypes /* remove-proptypes */ = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "pnpm proptypes" |
// ----------------------------------------------------------------------
api: _propTypes.default.object,
/**
* The mode of the cell.
*/
cellMode: _propTypes.default.oneOf(['edit', 'view']).isRequired,
children: _propTypes.default.node,
/**
* The column of the row that the current cell belongs to.
*/
colDef: _propTypes.default.object.isRequired,
/**
* The column field of the cell that triggered the event.
*/
field: _propTypes.default.string.isRequired,
/**
* The cell value formatted with the column valueFormatter.
*/
formattedValue: _propTypes.default.any,
/**
* If true, the cell is the active element.
*/
hasFocus: _propTypes.default.bool.isRequired,
/**
* The grid row id.
*/
id: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]).isRequired,
/**
* If true, the cell is editable.
*/
isEditable: _propTypes.default.bool,
/**
* Callback to fire before the menu gets closed.
* Use this callback to prevent the menu from closing.
*
* @param {GridRowParams<R>} params Row parameters.
* @param {React.MouseEvent<HTMLElement> | React.KeyboardEvent | MouseEvent | TouchEvent | undefined} event The event triggering this callback.
* @returns {boolean} if the menu should be closed.
*/
onMenuClose: _propTypes.default.func,
/**
* Callback to fire before the menu gets opened.
* Use this callback to prevent the menu from opening.
*
* @param {GridRowParams<R>} params Row parameters.
* @param {React.MouseEvent<HTMLElement>} event The event triggering this callback.
* @returns {boolean} if the menu should be opened.
*/
onMenuOpen: _propTypes.default.func,
position: _propTypes.default.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.default.object.isRequired,
/**
* The node of the row that the current cell belongs to.
*/
rowNode: _propTypes.default.object.isRequired,
/**
* If true, the children passed to the component will not be validated.
* If false, only `GridActionsCellItem` and `React.Fragment` are allowed as children.
* Only use this prop if you know what you are doing.
* @default false
*/
suppressChildrenValidation: _propTypes.default.bool,
/**
* the tabIndex value.
*/
tabIndex: _propTypes.default.oneOf([-1, 0]).isRequired,
/**
* The cell value.
* If the column has `valueGetter`, use `params.row` to directly access the fields.
*/
value: _propTypes.default.any
} : void 0;
// Temporary wrapper for backward compatibility.
// Only used to support `getActions` method in `GridColDef`.
// TODO(v9): Remove this wrapper and the default `renderCell` in gridActionsColDef
function GridActionsCellWrapper(props) {
const {
colDef,
id
} = props;
const apiRef = (0, _useGridApiContext.useGridApiContext)();
if (!hasActions(colDef)) {
throw new Error(process.env.NODE_ENV !== "production" ? 'MUI X: Missing the `getActions` property in the `GridColDef`.' : (0, _formatErrorMessage2.default)(60));
}
const actions = colDef.getActions(apiRef.current.getRowParams(id));
return /*#__PURE__*/(0, _jsxRuntime.jsx)(GridActionsCell, (0, _extends2.default)({
suppressChildrenValidation: true
}, props, {
children: actions
}));
}
process.env.NODE_ENV !== "production" ? GridActionsCellWrapper.propTypes /* remove-proptypes */ = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "pnpm proptypes" |
// ----------------------------------------------------------------------
/**
* GridApi that let you manipulate the grid.
*/
api: _propTypes.default.object.isRequired,
/**
* The mode of the cell.
*/
cellMode: _propTypes.default.oneOf(['edit', 'view']).isRequired,
/**
* The column of the row that the current cell belongs to.
*/
colDef: _propTypes.default.object.isRequired,
/**
* The column field of the cell that triggered the event.
*/
field: _propTypes.default.string.isRequired,
/**
* The cell value formatted with the column valueFormatter.
*/
formattedValue: _propTypes.default.any,
/**
* If true, the cell is the active element.
*/
hasFocus: _propTypes.default.bool.isRequired,
/**
* The grid row id.
*/
id: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]).isRequired,
/**
* If true, the cell is editable.
*/
isEditable: _propTypes.default.bool,
/**
* The row model of the row that the current cell belongs to.
*/
row: _propTypes.default.any.isRequired,
/**
* The node of the row that the current cell belongs to.
*/
rowNode: _propTypes.default.object.isRequired,
/**
* the tabIndex value.
*/
tabIndex: _propTypes.default.oneOf([-1, 0]).isRequired,
/**
* The cell value.
* If the column has `valueGetter`, use `params.row` to directly access the fields.
*/
value: _propTypes.default.any
} : void 0;
const renderActionsCell = params => /*#__PURE__*/(0, _jsxRuntime.jsx)(GridActionsCellWrapper, (0, _extends2.default)({}, params));
exports.renderActionsCell = renderActionsCell;
if (process.env.NODE_ENV !== "production") renderActionsCell.displayName = "renderActionsCell";
@@ -0,0 +1,371 @@
'use client';
import _formatErrorMessage from "@mui/x-internals/formatErrorMessage";
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
const _excluded = ["api", "colDef", "id", "hasFocus", "isEditable", "field", "value", "formattedValue", "row", "rowNode", "cellMode", "tabIndex", "position", "onMenuOpen", "onMenuClose", "children", "suppressChildrenValidation"];
import * as React from 'react';
import PropTypes from 'prop-types';
import { useRtl } from '@mui/system/RtlProvider';
import useId from '@mui/utils/useId';
import { warnOnce } from '@mui/x-internals/warning';
import { gridClasses } from "../../constants/gridClasses.mjs";
import { GridMenu } from "../menu/GridMenu.mjs";
import { useGridRootProps } from "../../hooks/utils/useGridRootProps.mjs";
import { useGridApiContext } from "../../hooks/utils/useGridApiContext.mjs";
import { GridActionsCellItem } from "./GridActionsCellItem.mjs";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
const hasActions = colDef => typeof colDef.getActions === 'function';
function GridActionsCell(props) {
const {
id,
hasFocus,
tabIndex,
position = 'bottom-end',
onMenuOpen,
onMenuClose,
children,
suppressChildrenValidation
} = props,
other = _objectWithoutPropertiesLoose(props, _excluded);
const [focusedButtonIndex, setFocusedButtonIndex] = React.useState(-1);
const [open, setOpen] = React.useState(false);
const apiRef = useGridApiContext();
const rootRef = React.useRef(null);
const buttonRef = React.useRef(null);
const ignoreCallToFocus = React.useRef(false);
const touchRippleRefs = React.useRef({});
const isRtl = useRtl();
const menuId = useId();
const buttonId = useId();
const rootProps = useGridRootProps();
const rowParams = apiRef.current.getRowParams(id);
const actions = [];
React.Children.forEach(children, child => {
// Unwrap React.Fragment
if (/*#__PURE__*/React.isValidElement(child)) {
if (child.type === React.Fragment) {
React.Children.forEach(child.props.children, fragChild => {
if (/*#__PURE__*/React.isValidElement(fragChild)) {
actions.push(fragChild);
}
});
} else if (child.type === GridActionsCellItem || suppressChildrenValidation) {
actions.push(child);
} else if (process.env.NODE_ENV !== 'production') {
const childType = typeof child.type === 'function' ? child.type.name : child.type;
warnOnce(`MUI X: Invalid child type in \`GridActionsCell\`. Expected \`GridActionsCellItem\` or \`React.Fragment\`, got \`${childType}\`.
If this is intentional, you can suppress this warning by passing the \`suppressChildrenValidation\` prop to \`GridActionsCell\`.`, 'error');
}
}
});
const iconButtons = actions.filter(option => !option.props.showInMenu);
const menuButtons = actions.filter(option => option.props.showInMenu);
const numberOfButtons = iconButtons.length + (menuButtons.length ? 1 : 0);
React.useLayoutEffect(() => {
if (!hasFocus) {
Object.entries(touchRippleRefs.current).forEach(([index, ref]) => {
ref?.stop({}, () => {
delete touchRippleRefs.current[index];
});
});
}
}, [hasFocus]);
React.useEffect(() => {
if (focusedButtonIndex < 0 || !rootRef.current) {
return;
}
if (focusedButtonIndex >= rootRef.current.children.length) {
return;
}
const child = rootRef.current.children[focusedButtonIndex];
child.focus({
preventScroll: true
});
}, [focusedButtonIndex]);
const firstFocusableButtonIndex = actions.findIndex(o => !o.props.disabled);
React.useEffect(() => {
if (hasFocus && focusedButtonIndex === -1) {
setFocusedButtonIndex(firstFocusableButtonIndex);
}
if (!hasFocus) {
setFocusedButtonIndex(-1);
ignoreCallToFocus.current = false;
}
}, [hasFocus, focusedButtonIndex, firstFocusableButtonIndex]);
React.useEffect(() => {
if (focusedButtonIndex >= numberOfButtons) {
setFocusedButtonIndex(numberOfButtons - 1);
}
}, [focusedButtonIndex, numberOfButtons]);
const showMenu = event => {
if (onMenuOpen && !onMenuOpen(rowParams, event)) {
return;
}
setOpen(true);
setFocusedButtonIndex(numberOfButtons - 1);
ignoreCallToFocus.current = true;
};
const hideMenu = event => {
if (onMenuClose && !onMenuClose(rowParams, event)) {
return;
}
setOpen(false);
};
const toggleMenu = event => {
event.stopPropagation();
event.preventDefault();
if (open) {
hideMenu(event);
} else {
showMenu(event);
}
};
const handleTouchRippleRef = index => instance => {
touchRippleRefs.current[index] = instance;
};
const handleButtonClick = (index, onClick) => event => {
setFocusedButtonIndex(index);
ignoreCallToFocus.current = true;
if (onClick) {
onClick(event);
}
};
const handleRootKeyDown = event => {
if (numberOfButtons <= 1) {
return;
}
const getNewIndex = (index, direction) => {
if (index < 0 || index > actions.length) {
return index;
}
// for rtl mode we need to reverse the direction
const rtlMod = isRtl ? -1 : 1;
const indexMod = (direction === 'left' ? -1 : 1) * rtlMod;
// if the button that should receive focus is disabled go one more step
return actions[index + indexMod]?.props.disabled ? getNewIndex(index + indexMod, direction) : index + indexMod;
};
let 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, for example ArrowUp
setFocusedButtonIndex(newIndex);
}
};
// role="menu" requires at least one child element
const attributes = numberOfButtons > 0 ? {
role: 'menu',
onKeyDown: handleRootKeyDown
} : undefined;
return /*#__PURE__*/_jsxs("div", _extends({
ref: rootRef,
tabIndex: -1,
className: gridClasses.actionsCell
}, attributes, other, {
children: [iconButtons.map((button, index) => /*#__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: toggleMenu,
touchRippleRef: handleTouchRippleRef(buttonId),
tabIndex: focusedButtonIndex === iconButtons.length ? tabIndex : -1
}, 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(rootProps.slots.baseMenuList, {
id: menuId,
className: gridClasses.menuList,
"aria-labelledby": buttonId,
autoFocusItem: true,
children: menuButtons.map((button, index) => /*#__PURE__*/React.cloneElement(button, {
key: index,
closeMenu: hideMenu
}))
})
})]
}));
}
process.env.NODE_ENV !== "production" ? GridActionsCell.propTypes /* remove-proptypes */ = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "pnpm proptypes" |
// ----------------------------------------------------------------------
api: PropTypes.object,
/**
* The mode of the cell.
*/
cellMode: PropTypes.oneOf(['edit', 'view']).isRequired,
children: PropTypes.node,
/**
* 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,
/**
* Callback to fire before the menu gets closed.
* Use this callback to prevent the menu from closing.
*
* @param {GridRowParams<R>} params Row parameters.
* @param {React.MouseEvent<HTMLElement> | React.KeyboardEvent | MouseEvent | TouchEvent | undefined} event The event triggering this callback.
* @returns {boolean} if the menu should be closed.
*/
onMenuClose: PropTypes.func,
/**
* Callback to fire before the menu gets opened.
* Use this callback to prevent the menu from opening.
*
* @param {GridRowParams<R>} params Row parameters.
* @param {React.MouseEvent<HTMLElement>} event The event triggering this callback.
* @returns {boolean} if the menu should be opened.
*/
onMenuOpen: PropTypes.func,
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.object.isRequired,
/**
* The node of the row that the current cell belongs to.
*/
rowNode: PropTypes.object.isRequired,
/**
* If true, the children passed to the component will not be validated.
* If false, only `GridActionsCellItem` and `React.Fragment` are allowed as children.
* Only use this prop if you know what you are doing.
* @default false
*/
suppressChildrenValidation: PropTypes.bool,
/**
* 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 };
// Temporary wrapper for backward compatibility.
// Only used to support `getActions` method in `GridColDef`.
// TODO(v9): Remove this wrapper and the default `renderCell` in gridActionsColDef
function GridActionsCellWrapper(props) {
const {
colDef,
id
} = props;
const apiRef = useGridApiContext();
if (!hasActions(colDef)) {
throw new Error(process.env.NODE_ENV !== "production" ? 'MUI X: Missing the `getActions` property in the `GridColDef`.' : _formatErrorMessage(60));
}
const actions = colDef.getActions(apiRef.current.getRowParams(id));
return /*#__PURE__*/_jsx(GridActionsCell, _extends({
suppressChildrenValidation: true
}, props, {
children: actions
}));
}
process.env.NODE_ENV !== "production" ? GridActionsCellWrapper.propTypes /* remove-proptypes */ = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "pnpm 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,
/**
* 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;
export const renderActionsCell = params => /*#__PURE__*/_jsx(GridActionsCellWrapper, _extends({}, params));
if (process.env.NODE_ENV !== "production") renderActionsCell.displayName = "renderActionsCell";
@@ -0,0 +1,55 @@
import * as React from 'react';
import type { GridSlotProps, GridBaseIconProps } from "../../models/gridSlotsComponentsProps.mjs";
interface GridActionsCellItemCommonProps {
icon?: React.JSXElementConstructor<GridBaseIconProps> | React.ReactNode;
/** from https://mui.com/material-ui/api/button-base/#ButtonBase-prop-component */
component?: React.ElementType;
}
export type GridActionsCellItemProps = GridActionsCellItemCommonProps & (({
showInMenu?: false;
icon: React.ReactElement<any>;
label: string;
} & Omit<GridSlotProps['baseIconButton'], 'component'>) | ({
showInMenu: true;
/**
* If false, the menu will not close when this item is clicked.
* @default true
*/
closeMenuOnClick?: boolean;
closeMenu?: () => void;
label: React.ReactNode;
} & Omit<GridSlotProps['baseMenuItem'], 'component'>));
declare const GridActionsCellItem: React.ForwardRefExoticComponent<GridActionsCellItemProps> | React.ForwardRefExoticComponent<(Omit<GridActionsCellItemCommonProps & {
showInMenu?: false;
icon: React.ReactElement<any>;
label: string;
} & Omit<Omit<import("../../models/gridBaseSlots.mjs").ButtonProps, "startIcon"> & {
label?: string;
color?: 'default' | 'inherit' | 'primary';
edge?: 'start' | 'end' | false;
} & import("@mui/x-data-grid").BaseIconButtonPropsOverrides, "component">, "ref"> | (GridActionsCellItemCommonProps & {
showInMenu: true;
/**
* If false, the menu will not close when this item is clicked.
* @default true
*/
closeMenuOnClick?: boolean;
closeMenu?: () => void;
label: React.ReactNode;
} & Omit<React.DOMAttributes<HTMLElement> & {
[k: `aria-${string}`]: any;
[k: `data-${string}`]: any;
className?: string;
style?: React.CSSProperties;
} & {
autoFocus?: boolean;
children?: React.ReactNode;
inert?: boolean;
disabled?: boolean;
iconStart?: React.ReactNode;
iconEnd?: React.ReactNode;
selected?: boolean;
value?: number | string | readonly string[];
style?: React.CSSProperties;
} & import("@mui/x-data-grid").BaseMenuItemPropsOverrides, "component">)) & React.RefAttributes<HTMLElement>>;
export { GridActionsCellItem };
@@ -0,0 +1,55 @@
import * as React from 'react';
import type { GridSlotProps, GridBaseIconProps } from "../../models/gridSlotsComponentsProps.js";
interface GridActionsCellItemCommonProps {
icon?: React.JSXElementConstructor<GridBaseIconProps> | React.ReactNode;
/** from https://mui.com/material-ui/api/button-base/#ButtonBase-prop-component */
component?: React.ElementType;
}
export type GridActionsCellItemProps = GridActionsCellItemCommonProps & (({
showInMenu?: false;
icon: React.ReactElement<any>;
label: string;
} & Omit<GridSlotProps['baseIconButton'], 'component'>) | ({
showInMenu: true;
/**
* If false, the menu will not close when this item is clicked.
* @default true
*/
closeMenuOnClick?: boolean;
closeMenu?: () => void;
label: React.ReactNode;
} & Omit<GridSlotProps['baseMenuItem'], 'component'>));
declare const GridActionsCellItem: React.ForwardRefExoticComponent<GridActionsCellItemProps> | React.ForwardRefExoticComponent<(Omit<GridActionsCellItemCommonProps & {
showInMenu?: false;
icon: React.ReactElement<any>;
label: string;
} & Omit<Omit<import("../../models/gridBaseSlots.js").ButtonProps, "startIcon"> & {
label?: string;
color?: 'default' | 'inherit' | 'primary';
edge?: 'start' | 'end' | false;
} & import("@mui/x-data-grid").BaseIconButtonPropsOverrides, "component">, "ref"> | (GridActionsCellItemCommonProps & {
showInMenu: true;
/**
* If false, the menu will not close when this item is clicked.
* @default true
*/
closeMenuOnClick?: boolean;
closeMenu?: () => void;
label: React.ReactNode;
} & Omit<React.DOMAttributes<HTMLElement> & {
[k: `aria-${string}`]: any;
[k: `data-${string}`]: any;
className?: string;
style?: React.CSSProperties;
} & {
autoFocus?: boolean;
children?: React.ReactNode;
inert?: boolean;
disabled?: boolean;
iconStart?: React.ReactNode;
iconEnd?: React.ReactNode;
selected?: boolean;
value?: number | string | readonly string[];
style?: React.CSSProperties;
} & import("@mui/x-data-grid").BaseMenuItemPropsOverrides, "component">)) & React.RefAttributes<HTMLElement>>;
export { GridActionsCellItem };
@@ -0,0 +1,82 @@
"use strict";
'use client';
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.GridActionsCellItem = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var React = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _forwardRef = require("@mui/x-internals/forwardRef");
var _useGridRootProps = require("../../hooks/utils/useGridRootProps");
var _jsxRuntime = require("react/jsx-runtime");
const _excluded = ["label", "icon", "showInMenu", "onClick"],
_excluded2 = ["label", "icon", "showInMenu", "onClick", "closeMenuOnClick", "closeMenu"];
const GridActionsCellItem = exports.GridActionsCellItem = (0, _forwardRef.forwardRef)((props, ref) => {
const rootProps = (0, _useGridRootProps.useGridRootProps)();
if (!props.showInMenu) {
const {
label,
icon,
onClick
} = props,
other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
const handleClick = event => {
onClick?.(event);
};
return /*#__PURE__*/(0, _jsxRuntime.jsx)(rootProps.slots.baseIconButton, (0, _extends2.default)({
size: "small",
role: "menuitem",
"aria-label": label
}, other, {
onClick: handleClick
}, rootProps.slotProps?.baseIconButton, {
ref: ref,
children: /*#__PURE__*/React.cloneElement(icon, {
fontSize: 'inherit'
})
}));
}
const {
label,
icon,
onClick,
closeMenuOnClick = true,
closeMenu
} = props,
other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded2);
const handleClick = event => {
onClick?.(event);
if (closeMenuOnClick) {
closeMenu?.();
}
};
return /*#__PURE__*/(0, _jsxRuntime.jsx)(rootProps.slots.baseMenuItem, (0, _extends2.default)({
ref: ref
}, other, {
onClick: handleClick,
iconStart: icon,
children: label
}));
});
if (process.env.NODE_ENV !== "production") GridActionsCellItem.displayName = "GridActionsCellItem";
process.env.NODE_ENV !== "production" ? GridActionsCellItem.propTypes /* remove-proptypes */ = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "pnpm proptypes" |
// ----------------------------------------------------------------------
className: _propTypes.default.string,
/**
* from https://mui.com/material-ui/api/button-base/#ButtonBase-prop-component
*/
component: _propTypes.default.elementType,
disabled: _propTypes.default.bool,
icon: _propTypes.default /* @typescript-to-proptypes-ignore */.element,
label: _propTypes.default.node,
showInMenu: _propTypes.default.bool,
style: _propTypes.default.object
} : void 0;
@@ -0,0 +1,76 @@
'use client';
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
const _excluded = ["label", "icon", "showInMenu", "onClick"],
_excluded2 = ["label", "icon", "showInMenu", "onClick", "closeMenuOnClick", "closeMenu"];
import * as React from 'react';
import PropTypes from 'prop-types';
import { forwardRef } from '@mui/x-internals/forwardRef';
import { useGridRootProps } from "../../hooks/utils/useGridRootProps.mjs";
import { jsx as _jsx } from "react/jsx-runtime";
const GridActionsCellItem = forwardRef((props, ref) => {
const rootProps = useGridRootProps();
if (!props.showInMenu) {
const {
label,
icon,
onClick
} = props,
other = _objectWithoutPropertiesLoose(props, _excluded);
const handleClick = event => {
onClick?.(event);
};
return /*#__PURE__*/_jsx(rootProps.slots.baseIconButton, _extends({
size: "small",
role: "menuitem",
"aria-label": label
}, other, {
onClick: handleClick
}, rootProps.slotProps?.baseIconButton, {
ref: ref,
children: /*#__PURE__*/React.cloneElement(icon, {
fontSize: 'inherit'
})
}));
}
const {
label,
icon,
onClick,
closeMenuOnClick = true,
closeMenu
} = props,
other = _objectWithoutPropertiesLoose(props, _excluded2);
const handleClick = event => {
onClick?.(event);
if (closeMenuOnClick) {
closeMenu?.();
}
};
return /*#__PURE__*/_jsx(rootProps.slots.baseMenuItem, _extends({
ref: ref
}, other, {
onClick: handleClick,
iconStart: icon,
children: label
}));
});
if (process.env.NODE_ENV !== "production") GridActionsCellItem.displayName = "GridActionsCellItem";
process.env.NODE_ENV !== "production" ? GridActionsCellItem.propTypes /* remove-proptypes */ = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "pnpm proptypes" |
// ----------------------------------------------------------------------
className: PropTypes.string,
/**
* from https://mui.com/material-ui/api/button-base/#ButtonBase-prop-component
*/
component: PropTypes.elementType,
disabled: PropTypes.bool,
icon: PropTypes /* @typescript-to-proptypes-ignore */.element,
label: PropTypes.node,
showInMenu: PropTypes.bool,
style: PropTypes.object
} : void 0;
export { GridActionsCellItem };
@@ -0,0 +1,10 @@
import * as React from 'react';
import type { GridColDef } from "../../models/colDef/gridColDef.mjs";
import type { GridRenderCellParams } from "../../models/params/gridCellParams.mjs";
interface GridBooleanCellProps extends GridRenderCellParams {
hideDescendantCount?: boolean;
}
declare function GridBooleanCellRaw(props: GridBooleanCellProps): React.JSX.Element | null;
declare const GridBooleanCell: React.MemoExoticComponent<typeof GridBooleanCellRaw>;
export { GridBooleanCell };
export declare const renderBooleanCell: GridColDef['renderCell'];
@@ -0,0 +1,10 @@
import * as React from 'react';
import type { GridColDef } from "../../models/colDef/gridColDef.js";
import type { GridRenderCellParams } from "../../models/params/gridCellParams.js";
interface GridBooleanCellProps extends GridRenderCellParams {
hideDescendantCount?: boolean;
}
declare function GridBooleanCellRaw(props: GridBooleanCellProps): React.JSX.Element | null;
declare const GridBooleanCell: React.MemoExoticComponent<typeof GridBooleanCellRaw>;
export { GridBooleanCell };
export declare const renderBooleanCell: GridColDef['renderCell'];
@@ -0,0 +1,132 @@
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.renderBooleanCell = exports.GridBooleanCell = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var React = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _composeClasses = _interopRequireDefault(require("@mui/utils/composeClasses"));
var _useGridSelector = require("../../hooks/utils/useGridSelector");
var _gridRowsSelector = require("../../hooks/features/rows/gridRowsSelector");
var _gridClasses = require("../../constants/gridClasses");
var _useGridRootProps = require("../../hooks/utils/useGridRootProps");
var _useGridApiContext = require("../../hooks/utils/useGridApiContext");
var _gridRowsUtils = require("../../hooks/features/rows/gridRowsUtils");
var _constants = require("../../internals/constants");
var _GridFooterCell = require("./GridFooterCell");
var _jsxRuntime = require("react/jsx-runtime");
const _excluded = ["id", "value", "formattedValue", "api", "field", "row", "rowNode", "colDef", "cellMode", "isEditable", "hasFocus", "tabIndex", "hideDescendantCount"];
const useUtilityClasses = ownerState => {
const {
classes
} = ownerState;
const slots = {
root: ['booleanCell']
};
return (0, _composeClasses.default)(slots, _gridClasses.getDataGridUtilityClass, classes);
};
function GridBooleanCellRaw(props) {
const {
value,
rowNode
} = props,
other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
const apiRef = (0, _useGridApiContext.useGridApiContext)();
const rootProps = (0, _useGridRootProps.useGridRootProps)();
const ownerState = {
classes: rootProps.classes
};
const classes = useUtilityClasses(ownerState);
const maxDepth = (0, _useGridSelector.useGridSelector)(apiRef, _gridRowsSelector.gridRowMaximumTreeDepthSelector);
const isServerSideRowGroupingRow =
// @ts-expect-error - Access tree data prop
maxDepth > 0 && rowNode.type === 'group' && rootProps.treeData === false;
const Icon = React.useMemo(() => value ? rootProps.slots.booleanCellTrueIcon : rootProps.slots.booleanCellFalseIcon, [rootProps.slots.booleanCellFalseIcon, rootProps.slots.booleanCellTrueIcon, value]);
if (isServerSideRowGroupingRow && value === undefined) {
return null;
}
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Icon, (0, _extends2.default)({
fontSize: "small",
className: classes.root,
titleAccess: apiRef.current.getLocaleText(value ? 'booleanCellTrueLabel' : 'booleanCellFalseLabel'),
"data-value": Boolean(value)
}, other));
}
process.env.NODE_ENV !== "production" ? GridBooleanCellRaw.propTypes /* remove-proptypes */ = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "pnpm proptypes" |
// ----------------------------------------------------------------------
/**
* GridApi that let you manipulate the grid.
*/
api: _propTypes.default.object.isRequired,
/**
* The mode of the cell.
*/
cellMode: _propTypes.default.oneOf(['edit', 'view']).isRequired,
/**
* The column of the row that the current cell belongs to.
*/
colDef: _propTypes.default.object.isRequired,
/**
* The column field of the cell that triggered the event.
*/
field: _propTypes.default.string.isRequired,
/**
* The cell value formatted with the column valueFormatter.
*/
formattedValue: _propTypes.default.any,
/**
* If true, the cell is the active element.
*/
hasFocus: _propTypes.default.bool.isRequired,
hideDescendantCount: _propTypes.default.bool,
/**
* The grid row id.
*/
id: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]).isRequired,
/**
* If true, the cell is editable.
*/
isEditable: _propTypes.default.bool,
/**
* The row model of the row that the current cell belongs to.
*/
row: _propTypes.default.any.isRequired,
/**
* The node of the row that the current cell belongs to.
*/
rowNode: _propTypes.default.object.isRequired,
/**
* the tabIndex value.
*/
tabIndex: _propTypes.default.oneOf([-1, 0]).isRequired,
/**
* The cell value.
* If the column has `valueGetter`, use `params.row` to directly access the fields.
*/
value: _propTypes.default.any
} : void 0;
const GridBooleanCell = exports.GridBooleanCell = /*#__PURE__*/React.memo(GridBooleanCellRaw);
if (process.env.NODE_ENV !== "production") GridBooleanCell.displayName = "GridBooleanCell";
const renderBooleanCell = params => {
if (params.field !== _constants.GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD && (0, _gridRowsUtils.isAutogeneratedRowNode)(params.rowNode)) {
const aggregationMetaData = params.aggregation;
if (!aggregationMetaData) {
return '';
}
if (aggregationMetaData.position === 'footer') {
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_GridFooterCell.GridFooterCell, (0, _extends2.default)({}, params));
}
return params.formattedValue;
}
return /*#__PURE__*/(0, _jsxRuntime.jsx)(GridBooleanCell, (0, _extends2.default)({}, params));
};
exports.renderBooleanCell = renderBooleanCell;
if (process.env.NODE_ENV !== "production") renderBooleanCell.displayName = "renderBooleanCell";
@@ -0,0 +1,124 @@
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
const _excluded = ["id", "value", "formattedValue", "api", "field", "row", "rowNode", "colDef", "cellMode", "isEditable", "hasFocus", "tabIndex", "hideDescendantCount"];
import * as React from 'react';
import PropTypes from 'prop-types';
import composeClasses from '@mui/utils/composeClasses';
import { useGridSelector } from "../../hooks/utils/useGridSelector.mjs";
import { gridRowMaximumTreeDepthSelector } from "../../hooks/features/rows/gridRowsSelector.mjs";
import { getDataGridUtilityClass } from "../../constants/gridClasses.mjs";
import { useGridRootProps } from "../../hooks/utils/useGridRootProps.mjs";
import { useGridApiContext } from "../../hooks/utils/useGridApiContext.mjs";
import { isAutogeneratedRowNode } from "../../hooks/features/rows/gridRowsUtils.mjs";
import { GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD } from "../../internals/constants.mjs";
import { GridFooterCell } from "./GridFooterCell.mjs";
import { jsx as _jsx } from "react/jsx-runtime";
const useUtilityClasses = ownerState => {
const {
classes
} = ownerState;
const slots = {
root: ['booleanCell']
};
return composeClasses(slots, getDataGridUtilityClass, classes);
};
function GridBooleanCellRaw(props) {
const {
value,
rowNode
} = props,
other = _objectWithoutPropertiesLoose(props, _excluded);
const apiRef = useGridApiContext();
const rootProps = useGridRootProps();
const ownerState = {
classes: rootProps.classes
};
const classes = useUtilityClasses(ownerState);
const maxDepth = useGridSelector(apiRef, gridRowMaximumTreeDepthSelector);
const isServerSideRowGroupingRow =
// @ts-expect-error - Access tree data prop
maxDepth > 0 && rowNode.type === 'group' && rootProps.treeData === false;
const Icon = React.useMemo(() => value ? rootProps.slots.booleanCellTrueIcon : rootProps.slots.booleanCellFalseIcon, [rootProps.slots.booleanCellFalseIcon, rootProps.slots.booleanCellTrueIcon, value]);
if (isServerSideRowGroupingRow && value === undefined) {
return null;
}
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 /* remove-proptypes */ = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "pnpm 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,
/**
* The cell value formatted with the column valueFormatter.
*/
formattedValue: PropTypes.any,
/**
* If true, the cell is the active element.
*/
hasFocus: PropTypes.bool.isRequired,
hideDescendantCount: PropTypes.bool,
/**
* 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;
const GridBooleanCell = /*#__PURE__*/React.memo(GridBooleanCellRaw);
if (process.env.NODE_ENV !== "production") GridBooleanCell.displayName = "GridBooleanCell";
export { GridBooleanCell };
export const renderBooleanCell = params => {
if (params.field !== GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD && isAutogeneratedRowNode(params.rowNode)) {
const aggregationMetaData = params.aggregation;
if (!aggregationMetaData) {
return '';
}
if (aggregationMetaData.position === 'footer') {
return /*#__PURE__*/_jsx(GridFooterCell, _extends({}, params));
}
return params.formattedValue;
}
return /*#__PURE__*/_jsx(GridBooleanCell, _extends({}, params));
};
if (process.env.NODE_ENV !== "production") renderBooleanCell.displayName = "renderBooleanCell";
+70
View File
@@ -0,0 +1,70 @@
import * as React from 'react';
import type { GridRowId } from "../../models/index.mjs";
import type { GridAlignment, GridStateColDef } from "../../models/colDef/gridColDef.mjs";
import type { GridRowModel, GridTreeNode } from "../../models/gridRows.mjs";
import { PinnedColumnPosition } from "../../internals/constants.mjs";
export type GridCellProps = React.HTMLAttributes<HTMLDivElement> & {
align: GridAlignment;
className?: string;
colIndex: number;
column: GridStateColDef;
row: GridRowModel;
rowId: GridRowId;
rowNode: GridTreeNode;
width: number;
colSpan?: number;
disableDragEvents?: boolean;
isNotVisible: boolean;
pinnedOffset?: number;
pinnedPosition: PinnedColumnPosition;
showRightBorder: boolean;
showLeftBorder: boolean;
onClick?: React.MouseEventHandler<HTMLDivElement>;
onDoubleClick?: React.MouseEventHandler<HTMLDivElement>;
onMouseEnter?: React.MouseEventHandler<HTMLDivElement>;
onMouseDown?: React.MouseEventHandler<HTMLDivElement>;
onMouseLeave?: React.MouseEventHandler<HTMLDivElement>;
onMouseUp?: React.MouseEventHandler<HTMLDivElement>;
onMouseOver?: React.MouseEventHandler<HTMLDivElement>;
onKeyUp?: React.KeyboardEventHandler<HTMLDivElement>;
onKeyDown?: React.KeyboardEventHandler<HTMLDivElement>;
onDragEnter?: React.DragEventHandler<HTMLDivElement>;
onDragOver?: React.DragEventHandler<HTMLDivElement>;
onFocus?: React.FocusEventHandler<Element>;
children?: React.ReactNode;
style?: React.CSSProperties;
[x: `data-${string}`]: string;
};
declare const MemoizedGridCell: React.ForwardRefExoticComponent<GridCellProps> | React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & {
[x: `data-${string}`]: string;
align: GridAlignment;
className?: string;
colIndex: number;
column: GridStateColDef;
row: GridRowModel;
rowId: GridRowId;
rowNode: GridTreeNode;
width: number;
colSpan?: number;
disableDragEvents?: boolean;
isNotVisible: boolean;
pinnedOffset?: number;
pinnedPosition: PinnedColumnPosition;
showRightBorder: boolean;
showLeftBorder: boolean;
onClick?: React.MouseEventHandler<HTMLDivElement>;
onDoubleClick?: React.MouseEventHandler<HTMLDivElement>;
onMouseEnter?: React.MouseEventHandler<HTMLDivElement>;
onMouseDown?: React.MouseEventHandler<HTMLDivElement>;
onMouseLeave?: React.MouseEventHandler<HTMLDivElement>;
onMouseUp?: React.MouseEventHandler<HTMLDivElement>;
onMouseOver?: React.MouseEventHandler<HTMLDivElement>;
onKeyUp?: React.KeyboardEventHandler<HTMLDivElement>;
onKeyDown?: React.KeyboardEventHandler<HTMLDivElement>;
onDragEnter?: React.DragEventHandler<HTMLDivElement>;
onDragOver?: React.DragEventHandler<HTMLDivElement>;
onFocus?: React.FocusEventHandler<Element>;
children?: React.ReactNode;
style?: React.CSSProperties;
} & React.RefAttributes<HTMLDivElement>>;
export { MemoizedGridCell as GridCell };
+70
View File
@@ -0,0 +1,70 @@
import * as React from 'react';
import type { GridRowId } from "../../models/index.js";
import type { GridAlignment, GridStateColDef } from "../../models/colDef/gridColDef.js";
import type { GridRowModel, GridTreeNode } from "../../models/gridRows.js";
import { PinnedColumnPosition } from "../../internals/constants.js";
export type GridCellProps = React.HTMLAttributes<HTMLDivElement> & {
align: GridAlignment;
className?: string;
colIndex: number;
column: GridStateColDef;
row: GridRowModel;
rowId: GridRowId;
rowNode: GridTreeNode;
width: number;
colSpan?: number;
disableDragEvents?: boolean;
isNotVisible: boolean;
pinnedOffset?: number;
pinnedPosition: PinnedColumnPosition;
showRightBorder: boolean;
showLeftBorder: boolean;
onClick?: React.MouseEventHandler<HTMLDivElement>;
onDoubleClick?: React.MouseEventHandler<HTMLDivElement>;
onMouseEnter?: React.MouseEventHandler<HTMLDivElement>;
onMouseDown?: React.MouseEventHandler<HTMLDivElement>;
onMouseLeave?: React.MouseEventHandler<HTMLDivElement>;
onMouseUp?: React.MouseEventHandler<HTMLDivElement>;
onMouseOver?: React.MouseEventHandler<HTMLDivElement>;
onKeyUp?: React.KeyboardEventHandler<HTMLDivElement>;
onKeyDown?: React.KeyboardEventHandler<HTMLDivElement>;
onDragEnter?: React.DragEventHandler<HTMLDivElement>;
onDragOver?: React.DragEventHandler<HTMLDivElement>;
onFocus?: React.FocusEventHandler<Element>;
children?: React.ReactNode;
style?: React.CSSProperties;
[x: `data-${string}`]: string;
};
declare const MemoizedGridCell: React.ForwardRefExoticComponent<GridCellProps> | React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & {
[x: `data-${string}`]: string;
align: GridAlignment;
className?: string;
colIndex: number;
column: GridStateColDef;
row: GridRowModel;
rowId: GridRowId;
rowNode: GridTreeNode;
width: number;
colSpan?: number;
disableDragEvents?: boolean;
isNotVisible: boolean;
pinnedOffset?: number;
pinnedPosition: PinnedColumnPosition;
showRightBorder: boolean;
showLeftBorder: boolean;
onClick?: React.MouseEventHandler<HTMLDivElement>;
onDoubleClick?: React.MouseEventHandler<HTMLDivElement>;
onMouseEnter?: React.MouseEventHandler<HTMLDivElement>;
onMouseDown?: React.MouseEventHandler<HTMLDivElement>;
onMouseLeave?: React.MouseEventHandler<HTMLDivElement>;
onMouseUp?: React.MouseEventHandler<HTMLDivElement>;
onMouseOver?: React.MouseEventHandler<HTMLDivElement>;
onKeyUp?: React.KeyboardEventHandler<HTMLDivElement>;
onKeyDown?: React.KeyboardEventHandler<HTMLDivElement>;
onDragEnter?: React.DragEventHandler<HTMLDivElement>;
onDragOver?: React.DragEventHandler<HTMLDivElement>;
onFocus?: React.FocusEventHandler<Element>;
children?: React.ReactNode;
style?: React.CSSProperties;
} & React.RefAttributes<HTMLDivElement>>;
export { MemoizedGridCell as GridCell };
+337
View File
@@ -0,0 +1,337 @@
"use strict";
'use client';
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.GridCell = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var React = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _clsx = _interopRequireDefault(require("clsx"));
var _useForkRef = _interopRequireDefault(require("@mui/utils/useForkRef"));
var _composeClasses = _interopRequireDefault(require("@mui/utils/composeClasses"));
var _ownerDocument = _interopRequireDefault(require("@mui/utils/ownerDocument"));
var _capitalize = _interopRequireDefault(require("@mui/utils/capitalize"));
var _fastMemo = require("@mui/x-internals/fastMemo");
var _RtlProvider = require("@mui/system/RtlProvider");
var _forwardRef = require("@mui/x-internals/forwardRef");
var _store = require("@mui/x-internals/store");
var _xVirtualizer = require("@mui/x-virtualizer");
var _useEnhancedEffect = _interopRequireDefault(require("@mui/utils/useEnhancedEffect"));
var _focusElement = require("../../utils/focusElement");
var _gridClasses = require("../../constants/gridClasses");
var _models = require("../../models");
var _useGridSelector = require("../../hooks/utils/useGridSelector");
var _useGridRootProps = require("../../hooks/utils/useGridRootProps");
var _gridFocusStateSelector = require("../../hooks/features/focus/gridFocusStateSelector");
var _constants = require("../../internals/constants");
var _useGridPrivateApiContext = require("../../hooks/utils/useGridPrivateApiContext");
var _usePinnedScrollOffset = require("../../hooks/utils/usePinnedScrollOffset");
var _gridEditingSelectors = require("../../hooks/features/editing/gridEditingSelectors");
var _utils = require("../../internals/utils");
var _useGridConfiguration = require("../../hooks/utils/useGridConfiguration");
var _jsxRuntime = require("react/jsx-runtime");
const _excluded = ["column", "row", "rowId", "rowNode", "align", "children", "colIndex", "width", "className", "style", "colSpan", "disableDragEvents", "isNotVisible", "pinnedOffset", "pinnedPosition", "showRightBorder", "showLeftBorder", "onClick", "onDoubleClick", "onMouseDown", "onMouseUp", "onMouseOver", "onKeyDown", "onKeyUp", "onDragEnter", "onDragOver"],
_excluded2 = ["changeReason", "unstable_updateValueOnRender"];
const useUtilityClasses = ownerState => {
const {
align,
showLeftBorder,
showRightBorder,
pinnedPosition,
isEditable,
isSelected,
isSelectionMode,
classes
} = ownerState;
const slots = {
root: ['cell', `cell--text${(0, _capitalize.default)(align)}`, isSelected && 'selected', isEditable && 'cell--editable', showLeftBorder && 'cell--withLeftBorder', showRightBorder && 'cell--withRightBorder', pinnedPosition === _constants.PinnedColumnPosition.LEFT && 'cell--pinnedLeft', pinnedPosition === _constants.PinnedColumnPosition.RIGHT && 'cell--pinnedRight', isSelectionMode && !isEditable && 'cell--selectionMode']
};
return (0, _composeClasses.default)(slots, _gridClasses.getDataGridUtilityClass, classes);
};
let warnedOnce = false;
// TODO(v7): Removing the wrapper will break the docs performance visualization demo.
const GridCell = (0, _forwardRef.forwardRef)(function GridCell(props, ref) {
const {
column,
row,
rowId,
rowNode,
align,
colIndex,
width,
className,
style: styleProp,
colSpan,
disableDragEvents,
isNotVisible,
pinnedOffset,
pinnedPosition,
showRightBorder,
showLeftBorder,
onClick,
onDoubleClick,
onMouseDown,
onMouseUp,
onMouseOver,
onKeyDown,
onKeyUp,
onDragEnter,
onDragOver
} = props,
other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
const apiRef = (0, _useGridPrivateApiContext.useGridPrivateApiContext)();
const rootProps = (0, _useGridRootProps.useGridRootProps)();
const isRtl = (0, _RtlProvider.useRtl)();
const field = column.field;
const editCellState = (0, _useGridSelector.useGridSelector)(apiRef, _gridEditingSelectors.gridEditCellStateSelector, {
rowId,
field
});
const config = (0, _useGridConfiguration.useGridConfiguration)();
const cellAggregationResult = config.hooks.useCellAggregationResult(rowId, field);
const cellMode = editCellState ? _models.GridCellModes.Edit : _models.GridCellModes.View;
const {
value: forcedValue,
formattedValue: forcedFormattedValue
} = cellAggregationResult || {};
const cellParams = apiRef.current.getCellParamsForRow(rowId, field, row, {
colDef: column,
cellMode,
rowNode: rowNode,
tabIndex: (0, _useGridSelector.useGridSelector)(apiRef, () => {
const cellTabIndex = (0, _gridFocusStateSelector.gridTabIndexCellSelector)(apiRef);
return cellTabIndex && cellTabIndex.field === field && cellTabIndex.id === rowId ? 0 : -1;
}),
hasFocus: (0, _useGridSelector.useGridSelector)(apiRef, () => {
const focus = (0, _gridFocusStateSelector.gridFocusCellSelector)(apiRef);
return focus?.id === rowId && focus.field === field;
}),
value: forcedValue,
formattedValue: forcedFormattedValue
});
cellParams.api = apiRef.current;
// Subscribe to changes of the `isCellEditable` API result to ensure cells re-render.
// We don't use the result.
// Subscription will trigger a new call of `getCellParamsForRow` above which will recompute the correct value of `isEditable`.
// This is to ensure both of the following cases work:
// - https://github.com/mui/mui-x/issues/19732
// - https://github.com/mui/mui-x/issues/20143
(0, _useGridSelector.useGridSelector)(apiRef, () => apiRef.current.isCellEditable(cellParams));
const isSelected = (0, _useGridSelector.useGridSelector)(apiRef, () => apiRef.current.unstable_applyPipeProcessors('isCellSelected', false, {
id: rowId,
field
}));
const store = apiRef.current.virtualizer.store;
const hiddenCells = (0, _store.useStore)(store, _xVirtualizer.Rowspan.selectors.hiddenCells);
const spannedCells = (0, _store.useStore)(store, _xVirtualizer.Rowspan.selectors.spannedCells);
const {
hasFocus,
isEditable = false,
value
} = cellParams;
const tabIndex = (cellMode === 'view' || !isEditable) && column.type !== 'actions' ? cellParams.tabIndex : -1;
const {
classes: rootClasses,
getCellClassName
} = rootProps;
// There is a hidden grid state access in `applyPipeProcessor('cellClassName', ...)`
const pipesClassName = (0, _useGridSelector.useGridSelector)(apiRef, () => apiRef.current.unstable_applyPipeProcessors('cellClassName', [], {
id: rowId,
field
}).filter(Boolean).join(' '));
const classNames = [pipesClassName];
if (column.cellClassName) {
classNames.push(typeof column.cellClassName === 'function' ? column.cellClassName(cellParams) : column.cellClassName);
}
if (column.display === 'flex') {
classNames.push(_gridClasses.gridClasses['cell--flex']);
}
if (getCellClassName) {
classNames.push(getCellClassName(cellParams));
}
const valueToRender = cellParams.formattedValue ?? value;
const cellRef = React.useRef(null);
const handleRef = (0, _useForkRef.default)(ref, cellRef);
const isSelectionMode = rootProps.cellSelection ?? false;
const ownerState = {
align,
showLeftBorder,
showRightBorder,
isEditable,
classes: rootProps.classes,
pinnedPosition,
isSelected,
isSelectionMode
};
const classes = useUtilityClasses(ownerState);
const publishMouseUp = React.useCallback(eventName => event => {
const params = apiRef.current.getCellParams(rowId, field || '');
apiRef.current.publishEvent(eventName, params, event);
if (onMouseUp) {
onMouseUp(event);
}
}, [apiRef, field, onMouseUp, rowId]);
const publishMouseDown = React.useCallback(eventName => event => {
const params = apiRef.current.getCellParams(rowId, field || '');
apiRef.current.publishEvent(eventName, params, event);
if (onMouseDown) {
onMouseDown(event);
}
}, [apiRef, field, onMouseDown, rowId]);
const publish = React.useCallback((eventName, propHandler) => event => {
// The row might have been deleted during the click
if (!apiRef.current.getRow(rowId)) {
return;
}
const params = apiRef.current.getCellParams(rowId, field || '');
apiRef.current.publishEvent(eventName, params, event);
if (propHandler) {
propHandler(event);
}
}, [apiRef, field, rowId]);
const isCellRowSpanned = hiddenCells[rowId]?.[colIndex] ?? false;
const rowSpan = spannedCells[rowId]?.[colIndex] ?? 1;
const pinnedScrollOffset = (0, _usePinnedScrollOffset.usePinnedScrollOffset)(apiRef, pinnedPosition);
const style = React.useMemo(() => {
if (isNotVisible) {
return {
padding: 0,
opacity: 0,
width: 0,
height: 0,
border: 0
};
}
const cellStyle = (0, _utils.attachPinnedStyle)((0, _extends2.default)({
'--width': `${width}px`
}, styleProp), isRtl, pinnedPosition, pinnedOffset !== undefined ? pinnedOffset + pinnedScrollOffset : undefined);
const isLeftPinned = pinnedPosition === _constants.PinnedColumnPosition.LEFT;
const isRightPinned = pinnedPosition === _constants.PinnedColumnPosition.RIGHT;
if (rowSpan > 1) {
cellStyle.height = `calc(var(--height) * ${rowSpan})`;
cellStyle.zIndex = 10;
if (isLeftPinned || isRightPinned) {
cellStyle.zIndex = 40;
}
}
return cellStyle;
}, [width, isNotVisible, styleProp, pinnedOffset, pinnedPosition, pinnedScrollOffset, isRtl, rowSpan]);
(0, _useEnhancedEffect.default)(() => {
if (!hasFocus || cellMode === _models.GridCellModes.Edit) {
return;
}
const doc = (0, _ownerDocument.default)(apiRef.current.rootElementRef.current);
if (cellRef.current && !cellRef.current.contains(doc.activeElement)) {
const focusableElement = cellRef.current.querySelector('[tabindex="0"]');
const elementToFocus = focusableElement || cellRef.current;
(0, _focusElement.focusElement)(elementToFocus, apiRef);
}
}, [hasFocus, cellMode, apiRef]);
if (isCellRowSpanned) {
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
"data-colindex": colIndex,
role: "none",
style: (0, _extends2.default)({
width: 'var(--width)'
}, style)
});
}
let handleFocus = other.onFocus;
if (process.env.NODE_ENV === 'test' && rootProps.experimentalFeatures?.warnIfFocusStateIsNotSynced) {
handleFocus = event => {
const focusedCell = (0, _gridFocusStateSelector.gridFocusCellSelector)(apiRef);
if (focusedCell?.id === rowId && focusedCell.field === field) {
if (typeof other.onFocus === 'function') {
other.onFocus(event);
}
return;
}
if (!warnedOnce) {
console.warn([`MUI X: The cell with id=${rowId} and field=${field} received focus.`, `According to the state, the focus should be at id=${focusedCell?.id}, field=${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;
}
};
}
let children;
let title;
if (editCellState === null && column.renderCell) {
children = column.renderCell(cellParams);
}
if (editCellState !== null && column.renderEditCell) {
const updatedRow = apiRef.current.getRowWithUpdatedValues(rowId, column.field);
// eslint-disable-next-line @typescript-eslint/naming-convention
const editCellStateRest = (0, _objectWithoutPropertiesLoose2.default)(editCellState, _excluded2);
const formattedValue = column.valueFormatter ? column.valueFormatter(editCellState.value, updatedRow, column, apiRef) : cellParams.formattedValue;
const params = (0, _extends2.default)({}, cellParams, {
row: updatedRow,
formattedValue
}, editCellStateRest);
children = column.renderEditCell(params);
classNames.push(_gridClasses.gridClasses['cell--editing']);
classNames.push(rootClasses?.['cell--editing']);
}
if (children === undefined) {
const valueString = valueToRender?.toString();
children = valueString;
title = valueString;
}
const draggableEventHandlers = disableDragEvents ? null : {
onDragEnter: publish('cellDragEnter', onDragEnter),
onDragOver: publish('cellDragOver', onDragOver)
};
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", (0, _extends2.default)({
className: (0, _clsx.default)(classes.root, classNames, className),
role: "gridcell",
"data-field": field,
"data-colindex": colIndex,
"aria-colindex": colIndex + 1,
"aria-colspan": colSpan,
"aria-rowspan": rowSpan,
style: style,
title: title,
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,
ref: handleRef,
children: children
}));
});
if (process.env.NODE_ENV !== "production") GridCell.displayName = "GridCell";
process.env.NODE_ENV !== "production" ? GridCell.propTypes /* remove-proptypes */ = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "pnpm proptypes" |
// ----------------------------------------------------------------------
align: _propTypes.default.oneOf(['center', 'left', 'right']).isRequired,
colIndex: _propTypes.default.number.isRequired,
colSpan: _propTypes.default.number,
column: _propTypes.default.object.isRequired,
disableDragEvents: _propTypes.default.bool,
isNotVisible: _propTypes.default.bool.isRequired,
pinnedOffset: _propTypes.default.number,
pinnedPosition: _propTypes.default.oneOf([0, 1, 2, 3]).isRequired,
row: _propTypes.default.object.isRequired,
rowId: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]).isRequired,
rowNode: _propTypes.default.object.isRequired,
showLeftBorder: _propTypes.default.bool.isRequired,
showRightBorder: _propTypes.default.bool.isRequired,
width: _propTypes.default.number.isRequired
} : void 0;
const MemoizedGridCell = exports.GridCell = (0, _fastMemo.fastMemo)(GridCell);
+331
View File
@@ -0,0 +1,331 @@
'use client';
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
const _excluded = ["column", "row", "rowId", "rowNode", "align", "children", "colIndex", "width", "className", "style", "colSpan", "disableDragEvents", "isNotVisible", "pinnedOffset", "pinnedPosition", "showRightBorder", "showLeftBorder", "onClick", "onDoubleClick", "onMouseDown", "onMouseUp", "onMouseOver", "onKeyDown", "onKeyUp", "onDragEnter", "onDragOver"],
_excluded2 = ["changeReason", "unstable_updateValueOnRender"];
import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import useForkRef from '@mui/utils/useForkRef';
import composeClasses from '@mui/utils/composeClasses';
import ownerDocument from '@mui/utils/ownerDocument';
import capitalize from '@mui/utils/capitalize';
import { fastMemo } from '@mui/x-internals/fastMemo';
import { useRtl } from '@mui/system/RtlProvider';
import { forwardRef } from '@mui/x-internals/forwardRef';
import { useStore } from '@mui/x-internals/store';
import { Rowspan } from '@mui/x-virtualizer';
import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
import { focusElement } from "../../utils/focusElement.mjs";
import { getDataGridUtilityClass, gridClasses } from "../../constants/gridClasses.mjs";
import { GridCellModes } from "../../models/index.mjs";
import { useGridSelector } from "../../hooks/utils/useGridSelector.mjs";
import { useGridRootProps } from "../../hooks/utils/useGridRootProps.mjs";
import { gridFocusCellSelector, gridTabIndexCellSelector } from "../../hooks/features/focus/gridFocusStateSelector.mjs";
import { PinnedColumnPosition } from "../../internals/constants.mjs";
import { useGridPrivateApiContext } from "../../hooks/utils/useGridPrivateApiContext.mjs";
import { usePinnedScrollOffset } from "../../hooks/utils/usePinnedScrollOffset.mjs";
import { gridEditCellStateSelector } from "../../hooks/features/editing/gridEditingSelectors.mjs";
import { attachPinnedStyle } from "../../internals/utils/index.mjs";
import { useGridConfiguration } from "../../hooks/utils/useGridConfiguration.mjs";
import { jsx as _jsx } from "react/jsx-runtime";
const useUtilityClasses = ownerState => {
const {
align,
showLeftBorder,
showRightBorder,
pinnedPosition,
isEditable,
isSelected,
isSelectionMode,
classes
} = ownerState;
const slots = {
root: ['cell', `cell--text${capitalize(align)}`, isSelected && 'selected', isEditable && 'cell--editable', showLeftBorder && 'cell--withLeftBorder', showRightBorder && 'cell--withRightBorder', pinnedPosition === PinnedColumnPosition.LEFT && 'cell--pinnedLeft', pinnedPosition === PinnedColumnPosition.RIGHT && 'cell--pinnedRight', isSelectionMode && !isEditable && 'cell--selectionMode']
};
return composeClasses(slots, getDataGridUtilityClass, classes);
};
let warnedOnce = false;
// TODO(v7): Removing the wrapper will break the docs performance visualization demo.
const GridCell = forwardRef(function GridCell(props, ref) {
const {
column,
row,
rowId,
rowNode,
align,
colIndex,
width,
className,
style: styleProp,
colSpan,
disableDragEvents,
isNotVisible,
pinnedOffset,
pinnedPosition,
showRightBorder,
showLeftBorder,
onClick,
onDoubleClick,
onMouseDown,
onMouseUp,
onMouseOver,
onKeyDown,
onKeyUp,
onDragEnter,
onDragOver
} = props,
other = _objectWithoutPropertiesLoose(props, _excluded);
const apiRef = useGridPrivateApiContext();
const rootProps = useGridRootProps();
const isRtl = useRtl();
const field = column.field;
const editCellState = useGridSelector(apiRef, gridEditCellStateSelector, {
rowId,
field
});
const config = useGridConfiguration();
const cellAggregationResult = config.hooks.useCellAggregationResult(rowId, field);
const cellMode = editCellState ? GridCellModes.Edit : GridCellModes.View;
const {
value: forcedValue,
formattedValue: forcedFormattedValue
} = cellAggregationResult || {};
const cellParams = apiRef.current.getCellParamsForRow(rowId, field, row, {
colDef: column,
cellMode,
rowNode: rowNode,
tabIndex: useGridSelector(apiRef, () => {
const cellTabIndex = gridTabIndexCellSelector(apiRef);
return cellTabIndex && cellTabIndex.field === field && cellTabIndex.id === rowId ? 0 : -1;
}),
hasFocus: useGridSelector(apiRef, () => {
const focus = gridFocusCellSelector(apiRef);
return focus?.id === rowId && focus.field === field;
}),
value: forcedValue,
formattedValue: forcedFormattedValue
});
cellParams.api = apiRef.current;
// Subscribe to changes of the `isCellEditable` API result to ensure cells re-render.
// We don't use the result.
// Subscription will trigger a new call of `getCellParamsForRow` above which will recompute the correct value of `isEditable`.
// This is to ensure both of the following cases work:
// - https://github.com/mui/mui-x/issues/19732
// - https://github.com/mui/mui-x/issues/20143
useGridSelector(apiRef, () => apiRef.current.isCellEditable(cellParams));
const isSelected = useGridSelector(apiRef, () => apiRef.current.unstable_applyPipeProcessors('isCellSelected', false, {
id: rowId,
field
}));
const store = apiRef.current.virtualizer.store;
const hiddenCells = useStore(store, Rowspan.selectors.hiddenCells);
const spannedCells = useStore(store, Rowspan.selectors.spannedCells);
const {
hasFocus,
isEditable = false,
value
} = cellParams;
const tabIndex = (cellMode === 'view' || !isEditable) && column.type !== 'actions' ? cellParams.tabIndex : -1;
const {
classes: rootClasses,
getCellClassName
} = rootProps;
// There is a hidden grid state access in `applyPipeProcessor('cellClassName', ...)`
const pipesClassName = useGridSelector(apiRef, () => apiRef.current.unstable_applyPipeProcessors('cellClassName', [], {
id: rowId,
field
}).filter(Boolean).join(' '));
const classNames = [pipesClassName];
if (column.cellClassName) {
classNames.push(typeof column.cellClassName === 'function' ? column.cellClassName(cellParams) : column.cellClassName);
}
if (column.display === 'flex') {
classNames.push(gridClasses['cell--flex']);
}
if (getCellClassName) {
classNames.push(getCellClassName(cellParams));
}
const valueToRender = cellParams.formattedValue ?? value;
const cellRef = React.useRef(null);
const handleRef = useForkRef(ref, cellRef);
const isSelectionMode = rootProps.cellSelection ?? false;
const ownerState = {
align,
showLeftBorder,
showRightBorder,
isEditable,
classes: rootProps.classes,
pinnedPosition,
isSelected,
isSelectionMode
};
const classes = useUtilityClasses(ownerState);
const publishMouseUp = React.useCallback(eventName => event => {
const params = apiRef.current.getCellParams(rowId, field || '');
apiRef.current.publishEvent(eventName, params, event);
if (onMouseUp) {
onMouseUp(event);
}
}, [apiRef, field, onMouseUp, rowId]);
const publishMouseDown = React.useCallback(eventName => event => {
const params = apiRef.current.getCellParams(rowId, field || '');
apiRef.current.publishEvent(eventName, params, event);
if (onMouseDown) {
onMouseDown(event);
}
}, [apiRef, field, onMouseDown, rowId]);
const publish = React.useCallback((eventName, propHandler) => event => {
// The row might have been deleted during the click
if (!apiRef.current.getRow(rowId)) {
return;
}
const params = apiRef.current.getCellParams(rowId, field || '');
apiRef.current.publishEvent(eventName, params, event);
if (propHandler) {
propHandler(event);
}
}, [apiRef, field, rowId]);
const isCellRowSpanned = hiddenCells[rowId]?.[colIndex] ?? false;
const rowSpan = spannedCells[rowId]?.[colIndex] ?? 1;
const pinnedScrollOffset = usePinnedScrollOffset(apiRef, pinnedPosition);
const style = React.useMemo(() => {
if (isNotVisible) {
return {
padding: 0,
opacity: 0,
width: 0,
height: 0,
border: 0
};
}
const cellStyle = attachPinnedStyle(_extends({
'--width': `${width}px`
}, styleProp), isRtl, pinnedPosition, pinnedOffset !== undefined ? pinnedOffset + pinnedScrollOffset : undefined);
const isLeftPinned = pinnedPosition === PinnedColumnPosition.LEFT;
const isRightPinned = pinnedPosition === PinnedColumnPosition.RIGHT;
if (rowSpan > 1) {
cellStyle.height = `calc(var(--height) * ${rowSpan})`;
cellStyle.zIndex = 10;
if (isLeftPinned || isRightPinned) {
cellStyle.zIndex = 40;
}
}
return cellStyle;
}, [width, isNotVisible, styleProp, pinnedOffset, pinnedPosition, pinnedScrollOffset, isRtl, rowSpan]);
useEnhancedEffect(() => {
if (!hasFocus || cellMode === GridCellModes.Edit) {
return;
}
const doc = ownerDocument(apiRef.current.rootElementRef.current);
if (cellRef.current && !cellRef.current.contains(doc.activeElement)) {
const focusableElement = cellRef.current.querySelector('[tabindex="0"]');
const elementToFocus = focusableElement || cellRef.current;
focusElement(elementToFocus, apiRef);
}
}, [hasFocus, cellMode, apiRef]);
if (isCellRowSpanned) {
return /*#__PURE__*/_jsx("div", {
"data-colindex": colIndex,
role: "none",
style: _extends({
width: 'var(--width)'
}, style)
});
}
let handleFocus = other.onFocus;
if (process.env.NODE_ENV === 'test' && rootProps.experimentalFeatures?.warnIfFocusStateIsNotSynced) {
handleFocus = event => {
const focusedCell = gridFocusCellSelector(apiRef);
if (focusedCell?.id === rowId && focusedCell.field === field) {
if (typeof other.onFocus === 'function') {
other.onFocus(event);
}
return;
}
if (!warnedOnce) {
console.warn([`MUI X: The cell with id=${rowId} and field=${field} received focus.`, `According to the state, the focus should be at id=${focusedCell?.id}, field=${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;
}
};
}
let children;
let title;
if (editCellState === null && column.renderCell) {
children = column.renderCell(cellParams);
}
if (editCellState !== null && column.renderEditCell) {
const updatedRow = apiRef.current.getRowWithUpdatedValues(rowId, column.field);
// eslint-disable-next-line @typescript-eslint/naming-convention
const editCellStateRest = _objectWithoutPropertiesLoose(editCellState, _excluded2);
const formattedValue = column.valueFormatter ? column.valueFormatter(editCellState.value, updatedRow, column, apiRef) : cellParams.formattedValue;
const params = _extends({}, cellParams, {
row: updatedRow,
formattedValue
}, editCellStateRest);
children = column.renderEditCell(params);
classNames.push(gridClasses['cell--editing']);
classNames.push(rootClasses?.['cell--editing']);
}
if (children === undefined) {
const valueString = valueToRender?.toString();
children = valueString;
title = valueString;
}
const draggableEventHandlers = disableDragEvents ? null : {
onDragEnter: publish('cellDragEnter', onDragEnter),
onDragOver: publish('cellDragOver', onDragOver)
};
return /*#__PURE__*/_jsx("div", _extends({
className: clsx(classes.root, classNames, className),
role: "gridcell",
"data-field": field,
"data-colindex": colIndex,
"aria-colindex": colIndex + 1,
"aria-colspan": colSpan,
"aria-rowspan": rowSpan,
style: style,
title: title,
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,
ref: handleRef,
children: children
}));
});
if (process.env.NODE_ENV !== "production") GridCell.displayName = "GridCell";
process.env.NODE_ENV !== "production" ? GridCell.propTypes /* remove-proptypes */ = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "pnpm proptypes" |
// ----------------------------------------------------------------------
align: PropTypes.oneOf(['center', 'left', 'right']).isRequired,
colIndex: PropTypes.number.isRequired,
colSpan: PropTypes.number,
column: PropTypes.object.isRequired,
disableDragEvents: PropTypes.bool,
isNotVisible: PropTypes.bool.isRequired,
pinnedOffset: PropTypes.number,
pinnedPosition: PropTypes.oneOf([0, 1, 2, 3]).isRequired,
row: PropTypes.object.isRequired,
rowId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
rowNode: PropTypes.object.isRequired,
showLeftBorder: PropTypes.bool.isRequired,
showRightBorder: PropTypes.bool.isRequired,
width: PropTypes.number.isRequired
} : void 0;
const MemoizedGridCell = fastMemo(GridCell);
export { MemoizedGridCell as GridCell };
@@ -0,0 +1,17 @@
import * as React from 'react';
import type { GridRenderEditCellParams } from "../../models/params/gridCellParams.mjs";
export interface GridEditBooleanCellProps extends GridRenderEditCellParams, Omit<React.DetailedHTMLProps<React.LabelHTMLAttributes<HTMLLabelElement>, HTMLLabelElement>, 'id' | 'tabIndex'> {
/**
* 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?: (event: React.ChangeEvent<HTMLInputElement>, newValue: boolean) => Promise<void> | void;
}
declare function GridEditBooleanCell(props: GridEditBooleanCellProps): React.JSX.Element;
declare namespace GridEditBooleanCell {
var propTypes: any;
}
export { GridEditBooleanCell };
export declare const renderEditBooleanCell: (params: GridEditBooleanCellProps) => React.JSX.Element;
@@ -0,0 +1,17 @@
import * as React from 'react';
import type { GridRenderEditCellParams } from "../../models/params/gridCellParams.js";
export interface GridEditBooleanCellProps extends GridRenderEditCellParams, Omit<React.DetailedHTMLProps<React.LabelHTMLAttributes<HTMLLabelElement>, HTMLLabelElement>, 'id' | 'tabIndex'> {
/**
* 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?: (event: React.ChangeEvent<HTMLInputElement>, newValue: boolean) => Promise<void> | void;
}
declare function GridEditBooleanCell(props: GridEditBooleanCellProps): React.JSX.Element;
declare namespace GridEditBooleanCell {
var propTypes: any;
}
export { GridEditBooleanCell };
export declare const renderEditBooleanCell: (params: GridEditBooleanCellProps) => React.JSX.Element;
@@ -0,0 +1,152 @@
"use strict";
'use client';
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.GridEditBooleanCell = GridEditBooleanCell;
exports.renderEditBooleanCell = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var React = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _clsx = _interopRequireDefault(require("clsx"));
var _composeClasses = _interopRequireDefault(require("@mui/utils/composeClasses"));
var _useId = _interopRequireDefault(require("@mui/utils/useId"));
var _useEnhancedEffect = _interopRequireDefault(require("@mui/utils/useEnhancedEffect"));
var _gridClasses = require("../../constants/gridClasses");
var _useGridRootProps = require("../../hooks/utils/useGridRootProps");
var _useGridApiContext = require("../../hooks/utils/useGridApiContext");
var _jsxRuntime = require("react/jsx-runtime");
const _excluded = ["id", "value", "formattedValue", "api", "field", "row", "rowNode", "colDef", "cellMode", "isEditable", "tabIndex", "className", "hasFocus", "isValidating", "isProcessingProps", "error", "onValueChange"];
const useUtilityClasses = ownerState => {
const {
classes
} = ownerState;
const slots = {
root: ['editBooleanCell']
};
return (0, _composeClasses.default)(slots, _gridClasses.getDataGridUtilityClass, classes);
};
function GridEditBooleanCell(props) {
const {
id: idProp,
value,
field,
className,
hasFocus,
onValueChange
} = props,
other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
const apiRef = (0, _useGridApiContext.useGridApiContext)();
const inputRef = React.useRef(null);
const id = (0, _useId.default)();
const [valueState, setValueState] = React.useState(value);
const rootProps = (0, _useGridRootProps.useGridRootProps)();
const ownerState = {
classes: rootProps.classes
};
const classes = useUtilityClasses(ownerState);
const handleChange = React.useCallback(async event => {
const newValue = event.target.checked;
if (onValueChange) {
await onValueChange(event, newValue);
}
setValueState(newValue);
await apiRef.current.setEditCellValue({
id: idProp,
field,
value: newValue
}, event);
}, [apiRef, field, idProp, onValueChange]);
React.useEffect(() => {
setValueState(value);
}, [value]);
(0, _useEnhancedEffect.default)(() => {
if (hasFocus) {
inputRef.current.focus();
}
}, [hasFocus]);
return /*#__PURE__*/(0, _jsxRuntime.jsx)("label", (0, _extends2.default)({
htmlFor: id,
className: (0, _clsx.default)(classes.root, className)
}, other, {
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(rootProps.slots.baseCheckbox, (0, _extends2.default)({
id: id,
inputRef: inputRef,
checked: Boolean(valueState),
onChange: handleChange,
size: "small"
}, rootProps.slotProps?.baseCheckbox))
}));
}
process.env.NODE_ENV !== "production" ? GridEditBooleanCell.propTypes /* remove-proptypes */ = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "pnpm proptypes" |
// ----------------------------------------------------------------------
/**
* GridApi that let you manipulate the grid.
*/
api: _propTypes.default.object.isRequired,
/**
* The mode of the cell.
*/
cellMode: _propTypes.default.oneOf(['edit', 'view']).isRequired,
changeReason: _propTypes.default.oneOf(['debouncedSetEditCellValue', 'setEditCellValue']),
/**
* The column of the row that the current cell belongs to.
*/
colDef: _propTypes.default.object.isRequired,
/**
* The column field of the cell that triggered the event.
*/
field: _propTypes.default.string.isRequired,
/**
* The cell value formatted with the column valueFormatter.
*/
formattedValue: _propTypes.default.any,
/**
* If true, the cell is the active element.
*/
hasFocus: _propTypes.default.bool.isRequired,
/**
* The grid row id.
*/
id: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]).isRequired,
/**
* If true, the cell is editable.
*/
isEditable: _propTypes.default.bool,
isProcessingProps: _propTypes.default.bool,
isValidating: _propTypes.default.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.default.func,
/**
* The row model of the row that the current cell belongs to.
*/
row: _propTypes.default.any.isRequired,
/**
* The node of the row that the current cell belongs to.
*/
rowNode: _propTypes.default.object.isRequired,
/**
* the tabIndex value.
*/
tabIndex: _propTypes.default.oneOf([-1, 0]).isRequired,
/**
* The cell value.
* If the column has `valueGetter`, use `params.row` to directly access the fields.
*/
value: _propTypes.default.any
} : void 0;
const renderEditBooleanCell = params => /*#__PURE__*/(0, _jsxRuntime.jsx)(GridEditBooleanCell, (0, _extends2.default)({}, params));
exports.renderEditBooleanCell = renderEditBooleanCell;
if (process.env.NODE_ENV !== "production") renderEditBooleanCell.displayName = "renderEditBooleanCell";
@@ -0,0 +1,144 @@
'use client';
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
const _excluded = ["id", "value", "formattedValue", "api", "field", "row", "rowNode", "colDef", "cellMode", "isEditable", "tabIndex", "className", "hasFocus", "isValidating", "isProcessingProps", "error", "onValueChange"];
import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import composeClasses from '@mui/utils/composeClasses';
import useId from '@mui/utils/useId';
import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
import { getDataGridUtilityClass } from "../../constants/gridClasses.mjs";
import { useGridRootProps } from "../../hooks/utils/useGridRootProps.mjs";
import { useGridApiContext } from "../../hooks/utils/useGridApiContext.mjs";
import { jsx as _jsx } from "react/jsx-runtime";
const useUtilityClasses = ownerState => {
const {
classes
} = ownerState;
const slots = {
root: ['editBooleanCell']
};
return composeClasses(slots, getDataGridUtilityClass, classes);
};
function GridEditBooleanCell(props) {
const {
id: idProp,
value,
field,
className,
hasFocus,
onValueChange
} = props,
other = _objectWithoutPropertiesLoose(props, _excluded);
const apiRef = useGridApiContext();
const inputRef = React.useRef(null);
const id = useId();
const [valueState, setValueState] = React.useState(value);
const rootProps = useGridRootProps();
const ownerState = {
classes: rootProps.classes
};
const classes = useUtilityClasses(ownerState);
const handleChange = React.useCallback(async event => {
const newValue = event.target.checked;
if (onValueChange) {
await onValueChange(event, newValue);
}
setValueState(newValue);
await apiRef.current.setEditCellValue({
id: idProp,
field,
value: newValue
}, event);
}, [apiRef, field, idProp, onValueChange]);
React.useEffect(() => {
setValueState(value);
}, [value]);
useEnhancedEffect(() => {
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?.baseCheckbox))
}));
}
process.env.NODE_ENV !== "production" ? GridEditBooleanCell.propTypes /* remove-proptypes */ = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "pnpm 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 const renderEditBooleanCell = params => /*#__PURE__*/_jsx(GridEditBooleanCell, _extends({}, params));
if (process.env.NODE_ENV !== "production") renderEditBooleanCell.displayName = "renderEditBooleanCell";
@@ -0,0 +1,21 @@
import * as React from 'react';
import type { GridSlotProps } from "../../models/gridSlotsComponent.mjs";
import type { GridRenderEditCellParams } from "../../models/params/gridCellParams.mjs";
export interface GridEditDateCellProps extends GridRenderEditCellParams {
/**
* 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?: (event: React.ChangeEvent<HTMLInputElement>, newValue: Date | null) => Promise<void> | void;
slotProps?: {
root?: Partial<GridSlotProps['baseInput']>;
};
}
declare function GridEditDateCell(props: GridEditDateCellProps): React.JSX.Element;
declare namespace GridEditDateCell {
var propTypes: any;
}
export { GridEditDateCell };
export declare const renderEditDateCell: (params: GridRenderEditCellParams) => React.JSX.Element;
@@ -0,0 +1,21 @@
import * as React from 'react';
import type { GridSlotProps } from "../../models/gridSlotsComponent.js";
import type { GridRenderEditCellParams } from "../../models/params/gridCellParams.js";
export interface GridEditDateCellProps extends GridRenderEditCellParams {
/**
* 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?: (event: React.ChangeEvent<HTMLInputElement>, newValue: Date | null) => Promise<void> | void;
slotProps?: {
root?: Partial<GridSlotProps['baseInput']>;
};
}
declare function GridEditDateCell(props: GridEditDateCellProps): React.JSX.Element;
declare namespace GridEditDateCell {
var propTypes: any;
}
export { GridEditDateCell };
export declare const renderEditDateCell: (params: GridRenderEditCellParams) => React.JSX.Element;
@@ -0,0 +1,207 @@
"use strict";
'use client';
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.GridEditDateCell = GridEditDateCell;
exports.renderEditDateCell = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var React = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _composeClasses = _interopRequireDefault(require("@mui/utils/composeClasses"));
var _useEnhancedEffect = _interopRequireDefault(require("@mui/utils/useEnhancedEffect"));
var _styles = require("@mui/material/styles");
var _assert = require("../../utils/assert");
var _gridClasses = require("../../constants/gridClasses");
var _useGridRootProps = require("../../hooks/utils/useGridRootProps");
var _useGridApiContext = require("../../hooks/utils/useGridApiContext");
var _jsxRuntime = require("react/jsx-runtime");
const _excluded = ["id", "value", "formattedValue", "api", "field", "row", "rowNode", "colDef", "cellMode", "isEditable", "tabIndex", "hasFocus", "inputProps", "isValidating", "isProcessingProps", "onValueChange", "slotProps"];
const StyledInputBase = (0, _styles.styled)(_assert.NotRendered, {
slot: 'internal'
})({
fontSize: 'inherit'
});
const useUtilityClasses = ownerState => {
const {
classes
} = ownerState;
const slots = {
root: ['editInputCell']
};
return (0, _composeClasses.default)(slots, _gridClasses.getDataGridUtilityClass, classes);
};
function GridEditDateCell(props) {
const {
id,
value: valueProp,
field,
colDef,
hasFocus,
onValueChange,
slotProps
} = props,
other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
const isDateTime = colDef.type === 'dateTime';
const apiRef = (0, _useGridApiContext.useGridApiContext)();
const inputRef = React.useRef(null);
const valueTransformed = React.useMemo(() => {
let parsedDate;
if (valueProp == null) {
parsedDate = null;
} else if (valueProp instanceof Date) {
parsedDate = valueProp;
} else {
parsedDate = new Date((valueProp ?? '').toString());
}
let formattedDate;
if (parsedDate == null || Number.isNaN(parsedDate.getTime())) {
formattedDate = '';
} else {
const localDate = new Date(parsedDate.getTime() - parsedDate.getTimezoneOffset() * 60 * 1000);
formattedDate = localDate.toISOString().substr(0, isDateTime ? 16 : 10);
}
return {
parsed: parsedDate,
formatted: formattedDate
};
}, [valueProp, isDateTime]);
const [valueState, setValueState] = React.useState(valueTransformed);
const rootProps = (0, _useGridRootProps.useGridRootProps)();
const ownerState = {
classes: rootProps.classes
};
const classes = useUtilityClasses(ownerState);
const parseValueToDate = React.useCallback(value => {
if (value === '') {
return null;
}
const [date, time] = value.split('T');
const [year, month, day] = date.split('-');
const parsedDate = new Date();
parsedDate.setFullYear(Number(year), Number(month) - 1, Number(day));
parsedDate.setHours(0, 0, 0, 0);
if (time) {
const [hours, minutes] = time.split(':');
parsedDate.setHours(Number(hours), Number(minutes), 0, 0);
}
return parsedDate;
}, []);
const handleChange = React.useCallback(async event => {
const newFormattedDate = event.target.value;
const newParsedDate = parseValueToDate(newFormattedDate);
if (onValueChange) {
await onValueChange(event, newParsedDate);
}
setValueState({
parsed: newParsedDate,
formatted: newFormattedDate
});
apiRef.current.setEditCellValue({
id,
field,
value: newParsedDate
}, event);
}, [apiRef, field, id, onValueChange, parseValueToDate]);
React.useEffect(() => {
setValueState(state => {
if (valueTransformed.parsed !== state.parsed && valueTransformed.parsed?.getTime() !== state.parsed?.getTime()) {
return valueTransformed;
}
return state;
});
}, [valueTransformed]);
(0, _useEnhancedEffect.default)(() => {
if (hasFocus) {
inputRef.current.focus();
}
}, [hasFocus]);
return /*#__PURE__*/(0, _jsxRuntime.jsx)(StyledInputBase, (0, _extends2.default)({
as: rootProps.slots.baseInput,
inputRef: inputRef,
fullWidth: true,
className: classes.root,
type: isDateTime ? 'datetime-local' : 'date',
value: valueState.formatted,
onChange: handleChange
}, other, slotProps?.root, {
slotProps: {
htmlInput: (0, _extends2.default)({
max: isDateTime ? '9999-12-31T23:59' : '9999-12-31'
}, slotProps?.root?.slotProps?.htmlInput)
}
}));
}
process.env.NODE_ENV !== "production" ? GridEditDateCell.propTypes /* remove-proptypes */ = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "pnpm proptypes" |
// ----------------------------------------------------------------------
/**
* GridApi that let you manipulate the grid.
*/
api: _propTypes.default.object.isRequired,
/**
* The mode of the cell.
*/
cellMode: _propTypes.default.oneOf(['edit', 'view']).isRequired,
changeReason: _propTypes.default.oneOf(['debouncedSetEditCellValue', 'setEditCellValue']),
/**
* The column of the row that the current cell belongs to.
*/
colDef: _propTypes.default.object.isRequired,
/**
* The column field of the cell that triggered the event.
*/
field: _propTypes.default.string.isRequired,
/**
* The cell value formatted with the column valueFormatter.
*/
formattedValue: _propTypes.default.any,
/**
* If true, the cell is the active element.
*/
hasFocus: _propTypes.default.bool.isRequired,
/**
* The grid row id.
*/
id: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]).isRequired,
/**
* If true, the cell is editable.
*/
isEditable: _propTypes.default.bool,
isProcessingProps: _propTypes.default.bool,
isValidating: _propTypes.default.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.default.func,
/**
* The row model of the row that the current cell belongs to.
*/
row: _propTypes.default.any.isRequired,
/**
* The node of the row that the current cell belongs to.
*/
rowNode: _propTypes.default.object.isRequired,
slotProps: _propTypes.default.object,
/**
* the tabIndex value.
*/
tabIndex: _propTypes.default.oneOf([-1, 0]).isRequired,
/**
* The cell value.
* If the column has `valueGetter`, use `params.row` to directly access the fields.
*/
value: _propTypes.default.any
} : void 0;
const renderEditDateCell = params => /*#__PURE__*/(0, _jsxRuntime.jsx)(GridEditDateCell, (0, _extends2.default)({}, params));
exports.renderEditDateCell = renderEditDateCell;
if (process.env.NODE_ENV !== "production") renderEditDateCell.displayName = "renderEditDateCell";
@@ -0,0 +1,199 @@
'use client';
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
const _excluded = ["id", "value", "formattedValue", "api", "field", "row", "rowNode", "colDef", "cellMode", "isEditable", "tabIndex", "hasFocus", "inputProps", "isValidating", "isProcessingProps", "onValueChange", "slotProps"];
import * as React from 'react';
import PropTypes from 'prop-types';
import composeClasses from '@mui/utils/composeClasses';
import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
import { styled } from '@mui/material/styles';
import { NotRendered } from "../../utils/assert.mjs";
import { getDataGridUtilityClass } from "../../constants/gridClasses.mjs";
import { useGridRootProps } from "../../hooks/utils/useGridRootProps.mjs";
import { useGridApiContext } from "../../hooks/utils/useGridApiContext.mjs";
import { jsx as _jsx } from "react/jsx-runtime";
const StyledInputBase = styled(NotRendered, {
slot: 'internal'
})({
fontSize: 'inherit'
});
const useUtilityClasses = ownerState => {
const {
classes
} = ownerState;
const slots = {
root: ['editInputCell']
};
return composeClasses(slots, getDataGridUtilityClass, classes);
};
function GridEditDateCell(props) {
const {
id,
value: valueProp,
field,
colDef,
hasFocus,
onValueChange,
slotProps
} = props,
other = _objectWithoutPropertiesLoose(props, _excluded);
const isDateTime = colDef.type === 'dateTime';
const apiRef = useGridApiContext();
const inputRef = React.useRef(null);
const valueTransformed = React.useMemo(() => {
let parsedDate;
if (valueProp == null) {
parsedDate = null;
} else if (valueProp instanceof Date) {
parsedDate = valueProp;
} else {
parsedDate = new Date((valueProp ?? '').toString());
}
let formattedDate;
if (parsedDate == null || Number.isNaN(parsedDate.getTime())) {
formattedDate = '';
} else {
const localDate = new Date(parsedDate.getTime() - parsedDate.getTimezoneOffset() * 60 * 1000);
formattedDate = localDate.toISOString().substr(0, isDateTime ? 16 : 10);
}
return {
parsed: parsedDate,
formatted: formattedDate
};
}, [valueProp, isDateTime]);
const [valueState, setValueState] = React.useState(valueTransformed);
const rootProps = useGridRootProps();
const ownerState = {
classes: rootProps.classes
};
const classes = useUtilityClasses(ownerState);
const parseValueToDate = React.useCallback(value => {
if (value === '') {
return null;
}
const [date, time] = value.split('T');
const [year, month, day] = date.split('-');
const parsedDate = new Date();
parsedDate.setFullYear(Number(year), Number(month) - 1, Number(day));
parsedDate.setHours(0, 0, 0, 0);
if (time) {
const [hours, minutes] = time.split(':');
parsedDate.setHours(Number(hours), Number(minutes), 0, 0);
}
return parsedDate;
}, []);
const handleChange = React.useCallback(async event => {
const newFormattedDate = event.target.value;
const newParsedDate = parseValueToDate(newFormattedDate);
if (onValueChange) {
await onValueChange(event, newParsedDate);
}
setValueState({
parsed: newParsedDate,
formatted: newFormattedDate
});
apiRef.current.setEditCellValue({
id,
field,
value: newParsedDate
}, event);
}, [apiRef, field, id, onValueChange, parseValueToDate]);
React.useEffect(() => {
setValueState(state => {
if (valueTransformed.parsed !== state.parsed && valueTransformed.parsed?.getTime() !== state.parsed?.getTime()) {
return valueTransformed;
}
return state;
});
}, [valueTransformed]);
useEnhancedEffect(() => {
if (hasFocus) {
inputRef.current.focus();
}
}, [hasFocus]);
return /*#__PURE__*/_jsx(StyledInputBase, _extends({
as: rootProps.slots.baseInput,
inputRef: inputRef,
fullWidth: true,
className: classes.root,
type: isDateTime ? 'datetime-local' : 'date',
value: valueState.formatted,
onChange: handleChange
}, other, slotProps?.root, {
slotProps: {
htmlInput: _extends({
max: isDateTime ? '9999-12-31T23:59' : '9999-12-31'
}, slotProps?.root?.slotProps?.htmlInput)
}
}));
}
process.env.NODE_ENV !== "production" ? GridEditDateCell.propTypes /* remove-proptypes */ = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "pnpm 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,
slotProps: PropTypes.object,
/**
* 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 const renderEditDateCell = params => /*#__PURE__*/_jsx(GridEditDateCell, _extends({}, params));
if (process.env.NODE_ENV !== "production") renderEditDateCell.displayName = "renderEditDateCell";
@@ -0,0 +1,19 @@
import * as React from 'react';
import type { GridSlotProps } from "../../models/gridSlotsComponent.mjs";
import type { GridRenderEditCellParams } from "../../models/params/gridCellParams.mjs";
export interface GridEditInputCellProps extends GridRenderEditCellParams {
debounceMs?: number;
/**
* 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?: (event: React.ChangeEvent<HTMLInputElement>, newValue: string) => Promise<void> | void;
slotProps?: {
root?: Partial<GridSlotProps['baseInput']>;
};
}
declare const GridEditInputCell: React.ForwardRefExoticComponent<GridEditInputCellProps> | React.ForwardRefExoticComponent<Omit<GridEditInputCellProps, "ref"> & React.RefAttributes<HTMLInputElement>>;
export { GridEditInputCell };
export declare const renderEditInputCell: (params: GridEditInputCellProps) => React.JSX.Element;
@@ -0,0 +1,19 @@
import * as React from 'react';
import type { GridSlotProps } from "../../models/gridSlotsComponent.js";
import type { GridRenderEditCellParams } from "../../models/params/gridCellParams.js";
export interface GridEditInputCellProps extends GridRenderEditCellParams {
debounceMs?: number;
/**
* 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?: (event: React.ChangeEvent<HTMLInputElement>, newValue: string) => Promise<void> | void;
slotProps?: {
root?: Partial<GridSlotProps['baseInput']>;
};
}
declare const GridEditInputCell: React.ForwardRefExoticComponent<GridEditInputCellProps> | React.ForwardRefExoticComponent<Omit<GridEditInputCellProps, "ref"> & React.RefAttributes<HTMLInputElement>>;
export { GridEditInputCell };
export declare const renderEditInputCell: (params: GridEditInputCellProps) => React.JSX.Element;
@@ -0,0 +1,180 @@
"use strict";
'use client';
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.renderEditInputCell = exports.GridEditInputCell = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var React = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _composeClasses = _interopRequireDefault(require("@mui/utils/composeClasses"));
var _useEnhancedEffect = _interopRequireDefault(require("@mui/utils/useEnhancedEffect"));
var _styles = require("@mui/material/styles");
var _forwardRef = require("@mui/x-internals/forwardRef");
var _assert = require("../../utils/assert");
var _cssVariables = require("../../constants/cssVariables");
var _gridClasses = require("../../constants/gridClasses");
var _useGridRootProps = require("../../hooks/utils/useGridRootProps");
var _useGridApiContext = require("../../hooks/utils/useGridApiContext");
var _jsxRuntime = require("react/jsx-runtime");
const _excluded = ["id", "value", "formattedValue", "api", "field", "row", "rowNode", "colDef", "cellMode", "isEditable", "tabIndex", "hasFocus", "isValidating", "debounceMs", "isProcessingProps", "onValueChange", "slotProps"];
const useUtilityClasses = ownerState => {
const {
classes
} = ownerState;
const slots = {
root: ['editInputCell']
};
return (0, _composeClasses.default)(slots, _gridClasses.getDataGridUtilityClass, classes);
};
const GridEditInputCellRoot = (0, _styles.styled)(_assert.NotRendered, {
name: 'MuiDataGrid',
slot: 'EditInputCell'
})({
font: _cssVariables.vars.typography.font.body,
padding: '1px 0',
'& input': {
padding: '0 16px',
height: '100%'
}
});
const GridEditInputCell = exports.GridEditInputCell = (0, _forwardRef.forwardRef)((props, ref) => {
const rootProps = (0, _useGridRootProps.useGridRootProps)();
const {
id,
value,
field,
colDef,
hasFocus,
debounceMs = 200,
isProcessingProps,
onValueChange,
slotProps
} = props,
other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
const apiRef = (0, _useGridApiContext.useGridApiContext)();
const inputRef = React.useRef(null);
const [valueState, setValueState] = React.useState(value);
const classes = useUtilityClasses(rootProps);
const handleChange = React.useCallback(async event => {
const newValue = event.target.value;
const column = apiRef.current.getColumn(field);
let parsedValue = newValue;
if (column?.valueParser) {
parsedValue = column.valueParser(newValue, apiRef.current.getRow(id), column, apiRef);
}
setValueState(parsedValue);
apiRef.current.setEditCellValue({
id,
field,
value: parsedValue,
debounceMs,
unstable_skipValueParser: true
}, event);
if (onValueChange) {
await onValueChange(event, newValue);
}
}, [apiRef, debounceMs, field, id, onValueChange]);
const meta = apiRef.current.unstable_getEditCellMeta(id, field);
React.useEffect(() => {
if (meta?.changeReason !== 'debouncedSetEditCellValue') {
setValueState(value);
}
}, [meta, value]);
(0, _useEnhancedEffect.default)(() => {
if (hasFocus) {
inputRef.current.focus();
}
}, [hasFocus]);
return /*#__PURE__*/(0, _jsxRuntime.jsx)(GridEditInputCellRoot, (0, _extends2.default)({
as: rootProps.slots.baseInput,
inputRef: inputRef,
className: classes.root,
ownerState: rootProps,
fullWidth: true,
type: colDef.type === 'number' ? colDef.type : 'text',
value: valueState ?? '',
onChange: handleChange,
endAdornment: isProcessingProps ? /*#__PURE__*/(0, _jsxRuntime.jsx)(rootProps.slots.loadIcon, {
fontSize: "small",
color: "action"
}) : undefined
}, other, slotProps?.root, {
ref: ref
}));
});
if (process.env.NODE_ENV !== "production") GridEditInputCell.displayName = "GridEditInputCell";
process.env.NODE_ENV !== "production" ? GridEditInputCell.propTypes /* remove-proptypes */ = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "pnpm proptypes" |
// ----------------------------------------------------------------------
/**
* GridApi that let you manipulate the grid.
*/
api: _propTypes.default.object.isRequired,
/**
* The mode of the cell.
*/
cellMode: _propTypes.default.oneOf(['edit', 'view']).isRequired,
changeReason: _propTypes.default.oneOf(['debouncedSetEditCellValue', 'setEditCellValue']),
/**
* The column of the row that the current cell belongs to.
*/
colDef: _propTypes.default.object.isRequired,
debounceMs: _propTypes.default.number,
/**
* The column field of the cell that triggered the event.
*/
field: _propTypes.default.string.isRequired,
/**
* The cell value formatted with the column valueFormatter.
*/
formattedValue: _propTypes.default.any,
/**
* If true, the cell is the active element.
*/
hasFocus: _propTypes.default.bool.isRequired,
/**
* The grid row id.
*/
id: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]).isRequired,
/**
* If true, the cell is editable.
*/
isEditable: _propTypes.default.bool,
isProcessingProps: _propTypes.default.bool,
isValidating: _propTypes.default.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.default.func,
/**
* The row model of the row that the current cell belongs to.
*/
row: _propTypes.default.any.isRequired,
/**
* The node of the row that the current cell belongs to.
*/
rowNode: _propTypes.default.object.isRequired,
slotProps: _propTypes.default.object,
/**
* the tabIndex value.
*/
tabIndex: _propTypes.default.oneOf([-1, 0]).isRequired,
/**
* The cell value.
* If the column has `valueGetter`, use `params.row` to directly access the fields.
*/
value: _propTypes.default.any
} : void 0;
const renderEditInputCell = params => /*#__PURE__*/(0, _jsxRuntime.jsx)(GridEditInputCell, (0, _extends2.default)({}, params));
exports.renderEditInputCell = renderEditInputCell;
if (process.env.NODE_ENV !== "production") renderEditInputCell.displayName = "renderEditInputCell";
@@ -0,0 +1,173 @@
'use client';
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
const _excluded = ["id", "value", "formattedValue", "api", "field", "row", "rowNode", "colDef", "cellMode", "isEditable", "tabIndex", "hasFocus", "isValidating", "debounceMs", "isProcessingProps", "onValueChange", "slotProps"];
import * as React from 'react';
import PropTypes from 'prop-types';
import composeClasses from '@mui/utils/composeClasses';
import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
import { styled } from '@mui/material/styles';
import { forwardRef } from '@mui/x-internals/forwardRef';
import { NotRendered } from "../../utils/assert.mjs";
import { vars } from "../../constants/cssVariables.mjs";
import { getDataGridUtilityClass } from "../../constants/gridClasses.mjs";
import { useGridRootProps } from "../../hooks/utils/useGridRootProps.mjs";
import { useGridApiContext } from "../../hooks/utils/useGridApiContext.mjs";
import { jsx as _jsx } from "react/jsx-runtime";
const useUtilityClasses = ownerState => {
const {
classes
} = ownerState;
const slots = {
root: ['editInputCell']
};
return composeClasses(slots, getDataGridUtilityClass, classes);
};
const GridEditInputCellRoot = styled(NotRendered, {
name: 'MuiDataGrid',
slot: 'EditInputCell'
})({
font: vars.typography.font.body,
padding: '1px 0',
'& input': {
padding: '0 16px',
height: '100%'
}
});
const GridEditInputCell = forwardRef((props, ref) => {
const rootProps = useGridRootProps();
const {
id,
value,
field,
colDef,
hasFocus,
debounceMs = 200,
isProcessingProps,
onValueChange,
slotProps
} = props,
other = _objectWithoutPropertiesLoose(props, _excluded);
const apiRef = useGridApiContext();
const inputRef = React.useRef(null);
const [valueState, setValueState] = React.useState(value);
const classes = useUtilityClasses(rootProps);
const handleChange = React.useCallback(async event => {
const newValue = event.target.value;
const column = apiRef.current.getColumn(field);
let parsedValue = newValue;
if (column?.valueParser) {
parsedValue = column.valueParser(newValue, apiRef.current.getRow(id), column, apiRef);
}
setValueState(parsedValue);
apiRef.current.setEditCellValue({
id,
field,
value: parsedValue,
debounceMs,
unstable_skipValueParser: true
}, event);
if (onValueChange) {
await onValueChange(event, newValue);
}
}, [apiRef, debounceMs, field, id, onValueChange]);
const meta = apiRef.current.unstable_getEditCellMeta(id, field);
React.useEffect(() => {
if (meta?.changeReason !== 'debouncedSetEditCellValue') {
setValueState(value);
}
}, [meta, value]);
useEnhancedEffect(() => {
if (hasFocus) {
inputRef.current.focus();
}
}, [hasFocus]);
return /*#__PURE__*/_jsx(GridEditInputCellRoot, _extends({
as: rootProps.slots.baseInput,
inputRef: inputRef,
className: classes.root,
ownerState: rootProps,
fullWidth: true,
type: colDef.type === 'number' ? colDef.type : 'text',
value: valueState ?? '',
onChange: handleChange,
endAdornment: isProcessingProps ? /*#__PURE__*/_jsx(rootProps.slots.loadIcon, {
fontSize: "small",
color: "action"
}) : undefined
}, other, slotProps?.root, {
ref: ref
}));
});
if (process.env.NODE_ENV !== "production") GridEditInputCell.displayName = "GridEditInputCell";
process.env.NODE_ENV !== "production" ? GridEditInputCell.propTypes /* remove-proptypes */ = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "pnpm 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,
slotProps: PropTypes.object,
/**
* 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 const renderEditInputCell = params => /*#__PURE__*/_jsx(GridEditInputCell, _extends({}, params));
if (process.env.NODE_ENV !== "production") renderEditInputCell.displayName = "renderEditInputCell";
@@ -0,0 +1,44 @@
import * as React from 'react';
import type { GridRenderEditCellParams } from "../../models/params/gridCellParams.mjs";
import type { GridSlotProps } from "../../models/gridSlotsComponent.mjs";
export interface GridEditLongTextCellProps extends GridRenderEditCellParams<any, string | null> {
debounceMs?: number;
/**
* Callback called when the value is changed by the user.
* @param {React.ChangeEvent<HTMLTextAreaElement>} event The event source of the callback.
* @param {string} 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?: (event: React.ChangeEvent<HTMLTextAreaElement>, newValue: string) => Promise<void> | void;
/**
* Props passed to internal components.
*/
slotProps?: {
/**
* Props passed to the root element.
*/
root?: React.HTMLAttributes<HTMLDivElement>;
/**
* Props passed to the value element.
*/
value?: React.HTMLAttributes<HTMLDivElement>;
/**
* Props passed to the popper element.
*/
popper?: Partial<GridSlotProps['basePopper']>;
/**
* Props passed to the popper content element.
*/
popperContent?: React.HTMLAttributes<HTMLDivElement>;
/**
* Props passed to the textarea element.
*/
textarea?: Partial<GridSlotProps['baseTextarea']>;
};
}
declare function GridEditLongTextCell(props: GridEditLongTextCellProps): React.JSX.Element;
declare namespace GridEditLongTextCell {
var propTypes: any;
}
export { GridEditLongTextCell };
export declare const renderEditLongTextCell: (params: GridEditLongTextCellProps) => React.JSX.Element;
@@ -0,0 +1,44 @@
import * as React from 'react';
import type { GridRenderEditCellParams } from "../../models/params/gridCellParams.js";
import type { GridSlotProps } from "../../models/gridSlotsComponent.js";
export interface GridEditLongTextCellProps extends GridRenderEditCellParams<any, string | null> {
debounceMs?: number;
/**
* Callback called when the value is changed by the user.
* @param {React.ChangeEvent<HTMLTextAreaElement>} event The event source of the callback.
* @param {string} 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?: (event: React.ChangeEvent<HTMLTextAreaElement>, newValue: string) => Promise<void> | void;
/**
* Props passed to internal components.
*/
slotProps?: {
/**
* Props passed to the root element.
*/
root?: React.HTMLAttributes<HTMLDivElement>;
/**
* Props passed to the value element.
*/
value?: React.HTMLAttributes<HTMLDivElement>;
/**
* Props passed to the popper element.
*/
popper?: Partial<GridSlotProps['basePopper']>;
/**
* Props passed to the popper content element.
*/
popperContent?: React.HTMLAttributes<HTMLDivElement>;
/**
* Props passed to the textarea element.
*/
textarea?: Partial<GridSlotProps['baseTextarea']>;
};
}
declare function GridEditLongTextCell(props: GridEditLongTextCellProps): React.JSX.Element;
declare namespace GridEditLongTextCell {
var propTypes: any;
}
export { GridEditLongTextCell };
export declare const renderEditLongTextCell: (params: GridEditLongTextCellProps) => React.JSX.Element;
@@ -0,0 +1,389 @@
"use strict";
'use client';
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.GridEditLongTextCell = GridEditLongTextCell;
exports.renderEditLongTextCell = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var React = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _clsx = _interopRequireDefault(require("clsx"));
var _composeClasses = _interopRequireDefault(require("@mui/utils/composeClasses"));
var _useEnhancedEffect = _interopRequireDefault(require("@mui/utils/useEnhancedEffect"));
var _styles = require("@mui/material/styles");
var _gridClasses = require("../../constants/gridClasses");
var _useGridRootProps = require("../../hooks/utils/useGridRootProps");
var _useGridApiContext = require("../../hooks/utils/useGridApiContext");
var _useGridSelector = require("../../hooks/utils/useGridSelector");
var _gridDimensionsSelectors = require("../../hooks/features/dimensions/gridDimensionsSelectors");
var _assert = require("../../utils/assert");
var _cssVariables = require("../../constants/cssVariables");
var _jsxRuntime = require("react/jsx-runtime");
const useUtilityClasses = ownerState => {
const {
classes
} = ownerState;
const slots = {
root: ['editLongTextCell'],
value: ['editLongTextCellValue'],
popup: ['editLongTextCellPopup'],
popperContent: ['editLongTextCellPopperContent'],
textarea: ['editLongTextCellTextarea']
};
return (0, _composeClasses.default)(slots, _gridClasses.getDataGridUtilityClass, classes);
};
const GridEditLongTextCellTextarea = (0, _styles.styled)(_assert.NotRendered, {
name: 'MuiDataGrid',
slot: 'EditLongTextCellTextarea'
})(({
theme
}) => (0, _extends2.default)({
width: '100%',
padding: 0
}, theme.typography.body2, {
letterSpacing: 'normal',
outline: 'none',
background: 'transparent',
border: 'none',
resize: 'vertical'
}));
const GridEditLongTextCellRoot = (0, _styles.styled)('div', {
name: 'MuiDataGrid',
slot: 'EditLongTextCell'
})({
display: 'flex',
alignItems: 'center',
width: '100%',
height: '100%',
position: 'relative'
});
const GridEditLongTextCellValue = (0, _styles.styled)('div', {
name: 'MuiDataGrid',
slot: 'EditLongTextCellValue'
})({
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
width: '100%',
paddingInline: 10
});
const GridEditLongTextCellPopper = (0, _styles.styled)(_assert.NotRendered, {
name: 'MuiDataGrid',
slot: 'EditLongTextCellPopper'
})(({
theme
}) => ({
zIndex: _cssVariables.vars.zIndex.menu,
background: (theme.vars || theme).palette.background.paper,
'&[data-popper-reference-hidden]': {
opacity: 0 // use opacity to preserve focus.
}
}));
const GridEditLongTextCellPopperContent = (0, _styles.styled)('div', {
name: 'MuiDataGrid',
slot: 'EditLongTextCellPopperContent'
})(({
theme
}) => (0, _extends2.default)({}, theme.typography.body2, {
letterSpacing: 'normal',
paddingBlock: 15.5,
paddingInline: 9,
height: 'max-content',
overflow: 'auto',
whiteSpace: 'pre-wrap',
wordBreak: 'break-word',
width: 'var(--_width)',
border: `1px solid ${(theme.vars || theme).palette.divider}`,
boxShadow: (theme.vars || theme).shadows[4],
boxSizing: 'border-box'
}));
function GridEditLongTextCell(props) {
const {
id,
value,
field,
colDef,
hasFocus,
cellMode,
slotProps
} = props;
const rootProps = (0, _useGridRootProps.useGridRootProps)();
const apiRef = (0, _useGridApiContext.useGridApiContext)();
const classes = useUtilityClasses(rootProps);
const rowHeight = (0, _useGridSelector.useGridSelector)(apiRef, _gridDimensionsSelectors.gridRowHeightSelector);
const [valueState, setValueState] = React.useState(value);
const [anchorEl, setAnchorEl] = React.useState(null);
const meta = apiRef.current.unstable_getEditCellMeta(id, field);
const popupId = `${id}-${field}-longtext-edit-popup`;
// Only show popup when this cell has focus
// This fixes editMode="row" where all cells enter edit mode simultaneously
const showPopup = hasFocus && Boolean(anchorEl);
React.useEffect(() => {
if (meta?.changeReason !== 'debouncedSetEditCellValue') {
setValueState(value);
}
}, [meta, value]);
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(GridEditLongTextCellRoot, (0, _extends2.default)({
tabIndex: cellMode === 'edit' && rootProps.editMode === 'row' ? 0 : undefined,
ref: setAnchorEl,
"aria-controls": showPopup ? popupId : undefined,
"aria-expanded": showPopup
}, slotProps?.root, {
className: (0, _clsx.default)(classes.root, slotProps?.root?.className),
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(GridEditLongTextCellValue, (0, _extends2.default)({}, slotProps?.value, {
className: (0, _clsx.default)(classes.value, slotProps?.value?.className),
children: valueState
})), /*#__PURE__*/(0, _jsxRuntime.jsx)(GridEditLongTextCellPopper, (0, _extends2.default)({
as: rootProps.slots.basePopper,
ownerState: rootProps,
id: popupId,
role: "dialog",
"aria-label": colDef.headerName || field,
open: showPopup,
target: anchorEl,
placement: "bottom-start",
flip: true,
material: {
container: anchorEl?.closest('[role="row"]'),
modifiers: [{
name: 'offset',
options: {
offset: [-1, -rowHeight]
}
}]
}
}, slotProps?.popper, {
className: (0, _clsx.default)(classes.popup, slotProps?.popper?.className),
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(GridEditLongTextCellPopperContent, (0, _extends2.default)({}, slotProps?.popperContent, {
className: (0, _clsx.default)(classes.popperContent, slotProps?.popperContent?.className),
style: {
'--_width': `${colDef.computedWidth}px`
},
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(GridEditLongTextarea, (0, _extends2.default)({}, props, {
valueState: valueState,
setValueState: setValueState
}))
}))
}))]
}));
}
process.env.NODE_ENV !== "production" ? GridEditLongTextCell.propTypes /* remove-proptypes */ = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "pnpm proptypes" |
// ----------------------------------------------------------------------
/**
* GridApi that let you manipulate the grid.
*/
api: _propTypes.default.object.isRequired,
/**
* The mode of the cell.
*/
cellMode: _propTypes.default.oneOf(['edit', 'view']).isRequired,
changeReason: _propTypes.default.oneOf(['debouncedSetEditCellValue', 'setEditCellValue']),
/**
* The column of the row that the current cell belongs to.
*/
colDef: _propTypes.default.object.isRequired,
debounceMs: _propTypes.default.number,
/**
* The column field of the cell that triggered the event.
*/
field: _propTypes.default.string.isRequired,
/**
* The cell value formatted with the column valueFormatter.
*/
formattedValue: _propTypes.default.string,
/**
* If true, the cell is the active element.
*/
hasFocus: _propTypes.default.bool.isRequired,
/**
* The grid row id.
*/
id: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]).isRequired,
/**
* If true, the cell is editable.
*/
isEditable: _propTypes.default.bool,
isProcessingProps: _propTypes.default.bool,
isValidating: _propTypes.default.bool,
/**
* Callback called when the value is changed by the user.
* @param {React.ChangeEvent<HTMLTextAreaElement>} event The event source of the callback.
* @param {string} 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.default.func,
/**
* The row model of the row that the current cell belongs to.
*/
row: _propTypes.default.any.isRequired,
/**
* The node of the row that the current cell belongs to.
*/
rowNode: _propTypes.default.object.isRequired,
/**
* Props passed to internal components.
*/
slotProps: _propTypes.default.object,
/**
* the tabIndex value.
*/
tabIndex: _propTypes.default.oneOf([-1, 0]).isRequired,
/**
* The cell value.
* If the column has `valueGetter`, use `params.row` to directly access the fields.
*/
value: _propTypes.default.string
} : void 0;
function GridEditLongTextarea(props) {
const {
id,
field,
colDef,
debounceMs = 200,
onValueChange,
valueState,
setValueState,
hasFocus,
slotProps
} = props;
const textareaRef = React.useRef(null);
const apiRef = (0, _useGridApiContext.useGridApiContext)();
const rootProps = (0, _useGridRootProps.useGridRootProps)();
const classes = useUtilityClasses(rootProps);
(0, _useEnhancedEffect.default)(() => {
if (hasFocus && textareaRef.current) {
// preventScroll: the popper is portaled into the GridRow, so focusing
// without it triggers the browser to scroll the grid container which is undesirable.
textareaRef.current.focus({
preventScroll: true
});
// Move cursor to end of text
const length = textareaRef.current.value.length;
textareaRef.current.setSelectionRange(length, length);
}
}, [hasFocus]);
const handleChange = React.useCallback(async event => {
const newValue = event.target.value;
const column = apiRef.current.getColumn(field);
let parsedValue = newValue;
if (column?.valueParser) {
parsedValue = column.valueParser(newValue, apiRef.current.getRow(id), column, apiRef);
}
setValueState(parsedValue);
apiRef.current.setEditCellValue({
id,
field,
value: parsedValue,
debounceMs,
unstable_skipValueParser: true
}, event);
if (onValueChange) {
await onValueChange(event, newValue);
}
}, [apiRef, debounceMs, field, id, onValueChange, setValueState]);
const handleKeyDown = React.useCallback(event => {
if (event.key === 'Enter' && event.shiftKey) {
// Shift+Enter: let textarea handle newline, stop propagation to prevent grid from exiting edit
event.stopPropagation();
}
if (rootProps.editMode === 'cell' && event.key === 'Escape') {
apiRef.current.stopCellEditMode({
id,
field,
ignoreModifications: true
});
}
}, [apiRef, field, id, rootProps.editMode]);
return /*#__PURE__*/(0, _jsxRuntime.jsx)(GridEditLongTextCellTextarea, (0, _extends2.default)({
ref: textareaRef,
as: rootProps.slots.baseTextarea,
ownerState: rootProps,
"aria-label": colDef.headerName || field,
value: valueState ?? '',
onChange: handleChange,
onKeyDown: handleKeyDown
}, slotProps?.textarea, {
className: (0, _clsx.default)(classes.textarea, slotProps?.textarea?.className)
}));
}
process.env.NODE_ENV !== "production" ? GridEditLongTextarea.propTypes /* remove-proptypes */ = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "pnpm proptypes" |
// ----------------------------------------------------------------------
/**
* GridApi that let you manipulate the grid.
*/
api: _propTypes.default.object.isRequired,
/**
* The mode of the cell.
*/
cellMode: _propTypes.default.oneOf(['edit', 'view']).isRequired,
changeReason: _propTypes.default.oneOf(['debouncedSetEditCellValue', 'setEditCellValue']),
/**
* The column of the row that the current cell belongs to.
*/
colDef: _propTypes.default.object.isRequired,
debounceMs: _propTypes.default.number,
/**
* The column field of the cell that triggered the event.
*/
field: _propTypes.default.string.isRequired,
/**
* The cell value formatted with the column valueFormatter.
*/
formattedValue: _propTypes.default.string,
/**
* If true, the cell is the active element.
*/
hasFocus: _propTypes.default.bool.isRequired,
/**
* The grid row id.
*/
id: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]).isRequired,
/**
* If true, the cell is editable.
*/
isEditable: _propTypes.default.bool,
isProcessingProps: _propTypes.default.bool,
isValidating: _propTypes.default.bool,
/**
* Callback called when the value is changed by the user.
* @param {React.ChangeEvent<HTMLTextAreaElement>} event The event source of the callback.
* @param {string} 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.default.func,
/**
* The row model of the row that the current cell belongs to.
*/
row: _propTypes.default.any.isRequired,
/**
* The node of the row that the current cell belongs to.
*/
rowNode: _propTypes.default.object.isRequired,
/**
* Props passed to internal components.
*/
slotProps: _propTypes.default.object,
/**
* the tabIndex value.
*/
tabIndex: _propTypes.default.oneOf([-1, 0]).isRequired,
/**
* The cell value.
* If the column has `valueGetter`, use `params.row` to directly access the fields.
*/
value: _propTypes.default.string
} : void 0;
const renderEditLongTextCell = params => /*#__PURE__*/(0, _jsxRuntime.jsx)(GridEditLongTextCell, (0, _extends2.default)({}, params));
exports.renderEditLongTextCell = renderEditLongTextCell;
if (process.env.NODE_ENV !== "production") renderEditLongTextCell.displayName = "renderEditLongTextCell";
@@ -0,0 +1,381 @@
'use client';
import _extends from "@babel/runtime/helpers/esm/extends";
import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import composeClasses from '@mui/utils/composeClasses';
import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
import { styled } from '@mui/material/styles';
import { getDataGridUtilityClass } from "../../constants/gridClasses.mjs";
import { useGridRootProps } from "../../hooks/utils/useGridRootProps.mjs";
import { useGridApiContext } from "../../hooks/utils/useGridApiContext.mjs";
import { useGridSelector } from "../../hooks/utils/useGridSelector.mjs";
import { gridRowHeightSelector } from "../../hooks/features/dimensions/gridDimensionsSelectors.mjs";
import { NotRendered } from "../../utils/assert.mjs";
import { vars } from "../../constants/cssVariables.mjs";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
const useUtilityClasses = ownerState => {
const {
classes
} = ownerState;
const slots = {
root: ['editLongTextCell'],
value: ['editLongTextCellValue'],
popup: ['editLongTextCellPopup'],
popperContent: ['editLongTextCellPopperContent'],
textarea: ['editLongTextCellTextarea']
};
return composeClasses(slots, getDataGridUtilityClass, classes);
};
const GridEditLongTextCellTextarea = styled(NotRendered, {
name: 'MuiDataGrid',
slot: 'EditLongTextCellTextarea'
})(({
theme
}) => _extends({
width: '100%',
padding: 0
}, theme.typography.body2, {
letterSpacing: 'normal',
outline: 'none',
background: 'transparent',
border: 'none',
resize: 'vertical'
}));
const GridEditLongTextCellRoot = styled('div', {
name: 'MuiDataGrid',
slot: 'EditLongTextCell'
})({
display: 'flex',
alignItems: 'center',
width: '100%',
height: '100%',
position: 'relative'
});
const GridEditLongTextCellValue = styled('div', {
name: 'MuiDataGrid',
slot: 'EditLongTextCellValue'
})({
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
width: '100%',
paddingInline: 10
});
const GridEditLongTextCellPopper = styled(NotRendered, {
name: 'MuiDataGrid',
slot: 'EditLongTextCellPopper'
})(({
theme
}) => ({
zIndex: vars.zIndex.menu,
background: (theme.vars || theme).palette.background.paper,
'&[data-popper-reference-hidden]': {
opacity: 0 // use opacity to preserve focus.
}
}));
const GridEditLongTextCellPopperContent = styled('div', {
name: 'MuiDataGrid',
slot: 'EditLongTextCellPopperContent'
})(({
theme
}) => _extends({}, theme.typography.body2, {
letterSpacing: 'normal',
paddingBlock: 15.5,
paddingInline: 9,
height: 'max-content',
overflow: 'auto',
whiteSpace: 'pre-wrap',
wordBreak: 'break-word',
width: 'var(--_width)',
border: `1px solid ${(theme.vars || theme).palette.divider}`,
boxShadow: (theme.vars || theme).shadows[4],
boxSizing: 'border-box'
}));
function GridEditLongTextCell(props) {
const {
id,
value,
field,
colDef,
hasFocus,
cellMode,
slotProps
} = props;
const rootProps = useGridRootProps();
const apiRef = useGridApiContext();
const classes = useUtilityClasses(rootProps);
const rowHeight = useGridSelector(apiRef, gridRowHeightSelector);
const [valueState, setValueState] = React.useState(value);
const [anchorEl, setAnchorEl] = React.useState(null);
const meta = apiRef.current.unstable_getEditCellMeta(id, field);
const popupId = `${id}-${field}-longtext-edit-popup`;
// Only show popup when this cell has focus
// This fixes editMode="row" where all cells enter edit mode simultaneously
const showPopup = hasFocus && Boolean(anchorEl);
React.useEffect(() => {
if (meta?.changeReason !== 'debouncedSetEditCellValue') {
setValueState(value);
}
}, [meta, value]);
return /*#__PURE__*/_jsxs(GridEditLongTextCellRoot, _extends({
tabIndex: cellMode === 'edit' && rootProps.editMode === 'row' ? 0 : undefined,
ref: setAnchorEl,
"aria-controls": showPopup ? popupId : undefined,
"aria-expanded": showPopup
}, slotProps?.root, {
className: clsx(classes.root, slotProps?.root?.className),
children: [/*#__PURE__*/_jsx(GridEditLongTextCellValue, _extends({}, slotProps?.value, {
className: clsx(classes.value, slotProps?.value?.className),
children: valueState
})), /*#__PURE__*/_jsx(GridEditLongTextCellPopper, _extends({
as: rootProps.slots.basePopper,
ownerState: rootProps,
id: popupId,
role: "dialog",
"aria-label": colDef.headerName || field,
open: showPopup,
target: anchorEl,
placement: "bottom-start",
flip: true,
material: {
container: anchorEl?.closest('[role="row"]'),
modifiers: [{
name: 'offset',
options: {
offset: [-1, -rowHeight]
}
}]
}
}, slotProps?.popper, {
className: clsx(classes.popup, slotProps?.popper?.className),
children: /*#__PURE__*/_jsx(GridEditLongTextCellPopperContent, _extends({}, slotProps?.popperContent, {
className: clsx(classes.popperContent, slotProps?.popperContent?.className),
style: {
'--_width': `${colDef.computedWidth}px`
},
children: /*#__PURE__*/_jsx(GridEditLongTextarea, _extends({}, props, {
valueState: valueState,
setValueState: setValueState
}))
}))
}))]
}));
}
process.env.NODE_ENV !== "production" ? GridEditLongTextCell.propTypes /* remove-proptypes */ = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "pnpm 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.string,
/**
* 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<HTMLTextAreaElement>} event The event source of the callback.
* @param {string} 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,
/**
* Props passed to internal components.
*/
slotProps: PropTypes.object,
/**
* 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.string
} : void 0;
function GridEditLongTextarea(props) {
const {
id,
field,
colDef,
debounceMs = 200,
onValueChange,
valueState,
setValueState,
hasFocus,
slotProps
} = props;
const textareaRef = React.useRef(null);
const apiRef = useGridApiContext();
const rootProps = useGridRootProps();
const classes = useUtilityClasses(rootProps);
useEnhancedEffect(() => {
if (hasFocus && textareaRef.current) {
// preventScroll: the popper is portaled into the GridRow, so focusing
// without it triggers the browser to scroll the grid container which is undesirable.
textareaRef.current.focus({
preventScroll: true
});
// Move cursor to end of text
const length = textareaRef.current.value.length;
textareaRef.current.setSelectionRange(length, length);
}
}, [hasFocus]);
const handleChange = React.useCallback(async event => {
const newValue = event.target.value;
const column = apiRef.current.getColumn(field);
let parsedValue = newValue;
if (column?.valueParser) {
parsedValue = column.valueParser(newValue, apiRef.current.getRow(id), column, apiRef);
}
setValueState(parsedValue);
apiRef.current.setEditCellValue({
id,
field,
value: parsedValue,
debounceMs,
unstable_skipValueParser: true
}, event);
if (onValueChange) {
await onValueChange(event, newValue);
}
}, [apiRef, debounceMs, field, id, onValueChange, setValueState]);
const handleKeyDown = React.useCallback(event => {
if (event.key === 'Enter' && event.shiftKey) {
// Shift+Enter: let textarea handle newline, stop propagation to prevent grid from exiting edit
event.stopPropagation();
}
if (rootProps.editMode === 'cell' && event.key === 'Escape') {
apiRef.current.stopCellEditMode({
id,
field,
ignoreModifications: true
});
}
}, [apiRef, field, id, rootProps.editMode]);
return /*#__PURE__*/_jsx(GridEditLongTextCellTextarea, _extends({
ref: textareaRef,
as: rootProps.slots.baseTextarea,
ownerState: rootProps,
"aria-label": colDef.headerName || field,
value: valueState ?? '',
onChange: handleChange,
onKeyDown: handleKeyDown
}, slotProps?.textarea, {
className: clsx(classes.textarea, slotProps?.textarea?.className)
}));
}
process.env.NODE_ENV !== "production" ? GridEditLongTextarea.propTypes /* remove-proptypes */ = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "pnpm 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.string,
/**
* 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<HTMLTextAreaElement>} event The event source of the callback.
* @param {string} 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,
/**
* Props passed to internal components.
*/
slotProps: PropTypes.object,
/**
* 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.string
} : void 0;
export { GridEditLongTextCell };
export const renderEditLongTextCell = params => /*#__PURE__*/_jsx(GridEditLongTextCell, _extends({}, params));
if (process.env.NODE_ENV !== "production") renderEditLongTextCell.displayName = "renderEditLongTextCell";
@@ -0,0 +1,22 @@
import * as React from 'react';
import type { GridSlotProps } from "../../models/gridSlotsComponentsProps.mjs";
import type { GridRenderEditCellParams } from "../../models/params/gridCellParams.mjs";
export interface GridEditSingleSelectCellProps extends GridRenderEditCellParams {
/**
* Callback called when the value is changed by the user.
* @param {Event<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?: (event: Parameters<NonNullable<GridSlotProps['baseSelect']['onOpen']>>[0], newValue: any) => Promise<void> | void;
/**
* If true, the select opens by default.
*/
initialOpen?: boolean;
}
declare function GridEditSingleSelectCell(props: GridEditSingleSelectCellProps): React.JSX.Element | null;
declare namespace GridEditSingleSelectCell {
var propTypes: any;
}
export { GridEditSingleSelectCell };
export declare const renderEditSingleSelectCell: (params: GridEditSingleSelectCellProps) => React.JSX.Element;
@@ -0,0 +1,22 @@
import * as React from 'react';
import type { GridSlotProps } from "../../models/gridSlotsComponentsProps.js";
import type { GridRenderEditCellParams } from "../../models/params/gridCellParams.js";
export interface GridEditSingleSelectCellProps extends GridRenderEditCellParams {
/**
* Callback called when the value is changed by the user.
* @param {Event<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?: (event: Parameters<NonNullable<GridSlotProps['baseSelect']['onOpen']>>[0], newValue: any) => Promise<void> | void;
/**
* If true, the select opens by default.
*/
initialOpen?: boolean;
}
declare function GridEditSingleSelectCell(props: GridEditSingleSelectCellProps): React.JSX.Element | null;
declare namespace GridEditSingleSelectCell {
var propTypes: any;
}
export { GridEditSingleSelectCell };
export declare const renderEditSingleSelectCell: (params: GridEditSingleSelectCellProps) => React.JSX.Element;
@@ -0,0 +1,200 @@
"use strict";
'use client';
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.GridEditSingleSelectCell = GridEditSingleSelectCell;
exports.renderEditSingleSelectCell = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var _react = _interopRequireWildcard(require("react"));
var React = _react;
var _propTypes = _interopRequireDefault(require("prop-types"));
var _useEnhancedEffect = _interopRequireDefault(require("@mui/utils/useEnhancedEffect"));
var _gridEditCellParams = require("../../models/params/gridEditCellParams");
var _useGridRootProps = require("../../hooks/utils/useGridRootProps");
var _gridEditRowModel = require("../../models/gridEditRowModel");
var _filterPanelUtils = require("../panel/filterPanel/filterPanelUtils");
var _useGridApiContext = require("../../hooks/utils/useGridApiContext");
var _jsxRuntime = require("react/jsx-runtime");
const _excluded = ["id", "value", "formattedValue", "api", "field", "row", "rowNode", "colDef", "cellMode", "isEditable", "tabIndex", "className", "hasFocus", "isValidating", "isProcessingProps", "error", "onValueChange", "initialOpen", "slotProps"];
function isKeyboardEvent(event) {
return 'key' in event && !!event.key;
}
function GridEditSingleSelectCell(props) {
const rootProps = (0, _useGridRootProps.useGridRootProps)();
const {
id,
value: valueProp,
field,
row,
colDef,
hasFocus,
error,
onValueChange,
initialOpen = rootProps.editMode === _gridEditRowModel.GridEditModes.Cell,
slotProps
} = props,
other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
const apiRef = (0, _useGridApiContext.useGridApiContext)();
const ref = React.useRef(null);
const inputRef = React.useRef(null);
const [open, setOpen] = React.useState(initialOpen);
const baseSelectProps = rootProps.slotProps?.baseSelect || {};
const isSelectNative = baseSelectProps.native ?? false;
(0, _useEnhancedEffect.default)(() => {
if (hasFocus) {
inputRef.current?.focus();
}
}, [hasFocus]);
if (!(0, _filterPanelUtils.isSingleSelectColDef)(colDef)) {
return null;
}
const valueOptions = (0, _filterPanelUtils.getValueOptions)(colDef, {
id,
row
});
if (!valueOptions) {
return null;
}
const getOptionValue = colDef.getOptionValue;
const getOptionLabel = colDef.getOptionLabel;
const handleChange = async event => {
if (!(0, _filterPanelUtils.isSingleSelectColDef)(colDef) || !valueOptions) {
return;
}
setOpen(false);
const target = event.target;
// NativeSelect casts the value to a string.
const formattedTargetValue = (0, _filterPanelUtils.getValueFromValueOptions)(target.value, valueOptions, getOptionValue);
if (onValueChange) {
await onValueChange(event, formattedTargetValue);
}
await apiRef.current.setEditCellValue({
id,
field,
value: formattedTargetValue
}, event);
};
const handleClose = (event, reason) => {
if (rootProps.editMode === _gridEditRowModel.GridEditModes.Row) {
setOpen(false);
return;
}
if (reason === 'backdropClick' || event.key === 'Escape') {
const params = apiRef.current.getCellParams(id, field);
apiRef.current.publishEvent('cellEditStop', (0, _extends2.default)({}, params, {
reason: event.key === 'Escape' ? _gridEditCellParams.GridCellEditStopReasons.escapeKeyDown : _gridEditCellParams.GridCellEditStopReasons.cellFocusOut
}));
}
};
const handleOpen = event => {
if (isKeyboardEvent(event) && event.key === 'Enter') {
return;
}
setOpen(true);
};
if (!valueOptions || !colDef) {
return null;
}
return /*#__PURE__*/(0, _jsxRuntime.jsx)(rootProps.slots.baseSelect, (0, _extends2.default)({
ref: ref,
value: valueProp,
onChange: handleChange,
open: open,
onOpen: handleOpen,
onClose: handleClose,
error: error,
native: isSelectNative,
fullWidth: true,
slotProps: {
htmlInput: {
ref: inputRef
}
}
}, other, slotProps?.root, rootProps.slotProps?.baseSelect, {
children: valueOptions.map(valueOption => {
const value = getOptionValue(valueOption);
return /*#__PURE__*/(0, _react.createElement)(rootProps.slots.baseSelectOption, (0, _extends2.default)({}, rootProps.slotProps?.baseSelectOption || {}, {
native: isSelectNative,
key: value,
value: value
}), getOptionLabel(valueOption));
})
}));
}
process.env.NODE_ENV !== "production" ? GridEditSingleSelectCell.propTypes /* remove-proptypes */ = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "pnpm proptypes" |
// ----------------------------------------------------------------------
/**
* GridApi that let you manipulate the grid.
*/
api: _propTypes.default.object.isRequired,
/**
* The mode of the cell.
*/
cellMode: _propTypes.default.oneOf(['edit', 'view']).isRequired,
changeReason: _propTypes.default.oneOf(['debouncedSetEditCellValue', 'setEditCellValue']),
/**
* The column of the row that the current cell belongs to.
*/
colDef: _propTypes.default.object.isRequired,
/**
* The column field of the cell that triggered the event.
*/
field: _propTypes.default.string.isRequired,
/**
* The cell value formatted with the column valueFormatter.
*/
formattedValue: _propTypes.default.any,
/**
* If true, the cell is the active element.
*/
hasFocus: _propTypes.default.bool.isRequired,
/**
* The grid row id.
*/
id: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]).isRequired,
/**
* If true, the select opens by default.
*/
initialOpen: _propTypes.default.bool,
/**
* If true, the cell is editable.
*/
isEditable: _propTypes.default.bool,
isProcessingProps: _propTypes.default.bool,
isValidating: _propTypes.default.bool,
/**
* Callback called when the value is changed by the user.
* @param {Event<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.default.func,
/**
* The row model of the row that the current cell belongs to.
*/
row: _propTypes.default.any.isRequired,
/**
* The node of the row that the current cell belongs to.
*/
rowNode: _propTypes.default.object.isRequired,
/**
* the tabIndex value.
*/
tabIndex: _propTypes.default.oneOf([-1, 0]).isRequired,
/**
* The cell value.
* If the column has `valueGetter`, use `params.row` to directly access the fields.
*/
value: _propTypes.default.any
} : void 0;
const renderEditSingleSelectCell = params => /*#__PURE__*/(0, _jsxRuntime.jsx)(GridEditSingleSelectCell, (0, _extends2.default)({}, params));
exports.renderEditSingleSelectCell = renderEditSingleSelectCell;
if (process.env.NODE_ENV !== "production") renderEditSingleSelectCell.displayName = "renderEditSingleSelectCell";
@@ -0,0 +1,192 @@
'use client';
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
const _excluded = ["id", "value", "formattedValue", "api", "field", "row", "rowNode", "colDef", "cellMode", "isEditable", "tabIndex", "className", "hasFocus", "isValidating", "isProcessingProps", "error", "onValueChange", "initialOpen", "slotProps"];
import * as React from 'react';
import PropTypes from 'prop-types';
import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
import { GridCellEditStopReasons } from "../../models/params/gridEditCellParams.mjs";
import { useGridRootProps } from "../../hooks/utils/useGridRootProps.mjs";
import { GridEditModes } from "../../models/gridEditRowModel.mjs";
import { getValueFromValueOptions, getValueOptions, isSingleSelectColDef } from "../panel/filterPanel/filterPanelUtils.mjs";
import { useGridApiContext } from "../../hooks/utils/useGridApiContext.mjs";
import { createElement as _createElement } from "react";
import { jsx as _jsx } from "react/jsx-runtime";
function isKeyboardEvent(event) {
return 'key' in event && !!event.key;
}
function GridEditSingleSelectCell(props) {
const rootProps = useGridRootProps();
const {
id,
value: valueProp,
field,
row,
colDef,
hasFocus,
error,
onValueChange,
initialOpen = rootProps.editMode === GridEditModes.Cell,
slotProps
} = props,
other = _objectWithoutPropertiesLoose(props, _excluded);
const apiRef = useGridApiContext();
const ref = React.useRef(null);
const inputRef = React.useRef(null);
const [open, setOpen] = React.useState(initialOpen);
const baseSelectProps = rootProps.slotProps?.baseSelect || {};
const isSelectNative = baseSelectProps.native ?? false;
useEnhancedEffect(() => {
if (hasFocus) {
inputRef.current?.focus();
}
}, [hasFocus]);
if (!isSingleSelectColDef(colDef)) {
return null;
}
const valueOptions = getValueOptions(colDef, {
id,
row
});
if (!valueOptions) {
return null;
}
const getOptionValue = colDef.getOptionValue;
const getOptionLabel = colDef.getOptionLabel;
const handleChange = async event => {
if (!isSingleSelectColDef(colDef) || !valueOptions) {
return;
}
setOpen(false);
const target = event.target;
// NativeSelect casts the value to a string.
const formattedTargetValue = getValueFromValueOptions(target.value, valueOptions, getOptionValue);
if (onValueChange) {
await onValueChange(event, formattedTargetValue);
}
await apiRef.current.setEditCellValue({
id,
field,
value: formattedTargetValue
}, event);
};
const handleClose = (event, reason) => {
if (rootProps.editMode === GridEditModes.Row) {
setOpen(false);
return;
}
if (reason === 'backdropClick' || event.key === 'Escape') {
const params = apiRef.current.getCellParams(id, field);
apiRef.current.publishEvent('cellEditStop', _extends({}, params, {
reason: event.key === 'Escape' ? GridCellEditStopReasons.escapeKeyDown : GridCellEditStopReasons.cellFocusOut
}));
}
};
const 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,
value: valueProp,
onChange: handleChange,
open: open,
onOpen: handleOpen,
onClose: handleClose,
error: error,
native: isSelectNative,
fullWidth: true,
slotProps: {
htmlInput: {
ref: inputRef
}
}
}, other, slotProps?.root, rootProps.slotProps?.baseSelect, {
children: valueOptions.map(valueOption => {
const value = getOptionValue(valueOption);
return /*#__PURE__*/_createElement(rootProps.slots.baseSelectOption, _extends({}, rootProps.slotProps?.baseSelectOption || {}, {
native: isSelectNative,
key: value,
value: value
}), getOptionLabel(valueOption));
})
}));
}
process.env.NODE_ENV !== "production" ? GridEditSingleSelectCell.propTypes /* remove-proptypes */ = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "pnpm 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 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 {Event<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 const renderEditSingleSelectCell = params => /*#__PURE__*/_jsx(GridEditSingleSelectCell, _extends({}, params));
if (process.env.NODE_ENV !== "production") renderEditSingleSelectCell.displayName = "renderEditSingleSelectCell";
@@ -0,0 +1,9 @@
import * as React from 'react';
import type { SxProps, Theme } from '@mui/material/styles';
import type { GridRenderCellParams } from "../../models/params/gridCellParams.mjs";
interface GridFooterCellProps extends GridRenderCellParams {
sx?: SxProps<Theme>;
}
declare function GridFooterCellRaw(props: GridFooterCellProps): React.JSX.Element;
declare const GridFooterCell: React.MemoExoticComponent<typeof GridFooterCellRaw>;
export { GridFooterCell };
@@ -0,0 +1,9 @@
import * as React from 'react';
import type { SxProps, Theme } from '@mui/material/styles';
import type { GridRenderCellParams } from "../../models/params/gridCellParams.js";
interface GridFooterCellProps extends GridRenderCellParams {
sx?: SxProps<Theme>;
}
declare function GridFooterCellRaw(props: GridFooterCellProps): React.JSX.Element;
declare const GridFooterCell: React.MemoExoticComponent<typeof GridFooterCellRaw>;
export { GridFooterCell };
@@ -0,0 +1,54 @@
"use strict";
'use client';
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.GridFooterCell = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var React = _interopRequireWildcard(require("react"));
var _composeClasses = _interopRequireDefault(require("@mui/utils/composeClasses"));
var _styles = require("@mui/material/styles");
var _cssVariables = require("../../constants/cssVariables");
var _useGridRootProps = require("../../hooks/utils/useGridRootProps");
var _gridClasses = require("../../constants/gridClasses");
var _jsxRuntime = require("react/jsx-runtime");
const _excluded = ["formattedValue", "colDef", "cellMode", "row", "api", "id", "value", "rowNode", "field", "hasFocus", "tabIndex", "isEditable"];
const GridFooterCellRoot = (0, _styles.styled)('div', {
name: 'MuiDataGrid',
slot: 'FooterCell'
})({
fontWeight: _cssVariables.vars.typography.fontWeight.medium,
color: _cssVariables.vars.colors.foreground.accent
});
const useUtilityClasses = ownerState => {
const {
classes
} = ownerState;
const slots = {
root: ['footerCell']
};
return (0, _composeClasses.default)(slots, _gridClasses.getDataGridUtilityClass, classes);
};
function GridFooterCellRaw(props) {
const {
formattedValue
} = props,
other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
const rootProps = (0, _useGridRootProps.useGridRootProps)();
const ownerState = {
classes: rootProps.classes
};
const classes = useUtilityClasses(ownerState);
return /*#__PURE__*/(0, _jsxRuntime.jsx)(GridFooterCellRoot, (0, _extends2.default)({
ownerState: ownerState,
className: classes.root
}, other, {
children: formattedValue
}));
}
const GridFooterCell = exports.GridFooterCell = /*#__PURE__*/React.memo(GridFooterCellRaw);
if (process.env.NODE_ENV !== "production") GridFooterCell.displayName = "GridFooterCell";
@@ -0,0 +1,48 @@
'use client';
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
const _excluded = ["formattedValue", "colDef", "cellMode", "row", "api", "id", "value", "rowNode", "field", "hasFocus", "tabIndex", "isEditable"];
import * as React from 'react';
import composeClasses from '@mui/utils/composeClasses';
import { styled } from '@mui/material/styles';
import { vars } from "../../constants/cssVariables.mjs";
import { useGridRootProps } from "../../hooks/utils/useGridRootProps.mjs";
import { getDataGridUtilityClass } from "../../constants/gridClasses.mjs";
import { jsx as _jsx } from "react/jsx-runtime";
const GridFooterCellRoot = styled('div', {
name: 'MuiDataGrid',
slot: 'FooterCell'
})({
fontWeight: vars.typography.fontWeight.medium,
color: vars.colors.foreground.accent
});
const useUtilityClasses = ownerState => {
const {
classes
} = ownerState;
const slots = {
root: ['footerCell']
};
return composeClasses(slots, getDataGridUtilityClass, classes);
};
function GridFooterCellRaw(props) {
const {
formattedValue
} = props,
other = _objectWithoutPropertiesLoose(props, _excluded);
const rootProps = useGridRootProps();
const ownerState = {
classes: rootProps.classes
};
const classes = useUtilityClasses(ownerState);
return /*#__PURE__*/_jsx(GridFooterCellRoot, _extends({
ownerState: ownerState,
className: classes.root
}, other, {
children: formattedValue
}));
}
const GridFooterCell = /*#__PURE__*/React.memo(GridFooterCellRaw);
if (process.env.NODE_ENV !== "production") GridFooterCell.displayName = "GridFooterCell";
export { GridFooterCell };
@@ -0,0 +1,46 @@
import * as React from 'react';
import type { GridRenderCellParams } from "../../models/params/gridCellParams.mjs";
import type { GridSlotProps } from "../../models/gridSlotsComponent.mjs";
export interface GridLongTextCellProps extends GridRenderCellParams<any, string | null> {
/**
* A function to customize the content rendered in the popup.
* @param {string | null} value The cell value.
* @returns {React.ReactNode} The content to render in the popup.
*/
renderContent?: (value: string | null) => React.ReactNode;
/**
* Props passed to internal components.
*/
slotProps?: {
/**
* Props passed to the root element.
*/
root?: React.HTMLAttributes<HTMLDivElement>;
/**
* Props passed to the content element.
*/
content?: React.HTMLAttributes<HTMLDivElement>;
/**
* Props passed to the expand button element.
*/
expandButton?: React.ButtonHTMLAttributes<HTMLButtonElement>;
/**
* Props passed to the collapse button element.
*/
collapseButton?: React.ButtonHTMLAttributes<HTMLButtonElement>;
/**
* Props passed to the popper element.
*/
popper?: Partial<GridSlotProps['basePopper']>;
/**
* Props passed to the popper content element.
*/
popperContent?: React.HTMLAttributes<HTMLDivElement>;
};
}
declare function GridLongTextCell(props: GridLongTextCellProps): React.JSX.Element;
declare namespace GridLongTextCell {
var propTypes: any;
}
export { GridLongTextCell };
export declare const renderLongTextCell: (params: GridLongTextCellProps) => React.JSX.Element;
@@ -0,0 +1,46 @@
import * as React from 'react';
import type { GridRenderCellParams } from "../../models/params/gridCellParams.js";
import type { GridSlotProps } from "../../models/gridSlotsComponent.js";
export interface GridLongTextCellProps extends GridRenderCellParams<any, string | null> {
/**
* A function to customize the content rendered in the popup.
* @param {string | null} value The cell value.
* @returns {React.ReactNode} The content to render in the popup.
*/
renderContent?: (value: string | null) => React.ReactNode;
/**
* Props passed to internal components.
*/
slotProps?: {
/**
* Props passed to the root element.
*/
root?: React.HTMLAttributes<HTMLDivElement>;
/**
* Props passed to the content element.
*/
content?: React.HTMLAttributes<HTMLDivElement>;
/**
* Props passed to the expand button element.
*/
expandButton?: React.ButtonHTMLAttributes<HTMLButtonElement>;
/**
* Props passed to the collapse button element.
*/
collapseButton?: React.ButtonHTMLAttributes<HTMLButtonElement>;
/**
* Props passed to the popper element.
*/
popper?: Partial<GridSlotProps['basePopper']>;
/**
* Props passed to the popper content element.
*/
popperContent?: React.HTMLAttributes<HTMLDivElement>;
};
}
declare function GridLongTextCell(props: GridLongTextCellProps): React.JSX.Element;
declare namespace GridLongTextCell {
var propTypes: any;
}
export { GridLongTextCell };
export declare const renderLongTextCell: (params: GridLongTextCellProps) => React.JSX.Element;
@@ -0,0 +1,322 @@
"use strict";
'use client';
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.GridLongTextCell = GridLongTextCell;
exports.renderLongTextCell = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var React = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _clsx = _interopRequireDefault(require("clsx"));
var _composeClasses = _interopRequireDefault(require("@mui/utils/composeClasses"));
var _styles = require("@mui/material/styles");
var _gridClasses = require("../../constants/gridClasses");
var _useGridRootProps = require("../../hooks/utils/useGridRootProps");
var _useGridApiContext = require("../../hooks/utils/useGridApiContext");
var _useGridSelector = require("../../hooks/utils/useGridSelector");
var _gridDimensionsSelectors = require("../../hooks/features/dimensions/gridDimensionsSelectors");
var _assert = require("../../utils/assert");
var _cssVariables = require("../../constants/cssVariables");
var _jsxRuntime = require("react/jsx-runtime");
const useUtilityClasses = ownerState => {
const {
classes
} = ownerState;
const slots = {
root: ['longTextCell'],
content: ['longTextCellContent'],
expandButton: ['longTextCellExpandButton'],
collapseButton: ['longTextCellCollapseButton'],
popup: ['longTextCellPopup'],
popperContent: ['longTextCellPopperContent']
};
return (0, _composeClasses.default)(slots, _gridClasses.getDataGridUtilityClass, classes);
};
const GridLongTextCellRoot = (0, _styles.styled)('div', {
name: 'MuiDataGrid',
slot: 'LongTextCell'
})({
display: 'flex',
alignItems: 'center',
width: '100%',
height: '100%',
position: 'relative'
});
const GridLongTextCellContent = (0, _styles.styled)('div', {
name: 'MuiDataGrid',
slot: 'LongTextCellContent'
})({
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
flex: 1
});
const GridLongTextCellPopperContent = (0, _styles.styled)('div', {
name: 'MuiDataGrid',
slot: 'LongTextCellPopperContent'
})(({
theme
}) => (0, _extends2.default)({}, theme.typography.body2, {
letterSpacing: 'normal',
paddingBlock: 15.5,
paddingInline: 9,
maxHeight: 52 * 3,
overflow: 'auto',
whiteSpace: 'pre-wrap',
wordBreak: 'break-word',
width: 'var(--_width)',
border: `1px solid ${(theme.vars || theme).palette.divider}`,
boxSizing: 'border-box'
}));
const GridLongTextCellCornerButton = (0, _styles.styled)('button', {
name: 'MuiDataGrid',
slot: 'LongTextCellCornerButton'
})(({
theme
}) => ({
lineHeight: 0,
position: 'absolute',
bottom: 1,
right: 0,
border: '1px solid',
color: (theme.vars || theme).palette.text.secondary,
borderColor: (theme.vars || theme).palette.divider,
backgroundColor: (theme.vars || theme).palette.background.paper,
borderRadius: 0,
fontSize: '0.875rem',
padding: 2,
'&:focus-visible': {
outline: 'none'
},
'&:hover': {
backgroundColor: (theme.vars || theme).palette.background.paper,
color: (theme.vars || theme).palette.text.primary
},
[`&.${_gridClasses.gridClasses.longTextCellExpandButton}`]: {
right: -9,
opacity: 0,
[`.${_gridClasses.gridClasses.longTextCell}:hover &, .${_gridClasses.gridClasses.longTextCell}.Mui-focused &`]: {
opacity: 1
}
},
[`&.${_gridClasses.gridClasses.longTextCellCollapseButton}`]: {
bottom: 2,
right: 2,
border: 'none'
}
}));
const GridLongTextCellPopper = (0, _styles.styled)(_assert.NotRendered, {
name: 'MuiDataGrid',
slot: 'LongTextCellPopper'
})(({
theme
}) => ({
zIndex: _cssVariables.vars.zIndex.menu,
background: (theme.vars || theme).palette.background.paper,
'&[data-popper-reference-hidden]': {
visibility: 'hidden',
pointerEvents: 'none'
}
}));
function GridLongTextCell(props) {
const {
id,
value = '',
colDef,
hasFocus,
slotProps,
renderContent
} = props;
const popupId = `${id}-${colDef.field}-longtext-popup`;
const rootProps = (0, _useGridRootProps.useGridRootProps)();
const apiRef = (0, _useGridApiContext.useGridApiContext)();
const classes = useUtilityClasses(rootProps);
const rowHeight = (0, _useGridSelector.useGridSelector)(apiRef, _gridDimensionsSelectors.gridRowHeightSelector);
const [popupOpen, setPopupOpen] = React.useState(false);
const cellRef = React.useRef(null);
const cornerButtonRef = React.useRef(null);
React.useEffect(() => {
if (hasFocus && !popupOpen) {
if (cornerButtonRef.current && cornerButtonRef.current !== document.activeElement) {
cornerButtonRef.current.focus();
}
}
if (!hasFocus) {
setPopupOpen(false);
}
}, [hasFocus, popupOpen]);
const handleExpandClick = event => {
// event.detail === 0 means keyboard-triggered click (Enter keyup on focused button)
// Ignore these to prevent popup from opening when focus moves to this cell via Enter
if (event.detail === 0) {
return;
}
event.stopPropagation();
setPopupOpen(true);
};
const handleExpandKeyDown = event => {
if (event.key === ' ' && !event.shiftKey) {
event.preventDefault(); // Prevent native button click on keyup
event.stopPropagation(); // Prevent grid row selection
setPopupOpen(prev => !prev);
}
if (event.key === 'Escape' && popupOpen) {
event.stopPropagation(); // Prevent grid cell navigation
setPopupOpen(false);
}
};
const handleClickAway = () => {
setPopupOpen(false);
};
const handleCollapseClick = event => {
event.stopPropagation();
setPopupOpen(false);
apiRef.current.getCellElement(id, colDef.field)?.focus();
};
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(GridLongTextCellRoot, (0, _extends2.default)({
ref: cellRef
}, slotProps?.root, {
className: (0, _clsx.default)(classes.root, slotProps?.root?.className, hasFocus && 'Mui-focused'),
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(GridLongTextCellContent, (0, _extends2.default)({}, slotProps?.content, {
className: (0, _clsx.default)(classes.content, slotProps?.content?.className),
children: value
})), /*#__PURE__*/(0, _jsxRuntime.jsx)(GridLongTextCellCornerButton, (0, _extends2.default)({
ref: cornerButtonRef,
type: "button",
"aria-label": `${value}, ${apiRef.current.getLocaleText('longTextCellExpandLabel')}`,
"aria-haspopup": "dialog",
"aria-controls": popupOpen ? popupId : undefined,
"aria-expanded": popupOpen,
"aria-keyshortcuts": "Space",
tabIndex: 0
}, slotProps?.expandButton, {
className: (0, _clsx.default)(classes.expandButton, slotProps?.expandButton?.className),
onClick: handleExpandClick,
onKeyDown: handleExpandKeyDown,
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(rootProps.slots.longTextCellExpandIcon, {
fontSize: "inherit"
})
})), /*#__PURE__*/(0, _jsxRuntime.jsx)(GridLongTextCellPopper, (0, _extends2.default)({
id: popupId,
role: "dialog",
"aria-label": colDef.headerName || colDef.field,
as: rootProps.slots.basePopper,
ownerState: rootProps,
open: popupOpen,
target: cellRef.current,
placement: "bottom-start",
onClickAway: handleClickAway,
clickAwayMouseEvent: "onMouseDown",
flip: true,
material: {
container: cellRef.current?.closest('[role="row"]'),
modifiers: [{
name: 'offset',
options: {
offset: [-10, -rowHeight]
}
}]
}
}, slotProps?.popper, {
className: (0, _clsx.default)(classes.popup, slotProps?.popper?.className),
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(GridLongTextCellPopperContent, (0, _extends2.default)({
tabIndex: -1,
onKeyDown: event => {
if (event.key === 'Escape') {
event.stopPropagation();
setPopupOpen(false);
apiRef.current.getCellElement(id, colDef.field)?.focus();
}
}
}, slotProps?.popperContent, {
className: (0, _clsx.default)(classes.popperContent, slotProps?.popperContent?.className),
style: (0, _extends2.default)({
'--_width': `${colDef.computedWidth}px`
}, slotProps?.popperContent?.style),
children: [renderContent ? renderContent(value) : value, /*#__PURE__*/(0, _jsxRuntime.jsx)(GridLongTextCellCornerButton, (0, _extends2.default)({
type: "button",
"aria-label": apiRef.current.getLocaleText('longTextCellCollapseLabel'),
"aria-keyshortcuts": "Escape"
}, slotProps?.collapseButton, {
className: (0, _clsx.default)(classes.collapseButton, slotProps?.collapseButton?.className),
onClick: handleCollapseClick,
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(rootProps.slots.longTextCellCollapseIcon, {
fontSize: "inherit"
})
}))]
}))
}))]
}));
}
process.env.NODE_ENV !== "production" ? GridLongTextCell.propTypes /* remove-proptypes */ = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "pnpm proptypes" |
// ----------------------------------------------------------------------
/**
* GridApi that let you manipulate the grid.
*/
api: _propTypes.default.object.isRequired,
/**
* The mode of the cell.
*/
cellMode: _propTypes.default.oneOf(['edit', 'view']).isRequired,
/**
* The column of the row that the current cell belongs to.
*/
colDef: _propTypes.default.object.isRequired,
/**
* The column field of the cell that triggered the event.
*/
field: _propTypes.default.string.isRequired,
/**
* The cell value formatted with the column valueFormatter.
*/
formattedValue: _propTypes.default.string,
/**
* If true, the cell is the active element.
*/
hasFocus: _propTypes.default.bool.isRequired,
/**
* The grid row id.
*/
id: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]).isRequired,
/**
* If true, the cell is editable.
*/
isEditable: _propTypes.default.bool,
/**
* A function to customize the content rendered in the popup.
* @param {string | null} value The cell value.
* @returns {React.ReactNode} The content to render in the popup.
*/
renderContent: _propTypes.default.func,
/**
* The row model of the row that the current cell belongs to.
*/
row: _propTypes.default.any.isRequired,
/**
* The node of the row that the current cell belongs to.
*/
rowNode: _propTypes.default.object.isRequired,
/**
* Props passed to internal components.
*/
slotProps: _propTypes.default.object,
/**
* the tabIndex value.
*/
tabIndex: _propTypes.default.oneOf([-1, 0]).isRequired,
/**
* The cell value.
* If the column has `valueGetter`, use `params.row` to directly access the fields.
*/
value: _propTypes.default.string
} : void 0;
const renderLongTextCell = params => /*#__PURE__*/(0, _jsxRuntime.jsx)(GridLongTextCell, (0, _extends2.default)({}, params));
exports.renderLongTextCell = renderLongTextCell;
if (process.env.NODE_ENV !== "production") renderLongTextCell.displayName = "renderLongTextCell";
@@ -0,0 +1,314 @@
'use client';
import _extends from "@babel/runtime/helpers/esm/extends";
import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import composeClasses from '@mui/utils/composeClasses';
import { styled } from '@mui/material/styles';
import { getDataGridUtilityClass, gridClasses } from "../../constants/gridClasses.mjs";
import { useGridRootProps } from "../../hooks/utils/useGridRootProps.mjs";
import { useGridApiContext } from "../../hooks/utils/useGridApiContext.mjs";
import { useGridSelector } from "../../hooks/utils/useGridSelector.mjs";
import { gridRowHeightSelector } from "../../hooks/features/dimensions/gridDimensionsSelectors.mjs";
import { NotRendered } from "../../utils/assert.mjs";
import { vars } from "../../constants/cssVariables.mjs";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
const useUtilityClasses = ownerState => {
const {
classes
} = ownerState;
const slots = {
root: ['longTextCell'],
content: ['longTextCellContent'],
expandButton: ['longTextCellExpandButton'],
collapseButton: ['longTextCellCollapseButton'],
popup: ['longTextCellPopup'],
popperContent: ['longTextCellPopperContent']
};
return composeClasses(slots, getDataGridUtilityClass, classes);
};
const GridLongTextCellRoot = styled('div', {
name: 'MuiDataGrid',
slot: 'LongTextCell'
})({
display: 'flex',
alignItems: 'center',
width: '100%',
height: '100%',
position: 'relative'
});
const GridLongTextCellContent = styled('div', {
name: 'MuiDataGrid',
slot: 'LongTextCellContent'
})({
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
flex: 1
});
const GridLongTextCellPopperContent = styled('div', {
name: 'MuiDataGrid',
slot: 'LongTextCellPopperContent'
})(({
theme
}) => _extends({}, theme.typography.body2, {
letterSpacing: 'normal',
paddingBlock: 15.5,
paddingInline: 9,
maxHeight: 52 * 3,
overflow: 'auto',
whiteSpace: 'pre-wrap',
wordBreak: 'break-word',
width: 'var(--_width)',
border: `1px solid ${(theme.vars || theme).palette.divider}`,
boxSizing: 'border-box'
}));
const GridLongTextCellCornerButton = styled('button', {
name: 'MuiDataGrid',
slot: 'LongTextCellCornerButton'
})(({
theme
}) => ({
lineHeight: 0,
position: 'absolute',
bottom: 1,
right: 0,
border: '1px solid',
color: (theme.vars || theme).palette.text.secondary,
borderColor: (theme.vars || theme).palette.divider,
backgroundColor: (theme.vars || theme).palette.background.paper,
borderRadius: 0,
fontSize: '0.875rem',
padding: 2,
'&:focus-visible': {
outline: 'none'
},
'&:hover': {
backgroundColor: (theme.vars || theme).palette.background.paper,
color: (theme.vars || theme).palette.text.primary
},
[`&.${gridClasses.longTextCellExpandButton}`]: {
right: -9,
opacity: 0,
[`.${gridClasses.longTextCell}:hover &, .${gridClasses.longTextCell}.Mui-focused &`]: {
opacity: 1
}
},
[`&.${gridClasses.longTextCellCollapseButton}`]: {
bottom: 2,
right: 2,
border: 'none'
}
}));
const GridLongTextCellPopper = styled(NotRendered, {
name: 'MuiDataGrid',
slot: 'LongTextCellPopper'
})(({
theme
}) => ({
zIndex: vars.zIndex.menu,
background: (theme.vars || theme).palette.background.paper,
'&[data-popper-reference-hidden]': {
visibility: 'hidden',
pointerEvents: 'none'
}
}));
function GridLongTextCell(props) {
const {
id,
value = '',
colDef,
hasFocus,
slotProps,
renderContent
} = props;
const popupId = `${id}-${colDef.field}-longtext-popup`;
const rootProps = useGridRootProps();
const apiRef = useGridApiContext();
const classes = useUtilityClasses(rootProps);
const rowHeight = useGridSelector(apiRef, gridRowHeightSelector);
const [popupOpen, setPopupOpen] = React.useState(false);
const cellRef = React.useRef(null);
const cornerButtonRef = React.useRef(null);
React.useEffect(() => {
if (hasFocus && !popupOpen) {
if (cornerButtonRef.current && cornerButtonRef.current !== document.activeElement) {
cornerButtonRef.current.focus();
}
}
if (!hasFocus) {
setPopupOpen(false);
}
}, [hasFocus, popupOpen]);
const handleExpandClick = event => {
// event.detail === 0 means keyboard-triggered click (Enter keyup on focused button)
// Ignore these to prevent popup from opening when focus moves to this cell via Enter
if (event.detail === 0) {
return;
}
event.stopPropagation();
setPopupOpen(true);
};
const handleExpandKeyDown = event => {
if (event.key === ' ' && !event.shiftKey) {
event.preventDefault(); // Prevent native button click on keyup
event.stopPropagation(); // Prevent grid row selection
setPopupOpen(prev => !prev);
}
if (event.key === 'Escape' && popupOpen) {
event.stopPropagation(); // Prevent grid cell navigation
setPopupOpen(false);
}
};
const handleClickAway = () => {
setPopupOpen(false);
};
const handleCollapseClick = event => {
event.stopPropagation();
setPopupOpen(false);
apiRef.current.getCellElement(id, colDef.field)?.focus();
};
return /*#__PURE__*/_jsxs(GridLongTextCellRoot, _extends({
ref: cellRef
}, slotProps?.root, {
className: clsx(classes.root, slotProps?.root?.className, hasFocus && 'Mui-focused'),
children: [/*#__PURE__*/_jsx(GridLongTextCellContent, _extends({}, slotProps?.content, {
className: clsx(classes.content, slotProps?.content?.className),
children: value
})), /*#__PURE__*/_jsx(GridLongTextCellCornerButton, _extends({
ref: cornerButtonRef,
type: "button",
"aria-label": `${value}, ${apiRef.current.getLocaleText('longTextCellExpandLabel')}`,
"aria-haspopup": "dialog",
"aria-controls": popupOpen ? popupId : undefined,
"aria-expanded": popupOpen,
"aria-keyshortcuts": "Space",
tabIndex: 0
}, slotProps?.expandButton, {
className: clsx(classes.expandButton, slotProps?.expandButton?.className),
onClick: handleExpandClick,
onKeyDown: handleExpandKeyDown,
children: /*#__PURE__*/_jsx(rootProps.slots.longTextCellExpandIcon, {
fontSize: "inherit"
})
})), /*#__PURE__*/_jsx(GridLongTextCellPopper, _extends({
id: popupId,
role: "dialog",
"aria-label": colDef.headerName || colDef.field,
as: rootProps.slots.basePopper,
ownerState: rootProps,
open: popupOpen,
target: cellRef.current,
placement: "bottom-start",
onClickAway: handleClickAway,
clickAwayMouseEvent: "onMouseDown",
flip: true,
material: {
container: cellRef.current?.closest('[role="row"]'),
modifiers: [{
name: 'offset',
options: {
offset: [-10, -rowHeight]
}
}]
}
}, slotProps?.popper, {
className: clsx(classes.popup, slotProps?.popper?.className),
children: /*#__PURE__*/_jsxs(GridLongTextCellPopperContent, _extends({
tabIndex: -1,
onKeyDown: event => {
if (event.key === 'Escape') {
event.stopPropagation();
setPopupOpen(false);
apiRef.current.getCellElement(id, colDef.field)?.focus();
}
}
}, slotProps?.popperContent, {
className: clsx(classes.popperContent, slotProps?.popperContent?.className),
style: _extends({
'--_width': `${colDef.computedWidth}px`
}, slotProps?.popperContent?.style),
children: [renderContent ? renderContent(value) : value, /*#__PURE__*/_jsx(GridLongTextCellCornerButton, _extends({
type: "button",
"aria-label": apiRef.current.getLocaleText('longTextCellCollapseLabel'),
"aria-keyshortcuts": "Escape"
}, slotProps?.collapseButton, {
className: clsx(classes.collapseButton, slotProps?.collapseButton?.className),
onClick: handleCollapseClick,
children: /*#__PURE__*/_jsx(rootProps.slots.longTextCellCollapseIcon, {
fontSize: "inherit"
})
}))]
}))
}))]
}));
}
process.env.NODE_ENV !== "production" ? GridLongTextCell.propTypes /* remove-proptypes */ = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "pnpm 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,
/**
* The cell value formatted with the column valueFormatter.
*/
formattedValue: PropTypes.string,
/**
* 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,
/**
* A function to customize the content rendered in the popup.
* @param {string | null} value The cell value.
* @returns {React.ReactNode} The content to render in the popup.
*/
renderContent: 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,
/**
* Props passed to internal components.
*/
slotProps: PropTypes.object,
/**
* 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.string
} : void 0;
export { GridLongTextCell };
export const renderLongTextCell = params => /*#__PURE__*/_jsx(GridLongTextCell, _extends({}, params));
if (process.env.NODE_ENV !== "production") renderLongTextCell.displayName = "renderLongTextCell";
@@ -0,0 +1,18 @@
import * as React from 'react';
import type { GridColType, GridSlotProps } from "../../models/index.mjs";
export interface GridSkeletonCellProps extends React.HTMLAttributes<HTMLDivElement> {
type?: GridColType;
width?: number | string;
height?: number | 'auto';
field?: string;
align?: string;
/**
* If `true`, the cell will not display the skeleton but still reserve the cell space.
* @default false
*/
empty?: boolean;
skeletonProps?: GridSlotProps['baseSkeleton'];
}
declare function GridSkeletonCell(props: GridSkeletonCellProps): React.JSX.Element;
declare const Memoized: typeof GridSkeletonCell;
export { Memoized as GridSkeletonCell };
@@ -0,0 +1,18 @@
import * as React from 'react';
import type { GridColType, GridSlotProps } from "../../models/index.js";
export interface GridSkeletonCellProps extends React.HTMLAttributes<HTMLDivElement> {
type?: GridColType;
width?: number | string;
height?: number | 'auto';
field?: string;
align?: string;
/**
* If `true`, the cell will not display the skeleton but still reserve the cell space.
* @default false
*/
empty?: boolean;
skeletonProps?: GridSlotProps['baseSkeleton'];
}
declare function GridSkeletonCell(props: GridSkeletonCellProps): React.JSX.Element;
declare const Memoized: typeof GridSkeletonCell;
export { Memoized as GridSkeletonCell };
@@ -0,0 +1,118 @@
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.GridSkeletonCell = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var React = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _clsx = _interopRequireDefault(require("clsx"));
var _composeClasses = _interopRequireDefault(require("@mui/utils/composeClasses"));
var _capitalize = _interopRequireDefault(require("@mui/utils/capitalize"));
var _fastMemo = require("@mui/x-internals/fastMemo");
var _utils = require("../../utils/utils");
var _useGridRootProps = require("../../hooks/utils/useGridRootProps");
var _gridClasses = require("../../constants/gridClasses");
var _jsxRuntime = require("react/jsx-runtime");
const _excluded = ["field", "type", "align", "width", "height", "empty", "style", "className", "skeletonProps"];
const CIRCULAR_CONTENT_SIZE = '1.3em';
const CONTENT_HEIGHT = '1.2em';
const DEFAULT_CONTENT_WIDTH_RANGE = [40, 80];
const CONTENT_WIDTH_RANGE_BY_TYPE = {
number: [40, 60],
string: [40, 80],
date: [40, 60],
dateTime: [60, 80],
singleSelect: [40, 80]
};
const useUtilityClasses = ownerState => {
const {
align,
classes,
empty
} = ownerState;
const slots = {
root: ['cell', 'cellSkeleton', `cell--text${align ? (0, _capitalize.default)(align) : 'Left'}`, empty && 'cellEmpty']
};
return (0, _composeClasses.default)(slots, _gridClasses.getDataGridUtilityClass, classes);
};
const randomNumberGenerator = (0, _utils.createRandomNumberGenerator)(12345);
function GridSkeletonCell(props) {
const {
field,
type,
align,
width,
height,
empty = false,
style,
className,
skeletonProps: skeletonPropsOverride
} = props,
other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
const rootProps = (0, _useGridRootProps.useGridRootProps)();
const ownerState = {
classes: rootProps.classes,
align,
empty
};
const classes = useUtilityClasses(ownerState);
// Memo prevents the non-circular skeleton widths changing to random widths on every render
const baseSkeletonProps = React.useMemo(() => {
const isCircularContent = type === 'boolean' || type === 'actions';
if (isCircularContent) {
return {
variant: 'circular',
width: CIRCULAR_CONTENT_SIZE,
height: CIRCULAR_CONTENT_SIZE
};
}
// The width of the skeleton is a random number between the min and max values
// The min and max values are determined by the type of the column
const [min, max] = type ? CONTENT_WIDTH_RANGE_BY_TYPE[type] ?? DEFAULT_CONTENT_WIDTH_RANGE : DEFAULT_CONTENT_WIDTH_RANGE;
return {
variant: 'text',
width: `${Math.round(randomNumberGenerator(min, max))}%`,
height: CONTENT_HEIGHT
};
}, [type]);
// Merge caller overrides outside the memo so an inline `skeletonProps` object
// doesn't bust the memo and re-roll the random width on every render
const skeletonProps = skeletonPropsOverride && Object.keys(skeletonPropsOverride).length > 0 ? (0, _extends2.default)({}, baseSkeletonProps, skeletonPropsOverride) : baseSkeletonProps;
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", (0, _extends2.default)({
"data-field": field,
className: (0, _clsx.default)(classes.root, className),
style: (0, _extends2.default)({
height,
maxWidth: width,
minWidth: width
}, style)
}, other, {
children: !empty && /*#__PURE__*/(0, _jsxRuntime.jsx)(rootProps.slots.baseSkeleton, (0, _extends2.default)({}, skeletonProps))
}));
}
process.env.NODE_ENV !== "production" ? GridSkeletonCell.propTypes /* remove-proptypes */ = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "pnpm proptypes" |
// ----------------------------------------------------------------------
align: _propTypes.default.string,
/**
* If `true`, the cell will not display the skeleton but still reserve the cell space.
* @default false
*/
empty: _propTypes.default.bool,
field: _propTypes.default.string,
height: _propTypes.default.oneOfType([_propTypes.default.oneOf(['auto']), _propTypes.default.number]),
skeletonProps: _propTypes.default.object,
type: _propTypes.default.oneOf(['actions', 'boolean', 'custom', 'date', 'dateTime', 'longText', 'multiSelect', 'number', 'singleSelect', 'string']),
width: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string])
} : void 0;
const Memoized = exports.GridSkeletonCell = (0, _fastMemo.fastMemo)(GridSkeletonCell);
@@ -0,0 +1,111 @@
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
const _excluded = ["field", "type", "align", "width", "height", "empty", "style", "className", "skeletonProps"];
import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import composeClasses from '@mui/utils/composeClasses';
import capitalize from '@mui/utils/capitalize';
import { fastMemo } from '@mui/x-internals/fastMemo';
import { createRandomNumberGenerator } from "../../utils/utils.mjs";
import { useGridRootProps } from "../../hooks/utils/useGridRootProps.mjs";
import { getDataGridUtilityClass } from "../../constants/gridClasses.mjs";
import { jsx as _jsx } from "react/jsx-runtime";
const CIRCULAR_CONTENT_SIZE = '1.3em';
const CONTENT_HEIGHT = '1.2em';
const DEFAULT_CONTENT_WIDTH_RANGE = [40, 80];
const CONTENT_WIDTH_RANGE_BY_TYPE = {
number: [40, 60],
string: [40, 80],
date: [40, 60],
dateTime: [60, 80],
singleSelect: [40, 80]
};
const useUtilityClasses = ownerState => {
const {
align,
classes,
empty
} = ownerState;
const slots = {
root: ['cell', 'cellSkeleton', `cell--text${align ? capitalize(align) : 'Left'}`, empty && 'cellEmpty']
};
return composeClasses(slots, getDataGridUtilityClass, classes);
};
const randomNumberGenerator = createRandomNumberGenerator(12345);
function GridSkeletonCell(props) {
const {
field,
type,
align,
width,
height,
empty = false,
style,
className,
skeletonProps: skeletonPropsOverride
} = props,
other = _objectWithoutPropertiesLoose(props, _excluded);
const rootProps = useGridRootProps();
const ownerState = {
classes: rootProps.classes,
align,
empty
};
const classes = useUtilityClasses(ownerState);
// Memo prevents the non-circular skeleton widths changing to random widths on every render
const baseSkeletonProps = React.useMemo(() => {
const isCircularContent = type === 'boolean' || type === 'actions';
if (isCircularContent) {
return {
variant: 'circular',
width: CIRCULAR_CONTENT_SIZE,
height: CIRCULAR_CONTENT_SIZE
};
}
// The width of the skeleton is a random number between the min and max values
// The min and max values are determined by the type of the column
const [min, max] = type ? CONTENT_WIDTH_RANGE_BY_TYPE[type] ?? DEFAULT_CONTENT_WIDTH_RANGE : DEFAULT_CONTENT_WIDTH_RANGE;
return {
variant: 'text',
width: `${Math.round(randomNumberGenerator(min, max))}%`,
height: CONTENT_HEIGHT
};
}, [type]);
// Merge caller overrides outside the memo so an inline `skeletonProps` object
// doesn't bust the memo and re-roll the random width on every render
const skeletonProps = skeletonPropsOverride && Object.keys(skeletonPropsOverride).length > 0 ? _extends({}, baseSkeletonProps, skeletonPropsOverride) : baseSkeletonProps;
return /*#__PURE__*/_jsx("div", _extends({
"data-field": field,
className: clsx(classes.root, className),
style: _extends({
height,
maxWidth: width,
minWidth: width
}, style)
}, other, {
children: !empty && /*#__PURE__*/_jsx(rootProps.slots.baseSkeleton, _extends({}, skeletonProps))
}));
}
process.env.NODE_ENV !== "production" ? GridSkeletonCell.propTypes /* remove-proptypes */ = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "pnpm proptypes" |
// ----------------------------------------------------------------------
align: PropTypes.string,
/**
* If `true`, the cell will not display the skeleton but still reserve the cell space.
* @default false
*/
empty: PropTypes.bool,
field: PropTypes.string,
height: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]),
skeletonProps: PropTypes.object,
type: PropTypes.oneOf(['actions', 'boolean', 'custom', 'date', 'dateTime', 'longText', 'multiSelect', 'number', 'singleSelect', 'string']),
width: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
} : void 0;
const Memoized = fastMemo(GridSkeletonCell);
export { Memoized as GridSkeletonCell };
+12
View File
@@ -0,0 +1,12 @@
export { GridCell } from "./GridCell.mjs";
export type { GridCellProps } from "./GridCell.mjs";
export * from "./GridBooleanCell.mjs";
export * from "./GridEditBooleanCell.mjs";
export * from "./GridEditDateCell.mjs";
export * from "./GridEditInputCell.mjs";
export * from "./GridEditSingleSelectCell.mjs";
export * from "./GridActionsCell.mjs";
export * from "./GridActionsCellItem.mjs";
export * from "./GridSkeletonCell.mjs";
export * from "./GridLongTextCell.mjs";
export * from "./GridEditLongTextCell.mjs";
+12
View File
@@ -0,0 +1,12 @@
export { GridCell } from "./GridCell.js";
export type { GridCellProps } from "./GridCell.js";
export * from "./GridBooleanCell.js";
export * from "./GridEditBooleanCell.js";
export * from "./GridEditDateCell.js";
export * from "./GridEditInputCell.js";
export * from "./GridEditSingleSelectCell.js";
export * from "./GridActionsCell.js";
export * from "./GridActionsCellItem.js";
export * from "./GridSkeletonCell.js";
export * from "./GridLongTextCell.js";
export * from "./GridEditLongTextCell.js";
+135
View File
@@ -0,0 +1,135 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _exportNames = {
GridCell: true
};
Object.defineProperty(exports, "GridCell", {
enumerable: true,
get: function () {
return _GridCell.GridCell;
}
});
var _GridCell = require("./GridCell");
var _GridBooleanCell = require("./GridBooleanCell");
Object.keys(_GridBooleanCell).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _GridBooleanCell[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _GridBooleanCell[key];
}
});
});
var _GridEditBooleanCell = require("./GridEditBooleanCell");
Object.keys(_GridEditBooleanCell).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _GridEditBooleanCell[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _GridEditBooleanCell[key];
}
});
});
var _GridEditDateCell = require("./GridEditDateCell");
Object.keys(_GridEditDateCell).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _GridEditDateCell[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _GridEditDateCell[key];
}
});
});
var _GridEditInputCell = require("./GridEditInputCell");
Object.keys(_GridEditInputCell).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _GridEditInputCell[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _GridEditInputCell[key];
}
});
});
var _GridEditSingleSelectCell = require("./GridEditSingleSelectCell");
Object.keys(_GridEditSingleSelectCell).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _GridEditSingleSelectCell[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _GridEditSingleSelectCell[key];
}
});
});
var _GridActionsCell = require("./GridActionsCell");
Object.keys(_GridActionsCell).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _GridActionsCell[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _GridActionsCell[key];
}
});
});
var _GridActionsCellItem = require("./GridActionsCellItem");
Object.keys(_GridActionsCellItem).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _GridActionsCellItem[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _GridActionsCellItem[key];
}
});
});
var _GridSkeletonCell = require("./GridSkeletonCell");
Object.keys(_GridSkeletonCell).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _GridSkeletonCell[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _GridSkeletonCell[key];
}
});
});
var _GridLongTextCell = require("./GridLongTextCell");
Object.keys(_GridLongTextCell).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _GridLongTextCell[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _GridLongTextCell[key];
}
});
});
var _GridEditLongTextCell = require("./GridEditLongTextCell");
Object.keys(_GridEditLongTextCell).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _GridEditLongTextCell[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _GridEditLongTextCell[key];
}
});
});
+11
View File
@@ -0,0 +1,11 @@
export { GridCell } from "./GridCell.mjs";
export * from "./GridBooleanCell.mjs";
export * from "./GridEditBooleanCell.mjs";
export * from "./GridEditDateCell.mjs";
export * from "./GridEditInputCell.mjs";
export * from "./GridEditSingleSelectCell.mjs";
export * from "./GridActionsCell.mjs";
export * from "./GridActionsCellItem.mjs";
export * from "./GridSkeletonCell.mjs";
export * from "./GridLongTextCell.mjs";
export * from "./GridEditLongTextCell.mjs";