@umijs/plugins 4.0.0-canary.20220628.1 → 4.0.0-canary.20220713.1

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
@@ -114,7 +114,7 @@ export const useAccessMarkedRoutes = (routes: IRoute[]) => {
114
114
  }
115
115
 
116
116
  return routes.map(route => process(route));
117
- }, [routes.length]);
117
+ }, [routes.length, access]);
118
118
 
119
119
  return markdedRoutes;
120
120
  }
package/dist/layout.js CHANGED
@@ -91,6 +91,7 @@ exports.default = (api) => {
91
91
  path: 'Layout.tsx',
92
92
  content: `
93
93
  import { Link, useLocation, useNavigate, Outlet, useAppData, useRouteData, matchRoutes } from 'umi';
94
+ import type { IRoute } from 'umi';
94
95
  import React, { useMemo } from 'react';
95
96
  import {
96
97
  ProLayout,
@@ -113,6 +114,48 @@ import { useIntl } from '@@/plugin-locale';
113
114
  `.trim()
114
115
  : ''}
115
116
 
117
+ // 过滤出需要显示的路由, 这里的filterFn 指 不希望显示的层级
118
+ const filterRoutes = (routes: IRoute[], filterFn: (route: IRoute) => boolean) => {
119
+ if (routes.length === 0) {
120
+ return []
121
+ }
122
+
123
+ let newRoutes = []
124
+ for (const route of routes) {
125
+ if (filterFn(route)) {
126
+ if (Array.isArray(route.routes)) {
127
+ newRoutes.push(...filterRoutes(route.routes, filterFn))
128
+ }
129
+ } else {
130
+ newRoutes.push(route);
131
+ if (Array.isArray(route.routes)) {
132
+ route.routes = filterRoutes(route.routes, filterFn);
133
+ }
134
+ }
135
+ }
136
+
137
+ return newRoutes;
138
+ }
139
+
140
+ // 格式化路由 处理因 wrapper 导致的 菜单 path 不一致
141
+ const mapRoutes = (routes: IRoute[]) => {
142
+ if (routes.length === 0) {
143
+ return []
144
+ }
145
+ return routes.map(route => {
146
+ // 需要 copy 一份, 否则会污染原始数据
147
+ const newRoute = {...route}
148
+ if (route.originPath) {
149
+ newRoute.path = route.originPath
150
+ }
151
+
152
+ if (Array.isArray(route.routes)) {
153
+ newRoute.routes = mapRoutes(route.routes);
154
+ }
155
+
156
+ return newRoute
157
+ })
158
+ }
116
159
 
117
160
  export default (props: any) => {
118
161
  const location = useLocation();
@@ -137,8 +180,13 @@ const { formatMessage } = useIntl();
137
180
  ...initialInfo
138
181
  },
139
182
  });
183
+
140
184
  const matchedRoute = useMemo(() => matchRoutes(clientRoutes, location.pathname).pop()?.route, [location.pathname]);
