@rjsf/core 5.0.0-beta.16 → 5.0.0-beta.17

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.
@@ -10,8 +10,8 @@ var _pick = require('lodash/pick');
10
10
  var isObject = require('lodash/isObject');
11
11
  var set = require('lodash/set');
12
12
  var nanoid = require('nanoid');
13
- var unset = require('lodash/unset');
14
13
  var has = require('lodash/has');
14
+ var unset = require('lodash/unset');
15
15
  var omit = require('lodash/omit');
16
16
 
17
17
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -22,8 +22,8 @@ var _isEmpty__default = /*#__PURE__*/_interopDefaultLegacy(_isEmpty);
22
22
  var _pick__default = /*#__PURE__*/_interopDefaultLegacy(_pick);
23
23
  var isObject__default = /*#__PURE__*/_interopDefaultLegacy(isObject);
24
24
  var set__default = /*#__PURE__*/_interopDefaultLegacy(set);
25
- var unset__default = /*#__PURE__*/_interopDefaultLegacy(unset);
26
25
  var has__default = /*#__PURE__*/_interopDefaultLegacy(has);
26
+ var unset__default = /*#__PURE__*/_interopDefaultLegacy(unset);
27
27
  var omit__default = /*#__PURE__*/_interopDefaultLegacy(omit);
28
28
 
29
29
  function _defineProperties(target, props) {
@@ -32,7 +32,7 @@ function _defineProperties(target, props) {
32
32
  descriptor.enumerable = descriptor.enumerable || false;
33
33
  descriptor.configurable = true;
34
34
  if ("value" in descriptor) descriptor.writable = true;
35
- Object.defineProperty(target, descriptor.key, descriptor);
35
+ Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
36
36
  }
37
37
  }
38
38
  function _createClass(Constructor, protoProps, staticProps) {
@@ -112,6 +112,20 @@ function _createForOfIteratorHelperLoose(o, allowArrayLike) {
112
112
  }
113
113
  throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
114
114
  }
115
+ function _toPrimitive(input, hint) {
116
+ if (typeof input !== "object" || input === null) return input;
117
+ var prim = input[Symbol.toPrimitive];
118
+ if (prim !== undefined) {
119
+ var res = prim.call(input, hint || "default");
120
+ if (typeof res !== "object") return res;
121
+ throw new TypeError("@@toPrimitive must return a primitive value.");
122
+ }
123
+ return (hint === "string" ? String : Number)(input);
124
+ }
125
+ function _toPropertyKey(arg) {
126
+ var key = _toPrimitive(arg, "string");
127
+ return typeof key === "symbol" ? key : String(key);
128
+ }
115
129
 
116
130
  var _excluded$9 = ["widget"],
117
131
  _excluded2 = ["widget"],
