@rjsf/utils 5.6.2 → 5.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/utils.esm.js CHANGED
@@ -18,6 +18,7 @@ import { jsx } from 'react/jsx-runtime';
18
18
  import { createElement } from 'react';
19
19
  import ReactIs from 'react-is';
20
20
  import toPath from 'lodash-es/toPath';
21
+ import forEach from 'lodash-es/forEach';
21
22
 
22
23
  /** Determines whether a `thing` is an object for the purposes of RSJF. In this case, `thing` is an object if it has
23
24
  * the type `object` but is NOT null, an array or a File.
@@ -161,6 +162,7 @@ var DEPENDENCIES_KEY = 'dependencies';
161
162
  var ENUM_KEY = 'enum';
162
163
  var ERRORS_KEY = '__errors';
163
164
  var ID_KEY = '$id';
165
+ var IF_KEY = 'if';
164
166
  var ITEMS_KEY = 'items';
165
167
  var NAME_KEY = '$name';
166
168
  var ONE_OF_KEY = 'oneOf';
@@ -418,6 +420,23 @@ function getFirstMatchingOption(validator, formData, options, rootSchema, discri
418
420
  return getMatchingOption(validator, formData, options, rootSchema, discriminatorField);
419
421
  }
420
422
 
423
+ /** Returns the `discriminator.propertyName` when defined in the `schema` if it is a string. A warning is generated when
424
+ * it is not a string. Returns `undefined` when a valid discriminator is not present.
425
+ *
426
+ * @param schema - The schema from which the discriminator is potentially obtained
427
+ * @returns - The `discriminator.propertyName` if it exists in the schema, otherwise `undefined`
428
+ */
429
+ function getDiscriminatorFieldFromSchema(schema) {
430
+ var discriminator;
431
+ var maybeString = get(schema, 'discriminator.propertyName', undefined);
432
+ if (isString(maybeString)) {
433
+ discriminator = maybeString;
434
+ } else if (maybeString !== undefined) {
435
+ console.warn("Expecting discriminator to be a string, got \"" + typeof maybeString + "\" instead");
436
+ }
437
+ return discriminator;
438
+ }
439
+
421
440
  /** Given a specific `value` attempts to guess the type of a schema element. In the case where we have to implicitly
422
441
  * create a schema, it is useful to know what type to use based on the data we are defining.
423
442
  *
@@ -507,82 +526,164 @@ var _excluded$1 = ["if", "then", "else"],
507
526
  _excluded3 = ["allOf"],
508
527
  _excluded4 = ["dependencies"],
509
528
  _excluded5 = ["oneOf"];
529
+ /** Retrieves an expanded schema that has had all of its conditions, additional properties, references and dependencies
530
+ * resolved and merged into the `schema` given a `validator`, `rootSchema` and `rawFormData` that is used to do the
531
+ * potentially recursive resolution.
532
+ *
533
+ * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
534
+ * @param schema - The schema for which retrieving a schema is desired
535
+ * @param [rootSchema={}] - The root schema that will be forwarded to all the APIs
536
+ * @param [rawFormData] - The current formData, if any, to assist retrieving a schema
537
+ * @returns - The schema having its conditions, additional properties, references and dependencies resolved
538
+ */
539
+ function retrieveSchema(validator, schema, rootSchema, rawFormData) {
540
+ if (rootSchema === void 0) {
541
+ rootSchema = {};
542
+ }
543
+ return retrieveSchemaInternal(validator, schema, rootSchema, rawFormData)[0];
544
+ }
510
545
  /** Resolves a conditional block (if/else/then) by removing the condition and merging the appropriate conditional branch
511
- * with the rest of the schema
546
+ * with the rest of the schema. If `expandAllBranches` is true, then the `retrieveSchemaInteral()` results for both
547
+ * conditions will be returned.
512
548
  *
513
- * @param validator - An implementation of the `ValidatorType<T, S>` interface that is used to detect valid schema conditions
549
+ * @param validator - An implementation of the `ValidatorType` interface that is used to detect valid schema conditions
514
550
  * @param schema - The schema for which resolving a condition is desired
515
551
  * @param rootSchema - The root schema that will be forwarded to all the APIs
552
+ * @param expandAllBranches - Flag, if true, will return all possible branches of conditions, any/oneOf and
553
+ * dependencies as a list of schemas
516
554
  * @param [formData] - The current formData to assist retrieving a schema
517
- * @returns - A schema with the appropriate condition resolved
555
+ * @returns - A list of schemas with the appropriate conditions resolved, possibly with all branches expanded
518
556
  */
