@rjsf/utils 6.0.0-beta.1 → 6.0.0-beta.10
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 +158 -109
- package/dist/index.js.map +3 -3
- package/dist/utils.esm.js +158 -109
- package/dist/utils.esm.js.map +3 -3
- package/dist/utils.umd.js +132 -87
- package/lib/canExpand.d.ts +1 -1
- package/lib/constants.d.ts +4 -0
- package/lib/constants.js +4 -0
- package/lib/constants.js.map +1 -1
- package/lib/findSchemaDefinition.d.ts +4 -2
- package/lib/findSchemaDefinition.js +53 -10
- package/lib/findSchemaDefinition.js.map +1 -1
- package/lib/schema/findFieldInSchema.d.ts +1 -1
- package/lib/schema/findFieldInSchema.js +1 -1
- package/lib/schema/getDefaultFormState.js +13 -2
- package/lib/schema/getDefaultFormState.js.map +1 -1
- package/lib/schema/retrieveSchema.d.ts +2 -1
- package/lib/schema/retrieveSchema.js +14 -7
- package/lib/schema/retrieveSchema.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types.d.ts +13 -12
- package/package.json +2 -1
- package/src/constants.ts +5 -0
- package/src/findSchemaDefinition.ts +53 -8
- package/src/schema/findFieldInSchema.ts +1 -1
- package/src/schema/getDefaultFormState.ts +15 -3
- package/src/schema/retrieveSchema.ts +14 -5
- package/src/types.ts +13 -11
package/dist/utils.umd.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('lodash/isPlainObject'), require('lodash/isEqualWith'), require('lodash/get'), require('lodash/has'), require('lodash/isEqual'), require('lodash/set'), require('lodash/times'), require('lodash/transform'), require('lodash/merge'), require('lodash/flattenDeep'), require('lodash/uniq'), require('json-schema-merge-allof'), require('jsonpointer'), require('lodash/omit'), require('lodash/
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'lodash/isPlainObject', 'lodash/isEqualWith', 'lodash/get', 'lodash/has', 'lodash/isEqual', 'lodash/set', 'lodash/times', 'lodash/transform', 'lodash/merge', 'lodash/flattenDeep', 'lodash/uniq', 'json-schema-merge-allof', 'jsonpointer', 'lodash/omit', 'lodash/
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@rjsf/utils"] = {}, global.isPlainObject4, global.isEqualWith, global.
|
|
5
|
-
})(this, (function (exports, isPlainObject4, isEqualWith,
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('lodash/isPlainObject'), require('lodash/isEqualWith'), require('lodash/get'), require('lodash/has'), require('lodash/isEqual'), require('lodash/set'), require('lodash/times'), require('lodash/transform'), require('lodash/merge'), require('lodash/flattenDeep'), require('lodash/uniq'), require('json-schema-merge-allof'), require('jsonpointer'), require('lodash/omit'), require('lodash/isObject'), require('lodash/isEmpty'), require('fast-uri'), require('lodash/isString'), require('lodash/union'), require('lodash/isNumber'), require('lodash/reduce'), require('lodash/isNil'), require('lodash/cloneDeep'), require('lodash/setWith'), require('nanoid'), require('react'), require('react-is'), require('react/jsx-runtime'), require('lodash/toPath'), require('lodash/keys'), require('lodash/pickBy'), require('lodash/difference'), require('lodash/forEach')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'lodash/isPlainObject', 'lodash/isEqualWith', 'lodash/get', 'lodash/has', 'lodash/isEqual', 'lodash/set', 'lodash/times', 'lodash/transform', 'lodash/merge', 'lodash/flattenDeep', 'lodash/uniq', 'json-schema-merge-allof', 'jsonpointer', 'lodash/omit', 'lodash/isObject', 'lodash/isEmpty', 'fast-uri', 'lodash/isString', 'lodash/union', 'lodash/isNumber', 'lodash/reduce', 'lodash/isNil', 'lodash/cloneDeep', 'lodash/setWith', 'nanoid', 'react', 'react-is', 'react/jsx-runtime', 'lodash/toPath', 'lodash/keys', 'lodash/pickBy', 'lodash/difference', 'lodash/forEach'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@rjsf/utils"] = {}, global.isPlainObject4, global.isEqualWith, global.get13, global.has5, global.isEqual, global.set, global.times, global.transform, global.merge, global.flattenDeep, global.uniq, global.mergeAllOf, global.jsonpointer, global.omit, global.isObject3, global.isEmpty2, global.UriResolver, global.isString, global.union, global.isNumber, global.reduce, global.isNil, global.cloneDeep, global.setWith, global.nanoid, global.react, global.ReactIs, global.jsxRuntime, global.toPath, global.keys, global.pickBy, global.difference, global.forEach));
|
|
5
|
+
})(this, (function (exports, isPlainObject4, isEqualWith, get13, has5, isEqual, set, times, transform, merge, flattenDeep, uniq, mergeAllOf, jsonpointer, omit, isObject3, isEmpty2, UriResolver, isString, union, isNumber, reduce, isNil, cloneDeep, setWith, nanoid, react, ReactIs, jsxRuntime, toPath, keys, pickBy, difference, forEach) { 'use strict';
|
|
6
6
|
|
|
7
7
|
// src/isObject.ts
|
|
8
8
|
function isObject(thing) {
|
|
@@ -71,6 +71,7 @@
|
|
|
71
71
|
var REQUIRED_KEY = "required";
|
|
72
72
|
var SUBMIT_BTN_OPTIONS_KEY = "submitButtonOptions";
|
|
73
73
|
var REF_KEY = "$ref";
|
|
74
|
+
var SCHEMA_KEY = "$schema";
|
|
74
75
|
var DISCRIMINATOR_PATH = ["discriminator", "propertyName"];
|
|
75
76
|
var FORM_CONTEXT_NAME = "formContext";
|
|
76
77
|
var LOOKUP_MAP_NAME = "layoutGridLookupMap";
|
|
@@ -80,6 +81,7 @@
|
|
|
80
81
|
var UI_WIDGET_KEY = "ui:widget";
|
|
81
82
|
var UI_OPTIONS_KEY = "ui:options";
|
|
82
83
|
var UI_GLOBAL_OPTIONS_KEY = "ui:globalOptions";
|
|
84
|
+
var JSON_SCHEMA_DRAFT_2020_12 = "https://json-schema.org/draft/2020-12/schema";
|
|
83
85
|
|
|
84
86
|
// src/getUiOptions.ts
|
|
85
87
|
function getUiOptions(uiSchema = {}, globalOptions = {}) {
|
|
@@ -144,20 +146,49 @@
|
|
|
144
146
|
return void 0;
|
|
145
147
|
});
|
|
146
148
|
}
|
|
149
|
+
function findEmbeddedSchemaRecursive(schema, ref) {
|
|
150
|
+
if (ID_KEY in schema && UriResolver.equal(schema[ID_KEY], ref)) {
|
|
151
|
+
return schema;
|
|
152
|
+
}
|
|
153
|
+
for (const subSchema of Object.values(schema)) {
|
|
154
|
+
if (isObject3(subSchema)) {
|
|
155
|
+
const result = findEmbeddedSchemaRecursive(subSchema, ref);
|
|
156
|
+
if (result !== void 0) {
|
|
157
|
+
return result;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return void 0;
|
|
162
|
+
}
|
|
147
163
|
function splitKeyElementFromObject(key, object) {
|
|
148
164
|
const value = object[key];
|
|
149
165
|
const remaining = omit(object, [key]);
|
|
150
166
|
return [remaining, value];
|
|
151
167
|
}
|
|
152
|
-
function findSchemaDefinitionRecursive($ref, rootSchema = {}, recurseList = []) {
|
|
168
|
+
function findSchemaDefinitionRecursive($ref, rootSchema = {}, recurseList = [], baseURI = get13(rootSchema, [ID_KEY])) {
|
|
153
169
|
const ref = $ref || "";
|
|
154
|
-
let
|
|
170
|
+
let current = void 0;
|
|
155
171
|
if (ref.startsWith("#")) {
|
|
156
|
-
decodedRef = decodeURIComponent(ref.substring(1));
|
|
157
|
-
|
|
158
|
-
|
|
172
|
+
const decodedRef = decodeURIComponent(ref.substring(1));
|
|
173
|
+
if (baseURI === void 0 || ID_KEY in rootSchema && rootSchema[ID_KEY] === baseURI) {
|
|
174
|
+
current = jsonpointer.get(rootSchema, decodedRef);
|
|
175
|
+
} else if (rootSchema[SCHEMA_KEY] === JSON_SCHEMA_DRAFT_2020_12) {
|
|
176
|
+
current = findEmbeddedSchemaRecursive(rootSchema, baseURI.replace(/\/$/, ""));
|
|
177
|
+
if (current !== void 0) {
|
|
178
|
+
current = jsonpointer.get(current, decodedRef);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
} else if (rootSchema[SCHEMA_KEY] === JSON_SCHEMA_DRAFT_2020_12) {
|
|
182
|
+
const resolvedRef = baseURI ? UriResolver.resolve(baseURI, ref) : ref;
|
|
183
|
+
const [refId, ...refAnchor] = resolvedRef.replace(/#\/?$/, "").split("#");
|
|
184
|
+
current = findEmbeddedSchemaRecursive(rootSchema, refId.replace(/\/$/, ""));
|
|
185
|
+
if (current !== void 0) {
|
|
186
|
+
baseURI = current[ID_KEY];
|
|
187
|
+
if (!isEmpty2(refAnchor)) {
|
|
188
|
+
current = jsonpointer.get(current, decodeURIComponent(refAnchor.join("#")));
|
|
189
|
+
}
|
|
190
|
+
}
|
|
159
191
|
}
|
|
160
|
-
const current = jsonpointer.get(rootSchema, decodedRef);
|
|
161
192
|
if (current === void 0) {
|
|
162
193
|
throw new Error(`Could not find a definition for ${$ref}.`);
|
|
163
194
|
}
|
|
@@ -172,7 +203,7 @@
|
|
|
172
203
|
throw new Error(`Definition for ${firstRef} contains a circular reference through ${circularPath}`);
|
|
173
204
|
}
|
|
174
205
|
const [remaining, theRef] = splitKeyElementFromObject(REF_KEY, current);
|
|
175
|
-
const subSchema = findSchemaDefinitionRecursive(theRef, rootSchema, [...recurseList, ref]);
|
|
206
|
+
const subSchema = findSchemaDefinitionRecursive(theRef, rootSchema, [...recurseList, ref], baseURI);
|
|
176
207
|
if (Object.keys(remaining).length > 0) {
|
|
177
208
|
return { ...remaining, ...subSchema };
|
|
178
209
|
}
|
|
@@ -180,13 +211,13 @@
|
|
|
180
211
|
}
|
|
181
212
|
return current;
|
|
182
213
|
}
|
|
183
|
-
function findSchemaDefinition($ref, rootSchema = {}) {
|
|
214
|
+
function findSchemaDefinition($ref, rootSchema = {}, baseURI = get13(rootSchema, [ID_KEY])) {
|
|
184
215
|
const recurseList = [];
|
|
185
|
-
return findSchemaDefinitionRecursive($ref, rootSchema, recurseList);
|
|
216
|
+
return findSchemaDefinitionRecursive($ref, rootSchema, recurseList, baseURI);
|
|
186
217
|
}
|
|
187
218
|
function getDiscriminatorFieldFromSchema(schema) {
|
|
188
219
|
let discriminator;
|
|
189
|
-
const maybeString =
|
|
220
|
+
const maybeString = get13(schema, DISCRIMINATOR_PATH);
|
|
190
221
|
if (isString(maybeString)) {
|
|
191
222
|
discriminator = maybeString;
|
|
192
223
|
} else if (maybeString !== void 0) {
|
|
@@ -257,13 +288,13 @@
|
|
|
257
288
|
}
|
|
258
289
|
function getOptionMatchingSimpleDiscriminator(formData, options, discriminatorField) {
|
|
259
290
|
if (formData && discriminatorField) {
|
|
260
|
-
const value =
|
|
291
|
+
const value = get13(formData, discriminatorField);
|
|
261
292
|
if (value === void 0) {
|
|
262
293
|
return;
|
|
263
294
|
}
|
|
264
295
|
for (let i = 0; i < options.length; i++) {
|
|
265
296
|
const option = options[i];
|
|
266
|
-
const discriminator =
|
|
297
|
+
const discriminator = get13(option, [PROPERTIES_KEY, discriminatorField], {});
|
|
267
298
|
if (discriminator.type === "object" || discriminator.type === "array") {
|
|
268
299
|
continue;
|
|
269
300
|
}
|
|
@@ -290,8 +321,8 @@
|
|
|
290
321
|
for (let i = 0; i < options.length; i++) {
|
|
291
322
|
const option = options[i];
|
|
292
323
|
if (discriminatorField && has5(option, [PROPERTIES_KEY, discriminatorField])) {
|
|
293
|
-
const value =
|
|
294
|
-
const discriminator =
|
|
324
|
+
const value = get13(formData, discriminatorField);
|
|
325
|
+
const discriminator = get13(option, [PROPERTIES_KEY, discriminatorField], {});
|
|
295
326
|
if (validator.isValid(discriminator, value, rootSchema)) {
|
|
296
327
|
return i;
|
|
297
328
|
}
|
|
@@ -489,7 +520,7 @@
|
|
|
489
520
|
}
|
|
490
521
|
return [schema];
|
|
491
522
|
}
|
|
492
|
-
function resolveAllReferences(schema, rootSchema, recurseList) {
|
|
523
|
+
function resolveAllReferences(schema, rootSchema, recurseList, baseURI) {
|
|
493
524
|
if (!isObject(schema)) {
|
|
494
525
|
return schema;
|
|
495
526
|
}
|
|
@@ -500,8 +531,11 @@
|
|
|
500
531
|
return resolvedSchema;
|
|
501
532
|
}
|
|
502
533
|
recurseList.push($ref);
|
|
503
|
-
const refSchema = findSchemaDefinition($ref, rootSchema);
|
|
534
|
+
const refSchema = findSchemaDefinition($ref, rootSchema, baseURI);
|
|
504
535
|
resolvedSchema = { ...refSchema, ...localSchema };
|
|
536
|
+
if (ID_KEY in resolvedSchema) {
|
|
537
|
+
baseURI = resolvedSchema[ID_KEY];
|
|
538
|
+
}
|
|
505
539
|
}
|
|
506
540
|
if (PROPERTIES_KEY in resolvedSchema) {
|
|
507
541
|
const childrenLists = [];
|
|
@@ -509,7 +543,7 @@
|
|
|
509
543
|
resolvedSchema[PROPERTIES_KEY],
|
|
510
544
|
(result, value, key) => {
|
|
511
545
|
const childList = [...recurseList];
|
|
512
|
-
result[key] = resolveAllReferences(value, rootSchema, childList);
|
|
546
|
+
result[key] = resolveAllReferences(value, rootSchema, childList, baseURI);
|
|
513
547
|
childrenLists.push(childList);
|
|
514
548
|
},
|
|
515
549
|
{}
|
|
@@ -520,7 +554,7 @@
|
|
|
520
554
|
if (ITEMS_KEY in resolvedSchema && !Array.isArray(resolvedSchema.items) && typeof resolvedSchema.items !== "boolean") {
|
|
521
555
|
resolvedSchema = {
|
|
522
556
|
...resolvedSchema,
|
|
523
|
-
items: resolveAllReferences(resolvedSchema.items, rootSchema, recurseList)
|
|
557
|
+
items: resolveAllReferences(resolvedSchema.items, rootSchema, recurseList, baseURI)
|
|
524
558
|
};
|
|
525
559
|
}
|
|
526
560
|
return deepEquals(schema, resolvedSchema) ? schema : resolvedSchema;
|
|
@@ -537,12 +571,12 @@
|
|
|
537
571
|
}
|
|
538
572
|
if (PATTERN_PROPERTIES_KEY in schema) {
|
|
539
573
|
const matchingProperties = getMatchingPatternProperties(schema, key);
|
|
540
|
-
if (!
|
|
574
|
+
if (!isEmpty2(matchingProperties)) {
|
|
541
575
|
schema.properties[key] = retrieveSchema(
|
|
542
576
|
validator,
|
|
543
577
|
{ allOf: Object.values(matchingProperties) },
|
|
544
578
|
rootSchema,
|
|
545
|
-
formData,
|
|
579
|
+
get13(formData, [key]),
|
|
546
580
|
experimental_customMergeAllOf
|
|
547
581
|
);
|
|
548
582
|
set(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
|
|
@@ -555,7 +589,7 @@
|
|
|
555
589
|
if (REF_KEY in schema.additionalProperties) {
|
|
556
590
|
additionalProperties = retrieveSchema(
|
|
557
591
|
validator,
|
|
558
|
-
{ $ref:
|
|
592
|
+
{ $ref: get13(schema.additionalProperties, [REF_KEY]) },
|
|
559
593
|
rootSchema,
|
|
560
594
|
formData,
|
|
561
595
|
experimental_customMergeAllOf
|
|
@@ -568,10 +602,10 @@
|
|
|
568
602
|
...schema.additionalProperties
|
|
569
603
|
};
|
|
570
604
|
} else {
|
|
571
|
-
additionalProperties = { type: guessType(
|
|
605
|
+
additionalProperties = { type: guessType(get13(formData, [key])) };
|
|
572
606
|
}
|
|
573
607
|
} else {
|
|
574
|
-
additionalProperties = { type: guessType(
|
|
608
|
+
additionalProperties = { type: guessType(get13(formData, [key])) };
|
|
575
609
|
}
|
|
576
610
|
schema.properties[key] = additionalProperties;
|
|
577
611
|
set(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
|
|
@@ -627,7 +661,10 @@
|
|
|
627
661
|
resolvedSchema = { ...resolvedSchema, allOf: withoutContainsSchemas };
|
|
628
662
|
}
|
|
629
663
|
resolvedSchema = experimental_customMergeAllOf ? experimental_customMergeAllOf(resolvedSchema) : mergeAllOf(resolvedSchema, {
|
|
630
|
-
deep: false
|
|
664
|
+
deep: false,
|
|
665
|
+
resolvers: {
|
|
666
|
+
$defs: mergeAllOf.options.resolvers.definitions
|
|
667
|
+
}
|
|
631
668
|
});
|
|
632
669
|
if (withContainsSchemas.length) {
|
|
633
670
|
resolvedSchema.allOf = withContainsSchemas;
|
|
@@ -642,12 +679,12 @@
|
|
|
642
679
|
resolvedSchema = Object.keys(resolvedSchema.properties).reduce(
|
|
643
680
|
(schema2, key) => {
|
|
644
681
|
const matchingProperties = getMatchingPatternProperties(schema2, key);
|
|
645
|
-
if (!
|
|
682
|
+
if (!isEmpty2(matchingProperties)) {
|
|
646
683
|
schema2.properties[key] = retrieveSchema(
|
|
647
684
|
validator,
|
|
648
685
|
{ allOf: [schema2.properties[key], ...Object.values(matchingProperties)] },
|
|
649
686
|
rootSchema,
|
|
650
|
-
rawFormData,
|
|
687
|
+
get13(rawFormData, [key]),
|
|
651
688
|
experimental_customMergeAllOf
|
|
652
689
|
);
|
|
653
690
|
}
|
|
@@ -719,7 +756,7 @@
|
|
|
719
756
|
function processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
720
757
|
let schemas = [resolvedSchema];
|
|
721
758
|
for (const dependencyKey in dependencies) {
|
|
722
|
-
if (!expandAllBranches &&
|
|
759
|
+
if (!expandAllBranches && get13(formData, [dependencyKey]) === void 0) {
|
|
723
760
|
continue;
|
|
724
761
|
}
|
|
725
762
|
if (resolvedSchema.properties && !(dependencyKey in resolvedSchema.properties)) {
|
|
@@ -850,11 +887,11 @@
|
|
|
850
887
|
const xxxOfs = schema[xxx].map(
|
|
851
888
|
(xxxOf) => retrieveSchema(validator, xxxOf, rootSchema, formData, experimental_customMergeAllOf)
|
|
852
889
|
);
|
|
853
|
-
const data =
|
|
890
|
+
const data = get13(formData, selectorField);
|
|
854
891
|
if (data !== void 0) {
|
|
855
892
|
return xxxOfs.find((xxx2) => {
|
|
856
893
|
return isEqual(
|
|
857
|
-
|
|
894
|
+
get13(xxx2, [PROPERTIES_KEY, selectorField, DEFAULT_KEY], get13(xxx2, [PROPERTIES_KEY, selectorField, CONST_KEY])),
|
|
858
895
|
data
|
|
859
896
|
);
|
|
860
897
|
});
|
|
@@ -867,13 +904,13 @@
|
|
|
867
904
|
if (has5(schema, REF_KEY)) {
|
|
868
905
|
fieldSchema = retrieveSchema(validator, schema, rootSchema, void 0, experimental_customMergeAllOf);
|
|
869
906
|
}
|
|
870
|
-
if (
|
|
907
|
+
if (isEmpty2(path)) {
|
|
871
908
|
return fieldSchema;
|
|
872
909
|
}
|
|
873
910
|
const pathList = Array.isArray(path) ? path : path.split(".");
|
|
874
911
|
const [part, ...nestedPath] = pathList;
|
|
875
912
|
if (part && has5(fieldSchema, part)) {
|
|
876
|
-
fieldSchema =
|
|
913
|
+
fieldSchema = get13(fieldSchema, part);
|
|
877
914
|
return getFromSchemaInternal(
|
|
878
915
|
validator,
|
|
879
916
|
rootSchema,
|
|
@@ -915,7 +952,7 @@
|
|
|
915
952
|
parentField,
|
|
916
953
|
fieldName,
|
|
917
954
|
ONE_OF_KEY,
|
|
918
|
-
|
|
955
|
+
get13(formData, subPath),
|
|
919
956
|
experimental_customMergeAllOf
|
|
920
957
|
);
|
|
921
958
|
} else if (has5(parentField, ANY_OF_KEY)) {
|
|
@@ -925,7 +962,7 @@
|
|
|
925
962
|
parentField,
|
|
926
963
|
fieldName,
|
|
927
964
|
ANY_OF_KEY,
|
|
928
|
-
|
|
965
|
+
get13(formData, subPath),
|
|
929
966
|
experimental_customMergeAllOf
|
|
930
967
|
);
|
|
931
968
|
}
|
|
@@ -989,11 +1026,11 @@
|
|
|
989
1026
|
function calculateIndexScore(validator, rootSchema, schema, formData, experimental_customMergeAllOf) {
|
|
990
1027
|
let totalScore = 0;
|
|
991
1028
|
if (schema) {
|
|
992
|
-
if (
|
|
1029
|
+
if (isObject3(schema.properties)) {
|
|
993
1030
|
totalScore += reduce(
|
|
994
1031
|
schema.properties,
|
|
995
1032
|
(score, value, key) => {
|
|
996
|
-
const formValue =
|
|
1033
|
+
const formValue = get13(formData, key);
|
|
997
1034
|
if (typeof value === "boolean") {
|
|
998
1035
|
return score;
|
|
999
1036
|
}
|
|
@@ -1020,14 +1057,14 @@
|
|
|
1020
1057
|
validator,
|
|
1021
1058
|
rootSchema,
|
|
1022
1059
|
formValue,
|
|
1023
|
-
|
|
1060
|
+
get13(value, key2),
|
|
1024
1061
|
-1,
|
|
1025
1062
|
discriminator,
|
|
1026
1063
|
experimental_customMergeAllOf
|
|
1027
1064
|
);
|
|
1028
1065
|
}
|
|
1029
1066
|
if (value.type === "object") {
|
|
1030
|
-
if (
|
|
1067
|
+
if (isObject3(formValue)) {
|
|
1031
1068
|
score += 1;
|
|
1032
1069
|
}
|
|
1033
1070
|
return score + calculateIndexScore(validator, rootSchema, value, formValue, experimental_customMergeAllOf);
|
|
@@ -1122,11 +1159,11 @@
|
|
|
1122
1159
|
if (isObject(formData)) {
|
|
1123
1160
|
const acc = Object.assign({}, defaults);
|
|
1124
1161
|
return Object.keys(formData).reduce((acc2, key) => {
|
|
1125
|
-
const keyValue =
|
|
1162
|
+
const keyValue = get13(formData, key);
|
|
1126
1163
|
const keyExistsInDefaults = isObject(defaults) && key in defaults;
|
|
1127
1164
|
const keyExistsInFormData = key in formData;
|
|
1128
1165
|
acc2[key] = mergeDefaultsWithFormData(
|
|
1129
|
-
defaults ?
|
|
1166
|
+
defaults ? get13(defaults, key) : {},
|
|
1130
1167
|
keyValue,
|
|
1131
1168
|
mergeExtraArrayDefaults,
|
|
1132
1169
|
defaultSupercedesUndefined,
|
|
@@ -1245,8 +1282,8 @@
|
|
|
1245
1282
|
let value;
|
|
1246
1283
|
let label = title;
|
|
1247
1284
|
if (selectorField) {
|
|
1248
|
-
const innerSchema =
|
|
1249
|
-
value =
|
|
1285
|
+
const innerSchema = get13(aSchema, [PROPERTIES_KEY, selectorField], {});
|
|
1286
|
+
value = get13(innerSchema, DEFAULT_KEY, get13(innerSchema, CONST_KEY));
|
|
1250
1287
|
label = label || innerSchema?.title || aSchema.title || String(value);
|
|
1251
1288
|
} else {
|
|
1252
1289
|
value = toConstant(aSchema);
|
|
@@ -1286,10 +1323,10 @@
|
|
|
1286
1323
|
const isSelfOrParentRequired = isParentRequired === void 0 ? requiredFields.includes(key) : isParentRequired;
|
|
1287
1324
|
if (isObject(computedDefault)) {
|
|
1288
1325
|
if (emptyObjectFields === "skipEmptyDefaults") {
|
|
1289
|
-
if (!
|
|
1326
|
+
if (!isEmpty2(computedDefault)) {
|
|
1290
1327
|
obj[key] = computedDefault;
|
|
1291
1328
|
}
|
|
1292
|
-
} else if ((!
|
|
1329
|
+
} else if ((!isEmpty2(computedDefault) || requiredFields.includes(key)) && (isSelfOrParentRequired || emptyObjectFields !== "populateRequiredDefaults")) {
|
|
1293
1330
|
obj[key] = computedDefault;
|
|
1294
1331
|
}
|
|
1295
1332
|
} else if (
|
|
@@ -1315,7 +1352,7 @@
|
|
|
1315
1352
|
required,
|
|
1316
1353
|
shouldMergeDefaultsIntoFormData = false
|
|
1317
1354
|
} = computeDefaultsProps;
|
|
1318
|
-
|
|
1355
|
+
let formData = isObject(rawFormData) ? rawFormData : {};
|
|
1319
1356
|
const schema = isObject(rawSchema) ? rawSchema : {};
|
|
1320
1357
|
let defaults = parentDefaults;
|
|
1321
1358
|
let schemaToCompute = null;
|
|
@@ -1325,7 +1362,7 @@
|
|
|
1325
1362
|
defaults = schema[CONST_KEY];
|
|
1326
1363
|
} else if (isObject(defaults) && isObject(schema.default)) {
|
|
1327
1364
|
defaults = mergeObjects(defaults, schema.default);
|
|
1328
|
-
} else if (DEFAULT_KEY in schema && !schema[ANY_OF_KEY] && !schema[ONE_OF_KEY]) {
|
|
1365
|
+
} else if (DEFAULT_KEY in schema && !schema[ANY_OF_KEY] && !schema[ONE_OF_KEY] && !schema[REF_KEY]) {
|
|
1329
1366
|
defaults = schema.default;
|
|
1330
1367
|
} else if (REF_KEY in schema) {
|
|
1331
1368
|
const refName = schema[REF_KEY];
|
|
@@ -1333,6 +1370,12 @@
|
|
|
1333
1370
|
updatedRecurseList = _recurseList.concat(refName);
|
|
1334
1371
|
schemaToCompute = findSchemaDefinition(refName, rootSchema);
|
|
1335
1372
|
}
|
|
1373
|
+
if (schemaToCompute && !defaults) {
|
|
1374
|
+
defaults = schema.default;
|
|
1375
|
+
}
|
|
1376
|
+
if (shouldMergeDefaultsIntoFormData && schemaToCompute && !isObject(rawFormData)) {
|
|
1377
|
+
formData = rawFormData;
|
|
1378
|
+
}
|
|
1336
1379
|
} else if (DEPENDENCIES_KEY in schema) {
|
|
1337
1380
|
const defaultFormData = {
|
|
1338
1381
|
...getDefaultBasedOnSchemaType(validator, schema, computeDefaultsProps, defaults),
|
|
@@ -1473,7 +1516,7 @@
|
|
|
1473
1516
|
const parentConst = retrievedSchema[CONST_KEY];
|
|
1474
1517
|
const objectDefaults = Object.keys(retrievedSchema.properties || {}).reduce(
|
|
1475
1518
|
(acc, key) => {
|
|
1476
|
-
const propertySchema =
|
|
1519
|
+
const propertySchema = get13(retrievedSchema, [PROPERTIES_KEY, key], {});
|
|
1477
1520
|
const hasParentConst = isObject(parentConst) && parentConst[key] !== void 0;
|
|
1478
1521
|
const hasConst = (isObject(propertySchema) && CONST_KEY in propertySchema || hasParentConst) && experimental_defaultFormStateBehavior?.constAsDefaults !== "never" && !constIsAjvDataReference(propertySchema);
|
|
1479
1522
|
const computedDefault = computeDefaults(validator, propertySchema, {
|
|
@@ -1482,8 +1525,8 @@
|
|
|
1482
1525
|
experimental_defaultFormStateBehavior,
|
|
1483
1526
|
experimental_customMergeAllOf,
|
|
1484
1527
|
includeUndefinedValues: includeUndefinedValues === true,
|
|
1485
|
-
parentDefaults:
|
|
1486
|
-
rawFormData:
|
|
1528
|
+
parentDefaults: get13(defaults, [key]),
|
|
1529
|
+
rawFormData: get13(formData, [key]),
|
|
1487
1530
|
required: retrievedSchema.required?.includes(key),
|
|
1488
1531
|
shouldMergeDefaultsIntoFormData
|
|
1489
1532
|
});
|
|
@@ -1519,8 +1562,8 @@
|
|
|
1519
1562
|
experimental_defaultFormStateBehavior,
|
|
1520
1563
|
experimental_customMergeAllOf,
|
|
1521
1564
|
includeUndefinedValues: includeUndefinedValues === true,
|
|
1522
|
-
parentDefaults:
|
|
1523
|
-
rawFormData:
|
|
1565
|
+
parentDefaults: get13(defaults, [key]),
|
|
1566
|
+
rawFormData: get13(formData, [key]),
|
|
1524
1567
|
required: retrievedSchema.required?.includes(key),
|
|
1525
1568
|
shouldMergeDefaultsIntoFormData
|
|
1526
1569
|
});
|
|
@@ -1581,7 +1624,7 @@
|
|
|
1581
1624
|
experimental_defaultFormStateBehavior,
|
|
1582
1625
|
experimental_customMergeAllOf,
|
|
1583
1626
|
rawFormData: item,
|
|
1584
|
-
parentDefaults:
|
|
1627
|
+
parentDefaults: get13(defaults, [idx]),
|
|
1585
1628
|
required,
|
|
1586
1629
|
shouldMergeDefaultsIntoFormData
|
|
1587
1630
|
});
|
|
@@ -1713,19 +1756,19 @@
|
|
|
1713
1756
|
if (has5(newSchema, PROPERTIES_KEY)) {
|
|
1714
1757
|
const removeOldSchemaData = {};
|
|
1715
1758
|
if (has5(oldSchema, PROPERTIES_KEY)) {
|
|
1716
|
-
const properties =
|
|
1759
|
+
const properties = get13(oldSchema, PROPERTIES_KEY, {});
|
|
1717
1760
|
Object.keys(properties).forEach((key) => {
|
|
1718
1761
|
if (has5(data, key)) {
|
|
1719
1762
|
removeOldSchemaData[key] = void 0;
|
|
1720
1763
|
}
|
|
1721
1764
|
});
|
|
1722
1765
|
}
|
|
1723
|
-
const keys2 = Object.keys(
|
|
1766
|
+
const keys2 = Object.keys(get13(newSchema, PROPERTIES_KEY, {}));
|
|
1724
1767
|
const nestedData = {};
|
|
1725
1768
|
keys2.forEach((key) => {
|
|
1726
|
-
const formValue =
|
|
1727
|
-
let oldKeyedSchema =
|
|
1728
|
-
let newKeyedSchema =
|
|
1769
|
+
const formValue = get13(data, key);
|
|
1770
|
+
let oldKeyedSchema = get13(oldSchema, [PROPERTIES_KEY, key], {});
|
|
1771
|
+
let newKeyedSchema = get13(newSchema, [PROPERTIES_KEY, key], {});
|
|
1729
1772
|
if (has5(oldKeyedSchema, REF_KEY)) {
|
|
1730
1773
|
oldKeyedSchema = retrieveSchema(
|
|
1731
1774
|
validator,
|
|
@@ -1744,8 +1787,8 @@
|
|
|
1744
1787
|
experimental_customMergeAllOf
|
|
1745
1788
|
);
|
|
1746
1789
|
}
|
|
1747
|
-
const oldSchemaTypeForKey =
|
|
1748
|
-
const newSchemaTypeForKey =
|
|
1790
|
+
const oldSchemaTypeForKey = get13(oldKeyedSchema, "type");
|
|
1791
|
+
const newSchemaTypeForKey = get13(newKeyedSchema, "type");
|
|
1749
1792
|
if (!oldSchemaTypeForKey || oldSchemaTypeForKey === newSchemaTypeForKey) {
|
|
1750
1793
|
if (has5(removeOldSchemaData, key)) {
|
|
1751
1794
|
delete removeOldSchemaData[key];
|
|
@@ -1763,17 +1806,17 @@
|
|
|
1763
1806
|
nestedData[key] = itemData;
|
|
1764
1807
|
}
|
|
1765
1808
|
} else {
|
|
1766
|
-
const newOptionDefault =
|
|
1767
|
-
const oldOptionDefault =
|
|
1809
|
+
const newOptionDefault = get13(newKeyedSchema, "default", NO_VALUE);
|
|
1810
|
+
const oldOptionDefault = get13(oldKeyedSchema, "default", NO_VALUE);
|
|
1768
1811
|
if (newOptionDefault !== NO_VALUE && newOptionDefault !== formValue) {
|
|
1769
1812
|
if (oldOptionDefault === formValue) {
|
|
1770
1813
|
removeOldSchemaData[key] = newOptionDefault;
|
|
1771
|
-
} else if (
|
|
1814
|
+
} else if (get13(newKeyedSchema, "readOnly") === true) {
|
|
1772
1815
|
removeOldSchemaData[key] = void 0;
|
|
1773
1816
|
}
|
|
1774
1817
|
}
|
|
1775
|
-
const newOptionConst =
|
|
1776
|
-
const oldOptionConst =
|
|
1818
|
+
const newOptionConst = get13(newKeyedSchema, "const", NO_VALUE);
|
|
1819
|
+
const oldOptionConst = get13(oldKeyedSchema, "const", NO_VALUE);
|
|
1777
1820
|
if (newOptionConst !== NO_VALUE && newOptionConst !== formValue) {
|
|
1778
1821
|
removeOldSchemaData[key] = oldOptionConst === formValue ? newOptionConst : void 0;
|
|
1779
1822
|
}
|
|
@@ -1785,9 +1828,9 @@
|
|
|
1785
1828
|
...removeOldSchemaData,
|
|
1786
1829
|
...nestedData
|
|
1787
1830
|
};
|
|
1788
|
-
} else if (
|
|
1789
|
-
let oldSchemaItems =
|
|
1790
|
-
let newSchemaItems =
|
|
1831
|
+
} else if (get13(oldSchema, "type") === "array" && get13(newSchema, "type") === "array" && Array.isArray(data)) {
|
|
1832
|
+
let oldSchemaItems = get13(oldSchema, "items");
|
|
1833
|
+
let newSchemaItems = get13(newSchema, "items");
|
|
1791
1834
|
if (typeof oldSchemaItems === "object" && typeof newSchemaItems === "object" && !Array.isArray(oldSchemaItems) && !Array.isArray(newSchemaItems)) {
|
|
1792
1835
|
if (has5(oldSchemaItems, REF_KEY)) {
|
|
1793
1836
|
oldSchemaItems = retrieveSchema(
|
|
@@ -1807,10 +1850,10 @@
|
|
|
1807
1850
|
experimental_customMergeAllOf
|
|
1808
1851
|
);
|
|
1809
1852
|
}
|
|
1810
|
-
const oldSchemaType =
|
|
1811
|
-
const newSchemaType =
|
|
1853
|
+
const oldSchemaType = get13(oldSchemaItems, "type");
|
|
1854
|
+
const newSchemaType = get13(newSchemaItems, "type");
|
|
1812
1855
|
if (!oldSchemaType || oldSchemaType === newSchemaType) {
|
|
1813
|
-
const maxItems =
|
|
1856
|
+
const maxItems = get13(newSchema, "maxItems", -1);
|
|
1814
1857
|
if (newSchemaType === "object") {
|
|
1815
1858
|
newFormData = data.reduce((newValue, aValue) => {
|
|
1816
1859
|
const itemValue = sanitizeDataForNewSchema(
|
|
@@ -1857,10 +1900,10 @@
|
|
|
1857
1900
|
);
|
|
1858
1901
|
}
|
|
1859
1902
|
}
|
|
1860
|
-
if (ITEMS_KEY in schema && !
|
|
1903
|
+
if (ITEMS_KEY in schema && !get13(schema, [ITEMS_KEY, REF_KEY])) {
|
|
1861
1904
|
return toIdSchemaInternal(
|
|
1862
1905
|
validator,
|
|
1863
|
-
|
|
1906
|
+
get13(schema, ITEMS_KEY),
|
|
1864
1907
|
idPrefix,
|
|
1865
1908
|
idSeparator,
|
|
1866
1909
|
id,
|
|
@@ -1883,7 +1926,7 @@
|
|
|
1883
1926
|
rootSchema,
|
|
1884
1927
|
// It's possible that formData is not an object -- this can happen if an
|
|
1885
1928
|
// array item has just been added, but not populated with data yet
|
|
1886
|
-
|
|
1929
|
+
get13(formData, [name]),
|
|
1887
1930
|
_recurseList,
|
|
1888
1931
|
experimental_customMergeAllOf
|
|
1889
1932
|
);
|
|
@@ -1996,7 +2039,7 @@
|
|
|
1996
2039
|
}
|
|
1997
2040
|
} else if (PROPERTIES_KEY in schema) {
|
|
1998
2041
|
for (const property in schema.properties) {
|
|
1999
|
-
const field =
|
|
2042
|
+
const field = get13(schema, [PROPERTIES_KEY, property], {});
|
|
2000
2043
|
pathSchema[property] = toPathSchemaInternal(
|
|
2001
2044
|
validator,
|
|
2002
2045
|
field,
|
|
@@ -2004,7 +2047,7 @@
|
|
|
2004
2047
|
rootSchema,
|
|
2005
2048
|
// It's possible that formData is not an object -- this can happen if an
|
|
2006
2049
|
// array item has just been added, but not populated with data yet
|
|
2007
|
-
|
|
2050
|
+
get13(formData, [property]),
|
|
2008
2051
|
_recurseList,
|
|
2009
2052
|
experimental_customMergeAllOf
|
|
2010
2053
|
);
|
|
@@ -2442,7 +2485,7 @@
|
|
|
2442
2485
|
*/
|
|
2443
2486
|
getOrCreateErrorBlock(pathOfError) {
|
|
2444
2487
|
const hasPath = Array.isArray(pathOfError) && pathOfError.length > 0 || typeof pathOfError === "string";
|
|
2445
|
-
let errorBlock = hasPath ?
|
|
2488
|
+
let errorBlock = hasPath ? get13(this.errorSchema, pathOfError) : this.errorSchema;
|
|
2446
2489
|
if (!errorBlock && pathOfError) {
|
|
2447
2490
|
errorBlock = {};
|
|
2448
2491
|
setWith(this.errorSchema, pathOfError, errorBlock, Object);
|
|
@@ -2468,7 +2511,7 @@
|
|
|
2468
2511
|
*/
|
|
2469
2512
|
addErrors(errorOrList, pathOfError) {
|
|
2470
2513
|
const errorBlock = this.getOrCreateErrorBlock(pathOfError);
|
|
2471
|
-
let errorsList =
|
|
2514
|
+
let errorsList = get13(errorBlock, ERRORS_KEY);
|
|
2472
2515
|
if (!Array.isArray(errorsList)) {
|
|
2473
2516
|
errorsList = [];
|
|
2474
2517
|
errorBlock[ERRORS_KEY] = errorsList;
|
|
@@ -2615,7 +2658,7 @@
|
|
|
2615
2658
|
);
|
|
2616
2659
|
}
|
|
2617
2660
|
function getTestIds() {
|
|
2618
|
-
if (typeof process === "undefined" ||
|
|
2661
|
+
if (typeof process === "undefined" || get13(process, "env.NODE_ENV") !== "test") {
|
|
2619
2662
|
return {};
|
|
2620
2663
|
}
|
|
2621
2664
|
const ids = /* @__PURE__ */ new Map();
|
|
@@ -2684,7 +2727,7 @@
|
|
|
2684
2727
|
}
|
|
2685
2728
|
};
|
|
2686
2729
|
function mergeWidgetOptions(AWidget) {
|
|
2687
|
-
let MergedWidget =
|
|
2730
|
+
let MergedWidget = get13(AWidget, "MergedWidget");
|
|
2688
2731
|
if (!MergedWidget) {
|
|
2689
2732
|
const defaultOptions = AWidget.defaultProps && AWidget.defaultProps.options || {};
|
|
2690
2733
|
MergedWidget = ({ options, ...props }) => {
|
|
@@ -2797,7 +2840,7 @@
|
|
|
2797
2840
|
if (has5(regOrFc, FORM_CONTEXT_NAME)) {
|
|
2798
2841
|
lookupPath.unshift(FORM_CONTEXT_NAME);
|
|
2799
2842
|
}
|
|
2800
|
-
return
|
|
2843
|
+
return get13(regOrFc, [...lookupPath, toLookup], fallback);
|
|
2801
2844
|
}
|
|
2802
2845
|
|
|
2803
2846
|
// src/orderProperties.ts
|
|
@@ -2972,7 +3015,7 @@
|
|
|
2972
3015
|
const { errors: oldErrors, errorSchema: oldErrorSchema } = validationData;
|
|
2973
3016
|
let errors = toErrorList(additionalErrorSchema);
|
|
2974
3017
|
let errorSchema = additionalErrorSchema;
|
|
2975
|
-
if (!
|
|
3018
|
+
if (!isEmpty2(oldErrorSchema)) {
|
|
2976
3019
|
errorSchema = mergeObjects(oldErrorSchema, additionalErrorSchema, true);
|
|
2977
3020
|
errors = [...oldErrors].concat(errors);
|
|
2978
3021
|
}
|
|
@@ -3000,7 +3043,7 @@
|
|
|
3000
3043
|
if (Array.isArray(schemaNode)) {
|
|
3001
3044
|
return withIdRefPrefixArray([...schemaNode]);
|
|
3002
3045
|
}
|
|
3003
|
-
if (
|
|
3046
|
+
if (isObject3(schemaNode)) {
|
|
3004
3047
|
return withIdRefPrefixObject({ ...schemaNode });
|
|
3005
3048
|
}
|
|
3006
3049
|
return schemaNode;
|
|
@@ -3016,7 +3059,7 @@
|
|
|
3016
3059
|
} else if (!aIsPlainObject && bIsPlainObject) {
|
|
3017
3060
|
return keys(b);
|
|
3018
3061
|
} else {
|
|
3019
|
-
const unequalFields = keys(pickBy(a, (value, key) => !deepEquals(value,
|
|
3062
|
+
const unequalFields = keys(pickBy(a, (value, key) => !deepEquals(value, get13(b, key))));
|
|
3020
3063
|
const diffFields = difference(keys(b), keys(a));
|
|
3021
3064
|
return [...unequalFields, ...diffFields];
|
|
3022
3065
|
}
|
|
@@ -3081,7 +3124,7 @@
|
|
|
3081
3124
|
* @param hash - The hash value at which to map the schema
|
|
3082
3125
|
*/
|
|
3083
3126
|
addSchema(schema, hash) {
|
|
3084
|
-
const key =
|
|
3127
|
+
const key = get13(schema, ID_KEY, hash);
|
|
3085
3128
|
const identifiedSchema = { ...schema, [ID_KEY]: key };
|
|
3086
3129
|
const existing = this.schemaMap[key];
|
|
3087
3130
|
if (!existing) {
|
|
@@ -3188,6 +3231,7 @@
|
|
|
3188
3231
|
exports.ID_KEY = ID_KEY;
|
|
3189
3232
|
exports.IF_KEY = IF_KEY;
|
|
3190
3233
|
exports.ITEMS_KEY = ITEMS_KEY;
|
|
3234
|
+
exports.JSON_SCHEMA_DRAFT_2020_12 = JSON_SCHEMA_DRAFT_2020_12;
|
|
3191
3235
|
exports.JUNK_OPTION_ID = JUNK_OPTION_ID;
|
|
3192
3236
|
exports.LOOKUP_MAP_NAME = LOOKUP_MAP_NAME;
|
|
3193
3237
|
exports.NAME_KEY = NAME_KEY;
|
|
@@ -3199,6 +3243,7 @@
|
|
|
3199
3243
|
exports.REQUIRED_KEY = REQUIRED_KEY;
|
|
3200
3244
|
exports.RJSF_ADDITIONAL_PROPERTIES_FLAG = RJSF_ADDITIONAL_PROPERTIES_FLAG;
|
|
3201
3245
|
exports.ROOT_SCHEMA_PREFIX = ROOT_SCHEMA_PREFIX;
|
|
3246
|
+
exports.SCHEMA_KEY = SCHEMA_KEY;
|
|
3202
3247
|
exports.SUBMIT_BTN_OPTIONS_KEY = SUBMIT_BTN_OPTIONS_KEY;
|
|
3203
3248
|
exports.TranslatableString = TranslatableString;
|
|
3204
3249
|
exports.UI_FIELD_KEY = UI_FIELD_KEY;
|
package/lib/canExpand.d.ts
CHANGED
|
@@ -8,4 +8,4 @@ import { FormContextType, RJSFSchema, StrictRJSFSchema, UiSchema } from './types
|
|
|
8
8
|
* @param [formData] - The formData for the field
|
|
9
9
|
* @returns - True if the schema element has additionalProperties, is expandable, and not at the maxProperties limit
|
|
10
10
|
*/
|
|
11
|
-
export default function canExpand<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(schema: RJSFSchema, uiSchema?: UiSchema<T, S, F>, formData?: T):
|
|
11
|
+
export default function canExpand<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(schema: RJSFSchema, uiSchema?: UiSchema<T, S, F>, formData?: T): any;
|