@typed/router 0.13.0 → 0.15.0
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/Link.d.ts +26 -11
- package/dist/Link.d.ts.map +1 -1
- package/dist/Link.js +47 -23
- package/dist/Link.js.map +1 -1
- package/dist/Match.d.ts +33 -0
- package/dist/Match.d.ts.map +1 -0
- package/dist/Match.js +16 -0
- package/dist/Match.js.map +1 -0
- package/dist/Matcher.d.ts +28 -0
- package/dist/Matcher.d.ts.map +1 -0
- package/dist/Matcher.js +24 -0
- package/dist/Matcher.js.map +1 -0
- package/dist/Navigation.d.ts +10 -0
- package/dist/Navigation.d.ts.map +1 -0
- package/dist/Navigation.js +7 -0
- package/dist/Navigation.js.map +1 -0
- package/dist/Redirect.d.ts +29 -0
- package/dist/Redirect.d.ts.map +1 -0
- package/dist/Redirect.js +17 -0
- package/dist/Redirect.js.map +1 -0
- package/dist/RouteOutlet.d.ts +3 -0
- package/dist/RouteOutlet.d.ts.map +1 -0
- package/dist/RouteOutlet.js +2 -0
- package/dist/RouteOutlet.js.map +1 -0
- package/dist/ScrollRestoration.d.ts +19 -0
- package/dist/ScrollRestoration.d.ts.map +1 -0
- package/dist/ScrollRestoration.js +64 -0
- package/dist/ScrollRestoration.js.map +1 -0
- package/dist/cjs/Link.d.ts +26 -11
- package/dist/cjs/Link.d.ts.map +1 -1
- package/dist/cjs/Link.js +47 -22
- package/dist/cjs/Link.js.map +1 -1
- package/dist/cjs/Match.d.ts +33 -0
- package/dist/cjs/Match.d.ts.map +1 -0
- package/dist/cjs/Match.js +43 -0
- package/dist/cjs/Match.js.map +1 -0
- package/dist/cjs/Matcher.d.ts +28 -0
- package/dist/cjs/Matcher.d.ts.map +1 -0
- package/dist/cjs/Matcher.js +52 -0
- package/dist/cjs/Matcher.js.map +1 -0
- package/dist/cjs/Navigation.d.ts +10 -0
- package/dist/cjs/Navigation.d.ts.map +1 -0
- package/dist/cjs/Navigation.js +34 -0
- package/dist/cjs/Navigation.js.map +1 -0
- package/dist/cjs/Redirect.d.ts +29 -0
- package/dist/cjs/Redirect.d.ts.map +1 -0
- package/dist/cjs/Redirect.js +44 -0
- package/dist/cjs/Redirect.js.map +1 -0
- package/dist/cjs/ScrollRestoration.d.ts +19 -0
- package/dist/cjs/ScrollRestoration.d.ts.map +1 -0
- package/dist/cjs/ScrollRestoration.js +91 -0
- package/dist/cjs/ScrollRestoration.js.map +1 -0
- package/dist/cjs/index.d.ts +7 -3
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +7 -3
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/matchRoutes.d.ts +8 -0
- package/dist/cjs/matchRoutes.d.ts.map +1 -0
- package/dist/cjs/matchRoutes.js +77 -0
- package/dist/cjs/matchRoutes.js.map +1 -0
- package/dist/cjs/router.d.ts +24 -63
- package/dist/cjs/router.d.ts.map +1 -1
- package/dist/cjs/router.js +22 -160
- package/dist/cjs/router.js.map +1 -1
- package/dist/index.d.ts +7 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -3
- package/dist/index.js.map +1 -1
- package/dist/matchRoutes.d.ts +8 -0
- package/dist/matchRoutes.d.ts.map +1 -0
- package/dist/matchRoutes.js +50 -0
- package/dist/matchRoutes.js.map +1 -0
- package/dist/router.d.ts +24 -63
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +18 -153
- package/dist/router.js.map +1 -1
- package/dist/tsconfig.cjs.build.tsbuildinfo +1 -1
- package/package.json +13 -11
- package/project.json +12 -10
- package/src/Link.ts +129 -39
- package/src/Match.ts +114 -0
- package/src/Matcher.ts +139 -0
- package/src/Navigation.ts +24 -0
- package/src/Redirect.ts +21 -0
- package/src/ScrollRestoration.ts +110 -0
- package/src/index.ts +7 -3
- package/src/matchRoutes.ts +112 -0
- package/src/router.ts +53 -311
- package/tsconfig.build.json +5 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/tsconfig.cjs.build.json +6 -0
- package/tsconfig.json +6 -0
- package/vite.config.js +3 -0
- package/src/RouteMatch.ts +0 -56
- package/src/RouteMatcher.ts +0 -264
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.matchRoutes = void 0;
|
|
27
|
+
const Function_1 = require("@effect/data/Function");
|
|
28
|
+
const Option = __importStar(require("@effect/data/Option"));
|
|
29
|
+
const Effect = __importStar(require("@effect/io/Effect"));
|
|
30
|
+
const Fx = __importStar(require("@typed/fx"));
|
|
31
|
+
const html_1 = require("@typed/html");
|
|
32
|
+
const Redirect_js_1 = require("./Redirect.js");
|
|
33
|
+
const router_js_1 = require("./router.js");
|
|
34
|
+
function matchRoutes(matches, onNotFound = () => Fx.empty()) {
|
|
35
|
+
return Fx.gen(function* ($) {
|
|
36
|
+
const { environment } = yield* $(html_1.RenderContext);
|
|
37
|
+
const isBrowser = environment === 'browser';
|
|
38
|
+
const router = yield* $(router_js_1.Router);
|
|
39
|
+
const notFound = onNotFound(router.params);
|
|
40
|
+
const matchers = matches.map((match) => {
|
|
41
|
+
const nestedRouter = router.define(match.route);
|
|
42
|
+
const render = (0, Function_1.pipe)(nestedRouter.params, match.render, Fx.provideService(router_js_1.Router, nestedRouter), Fx.scoped);
|
|
43
|
+
return [
|
|
44
|
+
match.route,
|
|
45
|
+
render,
|
|
46
|
+
match.options?.guard,
|
|
47
|
+
match.options?.onMatch,
|
|
48
|
+
];
|
|
49
|
+
});
|
|
50
|
+
const length = matchers.length;
|
|
51
|
+
const matched = yield* $(Fx.makeRef(Effect.succeed(Fx.empty())));
|
|
52
|
+
const matchPath = (path) => Effect.gen(function* ($) {
|
|
53
|
+
for (let i = 0; i < length; ++i) {
|
|
54
|
+
const [route, render, guard, onMatch] = matchers[i];
|
|
55
|
+
const params = route.match(path);
|
|
56
|
+
if (Option.isSome(params)) {
|
|
57
|
+
// If there is a guard and it fails, continue to next route
|
|
58
|
+
if (guard && !(yield* $(guard(params.value)))) {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
// If there is an onMatch handler, run it and catch any errors
|
|
62
|
+
// This is useful when you want to add tracking when a route is matched
|
|
63
|
+
if (onMatch) {
|
|
64
|
+
yield* $(onMatch(params.value), Effect.catchAllCause((cause) => matched.error(cause)), Effect.forkScoped);
|
|
65
|
+
}
|
|
66
|
+
return yield* $(matched.set(render));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return yield* $(matched.set(notFound));
|
|
70
|
+
});
|
|
71
|
+
// Match a Route when navigation occurs
|
|
72
|
+
yield* $(router.navigation.onNavigation((event) => matchPath((0, router_js_1.getCurrentPathFromUrl)(event.destination.url))));
|
|
73
|
+
return (0, Function_1.pipe)(matched, isBrowser ? Function_1.identity : Fx.take(1), Redirect_js_1.Redirect.switchMatch((r) => Fx.as(Fx.fromEffect(router.navigation.navigate(r.url, r.options)), Option.none()), Fx.map(Option.some)), Fx.compact);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
exports.matchRoutes = matchRoutes;
|
|
77
|
+
//# sourceMappingURL=matchRoutes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matchRoutes.js","sourceRoot":"","sources":["../../src/matchRoutes.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAsD;AACtD,4DAA6C;AAC7C,0DAA2C;AAE3C,8CAA+B;AAC/B,sCAA2C;AAK3C,+CAAwC;AACxC,2CAA2D;AAE3D,SAAgB,WAAW,CAMzB,OAAgB,EAChB,aAEsB,GAAG,EAAE,CAAC,EAAE,CAAC,KAAK,EAAE;IAYtC,OAAO,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;QACxB,MAAM,EAAE,WAAW,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,oBAAa,CAAC,CAAA;QAC/C,MAAM,SAAS,GAAG,WAAW,KAAK,SAAS,CAAA;QAC3C,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,kBAAM,CAAC,CAAA;QAC/B,MAAM,QAAQ,GAAG,UAAU,CAAC,MAAM,CAAC,MAAM,CAAe,CAAA;QACxD,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;YACrC,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;YAC/C,MAAM,MAAM,GAAG,IAAA,eAAI,EACjB,YAAY,CAAC,MAAM,EACnB,KAAK,CAAC,MAAM,EACZ,EAAE,CAAC,cAAc,CAAC,kBAAM,E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C,UAAU,CAClB,CAAA;qBACF;oBAED,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAA;iBACrC;aACF;YAED,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAA;QACxC,CAAC,CAAC,CAAA;QAEJ,uCAAuC;QACvC,KAAK,CAAC,CAAC,CAAC,CACN,MAAM,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,KAAK,EAAE,EAAE,CACvC,SAAS,CAAC,IAAA,iCAAqB,EAAC,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CACxD,CACF,CAAA;QAED,OAAO,IAAA,eAAI,EACT,OAAO,EACP,SAAS,CAAC,CAAC,CAAC,mBAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,EACjC,sBAAQ,CAAC,WAAW,CAClB,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC,EACxF,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CACpB,EACD,EAAE,CAAC,OAAO,CACX,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC;AAlGD,kCAkGC"}
|
package/dist/cjs/router.d.ts
CHANGED
|
@@ -1,76 +1,37 @@
|
|
|
1
1
|
import * as Option from '@effect/data/Option';
|
|
2
|
-
import * as
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
import * as Path from '@typed/path';
|
|
11
|
-
import * as Route from '@typed/route';
|
|
12
|
-
export interface Router<out R = never, out E = never, in out P extends string = string> {
|
|
2
|
+
import * as Layer from '@effect/io/Layer';
|
|
3
|
+
import { Tag } from '@typed/context';
|
|
4
|
+
import { DomServicesElementParams } from '@typed/dom';
|
|
5
|
+
import { Filtered } from '@typed/fx';
|
|
6
|
+
import * as Navigation from '@typed/navigation';
|
|
7
|
+
import { ParamsOf, PathJoin } from '@typed/path';
|
|
8
|
+
import { Route } from '@typed/route';
|
|
9
|
+
export interface Router<in out P extends string = string> {
|
|
13
10
|
/**
|
|
14
|
-
* The base
|
|
11
|
+
* The base Route for this Router instance.
|
|
15
12
|
*/
|
|
16
|
-
readonly route: Route
|
|
13
|
+
readonly route: Route<P>;
|
|
17
14
|
/**
|
|
18
|
-
* The current
|
|
15
|
+
* The current params for the current path.
|
|
19
16
|
*/
|
|
20
|
-
readonly
|
|
17
|
+
readonly params: Filtered<never, never, ParamsOf<P>>;
|
|
21
18
|
/**
|
|
22
|
-
*
|
|
19
|
+
* Construct a new Router instance by defining a new Route which is concatenated
|
|
20
|
+
* to the current Route.
|
|
23
21
|
*/
|
|
24
|
-
readonly
|
|
22
|
+
readonly define: <P2 extends string>(route: Route<P2>) => Router<PathJoin<[P, P2]>>;
|
|
25
23
|
/**
|
|
26
|
-
* The
|
|
24
|
+
* The parent Router instance if one exists.
|
|
27
25
|
*/
|
|
28
|
-
readonly
|
|
26
|
+
readonly parent: Option.Option<Router<string>>;
|
|
29
27
|
/**
|
|
30
|
-
*
|
|
28
|
+
* The Navigation Service
|
|
31
29
|
*/
|
|
32
|
-
readonly
|
|
33
|
-
Path.Interpolate<Route.PathOf<R>, Route.ParamsOf<R>>,
|
|
34
|
-
Path.Interpolate<Route.PathOf<R2>, P>
|
|
35
|
-
]>>;
|
|
36
|
-
/**
|
|
37
|
-
* Helper for constructing a nested router
|
|
38
|
-
*/
|
|
39
|
-
readonly define: <R2, E2, Path2 extends string>(route: Route.Route<R2, E2, Path2>) => Router<R | R2, E | E2, Path.PathJoin<[P, Path2]>>;
|
|
40
|
-
/**
|
|
41
|
-
* The parent router if one exists
|
|
42
|
-
*/
|
|
43
|
-
readonly parent: Option.Option<Router<any, string>>;
|
|
44
|
-
/**
|
|
45
|
-
* Provide all the resources needed for a Router
|
|
46
|
-
*/
|
|
47
|
-
readonly provideContext: (environment: Context.Context<R>) => Router<never, E, P>;
|
|
48
|
-
}
|
|
49
|
-
export declare const Router: Context.Tag<Router<never, never, string>, Router<never, never, string>> & {
|
|
50
|
-
make: <R = never, E = never, P extends string = string>(route: Route.Route<R, E, P>, currentPath: Fx.RefSubject<never, string>, parent?: Option.Option<Router<any, any, string>>) => Router<R, E, P>;
|
|
51
|
-
};
|
|
52
|
-
export declare const outlet: Fx.Fx<RenderContext | Router, Redirect, html.Renderable>;
|
|
53
|
-
export declare const currentPath: Fx.Fx<Router, never, string>;
|
|
54
|
-
export declare function provideContext<R>(environment: Context.Context<R>): <E, P extends string>(router: Router<R, E, P>) => Router<never, E, P>;
|
|
55
|
-
export interface Redirect {
|
|
56
|
-
readonly _tag: 'Redirect';
|
|
57
|
-
readonly path: string;
|
|
58
|
-
}
|
|
59
|
-
export declare namespace Redirect {
|
|
60
|
-
const make: (path: string) => Redirect;
|
|
61
|
-
const is: (r: unknown) => r is Redirect;
|
|
62
|
-
}
|
|
63
|
-
export declare function redirect(path: string): Effect.Effect<never, Redirect, never>;
|
|
64
|
-
export declare namespace redirect {
|
|
65
|
-
var fx: (path: string) => Fx.Fx<never, Redirect, never>;
|
|
30
|
+
readonly navigation: Navigation.Navigation;
|
|
66
31
|
}
|
|
67
|
-
export declare const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
export declare const
|
|
72
|
-
export declare const live: (currentPath?: Fx.RefSubject<never, string>) => Layer.Layer<Location | History | Window | Document, never, Router<never, never, string>>;
|
|
73
|
-
export declare function getCurrentPathFromLocation(location: Location | HTMLAnchorElement | URL): string;
|
|
74
|
-
export declare const getCurrentPath: Effect.Effect<Router<never, never, string>, never, string>;
|
|
75
|
-
export declare const getBasePath: Effect.Effect<Router<never, never, string>, never, string>;
|
|
32
|
+
export declare const Router: Tag<Router<string>, Router<string>>;
|
|
33
|
+
export declare const navigation: Layer.Layer<Navigation.Navigation, never, Router>;
|
|
34
|
+
export declare function getCurrentPathFromUrl(url: URL): string;
|
|
35
|
+
export declare const dom: (options?: Navigation.DomNavigationOptions & DomServicesElementParams) => Layer.Layer<Navigation.NavigationServices, never, Navigation.Navigation | Router>;
|
|
36
|
+
export declare const memory: (options: Navigation.MemoryNavigationOptions) => Layer.Layer<never, never, Navigation.Navigation | Router>;
|
|
76
37
|
//# sourceMappingURL=router.d.ts.map
|
package/dist/cjs/router.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/router.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/router.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,qBAAqB,CAAA;AAE7C,OAAO,KAAK,KAAK,MAAM,kBAAkB,CAAA;AACzC,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAA;AACpC,OAAO,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAA;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AACpC,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AAEpC,MAAM,WAAW,MAAM,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM;IACtD;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAA;IAExB;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAA;IAEpD;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,SAAS,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAA;IAEnF;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAA;IAE9C;;OAEG;IACH,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC,UAAU,CAAA;CAC3C;AAED,eAAO,MAAM,MAAM,qCAAwB,CAAA;AAE3C,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,UAAU,EAAE,KAAK,EAAE,MAAM,CAyBxE,CAAA;AAED,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,CAEtD;AAED,eAAO,MAAM,GAAG,aACJ,WAAW,oBAAoB,GAAG,wBAAwB,KACnE,WAAW,CAAC,WAAW,kBAAkB,EAAE,KAAK,EAAE,qBAAqB,GAAG,MAAM,CAC1B,CAAA;AAEzD,eAAO,MAAM,MAAM,YACR,WAAW,uBAAuB,KAC1C,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,qBAAqB,GAAG,MAAM,CACC,CAAA"}
|
package/dist/cjs/router.js
CHANGED
|
@@ -23,173 +23,35 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
27
|
-
/* eslint-disable @typescript-eslint/ban-types */
|
|
28
|
-
const Function_1 = require("@effect/data/Function");
|
|
26
|
+
exports.memory = exports.dom = exports.getCurrentPathFromUrl = exports.navigation = exports.Router = void 0;
|
|
29
27
|
const Option = __importStar(require("@effect/data/Option"));
|
|
30
28
|
const Effect = __importStar(require("@effect/io/Effect"));
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const outlet = Fx.RefSubject.unsafeMake(Effect.sync(() => null));
|
|
41
|
-
const createPath = (other, ...[params]) => Effect.gen(function* ($) {
|
|
42
|
-
const path = yield* $(currentPath.get);
|
|
43
|
-
const baseParams = yield* $(route.match(path));
|
|
44
|
-
if (Option.isNone(baseParams)) {
|
|
45
|
-
return yield* $(Effect.dieMessage(`Can not create path when the parent can not be matched.
|
|
46
|
-
Parent Route: ${route.path}
|
|
47
|
-
Current Route: ${other.path}
|
|
48
|
-
Current Path: ${path}`));
|
|
49
|
-
}
|
|
50
|
-
return route.concat(other).make({ ...baseParams.value, ...params });
|
|
51
|
-
});
|
|
29
|
+
const Layer = __importStar(require("@effect/io/Layer"));
|
|
30
|
+
const context_1 = require("@typed/context");
|
|
31
|
+
const Navigation = __importStar(require("@typed/navigation"));
|
|
32
|
+
const route_1 = require("@typed/route");
|
|
33
|
+
exports.Router = (0, context_1.Tag)('Router');
|
|
34
|
+
exports.navigation = exports.Router.layer(Effect.gen(function* ($) {
|
|
35
|
+
const navigation = yield* $(Navigation.Navigation);
|
|
36
|
+
const currentPath = navigation.currentEntry.map((destination) => getCurrentPathFromUrl(destination.url));
|
|
37
|
+
function makeRouter(route, parent) {
|
|
52
38
|
const router = {
|
|
53
39
|
route,
|
|
54
|
-
|
|
55
|
-
params:
|
|
56
|
-
|
|
57
|
-
createPath: createPath,
|
|
58
|
-
define: (other) => makeRouter(route.concat(other), currentPath, Option.some(router)),
|
|
59
|
-
provideContext: (env) => provideContext(env)(router),
|
|
40
|
+
navigation,
|
|
41
|
+
params: currentPath.filterMap(route.match),
|
|
42
|
+
define: (other) => makeRouter(route.concat(other), Option.some(router)),
|
|
60
43
|
parent,
|
|
61
44
|
};
|
|
62
45
|
return router;
|
|
63
|
-
},
|
|
64
|
-
});
|
|
65
|
-
exports.outlet = html_1.RenderContext.withFx(({ environment }) => exports.Router.withFx((r) => environment === 'browser'
|
|
66
|
-
? r.outlet
|
|
67
|
-
: (0, Function_1.pipe)(r.outlet, Fx.skipUntil((x) => x !== null), Fx.take(1))));
|
|
68
|
-
exports.currentPath = exports.Router.withFx((r) => r.currentPath);
|
|
69
|
-
function provideContext(environment) {
|
|
70
|
-
return (router) => {
|
|
71
|
-
const provided = {
|
|
72
|
-
...router,
|
|
73
|
-
params: (0, Function_1.pipe)(router.params, Fx.provideContext(environment)),
|
|
74
|
-
route: Route.provideContext(environment)(router.route),
|
|
75
|
-
createPath: ((other, ...params) => Effect.provideContext(environment)(router.createPath(other, ...params))),
|
|
76
|
-
provideContext: (env) => provideContext(env)(provided),
|
|
77
|
-
};
|
|
78
|
-
return provided;
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
exports.provideContext = provideContext;
|
|
82
|
-
var Redirect;
|
|
83
|
-
(function (Redirect) {
|
|
84
|
-
Redirect.make = (path) => ({ _tag: 'Redirect', path });
|
|
85
|
-
Redirect.is = (r) => typeof r === 'object' && r !== null && '_tag' in r && r._tag === 'Redirect';
|
|
86
|
-
})(Redirect = exports.Redirect || (exports.Redirect = {}));
|
|
87
|
-
function redirect(path) {
|
|
88
|
-
return Effect.fail(Redirect.make(path));
|
|
89
|
-
}
|
|
90
|
-
exports.redirect = redirect;
|
|
91
|
-
redirect.fx = (path) => Fx.fail(Redirect.make(path));
|
|
92
|
-
const redirectTo = (route, ...[params]) => (0, Function_1.pipe)(exports.Router.withEffect((r) => r.createPath(route, params)), Effect.flatMap(redirect));
|
|
93
|
-
exports.redirectTo = redirectTo;
|
|
94
|
-
exports.redirectTo.fx = (route, ...params) => (0, Function_1.pipe)(exports.Router.withEffect((r) => r.createPath(route, params)), Fx.fromEffect, Fx.switchMap(redirect.fx));
|
|
95
|
-
// TOOD: Add support for reading <base> tag for default Router path.
|
|
96
|
-
const makeRouter = (currentPath) => Effect.gen(function* ($) {
|
|
97
|
-
const history = yield* $(dom_1.History);
|
|
98
|
-
const location = yield* $(dom_1.Location);
|
|
99
|
-
if (!currentPath) {
|
|
100
|
-
currentPath = Fx.RefSubject.unsafeMake(Effect.sync(() => getCurrentPathFromLocation(location)));
|
|
101
|
-
}
|
|
102
|
-
// Patch history events to emit an event when the path changes
|
|
103
|
-
const historyEvents = yield* $(patchHistory);
|
|
104
|
-
// Update the current path when events occur:
|
|
105
|
-
// - popstate
|
|
106
|
-
// - hashchange
|
|
107
|
-
// - history events
|
|
108
|
-
yield* $(Fx.mergeAll((0, dom_1.addWindowListener)('popstate'), (0, dom_1.addWindowListener)('hashchange'), historyEvents),
|
|
109
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
110
|
-
Fx.switchMapEffect(() => currentPath.set(getCurrentPathFromLocation(location))), Fx.drain, Effect.forkScoped);
|
|
111
|
-
// Listen to path changes and update the current history location, if necessary
|
|
112
|
-
yield* $((0, Function_1.pipe)(currentPath, Fx.skipRepeats, Fx.observe((path) => Effect.sync(() => {
|
|
113
|
-
if (path !== getCurrentPathFromLocation(location)) {
|
|
114
|
-
history.pushState({}, '', path);
|
|
115
|
-
}
|
|
116
|
-
})), Effect.forkScoped));
|
|
117
|
-
// Find the configured base path
|
|
118
|
-
const document = yield* $(dom_1.Document);
|
|
119
|
-
const base = document.querySelector('base');
|
|
120
|
-
const baseHref = base ? getBasePathFromHref(base.href) : '/';
|
|
121
|
-
// Make our base router
|
|
122
|
-
return exports.Router.make(Route.Route(baseHref), currentPath);
|
|
123
|
-
});
|
|
124
|
-
exports.makeRouter = makeRouter;
|
|
125
|
-
const live = (currentPath) => exports.Router.layerScoped((0, exports.makeRouter)(currentPath));
|
|
126
|
-
exports.live = live;
|
|
127
|
-
function getCurrentPathFromLocation(location) {
|
|
128
|
-
return location.pathname + location.search + location.hash;
|
|
129
|
-
}
|
|
130
|
-
exports.getCurrentPathFromLocation = getCurrentPathFromLocation;
|
|
131
|
-
exports.getCurrentPath = exports.Router.withEffect((r) => r.currentPath.get);
|
|
132
|
-
exports.getBasePath = exports.Router.with((r) => {
|
|
133
|
-
const routers = [r];
|
|
134
|
-
let current = r;
|
|
135
|
-
while (Option.isSome(current.parent)) {
|
|
136
|
-
current = current.parent.value;
|
|
137
|
-
routers.push(current);
|
|
138
|
-
}
|
|
139
|
-
return routers.reduceRight((acc, r) => Path.pathJoin(r.route.path, acc), '');
|
|
140
|
-
});
|
|
141
|
-
const patchHistory = Effect.gen(function* ($) {
|
|
142
|
-
const history = yield* $(dom_1.History);
|
|
143
|
-
const historyEvents = Fx.makeSubject();
|
|
144
|
-
const runtime = yield* $(Effect.runtime());
|
|
145
|
-
const runFork = Runtime.runFork(runtime);
|
|
146
|
-
const cleanup = patchHistory_(history, () => runFork(historyEvents.event()));
|
|
147
|
-
// unpatch history upon finalization
|
|
148
|
-
yield* $(Effect.addFinalizer(() => Effect.sync(cleanup)));
|
|
149
|
-
return historyEvents;
|
|
150
|
-
});
|
|
151
|
-
function patchHistory_(history, sendEvent) {
|
|
152
|
-
const pushState = history.pushState.bind(history);
|
|
153
|
-
const replaceState = history.replaceState.bind(history);
|
|
154
|
-
const go = history.go.bind(history);
|
|
155
|
-
const back = history.back.bind(history);
|
|
156
|
-
const forward = history.forward.bind(history);
|
|
157
|
-
history.pushState = function (state, title, url) {
|
|
158
|
-
pushState(state, title, url);
|
|
159
|
-
sendEvent();
|
|
160
|
-
};
|
|
161
|
-
history.replaceState = function (state, title, url) {
|
|
162
|
-
replaceState(state, title, url);
|
|
163
|
-
sendEvent();
|
|
164
|
-
};
|
|
165
|
-
history.go = function (delta) {
|
|
166
|
-
go(delta);
|
|
167
|
-
sendEvent();
|
|
168
|
-
};
|
|
169
|
-
history.back = function () {
|
|
170
|
-
back();
|
|
171
|
-
sendEvent();
|
|
172
|
-
};
|
|
173
|
-
history.forward = function () {
|
|
174
|
-
forward();
|
|
175
|
-
sendEvent();
|
|
176
|
-
};
|
|
177
|
-
// Reset history to original state
|
|
178
|
-
return () => {
|
|
179
|
-
history.pushState = pushState;
|
|
180
|
-
history.replaceState = replaceState;
|
|
181
|
-
history.go = go;
|
|
182
|
-
history.back = back;
|
|
183
|
-
history.forward = forward;
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
function getBasePathFromHref(href) {
|
|
187
|
-
try {
|
|
188
|
-
const url = new URL(href);
|
|
189
|
-
return getCurrentPathFromLocation(url);
|
|
190
|
-
}
|
|
191
|
-
catch {
|
|
192
|
-
return href;
|
|
193
46
|
}
|
|
47
|
+
return makeRouter((0, route_1.Route)(navigation.base), Option.none());
|
|
48
|
+
}));
|
|
49
|
+
function getCurrentPathFromUrl(url) {
|
|
50
|
+
return url.pathname + url.search + url.hash;
|
|
194
51
|
}
|
|
52
|
+
exports.getCurrentPathFromUrl = getCurrentPathFromUrl;
|
|
53
|
+
const dom = (options) => Layer.provideMerge(Navigation.dom(options), exports.navigation);
|
|
54
|
+
exports.dom = dom;
|
|
55
|
+
const memory = (options) => Layer.provideMerge(Navigation.memory(options), exports.navigation);
|
|
56
|
+
exports.memory = memory;
|
|
195
57
|
//# sourceMappingURL=router.js.map
|
package/dist/cjs/router.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../src/router.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../src/router.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4DAA6C;AAC7C,0DAA2C;AAC3C,wDAAyC;AACzC,4CAAoC;AAGpC,8DAA+C;AAE/C,wCAAoC;AA8BvB,QAAA,MAAM,GAAG,IAAA,aAAG,EAAS,QAAQ,CAAC,CAAA;AAE9B,QAAA,UAAU,GAAsD,cAAM,CAAC,KAAK,CACvF,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,QAAA,MAAM,UAGyC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
export * from './router.js';
|
|
2
1
|
export * from './Link.js';
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
2
|
+
export * from './Match.js';
|
|
3
|
+
export * from './Matcher.js';
|
|
4
|
+
export * from './matchRoutes.js';
|
|
5
|
+
export * from './Navigation.js';
|
|
6
|
+
export * from './Redirect.js';
|
|
7
|
+
export * from './router.js';
|
|
8
|
+
export * from './ScrollRestoration.js';
|
|
5
9
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAC5B,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,wBAAwB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
export * from './router.js';
|
|
2
1
|
export * from './Link.js';
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
2
|
+
export * from './Match.js';
|
|
3
|
+
export * from './Matcher.js';
|
|
4
|
+
export * from './matchRoutes.js';
|
|
5
|
+
export * from './Navigation.js';
|
|
6
|
+
export * from './Redirect.js';
|
|
7
|
+
export * from './router.js';
|
|
8
|
+
export * from './ScrollRestoration.js';
|
|
5
9
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAC5B,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,wBAAwB,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as Scope from '@effect/io/Scope';
|
|
2
|
+
import * as Fx from '@typed/fx';
|
|
3
|
+
import { RenderContext } from '@typed/html';
|
|
4
|
+
import { Match } from './Match.js';
|
|
5
|
+
import { Redirect } from './Redirect.js';
|
|
6
|
+
import { Router } from './router.js';
|
|
7
|
+
export declare function matchRoutes<const Matches extends ReadonlyArray<Match.Any>, R = never, E = never, A = never>(matches: Matches, onNotFound?: (params: Fx.Filtered<never, never, Readonly<Record<string, string>>>) => Fx.Fx<R, E, A>): Fx.Fx<Router | RenderContext | Scope.Scope | R | Match.Context<Matches[number]>, Exclude<E | Match.Error<Matches[number]>, Redirect>, A | Match.Success<Matches[number]>>;
|
|
8
|
+
//# sourceMappingURL=matchRoutes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matchRoutes.d.ts","sourceRoot":"","sources":["../src/matchRoutes.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,MAAM,kBAAkB,CAAA;AACzC,OAAO,KAAK,EAAE,MAAM,WAAW,CAAA;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAI3C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,MAAM,EAAyB,MAAM,aAAa,CAAA;AAE3D,wBAAgB,WAAW,CACzB,KAAK,CAAC,OAAO,SAAS,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,EAC9C,CAAC,GAAG,KAAK,EACT,CAAC,GAAG,KAAK,EACT,CAAC,GAAG,KAAK,EAET,OAAO,EAAE,OAAO,EAChB,UAAU,GAAE,CACV,MAAM,EAAE,EAAE,CAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,KAChE,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAoB,GACrC,EAAE,CAAC,EAAE,CACN,MAAM,GAAG,aAAa,GAAG,KAAK,CAAC,KAAK,GAAG,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,EACzE,OAAO,CAAC,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,QAAQ,CAAC,EACnD,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CACnC,CAoFA"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { identity, pipe } from '@effect/data/Function';
|
|
2
|
+
import * as Option from '@effect/data/Option';
|
|
3
|
+
import * as Effect from '@effect/io/Effect';
|
|
4
|
+
import * as Fx from '@typed/fx';
|
|
5
|
+
import { RenderContext } from '@typed/html';
|
|
6
|
+
import { Redirect } from './Redirect.js';
|
|
7
|
+
import { Router, getCurrentPathFromUrl } from './router.js';
|
|
8
|
+
export function matchRoutes(matches, onNotFound = () => Fx.empty()) {
|
|
9
|
+
return Fx.gen(function* ($) {
|
|
10
|
+
const { environment } = yield* $(RenderContext);
|
|
11
|
+
const isBrowser = environment === 'browser';
|
|
12
|
+
const router = yield* $(Router);
|
|
13
|
+
const notFound = onNotFound(router.params);
|
|
14
|
+
const matchers = matches.map((match) => {
|
|
15
|
+
const nestedRouter = router.define(match.route);
|
|
16
|
+
const render = pipe(nestedRouter.params, match.render, Fx.provideService(Router, nestedRouter), Fx.scoped);
|
|
17
|
+
return [
|
|
18
|
+
match.route,
|
|
19
|
+
render,
|
|
20
|
+
match.options?.guard,
|
|
21
|
+
match.options?.onMatch,
|
|
22
|
+
];
|
|
23
|
+
});
|
|
24
|
+
const length = matchers.length;
|
|
25
|
+
const matched = yield* $(Fx.makeRef(Effect.succeed(Fx.empty())));
|
|
26
|
+
const matchPath = (path) => Effect.gen(function* ($) {
|
|
27
|
+
for (let i = 0; i < length; ++i) {
|
|
28
|
+
const [route, render, guard, onMatch] = matchers[i];
|
|
29
|
+
const params = route.match(path);
|
|
30
|
+
if (Option.isSome(params)) {
|
|
31
|
+
// If there is a guard and it fails, continue to next route
|
|
32
|
+
if (guard && !(yield* $(guard(params.value)))) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
// If there is an onMatch handler, run it and catch any errors
|
|
36
|
+
// This is useful when you want to add tracking when a route is matched
|
|
37
|
+
if (onMatch) {
|
|
38
|
+
yield* $(onMatch(params.value), Effect.catchAllCause((cause) => matched.error(cause)), Effect.forkScoped);
|
|
39
|
+
}
|
|
40
|
+
return yield* $(matched.set(render));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return yield* $(matched.set(notFound));
|
|
44
|
+
});
|
|
45
|
+
// Match a Route when navigation occurs
|
|
46
|
+
yield* $(router.navigation.onNavigation((event) => matchPath(getCurrentPathFromUrl(event.destination.url))));
|
|
47
|
+
return pipe(matched, isBrowser ? identity : Fx.take(1), Redirect.switchMatch((r) => Fx.as(Fx.fromEffect(router.navigation.navigate(r.url, r.options)), Option.none()), Fx.map(Option.some)), Fx.compact);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=matchRoutes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matchRoutes.js","sourceRoot":"","sources":["../src/matchRoutes.ts"],"names":[],"mappings":"AAAA,OA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