weifuwu 0.31.0 → 0.31.2
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/README.md +107 -78
- package/dist/core/router.d.ts +11 -0
- package/dist/index.d.ts +7 -7
- package/dist/index.js +895 -311
- package/dist/middleware/esbuild-dev.d.ts +69 -0
- package/dist/middleware/esbuild-dev.js +335 -0
- package/dist/middleware/tailwind-dev.d.ts +43 -0
- package/dist/middleware/tailwind-dev.js +199 -0
- package/dist/react/client.d.ts +64 -27
- package/dist/react/client.js +130 -248
- package/dist/react/compile.d.ts +17 -0
- package/dist/react/error-boundary.d.ts +18 -19
- package/dist/react/index.d.ts +80 -16
- package/dist/react/index.js +835 -267
- package/dist/react/types.d.ts +134 -34
- package/package.json +16 -6
- package/dist/react/navigation.d.ts +0 -63
- package/dist/react/navigation.js +0 -154
- package/dist/react/render.d.ts +0 -8
- package/dist/react/route-utils.d.ts +0 -31
package/dist/react/index.d.ts
CHANGED
|
@@ -1,28 +1,92 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ReactElement, type ComponentType } from 'react';
|
|
2
|
+
import { type Middleware } from '../types.ts';
|
|
3
|
+
import type { Router } from '../core/router.ts';
|
|
4
|
+
import type { ReactOptions, ReactRouterOptions, ReactAppOptions } from './types.ts';
|
|
2
5
|
/**
|
|
3
|
-
* React SSR middleware.
|
|
6
|
+
* React SSR middleware — injects `ctx.render(path, opts?)`.
|
|
4
7
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
8
|
+
* Options:
|
|
9
|
+
* - `layout`: Wrap every page in a shared layout component (nav, footer, etc.)
|
|
10
|
+
*
|
|
11
|
+
* For Tailwind CSS: use `tailwindDev` middleware.
|
|
12
|
+
* For client bundles: use `esbuildDev` middleware.
|
|
7
13
|
*
|
|
8
14
|
* @example
|
|
9
15
|
* ```ts
|
|
10
|
-
* app.use(
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
16
|
+
* app.use(tailwindDev({ '/assets/tailwind.css': { entry: './styles/input.css' } }))
|
|
17
|
+
* app.use(esbuildDev({ '/assets/client.js': { entry: './client.ts', ... } }))
|
|
18
|
+
* app.use(react({ layout: './components/PageShell.tsx' }))
|
|
19
|
+
* app.get('/', (_req, ctx) => ctx.render('./pages/HomePage.tsx', {
|
|
20
|
+
* stylesheets: ['/assets/tailwind.css'],
|
|
21
|
+
* bootstrapModules: ['/assets/client.js'],
|
|
14
22
|
* }))
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* React SSR middleware — injects `ctx.render(path, opts?)`.
|
|
27
|
+
*
|
|
28
|
+
* **Lightweight mode** (no `pages`): returns middleware for `app.use()`.
|
|
29
|
+
* Use with manual `app.get()` + `ctx.render()`.
|
|
15
30
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
31
|
+
* **Full mode** (has `pages`): returns a plugin for `app.plugin()`.
|
|
32
|
+
* Handles routing, data loading, Tailwind, client bundle, and error pages.
|
|
33
|
+
*/
|
|
34
|
+
export declare function react(opts?: ReactOptions): Middleware;
|
|
35
|
+
export declare function react(opts: ReactAppOptions): (app: Router) => void;
|
|
36
|
+
/**
|
|
37
|
+
* Auto-register routes from a shared route config.
|
|
38
|
+
*
|
|
39
|
+
* Use a single routes file shared between server and client to eliminate duplication.
|
|
40
|
+
* Routes with data dependencies use the `loaders` option — request ctx is passed
|
|
41
|
+
* to the loader, which can throw `HttpError` for non-200 status codes.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* // routes.ts — shared by server and client
|
|
46
|
+
* export const routes = {
|
|
47
|
+
* '/': () => import('./pages/Home.tsx'),
|
|
48
|
+
* '/users': () => import('./pages/Users.tsx'),
|
|
49
|
+
* '/users/:id': () => import('./pages/UserDetail.tsx'),
|
|
50
|
+
* }
|
|
51
|
+
*
|
|
52
|
+
* // server.ts
|
|
53
|
+
* import { reactRouter } from 'weifuwu/react'
|
|
54
|
+
* import { routes } from './routes.ts'
|
|
55
|
+
*
|
|
56
|
+
* reactRouter(app, routes, {
|
|
57
|
+
* layout: './layouts/Root.tsx',
|
|
58
|
+
* stylesheets: ['/assets/tailwind.css'],
|
|
59
|
+
* bootstrapModules: ['/assets/client.js'],
|
|
60
|
+
* loaders: {
|
|
61
|
+
* '/users': async (ctx) => ({ users: await db.listUsers() }),
|
|
62
|
+
* '/users/:id': async (ctx) => {
|
|
63
|
+
* const user = await db.findUser(ctx.params.id)
|
|
64
|
+
* if (!user) throw new HttpError('Not found', 404)
|
|
65
|
+
* return { user }
|
|
66
|
+
* },
|
|
67
|
+
* },
|
|
18
68
|
* })
|
|
69
|
+
*
|
|
70
|
+
* // client.ts — same routes config, no loaders
|
|
71
|
+
* import { createBrowserRouter } from 'weifuwu/react/client'
|
|
72
|
+
* import { routes } from './routes.ts'
|
|
73
|
+
*
|
|
74
|
+
* createBrowserRouter({ layout: Root, routes })
|
|
19
75
|
* ```
|
|
20
76
|
*/
|
|
21
|
-
export declare function
|
|
77
|
+
export declare function reactRouter(app: Router, routes: Record<string, () => Promise<{
|
|
78
|
+
default: ComponentType;
|
|
79
|
+
}>>, opts?: ReactRouterOptions): void;
|
|
80
|
+
/**
|
|
81
|
+
* Client-side navigation link. Renders as `<a>` on the server.
|
|
82
|
+
* On the client, intercepted by `createBrowserRouter` for SPA navigation.
|
|
83
|
+
*/
|
|
84
|
+
export declare function Link({ href, children, ...props }: {
|
|
85
|
+
href: string;
|
|
86
|
+
children: React.ReactNode;
|
|
87
|
+
[key: string]: unknown;
|
|
88
|
+
}): ReactElement;
|
|
89
|
+
export { ErrorBoundary } from './error-boundary.ts';
|
|
22
90
|
export { useServerData } from './hooks.ts';
|
|
23
91
|
export { ServerDataContext } from './context.ts';
|
|
24
|
-
export {
|
|
25
|
-
export type { LinkProps, FormProps, NavigationState } from './navigation.ts';
|
|
26
|
-
export { ErrorBoundary } from './error-boundary.ts';
|
|
27
|
-
export type { ErrorBoundaryProps } from './error-boundary.ts';
|
|
28
|
-
export type { ReactOptions, RenderOptions, ReactInjected } from './types.ts';
|
|
92
|
+
export type { ReactOptions, RenderOptions, ReactRouterOptions, ReactAppOptions } from './types.ts';
|