@kasperrt/smolter 0.2.0 → 0.3.1
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/deployment.ts +161 -0
- package/{src/internal → .generated}/client/index.ts +3 -0
- package/.generated/core/environment.ts +43 -0
- package/{src/internal → .generated}/core/errors.ts +1 -1
- package/{src/internal → .generated}/core/index.ts +1 -0
- package/.generated/core/navigation-router.ts +107 -0
- package/.generated/core/navigation.ts +147 -0
- package/.generated/core/presentation.ts +108 -0
- package/.generated/core/resource-types.ts +44 -0
- package/.generated/core/resources.ts +444 -0
- package/.generated/core/responses.ts +86 -0
- package/{src/internal → .generated}/core/router.ts +136 -63
- package/{src/internal → .generated}/core/serialize.ts +7 -2
- package/.generated/core/store.ts +25 -0
- package/.generated/core/submission.ts +116 -0
- package/{src/internal → .generated}/core/types.ts +18 -1
- package/.generated/core/url.ts +29 -0
- package/.generated/core/utils.ts +5 -0
- package/.generated/preact/await.tsx +41 -0
- package/.generated/preact/client.tsx +93 -0
- package/.generated/preact/context.ts +59 -0
- package/.generated/preact/document.tsx +198 -0
- package/{src/internal → .generated}/preact/fetcher.ts +43 -23
- package/.generated/preact/form.ts +58 -0
- package/{src/internal → .generated}/preact/hooks.ts +25 -28
- package/.generated/preact/index.ts +34 -0
- package/.generated/preact/lazy-route.ts +100 -0
- package/.generated/preact/navigation-state.ts +9 -0
- package/.generated/preact/navigation.tsx +147 -0
- package/.generated/preact/root-context.ts +21 -0
- package/.generated/preact/root-data.ts +45 -0
- package/.generated/preact/route-hooks.tsx +170 -0
- package/.generated/preact/route-types.ts +76 -0
- package/.generated/preact/router.tsx +107 -0
- package/{src/internal → .generated}/preact/routes.ts +17 -9
- package/.generated/react/context.ts +59 -0
- package/.generated/react/data.ts +25 -0
- package/{src/internal → .generated}/react/fetcher.ts +13 -11
- package/.generated/react/form.ts +58 -0
- package/{src/internal → .generated}/react/hooks.ts +9 -14
- package/{src/internal/preact → .generated/react}/index.ts +5 -1
- package/{src/internal → .generated}/react/link.ts +13 -21
- package/.generated/react/resources/components.tsx +404 -0
- package/{src/internal → .generated}/react/routes.ts +17 -9
- package/.generated/server/application.tsx +185 -0
- package/.generated/server/assets.ts +19 -0
- package/.generated/server/handler.ts +69 -0
- package/.generated/server/http.ts +55 -0
- package/{src/internal → .generated}/server/index.ts +3 -3
- package/.generated/server/node.ts +4 -0
- package/.generated/server/preact.ts +7 -0
- package/.generated/vite/application/browser-boundary.ts +42 -0
- package/.generated/vite/application/lazy-files.ts +138 -0
- package/.generated/vite/application/vite.ts +144 -0
- package/.generated/vite/deployment.ts +46 -0
- package/{src/internal → .generated}/vite/index.ts +11 -4
- package/{src/preact-vite.ts → .generated/vite/preact.ts} +14 -3
- package/{src/react-vite.ts → .generated/vite/react.ts} +8 -3
- package/CHANGELOG.md +63 -0
- package/README.md +277 -35
- package/dist/client/deployment.d.ts +12 -0
- package/dist/client/deployment.js +102 -0
- package/dist/client/deserialize.js +10 -0
- package/dist/{internal/client → client}/index.d.ts +2 -0
- package/dist/client/index.js +47 -0
- package/dist/core/environment.d.ts +12 -0
- package/dist/core/environment.js +23 -0
- package/dist/core/errors.js +7 -0
- package/dist/{internal/core → core}/index.d.ts +1 -0
- package/dist/core/match.js +33 -0
- package/dist/core/navigation-router.d.ts +15 -0
- package/dist/core/navigation-router.js +64 -0
- package/dist/core/navigation.d.ts +15 -0
- package/dist/core/navigation.js +92 -0
- package/dist/core/presentation.d.ts +5 -0
- package/dist/core/presentation.js +69 -0
- package/dist/core/resource-types.d.ts +37 -0
- package/dist/core/resources.d.ts +19 -0
- package/dist/core/resources.js +345 -0
- package/dist/core/responses.d.ts +15 -0
- package/dist/core/responses.js +48 -0
- package/dist/{internal/core → core}/router.d.ts +1 -1
- package/dist/core/router.js +204 -0
- package/dist/{internal/core → core}/serialize.d.ts +2 -0
- package/dist/core/serialize.js +17 -0
- package/dist/core/store.d.ts +6 -0
- package/dist/core/store.js +21 -0
- package/dist/core/submission.d.ts +30 -0
- package/dist/core/submission.js +41 -0
- package/dist/{internal/core → core}/types.d.ts +16 -1
- package/dist/core/url.d.ts +7 -0
- package/dist/core/url.js +12 -0
- package/dist/core/utils.d.ts +5 -0
- package/dist/core/utils.js +5 -0
- package/dist/files/index.js +64 -0
- package/dist/preact/await.d.ts +7 -0
- package/dist/preact/await.js +19 -0
- package/dist/preact/client.d.ts +7 -0
- package/dist/preact/client.js +68 -0
- package/dist/preact/context.d.ts +18 -0
- package/dist/preact/context.js +23 -0
- package/dist/preact/document.d.ts +15 -0
- package/dist/preact/document.js +155 -0
- package/dist/{internal/preact → preact}/fetcher.d.ts +9 -5
- package/dist/preact/fetcher.js +45 -0
- package/dist/{internal/preact → preact}/form.d.ts +5 -6
- package/dist/preact/form.js +21 -0
- package/dist/{internal/preact → preact}/hooks.d.ts +7 -6
- package/dist/preact/hooks.js +25 -0
- package/dist/preact/index.d.ts +18 -0
- package/dist/preact/index.js +15 -0
- package/dist/preact/lazy-route.d.ts +19 -0
- package/dist/preact/lazy-route.js +51 -0
- package/dist/preact/navigation-state.d.ts +2 -0
- package/dist/preact/navigation-state.js +9 -0
- package/dist/preact/navigation.d.ts +28 -0
- package/dist/preact/navigation.js +60 -0
- package/dist/preact/root-context.d.ts +13 -0
- package/dist/preact/root-context.js +9 -0
- package/dist/preact/root-data.d.ts +8 -0
- package/dist/preact/root-data.js +28 -0
- package/dist/preact/route-hooks.d.ts +32 -0
- package/dist/preact/route-hooks.js +94 -0
- package/dist/preact/route-types.d.ts +54 -0
- package/dist/preact/router.d.ts +16 -0
- package/dist/preact/router.js +63 -0
- package/dist/{internal/preact → preact}/routes.d.ts +1 -1
- package/dist/preact/routes.js +12 -0
- package/dist/{internal/preact → preact}/runtime.js +1 -1
- package/dist/react/context.d.ts +18 -0
- package/dist/react/context.js +23 -0
- package/dist/react/data.d.ts +5 -0
- package/dist/react/data.js +3 -0
- package/dist/{internal/react → react}/fetcher.d.ts +2 -2
- package/dist/react/fetcher.js +34 -0
- package/dist/{internal/react → react}/form.d.ts +5 -6
- package/dist/react/form.js +21 -0
- package/dist/react/hooks.js +25 -0
- package/dist/{internal/react → react}/index.d.ts +1 -1
- package/dist/react/index.js +10 -0
- package/dist/{internal/react → react}/link.d.ts +2 -2
- package/dist/react/link.js +27 -0
- package/dist/react/resources/components.d.ts +64 -0
- package/dist/react/resources/components.js +239 -0
- package/dist/{internal/react → react}/routes.d.ts +1 -1
- package/dist/react/routes.js +12 -0
- package/dist/react/runtime.js +1 -0
- package/dist/server/application.d.ts +4 -0
- package/dist/server/application.js +119 -0
- package/dist/server/assets.d.ts +5 -0
- package/dist/server/assets.js +7 -0
- package/dist/server/handler.d.ts +19 -0
- package/dist/server/handler.js +22 -0
- package/dist/server/http.d.ts +4 -0
- package/dist/server/http.js +27 -0
- package/dist/server/index.js +76 -0
- package/dist/server/node.d.ts +3 -0
- package/dist/server/node.js +3 -0
- package/dist/server/preact.d.ts +3 -0
- package/dist/server/preact.js +4 -0
- package/dist/vite/application/browser-boundary.d.ts +3 -0
- package/dist/vite/application/browser-boundary.js +35 -0
- package/dist/vite/application/lazy-files.d.ts +2 -0
- package/dist/vite/application/lazy-files.js +88 -0
- package/dist/vite/application/vite.d.ts +9 -0
- package/dist/vite/application/vite.js +101 -0
- package/dist/vite/deployment.d.ts +8 -0
- package/dist/vite/deployment.js +36 -0
- package/dist/vite/index.js +109 -0
- package/dist/{preact-vite.d.ts → vite/preact.d.ts} +6 -3
- package/dist/vite/preact.js +16 -0
- package/dist/{react-vite.d.ts → vite/react.d.ts} +4 -3
- package/dist/vite/react.js +15 -0
- package/dist/vite/transport.js +35 -0
- package/jsr.json +28 -16
- package/package.json +115 -35
- package/dist/client.d.ts +0 -2
- package/dist/client.js +0 -2
- package/dist/core.d.ts +0 -2
- package/dist/core.js +0 -2
- package/dist/files.d.ts +0 -2
- package/dist/files.js +0 -2
- package/dist/internal/client/deserialize.js +0 -11
- package/dist/internal/client/index.js +0 -44
- package/dist/internal/core/errors.js +0 -6
- package/dist/internal/core/index.js +0 -7
- package/dist/internal/core/match.js +0 -27
- package/dist/internal/core/router.js +0 -189
- package/dist/internal/core/serialize.js +0 -13
- package/dist/internal/core/types.js +0 -5
- package/dist/internal/core/url.d.ts +0 -2
- package/dist/internal/core/url.js +0 -6
- package/dist/internal/files/index.js +0 -77
- package/dist/internal/preact/context.d.ts +0 -18
- package/dist/internal/preact/context.js +0 -20
- package/dist/internal/preact/fetcher.js +0 -28
- package/dist/internal/preact/form.js +0 -41
- package/dist/internal/preact/hooks.js +0 -35
- package/dist/internal/preact/index.d.ts +0 -9
- package/dist/internal/preact/index.js +0 -7
- package/dist/internal/preact/link.d.ts +0 -12
- package/dist/internal/preact/link.js +0 -28
- package/dist/internal/preact/routes.js +0 -22
- package/dist/internal/react/context.d.ts +0 -18
- package/dist/internal/react/context.js +0 -20
- package/dist/internal/react/fetcher.js +0 -28
- package/dist/internal/react/form.js +0 -41
- package/dist/internal/react/hooks.js +0 -35
- package/dist/internal/react/index.js +0 -7
- package/dist/internal/react/link.js +0 -28
- package/dist/internal/react/routes.js +0 -22
- package/dist/internal/react/runtime.js +0 -2
- package/dist/internal/server/index.js +0 -69
- package/dist/internal/vite/index.js +0 -132
- package/dist/internal/vite/transport.js +0 -42
- package/dist/preact-client.d.ts +0 -2
- package/dist/preact-client.js +0 -2
- package/dist/preact-server.d.ts +0 -2
- package/dist/preact-server.js +0 -2
- package/dist/preact-vite.js +0 -9
- package/dist/preact.d.ts +0 -2
- package/dist/preact.js +0 -2
- package/dist/react-client.d.ts +0 -2
- package/dist/react-client.js +0 -2
- package/dist/react-server.d.ts +0 -2
- package/dist/react-server.js +0 -2
- package/dist/react-vite.js +0 -9
- package/dist/react.d.ts +0 -2
- package/dist/react.js +0 -2
- package/dist/server.d.ts +0 -2
- package/dist/server.js +0 -2
- package/dist/utils.d.ts +0 -5
- package/dist/utils.js +0 -5
- package/dist/vite.d.ts +0 -2
- package/dist/vite.js +0 -2
- package/src/client.ts +0 -2
- package/src/core.ts +0 -2
- package/src/files.ts +0 -2
- package/src/internal/core/url.ts +0 -6
- package/src/internal/preact/context.ts +0 -46
- package/src/internal/preact/form.ts +0 -79
- package/src/internal/preact/link.ts +0 -46
- package/src/internal/react/context.ts +0 -46
- package/src/internal/react/form.ts +0 -79
- package/src/internal/react/index.ts +0 -13
- package/src/preact-client.ts +0 -2
- package/src/preact-server.ts +0 -2
- package/src/preact.ts +0 -2
- package/src/react-client.ts +0 -2
- package/src/react-server.ts +0 -2
- package/src/react.ts +0 -2
- package/src/server.ts +0 -2
- package/src/utils.ts +0 -5
- package/src/vite.ts +0 -2
- /package/{src/internal → .generated}/client/deserialize.ts +0 -0
- /package/{src/internal → .generated}/core/match.ts +0 -0
- /package/{src/internal → .generated}/files/index.ts +0 -0
- /package/{src/internal → .generated}/preact/runtime.ts +0 -0
- /package/{src/internal → .generated}/react/runtime.ts +0 -0
- /package/{src/internal → .generated}/vite/transport.ts +0 -0
- /package/dist/{internal/client → client}/deserialize.d.ts +0 -0
- /package/dist/{internal/core → core}/errors.d.ts +0 -0
- /package/dist/{internal/core → core}/match.d.ts +0 -0
- /package/dist/{internal/files → files}/index.d.ts +0 -0
- /package/dist/{internal/preact → preact}/runtime.d.ts +0 -0
- /package/dist/{internal/react → react}/hooks.d.ts +0 -0
- /package/dist/{internal/react → react}/runtime.d.ts +0 -0
- /package/dist/{internal/server → server}/index.d.ts +0 -0
- /package/dist/{internal/vite → vite}/index.d.ts +0 -0
- /package/dist/{internal/vite → vite}/transport.d.ts +0 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { submitForm } from "../core/submission.js";
|
|
2
|
+
import { createElement } from "./runtime.js";
|
|
3
|
+
import { useRouter } from "./context.js";
|
|
4
|
+
//#region .generated/preact/form.ts
|
|
5
|
+
/** Submit form data to a registered route without a document reload. */
|
|
6
|
+
function Form(options) {
|
|
7
|
+
const { action, method, fetcher, onSubmit, reloadDocument, preventScrollReset, replace, ...props } = options;
|
|
8
|
+
const router = useRouter();
|
|
9
|
+
const submit = (event) => {
|
|
10
|
+
onSubmit?.(event);
|
|
11
|
+
submitForm(router, event, event.submitter, options, fetcher);
|
|
12
|
+
};
|
|
13
|
+
return createElement("form", {
|
|
14
|
+
...props,
|
|
15
|
+
action,
|
|
16
|
+
method: method === "get" ? "get" : "post",
|
|
17
|
+
onSubmit: submit
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { Form };
|
|
@@ -2,19 +2,20 @@
|
|
|
2
2
|
* Preact components and typed data hooks. Import from @kasperrt/smolter/preact.
|
|
3
3
|
* @module
|
|
4
4
|
*/
|
|
5
|
-
import type { AnyDataFunction,
|
|
5
|
+
import type { AnyDataFunction, RouteModule, Router, Snapshot } from "../core/index.ts";
|
|
6
|
+
import type { RouteData } from "./route-types.ts";
|
|
6
7
|
/** A route module or loader function used for data inference. */
|
|
7
8
|
export type LoaderSource = RouteModule | AnyDataFunction;
|
|
8
9
|
/** Infer server and client loader data from a route module or function. */
|
|
9
|
-
export type LoaderData<T> = T extends AnyDataFunction ?
|
|
10
|
+
export type LoaderData<T> = T extends AnyDataFunction ? RouteData<T> : T extends RouteModule ? RouteData<Extract<T["loader"] | T["clientLoader"], AnyDataFunction>> : RouteData<T>;
|
|
10
11
|
/** Infer server and client action data from a route module or function. */
|
|
11
|
-
export type ActionData<T> = T extends AnyDataFunction ?
|
|
12
|
+
export type ActionData<T> = T extends AnyDataFunction ? RouteData<T> : T extends RouteModule ? RouteData<Extract<T["action"] | T["clientAction"], AnyDataFunction>> : RouteData<T>;
|
|
12
13
|
/** Pass a route for inference, or use useLoaderData<typeof loader>() in its module. */
|
|
13
|
-
export declare function useLoaderData<T
|
|
14
|
+
export declare function useLoaderData<T = RouteModule>(route?: T & LoaderSource): LoaderData<T>;
|
|
14
15
|
/** Read the last page action result, optionally inferring its type from a route. */
|
|
15
|
-
export declare function useActionData<T
|
|
16
|
+
export declare function useActionData<T = RouteModule>(route?: T & LoaderSource): ActionData<T> | undefined;
|
|
16
17
|
/** Read path parameters for the active route. */
|
|
17
|
-
export declare function useParams
|
|
18
|
+
export declare function useParams<T extends Snapshot["params"] = Snapshot["params"]>(): T;
|
|
18
19
|
/** Read the current path, search, and hash together with the navigate function. */
|
|
19
20
|
export declare function useLocation(): readonly [string, Router["navigate"]];
|
|
20
21
|
/** Get the function that revalidates the current loader subject to shouldRevalidate. */
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { useRouter, useSnapshot } from "./context.js";
|
|
2
|
+
//#region .generated/preact/hooks.ts
|
|
3
|
+
/** Pass a route for inference, or use useLoaderData<typeof loader>() in its module. */
|
|
4
|
+
function useLoaderData(route) {
|
|
5
|
+
return useSnapshot("data", route?.path);
|
|
6
|
+
}
|
|
7
|
+
/** Read the last page action result, optionally inferring its type from a route. */
|
|
8
|
+
function useActionData(route) {
|
|
9
|
+
return useSnapshot("actionData", route?.path);
|
|
10
|
+
}
|
|
11
|
+
/** Read path parameters for the active route. */
|
|
12
|
+
function useParams() {
|
|
13
|
+
return useSnapshot("params");
|
|
14
|
+
}
|
|
15
|
+
/** Read the current path, search, and hash together with the navigate function. */
|
|
16
|
+
function useLocation() {
|
|
17
|
+
const router = useRouter();
|
|
18
|
+
return [useSnapshot("url").replace(/^\w+:\/\/[^/]+/, ""), router.navigate];
|
|
19
|
+
}
|
|
20
|
+
/** Get the function that revalidates the current loader subject to shouldRevalidate. */
|
|
21
|
+
function useRevalidator() {
|
|
22
|
+
return useRouter().revalidate;
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { useActionData, useLoaderData, useLocation, useParams, useRevalidator };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Framework components and typed data hooks. @module */
|
|
2
|
+
export type * from "../core/index.ts";
|
|
3
|
+
export { createDataRouter, createRouter, defineRoute, } from "../core/index.ts";
|
|
4
|
+
export type { ApplicationEnvironment } from "../core/environment.ts";
|
|
5
|
+
export * from "../core/responses.ts";
|
|
6
|
+
export type { Submission, SubmissionOptions } from "../core/submission.ts";
|
|
7
|
+
export { readSubmission } from "../core/submission.ts";
|
|
8
|
+
export { Await } from "./await.tsx";
|
|
9
|
+
export { RouterProvider, type RouterProviderProps, useRouter, } from "./context.ts";
|
|
10
|
+
export * from "./fetcher.ts";
|
|
11
|
+
export * from "./form.ts";
|
|
12
|
+
export * from "./hooks.ts";
|
|
13
|
+
export type { NavigateOptions } from "./navigation.tsx";
|
|
14
|
+
export * from "./navigation.tsx";
|
|
15
|
+
export { useMatches, useNavigation, useOutletContext, useRootData, useRouteError, useRouteLoaderData, useSubmit, } from "./route-hooks.tsx";
|
|
16
|
+
export * from "./route-types.ts";
|
|
17
|
+
export { Outlet, RouterApplication } from "./router.tsx";
|
|
18
|
+
export * from "./routes.ts";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { defineRoute } from "../core/match.js";
|
|
2
|
+
import { createRouter } from "../core/navigation-router.js";
|
|
3
|
+
import { createDataRouter } from "../core/router.js";
|
|
4
|
+
import { readSubmission } from "../core/submission.js";
|
|
5
|
+
import { data, isRouteErrorResponse, normalizeResult, redirect, resolveData } from "../core/responses.js";
|
|
6
|
+
import { Await } from "./await.js";
|
|
7
|
+
import { RouterProvider, useRouter } from "./context.js";
|
|
8
|
+
import { Form } from "./form.js";
|
|
9
|
+
import { useFetcher } from "./fetcher.js";
|
|
10
|
+
import { useActionData, useLoaderData, useLocation, useParams, useRevalidator } from "./hooks.js";
|
|
11
|
+
import { useMatches, useNavigate, useNavigation, useNavigationType, useOutletContext, useRootData, useRouteError, useRouteLoaderData, useSearchParams, useSubmit, useURLLocation } from "./route-hooks.js";
|
|
12
|
+
import { Link, NavLink } from "./navigation.js";
|
|
13
|
+
import { Routes } from "./routes.js";
|
|
14
|
+
import { Outlet, RouterApplication } from "./router.js";
|
|
15
|
+
export { Await, Form, Link, NavLink, Outlet, RouterApplication, RouterProvider, Routes, createDataRouter, createRouter, data, defineRoute, isRouteErrorResponse, normalizeResult, readSubmission, redirect, resolveData, useActionData, useFetcher, useLoaderData, useLocation, useMatches, useNavigate, useNavigation, useNavigationType, useOutletContext, useParams, useRevalidator, useRootData, useRouteError, useRouteLoaderData, useRouter, useSearchParams, useSubmit, useURLLocation };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { RouteModule } from "../core/index.ts";
|
|
2
|
+
import { type ComponentType } from "preact";
|
|
3
|
+
import type { AppRoute } from "./route-types.ts";
|
|
4
|
+
export interface LazyRouteOptions {
|
|
5
|
+
path: string;
|
|
6
|
+
id?: string;
|
|
7
|
+
loader?: boolean;
|
|
8
|
+
action?: boolean;
|
|
9
|
+
clientAction?: boolean;
|
|
10
|
+
meta?: boolean;
|
|
11
|
+
shouldRevalidate?: boolean;
|
|
12
|
+
ErrorBoundary?: boolean;
|
|
13
|
+
}
|
|
14
|
+
type LoadedRoute = RouteModule & Pick<AppRoute, "meta">;
|
|
15
|
+
interface LazyAppRoute extends AppRoute {
|
|
16
|
+
resolveComponent: () => ComponentType | undefined;
|
|
17
|
+
}
|
|
18
|
+
export declare function lazyRoute(options: LazyRouteOptions, importer: () => Promise<LoadedRoute>): LazyAppRoute;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { useSyncExternalStore } from "./runtime.js";
|
|
2
|
+
import { useRouter } from "./context.js";
|
|
3
|
+
import { serverRoute } from "../client/index.js";
|
|
4
|
+
import { createElement } from "preact";
|
|
5
|
+
//#region .generated/preact/lazy-route.ts
|
|
6
|
+
function LazyView() {
|
|
7
|
+
const router = useRouter();
|
|
8
|
+
const { path } = useSyncExternalStore(router.subscribe, router.getSnapshot);
|
|
9
|
+
const Component = router.routes.find((item) => item.path === path)?.resolveComponent();
|
|
10
|
+
return Component && createElement(Component, {});
|
|
11
|
+
}
|
|
12
|
+
function lazyRoute(options, importer) {
|
|
13
|
+
let module;
|
|
14
|
+
let pending;
|
|
15
|
+
function preload() {
|
|
16
|
+
pending ??= importer().then((loaded) => {
|
|
17
|
+
module = serverRoute(options.path, loaded, {
|
|
18
|
+
loader: options.loader,
|
|
19
|
+
action: options.action
|
|
20
|
+
});
|
|
21
|
+
}).catch((error) => {
|
|
22
|
+
pending = void 0;
|
|
23
|
+
throw error;
|
|
24
|
+
});
|
|
25
|
+
return pending;
|
|
26
|
+
}
|
|
27
|
+
async function run(args, action = false) {
|
|
28
|
+
await preload();
|
|
29
|
+
if (args.signal.aborted) return /* @__PURE__ */ new Error("Navigation cancelled");
|
|
30
|
+
return (action ? module.clientAction ?? module.action : module.clientLoader ?? module.loader)?.(args);
|
|
31
|
+
}
|
|
32
|
+
function ErrorBoundary(props) {
|
|
33
|
+
const Component = module?.ErrorBoundary;
|
|
34
|
+
if (!Component) return props.error.message;
|
|
35
|
+
return createElement(Component, props);
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
path: options.path,
|
|
39
|
+
id: options.id,
|
|
40
|
+
preload,
|
|
41
|
+
default: LazyView,
|
|
42
|
+
resolveComponent: () => module?.default,
|
|
43
|
+
clientLoader: (args) => run(args),
|
|
44
|
+
...(options.action || options.clientAction) && { clientAction: (args) => run(args, true) },
|
|
45
|
+
...options.meta && { meta: (args) => module?.meta?.(args) ?? [] },
|
|
46
|
+
...options.shouldRevalidate && { shouldRevalidate: (args) => module?.shouldRevalidate?.(args) ?? true },
|
|
47
|
+
...options.ErrorBoundary && { ErrorBoundary }
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
export { lazyRoute };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { useSyncExternalStore } from "./runtime.js";
|
|
2
|
+
import { navigationStore } from "../core/navigation.js";
|
|
3
|
+
//#region .generated/preact/navigation-state.ts
|
|
4
|
+
function useNavigationSnapshot(router) {
|
|
5
|
+
const store = navigationStore(router);
|
|
6
|
+
return useSyncExternalStore(store.subscribe, store.getSnapshot);
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { useNavigationSnapshot };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type NavigateOptions } from "../core/index.ts";
|
|
2
|
+
import type { ComponentProps, ReactNode } from "preact/compat";
|
|
3
|
+
export type { NavigateOptions } from "../core/index.ts";
|
|
4
|
+
export type { NavigationType } from "../core/navigation.ts";
|
|
5
|
+
export type NavigateFunction = (to: string | number | Partial<Pick<URL, "pathname" | "search" | "hash">>, options?: NavigateOptions) => void;
|
|
6
|
+
export interface LinkProps extends Omit<ComponentProps<"a">, "href" | "role"> {
|
|
7
|
+
to?: string;
|
|
8
|
+
href?: string;
|
|
9
|
+
replace?: boolean;
|
|
10
|
+
role?: "link" | "button" | "checkbox" | "menuitem" | "menuitemcheckbox" | "menuitemradio" | "option" | "radio" | "switch" | "tab" | "treeitem" | "doc-backlink" | "doc-biblioref" | "doc-glossref" | "doc-noteref";
|
|
11
|
+
prefetch?: string;
|
|
12
|
+
state?: unknown;
|
|
13
|
+
preventScrollReset?: boolean;
|
|
14
|
+
viewTransition?: boolean;
|
|
15
|
+
reloadDocument?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface NavLinkRenderProps {
|
|
18
|
+
isActive: boolean;
|
|
19
|
+
isPending: boolean;
|
|
20
|
+
}
|
|
21
|
+
export interface NavLinkProps extends Omit<LinkProps, "className" | "children"> {
|
|
22
|
+
end?: boolean;
|
|
23
|
+
className?: string | ((state: NavLinkRenderProps) => string);
|
|
24
|
+
children?: ReactNode | ((state: NavLinkRenderProps) => ReactNode);
|
|
25
|
+
}
|
|
26
|
+
export declare function Link(options: LinkProps): ReactNode;
|
|
27
|
+
export declare function NavLink({ href, to, end, className, children, ...props }: NavLinkProps): ReactNode;
|
|
28
|
+
export { useNavigate, useNavigationType, useSearchParams, useURLLocation, } from "./route-hooks.tsx";
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { matchRoutes } from "../core/match.js";
|
|
2
|
+
import { navigationClick } from "../core/url.js";
|
|
3
|
+
import { createElement } from "./runtime.js";
|
|
4
|
+
import { useRouter, useSnapshot } from "./context.js";
|
|
5
|
+
import { handoffDocument, resolveApplicationURL } from "../core/environment.js";
|
|
6
|
+
import { useNavigate, useNavigationType, useSearchParams, useURLLocation } from "./route-hooks.js";
|
|
7
|
+
//#region .generated/preact/navigation.tsx
|
|
8
|
+
function Link(options) {
|
|
9
|
+
const { href: hrefProp, to = hrefProp ?? "/", replace, preventScrollReset, viewTransition, prefetch, state, reloadDocument, ...props } = options;
|
|
10
|
+
const router = useRouter();
|
|
11
|
+
const current = new URL(useSnapshot("url"));
|
|
12
|
+
const destination = resolveApplicationURL(new URL(to, current));
|
|
13
|
+
const internal = destination.origin === current.origin;
|
|
14
|
+
const preload = () => {
|
|
15
|
+
(matchRoutes(router.routes, destination.pathname)?.route)?.preload?.().catch(() => {});
|
|
16
|
+
};
|
|
17
|
+
if (!reloadDocument && prefetch !== "none" && internal) for (const name of [
|
|
18
|
+
"onPointerEnter",
|
|
19
|
+
"onFocus",
|
|
20
|
+
"onTouchStart"
|
|
21
|
+
]) {
|
|
22
|
+
const handler = props[name];
|
|
23
|
+
props[name] = (event) => {
|
|
24
|
+
handler?.(event);
|
|
25
|
+
preload();
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
return createElement("a", {
|
|
29
|
+
...props,
|
|
30
|
+
href: destination.href,
|
|
31
|
+
onClick(event) {
|
|
32
|
+
props.onClick?.(event);
|
|
33
|
+
if (reloadDocument || !navigationClick(event, event.currentTarget)) return;
|
|
34
|
+
if (!internal) {
|
|
35
|
+
handoffDocument(event, destination);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
event.preventDefault();
|
|
39
|
+
router.navigate(destination.href, options);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
function NavLink({ href, to = href ?? "/", end, className, children, ...props }) {
|
|
44
|
+
const location = useURLLocation();
|
|
45
|
+
const target = new URL(to, location.href).pathname;
|
|
46
|
+
const isActive = location.pathname === target || !end && target !== "/" && location.pathname.startsWith(`${target}/`);
|
|
47
|
+
const state = {
|
|
48
|
+
isActive,
|
|
49
|
+
isPending: false
|
|
50
|
+
};
|
|
51
|
+
return createElement(Link, {
|
|
52
|
+
...props,
|
|
53
|
+
to,
|
|
54
|
+
className: typeof className === "function" ? className(state) : className,
|
|
55
|
+
...isActive && { "aria-current": "page" },
|
|
56
|
+
children: typeof children === "function" ? children(state) : children
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
60
|
+
export { Link, NavLink, useNavigate, useNavigationType, useSearchParams, useURLLocation };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Router } from "../core/index.ts";
|
|
2
|
+
import type { AppRoute, Hydration, RootModule } from "./route-types.ts";
|
|
3
|
+
export interface ApplicationContext {
|
|
4
|
+
router: Router;
|
|
5
|
+
routes: AppRoute[];
|
|
6
|
+
root: unknown;
|
|
7
|
+
rootModule?: RootModule;
|
|
8
|
+
hydration?: Hydration;
|
|
9
|
+
entry?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare const Application: import("preact").Context<ApplicationContext | null>;
|
|
12
|
+
export declare const OutletContext: import("preact").Context<unknown>;
|
|
13
|
+
export declare function useApplication(): ApplicationContext;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { createContext, useContext } from "./runtime.js";
|
|
2
|
+
//#region .generated/preact/root-context.ts
|
|
3
|
+
var Application = createContext(null);
|
|
4
|
+
var OutletContext = createContext(void 0);
|
|
5
|
+
function useApplication() {
|
|
6
|
+
return useContext(Application);
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { Application, OutletContext, useApplication };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Router } from "../core/index.ts";
|
|
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
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { createStore } from "../core/store.js";
|
|
2
|
+
//#region .generated/preact/root-data.ts
|
|
3
|
+
function attachRootData(router, initial, rootModule) {
|
|
4
|
+
const store = createStore(initial);
|
|
5
|
+
const loaderPath = rootModule?.loaderPath;
|
|
6
|
+
if (!rootModule || !loaderPath) return store;
|
|
7
|
+
let pending;
|
|
8
|
+
const unregister = router.registerRevalidator(rootModule.id ?? "root", async (args) => {
|
|
9
|
+
if (rootModule.shouldRevalidate?.(args) === false) return;
|
|
10
|
+
pending?.dispose();
|
|
11
|
+
const fetcher = router.createFetcher();
|
|
12
|
+
pending = fetcher;
|
|
13
|
+
const result = await fetcher.load(loaderPath);
|
|
14
|
+
if (pending === fetcher && !result.error) store.update(result.data);
|
|
15
|
+
fetcher.dispose();
|
|
16
|
+
if (pending === fetcher) pending = void 0;
|
|
17
|
+
});
|
|
18
|
+
const dispose = router.dispose;
|
|
19
|
+
router.dispose = () => {
|
|
20
|
+
pending?.dispose();
|
|
21
|
+
pending = void 0;
|
|
22
|
+
unregister();
|
|
23
|
+
dispose();
|
|
24
|
+
};
|
|
25
|
+
return store;
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { attachRootData, createStore as createRootStore };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { NavigateOptions } from "../core/index.ts";
|
|
2
|
+
import type { NavigationType } from "../core/navigation.ts";
|
|
3
|
+
import { type Submission, type SubmissionOptions } from "../core/submission.ts";
|
|
4
|
+
import { useSnapshot } from "./context.ts";
|
|
5
|
+
import type { NavigateFunction } from "./navigation.tsx";
|
|
6
|
+
import type { RouteData } from "./route-types.ts";
|
|
7
|
+
export declare function useRootData<T = unknown>(): RouteData<T>;
|
|
8
|
+
/** Read root data or the active route's data by its manifest identifier. */
|
|
9
|
+
export declare function useRouteLoaderData<T = unknown>(id: string): RouteData<T> | undefined;
|
|
10
|
+
export { useSnapshot };
|
|
11
|
+
export declare function useRouteError(): Error | undefined;
|
|
12
|
+
export declare function useNavigation(): {
|
|
13
|
+
state: "idle" | "loading" | "submitting";
|
|
14
|
+
location: URL | undefined;
|
|
15
|
+
};
|
|
16
|
+
export declare function useMatches(): {
|
|
17
|
+
id: string;
|
|
18
|
+
data: unknown;
|
|
19
|
+
params: import("../core/index.ts").Params;
|
|
20
|
+
}[];
|
|
21
|
+
export declare function useOutletContext<T>(): T;
|
|
22
|
+
export declare function useSubmit(): (value: Submission, options?: SubmissionOptions) => Promise<void> | Promise<import("../core/index.ts").Result<unknown>>;
|
|
23
|
+
export declare function useURLLocation(): URL & {
|
|
24
|
+
state: unknown;
|
|
25
|
+
key: string;
|
|
26
|
+
};
|
|
27
|
+
export declare function useNavigate(): NavigateFunction;
|
|
28
|
+
export declare function useSearchParams(): [
|
|
29
|
+
URLSearchParams,
|
|
30
|
+
(value: URLSearchParams | Record<string, string>, options?: NavigateOptions) => void
|
|
31
|
+
];
|
|
32
|
+
export declare function useNavigationType(): NavigationType;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { submissionBody, submissionSearch } from "../core/submission.js";
|
|
2
|
+
import { useContext, useMemo } from "./runtime.js";
|
|
3
|
+
import { useRouter, useSnapshot } from "./context.js";
|
|
4
|
+
import { pendingLocation } from "../core/presentation.js";
|
|
5
|
+
import { useNavigationSnapshot } from "./navigation-state.js";
|
|
6
|
+
import { OutletContext, useApplication } from "./root-context.js";
|
|
7
|
+
import { useCallback } from "preact/hooks";
|
|
8
|
+
//#region .generated/preact/route-hooks.tsx
|
|
9
|
+
function useRootData() {
|
|
10
|
+
return useApplication().root;
|
|
11
|
+
}
|
|
12
|
+
/** Read root data or the active route's data by its manifest identifier. */
|
|
13
|
+
function useRouteLoaderData(id) {
|
|
14
|
+
const app = useApplication();
|
|
15
|
+
const snapshot = useSnapshot();
|
|
16
|
+
if (id === "root") return app.root;
|
|
17
|
+
const route = app.routes.find((item) => item.id === id);
|
|
18
|
+
if (!route || route.path !== snapshot.path) return void 0;
|
|
19
|
+
return snapshot.data;
|
|
20
|
+
}
|
|
21
|
+
function useRouteError() {
|
|
22
|
+
return useSnapshot("error");
|
|
23
|
+
}
|
|
24
|
+
function useNavigation() {
|
|
25
|
+
const router = useRouter();
|
|
26
|
+
const snapshot = useSnapshot();
|
|
27
|
+
const location = pendingLocation(router);
|
|
28
|
+
return useMemo(() => ({
|
|
29
|
+
state: snapshot.state,
|
|
30
|
+
location
|
|
31
|
+
}), [snapshot.state, location?.href]);
|
|
32
|
+
}
|
|
33
|
+
function useMatches() {
|
|
34
|
+
const { routes } = useApplication();
|
|
35
|
+
const snapshot = useSnapshot();
|
|
36
|
+
return [{
|
|
37
|
+
id: routes.find((item) => item.path === snapshot.path)?.id ?? "",
|
|
38
|
+
data: snapshot.data,
|
|
39
|
+
params: snapshot.params
|
|
40
|
+
}];
|
|
41
|
+
}
|
|
42
|
+
function useOutletContext() {
|
|
43
|
+
return useContext(OutletContext);
|
|
44
|
+
}
|
|
45
|
+
function useSubmit() {
|
|
46
|
+
const router = useRouter();
|
|
47
|
+
return useCallback((value, options = {}) => {
|
|
48
|
+
const body = submissionBody(value, options.encType);
|
|
49
|
+
const method = options.method?.toUpperCase();
|
|
50
|
+
const target = options.action ?? router.getSnapshot().url;
|
|
51
|
+
if (method === "GET") {
|
|
52
|
+
const url = new URL(target, router.getSnapshot().url);
|
|
53
|
+
url.search = submissionSearch(body);
|
|
54
|
+
return router.navigate(url.href, options);
|
|
55
|
+
}
|
|
56
|
+
return router.submit(target, body, { method });
|
|
57
|
+
}, [router]);
|
|
58
|
+
}
|
|
59
|
+
function useURLLocation() {
|
|
60
|
+
const href = useSnapshot("url");
|
|
61
|
+
const snapshot = useNavigationSnapshot(useRouter());
|
|
62
|
+
return useMemo(() => Object.assign(new URL(href), {
|
|
63
|
+
state: snapshot.state,
|
|
64
|
+
key: snapshot.key
|
|
65
|
+
}), [
|
|
66
|
+
href,
|
|
67
|
+
snapshot.state,
|
|
68
|
+
snapshot.key
|
|
69
|
+
]);
|
|
70
|
+
}
|
|
71
|
+
function useNavigate() {
|
|
72
|
+
const router = useRouter();
|
|
73
|
+
return useCallback((to, options) => {
|
|
74
|
+
if (typeof to === "number") {
|
|
75
|
+
window.history.go(to);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const current = new URL(router.getSnapshot().url);
|
|
79
|
+
const target = typeof to === "string" ? to : `${to.pathname ?? current.pathname}${to.search ?? current.search}${to.hash ?? current.hash}`;
|
|
80
|
+
router.navigate(target, options);
|
|
81
|
+
}, [router]);
|
|
82
|
+
}
|
|
83
|
+
function useSearchParams() {
|
|
84
|
+
const location = useURLLocation();
|
|
85
|
+
const navigate = useNavigate();
|
|
86
|
+
return [useMemo(() => new URLSearchParams(location.search), [location.search]), useCallback((value, options) => {
|
|
87
|
+
navigate(`${location.pathname}?${new URLSearchParams(value)}`, options);
|
|
88
|
+
}, [location.pathname, navigate])];
|
|
89
|
+
}
|
|
90
|
+
function useNavigationType() {
|
|
91
|
+
return useNavigationSnapshot(useRouter()).type;
|
|
92
|
+
}
|
|
93
|
+
//#endregion
|
|
94
|
+
export { useMatches, useNavigate, useNavigation, useNavigationType, useOutletContext, useRootData, useRouteError, useRouteLoaderData, useSearchParams, useSnapshot, useSubmit, useURLLocation };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { DataArgs, RevalidationArgs, Route, Snapshot } from "../core/index.ts";
|
|
2
|
+
import type { DataResponse } from "../core/responses.ts";
|
|
3
|
+
import type { ComponentType, ReactNode } from "preact/compat";
|
|
4
|
+
export interface LoaderFunctionArgs extends DataArgs {
|
|
5
|
+
context?: unknown;
|
|
6
|
+
}
|
|
7
|
+
export type ActionFunctionArgs = LoaderFunctionArgs;
|
|
8
|
+
export interface ClientLoaderFunctionArgs extends LoaderFunctionArgs {
|
|
9
|
+
serverLoader: <T = unknown>() => Promise<T>;
|
|
10
|
+
}
|
|
11
|
+
export interface ClientActionFunctionArgs extends LoaderFunctionArgs {
|
|
12
|
+
serverAction: <T = unknown>() => Promise<T>;
|
|
13
|
+
}
|
|
14
|
+
export type ShouldRevalidateFunctionArgs = RevalidationArgs;
|
|
15
|
+
type UnwrapData<T> = T extends DataResponse<infer V> ? V : T;
|
|
16
|
+
export type RouteData<T> = T extends (...args: never[]) => infer R ? UnwrapData<Exclude<Awaited<R>, Response | Error>> : T;
|
|
17
|
+
export type MetaDescriptor = Record<string, unknown>;
|
|
18
|
+
export interface MetaArgs<T> {
|
|
19
|
+
data: RouteData<T> | undefined;
|
|
20
|
+
loaderData: RouteData<T> | undefined;
|
|
21
|
+
error?: unknown;
|
|
22
|
+
params: Record<string, string>;
|
|
23
|
+
location: URL;
|
|
24
|
+
}
|
|
25
|
+
export type MetaFunction<T = unknown> = (args: MetaArgs<T>) => MetaDescriptor[];
|
|
26
|
+
export type LinksFunction = () => Record<string, string>[];
|
|
27
|
+
export interface AppRoute extends Route {
|
|
28
|
+
resolveComponent?: () => ComponentType | undefined;
|
|
29
|
+
preload?: () => Promise<void>;
|
|
30
|
+
id?: string;
|
|
31
|
+
routePath?: string;
|
|
32
|
+
meta?: MetaFunction;
|
|
33
|
+
}
|
|
34
|
+
export interface RootModule {
|
|
35
|
+
/** Route identity used by targeted revalidation. Defaults to root. */
|
|
36
|
+
id?: string;
|
|
37
|
+
/** Optional registered route URL used to revalidate root data after mutations. */
|
|
38
|
+
loaderPath?: string;
|
|
39
|
+
ErrorBoundary?: ComponentType;
|
|
40
|
+
default: ComponentType;
|
|
41
|
+
Layout: ComponentType<{
|
|
42
|
+
children: ReactNode;
|
|
43
|
+
}>;
|
|
44
|
+
loader?: (args: LoaderFunctionArgs) => unknown;
|
|
45
|
+
links?: LinksFunction;
|
|
46
|
+
meta?: MetaFunction;
|
|
47
|
+
shouldRevalidate?: (args: RevalidationArgs) => boolean;
|
|
48
|
+
}
|
|
49
|
+
export interface Hydration {
|
|
50
|
+
root: unknown;
|
|
51
|
+
snapshot: Snapshot;
|
|
52
|
+
}
|
|
53
|
+
export type HandleDataRequestFunction = (response: Response, args: LoaderFunctionArgs) => Response | Promise<Response>;
|
|
54
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** @jsxImportSource preact */
|
|
2
|
+
import type { ReactNode } from "preact/compat";
|
|
3
|
+
import { type ApplicationContext } from "./root-context.ts";
|
|
4
|
+
import { createRootStore } from "./root-data.ts";
|
|
5
|
+
import type { AppRoute } from "./route-types.ts";
|
|
6
|
+
export interface OutletProps {
|
|
7
|
+
context?: unknown;
|
|
8
|
+
children?: ReactNode;
|
|
9
|
+
}
|
|
10
|
+
export declare function Outlet({ context, children, }: OutletProps): import("preact").JSX.Element;
|
|
11
|
+
export interface ApplicationProps extends ApplicationContext {
|
|
12
|
+
document?: boolean;
|
|
13
|
+
rootStore?: ReturnType<typeof createRootStore>;
|
|
14
|
+
}
|
|
15
|
+
export declare function RouterApplication(props: ApplicationProps): import("preact").JSX.Element;
|
|
16
|
+
export declare function prepareRoutes(routes: AppRoute[]): AppRoute[];
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { normalizeResult } from "../core/responses.js";
|
|
2
|
+
import { useContext, useMemo, useSyncExternalStore } from "./runtime.js";
|
|
3
|
+
import { RouterProvider } from "./context.js";
|
|
4
|
+
import { createStore } from "../core/store.js";
|
|
5
|
+
import { Application, OutletContext } from "./root-context.js";
|
|
6
|
+
import { Routes } from "./routes.js";
|
|
7
|
+
import { jsx } from "preact/jsx-runtime";
|
|
8
|
+
//#region .generated/preact/router.tsx
|
|
9
|
+
function Outlet({ context, children }) {
|
|
10
|
+
const current = useContext(OutletContext);
|
|
11
|
+
return /* @__PURE__ */ jsx(OutletContext, {
|
|
12
|
+
value: context ?? current,
|
|
13
|
+
children: children ?? /* @__PURE__ */ jsx(Routes, { fallback: /* @__PURE__ */ jsx("p", {
|
|
14
|
+
role: "status",
|
|
15
|
+
children: "Loading…"
|
|
16
|
+
}) })
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
function RouterApplication(props) {
|
|
20
|
+
const rootStore = useMemo(() => props.rootStore ?? createStore(props.root), [props.rootStore, props.root]);
|
|
21
|
+
const root = useSyncExternalStore(rootStore.subscribe, rootStore.getSnapshot);
|
|
22
|
+
const snapshot = useSyncExternalStore(props.router.subscribe, props.router.getSnapshot);
|
|
23
|
+
const route = props.routes.find((item) => item.path === snapshot.path);
|
|
24
|
+
const Root = snapshot.error && !route?.ErrorBoundary ? props.rootModule?.ErrorBoundary ?? Outlet : props.rootModule?.default ?? Outlet;
|
|
25
|
+
const Layout = props.rootModule?.Layout;
|
|
26
|
+
const children = /* @__PURE__ */ jsx(Root, {});
|
|
27
|
+
return /* @__PURE__ */ jsx(RouterProvider, {
|
|
28
|
+
router: props.router,
|
|
29
|
+
children: /* @__PURE__ */ jsx(Application, {
|
|
30
|
+
value: {
|
|
31
|
+
...props,
|
|
32
|
+
root
|
|
33
|
+
},
|
|
34
|
+
children: props.document ? Layout && /* @__PURE__ */ jsx(Layout, { children }) : children
|
|
35
|
+
})
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
function prepareRoutes(routes) {
|
|
39
|
+
return routes.map((route) => {
|
|
40
|
+
const wrapped = {
|
|
41
|
+
...route,
|
|
42
|
+
path: route.routePath ?? route.path,
|
|
43
|
+
shouldRevalidate: (args) => {
|
|
44
|
+
const { currentUrl, nextUrl } = args;
|
|
45
|
+
if (args.reason === "navigation" && currentUrl.pathname === nextUrl.pathname && currentUrl.search === nextUrl.search && currentUrl.hash !== nextUrl.hash) return false;
|
|
46
|
+
return route.shouldRevalidate?.(args) ?? args.defaultShouldRevalidate;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
for (const key of [
|
|
50
|
+
"loader",
|
|
51
|
+
"action",
|
|
52
|
+
"clientLoader",
|
|
53
|
+
"clientAction"
|
|
54
|
+
]) {
|
|
55
|
+
const handler = route[key];
|
|
56
|
+
if (!handler) continue;
|
|
57
|
+
wrapped[key] = (args) => Promise.resolve().then(() => handler(args)).then(normalizeResult, normalizeResult);
|
|
58
|
+
}
|
|
59
|
+
return wrapped;
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
//#endregion
|
|
63
|
+
export { Outlet, RouterApplication, prepareRoutes };
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @module
|
|
4
4
|
*/
|
|
5
5
|
import type { RouteModule } from "../core/index.ts";
|
|
6
|
-
import type
|
|
6
|
+
import { type ComponentType, type ReactNode } from "./runtime.ts";
|
|
7
7
|
/** Renderable route module with optional loading and error components. */
|
|
8
8
|
export interface ViewModule extends RouteModule {
|
|
9
9
|
default?: ComponentType;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { createElement, useMemo } from "./runtime.js";
|
|
2
|
+
import { useRouter, useSnapshot } from "./context.js";
|
|
3
|
+
//#region .generated/preact/routes.ts
|
|
4
|
+
/** Renders the first matching registered module. */
|
|
5
|
+
function Routes({ fallback }) {
|
|
6
|
+
const router = useRouter();
|
|
7
|
+
const state = useSnapshot();
|
|
8
|
+
const component = router.routes.find((route) => route.path === state.path)?.[state.error ? "ErrorBoundary" : state.state === "loading" && !state.loaded ? "HydrateFallback" : "default"];
|
|
9
|
+
return useMemo(() => component && createElement(component, { error: state.error }), [component, state.error]) ?? state.error?.message ?? fallback;
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { Routes };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { createContext, createElement, useContext, useEffect, useMemo, useSyncExternalStore
|
|
1
|
+
export { createContext, createElement, useContext, useEffect, useMemo, useSyncExternalStore } from "preact/compat";
|