@vef-framework/starter 1.0.133 → 1.0.135
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/cjs/routes/layout.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
"use strict";var
|
|
2
|
+
"use strict";var o=require("@emotion/react/jsx-runtime"),a=require("@tanstack/react-router"),m=require("@vef-framework/components"),S=require("@vef-framework/core"),_=require("@vef-framework/shared"),w=require("lucide-react"),h=require("react"),p=require("../constants.cjs"),L=require("../helper.cjs"),A=require("../store.cjs");const x={key:p.INDEX_PAGE_PATH,label:o.jsx(m.VefIcon,{children:o.jsx(w.HomeIcon,{})})};function R({title:v,logo:y,getUserDescription:M,userMenuItems:C,onUserMenuClick:P}){function k(){const r=a.useRouter(),n=a.useNavigate(),{pathname:t}=a.useLocation(),[i,s,u]=A.useAppStore(e=>[e.menus,e.user,e.routeParentMenusMappings]),c=u?.get(t)?.[1].map(e=>e.key),E=h.useMemo(()=>{const e=u?.get(t);if(!e)return[];const[q,O]=e;return[x,...O.map(d=>({key:d.key,label:d.label,dropdownItems:d.children.filter(l=>l.type!=="divider").map(l=>({key:l.key,label:l.label}))})),{label:q.label}]},[t,u]),{logoutApi:I,fetchAuthenticatedUserApi:f}=S.useApiContext(),{mutate:g}=I.useMutation(),j=h.useCallback(async()=>{await g(),await L.handleClientLogout(r,f)},[g,r,f]),b=h.useCallback(e=>{n({to:e})},[n]);return o.jsx(m.VefLayout,{activeMenuKey:t,breadcrumbItems:E,defaultOpenedMenuKeys:c,logo:y,menuItems:i,title:v,userAvatar:s?.avatar,userDescription:M?.(s),userGender:s?.gender,userMenuItems:C,userName:s?.name,onActiveMenuKeyChange:b,onBreadcrumbClick:b,onLogout:j,onUserMenuClick:P,children:o.jsx(a.Outlet,{})})}return{beforeLoad:({location:r})=>{const{isAuthenticated:n,routeParentMenusMappings:t}=A.useAppStore.getState();if(!n)throw a.redirect({to:p.LOGIN_PAGE_PATH,search:{redirect:r.href}});if(t&&!t.has(r.pathname))throw a.redirect({to:p.ACCESS_DENIED_PAGE_PATH,replace:!0})},loader:async({context:r,location:n})=>{const{fetchAuthenticatedUserApi:t}=r,{menus:i,permissions:s,...u}=await t.fetchQuery(),c=Object.freeze(_.buildRouteParentMenusMappings(i));if(A.useAppStore.setState({user:Object.freeze(u),menus:Object.freeze(i),permissions:Object.freeze(new Set(s)),routeParentMenusMappings:c}),!c.has(n.pathname))throw a.redirect({to:p.ACCESS_DENIED_PAGE_PATH,replace:!0})},pendingComponent:()=>o.jsx(m.VefLoadingPlaceholder,{size:"large",tip:"系统加载中,请稍后..."}),component:k,staleTime:1/0,gcTime:0,shouldReload:!1}}exports.createLayoutRouteOptions=R;
|
package/esm/routes/layout.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import{jsx as i}from"@emotion/react/jsx-runtime";import{useRouter as
|
|
2
|
+
import{jsx as i}from"@emotion/react/jsx-runtime";import{useRouter as E,useNavigate as _,useLocation as S,Outlet as j,redirect as l}from"@tanstack/react-router";import{VefIcon as z,VefLayout as D,VefLoadingPlaceholder as G}from"@vef-framework/components";import{useApiContext as N}from"@vef-framework/core";import{buildRouteParentMenusMappings as T}from"@vef-framework/shared";import{HomeIcon as U}from"lucide-react";import{useMemo as x,useCallback as g}from"react";import{INDEX_PAGE_PATH as H,ACCESS_DENIED_PAGE_PATH as b,LOGIN_PAGE_PATH as K}from"../constants.js";import{handleClientLogout as R}from"../helper.js";import{useAppStore as p}from"../store.js";const V={key:H,label:i(z,{children:i(U,{})})};function B({title:A,logo:M,getUserDescription:y,userMenuItems:P,onUserMenuClick:k}){function C(){const r=E(),o=_(),{pathname:t}=S(),[s,n,a]=p(e=>[e.menus,e.user,e.routeParentMenusMappings]),u=a?.get(t)?.[1].map(e=>e.key),I=x(()=>{const e=a?.get(t);if(!e)return[];const[L,v]=e;return[V,...v.map(c=>({key:c.key,label:c.label,dropdownItems:c.children.filter(m=>m.type!=="divider").map(m=>({key:m.key,label:m.label}))})),{label:L.label}]},[t,a]),{logoutApi:w,fetchAuthenticatedUserApi:f}=N(),{mutate:d}=w.useMutation(),O=g(async()=>{await d(),await R(r,f)},[d,r,f]),h=g(e=>{o({to:e})},[o]);return i(D,{activeMenuKey:t,breadcrumbItems:I,defaultOpenedMenuKeys:u,logo:M,menuItems:s,title:A,userAvatar:n?.avatar,userDescription:y?.(n),userGender:n?.gender,userMenuItems:P,userName:n?.name,onActiveMenuKeyChange:h,onBreadcrumbClick:h,onLogout:O,onUserMenuClick:k,children:i(j,{})})}return{beforeLoad:({location:r})=>{const{isAuthenticated:o,routeParentMenusMappings:t}=p.getState();if(!o)throw l({to:K,search:{redirect:r.href}});if(t&&!t.has(r.pathname))throw l({to:b,replace:!0})},loader:async({context:r,location:o})=>{const{fetchAuthenticatedUserApi:t}=r,{menus:s,permissions:n,...a}=await t.fetchQuery(),u=Object.freeze(T(s));if(p.setState({user:Object.freeze(a),menus:Object.freeze(s),permissions:Object.freeze(new Set(n)),routeParentMenusMappings:u}),!u.has(o.pathname))throw l({to:b,replace:!0})},pendingComponent:()=>i(G,{size:"large",tip:"系统加载中,请稍后..."}),component:C,staleTime:1/0,gcTime:0,shouldReload:!1}}export{B as createLayoutRouteOptions};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vef-framework/starter",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.135",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "The starter of the VEF framework",
|
|
7
7
|
"author": "Venus",
|
|
@@ -32,10 +32,10 @@
|
|
|
32
32
|
"use-sync-external-store": "^1.5.0",
|
|
33
33
|
"@tanstack/react-query-devtools": "5.74.3",
|
|
34
34
|
"@tanstack/router-devtools": "^1.116.0",
|
|
35
|
-
"@vef-framework/components": "1.0.
|
|
36
|
-
"@vef-framework/core": "1.0.
|
|
37
|
-
"@vef-framework/hooks": "1.0.
|
|
38
|
-
"@vef-framework/shared": "1.0.
|
|
35
|
+
"@vef-framework/components": "1.0.135",
|
|
36
|
+
"@vef-framework/core": "1.0.135",
|
|
37
|
+
"@vef-framework/hooks": "1.0.135",
|
|
38
|
+
"@vef-framework/shared": "1.0.135",
|
|
39
39
|
"lucide-react": "0.488.0",
|
|
40
40
|
"motion": "12.7.3",
|
|
41
41
|
"nprogress": "^0.2.0"
|
package/types/routes/layout.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { AppState } from "../store";
|
|
|
6
6
|
/**
|
|
7
7
|
* The options for the layout route.
|
|
8
8
|
*/
|
|
9
|
-
export interface LayoutOptions extends Pick<VefLayoutProps, "title" | "logo"> {
|
|
9
|
+
export interface LayoutOptions extends Pick<VefLayoutProps, "title" | "logo" | "userMenuItems" | "onUserMenuClick"> {
|
|
10
10
|
/**
|
|
11
11
|
* The user description mapper.
|
|
12
12
|
*/
|
|
@@ -17,7 +17,7 @@ export interface LayoutOptions extends Pick<VefLayoutProps, "title" | "logo"> {
|
|
|
17
17
|
*
|
|
18
18
|
* @returns The options for the layout route.
|
|
19
19
|
*/
|
|
20
|
-
export declare function createLayoutRouteOptions({ title, logo, getUserDescription, }: LayoutOptions): {
|
|
20
|
+
export declare function createLayoutRouteOptions({ title, logo, getUserDescription, userMenuItems, onUserMenuClick, }: LayoutOptions): {
|
|
21
21
|
readonly beforeLoad: ({ location }: {
|
|
22
22
|
location: ParsedLocation;
|
|
23
23
|
}) => void;
|