@rjsf/core 5.0.0-beta.10 → 5.0.0-beta.12

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.
@@ -4,9 +4,9 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var React = require('react');
6
6
  var utils = require('@rjsf/utils');
7
- var _pick = require('lodash/pick');
8
7
  var get = require('lodash/get');
9
8
  var _isEmpty = require('lodash/isEmpty');
9
+ var _pick = require('lodash/pick');
10
10
  var isObject = require('lodash/isObject');
11
11
  var set = require('lodash/set');
12
12
  var nanoid = require('nanoid');
@@ -17,9 +17,9 @@ var omit = require('lodash/omit');
17
17
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
18
18
 
19
19
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
20
- var _pick__default = /*#__PURE__*/_interopDefaultLegacy(_pick);
21
20
  var get__default = /*#__PURE__*/_interopDefaultLegacy(get);
22
21
  var _isEmpty__default = /*#__PURE__*/_interopDefaultLegacy(_isEmpty);
22
+ var _pick__default = /*#__PURE__*/_interopDefaultLegacy(_pick);
23
23
  var isObject__default = /*#__PURE__*/_interopDefaultLegacy(isObject);
24
24
  var set__default = /*#__PURE__*/_interopDefaultLegacy(set);
25
25
  var unset__default = /*#__PURE__*/_interopDefaultLegacy(unset);
@@ -27,7 +27,6 @@ var has__default = /*#__PURE__*/_interopDefaultLegacy(has);
27
27
  var omit__default = /*#__PURE__*/_interopDefaultLegacy(omit);
28
28
 
29
29
  /** Used to generate a unique ID for an element in a row */
30
-
31
30
  function generateRowId() {
32
31
  return nanoid.nanoid();
33
32
  }
