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