@rjsf/utils 6.1.2 → 6.2.4
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 +228 -155
- package/dist/index.cjs.map +4 -4
- package/dist/utils.esm.js +228 -155
- package/dist/utils.esm.js.map +4 -4
- package/dist/utils.umd.js +246 -178
- 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/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 +1 -1
- 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/toPathSchema.ts +2 -1
- package/src/types.ts +19 -1
package/dist/utils.esm.js
CHANGED
|
@@ -1519,7 +1519,7 @@ function computeDefaults(validator, rawSchema, computeDefaultsProps = {}) {
|
|
|
1519
1519
|
let updatedRecurseList = _recurseList;
|
|
1520
1520
|
if (schema[CONST_KEY] !== void 0 && experimental_defaultFormStateBehavior?.constAsDefaults !== "never" && !constIsAjvDataReference(schema)) {
|
|
1521
1521
|
defaults = schema[CONST_KEY];
|
|
1522
|
-
} 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]) {
|
|
1523
1523
|
defaults = mergeObjects(defaults, schema.default);
|
|
1524
1524
|
} else if (DEFAULT_KEY in schema && !schema[ANY_OF_KEY] && !schema[ONE_OF_KEY] && !schema[REF_KEY]) {
|
|
1525
1525
|
defaults = schema.default;
|
|
@@ -1529,7 +1529,8 @@ function computeDefaults(validator, rawSchema, computeDefaultsProps = {}) {
|
|
|
1529
1529
|
updatedRecurseList = _recurseList.concat(refName);
|
|
1530
1530
|
schemaToCompute = findSchemaDefinition(refName, rootSchema);
|
|
1531
1531
|
}
|
|
1532
|
-
|
|
1532
|
+
const hasNoExistingData = rawFormData === void 0 || isObject(rawFormData) && isEmpty4(rawFormData);
|
|
1533
|
+
if (schemaToCompute && !defaults && hasNoExistingData) {
|
|
1533
1534
|
defaults = schema.default;
|
|
1534
1535
|
}
|
|
1535
1536
|
if (shouldMergeDefaultsIntoFormData && schemaToCompute && !isObject(rawFormData)) {
|
|
@@ -1673,7 +1674,8 @@ function getObjectDefaults(validator, rawSchema, {
|
|
|
1673
1674
|
{
|
|
1674
1675
|
const formData = isObject(rawFormData) ? rawFormData : {};
|
|
1675
1676
|
const schema = rawSchema;
|
|
1676
|
-
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;
|
|
1677
1679
|
const parentConst = retrievedSchema[CONST_KEY];
|
|
1678
1680
|
const objectDefaults = Object.keys(retrievedSchema.properties || {}).reduce(
|
|
1679
1681
|
(acc, key) => {
|
|
@@ -1767,12 +1769,14 @@ function getArrayDefaults(validator, rawSchema, {
|
|
|
1767
1769
|
if (Array.isArray(defaults)) {
|
|
1768
1770
|
defaults = defaults.map((item, idx) => {
|
|
1769
1771
|
const schemaItem = getInnerSchemaForArrayItem(schema, 2 /* Fallback */, idx);
|
|
1772
|
+
const itemFormData = Array.isArray(rawFormData) ? rawFormData[idx] : void 0;
|
|
1770
1773
|
return computeDefaults(validator, schemaItem, {
|
|
1771
1774
|
rootSchema,
|
|
1772
1775
|
_recurseList,
|
|
1773
1776
|
experimental_defaultFormStateBehavior,
|
|
1774
1777
|
experimental_customMergeAllOf,
|
|
1775
1778
|
parentDefaults: item,
|
|
1779
|
+
rawFormData: itemFormData,
|
|
1776
1780
|
required,
|
|
1777
1781
|
shouldMergeDefaultsIntoFormData,
|
|
1778
1782
|
initialDefaultsGenerated
|
|
@@ -1937,8 +1941,175 @@ function getDisplayLabel(validator, schema, uiSchema = {}, rootSchema, globalOpt
|
|
|
1937
1941
|
return displayLabel;
|
|
1938
1942
|
}
|
|
1939
1943
|
|
|
1940
|
-
// 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
|
|
1941
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";
|
|
1942
2113
|
import has5 from "lodash/has";
|
|
1943
2114
|
var NO_VALUE = Symbol("no Value");
|
|
1944
2115
|
function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, data = {}, experimental_customMergeAllOf) {
|
|
@@ -1946,19 +2117,19 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1946
2117
|
if (has5(newSchema, PROPERTIES_KEY)) {
|
|
1947
2118
|
const removeOldSchemaData = {};
|
|
1948
2119
|
if (has5(oldSchema, PROPERTIES_KEY)) {
|
|
1949
|
-
const properties =
|
|
2120
|
+
const properties = get16(oldSchema, PROPERTIES_KEY, {});
|
|
1950
2121
|
Object.keys(properties).forEach((key) => {
|
|
1951
2122
|
if (has5(data, key)) {
|
|
1952
2123
|
removeOldSchemaData[key] = void 0;
|
|
1953
2124
|
}
|
|
1954
2125
|
});
|
|
1955
2126
|
}
|
|
1956
|
-
const keys2 = Object.keys(
|
|
2127
|
+
const keys2 = Object.keys(get16(newSchema, PROPERTIES_KEY, {}));
|
|
1957
2128
|
const nestedData = {};
|
|
1958
2129
|
keys2.forEach((key) => {
|
|
1959
|
-
const formValue =
|
|
1960
|
-
let oldKeyedSchema =
|
|
1961
|
-
let newKeyedSchema =
|
|
2130
|
+
const formValue = get16(data, key);
|
|
2131
|
+
let oldKeyedSchema = get16(oldSchema, [PROPERTIES_KEY, key], {});
|
|
2132
|
+
let newKeyedSchema = get16(newSchema, [PROPERTIES_KEY, key], {});
|
|
1962
2133
|
if (has5(oldKeyedSchema, REF_KEY)) {
|
|
1963
2134
|
oldKeyedSchema = retrieveSchema(
|
|
1964
2135
|
validator,
|
|
@@ -1977,8 +2148,8 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1977
2148
|
experimental_customMergeAllOf
|
|
1978
2149
|
);
|
|
1979
2150
|
}
|
|
1980
|
-
const oldSchemaTypeForKey =
|
|
1981
|
-
const newSchemaTypeForKey =
|
|
2151
|
+
const oldSchemaTypeForKey = get16(oldKeyedSchema, "type");
|
|
2152
|
+
const newSchemaTypeForKey = get16(newKeyedSchema, "type");
|
|
1982
2153
|
if (!oldSchemaTypeForKey || oldSchemaTypeForKey === newSchemaTypeForKey) {
|
|
1983
2154
|
if (has5(removeOldSchemaData, key)) {
|
|
1984
2155
|
delete removeOldSchemaData[key];
|
|
@@ -1996,17 +2167,17 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1996
2167
|
nestedData[key] = itemData;
|
|
1997
2168
|
}
|
|
1998
2169
|
} else {
|
|
1999
|
-
const newOptionDefault =
|
|
2000
|
-
const oldOptionDefault =
|
|
2170
|
+
const newOptionDefault = get16(newKeyedSchema, "default", NO_VALUE);
|
|
2171
|
+
const oldOptionDefault = get16(oldKeyedSchema, "default", NO_VALUE);
|
|
2001
2172
|
if (newOptionDefault !== NO_VALUE && newOptionDefault !== formValue) {
|
|
2002
2173
|
if (oldOptionDefault === formValue) {
|
|
2003
2174
|
removeOldSchemaData[key] = newOptionDefault;
|
|
2004
|
-
} else if (
|
|
2175
|
+
} else if (get16(newKeyedSchema, "readOnly") === true) {
|
|
2005
2176
|
removeOldSchemaData[key] = void 0;
|
|
2006
2177
|
}
|
|
2007
2178
|
}
|
|
2008
|
-
const newOptionConst =
|
|
2009
|
-
const oldOptionConst =
|
|
2179
|
+
const newOptionConst = get16(newKeyedSchema, "const", NO_VALUE);
|
|
2180
|
+
const oldOptionConst = get16(oldKeyedSchema, "const", NO_VALUE);
|
|
2010
2181
|
if (newOptionConst !== NO_VALUE && newOptionConst !== formValue) {
|
|
2011
2182
|
removeOldSchemaData[key] = oldOptionConst === formValue ? newOptionConst : void 0;
|
|
2012
2183
|
}
|
|
@@ -2018,9 +2189,9 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
2018
2189
|
...removeOldSchemaData,
|
|
2019
2190
|
...nestedData
|
|
2020
2191
|
};
|
|
2021
|
-
} else if (
|
|
2022
|
-
let oldSchemaItems =
|
|
2023
|
-
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");
|
|
2024
2195
|
if (typeof oldSchemaItems === "object" && typeof newSchemaItems === "object" && !Array.isArray(oldSchemaItems) && !Array.isArray(newSchemaItems)) {
|
|
2025
2196
|
if (has5(oldSchemaItems, REF_KEY)) {
|
|
2026
2197
|
oldSchemaItems = retrieveSchema(
|
|
@@ -2040,10 +2211,10 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
2040
2211
|
experimental_customMergeAllOf
|
|
2041
2212
|
);
|
|
2042
2213
|
}
|
|
2043
|
-
const oldSchemaType =
|
|
2044
|
-
const newSchemaType =
|
|
2214
|
+
const oldSchemaType = get16(oldSchemaItems, "type");
|
|
2215
|
+
const newSchemaType = get16(newSchemaItems, "type");
|
|
2045
2216
|
if (!oldSchemaType || oldSchemaType === newSchemaType) {
|
|
2046
|
-
const maxItems =
|
|
2217
|
+
const maxItems = get16(newSchema, "maxItems", -1);
|
|
2047
2218
|
if (newSchemaType === "object") {
|
|
2048
2219
|
newFormData = data.reduce((newValue, aValue) => {
|
|
2049
2220
|
const itemValue = sanitizeDataForNewSchema(
|
|
@@ -2070,122 +2241,8 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
2070
2241
|
return newFormData;
|
|
2071
2242
|
}
|
|
2072
2243
|
|
|
2073
|
-
// src/schema/toPathSchema.ts
|
|
2074
|
-
import get15 from "lodash/get";
|
|
2075
|
-
import set2 from "lodash/set";
|
|
2076
|
-
function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
|
|
2077
|
-
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
2078
|
-
const _schema = retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf);
|
|
2079
|
-
const sameSchemaIndex = _recurseList.findIndex((item) => deepEquals(item, _schema));
|
|
2080
|
-
if (sameSchemaIndex === -1) {
|
|
2081
|
-
return toPathSchemaInternal(
|
|
2082
|
-
validator,
|
|
2083
|
-
_schema,
|
|
2084
|
-
name,
|
|
2085
|
-
rootSchema,
|
|
2086
|
-
formData,
|
|
2087
|
-
_recurseList.concat(_schema),
|
|
2088
|
-
experimental_customMergeAllOf
|
|
2089
|
-
);
|
|
2090
|
-
}
|
|
2091
|
-
}
|
|
2092
|
-
let pathSchema = {
|
|
2093
|
-
[NAME_KEY]: name.replace(/^\./, "")
|
|
2094
|
-
};
|
|
2095
|
-
if (ONE_OF_KEY in schema || ANY_OF_KEY in schema) {
|
|
2096
|
-
const xxxOf = ONE_OF_KEY in schema ? schema.oneOf : schema.anyOf;
|
|
2097
|
-
const discriminator = getDiscriminatorFieldFromSchema(schema);
|
|
2098
|
-
const index = getClosestMatchingOption(
|
|
2099
|
-
validator,
|
|
2100
|
-
rootSchema,
|
|
2101
|
-
formData,
|
|
2102
|
-
xxxOf,
|
|
2103
|
-
0,
|
|
2104
|
-
discriminator,
|
|
2105
|
-
experimental_customMergeAllOf
|
|
2106
|
-
);
|
|
2107
|
-
const _schema = xxxOf[index];
|
|
2108
|
-
pathSchema = {
|
|
2109
|
-
...pathSchema,
|
|
2110
|
-
...toPathSchemaInternal(
|
|
2111
|
-
validator,
|
|
2112
|
-
_schema,
|
|
2113
|
-
name,
|
|
2114
|
-
rootSchema,
|
|
2115
|
-
formData,
|
|
2116
|
-
_recurseList,
|
|
2117
|
-
experimental_customMergeAllOf
|
|
2118
|
-
)
|
|
2119
|
-
};
|
|
2120
|
-
}
|
|
2121
|
-
if (ADDITIONAL_PROPERTIES_KEY in schema && schema[ADDITIONAL_PROPERTIES_KEY] !== false) {
|
|
2122
|
-
set2(pathSchema, RJSF_ADDITIONAL_PROPERTIES_FLAG, true);
|
|
2123
|
-
}
|
|
2124
|
-
if (ITEMS_KEY in schema && Array.isArray(formData)) {
|
|
2125
|
-
const { items: schemaItems, additionalItems: schemaAdditionalItems } = schema;
|
|
2126
|
-
if (Array.isArray(schemaItems)) {
|
|
2127
|
-
formData.forEach((element, i) => {
|
|
2128
|
-
if (schemaItems[i]) {
|
|
2129
|
-
pathSchema[i] = toPathSchemaInternal(
|
|
2130
|
-
validator,
|
|
2131
|
-
schemaItems[i],
|
|
2132
|
-
`${name}.${i}`,
|
|
2133
|
-
rootSchema,
|
|
2134
|
-
element,
|
|
2135
|
-
_recurseList,
|
|
2136
|
-
experimental_customMergeAllOf
|
|
2137
|
-
);
|
|
2138
|
-
} else if (schemaAdditionalItems) {
|
|
2139
|
-
pathSchema[i] = toPathSchemaInternal(
|
|
2140
|
-
validator,
|
|
2141
|
-
schemaAdditionalItems,
|
|
2142
|
-
`${name}.${i}`,
|
|
2143
|
-
rootSchema,
|
|
2144
|
-
element,
|
|
2145
|
-
_recurseList,
|
|
2146
|
-
experimental_customMergeAllOf
|
|
2147
|
-
);
|
|
2148
|
-
} else {
|
|
2149
|
-
console.warn(`Unable to generate path schema for "${name}.${i}". No schema defined for it`);
|
|
2150
|
-
}
|
|
2151
|
-
});
|
|
2152
|
-
} else {
|
|
2153
|
-
formData.forEach((element, i) => {
|
|
2154
|
-
pathSchema[i] = toPathSchemaInternal(
|
|
2155
|
-
validator,
|
|
2156
|
-
schemaItems,
|
|
2157
|
-
`${name}.${i}`,
|
|
2158
|
-
rootSchema,
|
|
2159
|
-
element,
|
|
2160
|
-
_recurseList,
|
|
2161
|
-
experimental_customMergeAllOf
|
|
2162
|
-
);
|
|
2163
|
-
});
|
|
2164
|
-
}
|
|
2165
|
-
} else if (PROPERTIES_KEY in schema) {
|
|
2166
|
-
for (const property in schema.properties) {
|
|
2167
|
-
const field = get15(schema, [PROPERTIES_KEY, property], {});
|
|
2168
|
-
pathSchema[property] = toPathSchemaInternal(
|
|
2169
|
-
validator,
|
|
2170
|
-
field,
|
|
2171
|
-
`${name}.${property}`,
|
|
2172
|
-
rootSchema,
|
|
2173
|
-
// It's possible that formData is not an object -- this can happen if an
|
|
2174
|
-
// array item has just been added, but not populated with data yet
|
|
2175
|
-
get15(formData, [property]),
|
|
2176
|
-
_recurseList,
|
|
2177
|
-
experimental_customMergeAllOf
|
|
2178
|
-
);
|
|
2179
|
-
}
|
|
2180
|
-
}
|
|
2181
|
-
return pathSchema;
|
|
2182
|
-
}
|
|
2183
|
-
function toPathSchema(validator, schema, name = "", rootSchema, formData, experimental_customMergeAllOf) {
|
|
2184
|
-
return toPathSchemaInternal(validator, schema, name, rootSchema, formData, void 0, experimental_customMergeAllOf);
|
|
2185
|
-
}
|
|
2186
|
-
|
|
2187
2244
|
// src/createSchemaUtils.ts
|
|
2188
|
-
import
|
|
2245
|
+
import get17 from "lodash/get";
|
|
2189
2246
|
var SchemaUtils = class {
|
|
2190
2247
|
/** Constructs the `SchemaUtils` instance with the given `validator` and `rootSchema` stored as instance variables
|
|
2191
2248
|
*
|
|
@@ -2196,7 +2253,7 @@ var SchemaUtils = class {
|
|
|
2196
2253
|
*/
|
|
2197
2254
|
constructor(validator, rootSchema, experimental_defaultFormStateBehavior, experimental_customMergeAllOf) {
|
|
2198
2255
|
if (rootSchema && rootSchema[SCHEMA_KEY] === JSON_SCHEMA_DRAFT_2020_12) {
|
|
2199
|
-
this.rootSchema = makeAllReferencesAbsolute(rootSchema,
|
|
2256
|
+
this.rootSchema = makeAllReferencesAbsolute(rootSchema, get17(rootSchema, ID_KEY, "#"));
|
|
2200
2257
|
} else {
|
|
2201
2258
|
this.rootSchema = rootSchema;
|
|
2202
2259
|
}
|
|
@@ -2388,6 +2445,18 @@ var SchemaUtils = class {
|
|
|
2388
2445
|
isSelect(schema) {
|
|
2389
2446
|
return isSelect(this.validator, schema, this.rootSchema, this.experimental_customMergeAllOf);
|
|
2390
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
|
+
}
|
|
2391
2460
|
/** Retrieves an expanded schema that has had all of its conditions, additional properties, references and
|
|
2392
2461
|
* dependencies resolved and merged into the `schema` given a `rawFormData` that is used to do the potentially
|
|
2393
2462
|
* recursive resolution.
|
|
@@ -2610,7 +2679,7 @@ function enumOptionsSelectValue(valueIndex, selected, allEnumOptions = []) {
|
|
|
2610
2679
|
|
|
2611
2680
|
// src/ErrorSchemaBuilder.ts
|
|
2612
2681
|
import cloneDeep from "lodash/cloneDeep";
|
|
2613
|
-
import
|
|
2682
|
+
import get18 from "lodash/get";
|
|
2614
2683
|
import set3 from "lodash/set";
|
|
2615
2684
|
import setWith from "lodash/setWith";
|
|
2616
2685
|
var ErrorSchemaBuilder = class {
|
|
@@ -2639,7 +2708,7 @@ var ErrorSchemaBuilder = class {
|
|
|
2639
2708
|
*/
|
|
2640
2709
|
getOrCreateErrorBlock(pathOfError) {
|
|
2641
2710
|
const hasPath = Array.isArray(pathOfError) && pathOfError.length > 0 || typeof pathOfError === "string";
|
|
2642
|
-
let errorBlock = hasPath ?
|
|
2711
|
+
let errorBlock = hasPath ? get18(this.errorSchema, pathOfError) : this.errorSchema;
|
|
2643
2712
|
if (!errorBlock && pathOfError) {
|
|
2644
2713
|
errorBlock = {};
|
|
2645
2714
|
setWith(this.errorSchema, pathOfError, errorBlock, Object);
|
|
@@ -2665,7 +2734,7 @@ var ErrorSchemaBuilder = class {
|
|
|
2665
2734
|
*/
|
|
2666
2735
|
addErrors(errorOrList, pathOfError) {
|
|
2667
2736
|
const errorBlock = this.getOrCreateErrorBlock(pathOfError);
|
|
2668
|
-
let errorsList =
|
|
2737
|
+
let errorsList = get18(errorBlock, ERRORS_KEY);
|
|
2669
2738
|
if (!Array.isArray(errorsList)) {
|
|
2670
2739
|
errorsList = [];
|
|
2671
2740
|
errorBlock[ERRORS_KEY] = errorsList;
|
|
@@ -2709,7 +2778,7 @@ var ErrorSchemaBuilder = class {
|
|
|
2709
2778
|
import keys from "lodash/keys";
|
|
2710
2779
|
import pickBy from "lodash/pickBy";
|
|
2711
2780
|
import isPlainObject2 from "lodash/isPlainObject";
|
|
2712
|
-
import
|
|
2781
|
+
import get19 from "lodash/get";
|
|
2713
2782
|
import difference from "lodash/difference";
|
|
2714
2783
|
function getChangedFields(a, b) {
|
|
2715
2784
|
const aIsPlainObject = isPlainObject2(a);
|
|
@@ -2722,7 +2791,7 @@ function getChangedFields(a, b) {
|
|
|
2722
2791
|
} else if (!aIsPlainObject && bIsPlainObject) {
|
|
2723
2792
|
return keys(b);
|
|
2724
2793
|
} else {
|
|
2725
|
-
const unequalFields = keys(pickBy(a, (value, key) => !deepEquals(value,
|
|
2794
|
+
const unequalFields = keys(pickBy(a, (value, key) => !deepEquals(value, get19(b, key))));
|
|
2726
2795
|
const diffFields = difference(keys(b), keys(a));
|
|
2727
2796
|
return [...unequalFields, ...diffFields];
|
|
2728
2797
|
}
|
|
@@ -2836,10 +2905,10 @@ function getTemplate(name, registry, uiOptions = {}) {
|
|
|
2836
2905
|
}
|
|
2837
2906
|
|
|
2838
2907
|
// src/getTestIds.ts
|
|
2839
|
-
import
|
|
2908
|
+
import get20 from "lodash/get";
|
|
2840
2909
|
import uniqueId from "lodash/uniqueId";
|
|
2841
2910
|
function getTestIds() {
|
|
2842
|
-
if (typeof process === "undefined" ||
|
|
2911
|
+
if (typeof process === "undefined" || get20(process, "env.NODE_ENV") !== "test") {
|
|
2843
2912
|
return {};
|
|
2844
2913
|
}
|
|
2845
2914
|
const ids = /* @__PURE__ */ new Map();
|
|
@@ -2859,7 +2928,7 @@ function getTestIds() {
|
|
|
2859
2928
|
// src/getWidget.tsx
|
|
2860
2929
|
import { createElement } from "react";
|
|
2861
2930
|
import ReactIs from "react-is";
|
|
2862
|
-
import
|
|
2931
|
+
import get21 from "lodash/get";
|
|
2863
2932
|
import set4 from "lodash/set";
|
|
2864
2933
|
import { jsx } from "react/jsx-runtime";
|
|
2865
2934
|
var widgetMap = {
|
|
@@ -2915,7 +2984,7 @@ var widgetMap = {
|
|
|
2915
2984
|
}
|
|
2916
2985
|
};
|
|
2917
2986
|
function mergeWidgetOptions(AWidget) {
|
|
2918
|
-
let MergedWidget =
|
|
2987
|
+
let MergedWidget = get21(AWidget, "MergedWidget");
|
|
2919
2988
|
if (!MergedWidget) {
|
|
2920
2989
|
const defaultOptions = AWidget.defaultProps && AWidget.defaultProps.options || {};
|
|
2921
2990
|
MergedWidget = ({ options, ...props }) => {
|
|
@@ -3022,10 +3091,10 @@ function optionalControlsId(id, element) {
|
|
|
3022
3091
|
|
|
3023
3092
|
// src/isFormDataAvailable.ts
|
|
3024
3093
|
import isNil3 from "lodash/isNil";
|
|
3025
|
-
import
|
|
3094
|
+
import isEmpty6 from "lodash/isEmpty";
|
|
3026
3095
|
import isObject4 from "lodash/isObject";
|
|
3027
3096
|
function isFormDataAvailable(formData) {
|
|
3028
|
-
return !isNil3(formData) && (!isObject4(formData) || Array.isArray(formData) || !
|
|
3097
|
+
return !isNil3(formData) && (!isObject4(formData) || Array.isArray(formData) || !isEmpty6(formData));
|
|
3029
3098
|
}
|
|
3030
3099
|
|
|
3031
3100
|
// src/isRootSchema.ts
|
|
@@ -3053,14 +3122,14 @@ function localToUTC(dateString) {
|
|
|
3053
3122
|
}
|
|
3054
3123
|
|
|
3055
3124
|
// src/lookupFromFormContext.ts
|
|
3056
|
-
import
|
|
3125
|
+
import get22 from "lodash/get";
|
|
3057
3126
|
import has6 from "lodash/has";
|
|
3058
3127
|
function lookupFromFormContext(regOrFc, toLookup, fallback) {
|
|
3059
3128
|
const lookupPath = [LOOKUP_MAP_NAME];
|
|
3060
3129
|
if (has6(regOrFc, FORM_CONTEXT_NAME)) {
|
|
3061
3130
|
lookupPath.unshift(FORM_CONTEXT_NAME);
|
|
3062
3131
|
}
|
|
3063
|
-
return
|
|
3132
|
+
return get22(regOrFc, [...lookupPath, toLookup], fallback);
|
|
3064
3133
|
}
|
|
3065
3134
|
|
|
3066
3135
|
// src/orderProperties.ts
|
|
@@ -3484,7 +3553,7 @@ function utcToLocal(jsonDate) {
|
|
|
3484
3553
|
}
|
|
3485
3554
|
|
|
3486
3555
|
// src/validationDataMerge.ts
|
|
3487
|
-
import
|
|
3556
|
+
import isEmpty7 from "lodash/isEmpty";
|
|
3488
3557
|
function validationDataMerge(validationData, additionalErrorSchema, preventDuplicates = false) {
|
|
3489
3558
|
if (!additionalErrorSchema) {
|
|
3490
3559
|
return validationData;
|
|
@@ -3492,7 +3561,7 @@ function validationDataMerge(validationData, additionalErrorSchema, preventDupli
|
|
|
3492
3561
|
const { errors: oldErrors, errorSchema: oldErrorSchema } = validationData;
|
|
3493
3562
|
let errors = toErrorList(additionalErrorSchema);
|
|
3494
3563
|
let errorSchema = additionalErrorSchema;
|
|
3495
|
-
if (!
|
|
3564
|
+
if (!isEmpty7(oldErrorSchema)) {
|
|
3496
3565
|
errorSchema = mergeObjects(
|
|
3497
3566
|
oldErrorSchema,
|
|
3498
3567
|
additionalErrorSchema,
|
|
@@ -3580,6 +3649,7 @@ var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
|
|
|
3580
3649
|
TranslatableString2["OptionalObjectEmptyMsg"] = "No data for optional field";
|
|
3581
3650
|
TranslatableString2["Type"] = "Type";
|
|
3582
3651
|
TranslatableString2["Value"] = "Value";
|
|
3652
|
+
TranslatableString2["ClearButton"] = "clear input";
|
|
3583
3653
|
TranslatableString2["UnknownFieldType"] = "Unknown field type %1";
|
|
3584
3654
|
TranslatableString2["OptionPrefix"] = "Option %1";
|
|
3585
3655
|
TranslatableString2["TitleOptionPrefix"] = "%1 option %2";
|
|
@@ -3597,7 +3667,7 @@ var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
|
|
|
3597
3667
|
import forEach from "lodash/forEach";
|
|
3598
3668
|
|
|
3599
3669
|
// src/parser/ParserValidator.ts
|
|
3600
|
-
import
|
|
3670
|
+
import get23 from "lodash/get";
|
|
3601
3671
|
var ParserValidator = class {
|
|
3602
3672
|
/** Construct the ParserValidator for the given `rootSchema`. This `rootSchema` will be stashed in the `schemaMap`
|
|
3603
3673
|
* first.
|
|
@@ -3623,7 +3693,7 @@ var ParserValidator = class {
|
|
|
3623
3693
|
* @param hash - The hash value at which to map the schema
|
|
3624
3694
|
*/
|
|
3625
3695
|
addSchema(schema, hash) {
|
|
3626
|
-
const key =
|
|
3696
|
+
const key = get23(schema, ID_KEY, hash);
|
|
3627
3697
|
const identifiedSchema = { ...schema, [ID_KEY]: key };
|
|
3628
3698
|
const existing = this.schemaMap[key];
|
|
3629
3699
|
if (!existing) {
|
|
@@ -3783,6 +3853,7 @@ export {
|
|
|
3783
3853
|
getDefaultFormState,
|
|
3784
3854
|
getDiscriminatorFieldFromSchema,
|
|
3785
3855
|
getDisplayLabel,
|
|
3856
|
+
getFieldNames,
|
|
3786
3857
|
getFirstMatchingOption,
|
|
3787
3858
|
getFromSchema,
|
|
3788
3859
|
getInputProps,
|
|
@@ -3792,6 +3863,7 @@ export {
|
|
|
3792
3863
|
getTemplate,
|
|
3793
3864
|
getTestIds,
|
|
3794
3865
|
getUiOptions,
|
|
3866
|
+
getUsedFormData,
|
|
3795
3867
|
getWidget,
|
|
3796
3868
|
guessType,
|
|
3797
3869
|
hasWidget,
|
|
@@ -3814,6 +3886,7 @@ export {
|
|
|
3814
3886
|
mergeDefaultsWithFormData,
|
|
3815
3887
|
mergeObjects,
|
|
3816
3888
|
mergeSchemas,
|
|
3889
|
+
omitExtraData,
|
|
3817
3890
|
optionId,
|
|
3818
3891
|
optionalControlsId,
|
|
3819
3892
|
optionsList,
|