@rjsf/mui 5.0.0-beta.2 → 5.0.0-beta.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/README.md +6 -4
  2. package/dist/index.d.ts +17 -6
  3. package/dist/mui.cjs.development.js +722 -669
  4. package/dist/mui.cjs.development.js.map +1 -1
  5. package/dist/mui.cjs.production.min.js +1 -1
  6. package/dist/mui.cjs.production.min.js.map +1 -1
  7. package/dist/mui.esm.js +717 -668
  8. package/dist/mui.esm.js.map +1 -1
  9. package/dist/mui.umd.development.js +723 -670
  10. package/dist/mui.umd.development.js.map +1 -1
  11. package/dist/mui.umd.production.min.js +1 -1
  12. package/dist/mui.umd.production.min.js.map +1 -1
  13. package/package.json +18 -18
  14. package/dist/AddButton/AddButton.d.ts +0 -4
  15. package/dist/AddButton/index.d.ts +0 -2
  16. package/dist/ArrayFieldItemTemplate/ArrayFieldItemTemplate.d.ts +0 -3
  17. package/dist/ArrayFieldItemTemplate/index.d.ts +0 -2
  18. package/dist/ArrayFieldTemplate/ArrayFieldTemplate.d.ts +0 -3
  19. package/dist/ArrayFieldTemplate/index.d.ts +0 -2
  20. package/dist/BaseInputTemplate/BaseInputTemplate.d.ts +0 -3
  21. package/dist/BaseInputTemplate/index.d.ts +0 -2
  22. package/dist/CheckboxWidget/CheckboxWidget.d.ts +0 -3
  23. package/dist/CheckboxWidget/index.d.ts +0 -2
  24. package/dist/CheckboxesWidget/CheckboxesWidget.d.ts +0 -3
  25. package/dist/CheckboxesWidget/index.d.ts +0 -2
  26. package/dist/DateTimeWidget/DateTimeWidget.d.ts +0 -3
  27. package/dist/DateTimeWidget/index.d.ts +0 -2
  28. package/dist/DateWidget/DateWidget.d.ts +0 -3
  29. package/dist/DateWidget/index.d.ts +0 -2
  30. package/dist/DescriptionField/DescriptionField.d.ts +0 -3
  31. package/dist/DescriptionField/index.d.ts +0 -2
  32. package/dist/ErrorList/ErrorList.d.ts +0 -3
  33. package/dist/ErrorList/index.d.ts +0 -2
  34. package/dist/FieldTemplate/FieldTemplate.d.ts +0 -3
  35. package/dist/FieldTemplate/WrapIfAdditional.d.ts +0 -7
  36. package/dist/FieldTemplate/index.d.ts +0 -2
  37. package/dist/IconButton/IconButton.d.ts +0 -5
  38. package/dist/IconButton/index.d.ts +0 -2
  39. package/dist/MuiForm/MuiForm.d.ts +0 -4
  40. package/dist/MuiForm/index.d.ts +0 -2
  41. package/dist/ObjectFieldTemplate/ObjectFieldTemplate.d.ts +0 -3
  42. package/dist/ObjectFieldTemplate/index.d.ts +0 -2
  43. package/dist/RadioWidget/RadioWidget.d.ts +0 -3
  44. package/dist/RadioWidget/index.d.ts +0 -2
  45. package/dist/RangeWidget/RangeWidget.d.ts +0 -3
  46. package/dist/RangeWidget/index.d.ts +0 -2
  47. package/dist/SelectWidget/SelectWidget.d.ts +0 -3
  48. package/dist/SelectWidget/index.d.ts +0 -2
  49. package/dist/SubmitButton/SubmitButton.d.ts +0 -4
  50. package/dist/SubmitButton/index.d.ts +0 -2
  51. package/dist/Templates/Templates.d.ts +0 -20
  52. package/dist/Templates/index.d.ts +0 -2
  53. package/dist/TextareaWidget/TextareaWidget.d.ts +0 -3
  54. package/dist/TextareaWidget/index.d.ts +0 -2
  55. package/dist/Theme/Theme.d.ts +0 -3
  56. package/dist/Theme/index.d.ts +0 -2
  57. package/dist/TitleField/TitleField.d.ts +0 -3
  58. package/dist/TitleField/index.d.ts +0 -2
  59. package/dist/Widgets/Widgets.d.ts +0 -11
  60. package/dist/Widgets/index.d.ts +0 -2
package/dist/mui.esm.js CHANGED
@@ -5,7 +5,7 @@ import IconButton from '@mui/material/IconButton';
5
5
  import Box from '@mui/material/Box';
6
6
  import Grid from '@mui/material/Grid';
7
7
  import Paper from '@mui/material/Paper';
8
- import { getUiOptions, getTemplate, getInputProps, ADDITIONAL_PROPERTY_FLAG, canExpand, getSubmitButtonOptions, schemaRequiresTrueValue, utcToLocal, localToUTC, rangeSpec, processSelectValue } from '@rjsf/utils';
8
+ import { getUiOptions, getTemplate, getInputProps, examplesId, ariaDescribedByIds, errorId, helpId, titleId, descriptionId, canExpand, getSubmitButtonOptions, ADDITIONAL_PROPERTY_FLAG, schemaRequiresTrueValue, optionId, enumOptionsSelectValue, enumOptionsDeselectValue, utcToLocal, localToUTC, rangeSpec, processSelectValue } from '@rjsf/utils';
9
9
  import TextField from '@mui/material/TextField';
10
10
  import Typography from '@mui/material/Typography';
11
11
  import ErrorIcon from '@mui/icons-material/Error';
@@ -16,12 +16,12 @@ import ListItemText from '@mui/material/ListItemText';
16
16
  import ArrowDownwardIcon from '@mui/icons-material/ArrowDownward';
17
17
  import ArrowUpwardIcon from '@mui/icons-material/ArrowUpward';
18
18
  import RemoveIcon from '@mui/icons-material/Remove';
19
- import FormControl from '@mui/material/FormControl';
20
19
  import FormHelperText from '@mui/material/FormHelperText';
21
- import InputLabel from '@mui/material/InputLabel';
22
- import Input from '@mui/material/OutlinedInput';
20
+ import FormControl from '@mui/material/FormControl';
23
21
  import Button from '@mui/material/Button';
24
22
  import Divider from '@mui/material/Divider';
23
+ import InputLabel from '@mui/material/InputLabel';
24
+ import Input from '@mui/material/OutlinedInput';
25
25
  import Checkbox from '@mui/material/Checkbox';
26
26
  import FormControlLabel from '@mui/material/FormControlLabel';
27
27
  import FormGroup from '@mui/material/FormGroup';
@@ -31,34 +31,67 @@ import RadioGroup from '@mui/material/RadioGroup';
31
31
  import Slider from '@mui/material/Slider';
32
32
  import MenuItem from '@mui/material/MenuItem';
33
33
 
34
- const AddButton = props => {
35
- return /*#__PURE__*/React.createElement(IconButton, {
36
- title: "Add Item",
37
- ...props,
34
+ function _extends() {
35
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
36
+ for (var i = 1; i < arguments.length; i++) {
37
+ var source = arguments[i];
38
+ for (var key in source) {
39
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
40
+ target[key] = source[key];
41
+ }
42
+ }
43
+ }
44
+ return target;
45
+ };
46
+ return _extends.apply(this, arguments);
47
+ }
48
+ function _objectWithoutPropertiesLoose(source, excluded) {
49
+ if (source == null) return {};
50
+ var target = {};
51
+ var sourceKeys = Object.keys(source);
52
+ var key, i;
53
+ for (i = 0; i < sourceKeys.length; i++) {
54
+ key = sourceKeys[i];
55
+ if (excluded.indexOf(key) >= 0) continue;
56
+ target[key] = source[key];
57
+ }
58
+ return target;
59
+ }
60
+
61
+ var _excluded$4 = ["uiSchema", "registry"];
62
+ /** The `AddButton` renders a button that represent the `Add` action on a form
63
+ */
64
+ function AddButton(_ref) {
65
+ var props = _objectWithoutPropertiesLoose(_ref, _excluded$4);
66
+ return /*#__PURE__*/React.createElement(IconButton, _extends({
67
+ title: "Add Item"
68
+ }, props, {
38
69
  color: "primary"
39
- }, /*#__PURE__*/React.createElement(AddIcon, null));
40
- };
70
+ }), /*#__PURE__*/React.createElement(AddIcon, null));
71
+ }
41
72
 
