listpage-next 0.0.242 → 0.0.243
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/components/Menu/types.d.ts +8 -2
- package/dist/components/PageLayout/components/PageLogo/index.js +2 -6
- package/dist/features/ReactApp/App.d.ts +11 -0
- package/dist/features/ReactApp/App.js +42 -0
- package/dist/features/ReactApp/Auth.d.ts +4 -0
- package/dist/features/ReactApp/Auth.js +16 -0
- package/dist/features/ReactApp/Layout.d.ts +9 -0
- package/dist/features/ReactApp/Layout.js +26 -0
- package/dist/features/ReactApp/index.d.ts +1 -0
- package/dist/features/ReactApp/index.js +2 -0
- package/dist/features/ReactApp/utils.d.ts +4 -0
- package/dist/features/ReactApp/utils.js +15 -0
- package/package.json +5 -1
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
import { ItemType } from 'antd/es/menu/interface';
|
|
2
1
|
import { MenuProps as AntdMenuProps } from 'antd';
|
|
3
|
-
|
|
2
|
+
import { JSX, ReactNode } from 'react';
|
|
3
|
+
export type MenuItem = {
|
|
4
|
+
key: string;
|
|
5
|
+
label: string;
|
|
6
|
+
icon?: ReactNode;
|
|
7
|
+
children?: MenuItem[];
|
|
8
|
+
element?: JSX.Element;
|
|
9
|
+
};
|
|
4
10
|
export interface MenuProps extends Omit<AntdMenuProps, 'onSelect'> {
|
|
5
11
|
onSelect?: (path: string) => void;
|
|
6
12
|
defaultActiveKey?: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { Image } from "antd";
|
|
3
3
|
import { styled } from "styled-components";
|
|
4
4
|
import { usePageContext } from "../PageProvider/index.js";
|
|
5
5
|
const PageLogo = (props)=>{
|
|
@@ -11,11 +11,7 @@ const PageLogo = (props)=>{
|
|
|
11
11
|
src: src,
|
|
12
12
|
preview: true
|
|
13
13
|
});
|
|
14
|
-
const avatar = icon
|
|
15
|
-
icon: icon,
|
|
16
|
-
shape: "circle",
|
|
17
|
-
size: 22
|
|
18
|
-
});
|
|
14
|
+
const avatar = icon;
|
|
19
15
|
if (collapsed) return /*#__PURE__*/ jsx(LogoContentCollapseWrapper, {
|
|
20
16
|
children: image || avatar
|
|
21
17
|
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { MenuItem } from '../../components';
|
|
2
|
+
import { JSX, ReactNode } from 'react';
|
|
3
|
+
export interface AppProps {
|
|
4
|
+
menus: MenuItem[];
|
|
5
|
+
basename?: string;
|
|
6
|
+
title?: string;
|
|
7
|
+
icon?: ReactNode;
|
|
8
|
+
hasAuth?: () => boolean;
|
|
9
|
+
loginElement?: JSX.Element;
|
|
10
|
+
}
|
|
11
|
+
export declare const App: (props: AppProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
import { RouterProvider, createBrowserRouter } from "react-router-dom";
|
|
4
|
+
import { createRoutes } from "./utils.js";
|
|
5
|
+
import { Auth } from "./Auth.js";
|
|
6
|
+
import { Layout } from "./Layout.js";
|
|
7
|
+
const App = (props)=>{
|
|
8
|
+
const { menus, basename = '', title, icon, loginElement, hasAuth } = props;
|
|
9
|
+
const router = useMemo(()=>{
|
|
10
|
+
const routes = createRoutes(menus);
|
|
11
|
+
return createBrowserRouter([
|
|
12
|
+
loginElement && {
|
|
13
|
+
path: '/login',
|
|
14
|
+
element: loginElement
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
path: '/',
|
|
18
|
+
element: /*#__PURE__*/ jsx(Auth, {
|
|
19
|
+
hasAuth: hasAuth,
|
|
20
|
+
children: /*#__PURE__*/ jsx(Layout, {
|
|
21
|
+
menus: menus,
|
|
22
|
+
title: title,
|
|
23
|
+
icon: icon,
|
|
24
|
+
basename: basename
|
|
25
|
+
})
|
|
26
|
+
}),
|
|
27
|
+
children: routes
|
|
28
|
+
}
|
|
29
|
+
].filter(Boolean), {
|
|
30
|
+
basename
|
|
31
|
+
});
|
|
32
|
+
}, [
|
|
33
|
+
basename,
|
|
34
|
+
title,
|
|
35
|
+
icon,
|
|
36
|
+
menus
|
|
37
|
+
]);
|
|
38
|
+
return /*#__PURE__*/ jsx(RouterProvider, {
|
|
39
|
+
router: router
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
export { App };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Navigate, useLocation } from "react-router-dom";
|
|
3
|
+
const Auth = ({ children, hasAuth = ()=>true })=>{
|
|
4
|
+
const location = useLocation();
|
|
5
|
+
if (!hasAuth()) return /*#__PURE__*/ jsx(Navigate, {
|
|
6
|
+
to: "/login",
|
|
7
|
+
state: {
|
|
8
|
+
from: location
|
|
9
|
+
},
|
|
10
|
+
replace: true
|
|
11
|
+
});
|
|
12
|
+
return /*#__PURE__*/ jsx(Fragment, {
|
|
13
|
+
children: children
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
export { Auth };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { MenuItem } from '../../components';
|
|
3
|
+
export interface LayoutProps {
|
|
4
|
+
menus: MenuItem[];
|
|
5
|
+
basename?: string;
|
|
6
|
+
title?: string;
|
|
7
|
+
icon?: ReactNode;
|
|
8
|
+
}
|
|
9
|
+
export declare const Layout: (props: LayoutProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
import { Outlet, useNavigate } from "react-router-dom";
|
|
4
|
+
import { Menu, PageLayout } from "../../components/index.js";
|
|
5
|
+
import { getDefaultActiveKey } from "./utils.js";
|
|
6
|
+
const Layout = (props)=>{
|
|
7
|
+
const { menus, basename = '', title, icon } = props;
|
|
8
|
+
const navigate = useNavigate();
|
|
9
|
+
const defaultActiveKey = useMemo(()=>getDefaultActiveKey(basename, menus), [
|
|
10
|
+
basename,
|
|
11
|
+
menus
|
|
12
|
+
]);
|
|
13
|
+
return /*#__PURE__*/ jsx(PageLayout, {
|
|
14
|
+
logo: {
|
|
15
|
+
icon,
|
|
16
|
+
title
|
|
17
|
+
},
|
|
18
|
+
sider: /*#__PURE__*/ jsx(Menu, {
|
|
19
|
+
items: menus,
|
|
20
|
+
defaultActiveKey: defaultActiveKey,
|
|
21
|
+
onSelect: navigate
|
|
22
|
+
}),
|
|
23
|
+
content: /*#__PURE__*/ jsx(Outlet, {})
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
export { Layout };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { App } from './App';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { MenuItem } from '../../components';
|
|
2
|
+
import { RouteObject } from 'react-router-dom';
|
|
3
|
+
export declare const getDefaultActiveKey: (basename: string, menus: MenuItem[]) => string | undefined;
|
|
4
|
+
export declare const createRoutes: (menus: MenuItem[]) => RouteObject[];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { detectActiveMenu } from "../../components/index.js";
|
|
2
|
+
const getDefaultActiveKey = (basename, menus)=>{
|
|
3
|
+
let pathname = window.location.pathname;
|
|
4
|
+
if (pathname.startsWith(`${basename}`)) pathname = pathname.slice(basename.length + 1);
|
|
5
|
+
return detectActiveMenu(pathname, menus);
|
|
6
|
+
};
|
|
7
|
+
const createRoutes = (menus)=>{
|
|
8
|
+
const routes = menus.filter((menu)=>menu?.element).map((menu)=>({
|
|
9
|
+
path: menu.key,
|
|
10
|
+
element: menu.element,
|
|
11
|
+
children: createRoutes(menu?.children ?? [])
|
|
12
|
+
}));
|
|
13
|
+
return routes;
|
|
14
|
+
};
|
|
15
|
+
export { createRoutes, getDefaultActiveKey };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "listpage-next",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.243",
|
|
4
4
|
"description": "A React component library for creating filter forms with Ant Design",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -14,6 +14,10 @@
|
|
|
14
14
|
"types": "./dist/ui/index.d.ts",
|
|
15
15
|
"import": "./dist/ui/index.js"
|
|
16
16
|
},
|
|
17
|
+
"./features/*": {
|
|
18
|
+
"types": "./dist/features/*/index.d.ts",
|
|
19
|
+
"import": "./dist/features/*/index.js"
|
|
20
|
+
},
|
|
17
21
|
"./ui.css": "./dist/ui.css"
|
|
18
22
|
},
|
|
19
23
|
"types": "./dist/index.d.ts",
|