@zat-design/sisyphus-react 4.0.9 → 4.0.11
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/es/ProConfigProvider/index.d.ts +3 -45
- package/es/ProConfigProvider/index.js +23 -40
- package/es/ProConfigProvider/propsType.d.ts +55 -0
- package/es/ProConfigProvider/propsType.js +1 -0
- package/es/ProEnum/propsType.d.ts +0 -1
- package/es/ProForm/components/combination/Group/utils/index.d.ts +10 -10
- package/es/ProForm/components/render/propsType.d.ts +2 -2
- package/es/ProForm/index.d.ts +2 -12
- package/es/ProForm/index.js +0 -2
- package/es/ProForm/propsType.d.ts +11 -0
- package/es/ProForm/propsType.js +6 -0
- package/es/ProThemeTools/context/ThemeContext.d.ts +2 -0
- package/es/ProThemeTools/context/ThemeContext.js +124 -11
- package/es/ProThemeTools/utils/index.d.ts +2 -0
- package/es/ProThemeTools/utils/index.js +40 -4
- package/es/index.d.ts +7 -6
- package/es/index.js +0 -1
- package/lib/ProConfigProvider/index.d.ts +3 -45
- package/lib/ProConfigProvider/index.js +23 -40
- package/lib/ProConfigProvider/propsType.d.ts +55 -0
- package/lib/ProConfigProvider/propsType.js +5 -0
- package/lib/ProEnum/propsType.d.ts +0 -1
- package/lib/ProForm/components/combination/Group/utils/index.d.ts +10 -10
- package/lib/ProForm/components/render/propsType.d.ts +2 -2
- package/lib/ProForm/index.d.ts +2 -12
- package/lib/ProForm/index.js +0 -2
- package/lib/ProForm/propsType.d.ts +11 -0
- package/lib/ProForm/propsType.js +6 -0
- package/lib/ProThemeTools/context/ThemeContext.d.ts +2 -0
- package/lib/ProThemeTools/context/ThemeContext.js +123 -10
- package/lib/ProThemeTools/utils/index.d.ts +2 -0
- package/lib/ProThemeTools/utils/index.js +44 -6
- package/lib/index.d.ts +7 -6
- package/package.json +1 -1
|
@@ -1,51 +1,9 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
|
-
import { FormInstance } from 'antd';
|
|
3
2
|
import 'dayjs/locale/zh-cn';
|
|
4
|
-
import type {
|
|
5
|
-
import type { ProModalSelectType } from '../ProForm/components/combination/ProModalSelect/propsType';
|
|
6
|
-
import type { ProCascaderType } from '../ProForm/components/combination/ProCascader/propsType';
|
|
7
|
-
import type { ProEnumConfig } from '../ProEnum/propsType';
|
|
8
|
-
export interface ProConfigState {
|
|
9
|
-
locale?: string;
|
|
10
|
-
ProEnum?: Partial<ProEnumConfig>;
|
|
11
|
-
ProSelect?: Partial<PropSelectType> & Record<string, any>;
|
|
12
|
-
ProModalSelect?: Partial<ProModalSelectType> & Record<string, any>;
|
|
13
|
-
ProAddressBar?: Partial<ProCascaderType> & Record<string, any>;
|
|
14
|
-
forms: Record<string, FormInstance | undefined>;
|
|
15
|
-
[key: string]: any;
|
|
16
|
-
}
|
|
17
|
-
interface ConfigContext {
|
|
18
|
-
state: ProConfigState;
|
|
19
|
-
dispatch: React.Dispatch<Actions>;
|
|
20
|
-
}
|
|
3
|
+
import type { ProConfigProviderProps, ConfigContext } from './propsType';
|
|
21
4
|
export declare const ProConfigContext: React.Context<ConfigContext>;
|
|
22
5
|
export declare function useProConfig(): ConfigContext;
|
|
23
6
|
export declare function useProConfig(name: keyof ConfigContext['state']): ConfigContext['state'][keyof ConfigContext['state']];
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
name: string;
|
|
27
|
-
value: FormInstance;
|
|
28
|
-
} | {
|
|
29
|
-
type: 'deleteFormRef';
|
|
30
|
-
name: string;
|
|
31
|
-
} | {
|
|
32
|
-
type: 'set';
|
|
33
|
-
payload: ProConfigState;
|
|
34
|
-
} | {
|
|
35
|
-
type: 'setProEnum';
|
|
36
|
-
payload: Record<string, any>;
|
|
37
|
-
} | {
|
|
38
|
-
type: 'setProEnumDic';
|
|
39
|
-
key: string;
|
|
40
|
-
payload: any;
|
|
41
|
-
} | {
|
|
42
|
-
type: 'setWithLocal';
|
|
43
|
-
payload: ProConfigState;
|
|
44
|
-
};
|
|
45
|
-
export declare const ProConfigProvider: FC<{
|
|
46
|
-
value?: ProConfigState;
|
|
47
|
-
locale?: string;
|
|
48
|
-
onSuccess?: (data: any, params: any) => void;
|
|
49
|
-
children?: React.ReactNode;
|
|
50
|
-
}>;
|
|
7
|
+
export declare const ProConfigProvider: FC<ProConfigProviderProps>;
|
|
8
|
+
export type { ProConfigProviderType, ProConfigProviderProps } from './propsType';
|
|
51
9
|
export default ProConfigProvider;
|
|
@@ -37,38 +37,36 @@ var initialState = {
|
|
|
37
37
|
}]
|
|
38
38
|
}
|
|
39
39
|
};
|
|
40
|
+
var antdLangMap = {
|
|
41
|
+
'zh-CN': zhCN,
|
|
42
|
+
'en-US': enUS
|
|
43
|
+
};
|
|
40
44
|
export var ProConfigContext = /*#__PURE__*/React.createContext({
|
|
41
45
|
state: initialState,
|
|
42
46
|
dispatch: () => {}
|
|
43
47
|
});
|
|
44
|
-
|
|
45
|
-
// eslint-disable-next-line no-redeclare
|
|
46
|
-
|
|
47
|
-
// eslint-disable-next-line no-redeclare
|
|
48
48
|
export function useProConfig(name) {
|
|
49
49
|
var _useContext = useContext(ProConfigContext),
|
|
50
50
|
state = _useContext.state,
|
|
51
51
|
dispatch = _useContext.dispatch;
|
|
52
|
-
if (name)
|
|
53
|
-
return state[name];
|
|
54
|
-
}
|
|
52
|
+
if (name) return state[name];
|
|
55
53
|
return {
|
|
56
54
|
state,
|
|
57
55
|
dispatch
|
|
58
56
|
};
|
|
59
57
|
}
|
|
60
|
-
|
|
61
|
-
var _state$ProEnum;
|
|
58
|
+
function reducer(state, action) {
|
|
59
|
+
var _state$forms, _state$forms2, _state$ProEnum$dics, _state$ProEnum;
|
|
62
60
|
switch (action.type) {
|
|
63
61
|
case 'setFormRef':
|
|
64
62
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
65
|
-
forms: _objectSpread(_objectSpread({}, state.forms), {}, {
|
|
63
|
+
forms: _objectSpread(_objectSpread({}, (_state$forms = state.forms) !== null && _state$forms !== void 0 ? _state$forms : {}), {}, {
|
|
66
64
|
[action.name]: action.value
|
|
67
65
|
})
|
|
68
66
|
});
|
|
69
67
|
case 'deleteFormRef':
|
|
70
68
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
71
|
-
forms: _objectSpread(_objectSpread({}, state.forms), {}, {
|
|
69
|
+
forms: _objectSpread(_objectSpread({}, (_state$forms2 = state.forms) !== null && _state$forms2 !== void 0 ? _state$forms2 : {}), {}, {
|
|
72
70
|
[action.name]: undefined
|
|
73
71
|
})
|
|
74
72
|
});
|
|
@@ -81,19 +79,16 @@ var reducer = (state, action) => {
|
|
|
81
79
|
case 'setProEnumDic':
|
|
82
80
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
83
81
|
ProEnum: _objectSpread(_objectSpread({}, state.ProEnum), {}, {
|
|
84
|
-
dics: _objectSpread(_objectSpread({}, ((_state$ProEnum = state.ProEnum) === null || _state$ProEnum === void 0 ? void 0 : _state$ProEnum.
|
|
82
|
+
dics: _objectSpread(_objectSpread({}, (_state$ProEnum$dics = (_state$ProEnum = state.ProEnum) === null || _state$ProEnum === void 0 ? void 0 : _state$ProEnum.dics) !== null && _state$ProEnum$dics !== void 0 ? _state$ProEnum$dics : {}), action.payload)
|
|
85
83
|
})
|
|
86
84
|
});
|
|
87
85
|
case 'setWithLocal':
|
|
88
|
-
// 本地配置合并
|
|
89
86
|
localStorage.setItem('localConfig', JSON.stringify(action.payload));
|
|
90
87
|
return _objectSpread({}, state);
|
|
91
88
|
default:
|
|
92
|
-
return
|
|
89
|
+
return state;
|
|
93
90
|
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// 内部组件,用于监听主题变化并应用到 ConfigProvider
|
|
91
|
+
}
|
|
97
92
|
var ThemeAwareConfigProvider = _ref => {
|
|
98
93
|
var locale = _ref.locale,
|
|
99
94
|
children = _ref.children;
|
|
@@ -108,45 +103,33 @@ var ThemeAwareConfigProvider = _ref => {
|
|
|
108
103
|
});
|
|
109
104
|
};
|
|
110
105
|
export var ProConfigProvider = props => {
|
|
111
|
-
var _props$value, _props$value2, _props$value3, _props$value4;
|
|
106
|
+
var _props$value, _props$value2, _props$value3, _props$value4, _ref2, _ref3, _state$locale, _antdLangMap$lang;
|
|
112
107
|
var _useReducer = useReducer(reducer, initialState),
|
|
113
108
|
_useReducer2 = _slicedToArray(_useReducer, 2),
|
|
114
109
|
state = _useReducer2[0],
|
|
115
110
|
dispatch = _useReducer2[1];
|
|
116
111
|
var enumRes = useEnumRequest(_objectSpread(_objectSpread(_objectSpread({}, state.ProEnum), props === null || props === void 0 || (_props$value = props.value) === null || _props$value === void 0 ? void 0 : _props$value.ProEnum), props === null || props === void 0 || (_props$value2 = props.value) === null || _props$value2 === void 0 ? void 0 : _props$value2.globalConfig), dispatch);
|
|
117
|
-
|
|
118
|
-
// 处理频繁枚举请求
|
|
119
112
|
var frequentEnumRes = useFrequentEnumRequest(_objectSpread(_objectSpread(_objectSpread({}, state.ProEnum), props === null || props === void 0 || (_props$value3 = props.value) === null || _props$value3 === void 0 ? void 0 : _props$value3.ProEnum), props === null || props === void 0 || (_props$value4 = props.value) === null || _props$value4 === void 0 ? void 0 : _props$value4.globalConfig), dispatch);
|
|
113
|
+
var cacheLang = localStorage.getItem('locale');
|
|
114
|
+
var lang = (_ref2 = (_ref3 = (_state$locale = state === null || state === void 0 ? void 0 : state.locale) !== null && _state$locale !== void 0 ? _state$locale : cacheLang) !== null && _ref3 !== void 0 ? _ref3 : props === null || props === void 0 ? void 0 : props.locale) !== null && _ref2 !== void 0 ? _ref2 : 'zh-CN';
|
|
120
115
|
useEffect(() => {
|
|
121
|
-
|
|
122
|
-
var
|
|
123
|
-
var localConfig = JSON.parse(localConfigStr || '{}');
|
|
116
|
+
var raw = localStorage.getItem('localConfig');
|
|
117
|
+
var localConfig = JSON.parse(raw || '{}');
|
|
124
118
|
dispatch({
|
|
125
119
|
type: 'set',
|
|
126
|
-
payload: merge(
|
|
120
|
+
payload: merge(initialState, localConfig)
|
|
127
121
|
});
|
|
128
122
|
}, []);
|
|
129
|
-
var cacheLang = localStorage.getItem('locale');
|
|
130
|
-
// 如果是用户切换了语言那么优先使用用户切换的,否则从缓存中取用户语言,在取默认值
|
|
131
|
-
var lang = (state === null || state === void 0 ? void 0 : state.locale) || cacheLang || (props === null || props === void 0 ? void 0 : props.locale);
|
|
132
123
|
useEffect(() => {
|
|
133
124
|
setLanguage(lang);
|
|
134
125
|
}, [lang]);
|
|
135
126
|
useEffect(() => {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
127
|
+
var _props$onSuccess;
|
|
128
|
+
if (enumRes !== null && enumRes !== void 0 && enumRes.data) props === null || props === void 0 || (_props$onSuccess = props.onSuccess) === null || _props$onSuccess === void 0 || _props$onSuccess.call(props, enumRes.data, enumRes.params);
|
|
139
129
|
}, [enumRes === null || enumRes === void 0 ? void 0 : enumRes.loading]);
|
|
140
|
-
var antdLangMap = {
|
|
141
|
-
'zh-CN': zhCN,
|
|
142
|
-
// zh-CN 中文
|
|
143
|
-
'en-US': enUS // en-US
|
|
144
|
-
};
|
|
145
|
-
// 处理频繁枚举的成功回调
|
|
146
130
|
useEffect(() => {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
131
|
+
var _props$onSuccess2;
|
|
132
|
+
if (frequentEnumRes !== null && frequentEnumRes !== void 0 && frequentEnumRes.data) props === null || props === void 0 || (_props$onSuccess2 = props.onSuccess) === null || _props$onSuccess2 === void 0 || _props$onSuccess2.call(props, frequentEnumRes.data, frequentEnumRes.params);
|
|
150
133
|
}, [frequentEnumRes === null || frequentEnumRes === void 0 ? void 0 : frequentEnumRes.loading]);
|
|
151
134
|
return /*#__PURE__*/_jsx(ThemeProvider, {
|
|
152
135
|
children: /*#__PURE__*/_jsx(ProConfigContext.Provider, {
|
|
@@ -155,7 +138,7 @@ export var ProConfigProvider = props => {
|
|
|
155
138
|
dispatch
|
|
156
139
|
},
|
|
157
140
|
children: /*#__PURE__*/_jsx(ThemeAwareConfigProvider, {
|
|
158
|
-
locale: antdLangMap[lang],
|
|
141
|
+
locale: (_antdLangMap$lang = antdLangMap[lang]) !== null && _antdLangMap$lang !== void 0 ? _antdLangMap$lang : zhCN,
|
|
159
142
|
children: props.children
|
|
160
143
|
})
|
|
161
144
|
})
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import type { FormInstance } from 'antd';
|
|
3
|
+
import type { PropSelectType } from '../ProSelect/propsType';
|
|
4
|
+
import type { ProModalSelectType } from '../ProForm/components/combination/ProModalSelect/propsType';
|
|
5
|
+
import type { ProCascaderType } from '../ProForm/components/combination/ProCascader/propsType';
|
|
6
|
+
import type { ProEnumConfigType } from '../ProEnum/propsType';
|
|
7
|
+
/** 对外配置项类型(value、内部 state 均为此类型,字段均可选) */
|
|
8
|
+
export interface ProConfigProviderType {
|
|
9
|
+
locale?: string;
|
|
10
|
+
ProEnum?: Partial<ProEnumConfigType>;
|
|
11
|
+
ProSelect?: Partial<PropSelectType> & Record<string, any>;
|
|
12
|
+
ProModalSelect?: Partial<ProModalSelectType> & Record<string, any>;
|
|
13
|
+
ProAddressBar?: Partial<ProCascaderType> & Record<string, any>;
|
|
14
|
+
forms?: Record<string, FormInstance | undefined>;
|
|
15
|
+
[key: string]: any;
|
|
16
|
+
}
|
|
17
|
+
/** ProConfigProvider 组件 Props(内部使用) */
|
|
18
|
+
export interface ProConfigProviderProps {
|
|
19
|
+
value?: ProConfigProviderType;
|
|
20
|
+
locale?: string;
|
|
21
|
+
onSuccess?: (data: any, params: any) => void;
|
|
22
|
+
children?: React.ReactNode;
|
|
23
|
+
}
|
|
24
|
+
/** Config 上下文 */
|
|
25
|
+
export interface ConfigContext {
|
|
26
|
+
state: ProConfigProviderType;
|
|
27
|
+
dispatch: React.Dispatch<ProConfigActions>;
|
|
28
|
+
}
|
|
29
|
+
/** ThemeAwareConfigProvider 内部组件 Props */
|
|
30
|
+
export interface ThemeAwareConfigProviderProps {
|
|
31
|
+
locale: any;
|
|
32
|
+
children: React.ReactNode;
|
|
33
|
+
}
|
|
34
|
+
/** Reducer Actions */
|
|
35
|
+
export type ProConfigActions = {
|
|
36
|
+
type: 'setFormRef';
|
|
37
|
+
name: string;
|
|
38
|
+
value: FormInstance;
|
|
39
|
+
} | {
|
|
40
|
+
type: 'deleteFormRef';
|
|
41
|
+
name: string;
|
|
42
|
+
} | {
|
|
43
|
+
type: 'set';
|
|
44
|
+
payload: ProConfigProviderType;
|
|
45
|
+
} | {
|
|
46
|
+
type: 'setProEnum';
|
|
47
|
+
payload: Record<string, any>;
|
|
48
|
+
} | {
|
|
49
|
+
type: 'setProEnumDic';
|
|
50
|
+
key: string;
|
|
51
|
+
payload: any;
|
|
52
|
+
} | {
|
|
53
|
+
type: 'setWithLocal';
|
|
54
|
+
payload: ProConfigProviderType;
|
|
55
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -303,7 +303,6 @@ export interface TagPropsMapType {
|
|
|
303
303
|
*/
|
|
304
304
|
export type ProEnumType = Omit<ProEnumBaseType, 'type'> & (PropProSelectsMapType | PropRadioPropsMapType | CheckboxPropsMapType | TagPropsMapType);
|
|
305
305
|
export type DataOption = DataOptionType;
|
|
306
|
-
export type ProEnumConfig = ProEnumConfigType;
|
|
307
306
|
export type ProEnum = ProEnumBaseType;
|
|
308
307
|
export type PropProSelectsMap = PropProSelectsMapType;
|
|
309
308
|
export type PropRadioPropsMap = PropRadioPropsMapType;
|
|
@@ -75,31 +75,32 @@ export declare const useFormItemProps: (column: FlexibleGroupColumnType, context
|
|
|
75
75
|
confirm?: boolean | import("antd").ModalFuncProps | import("../../../render/propsType").FunctionArgs<any, boolean | import("antd").ModalFuncProps>;
|
|
76
76
|
show?: boolean | ReactiveFunction<any, boolean>;
|
|
77
77
|
component?: React.ReactNode | ReactiveFunction<any, React.ReactNode>;
|
|
78
|
-
|
|
78
|
+
children?: React.ReactNode | ((form: FormInstance<any>) => React.ReactNode);
|
|
79
79
|
trim?: boolean;
|
|
80
80
|
normalize?: (value: any, prevValue: any, allValues: import("@rc-component/form/lib/interface").Store) => any;
|
|
81
|
-
children?: React.ReactNode | ((form: FormInstance<any>) => React.ReactNode);
|
|
82
81
|
className?: string;
|
|
83
|
-
hidden?: boolean;
|
|
84
|
-
layout?: import("antd/es/form/Form").FormItemLayout;
|
|
85
|
-
help?: React.ReactNode;
|
|
86
|
-
vertical?: boolean;
|
|
87
|
-
preserve?: boolean;
|
|
88
82
|
prefixCls?: string;
|
|
83
|
+
style?: React.CSSProperties;
|
|
89
84
|
onReset?: () => void;
|
|
90
85
|
status?: "" | "warning" | "error" | "success" | "validating";
|
|
86
|
+
hidden?: boolean;
|
|
91
87
|
id?: string;
|
|
88
|
+
vertical?: boolean;
|
|
92
89
|
rootClassName?: string;
|
|
93
90
|
isView?: boolean;
|
|
94
91
|
getValueProps?: ((value: any) => Record<string, unknown>) & ((value: any) => Record<string, unknown>);
|
|
95
92
|
desensitization?: [number, number] | ReactiveFunction<any, [number, number]>;
|
|
96
93
|
htmlFor?: string;
|
|
94
|
+
layout?: import("antd/es/form/Form").FormItemLayout;
|
|
95
|
+
help?: React.ReactNode;
|
|
96
|
+
preserve?: boolean;
|
|
97
|
+
trigger?: string;
|
|
97
98
|
colon?: boolean;
|
|
99
|
+
clearNotShow?: boolean;
|
|
98
100
|
labelAlign?: import("antd/es/form/interface").FormLabelAlign;
|
|
99
101
|
labelCol?: import("antd").ColProps;
|
|
100
102
|
getValueFromEvent?: (...args: import("@rc-component/form/lib/interface").EventArgs) => any;
|
|
101
103
|
shouldUpdate?: import("@rc-component/form/lib/Field").ShouldUpdate<any>;
|
|
102
|
-
trigger?: string;
|
|
103
104
|
validateTrigger?: string | false | string[];
|
|
104
105
|
validateDebounce?: number;
|
|
105
106
|
valuePropName?: string;
|
|
@@ -126,7 +127,6 @@ export declare const useFormItemProps: (column: FlexibleGroupColumnType, context
|
|
|
126
127
|
upperCase?: boolean;
|
|
127
128
|
toISOString?: boolean;
|
|
128
129
|
toCSTString?: boolean;
|
|
129
|
-
clearNotShow?: boolean;
|
|
130
130
|
name: any;
|
|
131
131
|
dependencies: any[];
|
|
132
132
|
tooltip: string | {
|
|
@@ -141,7 +141,7 @@ export declare const useFormItemProps: (column: FlexibleGroupColumnType, context
|
|
|
141
141
|
* 创建组件属性
|
|
142
142
|
*/
|
|
143
143
|
export declare const createComponentProps: (column: FlexibleGroupColumnType, formItemProps: any) => {
|
|
144
|
-
componentProps: import("lodash").Omit<any, "format" | "valueType" | "switchValue" | "dependNames" | "toISOString" | "toCSTString" | "
|
|
144
|
+
componentProps: import("lodash").Omit<any, "format" | "clearNotShow" | "valueType" | "switchValue" | "dependNames" | "toISOString" | "toCSTString" | "precision">;
|
|
145
145
|
formItemTransform: {
|
|
146
146
|
getValueProps: any;
|
|
147
147
|
normalize: any;
|
|
@@ -55,7 +55,7 @@ export type FunctionArgs<Values, R = any> = (value: any, record: any, { form, in
|
|
|
55
55
|
namePath?: NamePath;
|
|
56
56
|
[key: string]: any;
|
|
57
57
|
}) => R;
|
|
58
|
-
type TransformToFormField<T extends ControlProps, Values> = DistributiveOmit<T, 'onChange' | 'value'> & {
|
|
58
|
+
type TransformToFormField<T extends ControlProps, Values> = DistributiveOmit<T, 'onChange' | 'value' | 'role'> & {
|
|
59
59
|
value?: T['value'];
|
|
60
60
|
onChange?: (value: Parameters<T['onChange']>[0], options: Parameters<T['onChange']>[1], form: FormInstance<Values>) => void;
|
|
61
61
|
onFieldChange?: FunctionArgs<Values>;
|
|
@@ -66,7 +66,7 @@ type TransformToFormField<T extends ControlProps, Values> = DistributiveOmit<T,
|
|
|
66
66
|
type ProEnumFormType<Values> = TransformToFormField<ProEnum, Values> | TransformToFormField<ProEnum & PropProSelectsMap, Values> | TransformToFormField<ProEnum & PropRadioPropsMap, Values> | TransformToFormField<ProEnum & CheckboxPropsMap, Values>;
|
|
67
67
|
type ProEnumTableType<Values> = TransformToTableField<ProEnum, Values> | TransformToTableField<ProEnum & PropProSelectsMap, Values> | TransformToTableField<ProEnum & PropRadioPropsMap, Values> | TransformToTableField<ProEnum & CheckboxPropsMap, Values>;
|
|
68
68
|
type ProEnumFieldType<Values, TT> = TT extends 'ProForm' ? ProEnumFormType<Values> | ReactiveFunction<Values, ProEnumFormType<Values>> : ProEnumTableType<Values> | ((text: any, values: Values, index: number) => ProEnumTableType<Values>);
|
|
69
|
-
type TransformToTableField<T extends ControlProps, Values> = Omit<T, 'onChange' | 'value' | 'onBlur'> & {
|
|
69
|
+
type TransformToTableField<T extends ControlProps, Values> = Omit<T, 'onChange' | 'value' | 'onBlur' | 'role'> & {
|
|
70
70
|
value?: T['value'];
|
|
71
71
|
onChange?: (value: Parameters<T['onChange']>[0], options: Parameters<T['onChange']>[1], record: any, index: number, form: FormInstance<Values>) => void;
|
|
72
72
|
onFieldChange?: FunctionArgs<Values>;
|
package/es/ProForm/index.d.ts
CHANGED
|
@@ -1,16 +1,6 @@
|
|
|
1
|
-
import { FormInstance } from 'antd';
|
|
2
1
|
import React from 'react';
|
|
3
2
|
import { FormProviderProps } from 'antd/es/form/context';
|
|
4
|
-
import type {
|
|
5
|
-
|
|
6
|
-
import useWatch from './utils/useWatch';
|
|
7
|
-
import { useForms } from '../FormsProvider';
|
|
8
|
-
interface IProForm<T = any> extends React.ForwardRefExoticComponent<ProFormType<T> & React.RefAttributes<FormInstance<T>>> {
|
|
9
|
-
useForm: typeof useForm;
|
|
10
|
-
useWatch: typeof useWatch;
|
|
11
|
-
useFormInstances: typeof useForms;
|
|
12
|
-
[key: string]: any;
|
|
13
|
-
}
|
|
14
|
-
declare const ProFormForward: IProForm;
|
|
3
|
+
import type { ProFormInstanceType } from './propsType';
|
|
4
|
+
declare const ProFormForward: ProFormInstanceType<any>;
|
|
15
5
|
export declare const ProFormProvider: React.FC<FormProviderProps>;
|
|
16
6
|
export default ProFormForward;
|
package/es/ProForm/index.js
CHANGED
|
@@ -117,6 +117,17 @@ export interface TransformType<T = any> {
|
|
|
117
117
|
shouldUpdate?: ShouldUpdate<T>;
|
|
118
118
|
}
|
|
119
119
|
export type DistributiveOmit<T, K extends keyof any> = T extends any ? Omit<T, K> : never;
|
|
120
|
+
/**
|
|
121
|
+
* ProForm 组件接口类型
|
|
122
|
+
* 用于定义 ProForm 组件及其静态方法的类型
|
|
123
|
+
* 注意:此接口的具体实现方法类型在组件文件中定义,这里只提供基础结构
|
|
124
|
+
*/
|
|
125
|
+
export interface ProFormInstanceType<T = any> extends React.ForwardRefExoticComponent<ProFormType<T> & React.RefAttributes<FormInstance<T>>> {
|
|
126
|
+
useForm: any;
|
|
127
|
+
useWatch: any;
|
|
128
|
+
useFormInstances: any;
|
|
129
|
+
[key: string]: any;
|
|
130
|
+
}
|
|
120
131
|
/**
|
|
121
132
|
* 兼容旧命名导出
|
|
122
133
|
*/
|
package/es/ProForm/propsType.js
CHANGED
|
@@ -35,6 +35,8 @@ export declare const getThemeUpdaters: () => {
|
|
|
35
35
|
};
|
|
36
36
|
interface ThemeProviderProps {
|
|
37
37
|
children: ReactNode;
|
|
38
|
+
initialLocalConfig?: Partial<LocalThemeConfigType>;
|
|
39
|
+
initialAntdConfig?: AntdThemeConfigType;
|
|
38
40
|
}
|
|
39
41
|
export declare const ThemeProvider: React.FC<ThemeProviderProps>;
|
|
40
42
|
export declare const useTheme: () => ThemeContextType;
|
|
@@ -9,7 +9,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
9
9
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
10
10
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
11
11
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
12
|
-
import React, { createContext, useContext, useReducer, useCallback } from 'react';
|
|
12
|
+
import React, { createContext, useContext, useReducer, useCallback, useEffect } from 'react';
|
|
13
13
|
|
|
14
14
|
// antd5 主题配置接口
|
|
15
15
|
|
|
@@ -36,17 +36,44 @@ var defaultThemeConfig = {
|
|
|
36
36
|
zauiStripe: true
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
-
//
|
|
40
|
-
var
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
// 获取初始状态,检查是否有待应用的主题
|
|
40
|
+
var getInitialState = () => {
|
|
41
|
+
// 检查是否有待应用的主题(在模块加载时可能已经设置)
|
|
42
|
+
var initialAntdConfig = {
|
|
43
43
|
token: {
|
|
44
|
-
colorPrimary:
|
|
44
|
+
colorPrimary: defaultThemeConfig.zauiBrand
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// 尝试获取待应用的主题(避免循环依赖,使用动态导入)
|
|
49
|
+
if (typeof window !== 'undefined') {
|
|
50
|
+
try {
|
|
51
|
+
var _document$documentEle;
|
|
52
|
+
// 使用同步方式检查 pendingThemes(通过全局变量访问)
|
|
53
|
+
// 注意:这里不能直接导入 utils,因为会有循环依赖
|
|
54
|
+
// 但我们可以通过检查 CSS 变量来判断是否有待应用的主题
|
|
55
|
+
var cssZauiBrand = (_document$documentEle = document.documentElement.style.getPropertyValue('--zaui-brand')) === null || _document$documentEle === void 0 ? void 0 : _document$documentEle.trim();
|
|
56
|
+
if (cssZauiBrand && cssZauiBrand !== defaultThemeConfig.zauiBrand) {
|
|
57
|
+
initialAntdConfig = {
|
|
58
|
+
token: {
|
|
59
|
+
colorPrimary: cssZauiBrand
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
} catch (e) {
|
|
64
|
+
// 忽略错误,使用默认配置
|
|
45
65
|
}
|
|
46
|
-
}
|
|
47
|
-
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
localConfig: defaultThemeConfig,
|
|
69
|
+
antdConfig: initialAntdConfig,
|
|
70
|
+
cssVariables: {}
|
|
71
|
+
};
|
|
48
72
|
};
|
|
49
73
|
|
|
74
|
+
// 初始状态
|
|
75
|
+
var initialState = getInitialState();
|
|
76
|
+
|
|
50
77
|
// Reducer 函数
|
|
51
78
|
function themeReducer(state, action) {
|
|
52
79
|
switch (action.type) {
|
|
@@ -103,8 +130,51 @@ export var getThemeUpdaters = () => ({
|
|
|
103
130
|
// Provider 组件
|
|
104
131
|
|
|
105
132
|
export var ThemeProvider = _ref => {
|
|
106
|
-
var children = _ref.children
|
|
107
|
-
|
|
133
|
+
var children = _ref.children,
|
|
134
|
+
initialLocalConfig = _ref.initialLocalConfig,
|
|
135
|
+
initialAntdConfig = _ref.initialAntdConfig;
|
|
136
|
+
// 使用惰性初始化,在组件渲染时检查 CSS 变量
|
|
137
|
+
var _useReducer = useReducer(themeReducer, initialState, initial => {
|
|
138
|
+
// 合并初始配置
|
|
139
|
+
var finalState = _objectSpread({}, initial);
|
|
140
|
+
|
|
141
|
+
// 应用 initialLocalConfig
|
|
142
|
+
if (initialLocalConfig) {
|
|
143
|
+
finalState = _objectSpread(_objectSpread({}, finalState), {}, {
|
|
144
|
+
localConfig: _objectSpread(_objectSpread({}, finalState.localConfig), initialLocalConfig)
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// 应用 initialAntdConfig
|
|
149
|
+
if (initialAntdConfig) {
|
|
150
|
+
finalState = _objectSpread(_objectSpread({}, finalState), {}, {
|
|
151
|
+
antdConfig: initialAntdConfig
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// 在初始化时检查 CSS 变量
|
|
156
|
+
if (typeof window !== 'undefined') {
|
|
157
|
+
try {
|
|
158
|
+
var _document$documentEle2, _finalState$antdConfi;
|
|
159
|
+
var cssZauiBrand = (_document$documentEle2 = document.documentElement.style.getPropertyValue('--zaui-brand')) === null || _document$documentEle2 === void 0 ? void 0 : _document$documentEle2.trim();
|
|
160
|
+
if (cssZauiBrand && cssZauiBrand !== ((_finalState$antdConfi = finalState.antdConfig.token) === null || _finalState$antdConfi === void 0 ? void 0 : _finalState$antdConfi.colorPrimary)) {
|
|
161
|
+
return _objectSpread(_objectSpread({}, finalState), {}, {
|
|
162
|
+
antdConfig: {
|
|
163
|
+
token: {
|
|
164
|
+
colorPrimary: cssZauiBrand
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
localConfig: _objectSpread(_objectSpread({}, finalState.localConfig), {}, {
|
|
168
|
+
zauiBrand: cssZauiBrand
|
|
169
|
+
})
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
} catch (e) {
|
|
173
|
+
// 忽略错误
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return finalState;
|
|
177
|
+
}),
|
|
108
178
|
_useReducer2 = _slicedToArray(_useReducer, 2),
|
|
109
179
|
state = _useReducer2[0],
|
|
110
180
|
dispatch = _useReducer2[1];
|
|
@@ -139,12 +209,55 @@ export var ThemeProvider = _ref => {
|
|
|
139
209
|
}, []);
|
|
140
210
|
|
|
141
211
|
// 注册全局更新函数,供 setThemes 静态方法使用
|
|
142
|
-
|
|
212
|
+
useEffect(() => {
|
|
143
213
|
registerThemeUpdaters({
|
|
144
214
|
updateAntdConfig,
|
|
145
215
|
updateCssVariables,
|
|
146
216
|
updateLocalConfig
|
|
147
217
|
});
|
|
218
|
+
|
|
219
|
+
// 应用待应用的主题配置(如果存在)
|
|
220
|
+
// 使用同步方式应用以避免闪烁,但需要避免循环依赖
|
|
221
|
+
// 由于初始状态已经检查了 CSS 变量,这里只需要确保 Context 状态同步
|
|
222
|
+
if (typeof window !== 'undefined') {
|
|
223
|
+
var _document$documentEle3, _state$antdConfig$tok;
|
|
224
|
+
// 检查 CSS 变量,如果与当前状态不一致,更新 Context
|
|
225
|
+
var cssZauiBrand = (_document$documentEle3 = document.documentElement.style.getPropertyValue('--zaui-brand')) === null || _document$documentEle3 === void 0 ? void 0 : _document$documentEle3.trim();
|
|
226
|
+
if (cssZauiBrand && cssZauiBrand !== ((_state$antdConfig$tok = state.antdConfig.token) === null || _state$antdConfig$tok === void 0 ? void 0 : _state$antdConfig$tok.colorPrimary)) {
|
|
227
|
+
var antdConfig = {
|
|
228
|
+
token: {
|
|
229
|
+
colorPrimary: cssZauiBrand
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
updateAntdConfig(antdConfig);
|
|
233
|
+
updateLocalConfig({
|
|
234
|
+
zauiBrand: cssZauiBrand
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// 也检查是否有待应用的主题(通过动态导入)
|
|
239
|
+
// 使用微任务确保在同一个渲染周期内执行,但避免阻塞
|
|
240
|
+
Promise.resolve().then(() => {
|
|
241
|
+
// 动态导入以避免循环依赖
|
|
242
|
+
import("../utils/index").then(_ref2 => {
|
|
243
|
+
var getPendingThemes = _ref2.getPendingThemes,
|
|
244
|
+
setThemes = _ref2.setThemes,
|
|
245
|
+
clearPendingThemes = _ref2.clearPendingThemes;
|
|
246
|
+
var pending = getPendingThemes();
|
|
247
|
+
if (pending) {
|
|
248
|
+
// 重新调用 setThemes 以应用主题(此时更新函数已经注册)
|
|
249
|
+
setThemes(pending);
|
|
250
|
+
clearPendingThemes();
|
|
251
|
+
}
|
|
252
|
+
}).catch(e => {
|
|
253
|
+
// 在测试环境中,动态导入可能失败,忽略错误
|
|
254
|
+
// eslint-disable-next-line no-console
|
|
255
|
+
if (process.env.NODE_ENV !== 'test') {
|
|
256
|
+
console.warn('Failed to load pending themes:', e);
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
}
|
|
148
261
|
}, [updateAntdConfig, updateCssVariables, updateLocalConfig]);
|
|
149
262
|
var contextValue = {
|
|
150
263
|
state,
|
|
@@ -7,6 +7,8 @@ declare let getThemeUpdaters: (() => {
|
|
|
7
7
|
updateLocalConfig: ((config: any) => void) | null;
|
|
8
8
|
}) | null;
|
|
9
9
|
export declare const setThemeUpdatersGetter: (getter: typeof getThemeUpdaters) => void;
|
|
10
|
+
export declare const getPendingThemes: () => ThemesProps | null;
|
|
11
|
+
export declare const clearPendingThemes: () => void;
|
|
10
12
|
/**
|
|
11
13
|
* 将 kebab-case 的主题配置转换为 antd5 的 token 格式
|
|
12
14
|
* @param themes kebab-case 格式的主题配置
|