@rjsf/core 5.21.2 → 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/core.umd.js CHANGED
@@ -897,8 +897,9 @@
897
897
  if (newFormData && newOption) {
898
898
  newFormData = schemaUtils.getDefaultFormState(newOption, newFormData, "excludeObjectChildren");
899
899
  }
900
- onChange(newFormData, void 0, this.getFieldId());
901
- this.setState({ selectedOption: intOption });
900
+ this.setState({ selectedOption: intOption }, () => {
901
+ onChange(newFormData, void 0, this.getFieldId());
902
+ });
902
903
  };
903
904
  const {
904
905
  formData,
@@ -1186,15 +1187,18 @@
1186
1187
  const { formData, onChange, registry } = this.props;
1187
1188
  const newFormData = { ...formData };
1188
1189
  let type = void 0;
1190
+ let constValue = void 0;
1189
1191
  let defaultValue = void 0;
1190
1192
  if (isObject(schema.additionalProperties)) {
1191
1193
  type = schema.additionalProperties.type;
1194
+ constValue = schema.additionalProperties.const;
1192
1195
  defaultValue = schema.additionalProperties.default;
1193
1196
  let apSchema = schema.additionalProperties;
1194
1197
  if (utils.REF_KEY in apSchema) {
1195
1198
  const { schemaUtils } = registry;
1196
1199
  apSchema = schemaUtils.retrieveSchema({ $ref: apSchema[utils.REF_KEY] }, formData);
1197
1200
  type = apSchema.type;
1201
+ constValue = apSchema.const;
1198
1202
  defaultValue = apSchema.default;
1199
1203
  }
1200
1204
  if (!type && (utils.ANY_OF_KEY in apSchema || utils.ONE_OF_KEY in apSchema)) {
@@ -1202,7 +1206,8 @@
1202
1206
  }
1203
1207
  }
1204
1208
  const newKey = this.getAvailableKey("newKey", newFormData);
1205
- set(newFormData, newKey, defaultValue ?? this.getDefaultValue(type));
1209
+ const newValue = constValue ?? defaultValue ?? this.getDefaultValue(type);
1210
+ set(newFormData, newKey, newValue);
1206
1211
  onChange(newFormData);
1207
1212
  };
1208
1213
  }
@@ -1423,7 +1428,9 @@
1423
1428
  );
1424
1429
  const FieldComponent = getFieldComponent(schema, uiOptions, idSchema, registry);
1425
1430
  const disabled = Boolean(uiOptions.disabled ?? props.disabled);
1426
- const readonly = Boolean(uiOptions.readonly ?? (props.readonly || props.schema.readOnly || schema.readOnly));
1431
+ const readonly = Boolean(
1432
+ uiOptions.readonly ?? (props.readonly || props.schema.const || props.schema.readOnly || schema.readOnly)
1433
+ );
1427
1434
  const uiSchemaHideError = uiOptions.hideError;
1428
1435
  const hideError = uiSchemaHideError === void 0 ? props.hideError : Boolean(uiSchemaHideError);
1429
1436
  const autofocus = Boolean(uiOptions.autofocus ?? props.autofocus);
@@ -3337,9 +3344,20 @@
3337
3344
  const mustValidate = edit && !props.noValidate && liveValidate;
3338
3345
  const rootSchema = schema;
3339
3346
  const experimental_defaultFormStateBehavior = "experimental_defaultFormStateBehavior" in props ? props.experimental_defaultFormStateBehavior : this.props.experimental_defaultFormStateBehavior;
3347
+ const experimental_customMergeAllOf = "experimental_customMergeAllOf" in props ? props.experimental_customMergeAllOf : this.props.experimental_customMergeAllOf;
3340
3348
  let schemaUtils = state.schemaUtils;
