htmx-router 1.0.2 → 1.0.4
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/defer.d.ts +1 -1
- package/defer.js +2 -7
- package/endpoint.d.ts +1 -1
- package/endpoint.js +1 -6
- package/internal/component/defer.js +1 -1
- package/internal/component/head.js +1 -1
- package/internal/router.js +1 -0
- package/package.json +1 -1
- package/router.js +8 -6
- package/status.d.ts +4 -2
- package/status.js +2 -0
package/defer.d.ts
CHANGED
|
@@ -10,5 +10,5 @@ export declare const path = "_/defer/$";
|
|
|
10
10
|
export declare const parameters: {
|
|
11
11
|
$: StringConstructor;
|
|
12
12
|
};
|
|
13
|
-
export declare function loader(ctx: RouteContext<typeof parameters>): Promise<
|
|
13
|
+
export declare function loader(ctx: RouteContext<typeof parameters>): Promise<JSX.Element | null>;
|
|
14
14
|
export declare const action: typeof loader;
|
package/defer.js
CHANGED
|
@@ -68,13 +68,8 @@ export async function loader(ctx) {
|
|
|
68
68
|
console.warn(`Warn: Function ${endpoint.name} was not registered for defer use`);
|
|
69
69
|
return null;
|
|
70
70
|
}
|
|
71
|
-
const forward = new RouteContext(ctx, prelude, entry.shape);
|
|
72
|
-
const res = await endpoint(forward);
|
|
73
|
-
if (res instanceof Response)
|
|
74
|
-
return res;
|
|
75
|
-
if (res === null)
|
|
76
|
-
return null;
|
|
77
71
|
ctx.headers.set("X-Partial", "true");
|
|
78
|
-
|
|
72
|
+
const forward = new RouteContext(ctx, prelude, entry.shape);
|
|
73
|
+
return await endpoint(forward);
|
|
79
74
|
}
|
|
80
75
|
export const action = loader;
|
package/endpoint.d.ts
CHANGED
|
@@ -16,5 +16,5 @@ export declare const path = "_/endpoint/$";
|
|
|
16
16
|
export declare const parameters: {
|
|
17
17
|
$: StringConstructor;
|
|
18
18
|
};
|
|
19
|
-
export declare function loader(ctx: RouteContext<typeof parameters>): Promise<
|
|
19
|
+
export declare function loader(ctx: RouteContext<typeof parameters>): Promise<JSX.Element | null>;
|
|
20
20
|
export declare const action: typeof loader;
|
package/endpoint.js
CHANGED
|
@@ -30,11 +30,6 @@ export async function loader(ctx) {
|
|
|
30
30
|
const endpoint = registry.get(ctx.params["$"]);
|
|
31
31
|
if (!endpoint)
|
|
32
32
|
return null;
|
|
33
|
-
|
|
34
|
-
if (res === null)
|
|
35
|
-
return null;
|
|
36
|
-
if (res instanceof Response)
|
|
37
|
-
return res;
|
|
38
|
-
return ctx.render(res, ctx.headers);
|
|
33
|
+
return await endpoint.render(ctx);
|
|
39
34
|
}
|
|
40
35
|
export const action = loader;
|
|
@@ -5,7 +5,7 @@ import { Deferral } from "htmx-router/defer";
|
|
|
5
5
|
export function Defer<T extends ParameterShaper>(props: {
|
|
6
6
|
params?: Parameterized<T>,
|
|
7
7
|
loader: RenderFunction<T>,
|
|
8
|
-
children?: JSX.Element
|
|
8
|
+
children?: JSX.Element[] | JSX.Element
|
|
9
9
|
}): JSX.Element {
|
|
10
10
|
return <div
|
|
11
11
|
hx-get={Deferral(props.loader, props.params)}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const generic = `import { RenderMetaDescriptor, ShellOptions } from "htmx-router/shell";
|
|
2
2
|
|
|
3
|
-
export function Head<T>(props: { options: ShellOptions<T>, children: JSX.Element }) {
|
|
3
|
+
export function Head<T>(props: { options: ShellOptions<T>, children: JSX.Element[] | JSX.Element }) {
|
|
4
4
|
return <head>
|
|
5
5
|
{ RenderMetaDescriptor(props.options) as "safe" }
|
|
6
6
|
{ props.children as "safe" }
|
package/internal/router.js
CHANGED
package/package.json
CHANGED
package/router.js
CHANGED
|
@@ -132,6 +132,8 @@ export class RouteTree {
|
|
|
132
132
|
const res = await this.index.resolve(ctx);
|
|
133
133
|
if (res instanceof Response)
|
|
134
134
|
return res;
|
|
135
|
+
if (res === null)
|
|
136
|
+
return null;
|
|
135
137
|
return new Response(res, { headers: ctx.headers });
|
|
136
138
|
}
|
|
137
139
|
async resolveNext(fragments, ctx) {
|
|
@@ -154,17 +156,17 @@ export class RouteTree {
|
|
|
154
156
|
if (!this.slug)
|
|
155
157
|
return null;
|
|
156
158
|
ctx.params["$"] = fragments.join("/");
|
|
157
|
-
const res = this.slug.resolve
|
|
158
|
-
? await this.slug.resolve(ctx)
|
|
159
|
-
: null;
|
|
159
|
+
const res = await this.slug.resolve(ctx);
|
|
160
160
|
if (res instanceof Response)
|
|
161
161
|
return res;
|
|
162
|
+
if (res === null)
|
|
163
|
+
return null;
|
|
162
164
|
return new Response(res, { headers: ctx.headers });
|
|
163
165
|
}
|
|
164
166
|
async unwrap(ctx, res) {
|
|
165
167
|
if (!this.slug)
|
|
166
168
|
throw res;
|
|
167
|
-
|
|
169
|
+
const caught = await this.slug.error(ctx, res);
|
|
168
170
|
if (caught instanceof Response) {
|
|
169
171
|
caught.headers.set("X-Caught", "true");
|
|
170
172
|
return caught;
|
|
@@ -183,7 +185,7 @@ class RouteLeaf {
|
|
|
183
185
|
this.module = module;
|
|
184
186
|
}
|
|
185
187
|
async resolve(ctx) {
|
|
186
|
-
const res = await this.
|
|
188
|
+
const res = await this.response(ctx);
|
|
187
189
|
if (res === null)
|
|
188
190
|
return null;
|
|
189
191
|
if (res instanceof Response)
|
|
@@ -198,7 +200,7 @@ class RouteLeaf {
|
|
|
198
200
|
return res;
|
|
199
201
|
return await ctx.render(res, ctx.headers);
|
|
200
202
|
}
|
|
201
|
-
async
|
|
203
|
+
async response(ctx) {
|
|
202
204
|
try {
|
|
203
205
|
if (!this.module.loader && !this.module.action)
|
|
204
206
|
return null;
|
package/status.d.ts
CHANGED
|
@@ -20,11 +20,13 @@ declare const definitions: {
|
|
|
20
20
|
304: "Not Modified";
|
|
21
21
|
305: "Use Proxy";
|
|
22
22
|
306: "Switch Proxy";
|
|
23
|
+
307: "Temporary Redirect";
|
|
23
24
|
308: "Permanent Redirect";
|
|
24
25
|
400: "Bad Request";
|
|
25
26
|
401: "Unauthorized";
|
|
26
27
|
402: "Payment Required";
|
|
27
28
|
403: "Forbidden";
|
|
29
|
+
404: "Not Found";
|
|
28
30
|
405: "Method Not Allowed";
|
|
29
31
|
406: "Not Acceptable";
|
|
30
32
|
407: "Proxy Authentication Required";
|
|
@@ -62,8 +64,8 @@ declare const definitions: {
|
|
|
62
64
|
511: "Network Authentication Required";
|
|
63
65
|
};
|
|
64
66
|
export type StatusText = typeof definitions[keyof typeof definitions];
|
|
65
|
-
export declare function MakeStatus(lookup: number | StatusText
|
|
67
|
+
export declare function MakeStatus(lookup: number | StatusText): {
|
|
66
68
|
status: number;
|
|
67
|
-
statusText:
|
|
69
|
+
statusText: StatusText;
|
|
68
70
|
};
|
|
69
71
|
export {};
|
package/status.js
CHANGED
|
@@ -20,11 +20,13 @@ const definitions = {
|
|
|
20
20
|
304: "Not Modified",
|
|
21
21
|
305: "Use Proxy",
|
|
22
22
|
306: "Switch Proxy",
|
|
23
|
+
307: "Temporary Redirect",
|
|
23
24
|
308: "Permanent Redirect",
|
|
24
25
|
400: "Bad Request",
|
|
25
26
|
401: "Unauthorized",
|
|
26
27
|
402: "Payment Required",
|
|
27
28
|
403: "Forbidden",
|
|
29
|
+
404: "Not Found",
|
|
28
30
|
405: "Method Not Allowed",
|
|
29
31
|
406: "Not Acceptable",
|
|
30
32
|
407: "Proxy Authentication Required",
|