@e7w/easy-routes 0.1.7 → 0.1.9
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/index.d.mts +8 -1
- package/dist/index.mjs +58 -152
- package/dist/style.css +267 -637
- package/package.json +5 -1
package/dist/index.d.mts
CHANGED
|
@@ -19,8 +19,15 @@ declare abstract class Permission {
|
|
|
19
19
|
abstract init(req: Ctx["req"]): Promise<void> | void;
|
|
20
20
|
}
|
|
21
21
|
declare const PermissionSchema: z.ZodType<Permission, Permission>;
|
|
22
|
+
type Menu = {
|
|
23
|
+
name: string;
|
|
24
|
+
icon?: string;
|
|
25
|
+
path: string;
|
|
26
|
+
children?: Menu[];
|
|
27
|
+
};
|
|
22
28
|
//#endregion
|
|
23
29
|
//#region src/router.d.ts
|
|
24
30
|
declare const routes: RouteObject[];
|
|
31
|
+
declare const menu: Menu;
|
|
25
32
|
//#endregion
|
|
26
|
-
export { type Ctx, Permission, PermissionSchema, routes };
|
|
33
|
+
export { type Ctx, Permission, PermissionSchema, menu, routes };
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import z from "zod";
|
|
2
2
|
import { Navigate, Outlet, isRouteErrorResponse, redirect, useNavigation, useRouteError } from "react-router";
|
|
3
|
-
import { c } from "react/compiler-runtime";
|
|
4
3
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
4
|
import { useEffect, useRef, useState } from "react";
|
|
6
5
|
import nProgress from "nprogress";
|
|
@@ -18,147 +17,72 @@ const PermissionSchema = z.object({
|
|
|
18
17
|
}).describe("权限");
|
|
19
18
|
//#endregion
|
|
20
19
|
//#region src/components/DefaultOutlet.tsx
|
|
21
|
-
const DefaultOutlet = () => {
|
|
22
|
-
const $ = c(2);
|
|
23
|
-
if ($[0] !== "86245ef798e2727374ee553b08ad2562f91d79b38190dfff1bf2e15388787321") {
|
|
24
|
-
for (let $i = 0; $i < 2; $i += 1) $[$i] = Symbol.for("react.memo_cache_sentinel");
|
|
25
|
-
$[0] = "86245ef798e2727374ee553b08ad2562f91d79b38190dfff1bf2e15388787321";
|
|
26
|
-
}
|
|
27
|
-
let t0;
|
|
28
|
-
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
|
|
29
|
-
t0 = /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(Outlet, {}) });
|
|
30
|
-
$[1] = t0;
|
|
31
|
-
} else t0 = $[1];
|
|
32
|
-
return t0;
|
|
33
|
-
};
|
|
20
|
+
const DefaultOutlet = () => /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(Outlet, {}) });
|
|
34
21
|
//#endregion
|
|
35
22
|
//#region src/components/ErrorBoundary.tsx
|
|
36
23
|
const ErrorBoundary = () => {
|
|
37
|
-
const $ = c(10);
|
|
38
|
-
if ($[0] !== "c0519d7cbaee7b0126a2e952b78b40bd9558a23ee78ea987eb3dcf5c9585862b") {
|
|
39
|
-
for (let $i = 0; $i < 10; $i += 1) $[$i] = Symbol.for("react.memo_cache_sentinel");
|
|
40
|
-
$[0] = "c0519d7cbaee7b0126a2e952b78b40bd9558a23ee78ea987eb3dcf5c9585862b";
|
|
41
|
-
}
|
|
42
24
|
const error = useRouteError();
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
className: "text-2xl font-bold mb-4",
|
|
48
|
-
children: "Error"
|
|
49
|
-
});
|
|
50
|
-
t1 = /* @__PURE__ */ jsx("p", { children: "Something went wrong." });
|
|
51
|
-
$[1] = t0;
|
|
52
|
-
$[2] = t1;
|
|
53
|
-
} else {
|
|
54
|
-
t0 = $[1];
|
|
55
|
-
t1 = $[2];
|
|
56
|
-
}
|
|
57
|
-
let t2;
|
|
58
|
-
if ($[3] !== error) {
|
|
59
|
-
t2 = isRouteErrorResponse(error) && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("p", {
|
|
60
|
-
className: "text-red-300",
|
|
25
|
+
return /* @__PURE__ */ jsx("div", {
|
|
26
|
+
className: "flex h-screen w-full items-center justify-center",
|
|
27
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
28
|
+
className: "flex flex-col items-center justify-center",
|
|
61
29
|
children: [
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
30
|
+
/* @__PURE__ */ jsx("h1", {
|
|
31
|
+
className: "text-2xl font-bold mb-4",
|
|
32
|
+
children: "Error"
|
|
33
|
+
}),
|
|
34
|
+
/* @__PURE__ */ jsx("p", { children: "Something went wrong." }),
|
|
35
|
+
isRouteErrorResponse(error) && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("p", {
|
|
36
|
+
className: "text-red-300",
|
|
37
|
+
children: [
|
|
38
|
+
error.status,
|
|
39
|
+
" ",
|
|
40
|
+
error.statusText
|
|
41
|
+
]
|
|
42
|
+
}), /* @__PURE__ */ jsx("p", {
|
|
43
|
+
className: "text-red-300",
|
|
44
|
+
children: JSON.stringify(error.data)
|
|
45
|
+
})] }),
|
|
46
|
+
error instanceof Error && /* @__PURE__ */ jsx("p", {
|
|
47
|
+
className: "text-red-300",
|
|
48
|
+
children: error.message
|
|
49
|
+
})
|
|
65
50
|
]
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
children: JSON.stringify(error.data)
|
|
69
|
-
})] });
|
|
70
|
-
$[3] = error;
|
|
71
|
-
$[4] = t2;
|
|
72
|
-
} else t2 = $[4];
|
|
73
|
-
let t3;
|
|
74
|
-
if ($[5] !== error) {
|
|
75
|
-
t3 = error instanceof Error && /* @__PURE__ */ jsx("p", {
|
|
76
|
-
className: "text-red-300",
|
|
77
|
-
children: error.message
|
|
78
|
-
});
|
|
79
|
-
$[5] = error;
|
|
80
|
-
$[6] = t3;
|
|
81
|
-
} else t3 = $[6];
|
|
82
|
-
let t4;
|
|
83
|
-
if ($[7] !== t2 || $[8] !== t3) {
|
|
84
|
-
t4 = /* @__PURE__ */ jsx("div", {
|
|
85
|
-
className: "flex h-screen w-full items-center justify-center",
|
|
86
|
-
children: /* @__PURE__ */ jsxs("div", {
|
|
87
|
-
className: "flex flex-col items-center justify-center",
|
|
88
|
-
children: [
|
|
89
|
-
t0,
|
|
90
|
-
t1,
|
|
91
|
-
t2,
|
|
92
|
-
t3
|
|
93
|
-
]
|
|
94
|
-
})
|
|
95
|
-
});
|
|
96
|
-
$[7] = t2;
|
|
97
|
-
$[8] = t3;
|
|
98
|
-
$[9] = t4;
|
|
99
|
-
} else t4 = $[9];
|
|
100
|
-
return t4;
|
|
51
|
+
})
|
|
52
|
+
});
|
|
101
53
|
};
|
|
102
54
|
//#endregion
|
|
103
55
|
//#region src/utils/hooks.ts
|
|
104
56
|
function useDebouncedValue(value) {
|
|
105
|
-
const $ = c(6);
|
|
106
|
-
if ($[0] !== "cafc571037d3460a1577637e6ed6134f48e275412c9fbdd1e3259d6b7886985f") {
|
|
107
|
-
for (let $i = 0; $i < 6; $i += 1) $[$i] = Symbol.for("react.memo_cache_sentinel");
|
|
108
|
-
$[0] = "cafc571037d3460a1577637e6ed6134f48e275412c9fbdd1e3259d6b7886985f";
|
|
109
|
-
}
|
|
110
57
|
const [result, setResult] = useState(value);
|
|
111
58
|
const timer = useRef(void 0);
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
return () => {
|
|
120
|
-
window.clearTimeout(timer.current);
|
|
121
|
-
};
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
clearTimeout(timer.current);
|
|
61
|
+
timer.current = window.setTimeout(() => {
|
|
62
|
+
setResult(value);
|
|
63
|
+
}, 700);
|
|
64
|
+
return () => {
|
|
65
|
+
window.clearTimeout(timer.current);
|
|
122
66
|
};
|
|
123
|
-
|
|
124
|
-
$[2] = t0;
|
|
125
|
-
} else t0 = $[2];
|
|
126
|
-
let t1;
|
|
127
|
-
if ($[3] !== result || $[4] !== value) {
|
|
128
|
-
t1 = [result, value];
|
|
129
|
-
$[3] = result;
|
|
130
|
-
$[4] = value;
|
|
131
|
-
$[5] = t1;
|
|
132
|
-
} else t1 = $[5];
|
|
133
|
-
useEffect(t0, t1);
|
|
67
|
+
}, [result, value]);
|
|
134
68
|
return result;
|
|
135
69
|
}
|
|
136
70
|
//#endregion
|
|
137
71
|
//#region src/components/Loading.tsx
|
|
138
72
|
const Loading = () => {
|
|
139
|
-
const $ = c(2);
|
|
140
|
-
if ($[0] !== "9ba59b6b2e9bf36d0d2119a54dc7f29c23de32230207b1503967b02ba51f79d2") {
|
|
141
|
-
for (let $i = 0; $i < 2; $i += 1) $[$i] = Symbol.for("react.memo_cache_sentinel");
|
|
142
|
-
$[0] = "9ba59b6b2e9bf36d0d2119a54dc7f29c23de32230207b1503967b02ba51f79d2";
|
|
143
|
-
}
|
|
144
73
|
const { isGlobalLoading } = useLoader();
|
|
145
74
|
if (!useDebouncedValue(isGlobalLoading)) return;
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
className: "
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
]
|
|
158
|
-
});
|
|
159
|
-
$[1] = t0;
|
|
160
|
-
} else t0 = $[1];
|
|
161
|
-
return t0;
|
|
75
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
76
|
+
className: "spinner-box",
|
|
77
|
+
children: [
|
|
78
|
+
/* @__PURE__ */ jsx("div", { className: "blue-orbit leo" }),
|
|
79
|
+
/* @__PURE__ */ jsx("div", { className: "green-orbit leo" }),
|
|
80
|
+
/* @__PURE__ */ jsx("div", { className: "red-orbit leo" }),
|
|
81
|
+
/* @__PURE__ */ jsx("div", { className: "white-orbit w1 leo" }),
|
|
82
|
+
/* @__PURE__ */ jsx("div", { className: "white-orbit w2 leo" }),
|
|
83
|
+
/* @__PURE__ */ jsx("div", { className: "white-orbit w3 leo" })
|
|
84
|
+
]
|
|
85
|
+
});
|
|
162
86
|
};
|
|
163
87
|
//#endregion
|
|
164
88
|
//#region src/components/ProgressLayout.tsx
|
|
@@ -170,34 +94,12 @@ nProgress.configure({
|
|
|
170
94
|
trickleSpeed: 200
|
|
171
95
|
});
|
|
172
96
|
const ProgressLayout = () => {
|
|
173
|
-
const $ = c(5);
|
|
174
|
-
if ($[0] !== "de22e6cf6e3aceb20c6d7925d182a0e90b0719d98cf1e99dbf79a6686dd7cae1") {
|
|
175
|
-
for (let $i = 0; $i < 5; $i += 1) $[$i] = Symbol.for("react.memo_cache_sentinel");
|
|
176
|
-
$[0] = "de22e6cf6e3aceb20c6d7925d182a0e90b0719d98cf1e99dbf79a6686dd7cae1";
|
|
177
|
-
}
|
|
178
97
|
const { state } = useNavigation();
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
else nProgress.done();
|
|
185
|
-
};
|
|
186
|
-
t1 = [state];
|
|
187
|
-
$[1] = state;
|
|
188
|
-
$[2] = t0;
|
|
189
|
-
$[3] = t1;
|
|
190
|
-
} else {
|
|
191
|
-
t0 = $[2];
|
|
192
|
-
t1 = $[3];
|
|
193
|
-
}
|
|
194
|
-
useEffect(t0, t1);
|
|
195
|
-
let t2;
|
|
196
|
-
if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
|
|
197
|
-
t2 = /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Outlet, {}), /* @__PURE__ */ jsx(Loading, {})] });
|
|
198
|
-
$[4] = t2;
|
|
199
|
-
} else t2 = $[4];
|
|
200
|
-
return t2;
|
|
98
|
+
useEffect(() => {
|
|
99
|
+
if (state === "loading") nProgress.start();
|
|
100
|
+
else nProgress.done();
|
|
101
|
+
}, [state]);
|
|
102
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Outlet, {}), /* @__PURE__ */ jsx(Loading, {})] });
|
|
201
103
|
};
|
|
202
104
|
//#endregion
|
|
203
105
|
//#region src/models/system.ts
|
|
@@ -409,7 +311,11 @@ filePaths.forEach((filePath) => {
|
|
|
409
311
|
query: Object.fromEntries(url.searchParams),
|
|
410
312
|
pathname: url.pathname.replace(/\/?$/, "/")
|
|
411
313
|
};
|
|
412
|
-
|
|
314
|
+
try {
|
|
315
|
+
await system.init(req);
|
|
316
|
+
} catch (error) {
|
|
317
|
+
console.error(error);
|
|
318
|
+
}
|
|
413
319
|
const ctx = system.getCtx(req, meta.permission);
|
|
414
320
|
try {
|
|
415
321
|
await meta.loader?.(ctx);
|
|
@@ -470,6 +376,6 @@ routes.push({
|
|
|
470
376
|
replace: true
|
|
471
377
|
})
|
|
472
378
|
});
|
|
473
|
-
menuObj["/"];
|
|
379
|
+
const menu = menuObj["/"];
|
|
474
380
|
//#endregion
|
|
475
|
-
export { Permission, PermissionSchema, routes };
|
|
381
|
+
export { Permission, PermissionSchema, menu, routes };
|