@allahjs/umi-plugin-layout-lite 0.1.0 → 0.1.2

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 CHANGED
@@ -44,3 +44,5 @@ export const layout = ({ initialState }: any) => ({
44
44
  cd packages/umi-plugin-layout-lite
45
45
  npm publish --access public
46
46
  ```
47
+
48
+ 建议先发布 `0.1.1`(修复 CJS 产物在部分 MFSU 场景下的运行时兼容问题)。
package/dist/Layout.js CHANGED
@@ -1,25 +1,22 @@
1
- 'use strict';
2
-
3
- var jsxRuntime = require('react/jsx-runtime');
4
- var React = require('react');
5
- var max = require('@umijs/max');
6
- var proComponents = require('@ant-design/pro-components');
7
- var antd = require('antd');
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import { useMemo } from 'react';
3
+ import { useLocation, useNavigate, useAppData, useModel, matchRoutes, Outlet, Link, history } from '@umijs/max';
4
+ import { ProLayout } from '@ant-design/pro-components';
5
+ import { Result, Button, Spin } from 'antd';
8
6
 
9
7
  const Exception = props => {
10
8
  var _a, _b;
11
- return ((!props.route && (props.noFound || props.notFound)) ||
12
- (((_a = props.route) === null || _a === void 0 ? void 0 : _a.unaccessible) &&
13
- (props.unAccessible || props.noAccessible)) ||
14
- ((!props.route || ((_b = props.route) === null || _b === void 0 ? void 0 : _b.unaccessible)) && (jsxRuntime.jsx(antd.Result, { status: props.route ? '403' : '404', title: props.route ? '403' : '404', subTitle: props.route ? '抱歉,你无权访问该页面' : '抱歉,你访问的页面不存在', extra: jsxRuntime.jsx(antd.Button, { type: "primary", onClick: () => max.history.push('/'), children: "\u8FD4\u56DE\u9996\u9875" }) }))) ||
15
- props.children);
9
+ return (!props.route && (props.noFound || props.notFound)) ||
10
+ (((_a = props.route) === null || _a === void 0 ? void 0 : _a.unaccessible) && (props.unAccessible || props.noAccessible)) ||
11
+ ((!props.route || ((_b = props.route) === null || _b === void 0 ? void 0 : _b.unaccessible)) && (jsx(Result, { status: props.route ? '403' : '404', title: props.route ? '403' : '404', subTitle: props.route ? '抱歉,你无权访问该页面' : '抱歉,你访问的页面不存在', extra: jsx(Button, { type: "primary", onClick: () => history.push('/'), children: "\u8FD4\u56DE\u9996\u9875" }) }))) ||
12
+ props.children;
16
13
  };
17
14
  function getRightRenderContent(opts) {
18
15
  if (opts.runtimeConfig.rightRender) {
19
16
  return opts.runtimeConfig.rightRender(opts.initialState, opts.setInitialState, opts.runtimeConfig);
20
17
  }
21
18
  if (opts.loading) {
22
- return jsxRuntime.jsx(antd.Spin, { size: "small", style: { marginLeft: 8, marginRight: 8 } });
19
+ return jsx(Spin, { size: "small", style: { marginLeft: 8, marginRight: 8 } });
23
20
  }
24
21
  return null;
25
22
  }
@@ -62,10 +59,10 @@ const mapRoutes = (routes) => {
62
59
  });
63
60
  };
64
61
  function LayoutLite(props) {
65
- const location = max.useLocation();
66
- const navigate = max.useNavigate();
67
- const { clientRoutes, pluginManager } = max.useAppData();
68
- const initialInfo = max.useModel('@@initialState') || {
62
+ const location = useLocation();
63
+ const navigate = useNavigate();
64
+ const { clientRoutes, pluginManager } = useAppData();
65
+ const initialInfo = useModel('@@initialState') || {
69
66
  initialState: undefined,
70
67
  loading: false,
71
68
  setInitialState: null,
@@ -81,7 +78,7 @@ function LayoutLite(props) {
81
78
  const userConfig = {};
82
79
  const newRoutes = filterRoutes(clientRoutes.filter((route) => route.id === 'layout-lite'), route => (route.isLayout && route.id !== 'layout-lite') || !!route.isWrapper);
83
80
  const route = mapRoutes(newRoutes)[0];
84
- const matchedRoute = React.useMemo(() => { var _a, _b, _c; return (_c = (_b = (_a = max.matchRoutes((route === null || route === void 0 ? void 0 : route.children) || [], location.pathname)) === null || _a === void 0 ? void 0 : _a.pop) === null || _b === void 0 ? void 0 : _b.call(_a)) === null || _c === void 0 ? void 0 : _c.route; }, [route, location.pathname]);
81
+ const matchedRoute = useMemo(() => { var _a, _b, _c; return (_c = (_b = (_a = matchRoutes((route === null || route === void 0 ? void 0 : route.children) || [], location.pathname)) === null || _a === void 0 ? void 0 : _a.pop) === null || _b === void 0 ? void 0 : _b.call(_a)) === null || _c === void 0 ? void 0 : _c.route; }, [route, location.pathname]);
85
82
  const renderRightActions = (layoutProps) => {
86
83
  const dom = getRightRenderContent({
87
84
  runtimeConfig,
@@ -100,28 +97,29 @@ function LayoutLite(props) {
100
97
  }
101
98
  return dom;
102
99
  };
103
- return (jsxRuntime.jsx(proComponents.ProLayout, { route: route, location: location, title: runtimeConfig.title || 'layout-lite', menu: { locale: runtimeConfig.locale }, onMenuHeaderClick: event => {
100
+ return (jsx(ProLayout, { route: route, location: location, title: runtimeConfig.title || 'layout-lite', menu: { locale: runtimeConfig.locale }, onMenuHeaderClick: event => {
104
101
  event.stopPropagation();
105
102
  event.preventDefault();
106
103
  navigate('/');
104
+ }, menuProps: {
105
+ onClick: e => {
106
+ if (e.key) {
107
+ navigate(e.key.replace('/*', ''));
108
+ }
109
+ },
107
110
  }, menuItemRender: (menuItemProps, defaultDom) => {
108
- if (menuItemProps.isUrl || menuItemProps.children) {
109
- return defaultDom;
110
- }
111
- if (menuItemProps.path && location.pathname !== menuItemProps.path) {
112
- return (jsxRuntime.jsx(max.Link, { to: menuItemProps.path.replace('/*', ''), target: menuItemProps.target, children: defaultDom }));
111
+ if (menuItemProps.isUrl) {
112
+ return (jsx("a", { href: menuItemProps.path, target: menuItemProps.target, children: defaultDom }));
113
113
  }
114
- return defaultDom;
114
+ return jsx("div", { children: defaultDom });
115
115
  }, itemRender: (currentRoute, _, routes) => {
116
- const label = currentRoute.title || currentRoute.breadcrumbName;
116
+ const label = currentRoute.title;
117
117
  const lastRoute = routes[routes.length - 1];
118
118
  if (lastRoute && (lastRoute.path === currentRoute.path || lastRoute.linkPath === currentRoute.path)) {
119
- return jsxRuntime.jsx("span", { children: label });
119
+ return jsx("span", { children: label });
120
120
  }
121
- return jsxRuntime.jsx(max.Link, { to: currentRoute.path || '/', children: label });
122
- }, actionsRender: renderRightActions, ...runtimeConfig, children: jsxRuntime.jsx(Exception, { route: matchedRoute, noFound: runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.noFound, notFound: runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.notFound, unAccessible: runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.unAccessible, noAccessible: runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.noAccessible, children: runtimeConfig.childrenRender
123
- ? runtimeConfig.childrenRender(jsxRuntime.jsx(max.Outlet, {}), props)
124
- : jsxRuntime.jsx(max.Outlet, {}) }) }));
121
+ return jsx(Link, { to: currentRoute.path || '/', children: label });
122
+ }, actionsRender: renderRightActions, ...runtimeConfig, children: jsx(Exception, { route: matchedRoute, noFound: runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.noFound, notFound: runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.notFound, unAccessible: runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.unAccessible, noAccessible: runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.noAccessible, children: runtimeConfig.childrenRender ? runtimeConfig.childrenRender(jsx(Outlet, {}), props) : jsx(Outlet, {}) }) }));
125
123
  }
126
124
 
127
- module.exports = LayoutLite;
125
+ export { LayoutLite as default };
package/dist/runtime.js CHANGED
@@ -1,26 +1,5 @@
1
- 'use strict';
2
-
3
- var React = require('react');
4
- var Icons = require('@ant-design/icons');
5
-
6
- function _interopNamespaceDefault(e) {
7
- var n = Object.create(null);
8
- if (e) {
9
- Object.keys(e).forEach(function (k) {
10
- if (k !== 'default') {
11
- var d = Object.getOwnPropertyDescriptor(e, k);
12
- Object.defineProperty(n, k, d.get ? d : {
13
- enumerable: true,
14
- get: function () { return e[k]; }
15
- });
16
- }
17
- });
18
- }
19
- n.default = e;
20
- return Object.freeze(n);
21
- }
22
-
23
- var Icons__namespace = /*#__PURE__*/_interopNamespaceDefault(Icons);
1
+ import React from 'react';
2
+ import * as Icons from '@ant-design/icons';
24
3
 
25
4
  function formatIcon(name) {
26
5
  return name
@@ -34,11 +13,11 @@ function patchRoutes({ routes }) {
34
13
  if (!icon || typeof icon !== 'string')
35
14
  return;
36
15
  const iconName = formatIcon(icon);
37
- const IconComponent = Icons__namespace[iconName] || Icons__namespace[`${iconName}Outlined`];
16
+ const IconComponent = Icons[iconName] || Icons[`${iconName}Outlined`];
38
17
  if (IconComponent) {
39
18
  routes[key].icon = React.createElement(IconComponent);
40
19
  }
41
20
  });
42
21
  }
43
22
 
44
- exports.patchRoutes = patchRoutes;
23
+ export { patchRoutes };
package/package.json CHANGED
@@ -1,54 +1,54 @@
1
1
  {
2
- "name": "@allahjs/umi-plugin-layout-lite",
3
- "version": "0.1.0",
4
- "description": "A lightweight Umi layout plugin with ProLayout and rightContentRender compatibility.",
5
- "repository": "https://github.com/allah-prime/umi-plugin-layout-lite",
6
- "main": "dist/index.js",
7
- "types": "dist/index.d.ts",
8
- "files": [
9
- "dist",
10
- "README.md"
11
- ],
12
- "exports": {
13
- ".": {
14
- "types": "./dist/index.d.ts",
15
- "import": "./dist/index.js",
16
- "require": "./dist/index.js"
17
- }
18
- },
19
- "scripts": {
20
- "build": "rimraf dist && rollup -c",
21
- "prepublishOnly": "npm run build"
22
- },
23
- "keywords": [
24
- "umi",
25
- "umijs",
26
- "plugin",
27
- "layout",
28
- "prolayout",
29
- "antd"
30
- ],
31
- "peerDependencies": {
32
- "@ant-design/icons": ">=6",
33
- "@ant-design/pro-components": ">=3.0.0-0",
34
- "@umijs/max": ">=4",
35
- "antd": ">=6",
36
- "react": ">=18",
37
- "react-dom": ">=18",
38
- "umi": ">=4"
39
- },
40
- "devDependencies": {
41
- "@rollup/plugin-commonjs": "^28.0.9",
42
- "@rollup/plugin-node-resolve": "^16.0.3",
43
- "@rollup/plugin-typescript": "^12.3.0",
44
- "@types/node": "^24.3.0",
45
- "@types/react": "^19.2.0",
46
- "rimraf": "^6.0.1",
47
- "rollup": "^4.50.1",
48
- "rollup-plugin-dts": "^6.2.3",
49
- "rollup-plugin-peer-deps-external": "^2.2.4",
50
- "tslib": "^2.8.1",
51
- "typescript": "^5.9.0"
52
- },
53
- "license": "MIT"
2
+ "name": "@allahjs/umi-plugin-layout-lite",
3
+ "version": "0.1.2",
4
+ "description": "A lightweight Umi layout plugin with ProLayout and rightContentRender compatibility.",
5
+ "repository": "https://github.com/allah-prime/umi-plugin-layout-lite",
6
+ "main": "dist/index.cjs",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist",
10
+ "README.md"
11
+ ],
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/index.cjs",
16
+ "require": "./dist/index.cjs"
17
+ }
18
+ },
19
+ "scripts": {
20
+ "build": "rimraf dist && rollup -c",
21
+ "prepublishOnly": "npm run build"
22
+ },
23
+ "keywords": [
24
+ "umi",
25
+ "umijs",
26
+ "plugin",
27
+ "layout",
28
+ "prolayout",
29
+ "antd"
30
+ ],
31
+ "peerDependencies": {
32
+ "@ant-design/icons": ">=6",
33
+ "@ant-design/pro-components": ">=3.0.0-0",
34
+ "@umijs/max": ">=4",
35
+ "antd": ">=6",
36
+ "react": ">=18",
37
+ "react-dom": ">=18",
38
+ "umi": ">=4"
39
+ },
40
+ "devDependencies": {
41
+ "@rollup/plugin-commonjs": "^28.0.9",
42
+ "@rollup/plugin-node-resolve": "^16.0.3",
43
+ "@rollup/plugin-typescript": "^12.3.0",
44
+ "@types/node": "^24.3.0",
45
+ "@types/react": "^19.2.0",
46
+ "rimraf": "^6.0.1",
47
+ "rollup": "^4.50.1",
48
+ "rollup-plugin-dts": "^6.2.3",
49
+ "rollup-plugin-peer-deps-external": "^2.2.4",
50
+ "tslib": "^2.8.1",
51
+ "typescript": "^5.9.0"
52
+ },
53
+ "license": "MIT"
54
54
  }
File without changes