@rjsf/core 5.12.1 → 5.13.1

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
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('@rjsf/utils'), require('lodash/get'), require('lodash/isEmpty'), require('lodash/pick'), require('lodash/toPath'), require('lodash/cloneDeep'), require('lodash/isObject'), require('lodash/set'), require('nanoid'), require('react/jsx-runtime'), require('lodash/omit'), require('lodash/unset'), require('markdown-to-jsx'), require('lodash/has')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'react', '@rjsf/utils', 'lodash/get', 'lodash/isEmpty', 'lodash/pick', 'lodash/toPath', 'lodash/cloneDeep', 'lodash/isObject', 'lodash/set', 'nanoid', 'react/jsx-runtime', 'lodash/omit', 'lodash/unset', 'markdown-to-jsx', 'lodash/has'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.JSONSchemaForm = {}, global.react, global.utils, global.get3, global.isEmpty, global._pick, global._toPath, global.cloneDeep, global.isObject, global.set, global.nanoid, global.jsxRuntime, global.omit2, global.unset, global.Markdown, global.has));
5
- })(this, (function (exports, react, utils, get3, isEmpty, _pick, _toPath, cloneDeep, isObject, set, nanoid, jsxRuntime, omit2, unset, Markdown, has) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('@rjsf/utils'), require('lodash/get'), require('lodash/isEmpty'), require('lodash/pick'), require('lodash/toPath'), require('lodash/cloneDeep'), require('lodash/isObject'), require('lodash/set'), require('nanoid'), require('react/jsx-runtime'), require('lodash/omit'), require('markdown-to-jsx'), require('lodash/has'), require('lodash/unset')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'react', '@rjsf/utils', 'lodash/get', 'lodash/isEmpty', 'lodash/pick', 'lodash/toPath', 'lodash/cloneDeep', 'lodash/isObject', 'lodash/set', 'nanoid', 'react/jsx-runtime', 'lodash/omit', 'markdown-to-jsx', 'lodash/has', 'lodash/unset'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.JSONSchemaForm = {}, global.react, global.utils, global.get3, global.isEmpty, global._pick, global._toPath, global.cloneDeep, global.isObject, global.set, global.nanoid, global.jsxRuntime, global.omit2, global.Markdown, global.has, global.unset));
5
+ })(this, (function (exports, react, utils, get3, isEmpty, _pick, _toPath, cloneDeep, isObject, set, nanoid, jsxRuntime, omit2, Markdown, has, unset) { 'use strict';
6
6
 
7
7
  // src/components/Form.tsx
8
8
  function generateRowId() {
@@ -72,8 +72,20 @@
72
72
  if (event) {
73
73
  event.preventDefault();
74
74
  }
75
- const { onChange } = this.props;
75
+ const { onChange, errorSchema } = this.props;
76
76
  const { keyedFormData } = this.state;
77
+ let newErrorSchema;
78
+ if (errorSchema) {
79
+ newErrorSchema = {};
80
+ for (const idx in errorSchema) {
81
+ const i = parseInt(idx);
82
+ if (i <= index) {
83
+ set(newErrorSchema, [i], errorSchema[idx]);
84
+ } else if (i > index) {
85
+ set(newErrorSchema, [i + 1], errorSchema[idx]);
86
+ }
87
+ }
88
+ }
77
89
  const newKeyedFormDataRow = {
78
90
  key: generateRowId(),
79
91
  item: cloneDeep(keyedFormData[index].item)
@@ -89,7 +101,7 @@
89
101
  keyedFormData: newKeyedFormData,
90
102
  updatedKeyedFormData: true
91
103
  },
92
- () => onChange(keyedToPlainFormData(newKeyedFormData))
104
+ () => onChange(keyedToPlainFormData(newKeyedFormData), newErrorSchema)
93
105
  );
94
106
  };
95
107
  };
@@ -285,8 +297,20 @@
285
297
  if (event) {
286
298
  event.preventDefault();
287
299
  }
288
- const { onChange } = this.props;
300
+ const { onChange, errorSchema } = this.props;
289
301
  const { keyedFormData } = this.state;
302
+ let newErrorSchema;
303
+ if (errorSchema) {
304
+ newErrorSchema = {};
305
+ for (const idx in errorSchema) {
306
+ const i = parseInt(idx);
307
+ if (index === void 0 || i < index) {
308
+ set(newErrorSchema, [i], errorSchema[idx]);
309
+ } else if (i >= index) {
310
+ set(newErrorSchema, [i + 1], errorSchema[idx]);
311
+ }
312
+ }
313
+ }
290
314
  const newKeyedFormDataRow = {
291
315
  key: generateRowId(),
292
316
  item: this._getNewFormDataRow()
@@ -302,7 +326,7 @@
302
326
  keyedFormData: newKeyedFormData,
303
327
  updatedKeyedFormData: true
304
328
  },
305
- () => onChange(keyedToPlainFormData(newKeyedFormData))
329
+ () => onChange(keyedToPlainFormData(newKeyedFormData), newErrorSchema)
306
330
  );
