@rjsf/mui 5.0.0-beta.8 → 5.0.0

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.
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, enumOptionsIsSelected, optionId, enumOptionsSelectValue, enumOptionsDeselectValue, enumOptionsValueForIndex, utcToLocal, localToUTC, enumOptionsIndexForValue, rangeSpec } 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';
@@ -18,10 +18,10 @@ import ArrowUpwardIcon from '@mui/icons-material/ArrowUpward';
18
18
  import RemoveIcon from '@mui/icons-material/Remove';
19
19
  import FormHelperText from '@mui/material/FormHelperText';
20
20
  import FormControl from '@mui/material/FormControl';
21
- import InputLabel from '@mui/material/InputLabel';
22
- import Input from '@mui/material/OutlinedInput';
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,113 +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
- ...(schema.examples ? {
201
- list: "examples_" + id
202
- } : undefined)
203
- },
204
- ...rest
205
- };
202
+ }
206
203
 
207
- const _onChange = _ref2 => {
208
- let {
209
- target: {
210
- value
211
- }
212
- } = _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;
213
249
  return onChange(value === "" ? options.emptyValue : value);
214
250
  };
215
-
216
- const _onBlur = _ref3 => {
217
- let {
218
- target: {
219
- value
220
- }
221
- } = _ref3;
251
+ var _onBlur = function _onBlur(_ref2) {
252
+ var value = _ref2.target.value;
222
253
  return onBlur(id, value);
223
254
  };
224
-
225
- const _onFocus = _ref4 => {
226
- let {
227
- target: {
228
- value
229
- }
230
- } = _ref4;
255
+ var _onFocus = function _onFocus(_ref3) {
256
+ var value = _ref3.target.value;
231
257
  return onFocus(id, value);
232
258
  };
233
-
234
- const {
235
- schemaUtils
236
- } = registry;
237
- const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema);
238
- return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__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({
239
262
  id: id,
263
+ name: id,
240
264
  placeholder: placeholder,
241
265
  label: displayLabel ? label || schema.title : false,
242
266
  autoFocus: autofocus,
243
267
  required: required,
244
- disabled: disabled || readonly,
245
- ...otherProps,
268
+ disabled: disabled || readonly
269
+ }, otherProps, {
246
270
  value: value || value === 0 ? value : "",
247
271
  error: rawErrors.length > 0,
248
272
  onChange: _onChange,
249
273
  onBlur: _onBlur,
250
- onFocus: _onFocus,
251
- ...textFieldProps
252
- }), schema.examples && /*#__PURE__*/React.createElement("datalist", {
253
- id: "examples_" + id
254
- }, schema.examples.concat(schema.default ? [schema.default] : []).map(example => {
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) {
255
280
  return /*#__PURE__*/React.createElement("option", {
256
281
  key: example,
257
282
  value: example
258
283
  });
259
284
  })));
260
- };
261
-
262
- const DescriptionField = _ref => {
263
- let {
264
- description,
265
- id
266
- } = _ref;
285
+ }
267
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;
268
294
  if (description) {
269
295
  return /*#__PURE__*/React.createElement(Typography, {
270
296
  id: id,
@@ -274,14 +300,15 @@ const DescriptionField = _ref => {
274
300
  }
275
301
  }, description);
276
302
  }
277
-
278
303
  return null;
279
- };
304
+ }
280
305
 
281
- const ErrorList = _ref => {
282
- let {
283
- errors
284
- } = _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;
285
312
  return /*#__PURE__*/React.createElement(Paper, {
286
313
  elevation: 2
287
314
  }, /*#__PURE__*/React.createElement(Box, {
@@ -291,7 +318,7 @@ const ErrorList = _ref => {
291
318
  variant: "h6"
292
319
  }, "Errors"), /*#__PURE__*/React.createElement(List, {
293
320
  dense: true
294
- }, errors.map((error, i) => {
321
+ }, errors.map(function (error, i) {
295
322
  return /*#__PURE__*/React.createElement(ListItem, {
296
323
  key: i
297
324
  }, /*#__PURE__*/React.createElement(ListItemIcon, null, /*#__PURE__*/React.createElement(ErrorIcon, {
@@ -300,72 +327,66 @@ const ErrorList = _ref => {
300
327
  primary: error.stack
301
328
  }));
302
329
  }))));
303
- };
330
+ }
304
331
 
332
+ var _excluded$1 = ["icon", "color", "uiSchema", "registry"],
333
+ _excluded2 = ["iconType"];
305
334
  function MuiIconButton(props) {
306
- const {
307
- icon,
308
- color,
309
- ...otherProps
310
- } = props;
311
- 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, {
312
339
  size: "small",
313
340
  color: color
314
- }, icon);
341
+ }), icon);
315
342
  }
316
343
  function MoveDownButton(props) {
317
- return /*#__PURE__*/React.createElement(MuiIconButton, {
318
- title: "Move down",
319
- ...props,
344
+ return /*#__PURE__*/React.createElement(MuiIconButton, _extends({
345
+ title: "Move down"
346
+ }, props, {
320
347
  icon: /*#__PURE__*/React.createElement(ArrowDownwardIcon, {
321
348
  fontSize: "small"
322
349
  })
323
- });
350
+ }));
324
351
  }
