@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.
@@ -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-es/get'), require('lodash-es/isEmpty'), require('lodash-es/pick'), require('lodash-es/isObject'), require('lodash-es/set'), require('nanoid'), require('lodash-es/unset'), require('lodash-es/has'), require('lodash-es/omit')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'react', '@rjsf/utils', 'lodash-es/get', 'lodash-es/isEmpty', 'lodash-es/pick', 'lodash-es/isObject', 'lodash-es/set', 'nanoid', 'lodash-es/unset', 'lodash-es/has', 'lodash-es/omit'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.JSONSchemaForm = {}, global.React, global.utils, global.get, global._isEmpty, global._pick, global.isObject, global.set, global.nanoid, global.unset, global.has, global.omit));
5
- })(this, (function (exports, React, utils, get, _isEmpty, _pick, isObject, set, nanoid, unset, has, omit) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('@rjsf/utils'), require('lodash-es/get'), require('lodash-es/isEmpty'), require('lodash-es/pick'), require('lodash-es/isObject'), require('lodash-es/set'), require('nanoid'), require('lodash-es/has'), require('lodash-es/unset'), require('lodash-es/omit')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'react', '@rjsf/utils', 'lodash-es/get', 'lodash-es/isEmpty', 'lodash-es/pick', 'lodash-es/isObject', 'lodash-es/set', 'nanoid', 'lodash-es/has', 'lodash-es/unset', 'lodash-es/omit'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.JSONSchemaForm = {}, global.React, global.utils, global.get, global._isEmpty, global._pick, global.isObject, global.set, global.nanoid, global.has, global.unset, global.omit));
5
+ })(this, (function (exports, React, utils, get, _isEmpty, _pick, isObject, set, nanoid, has, unset, omit) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -12,8 +12,8 @@
12
12
  var _pick__default = /*#__PURE__*/_interopDefaultLegacy(_pick);
13
13
  var isObject__default = /*#__PURE__*/_interopDefaultLegacy(isObject);
14
14
  var set__default = /*#__PURE__*/_interopDefaultLegacy(set);
15
- var unset__default = /*#__PURE__*/_interopDefaultLegacy(unset);
16
15
  var has__default = /*#__PURE__*/_interopDefaultLegacy(has);
16
+ var unset__default = /*#__PURE__*/_interopDefaultLegacy(unset);
17
17
  var omit__default = /*#__PURE__*/_interopDefaultLegacy(omit);
18
18
 
19
19
  function _defineProperties(target, props) {
@@ -22,7 +22,7 @@
22
22
  descriptor.enumerable = descriptor.enumerable || false;
23
23
  descriptor.configurable = true;
24
24
  if ("value" in descriptor) descriptor.writable = true;
25
- Object.defineProperty(target, descriptor.key, descriptor);
25
+ Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
26
26
  }
27
27
  }
28
28
  function _createClass(Constructor, protoProps, staticProps) {
@@ -102,6 +102,20 @@
102
102
  }
103
103
  throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
104
104
  }
105
+ function _toPrimitive(input, hint) {
106
+ if (typeof input !== "object" || input === null) return input;
107
+ var prim = input[Symbol.toPrimitive];
108
+ if (prim !== undefined) {
109
+ var res = prim.call(input, hint || "default");
110
+ if (typeof res !== "object") return res;
111
+ throw new TypeError("@@toPrimitive must return a primitive value.");
112
+ }
113
+ return (hint === "string" ? String : Number)(input);
114
+ }
115
+ function _toPropertyKey(arg) {
116
+ var key = _toPrimitive(arg, "string");
117
+ return typeof key === "symbol" ? key : String(key);
118
+ }
105
119
 
106
120
  var _excluded$9 = ["widget"],
107
121
  _excluded2 = ["widget"],
@@ -528,7 +542,7 @@
528
542
  options = _objectWithoutPropertiesLoose(_getUiOptions2, _excluded$9);
529
543
  var Widget = utils.getWidget(schema, widget, widgets);
