@rjsf/utils 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('lodash-es/isEqualWith'), require('lodash-es/get'), require('lodash-es/isEmpty'), require('jsonpointer'), require('lodash-es/omit'), require('lodash-es/set'), require('json-schema-merge-allof'), require('lodash-es/union'), require('lodash-es/cloneDeep'), require('react'), require('react-is')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'lodash-es/isEqualWith', 'lodash-es/get', 'lodash-es/isEmpty', 'jsonpointer', 'lodash-es/omit', 'lodash-es/set', 'json-schema-merge-allof', 'lodash-es/union', 'lodash-es/cloneDeep', 'react', 'react-is'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@rjsf/utils"] = {}, global.isEqualWith, global.get, global.isEmpty, global.jsonpointer, global.omit, global.set, global.mergeAllOf, global.union, global.cloneDeep, global.React, global.ReactIs));
5
- })(this, (function (exports, isEqualWith, get, isEmpty, jsonpointer, omit, set, mergeAllOf, union, cloneDeep, React, ReactIs) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('lodash-es/isEqualWith'), require('lodash-es/get'), require('lodash-es/isEmpty'), require('jsonpointer'), require('lodash-es/omit'), require('lodash-es/set'), require('json-schema-merge-allof'), require('lodash-es/union'), require('lodash-es/cloneDeep'), require('react'), require('react-is'), require('lodash-es/isString')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'lodash-es/isEqualWith', 'lodash-es/get', 'lodash-es/isEmpty', 'jsonpointer', 'lodash-es/omit', 'lodash-es/set', 'json-schema-merge-allof', 'lodash-es/union', 'lodash-es/cloneDeep', 'react', 'react-is', 'lodash-es/isString'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@rjsf/utils"] = {}, global.isEqualWith, global.get, global.isEmpty, global.jsonpointer, global.omit, global.set, global.mergeAllOf, global.union, global.cloneDeep, global.React, global.ReactIs, global.isString));
5
+ })(this, (function (exports, isEqualWith, get, isEmpty, jsonpointer, omit, set, mergeAllOf, union, cloneDeep, React, ReactIs, isString) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -17,6 +17,7 @@
17
17
  var cloneDeep__default = /*#__PURE__*/_interopDefaultLegacy(cloneDeep);
18
18
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
19
19
  var ReactIs__default = /*#__PURE__*/_interopDefaultLegacy(ReactIs);
20
+ var isString__default = /*#__PURE__*/_interopDefaultLegacy(isString);
20
21
 
21
22
  /** Determines whether a `thing` is an object for the purposes of RSJF. In this case, `thing` is an object if it has
22
23
  * the type `object` but is NOT null, an array or a File.
@@ -89,7 +90,7 @@
89
90
  descriptor.enumerable = descriptor.enumerable || false;
90
91
  descriptor.configurable = true;
91
92
  if ("value" in descriptor) descriptor.writable = true;
92
- Object.defineProperty(target, descriptor.key, descriptor);
93
+ Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
93
94
  }
94
95
  }
95
96
  function _createClass(Constructor, protoProps, staticProps) {
@@ -129,6 +130,20 @@
129
130
  }
130
131
  return target;
131
132
  }
133
+ function _toPrimitive(input, hint) {
134
+ if (typeof input !== "object" || input === null) return input;
135
+ var prim = input[Symbol.toPrimitive];
136
+ if (prim !== undefined) {
137
+ var res = prim.call(input, hint || "default");
138
+ if (typeof res !== "object") return res;
139
+ throw new TypeError("@@toPrimitive must return a primitive value.");
140
+ }
141
+ return (hint === "string" ? String : Number)(input);
142
+ }
143
+ function _toPropertyKey(arg) {
144
+ var key = _toPrimitive(arg, "string");
145
+ return typeof key === "symbol" ? key : String(key);
146
+ }
132
147
 
133
148
  /** Below are the list of all the keys into various elements of a RJSFSchema or UiSchema that are used by the various
134
149
  * utility functions. In addition to those keys, there are the special `ADDITIONAL_PROPERTY_FLAG` and
@@ -1418,6 +1433,43 @@
1418
1433
  };
1419
1434
  }
1420
1435
 
1436
+ /** Removes the `value` from the currently `selected` list of values
1437
+ *
1438
+ * @param value - The value to be removed from the selected list
1439
+ * @param selected - The current list of selected values
1440
+ * @returns - The updated `selected` list with the `value` removed from it
1441
+ */
1442
+ function enumOptionsDeselectValue(value, selected) {
1443
+ return selected.filter(function (v) {
1444
+ return v !== value;
1445
+ });
1446
+ }
1447
+
1448
+ /** Add the `value` to the list of `selected` values in the proper order as defined by `allEnumOptions`
1449
+ *
1450
+ * @param value - The value that should be selected
1451
+ * @param selected - The current list of selected values
1452
+ * @param allEnumOptions - The list of all the known enumOptions
1453
+ * @returns - The updated list of selected enum values with `value` added to it in the proper location
1454
+ */
1455
+ function enumOptionsSelectValue(value, selected, allEnumOptions) {
1456
+ if (allEnumOptions === void 0) {
1457
+ allEnumOptions = [];
1458
+ }
1459
+ var all = allEnumOptions.map(function (_ref) {
1460
+ var value = _ref.value;
1461
+ return value;
1462
+ });
1463
+ var at = all.indexOf(value);
1464
+ // If location of the value is not in the list of all enum values, just put it at the end
1465
+ var updated = at === -1 ? selected.concat(value) : selected.slice(0, at).concat(value, selected.slice(at));
1466
+ // As inserting values at predefined index positions doesn't work with empty
1467
+ // arrays, we need to reorder the updated selection to match the initial order
1468
+ return updated.sort(function (a, b) {
1469
+ return Number(all.indexOf(a) > all.indexOf(b));
1470
+ });
1471
+ }
1472
+
1421
1473
  /** The `ErrorSchemaBuilder<T>` is used to build an `ErrorSchema<T>` since the definition of the `ErrorSchema` type is
1422
1474
  * designed for reading information rather than writing it. Use this class to add, replace or clear errors in an error
1423
1475
  * schema by using either dotted path or an array of path names. Once you are done building the `ErrorSchema`, you can
@@ -1777,6 +1829,80 @@
1777
1829
  }
1778
1830
  }
1779
1831
 
1832
+ /** Generates a consistent `id` pattern for a given `id` and a `suffix`
1833
+ *
1834
+ * @param id - Either simple string id or an IdSchema from which to extract it
1835
+ * @param suffix - The suffix to append to the id
1836
+ */
1837
+ function idGenerator(id, suffix) {
1838
+ var theId = isString__default["default"](id) ? id : id[ID_KEY];
1839
+ return theId + "__" + suffix;
1840
+ }
1841
+ /** Return a consistent `id` for the field description element
1842
+ *
1843
+ * @param id - Either simple string id or an IdSchema from which to extract it
1844
+ * @returns - The consistent id for the field description element from the given `id`
1845
+ */
1846
+ function descriptionId(id) {
1847
+ return idGenerator(id, "description");
1848
+ }
1849
+ /** Return a consistent `id` for the field error element
1850
+ *
1851
+ * @param id - Either simple string id or an IdSchema from which to extract it
1852
+ * @returns - The consistent id for the field error element from the given `id`
1853
+ */
1854
+ function errorId(id) {
1855
+ return idGenerator(id, "error");
1856
+ }
1857
+ /** Return a consistent `id` for the field examples element
1858
+ *
1859
+ * @param id - Either simple string id or an IdSchema from which to extract it
1860
+ * @returns - The consistent id for the field examples element from the given `id`
1861
+ */
1862
+ function examplesId(id) {
1863
+ return idGenerator(id, "examples");
1864
+ }
1865
+ /** Return a consistent `id` for the field help element
1866
+ *
1867
+ * @param id - Either simple string id or an IdSchema from which to extract it
1868
+ * @returns - The consistent id for the field help element from the given `id`
1869
+ */
1870
+ function helpId(id) {
1871
+ return idGenerator(id, "help");
1872
+ }
1873
+ /** Return a consistent `id` for the field title element
1874
+ *
1875
+ * @param id - Either simple string id or an IdSchema from which to extract it
1876
+ * @returns - The consistent id for the field title element from the given `id`
1877
+ */
1878
+ function titleId(id) {
1879
+ return idGenerator(id, "title");
1880
+ }
1881
+ /** Return a list of element ids that contain additional information about the field that can be used to as the aria
1882
+ * description of the field. This is correctly omitting `titleId` which would be "labeling" rather than "describing" the
1883
+ * element.
1884
+ *
1885
+ * @param id - Either simple string id or an IdSchema from which to extract it
1886
+ * @param [includeExamples=false] - Optional flag, if true, will add the `examplesId` into the list
1887
+ * @returns - The string containing the list of ids for use in an `aria-describedBy` attribute
1888
+ */
1889
+ function ariaDescribedByIds(id, includeExamples) {
1890
+ if (includeExamples === void 0) {
1891
+ includeExamples = false;
1892
+ }
1893
+ var examples = includeExamples ? " " + examplesId(id) : "";
1894
+ return errorId(id) + " " + descriptionId(id) + " " + helpId(id) + examples;
1895
+ }
1896
+ /** Return a consistent `id` for the `option`s of a `Radio` or `Checkboxes` widget
1897
+ *
1898
+ * @param id - The id of the parent component for the option
1899
+ * @param option - The option for which the id is desired
1900
+ * @returns - An id for the option based on the parent `id`
1901
+ */
1902
+ function optionId(id, option) {
1903
+ return id + "-" + option.value;
1904
+ }
1905
+
1780
1906
  /** Converts a local Date string into a UTC date string
1781
1907
  *
1782
1908
  * @param dateString - The string representation of a date as accepted by the `Date()` constructor
@@ -2102,11 +2228,17 @@
2102
2228
  exports.UI_OPTIONS_KEY = UI_OPTIONS_KEY;
2103
2229
  exports.UI_WIDGET_KEY = UI_WIDGET_KEY;
2104
2230
  exports.allowAdditionalItems = allowAdditionalItems;
2231
+ exports.ariaDescribedByIds = ariaDescribedByIds;
2105
2232
  exports.asNumber = asNumber;
2106
2233
  exports.canExpand = canExpand;
2107
2234
  exports.createSchemaUtils = createSchemaUtils;
2108
2235
  exports.dataURItoBlob = dataURItoBlob;
2109
2236
  exports.deepEquals = deepEquals;
2237
+ exports.descriptionId = descriptionId;
2238
+ exports.enumOptionsDeselectValue = enumOptionsDeselectValue;
2239
+ exports.enumOptionsSelectValue = enumOptionsSelectValue;
2240
+ exports.errorId = errorId;
2241
+ exports.examplesId = examplesId;
2110
2242
  exports.findSchemaDefinition = findSchemaDefinition;
2111
2243
  exports.getDefaultFormState = getDefaultFormState;
2112
2244
  exports.getDisplayLabel = getDisplayLabel;
@@ -2119,6 +2251,7 @@
2119
2251
  exports.getWidget = getWidget;
2120
2252
  exports.guessType = guessType;
2121
2253
  exports.hasWidget = hasWidget;
2254
+ exports.helpId = helpId;
2122
2255
  exports.isConstant = isConstant;
2123
2256
  exports.isCustomWidget = isCustomWidget;
2124
2257
  exports.isFilesArray = isFilesArray;
@@ -2131,6 +2264,7 @@
2131
2264
  exports.mergeObjects = mergeObjects;
2132
2265
  exports.mergeSchemas = mergeSchemas;
2133
2266
  exports.mergeValidationData = mergeValidationData;
2267
+ exports.optionId = optionId;
2134
2268
  exports.optionsList = optionsList;
2135
2269
  exports.orderProperties = orderProperties;
2136
2270
  exports.pad = pad;
@@ -2140,6 +2274,7 @@
2140
2274
  exports.retrieveSchema = retrieveSchema;
2141
2275
  exports.schemaRequiresTrueValue = schemaRequiresTrueValue;
2142
2276
  exports.shouldRender = shouldRender;
2277
+ exports.titleId = titleId;
2143
2278
  exports.toConstant = toConstant;
2144
2279
  exports.toDateString = toDateString;
2145
2280
  exports.toIdSchema = toIdSchema;