@@ -538,7 +552,7 @@ var ArrayField = /*#__PURE__*/function (_Component) {
538
552
  options = _objectWithoutPropertiesLoose(_getUiOptions2, _excluded$9);
539
553
  var Widget = utils.getWidget(schema, widget, widgets);
540
554
  return /*#__PURE__*/React__default["default"].createElement(Widget, {
541
- id: idSchema && idSchema.$id,
555
+ id: idSchema.$id,
542
556
  multiple: true,
543
557
  onChange: this.onSelectChange,
544
558
  onBlur: onBlur,
@@ -594,7 +608,7 @@ var ArrayField = /*#__PURE__*/function (_Component) {
594
608
  options = _objectWithoutPropertiesLoose(_getUiOptions3, _excluded2);
595
609
  var Widget = utils.getWidget(schema, widget, widgets);
596
610
  return /*#__PURE__*/React__default["default"].createElement(Widget, {
597
- id: idSchema && idSchema.$id,
611
+ id: idSchema.$id,
598
612
  multiple: true,
599
613
  onChange: this.onSelectChange,
600
614
  onBlur: onBlur,
@@ -648,7 +662,7 @@ var ArrayField = /*#__PURE__*/function (_Component) {
648
662
  var Widget = utils.getWidget(schema, widget, widgets);
649
663
  return /*#__PURE__*/React__default["default"].createElement(Widget, {
650
664
  options: options,
651
- id: idSchema && idSchema.$id,
665
+ id: idSchema.$id,
652
666
  multiple: true,
653
667
  onChange: this.onSelectChange,
654
668
  onBlur: onBlur,
@@ -941,7 +955,7 @@ function BooleanField(props) {
941
955
  }),
942
956
  schema: schema,
943
957
  uiSchema: uiSchema,
944
- id: idSchema && idSchema.$id,
958
+ id: idSchema.$id,
945
959
  onChange: onChange,
946
960
  onFocus: onFocus,
947
961
  onBlur: onBlur,
@@ -993,7 +1007,7 @@ var AnyOfField = /*#__PURE__*/function (_Component) {
993
1007
  var _option = _step.value;
994
1008
  if (_option.properties) {
995
1009
  for (var key in _option.properties) {
996
- if (key in newFormData) {
1010
+ if (has__default["default"](newFormData, key)) {
997
1011
  unset__default["default"](newFormData, key);
998
1012
  }
999
1013
  }
@@ -1291,7 +1305,7 @@ var ObjectField = /*#__PURE__*/function (_Component) {
1291
1305
  duplicateKeySuffixSeparator = _getUiOptions$duplica === void 0 ? "-" : _getUiOptions$duplica;
1292
1306
  var index = 0;
1293
1307
  var newKey = preferredKey;
1294
- while (newKey in formData) {
1308
+ while (has__default["default"](formData, newKey)) {
1295
1309
  newKey = "" + preferredKey + duplicateKeySuffixSeparator + ++index;
1296
1310
  }
1297
1311
  return newKey;
@@ -1602,10 +1616,10 @@ function SchemaFieldRender(props) {
1602
1616
  var _ref = errorSchema || {},
1603
1617
  __errors = _ref.__errors,
1604
1618
  fieldErrorSchema = _objectWithoutPropertiesLoose(_ref, _excluded$6);
1605
- // See #439: uiSchema: Don't pass consumed class names to child components
1606
- var fieldUiSchema = omit__default["default"](uiSchema, ["ui:classNames", "classNames"]);
1607
- if ("ui:options" in fieldUiSchema) {
1608
- fieldUiSchema["ui:options"] = omit__default["default"](fieldUiSchema["ui:options"], ["classNames"]);
1619
+ // See #439: uiSchema: Don't pass consumed class names or style to child components
1620
+ var fieldUiSchema = omit__default["default"](uiSchema, ["ui:classNames", "classNames", "ui:style"]);
1621
+ if (utils.UI_OPTIONS_KEY in fieldUiSchema) {
1622
+ fieldUiSchema[utils.UI_OPTIONS_KEY] = omit__default["default"](fieldUiSchema[utils.UI_OPTIONS_KEY], ["classNames", "style"]);
1609
1623
  }
1610
1624
  var field = /*#__PURE__*/React__default["default"].createElement(FieldComponent, _extends({}, props, {
1611
1625
  onChange: handleFieldComponentChange,
@@ -1662,7 +1676,7 @@ function SchemaFieldRender(props) {
1662
1676
  });
1663
1677
  var fieldProps = {
1664
1678
  description: /*#__PURE__*/React__default["default"].createElement(DescriptionFieldTemplate, {
1665
- id: id + "__description",
1679
+ id: utils.descriptionId(id),
1666
1680
  description: description,
1667
1681
  schema: schema,
1668
1682
  uiSchema: uiSchema,
@@ -1685,6 +1699,7 @@ function SchemaFieldRender(props) {
1685
1699
  hideError: hideError,
1686
1700
  displayLabel: displayLabel,
1687
1701
  classNames: classNames.join(" ").trim(),
1702
+ style: uiOptions.style,
1688
1703
  formContext: formContext,
1689
1704
  formData: formData,
1690
1705
  schema: schema,
@@ -1801,7 +1816,7 @@ function StringField(props) {
1801
1816
  }),
1802
1817
  schema: schema,
1803
1818
  uiSchema: uiSchema,
1804
- id: idSchema && idSchema.$id,
1819
+ id: idSchema.$id,
1805
1820
  label: title === undefined ? name : title,
1806
1821
  value: formData,
1807
1822
  onChange: onChange,
@@ -1867,9 +1882,8 @@ function ArrayFieldDescriptionTemplate(props) {
1867
1882
  return null;
1868
1883
  }
1869
1884
  var DescriptionFieldTemplate = utils.getTemplate("DescriptionFieldTemplate", registry, options);
1870
- var id = idSchema.$id + "__description";
1871
1885
  return /*#__PURE__*/React__default["default"].createElement(DescriptionFieldTemplate, {
1872
- id: id,
1886
+ id: utils.descriptionId(idSchema),
1873
1887
  description: description,
1874
1888
  schema: schema,
1875
1889
  uiSchema: uiSchema,
@@ -2014,9 +2028,8 @@ function ArrayFieldTitleTemplate(props) {
2014
2028
  return null;
2015
2029
  }
2016
2030
  var TitleFieldTemplate = utils.getTemplate("TitleFieldTemplate", registry, options);
2017
- var id = idSchema.$id + "__title";
2018
2031
  return /*#__PURE__*/React__default["default"].createElement(TitleFieldTemplate, {
2019
- id: id,
2032
+ id: utils.titleId(idSchema),
2020
2033
  title: title,
2021
2034
  required: required,
2022
2035
  schema: schema,
@@ -2079,13 +2092,14 @@ function BaseInputTemplate(props) {
2079
2092
  autoFocus: autofocus,
2080
2093
  value: inputValue
2081
2094
  }, inputProps, {
2082
- list: schema.examples ? "examples_" + id : undefined,
2095
+ list: schema.examples ? utils.examplesId(id) : undefined,
2083
2096
  onChange: _onChange,
2084
2097
  onBlur: _onBlur,
2085
- onFocus: _onFocus
2098
+ onFocus: _onFocus,
2099
+ "aria-describedby": utils.ariaDescribedByIds(id, !!schema.examples)
2086
2100
  })), Array.isArray(schema.examples) && /*#__PURE__*/React__default["default"].createElement("datalist", {
2087
2101
  key: "datalist_" + id,
2088
- id: "examples_" + id
2102
+ id: utils.examplesId(id)
2089
2103
  }, [].concat(new Set(schema.examples.concat(schema["default"] ? [schema["default"]] : []))).map(function (example) {
2090
2104
  return /*#__PURE__*/React__default["default"].createElement("option", {
2091
2105
  key: example,
@@ -2292,7 +2306,7 @@ function FieldErrorTemplate(props) {
2292
2306
  if (errors.length === 0) {
2293
2307
  return null;
2294
2308
  }
2295
- var id = idSchema.$id + "__error";
2309
+ var id = utils.errorId(idSchema);
2296
2310
  return /*#__PURE__*/React__default["default"].createElement("div", null, /*#__PURE__*/React__default["default"].createElement("ul", {
2297
2311
  id: id,
2298
2312
  className: "error-detail bs-callout bs-callout-info"
@@ -2316,7 +2330,7 @@ function FieldHelpTemplate(props) {
2316
2330
  if (!help) {
2317
2331
  return null;
2318
2332
  }
2319
- var id = idSchema.$id + "__help";
2333
+ var id = utils.helpId(idSchema);
2320
2334
  if (typeof help === "string") {
2321
2335
  return /*#__PURE__*/React__default["default"].createElement("p", {
2322
2336
  id: id,
@@ -2356,14 +2370,14 @@ function ObjectFieldTemplate(props) {
2356
2370
  return /*#__PURE__*/React__default["default"].createElement("fieldset", {
2357
2371
  id: idSchema.$id
2358
2372
  }, (options.title || title) && /*#__PURE__*/React__default["default"].createElement(TitleFieldTemplate, {
2359
- id: idSchema.$id + "__title",
2373
+ id: utils.titleId(idSchema),
2360
2374
  title: options.title || title,
2361
2375
  required: required,
2362
2376
  schema: schema,
2363
2377
  uiSchema: uiSchema,
2364
2378
  registry: registry
2365
2379
  }), (options.description || description) && /*#__PURE__*/React__default["default"].createElement(DescriptionFieldTemplate, {
2366
- id: idSchema.$id + "__description",
2380
+ id: utils.descriptionId(idSchema),
2367
2381
  description: options.description || description,
2368
2382
  schema: schema,
2369
2383
  uiSchema: uiSchema,
@@ -2417,6 +2431,7 @@ function UnsupportedField(props) {
2417
2431
  function WrapIfAdditionalTemplate(props) {
2418
2432
  var id = props.id,
2419
2433
  classNames = props.classNames,
2434
+ style = props.style,
2420
2435
  disabled = props.disabled,
2421
2436
  label = props.label,
2422
2437
  onKeyChange = props.onKeyChange,
@@ -2433,11 +2448,13 @@ function WrapIfAdditionalTemplate(props) {
2433
2448
  var additional = (utils.ADDITIONAL_PROPERTY_FLAG in schema);
2434
2449
  if (!additional) {
2435
2450
  return /*#__PURE__*/React__default["default"].createElement("div", {
2436
- className: classNames
2451
+ className: classNames,
2452
+ style: style
2437
2453
  }, children);
2438
2454
  }
2439
2455
  return /*#__PURE__*/React__default["default"].createElement("div", {
2440
- className: classNames
2456
+ className: classNames,
2457
+ style: style
2441
2458
  }, /*#__PURE__*/React__default["default"].createElement("div", {
2442
2459
  className: "row"
2443
2460
  }, /*#__PURE__*/React__default["default"].createElement("div", {
@@ -2581,7 +2598,8 @@ function DateElement(_ref) {
2581
2598
  onBlur: onBlur,
2582
2599
  onFocus: onFocus,
2583
2600
  registry: registry,
2584
- label: ""
2601
+ label: "",
2602
+ "aria-describedby": utils.ariaDescribedByIds(rootId)
2585
2603
  });
2586
2604
  }
2587
2605
  /** The `AltDateWidget` is an alternative widget for rendering date properties.
@@ -2719,7 +2737,7 @@ function CheckboxWidget(_ref) {
2719
2737
  return /*#__PURE__*/React__default["default"].createElement("div", {
2720
2738
  className: "checkbox " + (disabled || readonly ? "disabled" : "")
2721
2739
  }, schema.description && /*#__PURE__*/React__default["default"].createElement(DescriptionFieldTemplate, {
2722
- id: id + "__description",
2740
+ id: utils.descriptionId(id),
2723
2741
  description: schema.description,
2724
2742
  schema: schema,
2725
2743
  uiSchema: uiSchema,
@@ -2734,24 +2752,11 @@ function CheckboxWidget(_ref) {
2734
2752
  autoFocus: autofocus,
2735
2753
  onChange: handleChange,
2736
2754
  onBlur: handleBlur,
2737
- onFocus: handleFocus
2755
+ onFocus: handleFocus,
2756
+ "aria-describedby": utils.ariaDescribedByIds(id)
2738
2757
  }), /*#__PURE__*/React__default["default"].createElement("span", null, label)));
2739
2758
  }
2740
2759
 
2741
- function selectValue(value, selected, all) {
2742
- var at = all.indexOf(value);
2743
- var updated = selected.slice(0, at).concat(value, selected.slice(at));
2744
- // As inserting values at predefined index positions doesn't work with empty
2745
- // arrays, we need to reorder the updated selection to match the initial order
2746
- return updated.sort(function (a, b) {
2747
- return Number(all.indexOf(a) > all.indexOf(b));
2748
- });
2749
- }
2750
- function deselectValue(value, selected) {
2751
- return selected.filter(function (v) {
2752
- return v !== value;
2753
- });
2754
- }
2755
2760
  /** The `CheckboxesWidget` is a widget for rendering checkbox groups.
2756
2761
  * It is typically used to represent an array of enums.
2757
2762
  *
@@ -2770,32 +2775,30 @@ function CheckboxesWidget(_ref) {
2770
2775
  autofocus = _ref$autofocus === void 0 ? false : _ref$autofocus,
2771
2776
  readonly = _ref.readonly,
2772
2777
  onChange = _ref.onChange;
2778
+ var checkboxesValues = Array.isArray(value) ? value : [value];
2773
2779
  return /*#__PURE__*/React__default["default"].createElement("div", {
2774
2780
  className: "checkboxes",
2775
2781
  id: id
2776
2782
  }, Array.isArray(enumOptions) && enumOptions.map(function (option, index) {
2777
- var checked = value.indexOf(option.value) !== -1;
2783
+ var checked = checkboxesValues.includes(option.value);
2778
2784
  var itemDisabled = Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) != -1;
2779
2785
  var disabledCls = disabled || itemDisabled || readonly ? "disabled" : "";
2780
2786
  var handleChange = function handleChange(event) {
2781
- var all = enumOptions.map(function (_ref2) {
2782
- var value = _ref2.value;
2783
- return value;
2784
- });
2785
2787
  if (event.target.checked) {
2786
- onChange(selectValue(option.value, value, all));
2788
+ onChange(utils.enumOptionsSelectValue(option.value, checkboxesValues, enumOptions));
2787
2789
  } else {
2788
- onChange(deselectValue(option.value, value));
2790
+ onChange(utils.enumOptionsDeselectValue(option.value, checkboxesValues));
2789
2791
  }
2790
2792
  };
2791
2793
  var checkbox = /*#__PURE__*/React__default["default"].createElement("span", null, /*#__PURE__*/React__default["default"].createElement("input", {
2792
2794
  type: "checkbox",
2793
- id: id + "-" + option.value,
2795
+ id: utils.optionId(id, option),
2794
2796
  name: id,
2795
2797
  checked: checked,
2796
2798
  disabled: disabled || itemDisabled || readonly,
2797
2799
  autoFocus: autofocus && index === 0,
2798
- onChange: handleChange
2800
+ onChange: handleChange,
2801
+ "aria-describedby": utils.ariaDescribedByIds(id)
2799
2802
  }), /*#__PURE__*/React__default["default"].createElement("span", null, option.label));
2800
2803
  return inline ? /*#__PURE__*/React__default["default"].createElement("label", {
2801
2804
  key: option.value,
@@ -2991,7 +2994,8 @@ function FileWidget(_ref2) {
2991
2994
  defaultValue: "",
2992
2995
  autoFocus: autofocus,
2993
2996
  multiple: multiple,
2994
- accept: options.accept ? String(options.accept) : undefined
2997
+ accept: options.accept ? String(options.accept) : undefined,
2998
+ "aria-describedby": utils.ariaDescribedByIds(id)
2995
2999
  })), /*#__PURE__*/React__default["default"].createElement(FilesInfo, {
2996
3000
  filesInfo: filesInfo
2997
3001
  }));
@@ -3068,7 +3072,7 @@ function RadioWidget(_ref) {
3068
3072
  };
3069
3073
  var radio = /*#__PURE__*/React__default["default"].createElement("span", null, /*#__PURE__*/React__default["default"].createElement("input", {
3070
3074
  type: "radio",
3071
- id: id + "-" + option.value,
3075
+ id: utils.optionId(id, option),
3072
3076
  checked: checked,
3073
3077
  name: name,
3074
3078
  required: required,
@@ -3077,7 +3081,8 @@ function RadioWidget(_ref) {
3077
3081
  autoFocus: autofocus && i === 0,
3078
3082
  onChange: handleChange,
3079
3083
  onBlur: handleBlur,
3080
- onFocus: handleFocus
3084
+ onFocus: handleFocus,
3085
+ "aria-describedby": utils.ariaDescribedByIds(id)
3081
3086
  }), /*#__PURE__*/React__default["default"].createElement("span", null, option.label));
3082
3087
  return inline ? /*#__PURE__*/React__default["default"].createElement("label", {
3083
3088
  key: option.value,
@@ -3163,7 +3168,8 @@ function SelectWidget(_ref) {
3163
3168
  autoFocus: autofocus,
3164
3169
  onBlur: handleBlur,
3165
3170
  onFocus: handleFocus,
3166
- onChange: handleChange
3171
+ onChange: handleChange,
3172
+ "aria-describedby": utils.ariaDescribedByIds(id)
3167
3173
  }, !multiple && schema["default"] === undefined && /*#__PURE__*/React__default["default"].createElement("option", {
3168
3174
  value: ""
3169
3175
  }, placeholder), Array.isArray(enumOptions) && enumOptions.map(function (_ref2, i) {
@@ -3221,7 +3227,8 @@ function TextareaWidget(_ref) {
3221
3227
  rows: options.rows,
3222
3228
  onBlur: handleBlur,
3223
3229
  onFocus: handleFocus,
3224
- onChange: handleChange
3230
+ onChange: handleChange,
3231
+ "aria-describedby": utils.ariaDescribedByIds(id)
3225
3232
  });
3226
3233
  }
3227
3234
  TextareaWidget.defaultProps = {