@rjsf/core 5.14.1 → 5.14.3

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.
Files changed (93) hide show
  1. package/dist/core.umd.js +22 -13
  2. package/dist/index.esm.js +22 -13
  3. package/dist/index.esm.js.map +2 -2
  4. package/dist/index.js +22 -13
  5. package/dist/index.js.map +2 -2
  6. package/lib/components/Form.d.ts +4 -2
  7. package/lib/components/Form.js +32 -20
  8. package/lib/components/Form.js.map +1 -1
  9. package/lib/components/fields/ArrayField.js +10 -8
  10. package/lib/components/fields/ArrayField.js.map +1 -1
  11. package/lib/components/fields/BooleanField.js +7 -5
  12. package/lib/components/fields/BooleanField.js.map +1 -1
  13. package/lib/components/fields/MultiSchemaField.js +2 -3
  14. package/lib/components/fields/MultiSchemaField.js.map +1 -1
  15. package/lib/components/fields/NumberField.js +1 -1
  16. package/lib/components/fields/NumberField.js.map +1 -1
  17. package/lib/components/fields/ObjectField.js +16 -8
  18. package/lib/components/fields/ObjectField.js.map +1 -1
  19. package/lib/components/fields/SchemaField.js +4 -5
  20. package/lib/components/fields/SchemaField.js.map +1 -1
  21. package/lib/components/fields/StringField.js +2 -3
  22. package/lib/components/fields/StringField.js.map +1 -1
  23. package/lib/components/templates/ArrayFieldItemTemplate.js +2 -2
  24. package/lib/components/templates/ArrayFieldItemTemplate.js.map +1 -1
  25. package/lib/components/templates/ArrayFieldTemplate.js +2 -6
  26. package/lib/components/templates/ArrayFieldTemplate.js.map +1 -1
  27. package/lib/components/templates/BaseInputTemplate.js +8 -6
  28. package/lib/components/templates/BaseInputTemplate.js.map +1 -1
  29. package/lib/components/templates/ButtonTemplates/AddButton.js +1 -1
  30. package/lib/components/templates/ButtonTemplates/AddButton.js.map +1 -1
  31. package/lib/components/templates/ButtonTemplates/IconButton.js +6 -7
  32. package/lib/components/templates/ButtonTemplates/IconButton.js.map +1 -1
  33. package/lib/components/templates/ButtonTemplates/SubmitButton.js +1 -1
  34. package/lib/components/templates/ButtonTemplates/SubmitButton.js.map +1 -1
  35. package/lib/components/templates/DescriptionField.js +2 -2
  36. package/lib/components/templates/DescriptionField.js.map +1 -1
  37. package/lib/components/templates/ErrorList.js +3 -3
  38. package/lib/components/templates/ErrorList.js.map +1 -1
  39. package/lib/components/templates/FieldErrorTemplate.js +3 -3
  40. package/lib/components/templates/FieldErrorTemplate.js.map +1 -1
  41. package/lib/components/templates/FieldHelpTemplate.js +2 -2
  42. package/lib/components/templates/FieldHelpTemplate.js.map +1 -1
  43. package/lib/components/templates/FieldTemplate/FieldTemplate.js +2 -2
  44. package/lib/components/templates/FieldTemplate/FieldTemplate.js.map +1 -1
  45. package/lib/components/templates/FieldTemplate/Label.js +1 -1
  46. package/lib/components/templates/FieldTemplate/Label.js.map +1 -1
  47. package/lib/components/templates/ObjectFieldTemplate.js +1 -1
  48. package/lib/components/templates/ObjectFieldTemplate.js.map +1 -1
  49. package/lib/components/templates/TitleField.js +1 -1
  50. package/lib/components/templates/TitleField.js.map +1 -1
  51. package/lib/components/templates/UnsupportedField.js +1 -1
  52. package/lib/components/templates/UnsupportedField.js.map +1 -1
  53. package/lib/components/templates/WrapIfAdditionalTemplate.js +2 -2
  54. package/lib/components/templates/WrapIfAdditionalTemplate.js.map +1 -1
  55. package/lib/components/widgets/AltDateTimeWidget.js +2 -4
  56. package/lib/components/widgets/AltDateTimeWidget.js.map +1 -1
  57. package/lib/components/widgets/AltDateWidget.js +2 -2
  58. package/lib/components/widgets/AltDateWidget.js.map +1 -1
  59. package/lib/components/widgets/CheckboxWidget.js +1 -1
  60. package/lib/components/widgets/CheckboxWidget.js.map +1 -1
  61. package/lib/components/widgets/CheckboxesWidget.js +3 -3
  62. package/lib/components/widgets/CheckboxesWidget.js.map +1 -1
  63. package/lib/components/widgets/ColorWidget.js +1 -1
  64. package/lib/components/widgets/ColorWidget.js.map +1 -1
  65. package/lib/components/widgets/DateTimeWidget.js +1 -1
  66. package/lib/components/widgets/DateTimeWidget.js.map +1 -1
  67. package/lib/components/widgets/DateWidget.js +1 -1
  68. package/lib/components/widgets/DateWidget.js.map +1 -1
  69. package/lib/components/widgets/EmailWidget.js +1 -1
  70. package/lib/components/widgets/EmailWidget.js.map +1 -1
  71. package/lib/components/widgets/FileWidget.js +4 -4
  72. package/lib/components/widgets/FileWidget.js.map +1 -1
  73. package/lib/components/widgets/PasswordWidget.js +1 -1
  74. package/lib/components/widgets/PasswordWidget.js.map +1 -1
  75. package/lib/components/widgets/RadioWidget.js +3 -3
  76. package/lib/components/widgets/RadioWidget.js.map +1 -1
  77. package/lib/components/widgets/RangeWidget.js +1 -1
  78. package/lib/components/widgets/RangeWidget.js.map +1 -1
  79. package/lib/components/widgets/SelectWidget.js +3 -3
  80. package/lib/components/widgets/SelectWidget.js.map +1 -1
  81. package/lib/components/widgets/TextWidget.js +1 -1
  82. package/lib/components/widgets/TextWidget.js.map +1 -1
  83. package/lib/components/widgets/TimeWidget.js +1 -1
  84. package/lib/components/widgets/TimeWidget.js.map +1 -1
  85. package/lib/components/widgets/URLWidget.js +1 -1
  86. package/lib/components/widgets/URLWidget.js.map +1 -1
  87. package/lib/components/widgets/UpDownWidget.js +1 -1
  88. package/lib/components/widgets/UpDownWidget.js.map +1 -1
  89. package/lib/tsconfig.tsbuildinfo +1 -1
  90. package/lib/withTheme.js +13 -8
  91. package/lib/withTheme.js.map +1 -1
  92. package/package.json +6 -6
  93. package/src/components/Form.tsx +26 -12
