@rjsf/core 6.0.0-beta.21 → 6.0.0-beta.23
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/core.umd.js +1580 -1771
- package/dist/index.cjs +2019 -2206
- package/dist/index.cjs.map +4 -4
- package/dist/index.esm.js +2011 -2182
- package/dist/index.esm.js.map +4 -4
- package/lib/components/Form.d.ts +50 -12
- package/lib/components/Form.d.ts.map +1 -1
- package/lib/components/Form.js +114 -31
- package/lib/components/fields/ArrayField.d.ts +2 -197
- package/lib/components/fields/ArrayField.d.ts.map +1 -1
- package/lib/components/fields/ArrayField.js +518 -536
- package/lib/components/fields/BooleanField.js +2 -2
- package/lib/components/fields/FallbackField.d.ts +7 -0
- package/lib/components/fields/FallbackField.d.ts.map +1 -0
- package/lib/components/fields/FallbackField.js +72 -0
- package/lib/components/fields/LayoutGridField.d.ts +109 -191
- package/lib/components/fields/LayoutGridField.d.ts.map +1 -1
- package/lib/components/fields/LayoutGridField.js +417 -444
- package/lib/components/fields/LayoutMultiSchemaField.d.ts.map +1 -1
- package/lib/components/fields/LayoutMultiSchemaField.js +2 -3
- package/lib/components/fields/MultiSchemaField.d.ts.map +1 -1
- package/lib/components/fields/MultiSchemaField.js +5 -3
- package/lib/components/fields/ObjectField.d.ts +2 -68
- package/lib/components/fields/ObjectField.d.ts.map +1 -1
- package/lib/components/fields/ObjectField.js +166 -168
- package/lib/components/fields/SchemaField.d.ts.map +1 -1
- package/lib/components/fields/SchemaField.js +35 -22
- package/lib/components/fields/StringField.js +2 -2
- package/lib/components/fields/index.d.ts.map +1 -1
- package/lib/components/fields/index.js +2 -0
- package/lib/components/templates/ArrayFieldItemButtonsTemplate.d.ts +3 -3
- package/lib/components/templates/ArrayFieldItemButtonsTemplate.d.ts.map +1 -1
- package/lib/components/templates/ArrayFieldItemButtonsTemplate.js +3 -8
- package/lib/components/templates/ArrayFieldItemTemplate.d.ts +3 -3
- package/lib/components/templates/ArrayFieldItemTemplate.d.ts.map +1 -1
- package/lib/components/templates/ArrayFieldItemTemplate.js +1 -1
- package/lib/components/templates/ArrayFieldTemplate.d.ts +1 -1
- package/lib/components/templates/ArrayFieldTemplate.d.ts.map +1 -1
- package/lib/components/templates/ArrayFieldTemplate.js +2 -4
- package/lib/components/templates/BaseInputTemplate.js +2 -2
- package/lib/components/templates/FallbackFieldTemplate.d.ts +7 -0
- package/lib/components/templates/FallbackFieldTemplate.d.ts.map +1 -0
- package/lib/components/templates/FallbackFieldTemplate.js +12 -0
- package/lib/components/templates/ObjectFieldTemplate.js +2 -2
- package/lib/components/templates/WrapIfAdditionalTemplate.js +2 -2
- package/lib/components/templates/index.d.ts.map +1 -1
- package/lib/components/templates/index.js +2 -0
- package/lib/components/widgets/AltDateWidget.d.ts +1 -1
- package/lib/components/widgets/AltDateWidget.d.ts.map +1 -1
- package/lib/components/widgets/AltDateWidget.js +5 -43
- package/lib/components/widgets/CheckboxWidget.d.ts +1 -1
- package/lib/components/widgets/CheckboxWidget.d.ts.map +1 -1
- package/lib/components/widgets/CheckboxWidget.js +2 -2
- package/lib/components/widgets/CheckboxesWidget.d.ts +1 -1
- package/lib/components/widgets/CheckboxesWidget.d.ts.map +1 -1
- package/lib/components/widgets/CheckboxesWidget.js +2 -2
- package/lib/components/widgets/FileWidget.d.ts.map +1 -1
- package/lib/components/widgets/FileWidget.js +7 -87
- package/lib/components/widgets/HiddenWidget.d.ts +1 -1
- package/lib/components/widgets/HiddenWidget.d.ts.map +1 -1
- package/lib/components/widgets/HiddenWidget.js +2 -2
- package/lib/components/widgets/RadioWidget.d.ts +1 -1
- package/lib/components/widgets/RadioWidget.d.ts.map +1 -1
- package/lib/components/widgets/RadioWidget.js +2 -2
- package/lib/components/widgets/RatingWidget.d.ts +1 -1
- package/lib/components/widgets/RatingWidget.d.ts.map +1 -1
- package/lib/components/widgets/RatingWidget.js +2 -2
- package/lib/components/widgets/SelectWidget.d.ts +1 -1
- package/lib/components/widgets/SelectWidget.d.ts.map +1 -1
- package/lib/components/widgets/SelectWidget.js +2 -2
- package/lib/components/widgets/TextareaWidget.d.ts +1 -1
- package/lib/components/widgets/TextareaWidget.d.ts.map +1 -1
- package/lib/components/widgets/TextareaWidget.js +2 -2
- package/lib/getDefaultRegistry.d.ts.map +1 -1
- package/lib/getDefaultRegistry.js +5 -1
- package/lib/getTestRegistry.d.ts.map +1 -1
- package/lib/getTestRegistry.js +5 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +21 -5
- package/src/components/Form.tsx +176 -43
- package/src/components/fields/ArrayField.tsx +849 -758
- package/src/components/fields/BooleanField.tsx +2 -2
- package/src/components/fields/FallbackField.tsx +157 -0
- package/src/components/fields/LayoutGridField.tsx +613 -600
- package/src/components/fields/LayoutMultiSchemaField.tsx +4 -5
- package/src/components/fields/MultiSchemaField.tsx +30 -25
- package/src/components/fields/ObjectField.tsx +315 -242
- package/src/components/fields/OptionalDataControlsField.tsx +1 -1
- package/src/components/fields/SchemaField.tsx +46 -70
- package/src/components/fields/StringField.tsx +2 -2
- package/src/components/fields/index.ts +2 -0
- package/src/components/templates/ArrayFieldItemButtonsTemplate.tsx +11 -16
- package/src/components/templates/ArrayFieldItemTemplate.tsx +3 -3
- package/src/components/templates/ArrayFieldTemplate.tsx +2 -13
- package/src/components/templates/BaseInputTemplate.tsx +2 -2
- package/src/components/templates/FallbackFieldTemplate.tsx +28 -0
- package/src/components/templates/ObjectFieldTemplate.tsx +2 -2
- package/src/components/templates/WrapIfAdditionalTemplate.tsx +4 -4
- package/src/components/templates/index.ts +2 -0
- package/src/components/widgets/AltDateWidget.tsx +8 -124
- package/src/components/widgets/CheckboxWidget.tsx +2 -1
- package/src/components/widgets/CheckboxesWidget.tsx +2 -1
- package/src/components/widgets/FileWidget.tsx +11 -102
- package/src/components/widgets/HiddenWidget.tsx +2 -1
- package/src/components/widgets/RadioWidget.tsx +2 -1
- package/src/components/widgets/RatingWidget.tsx +2 -1
- package/src/components/widgets/SelectWidget.tsx +2 -1
- package/src/components/widgets/TextareaWidget.tsx +2 -1
- package/src/getDefaultRegistry.ts +5 -1
- package/src/getTestRegistry.tsx +5 -1
|
@@ -40,7 +40,7 @@ function BooleanField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extend
|
|
|
40
40
|
rawErrors,
|
|
41
41
|
} = props;
|
|
42
42
|
const { title: schemaTitle } = schema;
|
|
43
|
-
const { widgets,
|
|
43
|
+
const { widgets, translateString, globalUiOptions } = registry;
|
|
44
44
|
const {
|
|
45
45
|
widget = 'checkbox',
|
|
46
46
|
title: uiTitle,
|
|
@@ -114,9 +114,9 @@ function BooleanField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extend
|
|
|
114
114
|
readonly={readonly}
|
|
115
115
|
hideError={hideError}
|
|
116
116
|
registry={registry}
|
|
117
|
-
formContext={formContext}
|
|
118
117
|
autofocus={autofocus}
|
|
119
118
|
rawErrors={rawErrors}
|
|
119
|
+
htmlName={fieldPathId.name}
|
|
120
120
|
/>
|
|
121
121
|
);
|
|
122
122
|
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FallbackFieldProps,
|
|
3
|
+
FieldPathId,
|
|
4
|
+
FormContextType,
|
|
5
|
+
getTemplate,
|
|
6
|
+
getUiOptions,
|
|
7
|
+
hashObject,
|
|
8
|
+
RJSFSchema,
|
|
9
|
+
StrictRJSFSchema,
|
|
10
|
+
toFieldPathId,
|
|
11
|
+
TranslatableString,
|
|
12
|
+
useDeepCompareMemo,
|
|
13
|
+
} from '@rjsf/utils';
|
|
14
|
+
import { useMemo, useState } from 'react';
|
|
15
|
+
import { JSONSchema7TypeName } from 'json-schema';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Get the schema for the type selection component.
|
|
19
|
+
* @param title - The translated title for the type selection schema.
|
|
20
|
+
*/
|
|
21
|
+
function getFallbackTypeSelectionSchema(title: string): RJSFSchema {
|
|
22
|
+
return {
|
|
23
|
+
type: 'string',
|
|
24
|
+
enum: ['string', 'number', 'boolean'],
|
|
25
|
+
default: 'string',
|
|
26
|
+
title: title,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Determines the JSON Schema type of the given formData.
|
|
32
|
+
* @param formData - The form data whose type is to be determined.
|
|
33
|
+
*/
|
|
34
|
+
function getTypeOfFormData(formData: any): JSONSchema7TypeName {
|
|
35
|
+
const dataType = typeof formData;
|
|
36
|
+
if (dataType === 'string' || dataType === 'number' || dataType === 'boolean') {
|
|
37
|
+
return dataType;
|
|
38
|
+
}
|
|
39
|
+
// Treat everything else as a string
|
|
40
|
+
return 'string';
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Casts the given formData to the specified type.
|
|
45
|
+
* @param formData - The form data to be casted.
|
|
46
|
+
* @param newType - The target type to which the form data should be casted.
|
|
47
|
+
*/
|
|
48
|
+
function castToNewType<T = any>(formData: T, newType: JSONSchema7TypeName): T {
|
|
49
|
+
switch (newType) {
|
|
50
|
+
case 'string':
|
|
51
|
+
return String(formData) as T;
|
|
52
|
+
case 'number': {
|
|
53
|
+
const castedNumber = Number(formData);
|
|
54
|
+
return (isNaN(castedNumber) ? 0 : castedNumber) as T;
|
|
55
|
+
}
|
|
56
|
+
case 'boolean':
|
|
57
|
+
return Boolean(formData) as T;
|
|
58
|
+
default:
|
|
59
|
+
return formData;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The `FallbackField` component is used to render a field for unsupported or unknown schema types. If
|
|
65
|
+
* `useFallbackUiForUnsupportedType` is enabled in the `globalUiOptions`, it provides a type selector
|
|
66
|
+
*/
|
|
67
|
+
export default function FallbackField<
|
|
68
|
+
T = any,
|
|
69
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
70
|
+
F extends FormContextType = any,
|
|
71
|
+
>(props: FallbackFieldProps<T, S, F>) {
|
|
72
|
+
const {
|
|
73
|
+
id,
|
|
74
|
+
formData,
|
|
75
|
+
displayLabel = true,
|
|
76
|
+
schema,
|
|
77
|
+
name,
|
|
78
|
+
uiSchema,
|
|
79
|
+
required,
|
|
80
|
+
disabled = false,
|
|
81
|
+
readonly = false,
|
|
82
|
+
onBlur,
|
|
83
|
+
onFocus,
|
|
84
|
+
registry,
|
|
85
|
+
fieldPathId,
|
|
86
|
+
onChange,
|
|
87
|
+
errorSchema,
|
|
88
|
+
} = props;
|
|
89
|
+
const { translateString, fields, globalFormOptions } = registry;
|
|
90
|
+
const [type, setType] = useState<JSONSchema7TypeName>(getTypeOfFormData(formData));
|
|
91
|
+
|
|
92
|
+
const uiOptions = getUiOptions<T, S, F>(uiSchema);
|
|
93
|
+
|
|
94
|
+
const typeSelectorInnerFieldPathId = useDeepCompareMemo<FieldPathId>(
|
|
95
|
+
toFieldPathId('__internal_type_selector', globalFormOptions, fieldPathId),
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
const schemaTitle = translateString(TranslatableString.Type);
|
|
99
|
+
const typesOptionSchema = useMemo(() => getFallbackTypeSelectionSchema(schemaTitle), [schemaTitle]);
|
|
100
|
+
|
|
101
|
+
const onTypeChange = (newType: T | undefined) => {
|
|
102
|
+
if (newType != null) {
|
|
103
|
+
setType(newType as JSONSchema7TypeName);
|
|
104
|
+
onChange(castToNewType<T>(formData as T, newType as JSONSchema7TypeName), fieldPathId.path, errorSchema, id);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
if (!globalFormOptions.useFallbackUiForUnsupportedType) {
|
|
109
|
+
const UnsupportedFieldTemplate = getTemplate<'UnsupportedFieldTemplate', T, S, F>(
|
|
110
|
+
'UnsupportedFieldTemplate',
|
|
111
|
+
registry,
|
|
112
|
+
uiOptions,
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
return (
|
|
116
|
+
<UnsupportedFieldTemplate
|
|
117
|
+
schema={schema}
|
|
118
|
+
fieldPathId={fieldPathId}
|
|
119
|
+
reason={translateString(TranslatableString.UnknownFieldType, [String(schema.type)])}
|
|
120
|
+
registry={registry}
|
|
121
|
+
/>
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const FallbackFieldTemplate = getTemplate<'FallbackFieldTemplate', T, S, F>(
|
|
126
|
+
'FallbackFieldTemplate',
|
|
127
|
+
registry,
|
|
128
|
+
uiOptions,
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
const { SchemaField } = fields;
|
|
132
|
+
|
|
133
|
+
return (
|
|
134
|
+
<FallbackFieldTemplate
|
|
135
|
+
schema={schema}
|
|
136
|
+
registry={registry}
|
|
137
|
+
typeSelector={
|
|
138
|
+
<SchemaField
|
|
139
|
+
key={formData ? hashObject(formData) : '__empty__'}
|
|
140
|
+
fieldPathId={typeSelectorInnerFieldPathId}
|
|
141
|
+
name={`${name}__fallback_type`}
|
|
142
|
+
schema={typesOptionSchema as S}
|
|
143
|
+
formData={type as T}
|
|
144
|
+
onChange={onTypeChange}
|
|
145
|
+
onBlur={onBlur}
|
|
146
|
+
onFocus={onFocus}
|
|
147
|
+
registry={registry}
|
|
148
|
+
hideLabel={!displayLabel}
|
|
149
|
+
disabled={disabled}
|
|
150
|
+
readonly={readonly}
|
|
151
|
+
required={required}
|
|
152
|
+
/>
|
|
153
|
+
}
|
|
154
|
+
schemaField={<SchemaField {...props} schema={{ type, title: translateString(TranslatableString.Value) } as S} />}
|
|
155
|
+
/>
|
|
156
|
+
);
|
|
157
|
+
}
|