@rjsf/mui
Version:
Material UI 7 theme, fields and widgets for react-jsonschema-form
1,153 lines (1,142 loc) • 42.9 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@rjsf/core'), require('@mui/icons-material/Add'), require('@mui/material/IconButton'), require('@rjsf/utils'), require('react/jsx-runtime'), require('@mui/material/Box'), require('@mui/material/Grid'), require('@mui/material/Paper'), require('react'), require('@mui/material/TextField'), require('@mui/material/InputAdornment'), require('@mui/material/Typography'), require('@mui/icons-material/Error'), require('@mui/material/List'), require('@mui/material/ListItem'), require('@mui/material/ListItemIcon'), require('@mui/material/ListItemText'), require('@mui/icons-material/ArrowDownward'), require('@mui/icons-material/ArrowUpward'), require('@mui/icons-material/ContentCopy'), require('@mui/icons-material/Remove'), require('@mui/icons-material/Clear'), require('@mui/material/FormHelperText'), require('@mui/material/FormControl'), require('@mui/material/Button'), require('@mui/material/Divider'), require('@mui/material/Checkbox'), require('@mui/material/FormControlLabel'), require('@mui/material/FormGroup'), require('@mui/material/FormLabel'), require('@mui/material/Radio'), require('@mui/material/RadioGroup'), require('@mui/material/Slider'), require('@mui/material/MenuItem')) :
typeof define === 'function' && define.amd ? define(['exports', '@rjsf/core', '@mui/icons-material/Add', '@mui/material/IconButton', '@rjsf/utils', 'react/jsx-runtime', '@mui/material/Box', '@mui/material/Grid', '@mui/material/Paper', 'react', '@mui/material/TextField', '@mui/material/InputAdornment', '@mui/material/Typography', '@mui/icons-material/Error', '@mui/material/List', '@mui/material/ListItem', '@mui/material/ListItemIcon', '@mui/material/ListItemText', '@mui/icons-material/ArrowDownward', '@mui/icons-material/ArrowUpward', '@mui/icons-material/ContentCopy', '@mui/icons-material/Remove', '@mui/icons-material/Clear', '@mui/material/FormHelperText', '@mui/material/FormControl', '@mui/material/Button', '@mui/material/Divider', '@mui/material/Checkbox', '@mui/material/FormControlLabel', '@mui/material/FormGroup', '@mui/material/FormLabel', '@mui/material/Radio', '@mui/material/RadioGroup', '@mui/material/Slider', '@mui/material/MenuItem'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@rjsf/mui"] = {}, global.core, global.AddIcon, global.IconButton, global.utils, global.jsxRuntime, global.Box, global.Grid4, global.Paper, global.react, global.TextField, global.InputAdornment, global.Typography, global.ErrorIcon, global.List, global.ListItem, global.ListItemIcon, global.ListItemText, global.ArrowDownwardIcon, global.ArrowUpwardIcon, global.CopyIcon, global.RemoveIcon, global.ClearIcon, global.FormHelperText, global.FormControl, global.Button, global.Divider, global.Checkbox, global.FormControlLabel, global.FormGroup, global.FormLabel, global.Radio, global.RadioGroup, global.Slider, global.MenuItem));
})(this, (function (exports, core, AddIcon, IconButton, utils, jsxRuntime, Box, Grid4, Paper, react, TextField, InputAdornment, Typography, ErrorIcon, List, ListItem, ListItemIcon, ListItemText, ArrowDownwardIcon, ArrowUpwardIcon, CopyIcon, RemoveIcon, ClearIcon, FormHelperText, FormControl, Button, Divider, Checkbox, FormControlLabel, FormGroup, FormLabel, Radio, RadioGroup, Slider, MenuItem) { 'use strict';
// src/MuiForm/MuiForm.tsx
// src/util.ts
function getMuiProps(options, propsToFilter, rjsfSlotPropsOnly) {
const muiProps = options?.mui || {};
if (propsToFilter) {
return Object.keys(muiProps).filter((key) => propsToFilter.includes(key)).reduce((obj, key) => {
obj[key] = muiProps[key];
return obj;
}, {});
}
return muiProps;
}
function computeSxProps(sxProps, muiProps) {
if (!muiProps) {
return sxProps;
}
if (Array.isArray(muiProps?.sx)) {
return [sxProps, ...muiProps.sx];
}
return { ...sxProps, ...muiProps?.sx };
}
function AddButton({
uiSchema,
registry,
...props
}) {
const { translateString } = registry;
const uiOptions = utils.getUiOptions(uiSchema);
const muiProps = getMuiProps(uiOptions, [
"color",
"disableFocusRipple",
"disableRipple",
"edge",
"size",
"sx"
]);
return /* @__PURE__ */ jsxRuntime.jsx(IconButton, { title: translateString(utils.TranslatableString.AddItemButton), ...props, color: "primary", ...muiProps, children: /* @__PURE__ */ jsxRuntime.jsx(AddIcon, {}) });
}
function ArrayFieldItemTemplate(props) {
const { children, buttonsProps, hasDescription, hasToolbar, uiSchema, registry } = props;
const uiOptions = utils.getUiOptions(uiSchema);
const ArrayFieldItemButtonsTemplate = utils.getTemplate(
"ArrayFieldItemButtonsTemplate",
registry,
uiOptions
);
const btnStyle = {
flex: 1,
paddingLeft: 6,
paddingRight: 6,
fontWeight: "bold",
minWidth: 0
};
const {
rjsfSlotProps: {
arrayItemGridContainer,
arrayItemGridItem,
arrayItemInnerBox,
arrayItemOuterBox,
arrayItemPaper,
arrayItemToolbarGrid
} = {}
} = getMuiProps(uiOptions);
return /* @__PURE__ */ jsxRuntime.jsxs(
Grid4,
{
container: true,
...arrayItemGridContainer,
sx: computeSxProps({ alignItems: "center" }, arrayItemGridContainer),
children: [
/* @__PURE__ */ jsxRuntime.jsx(
Grid4,
{
size: { xs: 8, sm: 9, md: 10, lg: 11, xl: 11.25 },
...arrayItemGridItem,
sx: computeSxProps({ overflow: "auto" }, arrayItemGridItem),
children: /* @__PURE__ */ jsxRuntime.jsx(Box, { ...arrayItemOuterBox, sx: computeSxProps({ mb: 2 }, arrayItemOuterBox), children: /* @__PURE__ */ jsxRuntime.jsx(Paper, { elevation: 2, ...arrayItemPaper, children: /* @__PURE__ */ jsxRuntime.jsx(Box, { ...arrayItemInnerBox, sx: computeSxProps({ p: 2 }, arrayItemInnerBox), children }) }) })
}
),
hasToolbar && /* @__PURE__ */ jsxRuntime.jsx(
Grid4,
{
...arrayItemToolbarGrid,
sx: computeSxProps({ mt: hasDescription ? -5 : -1.5 }, arrayItemToolbarGrid),
children: /* @__PURE__ */ jsxRuntime.jsx(ArrayFieldItemButtonsTemplate, { ...buttonsProps, style: btnStyle })
}
)
]
}
);
}
function ArrayFieldTemplate(props) {
const {
canAdd,
disabled,
fieldPathId,
uiSchema,
items,
optionalDataControl,
onAddClick,
readonly,
registry,
required,
schema,
title
} = props;
const uiOptions = utils.getUiOptions(uiSchema);
const ArrayFieldDescriptionTemplate = utils.getTemplate(
"ArrayFieldDescriptionTemplate",
registry,
uiOptions
);
const ArrayFieldTitleTemplate = utils.getTemplate(
"ArrayFieldTitleTemplate",
registry,
uiOptions
);
const showOptionalDataControlInTitle = !readonly && !disabled;
const {
ButtonTemplates: { AddButton: AddButton2 }
} = registry.templates;
const {
rjsfSlotProps: {
arrayPaper,
arrayBox,
arrayAddButtonGridContainer,
arrayAddButtonGridItem,
arrayAddButtonBox
} = {}
} = getMuiProps(uiOptions);
return /* @__PURE__ */ jsxRuntime.jsx(Paper, { elevation: 2, ...arrayPaper, children: /* @__PURE__ */ jsxRuntime.jsxs(Box, { ...arrayBox, sx: computeSxProps({ p: 2 }, arrayBox), children: [
/* @__PURE__ */ jsxRuntime.jsx(
ArrayFieldTitleTemplate,
{
fieldPathId,
title: uiOptions.title || title,
schema,
uiSchema,
required,
registry,
optionalDataControl: showOptionalDataControlInTitle ? optionalDataControl : void 0
}
),
/* @__PURE__ */ jsxRuntime.jsx(
ArrayFieldDescriptionTemplate,
{
fieldPathId,
description: uiOptions.description || schema.description,
schema,
uiSchema,
registry
}
),
!showOptionalDataControlInTitle ? optionalDataControl : void 0,
items,
canAdd && /* @__PURE__ */ jsxRuntime.jsx(
Grid4,
{
container: true,
...arrayAddButtonGridContainer,
sx: computeSxProps({ justifyContent: "flex-end" }, arrayAddButtonGridContainer),
children: /* @__PURE__ */ jsxRuntime.jsx(Grid4, { ...arrayAddButtonGridItem, children: /* @__PURE__ */ jsxRuntime.jsx(Box, { ...arrayAddButtonBox, sx: computeSxProps({ mt: 2 }, arrayAddButtonBox), children: /* @__PURE__ */ jsxRuntime.jsx(
AddButton2,
{
id: utils.buttonId(fieldPathId, "add"),
className: "rjsf-array-item-add",
onClick: onAddClick,
disabled: disabled || readonly,
uiSchema,
registry
}
) }) })
}
)
] }) });
}
var TYPES_THAT_SHRINK_LABEL = ["date", "datetime-local", "file", "time"];
function BaseInputTemplate(props) {
const {
id,
name,
// remove this from textFieldProps
htmlName,
placeholder,
required,
readonly,
disabled,
type,
label,
hideLabel,
hideError,
value,
onChange,
onChangeOverride,
onBlur,
onFocus,
autofocus,
options,
schema,
uiSchema,
rawErrors = [],
errorSchema,
registry,
InputLabelProps,
InputProps,
slotProps,
...textFieldProps
} = props;
const { ClearButton: ClearButton2 } = registry.templates.ButtonTemplates;
const { step, min, max, accept, ...rest } = utils.getInputProps(schema, type, options);
const muiProps = getMuiProps(options);
const { slotProps: muiSlotProps, ...otherMuiProps } = muiProps;
const htmlInputProps = {
...slotProps?.htmlInput,
...muiSlotProps?.htmlInput,
step,
min,
max,
accept,
...schema.examples ? { list: utils.examplesId(id) } : void 0
};
const _onChange = ({ target: { value: value2 } }) => onChange(value2 === "" ? options.emptyValue : value2);
const _onBlur = ({ target }) => onBlur(id, target && target.value);
const _onFocus = ({ target }) => onFocus(id, target && target.value);
const DisplayInputLabelProps = TYPES_THAT_SHRINK_LABEL.includes(type) ? { ...slotProps?.inputLabel, ...muiSlotProps?.inputLabel, ...InputLabelProps, shrink: true } : { ...slotProps?.inputLabel, ...muiSlotProps?.inputLabel, ...InputLabelProps };
const _onClear = react.useCallback(
(e) => {
e.preventDefault();
e.stopPropagation();
onChange(options.emptyValue ?? "");
},
[onChange, options.emptyValue]
);
const inputProps = { ...InputProps, ...slotProps?.input, ...muiSlotProps?.input };
if (options.allowClearTextInputs && value && !readonly && !disabled) {
const clearAdornment = /* @__PURE__ */ jsxRuntime.jsx(InputAdornment, { position: "end", children: /* @__PURE__ */ jsxRuntime.jsx(ClearButton2, { registry, onClick: _onClear }) });
inputProps.endAdornment = !inputProps.endAdornment ? clearAdornment : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
inputProps.endAdornment,
clearAdornment
] });
}
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
/* @__PURE__ */ jsxRuntime.jsx(
TextField,
{
id,
name: htmlName || id,
placeholder,
label: utils.labelValue(label || void 0, hideLabel, void 0),
autoFocus: autofocus,
required,
disabled: disabled || readonly,
slotProps: {
...slotProps,
...muiSlotProps,
input: inputProps,
htmlInput: htmlInputProps,
inputLabel: DisplayInputLabelProps
},
...rest,
value: value || value === 0 ? value : "",
error: rawErrors.length > 0,
onChange: onChangeOverride || _onChange,
onBlur: _onBlur,
onFocus: _onFocus,
...{ ...otherMuiProps, ...textFieldProps },
"aria-describedby": utils.ariaDescribedByIds(id, !!schema.examples)
}
),
/* @__PURE__ */ jsxRuntime.jsx(core.SchemaExamples, { id, schema })
] });
}
function DescriptionField(props) {
const { id, description, registry, uiSchema } = props;
const uiOptions = utils.getUiOptions(uiSchema);
const { rjsfSlotProps: { descTypography } = {} } = getMuiProps(uiOptions);
if (description) {
return /* @__PURE__ */ jsxRuntime.jsx(
Typography,
{
id,
variant: "subtitle2",
...descTypography,
sx: computeSxProps({ mt: 0.625 }, descTypography),
children: /* @__PURE__ */ jsxRuntime.jsx(core.RichDescription, { description, registry, uiSchema })
}
);
}
return null;
}
function ErrorList({
errors,
registry,
uiSchema
}) {
const { translateString } = registry;
const uiOptions = utils.getUiOptions(uiSchema);
const {
rjsfSlotProps: {
errorPaper,
errorBox,
errorTypography,
errorList,
errorListItem,
errorListItemIcon,
errorListItemText
} = {}
} = getMuiProps(uiOptions);
return /* @__PURE__ */ jsxRuntime.jsx(Paper, { elevation: 2, ...errorPaper, children: /* @__PURE__ */ jsxRuntime.jsxs(Box, { ...errorBox, sx: computeSxProps({ mb: 2, p: 2 }, errorBox), children: [
/* @__PURE__ */ jsxRuntime.jsx(Typography, { variant: "h6", ...errorTypography, children: translateString(utils.TranslatableString.ErrorsLabel) }),
/* @__PURE__ */ jsxRuntime.jsx(List, { dense: true, ...errorList, children: errors.map((error, i) => {
return /* @__PURE__ */ jsxRuntime.jsxs(ListItem, { ...errorListItem, children: [
/* @__PURE__ */ jsxRuntime.jsx(ListItemIcon, { ...errorListItemIcon, children: /* @__PURE__ */ jsxRuntime.jsx(ErrorIcon, { color: "error" }) }),
/* @__PURE__ */ jsxRuntime.jsx(ListItemText, { primary: error.stack, ...errorListItemText })
] }, i);
}) })
] }) });
}
function MuiIconButton(props) {
const { icon, color, uiSchema, registry, ...otherProps } = props;
const uiOptions = utils.getUiOptions(uiSchema);
const muiProps = getMuiProps(uiOptions, [
"color",
"disableFocusRipple",
"disableRipple",
"edge",
"size",
"sx"
]);
return /* @__PURE__ */ jsxRuntime.jsx(IconButton, { ...muiProps, ...otherProps, size: "small", color, children: icon });
}
function CopyButton(props) {
const {
registry: { translateString }
} = props;
return /* @__PURE__ */ jsxRuntime.jsx(
MuiIconButton,
{
title: translateString(utils.TranslatableString.CopyButton),
...props,
icon: /* @__PURE__ */ jsxRuntime.jsx(CopyIcon, { fontSize: "small" })
}
);
}
function MoveDownButton(props) {
const {
registry: { translateString }
} = props;
return /* @__PURE__ */ jsxRuntime.jsx(
MuiIconButton,
{
title: translateString(utils.TranslatableString.MoveDownButton),
...props,
icon: /* @__PURE__ */ jsxRuntime.jsx(ArrowDownwardIcon, { fontSize: "small" })
}
);
}
function MoveUpButton(props) {
const {
registry: { translateString }
} = props;
return /* @__PURE__ */ jsxRuntime.jsx(
MuiIconButton,
{
title: translateString(utils.TranslatableString.MoveUpButton),
...props,
icon: /* @__PURE__ */ jsxRuntime.jsx(ArrowUpwardIcon, { fontSize: "small" })
}
);
}
function RemoveButton(props) {
const { iconType, ...otherProps } = props;
const {
registry: { translateString }
} = otherProps;
return /* @__PURE__ */ jsxRuntime.jsx(
MuiIconButton,
{
title: translateString(utils.TranslatableString.RemoveButton),
...otherProps,
color: "error",
icon: /* @__PURE__ */ jsxRuntime.jsx(RemoveIcon, { fontSize: iconType === "default" ? void 0 : "small" })
}
);
}
function ClearButton(props) {
const { iconType, ...otherProps } = props;
const {
registry: { translateString }
} = otherProps;
return /* @__PURE__ */ jsxRuntime.jsx(
MuiIconButton,
{
title: translateString(utils.TranslatableString.ClearButton),
...otherProps,
icon: /* @__PURE__ */ jsxRuntime.jsx(ClearIcon, { fontSize: iconType === "default" ? void 0 : "small" })
}
);
}
function FieldErrorTemplate(props) {
const { errors = [], fieldPathId, uiSchema } = props;
if (errors.length === 0) {
return null;
}
const id = utils.errorId(fieldPathId);
const uiOptions = utils.getUiOptions(uiSchema);
const muiProps = getMuiProps(uiOptions);
const { rjsfSlotProps: muiSlotProps } = muiProps;
return /* @__PURE__ */ jsxRuntime.jsx(List, { id, dense: true, disablePadding: true, ...muiSlotProps?.fieldErrorList, children: errors.map((error, i) => {
return /* @__PURE__ */ jsxRuntime.jsx(ListItem, { disableGutters: true, ...muiSlotProps?.fieldErrorListItem, children: /* @__PURE__ */ jsxRuntime.jsx(FormHelperText, { component: "div", id: `${id}-${i}`, ...muiSlotProps?.fieldErrorFormHelperText, children: error }) }, i);
}) });
}
function FieldHelpTemplate(props) {
const { fieldPathId, help, uiSchema, registry } = props;
if (!help) {
return null;
}
const uiOptions = utils.getUiOptions(uiSchema);
const { rjsfSlotProps: { helpFormHelperText } = {} } = getMuiProps(uiOptions);
return /* @__PURE__ */ jsxRuntime.jsx(
FormHelperText,
{
component: "div",
id: utils.helpId(fieldPathId),
...helpFormHelperText,
sx: computeSxProps({ mt: 0.625 }, helpFormHelperText),
children: /* @__PURE__ */ jsxRuntime.jsx(core.RichHelp, { help, registry, uiSchema })
}
);
}
function FieldTemplate(props) {
const {
id,
children,
classNames,
style,
disabled,
displayLabel,
hidden,
label,
onKeyRename,
onKeyRenameBlur,
onRemoveProperty,
readonly,
required,
rawErrors = [],
errors,
help,
description,
rawDescription,
schema,
uiSchema,
registry
} = props;
const uiOptions = utils.getUiOptions(uiSchema);
const WrapIfAdditionalTemplate2 = utils.getTemplate(
"WrapIfAdditionalTemplate",
registry,
uiOptions
);
if (hidden) {
return /* @__PURE__ */ jsxRuntime.jsx("div", { style: { display: "none" }, children });
}
const isCheckbox = uiOptions.widget === "checkbox";
const { rjsfSlotProps: muiSlotProps, ...otherMuiProps } = getMuiProps(uiOptions);
return /* @__PURE__ */ jsxRuntime.jsx(
WrapIfAdditionalTemplate2,
{
classNames,
style,
disabled,
id,
label,
displayLabel,
rawDescription,
onKeyRename,
onKeyRenameBlur,
onRemoveProperty,
readonly,
required,
schema,
uiSchema,
registry,
children: /* @__PURE__ */ jsxRuntime.jsxs(
FormControl,
{
fullWidth: true,
error: rawErrors.length ? true : false,
required,
...muiSlotProps?.fieldFormControl,
sx: otherMuiProps.sx,
className: otherMuiProps.className,
children: [
children,
displayLabel && !isCheckbox && rawDescription ? /* @__PURE__ */ jsxRuntime.jsx(Typography, { variant: "caption", color: "textSecondary", ...muiSlotProps?.fieldTypography, children: description }) : null,
errors,
help
]
}
)
}
);
}
function GridTemplate(props) {
const { children, column, ...rest } = props;
return /* @__PURE__ */ jsxRuntime.jsx(Grid4, { container: !column, ...rest, children });
}
function MultiSchemaFieldTemplate(props) {
const { optionSchemaField, selector, uiSchema } = props;
const uiOptions = utils.getUiOptions(uiSchema);
const { rjsfSlotProps: muiSlotProps } = getMuiProps(uiOptions);
return /* @__PURE__ */ jsxRuntime.jsxs(Box, { sx: { mb: 2 }, ...muiSlotProps?.multiBox, children: [
/* @__PURE__ */ jsxRuntime.jsx(FormControl, { fullWidth: true, sx: { mb: 2 }, ...muiSlotProps?.multiFormControl, children: selector }),
optionSchemaField
] });
}
function ObjectFieldTemplate(props) {
const {
description,
title,
properties,
required,
disabled,
readonly,
uiSchema,
fieldPathId,
schema,
formData,
optionalDataControl,
onAddProperty,
registry
} = props;
const uiOptions = utils.getUiOptions(uiSchema);
const TitleFieldTemplate = utils.getTemplate("TitleFieldTemplate", registry, uiOptions);
const DescriptionFieldTemplate = utils.getTemplate(
"DescriptionFieldTemplate",
registry,
uiOptions
);
const showOptionalDataControlInTitle = !readonly && !disabled;
const {
ButtonTemplates: { AddButton: AddButton2 }
} = registry.templates;
const {
rjsfSlotProps: { objectGridContainer, objectGridItem, objectAddButtonGridContainer, objectAddButtonGridItem } = {}
} = getMuiProps(uiOptions);
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
title && /* @__PURE__ */ jsxRuntime.jsx(
TitleFieldTemplate,
{
id: utils.titleId(fieldPathId),
title,
required,
schema,
uiSchema,
registry,
optionalDataControl: showOptionalDataControlInTitle ? optionalDataControl : void 0
}
),
description && /* @__PURE__ */ jsxRuntime.jsx(
DescriptionFieldTemplate,
{
id: utils.descriptionId(fieldPathId),
description,
schema,
uiSchema,
registry
}
),
/* @__PURE__ */ jsxRuntime.jsxs(
Grid4,
{
container: true,
spacing: 2,
...objectGridContainer,
sx: computeSxProps({ mt: 1.25 }, objectGridContainer),
children: [
!showOptionalDataControlInTitle ? optionalDataControl : void 0,
properties.map(
(element, index) => (
// Remove the <Grid> if the inner element is hidden as the <Grid>
// itself would otherwise still take up space.
element.hidden ? element.content : /* @__PURE__ */ jsxRuntime.jsx(
Grid4,
{
size: { xs: 12 },
...objectGridItem,
sx: computeSxProps({ mb: 1.25 }, objectGridItem),
children: element.content
},
index
)
)
)
]
}
),
utils.canExpand(schema, uiSchema, formData) && /* @__PURE__ */ jsxRuntime.jsx(
Grid4,
{
container: true,
...objectAddButtonGridContainer,
sx: computeSxProps({ justifyContent: "flex-end" }, objectAddButtonGridContainer),
children: /* @__PURE__ */ jsxRuntime.jsx(Grid4, { ...objectAddButtonGridItem, children: /* @__PURE__ */ jsxRuntime.jsx(
AddButton2,
{
id: utils.buttonId(fieldPathId, "add"),
className: "rjsf-object-property-expand",
onClick: onAddProperty,
disabled: disabled || readonly,
uiSchema,
registry
}
) })
}
)
] });
}
function OptionalDataControlsTemplate(props) {
const { id, registry, label, onAddClick, onRemoveClick, uiSchema } = props;
if (onAddClick) {
return /* @__PURE__ */ jsxRuntime.jsx(
MuiIconButton,
{
id,
registry,
uiSchema,
className: "rjsf-add-optional-data",
onClick: onAddClick,
title: label,
icon: /* @__PURE__ */ jsxRuntime.jsx(AddIcon, { fontSize: "small" })
}
);
} else if (onRemoveClick) {
return /* @__PURE__ */ jsxRuntime.jsx(
RemoveButton,
{
id,
registry,
uiSchema,
className: "rjsf-remove-optional-data",
onClick: onRemoveClick,
title: label
}
);
}
return /* @__PURE__ */ jsxRuntime.jsx("em", { id, children: label });
}
function SubmitButton({ uiSchema }) {
const { submitText, norender, props: submitButtonProps = {} } = utils.getSubmitButtonOptions(uiSchema);
if (norender) {
return null;
}
const uiOptions = utils.getUiOptions(uiSchema);
const { rjsfSlotProps: { submitBox, submitButton } = {}, ...otherMuiProps } = getMuiProps(uiOptions);
return /* @__PURE__ */ jsxRuntime.jsx(Box, { ...submitBox, sx: computeSxProps({ mt: 3 }, submitBox), children: /* @__PURE__ */ jsxRuntime.jsx(
Button,
{
type: "submit",
variant: "contained",
color: "primary",
...submitButtonProps,
...otherMuiProps,
...submitButton,
children: submitText
}
) });
}
function TitleField(props) {
const { id, title, optionalDataControl, uiSchema } = props;
const uiOptions = utils.getUiOptions(uiSchema);
const {
rjsfSlotProps: {
titleBox,
titleDivider,
titleTypography,
titleGridContainer,
titleGridItem,
titleOptionalDataGridItem
} = {}
} = getMuiProps(uiOptions);
let heading = /* @__PURE__ */ jsxRuntime.jsx(Typography, { variant: "h5", ...titleTypography, children: title });
if (optionalDataControl) {
heading = /* @__PURE__ */ jsxRuntime.jsxs(Grid4, { container: true, spacing: 0, ...titleGridContainer, children: [
/* @__PURE__ */ jsxRuntime.jsx(Grid4, { size: "grow", ...titleGridItem, children: heading }),
/* @__PURE__ */ jsxRuntime.jsx(
Grid4,
{
...titleOptionalDataGridItem,
sx: computeSxProps({ justifyContent: "flex-end" }, titleOptionalDataGridItem),
children: optionalDataControl
}
)
] });
}
return /* @__PURE__ */ jsxRuntime.jsxs(Box, { id, ...titleBox, sx: computeSxProps({ mb: 1, mt: 1 }, titleBox), children: [
heading,
/* @__PURE__ */ jsxRuntime.jsx(Divider, { ...titleDivider })
] });
}
function WrapIfAdditionalTemplate(props) {
const {
children,
classNames,
style,
disabled,
id,
label,
displayLabel,
onKeyRenameBlur,
onRemoveProperty,
readonly,
required,
schema,
uiSchema,
registry
} = props;
const { templates, translateString } = registry;
const { RemoveButton: RemoveButton2 } = templates.ButtonTemplates;
const keyLabel = translateString(utils.TranslatableString.KeyLabel, [label]);
const additional = utils.ADDITIONAL_PROPERTY_FLAG in schema;
const btnStyle = {
flex: 1,
paddingLeft: 6,
paddingRight: 6,
fontWeight: "bold"
};
const uiOptions = utils.getUiOptions(uiSchema);
const { rjsfSlotProps: { wrapGridContainer, wrapKeyGridItem, wrapChildrenGridItem, wrapRemoveButtonGridItem } = {} } = getMuiProps(uiOptions);
if (!additional) {
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: classNames, style, children });
}
return /* @__PURE__ */ jsxRuntime.jsxs(
Grid4,
{
container: true,
spacing: 2,
className: classNames,
style,
...wrapGridContainer,
sx: computeSxProps({ alignItems: "flex-start" }, wrapGridContainer),
children: [
/* @__PURE__ */ jsxRuntime.jsx(Grid4, { size: 5.5, ...wrapKeyGridItem, children: /* @__PURE__ */ jsxRuntime.jsx(
TextField,
{
fullWidth: true,
required,
label: displayLabel ? keyLabel : void 0,
defaultValue: label,
disabled: disabled || readonly,
id: `${id}-key`,
name: `${id}-key`,
onBlur: !readonly ? onKeyRenameBlur : void 0,
type: "text"
},
label
) }),
/* @__PURE__ */ jsxRuntime.jsx(Grid4, { size: 5.5, ...wrapChildrenGridItem, children }),
/* @__PURE__ */ jsxRuntime.jsx(Grid4, { ...wrapRemoveButtonGridItem, sx: computeSxProps({ mt: 1.5 }, wrapRemoveButtonGridItem), children: /* @__PURE__ */ jsxRuntime.jsx(
RemoveButton2,
{
id: utils.buttonId(id, "remove"),
className: "rjsf-object-property-remove",
iconType: "default",
style: btnStyle,
disabled: disabled || readonly,
onClick: onRemoveProperty,
uiSchema,
registry
}
) })
]
},
`${id}-key`
);
}
// src/Templates/Templates.ts
function generateTemplates() {
return {
ArrayFieldItemTemplate,
ArrayFieldTemplate,
BaseInputTemplate,
ButtonTemplates: {
AddButton,
CopyButton,
MoveDownButton,
MoveUpButton,
RemoveButton,
SubmitButton,
ClearButton
},
DescriptionFieldTemplate: DescriptionField,
ErrorListTemplate: ErrorList,
FieldErrorTemplate,
FieldHelpTemplate,
FieldTemplate,
GridTemplate,
MultiSchemaFieldTemplate,
ObjectFieldTemplate,
OptionalDataControlsTemplate,
TitleFieldTemplate: TitleField,
WrapIfAdditionalTemplate
};
}
var Templates_default = generateTemplates();
function CheckboxWidget(props) {
const {
schema,
id,
htmlName,
value,
disabled,
readonly,
label = "",
hideLabel,
autofocus,
onChange,
onBlur,
onFocus,
registry,
options,
uiSchema
} = props;
const DescriptionFieldTemplate = utils.getTemplate(
"DescriptionFieldTemplate",
registry,
options
);
const required = utils.schemaRequiresTrueValue(schema);
const _onChange = (_, checked) => onChange(checked);
const _onBlur = () => onBlur(id, value);
const _onFocus = () => onFocus(id, value);
const description = options.description ?? schema.description;
const { rjsfSlotProps: muiSlotProps, ...otherMuiProps } = getMuiProps(options);
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
!hideLabel && description && /* @__PURE__ */ jsxRuntime.jsx(
DescriptionFieldTemplate,
{
id: utils.descriptionId(id),
description,
schema,
uiSchema,
registry
}
),
/* @__PURE__ */ jsxRuntime.jsx(
FormControlLabel,
{
...otherMuiProps,
...muiSlotProps?.formControlLabel,
control: /* @__PURE__ */ jsxRuntime.jsx(
Checkbox,
{
id,
name: htmlName || id,
checked: typeof value === "undefined" ? false : Boolean(value),
required,
disabled: disabled || readonly,
autoFocus: autofocus,
onChange: _onChange,
onBlur: _onBlur,
onFocus: _onFocus,
"aria-describedby": utils.ariaDescribedByIds(id),
...muiSlotProps?.checkbox
}
),
label: utils.labelValue(label, hideLabel, false)
}
)
] });
}
function CheckboxesWidget(props) {
const {
label,
hideLabel,
id,
htmlName,
disabled,
options,
value,
autofocus,
readonly,
required,
onChange,
onBlur,
onFocus
} = props;
const { enumOptions, enumDisabled, inline, emptyValue } = options;
const optionValueFormat = utils.getOptionValueFormat(options);
const checkboxesValues = Array.isArray(value) ? value : [value];
const _onChange = (index) => ({ target: { checked } }) => {
if (checked) {
onChange(utils.enumOptionsSelectValue(index, checkboxesValues, enumOptions));
} else {
onChange(utils.enumOptionsDeselectValue(index, checkboxesValues, enumOptions));
}
};
const _onBlur = ({ target }) => onBlur(id, utils.enumOptionValueDecoder(target && target.value, enumOptions, optionValueFormat, emptyValue));
const _onFocus = ({ target }) => onFocus(id, utils.enumOptionValueDecoder(target && target.value, enumOptions, optionValueFormat, emptyValue));
const { rjsfSlotProps: muiSlotProps, ...otherMuiProps } = getMuiProps(options);
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
utils.labelValue(
/* @__PURE__ */ jsxRuntime.jsx(FormLabel, { required, htmlFor: id, children: label || void 0 }),
hideLabel
),
/* @__PURE__ */ jsxRuntime.jsx(FormGroup, { ...otherMuiProps, ...muiSlotProps?.formGroup, id, row: !!inline, children: Array.isArray(enumOptions) && enumOptions.map((option, index) => {
const checked = utils.enumOptionsIsSelected(option.value, checkboxesValues);
const itemDisabled = Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) !== -1;
const checkbox = /* @__PURE__ */ jsxRuntime.jsx(
Checkbox,
{
...muiSlotProps?.checkbox,
id: utils.optionId(id, index),
name: htmlName || id,
checked,
disabled: disabled || itemDisabled || readonly,
autoFocus: autofocus && index === 0,
onChange: _onChange(index),
onBlur: _onBlur,
onFocus: _onFocus,
"aria-describedby": utils.ariaDescribedByIds(id)
}
);
return /* @__PURE__ */ react.createElement(
FormControlLabel,
{
...muiSlotProps?.formControlLabel,
control: checkbox,
key: index,
label: option.label
}
);
}) })
] });
}
function RadioWidget(props) {
const { id, htmlName, options, value, required, disabled, readonly, label, hideLabel, onChange, onBlur, onFocus } = props;
const { enumOptions, enumDisabled, emptyValue } = options;
const optionValueFormat = utils.getOptionValueFormat(options);
const _onChange = (_, value2) => onChange(utils.enumOptionValueDecoder(value2, enumOptions, optionValueFormat, emptyValue));
const _onBlur = ({ target }) => onBlur(id, utils.enumOptionValueDecoder(target && target.value, enumOptions, optionValueFormat, emptyValue));
const _onFocus = ({ target }) => onFocus(id, utils.enumOptionValueDecoder(target && target.value, enumOptions, optionValueFormat, emptyValue));
const row = options ? options.inline : false;
const selectValue = utils.enumOptionSelectedValue(value, enumOptions, false, optionValueFormat, "");
const { rjsfSlotProps: muiSlotProps, ...otherMuiProps } = getMuiProps(options);
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
utils.labelValue(
/* @__PURE__ */ jsxRuntime.jsx(FormLabel, { required, htmlFor: id, children: label || void 0 }),
hideLabel
),
/* @__PURE__ */ jsxRuntime.jsx(
RadioGroup,
{
...otherMuiProps,
...muiSlotProps?.radioGroup,
id,
name: htmlName || id,
value: selectValue,
row,
onChange: _onChange,
onBlur: _onBlur,
onFocus: _onFocus,
"aria-describedby": utils.ariaDescribedByIds(id),
children: Array.isArray(enumOptions) && enumOptions.map((option, index) => {
const itemDisabled = Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) !== -1;
const radio = /* @__PURE__ */ react.createElement(
FormControlLabel,
{
...muiSlotProps?.formControlLabel,
control: /* @__PURE__ */ jsxRuntime.jsx(Radio, { ...muiSlotProps?.radio, name: htmlName || id, id: utils.optionId(id, index), color: "primary" }),
label: option.label,
value: utils.enumOptionValueEncoder(option.value, index, optionValueFormat),
key: index,
disabled: disabled || itemDisabled || readonly
}
);
return radio;
})
}
)
] });
}
function RangeWidget(props) {
const { value, readonly, disabled, onBlur, onFocus, options, schema, onChange, required, label, hideLabel, id } = props;
const sliderProps = { value, label, id, name: id, ...utils.rangeSpec(schema) };
const _onChange = (_, value2) => {
onChange(value2 ?? options.emptyValue);
};
const _onBlur = ({ target }) => onBlur(id, target && target.value);
const _onFocus = ({ target }) => onFocus(id, target && target.value);
const { rjsfSlotProps: muiSlotProps, ...otherMuiProps } = getMuiProps(options);
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
utils.labelValue(
/* @__PURE__ */ jsxRuntime.jsx(FormLabel, { required, htmlFor: id, children: label || void 0 }),
hideLabel
),
/* @__PURE__ */ jsxRuntime.jsx(
Slider,
{
disabled: disabled || readonly,
onChange: _onChange,
onBlur: _onBlur,
onFocus: _onFocus,
valueLabelDisplay: "auto",
...otherMuiProps,
...muiSlotProps?.slider,
...sliderProps,
"aria-describedby": utils.ariaDescribedByIds(id)
}
)
] });
}
function SelectWidget(props) {
const {
schema,
id,
name,
// remove this from textFieldProps
htmlName,
options,
label,
hideLabel,
required,
disabled,
placeholder,
readonly,
value,
multiple,
autofocus,
onChange,
onBlur,
onFocus,
errorSchema,
rawErrors = [],
registry,
uiSchema,
hideError,
...textFieldProps
} = props;
const { enumOptions, enumDisabled, emptyValue: optEmptyVal } = options;
const optionValueFormat = utils.getOptionValueFormat(options);
const isMultiple = typeof multiple === "undefined" ? false : !!multiple;
const emptyValue = isMultiple ? [] : "";
const isEmpty = typeof value === "undefined" || isMultiple && value.length < 1 || !isMultiple && value === emptyValue;
const _onChange = ({ target: { value: value2 } }) => onChange(utils.enumOptionValueDecoder(value2, enumOptions, optionValueFormat, optEmptyVal));
const _onBlur = ({ target }) => onBlur(id, utils.enumOptionValueDecoder(target && target.value, enumOptions, optionValueFormat, optEmptyVal));
const _onFocus = ({ target }) => onFocus(id, utils.enumOptionValueDecoder(target && target.value, enumOptions, optionValueFormat, optEmptyVal));
const { rjsfSlotProps: muiSlotProps, ...otherMuiProps } = getMuiProps(options);
const { InputLabelProps, SelectProps, autocomplete, ...textFieldRemainingProps } = textFieldProps;
const showPlaceholderOption = !isMultiple && schema.default === void 0;
return /* @__PURE__ */ jsxRuntime.jsxs(
TextField,
{
id,
name: htmlName || id,
label: utils.labelValue(label || void 0, hideLabel, void 0),
value: utils.enumOptionSelectedValue(value, enumOptions, isMultiple, optionValueFormat, emptyValue),
required,
disabled: disabled || readonly,
autoFocus: autofocus,
autoComplete: autocomplete,
placeholder,
error: rawErrors.length > 0,
onChange: _onChange,
onBlur: _onBlur,
onFocus: _onFocus,
...{ ...otherMuiProps, ...textFieldRemainingProps },
select: true,
slotProps: {
...muiSlotProps,
inputLabel: {
...muiSlotProps?.inputLabel,
shrink: !isEmpty
},
select: {
...muiSlotProps?.select,
multiple
}
},
"aria-describedby": utils.ariaDescribedByIds(id),
children: [
showPlaceholderOption && /* @__PURE__ */ jsxRuntime.jsx(MenuItem, { value: "", children: placeholder }),
Array.isArray(enumOptions) && enumOptions.map(({ value: value2, label: label2 }, i) => {
const disabled2 = Array.isArray(enumDisabled) && enumDisabled.indexOf(value2) !== -1;
return /* @__PURE__ */ jsxRuntime.jsx(MenuItem, { value: utils.enumOptionValueEncoder(value2, i, optionValueFormat), disabled: disabled2, children: label2 }, i);
})
]
}
);
}
function TextareaWidget(props) {
const { options, registry } = props;
const BaseInputTemplate2 = utils.getTemplate("BaseInputTemplate", registry, options);
let rows = 5;
if (typeof options.rows === "string" || typeof options.rows === "number") {
rows = options.rows;
}
return /* @__PURE__ */ jsxRuntime.jsx(BaseInputTemplate2, { ...props, multiline: true, rows });
}
// src/Widgets/Widgets.ts
function generateWidgets() {
return {
CheckboxWidget,
CheckboxesWidget,
RadioWidget,
RangeWidget,
SelectWidget,
TextareaWidget
};
}
var Widgets_default = generateWidgets();
// src/Theme/Theme.tsx
function generateTheme() {
return {
templates: generateTemplates(),
widgets: generateWidgets()
};
}
var Theme_default = generateTheme();
// src/MuiForm/MuiForm.tsx
function generateForm() {
return core.withTheme(generateTheme());
}
var MuiForm_default = generateForm();
// src/index.ts
var index_default = MuiForm_default;
exports.Form = MuiForm_default;
exports.Templates = Templates_default;
exports.Theme = Theme_default;
exports.Widgets = Widgets_default;
exports.default = index_default;
exports.generateForm = generateForm;
exports.generateTemplates = generateTemplates;
exports.generateTheme = generateTheme;
exports.generateWidgets = generateWidgets;
Object.defineProperty(exports, '__esModule', { value: true });
}));