@rjsf/utils 5.1.0 → 5.2.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
@@ -2,6 +2,73 @@ import React, { StyleHTMLAttributes } from 'react';
2
2
  import * as json_schema from 'json-schema';
3
3
  import { JSONSchema7 } from 'json-schema';
4
4
 
5
+ /** An enumeration of all the translatable strings used by `@rjsf/core` and its themes. The value of each of the
6
+ * enumeration keys is expected to be the actual english string. Some strings contain replaceable parameter values
7
+ * as indicated by `%1`, `%2`, etc. The number after the `%` indicates the order of the parameter. The ordering of
8
+ * parameters is important because some languages may choose to put the second parameter before the first in its
9
+ * translation. Also, some strings are rendered using `markdown-to-jsx` and thus support markdown and inline html.
10
+ */
11
+ declare enum TranslatableString {
12
+ /** Fallback title of an array item, used by ArrayField */
13
+ ArrayItemTitle = "Item",
14
+ /** Missing items reason, used by ArrayField */
15
+ MissingItems = "Missing items definition",
16
+ /** Yes label, used by BooleanField */
17
+ YesLabel = "Yes",
18
+ /** No label, used by BooleanField */
19
+ NoLabel = "No",
20
+ /** Close label, used by ErrorList */
21
+ CloseLabel = "Close",
22
+ /** Errors label, used by ErrorList */
23
+ ErrorsLabel = "Errors",
24
+ /** New additionalProperties string default value, used by ObjectField */
25
+ NewStringDefault = "New Value",
26
+ /** Add button title, used by AddButton */
27
+ AddButton = "Add",
28
+ /** Add button title, used by AddButton */
29
+ AddItemButton = "Add Item",
30
+ /** Move down button title, used by IconButton */
31
+ MoveDownButton = "Move down",
32
+ /** Move up button title, used by IconButton */
33
+ MoveUpButton = "Move up",
34
+ /** Remove button title, used by IconButton */
35
+ RemoveButton = "Remove",
36
+ /** Now label, used by AltDateWidget */
37
+ NowLabel = "Now",
38
+ /** Clear label, used by AltDateWidget */
39
+ ClearLabel = "Clear",
40
+ /** Aria date label, used by DateWidget */
41
+ AriaDateLabel = "Select a date",
42
+ /** Decrement button aria label, used by UpDownWidget */
43
+ DecrementAriaLabel = "Decrease value by 1",
44
+ /** Increment button aria label, used by UpDownWidget */
45
+ IncrementAriaLabel = "Increase value by 1",
46
+ /** Unknown field type reason, where %1 will be replaced with the type as provided by SchemaField */
47
+ UnknownFieldType = "Unknown field type %1",
48
+ /** Option prefix, where %1 will be replaced with the option index as provided by MultiSchemaField */
49
+ OptionPrefix = "Option %1",
50
+ /** Option prefix, where %1 and %2 will be replaced by the schema title and option index, respectively as provided by
51
+ * MultiSchemaField
52
+ */
53
+ TitleOptionPrefix = "%1 option %2",
54
+ /** Key label, where %1 will be replaced by the label as provided by WrapIfAdditionalTemplate */
55
+ KeyLabel = "%1 Key",
56
+ /** Unsupported field schema, used by UnsupportedField */
57
+ UnsupportedField = "Unsupported field schema.",
58
+ /** Unsupported field schema, where %1 will be replaced by the idSchema.$id as provided by UnsupportedField */
59
+ UnsupportedFieldWithId = "Unsupported field schema for field <code>%1</code>.",
60
+ /** Unsupported field schema, where %1 will be replaced by the reason string as provided by UnsupportedField */
61
+ UnsupportedFieldWithReason = "Unsupported field schema: <em>%1</em>.",
62
+ /** Unsupported field schema, where %1 and %2 will be replaced by the idSchema.$id and reason strings, respectively,
63
+ * as provided by UnsupportedField
64
+ */
65
+ UnsupportedFieldWithIdAndReason = "Unsupported field schema for field <code>%1</code>: <em>%2</em>.",
66
+ /** File name, type and size info, where %1, %2 and %3 will be replaced by the file name, file type and file size as
67
+ * provided by FileWidget
68
+ */
69
+ FilesInfo = "<strong>%1</strong> (%2, %3 bytes)"
70
+ }
71
+
5
72
  /** The representation of any generic object type, usually used as an intersection on other types to make them more
6
73
  * flexible in the properties they support (i.e. anything else)
7
74
  */
@@ -123,6 +190,8 @@ type ErrorListProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends
123
190
  schema: S;
124
191
  /** The uiSchema that was passed to `Form` */
