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