@rjsf/utils 5.0.0-beta.1

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.
Files changed (62) hide show
  1. package/LICENSE.md +201 -0
  2. package/README.md +106 -0
  3. package/dist/allowAdditionalItems.d.ts +8 -0
  4. package/dist/asNumber.d.ts +10 -0
  5. package/dist/canExpand.d.ts +11 -0
  6. package/dist/constants.d.ts +27 -0
  7. package/dist/createSchemaUtils.d.ts +9 -0
  8. package/dist/dataURItoBlob.d.ts +10 -0
  9. package/dist/deepEquals.d.ts +8 -0
  10. package/dist/findSchemaDefinition.d.ts +20 -0
  11. package/dist/getInputProps.d.ts +10 -0
  12. package/dist/getSchemaType.d.ts +13 -0
  13. package/dist/getSubmitButtonOptions.d.ts +10 -0
  14. package/dist/getTemplate.d.ts +10 -0
  15. package/dist/getUiOptions.d.ts +8 -0
  16. package/dist/getWidget.d.ts +13 -0
  17. package/dist/guessType.d.ts +7 -0
  18. package/dist/hasWidget.d.ts +10 -0
  19. package/dist/index.d.ts +38 -0
  20. package/dist/index.js +8 -0
  21. package/dist/isConstant.d.ts +8 -0
  22. package/dist/isCustomWidget.d.ts +7 -0
  23. package/dist/isFixedItems.d.ts +8 -0
  24. package/dist/isObject.d.ts +7 -0
  25. package/dist/localToUTC.d.ts +6 -0
  26. package/dist/mergeDefaultsWithFormData.d.ts +15 -0
  27. package/dist/mergeObjects.d.ts +9 -0
  28. package/dist/mergeSchemas.d.ts +10 -0
  29. package/dist/optionsList.d.ts +10 -0
  30. package/dist/orderProperties.d.ts +11 -0
  31. package/dist/pad.d.ts +7 -0
  32. package/dist/parseDateString.d.ts +9 -0
  33. package/dist/processSelectValue.d.ts +11 -0
  34. package/dist/rangeSpec.d.ts +9 -0
  35. package/dist/schema/getDefaultFormState.d.ts +47 -0
  36. package/dist/schema/getDisplayLabel.d.ts +11 -0
  37. package/dist/schema/getMatchingOption.d.ts +10 -0
  38. package/dist/schema/index.d.ts +11 -0
  39. package/dist/schema/isFilesArray.d.ts +10 -0
  40. package/dist/schema/isMultiSelect.d.ts +9 -0
  41. package/dist/schema/isSelect.d.ts +9 -0
  42. package/dist/schema/mergeValidationData.d.ts +12 -0
  43. package/dist/schema/retrieveSchema.d.ts +98 -0
  44. package/dist/schema/toIdSchema.d.ts +13 -0
  45. package/dist/schema/toPathSchema.d.ts +11 -0
  46. package/dist/schemaRequiresTrueValue.d.ts +11 -0
  47. package/dist/shouldRender.d.ts +10 -0
  48. package/dist/toConstant.d.ts +9 -0
  49. package/dist/toDateString.d.ts +9 -0
  50. package/dist/types.d.ts +755 -0
  51. package/dist/utcToLocal.d.ts +6 -0
  52. package/dist/utils.cjs.development.js +2274 -0
  53. package/dist/utils.cjs.development.js.map +1 -0
  54. package/dist/utils.cjs.production.min.js +2 -0
  55. package/dist/utils.cjs.production.min.js.map +1 -0
  56. package/dist/utils.esm.js +2192 -0
  57. package/dist/utils.esm.js.map +1 -0
  58. package/dist/utils.umd.development.js +2269 -0
  59. package/dist/utils.umd.development.js.map +1 -0
  60. package/dist/utils.umd.production.min.js +2 -0
  61. package/dist/utils.umd.production.min.js.map +1 -0
  62. package/package.json +79 -0
