@rjsf/core 5.5.2 → 5.6.2

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.
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react/jsx-runtime'), require('react'), require('@rjsf/utils'), require('lodash-es/get'), require('lodash-es/isEmpty'), require('lodash-es/pick'), require('lodash-es/toPath'), require('lodash-es/cloneDeep'), require('lodash-es/isObject'), require('lodash-es/set'), require('nanoid'), require('lodash-es/omit'), require('markdown-to-jsx'), require('lodash-es/has'), require('lodash-es/unset')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'react/jsx-runtime', 'react', '@rjsf/utils', 'lodash-es/get', 'lodash-es/isEmpty', 'lodash-es/pick', 'lodash-es/toPath', 'lodash-es/cloneDeep', 'lodash-es/isObject', 'lodash-es/set', 'nanoid', 'lodash-es/omit', 'markdown-to-jsx', 'lodash-es/has', 'lodash-es/unset'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.JSONSchemaForm = {}, global.jsxRuntime, global.React, global.utils, global.get, global.isEmpty, global._pick, global._toPath, global.cloneDeep, global.isObject, global.set, global.nanoid, global.omit, global.Markdown, global.has, global.unset));
5
- })(this, (function (exports, jsxRuntime, react, utils, get, isEmpty, _pick, _toPath, cloneDeep, isObject, set, nanoid, omit, Markdown, has, unset) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react/jsx-runtime'), require('react'), require('@rjsf/utils'), require('lodash-es/get'), require('lodash-es/isEmpty'), require('lodash-es/pick'), require('lodash-es/toPath'), require('lodash-es/cloneDeep'), require('lodash-es/isObject'), require('lodash-es/set'), require('nanoid'), require('lodash-es/isString'), require('lodash-es/omit'), require('markdown-to-jsx'), require('lodash-es/has'), require('lodash-es/unset')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'react/jsx-runtime', 'react', '@rjsf/utils', 'lodash-es/get', 'lodash-es/isEmpty', 'lodash-es/pick', 'lodash-es/toPath', 'lodash-es/cloneDeep', 'lodash-es/isObject', 'lodash-es/set', 'nanoid', 'lodash-es/isString', 'lodash-es/omit', 'markdown-to-jsx', 'lodash-es/has', 'lodash-es/unset'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.JSONSchemaForm = {}, global.jsxRuntime, global.React, global.utils, global.get, global.isEmpty, global._pick, global._toPath, global.cloneDeep, global.isObject, global.set, global.nanoid, global.isString, global.omit, global.Markdown, global.has, global.unset));
5
+ })(this, (function (exports, jsxRuntime, react, utils, get, isEmpty, _pick, _toPath, cloneDeep, isObject, set, nanoid, isString, omit, Markdown, has, unset) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -13,6 +13,7 @@
13
13
  var cloneDeep__default = /*#__PURE__*/_interopDefaultLegacy(cloneDeep);
14
14
  var isObject__default = /*#__PURE__*/_interopDefaultLegacy(isObject);
15
15
  var set__default = /*#__PURE__*/_interopDefaultLegacy(set);
16
+ var isString__default = /*#__PURE__*/_interopDefaultLegacy(isString);
16
17
  var omit__default = /*#__PURE__*/_interopDefaultLegacy(omit);
17
18
  var Markdown__default = /*#__PURE__*/_interopDefaultLegacy(Markdown);
18
19
  var has__default = /*#__PURE__*/_interopDefaultLegacy(has);
@@ -1135,8 +1136,17 @@
1135
1136
  * @return - The index of the `option` that best matches the `formData`
1136
1137
  */;
1137
1138
  _proto.getMatchingOption = function getMatchingOption(selectedOption, formData, options) {
1138
- var schemaUtils = this.props.registry.schemaUtils;
1139
- var option = schemaUtils.getClosestMatchingOption(formData, options, selectedOption);
1139
+ var _this$props4 = this.props,
1140
+ schema = _this$props4.schema,
1141
+ schemaUtils = _this$props4.registry.schemaUtils;
1142
+ var discriminator;
1143
+ var maybeString = get__default["default"](schema, 'discriminator.propertyName', undefined);
1144
+ if (isString__default["default"](maybeString)) {
1145
+ discriminator = maybeString;
1146
+ } else if (maybeString !== undefined) {
1147
+ console.warn("Expecting discriminator to be a string, got \"" + typeof maybeString + "\" instead");
1148
+ }
1149
+ var option = schemaUtils.getClosestMatchingOption(formData, options, selectedOption, discriminator);
1140
1150
  if (option > 0) {
1141
1151
  return option;
1142
1152
  }
@@ -1145,27 +1155,27 @@
1145
1155
  return selectedOption || 0;
1146
1156
  };
1147
1157
  _proto.getFieldId = function getFieldId() {
1148
- var _this$props4 = this.props,
1149
- idSchema = _this$props4.idSchema,
1150
- schema = _this$props4.schema;
1158
+ var _this$props5 = this.props,
1159
+ idSchema = _this$props5.idSchema,
1160
+ schema = _this$props5.schema;
1151
1161
  return "" + idSchema.$id + (schema.oneOf ? '__oneof_select' : '__anyof_select');
1152
1162
  }
1153
1163
  /** Renders the `AnyOfField` selector along with a `SchemaField` for the value of the `formData`
1154
1164
  */;
1155
1165
  _proto.render = function render() {
1156
- var _this$props5 = this.props,
1157
- name = _this$props5.name,
1158
- baseType = _this$props5.baseType,
1159
- _this$props5$disabled = _this$props5.disabled,
1160
- disabled = _this$props5$disabled === void 0 ? false : _this$props5$disabled,
1161
- _this$props5$errorSch = _this$props5.errorSchema,
1162
- errorSchema = _this$props5$errorSch === void 0 ? {} : _this$props5$errorSch,
1163
- formContext = _this$props5.formContext,
1164
- onBlur = _this$props5.onBlur,
1165
- onFocus = _this$props5.onFocus,
1166
- registry = _this$props5.registry,
1167
- schema = _this$props5.schema,
1168
- uiSchema = _this$props5.uiSchema;
1166
+ var _this$props6 = this.props,
1167
+ name = _this$props6.name,
1168
+ baseType = _this$props6.baseType,
1169
+ _this$props6$disabled = _this$props6.disabled,
1170
+ disabled = _this$props6$disabled === void 0 ? false : _this$props6$disabled,
1171
+ _this$props6$errorSch = _this$props6.errorSchema,
1172
+ errorSchema = _this$props6$errorSch === void 0 ? {} : _this$props6$errorSch,
1173
+ formContext = _this$props6.formContext,
1174
+ onBlur = _this$props6.onBlur,
1175
+ onFocus = _this$props6.onFocus,
1176
+ registry = _this$props6.registry,
1177
+ schema = _this$props6.schema,
1178
+ uiSchema = _this$props6.uiSchema;
1169
1179
  var widgets = registry.widgets,
1170
1180
  fields = registry.fields,
1171
1181
  translateString = registry.translateString,
@@ -1757,7 +1767,7 @@
1757
1767
  var description = uiOptions.description || props.schema.description || schema.description || '';
1758
1768
  var help = uiOptions.help;
1759
1769
  var hidden = uiOptions.widget === 'hidden';
1760
- var classNames = ['form-group', 'field', "field-" + schema.type];
1770
+ var classNames = ['form-group', 'field', "field-" + utils.getSchemaType(schema)];
1761
1771
  if (!hideError && __errors && __errors.length > 0) {
1762
1772
  classNames.push('field-error has-error has-danger');
1763
1773
  }
@@ -3759,7 +3769,7 @@
3759
3769
  var schemaValidationErrors = errors;
3760
3770
  var schemaValidationErrorSchema = errorSchema;
3761
3771
  if (extraErrors) {
3762
- var merged = schemaUtils.mergeValidationData(schemaValidation, extraErrors);
3772
+ var merged = utils.validationDataMerge(schemaValidation, extraErrors);
3763
3773
  errorSchema = merged.errorSchema;
3764
3774
  errors = merged.errors;
3765
3775
  }
@@ -3775,7 +3785,7 @@
3775
3785
  state = {
3776
3786
  formData: newFormData,
3777
3787
  errorSchema: _errorSchema,
3778
- errors: schemaUtils.getValidator().toErrorList(_errorSchema)
3788
+ errors: utils.toErrorList(_errorSchema)
3779
3789
  };
3780
3790
  }
3781
3791
  _this.setState(state, function () {
@@ -3860,7 +3870,7 @@
3860
3870
  // There are no errors generated through schema validation.
3861
3871
  // Check for user provided errors and update state accordingly.
3862
3872
  var errorSchema = extraErrors || {};
3863
- var errors = extraErrors ? schemaUtils.getValidator().toErrorList(extraErrors) : [];
3873
+ var errors = extraErrors ? utils.toErrorList(extraErrors) : [];
3864
3874
  _this.setState({
3865
3875
  formData: newFormData,
3866
3876
  errors: errors,
@@ -3956,7 +3966,7 @@
3956
3966
  errorSchema = currentErrors.errorSchema;
3957
3967
  }
3958
3968
  if (props.extraErrors) {
3959
- var merged = schemaUtils.mergeValidationData({
3969
+ var merged = utils.validationDataMerge({
3960
3970
  errorSchema: errorSchema,
3961
3971
  errors: errors
3962
3972
  }, props.extraErrors);
@@ -4110,7 +4120,6 @@
4110
4120
  focusOnFirstError = _this$props6.focusOnFirstError,
4111
4121
  onError = _this$props6.onError;
4112
4122
  var formData = this.state.formData;
4113
- var schemaUtils = this.state.schemaUtils;
4114
4123
  var schemaValidation = this.validate(formData);
4115
4124
  var errors = schemaValidation.errors;
4116
4125
  var errorSchema = schemaValidation.errorSchema;
@@ -4118,12 +4127,16 @@
4118
4127
  var schemaValidationErrorSchema = errorSchema;
4119
4128
  if (errors.length > 0) {
4120
4129
  if (extraErrors) {
4121
- var merged = schemaUtils.mergeValidationData(schemaValidation, extraErrors);
4130
+ var merged = utils.validationDataMerge(schemaValidation, extraErrors);
4122
4131
  errorSchema = merged.errorSchema;
4123
4132
  errors = merged.errors;
4124
4133
  }
4125
4134
  if (focusOnFirstError) {
4126
- this.focusOnError(schemaValidation.errors[0]);
4135
+ if (typeof focusOnFirstError === 'function') {
4136
+ focusOnFirstError(schemaValidation.errors[0]);
4137
+ } else {
4138
+ this.focusOnError(schemaValidation.errors[0]);
4139
+ }
4127
4140
  }
4128
4141
  this.setState({
4129
4142
  errors: errors,