@rjsf/utils 5.19.4 → 5.20.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/utils.esm.js CHANGED
@@ -2241,22 +2241,41 @@ function toConstant(schema) {
2241
2241
  }
2242
2242
 
2243
2243
  // src/optionsList.ts
2244
- function optionsList(schema) {
2244
+ function optionsList(schema, uiSchema) {
2245
2245
  const schemaWithEnumNames = schema;
2246
- if (schemaWithEnumNames.enumNames && true) {
2247
- console.warn("The enumNames property is deprecated and may be removed in a future major release.");
2248
- }
2249
2246
  if (schema.enum) {
2247
+ let enumNames;
2248
+ if (uiSchema) {
2249
+ const { enumNames: uiEnumNames } = getUiOptions(uiSchema);
2250
+ enumNames = uiEnumNames;
2251
+ }
2252
+ if (!enumNames && schemaWithEnumNames.enumNames) {
2253
+ if (true) {
2254
+ console.warn(
2255
+ 'The "enumNames" property in the schema is deprecated and will be removed in a future major release. Use the "ui:enumNames" property in the uiSchema instead.'
2256
+ );
2257
+ }
2258
+ enumNames = schemaWithEnumNames.enumNames;
2259
+ }
2250
2260
  return schema.enum.map((value, i) => {
2251
- const label = schemaWithEnumNames.enumNames && schemaWithEnumNames.enumNames[i] || String(value);
2261
+ const label = enumNames?.[i] || String(value);
2252
2262
  return { label, value };
2253
2263
  });
2254
2264
  }
2255
- const altSchemas = schema.oneOf || schema.anyOf;
2256
- return altSchemas && altSchemas.map((aSchemaDef) => {
2265
+ let altSchemas = void 0;
2266
+ let altUiSchemas = void 0;
2267
+ if (schema.anyOf) {
2268
+ altSchemas = schema.anyOf;
2269
+ altUiSchemas = uiSchema?.anyOf;
2270
+ } else if (schema.oneOf) {
2271
+ altSchemas = schema.oneOf;
2272
+ altUiSchemas = uiSchema?.oneOf;
2273
+ }
2274
+ return altSchemas && altSchemas.map((aSchemaDef, index) => {
2275
+ const { title } = getUiOptions(altUiSchemas?.[index]);
2257
2276
  const aSchema = aSchemaDef;
2258
2277
  const value = toConstant(aSchema);
2259
- const label = aSchema.title || String(value);
2278
+ const label = title || aSchema.title || String(value);
2260
2279
  return {
2261
2280
  schema: aSchema,
2262
2281
  label,