@rjsf/core 6.0.0-alpha.0 → 6.0.0-beta.2
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 +1680 -809
- package/dist/index.esm.js +2166 -1198
- package/dist/index.esm.js.map +4 -4
- package/dist/index.js +2221 -1299
- package/dist/index.js.map +4 -4
- package/lib/components/Form.d.ts +22 -9
- package/lib/components/Form.d.ts.map +1 -0
- package/lib/components/Form.js +368 -312
- package/lib/components/RichDescription.d.ts +20 -0
- package/lib/components/RichDescription.d.ts.map +1 -0
- package/lib/components/RichDescription.js +17 -0
- package/lib/components/fields/ArrayField.d.ts +20 -9
- package/lib/components/fields/ArrayField.d.ts.map +1 -0
- package/lib/components/fields/ArrayField.js +212 -206
- package/lib/components/fields/BooleanField.d.ts +1 -0
- package/lib/components/fields/BooleanField.d.ts.map +1 -0
- package/lib/components/fields/BooleanField.js +6 -14
- package/lib/components/fields/LayoutGridField.d.ts +480 -0
- package/lib/components/fields/LayoutGridField.d.ts.map +1 -0
- package/lib/components/fields/LayoutGridField.js +711 -0
- package/lib/components/fields/LayoutHeaderField.d.ts +12 -0
- package/lib/components/fields/LayoutHeaderField.d.ts.map +1 -0
- package/lib/components/fields/LayoutHeaderField.js +23 -0
- package/lib/components/fields/LayoutMultiSchemaField.d.ts +28 -0
- package/lib/components/fields/LayoutMultiSchemaField.d.ts.map +1 -0
- package/lib/components/fields/LayoutMultiSchemaField.js +114 -0
- package/lib/components/fields/MultiSchemaField.d.ts +1 -0
- package/lib/components/fields/MultiSchemaField.d.ts.map +1 -0
- package/lib/components/fields/MultiSchemaField.js +31 -31
- package/lib/components/fields/NullField.d.ts +1 -0
- package/lib/components/fields/NullField.d.ts.map +1 -0
- package/lib/components/fields/NullField.js +0 -1
- package/lib/components/fields/NumberField.d.ts +1 -0
- package/lib/components/fields/NumberField.d.ts.map +1 -0
- package/lib/components/fields/NumberField.js +2 -3
- package/lib/components/fields/ObjectField.d.ts +1 -0
- package/lib/components/fields/ObjectField.d.ts.map +1 -0
- package/lib/components/fields/ObjectField.js +146 -141
- package/lib/components/fields/SchemaField.d.ts +1 -0
- package/lib/components/fields/SchemaField.d.ts.map +1 -0
- package/lib/components/fields/SchemaField.js +10 -20
- package/lib/components/fields/StringField.d.ts +1 -0
- package/lib/components/fields/StringField.d.ts.map +1 -0
- package/lib/components/fields/StringField.js +1 -3
- package/lib/components/fields/index.d.ts +1 -0
- package/lib/components/fields/index.d.ts.map +1 -0
- package/lib/components/fields/index.js +14 -9
- package/lib/components/templates/ArrayFieldDescriptionTemplate.d.ts +1 -0
- package/lib/components/templates/ArrayFieldDescriptionTemplate.d.ts.map +1 -0
- package/lib/components/templates/ArrayFieldDescriptionTemplate.js +0 -1
- package/lib/components/templates/ArrayFieldItemButtonsTemplate.d.ts +8 -0
- package/lib/components/templates/ArrayFieldItemButtonsTemplate.d.ts.map +1 -0
- package/lib/components/templates/ArrayFieldItemButtonsTemplate.js +17 -0
- package/lib/components/templates/ArrayFieldItemTemplate.d.ts +4 -3
- package/lib/components/templates/ArrayFieldItemTemplate.d.ts.map +1 -0
- package/lib/components/templates/ArrayFieldItemTemplate.js +7 -6
- package/lib/components/templates/ArrayFieldTemplate.d.ts +2 -1
- package/lib/components/templates/ArrayFieldTemplate.d.ts.map +1 -0
- package/lib/components/templates/ArrayFieldTemplate.js +3 -4
- package/lib/components/templates/ArrayFieldTitleTemplate.d.ts +1 -0
- package/lib/components/templates/ArrayFieldTitleTemplate.d.ts.map +1 -0
- package/lib/components/templates/ArrayFieldTitleTemplate.js +0 -1
- package/lib/components/templates/BaseInputTemplate.d.ts +1 -0
- package/lib/components/templates/BaseInputTemplate.d.ts.map +1 -0
- package/lib/components/templates/BaseInputTemplate.js +0 -1
- package/lib/components/templates/ButtonTemplates/AddButton.d.ts +1 -0
- package/lib/components/templates/ButtonTemplates/AddButton.d.ts.map +1 -0
- package/lib/components/templates/ButtonTemplates/AddButton.js +1 -2
- package/lib/components/templates/ButtonTemplates/IconButton.d.ts +1 -0
- package/lib/components/templates/ButtonTemplates/IconButton.d.ts.map +1 -0
- package/lib/components/templates/ButtonTemplates/IconButton.js +4 -5
- package/lib/components/templates/ButtonTemplates/SubmitButton.d.ts +1 -0
- package/lib/components/templates/ButtonTemplates/SubmitButton.d.ts.map +1 -0
- package/lib/components/templates/ButtonTemplates/SubmitButton.js +0 -1
- package/lib/components/templates/ButtonTemplates/index.d.ts +1 -0
- package/lib/components/templates/ButtonTemplates/index.d.ts.map +1 -0
- package/lib/components/templates/ButtonTemplates/index.js +3 -4
- package/lib/components/templates/DescriptionField.d.ts +1 -0
- package/lib/components/templates/DescriptionField.d.ts.map +1 -0
- package/lib/components/templates/DescriptionField.js +3 -8
- package/lib/components/templates/ErrorList.d.ts +1 -0
- package/lib/components/templates/ErrorList.d.ts.map +1 -0
- package/lib/components/templates/ErrorList.js +0 -1
- package/lib/components/templates/FieldErrorTemplate.d.ts +1 -0
- package/lib/components/templates/FieldErrorTemplate.d.ts.map +1 -0
- package/lib/components/templates/FieldErrorTemplate.js +0 -1
- package/lib/components/templates/FieldHelpTemplate.d.ts +1 -0
- package/lib/components/templates/FieldHelpTemplate.d.ts.map +1 -0
- package/lib/components/templates/FieldHelpTemplate.js +0 -1
- package/lib/components/templates/FieldTemplate/FieldTemplate.d.ts +1 -0
- package/lib/components/templates/FieldTemplate/FieldTemplate.d.ts.map +1 -0
- package/lib/components/templates/FieldTemplate/FieldTemplate.js +1 -2
- package/lib/components/templates/FieldTemplate/Label.d.ts +1 -0
- package/lib/components/templates/FieldTemplate/Label.d.ts.map +1 -0
- package/lib/components/templates/FieldTemplate/Label.js +0 -1
- package/lib/components/templates/FieldTemplate/index.d.ts +2 -1
- package/lib/components/templates/FieldTemplate/index.d.ts.map +1 -0
- package/lib/components/templates/FieldTemplate/index.js +1 -2
- package/lib/components/templates/GridTemplate.d.ts +8 -0
- package/lib/components/templates/GridTemplate.d.ts.map +1 -0
- package/lib/components/templates/GridTemplate.js +10 -0
- package/lib/components/templates/ObjectFieldTemplate.d.ts +1 -0
- package/lib/components/templates/ObjectFieldTemplate.d.ts.map +1 -0
- package/lib/components/templates/ObjectFieldTemplate.js +2 -3
- package/lib/components/templates/TitleField.d.ts +1 -0
- package/lib/components/templates/TitleField.d.ts.map +1 -0
- package/lib/components/templates/TitleField.js +0 -1
- package/lib/components/templates/UnsupportedField.d.ts +1 -0
- package/lib/components/templates/UnsupportedField.d.ts.map +1 -0
- package/lib/components/templates/UnsupportedField.js +0 -1
- package/lib/components/templates/WrapIfAdditionalTemplate.d.ts +1 -0
- package/lib/components/templates/WrapIfAdditionalTemplate.d.ts.map +1 -0
- package/lib/components/templates/WrapIfAdditionalTemplate.js +10 -6
- package/lib/components/templates/index.d.ts +1 -0
- package/lib/components/templates/index.d.ts.map +1 -0
- package/lib/components/templates/index.js +19 -16
- package/lib/components/widgets/AltDateTimeWidget.d.ts +1 -0
- package/lib/components/widgets/AltDateTimeWidget.d.ts.map +1 -0
- package/lib/components/widgets/AltDateTimeWidget.js +0 -1
- package/lib/components/widgets/AltDateWidget.d.ts +1 -0
- package/lib/components/widgets/AltDateWidget.d.ts.map +1 -0
- package/lib/components/widgets/AltDateWidget.js +0 -1
- package/lib/components/widgets/CheckboxWidget.d.ts +1 -0
- package/lib/components/widgets/CheckboxWidget.d.ts.map +1 -0
- package/lib/components/widgets/CheckboxWidget.js +2 -4
- package/lib/components/widgets/CheckboxesWidget.d.ts +1 -0
- package/lib/components/widgets/CheckboxesWidget.d.ts.map +1 -0
- package/lib/components/widgets/CheckboxesWidget.js +0 -1
- package/lib/components/widgets/ColorWidget.d.ts +1 -0
- package/lib/components/widgets/ColorWidget.d.ts.map +1 -0
- package/lib/components/widgets/ColorWidget.js +0 -1
- package/lib/components/widgets/DateTimeWidget.d.ts +1 -0
- package/lib/components/widgets/DateTimeWidget.d.ts.map +1 -0
- package/lib/components/widgets/DateTimeWidget.js +0 -1
- package/lib/components/widgets/DateWidget.d.ts +1 -0
- package/lib/components/widgets/DateWidget.d.ts.map +1 -0
- package/lib/components/widgets/DateWidget.js +0 -1
- package/lib/components/widgets/EmailWidget.d.ts +1 -0
- package/lib/components/widgets/EmailWidget.d.ts.map +1 -0
- package/lib/components/widgets/EmailWidget.js +0 -1
- package/lib/components/widgets/FileWidget.d.ts +1 -0
- package/lib/components/widgets/FileWidget.d.ts.map +1 -0
- package/lib/components/widgets/FileWidget.js +3 -5
- package/lib/components/widgets/HiddenWidget.d.ts +1 -0
- package/lib/components/widgets/HiddenWidget.d.ts.map +1 -0
- package/lib/components/widgets/HiddenWidget.js +0 -1
- package/lib/components/widgets/PasswordWidget.d.ts +1 -0
- package/lib/components/widgets/PasswordWidget.d.ts.map +1 -0
- package/lib/components/widgets/PasswordWidget.js +0 -1
- package/lib/components/widgets/RadioWidget.d.ts +1 -0
- package/lib/components/widgets/RadioWidget.d.ts.map +1 -0
- package/lib/components/widgets/RadioWidget.js +3 -4
- package/lib/components/widgets/RangeWidget.d.ts +1 -0
- package/lib/components/widgets/RangeWidget.d.ts.map +1 -0
- package/lib/components/widgets/RangeWidget.js +0 -1
- package/lib/components/widgets/RatingWidget.d.ts +15 -0
- package/lib/components/widgets/RatingWidget.d.ts.map +1 -0
- package/lib/components/widgets/RatingWidget.js +63 -0
- package/lib/components/widgets/SelectWidget.d.ts +1 -0
- package/lib/components/widgets/SelectWidget.d.ts.map +1 -0
- package/lib/components/widgets/SelectWidget.js +4 -5
- package/lib/components/widgets/TextWidget.d.ts +1 -0
- package/lib/components/widgets/TextWidget.d.ts.map +1 -0
- package/lib/components/widgets/TextWidget.js +0 -1
- package/lib/components/widgets/TextareaWidget.d.ts +1 -0
- package/lib/components/widgets/TextareaWidget.d.ts.map +1 -0
- package/lib/components/widgets/TextareaWidget.js +0 -1
- package/lib/components/widgets/TimeWidget.d.ts +1 -0
- package/lib/components/widgets/TimeWidget.d.ts.map +1 -0
- package/lib/components/widgets/TimeWidget.js +0 -1
- package/lib/components/widgets/URLWidget.d.ts +1 -0
- package/lib/components/widgets/URLWidget.d.ts.map +1 -0
- package/lib/components/widgets/URLWidget.js +0 -1
- package/lib/components/widgets/UpDownWidget.d.ts +1 -0
- package/lib/components/widgets/UpDownWidget.d.ts.map +1 -0
- package/lib/components/widgets/UpDownWidget.js +0 -1
- package/lib/components/widgets/index.d.ts +1 -0
- package/lib/components/widgets/index.d.ts.map +1 -0
- package/lib/components/widgets/index.js +21 -20
- package/lib/getDefaultRegistry.d.ts +1 -0
- package/lib/getDefaultRegistry.d.ts.map +1 -0
- package/lib/getDefaultRegistry.js +3 -4
- package/lib/index.d.ts +7 -5
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +5 -5
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/withTheme.d.ts +2 -1
- package/lib/withTheme.d.ts.map +1 -0
- package/lib/withTheme.js +7 -8
- package/package.json +46 -37
- package/src/components/Form.tsx +127 -41
- package/src/components/RichDescription.tsx +50 -0
- package/src/components/fields/ArrayField.tsx +34 -24
- package/src/components/fields/BooleanField.tsx +6 -14
- package/src/components/fields/LayoutGridField.tsx +967 -0
- package/src/components/fields/LayoutHeaderField.tsx +49 -0
- package/src/components/fields/LayoutMultiSchemaField.tsx +228 -0
- package/src/components/fields/MultiSchemaField.tsx +9 -4
- package/src/components/fields/NullField.tsx +1 -1
- package/src/components/fields/NumberField.tsx +5 -5
- package/src/components/fields/ObjectField.tsx +32 -24
- package/src/components/fields/SchemaField.tsx +17 -30
- package/src/components/fields/StringField.tsx +2 -2
- package/src/components/fields/index.ts +7 -1
- package/src/components/templates/ArrayFieldDescriptionTemplate.tsx +2 -2
- package/src/components/templates/ArrayFieldItemButtonsTemplate.tsx +85 -0
- package/src/components/templates/ArrayFieldItemTemplate.tsx +18 -57
- package/src/components/templates/ArrayFieldTemplate.tsx +10 -8
- package/src/components/templates/ArrayFieldTitleTemplate.tsx +2 -2
- package/src/components/templates/BaseInputTemplate.tsx +4 -4
- package/src/components/templates/ButtonTemplates/IconButton.tsx +9 -36
- package/src/components/templates/ButtonTemplates/SubmitButton.tsx +1 -1
- package/src/components/templates/ButtonTemplates/index.ts +1 -1
- package/src/components/templates/DescriptionField.tsx +9 -15
- package/src/components/templates/FieldErrorTemplate.tsx +1 -1
- package/src/components/templates/FieldHelpTemplate.tsx +1 -1
- package/src/components/templates/FieldTemplate/FieldTemplate.tsx +2 -2
- package/src/components/templates/GridTemplate.tsx +15 -0
- package/src/components/templates/ObjectFieldTemplate.tsx +5 -3
- package/src/components/templates/TitleField.tsx +1 -1
- package/src/components/templates/UnsupportedField.tsx +1 -1
- package/src/components/templates/WrapIfAdditionalTemplate.tsx +14 -4
- package/src/components/templates/index.ts +4 -0
- package/src/components/widgets/AltDateWidget.tsx +9 -6
- package/src/components/widgets/CheckboxWidget.tsx +5 -5
- package/src/components/widgets/CheckboxesWidget.tsx +2 -2
- package/src/components/widgets/ColorWidget.tsx +1 -1
- package/src/components/widgets/DateTimeWidget.tsx +1 -1
- package/src/components/widgets/DateWidget.tsx +1 -1
- package/src/components/widgets/EmailWidget.tsx +1 -1
- package/src/components/widgets/FileWidget.tsx +5 -5
- package/src/components/widgets/PasswordWidget.tsx +1 -1
- package/src/components/widgets/RadioWidget.tsx +3 -3
- package/src/components/widgets/RangeWidget.tsx +1 -1
- package/src/components/widgets/RatingWidget.tsx +129 -0
- package/src/components/widgets/SelectWidget.tsx +4 -3
- package/src/components/widgets/TextWidget.tsx +1 -1
- package/src/components/widgets/TextareaWidget.tsx +3 -3
- package/src/components/widgets/TimeWidget.tsx +1 -1
- package/src/components/widgets/URLWidget.tsx +1 -1
- package/src/components/widgets/UpDownWidget.tsx +1 -1
- package/src/components/widgets/index.ts +3 -1
- package/src/getDefaultRegistry.ts +1 -1
- package/src/index.ts +3 -2
- package/src/tsconfig.json +14 -6
- package/src/withTheme.tsx +4 -3
- package/LICENSE.md +0 -201
- package/lib/components/Form.js.map +0 -1
- package/lib/components/fields/ArrayField.js.map +0 -1
- package/lib/components/fields/BooleanField.js.map +0 -1
- package/lib/components/fields/MultiSchemaField.js.map +0 -1
- package/lib/components/fields/NullField.js.map +0 -1
- package/lib/components/fields/NumberField.js.map +0 -1
- package/lib/components/fields/ObjectField.js.map +0 -1
- package/lib/components/fields/SchemaField.js.map +0 -1
- package/lib/components/fields/StringField.js.map +0 -1
- package/lib/components/fields/index.js.map +0 -1
- package/lib/components/templates/ArrayFieldDescriptionTemplate.js.map +0 -1
- package/lib/components/templates/ArrayFieldItemTemplate.js.map +0 -1
- package/lib/components/templates/ArrayFieldTemplate.js.map +0 -1
- package/lib/components/templates/ArrayFieldTitleTemplate.js.map +0 -1
- package/lib/components/templates/BaseInputTemplate.js.map +0 -1
- package/lib/components/templates/ButtonTemplates/AddButton.js.map +0 -1
- package/lib/components/templates/ButtonTemplates/IconButton.js.map +0 -1
- package/lib/components/templates/ButtonTemplates/SubmitButton.js.map +0 -1
- package/lib/components/templates/ButtonTemplates/index.js.map +0 -1
- package/lib/components/templates/DescriptionField.js.map +0 -1
- package/lib/components/templates/ErrorList.js.map +0 -1
- package/lib/components/templates/FieldErrorTemplate.js.map +0 -1
- package/lib/components/templates/FieldHelpTemplate.js.map +0 -1
- package/lib/components/templates/FieldTemplate/FieldTemplate.js.map +0 -1
- package/lib/components/templates/FieldTemplate/Label.js.map +0 -1
- package/lib/components/templates/FieldTemplate/index.js.map +0 -1
- package/lib/components/templates/ObjectFieldTemplate.js.map +0 -1
- package/lib/components/templates/TitleField.js.map +0 -1
- package/lib/components/templates/UnsupportedField.js.map +0 -1
- package/lib/components/templates/WrapIfAdditionalTemplate.js.map +0 -1
- package/lib/components/templates/index.js.map +0 -1
- package/lib/components/widgets/AltDateTimeWidget.js.map +0 -1
- package/lib/components/widgets/AltDateWidget.js.map +0 -1
- package/lib/components/widgets/CheckboxWidget.js.map +0 -1
- package/lib/components/widgets/CheckboxesWidget.js.map +0 -1
- package/lib/components/widgets/ColorWidget.js.map +0 -1
- package/lib/components/widgets/DateTimeWidget.js.map +0 -1
- package/lib/components/widgets/DateWidget.js.map +0 -1
- package/lib/components/widgets/EmailWidget.js.map +0 -1
- package/lib/components/widgets/FileWidget.js.map +0 -1
- package/lib/components/widgets/HiddenWidget.js.map +0 -1
- package/lib/components/widgets/PasswordWidget.js.map +0 -1
- package/lib/components/widgets/RadioWidget.js.map +0 -1
- package/lib/components/widgets/RangeWidget.js.map +0 -1
- package/lib/components/widgets/SelectWidget.js.map +0 -1
- package/lib/components/widgets/TextWidget.js.map +0 -1
- package/lib/components/widgets/TextareaWidget.js.map +0 -1
- package/lib/components/widgets/TimeWidget.js.map +0 -1
- package/lib/components/widgets/URLWidget.js.map +0 -1
- package/lib/components/widgets/UpDownWidget.js.map +0 -1
- package/lib/components/widgets/index.js.map +0 -1
- package/lib/getDefaultRegistry.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/withTheme.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rjsf/core",
|
|
3
|
-
"version": "6.0.0-
|
|
3
|
+
"version": "6.0.0-beta.2",
|
|
4
4
|
"description": "A simple React component capable of building HTML forms out of a JSON schema.",
|
|
5
5
|
"scripts": {
|
|
6
|
-
"
|
|
6
|
+
"compileReplacer": "tsc -p tsconfig.replacer.json && move-file lodashReplacer.js lodashReplacer.cjs",
|
|
7
|
+
"build:ts": "npm run compileReplacer && rimraf ./lib && tsc -b tsconfig.build.json && tsc-alias -p tsconfig.build.json",
|
|
7
8
|
"build:cjs": "esbuild ./src/index.ts --bundle --outfile=dist/index.js --sourcemap --packages=external --format=cjs",
|
|
8
9
|
"build:esm": "esbuild ./src/index.ts --bundle --outfile=dist/index.esm.js --sourcemap --packages=external --format=esm",
|
|
9
10
|
"build:umd": "rollup dist/index.esm.js --format=umd --file=dist/core.umd.js --name=JSONSchemaForm",
|
|
@@ -14,7 +15,7 @@
|
|
|
14
15
|
"precommit": "lint-staged",
|
|
15
16
|
"publish-to-npm": "npm run build && npm publish",
|
|
16
17
|
"test": "jest",
|
|
17
|
-
"test:debug": "node --inspect-brk node_modules/.bin/jest",
|
|
18
|
+
"test:debug": "node --inspect-brk ../../node_modules/.bin/jest",
|
|
18
19
|
"test:update": "jest --u",
|
|
19
20
|
"test:watch": "jest --watch",
|
|
20
21
|
"test-coverage": "jest --coverage"
|
|
@@ -27,6 +28,34 @@
|
|
|
27
28
|
"main": "dist/index.js",
|
|
28
29
|
"module": "lib/index.js",
|
|
29
30
|
"typings": "lib/index.d.ts",
|
|
31
|
+
"type": "module",
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"types": "./lib/index.d.ts",
|
|
35
|
+
"require": "./dist/index.js",
|
|
36
|
+
"import": "./lib/index.js"
|
|
37
|
+
},
|
|
38
|
+
"./lib": {
|
|
39
|
+
"types": "./lib/index.d.ts",
|
|
40
|
+
"require": "./dist/index.js",
|
|
41
|
+
"import": "./lib/index.js"
|
|
42
|
+
},
|
|
43
|
+
"./lib/*.js": {
|
|
44
|
+
"types": "./lib/*.d.ts",
|
|
45
|
+
"require": "./dist/*.js",
|
|
46
|
+
"import": "./lib/*.js"
|
|
47
|
+
},
|
|
48
|
+
"./dist": {
|
|
49
|
+
"types": "./lib/index.d.ts",
|
|
50
|
+
"require": "./dist/index.js",
|
|
51
|
+
"import": "./lib/index.js"
|
|
52
|
+
},
|
|
53
|
+
"./dist/*.js": {
|
|
54
|
+
"types": "./lib/*.d.ts",
|
|
55
|
+
"require": "./dist/*.js",
|
|
56
|
+
"import": "./lib/*.js"
|
|
57
|
+
}
|
|
58
|
+
},
|
|
30
59
|
"files": [
|
|
31
60
|
"dist",
|
|
32
61
|
"lib",
|
|
@@ -34,54 +63,35 @@
|
|
|
34
63
|
],
|
|
35
64
|
"engineStrict": false,
|
|
36
65
|
"engines": {
|
|
37
|
-
"node": ">=
|
|
66
|
+
"node": ">=20"
|
|
38
67
|
},
|
|
39
68
|
"peerDependencies": {
|
|
40
|
-
"@rjsf/utils": "^
|
|
41
|
-
"react": "
|
|
69
|
+
"@rjsf/utils": "^6.0.0-beta.x",
|
|
70
|
+
"react": ">=18"
|
|
42
71
|
},
|
|
43
72
|
"dependencies": {
|
|
44
73
|
"lodash": "^4.17.21",
|
|
45
74
|
"lodash-es": "^4.17.21",
|
|
46
|
-
"markdown-to-jsx": "^7.
|
|
47
|
-
"nanoid": "^
|
|
75
|
+
"markdown-to-jsx": "^7.7.6",
|
|
76
|
+
"nanoid": "^5.1.5",
|
|
48
77
|
"prop-types": "^15.8.1"
|
|
49
78
|
},
|
|
50
79
|
"devDependencies": {
|
|
51
|
-
"@
|
|
52
|
-
"@
|
|
53
|
-
"@
|
|
54
|
-
"@
|
|
55
|
-
"@
|
|
56
|
-
"@
|
|
57
|
-
"@rjsf/snapshot-tests": "^6.0.0-alpha.0",
|
|
58
|
-
"@rjsf/utils": "^6.0.0-alpha.0",
|
|
59
|
-
"@rjsf/validator-ajv6": "^6.0.0-alpha.0",
|
|
60
|
-
"@rjsf/validator-ajv8": "^6.0.0-alpha.0",
|
|
61
|
-
"@types/jest": "^29.5.12",
|
|
62
|
-
"@types/lodash": "^4.14.202",
|
|
63
|
-
"@types/react": "^18.2.58",
|
|
64
|
-
"@types/react-dom": "^18.2.19",
|
|
65
|
-
"@types/react-test-renderer": "^18.0.7",
|
|
80
|
+
"@rjsf/snapshot-tests": "^6.0.0-beta.2",
|
|
81
|
+
"@rjsf/utils": "^6.0.0-beta.2",
|
|
82
|
+
"@rjsf/validator-ajv8": "^6.0.0-beta.2",
|
|
83
|
+
"@testing-library/jest-dom": "^6.6.3",
|
|
84
|
+
"@testing-library/react": "^16.2.0",
|
|
85
|
+
"@testing-library/user-event": "^14.6.1",
|
|
66
86
|
"ajv": "^8.12.0",
|
|
67
87
|
"atob": "^2.1.2",
|
|
68
|
-
"babel-jest": "^29.7.0",
|
|
69
88
|
"chai": "^3.5.0",
|
|
70
|
-
"esbuild": "^0.18.20",
|
|
71
89
|
"eslint": "^8.56.0",
|
|
72
90
|
"html": "^1.0.0",
|
|
73
|
-
"jest": "^29.7.0",
|
|
74
|
-
"jest-environment-jsdom": "^29.7.0",
|
|
75
91
|
"jsdom": "^20.0.3",
|
|
76
92
|
"mocha": "^10.2.0",
|
|
77
|
-
"react": "^
|
|
78
|
-
"
|
|
79
|
-
"react-portal": "^4.2.2",
|
|
80
|
-
"react-test-renderer": "^18.2.0",
|
|
81
|
-
"rimraf": "^5.0.5",
|
|
82
|
-
"rollup": "^3.29.4",
|
|
83
|
-
"sinon": "^9.2.4",
|
|
84
|
-
"typescript": "^4.9.5"
|
|
93
|
+
"react-portal": "^4.3.0",
|
|
94
|
+
"sinon": "^9.2.4"
|
|
85
95
|
},
|
|
86
96
|
"directories": {
|
|
87
97
|
"test": "test"
|
|
@@ -103,6 +113,5 @@
|
|
|
103
113
|
"homepage": "https://github.com/rjsf-team/react-jsonschema-form",
|
|
104
114
|
"publishConfig": {
|
|
105
115
|
"access": "public"
|
|
106
|
-
}
|
|
107
|
-
"gitHead": "f4229bf6e067d31b24de3ef9d3ca754ee52529ac"
|
|
116
|
+
}
|
|
108
117
|
}
|
package/src/components/Form.tsx
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
ErrorTransformer,
|
|
8
8
|
FormContextType,
|
|
9
9
|
GenericObjectType,
|
|
10
|
+
getChangedFields,
|
|
10
11
|
getTemplate,
|
|
11
12
|
getUiOptions,
|
|
12
13
|
IdSchema,
|
|
@@ -33,10 +34,14 @@ import {
|
|
|
33
34
|
validationDataMerge,
|
|
34
35
|
ValidatorType,
|
|
35
36
|
Experimental_DefaultFormStateBehavior,
|
|
37
|
+
Experimental_CustomMergeAllOf,
|
|
38
|
+
createErrorHandler,
|
|
39
|
+
unwrapErrorHandler,
|
|
36
40
|
} from '@rjsf/utils';
|
|
37
41
|
import _forEach from 'lodash/forEach';
|
|
38
42
|
import _get from 'lodash/get';
|
|
39
43
|
import _isEmpty from 'lodash/isEmpty';
|
|
44
|
+
import _isNil from 'lodash/isNil';
|
|
40
45
|
import _pick from 'lodash/pick';
|
|
41
46
|
import _toPath from 'lodash/toPath';
|
|
42
47
|
|
|
@@ -111,11 +116,6 @@ export interface FormProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
|
|
|
111
116
|
* an `onFocus` handler, which will receive the id of the input that is focused and the field value
|
|
112
117
|
*/
|
|
113
118
|
onFocus?: (id: string, data: any) => void;
|
|
114
|
-
// <form /> HTML attributes
|
|
115
|
-
/** The value of this prop will be passed to the `accept-charset` HTML attribute on the form
|
|
116
|
-
* @deprecated replaced with `acceptCharset` which will supercede this value if both are specified
|
|
117
|
-
*/
|
|
118
|
-
acceptcharset?: string;
|
|
119
119
|
/** The value of this prop will be passed to the `accept-charset` HTML attribute on the form */
|
|
120
120
|
acceptCharset?: string;
|
|
121
121
|
/** The value of this prop will be passed to the `action` HTML attribute on the form
|
|
@@ -195,6 +195,9 @@ export interface FormProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
|
|
|
195
195
|
* `emptyObjectFields`
|
|
196
196
|
*/
|
|
197
197
|
experimental_defaultFormStateBehavior?: Experimental_DefaultFormStateBehavior;
|
|
198
|
+
/** Optional function that allows for custom merging of `allOf` schemas
|
|
199
|
+
*/
|
|
200
|
+
experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>;
|
|
198
201
|
// Private
|
|
199
202
|
/**
|
|
200
203
|
* _internalFormWrapper is currently used by the semantic-ui theme to provide a custom wrapper around `<Form />`
|
|
@@ -261,7 +264,7 @@ export interface IChangeEvent<T = any, S extends StrictRJSFSchema = RJSFSchema,
|
|
|
261
264
|
export default class Form<
|
|
262
265
|
T = any,
|
|
263
266
|
S extends StrictRJSFSchema = RJSFSchema,
|
|
264
|
-
F extends FormContextType = any
|
|
267
|
+
F extends FormContextType = any,
|
|
265
268
|
> extends Component<FormProps<T, S, F>, FormState<T, S, F>> {
|
|
266
269
|
/** The ref used to hold the `form` element, this needs to be `any` because `tagName` or `_internalFormWrapper` can
|
|
267
270
|
* provide any possible type here
|
|
@@ -308,11 +311,15 @@ export default class Form<
|
|
|
308
311
|
*/
|
|
309
312
|
getSnapshotBeforeUpdate(
|
|
310
313
|
prevProps: FormProps<T, S, F>,
|
|
311
|
-
prevState: FormState<T, S, F
|
|
314
|
+
prevState: FormState<T, S, F>,
|
|
312
315
|
): { nextState: FormState<T, S, F>; shouldUpdate: true } | { shouldUpdate: false } {
|
|
313
316
|
if (!deepEquals(this.props, prevProps)) {
|
|
317
|
+
const formDataChangedFields = getChangedFields(this.props.formData, prevProps.formData);
|
|
314
318
|
const isSchemaChanged = !deepEquals(prevProps.schema, this.props.schema);
|
|
315
|
-
|
|
319
|
+
// When formData is not an object, getChangedFields returns an empty array.
|
|
320
|
+
// In this case, deepEquals is most needed to check again.
|
|
321
|
+
const isFormDataChanged =
|
|
322
|
+
formDataChangedFields.length > 0 || !deepEquals(prevProps.formData, this.props.formData);
|
|
316
323
|
const nextState = this.getStateFromProps(
|
|
317
324
|
this.props,
|
|
318
325
|
this.props.formData,
|
|
@@ -320,7 +327,8 @@ export default class Form<
|
|
|
320
327
|
// Or if the `formData` changes, for example in the case of a schema with dependencies that need to
|
|
321
328
|
// match one of the subSchemas, the retrieved schema must be updated.
|
|
322
329
|
isSchemaChanged || isFormDataChanged ? undefined : this.state.retrievedSchema,
|
|
323
|
-
isSchemaChanged
|
|
330
|
+
isSchemaChanged,
|
|
331
|
+
formDataChangedFields,
|
|
324
332
|
);
|
|
325
333
|
const shouldUpdate = !deepEquals(nextState, prevState);
|
|
326
334
|
return { nextState, shouldUpdate };
|
|
@@ -336,9 +344,6 @@ export default class Form<
|
|
|
336
344
|
* If an update is required, it applies the next state and, if needed, triggers the `onChange` handler to inform about
|
|
337
345
|
* changes.
|
|
338
346
|
*
|
|
339
|
-
* This method effectively replaces the deprecated `UNSAFE_componentWillReceiveProps`, providing a safer alternative
|
|
340
|
-
* to handle prop changes and state updates.
|
|
341
|
-
*
|
|
342
347
|
* @param _ - The previous set of props.
|
|
343
348
|
* @param prevState - The previous state of the component before the update.
|
|
344
349
|
* @param snapshot - The value returned from `getSnapshotBeforeUpdate`.
|
|
@@ -346,7 +351,7 @@ export default class Form<
|
|
|
346
351
|
componentDidUpdate(
|
|
347
352
|
_: FormProps<T, S, F>,
|
|
348
353
|
prevState: FormState<T, S, F>,
|
|
349
|
-
snapshot: { nextState: FormState<T, S, F>; shouldUpdate: true } | { shouldUpdate: false }
|
|
354
|
+
snapshot: { nextState: FormState<T, S, F>; shouldUpdate: true } | { shouldUpdate: false },
|
|
350
355
|
) {
|
|
351
356
|
if (snapshot.shouldUpdate) {
|
|
352
357
|
const { nextState } = snapshot;
|
|
@@ -370,13 +375,15 @@ export default class Form<
|
|
|
370
375
|
* @param inputFormData - The new or current data for the `Form`
|
|
371
376
|
* @param retrievedSchema - An expanded schema, if not provided, it will be retrieved from the `schema` and `formData`.
|
|
372
377
|
* @param isSchemaChanged - A flag indicating whether the schema has changed.
|
|
378
|
+
* @param formDataChangedFields - The changed fields of `formData`
|
|
373
379
|
* @returns - The new state for the `Form`
|
|
374
380
|
*/
|
|
375
381
|
getStateFromProps(
|
|
376
382
|
props: FormProps<T, S, F>,
|
|
377
383
|
inputFormData?: T,
|
|
378
384
|
retrievedSchema?: S,
|
|
379
|
-
isSchemaChanged = false
|
|
385
|
+
isSchemaChanged = false,
|
|
386
|
+
formDataChangedFields: string[] = [],
|
|
380
387
|
): FormState<T, S, F> {
|
|
381
388
|
const state: FormState<T, S, F> = this.state || {};
|
|
382
389
|
const schema = 'schema' in props ? props.schema : this.props.schema;
|
|
@@ -389,15 +396,31 @@ export default class Form<
|
|
|
389
396
|
'experimental_defaultFormStateBehavior' in props
|
|
390
397
|
? props.experimental_defaultFormStateBehavior
|
|
391
398
|
: this.props.experimental_defaultFormStateBehavior;
|
|
399
|
+
const experimental_customMergeAllOf =
|
|
400
|
+
'experimental_customMergeAllOf' in props
|
|
401
|
+
? props.experimental_customMergeAllOf
|
|
402
|
+
: this.props.experimental_customMergeAllOf;
|
|
392
403
|
let schemaUtils: SchemaUtilsType<T, S, F> = state.schemaUtils;
|
|
393
404
|
if (
|
|
394
405
|
!schemaUtils ||
|
|
395
|
-
schemaUtils.doesSchemaUtilsDiffer(
|
|
406
|
+
schemaUtils.doesSchemaUtilsDiffer(
|
|
407
|
+
props.validator,
|
|
408
|
+
rootSchema,
|
|
409
|
+
experimental_defaultFormStateBehavior,
|
|
410
|
+
experimental_customMergeAllOf,
|
|
411
|
+
)
|
|
396
412
|
) {
|
|
397
|
-
schemaUtils = createSchemaUtils<T, S, F>(
|
|
413
|
+
schemaUtils = createSchemaUtils<T, S, F>(
|
|
414
|
+
props.validator,
|
|
415
|
+
rootSchema,
|
|
416
|
+
experimental_defaultFormStateBehavior,
|
|
417
|
+
experimental_customMergeAllOf,
|
|
418
|
+
);
|
|
398
419
|
}
|
|
399
420
|
const formData: T = schemaUtils.getDefaultFormState(schema, inputFormData) as T;
|
|
400
|
-
const _retrievedSchema =
|
|
421
|
+
const _retrievedSchema = this.updateRetrievedSchema(
|
|
422
|
+
retrievedSchema ?? schemaUtils.retrieveSchema(schema, formData),
|
|
423
|
+
);
|
|
401
424
|
|
|
402
425
|
const getCurrentErrors = (): ValidationData<T> => {
|
|
403
426
|
// If the `props.noValidate` option is set or the schema has changed, we reset the error state.
|
|
@@ -422,15 +445,15 @@ export default class Form<
|
|
|
422
445
|
if (mustValidate) {
|
|
423
446
|
const schemaValidation = this.validate(formData, schema, schemaUtils, _retrievedSchema);
|
|
424
447
|
errors = schemaValidation.errors;
|
|
425
|
-
// If the schema has changed, we do not merge state.
|
|
448
|
+
// If retrievedSchema is undefined which means the schema or formData has changed, we do not merge state.
|
|
426
449
|
// Else in the case where it hasn't changed, we merge 'state.errorSchema' with 'schemaValidation.errorSchema.' This done to display the raised field error.
|
|
427
|
-
if (
|
|
450
|
+
if (retrievedSchema === undefined) {
|
|
428
451
|
errorSchema = schemaValidation.errorSchema;
|
|
429
452
|
} else {
|
|
430
453
|
errorSchema = mergeObjects(
|
|
431
454
|
this.state?.errorSchema,
|
|
432
455
|
schemaValidation.errorSchema,
|
|
433
|
-
'preventDuplicates'
|
|
456
|
+
'preventDuplicates',
|
|
434
457
|
) as ErrorSchema<T>;
|
|
435
458
|
}
|
|
436
459
|
schemaValidationErrors = errors;
|
|
@@ -439,7 +462,22 @@ export default class Form<
|
|
|
439
462
|
const currentErrors = getCurrentErrors();
|
|
440
463
|
errors = currentErrors.errors;
|
|
441
464
|
errorSchema = currentErrors.errorSchema;
|
|
465
|
+
if (formDataChangedFields.length > 0) {
|
|
466
|
+
const newErrorSchema = formDataChangedFields.reduce(
|
|
467
|
+
(acc, key) => {
|
|
468
|
+
acc[key] = undefined;
|
|
469
|
+
return acc;
|
|
470
|
+
},
|
|
471
|
+
{} as Record<string, undefined>,
|
|
472
|
+
);
|
|
473
|
+
errorSchema = schemaValidationErrorSchema = mergeObjects(
|
|
474
|
+
currentErrors.errorSchema,
|
|
475
|
+
newErrorSchema,
|
|
476
|
+
'preventDuplicates',
|
|
477
|
+
) as ErrorSchema<T>;
|
|
478
|
+
}
|
|
442
479
|
}
|
|
480
|
+
|
|
443
481
|
if (props.extraErrors) {
|
|
444
482
|
const merged = validationDataMerge({ errorSchema, errors }, props.extraErrors);
|
|
445
483
|
errorSchema = merged.errorSchema;
|
|
@@ -450,7 +488,7 @@ export default class Form<
|
|
|
450
488
|
uiSchema['ui:rootFieldId'],
|
|
451
489
|
formData,
|
|
452
490
|
props.idPrefix,
|
|
453
|
-
props.idSeparator
|
|
491
|
+
props.idSeparator,
|
|
454
492
|
);
|
|
455
493
|
const nextState: FormState<T, S, F> = {
|
|
456
494
|
schemaUtils,
|
|
@@ -478,6 +516,22 @@ export default class Form<
|
|
|
478
516
|
return shouldRender(this, nextProps, nextState);
|
|
479
517
|
}
|
|
480
518
|
|
|
519
|
+
/** Gets the previously raised customValidate errors.
|
|
520
|
+
*
|
|
521
|
+
* @returns the previous customValidate errors
|
|
522
|
+
*/
|
|
523
|
+
private getPreviousCustomValidateErrors(): ErrorSchema<T> {
|
|
524
|
+
const { customValidate, uiSchema } = this.props;
|
|
525
|
+
const prevFormData = this.state.formData as T;
|
|
526
|
+
let customValidateErrors = {};
|
|
527
|
+
if (typeof customValidate === 'function') {
|
|
528
|
+
const errorHandler = customValidate(prevFormData, createErrorHandler<T>(prevFormData), uiSchema);
|
|
529
|
+
const userErrorSchema = unwrapErrorHandler<T>(errorHandler);
|
|
530
|
+
customValidateErrors = userErrorSchema;
|
|
531
|
+
}
|
|
532
|
+
return customValidateErrors;
|
|
533
|
+
}
|
|
534
|
+
|
|
481
535
|
/** Validates the `formData` against the `schema` using the `altSchemaUtils` (if provided otherwise it uses the
|
|
482
536
|
* `schemaUtils` in the state), returning the results.
|
|
483
537
|
*
|
|
@@ -489,7 +543,7 @@ export default class Form<
|
|
|
489
543
|
formData: T | undefined,
|
|
490
544
|
schema = this.props.schema,
|
|
491
545
|
altSchemaUtils?: SchemaUtilsType<T, S, F>,
|
|
492
|
-
retrievedSchema?: S
|
|
546
|
+
retrievedSchema?: S,
|
|
493
547
|
): ValidationData<T> {
|
|
494
548
|
const schemaUtils = altSchemaUtils ? altSchemaUtils : this.state.schemaUtils;
|
|
495
549
|
const { customValidate, transformErrors, uiSchema } = this.props;
|
|
@@ -603,18 +657,39 @@ export default class Form<
|
|
|
603
657
|
if (resolvedSchema?.type !== 'object' && resolvedSchema?.type !== 'array') {
|
|
604
658
|
filteredErrors.__errors = schemaErrors.__errors;
|
|
605
659
|
}
|
|
606
|
-
|
|
607
|
-
const
|
|
608
|
-
|
|
609
|
-
|
|
660
|
+
|
|
661
|
+
const prevCustomValidateErrors = this.getPreviousCustomValidateErrors();
|
|
662
|
+
// Filtering out the previous raised customValidate errors so that they are cleared when no longer valid.
|
|
663
|
+
const filterPreviousCustomErrors = (errors: string[] = [], prevCustomErrors: string[]) => {
|
|
664
|
+
if (errors.length === 0) {
|
|
665
|
+
return errors;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
return errors.filter((error) => {
|
|
669
|
+
return !prevCustomErrors.includes(error);
|
|
670
|
+
});
|
|
671
|
+
};
|
|
672
|
+
|
|
673
|
+
// Removing undefined, null and empty errors.
|
|
674
|
+
const filterNilOrEmptyErrors = (errors: any, previousCustomValidateErrors: any = {}): ErrorSchema<T> => {
|
|
675
|
+
_forEach(errors, (errorAtKey: ErrorSchema<T>['__errors'] | undefined, errorKey: keyof typeof errors) => {
|
|
676
|
+
const prevCustomValidateErrorAtKey: ErrorSchema<T> | undefined = previousCustomValidateErrors[errorKey];
|
|
677
|
+
if (_isNil(errorAtKey) || (Array.isArray(errorAtKey) && errorAtKey.length === 0)) {
|
|
610
678
|
delete errors[errorKey];
|
|
679
|
+
} else if (
|
|
680
|
+
isObject(errorAtKey) &&
|
|
681
|
+
isObject(prevCustomValidateErrorAtKey) &&
|
|
682
|
+
Array.isArray(prevCustomValidateErrorAtKey?.__errors)
|
|
683
|
+
) {
|
|
684
|
+
// if previous customValidate error is an object and has __errors array, filter out the errors previous customValidate errors.
|
|
685
|
+
errors[errorKey] = filterPreviousCustomErrors(errorAtKey.__errors, prevCustomValidateErrorAtKey.__errors);
|
|
611
686
|
} else if (typeof errorAtKey === 'object' && !Array.isArray(errorAtKey.__errors)) {
|
|
612
|
-
|
|
687
|
+
filterNilOrEmptyErrors(errorAtKey, previousCustomValidateErrors[errorKey]);
|
|
613
688
|
}
|
|
614
689
|
});
|
|
615
690
|
return errors;
|
|
616
691
|
};
|
|
617
|
-
return
|
|
692
|
+
return filterNilOrEmptyErrors(filteredErrors, prevCustomValidateErrors);
|
|
618
693
|
}
|
|
619
694
|
|
|
620
695
|
/** Function to handle changes made to a field in the `Form`. This handler receives an entirely new copy of the
|
|
@@ -630,18 +705,19 @@ export default class Form<
|
|
|
630
705
|
*/
|
|
631
706
|
onChange = (formData: T | undefined, newErrorSchema?: ErrorSchema<T>, id?: string) => {
|
|
632
707
|
const { extraErrors, omitExtraData, liveOmit, noValidate, liveValidate, onChange } = this.props;
|
|
633
|
-
const { schemaUtils, schema
|
|
708
|
+
const { schemaUtils, schema } = this.state;
|
|
634
709
|
|
|
710
|
+
let retrievedSchema = this.state.retrievedSchema;
|
|
635
711
|
if (isObject(formData) || Array.isArray(formData)) {
|
|
636
|
-
const newState = this.getStateFromProps(this.props, formData
|
|
712
|
+
const newState = this.getStateFromProps(this.props, formData);
|
|
637
713
|
formData = newState.formData;
|
|
714
|
+
retrievedSchema = newState.retrievedSchema;
|
|
638
715
|
}
|
|
639
716
|
|
|
640
717
|
const mustValidate = !noValidate && liveValidate;
|
|
641
718
|
let state: Partial<FormState<T, S, F>> = { formData, schema };
|
|
642
719
|
let newFormData = formData;
|
|
643
720
|
|
|
644
|
-
let _retrievedSchema: S | undefined;
|
|
645
721
|
if (omitExtraData === true && liveOmit === true) {
|
|
646
722
|
newFormData = this.omitExtraData(formData);
|
|
647
723
|
state = {
|
|
@@ -682,12 +758,23 @@ export default class Form<
|
|
|
682
758
|
errors: toErrorList(errorSchema),
|
|
683
759
|
};
|
|
684
760
|
}
|
|
685
|
-
if (_retrievedSchema) {
|
|
686
|
-
state.retrievedSchema = _retrievedSchema;
|
|
687
|
-
}
|
|
688
761
|
this.setState(state as FormState<T, S, F>, () => onChange && onChange({ ...this.state, ...state }, id));
|
|
689
762
|
};
|
|
690
763
|
|
|
764
|
+
/**
|
|
765
|
+
* If the retrievedSchema has changed the new retrievedSchema is returned.
|
|
766
|
+
* Otherwise, the old retrievedSchema is returned to persist reference.
|
|
767
|
+
* - This ensures that AJV retrieves the schema from the cache when it has not changed,
|
|
768
|
+
* avoiding the performance cost of recompiling the schema.
|
|
769
|
+
*
|
|
770
|
+
* @param retrievedSchema The new retrieved schema.
|
|
771
|
+
* @returns The new retrieved schema if it has changed, else the old retrieved schema.
|
|
772
|
+
*/
|
|
773
|
+
private updateRetrievedSchema(retrievedSchema: S) {
|
|
774
|
+
const isTheSame = deepEquals(retrievedSchema, this.state?.retrievedSchema);
|
|
775
|
+
return isTheSame ? this.state.retrievedSchema : retrievedSchema;
|
|
776
|
+
}
|
|
777
|
+
|
|
691
778
|
/**
|
|
692
779
|
* Callback function to handle reset form data.
|
|
693
780
|
* - Reset all fields with default values.
|
|
@@ -774,7 +861,7 @@ export default class Form<
|
|
|
774
861
|
if (onSubmit) {
|
|
775
862
|
onSubmit({ ...this.state, formData: newFormData, status: 'submitted' }, event);
|
|
776
863
|
}
|
|
777
|
-
}
|
|
864
|
+
},
|
|
778
865
|
);
|
|
779
866
|
}
|
|
780
867
|
};
|
|
@@ -837,7 +924,7 @@ export default class Form<
|
|
|
837
924
|
let field = this.formElement.current.elements[elementId];
|
|
838
925
|
if (!field) {
|
|
839
926
|
// if not an exact match, try finding an input starting with the element id (like radio buttons or checkboxes)
|
|
840
|
-
field = this.formElement.current.querySelector(`input[id
|
|
927
|
+
field = this.formElement.current.querySelector(`input[id^="${elementId}"`);
|
|
841
928
|
}
|
|
842
929
|
if (field && field.length) {
|
|
843
930
|
// If we got a list with length > 0
|
|
@@ -889,7 +976,7 @@ export default class Form<
|
|
|
889
976
|
} else {
|
|
890
977
|
console.error('Form validation failed', errors);
|
|
891
978
|
}
|
|
892
|
-
}
|
|
979
|
+
},
|
|
893
980
|
);
|
|
894
981
|
} else if (prevErrors.length > 0) {
|
|
895
982
|
this.setState({
|
|
@@ -934,7 +1021,6 @@ export default class Form<
|
|
|
934
1021
|
action,
|
|
935
1022
|
autoComplete,
|
|
936
1023
|
enctype,
|
|
937
|
-
acceptcharset,
|
|
938
1024
|
acceptCharset,
|
|
939
1025
|
noHtml5Validate = false,
|
|
940
1026
|
disabled,
|
|
@@ -948,9 +1034,9 @@ export default class Form<
|
|
|
948
1034
|
const registry = this.getRegistry();
|
|
949
1035
|
const { SchemaField: _SchemaField } = registry.fields;
|
|
950
1036
|
const { SubmitButton } = registry.templates.ButtonTemplates;
|
|
951
|
-
// The `semantic-ui`
|
|
1037
|
+
// The `semantic-ui` and `material-ui` themes have `_internalFormWrapper`s that take an `as` prop that is the
|
|
952
1038
|
// PropTypes.elementType to use for the inner tag, so we'll need to pass `tagName` along if it is provided.
|
|
953
|
-
// NOTE, the `as` prop is native to `semantic-ui`
|
|
1039
|
+
// NOTE, the `as` prop is native to `semantic-ui` and is emulated in the `material-ui` theme
|
|
954
1040
|
const as = _internalFormWrapper ? tagName : undefined;
|
|
955
1041
|
const FormTag = _internalFormWrapper || tagName || 'form';
|
|
956
1042
|
|
|
@@ -970,7 +1056,7 @@ export default class Form<
|
|
|
970
1056
|
action={action}
|
|
971
1057
|
autoComplete={autoComplete}
|
|
972
1058
|
encType={enctype}
|
|
973
|
-
acceptCharset={acceptCharset
|
|
1059
|
+
acceptCharset={acceptCharset}
|
|
974
1060
|
noValidate={noHtml5Validate}
|
|
975
1061
|
onSubmit={this.onSubmit}
|
|
976
1062
|
as={as}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
FormContextType,
|
|
4
|
+
Registry,
|
|
5
|
+
RJSFSchema,
|
|
6
|
+
StrictRJSFSchema,
|
|
7
|
+
UiSchema,
|
|
8
|
+
getTestIds,
|
|
9
|
+
getUiOptions,
|
|
10
|
+
} from '@rjsf/utils';
|
|
11
|
+
import Markdown from 'markdown-to-jsx';
|
|
12
|
+
|
|
13
|
+
const TEST_IDS = getTestIds();
|
|
14
|
+
|
|
15
|
+
export interface RichDescriptionProps<
|
|
16
|
+
T = any,
|
|
17
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
18
|
+
F extends FormContextType = any,
|
|
19
|
+
> {
|
|
20
|
+
/** The description text for a field, potentially containing markdown */
|
|
21
|
+
description: string | ReactElement;
|
|
22
|
+
/** The uiSchema object for this base component */
|
|
23
|
+
uiSchema?: UiSchema<T, S, F>;
|
|
24
|
+
/** The `registry` object */
|
|
25
|
+
registry: Registry<T, S, F>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Renders the given `description` in the props as
|
|
29
|
+
*
|
|
30
|
+
* @param props - The `RichDescriptionProps` for this component
|
|
31
|
+
*/
|
|
32
|
+
export default function RichDescription<
|
|
33
|
+
T = any,
|
|
34
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
35
|
+
F extends FormContextType = any,
|
|
36
|
+
>({ description, registry, uiSchema = {} }: RichDescriptionProps<T, S, F>) {
|
|
37
|
+
const { globalUiOptions } = registry;
|
|
38
|
+
const uiOptions = getUiOptions<T, S, F>(uiSchema, globalUiOptions);
|
|
39
|
+
|
|
40
|
+
if (uiOptions.enableMarkdownInDescription && typeof description === 'string') {
|
|
41
|
+
return (
|
|
42
|
+
<Markdown options={{ disableParsingRawHTML: true }} data-testid={TEST_IDS.markdown}>
|
|
43
|
+
{description}
|
|
44
|
+
</Markdown>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
return description;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
RichDescription.TEST_IDS = TEST_IDS;
|