@rjsf/utils 6.0.0-beta.19 → 6.0.0-beta.20

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
@@ -66,6 +66,8 @@ var REQUIRED_KEY = "required";
66
66
  var SUBMIT_BTN_OPTIONS_KEY = "submitButtonOptions";
67
67
  var REF_KEY = "$ref";
68
68
  var SCHEMA_KEY = "$schema";
69
+ var DEFAULT_ID_PREFIX = "root";
70
+ var DEFAULT_ID_SEPARATOR = "_";
69
71
  var DISCRIMINATOR_PATH = ["discriminator", "propertyName"];
70
72
  var FORM_CONTEXT_NAME = "formContext";
71
73
  var LOOKUP_MAP_NAME = "layoutGridLookupMap";
@@ -2022,80 +2024,8 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
2022
2024
  return newFormData;
2023
2025
  }
2024
2026
 
2025
- // src/schema/toIdSchema.ts
2026
- import get14 from "lodash/get";
2027
- function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
2028
- const $id = id || idPrefix;
2029
- const idSchema = { $id };
2030
- if (typeof schema === "object") {
2031
- if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
2032
- const _schema = retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf);
2033
- const sameSchemaIndex = _recurseList.findIndex((item) => deepEquals(item, _schema));
2034
- if (sameSchemaIndex === -1) {
2035
- return toIdSchemaInternal(
2036
- validator,
2037
- _schema,
2038
- idPrefix,
2039
- idSeparator,
2040
- id,
2041
- rootSchema,
2042
- formData,
2043
- _recurseList.concat(_schema),
2044
- experimental_customMergeAllOf
2045
- );
2046
- }
2047
- }
2048
- if (ITEMS_KEY in schema && !get14(schema, [ITEMS_KEY, REF_KEY])) {
2049
- return toIdSchemaInternal(
2050
- validator,
2051
- get14(schema, ITEMS_KEY),
2052
- idPrefix,
2053
- idSeparator,
2054
- id,
2055
- rootSchema,
2056
- formData,
2057
- _recurseList,
2058
- experimental_customMergeAllOf
2059
- );
2060
- }
2061
- if (getSchemaType(schema) === "object" && PROPERTIES_KEY in schema) {
2062
- for (const name in schema.properties) {
2063
- const field = schema[PROPERTIES_KEY][name];
2064
- const fieldId = idSchema[ID_KEY] + idSeparator + name;
2065
- idSchema[name] = toIdSchemaInternal(
2066
- validator,
2067
- field,
2068
- idPrefix,
2069
- idSeparator,
2070
- fieldId,
2071
- rootSchema,
2072
- // It's possible that formData is not an object -- this can happen if an
2073
- // array item has just been added, but not populated with data yet
2074
- get14(formData, [name]),
2075
- _recurseList,
2076
- experimental_customMergeAllOf
2077
- );
2078
- }
2079
- }
2080
- }
2081
- return idSchema;
2082
- }
2083
- function toIdSchema(validator, schema, id, rootSchema, formData, idPrefix = "root", idSeparator = "_", experimental_customMergeAllOf) {
2084
- return toIdSchemaInternal(
2085
- validator,
2086
- schema,
2087
- idPrefix,
2088
- idSeparator,
2089
- id,
2090
- rootSchema,
2091
- formData,
2092
- void 0,
2093
- experimental_customMergeAllOf
2094
- );
2095
- }
2096
-
2097
2027
  // src/schema/toPathSchema.ts
2098
- import get15 from "lodash/get";
2028
+ import get14 from "lodash/get";
2099
2029
  import set2 from "lodash/set";
2100
2030
  function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
2101
2031
  if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
@@ -2188,7 +2118,7 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
2188
2118
  }
