@rjsf/utils 6.0.0-beta.12 → 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 +95 -21
- package/dist/index.js.map +4 -4
- package/dist/utils.esm.js +95 -21
- package/dist/utils.esm.js.map +4 -4
- package/dist/utils.umd.js +93 -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 +9 -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 +2 -0
- package/package.json +1 -1
- package/src/constants.ts +1 -0
- package/src/createSchemaUtils.ts +8 -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 +2 -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,7 +2205,11 @@ 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;
|
|
@@ -2500,6 +2540,31 @@ function dateRangeOptions(start, stop) {
|
|
|
2500
2540
|
return options;
|
|
2501
2541
|
}
|
|
2502
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
|
+
|
|
2503
2568
|
// src/replaceStringParameters.ts
|
|
2504
2569
|
function replaceStringParameters(inputString, params) {
|
|
2505
2570
|
let output = inputString;
|
|
@@ -2572,7 +2637,7 @@ function enumOptionsSelectValue(valueIndex, selected, allEnumOptions = []) {
|
|
|
2572
2637
|
|
|
2573
2638
|
// src/ErrorSchemaBuilder.ts
|
|
2574
2639
|
import cloneDeep from "lodash/cloneDeep";
|
|
2575
|
-
import
|
|
2640
|
+
import get17 from "lodash/get";
|
|
2576
2641
|
import set3 from "lodash/set";
|
|
2577
2642
|
import setWith from "lodash/setWith";
|
|
2578
2643
|
var ErrorSchemaBuilder = class {
|
|
@@ -2601,7 +2666,7 @@ var ErrorSchemaBuilder = class {
|
|
|
2601
2666
|
*/
|
|
2602
2667
|
getOrCreateErrorBlock(pathOfError) {
|
|
2603
2668
|
const hasPath = Array.isArray(pathOfError) && pathOfError.length > 0 || typeof pathOfError === "string";
|
|
2604
|
-
let errorBlock = hasPath ?
|
|
2669
|
+
let errorBlock = hasPath ? get17(this.errorSchema, pathOfError) : this.errorSchema;
|
|
2605
2670
|
if (!errorBlock && pathOfError) {
|
|
2606
2671
|
errorBlock = {};
|
|
2607
2672
|
setWith(this.errorSchema, pathOfError, errorBlock, Object);
|
|
@@ -2627,7 +2692,7 @@ var ErrorSchemaBuilder = class {
|
|
|
2627
2692
|
*/
|
|
2628
2693
|
addErrors(errorOrList, pathOfError) {
|
|
2629
2694
|
const errorBlock = this.getOrCreateErrorBlock(pathOfError);
|
|
2630
|
-
let errorsList =
|
|
2695
|
+
let errorsList = get17(errorBlock, ERRORS_KEY);
|
|
2631
2696
|
if (!Array.isArray(errorsList)) {
|
|
2632
2697
|
errorsList = [];
|
|
2633
2698
|
errorBlock[ERRORS_KEY] = errorsList;
|
|
@@ -2776,9 +2841,9 @@ function getTemplate(name, registry, uiOptions = {}) {
|
|
|
2776
2841
|
|
|
2777
2842
|
// src/getTestIds.ts
|
|
2778
2843
|
import { nanoid } from "nanoid";
|
|
2779
|
-
import
|
|
2844
|
+
import get18 from "lodash/get";
|
|
2780
2845
|
function getTestIds() {
|
|
2781
|
-
if (typeof process === "undefined" ||
|
|
2846
|
+
if (typeof process === "undefined" || get18(process, "env.NODE_ENV") !== "test") {
|
|
2782
2847
|
return {};
|
|
2783
2848
|
}
|
|
2784
2849
|
const ids = /* @__PURE__ */ new Map();
|
|
@@ -2798,7 +2863,7 @@ function getTestIds() {
|
|
|
2798
2863
|
// src/getWidget.tsx
|
|
2799
2864
|
import { createElement } from "react";
|
|
2800
2865
|
import ReactIs from "react-is";
|
|
2801
|
-
import
|
|
2866
|
+
import get19 from "lodash/get";
|
|
2802
2867
|
import set4 from "lodash/set";
|
|
2803
2868
|
import { jsx } from "react/jsx-runtime";
|
|
2804
2869
|
var widgetMap = {
|
|
@@ -2854,7 +2919,7 @@ var widgetMap = {
|
|
|
2854
2919
|
}
|
|
2855
2920
|
};
|
|
2856
2921
|
function mergeWidgetOptions(AWidget) {
|
|
2857
|
-
let MergedWidget =
|
|
2922
|
+
let MergedWidget = get19(AWidget, "MergedWidget");
|
|
2858
2923
|
if (!MergedWidget) {
|
|
2859
2924
|
const defaultOptions = AWidget.defaultProps && AWidget.defaultProps.options || {};
|
|
2860
2925
|
MergedWidget = ({ options, ...props }) => {
|
|
@@ -2967,14 +3032,14 @@ function localToUTC(dateString) {
|
|
|
2967
3032
|
}
|
|
2968
3033
|
|
|
2969
3034
|
// src/lookupFromFormContext.ts
|
|
2970
|
-
import
|
|
3035
|
+
import get20 from "lodash/get";
|
|
2971
3036
|
import has6 from "lodash/has";
|
|
2972
3037
|
function lookupFromFormContext(regOrFc, toLookup, fallback) {
|
|
2973
3038
|
const lookupPath = [LOOKUP_MAP_NAME];
|
|
2974
3039
|
if (has6(regOrFc, FORM_CONTEXT_NAME)) {
|
|
2975
3040
|
lookupPath.unshift(FORM_CONTEXT_NAME);
|
|
2976
3041
|
}
|
|
2977
|
-
return
|
|
3042
|
+
return get20(regOrFc, [...lookupPath, toLookup], fallback);
|
|
2978
3043
|
}
|
|
2979
3044
|
|
|
2980
3045
|
// src/orderProperties.ts
|
|
@@ -3055,7 +3120,14 @@ function schemaRequiresTrueValue(schema) {
|
|
|
3055
3120
|
}
|
|
3056
3121
|
|
|
3057
3122
|
// src/shouldRender.ts
|
|
3058
|
-
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
|
+
}
|
|
3059
3131
|
const { props, state } = component;
|
|
3060
3132
|
return !deepEquals(props, nextProps) || !deepEquals(state, nextState);
|
|
3061
3133
|
}
|
|
@@ -3202,7 +3274,7 @@ function withIdRefPrefix(schemaNode) {
|
|
|
3202
3274
|
import keys from "lodash/keys";
|
|
3203
3275
|
import pickBy from "lodash/pickBy";
|
|
3204
3276
|
import isPlainObject4 from "lodash/isPlainObject";
|
|
3205
|
-
import
|
|
3277
|
+
import get21 from "lodash/get";
|
|
3206
3278
|
import difference from "lodash/difference";
|
|
3207
3279
|
function getChangedFields(a, b) {
|
|
3208
3280
|
const aIsPlainObject = isPlainObject4(a);
|
|
@@ -3215,7 +3287,7 @@ function getChangedFields(a, b) {
|
|
|
3215
3287
|
} else if (!aIsPlainObject && bIsPlainObject) {
|
|
3216
3288
|
return keys(b);
|
|
3217
3289
|
} else {
|
|
3218
|
-
const unequalFields = keys(pickBy(a, (value, key) => !deepEquals(value,
|
|
3290
|
+
const unequalFields = keys(pickBy(a, (value, key) => !deepEquals(value, get21(b, key))));
|
|
3219
3291
|
const diffFields = difference(keys(b), keys(a));
|
|
3220
3292
|
return [...unequalFields, ...diffFields];
|
|
3221
3293
|
}
|
|
@@ -3260,7 +3332,7 @@ var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
|
|
|
3260
3332
|
import forEach from "lodash/forEach";
|
|
3261
3333
|
|
|
3262
3334
|
// src/parser/ParserValidator.ts
|
|
3263
|
-
import
|
|
3335
|
+
import get22 from "lodash/get";
|
|
3264
3336
|
var ParserValidator = class {
|
|
3265
3337
|
/** Construct the ParserValidator for the given `rootSchema`. This `rootSchema` will be stashed in the `schemaMap`
|
|
3266
3338
|
* first.
|
|
@@ -3286,7 +3358,7 @@ var ParserValidator = class {
|
|
|
3286
3358
|
* @param hash - The hash value at which to map the schema
|
|
3287
3359
|
*/
|
|
3288
3360
|
addSchema(schema, hash) {
|
|
3289
|
-
const key =
|
|
3361
|
+
const key = get22(schema, ID_KEY, hash);
|
|
3290
3362
|
const identifiedSchema = { ...schema, [ID_KEY]: key };
|
|
3291
3363
|
const existing = this.schemaMap[key];
|
|
3292
3364
|
if (!existing) {
|
|
@@ -3393,6 +3465,7 @@ export {
|
|
|
3393
3465
|
ID_KEY,
|
|
3394
3466
|
IF_KEY,
|
|
3395
3467
|
ITEMS_KEY,
|
|
3468
|
+
JSON_SCHEMA_DRAFT_2019_09,
|
|
3396
3469
|
JSON_SCHEMA_DRAFT_2020_12,
|
|
3397
3470
|
JUNK_OPTION_ID,
|
|
3398
3471
|
LOOKUP_MAP_NAME,
|
|
@@ -3480,6 +3553,7 @@ export {
|
|
|
3480
3553
|
sanitizeDataForNewSchema,
|
|
3481
3554
|
schemaParser,
|
|
3482
3555
|
schemaRequiresTrueValue,
|
|
3556
|
+
shallowEquals,
|
|
3483
3557
|
shouldRender,
|
|
3484
3558
|
sortedJSONStringify,
|
|
3485
3559
|
titleId,
|