htmx-router 1.0.3 → 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.
@@ -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" }
@@ -17,6 +17,7 @@ export class GenericContext {
17
17
  this.url = url;
18
18
  this.render = renderer;
19
19
  this.headers.set("x-powered-by", "htmx-router");
20
+ this.headers.set("content-type", "text/html");
20
21
  }
21
22
  shape(shape) {
22
23
  return new RouteContext(this, this.params, shape);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "htmx-router",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "A lightweight SSR framework with server+client islands",
5
5
  "keywords": [
6
6
  "htmx",
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,11 +156,11 @@ 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) {
@@ -183,7 +185,7 @@ class RouteLeaf {
183
185
  this.module = module;
184
186
  }
185
187
  async resolve(ctx) {
186
- const res = await this.renderWrapper(ctx);
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 renderWrapper(ctx) {
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 | string): {
67
+ export declare function MakeStatus(lookup: number | StatusText): {
66
68
  status: number;
67
- statusText: string;
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",