package/dist/core.umd.js CHANGED
@@ -2991,17 +2991,18 @@
2991
2991
  */
2992
2992
  this.onChange = (formData, newErrorSchema, id) => {
2993
2993
  const { extraErrors, omitExtraData, liveOmit, noValidate, liveValidate, onChange } = this.props;
2994
- const { schemaUtils, schema } = this.state;
2994
+ const { schemaUtils, schema, retrievedSchema } = this.state;
2995
2995
  if (utils.isObject(formData) || Array.isArray(formData)) {
2996
- const newState = this.getStateFromProps(this.props, formData);
2996
+ const newState = this.getStateFromProps(this.props, formData, retrievedSchema);
2997
2997
  formData = newState.formData;
2998
2998
  }
2999
2999
  const mustValidate = !noValidate && liveValidate;
3000
3000
  let state = { formData, schema };
3001
3001
  let newFormData = formData;
3002
+ let _retrievedSchema;
3002
3003
  if (omitExtraData === true && liveOmit === true) {
3003
- const retrievedSchema = schemaUtils.retrieveSchema(schema, formData);
3004
- const pathSchema = schemaUtils.toPathSchema(retrievedSchema, "", formData);
3004
+ _retrievedSchema = schemaUtils.retrieveSchema(schema, formData);
3005
+ const pathSchema = schemaUtils.toPathSchema(_retrievedSchema, "", formData);
3005
3006
  const fieldNames = this.getFieldNames(pathSchema, formData);
3006
3007
  newFormData = this.getUsedFormData(formData, fieldNames);
3007
3008
  state = {
@@ -3009,7 +3010,7 @@
3009
3010
  };
3010
3011
  }
3011
3012
  if (mustValidate) {
3012
- const schemaValidation = this.validate(newFormData);
3013
+ const schemaValidation = this.validate(newFormData, schema, schemaUtils, retrievedSchema);
3013
3014
  let errors = schemaValidation.errors;
3014
3015
  let errorSchema = schemaValidation.errorSchema;
3015
3016
  const schemaValidationErrors = errors;
@@ -3034,6 +3035,9 @@
3034
3035
  errors: utils.toErrorList(errorSchema)
3035
3036
  };
3036
3037
  }
