@kasperrt/smolter 0.4.2 → 0.4.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/.generated/client/hash-history.ts +27 -0
- package/.generated/client/hydration.ts +98 -0
- package/.generated/client/root-data.ts +52 -0
- package/.generated/core/environment.ts +1 -0
- package/.generated/core/navigation.ts +1 -0
- package/.generated/core/prepare-routes.ts +50 -0
- package/.generated/core/presentation.ts +1 -1
- package/.generated/core/responses.ts +12 -0
- package/.generated/core/utils.ts +5 -2
- package/.generated/preact/await.tsx +1 -0
- package/.generated/preact/client.tsx +8 -27
- package/.generated/preact/deferred-hydration.ts +1 -98
- package/.generated/preact/document.tsx +10 -0
- package/.generated/preact/index.ts +11 -2
- package/.generated/preact/lazy-route.ts +7 -0
- package/.generated/preact/navigation.tsx +19 -5
- package/.generated/preact/root-data.ts +1 -45
- package/.generated/preact/route-hooks.tsx +12 -2
- package/.generated/preact/route-types.ts +14 -0
- package/.generated/preact/router.tsx +5 -48
- package/.generated/react/client.tsx +130 -0
- package/.generated/react/document.tsx +235 -0
- package/.generated/react/fetcher.ts +29 -7
- package/.generated/react/hooks.ts +20 -18
- package/.generated/react/index.ts +28 -2
- package/.generated/react/lazy-route.ts +116 -0
- package/.generated/react/link.ts +1 -38
- package/.generated/react/navigation-state.ts +13 -0
- package/.generated/react/navigation.ts +145 -0
- package/.generated/react/outlet.ts +48 -0
- package/.generated/react/root-context.ts +22 -0
- package/.generated/react/route-hooks.ts +159 -0
- package/.generated/react/route-types.ts +91 -0
- package/.generated/react/router.ts +50 -0
- package/.generated/react/runtime.ts +1 -0
- package/.generated/server/application.tsx +18 -250
- package/.generated/server/assets.ts +7 -0
- package/.generated/server/dispatch.ts +87 -0
- package/.generated/server/handler.ts +3 -0
- package/.generated/server/http.ts +2 -0
- package/.generated/server/index.ts +2 -0
- package/.generated/server/node.ts +5 -2
- package/.generated/server/preact.ts +5 -2
- package/.generated/server/react.ts +34 -0
- package/.generated/server/render-application.ts +203 -0
- package/.generated/vite/application/lazy-files.ts +2 -1
- package/.generated/vite/application/vite.ts +12 -4
- package/.generated/vite/react.ts +11 -0
- package/CHANGELOG.md +20 -0
- package/README.md +48 -48
- package/dist/client/hash-history.d.ts +2 -0
- package/dist/client/hash-history.js +26 -0
- package/dist/client/hydration.d.ts +10 -0
- package/dist/{preact/deferred-hydration.js → client/hydration.js} +1 -1
- package/dist/client/root-data.d.ts +14 -0
- package/dist/{preact → client}/root-data.js +1 -1
- package/dist/core/environment.d.ts +1 -0
- package/dist/core/navigation.d.ts +1 -0
- package/dist/core/prepare-routes.d.ts +7 -0
- package/dist/core/prepare-routes.js +28 -0
- package/dist/core/presentation.js +1 -1
- package/dist/core/responses.d.ts +12 -0
- package/dist/core/responses.js +5 -0
- package/dist/core/utils.d.ts +5 -2
- package/dist/core/utils.js +1 -2
- package/dist/preact/await.d.ts +1 -0
- package/dist/preact/await.js +1 -0
- package/dist/preact/client.d.ts +7 -1
- package/dist/preact/client.js +11 -27
- package/dist/preact/deferred-hydration.d.ts +1 -10
- package/dist/preact/document.d.ts +10 -0
- package/dist/preact/document.js +11 -2
- package/dist/preact/index.d.ts +6 -2
- package/dist/preact/index.js +1 -1
- package/dist/preact/lazy-route.d.ts +2 -0
- package/dist/preact/lazy-route.js +6 -0
- package/dist/preact/navigation-state.js +1 -1
- package/dist/preact/navigation.d.ts +6 -0
- package/dist/preact/navigation.js +9 -5
- package/dist/preact/root-data.d.ts +1 -8
- package/dist/preact/route-hooks.d.ts +10 -0
- package/dist/preact/route-hooks.js +13 -3
- package/dist/preact/route-types.d.ts +14 -0
- package/dist/preact/router.d.ts +5 -2
- package/dist/preact/router.js +4 -26
- package/dist/react/client.d.ts +20 -0
- package/dist/react/client.js +86 -0
- package/dist/react/document.d.ts +25 -0
- package/dist/react/document.js +169 -0
- package/dist/react/fetcher.d.ts +8 -4
- package/dist/react/fetcher.js +12 -1
- package/dist/react/form.js +1 -1
- package/dist/react/hooks.d.ts +7 -6
- package/dist/react/index.d.ts +13 -2
- package/dist/react/index.js +7 -2
- package/dist/react/lazy-route.d.ts +22 -0
- package/dist/react/lazy-route.js +57 -0
- package/dist/react/link.d.ts +1 -12
- package/dist/react/navigation-state.d.ts +2 -0
- package/dist/react/navigation-state.js +9 -0
- package/dist/react/navigation.d.ts +33 -0
- package/dist/react/navigation.js +64 -0
- package/dist/react/outlet.d.ts +16 -0
- package/dist/react/outlet.js +26 -0
- package/dist/react/root-context.d.ts +14 -0
- package/dist/react/root-context.js +10 -0
- package/dist/react/route-hooks.d.ts +34 -0
- package/dist/react/route-hooks.js +89 -0
- package/dist/react/route-types.d.ts +69 -0
- package/dist/react/router.d.ts +10 -0
- package/dist/react/router.js +22 -0
- package/dist/react/runtime.d.ts +1 -1
- package/dist/react/runtime.js +1 -1
- package/dist/server/application.d.ts +4 -5
- package/dist/server/application.js +9 -154
- package/dist/server/assets.d.ts +2 -0
- package/dist/server/assets.js +6 -0
- package/dist/server/dispatch.d.ts +5 -0
- package/dist/server/dispatch.js +50 -0
- package/dist/server/handler.d.ts +3 -0
- package/dist/server/http.d.ts +2 -0
- package/dist/server/http.js +2 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +2 -1
- package/dist/server/node.d.ts +5 -1
- package/dist/server/preact.d.ts +5 -1
- package/dist/server/preact.js +2 -1
- package/dist/server/react.d.ts +10 -0
- package/dist/server/react.js +22 -0
- package/dist/server/render-application.d.ts +31 -0
- package/dist/server/render-application.js +118 -0
- package/dist/vite/application/lazy-files.d.ts +1 -1
- package/dist/vite/application/lazy-files.js +2 -2
- package/dist/vite/application/vite.d.ts +2 -1
- package/dist/vite/application/vite.js +12 -5
- package/dist/vite/react.d.ts +4 -0
- package/dist/vite/react.js +9 -1
- package/jsr.json +10 -6
- package/package.json +21 -12
- package/.generated/core/resource-types.ts +0 -44
- package/.generated/core/resources.ts +0 -444
- package/.generated/react/data.ts +0 -25
- package/.generated/react/resources/components.tsx +0 -404
- package/dist/core/resource-types.d.ts +0 -37
- package/dist/core/resources.d.ts +0 -19
- package/dist/core/resources.js +0 -345
- package/dist/react/data.d.ts +0 -5
- package/dist/react/data.js +0 -3
- package/dist/react/link.js +0 -27
- package/dist/react/resources/components.d.ts +0 -64
- package/dist/react/resources/components.js +0 -239
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createStore } from "../core/store.js";
|
|
2
|
-
//#region .generated/
|
|
2
|
+
//#region .generated/client/root-data.ts
|
|
3
3
|
function attachRootData(router, initial, rootModule) {
|
|
4
4
|
const store = createStore(initial);
|
|
5
5
|
const loaderPath = rootModule?.loaderPath;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { normalizeResult } from "./responses.js";
|
|
2
|
+
//#region .generated/core/prepare-routes.ts
|
|
3
|
+
function prepareRoutes(routes, preserveDeferred = false) {
|
|
4
|
+
return routes.map((route) => {
|
|
5
|
+
const wrapped = {
|
|
6
|
+
...route,
|
|
7
|
+
path: route.routePath ?? route.path,
|
|
8
|
+
shouldRevalidate: (args) => {
|
|
9
|
+
const { currentUrl, nextUrl } = args;
|
|
10
|
+
if (args.reason === "navigation" && currentUrl.pathname === nextUrl.pathname && currentUrl.search === nextUrl.search && currentUrl.hash !== nextUrl.hash) return false;
|
|
11
|
+
return route.shouldRevalidate?.(args) ?? args.defaultShouldRevalidate;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
for (const key of [
|
|
15
|
+
"loader",
|
|
16
|
+
"action",
|
|
17
|
+
"clientLoader",
|
|
18
|
+
"clientAction"
|
|
19
|
+
]) {
|
|
20
|
+
const handler = route[key];
|
|
21
|
+
if (!handler) continue;
|
|
22
|
+
wrapped[key] = (args) => Promise.resolve().then(() => handler(args)).then((value) => normalizeResult(value, !preserveDeferred), (error) => normalizeResult(error, !preserveDeferred));
|
|
23
|
+
}
|
|
24
|
+
return wrapped;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { prepareRoutes };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
//#region .generated/core/presentation.ts
|
|
2
2
|
var pending = /* @__PURE__ */ new WeakMap();
|
|
3
3
|
function pendingLocation(router) {
|
|
4
|
-
const snapshot = pending.get(router)?.();
|
|
4
|
+
const snapshot = pending.get(router)?.() ?? router.getSnapshot();
|
|
5
5
|
return snapshot?.state !== "idle" && snapshot?.url ? new URL(snapshot.url) : void 0;
|
|
6
6
|
}
|
|
7
7
|
function retainRoute(router, commitView) {
|
package/dist/core/responses.d.ts
CHANGED
|
@@ -1,15 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP response helpers and loader result normalization.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
/** Normalized route failure with an HTTP status, status text and optional response data. */
|
|
1
7
|
export interface RouteError extends Error {
|
|
2
8
|
status: number;
|
|
3
9
|
statusText: string;
|
|
4
10
|
data?: unknown;
|
|
5
11
|
}
|
|
12
|
+
/** Loader value paired with HTTP response metadata. */
|
|
6
13
|
export interface DataResponse<T> {
|
|
7
14
|
value: T;
|
|
8
15
|
init: ResponseInit;
|
|
9
16
|
__routeData: true;
|
|
10
17
|
}
|
|
18
|
+
/** Wrap loader data with HTTP status and headers without creating a Response body. */
|
|
11
19
|
export declare function data<T>(value: T, init?: ResponseInit): DataResponse<T>;
|
|
20
|
+
/** Create an empty redirect Response with a Location header; defaults to HTTP 302. */
|
|
12
21
|
export declare function redirect(location: string, init?: number | ResponseInit): Response;
|
|
22
|
+
/** Identify normalized Error objects carrying an HTTP status. */
|
|
13
23
|
export declare function isRouteErrorResponse(value: unknown): value is RouteError;
|
|
24
|
+
/** Normalize transport responses and wrapped data, optionally resolving nested deferred values. */
|
|
14
25
|
export declare function normalizeResult(value: unknown, resolveDeferred?: boolean): Promise<unknown>;
|
|
26
|
+
/** Recursively resolve promises in arrays and plain objects before JSON serialization. */
|
|
15
27
|
export declare function resolveData(value: unknown): Promise<unknown>;
|
package/dist/core/responses.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
//#region .generated/core/responses.ts
|
|
2
|
+
/** Wrap loader data with HTTP status and headers without creating a Response body. */
|
|
2
3
|
function data(value, init = {}) {
|
|
3
4
|
return {
|
|
4
5
|
value,
|
|
@@ -6,6 +7,7 @@ function data(value, init = {}) {
|
|
|
6
7
|
__routeData: true
|
|
7
8
|
};
|
|
8
9
|
}
|
|
10
|
+
/** Create an empty redirect Response with a Location header; defaults to HTTP 302. */
|
|
9
11
|
function redirect(location, init = 302) {
|
|
10
12
|
const options = typeof init === "number" ? { status: init } : init;
|
|
11
13
|
const headers = new Headers(options.headers);
|
|
@@ -16,9 +18,11 @@ function redirect(location, init = 302) {
|
|
|
16
18
|
headers
|
|
17
19
|
});
|
|
18
20
|
}
|
|
21
|
+
/** Identify normalized Error objects carrying an HTTP status. */
|
|
19
22
|
function isRouteErrorResponse(value) {
|
|
20
23
|
return value instanceof Error && "status" in value;
|
|
21
24
|
}
|
|
25
|
+
/** Normalize transport responses and wrapped data, optionally resolving nested deferred values. */
|
|
22
26
|
async function normalizeResult(value, resolveDeferred = true) {
|
|
23
27
|
if (value && typeof value === "object" && "__routeError" in value) {
|
|
24
28
|
const error = value.__routeError;
|
|
@@ -35,6 +39,7 @@ async function normalizeResult(value, resolveDeferred = true) {
|
|
|
35
39
|
if (value && typeof value === "object" && "__routeData" in value) return resolveDeferred ? resolveData(value.value) : value.value;
|
|
36
40
|
return resolveDeferred ? resolveData(value) : value;
|
|
37
41
|
}
|
|
42
|
+
/** Recursively resolve promises in arrays and plain objects before JSON serialization. */
|
|
38
43
|
async function resolveData(value) {
|
|
39
44
|
const resolved = await value;
|
|
40
45
|
if (Array.isArray(resolved)) return Promise.all(resolved.map(resolveData));
|
package/dist/core/utils.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Routing patterns, query strings and serialized data utilities.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
3
6
|
export * from "./match.ts";
|
|
4
7
|
export * from "./serialize.ts";
|
|
5
8
|
export * from "./url.ts";
|
package/dist/core/utils.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { safeWrapAsync } from "./errors.js";
|
|
2
1
|
import { defineRoute, matchRoutes } from "./match.js";
|
|
3
2
|
import { internalURL, navigationClick } from "./url.js";
|
|
4
3
|
import { serialize, serializeData } from "./serialize.js";
|
|
5
|
-
export { defineRoute, internalURL, matchRoutes, navigationClick,
|
|
4
|
+
export { defineRoute, internalURL, matchRoutes, navigationClick, serialize, serializeData };
|
package/dist/preact/await.d.ts
CHANGED
|
@@ -7,4 +7,5 @@ export interface AwaitProps<T> {
|
|
|
7
7
|
/** Component-owned pending content, safe during early hydration. Pass null to render nothing. */
|
|
8
8
|
fallback?: ComponentChildren;
|
|
9
9
|
}
|
|
10
|
+
/** Render a value or promise. An explicit fallback owns pending content during early hydration; errorElement handles rejection. */
|
|
10
11
|
export declare function Await<T>(props: AwaitProps<T>): ComponentChildren;
|
package/dist/preact/await.js
CHANGED
|
@@ -4,6 +4,7 @@ import { use, useContext } from "preact/compat";
|
|
|
4
4
|
import { jsx } from "preact/jsx-runtime";
|
|
5
5
|
//#region .generated/preact/await.tsx
|
|
6
6
|
var resolutions = /* @__PURE__ */ new WeakMap();
|
|
7
|
+
/** Render a value or promise. An explicit fallback owns pending content during early hydration; errorElement handles rejection. */
|
|
7
8
|
function Await(props) {
|
|
8
9
|
const app = useContext(Application);
|
|
9
10
|
if (!(props.resolve instanceof Promise)) return props.children(props.resolve);
|
package/dist/preact/client.d.ts
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Preact document hydration, browser history and deployment recovery.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
2
6
|
/** @jsxImportSource preact */
|
|
3
7
|
import { type DeploymentOptions } from "../client/index.ts";
|
|
4
8
|
import { type Router } from "../core/index.ts";
|
|
5
9
|
import type { AppRoute, RootModule } from "./route-types.ts";
|
|
6
10
|
export * from "../client/index.ts";
|
|
7
11
|
export { configureApplication } from "../core/environment.ts";
|
|
12
|
+
/** Browser hydration settings for hash history, deployment recovery and deferred-data timeout. */
|
|
8
13
|
export interface MountApplicationOptions {
|
|
9
14
|
hash?: boolean;
|
|
10
15
|
deployment?: DeploymentOptions | null;
|
|
11
16
|
/** Total initial deferred-data budget in integer milliseconds; not an inactivity timeout. Defaults to 30,000. */
|
|
12
17
|
deferredTimeout?: number;
|
|
13
18
|
}
|
|
19
|
+
/** Create the browser application router and hydrate the document, installing recovery before initial lazy loading. */
|
|
14
20
|
export declare function mountApplication(routes: AppRoute[], rootModule?: RootModule, options?: boolean | MountApplicationOptions): Promise<Router>;
|
package/dist/preact/client.js
CHANGED
|
@@ -3,18 +3,25 @@ import { createDataRouter } from "../core/router.js";
|
|
|
3
3
|
import { configureApplication } from "../core/environment.js";
|
|
4
4
|
import { retainRoute } from "../core/presentation.js";
|
|
5
5
|
import { connectNavigation } from "../core/navigation.js";
|
|
6
|
-
import { attachRootData } from "
|
|
7
|
-
import {
|
|
6
|
+
import { attachRootData } from "../client/root-data.js";
|
|
7
|
+
import { prepareRoutes } from "../core/prepare-routes.js";
|
|
8
|
+
import { RouterApplication } from "./router.js";
|
|
8
9
|
import { deserialize } from "../client/deserialize.js";
|
|
9
10
|
import { recoverDeployment, watchDeployment } from "../client/deployment.js";
|
|
10
11
|
import { serverRoute } from "../client/index.js";
|
|
11
|
-
import {
|
|
12
|
+
import { connectHashHistory } from "../client/hash-history.js";
|
|
13
|
+
import { readHydration } from "../client/hydration.js";
|
|
12
14
|
import { flushSync } from "preact/compat";
|
|
13
15
|
import { jsx } from "preact/jsx-runtime";
|
|
14
16
|
import { hydrate, render } from "preact";
|
|
15
17
|
//#region .generated/preact/client.tsx
|
|
16
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* Preact document hydration, browser history and deployment recovery.
|
|
20
|
+
*
|
|
21
|
+
* @module
|
|
22
|
+
*/
|
|
17
23
|
/** @jsxImportSource preact */
|
|
24
|
+
/** Create the browser application router and hydrate the document, installing recovery before initial lazy loading. */
|
|
18
25
|
async function mountApplication(routes, rootModule, options = false) {
|
|
19
26
|
const { hash = false, deployment = null, deferredTimeout } = typeof options === "boolean" ? { hash: options } : options;
|
|
20
27
|
const initialURL = new URL(hash ? location.hash.slice(1) || "/" : location.href, location.origin);
|
|
@@ -69,28 +76,5 @@ async function mountApplication(routes, rootModule, options = false) {
|
|
|
69
76
|
if (target) render(/* @__PURE__ */ jsx(RouterApplication, { ...props }), target);
|
|
70
77
|
return router;
|
|
71
78
|
}
|
|
72
|
-
function connectHashHistory(router) {
|
|
73
|
-
const read = router.getSnapshot;
|
|
74
|
-
const navigate = router.navigate;
|
|
75
|
-
router.navigate = async (url, options) => {
|
|
76
|
-
const target = new URL(url, router.getSnapshot().url);
|
|
77
|
-
const hash = `#${target.pathname}${target.search}${target.hash}`;
|
|
78
|
-
history[options?.replace ? "replaceState" : "pushState"](null, "", hash);
|
|
79
|
-
await navigate(url, options);
|
|
80
|
-
};
|
|
81
|
-
const unsubscribe = router.subscribe(() => {
|
|
82
|
-
const target = new URL(read().url);
|
|
83
|
-
const hash = `#${target.pathname}${target.search}${target.hash}`;
|
|
84
|
-
if (location.hash !== hash) history.replaceState(history.state, "", hash);
|
|
85
|
-
});
|
|
86
|
-
const onHashChange = () => void navigate(location.hash.slice(1) || "/");
|
|
87
|
-
window.addEventListener("hashchange", onHashChange);
|
|
88
|
-
const dispose = router.dispose;
|
|
89
|
-
router.dispose = () => {
|
|
90
|
-
unsubscribe();
|
|
91
|
-
window.removeEventListener("hashchange", onHashChange);
|
|
92
|
-
dispose();
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
79
|
//#endregion
|
|
96
80
|
export { configureApplication, deserialize, mountApplication, recoverDeployment, serverRoute, watchDeployment };
|
|
@@ -1,10 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export interface DeferredWindow extends Window {
|
|
3
|
-
__smolterDeferred?: Settlement[];
|
|
4
|
-
}
|
|
5
|
-
/** Restore promise identity before hydrating Suspense boundaries. */
|
|
6
|
-
export declare function readHydration(json: string, timeout?: number): {
|
|
7
|
-
hydration: any;
|
|
8
|
-
dispose: () => void;
|
|
9
|
-
};
|
|
10
|
-
export {};
|
|
1
|
+
export { type DeferredWindow, readHydration } from "../client/hydration.ts";
|
|
@@ -1,11 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Preact document metadata, resource links and hydration scripts.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
1
6
|
/** @jsxImportSource preact */
|
|
2
7
|
import type { ComponentProps } from "preact/compat";
|
|
8
|
+
/** Render root or active-route metadata in the document head. */
|
|
3
9
|
export declare function Meta(): import("preact").JSX.Element;
|
|
10
|
+
/** Render stylesheet and other link descriptors from the application root. */
|
|
4
11
|
export declare function Links(): import("preact").JSX.Element;
|
|
12
|
+
/** Nonce and browser entry options for the document hydration scripts. */
|
|
5
13
|
export interface ScriptProps {
|
|
6
14
|
nonce?: string;
|
|
7
15
|
}
|
|
16
|
+
/** Render the hydration snapshot and browser entry script with an optional CSP nonce. */
|
|
8
17
|
export declare function Scripts({ nonce }: ScriptProps): import("preact").JSX.Element;
|
|
18
|
+
/** Reset scroll after navigation unless the navigation requests preservation. */
|
|
9
19
|
export declare function ScrollRestoration(_props: ScriptProps): null;
|
|
10
20
|
/** HTML attributes for server markup and client document reconciliation. */
|
|
11
21
|
export interface DocumentProps extends ComponentProps<"html"> {
|
package/dist/preact/document.js
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { serializeData } from "../core/serialize.js";
|
|
2
|
-
import { useApplication } from "./root-context.js";
|
|
3
|
-
import { useSnapshot } from "./context.js";
|
|
4
2
|
import { applicationEnvironment } from "../core/environment.js";
|
|
5
3
|
import { scrollPositions } from "../core/navigation.js";
|
|
4
|
+
import { useApplication } from "./root-context.js";
|
|
5
|
+
import { useSnapshot } from "./context.js";
|
|
6
6
|
import { useNavigationSnapshot } from "./navigation-state.js";
|
|
7
7
|
import { useEffect, useLayoutEffect, useRef, useState } from "preact/hooks";
|
|
8
8
|
import { Fragment, jsx, jsxs } from "preact/jsx-runtime";
|
|
9
9
|
import { Fragment as Fragment$1, createElement } from "preact";
|
|
10
10
|
//#region .generated/preact/document.tsx
|
|
11
|
+
/**
|
|
12
|
+
* Preact document metadata, resource links and hydration scripts.
|
|
13
|
+
*
|
|
14
|
+
* @module
|
|
15
|
+
*/
|
|
11
16
|
/** @jsxImportSource preact */
|
|
12
17
|
function renderMeta(item, index) {
|
|
13
18
|
if (typeof item.title === "string") return /* @__PURE__ */ jsx("title", { children: item.title }, index);
|
|
@@ -21,6 +26,7 @@ function renderMeta(item, index) {
|
|
|
21
26
|
key: index
|
|
22
27
|
});
|
|
23
28
|
}
|
|
29
|
+
/** Render root or active-route metadata in the document head. */
|
|
24
30
|
function Meta() {
|
|
25
31
|
const { routes, rootModule } = useApplication();
|
|
26
32
|
const snapshot = useSnapshot();
|
|
@@ -39,10 +45,12 @@ function Meta() {
|
|
|
39
45
|
}, [values]);
|
|
40
46
|
return /* @__PURE__ */ jsx(Fragment$1, { children: values.map(renderMeta) });
|
|
41
47
|
}
|
|
48
|
+
/** Render stylesheet and other link descriptors from the application root. */
|
|
42
49
|
function Links() {
|
|
43
50
|
const { rootModule } = useApplication();
|
|
44
51
|
return /* @__PURE__ */ jsx(Fragment$1, { children: rootModule?.links?.().map((props, index) => /* @__PURE__ */ jsx("link", { ...props }, index)) });
|
|
45
52
|
}
|
|
53
|
+
/** Render the hydration snapshot and browser entry script with an optional CSP nonce. */
|
|
46
54
|
function Scripts({ nonce }) {
|
|
47
55
|
const { root, rootError, router, entry, streaming, initialData } = useApplication();
|
|
48
56
|
const [json] = useState(() => {
|
|
@@ -82,6 +90,7 @@ function Scripts({ nonce }) {
|
|
|
82
90
|
})
|
|
83
91
|
] });
|
|
84
92
|
}
|
|
93
|
+
/** Reset scroll after navigation unless the navigation requests preservation. */
|
|
85
94
|
function ScrollRestoration(_props) {
|
|
86
95
|
const { router } = useApplication();
|
|
87
96
|
const { url, state } = useSnapshot();
|
package/dist/preact/index.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Preact routing components, typed data hooks and application integration.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
2
6
|
export type * from "../core/index.ts";
|
|
3
7
|
export { createDataRouter, createRouter, defineRoute, } from "../core/index.ts";
|
|
4
8
|
export type { ApplicationEnvironment } from "../core/environment.ts";
|
|
@@ -14,5 +18,5 @@ export type { NavigateOptions } from "./navigation.tsx";
|
|
|
14
18
|
export * from "./navigation.tsx";
|
|
15
19
|
export { useMatches, useNavigation, useOutletContext, useRootData, useRouteError, useRouteLoaderData, useSubmit, } from "./route-hooks.tsx";
|
|
16
20
|
export * from "./route-types.ts";
|
|
17
|
-
export { Outlet, RouterApplication } from "./router.tsx";
|
|
21
|
+
export { type ApplicationProps, Outlet, type OutletProps, RouterApplication, } from "./router.tsx";
|
|
18
22
|
export * from "./routes.ts";
|
package/dist/preact/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { defineRoute } from "../core/match.js";
|
|
2
2
|
import { createRouter } from "../core/navigation-router.js";
|
|
3
3
|
import { createDataRouter } from "../core/router.js";
|
|
4
|
-
import { readSubmission } from "../core/submission.js";
|
|
5
4
|
import { data, isRouteErrorResponse, normalizeResult, redirect, resolveData } from "../core/responses.js";
|
|
5
|
+
import { readSubmission } from "../core/submission.js";
|
|
6
6
|
import { Await } from "./await.js";
|
|
7
7
|
import { RouterProvider, useRouter } from "./context.js";
|
|
8
8
|
import { Form } from "./form.js";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { RouteModule } from "../core/index.ts";
|
|
2
2
|
import { type ComponentType } from "preact";
|
|
3
3
|
import type { AppRoute } from "./route-types.ts";
|
|
4
|
+
/** Lazy route path, server transport endpoint and available handler capabilities. */
|
|
4
5
|
export interface LazyRouteOptions {
|
|
5
6
|
path: string;
|
|
6
7
|
dataEndpoint?: string;
|
|
@@ -16,5 +17,6 @@ type LoadedRoute = RouteModule & Pick<AppRoute, "meta">;
|
|
|
16
17
|
interface LazyAppRoute extends AppRoute {
|
|
17
18
|
resolveComponent: () => ComponentType | undefined;
|
|
18
19
|
}
|
|
20
|
+
/** Create a route that imports its module on demand and shares the import with intent prefetching. */
|
|
19
21
|
export declare function lazyRoute(options: LazyRouteOptions, importer: () => Promise<LoadedRoute>): LazyAppRoute;
|
|
20
22
|
export {};
|
|
@@ -3,12 +3,18 @@ import { useRouter } from "./context.js";
|
|
|
3
3
|
import { serverRoute } from "../client/index.js";
|
|
4
4
|
import { createElement } from "preact";
|
|
5
5
|
//#region .generated/preact/lazy-route.ts
|
|
6
|
+
/**
|
|
7
|
+
* On-demand Preact route modules with shared intent prefetching.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
6
11
|
function LazyView() {
|
|
7
12
|
const router = useRouter();
|
|
8
13
|
const { path } = useSyncExternalStore(router.subscribe, router.getSnapshot);
|
|
9
14
|
const Component = router.routes.find((item) => item.path === path)?.resolveComponent();
|
|
10
15
|
return Component && createElement(Component, {});
|
|
11
16
|
}
|
|
17
|
+
/** Create a route that imports its module on demand and shares the import with intent prefetching. */
|
|
12
18
|
function lazyRoute(options, importer) {
|
|
13
19
|
let module;
|
|
14
20
|
let pending;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useSyncExternalStore } from "./runtime.js";
|
|
2
1
|
import { navigationStore } from "../core/navigation.js";
|
|
2
|
+
import { useSyncExternalStore } from "./runtime.js";
|
|
3
3
|
//#region .generated/preact/navigation-state.ts
|
|
4
4
|
function useNavigationSnapshot(router) {
|
|
5
5
|
const store = navigationStore(router);
|
|
@@ -2,7 +2,9 @@ import { type NavigateOptions } from "../core/index.ts";
|
|
|
2
2
|
import type { ComponentProps, ReactNode } from "preact/compat";
|
|
3
3
|
export type { NavigateOptions } from "../core/index.ts";
|
|
4
4
|
export type { NavigationType } from "../core/navigation.ts";
|
|
5
|
+
/** Navigate to a URL or move through browser history using a numeric offset. */
|
|
5
6
|
export type NavigateFunction = (to: string | number | Partial<Pick<URL, "pathname" | "search" | "hash">>, options?: NavigateOptions) => void;
|
|
7
|
+
/** Anchor properties and router navigation options, including document reload and prefetch controls. */
|
|
6
8
|
export interface LinkProps extends Omit<ComponentProps<"a">, "href" | "role"> {
|
|
7
9
|
to?: string;
|
|
8
10
|
href?: string;
|
|
@@ -14,15 +16,19 @@ export interface LinkProps extends Omit<ComponentProps<"a">, "href" | "role"> {
|
|
|
14
16
|
viewTransition?: boolean;
|
|
15
17
|
reloadDocument?: boolean;
|
|
16
18
|
}
|
|
19
|
+
/** Active and pending flags supplied to NavLink render callbacks. */
|
|
17
20
|
export interface NavLinkRenderProps {
|
|
18
21
|
isActive: boolean;
|
|
19
22
|
isPending: boolean;
|
|
20
23
|
}
|
|
24
|
+
/** Link options with matching rules and state-aware class or children callbacks. */
|
|
21
25
|
export interface NavLinkProps extends Omit<LinkProps, "className" | "children"> {
|
|
22
26
|
end?: boolean;
|
|
23
27
|
className?: string | ((state: NavLinkRenderProps) => string);
|
|
24
28
|
children?: ReactNode | ((state: NavLinkRenderProps) => ReactNode);
|
|
25
29
|
}
|
|
30
|
+
/** Render an anchor with same-origin router navigation and optional intent prefetching. */
|
|
26
31
|
export declare function Link(options: LinkProps): ReactNode;
|
|
32
|
+
/** Render a Link with active-route state and aria-current for the matching destination. */
|
|
27
33
|
export declare function NavLink({ href, to, end, className, children, ...props }: NavLinkProps): ReactNode;
|
|
28
34
|
export { useNavigate, useNavigationType, useSearchParams, useURLLocation, } from "./route-hooks.tsx";
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { matchRoutes } from "../core/match.js";
|
|
2
2
|
import { navigationClick } from "../core/url.js";
|
|
3
|
+
import { handoffDocument, resolveApplicationURL } from "../core/environment.js";
|
|
3
4
|
import { createElement } from "./runtime.js";
|
|
4
5
|
import { useRouter, useSnapshot } from "./context.js";
|
|
5
|
-
import {
|
|
6
|
-
import { useNavigate, useNavigationType, useSearchParams, useURLLocation } from "./route-hooks.js";
|
|
6
|
+
import { useNavigate, useNavigation, useNavigationType, useSearchParams, useURLLocation } from "./route-hooks.js";
|
|
7
7
|
//#region .generated/preact/navigation.tsx
|
|
8
|
+
/** Render an anchor with same-origin router navigation and optional intent prefetching. */
|
|
8
9
|
function Link(options) {
|
|
9
10
|
const { href: hrefProp, to = hrefProp ?? "/", replace, preventScrollReset, viewTransition, prefetch, state, reloadDocument, ...props } = options;
|
|
10
11
|
const router = useRouter();
|
|
@@ -40,13 +41,16 @@ function Link(options) {
|
|
|
40
41
|
}
|
|
41
42
|
});
|
|
42
43
|
}
|
|
44
|
+
/** Render a Link with active-route state and aria-current for the matching destination. */
|
|
43
45
|
function NavLink({ href, to = href ?? "/", end, className, children, ...props }) {
|
|
44
46
|
const location = useURLLocation();
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
+
const destination = resolveApplicationURL(new URL(to, location.href));
|
|
48
|
+
const target = destination.pathname;
|
|
49
|
+
const isActive = destination.origin === location.origin && (location.pathname === target || !end && target !== "/" && location.pathname.startsWith(`${target}/`));
|
|
50
|
+
const pending = useNavigation().location;
|
|
47
51
|
const state = {
|
|
48
52
|
isActive,
|
|
49
|
-
isPending:
|
|
53
|
+
isPending: !!pending && pending.origin === destination.origin && (pending.pathname === target || !end && target !== "/" && pending.pathname.startsWith(`${target}/`))
|
|
50
54
|
};
|
|
51
55
|
return createElement(Link, {
|
|
52
56
|
...props,
|
|
@@ -1,8 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import type { RootModule } from "./route-types.ts";
|
|
3
|
-
export { createStore as createRootStore } from "../core/store.ts";
|
|
4
|
-
export declare function attachRootData(router: Router, initial: unknown, rootModule?: RootModule): {
|
|
5
|
-
getSnapshot: () => unknown;
|
|
6
|
-
subscribe(listener: () => void): () => void;
|
|
7
|
-
update(next: unknown): void;
|
|
8
|
-
};
|
|
1
|
+
export { attachRootData, createRootStore } from "../client/root-data.ts";
|
|
@@ -4,29 +4,39 @@ import { type Submission, type SubmissionOptions } from "../core/submission.ts";
|
|
|
4
4
|
import { useSnapshot } from "./context.ts";
|
|
5
5
|
import type { NavigateFunction } from "./navigation.tsx";
|
|
6
6
|
import type { RouteData } from "./route-types.ts";
|
|
7
|
+
/** Read root loader data from the application context. */
|
|
7
8
|
export declare function useRootData<T = unknown>(): RouteData<T>;
|
|
8
9
|
/** Read root data or the active route's data by its manifest identifier. */
|
|
9
10
|
export declare function useRouteLoaderData<T = unknown>(id: string): RouteData<T> | undefined;
|
|
10
11
|
export { useSnapshot };
|
|
12
|
+
/** Read the current route error for an error boundary. */
|
|
11
13
|
export declare function useRouteError(): Error | undefined;
|
|
14
|
+
/** Read the current page navigation or submission state. */
|
|
12
15
|
export declare function useNavigation(): {
|
|
13
16
|
state: "idle" | "loading" | "submitting";
|
|
14
17
|
location: URL | undefined;
|
|
15
18
|
};
|
|
19
|
+
/** Read the active flat route match and loader data; this is not a nested layout match chain. */
|
|
16
20
|
export declare function useMatches(): {
|
|
17
21
|
id: string;
|
|
18
22
|
data: unknown;
|
|
19
23
|
params: import("../core/index.ts").Params;
|
|
20
24
|
}[];
|
|
25
|
+
/** Read context supplied by the nearest Outlet. */
|
|
21
26
|
export declare function useOutletContext<T>(): T;
|
|
27
|
+
/** Return a function that submits form data through the current router. */
|
|
22
28
|
export declare function useSubmit(): (value: Submission, options?: SubmissionOptions) => Promise<void> | Promise<import("../core/index.ts").Result<unknown>>;
|
|
29
|
+
/** Read the current router location as a URL. */
|
|
23
30
|
export declare function useURLLocation(): URL & {
|
|
24
31
|
state: unknown;
|
|
25
32
|
key: string;
|
|
26
33
|
};
|
|
34
|
+
/** Return the application navigation function, including history offsets and relative destinations. */
|
|
27
35
|
export declare function useNavigate(): NavigateFunction;
|
|
36
|
+
/** Read URL search parameters and update them through router navigation. */
|
|
28
37
|
export declare function useSearchParams(): [
|
|
29
38
|
URLSearchParams,
|
|
30
39
|
(value: URLSearchParams | Record<string, string>, options?: NavigateOptions) => void
|
|
31
40
|
];
|
|
41
|
+
/** Read the last browser history operation. */
|
|
32
42
|
export declare function useNavigationType(): NavigationType;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { submissionBody, submissionSearch } from "../core/submission.js";
|
|
2
|
+
import { pendingLocation } from "../core/presentation.js";
|
|
2
3
|
import { useContext, useMemo } from "./runtime.js";
|
|
3
4
|
import { OutletContext, useApplication } from "./root-context.js";
|
|
4
5
|
import { useRouter, useSnapshot } from "./context.js";
|
|
5
|
-
import { pendingLocation } from "../core/presentation.js";
|
|
6
6
|
import { useNavigationSnapshot } from "./navigation-state.js";
|
|
7
7
|
import { useCallback } from "preact/hooks";
|
|
8
8
|
//#region .generated/preact/route-hooks.tsx
|
|
9
|
+
/** Read root loader data from the application context. */
|
|
9
10
|
function useRootData() {
|
|
10
11
|
return useApplication().root;
|
|
11
12
|
}
|
|
@@ -18,9 +19,11 @@ function useRouteLoaderData(id) {
|
|
|
18
19
|
if (!route || route.path !== snapshot.path) return void 0;
|
|
19
20
|
return snapshot.data;
|
|
20
21
|
}
|
|
22
|
+
/** Read the current route error for an error boundary. */
|
|
21
23
|
function useRouteError() {
|
|
22
24
|
return useSnapshot("error");
|
|
23
25
|
}
|
|
26
|
+
/** Read the current page navigation or submission state. */
|
|
24
27
|
function useNavigation() {
|
|
25
28
|
const router = useRouter();
|
|
26
29
|
const snapshot = useSnapshot();
|
|
@@ -30,18 +33,21 @@ function useNavigation() {
|
|
|
30
33
|
location
|
|
31
34
|
}), [snapshot.state, location?.href]);
|
|
32
35
|
}
|
|
36
|
+
/** Read the active flat route match and loader data; this is not a nested layout match chain. */
|
|
33
37
|
function useMatches() {
|
|
34
|
-
const
|
|
38
|
+
const router = useRouter();
|
|
35
39
|
const snapshot = useSnapshot();
|
|
36
40
|
return [{
|
|
37
|
-
id: routes.find((item) => item.path === snapshot.path)?.id ?? "",
|
|
41
|
+
id: router.routes.find((item) => item.path === snapshot.path)?.id ?? "",
|
|
38
42
|
data: snapshot.data,
|
|
39
43
|
params: snapshot.params
|
|
40
44
|
}];
|
|
41
45
|
}
|
|
46
|
+
/** Read context supplied by the nearest Outlet. */
|
|
42
47
|
function useOutletContext() {
|
|
43
48
|
return useContext(OutletContext);
|
|
44
49
|
}
|
|
50
|
+
/** Return a function that submits form data through the current router. */
|
|
45
51
|
function useSubmit() {
|
|
46
52
|
const router = useRouter();
|
|
47
53
|
return useCallback((value, options = {}) => {
|
|
@@ -56,6 +62,7 @@ function useSubmit() {
|
|
|
56
62
|
return router.submit(target, body, { method });
|
|
57
63
|
}, [router]);
|
|
58
64
|
}
|
|
65
|
+
/** Read the current router location as a URL. */
|
|
59
66
|
function useURLLocation() {
|
|
60
67
|
const href = useSnapshot("url");
|
|
61
68
|
const snapshot = useNavigationSnapshot(useRouter());
|
|
@@ -68,6 +75,7 @@ function useURLLocation() {
|
|
|
68
75
|
snapshot.key
|
|
69
76
|
]);
|
|
70
77
|
}
|
|
78
|
+
/** Return the application navigation function, including history offsets and relative destinations. */
|
|
71
79
|
function useNavigate() {
|
|
72
80
|
const router = useRouter();
|
|
73
81
|
return useCallback((to, options) => {
|
|
@@ -80,6 +88,7 @@ function useNavigate() {
|
|
|
80
88
|
router.navigate(target, options);
|
|
81
89
|
}, [router]);
|
|
82
90
|
}
|
|
91
|
+
/** Read URL search parameters and update them through router navigation. */
|
|
83
92
|
function useSearchParams() {
|
|
84
93
|
const location = useURLLocation();
|
|
85
94
|
const navigate = useNavigate();
|
|
@@ -87,6 +96,7 @@ function useSearchParams() {
|
|
|
87
96
|
navigate(`${location.pathname}?${new URLSearchParams(value)}`, options);
|
|
88
97
|
}, [location.pathname, navigate])];
|
|
89
98
|
}
|
|
99
|
+
/** Read the last browser history operation. */
|
|
90
100
|
function useNavigationType() {
|
|
91
101
|
return useNavigationSnapshot(useRouter()).type;
|
|
92
102
|
}
|