@rjsf/utils 6.0.0-beta.11 → 6.0.0-beta.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +102 -21
- package/dist/index.js.map +4 -4
- package/dist/utils.esm.js +102 -21
- package/dist/utils.esm.js.map +4 -4
- package/dist/utils.umd.js +100 -22
- package/lib/constants.d.ts +1 -0
- package/lib/constants.js +1 -0
- package/lib/constants.js.map +1 -1
- package/lib/createSchemaUtils.js +16 -1
- package/lib/createSchemaUtils.js.map +1 -1
- package/lib/findSchemaDefinition.d.ts +6 -0
- package/lib/findSchemaDefinition.js +44 -3
- package/lib/findSchemaDefinition.js.map +1 -1
- package/lib/index.d.ts +3 -1
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/lib/mergeDefaultsWithFormData.js +2 -2
- package/lib/mergeDefaultsWithFormData.js.map +1 -1
- package/lib/schema/getDefaultFormState.js +10 -2
- package/lib/schema/getDefaultFormState.js.map +1 -1
- package/lib/schema/retrieveSchema.js +2 -2
- package/lib/schema/retrieveSchema.js.map +1 -1
- package/lib/shallowEquals.d.ts +8 -0
- package/lib/shallowEquals.js +36 -0
- package/lib/shallowEquals.js.map +1 -0
- package/lib/shouldRender.d.ts +8 -2
- package/lib/shouldRender.js +17 -2
- package/lib/shouldRender.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types.d.ts +7 -0
- package/package.json +1 -1
- package/src/constants.ts +1 -0
- package/src/createSchemaUtils.ts +16 -1
- package/src/findSchemaDefinition.ts +51 -3
- package/src/index.ts +4 -0
- package/src/mergeDefaultsWithFormData.ts +1 -1
- package/src/schema/getDefaultFormState.ts +12 -2
- package/src/schema/retrieveSchema.ts +2 -2
- package/src/shallowEquals.ts +41 -0
- package/src/shouldRender.ts +27 -2
- package/src/types.ts +7 -0
package/dist/utils.esm.js
CHANGED
|
@@ -75,6 +75,7 @@ var UI_FIELD_KEY = "ui:field";
|
|
|
75
75
|
var UI_WIDGET_KEY = "ui:widget";
|
|
76
76
|
var UI_OPTIONS_KEY = "ui:options";
|
|
77
77
|
var UI_GLOBAL_OPTIONS_KEY = "ui:globalOptions";
|
|
78
|
+
var JSON_SCHEMA_DRAFT_2019_09 = "https://json-schema.org/draft/2019-09/schema";
|
|
78
79
|
var JSON_SCHEMA_DRAFT_2020_12 = "https://json-schema.org/draft/2020-12/schema";
|
|
79
80
|
|
|
80
81
|
// src/getUiOptions.ts
|
|
@@ -177,7 +178,16 @@ function findEmbeddedSchemaRecursive(schema, ref) {
|
|
|
177
178
|
return schema;
|
|
178
179
|
}
|
|
179
180
|
for (const subSchema of Object.values(schema)) {
|
|
180
|
-
if (
|
|
181
|
+
if (Array.isArray(subSchema)) {
|
|
182
|
+
for (const item of subSchema) {
|
|
183
|
+
if (isObject2(item)) {
|
|
184
|
+
const result = findEmbeddedSchemaRecursive(item, ref);
|
|
185
|
+
if (result !== void 0) {
|
|
186
|
+
return result;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
} else if (isObject2(subSchema)) {
|
|
181
191
|
const result = findEmbeddedSchemaRecursive(subSchema, ref);
|
|
182
192
|
if (result !== void 0) {
|
|
183
193
|
return result;
|
|
@@ -186,6 +196,23 @@ function findEmbeddedSchemaRecursive(schema, ref) {
|
|
|
186
196
|
}
|
|
187
197
|
return void 0;
|
|
188
198
|
}
|
|
199
|
+
function makeAllReferencesAbsolute(schema, baseURI) {
|
|
200
|
+
const currentURI = get(schema, ID_KEY, baseURI);
|
|
201
|
+
if (REF_KEY in schema) {
|
|
202
|
+
schema = { ...schema, [REF_KEY]: UriResolver.resolve(currentURI, schema[REF_KEY]) };
|
|
203
|
+
}
|
|
204
|
+
for (const [key, subSchema] of Object.entries(schema)) {
|
|
205
|
+
if (Array.isArray(subSchema)) {
|
|
206
|
+
schema = {
|
|
207
|
+
...schema,
|
|
208
|
+
[key]: subSchema.map((item) => isObject2(item) ? makeAllReferencesAbsolute(item, currentURI) : item)
|
|
209
|
+
};
|
|
210
|
+
} else if (isObject2(subSchema)) {
|
|
211
|
+
schema = { ...schema, [key]: makeAllReferencesAbsolute(subSchema, currentURI) };
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return schema;
|
|
215
|
+
}
|
|
189
216
|
function splitKeyElementFromObject(key, object) {
|
|
190
217
|
const value = object[key];
|
|
191
218
|
const remaining = omit(object, [key]);
|
|
@@ -231,7 +258,11 @@ function findSchemaDefinitionRecursive($ref, rootSchema = {}, recurseList = [],
|
|
|
231
258
|
const [remaining, theRef] = splitKeyElementFromObject(REF_KEY, current);
|
|
232
259
|
const subSchema = findSchemaDefinitionRecursive(theRef, rootSchema, [...recurseList, ref], baseURI);
|
|
233
260
|
if (Object.keys(remaining).length > 0) {
|
|
234
|
-
|
|
261
|
+
if (rootSchema[SCHEMA_KEY] === JSON_SCHEMA_DRAFT_2019_09 || rootSchema[SCHEMA_KEY] === JSON_SCHEMA_DRAFT_2020_12) {
|
|
262
|
+
return { [ALL_OF_KEY]: [remaining, subSchema] };
|
|
263
|
+
} else {
|
|
264
|
+
return { ...remaining, ...subSchema };
|
|
265
|
+
}
|
|
235
266
|
}
|
|
236
267
|
return subSchema;
|
|
237
268
|
}
|
|
@@ -618,7 +649,7 @@ function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFor
|
|
|
618
649
|
if (!isEmpty2(matchingProperties)) {
|
|
619
650
|
schema.properties[key] = retrieveSchema(
|
|
620
651
|
validator,
|
|
621
|
-
{
|
|
652
|
+
{ [ALL_OF_KEY]: Object.values(matchingProperties) },
|
|
622
653
|
rootSchema,
|
|
623
654
|
get5(formData, [key]),
|
|
624
655
|
experimental_customMergeAllOf
|
|
@@ -633,7 +664,7 @@ function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFor
|
|
|
633
664
|
if (REF_KEY in schema.additionalProperties) {
|
|
634
665
|
additionalProperties = retrieveSchema(
|
|
635
666
|
validator,
|
|
636
|
-
{
|
|
667
|
+
{ [REF_KEY]: get5(schema.additionalProperties, [REF_KEY]) },
|
|
637
668
|
rootSchema,
|
|
638
669
|
formData,
|
|
639
670
|
experimental_customMergeAllOf
|
|
@@ -1240,7 +1271,7 @@ function mergeDefaultsWithFormData(defaults, formData, mergeExtraArrayDefaults =
|
|
|
1240
1271
|
return acc2;
|
|
1241
1272
|
}
|
|
1242
1273
|
acc2[key] = mergeDefaultsWithFormData(
|
|
1243
|
-
get10(defaults, key)
|
|
1274
|
+
get10(defaults, key),
|
|
1244
1275
|
keyValue,
|
|
1245
1276
|
mergeExtraArrayDefaults,
|
|
1246
1277
|
defaultSupercedesUndefined,
|
|
@@ -1400,8 +1431,12 @@ function getInnerSchemaForArrayItem(schema, additionalItems = 0 /* Ignore */, id
|
|
|
1400
1431
|
}
|
|
1401
1432
|
function maybeAddDefaultToObject(obj, key, computedDefault, includeUndefinedValues, isParentRequired, requiredFields = [], experimental_defaultFormStateBehavior = {}, isConst = false) {
|
|
1402
1433
|
const { emptyObjectFields = "populateAllDefaults" } = experimental_defaultFormStateBehavior;
|
|
1403
|
-
if (includeUndefinedValues || isConst) {
|
|
1434
|
+
if (includeUndefinedValues === true || isConst) {
|
|
1404
1435
|
obj[key] = computedDefault;
|
|
1436
|
+
} else if (includeUndefinedValues === "excludeObjectChildren") {
|
|
1437
|
+
if (!isObject(computedDefault) || !isEmpty4(computedDefault)) {
|
|
1438
|
+
obj[key] = computedDefault;
|
|
1439
|
+
}
|
|
1405
1440
|
} else if (emptyObjectFields !== "skipDefaults") {
|
|
1406
1441
|
const isSelfOrParentRequired = isParentRequired === void 0 ? requiredFields.includes(key) : isParentRequired;
|
|
1407
1442
|
if (isObject(computedDefault)) {
|
|
@@ -2160,6 +2195,7 @@ function toPathSchema(validator, schema, name = "", rootSchema, formData, experi
|
|
|
2160
2195
|
}
|
|
2161
2196
|
|
|
2162
2197
|
// src/createSchemaUtils.ts
|
|
2198
|
+
import get16 from "lodash/get";
|
|
2163
2199
|
var SchemaUtils = class {
|
|
2164
2200
|
/** Constructs the `SchemaUtils` instance with the given `validator` and `rootSchema` stored as instance variables
|
|
2165
2201
|
*
|
|
@@ -2169,11 +2205,22 @@ var SchemaUtils = class {
|
|
|
2169
2205
|
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
2170
2206
|
*/
|
|
2171
2207
|
constructor(validator, rootSchema, experimental_defaultFormStateBehavior, experimental_customMergeAllOf) {
|
|
2172
|
-
|
|
2208
|
+
if (rootSchema[SCHEMA_KEY] === JSON_SCHEMA_DRAFT_2020_12) {
|
|
2209
|
+
this.rootSchema = makeAllReferencesAbsolute(rootSchema, get16(rootSchema, ID_KEY, "#"));
|
|
2210
|
+
} else {
|
|
2211
|
+
this.rootSchema = rootSchema;
|
|
2212
|
+
}
|
|
2173
2213
|
this.validator = validator;
|
|
2174
2214
|
this.experimental_defaultFormStateBehavior = experimental_defaultFormStateBehavior;
|
|
2175
2215
|
this.experimental_customMergeAllOf = experimental_customMergeAllOf;
|
|
2176
2216
|
}
|
|
2217
|
+
/** Returns the `rootSchema` in the `SchemaUtilsType`
|
|
2218
|
+
*
|
|
2219
|
+
* @returns - The `rootSchema`
|
|
2220
|
+
*/
|
|
2221
|
+
getRootSchema() {
|
|
2222
|
+
return this.rootSchema;
|
|
2223
|
+
}
|
|
2177
2224
|
/** Returns the `ValidatorType` in the `SchemaUtilsType`
|
|
2178
2225
|
*
|
|
2179
2226
|
* @returns - The `ValidatorType`
|
|
@@ -2493,6 +2540,31 @@ function dateRangeOptions(start, stop) {
|
|
|
2493
2540
|
return options;
|
|
2494
2541
|
}
|
|
2495
2542
|
|
|
2543
|
+
// src/shallowEquals.ts
|
|
2544
|
+
function shallowEquals(a, b) {
|
|
2545
|
+
if (Object.is(a, b)) {
|
|
2546
|
+
return true;
|
|
2547
|
+
}
|
|
2548
|
+
if (a == null || b == null) {
|
|
2549
|
+
return false;
|
|
2550
|
+
}
|
|
2551
|
+
if (typeof a !== "object" || typeof b !== "object") {
|
|
2552
|
+
return false;
|
|
2553
|
+
}
|
|
2554
|
+
const keysA = Object.keys(a);
|
|
2555
|
+
const keysB = Object.keys(b);
|
|
2556
|
+
if (keysA.length !== keysB.length) {
|
|
2557
|
+
return false;
|
|
2558
|
+
}
|
|
2559
|
+
for (let i = 0; i < keysA.length; i++) {
|
|
2560
|
+
const key = keysA[i];
|
|
2561
|
+
if (!Object.prototype.hasOwnProperty.call(b, key) || !Object.is(a[key], b[key])) {
|
|
2562
|
+
return false;
|
|
2563
|
+
}
|
|
2564
|
+
}
|
|
2565
|
+
return true;
|
|
2566
|
+
}
|
|
2567
|
+
|
|
2496
2568
|
// src/replaceStringParameters.ts
|
|
2497
2569
|
function replaceStringParameters(inputString, params) {
|
|
2498
2570
|
let output = inputString;
|
|
@@ -2565,7 +2637,7 @@ function enumOptionsSelectValue(valueIndex, selected, allEnumOptions = []) {
|
|
|
2565
2637
|
|
|
2566
2638
|
// src/ErrorSchemaBuilder.ts
|
|
2567
2639
|
import cloneDeep from "lodash/cloneDeep";
|
|
2568
|
-
import
|
|
2640
|
+
import get17 from "lodash/get";
|
|
2569
2641
|
import set3 from "lodash/set";
|
|
2570
2642
|
import setWith from "lodash/setWith";
|
|
2571
2643
|
var ErrorSchemaBuilder = class {
|
|
@@ -2594,7 +2666,7 @@ var ErrorSchemaBuilder = class {
|
|
|
2594
2666
|
*/
|
|
2595
2667
|
getOrCreateErrorBlock(pathOfError) {
|
|
2596
2668
|
const hasPath = Array.isArray(pathOfError) && pathOfError.length > 0 || typeof pathOfError === "string";
|
|
2597
|
-
let errorBlock = hasPath ?
|
|
2669
|
+
let errorBlock = hasPath ? get17(this.errorSchema, pathOfError) : this.errorSchema;
|
|
2598
2670
|
if (!errorBlock && pathOfError) {
|
|
2599
2671
|
errorBlock = {};
|
|
2600
2672
|
setWith(this.errorSchema, pathOfError, errorBlock, Object);
|
|
@@ -2620,7 +2692,7 @@ var ErrorSchemaBuilder = class {
|
|
|
2620
2692
|
*/
|
|
2621
2693
|
addErrors(errorOrList, pathOfError) {
|
|
2622
2694
|
const errorBlock = this.getOrCreateErrorBlock(pathOfError);
|
|
2623
|
-
let errorsList =
|
|
2695
|
+
let errorsList = get17(errorBlock, ERRORS_KEY);
|
|
2624
2696
|
if (!Array.isArray(errorsList)) {
|
|
2625
2697
|
errorsList = [];
|
|
2626
2698
|
errorBlock[ERRORS_KEY] = errorsList;
|
|
@@ -2769,9 +2841,9 @@ function getTemplate(name, registry, uiOptions = {}) {
|
|
|
2769
2841
|
|
|
2770
2842
|
// src/getTestIds.ts
|
|
2771
2843
|
import { nanoid } from "nanoid";
|
|
2772
|
-
import
|
|
2844
|
+
import get18 from "lodash/get";
|
|
2773
2845
|
function getTestIds() {
|
|
2774
|
-
if (typeof process === "undefined" ||
|
|
2846
|
+
if (typeof process === "undefined" || get18(process, "env.NODE_ENV") !== "test") {
|
|
2775
2847
|
return {};
|
|
2776
2848
|
}
|
|
2777
2849
|
const ids = /* @__PURE__ */ new Map();
|
|
@@ -2791,7 +2863,7 @@ function getTestIds() {
|
|
|
2791
2863
|
// src/getWidget.tsx
|
|
2792
2864
|
import { createElement } from "react";
|
|
2793
2865
|
import ReactIs from "react-is";
|
|
2794
|
-
import
|
|
2866
|
+
import get19 from "lodash/get";
|
|
2795
2867
|
import set4 from "lodash/set";
|
|
2796
2868
|
import { jsx } from "react/jsx-runtime";
|
|
2797
2869
|
var widgetMap = {
|
|
@@ -2847,7 +2919,7 @@ var widgetMap = {
|
|
|
2847
2919
|
}
|
|
2848
2920
|
};
|
|
2849
2921
|
function mergeWidgetOptions(AWidget) {
|
|
2850
|
-
let MergedWidget =
|
|
2922
|
+
let MergedWidget = get19(AWidget, "MergedWidget");
|
|
2851
2923
|
if (!MergedWidget) {
|
|
2852
2924
|
const defaultOptions = AWidget.defaultProps && AWidget.defaultProps.options || {};
|
|
2853
2925
|
MergedWidget = ({ options, ...props }) => {
|
|
@@ -2960,14 +3032,14 @@ function localToUTC(dateString) {
|
|
|
2960
3032
|
}
|
|
2961
3033
|
|
|
2962
3034
|
// src/lookupFromFormContext.ts
|
|
2963
|
-
import
|
|
3035
|
+
import get20 from "lodash/get";
|
|
2964
3036
|
import has6 from "lodash/has";
|
|
2965
3037
|
function lookupFromFormContext(regOrFc, toLookup, fallback) {
|
|
2966
3038
|
const lookupPath = [LOOKUP_MAP_NAME];
|
|
2967
3039
|
if (has6(regOrFc, FORM_CONTEXT_NAME)) {
|
|
2968
3040
|
lookupPath.unshift(FORM_CONTEXT_NAME);
|
|
2969
3041
|
}
|
|
2970
|
-
return
|
|
3042
|
+
return get20(regOrFc, [...lookupPath, toLookup], fallback);
|
|
2971
3043
|
}
|
|
2972
3044
|
|
|
2973
3045
|
// src/orderProperties.ts
|
|
@@ -3048,7 +3120,14 @@ function schemaRequiresTrueValue(schema) {
|
|
|
3048
3120
|
}
|
|
3049
3121
|
|
|
3050
3122
|
// src/shouldRender.ts
|
|
3051
|
-
function shouldRender(component, nextProps, nextState) {
|
|
3123
|
+
function shouldRender(component, nextProps, nextState, updateStrategy = "customDeep") {
|
|
3124
|
+
if (updateStrategy === "always") {
|
|
3125
|
+
return true;
|
|
3126
|
+
}
|
|
3127
|
+
if (updateStrategy === "shallow") {
|
|
3128
|
+
const { props: props2, state: state2 } = component;
|
|
3129
|
+
return !shallowEquals(props2, nextProps) || !shallowEquals(state2, nextState);
|
|
3130
|
+
}
|
|
3052
3131
|
const { props, state } = component;
|
|
3053
3132
|
return !deepEquals(props, nextProps) || !deepEquals(state, nextState);
|
|
3054
3133
|
}
|
|
@@ -3195,7 +3274,7 @@ function withIdRefPrefix(schemaNode) {
|
|
|
3195
3274
|
import keys from "lodash/keys";
|
|
3196
3275
|
import pickBy from "lodash/pickBy";
|
|
3197
3276
|
import isPlainObject4 from "lodash/isPlainObject";
|
|
3198
|
-
import
|
|
3277
|
+
import get21 from "lodash/get";
|
|
3199
3278
|
import difference from "lodash/difference";
|
|
3200
3279
|
function getChangedFields(a, b) {
|
|
3201
3280
|
const aIsPlainObject = isPlainObject4(a);
|
|
@@ -3208,7 +3287,7 @@ function getChangedFields(a, b) {
|
|
|
3208
3287
|
} else if (!aIsPlainObject && bIsPlainObject) {
|
|
3209
3288
|
return keys(b);
|
|
3210
3289
|
} else {
|
|
3211
|
-
const unequalFields = keys(pickBy(a, (value, key) => !deepEquals(value,
|
|
3290
|
+
const unequalFields = keys(pickBy(a, (value, key) => !deepEquals(value, get21(b, key))));
|
|
3212
3291
|
const diffFields = difference(keys(b), keys(a));
|
|
3213
3292
|
return [...unequalFields, ...diffFields];
|
|
3214
3293
|
}
|
|
@@ -3253,7 +3332,7 @@ var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
|
|
|
3253
3332
|
import forEach from "lodash/forEach";
|
|
3254
3333
|
|
|
3255
3334
|
// src/parser/ParserValidator.ts
|
|
3256
|
-
import
|
|
3335
|
+
import get22 from "lodash/get";
|
|
3257
3336
|
var ParserValidator = class {
|
|
3258
3337
|
/** Construct the ParserValidator for the given `rootSchema`. This `rootSchema` will be stashed in the `schemaMap`
|
|
3259
3338
|
* first.
|
|
@@ -3279,7 +3358,7 @@ var ParserValidator = class {
|
|
|
3279
3358
|
* @param hash - The hash value at which to map the schema
|
|
3280
3359
|
*/
|
|
3281
3360
|
addSchema(schema, hash) {
|
|
3282
|
-
const key =
|
|
3361
|
+
const key = get22(schema, ID_KEY, hash);
|
|
3283
3362
|
const identifiedSchema = { ...schema, [ID_KEY]: key };
|
|
3284
3363
|
const existing = this.schemaMap[key];
|
|
3285
3364
|
if (!existing) {
|
|
@@ -3386,6 +3465,7 @@ export {
|
|
|
3386
3465
|
ID_KEY,
|
|
3387
3466
|
IF_KEY,
|
|
3388
3467
|
ITEMS_KEY,
|
|
3468
|
+
JSON_SCHEMA_DRAFT_2019_09,
|
|
3389
3469
|
JSON_SCHEMA_DRAFT_2020_12,
|
|
3390
3470
|
JUNK_OPTION_ID,
|
|
3391
3471
|
LOOKUP_MAP_NAME,
|
|
@@ -3473,6 +3553,7 @@ export {
|
|
|
3473
3553
|
sanitizeDataForNewSchema,
|
|
3474
3554
|
schemaParser,
|
|
3475
3555
|
schemaRequiresTrueValue,
|
|
3556
|
+
shallowEquals,
|
|
3476
3557
|
shouldRender,
|
|
3477
3558
|
sortedJSONStringify,
|
|
3478
3559
|
titleId,
|