@esportsplus/routing 0.7.1 → 0.7.3
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/build/client/index.d.ts +0 -1
- package/build/client/index.js +10 -11
- package/build/client/router/index.js +15 -12
- package/package.json +1 -1
- package/src/client/index.ts +1 -3
- package/src/client/router/index.ts +19 -14
package/build/client/index.d.ts
CHANGED
|
@@ -10,7 +10,6 @@ declare const router: <const Factories extends readonly RouteFactory<any>[]>(...
|
|
|
10
10
|
match(fallback: Route<InferOutput<Factories[number]>>): (request: Request<InferOutput<Factories[number]>>, next: Next<InferOutput<Factories[number]>>) => InferOutput<Factories[number]>;
|
|
11
11
|
};
|
|
12
12
|
redirect: <RouteName extends keyof AccumulateRoutes<Factories>>(name: RouteName, ...values: ExtractRequiredParams<RoutePath<AccumulateRoutes<Factories>, RouteName>> extends never ? ExtractOptionalParams<RoutePath<AccumulateRoutes<Factories>, RouteName>> extends never ? [] : [params?: PathParamsObject<RoutePath<AccumulateRoutes<Factories>, RouteName>>] : [params: PathParamsObject<RoutePath<AccumulateRoutes<Factories>, RouteName>>]) => void;
|
|
13
|
-
routes: Record<string, Route<InferOutput<Factories[number]>>>;
|
|
14
13
|
uri: <RouteName extends keyof AccumulateRoutes<Factories>>(name: RouteName, ...values: ExtractRequiredParams<RoutePath<AccumulateRoutes<Factories>, RouteName>> extends never ? ExtractOptionalParams<RoutePath<AccumulateRoutes<Factories>, RouteName>> extends never ? [] : [params?: PathParamsObject<RoutePath<AccumulateRoutes<Factories>, RouteName>>] : [params: PathParamsObject<RoutePath<AccumulateRoutes<Factories>, RouteName>>]) => string;
|
|
15
14
|
};
|
|
16
15
|
export { router };
|
package/build/client/index.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as reactivity_b8c1970d69d44d969d8e19418a3a5cc10 from '@esportsplus/reactivity';
|
|
2
2
|
import { effect, root } from '@esportsplus/reactivity';
|
|
3
3
|
import { Router } from './router/index.js';
|
|
4
4
|
import { PACKAGE_NAME } from './constants.js';
|
|
5
|
-
class
|
|
5
|
+
class ReactiveObject_b8c1970d69d44d969d8e19418a3a5cc11 extends reactivity_b8c1970d69d44d969d8e19418a3a5cc10.ReactiveObject {
|
|
6
6
|
#parameters;
|
|
7
7
|
#route;
|
|
8
8
|
constructor(_p0, _p1) {
|
|
9
9
|
super(null);
|
|
10
|
-
this.#parameters = this[
|
|
11
|
-
this.#route = this[
|
|
10
|
+
this.#parameters = this[reactivity_b8c1970d69d44d969d8e19418a3a5cc10.SIGNAL](_p0);
|
|
11
|
+
this.#route = this[reactivity_b8c1970d69d44d969d8e19418a3a5cc10.SIGNAL](_p1);
|
|
12
12
|
}
|
|
13
13
|
get parameters() {
|
|
14
|
-
return
|
|
14
|
+
return reactivity_b8c1970d69d44d969d8e19418a3a5cc10.read(this.#parameters);
|
|
15
15
|
}
|
|
16
16
|
set parameters(_v0) {
|
|
17
|
-
|
|
17
|
+
reactivity_b8c1970d69d44d969d8e19418a3a5cc10.write(this.#parameters, _v0);
|
|
18
18
|
}
|
|
19
19
|
get route() {
|
|
20
|
-
return
|
|
20
|
+
return reactivity_b8c1970d69d44d969d8e19418a3a5cc10.read(this.#route);
|
|
21
21
|
}
|
|
22
22
|
set route(_v1) {
|
|
23
|
-
|
|
23
|
+
reactivity_b8c1970d69d44d969d8e19418a3a5cc10.write(this.#route, _v1);
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
let cache = [], location = window.location;
|
|
@@ -90,7 +90,7 @@ function middleware(request, router) {
|
|
|
90
90
|
return route.middleware(request);
|
|
91
91
|
};
|
|
92
92
|
host.match = (fallback) => {
|
|
93
|
-
let state = new
|
|
93
|
+
let state = new ReactiveObject_b8c1970d69d44d969d8e19418a3a5cc11(undefined, undefined);
|
|
94
94
|
if (fallback === undefined) {
|
|
95
95
|
throw new Error(`${PACKAGE_NAME}: fallback route does not exist`);
|
|
96
96
|
}
|
|
@@ -130,7 +130,7 @@ function onpopstate() {
|
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
132
|
const router = (...factories) => {
|
|
133
|
-
let instance = factories.reduce((r, factory) => factory(r), new Router()), request =
|
|
133
|
+
let instance = factories.reduce((r, factory) => factory(r), new Router()), request = reactivity_b8c1970d69d44d969d8e19418a3a5cc10.reactive(Object.assign(href(), { data: {} }));
|
|
134
134
|
if (cache.push(request) === 1) {
|
|
135
135
|
window.addEventListener('hashchange', onpopstate);
|
|
136
136
|
}
|
|
@@ -144,7 +144,6 @@ const router = (...factories) => {
|
|
|
144
144
|
}
|
|
145
145
|
window.location.hash = normalize(instance.uri(name, values));
|
|
146
146
|
},
|
|
147
|
-
routes: instance.routes,
|
|
148
147
|
uri: (name, ...values) => {
|
|
149
148
|
return normalize(instance.uri(name, values));
|
|
150
149
|
}
|
|
@@ -16,20 +16,23 @@ function normalize(path) {
|
|
|
16
16
|
}
|
|
17
17
|
function set(route, options) {
|
|
18
18
|
let middleware = route.middleware;
|
|
19
|
-
|
|
20
|
-
let
|
|
21
|
-
|
|
22
|
-
for (let i = 0, n = value.length; i < n; i++) {
|
|
23
|
-
middleware.push(value[i]);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
else if (key === 'responder') {
|
|
27
|
-
middleware.push(value);
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
route[key] = (route[key] || '') + value;
|
|
19
|
+
if (options.middleware) {
|
|
20
|
+
for (let i = 0, n = options.middleware.length; i < n; i++) {
|
|
21
|
+
middleware.push(options.middleware[i]);
|
|
31
22
|
}
|
|
32
23
|
}
|
|
24
|
+
if ('responder' in options) {
|
|
25
|
+
middleware.push(options.responder);
|
|
26
|
+
}
|
|
27
|
+
if (options.name) {
|
|
28
|
+
route.name = (route.name || '') + options.name;
|
|
29
|
+
}
|
|
30
|
+
if (options.path) {
|
|
31
|
+
route.path = (route.path || '') + options.path;
|
|
32
|
+
}
|
|
33
|
+
if (options.subdomain) {
|
|
34
|
+
route.subdomain = (route.subdomain || '') + options.subdomain;
|
|
35
|
+
}
|
|
33
36
|
}
|
|
34
37
|
class Router {
|
|
35
38
|
bucket = {};
|
package/package.json
CHANGED
package/src/client/index.ts
CHANGED
|
@@ -149,8 +149,7 @@ function onpopstate() {
|
|
|
149
149
|
let state = cache[i];
|
|
150
150
|
|
|
151
151
|
for (let key in values) {
|
|
152
|
-
|
|
153
|
-
state[key] = values[key];
|
|
152
|
+
(state as Record<string, unknown>)[key] = (values as Record<string, unknown>)[key];
|
|
154
153
|
}
|
|
155
154
|
}
|
|
156
155
|
}
|
|
@@ -188,7 +187,6 @@ const router = <const Factories extends readonly RouteFactory<any>[]>(...factori
|
|
|
188
187
|
|
|
189
188
|
window.location.hash = normalize(instance.uri(name as any, values as any));
|
|
190
189
|
},
|
|
191
|
-
routes: instance.routes,
|
|
192
190
|
uri: <RouteName extends keyof Routes>(
|
|
193
191
|
name: RouteName,
|
|
194
192
|
...values: ExtractRequiredParams<RoutePath<Routes, RouteName>> extends never
|
|
@@ -24,22 +24,27 @@ function normalize(path: string) {
|
|
|
24
24
|
function set<T>(route: Route<T>, options: Options<T> | RouteOptions<T>) {
|
|
25
25
|
let middleware = route.middleware as Middleware<T>[];
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
let
|
|
29
|
-
|
|
30
|
-
if (key === 'middleware') {
|
|
31
|
-
for (let i = 0, n = value.length; i < n; i++) {
|
|
32
|
-
middleware.push(value[i]);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
else if (key === 'responder') {
|
|
36
|
-
middleware.push(value);
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
// @ts-ignore
|
|
40
|
-
route[key] = (route[key] || '') + value;
|
|
27
|
+
if (options.middleware) {
|
|
28
|
+
for (let i = 0, n = options.middleware.length; i < n; i++) {
|
|
29
|
+
middleware.push(options.middleware[i]);
|
|
41
30
|
}
|
|
42
31
|
}
|
|
32
|
+
|
|
33
|
+
if ('responder' in options) {
|
|
34
|
+
middleware.push((options as RouteOptions<T>).responder);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (options.name) {
|
|
38
|
+
route.name = (route.name || '') + options.name;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (options.path) {
|
|
42
|
+
route.path = (route.path || '') + options.path;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (options.subdomain) {
|
|
46
|
+
route.subdomain = (route.subdomain || '') + options.subdomain;
|
|
47
|
+
}
|
|
43
48
|
}
|
|
44
49
|
|
|
45
50
|
|