@rjsf/core 5.19.3 → 5.20.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
@@ -39,6 +39,7 @@ module.exports = __toCommonJS(src_exports);
39
39
  // src/components/Form.tsx
40
40
  var import_react17 = require("react");
41
41
  var import_utils39 = require("@rjsf/utils");
42
+ var import_forEach = __toESM(require("lodash/forEach"));
42
43
  var import_get4 = __toESM(require("lodash/get"));
43
44
  var import_isEmpty2 = __toESM(require("lodash/isEmpty"));
44
45
  var import_pick = __toESM(require("lodash/pick"));
@@ -564,7 +565,7 @@ var ArrayField = class extends import_react.Component {
564
565
  } = this.props;
565
566
  const { widgets: widgets2, schemaUtils, formContext, globalUiOptions } = registry;
566
567
  const itemsSchema = schemaUtils.retrieveSchema(schema.items, items);
567
- const enumOptions = (0, import_utils.optionsList)(itemsSchema);
568
+ const enumOptions = (0, import_utils.optionsList)(itemsSchema, uiSchema);
568
569
  const { widget = "select", title: uiTitle, ...options } = (0, import_utils.getUiOptions)(uiSchema, globalUiOptions);
569
570
  const Widget = (0, import_utils.getWidget)(schema, widget, widgets2);
570
571
  const label = uiTitle ?? schema.title ?? name;
@@ -860,18 +861,21 @@ function BooleanField(props) {
860
861
  let enumOptions;
861
862
  const label = uiTitle ?? schemaTitle ?? title ?? name;
862
863
  if (Array.isArray(schema.oneOf)) {
863
- enumOptions = (0, import_utils2.optionsList)({
864
- oneOf: schema.oneOf.map((option) => {
865
- if ((0, import_isObject2.default)(option)) {
866
- return {
867
- ...option,
868
- title: option.title || (option.const === true ? yes : no)
869
- };
870
- }
871
- return void 0;
872
- }).filter((o) => o)
873
- // cast away the error that typescript can't grok is fixed
874
- });
864
+ enumOptions = (0, import_utils2.optionsList)(
865
+ {
866
+ oneOf: schema.oneOf.map((option) => {
867
+ if ((0, import_isObject2.default)(option)) {
868
+ return {
869
+ ...option,
870
+ title: option.title || (option.const === true ? yes : no)
871
+ };
872
+ }
873
+ return void 0;
874
+ }).filter((o) => o)
875
+ // cast away the error that typescript can't grok is fixed
876
+ },
877
+ uiSchema
878
+ );
875
879
  } else {
876
880
  const schemaWithEnumNames = schema;
877
881
  const enums = schema.enum ?? [true, false];
@@ -887,11 +891,14 @@ function BooleanField(props) {
887
891
  }
888
892
  ];
889
893
  } else {
890
- enumOptions = (0, import_utils2.optionsList)({
891
- enum: enums,
892
- // NOTE: enumNames is deprecated, but still supported for now.
893
- enumNames: schemaWithEnumNames.enumNames
894
- });
894
+ enumOptions = (0, import_utils2.optionsList)(
895
+ {
896
+ enum: enums,
897
+ // NOTE: enumNames is deprecated, but still supported for now.
898
+ enumNames: schemaWithEnumNames.enumNames
899
+ },
900
+ uiSchema
901
+ );
895
902
  }
896
903
  }
897
904
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
@@ -1347,7 +1354,7 @@ var ObjectField = class extends import_react4.Component {
1347
1354
  orderedProperties = (0, import_utils5.orderProperties)(properties, uiOptions.order);
1348
1355
  } catch (err) {
1349
1356
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
1350
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "config-error", style: { color: "red" }, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_markdown_to_jsx.default, { children: translateString(import_utils5.TranslatableString.InvalidObjectField, [name || "root", err.message]) }) }),
1357
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "config-error", style: { color: "red" }, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_markdown_to_jsx.default, { options: { disableParsingRawHTML: true }, children: translateString(import_utils5.TranslatableString.InvalidObjectField, [name || "root", err.message]) }) }),
1351
1358
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("pre", { children: JSON.stringify(schema) })
1352
1359
  ] });
1353
1360
  }
@@ -1543,7 +1550,7 @@ function SchemaFieldRender(props) {
1543
1550
  label = import_utils6.ADDITIONAL_PROPERTY_FLAG in schema ? name : uiOptions.title || props.schema.title || schema.title || props.title || name;
1544
1551
  }
1545
1552
  const description = uiOptions.description || props.schema.description || schema.description || "";
1546
- const richDescription = uiOptions.enableMarkdownInDescription ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_markdown_to_jsx2.default, { children: description }) : description;
1553
+ const richDescription = uiOptions.enableMarkdownInDescription ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_markdown_to_jsx2.default, { options: { disableParsingRawHTML: true }, children: description }) : description;
1547
1554
  const help = uiOptions.help;
