@rjsf/utils 6.0.2 → 6.1.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
@@ -1878,6 +1878,9 @@ function getDefaultFormState(validator, theSchema, formData, rootSchema, include
1878
1878
  return defaults;
1879
1879
  }
1880
1880
 
1881
+ // src/schema/getDisplayLabel.ts
1882
+ import get13 from "lodash/get";
1883
+
1881
1884
  // src/isCustomWidget.ts
1882
1885
  function isCustomWidget(uiSchema = {}) {
1883
1886
  return (
@@ -1909,25 +1912,28 @@ function isFilesArray(validator, schema, uiSchema = {}, rootSchema, experimental
1909
1912
  function getDisplayLabel(validator, schema, uiSchema = {}, rootSchema, globalOptions, experimental_customMergeAllOf) {
1910
1913
  const uiOptions = getUiOptions(uiSchema, globalOptions);
1911
1914
  const { label = true } = uiOptions;
1912
- let displayLabel = !!label;
1913
- const schemaType = getSchemaType(schema);
1914
- if (schemaType === "array") {
1915
- displayLabel = isMultiSelect(validator, schema, rootSchema, experimental_customMergeAllOf) || isFilesArray(validator, schema, uiSchema, rootSchema, experimental_customMergeAllOf) || isCustomWidget(uiSchema);
1916
- }
1917
- if (schemaType === "object") {
1918
- displayLabel = false;
1919
- }
1920
- if (schemaType === "boolean" && uiSchema && !uiSchema[UI_WIDGET_KEY]) {
1921
- displayLabel = false;
1922
- }
1923
- if (uiSchema && uiSchema[UI_FIELD_KEY]) {
1924
- displayLabel = false;
1915
+ let displayLabel = Boolean(label);
1916
+ if (displayLabel) {
1917
+ const schemaType = getSchemaType(schema);
1918
+ const addedByAdditionalProperty = get13(schema, ADDITIONAL_PROPERTY_FLAG, false);
1919
+ if (schemaType === "array") {
1920
+ displayLabel = addedByAdditionalProperty || isMultiSelect(validator, schema, rootSchema, experimental_customMergeAllOf) || isFilesArray(validator, schema, uiSchema, rootSchema, experimental_customMergeAllOf) || isCustomWidget(uiSchema);
1921
+ }
1922
+ if (schemaType === "object") {
1923
+ displayLabel = addedByAdditionalProperty;
1924
+ }
1925
+ if (schemaType === "boolean" && uiSchema && !uiSchema[UI_WIDGET_KEY]) {
1926
+ displayLabel = false;
1927
+ }
1928
+ if (uiSchema && uiSchema[UI_FIELD_KEY]) {
1929
+ displayLabel = false;
1930
+ }
1925
1931
  }
1926
1932
  return displayLabel;
1927
1933
  }
1928
1934
 
1929
1935
  // src/schema/sanitizeDataForNewSchema.ts
1930
- import get13 from "lodash/get";
1936
+ import get14 from "lodash/get";
1931
1937
  import has5 from "lodash/has";
1932
1938
  var NO_VALUE = Symbol("no Value");
1933
1939
  function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, data = {}, experimental_customMergeAllOf) {
@@ -1935,19 +1941,19 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
1935
1941
  if (has5(newSchema, PROPERTIES_KEY)) {
1936
1942
  const removeOldSchemaData = {};
1937
1943
  if (has5(oldSchema, PROPERTIES_KEY)) {
1938
- const properties = get13(oldSchema, PROPERTIES_KEY, {});
1944
+ const properties = get14(oldSchema, PROPERTIES_KEY, {});
1939
1945
  Object.keys(properties).forEach((key) => {
1940
1946
  if (has5(data, key)) {
1941
1947
  removeOldSchemaData[key] = void 0;
1942
1948
  }
1943
1949
  });
1944
1950
  }
1945
- const keys2 = Object.keys(get13(newSchema, PROPERTIES_KEY, {}));
1951
+ const keys2 = Object.keys(get14(newSchema, PROPERTIES_KEY, {}));
1946
1952
  const nestedData = {};
1947
1953
  keys2.forEach((key) => {
1948
- const formValue = get13(data, key);
1949
- let oldKeyedSchema = get13(oldSchema, [PROPERTIES_KEY, key], {});
1950
- let newKeyedSchema = get13(newSchema, [PROPERTIES_KEY, key], {});
1954
+ const formValue = get14(data, key);
1955
+ let oldKeyedSchema = get14(oldSchema, [PROPERTIES_KEY, key], {});
1956
+ let newKeyedSchema = get14(newSchema, [PROPERTIES_KEY, key], {});
1951
1957
  if (has5(oldKeyedSchema, REF_KEY)) {
1952
1958
  oldKeyedSchema = retrieveSchema(
1953
1959
  validator,
@@ -1966,8 +1972,8 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
1966
1972
  experimental_customMergeAllOf
1967
1973
  );
1968
1974
  }
1969
- const oldSchemaTypeForKey = get13(oldKeyedSchema, "type");
1970
- const newSchemaTypeForKey = get13(newKeyedSchema, "type");
1975
+ const oldSchemaTypeForKey = get14(oldKeyedSchema, "type");
1976
+ const newSchemaTypeForKey = get14(newKeyedSchema, "type");
1971
1977
  if (!oldSchemaTypeForKey || oldSchemaTypeForKey === newSchemaTypeForKey) {
1972
1978
  if (has5(removeOldSchemaData, key)) {
1973
1979
  delete removeOldSchemaData[key];
@@ -1985,17 +1991,17 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
1985
1991
  nestedData[key] = itemData;
1986
1992
  }
1987
1993
  } else {
1988
- const newOptionDefault = get13(newKeyedSchema, "default", NO_VALUE);
1989
- const oldOptionDefault = get13(oldKeyedSchema, "default", NO_VALUE);
1994
+ const newOptionDefault = get14(newKeyedSchema, "default", NO_VALUE);
1995
+ const oldOptionDefault = get14(oldKeyedSchema, "default", NO_VALUE);
1990
1996
  if (newOptionDefault !== NO_VALUE && newOptionDefault !== formValue) {
1991
1997
  if (oldOptionDefault === formValue) {
1992
1998
  removeOldSchemaData[key] = newOptionDefault;
1993
- } else if (get13(newKeyedSchema, "readOnly") === true) {
1999
+ } else if (get14(newKeyedSchema, "readOnly") === true) {
1994
2000
  removeOldSchemaData[key] = void 0;
1995
2001
  }
1996
2002
  }
1997
- const newOptionConst = get13(newKeyedSchema, "const", NO_VALUE);
1998
- const oldOptionConst = get13(oldKeyedSchema, "const", NO_VALUE);
2003
+ const newOptionConst = get14(newKeyedSchema, "const", NO_VALUE);
2004
+ const oldOptionConst = get14(oldKeyedSchema, "const", NO_VALUE);
1999
2005
  if (newOptionConst !== NO_VALUE && newOptionConst !== formValue) {
2000
2006
  removeOldSchemaData[key] = oldOptionConst === formValue ? newOptionConst : void 0;
2001
2007
  }
@@ -2007,9 +2013,9 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
2007
2013
  ...removeOldSchemaData,
2008
2014
  ...nestedData
2009
2015
  };
2010
- } else if (get13(oldSchema, "type") === "array" && get13(newSchema, "type") === "array" && Array.isArray(data)) {
2011
- let oldSchemaItems = get13(oldSchema, "items");
2012
- let newSchemaItems = get13(newSchema, "items");
2016
+ } else if (get14(oldSchema, "type") === "array" && get14(newSchema, "type") === "array" && Array.isArray(data)) {
2017
+ let oldSchemaItems = get14(oldSchema, "items");
2018
+ let newSchemaItems = get14(newSchema, "items");
2013
2019
  if (typeof oldSchemaItems === "object" && typeof newSchemaItems === "object" && !Array.isArray(oldSchemaItems) && !Array.isArray(newSchemaItems)) {
2014
2020
  if (has5(oldSchemaItems, REF_KEY)) {
2015
2021
  oldSchemaItems = retrieveSchema(
@@ -2029,10 +2035,10 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
2029
2035
  experimental_customMergeAllOf
2030
2036
  );
2031
2037
  }
2032
- const oldSchemaType = get13(oldSchemaItems, "type");
2033
- const newSchemaType = get13(newSchemaItems, "type");
2038
+ const oldSchemaType = get14(oldSchemaItems, "type");
2039
+ const newSchemaType = get14(newSchemaItems, "type");
2034
2040
  if (!oldSchemaType || oldSchemaType === newSchemaType) {
2035
- const maxItems = get13(newSchema, "maxItems", -1);
2041
+ const maxItems = get14(newSchema, "maxItems", -1);
2036
2042
  if (newSchemaType === "object") {
2037
2043
  newFormData = data.reduce((newValue, aValue) => {
2038
2044
  const itemValue = sanitizeDataForNewSchema(
@@ -2060,7 +2066,7 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
2060
2066
  }
2061
2067
 
2062
2068
  // src/schema/toPathSchema.ts
2063
- import get14 from "lodash/get";
2069
+ import get15 from "lodash/get";
2064
2070
  import set2 from "lodash/set";
2065
2071
  function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
2066
2072
  if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
@@ -2153,7 +2159,7 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
2153
2159
  }
2154
2160
  } else if (PROPERTIES_KEY in schema) {
2155
2161
  for (const property in schema.properties) {
2156
- const field = get14(schema, [PROPERTIES_KEY, property], {});
2162
+ const field = get15(schema, [PROPERTIES_KEY, property], {});
2157
2163
  pathSchema[property] = toPathSchemaInternal(
2158
2164
  validator,
2159
2165
  field,
@@ -2161,7 +2167,7 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
2161
2167
  rootSchema,
2162
2168
  // It's possible that formData is not an object -- this can happen if an
2163
2169
  // array item has just been added, but not populated with data yet
2164
- get14(formData, [property]),
2170
+ get15(formData, [property]),
2165
2171
  _recurseList,
2166
2172
  experimental_customMergeAllOf
2167
2173
  );
@@ -2174,7 +2180,7 @@ function toPathSchema(validator, schema, name = "", rootSchema, formData, experi
2174
2180
  }
2175
2181
 
2176
2182
  // src/createSchemaUtils.ts
2177
- import get15 from "lodash/get";
2183
+ import get16 from "lodash/get";
2178
2184
  var SchemaUtils = class {
2179
2185
  /** Constructs the `SchemaUtils` instance with the given `validator` and `rootSchema` stored as instance variables
2180
2186
  *
@@ -2185,7 +2191,7 @@ var SchemaUtils = class {
2185
2191
  */
2186
2192
  constructor(validator, rootSchema, experimental_defaultFormStateBehavior, experimental_customMergeAllOf) {
2187
2193
  if (rootSchema && rootSchema[SCHEMA_KEY] === JSON_SCHEMA_DRAFT_2020_12) {
2188
- this.rootSchema = makeAllReferencesAbsolute(rootSchema, get15(rootSchema, ID_KEY, "#"));
2194
+ this.rootSchema = makeAllReferencesAbsolute(rootSchema, get16(rootSchema, ID_KEY, "#"));
2189
2195
  } else {
2190
2196
  this.rootSchema = rootSchema;
2191
2197
  }
@@ -2599,7 +2605,7 @@ function enumOptionsSelectValue(valueIndex, selected, allEnumOptions = []) {
2599
2605
 
2600
2606
  // src/ErrorSchemaBuilder.ts
2601
2607
  import cloneDeep from "lodash/cloneDeep";
2602
- import get16 from "lodash/get";
2608
+ import get17 from "lodash/get";
2603
2609
  import set3 from "lodash/set";
2604
2610
  import setWith from "lodash/setWith";
2605
2611
  var ErrorSchemaBuilder = class {
@@ -2628,7 +2634,7 @@ var ErrorSchemaBuilder = class {
2628
2634
  */
2629
2635
  getOrCreateErrorBlock(pathOfError) {
2630
2636
  const hasPath = Array.isArray(pathOfError) && pathOfError.length > 0 || typeof pathOfError === "string";
2631
- let errorBlock = hasPath ? get16(this.errorSchema, pathOfError) : this.errorSchema;
2637
+ let errorBlock = hasPath ? get17(this.errorSchema, pathOfError) : this.errorSchema;
2632
2638
  if (!errorBlock && pathOfError) {
2633
2639
  errorBlock = {};
2634
2640
  setWith(this.errorSchema, pathOfError, errorBlock, Object);
@@ -2654,7 +2660,7 @@ var ErrorSchemaBuilder = class {
2654
2660
  */
2655
2661
  addErrors(errorOrList, pathOfError) {
2656
2662
  const errorBlock = this.getOrCreateErrorBlock(pathOfError);
2657
- let errorsList = get16(errorBlock, ERRORS_KEY);
2663
+ let errorsList = get17(errorBlock, ERRORS_KEY);
2658
2664
  if (!Array.isArray(errorsList)) {
2659
2665
  errorsList = [];
2660
2666
  errorBlock[ERRORS_KEY] = errorsList;
@@ -2698,7 +2704,7 @@ var ErrorSchemaBuilder = class {
2698
2704
  import keys from "lodash/keys";
2699
2705
  import pickBy from "lodash/pickBy";
2700
2706
  import isPlainObject2 from "lodash/isPlainObject";
2701
- import get17 from "lodash/get";
2707
+ import get18 from "lodash/get";
2702
2708
  import difference from "lodash/difference";
2703
2709
  function getChangedFields(a, b) {
2704
2710
  const aIsPlainObject = isPlainObject2(a);
@@ -2711,7 +2717,7 @@ function getChangedFields(a, b) {
2711
2717
  } else if (!aIsPlainObject && bIsPlainObject) {
2712
2718
  return keys(b);
2713
2719
  } else {
2714
- const unequalFields = keys(pickBy(a, (value, key) => !deepEquals(value, get17(b, key))));
2720
+ const unequalFields = keys(pickBy(a, (value, key) => !deepEquals(value, get18(b, key))));
2715
2721
  const diffFields = difference(keys(b), keys(a));
2716
2722
  return [...unequalFields, ...diffFields];
2717
2723
  }
@@ -2825,10 +2831,10 @@ function getTemplate(name, registry, uiOptions = {}) {
2825
2831
  }
2826
2832
 
2827
2833
  // src/getTestIds.ts
2828
- import get18 from "lodash/get";
2834
+ import get19 from "lodash/get";
2829
2835
  import uniqueId from "lodash/uniqueId";
2830
2836
  function getTestIds() {
2831
- if (typeof process === "undefined" || get18(process, "env.NODE_ENV") !== "test") {
2837
+ if (typeof process === "undefined" || get19(process, "env.NODE_ENV") !== "test") {
2832
2838
  return {};
2833
2839
  }
2834
2840
  const ids = /* @__PURE__ */ new Map();
@@ -2848,7 +2854,7 @@ function getTestIds() {
2848
2854
  // src/getWidget.tsx
2849
2855
  import { createElement } from "react";
2850
2856
  import ReactIs from "react-is";
2851
- import get19 from "lodash/get";
2857
+ import get20 from "lodash/get";
2852
2858
  import set4 from "lodash/set";
2853
2859
  import { jsx } from "react/jsx-runtime";
2854
2860
  var widgetMap = {
@@ -2904,7 +2910,7 @@ var widgetMap = {
2904
2910
  }
2905
2911
  };
2906
2912
  function mergeWidgetOptions(AWidget) {
2907
- let MergedWidget = get19(AWidget, "MergedWidget");
2913
+ let MergedWidget = get20(AWidget, "MergedWidget");
2908
2914
  if (!MergedWidget) {
2909
2915
  const defaultOptions = AWidget.defaultProps && AWidget.defaultProps.options || {};
2910
2916
  MergedWidget = ({ options, ...props }) => {
@@ -3042,14 +3048,14 @@ function localToUTC(dateString) {
3042
3048
  }
3043
3049
 
3044
3050
  // src/lookupFromFormContext.ts
3045
- import get20 from "lodash/get";
3051
+ import get21 from "lodash/get";
3046
3052
  import has6 from "lodash/has";
3047
3053
  function lookupFromFormContext(regOrFc, toLookup, fallback) {
3048
3054
  const lookupPath = [LOOKUP_MAP_NAME];
3049
3055
  if (has6(regOrFc, FORM_CONTEXT_NAME)) {
3050
3056
  lookupPath.unshift(FORM_CONTEXT_NAME);
3051
3057
  }
3052
- return get20(regOrFc, [...lookupPath, toLookup], fallback);
3058
+ return get21(regOrFc, [...lookupPath, toLookup], fallback);
3053
3059
  }
3054
3060
 
3055
3061
  // src/orderProperties.ts
@@ -3586,7 +3592,7 @@ var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
3586
3592
  import forEach from "lodash/forEach";
3587
3593
 
3588
3594
  // src/parser/ParserValidator.ts
3589
- import get21 from "lodash/get";
3595
+ import get22 from "lodash/get";
3590
3596
  var ParserValidator = class {
3591
3597
  /** Construct the ParserValidator for the given `rootSchema`. This `rootSchema` will be stashed in the `schemaMap`
3592
3598
  * first.
@@ -3612,7 +3618,7 @@ var ParserValidator = class {
3612
3618
  * @param hash - The hash value at which to map the schema
3613
3619
  */
3614
3620
  addSchema(schema, hash) {
3615
- const key = get21(schema, ID_KEY, hash);
3621
+ const key = get22(schema, ID_KEY, hash);
3616
3622
  const identifiedSchema = { ...schema, [ID_KEY]: key };
3617
3623
  const existing = this.schemaMap[key];
3618
3624
  if (!existing) {