530
544
  return /*#__PURE__*/React__default["default"].createElement(Widget, {
531
- id: idSchema && idSchema.$id,
545
+ id: idSchema.$id,
532
546
  multiple: true,
533
547
  onChange: this.onSelectChange,
534
548
  onBlur: onBlur,
@@ -584,7 +598,7 @@
584
598
  options = _objectWithoutPropertiesLoose(_getUiOptions3, _excluded2);
585
599
  var Widget = utils.getWidget(schema, widget, widgets);
586
600
  return /*#__PURE__*/React__default["default"].createElement(Widget, {
587
- id: idSchema && idSchema.$id,
601
+ id: idSchema.$id,
588
602
  multiple: true,
589
603
  onChange: this.onSelectChange,
590
604
  onBlur: onBlur,
@@ -638,7 +652,7 @@
638
652
  var Widget = utils.getWidget(schema, widget, widgets);
639
653
  return /*#__PURE__*/React__default["default"].createElement(Widget, {
640
654
  options: options,
641
- id: idSchema && idSchema.$id,
655
+ id: idSchema.$id,
642
656
  multiple: true,
643
657
  onChange: this.onSelectChange,
644
658
  onBlur: onBlur,
@@ -931,7 +945,7 @@
931
945
  }),
932
946
  schema: schema,
933
947
  uiSchema: uiSchema,
934
- id: idSchema && idSchema.$id,
948
+ id: idSchema.$id,
935
949
  onChange: onChange,
936
950
  onFocus: onFocus,
937
951
  onBlur: onBlur,
@@ -983,7 +997,7 @@
983
997
  var _option = _step.value;
984
998
  if (_option.properties) {
985
999
  for (var key in _option.properties) {
986
- if (key in newFormData) {
1000
+ if (has__default["default"](newFormData, key)) {
987
1001
  unset__default["default"](newFormData, key);
988
1002
  }
989
1003
  }
@@ -1281,7 +1295,7 @@
1281
1295
  duplicateKeySuffixSeparator = _getUiOptions$duplica === void 0 ? "-" : _getUiOptions$duplica;
1282
1296
  var index = 0;
1283
1297
  var newKey = preferredKey;
1284
- while (newKey in formData) {
1298
+ while (has__default["default"](formData, newKey)) {
1285
1299
  newKey = "" + preferredKey + duplicateKeySuffixSeparator + ++index;
1286
1300
  }
1287
1301
  return newKey;
@@ -1592,10 +1606,10 @@
1592
1606
  var _ref = errorSchema || {},
1593
1607
  __errors = _ref.__errors,
1594
1608
  fieldErrorSchema = _objectWithoutPropertiesLoose(_ref, _excluded$6);
1595
- // See #439: uiSchema: Don't pass consumed class names to child components
1596
- var fieldUiSchema = omit__default["default"](uiSchema, ["ui:classNames", "classNames"]);
1597
- if ("ui:options" in fieldUiSchema) {
1598
- fieldUiSchema["ui:options"] = omit__default["default"](fieldUiSchema["ui:options"], ["classNames"]);
1609
+ // See #439: uiSchema: Don't pass consumed class names or style to child components
1610
+ var fieldUiSchema = omit__default["default"](uiSchema, ["ui:classNames", "classNames", "ui:style"]);
1611
+ if (utils.UI_OPTIONS_KEY in fieldUiSchema) {
1612
+ fieldUiSchema[utils.UI_OPTIONS_KEY] = omit__default["default"](fieldUiSchema[utils.UI_OPTIONS_KEY], ["classNames", "style"]);
1599
1613
  }
1600
1614
  var field = /*#__PURE__*/React__default["default"].createElement(FieldComponent, _extends({}, props, {
1601
1615
  onChange: handleFieldComponentChange,
@@ -1652,7 +1666,7 @@
1652
1666
  });
1653
1667
  var fieldProps = {
1654
1668
  description: /*#__PURE__*/React__default["default"].createElement(DescriptionFieldTemplate, {
1655
- id: id + "__description",
1669
+ id: utils.descriptionId(id),
1656
1670
  description: description,
1657
1671
  schema: schema,
1658
1672
  uiSchema: uiSchema,
@@ -1675,6 +1689,7 @@
1675
1689
  hideError: hideError,
1676
1690
  displayLabel: displayLabel,
1677
1691
  classNames: classNames.join(" ").trim(),
1692
+ style: uiOptions.style,
1678
1693
  formContext: formContext,
1679
1694
  formData: formData,
1680
1695
  schema: schema,
@@ -1791,7 +1806,7 @@
1791
1806
  }),
1792
1807
  schema: schema,
1793
1808
  uiSchema: uiSchema,
1794
- id: idSchema && idSchema.$id,
1809
+ id: idSchema.$id,
1795
1810
  label: title === undefined ? name : title,
1796
1811
  value: formData,
1797
1812
  onChange: onChange,
@@ -1857,9 +1872,8 @@
1857
1872
  return null;
1858
1873
  }
1859
1874
  var DescriptionFieldTemplate = utils.getTemplate("DescriptionFieldTemplate", registry, options);
1860
- var id = idSchema.$id + "__description";
1861
1875
  return /*#__PURE__*/React__default["default"].createElement(DescriptionFieldTemplate, {
1862
- id: id,
1876
+ id: utils.descriptionId(idSchema),
1863
1877
  description: description,
1864
1878
  schema: schema,
1865
1879
  uiSchema: uiSchema,
@@ -2004,9 +2018,8 @@
2004
2018
  return null;
2005
2019
  }
2006
2020
  var TitleFieldTemplate = utils.getTemplate("TitleFieldTemplate", registry, options);
2007
- var id = idSchema.$id + "__title";
2008
2021
  return /*#__PURE__*/React__default["default"].createElement(TitleFieldTemplate, {
2009
- id: id,
2022
+ id: utils.titleId(idSchema),
2010
2023
  title: title,
2011
2024
  required: required,
2012
2025
  schema: schema,
@@ -2069,13 +2082,14 @@
2069
2082
  autoFocus: autofocus,
2070
2083
  value: inputValue
2071
2084
  }, inputProps, {
2072
- list: schema.examples ? "examples_" + id : undefined,
2085
+ list: schema.examples ? utils.examplesId(id) : undefined,
2073
2086
  onChange: _onChange,
2074
2087
  onBlur: _onBlur,
2075
- onFocus: _onFocus
2088
+ onFocus: _onFocus,
2089
+ "aria-describedby": utils.ariaDescribedByIds(id, !!schema.examples)
2076
2090
  })), Array.isArray(schema.examples) && /*#__PURE__*/React__default["default"].createElement("datalist", {
2077
2091
  key: "datalist_" + id,
2078
- id: "examples_" + id
2092
+ id: utils.examplesId(id)
2079
2093
  }, [].concat(new Set(schema.examples.concat(schema["default"] ? [schema["default"]] : []))).map(function (example) {
2080
2094
  return /*#__PURE__*/React__default["default"].createElement("option", {
2081
2095
  key: example,
@@ -2282,7 +2296,7 @@
2282
2296
  if (errors.length === 0) {
2283
2297
  return null;
2284
2298
  }
2285
- var id = idSchema.$id + "__error";
2299
+ var id = utils.errorId(idSchema);
2286
2300
  return /*#__PURE__*/React__default["default"].createElement("div", null, /*#__PURE__*/React__default["default"].createElement("ul", {
2287
2301
  id: id,
2288
2302
  className: "error-detail bs-callout bs-callout-info"
@@ -2306,7 +2320,7 @@
2306
2320
  if (!help) {
2307
2321
  return null;
2308
2322
  }
2309
- var id = idSchema.$id + "__help";
2323
+ var id = utils.helpId(idSchema);
2310
2324
  if (typeof help === "string") {
2311
2325
  return /*#__PURE__*/React__default["default"].createElement("p", {
2312
2326
  id: id,
@@ -2346,14 +2360,14 @@
2346
2360
  return /*#__PURE__*/React__default["default"].createElement("fieldset", {
2347
2361
  id: idSchema.$id
2348
2362
  }, (options.title || title) && /*#__PURE__*/React__default["default"].createElement(TitleFieldTemplate, {
2349
- id: idSchema.$id + "__title",
2363
+ id: utils.titleId(idSchema),
2350
2364
  title: options.title || title,
2351
2365
  required: required,
2352
2366
  schema: schema,
2353
2367
  uiSchema: uiSchema,
2354
2368
  registry: registry
2355
2369
  }), (options.description || description) && /*#__PURE__*/React__default["default"].createElement(DescriptionFieldTemplate, {
2356
- id: idSchema.$id + "__description",
2370
+ id: utils.descriptionId(idSchema),
2357
2371
  description: options.description || description,
2358
2372
  schema: schema,
2359
2373
  uiSchema: uiSchema,
@@ -2407,6 +2421,7 @@
2407
2421
  function WrapIfAdditionalTemplate(props) {
2408
2422
  var id = props.id,
2409
2423
  classNames = props.classNames,
2424
+ style = props.style,
2410
2425
  disabled = props.disabled,
2411
2426
  label = props.label,
2412
2427
  onKeyChange = props.onKeyChange,
@@ -2423,11 +2438,13 @@
2423
2438
  var additional = (utils.ADDITIONAL_PROPERTY_FLAG in schema);
2424
2439
  if (!additional) {
2425
2440
  return /*#__PURE__*/React__default["default"].createElement("div", {
2426
- className: classNames
2441
+ className: classNames,
2442
+ style: style
2427
2443
  }, children);
2428
2444
  }
2429
2445
  return /*#__PURE__*/React__default["default"].createElement("div", {
2430
- className: classNames
2446
+ className: classNames,
2447
+ style: style
2431
2448
  }, /*#__PURE__*/React__default["default"].createElement("div", {
2432
2449
  className: "row"
2433
2450
  }, /*#__PURE__*/React__default["default"].createElement("div", {
@@ -2571,7 +2588,8 @@
2571
2588
  onBlur: onBlur,
2572
2589
  onFocus: onFocus,
2573
2590
  registry: registry,
2574
- label: ""
2591
+ label: "",
2592
+ "aria-describedby": utils.ariaDescribedByIds(rootId)
2575
2593
  });
2576
2594
  }
2577
2595
  /** The `AltDateWidget` is an alternative widget for rendering date properties.
@@ -2709,7 +2727,7 @@
2709
2727
  return /*#__PURE__*/React__default["default"].createElement("div", {
2710
2728
  className: "checkbox " + (disabled || readonly ? "disabled" : "")
2711
2729
  }, schema.description && /*#__PURE__*/React__default["default"].createElement(DescriptionFieldTemplate, {
2712
- id: id + "__description",
2730
+ id: utils.descriptionId(id),
2713
2731
  description: schema.description,
2714
2732
  schema: schema,
2715
2733
  uiSchema: uiSchema,
@@ -2724,24 +2742,11 @@
2724
2742
  autoFocus: autofocus,
2725
2743
  onChange: handleChange,
2726
2744
  onBlur: handleBlur,
2727
- onFocus: handleFocus
2745
+ onFocus: handleFocus,
2746
+ "aria-describedby": utils.ariaDescribedByIds(id)
2728
2747
  }), /*#__PURE__*/React__default["default"].createElement("span", null, label)));
2729
2748
  }
2730
2749
 
2731
- function selectValue(value, selected, all) {
2732
- var at = all.indexOf(value);
2733
- var updated = selected.slice(0, at).concat(value, selected.slice(at));
2734
- // As inserting values at predefined index positions doesn't work with empty
2735
- // arrays, we need to reorder the updated selection to match the initial order
2736
- return updated.sort(function (a, b) {
2737
- return Number(all.indexOf(a) > all.indexOf(b));
2738
- });
2739
- }
2740
- function deselectValue(value, selected) {
2741
- return selected.filter(function (v) {
2742
- return v !== value;
2743
- });
2744
- }
2745
2750
  /** The `CheckboxesWidget` is a widget for rendering checkbox groups.
2746
2751
  * It is typically used to represent an array of enums.
2747
2752
  *
@@ -2760,32 +2765,30 @@
2760
2765
  autofocus = _ref$autofocus === void 0 ? false : _ref$autofocus,
2761
2766
  readonly = _ref.readonly,
2762
2767
  onChange = _ref.onChange;
2768
+ var checkboxesValues = Array.isArray(value) ? value : [value];
2763
2769
  return /*#__PURE__*/React__default["default"].createElement("div", {
2764
2770
  className: "checkboxes",
2765
2771
  id: id
2766
2772
  }, Array.isArray(enumOptions) && enumOptions.map(function (option, index) {
2767
- var checked = value.indexOf(option.value) !== -1;
2773
+ var checked = checkboxesValues.includes(option.value);
2768
2774
  var itemDisabled = Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) != -1;
2769
2775
  var disabledCls = disabled || itemDisabled || readonly ? "disabled" : "";
2770
2776
  var handleChange = function handleChange(event) {
2771
- var all = enumOptions.map(function (_ref2) {
2772
- var value = _ref2.value;
2773
- return value;
2774
- });
2775
2777
  if (event.target.checked) {
2776
- onChange(selectValue(option.value, value, all));
2778
+ onChange(utils.enumOptionsSelectValue(option.value, checkboxesValues, enumOptions));
2777
2779
  } else {
2778
- onChange(deselectValue(option.value, value));
2780
+ onChange(utils.enumOptionsDeselectValue(option.value, checkboxesValues));
2779
2781
  }
2780
2782
  };
2781
2783
  var checkbox = /*#__PURE__*/React__default["default"].createElement("span", null, /*#__PURE__*/React__default["default"].createElement("input", {
2782
2784
  type: "checkbox",
2783
- id: id + "-" + option.value,
2785
+ id: utils.optionId(id, option),
2784
2786
  name: id,
2785
2787
  checked: checked,
2786
2788
  disabled: disabled || itemDisabled || readonly,
2787
2789
  autoFocus: autofocus && index === 0,
2788
- onChange: handleChange
2790
+ onChange: handleChange,
2791
+ "aria-describedby": utils.ariaDescribedByIds(id)
2789
2792
  }), /*#__PURE__*/React__default["default"].createElement("span", null, option.label));
2790
2793
  return inline ? /*#__PURE__*/React__default["default"].createElement("label", {
2791
2794
  key: option.value,
@@ -2981,7 +2984,8 @@
2981
2984
  defaultValue: "",
2982
2985
  autoFocus: autofocus,
2983
2986
  multiple: multiple,
2984
- accept: options.accept ? String(options.accept) : undefined
2987
+ accept: options.accept ? String(options.accept) : undefined,
2988
+ "aria-describedby": utils.ariaDescribedByIds(id)
2985
2989
  })), /*#__PURE__*/React__default["default"].createElement(FilesInfo, {
2986
2990
  filesInfo: filesInfo
2987
2991
  }));
@@ -3058,7 +3062,7 @@
3058
3062
  };
3059
3063
  var radio = /*#__PURE__*/React__default["default"].createElement("span", null, /*#__PURE__*/React__default["default"].createElement("input", {
3060
3064
  type: "radio",
3061
- id: id + "-" + option.value,
3065
+ id: utils.optionId(id, option),
3062
3066
  checked: checked,
3063
3067
  name: name,
3064
3068
  required: required,
@@ -3067,7 +3071,8 @@
3067
3071
  autoFocus: autofocus && i === 0,
3068
3072
  onChange: handleChange,
3069
3073
  onBlur: handleBlur,
3070
- onFocus: handleFocus
3074
+ onFocus: handleFocus,
3075
+ "aria-describedby": utils.ariaDescribedByIds(id)
3071
3076
  }), /*#__PURE__*/React__default["default"].createElement("span", null, option.label));
3072
3077
  return inline ? /*#__PURE__*/React__default["default"].createElement("label", {
3073
3078
  key: option.value,
@@ -3153,7 +3158,8 @@
3153
3158
  autoFocus: autofocus,
3154
3159
  onBlur: handleBlur,
3155
3160
  onFocus: handleFocus,
3156
- onChange: handleChange
3161
+ onChange: handleChange,
3162
+ "aria-describedby": utils.ariaDescribedByIds(id)
3157
3163
  }, !multiple && schema["default"] === undefined && /*#__PURE__*/React__default["default"].createElement("option", {
3158
3164
  value: ""
3159
3165
  }, placeholder), Array.isArray(enumOptions) && enumOptions.map(function (_ref2, i) {
@@ -3211,7 +3217,8 @@
3211
3217
  rows: options.rows,
3212
3218
  onBlur: handleBlur,
3213
3219
  onFocus: handleFocus,
3214
- onChange: handleChange
3220
+ onChange: handleChange,
3221
+ "aria-describedby": utils.ariaDescribedByIds(id)
3215
3222
  });
3216
3223
  }
3217
3224
  TextareaWidget.defaultProps = {