@@ -0,0 +1,2269 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('lodash-es/isEqualWith'), require('lodash-es/get'), require('jsonpointer'), require('lodash-es/omit'), require('lodash-es/set'), require('json-schema-merge-allof'), require('lodash-es/union'), require('lodash-es/isEmpty'), require('react'), require('react-is')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'lodash-es/isEqualWith', 'lodash-es/get', 'jsonpointer', 'lodash-es/omit', 'lodash-es/set', 'json-schema-merge-allof', 'lodash-es/union', 'lodash-es/isEmpty', 'react', 'react-is'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@rjsf/utils"] = {}, global.isEqualWith, global.get, global.jsonpointer, global.omit, global.set, global.mergeAllOf, global.union, global.isEmpty, global.React, global.ReactIs));
5
+ })(this, (function (exports, isEqualWith, get, jsonpointer, omit, set, mergeAllOf, union, isEmpty, React, ReactIs) { 'use strict';
6
+
7
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
+
9
+ var isEqualWith__default = /*#__PURE__*/_interopDefaultLegacy(isEqualWith);
10
+ var get__default = /*#__PURE__*/_interopDefaultLegacy(get);
11
+ var jsonpointer__default = /*#__PURE__*/_interopDefaultLegacy(jsonpointer);
12
+ var omit__default = /*#__PURE__*/_interopDefaultLegacy(omit);
13
+ var set__default = /*#__PURE__*/_interopDefaultLegacy(set);
14
+ var mergeAllOf__default = /*#__PURE__*/_interopDefaultLegacy(mergeAllOf);
15
+ var union__default = /*#__PURE__*/_interopDefaultLegacy(union);
16
+ var isEmpty__default = /*#__PURE__*/_interopDefaultLegacy(isEmpty);
17
+ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
18
+ var ReactIs__default = /*#__PURE__*/_interopDefaultLegacy(ReactIs);
19
+
20
+ /** Determines whether a `thing` is an object for the purposes of RSJF. In this case, `thing` is an object if it has
21
+ * the type `object` but is NOT null, an array or a File.
22
+ *
23
+ * @param thing - The thing to check to see whether it is an object
24
+ * @returns - True if it is a non-null, non-array, non-File object
25
+ */
26
+ function isObject(thing) {
27
+ if (typeof File !== "undefined" && thing instanceof File) {
28
+ return false;
29
+ }
30
+
31
+ return typeof thing === "object" && thing !== null && !Array.isArray(thing);
32
+ }
33
+
34
+ /** Checks the schema to see if it is allowing additional items, by verifying that `schema.additionalItems` is an
35
+ * object. The user is warned in the console if `schema.additionalItems` has the value `true`.
36
+ *
37
+ * @param schema - The schema object to check
38
+ * @returns - True if additional items is allowed, otherwise false
39
+ */
40
+
41
+ function allowAdditionalItems(schema) {
42
+ if (schema.additionalItems === true) {
43
+ console.warn("additionalItems=true is currently not supported");
44
+ }
45
+
46
+ return isObject(schema.additionalItems);
47
+ }
48
+
49
+ /** Attempts to convert the string into a number. If an empty string is provided, then `undefined` is returned. If a
50
+ * `null` is provided, it is returned. If the string ends in a `.` then the string is returned because the user may be
51
+ * in the middle of typing a float number. If a number ends in a pattern like `.0`, `.20`, `.030`, string is returned
52
+ * because the user may be typing number that will end in a non-zero digit. Otherwise, the string is wrapped by
53
+ * `Number()` and if that result is not `NaN`, that number will be returned, otherwise the string `value` will be.
54
+ *
55
+ * @param value - The string or null value to convert to a number
56
+ * @returns - The `value` converted to a number when appropriate, otherwise the `value`
57
+ */
58
+ function asNumber(value) {
59
+ if (value === "") {
60
+ return undefined;
61
+ }
62
+
63
+ if (value === null) {
64
+ return null;
65
+ }
66
+
67
+ if (/\.$/.test(value)) {
68
+ // '3.' can't really be considered a number even if it parses in js. The
69
+ // user is most likely entering a float.
70
+ return value;
71
+ }
72
+
73
+ if (/\.0$/.test(value)) {
74
+ // we need to return this as a string here, to allow for input like 3.07
75
+ return value;
76
+ }
77
+
78
+ if (/\.\d*0$/.test(value)) {
79
+ // It's a number, that's cool - but we need it as a string so it doesn't screw
80
+ // with the user when entering dollar amounts or other values (such as those with
81
+ // specific precision or number of significant digits)
82
+ return value;
83
+ }
84
+
85
+ const n = Number(value);
86
+ const valid = typeof n === "number" && !Number.isNaN(n);
87
+ return valid ? n : value;
88
+ }
89
+
90
+ /** Below are the list of all the keys into various elements of a RJSFSchema or UiSchema that are used by the various
91
+ * utility functions. In addition to those keys, there are the special `ADDITIONAL_PROPERTY_FLAG` and
92
+ * `RJSF_ADDITONAL_PROPERTIES_FLAG` flags that is added to a schema under certain conditions by the `retrieveSchema()`
93
+ * utility.
94
+ */
95
+ const ADDITIONAL_PROPERTY_FLAG = "__additional_property";
96
+ const ADDITIONAL_PROPERTIES_KEY = "additionalProperties";
97
+ const ALL_OF_KEY = "allOf";
98
+ const ANY_OF_KEY = "anyOf";
99
+ const CONST_KEY = "const";
100
+ const DEFAULT_KEY = "default";
101
+ const DEFINITIONS_KEY = "definitions";
102
+ const DEPENDENCIES_KEY = "dependencies";
103
+ const ENUM_KEY = "enum";
104
+ const ERRORS_KEY = "__errors";
105
+ const ID_KEY = "$id";
106
+ const ITEMS_KEY = "items";
107
+ const NAME_KEY = "$name";
108
+ const ONE_OF_KEY = "oneOf";
109
+ const PROPERTIES_KEY = "properties";
110
+ const REQUIRED_KEY = "required";
111
+ const SUBMIT_BTN_OPTIONS_KEY = "submitButtonOptions";
112
+ const REF_KEY = "$ref";
113
+ const RJSF_ADDITONAL_PROPERTIES_FLAG = "__rjsf_additionalProperties";
114
+ const UI_FIELD_KEY = "ui:field";
115
+ const UI_WIDGET_KEY = "ui:widget";
116
+ const UI_OPTIONS_KEY = "ui:options";
117
+
118
+ /** Get all passed options from ui:options, and ui:<optionName>, returning them in an object with the `ui:`
119
+ * stripped off.
120
+ *
121
+ * @param [uiSchema={}] - The UI Schema from which to get any `ui:xxx` options
122
+ * @returns - An object containing all of the `ui:xxx` options with the stripped off
123
+ */
124
+
125
+ function getUiOptions(uiSchema) {
126
+ if (uiSchema === void 0) {
127
+ uiSchema = {};
128
+ }
129
+
130
+ return Object.keys(uiSchema).filter(key => key.indexOf("ui:") === 0).reduce((options, key) => {
131
+ const value = uiSchema[key];
132
+
133
+ if (key === UI_WIDGET_KEY && isObject(value)) {
134
+ console.error("Setting options via ui:widget object is no longer supported, use ui:options instead");
135
+ return options;
136
+ }
137
+
138
+ if (key === UI_OPTIONS_KEY && isObject(value)) {
139
+ return { ...options,
140
+ ...value
141
+ };
142
+ }
143
+
144
+ return { ...options,
145
+ [key.substring(3)]: value
146
+ };
147
+ }, {});
148
+ }
149
+
150
+ /** Checks whether the field described by `schema`, having the `uiSchema` and `formData` supports expanding. The UI for
151
+ * the field can expand if it has additional properties, is not forced as non-expandable by the `uiSchema` and the
152
+ * `formData` object doesn't already have `schema.maxProperties` elements.
153
+ *
154
+ * @param schema - The schema for the field that is being checked
155
+ * @param [uiSchema={}] - The uiSchema for the field
156
+ * @param [formData] - The formData for the field
157
+ * @returns - True if the schema element has additionalProperties, is expandable, and not at the maxProperties limit
158
+ */
159
+
160
+ function canExpand(schema, uiSchema, formData) {
161
+ if (uiSchema === void 0) {
162
+ uiSchema = {};
163
+ }
164
+
165
+ if (!schema.additionalProperties) {
166
+ return false;
167
+ }
168
+
169
+ const {
170
+ expandable = true
171
+ } = getUiOptions(uiSchema);
172
+
173
+ if (expandable === false) {
174
+ return expandable;
175
+ } // if ui:options.expandable was not explicitly set to false, we can add
176
+ // another property if we have not exceeded maxProperties yet
177
+
178
+
179
+ if (schema.maxProperties !== undefined && formData) {
180
+ return Object.keys(formData).length < schema.maxProperties;
181
+ }
182
+
183
+ return true;
184
+ }
185
+
186
+ /** Implements a deep equals using the `lodash.isEqualWith` function, that provides a customized comparator that
187
+ * assumes all functions are equivalent.
188
+ *
189
+ * @param a - The first element to compare
190
+ * @param b - The second element to compare
191
+ * @returns - True if the `a` and `b` are deeply equal, false otherwise
192
+ */
193
+
194
+ function deepEquals(a, b) {
195
+ return isEqualWith__default["default"](a, b, (obj, other) => {
196
+ if (typeof obj === "function" && typeof other === "function") {
197
+ // Assume all functions are equivalent
198
+ // see https://github.com/rjsf-team/react-jsonschema-form/issues/255
199
+ return true;
200
+ }
201
+
202
+ return undefined; // fallback to default isEquals behavior
203
+ });
204
+ }
205
+
206
+ /** Splits out the value at the `key` in `object` from the `object`, returning an array that contains in the first
207
+ * location, the `object` minus the `key: value` and in the second location the `value`.
208
+ *
209
+ * @param key - The key from the object to extract
210
+ * @param object - The object from which to extract the element
211
+ * @returns - An array with the first value being the object minus the `key` element and the second element being the
212
+ * value from `object[key]`
213
+ */
214
+
215
+ function splitKeyElementFromObject(key, object) {
216
+ const value = object[key];
217
+ const remaining = omit__default["default"](object, [key]);
218
+ return [remaining, value];
219
+ }
220
+ /** Given the name of a `$ref` from within a schema, using the `rootSchema`, look up and return the sub-schema using the
221
+ * path provided by that reference. If `#` is not the first character of the reference, or the path does not exist in
222
+ * the schema, then throw an Error. Otherwise return the sub-schema. Also deals with nested `$ref`s in the sub-schema.
223
+ *
224
+ * @param $ref - The ref string for which the schema definition is desired
225
+ * @param [rootSchema={}] - The root schema in which to search for the definition
226
+ * @returns - The sub-schema within the `rootSchema` which matches the `$ref` if it exists
227
+ * @throws - Error indicating that no schema for that reference exists
228
+ */
229
+
230
+ function findSchemaDefinition($ref, rootSchema) {
231
+ if (rootSchema === void 0) {
232
+ rootSchema = {};
233
+ }
234
+
235
+ let ref = $ref || "";
236
+
237
+ if (ref.startsWith("#")) {
238
+ // Decode URI fragment representation.
239
+ ref = decodeURIComponent(ref.substring(1));
240
+ } else {
241
+ throw new Error("Could not find a definition for " + $ref + ".");
242
+ }
243
+
244
+ const current = jsonpointer__default["default"].get(rootSchema, ref);
245
+
246
+ if (current === undefined) {
247
+ throw new Error("Could not find a definition for " + $ref + ".");
248
+ }
249
+
250
+ if (current[REF_KEY]) {
251
+ const [remaining, theRef] = splitKeyElementFromObject(REF_KEY, current);
252
+ const subSchema = findSchemaDefinition(theRef, rootSchema);
253
+
254
+ if (Object.keys(remaining).length > 0) {
255
+ return { ...remaining,
256
+ ...subSchema
257
+ };
258
+ }
259
+
260
+ return subSchema;
261
+ }
262
+
263
+ return current;
264
+ }
265
+
266
+ /** Given the `formData` and list of `options`, attempts to find the index of the option that best matches the data.
267
+ *
268
+ * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
269
+ * @param formData - The current formData, if any, used to figure out a match
270
+ * @param options - The list of options to find a matching options from
271
+ * @param rootSchema - The root schema, used to primarily to look up `$ref`s
272
+ * @returns - The index of the matched option or 0 if none is available
273
+ */
274
+ function getMatchingOption(validator, formData, options, rootSchema) {
275
+ // For performance, skip validating subschemas if formData is undefined. We just
276
+ // want to get the first option in that case.
277
+ if (formData === undefined) {
278
+ return 0;
279
+ }
280
+
281
+ for (let i = 0; i < options.length; i++) {
282
+ const option = options[i]; // If the schema describes an object then we need to add slightly more
283
+ // strict matching to the schema, because unless the schema uses the
284
+ // "requires" keyword, an object will match the schema as long as it
285
+ // doesn't have matching keys with a conflicting type. To do this we use an
286
+ // "anyOf" with an array of requires. This augmentation expresses that the
287
+ // schema should match if any of the keys in the schema are present on the
288
+ // object and pass validation.
289
+
290
+ if (option.properties) {
291
+ // Create an "anyOf" schema that requires at least one of the keys in the
292
+ // "properties" object
293
+ const requiresAnyOf = {
294
+ anyOf: Object.keys(option.properties).map(key => ({
295
+ required: [key]
296
+ }))
297
+ };
298
+ let augmentedSchema; // If the "anyOf" keyword already exists, wrap the augmentation in an "allOf"
299
+
300
+ if (option.anyOf) {
301
+ // Create a shallow clone of the option
302
+ const { ...shallowClone
303
+ } = option;
304
+
305
+ if (!shallowClone.allOf) {
306
+ shallowClone.allOf = [];
307
+ } else {
308
+ // If "allOf" already exists, shallow clone the array
309
+ shallowClone.allOf = shallowClone.allOf.slice();
310
+ }
311
+
312
+ shallowClone.allOf.push(requiresAnyOf);
313
+ augmentedSchema = shallowClone;
314
+ } else {
315
+ augmentedSchema = Object.assign({}, option, requiresAnyOf);
316
+ } // Remove the "required" field as it's likely that not all fields have
317
+ // been filled in yet, which will mean that the schema is not valid
318
+
319
+
320
+ delete augmentedSchema.required;
321
+
322
+ if (validator.isValid(augmentedSchema, formData, rootSchema)) {
323
+ return i;
324
+ }
325
+ } else if (validator.isValid(option, formData, rootSchema)) {
326
+ return i;
327
+ }
328
+ }
329
+
330
+ return 0;
331
+ }
332
+
333
+ /** Given a specific `value` attempts to guess the type of a schema element. In the case where we have to implicitly
334
+ * create a schema, it is useful to know what type to use based on the data we are defining.
335
+ *
336
+ * @param value - The value from which to guess the type
337
+ * @returns - The best guess for the object type
338
+ */
339
+ function guessType(value) {
340
+ if (Array.isArray(value)) {
341
+ return "array";
342
+ }
343
+
344
+ if (typeof value === "string") {
345
+ return "string";
346
+ }
347
+
348
+ if (value == null) {
349
+ return "null";
350
+ }
351
+
352
+ if (typeof value === "boolean") {
353
+ return "boolean";
354
+ }
355
+
356
+ if (!isNaN(value)) {
357
+ return "number";
358
+ }
359
+
360
+ if (typeof value === "object") {
361
+ return "object";
362
+ } // Default to string if we can't figure it out
363
+
364
+
365
+ return "string";
366
+ }
367
+
368
+ /** Gets the type of a given `schema`. If the type is not explicitly defined, then an attempt is made to infer it from
369
+ * other elements of the schema as follows:
370
+ * - schema.const: Returns the `guessType()` of that value
371
+ * - schema.enum: Returns `string`
372
+ * - schema.properties: Returns `object`
373
+ * - schema.additionalProperties: Returns `object`
374
+ * - type is an array with a length of 2 and one type is 'null': Returns the other type
375
+ *
376
+ * @param schema - The schema for which to get the type
377
+ * @returns - The type of the schema
378
+ */
379
+
380
+ function getSchemaType(schema) {
381
+ let {
382
+ type
383
+ } = schema;
384
+
385
+ if (!type && schema.const) {
386
+ return guessType(schema.const);
387
+ }
388
+
389
+ if (!type && schema.enum) {
390
+ return "string";
391
+ }
392
+
393
+ if (!type && (schema.properties || schema.additionalProperties)) {
394
+ return "object";
395
+ }
396
+
397
+ if (Array.isArray(type) && type.length === 2 && type.includes("null")) {
398
+ type = type.find(type => type !== "null");
399
+ }
400
+
401
+ return type;
402
+ }
403
+
404
+ /** Detects whether the given `schema` contains fixed items. This is the case when `schema.items` is a non-empty array
405
+ * that only contains objects.
406
+ *
407
+ * @param schema - The schema in which to check for fixed items
408
+ * @returns - True if there are fixed items in the schema, false otherwise
409
+ */
410
+
411
+ function isFixedItems(schema) {
412
+ return Array.isArray(schema.items) && schema.items.length > 0 && schema.items.every(item => isObject(item));
413
+ }
414
+
415
+ /** Merges the `defaults` object of type `T` into the `formData` of type `T`
416
+ *
417
+ * When merging defaults and form data, we want to merge in this specific way:
418
+ * - objects are deeply merged
419
+ * - arrays are merged in such a way that:
420
+ * - when the array is set in form data, only array entries set in form data
421
+ * are deeply merged; additional entries from the defaults are ignored
422
+ * - when the array is not set in form data, the default is copied over
423
+ * - scalars are overwritten/set by form data
424
+ *
425
+ * @param defaults - The defaults to merge
426
+ * @param formData - The form data into which the defaults will be merged
427
+ * @returns - The resulting merged form data with defaults
428
+ */
429
+
430
+ function mergeDefaultsWithFormData(defaults, formData) {
431
+ if (Array.isArray(formData)) {
432
+ const defaultsArray = Array.isArray(defaults) ? defaults : [];
433
+ const mapped = formData.map((value, idx) => {
434
+ if (defaultsArray[idx]) {
435
+ return mergeDefaultsWithFormData(defaultsArray[idx], value);
436
+ }
437
+
438
+ return value;
439
+ });
440
+ return mapped;
441
+ }
442
+
443
+ if (isObject(formData)) {
444
+ // eslint-disable-next-line no-unused-vars
445
+ const acc = Object.assign({}, defaults); // Prevent mutation of source object.
446
+
447
+ return Object.keys(formData).reduce((acc, key) => {
448
+ acc[key] = mergeDefaultsWithFormData(defaults ? get__default["default"](defaults, key) : {}, get__default["default"](formData, key));
449
+ return acc;
450
+ }, acc);
451
+ }
452
+
453
+ return formData;
454
+ }
455
+
456
+ /** Recursively merge deeply nested objects.
457
+ *
458
+ * @param obj1 - The first object to merge
459
+ * @param obj2 - The second object to merge
460
+ * @param [concatArrays=false] - Optional flag that, when true, will cause arrays to be concatenated
461
+ * @returns - A new object that is the merge of the two given objects
462
+ */
463
+
464
+ function mergeObjects(obj1, obj2, concatArrays) {
465
+ if (concatArrays === void 0) {
466
+ concatArrays = false;
467
+ }
468
+
469
+ return Object.keys(obj2).reduce((acc, key) => {
470
+ const left = obj1 ? obj1[key] : {},
471
+ right = obj2[key];
472
+
473
+ if (obj1 && key in obj1 && isObject(right)) {
474
+ acc[key] = mergeObjects(left, right, concatArrays);
475
+ } else if (concatArrays && Array.isArray(left) && Array.isArray(right)) {
476
+ acc[key] = left.concat(right);
477
+ } else {
478
+ acc[key] = right;
479
+ }
480
+
481
+ return acc;
482
+ }, Object.assign({}, obj1)); // Prevent mutation of source object.
483
+ }
484
+
485
+ /** This function checks if the given `schema` matches a single constant value. This happens when either the schema has
486
+ * an `enum` array with a single value or there is a `const` defined.
487
+ *
488
+ * @param schema - The schema for a field
489
+ * @returns - True if the `schema` has a single constant value, false otherwise
490
+ */
491
+
492
+ function isConstant(schema) {
493
+ return Array.isArray(schema.enum) && schema.enum.length === 1 || CONST_KEY in schema;
494
+ }
495
+
496
+ /** Recursively merge deeply nested schemas. The difference between `mergeSchemas` and `mergeObjects` is that
497
+ * `mergeSchemas` only concats arrays for values under the 'required' keyword, and when it does, it doesn't include
498
+ * duplicate values.
499
+ *
500
+ * @param obj1 - The first schema object to merge
501
+ * @param obj2 - The second schema object to merge
502
+ * @returns - The merged schema object
503
+ */
504
+
505
+ function mergeSchemas(obj1, obj2) {
506
+ const acc = Object.assign({}, obj1); // Prevent mutation of source object.
507
+
508
+ return Object.keys(obj2).reduce((acc, key) => {
509
+ const left = obj1 ? obj1[key] : {},
510
+ right = obj2[key];
511
+
512
+ if (obj1 && key in obj1 && isObject(right)) {
513
+ acc[key] = mergeSchemas(left, right);
514
+ } else if (obj1 && obj2 && (getSchemaType(obj1) === "object" || getSchemaType(obj2) === "object") && key === REQUIRED_KEY && Array.isArray(left) && Array.isArray(right)) {
515
+ // Don't include duplicate values when merging 'required' fields.
516
+ acc[key] = union__default["default"](left, right);
517
+ } else {
518
+ acc[key] = right;
519
+ }
520
+
521
+ return acc;
522
+ }, acc);
523
+ }
524
+
525
+ /** Resolves a conditional block (if/else/then) by removing the condition and merging the appropriate conditional branch
526
+ * with the rest of the schema
527
+ *
528
+ * @param validator - An implementation of the `ValidatorType` interface that is used to detect valid schema conditions
529
+ * @param schema - The schema for which resolving a condition is desired
530
+ * @param rootSchema - The root schema that will be forwarded to all the APIs
531
+ * @param formData - The current formData to assist retrieving a schema
532
+ * @returns - A schema with the appropriate condition resolved
533
+ */
534
+
535
+ function resolveCondition(validator, schema, rootSchema, formData) {
536
+ const {
537
+ if: expression,
538
+ then,
539
+ else: otherwise,
540
+ ...resolvedSchemaLessConditional
541
+ } = schema;
542
+ const conditionalSchema = validator.isValid(expression, formData, rootSchema) ? then : otherwise;
543
+
544
+ if (conditionalSchema && typeof conditionalSchema !== "boolean") {
545
+ return retrieveSchema(validator, mergeSchemas(resolvedSchemaLessConditional, retrieveSchema(validator, conditionalSchema, rootSchema, formData)), rootSchema, formData);
546
+ }
547
+
548
+ return retrieveSchema(validator, resolvedSchemaLessConditional, rootSchema, formData);
549
+ }
550
+ /** Resolves references and dependencies within a schema and its 'allOf' children.
551
+ * Called internally by retrieveSchema.
552
+ *
553
+ * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
554
+ * @param schema - The schema for which resolving a schema is desired
555
+ * @param [rootSchema={}] - The root schema that will be forwarded to all the APIs
556
+ * @param [formData] - The current formData, if any, to assist retrieving a schema
557
+ * @returns - The schema having its references and dependencies resolved
558
+ */
559
+
560
+ function resolveSchema(validator, schema, rootSchema, formData) {
561
+ if (rootSchema === void 0) {
562
+ rootSchema = {};
563
+ }
564
+
565
+ if (REF_KEY in schema) {
566
+ return resolveReference(validator, schema, rootSchema, formData);
567
+ }
568
+
569
+ if (DEPENDENCIES_KEY in schema) {
570
+ const resolvedSchema = resolveDependencies(validator, schema, rootSchema, formData);
571
+ return retrieveSchema(validator, resolvedSchema, rootSchema, formData);
572
+ }
573
+
574
+ if (ALL_OF_KEY in schema) {
575
+ return { ...schema,
576
+ allOf: schema.allOf.map(allOfSubschema => retrieveSchema(validator, allOfSubschema, rootSchema, formData))
577
+ };
578
+ } // No $ref or dependencies attribute found, returning the original schema.
579
+
580
+
581
+ return schema;
582
+ }
583
+ /** Resolves references within a schema and its 'allOf' children.
584
+ *
585
+ * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
586
+ * @param schema - The schema for which resolving a reference is desired
587
+ * @param rootSchema - The root schema that will be forwarded to all the APIs
588
+ * @param [formData] - The current formData, if any, to assist retrieving a schema
589
+ * @returns - The schema having its references resolved
590
+ */
591
+
592
+ function resolveReference(validator, schema, rootSchema, formData) {
593
+ // Retrieve the referenced schema definition.
594
+ const $refSchema = findSchemaDefinition(schema.$ref, rootSchema); // Drop the $ref property of the source schema.
595
+
596
+ const {
597
+ $ref,
598
+ ...localSchema
599
+ } = schema; // Update referenced schema definition with local schema properties.
600
+
601
+ return retrieveSchema(validator, { ...$refSchema,
602
+ ...localSchema
603
+ }, rootSchema, formData);
604
+ }
605
+ /** Creates new 'properties' items for each key in the `formData`
606
+ *
607
+ * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
608
+ * @param theSchema - The schema for which the existing additional properties is desired
609
+ * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s * @param validator
610
+ * @param [aFormData] - The current formData, if any, to assist retrieving a schema
611
+ * @returns - The updated schema with additional properties stubbed
612
+ */
613
+
614
+ function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFormData) {
615
+ // Clone the schema so we don't ruin the consumer's original
616
+ const schema = { ...theSchema,
617
+ properties: { ...theSchema.properties
618
+ }
619
+ }; // make sure formData is an object
620
+
621
+ const formData = aFormData && isObject(aFormData) ? aFormData : {};
622
+ Object.keys(formData).forEach(key => {
623
+ if (key in schema.properties) {
624
+ // No need to stub, our schema already has the property
625
+ return;
626
+ }
627
+
628
+ let additionalProperties = {};
629
+
630
+ if (typeof schema.additionalProperties !== "boolean") {
631
+ if (REF_KEY in schema.additionalProperties) {
632
+ additionalProperties = retrieveSchema(validator, {
633
+ $ref: get__default["default"](schema.additionalProperties, [REF_KEY])
634
+ }, rootSchema, formData);
635
+ } else if ("type" in schema.additionalProperties) {
636
+ additionalProperties = { ...schema.additionalProperties
637
+ };
638
+ } else {
639
+ additionalProperties = {
640
+ type: guessType(get__default["default"](formData, [key]))
641
+ };
642
+ }
643
+ } else {
644
+ additionalProperties = {
645
+ type: guessType(get__default["default"](formData, [key]))
646
+ };
647
+ } // The type of our new key should match the additionalProperties value;
648
+
649
+
650
+ schema.properties[key] = additionalProperties; // Set our additional property flag so we know it was dynamically added
651
+
652
+ set__default["default"](schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
653
+ });
654
+ return schema;
655
+ }
656
+ /** Retrieves an expanded schema that has had all of its conditions, additional properties, references and dependencies
657
+ * resolved and merged into the `schema` given a `validator`, `rootSchema` and `rawFormData` that is used to do the
658
+ * potentially recursive resolution.
659
+ *
660
+ * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
661
+ * @param schema - The schema for which retrieving a schema is desired
662
+ * @param [rootSchema={}] - The root schema that will be forwarded to all the APIs
663
+ * @param [rawFormData] - The current formData, if any, to assist retrieving a schema
664
+ * @returns - The schema having its conditions, additional properties, references and dependencies resolved
665
+ */
666
+
667
+ function retrieveSchema(validator, schema, rootSchema, rawFormData) {
668
+ if (rootSchema === void 0) {
669
+ rootSchema = {};
670
+ }
671
+
672
+ if (!isObject(schema)) {
673
+ return {};
674
+ }
675
+
676
+ let resolvedSchema = resolveSchema(validator, schema, rootSchema, rawFormData);
677
+
678
+ if ("if" in schema) {
679
+ return resolveCondition(validator, schema, rootSchema, rawFormData);
680
+ }
681
+
682
+ const formData = rawFormData || {}; // For each level of the dependency, we need to recursively determine the appropriate resolved schema given the current state of formData.
683
+ // Otherwise, nested allOf subschemas will not be correctly displayed.
684
+
685
+ if (resolvedSchema.properties) {
686
+ const properties = {};
687
+ Object.entries(resolvedSchema.properties).forEach(entries => {
688
+ const propName = entries[0];
689
+ const propSchema = entries[1];
690
+ const rawPropData = formData[propName];
691
+ const propData = isObject(rawPropData) ? rawPropData : {};
692
+ const resolvedPropSchema = retrieveSchema(validator, propSchema, rootSchema, propData);
693
+ properties[propName] = resolvedPropSchema;
694
+
695
+ if (propSchema !== resolvedPropSchema && resolvedSchema.properties !== properties) {
696
+ resolvedSchema = { ...resolvedSchema,
697
+ properties
698
+ };
699
+ }
700
+ });
701
+ }
702
+
703
+ if (ALL_OF_KEY in schema) {
704
+ try {
705
+ resolvedSchema = mergeAllOf__default["default"]({ ...resolvedSchema,
706
+ allOf: resolvedSchema.allOf
707
+ });
708
+ } catch (e) {
709
+ console.warn("could not merge subschemas in allOf:\n" + e);
710
+ const {
711
+ allOf,
712
+ ...resolvedSchemaWithoutAllOf
713
+ } = resolvedSchema;
714
+ return resolvedSchemaWithoutAllOf;
715
+ }
716
+ }
717
+
718
+ const hasAdditionalProperties = ADDITIONAL_PROPERTIES_KEY in resolvedSchema && resolvedSchema.additionalProperties !== false;
719
+
720
+ if (hasAdditionalProperties) {
721
+ return stubExistingAdditionalProperties(validator, resolvedSchema, rootSchema, formData);
722
+ }
723
+
724
+ return resolvedSchema;
725
+ }
726
+ /** Resolves dependencies within a schema and its 'allOf' children.
727
+ *
728
+ * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
729
+ * @param schema - The schema for which resolving a dependency is desired
730
+ * @param rootSchema - The root schema that will be forwarded to all the APIs
731
+ * @param [formData] - The current formData, if any, to assist retrieving a schema
732
+ * @returns - The schema with its dependencies resolved
733
+ */
734
+
735
+ function resolveDependencies(validator, schema, rootSchema, formData) {
736
+ // Drop the dependencies from the source schema.
737
+ const {
738
+ dependencies,
739
+ ...remainingSchema
740
+ } = schema;
741
+ let resolvedSchema = remainingSchema;
742
+
743
+ if (Array.isArray(resolvedSchema.oneOf)) {
744
+ resolvedSchema = resolvedSchema.oneOf[getMatchingOption(validator, formData, resolvedSchema.oneOf, rootSchema)];
745
+ } else if (Array.isArray(resolvedSchema.anyOf)) {
746
+ resolvedSchema = resolvedSchema.anyOf[getMatchingOption(validator, formData, resolvedSchema.anyOf, rootSchema)];
747
+ }
748
+
749
+ return processDependencies(validator, dependencies, resolvedSchema, rootSchema, formData);
750
+ }
751
+ /** Processes all the `dependencies` recursively into the `resolvedSchema` as needed
752
+ *
753
+ * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
754
+ * @param dependencies - The set of dependencies that needs to be processed
755
+ * @param resolvedSchema - The schema for which processing dependencies is desired
756
+ * @param rootSchema - The root schema that will be forwarded to all the APIs
757
+ * @param [formData] - The current formData, if any, to assist retrieving a schema
758
+ * @returns - The schema with the `dependencies` resolved into it
759
+ */
760
+
761
+ function processDependencies(validator, dependencies, resolvedSchema, rootSchema, formData) {
762
+ let schema = resolvedSchema; // Process dependencies updating the local schema properties as appropriate.
763
+
764
+ for (const dependencyKey in dependencies) {
765
+ // Skip this dependency if its trigger property is not present.
766
+ if (get__default["default"](formData, [dependencyKey]) === undefined) {
767
+ continue;
768
+ } // Skip this dependency if it is not included in the schema (such as when dependencyKey is itself a hidden dependency.)
769
+
770
+
771
+ if (schema.properties && !(dependencyKey in schema.properties)) {
772
+ continue;
773
+ }
774
+
775
+ const [remainingDependencies, dependencyValue] = splitKeyElementFromObject(dependencyKey, dependencies);
776
+
777
+ if (Array.isArray(dependencyValue)) {
778
+ schema = withDependentProperties(schema, dependencyValue);
779
+ } else if (isObject(dependencyValue)) {
780
+ schema = withDependentSchema(validator, schema, rootSchema, dependencyKey, dependencyValue, formData);
781
+ }
782
+
783
+ return processDependencies(validator, remainingDependencies, schema, rootSchema, formData);
784
+ }
785
+
786
+ return schema;
787
+ }
788
+ /** Updates a schema with additionally required properties added
789
+ *
790
+ * @param schema - The schema for which resolving a dependent properties is desired
791
+ * @param [additionallyRequired] - An optional array of additionally required names
792
+ * @returns - The schema with the additional required values merged in
793
+ */
794
+
795
+ function withDependentProperties(schema, additionallyRequired) {
796
+ if (!additionallyRequired) {
797
+ return schema;
798
+ }
799
+
800
+ const required = Array.isArray(schema.required) ? Array.from(new Set([...schema.required, ...additionallyRequired])) : additionallyRequired;
801
+ return { ...schema,
802
+ required: required
803
+ };
804
+ }
805
+ /** Merges a dependent schema into the `schema` dealing with oneOfs and references
806
+ *
807
+ * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
808
+ * @param schema - The schema for which resolving a dependent schema is desired
809
+ * @param rootSchema - The root schema that will be forwarded to all the APIs
810
+ * @param dependencyKey - The key name of the dependency
811
+ * @param dependencyValue - The potentially dependent schema
812
+ * @param formData- The current formData to assist retrieving a schema
813
+ * @returns - The schema with the dependent schema resolved into it
814
+ */
815
+
816
+ function withDependentSchema(validator, schema, rootSchema, dependencyKey, dependencyValue, formData) {
817
+ const {
818
+ oneOf,
819
+ ...dependentSchema
820
+ } = retrieveSchema(validator, dependencyValue, rootSchema, formData);
821
+ schema = mergeSchemas(schema, dependentSchema); // Since it does not contain oneOf, we return the original schema.
822
+
823
+ if (oneOf === undefined) {
824
+ return schema;
825
+ } // Resolve $refs inside oneOf.
826
+
827
+
828
+ const resolvedOneOf = oneOf.map(subschema => {
829
+ if (typeof subschema === "boolean" || !(REF_KEY in subschema)) {
830
+ return subschema;
831
+ }
832
+
833
+ return resolveReference(validator, subschema, rootSchema, formData);
834
+ });
835
+ return withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, resolvedOneOf, formData);
836
+ }
837
+ /** Returns a `schema` with the best choice from the `oneOf` options merged into it
838
+ *
839
+ * @param validator - An implementation of the `ValidatorType` interface that will be used to validate oneOf options
840
+ * @param schema - The schema for which resolving a oneOf subschema is desired
841
+ * @param rootSchema - The root schema that will be forwarded to all the APIs
842
+ * @param dependencyKey - The key name of the oneOf dependency
843
+ * @param oneOf - The list of schemas representing the oneOf options
844
+ * @param [formData] - The current formData to assist retrieving a schema
845
+ * @returns The schema with best choice of oneOf schemas merged into
846
+ */
847
+
848
+ function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, oneOf, formData) {
849
+ const validSubschemas = oneOf.filter(subschema => {
850
+ if (typeof subschema === "boolean" || !subschema.properties) {
851
+ return false;
852
+ }
853
+
854
+ const {
855
+ [dependencyKey]: conditionPropertySchema
856
+ } = subschema.properties;
857
+
858
+ if (conditionPropertySchema) {
859
+ const conditionSchema = {
860
+ type: "object",
861
+ properties: {
862
+ [dependencyKey]: conditionPropertySchema
863
+ }
864
+ };
865
+ const {
866
+ errors
867
+ } = validator.validateFormData(formData, conditionSchema);
868
+ return errors.length === 0;
869
+ }
870
+
871
+ return false;
872
+ });
873
+
874
+ if (validSubschemas.length !== 1) {
875
+ console.warn("ignoring oneOf in dependencies because there isn't exactly one subschema that is valid");
876
+ return schema;
877
+ }
878
+
879
+ const subschema = validSubschemas[0];
880
+ const [dependentSubschema] = splitKeyElementFromObject(dependencyKey, subschema.properties);
881
+ const dependentSchema = { ...subschema,
882
+ properties: dependentSubschema
883
+ };
884
+ return mergeSchemas(schema, retrieveSchema(validator, dependentSchema, rootSchema, formData));
885
+ }
886
+
887
+ /** Checks to see if the `schema` combination represents a select
888
+ *
889
+ * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
890
+ * @param theSchema - The schema for which check for a select flag is desired
891
+ * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
892
+ * @returns - True if schema contains a select, otherwise false
893
+ */
894
+
895
+ function isSelect(validator, theSchema, rootSchema) {
896
+ if (rootSchema === void 0) {
897
+ rootSchema = {};
898
+ }
899
+
900
+ const schema = retrieveSchema(validator, theSchema, rootSchema, undefined);
901
+ const altSchemas = schema.oneOf || schema.anyOf;
902
+
903
+ if (Array.isArray(schema.enum)) {
904
+ return true;
905
+ }
906
+
907
+ if (Array.isArray(altSchemas)) {
908
+ return altSchemas.every(altSchemas => typeof altSchemas !== "boolean" && isConstant(altSchemas));
909
+ }
910
+
911
+ return false;
912
+ }
913
+
914
+ /** Checks to see if the `schema` combination represents a multi-select
915
+ *
916
+ * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
917
+ * @param schema - The schema for which check for a multi-select flag is desired
918
+ * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
919
+ * @returns - True if schema contains a multi-select, otherwise false
920
+ */
921
+
922
+ function isMultiSelect(validator, schema, rootSchema) {
923
+ if (!schema.uniqueItems || !schema.items || typeof schema.items === "boolean") {
924
+ return false;
925
+ }
926
+
927
+ return isSelect(validator, schema.items, rootSchema);
928
+ }
929
+
930
+ /** Enum that indicates how `schema.additionalItems` should be handled by the `getInnerSchemaForArrayItem()` function.
931
+ */
932
+
933
+ var AdditionalItemsHandling;
934
+
935
+ (function (AdditionalItemsHandling) {
936
+ AdditionalItemsHandling[AdditionalItemsHandling["Ignore"] = 0] = "Ignore";
937
+ AdditionalItemsHandling[AdditionalItemsHandling["Invert"] = 1] = "Invert";
938
+ AdditionalItemsHandling[AdditionalItemsHandling["Fallback"] = 2] = "Fallback";
939
+ })(AdditionalItemsHandling || (AdditionalItemsHandling = {}));
940
+ /** Given a `schema` will return an inner schema that for an array item. This is computed differently based on the
941
+ * `additionalItems` enum and the value of `idx`. There are four possible returns:
942
+ * 1. If `idx` is >= 0, then if `schema.items` is an array the `idx`th element of the array is returned if it is a valid
943
+ * index and not a boolean, otherwise it falls through to 3.
944
+ * 2. If `schema.items` is not an array AND truthy and not a boolean, then `schema.items` is returned since it actually
945
+ * is a schema, otherwise it falls through to 3.
946
+ * 3. If `additionalItems` is not `AdditionalItemsHandling.Ignore` and `schema.additionalItems` is an object, then
947
+ * `schema.additionalItems` is returned since it actually is a schema, otherwise it falls through to 4.
948
+ * 4. {} is returned representing an empty schema
949
+ *
950
+ * @param schema - The schema from which to get the particular item
951
+ * @param [additionalItems=AdditionalItemsHandling.Ignore] - How do we want to handle additional items?
952
+ * @param [idx=-1] - Index, if non-negative, will be used to return the idx-th element in a `schema.items` array
953
+ * @returns - The best fit schema object from the `schema` given the `additionalItems` and `idx` modifiers
954
+ */
955
+
956
+
957
+ function getInnerSchemaForArrayItem(schema, additionalItems, idx) {
958
+ if (additionalItems === void 0) {
959
+ additionalItems = AdditionalItemsHandling.Ignore;
960
+ }
961
+
962
+ if (idx === void 0) {
963
+ idx = -1;
964
+ }
965
+
966
+ if (idx >= 0) {
967
+ if (Array.isArray(schema.items) && idx < schema.items.length) {
968
+ const item = schema.items[idx];
969
+
970
+ if (typeof item !== "boolean") {
971
+ return item;
972
+ }
973
+ }
974
+ } else if (schema.items && !Array.isArray(schema.items) && typeof schema.items !== "boolean") {
975
+ return schema.items;
976
+ }
977
+
978
+ if (additionalItems !== AdditionalItemsHandling.Ignore && isObject(schema.additionalItems)) {
979
+ return schema.additionalItems;
980
+ }
981
+
982
+ return {};
983
+ }
984
+ /** Computes the defaults for the current `schema` given the `rawFormData` and `parentDefaults` if any. This drills into
985
+ * the each level of the schema, recursively, to fill out every level of defaults provided by the schema.
986
+ *
987
+ * @param validator - an implementation of the `ValidatorType` interface that will be used when necessary
988
+ * @param schema - The schema for which the default state is desired
989
+ * @param [parentDefaults] - Any defaults provided by the parent field in the schema
990
+ * @param [rootSchema] - The options root schema, used to primarily to look up `$ref`s
991
+ * @param [rawFormData] - The current formData, if any, onto which to provide any missing defaults
992
+ * @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults
993
+ * @returns - The resulting `formData` with all the defaults provided
994
+ */
995
+
996
+ function computeDefaults(validator, schema, parentDefaults, rootSchema, rawFormData, includeUndefinedValues) {
997
+ if (rootSchema === void 0) {
998
+ rootSchema = {};
999
+ }
1000
+
1001
+ if (includeUndefinedValues === void 0) {
1002
+ includeUndefinedValues = false;
1003
+ }
1004
+
1005
+ const formData = isObject(rawFormData) ? rawFormData : {}; // Compute the defaults recursively: give highest priority to deepest nodes.
1006
+
1007
+ let defaults = parentDefaults;
1008
+
1009
+ if (isObject(defaults) && isObject(schema.default)) {
1010
+ // For object defaults, only override parent defaults that are defined in
1011
+ // schema.default.
1012
+ defaults = mergeObjects(defaults, schema.default);
1013
+ } else if (DEFAULT_KEY in schema) {
1014
+ defaults = schema.default;
1015
+ } else if (REF_KEY in schema) {
1016
+ // Use referenced schema defaults for this node.
1017
+ const refSchema = findSchemaDefinition(schema[REF_KEY], rootSchema);
1018
+ return computeDefaults(validator, refSchema, defaults, rootSchema, formData, includeUndefinedValues);
1019
+ } else if (DEPENDENCIES_KEY in schema) {
1020
+ const resolvedSchema = resolveDependencies(validator, schema, rootSchema, formData);
1021
+ return computeDefaults(validator, resolvedSchema, defaults, rootSchema, formData, includeUndefinedValues);
1022
+ } else if (isFixedItems(schema)) {
1023
+ defaults = schema.items.map((itemSchema, idx) => computeDefaults(validator, itemSchema, Array.isArray(parentDefaults) ? parentDefaults[idx] : undefined, rootSchema, formData, includeUndefinedValues));
1024
+ } else if (ONE_OF_KEY in schema) {
1025
+ schema = schema.oneOf[getMatchingOption(validator, undefined, schema.oneOf, rootSchema)];
1026
+ } else if (ANY_OF_KEY in schema) {
1027
+ schema = schema.anyOf[getMatchingOption(validator, undefined, schema.anyOf, rootSchema)];
1028
+ } // Not defaults defined for this node, fallback to generic typed ones.
1029
+
1030
+
1031
+ if (typeof defaults === "undefined") {
1032
+ defaults = schema.default;
1033
+ }
1034
+
1035
+ switch (getSchemaType(schema)) {
1036
+ // We need to recur for object schema inner default values.
1037
+ case "object":
1038
+ return Object.keys(schema.properties || {}).reduce((acc, key) => {
1039
+ // Compute the defaults for this node, with the parent defaults we might
1040
+ // have from a previous run: defaults[key].
1041
+ const computedDefault = computeDefaults(validator, get__default["default"](schema, [PROPERTIES_KEY, key]), get__default["default"](defaults, [key]), rootSchema, get__default["default"](formData, [key]), includeUndefinedValues);
1042
+
1043
+ if (includeUndefinedValues || computedDefault !== undefined) {
1044
+ acc[key] = computedDefault;
1045
+ }
1046
+
1047
+ return acc;
1048
+ }, {});
1049
+
1050
+ case "array":
1051
+ // Inject defaults into existing array defaults
1052
+ if (Array.isArray(defaults)) {
1053
+ defaults = defaults.map((item, idx) => {
1054
+ const schemaItem = getInnerSchemaForArrayItem(schema, AdditionalItemsHandling.Fallback, idx);
1055
+ return computeDefaults(validator, schemaItem, item, rootSchema);
1056
+ });
1057
+ } // Deeply inject defaults into already existing form data
1058
+
1059
+
1060
+ if (Array.isArray(rawFormData)) {
1061
+ const schemaItem = getInnerSchemaForArrayItem(schema);
1062
+ defaults = rawFormData.map((item, idx) => {
1063
+ return computeDefaults(validator, schemaItem, get__default["default"](defaults, [idx]), rootSchema, item);
1064
+ });
1065
+ }
1066
+
1067
+ if (schema.minItems) {
1068
+ if (!isMultiSelect(validator, schema, rootSchema)) {
1069
+ const defaultsLength = Array.isArray(defaults) ? defaults.length : 0;
1070
+
1071
+ if (schema.minItems > defaultsLength) {
1072
+ const defaultEntries = defaults || []; // populate the array with the defaults
1073
+
1074
+ const fillerSchema = getInnerSchemaForArrayItem(schema, AdditionalItemsHandling.Invert);
1075
+ const fillerDefault = fillerSchema.default;
1076
+ const fillerEntries = new Array(schema.minItems - defaultsLength).fill(computeDefaults(validator, fillerSchema, fillerDefault, rootSchema)); // then fill up the rest with either the item default or empty, up to minItems
1077
+
1078
+ return defaultEntries.concat(fillerEntries);
1079
+ }
1080
+ }
1081
+
1082
+ return defaults ? defaults : [];
1083
+ }
1084
+
1085
+ }
1086
+
1087
+ return defaults;
1088
+ }
1089
+ /** Returns the superset of `formData` that includes the given set updated to include any missing fields that have
1090
+ * computed to have defaults provided in the `schema`.
1091
+ *
1092
+ * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
1093
+ * @param theSchema - The schema for which the default state is desired
1094
+ * @param [formData] - The current formData, if any, onto which to provide any missing defaults
1095
+ * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
1096
+ * @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults
1097
+ * @returns - The resulting `formData` with all the defaults provided
1098
+ */
1099
+
1100
+ function getDefaultFormState(validator, theSchema, formData, rootSchema, includeUndefinedValues) {
1101
+ if (includeUndefinedValues === void 0) {
1102
+ includeUndefinedValues = false;
1103
+ }
1104
+
1105
+ if (!isObject(theSchema)) {
1106
+ throw new Error("Invalid schema: " + theSchema);
1107
+ }
1108
+
1109
+ const schema = retrieveSchema(validator, theSchema, rootSchema, formData);
1110
+ const defaults = computeDefaults(validator, schema, undefined, rootSchema, formData, includeUndefinedValues);
1111
+
1112
+ if (typeof formData === "undefined" || formData === null || typeof formData === "number" && isNaN(formData)) {
1113
+ // No form data? Use schema defaults.
1114
+ return defaults;
1115
+ }
1116
+
1117
+ if (isObject(formData)) {
1118
+ return mergeDefaultsWithFormData(defaults, formData);
1119
+ }
1120
+
1121
+ if (Array.isArray(formData)) {
1122
+ return mergeDefaultsWithFormData(defaults, formData);
1123
+ }
1124
+
1125
+ return formData;
1126
+ }
1127
+
1128
+ /** Checks to see if the `uiSchema` contains the `widget` field and that the widget is not `hidden`
1129
+ *
1130
+ * @param uiSchema - The UI Schema from which to detect if it is customized
1131
+ * @returns - True if the `uiSchema` describes a custom widget, false otherwise
1132
+ */
1133
+
1134
+ function isCustomWidget(uiSchema) {
1135
+ if (uiSchema === void 0) {
1136
+ uiSchema = {};
1137
+ }
1138
+
1139
+ return (// TODO: Remove the `&& uiSchema['ui:widget'] !== 'hidden'` once we support hidden widgets for arrays.
1140
+ // https://react-jsonschema-form.readthedocs.io/en/latest/usage/widgets/#hidden-widgets
1141
+ "widget" in getUiOptions(uiSchema) && getUiOptions(uiSchema)["widget"] !== "hidden"
1142
+ );
1143
+ }
1144
+
1145
+ /** Checks to see if the `schema` and `uiSchema` combination represents an array of files
1146
+ *
1147
+ * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
1148
+ * @param schema - The schema for which check for array of files flag is desired
1149
+ * @param [uiSchema={}] - The UI schema from which to check the widget
1150
+ * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
1151
+ * @returns - True if schema/uiSchema contains an array of files, otherwise false
1152
+ */
1153
+
1154
+ function isFilesArray(validator, schema, uiSchema, rootSchema) {
1155
+ if (uiSchema === void 0) {
1156
+ uiSchema = {};
1157
+ }
1158
+
1159
+ if (uiSchema[UI_WIDGET_KEY] === "files") {
1160
+ return true;
1161
+ }
1162
+
1163
+ if (schema.items) {
1164
+ const itemsSchema = retrieveSchema(validator, schema.items, rootSchema);
1165
+ return itemsSchema.type === "string" && itemsSchema.format === "data-url";
1166
+ }
1167
+
1168
+ return false;
1169
+ }
1170
+
1171
+ /** Determines whether the combination of `schema` and `uiSchema` properties indicates that the label for the `schema`
1172
+ * should be displayed in a UI.
1173
+ *
1174
+ * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
1175
+ * @param schema - The schema for which the display label flag is desired
1176
+ * @param [uiSchema={}] - The UI schema from which to derive potentially displayable information
1177
+ * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
1178
+ * @returns - True if the label should be displayed or false if it should not
1179
+ */
1180
+
1181
+ function getDisplayLabel(validator, schema, uiSchema, rootSchema) {
1182
+ if (uiSchema === void 0) {
1183
+ uiSchema = {};
1184
+ }
1185
+
1186
+ const uiOptions = getUiOptions(uiSchema);
1187
+ const {
1188
+ label = true
1189
+ } = uiOptions;
1190
+ let displayLabel = !!label;
1191
+ const schemaType = getSchemaType(schema);
1192
+
1193
+ if (schemaType === "array") {
1194
+ displayLabel = isMultiSelect(validator, schema, rootSchema) || isFilesArray(validator, schema, uiSchema, rootSchema) || isCustomWidget(uiSchema);
1195
+ }
1196
+
1197
+ if (schemaType === "object") {
1198
+ displayLabel = false;
1199
+ }
1200
+
1201
+ if (schemaType === "boolean" && !uiSchema[UI_WIDGET_KEY]) {
1202
+ displayLabel = false;
1203
+ }
1204
+
1205
+ if (uiSchema[UI_FIELD_KEY]) {
1206
+ displayLabel = false;
1207
+ }
1208
+
1209
+ return displayLabel;
1210
+ }
1211
+
1212
+ /** Merges the errors in `additionalErrorSchema` into the existing `validationData` by combining the hierarchies in the
1213
+ * two `ErrorSchema`s and then appending the error list from the `additionalErrorSchema` obtained by calling
1214
+ * `validator.toErrorList()` onto the `errors` in the `validationData`. If no `additionalErrorSchema` is passed, then
1215
+ * `validationData` is returned.
1216
+ *
1217
+ * @param validator - The validator used to convert an ErrorSchema to a list of errors
1218
+ * @param validationData - The current `ValidationData` into which to merge the additional errors
1219
+ * @param [additionalErrorSchema] - The additional set of errors in an `ErrorSchema`
1220
+ * @returns - The `validationData` with the additional errors from `additionalErrorSchema` merged into it, if provided.
1221
+ */
1222
+
1223
+ function mergeValidationData(validator, validationData, additionalErrorSchema) {
1224
+ if (!additionalErrorSchema) {
1225
+ return validationData;
1226
+ }
1227
+
1228
+ const {
1229
+ errors: oldErrors,
1230
+ errorSchema: oldErrorSchema
1231
+ } = validationData;
1232
+ let errors = validator.toErrorList(additionalErrorSchema);
1233
+ let errorSchema = additionalErrorSchema;
1234
+
1235
+ if (!isEmpty__default["default"](oldErrorSchema)) {
1236
+ errorSchema = mergeObjects(oldErrorSchema, additionalErrorSchema, true);
1237
+ errors = [...oldErrors].concat(errors);
1238
+ }
1239
+
1240
+ return {
1241
+ errorSchema,
1242
+ errors
1243
+ };
1244
+ }
1245
+
1246
+ /** Generates an `IdSchema` object for the `schema`, recursively
1247
+ *
1248
+ * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
1249
+ * @param schema - The schema for which the `IdSchema` is desired
1250
+ * @param [id] - The base id for the schema
1251
+ * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
1252
+ * @param [formData] - The current formData, if any, to assist retrieving a schema
1253
+ * @param [idPrefix='root'] - The prefix to use for the id
1254
+ * @param [idSeparator='_'] - The separator to use for the path segments in the id
1255
+ * @returns - The `IdSchema` object for the `schema`
1256
+ */
1257
+
1258
+ function toIdSchema(validator, schema, id, rootSchema, formData, idPrefix, idSeparator) {
1259
+ if (idPrefix === void 0) {
1260
+ idPrefix = "root";
1261
+ }
1262
+
1263
+ if (idSeparator === void 0) {
1264
+ idSeparator = "_";
1265
+ }
1266
+
1267
+ if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
1268
+ const _schema = retrieveSchema(validator, schema, rootSchema, formData);
1269
+
1270
+ return toIdSchema(validator, _schema, id, rootSchema, formData, idPrefix, idSeparator);
1271
+ }
1272
+
1273
+ if (ITEMS_KEY in schema && !get__default["default"](schema, [ITEMS_KEY, REF_KEY])) {
1274
+ return toIdSchema(validator, get__default["default"](schema, ITEMS_KEY), id, rootSchema, formData, idPrefix, idSeparator);
1275
+ }
1276
+
1277
+ const $id = id || idPrefix;
1278
+ const idSchema = {
1279
+ $id
1280
+ };
1281
+
1282
+ if (schema.type === "object" && PROPERTIES_KEY in schema) {
1283
+ for (const name in schema.properties) {
1284
+ const field = get__default["default"](schema, [PROPERTIES_KEY, name]);
1285
+ const fieldId = idSchema[ID_KEY] + idSeparator + name;
1286
+ idSchema[name] = toIdSchema(validator, isObject(field) ? field : {}, fieldId, rootSchema, // It's possible that formData is not an object -- this can happen if an
1287
+ // array item has just been added, but not populated with data yet
1288
+ get__default["default"](formData, [name]), idPrefix, idSeparator);
1289
+ }
1290
+ }
1291
+
1292
+ return idSchema;
1293
+ }
1294
+
1295
+ /** Generates an `PathSchema` object for the `schema`, recursively
1296
+ *
1297
+ * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
1298
+ * @param schema - The schema for which the `PathSchema` is desired
1299
+ * @param [name=''] - The base name for the schema
1300
+ * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
1301
+ * @param [formData] - The current formData, if any, to assist retrieving a schema
1302
+ * @returns - The `PathSchema` object for the `schema`
1303
+ */
1304
+
1305
+ function toPathSchema(validator, schema, name, rootSchema, formData) {
1306
+ if (name === void 0) {
1307
+ name = "";
1308
+ }
1309
+
1310
+ if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
1311
+ const _schema = retrieveSchema(validator, schema, rootSchema, formData);
1312
+
1313
+ return toPathSchema(validator, _schema, name, rootSchema, formData);
1314
+ }
1315
+
1316
+ const pathSchema = {
1317
+ [NAME_KEY]: name.replace(/^\./, "")
1318
+ };
1319
+
1320
+ if (ADDITIONAL_PROPERTIES_KEY in schema && schema[ADDITIONAL_PROPERTIES_KEY] === true) {
1321
+ set__default["default"](pathSchema, RJSF_ADDITONAL_PROPERTIES_FLAG, true);
1322
+ }
1323
+
1324
+ if (ITEMS_KEY in schema && Array.isArray(formData)) {
1325
+ formData.forEach((element, i) => {
1326
+ pathSchema[i] = toPathSchema(validator, schema.items, name + "." + i, rootSchema, element);
1327
+ });
1328
+ } else if (PROPERTIES_KEY in schema) {
1329
+ for (const property in schema.properties) {
1330
+ const field = get__default["default"](schema, [PROPERTIES_KEY, property]);
1331
+ pathSchema[property] = toPathSchema(validator, field, name + "." + property, rootSchema, // It's possible that formData is not an object -- this can happen if an
1332
+ // array item has just been added, but not populated with data yet
1333
+ get__default["default"](formData, [property]));
1334
+ }
1335
+ }
1336
+
1337
+ return pathSchema;
1338
+ }
1339
+
1340
+ /** The `SchemaUtils` class provides a wrapper around the publicly exported APIs in the `utils/schema` directory such
1341
+ * that one does not have to explicitly pass the `validator` or `rootSchema` to each method. Since both the `validator`
1342
+ * and `rootSchema` generally does not change across a `Form`, this allows for providing a simplified set of APIs to the
1343
+ * `@rjsf/core` components and the various themes as well. This class implements the `SchemaUtilsType` interface.
1344
+ */
1345
+
1346
+ class SchemaUtils {
1347
+ /** Constructs the `SchemaUtils` instance with the given `validator` and `rootSchema` stored as instance variables
1348
+ *
1349
+ * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
1350
+ * @param rootSchema - The root schema that will be forwarded to all the APIs
1351
+ */
1352
+ constructor(validator, rootSchema) {
1353
+ this.rootSchema = void 0;
1354
+ this.validator = void 0;
1355
+ this.rootSchema = rootSchema;
1356
+ this.validator = validator;
1357
+ }
1358
+ /** Returns the `ValidatorType` in the `SchemaUtilsType`
1359
+ *
1360
+ * @returns - The `ValidatorType`
1361
+ */
1362
+
1363
+
1364
+ getValidator() {
1365
+ return this.validator;
1366
+ }
1367
+ /** Determines whether either the `validator` and `rootSchema` differ from the ones associated with this instance of
1368
+ * the `SchemaUtilsType`. If either `validator` or `rootSchema` are falsy, then return false to prevent the creation
1369
+ * of a new `SchemaUtilsType` with incomplete properties.
1370
+ *
1371
+ * @param validator - An implementation of the `ValidatorType` interface that will be compared against the current one
1372
+ * @param rootSchema - The root schema that will be compared against the current one
1373
+ * @returns - True if the `SchemaUtilsType` differs from the given `validator` or `rootSchema`
1374
+ */
1375
+
1376
+
1377
+ doesSchemaUtilsDiffer(validator, rootSchema) {
1378
+ if (!validator || !rootSchema) {
1379
+ return false;
1380
+ }
1381
+
1382
+ return this.validator !== validator || !deepEquals(this.rootSchema, rootSchema);
1383
+ }
1384
+ /** Returns the superset of `formData` that includes the given set updated to include any missing fields that have
1385
+ * computed to have defaults provided in the `schema`.
1386
+ *
1387
+ * @param schema - The schema for which the default state is desired
1388
+ * @param [formData] - The current formData, if any, onto which to provide any missing defaults
1389
+ * @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults
1390
+ * @returns - The resulting `formData` with all the defaults provided
1391
+ */
1392
+
1393
+
1394
+ getDefaultFormState(schema, formData, includeUndefinedValues) {
1395
+ if (includeUndefinedValues === void 0) {
1396
+ includeUndefinedValues = false;
1397
+ }
1398
+
1399
+ return getDefaultFormState(this.validator, schema, formData, this.rootSchema, includeUndefinedValues);
1400
+ }
1401
+ /** Determines whether the combination of `schema` and `uiSchema` properties indicates that the label for the `schema`
1402
+ * should be displayed in a UI.
1403
+ *
1404
+ * @param schema - The schema for which the display label flag is desired
1405
+ * @param [uiSchema] - The UI schema from which to derive potentially displayable information
1406
+ * @returns - True if the label should be displayed or false if it should not
1407
+ */
1408
+
1409
+
1410
+ getDisplayLabel(schema, uiSchema) {
1411
+ return getDisplayLabel(this.validator, schema, uiSchema, this.rootSchema);
1412
+ }
1413
+ /** Given the `formData` and list of `options`, attempts to find the index of the option that best matches the data.
1414
+ *
1415
+ * @param formData - The current formData, if any, onto which to provide any missing defaults
1416
+ * @param options - The list of options to find a matching options from
1417
+ * @returns - The index of the matched option or 0 if none is available
1418
+ */
1419
+
1420
+
1421
+ getMatchingOption(formData, options) {
1422
+ return getMatchingOption(this.validator, formData, options, this.rootSchema);
1423
+ }
1424
+ /** Checks to see if the `schema` and `uiSchema` combination represents an array of files
1425
+ *
1426
+ * @param schema - The schema for which check for array of files flag is desired
1427
+ * @param [uiSchema] - The UI schema from which to check the widget
1428
+ * @returns - True if schema/uiSchema contains an array of files, otherwise false
1429
+ */
1430
+
1431
+
1432
+ isFilesArray(schema, uiSchema) {
1433
+ return isFilesArray(this.validator, schema, uiSchema, this.rootSchema);
1434
+ }
1435
+ /** Checks to see if the `schema` combination represents a multi-select
1436
+ *
1437
+ * @param schema - The schema for which check for a multi-select flag is desired
1438
+ * @returns - True if schema contains a multi-select, otherwise false
1439
+ */
1440
+
1441
+
1442
+ isMultiSelect(schema) {
1443
+ return isMultiSelect(this.validator, schema, this.rootSchema);
1444
+ }
1445
+ /** Checks to see if the `schema` combination represents a select
1446
+ *
1447
+ * @param schema - The schema for which check for a select flag is desired
1448
+ * @returns - True if schema contains a select, otherwise false
1449
+ */
1450
+
1451
+
1452
+ isSelect(schema) {
1453
+ return isSelect(this.validator, schema, this.rootSchema);
1454
+ }
1455
+ /** Merges the errors in `additionalErrorSchema` into the existing `validationData` by combining the hierarchies in
1456
+ * the two `ErrorSchema`s and then appending the error list from the `additionalErrorSchema` obtained by calling
1457
+ * `getValidator().toErrorList()` onto the `errors` in the `validationData`. If no `additionalErrorSchema` is passed,
1458
+ * then `validationData` is returned.
1459
+ *
1460
+ * @param validationData - The current `ValidationData` into which to merge the additional errors
1461
+ * @param [additionalErrorSchema] - The additional set of errors
1462
+ * @returns - The `validationData` with the additional errors from `additionalErrorSchema` merged into it, if provided.
1463
+ */
1464
+
1465
+
1466
+ mergeValidationData(validationData, additionalErrorSchema) {
1467
+ return mergeValidationData(this.validator, validationData, additionalErrorSchema);
1468
+ }
1469
+ /** Retrieves an expanded schema that has had all of its conditions, additional properties, references and
1470
+ * dependencies resolved and merged into the `schema` given a `rawFormData` that is used to do the potentially
1471
+ * recursive resolution.
1472
+ *
1473
+ * @param schema - The schema for which retrieving a schema is desired
1474
+ * @param [rawFormData] - The current formData, if any, to assist retrieving a schema
1475
+ * @returns - The schema having its conditions, additional properties, references and dependencies resolved
1476
+ */
1477
+
1478
+
1479
+ retrieveSchema(schema, rawFormData) {
1480
+ return retrieveSchema(this.validator, schema, this.rootSchema, rawFormData);
1481
+ }
1482
+ /** Generates an `IdSchema` object for the `schema`, recursively
1483
+ *
1484
+ * @param schema - The schema for which the display label flag is desired
1485
+ * @param [id] - The base id for the schema
1486
+ * @param [formData] - The current formData, if any, onto which to provide any missing defaults
1487
+ * @param [idPrefix='root'] - The prefix to use for the id
1488
+ * @param [idSeparator='_'] - The separator to use for the path segments in the id
1489
+ * @returns - The `IdSchema` object for the `schema`
1490
+ */
1491
+
1492
+
1493
+ toIdSchema(schema, id, formData, idPrefix, idSeparator) {
1494
+ if (idPrefix === void 0) {
1495
+ idPrefix = "root";
1496
+ }
1497
+
1498
+ if (idSeparator === void 0) {
1499
+ idSeparator = "_";
1500
+ }
1501
+
1502
+ return toIdSchema(this.validator, schema, id, this.rootSchema, formData, idPrefix, idSeparator);
1503
+ }
1504
+ /** Generates an `PathSchema` object for the `schema`, recursively
1505
+ *
1506
+ * @param schema - The schema for which the display label flag is desired
1507
+ * @param [name] - The base name for the schema
1508
+ * @param [formData] - The current formData, if any, onto which to provide any missing defaults
1509
+ * @returns - The `PathSchema` object for the `schema`
1510
+ */
1511
+
1512
+
1513
+ toPathSchema(schema, name, formData) {
1514
+ return toPathSchema(this.validator, schema, name, this.rootSchema, formData);
1515
+ }
1516
+
1517
+ }
1518
+ /** Creates a `SchemaUtilsType` interface that is based around the given `validator` and `rootSchema` parameters. The
1519
+ * resulting interface implementation will forward the `validator` and `rootSchema` to all the wrapped APIs.
1520
+ *
1521
+ * @param validator - an implementation of the `ValidatorType` interface that will be forwarded to all the APIs
1522
+ * @param rootSchema - The root schema that will be forwarded to all the APIs
1523
+ * @returns - An implementation of a `SchemaUtilsType` interface
1524
+ */
1525
+
1526
+
1527
+ function createSchemaUtils(validator, rootSchema) {
1528
+ return new SchemaUtils(validator, rootSchema);
1529
+ }
1530
+
1531
+ /** Given the `FileReader.readAsDataURL()` based `dataURI` extracts that data into an actual Blob along with the name
1532
+ * of that Blob if provided in the URL. If no name is provided, then the name falls back to `unknown`.
1533
+ *
1534
+ * @param dataURI - The `DataUrl` potentially containing name and raw data to be converted to a Blob
1535
+ * @returns - an object containing a Blob and its name, extracted from the URI
1536
+ */
1537
+ function dataURItoBlob(dataURI) {
1538
+ // Split metadata from data
1539
+ const splitted = dataURI.split(","); // Split params
1540
+
1541
+ const params = splitted[0].split(";"); // Get mime-type from params
1542
+
1543
+ const type = params[0].replace("data:", ""); // Filter the name property from params
1544
+
1545
+ const properties = params.filter(param => {
1546
+ return param.split("=")[0] === "name";
1547
+ }); // Look for the name and use unknown if no name property.
1548
+
1549
+ let name;
1550
+
1551
+ if (properties.length !== 1) {
1552
+ name = "unknown";
1553
+ } else {
1554
+ // Because we filtered out the other property,
1555
+ // we only have the name case here.
1556
+ name = properties[0].split("=")[1];
1557
+ } // Built the Uint8Array Blob parameter from the base64 string.
1558
+
1559
+
1560
+ const binary = atob(splitted[1]);
1561
+ const array = [];
1562
+
1563
+ for (let i = 0; i < binary.length; i++) {
1564
+ array.push(binary.charCodeAt(i));
1565
+ } // Create the blob object
1566
+
1567
+
1568
+ const blob = new window.Blob([new Uint8Array(array)], {
1569
+ type
1570
+ });
1571
+ return {
1572
+ blob,
1573
+ name
1574
+ };
1575
+ }
1576
+
1577
+ /** Extracts the range spec information `{ step?: number, min?: number, max?: number }` that can be spread onto an HTML
1578
+ * input from the range analog in the schema `{ multipleOf?: number, minimum?: number, maximum?: number }`.
1579
+ *
1580
+ * @param schema - The schema from which to extract the range spec
1581
+ * @returns - A range specification from the schema
1582
+ */
1583
+ function rangeSpec(schema) {
1584
+ const spec = {};
1585
+
1586
+ if (schema.multipleOf) {
1587
+ spec.step = schema.multipleOf;
1588
+ }
1589
+
1590
+ if (schema.minimum || schema.minimum === 0) {
1591
+ spec.min = schema.minimum;
1592
+ }
1593
+
1594
+ if (schema.maximum || schema.maximum === 0) {
1595
+ spec.max = schema.maximum;
1596
+ }
1597
+
1598
+ return spec;
1599
+ }
1600
+
1601
+ /** Using the `schema`, `defaultType` and `options`, extract out the props for the <input> element that make sense.
1602
+ *
1603
+ * @param schema - The schema for the field provided by the widget
1604
+ * @param [defaultType] - The default type, if any, for the field provided by the widget
1605
+ * @param [options={}] - The UI Options for the field provided by the widget
1606
+ * @param [autoDefaultStepAny=true] - Determines whether to auto-default step=any when the type is number and no step
1607
+ * @returns - The extracted `InputPropsType` object
1608
+ */
1609
+
1610
+ function getInputProps(schema, defaultType, options, autoDefaultStepAny) {
1611
+ if (options === void 0) {
1612
+ options = {};
1613
+ }
1614
+
1615
+ if (autoDefaultStepAny === void 0) {
1616
+ autoDefaultStepAny = true;
1617
+ }
1618
+
1619
+ const inputProps = {
1620
+ type: defaultType || "text",
1621
+ ...rangeSpec(schema)
1622
+ }; // If options.inputType is set use that as the input type
1623
+
1624
+ if (options.inputType) {
1625
+ inputProps.type = options.inputType;
1626
+ } else if (!defaultType) {
1627
+ // If the schema is of type number or integer, set the input type to number
1628
+ if (schema.type === "number") {
1629
+ inputProps.type = "number"; // Only add step if one isn't already defined and we are auto-defaulting the "any" step
1630
+
1631
+ if (autoDefaultStepAny && inputProps.step === undefined) {
1632
+ // Setting step to 'any' fixes a bug in Safari where decimals are not
1633
+ // allowed in number inputs
1634
+ inputProps.step = "any";
1635
+ }
1636
+ } else if (schema.type === "integer") {
1637
+ inputProps.type = "number"; // Only add step if one isn't already defined
1638
+
1639
+ if (inputProps.step === undefined) {
1640
+ // Since this is integer, you always want to step up or down in multiples of 1
1641
+ inputProps.step = 1;
1642
+ }
1643
+ }
1644
+ }
1645
+
1646
+ if (options.autocomplete) {
1647
+ inputProps.autoComplete = options.autocomplete;
1648
+ }
1649
+
1650
+ return inputProps;
1651
+ }
1652
+
1653
+ /** The default submit button options, exported for testing purposes
1654
+ */
1655
+
1656
+ const DEFAULT_OPTIONS = {
1657
+ props: {
1658
+ disabled: false
1659
+ },
1660
+ submitText: "Submit",
1661
+ norender: false
1662
+ };
1663
+ /** Extracts any `ui:submitButtonOptions` from the `uiSchema` and merges them onto the `DEFAULT_OPTIONS`
1664
+ *
1665
+ * @param [uiSchema={}] - the UI Schema from which to extract submit button props
1666
+ * @returns - The merging of the `DEFAULT_OPTIONS` with any custom ones
1667
+ */
1668
+
1669
+ function getSubmitButtonOptions(uiSchema) {
1670
+ if (uiSchema === void 0) {
1671
+ uiSchema = {};
1672
+ }
1673
+
1674
+ const uiOptions = getUiOptions(uiSchema);
1675
+
1676
+ if (uiOptions && uiOptions[SUBMIT_BTN_OPTIONS_KEY]) {
1677
+ const options = uiOptions[SUBMIT_BTN_OPTIONS_KEY];
1678
+ return { ...DEFAULT_OPTIONS,
1679
+ ...options
1680
+ };
1681
+ }
1682
+
1683
+ return DEFAULT_OPTIONS;
1684
+ }
1685
+
1686
+ /** Returns the template with the given `name` from either the `uiSchema` if it is defined or from the `registry`
1687
+ * otherwise. NOTE, since `ButtonTemplates` are not overridden in `uiSchema` only those in the `registry` are returned.
1688
+ *
1689
+ * @param name - The name of the template to fetch, restricted to the keys of `TemplatesType`
1690
+ * @param registry - The `Registry` from which to read the template
1691
+ * @param [uiOptions={}] - The `UIOptionsType` from which to read an alternate template
1692
+ * @returns - The template from either the `uiSchema` or `registry` for the `name`
1693
+ */
1694
+ function getTemplate(name, registry, uiOptions) {
1695
+ if (uiOptions === void 0) {
1696
+ uiOptions = {};
1697
+ }
1698
+
1699
+ const {
1700
+ templates
1701
+ } = registry;
1702
+
1703
+ if (name === "ButtonTemplates") {
1704
+ return templates[name];
1705
+ }
1706
+
1707
+ return uiOptions[name] || templates[name];
1708
+ }
1709
+
1710
+ /** The map of schema types to widget type to widget name
1711
+ */
1712
+
1713
+ const widgetMap = {
1714
+ boolean: {
1715
+ checkbox: "CheckboxWidget",
1716
+ radio: "RadioWidget",
1717
+ select: "SelectWidget",
1718
+ hidden: "HiddenWidget"
1719
+ },
1720
+ string: {
1721
+ text: "TextWidget",
1722
+ password: "PasswordWidget",
1723
+ email: "EmailWidget",
1724
+ hostname: "TextWidget",
1725
+ ipv4: "TextWidget",
1726
+ ipv6: "TextWidget",
1727
+ uri: "URLWidget",
1728
+ "data-url": "FileWidget",
1729
+ radio: "RadioWidget",
1730
+ select: "SelectWidget",
1731
+ textarea: "TextareaWidget",
1732
+ hidden: "HiddenWidget",
1733
+ date: "DateWidget",
1734
+ datetime: "DateTimeWidget",
1735
+ "date-time": "DateTimeWidget",
1736
+ "alt-date": "AltDateWidget",
1737
+ "alt-datetime": "AltDateTimeWidget",
1738
+ color: "ColorWidget",
1739
+ file: "FileWidget"
1740
+ },
1741
+ number: {
1742
+ text: "TextWidget",
1743
+ select: "SelectWidget",
1744
+ updown: "UpDownWidget",
1745
+ range: "RangeWidget",
1746
+ radio: "RadioWidget",
1747
+ hidden: "HiddenWidget"
1748
+ },
1749
+ integer: {
1750
+ text: "TextWidget",
1751
+ select: "SelectWidget",
1752
+ updown: "UpDownWidget",
1753
+ range: "RangeWidget",
1754
+ radio: "RadioWidget",
1755
+ hidden: "HiddenWidget"
1756
+ },
1757
+ array: {
1758
+ select: "SelectWidget",
1759
+ checkboxes: "CheckboxesWidget",
1760
+ files: "FileWidget",
1761
+ hidden: "HiddenWidget"
1762
+ }
1763
+ };
1764
+ /** Wraps the given widget with stateless functional component that will merge any `defaultProps.options` with the
1765
+ * `options` that are provided in the props. It will add the wrapper component as a `MergedWidget` property onto the
1766
+ * `Widget` so that future attempts to wrap `AWidget` will return the already existing wrapper.
1767
+ *
1768
+ * @param AWidget - A widget that will be wrapped or one that is already wrapped
1769
+ * @returns - The wrapper widget
1770
+ */
1771
+
1772
+ function mergeWidgetOptions(AWidget) {
1773
+ let MergedWidget = get__default["default"](AWidget, "MergedWidget"); // cache return value as property of widget for proper react reconciliation
1774
+
1775
+ if (!MergedWidget) {
1776
+ const defaultOptions = AWidget.defaultProps && AWidget.defaultProps.options || {};
1777
+
1778
+ MergedWidget = _ref => {
1779
+ let {
1780
+ options,
1781
+ ...props
1782
+ } = _ref;
1783
+ return /*#__PURE__*/React__default["default"].createElement(AWidget, {
1784
+ options: { ...defaultOptions,
1785
+ ...options
1786
+ },
1787
+ ...props
1788
+ });
1789
+ };
1790
+
1791
+ set__default["default"](AWidget, "MergedWidget", MergedWidget);
1792
+ }
1793
+
1794
+ return MergedWidget;
1795
+ }
1796
+ /** Given a schema representing a field to render and either the name or actual `Widget` implementation, returns the
1797
+ * React component that is used to render the widget. If the `widget` is already a React component, then it is wrapped
1798
+ * with a `MergedWidget`. Otherwise an attempt is made to look up the widget inside of the `registeredWidgets` map based
1799
+ * on the schema type and `widget` name. If no widget component can be found an `Error` is thrown.
1800
+ *
1801
+ * @param schema - The schema for the field
1802
+ * @param [widget] - Either the name of the widget OR a `Widget` implementation to use
1803
+ * @param [registeredWidgets={}] - A registry of widget name to `Widget` implementation
1804
+ * @returns - The `Widget` component to use
1805
+ * @throws - An error if there is no `Widget` component that can be returned
1806
+ */
1807
+
1808
+
1809
+ function getWidget(schema, widget, registeredWidgets) {
1810
+ if (registeredWidgets === void 0) {
1811
+ registeredWidgets = {};
1812
+ }
1813
+
1814
+ const type = getSchemaType(schema);
1815
+
1816
+ if (typeof widget === "function" || widget && ReactIs__default["default"].isForwardRef( /*#__PURE__*/React__default["default"].createElement(widget)) || ReactIs__default["default"].isMemo(widget)) {
1817
+ return mergeWidgetOptions(widget);
1818
+ }
1819
+
1820
+ if (typeof widget !== "string") {
1821
+ throw new Error("Unsupported widget definition: " + typeof widget);
1822
+ }
1823
+
1824
+ if (widget in registeredWidgets) {
1825
+ const registeredWidget = registeredWidgets[widget];
1826
+ return getWidget(schema, registeredWidget, registeredWidgets);
1827
+ }
1828
+
1829
+ if (typeof type === "string") {
1830
+ if (!(type in widgetMap)) {
1831
+ throw new Error("No widget for type '" + type + "'");
1832
+ }
1833
+
1834
+ if (widget in widgetMap[type]) {
1835
+ const registeredWidget = registeredWidgets[widgetMap[type][widget]];
1836
+ return getWidget(schema, registeredWidget, registeredWidgets);
1837
+ }
1838
+ }
1839
+
1840
+ throw new Error("No widget '" + widget + "' for type '" + type + "'");
1841
+ }
1842
+
1843
+ /** Detects whether the `widget` exists for the `schema` with the associated `registryWidgets` and returns true if it
1844
+ * does, or false if it doesn't.
1845
+ *
1846
+ * @param schema - The schema for the field
1847
+ * @param widget - Either the name of the widget OR a `Widget` implementation to use
1848
+ * @param [registeredWidgets={}] - A registry of widget name to `Widget` implementation
1849
+ * @returns - True if the widget exists, false otherwise
1850
+ */
1851
+
1852
+ function hasWidget(schema, widget, registeredWidgets) {
1853
+ if (registeredWidgets === void 0) {
1854
+ registeredWidgets = {};
1855
+ }
1856
+
1857
+ try {
1858
+ getWidget(schema, widget, registeredWidgets);
1859
+ return true;
1860
+ } catch (e) {
1861
+ const err = e;
1862
+
1863
+ if (err.message && (err.message.startsWith("No widget") || err.message.startsWith("Unsupported widget"))) {
1864
+ return false;
1865
+ }
1866
+
1867
+ throw e;
1868
+ }
1869
+ }
1870
+
1871
+ /** Converts a local Date string into a UTC date string
1872
+ *
1873
+ * @param dateString - The string representation of a date as accepted by the `Date()` constructor
1874
+ * @returns - A UTC date string if `dateString` is truthy, otherwise undefined
1875
+ */
1876
+ function localToUTC(dateString) {
1877
+ return dateString ? new Date(dateString).toJSON() : undefined;
1878
+ }
1879
+
1880
+ /** Returns the constant value from the schema when it is either a single value enum or has a const key. Otherwise
1881
+ * throws an error.
1882
+ *
1883
+ * @param schema - The schema from which to obtain the constant value
1884
+ * @returns - The constant value for the schema
1885
+ * @throws - Error when the schema does not have a constant value
1886
+ */
1887
+
1888
+ function toConstant(schema) {
1889
+ if (ENUM_KEY in schema && Array.isArray(schema.enum) && schema.enum.length === 1) {
1890
+ return schema.enum[0];
1891
+ }
1892
+
1893
+ if (CONST_KEY in schema) {
1894
+ return schema.const;
1895
+ }
1896
+
1897
+ throw new Error("schema cannot be inferred as a constant");
1898
+ }
1899
+
1900
+ /** Gets the list of options from the schema. If the schema has an enum list, then those enum values are returned. The
1901
+ * labels for the options will be extracted from the non-standard, RJSF-deprecated `enumNames` if it exists, otherwise
1902
+ * the label will be the same as the `value`. If the schema has a `oneOf` or `anyOf`, then the value is the list of
1903
+ * `const` values from the schema and the label is either the `schema.title` or the value.
1904
+ *
1905
+ * @param schema - The schema from which to extract the options list
1906
+ * @returns - The list of options from the schema
1907
+ */
1908
+
1909
+ function optionsList(schema) {
1910
+ // enumNames was deprecated in v5 and is intentionally omitted from the RJSFSchema type.
1911
+ // Cast the type to include enumNames so the feature still works.
1912
+ const schemaWithEnumNames = schema;
1913
+
1914
+ if (schemaWithEnumNames.enumNames && "development" !== "production") {
1915
+ console.warn("The enumNames property is deprecated and may be removed in a future major release.");
1916
+ }
1917
+
1918
+ if (schema.enum) {
1919
+ return schema.enum.map((value, i) => {
1920
+ const label = schemaWithEnumNames.enumNames && schemaWithEnumNames.enumNames[i] || String(value);
1921
+ return {
1922
+ label,
1923
+ value
1924
+ };
1925
+ });
1926
+ }
1927
+
1928
+ const altSchemas = schema.oneOf || schema.anyOf;
1929
+ return altSchemas && altSchemas.map(aSchemaDef => {
1930
+ const aSchema = aSchemaDef;
1931
+ const value = toConstant(aSchema);
1932
+ const label = aSchema.title || String(value);
1933
+ return {
1934
+ schema: aSchema,
1935
+ label,
1936
+ value
1937
+ };
1938
+ });
1939
+ }
1940
+
1941
+ /** Given a list of `properties` and an `order` list, returns a list that contains the `properties` ordered correctly.
1942
+ * If `order` is not an array, then the untouched `properties` list is returned. Otherwise `properties` is ordered per
1943
+ * the `order` list. If `order` contains a '*' then any `properties` that are not mentioned explicity in `order` will be
1944
+ * places in the location of the `*`.
1945
+ *
1946
+ * @param properties - The list of property keys to be ordered
1947
+ * @param order - An array of property keys to be ordered first, with an optional '*' property
1948
+ * @returns - A list with the `properties` ordered
1949
+ * @throws - Error when the properties cannot be ordered correctly
1950
+ */
1951
+ function orderProperties(properties, order) {
1952
+ if (!Array.isArray(order)) {
1953
+ return properties;
1954
+ }
1955
+
1956
+ const arrayToHash = arr => arr.reduce((prev, curr) => {
1957
+ prev[curr] = true;
1958
+ return prev;
1959
+ }, {});
1960
+
1961
+ const errorPropList = arr => arr.length > 1 ? "properties '" + arr.join("', '") + "'" : "property '" + arr[0] + "'";
1962
+
1963
+ const propertyHash = arrayToHash(properties);
1964
+ const orderFiltered = order.filter(prop => prop === "*" || propertyHash[prop]);
1965
+ const orderHash = arrayToHash(orderFiltered);
1966
+ const rest = properties.filter(prop => !orderHash[prop]);
1967
+ const restIndex = orderFiltered.indexOf("*");
1968
+
1969
+ if (restIndex === -1) {
1970
+ if (rest.length) {
1971
+ throw new Error("uiSchema order list does not contain " + errorPropList(rest));
1972
+ }
1973
+
1974
+ return orderFiltered;
1975
+ }
1976
+
1977
+ if (restIndex !== orderFiltered.lastIndexOf("*")) {
1978
+ throw new Error("uiSchema order list contains more than one wildcard item");
1979
+ }
1980
+
1981
+ const complete = [...orderFiltered];
1982
+ complete.splice(restIndex, 1, ...rest);
1983
+ return complete;
1984
+ }
1985
+
1986
+ /** Returns a string representation of the `num` that is padded with leading "0"s if necessary
1987
+ *
1988
+ * @param num - The number to pad
1989
+ * @param width - The width of the string at which no lead padding is necessary
1990
+ * @returns - The number converted to a string with leading zero padding if the number of digits is less than `width`
1991
+ */
1992
+ function pad(num, width) {
1993
+ let s = String(num);
1994
+
1995
+ while (s.length < width) {
1996
+ s = "0" + s;
1997
+ }
1998
+
1999
+ return s;
2000
+ }
2001
+
2002
+ /** Parses the `dateString` into a `DateObject`, including the time information when `includeTime` is true
2003
+ *
2004
+ * @param dateString - The date string to parse into a DateObject
2005
+ * @param [includeTime=true] - Optional flag, if false, will not include the time data into the object
2006
+ * @returns - The date string converted to a `DateObject`
2007
+ * @throws - Error when the date cannot be parsed from the string
2008
+ */
2009
+ function parseDateString(dateString, includeTime) {
2010
+ if (includeTime === void 0) {
2011
+ includeTime = true;
2012
+ }
2013
+
2014
+ if (!dateString) {
2015
+ return {
2016
+ year: -1,
2017
+ month: -1,
2018
+ day: -1,
2019
+ hour: includeTime ? -1 : 0,
2020
+ minute: includeTime ? -1 : 0,
2021
+ second: includeTime ? -1 : 0
2022
+ };
2023
+ }
2024
+
2025
+ const date = new Date(dateString);
2026
+
2027
+ if (Number.isNaN(date.getTime())) {
2028
+ throw new Error("Unable to parse date " + dateString);
2029
+ }
2030
+
2031
+ return {
2032
+ year: date.getUTCFullYear(),
2033
+ month: date.getUTCMonth() + 1,
2034
+ day: date.getUTCDate(),
2035
+ hour: includeTime ? date.getUTCHours() : 0,
2036
+ minute: includeTime ? date.getUTCMinutes() : 0,
2037
+ second: includeTime ? date.getUTCSeconds() : 0
2038
+ };
2039
+ }
2040
+
2041
+ const nums = /*#__PURE__*/new Set(["number", "integer"]);
2042
+ /** Returns the real value for a select widget due to a silly limitation in the DOM which causes option change event
2043
+ * values to always be retrieved as strings. Uses the `schema` to help determine the value's true type. If the value is
2044
+ * an empty string, then the `emptyValue` from the `options` is returned, falling back to undefined.
2045
+ *
2046
+ * @param schema - The schema to used to determine the value's true type
2047
+ * @param [value] - The value to convert
2048
+ * @param [options] - The UIOptionsType from which to potentially extract the emptyValue
2049
+ * @returns - The `value` converted to the proper type
2050
+ */
2051
+
2052
+ function processSelectValue(schema, value, options) {
2053
+ const {
2054
+ enum: schemaEnum,
2055
+ type,
2056
+ items
2057
+ } = schema;
2058
+
2059
+ if (value === "") {
2060
+ return options && options.emptyValue !== undefined ? options.emptyValue : undefined;
2061
+ }
2062
+
2063
+ if (type === "array" && items && nums.has(get__default["default"](items, "type"))) {
2064
+ return value.map(asNumber);
2065
+ }
2066
+
2067
+ if (type === "boolean") {
2068
+ return value === "true";
2069
+ }
2070
+
2071
+ if (nums.has(type)) {
2072
+ return asNumber(value);
2073
+ } // If type is undefined, but an enum is present, try and infer the type from
2074
+ // the enum values
2075
+
2076
+
2077
+ if (Array.isArray(schemaEnum)) {
2078
+ if (schemaEnum.every(x => nums.has(guessType(x)))) {
2079
+ return asNumber(value);
2080
+ }
2081
+
2082
+ if (schemaEnum.every(x => guessType(x) === "boolean")) {
2083
+ return value === "true";
2084
+ }
2085
+ }
2086
+
2087
+ return value;
2088
+ }
2089
+
2090
+ /** Check to see if a `schema` specifies that a value must be true. This happens when:
2091
+ * - `schema.const` is truthy
2092
+ * - `schema.enum` == `[true]`
2093
+ * - `schema.anyOf` or `schema.oneOf` has a single value which recursively returns true
2094
+ * - `schema.allOf` has at least one value which recursively returns true
2095
+ *
2096
+ * @param schema - The schema to check
2097
+ * @returns - True if the schema specifies a value that must be true, false otherwise
2098
+ */
2099
+ function schemaRequiresTrueValue(schema) {
2100
+ // Check if const is a truthy value
2101
+ if (schema.const) {
2102
+ return true;
2103
+ } // Check if an enum has a single value of true
2104
+
2105
+
2106
+ if (schema.enum && schema.enum.length === 1 && schema.enum[0] === true) {
2107
+ return true;
2108
+ } // If anyOf has a single value, evaluate the subschema
2109
+
2110
+
2111
+ if (schema.anyOf && schema.anyOf.length === 1) {
2112
+ return schemaRequiresTrueValue(schema.anyOf[0]);
2113
+ } // If oneOf has a single value, evaluate the subschema
2114
+
2115
+
2116
+ if (schema.oneOf && schema.oneOf.length === 1) {
2117
+ return schemaRequiresTrueValue(schema.oneOf[0]);
2118
+ } // Evaluate each subschema in allOf, to see if one of them requires a true value
2119
+
2120
+
2121
+ if (schema.allOf) {
2122
+ const schemaSome = subSchema => schemaRequiresTrueValue(subSchema);
2123
+
2124
+ return schema.allOf.some(schemaSome);
2125
+ }
2126
+
2127
+ return false;
2128
+ }
2129
+
2130
+ /** Determines whether the given `component` should be rerendered by comparing its current set of props and state
2131
+ * against the next set. If either of those two sets are not the same, then the component should be rerendered.
2132
+ *
2133
+ * @param component - A React component being checked
2134
+ * @param nextProps - The next set of props against which to check
2135
+ * @param nextState - The next set of state against which to check
2136
+ * @returns - True if the component should be re-rendered, false otherwise
2137
+ */
2138
+
2139
+ function shouldRender(component, nextProps, nextState) {
2140
+ const {
2141
+ props,
2142
+ state
2143
+ } = component;
2144
+ return !deepEquals(props, nextProps) || !deepEquals(state, nextState);
2145
+ }
2146
+
2147
+ /** Returns a UTC date string for the given `dateObject`. If `time` is false, then the time portion of the string is
2148
+ * removed.
2149
+ *
2150
+ * @param dateObject - The `DateObject` to convert to a date string
2151
+ * @param [time=true] - Optional flag used to remove the time portion of the date string if false
2152
+ * @returns - The UTC date string
2153
+ */
2154
+ function toDateString(dateObject, time) {
2155
+ if (time === void 0) {
2156
+ time = true;
2157
+ }
2158
+
2159
+ const {
2160
+ year,
2161
+ month,
2162
+ day,
2163
+ hour = 0,
2164
+ minute = 0,
2165
+ second = 0
2166
+ } = dateObject;
2167
+ const utcTime = Date.UTC(year, month - 1, day, hour, minute, second);
2168
+ const datetime = new Date(utcTime).toJSON();
2169
+ return time ? datetime : datetime.slice(0, 10);
2170
+ }
2171
+
2172
+ /** Converts a UTC date string into a local Date format
2173
+ *
2174
+ * @param jsonDate - A UTC date string
2175
+ * @returns - An empty string when `jsonDate` is falsey, otherwise a date string in local format
2176
+ */
2177
+
2178
+ function utcToLocal(jsonDate) {
2179
+ if (!jsonDate) {
2180
+ return "";
2181
+ } // required format of `'yyyy-MM-ddThh:mm' followed by optional ':ss' or ':ss.SSS'
2182
+ // https://html.spec.whatwg.org/multipage/input.html#local-date-and-time-state-(type%3Ddatetime-local)
2183
+ // > should be a _valid local date and time string_ (not GMT)
2184
+ // Note - date constructor passed local ISO-8601 does not correctly
2185
+ // change time to UTC in node pre-8
2186
+
2187
+
2188
+ const date = new Date(jsonDate);
2189
+ const yyyy = pad(date.getFullYear(), 4);
2190
+ const MM = pad(date.getMonth() + 1, 2);
2191
+ const dd = pad(date.getDate(), 2);
2192
+ const hh = pad(date.getHours(), 2);
2193
+ const mm = pad(date.getMinutes(), 2);
2194
+ const ss = pad(date.getSeconds(), 2);
2195
+ const SSS = pad(date.getMilliseconds(), 3);
2196
+ return yyyy + "-" + MM + "-" + dd + "T" + hh + ":" + mm + ":" + ss + "." + SSS;
2197
+ }
2198
+
2199
+ exports.ADDITIONAL_PROPERTIES_KEY = ADDITIONAL_PROPERTIES_KEY;
2200
+ exports.ADDITIONAL_PROPERTY_FLAG = ADDITIONAL_PROPERTY_FLAG;
2201
+ exports.ALL_OF_KEY = ALL_OF_KEY;
2202
+ exports.ANY_OF_KEY = ANY_OF_KEY;
2203
+ exports.CONST_KEY = CONST_KEY;
2204
+ exports.DEFAULT_KEY = DEFAULT_KEY;
2205
+ exports.DEFINITIONS_KEY = DEFINITIONS_KEY;
2206
+ exports.DEPENDENCIES_KEY = DEPENDENCIES_KEY;
2207
+ exports.ENUM_KEY = ENUM_KEY;
2208
+ exports.ERRORS_KEY = ERRORS_KEY;
2209
+ exports.ID_KEY = ID_KEY;
2210
+ exports.ITEMS_KEY = ITEMS_KEY;
2211
+ exports.NAME_KEY = NAME_KEY;
2212
+ exports.ONE_OF_KEY = ONE_OF_KEY;
2213
+ exports.PROPERTIES_KEY = PROPERTIES_KEY;
2214
+ exports.REF_KEY = REF_KEY;
2215
+ exports.REQUIRED_KEY = REQUIRED_KEY;
2216
+ exports.RJSF_ADDITONAL_PROPERTIES_FLAG = RJSF_ADDITONAL_PROPERTIES_FLAG;
2217
+ exports.SUBMIT_BTN_OPTIONS_KEY = SUBMIT_BTN_OPTIONS_KEY;
2218
+ exports.UI_FIELD_KEY = UI_FIELD_KEY;
2219
+ exports.UI_OPTIONS_KEY = UI_OPTIONS_KEY;
2220
+ exports.UI_WIDGET_KEY = UI_WIDGET_KEY;
2221
+ exports.allowAdditionalItems = allowAdditionalItems;
2222
+ exports.asNumber = asNumber;
2223
+ exports.canExpand = canExpand;
2224
+ exports.createSchemaUtils = createSchemaUtils;
2225
+ exports.dataURItoBlob = dataURItoBlob;
2226
+ exports.deepEquals = deepEquals;
2227
+ exports.findSchemaDefinition = findSchemaDefinition;
2228
+ exports.getDefaultFormState = getDefaultFormState;
2229
+ exports.getDisplayLabel = getDisplayLabel;
2230
+ exports.getInputProps = getInputProps;
2231
+ exports.getMatchingOption = getMatchingOption;
2232
+ exports.getSchemaType = getSchemaType;
2233
+ exports.getSubmitButtonOptions = getSubmitButtonOptions;
2234
+ exports.getTemplate = getTemplate;
2235
+ exports.getUiOptions = getUiOptions;
2236
+ exports.getWidget = getWidget;
2237
+ exports.guessType = guessType;
2238
+ exports.hasWidget = hasWidget;
2239
+ exports.isConstant = isConstant;
2240
+ exports.isCustomWidget = isCustomWidget;
2241
+ exports.isFilesArray = isFilesArray;
2242
+ exports.isFixedItems = isFixedItems;
2243
+ exports.isMultiSelect = isMultiSelect;
2244
+ exports.isObject = isObject;
2245
+ exports.isSelect = isSelect;
2246
+ exports.localToUTC = localToUTC;
2247
+ exports.mergeDefaultsWithFormData = mergeDefaultsWithFormData;
2248
+ exports.mergeObjects = mergeObjects;
2249
+ exports.mergeSchemas = mergeSchemas;
2250
+ exports.mergeValidationData = mergeValidationData;
2251
+ exports.optionsList = optionsList;
2252
+ exports.orderProperties = orderProperties;
2253
+ exports.pad = pad;
2254
+ exports.parseDateString = parseDateString;
2255
+ exports.processSelectValue = processSelectValue;
2256
+ exports.rangeSpec = rangeSpec;
2257
+ exports.retrieveSchema = retrieveSchema;
2258
+ exports.schemaRequiresTrueValue = schemaRequiresTrueValue;
2259
+ exports.shouldRender = shouldRender;
2260
+ exports.toConstant = toConstant;
2261
+ exports.toDateString = toDateString;
2262
+ exports.toIdSchema = toIdSchema;
2263
+ exports.toPathSchema = toPathSchema;
2264
+ exports.utcToLocal = utcToLocal;
2265
+
2266
+ Object.defineProperty(exports, '__esModule', { value: true });
2267
+
2268
+ }));
2269
+ //# sourceMappingURL=utils.umd.development.js.map