@rjsf/utils 6.3.1 → 6.4.1

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
@@ -65,6 +65,7 @@ var READONLY_KEY = "readonly";
65
65
  var REQUIRED_KEY = "required";
66
66
  var SUBMIT_BTN_OPTIONS_KEY = "submitButtonOptions";
67
67
  var REF_KEY = "$ref";
68
+ var RJSF_REF_KEY = "__rjsf_ref";
68
69
  var SCHEMA_KEY = "$schema";
69
70
  var DEFAULT_ID_PREFIX = "root";
70
71
  var DEFAULT_ID_SEPARATOR = "_";
@@ -619,7 +620,7 @@ function resolveAllReferences(schema, rootSchema, recurseList, baseURI, resolveA
619
620
  }
620
621
  recurseList.push($ref);
621
622
  const refSchema = findSchemaDefinition($ref, rootSchema, baseURI);
622
- resolvedSchema = { ...refSchema, ...localSchema };
623
+ resolvedSchema = { ...refSchema, ...localSchema, [RJSF_REF_KEY]: $ref };
623
624
  if (ID_KEY in resolvedSchema) {
624
625
  baseURI = resolvedSchema[ID_KEY];
625
626
  }
@@ -1400,17 +1401,35 @@ function toConstant(schema) {
1400
1401
  }
1401
1402
 
1402
1403
  // src/optionsList.ts
