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