@rjsf/core 5.21.1 → 5.22.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
@@ -42,6 +42,7 @@ var import_utils39 = require("@rjsf/utils");
42
42
  var import_forEach = __toESM(require("lodash/forEach"));
43
43
  var import_get4 = __toESM(require("lodash/get"));
44
44
  var import_isEmpty2 = __toESM(require("lodash/isEmpty"));
45
+ var import_isNil = __toESM(require("lodash/isNil"));
45
46
  var import_pick = __toESM(require("lodash/pick"));
46
47
  var import_toPath = __toESM(require("lodash/toPath"));
47
48
 
@@ -962,8 +963,9 @@ var AnyOfField = class extends import_react2.Component {
962
963
  if (newFormData && newOption) {
963
964
  newFormData = schemaUtils.getDefaultFormState(newOption, newFormData, "excludeObjectChildren");
964
965
  }
965
- onChange(newFormData, void 0, this.getFieldId());
966
- this.setState({ selectedOption: intOption });
966
+ this.setState({ selectedOption: intOption }, () => {
967
+ onChange(newFormData, void 0, this.getFieldId());
968
+ });
967
969
  };
968
970
  const {
969
971
  formData,
@@ -1267,15 +1269,18 @@ var ObjectField = class extends import_react4.Component {
1267
1269
  const { formData, onChange, registry } = this.props;
1268
1270
  const newFormData = { ...formData };
1269
1271
  let type = void 0;
1272
+ let constValue = void 0;
1270
1273
  let defaultValue = void 0;
1271
1274
  if ((0, import_isObject3.default)(schema.additionalProperties)) {
1272
1275
  type = schema.additionalProperties.type;
1276
+ constValue = schema.additionalProperties.const;
1273
1277
  defaultValue = schema.additionalProperties.default;
1274
1278
  let apSchema = schema.additionalProperties;
1275
1279
  if (import_utils5.REF_KEY in apSchema) {
1276
1280
  const { schemaUtils } = registry;
1277
1281
  apSchema = schemaUtils.retrieveSchema({ $ref: apSchema[import_utils5.REF_KEY] }, formData);
1278
1282
  type = apSchema.type;
1283
+ constValue = apSchema.const;
1279
1284
  defaultValue = apSchema.default;
1280
1285
  }
1281
1286
  if (!type && (import_utils5.ANY_OF_KEY in apSchema || import_utils5.ONE_OF_KEY in apSchema)) {
@@ -1283,7 +1288,8 @@ var ObjectField = class extends import_react4.Component {
1283
1288
  }
1284
1289
  }
1285
1290
  const newKey = this.getAvailableKey("newKey", newFormData);
1286
- (0, import_set2.default)(newFormData, newKey, defaultValue ?? this.getDefaultValue(type));
1291
+ const newValue = constValue ?? defaultValue ?? this.getDefaultValue(type);
1292
+ (0, import_set2.default)(newFormData, newKey, newValue);
1287
1293
  onChange(newFormData);
1288
1294
  };
1289
1295
  }
@@ -1512,7 +1518,9 @@ function SchemaFieldRender(props) {
1512
1518
  );
1513
1519
  const FieldComponent = getFieldComponent(schema, uiOptions, idSchema, registry);
1514
1520
  const disabled = Boolean(uiOptions.disabled ?? props.disabled);
1515
- const readonly = Boolean(uiOptions.readonly ?? (props.readonly || props.schema.readOnly || schema.readOnly));
1521
+ const readonly = Boolean(
1522
+ uiOptions.readonly ?? (props.readonly || props.schema.const || props.schema.readOnly || schema.readOnly)
1523
+ );
1516
1524
  const uiSchemaHideError = uiOptions.hideError;
1517
1525
  const hideError = uiSchemaHideError === void 0 ? props.hideError : Boolean(uiSchemaHideError);
1518
1526
  const autofocus = Boolean(uiOptions.autofocus ?? props.autofocus);
@@ -1650,6 +1658,7 @@ function SchemaFieldRender(props) {
1650
1658
  (_schema2) => schemaUtils.retrieveSchema((0, import_isObject4.default)(_schema2) ? _schema2 : {}, formData)
1651
1659
  ),
1652
1660
  registry,
1661
+ required,
1653
1662
  schema,
1654
1663
  uiSchema
1655
1664
  }