3038
+ if (_retrievedSchema) {
3039
+ state.retrievedSchema = _retrievedSchema;
3040
+ }
3037
3041
  this.setState(state, () => onChange && onChange({ ...this.state, ...state }, id));
3038
3042
  };
3039
3043
  /**
@@ -3150,7 +3154,11 @@
3150
3154
  */
3151
3155
  getSnapshotBeforeUpdate(prevProps, prevState) {
3152
3156
  if (!utils.deepEquals(this.props, prevProps)) {
3153
- const nextState = this.getStateFromProps(this.props, this.props.formData);
3157
+ const nextState = this.getStateFromProps(
3158
+ this.props,
3159
+ this.props.formData,
3160
+ prevProps.schema !== this.props.schema ? void 0 : this.state.retrievedSchema
3161
+ );
3154
3162
  const shouldUpdate = !utils.deepEquals(nextState, prevState);
3155
3163
  return { nextState, shouldUpdate };
3156
3164
  }
@@ -3188,7 +3196,7 @@
3188
3196
  * @param inputFormData - The new or current data for the `Form`
3189
3197
  * @returns - The new state for the `Form`
3190
3198
  */
3191
- getStateFromProps(props, inputFormData) {
3199
+ getStateFromProps(props, inputFormData, retrievedSchema) {
3192
3200
  const state = this.state || {};
3193
3201
  const schema = "schema" in props ? props.schema : this.props.schema;
3194
3202
  const uiSchema = ("uiSchema" in props ? props.uiSchema : this.props.uiSchema) || {};
@@ -3202,7 +3210,7 @@
3202
3210
  schemaUtils = utils.createSchemaUtils(props.validator, rootSchema, experimental_defaultFormStateBehavior);
3203
3211
  }
3204
3212
  const formData = schemaUtils.getDefaultFormState(schema, inputFormData);
3205
- const retrievedSchema = schemaUtils.retrieveSchema(schema, formData);
3213
+ const _retrievedSchema = retrievedSchema ?? schemaUtils.retrieveSchema(schema, formData);
3206
3214
  const getCurrentErrors = () => {
3207
3215
  if (props.noValidate) {
3208
3216
  return { errors: [], errorSchema: {} };
@@ -3222,7 +3230,7 @@
3222
3230
  let schemaValidationErrors = state.schemaValidationErrors;
3223
3231
  let schemaValidationErrorSchema = state.schemaValidationErrorSchema;
3224
3232
  if (mustValidate) {
3225
- const schemaValidation = this.validate(formData, schema, schemaUtils);
3233
+ const schemaValidation = this.validate(formData, schema, schemaUtils, _retrievedSchema);
3226
3234
  errors = schemaValidation.errors;
3227
3235
  errorSchema = schemaValidation.errorSchema;
3228
3236
  schemaValidationErrors = errors;
@@ -3238,7 +3246,7 @@
3238
3246
  errors = merged.errors;
3239
3247
  }
3240
3248
  const idSchema = schemaUtils.toIdSchema(
3241
- retrievedSchema,
3249
+ _retrievedSchema,
3242
3250
  uiSchema["ui:rootFieldId"],
3243
3251
  formData,
3244
3252
  props.idPrefix,
@@ -3254,7 +3262,8 @@
3254
3262
  errors,
3255
3263
  errorSchema,
3256
3264
  schemaValidationErrors,
3257
- schemaValidationErrorSchema
3265
+ schemaValidationErrorSchema,
3266
+ retrievedSchema: _retrievedSchema
3258
3267
  };
3259
3268
  return nextState;
3260
3269
  }
@@ -3274,10 +3283,10 @@
3274
3283
  * @param schema - The schema used to validate against
3275
3284
  * @param altSchemaUtils - The alternate schemaUtils to use for validation
3276
3285
  */
3277
- validate(formData, schema = this.props.schema, altSchemaUtils) {
3286
+ validate(formData, schema = this.props.schema, altSchemaUtils, retrievedSchema) {
3278
3287
  const schemaUtils = altSchemaUtils ? altSchemaUtils : this.state.schemaUtils;
3279
3288
  const { customValidate, transformErrors, uiSchema } = this.props;
3280
- const resolvedSchema = schemaUtils.retrieveSchema(schema, formData);
3289
+ const resolvedSchema = retrievedSchema ?? schemaUtils.retrieveSchema(schema, formData);
3281
3290
  return schemaUtils.getValidator().validateFormData(formData, resolvedSchema, customValidate, transformErrors, uiSchema);
3282
3291
  }
3283
3292
  /** Renders any errors contained in the `state` in using the `ErrorList`, if not disabled by `showErrorList`. */
package/dist/index.esm.js CHANGED
@@ -3337,17 +3337,18 @@ var Form = class extends Component5 {
3337
3337
  */
3338
3338
  this.onChange = (formData, newErrorSchema, id) => {
3339
3339
  const { extraErrors, omitExtraData, liveOmit, noValidate, liveValidate, onChange } = this.props;
3340
- const { schemaUtils, schema } = this.state;
3340
+ const { schemaUtils, schema, retrievedSchema } = this.state;
3341
3341
  if (isObject5(formData) || Array.isArray(formData)) {
3342
- const newState = this.getStateFromProps(this.props, formData);
3342
+ const newState = this.getStateFromProps(this.props, formData, retrievedSchema);
3343
3343
  formData = newState.formData;
3344
3344
  }
3345
3345
  const mustValidate = !noValidate && liveValidate;
3346
3346
  let state = { formData, schema };
3347
3347
  let newFormData = formData;
3348
+ let _retrievedSchema;
3348
3349
  if (omitExtraData === true && liveOmit === true) {
3349
- const retrievedSchema = schemaUtils.retrieveSchema(schema, formData);
3350
- const pathSchema = schemaUtils.toPathSchema(retrievedSchema, "", formData);
3350
+ _retrievedSchema = schemaUtils.retrieveSchema(schema, formData);
3351
+ const pathSchema = schemaUtils.toPathSchema(_retrievedSchema, "", formData);
3351
3352
  const fieldNames = this.getFieldNames(pathSchema, formData);
3352
3353
  newFormData = this.getUsedFormData(formData, fieldNames);
3353
3354
  state = {
@@ -3355,7 +3356,7 @@ var Form = class extends Component5 {
3355
3356
  };
3356
3357
  }
3357
3358
  if (mustValidate) {
3358
- const schemaValidation = this.validate(newFormData);
3359
+ const schemaValidation = this.validate(newFormData, schema, schemaUtils, retrievedSchema);
3359
3360
  let errors = schemaValidation.errors;
3360
3361
  let errorSchema = schemaValidation.errorSchema;
3361
3362
  const schemaValidationErrors = errors;
@@ -3380,6 +3381,9 @@ var Form = class extends Component5 {
3380
3381
  errors: toErrorList(errorSchema)
3381
3382
  };
3382
3383
  }
3384
+ if (_retrievedSchema) {
3385
+ state.retrievedSchema = _retrievedSchema;
3386
+ }
3383
3387
  this.setState(state, () => onChange && onChange({ ...this.state, ...state }, id));
3384
3388
  };
3385
3389
  /**
@@ -3496,7 +3500,11 @@ var Form = class extends Component5 {
3496
3500
  */
3497
3501
  getSnapshotBeforeUpdate(prevProps, prevState) {
3498
3502
  if (!deepEquals3(this.props, prevProps)) {
3499
- const nextState = this.getStateFromProps(this.props, this.props.formData);
3503
+ const nextState = this.getStateFromProps(
3504
+ this.props,
3505
+ this.props.formData,
3506
+ prevProps.schema !== this.props.schema ? void 0 : this.state.retrievedSchema
3507
+ );
3500
3508
  const shouldUpdate = !deepEquals3(nextState, prevState);
3501
3509
  return { nextState, shouldUpdate };
3502
3510
  }
@@ -3534,7 +3542,7 @@ var Form = class extends Component5 {
3534
3542
  * @param inputFormData - The new or current data for the `Form`
3535
3543
  * @returns - The new state for the `Form`
3536
3544
  */
3537
- getStateFromProps(props, inputFormData) {
3545
+ getStateFromProps(props, inputFormData, retrievedSchema) {
3538
3546
  const state = this.state || {};
3539
3547
  const schema = "schema" in props ? props.schema : this.props.schema;
3540
3548
  const uiSchema = ("uiSchema" in props ? props.uiSchema : this.props.uiSchema) || {};
@@ -3548,7 +3556,7 @@ var Form = class extends Component5 {
3548
3556
  schemaUtils = createSchemaUtils(props.validator, rootSchema, experimental_defaultFormStateBehavior);
3549
3557
  }
3550
3558
  const formData = schemaUtils.getDefaultFormState(schema, inputFormData);
3551
- const retrievedSchema = schemaUtils.retrieveSchema(schema, formData);
3559
+ const _retrievedSchema = retrievedSchema ?? schemaUtils.retrieveSchema(schema, formData);
3552
3560
  const getCurrentErrors = () => {
3553
3561
  if (props.noValidate) {
3554
3562
  return { errors: [], errorSchema: {} };
@@ -3568,7 +3576,7 @@ var Form = class extends Component5 {
3568
3576
  let schemaValidationErrors = state.schemaValidationErrors;
3569
3577
  let schemaValidationErrorSchema = state.schemaValidationErrorSchema;
3570
3578
  if (mustValidate) {
3571
- const schemaValidation = this.validate(formData, schema, schemaUtils);
3579
+ const schemaValidation = this.validate(formData, schema, schemaUtils, _retrievedSchema);
3572
3580
  errors = schemaValidation.errors;
3573
3581
  errorSchema = schemaValidation.errorSchema;
3574
3582
  schemaValidationErrors = errors;
@@ -3584,7 +3592,7 @@ var Form = class extends Component5 {
3584
3592
  errors = merged.errors;
3585
3593
  }
3586
3594
  const idSchema = schemaUtils.toIdSchema(
3587
- retrievedSchema,
3595
+ _retrievedSchema,
3588
3596
  uiSchema["ui:rootFieldId"],
3589
3597
  formData,
3590
3598
  props.idPrefix,
@@ -3600,7 +3608,8 @@ var Form = class extends Component5 {
3600
3608
  errors,
3601
3609
  errorSchema,
3602
3610
  schemaValidationErrors,
3603
- schemaValidationErrorSchema
3611
+ schemaValidationErrorSchema,
3612
+ retrievedSchema: _retrievedSchema
3604
3613
  };
3605
3614
  return nextState;
3606
3615
  }
@@ -3620,10 +3629,10 @@ var Form = class extends Component5 {
3620
3629
  * @param schema - The schema used to validate against
3621
3630
  * @param altSchemaUtils - The alternate schemaUtils to use for validation
3622
3631
  */
3623
- validate(formData, schema = this.props.schema, altSchemaUtils) {
3632
+ validate(formData, schema = this.props.schema, altSchemaUtils, retrievedSchema) {
3624
3633
  const schemaUtils = altSchemaUtils ? altSchemaUtils : this.state.schemaUtils;
3625
3634
  const { customValidate, transformErrors, uiSchema } = this.props;
3626
- const resolvedSchema = schemaUtils.retrieveSchema(schema, formData);
3635
+ const resolvedSchema = retrievedSchema ?? schemaUtils.retrieveSchema(schema, formData);
3627
3636
  return schemaUtils.getValidator().validateFormData(formData, resolvedSchema, customValidate, transformErrors, uiSchema);
3628
3637
  }
3629
3638
  /** Renders any errors contained in the `state` in using the `ErrorList`, if not disabled by `showErrorList`. */