307
331
  }
308
332
  /** Renders the `ArrayField` depending on the specific needs of the schema and uischema elements
@@ -950,9 +974,8 @@
950
974
  const option = selectedOption >= 0 ? retrievedOptions[selectedOption] || null : null;
951
975
  let optionSchema;
952
976
  if (option) {
953
- const { oneOf, anyOf, properties, ...remaining } = schema;
954
- unset(remaining, utils.ADDITIONAL_PROPERTY_FLAG);
955
- optionSchema = !isEmpty(remaining) ? utils.mergeSchemas(remaining, option) : option;
977
+ const { required } = schema;
978
+ optionSchema = required ? utils.mergeSchemas({ required }, option) : option;
956
979
  }
957
980
  const translateEnum = title ? utils.TranslatableString.TitleOptionPrefix : utils.TranslatableString.OptionPrefix;
958
981
  const translateParams = title ? [title] : [];
@@ -3305,13 +3328,14 @@
3305
3328
  */
3306
3329
  validateForm() {
3307
3330
  const { extraErrors, extraErrorsBlockSubmit, focusOnFirstError, onError } = this.props;
3308
- const { formData } = this.state;
3331
+ const { formData, errors: prevErrors } = this.state;
3309
3332
  const schemaValidation = this.validate(formData);
3310
3333
  let errors = schemaValidation.errors;
3311
3334
  let errorSchema = schemaValidation.errorSchema;
3312
3335
  const schemaValidationErrors = errors;
3313
3336
  const schemaValidationErrorSchema = errorSchema;
3314
- if (errors.length > 0 || extraErrors && extraErrorsBlockSubmit) {
3337
+ const hasError = errors.length > 0 || extraErrors && extraErrorsBlockSubmit;
3338
+ if (hasError) {
3315
3339
  if (extraErrors) {
3316
3340
  const merged = utils.validationDataMerge(schemaValidation, extraErrors);
3317
3341
  errorSchema = merged.errorSchema;
@@ -3339,9 +3363,15 @@
3339
3363
  }
3340
3364
  }
3341
3365
  );
3342
- return false;
3366
+ } else if (prevErrors.length > 0) {
3367
+ this.setState({
3368
+ errors: [],
3369
+ errorSchema: {},
3370
+ schemaValidationErrors: [],
3371
+ schemaValidationErrorSchema: {}
3372
+ });
3343
3373
  }
3344
- return true;
3374
+ return !hasError;
3345
3375
  }
