@umijs/plugins 4.0.23 → 4.0.25

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/access.js CHANGED
@@ -50,7 +50,7 @@ import { AccessContext } from './context';
50
50
 
51
51
  function Provider(props) {${hasAccessFile ? `
52
52
  const { initialState } = useModel('@@initialState');
53
- const access = accessFactory(initialState);
53
+ const access = React.useMemo(() => accessFactory(initialState), [initialState]);
54
54
  ` : `
55
55
  const access = {};
56
56
  `}
@@ -91,7 +91,8 @@ export const Access: React.FC<PropsWithChildren<AccessProps>> = (props) => {
91
91
 
92
92
  export const useAccessMarkedRoutes = (routes: IRoute[]) => {
93
93
  const access = useAccess();
94
- const process = (route, parentAccessCode, parentRoute) => {
94
+ const markdedRoutes: IRoute[] = React.useMemo(() => {
95
+ const process = (route, parentAccessCode, parentRoute) => {
95
96
  let accessCode = route.access;
96
97
  // \u7528\u7236\u7EA7\u7684\u8DEF\u7531\u68C0\u6D4B\u7236\u7EA7\u7684 accessCode
97
98
  let detectorRoute = route;
@@ -100,50 +101,44 @@ export const useAccessMarkedRoutes = (routes: IRoute[]) => {
100
101
  detectorRoute = parentRoute;
101
102
  }
102
103
 
103
- // set default status
104
- route.unaccessible = ${api.config.access.strictMode ? "true" : "false"};
104
+ // set default status
105
+ route.unaccessible = ${api.config.access.strictMode ? "true" : "false"};
105
106
 
106
- // check access code
107
- if (typeof accessCode === "string") {
108
- const detector = access[accessCode];
107
+ // check access code
108
+ if (typeof accessCode === 'string') {
109
+ const detector = access[accessCode];
109
110
 
110
- if (typeof detector === "function") {
111
- route.unaccessible = !detector(detectorRoute);
112
- } else if (typeof detector === "boolean") {
113
- route.unaccessible = !detector;
114
- } else if (typeof detector === "undefined") {
115
- route.unaccessible = true;
111
+ if (typeof detector === 'function') {
112
+ route.unaccessible = !detector(detectorRoute);
113
+ } else if (typeof detector === 'boolean') {
114
+ route.unaccessible = !detector;
115
+ } else if (typeof detector === 'undefined') {
116
+ route.unaccessible = true;
117
+ }
116
118
  }
117
- }
118
119
 
119
- // check children access code
120
- if (route.children?.length) {
121
- const isNoAccessibleChild = !route.children.reduce(
122
- (hasAccessibleChild, child) => {
120
+ // check children access code
121
+ if (route.children?.length) {
122
+ const isNoAccessibleChild = !route.children.reduce((hasAccessibleChild, child) => {
123
123
  process(child, accessCode, route);
124
124
 
125
125
  return hasAccessibleChild || !child.unaccessible;
126
- },
127
- false
128
- );
126
+ }, false);
129
127
 
130
- // make sure parent route is unaccessible if all children are unaccessible
131
- if (isNoAccessibleChild) {
132
- route.unaccessible = true;
128
+ // make sure parent route is unaccessible if all children are unaccessible
129
+ if (isNoAccessibleChild) {
130
+ route.unaccessible = true;
131
+ }
133
132
  }
134
- }
135
-
136
- // \u4E3A\u4E86\u517C\u5BB9\u65E7\u7248\u672C\u7684layout\uFF0C<= 7.1.0
137
- // \u5982\u679C\u662F 7.1.0 \u4EE5\u4E0B\u7684layout\u53EF\u80FD\u4F1A\u51FA\u73B0\u6570\u636E\u5F02\u5E38\u3002
138
- delete route.routes;
139
- route.routes = route.children;
140
133
 
141
- return route;
142
- };
134
+ return route;
135
+ }
143
136
 
144
- return routes.map((route) => process(route));
145
- };
137
+ return routes.map(route => process(route));
138
+ }, [routes.length, access]);
146
139
 
140
+ return markdedRoutes;
141
+ }
147
142
  `
148
143
  });
149
144
  api.writeTmpFile({
package/dist/antd.js CHANGED
@@ -26,6 +26,7 @@ __export(antd_exports, {
26
26
  });
27
27
  module.exports = __toCommonJS(antd_exports);
28
28
  var import_path = require("path");
29
+ var import_assert = __toESM(require("assert"));
29
30
  var import_plugin_utils = require("umi/plugin-utils");
30
31
  var import_resolveProjectDep = require("./utils/resolveProjectDep");
31
32
  var import_withTmpPath = require("./utils/withTmpPath");
@@ -49,7 +50,8 @@ var antd_default = (api) => {
49
50
  dark: Joi.boolean(),
50
51
  compact: Joi.boolean(),
51
52
  import: Joi.boolean(),
52
- style: Joi.string().allow("less", "css")
53
+ style: Joi.string().allow("less", "css"),
54
+ theme: Joi.object()
53
55
  }), Joi.boolean().invalid(true));
54
56
  }
55
57
  },
@@ -76,7 +78,7 @@ var antd_default = (api) => {
76
78
  let antd = memo.antd || {};
77
79
  if (process.env.UMI_PLUGIN_ANTD_ENABLE) {
78
80
  const { defaultConfig } = JSON.parse(process.env.UMI_PLUGIN_ANTD_ENABLE);
79
- antd = Object.assign(defaultConfig, antd);
81
+ memo.antd = antd = Object.assign(defaultConfig, antd);
80
82
  }
81
83
  memo.alias.antd = pkgPath;
82
84
  if (antd.dayjs) {
@@ -100,6 +102,11 @@ var antd_default = (api) => {
100
102
  "root-entry-name": "default",
101
103
  ...memo.theme
102
104
  };
105
+ if (antd.theme) {
106
+ (0, import_assert.default)(antdVersion.startsWith("5"), `antd.theme is only valid when antd is 5`);
107
+ antd.configProvider ?? (antd.configProvider = {});
108
+ antd.configProvider.theme = (0, import_plugin_utils.deepmerge)(antd.configProvider.theme || {}, antd.theme);
109
+ }
103
110
  return memo;
104
111
  });
105
112
  api.addExtraBabelPlugins(() => {
package/dist/layout.js CHANGED
@@ -124,13 +124,13 @@ const filterRoutes = (routes: IRoute[], filterFn: (route: IRoute) => boolean) =>
124
124
  let newRoutes = []
125
125
  for (const route of routes) {
126
126
  if (filterFn(route)) {
127
- if (Array.isArray(route.children)) {
128
- newRoutes.push(...filterRoutes(route.children, filterFn))
127
+ if (Array.isArray(route.routes)) {
128
+ newRoutes.push(...filterRoutes(route.routes, filterFn))
129
129
  }
130
130
  } else {
131
131
  newRoutes.push(route);
132
- if (Array.isArray(route.children)) {
133
- route.children = filterRoutes(route.children, filterFn);
132
+ if (Array.isArray(route.routes)) {
133
+ route.routes = filterRoutes(route.routes, filterFn);
134
134
  }
135
135
  }
136
136
  }
@@ -150,11 +150,11 @@ const mapRoutes = (routes: IRoute[]) => {
150
150
  newRoute.path = route.originPath
151
151
  }
152
152
 
153
- if (Array.isArray(route.children)) {
154
- newRoute.children = mapRoutes(route.children);
153
+ if (Array.isArray(route.routes)) {
154
+ newRoute.routes = mapRoutes(route.routes);
155
155
  }
156
156
 
157
- return newRoute;
157
+ return newRoute
158
158
  })
159
159
  }
160
160
 
@@ -180,13 +180,13 @@ const { formatMessage } = useIntl();
180
180
  },
181
181
  });
182
182
 
183
- const matchedRouteNoAccess = useMemo(() => matchRoutes(clientRoutes, location.pathname)?.pop()?.route||[], [location.pathname]);
183
+ const matchedRoute = useMemo(() => matchRoutes(clientRoutes, location.pathname).pop()?.route, [location.pathname]);
184
184
  // \u73B0\u5728\u7684 layout \u53CA wrapper \u5B9E\u73B0\u662F\u901A\u8FC7\u7236\u8DEF\u7531\u7684\u5F62\u5F0F\u5B9E\u73B0\u7684, \u4F1A\u5BFC\u81F4\u8DEF\u7531\u6570\u636E\u591A\u4E86\u5197\u4F59\u5C42\u7EA7, proLayout \u6D88\u8D39\u65F6, \u65E0\u6CD5\u6B63\u786E\u5C55\u793A\u83DC\u5355, \u8FD9\u91CC\u5BF9\u5197\u4F59\u6570\u636E\u8FDB\u884C\u8FC7\u6EE4\u64CD\u4F5C
185
185
  const newRoutes = filterRoutes(clientRoutes.filter(route => route.id === 'ant-design-pro-layout'), (route) => {
186
186
  return (!!route.isLayout && route.id !== 'ant-design-pro-layout') || !!route.isWrapper;
187
187
  })
188
188
  const [route] = useAccessMarkedRoutes(mapRoutes(newRoutes));
189
- const [matchedRoute] = useAccessMarkedRoutes([matchedRouteNoAccess]);
189
+
190
190
  return (
191
191
  <ProLayout
192
192
  route={route}
@@ -16,13 +16,15 @@ export function patchRoutes({ routes }) {
16
16
  Object.keys(routes).forEach((key) => {
17
17
  const route = routes[key];
18
18
  if (route.title) {
19
- route.locale = route.title;
20
19
  const newTitle = intl.messages[route.title] ? intl.formatMessage({ id: route.title }, {}) : route.title;
21
20
  route.name = intl.messages[route.title] ? intl.formatMessage({ id: route.title }, {}) : route.name;
22
21
  route.title = newTitle;
23
22
  }
24
- if (route.children) {
25
- traverseRoute(route.children);
23
+ if (route.routes) {
24
+ traverseRoute(route.routes);
25
+ }
26
+ if (route.routes) {
27
+ traverseRoute(route.routes);
26
28
  }
27
29
  })
28
30
  }
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import { useMatch } from 'umi';
2
3
  import { MicroApp } from './MicroApp';
3
4
 
4
5
  export function getMicroAppRouteComponent(opts: {
@@ -10,11 +11,13 @@ export function getMicroAppRouteComponent(opts: {
10
11
  }) {
11
12
  const { base, masterHistoryType, appName, routeProps, routePath } = opts;
12
13
  const RouteComponent = () => {
14
+ const match = useMatch(routePath);
15
+ const url = match.pathnameBase;
13
16
  // 默认取静态配置的 base
14
17
  let umiConfigBase = base === '/' ? '' : base;
15
18
 
16
19
  // 拼接子应用挂载路由
17
- let runtimeMatchedBase = umiConfigBase + routePath.replace('/*', '');
20
+ let runtimeMatchedBase = umiConfigBase + (url.endsWith('/') ? url.substr(0, url.length - 1) : url);
18
21
 
19
22
  {{#dynamicRoot}}
20
23
  // @see https://github.com/umijs/umi/blob/master/packages/preset-built-in/src/plugins/commands/htmlUtils.ts#L102
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/plugins",
3
- "version": "4.0.23",
3
+ "version": "4.0.25",
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.23",
30
+ "@umijs/bundler-utils": "4.0.25",
31
31
  "@umijs/valtio": "^1.0.0",
32
32
  "antd-dayjs-webpack-plugin": "^1.0.6",
33
33
  "axios": "^0.27.2",
@@ -47,7 +47,7 @@
47
47
  "warning": "^4.0.3"
48
48
  },
49
49
  "devDependencies": {
50
- "umi": "4.0.23"
50
+ "umi": "4.0.25"
51
51
  },
52
52
  "publishConfig": {
53
53
  "access": "public"