@rjsf/utils 6.3.0 → 6.4.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 CHANGED
@@ -61,6 +61,7 @@ __export(index_exports, {
61
61
  REF_KEY: () => REF_KEY,
62
62
  REQUIRED_KEY: () => REQUIRED_KEY,
63
63
  RJSF_ADDITIONAL_PROPERTIES_FLAG: () => RJSF_ADDITIONAL_PROPERTIES_FLAG,
64
+ RJSF_REF_KEY: () => RJSF_REF_KEY,
64
65
  ROOT_SCHEMA_PREFIX: () => ROOT_SCHEMA_PREFIX,
65
66
  SCHEMA_KEY: () => SCHEMA_KEY,
66
67
  SUBMIT_BTN_OPTIONS_KEY: () => SUBMIT_BTN_OPTIONS_KEY,
@@ -236,6 +237,7 @@ var READONLY_KEY = "readonly";
236
237
  var REQUIRED_KEY = "required";
237
238
  var SUBMIT_BTN_OPTIONS_KEY = "submitButtonOptions";
238
239
  var REF_KEY = "$ref";
240
+ var RJSF_REF_KEY = "__rjsf_ref";
239
241
  var SCHEMA_KEY = "$schema";
240
242
  var DEFAULT_ID_PREFIX = "root";
241
243
  var DEFAULT_ID_SEPARATOR = "_";
@@ -790,7 +792,7 @@ function resolveAllReferences(schema, rootSchema, recurseList, baseURI, resolveA
790
792
  }
791
793
  recurseList.push($ref);
792
794
  const refSchema = findSchemaDefinition($ref, rootSchema, baseURI);
793
- resolvedSchema = { ...refSchema, ...localSchema };
795
+ resolvedSchema = { ...refSchema, ...localSchema, [RJSF_REF_KEY]: $ref };
794
796
  if (ID_KEY in resolvedSchema) {
795
797
  baseURI = resolvedSchema[ID_KEY];
796
798
  }
@@ -1571,17 +1573,35 @@ function toConstant(schema) {
1571
1573
  }
1572
1574
 
1573
1575
  // src/optionsList.ts
1576
+ function applyEnumOrder(options, order) {
1577
+ const optionsByValue = new Map(options.map((opt) => [String(opt.value), opt]));
1578
+ const orderedKeys = new Set(order.filter((v) => v !== "*").map(String));
1579
+ const rest = options.filter((opt) => !orderedKeys.has(String(opt.value)));
1580
+ return order.flatMap((entry) => {
1581
+ if (entry === "*") {
1582
+ return rest;
1583
+ }
1584
+ const opt = optionsByValue.get(String(entry));
1585
+ return opt ? [opt] : [];
1586
+ });
1587
+ }
1574
1588
  function optionsList(schema, uiSchema) {
1575
1589
  if (schema.enum) {
1576
1590
  let enumNames;
1591
+ let enumOrder;
1577
1592
  if (uiSchema) {
1578
- const { enumNames: uiEnumNames } = getUiOptions(uiSchema);
1593
+ const { enumNames: uiEnumNames, enumOrder: uiEnumOrder } = getUiOptions(uiSchema);
1579
1594
  enumNames = uiEnumNames;
1595
+ enumOrder = uiEnumOrder;
1580
1596
  }
1581
- return schema.enum.map((value, i) => {
1582
- const label = enumNames?.[i] || String(value);
1597
+ let options = schema.enum.map((value, i) => {
1598
+ const label = Array.isArray(enumNames) ? enumNames[i] || String(value) : enumNames?.[String(value)] || String(value);
1583
1599
  return { label, value };
1584
1600
  });
1601
+ if (enumOrder) {
1602
+ options = applyEnumOrder(options, enumOrder);
1603
+ }
1604
+ return options;
1585
1605
  }
1586
1606
  let altSchemas = void 0;
1587
1607
  let altUiSchemas = void 0;
@@ -2120,6 +2140,7 @@ var import_get15 = __toESM(require("lodash/get"), 1);
2120
2140
 
2121
2141
  // src/schema/toPathSchema.ts
2122
2142
  var import_get14 = __toESM(require("lodash/get"), 1);
2143
+ var import_isObject11 = __toESM(require("lodash/isObject"), 1);
2123
2144
  var import_set2 = __toESM(require("lodash/set"), 1);
2124
2145
  function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
2125
2146
  if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema || IF_KEY in schema) {
@@ -2168,6 +2189,21 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
2168
2189
  }
2169
2190
  if (ADDITIONAL_PROPERTIES_KEY in schema && schema[ADDITIONAL_PROPERTIES_KEY] !== false) {
2170
2191
  (0, import_set2.default)(pathSchema, RJSF_ADDITIONAL_PROPERTIES_FLAG, true);
2192
+ const additionalSchema = (0, import_isObject11.default)(schema[ADDITIONAL_PROPERTIES_KEY]) ? schema[ADDITIONAL_PROPERTIES_KEY] : {};
2193
+ const definedProperties = (0, import_get14.default)(schema, PROPERTIES_KEY, {});
2194
+ for (const key of Object.keys(formData ?? {})) {
2195
+ if (!(key in definedProperties)) {
2196
+ pathSchema[key] = toPathSchemaInternal(
2197
+ validator,
2198
+ additionalSchema,
2199
+ `${name}.${key}`,
2200
+ rootSchema,
2201
+ (0, import_get14.default)(formData, [key]),
2202
+ _recurseList,
2203
+ experimental_customMergeAllOf
2204
+ );
2205
+ }
2206
+ }
2171
2207
  }
2172
2208
  if (ITEMS_KEY in schema && Array.isArray(formData)) {
2173
2209
  const { items: schemaItems, additionalItems: schemaAdditionalItems } = schema;
@@ -3264,13 +3300,14 @@ function optionalControlsId(id, element) {
3264
3300
  // src/isFormDataAvailable.ts
3265
3301
  var import_isNil3 = __toESM(require("lodash/isNil"), 1);
3266
3302
  var import_isEmpty6 = __toESM(require("lodash/isEmpty"), 1);
3267
- var import_isObject11 = __toESM(require("lodash/isObject"), 1);
3303
+ var import_isObject12 = __toESM(require("lodash/isObject"), 1);
3268
3304
  function isFormDataAvailable(formData) {
3269
- return !(0, import_isNil3.default)(formData) && (!(0, import_isObject11.default)(formData) || Array.isArray(formData) || !(0, import_isEmpty6.default)(formData));
3305
+ return !(0, import_isNil3.default)(formData) && (!(0, import_isObject12.default)(formData) || Array.isArray(formData) || !(0, import_isEmpty6.default)(formData));
3270
3306
  }
3271
3307
 
3272
3308
  // src/isRootSchema.ts
3273
3309
  var import_isEqual2 = __toESM(require("lodash/isEqual"), 1);
3310
+ var import_omit2 = __toESM(require("lodash/omit"), 1);
3274
3311
  function isRootSchema(registry, schemaToCompare) {
3275
3312
  const { rootSchema, schemaUtils } = registry;
3276
3313
  if ((0, import_isEqual2.default)(schemaToCompare, rootSchema)) {
@@ -3278,7 +3315,7 @@ function isRootSchema(registry, schemaToCompare) {
3278
3315
  }
3279
3316
  if (REF_KEY in rootSchema) {
3280
3317
  const resolvedSchema = schemaUtils.retrieveSchema(rootSchema);
3281
- return (0, import_isEqual2.default)(schemaToCompare, resolvedSchema);
3318
+ return (0, import_isEqual2.default)(schemaToCompare, (0, import_omit2.default)(resolvedSchema, RJSF_REF_KEY));
3282
3319
  }
3283
3320
  return false;
3284
3321
  }
@@ -3429,7 +3466,7 @@ function expandUiSchemaDefinitions(currentSchema, uiSchema, registry, visited =
3429
3466
  return result;
3430
3467
  }
3431
3468
  function resolveUiSchema(schema, localUiSchema, registry) {
3432
- const ref = schema[REF_KEY];
3469
+ const ref = schema[RJSF_REF_KEY] ?? schema[REF_KEY];
3433
3470
  const definitionUiSchema = ref ? registry.uiSchemaDefinitions?.[ref] : void 0;
3434
3471
  if (!definitionUiSchema) {
3435
3472
  return localUiSchema || {};
@@ -3475,11 +3512,11 @@ function shouldRender(component, nextProps, nextState, updateStrategy = "customD
3475
3512
  }
3476
3513
 
3477
3514
  // src/shouldRenderOptionalField.ts
3478
- var import_isObject13 = __toESM(require("lodash/isObject"), 1);
3515
+ var import_isObject14 = __toESM(require("lodash/isObject"), 1);
3479
3516
  var import_uniq2 = __toESM(require("lodash/uniq"), 1);
3480
3517
  function getSchemaTypesForXxxOf(schemas) {
3481
3518
  const allTypes = (0, import_uniq2.default)(
3482
- schemas.map((s) => (0, import_isObject13.default)(s) ? getSchemaType(s) : void 0).flat().filter((t) => t !== void 0)
3519
+ schemas.map((s) => (0, import_isObject14.default)(s) ? getSchemaType(s) : void 0).flat().filter((t) => t !== void 0)
3483
3520
  );
3484
3521
  return allTypes.length === 1 ? allTypes[0] : allTypes;
3485
3522
  }
@@ -3825,7 +3862,7 @@ function validationDataMerge(validationData, additionalErrorSchema, preventDupli
3825
3862
  }
3826
3863
 
3827
3864
  // src/withIdRefPrefix.ts
3828
- var import_isObject14 = __toESM(require("lodash/isObject"), 1);
3865
+ var import_isObject15 = __toESM(require("lodash/isObject"), 1);
3829
3866
  function withIdRefPrefixObject(node) {
3830
3867
  for (const key in node) {
3831
3868
  const realObj = node;
@@ -3848,7 +3885,7 @@ function withIdRefPrefix(schemaNode) {
3848
3885
  if (Array.isArray(schemaNode)) {
3849
3886
  return withIdRefPrefixArray([...schemaNode]);
3850
3887
  }
3851
- if ((0, import_isObject14.default)(schemaNode)) {
3888
+ if ((0, import_isObject15.default)(schemaNode)) {
3852
3889
  return withIdRefPrefixObject({ ...schemaNode });
3853
3890
  }
3854
3891
  return schemaNode;