@rjsf/core 6.0.0-beta.2 → 6.0.0-beta.20
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 +469 -360
- package/dist/{index.js → index.cjs} +640 -519
- package/dist/index.cjs.map +7 -0
- package/dist/index.esm.js +706 -566
- package/dist/index.esm.js.map +4 -4
- package/lib/components/Form.d.ts +66 -16
- package/lib/components/Form.d.ts.map +1 -1
- package/lib/components/Form.js +138 -59
- package/lib/components/fields/ArrayField.d.ts +17 -7
- package/lib/components/fields/ArrayField.d.ts.map +1 -1
- package/lib/components/fields/ArrayField.js +92 -59
- package/lib/components/fields/BooleanField.d.ts.map +1 -1
- package/lib/components/fields/BooleanField.js +7 -2
- package/lib/components/fields/LayoutGridField.d.ts +27 -25
- package/lib/components/fields/LayoutGridField.d.ts.map +1 -1
- package/lib/components/fields/LayoutGridField.js +83 -53
- package/lib/components/fields/LayoutHeaderField.d.ts +1 -1
- package/lib/components/fields/LayoutHeaderField.js +3 -3
- package/lib/components/fields/LayoutMultiSchemaField.js +6 -5
- package/lib/components/fields/MultiSchemaField.d.ts.map +1 -1
- package/lib/components/fields/MultiSchemaField.js +13 -9
- package/lib/components/fields/NullField.js +3 -3
- package/lib/components/fields/NumberField.d.ts.map +1 -1
- package/lib/components/fields/NumberField.js +3 -3
- package/lib/components/fields/ObjectField.d.ts +3 -3
- package/lib/components/fields/ObjectField.d.ts.map +1 -1
- package/lib/components/fields/ObjectField.js +18 -25
- package/lib/components/fields/SchemaField.d.ts.map +1 -1
- package/lib/components/fields/SchemaField.js +17 -17
- package/lib/components/fields/StringField.d.ts.map +1 -1
- package/lib/components/fields/StringField.js +7 -2
- package/lib/components/templates/ArrayFieldDescriptionTemplate.d.ts +1 -1
- package/lib/components/templates/ArrayFieldDescriptionTemplate.js +3 -3
- package/lib/components/templates/ArrayFieldItemButtonsTemplate.js +2 -2
- package/lib/components/templates/ArrayFieldTemplate.js +3 -3
- package/lib/components/templates/ArrayFieldTitleTemplate.d.ts +1 -1
- package/lib/components/templates/ArrayFieldTitleTemplate.js +3 -3
- package/lib/components/templates/FieldErrorTemplate.js +2 -2
- package/lib/components/templates/FieldHelpTemplate.js +2 -2
- package/lib/components/templates/MultiSchemaFieldTemplate.d.ts +8 -0
- package/lib/components/templates/MultiSchemaFieldTemplate.d.ts.map +1 -0
- package/lib/components/templates/MultiSchemaFieldTemplate.js +10 -0
- package/lib/components/templates/ObjectFieldTemplate.js +2 -2
- package/lib/components/templates/UnsupportedField.js +3 -3
- 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.map +1 -1
- package/lib/components/widgets/AltDateWidget.js +15 -18
- package/lib/components/widgets/CheckboxesWidget.js +2 -2
- package/lib/getDefaultRegistry.d.ts.map +1 -1
- package/lib/getDefaultRegistry.js +2 -1
- package/lib/getTestRegistry.d.ts +5 -0
- package/lib/getTestRegistry.d.ts.map +1 -0
- package/lib/getTestRegistry.js +19 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +18 -19
- package/src/components/Form.tsx +183 -73
- package/src/components/fields/ArrayField.tsx +99 -67
- package/src/components/fields/BooleanField.tsx +12 -3
- package/src/components/fields/LayoutGridField.tsx +95 -82
- package/src/components/fields/LayoutHeaderField.tsx +3 -3
- package/src/components/fields/LayoutMultiSchemaField.tsx +5 -5
- package/src/components/fields/MultiSchemaField.tsx +51 -35
- package/src/components/fields/NullField.tsx +3 -3
- package/src/components/fields/NumberField.tsx +11 -3
- package/src/components/fields/ObjectField.tsx +19 -36
- package/src/components/fields/SchemaField.tsx +24 -30
- package/src/components/fields/StringField.tsx +12 -3
- package/src/components/templates/ArrayFieldDescriptionTemplate.tsx +3 -3
- package/src/components/templates/ArrayFieldItemButtonsTemplate.tsx +5 -5
- package/src/components/templates/ArrayFieldTemplate.tsx +5 -5
- package/src/components/templates/ArrayFieldTitleTemplate.tsx +3 -3
- package/src/components/templates/BaseInputTemplate.tsx +3 -3
- package/src/components/templates/FieldErrorTemplate.tsx +2 -2
- package/src/components/templates/FieldHelpTemplate.tsx +2 -2
- package/src/components/templates/MultiSchemaFieldTemplate.tsx +20 -0
- package/src/components/templates/ObjectFieldTemplate.tsx +5 -5
- package/src/components/templates/UnsupportedField.tsx +3 -3
- package/src/components/templates/WrapIfAdditionalTemplate.tsx +1 -1
- package/src/components/templates/index.ts +2 -0
- package/src/components/widgets/AltDateWidget.tsx +21 -23
- package/src/components/widgets/CheckboxWidget.tsx +2 -2
- package/src/components/widgets/CheckboxesWidget.tsx +3 -3
- package/src/components/widgets/RadioWidget.tsx +1 -1
- package/src/components/widgets/SelectWidget.tsx +1 -1
- package/src/components/widgets/TextareaWidget.tsx +1 -1
- package/src/getDefaultRegistry.ts +10 -1
- package/src/getTestRegistry.tsx +34 -0
- package/src/index.ts +2 -1
- package/dist/index.js.map +0 -7
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MouseEvent, useCallback, useEffect,
|
|
1
|
+
import { MouseEvent, useCallback, useEffect, useState } from 'react';
|
|
2
2
|
import {
|
|
3
3
|
ariaDescribedByIds,
|
|
4
4
|
dateRangeOptions,
|
|
@@ -61,7 +61,7 @@ function DateElement<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends
|
|
|
61
61
|
onFocus={onFocus}
|
|
62
62
|
registry={registry}
|
|
63
63
|
label=''
|
|
64
|
-
aria-describedby={ariaDescribedByIds
|
|
64
|
+
aria-describedby={ariaDescribedByIds(rootId)}
|
|
65
65
|
/>
|
|
66
66
|
);
|
|
67
67
|
}
|
|
@@ -84,29 +84,27 @@ function AltDateWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F exten
|
|
|
84
84
|
value,
|
|
85
85
|
}: WidgetProps<T, S, F>) {
|
|
86
86
|
const { translateString } = registry;
|
|
87
|
-
const [
|
|
88
|
-
const [state, setState] = useReducer(
|
|
89
|
-
(state: DateObject, action: Partial<DateObject>) => {
|
|
90
|
-
return { ...state, ...action };
|
|
91
|
-
},
|
|
92
|
-
parseDateString(value, time),
|
|
93
|
-
);
|
|
87
|
+
const [state, setState] = useState(parseDateString(value, time));
|
|
94
88
|
|
|
95
89
|
useEffect(() => {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}, [time, value, onChange, state, lastValue]);
|
|
90
|
+
setState(parseDateString(value, time));
|
|
91
|
+
}, [time, value]);
|
|
92
|
+
|
|
93
|
+
const handleChange = useCallback(
|
|
94
|
+
(property: keyof DateObject, value: string) => {
|
|
95
|
+
const nextState = {
|
|
96
|
+
...state,
|
|
97
|
+
[property]: typeof value === 'undefined' ? -1 : value,
|
|
98
|
+
};
|
|
106
99
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
100
|
+
if (readyForChange(nextState)) {
|
|
101
|
+
onChange(toDateString(nextState, time));
|
|
102
|
+
} else {
|
|
103
|
+
setState(nextState);
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
[state, onChange, time],
|
|
107
|
+
);
|
|
110
108
|
|
|
111
109
|
const handleSetNow = useCallback(
|
|
112
110
|
(event: MouseEvent<HTMLAnchorElement>) => {
|
|
@@ -117,7 +115,7 @@ function AltDateWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F exten
|
|
|
117
115
|
const nextState = parseDateString(new Date().toJSON(), time);
|
|
118
116
|
onChange(toDateString(nextState, time));
|
|
119
117
|
},
|
|
120
|
-
[disabled, readonly, time],
|
|
118
|
+
[disabled, readonly, time, onChange],
|
|
121
119
|
);
|
|
122
120
|
|
|
123
121
|
const handleClear = useCallback(
|
|
@@ -62,7 +62,7 @@ function CheckboxWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F exte
|
|
|
62
62
|
<div className={`checkbox ${disabled || readonly ? 'disabled' : ''}`}>
|
|
63
63
|
{!hideLabel && description && (
|
|
64
64
|
<DescriptionFieldTemplate
|
|
65
|
-
id={descriptionId
|
|
65
|
+
id={descriptionId(id)}
|
|
66
66
|
description={description}
|
|
67
67
|
schema={schema}
|
|
68
68
|
uiSchema={uiSchema}
|
|
@@ -81,7 +81,7 @@ function CheckboxWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F exte
|
|
|
81
81
|
onChange={handleChange}
|
|
82
82
|
onBlur={handleBlur}
|
|
83
83
|
onFocus={handleFocus}
|
|
84
|
-
aria-describedby={ariaDescribedByIds
|
|
84
|
+
aria-describedby={ariaDescribedByIds(id)}
|
|
85
85
|
/>
|
|
86
86
|
{labelValue(<span>{label}</span>, hideLabel)}
|
|
87
87
|
</label>
|
|
@@ -33,13 +33,13 @@ function CheckboxesWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F ex
|
|
|
33
33
|
const handleBlur = useCallback(
|
|
34
34
|
({ target }: FocusEvent<HTMLInputElement>) =>
|
|
35
35
|
onBlur(id, enumOptionsValueForIndex<S>(target && target.value, enumOptions, emptyValue)),
|
|
36
|
-
[onBlur, id],
|
|
36
|
+
[onBlur, id, enumOptions, emptyValue],
|
|
37
37
|
);
|
|
38
38
|
|
|
39
39
|
const handleFocus = useCallback(
|
|
40
40
|
({ target }: FocusEvent<HTMLInputElement>) =>
|
|
41
41
|
onFocus(id, enumOptionsValueForIndex<S>(target && target.value, enumOptions, emptyValue)),
|
|
42
|
-
[onFocus, id],
|
|
42
|
+
[onFocus, id, enumOptions, emptyValue],
|
|
43
43
|
);
|
|
44
44
|
return (
|
|
45
45
|
<div className='checkboxes' id={id}>
|
|
@@ -70,7 +70,7 @@ function CheckboxesWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F ex
|
|
|
70
70
|
onChange={handleChange}
|
|
71
71
|
onBlur={handleBlur}
|
|
72
72
|
onFocus={handleFocus}
|
|
73
|
-
aria-describedby={ariaDescribedByIds
|
|
73
|
+
aria-describedby={ariaDescribedByIds(id)}
|
|
74
74
|
/>
|
|
75
75
|
<span>{option.label}</span>
|
|
76
76
|
</span>
|
|
@@ -65,7 +65,7 @@ function RadioWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends
|
|
|
65
65
|
onChange={handleChange}
|
|
66
66
|
onBlur={handleBlur}
|
|
67
67
|
onFocus={handleFocus}
|
|
68
|
-
aria-describedby={ariaDescribedByIds
|
|
68
|
+
aria-describedby={ariaDescribedByIds(id)}
|
|
69
69
|
/>
|
|
70
70
|
<span>{option.label}</span>
|
|
71
71
|
</span>
|
|
@@ -83,7 +83,7 @@ function SelectWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extend
|
|
|
83
83
|
onBlur={handleBlur}
|
|
84
84
|
onFocus={handleFocus}
|
|
85
85
|
onChange={handleChange}
|
|
86
|
-
aria-describedby={ariaDescribedByIds
|
|
86
|
+
aria-describedby={ariaDescribedByIds(id)}
|
|
87
87
|
>
|
|
88
88
|
{showPlaceholderOption && <option value=''>{placeholder}</option>}
|
|
89
89
|
{Array.isArray(enumOptions) &&
|
|
@@ -48,7 +48,7 @@ function TextareaWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F exte
|
|
|
48
48
|
onBlur={handleBlur}
|
|
49
49
|
onFocus={handleFocus}
|
|
50
50
|
onChange={handleChange}
|
|
51
|
-
aria-describedby={ariaDescribedByIds
|
|
51
|
+
aria-describedby={ariaDescribedByIds(id)}
|
|
52
52
|
/>
|
|
53
53
|
);
|
|
54
54
|
}
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_ID_PREFIX,
|
|
3
|
+
DEFAULT_ID_SEPARATOR,
|
|
4
|
+
englishStringTranslator,
|
|
5
|
+
FormContextType,
|
|
6
|
+
Registry,
|
|
7
|
+
RJSFSchema,
|
|
8
|
+
StrictRJSFSchema,
|
|
9
|
+
} from '@rjsf/utils';
|
|
2
10
|
|
|
3
11
|
import fields from './components/fields';
|
|
4
12
|
import templates from './components/templates';
|
|
@@ -20,5 +28,6 @@ export default function getDefaultRegistry<
|
|
|
20
28
|
rootSchema: {} as S,
|
|
21
29
|
formContext: {} as F,
|
|
22
30
|
translateString: englishStringTranslator,
|
|
31
|
+
globalFormOptions: { idPrefix: DEFAULT_ID_PREFIX, idSeparator: DEFAULT_ID_SEPARATOR },
|
|
23
32
|
};
|
|
24
33
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_ID_PREFIX,
|
|
3
|
+
DEFAULT_ID_SEPARATOR,
|
|
4
|
+
createSchemaUtils,
|
|
5
|
+
englishStringTranslator,
|
|
6
|
+
Registry,
|
|
7
|
+
} from '@rjsf/utils';
|
|
8
|
+
import validator from '@rjsf/validator-ajv8';
|
|
9
|
+
|
|
10
|
+
import getDefaultRegistry from './getDefaultRegistry';
|
|
11
|
+
|
|
12
|
+
/** Use for react testing library tests where we directly test the component rather than testing inside a Form
|
|
13
|
+
*/
|
|
14
|
+
export default function getTestRegistry(
|
|
15
|
+
rootSchema: Registry['rootSchema'],
|
|
16
|
+
fields: Registry['fields'] = {},
|
|
17
|
+
templates: Partial<Registry['templates']> = {},
|
|
18
|
+
widgets: Registry['widgets'] = {},
|
|
19
|
+
formContext: Registry['formContext'] = {},
|
|
20
|
+
globalFormOptions: Registry['globalFormOptions'] = { idPrefix: DEFAULT_ID_PREFIX, idSeparator: DEFAULT_ID_SEPARATOR },
|
|
21
|
+
): Registry {
|
|
22
|
+
const defaults = getDefaultRegistry();
|
|
23
|
+
const schemaUtils = createSchemaUtils(validator, rootSchema);
|
|
24
|
+
return {
|
|
25
|
+
fields: { ...defaults.fields, ...fields },
|
|
26
|
+
templates: { ...defaults.templates, ...templates },
|
|
27
|
+
widgets: { ...defaults.widgets, ...widgets },
|
|
28
|
+
formContext,
|
|
29
|
+
rootSchema,
|
|
30
|
+
schemaUtils,
|
|
31
|
+
translateString: englishStringTranslator,
|
|
32
|
+
globalFormOptions,
|
|
33
|
+
};
|
|
34
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -2,8 +2,9 @@ import Form, { FormProps, FormState, IChangeEvent } from './components/Form';
|
|
|
2
2
|
import RichDescription, { RichDescriptionProps } from './components/RichDescription';
|
|
3
3
|
import withTheme, { ThemeProps } from './withTheme';
|
|
4
4
|
import getDefaultRegistry from './getDefaultRegistry';
|
|
5
|
+
import getTestRegistry from './getTestRegistry';
|
|
5
6
|
|
|
6
7
|
export type { FormProps, FormState, IChangeEvent, ThemeProps, RichDescriptionProps };
|
|
7
8
|
|
|
8
|
-
export { withTheme, getDefaultRegistry, RichDescription };
|
|
9
|
+
export { withTheme, getDefaultRegistry, getTestRegistry, RichDescription };
|
|
9
10
|
export default Form;
|