@rjsf/mui 5.0.0-beta.1

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 (62) hide show
  1. package/LICENSE.md +201 -0
  2. package/README.md +137 -0
  3. package/dist/AddButton/AddButton.d.ts +4 -0
  4. package/dist/AddButton/index.d.ts +2 -0
  5. package/dist/ArrayFieldItemTemplate/ArrayFieldItemTemplate.d.ts +3 -0
  6. package/dist/ArrayFieldItemTemplate/index.d.ts +2 -0
  7. package/dist/ArrayFieldTemplate/ArrayFieldTemplate.d.ts +3 -0
  8. package/dist/ArrayFieldTemplate/index.d.ts +2 -0
  9. package/dist/BaseInputTemplate/BaseInputTemplate.d.ts +3 -0
  10. package/dist/BaseInputTemplate/index.d.ts +2 -0
  11. package/dist/CheckboxWidget/CheckboxWidget.d.ts +3 -0
  12. package/dist/CheckboxWidget/index.d.ts +2 -0
  13. package/dist/CheckboxesWidget/CheckboxesWidget.d.ts +3 -0
  14. package/dist/CheckboxesWidget/index.d.ts +2 -0
  15. package/dist/DateTimeWidget/DateTimeWidget.d.ts +3 -0
  16. package/dist/DateTimeWidget/index.d.ts +2 -0
  17. package/dist/DateWidget/DateWidget.d.ts +3 -0
  18. package/dist/DateWidget/index.d.ts +2 -0
  19. package/dist/DescriptionField/DescriptionField.d.ts +3 -0
  20. package/dist/DescriptionField/index.d.ts +2 -0
  21. package/dist/ErrorList/ErrorList.d.ts +3 -0
  22. package/dist/ErrorList/index.d.ts +2 -0
  23. package/dist/FieldTemplate/FieldTemplate.d.ts +3 -0
  24. package/dist/FieldTemplate/WrapIfAdditional.d.ts +7 -0
  25. package/dist/FieldTemplate/index.d.ts +2 -0
  26. package/dist/IconButton/IconButton.d.ts +5 -0
  27. package/dist/IconButton/index.d.ts +2 -0
  28. package/dist/MuiForm/MuiForm.d.ts +4 -0
  29. package/dist/MuiForm/index.d.ts +2 -0
  30. package/dist/ObjectFieldTemplate/ObjectFieldTemplate.d.ts +3 -0
  31. package/dist/ObjectFieldTemplate/index.d.ts +2 -0
  32. package/dist/RadioWidget/RadioWidget.d.ts +3 -0
  33. package/dist/RadioWidget/index.d.ts +2 -0
  34. package/dist/RangeWidget/RangeWidget.d.ts +3 -0
  35. package/dist/RangeWidget/index.d.ts +2 -0
  36. package/dist/SelectWidget/SelectWidget.d.ts +3 -0
  37. package/dist/SelectWidget/index.d.ts +2 -0
  38. package/dist/SubmitButton/SubmitButton.d.ts +4 -0
  39. package/dist/SubmitButton/index.d.ts +2 -0
  40. package/dist/Templates/Templates.d.ts +20 -0
  41. package/dist/Templates/index.d.ts +2 -0
  42. package/dist/TextareaWidget/TextareaWidget.d.ts +3 -0
  43. package/dist/TextareaWidget/index.d.ts +2 -0
  44. package/dist/Theme/Theme.d.ts +3 -0
  45. package/dist/Theme/index.d.ts +2 -0
  46. package/dist/TitleField/TitleField.d.ts +3 -0
  47. package/dist/TitleField/index.d.ts +2 -0
  48. package/dist/Widgets/Widgets.d.ts +11 -0
  49. package/dist/Widgets/index.d.ts +2 -0
  50. package/dist/index.d.ts +6 -0
  51. package/dist/index.js +8 -0
  52. package/dist/mui.cjs.development.js +1057 -0
  53. package/dist/mui.cjs.development.js.map +1 -0
  54. package/dist/mui.cjs.production.min.js +2 -0
  55. package/dist/mui.cjs.production.min.js.map +1 -0
  56. package/dist/mui.esm.js +1016 -0
  57. package/dist/mui.esm.js.map +1 -0
  58. package/dist/mui.umd.development.js +1030 -0
  59. package/dist/mui.umd.development.js.map +1 -0
  60. package/dist/mui.umd.production.min.js +2 -0
  61. package/dist/mui.umd.production.min.js.map +1 -0
  62. package/package.json +88 -0
