@praxisjs/router 0.1.1 → 0.2.1
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/CHANGELOG.md +30 -0
- package/dist/components/link.d.ts +5 -2
- package/dist/components/link.d.ts.map +1 -1
- package/dist/components/link.js +69 -12
- package/dist/components/link.js.map +1 -1
- package/dist/components/router-view.d.ts +4 -2
- package/dist/components/router-view.d.ts.map +1 -1
- package/dist/components/router-view.js +62 -7
- package/dist/components/router-view.js.map +1 -1
- package/dist/decorators.d.ts +1 -1
- package/dist/decorators.d.ts.map +1 -1
- package/dist/decorators.js +2 -4
- package/dist/decorators.js.map +1 -1
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +13 -5
- package/dist/router.js.map +1 -1
- package/package.json +5 -4
- package/src/components/link.tsx +35 -30
- package/src/components/router-view.tsx +15 -11
- package/src/decorators.ts +2 -4
- package/src/router.ts +3 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# @praxisjs/router
|
|
2
2
|
|
|
3
|
+
## 0.2.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [f52354d]
|
|
8
|
+
- @praxisjs/decorators@0.4.0
|
|
9
|
+
- @praxisjs/core@0.4.0
|
|
10
|
+
- @praxisjs/jsx@0.2.1
|
|
11
|
+
|
|
12
|
+
## 0.2.0
|
|
13
|
+
|
|
14
|
+
### Minor Changes
|
|
15
|
+
|
|
16
|
+
- bb0d4f8: **Refactor decorator system and component architecture across PraxisJS packages**
|
|
17
|
+
|
|
18
|
+
- Replaced legacy decorator signatures (`constructor`, `target`, `propertyKey`, method descriptor) with the standard TC39 decorator context API (`ClassDecoratorContext`, `ClassFieldDecoratorContext`, `ClassMethodDecoratorContext`) across `@praxisjs/decorators`, `@praxisjs/store`, `@praxisjs/concurrent`, `@praxisjs/router`, `@praxisjs/motion`, `@praxisjs/di`, and `@praxisjs/fsm`.
|
|
19
|
+
- Introduced `StatefulComponent` and `StatelessComponent` as the new base classes, replacing the deprecated `BaseComponent`/`Function Component` pattern, across `@praxisjs/core`, `@praxisjs/runtime`, `@praxisjs/devtools`, and templates.
|
|
20
|
+
- Implemented core rendering functionality in `@praxisjs/runtime` (`mountChildren`, `mountComponent`, reactive scope management) and removed the deprecated `renderer.ts`.
|
|
21
|
+
- Refactored `@praxisjs/jsx` to delegate rendering to `@praxisjs/runtime` and improved type safety with `flattenChildren` and `isComponent` utilities.
|
|
22
|
+
- Updated internal module structure with new `internal` exports in `package.json` files for shared utilities and types.
|
|
23
|
+
- Removed `experimentalDecorators`/`emitDecoratorMetadata` from `tsconfig.json` in favor of native decorator support.
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- Updated dependencies [bb0d4f8]
|
|
28
|
+
- @praxisjs/decorators@0.3.0
|
|
29
|
+
- @praxisjs/core@0.3.0
|
|
30
|
+
- @praxisjs/jsx@0.2.0
|
|
31
|
+
- @praxisjs/shared@0.2.0
|
|
32
|
+
|
|
3
33
|
## 0.1.1
|
|
4
34
|
|
|
5
35
|
### Patch Changes
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { StatelessComponent } from "@praxisjs/core";
|
|
2
|
+
import type { Children } from "@praxisjs/shared";
|
|
2
3
|
interface LinkProps {
|
|
3
4
|
to: string;
|
|
4
5
|
replace?: boolean;
|
|
@@ -6,6 +7,8 @@ interface LinkProps {
|
|
|
6
7
|
activeClass?: string;
|
|
7
8
|
children?: Children | Children[];
|
|
8
9
|
}
|
|
9
|
-
export declare
|
|
10
|
+
export declare class Link extends StatelessComponent<LinkProps> {
|
|
11
|
+
render(): import("@praxisjs/jsx/jsx-runtime").JSX.Element;
|
|
12
|
+
}
|
|
10
13
|
export {};
|
|
11
14
|
//# sourceMappingURL=link.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../../src/components/link.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../../src/components/link.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAIjD,UAAU,SAAS;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,QAAQ,GAAG,QAAQ,EAAE,CAAC;CAClC;AAED,qBACa,IAAK,SAAQ,kBAAkB,CAAC,SAAS,CAAC;IACrD,MAAM;CAiCP"}
|
package/dist/components/link.js
CHANGED
|
@@ -1,18 +1,75 @@
|
|
|
1
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
2
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
3
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
4
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
5
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
6
|
+
var _, done = false;
|
|
7
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
8
|
+
var context = {};
|
|
9
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
10
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
11
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
12
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
13
|
+
if (kind === "accessor") {
|
|
14
|
+
if (result === void 0) continue;
|
|
15
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
16
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
17
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
18
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
19
|
+
}
|
|
20
|
+
else if (_ = accept(result)) {
|
|
21
|
+
if (kind === "field") initializers.unshift(_);
|
|
22
|
+
else descriptor[key] = _;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
26
|
+
done = true;
|
|
27
|
+
};
|
|
28
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
29
|
+
var useValue = arguments.length > 2;
|
|
30
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
31
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
32
|
+
}
|
|
33
|
+
return useValue ? value : void 0;
|
|
34
|
+
};
|
|
1
35
|
import { jsx as _jsx } from "@praxisjs/jsx/jsx-runtime";
|
|
2
|
-
import {
|
|
36
|
+
import { StatelessComponent } from "@praxisjs/core";
|
|
37
|
+
import { Component } from "@praxisjs/decorators";
|
|
3
38
|
import { useRouter } from "../router";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
39
|
+
let Link = (() => {
|
|
40
|
+
let _classDecorators = [Component()];
|
|
41
|
+
let _classDescriptor;
|
|
42
|
+
let _classExtraInitializers = [];
|
|
43
|
+
let _classThis;
|
|
44
|
+
let _classSuper = StatelessComponent;
|
|
45
|
+
var Link = class extends _classSuper {
|
|
46
|
+
static { _classThis = this; }
|
|
47
|
+
static {
|
|
48
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
49
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
50
|
+
Link = _classThis = _classDescriptor.value;
|
|
51
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
52
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
11
53
|
}
|
|
12
|
-
|
|
13
|
-
|
|
54
|
+
render() {
|
|
55
|
+
const { to, replace = false, class: cls = "", activeClass = "active", children, } = this.props;
|
|
56
|
+
const router = useRouter();
|
|
57
|
+
const handleClick = (e) => {
|
|
58
|
+
e.preventDefault();
|
|
59
|
+
if (replace) {
|
|
60
|
+
void router.replace(to);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
void router.push(to);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
return (_jsx("a", { href: to, class: () => {
|
|
67
|
+
const isActive = router.location().path === to;
|
|
68
|
+
return [cls, isActive ? activeClass : ""].filter(Boolean).join(" ");
|
|
69
|
+
}, onClick: handleClick, children: children }));
|
|
14
70
|
}
|
|
15
71
|
};
|
|
16
|
-
return
|
|
17
|
-
}
|
|
72
|
+
return Link = _classThis;
|
|
73
|
+
})();
|
|
74
|
+
export { Link };
|
|
18
75
|
//# sourceMappingURL=link.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link.js","sourceRoot":"","sources":["../../src/components/link.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"link.js","sourceRoot":"","sources":["../../src/components/link.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGjD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;IAWzB,IAAI;4BADhB,SAAS,EAAE;;;;sBACc,kBAAkB;oBAA1B,SAAQ,WAA6B;;;;YAAvD,6KAkCC;;;YAlCY,uDAAI;;QACf,MAAM;YACJ,MAAM,EACJ,EAAE,EACF,OAAO,GAAG,KAAK,EACf,KAAK,EAAE,GAAG,GAAG,EAAE,EACf,WAAW,GAAG,QAAQ,EACtB,QAAQ,GACT,GAAG,IAAI,CAAC,KAAK,CAAC;YAEf,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;YAE3B,MAAM,WAAW,GAAG,CAAC,CAAa,EAAE,EAAE;gBACpC,CAAC,CAAC,cAAc,EAAE,CAAC;gBACnB,IAAI,OAAO,EAAE,CAAC;oBACZ,KAAK,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;gBAC1B,CAAC;qBAAM,CAAC;oBACN,KAAK,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;gBACvB,CAAC;YACH,CAAC,CAAC;YAEF,OAAO,CACL,YACE,IAAI,EAAE,EAAE,EACR,KAAK,EAAE,GAAG,EAAE;oBACV,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC;oBAC/C,OAAO,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;gBACtE,CAAC,EACD,OAAO,EAAE,WAAW,YAEnB,QAAQ,GACP,CACL,CAAC;QACJ,CAAC;;;;SAjCU,IAAI"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
export declare
|
|
1
|
+
import { StatelessComponent } from "@praxisjs/core";
|
|
2
|
+
export declare class RouterView extends StatelessComponent {
|
|
3
|
+
render(): import("@praxisjs/jsx/jsx-runtime").JSX.Element;
|
|
4
|
+
}
|
|
3
5
|
//# sourceMappingURL=router-view.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router-view.d.ts","sourceRoot":"","sources":["../../src/components/router-view.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"router-view.d.ts","sourceRoot":"","sources":["../../src/components/router-view.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAKpD,qBACa,UAAW,SAAQ,kBAAkB;IAChD,MAAM;CAYP"}
|
|
@@ -1,10 +1,65 @@
|
|
|
1
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
2
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
3
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
4
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
5
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
6
|
+
var _, done = false;
|
|
7
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
8
|
+
var context = {};
|
|
9
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
10
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
11
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
12
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
13
|
+
if (kind === "accessor") {
|
|
14
|
+
if (result === void 0) continue;
|
|
15
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
16
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
17
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
18
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
19
|
+
}
|
|
20
|
+
else if (_ = accept(result)) {
|
|
21
|
+
if (kind === "field") initializers.unshift(_);
|
|
22
|
+
else descriptor[key] = _;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
26
|
+
done = true;
|
|
27
|
+
};
|
|
28
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
29
|
+
var useValue = arguments.length > 2;
|
|
30
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
31
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
32
|
+
}
|
|
33
|
+
return useValue ? value : void 0;
|
|
34
|
+
};
|
|
1
35
|
import { jsx as _jsx } from "@praxisjs/jsx/jsx-runtime";
|
|
36
|
+
import { StatelessComponent } from "@praxisjs/core";
|
|
37
|
+
import { Component } from "@praxisjs/decorators";
|
|
2
38
|
import { useRouter } from "../router";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
39
|
+
let RouterView = (() => {
|
|
40
|
+
let _classDecorators = [Component()];
|
|
41
|
+
let _classDescriptor;
|
|
42
|
+
let _classExtraInitializers = [];
|
|
43
|
+
let _classThis;
|
|
44
|
+
let _classSuper = StatelessComponent;
|
|
45
|
+
var RouterView = class extends _classSuper {
|
|
46
|
+
static { _classThis = this; }
|
|
47
|
+
static {
|
|
48
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
49
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
50
|
+
RouterView = _classThis = _classDescriptor.value;
|
|
51
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
52
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
53
|
+
}
|
|
54
|
+
render() {
|
|
55
|
+
const router = useRouter();
|
|
56
|
+
return (_jsx("div", { "data-router-view": "true", children: () => {
|
|
57
|
+
const RouteComponent = router.currentComponent();
|
|
58
|
+
return RouteComponent ? _jsx(RouteComponent, {}) : null;
|
|
59
|
+
} }));
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
return RouterView = _classThis;
|
|
63
|
+
})();
|
|
64
|
+
export { RouterView };
|
|
10
65
|
//# sourceMappingURL=router-view.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router-view.js","sourceRoot":"","sources":["../../src/components/router-view.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"router-view.js","sourceRoot":"","sources":["../../src/components/router-view.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;IAGzB,UAAU;4BADtB,SAAS,EAAE;;;;sBACoB,kBAAkB;0BAA1B,SAAQ,WAAkB;;;;YAAlD,6KAaC;;;YAbY,uDAAU;;QACrB,MAAM;YACJ,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;YAE3B,OAAO,CACL,kCAAsB,MAAM,YACzB,GAAG,EAAE;oBACJ,MAAM,cAAc,GAAG,MAAM,CAAC,gBAAgB,EAAE,CAAC;oBACjD,OAAO,cAAc,CAAC,CAAC,CAAC,KAAC,cAAc,KAAG,CAAC,CAAC,CAAC,IAAI,CAAC;gBACpD,CAAC,GACG,CACP,CAAC;QACJ,CAAC;;;;SAZU,UAAU"}
|
package/dist/decorators.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function Route(path: string):
|
|
1
|
+
export declare function Route(path: string): (value: abstract new (...args: unknown[]) => unknown, _context: ClassDecoratorContext) => void;
|
|
2
2
|
//# sourceMappingURL=decorators.d.ts.map
|
package/dist/decorators.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":"AAAA,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":"AAAA,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,IACf,OAAO,QAAQ,MAAM,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,EAAE,UAAU,qBAAqB,KAAG,IAAI,CAO7G"}
|
package/dist/decorators.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
export function Route(path) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(constructor, "__routePath", {
|
|
2
|
+
return function (value, _context) {
|
|
3
|
+
Object.defineProperty(value, "__routePath", {
|
|
5
4
|
value: path,
|
|
6
5
|
writable: false,
|
|
7
6
|
configurable: false,
|
|
8
7
|
});
|
|
9
|
-
return constructor;
|
|
10
8
|
};
|
|
11
9
|
}
|
|
12
10
|
//# sourceMappingURL=decorators.js.map
|
package/dist/decorators.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,KAAK,CAAC,IAAY;IAChC,
|
|
1
|
+
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,KAAK,CAAC,IAAY;IAChC,OAAO,UAAU,KAAmD,EAAE,QAA+B;QACnG,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,aAAa,EAAE;YAC1C,KAAK,EAAE,IAAI;YACX,QAAQ,EAAE,KAAK;YACf,YAAY,EAAE,KAAK;SACpB,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/router.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAIzD,OAAO,KAAK,EAEV,kBAAkB,EAClB,cAAc,EACd,eAAe,EACf,aAAa,EACb,WAAW,EACX,UAAU,EACX,MAAM,eAAe,CAAC;AAEvB,qBAAa,MAAM;IACjB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAuB;IAChD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAwB;IAClD,OAAO,CAAC,aAAa,CAA8B;IACnD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAgC;IAC3D,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAkB;IAC3C,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAGhC;IAEJ,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,aAAa,CAAC,CAAC;IACzC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;IACzD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IAClC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;IACvC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAC;gBAEzB,MAAM,EAAE,eAAe,EAAE;IA4BrC,OAAO,CAAC,QAAQ;IAYhB,OAAO,CAAC,aAAa;IAcrB,OAAO,CAAC,WAAW;IAanB,OAAO,CAAC,MAAM;YAMA,gBAAgB;
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../src/router.ts"],"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AGZ,OAAO,IAAI,IAAI;IAIf,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;CAGxB;AAID,wBAAgB,IAAI,CAElB,MAAM,EAAE,MAAM,OAAO,CAAC;IAAE,OAAO,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAA;CAAE,CAAC,GAC9D,kBAAkB,CAEpB;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,eAAe,EAAE,GAAG,MAAM,CAG9D;AAED,wBAAgB,SAAS,IAAI,MAAM,CAGlC;AAED,wBAAgB,SAAS,IAAI,QAAQ,CAAC,WAAW,CAAC,CAEjD;AAED,wBAAgB,QAAQ,IAAI,QAAQ,CAAC,UAAU,CAAC,CAE/C;AAED,wBAAgB,WAAW,IAAI,MAAM,CAAC,aAAa,CAAC,CAEnD"}
|
package/dist/router.js
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
|
-
import { computed, signal } from "@praxisjs/core";
|
|
1
|
+
import { computed, signal } from "@praxisjs/core/internal";
|
|
2
2
|
import { compilePath, parseQuery } from "./utils";
|
|
3
3
|
export class Router {
|
|
4
|
+
compiled = [];
|
|
5
|
+
_location;
|
|
6
|
+
_prevLocation = null;
|
|
7
|
+
_component;
|
|
8
|
+
_loading;
|
|
9
|
+
_resolvedComponents = new Map();
|
|
10
|
+
location;
|
|
11
|
+
currentComponent;
|
|
12
|
+
loading;
|
|
13
|
+
params;
|
|
14
|
+
query;
|
|
4
15
|
constructor(routes) {
|
|
5
|
-
this.compiled = [];
|
|
6
|
-
this._prevLocation = null;
|
|
7
|
-
this._resolvedComponents = new Map();
|
|
8
16
|
for (const route of routes) {
|
|
9
17
|
this.addRoute(route);
|
|
10
18
|
}
|
|
@@ -55,7 +63,7 @@ export class Router {
|
|
|
55
63
|
return {};
|
|
56
64
|
}
|
|
57
65
|
isLazy(c) {
|
|
58
|
-
return "__isLazy" in c &&
|
|
66
|
+
return "__isLazy" in c && c.__isLazy;
|
|
59
67
|
}
|
|
60
68
|
async resolveComponent(path) {
|
|
61
69
|
for (const route of this.compiled) {
|
package/dist/router.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.js","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"router.js","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAG3D,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAYlD,MAAM,OAAO,MAAM;IACA,QAAQ,GAAoB,EAAE,CAAC;IAC/B,SAAS,CAAwB;IAC1C,aAAa,GAAyB,IAAI,CAAC;IAClC,UAAU,CAAgC;IAC1C,QAAQ,CAAkB;IAC1B,mBAAmB,GAAG,IAAI,GAAG,EAG3C,CAAC;IAEK,QAAQ,CAAwB;IAChC,gBAAgB,CAAgC;IAChD,OAAO,CAAkB;IACzB,MAAM,CAAwB;IAC9B,KAAK,CAAuB;IAErC,YAAY,MAAyB;QACnC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QACvB,CAAC;QAED,MAAM,OAAO,GAAG,IAAI,CAAC,aAAa,CAChC,MAAM,CAAC,QAAQ,CAAC,QAAQ,EACxB,MAAM,CAAC,QAAQ,CAAC,MAAM,EACtB,MAAM,CAAC,QAAQ,CAAC,IAAI,CACrB,CAAC;QACF,IAAI,CAAC,SAAS,GAAG,MAAM,CAAgB,OAAO,CAAC,CAAC;QAChD,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAU,KAAK,CAAC,CAAC;QACvC,IAAI,CAAC,UAAU,GAAG,MAAM,CAAwB,IAAI,CAAC,CAAC;QAEtD,IAAI,CAAC,QAAQ,GAAG,IAAI,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
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@praxisjs/router",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -14,9 +14,10 @@
|
|
|
14
14
|
"typescript": "^5.9.3"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@praxisjs/core": "0.
|
|
18
|
-
"@praxisjs/
|
|
19
|
-
"@praxisjs/
|
|
17
|
+
"@praxisjs/core": "0.4.0",
|
|
18
|
+
"@praxisjs/decorators": "0.4.0",
|
|
19
|
+
"@praxisjs/jsx": "0.2.1",
|
|
20
|
+
"@praxisjs/shared": "0.2.0"
|
|
20
21
|
},
|
|
21
22
|
"scripts": {
|
|
22
23
|
"build": "tsc",
|
package/src/components/link.tsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { StatelessComponent } from "@praxisjs/core";
|
|
2
|
+
import { Component } from "@praxisjs/decorators";
|
|
3
|
+
import type { Children } from "@praxisjs/shared";
|
|
3
4
|
|
|
4
5
|
import { useRouter } from "../router";
|
|
5
6
|
|
|
@@ -11,35 +12,39 @@ interface LinkProps {
|
|
|
11
12
|
children?: Children | Children[];
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
@Component()
|
|
16
|
+
export class Link extends StatelessComponent<LinkProps> {
|
|
17
|
+
render() {
|
|
18
|
+
const {
|
|
19
|
+
to,
|
|
20
|
+
replace = false,
|
|
21
|
+
class: cls = "",
|
|
22
|
+
activeClass = "active",
|
|
23
|
+
children,
|
|
24
|
+
} = this.props;
|
|
22
25
|
|
|
23
|
-
|
|
26
|
+
const router = useRouter();
|
|
24
27
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
return (
|
|
35
|
-
<a
|
|
36
|
-
href={to}
|
|
37
|
-
class={() =>
|
|
38
|
-
[cls, isActive() ? activeClass : ""].filter(Boolean).join(" ")
|
|
28
|
+
const handleClick = (e: MouseEvent) => {
|
|
29
|
+
e.preventDefault();
|
|
30
|
+
if (replace) {
|
|
31
|
+
void router.replace(to);
|
|
32
|
+
} else {
|
|
33
|
+
void router.push(to);
|
|
39
34
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<a
|
|
39
|
+
href={to}
|
|
40
|
+
class={() => {
|
|
41
|
+
const isActive = router.location().path === to;
|
|
42
|
+
return [cls, isActive ? activeClass : ""].filter(Boolean).join(" ");
|
|
43
|
+
}}
|
|
44
|
+
onClick={handleClick}
|
|
45
|
+
>
|
|
46
|
+
{children}
|
|
47
|
+
</a>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
45
50
|
}
|
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { StatelessComponent } from "@praxisjs/core";
|
|
2
|
+
import { Component } from "@praxisjs/decorators";
|
|
2
3
|
|
|
3
4
|
import { useRouter } from "../router";
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
@Component()
|
|
7
|
+
export class RouterView extends StatelessComponent {
|
|
8
|
+
render() {
|
|
9
|
+
const router = useRouter();
|
|
7
10
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
return (
|
|
12
|
+
<div data-router-view="true">
|
|
13
|
+
{() => {
|
|
14
|
+
const RouteComponent = router.currentComponent();
|
|
15
|
+
return RouteComponent ? <RouteComponent /> : null;
|
|
16
|
+
}}
|
|
17
|
+
</div>
|
|
18
|
+
);
|
|
19
|
+
}
|
|
16
20
|
}
|
package/src/decorators.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
export function Route(path: string) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(constructor, "__routePath", {
|
|
2
|
+
return function (value: abstract new (...args: unknown[]) => unknown, _context: ClassDecoratorContext): void {
|
|
3
|
+
Object.defineProperty(value, "__routePath", {
|
|
5
4
|
value: path,
|
|
6
5
|
writable: false,
|
|
7
6
|
configurable: false,
|
|
8
7
|
});
|
|
9
|
-
return constructor;
|
|
10
8
|
};
|
|
11
9
|
}
|
package/src/router.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { computed, signal } from "@praxisjs/core";
|
|
1
|
+
import { computed, signal } from "@praxisjs/core/internal";
|
|
2
2
|
import type { Signal, Computed } from "@praxisjs/shared";
|
|
3
3
|
|
|
4
4
|
import { compilePath, parseQuery } from "./utils";
|
|
@@ -100,12 +100,10 @@ export class Router {
|
|
|
100
100
|
private isLazy(
|
|
101
101
|
c: RouteComponent | LazyRouteComponent,
|
|
102
102
|
): c is LazyRouteComponent {
|
|
103
|
-
return "__isLazy" in c &&
|
|
103
|
+
return "__isLazy" in c && c.__isLazy;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
private async resolveComponent(
|
|
107
|
-
path: string,
|
|
108
|
-
): Promise<RouteComponent | null> {
|
|
106
|
+
private async resolveComponent(path: string): Promise<RouteComponent | null> {
|
|
109
107
|
for (const route of this.compiled) {
|
|
110
108
|
if (!route.regex.test(path)) continue;
|
|
111
109
|
const { component } = route.definition;
|
|
@@ -190,7 +188,6 @@ export class Router {
|
|
|
190
188
|
|
|
191
189
|
let _router: Router | null = null;
|
|
192
190
|
|
|
193
|
-
|
|
194
191
|
export function lazy(
|
|
195
192
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
196
193
|
loader: () => Promise<{ default: new (...args: any[]) => any }>,
|