@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/index.cjs
CHANGED
|
@@ -65,6 +65,7 @@ __export(index_exports, {
|
|
|
65
65
|
SCHEMA_KEY: () => SCHEMA_KEY,
|
|
66
66
|
SUBMIT_BTN_OPTIONS_KEY: () => SUBMIT_BTN_OPTIONS_KEY,
|
|
67
67
|
TranslatableString: () => TranslatableString,
|
|
68
|
+
UI_DEFINITIONS_KEY: () => UI_DEFINITIONS_KEY,
|
|
68
69
|
UI_FIELD_KEY: () => UI_FIELD_KEY,
|
|
69
70
|
UI_GLOBAL_OPTIONS_KEY: () => UI_GLOBAL_OPTIONS_KEY,
|
|
70
71
|
UI_OPTIONS_KEY: () => UI_OPTIONS_KEY,
|
|
@@ -90,6 +91,7 @@ __export(index_exports, {
|
|
|
90
91
|
enumOptionsValueForIndex: () => enumOptionsValueForIndex,
|
|
91
92
|
errorId: () => errorId,
|
|
92
93
|
examplesId: () => examplesId,
|
|
94
|
+
expandUiSchemaDefinitions: () => expandUiSchemaDefinitions,
|
|
93
95
|
findFieldInSchema: () => findFieldInSchema,
|
|
94
96
|
findSchemaDefinition: () => findSchemaDefinition,
|
|
95
97
|
findSelectedOptionInXxxOf: () => findSelectedOptionInXxxOf,
|
|
@@ -141,6 +143,7 @@ __export(index_exports, {
|
|
|
141
143
|
parseDateString: () => parseDateString,
|
|
142
144
|
rangeSpec: () => rangeSpec,
|
|
143
145
|
replaceStringParameters: () => replaceStringParameters,
|
|
146
|
+
resolveUiSchema: () => resolveUiSchema,
|
|
144
147
|
retrieveSchema: () => retrieveSchema,
|
|
145
148
|
sanitizeDataForNewSchema: () => sanitizeDataForNewSchema,
|
|
146
149
|
schemaParser: () => schemaParser,
|
|
@@ -245,6 +248,7 @@ var UI_FIELD_KEY = "ui:field";
|
|
|
245
248
|
var UI_WIDGET_KEY = "ui:widget";
|
|
246
249
|
var UI_OPTIONS_KEY = "ui:options";
|
|
247
250
|
var UI_GLOBAL_OPTIONS_KEY = "ui:globalOptions";
|
|
251
|
+
var UI_DEFINITIONS_KEY = "ui:definitions";
|
|
248
252
|
var JSON_SCHEMA_DRAFT_2019_09 = "https://json-schema.org/draft/2019-09/schema";
|
|
249
253
|
var JSON_SCHEMA_DRAFT_2020_12 = "https://json-schema.org/draft/2020-12/schema";
|
|
250
254
|
|
|
@@ -3356,6 +3360,86 @@ function parseDateString(dateString, includeTime = true) {
|
|
|
3356
3360
|
};
|
|
3357
3361
|
}
|
|
3358
3362
|
|
|
3363
|
+
// src/resolveUiSchema.ts
|
|
3364
|
+
var SAME_KEY_KEYWORDS = [ITEMS_KEY, ADDITIONAL_PROPERTIES_KEY];
|
|
3365
|
+
var ARRAY_KEYWORDS = [ONE_OF_KEY, ANY_OF_KEY, ALL_OF_KEY];
|
|
3366
|
+
function expandUiSchemaDefinitions(currentSchema, uiSchema, registry, visited = /* @__PURE__ */ new Set()) {
|
|
3367
|
+
const { rootSchema, uiSchemaDefinitions: definitions } = registry;
|
|
3368
|
+
let result = { ...uiSchema };
|
|
3369
|
+
let resolvedSchema = currentSchema;
|
|
3370
|
+
const ref = currentSchema[REF_KEY];
|
|
3371
|
+
const isRecursive = ref && visited.has(ref);
|
|
3372
|
+
if (ref) {
|
|
3373
|
+
visited.add(ref);
|
|
3374
|
+
if (definitions && ref in definitions) {
|
|
3375
|
+
result = mergeObjects(definitions[ref], result);
|
|
3376
|
+
}
|
|
3377
|
+
if (isRecursive) {
|
|
3378
|
+
return result;
|
|
3379
|
+
}
|
|
3380
|
+
try {
|
|
3381
|
+
resolvedSchema = findSchemaDefinition(ref, rootSchema);
|
|
3382
|
+
} catch {
|
|
3383
|
+
resolvedSchema = currentSchema;
|
|
3384
|
+
}
|
|
3385
|
+
}
|
|
3386
|
+
const properties = resolvedSchema[PROPERTIES_KEY];
|
|
3387
|
+
if (properties && isObject(properties)) {
|
|
3388
|
+
for (const [propName, propSchema] of Object.entries(properties)) {
|
|
3389
|
+
const propUiSchema = result[propName] || {};
|
|
3390
|
+
const expanded = expandUiSchemaDefinitions(propSchema, propUiSchema, registry, new Set(visited));
|
|
3391
|
+
if (Object.keys(expanded).length > 0) {
|
|
3392
|
+
result[propName] = expanded;
|
|
3393
|
+
}
|
|
3394
|
+
}
|
|
3395
|
+
}
|
|
3396
|
+
for (const keyword of SAME_KEY_KEYWORDS) {
|
|
3397
|
+
const subSchema = resolvedSchema[keyword];
|
|
3398
|
+
if (subSchema && isObject(subSchema) && !Array.isArray(subSchema)) {
|
|
3399
|
+
const currentUiSchema = result[keyword];
|
|
3400
|
+
if (typeof currentUiSchema !== "function") {
|
|
3401
|
+
const subUiSchema = currentUiSchema || {};
|
|
3402
|
+
const expanded = expandUiSchemaDefinitions(subSchema, subUiSchema, registry, new Set(visited));
|
|
3403
|
+
if (Object.keys(expanded).length > 0) {
|
|
3404
|
+
result[keyword] = expanded;
|
|
3405
|
+
}
|
|
3406
|
+
}
|
|
3407
|
+
}
|
|
3408
|
+
}
|
|
3409
|
+
for (const keyword of ARRAY_KEYWORDS) {
|
|
3410
|
+
const schemaOptions = resolvedSchema[keyword];
|
|
3411
|
+
if (Array.isArray(schemaOptions) && schemaOptions.length > 0) {
|
|
3412
|
+
const currentUiSchemaArray = result[keyword];
|
|
3413
|
+
const uiSchemaArray = Array.isArray(currentUiSchemaArray) ? [...currentUiSchemaArray] : [];
|
|
3414
|
+
let hasExpanded = false;
|
|
3415
|
+
for (let i = 0; i < schemaOptions.length; i++) {
|
|
3416
|
+
const optionSchema = schemaOptions[i];
|
|
3417
|
+
const optionUiSchema = uiSchemaArray[i] || {};
|
|
3418
|
+
const expanded = expandUiSchemaDefinitions(optionSchema, optionUiSchema, registry, new Set(visited));
|
|
3419
|
+
if (Object.keys(expanded).length > 0) {
|
|
3420
|
+
uiSchemaArray[i] = expanded;
|
|
3421
|
+
hasExpanded = true;
|
|
3422
|
+
}
|
|
3423
|
+
}
|
|
3424
|
+
if (hasExpanded) {
|
|
3425
|
+
result[keyword] = uiSchemaArray;
|
|
3426
|
+
}
|
|
3427
|
+
}
|
|
3428
|
+
}
|
|
3429
|
+
return result;
|
|
3430
|
+
}
|
|
3431
|
+
function resolveUiSchema(schema, localUiSchema, registry) {
|
|
3432
|
+
const ref = schema[REF_KEY];
|
|
3433
|
+
const definitionUiSchema = ref ? registry.uiSchemaDefinitions?.[ref] : void 0;
|
|
3434
|
+
if (!definitionUiSchema) {
|
|
3435
|
+
return localUiSchema || {};
|
|
3436
|
+
}
|
|
3437
|
+
if (!localUiSchema || Object.keys(localUiSchema).length === 0) {
|
|
3438
|
+
return { ...definitionUiSchema };
|
|
3439
|
+
}
|
|
3440
|
+
return mergeObjects(definitionUiSchema, localUiSchema);
|
|
3441
|
+
}
|
|
3442
|
+
|
|
3359
3443
|
// src/schemaRequiresTrueValue.ts
|
|
3360
3444
|
function schemaRequiresTrueValue(schema) {
|
|
3361
3445
|
if (schema.const) {
|
|
@@ -3391,11 +3475,11 @@ function shouldRender(component, nextProps, nextState, updateStrategy = "customD
|
|
|
3391
3475
|
}
|
|
3392
3476
|
|
|
3393
3477
|
// src/shouldRenderOptionalField.ts
|
|
3394
|
-
var
|
|
3478
|
+
var import_isObject13 = __toESM(require("lodash/isObject"), 1);
|
|
3395
3479
|
var import_uniq2 = __toESM(require("lodash/uniq"), 1);
|
|
3396
3480
|
function getSchemaTypesForXxxOf(schemas) {
|
|
3397
3481
|
const allTypes = (0, import_uniq2.default)(
|
|
3398
|
-
schemas.map((s) => (0,
|
|
3482
|
+
schemas.map((s) => (0, import_isObject13.default)(s) ? getSchemaType(s) : void 0).flat().filter((t) => t !== void 0)
|
|
3399
3483
|
);
|
|
3400
3484
|
return allTypes.length === 1 ? allTypes[0] : allTypes;
|
|
3401
3485
|
}
|
|
@@ -3741,7 +3825,7 @@ function validationDataMerge(validationData, additionalErrorSchema, preventDupli
|
|
|
3741
3825
|
}
|
|
3742
3826
|
|
|
3743
3827
|
// src/withIdRefPrefix.ts
|
|
3744
|
-
var
|
|
3828
|
+
var import_isObject14 = __toESM(require("lodash/isObject"), 1);
|
|
3745
3829
|
function withIdRefPrefixObject(node) {
|
|
3746
3830
|
for (const key in node) {
|
|
3747
3831
|
const realObj = node;
|
|
@@ -3764,7 +3848,7 @@ function withIdRefPrefix(schemaNode) {
|
|
|
3764
3848
|
if (Array.isArray(schemaNode)) {
|
|
3765
3849
|
return withIdRefPrefixArray([...schemaNode]);
|
|
3766
3850
|
}
|
|
3767
|
-
if ((0,
|
|
3851
|
+
if ((0, import_isObject14.default)(schemaNode)) {
|
|
3768
3852
|
return withIdRefPrefixObject({ ...schemaNode });
|
|
3769
3853
|
}
|
|
3770
3854
|
return schemaNode;
|