@rjsf/utils 6.5.3 → 6.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +618 -433
- package/dist/index.cjs.map +4 -4
- package/dist/utils.esm.js +614 -429
- package/dist/utils.esm.js.map +4 -4
- package/dist/utils.umd.js +623 -438
- package/lib/ErrorSchemaBuilder.js.map +1 -1
- package/lib/canExpand.js.map +1 -1
- package/lib/constIsAjvDataReference.js +1 -1
- package/lib/constIsAjvDataReference.js.map +1 -1
- package/lib/createSchemaUtils.js +3 -3
- package/lib/createSchemaUtils.js.map +1 -1
- package/lib/enumOptionSelectedValue.js.map +1 -1
- package/lib/enumOptionValueDecoder.js.map +1 -1
- package/lib/enumOptionsDeselectValue.js +1 -1
- package/lib/enumOptionsDeselectValue.js.map +1 -1
- package/lib/enumOptionsIndexForValue.js.map +1 -1
- package/lib/enumOptionsIsSelected.js.map +1 -1
- package/lib/enumOptionsSelectValue.js +1 -1
- package/lib/enumOptionsSelectValue.js.map +1 -1
- package/lib/enumOptionsValueForIndex.js +2 -2
- package/lib/enumOptionsValueForIndex.js.map +1 -1
- package/lib/findSchemaDefinition.js +4 -4
- package/lib/findSchemaDefinition.js.map +1 -1
- package/lib/getChangedFields.js +3 -3
- package/lib/getChangedFields.js.map +1 -1
- package/lib/getDiscriminatorFieldFromSchema.js.map +1 -1
- package/lib/getOptionMatchingSimpleDiscriminator.js.map +1 -1
- package/lib/getTestIds.d.ts +1 -1
- package/lib/getTestIds.js +4 -3
- package/lib/getTestIds.js.map +1 -1
- package/lib/getWidget.js +1 -1
- package/lib/getWidget.js.map +1 -1
- package/lib/idGenerators.js.map +1 -1
- package/lib/index.d.ts +6 -6
- package/lib/index.js +6 -6
- package/lib/index.js.map +1 -1
- package/lib/isFormDataAvailable.js +1 -1
- package/lib/isFormDataAvailable.js.map +1 -1
- package/lib/isRootSchema.js +1 -1
- package/lib/isRootSchema.js.map +1 -1
- package/lib/mergeDefaultsWithFormData.js +1 -1
- package/lib/mergeDefaultsWithFormData.js.map +1 -1
- package/lib/parser/ParserValidator.js +1 -1
- package/lib/parser/ParserValidator.js.map +1 -1
- package/lib/parser/index.d.ts +1 -1
- package/lib/parser/index.js.map +1 -1
- package/lib/parser/schemaParser.js +2 -2
- package/lib/parser/schemaParser.js.map +1 -1
- package/lib/removeOptionalEmptyObjects.d.ts +2 -0
- package/lib/removeOptionalEmptyObjects.js +8 -29
- package/lib/removeOptionalEmptyObjects.js.map +1 -1
- package/lib/schema/findFieldInSchema.js +1 -1
- package/lib/schema/findFieldInSchema.js.map +1 -1
- package/lib/schema/findSelectedOptionInXxxOf.js +1 -1
- package/lib/schema/findSelectedOptionInXxxOf.js.map +1 -1
- package/lib/schema/getClosestMatchingOption.js +3 -3
- package/lib/schema/getClosestMatchingOption.js.map +1 -1
- package/lib/schema/getDefaultFormState.d.ts +4 -4
- package/lib/schema/getDefaultFormState.js +17 -22
- package/lib/schema/getDefaultFormState.js.map +1 -1
- package/lib/schema/getFromSchema.js +1 -1
- package/lib/schema/getFromSchema.js.map +1 -1
- package/lib/schema/index.d.ts +4 -4
- package/lib/schema/index.js +4 -4
- package/lib/schema/index.js.map +1 -1
- package/lib/schema/isMultiSelect.js.map +1 -1
- package/lib/schema/omitExtraData.d.ts +18 -8
- package/lib/schema/omitExtraData.js +352 -16
- package/lib/schema/omitExtraData.js.map +1 -1
- package/lib/schema/retrieveSchema.d.ts +15 -0
- package/lib/schema/retrieveSchema.js +36 -13
- package/lib/schema/retrieveSchema.js.map +1 -1
- package/lib/schema/sanitizeDataForNewSchema.js.map +1 -1
- package/lib/schema/shallowAllOfMerge.d.ts +11 -0
- package/lib/schema/shallowAllOfMerge.js +18 -0
- package/lib/schema/shallowAllOfMerge.js.map +1 -0
- package/lib/schema/toPathSchema.d.ts +1 -0
- package/lib/schema/toPathSchema.js +2 -1
- package/lib/schema/toPathSchema.js.map +1 -1
- package/lib/shouldRenderOptionalField.js +1 -1
- package/lib/shouldRenderOptionalField.js.map +1 -1
- package/lib/toErrorSchema.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types.d.ts +4 -1
- package/lib/useFileWidgetProps.d.ts +1 -1
- package/lib/useFileWidgetProps.js +9 -10
- package/lib/useFileWidgetProps.js.map +1 -1
- package/lib/withIdRefPrefix.js +1 -1
- package/lib/withIdRefPrefix.js.map +1 -1
- package/package.json +10 -10
- package/src/ErrorSchemaBuilder.ts +1 -1
- package/src/canExpand.ts +1 -1
- package/src/constIsAjvDataReference.ts +3 -2
- package/src/createSchemaUtils.ts +18 -17
- package/src/enumOptionSelectedValue.ts +1 -1
- package/src/enumOptionValueDecoder.ts +1 -1
- package/src/enumOptionsDeselectValue.ts +2 -2
- package/src/enumOptionsIndexForValue.ts +1 -1
- package/src/enumOptionsIsSelected.ts +1 -1
- package/src/enumOptionsSelectValue.ts +3 -2
- package/src/enumOptionsValueForIndex.ts +2 -2
- package/src/findSchemaDefinition.ts +4 -4
- package/src/getChangedFields.ts +4 -3
- package/src/getDiscriminatorFieldFromSchema.ts +1 -1
- package/src/getOptionMatchingSimpleDiscriminator.ts +1 -0
- package/src/getTestIds.ts +4 -3
- package/src/getWidget.tsx +2 -2
- package/src/idGenerators.ts +1 -1
- package/src/index.ts +6 -6
- package/src/isFormDataAvailable.ts +1 -1
- package/src/isRootSchema.ts +1 -1
- package/src/mergeDefaultsWithFormData.ts +2 -2
- package/src/parser/ParserValidator.ts +1 -1
- package/src/parser/index.ts +1 -1
- package/src/parser/schemaParser.ts +3 -3
- package/src/removeOptionalEmptyObjects.ts +8 -30
- package/src/schema/findFieldInSchema.ts +2 -2
- package/src/schema/findSelectedOptionInXxxOf.ts +1 -1
- package/src/schema/getClosestMatchingOption.ts +4 -4
- package/src/schema/getDefaultFormState.ts +18 -24
- package/src/schema/getFromSchema.ts +2 -2
- package/src/schema/index.ts +5 -3
- package/src/schema/isMultiSelect.ts +0 -1
- package/src/schema/omitExtraData.ts +398 -19
- package/src/schema/retrieveSchema.ts +41 -15
- package/src/schema/sanitizeDataForNewSchema.ts +1 -1
- package/src/schema/shallowAllOfMerge.ts +19 -0
- package/src/schema/toPathSchema.ts +2 -1
- package/src/shouldRenderOptionalField.ts +2 -2
- package/src/toErrorSchema.ts +1 -1
- package/src/tsconfig.json +0 -1
- package/src/types.ts +4 -1
- package/src/useFileWidgetProps.ts +9 -10
- package/src/withIdRefPrefix.ts +2 -1
package/dist/utils.esm.js
CHANGED
|
@@ -144,6 +144,9 @@ function createErrorHandler(formData) {
|
|
|
144
144
|
return handler;
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
+
// src/createSchemaUtils.ts
|
|
148
|
+
import get17 from "lodash/get";
|
|
149
|
+
|
|
147
150
|
// src/deepEquals.ts
|
|
148
151
|
import { createCustomEqual } from "fast-equals";
|
|
149
152
|
var deepEquals = createCustomEqual({
|
|
@@ -156,32 +159,13 @@ var deepEquals = createCustomEqual({
|
|
|
156
159
|
});
|
|
157
160
|
var deepEquals_default = deepEquals;
|
|
158
161
|
|
|
159
|
-
// src/schema/findFieldInSchema.ts
|
|
160
|
-
import get8 from "lodash/get";
|
|
161
|
-
import has3 from "lodash/has";
|
|
162
|
-
|
|
163
|
-
// src/schema/findSelectedOptionInXxxOf.ts
|
|
164
|
-
import get6 from "lodash/get";
|
|
165
|
-
|
|
166
|
-
// src/schema/retrieveSchema.ts
|
|
167
|
-
import get5 from "lodash/get";
|
|
168
|
-
import set from "lodash/set";
|
|
169
|
-
import times from "lodash/times";
|
|
170
|
-
import transform from "lodash/transform";
|
|
171
|
-
import merge from "lodash/merge";
|
|
172
|
-
import flattenDeep from "lodash/flattenDeep";
|
|
173
|
-
import uniq from "lodash/uniq";
|
|
174
|
-
import isEmpty2 from "lodash/isEmpty";
|
|
175
|
-
import { createComparator, createMerger, createShallowAllOfMerge } from "@x0k/json-schema-merge";
|
|
176
|
-
import { createDeduplicator, createIntersector } from "@x0k/json-schema-merge/lib/array";
|
|
177
|
-
|
|
178
162
|
// src/findSchemaDefinition.ts
|
|
179
|
-
import jsonpointer from "jsonpointer";
|
|
180
|
-
import omit from "lodash/omit";
|
|
181
|
-
import isObject2 from "lodash/isObject";
|
|
182
|
-
import isEmpty from "lodash/isEmpty";
|
|
183
163
|
import UriResolver from "fast-uri";
|
|
164
|
+
import jsonpointer from "jsonpointer";
|
|
184
165
|
import get from "lodash/get";
|
|
166
|
+
import isEmpty from "lodash/isEmpty";
|
|
167
|
+
import isObject2 from "lodash/isObject";
|
|
168
|
+
import omit from "lodash/omit";
|
|
185
169
|
function findEmbeddedSchemaRecursive(schema, ref) {
|
|
186
170
|
if (ID_KEY in schema && UriResolver.equal(schema[ID_KEY], ref)) {
|
|
187
171
|
return schema;
|
|
@@ -282,6 +266,13 @@ function findSchemaDefinition($ref, rootSchema = {}, baseURI = get(rootSchema, [
|
|
|
282
266
|
return findSchemaDefinitionRecursive($ref, rootSchema, recurseList, baseURI);
|
|
283
267
|
}
|
|
284
268
|
|
|
269
|
+
// src/schema/findFieldInSchema.ts
|
|
270
|
+
import get8 from "lodash/get";
|
|
271
|
+
import has3 from "lodash/has";
|
|
272
|
+
|
|
273
|
+
// src/schema/findSelectedOptionInXxxOf.ts
|
|
274
|
+
import get6 from "lodash/get";
|
|
275
|
+
|
|
285
276
|
// src/getDiscriminatorFieldFromSchema.ts
|
|
286
277
|
import get2 from "lodash/get";
|
|
287
278
|
import isString from "lodash/isString";
|
|
@@ -296,6 +287,16 @@ function getDiscriminatorFieldFromSchema(schema) {
|
|
|
296
287
|
return discriminator;
|
|
297
288
|
}
|
|
298
289
|
|
|
290
|
+
// src/schema/retrieveSchema.ts
|
|
291
|
+
import flattenDeep from "lodash/flattenDeep";
|
|
292
|
+
import get5 from "lodash/get";
|
|
293
|
+
import isEmpty2 from "lodash/isEmpty";
|
|
294
|
+
import merge from "lodash/merge";
|
|
295
|
+
import set from "lodash/set";
|
|
296
|
+
import times from "lodash/times";
|
|
297
|
+
import transform from "lodash/transform";
|
|
298
|
+
import uniq from "lodash/uniq";
|
|
299
|
+
|
|
299
300
|
// src/guessType.ts
|
|
300
301
|
function guessType(value) {
|
|
301
302
|
if (Array.isArray(value)) {
|
|
@@ -437,6 +438,16 @@ function getFirstMatchingOption(validator, formData, options, rootSchema, discri
|
|
|
437
438
|
return 0;
|
|
438
439
|
}
|
|
439
440
|
|
|
441
|
+
// src/schema/shallowAllOfMerge.ts
|
|
442
|
+
import { createComparator, createMerger, createShallowAllOfMerge } from "@x0k/json-schema-merge";
|
|
443
|
+
import { createDeduplicator, createIntersector } from "@x0k/json-schema-merge/lib/array";
|
|
444
|
+
var { compareSchemaDefinitions, compareSchemaValues } = createComparator();
|
|
445
|
+
var { mergeArrayOfSchemaDefinitions } = createMerger({
|
|
446
|
+
intersectJson: createIntersector(compareSchemaValues),
|
|
447
|
+
deduplicateJsonSchemaDef: createDeduplicator(compareSchemaDefinitions)
|
|
448
|
+
});
|
|
449
|
+
var shallowAllOfMerge_default = createShallowAllOfMerge(mergeArrayOfSchemaDefinitions);
|
|
450
|
+
|
|
440
451
|
// src/schema/retrieveSchema.ts
|
|
441
452
|
function retrieveSchema(validator, schema, rootSchema = {}, rawFormData, experimental_customMergeAllOf, resolveAnyOfOrOneOfRefs = false) {
|
|
442
453
|
return retrieveSchemaInternal(
|
|
@@ -723,14 +734,8 @@ function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFor
|
|
|
723
734
|
});
|
|
724
735
|
return schema;
|
|
725
736
|
}
|
|
726
|
-
var { compareSchemaDefinitions, compareSchemaValues } = createComparator();
|
|
727
|
-
var { mergeArrayOfSchemaDefinitions } = createMerger({
|
|
728
|
-
intersectJson: createIntersector(compareSchemaValues),
|
|
729
|
-
deduplicateJsonSchemaDef: createDeduplicator(compareSchemaDefinitions)
|
|
730
|
-
});
|
|
731
|
-
var shallowAllOfMerge = createShallowAllOfMerge(mergeArrayOfSchemaDefinitions);
|
|
732
737
|
function mergeAllOf(schema) {
|
|
733
|
-
return
|
|
738
|
+
return shallowAllOfMerge_default(schema);
|
|
734
739
|
}
|
|
735
740
|
function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expandAllBranches = false, recurseList = [], experimental_customMergeAllOf, resolveAnyOfOrOneOfRefs) {
|
|
736
741
|
if (!isObject(schema)) {
|
|
@@ -837,12 +842,23 @@ function resolveAnyOrOneOfSchemas(validator, schema, rootSchema, expandAllBranch
|
|
|
837
842
|
});
|
|
838
843
|
const option = getFirstMatchingOption(validator, formData, anyOrOneOf, rootSchema, discriminator);
|
|
839
844
|
if (expandAllBranches) {
|
|
845
|
+
const relaxed = relaxOptionsForScoring(anyOrOneOf, false, rootSchema);
|
|
846
|
+
getFirstMatchingOption(validator, formData, relaxed, rootSchema, discriminator);
|
|
840
847
|
return anyOrOneOf.map((item) => mergeSchemas(remaining, item));
|
|
841
848
|
}
|
|
842
849
|
schema = mergeSchemas(remaining, anyOrOneOf[option]);
|
|
843
850
|
}
|
|
844
851
|
return [schema];
|
|
845
852
|
}
|
|
853
|
+
function relaxOptionsForScoring(options, resolveRefs = false, rootSchema) {
|
|
854
|
+
return options.map((d) => {
|
|
855
|
+
if (!isObject(d)) {
|
|
856
|
+
return d ? {} : { not: {} };
|
|
857
|
+
}
|
|
858
|
+
const schema = resolveRefs && rootSchema ? resolveAllReferences(d, rootSchema, []) : d;
|
|
859
|
+
return schema.additionalProperties === false ? { ...schema, additionalProperties: true } : schema;
|
|
860
|
+
});
|
|
861
|
+
}
|
|
846
862
|
function resolveDependencies(validator, schema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
847
863
|
const { dependencies, ...remainingSchema } = schema;
|
|
848
864
|
const resolvedSchemas = resolveAnyOrOneOfSchemas(
|
|
@@ -1133,10 +1149,6 @@ function findFieldInSchema(validator, rootSchema, schema, path, formData = {}, e
|
|
|
1133
1149
|
return { field, isRequired };
|
|
1134
1150
|
}
|
|
1135
1151
|
|
|
1136
|
-
// src/schema/getDefaultFormState.ts
|
|
1137
|
-
import get12 from "lodash/get";
|
|
1138
|
-
import isEmpty4 from "lodash/isEmpty";
|
|
1139
|
-
|
|
1140
1152
|
// src/schema/getClosestMatchingOption.ts
|
|
1141
1153
|
import get9 from "lodash/get";
|
|
1142
1154
|
import has4 from "lodash/has";
|
|
@@ -1261,6 +1273,23 @@ function getClosestMatchingOption(validator, rootSchema, formData, options, sele
|
|
|
1261
1273
|
return bestIndex;
|
|
1262
1274
|
}
|
|
1263
1275
|
|
|
1276
|
+
// src/schema/getDefaultFormState.ts
|
|
1277
|
+
import get12 from "lodash/get";
|
|
1278
|
+
import isEmpty4 from "lodash/isEmpty";
|
|
1279
|
+
|
|
1280
|
+
// src/constIsAjvDataReference.ts
|
|
1281
|
+
import isString3 from "lodash/isString";
|
|
1282
|
+
function constIsAjvDataReference(schema) {
|
|
1283
|
+
const schemaConst = schema[CONST_KEY];
|
|
1284
|
+
const schemaType = getSchemaType(schema);
|
|
1285
|
+
return isObject(schemaConst) && isString3(schemaConst?.$data) && schemaType !== "object" && schemaType !== "array";
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
// src/isConstant.ts
|
|
1289
|
+
function isConstant(schema) {
|
|
1290
|
+
return Array.isArray(schema.enum) && schema.enum.length === 1 || CONST_KEY in schema;
|
|
1291
|
+
}
|
|
1292
|
+
|
|
1264
1293
|
// src/isFixedItems.ts
|
|
1265
1294
|
function isFixedItems(schema) {
|
|
1266
1295
|
return Array.isArray(schema.items) && schema.items.length > 0 && schema.items.every((item) => isObject(item));
|
|
@@ -1353,40 +1382,6 @@ function mergeObjects(obj1, obj2, concatArrays = false) {
|
|
|
1353
1382
|
);
|
|
1354
1383
|
}
|
|
1355
1384
|
|
|
1356
|
-
// src/isConstant.ts
|
|
1357
|
-
function isConstant(schema) {
|
|
1358
|
-
return Array.isArray(schema.enum) && schema.enum.length === 1 || CONST_KEY in schema;
|
|
1359
|
-
}
|
|
1360
|
-
|
|
1361
|
-
// src/schema/isSelect.ts
|
|
1362
|
-
function isSelect(validator, theSchema, rootSchema = {}, experimental_customMergeAllOf) {
|
|
1363
|
-
const schema = retrieveSchema(validator, theSchema, rootSchema, void 0, experimental_customMergeAllOf);
|
|
1364
|
-
const altSchemas = schema.oneOf || schema.anyOf;
|
|
1365
|
-
if (Array.isArray(schema.enum)) {
|
|
1366
|
-
return true;
|
|
1367
|
-
}
|
|
1368
|
-
if (Array.isArray(altSchemas)) {
|
|
1369
|
-
return altSchemas.every((altSchemas2) => typeof altSchemas2 !== "boolean" && isConstant(altSchemas2));
|
|
1370
|
-
}
|
|
1371
|
-
return false;
|
|
1372
|
-
}
|
|
1373
|
-
|
|
1374
|
-
// src/schema/isMultiSelect.ts
|
|
1375
|
-
function isMultiSelect(validator, schema, rootSchema, experimental_customMergeAllOf) {
|
|
1376
|
-
if (!schema.uniqueItems || !schema.items || typeof schema.items === "boolean") {
|
|
1377
|
-
return false;
|
|
1378
|
-
}
|
|
1379
|
-
return isSelect(validator, schema.items, rootSchema, experimental_customMergeAllOf);
|
|
1380
|
-
}
|
|
1381
|
-
|
|
1382
|
-
// src/constIsAjvDataReference.ts
|
|
1383
|
-
import isString3 from "lodash/isString";
|
|
1384
|
-
function constIsAjvDataReference(schema) {
|
|
1385
|
-
const schemaConst = schema[CONST_KEY];
|
|
1386
|
-
const schemaType = getSchemaType(schema);
|
|
1387
|
-
return isObject(schemaConst) && isString3(schemaConst?.$data) && schemaType !== "object" && schemaType !== "array";
|
|
1388
|
-
}
|
|
1389
|
-
|
|
1390
1385
|
// src/optionsList.ts
|
|
1391
1386
|
import get11 from "lodash/get";
|
|
1392
1387
|
|
|
@@ -1467,6 +1462,27 @@ function optionsList(schema, uiSchema) {
|
|
|
1467
1462
|
});
|
|
1468
1463
|
}
|
|
1469
1464
|
|
|
1465
|
+
// src/schema/isSelect.ts
|
|
1466
|
+
function isSelect(validator, theSchema, rootSchema = {}, experimental_customMergeAllOf) {
|
|
1467
|
+
const schema = retrieveSchema(validator, theSchema, rootSchema, void 0, experimental_customMergeAllOf);
|
|
1468
|
+
const altSchemas = schema.oneOf || schema.anyOf;
|
|
1469
|
+
if (Array.isArray(schema.enum)) {
|
|
1470
|
+
return true;
|
|
1471
|
+
}
|
|
1472
|
+
if (Array.isArray(altSchemas)) {
|
|
1473
|
+
return altSchemas.every((altSchemas2) => typeof altSchemas2 !== "boolean" && isConstant(altSchemas2));
|
|
1474
|
+
}
|
|
1475
|
+
return false;
|
|
1476
|
+
}
|
|
1477
|
+
|
|
1478
|
+
// src/schema/isMultiSelect.ts
|
|
1479
|
+
function isMultiSelect(validator, schema, rootSchema, experimental_customMergeAllOf) {
|
|
1480
|
+
if (!schema.uniqueItems || !schema.items || typeof schema.items === "boolean") {
|
|
1481
|
+
return false;
|
|
1482
|
+
}
|
|
1483
|
+
return isSelect(validator, schema.items, rootSchema, experimental_customMergeAllOf);
|
|
1484
|
+
}
|
|
1485
|
+
|
|
1470
1486
|
// src/schema/getDefaultFormState.ts
|
|
1471
1487
|
var PRIMITIVE_TYPES = ["string", "number", "integer", "boolean", "null"];
|
|
1472
1488
|
function getInnerSchemaForArrayItem(schema, additionalItems = 0 /* Ignore */, idx = -1) {
|
|
@@ -1826,14 +1842,11 @@ function getArrayDefaults(validator, rawSchema, {
|
|
|
1826
1842
|
defaults = mergeDefaultsWithFormData(defaults, itemDefaults, mergeExtraDefaults);
|
|
1827
1843
|
}
|
|
1828
1844
|
}
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
if (ignoreMinItemsFlagSet && !required) {
|
|
1835
|
-
return defaults ? defaults : void 0;
|
|
1836
|
-
}
|
|
1845
|
+
if (neverPopulate) {
|
|
1846
|
+
return defaults ?? emptyDefault;
|
|
1847
|
+
}
|
|
1848
|
+
if (ignoreMinItemsFlagSet && !required) {
|
|
1849
|
+
return defaults ? defaults : void 0;
|
|
1837
1850
|
}
|
|
1838
1851
|
let arrayDefault;
|
|
1839
1852
|
const defaultsLength = Array.isArray(defaults) ? defaults.length : 0;
|
|
@@ -1963,210 +1976,269 @@ function getDisplayLabel(validator, schema, uiSchema = {}, rootSchema, globalOpt
|
|
|
1963
1976
|
}
|
|
1964
1977
|
|
|
1965
1978
|
// src/schema/omitExtraData.ts
|
|
1966
|
-
import pick from "lodash/pick";
|
|
1967
|
-
import isEmpty5 from "lodash/isEmpty";
|
|
1968
|
-
import get15 from "lodash/get";
|
|
1969
|
-
|
|
1970
|
-
// src/schema/toPathSchema.ts
|
|
1971
1979
|
import get14 from "lodash/get";
|
|
1972
|
-
import
|
|
1973
|
-
import
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
if (sameSchemaIndex === -1) {
|
|
1979
|
-
return toPathSchemaInternal(
|
|
1980
|
-
validator,
|
|
1981
|
-
_schema,
|
|
1982
|
-
name,
|
|
1983
|
-
rootSchema,
|
|
1984
|
-
formData,
|
|
1985
|
-
_recurseList.concat(_schema),
|
|
1986
|
-
experimental_customMergeAllOf
|
|
1987
|
-
);
|
|
1988
|
-
}
|
|
1980
|
+
import isEmpty5 from "lodash/isEmpty";
|
|
1981
|
+
import isNil2 from "lodash/isNil";
|
|
1982
|
+
import pick from "lodash/pick";
|
|
1983
|
+
function getUsedFormData(formData, fields) {
|
|
1984
|
+
if (fields.length === 0 && typeof formData !== "object") {
|
|
1985
|
+
return formData;
|
|
1989
1986
|
}
|
|
1990
|
-
|
|
1991
|
-
|
|
1987
|
+
const data = pick(formData, fields);
|
|
1988
|
+
if (Array.isArray(formData)) {
|
|
1989
|
+
return Object.keys(data).map((key) => data[key]);
|
|
1990
|
+
}
|
|
1991
|
+
return data;
|
|
1992
|
+
}
|
|
1993
|
+
function getFieldNames(pathSchema, formData) {
|
|
1994
|
+
const formValueHasData = (value, isLeaf) => typeof value !== "object" || isEmpty5(value) || isLeaf && !isEmpty5(value);
|
|
1995
|
+
const getAllPaths = (_obj, acc = [], paths = [[]]) => {
|
|
1996
|
+
const objKeys = Object.keys(_obj);
|
|
1997
|
+
objKeys.forEach((key) => {
|
|
1998
|
+
const data = _obj[key];
|
|
1999
|
+
if (typeof data === "object") {
|
|
2000
|
+
const newPaths = paths.map((path) => [...path, key]);
|
|
2001
|
+
if (data[RJSF_ADDITIONAL_PROPERTIES_FLAG] && data[NAME_KEY] !== "") {
|
|
2002
|
+
acc.push(data[NAME_KEY]);
|
|
2003
|
+
} else {
|
|
2004
|
+
getAllPaths(data, acc, newPaths);
|
|
2005
|
+
}
|
|
2006
|
+
} else if (key === NAME_KEY && data !== "") {
|
|
2007
|
+
paths.forEach((path) => {
|
|
2008
|
+
const formValue = get14(formData, path);
|
|
2009
|
+
const isLeaf = objKeys.length === 1;
|
|
2010
|
+
if (formValueHasData(formValue, isLeaf) || Array.isArray(formValue) && formValue.every((val) => formValueHasData(val, isLeaf))) {
|
|
2011
|
+
acc.push(path);
|
|
2012
|
+
}
|
|
2013
|
+
});
|
|
2014
|
+
}
|
|
2015
|
+
});
|
|
2016
|
+
return acc;
|
|
1992
2017
|
};
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
2018
|
+
return getAllPaths(pathSchema);
|
|
2019
|
+
}
|
|
2020
|
+
function isValueEmpty(value) {
|
|
2021
|
+
if (isNil2(value) || value === "") {
|
|
2022
|
+
return true;
|
|
2023
|
+
}
|
|
2024
|
+
if (Array.isArray(value)) {
|
|
2025
|
+
return value.length === 0;
|
|
2026
|
+
}
|
|
2027
|
+
if (isObject(value)) {
|
|
2028
|
+
return Object.values(value).every(isValueEmpty);
|
|
2029
|
+
}
|
|
2030
|
+
return false;
|
|
2031
|
+
}
|
|
2032
|
+
function doMergeAllOf(schema, experimental_customMergeAllOf) {
|
|
2033
|
+
return experimental_customMergeAllOf ? experimental_customMergeAllOf(schema) : shallowAllOfMerge_default(schema);
|
|
2034
|
+
}
|
|
2035
|
+
function omitExtraData(validator, schema, rootSchema = {}, formData, experimental_customMergeAllOf) {
|
|
2036
|
+
function isObjectValue(value) {
|
|
2037
|
+
return isObject(value);
|
|
2038
|
+
}
|
|
2039
|
+
function isSchemaObj(schemaDef) {
|
|
2040
|
+
return isObject(schemaDef);
|
|
2041
|
+
}
|
|
2042
|
+
function handleObject(schema2, source, target) {
|
|
2043
|
+
const { properties, additionalProperties, patternProperties, propertyNames } = schema2;
|
|
2044
|
+
const requiredSet = new Set(schema2.required ?? []);
|
|
2045
|
+
function setProperty(key, schemaDef, value, required = false) {
|
|
2046
|
+
const v = omit3(schemaDef, value, target[key]);
|
|
2047
|
+
if (!required && isObject(v)) {
|
|
2048
|
+
let sd = isSchemaObj(schemaDef) ? schemaDef : {};
|
|
2049
|
+
if (sd.$ref !== void 0) {
|
|
2050
|
+
sd = findSchemaDefinition(sd.$ref, rootSchema);
|
|
2051
|
+
}
|
|
2052
|
+
const innerRequired = new Set(sd.required ?? []);
|
|
2053
|
+
const shouldDrop = Object.entries(v).every(
|
|
2054
|
+
([k, val]) => !innerRequired.has(k) && isValueEmpty(val)
|
|
2055
|
+
);
|
|
2056
|
+
if (shouldDrop) {
|
|
2057
|
+
return;
|
|
2058
|
+
}
|
|
2059
|
+
}
|
|
2060
|
+
if (v !== void 0) {
|
|
2061
|
+
target[key] = v;
|
|
2062
|
+
}
|
|
2063
|
+
}
|
|
2064
|
+
if (properties !== void 0) {
|
|
2065
|
+
for (const [key, schemaDef] of Object.entries(properties)) {
|
|
2066
|
+
setProperty(key, schemaDef, source[key], requiredSet.has(key));
|
|
2067
|
+
}
|
|
2068
|
+
}
|
|
2069
|
+
let patternPropertiesRest;
|
|
2070
|
+
if (patternProperties !== void 0) {
|
|
2071
|
+
patternPropertiesRest = [];
|
|
2072
|
+
const patterns = Object.entries(patternProperties).map(([pattern, schemaDef]) => [
|
|
2073
|
+
new RegExp(pattern),
|
|
2074
|
+
schemaDef
|
|
2075
|
+
]);
|
|
2076
|
+
const knownProperties = new Set(Object.keys(properties ?? {}));
|
|
2077
|
+
for (const [key, value] of Object.entries(source)) {
|
|
2078
|
+
if (knownProperties.has(key)) {
|
|
2079
|
+
continue;
|
|
2080
|
+
}
|
|
2081
|
+
const matched = patterns.find(([re]) => re.test(key));
|
|
2082
|
+
if (matched === void 0) {
|
|
2083
|
+
patternPropertiesRest.push(key);
|
|
2084
|
+
continue;
|
|
2085
|
+
}
|
|
2086
|
+
setProperty(key, matched[1], value);
|
|
2087
|
+
}
|
|
2088
|
+
}
|
|
2089
|
+
if (additionalProperties !== void 0 && additionalProperties !== false) {
|
|
2090
|
+
const addlSchema = additionalProperties;
|
|
2091
|
+
if (patternPropertiesRest !== void 0) {
|
|
2092
|
+
for (const key of patternPropertiesRest) {
|
|
2093
|
+
setProperty(key, addlSchema, source[key]);
|
|
2094
|
+
}
|
|
2095
|
+
} else {
|
|
2096
|
+
const knownProperties = new Set(Object.keys(properties ?? {}));
|
|
2097
|
+
for (const [key, value] of Object.entries(source)) {
|
|
2098
|
+
if (knownProperties.has(key)) {
|
|
2099
|
+
continue;
|
|
2100
|
+
}
|
|
2101
|
+
setProperty(key, addlSchema, value);
|
|
2102
|
+
}
|
|
2103
|
+
}
|
|
2104
|
+
}
|
|
2105
|
+
if (propertyNames !== void 0) {
|
|
2106
|
+
for (const [key, value] of Object.entries(source)) {
|
|
2107
|
+
target[key] = value;
|
|
2108
|
+
}
|
|
2109
|
+
}
|
|
2110
|
+
return target;
|
|
2111
|
+
}
|
|
2112
|
+
function handleArray(schema2, source, target) {
|
|
2113
|
+
const { items, additionalItems } = schema2;
|
|
2114
|
+
if (items !== void 0) {
|
|
2115
|
+
if (Array.isArray(items)) {
|
|
2116
|
+
for (let i = 0; i < items.length; i++) {
|
|
2117
|
+
target.push(omit3(items[i], source[i]));
|
|
2118
|
+
}
|
|
2119
|
+
} else {
|
|
2120
|
+
for (let i = 0; i < source.length; i++) {
|
|
2121
|
+
target.push(omit3(items, source[i]));
|
|
2122
|
+
}
|
|
2123
|
+
}
|
|
2124
|
+
}
|
|
2125
|
+
if (additionalItems) {
|
|
2126
|
+
for (let i = target.length; i < source.length; i++) {
|
|
2127
|
+
target.push(omit3(additionalItems, source[i]));
|
|
2128
|
+
}
|
|
2129
|
+
}
|
|
2130
|
+
return target;
|
|
2131
|
+
}
|
|
2132
|
+
function handleConditions(schema2, source, target) {
|
|
2133
|
+
const { if: condition, then, else: otherwise } = schema2;
|
|
2134
|
+
if (condition === void 0) {
|
|
2135
|
+
return target;
|
|
2136
|
+
}
|
|
2137
|
+
const isThenBranch = isSchemaObj(condition) ? validator.isValid(condition, source, rootSchema) : condition;
|
|
2138
|
+
const branch = isThenBranch ? then : otherwise;
|
|
2139
|
+
return branch === void 0 ? target : omit3(branch, source, target);
|
|
2140
|
+
}
|
|
2141
|
+
function handleOneOf(oneOf, schema2, source, target) {
|
|
2142
|
+
if (!Array.isArray(oneOf) || isSelect(validator, schema2, rootSchema, experimental_customMergeAllOf)) {
|
|
2143
|
+
return target;
|
|
2144
|
+
}
|
|
2145
|
+
const scoringOptions = relaxOptionsForScoring(oneOf, true, rootSchema);
|
|
2146
|
+
const bestIndex = getClosestMatchingOption(
|
|
1997
2147
|
validator,
|
|
1998
2148
|
rootSchema,
|
|
1999
|
-
|
|
2000
|
-
|
|
2149
|
+
source,
|
|
2150
|
+
scoringOptions,
|
|
2001
2151
|
0,
|
|
2002
|
-
|
|
2152
|
+
getDiscriminatorFieldFromSchema(schema2),
|
|
2003
2153
|
experimental_customMergeAllOf
|
|
2004
2154
|
);
|
|
2005
|
-
const
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
};
|
|
2018
|
-
}
|
|
2019
|
-
if (ADDITIONAL_PROPERTIES_KEY in schema && schema[ADDITIONAL_PROPERTIES_KEY] !== false) {
|
|
2020
|
-
set2(pathSchema, RJSF_ADDITIONAL_PROPERTIES_FLAG, true);
|
|
2021
|
-
const additionalSchema = isObject4(schema[ADDITIONAL_PROPERTIES_KEY]) ? schema[ADDITIONAL_PROPERTIES_KEY] : {};
|
|
2022
|
-
const definedProperties = get14(schema, PROPERTIES_KEY, {});
|
|
2023
|
-
for (const key of Object.keys(formData ?? {})) {
|
|
2024
|
-
if (!(key in definedProperties)) {
|
|
2025
|
-
pathSchema[key] = toPathSchemaInternal(
|
|
2026
|
-
validator,
|
|
2027
|
-
additionalSchema,
|
|
2028
|
-
`${name}.${key}`,
|
|
2029
|
-
rootSchema,
|
|
2030
|
-
get14(formData, [key]),
|
|
2031
|
-
_recurseList,
|
|
2032
|
-
experimental_customMergeAllOf
|
|
2033
|
-
);
|
|
2155
|
+
const winning = oneOf[bestIndex];
|
|
2156
|
+
const resolved = isObject(winning) ? resolveAllReferences(winning, rootSchema, []) : scoringOptions[bestIndex];
|
|
2157
|
+
return omit3(resolved, source, target);
|
|
2158
|
+
}
|
|
2159
|
+
function handleAnyOf(schema2, source, target) {
|
|
2160
|
+
const { anyOf } = schema2;
|
|
2161
|
+
if (!Array.isArray(anyOf)) {
|
|
2162
|
+
return target;
|
|
2163
|
+
}
|
|
2164
|
+
if (source === void 0 || Array.isArray(source) && source.length === 0 || isObject(source) && Object.keys(source).length === 0) {
|
|
2165
|
+
for (const branch of anyOf) {
|
|
2166
|
+
target = omit3(branch, source, target);
|
|
2034
2167
|
}
|
|
2168
|
+
return target;
|
|
2035
2169
|
}
|
|
2170
|
+
return handleOneOf(anyOf, schema2, source, target);
|
|
2036
2171
|
}
|
|
2037
|
-
|
|
2038
|
-
const {
|
|
2039
|
-
if (
|
|
2040
|
-
|
|
2041
|
-
if (schemaItems[i]) {
|
|
2042
|
-
pathSchema[i] = toPathSchemaInternal(
|
|
2043
|
-
validator,
|
|
2044
|
-
schemaItems[i],
|
|
2045
|
-
`${name}.${i}`,
|
|
2046
|
-
rootSchema,
|
|
2047
|
-
element,
|
|
2048
|
-
_recurseList,
|
|
2049
|
-
experimental_customMergeAllOf
|
|
2050
|
-
);
|
|
2051
|
-
} else if (schemaAdditionalItems) {
|
|
2052
|
-
pathSchema[i] = toPathSchemaInternal(
|
|
2053
|
-
validator,
|
|
2054
|
-
schemaAdditionalItems,
|
|
2055
|
-
`${name}.${i}`,
|
|
2056
|
-
rootSchema,
|
|
2057
|
-
element,
|
|
2058
|
-
_recurseList,
|
|
2059
|
-
experimental_customMergeAllOf
|
|
2060
|
-
);
|
|
2061
|
-
} else {
|
|
2062
|
-
console.warn(`Unable to generate path schema for "${name}.${i}". No schema defined for it`);
|
|
2063
|
-
}
|
|
2064
|
-
});
|
|
2065
|
-
} else {
|
|
2066
|
-
formData.forEach((element, i) => {
|
|
2067
|
-
pathSchema[i] = toPathSchemaInternal(
|
|
2068
|
-
validator,
|
|
2069
|
-
schemaItems,
|
|
2070
|
-
`${name}.${i}`,
|
|
2071
|
-
rootSchema,
|
|
2072
|
-
element,
|
|
2073
|
-
_recurseList,
|
|
2074
|
-
experimental_customMergeAllOf
|
|
2075
|
-
);
|
|
2076
|
-
});
|
|
2172
|
+
function handleDependencies(schema2, source, target) {
|
|
2173
|
+
const { dependencies } = schema2;
|
|
2174
|
+
if (dependencies === void 0 || !isObjectValue(source)) {
|
|
2175
|
+
return target;
|
|
2077
2176
|
}
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
field,
|
|
2084
|
-
`${name}.${property}`,
|
|
2085
|
-
rootSchema,
|
|
2086
|
-
// It's possible that formData is not an object -- this can happen if an
|
|
2087
|
-
// array item has just been added, but not populated with data yet
|
|
2088
|
-
get14(formData, [property]),
|
|
2089
|
-
_recurseList,
|
|
2090
|
-
experimental_customMergeAllOf
|
|
2091
|
-
);
|
|
2177
|
+
for (const [key, deps] of Object.entries(dependencies)) {
|
|
2178
|
+
if (!(key in source) || Array.isArray(deps)) {
|
|
2179
|
+
continue;
|
|
2180
|
+
}
|
|
2181
|
+
target = omit3(deps, source, target);
|
|
2092
2182
|
}
|
|
2183
|
+
return target;
|
|
2093
2184
|
}
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
const objKeys = Object.keys(_obj);
|
|
2115
|
-
objKeys.forEach((key) => {
|
|
2116
|
-
const data = _obj[key];
|
|
2117
|
-
if (typeof data === "object") {
|
|
2118
|
-
const newPaths = paths.map((path) => [...path, key]);
|
|
2119
|
-
if (data[RJSF_ADDITIONAL_PROPERTIES_FLAG] && data[NAME_KEY] !== "") {
|
|
2120
|
-
acc.push(data[NAME_KEY]);
|
|
2121
|
-
} else {
|
|
2122
|
-
getAllPaths(data, acc, newPaths);
|
|
2123
|
-
}
|
|
2124
|
-
} else if (key === NAME_KEY && data !== "") {
|
|
2125
|
-
paths.forEach((path) => {
|
|
2126
|
-
const formValue = get15(formData, path);
|
|
2127
|
-
const isLeaf = objKeys.length === 1;
|
|
2128
|
-
if (formValueHasData(formValue, isLeaf) || Array.isArray(formValue) && formValue.every((val) => formValueHasData(val, isLeaf))) {
|
|
2129
|
-
acc.push(path);
|
|
2130
|
-
}
|
|
2131
|
-
});
|
|
2185
|
+
function omit3(schemaDef, source, target) {
|
|
2186
|
+
if (source === void 0 || schemaDef === false) {
|
|
2187
|
+
return void 0;
|
|
2188
|
+
}
|
|
2189
|
+
if (schemaDef === true || isEmpty5(schemaDef)) {
|
|
2190
|
+
return source;
|
|
2191
|
+
}
|
|
2192
|
+
let schema2 = schemaDef;
|
|
2193
|
+
const { $ref: ref, allOf } = schema2;
|
|
2194
|
+
if (ref !== void 0) {
|
|
2195
|
+
return omit3(findSchemaDefinition(ref, rootSchema), source, target);
|
|
2196
|
+
}
|
|
2197
|
+
if (allOf) {
|
|
2198
|
+
schema2 = doMergeAllOf(schema2, experimental_customMergeAllOf);
|
|
2199
|
+
}
|
|
2200
|
+
target = handleAnyOf(schema2, source, handleOneOf(schema2.oneOf, schema2, source, target));
|
|
2201
|
+
const type = getSchemaType(schema2);
|
|
2202
|
+
if (type === "object") {
|
|
2203
|
+
if (!isObjectValue(source)) {
|
|
2204
|
+
return void 0;
|
|
2132
2205
|
}
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
}
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
);
|
|
2145
|
-
return getUsedFormData(formData, lodashFieldNames);
|
|
2206
|
+
target = handleObject(schema2, source, isObjectValue(target) ? target : {});
|
|
2207
|
+
} else if (type === "array") {
|
|
2208
|
+
if (!Array.isArray(source)) {
|
|
2209
|
+
return void 0;
|
|
2210
|
+
}
|
|
2211
|
+
target = handleArray(schema2, source, Array.isArray(target) ? target : []);
|
|
2212
|
+
} else if (target === void 0) {
|
|
2213
|
+
target = source;
|
|
2214
|
+
}
|
|
2215
|
+
return handleDependencies(schema2, source, handleConditions(schema2, source, target));
|
|
2216
|
+
}
|
|
2217
|
+
return omit3(schema, formData);
|
|
2146
2218
|
}
|
|
2147
2219
|
|
|
2148
2220
|
// src/schema/sanitizeDataForNewSchema.ts
|
|
2149
|
-
import
|
|
2221
|
+
import get15 from "lodash/get";
|
|
2150
2222
|
import has5 from "lodash/has";
|
|
2151
|
-
var NO_VALUE = Symbol("no Value");
|
|
2223
|
+
var NO_VALUE = /* @__PURE__ */ Symbol("no Value");
|
|
2152
2224
|
function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, data = {}, experimental_customMergeAllOf) {
|
|
2153
2225
|
let newFormData;
|
|
2154
2226
|
if (has5(newSchema, PROPERTIES_KEY)) {
|
|
2155
2227
|
const removeOldSchemaData = {};
|
|
2156
2228
|
if (has5(oldSchema, PROPERTIES_KEY)) {
|
|
2157
|
-
const properties =
|
|
2229
|
+
const properties = get15(oldSchema, PROPERTIES_KEY, {});
|
|
2158
2230
|
Object.keys(properties).forEach((key) => {
|
|
2159
2231
|
if (has5(data, key)) {
|
|
2160
2232
|
removeOldSchemaData[key] = void 0;
|
|
2161
2233
|
}
|
|
2162
2234
|
});
|
|
2163
2235
|
}
|
|
2164
|
-
const keys2 = Object.keys(
|
|
2236
|
+
const keys2 = Object.keys(get15(newSchema, PROPERTIES_KEY, {}));
|
|
2165
2237
|
const nestedData = {};
|
|
2166
2238
|
keys2.forEach((key) => {
|
|
2167
|
-
const formValue =
|
|
2168
|
-
let oldKeyedSchema =
|
|
2169
|
-
let newKeyedSchema =
|
|
2239
|
+
const formValue = get15(data, key);
|
|
2240
|
+
let oldKeyedSchema = get15(oldSchema, [PROPERTIES_KEY, key], {});
|
|
2241
|
+
let newKeyedSchema = get15(newSchema, [PROPERTIES_KEY, key], {});
|
|
2170
2242
|
if (has5(oldKeyedSchema, REF_KEY)) {
|
|
2171
2243
|
oldKeyedSchema = retrieveSchema(
|
|
2172
2244
|
validator,
|
|
@@ -2185,8 +2257,8 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
2185
2257
|
experimental_customMergeAllOf
|
|
2186
2258
|
);
|
|
2187
2259
|
}
|
|
2188
|
-
const oldSchemaTypeForKey =
|
|
2189
|
-
const newSchemaTypeForKey =
|
|
2260
|
+
const oldSchemaTypeForKey = get15(oldKeyedSchema, "type");
|
|
2261
|
+
const newSchemaTypeForKey = get15(newKeyedSchema, "type");
|
|
2190
2262
|
if (!oldSchemaTypeForKey || oldSchemaTypeForKey === newSchemaTypeForKey) {
|
|
2191
2263
|
if (has5(removeOldSchemaData, key)) {
|
|
2192
2264
|
delete removeOldSchemaData[key];
|
|
@@ -2204,17 +2276,17 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
2204
2276
|
nestedData[key] = itemData;
|
|
2205
2277
|
}
|
|
2206
2278
|
} else {
|
|
2207
|
-
const newOptionDefault =
|
|
2208
|
-
const oldOptionDefault =
|
|
2279
|
+
const newOptionDefault = get15(newKeyedSchema, "default", NO_VALUE);
|
|
2280
|
+
const oldOptionDefault = get15(oldKeyedSchema, "default", NO_VALUE);
|
|
2209
2281
|
if (newOptionDefault !== NO_VALUE && newOptionDefault !== formValue) {
|
|
2210
2282
|
if (oldOptionDefault === formValue) {
|
|
2211
2283
|
removeOldSchemaData[key] = newOptionDefault;
|
|
2212
|
-
} else if (
|
|
2284
|
+
} else if (get15(newKeyedSchema, "readOnly") === true) {
|
|
2213
2285
|
removeOldSchemaData[key] = void 0;
|
|
2214
2286
|
}
|
|
2215
2287
|
}
|
|
2216
|
-
const newOptionConst =
|
|
2217
|
-
const oldOptionConst =
|
|
2288
|
+
const newOptionConst = get15(newKeyedSchema, "const", NO_VALUE);
|
|
2289
|
+
const oldOptionConst = get15(oldKeyedSchema, "const", NO_VALUE);
|
|
2218
2290
|
if (newOptionConst !== NO_VALUE && newOptionConst !== formValue) {
|
|
2219
2291
|
removeOldSchemaData[key] = oldOptionConst === formValue ? newOptionConst : void 0;
|
|
2220
2292
|
}
|
|
@@ -2226,9 +2298,9 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
2226
2298
|
...removeOldSchemaData,
|
|
2227
2299
|
...nestedData
|
|
2228
2300
|
};
|
|
2229
|
-
} else if (
|
|
2230
|
-
let oldSchemaItems =
|
|
2231
|
-
let newSchemaItems =
|
|
2301
|
+
} else if (get15(oldSchema, "type") === "array" && get15(newSchema, "type") === "array" && Array.isArray(data)) {
|
|
2302
|
+
let oldSchemaItems = get15(oldSchema, "items");
|
|
2303
|
+
let newSchemaItems = get15(newSchema, "items");
|
|
2232
2304
|
if (typeof oldSchemaItems === "object" && typeof newSchemaItems === "object" && !Array.isArray(oldSchemaItems) && !Array.isArray(newSchemaItems)) {
|
|
2233
2305
|
if (has5(oldSchemaItems, REF_KEY)) {
|
|
2234
2306
|
oldSchemaItems = retrieveSchema(
|
|
@@ -2248,10 +2320,10 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
2248
2320
|
experimental_customMergeAllOf
|
|
2249
2321
|
);
|
|
2250
2322
|
}
|
|
2251
|
-
const oldSchemaType =
|
|
2252
|
-
const newSchemaType =
|
|
2323
|
+
const oldSchemaType = get15(oldSchemaItems, "type");
|
|
2324
|
+
const newSchemaType = get15(newSchemaItems, "type");
|
|
2253
2325
|
if (!oldSchemaType || oldSchemaType === newSchemaType) {
|
|
2254
|
-
const maxItems =
|
|
2326
|
+
const maxItems = get15(newSchema, "maxItems", -1);
|
|
2255
2327
|
if (newSchemaType === "object") {
|
|
2256
2328
|
newFormData = data.reduce((newValue, aValue) => {
|
|
2257
2329
|
const itemValue = sanitizeDataForNewSchema(
|
|
@@ -2278,8 +2350,137 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
2278
2350
|
return newFormData;
|
|
2279
2351
|
}
|
|
2280
2352
|
|
|
2353
|
+
// src/schema/toPathSchema.ts
|
|
2354
|
+
import get16 from "lodash/get";
|
|
2355
|
+
import isObject4 from "lodash/isObject";
|
|
2356
|
+
import set2 from "lodash/set";
|
|
2357
|
+
function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
|
|
2358
|
+
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema || IF_KEY in schema) {
|
|
2359
|
+
const _schema = retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf);
|
|
2360
|
+
const sameSchemaIndex = _recurseList.findIndex((item) => deepEquals_default(item, _schema));
|
|
2361
|
+
if (sameSchemaIndex === -1) {
|
|
2362
|
+
return toPathSchemaInternal(
|
|
2363
|
+
validator,
|
|
2364
|
+
_schema,
|
|
2365
|
+
name,
|
|
2366
|
+
rootSchema,
|
|
2367
|
+
formData,
|
|
2368
|
+
_recurseList.concat(_schema),
|
|
2369
|
+
experimental_customMergeAllOf
|
|
2370
|
+
);
|
|
2371
|
+
}
|
|
2372
|
+
}
|
|
2373
|
+
let pathSchema = {
|
|
2374
|
+
[NAME_KEY]: name.replace(/^\./, "")
|
|
2375
|
+
};
|
|
2376
|
+
if (ONE_OF_KEY in schema || ANY_OF_KEY in schema) {
|
|
2377
|
+
const xxxOf = ONE_OF_KEY in schema ? schema.oneOf : schema.anyOf;
|
|
2378
|
+
const discriminator = getDiscriminatorFieldFromSchema(schema);
|
|
2379
|
+
const index = getClosestMatchingOption(
|
|
2380
|
+
validator,
|
|
2381
|
+
rootSchema,
|
|
2382
|
+
formData,
|
|
2383
|
+
xxxOf,
|
|
2384
|
+
0,
|
|
2385
|
+
discriminator,
|
|
2386
|
+
experimental_customMergeAllOf
|
|
2387
|
+
);
|
|
2388
|
+
const _schema = xxxOf[index];
|
|
2389
|
+
pathSchema = {
|
|
2390
|
+
...pathSchema,
|
|
2391
|
+
...toPathSchemaInternal(
|
|
2392
|
+
validator,
|
|
2393
|
+
_schema,
|
|
2394
|
+
name,
|
|
2395
|
+
rootSchema,
|
|
2396
|
+
formData,
|
|
2397
|
+
_recurseList,
|
|
2398
|
+
experimental_customMergeAllOf
|
|
2399
|
+
)
|
|
2400
|
+
};
|
|
2401
|
+
}
|
|
2402
|
+
if (ADDITIONAL_PROPERTIES_KEY in schema && schema[ADDITIONAL_PROPERTIES_KEY] !== false) {
|
|
2403
|
+
set2(pathSchema, RJSF_ADDITIONAL_PROPERTIES_FLAG, true);
|
|
2404
|
+
const additionalSchema = isObject4(schema[ADDITIONAL_PROPERTIES_KEY]) ? schema[ADDITIONAL_PROPERTIES_KEY] : {};
|
|
2405
|
+
const definedProperties = get16(schema, PROPERTIES_KEY, {});
|
|
2406
|
+
for (const key of Object.keys(formData ?? {})) {
|
|
2407
|
+
if (!(key in definedProperties)) {
|
|
2408
|
+
pathSchema[key] = toPathSchemaInternal(
|
|
2409
|
+
validator,
|
|
2410
|
+
additionalSchema,
|
|
2411
|
+
`${name}.${key}`,
|
|
2412
|
+
rootSchema,
|
|
2413
|
+
get16(formData, [key]),
|
|
2414
|
+
_recurseList,
|
|
2415
|
+
experimental_customMergeAllOf
|
|
2416
|
+
);
|
|
2417
|
+
}
|
|
2418
|
+
}
|
|
2419
|
+
}
|
|
2420
|
+
if (ITEMS_KEY in schema && Array.isArray(formData)) {
|
|
2421
|
+
const { items: schemaItems, additionalItems: schemaAdditionalItems } = schema;
|
|
2422
|
+
if (Array.isArray(schemaItems)) {
|
|
2423
|
+
formData.forEach((element, i) => {
|
|
2424
|
+
if (schemaItems[i]) {
|
|
2425
|
+
pathSchema[i] = toPathSchemaInternal(
|
|
2426
|
+
validator,
|
|
2427
|
+
schemaItems[i],
|
|
2428
|
+
`${name}.${i}`,
|
|
2429
|
+
rootSchema,
|
|
2430
|
+
element,
|
|
2431
|
+
_recurseList,
|
|
2432
|
+
experimental_customMergeAllOf
|
|
2433
|
+
);
|
|
2434
|
+
} else if (schemaAdditionalItems) {
|
|
2435
|
+
pathSchema[i] = toPathSchemaInternal(
|
|
2436
|
+
validator,
|
|
2437
|
+
schemaAdditionalItems,
|
|
2438
|
+
`${name}.${i}`,
|
|
2439
|
+
rootSchema,
|
|
2440
|
+
element,
|
|
2441
|
+
_recurseList,
|
|
2442
|
+
experimental_customMergeAllOf
|
|
2443
|
+
);
|
|
2444
|
+
} else {
|
|
2445
|
+
console.warn(`Unable to generate path schema for "${name}.${i}". No schema defined for it`);
|
|
2446
|
+
}
|
|
2447
|
+
});
|
|
2448
|
+
} else {
|
|
2449
|
+
formData.forEach((element, i) => {
|
|
2450
|
+
pathSchema[i] = toPathSchemaInternal(
|
|
2451
|
+
validator,
|
|
2452
|
+
schemaItems,
|
|
2453
|
+
`${name}.${i}`,
|
|
2454
|
+
rootSchema,
|
|
2455
|
+
element,
|
|
2456
|
+
_recurseList,
|
|
2457
|
+
experimental_customMergeAllOf
|
|
2458
|
+
);
|
|
2459
|
+
});
|
|
2460
|
+
}
|
|
2461
|
+
} else if (PROPERTIES_KEY in schema) {
|
|
2462
|
+
for (const property in schema.properties) {
|
|
2463
|
+
const field = get16(schema, [PROPERTIES_KEY, property], {});
|
|
2464
|
+
pathSchema[property] = toPathSchemaInternal(
|
|
2465
|
+
validator,
|
|
2466
|
+
field,
|
|
2467
|
+
`${name}.${property}`,
|
|
2468
|
+
rootSchema,
|
|
2469
|
+
// It's possible that formData is not an object -- this can happen if an
|
|
2470
|
+
// array item has just been added, but not populated with data yet
|
|
2471
|
+
get16(formData, [property]),
|
|
2472
|
+
_recurseList,
|
|
2473
|
+
experimental_customMergeAllOf
|
|
2474
|
+
);
|
|
2475
|
+
}
|
|
2476
|
+
}
|
|
2477
|
+
return pathSchema;
|
|
2478
|
+
}
|
|
2479
|
+
function toPathSchema(validator, schema, name = "", rootSchema, formData, experimental_customMergeAllOf) {
|
|
2480
|
+
return toPathSchemaInternal(validator, schema, name, rootSchema, formData, void 0, experimental_customMergeAllOf);
|
|
2481
|
+
}
|
|
2482
|
+
|
|
2281
2483
|
// src/createSchemaUtils.ts
|
|
2282
|
-
import get17 from "lodash/get";
|
|
2283
2484
|
var SchemaUtils = class {
|
|
2284
2485
|
/** Constructs the `SchemaUtils` instance with the given `validator` and `rootSchema` stored as instance variables
|
|
2285
2486
|
*
|
|
@@ -2619,31 +2820,6 @@ function dateRangeOptions(start, stop) {
|
|
|
2619
2820
|
return options;
|
|
2620
2821
|
}
|
|
2621
2822
|
|
|
2622
|
-
// src/shallowEquals.ts
|
|
2623
|
-
function shallowEquals(a, b) {
|
|
2624
|
-
if (Object.is(a, b)) {
|
|
2625
|
-
return true;
|
|
2626
|
-
}
|
|
2627
|
-
if (a == null || b == null) {
|
|
2628
|
-
return false;
|
|
2629
|
-
}
|
|
2630
|
-
if (typeof a !== "object" || typeof b !== "object") {
|
|
2631
|
-
return false;
|
|
2632
|
-
}
|
|
2633
|
-
const keysA = Object.keys(a);
|
|
2634
|
-
const keysB = Object.keys(b);
|
|
2635
|
-
if (keysA.length !== keysB.length) {
|
|
2636
|
-
return false;
|
|
2637
|
-
}
|
|
2638
|
-
for (let i = 0; i < keysA.length; i++) {
|
|
2639
|
-
const key = keysA[i];
|
|
2640
|
-
if (!Object.prototype.hasOwnProperty.call(b, key) || !Object.is(a[key], b[key])) {
|
|
2641
|
-
return false;
|
|
2642
|
-
}
|
|
2643
|
-
}
|
|
2644
|
-
return true;
|
|
2645
|
-
}
|
|
2646
|
-
|
|
2647
2823
|
// src/replaceStringParameters.ts
|
|
2648
2824
|
function replaceStringParameters(inputString, params) {
|
|
2649
2825
|
let output = inputString;
|
|
@@ -2657,12 +2833,31 @@ function replaceStringParameters(inputString, params) {
|
|
|
2657
2833
|
});
|
|
2658
2834
|
output = parts.join("");
|
|
2659
2835
|
}
|
|
2660
|
-
return output;
|
|
2836
|
+
return output;
|
|
2837
|
+
}
|
|
2838
|
+
|
|
2839
|
+
// src/englishStringTranslator.ts
|
|
2840
|
+
function englishStringTranslator(stringToTranslate, params) {
|
|
2841
|
+
return replaceStringParameters(stringToTranslate, params);
|
|
2842
|
+
}
|
|
2843
|
+
|
|
2844
|
+
// src/enumOptionsValueForIndex.ts
|
|
2845
|
+
function enumOptionsValueForIndex(valueIndex, allEnumOptions = [], emptyValue) {
|
|
2846
|
+
if (Array.isArray(valueIndex)) {
|
|
2847
|
+
return valueIndex.map((index2) => enumOptionsValueForIndex(index2, allEnumOptions)).filter((val) => val !== void 0);
|
|
2848
|
+
}
|
|
2849
|
+
const index = valueIndex === "" || valueIndex === null ? -1 : Number(valueIndex);
|
|
2850
|
+
const option = allEnumOptions[index];
|
|
2851
|
+
return option ? option.value : emptyValue;
|
|
2661
2852
|
}
|
|
2662
2853
|
|
|
2663
|
-
// src/
|
|
2664
|
-
function
|
|
2665
|
-
|
|
2854
|
+
// src/enumOptionsDeselectValue.ts
|
|
2855
|
+
function enumOptionsDeselectValue(valueIndex, selected, allEnumOptions = []) {
|
|
2856
|
+
const value = enumOptionsValueForIndex(valueIndex, allEnumOptions);
|
|
2857
|
+
if (Array.isArray(selected)) {
|
|
2858
|
+
return selected.filter((v) => !deepEquals_default(v, value));
|
|
2859
|
+
}
|
|
2860
|
+
return deepEquals_default(value, selected) ? void 0 : selected;
|
|
2666
2861
|
}
|
|
2667
2862
|
|
|
2668
2863
|
// src/enumOptionsIsSelected.ts
|
|
@@ -2695,14 +2890,17 @@ function enumOptionSelectedValue(value, enumOptions, multiple, format = "indexed
|
|
|
2695
2890
|
return typeof indexes === "undefined" ? emptyValue : indexes;
|
|
2696
2891
|
}
|
|
2697
2892
|
|
|
2698
|
-
// src/
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2893
|
+
// src/enumOptionsSelectValue.ts
|
|
2894
|
+
import isNil3 from "lodash/isNil";
|
|
2895
|
+
function enumOptionsSelectValue(valueIndex, selected, allEnumOptions = []) {
|
|
2896
|
+
const value = enumOptionsValueForIndex(valueIndex, allEnumOptions);
|
|
2897
|
+
if (!isNil3(value)) {
|
|
2898
|
+
const index = allEnumOptions.findIndex((opt) => value === opt.value);
|
|
2899
|
+
const all = allEnumOptions.map(({ value: val }) => val);
|
|
2900
|
+
const updated = selected.slice(0, index).concat(value, selected.slice(index));
|
|
2901
|
+
return updated.sort((a, b) => Number(all.indexOf(a) > all.indexOf(b)));
|
|
2702
2902
|
}
|
|
2703
|
-
|
|
2704
|
-
const option = allEnumOptions[index];
|
|
2705
|
-
return option ? option.value : emptyValue;
|
|
2903
|
+
return selected;
|
|
2706
2904
|
}
|
|
2707
2905
|
|
|
2708
2906
|
// src/enumOptionValueDecoder.ts
|
|
@@ -2731,12 +2929,12 @@ function enumOptionValueDecoder(value, enumOptions, format = "indexed", emptyVal
|
|
|
2731
2929
|
}
|
|
2732
2930
|
|
|
2733
2931
|
// src/enumOptionValueEncoder.ts
|
|
2734
|
-
import
|
|
2932
|
+
import isNil4 from "lodash/isNil";
|
|
2735
2933
|
function enumOptionValueEncoder(value, index, format = "indexed") {
|
|
2736
2934
|
if (format !== "realValue") {
|
|
2737
2935
|
return String(index);
|
|
2738
2936
|
}
|
|
2739
|
-
if (
|
|
2937
|
+
if (isNil4(value)) {
|
|
2740
2938
|
return "";
|
|
2741
2939
|
}
|
|
2742
2940
|
if (typeof value === "object") {
|
|
@@ -2745,28 +2943,6 @@ function enumOptionValueEncoder(value, index, format = "indexed") {
|
|
|
2745
2943
|
return String(value);
|
|
2746
2944
|
}
|
|
2747
2945
|
|
|
2748
|
-
// src/enumOptionsDeselectValue.ts
|
|
2749
|
-
function enumOptionsDeselectValue(valueIndex, selected, allEnumOptions = []) {
|
|
2750
|
-
const value = enumOptionsValueForIndex(valueIndex, allEnumOptions);
|
|
2751
|
-
if (Array.isArray(selected)) {
|
|
2752
|
-
return selected.filter((v) => !deepEquals_default(v, value));
|
|
2753
|
-
}
|
|
2754
|
-
return deepEquals_default(value, selected) ? void 0 : selected;
|
|
2755
|
-
}
|
|
2756
|
-
|
|
2757
|
-
// src/enumOptionsSelectValue.ts
|
|
2758
|
-
import isNil3 from "lodash/isNil";
|
|
2759
|
-
function enumOptionsSelectValue(valueIndex, selected, allEnumOptions = []) {
|
|
2760
|
-
const value = enumOptionsValueForIndex(valueIndex, allEnumOptions);
|
|
2761
|
-
if (!isNil3(value)) {
|
|
2762
|
-
const index = allEnumOptions.findIndex((opt) => value === opt.value);
|
|
2763
|
-
const all = allEnumOptions.map(({ value: val }) => val);
|
|
2764
|
-
const updated = selected.slice(0, index).concat(value, selected.slice(index));
|
|
2765
|
-
return updated.sort((a, b) => Number(all.indexOf(a) > all.indexOf(b)));
|
|
2766
|
-
}
|
|
2767
|
-
return selected;
|
|
2768
|
-
}
|
|
2769
|
-
|
|
2770
2946
|
// src/ErrorSchemaBuilder.ts
|
|
2771
2947
|
import cloneDeep from "lodash/cloneDeep";
|
|
2772
2948
|
import get18 from "lodash/get";
|
|
@@ -2865,11 +3041,11 @@ var ErrorSchemaBuilder = class {
|
|
|
2865
3041
|
};
|
|
2866
3042
|
|
|
2867
3043
|
// src/getChangedFields.ts
|
|
3044
|
+
import difference from "lodash/difference";
|
|
3045
|
+
import get19 from "lodash/get";
|
|
3046
|
+
import isPlainObject2 from "lodash/isPlainObject";
|
|
2868
3047
|
import keys from "lodash/keys";
|
|
2869
3048
|
import pickBy from "lodash/pickBy";
|
|
2870
|
-
import isPlainObject2 from "lodash/isPlainObject";
|
|
2871
|
-
import get19 from "lodash/get";
|
|
2872
|
-
import difference from "lodash/difference";
|
|
2873
3049
|
function getChangedFields(a, b) {
|
|
2874
3050
|
const aIsPlainObject = isPlainObject2(a);
|
|
2875
3051
|
const bIsPlainObject = isPlainObject2(b);
|
|
@@ -3011,7 +3187,7 @@ function getTemplate(name, registry, uiOptions = {}) {
|
|
|
3011
3187
|
import get20 from "lodash/get";
|
|
3012
3188
|
import uniqueId from "lodash/uniqueId";
|
|
3013
3189
|
function getTestIds() {
|
|
3014
|
-
if (
|
|
3190
|
+
if (get20(globalThis, "process.env.NODE_ENV") !== "test") {
|
|
3015
3191
|
return {};
|
|
3016
3192
|
}
|
|
3017
3193
|
const ids = /* @__PURE__ */ new Map();
|
|
@@ -3030,9 +3206,9 @@ function getTestIds() {
|
|
|
3030
3206
|
|
|
3031
3207
|
// src/getWidget.tsx
|
|
3032
3208
|
import { createElement } from "react";
|
|
3033
|
-
import ReactIs from "react-is";
|
|
3034
3209
|
import get21 from "lodash/get";
|
|
3035
3210
|
import set4 from "lodash/set";
|
|
3211
|
+
import ReactIs from "react-is";
|
|
3036
3212
|
import { jsx } from "react/jsx-runtime";
|
|
3037
3213
|
var widgetMap = {
|
|
3038
3214
|
boolean: {
|
|
@@ -3193,11 +3369,11 @@ function optionalControlsId(id, element) {
|
|
|
3193
3369
|
}
|
|
3194
3370
|
|
|
3195
3371
|
// src/isFormDataAvailable.ts
|
|
3196
|
-
import isNil4 from "lodash/isNil";
|
|
3197
3372
|
import isEmpty6 from "lodash/isEmpty";
|
|
3373
|
+
import isNil5 from "lodash/isNil";
|
|
3198
3374
|
import isObject5 from "lodash/isObject";
|
|
3199
3375
|
function isFormDataAvailable(formData) {
|
|
3200
|
-
return !
|
|
3376
|
+
return !isNil5(formData) && (!isObject5(formData) || Array.isArray(formData) || !isEmpty6(formData));
|
|
3201
3377
|
}
|
|
3202
3378
|
|
|
3203
3379
|
// src/isRootSchema.ts
|
|
@@ -3235,80 +3411,25 @@ function lookupFromFormContext(regOrFc, toLookup, fallback) {
|
|
|
3235
3411
|
return get22(regOrFc, [...lookupPath, toLookup], fallback);
|
|
3236
3412
|
}
|
|
3237
3413
|
|
|
3238
|
-
// src/
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
return true;
|
|
3243
|
-
}
|
|
3244
|
-
if (Array.isArray(value)) {
|
|
3245
|
-
return value.length === 0;
|
|
3246
|
-
}
|
|
3247
|
-
if (isObject(value)) {
|
|
3248
|
-
const obj = value;
|
|
3249
|
-
const keys2 = Object.keys(obj);
|
|
3250
|
-
return keys2.every((key) => isValueEmpty(obj[key]));
|
|
3251
|
-
}
|
|
3252
|
-
return false;
|
|
3253
|
-
}
|
|
3254
|
-
function removeOptionalEmptyObjects(validator, schema, rootSchema, formData) {
|
|
3255
|
-
if (!isObject(schema)) {
|
|
3256
|
-
return formData;
|
|
3257
|
-
}
|
|
3258
|
-
const resolvedSchema = retrieveSchema(validator, schema, rootSchema, formData);
|
|
3259
|
-
if (Array.isArray(formData)) {
|
|
3260
|
-
const itemsSchema = resolvedSchema.items;
|
|
3261
|
-
if (!itemsSchema) {
|
|
3262
|
-
return formData;
|
|
3263
|
-
}
|
|
3264
|
-
let hasChanges = false;
|
|
3265
|
-
const mapped = formData.map((item, index) => {
|
|
3266
|
-
let itemSchema = itemsSchema;
|
|
3267
|
-
if (Array.isArray(itemsSchema)) {
|
|
3268
|
-
itemSchema = itemsSchema[index] || resolvedSchema.additionalItems || {};
|
|
3269
|
-
}
|
|
3270
|
-
const cleaned = removeOptionalEmptyObjects(validator, itemSchema, rootSchema, item);
|
|
3271
|
-
if (cleaned !== item) {
|
|
3272
|
-
hasChanges = true;
|
|
3273
|
-
}
|
|
3274
|
-
return cleaned === void 0 ? {} : cleaned;
|
|
3275
|
-
});
|
|
3276
|
-
return hasChanges ? mapped : formData;
|
|
3277
|
-
}
|
|
3278
|
-
const { properties, required: requiredFields = [] } = resolvedSchema;
|
|
3279
|
-
if (!isObject(formData) || !properties) {
|
|
3280
|
-
return formData;
|
|
3414
|
+
// src/nameGenerators.ts
|
|
3415
|
+
var bracketNameGenerator = (path, idPrefix, isMultiValue) => {
|
|
3416
|
+
if (!path || path.length === 0) {
|
|
3417
|
+
return idPrefix;
|
|
3281
3418
|
}
|
|
3282
|
-
const
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
for (const key of Object.keys(data)) {
|
|
3286
|
-
const value = data[key];
|
|
3287
|
-
const propertySchema = properties[key] || {};
|
|
3288
|
-
const isRequired = requiredFields.includes(key);
|
|
3289
|
-
const isObj = isObject(value);
|
|
3290
|
-
const isArr = Array.isArray(value);
|
|
3291
|
-
if ((isObj || isArr) && properties[key]) {
|
|
3292
|
-
const cleaned = removeOptionalEmptyObjects(validator, propertySchema, rootSchema, value);
|
|
3293
|
-
if (!isRequired && isValueEmpty(cleaned)) {
|
|
3294
|
-
continue;
|
|
3295
|
-
}
|
|
3296
|
-
result[key] = cleaned;
|
|
3297
|
-
hasAnyValue = true;
|
|
3298
|
-
} else if (!isRequired && isValueEmpty(value) && properties[key]) {
|
|
3299
|
-
continue;
|
|
3300
|
-
} else {
|
|
3301
|
-
result[key] = value;
|
|
3302
|
-
if (!isValueEmpty(value)) {
|
|
3303
|
-
hasAnyValue = true;
|
|
3304
|
-
}
|
|
3419
|
+
const baseName = path.reduce((acc, pathUnit, index) => {
|
|
3420
|
+
if (index === 0) {
|
|
3421
|
+
return `${idPrefix}[${String(pathUnit)}]`;
|
|
3305
3422
|
}
|
|
3423
|
+
return `${acc}[${String(pathUnit)}]`;
|
|
3424
|
+
}, "");
|
|
3425
|
+
return isMultiValue ? `${baseName}[]` : baseName;
|
|
3426
|
+
};
|
|
3427
|
+
var dotNotationNameGenerator = (path, idPrefix, _isMultiValue) => {
|
|
3428
|
+
if (!path || path.length === 0) {
|
|
3429
|
+
return idPrefix;
|
|
3306
3430
|
}
|
|
3307
|
-
|
|
3308
|
-
|
|
3309
|
-
}
|
|
3310
|
-
return result;
|
|
3311
|
-
}
|
|
3431
|
+
return `${idPrefix}.${path.map(String).join(".")}`;
|
|
3432
|
+
};
|
|
3312
3433
|
|
|
3313
3434
|
// src/orderProperties.ts
|
|
3314
3435
|
function orderProperties(properties, order) {
|
|
@@ -3366,6 +3487,64 @@ function parseDateString(dateString, includeTime = true) {
|
|
|
3366
3487
|
};
|
|
3367
3488
|
}
|
|
3368
3489
|
|
|
3490
|
+
// src/removeOptionalEmptyObjects.ts
|
|
3491
|
+
function removeOptionalEmptyObjects(validator, schema, rootSchema, formData) {
|
|
3492
|
+
if (!isObject(schema)) {
|
|
3493
|
+
return formData;
|
|
3494
|
+
}
|
|
3495
|
+
const resolvedSchema = retrieveSchema(validator, schema, rootSchema, formData);
|
|
3496
|
+
if (Array.isArray(formData)) {
|
|
3497
|
+
const itemsSchema = resolvedSchema.items;
|
|
3498
|
+
if (!itemsSchema) {
|
|
3499
|
+
return formData;
|
|
3500
|
+
}
|
|
3501
|
+
let hasChanges = false;
|
|
3502
|
+
const mapped = formData.map((item, index) => {
|
|
3503
|
+
let itemSchema = itemsSchema;
|
|
3504
|
+
if (Array.isArray(itemsSchema)) {
|
|
3505
|
+
itemSchema = itemsSchema[index] || resolvedSchema.additionalItems || {};
|
|
3506
|
+
}
|
|
3507
|
+
const cleaned = removeOptionalEmptyObjects(validator, itemSchema, rootSchema, item);
|
|
3508
|
+
if (cleaned !== item) {
|
|
3509
|
+
hasChanges = true;
|
|
3510
|
+
}
|
|
3511
|
+
return cleaned === void 0 ? {} : cleaned;
|
|
3512
|
+
});
|
|
3513
|
+
return hasChanges ? mapped : formData;
|
|
3514
|
+
}
|
|
3515
|
+
const { properties, required: requiredFields = [] } = resolvedSchema;
|
|
3516
|
+
if (!isObject(formData) || !properties) {
|
|
3517
|
+
return formData;
|
|
3518
|
+
}
|
|
3519
|
+
const result = {};
|
|
3520
|
+
const data = formData;
|
|
3521
|
+
let hasAnyValue = false;
|
|
3522
|
+
for (const key of Object.keys(data)) {
|
|
3523
|
+
const value = data[key];
|
|
3524
|
+
const propertySchema = properties[key] || {};
|
|
3525
|
+
const isRequired = requiredFields.includes(key);
|
|
3526
|
+
const isObj = isObject(value);
|
|
3527
|
+
const isArr = Array.isArray(value);
|
|
3528
|
+
if ((isObj || isArr) && properties[key]) {
|
|
3529
|
+
const cleaned = removeOptionalEmptyObjects(validator, propertySchema, rootSchema, value);
|
|
3530
|
+
if (!isRequired && isValueEmpty(cleaned)) {
|
|
3531
|
+
continue;
|
|
3532
|
+
}
|
|
3533
|
+
result[key] = cleaned;
|
|
3534
|
+
hasAnyValue = true;
|
|
3535
|
+
} else if (isRequired || !isValueEmpty(value) || !properties[key]) {
|
|
3536
|
+
result[key] = value;
|
|
3537
|
+
if (!isValueEmpty(value)) {
|
|
3538
|
+
hasAnyValue = true;
|
|
3539
|
+
}
|
|
3540
|
+
}
|
|
3541
|
+
}
|
|
3542
|
+
if (!hasAnyValue && Object.keys(result).length === 0) {
|
|
3543
|
+
return void 0;
|
|
3544
|
+
}
|
|
3545
|
+
return result;
|
|
3546
|
+
}
|
|
3547
|
+
|
|
3369
3548
|
// src/resolveUiSchema.ts
|
|
3370
3549
|
import isEmpty7 from "lodash/isEmpty";
|
|
3371
3550
|
function resolveUiSchema(schema, localUiSchema, registry) {
|
|
@@ -3436,6 +3615,31 @@ function schemaRequiresTrueValue(schema) {
|
|
|
3436
3615
|
return false;
|
|
3437
3616
|
}
|
|
3438
3617
|
|
|
3618
|
+
// src/shallowEquals.ts
|
|
3619
|
+
function shallowEquals(a, b) {
|
|
3620
|
+
if (Object.is(a, b)) {
|
|
3621
|
+
return true;
|
|
3622
|
+
}
|
|
3623
|
+
if (a == null || b == null) {
|
|
3624
|
+
return false;
|
|
3625
|
+
}
|
|
3626
|
+
if (typeof a !== "object" || typeof b !== "object") {
|
|
3627
|
+
return false;
|
|
3628
|
+
}
|
|
3629
|
+
const keysA = Object.keys(a);
|
|
3630
|
+
const keysB = Object.keys(b);
|
|
3631
|
+
if (keysA.length !== keysB.length) {
|
|
3632
|
+
return false;
|
|
3633
|
+
}
|
|
3634
|
+
for (let i = 0; i < keysA.length; i++) {
|
|
3635
|
+
const key = keysA[i];
|
|
3636
|
+
if (!Object.prototype.hasOwnProperty.call(b, key) || !Object.is(a[key], b[key])) {
|
|
3637
|
+
return false;
|
|
3638
|
+
}
|
|
3639
|
+
}
|
|
3640
|
+
return true;
|
|
3641
|
+
}
|
|
3642
|
+
|
|
3439
3643
|
// src/shouldRender.ts
|
|
3440
3644
|
function shouldRender(component, nextProps, nextState, updateStrategy = "customDeep") {
|
|
3441
3645
|
if (updateStrategy === "always") {
|
|
@@ -3736,15 +3940,14 @@ function useFileWidgetProps(value, onChange, multiple = false) {
|
|
|
3736
3940
|
[value]
|
|
3737
3941
|
);
|
|
3738
3942
|
const handleChange = useCallback2(
|
|
3739
|
-
(files) => {
|
|
3740
|
-
processFiles(files)
|
|
3741
|
-
|
|
3742
|
-
|
|
3743
|
-
|
|
3744
|
-
|
|
3745
|
-
|
|
3746
|
-
|
|
3747
|
-
});
|
|
3943
|
+
async (files) => {
|
|
3944
|
+
const filesInfoEvent = await processFiles(files);
|
|
3945
|
+
const newValue = filesInfoEvent.map((fileInfo) => fileInfo.dataURL || null);
|
|
3946
|
+
if (multiple) {
|
|
3947
|
+
onChange(values.concat(...newValue));
|
|
3948
|
+
} else {
|
|
3949
|
+
onChange(newValue[0]);
|
|
3950
|
+
}
|
|
3748
3951
|
},
|
|
3749
3952
|
[values, multiple, onChange]
|
|
3750
3953
|
);
|
|
@@ -3828,26 +4031,6 @@ function withIdRefPrefix(schemaNode) {
|
|
|
3828
4031
|
return schemaNode;
|
|
3829
4032
|
}
|
|
3830
4033
|
|
|
3831
|
-
// src/nameGenerators.ts
|
|
3832
|
-
var bracketNameGenerator = (path, idPrefix, isMultiValue) => {
|
|
3833
|
-
if (!path || path.length === 0) {
|
|
3834
|
-
return idPrefix;
|
|
3835
|
-
}
|
|
3836
|
-
const baseName = path.reduce((acc, pathUnit, index) => {
|
|
3837
|
-
if (index === 0) {
|
|
3838
|
-
return `${idPrefix}[${String(pathUnit)}]`;
|
|
3839
|
-
}
|
|
3840
|
-
return `${acc}[${String(pathUnit)}]`;
|
|
3841
|
-
}, "");
|
|
3842
|
-
return isMultiValue ? `${baseName}[]` : baseName;
|
|
3843
|
-
};
|
|
3844
|
-
var dotNotationNameGenerator = (path, idPrefix, _isMultiValue) => {
|
|
3845
|
-
if (!path || path.length === 0) {
|
|
3846
|
-
return idPrefix;
|
|
3847
|
-
}
|
|
3848
|
-
return `${idPrefix}.${path.map(String).join(".")}`;
|
|
3849
|
-
};
|
|
3850
|
-
|
|
3851
4034
|
// src/enums.ts
|
|
3852
4035
|
var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
|
|
3853
4036
|
TranslatableString2["ArrayItemTitle"] = "Item";
|
|
@@ -4113,6 +4296,7 @@ export {
|
|
|
4113
4296
|
isObject,
|
|
4114
4297
|
isRootSchema,
|
|
4115
4298
|
isSelect,
|
|
4299
|
+
isValueEmpty,
|
|
4116
4300
|
labelValue,
|
|
4117
4301
|
localToUTC,
|
|
4118
4302
|
lookupFromFormContext,
|
|
@@ -4127,6 +4311,7 @@ export {
|
|
|
4127
4311
|
pad,
|
|
4128
4312
|
parseDateString,
|
|
4129
4313
|
rangeSpec,
|
|
4314
|
+
relaxOptionsForScoring,
|
|
4130
4315
|
removeOptionalEmptyObjects,
|
|
4131
4316
|
replaceStringParameters,
|
|
4132
4317
|
resolveUiSchema,
|