@rjsf/utils 5.13.0 → 5.13.2
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.js +238 -122
- package/dist/index.js.map +4 -4
- package/dist/utils.esm.js +238 -122
- package/dist/utils.esm.js.map +4 -4
- package/dist/utils.umd.js +218 -108
- package/lib/getOptionMatchingSimpleDiscriminator.d.ts +12 -0
- package/lib/getOptionMatchingSimpleDiscriminator.js +36 -0
- package/lib/getOptionMatchingSimpleDiscriminator.js.map +1 -0
- package/lib/getSchemaType.js +7 -2
- package/lib/getSchemaType.js.map +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/lib/schema/getClosestMatchingOption.js +7 -1
- package/lib/schema/getClosestMatchingOption.js.map +1 -1
- package/lib/schema/getDefaultFormState.js +9 -12
- package/lib/schema/getDefaultFormState.js.map +1 -1
- package/lib/schema/getMatchingOption.js +6 -0
- package/lib/schema/getMatchingOption.js.map +1 -1
- package/lib/schema/retrieveSchema.d.ts +23 -13
- package/lib/schema/retrieveSchema.js +65 -41
- package/lib/schema/retrieveSchema.js.map +1 -1
- package/lib/types.d.ts +1 -1
- package/package.json +16 -16
- package/src/getOptionMatchingSimpleDiscriminator.ts +46 -0
- package/src/getSchemaType.ts +6 -2
- package/src/index.ts +2 -0
- package/src/schema/getClosestMatchingOption.ts +9 -1
- package/src/schema/getDefaultFormState.ts +9 -12
- package/src/schema/getMatchingOption.ts +8 -0
- package/src/schema/retrieveSchema.ts +146 -38
- package/src/types.ts +1 -1
package/dist/utils.esm.js
CHANGED
|
@@ -138,7 +138,7 @@ function deepEquals(a, b) {
|
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
// src/schema/getDefaultFormState.ts
|
|
141
|
-
import
|
|
141
|
+
import get7 from "lodash/get";
|
|
142
142
|
import isEmpty from "lodash/isEmpty";
|
|
143
143
|
|
|
144
144
|
// src/findSchemaDefinition.ts
|
|
@@ -172,25 +172,58 @@ function findSchemaDefinition($ref, rootSchema = {}) {
|
|
|
172
172
|
}
|
|
173
173
|
|
|
174
174
|
// src/schema/getClosestMatchingOption.ts
|
|
175
|
-
import
|
|
175
|
+
import get5 from "lodash/get";
|
|
176
176
|
import has2 from "lodash/has";
|
|
177
|
+
import isNumber2 from "lodash/isNumber";
|
|
177
178
|
import isObject2 from "lodash/isObject";
|
|
178
179
|
import isString2 from "lodash/isString";
|
|
179
180
|
import reduce from "lodash/reduce";
|
|
180
181
|
import times2 from "lodash/times";
|
|
181
182
|
|
|
182
183
|
// src/schema/getMatchingOption.ts
|
|
183
|
-
import
|
|
184
|
+
import get2 from "lodash/get";
|
|
184
185
|
import has from "lodash/has";
|
|
186
|
+
import isNumber from "lodash/isNumber";
|
|
187
|
+
|
|
188
|
+
// src/getOptionMatchingSimpleDiscriminator.ts
|
|
189
|
+
import get from "lodash/get";
|
|
190
|
+
function getOptionMatchingSimpleDiscriminator(formData, options, discriminatorField) {
|
|
191
|
+
if (formData && discriminatorField) {
|
|
192
|
+
const value = get(formData, discriminatorField);
|
|
193
|
+
if (value === void 0) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
for (let i = 0; i < options.length; i++) {
|
|
197
|
+
const option = options[i];
|
|
198
|
+
const discriminator = get(option, [PROPERTIES_KEY, discriminatorField], {});
|
|
199
|
+
if (discriminator.type === "object" || discriminator.type === "array") {
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
if (discriminator.const === value) {
|
|
203
|
+
return i;
|
|
204
|
+
}
|
|
205
|
+
if (discriminator.enum?.includes(value)) {
|
|
206
|
+
return i;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// src/schema/getMatchingOption.ts
|
|
185
214
|
function getMatchingOption(validator, formData, options, rootSchema, discriminatorField) {
|
|
186
215
|
if (formData === void 0) {
|
|
187
216
|
return 0;
|
|
188
217
|
}
|
|
218
|
+
const simpleDiscriminatorMatch = getOptionMatchingSimpleDiscriminator(formData, options, discriminatorField);
|
|
219
|
+
if (isNumber(simpleDiscriminatorMatch)) {
|
|
220
|
+
return simpleDiscriminatorMatch;
|
|
221
|
+
}
|
|
189
222
|
for (let i = 0; i < options.length; i++) {
|
|
190
223
|
const option = options[i];
|
|
191
224
|
if (discriminatorField && has(option, [PROPERTIES_KEY, discriminatorField])) {
|
|
192
|
-
const value =
|
|
193
|
-
const discriminator =
|
|
225
|
+
const value = get2(formData, discriminatorField);
|
|
226
|
+
const discriminator = get2(option, [PROPERTIES_KEY, discriminatorField], {});
|
|
194
227
|
if (validator.isValid(discriminator, value, rootSchema)) {
|
|
195
228
|
return i;
|
|
196
229
|
}
|
|
@@ -230,18 +263,19 @@ function getFirstMatchingOption(validator, formData, options, rootSchema, discri
|
|
|
230
263
|
}
|
|
231
264
|
|
|
232
265
|
// src/schema/retrieveSchema.ts
|
|
233
|
-
import
|
|
266
|
+
import get4 from "lodash/get";
|
|
267
|
+
import isEqual from "lodash/isEqual";
|
|
234
268
|
import set from "lodash/set";
|
|
235
269
|
import times from "lodash/times";
|
|
236
270
|
import transform from "lodash/transform";
|
|
237
271
|
import mergeAllOf from "json-schema-merge-allof";
|
|
238
272
|
|
|
239
273
|
// src/getDiscriminatorFieldFromSchema.ts
|
|
240
|
-
import
|
|
274
|
+
import get3 from "lodash/get";
|
|
241
275
|
import isString from "lodash/isString";
|
|
242
276
|
function getDiscriminatorFieldFromSchema(schema) {
|
|
243
277
|
let discriminator;
|
|
244
|
-
const maybeString =
|
|
278
|
+
const maybeString = get3(schema, "discriminator.propertyName", void 0);
|
|
245
279
|
if (isString(maybeString)) {
|
|
246
280
|
discriminator = maybeString;
|
|
247
281
|
} else if (maybeString !== void 0) {
|
|
@@ -288,8 +322,12 @@ function getSchemaType(schema) {
|
|
|
288
322
|
if (!type && (schema.properties || schema.additionalProperties)) {
|
|
289
323
|
return "object";
|
|
290
324
|
}
|
|
291
|
-
if (Array.isArray(type)
|
|
292
|
-
|
|
325
|
+
if (Array.isArray(type)) {
|
|
326
|
+
if (type.length === 2 && type.includes("null")) {
|
|
327
|
+
type = type.find((type2) => type2 !== "null");
|
|
328
|
+
} else {
|
|
329
|
+
type = type[0];
|
|
330
|
+
}
|
|
293
331
|
}
|
|
294
332
|
return type;
|
|
295
333
|
}
|
|
@@ -314,7 +352,7 @@ function mergeSchemas(obj1, obj2) {
|
|
|
314
352
|
function retrieveSchema(validator, schema, rootSchema = {}, rawFormData) {
|
|
315
353
|
return retrieveSchemaInternal(validator, schema, rootSchema, rawFormData)[0];
|
|
316
354
|
}
|
|
317
|
-
function resolveCondition(validator, schema, rootSchema, expandAllBranches, formData) {
|
|
355
|
+
function resolveCondition(validator, schema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
318
356
|
const { if: expression, then, else: otherwise, ...resolvedSchemaLessConditional } = schema;
|
|
319
357
|
const conditionValue = validator.isValid(expression, formData || {}, rootSchema);
|
|
320
358
|
let resolvedSchemas = [resolvedSchemaLessConditional];
|
|
@@ -322,19 +360,26 @@ function resolveCondition(validator, schema, rootSchema, expandAllBranches, form
|
|
|
322
360
|
if (expandAllBranches) {
|
|
323
361
|
if (then && typeof then !== "boolean") {
|
|
324
362
|
schemas = schemas.concat(
|
|
325
|
-
retrieveSchemaInternal(validator, then, rootSchema, formData, expandAllBranches)
|
|
363
|
+
retrieveSchemaInternal(validator, then, rootSchema, formData, expandAllBranches, recurseList)
|
|
326
364
|
);
|
|
327
365
|
}
|
|
328
366
|
if (otherwise && typeof otherwise !== "boolean") {
|
|
329
367
|
schemas = schemas.concat(
|
|
330
|
-
retrieveSchemaInternal(validator, otherwise, rootSchema, formData, expandAllBranches)
|
|
368
|
+
retrieveSchemaInternal(validator, otherwise, rootSchema, formData, expandAllBranches, recurseList)
|
|
331
369
|
);
|
|
332
370
|
}
|
|
333
371
|
} else {
|
|
334
372
|
const conditionalSchema = conditionValue ? then : otherwise;
|
|
335
373
|
if (conditionalSchema && typeof conditionalSchema !== "boolean") {
|
|
336
374
|
schemas = schemas.concat(
|
|
337
|
-
retrieveSchemaInternal(
|
|
375
|
+
retrieveSchemaInternal(
|
|
376
|
+
validator,
|
|
377
|
+
conditionalSchema,
|
|
378
|
+
rootSchema,
|
|
379
|
+
formData,
|
|
380
|
+
expandAllBranches,
|
|
381
|
+
recurseList
|
|
382
|
+
)
|
|
338
383
|
);
|
|
339
384
|
}
|
|
340
385
|
}
|
|
@@ -342,7 +387,7 @@ function resolveCondition(validator, schema, rootSchema, expandAllBranches, form
|
|
|
342
387
|
resolvedSchemas = schemas.map((s) => mergeSchemas(resolvedSchemaLessConditional, s));
|
|
343
388
|
}
|
|
344
389
|
return resolvedSchemas.flatMap(
|
|
345
|
-
(s) => retrieveSchemaInternal(validator, s, rootSchema, formData, expandAllBranches)
|
|
390
|
+
(s) => retrieveSchemaInternal(validator, s, rootSchema, formData, expandAllBranches, recurseList)
|
|
346
391
|
);
|
|
347
392
|
}
|
|
348
393
|
function getAllPermutationsOfXxxOf(listOfLists) {
|
|
@@ -359,40 +404,72 @@ function getAllPermutationsOfXxxOf(listOfLists) {
|
|
|
359
404
|
);
|
|
360
405
|
return allPermutations;
|
|
361
406
|
}
|
|
362
|
-
function resolveSchema(validator, schema, rootSchema, expandAllBranches, formData) {
|
|
363
|
-
|
|
364
|
-
|
|
407
|
+
function resolveSchema(validator, schema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
408
|
+
const updatedSchemas = resolveReference(
|
|
409
|
+
validator,
|
|
410
|
+
schema,
|
|
411
|
+
rootSchema,
|
|
412
|
+
expandAllBranches,
|
|
413
|
+
recurseList,
|
|
414
|
+
formData
|
|
415
|
+
);
|
|
416
|
+
if (updatedSchemas.length > 1 || updatedSchemas[0] !== schema) {
|
|
417
|
+
return updatedSchemas;
|
|
365
418
|
}
|
|
366
419
|
if (DEPENDENCIES_KEY in schema) {
|
|
367
|
-
const resolvedSchemas = resolveDependencies(
|
|
420
|
+
const resolvedSchemas = resolveDependencies(
|
|
421
|
+
validator,
|
|
422
|
+
schema,
|
|
423
|
+
rootSchema,
|
|
424
|
+
expandAllBranches,
|
|
425
|
+
recurseList,
|
|
426
|
+
formData
|
|
427
|
+
);
|
|
368
428
|
return resolvedSchemas.flatMap((s) => {
|
|
369
|
-
return retrieveSchemaInternal(validator, s, rootSchema, formData, expandAllBranches);
|
|
429
|
+
return retrieveSchemaInternal(validator, s, rootSchema, formData, expandAllBranches, recurseList);
|
|
370
430
|
});
|
|
371
431
|
}
|
|
372
432
|
if (ALL_OF_KEY in schema && Array.isArray(schema.allOf)) {
|
|
373
433
|
const allOfSchemaElements = schema.allOf.map(
|
|
374
|
-
(allOfSubschema) => retrieveSchemaInternal(
|
|
434
|
+
(allOfSubschema) => retrieveSchemaInternal(
|
|
435
|
+
validator,
|
|
436
|
+
allOfSubschema,
|
|
437
|
+
rootSchema,
|
|
438
|
+
formData,
|
|
439
|
+
expandAllBranches,
|
|
440
|
+
recurseList
|
|
441
|
+
)
|
|
375
442
|
);
|
|
376
443
|
const allPermutations = getAllPermutationsOfXxxOf(allOfSchemaElements);
|
|
377
444
|
return allPermutations.map((permutation) => ({ ...schema, allOf: permutation }));
|
|
378
445
|
}
|
|
379
446
|
return [schema];
|
|
380
447
|
}
|
|
381
|
-
function resolveReference(validator, schema, rootSchema, expandAllBranches, formData) {
|
|
382
|
-
const
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
448
|
+
function resolveReference(validator, schema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
449
|
+
const updatedSchema = resolveAllReferences(schema, rootSchema, recurseList);
|
|
450
|
+
if (updatedSchema !== schema) {
|
|
451
|
+
return retrieveSchemaInternal(
|
|
452
|
+
validator,
|
|
453
|
+
updatedSchema,
|
|
454
|
+
rootSchema,
|
|
455
|
+
formData,
|
|
456
|
+
expandAllBranches,
|
|
457
|
+
recurseList
|
|
458
|
+
);
|
|
459
|
+
}
|
|
460
|
+
return [schema];
|
|
391
461
|
}
|
|
392
|
-
function resolveAllReferences(schema, rootSchema) {
|
|
462
|
+
function resolveAllReferences(schema, rootSchema, recurseList) {
|
|
463
|
+
if (!isObject(schema)) {
|
|
464
|
+
return schema;
|
|
465
|
+
}
|
|
393
466
|
let resolvedSchema = schema;
|
|
394
467
|
if (REF_KEY in resolvedSchema) {
|
|
395
468
|
const { $ref, ...localSchema } = resolvedSchema;
|
|
469
|
+
if (recurseList.includes($ref)) {
|
|
470
|
+
return resolvedSchema;
|
|
471
|
+
}
|
|
472
|
+
recurseList.push($ref);
|
|
396
473
|
const refSchema = findSchemaDefinition($ref, rootSchema);
|
|
397
474
|
resolvedSchema = { ...refSchema, ...localSchema };
|
|
398
475
|
}
|
|
@@ -400,16 +477,19 @@ function resolveAllReferences(schema, rootSchema) {
|
|
|
400
477
|
const updatedProps = transform(
|
|
401
478
|
resolvedSchema[PROPERTIES_KEY],
|
|
402
479
|
(result, value, key) => {
|
|
403
|
-
result[key] = resolveAllReferences(value, rootSchema);
|
|
480
|
+
result[key] = resolveAllReferences(value, rootSchema, recurseList);
|
|
404
481
|
},
|
|
405
482
|
{}
|
|
406
483
|
);
|
|
407
484
|
resolvedSchema = { ...resolvedSchema, [PROPERTIES_KEY]: updatedProps };
|
|
408
485
|
}
|
|
409
486
|
if (ITEMS_KEY in resolvedSchema && !Array.isArray(resolvedSchema.items) && typeof resolvedSchema.items !== "boolean") {
|
|
410
|
-
resolvedSchema = {
|
|
487
|
+
resolvedSchema = {
|
|
488
|
+
...resolvedSchema,
|
|
489
|
+
items: resolveAllReferences(resolvedSchema.items, rootSchema, recurseList)
|
|
490
|
+
};
|
|
411
491
|
}
|
|
412
|
-
return resolvedSchema;
|
|
492
|
+
return isEqual(schema, resolvedSchema) ? schema : resolvedSchema;
|
|
413
493
|
}
|
|
414
494
|
function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFormData) {
|
|
415
495
|
const schema = {
|
|
@@ -426,7 +506,7 @@ function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFor
|
|
|
426
506
|
if (REF_KEY in schema.additionalProperties) {
|
|
427
507
|
additionalProperties = retrieveSchema(
|
|
428
508
|
validator,
|
|
429
|
-
{ $ref:
|
|
509
|
+
{ $ref: get4(schema.additionalProperties, [REF_KEY]) },
|
|
430
510
|
rootSchema,
|
|
431
511
|
formData
|
|
432
512
|
);
|
|
@@ -438,25 +518,39 @@ function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFor
|
|
|
438
518
|
...schema.additionalProperties
|
|
439
519
|
};
|
|
440
520
|
} else {
|
|
441
|
-
additionalProperties = { type: guessType(
|
|
521
|
+
additionalProperties = { type: guessType(get4(formData, [key])) };
|
|
442
522
|
}
|
|
443
523
|
} else {
|
|
444
|
-
additionalProperties = { type: guessType(
|
|
524
|
+
additionalProperties = { type: guessType(get4(formData, [key])) };
|
|
445
525
|
}
|
|
446
526
|
schema.properties[key] = additionalProperties;
|
|
447
527
|
set(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
|
|
448
528
|
});
|
|
449
529
|
return schema;
|
|
450
530
|
}
|
|
451
|
-
function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expandAllBranches = false) {
|
|
531
|
+
function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expandAllBranches = false, recurseList = []) {
|
|
452
532
|
if (!isObject(schema)) {
|
|
453
533
|
return [{}];
|
|
454
534
|
}
|
|
455
|
-
const resolvedSchemas = resolveSchema(
|
|
535
|
+
const resolvedSchemas = resolveSchema(
|
|
536
|
+
validator,
|
|
537
|
+
schema,
|
|
538
|
+
rootSchema,
|
|
539
|
+
expandAllBranches,
|
|
540
|
+
recurseList,
|
|
541
|
+
rawFormData
|
|
542
|
+
);
|
|
456
543
|
return resolvedSchemas.flatMap((s) => {
|
|
457
544
|
let resolvedSchema = s;
|
|
458
545
|
if (IF_KEY in resolvedSchema) {
|
|
459
|
-
return resolveCondition(
|
|
546
|
+
return resolveCondition(
|
|
547
|
+
validator,
|
|
548
|
+
resolvedSchema,
|
|
549
|
+
rootSchema,
|
|
550
|
+
expandAllBranches,
|
|
551
|
+
recurseList,
|
|
552
|
+
rawFormData
|
|
553
|
+
);
|
|
460
554
|
}
|
|
461
555
|
if (ALL_OF_KEY in resolvedSchema) {
|
|
462
556
|
if (expandAllBranches) {
|
|
@@ -492,7 +586,7 @@ function resolveAnyOrOneOfSchemas(validator, schema, rootSchema, expandAllBranch
|
|
|
492
586
|
const formData = rawFormData === void 0 && expandAllBranches ? {} : rawFormData;
|
|
493
587
|
const discriminator = getDiscriminatorFieldFromSchema(schema);
|
|
494
588
|
anyOrOneOf = anyOrOneOf.map((s) => {
|
|
495
|
-
return resolveAllReferences(s, rootSchema);
|
|
589
|
+
return resolveAllReferences(s, rootSchema, []);
|
|
496
590
|
});
|
|
497
591
|
const option = getFirstMatchingOption(validator, formData, anyOrOneOf, rootSchema, discriminator);
|
|
498
592
|
if (expandAllBranches) {
|
|
@@ -502,7 +596,7 @@ function resolveAnyOrOneOfSchemas(validator, schema, rootSchema, expandAllBranch
|
|
|
502
596
|
}
|
|
503
597
|
return [schema];
|
|
504
598
|
}
|
|
505
|
-
function resolveDependencies(validator, schema, rootSchema, expandAllBranches, formData) {
|
|
599
|
+
function resolveDependencies(validator, schema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
506
600
|
const { dependencies, ...remainingSchema } = schema;
|
|
507
601
|
const resolvedSchemas = resolveAnyOrOneOfSchemas(
|
|
508
602
|
validator,
|
|
@@ -512,13 +606,21 @@ function resolveDependencies(validator, schema, rootSchema, expandAllBranches, f
|
|
|
512
606
|
formData
|
|
513
607
|
);
|
|
514
608
|
return resolvedSchemas.flatMap(
|
|
515
|
-
(resolvedSchema) => processDependencies(
|
|
609
|
+
(resolvedSchema) => processDependencies(
|
|
610
|
+
validator,
|
|
611
|
+
dependencies,
|
|
612
|
+
resolvedSchema,
|
|
613
|
+
rootSchema,
|
|
614
|
+
expandAllBranches,
|
|
615
|
+
recurseList,
|
|
616
|
+
formData
|
|
617
|
+
)
|
|
516
618
|
);
|
|
517
619
|
}
|
|
518
|
-
function processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, formData) {
|
|
620
|
+
function processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
519
621
|
let schemas = [resolvedSchema];
|
|
520
622
|
for (const dependencyKey in dependencies) {
|
|
521
|
-
if (!expandAllBranches &&
|
|
623
|
+
if (!expandAllBranches && get4(formData, [dependencyKey]) === void 0) {
|
|
522
624
|
continue;
|
|
523
625
|
}
|
|
524
626
|
if (resolvedSchema.properties && !(dependencyKey in resolvedSchema.properties)) {
|
|
@@ -538,11 +640,20 @@ function processDependencies(validator, dependencies, resolvedSchema, rootSchema
|
|
|
538
640
|
dependencyKey,
|
|
539
641
|
dependencyValue,
|
|
540
642
|
expandAllBranches,
|
|
643
|
+
recurseList,
|
|
541
644
|
formData
|
|
542
645
|
);
|
|
543
646
|
}
|
|
544
647
|
return schemas.flatMap(
|
|
545
|
-
(schema) => processDependencies(
|
|
648
|
+
(schema) => processDependencies(
|
|
649
|
+
validator,
|
|
650
|
+
remainingDependencies,
|
|
651
|
+
schema,
|
|
652
|
+
rootSchema,
|
|
653
|
+
expandAllBranches,
|
|
654
|
+
recurseList,
|
|
655
|
+
formData
|
|
656
|
+
)
|
|
546
657
|
);
|
|
547
658
|
}
|
|
548
659
|
return schemas;
|
|
@@ -554,13 +665,14 @@ function withDependentProperties(schema, additionallyRequired) {
|
|
|
554
665
|
const required = Array.isArray(schema.required) ? Array.from(/* @__PURE__ */ new Set([...schema.required, ...additionallyRequired])) : additionallyRequired;
|
|
555
666
|
return { ...schema, required };
|
|
556
667
|
}
|
|
557
|
-
function withDependentSchema(validator, schema, rootSchema, dependencyKey, dependencyValue, expandAllBranches, formData) {
|
|
668
|
+
function withDependentSchema(validator, schema, rootSchema, dependencyKey, dependencyValue, expandAllBranches, recurseList, formData) {
|
|
558
669
|
const dependentSchemas = retrieveSchemaInternal(
|
|
559
670
|
validator,
|
|
560
671
|
dependencyValue,
|
|
561
672
|
rootSchema,
|
|
562
673
|
formData,
|
|
563
|
-
expandAllBranches
|
|
674
|
+
expandAllBranches,
|
|
675
|
+
recurseList
|
|
564
676
|
);
|
|
565
677
|
return dependentSchemas.flatMap((dependent) => {
|
|
566
678
|
const { oneOf, ...dependentSchema } = dependent;
|
|
@@ -572,7 +684,7 @@ function withDependentSchema(validator, schema, rootSchema, dependencyKey, depen
|
|
|
572
684
|
if (typeof subschema === "boolean" || !(REF_KEY in subschema)) {
|
|
573
685
|
return [subschema];
|
|
574
686
|
}
|
|
575
|
-
return resolveReference(validator, subschema, rootSchema, expandAllBranches, formData);
|
|
687
|
+
return resolveReference(validator, subschema, rootSchema, expandAllBranches, recurseList, formData);
|
|
576
688
|
});
|
|
577
689
|
const allPermutations = getAllPermutationsOfXxxOf(resolvedOneOfs);
|
|
578
690
|
return allPermutations.flatMap(
|
|
@@ -583,12 +695,13 @@ function withDependentSchema(validator, schema, rootSchema, dependencyKey, depen
|
|
|
583
695
|
dependencyKey,
|
|
584
696
|
resolvedOneOf,
|
|
585
697
|
expandAllBranches,
|
|
698
|
+
recurseList,
|
|
586
699
|
formData
|
|
587
700
|
)
|
|
588
701
|
);
|
|
589
702
|
});
|
|
590
703
|
}
|
|
591
|
-
function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, oneOf, expandAllBranches, formData) {
|
|
704
|
+
function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, oneOf, expandAllBranches, recurseList, formData) {
|
|
592
705
|
const validSubschemas = oneOf.filter((subschema) => {
|
|
593
706
|
if (typeof subschema === "boolean" || !subschema || !subschema.properties) {
|
|
594
707
|
return false;
|
|
@@ -618,7 +731,8 @@ function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, o
|
|
|
618
731
|
dependentSchema,
|
|
619
732
|
rootSchema,
|
|
620
733
|
formData,
|
|
621
|
-
expandAllBranches
|
|
734
|
+
expandAllBranches,
|
|
735
|
+
recurseList
|
|
622
736
|
);
|
|
623
737
|
return schemas.map((s2) => mergeSchemas(schema, s2));
|
|
624
738
|
});
|
|
@@ -641,7 +755,7 @@ function calculateIndexScore(validator, rootSchema, schema, formData = {}) {
|
|
|
641
755
|
totalScore += reduce(
|
|
642
756
|
schema.properties,
|
|
643
757
|
(score, value, key) => {
|
|
644
|
-
const formValue =
|
|
758
|
+
const formValue = get5(formData, key);
|
|
645
759
|
if (typeof value === "boolean") {
|
|
646
760
|
return score;
|
|
647
761
|
}
|
|
@@ -656,7 +770,7 @@ function calculateIndexScore(validator, rootSchema, schema, formData = {}) {
|
|
|
656
770
|
validator,
|
|
657
771
|
rootSchema,
|
|
658
772
|
formValue,
|
|
659
|
-
|
|
773
|
+
get5(value, key2),
|
|
660
774
|
-1,
|
|
661
775
|
discriminator
|
|
662
776
|
);
|
|
@@ -685,8 +799,12 @@ function calculateIndexScore(validator, rootSchema, schema, formData = {}) {
|
|
|
685
799
|
}
|
|
686
800
|
function getClosestMatchingOption(validator, rootSchema, formData, options, selectedOption = -1, discriminatorField) {
|
|
687
801
|
const resolvedOptions = options.map((option) => {
|
|
688
|
-
return resolveAllReferences(option, rootSchema);
|
|
802
|
+
return resolveAllReferences(option, rootSchema, []);
|
|
689
803
|
});
|
|
804
|
+
const simpleDiscriminatorMatch = getOptionMatchingSimpleDiscriminator(formData, options, discriminatorField);
|
|
805
|
+
if (isNumber2(simpleDiscriminatorMatch)) {
|
|
806
|
+
return simpleDiscriminatorMatch;
|
|
807
|
+
}
|
|
690
808
|
const allValidIndexes = resolvedOptions.reduce((validList, option, index) => {
|
|
691
809
|
const testOptions = [JUNK_OPTION, option];
|
|
692
810
|
const match = getFirstMatchingOption(validator, formData, testOptions, rootSchema, discriminatorField);
|
|
@@ -727,7 +845,7 @@ function isFixedItems(schema) {
|
|
|
727
845
|
}
|
|
728
846
|
|
|
729
847
|
// src/mergeDefaultsWithFormData.ts
|
|
730
|
-
import
|
|
848
|
+
import get6 from "lodash/get";
|
|
731
849
|
function mergeDefaultsWithFormData(defaults, formData, mergeExtraArrayDefaults = false) {
|
|
732
850
|
if (Array.isArray(formData)) {
|
|
733
851
|
const defaultsArray = Array.isArray(defaults) ? defaults : [];
|
|
@@ -746,8 +864,8 @@ function mergeDefaultsWithFormData(defaults, formData, mergeExtraArrayDefaults =
|
|
|
746
864
|
const acc = Object.assign({}, defaults);
|
|
747
865
|
return Object.keys(formData).reduce((acc2, key) => {
|
|
748
866
|
acc2[key] = mergeDefaultsWithFormData(
|
|
749
|
-
defaults ?
|
|
750
|
-
|
|
867
|
+
defaults ? get6(defaults, key) : {},
|
|
868
|
+
get6(formData, key),
|
|
751
869
|
mergeExtraArrayDefaults
|
|
752
870
|
);
|
|
753
871
|
return acc2;
|
|
@@ -868,7 +986,7 @@ function computeDefaults(validator, rawSchema, {
|
|
|
868
986
|
schemaToCompute = findSchemaDefinition(refName, rootSchema);
|
|
869
987
|
}
|
|
870
988
|
} else if (DEPENDENCIES_KEY in schema) {
|
|
871
|
-
const resolvedSchema = resolveDependencies(validator, schema, rootSchema, false, formData);
|
|
989
|
+
const resolvedSchema = resolveDependencies(validator, schema, rootSchema, false, [], formData);
|
|
872
990
|
schemaToCompute = resolvedSchema[0];
|
|
873
991
|
} else if (isFixedItems(schema)) {
|
|
874
992
|
defaults = schema.items.map(
|
|
@@ -930,13 +1048,13 @@ function computeDefaults(validator, rawSchema, {
|
|
|
930
1048
|
switch (getSchemaType(schema)) {
|
|
931
1049
|
case "object": {
|
|
932
1050
|
const objectDefaults = Object.keys(schema.properties || {}).reduce((acc, key) => {
|
|
933
|
-
const computedDefault = computeDefaults(validator,
|
|
1051
|
+
const computedDefault = computeDefaults(validator, get7(schema, [PROPERTIES_KEY, key]), {
|
|
934
1052
|
rootSchema,
|
|
935
1053
|
_recurseList,
|
|
936
1054
|
experimental_defaultFormStateBehavior,
|
|
937
1055
|
includeUndefinedValues: includeUndefinedValues === true,
|
|
938
|
-
parentDefaults:
|
|
939
|
-
rawFormData:
|
|
1056
|
+
parentDefaults: get7(defaults, [key]),
|
|
1057
|
+
rawFormData: get7(formData, [key]),
|
|
940
1058
|
required: schema.required?.includes(key)
|
|
941
1059
|
});
|
|
942
1060
|
maybeAddDefaultToObject(
|
|
@@ -956,22 +1074,19 @@ function computeDefaults(validator, rawSchema, {
|
|
|
956
1074
|
if (isObject(defaults)) {
|
|
957
1075
|
Object.keys(defaults).filter((key) => !schema.properties || !schema.properties[key]).forEach((key) => keys.add(key));
|
|
958
1076
|
}
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
formDataRequired.push(key);
|
|
965
|
-
});
|
|
966
|
-
}
|
|
1077
|
+
const formDataRequired = [];
|
|
1078
|
+
Object.keys(formData).filter((key) => !schema.properties || !schema.properties[key]).forEach((key) => {
|
|
1079
|
+
keys.add(key);
|
|
1080
|
+
formDataRequired.push(key);
|
|
1081
|
+
});
|
|
967
1082
|
keys.forEach((key) => {
|
|
968
1083
|
const computedDefault = computeDefaults(validator, additionalPropertiesSchema, {
|
|
969
1084
|
rootSchema,
|
|
970
1085
|
_recurseList,
|
|
971
1086
|
experimental_defaultFormStateBehavior,
|
|
972
1087
|
includeUndefinedValues: includeUndefinedValues === true,
|
|
973
|
-
parentDefaults:
|
|
974
|
-
rawFormData:
|
|
1088
|
+
parentDefaults: get7(defaults, [key]),
|
|
1089
|
+
rawFormData: get7(formData, [key]),
|
|
975
1090
|
required: schema.required?.includes(key)
|
|
976
1091
|
});
|
|
977
1092
|
maybeAddDefaultToObject(
|
|
@@ -1012,7 +1127,7 @@ function computeDefaults(validator, rawSchema, {
|
|
|
1012
1127
|
_recurseList,
|
|
1013
1128
|
experimental_defaultFormStateBehavior,
|
|
1014
1129
|
rawFormData: item,
|
|
1015
|
-
parentDefaults:
|
|
1130
|
+
parentDefaults: get7(defaults, [idx]),
|
|
1016
1131
|
required
|
|
1017
1132
|
});
|
|
1018
1133
|
});
|
|
@@ -1128,7 +1243,7 @@ function mergeValidationData(validator, validationData, additionalErrorSchema) {
|
|
|
1128
1243
|
}
|
|
1129
1244
|
|
|
1130
1245
|
// src/schema/sanitizeDataForNewSchema.ts
|
|
1131
|
-
import
|
|
1246
|
+
import get8 from "lodash/get";
|
|
1132
1247
|
import has3 from "lodash/has";
|
|
1133
1248
|
var NO_VALUE = Symbol("no Value");
|
|
1134
1249
|
function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, data = {}) {
|
|
@@ -1136,27 +1251,27 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1136
1251
|
if (has3(newSchema, PROPERTIES_KEY)) {
|
|
1137
1252
|
const removeOldSchemaData = {};
|
|
1138
1253
|
if (has3(oldSchema, PROPERTIES_KEY)) {
|
|
1139
|
-
const properties =
|
|
1254
|
+
const properties = get8(oldSchema, PROPERTIES_KEY, {});
|
|
1140
1255
|
Object.keys(properties).forEach((key) => {
|
|
1141
1256
|
if (has3(data, key)) {
|
|
1142
1257
|
removeOldSchemaData[key] = void 0;
|
|
1143
1258
|
}
|
|
1144
1259
|
});
|
|
1145
1260
|
}
|
|
1146
|
-
const keys = Object.keys(
|
|
1261
|
+
const keys = Object.keys(get8(newSchema, PROPERTIES_KEY, {}));
|
|
1147
1262
|
const nestedData = {};
|
|
1148
1263
|
keys.forEach((key) => {
|
|
1149
|
-
const formValue =
|
|
1150
|
-
let oldKeyedSchema =
|
|
1151
|
-
let newKeyedSchema =
|
|
1264
|
+
const formValue = get8(data, key);
|
|
1265
|
+
let oldKeyedSchema = get8(oldSchema, [PROPERTIES_KEY, key], {});
|
|
1266
|
+
let newKeyedSchema = get8(newSchema, [PROPERTIES_KEY, key], {});
|
|
1152
1267
|
if (has3(oldKeyedSchema, REF_KEY)) {
|
|
1153
1268
|
oldKeyedSchema = retrieveSchema(validator, oldKeyedSchema, rootSchema, formValue);
|
|
1154
1269
|
}
|
|
1155
1270
|
if (has3(newKeyedSchema, REF_KEY)) {
|
|
1156
1271
|
newKeyedSchema = retrieveSchema(validator, newKeyedSchema, rootSchema, formValue);
|
|
1157
1272
|
}
|
|
1158
|
-
const oldSchemaTypeForKey =
|
|
1159
|
-
const newSchemaTypeForKey =
|
|
1273
|
+
const oldSchemaTypeForKey = get8(oldKeyedSchema, "type");
|
|
1274
|
+
const newSchemaTypeForKey = get8(newKeyedSchema, "type");
|
|
1160
1275
|
if (!oldSchemaTypeForKey || oldSchemaTypeForKey === newSchemaTypeForKey) {
|
|
1161
1276
|
if (has3(removeOldSchemaData, key)) {
|
|
1162
1277
|
delete removeOldSchemaData[key];
|
|
@@ -1173,17 +1288,17 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1173
1288
|
nestedData[key] = itemData;
|
|
1174
1289
|
}
|
|
1175
1290
|
} else {
|
|
1176
|
-
const newOptionDefault =
|
|
1177
|
-
const oldOptionDefault =
|
|
1291
|
+
const newOptionDefault = get8(newKeyedSchema, "default", NO_VALUE);
|
|
1292
|
+
const oldOptionDefault = get8(oldKeyedSchema, "default", NO_VALUE);
|
|
1178
1293
|
if (newOptionDefault !== NO_VALUE && newOptionDefault !== formValue) {
|
|
1179
1294
|
if (oldOptionDefault === formValue) {
|
|
1180
1295
|
removeOldSchemaData[key] = newOptionDefault;
|
|
1181
|
-
} else if (
|
|
1296
|
+
} else if (get8(newKeyedSchema, "readOnly") === true) {
|
|
1182
1297
|
removeOldSchemaData[key] = void 0;
|
|
1183
1298
|
}
|
|
1184
1299
|
}
|
|
1185
|
-
const newOptionConst =
|
|
1186
|
-
const oldOptionConst =
|
|
1300
|
+
const newOptionConst = get8(newKeyedSchema, "const", NO_VALUE);
|
|
1301
|
+
const oldOptionConst = get8(oldKeyedSchema, "const", NO_VALUE);
|
|
1187
1302
|
if (newOptionConst !== NO_VALUE && newOptionConst !== formValue) {
|
|
1188
1303
|
removeOldSchemaData[key] = oldOptionConst === formValue ? newOptionConst : void 0;
|
|
1189
1304
|
}
|
|
@@ -1195,9 +1310,9 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1195
1310
|
...removeOldSchemaData,
|
|
1196
1311
|
...nestedData
|
|
1197
1312
|
};
|
|
1198
|
-
} else if (
|
|
1199
|
-
let oldSchemaItems =
|
|
1200
|
-
let newSchemaItems =
|
|
1313
|
+
} else if (get8(oldSchema, "type") === "array" && get8(newSchema, "type") === "array" && Array.isArray(data)) {
|
|
1314
|
+
let oldSchemaItems = get8(oldSchema, "items");
|
|
1315
|
+
let newSchemaItems = get8(newSchema, "items");
|
|
1201
1316
|
if (typeof oldSchemaItems === "object" && typeof newSchemaItems === "object" && !Array.isArray(oldSchemaItems) && !Array.isArray(newSchemaItems)) {
|
|
1202
1317
|
if (has3(oldSchemaItems, REF_KEY)) {
|
|
1203
1318
|
oldSchemaItems = retrieveSchema(validator, oldSchemaItems, rootSchema, data);
|
|
@@ -1205,10 +1320,10 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1205
1320
|
if (has3(newSchemaItems, REF_KEY)) {
|
|
1206
1321
|
newSchemaItems = retrieveSchema(validator, newSchemaItems, rootSchema, data);
|
|
1207
1322
|
}
|
|
1208
|
-
const oldSchemaType =
|
|
1209
|
-
const newSchemaType =
|
|
1323
|
+
const oldSchemaType = get8(oldSchemaItems, "type");
|
|
1324
|
+
const newSchemaType = get8(newSchemaItems, "type");
|
|
1210
1325
|
if (!oldSchemaType || oldSchemaType === newSchemaType) {
|
|
1211
|
-
const maxItems =
|
|
1326
|
+
const maxItems = get8(newSchema, "maxItems", -1);
|
|
1212
1327
|
if (newSchemaType === "object") {
|
|
1213
1328
|
newFormData = data.reduce((newValue, aValue) => {
|
|
1214
1329
|
const itemValue = sanitizeDataForNewSchema(
|
|
@@ -1235,12 +1350,12 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1235
1350
|
}
|
|
1236
1351
|
|
|
1237
1352
|
// src/schema/toIdSchema.ts
|
|
1238
|
-
import
|
|
1239
|
-
import
|
|
1353
|
+
import get9 from "lodash/get";
|
|
1354
|
+
import isEqual2 from "lodash/isEqual";
|
|
1240
1355
|
function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSchema, formData, _recurseList = []) {
|
|
1241
1356
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
1242
1357
|
const _schema = retrieveSchema(validator, schema, rootSchema, formData);
|
|
1243
|
-
const sameSchemaIndex = _recurseList.findIndex((item) =>
|
|
1358
|
+
const sameSchemaIndex = _recurseList.findIndex((item) => isEqual2(item, _schema));
|
|
1244
1359
|
if (sameSchemaIndex === -1) {
|
|
1245
1360
|
return toIdSchemaInternal(
|
|
1246
1361
|
validator,
|
|
@@ -1254,10 +1369,10 @@ function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSc
|
|
|
1254
1369
|
);
|
|
1255
1370
|
}
|
|
1256
1371
|
}
|
|
1257
|
-
if (ITEMS_KEY in schema && !
|
|
1372
|
+
if (ITEMS_KEY in schema && !get9(schema, [ITEMS_KEY, REF_KEY])) {
|
|
1258
1373
|
return toIdSchemaInternal(
|
|
1259
1374
|
validator,
|
|
1260
|
-
|
|
1375
|
+
get9(schema, ITEMS_KEY),
|
|
1261
1376
|
idPrefix,
|
|
1262
1377
|
idSeparator,
|
|
1263
1378
|
id,
|
|
@@ -1270,7 +1385,7 @@ function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSc
|
|
|
1270
1385
|
const idSchema = { $id };
|
|
1271
1386
|
if (getSchemaType(schema) === "object" && PROPERTIES_KEY in schema) {
|
|
1272
1387
|
for (const name in schema.properties) {
|
|
1273
|
-
const field =
|
|
1388
|
+
const field = get9(schema, [PROPERTIES_KEY, name]);
|
|
1274
1389
|
const fieldId = idSchema[ID_KEY] + idSeparator + name;
|
|
1275
1390
|
idSchema[name] = toIdSchemaInternal(
|
|
1276
1391
|
validator,
|
|
@@ -1281,7 +1396,7 @@ function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSc
|
|
|
1281
1396
|
rootSchema,
|
|
1282
1397
|
// It's possible that formData is not an object -- this can happen if an
|
|
1283
1398
|
// array item has just been added, but not populated with data yet
|
|
1284
|
-
|
|
1399
|
+
get9(formData, [name]),
|
|
1285
1400
|
_recurseList
|
|
1286
1401
|
);
|
|
1287
1402
|
}
|
|
@@ -1293,13 +1408,13 @@ function toIdSchema(validator, schema, id, rootSchema, formData, idPrefix = "roo
|
|
|
1293
1408
|
}
|
|
1294
1409
|
|
|
1295
1410
|
// src/schema/toPathSchema.ts
|
|
1296
|
-
import
|
|
1297
|
-
import
|
|
1411
|
+
import get10 from "lodash/get";
|
|
1412
|
+
import isEqual3 from "lodash/isEqual";
|
|
1298
1413
|
import set2 from "lodash/set";
|
|
1299
1414
|
function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = []) {
|
|
1300
1415
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
1301
1416
|
const _schema = retrieveSchema(validator, schema, rootSchema, formData);
|
|
1302
|
-
const sameSchemaIndex = _recurseList.findIndex((item) =>
|
|
1417
|
+
const sameSchemaIndex = _recurseList.findIndex((item) => isEqual3(item, _schema));
|
|
1303
1418
|
if (sameSchemaIndex === -1) {
|
|
1304
1419
|
return toPathSchemaInternal(
|
|
1305
1420
|
validator,
|
|
@@ -1340,7 +1455,7 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
1340
1455
|
});
|
|
1341
1456
|
} else if (PROPERTIES_KEY in schema) {
|
|
1342
1457
|
for (const property in schema.properties) {
|
|
1343
|
-
const field =
|
|
1458
|
+
const field = get10(schema, [PROPERTIES_KEY, property]);
|
|
1344
1459
|
pathSchema[property] = toPathSchemaInternal(
|
|
1345
1460
|
validator,
|
|
1346
1461
|
field,
|
|
@@ -1348,7 +1463,7 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
1348
1463
|
rootSchema,
|
|
1349
1464
|
// It's possible that formData is not an object -- this can happen if an
|
|
1350
1465
|
// array item has just been added, but not populated with data yet
|
|
1351
|
-
|
|
1466
|
+
get10(formData, [property]),
|
|
1352
1467
|
_recurseList
|
|
1353
1468
|
);
|
|
1354
1469
|
}
|
|
@@ -1613,7 +1728,7 @@ function englishStringTranslator(stringToTranslate, params) {
|
|
|
1613
1728
|
}
|
|
1614
1729
|
|
|
1615
1730
|
// src/enumOptionsDeselectValue.ts
|
|
1616
|
-
import
|
|
1731
|
+
import isEqual4 from "lodash/isEqual";
|
|
1617
1732
|
|
|
1618
1733
|
// src/enumOptionsValueForIndex.ts
|
|
1619
1734
|
function enumOptionsValueForIndex(valueIndex, allEnumOptions = [], emptyValue) {
|
|
@@ -1629,18 +1744,18 @@ function enumOptionsValueForIndex(valueIndex, allEnumOptions = [], emptyValue) {
|
|
|
1629
1744
|
function enumOptionsDeselectValue(valueIndex, selected, allEnumOptions = []) {
|
|
1630
1745
|
const value = enumOptionsValueForIndex(valueIndex, allEnumOptions);
|
|
1631
1746
|
if (Array.isArray(selected)) {
|
|
1632
|
-
return selected.filter((v) => !
|
|
1747
|
+
return selected.filter((v) => !isEqual4(v, value));
|
|
1633
1748
|
}
|
|
1634
|
-
return
|
|
1749
|
+
return isEqual4(value, selected) ? void 0 : selected;
|
|
1635
1750
|
}
|
|
1636
1751
|
|
|
1637
1752
|
// src/enumOptionsIsSelected.ts
|
|
1638
|
-
import
|
|
1753
|
+
import isEqual5 from "lodash/isEqual";
|
|
1639
1754
|
function enumOptionsIsSelected(value, selected) {
|
|
1640
1755
|
if (Array.isArray(selected)) {
|
|
1641
|
-
return selected.some((sel) =>
|
|
1756
|
+
return selected.some((sel) => isEqual5(sel, value));
|
|
1642
1757
|
}
|
|
1643
|
-
return
|
|
1758
|
+
return isEqual5(selected, value);
|
|
1644
1759
|
}
|
|
1645
1760
|
|
|
1646
1761
|
// src/enumOptionsIndexForValue.ts
|
|
@@ -1667,7 +1782,7 @@ function enumOptionsSelectValue(valueIndex, selected, allEnumOptions = []) {
|
|
|
1667
1782
|
|
|
1668
1783
|
// src/ErrorSchemaBuilder.ts
|
|
1669
1784
|
import cloneDeep from "lodash/cloneDeep";
|
|
1670
|
-
import
|
|
1785
|
+
import get11 from "lodash/get";
|
|
1671
1786
|
import set3 from "lodash/set";
|
|
1672
1787
|
var ErrorSchemaBuilder = class {
|
|
1673
1788
|
/** Construct an `ErrorSchemaBuilder` with an optional initial set of errors in an `ErrorSchema`.
|
|
@@ -1695,7 +1810,7 @@ var ErrorSchemaBuilder = class {
|
|
|
1695
1810
|
*/
|
|
1696
1811
|
getOrCreateErrorBlock(pathOfError) {
|
|
1697
1812
|
const hasPath = Array.isArray(pathOfError) && pathOfError.length > 0 || typeof pathOfError === "string";
|
|
1698
|
-
let errorBlock = hasPath ?
|
|
1813
|
+
let errorBlock = hasPath ? get11(this.errorSchema, pathOfError) : this.errorSchema;
|
|
1699
1814
|
if (!errorBlock && pathOfError) {
|
|
1700
1815
|
errorBlock = {};
|
|
1701
1816
|
set3(this.errorSchema, pathOfError, errorBlock);
|
|
@@ -1721,7 +1836,7 @@ var ErrorSchemaBuilder = class {
|
|
|
1721
1836
|
*/
|
|
1722
1837
|
addErrors(errorOrList, pathOfError) {
|
|
1723
1838
|
const errorBlock = this.getOrCreateErrorBlock(pathOfError);
|
|
1724
|
-
let errorsList =
|
|
1839
|
+
let errorsList = get11(errorBlock, ERRORS_KEY);
|
|
1725
1840
|
if (!Array.isArray(errorsList)) {
|
|
1726
1841
|
errorsList = [];
|
|
1727
1842
|
errorBlock[ERRORS_KEY] = errorsList;
|
|
@@ -1836,7 +1951,7 @@ function getTemplate(name, registry, uiOptions = {}) {
|
|
|
1836
1951
|
// src/getWidget.tsx
|
|
1837
1952
|
import { createElement } from "react";
|
|
1838
1953
|
import ReactIs from "react-is";
|
|
1839
|
-
import
|
|
1954
|
+
import get12 from "lodash/get";
|
|
1840
1955
|
import set4 from "lodash/set";
|
|
1841
1956
|
import { jsx } from "react/jsx-runtime";
|
|
1842
1957
|
var widgetMap = {
|
|
@@ -1892,7 +2007,7 @@ var widgetMap = {
|
|
|
1892
2007
|
}
|
|
1893
2008
|
};
|
|
1894
2009
|
function mergeWidgetOptions(AWidget) {
|
|
1895
|
-
let MergedWidget =
|
|
2010
|
+
let MergedWidget = get12(AWidget, "MergedWidget");
|
|
1896
2011
|
if (!MergedWidget) {
|
|
1897
2012
|
const defaultOptions = AWidget.defaultProps && AWidget.defaultProps.options || {};
|
|
1898
2013
|
MergedWidget = ({ options, ...props }) => {
|
|
@@ -2297,11 +2412,11 @@ var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
|
|
|
2297
2412
|
|
|
2298
2413
|
// src/parser/schemaParser.ts
|
|
2299
2414
|
import forEach from "lodash/forEach";
|
|
2300
|
-
import
|
|
2415
|
+
import isEqual7 from "lodash/isEqual";
|
|
2301
2416
|
|
|
2302
2417
|
// src/parser/ParserValidator.ts
|
|
2303
|
-
import
|
|
2304
|
-
import
|
|
2418
|
+
import get13 from "lodash/get";
|
|
2419
|
+
import isEqual6 from "lodash/isEqual";
|
|
2305
2420
|
var ParserValidator = class {
|
|
2306
2421
|
/** Construct the ParserValidator for the given `rootSchema`. This `rootSchema` will be stashed in the `schemaMap`
|
|
2307
2422
|
* first.
|
|
@@ -2322,12 +2437,12 @@ var ParserValidator = class {
|
|
|
2322
2437
|
* @param hash - The hash value at which to map the schema
|
|
2323
2438
|
*/
|
|
2324
2439
|
addSchema(schema, hash) {
|
|
2325
|
-
const key =
|
|
2440
|
+
const key = get13(schema, ID_KEY, hash);
|
|
2326
2441
|
const identifiedSchema = { ...schema, [ID_KEY]: key };
|
|
2327
2442
|
const existing = this.schemaMap[key];
|
|
2328
2443
|
if (!existing) {
|
|
2329
2444
|
this.schemaMap[key] = identifiedSchema;
|
|
2330
|
-
} else if (!
|
|
2445
|
+
} else if (!isEqual6(existing, identifiedSchema)) {
|
|
2331
2446
|
console.error("existing schema:", JSON.stringify(existing, null, 2));
|
|
2332
2447
|
console.error("new schema:", JSON.stringify(identifiedSchema, null, 2));
|
|
2333
2448
|
throw new Error(
|
|
@@ -2349,7 +2464,7 @@ var ParserValidator = class {
|
|
|
2349
2464
|
* @throws - Error when the given `rootSchema` differs from the root schema provided during construction
|
|
2350
2465
|
*/
|
|
2351
2466
|
isValid(schema, _formData, rootSchema) {
|
|
2352
|
-
if (!
|
|
2467
|
+
if (!isEqual6(rootSchema, this.rootSchema)) {
|
|
2353
2468
|
throw new Error("Unexpectedly calling isValid() with a rootSchema that differs from the construction rootSchema");
|
|
2354
2469
|
}
|
|
2355
2470
|
this.addSchema(schema, hashForSchema(schema));
|
|
@@ -2389,7 +2504,7 @@ var ParserValidator = class {
|
|
|
2389
2504
|
function parseSchema(validator, recurseList, rootSchema, schema) {
|
|
2390
2505
|
const schemas = retrieveSchemaInternal(validator, schema, rootSchema, void 0, true);
|
|
2391
2506
|
schemas.forEach((schema2) => {
|
|
2392
|
-
const sameSchemaIndex = recurseList.findIndex((item) =>
|
|
2507
|
+
const sameSchemaIndex = recurseList.findIndex((item) => isEqual7(item, schema2));
|
|
2393
2508
|
if (sameSchemaIndex === -1) {
|
|
2394
2509
|
recurseList.push(schema2);
|
|
2395
2510
|
const allOptions = resolveAnyOrOneOfSchemas(validator, schema2, rootSchema, true);
|
|
@@ -2466,6 +2581,7 @@ export {
|
|
|
2466
2581
|
getFirstMatchingOption,
|
|
2467
2582
|
getInputProps,
|
|
2468
2583
|
getMatchingOption,
|
|
2584
|
+
getOptionMatchingSimpleDiscriminator,
|
|
2469
2585
|
getSchemaType,
|
|
2470
2586
|
getSubmitButtonOptions,
|
|
2471
2587
|
getTemplate,
|