@zat-design/sisyphus-react 3.3.3-beta.4 → 3.3.3-beta.6
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/index.esm.css +7 -2
- package/es/ProConfigProvider/index.d.ts +10 -2
- package/es/ProConfigProvider/index.js +13 -6
- package/es/ProForm/components/base/TextArea/index.js +1 -3
- package/es/ProForm/components/base/TextArea/index.less +7 -0
- package/es/ProForm/components/combination/Group/index.js +6 -1
- package/es/ProForm/components/combination/Group/style/index.less +2 -1
- package/es/ProForm/index.js +31 -21
- package/es/ProForm/propsType.d.ts +1 -1
- package/es/ProForm/utils/useRules.js +4 -1
- package/es/index.d.ts +0 -1
- package/es/index.js +0 -1
- package/lib/ProConfigProvider/index.d.ts +10 -2
- package/lib/ProConfigProvider/index.js +14 -6
- package/lib/ProForm/components/base/TextArea/index.js +1 -3
- package/lib/ProForm/components/base/TextArea/index.less +7 -0
- package/lib/ProForm/components/combination/Group/index.js +6 -1
- package/lib/ProForm/components/combination/Group/style/index.less +2 -1
- package/lib/ProForm/index.js +27 -17
- package/lib/ProForm/propsType.d.ts +1 -1
- package/lib/ProForm/utils/useRules.js +4 -1
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -15
- package/package.json +1 -1
- package/es/ProForm/components/ProFormGroup/index.d.ts +0 -13
- package/es/ProForm/components/ProFormGroup/index.js +0 -27
- package/lib/ProForm/components/ProFormGroup/index.d.ts +0 -13
- package/lib/ProForm/components/ProFormGroup/index.js +0 -35
package/dist/index.esm.css
CHANGED
|
@@ -1941,6 +1941,9 @@ div.pro-textarea-view::after {
|
|
|
1941
1941
|
display: none;
|
|
1942
1942
|
padding-bottom: 12px;
|
|
1943
1943
|
}
|
|
1944
|
+
.pro-textarea .ant-input {
|
|
1945
|
+
resize: auto !important;
|
|
1946
|
+
}
|
|
1944
1947
|
.pro-form-list-block-title {
|
|
1945
1948
|
height: 14px;
|
|
1946
1949
|
margin: calc(var(--zaui-space-size-xs, 4px) * var(--zaui-size, 1)) 0;
|
|
@@ -2233,10 +2236,12 @@ span.ant-input-group-compact.pro-range-limit .forever-checkbox {
|
|
|
2233
2236
|
.pro-group {
|
|
2234
2237
|
width: unset !important;
|
|
2235
2238
|
}
|
|
2236
|
-
.pro-group.pro-group-diy-width .ant-space .ant-space-item
|
|
2239
|
+
.pro-group.pro-group-diy-width .ant-space .ant-space-item,
|
|
2240
|
+
.pro-group.pro-group-width-auto .ant-space .ant-space-item {
|
|
2237
2241
|
width: auto;
|
|
2238
2242
|
}
|
|
2239
|
-
.pro-group.pro-group-diy-width .ant-space .ant-space-item .ant-space-item
|
|
2243
|
+
.pro-group.pro-group-diy-width .ant-space .ant-space-item .ant-space-item,
|
|
2244
|
+
.pro-group.pro-group-width-auto .ant-space .ant-space-item .ant-space-item {
|
|
2240
2245
|
width: auto;
|
|
2241
2246
|
}
|
|
2242
2247
|
.pro-group .ant-space {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
|
+
import { FormInstance } from 'antd';
|
|
2
3
|
import { PropSelectProps } from '../ProSelect/propsType';
|
|
3
4
|
import { ProModalSelectPropsType } from '../ProForm/components/combination/ProModalSelect/propsType';
|
|
4
5
|
import { AddressProps } from '../ProForm/components/combination/ProAddressBar/propsType';
|
|
@@ -9,17 +10,24 @@ export interface ProConfigState {
|
|
|
9
10
|
ProSelect?: Partial<PropSelectProps> & Record<string, any>;
|
|
10
11
|
ProModalSelect?: Partial<ProModalSelectPropsType> & Record<string, any>;
|
|
11
12
|
ProAddressBar?: Partial<AddressProps> & Record<string, any>;
|
|
13
|
+
forms: Record<string, FormInstance | undefined>;
|
|
12
14
|
[key: string]: any;
|
|
13
15
|
}
|
|
14
16
|
interface ConfigContext {
|
|
15
17
|
state: ProConfigState;
|
|
16
|
-
dispatch: React.Dispatch<
|
|
18
|
+
dispatch: React.Dispatch<Actions>;
|
|
17
19
|
}
|
|
18
20
|
export declare const ProConfigContext: React.Context<ConfigContext>;
|
|
19
21
|
export declare function useProConfig(): ConfigContext;
|
|
20
22
|
export declare function useProConfig(name: keyof ConfigContext['state']): ConfigContext['state'][keyof ConfigContext['state']];
|
|
23
|
+
export declare function useContextForm(): Record<string, FormInstance<any>>;
|
|
24
|
+
type ActionsType = 'set' | 'setProEnum' | 'setProEnumDic';
|
|
25
|
+
interface Actions {
|
|
26
|
+
type: ActionsType;
|
|
27
|
+
payload: any;
|
|
28
|
+
}
|
|
21
29
|
export declare const ProConfigProvider: FC<{
|
|
22
|
-
value
|
|
30
|
+
value?: ProConfigState;
|
|
23
31
|
locale?: string;
|
|
24
32
|
}>;
|
|
25
33
|
export default ProConfigProvider;
|
|
@@ -9,12 +9,14 @@ import enUS from 'antd/es/locale/en_US';
|
|
|
9
9
|
import merge from 'lodash/merge';
|
|
10
10
|
import useEnumRequest from '../ProEnum/hooks/useEnumRequest';
|
|
11
11
|
import { setLanguage } from '../locale';
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
dics: {}
|
|
16
|
-
}
|
|
12
|
+
var initialState = {
|
|
13
|
+
ProEnum: {
|
|
14
|
+
dics: {}
|
|
17
15
|
},
|
|
16
|
+
forms: {}
|
|
17
|
+
};
|
|
18
|
+
export var ProConfigContext = /*#__PURE__*/React.createContext({
|
|
19
|
+
state: initialState,
|
|
18
20
|
dispatch: function dispatch() {}
|
|
19
21
|
});
|
|
20
22
|
// eslint-disable-next-line no-redeclare
|
|
@@ -22,6 +24,11 @@ export function useProConfig(name) {
|
|
|
22
24
|
var config = useContext(ProConfigContext);
|
|
23
25
|
return name ? config.state[name] : config;
|
|
24
26
|
}
|
|
27
|
+
export function useContextForm() {
|
|
28
|
+
var _config$state;
|
|
29
|
+
var config = useContext(ProConfigContext);
|
|
30
|
+
return (_config$state = config.state) === null || _config$state === void 0 ? void 0 : _config$state.forms;
|
|
31
|
+
}
|
|
25
32
|
var antdLangMap = {
|
|
26
33
|
'zh-CN': zhCN,
|
|
27
34
|
'en-US': enUS // en-US
|
|
@@ -47,7 +54,7 @@ var reducer = function reducer(state, action) {
|
|
|
47
54
|
};
|
|
48
55
|
export var ProConfigProvider = function ProConfigProvider(props) {
|
|
49
56
|
var _props$value, _props$value2;
|
|
50
|
-
var _useReducer = useReducer(reducer,
|
|
57
|
+
var _useReducer = useReducer(reducer, initialState),
|
|
51
58
|
_useReducer2 = _slicedToArray(_useReducer, 2),
|
|
52
59
|
state = _useReducer2[0],
|
|
53
60
|
dispatch = _useReducer2[1];
|
|
@@ -40,9 +40,7 @@ var TextAreaDef = function TextAreaDef(props) {
|
|
|
40
40
|
showCount: true,
|
|
41
41
|
autoComplete: "off",
|
|
42
42
|
placeholder: placeholder || "".concat(locale.ProForm.inputPlaceholder).concat(label || ''),
|
|
43
|
-
autoSize:
|
|
44
|
-
minRows: 4
|
|
45
|
-
}
|
|
43
|
+
autoSize: true
|
|
46
44
|
}, omit(initialConfig, ['trim'])), rest), {}, {
|
|
47
45
|
className: _className
|
|
48
46
|
}));
|
|
@@ -51,6 +51,9 @@ var Group = function Group(props) {
|
|
|
51
51
|
'pro-group-diy-width': columns.some(function (item) {
|
|
52
52
|
var _item$fieldProps, _item$fieldProps$styl;
|
|
53
53
|
return item === null || item === void 0 ? void 0 : (_item$fieldProps = item.fieldProps) === null || _item$fieldProps === void 0 ? void 0 : (_item$fieldProps$styl = _item$fieldProps.style) === null || _item$fieldProps$styl === void 0 ? void 0 : _item$fieldProps$styl.width;
|
|
54
|
+
}),
|
|
55
|
+
'pro-group-width-auto': columns.some(function (item) {
|
|
56
|
+
return ['Radio', 'Checkbox', 'Switch'].includes(item.type);
|
|
54
57
|
})
|
|
55
58
|
}, "".concat(className), className));
|
|
56
59
|
return _jsx("div", {
|
|
@@ -60,7 +63,9 @@ var Group = function Group(props) {
|
|
|
60
63
|
columns: data.columns,
|
|
61
64
|
form: form
|
|
62
65
|
}, omit(otherProps, ['colProps'])))
|
|
63
|
-
}) : _jsx(_Space, _objectSpread(_objectSpread({
|
|
66
|
+
}) : _jsx(_Space, _objectSpread(_objectSpread({
|
|
67
|
+
align: "start"
|
|
68
|
+
}, omit(space, ['separator', 'compact'])), {}, {
|
|
64
69
|
children: data.columns.map(function (column, index) {
|
|
65
70
|
return _jsx(RenderFields, _objectSpread({
|
|
66
71
|
columns: [column],
|
package/es/ProForm/index.js
CHANGED
|
@@ -1,33 +1,32 @@
|
|
|
1
1
|
import _toArray from "@babel/runtime/helpers/esm/toArray";
|
|
2
2
|
import "antd/es/row/style";
|
|
3
3
|
import _Row from "antd/es/row";
|
|
4
|
+
import "antd/es/form/style";
|
|
5
|
+
import _Form from "antd/es/form";
|
|
4
6
|
import "antd/es/col/style";
|
|
5
7
|
import _Col from "antd/es/col";
|
|
6
8
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
7
9
|
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
8
10
|
import "antd/es/space/style";
|
|
9
11
|
import _Space from "antd/es/space";
|
|
10
|
-
import "antd/es/form/style";
|
|
11
|
-
import _Form from "antd/es/form";
|
|
12
12
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
13
13
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
14
14
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
15
|
-
var _excluded = ["mode", "span", "disabled", "isView", "columns", "footer", "onOk", "okText", "onCancel", "confirmLoading", "cancelText", "form", "children", "rowProps", "className", "expand", "expandOpen", "expandOpenChange", "viewEmpty", "labelAlign", "labelWidth", "onValuesChange", "onFinish", "originalValues", "submitOnEnter", "clearNotShow", "initialValues", "requiredOnView", "formId", "required", "originalTip", "
|
|
15
|
+
var _excluded = ["mode", "span", "disabled", "isView", "columns", "footer", "onOk", "okText", "onCancel", "confirmLoading", "cancelText", "form", "children", "rowProps", "className", "expand", "expandOpen", "expandOpenChange", "viewEmpty", "labelAlign", "labelWidth", "onValuesChange", "onFinish", "originalValues", "submitOnEnter", "clearNotShow", "initialValues", "requiredOnView", "formId", "required", "originalTip", "formKey"];
|
|
16
16
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
17
17
|
import { DoubleLeftOutlined } from '@ant-design/icons';
|
|
18
18
|
import classnames from 'classnames';
|
|
19
|
-
import React, { forwardRef,
|
|
19
|
+
import React, { forwardRef, useImperativeHandle, useMemo } from 'react';
|
|
20
20
|
import { isObject, isString, merge } from 'lodash';
|
|
21
21
|
import { FormFooter, InputRange, ProAddress, ProAddressBar, ProCertNo, ProCertValidity, ProCombination, ProModalSelect, ProNumberRange, ProRangeBox, ProTimeLimit, transferAddressInfoToRegion, ProUpload, ProTreeSelect, ProTreeModal, ProTree, EnumSelect } from './components';
|
|
22
22
|
import RenderFields from './components/render/RenderFields';
|
|
23
|
-
import { useProConfig } from '../ProConfigProvider';
|
|
23
|
+
import { useProConfig, useContextForm } from '../ProConfigProvider';
|
|
24
24
|
import { getLayout, splitNameStr, useControlled, initialValuesToNames } from './utils/index';
|
|
25
25
|
import { useForm } from './utils/useForm';
|
|
26
26
|
import { useFieldProps } from './utils/useFieldProps';
|
|
27
27
|
import locale from '../locale';
|
|
28
|
-
import { groupContext } from './components/ProFormGroup';
|
|
29
28
|
var ProForm = function ProForm(props, ref) {
|
|
30
|
-
var
|
|
29
|
+
var _forms$formKey, _localStorage;
|
|
31
30
|
var _props$mode = props.mode,
|
|
32
31
|
mode = _props$mode === void 0 ? 'search' : _props$mode,
|
|
33
32
|
span = props.span,
|
|
@@ -66,13 +65,14 @@ var ProForm = function ProForm(props, ref) {
|
|
|
66
65
|
required = props.required,
|
|
67
66
|
_props$originalTip = props.originalTip,
|
|
68
67
|
originalTip = _props$originalTip === void 0 ? true : _props$originalTip,
|
|
69
|
-
|
|
68
|
+
formKey = props.formKey,
|
|
70
69
|
otherProps = _objectWithoutProperties(props, _excluded);
|
|
71
|
-
var
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
70
|
+
var _useProConfig = useProConfig(),
|
|
71
|
+
state = _useProConfig.state,
|
|
72
|
+
dispatch = _useProConfig.dispatch;
|
|
73
|
+
var config = state.ProForm,
|
|
74
|
+
forms = state.forms;
|
|
75
|
+
var _useForm = useForm((_forms$formKey = forms[formKey]) !== null && _forms$formKey !== void 0 ? _forms$formKey : originForm),
|
|
76
76
|
_useForm2 = _slicedToArray(_useForm, 1),
|
|
77
77
|
form = _useForm2[0];
|
|
78
78
|
var _useControlled = useControlled({
|
|
@@ -82,21 +82,30 @@ var ProForm = function ProForm(props, ref) {
|
|
|
82
82
|
_useControlled2 = _slicedToArray(_useControlled, 2),
|
|
83
83
|
openState = _useControlled2[0],
|
|
84
84
|
setOpenState = _useControlled2[1];
|
|
85
|
-
var config = useProConfig('ProForm');
|
|
86
85
|
// 把表单实例存入表单组
|
|
87
86
|
useMemo(function () {
|
|
88
|
-
if (
|
|
89
|
-
|
|
90
|
-
|
|
87
|
+
if (formKey && forms[formKey] !== form) {
|
|
88
|
+
forms[formKey] = form;
|
|
89
|
+
dispatch({
|
|
90
|
+
type: 'set',
|
|
91
|
+
payload: {
|
|
92
|
+
forms: _objectSpread({}, forms)
|
|
93
|
+
}
|
|
94
|
+
});
|
|
91
95
|
}
|
|
92
96
|
// 销毁
|
|
93
97
|
return function () {
|
|
94
|
-
if (
|
|
95
|
-
delete
|
|
96
|
-
|
|
98
|
+
if (formKey && forms[formKey]) {
|
|
99
|
+
delete forms[formKey];
|
|
100
|
+
dispatch({
|
|
101
|
+
type: 'set',
|
|
102
|
+
payload: {
|
|
103
|
+
forms: _objectSpread({}, forms)
|
|
104
|
+
}
|
|
105
|
+
});
|
|
97
106
|
}
|
|
98
107
|
};
|
|
99
|
-
}, [
|
|
108
|
+
}, [formKey, form]);
|
|
100
109
|
var _getLayout = getLayout({
|
|
101
110
|
span: span,
|
|
102
111
|
form: form
|
|
@@ -301,6 +310,7 @@ var ProFormProvider = function ProFormProvider(props) {
|
|
|
301
310
|
};
|
|
302
311
|
ProFormForward.Provider = ProFormProvider; // 包装Provider
|
|
303
312
|
ProFormForward.useFieldProps = useFieldProps; // 获取每个字段的其他参数 -otherProps
|
|
313
|
+
ProFormForward.useContextForm = useContextForm; // 获取 ProConfigProvider中的表单实例map
|
|
304
314
|
// 内置组合
|
|
305
315
|
ProFormForward.ProAddressBar = ProAddressBar;
|
|
306
316
|
ProFormForward.ProCombination = ProCombination;
|
|
@@ -46,7 +46,7 @@ var useRules = function useRules(props) {
|
|
|
46
46
|
internalRule.rules = internalRule.rules && rulesCreator(internalRule.rules, _label, isSelect);
|
|
47
47
|
useEffect(function () {
|
|
48
48
|
// 添加完整性校验
|
|
49
|
-
if (names && !isBoolean(labelRequired)
|
|
49
|
+
if (names && !isBoolean(labelRequired)) {
|
|
50
50
|
var customRequired = {
|
|
51
51
|
validator: function validator(rules, value) {
|
|
52
52
|
// 完整性校验, 空数组不校验, 数组有值且值不完整则校验不通过
|
|
@@ -56,6 +56,9 @@ var useRules = function useRules(props) {
|
|
|
56
56
|
return Promise.resolve();
|
|
57
57
|
}
|
|
58
58
|
};
|
|
59
|
+
if (type === 'Group' && Array.isArray(names) && !required) {
|
|
60
|
+
customRequired = null;
|
|
61
|
+
}
|
|
59
62
|
internalRule.rules.push(customRequired);
|
|
60
63
|
}
|
|
61
64
|
}, [internalRule]);
|
package/es/index.d.ts
CHANGED
|
@@ -8,7 +8,6 @@ export { default as ProViewer } from './ProViewer';
|
|
|
8
8
|
export { default as ProEditTable } from './ProEditTable';
|
|
9
9
|
export { default as ProDrawerForm } from './ProDrawerForm';
|
|
10
10
|
export { default as ProEditLabel } from './ProEditLabel';
|
|
11
|
-
export { ProFormGroup, useProFormGroup } from './ProForm/components/ProFormGroup';
|
|
12
11
|
export { default as ProForm } from './ProForm';
|
|
13
12
|
export * from './ProForm';
|
|
14
13
|
export * from './ProForm/components';
|
package/es/index.js
CHANGED
|
@@ -12,7 +12,6 @@ export { default as ProEditTable } from './ProEditTable';
|
|
|
12
12
|
export { default as ProDrawerForm } from './ProDrawerForm';
|
|
13
13
|
export { default as ProEditLabel } from './ProEditLabel';
|
|
14
14
|
// 表单
|
|
15
|
-
export { ProFormGroup, useProFormGroup } from './ProForm/components/ProFormGroup';
|
|
16
15
|
export { default as ProForm } from './ProForm';
|
|
17
16
|
export * from './ProForm';
|
|
18
17
|
export * from './ProForm/components'; // ProForm 中组件导出
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
|
+
import { FormInstance } from 'antd';
|
|
2
3
|
import { PropSelectProps } from '../ProSelect/propsType';
|
|
3
4
|
import { ProModalSelectPropsType } from '../ProForm/components/combination/ProModalSelect/propsType';
|
|
4
5
|
import { AddressProps } from '../ProForm/components/combination/ProAddressBar/propsType';
|
|
@@ -9,17 +10,24 @@ export interface ProConfigState {
|
|
|
9
10
|
ProSelect?: Partial<PropSelectProps> & Record<string, any>;
|
|
10
11
|
ProModalSelect?: Partial<ProModalSelectPropsType> & Record<string, any>;
|
|
11
12
|
ProAddressBar?: Partial<AddressProps> & Record<string, any>;
|
|
13
|
+
forms: Record<string, FormInstance | undefined>;
|
|
12
14
|
[key: string]: any;
|
|
13
15
|
}
|
|
14
16
|
interface ConfigContext {
|
|
15
17
|
state: ProConfigState;
|
|
16
|
-
dispatch: React.Dispatch<
|
|
18
|
+
dispatch: React.Dispatch<Actions>;
|
|
17
19
|
}
|
|
18
20
|
export declare const ProConfigContext: React.Context<ConfigContext>;
|
|
19
21
|
export declare function useProConfig(): ConfigContext;
|
|
20
22
|
export declare function useProConfig(name: keyof ConfigContext['state']): ConfigContext['state'][keyof ConfigContext['state']];
|
|
23
|
+
export declare function useContextForm(): Record<string, FormInstance<any>>;
|
|
24
|
+
type ActionsType = 'set' | 'setProEnum' | 'setProEnumDic';
|
|
25
|
+
interface Actions {
|
|
26
|
+
type: ActionsType;
|
|
27
|
+
payload: any;
|
|
28
|
+
}
|
|
21
29
|
export declare const ProConfigProvider: FC<{
|
|
22
|
-
value
|
|
30
|
+
value?: ProConfigState;
|
|
23
31
|
locale?: string;
|
|
24
32
|
}>;
|
|
25
33
|
export default ProConfigProvider;
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.default = exports.ProConfigProvider = exports.ProConfigContext = void 0;
|
|
9
|
+
exports.useContextForm = useContextForm;
|
|
9
10
|
exports.useProConfig = useProConfig;
|
|
10
11
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
12
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
@@ -17,12 +18,14 @@ var _en_US = _interopRequireDefault(require("antd/es/locale/en_US"));
|
|
|
17
18
|
var _merge = _interopRequireDefault(require("lodash/merge"));
|
|
18
19
|
var _useEnumRequest = _interopRequireDefault(require("../ProEnum/hooks/useEnumRequest"));
|
|
19
20
|
var _locale = require("../locale");
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
dics: {}
|
|
24
|
-
}
|
|
21
|
+
var initialState = {
|
|
22
|
+
ProEnum: {
|
|
23
|
+
dics: {}
|
|
25
24
|
},
|
|
25
|
+
forms: {}
|
|
26
|
+
};
|
|
27
|
+
var ProConfigContext = exports.ProConfigContext = /*#__PURE__*/_react.default.createContext({
|
|
28
|
+
state: initialState,
|
|
26
29
|
dispatch: function dispatch() {}
|
|
27
30
|
});
|
|
28
31
|
// eslint-disable-next-line no-redeclare
|
|
@@ -30,6 +33,11 @@ function useProConfig(name) {
|
|
|
30
33
|
var config = (0, _react.useContext)(ProConfigContext);
|
|
31
34
|
return name ? config.state[name] : config;
|
|
32
35
|
}
|
|
36
|
+
function useContextForm() {
|
|
37
|
+
var _config$state;
|
|
38
|
+
var config = (0, _react.useContext)(ProConfigContext);
|
|
39
|
+
return (_config$state = config.state) === null || _config$state === void 0 ? void 0 : _config$state.forms;
|
|
40
|
+
}
|
|
33
41
|
var antdLangMap = {
|
|
34
42
|
'zh-CN': _zh_CN.default,
|
|
35
43
|
'en-US': _en_US.default // en-US
|
|
@@ -55,7 +63,7 @@ var reducer = function reducer(state, action) {
|
|
|
55
63
|
};
|
|
56
64
|
var ProConfigProvider = exports.ProConfigProvider = function ProConfigProvider(props) {
|
|
57
65
|
var _props$value, _props$value2;
|
|
58
|
-
var _useReducer = (0, _react.useReducer)(reducer,
|
|
66
|
+
var _useReducer = (0, _react.useReducer)(reducer, initialState),
|
|
59
67
|
_useReducer2 = (0, _slicedToArray2.default)(_useReducer, 2),
|
|
60
68
|
state = _useReducer2[0],
|
|
61
69
|
dispatch = _useReducer2[1];
|
|
@@ -46,9 +46,7 @@ var TextAreaDef = function TextAreaDef(props) {
|
|
|
46
46
|
showCount: true,
|
|
47
47
|
autoComplete: "off",
|
|
48
48
|
placeholder: placeholder || "".concat(_locale.default.ProForm.inputPlaceholder).concat(label || ''),
|
|
49
|
-
autoSize:
|
|
50
|
-
minRows: 4
|
|
51
|
-
}
|
|
49
|
+
autoSize: true
|
|
52
50
|
}, (0, _lodash.omit)(initialConfig, ['trim'])), rest), {}, {
|
|
53
51
|
className: _className
|
|
54
52
|
}));
|
|
@@ -55,6 +55,9 @@ var Group = function Group(props) {
|
|
|
55
55
|
'pro-group-diy-width': columns.some(function (item) {
|
|
56
56
|
var _item$fieldProps, _item$fieldProps$styl;
|
|
57
57
|
return item === null || item === void 0 ? void 0 : (_item$fieldProps = item.fieldProps) === null || _item$fieldProps === void 0 ? void 0 : (_item$fieldProps$styl = _item$fieldProps.style) === null || _item$fieldProps$styl === void 0 ? void 0 : _item$fieldProps$styl.width;
|
|
58
|
+
}),
|
|
59
|
+
'pro-group-width-auto': columns.some(function (item) {
|
|
60
|
+
return ['Radio', 'Checkbox', 'Switch'].includes(item.type);
|
|
58
61
|
})
|
|
59
62
|
}, "".concat(className), className));
|
|
60
63
|
return (0, _jsxRuntime.jsx)("div", {
|
|
@@ -64,7 +67,9 @@ var Group = function Group(props) {
|
|
|
64
67
|
columns: data.columns,
|
|
65
68
|
form: form
|
|
66
69
|
}, (0, _lodash.omit)(otherProps, ['colProps'])))
|
|
67
|
-
}) : (0, _jsxRuntime.jsx)(_antd.Space, (0, _objectSpread2.default)((0, _objectSpread2.default)({
|
|
70
|
+
}) : (0, _jsxRuntime.jsx)(_antd.Space, (0, _objectSpread2.default)((0, _objectSpread2.default)({
|
|
71
|
+
align: "start"
|
|
72
|
+
}, (0, _lodash.omit)(space, ['separator', 'compact'])), {}, {
|
|
68
73
|
children: data.columns.map(function (column, index) {
|
|
69
74
|
return (0, _jsxRuntime.jsx)(_RenderFields.default, (0, _objectSpread2.default)({
|
|
70
75
|
columns: [column],
|
package/lib/ProForm/index.js
CHANGED
|
@@ -25,10 +25,9 @@ var _index = require("./utils/index");
|
|
|
25
25
|
var _useForm3 = require("./utils/useForm");
|
|
26
26
|
var _useFieldProps = require("./utils/useFieldProps");
|
|
27
27
|
var _locale = _interopRequireDefault(require("../locale"));
|
|
28
|
-
var
|
|
29
|
-
var _excluded = ["mode", "span", "disabled", "isView", "columns", "footer", "onOk", "okText", "onCancel", "confirmLoading", "cancelText", "form", "children", "rowProps", "className", "expand", "expandOpen", "expandOpenChange", "viewEmpty", "labelAlign", "labelWidth", "onValuesChange", "onFinish", "originalValues", "submitOnEnter", "clearNotShow", "initialValues", "requiredOnView", "formId", "required", "originalTip", "groupName"];
|
|
28
|
+
var _excluded = ["mode", "span", "disabled", "isView", "columns", "footer", "onOk", "okText", "onCancel", "confirmLoading", "cancelText", "form", "children", "rowProps", "className", "expand", "expandOpen", "expandOpenChange", "viewEmpty", "labelAlign", "labelWidth", "onValuesChange", "onFinish", "originalValues", "submitOnEnter", "clearNotShow", "initialValues", "requiredOnView", "formId", "required", "originalTip", "formKey"];
|
|
30
29
|
var ProForm = function ProForm(props, ref) {
|
|
31
|
-
var
|
|
30
|
+
var _forms$formKey, _localStorage;
|
|
32
31
|
var _props$mode = props.mode,
|
|
33
32
|
mode = _props$mode === void 0 ? 'search' : _props$mode,
|
|
34
33
|
span = props.span,
|
|
@@ -67,13 +66,14 @@ var ProForm = function ProForm(props, ref) {
|
|
|
67
66
|
required = props.required,
|
|
68
67
|
_props$originalTip = props.originalTip,
|
|
69
68
|
originalTip = _props$originalTip === void 0 ? true : _props$originalTip,
|
|
70
|
-
|
|
69
|
+
formKey = props.formKey,
|
|
71
70
|
otherProps = (0, _objectWithoutProperties2.default)(props, _excluded);
|
|
72
|
-
var
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
71
|
+
var _useProConfig = (0, _ProConfigProvider.useProConfig)(),
|
|
72
|
+
state = _useProConfig.state,
|
|
73
|
+
dispatch = _useProConfig.dispatch;
|
|
74
|
+
var config = state.ProForm,
|
|
75
|
+
forms = state.forms;
|
|
76
|
+
var _useForm = (0, _useForm3.useForm)((_forms$formKey = forms[formKey]) !== null && _forms$formKey !== void 0 ? _forms$formKey : originForm),
|
|
77
77
|
_useForm2 = (0, _slicedToArray2.default)(_useForm, 1),
|
|
78
78
|
form = _useForm2[0];
|
|
79
79
|
var _useControlled = (0, _index.useControlled)({
|
|
@@ -83,21 +83,30 @@ var ProForm = function ProForm(props, ref) {
|
|
|
83
83
|
_useControlled2 = (0, _slicedToArray2.default)(_useControlled, 2),
|
|
84
84
|
openState = _useControlled2[0],
|
|
85
85
|
setOpenState = _useControlled2[1];
|
|
86
|
-
var config = (0, _ProConfigProvider.useProConfig)('ProForm');
|
|
87
86
|
// 把表单实例存入表单组
|
|
88
87
|
(0, _react.useMemo)(function () {
|
|
89
|
-
if (
|
|
90
|
-
|
|
91
|
-
|
|
88
|
+
if (formKey && forms[formKey] !== form) {
|
|
89
|
+
forms[formKey] = form;
|
|
90
|
+
dispatch({
|
|
91
|
+
type: 'set',
|
|
92
|
+
payload: {
|
|
93
|
+
forms: (0, _objectSpread2.default)({}, forms)
|
|
94
|
+
}
|
|
95
|
+
});
|
|
92
96
|
}
|
|
93
97
|
// 销毁
|
|
94
98
|
return function () {
|
|
95
|
-
if (
|
|
96
|
-
delete
|
|
97
|
-
|
|
99
|
+
if (formKey && forms[formKey]) {
|
|
100
|
+
delete forms[formKey];
|
|
101
|
+
dispatch({
|
|
102
|
+
type: 'set',
|
|
103
|
+
payload: {
|
|
104
|
+
forms: (0, _objectSpread2.default)({}, forms)
|
|
105
|
+
}
|
|
106
|
+
});
|
|
98
107
|
}
|
|
99
108
|
};
|
|
100
|
-
}, [
|
|
109
|
+
}, [formKey, form]);
|
|
101
110
|
var _getLayout = (0, _index.getLayout)({
|
|
102
111
|
span: span,
|
|
103
112
|
form: form
|
|
@@ -302,6 +311,7 @@ var ProFormProvider = function ProFormProvider(props) {
|
|
|
302
311
|
};
|
|
303
312
|
ProFormForward.Provider = ProFormProvider; // 包装Provider
|
|
304
313
|
ProFormForward.useFieldProps = _useFieldProps.useFieldProps; // 获取每个字段的其他参数 -otherProps
|
|
314
|
+
ProFormForward.useContextForm = _ProConfigProvider.useContextForm; // 获取 ProConfigProvider中的表单实例map
|
|
305
315
|
// 内置组合
|
|
306
316
|
ProFormForward.ProAddressBar = _components.ProAddressBar;
|
|
307
317
|
ProFormForward.ProCombination = _components.ProCombination;
|
|
@@ -53,7 +53,7 @@ var useRules = function useRules(props) {
|
|
|
53
53
|
internalRule.rules = internalRule.rules && (0, _rulesCreator.rulesCreator)(internalRule.rules, _label, isSelect);
|
|
54
54
|
(0, _react.useEffect)(function () {
|
|
55
55
|
// 添加完整性校验
|
|
56
|
-
if (names && !(0, _lodash.isBoolean)(labelRequired)
|
|
56
|
+
if (names && !(0, _lodash.isBoolean)(labelRequired)) {
|
|
57
57
|
var customRequired = {
|
|
58
58
|
validator: function validator(rules, value) {
|
|
59
59
|
// 完整性校验, 空数组不校验, 数组有值且值不完整则校验不通过
|
|
@@ -63,6 +63,9 @@ var useRules = function useRules(props) {
|
|
|
63
63
|
return Promise.resolve();
|
|
64
64
|
}
|
|
65
65
|
};
|
|
66
|
+
if (type === 'Group' && Array.isArray(names) && !required) {
|
|
67
|
+
customRequired = null;
|
|
68
|
+
}
|
|
66
69
|
internalRule.rules.push(customRequired);
|
|
67
70
|
}
|
|
68
71
|
}, [internalRule]);
|
package/lib/index.d.ts
CHANGED
|
@@ -8,7 +8,6 @@ export { default as ProViewer } from './ProViewer';
|
|
|
8
8
|
export { default as ProEditTable } from './ProEditTable';
|
|
9
9
|
export { default as ProDrawerForm } from './ProDrawerForm';
|
|
10
10
|
export { default as ProEditLabel } from './ProEditLabel';
|
|
11
|
-
export { ProFormGroup, useProFormGroup } from './ProForm/components/ProFormGroup';
|
|
12
11
|
export { default as ProForm } from './ProForm';
|
|
13
12
|
export * from './ProForm';
|
|
14
13
|
export * from './ProForm/components';
|
package/lib/index.js
CHANGED
|
@@ -15,8 +15,6 @@ var _exportNames = {
|
|
|
15
15
|
ProEditTable: true,
|
|
16
16
|
ProDrawerForm: true,
|
|
17
17
|
ProEditLabel: true,
|
|
18
|
-
ProFormGroup: true,
|
|
19
|
-
useProFormGroup: true,
|
|
20
18
|
ProForm: true,
|
|
21
19
|
ProSelect: true,
|
|
22
20
|
ProEnum: true,
|
|
@@ -97,12 +95,6 @@ Object.defineProperty(exports, "ProForm", {
|
|
|
97
95
|
return _ProForm.default;
|
|
98
96
|
}
|
|
99
97
|
});
|
|
100
|
-
Object.defineProperty(exports, "ProFormGroup", {
|
|
101
|
-
enumerable: true,
|
|
102
|
-
get: function get() {
|
|
103
|
-
return _ProFormGroup.ProFormGroup;
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
98
|
Object.defineProperty(exports, "ProIcon", {
|
|
107
99
|
enumerable: true,
|
|
108
100
|
get: function get() {
|
|
@@ -169,12 +161,6 @@ Object.defineProperty(exports, "ProWaterMark", {
|
|
|
169
161
|
return _ProWaterMark.default;
|
|
170
162
|
}
|
|
171
163
|
});
|
|
172
|
-
Object.defineProperty(exports, "useProFormGroup", {
|
|
173
|
-
enumerable: true,
|
|
174
|
-
get: function get() {
|
|
175
|
-
return _ProFormGroup.useProFormGroup;
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
164
|
var _ProLayout = _interopRequireDefault(require("./ProLayout"));
|
|
179
165
|
var _ProStep = _interopRequireDefault(require("./ProStep"));
|
|
180
166
|
var _ProTabs = _interopRequireDefault(require("./ProTabs"));
|
|
@@ -184,7 +170,6 @@ var _ProViewer = _interopRequireDefault(require("./ProViewer"));
|
|
|
184
170
|
var _ProEditTable = _interopRequireDefault(require("./ProEditTable"));
|
|
185
171
|
var _ProDrawerForm = _interopRequireDefault(require("./ProDrawerForm"));
|
|
186
172
|
var _ProEditLabel = _interopRequireDefault(require("./ProEditLabel"));
|
|
187
|
-
var _ProFormGroup = require("./ProForm/components/ProFormGroup");
|
|
188
173
|
var _ProForm = _interopRequireWildcard(require("./ProForm"));
|
|
189
174
|
Object.keys(_ProForm).forEach(function (key) {
|
|
190
175
|
if (key === "default" || key === "__esModule") return;
|
package/package.json
CHANGED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { FormInstance } from 'antd';
|
|
3
|
-
interface FormGroup {
|
|
4
|
-
[K: string]: FormInstance | undefined;
|
|
5
|
-
}
|
|
6
|
-
type ContextType = [FormGroup, (forms: FormGroup) => void];
|
|
7
|
-
export declare const groupContext: React.Context<ContextType>;
|
|
8
|
-
interface Props {
|
|
9
|
-
formGroup?: FormGroup;
|
|
10
|
-
}
|
|
11
|
-
export declare const useProFormGroup: () => FormGroup;
|
|
12
|
-
export declare const ProFormGroup: React.FC<Props>;
|
|
13
|
-
export {};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
-
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
3
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
|
-
import React, { useContext, useMemo, useState } from 'react';
|
|
5
|
-
export var groupContext = /*#__PURE__*/React.createContext([{}, function () {
|
|
6
|
-
return undefined;
|
|
7
|
-
}]);
|
|
8
|
-
export var useProFormGroup = function useProFormGroup() {
|
|
9
|
-
var formGroup = useContext(groupContext);
|
|
10
|
-
return formGroup[0];
|
|
11
|
-
};
|
|
12
|
-
export var ProFormGroup = function ProFormGroup(props) {
|
|
13
|
-
var formGroup = props.formGroup,
|
|
14
|
-
children = props.children;
|
|
15
|
-
var Provider = groupContext.Provider;
|
|
16
|
-
var initialFormGroup = useMemo(function () {
|
|
17
|
-
return formGroup ? _objectSpread({}, formGroup) : {};
|
|
18
|
-
}, [formGroup]);
|
|
19
|
-
var _useState = useState(initialFormGroup),
|
|
20
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
21
|
-
forms = _useState2[0],
|
|
22
|
-
setForms = _useState2[1];
|
|
23
|
-
return _jsx(Provider, {
|
|
24
|
-
value: [forms, setForms],
|
|
25
|
-
children: children
|
|
26
|
-
});
|
|
27
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { FormInstance } from 'antd';
|
|
3
|
-
interface FormGroup {
|
|
4
|
-
[K: string]: FormInstance | undefined;
|
|
5
|
-
}
|
|
6
|
-
type ContextType = [FormGroup, (forms: FormGroup) => void];
|
|
7
|
-
export declare const groupContext: React.Context<ContextType>;
|
|
8
|
-
interface Props {
|
|
9
|
-
formGroup?: FormGroup;
|
|
10
|
-
}
|
|
11
|
-
export declare const useProFormGroup: () => FormGroup;
|
|
12
|
-
export declare const ProFormGroup: React.FC<Props>;
|
|
13
|
-
export {};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.useProFormGroup = exports.groupContext = exports.ProFormGroup = void 0;
|
|
9
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
|
12
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
13
|
-
var groupContext = exports.groupContext = /*#__PURE__*/_react.default.createContext([{}, function () {
|
|
14
|
-
return undefined;
|
|
15
|
-
}]);
|
|
16
|
-
var useProFormGroup = exports.useProFormGroup = function useProFormGroup() {
|
|
17
|
-
var formGroup = (0, _react.useContext)(groupContext);
|
|
18
|
-
return formGroup[0];
|
|
19
|
-
};
|
|
20
|
-
var ProFormGroup = exports.ProFormGroup = function ProFormGroup(props) {
|
|
21
|
-
var formGroup = props.formGroup,
|
|
22
|
-
children = props.children;
|
|
23
|
-
var Provider = groupContext.Provider;
|
|
24
|
-
var initialFormGroup = (0, _react.useMemo)(function () {
|
|
25
|
-
return formGroup ? (0, _objectSpread2.default)({}, formGroup) : {};
|
|
26
|
-
}, [formGroup]);
|
|
27
|
-
var _useState = (0, _react.useState)(initialFormGroup),
|
|
28
|
-
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
29
|
-
forms = _useState2[0],
|
|
30
|
-
setForms = _useState2[1];
|
|
31
|
-
return (0, _jsxRuntime.jsx)(Provider, {
|
|
32
|
-
value: [forms, setForms],
|
|
33
|
-
children: children
|
|
34
|
-
});
|
|
35
|
-
};
|