@rjsf/utils 6.2.5 → 6.3.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 +88 -4
- package/dist/index.cjs.map +3 -3
- package/dist/utils.esm.js +84 -0
- package/dist/utils.esm.js.map +3 -3
- package/dist/utils.umd.js +84 -0
- package/lib/constants.d.ts +1 -0
- package/lib/constants.js +1 -0
- package/lib/constants.js.map +1 -1
- package/lib/createSchemaUtils.js.map +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/lib/parser/ParserValidator.js.map +1 -1
- package/lib/resolveUiSchema.d.ts +32 -0
- package/lib/resolveUiSchema.js +119 -0
- package/lib/resolveUiSchema.js.map +1 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types.d.ts +18 -0
- package/package.json +3 -3
- package/src/constants.ts +1 -0
- package/src/createSchemaUtils.ts +5 -3
- package/src/index.ts +3 -0
- package/src/parser/ParserValidator.ts +5 -3
- package/src/resolveUiSchema.ts +156 -0
- package/src/types.ts +23 -2
package/dist/utils.esm.js
CHANGED
|
@@ -77,6 +77,7 @@ var UI_FIELD_KEY = "ui:field";
|
|
|
77
77
|
var UI_WIDGET_KEY = "ui:widget";
|
|
78
78
|
var UI_OPTIONS_KEY = "ui:options";
|
|
79
79
|
var UI_GLOBAL_OPTIONS_KEY = "ui:globalOptions";
|
|
80
|
+
var UI_DEFINITIONS_KEY = "ui:definitions";
|
|
80
81
|
var JSON_SCHEMA_DRAFT_2019_09 = "https://json-schema.org/draft/2019-09/schema";
|
|
81
82
|
var JSON_SCHEMA_DRAFT_2020_12 = "https://json-schema.org/draft/2020-12/schema";
|
|
82
83
|
|
|
@@ -3188,6 +3189,86 @@ function parseDateString(dateString, includeTime = true) {
|
|
|
3188
3189
|
};
|
|
3189
3190
|
}
|
|
3190
3191
|
|
|
3192
|
+
// src/resolveUiSchema.ts
|
|
3193
|
+
var SAME_KEY_KEYWORDS = [ITEMS_KEY, ADDITIONAL_PROPERTIES_KEY];
|
|
3194
|
+
var ARRAY_KEYWORDS = [ONE_OF_KEY, ANY_OF_KEY, ALL_OF_KEY];
|
|
3195
|
+
function expandUiSchemaDefinitions(currentSchema, uiSchema, registry, visited = /* @__PURE__ */ new Set()) {
|
|
3196
|
+
const { rootSchema, uiSchemaDefinitions: definitions } = registry;
|
|
3197
|
+
let result = { ...uiSchema };
|
|
3198
|
+
let resolvedSchema = currentSchema;
|
|
3199
|
+
const ref = currentSchema[REF_KEY];
|
|
3200
|
+
const isRecursive = ref && visited.has(ref);
|
|
3201
|
+
if (ref) {
|
|
3202
|
+
visited.add(ref);
|
|
3203
|
+
if (definitions && ref in definitions) {
|
|
3204
|
+
result = mergeObjects(definitions[ref], result);
|
|
3205
|
+
}
|
|
3206
|
+
if (isRecursive) {
|
|
3207
|
+
return result;
|
|
3208
|
+
}
|
|
3209
|
+
try {
|
|
3210
|
+
resolvedSchema = findSchemaDefinition(ref, rootSchema);
|
|
3211
|
+
} catch {
|
|
3212
|
+
resolvedSchema = currentSchema;
|
|
3213
|
+
}
|
|
3214
|
+
}
|
|
3215
|
+
const properties = resolvedSchema[PROPERTIES_KEY];
|
|
3216
|
+
if (properties && isObject(properties)) {
|
|
3217
|
+
for (const [propName, propSchema] of Object.entries(properties)) {
|
|
3218
|
+
const propUiSchema = result[propName] || {};
|
|
3219
|
+
const expanded = expandUiSchemaDefinitions(propSchema, propUiSchema, registry, new Set(visited));
|
|
3220
|
+
if (Object.keys(expanded).length > 0) {
|
|
3221
|
+
result[propName] = expanded;
|
|
3222
|
+
}
|
|
3223
|
+
}
|
|
3224
|
+
}
|
|
3225
|
+
for (const keyword of SAME_KEY_KEYWORDS) {
|
|
3226
|
+
const subSchema = resolvedSchema[keyword];
|
|
3227
|
+
if (subSchema && isObject(subSchema) && !Array.isArray(subSchema)) {
|
|
3228
|
+
const currentUiSchema = result[keyword];
|
|
3229
|
+
if (typeof currentUiSchema !== "function") {
|
|
3230
|
+
const subUiSchema = currentUiSchema || {};
|
|
3231
|
+
const expanded = expandUiSchemaDefinitions(subSchema, subUiSchema, registry, new Set(visited));
|
|
3232
|
+
if (Object.keys(expanded).length > 0) {
|
|
3233
|
+
result[keyword] = expanded;
|
|
3234
|
+
}
|
|
3235
|
+
}
|
|
3236
|
+
}
|
|
3237
|
+
}
|
|
3238
|
+
for (const keyword of ARRAY_KEYWORDS) {
|
|
3239
|
+
const schemaOptions = resolvedSchema[keyword];
|
|
3240
|
+
if (Array.isArray(schemaOptions) && schemaOptions.length > 0) {
|
|
3241
|
+
const currentUiSchemaArray = result[keyword];
|
|
3242
|
+
const uiSchemaArray = Array.isArray(currentUiSchemaArray) ? [...currentUiSchemaArray] : [];
|
|
3243
|
+
let hasExpanded = false;
|
|
3244
|
+
for (let i = 0; i < schemaOptions.length; i++) {
|
|
3245
|
+
const optionSchema = schemaOptions[i];
|
|
3246
|
+
const optionUiSchema = uiSchemaArray[i] || {};
|
|
3247
|
+
const expanded = expandUiSchemaDefinitions(optionSchema, optionUiSchema, registry, new Set(visited));
|
|
3248
|
+
if (Object.keys(expanded).length > 0) {
|
|
3249
|
+
uiSchemaArray[i] = expanded;
|
|
3250
|
+
hasExpanded = true;
|
|
3251
|
+
}
|
|
3252
|
+
}
|
|
3253
|
+
if (hasExpanded) {
|
|
3254
|
+
result[keyword] = uiSchemaArray;
|
|
3255
|
+
}
|
|
3256
|
+
}
|
|
3257
|
+
}
|
|
3258
|
+
return result;
|
|
3259
|
+
}
|
|
3260
|
+
function resolveUiSchema(schema, localUiSchema, registry) {
|
|
3261
|
+
const ref = schema[REF_KEY];
|
|
3262
|
+
const definitionUiSchema = ref ? registry.uiSchemaDefinitions?.[ref] : void 0;
|
|
3263
|
+
if (!definitionUiSchema) {
|
|
3264
|
+
return localUiSchema || {};
|
|
3265
|
+
}
|
|
3266
|
+
if (!localUiSchema || Object.keys(localUiSchema).length === 0) {
|
|
3267
|
+
return { ...definitionUiSchema };
|
|
3268
|
+
}
|
|
3269
|
+
return mergeObjects(definitionUiSchema, localUiSchema);
|
|
3270
|
+
}
|
|
3271
|
+
|
|
3191
3272
|
// src/schemaRequiresTrueValue.ts
|
|
3192
3273
|
function schemaRequiresTrueValue(schema) {
|
|
3193
3274
|
if (schema.const) {
|
|
@@ -3819,6 +3900,7 @@ export {
|
|
|
3819
3900
|
SCHEMA_KEY,
|
|
3820
3901
|
SUBMIT_BTN_OPTIONS_KEY,
|
|
3821
3902
|
TranslatableString,
|
|
3903
|
+
UI_DEFINITIONS_KEY,
|
|
3822
3904
|
UI_FIELD_KEY,
|
|
3823
3905
|
UI_GLOBAL_OPTIONS_KEY,
|
|
3824
3906
|
UI_OPTIONS_KEY,
|
|
@@ -3844,6 +3926,7 @@ export {
|
|
|
3844
3926
|
enumOptionsValueForIndex,
|
|
3845
3927
|
errorId,
|
|
3846
3928
|
examplesId,
|
|
3929
|
+
expandUiSchemaDefinitions,
|
|
3847
3930
|
findFieldInSchema,
|
|
3848
3931
|
findSchemaDefinition,
|
|
3849
3932
|
findSelectedOptionInXxxOf,
|
|
@@ -3895,6 +3978,7 @@ export {
|
|
|
3895
3978
|
parseDateString,
|
|
3896
3979
|
rangeSpec,
|
|
3897
3980
|
replaceStringParameters,
|
|
3981
|
+
resolveUiSchema,
|
|
3898
3982
|
retrieveSchema,
|
|
3899
3983
|
sanitizeDataForNewSchema,
|
|
3900
3984
|
schemaParser,
|