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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/README.md +13 -9
  2. package/dist/index.d.ts +1556 -38
  3. package/dist/utils.cjs.development.js +1212 -800
  4. package/dist/utils.cjs.development.js.map +1 -1
  5. package/dist/utils.cjs.production.min.js +1 -1
  6. package/dist/utils.cjs.production.min.js.map +1 -1
  7. package/dist/utils.esm.js +1193 -800
  8. package/dist/utils.esm.js.map +1 -1
  9. package/dist/utils.umd.development.js +1209 -803
  10. package/dist/utils.umd.development.js.map +1 -1
  11. package/dist/utils.umd.production.min.js +1 -1
  12. package/dist/utils.umd.production.min.js.map +1 -1
  13. package/package.json +13 -13
  14. package/dist/allowAdditionalItems.d.ts +0 -8
  15. package/dist/asNumber.d.ts +0 -10
  16. package/dist/canExpand.d.ts +0 -11
  17. package/dist/constants.d.ts +0 -27
  18. package/dist/createSchemaUtils.d.ts +0 -9
  19. package/dist/dataURItoBlob.d.ts +0 -10
  20. package/dist/deepEquals.d.ts +0 -8
  21. package/dist/findSchemaDefinition.d.ts +0 -20
  22. package/dist/getInputProps.d.ts +0 -10
  23. package/dist/getSchemaType.d.ts +0 -13
  24. package/dist/getSubmitButtonOptions.d.ts +0 -10
  25. package/dist/getTemplate.d.ts +0 -10
  26. package/dist/getUiOptions.d.ts +0 -8
  27. package/dist/getWidget.d.ts +0 -13
  28. package/dist/guessType.d.ts +0 -7
  29. package/dist/hasWidget.d.ts +0 -10
  30. package/dist/isConstant.d.ts +0 -8
  31. package/dist/isCustomWidget.d.ts +0 -7
  32. package/dist/isFixedItems.d.ts +0 -8
  33. package/dist/isObject.d.ts +0 -7
  34. package/dist/localToUTC.d.ts +0 -6
  35. package/dist/mergeDefaultsWithFormData.d.ts +0 -15
  36. package/dist/mergeObjects.d.ts +0 -9
  37. package/dist/mergeSchemas.d.ts +0 -10
  38. package/dist/optionsList.d.ts +0 -10
  39. package/dist/orderProperties.d.ts +0 -11
  40. package/dist/pad.d.ts +0 -7
  41. package/dist/parseDateString.d.ts +0 -9
  42. package/dist/processSelectValue.d.ts +0 -11
  43. package/dist/rangeSpec.d.ts +0 -9
  44. package/dist/schema/getDefaultFormState.d.ts +0 -47
  45. package/dist/schema/getDisplayLabel.d.ts +0 -11
  46. package/dist/schema/getMatchingOption.d.ts +0 -10
  47. package/dist/schema/index.d.ts +0 -11
  48. package/dist/schema/isFilesArray.d.ts +0 -10
  49. package/dist/schema/isMultiSelect.d.ts +0 -9
  50. package/dist/schema/isSelect.d.ts +0 -9
  51. package/dist/schema/mergeValidationData.d.ts +0 -12
  52. package/dist/schema/retrieveSchema.d.ts +0 -98
  53. package/dist/schema/toIdSchema.d.ts +0 -13
  54. package/dist/schema/toPathSchema.d.ts +0 -11
  55. package/dist/schemaRequiresTrueValue.d.ts +0 -11
  56. package/dist/shouldRender.d.ts +0 -10
  57. package/dist/toConstant.d.ts +0 -9
  58. package/dist/toDateString.d.ts +0 -9
  59. package/dist/types.d.ts +0 -755
  60. package/dist/utcToLocal.d.ts +0 -6
@@ -1,19 +1,25 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('lodash-es/isEqualWith'), require('lodash-es/get'), require('jsonpointer'), require('lodash-es/omit'), require('lodash-es/set'), require('json-schema-merge-allof'), require('lodash-es/union'), require('lodash-es/isEmpty'), require('react'), require('react-is')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'lodash-es/isEqualWith', 'lodash-es/get', 'jsonpointer', 'lodash-es/omit', 'lodash-es/set', 'json-schema-merge-allof', 'lodash-es/union', 'lodash-es/isEmpty', 'react', 'react-is'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@rjsf/utils"] = {}, global.isEqualWith, global.get, global.jsonpointer, global.omit, global.set, global.mergeAllOf, global.union, global.isEmpty, global.React, global.ReactIs));
5
- })(this, (function (exports, isEqualWith, get, jsonpointer, omit, set, mergeAllOf, union, isEmpty, React, ReactIs) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('lodash-es/isEqualWith'), require('lodash-es/get'), require('lodash-es/isEmpty'), require('jsonpointer'), require('lodash-es/omit'), require('lodash-es/has'), require('lodash-es/isObject'), require('lodash-es/isString'), require('lodash-es/reduce'), require('lodash-es/times'), require('lodash-es/set'), require('json-schema-merge-allof'), require('lodash-es/union'), require('lodash-es/cloneDeep'), require('react'), require('react-is')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'lodash-es/isEqualWith', 'lodash-es/get', 'lodash-es/isEmpty', 'jsonpointer', 'lodash-es/omit', 'lodash-es/has', 'lodash-es/isObject', 'lodash-es/isString', 'lodash-es/reduce', 'lodash-es/times', 'lodash-es/set', 'json-schema-merge-allof', 'lodash-es/union', 'lodash-es/cloneDeep', 'react', 'react-is'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@rjsf/utils"] = {}, global.isEqualWith, global.get, global.isEmpty, global.jsonpointer, global.omit, global.has, global.isObject$1, global.isString, global.reduce, global.times, global.set, global.mergeAllOf, global.union, global.cloneDeep, global.React, global.ReactIs));
5
+ })(this, (function (exports, isEqualWith, get, isEmpty, jsonpointer, omit, has, isObject$1, isString, reduce, times, set, mergeAllOf, union, cloneDeep, React, ReactIs) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
9
9
  var isEqualWith__default = /*#__PURE__*/_interopDefaultLegacy(isEqualWith);
10
10
  var get__default = /*#__PURE__*/_interopDefaultLegacy(get);
11
+ var isEmpty__default = /*#__PURE__*/_interopDefaultLegacy(isEmpty);
11
12
  var jsonpointer__default = /*#__PURE__*/_interopDefaultLegacy(jsonpointer);
12
13
  var omit__default = /*#__PURE__*/_interopDefaultLegacy(omit);
14
+ var has__default = /*#__PURE__*/_interopDefaultLegacy(has);
15
+ var isObject__default = /*#__PURE__*/_interopDefaultLegacy(isObject$1);
16
+ var isString__default = /*#__PURE__*/_interopDefaultLegacy(isString);
17
+ var reduce__default = /*#__PURE__*/_interopDefaultLegacy(reduce);
18
+ var times__default = /*#__PURE__*/_interopDefaultLegacy(times);
13
19
  var set__default = /*#__PURE__*/_interopDefaultLegacy(set);
14
20
  var mergeAllOf__default = /*#__PURE__*/_interopDefaultLegacy(mergeAllOf);
15
21
  var union__default = /*#__PURE__*/_interopDefaultLegacy(union);
16
- var isEmpty__default = /*#__PURE__*/_interopDefaultLegacy(isEmpty);
22
+ var cloneDeep__default = /*#__PURE__*/_interopDefaultLegacy(cloneDeep);
17
23
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
18
24
  var ReactIs__default = /*#__PURE__*/_interopDefaultLegacy(ReactIs);
19
25
 
@@ -27,7 +33,9 @@
27
33
  if (typeof File !== "undefined" && thing instanceof File) {
28
34
  return false;
29
35
  }
30
-
36
+ if (typeof Date !== "undefined" && thing instanceof Date) {
37
+ return false;
38
+ }
31
39
  return typeof thing === "object" && thing !== null && !Array.isArray(thing);
32
40
  }
33
41
 
@@ -37,12 +45,10 @@
37
45
  * @param schema - The schema object to check
38
46
  * @returns - True if additional items is allowed, otherwise false
39
47
  */
40
-
41
48
  function allowAdditionalItems(schema) {
42
49
  if (schema.additionalItems === true) {
43
50
  console.warn("additionalItems=true is currently not supported");
44
51
  }
45
-
46
52
  return isObject(schema.additionalItems);
47
53
  }
48
54
 
@@ -59,91 +65,141 @@
59
65
  if (value === "") {
60
66
  return undefined;
61
67
  }
62
-
63
68
  if (value === null) {
64
69
  return null;
65
70
  }
66
-
67
71
  if (/\.$/.test(value)) {
68
72
  // '3.' can't really be considered a number even if it parses in js. The
69
73
  // user is most likely entering a float.
70
74
  return value;
71
75
  }
72
-
73
76
  if (/\.0$/.test(value)) {
74
77
  // we need to return this as a string here, to allow for input like 3.07
75
78
  return value;
76
79
  }
77
-
78
80
  if (/\.\d*0$/.test(value)) {
79
81
  // It's a number, that's cool - but we need it as a string so it doesn't screw
80
82
  // with the user when entering dollar amounts or other values (such as those with
81
83
  // specific precision or number of significant digits)
82
84
  return value;
83
85
  }
84
-
85
- const n = Number(value);
86
- const valid = typeof n === "number" && !Number.isNaN(n);
86
+ var n = Number(value);
87
+ var valid = typeof n === "number" && !Number.isNaN(n);
87
88
  return valid ? n : value;
88
89
  }
89
90
 
91
+ function _defineProperties(target, props) {
92
+ for (var i = 0; i < props.length; i++) {
93
+ var descriptor = props[i];
94
+ descriptor.enumerable = descriptor.enumerable || false;
95
+ descriptor.configurable = true;
96
+ if ("value" in descriptor) descriptor.writable = true;
97
+ Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
98
+ }
99
+ }
100
+ function _createClass(Constructor, protoProps, staticProps) {
101
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
102
+ if (staticProps) _defineProperties(Constructor, staticProps);
103
+ Object.defineProperty(Constructor, "prototype", {
104
+ writable: false
105
+ });
106
+ return Constructor;
107
+ }
108
+ function _extends() {
109
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
110
+ for (var i = 1; i < arguments.length; i++) {
111
+ var source = arguments[i];
112
+ for (var key in source) {
113
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
114
+ target[key] = source[key];
115
+ }
116
+ }
117
+ }
118
+ return target;
119
+ };
120
+ return _extends.apply(this, arguments);
121
+ }
122
+ function _objectDestructuringEmpty(obj) {
123
+ if (obj == null) throw new TypeError("Cannot destructure " + obj);
124
+ }
125
+ function _objectWithoutPropertiesLoose(source, excluded) {
126
+ if (source == null) return {};
127
+ var target = {};
128
+ var sourceKeys = Object.keys(source);
129
+ var key, i;
130
+ for (i = 0; i < sourceKeys.length; i++) {
131
+ key = sourceKeys[i];
132
+ if (excluded.indexOf(key) >= 0) continue;
133
+ target[key] = source[key];
134
+ }
135
+ return target;
136
+ }
137
+ function _toPrimitive(input, hint) {
138
+ if (typeof input !== "object" || input === null) return input;
139
+ var prim = input[Symbol.toPrimitive];
140
+ if (prim !== undefined) {
141
+ var res = prim.call(input, hint || "default");
142
+ if (typeof res !== "object") return res;
143
+ throw new TypeError("@@toPrimitive must return a primitive value.");
144
+ }
145
+ return (hint === "string" ? String : Number)(input);
146
+ }
147
+ function _toPropertyKey(arg) {
148
+ var key = _toPrimitive(arg, "string");
149
+ return typeof key === "symbol" ? key : String(key);
150
+ }
151
+
90
152
  /** Below are the list of all the keys into various elements of a RJSFSchema or UiSchema that are used by the various
91
153
  * utility functions. In addition to those keys, there are the special `ADDITIONAL_PROPERTY_FLAG` and
92
154
  * `RJSF_ADDITONAL_PROPERTIES_FLAG` flags that is added to a schema under certain conditions by the `retrieveSchema()`
93
155
  * utility.
94
156
  */
95
- const ADDITIONAL_PROPERTY_FLAG = "__additional_property";
96
- const ADDITIONAL_PROPERTIES_KEY = "additionalProperties";
97
- const ALL_OF_KEY = "allOf";
98
- const ANY_OF_KEY = "anyOf";
99
- const CONST_KEY = "const";
100
- const DEFAULT_KEY = "default";
101
- const DEFINITIONS_KEY = "definitions";
102
- const DEPENDENCIES_KEY = "dependencies";
103
- const ENUM_KEY = "enum";
104
- const ERRORS_KEY = "__errors";
105
- const ID_KEY = "$id";
106
- const ITEMS_KEY = "items";
107
- const NAME_KEY = "$name";
108
- const ONE_OF_KEY = "oneOf";
109
- const PROPERTIES_KEY = "properties";
110
- const REQUIRED_KEY = "required";
111
- const SUBMIT_BTN_OPTIONS_KEY = "submitButtonOptions";
112
- const REF_KEY = "$ref";
113
- const RJSF_ADDITONAL_PROPERTIES_FLAG = "__rjsf_additionalProperties";
114
- const UI_FIELD_KEY = "ui:field";
115
- const UI_WIDGET_KEY = "ui:widget";
116
- const UI_OPTIONS_KEY = "ui:options";
157
+ var ADDITIONAL_PROPERTY_FLAG = "__additional_property";
158
+ var ADDITIONAL_PROPERTIES_KEY = "additionalProperties";
159
+ var ALL_OF_KEY = "allOf";
160
+ var ANY_OF_KEY = "anyOf";
161
+ var CONST_KEY = "const";
162
+ var DEFAULT_KEY = "default";
163
+ var DEFINITIONS_KEY = "definitions";
164
+ var DEPENDENCIES_KEY = "dependencies";
165
+ var ENUM_KEY = "enum";
166
+ var ERRORS_KEY = "__errors";
167
+ var ID_KEY = "$id";
168
+ var ITEMS_KEY = "items";
169
+ var NAME_KEY = "$name";
170
+ var ONE_OF_KEY = "oneOf";
171
+ var PROPERTIES_KEY = "properties";
172
+ var REQUIRED_KEY = "required";
173
+ var SUBMIT_BTN_OPTIONS_KEY = "submitButtonOptions";
174
+ var REF_KEY = "$ref";
175
+ var RJSF_ADDITONAL_PROPERTIES_FLAG = "__rjsf_additionalProperties";
176
+ var UI_FIELD_KEY = "ui:field";
177
+ var UI_WIDGET_KEY = "ui:widget";
178
+ var UI_OPTIONS_KEY = "ui:options";
117
179
 
118
180
  /** Get all passed options from ui:options, and ui:<optionName>, returning them in an object with the `ui:`
119
181
  * stripped off.
120
182
  *
121
183
  * @param [uiSchema={}] - The UI Schema from which to get any `ui:xxx` options
122
- * @returns - An object containing all of the `ui:xxx` options with the stripped off
184
+ * @returns - An object containing all the `ui:xxx` options with the stripped off
123
185
  */