3346
3376
  /** Renders the `Form` fields inside the <form> | `tagName` or `_internalFormWrapper`, rendering any errors if
3347
3377
  * needed along with the submit button or any children of the form.
package/dist/index.esm.js CHANGED
@@ -110,8 +110,20 @@ var ArrayField = class extends Component {
110
110
  if (event) {
111
111
  event.preventDefault();
112
112
  }
113
- const { onChange } = this.props;
113
+ const { onChange, errorSchema } = this.props;
114
114
  const { keyedFormData } = this.state;
115
+ let newErrorSchema;
116
+ if (errorSchema) {
117
+ newErrorSchema = {};
118
+ for (const idx in errorSchema) {
119
+ const i = parseInt(idx);
120
+ if (i <= index) {
121
+ set(newErrorSchema, [i], errorSchema[idx]);
122
+ } else if (i > index) {
123
+ set(newErrorSchema, [i + 1], errorSchema[idx]);
124
+ }
125
+ }
126
+ }
115
127
  const newKeyedFormDataRow = {
116
128
  key: generateRowId(),
117
129
  item: cloneDeep(keyedFormData[index].item)
@@ -127,7 +139,7 @@ var ArrayField = class extends Component {
127
139
  keyedFormData: newKeyedFormData,
128
140
  updatedKeyedFormData: true
129
141
  },
130
- () => onChange(keyedToPlainFormData(newKeyedFormData))
142
+ () => onChange(keyedToPlainFormData(newKeyedFormData), newErrorSchema)
131
143
  );
132
144
  };
133
145
  };
@@ -323,8 +335,20 @@ var ArrayField = class extends Component {
323
335
  if (event) {
324
336
  event.preventDefault();
325
337
  }
326
- const { onChange } = this.props;
338
+ const { onChange, errorSchema } = this.props;
327
339
  const { keyedFormData } = this.state;
340
+ let newErrorSchema;
341
+ if (errorSchema) {
342
+ newErrorSchema = {};
343
+ for (const idx in errorSchema) {
344
+ const i = parseInt(idx);
345
+ if (index === void 0 || i < index) {
346
+ set(newErrorSchema, [i], errorSchema[idx]);
347
+ } else if (i >= index) {
348
+ set(newErrorSchema, [i + 1], errorSchema[idx]);
349
+ }
350
+ }
351
+ }
328
352
  const newKeyedFormDataRow = {
329
353
  key: generateRowId(),
330
354
  item: this._getNewFormDataRow()
@@ -340,7 +364,7 @@ var ArrayField = class extends Component {
340
364
  keyedFormData: newKeyedFormData,
341
365
  updatedKeyedFormData: true
342
366
  },
343
- () => onChange(keyedToPlainFormData(newKeyedFormData))
367
+ () => onChange(keyedToPlainFormData(newKeyedFormData), newErrorSchema)
344
368
  );
345
369
  }
346
370
  /** Renders the `ArrayField` depending on the specific needs of the schema and uischema elements
@@ -884,9 +908,7 @@ import { Component as Component2 } from "react";
884
908
  import get2 from "lodash/get";
885
909
  import isEmpty from "lodash/isEmpty";
886
910
  import omit from "lodash/omit";
887
- import unset from "lodash/unset";
888
911
  import {
889
- ADDITIONAL_PROPERTY_FLAG,
890
912
  deepEquals,
891
913
  ERRORS_KEY,
892
914
  getDiscriminatorFieldFromSchema,
@@ -1016,9 +1038,8 @@ var AnyOfField = class extends Component2 {
1016
1038
  const option = selectedOption >= 0 ? retrievedOptions[selectedOption] || null : null;
1017
1039
  let optionSchema;
1018
1040
  if (option) {
1019
- const { oneOf, anyOf, properties, ...remaining } = schema;
1020
- unset(remaining, ADDITIONAL_PROPERTY_FLAG);
1021
- optionSchema = !isEmpty(remaining) ? mergeSchemas(remaining, option) : option;
1041
+ const { required } = schema;
1042
+ optionSchema = required ? mergeSchemas({ required }, option) : option;
1022
1043
  }
1023
1044
  const translateEnum = title ? TranslatableString3.TitleOptionPrefix : TranslatableString3.OptionPrefix;
1024
1045
  const translateParams = title ? [title] : [];
@@ -1096,7 +1117,7 @@ import {
1096
1117
  getUiOptions as getUiOptions4,
1097
1118
  orderProperties,
1098
1119
  TranslatableString as TranslatableString4,
1099
- ADDITIONAL_PROPERTY_FLAG as ADDITIONAL_PROPERTY_FLAG2,
1120
+ ADDITIONAL_PROPERTY_FLAG,
1100
1121
  PROPERTIES_KEY,
1101
1122
  REF_KEY,
1102
1123
  ANY_OF_KEY,
@@ -1107,7 +1128,7 @@ import get3 from "lodash/get";
1107
1128
  import has from "lodash/has";
1108
1129
  import isObject3 from "lodash/isObject";
1109
1130
  import set2 from "lodash/set";
1110
- import unset2 from "lodash/unset";
1131
+ import unset from "lodash/unset";
1111
1132
  import { jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
1112
1133
  var ObjectField = class extends Component3 {
1113
1134
  constructor() {
@@ -1153,7 +1174,7 @@ var ObjectField = class extends Component3 {
1153
1174
  event.preventDefault();
1154
1175
  const { onChange, formData } = this.props;
1155
1176
  const copiedFormData = { ...formData };
1156
- unset2(copiedFormData, key);
1177
+ unset(copiedFormData, key);
1157
1178
  onChange(copiedFormData);
1158
1179
  };
1159
1180
  };
@@ -1311,7 +1332,7 @@ var ObjectField = class extends Component3 {
1311
1332
  title: uiOptions.label === false ? "" : title,
1312
1333
  description: uiOptions.label === false ? void 0 : description,
1313
1334
  properties: orderedProperties.map((name2) => {
1314
- const addedByAdditionalProperties = has(schema, [PROPERTIES_KEY, name2, ADDITIONAL_PROPERTY_FLAG2]);
1335
+ const addedByAdditionalProperties = has(schema, [PROPERTIES_KEY, name2, ADDITIONAL_PROPERTY_FLAG]);
1315
1336
  const fieldUiSchema = addedByAdditionalProperties ? uiSchema.additionalProperties : uiSchema[name2];
1316
1337
  const hidden = getUiOptions4(fieldUiSchema).widget === "hidden";
1317
1338
  const fieldIdSchema = get3(idSchema, [name2], {});
@@ -1368,7 +1389,7 @@ var ObjectField_default = ObjectField;
1368
1389
  // src/components/fields/SchemaField.tsx
1369
1390
  import { useCallback as useCallback2, Component as Component4 } from "react";
1370
1391
  import {
1371
- ADDITIONAL_PROPERTY_FLAG as ADDITIONAL_PROPERTY_FLAG3,
1392
+ ADDITIONAL_PROPERTY_FLAG as ADDITIONAL_PROPERTY_FLAG2,
1372
1393
  deepEquals as deepEquals2,
1373
1394
  descriptionId,
1374
1395
  getSchemaType,
@@ -1505,7 +1526,7 @@ function SchemaFieldRender(props) {
1505
1526
  if (wasPropertyKeyModified) {
1506
1527
  label = name;
1507
1528
  } else {
1508
- label = ADDITIONAL_PROPERTY_FLAG3 in schema ? name : uiOptions.title || props.schema.title || schema.title || name;
1529
+ label = ADDITIONAL_PROPERTY_FLAG2 in schema ? name : uiOptions.title || props.schema.title || schema.title || name;
1509
1530
  }
1510
1531
  const description = uiOptions.description || props.schema.description || schema.description || "";
1511
1532
  const richDescription = uiOptions.enableMarkdownInDescription ? /* @__PURE__ */ jsx6(Markdown2, { children: description }) : description;
