@rjsf/utils 6.1.1 → 6.2.3
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 +241 -163
- package/dist/index.cjs.map +4 -4
- package/dist/utils.esm.js +241 -163
- package/dist/utils.esm.js.map +4 -4
- package/dist/utils.umd.js +258 -184
- package/lib/createSchemaUtils.js +13 -1
- package/lib/createSchemaUtils.js.map +1 -1
- package/lib/enums.d.ts +2 -0
- package/lib/enums.js +2 -0
- package/lib/enums.js.map +1 -1
- package/lib/schema/getDefaultFormState.js +21 -8
- package/lib/schema/getDefaultFormState.js.map +1 -1
- package/lib/schema/index.d.ts +4 -1
- package/lib/schema/index.js +4 -1
- package/lib/schema/index.js.map +1 -1
- package/lib/schema/omitExtraData.d.ts +26 -0
- package/lib/schema/omitExtraData.js +79 -0
- package/lib/schema/omitExtraData.js.map +1 -0
- package/lib/schema/retrieveSchema.js +19 -8
- package/lib/schema/retrieveSchema.js.map +1 -1
- package/lib/schema/toPathSchema.js +2 -2
- package/lib/schema/toPathSchema.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types.d.ts +19 -2
- package/package.json +2 -3
- package/src/createSchemaUtils.ts +13 -0
- package/src/enums.ts +2 -0
- package/src/schema/getDefaultFormState.ts +26 -10
- package/src/schema/index.ts +4 -0
- package/src/schema/omitExtraData.ts +93 -0
- package/src/schema/retrieveSchema.ts +22 -8
- package/src/schema/toPathSchema.ts +2 -1
- package/src/types.ts +19 -1
package/dist/utils.esm.js
CHANGED
|
@@ -169,7 +169,9 @@ import transform from "lodash/transform";
|
|
|
169
169
|
import merge from "lodash/merge";
|
|
170
170
|
import flattenDeep from "lodash/flattenDeep";
|
|
171
171
|
import uniq from "lodash/uniq";
|
|
172
|
-
import
|
|
172
|
+
import isEmpty2 from "lodash/isEmpty";
|
|
173
|
+
import { createComparator, createMerger, createShallowAllOfMerge } from "@x0k/json-schema-merge";
|
|
174
|
+
import { createDeduplicator, createIntersector } from "@x0k/json-schema-merge/lib/array";
|
|
173
175
|
|
|
174
176
|
// src/findSchemaDefinition.ts
|
|
175
177
|
import jsonpointer from "jsonpointer";
|
|
@@ -434,7 +436,6 @@ function getFirstMatchingOption(validator, formData, options, rootSchema, discri
|
|
|
434
436
|
}
|
|
435
437
|
|
|
436
438
|
// src/schema/retrieveSchema.ts
|
|
437
|
-
import isEmpty2 from "lodash/isEmpty";
|
|
438
439
|
function retrieveSchema(validator, schema, rootSchema = {}, rawFormData, experimental_customMergeAllOf, resolveAnyOfOrOneOfRefs = false) {
|
|
439
440
|
return retrieveSchemaInternal(
|
|
440
441
|
validator,
|
|
@@ -720,6 +721,15 @@ function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFor
|
|
|
720
721
|
});
|
|
721
722
|
return schema;
|
|
722
723
|
}
|
|
724
|
+
var { compareSchemaDefinitions, compareSchemaValues } = createComparator();
|
|
725
|
+
var { mergeArrayOfSchemaDefinitions } = createMerger({
|
|
726
|
+
intersectJson: createIntersector(compareSchemaValues),
|
|
727
|
+
deduplicateJsonSchemaDef: createDeduplicator(compareSchemaDefinitions)
|
|
728
|
+
});
|
|
729
|
+
var shallowAllOfMerge = createShallowAllOfMerge(mergeArrayOfSchemaDefinitions);
|
|
730
|
+
function mergeAllOf(schema) {
|
|
731
|
+
return shallowAllOfMerge(schema);
|
|
732
|
+
}
|
|
723
733
|
function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expandAllBranches = false, recurseList = [], experimental_customMergeAllOf, resolveAnyOfOrOneOfRefs) {
|
|
724
734
|
if (!isObject(schema)) {
|
|
725
735
|
return [{}];
|
|
@@ -765,12 +775,7 @@ function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expa
|
|
|
765
775
|
if (withContainsSchemas.length) {
|
|
766
776
|
resolvedSchema = { ...resolvedSchema, allOf: withoutContainsSchemas };
|
|
767
777
|
}
|
|
768
|
-
resolvedSchema = experimental_customMergeAllOf ? experimental_customMergeAllOf(resolvedSchema) : mergeAllOf(resolvedSchema
|
|
769
|
-
deep: false,
|
|
770
|
-
resolvers: {
|
|
771
|
-
$defs: mergeAllOf.options.resolvers.definitions
|
|
772
|
-
}
|
|
773
|
-
});
|
|
778
|
+
resolvedSchema = experimental_customMergeAllOf ? experimental_customMergeAllOf(resolvedSchema) : mergeAllOf(resolvedSchema);
|
|
774
779
|
if (withContainsSchemas.length) {
|
|
775
780
|
resolvedSchema.allOf = withContainsSchemas;
|
|
776
781
|
}
|
|
@@ -1514,7 +1519,7 @@ function computeDefaults(validator, rawSchema, computeDefaultsProps = {}) {
|
|
|
1514
1519
|
let updatedRecurseList = _recurseList;
|
|
1515
1520
|
if (schema[CONST_KEY] !== void 0 && experimental_defaultFormStateBehavior?.constAsDefaults !== "never" && !constIsAjvDataReference(schema)) {
|
|
1516
1521
|
defaults = schema[CONST_KEY];
|
|
1517
|
-
} else if (isObject(defaults) && isObject(schema.default)) {
|
|
1522
|
+
} else if (isObject(defaults) && isObject(schema.default) && !schema[ANY_OF_KEY] && !schema[ONE_OF_KEY] && !schema[REF_KEY]) {
|
|
1518
1523
|
defaults = mergeObjects(defaults, schema.default);
|
|
1519
1524
|
} else if (DEFAULT_KEY in schema && !schema[ANY_OF_KEY] && !schema[ONE_OF_KEY] && !schema[REF_KEY]) {
|
|
1520
1525
|
defaults = schema.default;
|
|
@@ -1524,7 +1529,8 @@ function computeDefaults(validator, rawSchema, computeDefaultsProps = {}) {
|
|
|
1524
1529
|
updatedRecurseList = _recurseList.concat(refName);
|
|
1525
1530
|
schemaToCompute = findSchemaDefinition(refName, rootSchema);
|
|
1526
1531
|
}
|
|
1527
|
-
|
|
1532
|
+
const hasNoExistingData = rawFormData === void 0 || isObject(rawFormData) && isEmpty4(rawFormData);
|
|
1533
|
+
if (schemaToCompute && !defaults && hasNoExistingData) {
|
|
1528
1534
|
defaults = schema.default;
|
|
1529
1535
|
}
|
|
1530
1536
|
if (shouldMergeDefaultsIntoFormData && schemaToCompute && !isObject(rawFormData)) {
|
|
@@ -1668,7 +1674,8 @@ function getObjectDefaults(validator, rawSchema, {
|
|
|
1668
1674
|
{
|
|
1669
1675
|
const formData = isObject(rawFormData) ? rawFormData : {};
|
|
1670
1676
|
const schema = rawSchema;
|
|
1671
|
-
const
|
|
1677
|
+
const shouldRetrieveSchema = experimental_defaultFormStateBehavior?.allOf === "populateDefaults" && ALL_OF_KEY in schema || experimental_defaultFormStateBehavior?.emptyObjectFields !== "skipEmptyDefaults" && IF_KEY in schema;
|
|
1678
|
+
const retrievedSchema = shouldRetrieveSchema ? retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf) : schema;
|
|
1672
1679
|
const parentConst = retrievedSchema[CONST_KEY];
|
|
1673
1680
|
const objectDefaults = Object.keys(retrievedSchema.properties || {}).reduce(
|
|
1674
1681
|
(acc, key) => {
|
|
@@ -1762,12 +1769,14 @@ function getArrayDefaults(validator, rawSchema, {
|
|
|
1762
1769
|
if (Array.isArray(defaults)) {
|
|
1763
1770
|
defaults = defaults.map((item, idx) => {
|
|
1764
1771
|
const schemaItem = getInnerSchemaForArrayItem(schema, 2 /* Fallback */, idx);
|
|
1772
|
+
const itemFormData = Array.isArray(rawFormData) ? rawFormData[idx] : void 0;
|
|
1765
1773
|
return computeDefaults(validator, schemaItem, {
|
|
1766
1774
|
rootSchema,
|
|
1767
1775
|
_recurseList,
|
|
1768
1776
|
experimental_defaultFormStateBehavior,
|
|
1769
1777
|
experimental_customMergeAllOf,
|
|
1770
1778
|
parentDefaults: item,
|
|
1779
|
+
rawFormData: itemFormData,
|
|
1771
1780
|
required,
|
|
1772
1781
|
shouldMergeDefaultsIntoFormData,
|
|
1773
1782
|
initialDefaultsGenerated
|
|
@@ -1932,8 +1941,175 @@ function getDisplayLabel(validator, schema, uiSchema = {}, rootSchema, globalOpt
|
|
|
1932
1941
|
return displayLabel;
|
|
1933
1942
|
}
|
|
1934
1943
|
|
|
1935
|
-
// src/schema/
|
|
1944
|
+
// src/schema/omitExtraData.ts
|
|
1945
|
+
import pick from "lodash/pick";
|
|
1946
|
+
import isEmpty5 from "lodash/isEmpty";
|
|
1947
|
+
import get15 from "lodash/get";
|
|
1948
|
+
|
|
1949
|
+
// src/schema/toPathSchema.ts
|
|
1936
1950
|
import get14 from "lodash/get";
|
|
1951
|
+
import set2 from "lodash/set";
|
|
1952
|
+
function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
|
|
1953
|
+
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema || IF_KEY in schema) {
|
|
1954
|
+
const _schema = retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf);
|
|
1955
|
+
const sameSchemaIndex = _recurseList.findIndex((item) => deepEquals(item, _schema));
|
|
1956
|
+
if (sameSchemaIndex === -1) {
|
|
1957
|
+
return toPathSchemaInternal(
|
|
1958
|
+
validator,
|
|
1959
|
+
_schema,
|
|
1960
|
+
name,
|
|
1961
|
+
rootSchema,
|
|
1962
|
+
formData,
|
|
1963
|
+
_recurseList.concat(_schema),
|
|
1964
|
+
experimental_customMergeAllOf
|
|
1965
|
+
);
|
|
1966
|
+
}
|
|
1967
|
+
}
|
|
1968
|
+
let pathSchema = {
|
|
1969
|
+
[NAME_KEY]: name.replace(/^\./, "")
|
|
1970
|
+
};
|
|
1971
|
+
if (ONE_OF_KEY in schema || ANY_OF_KEY in schema) {
|
|
1972
|
+
const xxxOf = ONE_OF_KEY in schema ? schema.oneOf : schema.anyOf;
|
|
1973
|
+
const discriminator = getDiscriminatorFieldFromSchema(schema);
|
|
1974
|
+
const index = getClosestMatchingOption(
|
|
1975
|
+
validator,
|
|
1976
|
+
rootSchema,
|
|
1977
|
+
formData,
|
|
1978
|
+
xxxOf,
|
|
1979
|
+
0,
|
|
1980
|
+
discriminator,
|
|
1981
|
+
experimental_customMergeAllOf
|
|
1982
|
+
);
|
|
1983
|
+
const _schema = xxxOf[index];
|
|
1984
|
+
pathSchema = {
|
|
1985
|
+
...pathSchema,
|
|
1986
|
+
...toPathSchemaInternal(
|
|
1987
|
+
validator,
|
|
1988
|
+
_schema,
|
|
1989
|
+
name,
|
|
1990
|
+
rootSchema,
|
|
1991
|
+
formData,
|
|
1992
|
+
_recurseList,
|
|
1993
|
+
experimental_customMergeAllOf
|
|
1994
|
+
)
|
|
1995
|
+
};
|
|
1996
|
+
}
|
|
1997
|
+
if (ADDITIONAL_PROPERTIES_KEY in schema && schema[ADDITIONAL_PROPERTIES_KEY] !== false) {
|
|
1998
|
+
set2(pathSchema, RJSF_ADDITIONAL_PROPERTIES_FLAG, true);
|
|
1999
|
+
}
|
|
2000
|
+
if (ITEMS_KEY in schema && Array.isArray(formData)) {
|
|
2001
|
+
const { items: schemaItems, additionalItems: schemaAdditionalItems } = schema;
|
|
2002
|
+
if (Array.isArray(schemaItems)) {
|
|
2003
|
+
formData.forEach((element, i) => {
|
|
2004
|
+
if (schemaItems[i]) {
|
|
2005
|
+
pathSchema[i] = toPathSchemaInternal(
|
|
2006
|
+
validator,
|
|
2007
|
+
schemaItems[i],
|
|
2008
|
+
`${name}.${i}`,
|
|
2009
|
+
rootSchema,
|
|
2010
|
+
element,
|
|
2011
|
+
_recurseList,
|
|
2012
|
+
experimental_customMergeAllOf
|
|
2013
|
+
);
|
|
2014
|
+
} else if (schemaAdditionalItems) {
|
|
2015
|
+
pathSchema[i] = toPathSchemaInternal(
|
|
2016
|
+
validator,
|
|
2017
|
+
schemaAdditionalItems,
|
|
2018
|
+
`${name}.${i}`,
|
|
2019
|
+
rootSchema,
|
|
2020
|
+
element,
|
|
2021
|
+
_recurseList,
|
|
2022
|
+
experimental_customMergeAllOf
|
|
2023
|
+
);
|
|
2024
|
+
} else {
|
|
2025
|
+
console.warn(`Unable to generate path schema for "${name}.${i}". No schema defined for it`);
|
|
2026
|
+
}
|
|
2027
|
+
});
|
|
2028
|
+
} else {
|
|
2029
|
+
formData.forEach((element, i) => {
|
|
2030
|
+
pathSchema[i] = toPathSchemaInternal(
|
|
2031
|
+
validator,
|
|
2032
|
+
schemaItems,
|
|
2033
|
+
`${name}.${i}`,
|
|
2034
|
+
rootSchema,
|
|
2035
|
+
element,
|
|
2036
|
+
_recurseList,
|
|
2037
|
+
experimental_customMergeAllOf
|
|
2038
|
+
);
|
|
2039
|
+
});
|
|
2040
|
+
}
|
|
2041
|
+
} else if (PROPERTIES_KEY in schema) {
|
|
2042
|
+
for (const property in schema.properties) {
|
|
2043
|
+
const field = get14(schema, [PROPERTIES_KEY, property], {});
|
|
2044
|
+
pathSchema[property] = toPathSchemaInternal(
|
|
2045
|
+
validator,
|
|
2046
|
+
field,
|
|
2047
|
+
`${name}.${property}`,
|
|
2048
|
+
rootSchema,
|
|
2049
|
+
// It's possible that formData is not an object -- this can happen if an
|
|
2050
|
+
// array item has just been added, but not populated with data yet
|
|
2051
|
+
get14(formData, [property]),
|
|
2052
|
+
_recurseList,
|
|
2053
|
+
experimental_customMergeAllOf
|
|
2054
|
+
);
|
|
2055
|
+
}
|
|
2056
|
+
}
|
|
2057
|
+
return pathSchema;
|
|
2058
|
+
}
|
|
2059
|
+
function toPathSchema(validator, schema, name = "", rootSchema, formData, experimental_customMergeAllOf) {
|
|
2060
|
+
return toPathSchemaInternal(validator, schema, name, rootSchema, formData, void 0, experimental_customMergeAllOf);
|
|
2061
|
+
}
|
|
2062
|
+
|
|
2063
|
+
// src/schema/omitExtraData.ts
|
|
2064
|
+
function getUsedFormData(formData, fields) {
|
|
2065
|
+
if (fields.length === 0 && typeof formData !== "object") {
|
|
2066
|
+
return formData;
|
|
2067
|
+
}
|
|
2068
|
+
const data = pick(formData, fields);
|
|
2069
|
+
if (Array.isArray(formData)) {
|
|
2070
|
+
return Object.keys(data).map((key) => data[key]);
|
|
2071
|
+
}
|
|
2072
|
+
return data;
|
|
2073
|
+
}
|
|
2074
|
+
function getFieldNames(pathSchema, formData) {
|
|
2075
|
+
const formValueHasData = (value, isLeaf) => typeof value !== "object" || isEmpty5(value) || isLeaf && !isEmpty5(value);
|
|
2076
|
+
const getAllPaths = (_obj, acc = [], paths = [[]]) => {
|
|
2077
|
+
const objKeys = Object.keys(_obj);
|
|
2078
|
+
objKeys.forEach((key) => {
|
|
2079
|
+
const data = _obj[key];
|
|
2080
|
+
if (typeof data === "object") {
|
|
2081
|
+
const newPaths = paths.map((path) => [...path, key]);
|
|
2082
|
+
if (data[RJSF_ADDITIONAL_PROPERTIES_FLAG] && data[NAME_KEY] !== "") {
|
|
2083
|
+
acc.push(data[NAME_KEY]);
|
|
2084
|
+
} else {
|
|
2085
|
+
getAllPaths(data, acc, newPaths);
|
|
2086
|
+
}
|
|
2087
|
+
} else if (key === NAME_KEY && data !== "") {
|
|
2088
|
+
paths.forEach((path) => {
|
|
2089
|
+
const formValue = get15(formData, path);
|
|
2090
|
+
const isLeaf = objKeys.length === 1;
|
|
2091
|
+
if (formValueHasData(formValue, isLeaf) || Array.isArray(formValue) && formValue.every((val) => formValueHasData(val, isLeaf))) {
|
|
2092
|
+
acc.push(path);
|
|
2093
|
+
}
|
|
2094
|
+
});
|
|
2095
|
+
}
|
|
2096
|
+
});
|
|
2097
|
+
return acc;
|
|
2098
|
+
};
|
|
2099
|
+
return getAllPaths(pathSchema);
|
|
2100
|
+
}
|
|
2101
|
+
function omitExtraData(validator, schema, rootSchema = {}, formData) {
|
|
2102
|
+
const retrievedSchema = retrieveSchema(validator, schema, rootSchema, formData);
|
|
2103
|
+
const pathSchema = toPathSchema(validator, retrievedSchema, "", rootSchema, formData);
|
|
2104
|
+
const fieldNames = getFieldNames(pathSchema, formData);
|
|
2105
|
+
const lodashFieldNames = fieldNames.map(
|
|
2106
|
+
(fieldPaths) => Array.isArray(fieldPaths) ? fieldPaths.join(".") : fieldPaths
|
|
2107
|
+
);
|
|
2108
|
+
return getUsedFormData(formData, lodashFieldNames);
|
|
2109
|
+
}
|
|
2110
|
+
|
|
2111
|
+
// src/schema/sanitizeDataForNewSchema.ts
|
|
2112
|
+
import get16 from "lodash/get";
|
|
1937
2113
|
import has5 from "lodash/has";
|
|
1938
2114
|
var NO_VALUE = Symbol("no Value");
|
|
1939
2115
|
function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, data = {}, experimental_customMergeAllOf) {
|
|
@@ -1941,19 +2117,19 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1941
2117
|
if (has5(newSchema, PROPERTIES_KEY)) {
|
|
1942
2118
|
const removeOldSchemaData = {};
|
|
1943
2119
|
if (has5(oldSchema, PROPERTIES_KEY)) {
|
|
1944
|
-
const properties =
|
|
2120
|
+
const properties = get16(oldSchema, PROPERTIES_KEY, {});
|
|
1945
2121
|
Object.keys(properties).forEach((key) => {
|
|
1946
2122
|
if (has5(data, key)) {
|
|
1947
2123
|
removeOldSchemaData[key] = void 0;
|
|
1948
2124
|
}
|
|
1949
2125
|
});
|
|
1950
2126
|
}
|
|
1951
|
-
const keys2 = Object.keys(
|
|
2127
|
+
const keys2 = Object.keys(get16(newSchema, PROPERTIES_KEY, {}));
|
|
1952
2128
|
const nestedData = {};
|
|
1953
2129
|
keys2.forEach((key) => {
|
|
1954
|
-
const formValue =
|
|
1955
|
-
let oldKeyedSchema =
|
|
1956
|
-
let newKeyedSchema =
|
|
2130
|
+
const formValue = get16(data, key);
|
|
2131
|
+
let oldKeyedSchema = get16(oldSchema, [PROPERTIES_KEY, key], {});
|
|
2132
|
+
let newKeyedSchema = get16(newSchema, [PROPERTIES_KEY, key], {});
|
|
1957
2133
|
if (has5(oldKeyedSchema, REF_KEY)) {
|
|
1958
2134
|
oldKeyedSchema = retrieveSchema(
|
|
1959
2135
|
validator,
|
|
@@ -1972,8 +2148,8 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1972
2148
|
experimental_customMergeAllOf
|
|
1973
2149
|
);
|
|
1974
2150
|
}
|
|
1975
|
-
const oldSchemaTypeForKey =
|
|
1976
|
-
const newSchemaTypeForKey =
|
|
2151
|
+
const oldSchemaTypeForKey = get16(oldKeyedSchema, "type");
|
|
2152
|
+
const newSchemaTypeForKey = get16(newKeyedSchema, "type");
|
|
1977
2153
|
if (!oldSchemaTypeForKey || oldSchemaTypeForKey === newSchemaTypeForKey) {
|
|
1978
2154
|
if (has5(removeOldSchemaData, key)) {
|
|
1979
2155
|
delete removeOldSchemaData[key];
|
|
@@ -1991,17 +2167,17 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1991
2167
|
nestedData[key] = itemData;
|
|
1992
2168
|
}
|
|
1993
2169
|
} else {
|
|
1994
|
-
const newOptionDefault =
|
|
1995
|
-
const oldOptionDefault =
|
|
2170
|
+
const newOptionDefault = get16(newKeyedSchema, "default", NO_VALUE);
|
|
2171
|
+
const oldOptionDefault = get16(oldKeyedSchema, "default", NO_VALUE);
|
|
1996
2172
|
if (newOptionDefault !== NO_VALUE && newOptionDefault !== formValue) {
|
|
1997
2173
|
if (oldOptionDefault === formValue) {
|
|
1998
2174
|
removeOldSchemaData[key] = newOptionDefault;
|
|
1999
|
-
} else if (
|
|
2175
|
+
} else if (get16(newKeyedSchema, "readOnly") === true) {
|
|
2000
2176
|
removeOldSchemaData[key] = void 0;
|
|
2001
2177
|
}
|
|
2002
2178
|
}
|
|
2003
|
-
const newOptionConst =
|
|
2004
|
-
const oldOptionConst =
|
|
2179
|
+
const newOptionConst = get16(newKeyedSchema, "const", NO_VALUE);
|
|
2180
|
+
const oldOptionConst = get16(oldKeyedSchema, "const", NO_VALUE);
|
|
2005
2181
|
if (newOptionConst !== NO_VALUE && newOptionConst !== formValue) {
|
|
2006
2182
|
removeOldSchemaData[key] = oldOptionConst === formValue ? newOptionConst : void 0;
|
|
2007
2183
|
}
|
|
@@ -2013,9 +2189,9 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
2013
2189
|
...removeOldSchemaData,
|
|
2014
2190
|
...nestedData
|
|
2015
2191
|
};
|
|
2016
|
-
} else if (
|
|
2017
|
-
let oldSchemaItems =
|
|
2018
|
-
let newSchemaItems =
|
|
2192
|
+
} else if (get16(oldSchema, "type") === "array" && get16(newSchema, "type") === "array" && Array.isArray(data)) {
|
|
2193
|
+
let oldSchemaItems = get16(oldSchema, "items");
|
|
2194
|
+
let newSchemaItems = get16(newSchema, "items");
|
|
2019
2195
|
if (typeof oldSchemaItems === "object" && typeof newSchemaItems === "object" && !Array.isArray(oldSchemaItems) && !Array.isArray(newSchemaItems)) {
|
|
2020
2196
|
if (has5(oldSchemaItems, REF_KEY)) {
|
|
2021
2197
|
oldSchemaItems = retrieveSchema(
|
|
@@ -2035,10 +2211,10 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
2035
2211
|
experimental_customMergeAllOf
|
|
2036
2212
|
);
|
|
2037
2213
|
}
|
|
2038
|
-
const oldSchemaType =
|
|
2039
|
-
const newSchemaType =
|
|
2214
|
+
const oldSchemaType = get16(oldSchemaItems, "type");
|
|
2215
|
+
const newSchemaType = get16(newSchemaItems, "type");
|
|
2040
2216
|
if (!oldSchemaType || oldSchemaType === newSchemaType) {
|
|
2041
|
-
const maxItems =
|
|
2217
|
+
const maxItems = get16(newSchema, "maxItems", -1);
|
|
2042
2218
|
if (newSchemaType === "object") {
|
|
2043
2219
|
newFormData = data.reduce((newValue, aValue) => {
|
|
2044
2220
|
const itemValue = sanitizeDataForNewSchema(
|
|
@@ -2065,122 +2241,8 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
2065
2241
|
return newFormData;
|
|
2066
2242
|
}
|
|
2067
2243
|
|
|
2068
|
-
// src/schema/toPathSchema.ts
|
|
2069
|
-
import get15 from "lodash/get";
|
|
2070
|
-
import set2 from "lodash/set";
|
|
2071
|
-
function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
|
|
2072
|
-
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
2073
|
-
const _schema = retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf);
|
|
2074
|
-
const sameSchemaIndex = _recurseList.findIndex((item) => deepEquals(item, _schema));
|
|
2075
|
-
if (sameSchemaIndex === -1) {
|
|
2076
|
-
return toPathSchemaInternal(
|
|
2077
|
-
validator,
|
|
2078
|
-
_schema,
|
|
2079
|
-
name,
|
|
2080
|
-
rootSchema,
|
|
2081
|
-
formData,
|
|
2082
|
-
_recurseList.concat(_schema),
|
|
2083
|
-
experimental_customMergeAllOf
|
|
2084
|
-
);
|
|
2085
|
-
}
|
|
2086
|
-
}
|
|
2087
|
-
let pathSchema = {
|
|
2088
|
-
[NAME_KEY]: name.replace(/^\./, "")
|
|
2089
|
-
};
|
|
2090
|
-
if (ONE_OF_KEY in schema || ANY_OF_KEY in schema) {
|
|
2091
|
-
const xxxOf = ONE_OF_KEY in schema ? schema.oneOf : schema.anyOf;
|
|
2092
|
-
const discriminator = getDiscriminatorFieldFromSchema(schema);
|
|
2093
|
-
const index = getClosestMatchingOption(
|
|
2094
|
-
validator,
|
|
2095
|
-
rootSchema,
|
|
2096
|
-
formData,
|
|
2097
|
-
xxxOf,
|
|
2098
|
-
0,
|
|
2099
|
-
discriminator,
|
|
2100
|
-
experimental_customMergeAllOf
|
|
2101
|
-
);
|
|
2102
|
-
const _schema = xxxOf[index];
|
|
2103
|
-
pathSchema = {
|
|
2104
|
-
...pathSchema,
|
|
2105
|
-
...toPathSchemaInternal(
|
|
2106
|
-
validator,
|
|
2107
|
-
_schema,
|
|
2108
|
-
name,
|
|
2109
|
-
rootSchema,
|
|
2110
|
-
formData,
|
|
2111
|
-
_recurseList,
|
|
2112
|
-
experimental_customMergeAllOf
|
|
2113
|
-
)
|
|
2114
|
-
};
|
|
2115
|
-
}
|
|
2116
|
-
if (ADDITIONAL_PROPERTIES_KEY in schema && schema[ADDITIONAL_PROPERTIES_KEY] !== false) {
|
|
2117
|
-
set2(pathSchema, RJSF_ADDITIONAL_PROPERTIES_FLAG, true);
|
|
2118
|
-
}
|
|
2119
|
-
if (ITEMS_KEY in schema && Array.isArray(formData)) {
|
|
2120
|
-
const { items: schemaItems, additionalItems: schemaAdditionalItems } = schema;
|
|
2121
|
-
if (Array.isArray(schemaItems)) {
|
|
2122
|
-
formData.forEach((element, i) => {
|
|
2123
|
-
if (schemaItems[i]) {
|
|
2124
|
-
pathSchema[i] = toPathSchemaInternal(
|
|
2125
|
-
validator,
|
|
2126
|
-
schemaItems[i],
|
|
2127
|
-
`${name}.${i}`,
|
|
2128
|
-
rootSchema,
|
|
2129
|
-
element,
|
|
2130
|
-
_recurseList,
|
|
2131
|
-
experimental_customMergeAllOf
|
|
2132
|
-
);
|
|
2133
|
-
} else if (schemaAdditionalItems) {
|
|
2134
|
-
pathSchema[i] = toPathSchemaInternal(
|
|
2135
|
-
validator,
|
|
2136
|
-
schemaAdditionalItems,
|
|
2137
|
-
`${name}.${i}`,
|
|
2138
|
-
rootSchema,
|
|
2139
|
-
element,
|
|
2140
|
-
_recurseList,
|
|
2141
|
-
experimental_customMergeAllOf
|
|
2142
|
-
);
|
|
2143
|
-
} else {
|
|
2144
|
-
console.warn(`Unable to generate path schema for "${name}.${i}". No schema defined for it`);
|
|
2145
|
-
}
|
|
2146
|
-
});
|
|
2147
|
-
} else {
|
|
2148
|
-
formData.forEach((element, i) => {
|
|
2149
|
-
pathSchema[i] = toPathSchemaInternal(
|
|
2150
|
-
validator,
|
|
2151
|
-
schemaItems,
|
|
2152
|
-
`${name}.${i}`,
|
|
2153
|
-
rootSchema,
|
|
2154
|
-
element,
|
|
2155
|
-
_recurseList,
|
|
2156
|
-
experimental_customMergeAllOf
|
|
2157
|
-
);
|
|
2158
|
-
});
|
|
2159
|
-
}
|
|
2160
|
-
} else if (PROPERTIES_KEY in schema) {
|
|
2161
|
-
for (const property in schema.properties) {
|
|
2162
|
-
const field = get15(schema, [PROPERTIES_KEY, property], {});
|
|
2163
|
-
pathSchema[property] = toPathSchemaInternal(
|
|
2164
|
-
validator,
|
|
2165
|
-
field,
|
|
2166
|
-
`${name}.${property}`,
|
|
2167
|
-
rootSchema,
|
|
2168
|
-
// It's possible that formData is not an object -- this can happen if an
|
|
2169
|
-
// array item has just been added, but not populated with data yet
|
|
2170
|
-
get15(formData, [property]),
|
|
2171
|
-
_recurseList,
|
|
2172
|
-
experimental_customMergeAllOf
|
|
2173
|
-
);
|
|
2174
|
-
}
|
|
2175
|
-
}
|
|
2176
|
-
return pathSchema;
|
|
2177
|
-
}
|
|
2178
|
-
function toPathSchema(validator, schema, name = "", rootSchema, formData, experimental_customMergeAllOf) {
|
|
2179
|
-
return toPathSchemaInternal(validator, schema, name, rootSchema, formData, void 0, experimental_customMergeAllOf);
|
|
2180
|
-
}
|
|
2181
|
-
|
|
2182
2244
|
// src/createSchemaUtils.ts
|
|
2183
|
-
import
|
|
2245
|
+
import get17 from "lodash/get";
|
|
2184
2246
|
var SchemaUtils = class {
|
|
2185
2247
|
/** Constructs the `SchemaUtils` instance with the given `validator` and `rootSchema` stored as instance variables
|
|
2186
2248
|
*
|
|
@@ -2191,7 +2253,7 @@ var SchemaUtils = class {
|
|
|
2191
2253
|
*/
|
|
2192
2254
|
constructor(validator, rootSchema, experimental_defaultFormStateBehavior, experimental_customMergeAllOf) {
|
|
2193
2255
|
if (rootSchema && rootSchema[SCHEMA_KEY] === JSON_SCHEMA_DRAFT_2020_12) {
|
|
2194
|
-
this.rootSchema = makeAllReferencesAbsolute(rootSchema,
|
|
2256
|
+
this.rootSchema = makeAllReferencesAbsolute(rootSchema, get17(rootSchema, ID_KEY, "#"));
|
|
2195
2257
|
} else {
|
|
2196
2258
|
this.rootSchema = rootSchema;
|
|
2197
2259
|
}
|
|
@@ -2383,6 +2445,18 @@ var SchemaUtils = class {
|
|
|
2383
2445
|
isSelect(schema) {
|
|
2384
2446
|
return isSelect(this.validator, schema, this.rootSchema, this.experimental_customMergeAllOf);
|
|
2385
2447
|
}
|
|
2448
|
+
/**
|
|
2449
|
+
* The function takes a `schema` and `formData` and returns a copy of the formData with any fields not defined in the schema removed.
|
|
2450
|
+
* This is useful for ensuring that only data that is relevant to the schema is preserved. Objects with `additionalProperties`
|
|
2451
|
+
* keyword set to `true` will not have their extra fields removed.
|
|
2452
|
+
*
|
|
2453
|
+
* @param schema - The schema to use for filtering the `formData`
|
|
2454
|
+
* @param [formData] - The formData to filter
|
|
2455
|
+
* @returns The new form data, with any fields not defined in the schema removed
|
|
2456
|
+
*/
|
|
2457
|
+
omitExtraData(schema, formData) {
|
|
2458
|
+
return omitExtraData(this.validator, schema, this.rootSchema, formData);
|
|
2459
|
+
}
|
|
2386
2460
|
/** Retrieves an expanded schema that has had all of its conditions, additional properties, references and
|
|
2387
2461
|
* dependencies resolved and merged into the `schema` given a `rawFormData` that is used to do the potentially
|
|
2388
2462
|
* recursive resolution.
|
|
@@ -2605,7 +2679,7 @@ function enumOptionsSelectValue(valueIndex, selected, allEnumOptions = []) {
|
|
|
2605
2679
|
|
|
2606
2680
|
// src/ErrorSchemaBuilder.ts
|
|
2607
2681
|
import cloneDeep from "lodash/cloneDeep";
|
|
2608
|
-
import
|
|
2682
|
+
import get18 from "lodash/get";
|
|
2609
2683
|
import set3 from "lodash/set";
|
|
2610
2684
|
import setWith from "lodash/setWith";
|
|
2611
2685
|
var ErrorSchemaBuilder = class {
|
|
@@ -2634,7 +2708,7 @@ var ErrorSchemaBuilder = class {
|
|
|
2634
2708
|
*/
|
|
2635
2709
|
getOrCreateErrorBlock(pathOfError) {
|
|
2636
2710
|
const hasPath = Array.isArray(pathOfError) && pathOfError.length > 0 || typeof pathOfError === "string";
|
|
2637
|
-
let errorBlock = hasPath ?
|
|
2711
|
+
let errorBlock = hasPath ? get18(this.errorSchema, pathOfError) : this.errorSchema;
|
|
2638
2712
|
if (!errorBlock && pathOfError) {
|
|
2639
2713
|
errorBlock = {};
|
|
2640
2714
|
setWith(this.errorSchema, pathOfError, errorBlock, Object);
|
|
@@ -2660,7 +2734,7 @@ var ErrorSchemaBuilder = class {
|
|
|
2660
2734
|
*/
|
|
2661
2735
|
addErrors(errorOrList, pathOfError) {
|
|
2662
2736
|
const errorBlock = this.getOrCreateErrorBlock(pathOfError);
|
|
2663
|
-
let errorsList =
|
|
2737
|
+
let errorsList = get18(errorBlock, ERRORS_KEY);
|
|
2664
2738
|
if (!Array.isArray(errorsList)) {
|
|
2665
2739
|
errorsList = [];
|
|
2666
2740
|
errorBlock[ERRORS_KEY] = errorsList;
|
|
@@ -2704,7 +2778,7 @@ var ErrorSchemaBuilder = class {
|
|
|
2704
2778
|
import keys from "lodash/keys";
|
|
2705
2779
|
import pickBy from "lodash/pickBy";
|
|
2706
2780
|
import isPlainObject2 from "lodash/isPlainObject";
|
|
2707
|
-
import
|
|
2781
|
+
import get19 from "lodash/get";
|
|
2708
2782
|
import difference from "lodash/difference";
|
|
2709
2783
|
function getChangedFields(a, b) {
|
|
2710
2784
|
const aIsPlainObject = isPlainObject2(a);
|
|
@@ -2717,7 +2791,7 @@ function getChangedFields(a, b) {
|
|
|
2717
2791
|
} else if (!aIsPlainObject && bIsPlainObject) {
|
|
2718
2792
|
return keys(b);
|
|
2719
2793
|
} else {
|
|
2720
|
-
const unequalFields = keys(pickBy(a, (value, key) => !deepEquals(value,
|
|
2794
|
+
const unequalFields = keys(pickBy(a, (value, key) => !deepEquals(value, get19(b, key))));
|
|
2721
2795
|
const diffFields = difference(keys(b), keys(a));
|
|
2722
2796
|
return [...unequalFields, ...diffFields];
|
|
2723
2797
|
}
|
|
@@ -2831,10 +2905,10 @@ function getTemplate(name, registry, uiOptions = {}) {
|
|
|
2831
2905
|
}
|
|
2832
2906
|
|
|
2833
2907
|
// src/getTestIds.ts
|
|
2834
|
-
import
|
|
2908
|
+
import get20 from "lodash/get";
|
|
2835
2909
|
import uniqueId from "lodash/uniqueId";
|
|
2836
2910
|
function getTestIds() {
|
|
2837
|
-
if (typeof process === "undefined" ||
|
|
2911
|
+
if (typeof process === "undefined" || get20(process, "env.NODE_ENV") !== "test") {
|
|
2838
2912
|
return {};
|
|
2839
2913
|
}
|
|
2840
2914
|
const ids = /* @__PURE__ */ new Map();
|
|
@@ -2854,7 +2928,7 @@ function getTestIds() {
|
|
|
2854
2928
|
// src/getWidget.tsx
|
|
2855
2929
|
import { createElement } from "react";
|
|
2856
2930
|
import ReactIs from "react-is";
|
|
2857
|
-
import
|
|
2931
|
+
import get21 from "lodash/get";
|
|
2858
2932
|
import set4 from "lodash/set";
|
|
2859
2933
|
import { jsx } from "react/jsx-runtime";
|
|
2860
2934
|
var widgetMap = {
|
|
@@ -2910,7 +2984,7 @@ var widgetMap = {
|
|
|
2910
2984
|
}
|
|
2911
2985
|
};
|
|
2912
2986
|
function mergeWidgetOptions(AWidget) {
|
|
2913
|
-
let MergedWidget =
|
|
2987
|
+
let MergedWidget = get21(AWidget, "MergedWidget");
|
|
2914
2988
|
if (!MergedWidget) {
|
|
2915
2989
|
const defaultOptions = AWidget.defaultProps && AWidget.defaultProps.options || {};
|
|
2916
2990
|
MergedWidget = ({ options, ...props }) => {
|
|
@@ -3017,10 +3091,10 @@ function optionalControlsId(id, element) {
|
|
|
3017
3091
|
|
|
3018
3092
|
// src/isFormDataAvailable.ts
|
|
3019
3093
|
import isNil3 from "lodash/isNil";
|
|
3020
|
-
import
|
|
3094
|
+
import isEmpty6 from "lodash/isEmpty";
|
|
3021
3095
|
import isObject4 from "lodash/isObject";
|
|
3022
3096
|
function isFormDataAvailable(formData) {
|
|
3023
|
-
return !isNil3(formData) && (!isObject4(formData) || Array.isArray(formData) || !
|
|
3097
|
+
return !isNil3(formData) && (!isObject4(formData) || Array.isArray(formData) || !isEmpty6(formData));
|
|
3024
3098
|
}
|
|
3025
3099
|
|
|
3026
3100
|
// src/isRootSchema.ts
|
|
@@ -3048,14 +3122,14 @@ function localToUTC(dateString) {
|
|
|
3048
3122
|
}
|
|
3049
3123
|
|
|
3050
3124
|
// src/lookupFromFormContext.ts
|
|
3051
|
-
import
|
|
3125
|
+
import get22 from "lodash/get";
|
|
3052
3126
|
import has6 from "lodash/has";
|
|
3053
3127
|
function lookupFromFormContext(regOrFc, toLookup, fallback) {
|
|
3054
3128
|
const lookupPath = [LOOKUP_MAP_NAME];
|
|
3055
3129
|
if (has6(regOrFc, FORM_CONTEXT_NAME)) {
|
|
3056
3130
|
lookupPath.unshift(FORM_CONTEXT_NAME);
|
|
3057
3131
|
}
|
|
3058
|
-
return
|
|
3132
|
+
return get22(regOrFc, [...lookupPath, toLookup], fallback);
|
|
3059
3133
|
}
|
|
3060
3134
|
|
|
3061
3135
|
// src/orderProperties.ts
|
|
@@ -3479,7 +3553,7 @@ function utcToLocal(jsonDate) {
|
|
|
3479
3553
|
}
|
|
3480
3554
|
|
|
3481
3555
|
// src/validationDataMerge.ts
|
|
3482
|
-
import
|
|
3556
|
+
import isEmpty7 from "lodash/isEmpty";
|
|
3483
3557
|
function validationDataMerge(validationData, additionalErrorSchema, preventDuplicates = false) {
|
|
3484
3558
|
if (!additionalErrorSchema) {
|
|
3485
3559
|
return validationData;
|
|
@@ -3487,7 +3561,7 @@ function validationDataMerge(validationData, additionalErrorSchema, preventDupli
|
|
|
3487
3561
|
const { errors: oldErrors, errorSchema: oldErrorSchema } = validationData;
|
|
3488
3562
|
let errors = toErrorList(additionalErrorSchema);
|
|
3489
3563
|
let errorSchema = additionalErrorSchema;
|
|
3490
|
-
if (!
|
|
3564
|
+
if (!isEmpty7(oldErrorSchema)) {
|
|
3491
3565
|
errorSchema = mergeObjects(
|
|
3492
3566
|
oldErrorSchema,
|
|
3493
3567
|
additionalErrorSchema,
|
|
@@ -3575,6 +3649,7 @@ var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
|
|
|
3575
3649
|
TranslatableString2["OptionalObjectEmptyMsg"] = "No data for optional field";
|
|
3576
3650
|
TranslatableString2["Type"] = "Type";
|
|
3577
3651
|
TranslatableString2["Value"] = "Value";
|
|
3652
|
+
TranslatableString2["ClearButton"] = "clear input";
|
|
3578
3653
|
TranslatableString2["UnknownFieldType"] = "Unknown field type %1";
|
|
3579
3654
|
TranslatableString2["OptionPrefix"] = "Option %1";
|
|
3580
3655
|
TranslatableString2["TitleOptionPrefix"] = "%1 option %2";
|
|
@@ -3592,7 +3667,7 @@ var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
|
|
|
3592
3667
|
import forEach from "lodash/forEach";
|
|
3593
3668
|
|
|
3594
3669
|
// src/parser/ParserValidator.ts
|
|
3595
|
-
import
|
|
3670
|
+
import get23 from "lodash/get";
|
|
3596
3671
|
var ParserValidator = class {
|
|
3597
3672
|
/** Construct the ParserValidator for the given `rootSchema`. This `rootSchema` will be stashed in the `schemaMap`
|
|
3598
3673
|
* first.
|
|
@@ -3618,7 +3693,7 @@ var ParserValidator = class {
|
|
|
3618
3693
|
* @param hash - The hash value at which to map the schema
|
|
3619
3694
|
*/
|
|
3620
3695
|
addSchema(schema, hash) {
|
|
3621
|
-
const key =
|
|
3696
|
+
const key = get23(schema, ID_KEY, hash);
|
|
3622
3697
|
const identifiedSchema = { ...schema, [ID_KEY]: key };
|
|
3623
3698
|
const existing = this.schemaMap[key];
|
|
3624
3699
|
if (!existing) {
|
|
@@ -3778,6 +3853,7 @@ export {
|
|
|
3778
3853
|
getDefaultFormState,
|
|
3779
3854
|
getDiscriminatorFieldFromSchema,
|
|
3780
3855
|
getDisplayLabel,
|
|
3856
|
+
getFieldNames,
|
|
3781
3857
|
getFirstMatchingOption,
|
|
3782
3858
|
getFromSchema,
|
|
3783
3859
|
getInputProps,
|
|
@@ -3787,6 +3863,7 @@ export {
|
|
|
3787
3863
|
getTemplate,
|
|
3788
3864
|
getTestIds,
|
|
3789
3865
|
getUiOptions,
|
|
3866
|
+
getUsedFormData,
|
|
3790
3867
|
getWidget,
|
|
3791
3868
|
guessType,
|
|
3792
3869
|
hasWidget,
|
|
@@ -3809,6 +3886,7 @@ export {
|
|
|
3809
3886
|
mergeDefaultsWithFormData,
|
|
3810
3887
|
mergeObjects,
|
|
3811
3888
|
mergeSchemas,
|
|
3889
|
+
omitExtraData,
|
|
3812
3890
|
optionId,
|
|
3813
3891
|
optionalControlsId,
|
|
3814
3892
|
optionsList,
|