@umijs/plugins 4.0.88 → 4.0.89
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/antd.js +45 -3
- package/dist/styled-components.js +18 -1
- package/package.json +4 -4
- package/templates/antd/runtime.ts.tpl +66 -37
package/dist/antd.js
CHANGED
|
@@ -158,6 +158,9 @@ var antd_default = (api) => {
|
|
|
158
158
|
);
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
|
+
if (antd.dark || antd.compact) {
|
|
162
|
+
antd.configProvider ?? (antd.configProvider = {});
|
|
163
|
+
}
|
|
161
164
|
return memo;
|
|
162
165
|
});
|
|
163
166
|
api.chainWebpack((memo) => {
|
|
@@ -189,6 +192,10 @@ var antd_default = (api) => {
|
|
|
189
192
|
}
|
|
190
193
|
return [];
|
|
191
194
|
});
|
|
195
|
+
const lodashPkg = (0, import_path.dirname)(require.resolve("lodash/package.json"));
|
|
196
|
+
const lodashPath = {
|
|
197
|
+
merge: (0, import_plugin_utils.winPath)((0, import_path.join)(lodashPkg, "merge"))
|
|
198
|
+
};
|
|
192
199
|
api.onGenerateFiles(() => {
|
|
193
200
|
var _a;
|
|
194
201
|
const withConfigProvider = !!api.config.antd.configProvider;
|
|
@@ -218,14 +225,21 @@ var antd_default = (api) => {
|
|
|
218
225
|
};
|
|
219
226
|
}
|
|
220
227
|
}
|
|
228
|
+
const configProvider = withConfigProvider && JSON.stringify(api.config.antd.configProvider);
|
|
229
|
+
const appConfig = appComponentAvailable && JSON.stringify(api.config.antd.appConfig);
|
|
230
|
+
const enableV5ThemeAlgorithm = isV5 && (userInputCompact || userInputDark) ? { compact: userInputCompact, dark: userInputDark } : false;
|
|
231
|
+
const hasConfigProvider = configProvider || enableV5ThemeAlgorithm;
|
|
232
|
+
const antdConfigSetter = isV5 && hasConfigProvider;
|
|
221
233
|
api.writeTmpFile({
|
|
222
234
|
path: `runtime.tsx`,
|
|
223
235
|
context: {
|
|
224
|
-
configProvider
|
|
225
|
-
appConfig
|
|
236
|
+
configProvider,
|
|
237
|
+
appConfig,
|
|
226
238
|
styleProvider: styleProviderConfig,
|
|
227
239
|
// 是否启用了 v5 的 theme algorithm
|
|
228
|
-
enableV5ThemeAlgorithm
|
|
240
|
+
enableV5ThemeAlgorithm,
|
|
241
|
+
antdConfigSetter,
|
|
242
|
+
lodashPath,
|
|
229
243
|
/**
|
|
230
244
|
* 是否重构了全局静态配置。 重构后需要在运行时将全局静态配置传入到 ConfigProvider 中。
|
|
231
245
|
* 实际上 4.13.0 重构后有一个 bug,真正的 warn 出现在 4.13.1,并且 4.13.1 修复了这个 bug。
|
|
@@ -253,6 +267,34 @@ export type IRuntimeConfig = {
|
|
|
253
267
|
};
|
|
254
268
|
`
|
|
255
269
|
});
|
|
270
|
+
if (antdConfigSetter) {
|
|
271
|
+
api.writeTmpFile({
|
|
272
|
+
path: "index.tsx",
|
|
273
|
+
content: `import React from 'react';
|
|
274
|
+
import { AntdConfigContext, AntdConfigContextSetter } from './context';
|
|
275
|
+
|
|
276
|
+
export function useAntdConfig() {
|
|
277
|
+
return React.useContext(AntdConfigContext);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export function useAntdConfigSetter() {
|
|
281
|
+
return React.useContext(AntdConfigContextSetter);
|
|
282
|
+
}`
|
|
283
|
+
});
|
|
284
|
+
api.writeTmpFile({
|
|
285
|
+
path: "context.tsx",
|
|
286
|
+
content: `import React from 'react';
|
|
287
|
+
import type { ConfigProviderProps } from 'antd/es/config-provider';
|
|
288
|
+
|
|
289
|
+
export const AntdConfigContext = React.createContext<ConfigProviderProps>(null!);
|
|
290
|
+
export const AntdConfigContextSetter = React.createContext<React.Dispatch<React.SetStateAction<ConfigProviderProps>>>(
|
|
291
|
+
() => {
|
|
292
|
+
console.error(\`The 'useAntdConfigSetter()' method depends on the antd 'ConfigProvider', requires one of 'antd.configProvider' / 'antd.dark' / 'antd.compact' to be enabled.\`);
|
|
293
|
+
}
|
|
294
|
+
);
|
|
295
|
+
`
|
|
296
|
+
});
|
|
297
|
+
}
|
|
256
298
|
});
|
|
257
299
|
api.addRuntimePlugin(() => {
|
|
258
300
|
if (api.config.antd.styleProvider || api.config.antd.configProvider || appComponentAvailable && api.config.antd.appConfig) {
|
|
@@ -34,6 +34,7 @@ __export(styled_components_exports, {
|
|
|
34
34
|
module.exports = __toCommonJS(styled_components_exports);
|
|
35
35
|
var import_utils = require("@umijs/utils");
|
|
36
36
|
var import_path = require("path");
|
|
37
|
+
var import_resolveProjectDep = require("./utils/resolveProjectDep");
|
|
37
38
|
var import_withTmpPath = require("./utils/withTmpPath");
|
|
38
39
|
var styled_components_default = (api) => {
|
|
39
40
|
api.describe({
|
|
@@ -49,6 +50,9 @@ var styled_components_default = (api) => {
|
|
|
49
50
|
});
|
|
50
51
|
api.modifyConfig((memo) => {
|
|
51
52
|
var _a, _b;
|
|
53
|
+
if (api.userConfig.mako || process.env.OKAM) {
|
|
54
|
+
return memo;
|
|
55
|
+
}
|
|
52
56
|
const isProd = api.env === "production";
|
|
53
57
|
const pluginConfig = {
|
|
54
58
|
// https://github.com/styled-components/babel-plugin-styled-components/blob/f8e9fb480d1645be8be797d73e49686bdf98975b/src/utils/options.js#L11
|
|
@@ -77,7 +81,20 @@ var styled_components_default = (api) => {
|
|
|
77
81
|
api.addRuntimePluginKey(() => {
|
|
78
82
|
return ["styledComponents"];
|
|
79
83
|
});
|
|
80
|
-
const
|
|
84
|
+
const SC_NAME = `styled-components`;
|
|
85
|
+
let libPath;
|
|
86
|
+
try {
|
|
87
|
+
libPath = (0, import_resolveProjectDep.resolveProjectDep)({
|
|
88
|
+
pkg: api.pkg,
|
|
89
|
+
cwd: api.cwd,
|
|
90
|
+
dep: SC_NAME
|
|
91
|
+
}) || (0, import_path.dirname)(require.resolve(`${SC_NAME}/package.json`));
|
|
92
|
+
} catch (e) {
|
|
93
|
+
}
|
|
94
|
+
api.modifyConfig((memo) => {
|
|
95
|
+
memo.alias[SC_NAME] = libPath;
|
|
96
|
+
return memo;
|
|
97
|
+
});
|
|
81
98
|
api.onGenerateFiles(() => {
|
|
82
99
|
var _a, _b, _c;
|
|
83
100
|
api.writeTmpFile({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/plugins",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.89",
|
|
4
4
|
"description": "@umijs/plugins",
|
|
5
5
|
"homepage": "https://github.com/umijs/umi/tree/master/packages/plugins#readme",
|
|
6
6
|
"bugs": "https://github.com/umijs/umi/issues",
|
|
@@ -42,15 +42,15 @@
|
|
|
42
42
|
"react-intl": "3.12.1",
|
|
43
43
|
"react-redux": "^8.0.5",
|
|
44
44
|
"redux": "^4.2.1",
|
|
45
|
-
"styled-components": "6.1.
|
|
45
|
+
"styled-components": "6.1.1",
|
|
46
46
|
"tslib": "^2",
|
|
47
47
|
"warning": "^4.0.3",
|
|
48
|
-
"@umijs/bundler-utils": "4.0.
|
|
48
|
+
"@umijs/bundler-utils": "4.0.89",
|
|
49
49
|
"@umijs/valtio": "1.0.4"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"antd": "^4.24.1",
|
|
53
|
-
"umi": "4.0.
|
|
53
|
+
"umi": "4.0.89"
|
|
54
54
|
},
|
|
55
55
|
"publishConfig": {
|
|
56
56
|
"access": "public"
|
|
@@ -23,6 +23,10 @@ import {
|
|
|
23
23
|
} from '{{{styleProvider.cssinjs}}}';
|
|
24
24
|
{{/styleProvider}}
|
|
25
25
|
import { getPluginManager } from '../core/plugin';
|
|
26
|
+
{{#antdConfigSetter}}
|
|
27
|
+
import { AntdConfigContext, AntdConfigContextSetter } from './context';
|
|
28
|
+
import merge from '{{{lodashPath.merge}}}'
|
|
29
|
+
{{/antdConfigSetter}}
|
|
26
30
|
|
|
27
31
|
let cacheAntdConfig = null;
|
|
28
32
|
|
|
@@ -44,73 +48,80 @@ const getAntdConfig = () => {
|
|
|
44
48
|
return cacheAntdConfig;
|
|
45
49
|
}
|
|
46
50
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
function AntdProvider({ children }) {
|
|
52
|
+
let container = children;
|
|
53
|
+
|
|
54
|
+
const [antdConfig, _setAntdConfig] = React.useState(() => {
|
|
55
|
+
const {
|
|
56
|
+
appConfig: _,
|
|
57
|
+
...finalConfigProvider
|
|
58
|
+
} = getAntdConfig();
|
|
59
|
+
{{#enableV5ThemeAlgorithm}}
|
|
60
|
+
finalConfigProvider.theme ??= {};
|
|
61
|
+
finalConfigProvider.theme.algorithm ??= [];
|
|
62
|
+
if (!Array.isArray(finalConfigProvider.theme.algorithm)) {
|
|
63
|
+
finalConfigProvider.theme.algorithm = [finalConfigProvider.theme.algorithm];
|
|
64
|
+
}
|
|
65
|
+
const algorithm = finalConfigProvider.theme.algorithm;
|
|
66
|
+
{{#enableV5ThemeAlgorithm.compact}}
|
|
67
|
+
if (!algorithm.includes(theme.compactAlgorithm)) {
|
|
68
|
+
algorithm.push(theme.compactAlgorithm);
|
|
69
|
+
}
|
|
70
|
+
{{/enableV5ThemeAlgorithm.compact}}
|
|
71
|
+
{{#enableV5ThemeAlgorithm.dark}}
|
|
72
|
+
if (!algorithm.includes(theme.darkAlgorithm)) {
|
|
73
|
+
algorithm.push(theme.darkAlgorithm);
|
|
74
|
+
}
|
|
75
|
+
{{/enableV5ThemeAlgorithm.dark}}
|
|
76
|
+
{{/enableV5ThemeAlgorithm}}
|
|
77
|
+
return finalConfigProvider
|
|
78
|
+
});
|
|
79
|
+
const setAntdConfig: typeof _setAntdConfig = (newConfig) => {
|
|
80
|
+
_setAntdConfig(prev => {
|
|
81
|
+
return merge({}, prev, typeof newConfig === 'function' ? newConfig(prev) : newConfig)
|
|
82
|
+
})
|
|
83
|
+
}
|
|
53
84
|
|
|
54
85
|
{{#configProvider}}
|
|
55
86
|
{{^disableInternalStatic}}
|
|
56
|
-
if (
|
|
87
|
+
if (antdConfig.prefixCls) {
|
|
57
88
|
Modal.config({
|
|
58
|
-
rootPrefixCls:
|
|
89
|
+
rootPrefixCls: antdConfig.prefixCls
|
|
59
90
|
});
|
|
60
91
|
message.config({
|
|
61
|
-
prefixCls: `${
|
|
92
|
+
prefixCls: `${antdConfig.prefixCls}-message`
|
|
62
93
|
});
|
|
63
94
|
notification.config({
|
|
64
|
-
prefixCls: `${
|
|
95
|
+
prefixCls: `${antdConfig.prefixCls}-notification`
|
|
65
96
|
});
|
|
66
97
|
}
|
|
67
98
|
{{/disableInternalStatic}}
|
|
68
99
|
|
|
69
100
|
{{#disableInternalStatic}}
|
|
70
|
-
if (
|
|
101
|
+
if (antdConfig.prefixCls) {
|
|
71
102
|
ConfigProvider.config({
|
|
72
|
-
prefixCls:
|
|
103
|
+
prefixCls: antdConfig.prefixCls,
|
|
73
104
|
});
|
|
74
105
|
};
|
|
75
106
|
{{/disableInternalStatic}}
|
|
76
107
|
|
|
77
|
-
if (
|
|
108
|
+
if (antdConfig.iconPrefixCls) {
|
|
78
109
|
// Icons in message need to set iconPrefixCls via ConfigProvider.config()
|
|
79
110
|
ConfigProvider.config({
|
|
80
|
-
iconPrefixCls:
|
|
111
|
+
iconPrefixCls: antdConfig.iconPrefixCls,
|
|
81
112
|
});
|
|
82
113
|
};
|
|
83
114
|
|
|
84
|
-
if (
|
|
115
|
+
if (antdConfig.theme) {
|
|
85
116
|
// Pass config theme to static method
|
|
86
117
|
ConfigProvider.config({
|
|
87
|
-
theme:
|
|
118
|
+
theme: antdConfig.theme,
|
|
88
119
|
});
|
|
89
120
|
}
|
|
90
121
|
|
|
91
|
-
container = <ConfigProvider {...
|
|
122
|
+
container = <ConfigProvider {...antdConfig}>{container}</ConfigProvider>;
|
|
92
123
|
{{/configProvider}}
|
|
93
124
|
|
|
94
|
-
{{#enableV5ThemeAlgorithm}}
|
|
95
|
-
// Add token algorithm for antd5 only
|
|
96
|
-
container = (
|
|
97
|
-
<ConfigProvider
|
|
98
|
-
theme={({
|
|
99
|
-
algorithm: [
|
|
100
|
-
{{#enableV5ThemeAlgorithm.compact}}
|
|
101
|
-
theme.compactAlgorithm,
|
|
102
|
-
{{/enableV5ThemeAlgorithm.compact}}
|
|
103
|
-
{{#enableV5ThemeAlgorithm.dark}}
|
|
104
|
-
theme.darkAlgorithm,
|
|
105
|
-
{{/enableV5ThemeAlgorithm.dark}}
|
|
106
|
-
],
|
|
107
|
-
})}
|
|
108
|
-
>
|
|
109
|
-
{container}
|
|
110
|
-
</ConfigProvider>
|
|
111
|
-
);
|
|
112
|
-
{{/enableV5ThemeAlgorithm}}
|
|
113
|
-
|
|
114
125
|
{{#styleProvider}}
|
|
115
126
|
container = (
|
|
116
127
|
<StyleProvider
|
|
@@ -126,9 +137,27 @@ export function rootContainer(rawContainer) {
|
|
|
126
137
|
);
|
|
127
138
|
{{/styleProvider}}
|
|
128
139
|
|
|
140
|
+
{{#antdConfigSetter}}
|
|
141
|
+
container = (
|
|
142
|
+
<AntdConfigContextSetter.Provider value={setAntdConfig}>
|
|
143
|
+
<AntdConfigContext.Provider value={antdConfig}>
|
|
144
|
+
{container}
|
|
145
|
+
</AntdConfigContext.Provider>
|
|
146
|
+
</AntdConfigContextSetter.Provider>
|
|
147
|
+
)
|
|
148
|
+
{{/antdConfigSetter}}
|
|
149
|
+
|
|
129
150
|
return container;
|
|
130
151
|
}
|
|
131
152
|
|
|
153
|
+
export function rootContainer(children) {
|
|
154
|
+
return (
|
|
155
|
+
<AntdProvider>
|
|
156
|
+
{children}
|
|
157
|
+
</AntdProvider>
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
|
|
132
161
|
{{#appConfig}}
|
|
133
162
|
// The App component should be under ConfigProvider
|
|
134
163
|
// plugin-locale has other ConfigProvider
|