@umijs/plugins 4.0.32 → 4.0.33

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/layout.js CHANGED
@@ -373,7 +373,7 @@ export function patchRoutes({ routes }) {
373
373
  });
374
374
  const rightRenderContent = `
375
375
  import React from 'react';
376
- import { Avatar, Dropdown, Menu, Spin } from 'antd';
376
+ import { Avatar, version, Dropdown, Menu, Spin } from 'antd';
377
377
  import { LogoutOutlined } from '@ant-design/icons';
378
378
  {{#Locale}}
379
379
  import { SelectLang } from '@@/plugin-locale';
@@ -393,19 +393,7 @@ export function getRightRenderContent (opts: {
393
393
  );
394
394
  }
395
395
 
396
- const menu = (
397
- <Menu className="umi-plugin-layout-menu">
398
- <Menu.Item
399
- key="logout"
400
- onClick={() =>
401
- opts.runtimeConfig.logout && opts.runtimeConfig?.logout(opts.initialState)
402
- }
403
- >
404
- <LogoutOutlined />
405
- \u9000\u51FA\u767B\u5F55
406
- </Menu.Item>
407
- </Menu>
408
- );
396
+
409
397
 
410
398
  const avatar = (
411
399
  <span className="umi-plugin-layout-action">
@@ -430,10 +418,35 @@ export function getRightRenderContent (opts: {
430
418
  );
431
419
  }
432
420
 
421
+ const langMenu = {
422
+ className: "umi-plugin-layout-menu",
423
+ selectedKeys: [],
424
+ items: [
425
+ {
426
+ key: "logout",
427
+ label: (
428
+ <>
429
+ <LogoutOutlined />
430
+ \u9000\u51FA\u767B\u5F55
431
+ </>
432
+ ),
433
+ onClick: () => {
434
+ opts?.runtimeConfig?.logout?.(opts.initialState);
435
+ },
436
+ },
437
+ ],
438
+ };
439
+
440
+ // antd@5 \u548C 4.24 \u4E4B\u540E\u63A8\u8350\u4F7F\u7528 menu\uFF0C\u6027\u80FD\u66F4\u597D
441
+ const dropdownProps =
442
+ version.startsWith("5.") || version.startsWith("4.24.")
443
+ ? { menu: langMenu }
444
+ : { overlay: <Menu {...langMenu} /> };
445
+
433
446
  return (
434
447
  <div className="umi-plugin-layout-right anticon">
435
448
  {opts.runtimeConfig.logout ? (
436
- <Dropdown overlay={menu} overlayClassName="umi-plugin-layout-container">
449
+ <Dropdown {...dropdownProps} overlayClassName="umi-plugin-layout-container">
437
450
  {avatar}
438
451
  </Dropdown>
439
452
  ) : (
@@ -218,20 +218,19 @@ export { connectMaster } from './connectMaster';
218
218
  });
219
219
  api.addMiddlewares(async () => {
220
220
  return async (req, res, next) => {
221
- var _a, _b;
221
+ var _a;
222
222
  const qiankunConfig = api.config.qiankun || {};
223
223
  const masterEntry = (_a = qiankunConfig.slave) == null ? void 0 : _a.masterEntry;
224
- const isMasterApp = (_b = qiankunConfig.master) == null ? void 0 : _b.enable;
225
224
  const { proxyToMasterEnabled } = await api.applyPlugins({
226
225
  key: "shouldProxyToMaster",
227
226
  type: api.ApplyPluginsType.modify,
228
227
  initialValue: { proxyToMasterEnabled: true, req }
229
228
  }) ?? {};
230
229
  if (masterEntry && proxyToMasterEnabled) {
231
- if (isMasterApp) {
232
- api.logger.warn("You should not set masterEntry in master app ");
233
- return next();
234
- }
230
+ await api.applyPlugins({
231
+ key: "onLocalProxyStart",
232
+ type: api.ApplyPluginsType.event
233
+ });
235
234
  return (0, import_http_proxy_middleware.createProxyMiddleware)((pathname) => pathname !== "/local-dev-server", {
236
235
  target: masterEntry,
237
236
  secure: false,
@@ -239,6 +238,14 @@ export { connectMaster } from './connectMaster';
239
238
  followRedirects: false,
240
239
  changeOrigin: true,
241
240
  selfHandleResponse: true,
241
+ onProxyReq(proxyReq) {
242
+ api.applyPlugins({
243
+ key: "onLocalProxyReq",
244
+ type: api.ApplyPluginsType.event,
245
+ sync: true,
246
+ args: proxyReq
247
+ });
248
+ },
242
249
  onProxyRes: (0, import_http_proxy_middleware.responseInterceptor)(async (responseBuffer, proxyRes, req2, res2) => {
243
250
  if (proxyRes.statusCode === 302) {
244
251
  const hostname = req2.hostname;
package/dist/request.js CHANGED
@@ -69,7 +69,7 @@ import {
69
69
  PaginatedResult,
70
70
  } from '{{{umiRequestPath}}}/es/types';
71
71
 
72
- type ResultWithData< T = any > = { data?: T; [key: string]: any };
72
+ type ResultWithData< T = any > = { {{resultDataType}} [key: string]: any };
73
73
 
74
74
  function useRequest<
75
75
  R = any,
@@ -82,8 +82,8 @@ function useRequest<
82
82
  ): BaseResult<U, P>;
83
83
  function useRequest<R extends ResultWithData = any, P extends any[] = any>(
84
84
  service: CombineService<R, P>,
85
- options?: BaseOptions<R['data'], P>,
86
- ): BaseResult<R['data'], P>;
85
+ options?: BaseOptions<R{{{resultDataField}}}, P>,
86
+ ): BaseResult<R{{{resultDataField}}}, P>;
87
87
  function useRequest<R extends LoadMoreFormatReturn = any, RR = any>(
88
88
  service: CombineService<RR, LoadMoreParams<R>>,
89
89
  options: LoadMoreOptionsWithFormat<R, RR>,
@@ -92,9 +92,9 @@ function useRequest<
92
92
  R extends ResultWithData<LoadMoreFormatReturn | any> = any,
93
93
  RR extends R = any,
94
94
  >(
95
- service: CombineService<R, LoadMoreParams<R['data']>>,
96
- options: LoadMoreOptions<RR['data']>,
97
- ): LoadMoreResult<R['data']>;
95
+ service: CombineService<R, LoadMoreParams<R{{{resultDataField}}}>>,
96
+ options: LoadMoreOptions<RR{{{resultDataField}}}>,
97
+ ): LoadMoreResult<R{{{resultDataField}}}>;
98
98
 
99
99
  function useRequest<R = any, Item = any, U extends Item = any>(
100
100
  service: CombineService<R, PaginatedParams>,
@@ -313,13 +313,18 @@ export type {
313
313
  let dataField = (_a = api.config.request) == null ? void 0 : _a.dataField;
314
314
  if (dataField === void 0)
315
315
  dataField = "data";
316
- const formatResult = dataField === "" ? `result => result` : `result => result?.${dataField}`;
316
+ const isEmpty = dataField === "";
317
+ const formatResult = isEmpty ? `result => result` : `result => result?.${dataField}`;
318
+ const resultDataType = isEmpty ? dataField : `${dataField}?: T;`;
319
+ const resultDataField = isEmpty ? dataField : `['${dataField}']`;
317
320
  api.writeTmpFile({
318
321
  path: "request.ts",
319
322
  content: import_plugin_utils.Mustache.render(requestTpl, {
320
323
  umiRequestPath,
321
324
  axiosPath,
322
- formatResult
325
+ formatResult,
326
+ resultDataType,
327
+ resultDataField
323
328
  })
324
329
  });
325
330
  api.writeTmpFile({
@@ -1,6 +1,6 @@
1
1
  import React,{ useState } from 'react';
2
2
  {{#Antd}}
3
- import { Menu, Dropdown } from 'antd';
3
+ import { Menu, version, Dropdown } from 'antd';
4
4
  import { ClickParam } from 'antd/{{{antdFiles}}}/menu';
5
5
  import { DropDownProps } from 'antd/{{{antdFiles}}}/dropdown';
6
6
  {{/Antd}}
@@ -422,20 +422,30 @@ export const SelectLang: React.FC<SelectLangProps> = (props) => {
422
422
 
423
423
  const menuItemStyle = { minWidth: "160px" };
424
424
  const menuItemIconStyle = { marginRight: "8px" };
425
- const langMenu = (
426
- <Menu selectedKeys={[selectedLang]} onClick={handleClick}>
427
- {allLangUIConfig.map((localeObj) => {
428
- return (
429
- <Menu.Item key={localeObj.lang || localeObj.key} style={menuItemStyle}>
430
- <span role="img" aria-label={localeObj?.label || "en-US"} style={menuItemIconStyle}>
431
- {localeObj?.icon || "🌐"}
432
- </span>
433
- {localeObj?.label || "en-US"}
434
- </Menu.Item>
435
- );
436
- })}
437
- </Menu>
438
- );
425
+
426
+ const langMenu = {
427
+ selectedKeys: [selectedLang],
428
+ onClick: handleClick,
429
+ items: allLangUIConfig.map((localeObj) => ({
430
+ key: localeObj.lang || localeObj.key,
431
+ style: menuItemStyle,
432
+ label: (
433
+ <>
434
+ <span role="img" aria-label={localeObj?.label || 'en-US'} style={menuItemIconStyle}>
435
+ {localeObj?.icon || '🌐'}
436
+ </span>
437
+ {localeObj?.label || 'en-US'}
438
+ </>
439
+ ),
440
+ })),
441
+ };
442
+
443
+ // antd@5 和 4.24 之后推荐使用 menu,性能更好
444
+ const dropdownProps =
445
+ version.startsWith('5.') || version.startsWith('4.24.')
446
+ ? { menu: langMenu }
447
+ : { overlay: <Menu {...langMenu} /> };
448
+
439
449
 
440
450
  const inlineStyle = {
441
451
  cursor: "pointer",
@@ -449,7 +459,7 @@ export const SelectLang: React.FC<SelectLangProps> = (props) => {
449
459
  };
450
460
 
451
461
  return (
452
- <HeaderDropdown overlay={langMenu} placement="bottomRight" {...restProps}>
462
+ <HeaderDropdown {...dropdownProps} placement="bottomRight" {...restProps}>
453
463
  <span className={globalIconClassName} style={inlineStyle}>
454
464
  <i className="anticon" title={allLangUIConfig[selectedLang]?.title}>
455
465
  { icon ?
@@ -186,9 +186,9 @@ export const MicroApp = forwardRef(
186
186
  prefetchApps(specialPrefetchApps, configuration);
187
187
  } else {
188
188
  // 不能无脑全量 prefetch,需要有一个阈值
189
- const otherNotMountedApps = apps.filter(
190
- (app) => !isCurrentApp(app),
191
- ).slice(0, prefetchThreshold);
189
+ const otherNotMountedApps = apps
190
+ .filter((app) => !isCurrentApp(app))
191
+ .slice(0, prefetchThreshold);
192
192
  prefetchApps(otherNotMountedApps, configuration);
193
193
  }
194
194
  noneMounted = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/plugins",
3
- "version": "4.0.32",
3
+ "version": "4.0.33",
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",
@@ -27,7 +27,7 @@
27
27
  "@ant-design/antd-theme-variable": "^1.0.0",
28
28
  "@ant-design/icons": "^4.7.0",
29
29
  "@ant-design/pro-components": "^2.0.1",
30
- "@umijs/bundler-utils": "4.0.32",
30
+ "@umijs/bundler-utils": "4.0.33",
31
31
  "@umijs/valtio": "^1.0.0",
32
32
  "antd-dayjs-webpack-plugin": "^1.0.6",
33
33
  "axios": "^0.27.2",
@@ -49,7 +49,7 @@
49
49
  },
50
50
  "devDependencies": {
51
51
  "antd": "^4.24.1",
52
- "umi": "4.0.32"
52
+ "umi": "4.0.33"
53
53
  },
54
54
  "publishConfig": {
55
55
  "access": "public"