@kasperrt/smolter 0.4.2 → 0.4.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/.generated/core/environment.ts +1 -0
- package/.generated/core/navigation.ts +1 -0
- package/.generated/core/resource-types.ts +4 -0
- package/.generated/core/resources.ts +2 -0
- 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 +7 -1
- package/.generated/preact/document.tsx +10 -0
- package/.generated/preact/index.ts +6 -2
- package/.generated/preact/lazy-route.ts +7 -0
- package/.generated/preact/navigation.tsx +6 -0
- package/.generated/preact/route-hooks.tsx +12 -2
- package/.generated/preact/route-types.ts +14 -0
- package/.generated/preact/router.tsx +3 -0
- package/.generated/react/data.ts +5 -1
- package/.generated/react/index.ts +11 -1
- package/.generated/react/outlet.ts +48 -0
- package/.generated/react/resources/components.tsx +12 -0
- package/.generated/server/application.tsx +3 -0
- package/.generated/server/assets.ts +7 -0
- package/.generated/server/handler.ts +3 -0
- package/.generated/server/http.ts +2 -0
- package/.generated/server/node.ts +5 -2
- package/.generated/server/preact.ts +5 -2
- package/CHANGELOG.md +10 -0
- package/README.md +16 -16
- package/dist/core/environment.d.ts +1 -0
- package/dist/core/navigation.d.ts +1 -0
- package/dist/core/resource-types.d.ts +4 -0
- package/dist/core/resources.d.ts +2 -0
- package/dist/core/resources.js +2 -0
- 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 +6 -1
- package/dist/preact/document.d.ts +10 -0
- package/dist/preact/document.js +9 -0
- package/dist/preact/index.d.ts +6 -2
- package/dist/preact/lazy-route.d.ts +2 -0
- package/dist/preact/lazy-route.js +6 -0
- package/dist/preact/navigation.d.ts +6 -0
- package/dist/preact/navigation.js +2 -0
- package/dist/preact/route-hooks.d.ts +10 -0
- package/dist/preact/route-hooks.js +12 -2
- package/dist/preact/route-types.d.ts +14 -0
- package/dist/preact/router.d.ts +3 -0
- package/dist/preact/router.js +2 -0
- package/dist/react/data.d.ts +5 -1
- package/dist/react/index.d.ts +6 -1
- package/dist/react/index.js +2 -1
- package/dist/react/outlet.d.ts +16 -0
- package/dist/react/outlet.js +26 -0
- package/dist/react/resources/components.d.ts +12 -0
- package/dist/react/resources/components.js +11 -0
- package/dist/server/application.d.ts +3 -0
- package/dist/server/application.js +2 -0
- package/dist/server/assets.d.ts +2 -0
- package/dist/server/assets.js +6 -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/node.d.ts +5 -1
- package/dist/server/preact.d.ts +5 -1
- package/jsr.json +1 -1
- package/package.json +6 -5
|
@@ -1,11 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Production route asset discovery for SSR preload hints.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
1
6
|
import { matchRoutes } from "../core/index.ts";
|
|
2
7
|
|
|
8
|
+
/** Emitted JavaScript and stylesheet URLs associated with a route. */
|
|
3
9
|
export interface RouteAssets {
|
|
4
10
|
path: string;
|
|
5
11
|
files: string[];
|
|
6
12
|
styles?: string[];
|
|
7
13
|
}
|
|
8
14
|
|
|
15
|
+
/** Collect matched-route JavaScript and stylesheet assets from the production route manifest. */
|
|
9
16
|
export function routePreloads(
|
|
10
17
|
routes: RouteAssets[],
|
|
11
18
|
pathname: string,
|
|
@@ -8,6 +8,7 @@ export interface ServerBuild {
|
|
|
8
8
|
handleDataRequest: (request: Request) => Response | Promise<Response>;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
/** SSR build, browser entry URL and application-scoped data endpoint for Node or Express. */
|
|
11
12
|
export interface RequestHandlerOptions {
|
|
12
13
|
build: ServerBuild;
|
|
13
14
|
/** Browser entry URL resolved from Vite's production manifest. */
|
|
@@ -16,12 +17,14 @@ export interface RequestHandlerOptions {
|
|
|
16
17
|
dataEndpoint?: string;
|
|
17
18
|
}
|
|
18
19
|
|
|
20
|
+
/** Node request with optional Express protocol and original URL information. */
|
|
19
21
|
export interface ServerIncomingMessage extends IncomingMessage {
|
|
20
22
|
/** Express supplies this using the application's trust proxy policy. */
|
|
21
23
|
protocol?: string;
|
|
22
24
|
originalUrl?: string;
|
|
23
25
|
}
|
|
24
26
|
|
|
27
|
+
/** Express-compatible callback for forwarding middleware errors. */
|
|
25
28
|
export type NextHandler = (error?: unknown) => void;
|
|
26
29
|
|
|
27
30
|
/** Node/Express middleware; mount after metrics, tracing and static assets. */
|
|
@@ -3,6 +3,7 @@ import { Readable, Transform } from "node:stream";
|
|
|
3
3
|
import { pipeline } from "node:stream/promises";
|
|
4
4
|
import type { ServerIncomingMessage } from "./handler.ts";
|
|
5
5
|
|
|
6
|
+
/** Convert a Node request to a Web Request with cancellation and an optional normalized route target. */
|
|
6
7
|
export async function webRequest(
|
|
7
8
|
incoming: ServerIncomingMessage,
|
|
8
9
|
outgoing: ServerResponse,
|
|
@@ -40,6 +41,7 @@ interface StreamingResponse extends ServerResponse {
|
|
|
40
41
|
flush?: () => void;
|
|
41
42
|
}
|
|
42
43
|
|
|
44
|
+
/** Write a Web Response to Node with streaming backpressure and disconnect cancellation. */
|
|
43
45
|
export async function send(response: Response, outgoing: StreamingResponse) {
|
|
44
46
|
outgoing.statusCode = response.status;
|
|
45
47
|
response.headers.forEach((value, name) => {
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.4.3
|
|
4
|
+
|
|
5
|
+
- Prefetch individual guide articles on pointer, keyboard and touch intent. Keep the shared header, sidebar and current article visible during cold guide navigation; show a quiet pending status without replacing the layout. Link the header directly to the canonical Getting started guide.
|
|
6
|
+
- Publish compact React/Preact and SSR compatibility indicators in guide navigation and detailed support information on each page.
|
|
7
|
+
- Document every public JSR entrypoint and exported symbol. Validate the generated documentation before publishing, preserving JSR-before-npm release ordering.
|
|
8
|
+
|
|
9
|
+
- Add React `Outlet`, `useMatches` and `useOutletContext`; allow Preact matches under a plain RouterProvider. Show renderer and SSR compatibility in documentation navigation and on each page. Integrated document/early-hydration APIs remain Preact-only.
|
|
10
|
+
|
|
11
|
+
- Remove the public `safeWrapAsync` utility; retain it internally for router and server error handling. Existing consumers of this export must provide their own error handling. `useMatches` and `useOutletContext` remain public Preact APIs.
|
|
12
|
+
|
|
3
13
|
## 0.4.2
|
|
4
14
|
|
|
5
15
|
- Add integrated `Await fallback` for early hydration: pending and resolved content belongs to the mounted component, so navigation, root revalidation and late settlement cannot leave abandoned content behind. Migrate early-hydrated deferred sections from outer Preact `Suspense` to this prop, including root sections. Native Preact streamed Suspense remains unsupported for this ownership contract; it is not patched. Ordinary non-early SSR still streams resolved HTML.
|
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# smolter _
|
|
2
2
|
|
|
3
3
|
<!-- bundlejs:start -->
|
|
4
|
-
[](https://bundlejs.com/?q=%40kasperrt%2Fsmolter%400.4.3%2Freact&treeshake=%5B*%5D&config=%7B%22compression%22%3A%22gzip%22%2C%22esbuild%22%3A%7B%22external%22%3A%5B%22react%22%2C%22react%2F*%22%5D%7D%7D&bundle)
|
|
5
|
+
[](https://bundlejs.com/?q=%40kasperrt%2Fsmolter%400.4.3%2Fpreact&treeshake=%5B*%5D&config=%7B%22compression%22%3A%22gzip%22%2C%22esbuild%22%3A%7B%22external%22%3A%5B%22preact%22%2C%22preact%2F*%22%5D%7D%7D&bundle)
|
|
6
6
|
<!-- bundlejs:end -->
|
|
7
7
|
|
|
8
8
|
A typed data router for React and Preact. **Zero runtime dependencies.**
|
|
@@ -14,9 +14,9 @@ loader; `shouldRevalidate` decides when that work is needed.
|
|
|
14
14
|
Inspired by [wouter](https://github.com/molefrog/wouter)
|
|
15
15
|
and [React Router](https://reactrouter.com/).
|
|
16
16
|
|
|
17
|
-
[Read the documentation](https://kasperrt.github.io/smolter/
|
|
17
|
+
[Read the documentation](https://kasperrt.github.io/smolter/docs/) for guides and the complete API reference. The prerendered site uses Preact and Smolter routes. Articles load individually; React examples remain available in the repository.
|
|
18
18
|
|
|
19
|
-
Start with [loaders](https://kasperrt.github.io/smolter/
|
|
19
|
+
Start with [loaders](https://kasperrt.github.io/smolter/docs/loaders/), [actions](https://kasperrt.github.io/smolter/docs/actions/), [forms and validation](https://kasperrt.github.io/smolter/docs/forms/), or [fetcher reads and mutations](https://kasperrt.github.io/smolter/docs/fetchers/). Each guide connects the handler to an actual route URL and its consuming view.
|
|
20
20
|
|
|
21
21
|
## Contents
|
|
22
22
|
|
|
@@ -445,18 +445,18 @@ Choose one renderer for your application. Both expose the same routing API:
|
|
|
445
445
|
| SSR and HTTP data dispatch | `@kasperrt/smolter/react/server` | `@kasperrt/smolter/preact/server` |
|
|
446
446
|
| Vite plugin and flat-file discovery | `@kasperrt/smolter/react/vite` | `@kasperrt/smolter/preact/vite` |
|
|
447
447
|
|
|
448
|
-
`@kasperrt/smolter/utils` contains browser-safe matching and
|
|
448
|
+
`@kasperrt/smolter/utils` contains browser-safe matching and URL helpers.
|
|
449
449
|
The main renderer entries never import server or build modules. Named imports
|
|
450
450
|
are tree-shaken; optional transport is included only when you import `/client`.
|
|
451
451
|
Server entries do not import either UI renderer. Vite entries are build-time only.
|
|
452
452
|
|
|
453
453
|
**Migrating renderer subpaths:** replace `/core` imports for types, router factories, and
|
|
454
454
|
`defineRoute` with your renderer entry. Use `/utils` for `matchRoutes`,
|
|
455
|
-
|
|
455
|
+
and `internalURL`. Move `/client`, `/server`,
|
|
456
456
|
`/files`, and `/vite` imports to the corresponding renderer-prefixed path above.
|
|
457
457
|
The bare package root and old top-level subpaths are no longer exported.
|
|
458
458
|
|
|
459
|
-
See the [0.3 migration guide](https://kasperrt.github.io/smolter/
|
|
459
|
+
See the [0.3 migration guide](https://kasperrt.github.io/smolter/docs/migration-0.3/) and [changelog](./CHANGELOG.md).
|
|
460
460
|
|
|
461
461
|
**Router factory migration:** code that previously used `createRouter` with
|
|
462
462
|
loaders, actions, fetchers or revalidation must now use `createDataRouter`.
|
|
@@ -525,7 +525,7 @@ re-exports and installs server proxies. `entry.client.tsx` and `entry.server.tsx
|
|
|
525
525
|
are application-owned files wiring those manifests to hydration and SSR.
|
|
526
526
|
Manual tables can be imported directly instead.
|
|
527
527
|
|
|
528
|
-
See the [virtual routes guide](https://kasperrt.github.io/smolter/
|
|
528
|
+
See the [virtual routes guide](https://kasperrt.github.io/smolter/docs/virtual-routes)
|
|
529
529
|
for the exact contract, TypeScript declaration, and both entrypoint examples.
|
|
530
530
|
|
|
531
531
|
### Express hosting
|
|
@@ -537,7 +537,7 @@ server entry and `entry` is the browser entry URL from Vite's manifest. Do not
|
|
|
537
537
|
consume request bodies with Express body parsers before this handler.
|
|
538
538
|
The adapter has no Express dependency and forwards failures to `next(error)`.
|
|
539
539
|
|
|
540
|
-
See the [Express guide](https://kasperrt.github.io/smolter/
|
|
540
|
+
See the [Express guide](https://kasperrt.github.io/smolter/docs/express)
|
|
541
541
|
for a complete server example and streaming and hydration behavior.
|
|
542
542
|
|
|
543
543
|
## Resource subscriptions
|
|
@@ -607,12 +607,12 @@ a claim of identical features.
|
|
|
607
607
|
| `React Router: data routing subset` | 29780 |
|
|
608
608
|
| `React: routing-only named exports` | 1245 |
|
|
609
609
|
| `Preact: routing-only named exports` | 1405 |
|
|
610
|
-
| `@kasperrt/smolter/react` |
|
|
611
|
-
| `@kasperrt/smolter/preact` |
|
|
612
|
-
| `@kasperrt/smolter/react + @kasperrt/smolter/react/client` |
|
|
613
|
-
| `@kasperrt/smolter/preact + server transport` |
|
|
614
|
-
| `@kasperrt/smolter/preact + client + document (application without lazy routes)` |
|
|
615
|
-
| `@kasperrt/smolter/preact + client + document + lazy-route (file-routed application)` |
|
|
610
|
+
| `@kasperrt/smolter/react` | 3082 |
|
|
611
|
+
| `@kasperrt/smolter/preact` | 5016 |
|
|
612
|
+
| `@kasperrt/smolter/react + @kasperrt/smolter/react/client` | 4419 |
|
|
613
|
+
| `@kasperrt/smolter/preact + server transport` | 6291 |
|
|
614
|
+
| `@kasperrt/smolter/preact + client + document (application without lazy routes)` | 9398 |
|
|
615
|
+
| `@kasperrt/smolter/preact + client + document + lazy-route (file-routed application)` | 9685 |
|
|
616
616
|
| `@kasperrt/smolter/react/data (optional resource API)` | 2962 |
|
|
617
617
|
| `React: common routing/data exports` | 2761 |
|
|
618
618
|
| `Preact: common routing/data exports` | 3046 |
|
|
@@ -735,7 +735,7 @@ normally, and a session marker prevents reload loops. Development/SSR builds
|
|
|
735
735
|
disable the helper. This optional client module adds nothing to the routing-only
|
|
736
736
|
entrypoints and never replays form submissions.
|
|
737
737
|
|
|
738
|
-
See [deployment updates](https://kasperrt.github.io/smolter/
|
|
738
|
+
See [deployment updates](https://kasperrt.github.io/smolter/docs/deployments/)
|
|
739
739
|
for Express, CDN paths, TypeScript declarations and unsaved-state handling.
|
|
740
740
|
|
|
741
741
|
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
export type Params = Readonly<Record<string, string>>;
|
|
2
|
+
/** Resource parameters and cancellation signal supplied to a loader. */
|
|
2
3
|
export interface LoaderFunctionArgs {
|
|
3
4
|
params: Params;
|
|
4
5
|
signal: AbortSignal;
|
|
5
6
|
}
|
|
7
|
+
/** Submitted input, resource parameters and cancellation signal supplied to an action. */
|
|
6
8
|
export interface ActionFunctionArgs<Input = unknown> {
|
|
7
9
|
input: Input;
|
|
8
10
|
params: Params;
|
|
9
11
|
signal: AbortSignal;
|
|
10
12
|
}
|
|
13
|
+
/** Successful resource data or a normalized resource failure. */
|
|
11
14
|
export interface DataResult<Data> {
|
|
12
15
|
data: Data | null;
|
|
13
16
|
error: string;
|
|
@@ -18,6 +21,7 @@ export interface ResourceModule {
|
|
|
18
21
|
loader?: (args: LoaderFunctionArgs) => Promise<DataResult<unknown>>;
|
|
19
22
|
shouldRevalidate?: (args: ShouldRevalidateFunctionArgs) => boolean;
|
|
20
23
|
}
|
|
24
|
+
/** Navigation or mutation context used to decide whether loader data should refresh. */
|
|
21
25
|
export interface ShouldRevalidateFunctionArgs {
|
|
22
26
|
actionResult: DataResult<unknown>;
|
|
23
27
|
defaultShouldRevalidate: boolean;
|
package/dist/core/resources.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { DataResult, Params, ResourceModule, RouteState } from "./resource-types.ts";
|
|
2
|
+
/** Manage keyed resource reads, submissions, subscriptions and cancellation independently of navigation. */
|
|
2
3
|
export declare class ResourceRouter {
|
|
3
4
|
#private;
|
|
4
5
|
constructor(routes: ReadonlyMap<string, ResourceModule>);
|
|
@@ -16,4 +17,5 @@ export declare class ResourceRouter {
|
|
|
16
17
|
retry(routeId: string, params: Params): Promise<DataResult<unknown>>;
|
|
17
18
|
reportUnexpected(routeId: string, params: Params): void;
|
|
18
19
|
}
|
|
20
|
+
/** Create an independent resource-data router from registered modules; this does not manage URL history. */
|
|
19
21
|
export declare function createResourceRouter(routes: ReadonlyMap<string, ResourceModule>): ResourceRouter;
|
package/dist/core/resources.js
CHANGED
|
@@ -11,6 +11,7 @@ var IDLE_ROUTE_STATE = {
|
|
|
11
11
|
navigationState: "idle",
|
|
12
12
|
unexpectedError: false
|
|
13
13
|
};
|
|
14
|
+
/** Manage keyed resource reads, submissions, subscriptions and cancellation independently of navigation. */
|
|
14
15
|
var ResourceRouter = class {
|
|
15
16
|
#cleanupTimers = /* @__PURE__ */ new Map();
|
|
16
17
|
#controllers = /* @__PURE__ */ new Map();
|
|
@@ -333,6 +334,7 @@ var ResourceRouter = class {
|
|
|
333
334
|
for (const listener of this.#listeners.get(routeKey) ?? []) listener();
|
|
334
335
|
}
|
|
335
336
|
};
|
|
337
|
+
/** Create an independent resource-data router from registered modules; this does not manage URL history. */
|
|
336
338
|
function createResourceRouter(routes) {
|
|
337
339
|
return new ResourceRouter(routes);
|
|
338
340
|
}
|
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
|
@@ -13,8 +13,13 @@ import { flushSync } from "preact/compat";
|
|
|
13
13
|
import { jsx } from "preact/jsx-runtime";
|
|
14
14
|
import { hydrate, render } from "preact";
|
|
15
15
|
//#region .generated/preact/client.tsx
|
|
16
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* Preact document hydration, browser history and deployment recovery.
|
|
18
|
+
*
|
|
19
|
+
* @module
|
|
20
|
+
*/
|
|
17
21
|
/** @jsxImportSource preact */
|
|
22
|
+
/** Create the browser application router and hydrate the document, installing recovery before initial lazy loading. */
|
|
18
23
|
async function mountApplication(routes, rootModule, options = false) {
|
|
19
24
|
const { hash = false, deployment = null, deferredTimeout } = typeof options === "boolean" ? { hash: options } : options;
|
|
20
25
|
const initialURL = new URL(hash ? location.hash.slice(1) || "/" : location.href, location.origin);
|
|
@@ -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
|
@@ -8,6 +8,11 @@ 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 { Outlet, type OutletProps, RouterApplication } from "./router.tsx";
|
|
18
22
|
export * from "./routes.ts";
|
|
@@ -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;
|
|
@@ -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";
|
|
@@ -5,6 +5,7 @@ import { useRouter, useSnapshot } from "./context.js";
|
|
|
5
5
|
import { handoffDocument, resolveApplicationURL } from "../core/environment.js";
|
|
6
6
|
import { useNavigate, 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,6 +41,7 @@ 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
47
|
const target = new URL(to, location.href).pathname;
|
|
@@ -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;
|