@@ -0,0 +1,1016 @@
1
+ import { withTheme } from '@rjsf/core';
2
+ import React from 'react';
3
+ import AddIcon from '@mui/icons-material/Add';
4
+ import IconButton from '@mui/material/IconButton';
5
+ import Box from '@mui/material/Box';
6
+ import Grid from '@mui/material/Grid';
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';
9
+ import TextField from '@mui/material/TextField';
10
+ import Typography from '@mui/material/Typography';
11
+ import ErrorIcon from '@mui/icons-material/Error';
12
+ import List from '@mui/material/List';
13
+ import ListItem from '@mui/material/ListItem';
14
+ import ListItemIcon from '@mui/material/ListItemIcon';
15
+ import ListItemText from '@mui/material/ListItemText';
16
+ import ArrowDownwardIcon from '@mui/icons-material/ArrowDownward';
17
+ import ArrowUpwardIcon from '@mui/icons-material/ArrowUpward';
18
+ import RemoveIcon from '@mui/icons-material/Remove';
19
+ import FormControl from '@mui/material/FormControl';
20
+ import FormHelperText from '@mui/material/FormHelperText';
21
+ import InputLabel from '@mui/material/InputLabel';
22
+ import Input from '@mui/material/OutlinedInput';
23
+ import Button from '@mui/material/Button';
24
+ import Divider from '@mui/material/Divider';
25
+ import Checkbox from '@mui/material/Checkbox';
26
+ import FormControlLabel from '@mui/material/FormControlLabel';
27
+ import FormGroup from '@mui/material/FormGroup';
28
+ import FormLabel from '@mui/material/FormLabel';
29
+ import Radio from '@mui/material/Radio';
30
+ import RadioGroup from '@mui/material/RadioGroup';
31
+ import Slider from '@mui/material/Slider';
32
+ import MenuItem from '@mui/material/MenuItem';
33
+
34
+ const AddButton = props => {
35
+ return /*#__PURE__*/React.createElement(IconButton, {
36
+ title: "Add Item",
37
+ ...props,
38
+ color: "primary"
39
+ }, /*#__PURE__*/React.createElement(AddIcon, null));
40
+ };
41
+
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 = {
62
+ flex: 1,
63
+ paddingLeft: 6,
64
+ paddingRight: 6,
65
+ fontWeight: "bold",
66
+ minWidth: 0
67
+ };
68
+ return /*#__PURE__*/React.createElement(Grid, {
69
+ container: true,
70
+ alignItems: "center"
71
+ }, /*#__PURE__*/React.createElement(Grid, {
72
+ item: true,
73
+ xs: true,
74
+ style: {
75
+ overflow: "auto"
76
+ }
77
+ }, /*#__PURE__*/React.createElement(Box, {
78
+ mb: 2
79
+ }, /*#__PURE__*/React.createElement(Paper, {
80
+ elevation: 2
81
+ }, /*#__PURE__*/React.createElement(Box, {
82
+ p: 2
83
+ }, children)))), hasToolbar && /*#__PURE__*/React.createElement(Grid, {
84
+ item: true
85
+ }, (hasMoveUp || hasMoveDown) && /*#__PURE__*/React.createElement(MoveUpButton, {
86
+ style: btnStyle,
87
+ disabled: disabled || readonly || !hasMoveUp,
88
+ onClick: onReorderClick(index, index - 1)
89
+ }), (hasMoveUp || hasMoveDown) && /*#__PURE__*/React.createElement(MoveDownButton, {
90
+ style: btnStyle,
91
+ disabled: disabled || readonly || !hasMoveDown,
92
+ onClick: onReorderClick(index, index + 1)
93
+ }), hasRemove && /*#__PURE__*/React.createElement(RemoveButton, {
94
+ style: btnStyle,
95
+ disabled: disabled || readonly,
96
+ onClick: onDropIndexClick(index)
97
+ })));
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
118
+
119
+ const {
120
+ ButtonTemplates: {
121
+ AddButton
122
+ }
123
+ } = registry.templates;
124
+ return /*#__PURE__*/React.createElement(Paper, {
125
+ elevation: 2
126
+ }, /*#__PURE__*/React.createElement(Box, {
127
+ p: 2
128
+ }, /*#__PURE__*/React.createElement(ArrayFieldTitleTemplate, {
129
+ idSchema: idSchema,
130
+ title: uiOptions.title || title,
131
+ uiSchema: uiSchema,
132
+ required: required,
133
+ registry: registry
134
+ }), (uiOptions.description || schema.description) && /*#__PURE__*/React.createElement(ArrayFieldDescriptionTemplate, {
135
+ idSchema: idSchema,
136
+ description: uiOptions.description || schema.description,
137
+ uiSchema: uiSchema,
138
+ registry: registry
139
+ }), /*#__PURE__*/React.createElement(Grid, {
140
+ container: true,
141
+ 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
+ });
151
+ }), canAdd && /*#__PURE__*/React.createElement(Grid, {
152
+ container: true,
153
+ justifyContent: "flex-end"
154
+ }, /*#__PURE__*/React.createElement(Grid, {
155
+ item: true
156
+ }, /*#__PURE__*/React.createElement(Box, {
157
+ mt: 2
158
+ }, /*#__PURE__*/React.createElement(AddButton, {
159
+ className: "array-item-add",
160
+ onClick: onAddClick,
161
+ disabled: disabled || readonly
162
+ })))))));
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
+ };
203
+
204
+ const _onChange = _ref2 => {
205
+ let {
206
+ target: {
207
+ value
208
+ }
209
+ } = _ref2;
210
+ return onChange(value === "" ? options.emptyValue : value);
211
+ };
212
+
213
+ const _onBlur = _ref3 => {
214
+ let {
215
+ target: {
216
+ value
217
+ }
218
+ } = _ref3;
219
+ return onBlur(id, value);
220
+ };
221
+
222
+ const _onFocus = _ref4 => {
223
+ let {
224
+ target: {
225
+ value
226
+ }
227
+ } = _ref4;
228
+ return onFocus(id, value);
229
+ };
230
+
231
+ const {
232
+ schemaUtils
233
+ } = registry;
234
+ const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema);
235
+ return /*#__PURE__*/React.createElement(TextField, {
236
+ id: id,
237
+ placeholder: placeholder,
238
+ label: displayLabel ? label || schema.title : false,
239
+ autoFocus: autofocus,
240
+ required: required,
241
+ disabled: disabled || readonly,
242
+ ...otherProps,
243
+ value: value || value === 0 ? value : "",
244
+ error: rawErrors.length > 0,
245
+ onChange: _onChange,
246
+ onBlur: _onBlur,
247
+ onFocus: _onFocus,
248
+ ...textFieldProps
249
+ });
250
+ };
251
+
252
+ const DescriptionField = _ref => {
253
+ let {
254
+ description,
255
+ id
256
+ } = _ref;
257
+
258
+ if (description) {
259
+ return /*#__PURE__*/React.createElement(Typography, {
260
+ id: id,
261
+ variant: "subtitle2",
262
+ style: {
263
+ marginTop: "5px"
264
+ }
265
+ }, description);
266
+ }
267
+
268
+ return null;
269
+ };
270
+
271
+ const ErrorList = _ref => {
272
+ let {
273
+ errors
274
+ } = _ref;
275
+ return /*#__PURE__*/React.createElement(Paper, {
276
+ elevation: 2
277
+ }, /*#__PURE__*/React.createElement(Box, {
278
+ mb: 2,
279
+ p: 2
280
+ }, /*#__PURE__*/React.createElement(Typography, {
281
+ variant: "h6"
282
+ }, "Errors"), /*#__PURE__*/React.createElement(List, {
283
+ dense: true
284
+ }, errors.map((error, i) => {
285
+ return /*#__PURE__*/React.createElement(ListItem, {
286
+ key: i
287
+ }, /*#__PURE__*/React.createElement(ListItemIcon, null, /*#__PURE__*/React.createElement(ErrorIcon, {
288
+ color: "error"
289
+ })), /*#__PURE__*/React.createElement(ListItemText, {
290
+ primary: error.stack
291
+ }));
292
+ }))));
293
+ };
294
+
295
+ function MuiIconButton(props) {
296
+ const {
297
+ icon,
298
+ color,
299
+ ...otherProps
300
+ } = props;
301
+ return /*#__PURE__*/React.createElement(IconButton, { ...otherProps,
302
+ size: "small",
303
+ color: color
304
+ }, icon);
305
+ }
306
+ function MoveDownButton(props) {
307
+ return /*#__PURE__*/React.createElement(MuiIconButton, {
308
+ title: "Move down",
309
+ ...props,
310
+ icon: /*#__PURE__*/React.createElement(ArrowDownwardIcon, {
311
+ fontSize: "small"
312
+ })
313
+ });
314
+ }
315
+ function MoveUpButton(props) {
316
+ return /*#__PURE__*/React.createElement(MuiIconButton, {
317
+ title: "Move up",
318
+ ...props,
319
+ icon: /*#__PURE__*/React.createElement(ArrowUpwardIcon, {
320
+ fontSize: "small"
321
+ })
322
+ });
323
+ }
324
+ function RemoveButton(props) {
325
+ const {
326
+ iconType,
327
+ ...otherProps
328
+ } = props;
329
+ return /*#__PURE__*/React.createElement(MuiIconButton, {
330
+ title: "Remove",
331
+ ...otherProps,
332
+ color: "error",
333
+ icon: /*#__PURE__*/React.createElement(RemoveIcon, {
334
+ fontSize: iconType === "default" ? undefined : "small"
335
+ })
336
+ });
337
+ }
338
+
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);
370
+ }
371
+
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;
430
+
431
+ if (hidden) {
432
+ return /*#__PURE__*/React.createElement("div", {
433
+ style: {
434
+ display: "none"
435
+ }
436
+ }, children);
437
+ }
438
+
439
+ return /*#__PURE__*/React.createElement(WrapIfAdditional, {
440
+ classNames: classNames,
441
+ disabled: disabled,
442
+ id: id,
443
+ label: label,
444
+ onDropPropertyClick: onDropPropertyClick,
445
+ onKeyChange: onKeyChange,
446
+ readonly: readonly,
447
+ required: required,
448
+ schema: schema,
449
+ registry: registry
450
+ }, /*#__PURE__*/React.createElement(FormControl, {
451
+ fullWidth: true,
452
+ error: rawErrors.length ? true : false,
453
+ required: required
454
+ }, children, displayLabel && rawDescription ? /*#__PURE__*/React.createElement(Typography, {
455
+ variant: "caption",
456
+ 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
490
+
491
+ const {
492
+ ButtonTemplates: {
493
+ AddButton
494
+ }
495
+ } = registry.templates;
496
+ return /*#__PURE__*/React.createElement(React.Fragment, null, (uiOptions.title || title) && /*#__PURE__*/React.createElement(TitleFieldTemplate, {
497
+ id: idSchema.$id + "-title",
498
+ title: title,
499
+ required: required,
500
+ uiSchema: uiSchema,
501
+ registry: registry
502
+ }), (uiOptions.description || description) && /*#__PURE__*/React.createElement(DescriptionFieldTemplate, {
503
+ id: idSchema.$id + "-description",
504
+ description: uiOptions.description || description,
505
+ registry: registry
506
+ }), /*#__PURE__*/React.createElement(Grid, {
507
+ container: true,
508
+ spacing: 2,
509
+ style: {
510
+ marginTop: "10px"
511
+ }
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, {
522
+ container: true,
523
+ justifyContent: "flex-end"
524
+ }, /*#__PURE__*/React.createElement(Grid, {
525
+ item: true
526
+ }, /*#__PURE__*/React.createElement(AddButton, {
527
+ className: "object-property-expand",
528
+ onClick: onAddClick(schema),
529
+ disabled: disabled || readonly
530
+ })))));
531
+ };
532
+
533
+ const SubmitButton = props => {
534
+ const {
535
+ submitText,
536
+ norender,
537
+ props: submitButtonProps
538
+ } = getSubmitButtonOptions(props.uiSchema);
539
+
540
+ if (norender) {
541
+ return null;
542
+ }
543
+
544
+ return /*#__PURE__*/React.createElement(Box, {
545
+ marginTop: 3
546
+ }, /*#__PURE__*/React.createElement(Button, {
547
+ type: "submit",
548
+ variant: "contained",
549
+ color: "primary",
550
+ ...submitButtonProps
551
+ }, submitText));
552
+ };
553
+
554
+ const TitleField = _ref => {
555
+ let {
556
+ id,
557
+ title
558
+ } = _ref;
559
+ return /*#__PURE__*/React.createElement(Box, {
560
+ id: id,
561
+ mb: 1,
562
+ mt: 1
563
+ }, /*#__PURE__*/React.createElement(Typography, {
564
+ variant: "h5"
565
+ }, title), /*#__PURE__*/React.createElement(Divider, null));
566
+ };
567
+
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
+ };
585
+
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
599
+ // the "required" attribute if the field value must be "true", due to the
600
+ // "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;
612
+ return onBlur(id, value);
613
+ };
614
+
615
+ const _onFocus = _ref2 => {
616
+ let {
617
+ target: {
618
+ value
619
+ }
620
+ } = _ref2;
621
+ return onFocus(id, value);
622
+ };
623
+
624
+ return /*#__PURE__*/React.createElement(FormControlLabel, {
625
+ control: /*#__PURE__*/React.createElement(Checkbox, {
626
+ id: id,
627
+ checked: typeof value === "undefined" ? false : Boolean(value),
628
+ required: required,
629
+ disabled: disabled || readonly,
630
+ autoFocus: autofocus,
631
+ onChange: _onChange,
632
+ onBlur: _onBlur,
633
+ onFocus: _onFocus
634
+ }),
635
+ label: label || ""
636
+ });
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;
671
+
672
+ const _onChange = option => _ref2 => {
673
+ let {
674
+ target: {
675
+ checked
676
+ }
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
+ }
690
+ };
691
+
692
+ const _onBlur = _ref4 => {
693
+ let {
694
+ target: {
695
+ value
696
+ }
697
+ } = _ref4;
698
+ return onBlur(id, value);
699
+ };
700
+
701
+ const _onFocus = _ref5 => {
702
+ let {
703
+ target: {
704
+ value
705
+ }
706
+ } = _ref5;
707
+ return onFocus(id, value);
708
+ };
709
+
710
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(FormLabel, {
711
+ required: required,
712
+ htmlFor: id
713
+ }, label || schema.title), /*#__PURE__*/React.createElement(FormGroup, {
714
+ id: id,
715
+ 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,
721
+ checked: checked,
722
+ disabled: disabled || itemDisabled || readonly,
723
+ autoFocus: autofocus && index === 0,
724
+ onChange: _onChange(option),
725
+ onBlur: _onBlur,
726
+ onFocus: _onFocus
727
+ });
728
+ return /*#__PURE__*/React.createElement(FormControlLabel, {
729
+ control: checkbox,
730
+ key: index,
731
+ label: option.label
732
+ });
733
+ })));
734
+ };
735
+
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, {
743
+ type: "date",
744
+ InputLabelProps: {
745
+ 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);
758
+
759
+ const onChange = value => {
760
+ props.onChange(localToUTC(value));
761
+ };
762
+
763
+ return /*#__PURE__*/React.createElement(BaseInputTemplate, {
764
+ type: "datetime-local",
765
+ InputLabelProps: {
766
+ shrink: true
767
+ },
768
+ ...props,
769
+ value: value,
770
+ 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);
794
+
795
+ const _onBlur = _ref2 => {
796
+ let {
797
+ target: {
798
+ value
799
+ }
800
+ } = _ref2;
801
+ return onBlur(id, value);
802
+ };
803
+
804
+ const _onFocus = _ref3 => {
805
+ let {
806
+ target: {
807
+ value
808
+ }
809
+ } = _ref3;
810
+ return onFocus(id, value);
811
+ };
812
+
813
+ const row = options ? options.inline : false;
814
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(FormLabel, {
815
+ required: required,
816
+ htmlFor: id
817
+ }, label || schema.title), /*#__PURE__*/React.createElement(RadioGroup, {
818
+ id: id,
819
+ value: "" + value,
820
+ row: row,
821
+ onChange: _onChange,
822
+ 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, {
827
+ control: /*#__PURE__*/React.createElement(Radio, {
828
+ name: id + "-" + i,
829
+ color: "primary",
830
+ key: i
831
+ }),
832
+ label: "" + option.label,
833
+ value: "" + option.value,
834
+ key: i,
835
+ disabled: disabled || itemDisabled || readonly
836
+ });
837
+ return radio;
838
+ })));
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
+ };
861
+
862
+ const _onChange = (_, value) => {
863
+ onChange(value ? options.emptyValue : value);
864
+ };
865
+
866
+ const _onBlur = _ref2 => {
867
+ let {
868
+ target: {
869
+ value
870
+ }
871
+ } = _ref2;
872
+ return onBlur(id, value);
873
+ };
874
+
875
+ const _onFocus = _ref3 => {
876
+ let {
877
+ target: {
878
+ value
879
+ }
880
+ } = _ref3;
881
+ return onFocus(id, value);
882
+ };
883
+
884
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(FormLabel, {
885
+ required: required,
886
+ id: id
887
+ }, label), /*#__PURE__*/React.createElement(Slider, {
888
+ disabled: disabled || readonly,
889
+ onChange: _onChange,
890
+ onBlur: _onBlur,
891
+ 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 ? [] : "";
919
+
920
+ const _onChange = _ref2 => {
921
+ let {
922
+ target: {
923
+ value
924
+ }
925
+ } = _ref2;
926
+ return onChange(processSelectValue(schema, value, options));
927
+ };
928
+
929
+ const _onBlur = _ref3 => {
930
+ let {
931
+ target: {
932
+ value
933
+ }
934
+ } = _ref3;
935
+ return onBlur(id, processSelectValue(schema, value, options));
936
+ };
937
+
938
+ const _onFocus = _ref4 => {
939
+ let {
940
+ target: {
941
+ value
942
+ }
943
+ } = _ref4;
944
+ return onFocus(id, processSelectValue(schema, value, options));
945
+ };
946
+
947
+ return /*#__PURE__*/React.createElement(TextField, {
948
+ id: id,
949
+ label: label || schema.title,
950
+ select: true,
951
+ value: typeof value === "undefined" ? emptyValue : value,
952
+ required: required,
953
+ disabled: disabled || readonly,
954
+ autoFocus: autofocus,
955
+ error: rawErrors.length > 0,
956
+ onChange: _onChange,
957
+ 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;
971
+ return /*#__PURE__*/React.createElement(MenuItem, {
972
+ key: i,
973
+ value: value,
974
+ disabled: disabled
975
+ }, label);
976
+ }));
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;
986
+
987
+ if (typeof options.rows === "string" || typeof options.rows === "number") {
988
+ rows = options.rows;
989
+ }
990
+
991
+ return /*#__PURE__*/React.createElement(BaseInputTemplate, { ...props,
992
+ multiline: true,
993
+ rows: rows
994
+ });
995
+ };
996
+
997
+ var Widgets = {
998
+ CheckboxWidget,
999
+ CheckboxesWidget,
1000
+ DateWidget,
1001
+ DateTimeWidget,
1002
+ RadioWidget,
1003
+ RangeWidget,
1004
+ SelectWidget,
1005
+ TextareaWidget
1006
+ };
1007
+
1008
+ const Theme = {
1009
+ templates: Templates,
1010
+ widgets: Widgets
1011
+ };
1012
+
1013
+ const MuiForm = /*#__PURE__*/withTheme(Theme);
1014
+
1015
+ export { MuiForm as Form, Templates, Theme, Widgets, MuiForm as default };
1016
+ //# sourceMappingURL=mui.esm.js.map