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