htmx-router 2.1.4 → 2.1.6
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/index.d.ts +2 -1
- package/dist/internal/client.js +0 -2
- package/dist/internal/component/scripts.js +3 -1
- package/dist/response.js +19 -7
- package/package.json +1 -1
- package/global.d.ts +0 -26
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ParameterShaper } from "./util/parameters.js";
|
|
2
|
+
import type { GenericContext } from "./internal/router.js";
|
|
2
3
|
import type { RouteContext } from "./router.js";
|
|
3
4
|
export type RenderFunction<T extends ParameterShaper = {}> = (ctx: RouteContext<T>) => Promise<Response | JSX.Element | null>;
|
|
4
5
|
export type CatchFunction<T extends ParameterShaper = {}> = (ctx: RouteContext<T>, err: unknown) => Promise<Response | JSX.Element>;
|
|
@@ -15,4 +16,4 @@ export type ClientIslandManifest<T> = {
|
|
|
15
16
|
type ClientIsland<T> = T extends (props: infer P) => JSX.Element ? (props: P & {
|
|
16
17
|
children?: JSX.Element;
|
|
17
18
|
}) => JSX.Element : T;
|
|
18
|
-
export { RouteContext };
|
|
19
|
+
export { RouteContext, GenericContext };
|
package/dist/internal/client.js
CHANGED
|
@@ -2,8 +2,6 @@ import { ServerOnlyWarning } from "./util.js";
|
|
|
2
2
|
ServerOnlyWarning("client-url");
|
|
3
3
|
import { readFile } from "fs/promises";
|
|
4
4
|
export async function GetClientEntryURL() {
|
|
5
|
-
if (import.meta.env.DEV)
|
|
6
|
-
return "/app/entry.client.ts";
|
|
7
5
|
const config = JSON.parse(await readFile("./dist/client/.vite/manifest.json", "utf8"));
|
|
8
6
|
for (const key in config) {
|
|
9
7
|
const def = config[key];
|
|
@@ -3,7 +3,9 @@ import { GetMountUrl } from 'htmx-router/internal/mount';
|
|
|
3
3
|
import { GetSheetUrl } from 'htmx-router/css';
|
|
4
4
|
|
|
5
5
|
let cache: JSX.Element | null = null;
|
|
6
|
-
const clientEntry =
|
|
6
|
+
const clientEntry = import.meta.env.DEV
|
|
7
|
+
? "/app/entry.client.ts"
|
|
8
|
+
: await GetClientEntryURL();
|
|
7
9
|
export function Scripts() {
|
|
8
10
|
if (cache) return cache;
|
|
9
11
|
|
package/dist/response.js
CHANGED
|
@@ -108,17 +108,29 @@ export function AssertETagStale(request, headers, etag, options) {
|
|
|
108
108
|
headers.append("Cache-Control", `max-age=${options.revalidate}`);
|
|
109
109
|
}
|
|
110
110
|
headers.append("Cache-Control", "must-revalidate");
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
111
|
+
etag = encodeURIComponent(etag.trim()); // safely handle any special characters
|
|
112
|
+
headers.set("ETag", `"${etag}"`);
|
|
113
|
+
const rules = request.headers.get("if-none-match");
|
|
114
|
+
if (!rules || !MatchEtags(rules.trim(), etag))
|
|
114
115
|
return;
|
|
115
|
-
const res = new Response(null, {
|
|
116
|
-
status: 304, statusText: "Not Modified",
|
|
117
|
-
headers
|
|
118
|
-
});
|
|
116
|
+
const res = new Response(null, { headers, status: 304, statusText: "Not Modified" });
|
|
119
117
|
res.headers.set("X-Caught", "true");
|
|
120
118
|
throw res;
|
|
121
119
|
}
|
|
120
|
+
function MatchEtags(header, etag) {
|
|
121
|
+
if (header === "*")
|
|
122
|
+
return true;
|
|
123
|
+
for (const term of header.split(/,\s*/)) {
|
|
124
|
+
let s = term.startsWith('W/') ? 'W/'.length : 0;
|
|
125
|
+
let e = term.endsWith('"') ? term.length - 1 : term.length;
|
|
126
|
+
if (term.startsWith('"', s))
|
|
127
|
+
s++;
|
|
128
|
+
const tag = term.slice(s, e);
|
|
129
|
+
if (etag === tag)
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
122
134
|
/**
|
|
123
135
|
* This is to fix issues with deno
|
|
124
136
|
* When you try and change the statusText on a Response object
|
package/package.json
CHANGED
package/global.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
declare namespace JSX {
|
|
2
|
-
interface Element {}
|
|
3
|
-
interface IntrinsicElements {
|
|
4
|
-
[elementName: string]: any;
|
|
5
|
-
}
|
|
6
|
-
interface Fragment {}
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
interface ImportMeta {
|
|
10
|
-
glob: (
|
|
11
|
-
pattern: string,
|
|
12
|
-
options?: {
|
|
13
|
-
eager?: boolean;
|
|
14
|
-
import?: string;
|
|
15
|
-
as?: string;
|
|
16
|
-
}
|
|
17
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
|
-
) => Record<string, any>;
|
|
19
|
-
env: {
|
|
20
|
-
BASE_URL: string,
|
|
21
|
-
DEV: boolean,
|
|
22
|
-
MODE: string,
|
|
23
|
-
PROD: boolean,
|
|
24
|
-
SSR: true,
|
|
25
|
-
} & Record<`VITE_${string}`, string>
|
|
26
|
-
}
|