@rjsf/utils 5.19.3 → 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/index.js CHANGED
@@ -2378,22 +2378,41 @@ function toConstant(schema) {
2378
2378
  }
2379
2379
 
2380
2380
  // src/optionsList.ts
2381
- function optionsList(schema) {
2381
+ function optionsList(schema, uiSchema) {
2382
2382
  const schemaWithEnumNames = schema;
2383
- if (schemaWithEnumNames.enumNames && true) {
2384
- console.warn("The enumNames property is deprecated and may be removed in a future major release.");
2385
- }
2386
2383
  if (schema.enum) {
2384
+ let enumNames;
2385
+ if (uiSchema) {
2386
+ const { enumNames: uiEnumNames } = getUiOptions(uiSchema);
2387
+ enumNames = uiEnumNames;
2388
+ }
2389
+ if (!enumNames && schemaWithEnumNames.enumNames) {
2390
+ if (true) {
2391
+ console.warn(
2392
+ '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.'
2393
+ );
2394
+ }
2395
+ enumNames = schemaWithEnumNames.enumNames;
2396
+ }
2387
2397
  return schema.enum.map((value, i) => {
2388
- const label = schemaWithEnumNames.enumNames && schemaWithEnumNames.enumNames[i] || String(value);
2398
+ const label = enumNames?.[i] || String(value);
2389
2399
  return { label, value };
2390
2400
  });
2391
2401
  }
2392
- const altSchemas = schema.oneOf || schema.anyOf;
2393
- return altSchemas && altSchemas.map((aSchemaDef) => {
2402
+ let altSchemas = void 0;
2403
+ let altUiSchemas = void 0;
2404
+ if (schema.anyOf) {
2405
+ altSchemas = schema.anyOf;
2406
+ altUiSchemas = uiSchema?.anyOf;
2407
+ } else if (schema.oneOf) {
2408
+ altSchemas = schema.oneOf;
2409
+ altUiSchemas = uiSchema?.oneOf;
2410
+ }
2411
+ return altSchemas && altSchemas.map((aSchemaDef, index) => {
2412
+ const { title } = getUiOptions(altUiSchemas?.[index]);
2394
2413
  const aSchema = aSchemaDef;
2395
2414
  const value = toConstant(aSchema);
2396
- const label = aSchema.title || String(value);
2415
+ const label = title || aSchema.title || String(value);
2397
2416
  return {
2398
2417
  schema: aSchema,
2399
2418
  label,
@@ -2648,11 +2667,11 @@ var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
2648
2667
  TranslatableString2["OptionPrefix"] = "Option %1";
2649
2668
  TranslatableString2["TitleOptionPrefix"] = "%1 option %2";
2650
2669
  TranslatableString2["KeyLabel"] = "%1 Key";
2651
- TranslatableString2["InvalidObjectField"] = 'Invalid "%1" object field configuration: <em>%2</em>.';
2670
+ TranslatableString2["InvalidObjectField"] = 'Invalid "%1" object field configuration: _%2_.';
2652
2671
  TranslatableString2["UnsupportedField"] = "Unsupported field schema.";
2653
- TranslatableString2["UnsupportedFieldWithId"] = "Unsupported field schema for field <code>%1</code>.";
2654
- TranslatableString2["UnsupportedFieldWithReason"] = "Unsupported field schema: <em>%1</em>.";
2655
- TranslatableString2["UnsupportedFieldWithIdAndReason"] = "Unsupported field schema for field <code>%1</code>: <em>%2</em>.";
2672
+ TranslatableString2["UnsupportedFieldWithId"] = "Unsupported field schema for field `%1`.";
2673
+ TranslatableString2["UnsupportedFieldWithReason"] = "Unsupported field schema: _%1_.";
2674
+ TranslatableString2["UnsupportedFieldWithIdAndReason"] = "Unsupported field schema for field `%1`: _%2_.";
2656
2675
  TranslatableString2["FilesInfo"] = "**%1** (%2, %3 bytes)";
2657
2676
  return TranslatableString2;
2658
2677
  })(TranslatableString || {});
@@ -2676,6 +2695,11 @@ var ParserValidator = class {
2676
2695
  this.rootSchema = rootSchema;
2677
2696
  this.addSchema(rootSchema, hashForSchema(rootSchema));
2678
2697
  }
2698
+ /** Resets the internal AJV validator to clear schemas from it. Can be helpful for resetting the validator for tests.
2699
+ */
2700
+ reset() {
2701
+ this.schemaMap = {};
2702
+ }
2679
2703
  /** Adds the given `schema` to the `schemaMap` keyed by the `hash` or `ID_KEY` if present on the `schema`. If the
2680
2704
  * schema does not have an `ID_KEY`, then the `hash` will be added as the `ID_KEY` to allow the schema to be
2681
2705
  * associated with it's `hash` for future use (by a schema compiler).