@rjsf/utils 5.17.1 → 5.18.0

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.js CHANGED
@@ -1090,14 +1090,18 @@ function maybeAddDefaultToObject(obj, key, computedDefault, includeUndefinedValu
1090
1090
  } else if (emptyObjectFields !== "skipDefaults") {
1091
1091
  if (isObject(computedDefault)) {
1092
1092
  const isSelfOrParentRequired = isParentRequired === void 0 ? requiredFields.includes(key) : isParentRequired;
1093
- if ((!(0, import_isEmpty.default)(computedDefault) || requiredFields.includes(key)) && (isSelfOrParentRequired || emptyObjectFields !== "populateRequiredDefaults")) {
1093
+ if (emptyObjectFields === "skipEmptyDefaults") {
1094
+ if (!(0, import_isEmpty.default)(computedDefault)) {
1095
+ obj[key] = computedDefault;
1096
+ }
1097
+ } else if ((!(0, import_isEmpty.default)(computedDefault) || requiredFields.includes(key)) && (isSelfOrParentRequired || emptyObjectFields !== "populateRequiredDefaults")) {
1094
1098
  obj[key] = computedDefault;
1095
1099
  }
1096
1100
  } else if (
1097
1101
  // Store computedDefault if it's a defined primitive (e.g., true) and satisfies certain conditions
1098
1102
  // Condition 1: computedDefault is not undefined
1099
- // Condition 2: If emptyObjectFields is 'populateAllDefaults' or if the key is a required field
1100
- computedDefault !== void 0 && (emptyObjectFields === "populateAllDefaults" || requiredFields.includes(key))
1103
+ // Condition 2: If emptyObjectFields is 'populateAllDefaults' or 'skipEmptyDefaults) or if the key is a required field
1104
+ computedDefault !== void 0 && (emptyObjectFields === "populateAllDefaults" || emptyObjectFields === "skipEmptyDefaults" || requiredFields.includes(key))
1101
1105
  ) {
1102
1106
  obj[key] = computedDefault;
1103
1107
  }
@@ -1250,6 +1254,9 @@ function computeDefaults(validator, rawSchema, {
1250
1254
  case "array": {
1251
1255
  const neverPopulate = experimental_defaultFormStateBehavior?.arrayMinItems?.populate === "never";
1252
1256
  const ignoreMinItemsFlagSet = experimental_defaultFormStateBehavior?.arrayMinItems?.populate === "requiredOnly";
1257
+ const isSkipEmptyDefaults = experimental_defaultFormStateBehavior?.emptyObjectFields === "skipEmptyDefaults";
1258
+ const computeSkipPopulate = experimental_defaultFormStateBehavior?.arrayMinItems?.computeSkipPopulate ?? (() => false);
1259
+ const emptyDefault = isSkipEmptyDefaults ? void 0 : [];
1253
1260
  if (Array.isArray(defaults)) {
1254
1261
  defaults = defaults.map((item, idx) => {
1255
1262
  const schemaItem = getInnerSchemaForArrayItem(schema, 2 /* Fallback */, idx);
@@ -1280,14 +1287,14 @@ function computeDefaults(validator, rawSchema, {
1280
1287
  }
1281
1288
  }
1282
1289
  if (neverPopulate) {
1283
- return defaults ?? [];
1290
+ return defaults ?? emptyDefault;
1284
1291
  }
1285
1292
  if (ignoreMinItemsFlagSet && !required) {
1286
1293
  return defaults ? defaults : void 0;
1287
1294
  }
1288
1295
  const defaultsLength = Array.isArray(defaults) ? defaults.length : 0;
1289
- if (!schema.minItems || isMultiSelect(validator, schema, rootSchema) || schema.minItems <= defaultsLength) {
1290
- return defaults ? defaults : [];
1296
+ if (!schema.minItems || isMultiSelect(validator, schema, rootSchema) || computeSkipPopulate(validator, schema, rootSchema) || schema.minItems <= defaultsLength) {
1297
+ return defaults ? defaults : emptyDefault;
1291
1298
  }
1292
1299
  const defaultEntries = defaults || [];
1293
1300
  const fillerSchema = getInnerSchemaForArrayItem(schema, 1 /* Invert */);
@@ -2611,7 +2618,7 @@ var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
2611
2618
  TranslatableString2["UnsupportedFieldWithId"] = "Unsupported field schema for field <code>%1</code>.";
2612
2619
  TranslatableString2["UnsupportedFieldWithReason"] = "Unsupported field schema: <em>%1</em>.";
2613
2620
  TranslatableString2["UnsupportedFieldWithIdAndReason"] = "Unsupported field schema for field <code>%1</code>: <em>%2</em>.";
2614
- TranslatableString2["FilesInfo"] = "<strong>%1</strong> (%2, %3 bytes)";
2621
+ TranslatableString2["FilesInfo"] = "**%1** (%2, %3 bytes)";
2615
2622
  return TranslatableString2;
2616
2623
  })(TranslatableString || {});
2617
2624