@rjsf/utils 6.6.1 → 6.7.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/LICENSE.md +201 -0
- package/dist/index.cjs +534 -376
- package/dist/index.cjs.map +4 -4
- package/dist/utils.esm.js +534 -376
- package/dist/utils.esm.js.map +4 -4
- package/dist/utils.umd.js +561 -400
- package/lib/ErrorSchemaBuilder.d.ts +1 -1
- package/lib/SelectedOptionDescription.d.ts +4 -0
- package/lib/SelectedOptionDescription.js +24 -0
- package/lib/SelectedOptionDescription.js.map +1 -0
- package/lib/allowAdditionalItems.d.ts +1 -1
- package/lib/allowAdditionalItems.js +1 -0
- package/lib/allowAdditionalItems.js.map +1 -1
- package/lib/asNumber.js +2 -0
- package/lib/asNumber.js.map +1 -1
- package/lib/canExpand.d.ts +1 -1
- package/lib/constIsAjvDataReference.d.ts +1 -1
- package/lib/constants.d.ts +8 -5
- package/lib/constants.js +10 -7
- package/lib/constants.js.map +1 -1
- package/lib/createErrorHandler.d.ts +1 -1
- package/lib/createErrorHandler.js +2 -6
- package/lib/createErrorHandler.js.map +1 -1
- package/lib/createSchemaUtils.d.ts +1 -1
- package/lib/createSchemaUtils.js +3 -1
- package/lib/createSchemaUtils.js.map +1 -1
- package/lib/dataURItoBlob.js +3 -3
- package/lib/dataURItoBlob.js.map +1 -1
- package/lib/dateRangeOptions.d.ts +1 -1
- package/lib/dateRangeOptions.js +8 -7
- package/lib/dateRangeOptions.js.map +1 -1
- package/lib/englishStringTranslator.d.ts +1 -1
- package/lib/enumOptionSelectedValue.d.ts +1 -1
- package/lib/enumOptionValueDecoder.d.ts +1 -1
- package/lib/enumOptionValueDecoder.js +1 -1
- package/lib/enumOptionValueDecoder.js.map +1 -1
- package/lib/enumOptionValueEncoder.d.ts +1 -1
- package/lib/enumOptionsDeselectValue.d.ts +1 -1
- package/lib/enumOptionsIndexForValue.d.ts +1 -1
- package/lib/enumOptionsIndexForValue.js.map +1 -1
- package/lib/enumOptionsIsSelected.d.ts +1 -1
- package/lib/enumOptionsSelectValue.d.ts +1 -1
- package/lib/enumOptionsValueForIndex.d.ts +2 -2
- package/lib/enumOptionsValueForIndex.js.map +1 -1
- package/lib/enums.d.ts +4 -0
- package/lib/enums.js +4 -0
- package/lib/enums.js.map +1 -1
- package/lib/findSchemaDefinition.d.ts +1 -1
- package/lib/findSchemaDefinition.js +15 -15
- package/lib/findSchemaDefinition.js.map +1 -1
- package/lib/getChangedFields.js +4 -6
- package/lib/getChangedFields.js.map +1 -1
- package/lib/getDateElementProps.d.ts +3 -3
- package/lib/getDiscriminatorFieldFromSchema.d.ts +1 -1
- package/lib/getDiscriminatorFieldFromSchema.js +1 -0
- package/lib/getDiscriminatorFieldFromSchema.js.map +1 -1
- package/lib/getInputProps.d.ts +1 -1
- package/lib/getOptionMatchingSimpleDiscriminator.d.ts +1 -1
- package/lib/getOptionMatchingSimpleDiscriminator.js +10 -11
- package/lib/getOptionMatchingSimpleDiscriminator.js.map +1 -1
- package/lib/getOptionValueFormat.d.ts +1 -1
- package/lib/getSchemaType.d.ts +1 -1
- package/lib/getSchemaType.js +2 -1
- package/lib/getSchemaType.js.map +1 -1
- package/lib/getSubmitButtonOptions.d.ts +1 -1
- package/lib/getSubmitButtonOptions.js +1 -1
- package/lib/getSubmitButtonOptions.js.map +1 -1
- package/lib/getTemplate.d.ts +1 -1
- package/lib/getTestIds.d.ts +1 -1
- package/lib/getUiOptions.d.ts +1 -1
- package/lib/getUiOptions.js +2 -1
- package/lib/getUiOptions.js.map +1 -1
- package/lib/getWidget.d.ts +1 -1
- package/lib/getWidget.js +4 -4
- package/lib/getWidget.js.map +1 -1
- package/lib/guessType.js +1 -1
- package/lib/guessType.js.map +1 -1
- package/lib/hasWidget.d.ts +1 -1
- package/lib/hashForSchema.d.ts +3 -1
- package/lib/hashForSchema.js +11 -4
- package/lib/hashForSchema.js.map +1 -1
- package/lib/idGenerators.d.ts +1 -1
- package/lib/index.d.ts +14 -7
- package/lib/index.js +5 -2
- package/lib/index.js.map +1 -1
- package/lib/isConstant.d.ts +1 -1
- package/lib/isCustomWidget.d.ts +1 -1
- package/lib/isCustomWidget.js +1 -1
- package/lib/isCustomWidget.js.map +1 -1
- package/lib/isFixedItems.d.ts +3 -3
- package/lib/isFixedItems.js +3 -3
- package/lib/isFixedItems.js.map +1 -1
- package/lib/isRootSchema.d.ts +1 -1
- package/lib/isRootSchema.js +2 -3
- package/lib/isRootSchema.js.map +1 -1
- package/lib/labelValue.d.ts +1 -1
- package/lib/logUnsupportedDefaultForEnum.d.ts +9 -0
- package/lib/logUnsupportedDefaultForEnum.js +18 -0
- package/lib/logUnsupportedDefaultForEnum.js.map +1 -0
- package/lib/lookupFromFormContext.d.ts +1 -1
- package/lib/mergeDefaultsWithFormData.js +6 -5
- package/lib/mergeDefaultsWithFormData.js.map +1 -1
- package/lib/mergeObjects.d.ts +4 -2
- package/lib/mergeObjects.js +1 -1
- package/lib/mergeObjects.js.map +1 -1
- package/lib/mergeSchemas.d.ts +4 -2
- package/lib/mergeSchemas.js +13 -6
- package/lib/mergeSchemas.js.map +1 -1
- package/lib/nameGenerators.d.ts +1 -1
- package/lib/optionsList.d.ts +1 -1
- package/lib/optionsList.js +22 -21
- package/lib/optionsList.js.map +1 -1
- package/lib/orderProperties.js +3 -3
- package/lib/orderProperties.js.map +1 -1
- package/lib/pad.js +1 -1
- package/lib/pad.js.map +1 -1
- package/lib/parseDateString.d.ts +1 -1
- package/lib/parseDateString.js +1 -1
- package/lib/parseDateString.js.map +1 -1
- package/lib/parser/ParserValidator.d.ts +2 -4
- package/lib/parser/ParserValidator.js +2 -0
- package/lib/parser/ParserValidator.js.map +1 -1
- package/lib/parser/index.d.ts +1 -1
- package/lib/parser/schemaParser.d.ts +2 -2
- package/lib/parser/schemaParser.js +7 -7
- package/lib/parser/schemaParser.js.map +1 -1
- package/lib/rangeSpec.d.ts +1 -2
- package/lib/rangeSpec.js.map +1 -1
- package/lib/removeOptionalEmptyObjects.d.ts +1 -1
- package/lib/removeOptionalEmptyObjects.js +6 -8
- package/lib/removeOptionalEmptyObjects.js.map +1 -1
- package/lib/resolveUiSchema.d.ts +1 -1
- package/lib/resolveUiSchema.js +16 -16
- package/lib/resolveUiSchema.js.map +1 -1
- package/lib/schema/findFieldInSchema.d.ts +1 -1
- package/lib/schema/findSelectedOptionInXxxOf.d.ts +1 -1
- package/lib/schema/findSelectedOptionInXxxOf.js +1 -3
- package/lib/schema/findSelectedOptionInXxxOf.js.map +1 -1
- package/lib/schema/getClosestMatchingOption.d.ts +1 -1
- package/lib/schema/getClosestMatchingOption.js +6 -9
- package/lib/schema/getClosestMatchingOption.js.map +1 -1
- package/lib/schema/getDefaultFormState.d.ts +4 -4
- package/lib/schema/getDefaultFormState.js +81 -43
- package/lib/schema/getDefaultFormState.js.map +1 -1
- package/lib/schema/getDisplayLabel.d.ts +1 -1
- package/lib/schema/getDisplayLabel.js +2 -3
- package/lib/schema/getDisplayLabel.js.map +1 -1
- package/lib/schema/getFirstMatchingOption.d.ts +1 -1
- package/lib/schema/getFirstMatchingOption.js +2 -2
- package/lib/schema/getFirstMatchingOption.js.map +1 -1
- package/lib/schema/getFromSchema.d.ts +1 -1
- package/lib/schema/index.js +9 -3
- package/lib/schema/index.js.map +1 -1
- package/lib/schema/isFilesArray.d.ts +1 -1
- package/lib/schema/isMultiSelect.d.ts +1 -1
- package/lib/schema/isMultiSelect.js.map +1 -1
- package/lib/schema/isSelect.d.ts +1 -1
- package/lib/schema/isSelect.js +1 -1
- package/lib/schema/isSelect.js.map +1 -1
- package/lib/schema/omitExtraData.d.ts +1 -1
- package/lib/schema/omitExtraData.js +66 -52
- package/lib/schema/omitExtraData.js.map +1 -1
- package/lib/schema/retrieveSchema.d.ts +7 -3
- package/lib/schema/retrieveSchema.js +83 -56
- package/lib/schema/retrieveSchema.js.map +1 -1
- package/lib/schema/sanitizeDataForNewSchema.d.ts +1 -1
- package/lib/schema/sanitizeDataForNewSchema.js +48 -7
- package/lib/schema/sanitizeDataForNewSchema.js.map +1 -1
- package/lib/schema/toPathSchema.d.ts +1 -1
- package/lib/schema/toPathSchema.js +9 -5
- package/lib/schema/toPathSchema.js.map +1 -1
- package/lib/schemaRequiresTrueValue.d.ts +1 -1
- package/lib/schemaRequiresTrueValue.js +4 -3
- package/lib/schemaRequiresTrueValue.js.map +1 -1
- package/lib/shallowEquals.js +2 -2
- package/lib/shallowEquals.js.map +1 -1
- package/lib/shouldRenderOptionalField.d.ts +1 -1
- package/lib/toConstant.d.ts +1 -1
- package/lib/toDateString.d.ts +1 -1
- package/lib/toErrorList.d.ts +1 -1
- package/lib/toErrorList.js +3 -3
- package/lib/toErrorList.js.map +1 -1
- package/lib/toErrorSchema.d.ts +1 -1
- package/lib/toFieldPathId.d.ts +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types.d.ts +63 -57
- package/lib/unwrapErrorHandler.d.ts +1 -1
- package/lib/unwrapErrorHandler.js +7 -9
- package/lib/unwrapErrorHandler.js.map +1 -1
- package/lib/useAltDateWidgetProps.d.ts +6 -6
- package/lib/useAltDateWidgetProps.js +3 -3
- package/lib/useAltDateWidgetProps.js.map +1 -1
- package/lib/useFileWidgetProps.d.ts +2 -2
- package/lib/useFileWidgetProps.js +3 -3
- package/lib/useFileWidgetProps.js.map +1 -1
- package/lib/validationDataMerge.d.ts +1 -1
- package/lib/withIdRefPrefix.d.ts +1 -1
- package/lib/withIdRefPrefix.js +12 -12
- package/lib/withIdRefPrefix.js.map +1 -1
- package/package.json +19 -19
- package/src/ErrorSchemaBuilder.ts +1 -1
- package/src/SelectedOptionDescription.tsx +48 -0
- package/src/allowAdditionalItems.ts +2 -1
- package/src/asNumber.ts +2 -0
- package/src/canExpand.ts +1 -1
- package/src/constIsAjvDataReference.ts +2 -2
- package/src/constants.ts +10 -7
- package/src/createErrorHandler.ts +6 -7
- package/src/createSchemaUtils.ts +4 -2
- package/src/dataURItoBlob.ts +3 -3
- package/src/dateRangeOptions.ts +9 -7
- package/src/englishStringTranslator.ts +1 -1
- package/src/enumOptionSelectedValue.ts +1 -1
- package/src/enumOptionValueDecoder.ts +2 -2
- package/src/enumOptionValueEncoder.ts +1 -1
- package/src/enumOptionsDeselectValue.ts +1 -1
- package/src/enumOptionsIndexForValue.ts +2 -2
- package/src/enumOptionsIsSelected.ts +1 -1
- package/src/enumOptionsSelectValue.ts +1 -1
- package/src/enumOptionsValueForIndex.ts +2 -2
- package/src/enums.ts +4 -0
- package/src/findSchemaDefinition.ts +18 -17
- package/src/getChangedFields.ts +5 -5
- package/src/getDateElementProps.ts +3 -3
- package/src/getDiscriminatorFieldFromSchema.ts +2 -1
- package/src/getInputProps.ts +1 -1
- package/src/getOptionMatchingSimpleDiscriminator.ts +11 -15
- package/src/getOptionValueFormat.ts +1 -1
- package/src/getSchemaType.ts +3 -2
- package/src/getSubmitButtonOptions.ts +3 -3
- package/src/getTemplate.ts +1 -1
- package/src/getTestIds.ts +1 -1
- package/src/getUiOptions.ts +10 -2
- package/src/getWidget.tsx +5 -6
- package/src/guessType.ts +1 -1
- package/src/hasWidget.ts +1 -1
- package/src/hashForSchema.ts +12 -5
- package/src/idGenerators.ts +1 -1
- package/src/index.ts +16 -5
- package/src/isConstant.ts +1 -1
- package/src/isCustomWidget.ts +2 -2
- package/src/isFixedItems.ts +4 -4
- package/src/isRootSchema.ts +3 -5
- package/src/labelValue.ts +1 -1
- package/src/logUnsupportedDefaultForEnum.ts +28 -0
- package/src/lookupFromFormContext.ts +1 -1
- package/src/mergeDefaultsWithFormData.ts +8 -7
- package/src/mergeObjects.ts +2 -2
- package/src/mergeSchemas.ts +14 -7
- package/src/nameGenerators.ts +1 -1
- package/src/optionsList.ts +21 -23
- package/src/orderProperties.ts +4 -4
- package/src/pad.ts +1 -1
- package/src/parseDateString.ts +2 -2
- package/src/parser/ParserValidator.ts +4 -4
- package/src/parser/index.ts +1 -1
- package/src/parser/schemaParser.ts +10 -9
- package/src/rangeSpec.ts +1 -2
- package/src/removeOptionalEmptyObjects.ts +8 -11
- package/src/resolveUiSchema.ts +32 -25
- package/src/schema/findFieldInSchema.ts +1 -1
- package/src/schema/findSelectedOptionInXxxOf.ts +17 -7
- package/src/schema/getClosestMatchingOption.ts +17 -11
- package/src/schema/getDefaultFormState.ts +104 -43
- package/src/schema/getDisplayLabel.ts +4 -5
- package/src/schema/getFirstMatchingOption.ts +3 -3
- package/src/schema/getFromSchema.ts +1 -1
- package/src/schema/index.ts +3 -0
- package/src/schema/isFilesArray.ts +1 -1
- package/src/schema/isMultiSelect.ts +7 -1
- package/src/schema/isSelect.ts +8 -2
- package/src/schema/omitExtraData.ts +73 -60
- package/src/schema/retrieveSchema.ts +131 -83
- package/src/schema/sanitizeDataForNewSchema.ts +57 -8
- package/src/schema/toPathSchema.ts +11 -7
- package/src/schemaRequiresTrueValue.ts +4 -4
- package/src/shallowEquals.ts +2 -2
- package/src/shouldRenderOptionalField.ts +1 -1
- package/src/toConstant.ts +1 -1
- package/src/toDateString.ts +1 -1
- package/src/toErrorList.ts +4 -4
- package/src/toErrorSchema.ts +1 -1
- package/src/toFieldPathId.ts +1 -1
- package/src/types.ts +92 -63
- package/src/unwrapErrorHandler.ts +11 -12
- package/src/useAltDateWidgetProps.tsx +10 -8
- package/src/useFileWidgetProps.ts +7 -7
- package/src/validationDataMerge.ts +1 -1
- package/src/withIdRefPrefix.ts +12 -12
package/src/shallowEquals.ts
CHANGED
|
@@ -30,9 +30,9 @@ export default function shallowEquals(a: any, b: any): boolean {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
// Check if all keys and values are equal
|
|
33
|
-
for (let i = 0; i < keysA.length; i
|
|
33
|
+
for (let i = 0; i < keysA.length; i += 1) {
|
|
34
34
|
const key = keysA[i];
|
|
35
|
-
if (!Object.
|
|
35
|
+
if (!Object.hasOwn(b, key) || !Object.is(a[key], b[key])) {
|
|
36
36
|
return false;
|
|
37
37
|
}
|
|
38
38
|
}
|
|
@@ -5,7 +5,7 @@ import { ANY_OF_KEY, ONE_OF_KEY } from './constants';
|
|
|
5
5
|
import getSchemaType from './getSchemaType';
|
|
6
6
|
import getUiOptions from './getUiOptions';
|
|
7
7
|
import isRootSchema from './isRootSchema';
|
|
8
|
-
import { FormContextType, Registry, RJSFSchema, StrictRJSFSchema, UiSchema } from './types';
|
|
8
|
+
import type { FormContextType, Registry, RJSFSchema, StrictRJSFSchema, UiSchema } from './types';
|
|
9
9
|
|
|
10
10
|
/** Returns the unique list of schema types for all of the options in a anyOf/oneOf
|
|
11
11
|
*
|
package/src/toConstant.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CONST_KEY, ENUM_KEY } from './constants';
|
|
2
|
-
import { RJSFSchema, StrictRJSFSchema } from './types';
|
|
2
|
+
import type { RJSFSchema, StrictRJSFSchema } from './types';
|
|
3
3
|
|
|
4
4
|
/** Returns the constant value from the schema when it is either a single value enum or has a const key. Otherwise
|
|
5
5
|
* throws an error.
|
package/src/toDateString.ts
CHANGED
package/src/toErrorList.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import isPlainObject from 'lodash/isPlainObject';
|
|
2
2
|
|
|
3
3
|
import { ERRORS_KEY } from './constants';
|
|
4
|
-
import { ErrorSchema, GenericObjectType, RJSFValidationError } from './types';
|
|
4
|
+
import type { ErrorSchema, GenericObjectType, RJSFValidationError } from './types';
|
|
5
5
|
|
|
6
6
|
/** Converts an `errorSchema` into a list of `RJSFValidationErrors`
|
|
7
7
|
*
|
|
@@ -29,13 +29,13 @@ export default function toErrorList<T = any>(
|
|
|
29
29
|
}),
|
|
30
30
|
);
|
|
31
31
|
}
|
|
32
|
-
return Object.keys(errorSchema).reduce((
|
|
32
|
+
return Object.keys(errorSchema).reduce((currentList, key) => {
|
|
33
33
|
if (key !== ERRORS_KEY) {
|
|
34
34
|
const childSchema = (errorSchema as GenericObjectType)[key];
|
|
35
35
|
if (isPlainObject(childSchema)) {
|
|
36
|
-
|
|
36
|
+
return currentList.concat(toErrorList(childSchema, [...fieldPath, key]));
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
return
|
|
39
|
+
return currentList;
|
|
40
40
|
}, errorList);
|
|
41
41
|
}
|
package/src/toErrorSchema.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import toPath from 'lodash/toPath';
|
|
2
2
|
|
|
3
3
|
import ErrorSchemaBuilder from './ErrorSchemaBuilder';
|
|
4
|
-
import { ErrorSchema, RJSFValidationError } from './types';
|
|
4
|
+
import type { ErrorSchema, RJSFValidationError } from './types';
|
|
5
5
|
|
|
6
6
|
/** Transforms a rjsf validation errors list:
|
|
7
7
|
* [
|
package/src/toFieldPathId.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ID_KEY } from './constants';
|
|
2
|
-
import { FieldPathId, FieldPathList, GlobalFormOptions } from './types';
|
|
2
|
+
import type { FieldPathId, FieldPathList, GlobalFormOptions } from './types';
|
|
3
3
|
|
|
4
4
|
/** Constructs the `FieldPathId` for `fieldPath`. If `parentPathId` is provided, the `fieldPath` is appended to the end
|
|
5
5
|
* of the parent path. Then the `ID_KEY` of the resulting `FieldPathId` is constructed from the `idPrefix` and
|
package/src/types.ts
CHANGED
|
@@ -8,17 +8,20 @@ import type {
|
|
|
8
8
|
ReactNode,
|
|
9
9
|
StyleHTMLAttributes,
|
|
10
10
|
} from 'react';
|
|
11
|
-
import { JSONSchema7 } from 'json-schema';
|
|
11
|
+
import type { JSONSchema7 } from 'json-schema';
|
|
12
12
|
|
|
13
|
-
import { TranslatableString } from './enums';
|
|
13
|
+
import type { TranslatableString } from './enums';
|
|
14
14
|
import './jsonSchemaAugmentation';
|
|
15
15
|
|
|
16
16
|
/** The representation of any generic object type, usually used as an intersection on other types to make them more
|
|
17
17
|
* flexible in the properties they support (i.e. anything else)
|
|
18
18
|
*/
|
|
19
|
-
export type GenericObjectType =
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
export type GenericObjectType = Record<string, any>;
|
|
20
|
+
|
|
21
|
+
/** The representation of any generic object type, usually used as an intersection on other types to make them more
|
|
22
|
+
* flexible in the properties they support (i.e. anything else) AND symbol markers with a value of string or boolean
|
|
23
|
+
*/
|
|
24
|
+
export type GenericSymbolObjectType = GenericObjectType & Record<symbol, boolean | string>;
|
|
22
25
|
|
|
23
26
|
/** Map the JSONSchema7 to our own type so that we can easily bump to a more recent version at some future date and only
|
|
24
27
|
* have to update this one type.
|
|
@@ -29,6 +32,11 @@ export type StrictRJSFSchema = JSONSchema7;
|
|
|
29
32
|
*/
|
|
30
33
|
export type RJSFSchema = StrictRJSFSchema & GenericObjectType;
|
|
31
34
|
|
|
35
|
+
/** Allow for more flexible schemas (i.e. draft-2019) than the strict JSONSchema7 with special marking added by
|
|
36
|
+
* `retrieveSchema()`
|
|
37
|
+
*/
|
|
38
|
+
export type RJSFMarkedSchema = StrictRJSFSchema & GenericSymbolObjectType;
|
|
39
|
+
|
|
32
40
|
/** Alias GenericObjectType as FormContextType to allow us to remap this at some future date
|
|
33
41
|
*/
|
|
34
42
|
export type FormContextType = GenericObjectType;
|
|
@@ -50,7 +58,7 @@ export type NameGeneratorFunction = (path: FieldPathList, idPrefix: string, isMu
|
|
|
50
58
|
|
|
51
59
|
/** Experimental feature that specifies the Array `minItems` default form state behavior
|
|
52
60
|
*/
|
|
53
|
-
export
|
|
61
|
+
export interface Experimental_ArrayMinItems {
|
|
54
62
|
/** Optional enumerated flag controlling how array minItems are populated, defaulting to `all`:
|
|
55
63
|
* - `all`: Legacy behavior, populate minItems entries with default values initially and include an empty array when
|
|
56
64
|
* no values have been defined.
|
|
@@ -79,14 +87,14 @@ export type Experimental_ArrayMinItems = {
|
|
|
79
87
|
* `formData` until the `minItems` condition is met.
|
|
80
88
|
*/
|
|
81
89
|
mergeExtraDefaults?: boolean;
|
|
82
|
-
}
|
|
90
|
+
}
|
|
83
91
|
|
|
84
92
|
/** Experimental features to specify different default form state behaviors. Currently, this affects the
|
|
85
93
|
* handling of optional array fields where `minItems` is set and handling of setting defaults based on the
|
|
86
94
|
* value of `emptyObjectFields`. It also affects how `allOf` fields are handled and how to handle merging defaults into
|
|
87
95
|
* the formData in relation to explicit `undefined` values via `mergeDefaultsIntoFormData`.
|
|
88
96
|
*/
|
|
89
|
-
export
|
|
97
|
+
export interface Experimental_DefaultFormStateBehavior {
|
|
90
98
|
/** Optional object, that controls how the default form state for arrays with `minItems` is handled. When not provided
|
|
91
99
|
* it defaults to `{ populate: 'all' }`.
|
|
92
100
|
*/
|
|
@@ -125,7 +133,13 @@ export type Experimental_DefaultFormStateBehavior = {
|
|
|
125
133
|
*
|
|
126
134
|
*/
|
|
127
135
|
constAsDefaults?: 'always' | 'skipOneOf' | 'never';
|
|
128
|
-
|
|
136
|
+
/** Optional enumerated flag controlling how defaults defined on multiple levels are merged together for overlapping
|
|
137
|
+
* properties, defaulting to `descendantWins`.
|
|
138
|
+
* - `descendantWins`: The innermost (descendant) default value definition takes precedence over its ancestor's defaults.
|
|
139
|
+
* - `ancestorWins`: The outermost (ancestor) default value definition takes precedence over any descendant's defaults.
|
|
140
|
+
*/
|
|
141
|
+
nestedDefaultsPrecedence?: 'descendantWins' | 'ancestorWins';
|
|
142
|
+
}
|
|
129
143
|
|
|
130
144
|
/** Optional function that allows for custom merging of `allOf` schemas
|
|
131
145
|
* @param schema - Schema with `allOf` that needs to be merged
|
|
@@ -150,17 +164,17 @@ export interface DateObject {
|
|
|
150
164
|
}
|
|
151
165
|
|
|
152
166
|
/** Properties describing a Range specification in terms of attribute that can be added to the `HTML` `<input>` */
|
|
153
|
-
export
|
|
167
|
+
export interface RangeSpecType {
|
|
154
168
|
/** Specifies the interval between legal numbers in an input field */
|
|
155
169
|
step?: number;
|
|
156
170
|
/** Specifies a minimum value for an <input> element */
|
|
157
171
|
min?: number;
|
|
158
172
|
/** Specifies the maximum value for an <input> element */
|
|
159
173
|
max?: number;
|
|
160
|
-
}
|
|
174
|
+
}
|
|
161
175
|
|
|
162
176
|
/** Properties describing a Range specification in terms of attribute that can be added to the `HTML` `<input>` */
|
|
163
|
-
export
|
|
177
|
+
export interface InputPropsType {
|
|
164
178
|
/** Specifies the type of the <input> element */
|
|
165
179
|
type: string;
|
|
166
180
|
/** Specifies the interval between legal numbers in an input field or "any" */
|
|
@@ -173,7 +187,7 @@ export type InputPropsType = {
|
|
|
173
187
|
autoComplete?: HTMLInputElement['autocomplete'];
|
|
174
188
|
/** Specifies a filter for what file types the user can upload. */
|
|
175
189
|
accept?: HTMLInputElement['accept'];
|
|
176
|
-
}
|
|
190
|
+
}
|
|
177
191
|
|
|
178
192
|
/** The list of path elements that represents where in the schema a field is located. When the item in the field list is
|
|
179
193
|
* a string, then it represents the name of the property within an object. When it is a number, then it represents the
|
|
@@ -190,38 +204,39 @@ export type FieldPathList = (string | number)[];
|
|
|
190
204
|
export type SchemaFieldPath = string | FieldPathList;
|
|
191
205
|
|
|
192
206
|
/** Type describing an id and path used for a field */
|
|
193
|
-
export
|
|
207
|
+
export interface FieldPathId {
|
|
194
208
|
/** The id for a field */
|
|
195
209
|
$id: string;
|
|
196
210
|
/** The path for a field */
|
|
197
211
|
path: FieldPathList;
|
|
198
212
|
/** The optional HTML name attribute for a field, generated by nameGenerator if provided */
|
|
199
213
|
name?: string;
|
|
200
|
-
}
|
|
214
|
+
}
|
|
201
215
|
|
|
202
216
|
/** Type describing a name used for a field in the `PathSchema` */
|
|
203
|
-
export
|
|
217
|
+
export interface FieldPath {
|
|
204
218
|
/** The name of a field */
|
|
205
219
|
$name: string;
|
|
206
|
-
}
|
|
220
|
+
}
|
|
207
221
|
|
|
208
222
|
/** Type describing a recursive structure of `FieldPath`s for an object with a non-empty set of keys
|
|
209
223
|
* @deprecated - To be removed as an exported `@rjsf/utils` type in a future release
|
|
210
224
|
*/
|
|
211
|
-
export type PathSchema<T = any> =
|
|
212
|
-
|
|
225
|
+
export type PathSchema<T = any> = T extends (infer U)[]
|
|
226
|
+
? FieldPath & {
|
|
227
|
+
// oxlint-disable-next-line typescript/no-deprecated
|
|
228
|
+
[i: number]: PathSchema<U>;
|
|
229
|
+
}
|
|
230
|
+
: T extends GenericObjectType
|
|
213
231
|
? FieldPath & {
|
|
214
|
-
|
|
232
|
+
/** The set of names for fields in the recursive object structure */
|
|
233
|
+
// oxlint-disable-next-line typescript/no-deprecated
|
|
234
|
+
[key in keyof T]?: PathSchema<T[key]>;
|
|
215
235
|
}
|
|
216
|
-
:
|
|
217
|
-
? FieldPath & {
|
|
218
|
-
/** The set of names for fields in the recursive object structure */
|
|
219
|
-
[key in keyof T]?: PathSchema<T[key]>;
|
|
220
|
-
}
|
|
221
|
-
: FieldPath;
|
|
236
|
+
: FieldPath;
|
|
222
237
|
|
|
223
238
|
/** The type for error produced by RJSF schema validation */
|
|
224
|
-
export
|
|
239
|
+
export interface RJSFValidationError {
|
|
225
240
|
/** Name of the error, for example, "required" or "minLength" */
|
|
226
241
|
name?: string;
|
|
227
242
|
/** Message, for example, "is a required property" or "should NOT be shorter than 3 characters" */
|
|
@@ -243,16 +258,16 @@ export type RJSFValidationError = {
|
|
|
243
258
|
stack: string;
|
|
244
259
|
/** The title property for the failing field*/
|
|
245
260
|
title?: string;
|
|
246
|
-
}
|
|
261
|
+
}
|
|
247
262
|
|
|
248
263
|
/** The type that describes an error in a field */
|
|
249
264
|
export type FieldError = string;
|
|
250
265
|
|
|
251
266
|
/** The type that describes the list of errors for a field */
|
|
252
|
-
export
|
|
267
|
+
export interface FieldErrors {
|
|
253
268
|
/** The list of errors for the field */
|
|
254
269
|
__errors?: FieldError[];
|
|
255
|
-
}
|
|
270
|
+
}
|
|
256
271
|
|
|
257
272
|
/** Type describing a recursive structure of `FieldErrors`s for an object with a non-empty set of keys */
|
|
258
273
|
export type ErrorSchema<T = any> = FieldErrors & {
|
|
@@ -273,13 +288,26 @@ export type FormValidation<T = any> = FieldValidation & {
|
|
|
273
288
|
};
|
|
274
289
|
|
|
275
290
|
/** The base properties passed to various RJSF components. */
|
|
276
|
-
export
|
|
291
|
+
export interface RJSFBaseProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> {
|
|
277
292
|
/** The schema object for the field being described */
|
|
278
293
|
schema: S;
|
|
279
294
|
/** The uiSchema object for this base component */
|
|
280
295
|
uiSchema?: UiSchema<T, S, F>;
|
|
281
296
|
/** The `registry` object */
|
|
282
297
|
registry: Registry<T, S, F>;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
export type CyclicSchemaExpandProps<
|
|
301
|
+
T = any,
|
|
302
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
303
|
+
F extends FormContextType = any,
|
|
304
|
+
> = RJSFBaseProps<T, S, F> & {
|
|
305
|
+
/** The FieldPathId of the field in the hierarchy */
|
|
306
|
+
fieldPathId: FieldPathId;
|
|
307
|
+
/** The unique name of the field, usually derived from the name of the property in the JSONSchema */
|
|
308
|
+
name: string;
|
|
309
|
+
/** Callback used to mark a cyclic scheme element as expanded */
|
|
310
|
+
onExpand: (id: string) => void;
|
|
283
311
|
};
|
|
284
312
|
|
|
285
313
|
/** The properties that are passed to an `ErrorListTemplate` implementation */
|
|
@@ -303,7 +331,7 @@ export type FieldErrorProps<
|
|
|
303
331
|
/** The errorSchema constructed by `Form` */
|
|
304
332
|
errorSchema?: ErrorSchema<T>;
|
|
305
333
|
/** An array of the errors */
|
|
306
|
-
errors?:
|
|
334
|
+
errors?: (string | ReactElement)[];
|
|
307
335
|
/** The FieldPathId of the field in the hierarchy */
|
|
308
336
|
fieldPathId: FieldPathId;
|
|
309
337
|
};
|
|
@@ -333,16 +361,18 @@ export interface GridTemplateProps extends GenericObjectType {
|
|
|
333
361
|
}
|
|
334
362
|
|
|
335
363
|
/** The set of `Fields` stored in the `Registry` */
|
|
336
|
-
export type RegistryFieldsType<
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
364
|
+
export type RegistryFieldsType<
|
|
365
|
+
T = any,
|
|
366
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
367
|
+
F extends FormContextType = any,
|
|
368
|
+
> = Record<string, Field<T, S, F>>;
|
|
340
369
|
|
|
341
370
|
/** The set of `Widgets` stored in the `Registry` */
|
|
342
|
-
export type RegistryWidgetsType<
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
371
|
+
export type RegistryWidgetsType<
|
|
372
|
+
T = any,
|
|
373
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
374
|
+
F extends FormContextType = any,
|
|
375
|
+
> = Record<string, Widget<T, S, F>>;
|
|
346
376
|
|
|
347
377
|
/** The set of RJSF templates that can be overridden by themes or users */
|
|
348
378
|
export type TemplatesType<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = {
|
|
@@ -358,6 +388,8 @@ export type TemplatesType<T = any, S extends StrictRJSFSchema = RJSFSchema, F ex
|
|
|
358
388
|
ArrayFieldTitleTemplate: ComponentType<ArrayFieldTitleProps<T, S, F>>;
|
|
359
389
|
/** The template to use while rendering the standard html input */
|
|
360
390
|
BaseInputTemplate: ComponentType<BaseInputTemplateProps<T, S, F>>;
|
|
391
|
+
/** The template to use while rendering the cyclic schema expand controls */
|
|
392
|
+
CyclicSchemaExpandTemplate: ComponentType<CyclicSchemaExpandProps<T, S, F>>;
|
|
361
393
|
/** The template to use for rendering the description of a field */
|
|
362
394
|
DescriptionFieldTemplate: ComponentType<DescriptionFieldProps<T, S, F>>;
|
|
363
395
|
/** The template to use while rendering the errors for the whole form */
|
|
@@ -401,10 +433,7 @@ export type TemplatesType<T = any, S extends StrictRJSFSchema = RJSFSchema, F ex
|
|
|
401
433
|
/** The template to use for the Clear button used for input fields */
|
|
402
434
|
ClearButton: ComponentType<IconButtonProps<T, S, F>>;
|
|
403
435
|
};
|
|
404
|
-
} &
|
|
405
|
-
/** Allow this to support any named `ComponentType` or an object of named `ComponentType`s */
|
|
406
|
-
[key: string]: ComponentType<any> | { [key: string]: ComponentType<any> } | undefined;
|
|
407
|
-
};
|
|
436
|
+
} & Record<string, ComponentType<any> | Record<string, ComponentType<any>> | undefined>;
|
|
408
437
|
|
|
409
438
|
/** The set of UiSchema options that can be set globally and used as fallbacks at an individual template, field or
|
|
410
439
|
* widget level when no field-level value of the option is provided. Extends GenericObjectType to support allowing users
|
|
@@ -464,7 +493,7 @@ export type GlobalUISchemaOptions = GenericObjectType & {
|
|
|
464
493
|
/** The set of options from the `Form` that will be available on the `Registry` for use in everywhere the `registry` is
|
|
465
494
|
* available.
|
|
466
495
|
*/
|
|
467
|
-
export
|
|
496
|
+
export interface GlobalFormOptions {
|
|
468
497
|
/** To avoid collisions with existing ids in the DOM, it is possible to change the prefix used for ids;
|
|
469
498
|
* Default is `root`. This prop is passed to the `toFilePathId()` function within the RJSF field implementations.
|
|
470
499
|
*/
|
|
@@ -485,7 +514,7 @@ export type GlobalFormOptions = {
|
|
|
485
514
|
* is not supported by RJSF or a custom field. When false, the UnsupportedField error component will be shown instead.
|
|
486
515
|
*/
|
|
487
516
|
readonly useFallbackUiForUnsupportedType?: boolean;
|
|
488
|
-
}
|
|
517
|
+
}
|
|
489
518
|
|
|
490
519
|
/** The object containing the registered core, theme and custom fields and widgets as well as the root schema, form
|
|
491
520
|
* context, schema utils and templates.
|
|
@@ -840,7 +869,7 @@ export type ArrayFieldTemplateProps<
|
|
|
840
869
|
};
|
|
841
870
|
|
|
842
871
|
/** The properties of each element in the ObjectFieldTemplateProps.properties array */
|
|
843
|
-
export
|
|
872
|
+
export interface ObjectFieldTemplatePropertyType {
|
|
844
873
|
/** The html for the property's content */
|
|
845
874
|
content: ReactElement;
|
|
846
875
|
/** A string representing the property name */
|
|
@@ -851,7 +880,7 @@ export type ObjectFieldTemplatePropertyType = {
|
|
|
851
880
|
readonly?: boolean;
|
|
852
881
|
/** A boolean value stating if the property should be hidden */
|
|
853
882
|
hidden: boolean;
|
|
854
|
-
}
|
|
883
|
+
}
|
|
855
884
|
|
|
856
885
|
/** The properties that are passed to an ObjectFieldTemplate implementation */
|
|
857
886
|
export type ObjectFieldTemplateProps<
|
|
@@ -1012,12 +1041,12 @@ export interface BaseInputTemplateProps<
|
|
|
1012
1041
|
}
|
|
1013
1042
|
|
|
1014
1043
|
/** The type that defines the props used by the Submit button */
|
|
1015
|
-
export
|
|
1044
|
+
export interface SubmitButtonProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> {
|
|
1016
1045
|
/** The uiSchema for this widget */
|
|
1017
1046
|
uiSchema?: UiSchema<T, S, F>;
|
|
1018
1047
|
/** The `registry` object */
|
|
1019
1048
|
registry: Registry<T, S, F>;
|
|
1020
|
-
}
|
|
1049
|
+
}
|
|
1021
1050
|
|
|
1022
1051
|
/** The type that defines the props for an Icon button, extending from a basic HTML button attributes */
|
|
1023
1052
|
export type IconButtonProps<
|
|
@@ -1033,7 +1062,7 @@ export type IconButtonProps<
|
|
|
1033
1062
|
};
|
|
1034
1063
|
|
|
1035
1064
|
/** The type that defines how to change the behavior of the submit button for the form */
|
|
1036
|
-
export
|
|
1065
|
+
export interface UISchemaSubmitButtonOptions {
|
|
1037
1066
|
/** The text of the submit button. Set to "Submit" by default */
|
|
1038
1067
|
submitText?: string;
|
|
1039
1068
|
/** Flag, if `true`, removes the submit button completely from the form */
|
|
@@ -1045,20 +1074,20 @@ export type UISchemaSubmitButtonOptions = {
|
|
|
1045
1074
|
/** The class name for the submit button */
|
|
1046
1075
|
className?: string;
|
|
1047
1076
|
};
|
|
1048
|
-
}
|
|
1077
|
+
}
|
|
1049
1078
|
|
|
1050
1079
|
/** Represents a primitive JSON Schema enum value */
|
|
1051
1080
|
export type EnumValue = string | number | boolean;
|
|
1052
1081
|
|
|
1053
1082
|
/** This type represents an element used to render an enum option */
|
|
1054
|
-
export
|
|
1083
|
+
export interface EnumOptionsType<S extends StrictRJSFSchema = RJSFSchema> {
|
|
1055
1084
|
/** The value for the enum option */
|
|
1056
1085
|
value: any;
|
|
1057
1086
|
/** The label for the enum options */
|
|
1058
1087
|
label: string;
|
|
1059
1088
|
/** The schema associated with the enum option when the option represents a `oneOf` or `anyOf` choice */
|
|
1060
1089
|
schema?: S;
|
|
1061
|
-
}
|
|
1090
|
+
}
|
|
1062
1091
|
|
|
1063
1092
|
/** This type remaps the keys of `Type` to prepend `ui:` onto them. As a result it does not need to be exported */
|
|
1064
1093
|
type MakeUIType<Type> = {
|
|
@@ -1155,10 +1184,7 @@ export type UIOptionsType<
|
|
|
1155
1184
|
T = any,
|
|
1156
1185
|
S extends StrictRJSFSchema = RJSFSchema,
|
|
1157
1186
|
F extends FormContextType = any,
|
|
1158
|
-
> = UIOptionsBaseType<T, S, F> &
|
|
1159
|
-
/** Anything else will be one of these types */
|
|
1160
|
-
[key: string]: boolean | number | string | object | any[] | null | undefined;
|
|
1161
|
-
};
|
|
1187
|
+
> = UIOptionsBaseType<T, S, F> & Record<string, boolean | number | string | object | any[] | null | undefined>;
|
|
1162
1188
|
|
|
1163
1189
|
/**
|
|
1164
1190
|
* A utility type that extracts the element type from an array type.
|
|
@@ -1172,9 +1198,11 @@ export type ArrayElement<A> = A extends readonly (infer E)[] ? E : A;
|
|
|
1172
1198
|
* When a schema with a matching `$ref` is resolved, the corresponding uiSchema definition
|
|
1173
1199
|
* is automatically applied and merged with any local uiSchema overrides.
|
|
1174
1200
|
*/
|
|
1175
|
-
export type UiSchemaDefinitions<
|
|
1176
|
-
|
|
1177
|
-
|
|
1201
|
+
export type UiSchemaDefinitions<
|
|
1202
|
+
T = any,
|
|
1203
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
1204
|
+
F extends FormContextType = any,
|
|
1205
|
+
> = Record<string, UiSchema<T, S, F>>;
|
|
1178
1206
|
|
|
1179
1207
|
/** Type describing the well-known properties of the `UiSchema` while also supporting all user defined properties,
|
|
1180
1208
|
* starting with `ui:`.
|
|
@@ -1238,12 +1266,12 @@ export type ErrorTransformer<T = any, S extends StrictRJSFSchema = RJSFSchema, F
|
|
|
1238
1266
|
) => RJSFValidationError[];
|
|
1239
1267
|
|
|
1240
1268
|
/** The type that describes the data that is returned from the `ValidatorType.validateFormData()` function */
|
|
1241
|
-
export
|
|
1269
|
+
export interface ValidationData<T> {
|
|
1242
1270
|
/** The validation errors as a list of `RJSFValidationError` objects */
|
|
1243
1271
|
errors: RJSFValidationError[];
|
|
1244
1272
|
/** The validation errors in the form of an `ErrorSchema` */
|
|
1245
1273
|
errorSchema: ErrorSchema<T>;
|
|
1246
|
-
}
|
|
1274
|
+
}
|
|
1247
1275
|
|
|
1248
1276
|
/** The interface that describes the validation functions that are provided by a Validator implementation used by the
|
|
1249
1277
|
* schema utilities.
|
|
@@ -1477,5 +1505,6 @@ export interface SchemaUtilsType<T = any, S extends StrictRJSFSchema = RJSFSchem
|
|
|
1477
1505
|
* @returns - The `PathSchema` object for the `schema`
|
|
1478
1506
|
* @deprecated - To be removed as an exported `@rjsf/utils` function in a future release
|
|
1479
1507
|
*/
|
|
1508
|
+
// oxlint-disable-next-line typescript/no-deprecated
|
|
1480
1509
|
toPathSchema(schema: S, name?: string, formData?: T): PathSchema<T>;
|
|
1481
1510
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import isPlainObject from 'lodash/isPlainObject';
|
|
2
2
|
|
|
3
|
-
import { ErrorSchema, FormValidation, GenericObjectType } from './types';
|
|
3
|
+
import type { ErrorSchema, FormValidation, GenericObjectType } from './types';
|
|
4
4
|
|
|
5
5
|
/** Unwraps the `errorHandler` structure into the associated `ErrorSchema`, stripping the `addError()` functions from it
|
|
6
6
|
*
|
|
@@ -8,18 +8,17 @@ import { ErrorSchema, FormValidation, GenericObjectType } from './types';
|
|
|
8
8
|
* @returns - The `ErrorSchema` resulting from the stripping of the `addError()` function
|
|
9
9
|
*/
|
|
10
10
|
export default function unwrapErrorHandler<T = any>(errorHandler: FormValidation<T>): ErrorSchema<T> {
|
|
11
|
-
return Object.keys(errorHandler).reduce((acc, key) => {
|
|
11
|
+
return Object.keys(errorHandler).reduce<ErrorSchema<T>>((acc, key) => {
|
|
12
12
|
if (key === 'addError') {
|
|
13
13
|
return acc;
|
|
14
|
-
} else {
|
|
15
|
-
const childSchema = (errorHandler as GenericObjectType)[key];
|
|
16
|
-
if (isPlainObject(childSchema)) {
|
|
17
|
-
return {
|
|
18
|
-
...acc,
|
|
19
|
-
[key]: unwrapErrorHandler(childSchema),
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
return { ...acc, [key]: childSchema };
|
|
23
14
|
}
|
|
24
|
-
|
|
15
|
+
const childSchema = (errorHandler as GenericObjectType)[key];
|
|
16
|
+
if (isPlainObject(childSchema)) {
|
|
17
|
+
return {
|
|
18
|
+
...acc,
|
|
19
|
+
[key]: unwrapErrorHandler(childSchema),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
return { ...acc, [key]: childSchema };
|
|
23
|
+
}, {});
|
|
25
24
|
}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import { MouseEvent
|
|
3
|
+
import type { MouseEvent } from 'react';
|
|
4
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
4
5
|
|
|
5
6
|
import dateRangeOptions from './dateRangeOptions';
|
|
6
|
-
import
|
|
7
|
+
import type { DateElementFormat, DateElementProp } from './getDateElementProps';
|
|
8
|
+
import getDateElementProps from './getDateElementProps';
|
|
7
9
|
import { ariaDescribedByIds } from './idGenerators';
|
|
8
10
|
import parseDateString from './parseDateString';
|
|
9
11
|
import toDateString from './toDateString';
|
|
10
|
-
import { DateObject, FormContextType, RJSFSchema, StrictRJSFSchema, WidgetProps } from './types';
|
|
12
|
+
import type { DateObject, FormContextType, RJSFSchema, StrictRJSFSchema, WidgetProps } from './types';
|
|
11
13
|
|
|
12
14
|
/** Function that checks to see if a `DateObject` is ready for the onChange callback to be triggered
|
|
13
15
|
*
|
|
@@ -58,7 +60,7 @@ export function DateElement<T = any, S extends StrictRJSFSchema = RJSFSchema, F
|
|
|
58
60
|
} = props;
|
|
59
61
|
const id = `${rootId}_${type}`;
|
|
60
62
|
const { SelectWidget } = registry.widgets;
|
|
61
|
-
const onChange = useCallback((
|
|
63
|
+
const onChange = useCallback((newValue: any) => select(type as keyof DateObject, newValue), [select, type]);
|
|
62
64
|
return (
|
|
63
65
|
<SelectWidget
|
|
64
66
|
schema={{ type: 'integer' } as S}
|
|
@@ -82,7 +84,7 @@ export function DateElement<T = any, S extends StrictRJSFSchema = RJSFSchema, F
|
|
|
82
84
|
}
|
|
83
85
|
|
|
84
86
|
/** The result of a call to the `useAltDateWidgetProps()` hook */
|
|
85
|
-
export
|
|
87
|
+
export interface UseAltDateWidgetResult {
|
|
86
88
|
/** The list of `DateElementProp` data to render for the `AltDateWidget` */
|
|
87
89
|
elements: DateElementProp[];
|
|
88
90
|
/** The callback that handles the changing of DateElement components */
|
|
@@ -91,7 +93,7 @@ export type UseAltDateWidgetResult = {
|
|
|
91
93
|
handleClear: (event: MouseEvent) => void;
|
|
92
94
|
/** The callback that will set the `AltDateWidget` to NOW when a button is clicked */
|
|
93
95
|
handleSetNow: (event: MouseEvent) => void;
|
|
94
|
-
}
|
|
96
|
+
}
|
|
95
97
|
|
|
96
98
|
/** Hook which encapsulates the logic needed to render an `AltDateWidget` with optional `time` elements. It contains
|
|
97
99
|
* the `state` of the current date(/time) selections in the widget. It returns a `UseAltDateWidgetResult` object
|
|
@@ -113,10 +115,10 @@ export default function useAltDateWidgetProps<
|
|
|
113
115
|
}, [time, value]);
|
|
114
116
|
|
|
115
117
|
const handleChange = useCallback(
|
|
116
|
-
(property: keyof DateObject,
|
|
118
|
+
(property: keyof DateObject, newValue?: string) => {
|
|
117
119
|
const nextState = {
|
|
118
120
|
...state,
|
|
119
|
-
[property]: typeof
|
|
121
|
+
[property]: typeof newValue === 'undefined' ? -1 : newValue,
|
|
120
122
|
};
|
|
121
123
|
|
|
122
124
|
if (readyForChange(nextState)) {
|
|
@@ -5,7 +5,7 @@ import { useCallback, useMemo } from 'react';
|
|
|
5
5
|
import dataURItoBlob from './dataURItoBlob';
|
|
6
6
|
|
|
7
7
|
/** The information about files used by a FileWidget */
|
|
8
|
-
export
|
|
8
|
+
export interface FileInfoType {
|
|
9
9
|
/** The url of the data containing the file */
|
|
10
10
|
dataURL?: string | null;
|
|
11
11
|
/** The name of the file */
|
|
@@ -14,7 +14,7 @@ export type FileInfoType = {
|
|
|
14
14
|
size: number;
|
|
15
15
|
/** The type of the file */
|
|
16
16
|
type: string;
|
|
17
|
-
}
|
|
17
|
+
}
|
|
18
18
|
|
|
19
19
|
export interface UseFileWidgetPropsResult {
|
|
20
20
|
/** The list of FileInfoType contained within the FileWidget */
|
|
@@ -40,7 +40,7 @@ function addNameToDataURL(dataURL: string, name: string) {
|
|
|
40
40
|
* @param file - The `File` information to read
|
|
41
41
|
* @returns - A promise that resolves to the read file.
|
|
42
42
|
*/
|
|
43
|
-
function processFile(file: File): Promise<FileInfoType> {
|
|
43
|
+
async function processFile(file: File): Promise<FileInfoType> {
|
|
44
44
|
const { name, size, type } = file;
|
|
45
45
|
return new Promise((resolve, reject) => {
|
|
46
46
|
const reader = new window.FileReader();
|
|
@@ -71,7 +71,7 @@ function processFile(file: File): Promise<FileInfoType> {
|
|
|
71
71
|
* @param files - The list of files to read
|
|
72
72
|
* @returns - The list of read files
|
|
73
73
|
*/
|
|
74
|
-
function processFiles(files: FileList) {
|
|
74
|
+
async function processFiles(files: FileList) {
|
|
75
75
|
return Promise.all(Array.from(files).map(processFile));
|
|
76
76
|
}
|
|
77
77
|
|
|
@@ -81,7 +81,7 @@ function processFiles(files: FileList) {
|
|
|
81
81
|
* @returns - The list of `FileInfoType` objects extracted from the data urls
|
|
82
82
|
*/
|
|
83
83
|
function extractFileInfo(dataURLs: string[]): FileInfoType[] {
|
|
84
|
-
return dataURLs.reduce((acc, dataURL) => {
|
|
84
|
+
return dataURLs.reduce<FileInfoType[]>((acc, dataURL) => {
|
|
85
85
|
if (!dataURL) {
|
|
86
86
|
return acc;
|
|
87
87
|
}
|
|
@@ -91,7 +91,7 @@ function extractFileInfo(dataURLs: string[]): FileInfoType[] {
|
|
|
91
91
|
...acc,
|
|
92
92
|
{
|
|
93
93
|
dataURL,
|
|
94
|
-
name
|
|
94
|
+
name,
|
|
95
95
|
size: blob.size,
|
|
96
96
|
type: blob.type,
|
|
97
97
|
},
|
|
@@ -100,7 +100,7 @@ function extractFileInfo(dataURLs: string[]): FileInfoType[] {
|
|
|
100
100
|
// Invalid dataURI, so just ignore it.
|
|
101
101
|
return acc;
|
|
102
102
|
}
|
|
103
|
-
}, []
|
|
103
|
+
}, []);
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
/** Hook which encapsulates the logic needed to read and convert a `value` of `File` or `File[]` into the
|
|
@@ -2,7 +2,7 @@ import isEmpty from 'lodash/isEmpty';
|
|
|
2
2
|
|
|
3
3
|
import mergeObjects from './mergeObjects';
|
|
4
4
|
import toErrorList from './toErrorList';
|
|
5
|
-
import { ErrorSchema, ValidationData } from './types';
|
|
5
|
+
import type { ErrorSchema, ValidationData } from './types';
|
|
6
6
|
|
|
7
7
|
/** Merges the errors in `additionalErrorSchema` into the existing `validationData` by combining the hierarchies in the
|
|
8
8
|
* two `ErrorSchema`s and then appending the error list from the `additionalErrorSchema` obtained by calling
|