@rjsf/utils 6.0.0-beta.16 → 6.0.0-beta.18

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