124
-
125
186
  function getUiOptions(uiSchema) {
126
187
  if (uiSchema === void 0) {
127
188
  uiSchema = {};
128
189
  }
129
-
130
- return Object.keys(uiSchema).filter(key => key.indexOf("ui:") === 0).reduce((options, key) => {
131
- const value = uiSchema[key];
132
-
190
+ return Object.keys(uiSchema).filter(function (key) {
191
+ return key.indexOf("ui:") === 0;
192
+ }).reduce(function (options, key) {
193
+ var _extends2;
194
+ var value = uiSchema[key];
133
195
  if (key === UI_WIDGET_KEY && isObject(value)) {
134
196
  console.error("Setting options via ui:widget object is no longer supported, use ui:options instead");
135
197
  return options;
136
198
  }
137
-
138
199
  if (key === UI_OPTIONS_KEY && isObject(value)) {
139
- return { ...options,
140
- ...value
141
- };
200
+ return _extends({}, options, value);
142
201
  }
143
-
144
- return { ...options,
145
- [key.substring(3)]: value
146
- };
202
+ return _extends({}, options, (_extends2 = {}, _extends2[key.substring(3)] = value, _extends2));
147
203
  }, {});
148
204
  }
149
205
 
@@ -156,30 +212,24 @@
156
212
  * @param [formData] - The formData for the field
157
213
  * @returns - True if the schema element has additionalProperties, is expandable, and not at the maxProperties limit
158
214
  */
159
-
160
215
  function canExpand(schema, uiSchema, formData) {
161
216
  if (uiSchema === void 0) {
162
217
  uiSchema = {};
163
218
  }
164
-
165
219
  if (!schema.additionalProperties) {
166
220
  return false;
167
221
  }
168
-
169
- const {
170
- expandable = true
171
- } = getUiOptions(uiSchema);
172
-
222
+ var _getUiOptions = getUiOptions(uiSchema),
223
+ _getUiOptions$expanda = _getUiOptions.expandable,
224
+ expandable = _getUiOptions$expanda === void 0 ? true : _getUiOptions$expanda;
173
225
  if (expandable === false) {
174
226
  return expandable;
175
- } // if ui:options.expandable was not explicitly set to false, we can add
227
+ }
228
+ // if ui:options.expandable was not explicitly set to false, we can add
176
229
  // another property if we have not exceeded maxProperties yet
177
-
178
-
179
230
  if (schema.maxProperties !== undefined && formData) {
180
231
  return Object.keys(formData).length < schema.maxProperties;
181
232
  }
182
-
183
233
  return true;
184
234
  }
185
235
 
@@ -190,15 +240,13 @@
190
240
  * @param b - The second element to compare
191
241
  * @returns - True if the `a` and `b` are deeply equal, false otherwise
192
242
  */
193
-
194
243
  function deepEquals(a, b) {
195
- return isEqualWith__default["default"](a, b, (obj, other) => {
244
+ return isEqualWith__default["default"](a, b, function (obj, other) {
196
245
  if (typeof obj === "function" && typeof other === "function") {
197
246
  // Assume all functions are equivalent
198
247
  // see https://github.com/rjsf-team/react-jsonschema-form/issues/255
199
248
  return true;
200
249
  }
201
-
202
250
  return undefined; // fallback to default isEquals behavior
203
251
  });
204
252
  }
@@ -211,10 +259,9 @@
211
259
  * @returns - An array with the first value being the object minus the `key` element and the second element being the
212
260
  * value from `object[key]`
213
261
  */
214
-
215
262
  function splitKeyElementFromObject(key, object) {
216
- const value = object[key];
217
- const remaining = omit__default["default"](object, [key]);
263
+ var value = object[key];
264
+ var remaining = omit__default["default"](object, [key]);
218
265
  return [remaining, value];
219
266
  }
220
267
  /** Given the name of a `$ref` from within a schema, using the `rootSchema`, look up and return the sub-schema using the
@@ -226,50 +273,43 @@
226
273
  * @returns - The sub-schema within the `rootSchema` which matches the `$ref` if it exists
227
274
  * @throws - Error indicating that no schema for that reference exists
228
275
  */
229
-
230
276
  function findSchemaDefinition($ref, rootSchema) {
231
277
  if (rootSchema === void 0) {
232
278
  rootSchema = {};
233
279
  }
234
-
235
- let ref = $ref || "";
236
-
280
+ var ref = $ref || "";
237
281
  if (ref.startsWith("#")) {
238
282
  // Decode URI fragment representation.
239
283
  ref = decodeURIComponent(ref.substring(1));
240
284
  } else {
241
285
  throw new Error("Could not find a definition for " + $ref + ".");
242
286
  }
243
-
244
- const current = jsonpointer__default["default"].get(rootSchema, ref);
245
-
287
+ var current = jsonpointer__default["default"].get(rootSchema, ref);
246
288
  if (current === undefined) {
247
289
  throw new Error("Could not find a definition for " + $ref + ".");
248
290
  }
249
-
250
291
  if (current[REF_KEY]) {
251
- const [remaining, theRef] = splitKeyElementFromObject(REF_KEY, current);
252
- const subSchema = findSchemaDefinition(theRef, rootSchema);
253
-
292
+ var _splitKeyElementFromO = splitKeyElementFromObject(REF_KEY, current),
293
+ remaining = _splitKeyElementFromO[0],
294
+ theRef = _splitKeyElementFromO[1];
295
+ var subSchema = findSchemaDefinition(theRef, rootSchema);
254
296
  if (Object.keys(remaining).length > 0) {
255
- return { ...remaining,
256
- ...subSchema
257
- };
297
+ return _extends({}, remaining, subSchema);
258
298
  }
259
-
260
299
  return subSchema;
261
300
  }
262
-
263
301
  return current;
264
302
  }
265
303
 
266
304
  /** Given the `formData` and list of `options`, attempts to find the index of the option that best matches the data.
305
+ * Deprecated, use `getFirstMatchingOption()` instead.
267
306
  *
268
307
  * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
269
308
  * @param formData - The current formData, if any, used to figure out a match
270
309
  * @param options - The list of options to find a matching options from
271
310
  * @param rootSchema - The root schema, used to primarily to look up `$ref`s
272
311
  * @returns - The index of the matched option or 0 if none is available
312
+ * @deprecated
273
313
  */
274
314
  function getMatchingOption(validator, formData, options, rootSchema) {
275
315
  // For performance, skip validating subschemas if formData is undefined. We just
@@ -277,48 +317,44 @@
277
317
  if (formData === undefined) {
278
318
  return 0;
279
319
  }
280
-
281
- for (let i = 0; i < options.length; i++) {
282
- const option = options[i]; // If the schema describes an object then we need to add slightly more
320
+ for (var i = 0; i < options.length; i++) {
321
+ var option = options[i];
322
+ // If the schema describes an object then we need to add slightly more
283
323
  // strict matching to the schema, because unless the schema uses the
284
324
  // "requires" keyword, an object will match the schema as long as it
285
325
  // doesn't have matching keys with a conflicting type. To do this we use an
286
326
  // "anyOf" with an array of requires. This augmentation expresses that the
287
327
  // schema should match if any of the keys in the schema are present on the
288
328
  // object and pass validation.
289
-
290
329
  if (option.properties) {
291
330
  // Create an "anyOf" schema that requires at least one of the keys in the
292
331
  // "properties" object
293
- const requiresAnyOf = {
294
- anyOf: Object.keys(option.properties).map(key => ({
295
- required: [key]
296
- }))
332
+ var requiresAnyOf = {
333
+ anyOf: Object.keys(option.properties).map(function (key) {
334
+ return {
335
+ required: [key]
336
+ };
337
+ })
297
338
  };
298
- let augmentedSchema; // If the "anyOf" keyword already exists, wrap the augmentation in an "allOf"
299
-
339
+ var augmentedSchema = void 0;
340
+ // If the "anyOf" keyword already exists, wrap the augmentation in an "allOf"
300
341
  if (option.anyOf) {
301
342
  // Create a shallow clone of the option
302
- const { ...shallowClone
303
- } = option;
304
-
343
+ var shallowClone = _extends({}, (_objectDestructuringEmpty(option), option));
305
344
  if (!shallowClone.allOf) {
306
345
  shallowClone.allOf = [];
307
346
  } else {
308
347
  // If "allOf" already exists, shallow clone the array
309
348
  shallowClone.allOf = shallowClone.allOf.slice();
310
349
  }
311
-
312
350
  shallowClone.allOf.push(requiresAnyOf);
313
351
  augmentedSchema = shallowClone;
314
352
  } else {
315
353
  augmentedSchema = Object.assign({}, option, requiresAnyOf);
316
- } // Remove the "required" field as it's likely that not all fields have
354
+ }
355
+ // Remove the "required" field as it's likely that not all fields have
317
356
  // been filled in yet, which will mean that the schema is not valid
318
-
319
-
320
357
  delete augmentedSchema.required;
321
-
322
358
  if (validator.isValid(augmentedSchema, formData, rootSchema)) {
323
359
  return i;
324
360
  }
@@ -326,10 +362,22 @@
326
362
  return i;
327
363
  }
328
364
  }
329
-
330
365
  return 0;
331
366
  }
332
367
 
368
+ /** Given the `formData` and list of `options`, attempts to find the index of the first option that matches the data.
369
+ * Always returns the first option if there is nothing that matches.
370
+ *
371
+ * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
372
+ * @param formData - The current formData, if any, used to figure out a match
373
+ * @param options - The list of options to find a matching options from
374
+ * @param rootSchema - The root schema, used to primarily to look up `$ref`s
375
+ * @returns - The index of the first matched option or 0 if none is available
376
+ */
377
+ function getFirstMatchingOption(validator, formData, options, rootSchema) {
378
+ return getMatchingOption(validator, formData, options, rootSchema);
379
+ }
380
+
333
381
  /** Given a specific `value` attempts to guess the type of a schema element. In the case where we have to implicitly
334
382
  * create a schema, it is useful to know what type to use based on the data we are defining.
335
383
  *
@@ -340,28 +388,22 @@
340
388
  if (Array.isArray(value)) {
341
389
  return "array";
342
390
  }
343
-
344
391
  if (typeof value === "string") {
345
392
  return "string";
346
393
  }
347
-
348
394
  if (value == null) {
349
395
  return "null";
350
396
  }
351
-
352
397
  if (typeof value === "boolean") {
353
398
  return "boolean";
354
399
  }
355
-
356
400
  if (!isNaN(value)) {
357
401
  return "number";
358
402
  }
359
-
360
403
  if (typeof value === "object") {
361
404
  return "object";
362
- } // Default to string if we can't figure it out
363
-
364
-
405
+ }
406
+ // Default to string if we can't figure it out
365
407
  return "string";
366
408
  }
367
409
 
@@ -376,121 +418,29 @@
376
418
  * @param schema - The schema for which to get the type
377
419
  * @returns - The type of the schema
378
420
  */
379
-
380
421
  function getSchemaType(schema) {
381
- let {
382
- type
383
- } = schema;
384
-
385
- if (!type && schema.const) {
386
- return guessType(schema.const);
422
+ var type = schema.type;
423
+ if (!type && schema["const"]) {
424
+ return guessType(schema["const"]);
387
425
  }
388
-
389
- if (!type && schema.enum) {
426
+ if (!type && schema["enum"]) {
390
427
  return "string";
391
428
  }
392
-
393
429
  if (!type && (schema.properties || schema.additionalProperties)) {
394
430
  return "object";
395
431
  }
396
-
397
- if (Array.isArray(type) && type.length === 2 && type.includes("null")) {
398
- type = type.find(type => type !== "null");
432
+ if (!type && Array.isArray(schema.oneOf) && schema.oneOf.length) {
433
+ return getSchemaType(schema.oneOf[0]);
399
434
  }
400
-
401
- return type;
402
- }
403
-
404
- /** Detects whether the given `schema` contains fixed items. This is the case when `schema.items` is a non-empty array
405
- * that only contains objects.
406
- *
407
- * @param schema - The schema in which to check for fixed items
408
- * @returns - True if there are fixed items in the schema, false otherwise
409
- */
410
-
411
- function isFixedItems(schema) {
412
- return Array.isArray(schema.items) && schema.items.length > 0 && schema.items.every(item => isObject(item));
413
- }
414
-
415
- /** Merges the `defaults` object of type `T` into the `formData` of type `T`
416
- *
417
- * When merging defaults and form data, we want to merge in this specific way:
418
- * - objects are deeply merged
419
- * - arrays are merged in such a way that:
420
- * - when the array is set in form data, only array entries set in form data
421
- * are deeply merged; additional entries from the defaults are ignored
422
- * - when the array is not set in form data, the default is copied over
423
- * - scalars are overwritten/set by form data
424
- *
425
- * @param defaults - The defaults to merge
426
- * @param formData - The form data into which the defaults will be merged
427
- * @returns - The resulting merged form data with defaults
428
- */
429
-
430
- function mergeDefaultsWithFormData(defaults, formData) {
431
- if (Array.isArray(formData)) {
432
- const defaultsArray = Array.isArray(defaults) ? defaults : [];
433
- const mapped = formData.map((value, idx) => {
434
- if (defaultsArray[idx]) {
435
- return mergeDefaultsWithFormData(defaultsArray[idx], value);
436
- }
437
-
438
- return value;
439
- });
440
- return mapped;
435
+ if (!type && Array.isArray(schema.anyOf) && schema.anyOf.length) {
436
+ return getSchemaType(schema.anyOf[0]);
441
437
  }
442
-
443
- if (isObject(formData)) {
444
- // eslint-disable-next-line no-unused-vars
445
- const acc = Object.assign({}, defaults); // Prevent mutation of source object.
446
-
447
- return Object.keys(formData).reduce((acc, key) => {
448
- acc[key] = mergeDefaultsWithFormData(defaults ? get__default["default"](defaults, key) : {}, get__default["default"](formData, key));
449
- return acc;
450
- }, acc);
451
- }
452
-
453
- return formData;
454
- }
455
-
456
- /** Recursively merge deeply nested objects.
457
- *
458
- * @param obj1 - The first object to merge
459
- * @param obj2 - The second object to merge
460
- * @param [concatArrays=false] - Optional flag that, when true, will cause arrays to be concatenated
461
- * @returns - A new object that is the merge of the two given objects
462
- */
463
-
464
- function mergeObjects(obj1, obj2, concatArrays) {
465
- if (concatArrays === void 0) {
466
- concatArrays = false;
438
+ if (Array.isArray(type) && type.length === 2 && type.includes("null")) {
439
+ type = type.find(function (type) {
440
+ return type !== "null";
441
+ });
467
442
  }
468
-
469
- return Object.keys(obj2).reduce((acc, key) => {
470
- const left = obj1 ? obj1[key] : {},
471
- right = obj2[key];
472
-
473
- if (obj1 && key in obj1 && isObject(right)) {
474
- acc[key] = mergeObjects(left, right, concatArrays);
475
- } else if (concatArrays && Array.isArray(left) && Array.isArray(right)) {
476
- acc[key] = left.concat(right);
477
- } else {
478
- acc[key] = right;
479
- }
480
-
481
- return acc;
482
- }, Object.assign({}, obj1)); // Prevent mutation of source object.
483
- }
484
-
485
- /** This function checks if the given `schema` matches a single constant value. This happens when either the schema has
486
- * an `enum` array with a single value or there is a `const` defined.
487
- *
488
- * @param schema - The schema for a field
489
- * @returns - True if the `schema` has a single constant value, false otherwise
490
- */
491
-
492
- function isConstant(schema) {
493
- return Array.isArray(schema.enum) && schema.enum.length === 1 || CONST_KEY in schema;
443
+ return type;
494
444
  }
495
445
 
496
446
  /** Recursively merge deeply nested schemas. The difference between `mergeSchemas` and `mergeObjects` is that
@@ -501,14 +451,11 @@
501
451
  * @param obj2 - The second schema object to merge
502
452
  * @returns - The merged schema object
503
453
  */
504
-
505
454
  function mergeSchemas(obj1, obj2) {
506
- const acc = Object.assign({}, obj1); // Prevent mutation of source object.
507
-
508
- return Object.keys(obj2).reduce((acc, key) => {
509
- const left = obj1 ? obj1[key] : {},
510
- right = obj2[key];
511
-
455
+ var acc = Object.assign({}, obj1); // Prevent mutation of source object.
456
+ return Object.keys(obj2).reduce(function (acc, key) {
457
+ var left = obj1 ? obj1[key] : {},
458
+ right = obj2[key];
512
459
  if (obj1 && key in obj1 && isObject(right)) {
513
460
  acc[key] = mergeSchemas(left, right);
514
461
  } else if (obj1 && obj2 && (getSchemaType(obj1) === "object" || getSchemaType(obj2) === "object") && key === REQUIRED_KEY && Array.isArray(left) && Array.isArray(right)) {
@@ -517,124 +464,113 @@
517
464
  } else {
518
465
  acc[key] = right;
519
466
  }
520
-
521
467
  return acc;
522
468
  }, acc);
523
469
  }
524
470
 
471
+ var _excluded$1 = ["if", "then", "else"],
472
+ _excluded2 = ["$ref"],
473
+ _excluded3 = ["allOf"],
474
+ _excluded4 = ["dependencies"],
475
+ _excluded5 = ["oneOf"];
525
476
  /** Resolves a conditional block (if/else/then) by removing the condition and merging the appropriate conditional branch
526
477
  * with the rest of the schema
527
478
  *
528
- * @param validator - An implementation of the `ValidatorType` interface that is used to detect valid schema conditions
479
+ * @param validator - An implementation of the `ValidatorType<T, S>` interface that is used to detect valid schema conditions
529
480
  * @param schema - The schema for which resolving a condition is desired
530
481
  * @param rootSchema - The root schema that will be forwarded to all the APIs
531
- * @param formData - The current formData to assist retrieving a schema
482
+ * @param [formData] - The current formData to assist retrieving a schema
532
483
  * @returns - A schema with the appropriate condition resolved
533
484
  */
534
-
535
485
  function resolveCondition(validator, schema, rootSchema, formData) {
536
- const {
537
- if: expression,
538
- then,
539
- else: otherwise,
540
- ...resolvedSchemaLessConditional
541
- } = schema;
542
- const conditionalSchema = validator.isValid(expression, formData, rootSchema) ? then : otherwise;
543
-
486
+ var expression = schema["if"],
487
+ then = schema.then,
488
+ otherwise = schema["else"],
489
+ resolvedSchemaLessConditional = _objectWithoutPropertiesLoose(schema, _excluded$1);
490
+ var conditionalSchema = validator.isValid(expression, formData, rootSchema) ? then : otherwise;
544
491
  if (conditionalSchema && typeof conditionalSchema !== "boolean") {
545
492
  return retrieveSchema(validator, mergeSchemas(resolvedSchemaLessConditional, retrieveSchema(validator, conditionalSchema, rootSchema, formData)), rootSchema, formData);
546
493
  }
547
-
548
494
  return retrieveSchema(validator, resolvedSchemaLessConditional, rootSchema, formData);
549
495
  }
550
496
  /** Resolves references and dependencies within a schema and its 'allOf' children.
551
497
  * Called internally by retrieveSchema.
552
498
  *
553
- * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
499
+ * @param validator - An implementation of the `ValidatorType<T, S>` interface that will be forwarded to all the APIs
554
500
  * @param schema - The schema for which resolving a schema is desired
555
501
  * @param [rootSchema={}] - The root schema that will be forwarded to all the APIs
556
502
  * @param [formData] - The current formData, if any, to assist retrieving a schema
557
503
  * @returns - The schema having its references and dependencies resolved
558
504
  */
559
-
560
505
  function resolveSchema(validator, schema, rootSchema, formData) {
561
506
  if (rootSchema === void 0) {
562
507
  rootSchema = {};
563
508
  }
564
-
565
509
  if (REF_KEY in schema) {
566
510
  return resolveReference(validator, schema, rootSchema, formData);
567
511
  }
568
-
569
512
  if (DEPENDENCIES_KEY in schema) {
570
- const resolvedSchema = resolveDependencies(validator, schema, rootSchema, formData);
513
+ var resolvedSchema = resolveDependencies(validator, schema, rootSchema, formData);
571
514
  return retrieveSchema(validator, resolvedSchema, rootSchema, formData);
572
515
  }
573
-
574
516
  if (ALL_OF_KEY in schema) {
575
- return { ...schema,
576
- allOf: schema.allOf.map(allOfSubschema => retrieveSchema(validator, allOfSubschema, rootSchema, formData))
577
- };
578
- } // No $ref or dependencies attribute found, returning the original schema.
579
-
580
-
517
+ return _extends({}, schema, {
518
+ allOf: schema.allOf.map(function (allOfSubschema) {
519
+ return retrieveSchema(validator, allOfSubschema, rootSchema, formData);
520
+ })
521
+ });
522
+ }
523
+ // No $ref or dependencies attribute found, returning the original schema.
581
524
  return schema;
582
525
  }
583
526
  /** Resolves references within a schema and its 'allOf' children.
584
527
  *
585
- * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
528
+ * @param validator - An implementation of the `ValidatorType<T, S>` interface that will be forwarded to all the APIs
586
529
  * @param schema - The schema for which resolving a reference is desired
587
530
  * @param rootSchema - The root schema that will be forwarded to all the APIs
588
531
  * @param [formData] - The current formData, if any, to assist retrieving a schema
589
532
  * @returns - The schema having its references resolved
590
533
  */
591
-
592
534
  function resolveReference(validator, schema, rootSchema, formData) {
593
535
  // Retrieve the referenced schema definition.
594
- const $refSchema = findSchemaDefinition(schema.$ref, rootSchema); // Drop the $ref property of the source schema.
595
-
596
- const {
597
- $ref,
598
- ...localSchema
599
- } = schema; // Update referenced schema definition with local schema properties.
600
-
601
- return retrieveSchema(validator, { ...$refSchema,
602
- ...localSchema
603
- }, rootSchema, formData);
536
+ var $refSchema = findSchemaDefinition(schema.$ref, rootSchema);
537
+ // Drop the $ref property of the source schema.
538
+ var localSchema = _objectWithoutPropertiesLoose(schema, _excluded2);
539
+ // Update referenced schema definition with local schema properties.
540
+ return retrieveSchema(validator, _extends({}, $refSchema, localSchema), rootSchema, formData);
604
541
  }
605
542
  /** Creates new 'properties' items for each key in the `formData`
606
543
  *
607
- * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
544
+ * @param validator - An implementation of the `ValidatorType<T, S>` interface that will be used when necessary
608
545
  * @param theSchema - The schema for which the existing additional properties is desired
609
546
  * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s * @param validator
610
547
  * @param [aFormData] - The current formData, if any, to assist retrieving a schema
611
548
  * @returns - The updated schema with additional properties stubbed
612
549
  */
613
-
614
550
  function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFormData) {
615
551
  // Clone the schema so we don't ruin the consumer's original
616
- const schema = { ...theSchema,
617
- properties: { ...theSchema.properties
618
- }
619
- }; // make sure formData is an object
620
-
621
- const formData = aFormData && isObject(aFormData) ? aFormData : {};
622
- Object.keys(formData).forEach(key => {
552
+ var schema = _extends({}, theSchema, {
553
+ properties: _extends({}, theSchema.properties)
554
+ });
555
+ // make sure formData is an object
556
+ var formData = aFormData && isObject(aFormData) ? aFormData : {};
557
+ Object.keys(formData).forEach(function (key) {
623
558
  if (key in schema.properties) {
624
559
  // No need to stub, our schema already has the property
625
560
  return;
626
561
  }
627
-
628
- let additionalProperties = {};
629
-
562
+ var additionalProperties = {};
630
563
  if (typeof schema.additionalProperties !== "boolean") {
631
564
  if (REF_KEY in schema.additionalProperties) {
632
565
  additionalProperties = retrieveSchema(validator, {
633
566
  $ref: get__default["default"](schema.additionalProperties, [REF_KEY])
634
567
  }, rootSchema, formData);
635
568
  } else if ("type" in schema.additionalProperties) {
636
- additionalProperties = { ...schema.additionalProperties
637
- };
569
+ additionalProperties = _extends({}, schema.additionalProperties);
570
+ } else if (ANY_OF_KEY in schema.additionalProperties || ONE_OF_KEY in schema.additionalProperties) {
571
+ additionalProperties = _extends({
572
+ type: "object"
573
+ }, schema.additionalProperties);
638
574
  } else {
639
575
  additionalProperties = {
640
576
  type: guessType(get__default["default"](formData, [key]))
@@ -644,11 +580,10 @@
644
580
  additionalProperties = {
645
581
  type: guessType(get__default["default"](formData, [key]))
646
582
  };
647
- } // The type of our new key should match the additionalProperties value;
648
-
649
-
650
- schema.properties[key] = additionalProperties; // Set our additional property flag so we know it was dynamically added
651
-
583
+ }
584
+ // The type of our new key should match the additionalProperties value;
585
+ schema.properties[key] = additionalProperties;
586
+ // Set our additional property flag so we know it was dynamically added
652
587
  set__default["default"](schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
653
588
  });
654
589
  return schema;
@@ -657,132 +592,93 @@
657
592
  * resolved and merged into the `schema` given a `validator`, `rootSchema` and `rawFormData` that is used to do the
658
593
  * potentially recursive resolution.
659
594
  *
660
- * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
595
+ * @param validator - An implementation of the `ValidatorType<T, S>` interface that will be forwarded to all the APIs
661
596
  * @param schema - The schema for which retrieving a schema is desired
662
597
  * @param [rootSchema={}] - The root schema that will be forwarded to all the APIs
663
598
  * @param [rawFormData] - The current formData, if any, to assist retrieving a schema
664
599
  * @returns - The schema having its conditions, additional properties, references and dependencies resolved
665
600
  */
666
-
667
601
  function retrieveSchema(validator, schema, rootSchema, rawFormData) {
668
602
  if (rootSchema === void 0) {
669
603
  rootSchema = {};
670
604
  }
671
-
672
605
  if (!isObject(schema)) {
673
606
  return {};
674
607
  }
675
-
676
- let resolvedSchema = resolveSchema(validator, schema, rootSchema, rawFormData);
677
-
608
+ var resolvedSchema = resolveSchema(validator, schema, rootSchema, rawFormData);
678
609
  if ("if" in schema) {
679
610
  return resolveCondition(validator, schema, rootSchema, rawFormData);
680
611
  }
681
-
682
- const formData = rawFormData || {}; // For each level of the dependency, we need to recursively determine the appropriate resolved schema given the current state of formData.
683
- // Otherwise, nested allOf subschemas will not be correctly displayed.
684
-
685
- if (resolvedSchema.properties) {
686
- const properties = {};
687
- Object.entries(resolvedSchema.properties).forEach(entries => {
688
- const propName = entries[0];
689
- const propSchema = entries[1];
690
- const rawPropData = formData[propName];
691
- const propData = isObject(rawPropData) ? rawPropData : {};
692
- const resolvedPropSchema = retrieveSchema(validator, propSchema, rootSchema, propData);
693
- properties[propName] = resolvedPropSchema;
694
-
695
- if (propSchema !== resolvedPropSchema && resolvedSchema.properties !== properties) {
696
- resolvedSchema = { ...resolvedSchema,
697
- properties
698
- };
699
- }
700
- });
701
- }
702
-
612
+ var formData = rawFormData || {};
703
613
  if (ALL_OF_KEY in schema) {
704
614
  try {
705
- resolvedSchema = mergeAllOf__default["default"]({ ...resolvedSchema,
706
- allOf: resolvedSchema.allOf
615
+ resolvedSchema = mergeAllOf__default["default"](resolvedSchema, {
616
+ deep: false
707
617
  });
708
618
  } catch (e) {
709
619
  console.warn("could not merge subschemas in allOf:\n" + e);
710
- const {
711
- allOf,
712
- ...resolvedSchemaWithoutAllOf
713
- } = resolvedSchema;
620
+ var _resolvedSchema = resolvedSchema,
621
+ resolvedSchemaWithoutAllOf = _objectWithoutPropertiesLoose(_resolvedSchema, _excluded3);
714
622
  return resolvedSchemaWithoutAllOf;
715
623
  }
716
624
  }
717
-
718
- const hasAdditionalProperties = ADDITIONAL_PROPERTIES_KEY in resolvedSchema && resolvedSchema.additionalProperties !== false;
719
-
625
+ var hasAdditionalProperties = ADDITIONAL_PROPERTIES_KEY in resolvedSchema && resolvedSchema.additionalProperties !== false;
720
626
  if (hasAdditionalProperties) {
721
627
  return stubExistingAdditionalProperties(validator, resolvedSchema, rootSchema, formData);
722
628
  }
723
-
724
629
  return resolvedSchema;
725
630
  }
726
631
  /** Resolves dependencies within a schema and its 'allOf' children.
727
632
  *
728
- * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
633
+ * @param validator - An implementation of the `ValidatorType<T, S>` interface that will be forwarded to all the APIs
729
634
  * @param schema - The schema for which resolving a dependency is desired
730
635
  * @param rootSchema - The root schema that will be forwarded to all the APIs
731
636
  * @param [formData] - The current formData, if any, to assist retrieving a schema
732
637
  * @returns - The schema with its dependencies resolved
733
638
  */
734
-
735
639
  function resolveDependencies(validator, schema, rootSchema, formData) {
736
640
  // Drop the dependencies from the source schema.
737
- const {
738
- dependencies,
739
- ...remainingSchema
740
- } = schema;
741
- let resolvedSchema = remainingSchema;
742
-
641
+ var dependencies = schema.dependencies,
642
+ remainingSchema = _objectWithoutPropertiesLoose(schema, _excluded4);
643
+ var resolvedSchema = remainingSchema;
743
644
  if (Array.isArray(resolvedSchema.oneOf)) {
744
- resolvedSchema = resolvedSchema.oneOf[getMatchingOption(validator, formData, resolvedSchema.oneOf, rootSchema)];
645
+ resolvedSchema = resolvedSchema.oneOf[getFirstMatchingOption(validator, formData, resolvedSchema.oneOf, rootSchema)];
745
646
  } else if (Array.isArray(resolvedSchema.anyOf)) {
746
- resolvedSchema = resolvedSchema.anyOf[getMatchingOption(validator, formData, resolvedSchema.anyOf, rootSchema)];
647
+ resolvedSchema = resolvedSchema.anyOf[getFirstMatchingOption(validator, formData, resolvedSchema.anyOf, rootSchema)];
747
648
  }
748
-
749
649
  return processDependencies(validator, dependencies, resolvedSchema, rootSchema, formData);
750
650
  }
751
651
  /** Processes all the `dependencies` recursively into the `resolvedSchema` as needed
752
652
  *
753
- * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
653
+ * @param validator - An implementation of the `ValidatorType<T, S>` interface that will be forwarded to all the APIs
754
654
  * @param dependencies - The set of dependencies that needs to be processed
755
655
  * @param resolvedSchema - The schema for which processing dependencies is desired
756
656
  * @param rootSchema - The root schema that will be forwarded to all the APIs
757
657
  * @param [formData] - The current formData, if any, to assist retrieving a schema
758
658
  * @returns - The schema with the `dependencies` resolved into it
759
659
  */
760
-
761
660
  function processDependencies(validator, dependencies, resolvedSchema, rootSchema, formData) {
762
- let schema = resolvedSchema; // Process dependencies updating the local schema properties as appropriate.
763
-
764
- for (const dependencyKey in dependencies) {
661
+ var schema = resolvedSchema;
662
+ // Process dependencies updating the local schema properties as appropriate.
663
+ for (var dependencyKey in dependencies) {
765
664
  // Skip this dependency if its trigger property is not present.
766
665
  if (get__default["default"](formData, [dependencyKey]) === undefined) {
767
666
  continue;
768
- } // Skip this dependency if it is not included in the schema (such as when dependencyKey is itself a hidden dependency.)
769
-
770
-
667
+ }
668
+ // Skip this dependency if it is not included in the schema (such as when dependencyKey is itself a hidden dependency.)
771
669
  if (schema.properties && !(dependencyKey in schema.properties)) {
772
670
  continue;
773
671
  }
774
-
775
- const [remainingDependencies, dependencyValue] = splitKeyElementFromObject(dependencyKey, dependencies);
776
-
672
+ var _splitKeyElementFromO = splitKeyElementFromObject(dependencyKey, dependencies),
673
+ remainingDependencies = _splitKeyElementFromO[0],
674
+ dependencyValue = _splitKeyElementFromO[1];
777
675
  if (Array.isArray(dependencyValue)) {
778
676
  schema = withDependentProperties(schema, dependencyValue);
779
677
  } else if (isObject(dependencyValue)) {
780
678
  schema = withDependentSchema(validator, schema, rootSchema, dependencyKey, dependencyValue, formData);
781
679
  }
782
-
783
680
  return processDependencies(validator, remainingDependencies, schema, rootSchema, formData);
784
681
  }
785
-
786
682
  return schema;
787
683
  }
788
684
  /** Updates a schema with additionally required properties added
@@ -791,20 +687,18 @@
791
687
  * @param [additionallyRequired] - An optional array of additionally required names
792
688
  * @returns - The schema with the additional required values merged in
793
689
  */
794
-
795
690
  function withDependentProperties(schema, additionallyRequired) {
796
691
  if (!additionallyRequired) {
797
692
  return schema;
798
693
  }
799
-
800
- const required = Array.isArray(schema.required) ? Array.from(new Set([...schema.required, ...additionallyRequired])) : additionallyRequired;
801
- return { ...schema,
694
+ var required = Array.isArray(schema.required) ? Array.from(new Set([].concat(schema.required, additionallyRequired))) : additionallyRequired;
695
+ return _extends({}, schema, {
802
696
  required: required
803
- };
697
+ });
804
698
  }
805
699
  /** Merges a dependent schema into the `schema` dealing with oneOfs and references
806
700
  *
807
- * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
701
+ * @param validator - An implementation of the `ValidatorType<T, S>` interface that will be forwarded to all the APIs
808
702
  * @param schema - The schema for which resolving a dependent schema is desired
809
703
  * @param rootSchema - The root schema that will be forwarded to all the APIs
810
704
  * @param dependencyKey - The key name of the dependency
@@ -812,78 +706,301 @@
812
706
  * @param formData- The current formData to assist retrieving a schema
813
707
  * @returns - The schema with the dependent schema resolved into it
814
708
  */
815
-
816
709
  function withDependentSchema(validator, schema, rootSchema, dependencyKey, dependencyValue, formData) {
817
- const {
818
- oneOf,
819
- ...dependentSchema
820
- } = retrieveSchema(validator, dependencyValue, rootSchema, formData);
821
- schema = mergeSchemas(schema, dependentSchema); // Since it does not contain oneOf, we return the original schema.
822
-
710
+ var _retrieveSchema = retrieveSchema(validator, dependencyValue, rootSchema, formData),
711
+ oneOf = _retrieveSchema.oneOf,
712
+ dependentSchema = _objectWithoutPropertiesLoose(_retrieveSchema, _excluded5);
713
+ schema = mergeSchemas(schema, dependentSchema);
714
+ // Since it does not contain oneOf, we return the original schema.
823
715
  if (oneOf === undefined) {
824
716
  return schema;
825
- } // Resolve $refs inside oneOf.
826
-
827
-
828
- const resolvedOneOf = oneOf.map(subschema => {
717
+ }
718
+ // Resolve $refs inside oneOf.
719
+ var resolvedOneOf = oneOf.map(function (subschema) {
829
720
  if (typeof subschema === "boolean" || !(REF_KEY in subschema)) {
830
721
  return subschema;
831
722
  }
832
-
833
723
  return resolveReference(validator, subschema, rootSchema, formData);
834
724
  });
835
725
  return withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, resolvedOneOf, formData);
836
726
  }
837
727
  /** Returns a `schema` with the best choice from the `oneOf` options merged into it
838
728
  *
839
- * @param validator - An implementation of the `ValidatorType` interface that will be used to validate oneOf options
729
+ * @param validator - An implementation of the `ValidatorType<T, S>` interface that will be used to validate oneOf options
840
730
  * @param schema - The schema for which resolving a oneOf subschema is desired
841
731
  * @param rootSchema - The root schema that will be forwarded to all the APIs
842
732
  * @param dependencyKey - The key name of the oneOf dependency
843
733
  * @param oneOf - The list of schemas representing the oneOf options
844
734
  * @param [formData] - The current formData to assist retrieving a schema
845
- * @returns The schema with best choice of oneOf schemas merged into
735
+ * @returns The schema with the best choice of oneOf schemas merged into
846
736
  */
847
-
848
737
  function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, oneOf, formData) {
849
- const validSubschemas = oneOf.filter(subschema => {
850
- if (typeof subschema === "boolean" || !subschema.properties) {
738
+ var validSubschemas = oneOf.filter(function (subschema) {
739
+ if (typeof subschema === "boolean" || !subschema || !subschema.properties) {
851
740
  return false;
852
741
  }
853
-
854
- const {
855
- [dependencyKey]: conditionPropertySchema
856
- } = subschema.properties;
857
-
742
+ var conditionPropertySchema = subschema.properties[dependencyKey];
858
743
  if (conditionPropertySchema) {
859
- const conditionSchema = {
744
+ var _properties;
745
+ var conditionSchema = {
860
746
  type: "object",
861
- properties: {
862
- [dependencyKey]: conditionPropertySchema
863
- }
747
+ properties: (_properties = {}, _properties[dependencyKey] = conditionPropertySchema, _properties)
864
748
  };
865
- const {
866
- errors
867
- } = validator.validateFormData(formData, conditionSchema);
749
+ var _validator$validateFo = validator.validateFormData(formData, conditionSchema),
750
+ errors = _validator$validateFo.errors;
868
751
  return errors.length === 0;
869
752
  }
870
-
871
753
  return false;
872
754
  });
873
-
874
755
  if (validSubschemas.length !== 1) {
875
756
  console.warn("ignoring oneOf in dependencies because there isn't exactly one subschema that is valid");
876
757
  return schema;
877
758
  }
878
-
879
- const subschema = validSubschemas[0];
880
- const [dependentSubschema] = splitKeyElementFromObject(dependencyKey, subschema.properties);
881
- const dependentSchema = { ...subschema,
759
+ var subschema = validSubschemas[0];
760
+ var _splitKeyElementFromO2 = splitKeyElementFromObject(dependencyKey, subschema.properties),
761
+ dependentSubschema = _splitKeyElementFromO2[0];
762
+ var dependentSchema = _extends({}, subschema, {
882
763
  properties: dependentSubschema
883
- };
764
+ });
884
765
  return mergeSchemas(schema, retrieveSchema(validator, dependentSchema, rootSchema, formData));
885
766
  }
886
767
 
768
+ /** A junk option used to determine when the getFirstMatchingOption call really matches an option rather than returning
769
+ * the first item
770
+ */
771
+ var JUNK_OPTION = {
772
+ type: "object",
773
+ properties: {
774
+ __not_really_there__: {
775
+ type: "number"
776
+ }
777
+ }
778
+ };
779
+ /** Recursive function that calculates the score of a `formData` against the given `schema`. The computation is fairly
780
+ * simple. Initially the total score is 0. When `schema.properties` object exists, then all the `key/value` pairs within
781
+ * the object are processed as follows after obtaining the formValue from `formData` using the `key`:
782
+ * - If the `value` contains a `$ref`, `calculateIndexScore()` is called recursively with the formValue and the new
783
+ * schema that is the result of the ref in the schema being resolved and that sub-schema's resulting score is added to
784
+ * the total.
785
+ * - If the `value` contains a `oneOf` and there is a formValue, then score based on the index returned from calling
786
+ * `getClosestMatchingOption()` of that oneOf.
787
+ * - If the type of the `value` is 'object', `calculateIndexScore()` is called recursively with the formValue and the
788
+ * `value` itself as the sub-schema, and the score is added to the total.
789
+ * - If the type of the `value` matches the guessed-type of the `formValue`, the score is incremented by 1, UNLESS the
790
+ * value has a `default` or `const`. In those case, if the `default` or `const` and the `formValue` match, the score
791
+ * is incremented by another 1 otherwise it is decremented by 1.
792
+ *
793
+ * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
794
+ * @param rootSchema - The root JSON schema of the entire form
795
+ * @param schema - The schema for which the score is being calculated
796
+ * @param formData - The form data associated with the schema, used to calculate the score
797
+ * @returns - The score a schema against the formData
798
+ */
799
+ function calculateIndexScore(validator, rootSchema, schema, formData) {
800
+ if (formData === void 0) {
801
+ formData = {};
802
+ }
803
+ var totalScore = 0;
804
+ if (schema) {
805
+ if (isObject__default["default"](schema.properties)) {
806
+ totalScore += reduce__default["default"](schema.properties, function (score, value, key) {
807
+ var formValue = get__default["default"](formData, key);
808
+ if (typeof value === "boolean") {
809
+ return score;
810
+ }
811
+ if (has__default["default"](value, REF_KEY)) {
812
+ var newSchema = retrieveSchema(validator, value, rootSchema, formValue);
813
+ return score + calculateIndexScore(validator, rootSchema, newSchema, formValue || {});
814
+ }
815
+ if (has__default["default"](value, ONE_OF_KEY) && formValue) {
816
+ return score + getClosestMatchingOption(validator, rootSchema, formValue, get__default["default"](value, ONE_OF_KEY));
817
+ }
818
+ if (value.type === "object") {
819
+ return score + calculateIndexScore(validator, rootSchema, value, formValue || {});
820
+ }
821
+ if (value.type === guessType(formValue)) {
822
+ // If the types match, then we bump the score by one
823
+ var newScore = score + 1;
824
+ if (value["default"]) {
825
+ // If the schema contains a readonly default value score the value that matches the default higher and
826
+ // any non-matching value lower
827
+ newScore += formValue === value["default"] ? 1 : -1;
828
+ } else if (value["const"]) {
829
+ // If the schema contains a const value score the value that matches the default higher and
830
+ // any non-matching value lower
831
+ newScore += formValue === value["const"] ? 1 : -1;
832
+ }
833
+ // TODO eventually, deal with enums/arrays
834
+ return newScore;
835
+ }
836
+ return score;
837
+ }, 0);
838
+ } else if (isString__default["default"](schema.type) && schema.type === guessType(formData)) {
839
+ totalScore += 1;
840
+ }
841
+ }
842
+ return totalScore;
843
+ }
844
+ /** Determines which of the given `options` provided most closely matches the `formData`. Using
845
+ * `getFirstMatchingOption()` to match two schemas that differ only by the readOnly, default or const value of a field
846
+ * based on the `formData` and returns 0 when there is no match. Rather than passing in all the `options` at once to
847
+ * this utility, instead an array of valid option indexes is created by iterating over the list of options, call
848
+ * `getFirstMatchingOptions` with a list of one junk option and one good option, seeing if the good option is considered
849
+ * matched.
850
+ *
851
+ * Once the list of valid indexes is created, if there is only one valid index, just return it. Otherwise, if there are
852
+ * no valid indexes, then fill the valid indexes array with the indexes of all the options. Next, the index of the
853
+ * option with the highest score is determined by iterating over the list of valid options, calling
854
+ * `calculateIndexScore()` on each, comparing it against the current best score, and returning the index of the one that
855
+ * eventually has the best score.
856
+ *
857
+ * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
858
+ * @param rootSchema - The root JSON schema of the entire form
859
+ * @param formData - The form data associated with the schema
860
+ * @param options - The list of options that can be selected from
861
+ * @param [selectedOption=-1] - The index of the currently selected option, defaulted to -1 if not specified
862
+ * @returns - The index of the option that is the closest match to the `formData` or the `selectedOption` if no match
863
+ */
864
+ function getClosestMatchingOption(validator, rootSchema, formData, options, selectedOption) {
865
+ if (selectedOption === void 0) {
866
+ selectedOption = -1;
867
+ }
868
+ // Reduce the array of options down to a list of the indexes that are considered matching options
869
+ var allValidIndexes = options.reduce(function (validList, option, index) {
870
+ var testOptions = [JUNK_OPTION, option];
871
+ var match = getFirstMatchingOption(validator, formData, testOptions, rootSchema);
872
+ // The match is the real option, so add its index to list of valid indexes
873
+ if (match === 1) {
874
+ validList.push(index);
875
+ }
876
+ return validList;
877
+ }, []);
878
+ // There is only one valid index, so return it!
879
+ if (allValidIndexes.length === 1) {
880
+ return allValidIndexes[0];
881
+ }
882
+ if (!allValidIndexes.length) {
883
+ // No indexes were valid, so we'll score all the options, add all the indexes
884
+ times__default["default"](options.length, function (i) {
885
+ return allValidIndexes.push(i);
886
+ });
887
+ }
888
+ // Score all the options in the list of valid indexes and return the index with the best score
889
+ var _allValidIndexes$redu = allValidIndexes.reduce(function (scoreData, index) {
890
+ var bestScore = scoreData.bestScore;
891
+ var option = options[index];
892
+ if (has__default["default"](option, REF_KEY)) {
893
+ option = retrieveSchema(validator, option, rootSchema, formData);
894
+ }
895
+ var score = calculateIndexScore(validator, rootSchema, option, formData);
896
+ if (score > bestScore) {
897
+ return {
898
+ bestIndex: index,
899
+ bestScore: score
900
+ };
901
+ }
902
+ return scoreData;
903
+ }, {
904
+ bestIndex: selectedOption,
905
+ bestScore: 0
906
+ }),
907
+ bestIndex = _allValidIndexes$redu.bestIndex;
908
+ return bestIndex;
909
+ }
910
+
911
+ /** Detects whether the given `schema` contains fixed items. This is the case when `schema.items` is a non-empty array
912
+ * that only contains objects.
913
+ *
914
+ * @param schema - The schema in which to check for fixed items
915
+ * @returns - True if there are fixed items in the schema, false otherwise
916
+ */
917
+ function isFixedItems(schema) {
918
+ return Array.isArray(schema.items) && schema.items.length > 0 && schema.items.every(function (item) {
919
+ return isObject(item);
920
+ });
921
+ }
922
+
923
+ /** Merges the `defaults` object of type `T` into the `formData` of type `T`
924
+ *
925
+ * When merging defaults and form data, we want to merge in this specific way:
926
+ * - objects are deeply merged
927
+ * - arrays are merged in such a way that:
928
+ * - when the array is set in form data, only array entries set in form data
929
+ * are deeply merged; additional entries from the defaults are ignored
930
+ * - when the array is not set in form data, the default is copied over
931
+ * - scalars are overwritten/set by form data
932
+ *
933
+ * @param [defaults] - The defaults to merge
934
+ * @param [formData] - The form data into which the defaults will be merged
935
+ * @returns - The resulting merged form data with defaults
936
+ */
937
+ function mergeDefaultsWithFormData(defaults, formData) {
938
+ if (Array.isArray(formData)) {
939
+ var defaultsArray = Array.isArray(defaults) ? defaults : [];
940
+ var mapped = formData.map(function (value, idx) {
941
+ if (defaultsArray[idx]) {
942
+ return mergeDefaultsWithFormData(defaultsArray[idx], value);
943
+ }
944
+ return value;
945
+ });
946
+ return mapped;
947
+ }
948
+ if (isObject(formData)) {
949
+ var acc = Object.assign({}, defaults); // Prevent mutation of source object.
950
+ return Object.keys(formData).reduce(function (acc, key) {
951
+ acc[key] = mergeDefaultsWithFormData(defaults ? get__default["default"](defaults, key) : {}, get__default["default"](formData, key));
952
+ return acc;
953
+ }, acc);
954
+ }
955
+ return formData;
956
+ }
957
+
958
+ /** Recursively merge deeply nested objects.
959
+ *
960
+ * @param obj1 - The first object to merge
961
+ * @param obj2 - The second object to merge
962
+ * @param [concatArrays=false] - Optional flag that, when true, will cause arrays to be concatenated. Use
963
+ * "preventDuplicates" to merge arrays in a manner that prevents any duplicate entries from being merged.
964
+ * NOTE: Uses shallow comparison for the duplicate checking.
965
+ * @returns - A new object that is the merge of the two given objects
966
+ */
967
+ function mergeObjects(obj1, obj2, concatArrays) {
968
+ if (concatArrays === void 0) {
969
+ concatArrays = false;
970
+ }
971
+ return Object.keys(obj2).reduce(function (acc, key) {
972
+ var left = obj1 ? obj1[key] : {},
973
+ right = obj2[key];
974
+ if (obj1 && key in obj1 && isObject(right)) {
975
+ acc[key] = mergeObjects(left, right, concatArrays);
976
+ } else if (concatArrays && Array.isArray(left) && Array.isArray(right)) {
977
+ var toMerge = right;
978
+ if (concatArrays === "preventDuplicates") {
979
+ toMerge = right.reduce(function (result, value) {
980
+ if (!left.includes(value)) {
981
+ result.push(value);
982
+ }
983
+ return result;
984
+ }, []);
985
+ }
986
+ acc[key] = left.concat(toMerge);
987
+ } else {
988
+ acc[key] = right;
989
+ }
990
+ return acc;
991
+ }, Object.assign({}, obj1)); // Prevent mutation of source object.
992
+ }
993
+
994
+ /** This function checks if the given `schema` matches a single constant value. This happens when either the schema has
995
+ * an `enum` array with a single value or there is a `const` defined.
996
+ *
997
+ * @param schema - The schema for a field
998
+ * @returns - True if the `schema` has a single constant value, false otherwise
999
+ */
1000
+ function isConstant(schema) {
1001
+ return Array.isArray(schema["enum"]) && schema["enum"].length === 1 || CONST_KEY in schema;
1002
+ }
1003
+
887
1004
  /** Checks to see if the `schema` combination represents a select
888
1005
  *
889
1006
  * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
@@ -891,23 +1008,20 @@
891
1008
  * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
892
1009
  * @returns - True if schema contains a select, otherwise false
893
1010
  */
894
-
895
1011
  function isSelect(validator, theSchema, rootSchema) {
896
1012
  if (rootSchema === void 0) {
897
1013
  rootSchema = {};
898
1014
  }
899
-
900
- const schema = retrieveSchema(validator, theSchema, rootSchema, undefined);
901
- const altSchemas = schema.oneOf || schema.anyOf;
902
-
903
- if (Array.isArray(schema.enum)) {
1015
+ var schema = retrieveSchema(validator, theSchema, rootSchema, undefined);
1016
+ var altSchemas = schema.oneOf || schema.anyOf;
1017
+ if (Array.isArray(schema["enum"])) {
904
1018
  return true;
905
1019
  }
906
-
907
1020
  if (Array.isArray(altSchemas)) {
908
- return altSchemas.every(altSchemas => typeof altSchemas !== "boolean" && isConstant(altSchemas));
1021
+ return altSchemas.every(function (altSchemas) {
1022
+ return typeof altSchemas !== "boolean" && isConstant(altSchemas);
1023
+ });
909
1024
  }
910
-
911
1025
  return false;
912
1026
  }
913
1027
 
@@ -918,20 +1032,16 @@
918
1032
  * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
919
1033
  * @returns - True if schema contains a multi-select, otherwise false
920
1034
  */
921
-
922
1035
  function isMultiSelect(validator, schema, rootSchema) {
923
1036
  if (!schema.uniqueItems || !schema.items || typeof schema.items === "boolean") {
924
1037
  return false;
925
1038
  }
926
-
927
1039
  return isSelect(validator, schema.items, rootSchema);
928
1040
  }
929
1041
 
930
1042
  /** Enum that indicates how `schema.additionalItems` should be handled by the `getInnerSchemaForArrayItem()` function.
931
1043
  */
932
-
933
1044
  var AdditionalItemsHandling;
934
-
935
1045
  (function (AdditionalItemsHandling) {
936
1046
  AdditionalItemsHandling[AdditionalItemsHandling["Ignore"] = 0] = "Ignore";
937
1047
  AdditionalItemsHandling[AdditionalItemsHandling["Invert"] = 1] = "Invert";
@@ -952,21 +1062,16 @@
952
1062
  * @param [idx=-1] - Index, if non-negative, will be used to return the idx-th element in a `schema.items` array
953
1063
  * @returns - The best fit schema object from the `schema` given the `additionalItems` and `idx` modifiers
954
1064
  */
955
-
956
-
957
1065
  function getInnerSchemaForArrayItem(schema, additionalItems, idx) {
958
1066
  if (additionalItems === void 0) {
959
1067
  additionalItems = AdditionalItemsHandling.Ignore;
960
1068
  }
961
-
962
1069
  if (idx === void 0) {
963
1070
  idx = -1;
964
1071
  }
965
-
966
1072
  if (idx >= 0) {
967
1073
  if (Array.isArray(schema.items) && idx < schema.items.length) {
968
- const item = schema.items[idx];
969
-
1074
+ var item = schema.items[idx];
970
1075
  if (typeof item !== "boolean") {
971
1076
  return item;
972
1077
  }
@@ -974,116 +1079,112 @@
974
1079
  } else if (schema.items && !Array.isArray(schema.items) && typeof schema.items !== "boolean") {
975
1080
  return schema.items;
976
1081
  }
977
-
978
1082
  if (additionalItems !== AdditionalItemsHandling.Ignore && isObject(schema.additionalItems)) {
979
1083
  return schema.additionalItems;
980
1084
  }
981
-
982
1085
  return {};
983
1086
  }
984
1087
  /** Computes the defaults for the current `schema` given the `rawFormData` and `parentDefaults` if any. This drills into
985
- * the each level of the schema, recursively, to fill out every level of defaults provided by the schema.
1088
+ * each level of the schema, recursively, to fill out every level of defaults provided by the schema.
986
1089
  *
987
1090
  * @param validator - an implementation of the `ValidatorType` interface that will be used when necessary
988
1091
  * @param schema - The schema for which the default state is desired
989
1092
  * @param [parentDefaults] - Any defaults provided by the parent field in the schema
990
1093
  * @param [rootSchema] - The options root schema, used to primarily to look up `$ref`s
991
1094
  * @param [rawFormData] - The current formData, if any, onto which to provide any missing defaults
992
- * @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults
1095
+ * @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults.
1096
+ * If "excludeObjectChildren", pass `includeUndefinedValues` as false when computing defaults for any nested
1097
+ * object properties.
993
1098
  * @returns - The resulting `formData` with all the defaults provided
994
1099
  */
995
-
996
- function computeDefaults(validator, schema, parentDefaults, rootSchema, rawFormData, includeUndefinedValues) {
1100
+ function computeDefaults(validator, rawSchema, parentDefaults, rootSchema, rawFormData, includeUndefinedValues) {
997
1101
  if (rootSchema === void 0) {
998
1102
  rootSchema = {};
999
1103
  }
1000
-
1001
1104
  if (includeUndefinedValues === void 0) {
1002
1105
  includeUndefinedValues = false;
1003
1106
  }
1004
-
1005
- const formData = isObject(rawFormData) ? rawFormData : {}; // Compute the defaults recursively: give highest priority to deepest nodes.
1006
-
1007
- let defaults = parentDefaults;
1008
-
1009
- if (isObject(defaults) && isObject(schema.default)) {
1107
+ var formData = isObject(rawFormData) ? rawFormData : {};
1108
+ var schema = isObject(rawSchema) ? rawSchema : {};
1109
+ // Compute the defaults recursively: give highest priority to deepest nodes.
1110
+ var defaults = parentDefaults;
1111
+ if (isObject(defaults) && isObject(schema["default"])) {
1010
1112
  // For object defaults, only override parent defaults that are defined in
1011
1113
  // schema.default.
1012
- defaults = mergeObjects(defaults, schema.default);
1114
+ defaults = mergeObjects(defaults, schema["default"]);
1013
1115
  } else if (DEFAULT_KEY in schema) {
1014
- defaults = schema.default;
1116
+ defaults = schema["default"];
1015
1117
  } else if (REF_KEY in schema) {
1016
1118
  // Use referenced schema defaults for this node.
1017
- const refSchema = findSchemaDefinition(schema[REF_KEY], rootSchema);
1119
+ var refSchema = findSchemaDefinition(schema[REF_KEY], rootSchema);
1018
1120
  return computeDefaults(validator, refSchema, defaults, rootSchema, formData, includeUndefinedValues);
1019
1121
  } else if (DEPENDENCIES_KEY in schema) {
1020
- const resolvedSchema = resolveDependencies(validator, schema, rootSchema, formData);
1122
+ var resolvedSchema = resolveDependencies(validator, schema, rootSchema, formData);
1021
1123
  return computeDefaults(validator, resolvedSchema, defaults, rootSchema, formData, includeUndefinedValues);
1022
1124
  } else if (isFixedItems(schema)) {
1023
- defaults = schema.items.map((itemSchema, idx) => computeDefaults(validator, itemSchema, Array.isArray(parentDefaults) ? parentDefaults[idx] : undefined, rootSchema, formData, includeUndefinedValues));
1125
+ defaults = schema.items.map(function (itemSchema, idx) {
1126
+ return computeDefaults(validator, itemSchema, Array.isArray(parentDefaults) ? parentDefaults[idx] : undefined, rootSchema, formData, includeUndefinedValues);
1127
+ });
1024
1128
  } else if (ONE_OF_KEY in schema) {
1025
- schema = schema.oneOf[getMatchingOption(validator, undefined, schema.oneOf, rootSchema)];
1129
+ schema = schema.oneOf[getClosestMatchingOption(validator, rootSchema, isEmpty__default["default"](formData) ? undefined : formData, schema.oneOf, 0)];
1026
1130
  } else if (ANY_OF_KEY in schema) {
1027
- schema = schema.anyOf[getMatchingOption(validator, undefined, schema.anyOf, rootSchema)];
1028
- } // Not defaults defined for this node, fallback to generic typed ones.
1029
-
1030
-
1131
+ schema = schema.anyOf[getClosestMatchingOption(validator, rootSchema, isEmpty__default["default"](formData) ? undefined : formData, schema.anyOf, 0)];
1132
+ }
1133
+ // Not defaults defined for this node, fallback to generic typed ones.
1031
1134
  if (typeof defaults === "undefined") {
1032
- defaults = schema.default;
1135
+ defaults = schema["default"];
1033
1136
  }
1034
-
1035
1137
  switch (getSchemaType(schema)) {
1036
1138
  // We need to recur for object schema inner default values.
1037
1139
  case "object":
1038
- return Object.keys(schema.properties || {}).reduce((acc, key) => {
1140
+ return Object.keys(schema.properties || {}).reduce(function (acc, key) {
1039
1141
  // Compute the defaults for this node, with the parent defaults we might
1040
1142
  // have from a previous run: defaults[key].
1041
- const computedDefault = computeDefaults(validator, get__default["default"](schema, [PROPERTIES_KEY, key]), get__default["default"](defaults, [key]), rootSchema, get__default["default"](formData, [key]), includeUndefinedValues);
1042
-
1043
- if (includeUndefinedValues || computedDefault !== undefined) {
1143
+ var computedDefault = computeDefaults(validator, get__default["default"](schema, [PROPERTIES_KEY, key]), get__default["default"](defaults, [key]), rootSchema, get__default["default"](formData, [key]), includeUndefinedValues === "excludeObjectChildren" ? false : includeUndefinedValues);
1144
+ if (includeUndefinedValues) {
1145
+ acc[key] = computedDefault;
1146
+ } else if (isObject(computedDefault)) {
1147
+ // Store computedDefault if it's a non-empty object (e.g. not {})
1148
+ if (!isEmpty__default["default"](computedDefault)) {
1149
+ acc[key] = computedDefault;
1150
+ }
1151
+ } else if (computedDefault !== undefined) {
1152
+ // Store computedDefault if it's a defined primitive (e.g. true)
1044
1153
  acc[key] = computedDefault;
1045
1154
  }
1046
-
1047
1155
  return acc;
1048
1156
  }, {});
1049
-
1050
1157
  case "array":
1051
1158
  // Inject defaults into existing array defaults
1052
1159
  if (Array.isArray(defaults)) {
1053
- defaults = defaults.map((item, idx) => {
1054
- const schemaItem = getInnerSchemaForArrayItem(schema, AdditionalItemsHandling.Fallback, idx);
1160
+ defaults = defaults.map(function (item, idx) {
1161
+ var schemaItem = getInnerSchemaForArrayItem(schema, AdditionalItemsHandling.Fallback, idx);
1055
1162
  return computeDefaults(validator, schemaItem, item, rootSchema);
1056
1163
  });
1057
- } // Deeply inject defaults into already existing form data
1058
-
1059
-
1164
+ }
1165
+ // Deeply inject defaults into already existing form data
1060
1166
  if (Array.isArray(rawFormData)) {
1061
- const schemaItem = getInnerSchemaForArrayItem(schema);
1062
- defaults = rawFormData.map((item, idx) => {
1167
+ var schemaItem = getInnerSchemaForArrayItem(schema);
1168
+ defaults = rawFormData.map(function (item, idx) {
1063
1169
  return computeDefaults(validator, schemaItem, get__default["default"](defaults, [idx]), rootSchema, item);
1064
1170
  });
1065
1171
  }
1066
-
1067
1172
  if (schema.minItems) {
1068
1173
  if (!isMultiSelect(validator, schema, rootSchema)) {
1069
- const defaultsLength = Array.isArray(defaults) ? defaults.length : 0;
1070
-
1174
+ var defaultsLength = Array.isArray(defaults) ? defaults.length : 0;
1071
1175
  if (schema.minItems > defaultsLength) {
1072
- const defaultEntries = defaults || []; // populate the array with the defaults
1073
-
1074
- const fillerSchema = getInnerSchemaForArrayItem(schema, AdditionalItemsHandling.Invert);
1075
- const fillerDefault = fillerSchema.default;
1076
- const fillerEntries = new Array(schema.minItems - defaultsLength).fill(computeDefaults(validator, fillerSchema, fillerDefault, rootSchema)); // then fill up the rest with either the item default or empty, up to minItems
1077
-
1176
+ var defaultEntries = defaults || [];
1177
+ // populate the array with the defaults
1178
+ var fillerSchema = getInnerSchemaForArrayItem(schema, AdditionalItemsHandling.Invert);
1179
+ var fillerDefault = fillerSchema["default"];
1180
+ var fillerEntries = new Array(schema.minItems - defaultsLength).fill(computeDefaults(validator, fillerSchema, fillerDefault, rootSchema));
1181
+ // then fill up the rest with either the item default or empty, up to minItems
1078
1182
  return defaultEntries.concat(fillerEntries);
1079
1183
  }
1080
1184
  }
1081
-
1082
1185
  return defaults ? defaults : [];
1083
1186
  }
1084
-
1085
1187
  }
1086
-
1087
1188
  return defaults;
1088
1189
  }
1089
1190
  /** Returns the superset of `formData` that includes the given set updated to include any missing fields that have
@@ -1093,35 +1194,30 @@
1093
1194
  * @param theSchema - The schema for which the default state is desired
1094
1195
  * @param [formData] - The current formData, if any, onto which to provide any missing defaults
1095
1196
  * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
1096
- * @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults
1197
+ * @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults.
1198
+ * If "excludeObjectChildren", pass `includeUndefinedValues` as false when computing defaults for any nested
1199
+ * object properties.
1097
1200
  * @returns - The resulting `formData` with all the defaults provided
1098
1201
  */
1099
-
1100
1202
  function getDefaultFormState(validator, theSchema, formData, rootSchema, includeUndefinedValues) {
1101
1203
  if (includeUndefinedValues === void 0) {
1102
1204
  includeUndefinedValues = false;
1103
1205
  }
1104
-
1105
1206
  if (!isObject(theSchema)) {
1106
1207
  throw new Error("Invalid schema: " + theSchema);
1107
1208
  }
1108
-
1109
- const schema = retrieveSchema(validator, theSchema, rootSchema, formData);
1110
- const defaults = computeDefaults(validator, schema, undefined, rootSchema, formData, includeUndefinedValues);
1111
-
1209
+ var schema = retrieveSchema(validator, theSchema, rootSchema, formData);
1210
+ var defaults = computeDefaults(validator, schema, undefined, rootSchema, formData, includeUndefinedValues);
1112
1211
  if (typeof formData === "undefined" || formData === null || typeof formData === "number" && isNaN(formData)) {
1113
1212
  // No form data? Use schema defaults.
1114
1213
  return defaults;
1115
1214
  }
1116
-
1117
1215
  if (isObject(formData)) {
1118
1216
  return mergeDefaultsWithFormData(defaults, formData);
1119
1217
  }
1120
-
1121
1218
  if (Array.isArray(formData)) {
1122
1219
  return mergeDefaultsWithFormData(defaults, formData);
1123
1220
  }
1124
-
1125
1221
  return formData;
1126
1222
  }
1127
1223
 
@@ -1130,13 +1226,12 @@
1130
1226
  * @param uiSchema - The UI Schema from which to detect if it is customized
1131
1227
  * @returns - True if the `uiSchema` describes a custom widget, false otherwise
1132
1228
  */
1133
-
1134
1229
  function isCustomWidget(uiSchema) {
1135
1230
  if (uiSchema === void 0) {
1136
1231
  uiSchema = {};
1137
1232
  }
1138
-
1139
- return (// TODO: Remove the `&& uiSchema['ui:widget'] !== 'hidden'` once we support hidden widgets for arrays.
1233
+ return (
1234
+ // TODO: Remove the `&& uiSchema['ui:widget'] !== 'hidden'` once we support hidden widgets for arrays.
1140
1235
  // https://react-jsonschema-form.readthedocs.io/en/latest/usage/widgets/#hidden-widgets
1141
1236
  "widget" in getUiOptions(uiSchema) && getUiOptions(uiSchema)["widget"] !== "hidden"
1142
1237
  );
@@ -1150,21 +1245,17 @@
1150
1245
  * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
1151
1246
  * @returns - True if schema/uiSchema contains an array of files, otherwise false
1152
1247
  */
1153
-
1154
1248
  function isFilesArray(validator, schema, uiSchema, rootSchema) {
1155
1249
  if (uiSchema === void 0) {
1156
1250
  uiSchema = {};
1157
1251
  }
1158
-
1159
1252
  if (uiSchema[UI_WIDGET_KEY] === "files") {
1160
1253
  return true;
1161
1254
  }
1162
-
1163
1255
  if (schema.items) {
1164
- const itemsSchema = retrieveSchema(validator, schema.items, rootSchema);
1256
+ var itemsSchema = retrieveSchema(validator, schema.items, rootSchema);
1165
1257
  return itemsSchema.type === "string" && itemsSchema.format === "data-url";
1166
1258
  }
1167
-
1168
1259
  return false;
1169
1260
  }
1170
1261
 
@@ -1177,35 +1268,27 @@
1177
1268
  * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
1178
1269
  * @returns - True if the label should be displayed or false if it should not
1179
1270
  */
1180
-
1181
1271
  function getDisplayLabel(validator, schema, uiSchema, rootSchema) {
1182
1272
  if (uiSchema === void 0) {
1183
1273
  uiSchema = {};
1184
1274
  }
1185
-
1186
- const uiOptions = getUiOptions(uiSchema);
1187
- const {
1188
- label = true
1189
- } = uiOptions;
1190
- let displayLabel = !!label;
1191
- const schemaType = getSchemaType(schema);
1192
-
1275
+ var uiOptions = getUiOptions(uiSchema);
1276
+ var _uiOptions$label = uiOptions.label,
1277
+ label = _uiOptions$label === void 0 ? true : _uiOptions$label;
1278
+ var displayLabel = !!label;
1279
+ var schemaType = getSchemaType(schema);
1193
1280
  if (schemaType === "array") {
1194
1281
  displayLabel = isMultiSelect(validator, schema, rootSchema) || isFilesArray(validator, schema, uiSchema, rootSchema) || isCustomWidget(uiSchema);
1195
1282
  }
1196
-
1197
1283
  if (schemaType === "object") {
1198
1284
  displayLabel = false;
1199
1285
  }
1200
-
1201
1286
  if (schemaType === "boolean" && !uiSchema[UI_WIDGET_KEY]) {
1202
1287
  displayLabel = false;
1203
1288
  }
1204
-
1205
1289
  if (uiSchema[UI_FIELD_KEY]) {
1206
1290
  displayLabel = false;
1207
1291
  }
1208
-
1209
1292
  return displayLabel;
1210
1293
  }
1211
1294
 
@@ -1219,28 +1302,185 @@
1219
1302
  * @param [additionalErrorSchema] - The additional set of errors in an `ErrorSchema`
1220
1303
  * @returns - The `validationData` with the additional errors from `additionalErrorSchema` merged into it, if provided.
1221
1304
  */
1222
-
1223
1305
  function mergeValidationData(validator, validationData, additionalErrorSchema) {
1224
1306
  if (!additionalErrorSchema) {
1225
1307
  return validationData;
1226
1308
  }
1227
-
1228
- const {
1229
- errors: oldErrors,
1230
- errorSchema: oldErrorSchema
1231
- } = validationData;
1232
- let errors = validator.toErrorList(additionalErrorSchema);
1233
- let errorSchema = additionalErrorSchema;
1234
-
1309
+ var oldErrors = validationData.errors,
1310
+ oldErrorSchema = validationData.errorSchema;
1311
+ var errors = validator.toErrorList(additionalErrorSchema);
1312
+ var errorSchema = additionalErrorSchema;
1235
1313
  if (!isEmpty__default["default"](oldErrorSchema)) {
1236
1314
  errorSchema = mergeObjects(oldErrorSchema, additionalErrorSchema, true);
1237
- errors = [...oldErrors].concat(errors);
1315
+ errors = [].concat(oldErrors).concat(errors);
1316
+ }
1317
+ return {
1318
+ errorSchema: errorSchema,
1319
+ errors: errors
1320
+ };
1321
+ }
1322
+
1323
+ var NO_VALUE = /*#__PURE__*/Symbol("no Value");
1324
+ /** Sanitize the `data` associated with the `oldSchema` so it is considered appropriate for the `newSchema`. If the new
1325
+ * schema does not contain any properties, then `undefined` is returned to clear all the form data. Due to the nature
1326
+ * of schemas, this sanitization happens recursively for nested objects of data. Also, any properties in the old schema
1327
+ * that are non-existent in the new schema are set to `undefined`. The data sanitization process has the following flow:
1328
+ *
1329
+ * - If the new schema is an object that contains a `properties` object then:
1330
+ * - Create a `removeOldSchemaData` object, setting each key in the `oldSchema.properties` having `data` to undefined
1331
+ * - Create an empty `nestedData` object for use in the key filtering below:
1332
+ * - Iterate over each key in the `newSchema.properties` as follows:
1333
+ * - Get the `formValue` of the key from the `data`
1334
+ * - Get the `oldKeySchema` and `newKeyedSchema` for the key, defaulting to `{}` when it doesn't exist
1335
+ * - Retrieve the schema for any refs within each `oldKeySchema` and/or `newKeySchema`
1336
+ * - Get the types of the old and new keyed schemas and if the old doesn't exist or the old & new are the same then:
1337
+ * - If `removeOldSchemaData` has an entry for the key, delete it since the new schema has the same property
1338
+ * - If type of the key in the new schema is `object`:
1339
+ * - Store the value from the recursive `sanitizeDataForNewSchema` call in `nestedData[key]`
1340
+ * - Otherwise, check for default or const values:
1341
+ * - Get the old and new `default` values from the schema and check:
1342
+ * - If the new `default` value does not match the form value:
1343
+ * - If the old `default` value DOES match the form value, then:
1344
+ * - Replace `removeOldSchemaData[key]` with the new `default`
1345
+ * - Otherwise, if the new schema is `readOnly` then replace `removeOldSchemaData[key]` with undefined
1346
+ * - Get the old and new `const` values from the schema and check:
1347
+ * - If the new `const` value does not match the form value:
1348
+ * - If the old `const` value DOES match the form value, then:
1349
+ * - Replace `removeOldSchemaData[key]` with the new `const`
1350
+ * - Otherwise, replace `removeOldSchemaData[key]` with undefined
1351
+ * - Once all keys have been processed, return an object built as follows:
1352
+ * - `{ ...removeOldSchemaData, ...nestedData, ...pick(data, keysToKeep) }`
1353
+ * - If the new and old schema types are array and the `data` is an array then:
1354
+ * - If the type of the old and new schema `items` are a non-array objects:
1355
+ * - Retrieve the schema for any refs within each `oldKeySchema.items` and/or `newKeySchema.items`
1356
+ * - If the `type`s of both items are the same (or the old does not have a type):
1357
+ * - If the type is "object", then:
1358
+ * - For each element in the `data` recursively sanitize the data, stopping at `maxItems` if specified
1359
+ * - Otherwise, just return the `data` removing any values after `maxItems` if it is set
1360
+ * - If the type of the old and new schema `items` are booleans of the same value, return `data` as is
1361
+ * - Otherwise return `undefined`
1362
+ *
1363
+ * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
1364
+ * @param rootSchema - The root JSON schema of the entire form
1365
+ * @param [newSchema] - The new schema for which the data is being sanitized
1366
+ * @param [oldSchema] - The old schema from which the data originated
1367
+ * @param [data={}] - The form data associated with the schema, defaulting to an empty object when undefined
1368
+ * @returns - The new form data, with all the fields uniquely associated with the old schema set
1369
+ * to `undefined`. Will return `undefined` if the new schema is not an object containing properties.
1370
+ */
1371
+ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, data) {
1372
+ if (data === void 0) {
1373
+ data = {};
1374
+ }
1375
+ // By default, we will clear the form data
1376
+ var newFormData;
1377
+ // If the new schema is of type object and that object contains a list of properties
1378
+ if (has__default["default"](newSchema, PROPERTIES_KEY)) {
1379
+ // Create an object containing root-level keys in the old schema, setting each key to undefined to remove the data
1380
+ var removeOldSchemaData = {};
1381
+ if (has__default["default"](oldSchema, PROPERTIES_KEY)) {
1382
+ var properties = get__default["default"](oldSchema, PROPERTIES_KEY, {});
1383
+ Object.keys(properties).forEach(function (key) {
1384
+ if (has__default["default"](data, key)) {
1385
+ removeOldSchemaData[key] = undefined;
1386
+ }
1387
+ });
1388
+ }
1389
+ var keys = Object.keys(get__default["default"](newSchema, PROPERTIES_KEY, {}));
1390
+ // Create a place to store nested data that will be a side-effect of the filter
1391
+ var nestedData = {};
1392
+ keys.forEach(function (key) {
1393
+ var formValue = get__default["default"](data, key);
1394
+ var oldKeyedSchema = get__default["default"](oldSchema, [PROPERTIES_KEY, key], {});
1395
+ var newKeyedSchema = get__default["default"](newSchema, [PROPERTIES_KEY, key], {});
1396
+ // Resolve the refs if they exist
1397
+ if (has__default["default"](oldKeyedSchema, REF_KEY)) {
1398
+ oldKeyedSchema = retrieveSchema(validator, oldKeyedSchema, rootSchema, formValue);
1399
+ }
1400
+ if (has__default["default"](newKeyedSchema, REF_KEY)) {
1401
+ newKeyedSchema = retrieveSchema(validator, newKeyedSchema, rootSchema, formValue);
1402
+ }
1403
+ // Now get types and see if they are the same
1404
+ var oldSchemaTypeForKey = get__default["default"](oldKeyedSchema, "type");
1405
+ var newSchemaTypeForKey = get__default["default"](newKeyedSchema, "type");
1406
+ // Check if the old option has the same key with the same type
1407
+ if (!oldSchemaTypeForKey || oldSchemaTypeForKey === newSchemaTypeForKey) {
1408
+ if (has__default["default"](removeOldSchemaData, key)) {
1409
+ // SIDE-EFFECT: remove the undefined value for a key that has the same type between the old and new schemas
1410
+ delete removeOldSchemaData[key];
1411
+ }
1412
+ // If it is an object, we'll recurse and store the resulting sanitized data for the key
1413
+ if (newSchemaTypeForKey === "object" || newSchemaTypeForKey === "array" && Array.isArray(formValue)) {
1414
+ // SIDE-EFFECT: process the new schema type of object recursively to save iterations
1415
+ var itemData = sanitizeDataForNewSchema(validator, rootSchema, newKeyedSchema, oldKeyedSchema, formValue);
1416
+ if (itemData !== undefined || newSchemaTypeForKey === "array") {
1417
+ // only put undefined values for the array type and not the object type
1418
+ nestedData[key] = itemData;
1419
+ }
1420
+ } else {
1421
+ // Ok, the non-object types match, let's make sure that a default or a const of a different value is replaced
1422
+ // with the new default or const. This allows the case where two schemas differ that only by the default/const
1423
+ // value to be properly selected
1424
+ var newOptionDefault = get__default["default"](newKeyedSchema, "default", NO_VALUE);
1425
+ var oldOptionDefault = get__default["default"](oldKeyedSchema, "default", NO_VALUE);
1426
+ if (newOptionDefault !== NO_VALUE && newOptionDefault !== formValue) {
1427
+ if (oldOptionDefault === formValue) {
1428
+ // If the old default matches the formValue, we'll update the new value to match the new default
1429
+ removeOldSchemaData[key] = newOptionDefault;
1430
+ } else if (get__default["default"](newKeyedSchema, "readOnly") === true) {
1431
+ // If the new schema has the default set to read-only, treat it like a const and remove the value
1432
+ removeOldSchemaData[key] = undefined;
1433
+ }
1434
+ }
1435
+ var newOptionConst = get__default["default"](newKeyedSchema, "const", NO_VALUE);
1436
+ var oldOptionConst = get__default["default"](oldKeyedSchema, "const", NO_VALUE);
1437
+ if (newOptionConst !== NO_VALUE && newOptionConst !== formValue) {
1438
+ // Since this is a const, if the old value matches, replace the value with the new const otherwise clear it
1439
+ removeOldSchemaData[key] = oldOptionConst === formValue ? newOptionConst : undefined;
1440
+ }
1441
+ }
1442
+ }
1443
+ });
1444
+ newFormData = _extends({}, data, removeOldSchemaData, nestedData);
1445
+ // First apply removing the old schema data, then apply the nested data, then apply the old data keys to keep
1446
+ } else if (get__default["default"](oldSchema, "type") === "array" && get__default["default"](newSchema, "type") === "array" && Array.isArray(data)) {
1447
+ var oldSchemaItems = get__default["default"](oldSchema, "items");
1448
+ var newSchemaItems = get__default["default"](newSchema, "items");
1449
+ // If any of the array types `items` are arrays (remember arrays are objects) then we'll just drop the data
1450
+ // Eventually, we may want to deal with when either of the `items` are arrays since those tuple validations
1451
+ if (typeof oldSchemaItems === "object" && typeof newSchemaItems === "object" && !Array.isArray(oldSchemaItems) && !Array.isArray(newSchemaItems)) {
1452
+ if (has__default["default"](oldSchemaItems, REF_KEY)) {
1453
+ oldSchemaItems = retrieveSchema(validator, oldSchemaItems, rootSchema, data);
1454
+ }
1455
+ if (has__default["default"](newSchemaItems, REF_KEY)) {
1456
+ newSchemaItems = retrieveSchema(validator, newSchemaItems, rootSchema, data);
1457
+ }
1458
+ // Now get types and see if they are the same
1459
+ var oldSchemaType = get__default["default"](oldSchemaItems, "type");
1460
+ var newSchemaType = get__default["default"](newSchemaItems, "type");
1461
+ // Check if the old option has the same key with the same type
1462
+ if (!oldSchemaType || oldSchemaType === newSchemaType) {
1463
+ var maxItems = get__default["default"](newSchema, "maxItems", -1);
1464
+ if (newSchemaType === "object") {
1465
+ newFormData = data.reduce(function (newValue, aValue) {
1466
+ var itemValue = sanitizeDataForNewSchema(validator, rootSchema, newSchemaItems, oldSchemaItems, aValue);
1467
+ if (itemValue !== undefined && (maxItems < 0 || newValue.length < maxItems)) {
1468
+ newValue.push(itemValue);
1469
+ }
1470
+ return newValue;
1471
+ }, []);
1472
+ } else {
1473
+ newFormData = maxItems > 0 && data.length > maxItems ? data.slice(0, maxItems) : data;
1474
+ }
1475
+ }
1476
+ } else if (typeof oldSchemaItems === "boolean" && typeof newSchemaItems === "boolean" && oldSchemaItems === newSchemaItems) {
1477
+ // If they are both booleans and have the same value just return the data as is otherwise fall-thru to undefined
1478
+ newFormData = data;
1479
+ }
1480
+ // Also probably want to deal with `prefixItems` as tuples with the latest 2020 draft
1238
1481
  }
1239
1482
 
1240
- return {
1241
- errorSchema,
1242
- errors
1243
- };
1483
+ return newFormData;
1244
1484
  }
1245
1485
 
1246
1486
  /** Generates an `IdSchema` object for the `schema`, recursively
@@ -1254,41 +1494,34 @@
1254
1494
  * @param [idSeparator='_'] - The separator to use for the path segments in the id
1255
1495
  * @returns - The `IdSchema` object for the `schema`
1256
1496
  */
1257
-
1258
1497
  function toIdSchema(validator, schema, id, rootSchema, formData, idPrefix, idSeparator) {
1259
1498
  if (idPrefix === void 0) {
1260
1499
  idPrefix = "root";
1261
1500
  }
1262
-
1263
1501
  if (idSeparator === void 0) {
1264
1502
  idSeparator = "_";
1265
1503
  }
1266
-
1267
1504
  if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
1268
- const _schema = retrieveSchema(validator, schema, rootSchema, formData);
1269
-
1505
+ var _schema = retrieveSchema(validator, schema, rootSchema, formData);
1270
1506
  return toIdSchema(validator, _schema, id, rootSchema, formData, idPrefix, idSeparator);
1271
1507
  }
1272
-
1273
1508
  if (ITEMS_KEY in schema && !get__default["default"](schema, [ITEMS_KEY, REF_KEY])) {
1274
1509
  return toIdSchema(validator, get__default["default"](schema, ITEMS_KEY), id, rootSchema, formData, idPrefix, idSeparator);
1275
1510
  }
1276
-
1277
- const $id = id || idPrefix;
1278
- const idSchema = {
1279
- $id
1511
+ var $id = id || idPrefix;
1512
+ var idSchema = {
1513
+ $id: $id
1280
1514
  };
1281
-
1282
1515
  if (schema.type === "object" && PROPERTIES_KEY in schema) {
1283
- for (const name in schema.properties) {
1284
- const field = get__default["default"](schema, [PROPERTIES_KEY, name]);
1285
- const fieldId = idSchema[ID_KEY] + idSeparator + name;
1286
- idSchema[name] = toIdSchema(validator, isObject(field) ? field : {}, fieldId, rootSchema, // It's possible that formData is not an object -- this can happen if an
1516
+ for (var name in schema.properties) {
1517
+ var field = get__default["default"](schema, [PROPERTIES_KEY, name]);
1518
+ var fieldId = idSchema[ID_KEY] + idSeparator + name;
1519
+ idSchema[name] = toIdSchema(validator, isObject(field) ? field : {}, fieldId, rootSchema,
1520
+ // It's possible that formData is not an object -- this can happen if an
1287
1521
  // array item has just been added, but not populated with data yet
1288
1522
  get__default["default"](formData, [name]), idPrefix, idSeparator);
1289
1523
  }
1290
1524
  }
1291
-
1292
1525
  return idSchema;
1293
1526
  }
1294
1527
 
@@ -1301,39 +1534,42 @@
1301
1534
  * @param [formData] - The current formData, if any, to assist retrieving a schema
1302
1535
  * @returns - The `PathSchema` object for the `schema`
1303
1536
  */
1304
-
1305
1537
  function toPathSchema(validator, schema, name, rootSchema, formData) {
1538
+ var _pathSchema;
1306
1539
  if (name === void 0) {
1307
1540
  name = "";
1308
1541
  }
1309
-
1310
1542
  if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
1311
- const _schema = retrieveSchema(validator, schema, rootSchema, formData);
1312
-
1543
+ var _schema = retrieveSchema(validator, schema, rootSchema, formData);
1313
1544
  return toPathSchema(validator, _schema, name, rootSchema, formData);
1314
1545
  }
1315
-
1316
- const pathSchema = {
1317
- [NAME_KEY]: name.replace(/^\./, "")
1318
- };
1319
-
1320
- if (ADDITIONAL_PROPERTIES_KEY in schema && schema[ADDITIONAL_PROPERTIES_KEY] === true) {
1546
+ var pathSchema = (_pathSchema = {}, _pathSchema[NAME_KEY] = name.replace(/^\./, ""), _pathSchema);
1547
+ if (ONE_OF_KEY in schema) {
1548
+ var index = getClosestMatchingOption(validator, rootSchema, formData, schema.oneOf, 0);
1549
+ var _schema2 = schema.oneOf[index];
1550
+ return toPathSchema(validator, _schema2, name, rootSchema, formData);
1551
+ }
1552
+ if (ANY_OF_KEY in schema) {
1553
+ var _index = getClosestMatchingOption(validator, rootSchema, formData, schema.anyOf, 0);
1554
+ var _schema3 = schema.anyOf[_index];
1555
+ return toPathSchema(validator, _schema3, name, rootSchema, formData);
1556
+ }
1557
+ if (ADDITIONAL_PROPERTIES_KEY in schema && schema[ADDITIONAL_PROPERTIES_KEY] !== false) {
1321
1558
  set__default["default"](pathSchema, RJSF_ADDITONAL_PROPERTIES_FLAG, true);
1322
1559
  }
1323
-
1324
1560
  if (ITEMS_KEY in schema && Array.isArray(formData)) {
1325
- formData.forEach((element, i) => {
1561
+ formData.forEach(function (element, i) {
1326
1562
  pathSchema[i] = toPathSchema(validator, schema.items, name + "." + i, rootSchema, element);
1327
1563
  });
1328
1564
  } else if (PROPERTIES_KEY in schema) {
1329
- for (const property in schema.properties) {
1330
- const field = get__default["default"](schema, [PROPERTIES_KEY, property]);
1331
- pathSchema[property] = toPathSchema(validator, field, name + "." + property, rootSchema, // It's possible that formData is not an object -- this can happen if an
1565
+ for (var property in schema.properties) {
1566
+ var field = get__default["default"](schema, [PROPERTIES_KEY, property]);
1567
+ pathSchema[property] = toPathSchema(validator, field, name + "." + property, rootSchema,
1568
+ // It's possible that formData is not an object -- this can happen if an
1332
1569
  // array item has just been added, but not populated with data yet
1333
1570
  get__default["default"](formData, [property]));
1334
1571
  }
1335
1572
  }
1336
-
1337
1573
  return pathSchema;
1338
1574
  }
1339
1575
 
@@ -1342,14 +1578,13 @@
1342
1578
  * and `rootSchema` generally does not change across a `Form`, this allows for providing a simplified set of APIs to the
1343
1579
  * `@rjsf/core` components and the various themes as well. This class implements the `SchemaUtilsType` interface.
1344
1580
  */
1345
-
1346
- class SchemaUtils {
1581
+ var SchemaUtils = /*#__PURE__*/function () {
1347
1582
  /** Constructs the `SchemaUtils` instance with the given `validator` and `rootSchema` stored as instance variables
1348
1583
  *
1349
1584
  * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
1350
1585
  * @param rootSchema - The root schema that will be forwarded to all the APIs
1351
1586
  */
1352
- constructor(validator, rootSchema) {
1587
+ function SchemaUtils(validator, rootSchema) {
1353
1588
  this.rootSchema = void 0;
1354
1589
  this.validator = void 0;
1355
1590
  this.rootSchema = rootSchema;
@@ -1359,9 +1594,8 @@
1359
1594
  *
1360
1595
  * @returns - The `ValidatorType`
1361
1596
  */
1362
-
1363
-
1364
- getValidator() {
1597
+ var _proto = SchemaUtils.prototype;
1598
+ _proto.getValidator = function getValidator() {
1365
1599
  return this.validator;
1366
1600
  }
1367
1601
  /** Determines whether either the `validator` and `rootSchema` differ from the ones associated with this instance of
@@ -1371,14 +1605,11 @@
1371
1605
  * @param validator - An implementation of the `ValidatorType` interface that will be compared against the current one
1372
1606
  * @param rootSchema - The root schema that will be compared against the current one
1373
1607
  * @returns - True if the `SchemaUtilsType` differs from the given `validator` or `rootSchema`
1374
- */
1375
-
1376
-
1377
- doesSchemaUtilsDiffer(validator, rootSchema) {
1608
+ */;
1609
+ _proto.doesSchemaUtilsDiffer = function doesSchemaUtilsDiffer(validator, rootSchema) {
1378
1610
  if (!validator || !rootSchema) {
1379
1611
  return false;
1380
1612
  }
1381
-
1382
1613
  return this.validator !== validator || !deepEquals(this.rootSchema, rootSchema);
1383
1614
  }
1384
1615
  /** Returns the superset of `formData` that includes the given set updated to include any missing fields that have
@@ -1386,16 +1617,15 @@
1386
1617
  *
1387
1618
  * @param schema - The schema for which the default state is desired
1388
1619
  * @param [formData] - The current formData, if any, onto which to provide any missing defaults
1389
- * @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults
1620
+ * @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults.
1621
+ * If "excludeObjectChildren", pass `includeUndefinedValues` as false when computing defaults for any nested
1622
+ * object properties.
1390
1623
  * @returns - The resulting `formData` with all the defaults provided
1391
- */
1392
-
1393
-
1394
- getDefaultFormState(schema, formData, includeUndefinedValues) {
1624
+ */;
1625
+ _proto.getDefaultFormState = function getDefaultFormState$1(schema, formData, includeUndefinedValues) {
1395
1626
  if (includeUndefinedValues === void 0) {
1396
1627
  includeUndefinedValues = false;
1397
1628
  }
1398
-
1399
1629
  return getDefaultFormState(this.validator, schema, formData, this.rootSchema, includeUndefinedValues);
1400
1630
  }
1401
1631
  /** Determines whether the combination of `schema` and `uiSchema` properties indicates that the label for the `schema`
@@ -1404,21 +1634,43 @@
1404
1634
  * @param schema - The schema for which the display label flag is desired
1405
1635
  * @param [uiSchema] - The UI schema from which to derive potentially displayable information
1406
1636
  * @returns - True if the label should be displayed or false if it should not
1407
- */
1408
-
1409
-
1410
- getDisplayLabel(schema, uiSchema) {
1637
+ */;
1638
+ _proto.getDisplayLabel = function getDisplayLabel$1(schema, uiSchema) {
1411
1639
  return getDisplayLabel(this.validator, schema, uiSchema, this.rootSchema);
1412
1640
  }
1641
+ /** Determines which of the given `options` provided most closely matches the `formData`.
1642
+ * Returns the index of the option that is valid and is the closest match, or 0 if there is no match.
1643
+ *
1644
+ * The closest match is determined using the number of matching properties, and more heavily favors options with
1645
+ * matching readOnly, default, or const values.
1646
+ *
1647
+ * @param formData - The form data associated with the schema
1648
+ * @param options - The list of options that can be selected from
1649
+ * @param [selectedOption] - The index of the currently selected option, defaulted to -1 if not specified
1650
+ * @returns - The index of the option that is the closest match to the `formData` or the `selectedOption` if no match
1651
+ */;
1652
+ _proto.getClosestMatchingOption = function getClosestMatchingOption$1(formData, options, selectedOption) {
1653
+ return getClosestMatchingOption(this.validator, this.rootSchema, formData, options, selectedOption);
1654
+ }
1655
+ /** Given the `formData` and list of `options`, attempts to find the index of the first option that matches the data.
1656
+ * Always returns the first option if there is nothing that matches.
1657
+ *
1658
+ * @param formData - The current formData, if any, used to figure out a match
1659
+ * @param options - The list of options to find a matching options from
1660
+ * @returns - The firstindex of the matched option or 0 if none is available
1661
+ */;
1662
+ _proto.getFirstMatchingOption = function getFirstMatchingOption$1(formData, options) {
1663
+ return getFirstMatchingOption(this.validator, formData, options, this.rootSchema);
1664
+ }
1413
1665
  /** Given the `formData` and list of `options`, attempts to find the index of the option that best matches the data.
1666
+ * Deprecated, use `getFirstMatchingOption()` instead.
1414
1667
  *
1415
1668
  * @param formData - The current formData, if any, onto which to provide any missing defaults
1416
1669
  * @param options - The list of options to find a matching options from
1417
1670
  * @returns - The index of the matched option or 0 if none is available
1418
- */
1419
-
1420
-
1421
- getMatchingOption(formData, options) {
1671
+ * @deprecated
1672
+ */;
1673
+ _proto.getMatchingOption = function getMatchingOption$1(formData, options) {
1422
1674
  return getMatchingOption(this.validator, formData, options, this.rootSchema);
1423
1675
  }
1424
1676
  /** Checks to see if the `schema` and `uiSchema` combination represents an array of files
@@ -1426,30 +1678,24 @@
1426
1678
  * @param schema - The schema for which check for array of files flag is desired
1427
1679
  * @param [uiSchema] - The UI schema from which to check the widget
1428
1680
  * @returns - True if schema/uiSchema contains an array of files, otherwise false
1429
- */
1430
-
1431
-
1432
- isFilesArray(schema, uiSchema) {
1681
+ */;
1682
+ _proto.isFilesArray = function isFilesArray$1(schema, uiSchema) {
1433
1683
  return isFilesArray(this.validator, schema, uiSchema, this.rootSchema);
1434
1684
  }
1435
1685
  /** Checks to see if the `schema` combination represents a multi-select
1436
1686
  *
1437
1687
  * @param schema - The schema for which check for a multi-select flag is desired
1438
1688
  * @returns - True if schema contains a multi-select, otherwise false
1439
- */
1440
-
1441
-
1442
- isMultiSelect(schema) {
1689
+ */;
1690
+ _proto.isMultiSelect = function isMultiSelect$1(schema) {
1443
1691
  return isMultiSelect(this.validator, schema, this.rootSchema);
1444
1692
  }
1445
1693
  /** Checks to see if the `schema` combination represents a select
1446
1694
  *
1447
1695
  * @param schema - The schema for which check for a select flag is desired
1448
1696
  * @returns - True if schema contains a select, otherwise false
1449
- */
1450
-
1451
-
1452
- isSelect(schema) {
1697
+ */;
1698
+ _proto.isSelect = function isSelect$1(schema) {
1453
1699
  return isSelect(this.validator, schema, this.rootSchema);
1454
1700
  }
1455
1701
  /** Merges the errors in `additionalErrorSchema` into the existing `validationData` by combining the hierarchies in
@@ -1460,10 +1706,8 @@
1460
1706
  * @param validationData - The current `ValidationData` into which to merge the additional errors
1461
1707
  * @param [additionalErrorSchema] - The additional set of errors
1462
1708
  * @returns - The `validationData` with the additional errors from `additionalErrorSchema` merged into it, if provided.
1463
- */
1464
-
1465
-
1466
- mergeValidationData(validationData, additionalErrorSchema) {
1709
+ */;
1710
+ _proto.mergeValidationData = function mergeValidationData$1(validationData, additionalErrorSchema) {
1467
1711
  return mergeValidationData(this.validator, validationData, additionalErrorSchema);
1468
1712
  }
1469
1713
  /** Retrieves an expanded schema that has had all of its conditions, additional properties, references and
@@ -1473,12 +1717,24 @@
1473
1717
  * @param schema - The schema for which retrieving a schema is desired
1474
1718
  * @param [rawFormData] - The current formData, if any, to assist retrieving a schema
1475
1719
  * @returns - The schema having its conditions, additional properties, references and dependencies resolved
1476
- */
1477
-
1478
-
1479
- retrieveSchema(schema, rawFormData) {
1720
+ */;
1721
+ _proto.retrieveSchema = function retrieveSchema$1(schema, rawFormData) {
1480
1722
  return retrieveSchema(this.validator, schema, this.rootSchema, rawFormData);
1481
1723
  }
1724
+ /** Sanitize the `data` associated with the `oldSchema` so it is considered appropriate for the `newSchema`. If the
1725
+ * new schema does not contain any properties, then `undefined` is returned to clear all the form data. Due to the
1726
+ * nature of schemas, this sanitization happens recursively for nested objects of data. Also, any properties in the
1727
+ * old schemas that are non-existent in the new schema are set to `undefined`.
1728
+ *
1729
+ * @param [newSchema] - The new schema for which the data is being sanitized
1730
+ * @param [oldSchema] - The old schema from which the data originated
1731
+ * @param [data={}] - The form data associated with the schema, defaulting to an empty object when undefined
1732
+ * @returns - The new form data, with all the fields uniquely associated with the old schema set
1733
+ * to `undefined`. Will return `undefined` if the new schema is not an object containing properties.
1734
+ */;
1735
+ _proto.sanitizeDataForNewSchema = function sanitizeDataForNewSchema$1(newSchema, oldSchema, data) {
1736
+ return sanitizeDataForNewSchema(this.validator, this.rootSchema, newSchema, oldSchema, data);
1737
+ }
1482
1738
  /** Generates an `IdSchema` object for the `schema`, recursively
1483
1739
  *
1484
1740
  * @param schema - The schema for which the display label flag is desired
@@ -1487,18 +1743,14 @@
1487
1743
  * @param [idPrefix='root'] - The prefix to use for the id
1488
1744
  * @param [idSeparator='_'] - The separator to use for the path segments in the id
1489
1745
  * @returns - The `IdSchema` object for the `schema`
1490
- */
1491
-
1492
-
1493
- toIdSchema(schema, id, formData, idPrefix, idSeparator) {
1746
+ */;
1747
+ _proto.toIdSchema = function toIdSchema$1(schema, id, formData, idPrefix, idSeparator) {
1494
1748
  if (idPrefix === void 0) {
1495
1749
  idPrefix = "root";
1496
1750
  }
1497
-
1498
1751
  if (idSeparator === void 0) {
1499
1752
  idSeparator = "_";
1500
1753
  }
1501
-
1502
1754
  return toIdSchema(this.validator, schema, id, this.rootSchema, formData, idPrefix, idSeparator);
1503
1755
  }
1504
1756
  /** Generates an `PathSchema` object for the `schema`, recursively
@@ -1507,14 +1759,12 @@
1507
1759
  * @param [name] - The base name for the schema
1508
1760
  * @param [formData] - The current formData, if any, onto which to provide any missing defaults
1509
1761
  * @returns - The `PathSchema` object for the `schema`
1510
- */
1511
-
1512
-
1513
- toPathSchema(schema, name, formData) {
1762
+ */;
1763
+ _proto.toPathSchema = function toPathSchema$1(schema, name, formData) {
1514
1764
  return toPathSchema(this.validator, schema, name, this.rootSchema, formData);
1515
- }
1516
-
1517
- }
1765
+ };
1766
+ return SchemaUtils;
1767
+ }();
1518
1768
  /** Creates a `SchemaUtilsType` interface that is based around the given `validator` and `rootSchema` parameters. The
1519
1769
  * resulting interface implementation will forward the `validator` and `rootSchema` to all the wrapped APIs.
1520
1770
  *
@@ -1522,8 +1772,6 @@
1522
1772
  * @param rootSchema - The root schema that will be forwarded to all the APIs
1523
1773
  * @returns - An implementation of a `SchemaUtilsType` interface
1524
1774
  */
1525
-
1526
-
1527
1775
  function createSchemaUtils(validator, rootSchema) {
1528
1776
  return new SchemaUtils(validator, rootSchema);
1529
1777
  }
@@ -1536,44 +1784,182 @@
1536
1784
  */
1537
1785
  function dataURItoBlob(dataURI) {
1538
1786
  // Split metadata from data
1539
- const splitted = dataURI.split(","); // Split params
1540
-
1541
- const params = splitted[0].split(";"); // Get mime-type from params
1542
-
1543
- const type = params[0].replace("data:", ""); // Filter the name property from params
1544
-
1545
- const properties = params.filter(param => {
1787
+ var splitted = dataURI.split(",");
1788
+ // Split params
1789
+ var params = splitted[0].split(";");
1790
+ // Get mime-type from params
1791
+ var type = params[0].replace("data:", "");
1792
+ // Filter the name property from params
1793
+ var properties = params.filter(function (param) {
1546
1794
  return param.split("=")[0] === "name";
1547
- }); // Look for the name and use unknown if no name property.
1548
-
1549
- let name;
1550
-
1795
+ });
1796
+ // Look for the name and use unknown if no name property.
1797
+ var name;
1551
1798
  if (properties.length !== 1) {
1552
1799
  name = "unknown";
1553
1800
  } else {
1554
1801
  // Because we filtered out the other property,
1555
1802
  // we only have the name case here.
1556
1803
  name = properties[0].split("=")[1];
1557
- } // Built the Uint8Array Blob parameter from the base64 string.
1558
-
1559
-
1560
- const binary = atob(splitted[1]);
1561
- const array = [];
1562
-
1563
- for (let i = 0; i < binary.length; i++) {
1804
+ }
1805
+ // Built the Uint8Array Blob parameter from the base64 string.
1806
+ var binary = atob(splitted[1]);
1807
+ var array = [];
1808
+ for (var i = 0; i < binary.length; i++) {
1564
1809
  array.push(binary.charCodeAt(i));
1565
- } // Create the blob object
1566
-
1567
-
1568
- const blob = new window.Blob([new Uint8Array(array)], {
1569
- type
1810
+ }
1811
+ // Create the blob object
1812
+ var blob = new window.Blob([new Uint8Array(array)], {
1813
+ type: type
1570
1814
  });
1571
1815
  return {
1572
- blob,
1573
- name
1816
+ blob: blob,
1817
+ name: name
1574
1818
  };
1575
1819
  }
1576
1820
 
1821
+ /** Removes the `value` from the currently `selected` list of values
1822
+ *
1823
+ * @param value - The value to be removed from the selected list
1824
+ * @param selected - The current list of selected values
1825
+ * @returns - The updated `selected` list with the `value` removed from it
1826
+ */
1827
+ function enumOptionsDeselectValue(value, selected) {
1828
+ return selected.filter(function (v) {
1829
+ return v !== value;
1830
+ });
1831
+ }
1832
+
1833
+ /** Add the `value` to the list of `selected` values in the proper order as defined by `allEnumOptions`
1834
+ *
1835
+ * @param value - The value that should be selected
1836
+ * @param selected - The current list of selected values
1837
+ * @param allEnumOptions - The list of all the known enumOptions
1838
+ * @returns - The updated list of selected enum values with `value` added to it in the proper location
1839
+ */
1840
+ function enumOptionsSelectValue(value, selected, allEnumOptions) {
1841
+ if (allEnumOptions === void 0) {
1842
+ allEnumOptions = [];
1843
+ }
1844
+ var all = allEnumOptions.map(function (_ref) {
1845
+ var value = _ref.value;
1846
+ return value;
1847
+ });
1848
+ var at = all.indexOf(value);
1849
+ // If location of the value is not in the list of all enum values, just put it at the end
1850
+ var updated = at === -1 ? selected.concat(value) : selected.slice(0, at).concat(value, selected.slice(at));
1851
+ // As inserting values at predefined index positions doesn't work with empty
1852
+ // arrays, we need to reorder the updated selection to match the initial order
1853
+ return updated.sort(function (a, b) {
1854
+ return Number(all.indexOf(a) > all.indexOf(b));
1855
+ });
1856
+ }
1857
+
1858
+ /** The `ErrorSchemaBuilder<T>` is used to build an `ErrorSchema<T>` since the definition of the `ErrorSchema` type is
1859
+ * designed for reading information rather than writing it. Use this class to add, replace or clear errors in an error
1860
+ * schema by using either dotted path or an array of path names. Once you are done building the `ErrorSchema`, you can
1861
+ * get the result and/or reset all the errors back to an initial set and start again.
1862
+ */
1863
+ var ErrorSchemaBuilder = /*#__PURE__*/function () {
1864
+ /** The error schema being built
1865
+ *
1866
+ * @private
1867
+ */
1868
+
1869
+ /** Construct an `ErrorSchemaBuilder` with an optional initial set of errors in an `ErrorSchema`.
1870
+ *
1871
+ * @param [initialSchema] - The optional set of initial errors, that will be cloned into the class
1872
+ */
1873
+ function ErrorSchemaBuilder(initialSchema) {
1874
+ this.errorSchema = {};
1875
+ this.resetAllErrors(initialSchema);
1876
+ }
1877
+ /** Returns the `ErrorSchema` that has been updated by the methods of the `ErrorSchemaBuilder`
1878
+ */
1879
+ var _proto = ErrorSchemaBuilder.prototype;
1880
+ /** Will get an existing `ErrorSchema` at the specified `pathOfError` or create and return one.
1881
+ *
1882
+ * @param [pathOfError] - The optional path into the `ErrorSchema` at which to add the error(s)
1883
+ * @returns - The error block for the given `pathOfError` or the root if not provided
1884
+ * @private
1885
+ */
1886
+ _proto.getOrCreateErrorBlock = function getOrCreateErrorBlock(pathOfError) {
1887
+ var hasPath = Array.isArray(pathOfError) && pathOfError.length > 0 || typeof pathOfError === "string";
1888
+ var errorBlock = hasPath ? get__default["default"](this.errorSchema, pathOfError) : this.errorSchema;
1889
+ if (!errorBlock && pathOfError) {
1890
+ errorBlock = {};
1891
+ set__default["default"](this.errorSchema, pathOfError, errorBlock);
1892
+ }
1893
+ return errorBlock;
1894
+ }
1895
+ /** Resets all errors in the `ErrorSchemaBuilder` back to the `initialSchema` if provided, otherwise an empty set.
1896
+ *
1897
+ * @param [initialSchema] - The optional set of initial errors, that will be cloned into the class
1898
+ * @returns - The `ErrorSchemaBuilder` object for chaining purposes
1899
+ */;
1900
+ _proto.resetAllErrors = function resetAllErrors(initialSchema) {
1901
+ this.errorSchema = initialSchema ? cloneDeep__default["default"](initialSchema) : {};
1902
+ return this;
1903
+ }
1904
+ /** Adds the `errorOrList` to the list of errors in the `ErrorSchema` at either the root level or the location within
1905
+ * the schema described by the `pathOfError`. For more information about how to specify the path see the
1906
+ * [eslint lodash plugin docs](https://github.com/wix/eslint-plugin-lodash/blob/master/docs/rules/path-style.md).
1907
+ *
1908
+ * @param errorOrList - The error or list of errors to add into the `ErrorSchema`
1909
+ * @param [pathOfError] - The optional path into the `ErrorSchema` at which to add the error(s)
1910
+ * @returns - The `ErrorSchemaBuilder` object for chaining purposes
1911
+ */;
1912
+ _proto.addErrors = function addErrors(errorOrList, pathOfError) {
1913
+ var errorBlock = this.getOrCreateErrorBlock(pathOfError);
1914
+ var errorsList = get__default["default"](errorBlock, ERRORS_KEY);
1915
+ if (!Array.isArray(errorsList)) {
1916
+ errorsList = [];
1917
+ errorBlock[ERRORS_KEY] = errorsList;
1918
+ }
1919
+ if (Array.isArray(errorOrList)) {
1920
+ var _errorsList;
1921
+ (_errorsList = errorsList).push.apply(_errorsList, errorOrList);
1922
+ } else {
1923
+ errorsList.push(errorOrList);
1924
+ }
1925
+ return this;
1926
+ }
1927
+ /** Sets/replaces the `errorOrList` as the error(s) in the `ErrorSchema` at either the root level or the location
1928
+ * within the schema described by the `pathOfError`. For more information about how to specify the path see the
1929
+ * [eslint lodash plugin docs](https://github.com/wix/eslint-plugin-lodash/blob/master/docs/rules/path-style.md).
1930
+ *
1931
+ * @param errorOrList - The error or list of errors to set into the `ErrorSchema`
1932
+ * @param [pathOfError] - The optional path into the `ErrorSchema` at which to set the error(s)
1933
+ * @returns - The `ErrorSchemaBuilder` object for chaining purposes
1934
+ */;
1935
+ _proto.setErrors = function setErrors(errorOrList, pathOfError) {
1936
+ var errorBlock = this.getOrCreateErrorBlock(pathOfError);
1937
+ // Effectively clone the array being given to prevent accidental outside manipulation of the given list
1938
+ var listToAdd = Array.isArray(errorOrList) ? [].concat(errorOrList) : [errorOrList];
1939
+ set__default["default"](errorBlock, ERRORS_KEY, listToAdd);
1940
+ return this;
1941
+ }
1942
+ /** Clears the error(s) in the `ErrorSchema` at either the root level or the location within the schema described by
1943
+ * the `pathOfError`. For more information about how to specify the path see the
1944
+ * [eslint lodash plugin docs](https://github.com/wix/eslint-plugin-lodash/blob/master/docs/rules/path-style.md).
1945
+ *
1946
+ * @param [pathOfError] - The optional path into the `ErrorSchema` at which to clear the error(s)
1947
+ * @returns - The `ErrorSchemaBuilder` object for chaining purposes
1948
+ */;
1949
+ _proto.clearErrors = function clearErrors(pathOfError) {
1950
+ var errorBlock = this.getOrCreateErrorBlock(pathOfError);
1951
+ set__default["default"](errorBlock, ERRORS_KEY, []);
1952
+ return this;
1953
+ };
1954
+ _createClass(ErrorSchemaBuilder, [{
1955
+ key: "ErrorSchema",
1956
+ get: function get() {
1957
+ return this.errorSchema;
1958
+ }
1959
+ }]);
1960
+ return ErrorSchemaBuilder;
1961
+ }();
1962
+
1577
1963
  /** Extracts the range spec information `{ step?: number, min?: number, max?: number }` that can be spread onto an HTML
1578
1964
  * input from the range analog in the schema `{ multipleOf?: number, minimum?: number, maximum?: number }`.
1579
1965
  *
@@ -1581,20 +1967,16 @@
1581
1967
  * @returns - A range specification from the schema
1582
1968
  */
1583
1969
  function rangeSpec(schema) {
1584
- const spec = {};
1585
-
1970
+ var spec = {};
1586
1971
  if (schema.multipleOf) {
1587
1972
  spec.step = schema.multipleOf;
1588
1973
  }
1589
-
1590
1974
  if (schema.minimum || schema.minimum === 0) {
1591
1975
  spec.min = schema.minimum;
1592
1976
  }
1593
-
1594
1977
  if (schema.maximum || schema.maximum === 0) {
1595
1978
  spec.max = schema.maximum;
1596
1979
  }
1597
-
1598
1980
  return spec;
1599
1981
  }
1600
1982
 
@@ -1606,54 +1988,47 @@
1606
1988
  * @param [autoDefaultStepAny=true] - Determines whether to auto-default step=any when the type is number and no step
1607
1989
  * @returns - The extracted `InputPropsType` object
1608
1990
  */
1609
-
1610
1991
  function getInputProps(schema, defaultType, options, autoDefaultStepAny) {
1611
1992
  if (options === void 0) {
1612
1993
  options = {};
1613
1994
  }
1614
-
1615
1995
  if (autoDefaultStepAny === void 0) {
1616
1996
  autoDefaultStepAny = true;
1617
1997
  }
1618
-
1619
- const inputProps = {
1620
- type: defaultType || "text",
1621
- ...rangeSpec(schema)
1622
- }; // If options.inputType is set use that as the input type
1623
-
1998
+ var inputProps = _extends({
1999
+ type: defaultType || "text"
2000
+ }, rangeSpec(schema));
2001
+ // If options.inputType is set use that as the input type
1624
2002
  if (options.inputType) {
1625
2003
  inputProps.type = options.inputType;
1626
2004
  } else if (!defaultType) {
1627
2005
  // If the schema is of type number or integer, set the input type to number
1628
2006
  if (schema.type === "number") {
1629
- inputProps.type = "number"; // Only add step if one isn't already defined and we are auto-defaulting the "any" step
1630
-
2007
+ inputProps.type = "number";
2008
+ // Only add step if one isn't already defined and we are auto-defaulting the "any" step
1631
2009
  if (autoDefaultStepAny && inputProps.step === undefined) {
1632
2010
  // Setting step to 'any' fixes a bug in Safari where decimals are not
1633
2011
  // allowed in number inputs
1634
2012
  inputProps.step = "any";
1635
2013
  }
1636
2014
  } else if (schema.type === "integer") {
1637
- inputProps.type = "number"; // Only add step if one isn't already defined
1638
-
2015
+ inputProps.type = "number";
2016
+ // Only add step if one isn't already defined
1639
2017
  if (inputProps.step === undefined) {
1640
2018
  // Since this is integer, you always want to step up or down in multiples of 1
1641
2019
  inputProps.step = 1;
1642
2020
  }
1643
2021
  }
1644
2022
  }
1645
-
1646
2023
  if (options.autocomplete) {
1647
2024
  inputProps.autoComplete = options.autocomplete;
1648
2025
  }
1649
-
1650
2026
  return inputProps;
1651
2027
  }
1652
2028
 
1653
2029
  /** The default submit button options, exported for testing purposes
1654
2030
  */
1655
-
1656
- const DEFAULT_OPTIONS = {
2031
+ var DEFAULT_OPTIONS = {
1657
2032
  props: {
1658
2033
  disabled: false
1659
2034
  },
@@ -1665,21 +2040,15 @@
1665
2040
  * @param [uiSchema={}] - the UI Schema from which to extract submit button props
1666
2041
  * @returns - The merging of the `DEFAULT_OPTIONS` with any custom ones
1667
2042
  */
1668
-
1669
2043
  function getSubmitButtonOptions(uiSchema) {
1670
2044
  if (uiSchema === void 0) {
1671
2045
  uiSchema = {};
1672
2046
  }
1673
-
1674
- const uiOptions = getUiOptions(uiSchema);
1675
-
2047
+ var uiOptions = getUiOptions(uiSchema);
1676
2048
  if (uiOptions && uiOptions[SUBMIT_BTN_OPTIONS_KEY]) {
1677
- const options = uiOptions[SUBMIT_BTN_OPTIONS_KEY];
1678
- return { ...DEFAULT_OPTIONS,
1679
- ...options
1680
- };
2049
+ var options = uiOptions[SUBMIT_BTN_OPTIONS_KEY];
2050
+ return _extends({}, DEFAULT_OPTIONS, options);
1681
2051
  }
1682
-
1683
2052
  return DEFAULT_OPTIONS;
1684
2053
  }
1685
2054
 
@@ -1695,23 +2064,22 @@
1695
2064
  if (uiOptions === void 0) {
1696
2065
  uiOptions = {};
1697
2066
  }
1698
-
1699
- const {
1700
- templates
1701
- } = registry;
1702
-
2067
+ var templates = registry.templates;
1703
2068
  if (name === "ButtonTemplates") {
1704
2069
  return templates[name];
1705
2070
  }
1706
-
1707
- return uiOptions[name] || templates[name];
2071
+ return (
2072
+ // Evaluating uiOptions[name] results in TS2590: Expression produces a union type that is too complex to represent
2073
+ // To avoid that, we cast uiOptions to `any` before accessing the name field
2074
+ uiOptions[name] || templates[name]
2075
+ );
1708
2076
  }
1709
2077
 
2078
+ var _excluded = ["options"];
1710
2079
  /** The map of schema types to widget type to widget name
1711
2080
  */
1712
-
1713
- const widgetMap = {
1714
- boolean: {
2081
+ var widgetMap = {
2082
+ "boolean": {
1715
2083
  checkbox: "CheckboxWidget",
1716
2084
  radio: "RadioWidget",
1717
2085
  select: "SelectWidget",
@@ -1768,29 +2136,20 @@
1768
2136
  * @param AWidget - A widget that will be wrapped or one that is already wrapped
1769
2137
  * @returns - The wrapper widget
1770
2138
  */
1771
-
1772
2139
  function mergeWidgetOptions(AWidget) {
1773
- let MergedWidget = get__default["default"](AWidget, "MergedWidget"); // cache return value as property of widget for proper react reconciliation
1774
-
2140
+ var MergedWidget = get__default["default"](AWidget, "MergedWidget");
2141
+ // cache return value as property of widget for proper react reconciliation
1775
2142
  if (!MergedWidget) {
1776
- const defaultOptions = AWidget.defaultProps && AWidget.defaultProps.options || {};
1777
-
1778
- MergedWidget = _ref => {
1779
- let {
1780
- options,
1781
- ...props
1782
- } = _ref;
1783
- return /*#__PURE__*/React__default["default"].createElement(AWidget, {
1784
- options: { ...defaultOptions,
1785
- ...options
1786
- },
1787
- ...props
1788
- });
2143
+ var defaultOptions = AWidget.defaultProps && AWidget.defaultProps.options || {};
2144
+ MergedWidget = function MergedWidget(_ref) {
2145
+ var options = _ref.options,
2146
+ props = _objectWithoutPropertiesLoose(_ref, _excluded);
2147
+ return /*#__PURE__*/React__default["default"].createElement(AWidget, _extends({
2148
+ options: _extends({}, defaultOptions, options)
2149
+ }, props));
1789
2150
  };
1790
-
1791
2151
  set__default["default"](AWidget, "MergedWidget", MergedWidget);
1792
2152
  }
1793
-
1794
2153
  return MergedWidget;
1795
2154
  }
1796
2155
  /** Given a schema representing a field to render and either the name or actual `Widget` implementation, returns the
@@ -1804,39 +2163,30 @@
1804
2163
  * @returns - The `Widget` component to use
1805
2164
  * @throws - An error if there is no `Widget` component that can be returned
1806
2165
  */
1807
-
1808
-
1809
2166
  function getWidget(schema, widget, registeredWidgets) {
1810
2167
  if (registeredWidgets === void 0) {
1811
2168
  registeredWidgets = {};
1812
2169
  }
1813
-
1814
- const type = getSchemaType(schema);
1815
-
2170
+ var type = getSchemaType(schema);
1816
2171
  if (typeof widget === "function" || widget && ReactIs__default["default"].isForwardRef( /*#__PURE__*/React__default["default"].createElement(widget)) || ReactIs__default["default"].isMemo(widget)) {
1817
2172
  return mergeWidgetOptions(widget);
1818
2173
  }
1819
-
1820
2174
  if (typeof widget !== "string") {
1821
2175
  throw new Error("Unsupported widget definition: " + typeof widget);
1822
2176
  }
1823
-
1824
2177
  if (widget in registeredWidgets) {
1825
- const registeredWidget = registeredWidgets[widget];
2178
+ var registeredWidget = registeredWidgets[widget];
1826
2179
  return getWidget(schema, registeredWidget, registeredWidgets);
1827
2180
  }
1828
-
1829
2181
  if (typeof type === "string") {
1830
2182
  if (!(type in widgetMap)) {
1831
2183
  throw new Error("No widget for type '" + type + "'");
1832
2184
  }
1833
-
1834
2185
  if (widget in widgetMap[type]) {
1835
- const registeredWidget = registeredWidgets[widgetMap[type][widget]];
1836
- return getWidget(schema, registeredWidget, registeredWidgets);
2186
+ var _registeredWidget = registeredWidgets[widgetMap[type][widget]];
2187
+ return getWidget(schema, _registeredWidget, registeredWidgets);
1837
2188
  }
1838
2189
  }
1839
-
1840
2190
  throw new Error("No widget '" + widget + "' for type '" + type + "'");
1841
2191
  }
1842
2192
 
@@ -1848,26 +2198,96 @@
1848
2198
  * @param [registeredWidgets={}] - A registry of widget name to `Widget` implementation
1849
2199
  * @returns - True if the widget exists, false otherwise
1850
2200
  */
1851
-
1852
2201
  function hasWidget(schema, widget, registeredWidgets) {
1853
2202
  if (registeredWidgets === void 0) {
1854
2203
  registeredWidgets = {};
1855
2204
  }
1856
-
1857
2205
  try {
1858
2206
  getWidget(schema, widget, registeredWidgets);
1859
2207
  return true;
1860
2208
  } catch (e) {
1861
- const err = e;
1862
-
2209
+ var err = e;
1863
2210
  if (err.message && (err.message.startsWith("No widget") || err.message.startsWith("Unsupported widget"))) {
1864
2211
  return false;
1865
2212
  }
1866
-
1867
2213
  throw e;
1868
2214
  }
1869
2215
  }
1870
2216
 
2217
+ /** Generates a consistent `id` pattern for a given `id` and a `suffix`
2218
+ *
2219
+ * @param id - Either simple string id or an IdSchema from which to extract it
2220
+ * @param suffix - The suffix to append to the id
2221
+ */
2222
+ function idGenerator(id, suffix) {
2223
+ var theId = isString__default["default"](id) ? id : id[ID_KEY];
2224
+ return theId + "__" + suffix;
2225
+ }
2226
+ /** Return a consistent `id` for the field description element
2227
+ *
2228
+ * @param id - Either simple string id or an IdSchema from which to extract it
2229
+ * @returns - The consistent id for the field description element from the given `id`
2230
+ */
2231
+ function descriptionId(id) {
2232
+ return idGenerator(id, "description");
2233
+ }
2234
+ /** Return a consistent `id` for the field error element
2235
+ *
2236
+ * @param id - Either simple string id or an IdSchema from which to extract it
2237
+ * @returns - The consistent id for the field error element from the given `id`
2238
+ */
2239
+ function errorId(id) {
2240
+ return idGenerator(id, "error");
2241
+ }
2242
+ /** Return a consistent `id` for the field examples element
2243
+ *
2244
+ * @param id - Either simple string id or an IdSchema from which to extract it
2245
+ * @returns - The consistent id for the field examples element from the given `id`
2246
+ */
2247
+ function examplesId(id) {
2248
+ return idGenerator(id, "examples");
2249
+ }
2250
+ /** Return a consistent `id` for the field help element
2251
+ *
2252
+ * @param id - Either simple string id or an IdSchema from which to extract it
2253
+ * @returns - The consistent id for the field help element from the given `id`
2254
+ */
2255
+ function helpId(id) {
2256
+ return idGenerator(id, "help");
2257
+ }
2258
+ /** Return a consistent `id` for the field title element
2259
+ *
2260
+ * @param id - Either simple string id or an IdSchema from which to extract it
2261
+ * @returns - The consistent id for the field title element from the given `id`
2262
+ */
2263
+ function titleId(id) {
2264
+ return idGenerator(id, "title");
2265
+ }
2266
+ /** Return a list of element ids that contain additional information about the field that can be used to as the aria
2267
+ * description of the field. This is correctly omitting `titleId` which would be "labeling" rather than "describing" the
2268
+ * element.
2269
+ *
2270
+ * @param id - Either simple string id or an IdSchema from which to extract it
2271
+ * @param [includeExamples=false] - Optional flag, if true, will add the `examplesId` into the list
2272
+ * @returns - The string containing the list of ids for use in an `aria-describedBy` attribute
2273
+ */
2274
+ function ariaDescribedByIds(id, includeExamples) {
2275
+ if (includeExamples === void 0) {
2276
+ includeExamples = false;
2277
+ }
2278
+ var examples = includeExamples ? " " + examplesId(id) : "";
2279
+ return errorId(id) + " " + descriptionId(id) + " " + helpId(id) + examples;
2280
+ }
2281
+ /** Return a consistent `id` for the `option`s of a `Radio` or `Checkboxes` widget
2282
+ *
2283
+ * @param id - The id of the parent component for the option
2284
+ * @param option - The option for which the id is desired
2285
+ * @returns - An id for the option based on the parent `id`
2286
+ */
2287
+ function optionId(id, option) {
2288
+ return id + "-" + option.value;
2289
+ }
2290
+
1871
2291
  /** Converts a local Date string into a UTC date string
1872
2292
  *
1873
2293
  * @param dateString - The string representation of a date as accepted by the `Date()` constructor
@@ -1884,16 +2304,13 @@
1884
2304
  * @returns - The constant value for the schema
1885
2305
  * @throws - Error when the schema does not have a constant value
1886
2306
  */
1887
-
1888
2307
  function toConstant(schema) {
1889
- if (ENUM_KEY in schema && Array.isArray(schema.enum) && schema.enum.length === 1) {
1890
- return schema.enum[0];
2308
+ if (ENUM_KEY in schema && Array.isArray(schema["enum"]) && schema["enum"].length === 1) {
2309
+ return schema["enum"][0];
1891
2310
  }
1892
-
1893
2311
  if (CONST_KEY in schema) {
1894
- return schema.const;
2312
+ return schema["const"];
1895
2313
  }
1896
-
1897
2314
  throw new Error("schema cannot be inferred as a constant");
1898
2315
  }
1899
2316
 
@@ -1905,35 +2322,31 @@
1905
2322
  * @param schema - The schema from which to extract the options list
1906
2323
  * @returns - The list of options from the schema
1907
2324
  */
1908
-
1909
2325
  function optionsList(schema) {
1910
2326
  // enumNames was deprecated in v5 and is intentionally omitted from the RJSFSchema type.
1911
2327
  // Cast the type to include enumNames so the feature still works.
1912
- const schemaWithEnumNames = schema;
1913
-
2328
+ var schemaWithEnumNames = schema;
1914
2329
  if (schemaWithEnumNames.enumNames && "development" !== "production") {
1915
2330
  console.warn("The enumNames property is deprecated and may be removed in a future major release.");
1916
2331
  }
1917
-
1918
- if (schema.enum) {
1919
- return schema.enum.map((value, i) => {
1920
- const label = schemaWithEnumNames.enumNames && schemaWithEnumNames.enumNames[i] || String(value);
2332
+ if (schema["enum"]) {
2333
+ return schema["enum"].map(function (value, i) {
2334
+ var label = schemaWithEnumNames.enumNames && schemaWithEnumNames.enumNames[i] || String(value);
1921
2335
  return {
1922
- label,
1923
- value
2336
+ label: label,
2337
+ value: value
1924
2338
  };
1925
2339
  });
1926
2340
  }
1927
-
1928
- const altSchemas = schema.oneOf || schema.anyOf;
1929
- return altSchemas && altSchemas.map(aSchemaDef => {
1930
- const aSchema = aSchemaDef;
1931
- const value = toConstant(aSchema);
1932
- const label = aSchema.title || String(value);
2341
+ var altSchemas = schema.oneOf || schema.anyOf;
2342
+ return altSchemas && altSchemas.map(function (aSchemaDef) {
2343
+ var aSchema = aSchemaDef;
2344
+ var value = toConstant(aSchema);
2345
+ var label = aSchema.title || String(value);
1933
2346
  return {
1934
2347
  schema: aSchema,
1935
- label,
1936
- value
2348
+ label: label,
2349
+ value: value
1937
2350
  };
1938
2351
  });
1939
2352
  }
@@ -1952,34 +2365,35 @@
1952
2365
  if (!Array.isArray(order)) {
1953
2366
  return properties;
1954
2367
  }
1955
-
1956
- const arrayToHash = arr => arr.reduce((prev, curr) => {
1957
- prev[curr] = true;
1958
- return prev;
1959
- }, {});
1960
-
1961
- const errorPropList = arr => arr.length > 1 ? "properties '" + arr.join("', '") + "'" : "property '" + arr[0] + "'";
1962
-
1963
- const propertyHash = arrayToHash(properties);
1964
- const orderFiltered = order.filter(prop => prop === "*" || propertyHash[prop]);
1965
- const orderHash = arrayToHash(orderFiltered);
1966
- const rest = properties.filter(prop => !orderHash[prop]);
1967
- const restIndex = orderFiltered.indexOf("*");
1968
-
2368
+ var arrayToHash = function arrayToHash(arr) {
2369
+ return arr.reduce(function (prev, curr) {
2370
+ prev[curr] = true;
2371
+ return prev;
2372
+ }, {});
2373
+ };
2374
+ var errorPropList = function errorPropList(arr) {
2375
+ return arr.length > 1 ? "properties '" + arr.join("', '") + "'" : "property '" + arr[0] + "'";
2376
+ };
2377
+ var propertyHash = arrayToHash(properties);
2378
+ var orderFiltered = order.filter(function (prop) {
2379
+ return prop === "*" || propertyHash[prop];
2380
+ });
2381
+ var orderHash = arrayToHash(orderFiltered);
2382
+ var rest = properties.filter(function (prop) {
2383
+ return !orderHash[prop];
2384
+ });
2385
+ var restIndex = orderFiltered.indexOf("*");
1969
2386
  if (restIndex === -1) {
1970
2387
  if (rest.length) {
1971
2388
  throw new Error("uiSchema order list does not contain " + errorPropList(rest));
1972
2389
  }
1973
-
1974
2390
  return orderFiltered;
1975
2391
  }
1976
-
1977
2392
  if (restIndex !== orderFiltered.lastIndexOf("*")) {
1978
2393
  throw new Error("uiSchema order list contains more than one wildcard item");
1979
2394
  }
1980
-
1981
- const complete = [...orderFiltered];
1982
- complete.splice(restIndex, 1, ...rest);
2395
+ var complete = [].concat(orderFiltered);
2396
+ complete.splice.apply(complete, [restIndex, 1].concat(rest));
1983
2397
  return complete;
1984
2398
  }
1985
2399
 
@@ -1990,12 +2404,10 @@
1990
2404
  * @returns - The number converted to a string with leading zero padding if the number of digits is less than `width`
1991
2405
  */
1992
2406
  function pad(num, width) {
1993
- let s = String(num);
1994
-
2407
+ var s = String(num);
1995
2408
  while (s.length < width) {
1996
2409
  s = "0" + s;
1997
2410
  }
1998
-
1999
2411
  return s;
2000
2412
  }
2001
2413
 
@@ -2010,7 +2422,6 @@
2010
2422
  if (includeTime === void 0) {
2011
2423
  includeTime = true;
2012
2424
  }
2013
-
2014
2425
  if (!dateString) {
2015
2426
  return {
2016
2427
  year: -1,
@@ -2021,13 +2432,10 @@
2021
2432
  second: includeTime ? -1 : 0
2022
2433
  };
2023
2434
  }
2024
-
2025
- const date = new Date(dateString);
2026
-
2435
+ var date = new Date(dateString);
2027
2436
  if (Number.isNaN(date.getTime())) {
2028
2437
  throw new Error("Unable to parse date " + dateString);
2029
2438
  }
2030
-
2031
2439
  return {
2032
2440
  year: date.getUTCFullYear(),
2033
2441
  month: date.getUTCMonth() + 1,
@@ -2038,7 +2446,7 @@
2038
2446
  };
2039
2447
  }
2040
2448
 
2041
- const nums = /*#__PURE__*/new Set(["number", "integer"]);
2449
+ var nums = /*#__PURE__*/new Set(["number", "integer"]);
2042
2450
  /** Returns the real value for a select widget due to a silly limitation in the DOM which causes option change event
2043
2451
  * values to always be retrieved as strings. Uses the `schema` to help determine the value's true type. If the value is
2044
2452
  * an empty string, then the `emptyValue` from the `options` is returned, falling back to undefined.
@@ -2048,42 +2456,36 @@
2048
2456
  * @param [options] - The UIOptionsType from which to potentially extract the emptyValue
2049
2457
  * @returns - The `value` converted to the proper type
2050
2458
  */
2051
-
2052
2459
  function processSelectValue(schema, value, options) {
2053
- const {
2054
- enum: schemaEnum,
2055
- type,
2056
- items
2057
- } = schema;
2058
-
2460
+ var schemaEnum = schema["enum"],
2461
+ type = schema.type,
2462
+ items = schema.items;
2059
2463
  if (value === "") {
2060
2464
  return options && options.emptyValue !== undefined ? options.emptyValue : undefined;
2061
2465
  }
2062
-
2063
2466
  if (type === "array" && items && nums.has(get__default["default"](items, "type"))) {
2064
2467
  return value.map(asNumber);
2065
2468
  }
2066
-
2067
2469
  if (type === "boolean") {
2068
2470
  return value === "true";
2069
2471
  }
2070
-
2071
2472
  if (nums.has(type)) {
2072
2473
  return asNumber(value);
2073
- } // If type is undefined, but an enum is present, try and infer the type from
2474
+ }
2475
+ // If type is undefined, but an enum is present, try and infer the type from
2074
2476
  // the enum values
2075
-
2076
-
2077
2477
  if (Array.isArray(schemaEnum)) {
2078
- if (schemaEnum.every(x => nums.has(guessType(x)))) {
2478
+ if (schemaEnum.every(function (x) {
2479
+ return nums.has(guessType(x));
2480
+ })) {
2079
2481
  return asNumber(value);
2080
2482
  }
2081
-
2082
- if (schemaEnum.every(x => guessType(x) === "boolean")) {
2483
+ if (schemaEnum.every(function (x) {
2484
+ return guessType(x) === "boolean";
2485
+ })) {
2083
2486
  return value === "true";
2084
2487
  }
2085
2488
  }
2086
-
2087
2489
  return value;
2088
2490
  }
2089
2491
 
@@ -2098,32 +2500,28 @@
2098
2500
  */
2099
2501
  function schemaRequiresTrueValue(schema) {
2100
2502
  // Check if const is a truthy value
2101
- if (schema.const) {
2503
+ if (schema["const"]) {
2102
2504
  return true;
2103
- } // Check if an enum has a single value of true
2104
-
2105
-
2106
- if (schema.enum && schema.enum.length === 1 && schema.enum[0] === true) {
2505
+ }
2506
+ // Check if an enum has a single value of true
2507
+ if (schema["enum"] && schema["enum"].length === 1 && schema["enum"][0] === true) {
2107
2508
  return true;
2108
- } // If anyOf has a single value, evaluate the subschema
2109
-
2110
-
2509
+ }
2510
+ // If anyOf has a single value, evaluate the subschema
2111
2511
  if (schema.anyOf && schema.anyOf.length === 1) {
2112
2512
  return schemaRequiresTrueValue(schema.anyOf[0]);
2113
- } // If oneOf has a single value, evaluate the subschema
2114
-
2115
-
2513
+ }
2514
+ // If oneOf has a single value, evaluate the subschema
2116
2515
  if (schema.oneOf && schema.oneOf.length === 1) {
2117
2516
  return schemaRequiresTrueValue(schema.oneOf[0]);
2118
- } // Evaluate each subschema in allOf, to see if one of them requires a true value
2119
-
2120
-
2517
+ }
2518
+ // Evaluate each subschema in allOf, to see if one of them requires a true value
2121
2519
  if (schema.allOf) {
2122
- const schemaSome = subSchema => schemaRequiresTrueValue(subSchema);
2123
-
2520
+ var schemaSome = function schemaSome(subSchema) {
2521
+ return schemaRequiresTrueValue(subSchema);
2522
+ };
2124
2523
  return schema.allOf.some(schemaSome);
2125
2524
  }
2126
-
2127
2525
  return false;
2128
2526
  }
2129
2527
 
@@ -2135,12 +2533,9 @@
2135
2533
  * @param nextState - The next set of state against which to check
2136
2534
  * @returns - True if the component should be re-rendered, false otherwise
2137
2535
  */
2138
-
2139
2536
  function shouldRender(component, nextProps, nextState) {
2140
- const {
2141
- props,
2142
- state
2143
- } = component;
2537
+ var props = component.props,
2538
+ state = component.state;
2144
2539
  return !deepEquals(props, nextProps) || !deepEquals(state, nextState);
2145
2540
  }
2146
2541
 
@@ -2155,17 +2550,17 @@
2155
2550
  if (time === void 0) {
2156
2551
  time = true;
2157
2552
  }
2158
-
2159
- const {
2160
- year,
2161
- month,
2162
- day,
2163
- hour = 0,
2164
- minute = 0,
2165
- second = 0
2166
- } = dateObject;
2167
- const utcTime = Date.UTC(year, month - 1, day, hour, minute, second);
2168
- const datetime = new Date(utcTime).toJSON();
2553
+ var year = dateObject.year,
2554
+ month = dateObject.month,
2555
+ day = dateObject.day,
2556
+ _dateObject$hour = dateObject.hour,
2557
+ hour = _dateObject$hour === void 0 ? 0 : _dateObject$hour,
2558
+ _dateObject$minute = dateObject.minute,
2559
+ minute = _dateObject$minute === void 0 ? 0 : _dateObject$minute,
2560
+ _dateObject$second = dateObject.second,
2561
+ second = _dateObject$second === void 0 ? 0 : _dateObject$second;
2562
+ var utcTime = Date.UTC(year, month - 1, day, hour, minute, second);
2563
+ var datetime = new Date(utcTime).toJSON();
2169
2564
  return time ? datetime : datetime.slice(0, 10);
2170
2565
  }
2171
2566
 
@@ -2174,25 +2569,23 @@
2174
2569
  * @param jsonDate - A UTC date string
2175
2570
  * @returns - An empty string when `jsonDate` is falsey, otherwise a date string in local format
2176
2571
  */
2177
-
2178
2572
  function utcToLocal(jsonDate) {
2179
2573
  if (!jsonDate) {
2180
2574
  return "";
2181
- } // required format of `'yyyy-MM-ddThh:mm' followed by optional ':ss' or ':ss.SSS'
2575
+ }
2576
+ // required format of `'yyyy-MM-ddThh:mm' followed by optional ':ss' or ':ss.SSS'
2182
2577
  // https://html.spec.whatwg.org/multipage/input.html#local-date-and-time-state-(type%3Ddatetime-local)
2183
2578
  // > should be a _valid local date and time string_ (not GMT)
2184
2579
  // Note - date constructor passed local ISO-8601 does not correctly
2185
2580
  // change time to UTC in node pre-8
2186
-
2187
-
2188
- const date = new Date(jsonDate);
2189
- const yyyy = pad(date.getFullYear(), 4);
2190
- const MM = pad(date.getMonth() + 1, 2);
2191
- const dd = pad(date.getDate(), 2);
2192
- const hh = pad(date.getHours(), 2);
2193
- const mm = pad(date.getMinutes(), 2);
2194
- const ss = pad(date.getSeconds(), 2);
2195
- const SSS = pad(date.getMilliseconds(), 3);
2581
+ var date = new Date(jsonDate);
2582
+ var yyyy = pad(date.getFullYear(), 4);
2583
+ var MM = pad(date.getMonth() + 1, 2);
2584
+ var dd = pad(date.getDate(), 2);
2585
+ var hh = pad(date.getHours(), 2);
2586
+ var mm = pad(date.getMinutes(), 2);
2587
+ var ss = pad(date.getSeconds(), 2);
2588
+ var SSS = pad(date.getMilliseconds(), 3);
2196
2589
  return yyyy + "-" + MM + "-" + dd + "T" + hh + ":" + mm + ":" + ss + "." + SSS;
2197
2590
  }
2198
2591
 
@@ -2206,6 +2599,7 @@
2206
2599
  exports.DEPENDENCIES_KEY = DEPENDENCIES_KEY;
2207
2600
  exports.ENUM_KEY = ENUM_KEY;
2208
2601
  exports.ERRORS_KEY = ERRORS_KEY;
2602
+ exports.ErrorSchemaBuilder = ErrorSchemaBuilder;
2209
2603
  exports.ID_KEY = ID_KEY;
2210
2604
  exports.ITEMS_KEY = ITEMS_KEY;
2211
2605
  exports.NAME_KEY = NAME_KEY;
@@ -2219,14 +2613,22 @@
2219
2613
  exports.UI_OPTIONS_KEY = UI_OPTIONS_KEY;
2220
2614
  exports.UI_WIDGET_KEY = UI_WIDGET_KEY;
2221
2615
  exports.allowAdditionalItems = allowAdditionalItems;
2616
+ exports.ariaDescribedByIds = ariaDescribedByIds;
2222
2617
  exports.asNumber = asNumber;
2223
2618
  exports.canExpand = canExpand;
2224
2619
  exports.createSchemaUtils = createSchemaUtils;
2225
2620
  exports.dataURItoBlob = dataURItoBlob;
2226
2621
  exports.deepEquals = deepEquals;
2622
+ exports.descriptionId = descriptionId;
2623
+ exports.enumOptionsDeselectValue = enumOptionsDeselectValue;
2624
+ exports.enumOptionsSelectValue = enumOptionsSelectValue;
2625
+ exports.errorId = errorId;
2626
+ exports.examplesId = examplesId;
2227
2627
  exports.findSchemaDefinition = findSchemaDefinition;
2628
+ exports.getClosestMatchingOption = getClosestMatchingOption;
2228
2629
  exports.getDefaultFormState = getDefaultFormState;
2229
2630
  exports.getDisplayLabel = getDisplayLabel;
2631
+ exports.getFirstMatchingOption = getFirstMatchingOption;
2230
2632
  exports.getInputProps = getInputProps;
2231
2633
  exports.getMatchingOption = getMatchingOption;
2232
2634
  exports.getSchemaType = getSchemaType;
@@ -2236,6 +2638,7 @@
2236
2638
  exports.getWidget = getWidget;
2237
2639
  exports.guessType = guessType;
2238
2640
  exports.hasWidget = hasWidget;
2641
+ exports.helpId = helpId;
2239
2642
  exports.isConstant = isConstant;
2240
2643
  exports.isCustomWidget = isCustomWidget;
2241
2644
  exports.isFilesArray = isFilesArray;
@@ -2248,6 +2651,7 @@
2248
2651
  exports.mergeObjects = mergeObjects;
2249
2652
  exports.mergeSchemas = mergeSchemas;
2250
2653
  exports.mergeValidationData = mergeValidationData;
2654
+ exports.optionId = optionId;
2251
2655
  exports.optionsList = optionsList;
2252
2656
  exports.orderProperties = orderProperties;
2253
2657
  exports.pad = pad;
@@ -2255,8 +2659,10 @@
2255
2659
  exports.processSelectValue = processSelectValue;
2256
2660
  exports.rangeSpec = rangeSpec;
2257
2661
  exports.retrieveSchema = retrieveSchema;
2662
+ exports.sanitizeDataForNewSchema = sanitizeDataForNewSchema;
2258
2663
  exports.schemaRequiresTrueValue = schemaRequiresTrueValue;
2259
2664
  exports.shouldRender = shouldRender;
2665
+ exports.titleId = titleId;
2260
2666
  exports.toConstant = toConstant;
2261
2667
  exports.toDateString = toDateString;
2262
2668
  exports.toIdSchema = toIdSchema;