141
- const [route] = useAccessMarkedRoutes(clientRoutes.filter(({ id }) => id === 'ant-design-pro-layout'));
185
+ const newRoutes = filterRoutes(clientRoutes.filter(route => route.id === 'ant-design-pro-layout'), (route) => {
186
+ return (!!route.isLayout && route.id !== 'ant-design-pro-layout') || !!route.isWrapper;
187
+ })
188
+ const [route] = useAccessMarkedRoutes(mapRoutes(newRoutes));
189
+
142
190
  return (
143
191
  <ProLayout
144
192
  route={route}
package/dist/locale.js CHANGED
@@ -182,7 +182,7 @@ exports.default = (api) => {
182
182
  api.writeTmpFile({
183
183
  path: 'index.ts',
184
184
  content: `
185
- export { setLocale, getLocale, getIntl, useIntl, injectIntl, formatMessage, FormattedMessage } from './localeExports.ts';
185
+ export { addLocale, setLocale, getLocale, getIntl, useIntl, injectIntl, formatMessage, FormattedMessage, getAllLocales } from './localeExports.ts';
186
186
  export { SelectLang } from './SelectLang.tsx';
187
187
  `,
188
188
  });
package/dist/request.js CHANGED
@@ -23,6 +23,7 @@ import axios, {
23
23
  type AxiosInstance,
24
24
  type AxiosRequestConfig,
25
25
  type AxiosResponse,
26
+ type AxiosError,
26
27
  } from '{{{axiosPath}}}';
27
28
  import useUmiRequest, { UseRequestProvider } from '{{{umiRequestPath}}}';
28
29
  import { ApplyPluginsType } from 'umi';
@@ -123,6 +124,8 @@ interface IRequest{
123
124
  <T = any>(url: string): Promise<T>; // 不提供 opts 时,默认使用 'GET' method,并且默认返回 data
124
125
  }
125
126
 
127
+ type RequestError = AxiosError | Error
128
+
126
129
  interface IErrorHandler {
127
130
  (error: RequestError, opts: IRequestOptions): void;
128
131
  }
@@ -134,10 +137,10 @@ type IResponseInterceptor = <T = any>(response : AxiosResponse<T>) => AxiosRespo
134
137
  type IRequestInterceptorTuple = [IRequestInterceptor , IErrorInterceptor] | [ IRequestInterceptor ] | IRequestInterceptor
135
138
  type IResponseInterceptorTuple = [IResponseInterceptor, IErrorInterceptor] | [IResponseInterceptor] | IResponseInterceptor
136
139
 
137
- export interface RequestConfig extends AxiosRequestConfig {
140
+ export interface RequestConfig<T = any> extends AxiosRequestConfig {
138
141
  errorConfig?: {
139
142
  errorHandler?: IErrorHandler;
140
- errorThrower?: <T = any>( res: T ) => void
143
+ errorThrower?: ( res: T ) => void
141
144
  };
142
145
  requestInterceptors?: IRequestInterceptorTuple[];
143
146
  responseInterceptors?: IResponseInterceptorTuple[];
@@ -302,6 +305,8 @@ export type {
302
305
  AxiosInstance,
303
306
  AxiosRequestConfig,
304
307
  AxiosResponse,
308
+ AxiosError,
309
+ RequestError,
305
310
  ResponseInterceptor } from './request';
306
311
  `,
307
312
  });
@@ -128,7 +128,7 @@ class ModelUtils {
128
128
  // check duplicate
129
129
  const namespaces = models.map((model) => model.namespace);
130
130
  if (new Set(namespaces).size !== namespaces.length) {
131
- throw new Error(`Duplicate namespace in models: ${namespaces.join(', ')}`);
131
+ throw new Error(`Duplicate namespace in models: ${namespaces.sort().join(', ')}`);
132
132
  }
133
133
  // sort models by deps
134
134
  if (opts.sort) {
@@ -228,7 +228,7 @@ const defaultLangUConfigMap = {
228
228
  title: 'Ziman'
229
229
  },
230
230
  'kn-IN': {
231
- lang: 'zh-TW',
231
+ lang: 'kn-IN',
232
232
  label: 'ಕನ್ನಡ',
233
233
  icon: '🇮🇳',
234
234
  title: 'ಭಾಷೆ'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/plugins",
3
- "version": "4.0.0-canary.20220628.1",
3
+ "version": "4.0.0-canary.20220713.1",
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",
@@ -25,7 +25,7 @@
25
25
  "@ahooksjs/use-request": "^2.0.0",
26
26
  "@ant-design/icons": "^4.7.0",
27
27
  "@ant-design/pro-layout": "^7.0.1-beta.20",
28
- "@umijs/bundler-utils": "4.0.0-canary.20220628.1",
28
+ "@umijs/bundler-utils": "4.0.0-canary.20220713.1",
29
29
  "antd-dayjs-webpack-plugin": "^1.0.6",
30
30
  "axios": "^0.27.2",
31
31
  "babel-plugin-import": "^1.13.5",
@@ -44,7 +44,7 @@
44
44
  "warning": "^4.0.3"
45
45
  },
46
46
  "devDependencies": {
47
- "umi": "4.0.0-canary.20220628.1"
47
+ "umi": "4.0.0-canary.20220713.1"
48
48
  },
49
49
  "publishConfig": {
50
50
  "access": "public"