@zat-design/sisyphus-react 4.0.9 → 4.0.10
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 +17 -17
- package/es/ProForm/components/render/propsType.d.ts +2 -2
- package/es/ProThemeTools/context/ThemeContext.js +98 -10
- 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 +17 -17
- package/lib/ProForm/components/render/propsType.d.ts +2 -2
- package/lib/ProThemeTools/context/ThemeContext.js +97 -9
- 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,37 +75,35 @@ 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
|
+
validateTrigger?: string | false | string[];
|
|
79
|
+
isView?: boolean;
|
|
80
|
+
id?: string;
|
|
81
|
+
prefixCls?: string;
|
|
82
|
+
className?: string;
|
|
78
83
|
style?: React.CSSProperties;
|
|
79
|
-
trim?: boolean;
|
|
80
|
-
normalize?: (value: any, prevValue: any, allValues: import("@rc-component/form/lib/interface").Store) => any;
|
|
81
84
|
children?: React.ReactNode | ((form: FormInstance<any>) => React.ReactNode);
|
|
82
|
-
className?: string;
|
|
83
|
-
hidden?: boolean;
|
|
84
|
-
layout?: import("antd/es/form/Form").FormItemLayout;
|
|
85
|
-
help?: React.ReactNode;
|
|
86
|
-
vertical?: boolean;
|
|
87
|
-
preserve?: boolean;
|
|
88
|
-
prefixCls?: string;
|
|
89
|
-
onReset?: () => void;
|
|
90
|
-
status?: "" | "warning" | "error" | "success" | "validating";
|
|
91
|
-
id?: string;
|
|
92
85
|
rootClassName?: string;
|
|
93
|
-
|
|
86
|
+
status?: "" | "warning" | "error" | "success" | "validating";
|
|
94
87
|
getValueProps?: ((value: any) => Record<string, unknown>) & ((value: any) => Record<string, unknown>);
|
|
88
|
+
hidden?: boolean;
|
|
89
|
+
onReset?: () => void;
|
|
95
90
|
desensitization?: [number, number] | ReactiveFunction<any, [number, number]>;
|
|
96
|
-
|
|
91
|
+
vertical?: boolean;
|
|
92
|
+
valueType?: import("../../../render/propsType").ProFormValueType;
|
|
97
93
|
colon?: boolean;
|
|
94
|
+
htmlFor?: string;
|
|
98
95
|
labelAlign?: import("antd/es/form/interface").FormLabelAlign;
|
|
99
96
|
labelCol?: import("antd").ColProps;
|
|
100
97
|
getValueFromEvent?: (...args: import("@rc-component/form/lib/interface").EventArgs) => any;
|
|
98
|
+
normalize?: (value: any, prevValue: any, allValues: import("@rc-component/form/lib/interface").Store) => any;
|
|
101
99
|
shouldUpdate?: import("@rc-component/form/lib/Field").ShouldUpdate<any>;
|
|
102
100
|
trigger?: string;
|
|
103
|
-
validateTrigger?: string | false | string[];
|
|
104
101
|
validateDebounce?: number;
|
|
105
102
|
valuePropName?: string;
|
|
106
103
|
messageVariables?: Record<string, string>;
|
|
107
104
|
initialValue?: any;
|
|
108
105
|
onMetaChange?: (meta: import("@rc-component/form/lib/Field").MetaEvent) => void;
|
|
106
|
+
preserve?: boolean;
|
|
109
107
|
isListField?: boolean;
|
|
110
108
|
isList?: boolean;
|
|
111
109
|
noStyle?: boolean;
|
|
@@ -113,9 +111,10 @@ export declare const useFormItemProps: (column: FlexibleGroupColumnType, context
|
|
|
113
111
|
icons: import("antd/es/form/FormItem").FeedbackIcons;
|
|
114
112
|
};
|
|
115
113
|
validateStatus?: "" | "warning" | "error" | "success" | "validating";
|
|
114
|
+
layout?: import("antd/es/form/Form").FormItemLayout;
|
|
116
115
|
wrapperCol?: import("antd").ColProps;
|
|
116
|
+
help?: React.ReactNode;
|
|
117
117
|
fieldId?: string;
|
|
118
|
-
valueType?: import("../../../render/propsType").ProFormValueType;
|
|
119
118
|
switchValue?: [any, any];
|
|
120
119
|
viewRender?: (value: any, record: any, { form, index, namePath, }: {
|
|
121
120
|
[key: string]: any;
|
|
@@ -123,6 +122,7 @@ export declare const useFormItemProps: (column: FlexibleGroupColumnType, context
|
|
|
123
122
|
index?: number;
|
|
124
123
|
}) => string | React.ReactElement<any, any>;
|
|
125
124
|
viewType?: import("../../../render/propsType").ViewType;
|
|
125
|
+
trim?: boolean;
|
|
126
126
|
upperCase?: boolean;
|
|
127
127
|
toISOString?: boolean;
|
|
128
128
|
toCSTString?: boolean;
|
|
@@ -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" | "clearNotShow"
|
|
144
|
+
componentProps: import("lodash").Omit<any, "precision" | "format" | "valueType" | "switchValue" | "dependNames" | "toISOString" | "toCSTString" | "clearNotShow">;
|
|
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>;
|
|
@@ -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) {
|
|
@@ -104,7 +131,31 @@ export var getThemeUpdaters = () => ({
|
|
|
104
131
|
|
|
105
132
|
export var ThemeProvider = _ref => {
|
|
106
133
|
var children = _ref.children;
|
|
107
|
-
|
|
134
|
+
// 使用惰性初始化,在组件渲染时检查 CSS 变量
|
|
135
|
+
var _useReducer = useReducer(themeReducer, initialState, initial => {
|
|
136
|
+
// 在初始化时检查 CSS 变量
|
|
137
|
+
if (typeof window !== 'undefined') {
|
|
138
|
+
try {
|
|
139
|
+
var _document$documentEle2, _initial$antdConfig$t;
|
|
140
|
+
var cssZauiBrand = (_document$documentEle2 = document.documentElement.style.getPropertyValue('--zaui-brand')) === null || _document$documentEle2 === void 0 ? void 0 : _document$documentEle2.trim();
|
|
141
|
+
if (cssZauiBrand && cssZauiBrand !== ((_initial$antdConfig$t = initial.antdConfig.token) === null || _initial$antdConfig$t === void 0 ? void 0 : _initial$antdConfig$t.colorPrimary)) {
|
|
142
|
+
return _objectSpread(_objectSpread({}, initial), {}, {
|
|
143
|
+
antdConfig: {
|
|
144
|
+
token: {
|
|
145
|
+
colorPrimary: cssZauiBrand
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
localConfig: _objectSpread(_objectSpread({}, initial.localConfig), {}, {
|
|
149
|
+
zauiBrand: cssZauiBrand
|
|
150
|
+
})
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
} catch (e) {
|
|
154
|
+
// 忽略错误
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return initial;
|
|
158
|
+
}),
|
|
108
159
|
_useReducer2 = _slicedToArray(_useReducer, 2),
|
|
109
160
|
state = _useReducer2[0],
|
|
110
161
|
dispatch = _useReducer2[1];
|
|
@@ -139,12 +190,49 @@ export var ThemeProvider = _ref => {
|
|
|
139
190
|
}, []);
|
|
140
191
|
|
|
141
192
|
// 注册全局更新函数,供 setThemes 静态方法使用
|
|
142
|
-
|
|
193
|
+
useEffect(() => {
|
|
143
194
|
registerThemeUpdaters({
|
|
144
195
|
updateAntdConfig,
|
|
145
196
|
updateCssVariables,
|
|
146
197
|
updateLocalConfig
|
|
147
198
|
});
|
|
199
|
+
|
|
200
|
+
// 应用待应用的主题配置(如果存在)
|
|
201
|
+
// 使用同步方式应用以避免闪烁,但需要避免循环依赖
|
|
202
|
+
// 由于初始状态已经检查了 CSS 变量,这里只需要确保 Context 状态同步
|
|
203
|
+
if (typeof window !== 'undefined') {
|
|
204
|
+
var _document$documentEle3, _state$antdConfig$tok;
|
|
205
|
+
// 检查 CSS 变量,如果与当前状态不一致,更新 Context
|
|
206
|
+
var cssZauiBrand = (_document$documentEle3 = document.documentElement.style.getPropertyValue('--zaui-brand')) === null || _document$documentEle3 === void 0 ? void 0 : _document$documentEle3.trim();
|
|
207
|
+
if (cssZauiBrand && cssZauiBrand !== ((_state$antdConfig$tok = state.antdConfig.token) === null || _state$antdConfig$tok === void 0 ? void 0 : _state$antdConfig$tok.colorPrimary)) {
|
|
208
|
+
var antdConfig = {
|
|
209
|
+
token: {
|
|
210
|
+
colorPrimary: cssZauiBrand
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
updateAntdConfig(antdConfig);
|
|
214
|
+
updateLocalConfig({
|
|
215
|
+
zauiBrand: cssZauiBrand
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// 也检查是否有待应用的主题(通过动态导入)
|
|
220
|
+
// 使用微任务确保在同一个渲染周期内执行,但避免阻塞
|
|
221
|
+
Promise.resolve().then(() => {
|
|
222
|
+
// 动态导入以避免循环依赖
|
|
223
|
+
import("../utils/index").then(_ref2 => {
|
|
224
|
+
var getPendingThemes = _ref2.getPendingThemes,
|
|
225
|
+
setThemes = _ref2.setThemes,
|
|
226
|
+
clearPendingThemes = _ref2.clearPendingThemes;
|
|
227
|
+
var pending = getPendingThemes();
|
|
228
|
+
if (pending) {
|
|
229
|
+
// 重新调用 setThemes 以应用主题(此时更新函数已经注册)
|
|
230
|
+
setThemes(pending);
|
|
231
|
+
clearPendingThemes();
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
}
|
|
148
236
|
}, [updateAntdConfig, updateCssVariables, updateLocalConfig]);
|
|
149
237
|
var contextValue = {
|
|
150
238
|
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 格式的主题配置
|
|
@@ -9,14 +9,45 @@ 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 { getThemeUpdaters as getThemeUpdatersFromContext } from "../context/ThemeContext";
|
|
12
13
|
// 动态导入 getThemeUpdaters,避免循环依赖
|
|
14
|
+
// 保留向后兼容性,但优先使用 ThemeContext 中的 getThemeUpdaters
|
|
13
15
|
var getThemeUpdaters = null;
|
|
14
16
|
|
|
15
|
-
// 设置 getThemeUpdaters 函数(由 index.tsx
|
|
17
|
+
// 设置 getThemeUpdaters 函数(由 index.tsx 调用,用于向后兼容)
|
|
16
18
|
export var setThemeUpdatersGetter = getter => {
|
|
17
19
|
getThemeUpdaters = getter;
|
|
18
20
|
};
|
|
19
21
|
|
|
22
|
+
// 保存待应用的主题配置(用于 ThemeProvider 初始化前设置的主题)
|
|
23
|
+
var pendingThemes = null;
|
|
24
|
+
|
|
25
|
+
// 获取待应用的主题配置
|
|
26
|
+
export var getPendingThemes = () => {
|
|
27
|
+
return pendingThemes;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// 清除待应用的主题配置
|
|
31
|
+
export var clearPendingThemes = () => {
|
|
32
|
+
pendingThemes = null;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// 获取主题更新函数的统一入口
|
|
36
|
+
// 优先使用 ThemeContext 中的 getThemeUpdaters,如果不可用则使用局部变量
|
|
37
|
+
var getThemeUpdatersWrapper = () => {
|
|
38
|
+
try {
|
|
39
|
+
// 优先使用 ThemeContext 中的 getThemeUpdaters(不依赖 ProThemeTools 组件)
|
|
40
|
+
var contextUpdaters = getThemeUpdatersFromContext();
|
|
41
|
+
if (contextUpdaters && (contextUpdaters.updateAntdConfig || contextUpdaters.updateCssVariables || contextUpdaters.updateLocalConfig)) {
|
|
42
|
+
return contextUpdaters;
|
|
43
|
+
}
|
|
44
|
+
} catch (e) {
|
|
45
|
+
// ThemeContext 可能还未初始化,继续使用局部变量
|
|
46
|
+
}
|
|
47
|
+
// 回退到局部变量(向后兼容)
|
|
48
|
+
return getThemeUpdaters ? getThemeUpdaters() : null;
|
|
49
|
+
};
|
|
50
|
+
|
|
20
51
|
/** antd5 主题配置 mapping */
|
|
21
52
|
var antd5ConfigMapping = {
|
|
22
53
|
'zaui-brand': 'colorPrimary'
|
|
@@ -77,9 +108,9 @@ export var setThemes = themes => {
|
|
|
77
108
|
});
|
|
78
109
|
|
|
79
110
|
// 同步更新 Context(如果已注册)
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
111
|
+
// 使用统一的获取函数,优先使用 ThemeContext 中的更新函数
|
|
112
|
+
var updaters = getThemeUpdatersWrapper();
|
|
113
|
+
if (updaters) {
|
|
83
114
|
// 更新 CSS 变量到 Context
|
|
84
115
|
if (updaters.updateCssVariables) {
|
|
85
116
|
updaters.updateCssVariables(filteredThemes.reduce((acc, _ref5) => {
|
|
@@ -121,6 +152,11 @@ export var setThemes = themes => {
|
|
|
121
152
|
updaters.updateLocalConfig(localConfig);
|
|
122
153
|
}
|
|
123
154
|
}
|
|
155
|
+
// 清除待应用的主题配置(因为已经应用了)
|
|
156
|
+
pendingThemes = null;
|
|
157
|
+
} else {
|
|
158
|
+
// 如果更新函数不可用,保存主题配置,等待 ThemeProvider 初始化后应用
|
|
159
|
+
pendingThemes = _objectSpread({}, themes);
|
|
124
160
|
}
|
|
125
161
|
return true;
|
|
126
162
|
};
|
package/es/index.d.ts
CHANGED
|
@@ -27,20 +27,21 @@ export { default as ProAction } from './ProAction';
|
|
|
27
27
|
export * from './ProConfigProvider';
|
|
28
28
|
export * from './locale';
|
|
29
29
|
export { default as ProBackBtn } from './ProLayout/components/ProHeader/components/ProBackBtn';
|
|
30
|
+
export type { ProConfigProviderType } from './ProConfigProvider';
|
|
30
31
|
export type { ProFormType, ProColumnProps, ProFormColumnType } from './ProForm/propsType';
|
|
31
32
|
export type { ProFormComponentType } from './ProForm/components';
|
|
32
|
-
export type { ProTableType, ProTableColumnType, ProTableSummaryType, ProTableUseAntdTableType, ProTableProps, ProTableSummaryProps, ProTableColumn, UseAntdTableState } from './ProTable/propsType';
|
|
33
|
+
export type { ProTableType, ProTableColumnType, ProTableSummaryType, ProTableUseAntdTableType, ProTableProps, ProTableSummaryProps, ProTableColumn, UseAntdTableState, } from './ProTable/propsType';
|
|
33
34
|
export type { ProUploadType, ProUploadProps } from './ProUpload/propsType';
|
|
34
35
|
export type { ProTabsType, ProTabsItemType, ProTabsProps, ProTabsItemsProps } from './ProTabs/propType';
|
|
35
|
-
export type { BreadcrumbColumnType, SubDescribeColumnType, DescribeColumnType, ProHeaderType, ProHeaderProps, BreadcrumbColumnsProps, SubDescribeColumnsProps, DescribeColumnsProps } from './ProLayout/components/ProHeader/PropTypes';
|
|
36
|
+
export type { BreadcrumbColumnType, SubDescribeColumnType, DescribeColumnType, ProHeaderType, ProHeaderProps, BreadcrumbColumnsProps, SubDescribeColumnsProps, DescribeColumnsProps, } from './ProLayout/components/ProHeader/PropTypes';
|
|
36
37
|
export type { ProLayoutTabsInstance, AddTabParams, AddTabOptions } from './ProLayout/propTypes';
|
|
37
38
|
export type { ProTooltipType, ProTooltipProps } from './ProTooltip/propsType';
|
|
38
39
|
export type { ProIconType, ProIconProps } from './ProIcon/propsTypes';
|
|
39
40
|
export type { ProTreeType, ProTreeSelectType, ProTreeProps, PropTreeSelectProps } from './ProTree/propsType';
|
|
40
|
-
export type { ProTreeModalType, ProTreeModalActionType, ProTreeModalProps, ProTreeModalAction } from './ProTreeModal/propsType';
|
|
41
|
-
export type { ProEditTableType, ProEditTableColumnType, ProEditTableSummaryColumnType, ProEditTableSummaryConfigType, ProEditTableActionType, ProEditTableProps, ProEditTableColumnsProps, SummaryProps, SummaryColumnProps, BaseActionProps } from './ProEditTable/propsType';
|
|
42
|
-
export type { ProStepType, ProStepContextType, ProStepItemType, ProStepPropsType, ProStepItemPropsType } from './ProStep/propsType';
|
|
41
|
+
export type { ProTreeModalType, ProTreeModalActionType, ProTreeModalProps, ProTreeModalAction, } from './ProTreeModal/propsType';
|
|
42
|
+
export type { ProEditTableType, ProEditTableColumnType, ProEditTableSummaryColumnType, ProEditTableSummaryConfigType, ProEditTableActionType, ProEditTableProps, ProEditTableColumnsProps, SummaryProps, SummaryColumnProps, BaseActionProps, } from './ProEditTable/propsType';
|
|
43
|
+
export type { ProStepType, ProStepContextType, ProStepItemType, ProStepPropsType, ProStepItemPropsType, } from './ProStep/propsType';
|
|
43
44
|
export type { ProDrawerFormType, ProDrawerFormPropsType } from './ProDrawerForm/propsType';
|
|
44
|
-
export type { ProModalSelectType, ProModalSelectConfigType, ProModalSelectPropsType } from './ProForm/components/combination/ProModalSelect/propsType';
|
|
45
|
+
export type { ProModalSelectType, ProModalSelectConfigType, ProModalSelectPropsType, } from './ProForm/components/combination/ProModalSelect/propsType';
|
|
45
46
|
export type { ProStepTabType, ProStepTabResultType } from './ProStepTab/propsType';
|
|
46
47
|
export * from './tokens';
|
package/es/index.js
CHANGED
|
@@ -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;
|
|
@@ -47,38 +47,36 @@ var initialState = {
|
|
|
47
47
|
}]
|
|
48
48
|
}
|
|
49
49
|
};
|
|
50
|
+
var antdLangMap = {
|
|
51
|
+
'zh-CN': _zh_CN.default,
|
|
52
|
+
'en-US': _en_US.default
|
|
53
|
+
};
|
|
50
54
|
var ProConfigContext = exports.ProConfigContext = /*#__PURE__*/_react.default.createContext({
|
|
51
55
|
state: initialState,
|
|
52
56
|
dispatch: () => {}
|
|
53
57
|
});
|
|
54
|
-
|
|
55
|
-
// eslint-disable-next-line no-redeclare
|
|
56
|
-
|
|
57
|
-
// eslint-disable-next-line no-redeclare
|
|
58
58
|
function useProConfig(name) {
|
|
59
59
|
var _useContext = (0, _react.useContext)(ProConfigContext),
|
|
60
60
|
state = _useContext.state,
|
|
61
61
|
dispatch = _useContext.dispatch;
|
|
62
|
-
if (name)
|
|
63
|
-
return state[name];
|
|
64
|
-
}
|
|
62
|
+
if (name) return state[name];
|
|
65
63
|
return {
|
|
66
64
|
state,
|
|
67
65
|
dispatch
|
|
68
66
|
};
|
|
69
67
|
}
|
|
70
|
-
|
|
71
|
-
var _state$ProEnum;
|
|
68
|
+
function reducer(state, action) {
|
|
69
|
+
var _state$forms, _state$forms2, _state$ProEnum$dics, _state$ProEnum;
|
|
72
70
|
switch (action.type) {
|
|
73
71
|
case 'setFormRef':
|
|
74
72
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
75
|
-
forms: _objectSpread(_objectSpread({}, state.forms), {}, {
|
|
73
|
+
forms: _objectSpread(_objectSpread({}, (_state$forms = state.forms) !== null && _state$forms !== void 0 ? _state$forms : {}), {}, {
|
|
76
74
|
[action.name]: action.value
|
|
77
75
|
})
|
|
78
76
|
});
|
|
79
77
|
case 'deleteFormRef':
|
|
80
78
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
81
|
-
forms: _objectSpread(_objectSpread({}, state.forms), {}, {
|
|
79
|
+
forms: _objectSpread(_objectSpread({}, (_state$forms2 = state.forms) !== null && _state$forms2 !== void 0 ? _state$forms2 : {}), {}, {
|
|
82
80
|
[action.name]: undefined
|
|
83
81
|
})
|
|
84
82
|
});
|
|
@@ -91,19 +89,16 @@ var reducer = (state, action) => {
|
|
|
91
89
|
case 'setProEnumDic':
|
|
92
90
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
93
91
|
ProEnum: _objectSpread(_objectSpread({}, state.ProEnum), {}, {
|
|
94
|
-
dics: _objectSpread(_objectSpread({}, ((_state$ProEnum = state.ProEnum) === null || _state$ProEnum === void 0 ? void 0 : _state$ProEnum.
|
|
92
|
+
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)
|
|
95
93
|
})
|
|
96
94
|
});
|
|
97
95
|
case 'setWithLocal':
|
|
98
|
-
// 本地配置合并
|
|
99
96
|
localStorage.setItem('localConfig', JSON.stringify(action.payload));
|
|
100
97
|
return _objectSpread({}, state);
|
|
101
98
|
default:
|
|
102
|
-
return
|
|
99
|
+
return state;
|
|
103
100
|
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// 内部组件,用于监听主题变化并应用到 ConfigProvider
|
|
101
|
+
}
|
|
107
102
|
var ThemeAwareConfigProvider = _ref => {
|
|
108
103
|
var locale = _ref.locale,
|
|
109
104
|
children = _ref.children;
|
|
@@ -118,45 +113,33 @@ var ThemeAwareConfigProvider = _ref => {
|
|
|
118
113
|
});
|
|
119
114
|
};
|
|
120
115
|
var ProConfigProvider = props => {
|
|
121
|
-
var _props$value, _props$value2, _props$value3, _props$value4;
|
|
116
|
+
var _props$value, _props$value2, _props$value3, _props$value4, _ref2, _ref3, _state$locale, _antdLangMap$lang;
|
|
122
117
|
var _useReducer = (0, _react.useReducer)(reducer, initialState),
|
|
123
118
|
_useReducer2 = _slicedToArray(_useReducer, 2),
|
|
124
119
|
state = _useReducer2[0],
|
|
125
120
|
dispatch = _useReducer2[1];
|
|
126
121
|
var enumRes = (0, _useEnumRequest.default)(_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);
|
|
127
|
-
|
|
128
|
-
// 处理频繁枚举请求
|
|
129
122
|
var frequentEnumRes = (0, _useFrequentEnumRequest.default)(_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);
|
|
123
|
+
var cacheLang = localStorage.getItem('locale');
|
|
124
|
+
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';
|
|
130
125
|
(0, _react.useEffect)(() => {
|
|
131
|
-
|
|
132
|
-
var
|
|
133
|
-
var localConfig = JSON.parse(localConfigStr || '{}');
|
|
126
|
+
var raw = localStorage.getItem('localConfig');
|
|
127
|
+
var localConfig = JSON.parse(raw || '{}');
|
|
134
128
|
dispatch({
|
|
135
129
|
type: 'set',
|
|
136
|
-
payload: (0, _merge.default)(
|
|
130
|
+
payload: (0, _merge.default)(initialState, localConfig)
|
|
137
131
|
});
|
|
138
132
|
}, []);
|
|
139
|
-
var cacheLang = localStorage.getItem('locale');
|
|
140
|
-
// 如果是用户切换了语言那么优先使用用户切换的,否则从缓存中取用户语言,在取默认值
|
|
141
|
-
var lang = (state === null || state === void 0 ? void 0 : state.locale) || cacheLang || (props === null || props === void 0 ? void 0 : props.locale);
|
|
142
133
|
(0, _react.useEffect)(() => {
|
|
143
134
|
(0, _locale.setLanguage)(lang);
|
|
144
135
|
}, [lang]);
|
|
145
136
|
(0, _react.useEffect)(() => {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
137
|
+
var _props$onSuccess;
|
|
138
|
+
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);
|
|
149
139
|
}, [enumRes === null || enumRes === void 0 ? void 0 : enumRes.loading]);
|
|
150
|
-
var antdLangMap = {
|
|
151
|
-
'zh-CN': _zh_CN.default,
|
|
152
|
-
// zh-CN 中文
|
|
153
|
-
'en-US': _en_US.default // en-US
|
|
154
|
-
};
|
|
155
|
-
// 处理频繁枚举的成功回调
|
|
156
140
|
(0, _react.useEffect)(() => {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}
|
|
141
|
+
var _props$onSuccess2;
|
|
142
|
+
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);
|
|
160
143
|
}, [frequentEnumRes === null || frequentEnumRes === void 0 ? void 0 : frequentEnumRes.loading]);
|
|
161
144
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_ThemeContext.ThemeProvider, {
|
|
162
145
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(ProConfigContext.Provider, {
|
|
@@ -165,7 +148,7 @@ var ProConfigProvider = props => {
|
|
|
165
148
|
dispatch
|
|
166
149
|
},
|
|
167
150
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(ThemeAwareConfigProvider, {
|
|
168
|
-
locale: antdLangMap[lang],
|
|
151
|
+
locale: (_antdLangMap$lang = antdLangMap[lang]) !== null && _antdLangMap$lang !== void 0 ? _antdLangMap$lang : _zh_CN.default,
|
|
169
152
|
children: props.children
|
|
170
153
|
})
|
|
171
154
|
})
|
|
@@ -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
|
+
};
|
|
@@ -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,37 +75,35 @@ 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
|
+
validateTrigger?: string | false | string[];
|
|
79
|
+
isView?: boolean;
|
|
80
|
+
id?: string;
|
|
81
|
+
prefixCls?: string;
|
|
82
|
+
className?: string;
|
|
78
83
|
style?: React.CSSProperties;
|
|
79
|
-
trim?: boolean;
|
|
80
|
-
normalize?: (value: any, prevValue: any, allValues: import("@rc-component/form/lib/interface").Store) => any;
|
|
81
84
|
children?: React.ReactNode | ((form: FormInstance<any>) => React.ReactNode);
|
|
82
|
-
className?: string;
|
|
83
|
-
hidden?: boolean;
|
|
84
|
-
layout?: import("antd/es/form/Form").FormItemLayout;
|
|
85
|
-
help?: React.ReactNode;
|
|
86
|
-
vertical?: boolean;
|
|
87
|
-
preserve?: boolean;
|
|
88
|
-
prefixCls?: string;
|
|
89
|
-
onReset?: () => void;
|
|
90
|
-
status?: "" | "warning" | "error" | "success" | "validating";
|
|
91
|
-
id?: string;
|
|
92
85
|
rootClassName?: string;
|
|
93
|
-
|
|
86
|
+
status?: "" | "warning" | "error" | "success" | "validating";
|
|
94
87
|
getValueProps?: ((value: any) => Record<string, unknown>) & ((value: any) => Record<string, unknown>);
|
|
88
|
+
hidden?: boolean;
|
|
89
|
+
onReset?: () => void;
|
|
95
90
|
desensitization?: [number, number] | ReactiveFunction<any, [number, number]>;
|
|
96
|
-
|
|
91
|
+
vertical?: boolean;
|
|
92
|
+
valueType?: import("../../../render/propsType").ProFormValueType;
|
|
97
93
|
colon?: boolean;
|
|
94
|
+
htmlFor?: string;
|
|
98
95
|
labelAlign?: import("antd/es/form/interface").FormLabelAlign;
|
|
99
96
|
labelCol?: import("antd").ColProps;
|
|
100
97
|
getValueFromEvent?: (...args: import("@rc-component/form/lib/interface").EventArgs) => any;
|
|
98
|
+
normalize?: (value: any, prevValue: any, allValues: import("@rc-component/form/lib/interface").Store) => any;
|
|
101
99
|
shouldUpdate?: import("@rc-component/form/lib/Field").ShouldUpdate<any>;
|
|
102
100
|
trigger?: string;
|
|
103
|
-
validateTrigger?: string | false | string[];
|
|
104
101
|
validateDebounce?: number;
|
|
105
102
|
valuePropName?: string;
|
|
106
103
|
messageVariables?: Record<string, string>;
|
|
107
104
|
initialValue?: any;
|
|
108
105
|
onMetaChange?: (meta: import("@rc-component/form/lib/Field").MetaEvent) => void;
|
|
106
|
+
preserve?: boolean;
|
|
109
107
|
isListField?: boolean;
|
|
110
108
|
isList?: boolean;
|
|
111
109
|
noStyle?: boolean;
|
|
@@ -113,9 +111,10 @@ export declare const useFormItemProps: (column: FlexibleGroupColumnType, context
|
|
|
113
111
|
icons: import("antd/es/form/FormItem").FeedbackIcons;
|
|
114
112
|
};
|
|
115
113
|
validateStatus?: "" | "warning" | "error" | "success" | "validating";
|
|
114
|
+
layout?: import("antd/es/form/Form").FormItemLayout;
|
|
116
115
|
wrapperCol?: import("antd").ColProps;
|
|
116
|
+
help?: React.ReactNode;
|
|
117
117
|
fieldId?: string;
|
|
118
|
-
valueType?: import("../../../render/propsType").ProFormValueType;
|
|
119
118
|
switchValue?: [any, any];
|
|
120
119
|
viewRender?: (value: any, record: any, { form, index, namePath, }: {
|
|
121
120
|
[key: string]: any;
|
|
@@ -123,6 +122,7 @@ export declare const useFormItemProps: (column: FlexibleGroupColumnType, context
|
|
|
123
122
|
index?: number;
|
|
124
123
|
}) => string | React.ReactElement<any, any>;
|
|
125
124
|
viewType?: import("../../../render/propsType").ViewType;
|
|
125
|
+
trim?: boolean;
|
|
126
126
|
upperCase?: boolean;
|
|
127
127
|
toISOString?: boolean;
|
|
128
128
|
toCSTString?: boolean;
|
|
@@ -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" | "clearNotShow"
|
|
144
|
+
componentProps: import("lodash").Omit<any, "precision" | "format" | "valueType" | "switchValue" | "dependNames" | "toISOString" | "toCSTString" | "clearNotShow">;
|
|
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>;
|
|
@@ -39,17 +39,44 @@ var defaultThemeConfig = exports.defaultThemeConfig = {
|
|
|
39
39
|
zauiStripe: true
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
-
//
|
|
43
|
-
var
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
// 获取初始状态,检查是否有待应用的主题
|
|
43
|
+
var getInitialState = () => {
|
|
44
|
+
// 检查是否有待应用的主题(在模块加载时可能已经设置)
|
|
45
|
+
var initialAntdConfig = {
|
|
46
46
|
token: {
|
|
47
|
-
colorPrimary:
|
|
47
|
+
colorPrimary: defaultThemeConfig.zauiBrand
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// 尝试获取待应用的主题(避免循环依赖,使用动态导入)
|
|
52
|
+
if (typeof window !== 'undefined') {
|
|
53
|
+
try {
|
|
54
|
+
var _document$documentEle;
|
|
55
|
+
// 使用同步方式检查 pendingThemes(通过全局变量访问)
|
|
56
|
+
// 注意:这里不能直接导入 utils,因为会有循环依赖
|
|
57
|
+
// 但我们可以通过检查 CSS 变量来判断是否有待应用的主题
|
|
58
|
+
var cssZauiBrand = (_document$documentEle = document.documentElement.style.getPropertyValue('--zaui-brand')) === null || _document$documentEle === void 0 ? void 0 : _document$documentEle.trim();
|
|
59
|
+
if (cssZauiBrand && cssZauiBrand !== defaultThemeConfig.zauiBrand) {
|
|
60
|
+
initialAntdConfig = {
|
|
61
|
+
token: {
|
|
62
|
+
colorPrimary: cssZauiBrand
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
} catch (e) {
|
|
67
|
+
// 忽略错误,使用默认配置
|
|
48
68
|
}
|
|
49
|
-
}
|
|
50
|
-
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
localConfig: defaultThemeConfig,
|
|
72
|
+
antdConfig: initialAntdConfig,
|
|
73
|
+
cssVariables: {}
|
|
74
|
+
};
|
|
51
75
|
};
|
|
52
76
|
|
|
77
|
+
// 初始状态
|
|
78
|
+
var initialState = getInitialState();
|
|
79
|
+
|
|
53
80
|
// Reducer 函数
|
|
54
81
|
function themeReducer(state, action) {
|
|
55
82
|
switch (action.type) {
|
|
@@ -108,7 +135,31 @@ var getThemeUpdaters = () => ({
|
|
|
108
135
|
exports.getThemeUpdaters = getThemeUpdaters;
|
|
109
136
|
var ThemeProvider = _ref => {
|
|
110
137
|
var children = _ref.children;
|
|
111
|
-
|
|
138
|
+
// 使用惰性初始化,在组件渲染时检查 CSS 变量
|
|
139
|
+
var _useReducer = (0, _react.useReducer)(themeReducer, initialState, initial => {
|
|
140
|
+
// 在初始化时检查 CSS 变量
|
|
141
|
+
if (typeof window !== 'undefined') {
|
|
142
|
+
try {
|
|
143
|
+
var _document$documentEle2, _initial$antdConfig$t;
|
|
144
|
+
var cssZauiBrand = (_document$documentEle2 = document.documentElement.style.getPropertyValue('--zaui-brand')) === null || _document$documentEle2 === void 0 ? void 0 : _document$documentEle2.trim();
|
|
145
|
+
if (cssZauiBrand && cssZauiBrand !== ((_initial$antdConfig$t = initial.antdConfig.token) === null || _initial$antdConfig$t === void 0 ? void 0 : _initial$antdConfig$t.colorPrimary)) {
|
|
146
|
+
return _objectSpread(_objectSpread({}, initial), {}, {
|
|
147
|
+
antdConfig: {
|
|
148
|
+
token: {
|
|
149
|
+
colorPrimary: cssZauiBrand
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
localConfig: _objectSpread(_objectSpread({}, initial.localConfig), {}, {
|
|
153
|
+
zauiBrand: cssZauiBrand
|
|
154
|
+
})
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
} catch (e) {
|
|
158
|
+
// 忽略错误
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return initial;
|
|
162
|
+
}),
|
|
112
163
|
_useReducer2 = _slicedToArray(_useReducer, 2),
|
|
113
164
|
state = _useReducer2[0],
|
|
114
165
|
dispatch = _useReducer2[1];
|
|
@@ -143,12 +194,49 @@ var ThemeProvider = _ref => {
|
|
|
143
194
|
}, []);
|
|
144
195
|
|
|
145
196
|
// 注册全局更新函数,供 setThemes 静态方法使用
|
|
146
|
-
_react.
|
|
197
|
+
(0, _react.useEffect)(() => {
|
|
147
198
|
registerThemeUpdaters({
|
|
148
199
|
updateAntdConfig,
|
|
149
200
|
updateCssVariables,
|
|
150
201
|
updateLocalConfig
|
|
151
202
|
});
|
|
203
|
+
|
|
204
|
+
// 应用待应用的主题配置(如果存在)
|
|
205
|
+
// 使用同步方式应用以避免闪烁,但需要避免循环依赖
|
|
206
|
+
// 由于初始状态已经检查了 CSS 变量,这里只需要确保 Context 状态同步
|
|
207
|
+
if (typeof window !== 'undefined') {
|
|
208
|
+
var _document$documentEle3, _state$antdConfig$tok;
|
|
209
|
+
// 检查 CSS 变量,如果与当前状态不一致,更新 Context
|
|
210
|
+
var cssZauiBrand = (_document$documentEle3 = document.documentElement.style.getPropertyValue('--zaui-brand')) === null || _document$documentEle3 === void 0 ? void 0 : _document$documentEle3.trim();
|
|
211
|
+
if (cssZauiBrand && cssZauiBrand !== ((_state$antdConfig$tok = state.antdConfig.token) === null || _state$antdConfig$tok === void 0 ? void 0 : _state$antdConfig$tok.colorPrimary)) {
|
|
212
|
+
var antdConfig = {
|
|
213
|
+
token: {
|
|
214
|
+
colorPrimary: cssZauiBrand
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
updateAntdConfig(antdConfig);
|
|
218
|
+
updateLocalConfig({
|
|
219
|
+
zauiBrand: cssZauiBrand
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// 也检查是否有待应用的主题(通过动态导入)
|
|
224
|
+
// 使用微任务确保在同一个渲染周期内执行,但避免阻塞
|
|
225
|
+
Promise.resolve().then(() => {
|
|
226
|
+
// 动态导入以避免循环依赖
|
|
227
|
+
Promise.resolve().then(() => _interopRequireWildcard(require("../utils/index"))).then(_ref2 => {
|
|
228
|
+
var getPendingThemes = _ref2.getPendingThemes,
|
|
229
|
+
setThemes = _ref2.setThemes,
|
|
230
|
+
clearPendingThemes = _ref2.clearPendingThemes;
|
|
231
|
+
var pending = getPendingThemes();
|
|
232
|
+
if (pending) {
|
|
233
|
+
// 重新调用 setThemes 以应用主题(此时更新函数已经注册)
|
|
234
|
+
setThemes(pending);
|
|
235
|
+
clearPendingThemes();
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
}
|
|
152
240
|
}, [updateAntdConfig, updateCssVariables, updateLocalConfig]);
|
|
153
241
|
var contextValue = {
|
|
154
242
|
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 格式的主题配置
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.setThemes = exports.setThemeUpdatersGetter = exports.setTableNoStripe = exports.setTableBorder = exports.getMapKebabCase = exports.getMapHumpCase = exports.getKebabCase = exports.getAntd5ThemeConfig = exports.convertToAntd5Tokens = void 0;
|
|
6
|
+
exports.setThemes = exports.setThemeUpdatersGetter = exports.setTableNoStripe = exports.setTableBorder = exports.getPendingThemes = exports.getMapKebabCase = exports.getMapHumpCase = exports.getKebabCase = exports.getAntd5ThemeConfig = exports.convertToAntd5Tokens = exports.clearPendingThemes = void 0;
|
|
7
|
+
var _ThemeContext = require("../context/ThemeContext");
|
|
7
8
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
8
9
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
9
10
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
@@ -16,15 +17,47 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
16
17
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
17
18
|
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); }
|
|
18
19
|
// 动态导入 getThemeUpdaters,避免循环依赖
|
|
20
|
+
// 保留向后兼容性,但优先使用 ThemeContext 中的 getThemeUpdaters
|
|
19
21
|
var getThemeUpdaters = null;
|
|
20
22
|
|
|
21
|
-
// 设置 getThemeUpdaters 函数(由 index.tsx
|
|
23
|
+
// 设置 getThemeUpdaters 函数(由 index.tsx 调用,用于向后兼容)
|
|
22
24
|
var setThemeUpdatersGetter = getter => {
|
|
23
25
|
getThemeUpdaters = getter;
|
|
24
26
|
};
|
|
25
27
|
|
|
26
|
-
|
|
28
|
+
// 保存待应用的主题配置(用于 ThemeProvider 初始化前设置的主题)
|
|
27
29
|
exports.setThemeUpdatersGetter = setThemeUpdatersGetter;
|
|
30
|
+
var pendingThemes = null;
|
|
31
|
+
|
|
32
|
+
// 获取待应用的主题配置
|
|
33
|
+
var getPendingThemes = () => {
|
|
34
|
+
return pendingThemes;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// 清除待应用的主题配置
|
|
38
|
+
exports.getPendingThemes = getPendingThemes;
|
|
39
|
+
var clearPendingThemes = () => {
|
|
40
|
+
pendingThemes = null;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// 获取主题更新函数的统一入口
|
|
44
|
+
// 优先使用 ThemeContext 中的 getThemeUpdaters,如果不可用则使用局部变量
|
|
45
|
+
exports.clearPendingThemes = clearPendingThemes;
|
|
46
|
+
var getThemeUpdatersWrapper = () => {
|
|
47
|
+
try {
|
|
48
|
+
// 优先使用 ThemeContext 中的 getThemeUpdaters(不依赖 ProThemeTools 组件)
|
|
49
|
+
var contextUpdaters = (0, _ThemeContext.getThemeUpdaters)();
|
|
50
|
+
if (contextUpdaters && (contextUpdaters.updateAntdConfig || contextUpdaters.updateCssVariables || contextUpdaters.updateLocalConfig)) {
|
|
51
|
+
return contextUpdaters;
|
|
52
|
+
}
|
|
53
|
+
} catch (e) {
|
|
54
|
+
// ThemeContext 可能还未初始化,继续使用局部变量
|
|
55
|
+
}
|
|
56
|
+
// 回退到局部变量(向后兼容)
|
|
57
|
+
return getThemeUpdaters ? getThemeUpdaters() : null;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/** antd5 主题配置 mapping */
|
|
28
61
|
var antd5ConfigMapping = {
|
|
29
62
|
'zaui-brand': 'colorPrimary'
|
|
30
63
|
// 可以根据需要添加更多映射
|
|
@@ -85,9 +118,9 @@ var setThemes = themes => {
|
|
|
85
118
|
});
|
|
86
119
|
|
|
87
120
|
// 同步更新 Context(如果已注册)
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
121
|
+
// 使用统一的获取函数,优先使用 ThemeContext 中的更新函数
|
|
122
|
+
var updaters = getThemeUpdatersWrapper();
|
|
123
|
+
if (updaters) {
|
|
91
124
|
// 更新 CSS 变量到 Context
|
|
92
125
|
if (updaters.updateCssVariables) {
|
|
93
126
|
updaters.updateCssVariables(filteredThemes.reduce((acc, _ref5) => {
|
|
@@ -129,6 +162,11 @@ var setThemes = themes => {
|
|
|
129
162
|
updaters.updateLocalConfig(localConfig);
|
|
130
163
|
}
|
|
131
164
|
}
|
|
165
|
+
// 清除待应用的主题配置(因为已经应用了)
|
|
166
|
+
pendingThemes = null;
|
|
167
|
+
} else {
|
|
168
|
+
// 如果更新函数不可用,保存主题配置,等待 ThemeProvider 初始化后应用
|
|
169
|
+
pendingThemes = _objectSpread({}, themes);
|
|
132
170
|
}
|
|
133
171
|
return true;
|
|
134
172
|
};
|
package/lib/index.d.ts
CHANGED
|
@@ -27,20 +27,21 @@ export { default as ProAction } from './ProAction';
|
|
|
27
27
|
export * from './ProConfigProvider';
|
|
28
28
|
export * from './locale';
|
|
29
29
|
export { default as ProBackBtn } from './ProLayout/components/ProHeader/components/ProBackBtn';
|
|
30
|
+
export type { ProConfigProviderType } from './ProConfigProvider';
|
|
30
31
|
export type { ProFormType, ProColumnProps, ProFormColumnType } from './ProForm/propsType';
|
|
31
32
|
export type { ProFormComponentType } from './ProForm/components';
|
|
32
|
-
export type { ProTableType, ProTableColumnType, ProTableSummaryType, ProTableUseAntdTableType, ProTableProps, ProTableSummaryProps, ProTableColumn, UseAntdTableState } from './ProTable/propsType';
|
|
33
|
+
export type { ProTableType, ProTableColumnType, ProTableSummaryType, ProTableUseAntdTableType, ProTableProps, ProTableSummaryProps, ProTableColumn, UseAntdTableState, } from './ProTable/propsType';
|
|
33
34
|
export type { ProUploadType, ProUploadProps } from './ProUpload/propsType';
|
|
34
35
|
export type { ProTabsType, ProTabsItemType, ProTabsProps, ProTabsItemsProps } from './ProTabs/propType';
|
|
35
|
-
export type { BreadcrumbColumnType, SubDescribeColumnType, DescribeColumnType, ProHeaderType, ProHeaderProps, BreadcrumbColumnsProps, SubDescribeColumnsProps, DescribeColumnsProps } from './ProLayout/components/ProHeader/PropTypes';
|
|
36
|
+
export type { BreadcrumbColumnType, SubDescribeColumnType, DescribeColumnType, ProHeaderType, ProHeaderProps, BreadcrumbColumnsProps, SubDescribeColumnsProps, DescribeColumnsProps, } from './ProLayout/components/ProHeader/PropTypes';
|
|
36
37
|
export type { ProLayoutTabsInstance, AddTabParams, AddTabOptions } from './ProLayout/propTypes';
|
|
37
38
|
export type { ProTooltipType, ProTooltipProps } from './ProTooltip/propsType';
|
|
38
39
|
export type { ProIconType, ProIconProps } from './ProIcon/propsTypes';
|
|
39
40
|
export type { ProTreeType, ProTreeSelectType, ProTreeProps, PropTreeSelectProps } from './ProTree/propsType';
|
|
40
|
-
export type { ProTreeModalType, ProTreeModalActionType, ProTreeModalProps, ProTreeModalAction } from './ProTreeModal/propsType';
|
|
41
|
-
export type { ProEditTableType, ProEditTableColumnType, ProEditTableSummaryColumnType, ProEditTableSummaryConfigType, ProEditTableActionType, ProEditTableProps, ProEditTableColumnsProps, SummaryProps, SummaryColumnProps, BaseActionProps } from './ProEditTable/propsType';
|
|
42
|
-
export type { ProStepType, ProStepContextType, ProStepItemType, ProStepPropsType, ProStepItemPropsType } from './ProStep/propsType';
|
|
41
|
+
export type { ProTreeModalType, ProTreeModalActionType, ProTreeModalProps, ProTreeModalAction, } from './ProTreeModal/propsType';
|
|
42
|
+
export type { ProEditTableType, ProEditTableColumnType, ProEditTableSummaryColumnType, ProEditTableSummaryConfigType, ProEditTableActionType, ProEditTableProps, ProEditTableColumnsProps, SummaryProps, SummaryColumnProps, BaseActionProps, } from './ProEditTable/propsType';
|
|
43
|
+
export type { ProStepType, ProStepContextType, ProStepItemType, ProStepPropsType, ProStepItemPropsType, } from './ProStep/propsType';
|
|
43
44
|
export type { ProDrawerFormType, ProDrawerFormPropsType } from './ProDrawerForm/propsType';
|
|
44
|
-
export type { ProModalSelectType, ProModalSelectConfigType, ProModalSelectPropsType } from './ProForm/components/combination/ProModalSelect/propsType';
|
|
45
|
+
export type { ProModalSelectType, ProModalSelectConfigType, ProModalSelectPropsType, } from './ProForm/components/combination/ProModalSelect/propsType';
|
|
45
46
|
export type { ProStepTabType, ProStepTabResultType } from './ProStepTab/propsType';
|
|
46
47
|
export * from './tokens';
|