2189
2119
  } else if (PROPERTIES_KEY in schema) {
2190
2120
  for (const property in schema.properties) {
2191
- const field = get15(schema, [PROPERTIES_KEY, property], {});
2121
+ const field = get14(schema, [PROPERTIES_KEY, property], {});
2192
2122
  pathSchema[property] = toPathSchemaInternal(
2193
2123
  validator,
2194
2124
  field,
@@ -2196,7 +2126,7 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
2196
2126
  rootSchema,
2197
2127
  // It's possible that formData is not an object -- this can happen if an
2198
2128
  // array item has just been added, but not populated with data yet
2199
- get15(formData, [property]),
2129
+ get14(formData, [property]),
2200
2130
  _recurseList,
2201
2131
  experimental_customMergeAllOf
2202
2132
  );
@@ -2209,7 +2139,7 @@ function toPathSchema(validator, schema, name = "", rootSchema, formData, experi
2209
2139
  }
2210
2140
 
2211
2141
  // src/createSchemaUtils.ts
2212
- import get16 from "lodash/get";
2142
+ import get15 from "lodash/get";
2213
2143
  var SchemaUtils = class {
2214
2144
  /** Constructs the `SchemaUtils` instance with the given `validator` and `rootSchema` stored as instance variables
2215
2145
  *
@@ -2220,7 +2150,7 @@ var SchemaUtils = class {
2220
2150
  */
2221
2151
  constructor(validator, rootSchema, experimental_defaultFormStateBehavior, experimental_customMergeAllOf) {
2222
2152
  if (rootSchema && rootSchema[SCHEMA_KEY] === JSON_SCHEMA_DRAFT_2020_12) {
2223
- this.rootSchema = makeAllReferencesAbsolute(rootSchema, get16(rootSchema, ID_KEY, "#"));
2153
+ this.rootSchema = makeAllReferencesAbsolute(rootSchema, get15(rootSchema, ID_KEY, "#"));
2224
2154
  } else {
2225
2155
  this.rootSchema = rootSchema;
2226
2156
  }
@@ -2448,27 +2378,6 @@ var SchemaUtils = class {
2448
2378
  this.experimental_customMergeAllOf
2449
2379
  );
2450
2380
  }
2451
- /** Generates an `IdSchema` object for the `schema`, recursively
2452
- *
2453
- * @param schema - The schema for which the display label flag is desired
2454
- * @param [id] - The base id for the schema
2455
- * @param [formData] - The current formData, if any, onto which to provide any missing defaults
2456
- * @param [idPrefix='root'] - The prefix to use for the id
2457
- * @param [idSeparator='_'] - The separator to use for the path segments in the id
2458
- * @returns - The `IdSchema` object for the `schema`
2459
- */
2460
- toIdSchema(schema, id, formData, idPrefix = "root", idSeparator = "_") {
2461
- return toIdSchema(
2462
- this.validator,
2463
- schema,
2464
- id,
2465
- this.rootSchema,
2466
- formData,
2467
- idPrefix,
2468
- idSeparator,
2469
- this.experimental_customMergeAllOf
2470
- );
2471
- }
2472
2381
  /** Generates an `PathSchema` object for the `schema`, recursively
2473
2382
  *
2474
2383
  * @param schema - The schema for which the display label flag is desired
@@ -2651,7 +2560,7 @@ function enumOptionsSelectValue(valueIndex, selected, allEnumOptions = []) {
2651
2560
 
2652
2561
  // src/ErrorSchemaBuilder.ts
2653
2562
  import cloneDeep from "lodash/cloneDeep";
2654
- import get17 from "lodash/get";
2563
+ import get16 from "lodash/get";
2655
2564
  import set3 from "lodash/set";
2656
2565
  import setWith from "lodash/setWith";
2657
2566
  var ErrorSchemaBuilder = class {
@@ -2680,7 +2589,7 @@ var ErrorSchemaBuilder = class {
2680
2589
  */
2681
2590
  getOrCreateErrorBlock(pathOfError) {
2682
2591
  const hasPath = Array.isArray(pathOfError) && pathOfError.length > 0 || typeof pathOfError === "string";
2683
- let errorBlock = hasPath ? get17(this.errorSchema, pathOfError) : this.errorSchema;
2592
+ let errorBlock = hasPath ? get16(this.errorSchema, pathOfError) : this.errorSchema;
2684
2593
  if (!errorBlock && pathOfError) {
2685
2594
  errorBlock = {};
2686
2595
  setWith(this.errorSchema, pathOfError, errorBlock, Object);
@@ -2706,7 +2615,7 @@ var ErrorSchemaBuilder = class {
2706
2615
  */
2707
2616
  addErrors(errorOrList, pathOfError) {
2708
2617
  const errorBlock = this.getOrCreateErrorBlock(pathOfError);
2709
- let errorsList = get17(errorBlock, ERRORS_KEY);
2618
+ let errorsList = get16(errorBlock, ERRORS_KEY);
2710
2619
  if (!Array.isArray(errorsList)) {
2711
2620
  errorsList = [];
2712
2621
  errorBlock[ERRORS_KEY] = errorsList;
@@ -2854,10 +2763,10 @@ function getTemplate(name, registry, uiOptions = {}) {
2854
2763
  }
2855
2764
 
2856
2765
  // src/getTestIds.ts
2857
- import get18 from "lodash/get";
2766
+ import get17 from "lodash/get";
2858
2767
  import uniqueId from "lodash/uniqueId";
2859
2768
  function getTestIds() {
2860
- if (typeof process === "undefined" || get18(process, "env.NODE_ENV") !== "test") {
2769
+ if (typeof process === "undefined" || get17(process, "env.NODE_ENV") !== "test") {
2861
2770
  return {};
2862
2771
  }
2863
2772
  const ids = /* @__PURE__ */ new Map();
@@ -2877,7 +2786,7 @@ function getTestIds() {
2877
2786
  // src/getWidget.tsx
2878
2787
  import { createElement } from "react";
2879
2788
  import ReactIs from "react-is";
2880
- import get19 from "lodash/get";
2789
+ import get18 from "lodash/get";
2881
2790
  import set4 from "lodash/set";
2882
2791
  import { jsx } from "react/jsx-runtime";
2883
2792
  var widgetMap = {
@@ -2933,7 +2842,7 @@ var widgetMap = {
2933
2842
  }
2934
2843
  };
2935
2844
  function mergeWidgetOptions(AWidget) {
2936
- let MergedWidget = get19(AWidget, "MergedWidget");
2845
+ let MergedWidget = get18(AWidget, "MergedWidget");
2937
2846
  if (!MergedWidget) {
2938
2847
  const defaultOptions = AWidget.defaultProps && AWidget.defaultProps.options || {};
2939
2848
  MergedWidget = ({ options, ...props }) => {
@@ -3046,14 +2955,14 @@ function localToUTC(dateString) {
3046
2955
  }
3047
2956
 
3048
2957
  // src/lookupFromFormContext.ts
3049
- import get20 from "lodash/get";
2958
+ import get19 from "lodash/get";
3050
2959
  import has6 from "lodash/has";
3051
2960
  function lookupFromFormContext(regOrFc, toLookup, fallback) {
3052
2961
  const lookupPath = [LOOKUP_MAP_NAME];
3053
2962
  if (has6(regOrFc, FORM_CONTEXT_NAME)) {
3054
2963
  lookupPath.unshift(FORM_CONTEXT_NAME);
3055
2964
  }
3056
- return get20(regOrFc, [...lookupPath, toLookup], fallback);
2965
+ return get19(regOrFc, [...lookupPath, toLookup], fallback);
3057
2966
  }
3058
2967
 
3059
2968
  // src/orderProperties.ts
@@ -3203,6 +3112,15 @@ function toErrorSchema(errors) {
3203
3112
  return builder.ErrorSchema;
3204
3113
  }
3205
3114
 
3115
+ // src/toFieldPathId.ts
3116
+ function toFieldPathId(fieldPath, globalFormOptions, parentPath) {
3117
+ const basePath = Array.isArray(parentPath) ? parentPath : parentPath?.path;
3118
+ const childPath = fieldPath === "" ? [] : [fieldPath];
3119
+ const path = basePath ? basePath.concat(...childPath) : childPath;
3120
+ const id = [globalFormOptions.idPrefix, ...path].join(globalFormOptions.idSeparator);
3121
+ return { path, [ID_KEY]: id };
3122
+ }
3123
+
3206
3124
  // src/unwrapErrorHandler.ts
3207
3125
  import isPlainObject3 from "lodash/isPlainObject";
3208
3126
  function unwrapErrorHandler(errorHandler) {
@@ -3288,7 +3206,7 @@ function withIdRefPrefix(schemaNode) {
3288
3206
  import keys from "lodash/keys";
3289
3207
  import pickBy from "lodash/pickBy";
3290
3208
  import isPlainObject4 from "lodash/isPlainObject";
3291
- import get21 from "lodash/get";
3209
+ import get20 from "lodash/get";
3292
3210
  import difference from "lodash/difference";
3293
3211
  function getChangedFields(a, b) {
3294
3212
  const aIsPlainObject = isPlainObject4(a);
@@ -3301,7 +3219,7 @@ function getChangedFields(a, b) {
3301
3219
  } else if (!aIsPlainObject && bIsPlainObject) {
3302
3220
  return keys(b);
3303
3221
  } else {
3304
- const unequalFields = keys(pickBy(a, (value, key) => !deepEquals(value, get21(b, key))));
3222
+ const unequalFields = keys(pickBy(a, (value, key) => !deepEquals(value, get20(b, key))));
3305
3223
  const diffFields = difference(keys(b), keys(a));
3306
3224
  return [...unequalFields, ...diffFields];
3307
3225
  }
@@ -3346,7 +3264,7 @@ var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
3346
3264
  import forEach from "lodash/forEach";
3347
3265
 
3348
3266
  // src/parser/ParserValidator.ts
3349
- import get22 from "lodash/get";
3267
+ import get21 from "lodash/get";
3350
3268
  var ParserValidator = class {
3351
3269
  /** Construct the ParserValidator for the given `rootSchema`. This `rootSchema` will be stashed in the `schemaMap`
3352
3270
  * first.
@@ -3372,7 +3290,7 @@ var ParserValidator = class {
3372
3290
  * @param hash - The hash value at which to map the schema
3373
3291
  */
3374
3292
  addSchema(schema, hash) {
3375
- const key = get22(schema, ID_KEY, hash);
3293
+ const key = get21(schema, ID_KEY, hash);
3376
3294
  const identifiedSchema = { ...schema, [ID_KEY]: key };
3377
3295
  const existing = this.schemaMap[key];
3378
3296
  if (!existing) {
@@ -3468,6 +3386,8 @@ export {
3468
3386
  ALL_OF_KEY,
3469
3387
  ANY_OF_KEY,
3470
3388
  CONST_KEY,
3389
+ DEFAULT_ID_PREFIX,
3390
+ DEFAULT_ID_SEPARATOR,
3471
3391
  DEFAULT_KEY,
3472
3392
  DEFINITIONS_KEY,
3473
3393
  DEPENDENCIES_KEY,
@@ -3575,7 +3495,7 @@ export {
3575
3495
  toDateString,
3576
3496
  toErrorList,
3577
3497
  toErrorSchema,
3578
- toIdSchema,
3498
+ toFieldPathId,
3579
3499
  toPathSchema,
3580
3500
  unwrapErrorHandler,
3581
3501
  utcToLocal,