@rjsf/utils 6.0.0-beta.17 → 6.0.0-beta.19

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
@@ -537,7 +537,8 @@ function resolveSchema(validator, schema, rootSchema, expandAllBranches, recurse
537
537
  rootSchema,
538
538
  expandAllBranches,
539
539
  recurseList,
540
- formData
540
+ formData,
541
+ experimental_customMergeAllOf
541
542
  );
542
543
  if (updatedSchemas.length > 1 || updatedSchemas[0] !== schema) {
543
544
  return updatedSchemas;
@@ -549,7 +550,8 @@ function resolveSchema(validator, schema, rootSchema, expandAllBranches, recurse
549
550
  rootSchema,
550
551
  expandAllBranches,
551
552
  recurseList,
552
- formData
553
+ formData,
554
+ experimental_customMergeAllOf
553
555
  );
554
556
  return resolvedSchemas.flatMap((s) => {
555
557
  return retrieveSchemaInternal(
@@ -1432,6 +1434,11 @@ function getInnerSchemaForArrayItem(schema, additionalItems = 0 /* Ignore */, id
1432
1434
  }
1433
1435
  return {};
1434
1436
  }
1437
+ function computeDefaultBasedOnSchemaTypeAndDefaults(schema, computedDefault) {
1438
+ const { default: schemaDefault, type } = schema;
1439
+ const shouldReturnNullAsDefault = Array.isArray(type) && type.includes("null") && isEmpty4(computedDefault) && schemaDefault === null;
1440
+ return shouldReturnNullAsDefault ? null : computedDefault;
1441
+ }
1435
1442
  function maybeAddDefaultToObject(obj, key, computedDefault, includeUndefinedValues, isParentRequired, requiredFields = [], experimental_defaultFormStateBehavior = {}, isConst = false) {
1436
1443
  const { emptyObjectFields = "populateAllDefaults" } = experimental_defaultFormStateBehavior;
1437
1444
  if (includeUndefinedValues === true || isConst) {
@@ -1698,7 +1705,7 @@ function getObjectDefaults(validator, rawSchema, {
1698
1705
  );
1699
1706
  });
1700
1707
  }
1701
- return objectDefaults;
1708
+ return computeDefaultBasedOnSchemaTypeAndDefaults(rawSchema, objectDefaults);
1702
1709
  }
1703
1710
  }
1704
1711
  function getArrayDefaults(validator, rawSchema, {
@@ -1763,26 +1770,29 @@ function getArrayDefaults(validator, rawSchema, {
1763
1770
  return defaults ? defaults : void 0;
1764
1771
  }
1765
1772
  }
1773
+ let arrayDefault;
1766
1774
  const defaultsLength = Array.isArray(defaults) ? defaults.length : 0;
1767
1775
  if (!schema.minItems || isMultiSelect(validator, schema, rootSchema, experimental_customMergeAllOf) || computeSkipPopulate(validator, schema, rootSchema) || schema.minItems <= defaultsLength) {
1768
- return defaults ? defaults : emptyDefault;
1769
- }
1770
- const defaultEntries = defaults || [];
1771
- const fillerSchema = getInnerSchemaForArrayItem(schema, 1 /* Invert */);
1772
- const fillerDefault = fillerSchema.default;
1773
- const fillerEntries = Array.from(
1774
- { length: schema.minItems - defaultsLength },
1775
- () => computeDefaults(validator, fillerSchema, {
1776
- parentDefaults: fillerDefault,
1777
- rootSchema,
1778
- _recurseList,
1779
- experimental_defaultFormStateBehavior,
1780
- experimental_customMergeAllOf,
1781
- required,
1782
- shouldMergeDefaultsIntoFormData
1783
- })
1784
- );
1785
- return defaultEntries.concat(fillerEntries);
1776
+ arrayDefault = defaults ? defaults : emptyDefault;
1777
+ } else {
1778
+ const defaultEntries = defaults || [];
1779
+ const fillerSchema = getInnerSchemaForArrayItem(schema, 1 /* Invert */);
1780
+ const fillerDefault = fillerSchema.default;
1781
+ const fillerEntries = Array.from(
1782
+ { length: schema.minItems - defaultsLength },
1783
+ () => computeDefaults(validator, fillerSchema, {
1784
+ parentDefaults: fillerDefault,
1785
+ rootSchema,
1786
+ _recurseList,
1787
+ experimental_defaultFormStateBehavior,
1788
+ experimental_customMergeAllOf,
1789
+ required,
1790
+ shouldMergeDefaultsIntoFormData
1791
+ })
1792
+ );
1793
+ arrayDefault = defaultEntries.concat(fillerEntries);
1794
+ }
1795
+ return computeDefaultBasedOnSchemaTypeAndDefaults(rawSchema, arrayDefault);
1786
1796
  }
1787
1797
  function getDefaultBasedOnSchemaType(validator, rawSchema, computeDefaultsProps = {}, defaults) {
1788
1798
  switch (getSchemaType(rawSchema)) {