325
352
  function MoveUpButton(props) {
326
- return /*#__PURE__*/React.createElement(MuiIconButton, {
327
- title: "Move up",
328
- ...props,
353
+ return /*#__PURE__*/React.createElement(MuiIconButton, _extends({
354
+ title: "Move up"
355
+ }, props, {
329
356
  icon: /*#__PURE__*/React.createElement(ArrowUpwardIcon, {
330
357
  fontSize: "small"
331
358
  })
332
- });
359
+ }));
333
360
  }
334
361
  function RemoveButton(props) {
335
- const {
336
- iconType,
337
- ...otherProps
338
- } = props;
339
- return /*#__PURE__*/React.createElement(MuiIconButton, {
340
- title: "Remove",
341
- ...otherProps,
362
+ var iconType = props.iconType,
363
+ otherProps = _objectWithoutPropertiesLoose(props, _excluded2);
364
+ return /*#__PURE__*/React.createElement(MuiIconButton, _extends({
365
+ title: "Remove"
366
+ }, otherProps, {
342
367
  color: "error",
343
368
  icon: /*#__PURE__*/React.createElement(RemoveIcon, {
344
369
  fontSize: iconType === "default" ? undefined : "small"
345
370
  })
346
- });
371
+ }));
347
372
  }
348
373
 
349
374
  /** The `FieldErrorTemplate` component renders the errors local to the particular field
350
375
  *
351
376
  * @param props - The `FieldErrorProps` for the errors being rendered
352
377
  */
