@rjsf/utils 5.0.0-beta.11 → 5.0.0-beta.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/utils.esm.js CHANGED
@@ -19,7 +19,6 @@ function isObject(thing) {
19
19
  if (typeof File !== "undefined" && thing instanceof File) {
20
20
  return false;
21
21
  }
22
-
23
22
  return typeof thing === "object" && thing !== null && !Array.isArray(thing);
24
23
  }
25
24
 
@@ -29,12 +28,10 @@ function isObject(thing) {
29
28
  * @param schema - The schema object to check
30
29
  * @returns - True if additional items is allowed, otherwise false
31
30
  */
32
-
33
31
  function allowAdditionalItems(schema) {
34
32
  if (schema.additionalItems === true) {
35
33
  console.warn("additionalItems=true is currently not supported");
36
34
  }
37
-
38
35
  return isObject(schema.additionalItems);
39
36
  }
40
37
 
@@ -51,29 +48,24 @@ function asNumber(value) {
51
48
  if (value === "") {
52
49
  return undefined;
53
50
  }
54
-
55
51
  if (value === null) {
56
52
  return null;
57
53
  }
58
-
59
54
  if (/\.$/.test(value)) {
60
55
  // '3.' can't really be considered a number even if it parses in js. The
61
56
  // user is most likely entering a float.
62
57
  return value;
63
58
  }
64
-
65
59
  if (/\.0$/.test(value)) {
66
60
  // we need to return this as a string here, to allow for input like 3.07
67
61
  return value;
68
62
  }
69
-
70
63
  if (/\.\d*0$/.test(value)) {
71
64
  // It's a number, that's cool - but we need it as a string so it doesn't screw
72
65
  // with the user when entering dollar amounts or other values (such as those with
73
66
  // specific precision or number of significant digits)
74
67
  return value;
75
68
  }
76
-
77
69
  const n = Number(value);
78
70
  const valid = typeof n === "number" && !Number.isNaN(n);
79
71
  return valid ? n : value;
@@ -111,29 +103,26 @@ const UI_OPTIONS_KEY = "ui:options";
111
103
  * stripped off.
112
104
  *
113
105
  * @param [uiSchema={}] - The UI Schema from which to get any `ui:xxx` options
114
- * @returns - An object containing all of the `ui:xxx` options with the stripped off
106
+ * @returns - An object containing all the `ui:xxx` options with the stripped off
115
107
  */
116
-
117
108
  function getUiOptions(uiSchema) {
118
109
  if (uiSchema === void 0) {
119
110
  uiSchema = {};
120
111
  }
121
-
122
112
  return Object.keys(uiSchema).filter(key => key.indexOf("ui:") === 0).reduce((options, key) => {
123
113
  const value = uiSchema[key];
124
-
125
114
  if (key === UI_WIDGET_KEY && isObject(value)) {
126
115
  console.error("Setting options via ui:widget object is no longer supported, use ui:options instead");
127
116
  return options;
128
117
  }
129
-
130
118
  if (key === UI_OPTIONS_KEY && isObject(value)) {
131
- return { ...options,
119
+ return {
120
+ ...options,
132
121
  ...value
133
122
  };
134
123
  }
135
-
136
- return { ...options,
124
+ return {
125
+ ...options,
137
126
  [key.substring(3)]: value
138
127
  };
139
128
  }, {});
@@ -148,30 +137,24 @@ function getUiOptions(uiSchema) {
148
137
  * @param [formData] - The formData for the field
149
138
  * @returns - True if the schema element has additionalProperties, is expandable, and not at the maxProperties limit
150
139
  */
151
-
152
140
  function canExpand(schema, uiSchema, formData) {
153
141
  if (uiSchema === void 0) {
154
142
  uiSchema = {};
155
143
  }
156
-
157
144
  if (!schema.additionalProperties) {
158
145
  return false;
159
146
  }
160
-
161
147
  const {
162
148
  expandable = true
163
149
  } = getUiOptions(uiSchema);
164
-
165
150
  if (expandable === false) {
166
151
  return expandable;
167
- } // if ui:options.expandable was not explicitly set to false, we can add
152
+ }
153
+ // if ui:options.expandable was not explicitly set to false, we can add
168
154
  // another property if we have not exceeded maxProperties yet
169
-
170
-
171
155
  if (schema.maxProperties !== undefined && formData) {
172
156
  return Object.keys(formData).length < schema.maxProperties;
173
157
  }
174
-
175
158
  return true;
176
159
  }
177
160
 
@@ -182,7 +165,6 @@ function canExpand(schema, uiSchema, formData) {
182
165
  * @param b - The second element to compare
183
166
  * @returns - True if the `a` and `b` are deeply equal, false otherwise
184
167
  */
185
-
186
168
  function deepEquals(a, b) {
187
169
  return isEqualWith(a, b, (obj, other) => {
188
170
  if (typeof obj === "function" && typeof other === "function") {
@@ -190,7 +172,6 @@ function deepEquals(a, b) {
190
172
  // see https://github.com/rjsf-team/react-jsonschema-form/issues/255
191
173
  return true;
192
174
  }
193
-
194
175
  return undefined; // fallback to default isEquals behavior
195
176
  });
196
177
  }
@@ -203,7 +184,6 @@ function deepEquals(a, b) {
203
184
  * @returns - An array with the first value being the object minus the `key` element and the second element being the
204
185
  * value from `object[key]`
205
186
  */
206
-
207
187
  function splitKeyElementFromObject(key, object) {
208
188
  const value = object[key];
209
189
  const remaining = omit(object, [key]);
@@ -218,40 +198,32 @@ function splitKeyElementFromObject(key, object) {
218
198
  * @returns - The sub-schema within the `rootSchema` which matches the `$ref` if it exists
219
199
  * @throws - Error indicating that no schema for that reference exists
220
200
  */
221
-
222
201
  function findSchemaDefinition($ref, rootSchema) {
223
202
  if (rootSchema === void 0) {
224
203
  rootSchema = {};
225
204
  }
226
-
227
205
  let ref = $ref || "";
228
-
229
206
  if (ref.startsWith("#")) {
230
207
  // Decode URI fragment representation.
231
208
  ref = decodeURIComponent(ref.substring(1));
232
209
  } else {
233
- throw new Error("Could not find a definition for " + $ref + ".");
210
+ throw new Error(`Could not find a definition for ${$ref}.`);
234
211
  }
235
-
236
212
  const current = jsonpointer.get(rootSchema, ref);
237
-
238
213
  if (current === undefined) {
239
- throw new Error("Could not find a definition for " + $ref + ".");
214
+ throw new Error(`Could not find a definition for ${$ref}.`);
240
215
  }
241
-
242
216
  if (current[REF_KEY]) {
243
217
  const [remaining, theRef] = splitKeyElementFromObject(REF_KEY, current);
244
218
  const subSchema = findSchemaDefinition(theRef, rootSchema);
245
-
246
219
  if (Object.keys(remaining).length > 0) {
247
- return { ...remaining,
220
+ return {
221
+ ...remaining,
248
222
  ...subSchema
249
223
  };
250
224
  }
251
-
252
225
  return subSchema;
253
226
  }
254
-
255
227
  return current;
256
228
  }
257
229
 
@@ -269,16 +241,15 @@ function getMatchingOption(validator, formData, options, rootSchema) {
269
241
  if (formData === undefined) {
270
242
  return 0;
271
243
  }
272
-
273
244
  for (let i = 0; i < options.length; i++) {
274
- const option = options[i]; // If the schema describes an object then we need to add slightly more
245
+ const option = options[i];
246
+ // If the schema describes an object then we need to add slightly more
275
247
  // strict matching to the schema, because unless the schema uses the
276
248
  // "requires" keyword, an object will match the schema as long as it
277
249
  // doesn't have matching keys with a conflicting type. To do this we use an
278
250
  // "anyOf" with an array of requires. This augmentation expresses that the
279
251
  // schema should match if any of the keys in the schema are present on the
280
252
  // object and pass validation.
281
-
282
253
  if (option.properties) {
283
254
  // Create an "anyOf" schema that requires at least one of the keys in the
284
255
  // "properties" object
@@ -287,30 +258,27 @@ function getMatchingOption(validator, formData, options, rootSchema) {
287
258
  required: [key]
288
259
  }))
289
260
  };
290
- let augmentedSchema; // If the "anyOf" keyword already exists, wrap the augmentation in an "allOf"
291
-
261
+ let augmentedSchema;
262
+ // If the "anyOf" keyword already exists, wrap the augmentation in an "allOf"
292
263
  if (option.anyOf) {
293
264
  // Create a shallow clone of the option
294
- const { ...shallowClone
265
+ const {
266
+ ...shallowClone
295
267
  } = option;
296
-
297
268
  if (!shallowClone.allOf) {
298
269
  shallowClone.allOf = [];
299
270
  } else {
300
271
  // If "allOf" already exists, shallow clone the array
301
272
  shallowClone.allOf = shallowClone.allOf.slice();
302
273
  }
303
-
304
274
  shallowClone.allOf.push(requiresAnyOf);
305
275
  augmentedSchema = shallowClone;
306
276
  } else {
307
277
  augmentedSchema = Object.assign({}, option, requiresAnyOf);
308
- } // Remove the "required" field as it's likely that not all fields have
278
+ }
279
+ // Remove the "required" field as it's likely that not all fields have
309
280
  // been filled in yet, which will mean that the schema is not valid
310
-
311
-
312
281
  delete augmentedSchema.required;
313
-
314
282
  if (validator.isValid(augmentedSchema, formData, rootSchema)) {
315
283
  return i;
316
284
  }
@@ -318,7 +286,6 @@ function getMatchingOption(validator, formData, options, rootSchema) {
318
286
  return i;
319
287
  }
320
288
  }
321
-
322
289
  return 0;
323
290
  }
324
291
 
@@ -332,28 +299,22 @@ function guessType(value) {
332
299
  if (Array.isArray(value)) {
333
300
  return "array";
334
301
  }
335
-
336
302
  if (typeof value === "string") {
337
303
  return "string";
338
304
  }
339
-
340
305
  if (value == null) {
341
306
  return "null";
342
307
  }
343
-
344
308
  if (typeof value === "boolean") {
345
309
  return "boolean";
346
310
  }
347
-
348
311
  if (!isNaN(value)) {
349
312
  return "number";
350
313
  }
351
-
352
314
  if (typeof value === "object") {
353
315
  return "object";
354
- } // Default to string if we can't figure it out
355
-
356
-
316
+ }
317
+ // Default to string if we can't figure it out
357
318
  return "string";
358
319
  }
359
320
 
@@ -368,28 +329,22 @@ function guessType(value) {
368
329
  * @param schema - The schema for which to get the type
369
330
  * @returns - The type of the schema
370
331
  */
371
-
372
332
  function getSchemaType(schema) {
373
333
  let {
374
334
  type
375
335
  } = schema;
376
-
377
336
  if (!type && schema.const) {
378
337
  return guessType(schema.const);
379
338
  }
380
-
381
339
  if (!type && schema.enum) {
382
340
  return "string";
383
341
  }
384
-
385
342
  if (!type && (schema.properties || schema.additionalProperties)) {
386
343
  return "object";
387
344
  }
388
-
389
345
  if (Array.isArray(type) && type.length === 2 && type.includes("null")) {
390
346
  type = type.find(type => type !== "null");
391
347
  }
392
-
393
348
  return type;
394
349
  }
395
350
 
@@ -399,7 +354,6 @@ function getSchemaType(schema) {
399
354
  * @param schema - The schema in which to check for fixed items
400
355
  * @returns - True if there are fixed items in the schema, false otherwise
401
356
  */
402
-
403
357
  function isFixedItems(schema) {
404
358
  return Array.isArray(schema.items) && schema.items.length > 0 && schema.items.every(item => isObject(item));
405
359
  }
@@ -418,7 +372,6 @@ function isFixedItems(schema) {
418
372
  * @param formData - The form data into which the defaults will be merged
419
373
  * @returns - The resulting merged form data with defaults
420
374
  */
421
-
422
375
  function mergeDefaultsWithFormData(defaults, formData) {
423
376
  if (Array.isArray(formData)) {
424
377
  const defaultsArray = Array.isArray(defaults) ? defaults : [];
@@ -426,22 +379,17 @@ function mergeDefaultsWithFormData(defaults, formData) {
426
379
  if (defaultsArray[idx]) {
427
380
  return mergeDefaultsWithFormData(defaultsArray[idx], value);
428
381
  }
429
-
430
382
  return value;
431
383
  });
432
384
  return mapped;
433
385
  }
434
-
435
386
  if (isObject(formData)) {
436
- // eslint-disable-next-line no-unused-vars
437
387
  const acc = Object.assign({}, defaults); // Prevent mutation of source object.
438
-
439
388
  return Object.keys(formData).reduce((acc, key) => {
440
389
  acc[key] = mergeDefaultsWithFormData(defaults ? get(defaults, key) : {}, get(formData, key));
441
390
  return acc;
442
391
  }, acc);
443
392
  }
444
-
445
393
  return formData;
446
394
  }
447
395
 
@@ -452,16 +400,13 @@ function mergeDefaultsWithFormData(defaults, formData) {
452
400
  * @param [concatArrays=false] - Optional flag that, when true, will cause arrays to be concatenated
453
401
  * @returns - A new object that is the merge of the two given objects
454
402
  */
455
-
456
403
  function mergeObjects(obj1, obj2, concatArrays) {
457
404
  if (concatArrays === void 0) {
458
405
  concatArrays = false;
459
406
  }
460
-
461
407
  return Object.keys(obj2).reduce((acc, key) => {
462
408
  const left = obj1 ? obj1[key] : {},
463
- right = obj2[key];
464
-
409
+ right = obj2[key];
465
410
  if (obj1 && key in obj1 && isObject(right)) {
466
411
  acc[key] = mergeObjects(left, right, concatArrays);
467
412
  } else if (concatArrays && Array.isArray(left) && Array.isArray(right)) {
@@ -469,7 +414,6 @@ function mergeObjects(obj1, obj2, concatArrays) {
469
414
  } else {
470
415
  acc[key] = right;
471
416
  }
472
-
473
417
  return acc;
474
418
  }, Object.assign({}, obj1)); // Prevent mutation of source object.
475
419
  }
@@ -480,7 +424,6 @@ function mergeObjects(obj1, obj2, concatArrays) {
480
424
  * @param schema - The schema for a field
481
425
  * @returns - True if the `schema` has a single constant value, false otherwise
482
426
  */
483
-
484
427
  function isConstant(schema) {
485
428
  return Array.isArray(schema.enum) && schema.enum.length === 1 || CONST_KEY in schema;
486
429
  }
@@ -493,14 +436,11 @@ function isConstant(schema) {
493
436
  * @param obj2 - The second schema object to merge
494
437
  * @returns - The merged schema object
495
438
  */
496
-
497
439
  function mergeSchemas(obj1, obj2) {
498
440
  const acc = Object.assign({}, obj1); // Prevent mutation of source object.
499
-
500
441
  return Object.keys(obj2).reduce((acc, key) => {
501
442
  const left = obj1 ? obj1[key] : {},
502
- right = obj2[key];
503
-
443
+ right = obj2[key];
504
444
  if (obj1 && key in obj1 && isObject(right)) {
505
445
  acc[key] = mergeSchemas(left, right);
506
446
  } else if (obj1 && obj2 && (getSchemaType(obj1) === "object" || getSchemaType(obj2) === "object") && key === REQUIRED_KEY && Array.isArray(left) && Array.isArray(right)) {
@@ -509,7 +449,6 @@ function mergeSchemas(obj1, obj2) {
509
449
  } else {
510
450
  acc[key] = right;
511
451
  }
512
-
513
452
  return acc;
514
453
  }, acc);
515
454
  }
@@ -517,13 +456,12 @@ function mergeSchemas(obj1, obj2) {
517
456
  /** Resolves a conditional block (if/else/then) by removing the condition and merging the appropriate conditional branch
518
457
  * with the rest of the schema
519
458
  *
520
- * @param validator - An implementation of the `ValidatorType` interface that is used to detect valid schema conditions
459
+ * @param validator - An implementation of the `ValidatorType<T, S>` interface that is used to detect valid schema conditions
521
460
  * @param schema - The schema for which resolving a condition is desired
522
461
  * @param rootSchema - The root schema that will be forwarded to all the APIs
523
462
  * @param formData - The current formData to assist retrieving a schema
524
463
  * @returns - A schema with the appropriate condition resolved
525
464
  */
526
-
527
465
  function resolveCondition(validator, schema, rootSchema, formData) {
528
466
  const {
529
467
  if: expression,
@@ -532,100 +470,94 @@ function resolveCondition(validator, schema, rootSchema, formData) {
532
470
  ...resolvedSchemaLessConditional
533
471
  } = schema;
534
472
  const conditionalSchema = validator.isValid(expression, formData, rootSchema) ? then : otherwise;
535
-
536
473
  if (conditionalSchema && typeof conditionalSchema !== "boolean") {
537
474
  return retrieveSchema(validator, mergeSchemas(resolvedSchemaLessConditional, retrieveSchema(validator, conditionalSchema, rootSchema, formData)), rootSchema, formData);
538
475
  }
539
-
540
476
  return retrieveSchema(validator, resolvedSchemaLessConditional, rootSchema, formData);
541
477
  }
542
478
  /** Resolves references and dependencies within a schema and its 'allOf' children.
543
479
  * Called internally by retrieveSchema.
544
480
  *
545
- * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
481
+ * @param validator - An implementation of the `ValidatorType<T, S>` interface that will be forwarded to all the APIs
546
482
  * @param schema - The schema for which resolving a schema is desired
547
483
  * @param [rootSchema={}] - The root schema that will be forwarded to all the APIs
548
484
  * @param [formData] - The current formData, if any, to assist retrieving a schema
549
485
  * @returns - The schema having its references and dependencies resolved
550
486
  */
551
-
552
487
  function resolveSchema(validator, schema, rootSchema, formData) {
553
488
  if (rootSchema === void 0) {
554
489
  rootSchema = {};
555
490
  }
556
-
557
491
  if (REF_KEY in schema) {
558
492
  return resolveReference(validator, schema, rootSchema, formData);
559
493
  }
560
-
561
494
  if (DEPENDENCIES_KEY in schema) {
562
495
  const resolvedSchema = resolveDependencies(validator, schema, rootSchema, formData);
563
496
  return retrieveSchema(validator, resolvedSchema, rootSchema, formData);
564
497
  }
565
-
566
498
  if (ALL_OF_KEY in schema) {
567
- return { ...schema,
499
+ return {
500
+ ...schema,
568
501
  allOf: schema.allOf.map(allOfSubschema => retrieveSchema(validator, allOfSubschema, rootSchema, formData))
569
502
  };
570
- } // No $ref or dependencies attribute found, returning the original schema.
571
-
572
-
503
+ }
504
+ // No $ref or dependencies attribute found, returning the original schema.
573
505
  return schema;
574
506
  }
575
507
  /** Resolves references within a schema and its 'allOf' children.
576
508
  *
577
- * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
509
+ * @param validator - An implementation of the `ValidatorType<T, S>` interface that will be forwarded to all the APIs
578
510
  * @param schema - The schema for which resolving a reference is desired
579
511
  * @param rootSchema - The root schema that will be forwarded to all the APIs
580
512
  * @param [formData] - The current formData, if any, to assist retrieving a schema
581
513
  * @returns - The schema having its references resolved
582
514
  */
583
-
584
515
  function resolveReference(validator, schema, rootSchema, formData) {
585
516
  // Retrieve the referenced schema definition.
586
- const $refSchema = findSchemaDefinition(schema.$ref, rootSchema); // Drop the $ref property of the source schema.
587
-
517
+ const $refSchema = findSchemaDefinition(schema.$ref, rootSchema);
518
+ // Drop the $ref property of the source schema.
588
519
  const {
589
520
  $ref,
590
521
  ...localSchema
591
- } = schema; // Update referenced schema definition with local schema properties.
592
-
593
- return retrieveSchema(validator, { ...$refSchema,
522
+ } = schema;
523
+ // Update referenced schema definition with local schema properties.
524
+ return retrieveSchema(validator, {
525
+ ...$refSchema,
594
526
  ...localSchema
595
527
  }, rootSchema, formData);
596
528
  }
597
529
  /** Creates new 'properties' items for each key in the `formData`
598
530
  *
599
- * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
531
+ * @param validator - An implementation of the `ValidatorType<T, S>` interface that will be used when necessary
600
532
  * @param theSchema - The schema for which the existing additional properties is desired
601
533
  * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s * @param validator
602
534
  * @param [aFormData] - The current formData, if any, to assist retrieving a schema
603
535
  * @returns - The updated schema with additional properties stubbed
604
536
  */
605
-
606
537
  function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFormData) {
607
538
  // Clone the schema so we don't ruin the consumer's original
608
- const schema = { ...theSchema,
609
- properties: { ...theSchema.properties
539
+ const schema = {
540
+ ...theSchema,
541
+ properties: {
542
+ ...theSchema.properties
610
543
  }
611
- }; // make sure formData is an object
612
-
544
+ };
545
+ // make sure formData is an object
613
546
  const formData = aFormData && isObject(aFormData) ? aFormData : {};
614
547
  Object.keys(formData).forEach(key => {
615
548
  if (key in schema.properties) {
616
549
  // No need to stub, our schema already has the property
617
550
  return;
618
551
  }
619
-
620
552
  let additionalProperties = {};
621
-
622
553
  if (typeof schema.additionalProperties !== "boolean") {
623
554
  if (REF_KEY in schema.additionalProperties) {
624
555
  additionalProperties = retrieveSchema(validator, {
625
556
  $ref: get(schema.additionalProperties, [REF_KEY])
626
557
  }, rootSchema, formData);
627
558
  } else if ("type" in schema.additionalProperties) {
628
- additionalProperties = { ...schema.additionalProperties
559
+ additionalProperties = {
560
+ ...schema.additionalProperties
629
561
  };
630
562
  } else {
631
563
  additionalProperties = {
@@ -636,11 +568,10 @@ function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFor
636
568
  additionalProperties = {
637
569
  type: guessType(get(formData, [key]))
638
570
  };
639
- } // The type of our new key should match the additionalProperties value;
640
-
641
-
642
- schema.properties[key] = additionalProperties; // Set our additional property flag so we know it was dynamically added
643
-
571
+ }
572
+ // The type of our new key should match the additionalProperties value;
573
+ schema.properties[key] = additionalProperties;
574
+ // Set our additional property flag so we know it was dynamically added
644
575
  set(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
645
576
  });
646
577
  return schema;
@@ -649,31 +580,26 @@ function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFor
649
580
  * resolved and merged into the `schema` given a `validator`, `rootSchema` and `rawFormData` that is used to do the
650
581
  * potentially recursive resolution.
651
582
  *
652
- * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
583
+ * @param validator - An implementation of the `ValidatorType<T, S>` interface that will be forwarded to all the APIs
653
584
  * @param schema - The schema for which retrieving a schema is desired
654
585
  * @param [rootSchema={}] - The root schema that will be forwarded to all the APIs
655
586
  * @param [rawFormData] - The current formData, if any, to assist retrieving a schema
656
587
  * @returns - The schema having its conditions, additional properties, references and dependencies resolved
657
588
  */
658
-
659
589
  function retrieveSchema(validator, schema, rootSchema, rawFormData) {
660
590
  if (rootSchema === void 0) {
661
591
  rootSchema = {};
662
592
  }
663
-
664
593
  if (!isObject(schema)) {
665
594
  return {};
666
595
  }
667
-
668
596
  let resolvedSchema = resolveSchema(validator, schema, rootSchema, rawFormData);
669
-
670
597
  if ("if" in schema) {
671
598
  return resolveCondition(validator, schema, rootSchema, rawFormData);
672
599
  }
673
-
674
- const formData = rawFormData || {}; // For each level of the dependency, we need to recursively determine the appropriate resolved schema given the current state of formData.
600
+ const formData = rawFormData || {};
601
+ // For each level of the dependency, we need to recursively determine the appropriate resolved schema given the current state of formData.
675
602
  // Otherwise, nested allOf subschemas will not be correctly displayed.
676
-
677
603
  if (resolvedSchema.properties) {
678
604
  const properties = {};
679
605
  Object.entries(resolvedSchema.properties).forEach(entries => {
@@ -683,18 +609,18 @@ function retrieveSchema(validator, schema, rootSchema, rawFormData) {
683
609
  const propData = isObject(rawPropData) ? rawPropData : {};
684
610
  const resolvedPropSchema = retrieveSchema(validator, propSchema, rootSchema, propData);
685
611
  properties[propName] = resolvedPropSchema;
686
-
687
612
  if (propSchema !== resolvedPropSchema && resolvedSchema.properties !== properties) {
688
- resolvedSchema = { ...resolvedSchema,
613
+ resolvedSchema = {
614
+ ...resolvedSchema,
689
615
  properties
690
616
  };
691
617
  }
692
618
  });
693
619
  }
694
-
695
620
  if (ALL_OF_KEY in schema) {
696
621
  try {
697
- resolvedSchema = mergeAllOf({ ...resolvedSchema,
622
+ resolvedSchema = mergeAllOf({
623
+ ...resolvedSchema,
698
624
  allOf: resolvedSchema.allOf
699
625
  });
700
626
  } catch (e) {
@@ -706,24 +632,20 @@ function retrieveSchema(validator, schema, rootSchema, rawFormData) {
706
632
  return resolvedSchemaWithoutAllOf;
707
633
  }
708
634
  }
709
-
710
635
  const hasAdditionalProperties = ADDITIONAL_PROPERTIES_KEY in resolvedSchema && resolvedSchema.additionalProperties !== false;
711
-
712
636
  if (hasAdditionalProperties) {
713
637
  return stubExistingAdditionalProperties(validator, resolvedSchema, rootSchema, formData);
714
638
  }
715
-
716
639
  return resolvedSchema;
717
640
  }
718
641
  /** Resolves dependencies within a schema and its 'allOf' children.
719
642
  *
720
- * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
643
+ * @param validator - An implementation of the `ValidatorType<T, S>` interface that will be forwarded to all the APIs
721
644
  * @param schema - The schema for which resolving a dependency is desired
722
645
  * @param rootSchema - The root schema that will be forwarded to all the APIs
723
646
  * @param [formData] - The current formData, if any, to assist retrieving a schema
724
647
  * @returns - The schema with its dependencies resolved
725
648
  */
726
-
727
649
  function resolveDependencies(validator, schema, rootSchema, formData) {
728
650
  // Drop the dependencies from the source schema.
729
651
  const {
@@ -731,50 +653,42 @@ function resolveDependencies(validator, schema, rootSchema, formData) {
731
653
  ...remainingSchema
732
654
  } = schema;
733
655
  let resolvedSchema = remainingSchema;
734
-
735
656
  if (Array.isArray(resolvedSchema.oneOf)) {
736
657
  resolvedSchema = resolvedSchema.oneOf[getMatchingOption(validator, formData, resolvedSchema.oneOf, rootSchema)];
737
658
  } else if (Array.isArray(resolvedSchema.anyOf)) {
738
659
  resolvedSchema = resolvedSchema.anyOf[getMatchingOption(validator, formData, resolvedSchema.anyOf, rootSchema)];
739
660
  }
740
-
741
661
  return processDependencies(validator, dependencies, resolvedSchema, rootSchema, formData);
742
662
  }
743
663
  /** Processes all the `dependencies` recursively into the `resolvedSchema` as needed
744
664
  *
745
- * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
665
+ * @param validator - An implementation of the `ValidatorType<T, S>` interface that will be forwarded to all the APIs
746
666
  * @param dependencies - The set of dependencies that needs to be processed
747
667
  * @param resolvedSchema - The schema for which processing dependencies is desired
748
668
  * @param rootSchema - The root schema that will be forwarded to all the APIs
749
669
  * @param [formData] - The current formData, if any, to assist retrieving a schema
750
670
  * @returns - The schema with the `dependencies` resolved into it
751
671
  */
752
-
753
672
  function processDependencies(validator, dependencies, resolvedSchema, rootSchema, formData) {
754
- let schema = resolvedSchema; // Process dependencies updating the local schema properties as appropriate.
755
-
673
+ let schema = resolvedSchema;
674
+ // Process dependencies updating the local schema properties as appropriate.
756
675
  for (const dependencyKey in dependencies) {
757
676
  // Skip this dependency if its trigger property is not present.
758
677
  if (get(formData, [dependencyKey]) === undefined) {
759
678
  continue;
760
- } // Skip this dependency if it is not included in the schema (such as when dependencyKey is itself a hidden dependency.)
761
-
762
-
679
+ }
680
+ // Skip this dependency if it is not included in the schema (such as when dependencyKey is itself a hidden dependency.)
763
681
  if (schema.properties && !(dependencyKey in schema.properties)) {
764
682
  continue;
765
683
  }
766
-
767
684
  const [remainingDependencies, dependencyValue] = splitKeyElementFromObject(dependencyKey, dependencies);
768
-
769
685
  if (Array.isArray(dependencyValue)) {
770
686
  schema = withDependentProperties(schema, dependencyValue);
771
687
  } else if (isObject(dependencyValue)) {
772
688
  schema = withDependentSchema(validator, schema, rootSchema, dependencyKey, dependencyValue, formData);
773
689
  }
774
-
775
690
  return processDependencies(validator, remainingDependencies, schema, rootSchema, formData);
776
691
  }
777
-
778
692
  return schema;
779
693
  }
780
694
  /** Updates a schema with additionally required properties added
@@ -783,20 +697,19 @@ function processDependencies(validator, dependencies, resolvedSchema, rootSchema
783
697
  * @param [additionallyRequired] - An optional array of additionally required names
784
698
  * @returns - The schema with the additional required values merged in
785
699
  */
786
-
787
700
  function withDependentProperties(schema, additionallyRequired) {
788
701
  if (!additionallyRequired) {
789
702
  return schema;
790
703
  }
791
-
792
704
  const required = Array.isArray(schema.required) ? Array.from(new Set([...schema.required, ...additionallyRequired])) : additionallyRequired;
793
- return { ...schema,
705
+ return {
706
+ ...schema,
794
707
  required: required
795
708
  };
796
709
  }
797
710
  /** Merges a dependent schema into the `schema` dealing with oneOfs and references
798
711
  *
799
- * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
712
+ * @param validator - An implementation of the `ValidatorType<T, S>` interface that will be forwarded to all the APIs
800
713
  * @param schema - The schema for which resolving a dependent schema is desired
801
714
  * @param rootSchema - The root schema that will be forwarded to all the APIs
802
715
  * @param dependencyKey - The key name of the dependency
@@ -804,49 +717,43 @@ function withDependentProperties(schema, additionallyRequired) {
804
717
  * @param formData- The current formData to assist retrieving a schema
805
718
  * @returns - The schema with the dependent schema resolved into it
806
719
  */
807
-
808
720
  function withDependentSchema(validator, schema, rootSchema, dependencyKey, dependencyValue, formData) {
809
721
  const {
810
722
  oneOf,
811
723
  ...dependentSchema
812
724
  } = retrieveSchema(validator, dependencyValue, rootSchema, formData);
813
- schema = mergeSchemas(schema, dependentSchema); // Since it does not contain oneOf, we return the original schema.
814
-
725
+ schema = mergeSchemas(schema, dependentSchema);
726
+ // Since it does not contain oneOf, we return the original schema.
815
727
  if (oneOf === undefined) {
816
728
  return schema;
817
- } // Resolve $refs inside oneOf.
818
-
819
-
729
+ }
730
+ // Resolve $refs inside oneOf.
820
731
  const resolvedOneOf = oneOf.map(subschema => {
821
732
  if (typeof subschema === "boolean" || !(REF_KEY in subschema)) {
822
733
  return subschema;
823
734
  }
824
-
825
735
  return resolveReference(validator, subschema, rootSchema, formData);
826
736
  });
827
737
  return withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, resolvedOneOf, formData);
828
738
  }
829
739
  /** Returns a `schema` with the best choice from the `oneOf` options merged into it
830
740
  *
831
- * @param validator - An implementation of the `ValidatorType` interface that will be used to validate oneOf options
741
+ * @param validator - An implementation of the `ValidatorType<T, S>` interface that will be used to validate oneOf options
832
742
  * @param schema - The schema for which resolving a oneOf subschema is desired
833
743
  * @param rootSchema - The root schema that will be forwarded to all the APIs
834
744
  * @param dependencyKey - The key name of the oneOf dependency
835
745
  * @param oneOf - The list of schemas representing the oneOf options
836
746
  * @param [formData] - The current formData to assist retrieving a schema
837
- * @returns The schema with best choice of oneOf schemas merged into
747
+ * @returns The schema with the best choice of oneOf schemas merged into
838
748
  */
839
-
840
749
  function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, oneOf, formData) {
841
750
  const validSubschemas = oneOf.filter(subschema => {
842
- if (typeof subschema === "boolean" || !subschema.properties) {
751
+ if (typeof subschema === "boolean" || !subschema || !subschema.properties) {
843
752
  return false;
844
753
  }
845
-
846
754
  const {
847
755
  [dependencyKey]: conditionPropertySchema
848
756
  } = subschema.properties;
849
-
850
757
  if (conditionPropertySchema) {
851
758
  const conditionSchema = {
852
759
  type: "object",
@@ -859,18 +766,16 @@ function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, o
859
766
  } = validator.validateFormData(formData, conditionSchema);
860
767
  return errors.length === 0;
861
768
  }
862
-
863
769
  return false;
864
770
  });
865
-
866
771
  if (validSubschemas.length !== 1) {
867
772
  console.warn("ignoring oneOf in dependencies because there isn't exactly one subschema that is valid");
868
773
  return schema;
869
774
  }
870
-
871
775
  const subschema = validSubschemas[0];
872
776
  const [dependentSubschema] = splitKeyElementFromObject(dependencyKey, subschema.properties);
873
- const dependentSchema = { ...subschema,
777
+ const dependentSchema = {
778
+ ...subschema,
874
779
  properties: dependentSubschema
875
780
  };
876
781
  return mergeSchemas(schema, retrieveSchema(validator, dependentSchema, rootSchema, formData));
@@ -883,23 +788,18 @@ function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, o
883
788
  * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
884
789
  * @returns - True if schema contains a select, otherwise false
885
790
  */
886
-
887
791
  function isSelect(validator, theSchema, rootSchema) {
888
792
  if (rootSchema === void 0) {
889
793
  rootSchema = {};
890
794
  }
891
-
892
795
  const schema = retrieveSchema(validator, theSchema, rootSchema, undefined);
893
796
  const altSchemas = schema.oneOf || schema.anyOf;
894
-
895
797
  if (Array.isArray(schema.enum)) {
896
798
  return true;
897
799
  }
898
-
899
800
  if (Array.isArray(altSchemas)) {
900
801
  return altSchemas.every(altSchemas => typeof altSchemas !== "boolean" && isConstant(altSchemas));
901
802
  }
902
-
903
803
  return false;
904
804
  }
905
805
 
@@ -910,20 +810,16 @@ function isSelect(validator, theSchema, rootSchema) {
910
810
  * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
911
811
  * @returns - True if schema contains a multi-select, otherwise false
912
812
  */
913
-
914
813
  function isMultiSelect(validator, schema, rootSchema) {
915
814
  if (!schema.uniqueItems || !schema.items || typeof schema.items === "boolean") {
916
815
  return false;
917
816
  }
918
-
919
817
  return isSelect(validator, schema.items, rootSchema);
920
818
  }
921
819
 
922
820
  /** Enum that indicates how `schema.additionalItems` should be handled by the `getInnerSchemaForArrayItem()` function.
923
821
  */
924
-
925
822
  var AdditionalItemsHandling;
926
-
927
823
  (function (AdditionalItemsHandling) {
928
824
  AdditionalItemsHandling[AdditionalItemsHandling["Ignore"] = 0] = "Ignore";
929
825
  AdditionalItemsHandling[AdditionalItemsHandling["Invert"] = 1] = "Invert";
@@ -944,21 +840,16 @@ var AdditionalItemsHandling;
944
840
  * @param [idx=-1] - Index, if non-negative, will be used to return the idx-th element in a `schema.items` array
945
841
  * @returns - The best fit schema object from the `schema` given the `additionalItems` and `idx` modifiers
946
842
  */
947
-
948
-
949
843
  function getInnerSchemaForArrayItem(schema, additionalItems, idx) {
950
844
  if (additionalItems === void 0) {
951
845
  additionalItems = AdditionalItemsHandling.Ignore;
952
846
  }
953
-
954
847
  if (idx === void 0) {
955
848
  idx = -1;
956
849
  }
957
-
958
850
  if (idx >= 0) {
959
851
  if (Array.isArray(schema.items) && idx < schema.items.length) {
960
852
  const item = schema.items[idx];
961
-
962
853
  if (typeof item !== "boolean") {
963
854
  return item;
964
855
  }
@@ -966,11 +857,9 @@ function getInnerSchemaForArrayItem(schema, additionalItems, idx) {
966
857
  } else if (schema.items && !Array.isArray(schema.items) && typeof schema.items !== "boolean") {
967
858
  return schema.items;
968
859
  }
969
-
970
860
  if (additionalItems !== AdditionalItemsHandling.Ignore && isObject(schema.additionalItems)) {
971
861
  return schema.additionalItems;
972
862
  }
973
-
974
863
  return {};
975
864
  }
976
865
  /** Computes the defaults for the current `schema` given the `rawFormData` and `parentDefaults` if any. This drills into
@@ -984,20 +873,16 @@ function getInnerSchemaForArrayItem(schema, additionalItems, idx) {
984
873
  * @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults
985
874
  * @returns - The resulting `formData` with all the defaults provided
986
875
  */
987
-
988
876
  function computeDefaults(validator, schema, parentDefaults, rootSchema, rawFormData, includeUndefinedValues) {
989
877
  if (rootSchema === void 0) {
990
878
  rootSchema = {};
991
879
  }
992
-
993
880
  if (includeUndefinedValues === void 0) {
994
881
  includeUndefinedValues = false;
995
882
  }
996
-
997
- const formData = isObject(rawFormData) ? rawFormData : {}; // Compute the defaults recursively: give highest priority to deepest nodes.
998
-
883
+ const formData = isObject(rawFormData) ? rawFormData : {};
884
+ // Compute the defaults recursively: give highest priority to deepest nodes.
999
885
  let defaults = parentDefaults;
1000
-
1001
886
  if (isObject(defaults) && isObject(schema.default)) {
1002
887
  // For object defaults, only override parent defaults that are defined in
1003
888
  // schema.default.
@@ -1017,13 +902,11 @@ function computeDefaults(validator, schema, parentDefaults, rootSchema, rawFormD
1017
902
  schema = schema.oneOf[getMatchingOption(validator, isEmpty(formData) ? undefined : formData, schema.oneOf, rootSchema)];
1018
903
  } else if (ANY_OF_KEY in schema) {
1019
904
  schema = schema.anyOf[getMatchingOption(validator, isEmpty(formData) ? undefined : formData, schema.anyOf, rootSchema)];
1020
- } // Not defaults defined for this node, fallback to generic typed ones.
1021
-
1022
-
905
+ }
906
+ // Not defaults defined for this node, fallback to generic typed ones.
1023
907
  if (typeof defaults === "undefined") {
1024
908
  defaults = schema.default;
1025
909
  }
1026
-
1027
910
  switch (getSchemaType(schema)) {
1028
911
  // We need to recur for object schema inner default values.
1029
912
  case "object":
@@ -1031,14 +914,11 @@ function computeDefaults(validator, schema, parentDefaults, rootSchema, rawFormD
1031
914
  // Compute the defaults for this node, with the parent defaults we might
1032
915
  // have from a previous run: defaults[key].
1033
916
  const computedDefault = computeDefaults(validator, get(schema, [PROPERTIES_KEY, key]), get(defaults, [key]), rootSchema, get(formData, [key]), includeUndefinedValues);
1034
-
1035
917
  if (includeUndefinedValues || computedDefault !== undefined) {
1036
918
  acc[key] = computedDefault;
1037
919
  }
1038
-
1039
920
  return acc;
1040
921
  }, {});
1041
-
1042
922
  case "array":
1043
923
  // Inject defaults into existing array defaults
1044
924
  if (Array.isArray(defaults)) {
@@ -1046,36 +926,30 @@ function computeDefaults(validator, schema, parentDefaults, rootSchema, rawFormD
1046
926
  const schemaItem = getInnerSchemaForArrayItem(schema, AdditionalItemsHandling.Fallback, idx);
1047
927
  return computeDefaults(validator, schemaItem, item, rootSchema);
1048
928
  });
1049
- } // Deeply inject defaults into already existing form data
1050
-
1051
-
929
+ }
930
+ // Deeply inject defaults into already existing form data
1052
931
  if (Array.isArray(rawFormData)) {
1053
932
  const schemaItem = getInnerSchemaForArrayItem(schema);
1054
933
  defaults = rawFormData.map((item, idx) => {
1055
934
  return computeDefaults(validator, schemaItem, get(defaults, [idx]), rootSchema, item);
1056
935
  });
1057
936
  }
1058
-
1059
937
  if (schema.minItems) {
1060
938
  if (!isMultiSelect(validator, schema, rootSchema)) {
1061
939
  const defaultsLength = Array.isArray(defaults) ? defaults.length : 0;
1062
-
1063
940
  if (schema.minItems > defaultsLength) {
1064
- const defaultEntries = defaults || []; // populate the array with the defaults
1065
-
941
+ const defaultEntries = defaults || [];
942
+ // populate the array with the defaults
1066
943
  const fillerSchema = getInnerSchemaForArrayItem(schema, AdditionalItemsHandling.Invert);
1067
944
  const fillerDefault = fillerSchema.default;
1068
- 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
1069
-
945
+ const fillerEntries = new Array(schema.minItems - defaultsLength).fill(computeDefaults(validator, fillerSchema, fillerDefault, rootSchema));
946
+ // then fill up the rest with either the item default or empty, up to minItems
1070
947
  return defaultEntries.concat(fillerEntries);
1071
948
  }
1072
949
  }
1073
-
1074
950
  return defaults ? defaults : [];
1075
951
  }
1076
-
1077
952
  }
1078
-
1079
953
  return defaults;
1080
954
  }
1081
955
  /** Returns the superset of `formData` that includes the given set updated to include any missing fields that have
@@ -1088,32 +962,25 @@ function computeDefaults(validator, schema, parentDefaults, rootSchema, rawFormD
1088
962
  * @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults
1089
963
  * @returns - The resulting `formData` with all the defaults provided
1090
964
  */
1091
-
1092
965
  function getDefaultFormState(validator, theSchema, formData, rootSchema, includeUndefinedValues) {
1093
966
  if (includeUndefinedValues === void 0) {
1094
967
  includeUndefinedValues = false;
1095
968
  }
1096
-
1097
969
  if (!isObject(theSchema)) {
1098
970
  throw new Error("Invalid schema: " + theSchema);
1099
971
  }
1100
-
1101
972
  const schema = retrieveSchema(validator, theSchema, rootSchema, formData);
1102
973
  const defaults = computeDefaults(validator, schema, undefined, rootSchema, formData, includeUndefinedValues);
1103
-
1104
974
  if (typeof formData === "undefined" || formData === null || typeof formData === "number" && isNaN(formData)) {
1105
975
  // No form data? Use schema defaults.
1106
976
  return defaults;
1107
977
  }
1108
-
1109
978
  if (isObject(formData)) {
1110
979
  return mergeDefaultsWithFormData(defaults, formData);
1111
980
  }
1112
-
1113
981
  if (Array.isArray(formData)) {
1114
982
  return mergeDefaultsWithFormData(defaults, formData);
1115
983
  }
1116
-
1117
984
  return formData;
1118
985
  }
1119
986
 
@@ -1122,13 +989,12 @@ function getDefaultFormState(validator, theSchema, formData, rootSchema, include
1122
989
  * @param uiSchema - The UI Schema from which to detect if it is customized
1123
990
  * @returns - True if the `uiSchema` describes a custom widget, false otherwise
1124
991
  */
1125
-
1126
992
  function isCustomWidget(uiSchema) {
1127
993
  if (uiSchema === void 0) {
1128
994
  uiSchema = {};
1129
995
  }
1130
-
1131
- return (// TODO: Remove the `&& uiSchema['ui:widget'] !== 'hidden'` once we support hidden widgets for arrays.
996
+ return (
997
+ // TODO: Remove the `&& uiSchema['ui:widget'] !== 'hidden'` once we support hidden widgets for arrays.
1132
998
  // https://react-jsonschema-form.readthedocs.io/en/latest/usage/widgets/#hidden-widgets
1133
999
  "widget" in getUiOptions(uiSchema) && getUiOptions(uiSchema)["widget"] !== "hidden"
1134
1000
  );
@@ -1142,21 +1008,17 @@ function isCustomWidget(uiSchema) {
1142
1008
  * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
1143
1009
  * @returns - True if schema/uiSchema contains an array of files, otherwise false
1144
1010
  */
1145
-
1146
1011
  function isFilesArray(validator, schema, uiSchema, rootSchema) {
1147
1012
  if (uiSchema === void 0) {
1148
1013
  uiSchema = {};
1149
1014
  }
1150
-
1151
1015
  if (uiSchema[UI_WIDGET_KEY] === "files") {
1152
1016
  return true;
1153
1017
  }
1154
-
1155
1018
  if (schema.items) {
1156
1019
  const itemsSchema = retrieveSchema(validator, schema.items, rootSchema);
1157
1020
  return itemsSchema.type === "string" && itemsSchema.format === "data-url";
1158
1021
  }
1159
-
1160
1022
  return false;
1161
1023
  }
1162
1024
 
@@ -1169,35 +1031,28 @@ function isFilesArray(validator, schema, uiSchema, rootSchema) {
1169
1031
  * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
1170
1032
  * @returns - True if the label should be displayed or false if it should not
1171
1033
  */
1172
-
1173
1034
  function getDisplayLabel(validator, schema, uiSchema, rootSchema) {
1174
1035
  if (uiSchema === void 0) {
1175
1036
  uiSchema = {};
1176
1037
  }
1177
-
1178
1038
  const uiOptions = getUiOptions(uiSchema);
1179
1039
  const {
1180
1040
  label = true
1181
1041
  } = uiOptions;
1182
1042
  let displayLabel = !!label;
1183
1043
  const schemaType = getSchemaType(schema);
1184
-
1185
1044
  if (schemaType === "array") {
1186
1045
  displayLabel = isMultiSelect(validator, schema, rootSchema) || isFilesArray(validator, schema, uiSchema, rootSchema) || isCustomWidget(uiSchema);
1187
1046
  }
1188
-
1189
1047
  if (schemaType === "object") {
1190
1048
  displayLabel = false;
1191
1049
  }
1192
-
1193
1050
  if (schemaType === "boolean" && !uiSchema[UI_WIDGET_KEY]) {
1194
1051
  displayLabel = false;
1195
1052
  }
1196
-
1197
1053
  if (uiSchema[UI_FIELD_KEY]) {
1198
1054
  displayLabel = false;
1199
1055
  }
1200
-
1201
1056
  return displayLabel;
1202
1057
  }
1203
1058
 
@@ -1211,24 +1066,20 @@ function getDisplayLabel(validator, schema, uiSchema, rootSchema) {
1211
1066
  * @param [additionalErrorSchema] - The additional set of errors in an `ErrorSchema`
1212
1067
  * @returns - The `validationData` with the additional errors from `additionalErrorSchema` merged into it, if provided.
1213
1068
  */
1214
-
1215
1069
  function mergeValidationData(validator, validationData, additionalErrorSchema) {
1216
1070
  if (!additionalErrorSchema) {
1217
1071
  return validationData;
1218
1072
  }
1219
-
1220
1073
  const {
1221
1074
  errors: oldErrors,
1222
1075
  errorSchema: oldErrorSchema
1223
1076
  } = validationData;
1224
1077
  let errors = validator.toErrorList(additionalErrorSchema);
1225
1078
  let errorSchema = additionalErrorSchema;
1226
-
1227
1079
  if (!isEmpty(oldErrorSchema)) {
1228
1080
  errorSchema = mergeObjects(oldErrorSchema, additionalErrorSchema, true);
1229
1081
  errors = [...oldErrors].concat(errors);
1230
1082
  }
1231
-
1232
1083
  return {
1233
1084
  errorSchema,
1234
1085
  errors
@@ -1246,41 +1097,34 @@ function mergeValidationData(validator, validationData, additionalErrorSchema) {
1246
1097
  * @param [idSeparator='_'] - The separator to use for the path segments in the id
1247
1098
  * @returns - The `IdSchema` object for the `schema`
1248
1099
  */
1249
-
1250
1100
  function toIdSchema(validator, schema, id, rootSchema, formData, idPrefix, idSeparator) {
1251
1101
  if (idPrefix === void 0) {
1252
1102
  idPrefix = "root";
1253
1103
  }
1254
-
1255
1104
  if (idSeparator === void 0) {
1256
1105
  idSeparator = "_";
1257
1106
  }
1258
-
1259
1107
  if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
1260
1108
  const _schema = retrieveSchema(validator, schema, rootSchema, formData);
1261
-
1262
1109
  return toIdSchema(validator, _schema, id, rootSchema, formData, idPrefix, idSeparator);
1263
1110
  }
1264
-
1265
1111
  if (ITEMS_KEY in schema && !get(schema, [ITEMS_KEY, REF_KEY])) {
1266
1112
  return toIdSchema(validator, get(schema, ITEMS_KEY), id, rootSchema, formData, idPrefix, idSeparator);
1267
1113
  }
1268
-
1269
1114
  const $id = id || idPrefix;
1270
1115
  const idSchema = {
1271
1116
  $id
1272
1117
  };
1273
-
1274
1118
  if (schema.type === "object" && PROPERTIES_KEY in schema) {
1275
1119
  for (const name in schema.properties) {
1276
1120
  const field = get(schema, [PROPERTIES_KEY, name]);
1277
1121
  const fieldId = idSchema[ID_KEY] + idSeparator + name;
1278
- idSchema[name] = toIdSchema(validator, isObject(field) ? field : {}, fieldId, rootSchema, // It's possible that formData is not an object -- this can happen if an
1122
+ idSchema[name] = toIdSchema(validator, isObject(field) ? field : {}, fieldId, rootSchema,
1123
+ // It's possible that formData is not an object -- this can happen if an
1279
1124
  // array item has just been added, but not populated with data yet
1280
1125
  get(formData, [name]), idPrefix, idSeparator);
1281
1126
  }
1282
1127
  }
1283
-
1284
1128
  return idSchema;
1285
1129
  }
1286
1130
 
@@ -1293,39 +1137,33 @@ function toIdSchema(validator, schema, id, rootSchema, formData, idPrefix, idSep
1293
1137
  * @param [formData] - The current formData, if any, to assist retrieving a schema
1294
1138
  * @returns - The `PathSchema` object for the `schema`
1295
1139
  */
1296
-
1297
1140
  function toPathSchema(validator, schema, name, rootSchema, formData) {
1298
1141
  if (name === void 0) {
1299
1142
  name = "";
1300
1143
  }
1301
-
1302
1144
  if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
1303
1145
  const _schema = retrieveSchema(validator, schema, rootSchema, formData);
1304
-
1305
1146
  return toPathSchema(validator, _schema, name, rootSchema, formData);
1306
1147
  }
1307
-
1308
1148
  const pathSchema = {
1309
1149
  [NAME_KEY]: name.replace(/^\./, "")
1310
1150
  };
1311
-
1312
1151
  if (ADDITIONAL_PROPERTIES_KEY in schema && schema[ADDITIONAL_PROPERTIES_KEY] === true) {
1313
1152
  set(pathSchema, RJSF_ADDITONAL_PROPERTIES_FLAG, true);
1314
1153
  }
1315
-
1316
1154
  if (ITEMS_KEY in schema && Array.isArray(formData)) {
1317
1155
  formData.forEach((element, i) => {
1318
- pathSchema[i] = toPathSchema(validator, schema.items, name + "." + i, rootSchema, element);
1156
+ pathSchema[i] = toPathSchema(validator, schema.items, `${name}.${i}`, rootSchema, element);
1319
1157
  });
1320
1158
  } else if (PROPERTIES_KEY in schema) {
1321
1159
  for (const property in schema.properties) {
1322
1160
  const field = get(schema, [PROPERTIES_KEY, property]);
1323
- pathSchema[property] = toPathSchema(validator, field, name + "." + property, rootSchema, // It's possible that formData is not an object -- this can happen if an
1161
+ pathSchema[property] = toPathSchema(validator, field, `${name}.${property}`, rootSchema,
1162
+ // It's possible that formData is not an object -- this can happen if an
1324
1163
  // array item has just been added, but not populated with data yet
1325
1164
  get(formData, [property]));
1326
1165
  }
1327
1166
  }
1328
-
1329
1167
  return pathSchema;
1330
1168
  }
1331
1169
 
@@ -1334,7 +1172,6 @@ function toPathSchema(validator, schema, name, rootSchema, formData) {
1334
1172
  * and `rootSchema` generally does not change across a `Form`, this allows for providing a simplified set of APIs to the
1335
1173
  * `@rjsf/core` components and the various themes as well. This class implements the `SchemaUtilsType` interface.
1336
1174
  */
1337
-
1338
1175
  class SchemaUtils {
1339
1176
  /** Constructs the `SchemaUtils` instance with the given `validator` and `rootSchema` stored as instance variables
1340
1177
  *
@@ -1351,8 +1188,6 @@ class SchemaUtils {
1351
1188
  *
1352
1189
  * @returns - The `ValidatorType`
1353
1190
  */
1354
-
1355
-
1356
1191
  getValidator() {
1357
1192
  return this.validator;
1358
1193
  }
@@ -1364,13 +1199,10 @@ class SchemaUtils {
1364
1199
  * @param rootSchema - The root schema that will be compared against the current one
1365
1200
  * @returns - True if the `SchemaUtilsType` differs from the given `validator` or `rootSchema`
1366
1201
  */
1367
-
1368
-
1369
1202
  doesSchemaUtilsDiffer(validator, rootSchema) {
1370
1203
  if (!validator || !rootSchema) {
1371
1204
  return false;
1372
1205
  }
1373
-
1374
1206
  return this.validator !== validator || !deepEquals(this.rootSchema, rootSchema);
1375
1207
  }
1376
1208
  /** Returns the superset of `formData` that includes the given set updated to include any missing fields that have
@@ -1381,13 +1213,10 @@ class SchemaUtils {
1381
1213
  * @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults
1382
1214
  * @returns - The resulting `formData` with all the defaults provided
1383
1215
  */
1384
-
1385
-
1386
1216
  getDefaultFormState(schema, formData, includeUndefinedValues) {
1387
1217
  if (includeUndefinedValues === void 0) {
1388
1218
  includeUndefinedValues = false;
1389
1219
  }
1390
-
1391
1220
  return getDefaultFormState(this.validator, schema, formData, this.rootSchema, includeUndefinedValues);
1392
1221
  }
1393
1222
  /** Determines whether the combination of `schema` and `uiSchema` properties indicates that the label for the `schema`
@@ -1397,8 +1226,6 @@ class SchemaUtils {
1397
1226
  * @param [uiSchema] - The UI schema from which to derive potentially displayable information
1398
1227
  * @returns - True if the label should be displayed or false if it should not
1399
1228
  */
1400
-
1401
-
1402
1229
  getDisplayLabel(schema, uiSchema) {
1403
1230
  return getDisplayLabel(this.validator, schema, uiSchema, this.rootSchema);
1404
1231
  }
@@ -1408,8 +1235,6 @@ class SchemaUtils {
1408
1235
  * @param options - The list of options to find a matching options from
1409
1236
  * @returns - The index of the matched option or 0 if none is available
1410
1237
  */
1411
-
1412
-
1413
1238
  getMatchingOption(formData, options) {
1414
1239
  return getMatchingOption(this.validator, formData, options, this.rootSchema);
1415
1240
  }
@@ -1419,8 +1244,6 @@ class SchemaUtils {
1419
1244
  * @param [uiSchema] - The UI schema from which to check the widget
1420
1245
  * @returns - True if schema/uiSchema contains an array of files, otherwise false
1421
1246
  */
1422
-
1423
-
1424
1247
  isFilesArray(schema, uiSchema) {
1425
1248
  return isFilesArray(this.validator, schema, uiSchema, this.rootSchema);
1426
1249
  }
@@ -1429,8 +1252,6 @@ class SchemaUtils {
1429
1252
  * @param schema - The schema for which check for a multi-select flag is desired
1430
1253
  * @returns - True if schema contains a multi-select, otherwise false
1431
1254
  */
1432
-
1433
-
1434
1255
  isMultiSelect(schema) {
1435
1256
  return isMultiSelect(this.validator, schema, this.rootSchema);
1436
1257
  }
@@ -1439,8 +1260,6 @@ class SchemaUtils {
1439
1260
  * @param schema - The schema for which check for a select flag is desired
1440
1261
  * @returns - True if schema contains a select, otherwise false
1441
1262
  */
1442
-
1443
-
1444
1263
  isSelect(schema) {
1445
1264
  return isSelect(this.validator, schema, this.rootSchema);
1446
1265
  }
@@ -1453,8 +1272,6 @@ class SchemaUtils {
1453
1272
  * @param [additionalErrorSchema] - The additional set of errors
1454
1273
  * @returns - The `validationData` with the additional errors from `additionalErrorSchema` merged into it, if provided.
1455
1274
  */
1456
-
1457
-
1458
1275
  mergeValidationData(validationData, additionalErrorSchema) {
1459
1276
  return mergeValidationData(this.validator, validationData, additionalErrorSchema);
1460
1277
  }
@@ -1466,8 +1283,6 @@ class SchemaUtils {
1466
1283
  * @param [rawFormData] - The current formData, if any, to assist retrieving a schema
1467
1284
  * @returns - The schema having its conditions, additional properties, references and dependencies resolved
1468
1285
  */
1469
-
1470
-
1471
1286
  retrieveSchema(schema, rawFormData) {
1472
1287
  return retrieveSchema(this.validator, schema, this.rootSchema, rawFormData);
1473
1288
  }
@@ -1480,17 +1295,13 @@ class SchemaUtils {
1480
1295
  * @param [idSeparator='_'] - The separator to use for the path segments in the id
1481
1296
  * @returns - The `IdSchema` object for the `schema`
1482
1297
  */
1483
-
1484
-
1485
1298
  toIdSchema(schema, id, formData, idPrefix, idSeparator) {
1486
1299
  if (idPrefix === void 0) {
1487
1300
  idPrefix = "root";
1488
1301
  }
1489
-
1490
1302
  if (idSeparator === void 0) {
1491
1303
  idSeparator = "_";
1492
1304
  }
1493
-
1494
1305
  return toIdSchema(this.validator, schema, id, this.rootSchema, formData, idPrefix, idSeparator);
1495
1306
  }
1496
1307
  /** Generates an `PathSchema` object for the `schema`, recursively
@@ -1500,12 +1311,9 @@ class SchemaUtils {
1500
1311
  * @param [formData] - The current formData, if any, onto which to provide any missing defaults
1501
1312
  * @returns - The `PathSchema` object for the `schema`
1502
1313
  */
1503
-
1504
-
1505
1314
  toPathSchema(schema, name, formData) {
1506
1315
  return toPathSchema(this.validator, schema, name, this.rootSchema, formData);
1507
1316
  }
1508
-
1509
1317
  }
1510
1318
  /** Creates a `SchemaUtilsType` interface that is based around the given `validator` and `rootSchema` parameters. The
1511
1319
  * resulting interface implementation will forward the `validator` and `rootSchema` to all the wrapped APIs.
@@ -1514,8 +1322,6 @@ class SchemaUtils {
1514
1322
  * @param rootSchema - The root schema that will be forwarded to all the APIs
1515
1323
  * @returns - An implementation of a `SchemaUtilsType` interface
1516
1324
  */
1517
-
1518
-
1519
1325
  function createSchemaUtils(validator, rootSchema) {
1520
1326
  return new SchemaUtils(validator, rootSchema);
1521
1327
  }
@@ -1528,35 +1334,31 @@ function createSchemaUtils(validator, rootSchema) {
1528
1334
  */
1529
1335
  function dataURItoBlob(dataURI) {
1530
1336
  // Split metadata from data
1531
- const splitted = dataURI.split(","); // Split params
1532
-
1533
- const params = splitted[0].split(";"); // Get mime-type from params
1534
-
1535
- const type = params[0].replace("data:", ""); // Filter the name property from params
1536
-
1337
+ const splitted = dataURI.split(",");
1338
+ // Split params
1339
+ const params = splitted[0].split(";");
1340
+ // Get mime-type from params
1341
+ const type = params[0].replace("data:", "");
1342
+ // Filter the name property from params
1537
1343
  const properties = params.filter(param => {
1538
1344
  return param.split("=")[0] === "name";
1539
- }); // Look for the name and use unknown if no name property.
1540
-
1345
+ });
1346
+ // Look for the name and use unknown if no name property.
1541
1347
  let name;
1542
-
1543
1348
  if (properties.length !== 1) {
1544
1349
  name = "unknown";
1545
1350
  } else {
1546
1351
  // Because we filtered out the other property,
1547
1352
  // we only have the name case here.
1548
1353
  name = properties[0].split("=")[1];
1549
- } // Built the Uint8Array Blob parameter from the base64 string.
1550
-
1551
-
1354
+ }
1355
+ // Built the Uint8Array Blob parameter from the base64 string.
1552
1356
  const binary = atob(splitted[1]);
1553
1357
  const array = [];
1554
-
1555
1358
  for (let i = 0; i < binary.length; i++) {
1556
1359
  array.push(binary.charCodeAt(i));
1557
- } // Create the blob object
1558
-
1559
-
1360
+ }
1361
+ // Create the blob object
1560
1362
  const blob = new window.Blob([new Uint8Array(array)], {
1561
1363
  type
1562
1364
  });
@@ -1574,19 +1376,15 @@ function dataURItoBlob(dataURI) {
1574
1376
  */
1575
1377
  function rangeSpec(schema) {
1576
1378
  const spec = {};
1577
-
1578
1379
  if (schema.multipleOf) {
1579
1380
  spec.step = schema.multipleOf;
1580
1381
  }
1581
-
1582
1382
  if (schema.minimum || schema.minimum === 0) {
1583
1383
  spec.min = schema.minimum;
1584
1384
  }
1585
-
1586
1385
  if (schema.maximum || schema.maximum === 0) {
1587
1386
  spec.max = schema.maximum;
1588
1387
  }
1589
-
1590
1388
  return spec;
1591
1389
  }
1592
1390
 
@@ -1598,53 +1396,47 @@ function rangeSpec(schema) {
1598
1396
  * @param [autoDefaultStepAny=true] - Determines whether to auto-default step=any when the type is number and no step
1599
1397
  * @returns - The extracted `InputPropsType` object
1600
1398
  */
1601
-
1602
1399
  function getInputProps(schema, defaultType, options, autoDefaultStepAny) {
1603
1400
  if (options === void 0) {
1604
1401
  options = {};
1605
1402
  }
1606
-
1607
1403
  if (autoDefaultStepAny === void 0) {
1608
1404
  autoDefaultStepAny = true;
1609
1405
  }
1610
-
1611
1406
  const inputProps = {
1612
1407
  type: defaultType || "text",
1613
1408
  ...rangeSpec(schema)
1614
- }; // If options.inputType is set use that as the input type
1615
-
1409
+ };
1410
+ // If options.inputType is set use that as the input type
1616
1411
  if (options.inputType) {
1617
1412
  inputProps.type = options.inputType;
1618
1413
  } else if (!defaultType) {
1619
1414
  // If the schema is of type number or integer, set the input type to number
1620
1415
  if (schema.type === "number") {
1621
- inputProps.type = "number"; // Only add step if one isn't already defined and we are auto-defaulting the "any" step
1622
-
1416
+ inputProps.type = "number";
1417
+ // Only add step if one isn't already defined and we are auto-defaulting the "any" step
1623
1418
  if (autoDefaultStepAny && inputProps.step === undefined) {
1624
1419
  // Setting step to 'any' fixes a bug in Safari where decimals are not
1625
1420
  // allowed in number inputs
1626
1421
  inputProps.step = "any";
1627
1422
  }
1628
1423
  } else if (schema.type === "integer") {
1629
- inputProps.type = "number"; // Only add step if one isn't already defined
1630
-
1424
+ inputProps.type = "number";
1425
+ // Only add step if one isn't already defined
1631
1426
  if (inputProps.step === undefined) {
1632
1427
  // Since this is integer, you always want to step up or down in multiples of 1
1633
1428
  inputProps.step = 1;
1634
1429
  }
1635
1430
  }
1636
1431
  }
1637
-
1638
1432
  if (options.autocomplete) {
1639
1433
  inputProps.autoComplete = options.autocomplete;
1640
1434
  }
1641
-
1642
1435
  return inputProps;
1643
1436
  }
1644
1437
 
1645
1438
  /** The default submit button options, exported for testing purposes
1646
1439
  */
1647
-
1648
1440
  const DEFAULT_OPTIONS = {
1649
1441
  props: {
1650
1442
  disabled: false
@@ -1657,21 +1449,18 @@ const DEFAULT_OPTIONS = {
1657
1449
  * @param [uiSchema={}] - the UI Schema from which to extract submit button props
1658
1450
  * @returns - The merging of the `DEFAULT_OPTIONS` with any custom ones
1659
1451
  */
1660
-
1661
1452
  function getSubmitButtonOptions(uiSchema) {
1662
1453
  if (uiSchema === void 0) {
1663
1454
  uiSchema = {};
1664
1455
  }
1665
-
1666
1456
  const uiOptions = getUiOptions(uiSchema);
1667
-
1668
1457
  if (uiOptions && uiOptions[SUBMIT_BTN_OPTIONS_KEY]) {
1669
1458
  const options = uiOptions[SUBMIT_BTN_OPTIONS_KEY];
1670
- return { ...DEFAULT_OPTIONS,
1459
+ return {
1460
+ ...DEFAULT_OPTIONS,
1671
1461
  ...options
1672
1462
  };
1673
1463
  }
1674
-
1675
1464
  return DEFAULT_OPTIONS;
1676
1465
  }
1677
1466
 
@@ -1687,16 +1476,14 @@ function getTemplate(name, registry, uiOptions) {
1687
1476
  if (uiOptions === void 0) {
1688
1477
  uiOptions = {};
1689
1478
  }
1690
-
1691
1479
  const {
1692
1480
  templates
1693
1481
  } = registry;
1694
-
1695
1482
  if (name === "ButtonTemplates") {
1696
1483
  return templates[name];
1697
1484
  }
1698
-
1699
- return (// Evaluating uiOptions[name] results in TS2590: Expression produces a union type that is too complex to represent
1485
+ return (
1486
+ // Evaluating uiOptions[name] results in TS2590: Expression produces a union type that is too complex to represent
1700
1487
  // To avoid that, we cast uiOptions to `any` before accessing the name field
1701
1488
  uiOptions[name] || templates[name]
1702
1489
  );
@@ -1704,7 +1491,6 @@ function getTemplate(name, registry, uiOptions) {
1704
1491
 
1705
1492
  /** The map of schema types to widget type to widget name
1706
1493
  */
1707
-
1708
1494
  const widgetMap = {
1709
1495
  boolean: {
1710
1496
  checkbox: "CheckboxWidget",
@@ -1763,29 +1549,26 @@ const widgetMap = {
1763
1549
  * @param AWidget - A widget that will be wrapped or one that is already wrapped
1764
1550
  * @returns - The wrapper widget
1765
1551
  */
1766
-
1767
1552
  function mergeWidgetOptions(AWidget) {
1768
- let MergedWidget = get(AWidget, "MergedWidget"); // cache return value as property of widget for proper react reconciliation
1769
-
1553
+ let MergedWidget = get(AWidget, "MergedWidget");
1554
+ // cache return value as property of widget for proper react reconciliation
1770
1555
  if (!MergedWidget) {
1771
1556
  const defaultOptions = AWidget.defaultProps && AWidget.defaultProps.options || {};
1772
-
1773
1557
  MergedWidget = _ref => {
1774
1558
  let {
1775
1559
  options,
1776
1560
  ...props
1777
1561
  } = _ref;
1778
1562
  return /*#__PURE__*/React.createElement(AWidget, {
1779
- options: { ...defaultOptions,
1563
+ options: {
1564
+ ...defaultOptions,
1780
1565
  ...options
1781
1566
  },
1782
1567
  ...props
1783
1568
  });
1784
1569
  };
1785
-
1786
1570
  set(AWidget, "MergedWidget", MergedWidget);
1787
1571
  }
1788
-
1789
1572
  return MergedWidget;
1790
1573
  }
1791
1574
  /** Given a schema representing a field to render and either the name or actual `Widget` implementation, returns the
@@ -1799,40 +1582,31 @@ function mergeWidgetOptions(AWidget) {
1799
1582
  * @returns - The `Widget` component to use
1800
1583
  * @throws - An error if there is no `Widget` component that can be returned
1801
1584
  */
1802
-
1803
-
1804
1585
  function getWidget(schema, widget, registeredWidgets) {
1805
1586
  if (registeredWidgets === void 0) {
1806
1587
  registeredWidgets = {};
1807
1588
  }
1808
-
1809
1589
  const type = getSchemaType(schema);
1810
-
1811
1590
  if (typeof widget === "function" || widget && ReactIs.isForwardRef( /*#__PURE__*/React.createElement(widget)) || ReactIs.isMemo(widget)) {
1812
1591
  return mergeWidgetOptions(widget);
1813
1592
  }
1814
-
1815
1593
  if (typeof widget !== "string") {
1816
- throw new Error("Unsupported widget definition: " + typeof widget);
1594
+ throw new Error(`Unsupported widget definition: ${typeof widget}`);
1817
1595
  }
1818
-
1819
1596
  if (widget in registeredWidgets) {
1820
1597
  const registeredWidget = registeredWidgets[widget];
1821
1598
  return getWidget(schema, registeredWidget, registeredWidgets);
1822
1599
  }
1823
-
1824
1600
  if (typeof type === "string") {
1825
1601
  if (!(type in widgetMap)) {
1826
- throw new Error("No widget for type '" + type + "'");
1602
+ throw new Error(`No widget for type '${type}'`);
1827
1603
  }
1828
-
1829
1604
  if (widget in widgetMap[type]) {
1830
1605
  const registeredWidget = registeredWidgets[widgetMap[type][widget]];
1831
1606
  return getWidget(schema, registeredWidget, registeredWidgets);
1832
1607
  }
1833
1608
  }
1834
-
1835
- throw new Error("No widget '" + widget + "' for type '" + type + "'");
1609
+ throw new Error(`No widget '${widget}' for type '${type}'`);
1836
1610
  }
1837
1611
 
1838
1612
  /** Detects whether the `widget` exists for the `schema` with the associated `registryWidgets` and returns true if it
@@ -1843,22 +1617,18 @@ function getWidget(schema, widget, registeredWidgets) {
1843
1617
  * @param [registeredWidgets={}] - A registry of widget name to `Widget` implementation
1844
1618
  * @returns - True if the widget exists, false otherwise
1845
1619
  */
1846
-
1847
1620
  function hasWidget(schema, widget, registeredWidgets) {
1848
1621
  if (registeredWidgets === void 0) {
1849
1622
  registeredWidgets = {};
1850
1623
  }
1851
-
1852
1624
  try {
1853
1625
  getWidget(schema, widget, registeredWidgets);
1854
1626
  return true;
1855
1627
  } catch (e) {
1856
1628
  const err = e;
1857
-
1858
1629
  if (err.message && (err.message.startsWith("No widget") || err.message.startsWith("Unsupported widget"))) {
1859
1630
  return false;
1860
1631
  }
1861
-
1862
1632
  throw e;
1863
1633
  }
1864
1634
  }
@@ -1879,16 +1649,13 @@ function localToUTC(dateString) {
1879
1649
  * @returns - The constant value for the schema
1880
1650
  * @throws - Error when the schema does not have a constant value
1881
1651
  */
1882
-
1883
1652
  function toConstant(schema) {
1884
1653
  if (ENUM_KEY in schema && Array.isArray(schema.enum) && schema.enum.length === 1) {
1885
1654
  return schema.enum[0];
1886
1655
  }
1887
-
1888
1656
  if (CONST_KEY in schema) {
1889
1657
  return schema.const;
1890
1658
  }
1891
-
1892
1659
  throw new Error("schema cannot be inferred as a constant");
1893
1660
  }
1894
1661
 
@@ -1900,16 +1667,13 @@ function toConstant(schema) {
1900
1667
  * @param schema - The schema from which to extract the options list
1901
1668
  * @returns - The list of options from the schema
1902
1669
  */
1903
-
1904
1670
  function optionsList(schema) {
1905
1671
  // enumNames was deprecated in v5 and is intentionally omitted from the RJSFSchema type.
1906
1672
  // Cast the type to include enumNames so the feature still works.
1907
1673
  const schemaWithEnumNames = schema;
1908
-
1909
1674
  if (schemaWithEnumNames.enumNames && process.env.NODE_ENV !== "production") {
1910
1675
  console.warn("The enumNames property is deprecated and may be removed in a future major release.");
1911
1676
  }
1912
-
1913
1677
  if (schema.enum) {
1914
1678
  return schema.enum.map((value, i) => {
1915
1679
  const label = schemaWithEnumNames.enumNames && schemaWithEnumNames.enumNames[i] || String(value);
@@ -1919,7 +1683,6 @@ function optionsList(schema) {
1919
1683
  };
1920
1684
  });
1921
1685
  }
1922
-
1923
1686
  const altSchemas = schema.oneOf || schema.anyOf;
1924
1687
  return altSchemas && altSchemas.map(aSchemaDef => {
1925
1688
  const aSchema = aSchemaDef;
@@ -1947,32 +1710,25 @@ function orderProperties(properties, order) {
1947
1710
  if (!Array.isArray(order)) {
1948
1711
  return properties;
1949
1712
  }
1950
-
1951
1713
  const arrayToHash = arr => arr.reduce((prev, curr) => {
1952
1714
  prev[curr] = true;
1953
1715
  return prev;
1954
1716
  }, {});
1955
-
1956
- const errorPropList = arr => arr.length > 1 ? "properties '" + arr.join("', '") + "'" : "property '" + arr[0] + "'";
1957
-
1717
+ const errorPropList = arr => arr.length > 1 ? `properties '${arr.join("', '")}'` : `property '${arr[0]}'`;
1958
1718
  const propertyHash = arrayToHash(properties);
1959
1719
  const orderFiltered = order.filter(prop => prop === "*" || propertyHash[prop]);
1960
1720
  const orderHash = arrayToHash(orderFiltered);
1961
1721
  const rest = properties.filter(prop => !orderHash[prop]);
1962
1722
  const restIndex = orderFiltered.indexOf("*");
1963
-
1964
1723
  if (restIndex === -1) {
1965
1724
  if (rest.length) {
1966
- throw new Error("uiSchema order list does not contain " + errorPropList(rest));
1725
+ throw new Error(`uiSchema order list does not contain ${errorPropList(rest)}`);
1967
1726
  }
1968
-
1969
1727
  return orderFiltered;
1970
1728
  }
1971
-
1972
1729
  if (restIndex !== orderFiltered.lastIndexOf("*")) {
1973
1730
  throw new Error("uiSchema order list contains more than one wildcard item");
1974
1731
  }
1975
-
1976
1732
  const complete = [...orderFiltered];
1977
1733
  complete.splice(restIndex, 1, ...rest);
1978
1734
  return complete;
@@ -1986,11 +1742,9 @@ function orderProperties(properties, order) {
1986
1742
  */
1987
1743
  function pad(num, width) {
1988
1744
  let s = String(num);
1989
-
1990
1745
  while (s.length < width) {
1991
1746
  s = "0" + s;
1992
1747
  }
1993
-
1994
1748
  return s;
1995
1749
  }
1996
1750
 
@@ -2005,7 +1759,6 @@ function parseDateString(dateString, includeTime) {
2005
1759
  if (includeTime === void 0) {
2006
1760
  includeTime = true;
2007
1761
  }
2008
-
2009
1762
  if (!dateString) {
2010
1763
  return {
2011
1764
  year: -1,
@@ -2016,13 +1769,10 @@ function parseDateString(dateString, includeTime) {
2016
1769
  second: includeTime ? -1 : 0
2017
1770
  };
2018
1771
  }
2019
-
2020
1772
  const date = new Date(dateString);
2021
-
2022
1773
  if (Number.isNaN(date.getTime())) {
2023
1774
  throw new Error("Unable to parse date " + dateString);
2024
1775
  }
2025
-
2026
1776
  return {
2027
1777
  year: date.getUTCFullYear(),
2028
1778
  month: date.getUTCMonth() + 1,
@@ -2043,42 +1793,34 @@ const nums = /*#__PURE__*/new Set(["number", "integer"]);
2043
1793
  * @param [options] - The UIOptionsType from which to potentially extract the emptyValue
2044
1794
  * @returns - The `value` converted to the proper type
2045
1795
  */
2046
-
2047
1796
  function processSelectValue(schema, value, options) {
2048
1797
  const {
2049
1798
  enum: schemaEnum,
2050
1799
  type,
2051
1800
  items
2052
1801
  } = schema;
2053
-
2054
1802
  if (value === "") {
2055
1803
  return options && options.emptyValue !== undefined ? options.emptyValue : undefined;
2056
1804
  }
2057
-
2058
1805
  if (type === "array" && items && nums.has(get(items, "type"))) {
2059
1806
  return value.map(asNumber);
2060
1807
  }
2061
-
2062
1808
  if (type === "boolean") {
2063
1809
  return value === "true";
2064
1810
  }
2065
-
2066
1811
  if (nums.has(type)) {
2067
1812
  return asNumber(value);
2068
- } // If type is undefined, but an enum is present, try and infer the type from
1813
+ }
1814
+ // If type is undefined, but an enum is present, try and infer the type from
2069
1815
  // the enum values
2070
-
2071
-
2072
1816
  if (Array.isArray(schemaEnum)) {
2073
1817
  if (schemaEnum.every(x => nums.has(guessType(x)))) {
2074
1818
  return asNumber(value);
2075
1819
  }
2076
-
2077
1820
  if (schemaEnum.every(x => guessType(x) === "boolean")) {
2078
1821
  return value === "true";
2079
1822
  }
2080
1823
  }
2081
-
2082
1824
  return value;
2083
1825
  }
2084
1826
 
@@ -2095,30 +1837,24 @@ function schemaRequiresTrueValue(schema) {
2095
1837
  // Check if const is a truthy value
2096
1838
  if (schema.const) {
2097
1839
  return true;
2098
- } // Check if an enum has a single value of true
2099
-
2100
-
1840
+ }
1841
+ // Check if an enum has a single value of true
2101
1842
  if (schema.enum && schema.enum.length === 1 && schema.enum[0] === true) {
2102
1843
  return true;
2103
- } // If anyOf has a single value, evaluate the subschema
2104
-
2105
-
1844
+ }
1845
+ // If anyOf has a single value, evaluate the subschema
2106
1846
  if (schema.anyOf && schema.anyOf.length === 1) {
2107
1847
  return schemaRequiresTrueValue(schema.anyOf[0]);
2108
- } // If oneOf has a single value, evaluate the subschema
2109
-
2110
-
1848
+ }
1849
+ // If oneOf has a single value, evaluate the subschema
2111
1850
  if (schema.oneOf && schema.oneOf.length === 1) {
2112
1851
  return schemaRequiresTrueValue(schema.oneOf[0]);
2113
- } // Evaluate each subschema in allOf, to see if one of them requires a true value
2114
-
2115
-
1852
+ }
1853
+ // Evaluate each subschema in allOf, to see if one of them requires a true value
2116
1854
  if (schema.allOf) {
2117
1855
  const schemaSome = subSchema => schemaRequiresTrueValue(subSchema);
2118
-
2119
1856
  return schema.allOf.some(schemaSome);
2120
1857
  }
2121
-
2122
1858
  return false;
2123
1859
  }
2124
1860
 
@@ -2130,7 +1866,6 @@ function schemaRequiresTrueValue(schema) {
2130
1866
  * @param nextState - The next set of state against which to check
2131
1867
  * @returns - True if the component should be re-rendered, false otherwise
2132
1868
  */
2133
-
2134
1869
  function shouldRender(component, nextProps, nextState) {
2135
1870
  const {
2136
1871
  props,
@@ -2150,7 +1885,6 @@ function toDateString(dateObject, time) {
2150
1885
  if (time === void 0) {
2151
1886
  time = true;
2152
1887
  }
2153
-
2154
1888
  const {
2155
1889
  year,
2156
1890
  month,
@@ -2169,17 +1903,15 @@ function toDateString(dateObject, time) {
2169
1903
  * @param jsonDate - A UTC date string
2170
1904
  * @returns - An empty string when `jsonDate` is falsey, otherwise a date string in local format
2171
1905
  */
2172
-
2173
1906
  function utcToLocal(jsonDate) {
2174
1907
  if (!jsonDate) {
2175
1908
  return "";
2176
- } // required format of `'yyyy-MM-ddThh:mm' followed by optional ':ss' or ':ss.SSS'
1909
+ }
1910
+ // required format of `'yyyy-MM-ddThh:mm' followed by optional ':ss' or ':ss.SSS'
2177
1911
  // https://html.spec.whatwg.org/multipage/input.html#local-date-and-time-state-(type%3Ddatetime-local)
2178
1912
  // > should be a _valid local date and time string_ (not GMT)
2179
1913
  // Note - date constructor passed local ISO-8601 does not correctly
2180
1914
  // change time to UTC in node pre-8
2181
-
2182
-
2183
1915
  const date = new Date(jsonDate);
2184
1916
  const yyyy = pad(date.getFullYear(), 4);
2185
1917
  const MM = pad(date.getMonth() + 1, 2);
@@ -2188,7 +1920,7 @@ function utcToLocal(jsonDate) {
2188
1920
  const mm = pad(date.getMinutes(), 2);
2189
1921
  const ss = pad(date.getSeconds(), 2);
2190
1922
  const SSS = pad(date.getMilliseconds(), 3);
2191
- return yyyy + "-" + MM + "-" + dd + "T" + hh + ":" + mm + ":" + ss + "." + SSS;
1923
+ return `${yyyy}-${MM}-${dd}T${hh}:${mm}:${ss}.${SSS}`;
2192
1924
  }
2193
1925
 
2194
1926
  export { ADDITIONAL_PROPERTIES_KEY, ADDITIONAL_PROPERTY_FLAG, ALL_OF_KEY, ANY_OF_KEY, CONST_KEY, DEFAULT_KEY, DEFINITIONS_KEY, DEPENDENCIES_KEY, ENUM_KEY, ERRORS_KEY, ID_KEY, ITEMS_KEY, NAME_KEY, ONE_OF_KEY, PROPERTIES_KEY, REF_KEY, REQUIRED_KEY, RJSF_ADDITONAL_PROPERTIES_FLAG, SUBMIT_BTN_OPTIONS_KEY, UI_FIELD_KEY, UI_OPTIONS_KEY, UI_WIDGET_KEY, allowAdditionalItems, asNumber, canExpand, createSchemaUtils, dataURItoBlob, deepEquals, findSchemaDefinition, getDefaultFormState, getDisplayLabel, getInputProps, getMatchingOption, getSchemaType, getSubmitButtonOptions, getTemplate, getUiOptions, getWidget, guessType, hasWidget, isConstant, isCustomWidget, isFilesArray, isFixedItems, isMultiSelect, isObject, isSelect, localToUTC, mergeDefaultsWithFormData, mergeObjects, mergeSchemas, mergeValidationData, optionsList, orderProperties, pad, parseDateString, processSelectValue, rangeSpec, retrieveSchema, schemaRequiresTrueValue, shouldRender, toConstant, toDateString, toIdSchema, toPathSchema, utcToLocal };