@rjsf/utils 5.0.2 → 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 +96 -5
- package/dist/utils.cjs.development.js +162 -21
- package/dist/utils.cjs.development.js.map +1 -1
- package/dist/utils.cjs.production.min.js +1 -1
- package/dist/utils.cjs.production.min.js.map +1 -1
- package/dist/utils.esm.js +161 -22
- package/dist/utils.esm.js.map +1 -1
- package/dist/utils.umd.development.js +162 -21
- package/dist/utils.umd.development.js.map +1 -1
- package/dist/utils.umd.production.min.js +1 -1
- package/dist/utils.umd.production.min.js.map +1 -1
- package/package.json +5 -5
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">> {
|
|
@@ -776,8 +847,8 @@ interface SchemaUtilsType<T = any, S extends StrictRJSFSchema = RJSFSchema, F ex
|
|
|
776
847
|
* @param schema - The schema for which the default state is desired
|
|
777
848
|
* @param [formData] - The current formData, if any, onto which to provide any missing defaults
|
|
778
849
|
* @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults.
|
|
779
|
-
* If "excludeObjectChildren",
|
|
780
|
-
* object properties.
|
|
850
|
+
* If "excludeObjectChildren", cause undefined values for this object and pass `includeUndefinedValues` as
|
|
851
|
+
* false when computing defaults for any nested object properties.
|
|
781
852
|
* @returns - The resulting `formData` with all the defaults provided
|
|
782
853
|
*/
|
|
783
854
|
getDefaultFormState(schema: S, formData?: T, includeUndefinedValues?: boolean | "excludeObjectChildren"): T | T[] | undefined;
|
|
@@ -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]`
|
|
@@ -1406,8 +1497,8 @@ declare const UI_OPTIONS_KEY = "ui:options";
|
|
|
1406
1497
|
* @param [formData] - The current formData, if any, onto which to provide any missing defaults
|
|
1407
1498
|
* @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
|
|
1408
1499
|
* @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults.
|
|
1409
|
-
* If "excludeObjectChildren",
|
|
1410
|
-
* object properties.
|
|
1500
|
+
* If "excludeObjectChildren", cause undefined values for this object and pass `includeUndefinedValues` as
|
|
1501
|
+
* false when computing defaults for any nested object properties.
|
|
1411
1502
|
* @returns - The resulting `formData` with all the defaults provided
|
|
1412
1503
|
*/
|
|
1413
1504
|
declare function getDefaultFormState<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, theSchema: S, formData?: T, rootSchema?: S, includeUndefinedValues?: boolean | "excludeObjectChildren"): T | T[] | undefined;
|
|
@@ -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 };
|
|
@@ -1095,17 +1095,48 @@ function getInnerSchemaForArrayItem(schema, additionalItems, idx) {
|
|
|
1095
1095
|
}
|
|
1096
1096
|
return {};
|
|
1097
1097
|
}
|
|
1098
|
+
/** Either add `computedDefault` at `key` into `obj` or not add it based on its value and the value of
|
|
1099
|
+
* `includeUndefinedValues`. Generally undefined `computedDefault` values are added only when `includeUndefinedValues`
|
|
1100
|
+
* is either true or "excludeObjectChildren". If `includeUndefinedValues` is false, then non-undefined and
|
|
1101
|
+
* non-empty-object values will be added.
|
|
1102
|
+
*
|
|
1103
|
+
* @param obj - The object into which the computed default may be added
|
|
1104
|
+
* @param key - The key into the object at which the computed default may be added
|
|
1105
|
+
* @param computedDefault - The computed default value that maybe should be added to the obj
|
|
1106
|
+
* @param includeUndefinedValues - Optional flag, if true, cause undefined values to be added as defaults.
|
|
1107
|
+
* If "excludeObjectChildren", cause undefined values for this object and pass `includeUndefinedValues` as
|
|
1108
|
+
* false when computing defaults for any nested object properties. If "allowEmptyObject", prevents undefined
|
|
1109
|
+
* values in this object while allow the object itself to be empty and passing `includeUndefinedValues` as
|
|
1110
|
+
* false when computing defaults for any nested object properties.
|
|
1111
|
+
* @param requiredFields - The list of fields that are required
|
|
1112
|
+
*/
|
|
1113
|
+
function maybeAddDefaultToObject(obj, key, computedDefault, includeUndefinedValues, requiredFields) {
|
|
1114
|
+
if (requiredFields === void 0) {
|
|
1115
|
+
requiredFields = [];
|
|
1116
|
+
}
|
|
1117
|
+
if (includeUndefinedValues) {
|
|
1118
|
+
obj[key] = computedDefault;
|
|
1119
|
+
} else if (isObject(computedDefault)) {
|
|
1120
|
+
// Store computedDefault if it's a non-empty object (e.g. not {})
|
|
1121
|
+
if (!isEmpty__default["default"](computedDefault) || requiredFields.includes(key)) {
|
|
1122
|
+
obj[key] = computedDefault;
|
|
1123
|
+
}
|
|
1124
|
+
} else if (computedDefault !== undefined) {
|
|
1125
|
+
// Store computedDefault if it's a defined primitive (e.g. true)
|
|
1126
|
+
obj[key] = computedDefault;
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1098
1129
|
/** Computes the defaults for the current `schema` given the `rawFormData` and `parentDefaults` if any. This drills into
|
|
1099
1130
|
* each level of the schema, recursively, to fill out every level of defaults provided by the schema.
|
|
1100
1131
|
*
|
|
1101
1132
|
* @param validator - an implementation of the `ValidatorType` interface that will be used when necessary
|
|
1102
|
-
* @param
|
|
1133
|
+
* @param rawSchema - The schema for which the default state is desired
|
|
1103
1134
|
* @param [parentDefaults] - Any defaults provided by the parent field in the schema
|
|
1104
1135
|
* @param [rootSchema] - The options root schema, used to primarily to look up `$ref`s
|
|
1105
1136
|
* @param [rawFormData] - The current formData, if any, onto which to provide any missing defaults
|
|
1106
1137
|
* @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults.
|
|
1107
|
-
* If "excludeObjectChildren",
|
|
1108
|
-
* object properties.
|
|
1138
|
+
* If "excludeObjectChildren", cause undefined values for this object and pass `includeUndefinedValues` as
|
|
1139
|
+
* false when computing defaults for any nested object properties.
|
|
1109
1140
|
* @returns - The resulting `formData` with all the defaults provided
|
|
1110
1141
|
*/
|
|
1111
1142
|
function computeDefaults(validator, rawSchema, parentDefaults, rootSchema, rawFormData, includeUndefinedValues) {
|
|
@@ -1137,8 +1168,14 @@ function computeDefaults(validator, rawSchema, parentDefaults, rootSchema, rawFo
|
|
|
1137
1168
|
return computeDefaults(validator, itemSchema, Array.isArray(parentDefaults) ? parentDefaults[idx] : undefined, rootSchema, formData, includeUndefinedValues);
|
|
1138
1169
|
});
|
|
1139
1170
|
} else if (ONE_OF_KEY in schema) {
|
|
1171
|
+
if (schema.oneOf.length === 0) {
|
|
1172
|
+
return undefined;
|
|
1173
|
+
}
|
|
1140
1174
|
schema = schema.oneOf[getClosestMatchingOption(validator, rootSchema, isEmpty__default["default"](formData) ? undefined : formData, schema.oneOf, 0)];
|
|
1141
1175
|
} else if (ANY_OF_KEY in schema) {
|
|
1176
|
+
if (schema.anyOf.length === 0) {
|
|
1177
|
+
return undefined;
|
|
1178
|
+
}
|
|
1142
1179
|
schema = schema.anyOf[getClosestMatchingOption(validator, rootSchema, isEmpty__default["default"](formData) ? undefined : formData, schema.anyOf, 0)];
|
|
1143
1180
|
}
|
|
1144
1181
|
// Not defaults defined for this node, fallback to generic typed ones.
|
|
@@ -1148,23 +1185,25 @@ function computeDefaults(validator, rawSchema, parentDefaults, rootSchema, rawFo
|
|
|
1148
1185
|
switch (getSchemaType(schema)) {
|
|
1149
1186
|
// We need to recur for object schema inner default values.
|
|
1150
1187
|
case "object":
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
acc
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1188
|
+
{
|
|
1189
|
+
var objectDefaults = Object.keys(schema.properties || {}).reduce(function (acc, key) {
|
|
1190
|
+
// Compute the defaults for this node, with the parent defaults we might
|
|
1191
|
+
// have from a previous run: defaults[key].
|
|
1192
|
+
var computedDefault = computeDefaults(validator, get__default["default"](schema, [PROPERTIES_KEY, key]), get__default["default"](defaults, [key]), rootSchema, get__default["default"](formData, [key]), includeUndefinedValues === true);
|
|
1193
|
+
maybeAddDefaultToObject(acc, key, computedDefault, includeUndefinedValues, schema.required);
|
|
1194
|
+
return acc;
|
|
1195
|
+
}, {});
|
|
1196
|
+
if (schema.additionalProperties && isObject(defaults)) {
|
|
1197
|
+
var additionalPropertiesSchema = isObject(schema.additionalProperties) ? schema.additionalProperties : {}; // as per spec additionalProperties may be either schema or boolean
|
|
1198
|
+
Object.keys(defaults).filter(function (key) {
|
|
1199
|
+
return !schema.properties || !schema.properties[key];
|
|
1200
|
+
}).forEach(function (key) {
|
|
1201
|
+
var computedDefault = computeDefaults(validator, additionalPropertiesSchema, get__default["default"](defaults, [key]), rootSchema, get__default["default"](formData, [key]), includeUndefinedValues === true);
|
|
1202
|
+
maybeAddDefaultToObject(objectDefaults, key, computedDefault, includeUndefinedValues);
|
|
1203
|
+
});
|
|
1165
1204
|
}
|
|
1166
|
-
return
|
|
1167
|
-
}
|
|
1205
|
+
return objectDefaults;
|
|
1206
|
+
}
|
|
1168
1207
|
case "array":
|
|
1169
1208
|
// Inject defaults into existing array defaults
|
|
1170
1209
|
if (Array.isArray(defaults)) {
|
|
@@ -1206,8 +1245,8 @@ function computeDefaults(validator, rawSchema, parentDefaults, rootSchema, rawFo
|
|
|
1206
1245
|
* @param [formData] - The current formData, if any, onto which to provide any missing defaults
|
|
1207
1246
|
* @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
|
|
1208
1247
|
* @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults.
|
|
1209
|
-
* If "excludeObjectChildren",
|
|
1210
|
-
* object properties.
|
|
1248
|
+
* If "excludeObjectChildren", cause undefined values for this object and pass `includeUndefinedValues` as
|
|
1249
|
+
* false when computing defaults for any nested object properties.
|
|
1211
1250
|
* @returns - The resulting `formData` with all the defaults provided
|
|
1212
1251
|
*/
|
|
1213
1252
|
function getDefaultFormState(validator, theSchema, formData, rootSchema, includeUndefinedValues) {
|
|
@@ -1829,6 +1868,36 @@ function dataURItoBlob(dataURI) {
|
|
|
1829
1868
|
};
|
|
1830
1869
|
}
|
|
1831
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
|
+
|
|
1832
1901
|
/** Returns the value(s) from `allEnumOptions` at the index(es) provided by `valueIndex`. If `valueIndex` is not an
|
|
1833
1902
|
* array AND the index is not valid for `allEnumOptions`, `emptyValue` is returned. If `valueIndex` is an array, AND it
|
|
1834
1903
|
* contains an invalid index, the returned array will have the resulting undefined values filtered out, leaving only
|
|
@@ -2648,6 +2717,76 @@ function utcToLocal(jsonDate) {
|
|
|
2648
2717
|
return yyyy + "-" + MM + "-" + dd + "T" + hh + ":" + mm + ":" + ss + "." + SSS;
|
|
2649
2718
|
}
|
|
2650
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
|
+
|
|
2651
2790
|
exports.ADDITIONAL_PROPERTIES_KEY = ADDITIONAL_PROPERTIES_KEY;
|
|
2652
2791
|
exports.ADDITIONAL_PROPERTY_FLAG = ADDITIONAL_PROPERTY_FLAG;
|
|
2653
2792
|
exports.ALL_OF_KEY = ALL_OF_KEY;
|
|
@@ -2679,6 +2818,7 @@ exports.createSchemaUtils = createSchemaUtils;
|
|
|
2679
2818
|
exports.dataURItoBlob = dataURItoBlob;
|
|
2680
2819
|
exports.deepEquals = deepEquals;
|
|
2681
2820
|
exports.descriptionId = descriptionId;
|
|
2821
|
+
exports.englishStringTranslator = englishStringTranslator;
|
|
2682
2822
|
exports.enumOptionsDeselectValue = enumOptionsDeselectValue;
|
|
2683
2823
|
exports.enumOptionsIndexForValue = enumOptionsIndexForValue;
|
|
2684
2824
|
exports.enumOptionsIsSelected = enumOptionsIsSelected;
|
|
@@ -2719,6 +2859,7 @@ exports.orderProperties = orderProperties;
|
|
|
2719
2859
|
exports.pad = pad;
|
|
2720
2860
|
exports.parseDateString = parseDateString;
|
|
2721
2861
|
exports.rangeSpec = rangeSpec;
|
|
2862
|
+
exports.replaceStringParameters = replaceStringParameters;
|
|
2722
2863
|
exports.retrieveSchema = retrieveSchema;
|
|
2723
2864
|
exports.sanitizeDataForNewSchema = sanitizeDataForNewSchema;
|
|
2724
2865
|
exports.schemaRequiresTrueValue = schemaRequiresTrueValue;
|