3341
- if (!schemaUtils || schemaUtils.doesSchemaUtilsDiffer(props.validator, rootSchema, experimental_defaultFormStateBehavior)) {
3342
- schemaUtils = utils.createSchemaUtils(props.validator, rootSchema, experimental_defaultFormStateBehavior);
3349
+ if (!schemaUtils || schemaUtils.doesSchemaUtilsDiffer(
3350
+ props.validator,
3351
+ rootSchema,
3352
+ experimental_defaultFormStateBehavior,
3353
+ experimental_customMergeAllOf
3354
+ )) {
3355
+ schemaUtils = utils.createSchemaUtils(
3356
+ props.validator,
3357
+ rootSchema,
3358
+ experimental_defaultFormStateBehavior,
3359
+ experimental_customMergeAllOf
3360
+ );
3343
3361
  }
3344
3362
  const formData = schemaUtils.getDefaultFormState(schema, inputFormData);
3345
3363
  const _retrievedSchema = retrievedSchema ?? schemaUtils.retrieveSchema(schema, formData);
package/dist/index.esm.js CHANGED
@@ -965,8 +965,9 @@ var AnyOfField = class extends Component2 {
965
965
  if (newFormData && newOption) {
966
966
  newFormData = schemaUtils.getDefaultFormState(newOption, newFormData, "excludeObjectChildren");
967
967
  }
968
- onChange(newFormData, void 0, this.getFieldId());
969
- this.setState({ selectedOption: intOption });
968
+ this.setState({ selectedOption: intOption }, () => {
969
+ onChange(newFormData, void 0, this.getFieldId());
970
+ });
970
971
  };
971
972
  const {
972
973
  formData,
@@ -1280,15 +1281,18 @@ var ObjectField = class extends Component3 {
1280
1281
  const { formData, onChange, registry } = this.props;
1281
1282
  const newFormData = { ...formData };
1282
1283
  let type = void 0;
1284
+ let constValue = void 0;
1283
1285
  let defaultValue = void 0;
1284
1286
  if (isObject3(schema.additionalProperties)) {
1285
1287
  type = schema.additionalProperties.type;
1288
+ constValue = schema.additionalProperties.const;
1286
1289
  defaultValue = schema.additionalProperties.default;
1287
1290
  let apSchema = schema.additionalProperties;
1288
1291
  if (REF_KEY in apSchema) {
1289
1292
  const { schemaUtils } = registry;
1290
1293
  apSchema = schemaUtils.retrieveSchema({ $ref: apSchema[REF_KEY] }, formData);
1291
1294
  type = apSchema.type;
1295
+ constValue = apSchema.const;
1292
1296
  defaultValue = apSchema.default;
1293
1297
  }
1294
1298
  if (!type && (ANY_OF_KEY2 in apSchema || ONE_OF_KEY2 in apSchema)) {
@@ -1296,7 +1300,8 @@ var ObjectField = class extends Component3 {
1296
1300
  }
1297
1301
  }
1298
1302
  const newKey = this.getAvailableKey("newKey", newFormData);
1299
- set2(newFormData, newKey, defaultValue ?? this.getDefaultValue(type));
1303
+ const newValue = constValue ?? defaultValue ?? this.getDefaultValue(type);
1304
+ set2(newFormData, newKey, newValue);
1300
1305
  onChange(newFormData);
1301
1306
  };
1302
1307
  }
@@ -1536,7 +1541,9 @@ function SchemaFieldRender(props) {
1536
1541
  );
1537
1542
  const FieldComponent = getFieldComponent(schema, uiOptions, idSchema, registry);
1538
1543
  const disabled = Boolean(uiOptions.disabled ?? props.disabled);
1539
- const readonly = Boolean(uiOptions.readonly ?? (props.readonly || props.schema.readOnly || schema.readOnly));
1544
+ const readonly = Boolean(
1545
+ uiOptions.readonly ?? (props.readonly || props.schema.const || props.schema.readOnly || schema.readOnly)
1546
+ );
1540
1547
  const uiSchemaHideError = uiOptions.hideError;
1541
1548
  const hideError = uiSchemaHideError === void 0 ? props.hideError : Boolean(uiSchemaHideError);
1542
1549
  const autofocus = Boolean(uiOptions.autofocus ?? props.autofocus);
@@ -3688,9 +3695,20 @@ var Form = class extends Component5 {
3688
3695
  const mustValidate = edit && !props.noValidate && liveValidate;
3689
3696
  const rootSchema = schema;
3690
3697
  const experimental_defaultFormStateBehavior = "experimental_defaultFormStateBehavior" in props ? props.experimental_defaultFormStateBehavior : this.props.experimental_defaultFormStateBehavior;
3698
+ const experimental_customMergeAllOf = "experimental_customMergeAllOf" in props ? props.experimental_customMergeAllOf : this.props.experimental_customMergeAllOf;
3691
3699
  let schemaUtils = state.schemaUtils;
3692
- if (!schemaUtils || schemaUtils.doesSchemaUtilsDiffer(props.validator, rootSchema, experimental_defaultFormStateBehavior)) {
3693
- schemaUtils = createSchemaUtils(props.validator, rootSchema, experimental_defaultFormStateBehavior);
3700
+ if (!schemaUtils || schemaUtils.doesSchemaUtilsDiffer(
3701
+ props.validator,
3702
+ rootSchema,
3703
+ experimental_defaultFormStateBehavior,
3704
+ experimental_customMergeAllOf
3705
+ )) {
3706
+ schemaUtils = createSchemaUtils(
3707
+ props.validator,
3708
+ rootSchema,
3709
+ experimental_defaultFormStateBehavior,
3710
+ experimental_customMergeAllOf
3711
+ );
3694
3712
  }
3695
3713
  const formData = schemaUtils.getDefaultFormState(schema, inputFormData);
3696
3714
  const _retrievedSchema = retrievedSchema ?? schemaUtils.retrieveSchema(schema, formData);