@umijs/plugins 4.0.0-beta.12 → 4.0.0-beta.16
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/README.md +4 -1
- package/dist/access.js +73 -1
- package/dist/{dayjs.d.ts → analytics.d.ts} +0 -0
- package/dist/analytics.js +67 -0
- package/dist/antd.js +0 -25
- package/dist/dva.d.ts +3 -9
- package/dist/dva.js +59 -107
- package/dist/initial-state.js +112 -1
- package/dist/layout.js +479 -1
- package/dist/locale.d.ts +1 -0
- package/dist/locale.js +199 -1
- package/dist/model.d.ts +0 -9
- package/dist/model.js +71 -74
- package/dist/moment2dayjs.d.ts +3 -0
- package/dist/moment2dayjs.js +96 -0
- package/dist/qiankun/constants.d.ts +5 -0
- package/dist/qiankun/constants.js +8 -0
- package/dist/qiankun/master.d.ts +6 -0
- package/dist/qiankun/master.js +114 -0
- package/dist/qiankun/slave.d.ts +3 -0
- package/dist/qiankun/slave.js +141 -0
- package/dist/qiankun.js +15 -1
- package/dist/request.js +297 -1
- package/dist/utils/{getIdentifierDeclaration.d.ts → astUtils.d.ts} +0 -0
- package/dist/utils/{getIdentifierDeclaration.js → astUtils.js} +0 -0
- package/dist/utils/localeUtils.d.ts +33 -0
- package/dist/utils/localeUtils.js +135 -0
- package/dist/utils/modelUtils.d.ts +35 -0
- package/dist/utils/modelUtils.js +145 -0
- package/libs/dva.ts +10 -0
- package/libs/locale/SelectLang.tpl +478 -0
- package/libs/locale/locale.tpl +82 -0
- package/libs/locale/localeExports.tpl +271 -0
- package/libs/locale/runtime.tpl +33 -0
- package/libs/model.tsx +140 -0
- package/libs/qiankun/master/AntdErrorBoundary.tsx +34 -0
- package/libs/qiankun/master/AntdLoader.tsx +15 -0
- package/libs/qiankun/master/ErrorBoundary.tsx +7 -0
- package/libs/qiankun/master/MicroApp.tsx +262 -0
- package/libs/qiankun/master/MicroAppWithMemoHistory.tsx +43 -0
- package/libs/qiankun/master/common.ts +133 -0
- package/libs/qiankun/master/constants.ts +7 -0
- package/libs/qiankun/master/getMicroAppRouteComponent.tsx.tpl +45 -0
- package/libs/qiankun/master/masterRuntimePlugin.tsx +130 -0
- package/libs/qiankun/master/types.ts +44 -0
- package/libs/qiankun/slave/connectMaster.tsx +15 -0
- package/libs/qiankun/slave/lifecycles.ts +149 -0
- package/libs/qiankun/slave/qiankunModel.ts +19 -0
- package/libs/qiankun/slave/slaveRuntimePlugin.ts +21 -0
- package/package.json +20 -6
- package/dist/dayjs.js +0 -5
package/dist/layout.js
CHANGED
|
@@ -1,5 +1,483 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
2
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
const allIcons = __importStar(require("@ant-design/icons"));
|
|
26
|
+
const assert_1 = __importDefault(require("assert"));
|
|
27
|
+
const path_1 = require("path");
|
|
28
|
+
const plugin_utils_1 = require("umi/plugin-utils");
|
|
29
|
+
const resolveProjectDep_1 = require("./utils/resolveProjectDep");
|
|
30
|
+
const withTmpPath_1 = require("./utils/withTmpPath");
|
|
3
31
|
exports.default = (api) => {
|
|
4
|
-
api
|
|
32
|
+
api.describe({
|
|
33
|
+
key: 'layout',
|
|
34
|
+
config: {
|
|
35
|
+
schema(joi) {
|
|
36
|
+
return joi.object();
|
|
37
|
+
},
|
|
38
|
+
onChange: api.ConfigChangeType.regenerateTmpFiles,
|
|
39
|
+
},
|
|
40
|
+
enableBy: api.EnableBy.config,
|
|
41
|
+
});
|
|
42
|
+
const pkgPath = (0, resolveProjectDep_1.resolveProjectDep)({
|
|
43
|
+
pkg: api.pkg,
|
|
44
|
+
cwd: api.cwd,
|
|
45
|
+
dep: '@ant-design/pro-layout',
|
|
46
|
+
}) || (0, path_1.dirname)(require.resolve('@ant-design/pro-layout/package.json'));
|
|
47
|
+
api.modifyAppData((memo) => {
|
|
48
|
+
const version = require(`${pkgPath}/package.json`).version;
|
|
49
|
+
memo.pluginLayout = {
|
|
50
|
+
pkgPath,
|
|
51
|
+
version,
|
|
52
|
+
};
|
|
53
|
+
return memo;
|
|
54
|
+
});
|
|
55
|
+
api.modifyConfig((memo) => {
|
|
56
|
+
// import from @ant-design/pro-layout
|
|
57
|
+
memo.alias['@ant-design/pro-layout'] = pkgPath;
|
|
58
|
+
return memo;
|
|
59
|
+
});
|
|
60
|
+
api.onGenerateFiles(() => {
|
|
61
|
+
const hasInitialStatePlugin = api.config.initialState;
|
|
62
|
+
// Layout.tsx
|
|
63
|
+
api.writeTmpFile({
|
|
64
|
+
path: 'Layout.tsx',
|
|
65
|
+
content: `
|
|
66
|
+
import { Link, useLocation, useNavigate, Outlet, useAppData, useRouteContext } from 'umi';
|
|
67
|
+
import ProLayout, {
|
|
68
|
+
PageLoading,
|
|
69
|
+
} from '@ant-design/pro-layout';
|
|
70
|
+
import './Layout.less';
|
|
71
|
+
import Logo from './Logo';
|
|
72
|
+
import { getRightRenderContent } from './rightRender';
|
|
73
|
+
${hasInitialStatePlugin
|
|
74
|
+
? `import { useModel } from '@@/plugin-model';`
|
|
75
|
+
: 'const useModel = null;'}
|
|
76
|
+
|
|
77
|
+
${api.config.locale
|
|
78
|
+
? `
|
|
79
|
+
import { useIntl } from '@@/plugin-locale';
|
|
80
|
+
`.trim()
|
|
81
|
+
: ''}
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
export default () => {
|
|
85
|
+
const location = useLocation();
|
|
86
|
+
const navigate = useNavigate();
|
|
87
|
+
const { clientRoutes, pluginManager } = useAppData();
|
|
88
|
+
const initialInfo = (useModel && useModel('@@initialState')) || {
|
|
89
|
+
initialState: undefined,
|
|
90
|
+
loading: false,
|
|
91
|
+
setInitialState: null,
|
|
92
|
+
};
|
|
93
|
+
const { initialState, loading, setInitialState } = initialInfo;
|
|
94
|
+
const userConfig = ${JSON.stringify(api.config.layout, null, 2)};
|
|
95
|
+
${api.config.locale
|
|
96
|
+
? `
|
|
97
|
+
const { formatMessage } = useIntl();
|
|
98
|
+
`.trim()
|
|
99
|
+
: 'const formatMessage = undefined;'}
|
|
100
|
+
const runtimeConfig = pluginManager.applyPlugins({
|
|
101
|
+
key: 'layout',
|
|
102
|
+
type: 'modify',
|
|
103
|
+
initialValue: {
|
|
104
|
+
...initialInfo
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
const route = clientRoutes.filter(r => {
|
|
108
|
+
return r.id === 'ant-design-pro-layout';
|
|
109
|
+
})[0];
|
|
110
|
+
return (
|
|
111
|
+
<ProLayout
|
|
112
|
+
route={route}
|
|
113
|
+
location={location}
|
|
114
|
+
title={userConfig.name || 'plugin-layout'}
|
|
115
|
+
navTheme="dark"
|
|
116
|
+
siderWidth={256}
|
|
117
|
+
onMenuHeaderClick={(e) => {
|
|
118
|
+
e.stopPropagation();
|
|
119
|
+
e.preventDefault();
|
|
120
|
+
navigate('/');
|
|
121
|
+
}}
|
|
122
|
+
formatMessage={userConfig.formatMessage || formatMessage}
|
|
123
|
+
menu={{ locale: userConfig.locale }}
|
|
124
|
+
logo={Logo}
|
|
125
|
+
menuItemRender={(menuItemProps, defaultDom) => {
|
|
126
|
+
if (menuItemProps.isUrl || menuItemProps.children) {
|
|
127
|
+
return defaultDom;
|
|
128
|
+
}
|
|
129
|
+
if (menuItemProps.path && location.pathname !== menuItemProps.path) {
|
|
130
|
+
return (
|
|
131
|
+
<Link to={menuItemProps.path} target={menuItemProps.target}>
|
|
132
|
+
{defaultDom}
|
|
133
|
+
</Link>
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
return defaultDom;
|
|
137
|
+
}}
|
|
138
|
+
disableContentMargin
|
|
139
|
+
fixSiderbar
|
|
140
|
+
fixedHeader
|
|
141
|
+
{...runtimeConfig}
|
|
142
|
+
rightContentRender={
|
|
143
|
+
runtimeConfig.rightContentRender !== false &&
|
|
144
|
+
((layoutProps) => {
|
|
145
|
+
const dom = getRightRenderContent({
|
|
146
|
+
runtimeConfig,
|
|
147
|
+
loading,
|
|
148
|
+
initialState,
|
|
149
|
+
setInitialState,
|
|
150
|
+
});
|
|
151
|
+
if (runtimeConfig.rightContentRender) {
|
|
152
|
+
return runtimeConfig.rightContentRender(layoutProps, dom, {
|
|
153
|
+
// BREAK CHANGE userConfig > runtimeConfig
|
|
154
|
+
userConfig,
|
|
155
|
+
runtimeConfig,
|
|
156
|
+
loading,
|
|
157
|
+
initialState,
|
|
158
|
+
setInitialState,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
return dom;
|
|
162
|
+
})
|
|
163
|
+
}
|
|
164
|
+
>
|
|
165
|
+
<Outlet />
|
|
166
|
+
</ProLayout>
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
`,
|
|
170
|
+
});
|
|
171
|
+
const iconsMap = Object.keys(api.appData.routes).reduce((memo, id) => {
|
|
172
|
+
const { icon } = api.appData.routes[id];
|
|
173
|
+
if (icon) {
|
|
174
|
+
const upperIcon = plugin_utils_1.lodash.upperFirst(plugin_utils_1.lodash.camelCase(icon));
|
|
175
|
+
(0, assert_1.default)(
|
|
176
|
+
// @ts-ignore
|
|
177
|
+
allIcons[upperIcon] || allIcons[`${upperIcon}Outlined`], `Icon ${upperIcon} is not found`);
|
|
178
|
+
// @ts-ignore
|
|
179
|
+
if (allIcons[upperIcon]) {
|
|
180
|
+
memo[upperIcon] = true;
|
|
181
|
+
}
|
|
182
|
+
// @ts-ignore
|
|
183
|
+
if (allIcons[`${upperIcon}Outlined`]) {
|
|
184
|
+
memo[`${upperIcon}Outlined`] = true;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return memo;
|
|
188
|
+
}, {});
|
|
189
|
+
const icons = Object.keys(iconsMap);
|
|
190
|
+
const antIconsPath = (0, path_1.dirname)(require.resolve('@ant-design/icons/package'));
|
|
191
|
+
api.writeTmpFile({
|
|
192
|
+
path: 'icons.tsx',
|
|
193
|
+
content: `
|
|
194
|
+
${icons
|
|
195
|
+
.map((icon) => {
|
|
196
|
+
return `import ${icon} from '${antIconsPath}/es/icons/${icon}';`;
|
|
197
|
+
})
|
|
198
|
+
.join('\n')}
|
|
199
|
+
export default { ${icons.join(', ')} };
|
|
200
|
+
`,
|
|
201
|
+
});
|
|
202
|
+
// runtime.tsx
|
|
203
|
+
api.writeTmpFile({
|
|
204
|
+
path: 'runtime.tsx',
|
|
205
|
+
content: `
|
|
206
|
+
import React from 'react';
|
|
207
|
+
import icons from './icons';
|
|
208
|
+
|
|
209
|
+
function formatIcon(name: string) {
|
|
210
|
+
return name
|
|
211
|
+
.replace(name[0], name[0].toUpperCase())
|
|
212
|
+
.replace(/-(\w)/g, function(all, letter) {
|
|
213
|
+
return letter.toUpperCase();
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export function patchRoutes({ routes }) {
|
|
218
|
+
Object.keys(routes).forEach(key => {
|
|
219
|
+
const { icon } = routes[key];
|
|
220
|
+
if (icon && typeof icon === 'string') {
|
|
221
|
+
const upperIcon = formatIcon(icon);
|
|
222
|
+
routes[key].icon = React.createElement(icons[upperIcon] || icons[upperIcon + 'Outlined']);
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
`,
|
|
227
|
+
});
|
|
228
|
+
const rightRenderContent = `
|
|
229
|
+
import React from 'react';
|
|
230
|
+
import { Avatar, Dropdown, Menu, Spin } from 'antd';
|
|
231
|
+
import { LogoutOutlined } from '@ant-design/icons';
|
|
232
|
+
{{#Locale}}
|
|
233
|
+
import { SelectLang } from '@@/plugin-locale';
|
|
234
|
+
{{/Locale}}
|
|
235
|
+
|
|
236
|
+
export function getRightRenderContent (opts: {
|
|
237
|
+
runtimeConfig: any,
|
|
238
|
+
loading: boolean,
|
|
239
|
+
initialState: any,
|
|
240
|
+
setInitialState: any,
|
|
241
|
+
}) {
|
|
242
|
+
if (opts.runtimeConfig.rightRender) {
|
|
243
|
+
return opts.runtimeConfig.rightRender(
|
|
244
|
+
opts.initialState,
|
|
245
|
+
opts.setInitialState,
|
|
246
|
+
opts.runtimeConfig,
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const menu = (
|
|
251
|
+
<Menu className="umi-plugin-layout-menu">
|
|
252
|
+
<Menu.Item
|
|
253
|
+
key="logout"
|
|
254
|
+
onClick={() =>
|
|
255
|
+
opts.runtimeConfig.logout && opts.runtimeConfig?.logout(opts.initialState)
|
|
256
|
+
}
|
|
257
|
+
>
|
|
258
|
+
<LogoutOutlined />
|
|
259
|
+
退出登录
|
|
260
|
+
</Menu.Item>
|
|
261
|
+
</Menu>
|
|
262
|
+
);
|
|
263
|
+
|
|
264
|
+
const avatar = (
|
|
265
|
+
<span className="umi-plugin-layout-action">
|
|
266
|
+
<Avatar
|
|
267
|
+
size="small"
|
|
268
|
+
className="umi-plugin-layout-avatar"
|
|
269
|
+
src={
|
|
270
|
+
opts.initialState?.avatar ||
|
|
271
|
+
'https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png'
|
|
272
|
+
}
|
|
273
|
+
alt="avatar"
|
|
274
|
+
/>
|
|
275
|
+
<span className="umi-plugin-layout-name">{opts.initialState?.name}</span>
|
|
276
|
+
</span>
|
|
277
|
+
);
|
|
278
|
+
|
|
279
|
+
if (opts.loading) {
|
|
280
|
+
return (
|
|
281
|
+
<div className="umi-plugin-layout-right">
|
|
282
|
+
<Spin size="small" style={ { marginLeft: 8, marginRight: 8 } } />
|
|
283
|
+
</div>
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
return (
|
|
288
|
+
<div className="umi-plugin-layout-right anticon">
|
|
289
|
+
{opts.runtimeConfig.logout ? (
|
|
290
|
+
<Dropdown overlay={menu} overlayClassName="umi-plugin-layout-container">
|
|
291
|
+
{avatar}
|
|
292
|
+
</Dropdown>
|
|
293
|
+
) : (
|
|
294
|
+
avatar
|
|
295
|
+
)}
|
|
296
|
+
{{#Locale}}
|
|
297
|
+
<SelectLang />
|
|
298
|
+
{{/Locale}}
|
|
299
|
+
</div>
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
`;
|
|
303
|
+
const Locale = api.isPluginEnable('locale');
|
|
304
|
+
// rightRender.tsx
|
|
305
|
+
api.writeTmpFile({
|
|
306
|
+
path: 'rightRender.tsx',
|
|
307
|
+
content: plugin_utils_1.Mustache.render(rightRenderContent, {
|
|
308
|
+
Locale,
|
|
309
|
+
}),
|
|
310
|
+
});
|
|
311
|
+
// Layout.less
|
|
312
|
+
api.writeTmpFile({
|
|
313
|
+
path: 'Layout.less',
|
|
314
|
+
content: `
|
|
315
|
+
@import '~antd/es/style/themes/default.less';
|
|
316
|
+
@pro-header-hover-bg: rgba(0, 0, 0, 0.025);
|
|
317
|
+
@media screen and (max-width: @screen-xs) {
|
|
318
|
+
// 在小屏幕的时候可以有更好的体验
|
|
319
|
+
.umi-plugin-layout-container {
|
|
320
|
+
width: 100% !important;
|
|
321
|
+
}
|
|
322
|
+
.umi-plugin-layout-container > * {
|
|
323
|
+
border-radius: 0 !important;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
.umi-plugin-layout-menu {
|
|
327
|
+
.anticon {
|
|
328
|
+
margin-right: 8px;
|
|
329
|
+
}
|
|
330
|
+
.ant-dropdown-menu-item {
|
|
331
|
+
min-width: 160px;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
.umi-plugin-layout-right {
|
|
335
|
+
display: flex !important;
|
|
336
|
+
float: right;
|
|
337
|
+
height: 100%;
|
|
338
|
+
margin-left: auto;
|
|
339
|
+
overflow: hidden;
|
|
340
|
+
.umi-plugin-layout-action {
|
|
341
|
+
display: flex;
|
|
342
|
+
align-items: center;
|
|
343
|
+
height: 100%;
|
|
344
|
+
padding: 0 12px;
|
|
345
|
+
cursor: pointer;
|
|
346
|
+
transition: all 0.3s;
|
|
347
|
+
> i {
|
|
348
|
+
color: @text-color;
|
|
349
|
+
vertical-align: middle;
|
|
350
|
+
}
|
|
351
|
+
&:hover {
|
|
352
|
+
background: @pro-header-hover-bg;
|
|
353
|
+
}
|
|
354
|
+
&:global(.opened) {
|
|
355
|
+
background: @pro-header-hover-bg;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
.umi-plugin-layout-search {
|
|
359
|
+
padding: 0 12px;
|
|
360
|
+
&:hover {
|
|
361
|
+
background: transparent;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
.umi-plugin-layout-name {
|
|
366
|
+
margin-left: 8px;
|
|
367
|
+
}
|
|
368
|
+
`,
|
|
369
|
+
});
|
|
370
|
+
// Logo.tsx
|
|
371
|
+
api.writeTmpFile({
|
|
372
|
+
path: 'Logo.tsx',
|
|
373
|
+
content: `
|
|
374
|
+
import React from 'react';
|
|
375
|
+
|
|
376
|
+
const LogoIcon: React.FC = () => {
|
|
377
|
+
return (
|
|
378
|
+
<svg
|
|
379
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
380
|
+
width="32"
|
|
381
|
+
height="32"
|
|
382
|
+
viewBox="0 0 200 200"
|
|
383
|
+
>
|
|
384
|
+
<defs>
|
|
385
|
+
<linearGradient
|
|
386
|
+
id="linearGradient-1"
|
|
387
|
+
x1="62.102%"
|
|
388
|
+
x2="108.197%"
|
|
389
|
+
y1="0%"
|
|
390
|
+
y2="37.864%"
|
|
391
|
+
>
|
|
392
|
+
<stop offset="0%" stopColor="#4285EB"></stop>
|
|
393
|
+
<stop offset="100%" stopColor="#2EC7FF"></stop>
|
|
394
|
+
</linearGradient>
|
|
395
|
+
<linearGradient
|
|
396
|
+
id="linearGradient-2"
|
|
397
|
+
x1="69.644%"
|
|
398
|
+
x2="54.043%"
|
|
399
|
+
y1="0%"
|
|
400
|
+
y2="108.457%"
|
|
401
|
+
>
|
|
402
|
+
<stop offset="0%" stopColor="#29CDFF"></stop>
|
|
403
|
+
<stop offset="37.86%" stopColor="#148EFF"></stop>
|
|
404
|
+
<stop offset="100%" stopColor="#0A60FF"></stop>
|
|
405
|
+
</linearGradient>
|
|
406
|
+
<linearGradient
|
|
407
|
+
id="linearGradient-3"
|
|
408
|
+
x1="69.691%"
|
|
409
|
+
x2="16.723%"
|
|
410
|
+
y1="-12.974%"
|
|
411
|
+
y2="117.391%"
|
|
412
|
+
>
|
|
413
|
+
<stop offset="0%" stopColor="#FA816E"></stop>
|
|
414
|
+
<stop offset="41.473%" stopColor="#F74A5C"></stop>
|
|
415
|
+
<stop offset="100%" stopColor="#F51D2C"></stop>
|
|
416
|
+
</linearGradient>
|
|
417
|
+
<linearGradient
|
|
418
|
+
id="linearGradient-4"
|
|
419
|
+
x1="68.128%"
|
|
420
|
+
x2="30.44%"
|
|
421
|
+
y1="-35.691%"
|
|
422
|
+
y2="114.943%"
|
|
423
|
+
>
|
|
424
|
+
<stop offset="0%" stopColor="#FA8E7D"></stop>
|
|
425
|
+
<stop offset="51.264%" stopColor="#F74A5C"></stop>
|
|
426
|
+
<stop offset="100%" stopColor="#F51D2C"></stop>
|
|
427
|
+
</linearGradient>
|
|
428
|
+
</defs>
|
|
429
|
+
<g fill="none" fillRule="evenodd" stroke="none" strokeWidth="1">
|
|
430
|
+
<g transform="translate(-20 -20)">
|
|
431
|
+
<g transform="translate(20 20)">
|
|
432
|
+
<g>
|
|
433
|
+
<g fillRule="nonzero">
|
|
434
|
+
<g>
|
|
435
|
+
<path
|
|
436
|
+
fill="url(#linearGradient-1)"
|
|
437
|
+
d="M91.588 4.177L4.18 91.513a11.981 11.981 0 000 16.974l87.408 87.336a12.005 12.005 0 0016.989 0l36.648-36.618c4.209-4.205 4.209-11.023 0-15.228-4.208-4.205-11.031-4.205-15.24 0l-27.783 27.76c-1.17 1.169-2.945 1.169-4.114 0l-69.802-69.744c-1.17-1.169-1.17-2.942 0-4.11l69.802-69.745c1.17-1.169 2.944-1.169 4.114 0l27.783 27.76c4.209 4.205 11.032 4.205 15.24 0 4.209-4.205 4.209-11.022 0-15.227L108.581 4.056c-4.719-4.594-12.312-4.557-16.993.12z"
|
|
438
|
+
></path>
|
|
439
|
+
<path
|
|
440
|
+
fill="url(#linearGradient-2)"
|
|
441
|
+
d="M91.588 4.177L4.18 91.513a11.981 11.981 0 000 16.974l87.408 87.336a12.005 12.005 0 0016.989 0l36.648-36.618c4.209-4.205 4.209-11.023 0-15.228-4.208-4.205-11.031-4.205-15.24 0l-27.783 27.76c-1.17 1.169-2.945 1.169-4.114 0l-69.802-69.744c-1.17-1.169-1.17-2.942 0-4.11l69.802-69.745c2.912-2.51 7.664-7.596 14.642-8.786 5.186-.883 10.855 1.062 17.009 5.837L108.58 4.056c-4.719-4.594-12.312-4.557-16.993.12z"
|
|
442
|
+
></path>
|
|
443
|
+
</g>
|
|
444
|
+
<path
|
|
445
|
+
fill="url(#linearGradient-3)"
|
|
446
|
+
d="M153.686 135.855c4.208 4.205 11.031 4.205 15.24 0l27.034-27.012c4.7-4.696 4.7-12.28 0-16.974l-27.27-27.15c-4.218-4.2-11.043-4.195-15.254.013-4.209 4.205-4.209 11.022 0 15.227l18.418 18.403c1.17 1.169 1.17 2.943 0 4.111l-18.168 18.154c-4.209 4.205-4.209 11.023 0 15.228z"
|
|
447
|
+
></path>
|
|
448
|
+
</g>
|
|
449
|
+
<ellipse
|
|
450
|
+
cx="100.519"
|
|
451
|
+
cy="100.437"
|
|
452
|
+
fill="url(#linearGradient-4)"
|
|
453
|
+
rx="23.6"
|
|
454
|
+
ry="23.581"
|
|
455
|
+
></ellipse>
|
|
456
|
+
</g>
|
|
457
|
+
</g>
|
|
458
|
+
</g>
|
|
459
|
+
</g>
|
|
460
|
+
</svg>
|
|
461
|
+
);
|
|
462
|
+
};
|
|
463
|
+
|
|
464
|
+
export default LogoIcon;
|
|
465
|
+
`,
|
|
466
|
+
});
|
|
467
|
+
});
|
|
468
|
+
api.addLayouts(() => {
|
|
469
|
+
return [
|
|
470
|
+
{
|
|
471
|
+
id: 'ant-design-pro-layout',
|
|
472
|
+
file: (0, withTmpPath_1.withTmpPath)({ api, path: 'Layout.tsx' }),
|
|
473
|
+
test: (route) => {
|
|
474
|
+
return route.layout !== false;
|
|
475
|
+
},
|
|
476
|
+
},
|
|
477
|
+
];
|
|
478
|
+
});
|
|
479
|
+
api.addRuntimePluginKey(() => ['layout']);
|
|
480
|
+
api.addRuntimePlugin(() => {
|
|
481
|
+
return [(0, withTmpPath_1.withTmpPath)({ api, path: 'runtime.tsx' })];
|
|
482
|
+
});
|
|
5
483
|
};
|
package/dist/locale.d.ts
CHANGED
package/dist/locale.js
CHANGED
|
@@ -1,5 +1,203 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.packageNormalize = void 0;
|
|
13
|
+
const utils_1 = require("@umijs/utils");
|
|
14
|
+
const fs_1 = require("fs");
|
|
15
|
+
const path_1 = require("path");
|
|
16
|
+
const localeUtils_1 = require("./utils/localeUtils");
|
|
17
|
+
const withTmpPath_1 = require("./utils/withTmpPath");
|
|
18
|
+
const packageNormalize = (packageName) => packageName.replace(/[@\/\-.]/g, '_');
|
|
19
|
+
exports.packageNormalize = packageNormalize;
|
|
20
|
+
// TODO: runtime plugin
|
|
3
21
|
exports.default = (api) => {
|
|
4
|
-
|
|
22
|
+
var _a;
|
|
23
|
+
// TODO: antd 的校验考虑 antd 插件
|
|
24
|
+
let hasAntd = false;
|
|
25
|
+
try {
|
|
26
|
+
hasAntd = !!require.resolve('antd');
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
api.logger.warn('antd is not installed. <SelecLang /> unavailable');
|
|
30
|
+
}
|
|
31
|
+
api.describe({
|
|
32
|
+
key: 'locale',
|
|
33
|
+
config: {
|
|
34
|
+
default: {
|
|
35
|
+
baseNavigator: true,
|
|
36
|
+
useLocalStorage: true,
|
|
37
|
+
baseSeparator: '-',
|
|
38
|
+
antd: hasAntd,
|
|
39
|
+
},
|
|
40
|
+
schema(joi) {
|
|
41
|
+
return joi.object({
|
|
42
|
+
default: joi.string(),
|
|
43
|
+
useLocalStorage: joi.boolean(),
|
|
44
|
+
baseNavigator: joi.boolean(),
|
|
45
|
+
title: joi.boolean(),
|
|
46
|
+
antd: joi.boolean(),
|
|
47
|
+
baseSeparator: joi.string(),
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
enableBy: api.EnableBy.config,
|
|
52
|
+
});
|
|
53
|
+
const reactIntlPkgPath = (0, path_1.dirname)(require.resolve('react-intl/package'));
|
|
54
|
+
// polyfill
|
|
55
|
+
if ((0, localeUtils_1.isNeedPolyfill)(((_a = api.userConfig) === null || _a === void 0 ? void 0 : _a.targets) || {})) {
|
|
56
|
+
api.addEntryImportsAhead(() => [
|
|
57
|
+
{
|
|
58
|
+
source: require.resolve('intl'),
|
|
59
|
+
},
|
|
60
|
+
]);
|
|
61
|
+
}
|
|
62
|
+
const addAntdLocales = (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
63
|
+
var _b;
|
|
64
|
+
return yield api.applyPlugins({
|
|
65
|
+
key: 'addAntdLocales',
|
|
66
|
+
type: api.ApplyPluginsType.add,
|
|
67
|
+
initialValue: [
|
|
68
|
+
`antd/${((_b = api.config) === null || _b === void 0 ? void 0 : _b.ssr) ? 'lib' : 'es'}/locale/${(0, localeUtils_1.getAntdLocale)(args.lang, args.country)}`,
|
|
69
|
+
],
|
|
70
|
+
args,
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
const getList = (resolveKey) => __awaiter(void 0, void 0, void 0, function* () {
|
|
74
|
+
var _c, _d;
|
|
75
|
+
const { paths } = api;
|
|
76
|
+
return (0, localeUtils_1.getLocaleList)({
|
|
77
|
+
localeFolder: ((_c = api.config) === null || _c === void 0 ? void 0 : _c.singular) ? 'locale' : 'locales',
|
|
78
|
+
separator: (_d = api.config.locale) === null || _d === void 0 ? void 0 : _d.baseSeparator,
|
|
79
|
+
absSrcPath: paths.absSrcPath,
|
|
80
|
+
absPagesPath: paths.absPagesPath,
|
|
81
|
+
addAntdLocales,
|
|
82
|
+
resolveKey,
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
api.onGenerateFiles(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
86
|
+
var _e, _f, _g, _h;
|
|
87
|
+
const localeTpl = (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../libs/locale/locale.tpl'), 'utf-8');
|
|
88
|
+
// moment2dayjs
|
|
89
|
+
const resolveKey = api.config.moment2dayjs ? 'dayjs' : 'moment';
|
|
90
|
+
const momentPkgPath = (0, path_1.dirname)(require.resolve(`${resolveKey}/package.json`));
|
|
91
|
+
const EventEmitterPkg = (0, path_1.dirname)(require.resolve('event-emitter/package'));
|
|
92
|
+
const { baseSeparator, baseNavigator, antd, title, useLocalStorage } = api
|
|
93
|
+
.config.locale;
|
|
94
|
+
const defaultLocale = ((_e = api.config.locale) === null || _e === void 0 ? void 0 : _e.default) || `zh${baseSeparator}CN`;
|
|
95
|
+
const localeList = yield getList(resolveKey);
|
|
96
|
+
const momentLocales = localeList
|
|
97
|
+
.map(({ momentLocale }) => momentLocale)
|
|
98
|
+
.filter((locale) => locale);
|
|
99
|
+
const antdLocales = localeList
|
|
100
|
+
.map(({ antdLocale }) => antdLocale)
|
|
101
|
+
.filter((locale) => locale);
|
|
102
|
+
let MomentLocales = momentLocales;
|
|
103
|
+
let DefaultMomentLocale = '';
|
|
104
|
+
// set moment default accounding to locale.default
|
|
105
|
+
if (!MomentLocales.length && ((_f = api.config.locale) === null || _f === void 0 ? void 0 : _f.default)) {
|
|
106
|
+
const [lang, country = ''] = defaultLocale.split(baseSeparator);
|
|
107
|
+
const { momentLocale } = (0, localeUtils_1.getMomentLocale)(lang, country, resolveKey);
|
|
108
|
+
if (momentLocale) {
|
|
109
|
+
MomentLocales = [momentLocale];
|
|
110
|
+
DefaultMomentLocale = momentLocale;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
let DefaultAntdLocales = [];
|
|
114
|
+
// set antd default locale
|
|
115
|
+
if (!antdLocales.length && ((_g = api.config.locale) === null || _g === void 0 ? void 0 : _g.antd)) {
|
|
116
|
+
const [lang, country = ''] = defaultLocale.split(baseSeparator);
|
|
117
|
+
DefaultAntdLocales = utils_1.lodash.uniq(yield addAntdLocales({
|
|
118
|
+
lang,
|
|
119
|
+
country,
|
|
120
|
+
}));
|
|
121
|
+
}
|
|
122
|
+
const NormalizeAntdLocalesName = function () {
|
|
123
|
+
// @ts-ignore
|
|
124
|
+
return (0, exports.packageNormalize)(this);
|
|
125
|
+
};
|
|
126
|
+
api.writeTmpFile({
|
|
127
|
+
content: utils_1.Mustache.render(localeTpl, {
|
|
128
|
+
MomentLocales,
|
|
129
|
+
DefaultMomentLocale,
|
|
130
|
+
NormalizeAntdLocalesName,
|
|
131
|
+
DefaultAntdLocales,
|
|
132
|
+
Antd: !!antd,
|
|
133
|
+
Title: title && api.config.title,
|
|
134
|
+
BaseSeparator: baseSeparator,
|
|
135
|
+
DefaultLocale: defaultLocale,
|
|
136
|
+
DefaultLang: defaultLocale,
|
|
137
|
+
momentPkgPath,
|
|
138
|
+
}),
|
|
139
|
+
path: 'locale.tsx',
|
|
140
|
+
});
|
|
141
|
+
const localeExportsTpl = (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../libs/locale/localeExports.tpl'), 'utf-8');
|
|
142
|
+
const localeDirName = api.config.singular ? 'locale' : 'locales';
|
|
143
|
+
const localeDirPath = (0, path_1.join)(api.paths.absSrcPath, localeDirName);
|
|
144
|
+
api.writeTmpFile({
|
|
145
|
+
path: 'localeExports.ts',
|
|
146
|
+
content: utils_1.Mustache.render(localeExportsTpl, {
|
|
147
|
+
EventEmitterPkg,
|
|
148
|
+
BaseSeparator: baseSeparator,
|
|
149
|
+
BaseNavigator: baseNavigator,
|
|
150
|
+
UseLocalStorage: !!useLocalStorage,
|
|
151
|
+
LocaleDir: localeDirName,
|
|
152
|
+
ExistLocaleDir: (0, fs_1.existsSync)(localeDirPath),
|
|
153
|
+
LocaleList: localeList.map((locale) => (Object.assign(Object.assign({}, locale), { antdLocale: locale.antdLocale.map((antdLocale, index) => ({
|
|
154
|
+
locale: antdLocale,
|
|
155
|
+
index: index,
|
|
156
|
+
})), paths: locale.paths.map((path, index) => ({
|
|
157
|
+
path,
|
|
158
|
+
index,
|
|
159
|
+
})) }))),
|
|
160
|
+
Antd: !!antd,
|
|
161
|
+
DefaultLocale: JSON.stringify(defaultLocale),
|
|
162
|
+
warningPkgPath: require.resolve('warning/package'),
|
|
163
|
+
reactIntlPkgPath,
|
|
164
|
+
}),
|
|
165
|
+
});
|
|
166
|
+
// runtime.tsx
|
|
167
|
+
const runtimeTpl = (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../libs/locale/runtime.tpl'), 'utf-8');
|
|
168
|
+
api.writeTmpFile({
|
|
169
|
+
path: 'runtime.tsx',
|
|
170
|
+
content: utils_1.Mustache.render(runtimeTpl, {
|
|
171
|
+
Title: !!title,
|
|
172
|
+
}),
|
|
173
|
+
});
|
|
174
|
+
// SelectLang.tsx
|
|
175
|
+
const selectLang = (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../libs/locale/SelectLang.tpl'), 'utf-8');
|
|
176
|
+
api.writeTmpFile({
|
|
177
|
+
path: 'SelectLang.tsx',
|
|
178
|
+
content: utils_1.Mustache.render(selectLang, {
|
|
179
|
+
Antd: !!antd,
|
|
180
|
+
LocaleList: localeList,
|
|
181
|
+
ShowSelectLang: localeList.length > 1 && !!antd,
|
|
182
|
+
antdFiles: ((_h = api.config) === null || _h === void 0 ? void 0 : _h.ssr) ? 'lib' : 'es',
|
|
183
|
+
}),
|
|
184
|
+
});
|
|
185
|
+
// index.ts
|
|
186
|
+
api.writeTmpFile({
|
|
187
|
+
path: 'index.ts',
|
|
188
|
+
content: `
|
|
189
|
+
export { useIntl, formatMessage, FormattedMessage } from './localeExports.ts';
|
|
190
|
+
export { SelectLang } from './SelectLang.tsx';
|
|
191
|
+
`,
|
|
192
|
+
});
|
|
193
|
+
}));
|
|
194
|
+
// Runtime Plugin
|
|
195
|
+
api.addRuntimePlugin(() => [(0, withTmpPath_1.withTmpPath)({ api, path: 'runtime.tsx' })]);
|
|
196
|
+
api.addRuntimePluginKey(() => ['locale']);
|
|
197
|
+
// watch locale files
|
|
198
|
+
api.addTmpGenerateWatcherPaths(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
199
|
+
const resolveKey = api.config.moment2dayjs ? 'dayjs' : 'moment';
|
|
200
|
+
const localeList = yield getList(resolveKey);
|
|
201
|
+
return (0, localeUtils_1.exactLocalePaths)(localeList);
|
|
202
|
+
}));
|
|
5
203
|
};
|