@rjsf/utils 5.3.0 → 5.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.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import React, { ReactElement, ComponentType, HTMLAttributes, StyleHTMLAttributes, ReactNode, ChangeEvent, ButtonHTMLAttributes } from 'react';
1
+ import * as react from 'react';
2
+ import react__default, { ReactElement, ComponentType, HTMLAttributes, StyleHTMLAttributes, ReactNode, ChangeEvent, ButtonHTMLAttributes } from 'react';
2
3
  import * as json_schema from 'json-schema';
3
4
  import { JSONSchema7 } from 'json-schema';
4
5
 
@@ -41,6 +42,8 @@ declare enum TranslatableString {
41
42
  ClearLabel = "Clear",
42
43
  /** Aria date label, used by DateWidget */
43
44
  AriaDateLabel = "Select a date",
45
+ /** File preview label, used by FileWidget */
46
+ PreviewLabel = "Preview",
44
47
  /** Decrement button aria label, used by UpDownWidget */
45
48
  DecrementAriaLabel = "Decrease value by 1",
46
49
  /** Increment button aria label, used by UpDownWidget */
@@ -662,6 +665,10 @@ interface WidgetProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extend
662
665
  onFocus: (id: string, value: any) => void;
663
666
  /** The computed label for this widget, as a string */
664
667
  label: string;
668
+ /** A boolean value, if true, will cause the label to be hidden. This is useful for nested fields where you don't want
669
+ * to clutter the UI. Customized via `label` in the `UiSchema`
670
+ */
671
+ hideLabel?: boolean;
665
672
  /** A boolean value stating if the widget can accept multiple values */
666
673
  multiple?: boolean;
667
674
  /** An array of strings listing all generated error messages from encountered errors for this widget */
@@ -758,6 +765,8 @@ type UIOptionsBaseType<T = any, S extends StrictRJSFSchema = RJSFSchema, F exten
758
765
  readonly?: boolean;
759
766
  /** This property allows you to reorder the properties that are shown for a particular object */
760
767
  order?: string[];
768
+ /** Flag, if set to `true`, will cause the `FileWidget` to show a preview (with download for non-image files) */
769
+ filePreview?: boolean;
761
770
  /** Flag, if set to `true`, will mark a list of checkboxes as displayed all on one line instead of one per row */
762
771
  inline?: boolean;
763
772
  /** Used to change the input type (for example, `tel` or `email`) for an <input> */
@@ -1359,6 +1368,19 @@ declare function isFixedItems<S extends StrictRJSFSchema = RJSFSchema>(schema: S
1359
1368
  */
1360
1369
  declare function isObject(thing: any): boolean;
1361
1370
 
1371
+ /** Helper function that will return the value to use for a widget `label` based on `hideLabel`. The `fallback` is used
1372
+ * as the return value from the function when `hideLabel` is true. Due to the implementation of theme components, it
1373
+ * may be necessary to return something other than `undefined` to cause the theme component to not render a label. Some
1374
+ * themes require may `false` and others may require and empty string.
1375
+ *
1376
+ * @param [label] - The label string or component to render when not hidden
1377
+ * @param [hideLabel] - Flag, if true, will cause the label to be hidden
1378
+ * @param [fallback] - One of 3 values, `undefined` (the default), `false` or an empty string
1379
+ * @returns - `fallback` if `hideLabel` is true, otherwise `label`
1380
+ */
1381
+ declare function labelValue(label?: string | ReactElement, hideLabel?: boolean, fallback?: ''): undefined | string;
1382
+ declare function labelValue(label?: string | ReactElement, hideLabel?: boolean, fallback?: false | ''): string | false | ReactElement<any, string | react.JSXElementConstructor<any>> | undefined;
1383
+
1362
1384
  /** Converts a local Date string into a UTC date string
1363
1385
  *
1364
1386
  * @param dateString - The string representation of a date as accepted by the `Date()` constructor
@@ -1479,7 +1501,7 @@ declare function schemaRequiresTrueValue<S extends StrictRJSFSchema = RJSFSchema
1479
1501
  * @param nextState - The next set of state against which to check
1480
1502
  * @returns - True if the component should be re-rendered, false otherwise
1481
1503
  */
1482
- declare function shouldRender(component: React.Component, nextProps: any, nextState: any): boolean;
1504
+ declare function shouldRender(component: react__default.Component, nextProps: any, nextState: any): boolean;
1483
1505
 
1484
1506
  /** Returns the constant value from the schema when it is either a single value enum or has a const key. Otherwise
1485
1507
  * throws an error.
@@ -1731,4 +1753,4 @@ declare function toIdSchema<T = any, S extends StrictRJSFSchema = RJSFSchema, F
1731
1753
  */
1732
1754
  declare function toPathSchema<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, schema: S, name?: string, rootSchema?: S, formData?: T): PathSchema<T>;
1733
1755
 
1734
- export { ADDITIONAL_PROPERTIES_KEY, ADDITIONAL_PROPERTY_FLAG, ALL_OF_KEY, ANY_OF_KEY, ArrayFieldDescriptionProps, ArrayFieldTemplateItemType, ArrayFieldTemplateProps, ArrayFieldTitleProps, BaseInputTemplateProps, CONST_KEY, CustomValidator, DEFAULT_KEY, DEFINITIONS_KEY, DEPENDENCIES_KEY, DateObject, DescriptionFieldProps, ENUM_KEY, ERRORS_KEY, EnumOptionsType, ErrorListProps, ErrorSchema, ErrorSchemaBuilder, ErrorTransformer, Field, FieldError, FieldErrorProps, FieldErrors, FieldHelpProps, FieldId, FieldPath, FieldProps, FieldTemplateProps, FieldValidation, FormContextType, FormValidation, GenericObjectType, GlobalUISchemaOptions, ID_KEY, ITEMS_KEY, IconButtonProps, IdSchema, InputPropsType, NAME_KEY, ONE_OF_KEY, ObjectFieldTemplatePropertyType, ObjectFieldTemplateProps, PROPERTIES_KEY, PathSchema, REF_KEY, REQUIRED_KEY, RJSFSchema, RJSFValidationError, RJSF_ADDITONAL_PROPERTIES_FLAG, RangeSpecType, Registry, RegistryFieldsType, RegistryWidgetsType, SUBMIT_BTN_OPTIONS_KEY, SchemaUtilsType, StrictRJSFSchema, SubmitButtonProps, TemplatesType, TitleFieldProps, TranslatableString, UIOptionsType, UISchemaSubmitButtonOptions, UI_FIELD_KEY, UI_GLOBAL_OPTIONS_KEY, UI_OPTIONS_KEY, UI_WIDGET_KEY, UiSchema, UnsupportedFieldProps, ValidationData, ValidatorType, Widget, WidgetProps, WrapIfAdditionalTemplateProps, allowAdditionalItems, ariaDescribedByIds, asNumber, canExpand, createSchemaUtils, dataURItoBlob, deepEquals, descriptionId, englishStringTranslator, enumOptionsDeselectValue, enumOptionsIndexForValue, enumOptionsIsSelected, enumOptionsSelectValue, enumOptionsValueForIndex, errorId, examplesId, findSchemaDefinition, getClosestMatchingOption, getDefaultFormState, getDisplayLabel, getFirstMatchingOption, getInputProps, getMatchingOption, getSchemaType, getSubmitButtonOptions, getTemplate, getUiOptions, getWidget, guessType, hasWidget, helpId, isConstant, isCustomWidget, isFilesArray, isFixedItems, isMultiSelect, isObject, isSelect, localToUTC, mergeDefaultsWithFormData, mergeObjects, mergeSchemas, mergeValidationData, optionId, optionsList, orderProperties, pad, parseDateString, rangeSpec, replaceStringParameters, retrieveSchema, sanitizeDataForNewSchema, schemaRequiresTrueValue, shouldRender, titleId, toConstant, toDateString, toIdSchema, toPathSchema, utcToLocal };
1756
+ export { ADDITIONAL_PROPERTIES_KEY, ADDITIONAL_PROPERTY_FLAG, ALL_OF_KEY, ANY_OF_KEY, ArrayFieldDescriptionProps, ArrayFieldTemplateItemType, ArrayFieldTemplateProps, ArrayFieldTitleProps, BaseInputTemplateProps, CONST_KEY, CustomValidator, DEFAULT_KEY, DEFINITIONS_KEY, DEPENDENCIES_KEY, DateObject, DescriptionFieldProps, ENUM_KEY, ERRORS_KEY, EnumOptionsType, ErrorListProps, ErrorSchema, ErrorSchemaBuilder, ErrorTransformer, Field, FieldError, FieldErrorProps, FieldErrors, FieldHelpProps, FieldId, FieldPath, FieldProps, FieldTemplateProps, FieldValidation, FormContextType, FormValidation, GenericObjectType, GlobalUISchemaOptions, ID_KEY, ITEMS_KEY, IconButtonProps, IdSchema, InputPropsType, NAME_KEY, ONE_OF_KEY, ObjectFieldTemplatePropertyType, ObjectFieldTemplateProps, PROPERTIES_KEY, PathSchema, REF_KEY, REQUIRED_KEY, RJSFSchema, RJSFValidationError, RJSF_ADDITONAL_PROPERTIES_FLAG, RangeSpecType, Registry, RegistryFieldsType, RegistryWidgetsType, SUBMIT_BTN_OPTIONS_KEY, SchemaUtilsType, StrictRJSFSchema, SubmitButtonProps, TemplatesType, TitleFieldProps, TranslatableString, UIOptionsType, UISchemaSubmitButtonOptions, UI_FIELD_KEY, UI_GLOBAL_OPTIONS_KEY, UI_OPTIONS_KEY, UI_WIDGET_KEY, UiSchema, UnsupportedFieldProps, ValidationData, ValidatorType, Widget, WidgetProps, WrapIfAdditionalTemplateProps, allowAdditionalItems, ariaDescribedByIds, asNumber, canExpand, createSchemaUtils, dataURItoBlob, deepEquals, descriptionId, englishStringTranslator, enumOptionsDeselectValue, enumOptionsIndexForValue, enumOptionsIsSelected, enumOptionsSelectValue, enumOptionsValueForIndex, errorId, examplesId, findSchemaDefinition, getClosestMatchingOption, getDefaultFormState, getDisplayLabel, getFirstMatchingOption, getInputProps, getMatchingOption, getSchemaType, getSubmitButtonOptions, getTemplate, getUiOptions, getWidget, guessType, hasWidget, helpId, isConstant, isCustomWidget, isFilesArray, isFixedItems, isMultiSelect, isObject, isSelect, labelValue, localToUTC, mergeDefaultsWithFormData, mergeObjects, mergeSchemas, mergeValidationData, optionId, optionsList, orderProperties, pad, parseDateString, rangeSpec, replaceStringParameters, retrieveSchema, sanitizeDataForNewSchema, schemaRequiresTrueValue, shouldRender, titleId, toConstant, toDateString, toIdSchema, toPathSchema, utcToLocal };
@@ -2484,6 +2484,10 @@ function optionId(id, optionIndex) {
2484
2484
  return id + "-" + optionIndex;
2485
2485
  }
2486
2486
 
2487
+ function labelValue(label, hideLabel, fallback) {
2488
+ return hideLabel ? fallback : label;
2489
+ }
2490
+
2487
2491
  /** Converts a local Date string into a UTC date string
2488
2492
  *
2489
2493
  * @param dateString - The string representation of a date as accepted by the `Date()` constructor
@@ -2782,6 +2786,8 @@ exports.TranslatableString = void 0;
2782
2786
  TranslatableString["ClearLabel"] = "Clear";
2783
2787
  /** Aria date label, used by DateWidget */
2784
2788
  TranslatableString["AriaDateLabel"] = "Select a date";
2789
+ /** File preview label, used by FileWidget */
2790
+ TranslatableString["PreviewLabel"] = "Preview";
2785
2791
  /** Decrement button aria label, used by UpDownWidget */
2786
2792
  TranslatableString["DecrementAriaLabel"] = "Decrease value by 1";
2787
2793
  /** Increment button aria label, used by UpDownWidget */
@@ -2878,6 +2884,7 @@ exports.isFixedItems = isFixedItems;
2878
2884
  exports.isMultiSelect = isMultiSelect;
2879
2885
  exports.isObject = isObject;
2880
2886
  exports.isSelect = isSelect;
2887
+ exports.labelValue = labelValue;
2881
2888
  exports.localToUTC = localToUTC;
2882
2889
  exports.mergeDefaultsWithFormData = mergeDefaultsWithFormData;
2883
2890
  exports.mergeObjects = mergeObjects;