@spacego/fe-components 0.0.1 → 0.0.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.
@@ -1,41 +1,41 @@
1
1
  import { message as o } from "antd";
2
2
  import { redirect as e } from "react-router-dom";
3
3
  function h(i) {
4
- const { getToken: r, setToken: a, removeToken: s } = i;
5
- function u() {
4
+ const { getToken: r, setToken: a, removeToken: u } = i;
5
+ function s() {
6
6
  return { token: r() };
7
7
  }
8
- function m({ request: t }) {
8
+ function l({ request: n }) {
9
9
  if (!r()) {
10
- const n = new URLSearchParams();
11
- return n.set("from", new URL(t.url).pathname), e("/auth/login?" + n.toString());
10
+ const t = new URLSearchParams();
11
+ return t.set("from", new URL(n.url).pathname), e("/auth/login?" + t.toString());
12
12
  }
13
13
  return null;
14
14
  }
15
- async function f() {
15
+ async function m() {
16
16
  return r() ? e("/") : null;
17
17
  }
18
- async function g({ request: t }) {
19
- const c = await t.formData(), n = c.get("token");
20
- if (!n)
21
- return o.warning("You must provide a token to log in");
18
+ async function f({ request: n }) {
19
+ const c = await n.formData(), t = c.get("token");
20
+ if (!t)
21
+ return o.warning("You must provide a token to log in"), null;
22
22
  try {
23
- a(n), o.success("登录成功");
23
+ a(t), o.success("登录成功");
24
24
  } catch {
25
- return o.warning("Invalid login attempt");
25
+ return o.warning("Invalid login attempt"), null;
26
26
  }
27
- const l = c.get("redirectTo");
28
- return e(l || "/");
27
+ const k = c.get("redirectTo");
28
+ return e(k || "/");
29
29
  }
30
- function k() {
31
- return s(), o.success("退出成功"), e("/auth/login");
30
+ function g() {
31
+ return u(), o.success("退出成功"), e("/auth/login");
32
32
  }
33
33
  return {
34
- RootLoader: u,
35
- ProtectedLoader: m,
36
- LoginLoader: f,
37
- LoginAction: g,
38
- LogoutAction: k
34
+ RootLoader: s,
35
+ ProtectedLoader: l,
36
+ LoginLoader: m,
37
+ LoginAction: f,
38
+ LogoutAction: g
39
39
  };
40
40
  }
41
41
  export {
@@ -1,30 +1,26 @@
1
- import { lazy as g } from "react";
2
- function C(o) {
1
+ import { lazy as y, createElement as C } from "react";
2
+ function R(o) {
3
3
  return `/src/pages/${o.replace(/^\/+/, "")}/index.tsx`;
4
4
  }
5
- function R(o, r) {
6
- const d = r[C(o)];
7
- if (!d) {
8
- console.warn(`Module not found for path: ${o}`);
9
- return;
10
- }
11
- return g(d);
5
+ function v(o, i) {
6
+ const d = i[R(o)];
7
+ return d ? y(d) : (console.warn(`Module not found for path: ${o}`), y(() => Promise.resolve({ default: () => C("div", null, `Module not found: ${o}`) })));
12
8
  }
13
9
  function w(o) {
14
10
  if (o)
15
11
  return o.startsWith("/") ? o : `/${o}`;
16
12
  }
17
- function y(o, r) {
18
- return (o.sort ?? 0) - (r.sort ?? 0);
13
+ function T(o, i) {
14
+ return (o.sort ?? 0) - (i.sort ?? 0);
19
15
  }
20
- function E(o, r, d) {
21
- const p = [...o].sort(y).reduce((e, t) => {
16
+ function N(o, i, d) {
17
+ const p = [...o].sort(T).reduce((e, t) => {
22
18
  const n = t.menuType || 2;
23
19
  return e[n] || (e[n] = []), e[n].push(t), e;
24
- }, {}), T = (p[3] || []).filter((e) => e.menuCode).map((e) => e.menuCode), l = [
20
+ }, {}), g = (p[3] || []).filter((e) => e.menuCode).map((e) => e.menuCode), l = [
25
21
  ...p[1] || [],
26
22
  ...p[2] || []
27
- ].sort(y), u = /* @__PURE__ */ new Map(), f = [];
23
+ ].sort(T), c = /* @__PURE__ */ new Map(), f = [];
28
24
  l.forEach((e) => {
29
25
  const t = e.parentId || "/", n = w(e.path), s = {
30
26
  id: e.menuId,
@@ -40,22 +36,22 @@ function E(o, r, d) {
40
36
  }
41
37
  };
42
38
  if (e.menuType === 2 && e.menuCode) {
43
- const i = R(e.menuCode, r);
44
- i && (s.Component = i), e.index && (s.index = !0, delete s.path), e.protected !== !1 && d && (s.loader = d);
39
+ const r = v(e.menuCode, i);
40
+ r && (s.Component = r), e.index && (s.index = !0, delete s.path), e.protected !== !1 && d && (s.loader = d);
45
41
  }
46
- u.set(e.menuId, s);
42
+ c.set(e.menuId, s);
47
43
  }), l.forEach((e) => {
48
- const t = u.get(e.menuId), n = e.parentId;
44
+ const t = c.get(e.menuId), n = e.parentId;
49
45
  if (n && n !== "/") {
50
- const s = u.get(n);
46
+ const s = c.get(n);
51
47
  s ? (s.children || (s.children = []), s.children.push(t)) : f.push(t);
52
48
  } else
53
49
  f.push(t);
54
50
  });
55
- const h = /* @__PURE__ */ new Map(), a = [], I = l.filter((e) => e.isShowMenu !== !1);
51
+ const a = /* @__PURE__ */ new Map(), h = [], I = l.filter((e) => e.isShowMenu !== !1);
56
52
  I.forEach((e) => {
57
- const t = u.get(e.menuId), n = t ? (() => {
58
- const { children: i, ...m } = t;
53
+ const t = c.get(e.menuId), n = t ? (() => {
54
+ const { children: r, ...m } = t;
59
55
  return m;
60
56
  })() : void 0, s = {
61
57
  key: e.menuId,
@@ -65,27 +61,27 @@ function E(o, r, d) {
65
61
  menuType: e.menuType,
66
62
  isIndependentMenu: e.isIndependentMenu
67
63
  };
68
- h.set(e.menuId, s);
64
+ a.set(e.menuId, s);
69
65
  }), I.forEach((e) => {
70
- const t = h.get(e.menuId), n = e.parentId;
66
+ const t = a.get(e.menuId), n = e.parentId;
71
67
  if (n && n !== "/") {
72
- const s = h.get(n);
73
- s ? (s.children || (s.children = []), s.children.push(t)) : a.push(t);
68
+ const s = a.get(n);
69
+ s ? (s.children || (s.children = []), s.children.push(t)) : h.push(t);
74
70
  } else
75
- a.push(t);
71
+ h.push(t);
76
72
  });
77
73
  function M(e) {
78
74
  const t = [];
79
75
  return e.forEach((n) => {
80
76
  if (n.children && n.children.length > 0 && (n.children = M(n.children)), n.menuType === 1 && n.children && n.children.length > 0) {
81
- const s = n.children.filter((i) => i.isIndependentMenu === !0 && i.menuType === 2 && !i.customType);
77
+ const s = n.children.filter((r) => r.isIndependentMenu === !0 && r.menuType === 2 && !r.customType);
82
78
  if (s.length > 0) {
83
- const i = s.map((c) => ({
84
- ...c,
79
+ const r = s.map((u) => ({
80
+ ...u,
85
81
  customType: "menu-promoted"
86
82
  // 内部标识,表示这个菜单是被提升的
87
- })), m = n.children.filter((c) => !(c.isIndependentMenu === !0 && c.menuType === 2 && !c.customType));
88
- t.push(...i, ...m);
83
+ })), m = n.children.filter((u) => !(u.isIndependentMenu === !0 && u.menuType === 2 && !u.customType));
84
+ t.push(...r, ...m);
89
85
  } else
90
86
  t.push(n);
91
87
  } else
@@ -94,12 +90,12 @@ function E(o, r, d) {
94
90
  }
95
91
  return {
96
92
  routes: f,
97
- menus: M(a),
98
- permissions: T
93
+ menus: M(h),
94
+ permissions: g
99
95
  };
100
96
  }
101
97
  export {
102
- R as createLazyComponent,
103
- C as getPath,
104
- E as processRoutes
98
+ v as createLazyComponent,
99
+ R as getPath,
100
+ N as processRoutes
105
101
  };
@@ -25,7 +25,7 @@ export declare function createRouter(options: CreateRouterOptions): {
25
25
  RootLoader: () => import('./permission').AuthStatus;
26
26
  ProtectedLoader: ({ request }: import('react-router-dom').LoaderFunctionArgs) => Response | null;
27
27
  LoginLoader: () => Promise<Response | null>;
28
- LoginAction: ({ request }: import('react-router-dom').LoaderFunctionArgs) => Promise<boolean | Response>;
28
+ LoginAction: ({ request }: import('react-router-dom').LoaderFunctionArgs) => Promise<Response | null>;
29
29
  LogoutAction: () => Response;
30
30
  };
31
31
  };
@@ -18,6 +18,6 @@ export declare function createPermissionHelpers(tokenHelpers: TokenHelpers): {
18
18
  RootLoader: () => AuthStatus;
19
19
  ProtectedLoader: ({ request }: LoaderFunctionArgs) => Response | null;
20
20
  LoginLoader: () => Promise<Response | null>;
21
- LoginAction: ({ request }: LoaderFunctionArgs) => Promise<boolean | Response>;
21
+ LoginAction: ({ request }: LoaderFunctionArgs) => Promise<Response | null>;
22
22
  LogoutAction: () => Response;
23
23
  };
@@ -18,7 +18,7 @@ export declare function getPath(name: string): string;
18
18
  * @param modules
19
19
  * @returns
20
20
  */
21
- export declare function createLazyComponent(name: string, modules: TModule): import('react').LazyExoticComponent<ComponentType<any>> | undefined;
21
+ export declare function createLazyComponent(name: string, modules: TModule): import('react').LazyExoticComponent<ComponentType<any>> | import('react').LazyExoticComponent<() => import('react').DetailedReactHTMLElement<import('react').HTMLAttributes<HTMLElement>, HTMLElement>>;
22
22
  /** 路由节点类型 */
23
23
  type RouteNode = RouteObject & {
24
24
  parentId: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spacego/fe-components",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "🚀 A component library for fe to use.",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",