42
- const ArrayFieldItemTemplate = props => {
43
- const {
44
- children,
45
- disabled,
46
- hasToolbar,
47
- hasMoveDown,
48
- hasMoveUp,
49
- hasRemove,
50
- index,
51
- onDropIndexClick,
52
- onReorderClick,
53
- readonly,
54
- registry
55
- } = props;
56
- const {
57
- MoveDownButton,
58
- MoveUpButton,
59
- RemoveButton
60
- } = registry.templates.ButtonTemplates;
61
- const btnStyle = {
73
+ /** The `ArrayFieldItemTemplate` component is the template used to render an items of an array.
74
+ *
75
+ * @param props - The `ArrayFieldTemplateItemType` props for the component
76
+ */
77
+ function ArrayFieldItemTemplate(props) {
78
+ var children = props.children,
79
+ disabled = props.disabled,
80
+ hasToolbar = props.hasToolbar,
81
+ hasMoveDown = props.hasMoveDown,
82
+ hasMoveUp = props.hasMoveUp,
83
+ hasRemove = props.hasRemove,
84
+ index = props.index,
85
+ onDropIndexClick = props.onDropIndexClick,
86
+ onReorderClick = props.onReorderClick,
87
+ readonly = props.readonly,
88
+ uiSchema = props.uiSchema,
89
+ registry = props.registry;
90
+ var _registry$templates$B = registry.templates.ButtonTemplates,
91
+ MoveDownButton = _registry$templates$B.MoveDownButton,
92
+ MoveUpButton = _registry$templates$B.MoveUpButton,
93
+ RemoveButton = _registry$templates$B.RemoveButton;
94
+ var btnStyle = {
62
95
  flex: 1,
63
96
  paddingLeft: 6,
64
97
  paddingRight: 6,
@@ -85,42 +118,47 @@ const ArrayFieldItemTemplate = props => {
85
118
  }, (hasMoveUp || hasMoveDown) && /*#__PURE__*/React.createElement(MoveUpButton, {
86
119
  style: btnStyle,
87
120
  disabled: disabled || readonly || !hasMoveUp,
88
- onClick: onReorderClick(index, index - 1)
121
+ onClick: onReorderClick(index, index - 1),
122
+ uiSchema: uiSchema,
123
+ registry: registry
89
124
  }), (hasMoveUp || hasMoveDown) && /*#__PURE__*/React.createElement(MoveDownButton, {
90
125
  style: btnStyle,
91
126
  disabled: disabled || readonly || !hasMoveDown,
92
- onClick: onReorderClick(index, index + 1)
127
+ onClick: onReorderClick(index, index + 1),
128
+ uiSchema: uiSchema,
129
+ registry: registry
93
130
  }), hasRemove && /*#__PURE__*/React.createElement(RemoveButton, {
94
131
  style: btnStyle,
95
132
  disabled: disabled || readonly,
96
- onClick: onDropIndexClick(index)
133
+ onClick: onDropIndexClick(index),
134
+ uiSchema: uiSchema,
135
+ registry: registry
97
136
  })));
98
- };
99
-
100
- const ArrayFieldTemplate = props => {
101
- const {
102
- canAdd,
103
- disabled,
104
- idSchema,
105
- uiSchema,
106
- items,
107
- onAddClick,
108
- readonly,
109
- registry,
110
- required,
111
- schema,
112
- title
113
- } = props;
114
- const uiOptions = getUiOptions(uiSchema);
115
- const ArrayFieldDescriptionTemplate = getTemplate("ArrayFieldDescriptionTemplate", registry, uiOptions);
116
- const ArrayFieldItemTemplate = getTemplate("ArrayFieldItemTemplate", registry, uiOptions);
117
- const ArrayFieldTitleTemplate = getTemplate("ArrayFieldTitleTemplate", registry, uiOptions); // Button templates are not overridden in the uiSchema
137
+ }
118
138
 
119
- const {
120
- ButtonTemplates: {
121
- AddButton
122
- }
123
- } = registry.templates;
139
+ var _excluded$3 = ["key"];
140
+ /** The `ArrayFieldTemplate` component is the template used to render all items in an array.
141
+ *
142
+ * @param props - The `ArrayFieldTemplateItemType` props for the component
143
+ */
144
+ function ArrayFieldTemplate(props) {
145
+ var canAdd = props.canAdd,
146
+ disabled = props.disabled,
147
+ idSchema = props.idSchema,
148
+ uiSchema = props.uiSchema,
149
+ items = props.items,
150
+ onAddClick = props.onAddClick,
151
+ readonly = props.readonly,
152
+ registry = props.registry,
153
+ required = props.required,
154
+ schema = props.schema,
155
+ title = props.title;
156
+ var uiOptions = getUiOptions(uiSchema);
157
+ var ArrayFieldDescriptionTemplate = getTemplate("ArrayFieldDescriptionTemplate", registry, uiOptions);
158
+ var ArrayFieldItemTemplate = getTemplate("ArrayFieldItemTemplate", registry, uiOptions);
159
+ var ArrayFieldTitleTemplate = getTemplate("ArrayFieldTitleTemplate", registry, uiOptions);
160
+ // Button templates are not overridden in the uiSchema
161
+ var AddButton = registry.templates.ButtonTemplates.AddButton;
124
162
  return /*#__PURE__*/React.createElement(Paper, {
125
163
  elevation: 2
126
164
  }, /*#__PURE__*/React.createElement(Box, {
@@ -128,26 +166,25 @@ const ArrayFieldTemplate = props => {
128
166
  }, /*#__PURE__*/React.createElement(ArrayFieldTitleTemplate, {
129
167
  idSchema: idSchema,
130
168
  title: uiOptions.title || title,
169
+ schema: schema,
131
170
  uiSchema: uiSchema,
132
171
  required: required,
133
172
  registry: registry
134
- }), (uiOptions.description || schema.description) && /*#__PURE__*/React.createElement(ArrayFieldDescriptionTemplate, {
173
+ }), /*#__PURE__*/React.createElement(ArrayFieldDescriptionTemplate, {
135
174
  idSchema: idSchema,
136
175
  description: uiOptions.description || schema.description,
176
+ schema: schema,
137
177
  uiSchema: uiSchema,
138
178
  registry: registry
139
179
  }), /*#__PURE__*/React.createElement(Grid, {
140
180
  container: true,
141
181
  key: "array-item-list-" + idSchema.$id
142
- }, items && items.map(_ref => {
143
- let {
144
- key,
145
- ...itemProps
146
- } = _ref;
147
- return /*#__PURE__*/React.createElement(ArrayFieldItemTemplate, {
148
- key: key,
149
- ...itemProps
150
- });
182
+ }, items && items.map(function (_ref) {
183
+ var key = _ref.key,
184
+ itemProps = _objectWithoutPropertiesLoose(_ref, _excluded$3);
185
+ return /*#__PURE__*/React.createElement(ArrayFieldItemTemplate, _extends({
186
+ key: key
187
+ }, itemProps));
151
188
  }), canAdd && /*#__PURE__*/React.createElement(Grid, {
152
189
  container: true,
153
190
  justifyContent: "flex-end"
@@ -158,103 +195,102 @@ const ArrayFieldTemplate = props => {
158
195
  }, /*#__PURE__*/React.createElement(AddButton, {
159
196
  className: "array-item-add",
160
197
  onClick: onAddClick,
161
- disabled: disabled || readonly
198
+ disabled: disabled || readonly,
199
+ uiSchema: uiSchema,
200
+ registry: registry
162
201
  })))))));
163
- };
164
-
165
- const BaseInputTemplate = _ref => {
166
- let {
167
- id,
168
- placeholder,
169
- required,
170
- readonly,
171
- disabled,
172
- type,
173
- label,
174
- value,
175
- onChange,
176
- onBlur,
177
- onFocus,
178
- autofocus,
179
- options,
180
- schema,
181
- uiSchema,
182
- rawErrors = [],
183
- formContext,
184
- registry,
185
- ...textFieldProps
186
- } = _ref;
187
- const inputProps = getInputProps(schema, type, options); // Now we need to pull out the step, min, max into an inner `inputProps` for material-ui
188
-
189
- const {
190
- step,
191
- min,
192
- max,
193
- ...rest
194
- } = inputProps;
195
- const otherProps = {
196
- inputProps: {
197
- step,
198
- min,
199
- max
200
- },
201
- ...rest
202
- };
202
+ }
203
203
 
204
- const _onChange = _ref2 => {
205
- let {
206
- target: {
207
- value
208
- }
209
- } = _ref2;
204
+ var _excluded$2 = ["id", "placeholder", "required", "readonly", "disabled", "type", "label", "value", "onChange", "onBlur", "onFocus", "autofocus", "options", "schema", "uiSchema", "rawErrors", "formContext", "registry"],
205
+ _excluded2$1 = ["step", "min", "max"];
206
+ /** The `BaseInputTemplate` is the template to use to render the basic `<input>` component for the `core` theme.
207
+ * It is used as the template for rendering many of the <input> based widgets that differ by `type` and callbacks only.
208
+ * It can be customized/overridden for other themes or individual implementations as needed.
209
+ *
210
+ * @param props - The `WidgetProps` for this template
211
+ */
212
+ function BaseInputTemplate(props) {
213
+ var id = props.id,
214
+ placeholder = props.placeholder,
215
+ required = props.required,
216
+ readonly = props.readonly,
217
+ disabled = props.disabled,
218
+ type = props.type,
219
+ label = props.label,
220
+ value = props.value,
221
+ onChange = props.onChange,
222
+ onBlur = props.onBlur,
223
+ onFocus = props.onFocus,
224
+ autofocus = props.autofocus,
225
+ options = props.options,
226
+ schema = props.schema,
227
+ uiSchema = props.uiSchema,
228
+ _props$rawErrors = props.rawErrors,
229
+ rawErrors = _props$rawErrors === void 0 ? [] : _props$rawErrors,
230
+ registry = props.registry,
231
+ textFieldProps = _objectWithoutPropertiesLoose(props, _excluded$2);
232
+ var inputProps = getInputProps(schema, type, options);
233
+ // Now we need to pull out the step, min, max into an inner `inputProps` for material-ui
234
+ var step = inputProps.step,
235
+ min = inputProps.min,
236
+ max = inputProps.max,
237
+ rest = _objectWithoutPropertiesLoose(inputProps, _excluded2$1);
238
+ var otherProps = _extends({
239
+ inputProps: _extends({
240
+ step: step,
241
+ min: min,
242
+ max: max
243
+ }, schema.examples ? {
244
+ list: examplesId(id)
245
+ } : undefined)
246
+ }, rest);
247
+ var _onChange = function _onChange(_ref) {
248
+ var value = _ref.target.value;
210
249
  return onChange(value === "" ? options.emptyValue : value);
211
250
  };
212
-
213
- const _onBlur = _ref3 => {
214
- let {
215
- target: {
216
- value
217
- }
218
- } = _ref3;
251
+ var _onBlur = function _onBlur(_ref2) {
252
+ var value = _ref2.target.value;
219
253
  return onBlur(id, value);
220
254
  };
221
-
222
- const _onFocus = _ref4 => {
223
- let {
224
- target: {
225
- value
226
- }
227
- } = _ref4;
255
+ var _onFocus = function _onFocus(_ref3) {
256
+ var value = _ref3.target.value;
228
257
  return onFocus(id, value);
229
258
  };
230
-
231
- const {
232
- schemaUtils
233
- } = registry;
234
- const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema);
235
- return /*#__PURE__*/React.createElement(TextField, {
259
+ var schemaUtils = registry.schemaUtils;
260
+ var displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema);
261
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(TextField, _extends({
236
262
  id: id,
263
+ name: id,
237
264
  placeholder: placeholder,
238
265
  label: displayLabel ? label || schema.title : false,
239
266
  autoFocus: autofocus,
240
267
  required: required,
241
- disabled: disabled || readonly,
242
- ...otherProps,
268
+ disabled: disabled || readonly
269
+ }, otherProps, {
243
270
  value: value || value === 0 ? value : "",
244
271
  error: rawErrors.length > 0,
245
272
  onChange: _onChange,
246
273
  onBlur: _onBlur,
247
- onFocus: _onFocus,
248
- ...textFieldProps
249
- });
250
- };
251
-
252
- const DescriptionField = _ref => {
253
- let {
254
- description,
255
- id
256
- } = _ref;
274
+ onFocus: _onFocus
275
+ }, textFieldProps, {
276
+ "aria-describedby": ariaDescribedByIds(id, !!schema.examples)
277
+ })), Array.isArray(schema.examples) && /*#__PURE__*/React.createElement("datalist", {
278
+ id: examplesId(id)
279
+ }, schema.examples.concat(schema["default"] && !schema.examples.includes(schema["default"]) ? [schema["default"]] : []).map(function (example) {
280
+ return /*#__PURE__*/React.createElement("option", {
281
+ key: example,
282
+ value: example
283
+ });
284
+ })));
285
+ }
257
286
 
287
+ /** The `DescriptionField` is the template to use to render the description of a field
288
+ *
289
+ * @param props - The `DescriptionFieldProps` for this component
290
+ */
291
+ function DescriptionField(props) {
292
+ var id = props.id,
293
+ description = props.description;
258
294
  if (description) {
259
295
  return /*#__PURE__*/React.createElement(Typography, {
260
296
  id: id,
@@ -264,14 +300,15 @@ const DescriptionField = _ref => {
264
300
  }
265
301
  }, description);
266
302
  }
267
-
268
303
  return null;
269
- };
304
+ }
270
305
 
271
- const ErrorList = _ref => {
272
- let {
273
- errors
274
- } = _ref;
306
+ /** The `ErrorList` component is the template that renders the all the errors associated with the fields in the `Form`
307
+ *
308
+ * @param props - The `ErrorListProps` for this component
309
+ */
310
+ function ErrorList(_ref) {
311
+ var errors = _ref.errors;
275
312
  return /*#__PURE__*/React.createElement(Paper, {
276
313
  elevation: 2
277
314
  }, /*#__PURE__*/React.createElement(Box, {
@@ -281,7 +318,7 @@ const ErrorList = _ref => {
281
318
  variant: "h6"
282
319
  }, "Errors"), /*#__PURE__*/React.createElement(List, {
283
320
  dense: true
284
- }, errors.map((error, i) => {
321
+ }, errors.map(function (error, i) {
285
322
  return /*#__PURE__*/React.createElement(ListItem, {
286
323
  key: i
287
324
  }, /*#__PURE__*/React.createElement(ListItemIcon, null, /*#__PURE__*/React.createElement(ErrorIcon, {
@@ -290,144 +327,119 @@ const ErrorList = _ref => {
290
327
  primary: error.stack
291
328
  }));
292
329
  }))));
293
- };
330
+ }
294
331
 
332
+ var _excluded$1 = ["icon", "color", "uiSchema", "registry"],
333
+ _excluded2 = ["iconType"];
295
334
  function MuiIconButton(props) {
296
- const {
297
- icon,
298
- color,
299
- ...otherProps
300
- } = props;
301
- return /*#__PURE__*/React.createElement(IconButton, { ...otherProps,
335
+ var icon = props.icon,
336
+ color = props.color,
337
+ otherProps = _objectWithoutPropertiesLoose(props, _excluded$1);
338
+ return /*#__PURE__*/React.createElement(IconButton, _extends({}, otherProps, {
302
339
  size: "small",
303
340
  color: color
304
- }, icon);
341
+ }), icon);
305
342
  }
306
343
  function MoveDownButton(props) {
307
- return /*#__PURE__*/React.createElement(MuiIconButton, {
308
- title: "Move down",
309
- ...props,
344
+ return /*#__PURE__*/React.createElement(MuiIconButton, _extends({
345
+ title: "Move down"
346
+ }, props, {
310
347
  icon: /*#__PURE__*/React.createElement(ArrowDownwardIcon, {
311
348
  fontSize: "small"
312
349
  })
313
- });
350
+ }));
314
351
  }
315
352
  function MoveUpButton(props) {
316
- return /*#__PURE__*/React.createElement(MuiIconButton, {
317
- title: "Move up",
318
- ...props,
353
+ return /*#__PURE__*/React.createElement(MuiIconButton, _extends({
354
+ title: "Move up"
355
+ }, props, {
319
356
  icon: /*#__PURE__*/React.createElement(ArrowUpwardIcon, {
320
357
  fontSize: "small"
321
358
  })
322
- });
359
+ }));
323
360
  }
324
361
  function RemoveButton(props) {
325
- const {
326
- iconType,
327
- ...otherProps
328
- } = props;
329
- return /*#__PURE__*/React.createElement(MuiIconButton, {
330
- title: "Remove",
331
- ...otherProps,
362
+ var iconType = props.iconType,
363
+ otherProps = _objectWithoutPropertiesLoose(props, _excluded2);
364
+ return /*#__PURE__*/React.createElement(MuiIconButton, _extends({
365
+ title: "Remove"
366
+ }, otherProps, {
332
367
  color: "error",
333
368
  icon: /*#__PURE__*/React.createElement(RemoveIcon, {
334
369
  fontSize: iconType === "default" ? undefined : "small"
335
370
  })
336
- });
371
+ }));
337
372
  }
338
373
 
339
- const WrapIfAdditional = _ref => {
340
- let {
341
- children,
342
- classNames,
343
- disabled,
344
- id,
345
- label,
346
- onDropPropertyClick,
347
- onKeyChange,
348
- readonly,
349
- required,
350
- schema,
351
- registry
352
- } = _ref;
353
- const {
354
- RemoveButton
355
- } = registry.templates.ButtonTemplates;
356
- const keyLabel = label + " Key"; // i18n ?
357
-
358
- const additional = (ADDITIONAL_PROPERTY_FLAG in schema);
359
- const btnStyle = {
360
- flex: 1,
361
- paddingLeft: 6,
362
- paddingRight: 6,
363
- fontWeight: "bold"
364
- };
365
-
366
- if (!additional) {
367
- return /*#__PURE__*/React.createElement("div", {
368
- className: classNames
369
- }, children);
374
+ /** The `FieldErrorTemplate` component renders the errors local to the particular field
375
+ *
376
+ * @param props - The `FieldErrorProps` for the errors being rendered
377
+ */
378
+ function FieldErrorTemplate(props) {
379
+ var _props$errors = props.errors,
380
+ errors = _props$errors === void 0 ? [] : _props$errors,
381
+ idSchema = props.idSchema;
382
+ if (errors.length === 0) {
383
+ return null;
370
384
  }
385
+ var id = errorId(idSchema);
386
+ return /*#__PURE__*/React.createElement(List, {
387
+ dense: true,
388
+ disablePadding: true
389
+ }, errors.map(function (error, i) {
390
+ return /*#__PURE__*/React.createElement(ListItem, {
391
+ key: i,
392
+ disableGutters: true
393
+ }, /*#__PURE__*/React.createElement(FormHelperText, {
394
+ id: id
395
+ }, error));
396
+ }));
397
+ }
371
398
 
372
- const handleBlur = _ref2 => {
373
- let {
374
- target
375
- } = _ref2;
376
- return onKeyChange(target.value);
377
- };
378
-
379
- return /*#__PURE__*/React.createElement(Grid, {
380
- container: true,
381
- key: id + "-key",
382
- alignItems: "center",
383
- spacing: 2,
384
- className: classNames
385
- }, /*#__PURE__*/React.createElement(Grid, {
386
- item: true,
387
- xs: true
388
- }, /*#__PURE__*/React.createElement(FormControl, {
389
- fullWidth: true,
390
- required: required
391
- }, /*#__PURE__*/React.createElement(InputLabel, null, keyLabel), /*#__PURE__*/React.createElement(Input, {
392
- defaultValue: label,
393
- disabled: disabled || readonly,
394
- id: id + "-key",
395
- name: id + "-key",
396
- onBlur: !readonly ? handleBlur : undefined,
397
- type: "text"
398
- }))), /*#__PURE__*/React.createElement(Grid, {
399
- item: true,
400
- xs: true
401
- }, children), /*#__PURE__*/React.createElement(Grid, {
402
- item: true
403
- }, /*#__PURE__*/React.createElement(RemoveButton, {
404
- iconType: "default",
405
- style: btnStyle,
406
- disabled: disabled || readonly,
407
- onClick: onDropPropertyClick(label)
408
- })));
409
- };
410
-
411
- const FieldTemplate = _ref => {
412
- let {
413
- id,
414
- children,
415
- classNames,
416
- disabled,
417
- displayLabel,
418
- hidden,
419
- label,
420
- onDropPropertyClick,
421
- onKeyChange,
422
- readonly,
423
- required,
424
- rawErrors = [],
425
- rawHelp,
426
- rawDescription,
427
- schema,
428
- registry
429
- } = _ref;
399
+ /** The `FieldHelpTemplate` component renders any help desired for a field
400
+ *
401
+ * @param props - The `FieldHelpProps` to be rendered
402
+ */
403
+ function FieldHelpTemplate(props) {
404
+ var idSchema = props.idSchema,
405
+ help = props.help;
406
+ if (!help) {
407
+ return null;
408
+ }
409
+ var id = helpId(idSchema);
410
+ return /*#__PURE__*/React.createElement(FormHelperText, {
411
+ id: id
412
+ }, help);
413
+ }
430
414
 
415
+ /** The `FieldTemplate` component is the template used by `SchemaField` to render any field. It renders the field
416
+ * content, (label, description, children, errors and help) inside of a `WrapIfAdditional` component.
417
+ *
418
+ * @param props - The `FieldTemplateProps` for this component
419
+ */
420
+ function FieldTemplate(props) {
421
+ var id = props.id,
422
+ children = props.children,
423
+ classNames = props.classNames,
424
+ style = props.style,
425
+ disabled = props.disabled,
426
+ displayLabel = props.displayLabel,
427
+ hidden = props.hidden,
428
+ label = props.label,
429
+ onDropPropertyClick = props.onDropPropertyClick,
430
+ onKeyChange = props.onKeyChange,
431
+ readonly = props.readonly,
432
+ required = props.required,
433
+ _props$rawErrors = props.rawErrors,
434
+ rawErrors = _props$rawErrors === void 0 ? [] : _props$rawErrors,
435
+ errors = props.errors,
436
+ help = props.help,
437
+ rawDescription = props.rawDescription,
438
+ schema = props.schema,
439
+ uiSchema = props.uiSchema,
440
+ registry = props.registry;
441
+ var uiOptions = getUiOptions(uiSchema);
442
+ var WrapIfAdditionalTemplate = getTemplate("WrapIfAdditionalTemplate", registry, uiOptions);
431
443
  if (hidden) {
432
444
  return /*#__PURE__*/React.createElement("div", {
433
445
  style: {
@@ -435,9 +447,9 @@ const FieldTemplate = _ref => {
435
447
  }
436
448
  }, children);
437
449
  }
438
-
439
- return /*#__PURE__*/React.createElement(WrapIfAdditional, {
450
+ return /*#__PURE__*/React.createElement(WrapIfAdditionalTemplate, {
440
451
  classNames: classNames,
452
+ style: style,
441
453
  disabled: disabled,
442
454
  id: id,
443
455
  label: label,
@@ -446,6 +458,7 @@ const FieldTemplate = _ref => {
446
458
  readonly: readonly,
447
459
  required: required,
448
460
  schema: schema,
461
+ uiSchema: uiSchema,
449
462
  registry: registry
450
463
  }, /*#__PURE__*/React.createElement(FormControl, {
451
464
  fullWidth: true,
@@ -454,54 +467,45 @@ const FieldTemplate = _ref => {
454
467
  }, children, displayLabel && rawDescription ? /*#__PURE__*/React.createElement(Typography, {
455
468
  variant: "caption",
456
469
  color: "textSecondary"
457
- }, rawDescription) : null, rawErrors.length > 0 && /*#__PURE__*/React.createElement(List, {
458
- dense: true,
459
- disablePadding: true
460
- }, rawErrors.map((error, i) => {
461
- return /*#__PURE__*/React.createElement(ListItem, {
462
- key: i,
463
- disableGutters: true
464
- }, /*#__PURE__*/React.createElement(FormHelperText, {
465
- id: id
466
- }, error));
467
- })), rawHelp && /*#__PURE__*/React.createElement(FormHelperText, {
468
- id: id
469
- }, rawHelp)));
470
- };
471
-
472
- const ObjectFieldTemplate = _ref => {
473
- let {
474
- description,
475
- title,
476
- properties,
477
- required,
478
- disabled,
479
- readonly,
480
- uiSchema,
481
- idSchema,
482
- schema,
483
- formData,
484
- onAddClick,
485
- registry
486
- } = _ref;
487
- const uiOptions = getUiOptions(uiSchema);
488
- const TitleFieldTemplate = getTemplate("TitleFieldTemplate", registry, uiOptions);
489
- const DescriptionFieldTemplate = getTemplate("DescriptionFieldTemplate", registry, uiOptions); // Button templates are not overridden in the uiSchema
470
+ }, rawDescription) : null, errors, help));
471
+ }
490
472
 
491
- const {
492
- ButtonTemplates: {
493
- AddButton
494
- }
495
- } = registry.templates;
473
+ /** The `ObjectFieldTemplate` is the template to use to render all the inner properties of an object along with the
474
+ * title and description if available. If the object is expandable, then an `AddButton` is also rendered after all
475
+ * the properties.
476
+ *
477
+ * @param props - The `ObjectFieldTemplateProps` for this component
478
+ */
479
+ function ObjectFieldTemplate(props) {
480
+ var description = props.description,
481
+ title = props.title,
482
+ properties = props.properties,
483
+ required = props.required,
484
+ disabled = props.disabled,
485
+ readonly = props.readonly,
486
+ uiSchema = props.uiSchema,
487
+ idSchema = props.idSchema,
488
+ schema = props.schema,
489
+ formData = props.formData,
490
+ onAddClick = props.onAddClick,
491
+ registry = props.registry;
492
+ var uiOptions = getUiOptions(uiSchema);
493
+ var TitleFieldTemplate = getTemplate("TitleFieldTemplate", registry, uiOptions);
494
+ var DescriptionFieldTemplate = getTemplate("DescriptionFieldTemplate", registry, uiOptions);
495
+ // Button templates are not overridden in the uiSchema
496
+ var AddButton = registry.templates.ButtonTemplates.AddButton;
496
497
  return /*#__PURE__*/React.createElement(React.Fragment, null, (uiOptions.title || title) && /*#__PURE__*/React.createElement(TitleFieldTemplate, {
497
- id: idSchema.$id + "-title",
498
+ id: titleId(idSchema),
498
499
  title: title,
499
500
  required: required,
501
+ schema: schema,
500
502
  uiSchema: uiSchema,
501
503
  registry: registry
502
504
  }), (uiOptions.description || description) && /*#__PURE__*/React.createElement(DescriptionFieldTemplate, {
503
- id: idSchema.$id + "-description",
505
+ id: descriptionId(idSchema),
504
506
  description: uiOptions.description || description,
507
+ schema: schema,
508
+ uiSchema: uiSchema,
505
509
  registry: registry
506
510
  }), /*#__PURE__*/React.createElement(Grid, {
507
511
  container: true,
@@ -509,16 +513,20 @@ const ObjectFieldTemplate = _ref => {
509
513
  style: {
510
514
  marginTop: "10px"
511
515
  }
512
- }, properties.map((element, index) => // Remove the <Grid> if the inner element is hidden as the <Grid>
513
- // itself would otherwise still take up space.
514
- element.hidden ? element.content : /*#__PURE__*/React.createElement(Grid, {
515
- item: true,
516
- xs: 12,
517
- key: index,
518
- style: {
519
- marginBottom: "10px"
520
- }
521
- }, element.content)), canExpand(schema, uiSchema, formData) && /*#__PURE__*/React.createElement(Grid, {
516
+ }, properties.map(function (element, index) {
517
+ return (
518
+ // Remove the <Grid> if the inner element is hidden as the <Grid>
519
+ // itself would otherwise still take up space.
520
+ element.hidden ? element.content : /*#__PURE__*/React.createElement(Grid, {
521
+ item: true,
522
+ xs: 12,
523
+ key: index,
524
+ style: {
525
+ marginBottom: "10px"
526
+ }
527
+ }, element.content)
528
+ );
529
+ }), canExpand(schema, uiSchema, formData) && /*#__PURE__*/React.createElement(Grid, {
522
530
  container: true,
523
531
  justifyContent: "flex-end"
524
532
  }, /*#__PURE__*/React.createElement(Grid, {
@@ -526,36 +534,40 @@ const ObjectFieldTemplate = _ref => {
526
534
  }, /*#__PURE__*/React.createElement(AddButton, {
527
535
  className: "object-property-expand",
528
536
  onClick: onAddClick(schema),
529
- disabled: disabled || readonly
537
+ disabled: disabled || readonly,
538
+ uiSchema: uiSchema,
539
+ registry: registry
530
540
  })))));
531
- };
532
-
533
- const SubmitButton = props => {
534
- const {
535
- submitText,
536
- norender,
537
- props: submitButtonProps
538
- } = getSubmitButtonOptions(props.uiSchema);
541
+ }
539
542
 
543
+ /** The `SubmitButton` renders a button that represent the `Submit` action on a form
544
+ */
545
+ function SubmitButton(_ref) {
546
+ var uiSchema = _ref.uiSchema;
547
+ var _getSubmitButtonOptio = getSubmitButtonOptions(uiSchema),
548
+ submitText = _getSubmitButtonOptio.submitText,
549
+ norender = _getSubmitButtonOptio.norender,
550
+ _getSubmitButtonOptio2 = _getSubmitButtonOptio.props,
551
+ submitButtonProps = _getSubmitButtonOptio2 === void 0 ? {} : _getSubmitButtonOptio2;
540
552
  if (norender) {
541
553
  return null;
542
554
  }
543
-
544
555
  return /*#__PURE__*/React.createElement(Box, {
545
556
  marginTop: 3
546
- }, /*#__PURE__*/React.createElement(Button, {
557
+ }, /*#__PURE__*/React.createElement(Button, _extends({
547
558
  type: "submit",
548
559
  variant: "contained",
549
- color: "primary",
550
- ...submitButtonProps
551
- }, submitText));
552
- };
560
+ color: "primary"
561
+ }, submitButtonProps), submitText));
562
+ }
553
563
 
554
- const TitleField = _ref => {
555
- let {
556
- id,
557
- title
558
- } = _ref;
564
+ /** The `TitleField` is the template to use to render the title of a field
565
+ *
566
+ * @param props - The `TitleFieldProps` for this component
567
+ */
568
+ function TitleField(_ref) {
569
+ var id = _ref.id,
570
+ title = _ref.title;
559
571
  return /*#__PURE__*/React.createElement(Box, {
560
572
  id: id,
561
573
  mb: 1,
@@ -563,454 +575,491 @@ const TitleField = _ref => {
563
575
  }, /*#__PURE__*/React.createElement(Typography, {
564
576
  variant: "h5"
565
577
  }, title), /*#__PURE__*/React.createElement(Divider, null));
566
- };
578
+ }
567
579
 
568
- var Templates = {
569
- ArrayFieldItemTemplate,
570
- ArrayFieldTemplate,
571
- BaseInputTemplate,
572
- ButtonTemplates: {
573
- AddButton,
574
- MoveDownButton,
575
- MoveUpButton,
576
- RemoveButton,
577
- SubmitButton
578
- },
579
- DescriptionFieldTemplate: DescriptionField,
580
- ErrorListTemplate: ErrorList,
581
- FieldTemplate,
582
- ObjectFieldTemplate,
583
- TitleFieldTemplate: TitleField
584
- };
580
+ /** The `WrapIfAdditional` component is used by the `FieldTemplate` to rename, or remove properties that are
581
+ * part of an `additionalProperties` part of a schema.
582
+ *
583
+ * @param props - The `WrapIfAdditionalProps` for this component
584
+ */
585
+ function WrapIfAdditionalTemplate(props) {
586
+ var children = props.children,
587
+ classNames = props.classNames,
588
+ style = props.style,
589
+ disabled = props.disabled,
590
+ id = props.id,
591
+ label = props.label,
592
+ onDropPropertyClick = props.onDropPropertyClick,
593
+ onKeyChange = props.onKeyChange,
594
+ readonly = props.readonly,
595
+ required = props.required,
596
+ schema = props.schema,
597
+ uiSchema = props.uiSchema,
598
+ registry = props.registry;
599
+ // Button templates are not overridden in the uiSchema
600
+ var RemoveButton = registry.templates.ButtonTemplates.RemoveButton;
601
+ var keyLabel = label + " Key"; // i18n ?
602
+ var additional = (ADDITIONAL_PROPERTY_FLAG in schema);
603
+ var btnStyle = {
604
+ flex: 1,
605
+ paddingLeft: 6,
606
+ paddingRight: 6,
607
+ fontWeight: "bold"
608
+ };
609
+ if (!additional) {
610
+ return /*#__PURE__*/React.createElement("div", {
611
+ className: classNames,
612
+ style: style
613
+ }, children);
614
+ }
615
+ var handleBlur = function handleBlur(_ref) {
616
+ var target = _ref.target;
617
+ return onKeyChange(target.value);
618
+ };
619
+ return /*#__PURE__*/React.createElement(Grid, {
620
+ container: true,
621
+ key: id + "-key",
622
+ alignItems: "center",
623
+ spacing: 2,
624
+ className: classNames,
625
+ style: style
626
+ }, /*#__PURE__*/React.createElement(Grid, {
627
+ item: true,
628
+ xs: true
629
+ }, /*#__PURE__*/React.createElement(FormControl, {
630
+ fullWidth: true,
631
+ required: required
632
+ }, /*#__PURE__*/React.createElement(InputLabel, null, keyLabel), /*#__PURE__*/React.createElement(Input, {
633
+ defaultValue: label,
634
+ disabled: disabled || readonly,
635
+ id: id + "-key",
636
+ name: id + "-key",
637
+ onBlur: !readonly ? handleBlur : undefined,
638
+ type: "text"
639
+ }))), /*#__PURE__*/React.createElement(Grid, {
640
+ item: true,
641
+ xs: true
642
+ }, children), /*#__PURE__*/React.createElement(Grid, {
643
+ item: true
644
+ }, /*#__PURE__*/React.createElement(RemoveButton, {
645
+ iconType: "default",
646
+ style: btnStyle,
647
+ disabled: disabled || readonly,
648
+ onClick: onDropPropertyClick(label),
649
+ uiSchema: uiSchema,
650
+ registry: registry
651
+ })));
652
+ }
585
653
 
586
- const CheckboxWidget = props => {
587
- const {
588
- schema,
589
- id,
590
- value,
591
- disabled,
592
- readonly,
593
- label,
594
- autofocus,
595
- onChange,
596
- onBlur,
597
- onFocus
598
- } = props; // Because an unchecked checkbox will cause html5 validation to fail, only add
654
+ function generateTemplates() {
655
+ return {
656
+ ArrayFieldItemTemplate: ArrayFieldItemTemplate,
657
+ ArrayFieldTemplate: ArrayFieldTemplate,
658
+ BaseInputTemplate: BaseInputTemplate,
659
+ ButtonTemplates: {
660
+ AddButton: AddButton,
661
+ MoveDownButton: MoveDownButton,
662
+ MoveUpButton: MoveUpButton,
663
+ RemoveButton: RemoveButton,
664
+ SubmitButton: SubmitButton
665
+ },
666
+ DescriptionFieldTemplate: DescriptionField,
667
+ ErrorListTemplate: ErrorList,
668
+ FieldErrorTemplate: FieldErrorTemplate,
669
+ FieldHelpTemplate: FieldHelpTemplate,
670
+ FieldTemplate: FieldTemplate,
671
+ ObjectFieldTemplate: ObjectFieldTemplate,
672
+ TitleFieldTemplate: TitleField,
673
+ WrapIfAdditionalTemplate: WrapIfAdditionalTemplate
674
+ };
675
+ }
676
+ var Templates = /*#__PURE__*/generateTemplates();
677
+
678
+ /** The `CheckBoxWidget` is a widget for rendering boolean properties.
679
+ * It is typically used to represent a boolean.
680
+ *
681
+ * @param props - The `WidgetProps` for this component
682
+ */
683
+ function CheckboxWidget(props) {
684
+ var schema = props.schema,
685
+ id = props.id,
686
+ value = props.value,
687
+ disabled = props.disabled,
688
+ readonly = props.readonly,
689
+ label = props.label,
690
+ autofocus = props.autofocus,
691
+ onChange = props.onChange,
692
+ onBlur = props.onBlur,
693
+ onFocus = props.onFocus;
694
+ // Because an unchecked checkbox will cause html5 validation to fail, only add
599
695
  // the "required" attribute if the field value must be "true", due to the
600
696
  // "const" or "enum" keywords
601
-
602
- const required = schemaRequiresTrueValue(schema);
603
-
604
- const _onChange = (_, checked) => onChange(checked);
605
-
606
- const _onBlur = _ref => {
607
- let {
608
- target: {
609
- value
610
- }
611
- } = _ref;
697
+ var required = schemaRequiresTrueValue(schema);
698
+ var _onChange = function _onChange(_, checked) {
699
+ return onChange(checked);
700
+ };
701
+ var _onBlur = function _onBlur(_ref) {
702
+ var value = _ref.target.value;
612
703
  return onBlur(id, value);
613
704
  };
614
-
615
- const _onFocus = _ref2 => {
616
- let {
617
- target: {
618
- value
619
- }
620
- } = _ref2;
705
+ var _onFocus = function _onFocus(_ref2) {
706
+ var value = _ref2.target.value;
621
707
  return onFocus(id, value);
622
708
  };
623
-
624
709
  return /*#__PURE__*/React.createElement(FormControlLabel, {
625
710
  control: /*#__PURE__*/React.createElement(Checkbox, {
626
711
  id: id,
712
+ name: id,
627
713
  checked: typeof value === "undefined" ? false : Boolean(value),
628
714
  required: required,
629
715
  disabled: disabled || readonly,
630
716
  autoFocus: autofocus,
631
717
  onChange: _onChange,
632
718
  onBlur: _onBlur,
633
- onFocus: _onFocus
719
+ onFocus: _onFocus,
720
+ "aria-describedby": ariaDescribedByIds(id)
634
721
  }),
635
722
  label: label || ""
636
723
  });
637
- };
638
-
639
- const selectValue = (value, selected, all) => {
640
- const at = all.indexOf(value);
641
- const updated = selected.slice(0, at).concat(value, selected.slice(at)); // As inserting values at predefined index positions doesn't work with empty
642
- // arrays, we need to reorder the updated selection to match the initial order
643
-
644
- return updated.sort((a, b) => all.indexOf(a) > all.indexOf(b));
645
- };
646
-
647
- const deselectValue = (value, selected) => {
648
- return selected.filter(v => v !== value);
649
- };
650
-
651
- const CheckboxesWidget = _ref => {
652
- let {
653
- schema,
654
- label,
655
- id,
656
- disabled,
657
- options,
658
- value,
659
- autofocus,
660
- readonly,
661
- required,
662
- onChange,
663
- onBlur,
664
- onFocus
665
- } = _ref;
666
- const {
667
- enumOptions,
668
- enumDisabled,
669
- inline
670
- } = options;
724
+ }
671
725
 
672
- const _onChange = option => _ref2 => {
673
- let {
674
- target: {
675
- checked
726
+ /** The `CheckboxesWidget` is a widget for rendering checkbox groups.
727
+ * It is typically used to represent an array of enums.
728
+ *
729
+ * @param props - The `WidgetProps` for this component
730
+ */
731
+ function CheckboxesWidget(_ref) {
732
+ var schema = _ref.schema,
733
+ label = _ref.label,
734
+ id = _ref.id,
735
+ disabled = _ref.disabled,
736
+ options = _ref.options,
737
+ value = _ref.value,
738
+ autofocus = _ref.autofocus,
739
+ readonly = _ref.readonly,
740
+ required = _ref.required,
741
+ onChange = _ref.onChange,
742
+ onBlur = _ref.onBlur,
743
+ onFocus = _ref.onFocus;
744
+ var enumOptions = options.enumOptions,
745
+ enumDisabled = options.enumDisabled,
746
+ inline = options.inline;
747
+ var checkboxesValues = Array.isArray(value) ? value : [value];
748
+ var _onChange = function _onChange(option) {
749
+ return function (_ref2) {
750
+ var checked = _ref2.target.checked;
751
+ if (checked) {
752
+ onChange(enumOptionsSelectValue(option.value, checkboxesValues, enumOptions));
753
+ } else {
754
+ onChange(enumOptionsDeselectValue(option.value, checkboxesValues));
676
755
  }
677
- } = _ref2;
678
- const all = enumOptions.map(_ref3 => {
679
- let {
680
- value
681
- } = _ref3;
682
- return value;
683
- });
684
-
685
- if (checked) {
686
- onChange(selectValue(option.value, value, all));
687
- } else {
688
- onChange(deselectValue(option.value, value));
689
- }
756
+ };
690
757
  };
691
-
692
- const _onBlur = _ref4 => {
693
- let {
694
- target: {
695
- value
696
- }
697
- } = _ref4;
758
+ var _onBlur = function _onBlur(_ref3) {
759
+ var value = _ref3.target.value;
698
760
  return onBlur(id, value);
699
761
  };
700
-
701
- const _onFocus = _ref5 => {
702
- let {
703
- target: {
704
- value
705
- }
706
- } = _ref5;
762
+ var _onFocus = function _onFocus(_ref4) {
763
+ var value = _ref4.target.value;
707
764
  return onFocus(id, value);
708
765
  };
709
-
710
766
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(FormLabel, {
711
767
  required: required,
712
768
  htmlFor: id
713
769
  }, label || schema.title), /*#__PURE__*/React.createElement(FormGroup, {
714
770
  id: id,
715
771
  row: !!inline
716
- }, enumOptions.map((option, index) => {
717
- const checked = value.indexOf(option.value) !== -1;
718
- const itemDisabled = enumDisabled && enumDisabled.indexOf(option.value) != -1;
719
- const checkbox = /*#__PURE__*/React.createElement(Checkbox, {
720
- id: id + "_" + index,
772
+ }, Array.isArray(enumOptions) && enumOptions.map(function (option, index) {
773
+ var checked = checkboxesValues.includes(option.value);
774
+ var itemDisabled = Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) !== -1;
775
+ var checkbox = /*#__PURE__*/React.createElement(Checkbox, {
776
+ id: optionId(id, option),
777
+ name: id,
721
778
  checked: checked,
722
779
  disabled: disabled || itemDisabled || readonly,
723
780
  autoFocus: autofocus && index === 0,
724
781
  onChange: _onChange(option),
725
782
  onBlur: _onBlur,
726
- onFocus: _onFocus
783
+ onFocus: _onFocus,
784
+ "aria-describedby": ariaDescribedByIds(id)
727
785
  });
728
786
  return /*#__PURE__*/React.createElement(FormControlLabel, {
729
787
  control: checkbox,
730
- key: index,
788
+ key: option.value,
731
789
  label: option.label
732
790
  });
733
791
  })));
734
- };
792
+ }
735
793
 
736
- const DateWidget = props => {
737
- const {
738
- options,
739
- registry
740
- } = props;
741
- const BaseInputTemplate = getTemplate("BaseInputTemplate", registry, options);
742
- return /*#__PURE__*/React.createElement(BaseInputTemplate, {
794
+ /** The `DateWidget` component uses the `BaseInputTemplate` changing the type to `date` and transforms
795
+ * the value to undefined when it is falsy during the `onChange` handling.
796
+ *
797
+ * @param props - The `WidgetProps` for this component
798
+ */
799
+ function DateWidget(props) {
800
+ var options = props.options,
801
+ registry = props.registry;
802
+ var BaseInputTemplate = getTemplate("BaseInputTemplate", registry, options);
803
+ return /*#__PURE__*/React.createElement(BaseInputTemplate, _extends({
743
804
  type: "date",
744
805
  InputLabelProps: {
745
806
  shrink: true
746
- },
747
- ...props
748
- });
749
- };
750
-
751
- const DateTimeWidget = props => {
752
- const {
753
- options,
754
- registry
755
- } = props;
756
- const BaseInputTemplate = getTemplate("BaseInputTemplate", registry, options);
757
- const value = utcToLocal(props.value);
807
+ }
808
+ }, props));
809
+ }
758
810
 
759
- const onChange = value => {
811
+ /** The `DateTimeWidget` component uses the `BaseInputTemplate` changing the type to `datetime-local` and transforms
812
+ * the value to/from utc using the appropriate utility functions.
813
+ *
814
+ * @param props - The `WidgetProps` for this component
815
+ */
816
+ function DateTimeWidget(props) {
817
+ var options = props.options,
818
+ registry = props.registry;
819
+ var BaseInputTemplate = getTemplate("BaseInputTemplate", registry, options);
820
+ var value = utcToLocal(props.value);
821
+ var onChange = function onChange(value) {
760
822
  props.onChange(localToUTC(value));
761
823
  };
762
-
763
- return /*#__PURE__*/React.createElement(BaseInputTemplate, {
824
+ return /*#__PURE__*/React.createElement(BaseInputTemplate, _extends({
764
825
  type: "datetime-local",
765
826
  InputLabelProps: {
766
827
  shrink: true
767
- },
768
- ...props,
828
+ }
829
+ }, props, {
769
830
  value: value,
770
831
  onChange: onChange
771
- });
772
- };
773
-
774
- const RadioWidget = _ref => {
775
- let {
776
- id,
777
- schema,
778
- options,
779
- value,
780
- required,
781
- disabled,
782
- readonly,
783
- label,
784
- onChange,
785
- onBlur,
786
- onFocus
787
- } = _ref;
788
- const {
789
- enumOptions,
790
- enumDisabled
791
- } = options;
792
-
793
- const _onChange = (_, value) => onChange(schema.type == "boolean" ? value !== "false" : value);
832
+ }));
833
+ }
794
834
 
795
- const _onBlur = _ref2 => {
796
- let {
797
- target: {
798
- value
799
- }
800
- } = _ref2;
835
+ /** The `RadioWidget` is a widget for rendering a radio group.
836
+ * It is typically used with a string property constrained with enum options.
837
+ *
838
+ * @param props - The `WidgetProps` for this component
839
+ */
840
+ function RadioWidget(_ref) {
841
+ var id = _ref.id,
842
+ schema = _ref.schema,
843
+ options = _ref.options,
844
+ value = _ref.value,
845
+ required = _ref.required,
846
+ disabled = _ref.disabled,
847
+ readonly = _ref.readonly,
848
+ label = _ref.label,
849
+ onChange = _ref.onChange,
850
+ onBlur = _ref.onBlur,
851
+ onFocus = _ref.onFocus;
852
+ var enumOptions = options.enumOptions,
853
+ enumDisabled = options.enumDisabled;
854
+ var _onChange = function _onChange(_, value) {
855
+ return onChange(schema.type == "boolean" ? value !== "false" : value);
856
+ };
857
+ var _onBlur = function _onBlur(_ref2) {
858
+ var value = _ref2.target.value;
801
859
  return onBlur(id, value);
802
860
  };
803
-
804
- const _onFocus = _ref3 => {
805
- let {
806
- target: {
807
- value
808
- }
809
- } = _ref3;
861
+ var _onFocus = function _onFocus(_ref3) {
862
+ var value = _ref3.target.value;
810
863
  return onFocus(id, value);
811
864
  };
812
-
813
- const row = options ? options.inline : false;
865
+ var row = options ? options.inline : false;
814
866
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(FormLabel, {
815
867
  required: required,
816
868
  htmlFor: id
817
869
  }, label || schema.title), /*#__PURE__*/React.createElement(RadioGroup, {
818
870
  id: id,
871
+ name: id,
819
872
  value: "" + value,
820
873
  row: row,
821
874
  onChange: _onChange,
822
875
  onBlur: _onBlur,
823
- onFocus: _onFocus
824
- }, enumOptions.map((option, i) => {
825
- const itemDisabled = enumDisabled && enumDisabled.indexOf(option.value) != -1;
826
- const radio = /*#__PURE__*/React.createElement(FormControlLabel, {
876
+ onFocus: _onFocus,
877
+ "aria-describedby": ariaDescribedByIds(id)
878
+ }, Array.isArray(enumOptions) && enumOptions.map(function (option) {
879
+ var itemDisabled = Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) !== -1;
880
+ var radio = /*#__PURE__*/React.createElement(FormControlLabel, {
827
881
  control: /*#__PURE__*/React.createElement(Radio, {
828
- name: id + "-" + i,
829
- color: "primary",
830
- key: i
882
+ name: id,
883
+ id: optionId(id, option),
884
+ color: "primary"
831
885
  }),
832
886
  label: "" + option.label,
833
887
  value: "" + option.value,
834
- key: i,
888
+ key: option.value,
835
889
  disabled: disabled || itemDisabled || readonly
836
890
  });
837
891
  return radio;
838
892
  })));
839
- };
840
-
841
- const RangeWidget = _ref => {
842
- let {
843
- value,
844
- readonly,
845
- disabled,
846
- onBlur,
847
- onFocus,
848
- options,
849
- schema,
850
- onChange,
851
- required,
852
- label,
853
- id
854
- } = _ref;
855
- const sliderProps = {
856
- value,
857
- label,
858
- id,
859
- ...rangeSpec(schema)
860
- };
893
+ }
861
894
 
862
- const _onChange = (_, value) => {
863
- onChange(value ? options.emptyValue : value);
895
+ /** The `RangeWidget` component uses the `BaseInputTemplate` changing the type to `range` and wrapping the result
896
+ * in a div, with the value along side it.
897
+ *
898
+ * @param props - The `WidgetProps` for this component
899
+ */
900
+ function RangeWidget(props) {
901
+ var value = props.value,
902
+ readonly = props.readonly,
903
+ disabled = props.disabled,
904
+ onBlur = props.onBlur,
905
+ onFocus = props.onFocus,
906
+ options = props.options,
907
+ schema = props.schema,
908
+ onChange = props.onChange,
909
+ required = props.required,
910
+ label = props.label,
911
+ id = props.id;
912
+ var sliderProps = _extends({
913
+ value: value,
914
+ label: label,
915
+ id: id,
916
+ name: id
917
+ }, rangeSpec(schema));
918
+ var _onChange = function _onChange(_, value) {
919
+ onChange(value ? value : options.emptyValue);
864
920
  };
865
-
866
- const _onBlur = _ref2 => {
867
- let {
868
- target: {
869
- value
870
- }
871
- } = _ref2;
921
+ var _onBlur = function _onBlur(_ref) {
922
+ var value = _ref.target.value;
872
923
  return onBlur(id, value);
873
924
  };
874
-
875
- const _onFocus = _ref3 => {
876
- let {
877
- target: {
878
- value
879
- }
880
- } = _ref3;
925
+ var _onFocus = function _onFocus(_ref2) {
926
+ var value = _ref2.target.value;
881
927
  return onFocus(id, value);
882
928
  };
883
-
884
929
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(FormLabel, {
885
930
  required: required,
886
- id: id
887
- }, label), /*#__PURE__*/React.createElement(Slider, {
931
+ htmlFor: id
932
+ }, label || schema.title), /*#__PURE__*/React.createElement(Slider, _extends({
888
933
  disabled: disabled || readonly,
889
934
  onChange: _onChange,
890
935
  onBlur: _onBlur,
891
936
  onFocus: _onFocus,
892
- valueLabelDisplay: "auto",
893
- ...sliderProps
894
- }));
895
- };
896
-
897
- const SelectWidget = _ref => {
898
- let {
899
- schema,
900
- id,
901
- options,
902
- label,
903
- required,
904
- disabled,
905
- readonly,
906
- value,
907
- multiple,
908
- autofocus,
909
- onChange,
910
- onBlur,
911
- onFocus,
912
- rawErrors = []
913
- } = _ref;
914
- const {
915
- enumOptions,
916
- enumDisabled
917
- } = options;
918
- const emptyValue = multiple ? [] : "";
937
+ valueLabelDisplay: "auto"
938
+ }, sliderProps, {
939
+ "aria-describedby": ariaDescribedByIds(id)
940
+ })));
941
+ }
919
942
 
920
- const _onChange = _ref2 => {
921
- let {
922
- target: {
923
- value
924
- }
925
- } = _ref2;
943
+ var _excluded = ["schema", "id", "options", "label", "required", "disabled", "placeholder", "readonly", "value", "multiple", "autofocus", "onChange", "onBlur", "onFocus", "rawErrors", "registry", "uiSchema", "hideError", "formContext"];
944
+ /** The `SelectWidget` is a widget for rendering dropdowns.
945
+ * It is typically used with string properties constrained with enum options.
946
+ *
947
+ * @param props - The `WidgetProps` for this component
948
+ */
949
+ function SelectWidget(_ref) {
950
+ var schema = _ref.schema,
951
+ id = _ref.id,
952
+ options = _ref.options,
953
+ label = _ref.label,
954
+ required = _ref.required,
955
+ disabled = _ref.disabled,
956
+ placeholder = _ref.placeholder,
957
+ readonly = _ref.readonly,
958
+ value = _ref.value,
959
+ multiple = _ref.multiple,
960
+ autofocus = _ref.autofocus,
961
+ onChange = _ref.onChange,
962
+ onBlur = _ref.onBlur,
963
+ onFocus = _ref.onFocus,
964
+ _ref$rawErrors = _ref.rawErrors,
965
+ rawErrors = _ref$rawErrors === void 0 ? [] : _ref$rawErrors,
966
+ textFieldProps = _objectWithoutPropertiesLoose(_ref, _excluded);
967
+ var enumOptions = options.enumOptions,
968
+ enumDisabled = options.enumDisabled;
969
+ multiple = typeof multiple === "undefined" ? false : !!multiple;
970
+ var emptyValue = multiple ? [] : "";
971
+ var isEmpty = typeof value === "undefined" || multiple && value.length < 1 || !multiple && value === emptyValue;
972
+ var _onChange = function _onChange(_ref2) {
973
+ var value = _ref2.target.value;
926
974
  return onChange(processSelectValue(schema, value, options));
927
975
  };
928
-
929
- const _onBlur = _ref3 => {
930
- let {
931
- target: {
932
- value
933
- }
934
- } = _ref3;
976
+ var _onBlur = function _onBlur(_ref3) {
977
+ var value = _ref3.target.value;
935
978
  return onBlur(id, processSelectValue(schema, value, options));
936
979
  };
937
-
938
- const _onFocus = _ref4 => {
939
- let {
940
- target: {
941
- value
942
- }
943
- } = _ref4;
980
+ var _onFocus = function _onFocus(_ref4) {
981
+ var value = _ref4.target.value;
944
982
  return onFocus(id, processSelectValue(schema, value, options));
945
983
  };
946
-
947
- return /*#__PURE__*/React.createElement(TextField, {
984
+ return /*#__PURE__*/React.createElement(TextField, _extends({
948
985
  id: id,
986
+ name: id,
949
987
  label: label || schema.title,
950
- select: true,
951
- value: typeof value === "undefined" ? emptyValue : value,
988
+ value: isEmpty ? emptyValue : value,
952
989
  required: required,
953
990
  disabled: disabled || readonly,
954
991
  autoFocus: autofocus,
992
+ placeholder: placeholder,
955
993
  error: rawErrors.length > 0,
956
994
  onChange: _onChange,
957
995
  onBlur: _onBlur,
958
- onFocus: _onFocus,
959
- InputLabelProps: {
960
- shrink: true
961
- },
962
- SelectProps: {
963
- multiple: typeof multiple === "undefined" ? false : multiple
964
- }
965
- }, enumOptions.map((_ref5, i) => {
966
- let {
967
- value,
968
- label
969
- } = _ref5;
970
- const disabled = enumDisabled && enumDisabled.indexOf(value) != -1;
996
+ onFocus: _onFocus
997
+ }, textFieldProps, {
998
+ select // Apply this and the following props after the potential overrides defined in textFieldProps
999
+ : true,
1000
+ InputLabelProps: _extends({}, textFieldProps.InputLabelProps, {
1001
+ shrink: !isEmpty
1002
+ }),
1003
+ SelectProps: _extends({}, textFieldProps.SelectProps, {
1004
+ multiple: multiple
1005
+ }),
1006
+ "aria-describedby": ariaDescribedByIds(id)
1007
+ }), enumOptions.map(function (_ref5, i) {
1008
+ var value = _ref5.value,
1009
+ label = _ref5.label;
1010
+ var disabled = enumDisabled && enumDisabled.indexOf(value) != -1;
971
1011
  return /*#__PURE__*/React.createElement(MenuItem, {
972
1012
  key: i,
973
1013
  value: value,
974
1014
  disabled: disabled
975
1015
  }, label);
976
1016
  }));
977
- };
978
-
979
- const TextareaWidget = props => {
980
- const {
981
- options,
982
- registry
983
- } = props;
984
- const BaseInputTemplate = getTemplate("BaseInputTemplate", registry, options);
985
- let rows = 5;
1017
+ }
986
1018
 
1019
+ /** The `TextareaWidget` is a widget for rendering input fields as textarea.
1020
+ *
1021
+ * @param props - The `WidgetProps` for this component
1022
+ */
1023
+ function TextareaWidget(props) {
1024
+ var options = props.options,
1025
+ registry = props.registry;
1026
+ var BaseInputTemplate = getTemplate("BaseInputTemplate", registry, options);
1027
+ var rows = 5;
987
1028
  if (typeof options.rows === "string" || typeof options.rows === "number") {
988
1029
  rows = options.rows;
989
1030
  }
990
-
991
- return /*#__PURE__*/React.createElement(BaseInputTemplate, { ...props,
1031
+ return /*#__PURE__*/React.createElement(BaseInputTemplate, _extends({}, props, {
992
1032
  multiline: true,
993
1033
  rows: rows
994
- });
995
- };
1034
+ }));
1035
+ }
996
1036
 
997
- var Widgets = {
998
- CheckboxWidget,
999
- CheckboxesWidget,
1000
- DateWidget,
1001
- DateTimeWidget,
1002
- RadioWidget,
1003
- RangeWidget,
1004
- SelectWidget,
1005
- TextareaWidget
1006
- };
1037
+ function generateWidgets() {
1038
+ return {
1039
+ CheckboxWidget: CheckboxWidget,
1040
+ CheckboxesWidget: CheckboxesWidget,
1041
+ DateWidget: DateWidget,
1042
+ DateTimeWidget: DateTimeWidget,
1043
+ RadioWidget: RadioWidget,
1044
+ RangeWidget: RangeWidget,
1045
+ SelectWidget: SelectWidget,
1046
+ TextareaWidget: TextareaWidget
1047
+ };
1048
+ }
1049
+ var Widgets = /*#__PURE__*/generateWidgets();
1007
1050
 
1008
- const Theme = {
1009
- templates: Templates,
1010
- widgets: Widgets
1011
- };
1051
+ function generateTheme() {
1052
+ return {
1053
+ templates: generateTemplates(),
1054
+ widgets: generateWidgets()
1055
+ };
1056
+ }
1057
+ var Theme = /*#__PURE__*/generateTheme();
1012
1058
 
1013
- const MuiForm = /*#__PURE__*/withTheme(Theme);
1059
+ function generateForm() {
1060
+ return withTheme(generateTheme());
1061
+ }
1062
+ var MuiForm = /*#__PURE__*/generateForm();
1014
1063
 
1015
- export { MuiForm as Form, Templates, Theme, Widgets, MuiForm as default };
1064
+ export { MuiForm as Form, Templates, Theme, Widgets, MuiForm as default, generateForm, generateTemplates, generateTheme, generateWidgets };
1016
1065
  //# sourceMappingURL=mui.esm.js.map