@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/index.cjs CHANGED
@@ -1585,6 +1585,11 @@ function getInnerSchemaForArrayItem(schema, additionalItems = 0 /* Ignore */, id
1585
1585
  }
1586
1586
  return {};
1587
1587
  }
1588
+ function computeDefaultBasedOnSchemaTypeAndDefaults(schema, computedDefault) {
1589
+ const { default: schemaDefault, type } = schema;
1590
+ const shouldReturnNullAsDefault = Array.isArray(type) && type.includes("null") && (0, import_isEmpty4.default)(computedDefault) && schemaDefault === null;
1591
+ return shouldReturnNullAsDefault ? null : computedDefault;
1592
+ }
1588
1593
  function maybeAddDefaultToObject(obj, key, computedDefault, includeUndefinedValues, isParentRequired, requiredFields = [], experimental_defaultFormStateBehavior = {}, isConst = false) {
1589
1594
  const { emptyObjectFields = "populateAllDefaults" } = experimental_defaultFormStateBehavior;
1590
1595
  if (includeUndefinedValues === true || isConst) {
@@ -1851,7 +1856,7 @@ function getObjectDefaults(validator, rawSchema, {
1851
1856
  );
1852
1857
  });
1853
1858
  }
1854
- return objectDefaults;
1859
+ return computeDefaultBasedOnSchemaTypeAndDefaults(rawSchema, objectDefaults);
1855
1860
  }
1856
1861
  }
1857
1862
  function getArrayDefaults(validator, rawSchema, {
@@ -1916,26 +1921,29 @@ function getArrayDefaults(validator, rawSchema, {
1916
1921
  return defaults ? defaults : void 0;
1917
1922
  }
1918
1923
  }
1924
+ let arrayDefault;
1919
1925
  const defaultsLength = Array.isArray(defaults) ? defaults.length : 0;
1920
1926
  if (!schema.minItems || isMultiSelect(validator, schema, rootSchema, experimental_customMergeAllOf) || computeSkipPopulate(validator, schema, rootSchema) || schema.minItems <= defaultsLength) {
1921
- return defaults ? defaults : emptyDefault;
1922
- }
1923
- const defaultEntries = defaults || [];
1924
- const fillerSchema = getInnerSchemaForArrayItem(schema, 1 /* Invert */);
1925
- const fillerDefault = fillerSchema.default;
1926
- const fillerEntries = Array.from(
1927
- { length: schema.minItems - defaultsLength },
1928
- () => computeDefaults(validator, fillerSchema, {
1929
- parentDefaults: fillerDefault,
1930
- rootSchema,
1931
- _recurseList,
1932
- experimental_defaultFormStateBehavior,
1933
- experimental_customMergeAllOf,
1934
- required,
1935
- shouldMergeDefaultsIntoFormData
1936
- })
1937
- );
1938
- return defaultEntries.concat(fillerEntries);
1927
+ arrayDefault = defaults ? defaults : emptyDefault;
1928
+ } else {
1929
+ const defaultEntries = defaults || [];
1930
+ const fillerSchema = getInnerSchemaForArrayItem(schema, 1 /* Invert */);
1931
+ const fillerDefault = fillerSchema.default;
1932
+ const fillerEntries = Array.from(
1933
+ { length: schema.minItems - defaultsLength },
1934
+ () => computeDefaults(validator, fillerSchema, {
1935
+ parentDefaults: fillerDefault,
1936
+ rootSchema,
1937
+ _recurseList,
1938
+ experimental_defaultFormStateBehavior,
1939
+ experimental_customMergeAllOf,
1940
+ required,
1941
+ shouldMergeDefaultsIntoFormData
1942
+ })
1943
+ );
1944
+ arrayDefault = defaultEntries.concat(fillerEntries);
1945
+ }
1946
+ return computeDefaultBasedOnSchemaTypeAndDefaults(rawSchema, arrayDefault);
1939
1947
  }
1940
1948
  function getDefaultBasedOnSchemaType(validator, rawSchema, computeDefaultsProps = {}, defaults) {
1941
1949
  switch (getSchemaType(rawSchema)) {