@@ -1674,6 +1683,7 @@ function SchemaFieldRender(props) {
1674
1683
  (_schema2) => schemaUtils.retrieveSchema((0, import_isObject4.default)(_schema2) ? _schema2 : {}, formData)
1675
1684
  ),
1676
1685
  registry,
1686
+ required,
1677
1687
  schema,
1678
1688
  uiSchema
1679
1689
  }
@@ -3320,7 +3330,6 @@ var Form = class extends import_react17.Component {
3320
3330
  const mustValidate = !noValidate && liveValidate;
3321
3331
  let state = { formData, schema };
3322
3332
  let newFormData = formData;
3323
- let _retrievedSchema;
3324
3333
  if (omitExtraData === true && liveOmit === true) {
3325
3334
  newFormData = this.omitExtraData(formData);
3326
3335
  state = {
@@ -3357,9 +3366,6 @@ var Form = class extends import_react17.Component {
3357
3366
  errors: (0, import_utils39.toErrorList)(errorSchema)
3358
3367
  };
3359
3368
  }
3360
- if (_retrievedSchema) {
3361
- state.retrievedSchema = _retrievedSchema;
3362
- }
3363
3369
  this.setState(state, () => onChange && onChange({ ...this.state, ...state }, id));
3364
3370
  };
3365
3371
  /**
@@ -3595,9 +3601,20 @@ var Form = class extends import_react17.Component {
3595
3601
  const mustValidate = edit && !props.noValidate && liveValidate;
3596
3602
  const rootSchema = schema;
3597
3603
  const experimental_defaultFormStateBehavior = "experimental_defaultFormStateBehavior" in props ? props.experimental_defaultFormStateBehavior : this.props.experimental_defaultFormStateBehavior;
3604
+ const experimental_customMergeAllOf = "experimental_customMergeAllOf" in props ? props.experimental_customMergeAllOf : this.props.experimental_customMergeAllOf;
3598
3605
  let schemaUtils = state.schemaUtils;
3599
- if (!schemaUtils || schemaUtils.doesSchemaUtilsDiffer(props.validator, rootSchema, experimental_defaultFormStateBehavior)) {
3600
- schemaUtils = (0, import_utils39.createSchemaUtils)(props.validator, rootSchema, experimental_defaultFormStateBehavior);
3606
+ if (!schemaUtils || schemaUtils.doesSchemaUtilsDiffer(
3607
+ props.validator,
3608
+ rootSchema,
3609
+ experimental_defaultFormStateBehavior,
3610
+ experimental_customMergeAllOf
3611
+ )) {
3612
+ schemaUtils = (0, import_utils39.createSchemaUtils)(
3613
+ props.validator,
3614
+ rootSchema,
3615
+ experimental_defaultFormStateBehavior,
3616
+ experimental_customMergeAllOf
3617
+ );
3601
3618
  }
3602
3619
  const formData = schemaUtils.getDefaultFormState(schema, inputFormData);
3603
3620
  const _retrievedSchema = retrievedSchema ?? schemaUtils.retrieveSchema(schema, formData);
@@ -3718,17 +3735,17 @@ var Form = class extends import_react17.Component {
3718
3735
  if (resolvedSchema?.type !== "object" && resolvedSchema?.type !== "array") {
3719
3736
  filteredErrors.__errors = schemaErrors.__errors;
3720
3737
  }
3721
- const filterUndefinedErrors = (errors) => {
3738
+ const filterNilOrEmptyErrors = (errors) => {
3722
3739
  (0, import_forEach.default)(errors, (errorAtKey, errorKey) => {
3723
- if (errorAtKey === void 0) {
3740
+ if ((0, import_isNil.default)(errorAtKey)) {
3724
3741
  delete errors[errorKey];
3725
3742
  } else if (typeof errorAtKey === "object" && !Array.isArray(errorAtKey.__errors)) {
3726
- filterUndefinedErrors(errorAtKey);
3743
+ filterNilOrEmptyErrors(errorAtKey);
3727
3744
  }
3728
3745
  });
3729
3746
  return errors;
3730
3747
  };
3731
- return filterUndefinedErrors(filteredErrors);
3748
+ return filterNilOrEmptyErrors(filteredErrors);
3732
3749
  }
3733
3750
  /** Returns the registry for the form */
3734
3751
  getRegistry() {