1548
1555
  const hidden = uiOptions.widget === "hidden";
1549
1556
  const classNames = ["form-group", "field", `field-${(0, import_utils6.getSchemaType)(schema)}`];
@@ -1706,7 +1713,7 @@ function StringField(props) {
1706
1713
  } = props;
1707
1714
  const { title, format } = schema;
1708
1715
  const { widgets: widgets2, formContext, schemaUtils, globalUiOptions } = registry;
1709
- const enumOptions = schemaUtils.isSelect(schema) ? (0, import_utils7.optionsList)(schema) : void 0;
1716
+ const enumOptions = schemaUtils.isSelect(schema) ? (0, import_utils7.optionsList)(schema, uiSchema) : void 0;
1710
1717
  let defaultWidget = enumOptions ? "select" : "text";
1711
1718
  if (format && (0, import_utils7.hasWidget)(schema, format, widgets2)) {
1712
1719
  defaultWidget = format;
@@ -2375,7 +2382,7 @@ function UnsupportedField(props) {
2375
2382
  translateParams.push(reason);
2376
2383
  }
2377
2384
  return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { className: "unsupported-field", children: [
2378
- /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("p", { children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_markdown_to_jsx3.default, { children: translateString(translateEnum, translateParams) }) }),
2385
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("p", { children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_markdown_to_jsx3.default, { options: { disableParsingRawHTML: true }, children: translateString(translateEnum, translateParams) }) }),
2379
2386
  schema && /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("pre", { children: JSON.stringify(schema, null, 2) })
2380
2387
  ] });
2381
2388
  }
@@ -3331,6 +3338,10 @@ var Form = class extends import_react17.Component {
3331
3338
  errorSchema = merged.errorSchema;
3332
3339
  errors = merged.errors;
3333
3340
  }
3341
+ if (newErrorSchema) {
3342
+ const filteredErrors = this.filterErrorsBasedOnSchema(newErrorSchema, retrievedSchema, newFormData);
3343
+ errorSchema = (0, import_utils39.mergeObjects)(errorSchema, filteredErrors, "preventDuplicates");
3344
+ }
3334
3345
  state = {
3335
3346
  formData: newFormData,
3336
3347
  errors,
@@ -3611,7 +3622,15 @@ var Form = class extends import_react17.Component {
3611
3622
  if (mustValidate) {
3612
3623
  const schemaValidation = this.validate(formData, schema, schemaUtils, _retrievedSchema);
3613
3624
  errors = schemaValidation.errors;
3614
- errorSchema = schemaValidation.errorSchema;
3625
+ if (isSchemaChanged) {
3626
+ errorSchema = schemaValidation.errorSchema;
3627
+ } else {
3628
+ errorSchema = (0, import_utils39.mergeObjects)(
3629
+ this.state?.errorSchema,
3630
+ schemaValidation.errorSchema,
3631
+ "preventDuplicates"
3632
+ );
3633
+ }
3615
3634
  schemaValidationErrors = errors;
3616
3635
  schemaValidationErrorSchema = errorSchema;
3617
3636
  } else {
@@ -3689,6 +3708,28 @@ var Form = class extends import_react17.Component {
3689
3708
  }
3690
3709
  return null;
3691
3710
  }
3711
+ // Filtering errors based on your retrieved schema to only show errors for properties in the selected branch.
3712
+ filterErrorsBasedOnSchema(schemaErrors, resolvedSchema, formData) {
3713
+ const { retrievedSchema, schemaUtils } = this.state;
3714
+ const _retrievedSchema = resolvedSchema ?? retrievedSchema;
3715
+ const pathSchema = schemaUtils.toPathSchema(_retrievedSchema, "", formData);
3716
+ const fieldNames = this.getFieldNames(pathSchema, formData);
3717
+ const filteredErrors = (0, import_pick.default)(schemaErrors, fieldNames);
3718
+ if (resolvedSchema?.type !== "object" && resolvedSchema?.type !== "array") {
3719
+ filteredErrors.__errors = schemaErrors.__errors;
3720
+ }
3721
+ const filterUndefinedErrors = (errors) => {
3722
+ (0, import_forEach.default)(errors, (errorAtKey, errorKey) => {
3723
+ if (errorAtKey === void 0) {
3724
+ delete errors[errorKey];
3725
+ } else if (typeof errorAtKey === "object" && !Array.isArray(errorAtKey.__errors)) {
3726
+ filterUndefinedErrors(errorAtKey);
3727
+ }
3728
+ });
3729
+ return errors;
3730
+ };
3731
+ return filterUndefinedErrors(filteredErrors);
3732
+ }
3692
3733
  /** Returns the registry for the form */
3693
3734
  getRegistry() {
3694
3735
  const { translateString: customTranslateString, uiSchema = {} } = this.props;