@rjsf/utils 5.0.0-beta.12 → 5.0.0-beta.14

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.
@@ -405,7 +405,9 @@
405
405
  *
406
406
  * @param obj1 - The first object to merge
407
407
  * @param obj2 - The second object to merge
408
- * @param [concatArrays=false] - Optional flag that, when true, will cause arrays to be concatenated
408
+ * @param [concatArrays=false] - Optional flag that, when true, will cause arrays to be concatenated. Use
409
+ * "preventDuplicates" to merge arrays in a manner that prevents any duplicate entries from being merged.
410
+ * NOTE: Uses shallow comparison for the duplicate checking.
409
411
  * @returns - A new object that is the merge of the two given objects
410
412
  */
411
413
  function mergeObjects(obj1, obj2, concatArrays) {
@@ -418,7 +420,16 @@
418
420
  if (obj1 && key in obj1 && isObject(right)) {
419
421
  acc[key] = mergeObjects(left, right, concatArrays);
420
422
  } else if (concatArrays && Array.isArray(left) && Array.isArray(right)) {
421
- acc[key] = left.concat(right);
423
+ let toMerge = right;
424
+ if (concatArrays === "preventDuplicates") {
425
+ toMerge = right.reduce((result, value) => {
426
+ if (!left.includes(value)) {
427
+ result.push(value);
428
+ }
429
+ return result;
430
+ }, []);
431
+ }
432
+ acc[key] = left.concat(toMerge);
422
433
  } else {
423
434
  acc[key] = right;
424
435
  }
@@ -878,7 +889,9 @@
878
889
  * @param [parentDefaults] - Any defaults provided by the parent field in the schema
879
890
  * @param [rootSchema] - The options root schema, used to primarily to look up `$ref`s
880
891
  * @param [rawFormData] - The current formData, if any, onto which to provide any missing defaults
881
- * @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults
892
+ * @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults.
893
+ * If "excludeObjectChildren", pass `includeUndefinedValues` as false when computing defaults for any nested
894
+ * object properties.
882
895
  * @returns - The resulting `formData` with all the defaults provided
883
896
  */
884
897
  function computeDefaults(validator, schema, parentDefaults, rootSchema, rawFormData, includeUndefinedValues) {
@@ -921,8 +934,16 @@
921
934
  return Object.keys(schema.properties || {}).reduce((acc, key) => {
922
935
  // Compute the defaults for this node, with the parent defaults we might
923
936
  // have from a previous run: defaults[key].
924
- const computedDefault = computeDefaults(validator, get__default["default"](schema, [PROPERTIES_KEY, key]), get__default["default"](defaults, [key]), rootSchema, get__default["default"](formData, [key]), includeUndefinedValues);
925
- if (includeUndefinedValues || computedDefault !== undefined) {
937
+ const computedDefault = computeDefaults(validator, get__default["default"](schema, [PROPERTIES_KEY, key]), get__default["default"](defaults, [key]), rootSchema, get__default["default"](formData, [key]), includeUndefinedValues === "excludeObjectChildren" ? false : includeUndefinedValues);
938
+ if (includeUndefinedValues) {
939
+ acc[key] = computedDefault;
940
+ } else if (isObject(computedDefault)) {
941
+ // Store computedDefault if it's a non-empty object (e.g. not {})
942
+ if (!isEmpty__default["default"](computedDefault)) {
943
+ acc[key] = computedDefault;
944
+ }
945
+ } else if (computedDefault !== undefined) {
946
+ // Store computedDefault if it's a defined primitive (e.g. true)
926
947
  acc[key] = computedDefault;
927
948
  }
928
949
  return acc;
@@ -967,7 +988,9 @@
967
988
  * @param theSchema - The schema for which the default state is desired
968
989
  * @param [formData] - The current formData, if any, onto which to provide any missing defaults
969
990
  * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
970
- * @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults
991
+ * @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults.
992
+ * If "excludeObjectChildren", pass `includeUndefinedValues` as false when computing defaults for any nested
993
+ * object properties.
971
994
  * @returns - The resulting `formData` with all the defaults provided
972
995
  */
973
996
  function getDefaultFormState(validator, theSchema, formData, rootSchema, includeUndefinedValues) {
@@ -1218,7 +1241,9 @@
1218
1241
  *
1219
1242
  * @param schema - The schema for which the default state is desired
1220
1243
  * @param [formData] - The current formData, if any, onto which to provide any missing defaults
1221
- * @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults
1244
+ * @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults.
1245
+ * If "excludeObjectChildren", pass `includeUndefinedValues` as false when computing defaults for any nested
1246
+ * object properties.
1222
1247
  * @returns - The resulting `formData` with all the defaults provided
1223
1248
  */
1224
1249
  getDefaultFormState(schema, formData, includeUndefinedValues) {