125
192
  uiSchema?: UiSchema<T, S, F>;
193
+ /** The `registry` object */
194
+ registry: Registry<T, S, F>;
126
195
  };
127
196
  /** The properties that are passed to an `FieldErrorTemplate` implementation */
128
197
  type FieldErrorProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = {
@@ -232,6 +301,8 @@ interface Registry<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends F
232
301
  * of the validation-schema-based utility functions
233
302
  */
234
303
  schemaUtils: SchemaUtilsType<T, S>;
304
+ /** The string translation function to use when displaying any of the RJSF strings in templates, fields or widgets */
305
+ translateString: (stringKey: TranslatableString, params?: string[]) => string;
235
306
  }
236
307
  /** The properties that are passed to a Field implementation */
237
308
  interface FieldProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> extends GenericObjectType, Pick<React.HTMLAttributes<HTMLElement>, Exclude<keyof React.HTMLAttributes<HTMLElement>, "onBlur" | "onFocus" | "onChange">> {
@@ -947,6 +1018,16 @@ declare function dataURItoBlob(dataURI: string): {
947
1018
  */
948
1019
  declare function deepEquals(a: any, b: any): boolean;
949
1020
 
1021
+ /** Translates a `TranslatableString` value `stringToTranslate` into english. When a `params` array is provided, each
1022
+ * value in the array is used to replace any of the replaceable parameters in the `stringToTranslate` using the `%1`,
1023
+ * `%2`, etc. replacement specifiers.
1024
+ *
1025
+ * @param stringToTranslate - The `TranslatableString` value to convert to english
1026
+ * @param params - The optional list of replaceable parameter values to substitute into the english string
1027
+ * @returns - The `stringToTranslate` itself with any replaceable parameter values substituted
1028
+ */
1029
+ declare function englishStringTranslator(stringToTranslate: TranslatableString, params?: string[]): string;
1030
+
950
1031
  /** Removes the enum option value at the `valueIndex` from the currently `selected` (list of) value(s). If `selected` is
951
1032
  * a list, then that list is updated to remove the enum option value with the `valueIndex` in `allEnumOptions`. If it is
952
1033
  * a single value, then if the enum option value with the `valueIndex` in `allEnumOptions` matches `selected`, undefined
@@ -1324,6 +1405,16 @@ declare function parseDateString(dateString?: string, includeTime?: boolean): Da
1324
1405
  */
1325
1406
  declare function rangeSpec<S extends StrictRJSFSchema = RJSFSchema>(schema: S): RangeSpecType;
1326
1407
 
1408
+ /** Potentially substitutes all replaceable parameters with the associated value(s) from the `params` if available. When
1409
+ * a `params` array is provided, each value in the array is used to replace any of the replaceable parameters in the
1410
+ * `inputString` using the `%1`, `%2`, etc. replacement specifiers.
1411
+ *
1412
+ * @param inputString - The string which will be potentially updated with replacement parameters
1413
+ * @param params - The optional list of replaceable parameter values to substitute into the english string
1414
+ * @returns - The updated string with any replacement specifiers replaced
1415
+ */
1416
+ declare function replaceStringParameters(inputString: string, params?: string[]): string;
1417
+
1327
1418
  /** Check to see if a `schema` specifies that a value must be true. This happens when:
1328
1419
  * - `schema.const` is truthy
1329
1420
  * - `schema.enum` == `[true]`
@@ -1593,4 +1684,4 @@ declare function toIdSchema<T = any, S extends StrictRJSFSchema = RJSFSchema, F
1593
1684
  */
1594
1685
  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>;
1595
1686
 
1596
- export { ADDITIONAL_PROPERTIES_KEY, ADDITIONAL_PROPERTY_FLAG, ALL_OF_KEY, ANY_OF_KEY, ArrayFieldDescriptionProps, ArrayFieldTemplateItemType, ArrayFieldTemplateProps, ArrayFieldTitleProps, 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, 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, UIOptionsType, UISchemaSubmitButtonOptions, UI_FIELD_KEY, UI_OPTIONS_KEY, UI_WIDGET_KEY, UiSchema, UnsupportedFieldProps, ValidationData, ValidatorType, Widget, WidgetProps, WrapIfAdditionalTemplateProps, allowAdditionalItems, ariaDescribedByIds, asNumber, canExpand, createSchemaUtils, dataURItoBlob, deepEquals, descriptionId, 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, retrieveSchema, sanitizeDataForNewSchema, schemaRequiresTrueValue, shouldRender, titleId, toConstant, toDateString, toIdSchema, toPathSchema, utcToLocal };
1687
+ export { ADDITIONAL_PROPERTIES_KEY, ADDITIONAL_PROPERTY_FLAG, ALL_OF_KEY, ANY_OF_KEY, ArrayFieldDescriptionProps, ArrayFieldTemplateItemType, ArrayFieldTemplateProps, ArrayFieldTitleProps, 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, 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_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 };
@@ -1868,6 +1868,36 @@ function dataURItoBlob(dataURI) {
1868
1868
  };
1869
1869
  }
1870
1870
 
1871
+ /** Potentially substitutes all replaceable parameters with the associated value(s) from the `params` if available. When
1872
+ * a `params` array is provided, each value in the array is used to replace any of the replaceable parameters in the
1873
+ * `inputString` using the `%1`, `%2`, etc. replacement specifiers.
1874
+ *
1875
+ * @param inputString - The string which will be potentially updated with replacement parameters
1876
+ * @param params - The optional list of replaceable parameter values to substitute into the english string
1877
+ * @returns - The updated string with any replacement specifiers replaced
1878
+ */
1879
+ function replaceStringParameters(inputString, params) {
1880
+ var output = inputString;
1881
+ if (Array.isArray(params)) {
1882
+ params.forEach(function (param, index) {
1883
+ output = output.replace("%" + (index + 1), param);
1884
+ });
1885
+ }
1886
+ return output;
1887
+ }
1888
+
1889
+ /** Translates a `TranslatableString` value `stringToTranslate` into english. When a `params` array is provided, each
1890
+ * value in the array is used to replace any of the replaceable parameters in the `stringToTranslate` using the `%1`,
1891
+ * `%2`, etc. replacement specifiers.
1892
+ *
1893
+ * @param stringToTranslate - The `TranslatableString` value to convert to english
1894
+ * @param params - The optional list of replaceable parameter values to substitute into the english string
1895
+ * @returns - The `stringToTranslate` itself with any replaceable parameter values substituted
1896
+ */
1897
+ function englishStringTranslator(stringToTranslate, params) {
1898
+ return replaceStringParameters(stringToTranslate, params);
1899
+ }
1900
+
1871
1901
  /** Returns the value(s) from `allEnumOptions` at the index(es) provided by `valueIndex`. If `valueIndex` is not an
1872
1902
  * array AND the index is not valid for `allEnumOptions`, `emptyValue` is returned. If `valueIndex` is an array, AND it
1873
1903
  * contains an invalid index, the returned array will have the resulting undefined values filtered out, leaving only
@@ -2687,6 +2717,76 @@ function utcToLocal(jsonDate) {
2687
2717
  return yyyy + "-" + MM + "-" + dd + "T" + hh + ":" + mm + ":" + ss + "." + SSS;
2688
2718
  }
2689
2719
 
2720
+ /** An enumeration of all the translatable strings used by `@rjsf/core` and its themes. The value of each of the
2721
+ * enumeration keys is expected to be the actual english string. Some strings contain replaceable parameter values
2722
+ * as indicated by `%1`, `%2`, etc. The number after the `%` indicates the order of the parameter. The ordering of
2723
+ * parameters is important because some languages may choose to put the second parameter before the first in its
2724
+ * translation. Also, some strings are rendered using `markdown-to-jsx` and thus support markdown and inline html.
2725
+ */
2726
+ exports.TranslatableString = void 0;
2727
+ (function (TranslatableString) {
2728
+ /** Fallback title of an array item, used by ArrayField */
2729
+ TranslatableString["ArrayItemTitle"] = "Item";
2730
+ /** Missing items reason, used by ArrayField */
2731
+ TranslatableString["MissingItems"] = "Missing items definition";
2732
+ /** Yes label, used by BooleanField */
2733
+ TranslatableString["YesLabel"] = "Yes";
2734
+ /** No label, used by BooleanField */
2735
+ TranslatableString["NoLabel"] = "No";
2736
+ /** Close label, used by ErrorList */
2737
+ TranslatableString["CloseLabel"] = "Close";
2738
+ /** Errors label, used by ErrorList */
2739
+ TranslatableString["ErrorsLabel"] = "Errors";
2740
+ /** New additionalProperties string default value, used by ObjectField */
2741
+ TranslatableString["NewStringDefault"] = "New Value";
2742
+ /** Add button title, used by AddButton */
2743
+ TranslatableString["AddButton"] = "Add";
2744
+ /** Add button title, used by AddButton */
2745
+ TranslatableString["AddItemButton"] = "Add Item";
2746
+ /** Move down button title, used by IconButton */
2747
+ TranslatableString["MoveDownButton"] = "Move down";
2748
+ /** Move up button title, used by IconButton */
2749
+ TranslatableString["MoveUpButton"] = "Move up";
2750
+ /** Remove button title, used by IconButton */
2751
+ TranslatableString["RemoveButton"] = "Remove";
2752
+ /** Now label, used by AltDateWidget */
2753
+ TranslatableString["NowLabel"] = "Now";
2754
+ /** Clear label, used by AltDateWidget */
2755
+ TranslatableString["ClearLabel"] = "Clear";
2756
+ /** Aria date label, used by DateWidget */
2757
+ TranslatableString["AriaDateLabel"] = "Select a date";
2758
+ /** Decrement button aria label, used by UpDownWidget */
2759
+ TranslatableString["DecrementAriaLabel"] = "Decrease value by 1";
2760
+ /** Increment button aria label, used by UpDownWidget */
2761
+ TranslatableString["IncrementAriaLabel"] = "Increase value by 1";
2762
+ // Strings with replaceable parameters
2763
+ /** Unknown field type reason, where %1 will be replaced with the type as provided by SchemaField */
2764
+ TranslatableString["UnknownFieldType"] = "Unknown field type %1";
2765
+ /** Option prefix, where %1 will be replaced with the option index as provided by MultiSchemaField */
2766
+ TranslatableString["OptionPrefix"] = "Option %1";
2767
+ /** Option prefix, where %1 and %2 will be replaced by the schema title and option index, respectively as provided by
2768
+ * MultiSchemaField
2769
+ */
2770
+ TranslatableString["TitleOptionPrefix"] = "%1 option %2";
2771
+ /** Key label, where %1 will be replaced by the label as provided by WrapIfAdditionalTemplate */
2772
+ TranslatableString["KeyLabel"] = "%1 Key";
2773
+ // Strings with replaceable parameters AND/OR that support markdown and html
2774
+ /** Unsupported field schema, used by UnsupportedField */
2775
+ TranslatableString["UnsupportedField"] = "Unsupported field schema.";
2776
+ /** Unsupported field schema, where %1 will be replaced by the idSchema.$id as provided by UnsupportedField */
2777
+ TranslatableString["UnsupportedFieldWithId"] = "Unsupported field schema for field <code>%1</code>.";
2778
+ /** Unsupported field schema, where %1 will be replaced by the reason string as provided by UnsupportedField */
2779
+ TranslatableString["UnsupportedFieldWithReason"] = "Unsupported field schema: <em>%1</em>.";
2780
+ /** Unsupported field schema, where %1 and %2 will be replaced by the idSchema.$id and reason strings, respectively,
2781
+ * as provided by UnsupportedField
2782
+ */
2783
+ TranslatableString["UnsupportedFieldWithIdAndReason"] = "Unsupported field schema for field <code>%1</code>: <em>%2</em>.";
2784
+ /** File name, type and size info, where %1, %2 and %3 will be replaced by the file name, file type and file size as
2785
+ * provided by FileWidget
2786
+ */
2787
+ TranslatableString["FilesInfo"] = "<strong>%1</strong> (%2, %3 bytes)";
2788
+ })(exports.TranslatableString || (exports.TranslatableString = {}));
2789
+
2690
2790
  exports.ADDITIONAL_PROPERTIES_KEY = ADDITIONAL_PROPERTIES_KEY;
2691
2791
  exports.ADDITIONAL_PROPERTY_FLAG = ADDITIONAL_PROPERTY_FLAG;
2692
2792
  exports.ALL_OF_KEY = ALL_OF_KEY;
@@ -2718,6 +2818,7 @@ exports.createSchemaUtils = createSchemaUtils;
2718
2818
  exports.dataURItoBlob = dataURItoBlob;
2719
2819
  exports.deepEquals = deepEquals;
2720
2820
  exports.descriptionId = descriptionId;
2821
+ exports.englishStringTranslator = englishStringTranslator;
2721
2822
  exports.enumOptionsDeselectValue = enumOptionsDeselectValue;
2722
2823
  exports.enumOptionsIndexForValue = enumOptionsIndexForValue;
2723
2824
  exports.enumOptionsIsSelected = enumOptionsIsSelected;
@@ -2758,6 +2859,7 @@ exports.orderProperties = orderProperties;
2758
2859
  exports.pad = pad;
2759
2860
  exports.parseDateString = parseDateString;
2760
2861
  exports.rangeSpec = rangeSpec;
2862
+ exports.replaceStringParameters = replaceStringParameters;
2761
2863
  exports.retrieveSchema = retrieveSchema;
2762
2864
  exports.sanitizeDataForNewSchema = sanitizeDataForNewSchema;
2763
2865
  exports.schemaRequiresTrueValue = schemaRequiresTrueValue;