@e7w/easy-routes 0.0.8 → 0.0.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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # 自用React-router配置
2
2
 
3
- /src/pages/\*\*/page.tsx为页面
3
+ src/\*\*/pages/\*\*/page.tsx为页面
4
4
 
5
5
  ```ts
6
6
  export function Page() {}
@@ -8,7 +8,7 @@ export function Page() {}
8
8
 
9
9
  ---
10
10
 
11
- /src/pages/\*\*/layout.tsx为layout
11
+ src/\*\*/pages/\*\*/layout.tsx为layout
12
12
 
13
13
  ```ts
14
14
  export function Layout() {
@@ -18,7 +18,7 @@ export function Layout() {
18
18
 
19
19
  ---
20
20
 
21
- /src/pages/\*\*/meta.ts配置如下
21
+ src/\*\*/pages/\*\*/meta.ts配置如下
22
22
 
23
23
  ```ts
24
24
  export const permission: number = 0b0; // 默认是0b0代表需要登录,只有最右边的一位代表登录,其他位可以自己定enum代表权限
@@ -8,7 +8,6 @@ interface RouterSchema {
8
8
  export declare const RouterSchema: z.ZodType<RouterSchema, RouterSchema>;
9
9
  export declare const system: {
10
10
  router: RouterSchema;
11
- ready: boolean;
12
11
  init(req: Ctx["req"], meta: Meta): Promise<void>;
13
12
  hasPermission(permission?: number): boolean;
14
13
  getCtx(req: Ctx["req"], permission?: number): Ctx;
@@ -79,6 +79,7 @@ export var RouterSchema = z.object({
79
79
  });
80
80
  export var system = provide((function () {
81
81
  var _a;
82
+ var _b;
82
83
  var _instanceExtraInitializers = [];
83
84
  var _router_decorators;
84
85
  var _router_initializers = [];
@@ -96,12 +97,7 @@ export var system = provide((function () {
96
97
  defaultTitle: document.title,
97
98
  }))
98
99
  });
99
- Object.defineProperty(this, "ready", {
100
- enumerable: true,
101
- configurable: true,
102
- writable: true,
103
- value: (__runInitializers(this, _router_extraInitializers), false)
104
- });
100
+ __runInitializers(this, _router_extraInitializers);
105
101
  }
106
102
  Object.defineProperty(System.prototype, "init", {
107
103
  enumerable: false,
@@ -114,7 +110,6 @@ export var system = provide((function () {
114
110
  case 0: return [4 /*yield*/, this.router.init(req, meta)];
115
111
  case 1:
116
112
  _b.sent();
117
- this.ready = true;
118
113
  return [2 /*return*/];
119
114
  }
120
115
  });
@@ -149,7 +144,7 @@ export var system = provide((function () {
149
144
  (function () {
150
145
  var _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
151
146
  _router_decorators = [inject(RouterSchema)];
152
- _init_decorators = [loader.load(true)];
147
+ _init_decorators = [(_b = loader).once.bind(_b), loader.load(true)];
153
148
  __esDecorate(_a, null, _init_decorators, { kind: "method", name: "init", static: false, private: false, access: { has: function (obj) { return "init" in obj; }, get: function (obj) { return obj.init; } }, metadata: _metadata }, null, _instanceExtraInitializers);
154
149
  __esDecorate(null, null, _router_decorators, { kind: "field", name: "router", static: false, private: false, access: { has: function (obj) { return "router" in obj; }, get: function (obj) { return obj.router; }, set: function (obj, value) { obj.router = value; } }, metadata: _metadata }, _router_initializers, _router_extraInitializers);
155
150
  if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
package/dist/router.js CHANGED
@@ -51,15 +51,15 @@ import { DefaultOutlet } from "./components/DefaultOutlet";
51
51
  import { ErrorBoundary } from "./components/ErrorBoundary";
52
52
  import { ProgressLayout } from "./components/ProgressLayout";
53
53
  import { system } from "./models/system";
54
- var pages = import.meta.glob("/src/pages/**/index.tsx", {
54
+ var pages = import.meta.glob("/src/**/pages/**/index.tsx", {
55
55
  eager: true,
56
56
  import: "Page",
57
57
  });
58
- var layouts = import.meta.glob("/src/pages/**/layout.tsx", {
58
+ var layouts = import.meta.glob("/src/**/pages/**/layout.tsx", {
59
59
  eager: true,
60
60
  import: "Layout",
61
61
  });
62
- var metas = import.meta.glob("/src/pages/**/meta.ts", {
62
+ var metas = import.meta.glob("/src/**/pages/**/meta.ts", {
63
63
  eager: true,
64
64
  });
65
65
  var routes = [];
@@ -95,20 +95,16 @@ filePaths.forEach(function (filePath) {
95
95
  req = {
96
96
  params: params,
97
97
  query: Object.fromEntries(url.searchParams),
98
- pathname: url.pathname.replace(/\/$/, ""),
98
+ pathname: url.pathname.replace(/\/?$/, "/"),
99
99
  };
100
- if (!!system.ready) return [3 /*break*/, 2];
101
100
  return [4 /*yield*/, ((_d = (_c = system.init(req, meta)) === null || _c === void 0 ? void 0 : _c.catch) === null || _d === void 0 ? void 0 : _d.call(_c, function () { }))];
102
101
  case 1:
103
102
  _h.sent();
104
- _h.label = 2;
105
- case 2:
106
103
  ctx = system.getCtx(req, meta.permission);
107
104
  return [4 /*yield*/, ((_g = (_f = (_e = meta.loader) === null || _e === void 0 ? void 0 : _e.call(meta, ctx)) === null || _f === void 0 ? void 0 : _f.catch) === null || _g === void 0 ? void 0 : _g.call(_f, function () { }))];
108
- case 3:
105
+ case 2:
109
106
  _h.sent();
110
107
  if (!ctx.signed) {
111
- system.ready = false;
112
108
  return [2 /*return*/, redirect("/login?from=".concat(encodeURIComponent(request.url)))];
113
109
  }
114
110
  if (ctx.noPermission)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e7w/easy-routes",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "registry": "https://registry.npmjs.org/"
@@ -10,6 +10,10 @@
10
10
  "types": "./dist/index.d.ts",
11
11
  "import": "./dist/index.js"
12
12
  },
13
+ "scripts": {
14
+ "build": "tsc --build && copyfiles -u 1 src/**/*.css dist/",
15
+ "lint": "eslint ."
16
+ },
13
17
  "dependencies": {
14
18
  "@e7w/easy-model": "^0.2.1",
15
19
  "nprogress": "^0.2.0",
@@ -40,9 +44,5 @@
40
44
  "README.md",
41
45
  "LICENSE.md"
42
46
  ],
43
- "license": "MIT",
44
- "scripts": {
45
- "build": "tsc --build && copyfiles -u 1 src/**/*.css dist/",
46
- "lint": "eslint ."
47
- }
47
+ "license": "MIT"
48
48
  }