@rjsf/utils 6.1.2 → 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 +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/index.cjs
CHANGED
|
@@ -99,6 +99,7 @@ __export(index_exports, {
|
|
|
99
99
|
getDefaultFormState: () => getDefaultFormState,
|
|
100
100
|
getDiscriminatorFieldFromSchema: () => getDiscriminatorFieldFromSchema,
|
|
101
101
|
getDisplayLabel: () => getDisplayLabel,
|
|
102
|
+
getFieldNames: () => getFieldNames,
|
|
102
103
|
getFirstMatchingOption: () => getFirstMatchingOption,
|
|
103
104
|
getFromSchema: () => getFromSchema,
|
|
104
105
|
getInputProps: () => getInputProps,
|
|
@@ -108,6 +109,7 @@ __export(index_exports, {
|
|
|
108
109
|
getTemplate: () => getTemplate,
|
|
109
110
|
getTestIds: () => getTestIds,
|
|
110
111
|
getUiOptions: () => getUiOptions,
|
|
112
|
+
getUsedFormData: () => getUsedFormData,
|
|
111
113
|
getWidget: () => getWidget,
|
|
112
114
|
guessType: () => guessType,
|
|
113
115
|
hasWidget: () => hasWidget,
|
|
@@ -130,6 +132,7 @@ __export(index_exports, {
|
|
|
130
132
|
mergeDefaultsWithFormData: () => mergeDefaultsWithFormData,
|
|
131
133
|
mergeObjects: () => mergeObjects,
|
|
132
134
|
mergeSchemas: () => mergeSchemas,
|
|
135
|
+
omitExtraData: () => omitExtraData,
|
|
133
136
|
optionId: () => optionId,
|
|
134
137
|
optionalControlsId: () => optionalControlsId,
|
|
135
138
|
optionsList: () => optionsList,
|
|
@@ -1684,7 +1687,7 @@ function computeDefaults(validator, rawSchema, computeDefaultsProps = {}) {
|
|
|
1684
1687
|
let updatedRecurseList = _recurseList;
|
|
1685
1688
|
if (schema[CONST_KEY] !== void 0 && experimental_defaultFormStateBehavior?.constAsDefaults !== "never" && !constIsAjvDataReference(schema)) {
|
|
1686
1689
|
defaults = schema[CONST_KEY];
|
|
1687
|
-
} else if (isObject(defaults) && isObject(schema.default)) {
|
|
1690
|
+
} else if (isObject(defaults) && isObject(schema.default) && !schema[ANY_OF_KEY] && !schema[ONE_OF_KEY] && !schema[REF_KEY]) {
|
|
1688
1691
|
defaults = mergeObjects(defaults, schema.default);
|
|
1689
1692
|
} else if (DEFAULT_KEY in schema && !schema[ANY_OF_KEY] && !schema[ONE_OF_KEY] && !schema[REF_KEY]) {
|
|
1690
1693
|
defaults = schema.default;
|
|
@@ -1694,7 +1697,8 @@ function computeDefaults(validator, rawSchema, computeDefaultsProps = {}) {
|
|
|
1694
1697
|
updatedRecurseList = _recurseList.concat(refName);
|
|
1695
1698
|
schemaToCompute = findSchemaDefinition(refName, rootSchema);
|
|
1696
1699
|
}
|
|
1697
|
-
|
|
1700
|
+
const hasNoExistingData = rawFormData === void 0 || isObject(rawFormData) && (0, import_isEmpty4.default)(rawFormData);
|
|
1701
|
+
if (schemaToCompute && !defaults && hasNoExistingData) {
|
|
1698
1702
|
defaults = schema.default;
|
|
1699
1703
|
}
|
|
1700
1704
|
if (shouldMergeDefaultsIntoFormData && schemaToCompute && !isObject(rawFormData)) {
|
|
@@ -1838,7 +1842,8 @@ function getObjectDefaults(validator, rawSchema, {
|
|
|
1838
1842
|
{
|
|
1839
1843
|
const formData = isObject(rawFormData) ? rawFormData : {};
|
|
1840
1844
|
const schema = rawSchema;
|
|
1841
|
-
const
|
|
1845
|
+
const shouldRetrieveSchema = experimental_defaultFormStateBehavior?.allOf === "populateDefaults" && ALL_OF_KEY in schema || experimental_defaultFormStateBehavior?.emptyObjectFields !== "skipEmptyDefaults" && IF_KEY in schema;
|
|
1846
|
+
const retrievedSchema = shouldRetrieveSchema ? retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf) : schema;
|
|
1842
1847
|
const parentConst = retrievedSchema[CONST_KEY];
|
|
1843
1848
|
const objectDefaults = Object.keys(retrievedSchema.properties || {}).reduce(
|
|
1844
1849
|
(acc, key) => {
|
|
@@ -1932,12 +1937,14 @@ function getArrayDefaults(validator, rawSchema, {
|
|
|
1932
1937
|
if (Array.isArray(defaults)) {
|
|
1933
1938
|
defaults = defaults.map((item, idx) => {
|
|
1934
1939
|
const schemaItem = getInnerSchemaForArrayItem(schema, 2 /* Fallback */, idx);
|
|
1940
|
+
const itemFormData = Array.isArray(rawFormData) ? rawFormData[idx] : void 0;
|
|
1935
1941
|
return computeDefaults(validator, schemaItem, {
|
|
1936
1942
|
rootSchema,
|
|
1937
1943
|
_recurseList,
|
|
1938
1944
|
experimental_defaultFormStateBehavior,
|
|
1939
1945
|
experimental_customMergeAllOf,
|
|
1940
1946
|
parentDefaults: item,
|
|
1947
|
+
rawFormData: itemFormData,
|
|
1941
1948
|
required,
|
|
1942
1949
|
shouldMergeDefaultsIntoFormData,
|
|
1943
1950
|
initialDefaultsGenerated
|
|
@@ -2102,8 +2109,175 @@ function getDisplayLabel(validator, schema, uiSchema = {}, rootSchema, globalOpt
|
|
|
2102
2109
|
return displayLabel;
|
|
2103
2110
|
}
|
|
2104
2111
|
|
|
2105
|
-
// src/schema/
|
|
2112
|
+
// src/schema/omitExtraData.ts
|
|
2113
|
+
var import_pick = __toESM(require("lodash/pick"), 1);
|
|
2114
|
+
var import_isEmpty5 = __toESM(require("lodash/isEmpty"), 1);
|
|
2115
|
+
var import_get15 = __toESM(require("lodash/get"), 1);
|
|
2116
|
+
|
|
2117
|
+
// src/schema/toPathSchema.ts
|
|
2106
2118
|
var import_get14 = __toESM(require("lodash/get"), 1);
|
|
2119
|
+
var import_set2 = __toESM(require("lodash/set"), 1);
|
|
2120
|
+
function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
|
|
2121
|
+
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema || IF_KEY in schema) {
|
|
2122
|
+
const _schema = retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf);
|
|
2123
|
+
const sameSchemaIndex = _recurseList.findIndex((item) => deepEquals(item, _schema));
|
|
2124
|
+
if (sameSchemaIndex === -1) {
|
|
2125
|
+
return toPathSchemaInternal(
|
|
2126
|
+
validator,
|
|
2127
|
+
_schema,
|
|
2128
|
+
name,
|
|
2129
|
+
rootSchema,
|
|
2130
|
+
formData,
|
|
2131
|
+
_recurseList.concat(_schema),
|
|
2132
|
+
experimental_customMergeAllOf
|
|
2133
|
+
);
|
|
2134
|
+
}
|
|
2135
|
+
}
|
|
2136
|
+
let pathSchema = {
|
|
2137
|
+
[NAME_KEY]: name.replace(/^\./, "")
|
|
2138
|
+
};
|
|
2139
|
+
if (ONE_OF_KEY in schema || ANY_OF_KEY in schema) {
|
|
2140
|
+
const xxxOf = ONE_OF_KEY in schema ? schema.oneOf : schema.anyOf;
|
|
2141
|
+
const discriminator = getDiscriminatorFieldFromSchema(schema);
|
|
2142
|
+
const index = getClosestMatchingOption(
|
|
2143
|
+
validator,
|
|
2144
|
+
rootSchema,
|
|
2145
|
+
formData,
|
|
2146
|
+
xxxOf,
|
|
2147
|
+
0,
|
|
2148
|
+
discriminator,
|
|
2149
|
+
experimental_customMergeAllOf
|
|
2150
|
+
);
|
|
2151
|
+
const _schema = xxxOf[index];
|
|
2152
|
+
pathSchema = {
|
|
2153
|
+
...pathSchema,
|
|
2154
|
+
...toPathSchemaInternal(
|
|
2155
|
+
validator,
|
|
2156
|
+
_schema,
|
|
2157
|
+
name,
|
|
2158
|
+
rootSchema,
|
|
2159
|
+
formData,
|
|
2160
|
+
_recurseList,
|
|
2161
|
+
experimental_customMergeAllOf
|
|
2162
|
+
)
|
|
2163
|
+
};
|
|
2164
|
+
}
|
|
2165
|
+
if (ADDITIONAL_PROPERTIES_KEY in schema && schema[ADDITIONAL_PROPERTIES_KEY] !== false) {
|
|
2166
|
+
(0, import_set2.default)(pathSchema, RJSF_ADDITIONAL_PROPERTIES_FLAG, true);
|
|
2167
|
+
}
|
|
2168
|
+
if (ITEMS_KEY in schema && Array.isArray(formData)) {
|
|
2169
|
+
const { items: schemaItems, additionalItems: schemaAdditionalItems } = schema;
|
|
2170
|
+
if (Array.isArray(schemaItems)) {
|
|
2171
|
+
formData.forEach((element, i) => {
|
|
2172
|
+
if (schemaItems[i]) {
|
|
2173
|
+
pathSchema[i] = toPathSchemaInternal(
|
|
2174
|
+
validator,
|
|
2175
|
+
schemaItems[i],
|
|
2176
|
+
`${name}.${i}`,
|
|
2177
|
+
rootSchema,
|
|
2178
|
+
element,
|
|
2179
|
+
_recurseList,
|
|
2180
|
+
experimental_customMergeAllOf
|
|
2181
|
+
);
|
|
2182
|
+
} else if (schemaAdditionalItems) {
|
|
2183
|
+
pathSchema[i] = toPathSchemaInternal(
|
|
2184
|
+
validator,
|
|
2185
|
+
schemaAdditionalItems,
|
|
2186
|
+
`${name}.${i}`,
|
|
2187
|
+
rootSchema,
|
|
2188
|
+
element,
|
|
2189
|
+
_recurseList,
|
|
2190
|
+
experimental_customMergeAllOf
|
|
2191
|
+
);
|
|
2192
|
+
} else {
|
|
2193
|
+
console.warn(`Unable to generate path schema for "${name}.${i}". No schema defined for it`);
|
|
2194
|
+
}
|
|
2195
|
+
});
|
|
2196
|
+
} else {
|
|
2197
|
+
formData.forEach((element, i) => {
|
|
2198
|
+
pathSchema[i] = toPathSchemaInternal(
|
|
2199
|
+
validator,
|
|
2200
|
+
schemaItems,
|
|
2201
|
+
`${name}.${i}`,
|
|
2202
|
+
rootSchema,
|
|
2203
|
+
element,
|
|
2204
|
+
_recurseList,
|
|
2205
|
+
experimental_customMergeAllOf
|
|
2206
|
+
);
|
|
2207
|
+
});
|
|
2208
|
+
}
|
|
2209
|
+
} else if (PROPERTIES_KEY in schema) {
|
|
2210
|
+
for (const property in schema.properties) {
|
|
2211
|
+
const field = (0, import_get14.default)(schema, [PROPERTIES_KEY, property], {});
|
|
2212
|
+
pathSchema[property] = toPathSchemaInternal(
|
|
2213
|
+
validator,
|
|
2214
|
+
field,
|
|
2215
|
+
`${name}.${property}`,
|
|
2216
|
+
rootSchema,
|
|
2217
|
+
// It's possible that formData is not an object -- this can happen if an
|
|
2218
|
+
// array item has just been added, but not populated with data yet
|
|
2219
|
+
(0, import_get14.default)(formData, [property]),
|
|
2220
|
+
_recurseList,
|
|
2221
|
+
experimental_customMergeAllOf
|
|
2222
|
+
);
|
|
2223
|
+
}
|
|
2224
|
+
}
|
|
2225
|
+
return pathSchema;
|
|
2226
|
+
}
|
|
2227
|
+
function toPathSchema(validator, schema, name = "", rootSchema, formData, experimental_customMergeAllOf) {
|
|
2228
|
+
return toPathSchemaInternal(validator, schema, name, rootSchema, formData, void 0, experimental_customMergeAllOf);
|
|
2229
|
+
}
|
|
2230
|
+
|
|
2231
|
+
// src/schema/omitExtraData.ts
|
|
2232
|
+
function getUsedFormData(formData, fields) {
|
|
2233
|
+
if (fields.length === 0 && typeof formData !== "object") {
|
|
2234
|
+
return formData;
|
|
2235
|
+
}
|
|
2236
|
+
const data = (0, import_pick.default)(formData, fields);
|
|
2237
|
+
if (Array.isArray(formData)) {
|
|
2238
|
+
return Object.keys(data).map((key) => data[key]);
|
|
2239
|
+
}
|
|
2240
|
+
return data;
|
|
2241
|
+
}
|
|
2242
|
+
function getFieldNames(pathSchema, formData) {
|
|
2243
|
+
const formValueHasData = (value, isLeaf) => typeof value !== "object" || (0, import_isEmpty5.default)(value) || isLeaf && !(0, import_isEmpty5.default)(value);
|
|
2244
|
+
const getAllPaths = (_obj, acc = [], paths = [[]]) => {
|
|
2245
|
+
const objKeys = Object.keys(_obj);
|
|
2246
|
+
objKeys.forEach((key) => {
|
|
2247
|
+
const data = _obj[key];
|
|
2248
|
+
if (typeof data === "object") {
|
|
2249
|
+
const newPaths = paths.map((path) => [...path, key]);
|
|
2250
|
+
if (data[RJSF_ADDITIONAL_PROPERTIES_FLAG] && data[NAME_KEY] !== "") {
|
|
2251
|
+
acc.push(data[NAME_KEY]);
|
|
2252
|
+
} else {
|
|
2253
|
+
getAllPaths(data, acc, newPaths);
|
|
2254
|
+
}
|
|
2255
|
+
} else if (key === NAME_KEY && data !== "") {
|
|
2256
|
+
paths.forEach((path) => {
|
|
2257
|
+
const formValue = (0, import_get15.default)(formData, path);
|
|
2258
|
+
const isLeaf = objKeys.length === 1;
|
|
2259
|
+
if (formValueHasData(formValue, isLeaf) || Array.isArray(formValue) && formValue.every((val) => formValueHasData(val, isLeaf))) {
|
|
2260
|
+
acc.push(path);
|
|
2261
|
+
}
|
|
2262
|
+
});
|
|
2263
|
+
}
|
|
2264
|
+
});
|
|
2265
|
+
return acc;
|
|
2266
|
+
};
|
|
2267
|
+
return getAllPaths(pathSchema);
|
|
2268
|
+
}
|
|
2269
|
+
function omitExtraData(validator, schema, rootSchema = {}, formData) {
|
|
2270
|
+
const retrievedSchema = retrieveSchema(validator, schema, rootSchema, formData);
|
|
2271
|
+
const pathSchema = toPathSchema(validator, retrievedSchema, "", rootSchema, formData);
|
|
2272
|
+
const fieldNames = getFieldNames(pathSchema, formData);
|
|
2273
|
+
const lodashFieldNames = fieldNames.map(
|
|
2274
|
+
(fieldPaths) => Array.isArray(fieldPaths) ? fieldPaths.join(".") : fieldPaths
|
|
2275
|
+
);
|
|
2276
|
+
return getUsedFormData(formData, lodashFieldNames);
|
|
2277
|
+
}
|
|
2278
|
+
|
|
2279
|
+
// src/schema/sanitizeDataForNewSchema.ts
|
|
2280
|
+
var import_get16 = __toESM(require("lodash/get"), 1);
|
|
2107
2281
|
var import_has5 = __toESM(require("lodash/has"), 1);
|
|
2108
2282
|
var NO_VALUE = Symbol("no Value");
|
|
2109
2283
|
function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, data = {}, experimental_customMergeAllOf) {
|
|
@@ -2111,19 +2285,19 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
2111
2285
|
if ((0, import_has5.default)(newSchema, PROPERTIES_KEY)) {
|
|
2112
2286
|
const removeOldSchemaData = {};
|
|
2113
2287
|
if ((0, import_has5.default)(oldSchema, PROPERTIES_KEY)) {
|
|
2114
|
-
const properties = (0,
|
|
2288
|
+
const properties = (0, import_get16.default)(oldSchema, PROPERTIES_KEY, {});
|
|
2115
2289
|
Object.keys(properties).forEach((key) => {
|
|
2116
2290
|
if ((0, import_has5.default)(data, key)) {
|
|
2117
2291
|
removeOldSchemaData[key] = void 0;
|
|
2118
2292
|
}
|
|
2119
2293
|
});
|
|
2120
2294
|
}
|
|
2121
|
-
const keys2 = Object.keys((0,
|
|
2295
|
+
const keys2 = Object.keys((0, import_get16.default)(newSchema, PROPERTIES_KEY, {}));
|
|
2122
2296
|
const nestedData = {};
|
|
2123
2297
|
keys2.forEach((key) => {
|
|
2124
|
-
const formValue = (0,
|
|
2125
|
-
let oldKeyedSchema = (0,
|
|
2126
|
-
let newKeyedSchema = (0,
|
|
2298
|
+
const formValue = (0, import_get16.default)(data, key);
|
|
2299
|
+
let oldKeyedSchema = (0, import_get16.default)(oldSchema, [PROPERTIES_KEY, key], {});
|
|
2300
|
+
let newKeyedSchema = (0, import_get16.default)(newSchema, [PROPERTIES_KEY, key], {});
|
|
2127
2301
|
if ((0, import_has5.default)(oldKeyedSchema, REF_KEY)) {
|
|
2128
2302
|
oldKeyedSchema = retrieveSchema(
|
|
2129
2303
|
validator,
|
|
@@ -2142,8 +2316,8 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
2142
2316
|
experimental_customMergeAllOf
|
|
2143
2317
|
);
|
|
2144
2318
|
}
|
|
2145
|
-
const oldSchemaTypeForKey = (0,
|
|
2146
|
-
const newSchemaTypeForKey = (0,
|
|
2319
|
+
const oldSchemaTypeForKey = (0, import_get16.default)(oldKeyedSchema, "type");
|
|
2320
|
+
const newSchemaTypeForKey = (0, import_get16.default)(newKeyedSchema, "type");
|
|
2147
2321
|
if (!oldSchemaTypeForKey || oldSchemaTypeForKey === newSchemaTypeForKey) {
|
|
2148
2322
|
if ((0, import_has5.default)(removeOldSchemaData, key)) {
|
|
2149
2323
|
delete removeOldSchemaData[key];
|
|
@@ -2161,17 +2335,17 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
2161
2335
|
nestedData[key] = itemData;
|
|
2162
2336
|
}
|
|
2163
2337
|
} else {
|
|
2164
|
-
const newOptionDefault = (0,
|
|
2165
|
-
const oldOptionDefault = (0,
|
|
2338
|
+
const newOptionDefault = (0, import_get16.default)(newKeyedSchema, "default", NO_VALUE);
|
|
2339
|
+
const oldOptionDefault = (0, import_get16.default)(oldKeyedSchema, "default", NO_VALUE);
|
|
2166
2340
|
if (newOptionDefault !== NO_VALUE && newOptionDefault !== formValue) {
|
|
2167
2341
|
if (oldOptionDefault === formValue) {
|
|
2168
2342
|
removeOldSchemaData[key] = newOptionDefault;
|
|
2169
|
-
} else if ((0,
|
|
2343
|
+
} else if ((0, import_get16.default)(newKeyedSchema, "readOnly") === true) {
|
|
2170
2344
|
removeOldSchemaData[key] = void 0;
|
|
2171
2345
|
}
|
|
2172
2346
|
}
|
|
2173
|
-
const newOptionConst = (0,
|
|
2174
|
-
const oldOptionConst = (0,
|
|
2347
|
+
const newOptionConst = (0, import_get16.default)(newKeyedSchema, "const", NO_VALUE);
|
|
2348
|
+
const oldOptionConst = (0, import_get16.default)(oldKeyedSchema, "const", NO_VALUE);
|
|
2175
2349
|
if (newOptionConst !== NO_VALUE && newOptionConst !== formValue) {
|
|
2176
2350
|
removeOldSchemaData[key] = oldOptionConst === formValue ? newOptionConst : void 0;
|
|
2177
2351
|
}
|
|
@@ -2183,9 +2357,9 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
2183
2357
|
...removeOldSchemaData,
|
|
2184
2358
|
...nestedData
|
|
2185
2359
|
};
|
|
2186
|
-
} else if ((0,
|
|
2187
|
-
let oldSchemaItems = (0,
|
|
2188
|
-
let newSchemaItems = (0,
|
|
2360
|
+
} else if ((0, import_get16.default)(oldSchema, "type") === "array" && (0, import_get16.default)(newSchema, "type") === "array" && Array.isArray(data)) {
|
|
2361
|
+
let oldSchemaItems = (0, import_get16.default)(oldSchema, "items");
|
|
2362
|
+
let newSchemaItems = (0, import_get16.default)(newSchema, "items");
|
|
2189
2363
|
if (typeof oldSchemaItems === "object" && typeof newSchemaItems === "object" && !Array.isArray(oldSchemaItems) && !Array.isArray(newSchemaItems)) {
|
|
2190
2364
|
if ((0, import_has5.default)(oldSchemaItems, REF_KEY)) {
|
|
2191
2365
|
oldSchemaItems = retrieveSchema(
|
|
@@ -2205,10 +2379,10 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
2205
2379
|
experimental_customMergeAllOf
|
|
2206
2380
|
);
|
|
2207
2381
|
}
|
|
2208
|
-
const oldSchemaType = (0,
|
|
2209
|
-
const newSchemaType = (0,
|
|
2382
|
+
const oldSchemaType = (0, import_get16.default)(oldSchemaItems, "type");
|
|
2383
|
+
const newSchemaType = (0, import_get16.default)(newSchemaItems, "type");
|
|
2210
2384
|
if (!oldSchemaType || oldSchemaType === newSchemaType) {
|
|
2211
|
-
const maxItems = (0,
|
|
2385
|
+
const maxItems = (0, import_get16.default)(newSchema, "maxItems", -1);
|
|
2212
2386
|
if (newSchemaType === "object") {
|
|
2213
2387
|
newFormData = data.reduce((newValue, aValue) => {
|
|
2214
2388
|
const itemValue = sanitizeDataForNewSchema(
|
|
@@ -2235,122 +2409,8 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
2235
2409
|
return newFormData;
|
|
2236
2410
|
}
|
|
2237
2411
|
|
|
2238
|
-
// src/schema/toPathSchema.ts
|
|
2239
|
-
var import_get15 = __toESM(require("lodash/get"), 1);
|
|
2240
|
-
var import_set2 = __toESM(require("lodash/set"), 1);
|
|
2241
|
-
function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
|
|
2242
|
-
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
2243
|
-
const _schema = retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf);
|
|
2244
|
-
const sameSchemaIndex = _recurseList.findIndex((item) => deepEquals(item, _schema));
|
|
2245
|
-
if (sameSchemaIndex === -1) {
|
|
2246
|
-
return toPathSchemaInternal(
|
|
2247
|
-
validator,
|
|
2248
|
-
_schema,
|
|
2249
|
-
name,
|
|
2250
|
-
rootSchema,
|
|
2251
|
-
formData,
|
|
2252
|
-
_recurseList.concat(_schema),
|
|
2253
|
-
experimental_customMergeAllOf
|
|
2254
|
-
);
|
|
2255
|
-
}
|
|
2256
|
-
}
|
|
2257
|
-
let pathSchema = {
|
|
2258
|
-
[NAME_KEY]: name.replace(/^\./, "")
|
|
2259
|
-
};
|
|
2260
|
-
if (ONE_OF_KEY in schema || ANY_OF_KEY in schema) {
|
|
2261
|
-
const xxxOf = ONE_OF_KEY in schema ? schema.oneOf : schema.anyOf;
|
|
2262
|
-
const discriminator = getDiscriminatorFieldFromSchema(schema);
|
|
2263
|
-
const index = getClosestMatchingOption(
|
|
2264
|
-
validator,
|
|
2265
|
-
rootSchema,
|
|
2266
|
-
formData,
|
|
2267
|
-
xxxOf,
|
|
2268
|
-
0,
|
|
2269
|
-
discriminator,
|
|
2270
|
-
experimental_customMergeAllOf
|
|
2271
|
-
);
|
|
2272
|
-
const _schema = xxxOf[index];
|
|
2273
|
-
pathSchema = {
|
|
2274
|
-
...pathSchema,
|
|
2275
|
-
...toPathSchemaInternal(
|
|
2276
|
-
validator,
|
|
2277
|
-
_schema,
|
|
2278
|
-
name,
|
|
2279
|
-
rootSchema,
|
|
2280
|
-
formData,
|
|
2281
|
-
_recurseList,
|
|
2282
|
-
experimental_customMergeAllOf
|
|
2283
|
-
)
|
|
2284
|
-
};
|
|
2285
|
-
}
|
|
2286
|
-
if (ADDITIONAL_PROPERTIES_KEY in schema && schema[ADDITIONAL_PROPERTIES_KEY] !== false) {
|
|
2287
|
-
(0, import_set2.default)(pathSchema, RJSF_ADDITIONAL_PROPERTIES_FLAG, true);
|
|
2288
|
-
}
|
|
2289
|
-
if (ITEMS_KEY in schema && Array.isArray(formData)) {
|
|
2290
|
-
const { items: schemaItems, additionalItems: schemaAdditionalItems } = schema;
|
|
2291
|
-
if (Array.isArray(schemaItems)) {
|
|
2292
|
-
formData.forEach((element, i) => {
|
|
2293
|
-
if (schemaItems[i]) {
|
|
2294
|
-
pathSchema[i] = toPathSchemaInternal(
|
|
2295
|
-
validator,
|
|
2296
|
-
schemaItems[i],
|
|
2297
|
-
`${name}.${i}`,
|
|
2298
|
-
rootSchema,
|
|
2299
|
-
element,
|
|
2300
|
-
_recurseList,
|
|
2301
|
-
experimental_customMergeAllOf
|
|
2302
|
-
);
|
|
2303
|
-
} else if (schemaAdditionalItems) {
|
|
2304
|
-
pathSchema[i] = toPathSchemaInternal(
|
|
2305
|
-
validator,
|
|
2306
|
-
schemaAdditionalItems,
|
|
2307
|
-
`${name}.${i}`,
|
|
2308
|
-
rootSchema,
|
|
2309
|
-
element,
|
|
2310
|
-
_recurseList,
|
|
2311
|
-
experimental_customMergeAllOf
|
|
2312
|
-
);
|
|
2313
|
-
} else {
|
|
2314
|
-
console.warn(`Unable to generate path schema for "${name}.${i}". No schema defined for it`);
|
|
2315
|
-
}
|
|
2316
|
-
});
|
|
2317
|
-
} else {
|
|
2318
|
-
formData.forEach((element, i) => {
|
|
2319
|
-
pathSchema[i] = toPathSchemaInternal(
|
|
2320
|
-
validator,
|
|
2321
|
-
schemaItems,
|
|
2322
|
-
`${name}.${i}`,
|
|
2323
|
-
rootSchema,
|
|
2324
|
-
element,
|
|
2325
|
-
_recurseList,
|
|
2326
|
-
experimental_customMergeAllOf
|
|
2327
|
-
);
|
|
2328
|
-
});
|
|
2329
|
-
}
|
|
2330
|
-
} else if (PROPERTIES_KEY in schema) {
|
|
2331
|
-
for (const property in schema.properties) {
|
|
2332
|
-
const field = (0, import_get15.default)(schema, [PROPERTIES_KEY, property], {});
|
|
2333
|
-
pathSchema[property] = toPathSchemaInternal(
|
|
2334
|
-
validator,
|
|
2335
|
-
field,
|
|
2336
|
-
`${name}.${property}`,
|
|
2337
|
-
rootSchema,
|
|
2338
|
-
// It's possible that formData is not an object -- this can happen if an
|
|
2339
|
-
// array item has just been added, but not populated with data yet
|
|
2340
|
-
(0, import_get15.default)(formData, [property]),
|
|
2341
|
-
_recurseList,
|
|
2342
|
-
experimental_customMergeAllOf
|
|
2343
|
-
);
|
|
2344
|
-
}
|
|
2345
|
-
}
|
|
2346
|
-
return pathSchema;
|
|
2347
|
-
}
|
|
2348
|
-
function toPathSchema(validator, schema, name = "", rootSchema, formData, experimental_customMergeAllOf) {
|
|
2349
|
-
return toPathSchemaInternal(validator, schema, name, rootSchema, formData, void 0, experimental_customMergeAllOf);
|
|
2350
|
-
}
|
|
2351
|
-
|
|
2352
2412
|
// src/createSchemaUtils.ts
|
|
2353
|
-
var
|
|
2413
|
+
var import_get17 = __toESM(require("lodash/get"), 1);
|
|
2354
2414
|
var SchemaUtils = class {
|
|
2355
2415
|
/** Constructs the `SchemaUtils` instance with the given `validator` and `rootSchema` stored as instance variables
|
|
2356
2416
|
*
|
|
@@ -2361,7 +2421,7 @@ var SchemaUtils = class {
|
|
|
2361
2421
|
*/
|
|
2362
2422
|
constructor(validator, rootSchema, experimental_defaultFormStateBehavior, experimental_customMergeAllOf) {
|
|
2363
2423
|
if (rootSchema && rootSchema[SCHEMA_KEY] === JSON_SCHEMA_DRAFT_2020_12) {
|
|
2364
|
-
this.rootSchema = makeAllReferencesAbsolute(rootSchema, (0,
|
|
2424
|
+
this.rootSchema = makeAllReferencesAbsolute(rootSchema, (0, import_get17.default)(rootSchema, ID_KEY, "#"));
|
|
2365
2425
|
} else {
|
|
2366
2426
|
this.rootSchema = rootSchema;
|
|
2367
2427
|
}
|
|
@@ -2553,6 +2613,18 @@ var SchemaUtils = class {
|
|
|
2553
2613
|
isSelect(schema) {
|
|
2554
2614
|
return isSelect(this.validator, schema, this.rootSchema, this.experimental_customMergeAllOf);
|
|
2555
2615
|
}
|
|
2616
|
+
/**
|
|
2617
|
+
* The function takes a `schema` and `formData` and returns a copy of the formData with any fields not defined in the schema removed.
|
|
2618
|
+
* This is useful for ensuring that only data that is relevant to the schema is preserved. Objects with `additionalProperties`
|
|
2619
|
+
* keyword set to `true` will not have their extra fields removed.
|
|
2620
|
+
*
|
|
2621
|
+
* @param schema - The schema to use for filtering the `formData`
|
|
2622
|
+
* @param [formData] - The formData to filter
|
|
2623
|
+
* @returns The new form data, with any fields not defined in the schema removed
|
|
2624
|
+
*/
|
|
2625
|
+
omitExtraData(schema, formData) {
|
|
2626
|
+
return omitExtraData(this.validator, schema, this.rootSchema, formData);
|
|
2627
|
+
}
|
|
2556
2628
|
/** Retrieves an expanded schema that has had all of its conditions, additional properties, references and
|
|
2557
2629
|
* dependencies resolved and merged into the `schema` given a `rawFormData` that is used to do the potentially
|
|
2558
2630
|
* recursive resolution.
|
|
@@ -2775,7 +2847,7 @@ function enumOptionsSelectValue(valueIndex, selected, allEnumOptions = []) {
|
|
|
2775
2847
|
|
|
2776
2848
|
// src/ErrorSchemaBuilder.ts
|
|
2777
2849
|
var import_cloneDeep = __toESM(require("lodash/cloneDeep"), 1);
|
|
2778
|
-
var
|
|
2850
|
+
var import_get18 = __toESM(require("lodash/get"), 1);
|
|
2779
2851
|
var import_set3 = __toESM(require("lodash/set"), 1);
|
|
2780
2852
|
var import_setWith = __toESM(require("lodash/setWith"), 1);
|
|
2781
2853
|
var ErrorSchemaBuilder = class {
|
|
@@ -2804,7 +2876,7 @@ var ErrorSchemaBuilder = class {
|
|
|
2804
2876
|
*/
|
|
2805
2877
|
getOrCreateErrorBlock(pathOfError) {
|
|
2806
2878
|
const hasPath = Array.isArray(pathOfError) && pathOfError.length > 0 || typeof pathOfError === "string";
|
|
2807
|
-
let errorBlock = hasPath ? (0,
|
|
2879
|
+
let errorBlock = hasPath ? (0, import_get18.default)(this.errorSchema, pathOfError) : this.errorSchema;
|
|
2808
2880
|
if (!errorBlock && pathOfError) {
|
|
2809
2881
|
errorBlock = {};
|
|
2810
2882
|
(0, import_setWith.default)(this.errorSchema, pathOfError, errorBlock, Object);
|
|
@@ -2830,7 +2902,7 @@ var ErrorSchemaBuilder = class {
|
|
|
2830
2902
|
*/
|
|
2831
2903
|
addErrors(errorOrList, pathOfError) {
|
|
2832
2904
|
const errorBlock = this.getOrCreateErrorBlock(pathOfError);
|
|
2833
|
-
let errorsList = (0,
|
|
2905
|
+
let errorsList = (0, import_get18.default)(errorBlock, ERRORS_KEY);
|
|
2834
2906
|
if (!Array.isArray(errorsList)) {
|
|
2835
2907
|
errorsList = [];
|
|
2836
2908
|
errorBlock[ERRORS_KEY] = errorsList;
|
|
@@ -2874,7 +2946,7 @@ var ErrorSchemaBuilder = class {
|
|
|
2874
2946
|
var import_keys = __toESM(require("lodash/keys"), 1);
|
|
2875
2947
|
var import_pickBy = __toESM(require("lodash/pickBy"), 1);
|
|
2876
2948
|
var import_isPlainObject2 = __toESM(require("lodash/isPlainObject"), 1);
|
|
2877
|
-
var
|
|
2949
|
+
var import_get19 = __toESM(require("lodash/get"), 1);
|
|
2878
2950
|
var import_difference = __toESM(require("lodash/difference"), 1);
|
|
2879
2951
|
function getChangedFields(a, b) {
|
|
2880
2952
|
const aIsPlainObject = (0, import_isPlainObject2.default)(a);
|
|
@@ -2887,7 +2959,7 @@ function getChangedFields(a, b) {
|
|
|
2887
2959
|
} else if (!aIsPlainObject && bIsPlainObject) {
|
|
2888
2960
|
return (0, import_keys.default)(b);
|
|
2889
2961
|
} else {
|
|
2890
|
-
const unequalFields = (0, import_keys.default)((0, import_pickBy.default)(a, (value, key) => !deepEquals(value, (0,
|
|
2962
|
+
const unequalFields = (0, import_keys.default)((0, import_pickBy.default)(a, (value, key) => !deepEquals(value, (0, import_get19.default)(b, key))));
|
|
2891
2963
|
const diffFields = (0, import_difference.default)((0, import_keys.default)(b), (0, import_keys.default)(a));
|
|
2892
2964
|
return [...unequalFields, ...diffFields];
|
|
2893
2965
|
}
|
|
@@ -3001,10 +3073,10 @@ function getTemplate(name, registry, uiOptions = {}) {
|
|
|
3001
3073
|
}
|
|
3002
3074
|
|
|
3003
3075
|
// src/getTestIds.ts
|
|
3004
|
-
var
|
|
3076
|
+
var import_get20 = __toESM(require("lodash/get"), 1);
|
|
3005
3077
|
var import_uniqueId = __toESM(require("lodash/uniqueId"), 1);
|
|
3006
3078
|
function getTestIds() {
|
|
3007
|
-
if (typeof process === "undefined" || (0,
|
|
3079
|
+
if (typeof process === "undefined" || (0, import_get20.default)(process, "env.NODE_ENV") !== "test") {
|
|
3008
3080
|
return {};
|
|
3009
3081
|
}
|
|
3010
3082
|
const ids = /* @__PURE__ */ new Map();
|
|
@@ -3024,7 +3096,7 @@ function getTestIds() {
|
|
|
3024
3096
|
// src/getWidget.tsx
|
|
3025
3097
|
var import_react = require("react");
|
|
3026
3098
|
var import_react_is = __toESM(require("react-is"), 1);
|
|
3027
|
-
var
|
|
3099
|
+
var import_get21 = __toESM(require("lodash/get"), 1);
|
|
3028
3100
|
var import_set4 = __toESM(require("lodash/set"), 1);
|
|
3029
3101
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
3030
3102
|
var widgetMap = {
|
|
@@ -3080,7 +3152,7 @@ var widgetMap = {
|
|
|
3080
3152
|
}
|
|
3081
3153
|
};
|
|
3082
3154
|
function mergeWidgetOptions(AWidget) {
|
|
3083
|
-
let MergedWidget = (0,
|
|
3155
|
+
let MergedWidget = (0, import_get21.default)(AWidget, "MergedWidget");
|
|
3084
3156
|
if (!MergedWidget) {
|
|
3085
3157
|
const defaultOptions = AWidget.defaultProps && AWidget.defaultProps.options || {};
|
|
3086
3158
|
MergedWidget = ({ options, ...props }) => {
|
|
@@ -3187,10 +3259,10 @@ function optionalControlsId(id, element) {
|
|
|
3187
3259
|
|
|
3188
3260
|
// src/isFormDataAvailable.ts
|
|
3189
3261
|
var import_isNil3 = __toESM(require("lodash/isNil"), 1);
|
|
3190
|
-
var
|
|
3262
|
+
var import_isEmpty6 = __toESM(require("lodash/isEmpty"), 1);
|
|
3191
3263
|
var import_isObject11 = __toESM(require("lodash/isObject"), 1);
|
|
3192
3264
|
function isFormDataAvailable(formData) {
|
|
3193
|
-
return !(0, import_isNil3.default)(formData) && (!(0, import_isObject11.default)(formData) || Array.isArray(formData) || !(0,
|
|
3265
|
+
return !(0, import_isNil3.default)(formData) && (!(0, import_isObject11.default)(formData) || Array.isArray(formData) || !(0, import_isEmpty6.default)(formData));
|
|
3194
3266
|
}
|
|
3195
3267
|
|
|
3196
3268
|
// src/isRootSchema.ts
|
|
@@ -3218,14 +3290,14 @@ function localToUTC(dateString) {
|
|
|
3218
3290
|
}
|
|
3219
3291
|
|
|
3220
3292
|
// src/lookupFromFormContext.ts
|
|
3221
|
-
var
|
|
3293
|
+
var import_get22 = __toESM(require("lodash/get"), 1);
|
|
3222
3294
|
var import_has6 = __toESM(require("lodash/has"), 1);
|
|
3223
3295
|
function lookupFromFormContext(regOrFc, toLookup, fallback) {
|
|
3224
3296
|
const lookupPath = [LOOKUP_MAP_NAME];
|
|
3225
3297
|
if ((0, import_has6.default)(regOrFc, FORM_CONTEXT_NAME)) {
|
|
3226
3298
|
lookupPath.unshift(FORM_CONTEXT_NAME);
|
|
3227
3299
|
}
|
|
3228
|
-
return (0,
|
|
3300
|
+
return (0, import_get22.default)(regOrFc, [...lookupPath, toLookup], fallback);
|
|
3229
3301
|
}
|
|
3230
3302
|
|
|
3231
3303
|
// src/orderProperties.ts
|
|
@@ -3649,7 +3721,7 @@ function utcToLocal(jsonDate) {
|
|
|
3649
3721
|
}
|
|
3650
3722
|
|
|
3651
3723
|
// src/validationDataMerge.ts
|
|
3652
|
-
var
|
|
3724
|
+
var import_isEmpty7 = __toESM(require("lodash/isEmpty"), 1);
|
|
3653
3725
|
function validationDataMerge(validationData, additionalErrorSchema, preventDuplicates = false) {
|
|
3654
3726
|
if (!additionalErrorSchema) {
|
|
3655
3727
|
return validationData;
|
|
@@ -3657,7 +3729,7 @@ function validationDataMerge(validationData, additionalErrorSchema, preventDupli
|
|
|
3657
3729
|
const { errors: oldErrors, errorSchema: oldErrorSchema } = validationData;
|
|
3658
3730
|
let errors = toErrorList(additionalErrorSchema);
|
|
3659
3731
|
let errorSchema = additionalErrorSchema;
|
|
3660
|
-
if (!(0,
|
|
3732
|
+
if (!(0, import_isEmpty7.default)(oldErrorSchema)) {
|
|
3661
3733
|
errorSchema = mergeObjects(
|
|
3662
3734
|
oldErrorSchema,
|
|
3663
3735
|
additionalErrorSchema,
|
|
@@ -3745,6 +3817,7 @@ var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
|
|
|
3745
3817
|
TranslatableString2["OptionalObjectEmptyMsg"] = "No data for optional field";
|
|
3746
3818
|
TranslatableString2["Type"] = "Type";
|
|
3747
3819
|
TranslatableString2["Value"] = "Value";
|
|
3820
|
+
TranslatableString2["ClearButton"] = "clear input";
|
|
3748
3821
|
TranslatableString2["UnknownFieldType"] = "Unknown field type %1";
|
|
3749
3822
|
TranslatableString2["OptionPrefix"] = "Option %1";
|
|
3750
3823
|
TranslatableString2["TitleOptionPrefix"] = "%1 option %2";
|
|
@@ -3762,7 +3835,7 @@ var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
|
|
|
3762
3835
|
var import_forEach = __toESM(require("lodash/forEach"), 1);
|
|
3763
3836
|
|
|
3764
3837
|
// src/parser/ParserValidator.ts
|
|
3765
|
-
var
|
|
3838
|
+
var import_get23 = __toESM(require("lodash/get"), 1);
|
|
3766
3839
|
var ParserValidator = class {
|
|
3767
3840
|
/** Construct the ParserValidator for the given `rootSchema`. This `rootSchema` will be stashed in the `schemaMap`
|
|
3768
3841
|
* first.
|
|
@@ -3788,7 +3861,7 @@ var ParserValidator = class {
|
|
|
3788
3861
|
* @param hash - The hash value at which to map the schema
|
|
3789
3862
|
*/
|
|
3790
3863
|
addSchema(schema, hash) {
|
|
3791
|
-
const key = (0,
|
|
3864
|
+
const key = (0, import_get23.default)(schema, ID_KEY, hash);
|
|
3792
3865
|
const identifiedSchema = { ...schema, [ID_KEY]: key };
|
|
3793
3866
|
const existing = this.schemaMap[key];
|
|
3794
3867
|
if (!existing) {
|