1404
+ function applyEnumOrder(options, order) {
1405
+ const optionsByValue = new Map(options.map((opt) => [String(opt.value), opt]));
1406
+ const orderedKeys = new Set(order.filter((v) => v !== "*").map(String));
1407
+ const rest = options.filter((opt) => !orderedKeys.has(String(opt.value)));
1408
+ return order.flatMap((entry) => {
1409
+ if (entry === "*") {
1410
+ return rest;
1411
+ }
1412
+ const opt = optionsByValue.get(String(entry));
1413
+ return opt ? [opt] : [];
1414
+ });
1415
+ }
1403
1416
  function optionsList(schema, uiSchema) {
1404
1417
  if (schema.enum) {
1405
1418
  let enumNames;
1419
+ let enumOrder;
1406
1420
  if (uiSchema) {
1407
- const { enumNames: uiEnumNames } = getUiOptions(uiSchema);
1421
+ const { enumNames: uiEnumNames, enumOrder: uiEnumOrder } = getUiOptions(uiSchema);
1408
1422
  enumNames = uiEnumNames;
1423
+ enumOrder = uiEnumOrder;
1409
1424
  }
1410
- return schema.enum.map((value, i) => {
1411
- const label = enumNames?.[i] || String(value);
1425
+ let options = schema.enum.map((value, i) => {
1426
+ const label = Array.isArray(enumNames) ? enumNames[i] || String(value) : enumNames?.[String(value)] || String(value);
1412
1427
  return { label, value };
1413
1428
  });
1429
+ if (enumOrder) {
1430
+ options = applyEnumOrder(options, enumOrder);
1431
+ }
1432
+ return options;
1414
1433
  }
1415
1434
  let altSchemas = void 0;
1416
1435
  let altUiSchemas = void 0;
@@ -1949,6 +1968,7 @@ import get15 from "lodash/get";
1949
1968
 
1950
1969
  // src/schema/toPathSchema.ts
1951
1970
  import get14 from "lodash/get";
1971
+ import isObject4 from "lodash/isObject";
1952
1972
  import set2 from "lodash/set";
1953
1973
  function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
1954
1974
  if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema || IF_KEY in schema) {
@@ -1997,6 +2017,21 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
1997
2017
  }
1998
2018
  if (ADDITIONAL_PROPERTIES_KEY in schema && schema[ADDITIONAL_PROPERTIES_KEY] !== false) {
1999
2019
  set2(pathSchema, RJSF_ADDITIONAL_PROPERTIES_FLAG, true);
2020
+ const additionalSchema = isObject4(schema[ADDITIONAL_PROPERTIES_KEY]) ? schema[ADDITIONAL_PROPERTIES_KEY] : {};
2021
+ const definedProperties = get14(schema, PROPERTIES_KEY, {});
2022
+ for (const key of Object.keys(formData ?? {})) {
2023
+ if (!(key in definedProperties)) {
2024
+ pathSchema[key] = toPathSchemaInternal(
2025
+ validator,
2026
+ additionalSchema,
2027
+ `${name}.${key}`,
2028
+ rootSchema,
2029
+ get14(formData, [key]),
2030
+ _recurseList,
2031
+ experimental_customMergeAllOf
2032
+ );
2033
+ }
2034
+ }
2000
2035
  }
2001
2036
  if (ITEMS_KEY in schema && Array.isArray(formData)) {
2002
2037
  const { items: schemaItems, additionalItems: schemaAdditionalItems } = schema;
@@ -3093,13 +3128,14 @@ function optionalControlsId(id, element) {
3093
3128
  // src/isFormDataAvailable.ts
3094
3129
  import isNil3 from "lodash/isNil";
3095
3130
  import isEmpty6 from "lodash/isEmpty";
3096
- import isObject4 from "lodash/isObject";
3131
+ import isObject5 from "lodash/isObject";
3097
3132
  function isFormDataAvailable(formData) {
3098
- return !isNil3(formData) && (!isObject4(formData) || Array.isArray(formData) || !isEmpty6(formData));
3133
+ return !isNil3(formData) && (!isObject5(formData) || Array.isArray(formData) || !isEmpty6(formData));
3099
3134
  }
3100
3135
 
3101
3136
  // src/isRootSchema.ts
3102
3137
  import isEqual2 from "lodash/isEqual";
3138
+ import omit2 from "lodash/omit";
3103
3139
  function isRootSchema(registry, schemaToCompare) {
3104
3140
  const { rootSchema, schemaUtils } = registry;
3105
3141
  if (isEqual2(schemaToCompare, rootSchema)) {
@@ -3107,7 +3143,7 @@ function isRootSchema(registry, schemaToCompare) {
3107
3143
  }
3108
3144
  if (REF_KEY in rootSchema) {
3109
3145
  const resolvedSchema = schemaUtils.retrieveSchema(rootSchema);
3110
- return isEqual2(schemaToCompare, resolvedSchema);
3146
+ return isEqual2(schemaToCompare, omit2(resolvedSchema, RJSF_REF_KEY));
3111
3147
  }
3112
3148
  return false;
3113
3149
  }
@@ -3258,7 +3294,7 @@ function expandUiSchemaDefinitions(currentSchema, uiSchema, registry, visited =
3258
3294
  return result;
3259
3295
  }
3260
3296
  function resolveUiSchema(schema, localUiSchema, registry) {
3261
- const ref = schema[REF_KEY];
3297
+ const ref = schema[RJSF_REF_KEY] ?? schema[REF_KEY];
3262
3298
  const definitionUiSchema = ref ? registry.uiSchemaDefinitions?.[ref] : void 0;
3263
3299
  if (!definitionUiSchema) {
3264
3300
  return localUiSchema || {};
@@ -3304,11 +3340,11 @@ function shouldRender(component, nextProps, nextState, updateStrategy = "customD
3304
3340
  }
3305
3341
 
3306
3342
  // src/shouldRenderOptionalField.ts
3307
- import isObject5 from "lodash/isObject";
3343
+ import isObject6 from "lodash/isObject";
3308
3344
  import uniq2 from "lodash/uniq";
3309
3345
  function getSchemaTypesForXxxOf(schemas) {
3310
3346
  const allTypes = uniq2(
3311
- schemas.map((s) => isObject5(s) ? getSchemaType(s) : void 0).flat().filter((t) => t !== void 0)
3347
+ schemas.map((s) => isObject6(s) ? getSchemaType(s) : void 0).flat().filter((t) => t !== void 0)
3312
3348
  );
3313
3349
  return allTypes.length === 1 ? allTypes[0] : allTypes;
3314
3350
  }
@@ -3654,7 +3690,7 @@ function validationDataMerge(validationData, additionalErrorSchema, preventDupli
3654
3690
  }
3655
3691
 
3656
3692
  // src/withIdRefPrefix.ts
3657
- import isObject6 from "lodash/isObject";
3693
+ import isObject7 from "lodash/isObject";
3658
3694
  function withIdRefPrefixObject(node) {
3659
3695
  for (const key in node) {
3660
3696
  const realObj = node;
@@ -3677,7 +3713,7 @@ function withIdRefPrefix(schemaNode) {
3677
3713
  if (Array.isArray(schemaNode)) {
3678
3714
  return withIdRefPrefixArray([...schemaNode]);
3679
3715
  }
3680
- if (isObject6(schemaNode)) {
3716
+ if (isObject7(schemaNode)) {
3681
3717
  return withIdRefPrefixObject({ ...schemaNode });
3682
3718
  }
3683
3719
  return schemaNode;
@@ -3896,6 +3932,7 @@ export {
3896
3932
  REF_KEY,
3897
3933
  REQUIRED_KEY,
3898
3934
  RJSF_ADDITIONAL_PROPERTIES_FLAG,
3935
+ RJSF_REF_KEY,
3899
3936
  ROOT_SCHEMA_PREFIX,
3900
3937
  SCHEMA_KEY,
3901
3938
  SUBMIT_BTN_OPTIONS_KEY,