@rjsf/utils 6.0.2 → 6.1.0
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 +56 -50
- package/dist/index.cjs.map +4 -4
- package/dist/utils.esm.js +56 -50
- package/dist/utils.esm.js.map +4 -4
- package/dist/utils.umd.js +80 -77
- package/lib/schema/getDisplayLabel.js +22 -17
- package/lib/schema/getDisplayLabel.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types.d.ts +8 -1
- package/lib/useAltDateWidgetProps.js +1 -0
- package/lib/useAltDateWidgetProps.js.map +1 -1
- package/lib/useDeepCompareMemo.js +1 -0
- package/lib/useDeepCompareMemo.js.map +1 -1
- package/lib/useFileWidgetProps.js +1 -0
- package/lib/useFileWidgetProps.js.map +1 -1
- package/package.json +1 -1
- package/src/schema/getDisplayLabel.ts +23 -17
- package/src/types.ts +9 -0
- package/src/useAltDateWidgetProps.tsx +2 -0
- package/src/useDeepCompareMemo.ts +2 -0
- package/src/useFileWidgetProps.ts +2 -0
package/dist/index.cjs
CHANGED
|
@@ -2043,6 +2043,9 @@ function getDefaultFormState(validator, theSchema, formData, rootSchema, include
|
|
|
2043
2043
|
return defaults;
|
|
2044
2044
|
}
|
|
2045
2045
|
|
|
2046
|
+
// src/schema/getDisplayLabel.ts
|
|
2047
|
+
var import_get13 = __toESM(require("lodash/get"), 1);
|
|
2048
|
+
|
|
2046
2049
|
// src/isCustomWidget.ts
|
|
2047
2050
|
function isCustomWidget(uiSchema = {}) {
|
|
2048
2051
|
return (
|
|
@@ -2074,25 +2077,28 @@ function isFilesArray(validator, schema, uiSchema = {}, rootSchema, experimental
|
|
|
2074
2077
|
function getDisplayLabel(validator, schema, uiSchema = {}, rootSchema, globalOptions, experimental_customMergeAllOf) {
|
|
2075
2078
|
const uiOptions = getUiOptions(uiSchema, globalOptions);
|
|
2076
2079
|
const { label = true } = uiOptions;
|
|
2077
|
-
let displayLabel =
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2080
|
+
let displayLabel = Boolean(label);
|
|
2081
|
+
if (displayLabel) {
|
|
2082
|
+
const schemaType = getSchemaType(schema);
|
|
2083
|
+
const addedByAdditionalProperty = (0, import_get13.default)(schema, ADDITIONAL_PROPERTY_FLAG, false);
|
|
2084
|
+
if (schemaType === "array") {
|
|
2085
|
+
displayLabel = addedByAdditionalProperty || isMultiSelect(validator, schema, rootSchema, experimental_customMergeAllOf) || isFilesArray(validator, schema, uiSchema, rootSchema, experimental_customMergeAllOf) || isCustomWidget(uiSchema);
|
|
2086
|
+
}
|
|
2087
|
+
if (schemaType === "object") {
|
|
2088
|
+
displayLabel = addedByAdditionalProperty;
|
|
2089
|
+
}
|
|
2090
|
+
if (schemaType === "boolean" && uiSchema && !uiSchema[UI_WIDGET_KEY]) {
|
|
2091
|
+
displayLabel = false;
|
|
2092
|
+
}
|
|
2093
|
+
if (uiSchema && uiSchema[UI_FIELD_KEY]) {
|
|
2094
|
+
displayLabel = false;
|
|
2095
|
+
}
|
|
2090
2096
|
}
|
|
2091
2097
|
return displayLabel;
|
|
2092
2098
|
}
|
|
2093
2099
|
|
|
2094
2100
|
// src/schema/sanitizeDataForNewSchema.ts
|
|
2095
|
-
var
|
|
2101
|
+
var import_get14 = __toESM(require("lodash/get"), 1);
|
|
2096
2102
|
var import_has5 = __toESM(require("lodash/has"), 1);
|
|
2097
2103
|
var NO_VALUE = Symbol("no Value");
|
|
2098
2104
|
function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, data = {}, experimental_customMergeAllOf) {
|
|
@@ -2100,19 +2106,19 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
2100
2106
|
if ((0, import_has5.default)(newSchema, PROPERTIES_KEY)) {
|
|
2101
2107
|
const removeOldSchemaData = {};
|
|
2102
2108
|
if ((0, import_has5.default)(oldSchema, PROPERTIES_KEY)) {
|
|
2103
|
-
const properties = (0,
|
|
2109
|
+
const properties = (0, import_get14.default)(oldSchema, PROPERTIES_KEY, {});
|
|
2104
2110
|
Object.keys(properties).forEach((key) => {
|
|
2105
2111
|
if ((0, import_has5.default)(data, key)) {
|
|
2106
2112
|
removeOldSchemaData[key] = void 0;
|
|
2107
2113
|
}
|
|
2108
2114
|
});
|
|
2109
2115
|
}
|
|
2110
|
-
const keys2 = Object.keys((0,
|
|
2116
|
+
const keys2 = Object.keys((0, import_get14.default)(newSchema, PROPERTIES_KEY, {}));
|
|
2111
2117
|
const nestedData = {};
|
|
2112
2118
|
keys2.forEach((key) => {
|
|
2113
|
-
const formValue = (0,
|
|
2114
|
-
let oldKeyedSchema = (0,
|
|
2115
|
-
let newKeyedSchema = (0,
|
|
2119
|
+
const formValue = (0, import_get14.default)(data, key);
|
|
2120
|
+
let oldKeyedSchema = (0, import_get14.default)(oldSchema, [PROPERTIES_KEY, key], {});
|
|
2121
|
+
let newKeyedSchema = (0, import_get14.default)(newSchema, [PROPERTIES_KEY, key], {});
|
|
2116
2122
|
if ((0, import_has5.default)(oldKeyedSchema, REF_KEY)) {
|
|
2117
2123
|
oldKeyedSchema = retrieveSchema(
|
|
2118
2124
|
validator,
|
|
@@ -2131,8 +2137,8 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
2131
2137
|
experimental_customMergeAllOf
|
|
2132
2138
|
);
|
|
2133
2139
|
}
|
|
2134
|
-
const oldSchemaTypeForKey = (0,
|
|
2135
|
-
const newSchemaTypeForKey = (0,
|
|
2140
|
+
const oldSchemaTypeForKey = (0, import_get14.default)(oldKeyedSchema, "type");
|
|
2141
|
+
const newSchemaTypeForKey = (0, import_get14.default)(newKeyedSchema, "type");
|
|
2136
2142
|
if (!oldSchemaTypeForKey || oldSchemaTypeForKey === newSchemaTypeForKey) {
|
|
2137
2143
|
if ((0, import_has5.default)(removeOldSchemaData, key)) {
|
|
2138
2144
|
delete removeOldSchemaData[key];
|
|
@@ -2150,17 +2156,17 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
2150
2156
|
nestedData[key] = itemData;
|
|
2151
2157
|
}
|
|
2152
2158
|
} else {
|
|
2153
|
-
const newOptionDefault = (0,
|
|
2154
|
-
const oldOptionDefault = (0,
|
|
2159
|
+
const newOptionDefault = (0, import_get14.default)(newKeyedSchema, "default", NO_VALUE);
|
|
2160
|
+
const oldOptionDefault = (0, import_get14.default)(oldKeyedSchema, "default", NO_VALUE);
|
|
2155
2161
|
if (newOptionDefault !== NO_VALUE && newOptionDefault !== formValue) {
|
|
2156
2162
|
if (oldOptionDefault === formValue) {
|
|
2157
2163
|
removeOldSchemaData[key] = newOptionDefault;
|
|
2158
|
-
} else if ((0,
|
|
2164
|
+
} else if ((0, import_get14.default)(newKeyedSchema, "readOnly") === true) {
|
|
2159
2165
|
removeOldSchemaData[key] = void 0;
|
|
2160
2166
|
}
|
|
2161
2167
|
}
|
|
2162
|
-
const newOptionConst = (0,
|
|
2163
|
-
const oldOptionConst = (0,
|
|
2168
|
+
const newOptionConst = (0, import_get14.default)(newKeyedSchema, "const", NO_VALUE);
|
|
2169
|
+
const oldOptionConst = (0, import_get14.default)(oldKeyedSchema, "const", NO_VALUE);
|
|
2164
2170
|
if (newOptionConst !== NO_VALUE && newOptionConst !== formValue) {
|
|
2165
2171
|
removeOldSchemaData[key] = oldOptionConst === formValue ? newOptionConst : void 0;
|
|
2166
2172
|
}
|
|
@@ -2172,9 +2178,9 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
2172
2178
|
...removeOldSchemaData,
|
|
2173
2179
|
...nestedData
|
|
2174
2180
|
};
|
|
2175
|
-
} else if ((0,
|
|
2176
|
-
let oldSchemaItems = (0,
|
|
2177
|
-
let newSchemaItems = (0,
|
|
2181
|
+
} else if ((0, import_get14.default)(oldSchema, "type") === "array" && (0, import_get14.default)(newSchema, "type") === "array" && Array.isArray(data)) {
|
|
2182
|
+
let oldSchemaItems = (0, import_get14.default)(oldSchema, "items");
|
|
2183
|
+
let newSchemaItems = (0, import_get14.default)(newSchema, "items");
|
|
2178
2184
|
if (typeof oldSchemaItems === "object" && typeof newSchemaItems === "object" && !Array.isArray(oldSchemaItems) && !Array.isArray(newSchemaItems)) {
|
|
2179
2185
|
if ((0, import_has5.default)(oldSchemaItems, REF_KEY)) {
|
|
2180
2186
|
oldSchemaItems = retrieveSchema(
|
|
@@ -2194,10 +2200,10 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
2194
2200
|
experimental_customMergeAllOf
|
|
2195
2201
|
);
|
|
2196
2202
|
}
|
|
2197
|
-
const oldSchemaType = (0,
|
|
2198
|
-
const newSchemaType = (0,
|
|
2203
|
+
const oldSchemaType = (0, import_get14.default)(oldSchemaItems, "type");
|
|
2204
|
+
const newSchemaType = (0, import_get14.default)(newSchemaItems, "type");
|
|
2199
2205
|
if (!oldSchemaType || oldSchemaType === newSchemaType) {
|
|
2200
|
-
const maxItems = (0,
|
|
2206
|
+
const maxItems = (0, import_get14.default)(newSchema, "maxItems", -1);
|
|
2201
2207
|
if (newSchemaType === "object") {
|
|
2202
2208
|
newFormData = data.reduce((newValue, aValue) => {
|
|
2203
2209
|
const itemValue = sanitizeDataForNewSchema(
|
|
@@ -2225,7 +2231,7 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
2225
2231
|
}
|
|
2226
2232
|
|
|
2227
2233
|
// src/schema/toPathSchema.ts
|
|
2228
|
-
var
|
|
2234
|
+
var import_get15 = __toESM(require("lodash/get"), 1);
|
|
2229
2235
|
var import_set2 = __toESM(require("lodash/set"), 1);
|
|
2230
2236
|
function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
|
|
2231
2237
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
@@ -2318,7 +2324,7 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
2318
2324
|
}
|
|
2319
2325
|
} else if (PROPERTIES_KEY in schema) {
|
|
2320
2326
|
for (const property in schema.properties) {
|
|
2321
|
-
const field = (0,
|
|
2327
|
+
const field = (0, import_get15.default)(schema, [PROPERTIES_KEY, property], {});
|
|
2322
2328
|
pathSchema[property] = toPathSchemaInternal(
|
|
2323
2329
|
validator,
|
|
2324
2330
|
field,
|
|
@@ -2326,7 +2332,7 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
2326
2332
|
rootSchema,
|
|
2327
2333
|
// It's possible that formData is not an object -- this can happen if an
|
|
2328
2334
|
// array item has just been added, but not populated with data yet
|
|
2329
|
-
(0,
|
|
2335
|
+
(0, import_get15.default)(formData, [property]),
|
|
2330
2336
|
_recurseList,
|
|
2331
2337
|
experimental_customMergeAllOf
|
|
2332
2338
|
);
|
|
@@ -2339,7 +2345,7 @@ function toPathSchema(validator, schema, name = "", rootSchema, formData, experi
|
|
|
2339
2345
|
}
|
|
2340
2346
|
|
|
2341
2347
|
// src/createSchemaUtils.ts
|
|
2342
|
-
var
|
|
2348
|
+
var import_get16 = __toESM(require("lodash/get"), 1);
|
|
2343
2349
|
var SchemaUtils = class {
|
|
2344
2350
|
/** Constructs the `SchemaUtils` instance with the given `validator` and `rootSchema` stored as instance variables
|
|
2345
2351
|
*
|
|
@@ -2350,7 +2356,7 @@ var SchemaUtils = class {
|
|
|
2350
2356
|
*/
|
|
2351
2357
|
constructor(validator, rootSchema, experimental_defaultFormStateBehavior, experimental_customMergeAllOf) {
|
|
2352
2358
|
if (rootSchema && rootSchema[SCHEMA_KEY] === JSON_SCHEMA_DRAFT_2020_12) {
|
|
2353
|
-
this.rootSchema = makeAllReferencesAbsolute(rootSchema, (0,
|
|
2359
|
+
this.rootSchema = makeAllReferencesAbsolute(rootSchema, (0, import_get16.default)(rootSchema, ID_KEY, "#"));
|
|
2354
2360
|
} else {
|
|
2355
2361
|
this.rootSchema = rootSchema;
|
|
2356
2362
|
}
|
|
@@ -2764,7 +2770,7 @@ function enumOptionsSelectValue(valueIndex, selected, allEnumOptions = []) {
|
|
|
2764
2770
|
|
|
2765
2771
|
// src/ErrorSchemaBuilder.ts
|
|
2766
2772
|
var import_cloneDeep = __toESM(require("lodash/cloneDeep"), 1);
|
|
2767
|
-
var
|
|
2773
|
+
var import_get17 = __toESM(require("lodash/get"), 1);
|
|
2768
2774
|
var import_set3 = __toESM(require("lodash/set"), 1);
|
|
2769
2775
|
var import_setWith = __toESM(require("lodash/setWith"), 1);
|
|
2770
2776
|
var ErrorSchemaBuilder = class {
|
|
@@ -2793,7 +2799,7 @@ var ErrorSchemaBuilder = class {
|
|
|
2793
2799
|
*/
|
|
2794
2800
|
getOrCreateErrorBlock(pathOfError) {
|
|
2795
2801
|
const hasPath = Array.isArray(pathOfError) && pathOfError.length > 0 || typeof pathOfError === "string";
|
|
2796
|
-
let errorBlock = hasPath ? (0,
|
|
2802
|
+
let errorBlock = hasPath ? (0, import_get17.default)(this.errorSchema, pathOfError) : this.errorSchema;
|
|
2797
2803
|
if (!errorBlock && pathOfError) {
|
|
2798
2804
|
errorBlock = {};
|
|
2799
2805
|
(0, import_setWith.default)(this.errorSchema, pathOfError, errorBlock, Object);
|
|
@@ -2819,7 +2825,7 @@ var ErrorSchemaBuilder = class {
|
|
|
2819
2825
|
*/
|
|
2820
2826
|
addErrors(errorOrList, pathOfError) {
|
|
2821
2827
|
const errorBlock = this.getOrCreateErrorBlock(pathOfError);
|
|
2822
|
-
let errorsList = (0,
|
|
2828
|
+
let errorsList = (0, import_get17.default)(errorBlock, ERRORS_KEY);
|
|
2823
2829
|
if (!Array.isArray(errorsList)) {
|
|
2824
2830
|
errorsList = [];
|
|
2825
2831
|
errorBlock[ERRORS_KEY] = errorsList;
|
|
@@ -2863,7 +2869,7 @@ var ErrorSchemaBuilder = class {
|
|
|
2863
2869
|
var import_keys = __toESM(require("lodash/keys"), 1);
|
|
2864
2870
|
var import_pickBy = __toESM(require("lodash/pickBy"), 1);
|
|
2865
2871
|
var import_isPlainObject2 = __toESM(require("lodash/isPlainObject"), 1);
|
|
2866
|
-
var
|
|
2872
|
+
var import_get18 = __toESM(require("lodash/get"), 1);
|
|
2867
2873
|
var import_difference = __toESM(require("lodash/difference"), 1);
|
|
2868
2874
|
function getChangedFields(a, b) {
|
|
2869
2875
|
const aIsPlainObject = (0, import_isPlainObject2.default)(a);
|
|
@@ -2876,7 +2882,7 @@ function getChangedFields(a, b) {
|
|
|
2876
2882
|
} else if (!aIsPlainObject && bIsPlainObject) {
|
|
2877
2883
|
return (0, import_keys.default)(b);
|
|
2878
2884
|
} else {
|
|
2879
|
-
const unequalFields = (0, import_keys.default)((0, import_pickBy.default)(a, (value, key) => !deepEquals(value, (0,
|
|
2885
|
+
const unequalFields = (0, import_keys.default)((0, import_pickBy.default)(a, (value, key) => !deepEquals(value, (0, import_get18.default)(b, key))));
|
|
2880
2886
|
const diffFields = (0, import_difference.default)((0, import_keys.default)(b), (0, import_keys.default)(a));
|
|
2881
2887
|
return [...unequalFields, ...diffFields];
|
|
2882
2888
|
}
|
|
@@ -2990,10 +2996,10 @@ function getTemplate(name, registry, uiOptions = {}) {
|
|
|
2990
2996
|
}
|
|
2991
2997
|
|
|
2992
2998
|
// src/getTestIds.ts
|
|
2993
|
-
var
|
|
2999
|
+
var import_get19 = __toESM(require("lodash/get"), 1);
|
|
2994
3000
|
var import_uniqueId = __toESM(require("lodash/uniqueId"), 1);
|
|
2995
3001
|
function getTestIds() {
|
|
2996
|
-
if (typeof process === "undefined" || (0,
|
|
3002
|
+
if (typeof process === "undefined" || (0, import_get19.default)(process, "env.NODE_ENV") !== "test") {
|
|
2997
3003
|
return {};
|
|
2998
3004
|
}
|
|
2999
3005
|
const ids = /* @__PURE__ */ new Map();
|
|
@@ -3013,7 +3019,7 @@ function getTestIds() {
|
|
|
3013
3019
|
// src/getWidget.tsx
|
|
3014
3020
|
var import_react = require("react");
|
|
3015
3021
|
var import_react_is = __toESM(require("react-is"), 1);
|
|
3016
|
-
var
|
|
3022
|
+
var import_get20 = __toESM(require("lodash/get"), 1);
|
|
3017
3023
|
var import_set4 = __toESM(require("lodash/set"), 1);
|
|
3018
3024
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
3019
3025
|
var widgetMap = {
|
|
@@ -3069,7 +3075,7 @@ var widgetMap = {
|
|
|
3069
3075
|
}
|
|
3070
3076
|
};
|
|
3071
3077
|
function mergeWidgetOptions(AWidget) {
|
|
3072
|
-
let MergedWidget = (0,
|
|
3078
|
+
let MergedWidget = (0, import_get20.default)(AWidget, "MergedWidget");
|
|
3073
3079
|
if (!MergedWidget) {
|
|
3074
3080
|
const defaultOptions = AWidget.defaultProps && AWidget.defaultProps.options || {};
|
|
3075
3081
|
MergedWidget = ({ options, ...props }) => {
|
|
@@ -3207,14 +3213,14 @@ function localToUTC(dateString) {
|
|
|
3207
3213
|
}
|
|
3208
3214
|
|
|
3209
3215
|
// src/lookupFromFormContext.ts
|
|
3210
|
-
var
|
|
3216
|
+
var import_get21 = __toESM(require("lodash/get"), 1);
|
|
3211
3217
|
var import_has6 = __toESM(require("lodash/has"), 1);
|
|
3212
3218
|
function lookupFromFormContext(regOrFc, toLookup, fallback) {
|
|
3213
3219
|
const lookupPath = [LOOKUP_MAP_NAME];
|
|
3214
3220
|
if ((0, import_has6.default)(regOrFc, FORM_CONTEXT_NAME)) {
|
|
3215
3221
|
lookupPath.unshift(FORM_CONTEXT_NAME);
|
|
3216
3222
|
}
|
|
3217
|
-
return (0,
|
|
3223
|
+
return (0, import_get21.default)(regOrFc, [...lookupPath, toLookup], fallback);
|
|
3218
3224
|
}
|
|
3219
3225
|
|
|
3220
3226
|
// src/orderProperties.ts
|
|
@@ -3751,7 +3757,7 @@ var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
|
|
|
3751
3757
|
var import_forEach = __toESM(require("lodash/forEach"), 1);
|
|
3752
3758
|
|
|
3753
3759
|
// src/parser/ParserValidator.ts
|
|
3754
|
-
var
|
|
3760
|
+
var import_get22 = __toESM(require("lodash/get"), 1);
|
|
3755
3761
|
var ParserValidator = class {
|
|
3756
3762
|
/** Construct the ParserValidator for the given `rootSchema`. This `rootSchema` will be stashed in the `schemaMap`
|
|
3757
3763
|
* first.
|
|
@@ -3777,7 +3783,7 @@ var ParserValidator = class {
|
|
|
3777
3783
|
* @param hash - The hash value at which to map the schema
|
|
3778
3784
|
*/
|
|
3779
3785
|
addSchema(schema, hash) {
|
|
3780
|
-
const key = (0,
|
|
3786
|
+
const key = (0, import_get22.default)(schema, ID_KEY, hash);
|
|
3781
3787
|
const identifiedSchema = { ...schema, [ID_KEY]: key };
|
|
3782
3788
|
const existing = this.schemaMap[key];
|
|
3783
3789
|
if (!existing) {
|