@@ -36,8 +35,6 @@ function generateRowId() {
36
35
  * @param formData - The data for the form
37
36
  * @returns - The `formData` converted into a `KeyedFormDataType` element
38
37
  */
39
-
40
-
41
38
  function generateKeyedFormData(formData) {
42
39
  return !Array.isArray(formData) ? [] : formData.map(item => {
43
40
  return {
@@ -51,20 +48,15 @@ function generateKeyedFormData(formData) {
51
48
  * @param keyedFormData - The `KeyedFormDataType` to be converted
52
49
  * @returns - The inner `formData` item(s) in the `keyedFormData`
53
50
  */
54
-
55
-
56
51
  function keyedToPlainFormData(keyedFormData) {
57
52
  if (Array.isArray(keyedFormData)) {
58
53
  return keyedFormData.map(keyedItem => keyedItem.item);
59
54
  }
60
-
61
55
  return [];
62
56
  }
63
57
  /** The `ArrayField` component is used to render a field in the schema that is of type `array`. It supports both normal
64
58
  * and fixed array, allowing user to add and remove elements from the array data.
65
59
  */
66
-
67
-
68
60
  class ArrayField extends React.Component {
69
61
  /** Constructs an `ArrayField` from the `props`, generating the initial keyed data from the `formData`
70
62
  *
@@ -72,7 +64,6 @@ class ArrayField extends React.Component {
72
64
  */
73
65
  constructor(props) {
74
66
  super(props);
75
-
76
67
  this._getNewFormDataRow = () => {
77
68
  const {
78
69
  schema,
@@ -82,20 +73,16 @@ class ArrayField extends React.Component {
82
73
  schemaUtils
83
74
  } = registry;
84
75
  let itemSchema = schema.items;
85
-
86
76
  if (utils.isFixedItems(schema) && utils.allowAdditionalItems(schema)) {
87
77
  itemSchema = schema.additionalItems;
88
- } // Cast this as a T to work around schema utils being for T[] caused by the FieldProps<T[], F> call on the class
89
-
90
-
78
+ }
79
+ // Cast this as a T to work around schema utils being for T[] caused by the FieldProps<T[], S, F> call on the class
91
80
  return schemaUtils.getDefaultFormState(itemSchema);
92
81
  };
93
-
94
82
  this.onAddClick = event => {
95
83
  if (event) {
96
84
  event.preventDefault();
97
85
  }
98
-
99
86
  const {
100
87
  onChange
101
88
  } = this.props;
@@ -112,13 +99,11 @@ class ArrayField extends React.Component {
112
99
  updatedKeyedFormData: true
113
100
  }, () => onChange(keyedToPlainFormData(newKeyedFormData)));
114
101
  };
115
-
116
102
  this.onAddIndexClick = index => {
117
103
  return event => {
118
104
  if (event) {
119
105
  event.preventDefault();
120
106
  }
121
-
122
107
  const {
123
108
  onChange
124
109
  } = this.props;
@@ -137,29 +122,24 @@ class ArrayField extends React.Component {
137
122
  }, () => onChange(keyedToPlainFormData(newKeyedFormData)));
138
123
  };
139
124
  };
140
-
141
125
  this.onDropIndexClick = index => {
142
126
  return event => {
143
127
  if (event) {
144
128
  event.preventDefault();
145
129
  }
146
-
147
130
  const {
148
131
  onChange,
149
132
  errorSchema
150
133
  } = this.props;
151
134
  const {
152
135
  keyedFormData
153
- } = this.state; // refs #195: revalidate to ensure properly reindexing errors
154
-
136
+ } = this.state;
137
+ // refs #195: revalidate to ensure properly reindexing errors
155
138
  let newErrorSchema;
156
-
157
139
  if (errorSchema) {
158
140
  newErrorSchema = {};
159
-
160
141
  for (const idx in errorSchema) {
161
142
  const i = parseInt(idx);
162
-
163
143
  if (i < index) {
164
144
  set__default["default"](newErrorSchema, [i], errorSchema[idx]);
165
145
  } else if (i > index) {
@@ -167,7 +147,6 @@ class ArrayField extends React.Component {
167
147
  }
168
148
  }
169
149
  }
170
-
171
150
  const newKeyedFormData = keyedFormData.filter((_, i) => i !== index);
172
151
  this.setState({
173
152
  keyedFormData: newKeyedFormData,
@@ -175,26 +154,21 @@ class ArrayField extends React.Component {
175
154
  }, () => onChange(keyedToPlainFormData(newKeyedFormData), newErrorSchema));
176
155
  };
177
156
  };
178
-
179
157
  this.onReorderClick = (index, newIndex) => {
180
158
  return event => {
181
159
  if (event) {
182
160
  event.preventDefault();
183
161
  event.currentTarget.blur();
184
162
  }
185
-
186
163
  const {
187
164
  onChange,
188
165
  errorSchema
189
166
  } = this.props;
190
167
  let newErrorSchema;
191
-
192
168
  if (this.props.errorSchema) {
193
169
  newErrorSchema = {};
194
-
195
170
  for (const idx in errorSchema) {
196
171
  const i = parseInt(idx);
197
-
198
172
  if (i == index) {
199
173
  set__default["default"](newErrorSchema, [newIndex], errorSchema[index]);
200
174
  } else if (i == newIndex) {
@@ -204,32 +178,25 @@ class ArrayField extends React.Component {
204
178
  }
205
179
  }
206
180
  }
207
-
208
181
  const {
209
182
  keyedFormData
210
183
  } = this.state;
211
-
212
184
  function reOrderArray() {
213
185
  // Copy item
214
- const _newKeyedFormData = keyedFormData.slice(); // Moves item from index to newIndex
215
-
216
-
186
+ const _newKeyedFormData = keyedFormData.slice();
187
+ // Moves item from index to newIndex
217
188
  _newKeyedFormData.splice(index, 1);
218
-
219
189
  _newKeyedFormData.splice(newIndex, 0, keyedFormData[index]);
220
-
221
190
  return _newKeyedFormData;
222
191
  }
223
-
224
192
  const newKeyedFormData = reOrderArray();
225
193
  this.setState({
226
194
  keyedFormData: newKeyedFormData
227
195
  }, () => onChange(keyedToPlainFormData(newKeyedFormData), newErrorSchema));
228
196
  };
229
197
  };
230
-
231
198
  this.onChangeForIndex = index => {
232
- return (value, newErrorSchema) => {
199
+ return (value, newErrorSchema, id) => {
233
200
  const {
234
201
  formData,
235
202
  onChange,
@@ -242,25 +209,23 @@ class ArrayField extends React.Component {
242
209
  const jsonValue = typeof value === "undefined" ? null : value;
243
210
  return index === i ? jsonValue : item;
244
211
  });
245
- onChange(newFormData, errorSchema && errorSchema && { ...errorSchema,
212
+ onChange(newFormData, errorSchema && errorSchema && {
213
+ ...errorSchema,
246
214
  [index]: newErrorSchema
247
- });
215
+ }, id);
248
216
  };
249
217
  };
250
-
251
218
  this.onSelectChange = value => {
252
219
  const {
253
- onChange
220
+ onChange,
221
+ idSchema
254
222
  } = this.props;
255
- onChange(value);
223
+ onChange(value, undefined, idSchema && idSchema.$id);
256
224
  };
257
-
258
225
  const {
259
226
  formData: _formData = []
260
227
  } = props;
261
-
262
228
  const _keyedFormData = generateKeyedFormData(_formData);
263
-
264
229
  this.state = {
265
230
  keyedFormData: _keyedFormData,
266
231
  updatedKeyedFormData: false
@@ -272,8 +237,6 @@ class ArrayField extends React.Component {
272
237
  * @param nextProps - The next set of props data
273
238
  * @param prevState - The previous set of state data
274
239
  */
275
-
276
-
277
240
  static getDerivedStateFromProps(nextProps, prevState) {
278
241
  // Don't call getDerivedStateFromProps if keyed formdata was just updated.
279
242
  if (prevState.updatedKeyedFormData) {
@@ -281,7 +244,6 @@ class ArrayField extends React.Component {
281
244
  updatedKeyedFormData: false
282
245
  };
283
246
  }
284
-
285
247
  const nextFormData = Array.isArray(nextProps.formData) ? nextProps.formData : [];
286
248
  const previousKeyedFormData = prevState.keyedFormData || [];
287
249
  const newKeyedFormData = nextFormData.length === previousKeyedFormData.length ? previousKeyedFormData.map((previousKeyedFormDatum, index) => {
@@ -297,8 +259,6 @@ class ArrayField extends React.Component {
297
259
  /** Returns the appropriate title for an item by getting first the title from the schema.items, then falling back to
298
260
  * the description from the schema.items, and finally the string "Item"
299
261
  */
300
-
301
-
302
262
  get itemTitle() {
303
263
  const {
304
264
  schema
@@ -311,16 +271,13 @@ class ArrayField extends React.Component {
311
271
  * @param itemSchema - The schema for the item
312
272
  * @return - True if the item schema type does not contain the "null" type
313
273
  */
314
-
315
-
316
274
  isItemRequired(itemSchema) {
317
275
  if (Array.isArray(itemSchema.type)) {
318
276
  // While we don't yet support composite/nullable jsonschema types, it's
319
277
  // future-proof to check for requirement against these.
320
278
  return !itemSchema.type.includes("null");
321
- } // All non-null array item types are inherently required by design
322
-
323
-
279
+ }
280
+ // All non-null array item types are inherently required by design
324
281
  return itemSchema.type !== "null";
325
282
  }
326
283
  /** Determines whether more items can be added to the array. If the uiSchema indicates the array doesn't allow adding
@@ -330,8 +287,6 @@ class ArrayField extends React.Component {
330
287
  * @param formItems - The list of items in the form
331
288
  * @returns - True if the item is addable otherwise false
332
289
  */
333
-
334
-
335
290
  canAddItem(formItems) {
336
291
  const {
337
292
  schema,
@@ -340,7 +295,6 @@ class ArrayField extends React.Component {
340
295
  let {
341
296
  addable
342
297
  } = utils.getUiOptions(uiSchema);
343
-
344
298
  if (addable !== false) {
345
299
  // if ui:options.addable was not explicitly set to false, we can add
346
300
  // another item if we have not exceeded maxItems yet
@@ -350,14 +304,12 @@ class ArrayField extends React.Component {
350
304
  addable = true;
351
305
  }
352
306
  }
353
-
354
307
  return addable;
355
308
  }
356
309
  /** Returns the default form information for an item based on the schema for that item. Deals with the possibility
357
310
  * that the schema is fixed and allows additional items.
358
311
  */
359
312
 
360
-
361
313
  /** Renders the `ArrayField` depending on the specific needs of the schema and uischema elements
362
314
  */
363
315
  render() {
@@ -370,7 +322,6 @@ class ArrayField extends React.Component {
370
322
  const {
371
323
  schemaUtils
372
324
  } = registry;
373
-
374
325
  if (!(utils.ITEMS_KEY in schema)) {
375
326
  const uiOptions = utils.getUiOptions(uiSchema);
376
327
  const UnsupportedFieldTemplate = utils.getTemplate("UnsupportedFieldTemplate", registry, uiOptions);
@@ -381,30 +332,23 @@ class ArrayField extends React.Component {
381
332
  registry: registry
382
333
  });
383
334
  }
384
-
385
335
  if (schemaUtils.isMultiSelect(schema)) {
386
336
  // If array has enum or uniqueItems set to true, call renderMultiSelect() to render the default multiselect widget or a custom widget, if specified.
387
337
  return this.renderMultiSelect();
388
338
  }
389
-
390
339
  if (utils.isCustomWidget(uiSchema)) {
391
340
  return this.renderCustomWidget();
392
341
  }
393
-
394
342
  if (utils.isFixedItems(schema)) {
395
343
  return this.renderFixedArray();
396
344
  }
397
-
398
345
  if (schemaUtils.isFilesArray(schema, uiSchema)) {
399
346
  return this.renderFiles();
400
347
  }
401
-
402
348
  return this.renderNormalArray();
403
349
  }
404
350
  /** Renders a normal array without any limitations of length
405
351
  */
406
-
407
-
408
352
  renderNormalArray() {
409
353
  const {
410
354
  schema,
@@ -432,9 +376,7 @@ class ArrayField extends React.Component {
432
376
  formContext
433
377
  } = registry;
434
378
  const uiOptions = utils.getUiOptions(uiSchema);
435
-
436
379
  const _schemaItems = isObject__default["default"](schema.items) ? schema.items : {};
437
-
438
380
  const itemsSchema = schemaUtils.retrieveSchema(_schemaItems);
439
381
  const formData = keyedToPlainFormData(this.state.keyedFormData);
440
382
  const arrayProps = {
@@ -443,8 +385,8 @@ class ArrayField extends React.Component {
443
385
  const {
444
386
  key,
445
387
  item
446
- } = keyedItem; // While we are actually dealing with a single item of type T, the types require a T[], so cast
447
-
388
+ } = keyedItem;
389
+ // While we are actually dealing with a single item of type T, the types require a T[], so cast
448
390
  const itemCast = item;
449
391
  const itemSchema = schemaUtils.retrieveSchema(_schemaItems, itemCast);
450
392
  const itemErrorSchema = errorSchema ? errorSchema[index] : undefined;
@@ -453,10 +395,10 @@ class ArrayField extends React.Component {
453
395
  return this.renderArrayFieldItem({
454
396
  key,
455
397
  index,
456
- name: name && name + "-" + index,
398
+ name: name && `${name}-${index}`,
457
399
  canMoveUp: index > 0,
458
400
  canMoveDown: index < formData.length - 1,
459
- itemSchema: itemSchema,
401
+ itemSchema,
460
402
  itemIdSchema,
461
403
  itemErrorSchema,
462
404
  itemData: itemCast,
@@ -467,7 +409,7 @@ class ArrayField extends React.Component {
467
409
  rawErrors
468
410
  });
469
411
  }),
470
- className: "field field-array field-array-of-" + itemsSchema.type,
412
+ className: `field field-array field-array-of-${itemsSchema.type}`,
471
413
  disabled,
472
414
  idSchema,
473
415
  uiSchema,
@@ -482,13 +424,12 @@ class ArrayField extends React.Component {
482
424
  registry
483
425
  };
484
426
  const Template = utils.getTemplate("ArrayFieldTemplate", registry, uiOptions);
485
- return /*#__PURE__*/React__default["default"].createElement(Template, { ...arrayProps
427
+ return /*#__PURE__*/React__default["default"].createElement(Template, {
428
+ ...arrayProps
486
429
  });
487
430
  }
488
431
  /** Renders an array using the custom widget provided by the user in the `uiSchema`
489
432
  */
490
-
491
-
492
433
  renderCustomWidget() {
493
434
  const {
494
435
  schema,
@@ -541,8 +482,6 @@ class ArrayField extends React.Component {
541
482
  }
542
483
  /** Renders an array as a set of checkboxes
543
484
  */
544
-
545
-
546
485
  renderMultiSelect() {
547
486
  const {
548
487
  schema,
@@ -579,7 +518,8 @@ class ArrayField extends React.Component {
579
518
  onChange: this.onSelectChange,
580
519
  onBlur: onBlur,
581
520
  onFocus: onFocus,
582
- options: { ...options,
521
+ options: {
522
+ ...options,
583
523
  enumOptions
584
524
  },
585
525
  schema: schema,
@@ -598,8 +538,6 @@ class ArrayField extends React.Component {
598
538
  }
599
539
  /** Renders an array of files using the `FileWidget`
600
540
  */
601
-
602
-
603
541
  renderFiles() {
604
542
  const {
605
543
  schema,
@@ -649,8 +587,6 @@ class ArrayField extends React.Component {
649
587
  }
650
588
  /** Renders an array that has a maximum limit of items
651
589
  */
652
-
653
-
654
590
  renderFixedArray() {
655
591
  const {
656
592
  schema,
@@ -682,20 +618,15 @@ class ArrayField extends React.Component {
682
618
  schemaUtils,
683
619
  formContext
684
620
  } = registry;
685
-
686
621
  const _schemaItems = isObject__default["default"](schema.items) ? schema.items : [];
687
-
688
622
  const itemSchemas = _schemaItems.map((item, index) => schemaUtils.retrieveSchema(item, formData[index]));
689
-
690
623
  const additionalSchema = isObject__default["default"](schema.additionalItems) ? schemaUtils.retrieveSchema(schema.additionalItems, formData) : null;
691
-
692
624
  if (!items || items.length < itemSchemas.length) {
693
625
  // to make sure at least all fixed items are generated
694
626
  items = items || [];
695
627
  items = items.concat(new Array(itemSchemas.length - items.length));
696
- } // These are the props passed into the render function
697
-
698
-
628
+ }
629
+ // These are the props passed into the render function
699
630
  const arrayProps = {
700
631
  canAdd: this.canAddItem(items) && !!additionalSchema,
701
632
  className: "field field-array field-array-fixed-items",
@@ -706,8 +637,8 @@ class ArrayField extends React.Component {
706
637
  const {
707
638
  key,
708
639
  item
709
- } = keyedItem; // While we are actually dealing with a single item of type T, the types require a T[], so cast
710
-
640
+ } = keyedItem;
641
+ // While we are actually dealing with a single item of type T, the types require a T[], so cast
711
642
  const itemCast = item;
712
643
  const additional = index >= itemSchemas.length;
713
644
  const itemSchema = additional && isObject__default["default"](schema.additionalItems) ? schemaUtils.retrieveSchema(schema.additionalItems, itemCast) : itemSchemas[index];
@@ -718,7 +649,7 @@ class ArrayField extends React.Component {
718
649
  return this.renderArrayFieldItem({
719
650
  key,
720
651
  index,
721
- name: name && name + "-" + index,
652
+ name: name && `${name}-${index}`,
722
653
  canRemove: additional,
723
654
  canMoveUp: index >= itemSchemas.length + 1,
724
655
  canMoveDown: additional && index < items.length - 1,
@@ -744,7 +675,8 @@ class ArrayField extends React.Component {
744
675
  rawErrors
745
676
  };
746
677
  const Template = utils.getTemplate("ArrayFieldTemplate", registry, uiOptions);
747
- return /*#__PURE__*/React__default["default"].createElement(Template, { ...arrayProps
678
+ return /*#__PURE__*/React__default["default"].createElement(Template, {
679
+ ...arrayProps
748
680
  });
749
681
  }
750
682
  /** Renders the individual array item using a `SchemaField` along with the additional properties required to be send
@@ -752,8 +684,6 @@ class ArrayField extends React.Component {
752
684
  *
753
685
  * @param props - The props for the individual array item to be rendered
754
686
  */
755
-
756
-
757
687
  renderArrayFieldItem(props) {
758
688
  const {
759
689
  key,
@@ -839,7 +769,6 @@ class ArrayField extends React.Component {
839
769
  uiSchema: itemUiSchema
840
770
  };
841
771
  }
842
-
843
772
  }
844
773
 
845
774
  /** The `BooleanField` component is used to render a field in the schema is boolean. It constructs `enumOptions` for the
@@ -847,7 +776,6 @@ class ArrayField extends React.Component {
847
776
  *
848
777
  * @param props - The `FieldProps` for this template
849
778
  */
850
-
851
779
  function BooleanField(props) {
852
780
  const {
853
781
  schema,
@@ -878,46 +806,41 @@ function BooleanField(props) {
878
806
  } = utils.getUiOptions(uiSchema);
879
807
  const Widget = utils.getWidget(schema, widget, widgets);
880
808
  let enumOptions;
881
-
882
809
  if (Array.isArray(schema.oneOf)) {
883
810
  enumOptions = utils.optionsList({
884
811
  oneOf: schema.oneOf.map(option => {
885
812
  if (isObject__default["default"](option)) {
886
- return { ...option,
813
+ return {
814
+ ...option,
887
815
  title: option.title || (option.const === true ? "Yes" : "No")
888
816
  };
889
817
  }
890
-
891
818
  return undefined;
892
819
  }).filter(o => o) // cast away the error that typescript can't grok is fixed
893
-
894
820
  });
895
821
  } else {
896
- var _schema$enum;
897
-
898
822
  // We deprecated enumNames in v5. It's intentionally omitted from RSJFSchema type, so we need to cast here.
899
823
  const schemaWithEnumNames = schema;
900
- schema.enum = (_schema$enum = schema.enum) != null ? _schema$enum : [true, false];
901
-
902
- if (!schemaWithEnumNames.enumNames && schema.enum && schema.enum.length === 2 && schema.enum.every(v => typeof v === "boolean")) {
824
+ const enums = schema.enum ?? [true, false];
825
+ if (!schemaWithEnumNames.enumNames && enums.length === 2 && enums.every(v => typeof v === "boolean")) {
903
826
  enumOptions = [{
904
- value: schema.enum[0],
905
- label: schema.enum[0] ? "Yes" : "No"
827
+ value: enums[0],
828
+ label: enums[0] ? "Yes" : "No"
906
829
  }, {
907
- value: schema.enum[1],
908
- label: schema.enum[1] ? "Yes" : "No"
830
+ value: enums[1],
831
+ label: enums[1] ? "Yes" : "No"
909
832
  }];
910
833
  } else {
911
834
  enumOptions = utils.optionsList({
912
- enum: schema.enum,
835
+ enum: enums,
913
836
  // NOTE: enumNames is deprecated, but still supported for now.
914
837
  enumNames: schemaWithEnumNames.enumNames
915
838
  });
916
839
  }
917
840
  }
918
-
919
841
  return /*#__PURE__*/React__default["default"].createElement(Widget, {
920
- options: { ...options,
842
+ options: {
843
+ ...options,
921
844
  enumOptions
922
845
  },
923
846
  schema: schema,
@@ -943,7 +866,6 @@ function BooleanField(props) {
943
866
  *
944
867
  * @param props - The `FieldProps` for this template
945
868
  */
946
-
947
869
  class AnyOfField extends React.Component {
948
870
  /** Constructs an `AnyOfField` with the given `props` to initialize the initially selected option in state
949
871
  *
@@ -951,7 +873,6 @@ class AnyOfField extends React.Component {
951
873
  */
952
874
  constructor(props) {
953
875
  super(props);
954
-
955
876
  this.onOptionChange = option => {
956
877
  const selectedOption = parseInt(option, 10);
957
878
  const {
@@ -963,16 +884,15 @@ class AnyOfField extends React.Component {
963
884
  const {
964
885
  schemaUtils
965
886
  } = registry;
966
- const newOption = schemaUtils.retrieveSchema(options[selectedOption], formData); // If the new option is of type object and the current data is an object,
887
+ const newOption = schemaUtils.retrieveSchema(options[selectedOption], formData);
888
+ // If the new option is of type object and the current data is an object,
967
889
  // discard properties added using the old option.
968
-
969
890
  let newFormData = undefined;
970
-
971
891
  if (utils.guessType(formData) === "object" && (newOption.type === "object" || newOption.properties)) {
972
892
  newFormData = Object.assign({}, formData);
973
893
  const optionsToDiscard = options.slice();
974
- optionsToDiscard.splice(selectedOption, 1); // Discard any data added using other options
975
-
894
+ optionsToDiscard.splice(selectedOption, 1);
895
+ // Discard any data added using other options
976
896
  for (const option of optionsToDiscard) {
977
897
  if (option.properties) {
978
898
  for (const key in option.properties) {
@@ -982,15 +902,13 @@ class AnyOfField extends React.Component {
982
902
  }
983
903
  }
984
904
  }
985
- } // Call getDefaultFormState to make sure defaults are populated on change.
986
-
987
-
988
- onChange(schemaUtils.getDefaultFormState(options[selectedOption], newFormData));
905
+ }
906
+ // Call getDefaultFormState to make sure defaults are populated on change.
907
+ onChange(schemaUtils.getDefaultFormState(options[selectedOption], newFormData), undefined, this.getFieldId());
989
908
  this.setState({
990
909
  selectedOption: parseInt(option, 10)
991
910
  });
992
911
  };
993
-
994
912
  const {
995
913
  formData: _formData,
996
914
  options: _options
@@ -1005,8 +923,6 @@ class AnyOfField extends React.Component {
1005
923
  * @param prevProps - The previous `FieldProps` for this template
1006
924
  * @param prevState - The previous `AnyOfFieldState` for this template
1007
925
  */
1008
-
1009
-
1010
926
  componentDidUpdate(prevProps, prevState) {
1011
927
  const {
1012
928
  formData,
@@ -1016,14 +932,11 @@ class AnyOfField extends React.Component {
1016
932
  const {
1017
933
  selectedOption
1018
934
  } = this.state;
1019
-
1020
935
  if (!utils.deepEquals(formData, prevProps.formData) && idSchema.$id === prevProps.idSchema.$id) {
1021
936
  const matchingOption = this.getMatchingOption(selectedOption, formData, options);
1022
-
1023
937
  if (!prevState || matchingOption === selectedOption) {
1024
938
  return;
1025
939
  }
1026
-
1027
940
  this.setState({
1028
941
  selectedOption: matchingOption
1029
942
  });
@@ -1035,20 +948,16 @@ class AnyOfField extends React.Component {
1035
948
  * @param options - The list of options to choose from
1036
949
  * @return - The index of the `option` that best matches the `formData`
1037
950
  */
1038
-
1039
-
1040
951
  getMatchingOption(selectedOption, formData, options) {
1041
952
  const {
1042
953
  schemaUtils
1043
954
  } = this.props.registry;
1044
955
  const option = schemaUtils.getMatchingOption(formData, options);
1045
-
1046
956
  if (option !== 0) {
1047
957
  return option;
1048
- } // If the form data matches none of the options, use the currently selected
958
+ }
959
+ // If the form data matches none of the options, use the currently selected
1049
960
  // option, assuming it's available; otherwise use the first option
1050
-
1051
-
1052
961
  return selectedOption || 0;
1053
962
  }
1054
963
  /** Callback handler to remember what the currently selected option is. In addition to that the `formData` is updated
@@ -1058,7 +967,13 @@ class AnyOfField extends React.Component {
1058
967
  * @param option -
1059
968
  */
1060
969
 
1061
-
970
+ getFieldId() {
971
+ const {
972
+ idSchema,
973
+ schema
974
+ } = this.props;
975
+ return `${idSchema.$id}${schema.oneOf ? "__oneof_select" : "__anyof_select"}`;
976
+ }
1062
977
  /** Renders the `AnyOfField` selector along with a `SchemaField` for the value of the `formData`
1063
978
  */
1064
979
  render() {
@@ -1079,8 +994,7 @@ class AnyOfField extends React.Component {
1079
994
  onFocus,
1080
995
  options,
1081
996
  registry,
1082
- uiSchema,
1083
- schema
997
+ uiSchema
1084
998
  } = this.props;
1085
999
  const {
1086
1000
  widgets,
@@ -1101,7 +1015,6 @@ class AnyOfField extends React.Component {
1101
1015
  }, widget, widgets);
1102
1016
  const option = options[selectedOption] || null;
1103
1017
  let optionSchema;
1104
-
1105
1018
  if (option) {
1106
1019
  // If the subschema doesn't declare a type, infer the type from the
1107
1020
  // parent schema
@@ -1109,9 +1022,8 @@ class AnyOfField extends React.Component {
1109
1022
  type: baseType
1110
1023
  });
1111
1024
  }
1112
-
1113
1025
  const enumOptions = options.map((option, index) => ({
1114
- label: option.title || "Option " + (index + 1),
1026
+ label: option.title || `Option ${index + 1}`,
1115
1027
  value: index
1116
1028
  }));
1117
1029
  return /*#__PURE__*/React__default["default"].createElement("div", {
@@ -1119,7 +1031,7 @@ class AnyOfField extends React.Component {
1119
1031
  }, /*#__PURE__*/React__default["default"].createElement("div", {
1120
1032
  className: "form-group"
1121
1033
  }, /*#__PURE__*/React__default["default"].createElement(Widget, {
1122
- id: "" + idSchema.$id + (schema.oneOf ? "__oneof_select" : "__anyof_select"),
1034
+ id: this.getFieldId(),
1123
1035
  schema: {
1124
1036
  type: "number",
1125
1037
  default: 0
@@ -1154,18 +1066,17 @@ class AnyOfField extends React.Component {
1154
1066
  hideError: hideError
1155
1067
  }));
1156
1068
  }
1157
-
1158
1069
  }
1159
1070
 
1071
+ // Matches a string that ends in a . character, optionally followed by a sequence of
1160
1072
  // digits followed by any number of 0 characters up until the end of the line.
1161
1073
  // Ensuring that there is at least one prefixed character is important so that
1162
1074
  // you don't incorrectly match against "0".
1163
-
1164
- const trailingCharMatcherWithPrefix = /\.([0-9]*0)*$/; // This is used for trimming the trailing 0 and . characters without affecting
1075
+ const trailingCharMatcherWithPrefix = /\.([0-9]*0)*$/;
1076
+ // This is used for trimming the trailing 0 and . characters without affecting
1165
1077
  // the rest of the string. Its possible to use one RegEx with groups for this
1166
1078
  // functionality, but it is fairly complex compared to simply defining two
1167
1079
  // different matchers.
1168
-
1169
1080
  const trailingCharMatcher = /[0.]0*$/;
1170
1081
  /**
1171
1082
  * The NumberField class has some special handling for dealing with trailing
@@ -1184,7 +1095,6 @@ const trailingCharMatcher = /[0.]0*$/;
1184
1095
  * value cached in the state. If it matches the cached value, the cached
1185
1096
  * value is passed to the input instead of the formData value
1186
1097
  */
1187
-
1188
1098
  function NumberField(props) {
1189
1099
  const {
1190
1100
  registry,
@@ -1201,36 +1111,33 @@ function NumberField(props) {
1201
1111
  *
1202
1112
  * @param value - The current value for the change occurring
1203
1113
  */
1204
-
1205
1114
  const handleChange = React.useCallback(value => {
1206
1115
  // Cache the original value in component state
1207
- setLastValue(value); // Normalize decimals that don't start with a zero character in advance so
1116
+ setLastValue(value);
1117
+ // Normalize decimals that don't start with a zero character in advance so
1208
1118
  // that the rest of the normalization logic is simpler
1209
-
1210
- if (("" + value).charAt(0) === ".") {
1211
- value = "0" + value;
1212
- } // Check that the value is a string (this can happen if the widget used is a
1119
+ if (`${value}`.charAt(0) === ".") {
1120
+ value = `0${value}`;
1121
+ }
1122
+ // Check that the value is a string (this can happen if the widget used is a
1213
1123
  // <select>, due to an enum declaration etc) then, if the value ends in a
1214
1124
  // trailing decimal point or multiple zeroes, strip the trailing values
1215
-
1216
-
1217
1125
  const processed = typeof value === "string" && value.match(trailingCharMatcherWithPrefix) ? utils.asNumber(value.replace(trailingCharMatcher, "")) : utils.asNumber(value);
1218
1126
  onChange(processed);
1219
1127
  }, [onChange]);
1220
-
1221
1128
  if (typeof lastValue === "string" && typeof value === "number") {
1222
1129
  // Construct a regular expression that checks for a string that consists
1223
1130
  // of the formData value suffixed with zero or one '.' characters and zero
1224
1131
  // or more '0' characters
1225
- const re = new RegExp(("" + value).replace(".", "\\.") + "\\.?0*$"); // If the cached "lastValue" is a match, use that instead of the formData
1132
+ const re = new RegExp(`${value}`.replace(".", "\\.") + "\\.?0*$");
1133
+ // If the cached "lastValue" is a match, use that instead of the formData
1226
1134
  // value to prevent the input value from changing in the UI
1227
-
1228
1135
  if (lastValue.match(re)) {
1229
1136
  value = lastValue;
1230
1137
  }
1231
1138
  }
1232
-
1233
- return /*#__PURE__*/React__default["default"].createElement(StringField, { ...props,
1139
+ return /*#__PURE__*/React__default["default"].createElement(StringField, {
1140
+ ...props,
1234
1141
  formData: value,
1235
1142
  onChange: handleChange
1236
1143
  });
@@ -1241,30 +1148,25 @@ function NumberField(props) {
1241
1148
  *
1242
1149
  * @param props - The `FieldProps` for this template
1243
1150
  */
1244
-
1245
1151
  class ObjectField extends React.Component {
1246
1152
  constructor() {
1247
1153
  var _this;
1248
-
1249
1154
  super(...arguments);
1250
1155
  _this = this;
1251
1156
  this.state = {
1252
1157
  wasPropertyKeyModified: false,
1253
1158
  additionalProperties: {}
1254
1159
  };
1255
-
1256
1160
  this.onPropertyChange = function (name, addedByAdditionalProperties) {
1257
1161
  if (addedByAdditionalProperties === void 0) {
1258
1162
  addedByAdditionalProperties = false;
1259
1163
  }
1260
-
1261
- return (value, newErrorSchema) => {
1164
+ return (value, newErrorSchema, id) => {
1262
1165
  const {
1263
1166
  formData,
1264
1167
  onChange,
1265
1168
  errorSchema
1266
1169
  } = _this.props;
1267
-
1268
1170
  if (value === undefined && addedByAdditionalProperties) {
1269
1171
  // Don't set value = undefined for fields added by
1270
1172
  // additionalProperties. Doing so removes them from the
@@ -1275,16 +1177,16 @@ class ObjectField extends React.Component {
1275
1177
  // set empty values to the empty string.
1276
1178
  value = "";
1277
1179
  }
1278
-
1279
- const newFormData = { ...formData,
1180
+ const newFormData = {
1181
+ ...formData,
1280
1182
  [name]: value
1281
1183
  };
1282
- onChange(newFormData, errorSchema && errorSchema && { ...errorSchema,
1184
+ onChange(newFormData, errorSchema && errorSchema && {
1185
+ ...errorSchema,
1283
1186
  [name]: newErrorSchema
1284
- });
1187
+ }, id);
1285
1188
  };
1286
1189
  };
1287
-
1288
1190
  this.onDropPropertyClick = key => {
1289
1191
  return event => {
1290
1192
  event.preventDefault();
@@ -1292,13 +1194,13 @@ class ObjectField extends React.Component {
1292
1194
  onChange,
1293
1195
  formData
1294
1196
  } = this.props;
1295
- const copiedFormData = { ...formData
1197
+ const copiedFormData = {
1198
+ ...formData
1296
1199
  };
1297
1200
  unset__default["default"](copiedFormData, key);
1298
1201
  onChange(copiedFormData);
1299
1202
  };
1300
1203
  };
1301
-
1302
1204
  this.getAvailableKey = (preferredKey, formData) => {
1303
1205
  const {
1304
1206
  uiSchema
@@ -1308,27 +1210,24 @@ class ObjectField extends React.Component {
1308
1210
  } = utils.getUiOptions(uiSchema);
1309
1211
  let index = 0;
1310
1212
  let newKey = preferredKey;
1311
-
1312
1213
  while (newKey in formData) {
1313
- newKey = "" + preferredKey + duplicateKeySuffixSeparator + ++index;
1214
+ newKey = `${preferredKey}${duplicateKeySuffixSeparator}${++index}`;
1314
1215
  }
1315
-
1316
1216
  return newKey;
1317
1217
  };
1318
-
1319
1218
  this.onKeyChange = oldValue => {
1320
1219
  return (value, newErrorSchema) => {
1321
1220
  if (oldValue === value) {
1322
1221
  return;
1323
1222
  }
1324
-
1325
1223
  const {
1326
1224
  formData,
1327
1225
  onChange,
1328
1226
  errorSchema
1329
1227
  } = this.props;
1330
1228
  value = this.getAvailableKey(value, formData);
1331
- const newFormData = { ...formData
1229
+ const newFormData = {
1230
+ ...formData
1332
1231
  };
1333
1232
  const newKeys = {
1334
1233
  [oldValue]: value
@@ -1343,43 +1242,43 @@ class ObjectField extends React.Component {
1343
1242
  this.setState({
1344
1243
  wasPropertyKeyModified: true
1345
1244
  });
1346
- onChange(renamedObj, errorSchema && errorSchema && { ...errorSchema,
1245
+ onChange(renamedObj, errorSchema && errorSchema && {
1246
+ ...errorSchema,
1347
1247
  [value]: newErrorSchema
1348
1248
  });
1349
1249
  };
1350
1250
  };
1351
-
1352
1251
  this.handleAddClick = schema => () => {
1353
- if (!isObject__default["default"](schema.additionalProperties)) {
1252
+ if (!schema.additionalProperties) {
1354
1253
  return;
1355
1254
  }
1356
-
1357
1255
  const {
1358
1256
  formData,
1359
1257
  onChange,
1360
1258
  registry
1361
1259
  } = this.props;
1362
- let type = schema.additionalProperties.type;
1363
- const newFormData = { ...formData
1260
+ const newFormData = {
1261
+ ...formData
1364
1262
  };
1365
-
1366
- if (utils.REF_KEY in schema.additionalProperties) {
1367
- const {
1368
- schemaUtils
1369
- } = registry;
1370
- const refSchema = schemaUtils.retrieveSchema({
1371
- $ref: schema.additionalProperties[utils.REF_KEY]
1372
- }, formData);
1373
- type = refSchema.type;
1263
+ let type = undefined;
1264
+ if (isObject__default["default"](schema.additionalProperties)) {
1265
+ type = schema.additionalProperties.type;
1266
+ if (utils.REF_KEY in schema.additionalProperties) {
1267
+ const {
1268
+ schemaUtils
1269
+ } = registry;
1270
+ const refSchema = schemaUtils.retrieveSchema({
1271
+ $ref: schema.additionalProperties[utils.REF_KEY]
1272
+ }, formData);
1273
+ type = refSchema.type;
1274
+ }
1374
1275
  }
1375
-
1376
- const newKey = this.getAvailableKey("newKey", newFormData); // Cast this to make the `set` work properly
1377
-
1276
+ const newKey = this.getAvailableKey("newKey", newFormData);
1277
+ // Cast this to make the `set` work properly
1378
1278
  set__default["default"](newFormData, newKey, this.getDefaultValue(type));
1379
1279
  onChange(newFormData);
1380
1280
  };
1381
1281
  }
1382
-
1383
1282
  /** Returns a flag indicating whether the `name` field is required in the object schema
1384
1283
  *
1385
1284
  * @param name - The name of the field to check for required-ness
@@ -1400,7 +1299,6 @@ class ObjectField extends React.Component {
1400
1299
  * @returns - The onPropertyChange callback for the `name` property
1401
1300
  */
1402
1301
 
1403
-
1404
1302
  /** Returns a default value to be used for a new additional schema property of the given `type`
1405
1303
  *
1406
1304
  * @param type - The type of the new additional schema property
@@ -1409,22 +1307,16 @@ class ObjectField extends React.Component {
1409
1307
  switch (type) {
1410
1308
  case "string":
1411
1309
  return "New Value";
1412
-
1413
1310
  case "array":
1414
1311
  return [];
1415
-
1416
1312
  case "boolean":
1417
1313
  return false;
1418
-
1419
1314
  case "null":
1420
1315
  return null;
1421
-
1422
1316
  case "number":
1423
1317
  return 0;
1424
-
1425
1318
  case "object":
1426
1319
  return {};
1427
-
1428
1320
  default:
1429
1321
  // We don't have a datatype for some reason (perhaps additionalProperties was true)
1430
1322
  return "New Value";
@@ -1436,7 +1328,6 @@ class ObjectField extends React.Component {
1436
1328
  * @param schema - The schema element to which the new property is being added
1437
1329
  */
1438
1330
 
1439
-
1440
1331
  /** Renders the `ObjectField` from the given props
1441
1332
  */
1442
1333
  render() {
@@ -1473,7 +1364,6 @@ class ObjectField extends React.Component {
1473
1364
  const title = schema.title === undefined ? name : schema.title;
1474
1365
  const description = uiOptions.description || schema.description;
1475
1366
  let orderedProperties;
1476
-
1477
1367
  try {
1478
1368
  const properties = Object.keys(schemaProperties);
1479
1369
  orderedProperties = utils.orderProperties(properties, uiOptions.order);
@@ -1485,7 +1375,6 @@ class ObjectField extends React.Component {
1485
1375
  }
1486
1376
  }, "Invalid ", name || "root", " object field configuration:", /*#__PURE__*/React__default["default"].createElement("em", null, err.message), "."), /*#__PURE__*/React__default["default"].createElement("pre", null, JSON.stringify(schema)));
1487
1377
  }
1488
-
1489
1378
  const Template = utils.getTemplate("ObjectFieldTemplate", registry, uiOptions);
1490
1379
  const templateProps = {
1491
1380
  title: uiOptions.title || title,
@@ -1536,15 +1425,14 @@ class ObjectField extends React.Component {
1536
1425
  formContext,
1537
1426
  registry
1538
1427
  };
1539
- return /*#__PURE__*/React__default["default"].createElement(Template, { ...templateProps,
1428
+ return /*#__PURE__*/React__default["default"].createElement(Template, {
1429
+ ...templateProps,
1540
1430
  onAddClick: this.handleAddClick
1541
1431
  });
1542
1432
  }
1543
-
1544
1433
  }
1545
1434
 
1546
1435
  /** The map of component type to FieldName */
1547
-
1548
1436
  const COMPONENT_TYPES = {
1549
1437
  array: "ArrayField",
1550
1438
  boolean: "BooleanField",
@@ -1564,36 +1452,31 @@ const COMPONENT_TYPES = {
1564
1452
  * @param registry - The registry from which fields and templates are obtained
1565
1453
  * @returns - The `Field` component that is used to render the actual field data
1566
1454
  */
1567
-
1568
1455
  function getFieldComponent(schema, uiOptions, idSchema, registry) {
1569
1456
  const field = uiOptions.field;
1570
1457
  const {
1571
1458
  fields
1572
1459
  } = registry;
1573
-
1574
1460
  if (typeof field === "function") {
1575
1461
  return field;
1576
1462
  }
1577
-
1578
1463
  if (typeof field === "string" && field in fields) {
1579
1464
  return fields[field];
1580
1465
  }
1581
-
1582
1466
  const schemaType = utils.getSchemaType(schema);
1583
1467
  const type = Array.isArray(schemaType) ? schemaType[0] : schemaType || "";
1584
- const componentName = COMPONENT_TYPES[type]; // If the type is not defined and the schema uses 'anyOf' or 'oneOf', don't
1468
+ const componentName = COMPONENT_TYPES[type];
1469
+ // If the type is not defined and the schema uses 'anyOf' or 'oneOf', don't
1585
1470
  // render a field and let the MultiSchemaField component handle the form display
1586
-
1587
1471
  if (!componentName && (schema.anyOf || schema.oneOf)) {
1588
1472
  return () => null;
1589
1473
  }
1590
-
1591
1474
  return componentName in fields ? fields[componentName] : () => {
1592
1475
  const UnsupportedFieldTemplate = utils.getTemplate("UnsupportedFieldTemplate", registry, uiOptions);
1593
1476
  return /*#__PURE__*/React__default["default"].createElement(UnsupportedFieldTemplate, {
1594
1477
  schema: schema,
1595
1478
  idSchema: idSchema,
1596
- reason: "Unknown field type " + schema.type,
1479
+ reason: `Unknown field type ${schema.type}`,
1597
1480
  registry: registry
1598
1481
  });
1599
1482
  };
@@ -1604,8 +1487,6 @@ function getFieldComponent(schema, uiOptions, idSchema, registry) {
1604
1487
  *
1605
1488
  * @param props - The `FieldProps` for this component
1606
1489
  */
1607
-
1608
-
1609
1490
  function SchemaFieldRender(props) {
1610
1491
  const {
1611
1492
  schema: _schema,
@@ -1633,32 +1514,38 @@ function SchemaFieldRender(props) {
1633
1514
  const FieldHelpTemplate = utils.getTemplate("FieldHelpTemplate", registry, uiOptions);
1634
1515
  const FieldErrorTemplate = utils.getTemplate("FieldErrorTemplate", registry, uiOptions);
1635
1516
  const schema = schemaUtils.retrieveSchema(_schema, formData);
1636
- const idSchema = utils.mergeObjects(schemaUtils.toIdSchema(schema, _idSchema.$id, formData, idPrefix, idSeparator), _idSchema);
1517
+ const fieldId = _idSchema[utils.ID_KEY];
1518
+ const idSchema = utils.mergeObjects(schemaUtils.toIdSchema(schema, fieldId, formData, idPrefix, idSeparator), _idSchema);
1519
+ /** Intermediary `onChange` handler for field components that will inject the `id` of the current field into the
1520
+ * `onChange` chain if it is not already being provided from a deeper level in the hierarchy
1521
+ */
1522
+ const handleFieldComponentChange = React__default["default"].useCallback((formData, newErrorSchema, id) => {
1523
+ const theId = id || fieldId;
1524
+ return onChange(formData, newErrorSchema, theId);
1525
+ }, [fieldId, onChange]);
1637
1526
  const FieldComponent = getFieldComponent(schema, uiOptions, idSchema, registry);
1638
1527
  const disabled = Boolean(props.disabled || uiOptions.disabled);
1639
1528
  const readonly = Boolean(props.readonly || uiOptions.readonly || props.schema.readOnly || schema.readOnly);
1640
- const uiSchemaHideError = uiOptions.hideError; // Set hideError to the value provided in the uiSchema, otherwise stick with the prop to propagate to children
1641
-
1529
+ const uiSchemaHideError = uiOptions.hideError;
1530
+ // Set hideError to the value provided in the uiSchema, otherwise stick with the prop to propagate to children
1642
1531
  const hideError = uiSchemaHideError === undefined ? props.hideError : Boolean(uiSchemaHideError);
1643
1532
  const autofocus = Boolean(props.autofocus || uiOptions.autofocus);
1644
-
1645
1533
  if (Object.keys(schema).length === 0) {
1646
1534
  return null;
1647
1535
  }
1648
-
1649
1536
  const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema);
1650
1537
  const {
1651
1538
  __errors,
1652
1539
  ...fieldErrorSchema
1653
- } = errorSchema || {}; // See #439: uiSchema: Don't pass consumed class names to child components
1654
-
1540
+ } = errorSchema || {};
1541
+ // See #439: uiSchema: Don't pass consumed class names to child components
1655
1542
  const fieldUiSchema = omit__default["default"](uiSchema, ["ui:classNames", "classNames"]);
1656
-
1657
1543
  if ("ui:options" in fieldUiSchema) {
1658
1544
  fieldUiSchema["ui:options"] = omit__default["default"](fieldUiSchema["ui:options"], ["classNames"]);
1659
1545
  }
1660
-
1661
- const field = /*#__PURE__*/React__default["default"].createElement(FieldComponent, { ...props,
1546
+ const field = /*#__PURE__*/React__default["default"].createElement(FieldComponent, {
1547
+ ...props,
1548
+ onChange: handleFieldComponentChange,
1662
1549
  idSchema: idSchema,
1663
1550
  schema: schema,
1664
1551
  uiSchema: fieldUiSchema,
@@ -1670,37 +1557,30 @@ function SchemaFieldRender(props) {
1670
1557
  formContext: formContext,
1671
1558
  rawErrors: __errors
1672
1559
  });
1673
- const id = idSchema[utils.ID_KEY]; // If this schema has a title defined, but the user has set a new key/label, retain their input.
1674
-
1560
+ const id = idSchema[utils.ID_KEY];
1561
+ // If this schema has a title defined, but the user has set a new key/label, retain their input.
1675
1562
  let label;
1676
-
1677
1563
  if (wasPropertyKeyModified) {
1678
1564
  label = name;
1679
1565
  } else {
1680
1566
  label = utils.ADDITIONAL_PROPERTY_FLAG in schema ? name : uiOptions.title || props.schema.title || schema.title || name;
1681
1567
  }
1682
-
1683
1568
  const description = uiOptions.description || props.schema.description || schema.description || "";
1684
1569
  const help = uiOptions.help;
1685
1570
  const hidden = uiOptions.widget === "hidden";
1686
- const classNames = ["form-group", "field", "field-" + schema.type];
1687
-
1571
+ const classNames = ["form-group", "field", `field-${schema.type}`];
1688
1572
  if (!hideError && __errors && __errors.length > 0) {
1689
1573
  classNames.push("field-error has-error has-danger");
1690
1574
  }
1691
-
1692
1575
  if (uiSchema !== null && uiSchema !== void 0 && uiSchema.classNames) {
1693
1576
  {
1694
1577
  console.warn("'uiSchema.classNames' is deprecated and may be removed in a major release; Use 'ui:classNames' instead.");
1695
1578
  }
1696
-
1697
1579
  classNames.push(uiSchema.classNames);
1698
1580
  }
1699
-
1700
1581
  if (uiOptions.classNames) {
1701
1582
  classNames.push(uiOptions.classNames);
1702
1583
  }
1703
-
1704
1584
  const helpComponent = /*#__PURE__*/React__default["default"].createElement(FieldHelpTemplate, {
1705
1585
  help: help,
1706
1586
  idSchema: idSchema,
@@ -1719,8 +1599,10 @@ function SchemaFieldRender(props) {
1719
1599
  });
1720
1600
  const fieldProps = {
1721
1601
  description: /*#__PURE__*/React__default["default"].createElement(DescriptionFieldTemplate, {
1722
- id: id + "__description",
1602
+ id: `${id}__description`,
1723
1603
  description: description,
1604
+ schema: schema,
1605
+ uiSchema: uiSchema,
1724
1606
  registry: registry
1725
1607
  }),
1726
1608
  rawDescription: description,
@@ -1748,7 +1630,8 @@ function SchemaFieldRender(props) {
1748
1630
  };
1749
1631
  const _AnyOfField = registry.fields.AnyOfField;
1750
1632
  const _OneOfField = registry.fields.OneOfField;
1751
- return /*#__PURE__*/React__default["default"].createElement(FieldTemplate, { ...fieldProps
1633
+ return /*#__PURE__*/React__default["default"].createElement(FieldTemplate, {
1634
+ ...fieldProps
1752
1635
  }, /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, field, schema.anyOf && !(uiSchema !== null && uiSchema !== void 0 && uiSchema["ui:field"]) && !schemaUtils.isSelect(schema) && /*#__PURE__*/React__default["default"].createElement(_AnyOfField, {
1753
1636
  name: name,
1754
1637
  disabled: disabled,
@@ -1792,25 +1675,21 @@ function SchemaFieldRender(props) {
1792
1675
  /** The `SchemaField` component determines whether it is necessary to rerender the component based on any props changes
1793
1676
  * and if so, calls the `SchemaFieldRender` component with the props.
1794
1677
  */
1795
-
1796
-
1797
1678
  class SchemaField extends React__default["default"].Component {
1798
1679
  shouldComponentUpdate(nextProps) {
1799
1680
  return !utils.deepEquals(this.props, nextProps);
1800
1681
  }
1801
-
1802
1682
  render() {
1803
- return /*#__PURE__*/React__default["default"].createElement(SchemaFieldRender, { ...this.props
1683
+ return /*#__PURE__*/React__default["default"].createElement(SchemaFieldRender, {
1684
+ ...this.props
1804
1685
  });
1805
1686
  }
1806
-
1807
1687
  }
1808
1688
 
1809
1689
  /** The `StringField` component is used to render a schema field that represents a string type
1810
1690
  *
1811
1691
  * @param props - The `FieldProps` for this template
1812
1692
  */
1813
-
1814
1693
  function StringField(props) {
1815
1694
  const {
1816
1695
  schema,
@@ -1839,11 +1718,9 @@ function StringField(props) {
1839
1718
  } = registry;
1840
1719
  const enumOptions = schemaUtils.isSelect(schema) ? utils.optionsList(schema) : undefined;
1841
1720
  let defaultWidget = enumOptions ? "select" : "text";
1842
-
1843
1721
  if (format && utils.hasWidget(schema, format, widgets)) {
1844
1722
  defaultWidget = format;
1845
1723
  }
1846
-
1847
1724
  const {
1848
1725
  widget = defaultWidget,
1849
1726
  placeholder = "",
@@ -1851,7 +1728,8 @@ function StringField(props) {
1851
1728
  } = utils.getUiOptions(uiSchema);
1852
1729
  const Widget = utils.getWidget(schema, widget, widgets);
1853
1730
  return /*#__PURE__*/React__default["default"].createElement(Widget, {
1854
- options: { ...options,
1731
+ options: {
1732
+ ...options,
1855
1733
  enumOptions
1856
1734
  },
1857
1735
  schema: schema,
@@ -1878,7 +1756,6 @@ function StringField(props) {
1878
1756
  *
1879
1757
  * @param props - The `FieldProps` for this template
1880
1758
  */
1881
-
1882
1759
  function NullField(props) {
1883
1760
  const {
1884
1761
  formData,
@@ -1892,43 +1769,48 @@ function NullField(props) {
1892
1769
  return null;
1893
1770
  }
1894
1771
 
1895
- const fields = {
1896
- AnyOfField: AnyOfField,
1897
- ArrayField,
1898
- // ArrayField falls back to SchemaField if ArraySchemaField is not defined, which it isn't by default
1899
- BooleanField,
1900
- NumberField,
1901
- ObjectField,
1902
- OneOfField: AnyOfField,
1903
- SchemaField,
1904
- StringField,
1905
- NullField
1906
- };
1772
+ function fields() {
1773
+ return {
1774
+ AnyOfField: AnyOfField,
1775
+ ArrayField: ArrayField,
1776
+ // ArrayField falls back to SchemaField if ArraySchemaField is not defined, which it isn't by default
1777
+ BooleanField,
1778
+ NumberField,
1779
+ ObjectField,
1780
+ OneOfField: AnyOfField,
1781
+ SchemaField,
1782
+ StringField,
1783
+ NullField
1784
+ };
1785
+ }
1907
1786
 
1908
1787
  /** The `ArrayFieldDescriptionTemplate` component renders a `DescriptionFieldTemplate` with an `id` derived from
1909
1788
  * the `idSchema`.
1910
1789
  *
1911
1790
  * @param props - The `ArrayFieldDescriptionProps` for the component
1912
1791
  */
1913
-
1914
1792
  function ArrayFieldDescriptionTemplate(props) {
1915
1793
  const {
1916
1794
  idSchema,
1917
1795
  description,
1918
1796
  registry,
1797
+ schema,
1919
1798
  uiSchema
1920
1799
  } = props;
1921
-
1922
- if (!description) {
1800
+ const options = utils.getUiOptions(uiSchema);
1801
+ const {
1802
+ label: displayLabel = true
1803
+ } = options;
1804
+ if (!description || !displayLabel) {
1923
1805
  return null;
1924
1806
  }
1925
-
1926
- const options = utils.getUiOptions(uiSchema);
1927
1807
  const DescriptionFieldTemplate = utils.getTemplate("DescriptionFieldTemplate", registry, options);
1928
- const id = idSchema.$id + "__description";
1808
+ const id = `${idSchema.$id}__description`;
1929
1809
  return /*#__PURE__*/React__default["default"].createElement(DescriptionFieldTemplate, {
1930
1810
  id: id,
1931
1811
  description: description,
1812
+ schema: schema,
1813
+ uiSchema: uiSchema,
1932
1814
  registry: registry
1933
1815
  });
1934
1816
  }
@@ -1937,7 +1819,6 @@ function ArrayFieldDescriptionTemplate(props) {
1937
1819
  *
1938
1820
  * @param props - The `ArrayFieldTemplateItemType` props for the component
1939
1821
  */
1940
-
1941
1822
  function ArrayFieldItemTemplate(props) {
1942
1823
  const {
1943
1824
  children,
@@ -1999,7 +1880,6 @@ function ArrayFieldItemTemplate(props) {
1999
1880
  *
2000
1881
  * @param props - The `ArrayFieldTemplateItemType` props for the component
2001
1882
  */
2002
-
2003
1883
  function ArrayFieldTemplate(props) {
2004
1884
  const {
2005
1885
  canAdd,
@@ -2018,8 +1898,8 @@ function ArrayFieldTemplate(props) {
2018
1898
  const uiOptions = utils.getUiOptions(uiSchema);
2019
1899
  const ArrayFieldDescriptionTemplate = utils.getTemplate("ArrayFieldDescriptionTemplate", registry, uiOptions);
2020
1900
  const ArrayFieldItemTemplate = utils.getTemplate("ArrayFieldItemTemplate", registry, uiOptions);
2021
- const ArrayFieldTitleTemplate = utils.getTemplate("ArrayFieldTitleTemplate", registry, uiOptions); // Button templates are not overridden in the uiSchema
2022
-
1901
+ const ArrayFieldTitleTemplate = utils.getTemplate("ArrayFieldTitleTemplate", registry, uiOptions);
1902
+ // Button templates are not overridden in the uiSchema
2023
1903
  const {
2024
1904
  ButtonTemplates: {
2025
1905
  AddButton
@@ -2032,11 +1912,13 @@ function ArrayFieldTemplate(props) {
2032
1912
  idSchema: idSchema,
2033
1913
  title: uiOptions.title || title,
2034
1914
  required: required,
1915
+ schema: schema,
2035
1916
  uiSchema: uiSchema,
2036
1917
  registry: registry
2037
- }), (uiOptions.description || schema.description) && /*#__PURE__*/React__default["default"].createElement(ArrayFieldDescriptionTemplate, {
1918
+ }), /*#__PURE__*/React__default["default"].createElement(ArrayFieldDescriptionTemplate, {
2038
1919
  idSchema: idSchema,
2039
1920
  description: uiOptions.description || schema.description,
1921
+ schema: schema,
2040
1922
  uiSchema: uiSchema,
2041
1923
  registry: registry
2042
1924
  }), /*#__PURE__*/React__default["default"].createElement("div", {
@@ -2063,27 +1945,29 @@ function ArrayFieldTemplate(props) {
2063
1945
  *
2064
1946
  * @param props - The `ArrayFieldTitleProps` for the component
2065
1947
  */
2066
-
2067
1948
  function ArrayFieldTitleTemplate(props) {
2068
1949
  const {
2069
1950
  idSchema,
2070
1951
  title,
1952
+ schema,
2071
1953
  uiSchema,
2072
1954
  required,
2073
1955
  registry
2074
1956
  } = props;
2075
-
2076
- if (!title) {
1957
+ const options = utils.getUiOptions(uiSchema);
1958
+ const {
1959
+ label: displayLabel = true
1960
+ } = options;
1961
+ if (!title || !displayLabel) {
2077
1962
  return null;
2078
1963
  }
2079
-
2080
- const options = utils.getUiOptions(uiSchema);
2081
1964
  const TitleFieldTemplate = utils.getTemplate("TitleFieldTemplate", registry, options);
2082
- const id = idSchema.$id + "__title";
1965
+ const id = `${idSchema.$id}__title`;
2083
1966
  return /*#__PURE__*/React__default["default"].createElement(TitleFieldTemplate, {
2084
1967
  id: id,
2085
1968
  title: title,
2086
1969
  required: required,
1970
+ schema: schema,
2087
1971
  uiSchema: uiSchema,
2088
1972
  registry: registry
2089
1973
  });
@@ -2095,7 +1979,6 @@ function ArrayFieldTitleTemplate(props) {
2095
1979
  *
2096
1980
  * @param props - The `WidgetProps` for this template
2097
1981
  */
2098
-
2099
1982
  function BaseInputTemplate(props) {
2100
1983
  const {
2101
1984
  id,
@@ -2114,25 +1997,23 @@ function BaseInputTemplate(props) {
2114
1997
  rawErrors,
2115
1998
  type,
2116
1999
  ...rest
2117
- } = props; // Note: since React 15.2.0 we can't forward unknown element attributes, so we
2000
+ } = props;
2001
+ // Note: since React 15.2.0 we can't forward unknown element attributes, so we
2118
2002
  // exclude the "options" and "schema" ones here.
2119
-
2120
2003
  if (!id) {
2121
2004
  console.log("No id for", props);
2122
- throw new Error("no id for props " + JSON.stringify(props));
2005
+ throw new Error(`no id for props ${JSON.stringify(props)}`);
2123
2006
  }
2124
-
2125
- const inputProps = { ...rest,
2007
+ const inputProps = {
2008
+ ...rest,
2126
2009
  ...utils.getInputProps(schema, type, options)
2127
2010
  };
2128
2011
  let inputValue;
2129
-
2130
2012
  if (inputProps.type === "number" || inputProps.type === "integer") {
2131
2013
  inputValue = value || value === 0 ? value : "";
2132
2014
  } else {
2133
2015
  inputValue = value == null ? "" : value;
2134
2016
  }
2135
-
2136
2017
  const _onChange = React.useCallback(_ref => {
2137
2018
  let {
2138
2019
  target: {
@@ -2141,7 +2022,6 @@ function BaseInputTemplate(props) {
2141
2022
  } = _ref;
2142
2023
  return onChange(value === "" ? options.emptyValue : value);
2143
2024
  }, [onChange, options]);
2144
-
2145
2025
  const _onBlur = React.useCallback(_ref2 => {
2146
2026
  let {
2147
2027
  target: {
@@ -2150,7 +2030,6 @@ function BaseInputTemplate(props) {
2150
2030
  } = _ref2;
2151
2031
  return onBlur(id, value);
2152
2032
  }, [onBlur, id]);
2153
-
2154
2033
  const _onFocus = React.useCallback(_ref3 => {
2155
2034
  let {
2156
2035
  target: {
@@ -2159,7 +2038,6 @@ function BaseInputTemplate(props) {
2159
2038
  } = _ref3;
2160
2039
  return onFocus(id, value);
2161
2040
  }, [onFocus, id]);
2162
-
2163
2041
  return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement("input", {
2164
2042
  id: id,
2165
2043
  name: id,
@@ -2169,13 +2047,13 @@ function BaseInputTemplate(props) {
2169
2047
  autoFocus: autofocus,
2170
2048
  value: inputValue,
2171
2049
  ...inputProps,
2172
- list: schema.examples ? "examples_" + id : undefined,
2050
+ list: schema.examples ? `examples_${id}` : undefined,
2173
2051
  onChange: _onChange,
2174
2052
  onBlur: _onBlur,
2175
2053
  onFocus: _onFocus
2176
2054
  }), Array.isArray(schema.examples) && /*#__PURE__*/React__default["default"].createElement("datalist", {
2177
- key: "datalist_" + id,
2178
- id: "examples_" + id
2055
+ key: `datalist_${id}`,
2056
+ id: `examples_${id}`
2179
2057
  }, [...new Set(schema.examples.concat(schema.default ? [schema.default] : []))].map(example => /*#__PURE__*/React__default["default"].createElement("option", {
2180
2058
  key: example,
2181
2059
  value: example
@@ -2184,7 +2062,6 @@ function BaseInputTemplate(props) {
2184
2062
 
2185
2063
  /** The `SubmitButton` renders a button that represent the `Submit` action on a form
2186
2064
  */
2187
-
2188
2065
  function SubmitButton(_ref) {
2189
2066
  let {
2190
2067
  uiSchema
@@ -2194,15 +2071,13 @@ function SubmitButton(_ref) {
2194
2071
  norender,
2195
2072
  props: submitButtonProps = {}
2196
2073
  } = utils.getSubmitButtonOptions(uiSchema);
2197
-
2198
2074
  if (norender) {
2199
2075
  return null;
2200
2076
  }
2201
-
2202
2077
  return /*#__PURE__*/React__default["default"].createElement("div", null, /*#__PURE__*/React__default["default"].createElement("button", {
2203
2078
  type: "submit",
2204
2079
  ...submitButtonProps,
2205
- className: "btn btn-info " + submitButtonProps.className
2080
+ className: `btn btn-info ${submitButtonProps.className}`
2206
2081
  }, submitText));
2207
2082
  }
2208
2083
 
@@ -2216,10 +2091,10 @@ function IconButton(props) {
2216
2091
  } = props;
2217
2092
  return /*#__PURE__*/React__default["default"].createElement("button", {
2218
2093
  type: "button",
2219
- className: "btn btn-" + iconType + " " + className,
2094
+ className: `btn btn-${iconType} ${className}`,
2220
2095
  ...otherProps
2221
2096
  }, /*#__PURE__*/React__default["default"].createElement("i", {
2222
- className: "glyphicon glyphicon-" + icon
2097
+ className: `glyphicon glyphicon-${icon}`
2223
2098
  }));
2224
2099
  }
2225
2100
  function MoveDownButton(props) {
@@ -2250,7 +2125,6 @@ function RemoveButton(props) {
2250
2125
 
2251
2126
  /** The `AddButton` renders a button that represent the `Add` action on a form
2252
2127
  */
2253
-
2254
2128
  function AddButton(_ref) {
2255
2129
  let {
2256
2130
  className,
@@ -2260,7 +2134,7 @@ function AddButton(_ref) {
2260
2134
  return /*#__PURE__*/React__default["default"].createElement("div", {
2261
2135
  className: "row"
2262
2136
  }, /*#__PURE__*/React__default["default"].createElement("p", {
2263
- className: "col-xs-3 col-xs-offset-9 text-right " + className
2137
+ className: `col-xs-3 col-xs-offset-9 text-right ${className}`
2264
2138
  }, /*#__PURE__*/React__default["default"].createElement(IconButton, {
2265
2139
  iconType: "info",
2266
2140
  icon: "plus",
@@ -2271,29 +2145,28 @@ function AddButton(_ref) {
2271
2145
  })));
2272
2146
  }
2273
2147
 
2274
- const buttonTemplates = {
2275
- SubmitButton,
2276
- AddButton,
2277
- MoveDownButton,
2278
- MoveUpButton,
2279
- RemoveButton
2280
- };
2148
+ function buttonTemplates() {
2149
+ return {
2150
+ SubmitButton,
2151
+ AddButton,
2152
+ MoveDownButton,
2153
+ MoveUpButton,
2154
+ RemoveButton
2155
+ };
2156
+ }
2281
2157
 
2282
2158
  /** The `DescriptionField` is the template to use to render the description of a field
2283
2159
  *
2284
2160
  * @param props - The `DescriptionFieldProps` for this component
2285
2161
  */
2286
-
2287
2162
  function DescriptionField(props) {
2288
2163
  const {
2289
2164
  id,
2290
2165
  description
2291
2166
  } = props;
2292
-
2293
2167
  if (!description) {
2294
2168
  return null;
2295
2169
  }
2296
-
2297
2170
  if (typeof description === "string") {
2298
2171
  return /*#__PURE__*/React__default["default"].createElement("p", {
2299
2172
  id: id,
@@ -2311,7 +2184,6 @@ function DescriptionField(props) {
2311
2184
  *
2312
2185
  * @param props - The `ErrorListProps` for this component
2313
2186
  */
2314
-
2315
2187
  function ErrorList(_ref) {
2316
2188
  let {
2317
2189
  errors
@@ -2337,18 +2209,15 @@ const REQUIRED_FIELD_SYMBOL$1 = "*";
2337
2209
  *
2338
2210
  * @param props - The `LabelProps` for this component
2339
2211
  */
2340
-
2341
2212
  function Label(props) {
2342
2213
  const {
2343
2214
  label,
2344
2215
  required,
2345
2216
  id
2346
2217
  } = props;
2347
-
2348
2218
  if (!label) {
2349
2219
  return null;
2350
2220
  }
2351
-
2352
2221
  return /*#__PURE__*/React__default["default"].createElement("label", {
2353
2222
  className: "control-label",
2354
2223
  htmlFor: id
@@ -2362,7 +2231,6 @@ function Label(props) {
2362
2231
  *
2363
2232
  * @param props - The `FieldTemplateProps` for this component
2364
2233
  */
2365
-
2366
2234
  function FieldTemplate(props) {
2367
2235
  const {
2368
2236
  id,
@@ -2379,14 +2247,13 @@ function FieldTemplate(props) {
2379
2247
  } = props;
2380
2248
  const uiOptions = utils.getUiOptions(uiSchema);
2381
2249
  const WrapIfAdditionalTemplate = utils.getTemplate("WrapIfAdditionalTemplate", registry, uiOptions);
2382
-
2383
2250
  if (hidden) {
2384
2251
  return /*#__PURE__*/React__default["default"].createElement("div", {
2385
2252
  className: "hidden"
2386
2253
  }, children);
2387
2254
  }
2388
-
2389
- return /*#__PURE__*/React__default["default"].createElement(WrapIfAdditionalTemplate, { ...props
2255
+ return /*#__PURE__*/React__default["default"].createElement(WrapIfAdditionalTemplate, {
2256
+ ...props
2390
2257
  }, displayLabel && /*#__PURE__*/React__default["default"].createElement(Label, {
2391
2258
  label: label,
2392
2259
  required: required,
@@ -2398,18 +2265,15 @@ function FieldTemplate(props) {
2398
2265
  *
2399
2266
  * @param props - The `FieldErrorProps` for the errors being rendered
2400
2267
  */
2401
-
2402
2268
  function FieldErrorTemplate(props) {
2403
2269
  const {
2404
2270
  errors = [],
2405
2271
  idSchema
2406
2272
  } = props;
2407
-
2408
2273
  if (errors.length === 0) {
2409
2274
  return null;
2410
2275
  }
2411
-
2412
- const id = idSchema.$id + "__error";
2276
+ const id = `${idSchema.$id}__error`;
2413
2277
  return /*#__PURE__*/React__default["default"].createElement("div", null, /*#__PURE__*/React__default["default"].createElement("ul", {
2414
2278
  id: id,
2415
2279
  className: "error-detail bs-callout bs-callout-info"
@@ -2425,26 +2289,21 @@ function FieldErrorTemplate(props) {
2425
2289
  *
2426
2290
  * @param props - The `FieldHelpProps` to be rendered
2427
2291
  */
2428
-
2429
2292
  function FieldHelpTemplate(props) {
2430
2293
  const {
2431
2294
  idSchema,
2432
2295
  help
2433
2296
  } = props;
2434
-
2435
2297
  if (!help) {
2436
2298
  return null;
2437
2299
  }
2438
-
2439
- const id = idSchema.$id + "__help";
2440
-
2300
+ const id = `${idSchema.$id}__help`;
2441
2301
  if (typeof help === "string") {
2442
2302
  return /*#__PURE__*/React__default["default"].createElement("p", {
2443
2303
  id: id,
2444
2304
  className: "help-block"
2445
2305
  }, help);
2446
2306
  }
2447
-
2448
2307
  return /*#__PURE__*/React__default["default"].createElement("div", {
2449
2308
  id: id,
2450
2309
  className: "help-block"
@@ -2457,7 +2316,6 @@ function FieldHelpTemplate(props) {
2457
2316
  *
2458
2317
  * @param props - The `ObjectFieldTemplateProps` for this component
2459
2318
  */
2460
-
2461
2319
  function ObjectFieldTemplate(props) {
2462
2320
  const {
2463
2321
  description,
@@ -2475,8 +2333,8 @@ function ObjectFieldTemplate(props) {
2475
2333
  } = props;
2476
2334
  const options = utils.getUiOptions(uiSchema);
2477
2335
  const TitleFieldTemplate = utils.getTemplate("TitleFieldTemplate", registry, options);
2478
- const DescriptionFieldTemplate = utils.getTemplate("DescriptionFieldTemplate", registry, options); // Button templates are not overridden in the uiSchema
2479
-
2336
+ const DescriptionFieldTemplate = utils.getTemplate("DescriptionFieldTemplate", registry, options);
2337
+ // Button templates are not overridden in the uiSchema
2480
2338
  const {
2481
2339
  ButtonTemplates: {
2482
2340
  AddButton
@@ -2485,14 +2343,17 @@ function ObjectFieldTemplate(props) {
2485
2343
  return /*#__PURE__*/React__default["default"].createElement("fieldset", {
2486
2344
  id: idSchema.$id
2487
2345
  }, (options.title || title) && /*#__PURE__*/React__default["default"].createElement(TitleFieldTemplate, {
2488
- id: idSchema.$id + "__title",
2346
+ id: `${idSchema.$id}__title`,
2489
2347
  title: options.title || title,
2490
2348
  required: required,
2349
+ schema: schema,
2491
2350
  uiSchema: uiSchema,
2492
2351
  registry: registry
2493
2352
  }), (options.description || description) && /*#__PURE__*/React__default["default"].createElement(DescriptionFieldTemplate, {
2494
- id: idSchema.$id + "__description",
2353
+ id: `${idSchema.$id}__description`,
2495
2354
  description: options.description || description,
2355
+ schema: schema,
2356
+ uiSchema: uiSchema,
2496
2357
  registry: registry
2497
2358
  }), properties.map(prop => prop.content), utils.canExpand(schema, uiSchema, formData) && /*#__PURE__*/React__default["default"].createElement(AddButton, {
2498
2359
  className: "object-property-expand",
@@ -2507,7 +2368,6 @@ const REQUIRED_FIELD_SYMBOL = "*";
2507
2368
  *
2508
2369
  * @param props - The `TitleFieldProps` for this component
2509
2370
  */
2510
-
2511
2371
  function TitleField(props) {
2512
2372
  const {
2513
2373
  id,
@@ -2526,7 +2386,6 @@ function TitleField(props) {
2526
2386
  *
2527
2387
  * @param props - The `FieldProps` for this template
2528
2388
  */
2529
-
2530
2389
  function UnsupportedField(props) {
2531
2390
  const {
2532
2391
  schema,
@@ -2543,7 +2402,6 @@ function UnsupportedField(props) {
2543
2402
  *
2544
2403
  * @param props - The `WrapIfAdditionalProps` for this component
2545
2404
  */
2546
-
2547
2405
  function WrapIfAdditionalTemplate(props) {
2548
2406
  const {
2549
2407
  id,
@@ -2558,21 +2416,18 @@ function WrapIfAdditionalTemplate(props) {
2558
2416
  children,
2559
2417
  uiSchema,
2560
2418
  registry
2561
- } = props; // Button templates are not overridden in the uiSchema
2562
-
2419
+ } = props;
2420
+ // Button templates are not overridden in the uiSchema
2563
2421
  const {
2564
2422
  RemoveButton
2565
2423
  } = registry.templates.ButtonTemplates;
2566
- const keyLabel = label + " Key"; // i18n ?
2567
-
2424
+ const keyLabel = `${label} Key`; // i18n ?
2568
2425
  const additional = (utils.ADDITIONAL_PROPERTY_FLAG in schema);
2569
-
2570
2426
  if (!additional) {
2571
2427
  return /*#__PURE__*/React__default["default"].createElement("div", {
2572
2428
  className: classNames
2573
2429
  }, children);
2574
2430
  }
2575
-
2576
2431
  return /*#__PURE__*/React__default["default"].createElement("div", {
2577
2432
  className: classNames
2578
2433
  }, /*#__PURE__*/React__default["default"].createElement("div", {
@@ -2584,11 +2439,11 @@ function WrapIfAdditionalTemplate(props) {
2584
2439
  }, /*#__PURE__*/React__default["default"].createElement(Label, {
2585
2440
  label: keyLabel,
2586
2441
  required: required,
2587
- id: id + "-key"
2442
+ id: `${id}-key`
2588
2443
  }), /*#__PURE__*/React__default["default"].createElement("input", {
2589
2444
  className: "form-control",
2590
2445
  type: "text",
2591
- id: id + "-key",
2446
+ id: `${id}-key`,
2592
2447
  onBlur: event => onKeyChange(event.target.value),
2593
2448
  defaultValue: label
2594
2449
  }))), /*#__PURE__*/React__default["default"].createElement("div", {
@@ -2606,46 +2461,43 @@ function WrapIfAdditionalTemplate(props) {
2606
2461
  }))));
2607
2462
  }
2608
2463
 
2609
- const templates = {
2610
- ArrayFieldDescriptionTemplate,
2611
- ArrayFieldItemTemplate,
2612
- ArrayFieldTemplate,
2613
- ArrayFieldTitleTemplate,
2614
- ButtonTemplates: buttonTemplates,
2615
- BaseInputTemplate,
2616
- DescriptionFieldTemplate: DescriptionField,
2617
- ErrorListTemplate: ErrorList,
2618
- FieldTemplate,
2619
- FieldErrorTemplate,
2620
- FieldHelpTemplate,
2621
- ObjectFieldTemplate,
2622
- TitleFieldTemplate: TitleField,
2623
- UnsupportedFieldTemplate: UnsupportedField,
2624
- WrapIfAdditionalTemplate
2625
- };
2464
+ function templates() {
2465
+ return {
2466
+ ArrayFieldDescriptionTemplate,
2467
+ ArrayFieldItemTemplate,
2468
+ ArrayFieldTemplate,
2469
+ ArrayFieldTitleTemplate,
2470
+ ButtonTemplates: buttonTemplates(),
2471
+ BaseInputTemplate,
2472
+ DescriptionFieldTemplate: DescriptionField,
2473
+ ErrorListTemplate: ErrorList,
2474
+ FieldTemplate,
2475
+ FieldErrorTemplate,
2476
+ FieldHelpTemplate,
2477
+ ObjectFieldTemplate,
2478
+ TitleFieldTemplate: TitleField,
2479
+ UnsupportedFieldTemplate: UnsupportedField,
2480
+ WrapIfAdditionalTemplate
2481
+ };
2482
+ }
2626
2483
 
2627
2484
  function rangeOptions(start, stop) {
2628
2485
  const options = [];
2629
-
2630
2486
  for (let i = start; i <= stop; i++) {
2631
2487
  options.push({
2632
2488
  value: i,
2633
2489
  label: utils.pad(i, 2)
2634
2490
  });
2635
2491
  }
2636
-
2637
2492
  return options;
2638
2493
  }
2639
-
2640
2494
  function readyForChange(state) {
2641
2495
  return Object.values(state).every(value => value !== -1);
2642
2496
  }
2643
-
2644
2497
  function dateElementProps(state, time, yearsRange) {
2645
2498
  if (yearsRange === void 0) {
2646
2499
  yearsRange = [1900, new Date().getFullYear() + 2];
2647
2500
  }
2648
-
2649
2501
  const {
2650
2502
  year,
2651
2503
  month,
@@ -2667,7 +2519,6 @@ function dateElementProps(state, time, yearsRange) {
2667
2519
  range: [1, 31],
2668
2520
  value: day
2669
2521
  }];
2670
-
2671
2522
  if (time) {
2672
2523
  data.push({
2673
2524
  type: "hour",
@@ -2683,10 +2534,8 @@ function dateElementProps(state, time, yearsRange) {
2683
2534
  value: second
2684
2535
  });
2685
2536
  }
2686
-
2687
2537
  return data;
2688
2538
  }
2689
-
2690
2539
  function DateElement(_ref) {
2691
2540
  let {
2692
2541
  type,
@@ -2729,8 +2578,6 @@ function DateElement(_ref) {
2729
2578
  /** The `AltDateWidget` is an alternative widget for rendering date properties.
2730
2579
  * @param props - The `WidgetProps` for this component
2731
2580
  */
2732
-
2733
-
2734
2581
  function AltDateWidget(_ref2) {
2735
2582
  let {
2736
2583
  time = false,
@@ -2746,7 +2593,8 @@ function AltDateWidget(_ref2) {
2746
2593
  value
2747
2594
  } = _ref2;
2748
2595
  const [state, setState] = React.useReducer((state, action) => {
2749
- return { ...state,
2596
+ return {
2597
+ ...state,
2750
2598
  ...action
2751
2599
  };
2752
2600
  }, utils.parseDateString(value, time));
@@ -2768,21 +2616,17 @@ function AltDateWidget(_ref2) {
2768
2616
  }, []);
2769
2617
  const handleSetNow = React.useCallback(event => {
2770
2618
  event.preventDefault();
2771
-
2772
2619
  if (disabled || readonly) {
2773
2620
  return;
2774
2621
  }
2775
-
2776
2622
  const nowDateObj = utils.parseDateString(new Date().toJSON(), time);
2777
2623
  setState(nowDateObj);
2778
2624
  }, [disabled, readonly, time]);
2779
2625
  const handleClear = React.useCallback(event => {
2780
2626
  event.preventDefault();
2781
-
2782
2627
  if (disabled || readonly) {
2783
2628
  return;
2784
2629
  }
2785
-
2786
2630
  setState(utils.parseDateString("", time));
2787
2631
  onChange(undefined);
2788
2632
  }, [disabled, readonly, time, onChange]);
@@ -2816,7 +2660,6 @@ function AltDateWidget(_ref2) {
2816
2660
  *
2817
2661
  * @param props - The `WidgetProps` for this component
2818
2662
  */
2819
-
2820
2663
  function AltDateTimeWidget(_ref) {
2821
2664
  let {
2822
2665
  time = true,
@@ -2836,10 +2679,10 @@ function AltDateTimeWidget(_ref) {
2836
2679
  *
2837
2680
  * @param props - The `WidgetProps` for this component
2838
2681
  */
2839
-
2840
2682
  function CheckboxWidget(_ref) {
2841
2683
  let {
2842
2684
  schema,
2685
+ uiSchema,
2843
2686
  options,
2844
2687
  id,
2845
2688
  value,
@@ -2852,19 +2695,21 @@ function CheckboxWidget(_ref) {
2852
2695
  onChange,
2853
2696
  registry
2854
2697
  } = _ref;
2855
- const DescriptionFieldTemplate = utils.getTemplate("DescriptionFieldTemplate", registry, options); // Because an unchecked checkbox will cause html5 validation to fail, only add
2698
+ const DescriptionFieldTemplate = utils.getTemplate("DescriptionFieldTemplate", registry, options);
2699
+ // Because an unchecked checkbox will cause html5 validation to fail, only add
2856
2700
  // the "required" attribute if the field value must be "true", due to the
2857
2701
  // "const" or "enum" keywords
2858
-
2859
2702
  const required = utils.schemaRequiresTrueValue(schema);
2860
2703
  const handleChange = React.useCallback(event => onChange(event.target.checked), [onChange]);
2861
2704
  const handleBlur = React.useCallback(event => onBlur(id, event.target.checked), [onBlur, id]);
2862
2705
  const handleFocus = React.useCallback(event => onFocus(id, event.target.checked), [onFocus, id]);
2863
2706
  return /*#__PURE__*/React__default["default"].createElement("div", {
2864
- className: "checkbox " + (disabled || readonly ? "disabled" : "")
2707
+ className: `checkbox ${disabled || readonly ? "disabled" : ""}`
2865
2708
  }, schema.description && /*#__PURE__*/React__default["default"].createElement(DescriptionFieldTemplate, {
2866
2709
  id: id + "__description",
2867
2710
  description: schema.description,
2711
+ schema: schema,
2712
+ uiSchema: uiSchema,
2868
2713
  registry: registry
2869
2714
  }), /*#__PURE__*/React__default["default"].createElement("label", null, /*#__PURE__*/React__default["default"].createElement("input", {
2870
2715
  type: "checkbox",
@@ -2882,12 +2727,11 @@ function CheckboxWidget(_ref) {
2882
2727
 
2883
2728
  function selectValue(value, selected, all) {
2884
2729
  const at = all.indexOf(value);
2885
- const updated = selected.slice(0, at).concat(value, selected.slice(at)); // As inserting values at predefined index positions doesn't work with empty
2730
+ const updated = selected.slice(0, at).concat(value, selected.slice(at));
2731
+ // As inserting values at predefined index positions doesn't work with empty
2886
2732
  // arrays, we need to reorder the updated selection to match the initial order
2887
-
2888
2733
  return updated.sort((a, b) => Number(all.indexOf(a) > all.indexOf(b)));
2889
2734
  }
2890
-
2891
2735
  function deselectValue(value, selected) {
2892
2736
  return selected.filter(v => v !== value);
2893
2737
  }
@@ -2896,8 +2740,6 @@ function deselectValue(value, selected) {
2896
2740
  *
2897
2741
  * @param props - The `WidgetProps` for this component
2898
2742
  */
2899
-
2900
-
2901
2743
  function CheckboxesWidget(_ref) {
2902
2744
  let {
2903
2745
  id,
@@ -2919,7 +2761,6 @@ function CheckboxesWidget(_ref) {
2919
2761
  const checked = value.indexOf(option.value) !== -1;
2920
2762
  const itemDisabled = Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) != -1;
2921
2763
  const disabledCls = disabled || itemDisabled || readonly ? "disabled" : "";
2922
-
2923
2764
  const handleChange = event => {
2924
2765
  const all = enumOptions.map(_ref2 => {
2925
2766
  let {
@@ -2927,17 +2768,15 @@ function CheckboxesWidget(_ref) {
2927
2768
  } = _ref2;
2928
2769
  return value;
2929
2770
  });
2930
-
2931
2771
  if (event.target.checked) {
2932
2772
  onChange(selectValue(option.value, value, all));
2933
2773
  } else {
2934
2774
  onChange(deselectValue(option.value, value));
2935
2775
  }
2936
2776
  };
2937
-
2938
2777
  const checkbox = /*#__PURE__*/React__default["default"].createElement("span", null, /*#__PURE__*/React__default["default"].createElement("input", {
2939
2778
  type: "checkbox",
2940
- id: id + "-" + option.value,
2779
+ id: `${id}-${option.value}`,
2941
2780
  name: id,
2942
2781
  checked: checked,
2943
2782
  disabled: disabled || itemDisabled || readonly,
@@ -2946,10 +2785,10 @@ function CheckboxesWidget(_ref) {
2946
2785
  }), /*#__PURE__*/React__default["default"].createElement("span", null, option.label));
2947
2786
  return inline ? /*#__PURE__*/React__default["default"].createElement("label", {
2948
2787
  key: option.value,
2949
- className: "checkbox-inline " + disabledCls
2788
+ className: `checkbox-inline ${disabledCls}`
2950
2789
  }, checkbox) : /*#__PURE__*/React__default["default"].createElement("div", {
2951
2790
  key: option.value,
2952
- className: "checkbox " + disabledCls
2791
+ className: `checkbox ${disabledCls}`
2953
2792
  }, /*#__PURE__*/React__default["default"].createElement("label", null, checkbox));
2954
2793
  }));
2955
2794
  }
@@ -2959,7 +2798,6 @@ function CheckboxesWidget(_ref) {
2959
2798
  *
2960
2799
  * @param props - The `WidgetProps` for this component
2961
2800
  */
2962
-
2963
2801
  function ColorWidget(props) {
2964
2802
  const {
2965
2803
  disabled,
@@ -2980,7 +2818,6 @@ function ColorWidget(props) {
2980
2818
  *
2981
2819
  * @param props - The `WidgetProps` for this component
2982
2820
  */
2983
-
2984
2821
  function DateWidget(props) {
2985
2822
  const {
2986
2823
  onChange,
@@ -3001,7 +2838,6 @@ function DateWidget(props) {
3001
2838
  *
3002
2839
  * @param props - The `WidgetProps` for this component
3003
2840
  */
3004
-
3005
2841
  function DateTimeWidget(props) {
3006
2842
  const {
3007
2843
  onChange,
@@ -3022,7 +2858,6 @@ function DateTimeWidget(props) {
3022
2858
  *
3023
2859
  * @param props - The `WidgetProps` for this component
3024
2860
  */
3025
-
3026
2861
  function EmailWidget(props) {
3027
2862
  const {
3028
2863
  options,
@@ -3039,10 +2874,8 @@ function addNameToDataURL(dataURL, name) {
3039
2874
  if (dataURL === null) {
3040
2875
  return null;
3041
2876
  }
3042
-
3043
- return dataURL.replace(";base64", ";name=" + encodeURIComponent(name) + ";base64");
2877
+ return dataURL.replace(";base64", `;name=${encodeURIComponent(name)};base64`);
3044
2878
  }
3045
-
3046
2879
  function processFile(file) {
3047
2880
  const {
3048
2881
  name,
@@ -3052,10 +2885,8 @@ function processFile(file) {
3052
2885
  return new Promise((resolve, reject) => {
3053
2886
  const reader = new window.FileReader();
3054
2887
  reader.onerror = reject;
3055
-
3056
2888
  reader.onload = event => {
3057
2889
  var _event$target;
3058
-
3059
2890
  if (typeof ((_event$target = event.target) === null || _event$target === void 0 ? void 0 : _event$target.result) === "string") {
3060
2891
  resolve({
3061
2892
  dataURL: addNameToDataURL(event.target.result, name),
@@ -3072,24 +2903,19 @@ function processFile(file) {
3072
2903
  });
3073
2904
  }
3074
2905
  };
3075
-
3076
2906
  reader.readAsDataURL(file);
3077
2907
  });
3078
2908
  }
3079
-
3080
2909
  function processFiles(files) {
3081
2910
  return Promise.all(Array.from(files).map(processFile));
3082
2911
  }
3083
-
3084
2912
  function FilesInfo(_ref) {
3085
2913
  let {
3086
2914
  filesInfo
3087
2915
  } = _ref;
3088
-
3089
2916
  if (filesInfo.length === 0) {
3090
2917
  return null;
3091
2918
  }
3092
-
3093
2919
  return /*#__PURE__*/React__default["default"].createElement("ul", {
3094
2920
  className: "file-info"
3095
2921
  }, filesInfo.map((fileInfo, key) => {
@@ -3103,7 +2929,6 @@ function FilesInfo(_ref) {
3103
2929
  }, /*#__PURE__*/React__default["default"].createElement("strong", null, name), " (", type, ", ", size, " bytes)");
3104
2930
  }));
3105
2931
  }
3106
-
3107
2932
  function extractFileInfo(dataURLs) {
3108
2933
  return dataURLs.filter(dataURL => typeof dataURL !== "undefined").map(dataURL => {
3109
2934
  const {
@@ -3121,8 +2946,6 @@ function extractFileInfo(dataURLs) {
3121
2946
  * The `FileWidget` is a widget for rendering file upload fields.
3122
2947
  * It is typically used with a string property with data-url format.
3123
2948
  */
3124
-
3125
-
3126
2949
  function FileWidget(_ref2) {
3127
2950
  let {
3128
2951
  multiple,
@@ -3140,11 +2963,9 @@ function FileWidget(_ref2) {
3140
2963
  if (!event.target.files) {
3141
2964
  return;
3142
2965
  }
3143
-
3144
2966
  processFiles(event.target.files).then(filesInfoEvent => {
3145
2967
  setFilesInfo(filesInfoEvent);
3146
2968
  const newValue = filesInfoEvent.map(fileInfo => fileInfo.dataURL);
3147
-
3148
2969
  if (multiple) {
3149
2970
  onChange(newValue);
3150
2971
  } else {
@@ -3172,7 +2993,6 @@ function FileWidget(_ref2) {
3172
2993
  *
3173
2994
  * @param props - The `WidgetProps` for this component
3174
2995
  */
3175
-
3176
2996
  function HiddenWidget(_ref) {
3177
2997
  let {
3178
2998
  id,
@@ -3190,7 +3010,6 @@ function HiddenWidget(_ref) {
3190
3010
  *
3191
3011
  * @param props - The `WidgetProps` for this component
3192
3012
  */
3193
-
3194
3013
  function PasswordWidget(props) {
3195
3014
  const {
3196
3015
  options,
@@ -3208,7 +3027,6 @@ function PasswordWidget(props) {
3208
3027
  *
3209
3028
  * @param props - The `WidgetProps` for this component
3210
3029
  */
3211
-
3212
3030
  function RadioWidget(_ref) {
3213
3031
  let {
3214
3032
  options,
@@ -3228,9 +3046,9 @@ function RadioWidget(_ref) {
3228
3046
  enumOptions,
3229
3047
  enumDisabled,
3230
3048
  inline
3231
- } = options; // checked={checked} has been moved above name={name}, As mentioned in #349;
3049
+ } = options;
3050
+ // checked={checked} has been moved above name={name}, As mentioned in #349;
3232
3051
  // this is a temporary fix for radio button rendering bug in React, facebook/react#7630.
3233
-
3234
3052
  const handleBlur = React.useCallback(event => onBlur(id, event.target.value), [onBlur, id]);
3235
3053
  const handleFocus = React.useCallback(event => onFocus(id, event.target.value), [onFocus, id]);
3236
3054
  return /*#__PURE__*/React__default["default"].createElement("div", {
@@ -3240,12 +3058,10 @@ function RadioWidget(_ref) {
3240
3058
  const checked = option.value === value;
3241
3059
  const itemDisabled = Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) != -1;
3242
3060
  const disabledCls = disabled || itemDisabled || readonly ? "disabled" : "";
3243
-
3244
3061
  const handleChange = () => onChange(option.value);
3245
-
3246
3062
  const radio = /*#__PURE__*/React__default["default"].createElement("span", null, /*#__PURE__*/React__default["default"].createElement("input", {
3247
3063
  type: "radio",
3248
- id: id + "-" + option.value,
3064
+ id: `${id}-${option.value}`,
3249
3065
  checked: checked,
3250
3066
  name: name,
3251
3067
  required: required,
@@ -3258,10 +3074,10 @@ function RadioWidget(_ref) {
3258
3074
  }), /*#__PURE__*/React__default["default"].createElement("span", null, option.label));
3259
3075
  return inline ? /*#__PURE__*/React__default["default"].createElement("label", {
3260
3076
  key: option.value,
3261
- className: "radio-inline " + disabledCls
3077
+ className: `radio-inline ${disabledCls}`
3262
3078
  }, radio) : /*#__PURE__*/React__default["default"].createElement("div", {
3263
3079
  key: option.value,
3264
- className: "radio " + disabledCls
3080
+ className: `radio ${disabledCls}`
3265
3081
  }, /*#__PURE__*/React__default["default"].createElement("label", null, radio));
3266
3082
  }));
3267
3083
  }
@@ -3271,7 +3087,6 @@ function RadioWidget(_ref) {
3271
3087
  *
3272
3088
  * @param props - The `WidgetProps` for this component
3273
3089
  */
3274
-
3275
3090
  function RangeWidget(props) {
3276
3091
  const {
3277
3092
  value,
@@ -3295,7 +3110,6 @@ function getValue(event, multiple) {
3295
3110
  if (multiple) {
3296
3111
  return Array.from(event.target.options).slice().filter(o => o.selected).map(o => o.value);
3297
3112
  }
3298
-
3299
3113
  return event.target.value;
3300
3114
  }
3301
3115
  /** The `SelectWidget` is a widget for rendering dropdowns.
@@ -3303,8 +3117,6 @@ function getValue(event, multiple) {
3303
3117
  *
3304
3118
  * @param props - The `WidgetProps` for this component
3305
3119
  */
3306
-
3307
-
3308
3120
  function SelectWidget(_ref) {
3309
3121
  let {
3310
3122
  schema,
@@ -3370,7 +3182,6 @@ function SelectWidget(_ref) {
3370
3182
  *
3371
3183
  * @param props - The `WidgetProps` for this component
3372
3184
  */
3373
-
3374
3185
  function TextareaWidget(_ref) {
3375
3186
  let {
3376
3187
  id,
@@ -3425,7 +3236,6 @@ function TextareaWidget(_ref) {
3425
3236
  onChange: handleChange
3426
3237
  });
3427
3238
  }
3428
-
3429
3239
  TextareaWidget.defaultProps = {
3430
3240
  autofocus: false,
3431
3241
  options: {}
@@ -3435,14 +3245,14 @@ TextareaWidget.defaultProps = {
3435
3245
  *
3436
3246
  * @param props - The `WidgetProps` for this component
3437
3247
  */
3438
-
3439
3248
  function TextWidget(props) {
3440
3249
  const {
3441
3250
  options,
3442
3251
  registry
3443
3252
  } = props;
3444
3253
  const BaseInputTemplate = utils.getTemplate("BaseInputTemplate", registry, options);
3445
- return /*#__PURE__*/React__default["default"].createElement(BaseInputTemplate, { ...props
3254
+ return /*#__PURE__*/React__default["default"].createElement(BaseInputTemplate, {
3255
+ ...props
3446
3256
  });
3447
3257
  }
3448
3258
 
@@ -3450,7 +3260,6 @@ function TextWidget(props) {
3450
3260
  *
3451
3261
  * @param props - The `WidgetProps` for this component
3452
3262
  */
3453
-
3454
3263
  function URLWidget(props) {
3455
3264
  const {
3456
3265
  options,
@@ -3467,7 +3276,6 @@ function URLWidget(props) {
3467
3276
  *
3468
3277
  * @param props - The `WidgetProps` for this component
3469
3278
  */
3470
-
3471
3279
  function UpDownWidget(props) {
3472
3280
  const {
3473
3281
  options,
@@ -3480,44 +3288,44 @@ function UpDownWidget(props) {
3480
3288
  });
3481
3289
  }
3482
3290
 
3483
- const widgets = {
3484
- PasswordWidget,
3485
- RadioWidget,
3486
- UpDownWidget,
3487
- RangeWidget,
3488
- SelectWidget,
3489
- TextWidget,
3490
- DateWidget,
3491
- DateTimeWidget,
3492
- AltDateWidget,
3493
- AltDateTimeWidget,
3494
- EmailWidget,
3495
- URLWidget,
3496
- TextareaWidget,
3497
- HiddenWidget,
3498
- ColorWidget,
3499
- FileWidget,
3500
- CheckboxWidget,
3501
- CheckboxesWidget
3502
- };
3291
+ function widgets() {
3292
+ return {
3293
+ PasswordWidget,
3294
+ RadioWidget,
3295
+ UpDownWidget,
3296
+ RangeWidget,
3297
+ SelectWidget,
3298
+ TextWidget,
3299
+ DateWidget,
3300
+ DateTimeWidget,
3301
+ AltDateWidget,
3302
+ AltDateTimeWidget,
3303
+ EmailWidget,
3304
+ URLWidget,
3305
+ TextareaWidget,
3306
+ HiddenWidget,
3307
+ ColorWidget,
3308
+ FileWidget,
3309
+ CheckboxWidget,
3310
+ CheckboxesWidget
3311
+ };
3312
+ }
3503
3313
 
3504
3314
  /** The default registry consists of all the fields, templates and widgets provided in the core implementation,
3505
3315
  * plus an empty `rootSchema` and `formContext. We omit schemaUtils here because it cannot be defaulted without a
3506
3316
  * rootSchema and validator. It will be added into the computed registry later in the Form.
3507
3317
  */
3508
-
3509
3318
  function getDefaultRegistry() {
3510
3319
  return {
3511
- fields,
3512
- templates,
3513
- widgets,
3320
+ fields: fields(),
3321
+ templates: templates(),
3322
+ widgets: widgets(),
3514
3323
  rootSchema: {},
3515
3324
  formContext: {}
3516
3325
  };
3517
3326
  }
3518
3327
 
3519
3328
  /** The `Form` component renders the outer form and all the fields defined in the `schema` */
3520
-
3521
3329
  class Form extends React.Component {
3522
3330
  /** The ref used to hold the `form` element, this needs to be `any` because `tagName` or `_internalFormWrapper` can
3523
3331
  * provide any possible type here
@@ -3532,36 +3340,30 @@ class Form extends React.Component {
3532
3340
  constructor(props) {
3533
3341
  super(props);
3534
3342
  this.formElement = void 0;
3535
-
3536
3343
  this.getUsedFormData = (formData, fields) => {
3537
3344
  // For the case of a single input form
3538
3345
  if (fields.length === 0 && typeof formData !== "object") {
3539
3346
  return formData;
3540
3347
  }
3541
-
3348
+ // _pick has incorrect type definition, it works with string[][], because lodash/hasIn supports it
3542
3349
  const data = _pick__default["default"](formData, fields);
3543
-
3544
3350
  if (Array.isArray(formData)) {
3545
3351
  return Object.keys(data).map(key => data[key]);
3546
3352
  }
3547
-
3548
3353
  return data;
3549
3354
  };
3550
-
3551
3355
  this.getFieldNames = (pathSchema, formData) => {
3552
3356
  const getAllPaths = function (_obj, acc, paths) {
3553
3357
  if (acc === void 0) {
3554
3358
  acc = [];
3555
3359
  }
3556
-
3557
3360
  if (paths === void 0) {
3558
- paths = [""];
3361
+ paths = [[]];
3559
3362
  }
3560
-
3561
3363
  Object.keys(_obj).forEach(key => {
3562
3364
  if (typeof _obj[key] === "object") {
3563
- const newPaths = paths.map(path => path + "." + key); // If an object is marked with additionalProperties, all its keys are valid
3564
-
3365
+ const newPaths = paths.map(path => [...path, key]);
3366
+ // If an object is marked with additionalProperties, all its keys are valid
3565
3367
  if (_obj[key][utils.RJSF_ADDITONAL_PROPERTIES_FLAG] && _obj[key][utils.NAME_KEY] !== "") {
3566
3368
  acc.push(_obj[key][utils.NAME_KEY]);
3567
3369
  } else {
@@ -3569,12 +3371,9 @@ class Form extends React.Component {
3569
3371
  }
3570
3372
  } else if (key === utils.NAME_KEY && _obj[key] !== "") {
3571
3373
  paths.forEach(path => {
3572
- path = path.replace(/^\./, "");
3573
-
3574
- const formValue = get__default["default"](formData, path); // adds path to fieldNames if it points to a value
3374
+ const formValue = get__default["default"](formData, path);
3375
+ // adds path to fieldNames if it points to a value
3575
3376
  // or an empty object/array
3576
-
3577
-
3578
3377
  if (typeof formValue !== "object" || _isEmpty__default["default"](formValue)) {
3579
3378
  acc.push(path);
3580
3379
  }
@@ -3583,11 +3382,9 @@ class Form extends React.Component {
3583
3382
  });
3584
3383
  return acc;
3585
3384
  };
3586
-
3587
3385
  return getAllPaths(pathSchema);
3588
3386
  };
3589
-
3590
- this.onChange = (formData, newErrorSchema) => {
3387
+ this.onChange = (formData, newErrorSchema, id) => {
3591
3388
  const {
3592
3389
  extraErrors,
3593
3390
  omitExtraData,
@@ -3600,19 +3397,16 @@ class Form extends React.Component {
3600
3397
  schemaUtils,
3601
3398
  schema
3602
3399
  } = this.state;
3603
-
3604
3400
  if (utils.isObject(formData) || Array.isArray(formData)) {
3605
3401
  const newState = this.getStateFromProps(this.props, formData);
3606
3402
  formData = newState.formData;
3607
3403
  }
3608
-
3609
3404
  const mustValidate = !noValidate && liveValidate;
3610
3405
  let state = {
3611
3406
  formData,
3612
3407
  schema
3613
3408
  };
3614
3409
  let newFormData = formData;
3615
-
3616
3410
  if (omitExtraData === true && liveOmit === true) {
3617
3411
  const retrievedSchema = schemaUtils.retrieveSchema(schema, formData);
3618
3412
  const pathSchema = schemaUtils.toPathSchema(retrievedSchema, "", formData);
@@ -3622,20 +3416,17 @@ class Form extends React.Component {
3622
3416
  formData: newFormData
3623
3417
  };
3624
3418
  }
3625
-
3626
3419
  if (mustValidate) {
3627
3420
  const schemaValidation = this.validate(newFormData);
3628
3421
  let errors = schemaValidation.errors;
3629
3422
  let errorSchema = schemaValidation.errorSchema;
3630
3423
  const schemaValidationErrors = errors;
3631
3424
  const schemaValidationErrorSchema = errorSchema;
3632
-
3633
3425
  if (extraErrors) {
3634
3426
  const merged = schemaUtils.mergeValidationData(schemaValidation, extraErrors);
3635
3427
  errorSchema = merged.errorSchema;
3636
3428
  errors = merged.errors;
3637
3429
  }
3638
-
3639
3430
  state = {
3640
3431
  formData: newFormData,
3641
3432
  errors,
@@ -3651,39 +3442,32 @@ class Form extends React.Component {
3651
3442
  errors: schemaUtils.getValidator().toErrorList(errorSchema)
3652
3443
  };
3653
3444
  }
3654
-
3655
- this.setState(state, () => onChange && onChange({ ...this.state,
3445
+ this.setState(state, () => onChange && onChange({
3446
+ ...this.state,
3656
3447
  ...state
3657
- }));
3448
+ }, id));
3658
3449
  };
3659
-
3660
3450
  this.onBlur = (id, data) => {
3661
3451
  const {
3662
3452
  onBlur
3663
3453
  } = this.props;
3664
-
3665
3454
  if (onBlur) {
3666
3455
  onBlur(id, data);
3667
3456
  }
3668
3457
  };
3669
-
3670
3458
  this.onFocus = (id, data) => {
3671
3459
  const {
3672
3460
  onFocus
3673
3461
  } = this.props;
3674
-
3675
3462
  if (onFocus) {
3676
3463
  onFocus(id, data);
3677
3464
  }
3678
3465
  };
3679
-
3680
3466
  this.onSubmit = event => {
3681
3467
  event.preventDefault();
3682
-
3683
3468
  if (event.target !== event.currentTarget) {
3684
3469
  return;
3685
3470
  }
3686
-
3687
3471
  event.persist();
3688
3472
  const {
3689
3473
  omitExtraData,
@@ -3698,14 +3482,12 @@ class Form extends React.Component {
3698
3482
  schema,
3699
3483
  schemaUtils
3700
3484
  } = this.state;
3701
-
3702
3485
  if (omitExtraData === true) {
3703
3486
  const retrievedSchema = schemaUtils.retrieveSchema(schema, newFormData);
3704
3487
  const pathSchema = schemaUtils.toPathSchema(retrievedSchema, "", newFormData);
3705
3488
  const fieldNames = this.getFieldNames(pathSchema, newFormData);
3706
3489
  newFormData = this.getUsedFormData(newFormData, fieldNames);
3707
3490
  }
3708
-
3709
3491
  if (noValidate || this.validateForm()) {
3710
3492
  // There are no errors generated through schema validation.
3711
3493
  // Check for user provided errors and update state accordingly.
@@ -3719,7 +3501,8 @@ class Form extends React.Component {
3719
3501
  schemaValidationErrorSchema: {}
3720
3502
  }, () => {
3721
3503
  if (onSubmit) {
3722
- onSubmit({ ...this.state,
3504
+ onSubmit({
3505
+ ...this.state,
3723
3506
  formData: newFormData,
3724
3507
  status: "submitted"
3725
3508
  }, event);
@@ -3727,17 +3510,13 @@ class Form extends React.Component {
3727
3510
  });
3728
3511
  }
3729
3512
  };
3730
-
3731
3513
  if (!props.validator) {
3732
3514
  throw new Error("A validator is required for Form functionality to work");
3733
3515
  }
3734
-
3735
3516
  this.state = this.getStateFromProps(props, props.formData);
3736
-
3737
3517
  if (this.props.onChange && !utils.deepEquals(this.state.formData, this.props.formData)) {
3738
3518
  this.props.onChange(this.state);
3739
3519
  }
3740
-
3741
3520
  this.formElement = /*#__PURE__*/React__default["default"].createRef();
3742
3521
  }
3743
3522
  /** React lifecycle method that gets called before new props are provided, updates the state based on new props. It
@@ -3746,15 +3525,11 @@ class Form extends React.Component {
3746
3525
  *
3747
3526
  * @param nextProps - The new set of props about to be applied to the `Form`
3748
3527
  */
3749
-
3750
-
3751
3528
  UNSAFE_componentWillReceiveProps(nextProps) {
3752
3529
  const nextState = this.getStateFromProps(nextProps, nextProps.formData);
3753
-
3754
3530
  if (!utils.deepEquals(nextState.formData, nextProps.formData) && !utils.deepEquals(nextState.formData, this.state.formData) && nextProps.onChange) {
3755
3531
  nextProps.onChange(nextState);
3756
3532
  }
3757
-
3758
3533
  this.setState(nextState);
3759
3534
  }
3760
3535
  /** Extracts the updated state from the given `props` and `inputFormData`. As part of this process, the
@@ -3765,8 +3540,6 @@ class Form extends React.Component {
3765
3540
  * @param inputFormData - The new or current data for the `Form`
3766
3541
  * @returns - The new state for the `Form`
3767
3542
  */
3768
-
3769
-
3770
3543
  getStateFromProps(props, inputFormData) {
3771
3544
  const state = this.state || {};
3772
3545
  const schema = "schema" in props ? props.schema : this.props.schema;
@@ -3776,14 +3549,11 @@ class Form extends React.Component {
3776
3549
  const mustValidate = edit && !props.noValidate && liveValidate;
3777
3550
  const rootSchema = schema;
3778
3551
  let schemaUtils = state.schemaUtils;
3779
-
3780
3552
  if (!schemaUtils || schemaUtils.doesSchemaUtilsDiffer(props.validator, rootSchema)) {
3781
3553
  schemaUtils = utils.createSchemaUtils(props.validator, rootSchema);
3782
3554
  }
3783
-
3784
3555
  const formData = schemaUtils.getDefaultFormState(schema, inputFormData);
3785
3556
  const retrievedSchema = schemaUtils.retrieveSchema(schema, formData);
3786
-
3787
3557
  const getCurrentErrors = () => {
3788
3558
  if (props.noValidate) {
3789
3559
  return {
@@ -3796,18 +3566,15 @@ class Form extends React.Component {
3796
3566
  errorSchema: state.schemaValidationErrorSchema || {}
3797
3567
  };
3798
3568
  }
3799
-
3800
3569
  return {
3801
3570
  errors: state.errors || [],
3802
3571
  errorSchema: state.errorSchema || {}
3803
3572
  };
3804
3573
  };
3805
-
3806
3574
  let errors;
3807
3575
  let errorSchema;
3808
3576
  let schemaValidationErrors = state.schemaValidationErrors;
3809
3577
  let schemaValidationErrorSchema = state.schemaValidationErrorSchema;
3810
-
3811
3578
  if (mustValidate) {
3812
3579
  const schemaValidation = this.validate(formData, schema, schemaUtils);
3813
3580
  errors = schemaValidation.errors;
@@ -3819,7 +3586,6 @@ class Form extends React.Component {
3819
3586
  errors = currentErrors.errors;
3820
3587
  errorSchema = currentErrors.errorSchema;
3821
3588
  }
3822
-
3823
3589
  if (props.extraErrors) {
3824
3590
  const merged = schemaUtils.mergeValidationData({
3825
3591
  errorSchema,
@@ -3828,7 +3594,6 @@ class Form extends React.Component {
3828
3594
  errorSchema = merged.errorSchema;
3829
3595
  errors = merged.errors;
3830
3596
  }
3831
-
3832
3597
  const idSchema = schemaUtils.toIdSchema(retrievedSchema, uiSchema["ui:rootFieldId"], formData, props.idPrefix, props.idSeparator);
3833
3598
  const nextState = {
3834
3599
  schemaUtils,
@@ -3850,8 +3615,6 @@ class Form extends React.Component {
3850
3615
  * @param nextState - The next version of the state
3851
3616
  * @returns - True if the component should be updated, false otherwise
3852
3617
  */
3853
-
3854
-
3855
3618
  shouldComponentUpdate(nextProps, nextState) {
3856
3619
  return utils.shouldRender(this, nextProps, nextState);
3857
3620
  }
@@ -3862,13 +3625,10 @@ class Form extends React.Component {
3862
3625
  * @param schema - The schema used to validate against
3863
3626
  * @param altSchemaUtils - The alternate schemaUtils to use for validation
3864
3627
  */
3865
-
3866
-
3867
3628
  validate(formData, schema, altSchemaUtils) {
3868
3629
  if (schema === void 0) {
3869
3630
  schema = this.props.schema;
3870
3631
  }
3871
-
3872
3632
  const schemaUtils = altSchemaUtils ? altSchemaUtils : this.state.schemaUtils;
3873
3633
  const {
3874
3634
  customValidate,
@@ -3878,8 +3638,6 @@ class Form extends React.Component {
3878
3638
  return schemaUtils.getValidator().validateFormData(formData, resolvedSchema, customValidate, transformErrors);
3879
3639
  }
3880
3640
  /** Renders any errors contained in the `state` in using the `ErrorList`, if not disabled by `showErrorList`. */
3881
-
3882
-
3883
3641
  renderErrors(registry) {
3884
3642
  const {
3885
3643
  errors,
@@ -3888,13 +3646,11 @@ class Form extends React.Component {
3888
3646
  uiSchema
3889
3647
  } = this.state;
3890
3648
  const {
3891
- showErrorList,
3892
3649
  formContext
3893
3650
  } = this.props;
3894
3651
  const options = utils.getUiOptions(uiSchema);
3895
3652
  const ErrorListTemplate = utils.getTemplate("ErrorListTemplate", registry, options);
3896
-
3897
- if (errors && errors.length && showErrorList != false) {
3653
+ if (errors && errors.length) {
3898
3654
  return /*#__PURE__*/React__default["default"].createElement(ErrorListTemplate, {
3899
3655
  errors: errors,
3900
3656
  errorSchema: errorSchema || {},
@@ -3903,7 +3659,6 @@ class Form extends React.Component {
3903
3659
  formContext: formContext
3904
3660
  });
3905
3661
  }
3906
-
3907
3662
  return null;
3908
3663
  }
3909
3664
  /** Returns the `formData` with only the elements specified in the `fields` list
@@ -3912,11 +3667,9 @@ class Form extends React.Component {
3912
3667
  * @param fields - The fields to keep while filtering
3913
3668
  */
3914
3669
 
3915
-
3916
3670
  /** Returns the registry for the form */
3917
3671
  getRegistry() {
3918
3672
  var _this$props$templates;
3919
-
3920
3673
  const {
3921
3674
  schemaUtils
3922
3675
  } = this.state;
@@ -3927,16 +3680,20 @@ class Form extends React.Component {
3927
3680
  formContext
3928
3681
  } = getDefaultRegistry();
3929
3682
  return {
3930
- fields: { ...fields,
3683
+ fields: {
3684
+ ...fields,
3931
3685
  ...this.props.fields
3932
3686
  },
3933
- templates: { ...templates,
3687
+ templates: {
3688
+ ...templates,
3934
3689
  ...this.props.templates,
3935
- ButtonTemplates: { ...templates.ButtonTemplates,
3690
+ ButtonTemplates: {
3691
+ ...templates.ButtonTemplates,
3936
3692
  ...((_this$props$templates = this.props.templates) === null || _this$props$templates === void 0 ? void 0 : _this$props$templates.ButtonTemplates)
3937
3693
  }
3938
3694
  },
3939
- widgets: { ...widgets,
3695
+ widgets: {
3696
+ ...widgets,
3940
3697
  ...this.props.widgets
3941
3698
  },
3942
3699
  rootSchema: this.props.schema,
@@ -3945,8 +3702,6 @@ class Form extends React.Component {
3945
3702
  };
3946
3703
  }
3947
3704
  /** Provides a function that can be used to programmatically submit the `Form` */
3948
-
3949
-
3950
3705
  submit() {
3951
3706
  if (this.formElement.current) {
3952
3707
  this.formElement.current.dispatchEvent(new CustomEvent("submit", {
@@ -3960,8 +3715,6 @@ class Form extends React.Component {
3960
3715
  *
3961
3716
  * @returns - True if the form is valid, false otherwise.
3962
3717
  */
3963
-
3964
-
3965
3718
  validateForm() {
3966
3719
  const {
3967
3720
  extraErrors,
@@ -3978,14 +3731,12 @@ class Form extends React.Component {
3978
3731
  let errorSchema = schemaValidation.errorSchema;
3979
3732
  const schemaValidationErrors = errors;
3980
3733
  const schemaValidationErrorSchema = errorSchema;
3981
-
3982
3734
  if (errors.length > 0) {
3983
3735
  if (extraErrors) {
3984
3736
  const merged = schemaUtils.mergeValidationData(schemaValidation, extraErrors);
3985
3737
  errorSchema = merged.errorSchema;
3986
3738
  errors = merged.errors;
3987
3739
  }
3988
-
3989
3740
  this.setState({
3990
3741
  errors,
3991
3742
  errorSchema,
@@ -4000,14 +3751,11 @@ class Form extends React.Component {
4000
3751
  });
4001
3752
  return false;
4002
3753
  }
4003
-
4004
3754
  return true;
4005
3755
  }
4006
3756
  /** Renders the `Form` fields inside the <form> | `tagName` or `_internalFormWrapper`, rendering any errors if
4007
3757
  * needed along with the submit button or any children of the form.
4008
3758
  */
4009
-
4010
-
4011
3759
  render() {
4012
3760
  const {
4013
3761
  children,
@@ -4027,6 +3775,7 @@ class Form extends React.Component {
4027
3775
  disabled = false,
4028
3776
  readonly = false,
4029
3777
  formContext,
3778
+ showErrorList = "top",
4030
3779
  _internalFormWrapper
4031
3780
  } = this.props;
4032
3781
  const {
@@ -4042,10 +3791,10 @@ class Form extends React.Component {
4042
3791
  } = registry.fields;
4043
3792
  const {
4044
3793
  SubmitButton
4045
- } = registry.templates.ButtonTemplates; // The `semantic-ui` and `material-ui` themes have `_internalFormWrapper`s that take an `as` prop that is the
4046
- // PropTypes.elementType to use for the inner tag so we'll need to pass `tagName` along if it is provided.
3794
+ } = registry.templates.ButtonTemplates;
3795
+ // The `semantic-ui` and `material-ui` themes have `_internalFormWrapper`s that take an `as` prop that is the
3796
+ // PropTypes.elementType to use for the inner tag, so we'll need to pass `tagName` along if it is provided.
4047
3797
  // NOTE, the `as` prop is native to `semantic-ui` and is emulated in the `material-ui` theme
4048
-
4049
3798
  const as = _internalFormWrapper ? tagName : undefined;
4050
3799
  const FormTag = _internalFormWrapper || tagName || "form";
4051
3800
  return /*#__PURE__*/React__default["default"].createElement(FormTag, {
@@ -4062,7 +3811,7 @@ class Form extends React.Component {
4062
3811
  onSubmit: this.onSubmit,
4063
3812
  as: as,
4064
3813
  ref: this.formElement
4065
- }, this.renderErrors(registry), /*#__PURE__*/React__default["default"].createElement(_SchemaField, {
3814
+ }, showErrorList === "top" && this.renderErrors(registry), /*#__PURE__*/React__default["default"].createElement(_SchemaField, {
4066
3815
  name: "",
4067
3816
  schema: schema,
4068
3817
  uiSchema: uiSchema,
@@ -4080,36 +3829,38 @@ class Form extends React.Component {
4080
3829
  readonly: readonly
4081
3830
  }), children ? children : /*#__PURE__*/React__default["default"].createElement(SubmitButton, {
4082
3831
  uiSchema: uiSchema
4083
- }));
3832
+ }), showErrorList === "bottom" && this.renderErrors(registry));
4084
3833
  }
4085
-
4086
3834
  }
4087
3835
 
4088
3836
  /** A Higher-Order component that creates a wrapper around a `Form` with the overrides from the `WithThemeProps` */
4089
-
4090
3837
  function withTheme(themeProps) {
4091
3838
  return /*#__PURE__*/React.forwardRef((_ref, ref) => {
4092
3839
  var _themeProps$templates, _templates;
4093
-
4094
3840
  let {
4095
3841
  fields,
4096
3842
  widgets,
4097
3843
  templates,
4098
3844
  ...directProps
4099
3845
  } = _ref;
4100
- fields = { ...themeProps.fields,
3846
+ fields = {
3847
+ ...themeProps.fields,
4101
3848
  ...fields
4102
3849
  };
4103
- widgets = { ...themeProps.widgets,
3850
+ widgets = {
3851
+ ...themeProps.widgets,
4104
3852
  ...widgets
4105
3853
  };
4106
- templates = { ...themeProps.templates,
3854
+ templates = {
3855
+ ...themeProps.templates,
4107
3856
  ...templates,
4108
- ButtonTemplates: { ...(themeProps === null || themeProps === void 0 ? void 0 : (_themeProps$templates = themeProps.templates) === null || _themeProps$templates === void 0 ? void 0 : _themeProps$templates.ButtonTemplates),
3857
+ ButtonTemplates: {
3858
+ ...(themeProps === null || themeProps === void 0 ? void 0 : (_themeProps$templates = themeProps.templates) === null || _themeProps$templates === void 0 ? void 0 : _themeProps$templates.ButtonTemplates),
4109
3859
  ...((_templates = templates) === null || _templates === void 0 ? void 0 : _templates.ButtonTemplates)
4110
3860
  }
4111
3861
  };
4112
- return /*#__PURE__*/React__default["default"].createElement(Form, { ...themeProps,
3862
+ return /*#__PURE__*/React__default["default"].createElement(Form, {
3863
+ ...themeProps,
4113
3864
  ...directProps,
4114
3865
  fields: fields,
4115
3866
  widgets: widgets,