@@ -2374,7 +2395,7 @@ var UnsupportedField_default = UnsupportedField;
2374
2395
 
2375
2396
  // src/components/templates/WrapIfAdditionalTemplate.tsx
2376
2397
  import {
2377
- ADDITIONAL_PROPERTY_FLAG as ADDITIONAL_PROPERTY_FLAG4,
2398
+ ADDITIONAL_PROPERTY_FLAG as ADDITIONAL_PROPERTY_FLAG3,
2378
2399
  TranslatableString as TranslatableString10
2379
2400
  } from "@rjsf/utils";
2380
2401
  import { jsx as jsx25, jsxs as jsxs13 } from "react/jsx-runtime";
@@ -2397,7 +2418,7 @@ function WrapIfAdditionalTemplate(props) {
2397
2418
  const { templates: templates2, translateString } = registry;
2398
2419
  const { RemoveButton: RemoveButton2 } = templates2.ButtonTemplates;
2399
2420
  const keyLabel = translateString(TranslatableString10.KeyLabel, [label]);
2400
- const additional = ADDITIONAL_PROPERTY_FLAG4 in schema;
2421
+ const additional = ADDITIONAL_PROPERTY_FLAG3 in schema;
2401
2422
  if (!additional) {
2402
2423
  return /* @__PURE__ */ jsx25("div", { className: classNames, style, children });
2403
2424
  }
@@ -3653,13 +3674,14 @@ var Form = class extends Component5 {
3653
3674
  */
3654
3675
  validateForm() {
3655
3676
  const { extraErrors, extraErrorsBlockSubmit, focusOnFirstError, onError } = this.props;
3656
- const { formData } = this.state;
3677
+ const { formData, errors: prevErrors } = this.state;
3657
3678
  const schemaValidation = this.validate(formData);
3658
3679
  let errors = schemaValidation.errors;
3659
3680
  let errorSchema = schemaValidation.errorSchema;
3660
3681
  const schemaValidationErrors = errors;
3661
3682
  const schemaValidationErrorSchema = errorSchema;
3662
- if (errors.length > 0 || extraErrors && extraErrorsBlockSubmit) {
3683
+ const hasError = errors.length > 0 || extraErrors && extraErrorsBlockSubmit;
3684
+ if (hasError) {
3663
3685
  if (extraErrors) {
3664
3686
  const merged = validationDataMerge(schemaValidation, extraErrors);
3665
3687
  errorSchema = merged.errorSchema;
@@ -3687,9 +3709,15 @@ var Form = class extends Component5 {
3687
3709
  }
3688
3710
  }
3689
3711
  );
3690
- return false;
3712
+ } else if (prevErrors.length > 0) {
3713
+ this.setState({
3714
+ errors: [],
3715
+ errorSchema: {},
3716
+ schemaValidationErrors: [],
3717
+ schemaValidationErrorSchema: {}
3718
+ });
3691
3719
  }
3692
- return true;
3720
+ return !hasError;
3693
3721
  }
3694
3722
  /** Renders the `Form` fields inside the <form> | `tagName` or `_internalFormWrapper`, rendering any errors if
3695
3723
  * needed along with the submit button or any children of the form.