353
-
354
378
  function FieldErrorTemplate(props) {
355
- const {
356
- errors = [],
357
- idSchema
358
- } = props;
359
-
379
+ var _props$errors = props.errors,
380
+ errors = _props$errors === void 0 ? [] : _props$errors,
381
+ idSchema = props.idSchema;
360
382
  if (errors.length === 0) {
361
383
  return null;
362
384
  }
363
-
364
- const id = idSchema.$id + "__error";
385
+ var id = errorId(idSchema);
365
386
  return /*#__PURE__*/React.createElement(List, {
366
387
  dense: true,
367
388
  disablePadding: true
368
- }, errors.map((error, i) => {
389
+ }, errors.map(function (error, i) {
369
390
  return /*#__PURE__*/React.createElement(ListItem, {
370
391
  key: i,
371
392
  disableGutters: true
@@ -379,116 +400,46 @@ function FieldErrorTemplate(props) {
379
400
  *
380
401
  * @param props - The `FieldHelpProps` to be rendered
381
402
  */
382
-
383
403
  function FieldHelpTemplate(props) {
384
- const {
385
- idSchema,
386
- help
387
- } = props;
388
-
404
+ var idSchema = props.idSchema,
405
+ help = props.help;
389
406
  if (!help) {
390
407
  return null;
391
408
  }
392
-
393
- const id = idSchema.$id + "__help";
409
+ var id = helpId(idSchema);
394
410
  return /*#__PURE__*/React.createElement(FormHelperText, {
395
411
  id: id
396
412
  }, help);
397
413
  }
398
414
 
399
- const WrapIfAdditional = _ref => {
400
- let {
401
- children,
402
- classNames,
403
- disabled,
404
- id,
405
- label,
406
- onDropPropertyClick,
407
- onKeyChange,
408
- readonly,
409
- required,
410
- schema,
411
- registry
412
- } = _ref;
413
- const {
414
- RemoveButton
415
- } = registry.templates.ButtonTemplates;
416
- const keyLabel = label + " Key"; // i18n ?
417
-
418
- const additional = (ADDITIONAL_PROPERTY_FLAG in schema);
419
- const btnStyle = {
420
- flex: 1,
421
- paddingLeft: 6,
422
- paddingRight: 6,
423
- fontWeight: "bold"
424
- };
425
-
426
- if (!additional) {
427
- return /*#__PURE__*/React.createElement("div", {
428
- className: classNames
429
- }, children);
430
- }
431
-
432
- const handleBlur = _ref2 => {
433
- let {
434
- target
435
- } = _ref2;
436
- return onKeyChange(target.value);
437
- };
438
-
439
- return /*#__PURE__*/React.createElement(Grid, {
440
- container: true,
441
- key: id + "-key",
442
- alignItems: "center",
443
- spacing: 2,
444
- className: classNames
445
- }, /*#__PURE__*/React.createElement(Grid, {
446
- item: true,
447
- xs: true
448
- }, /*#__PURE__*/React.createElement(FormControl, {
449
- fullWidth: true,
450
- required: required
451
- }, /*#__PURE__*/React.createElement(InputLabel, null, keyLabel), /*#__PURE__*/React.createElement(Input, {
452
- defaultValue: label,
453
- disabled: disabled || readonly,
454
- id: id + "-key",
455
- name: id + "-key",
456
- onBlur: !readonly ? handleBlur : undefined,
457
- type: "text"
458
- }))), /*#__PURE__*/React.createElement(Grid, {
459
- item: true,
460
- xs: true
461
- }, children), /*#__PURE__*/React.createElement(Grid, {
462
- item: true
463
- }, /*#__PURE__*/React.createElement(RemoveButton, {
464
- iconType: "default",
465
- style: btnStyle,
466
- disabled: disabled || readonly,
467
- onClick: onDropPropertyClick(label)
468
- })));
469
- };
470
-
471
- const FieldTemplate = _ref => {
472
- let {
473
- id,
474
- children,
475
- classNames,
476
- disabled,
477
- displayLabel,
478
- hidden,
479
- label,
480
- onDropPropertyClick,
481
- onKeyChange,
482
- readonly,
483
- required,
484
- rawErrors = [],
485
- errors,
486
- help,
487
- rawDescription,
488
- schema,
489
- registry
490
- } = _ref;
491
-
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);
492
443
  if (hidden) {
493
444
  return /*#__PURE__*/React.createElement("div", {
494
445
  style: {
@@ -496,9 +447,9 @@ const FieldTemplate = _ref => {
496
447
  }
497
448
  }, children);
498
449
  }
499
-
500
- return /*#__PURE__*/React.createElement(WrapIfAdditional, {
450
+ return /*#__PURE__*/React.createElement(WrapIfAdditionalTemplate, {
501
451
  classNames: classNames,
452
+ style: style,
502
453
  disabled: disabled,
503
454
  id: id,
504
455
  label: label,
@@ -507,6 +458,7 @@ const FieldTemplate = _ref => {
507
458
  readonly: readonly,
508
459
  required: required,
509
460
  schema: schema,
461
+ uiSchema: uiSchema,
510
462
  registry: registry
511
463
  }, /*#__PURE__*/React.createElement(FormControl, {
512
464
  fullWidth: true,
@@ -516,41 +468,44 @@ const FieldTemplate = _ref => {
516
468
  variant: "caption",
517
469
  color: "textSecondary"
518
470
  }, rawDescription) : null, errors, help));
519
- };
520
-
521
- const ObjectFieldTemplate = _ref => {
522
- let {
523
- description,
524
- title,
525
- properties,
526
- required,
527
- disabled,
528
- readonly,
529
- uiSchema,
530
- idSchema,
531
- schema,
532
- formData,
533
- onAddClick,
534
- registry
535
- } = _ref;
536
- const uiOptions = getUiOptions(uiSchema);
537
- const TitleFieldTemplate = getTemplate("TitleFieldTemplate", registry, uiOptions);
538
- const DescriptionFieldTemplate = getTemplate("DescriptionFieldTemplate", registry, uiOptions); // Button templates are not overridden in the uiSchema
471
+ }
539
472
 
540
- const {
541
- ButtonTemplates: {
542
- AddButton
543
- }
544
- } = 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;
545
497
  return /*#__PURE__*/React.createElement(React.Fragment, null, (uiOptions.title || title) && /*#__PURE__*/React.createElement(TitleFieldTemplate, {
546
- id: idSchema.$id + "-title",
498
+ id: titleId(idSchema),
547
499
  title: title,
548
500
  required: required,
501
+ schema: schema,
549
502
  uiSchema: uiSchema,
550
503
  registry: registry
551
504
  }), (uiOptions.description || description) && /*#__PURE__*/React.createElement(DescriptionFieldTemplate, {
552
- id: idSchema.$id + "-description",
505
+ id: descriptionId(idSchema),
553
506
  description: uiOptions.description || description,
507
+ schema: schema,
508
+ uiSchema: uiSchema,
554
509
  registry: registry
555
510
  }), /*#__PURE__*/React.createElement(Grid, {
556
511
  container: true,
@@ -558,16 +513,20 @@ const ObjectFieldTemplate = _ref => {
558
513
  style: {
559
514
  marginTop: "10px"
560
515
  }
561
- }, properties.map((element, index) => // Remove the <Grid> if the inner element is hidden as the <Grid>
562
- // itself would otherwise still take up space.
563
- element.hidden ? element.content : /*#__PURE__*/React.createElement(Grid, {
564
- item: true,
565
- xs: 12,
566
- key: index,
567
- style: {
568
- marginBottom: "10px"
569
- }
570
- }, 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, {
571
530
  container: true,
572
531
  justifyContent: "flex-end"
573
532
  }, /*#__PURE__*/React.createElement(Grid, {
@@ -575,36 +534,40 @@ const ObjectFieldTemplate = _ref => {
575
534
  }, /*#__PURE__*/React.createElement(AddButton, {
576
535
  className: "object-property-expand",
577
536
  onClick: onAddClick(schema),
578
- disabled: disabled || readonly
537
+ disabled: disabled || readonly,
538
+ uiSchema: uiSchema,
539
+ registry: registry
579
540
  })))));
580
- };
581
-
582
- const SubmitButton = props => {
583
- const {
584
- submitText,
585
- norender,
586
- props: submitButtonProps
587
- } = getSubmitButtonOptions(props.uiSchema);
541
+ }
588
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;
589
552
  if (norender) {
590
553
  return null;
591
554
  }
592
-
593
555
  return /*#__PURE__*/React.createElement(Box, {
594
556
  marginTop: 3
595
- }, /*#__PURE__*/React.createElement(Button, {
557
+ }, /*#__PURE__*/React.createElement(Button, _extends({
596
558
  type: "submit",
597
559
  variant: "contained",
598
- color: "primary",
599
- ...submitButtonProps
600
- }, submitText));
601
- };
560
+ color: "primary"
561
+ }, submitButtonProps), submitText));
562
+ }
602
563
 
603
- const TitleField = _ref => {
604
- let {
605
- id,
606
- title
607
- } = _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;
608
571
  return /*#__PURE__*/React.createElement(Box, {
609
572
  id: id,
610
573
  mb: 1,
@@ -612,169 +575,214 @@ const TitleField = _ref => {
612
575
  }, /*#__PURE__*/React.createElement(Typography, {
613
576
  variant: "h5"
614
577
  }, title), /*#__PURE__*/React.createElement(Divider, null));
615
- };
578
+ }
579
+
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
+ }
616
653
 
617
- var Templates = {
618
- ArrayFieldItemTemplate,
619
- ArrayFieldTemplate,
620
- BaseInputTemplate,
621
- ButtonTemplates: {
622
- AddButton,
623
- MoveDownButton,
624
- MoveUpButton,
625
- RemoveButton,
626
- SubmitButton
627
- },
628
- DescriptionFieldTemplate: DescriptionField,
629
- ErrorListTemplate: ErrorList,
630
- FieldErrorTemplate,
631
- FieldHelpTemplate,
632
- FieldTemplate,
633
- ObjectFieldTemplate,
634
- TitleFieldTemplate: TitleField
635
- };
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();
636
677
 
637
- const CheckboxWidget = props => {
638
- const {
639
- schema,
640
- id,
641
- value,
642
- disabled,
643
- readonly,
644
- label,
645
- autofocus,
646
- onChange,
647
- onBlur,
648
- onFocus
649
- } = props; // Because an unchecked checkbox will cause html5 validation to fail, only add
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
650
695
  // the "required" attribute if the field value must be "true", due to the
651
696
  // "const" or "enum" keywords
652
-
653
- const required = schemaRequiresTrueValue(schema);
654
-
655
- const _onChange = (_, checked) => onChange(checked);
656
-
657
- const _onBlur = _ref => {
658
- let {
659
- target: {
660
- value
661
- }
662
- } = _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;
663
703
  return onBlur(id, value);
664
704
  };
665
-
666
- const _onFocus = _ref2 => {
667
- let {
668
- target: {
669
- value
670
- }
671
- } = _ref2;
705
+ var _onFocus = function _onFocus(_ref2) {
706
+ var value = _ref2.target.value;
672
707
  return onFocus(id, value);
673
708
  };
674
-
675
709
  return /*#__PURE__*/React.createElement(FormControlLabel, {
676
710
  control: /*#__PURE__*/React.createElement(Checkbox, {
677
711
  id: id,
712
+ name: id,
678
713
  checked: typeof value === "undefined" ? false : Boolean(value),
679
714
  required: required,
680
715
  disabled: disabled || readonly,
681
716
  autoFocus: autofocus,
682
717
  onChange: _onChange,
683
718
  onBlur: _onBlur,
684
- onFocus: _onFocus
719
+ onFocus: _onFocus,
720
+ "aria-describedby": ariaDescribedByIds(id)
685
721
  }),
686
722
  label: label || ""
687
723
  });
688
- };
689
-
690
- const selectValue = (value, selected, all) => {
691
- const at = all.indexOf(value);
692
- const updated = selected.slice(0, at).concat(value, selected.slice(at)); // As inserting values at predefined index positions doesn't work with empty
693
- // arrays, we need to reorder the updated selection to match the initial order
694
-
695
- return updated.sort((a, b) => all.indexOf(a) > all.indexOf(b));
696
- };
697
-
698
- const deselectValue = (value, selected) => {
699
- return selected.filter(v => v !== value);
700
- };
701
-
702
- const CheckboxesWidget = _ref => {
703
- let {
704
- schema,
705
- label,
706
- id,
707
- disabled,
708
- options,
709
- value,
710
- autofocus,
711
- readonly,
712
- required,
713
- onChange,
714
- onBlur,
715
- onFocus
716
- } = _ref;
717
- const {
718
- enumOptions,
719
- enumDisabled,
720
- inline
721
- } = options;
724
+ }
722
725
 
723
- const _onChange = option => _ref2 => {
724
- let {
725
- target: {
726
- 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
+ emptyValue = options.emptyValue;
748
+ var checkboxesValues = Array.isArray(value) ? value : [value];
749
+ var _onChange = function _onChange(index) {
750
+ return function (_ref2) {
751
+ var checked = _ref2.target.checked;
752
+ if (checked) {
753
+ onChange(enumOptionsSelectValue(index, checkboxesValues, enumOptions));
754
+ } else {
755
+ onChange(enumOptionsDeselectValue(index, checkboxesValues, enumOptions));
727
756
  }
728
- } = _ref2;
729
- const all = enumOptions.map(_ref3 => {
730
- let {
731
- value
732
- } = _ref3;
733
- return value;
734
- });
735
-
736
- if (checked) {
737
- onChange(selectValue(option.value, value, all));
738
- } else {
739
- onChange(deselectValue(option.value, value));
740
- }
757
+ };
741
758
  };
742
-
743
- const _onBlur = _ref4 => {
744
- let {
745
- target: {
746
- value
747
- }
748
- } = _ref4;
749
- return onBlur(id, value);
759
+ var _onBlur = function _onBlur(_ref3) {
760
+ var value = _ref3.target.value;
761
+ return onBlur(id, enumOptionsValueForIndex(value, enumOptions, emptyValue));
750
762
  };
751
-
752
- const _onFocus = _ref5 => {
753
- let {
754
- target: {
755
- value
756
- }
757
- } = _ref5;
758
- return onFocus(id, value);
763
+ var _onFocus = function _onFocus(_ref4) {
764
+ var value = _ref4.target.value;
765
+ return onFocus(id, enumOptionsValueForIndex(value, enumOptions, emptyValue));
759
766
  };
760
-
761
767
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(FormLabel, {
762
768
  required: required,
763
769
  htmlFor: id
764
770
  }, label || schema.title), /*#__PURE__*/React.createElement(FormGroup, {
765
771
  id: id,
766
772
  row: !!inline
767
- }, enumOptions.map((option, index) => {
768
- const checked = value.indexOf(option.value) !== -1;
769
- const itemDisabled = enumDisabled && enumDisabled.indexOf(option.value) != -1;
770
- const checkbox = /*#__PURE__*/React.createElement(Checkbox, {
771
- id: id + "_" + index,
773
+ }, Array.isArray(enumOptions) && enumOptions.map(function (option, index) {
774
+ var checked = enumOptionsIsSelected(option.value, checkboxesValues);
775
+ var itemDisabled = Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) !== -1;
776
+ var checkbox = /*#__PURE__*/React.createElement(Checkbox, {
777
+ id: optionId(id, index),
778
+ name: id,
772
779
  checked: checked,
773
780
  disabled: disabled || itemDisabled || readonly,
774
781
  autoFocus: autofocus && index === 0,
775
- onChange: _onChange(option),
782
+ onChange: _onChange(index),
776
783
  onBlur: _onBlur,
777
- onFocus: _onFocus
784
+ onFocus: _onFocus,
785
+ "aria-describedby": ariaDescribedByIds(id)
778
786
  });
779
787
  return /*#__PURE__*/React.createElement(FormControlLabel, {
780
788
  control: checkbox,
@@ -782,286 +790,281 @@ const CheckboxesWidget = _ref => {
782
790
  label: option.label
783
791
  });
784
792
  })));
785
- };
793
+ }
786
794
 
787
- const DateWidget = props => {
788
- const {
789
- options,
790
- registry
791
- } = props;
792
- const BaseInputTemplate = getTemplate("BaseInputTemplate", registry, options);
793
- return /*#__PURE__*/React.createElement(BaseInputTemplate, {
795
+ /** The `DateWidget` component uses the `BaseInputTemplate` changing the type to `date` and transforms
796
+ * the value to undefined when it is falsy during the `onChange` handling.
797
+ *
798
+ * @param props - The `WidgetProps` for this component
799
+ */
800
+ function DateWidget(props) {
801
+ var options = props.options,
802
+ registry = props.registry;
803
+ var BaseInputTemplate = getTemplate("BaseInputTemplate", registry, options);
804
+ return /*#__PURE__*/React.createElement(BaseInputTemplate, _extends({
794
805
  type: "date",
795
806
  InputLabelProps: {
796
807
  shrink: true
797
- },
798
- ...props
799
- });
800
- };
801
-
802
- const DateTimeWidget = props => {
803
- const {
804
- options,
805
- registry
806
- } = props;
807
- const BaseInputTemplate = getTemplate("BaseInputTemplate", registry, options);
808
- const value = utcToLocal(props.value);
808
+ }
809
+ }, props));
810
+ }
809
811
 
810
- const onChange = value => {
812
+ /** The `DateTimeWidget` component uses the `BaseInputTemplate` changing the type to `datetime-local` and transforms
813
+ * the value to/from utc using the appropriate utility functions.
814
+ *
815
+ * @param props - The `WidgetProps` for this component
816
+ */
817
+ function DateTimeWidget(props) {
818
+ var options = props.options,
819
+ registry = props.registry;
820
+ var BaseInputTemplate = getTemplate("BaseInputTemplate", registry, options);
821
+ var value = utcToLocal(props.value);
822
+ var onChange = function onChange(value) {
811
823
  props.onChange(localToUTC(value));
812
824
  };
813
-
814
- return /*#__PURE__*/React.createElement(BaseInputTemplate, {
825
+ return /*#__PURE__*/React.createElement(BaseInputTemplate, _extends({
815
826
  type: "datetime-local",
816
827
  InputLabelProps: {
817
828
  shrink: true
818
- },
819
- ...props,
829
+ }
830
+ }, props, {
820
831
  value: value,
821
832
  onChange: onChange
822
- });
823
- };
824
-
825
- const RadioWidget = _ref => {
826
- let {
827
- id,
828
- schema,
829
- options,
830
- value,
831
- required,
832
- disabled,
833
- readonly,
834
- label,
835
- onChange,
836
- onBlur,
837
- onFocus
838
- } = _ref;
839
- const {
840
- enumOptions,
841
- enumDisabled
842
- } = options;
843
-
844
- const _onChange = (_, value) => onChange(schema.type == "boolean" ? value !== "false" : value);
833
+ }));
834
+ }
845
835
 
846
- const _onBlur = _ref2 => {
847
- let {
848
- target: {
849
- value
850
- }
851
- } = _ref2;
852
- return onBlur(id, value);
836
+ /** The `RadioWidget` is a widget for rendering a radio group.
837
+ * It is typically used with a string property constrained with enum options.
838
+ *
839
+ * @param props - The `WidgetProps` for this component
840
+ */
841
+ function RadioWidget(_ref) {
842
+ var id = _ref.id,
843
+ schema = _ref.schema,
844
+ options = _ref.options,
845
+ value = _ref.value,
846
+ required = _ref.required,
847
+ disabled = _ref.disabled,
848
+ readonly = _ref.readonly,
849
+ label = _ref.label,
850
+ onChange = _ref.onChange,
851
+ onBlur = _ref.onBlur,
852
+ onFocus = _ref.onFocus;
853
+ var enumOptions = options.enumOptions,
854
+ enumDisabled = options.enumDisabled,
855
+ emptyValue = options.emptyValue;
856
+ var _onChange = function _onChange(_, value) {
857
+ return onChange(enumOptionsValueForIndex(value, enumOptions, emptyValue));
853
858
  };
854
-
855
- const _onFocus = _ref3 => {
856
- let {
857
- target: {
858
- value
859
- }
860
- } = _ref3;
861
- return onFocus(id, value);
859
+ var _onBlur = function _onBlur(_ref2) {
860
+ var value = _ref2.target.value;
861
+ return onBlur(id, enumOptionsValueForIndex(value, enumOptions, emptyValue));
862
862
  };
863
-
864
- const row = options ? options.inline : false;
863
+ var _onFocus = function _onFocus(_ref3) {
864
+ var value = _ref3.target.value;
865
+ return onFocus(id, enumOptionsValueForIndex(value, enumOptions, emptyValue));
866
+ };
867
+ var row = options ? options.inline : false;
868
+ var selectedIndex = enumOptionsIndexForValue(value, enumOptions);
865
869
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(FormLabel, {
866
870
  required: required,
867
871
  htmlFor: id
868
872
  }, label || schema.title), /*#__PURE__*/React.createElement(RadioGroup, {
869
873
  id: id,
870
- value: "" + value,
874
+ name: id,
875
+ value: selectedIndex,
871
876
  row: row,
872
877
  onChange: _onChange,
873
878
  onBlur: _onBlur,
874
- onFocus: _onFocus
875
- }, enumOptions.map((option, i) => {
876
- const itemDisabled = enumDisabled && enumDisabled.indexOf(option.value) != -1;
877
- const radio = /*#__PURE__*/React.createElement(FormControlLabel, {
879
+ onFocus: _onFocus,
880
+ "aria-describedby": ariaDescribedByIds(id)
881
+ }, Array.isArray(enumOptions) && enumOptions.map(function (option, index) {
882
+ var itemDisabled = Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) !== -1;
883
+ var radio = /*#__PURE__*/React.createElement(FormControlLabel, {
878
884
  control: /*#__PURE__*/React.createElement(Radio, {
879
- name: id + "-" + i,
880
- color: "primary",
881
- key: i
885
+ name: id,
886
+ id: optionId(id, index),
887
+ color: "primary"
882
888
  }),
883
- label: "" + option.label,
884
- value: "" + option.value,
885
- key: i,
889
+ label: option.label,
890
+ value: String(index),
891
+ key: index,
886
892
  disabled: disabled || itemDisabled || readonly
887
893
  });
888
894
  return radio;
889
895
  })));
890
- };
891
-
892
- const RangeWidget = _ref => {
893
- let {
894
- value,
895
- readonly,
896
- disabled,
897
- onBlur,
898
- onFocus,
899
- options,
900
- schema,
901
- onChange,
902
- required,
903
- label,
904
- id
905
- } = _ref;
906
- const sliderProps = {
907
- value,
908
- label,
909
- id,
910
- ...rangeSpec(schema)
911
- };
896
+ }
912
897
 
913
- const _onChange = (_, value) => {
914
- onChange(value ? options.emptyValue : value);
898
+ /** The `RangeWidget` component uses the `BaseInputTemplate` changing the type to `range` and wrapping the result
899
+ * in a div, with the value along side it.
900
+ *
901
+ * @param props - The `WidgetProps` for this component
902
+ */
903
+ function RangeWidget(props) {
904
+ var value = props.value,
905
+ readonly = props.readonly,
906
+ disabled = props.disabled,
907
+ onBlur = props.onBlur,
908
+ onFocus = props.onFocus,
909
+ options = props.options,
910
+ schema = props.schema,
911
+ onChange = props.onChange,
912
+ required = props.required,
913
+ label = props.label,
914
+ id = props.id;
915
+ var sliderProps = _extends({
916
+ value: value,
917
+ label: label,
918
+ id: id,
919
+ name: id
920
+ }, rangeSpec(schema));
921
+ var _onChange = function _onChange(_, value) {
922
+ onChange(value ? value : options.emptyValue);
915
923
  };
916
-
917
- const _onBlur = _ref2 => {
918
- let {
919
- target: {
920
- value
921
- }
922
- } = _ref2;
924
+ var _onBlur = function _onBlur(_ref) {
925
+ var value = _ref.target.value;
923
926
  return onBlur(id, value);
924
927
  };
925
-
926
- const _onFocus = _ref3 => {
927
- let {
928
- target: {
929
- value
930
- }
931
- } = _ref3;
928
+ var _onFocus = function _onFocus(_ref2) {
929
+ var value = _ref2.target.value;
932
930
  return onFocus(id, value);
933
931
  };
934
-
935
932
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(FormLabel, {
936
933
  required: required,
937
- id: id
938
- }, label), /*#__PURE__*/React.createElement(Slider, {
934
+ htmlFor: id
935
+ }, label || schema.title), /*#__PURE__*/React.createElement(Slider, _extends({
939
936
  disabled: disabled || readonly,
940
937
  onChange: _onChange,
941
938
  onBlur: _onBlur,
942
939
  onFocus: _onFocus,
943
- valueLabelDisplay: "auto",
944
- ...sliderProps
945
- }));
946
- };
947
-
948
- const SelectWidget = _ref => {
949
- let {
950
- schema,
951
- id,
952
- options,
953
- label,
954
- required,
955
- disabled,
956
- readonly,
957
- value,
958
- multiple,
959
- autofocus,
960
- onChange,
961
- onBlur,
962
- onFocus,
963
- rawErrors = []
964
- } = _ref;
965
- const {
966
- enumOptions,
967
- enumDisabled
968
- } = options;
969
- const emptyValue = multiple ? [] : "";
940
+ valueLabelDisplay: "auto"
941
+ }, sliderProps, {
942
+ "aria-describedby": ariaDescribedByIds(id)
943
+ })));
944
+ }
970
945
 
971
- const _onChange = _ref2 => {
972
- let {
973
- target: {
974
- value
975
- }
976
- } = _ref2;
977
- return onChange(processSelectValue(schema, value, options));
946
+ var _excluded = ["schema", "id", "options", "label", "required", "disabled", "placeholder", "readonly", "value", "multiple", "autofocus", "onChange", "onBlur", "onFocus", "rawErrors", "registry", "uiSchema", "hideError", "formContext"];
947
+ /** The `SelectWidget` is a widget for rendering dropdowns.
948
+ * It is typically used with string properties constrained with enum options.
949
+ *
950
+ * @param props - The `WidgetProps` for this component
951
+ */
952
+ function SelectWidget(_ref) {
953
+ var schema = _ref.schema,
954
+ id = _ref.id,
955
+ options = _ref.options,
956
+ label = _ref.label,
957
+ required = _ref.required,
958
+ disabled = _ref.disabled,
959
+ placeholder = _ref.placeholder,
960
+ readonly = _ref.readonly,
961
+ value = _ref.value,
962
+ multiple = _ref.multiple,
963
+ autofocus = _ref.autofocus,
964
+ onChange = _ref.onChange,
965
+ onBlur = _ref.onBlur,
966
+ onFocus = _ref.onFocus,
967
+ _ref$rawErrors = _ref.rawErrors,
968
+ rawErrors = _ref$rawErrors === void 0 ? [] : _ref$rawErrors,
969
+ textFieldProps = _objectWithoutPropertiesLoose(_ref, _excluded);
970
+ var enumOptions = options.enumOptions,
971
+ enumDisabled = options.enumDisabled,
972
+ optEmptyVal = options.emptyValue;
973
+ multiple = typeof multiple === "undefined" ? false : !!multiple;
974
+ var emptyValue = multiple ? [] : "";
975
+ var isEmpty = typeof value === "undefined" || multiple && value.length < 1 || !multiple && value === emptyValue;
976
+ var _onChange = function _onChange(_ref2) {
977
+ var value = _ref2.target.value;
978
+ return onChange(enumOptionsValueForIndex(value, enumOptions, optEmptyVal));
978
979
  };
979
-
980
- const _onBlur = _ref3 => {
981
- let {
982
- target: {
983
- value
984
- }
985
- } = _ref3;
986
- return onBlur(id, processSelectValue(schema, value, options));
980
+ var _onBlur = function _onBlur(_ref3) {
981
+ var value = _ref3.target.value;
982
+ return onBlur(id, enumOptionsValueForIndex(value, enumOptions, optEmptyVal));
987
983
  };
988
-
989
- const _onFocus = _ref4 => {
990
- let {
991
- target: {
992
- value
993
- }
994
- } = _ref4;
995
- return onFocus(id, processSelectValue(schema, value, options));
984
+ var _onFocus = function _onFocus(_ref4) {
985
+ var value = _ref4.target.value;
986
+ return onFocus(id, enumOptionsValueForIndex(value, enumOptions, optEmptyVal));
996
987
  };
997
-
998
- return /*#__PURE__*/React.createElement(TextField, {
988
+ var selectedIndexes = enumOptionsIndexForValue(value, enumOptions, multiple);
989
+ return /*#__PURE__*/React.createElement(TextField, _extends({
999
990
  id: id,
991
+ name: id,
1000
992
  label: label || schema.title,
1001
- select: true,
1002
- value: typeof value === "undefined" ? emptyValue : value,
993
+ value: isEmpty ? emptyValue : selectedIndexes,
1003
994
  required: required,
1004
995
  disabled: disabled || readonly,
1005
996
  autoFocus: autofocus,
997
+ placeholder: placeholder,
1006
998
  error: rawErrors.length > 0,
1007
999
  onChange: _onChange,
1008
1000
  onBlur: _onBlur,
1009
- onFocus: _onFocus,
1010
- InputLabelProps: {
1011
- shrink: true
1012
- },
1013
- SelectProps: {
1014
- multiple: typeof multiple === "undefined" ? false : multiple
1015
- }
1016
- }, enumOptions.map((_ref5, i) => {
1017
- let {
1018
- value,
1019
- label
1020
- } = _ref5;
1021
- const disabled = enumDisabled && enumDisabled.indexOf(value) != -1;
1001
+ onFocus: _onFocus
1002
+ }, textFieldProps, {
1003
+ select // Apply this and the following props after the potential overrides defined in textFieldProps
1004
+ : true,
1005
+ InputLabelProps: _extends({}, textFieldProps.InputLabelProps, {
1006
+ shrink: !isEmpty
1007
+ }),
1008
+ SelectProps: _extends({}, textFieldProps.SelectProps, {
1009
+ multiple: multiple
1010
+ }),
1011
+ "aria-describedby": ariaDescribedByIds(id)
1012
+ }), Array.isArray(enumOptions) && enumOptions.map(function (_ref5, i) {
1013
+ var value = _ref5.value,
1014
+ label = _ref5.label;
1015
+ var disabled = Array.isArray(enumDisabled) && enumDisabled.indexOf(value) !== -1;
1022
1016
  return /*#__PURE__*/React.createElement(MenuItem, {
1023
1017
  key: i,
1024
- value: value,
1018
+ value: String(i),
1025
1019
  disabled: disabled
1026
1020
  }, label);
1027
1021
  }));
1028
- };
1029
-
1030
- const TextareaWidget = props => {
1031
- const {
1032
- options,
1033
- registry
1034
- } = props;
1035
- const BaseInputTemplate = getTemplate("BaseInputTemplate", registry, options);
1036
- let rows = 5;
1022
+ }
1037
1023
 
1024
+ /** The `TextareaWidget` is a widget for rendering input fields as textarea.
1025
+ *
1026
+ * @param props - The `WidgetProps` for this component
1027
+ */
1028
+ function TextareaWidget(props) {
1029
+ var options = props.options,
1030
+ registry = props.registry;
1031
+ var BaseInputTemplate = getTemplate("BaseInputTemplate", registry, options);
1032
+ var rows = 5;
1038
1033
  if (typeof options.rows === "string" || typeof options.rows === "number") {
1039
1034
  rows = options.rows;
1040
1035
  }
1041
-
1042
- return /*#__PURE__*/React.createElement(BaseInputTemplate, { ...props,
1036
+ return /*#__PURE__*/React.createElement(BaseInputTemplate, _extends({}, props, {
1043
1037
  multiline: true,
1044
1038
  rows: rows
1045
- });
1046
- };
1039
+ }));
1040
+ }
1047
1041
 
1048
- var Widgets = {
1049
- CheckboxWidget,
1050
- CheckboxesWidget,
1051
- DateWidget,
1052
- DateTimeWidget,
1053
- RadioWidget,
1054
- RangeWidget,
1055
- SelectWidget,
1056
- TextareaWidget
1057
- };
1042
+ function generateWidgets() {
1043
+ return {
1044
+ CheckboxWidget: CheckboxWidget,
1045
+ CheckboxesWidget: CheckboxesWidget,
1046
+ DateWidget: DateWidget,
1047
+ DateTimeWidget: DateTimeWidget,
1048
+ RadioWidget: RadioWidget,
1049
+ RangeWidget: RangeWidget,
1050
+ SelectWidget: SelectWidget,
1051
+ TextareaWidget: TextareaWidget
1052
+ };
1053
+ }
1054
+ var Widgets = /*#__PURE__*/generateWidgets();
1058
1055
 
1059
- const Theme = {
1060
- templates: Templates,
1061
- widgets: Widgets
1062
- };
1056
+ function generateTheme() {
1057
+ return {
1058
+ templates: generateTemplates(),
1059
+ widgets: generateWidgets()
1060
+ };
1061
+ }
1062
+ var Theme = /*#__PURE__*/generateTheme();
1063
1063
 
1064
- const MuiForm = /*#__PURE__*/withTheme(Theme);
1064
+ function generateForm() {
1065
+ return withTheme(generateTheme());
1066
+ }
1067
+ var MuiForm = /*#__PURE__*/generateForm();
1065
1068
 
1066
- export { MuiForm as Form, Templates, Theme, Widgets, MuiForm as default };
1069
+ export { MuiForm as Form, Templates, Theme, Widgets, MuiForm as default, generateForm, generateTemplates, generateTheme, generateWidgets };
1067
1070
  //# sourceMappingURL=mui.esm.js.map