Skip to content

Commit dd1a4c7

Browse files
Updated antd theme to use new @rjsf/utils and @rjsf/validator
- Updated `package*.json` to add `@rjsf/utils` and `@rjsf/validator` to dev and peer dependencies - Also, Removed a bunch of packages that were never used since the conversion to `tsdx` - Finally, bumped most of the dev dependencies that made sense to the latest version, except for those that cause breaking tests - Removed the `webpack.config.*.js` files since they are no longer needed since the conversion to `tsdx` - Updated all uses of non-schema utilities methods to `@rjsf/utils` and switched to using `registry.schemaUtils.XXX()` for those schema-based utilities - Updated the import of `getDefaultRegistry()` to be directly from `@rjsf/core` - Modified `SelectWidget` to use the new `processSelectValue()` function from `@rjsf/utils` - Updated the tests to change to using `RJSFSchema` rather than `JSON7Schema` and import the `validator` from `@rjsf/validator` to pass to the `Form` - Also updated the snapshots via the `test:update` script to deal with the little differences from the conversion
1 parent ec33b7a commit dd1a4c7

File tree

19 files changed

+10873
-27621
lines changed

19 files changed

+10873
-27621
lines changed

packages/antd/package-lock.json

+10,808-27,369
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/antd/package.json

+22-34
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"build": "rimraf dist && tsdx build --format cjs,es,umd",
1010
"test": "tsdx test",
1111
"test:update": "tsdx test --u"
12-
},
12+
},
1313
"files": [
1414
"dist"
1515
],
@@ -24,52 +24,37 @@
2424
},
2525
"peerDependencies": {
2626
"@ant-design/icons": "^4.0.0",
27-
"@rjsf/core": "^4.0.0",
27+
"@rjsf/core": "^4.2.0",
28+
"@rjsf/utils": "^4.2.0",
2829
"antd": "^4.0.0",
29-
"antd-dayjs-webpack-plugin": "1.0.0",
3030
"dayjs": "^1.8.0",
31-
"lodash": "^4.17.15",
32-
"lodash-es": "^4.17.15",
3331
"react": ">=16"
3432
},
3533
"devDependencies": {
3634
"@ant-design/icons": "^4.0.0",
37-
"@babel/cli": "^7.4.4",
38-
"@babel/core": "^7.4.5",
39-
"@babel/plugin-proposal-class-properties": "^7.5.5",
40-
"@babel/plugin-transform-react-jsx": "^7.3.0",
41-
"@babel/preset-env": "^7.10.3",
42-
"@babel/preset-react": "^7.0.0",
43-
"@babel/register": "^7.4.4",
35+
"@babel/cli": "^7.18.6",
36+
"@babel/core": "^7.18.6",
37+
"@babel/plugin-proposal-class-properties": "^7.18.6",
38+
"@babel/plugin-transform-react-jsx": "^7.18.6",
39+
"@babel/preset-env": "^7.18.6",
40+
"@babel/preset-react": "^7.18.6",
41+
"@babel/register": "^7.18.6",
4442
"@rjsf/core": "^4.2.0",
43+
"@rjsf/utils": "^4.2.0",
44+
"@rjsf/validator-ajv6": "^4.2.0",
4545
"antd": "^4.0.0",
4646
"atob": "^2.0.3",
4747
"babel-eslint": "^10.0.1",
48-
"babel-loader": "^8.0.6",
49-
"concurrently": "^5.1.0",
50-
"cross-env": "^2.0.1",
51-
"css-loader": "^3.2.0",
52-
"dayjs": "^1.8.0",
53-
"eslint": "^4.9.0",
54-
"eslint-config-react-app": "^2.0.1",
55-
"eslint-plugin-flowtype": "^2.39.1",
56-
"eslint-plugin-import": "^2.21.2",
57-
"eslint-plugin-jsx-a11y": "^5.1.1",
58-
"eslint-plugin-react": "^7.4.0",
59-
"jest": "24.9.0",
60-
"less": "^3.10.3",
61-
"less-loader": "^5.0.0",
48+
"dayjs": "^1.11.3",
49+
"eslint": "^8.19.0",
50+
"eslint-plugin-import": "^2.26.0",
6251
"lodash": "^4.17.15",
6352
"lodash-es": "^4.17.15",
64-
"react": "^16.8.6",
65-
"react-dom": "^16.8.6",
66-
"react-test-renderer": "^16.13.1",
53+
"react": "^16.14.0",
54+
"react-dom": "^16.14.0",
55+
"react-test-renderer": "^16.14.0",
6756
"rimraf": "^3.0.2",
68-
"style-loader": "^2.0.0",
69-
"webpack": "^4.20.2",
70-
"webpack-cli": "^3.1.2",
71-
"webpack-dev-middleware": "^3.4.0",
72-
"webpack-hot-middleware": "^2.13.2"
57+
"tsdx": "^0.14.1"
7358
},
7459
"repository": {
7560
"type": "git",
@@ -86,6 +71,9 @@
8671
"rjsf-antd"
8772
],
8873
"author": "Delyan Ruskov <[email protected]>",
74+
"contributors": [
75+
"Heath Chiavettone <[email protected]"
76+
],
8977
"license": "Apache-2.0",
9078
"bugs": {
9179
"url": "https://github.com/rjsf-team/react-jsonschema-form/issues"

packages/antd/src/index.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { utils, withTheme } from '@rjsf/core';
1+
import { withTheme, getDefaultRegistry } from '@rjsf/core';
22

33
import DescriptionField from './fields/DescriptionField';
44
import TitleField from './fields/TitleField';
@@ -29,7 +29,6 @@ import ErrorList from './ErrorList';
2929

3030
// import './index.less';
3131

32-
const { getDefaultRegistry } = utils;
3332
const { fields, widgets } = getDefaultRegistry();
3433

3534
export const Fields = {

packages/antd/src/templates/ArrayFieldTemplate/index.js

+6-16
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
11
import React from 'react';
22

3-
import { utils } from '@rjsf/core';
3+
import { getUiOptions, getWidget, isFixedItems, optionsList, ITEMS_KEY } from '@rjsf/utils';
44

55
import FixedArrayFieldTemplate from './FixedArrayFieldTemplate';
66
import NormalArrayFieldTemplate from './NormalArrayFieldTemplate';
77

8-
const {
9-
getUiOptions,
10-
getWidget,
11-
isFilesArray,
12-
isFixedItems,
13-
isMultiSelect,
14-
optionsList,
15-
retrieveSchema,
16-
} = utils;
17-
188
const ArrayFieldTemplate = ({
199
DescriptionField,
2010
TitleField,
@@ -41,7 +31,7 @@ const ArrayFieldTemplate = ({
4131
title,
4232
uiSchema,
4333
}) => {
44-
const { fields, rootSchema, widgets } = registry;
34+
const { fields, schemaUtils, widgets } = registry;
4535
const { UnsupportedField } = fields;
4636

4737
const renderFiles = () => {
@@ -71,7 +61,7 @@ const ArrayFieldTemplate = ({
7161
};
7262

7363
const renderMultiSelect = () => {
74-
const itemsSchema = retrieveSchema(schema.items, rootSchema, formData);
64+
const itemsSchema = schemaUtils.retrieveSchema(schema.items, formData);
7565
const enumOptions = optionsList(itemsSchema);
7666
const { widget = 'select', ...options } = {
7767
...getUiOptions(uiSchema),
@@ -103,7 +93,7 @@ const ArrayFieldTemplate = ({
10393
);
10494
};
10595

106-
if (!Object.prototype.hasOwnProperty.call(schema, 'items')) {
96+
if (!(ITEMS_KEY in schema)) {
10797
return (
10898
<UnsupportedField
10999
idSchema={idSchema}
@@ -135,10 +125,10 @@ const ArrayFieldTemplate = ({
135125
/>
136126
);
137127
}
138-
if (isFilesArray(schema, uiSchema, rootSchema)) {
128+
if (schemaUtils.isFilesArray(schema, uiSchema)) {
139129
return renderFiles();
140130
}
141-
if (isMultiSelect(schema, rootSchema)) {
131+
if (schemaUtils.isMultiSelect(schema)) {
142132
return renderMultiSelect();
143133
}
144134

packages/antd/src/templates/FieldTemplate/WrapIfAdditional.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import React from 'react';
22

3-
import { utils } from '@rjsf/core';
3+
import { ADDITIONAL_PROPERTY_FLAG } from '@rjsf/utils';
44
import Button from 'antd/lib/button';
55
import Col from 'antd/lib/col';
66
import Form from 'antd/lib/form';
77
import Input from 'antd/lib/input';
88
import Row from 'antd/lib/row';
99
import DeleteOutlined from '@ant-design/icons/DeleteOutlined';
1010

11-
const { ADDITIONAL_PROPERTY_FLAG } = utils;
12-
1311
const VERTICAL_LABEL_COL = { span: 24 };
1412
const VERTICAL_WRAPPER_COL = { span: 24 };
1513

packages/antd/src/templates/ObjectFieldTemplate/index.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@ import React from 'react';
22
import classNames from 'classnames';
33
import _ from 'lodash';
44

5-
import { utils } from '@rjsf/core';
5+
import { canExpand } from '@rjsf/utils';
66
import Button from 'antd/lib/button';
77
import Col from 'antd/lib/col';
88
import Row from 'antd/lib/row';
99
import { withConfigConsumer } from 'antd/lib/config-provider/context';
1010
import PlusCircleOutlined from '@ant-design/icons/PlusCircleOutlined';
1111

12-
const { canExpand } = utils;
13-
1412
const DESCRIPTION_COL_STYLE = {
1513
paddingBottom: '8px',
1614
};

packages/antd/src/widgets/AltDateWidget/index.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import React, { useEffect, useState } from "react";
22

3-
import { utils } from '@rjsf/core';
3+
import { pad, parseDateString, toDateString } from '@rjsf/utils';
44
import Button from 'antd/lib/button';
55
import Col from 'antd/lib/col';
66
import Row from 'antd/lib/row';
77

8-
const { pad, parseDateString, toDateString } = utils;
9-
108
const rangeOptions = (start, stop) => {
119
let options = [];
1210
for (let i = start; i <= stop; i++) {

packages/antd/src/widgets/RangeWidget/index.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
/* eslint-disable no-else-return */
22
import React from 'react';
33

4-
import { utils } from '@rjsf/core';
4+
import { rangeSpec } from '@rjsf/utils';
55
import Slider from 'antd/lib/slider';
66

7-
const { rangeSpec } = utils;
8-
97
const RangeWidget = ({
108
autofocus,
119
disabled,

packages/antd/src/widgets/SelectWidget/index.js

+4-39
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,13 @@
11
/* eslint-disable no-else-return */
22
import React from 'react';
33

4-
import { utils } from '@rjsf/core';
4+
import { processSelectValue } from '@rjsf/utils';
55
import Select from 'antd/lib/select';
66

7-
const { asNumber, guessType } = utils;
8-
97
const SELECT_STYLE = {
108
width: '100%',
119
};
1210

13-
const nums = new Set(['number', 'integer']);
14-
15-
/**
16-
* This is a silly limitation in the DOM where option change event values are
17-
* always retrieved as strings.
18-
*/
19-
const processValue = (schema, value) => {
20-
// "enum" is a reserved word, so only "type" and "items" can be destructured
21-
const { type, items } = schema;
22-
23-
if (value === '') {
24-
return undefined;
25-
} else if (type === 'array' && items && nums.has(items.type)) {
26-
return value.map(asNumber);
27-
} else if (type === 'boolean') {
28-
return value === 'true';
29-
} else if (type === 'number') {
30-
return asNumber(value);
31-
}
32-
33-
// If type is undefined, but an enum is present, try and infer the type from
34-
// the enum values
35-
if (schema.enum) {
36-
if (schema.enum.every((x) => guessType(x) === 'number')) {
37-
return asNumber(value);
38-
} else if (schema.enum.every((x) => guessType(x) === 'boolean')) {
39-
return value === 'true';
40-
}
41-
}
42-
43-
return value;
44-
};
45-
4611
const SelectWidget = ({
4712
autofocus,
4813
disabled,
@@ -64,11 +29,11 @@ const SelectWidget = ({
6429

6530
const { enumOptions, enumDisabled } = options;
6631

67-
const handleChange = (nextValue) => onChange(processValue(schema, nextValue));
32+
const handleChange = (nextValue) => onChange(processSelectValue(schema, nextValue));
6833

69-
const handleBlur = () => onBlur(id, processValue(schema, value));
34+
const handleBlur = () => onBlur(id, processSelectValue(schema, value));
7035

71-
const handleFocus = () => onFocus(id, processValue(schema, value));
36+
const handleFocus = () => onFocus(id, processSelectValue(schema, value));
7237

7338
const getPopupContainer = (node) => node.parentNode;
7439

packages/antd/src/widgets/SubmitButton/SubmitButton.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { utils } from '@rjsf/core';
1+
import { getSubmitButtonOptions } from '@rjsf/utils';
22
import React from "react";
33
import Button from 'antd/lib/button';
4-
const { getSubmitButtonOptions } = utils;
4+
55
export default ({ uiSchema }) => {
66
const { submitText, norender, props: submitButtonProps }= getSubmitButtonOptions(uiSchema);
77
if (norender) {return null;}

packages/antd/test/Array.test.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import renderer from 'react-test-renderer';
3+
import validator from '@rjsf/validator-ajv6';
34

45
import '../__mocks__/matchMedia.mock';
56
import Form from '../src';
@@ -15,7 +16,7 @@ describe("array fields", () => {
1516
}
1617
};
1718
const tree = renderer
18-
.create(<Form schema={schema} />)
19+
.create(<Form schema={schema} validator={validator} />)
1920
.toJSON();
2021
expect(tree).toMatchSnapshot();
2122
});
@@ -32,7 +33,7 @@ describe("array fields", () => {
3233
]
3334
};
3435
const tree = renderer
35-
.create(<Form schema={schema} />)
36+
.create(<Form schema={schema} validator={validator} />)
3637
.toJSON();
3738
expect(tree).toMatchSnapshot();
3839
});
@@ -46,7 +47,7 @@ describe("array fields", () => {
4647
uniqueItems: true
4748
};
4849
const tree = renderer
49-
.create(<Form schema={schema} />)
50+
.create(<Form schema={schema} validator={validator} />)
5051
.toJSON();
5152
expect(tree).toMatchSnapshot();
5253
});

0 commit comments

Comments
 (0)