519
- function resolveCondition(validator, schema, rootSchema, formData) {
557
+ function resolveCondition(validator, schema, rootSchema, expandAllBranches, formData) {
520
558
  var expression = schema["if"],
521
559
  then = schema.then,
522
560
  otherwise = schema["else"],
523
561
  resolvedSchemaLessConditional = _objectWithoutPropertiesLoose(schema, _excluded$1);
524
- var conditionalSchema = validator.isValid(expression, formData, rootSchema) ? then : otherwise;
525
- if (conditionalSchema && typeof conditionalSchema !== 'boolean') {
526
- return retrieveSchema(validator, mergeSchemas(resolvedSchemaLessConditional, retrieveSchema(validator, conditionalSchema, rootSchema, formData)), rootSchema, formData);
562
+ var conditionValue = validator.isValid(expression, formData, rootSchema);
563
+ var resolvedSchemas = [resolvedSchemaLessConditional];
564
+ var schemas = [];
565
+ if (expandAllBranches) {
566
+ if (then && typeof then !== 'boolean') {
567
+ schemas = schemas.concat(retrieveSchemaInternal(validator, then, rootSchema, formData, expandAllBranches));
568
+ }
569
+ if (otherwise && typeof otherwise !== 'boolean') {
570
+ schemas = schemas.concat(retrieveSchemaInternal(validator, otherwise, rootSchema, formData, expandAllBranches));
571
+ }
572
+ } else {
573
+ var conditionalSchema = conditionValue ? then : otherwise;
574
+ if (conditionalSchema && typeof conditionalSchema !== 'boolean') {
575
+ schemas = schemas.concat(retrieveSchemaInternal(validator, conditionalSchema, rootSchema, formData, expandAllBranches));
576
+ }
577
+ }
578
+ if (schemas.length) {
579
+ resolvedSchemas = schemas.map(function (s) {
580
+ return mergeSchemas(resolvedSchemaLessConditional, s);
581
+ });
527
582
  }
528
- return retrieveSchema(validator, resolvedSchemaLessConditional, rootSchema, formData);
583
+ return resolvedSchemas.flatMap(function (s) {
584
+ return retrieveSchemaInternal(validator, s, rootSchema, formData, expandAllBranches);
585
+ });
586
+ }
587
+ /** Given a list of lists of allOf, anyOf or oneOf values, create a list of lists of all permutations of the values. The
588
+ * `listOfLists` is expected to be all resolved values of the 1st...nth schemas within an `allOf`, `anyOf` or `oneOf`.
589
+ * From those lists, build a matrix for each `xxxOf` where there is more than one schema for a row in the list of lists.
590
+ *
591
+ * For example:
592
+ * - If there are three xxxOf rows (A, B, C) and they have been resolved such that there is only one A, two B and three
593
+ * C schemas then:
594
+ * - The permutation for the first row is `[[A]]`
595
+ * - The permutations for the second row are `[[A,B1], [A,B2]]`
596
+ * - The permutations for the third row are `[[A,B1,C1], [A,B1,C2], [A,B1,C3], [A,B2,C1], [A,B2,C2], [A,B2,C3]]`
597
+ *
598
+ * @param listOfLists - The list of lists of elements that represent the allOf, anyOf or oneOf resolved values in order
599
+ * @returns - The list of all permutations of schemas for a set of `xxxOf`s
600
+ */
601
+ function getAllPermutationsOfXxxOf(listOfLists) {
602
+ var allPermutations = listOfLists.reduce(function (permutations, list) {
603
+ // When there are more than one set of schemas for a row, duplicate the set of permutations and add in the values
604
+ if (list.length > 1) {
605
+ return list.flatMap(function (element) {
606
+ return times(permutations.length, function (i) {
607
+ return [].concat(permutations[i]).concat(element);
608
+ });
609
+ });
610
+ }
611
+ // Otherwise just push in the single value into the current set of permutations
612
+ permutations.forEach(function (permutation) {
613
+ return permutation.push(list[0]);
614
+ });
615
+ return permutations;
616
+ }, [[]] // Start with an empty list
617
+ );
618
+
619
+ return allPermutations;
529
620
  }
530
- /** Resolves references and dependencies within a schema and its 'allOf' children.
531
- * Called internally by retrieveSchema.
621
+ /** Resolves references and dependencies within a schema and its 'allOf' children. Passes the `expandAllBranches` flag
622
+ * down to the `retrieveSchemaInternal()`, `resolveReference()` and `resolveDependencies()` helper calls. If
623
+ * `expandAllBranches` is true, then all possible dependencies and/or allOf branches are returned.
532
624
  *
533
- * @param validator - An implementation of the `ValidatorType<T, S>` interface that will be forwarded to all the APIs
625
+ * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
534
626
  * @param schema - The schema for which resolving a schema is desired
535
- * @param [rootSchema={}] - The root schema that will be forwarded to all the APIs
627
+ * @param rootSchema - The root schema that will be forwarded to all the APIs
628
+ * @param expandAllBranches - Flag, if true, will return all possible branches of conditions, any/oneOf and dependencies
629
+ * as a list of schemas
536
630
  * @param [formData] - The current formData, if any, to assist retrieving a schema
537
- * @returns - The schema having its references and dependencies resolved
631
+ * @returns - The list of schemas having its references, dependencies and allOf schemas resolved
538
632
  */
539
- function resolveSchema(validator, schema, rootSchema, formData) {
540
- if (rootSchema === void 0) {
541
- rootSchema = {};
542
- }
633
+ function resolveSchema(validator, schema, rootSchema, expandAllBranches, formData) {
543
634
  if (REF_KEY in schema) {
544
- return resolveReference(validator, schema, rootSchema, formData);
635
+ return resolveReference(validator, schema, rootSchema, expandAllBranches, formData);
545
636
  }
546
637
  if (DEPENDENCIES_KEY in schema) {
547
- var resolvedSchema = resolveDependencies(validator, schema, rootSchema, formData);
548
- return retrieveSchema(validator, resolvedSchema, rootSchema, formData);
638
+ var resolvedSchemas = resolveDependencies(validator, schema, rootSchema, expandAllBranches, formData);
639
+ return resolvedSchemas.flatMap(function (s) {
640
+ return retrieveSchemaInternal(validator, s, rootSchema, formData, expandAllBranches);
641
+ });
549
642
  }
550
- if (ALL_OF_KEY in schema) {
551
- return _extends({}, schema, {
552
- allOf: schema.allOf.map(function (allOfSubschema) {
553
- return retrieveSchema(validator, allOfSubschema, rootSchema, formData);
554
- })
643
+ if (ALL_OF_KEY in schema && Array.isArray(schema.allOf)) {
644
+ var allOfSchemaElements = schema.allOf.map(function (allOfSubschema) {
645
+ return retrieveSchemaInternal(validator, allOfSubschema, rootSchema, formData, expandAllBranches);
646
+ });
647
+ var allPermutations = getAllPermutationsOfXxxOf(allOfSchemaElements);
648
+ return allPermutations.map(function (permutation) {
649
+ return _extends({}, schema, {
650
+ allOf: permutation
651
+ });
555
652
  });
556
653
  }
557
- // No $ref or dependencies attribute found, returning the original schema.
558
- return schema;
654
+ // No $ref or dependencies or allOf attribute was found, returning the original schema.
655
+ return [schema];
559
656
  }
560
- /** Resolves references within a schema and its 'allOf' children.
657
+ /** Resolves references within a schema and then returns the `retrieveSchemaInternal()` of the resolved schema. Passes
658
+ * the `expandAllBranches` flag down to the `retrieveSchemaInternal()` helper call.
561
659
  *
562
- * @param validator - An implementation of the `ValidatorType<T, S>` interface that will be forwarded to all the APIs
660
+ * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
563
661
  * @param schema - The schema for which resolving a reference is desired
564
662
  * @param rootSchema - The root schema that will be forwarded to all the APIs
663
+ * @param expandAllBranches - Flag, if true, will return all possible branches of conditions, any/oneOf and dependencies
664
+ * as a list of schemas
565
665
  * @param [formData] - The current formData, if any, to assist retrieving a schema
566
- * @returns - The schema having its references resolved
666
+ * @returns - The list schemas retrieved after having all references resolved
567
667
  */
568
- function resolveReference(validator, schema, rootSchema, formData) {
569
- // Retrieve the referenced schema definition.
570
- var $refSchema = findSchemaDefinition(schema.$ref, rootSchema);
668
+ function resolveReference(validator, schema, rootSchema, expandAllBranches, formData) {
571
669
  // Drop the $ref property of the source schema.
572
- var localSchema = _objectWithoutPropertiesLoose(schema, _excluded2);
670
+ var $ref = schema.$ref,
671
+ localSchema = _objectWithoutPropertiesLoose(schema, _excluded2);
672
+ // Retrieve the referenced schema definition.
673
+ var refSchema = findSchemaDefinition($ref, rootSchema);
573
674
  // Update referenced schema definition with local schema properties.
574
- return retrieveSchema(validator, _extends({}, $refSchema, localSchema), rootSchema, formData);
675
+ return retrieveSchemaInternal(validator, _extends({}, refSchema, localSchema), rootSchema, formData, expandAllBranches);
575
676
  }
576
677
  /** Creates new 'properties' items for each key in the `formData`
577
678
  *
578
- * @param validator - An implementation of the `ValidatorType<T, S>` interface that will be used when necessary
679
+ * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
579
680
  * @param theSchema - The schema for which the existing additional properties is desired
580
681
  * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s * @param validator
581
682
  * @param [aFormData] - The current formData, if any, to assist retrieving a schema
582
683
  * @returns - The updated schema with additional properties stubbed
583
684
  */
584
685
  function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFormData) {
585
- // Clone the schema so we don't ruin the consumer's original
686
+ // Clone the schema so that we don't ruin the consumer's original
586
687
  var schema = _extends({}, theSchema, {
587
688
  properties: _extends({}, theSchema.properties)
588
689
  });
@@ -622,98 +723,155 @@ function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFor
622
723
  });
623
724
  return schema;
624
725
  }
625
- /** Retrieves an expanded schema that has had all of its conditions, additional properties, references and dependencies
626
- * resolved and merged into the `schema` given a `validator`, `rootSchema` and `rawFormData` that is used to do the
627
- * potentially recursive resolution.
726
+ /** Internal handler that retrieves an expanded schema that has had all of its conditions, additional properties,
727
+ * references and dependencies resolved and merged into the `schema` given a `validator`, `rootSchema` and `rawFormData`
728
+ * that is used to do the potentially recursive resolution. If `expandAllBranches` is true, then all possible branches
729
+ * of the schema and its references, conditions and dependencies are returned.
628
730
  *
629
- * @param validator - An implementation of the `ValidatorType<T, S>` interface that will be forwarded to all the APIs
731
+ * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
630
732
  * @param schema - The schema for which retrieving a schema is desired
631
- * @param [rootSchema={}] - The root schema that will be forwarded to all the APIs
733
+ * @param rootSchema - The root schema that will be forwarded to all the APIs
632
734
  * @param [rawFormData] - The current formData, if any, to assist retrieving a schema
633
- * @returns - The schema having its conditions, additional properties, references and dependencies resolved
735
+ * @param [expandAllBranches=false] - Flag, if true, will return all possible branches of conditions, any/oneOf and
736
+ * dependencies as a list of schemas
737
+ * @returns - The schema(s) resulting from having its conditions, additional properties, references and dependencies
738
+ * resolved. Multiple schemas may be returned if `expandAllBranches` is true.
634
739
  */
635
- function retrieveSchema(validator, schema, rootSchema, rawFormData) {
636
- if (rootSchema === void 0) {
637
- rootSchema = {};
740
+ function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expandAllBranches) {
741
+ if (expandAllBranches === void 0) {
742
+ expandAllBranches = false;
638
743
  }
639
744
  if (!isObject(schema)) {
640
- return {};
745
+ return [{}];
641
746
  }
642
- var resolvedSchema = resolveSchema(validator, schema, rootSchema, rawFormData);
643
- if ('if' in schema) {
644
- return resolveCondition(validator, schema, rootSchema, rawFormData);
645
- }
646
- var formData = rawFormData || {};
647
- if (ALL_OF_KEY in schema) {
648
- try {
649
- resolvedSchema = mergeAllOf(resolvedSchema, {
650
- deep: false
651
- });
652
- } catch (e) {
653
- console.warn('could not merge subschemas in allOf:\n', e);
654
- var _resolvedSchema = resolvedSchema,
655
- resolvedSchemaWithoutAllOf = _objectWithoutPropertiesLoose(_resolvedSchema, _excluded3);
656
- return resolvedSchemaWithoutAllOf;
747
+ var resolvedSchemas = resolveSchema(validator, schema, rootSchema, expandAllBranches, rawFormData);
748
+ return resolvedSchemas.flatMap(function (s) {
749
+ var resolvedSchema = s;
750
+ if (IF_KEY in resolvedSchema) {
751
+ return resolveCondition(validator, resolvedSchema, rootSchema, expandAllBranches, rawFormData);
657
752
  }
753
+ if (ALL_OF_KEY in schema) {
754
+ try {
755
+ resolvedSchema = mergeAllOf(s, {
756
+ deep: false
757
+ });
758
+ } catch (e) {
759
+ console.warn('could not merge subschemas in allOf:\n', e);
760
+ var _resolvedSchema = resolvedSchema,
761
+ resolvedSchemaWithoutAllOf = _objectWithoutPropertiesLoose(_resolvedSchema, _excluded3);
762
+ return resolvedSchemaWithoutAllOf;
763
+ }
764
+ }
765
+ var hasAdditionalProperties = ADDITIONAL_PROPERTIES_KEY in resolvedSchema && resolvedSchema.additionalProperties !== false;
766
+ if (hasAdditionalProperties) {
767
+ return stubExistingAdditionalProperties(validator, resolvedSchema, rootSchema, rawFormData);
768
+ }
769
+ return resolvedSchema;
770
+ });
771
+ }
772
+ /** Resolves an `anyOf` or `oneOf` within a schema (if present) to the list of schemas returned from
773
+ * `retrieveSchemaInternal()` for the best matching option. If `expandAllBranches` is true, then a list of schemas for ALL
774
+ * options are retrieved and returned.
775
+ *
776
+ * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
777
+ * @param schema - The schema for which retrieving a schema is desired
778
+ * @param rootSchema - The root schema that will be forwarded to all the APIs
779
+ * @param expandAllBranches - Flag, if true, will return all possible branches of conditions, any/oneOf and dependencies
780
+ * as a list of schemas
781
+ * @param [rawFormData] - The current formData, if any, to assist retrieving a schema, defaults to an empty object
782
+ * @returns - Either an array containing the best matching option or all options if `expandAllBranches` is true
783
+ */
784
+ function resolveAnyOrOneOfSchemas(validator, schema, rootSchema, expandAllBranches, rawFormData) {
785
+ var anyOrOneOf;
786
+ if (Array.isArray(schema.oneOf)) {
787
+ anyOrOneOf = schema.oneOf;
788
+ } else if (Array.isArray(schema.anyOf)) {
789
+ anyOrOneOf = schema.anyOf;
790
+ }
791
+ if (anyOrOneOf) {
792
+ // Ensure that during expand all branches we pass an object rather than undefined so that all options are interrogated
793
+ var formData = rawFormData === undefined && expandAllBranches ? {} : rawFormData;
794
+ var discriminator = getDiscriminatorFieldFromSchema(schema);
795
+ anyOrOneOf = anyOrOneOf.map(function (s) {
796
+ if (REF_KEY in s) {
797
+ // For this ref situation, don't expand all branches and just pick the first/only schema result
798
+ return resolveReference(validator, s, rootSchema, false, formData)[0];
799
+ }
800
+ return s;
801
+ });
802
+ // Call this to trigger the set of isValid() calls that the schema parser will need
803
+ var option = getFirstMatchingOption(validator, formData, anyOrOneOf, rootSchema, discriminator);
804
+ if (expandAllBranches) {
805
+ return anyOrOneOf;
806
+ }
807
+ schema = anyOrOneOf[option];
658
808
  }
659
- var hasAdditionalProperties = ADDITIONAL_PROPERTIES_KEY in resolvedSchema && resolvedSchema.additionalProperties !== false;
660
- if (hasAdditionalProperties) {
661
- return stubExistingAdditionalProperties(validator, resolvedSchema, rootSchema, formData);
662
- }
663
- return resolvedSchema;
809
+ return [schema];
664
810
  }
665
- /** Resolves dependencies within a schema and its 'allOf' children.
811
+ /** Resolves dependencies within a schema and its 'anyOf/oneOf' children. Passes the `expandAllBranches` flag down to
812
+ * the `resolveAnyOrOneOfSchema()` and `processDependencies()` helper calls.
666
813
  *
667
- * @param validator - An implementation of the `ValidatorType<T, S>` interface that will be forwarded to all the APIs
814
+ * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
668
815
  * @param schema - The schema for which resolving a dependency is desired
669
816
  * @param rootSchema - The root schema that will be forwarded to all the APIs
817
+ * @param expandAllBranches - Flag, if true, will return all possible branches of conditions, any/oneOf and dependencies
818
+ * as a list of schemas
670
819
  * @param [formData] - The current formData, if any, to assist retrieving a schema
671
- * @returns - The schema with its dependencies resolved
820
+ * @returns - The list of schemas with their dependencies resolved
672
821
  */
673
- function resolveDependencies(validator, schema, rootSchema, formData) {
822
+ function resolveDependencies(validator, schema, rootSchema, expandAllBranches, formData) {
674
823
  // Drop the dependencies from the source schema.
675
824
  var dependencies = schema.dependencies,
676
825
  remainingSchema = _objectWithoutPropertiesLoose(schema, _excluded4);
677
- var resolvedSchema = remainingSchema;
678
- if (Array.isArray(resolvedSchema.oneOf)) {
679
- resolvedSchema = resolvedSchema.oneOf[getFirstMatchingOption(validator, formData, resolvedSchema.oneOf, rootSchema)];
680
- } else if (Array.isArray(resolvedSchema.anyOf)) {
681
- resolvedSchema = resolvedSchema.anyOf[getFirstMatchingOption(validator, formData, resolvedSchema.anyOf, rootSchema)];
682
- }
683
- return processDependencies(validator, dependencies, resolvedSchema, rootSchema, formData);
826
+ var resolvedSchemas = resolveAnyOrOneOfSchemas(validator, remainingSchema, rootSchema, expandAllBranches, formData);
827
+ return resolvedSchemas.flatMap(function (resolvedSchema) {
828
+ return processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, formData);
829
+ });
684
830
  }
685
- /** Processes all the `dependencies` recursively into the `resolvedSchema` as needed
831
+ /** Processes all the `dependencies` recursively into the list of `resolvedSchema`s as needed. Passes the
832
+ * `expandAllBranches` flag down to the `withDependentSchema()` and the recursive `processDependencies()` helper calls.
686
833
  *
687
- * @param validator - An implementation of the `ValidatorType<T, S>` interface that will be forwarded to all the APIs
834
+ * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
688
835
  * @param dependencies - The set of dependencies that needs to be processed
689
836
  * @param resolvedSchema - The schema for which processing dependencies is desired
690
837
  * @param rootSchema - The root schema that will be forwarded to all the APIs
838
+ * @param expandAllBranches - Flag, if true, will return all possible branches of conditions, any/oneOf and dependencies
839
+ * as a list of schemas
691
840
  * @param [formData] - The current formData, if any, to assist retrieving a schema
692
841
  * @returns - The schema with the `dependencies` resolved into it
693
842
  */
694
- function processDependencies(validator, dependencies, resolvedSchema, rootSchema, formData) {
695
- var schema = resolvedSchema;
843
+ function processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, formData) {
844
+ var schemas = [resolvedSchema];
696
845
  // Process dependencies updating the local schema properties as appropriate.
697
- for (var dependencyKey in dependencies) {
846
+ var _loop = function _loop() {
698
847
  // Skip this dependency if its trigger property is not present.
699
- if (get(formData, [dependencyKey]) === undefined) {
700
- continue;
848
+ if (!expandAllBranches && get(formData, [dependencyKey]) === undefined) {
849
+ return "continue";
701
850
  }
702
851
  // Skip this dependency if it is not included in the schema (such as when dependencyKey is itself a hidden dependency.)
703
- if (schema.properties && !(dependencyKey in schema.properties)) {
704
- continue;
852
+ if (resolvedSchema.properties && !(dependencyKey in resolvedSchema.properties)) {
853
+ return "continue";
705
854
  }
706
855
  var _splitKeyElementFromO = splitKeyElementFromObject(dependencyKey, dependencies),
707
856
  remainingDependencies = _splitKeyElementFromO[0],
708
857
  dependencyValue = _splitKeyElementFromO[1];
709
858
  if (Array.isArray(dependencyValue)) {
710
- schema = withDependentProperties(schema, dependencyValue);
859
+ schemas[0] = withDependentProperties(resolvedSchema, dependencyValue);
711
860
  } else if (isObject(dependencyValue)) {
712
- schema = withDependentSchema(validator, schema, rootSchema, dependencyKey, dependencyValue, formData);
861
+ schemas = withDependentSchema(validator, resolvedSchema, rootSchema, dependencyKey, dependencyValue, expandAllBranches, formData);
713
862
  }
714
- return processDependencies(validator, remainingDependencies, schema, rootSchema, formData);
863
+ return {
864
+ v: schemas.flatMap(function (schema) {
865
+ return processDependencies(validator, remainingDependencies, schema, rootSchema, expandAllBranches, formData);
866
+ })
867
+ };
868
+ };
869
+ for (var dependencyKey in dependencies) {
870
+ var _ret = _loop();
871
+ if (_ret === "continue") continue;
872
+ if (typeof _ret === "object") return _ret.v;
715
873
  }
716
- return schema;
874
+ return schemas;
717
875
  }
718
876
  /** Updates a schema with additionally required properties added
719
877
  *
@@ -730,45 +888,57 @@ function withDependentProperties(schema, additionallyRequired) {
730
888
  required: required
731
889
  });
732
890
  }
733
- /** Merges a dependent schema into the `schema` dealing with oneOfs and references
891
+ /** Merges a dependent schema into the `schema` dealing with oneOfs and references. Passes the `expandAllBranches` flag
892
+ * down to the `retrieveSchemaInternal()`, `resolveReference()` and `withExactlyOneSubschema()` helper calls.
734
893
  *
735
- * @param validator - An implementation of the `ValidatorType<T, S>` interface that will be forwarded to all the APIs
894
+ * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
736
895
  * @param schema - The schema for which resolving a dependent schema is desired
737
896
  * @param rootSchema - The root schema that will be forwarded to all the APIs
738
897
  * @param dependencyKey - The key name of the dependency
739
898
  * @param dependencyValue - The potentially dependent schema
740
- * @param formData- The current formData to assist retrieving a schema
741
- * @returns - The schema with the dependent schema resolved into it
742
- */
743
- function withDependentSchema(validator, schema, rootSchema, dependencyKey, dependencyValue, formData) {
744
- var _retrieveSchema = retrieveSchema(validator, dependencyValue, rootSchema, formData),
745
- oneOf = _retrieveSchema.oneOf,
746
- dependentSchema = _objectWithoutPropertiesLoose(_retrieveSchema, _excluded5);
747
- schema = mergeSchemas(schema, dependentSchema);
748
- // Since it does not contain oneOf, we return the original schema.
749
- if (oneOf === undefined) {
750
- return schema;
751
- }
752
- // Resolve $refs inside oneOf.
753
- var resolvedOneOf = oneOf.map(function (subschema) {
754
- if (typeof subschema === 'boolean' || !(REF_KEY in subschema)) {
755
- return subschema;
899
+ * @param expandAllBranches - Flag, if true, will return all possible branches of conditions, any/oneOf and dependencies
900
+ * as a list of schemas
901
+ * @param [formData]- The current formData to assist retrieving a schema
902
+ * @returns - The list of schemas with the dependent schema resolved into them
903
+ */
904
+ function withDependentSchema(validator, schema, rootSchema, dependencyKey, dependencyValue, expandAllBranches, formData) {
905
+ var dependentSchemas = retrieveSchemaInternal(validator, dependencyValue, rootSchema, formData, expandAllBranches);
906
+ return dependentSchemas.flatMap(function (dependent) {
907
+ var oneOf = dependent.oneOf,
908
+ dependentSchema = _objectWithoutPropertiesLoose(dependent, _excluded5);
909
+ schema = mergeSchemas(schema, dependentSchema);
910
+ // Since it does not contain oneOf, we return the original schema.
911
+ if (oneOf === undefined) {
912
+ return schema;
756
913
  }
757
- return resolveReference(validator, subschema, rootSchema, formData);
914
+ // Resolve $refs inside oneOf.
915
+ var resolvedOneOfs = oneOf.map(function (subschema) {
916
+ if (typeof subschema === 'boolean' || !(REF_KEY in subschema)) {
917
+ return [subschema];
918
+ }
919
+ return resolveReference(validator, subschema, rootSchema, expandAllBranches, formData);
920
+ });
921
+ var allPermutations = getAllPermutationsOfXxxOf(resolvedOneOfs);
922
+ return allPermutations.flatMap(function (resolvedOneOf) {
923
+ return withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, resolvedOneOf, expandAllBranches, formData);
924
+ });
758
925
  });
759
- return withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, resolvedOneOf, formData);
760
926
  }
761
- /** Returns a `schema` with the best choice from the `oneOf` options merged into it
927
+ /** Returns a list of `schema`s with the best choice from the `oneOf` options merged into it. If `expandAllBranches` is
928
+ * true, then a list of schemas for ALL options are retrieved and returned. Passes the `expandAllBranches` flag down to
929
+ * the `retrieveSchemaInternal()` helper call.
762
930
  *
763
- * @param validator - An implementation of the `ValidatorType<T, S>` interface that will be used to validate oneOf options
931
+ * @param validator - An implementation of the `ValidatorType` interface that will be used to validate oneOf options
764
932
  * @param schema - The schema for which resolving a oneOf subschema is desired
765
933
  * @param rootSchema - The root schema that will be forwarded to all the APIs
766
934
  * @param dependencyKey - The key name of the oneOf dependency
767
935
  * @param oneOf - The list of schemas representing the oneOf options
936
+ * @param expandAllBranches - Flag, if true, will return all possible branches of conditions, any/oneOf and dependencies
937
+ * as a list of schemas
768
938
  * @param [formData] - The current formData to assist retrieving a schema
769
- * @returns The schema with the best choice of oneOf schemas merged into
939
+ * @returns - Either an array containing the best matching option or all options if `expandAllBranches` is true
770
940
  */
771
- function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, oneOf, formData) {
941
+ function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, oneOf, expandAllBranches, formData) {
772
942
  var validSubschemas = oneOf.filter(function (subschema) {
773
943
  if (typeof subschema === 'boolean' || !subschema || !subschema.properties) {
774
944
  return false;
@@ -780,21 +950,26 @@ function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, o
780
950
  type: 'object',
781
951
  properties: (_properties = {}, _properties[dependencyKey] = conditionPropertySchema, _properties)
782
952
  };
783
- return validator.isValid(conditionSchema, formData, rootSchema);
953
+ return validator.isValid(conditionSchema, formData, rootSchema) || expandAllBranches;
784
954
  }
785
955
  return false;
786
956
  });
787
- if (validSubschemas.length !== 1) {
957
+ if (!expandAllBranches && validSubschemas.length !== 1) {
788
958
  console.warn("ignoring oneOf in dependencies because there isn't exactly one subschema that is valid");
789
- return schema;
790
- }
791
- var subschema = validSubschemas[0];
792
- var _splitKeyElementFromO2 = splitKeyElementFromObject(dependencyKey, subschema.properties),
793
- dependentSubschema = _splitKeyElementFromO2[0];
794
- var dependentSchema = _extends({}, subschema, {
795
- properties: dependentSubschema
959
+ return [schema];
960
+ }
961
+ return validSubschemas.flatMap(function (s) {
962
+ var subschema = s;
963
+ var _splitKeyElementFromO2 = splitKeyElementFromObject(dependencyKey, subschema.properties),
964
+ dependentSubschema = _splitKeyElementFromO2[0];
965
+ var dependentSchema = _extends({}, subschema, {
966
+ properties: dependentSubschema
967
+ });
968
+ var schemas = retrieveSchemaInternal(validator, dependentSchema, rootSchema, formData, expandAllBranches);
969
+ return schemas.map(function (s) {
970
+ return mergeSchemas(schema, s);
971
+ });
796
972
  });
797
- return mergeSchemas(schema, retrieveSchema(validator, dependentSchema, rootSchema, formData));
798
973
  }
799
974
 
800
975
  /** A junk option used to determine when the getFirstMatchingOption call really matches an option rather than returning
@@ -1118,10 +1293,11 @@ function getInnerSchemaForArrayItem(schema, additionalItems, idx) {
1118
1293
  }
1119
1294
  return {};
1120
1295
  }
1121
- /** Either add `computedDefault` at `key` into `obj` or not add it based on its value and the value of
1122
- * `includeUndefinedValues`. Generally undefined `computedDefault` values are added only when `includeUndefinedValues`
1123
- * is either true or "excludeObjectChildren". If `includeUndefinedValues` is false, then non-undefined and
1124
- * non-empty-object values will be added.
1296
+ /** Either add `computedDefault` at `key` into `obj` or not add it based on its value, the value of
1297
+ * `includeUndefinedValues`, the value of `emptyObjectFields` and if its parent field is required. Generally undefined
1298
+ * `computedDefault` values are added only when `includeUndefinedValues` is either true/"excludeObjectChildren". If `
1299
+ * includeUndefinedValues` is false and `emptyObjectFields` is not "skipDefaults", then non-undefined and non-empty-object
1300
+ * values will be added based on certain conditions.
1125
1301
  *
1126
1302
  * @param obj - The object into which the computed default may be added
1127
1303
  * @param key - The key into the object at which the computed default may be added
@@ -1131,22 +1307,38 @@ function getInnerSchemaForArrayItem(schema, additionalItems, idx) {
1131
1307
  * false when computing defaults for any nested object properties. If "allowEmptyObject", prevents undefined
1132
1308
  * values in this object while allow the object itself to be empty and passing `includeUndefinedValues` as
1133
1309
  * false when computing defaults for any nested object properties.
1310
+ * @param isParentRequired - The optional boolean that indicates whether the parent field is required
1134
1311
  * @param requiredFields - The list of fields that are required
1312
+ * @param experimental_defaultFormStateBehavior - Optional configuration object, if provided, allows users to override
1313
+ * default form state behavior
1135
1314
  */
1136
- function maybeAddDefaultToObject(obj, key, computedDefault, includeUndefinedValues, requiredFields) {
1315
+ function maybeAddDefaultToObject(obj, key, computedDefault, includeUndefinedValues, isParentRequired, requiredFields, experimental_defaultFormStateBehavior) {
1137
1316
  if (requiredFields === void 0) {
1138
1317
  requiredFields = [];
1139
1318
  }
1319
+ if (experimental_defaultFormStateBehavior === void 0) {
1320
+ experimental_defaultFormStateBehavior = {};
1321
+ }
1322
+ var _experimental_default = experimental_defaultFormStateBehavior,
1323
+ _experimental_default2 = _experimental_default.emptyObjectFields,
1324
+ emptyObjectFields = _experimental_default2 === void 0 ? 'populateAllDefaults' : _experimental_default2;
1140
1325
  if (includeUndefinedValues) {
1141
1326
  obj[key] = computedDefault;
1142
- } else if (isObject(computedDefault)) {
1143
- // Store computedDefault if it's a non-empty object (e.g. not {})
1144
- if (!isEmpty(computedDefault) || requiredFields.includes(key)) {
1327
+ } else if (emptyObjectFields !== 'skipDefaults') {
1328
+ if (isObject(computedDefault)) {
1329
+ // Store computedDefault if it's a non-empty object(e.g. not {}) and satisfies certain conditions
1330
+ // Condition 1: If computedDefault is not empty or if the key is a required field
1331
+ // Condition 2: If the parent object is required or emptyObjectFields is not 'populateRequiredDefaults'
1332
+ if ((!isEmpty(computedDefault) || requiredFields.includes(key)) && (isParentRequired || emptyObjectFields !== 'populateRequiredDefaults')) {
1333
+ obj[key] = computedDefault;
1334
+ }
1335
+ } else if (
1336
+ // Store computedDefault if it's a defined primitive (e.g., true) and satisfies certain conditions
1337
+ // Condition 1: computedDefault is not undefined
1338
+ // Condition 2: If emptyObjectFields is 'populateAllDefaults' or if the key is a required field
1339
+ computedDefault !== undefined && (emptyObjectFields === 'populateAllDefaults' || requiredFields.includes(key))) {
1145
1340
  obj[key] = computedDefault;
1146
1341
  }
1147
- } else if (computedDefault !== undefined) {
1148
- // Store computedDefault if it's a defined primitive (e.g. true)
1149
- obj[key] = computedDefault;
1150
1342
  }
1151
1343
  }
1152
1344
  /** Computes the defaults for the current `schema` given the `rawFormData` and `parentDefaults` if any. This drills into
@@ -1154,29 +1346,39 @@ function maybeAddDefaultToObject(obj, key, computedDefault, includeUndefinedValu
1154
1346
  *
1155
1347
  * @param validator - an implementation of the `ValidatorType` interface that will be used when necessary
1156
1348
  * @param rawSchema - The schema for which the default state is desired
1157
- * @param [parentDefaults] - Any defaults provided by the parent field in the schema
1158
- * @param [rootSchema] - The options root schema, used to primarily to look up `$ref`s
1159
- * @param [rawFormData] - The current formData, if any, onto which to provide any missing defaults
1160
- * @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults.
1349
+ * @param [props] - Optional props for this function
1350
+ * @param [props.parentDefaults] - Any defaults provided by the parent field in the schema
1351
+ * @param [props.rootSchema] - The options root schema, used to primarily to look up `$ref`s
1352
+ * @param [props.rawFormData] - The current formData, if any, onto which to provide any missing defaults
1353
+ * @param [props.includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults.
1161
1354
  * If "excludeObjectChildren", cause undefined values for this object and pass `includeUndefinedValues` as
1162
1355
  * false when computing defaults for any nested object properties.
1163
- * @param [_recurseList=[]] - The list of ref names currently being recursed, used to prevent infinite recursion
1356
+ * @param [props._recurseList=[]] - The list of ref names currently being recursed, used to prevent infinite recursion
1357
+ * @param [props.experimental_defaultFormStateBehavior] Optional configuration object, if provided, allows users to override default form state behavior
1358
+ * @param [props.required] - Optional flag, if true, indicates this schema was required in the parent schema.
1164
1359
  * @returns - The resulting `formData` with all the defaults provided
1165
1360
  */
1166
- function computeDefaults(validator, rawSchema, parentDefaults, rootSchema, rawFormData, includeUndefinedValues, _recurseList) {
1167
- if (rootSchema === void 0) {
1168
- rootSchema = {};
1169
- }
1170
- if (includeUndefinedValues === void 0) {
1171
- includeUndefinedValues = false;
1172
- }
1173
- if (_recurseList === void 0) {
1174
- _recurseList = [];
1175
- }
1361
+ function computeDefaults(validator, rawSchema, _temp) {
1362
+ var _ref = _temp === void 0 ? {} : _temp,
1363
+ parentDefaults = _ref.parentDefaults,
1364
+ rawFormData = _ref.rawFormData,
1365
+ _ref$rootSchema = _ref.rootSchema,
1366
+ rootSchema = _ref$rootSchema === void 0 ? {} : _ref$rootSchema,
1367
+ _ref$includeUndefined = _ref.includeUndefinedValues,
1368
+ includeUndefinedValues = _ref$includeUndefined === void 0 ? false : _ref$includeUndefined,
1369
+ _ref$_recurseList = _ref._recurseList,
1370
+ _recurseList = _ref$_recurseList === void 0 ? [] : _ref$_recurseList,
1371
+ _ref$experimental_def = _ref.experimental_defaultFormStateBehavior,
1372
+ experimental_defaultFormStateBehavior = _ref$experimental_def === void 0 ? undefined : _ref$experimental_def,
1373
+ _ref$required = _ref.required,
1374
+ required = _ref$required === void 0 ? false : _ref$required;
1176
1375
  var formData = isObject(rawFormData) ? rawFormData : {};
1177
1376
  var schema = isObject(rawSchema) ? rawSchema : {};
1178
1377
  // Compute the defaults recursively: give highest priority to deepest nodes.
1179
1378
  var defaults = parentDefaults;
1379
+ // If we get a new schema, then we need to recompute defaults again for the new schema found.
1380
+ var schemaToCompute = null;
1381
+ var updatedRecurseList = _recurseList;
1180
1382
  if (isObject(defaults) && isObject(schema["default"])) {
1181
1383
  // For object defaults, only override parent defaults that are defined in
1182
1384
  // schema.default.
@@ -1187,40 +1389,68 @@ function computeDefaults(validator, rawSchema, parentDefaults, rootSchema, rawFo
1187
1389
  var refName = schema[REF_KEY];
1188
1390
  // Use referenced schema defaults for this node.
1189
1391
  if (!_recurseList.includes(refName)) {
1190
- var refSchema = findSchemaDefinition(refName, rootSchema);
1191
- return computeDefaults(validator, refSchema, defaults, rootSchema, formData, includeUndefinedValues, _recurseList.concat(refName));
1392
+ updatedRecurseList = _recurseList.concat(refName);
1393
+ schemaToCompute = findSchemaDefinition(refName, rootSchema);
1192
1394
  }
1193
1395
  } else if (DEPENDENCIES_KEY in schema) {
1194
- var resolvedSchema = resolveDependencies(validator, schema, rootSchema, formData);
1195
- return computeDefaults(validator, resolvedSchema, defaults, rootSchema, formData, includeUndefinedValues, _recurseList);
1396
+ var resolvedSchema = resolveDependencies(validator, schema, rootSchema, false, formData);
1397
+ schemaToCompute = resolvedSchema[0]; // pick the first element from resolve dependencies
1196
1398
  } else if (isFixedItems(schema)) {
1197
1399
  defaults = schema.items.map(function (itemSchema, idx) {
1198
- return computeDefaults(validator, itemSchema, Array.isArray(parentDefaults) ? parentDefaults[idx] : undefined, rootSchema, formData, includeUndefinedValues, _recurseList);
1400
+ return computeDefaults(validator, itemSchema, {
1401
+ rootSchema: rootSchema,
1402
+ includeUndefinedValues: includeUndefinedValues,
1403
+ _recurseList: _recurseList,
1404
+ experimental_defaultFormStateBehavior: experimental_defaultFormStateBehavior,
1405
+ parentDefaults: Array.isArray(parentDefaults) ? parentDefaults[idx] : undefined,
1406
+ rawFormData: formData
1407
+ });
1199
1408
  });
1200
1409
  } else if (ONE_OF_KEY in schema) {
1201
1410
  if (schema.oneOf.length === 0) {
1202
1411
  return undefined;
1203
1412
  }
1204
- schema = schema.oneOf[getClosestMatchingOption(validator, rootSchema, isEmpty(formData) ? undefined : formData, schema.oneOf, 0)];
1413
+ var discriminator = getDiscriminatorFieldFromSchema(schema);
1414
+ schemaToCompute = schema.oneOf[getClosestMatchingOption(validator, rootSchema, isEmpty(formData) ? undefined : formData, schema.oneOf, 0, discriminator)];
1205
1415
  } else if (ANY_OF_KEY in schema) {
1206
1416
  if (schema.anyOf.length === 0) {
1207
1417
  return undefined;
1208
1418
  }
1209
- schema = schema.anyOf[getClosestMatchingOption(validator, rootSchema, isEmpty(formData) ? undefined : formData, schema.anyOf, 0)];
1419
+ var _discriminator = getDiscriminatorFieldFromSchema(schema);
1420
+ schemaToCompute = schema.anyOf[getClosestMatchingOption(validator, rootSchema, isEmpty(formData) ? undefined : formData, schema.anyOf, 0, _discriminator)];
1421
+ }
1422
+ if (schemaToCompute) {
1423
+ return computeDefaults(validator, schemaToCompute, {
1424
+ rootSchema: rootSchema,
1425
+ includeUndefinedValues: includeUndefinedValues,
1426
+ _recurseList: updatedRecurseList,
1427
+ experimental_defaultFormStateBehavior: experimental_defaultFormStateBehavior,
1428
+ parentDefaults: defaults,
1429
+ rawFormData: formData
1430
+ });
1210
1431
  }
1211
- // Not defaults defined for this node, fallback to generic typed ones.
1212
- if (typeof defaults === 'undefined') {
1432
+ // No defaults defined for this node, fallback to generic typed ones.
1433
+ if (defaults === undefined) {
1213
1434
  defaults = schema["default"];
1214
1435
  }
1215
1436
  switch (getSchemaType(schema)) {
1216
- // We need to recur for object schema inner default values.
1437
+ // We need to recurse for object schema inner default values.
1217
1438
  case 'object':
1218
1439
  {
1219
1440
  var objectDefaults = Object.keys(schema.properties || {}).reduce(function (acc, key) {
1441
+ var _schema$required;
1220
1442
  // Compute the defaults for this node, with the parent defaults we might
1221
1443
  // have from a previous run: defaults[key].
1222
- var computedDefault = computeDefaults(validator, get(schema, [PROPERTIES_KEY, key]), get(defaults, [key]), rootSchema, get(formData, [key]), includeUndefinedValues === true, _recurseList);
1223
- maybeAddDefaultToObject(acc, key, computedDefault, includeUndefinedValues, schema.required);
1444
+ var computedDefault = computeDefaults(validator, get(schema, [PROPERTIES_KEY, key]), {
1445
+ rootSchema: rootSchema,
1446
+ _recurseList: _recurseList,
1447
+ experimental_defaultFormStateBehavior: experimental_defaultFormStateBehavior,
1448
+ includeUndefinedValues: includeUndefinedValues === true,
1449
+ parentDefaults: get(defaults, [key]),
1450
+ rawFormData: get(formData, [key]),
1451
+ required: (_schema$required = schema.required) === null || _schema$required === void 0 ? void 0 : _schema$required.includes(key)
1452
+ });
1453
+ maybeAddDefaultToObject(acc, key, computedDefault, includeUndefinedValues, required, schema.required, experimental_defaultFormStateBehavior);
1224
1454
  return acc;
1225
1455
  }, {});
1226
1456
  if (schema.additionalProperties) {
@@ -1234,49 +1464,82 @@ function computeDefaults(validator, rawSchema, parentDefaults, rootSchema, rawFo
1234
1464
  return keys.add(key);
1235
1465
  });
1236
1466
  }
1467
+ var formDataRequired;
1237
1468
  if (isObject(formData)) {
1469
+ formDataRequired = [];
1238
1470
  Object.keys(formData).filter(function (key) {
1239
1471
  return !schema.properties || !schema.properties[key];
1240
1472
  }).forEach(function (key) {
1241
- return keys.add(key);
1473
+ keys.add(key);
1474
+ formDataRequired.push(key);
1242
1475
  });
1243
1476
  }
1244
1477
  keys.forEach(function (key) {
1245
- var computedDefault = computeDefaults(validator, additionalPropertiesSchema, get(defaults, [key]), rootSchema, get(formData, [key]), includeUndefinedValues === true, _recurseList);
1246
- maybeAddDefaultToObject(objectDefaults, key, computedDefault, includeUndefinedValues);
1478
+ var _schema$required2;
1479
+ var computedDefault = computeDefaults(validator, additionalPropertiesSchema, {
1480
+ rootSchema: rootSchema,
1481
+ _recurseList: _recurseList,
1482
+ experimental_defaultFormStateBehavior: experimental_defaultFormStateBehavior,
1483
+ includeUndefinedValues: includeUndefinedValues === true,
1484
+ parentDefaults: get(defaults, [key]),
1485
+ rawFormData: get(formData, [key]),
1486
+ required: (_schema$required2 = schema.required) === null || _schema$required2 === void 0 ? void 0 : _schema$required2.includes(key)
1487
+ });
1488
+ // Since these are additional properties we don’t need to add the `experimental_defaultFormStateBehavior` prop
1489
+ maybeAddDefaultToObject(objectDefaults, key, computedDefault, includeUndefinedValues, required, formDataRequired);
1247
1490
  });
1248
1491
  }
1249
1492
  return objectDefaults;
1250
1493
  }
1251
1494
  case 'array':
1252
- // Inject defaults into existing array defaults
1253
- if (Array.isArray(defaults)) {
1254
- defaults = defaults.map(function (item, idx) {
1255
- var schemaItem = getInnerSchemaForArrayItem(schema, AdditionalItemsHandling.Fallback, idx);
1256
- return computeDefaults(validator, schemaItem, item, rootSchema, undefined, undefined, _recurseList);
1257
- });
1258
- }
1259
- // Deeply inject defaults into already existing form data
1260
- if (Array.isArray(rawFormData)) {
1261
- var schemaItem = getInnerSchemaForArrayItem(schema);
1262
- defaults = rawFormData.map(function (item, idx) {
1263
- return computeDefaults(validator, schemaItem, get(defaults, [idx]), rootSchema, item, undefined, _recurseList);
1264
- });
1265
- }
1266
- if (schema.minItems) {
1267
- if (!isMultiSelect(validator, schema, rootSchema)) {
1268
- var defaultsLength = Array.isArray(defaults) ? defaults.length : 0;
1269
- if (schema.minItems > defaultsLength) {
1270
- var defaultEntries = defaults || [];
1271
- // populate the array with the defaults
1272
- var fillerSchema = getInnerSchemaForArrayItem(schema, AdditionalItemsHandling.Invert);
1273
- var fillerDefault = fillerSchema["default"];
1274
- var fillerEntries = new Array(schema.minItems - defaultsLength).fill(computeDefaults(validator, fillerSchema, fillerDefault, rootSchema, undefined, undefined, _recurseList));
1275
- // then fill up the rest with either the item default or empty, up to minItems
1276
- return defaultEntries.concat(fillerEntries);
1277
- }
1495
+ {
1496
+ // Inject defaults into existing array defaults
1497
+ if (Array.isArray(defaults)) {
1498
+ defaults = defaults.map(function (item, idx) {
1499
+ var schemaItem = getInnerSchemaForArrayItem(schema, AdditionalItemsHandling.Fallback, idx);
1500
+ return computeDefaults(validator, schemaItem, {
1501
+ rootSchema: rootSchema,
1502
+ _recurseList: _recurseList,
1503
+ experimental_defaultFormStateBehavior: experimental_defaultFormStateBehavior,
1504
+ parentDefaults: item
1505
+ });
1506
+ });
1278
1507
  }
1279
- return defaults ? defaults : [];
1508
+ // Deeply inject defaults into already existing form data
1509
+ if (Array.isArray(rawFormData)) {
1510
+ var schemaItem = getInnerSchemaForArrayItem(schema);
1511
+ defaults = rawFormData.map(function (item, idx) {
1512
+ return computeDefaults(validator, schemaItem, {
1513
+ rootSchema: rootSchema,
1514
+ _recurseList: _recurseList,
1515
+ experimental_defaultFormStateBehavior: experimental_defaultFormStateBehavior,
1516
+ rawFormData: item,
1517
+ parentDefaults: get(defaults, [idx])
1518
+ });
1519
+ });
1520
+ }
1521
+ var ignoreMinItemsFlagSet = (experimental_defaultFormStateBehavior === null || experimental_defaultFormStateBehavior === void 0 ? void 0 : experimental_defaultFormStateBehavior.arrayMinItems) === 'requiredOnly';
1522
+ if (ignoreMinItemsFlagSet && !required) {
1523
+ // If no form data exists or defaults are set leave the field empty/non-existent, otherwise
1524
+ // return form data/defaults
1525
+ return defaults ? defaults : undefined;
1526
+ }
1527
+ var defaultsLength = Array.isArray(defaults) ? defaults.length : 0;
1528
+ if (!schema.minItems || isMultiSelect(validator, schema, rootSchema) || schema.minItems <= defaultsLength) {
1529
+ return defaults ? defaults : [];
1530
+ }
1531
+ var defaultEntries = defaults || [];
1532
+ var fillerSchema = getInnerSchemaForArrayItem(schema, AdditionalItemsHandling.Invert);
1533
+ var fillerDefault = fillerSchema["default"];
1534
+ // Calculate filler entries for remaining items (minItems - existing raw data/defaults)
1535
+ var fillerEntries = new Array(schema.minItems - defaultsLength).fill(computeDefaults(validator, fillerSchema, {
1536
+ parentDefaults: fillerDefault,
1537
+ rootSchema: rootSchema,
1538
+ _recurseList: _recurseList,
1539
+ experimental_defaultFormStateBehavior: experimental_defaultFormStateBehavior
1540
+ }));
1541
+ // then fill up the rest with either the item default or empty, up to minItems
1542
+ return defaultEntries.concat(fillerEntries);
1280
1543
  }
1281
1544
  }
1282
1545
  return defaults;
@@ -1291,9 +1554,10 @@ function computeDefaults(validator, rawSchema, parentDefaults, rootSchema, rawFo
1291
1554
  * @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults.
1292
1555
  * If "excludeObjectChildren", cause undefined values for this object and pass `includeUndefinedValues` as
1293
1556
  * false when computing defaults for any nested object properties.
1557
+ * @param [experimental_defaultFormStateBehavior] Optional configuration object, if provided, allows users to override default form state behavior
1294
1558
  * @returns - The resulting `formData` with all the defaults provided
1295
1559
  */
1296
- function getDefaultFormState(validator, theSchema, formData, rootSchema, includeUndefinedValues) {
1560
+ function getDefaultFormState(validator, theSchema, formData, rootSchema, includeUndefinedValues, experimental_defaultFormStateBehavior) {
1297
1561
  if (includeUndefinedValues === void 0) {
1298
1562
  includeUndefinedValues = false;
1299
1563
  }
@@ -1301,8 +1565,13 @@ function getDefaultFormState(validator, theSchema, formData, rootSchema, include
1301
1565
  throw new Error('Invalid schema: ' + theSchema);
1302
1566
  }
1303
1567
  var schema = retrieveSchema(validator, theSchema, rootSchema, formData);
1304
- var defaults = computeDefaults(validator, schema, undefined, rootSchema, formData, includeUndefinedValues);
1305
- if (typeof formData === 'undefined' || formData === null || typeof formData === 'number' && isNaN(formData)) {
1568
+ var defaults = computeDefaults(validator, schema, {
1569
+ rootSchema: rootSchema,
1570
+ includeUndefinedValues: includeUndefinedValues,
1571
+ experimental_defaultFormStateBehavior: experimental_defaultFormStateBehavior,
1572
+ rawFormData: formData
1573
+ });
1574
+ if (formData === undefined || formData === null || typeof formData === 'number' && isNaN(formData)) {
1306
1575
  // No form data? Use schema defaults.
1307
1576
  return defaults;
1308
1577
  }
@@ -1672,15 +1941,12 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
1672
1941
  }
1673
1942
  }
1674
1943
  var pathSchema = (_pathSchema = {}, _pathSchema[NAME_KEY] = name.replace(/^\./, ''), _pathSchema);
1675
- if (ONE_OF_KEY in schema) {
1676
- var index = getClosestMatchingOption(validator, rootSchema, formData, schema.oneOf, 0);
1677
- var _schema2 = schema.oneOf[index];
1678
- return toPathSchemaInternal(validator, _schema2, name, rootSchema, formData, _recurseList);
1679
- }
1680
- if (ANY_OF_KEY in schema) {
1681
- var _index = getClosestMatchingOption(validator, rootSchema, formData, schema.anyOf, 0);
1682
- var _schema3 = schema.anyOf[_index];
1683
- return toPathSchemaInternal(validator, _schema3, name, rootSchema, formData, _recurseList);
1944
+ if (ONE_OF_KEY in schema || ANY_OF_KEY in schema) {
1945
+ var xxxOf = ONE_OF_KEY in schema ? schema.oneOf : schema.anyOf;
1946
+ var discriminator = getDiscriminatorFieldFromSchema(schema);
1947
+ var index = getClosestMatchingOption(validator, rootSchema, formData, xxxOf, 0, discriminator);
1948
+ var _schema2 = xxxOf[index];
1949
+ pathSchema = _extends({}, pathSchema, toPathSchemaInternal(validator, _schema2, name, rootSchema, formData, _recurseList));
1684
1950
  }
1685
1951
  if (ADDITIONAL_PROPERTIES_KEY in schema && schema[ADDITIONAL_PROPERTIES_KEY] !== false) {
1686
1952
  set(pathSchema, RJSF_ADDITONAL_PROPERTIES_FLAG, true);
@@ -1717,8 +1983,8 @@ function toPathSchema(validator, schema, name, rootSchema, formData) {
1717
1983
  }
1718
1984
 
1719
1985
  /** The `SchemaUtils` class provides a wrapper around the publicly exported APIs in the `utils/schema` directory such
1720
- * that one does not have to explicitly pass the `validator` or `rootSchema` to each method. Since both the `validator`
1721
- * and `rootSchema` generally does not change across a `Form`, this allows for providing a simplified set of APIs to the
1986
+ * that one does not have to explicitly pass the `validator`, `rootSchema`, or `experimental_defaultFormStateBehavior` to each method.
1987
+ * Since these generally do not change across a `Form`, this allows for providing a simplified set of APIs to the
1722
1988
  * `@rjsf/core` components and the various themes as well. This class implements the `SchemaUtilsType` interface.
1723
1989
  */
1724
1990
  var SchemaUtils = /*#__PURE__*/function () {
@@ -1726,12 +1992,15 @@ var SchemaUtils = /*#__PURE__*/function () {
1726
1992
  *
1727
1993
  * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
1728
1994
  * @param rootSchema - The root schema that will be forwarded to all the APIs
1995
+ * @param experimental_defaultFormStateBehavior - Configuration flags to allow users to override default form state behavior
1729
1996
  */
1730
- function SchemaUtils(validator, rootSchema) {
1997
+ function SchemaUtils(validator, rootSchema, experimental_defaultFormStateBehavior) {
1731
1998
  this.rootSchema = void 0;
1732
1999
  this.validator = void 0;
2000
+ this.experimental_defaultFormStateBehavior = void 0;
1733
2001
  this.rootSchema = rootSchema;
1734
2002
  this.validator = validator;
2003
+ this.experimental_defaultFormStateBehavior = experimental_defaultFormStateBehavior;
1735
2004
  }
1736
2005
  /** Returns the `ValidatorType` in the `SchemaUtilsType`
1737
2006
  *
@@ -1747,13 +2016,17 @@ var SchemaUtils = /*#__PURE__*/function () {
1747
2016
  *
1748
2017
  * @param validator - An implementation of the `ValidatorType` interface that will be compared against the current one
1749
2018
  * @param rootSchema - The root schema that will be compared against the current one
2019
+ * @param [experimental_defaultFormStateBehavior] Optional configuration object, if provided, allows users to override default form state behavior
1750
2020
  * @returns - True if the `SchemaUtilsType` differs from the given `validator` or `rootSchema`
1751
2021
  */;
1752
- _proto.doesSchemaUtilsDiffer = function doesSchemaUtilsDiffer(validator, rootSchema) {
2022
+ _proto.doesSchemaUtilsDiffer = function doesSchemaUtilsDiffer(validator, rootSchema, experimental_defaultFormStateBehavior) {
2023
+ if (experimental_defaultFormStateBehavior === void 0) {
2024
+ experimental_defaultFormStateBehavior = {};
2025
+ }
1753
2026
  if (!validator || !rootSchema) {
1754
2027
  return false;
1755
2028
  }
1756
- return this.validator !== validator || !deepEquals(this.rootSchema, rootSchema);
2029
+ return this.validator !== validator || !deepEquals(this.rootSchema, rootSchema) || !deepEquals(this.experimental_defaultFormStateBehavior, experimental_defaultFormStateBehavior);
1757
2030
  }
1758
2031
  /** Returns the superset of `formData` that includes the given set updated to include any missing fields that have
1759
2032
  * computed to have defaults provided in the `schema`.
@@ -1769,7 +2042,7 @@ var SchemaUtils = /*#__PURE__*/function () {
1769
2042
  if (includeUndefinedValues === void 0) {
1770
2043
  includeUndefinedValues = false;
1771
2044
  }
1772
- return getDefaultFormState(this.validator, schema, formData, this.rootSchema, includeUndefinedValues);
2045
+ return getDefaultFormState(this.validator, schema, formData, this.rootSchema, includeUndefinedValues, this.experimental_defaultFormStateBehavior);
1773
2046
  }
1774
2047
  /** Determines whether the combination of `schema` and `uiSchema` properties indicates that the label for the `schema`
1775
2048
  * should be displayed in a UI.
@@ -1922,10 +2195,14 @@ var SchemaUtils = /*#__PURE__*/function () {
1922
2195
  *
1923
2196
  * @param validator - an implementation of the `ValidatorType` interface that will be forwarded to all the APIs
1924
2197
  * @param rootSchema - The root schema that will be forwarded to all the APIs
2198
+ * @param [experimental_defaultFormStateBehavior] Optional configuration object, if provided, allows users to override default form state behavior
1925
2199
  * @returns - An implementation of a `SchemaUtilsType` interface
1926
2200
  */
1927
- function createSchemaUtils(validator, rootSchema) {
1928
- return new SchemaUtils(validator, rootSchema);
2201
+ function createSchemaUtils(validator, rootSchema, experimental_defaultFormStateBehavior) {
2202
+ if (experimental_defaultFormStateBehavior === void 0) {
2203
+ experimental_defaultFormStateBehavior = {};
2204
+ }
2205
+ return new SchemaUtils(validator, rootSchema, experimental_defaultFormStateBehavior);
1929
2206
  }
1930
2207
 
1931
2208
  /** Given the `FileReader.readAsDataURL()` based `dataURI` extracts that data into an actual Blob along with the name
@@ -2480,6 +2757,32 @@ function getWidget(schema, widget, registeredWidgets) {
2480
2757
  throw new Error("No widget '" + widget + "' for type '" + type + "'");
2481
2758
  }
2482
2759
 
2760
+ /** JS has no built-in hashing function, so rolling our own
2761
+ * based on Java's hashing fn:
2762
+ * http://www.java2s.com/example/nodejs-utility-method/string-hash/hashcode-4dc2b.html
2763
+ *
2764
+ * @param string - The string for which to get the hash
2765
+ * @returns - The resulting hash of the string in hex format
2766
+ */
2767
+ function hashString(string) {
2768
+ var hash = 0;
2769
+ for (var i = 0; i < string.length; i += 1) {
2770
+ var chr = string.charCodeAt(i);
2771
+ hash = (hash << 5) - hash + chr;
2772
+ hash = hash & hash; // Convert to 32bit integer
2773
+ }
2774
+
2775
+ return hash.toString(16);
2776
+ }
2777
+ /** Stringifies the schema and returns the hash of the resulting string.
2778
+ *
2779
+ * @param schema - The schema for which the hash is desired
2780
+ * @returns - The string obtained from the hash of the stringified schema
2781
+ */
2782
+ function hashForSchema(schema) {
2783
+ return hashString(JSON.stringify(schema));
2784
+ }
2785
+
2483
2786
  /** Detects whether the `widget` exists for the `schema` with the associated `registryWidgets` and returns true if it
2484
2787
  * does, or false if it doesn't.
2485
2788
  *
@@ -3083,5 +3386,140 @@ var TranslatableString;
3083
3386
  TranslatableString["FilesInfo"] = "<strong>%1</strong> (%2, %3 bytes)";
3084
3387
  })(TranslatableString || (TranslatableString = {}));
3085
3388
 
3086
- 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, ErrorSchemaBuilder, ID_KEY, ITEMS_KEY, NAME_KEY, ONE_OF_KEY, PROPERTIES_KEY, REF_KEY, REQUIRED_KEY, RJSF_ADDITONAL_PROPERTIES_FLAG, ROOT_SCHEMA_PREFIX, SUBMIT_BTN_OPTIONS_KEY, TranslatableString, UI_FIELD_KEY, UI_GLOBAL_OPTIONS_KEY, UI_OPTIONS_KEY, UI_WIDGET_KEY, allowAdditionalItems, ariaDescribedByIds, asNumber, canExpand, createErrorHandler, createSchemaUtils, dataURItoBlob, deepEquals, descriptionId, englishStringTranslator, enumOptionsDeselectValue, enumOptionsIndexForValue, enumOptionsIsSelected, enumOptionsSelectValue, enumOptionsValueForIndex, errorId, examplesId, findSchemaDefinition, getClosestMatchingOption, getDefaultFormState, getDisplayLabel, getFirstMatchingOption, getInputProps, getMatchingOption, getSchemaType, getSubmitButtonOptions, getTemplate, getUiOptions, getWidget, guessType, hasWidget, helpId, isConstant, isCustomWidget, isFilesArray, isFixedItems, isMultiSelect, isObject, isSelect, labelValue, localToUTC, mergeDefaultsWithFormData, mergeObjects, mergeSchemas, mergeValidationData, optionId, optionsList, orderProperties, pad, parseDateString, rangeSpec, replaceStringParameters, retrieveSchema, sanitizeDataForNewSchema, schemaRequiresTrueValue, shouldRender, titleId, toConstant, toDateString, toErrorList, toErrorSchema, toIdSchema, toPathSchema, unwrapErrorHandler, utcToLocal, validationDataMerge, withIdRefPrefix };
3389
+ /** An implementation of the `ValidatorType` interface that is designed for use in capturing schemas used by the
3390
+ * `isValid()` function. The rest of the implementation of the interface throws errors when it is attempted to be used.
3391
+ * An instance of the object allows the caller to capture the schemas used in calls to the `isValid()` function. These
3392
+ * captured schema, along with the root schema used to construct the object are stored in the map of schemas keyed by
3393
+ * the hashed value of the schema. NOTE: After hashing the schema, an $id with the hash value is added to the
3394
+ * schema IF that schema doesn't already have an $id, prior to putting the schema into the map.
3395
+ */
3396
+ var ParserValidator = /*#__PURE__*/function () {
3397
+ /** Construct the ParserValidator for the given `rootSchema`. This `rootSchema` will be stashed in the `schemaMap`
3398
+ * first.
3399
+ *
3400
+ * @param rootSchema - The root schema against which this validator will be executed
3401
+ */
3402
+ function ParserValidator(rootSchema) {
3403
+ /** The rootSchema provided during construction of the class */
3404
+ this.rootSchema = void 0;
3405
+ /** The map of schemas encountered by the ParserValidator */
3406
+ this.schemaMap = {};
3407
+ this.rootSchema = rootSchema;
3408
+ this.addSchema(rootSchema, hashForSchema(rootSchema));
3409
+ }
3410
+ /** Adds the given `schema` to the `schemaMap` keyed by the `hash` or `ID_KEY` if present on the `schema`. If the
3411
+ * schema does not have an `ID_KEY`, then the `hash` will be added as the `ID_KEY` to allow the schema to be
3412
+ * associated with it's `hash` for future use (by a schema compiler).
3413
+ *
3414
+ * @param schema - The schema which is to be added to the map
3415
+ * @param hash - The hash value at which to map the schema
3416
+ */
3417
+ var _proto = ParserValidator.prototype;
3418
+ _proto.addSchema = function addSchema(schema, hash) {
3419
+ var _extends2;
3420
+ var key = get(schema, ID_KEY, hash);
3421
+ var identifiedSchema = _extends({}, schema, (_extends2 = {}, _extends2[ID_KEY] = key, _extends2));
3422
+ var existing = this.schemaMap[key];
3423
+ if (!existing) {
3424
+ this.schemaMap[key] = identifiedSchema;
3425
+ } else if (!isEqual(existing, identifiedSchema)) {
3426
+ console.error('existing schema:', JSON.stringify(existing, null, 2));
3427
+ console.error('new schema:', JSON.stringify(identifiedSchema, null, 2));
3428
+ throw new Error("Two different schemas exist with the same key " + key + "! What a bad coincidence. If possible, try adding an $id to one of the schemas");
3429
+ }
3430
+ }
3431
+ /** Returns the current `schemaMap` to the caller
3432
+ */;
3433
+ _proto.getSchemaMap = function getSchemaMap() {
3434
+ return this.schemaMap;
3435
+ }
3436
+ /** Implements the `ValidatorType` `isValid()` method to capture the `schema` in the `schemaMap`. Throws an error when
3437
+ * the `rootSchema` is not the same as the root schema provided during construction.
3438
+ *
3439
+ * @param schema - The schema to record in the `schemaMap`
3440
+ * @param _formData - The formData parameter that is ignored
3441
+ * @param rootSchema - The root schema associated with the schema
3442
+ * @throws - Error when the given `rootSchema` differs from the root schema provided during construction
3443
+ */;
3444
+ _proto.isValid = function isValid(schema, _formData, rootSchema) {
3445
+ if (!isEqual(rootSchema, this.rootSchema)) {
3446
+ throw new Error('Unexpectedly calling isValid() with a rootSchema that differs from the construction rootSchema');
3447
+ }
3448
+ this.addSchema(schema, hashForSchema(schema));
3449
+ return false;
3450
+ }
3451
+ /** Implements the `ValidatorType` `rawValidation()` method to throw an error since it is never supposed to be called
3452
+ *
3453
+ * @param _schema - The schema parameter that is ignored
3454
+ * @param _formData - The formData parameter that is ignored
3455
+ */;
3456
+ _proto.rawValidation = function rawValidation(_schema, _formData) {
3457
+ throw new Error('Unexpectedly calling the `rawValidation()` method during schema parsing');
3458
+ }
3459
+ /** Implements the `ValidatorType` `toErrorList()` method to throw an error since it is never supposed to be called
3460
+ *
3461
+ * @param _errorSchema - The error schema parameter that is ignored
3462
+ * @param _fieldPath - The field path parameter that is ignored
3463
+ */;
3464
+ _proto.toErrorList = function toErrorList(_errorSchema, _fieldPath) {
3465
+ throw new Error('Unexpectedly calling the `toErrorList()` method during schema parsing');
3466
+ }
3467
+ /** Implements the `ValidatorType` `validateFormData()` method to throw an error since it is never supposed to be
3468
+ * called
3469
+ *
3470
+ * @param _formData - The formData parameter that is ignored
3471
+ * @param _schema - The schema parameter that is ignored
3472
+ * @param _customValidate - The customValidate parameter that is ignored
3473
+ * @param _transformErrors - The transformErrors parameter that is ignored
3474
+ * @param _uiSchema - The uiSchema parameter that is ignored
3475
+ */;
3476
+ _proto.validateFormData = function validateFormData(_formData, _schema, _customValidate, _transformErrors, _uiSchema) {
3477
+ throw new Error('Unexpectedly calling the `validateFormData()` method during schema parsing');
3478
+ };
3479
+ return ParserValidator;
3480
+ }();
3481
+
3482
+ /** Recursive function used to parse the given `schema` belonging to the `rootSchema`. The `validator` is used to
3483
+ * capture the sub-schemas that the `isValid()` function is called with. For each schema returned by the
3484
+ * `retrieveSchemaInternal()`, the `resolveAnyOrOneOfSchemas()` function is called. For each of the schemas returned
3485
+ * from THAT call have `properties`, then each of the sub-schema property objects are then recursively parsed.
3486
+ *
3487
+ * @param validator - The `ParserValidator` implementation used to capture `isValid()` calls during parsing
3488
+ * @param recurseList - The list of schemas returned from the `retrieveSchemaInternal`, preventing infinite recursion
3489
+ * @param rootSchema - The root schema from which the schema parsing began
3490
+ * @param schema - The current schema element being parsed
3491
+ */
3492
+ function parseSchema(validator, recurseList, rootSchema, schema) {
3493
+ var schemas = retrieveSchemaInternal(validator, schema, rootSchema, undefined, true);
3494
+ schemas.forEach(function (schema) {
3495
+ var sameSchemaIndex = recurseList.findIndex(function (item) {
3496
+ return isEqual(item, schema);
3497
+ });
3498
+ if (sameSchemaIndex === -1) {
3499
+ recurseList.push(schema);
3500
+ var allOptions = resolveAnyOrOneOfSchemas(validator, schema, rootSchema, true);
3501
+ allOptions.forEach(function (s) {
3502
+ if (PROPERTIES_KEY in s && s[PROPERTIES_KEY]) {
3503
+ forEach(schema[PROPERTIES_KEY], function (value) {
3504
+ parseSchema(validator, recurseList, rootSchema, value);
3505
+ });
3506
+ }
3507
+ });
3508
+ }
3509
+ });
3510
+ }
3511
+ /** Parses the given `rootSchema` to extract out all the sub-schemas that maybe contained within it. Returns a map of
3512
+ * the hash of the schema to schema/sub-schema.
3513
+ *
3514
+ * @param rootSchema - The root schema to parse for sub-schemas used by `isValid()` calls
3515
+ * @returns - The `SchemaMap` of all schemas that were parsed
3516
+ */
3517
+ function schemaParser(rootSchema) {
3518
+ var validator = new ParserValidator(rootSchema);
3519
+ var recurseList = [];
3520
+ parseSchema(validator, recurseList, rootSchema, rootSchema);
3521
+ return validator.getSchemaMap();
3522
+ }
3523
+
3524
+ 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, ErrorSchemaBuilder, ID_KEY, IF_KEY, ITEMS_KEY, NAME_KEY, ONE_OF_KEY, PROPERTIES_KEY, REF_KEY, REQUIRED_KEY, RJSF_ADDITONAL_PROPERTIES_FLAG, ROOT_SCHEMA_PREFIX, SUBMIT_BTN_OPTIONS_KEY, TranslatableString, UI_FIELD_KEY, UI_GLOBAL_OPTIONS_KEY, UI_OPTIONS_KEY, UI_WIDGET_KEY, allowAdditionalItems, ariaDescribedByIds, asNumber, canExpand, createErrorHandler, createSchemaUtils, dataURItoBlob, deepEquals, descriptionId, englishStringTranslator, enumOptionsDeselectValue, enumOptionsIndexForValue, enumOptionsIsSelected, enumOptionsSelectValue, enumOptionsValueForIndex, errorId, examplesId, findSchemaDefinition, getClosestMatchingOption, getDefaultFormState, getDiscriminatorFieldFromSchema, getDisplayLabel, getFirstMatchingOption, getInputProps, getMatchingOption, getSchemaType, getSubmitButtonOptions, getTemplate, getUiOptions, getWidget, guessType, hasWidget, hashForSchema, helpId, isConstant, isCustomWidget, isFilesArray, isFixedItems, isMultiSelect, isObject, isSelect, labelValue, localToUTC, mergeDefaultsWithFormData, mergeObjects, mergeSchemas, mergeValidationData, optionId, optionsList, orderProperties, pad, parseDateString, rangeSpec, replaceStringParameters, retrieveSchema, sanitizeDataForNewSchema, schemaParser, schemaRequiresTrueValue, shouldRender, titleId, toConstant, toDateString, toErrorList, toErrorSchema, toIdSchema, toPathSchema, unwrapErrorHandler, utcToLocal, validationDataMerge, withIdRefPrefix };
3087
3525
  //# sourceMappingURL=utils.esm.js.map