@alepha/react 0.14.1 → 0.14.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/dist/auth/index.browser.js +1488 -4
- package/dist/auth/index.browser.js.map +1 -1
- package/dist/auth/index.d.ts +2 -2
- package/dist/auth/index.js +1827 -4
- package/dist/auth/index.js.map +1 -1
- package/dist/core/index.d.ts +54 -937
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +132 -2010
- package/dist/core/index.js.map +1 -1
- package/dist/form/index.d.ts.map +1 -1
- package/dist/form/index.js +6 -1
- package/dist/form/index.js.map +1 -1
- package/dist/head/index.browser.js +3 -1
- package/dist/head/index.browser.js.map +1 -1
- package/dist/head/index.d.ts +552 -8
- package/dist/head/index.d.ts.map +1 -1
- package/dist/head/index.js +15 -1
- package/dist/head/index.js.map +1 -1
- package/dist/{core → router}/index.browser.js +126 -516
- package/dist/router/index.browser.js.map +1 -0
- package/dist/router/index.d.ts +1334 -0
- package/dist/router/index.d.ts.map +1 -0
- package/dist/router/index.js +1939 -0
- package/dist/router/index.js.map +1 -0
- package/package.json +12 -6
- package/src/auth/index.ts +1 -1
- package/src/auth/services/ReactAuth.ts +1 -1
- package/src/core/components/ClientOnly.tsx +14 -0
- package/src/core/components/ErrorBoundary.tsx +3 -2
- package/src/core/contexts/AlephaContext.ts +3 -0
- package/src/core/contexts/AlephaProvider.tsx +2 -1
- package/src/core/index.ts +13 -102
- package/src/form/services/FormModel.ts +5 -0
- package/src/head/index.ts +16 -7
- package/src/head/interfaces/Head.ts +3 -0
- package/src/head/providers/HeadProvider.ts +6 -1
- package/src/head/providers/ServerHeadProvider.ts +20 -0
- package/src/{core → router}/components/ErrorViewer.tsx +2 -0
- package/src/router/components/Link.tsx +21 -0
- package/src/{core → router}/components/NestedView.tsx +3 -5
- package/src/router/components/NotFound.tsx +30 -0
- package/src/router/errors/Redirection.ts +28 -0
- package/src/{core → router}/hooks/useActive.ts +6 -2
- package/src/{core → router}/hooks/useQueryParams.ts +2 -2
- package/src/{core → router}/hooks/useRouter.ts +1 -1
- package/src/{core → router}/hooks/useRouterState.ts +1 -1
- package/src/{core → router}/index.browser.ts +14 -12
- package/src/{core/index.shared-router.ts → router/index.shared.ts} +6 -3
- package/src/router/index.ts +125 -0
- package/src/{core → router}/primitives/$page.ts +1 -1
- package/src/{core → router}/providers/ReactBrowserProvider.ts +3 -13
- package/src/{core → router}/providers/ReactBrowserRendererProvider.ts +3 -0
- package/src/{core → router}/providers/ReactBrowserRouterProvider.ts +3 -0
- package/src/{core → router}/providers/ReactPageProvider.ts +5 -3
- package/src/{core → router}/providers/ReactServerProvider.ts +9 -28
- package/src/{core → router}/services/ReactPageServerService.ts +3 -0
- package/src/{core → router}/services/ReactPageService.ts +5 -5
- package/src/{core → router}/services/ReactRouter.ts +26 -5
- package/dist/core/index.browser.js.map +0 -1
- package/dist/core/index.native.js +0 -403
- package/dist/core/index.native.js.map +0 -1
- package/src/core/components/Link.tsx +0 -18
- package/src/core/components/NotFound.tsx +0 -27
- package/src/core/errors/Redirection.ts +0 -13
- package/src/core/hooks/useSchema.ts +0 -88
- package/src/core/index.native.ts +0 -21
- package/src/core/index.shared.ts +0 -9
- /package/src/{core → router}/contexts/RouterLayerContext.ts +0 -0
package/dist/core/index.d.ts
CHANGED
|
@@ -1,17 +1,10 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import { Alepha, Async, Atom, Hook, Hooks,
|
|
3
|
-
import { DateTimeProvider, DurationLike } from "alepha/datetime";
|
|
4
|
-
import * as alepha_server0 from "alepha/server";
|
|
5
|
-
import { RequestConfigSchema, ServerHandler, ServerProvider, ServerRequest, ServerRouterProvider, ServerTimingProvider } from "alepha/server";
|
|
6
|
-
import * as alepha_server_cache0 from "alepha/server/cache";
|
|
7
|
-
import { ServerRouteCache } from "alepha/server/cache";
|
|
8
|
-
import { ClientScope, HttpVirtualClient, LinkProvider, VirtualAction } from "alepha/server/links";
|
|
9
|
-
import * as alepha_logger1 from "alepha/logger";
|
|
1
|
+
import * as alepha0 from "alepha";
|
|
2
|
+
import { Alepha, Async, Atom, Hook, Hooks, Service, State, Static, TAtomObject } from "alepha";
|
|
10
3
|
import * as react0 from "react";
|
|
11
|
-
import React, {
|
|
4
|
+
import React, { DependencyList, ErrorInfo, PropsWithChildren, ReactNode } from "react";
|
|
12
5
|
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
6
|
+
import { DurationLike } from "alepha/datetime";
|
|
7
|
+
import { ClientScope, HttpVirtualClient } from "alepha/server/links";
|
|
15
8
|
|
|
16
9
|
//#region ../../src/core/components/ClientOnly.d.ts
|
|
17
10
|
interface ClientOnlyProps {
|
|
@@ -27,590 +20,62 @@ interface ClientOnlyProps {
|
|
|
27
20
|
* - you have code that relies on browser-specific APIs
|
|
28
21
|
* - you want to avoid server-side rendering for a specific part of your application
|
|
29
22
|
* - you want to prevent pre-rendering of a component
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```tsx
|
|
26
|
+
* import { ClientOnly } from "@alepha/react";
|
|
27
|
+
*
|
|
28
|
+
* const MyComponent = () => {
|
|
29
|
+
* // Avoids SSR issues with Date API
|
|
30
|
+
* return (
|
|
31
|
+
* <ClientOnly>
|
|
32
|
+
* {new Date().toLocaleTimeString()}
|
|
33
|
+
* </ClientOnly>
|
|
34
|
+
* );
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
30
37
|
*/
|
|
31
38
|
declare const ClientOnly: (props: PropsWithChildren<ClientOnlyProps>) => ReactNode;
|
|
32
39
|
//#endregion
|
|
33
|
-
//#region ../../src/core/
|
|
40
|
+
//#region ../../src/core/components/ErrorBoundary.d.ts
|
|
34
41
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* Depends on the context, it can be thrown or just returned.
|
|
42
|
+
* Props for the ErrorBoundary component.
|
|
38
43
|
*/
|
|
39
|
-
|
|
40
|
-
readonly redirect: string;
|
|
41
|
-
constructor(redirect: string);
|
|
42
|
-
}
|
|
43
|
-
//#endregion
|
|
44
|
-
//#region ../../src/core/providers/ReactPageProvider.d.ts
|
|
45
|
-
declare const envSchema$2: alepha19.TObject<{
|
|
46
|
-
REACT_STRICT_MODE: alepha19.TBoolean;
|
|
47
|
-
}>;
|
|
48
|
-
declare module "alepha" {
|
|
49
|
-
interface Env extends Partial<Static<typeof envSchema$2>> {}
|
|
50
|
-
}
|
|
51
|
-
declare class ReactPageProvider {
|
|
52
|
-
protected readonly log: alepha_logger1.Logger;
|
|
53
|
-
protected readonly env: {
|
|
54
|
-
REACT_STRICT_MODE: boolean;
|
|
55
|
-
};
|
|
56
|
-
protected readonly alepha: Alepha;
|
|
57
|
-
protected readonly pages: PageRoute[];
|
|
58
|
-
getPages(): PageRoute[];
|
|
59
|
-
getConcretePages(): ConcretePageRoute[];
|
|
60
|
-
page(name: string): PageRoute;
|
|
61
|
-
pathname(name: string, options?: {
|
|
62
|
-
params?: Record<string, string>;
|
|
63
|
-
query?: Record<string, string>;
|
|
64
|
-
}): string;
|
|
65
|
-
url(name: string, options?: {
|
|
66
|
-
params?: Record<string, string>;
|
|
67
|
-
host?: string;
|
|
68
|
-
}): URL;
|
|
69
|
-
root(state: ReactRouterState): ReactNode;
|
|
70
|
-
protected convertStringObjectToObject: (schema?: TSchema, value?: any) => any;
|
|
71
|
-
/**
|
|
72
|
-
* Create a new RouterState based on a given route and request.
|
|
73
|
-
* This method resolves the layers for the route, applying any query and params schemas defined in the route.
|
|
74
|
-
* It also handles errors and redirects.
|
|
75
|
-
*/
|
|
76
|
-
createLayers(route: PageRoute, state: ReactRouterState, previous?: PreviousLayerData[]): Promise<CreateLayersResult>;
|
|
77
|
-
protected getErrorHandler(route: PageRoute): ErrorHandler | undefined;
|
|
78
|
-
protected createElement(page: PageRoute, props: Record<string, any>): Promise<ReactNode>;
|
|
79
|
-
renderError(error: Error): ReactNode;
|
|
80
|
-
renderEmptyView(): ReactNode;
|
|
81
|
-
href(page: {
|
|
82
|
-
options: {
|
|
83
|
-
name?: string;
|
|
84
|
-
};
|
|
85
|
-
}, params?: Record<string, any>): string;
|
|
86
|
-
compile(path: string, params?: Record<string, string>): string;
|
|
87
|
-
protected renderView(index: number, path: string, view: ReactNode | undefined, page: PageRoute): ReactNode;
|
|
88
|
-
protected readonly configure: alepha19.HookPrimitive<"configure">;
|
|
89
|
-
protected map(pages: Array<PagePrimitive>, target: PagePrimitive): PageRouteEntry;
|
|
90
|
-
add(entry: PageRouteEntry): void;
|
|
91
|
-
protected createMatch(page: PageRoute): string;
|
|
92
|
-
protected _next: number;
|
|
93
|
-
protected nextId(): string;
|
|
94
|
-
}
|
|
95
|
-
declare const isPageRoute: (it: any) => it is PageRoute;
|
|
96
|
-
interface PageRouteEntry extends Omit<PagePrimitiveOptions, "children" | "parent"> {
|
|
97
|
-
children?: PageRouteEntry[];
|
|
98
|
-
}
|
|
99
|
-
interface ConcretePageRoute extends PageRoute {
|
|
100
|
-
/**
|
|
101
|
-
* When exported, static routes can be split into multiple pages with different params.
|
|
102
|
-
* We replace 'name' by the new name for each static entry, and old 'name' becomes 'staticName'.
|
|
103
|
-
*/
|
|
104
|
-
staticName?: string;
|
|
105
|
-
params?: Record<string, string>;
|
|
106
|
-
}
|
|
107
|
-
interface PageRoute extends PageRouteEntry {
|
|
108
|
-
type: "page";
|
|
109
|
-
name: string;
|
|
110
|
-
parent?: PageRoute;
|
|
111
|
-
match: string;
|
|
112
|
-
}
|
|
113
|
-
interface Layer {
|
|
114
|
-
config?: {
|
|
115
|
-
query?: Record<string, any>;
|
|
116
|
-
params?: Record<string, any>;
|
|
117
|
-
context?: Record<string, any>;
|
|
118
|
-
};
|
|
119
|
-
name: string;
|
|
120
|
-
props?: Record<string, any>;
|
|
121
|
-
error?: Error;
|
|
122
|
-
part?: string;
|
|
123
|
-
element: ReactNode;
|
|
124
|
-
index: number;
|
|
125
|
-
path: string;
|
|
126
|
-
route?: PageRoute;
|
|
127
|
-
cache?: boolean;
|
|
128
|
-
}
|
|
129
|
-
type PreviousLayerData = Omit<Layer, "element" | "index" | "path">;
|
|
130
|
-
interface AnchorProps {
|
|
131
|
-
href: string;
|
|
132
|
-
onClick: (ev?: any) => any;
|
|
133
|
-
}
|
|
134
|
-
interface ReactRouterState {
|
|
135
|
-
/**
|
|
136
|
-
* Stack of layers for the current page.
|
|
137
|
-
*/
|
|
138
|
-
layers: Array<Layer>;
|
|
139
|
-
/**
|
|
140
|
-
* URL of the current page.
|
|
141
|
-
*/
|
|
142
|
-
url: URL;
|
|
143
|
-
/**
|
|
144
|
-
* Error handler for the current page.
|
|
145
|
-
*/
|
|
146
|
-
onError: ErrorHandler;
|
|
147
|
-
/**
|
|
148
|
-
* Params extracted from the URL for the current page.
|
|
149
|
-
*/
|
|
150
|
-
params: Record<string, any>;
|
|
44
|
+
interface ErrorBoundaryProps {
|
|
151
45
|
/**
|
|
152
|
-
*
|
|
46
|
+
* Fallback React node to render when an error is caught.
|
|
47
|
+
* If not provided, a default error message will be shown.
|
|
153
48
|
*/
|
|
154
|
-
|
|
49
|
+
fallback: (error: Error) => ReactNode;
|
|
155
50
|
/**
|
|
156
|
-
* Optional
|
|
51
|
+
* Optional callback that receives the error and error info.
|
|
52
|
+
* Use this to log errors to a monitoring service.
|
|
157
53
|
*/
|
|
158
|
-
|
|
159
|
-
name?: string;
|
|
160
|
-
}
|
|
161
|
-
interface RouterStackItem {
|
|
162
|
-
route: PageRoute;
|
|
163
|
-
config?: Record<string, any>;
|
|
164
|
-
props?: Record<string, any>;
|
|
165
|
-
error?: Error;
|
|
166
|
-
cache?: boolean;
|
|
167
|
-
}
|
|
168
|
-
interface TransitionOptions {
|
|
169
|
-
previous?: PreviousLayerData[];
|
|
170
|
-
}
|
|
171
|
-
interface CreateLayersResult {
|
|
172
|
-
redirect?: string;
|
|
173
|
-
state?: ReactRouterState;
|
|
174
|
-
}
|
|
175
|
-
//#endregion
|
|
176
|
-
//#region ../../src/core/services/ReactPageService.d.ts
|
|
177
|
-
declare class ReactPageService {
|
|
178
|
-
fetch(pathname: string, options?: PagePrimitiveRenderOptions): Promise<{
|
|
179
|
-
html: string;
|
|
180
|
-
response: Response;
|
|
181
|
-
}>;
|
|
182
|
-
render(name: string, options?: PagePrimitiveRenderOptions): Promise<PagePrimitiveRenderResult>;
|
|
54
|
+
onError?: (error: Error, info: ErrorInfo) => void;
|
|
183
55
|
}
|
|
184
|
-
//#endregion
|
|
185
|
-
//#region ../../src/core/primitives/$page.d.ts
|
|
186
56
|
/**
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
* The $page primitive is the core building block for creating type-safe, SSR-enabled React routes.
|
|
190
|
-
* It provides a declarative way to define pages with powerful features:
|
|
191
|
-
*
|
|
192
|
-
* **Routing & Navigation**
|
|
193
|
-
* - URL pattern matching with parameters (e.g., `/users/:id`)
|
|
194
|
-
* - Nested routing with parent-child relationships
|
|
195
|
-
* - Type-safe URL parameter and query string validation
|
|
196
|
-
*
|
|
197
|
-
* **Data Loading**
|
|
198
|
-
* - Server-side data fetching with the `resolve` function
|
|
199
|
-
* - Automatic serialization and hydration for SSR
|
|
200
|
-
* - Access to request context, URL params, and parent data
|
|
201
|
-
*
|
|
202
|
-
* **Component Loading**
|
|
203
|
-
* - Direct component rendering or lazy loading for code splitting
|
|
204
|
-
* - Client-only rendering when browser APIs are needed
|
|
205
|
-
* - Automatic fallback handling during hydration
|
|
206
|
-
*
|
|
207
|
-
* **Performance Optimization**
|
|
208
|
-
* - Static generation for pre-rendered pages at build time
|
|
209
|
-
* - Server-side caching with configurable TTL and providers
|
|
210
|
-
* - Code splitting through lazy component loading
|
|
211
|
-
*
|
|
212
|
-
* **Error Handling**
|
|
213
|
-
* - Custom error handlers with support for redirects
|
|
214
|
-
* - Hierarchical error handling (child → parent)
|
|
215
|
-
* - HTTP status code handling (404, 401, etc.)
|
|
216
|
-
*
|
|
217
|
-
* **Page Animations**
|
|
218
|
-
* - CSS-based enter/exit animations
|
|
219
|
-
* - Dynamic animations based on page state
|
|
220
|
-
* - Custom timing and easing functions
|
|
221
|
-
*
|
|
222
|
-
* **Lifecycle Management**
|
|
223
|
-
* - Server response hooks for headers and status codes
|
|
224
|
-
* - Page leave handlers for cleanup (browser only)
|
|
225
|
-
* - Permission-based access control
|
|
226
|
-
*
|
|
227
|
-
* @example Simple page with data fetching
|
|
228
|
-
* ```typescript
|
|
229
|
-
* const userProfile = $page({
|
|
230
|
-
* path: "/users/:id",
|
|
231
|
-
* schema: {
|
|
232
|
-
* params: t.object({ id: t.integer() }),
|
|
233
|
-
* query: t.object({ tab: t.optional(t.text()) })
|
|
234
|
-
* },
|
|
235
|
-
* resolve: async ({ params }) => {
|
|
236
|
-
* const user = await userApi.getUser(params.id);
|
|
237
|
-
* return { user };
|
|
238
|
-
* },
|
|
239
|
-
* lazy: () => import("./UserProfile.tsx")
|
|
240
|
-
* });
|
|
241
|
-
* ```
|
|
242
|
-
*
|
|
243
|
-
* @example Nested routing with error handling
|
|
244
|
-
* ```typescript
|
|
245
|
-
* const projectSection = $page({
|
|
246
|
-
* path: "/projects/:id",
|
|
247
|
-
* children: () => [projectBoard, projectSettings],
|
|
248
|
-
* resolve: async ({ params }) => {
|
|
249
|
-
* const project = await projectApi.get(params.id);
|
|
250
|
-
* return { project };
|
|
251
|
-
* },
|
|
252
|
-
* errorHandler: (error) => {
|
|
253
|
-
* if (HttpError.is(error, 404)) {
|
|
254
|
-
* return <ProjectNotFound />;
|
|
255
|
-
* }
|
|
256
|
-
* }
|
|
257
|
-
* });
|
|
258
|
-
* ```
|
|
259
|
-
*
|
|
260
|
-
* @example Static generation with caching
|
|
261
|
-
* ```typescript
|
|
262
|
-
* const blogPost = $page({
|
|
263
|
-
* path: "/blog/:slug",
|
|
264
|
-
* static: {
|
|
265
|
-
* entries: posts.map(p => ({ params: { slug: p.slug } }))
|
|
266
|
-
* },
|
|
267
|
-
* resolve: async ({ params }) => {
|
|
268
|
-
* const post = await loadPost(params.slug);
|
|
269
|
-
* return { post };
|
|
270
|
-
* }
|
|
271
|
-
* });
|
|
272
|
-
* ```
|
|
57
|
+
* State of the ErrorBoundary component.
|
|
273
58
|
*/
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
[KIND]: typeof PagePrimitive;
|
|
277
|
-
};
|
|
278
|
-
interface PagePrimitiveOptions<TConfig extends PageConfigSchema = PageConfigSchema, TProps extends object = TPropsDefault, TPropsParent extends object = TPropsParentDefault> {
|
|
279
|
-
/**
|
|
280
|
-
* Identifier name for the page. Must be unique.
|
|
281
|
-
*
|
|
282
|
-
* @default Primitive key
|
|
283
|
-
*/
|
|
284
|
-
name?: string;
|
|
285
|
-
/**
|
|
286
|
-
* Add a pathname to the page.
|
|
287
|
-
*
|
|
288
|
-
* Pathname can contain parameters, like `/post/:slug`.
|
|
289
|
-
*
|
|
290
|
-
* @default ""
|
|
291
|
-
*/
|
|
292
|
-
path?: string;
|
|
293
|
-
/**
|
|
294
|
-
* Add an input schema to define:
|
|
295
|
-
* - `params`: parameters from the pathname.
|
|
296
|
-
* - `query`: query parameters from the URL.
|
|
297
|
-
*/
|
|
298
|
-
schema?: TConfig;
|
|
299
|
-
/**
|
|
300
|
-
* Load data before rendering the page.
|
|
301
|
-
*
|
|
302
|
-
* This function receives
|
|
303
|
-
* - the request context (params, query, etc.)
|
|
304
|
-
* - the parent props (if page has a parent)
|
|
305
|
-
*
|
|
306
|
-
* > In SSR, the returned data will be serialized and sent to the client, then reused during the client-side hydration.
|
|
307
|
-
*
|
|
308
|
-
* Resolve can be stopped by throwing an error, which will be handled by the `errorHandler` function.
|
|
309
|
-
* It's common to throw a `NotFoundError` to display a 404 page.
|
|
310
|
-
*
|
|
311
|
-
* RedirectError can be thrown to redirect the user to another page.
|
|
312
|
-
*/
|
|
313
|
-
resolve?: (context: PageResolve<TConfig, TPropsParent>) => Async<TProps>;
|
|
314
|
-
/**
|
|
315
|
-
* Default props to pass to the component when rendering the page.
|
|
316
|
-
*
|
|
317
|
-
* Resolved props from the `resolve` function will override these default props.
|
|
318
|
-
*/
|
|
319
|
-
props?: () => Partial<TProps>;
|
|
320
|
-
/**
|
|
321
|
-
* The component to render when the page is loaded.
|
|
322
|
-
*
|
|
323
|
-
* If `lazy` is defined, this will be ignored.
|
|
324
|
-
* Prefer using `lazy` to improve the initial loading time.
|
|
325
|
-
*/
|
|
326
|
-
component?: FC<TProps & TPropsParent>;
|
|
327
|
-
/**
|
|
328
|
-
* Lazy load the component when the page is loaded.
|
|
329
|
-
*
|
|
330
|
-
* It's recommended to use this for components to improve the initial loading time
|
|
331
|
-
* and enable code-splitting.
|
|
332
|
-
*/
|
|
333
|
-
lazy?: () => Promise<{
|
|
334
|
-
default: FC<TProps & TPropsParent>;
|
|
335
|
-
}>;
|
|
336
|
-
/**
|
|
337
|
-
* Attach child pages to create nested routes.
|
|
338
|
-
* This will make the page a parent route.
|
|
339
|
-
*/
|
|
340
|
-
children?: Array<PagePrimitive> | (() => Array<PagePrimitive>);
|
|
341
|
-
/**
|
|
342
|
-
* Define a parent page for nested routing.
|
|
343
|
-
*/
|
|
344
|
-
parent?: PagePrimitive<PageConfigSchema, TPropsParent, any>;
|
|
345
|
-
/**
|
|
346
|
-
* Function to determine if the page can be accessed.
|
|
347
|
-
*
|
|
348
|
-
* If it returns false, the page will not be accessible and a 403 Forbidden error will be returned.
|
|
349
|
-
* This function can be used to implement permission-based access control.
|
|
350
|
-
*/
|
|
351
|
-
can?: () => boolean;
|
|
352
|
-
/**
|
|
353
|
-
* Catch any error from the `resolve` function or during `rendering`.
|
|
354
|
-
*
|
|
355
|
-
* Expected to return one of the following:
|
|
356
|
-
* - a ReactNode to render an error page
|
|
357
|
-
* - a Redirection to redirect the user
|
|
358
|
-
* - undefined to let the error propagate
|
|
359
|
-
*
|
|
360
|
-
* If not defined, the error will be thrown and handled by the server or client error handler.
|
|
361
|
-
* If a leaf $page does not define an error handler, the error can be caught by parent pages.
|
|
362
|
-
*
|
|
363
|
-
* @example Catch a 404 from API and render a custom not found component:
|
|
364
|
-
* ```ts
|
|
365
|
-
* resolve: async ({ params, query }) => {
|
|
366
|
-
* api.fetch("/api/resource", { params, query });
|
|
367
|
-
* },
|
|
368
|
-
* errorHandler: (error, context) => {
|
|
369
|
-
* if (HttpError.is(error, 404)) {
|
|
370
|
-
* return <ResourceNotFound />;
|
|
371
|
-
* }
|
|
372
|
-
* }
|
|
373
|
-
* ```
|
|
374
|
-
*
|
|
375
|
-
* @example Catch an 401 error and redirect the user to the login page:
|
|
376
|
-
* ```ts
|
|
377
|
-
* resolve: async ({ params, query }) => {
|
|
378
|
-
* // but the user is not authenticated
|
|
379
|
-
* api.fetch("/api/resource", { params, query });
|
|
380
|
-
* },
|
|
381
|
-
* errorHandler: (error, context) => {
|
|
382
|
-
* if (HttpError.is(error, 401)) {
|
|
383
|
-
* // throwing a Redirection is also valid!
|
|
384
|
-
* return new Redirection("/login");
|
|
385
|
-
* }
|
|
386
|
-
* }
|
|
387
|
-
* ```
|
|
388
|
-
*/
|
|
389
|
-
errorHandler?: ErrorHandler;
|
|
390
|
-
/**
|
|
391
|
-
* If true, the page will be considered as a static page, immutable and cacheable.
|
|
392
|
-
* Replace boolean by an object to define static entries. (e.g. list of params/query)
|
|
393
|
-
*
|
|
394
|
-
* Browser-side: it only works with `alepha/vite`, which can pre-render the page at build time.
|
|
395
|
-
*
|
|
396
|
-
* Server-side: It will act as timeless cached page. You can use `cache` to configure the cache behavior.
|
|
397
|
-
*/
|
|
398
|
-
static?: boolean | {
|
|
399
|
-
entries?: Array<Partial<PageRequestConfig<TConfig>>>;
|
|
400
|
-
};
|
|
401
|
-
cache?: ServerRouteCache;
|
|
402
|
-
/**
|
|
403
|
-
* If true, force the page to be rendered only on the client-side (browser).
|
|
404
|
-
* It uses the `<ClientOnly/>` component to render the page.
|
|
405
|
-
*/
|
|
406
|
-
client?: boolean | ClientOnlyProps;
|
|
407
|
-
/**
|
|
408
|
-
* Called before the server response is sent to the client. (server only)
|
|
409
|
-
*/
|
|
410
|
-
onServerResponse?: (request: ServerRequest) => unknown;
|
|
411
|
-
/**
|
|
412
|
-
* Called when user leaves the page. (browser only)
|
|
413
|
-
*/
|
|
414
|
-
onLeave?: () => void;
|
|
415
|
-
/**
|
|
416
|
-
* @experimental
|
|
417
|
-
*
|
|
418
|
-
* Add a css animation when the page is loaded or unloaded.
|
|
419
|
-
* It uses CSS animations, so you need to define the keyframes in your CSS.
|
|
420
|
-
*
|
|
421
|
-
* @example Simple animation name
|
|
422
|
-
* ```ts
|
|
423
|
-
* animation: "fadeIn"
|
|
424
|
-
* ```
|
|
425
|
-
*
|
|
426
|
-
* CSS example:
|
|
427
|
-
* ```css
|
|
428
|
-
* @keyframes fadeIn {
|
|
429
|
-
* from { opacity: 0; }
|
|
430
|
-
* to { opacity: 1; }
|
|
431
|
-
* }
|
|
432
|
-
* ```
|
|
433
|
-
*
|
|
434
|
-
* @example Detailed animation
|
|
435
|
-
* ```ts
|
|
436
|
-
* animation: {
|
|
437
|
-
* enter: { name: "fadeIn", duration: 300 },
|
|
438
|
-
* exit: { name: "fadeOut", duration: 200, timing: "ease-in-out" },
|
|
439
|
-
* }
|
|
440
|
-
* ```
|
|
441
|
-
*
|
|
442
|
-
* @example Only exit animation
|
|
443
|
-
* ```ts
|
|
444
|
-
* animation: {
|
|
445
|
-
* exit: "fadeOut"
|
|
446
|
-
* }
|
|
447
|
-
* ```
|
|
448
|
-
*
|
|
449
|
-
* @example With custom timing function
|
|
450
|
-
* ```ts
|
|
451
|
-
* animation: {
|
|
452
|
-
* enter: { name: "fadeIn", duration: 300, timing: "cubic-bezier(0.4, 0, 0.2, 1)" },
|
|
453
|
-
* exit: { name: "fadeOut", duration: 200, timing: "ease-in-out" },
|
|
454
|
-
* }
|
|
455
|
-
* ```
|
|
456
|
-
*/
|
|
457
|
-
animation?: PageAnimation;
|
|
458
|
-
}
|
|
459
|
-
type ErrorHandler = (error: Error, state: ReactRouterState) => ReactNode | Redirection | undefined;
|
|
460
|
-
declare class PagePrimitive<TConfig extends PageConfigSchema = PageConfigSchema, TProps extends object = TPropsDefault, TPropsParent extends object = TPropsParentDefault> extends Primitive<PagePrimitiveOptions<TConfig, TProps, TPropsParent>> {
|
|
461
|
-
protected readonly reactPageService: ReactPageService;
|
|
462
|
-
protected onInit(): void;
|
|
463
|
-
get name(): string;
|
|
464
|
-
/**
|
|
465
|
-
* For testing or build purposes.
|
|
466
|
-
*
|
|
467
|
-
* This will render the page (HTML layout included or not) and return the HTML + context.
|
|
468
|
-
* Only valid for server-side rendering, it will throw an error if called on the client-side.
|
|
469
|
-
*/
|
|
470
|
-
render(options?: PagePrimitiveRenderOptions): Promise<PagePrimitiveRenderResult>;
|
|
471
|
-
fetch(options?: PagePrimitiveRenderOptions): Promise<{
|
|
472
|
-
html: string;
|
|
473
|
-
response: Response;
|
|
474
|
-
}>;
|
|
475
|
-
match(url: string): boolean;
|
|
476
|
-
pathname(config: any): string;
|
|
477
|
-
}
|
|
478
|
-
interface PageConfigSchema {
|
|
479
|
-
query?: TSchema;
|
|
480
|
-
params?: TSchema;
|
|
481
|
-
}
|
|
482
|
-
type TPropsDefault = any;
|
|
483
|
-
type TPropsParentDefault = {};
|
|
484
|
-
interface PagePrimitiveRenderOptions {
|
|
485
|
-
params?: Record<string, string>;
|
|
486
|
-
query?: Record<string, string>;
|
|
487
|
-
/**
|
|
488
|
-
* If true, the HTML layout will be included in the response.
|
|
489
|
-
* If false, only the page content will be returned.
|
|
490
|
-
*
|
|
491
|
-
* @default true
|
|
492
|
-
*/
|
|
493
|
-
html?: boolean;
|
|
494
|
-
hydration?: boolean;
|
|
495
|
-
}
|
|
496
|
-
interface PagePrimitiveRenderResult {
|
|
497
|
-
html: string;
|
|
498
|
-
state: ReactRouterState;
|
|
499
|
-
redirect?: string;
|
|
500
|
-
}
|
|
501
|
-
interface PageRequestConfig<TConfig extends PageConfigSchema = PageConfigSchema> {
|
|
502
|
-
params: TConfig["params"] extends TSchema ? Static<TConfig["params"]> : Record<string, string>;
|
|
503
|
-
query: TConfig["query"] extends TSchema ? Static<TConfig["query"]> : Record<string, string>;
|
|
504
|
-
}
|
|
505
|
-
type PageResolve<TConfig extends PageConfigSchema = PageConfigSchema, TPropsParent extends object = TPropsParentDefault> = PageRequestConfig<TConfig> & TPropsParent & Omit<ReactRouterState, "layers" | "onError">;
|
|
506
|
-
type PageAnimation = PageAnimationObject | ((state: ReactRouterState) => PageAnimationObject | undefined);
|
|
507
|
-
type PageAnimationObject = CssAnimationName | {
|
|
508
|
-
enter?: CssAnimation | CssAnimationName;
|
|
509
|
-
exit?: CssAnimation | CssAnimationName;
|
|
510
|
-
};
|
|
511
|
-
type CssAnimationName = string;
|
|
512
|
-
type CssAnimation = {
|
|
513
|
-
name: string;
|
|
514
|
-
duration?: number;
|
|
515
|
-
timing?: string;
|
|
516
|
-
};
|
|
517
|
-
//#endregion
|
|
518
|
-
//#region ../../src/core/providers/ReactBrowserRouterProvider.d.ts
|
|
519
|
-
interface BrowserRoute extends Route {
|
|
520
|
-
page: PageRoute;
|
|
521
|
-
}
|
|
522
|
-
declare class ReactBrowserRouterProvider extends RouterProvider<BrowserRoute> {
|
|
523
|
-
protected readonly log: alepha_logger1.Logger;
|
|
524
|
-
protected readonly alepha: Alepha;
|
|
525
|
-
protected readonly pageApi: ReactPageProvider;
|
|
526
|
-
add(entry: PageRouteEntry): void;
|
|
527
|
-
protected readonly configure: alepha19.HookPrimitive<"configure">;
|
|
528
|
-
transition(url: URL, previous?: PreviousLayerData[], meta?: {}): Promise<string | void>;
|
|
529
|
-
root(state: ReactRouterState): ReactNode;
|
|
530
|
-
}
|
|
531
|
-
//#endregion
|
|
532
|
-
//#region ../../src/core/providers/ReactBrowserProvider.d.ts
|
|
533
|
-
declare const envSchema$1: alepha19.TObject<{
|
|
534
|
-
REACT_ROOT_ID: alepha19.TString;
|
|
535
|
-
}>;
|
|
536
|
-
declare module "alepha" {
|
|
537
|
-
interface Env extends Partial<Static<typeof envSchema$1>> {}
|
|
59
|
+
interface ErrorBoundaryState {
|
|
60
|
+
error?: Error;
|
|
538
61
|
}
|
|
539
62
|
/**
|
|
540
|
-
*
|
|
63
|
+
* A reusable error boundary for catching rendering errors in any part of the React component tree.
|
|
64
|
+
*
|
|
65
|
+
* It's already included in the Alepha React framework when using page or layout components.
|
|
541
66
|
*/
|
|
542
|
-
declare
|
|
543
|
-
|
|
544
|
-
}>, "alepha.react.browser.options">;
|
|
545
|
-
type ReactBrowserRendererOptions = Static<typeof reactBrowserOptions.schema>;
|
|
546
|
-
declare module "alepha" {
|
|
547
|
-
interface State {
|
|
548
|
-
[reactBrowserOptions.key]: ReactBrowserRendererOptions;
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
declare class ReactBrowserProvider {
|
|
552
|
-
protected readonly env: {
|
|
553
|
-
REACT_ROOT_ID: string;
|
|
554
|
-
};
|
|
555
|
-
protected readonly log: alepha_logger1.Logger;
|
|
556
|
-
protected readonly client: LinkProvider;
|
|
557
|
-
protected readonly alepha: Alepha;
|
|
558
|
-
protected readonly router: ReactBrowserRouterProvider;
|
|
559
|
-
protected readonly dateTimeProvider: DateTimeProvider;
|
|
560
|
-
protected readonly options: Readonly<{
|
|
561
|
-
scrollRestoration: "top" | "manual";
|
|
562
|
-
}>;
|
|
563
|
-
protected getRootElement(): HTMLElement;
|
|
564
|
-
transitioning?: {
|
|
565
|
-
to: string;
|
|
566
|
-
from?: string;
|
|
567
|
-
};
|
|
568
|
-
get state(): ReactRouterState;
|
|
569
|
-
/**
|
|
570
|
-
* Accessor for Document DOM API.
|
|
571
|
-
*/
|
|
572
|
-
get document(): Document;
|
|
573
|
-
/**
|
|
574
|
-
* Accessor for History DOM API.
|
|
575
|
-
*/
|
|
576
|
-
get history(): History;
|
|
577
|
-
/**
|
|
578
|
-
* Accessor for Location DOM API.
|
|
579
|
-
*/
|
|
580
|
-
get location(): Location;
|
|
581
|
-
get base(): string;
|
|
582
|
-
get url(): string;
|
|
583
|
-
pushState(path: string, replace?: boolean): void;
|
|
584
|
-
invalidate(props?: Record<string, any>): Promise<void>;
|
|
585
|
-
go(url: string, options?: RouterGoOptions): Promise<void>;
|
|
586
|
-
protected render(options?: RouterRenderOptions): Promise<void>;
|
|
67
|
+
declare class ErrorBoundary extends React.Component<PropsWithChildren<ErrorBoundaryProps>, ErrorBoundaryState> {
|
|
68
|
+
constructor(props: ErrorBoundaryProps);
|
|
587
69
|
/**
|
|
588
|
-
*
|
|
70
|
+
* Update state so the next render shows the fallback UI.
|
|
589
71
|
*/
|
|
590
|
-
|
|
591
|
-
protected readonly onTransitionEnd: alepha19.HookPrimitive<"react:transition:end">;
|
|
592
|
-
readonly ready: alepha19.HookPrimitive<"ready">;
|
|
593
|
-
}
|
|
594
|
-
interface RouterGoOptions {
|
|
595
|
-
replace?: boolean;
|
|
596
|
-
match?: TransitionOptions;
|
|
597
|
-
params?: Record<string, string>;
|
|
598
|
-
query?: Record<string, string>;
|
|
599
|
-
meta?: Record<string, any>;
|
|
72
|
+
static getDerivedStateFromError(error: Error): ErrorBoundaryState;
|
|
600
73
|
/**
|
|
601
|
-
*
|
|
74
|
+
* Lifecycle method called when an error is caught.
|
|
75
|
+
* You can log the error or perform side effects here.
|
|
602
76
|
*/
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
type ReactHydrationState = {
|
|
606
|
-
layers?: Array<PreviousLayerData>;
|
|
607
|
-
} & {
|
|
608
|
-
[key: string]: any;
|
|
609
|
-
};
|
|
610
|
-
interface RouterRenderOptions {
|
|
611
|
-
url?: string;
|
|
612
|
-
previous?: PreviousLayerData[];
|
|
613
|
-
meta?: Record<string, any>;
|
|
77
|
+
componentDidCatch(error: Error, info: ErrorInfo): void;
|
|
78
|
+
render(): ReactNode;
|
|
614
79
|
}
|
|
615
80
|
//#endregion
|
|
616
81
|
//#region ../../src/core/contexts/AlephaProvider.d.ts
|
|
@@ -621,11 +86,15 @@ interface AlephaProviderProps {
|
|
|
621
86
|
}
|
|
622
87
|
/**
|
|
623
88
|
* AlephaProvider component to initialize and provide Alepha instance to the app.
|
|
624
|
-
*
|
|
89
|
+
*
|
|
90
|
+
* This isn't recommended for apps using `@alepha/react/router`, as Router will handle this for you.
|
|
625
91
|
*/
|
|
626
92
|
declare const AlephaProvider: (props: AlephaProviderProps) => string | number | bigint | boolean | Iterable<ReactNode> | Promise<string | number | bigint | boolean | react0.ReactPortal | react0.ReactElement<unknown, string | react0.JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | react_jsx_runtime0.JSX.Element | null | undefined;
|
|
627
93
|
//#endregion
|
|
628
94
|
//#region ../../src/core/contexts/AlephaContext.d.ts
|
|
95
|
+
/**
|
|
96
|
+
* React context to provide the Alepha instance throughout the component tree.
|
|
97
|
+
*/
|
|
629
98
|
declare const AlephaContext: react0.Context<Alepha | undefined>;
|
|
630
99
|
//#endregion
|
|
631
100
|
//#region ../../src/core/hooks/useAction.d.ts
|
|
@@ -874,14 +343,6 @@ interface UseActionReturn<Args extends any[], Result> {
|
|
|
874
343
|
*/
|
|
875
344
|
declare const useAlepha: () => Alepha;
|
|
876
345
|
//#endregion
|
|
877
|
-
//#region ../../src/core/hooks/useClient.d.ts
|
|
878
|
-
/**
|
|
879
|
-
* Hook to get a virtual client for the specified scope.
|
|
880
|
-
*
|
|
881
|
-
* It's the React-hook version of `$client()`, from `AlephaServerLinks` module.
|
|
882
|
-
*/
|
|
883
|
-
declare const useClient: <T$1 extends object>(scope?: ClientScope) => HttpVirtualClient<T$1>;
|
|
884
|
-
//#endregion
|
|
885
346
|
//#region ../../src/core/hooks/useEvents.d.ts
|
|
886
347
|
/**
|
|
887
348
|
* Allow subscribing to multiple Alepha events. See {@link Hooks} for available events.
|
|
@@ -916,17 +377,13 @@ type UseEvents = { [T in keyof Hooks]?: Hook<T> | ((payload: Hooks[T]) => Async<
|
|
|
916
377
|
*/
|
|
917
378
|
declare const useInject: <T$1 extends object>(service: Service<T$1>) => T$1;
|
|
918
379
|
//#endregion
|
|
919
|
-
//#region ../../src/core/hooks/
|
|
920
|
-
declare const useSchema: <TConfig extends RequestConfigSchema>(action: VirtualAction<TConfig>) => UseSchemaReturn<TConfig>;
|
|
921
|
-
type UseSchemaReturn<TConfig extends RequestConfigSchema> = TConfig & {
|
|
922
|
-
loading: boolean;
|
|
923
|
-
};
|
|
380
|
+
//#region ../../src/core/hooks/useClient.d.ts
|
|
924
381
|
/**
|
|
925
|
-
*
|
|
382
|
+
* Hook to get a virtual client for the specified scope.
|
|
383
|
+
*
|
|
384
|
+
* It's the React-hook version of `$client()`, from `AlephaServerLinks` module.
|
|
926
385
|
*/
|
|
927
|
-
declare const
|
|
928
|
-
loading: boolean;
|
|
929
|
-
};
|
|
386
|
+
declare const useClient: <T$1 extends object>(scope?: ClientScope) => HttpVirtualClient<T$1>;
|
|
930
387
|
//#endregion
|
|
931
388
|
//#region ../../src/core/hooks/useStore.d.ts
|
|
932
389
|
/**
|
|
@@ -936,322 +393,9 @@ declare function useStore<T$1 extends TAtomObject>(target: Atom<T$1>, defaultVal
|
|
|
936
393
|
declare function useStore<Key extends keyof State>(target: Key, defaultValue?: State[Key]): UseStoreReturn<State[Key]>;
|
|
937
394
|
type UseStoreReturn<T$1> = [T$1, (value: T$1) => void];
|
|
938
395
|
//#endregion
|
|
939
|
-
//#region ../../src/core/components/ErrorBoundary.d.ts
|
|
940
|
-
/**
|
|
941
|
-
* Props for the ErrorBoundary component.
|
|
942
|
-
*/
|
|
943
|
-
interface ErrorBoundaryProps {
|
|
944
|
-
/**
|
|
945
|
-
* Fallback React node to render when an error is caught.
|
|
946
|
-
* If not provided, a default error message will be shown.
|
|
947
|
-
*/
|
|
948
|
-
fallback: (error: Error) => ReactNode;
|
|
949
|
-
/**
|
|
950
|
-
* Optional callback that receives the error and error info.
|
|
951
|
-
* Use this to log errors to a monitoring service.
|
|
952
|
-
*/
|
|
953
|
-
onError?: (error: Error, info: ErrorInfo) => void;
|
|
954
|
-
}
|
|
955
|
-
/**
|
|
956
|
-
* State of the ErrorBoundary component.
|
|
957
|
-
*/
|
|
958
|
-
interface ErrorBoundaryState {
|
|
959
|
-
error?: Error;
|
|
960
|
-
}
|
|
961
|
-
/**
|
|
962
|
-
* A reusable error boundary for catching rendering errors
|
|
963
|
-
* in any part of the React component tree.
|
|
964
|
-
*/
|
|
965
|
-
declare class ErrorBoundary extends React.Component<PropsWithChildren<ErrorBoundaryProps>, ErrorBoundaryState> {
|
|
966
|
-
constructor(props: ErrorBoundaryProps);
|
|
967
|
-
/**
|
|
968
|
-
* Update state so the next render shows the fallback UI.
|
|
969
|
-
*/
|
|
970
|
-
static getDerivedStateFromError(error: Error): ErrorBoundaryState;
|
|
971
|
-
/**
|
|
972
|
-
* Lifecycle method called when an error is caught.
|
|
973
|
-
* You can log the error or perform side effects here.
|
|
974
|
-
*/
|
|
975
|
-
componentDidCatch(error: Error, info: ErrorInfo): void;
|
|
976
|
-
render(): ReactNode;
|
|
977
|
-
}
|
|
978
|
-
//#endregion
|
|
979
|
-
//#region ../../src/core/components/ErrorViewer.d.ts
|
|
980
|
-
interface ErrorViewerProps {
|
|
981
|
-
error: Error;
|
|
982
|
-
alepha: Alepha;
|
|
983
|
-
}
|
|
984
|
-
/**
|
|
985
|
-
* Error viewer component that displays error details in development mode
|
|
986
|
-
*/
|
|
987
|
-
declare const ErrorViewer: ({
|
|
988
|
-
error,
|
|
989
|
-
alepha
|
|
990
|
-
}: ErrorViewerProps) => react_jsx_runtime0.JSX.Element;
|
|
991
|
-
//#endregion
|
|
992
|
-
//#region ../../src/core/components/Link.d.ts
|
|
993
|
-
interface LinkProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
|
|
994
|
-
href: string;
|
|
995
|
-
}
|
|
996
|
-
declare const Link: (props: LinkProps) => react_jsx_runtime0.JSX.Element;
|
|
997
|
-
//#endregion
|
|
998
|
-
//#region ../../src/core/components/NestedView.d.ts
|
|
999
|
-
interface NestedViewProps {
|
|
1000
|
-
children?: ReactNode;
|
|
1001
|
-
errorBoundary?: false | ((error: Error) => ReactNode);
|
|
1002
|
-
}
|
|
1003
|
-
declare const _default: react0.MemoExoticComponent<(props: NestedViewProps) => react_jsx_runtime0.JSX.Element>;
|
|
1004
|
-
//#endregion
|
|
1005
|
-
//#region ../../src/core/components/NotFound.d.ts
|
|
1006
|
-
declare function NotFoundPage(props: {
|
|
1007
|
-
style?: CSSProperties;
|
|
1008
|
-
}): react_jsx_runtime0.JSX.Element;
|
|
1009
|
-
//#endregion
|
|
1010
|
-
//#region ../../src/core/contexts/RouterLayerContext.d.ts
|
|
1011
|
-
interface RouterLayerContextValue {
|
|
1012
|
-
index: number;
|
|
1013
|
-
path: string;
|
|
1014
|
-
onError: ErrorHandler;
|
|
1015
|
-
}
|
|
1016
|
-
declare const RouterLayerContext: react0.Context<RouterLayerContextValue | undefined>;
|
|
1017
|
-
//#endregion
|
|
1018
|
-
//#region ../../src/core/hooks/useActive.d.ts
|
|
1019
|
-
interface UseActiveOptions {
|
|
1020
|
-
href: string;
|
|
1021
|
-
startWith?: boolean;
|
|
1022
|
-
}
|
|
1023
|
-
declare const useActive: (args: string | UseActiveOptions) => UseActiveHook;
|
|
1024
|
-
interface UseActiveHook {
|
|
1025
|
-
isActive: boolean;
|
|
1026
|
-
anchorProps: AnchorProps;
|
|
1027
|
-
isPending: boolean;
|
|
1028
|
-
}
|
|
1029
|
-
//#endregion
|
|
1030
|
-
//#region ../../src/core/hooks/useQueryParams.d.ts
|
|
1031
|
-
/**
|
|
1032
|
-
* Not well tested. Use with caution.
|
|
1033
|
-
*/
|
|
1034
|
-
declare const useQueryParams: <T$1 extends TObject>(schema: T$1, options?: UseQueryParamsHookOptions) => [Partial<Static<T$1>>, (data: Static<T$1>) => void];
|
|
1035
|
-
interface UseQueryParamsHookOptions {
|
|
1036
|
-
format?: "base64" | "querystring";
|
|
1037
|
-
key?: string;
|
|
1038
|
-
push?: boolean;
|
|
1039
|
-
}
|
|
1040
|
-
//#endregion
|
|
1041
|
-
//#region ../../src/core/services/ReactRouter.d.ts
|
|
1042
|
-
declare class ReactRouter<T$1 extends object> {
|
|
1043
|
-
protected readonly alepha: Alepha;
|
|
1044
|
-
protected readonly pageApi: ReactPageProvider;
|
|
1045
|
-
get state(): ReactRouterState;
|
|
1046
|
-
get pages(): PageRoute[];
|
|
1047
|
-
get concretePages(): ConcretePageRoute[];
|
|
1048
|
-
get browser(): ReactBrowserProvider | undefined;
|
|
1049
|
-
isActive(href: string, options?: {
|
|
1050
|
-
startWith?: boolean;
|
|
1051
|
-
}): boolean;
|
|
1052
|
-
node(name: keyof VirtualRouter<T$1> | string, config?: {
|
|
1053
|
-
params?: Record<string, any>;
|
|
1054
|
-
query?: Record<string, any>;
|
|
1055
|
-
}): {
|
|
1056
|
-
label: any;
|
|
1057
|
-
href: string;
|
|
1058
|
-
children: undefined;
|
|
1059
|
-
type: "page";
|
|
1060
|
-
name: string;
|
|
1061
|
-
parent?: PageRoute;
|
|
1062
|
-
match: string;
|
|
1063
|
-
path?: string | undefined;
|
|
1064
|
-
schema?: PageConfigSchema | undefined;
|
|
1065
|
-
resolve?: ((context: PageResolve<PageConfigSchema, TPropsParentDefault>) => any) | undefined;
|
|
1066
|
-
props?: (() => Partial<any>) | undefined;
|
|
1067
|
-
component?: react0.FC<any> | undefined;
|
|
1068
|
-
lazy?: (() => Promise<{
|
|
1069
|
-
default: react0.FC<any>;
|
|
1070
|
-
}>) | undefined;
|
|
1071
|
-
can?: (() => boolean) | undefined;
|
|
1072
|
-
errorHandler?: ErrorHandler | undefined;
|
|
1073
|
-
static?: boolean | {
|
|
1074
|
-
entries?: Partial<PageRequestConfig<PageConfigSchema>>[] | undefined;
|
|
1075
|
-
} | undefined;
|
|
1076
|
-
cache?: alepha_server_cache0.ServerRouteCache | undefined;
|
|
1077
|
-
client?: (boolean | ClientOnlyProps) | undefined;
|
|
1078
|
-
onServerResponse?: ((request: alepha_server0.ServerRequest) => unknown) | undefined;
|
|
1079
|
-
onLeave?: (() => void) | undefined;
|
|
1080
|
-
animation?: PageAnimation | undefined;
|
|
1081
|
-
};
|
|
1082
|
-
path(name: keyof VirtualRouter<T$1> | string, config?: {
|
|
1083
|
-
params?: Record<string, any>;
|
|
1084
|
-
query?: Record<string, any>;
|
|
1085
|
-
}): string;
|
|
1086
|
-
/**
|
|
1087
|
-
* Reload the current page.
|
|
1088
|
-
* This is equivalent to calling `go()` with the current pathname and search.
|
|
1089
|
-
*/
|
|
1090
|
-
reload(): Promise<void>;
|
|
1091
|
-
getURL(): URL;
|
|
1092
|
-
get location(): Location;
|
|
1093
|
-
get current(): ReactRouterState;
|
|
1094
|
-
get pathname(): string;
|
|
1095
|
-
get query(): Record<string, string>;
|
|
1096
|
-
back(): Promise<void>;
|
|
1097
|
-
forward(): Promise<void>;
|
|
1098
|
-
invalidate(props?: Record<string, any>): Promise<void>;
|
|
1099
|
-
go(path: string, options?: RouterGoOptions): Promise<void>;
|
|
1100
|
-
go(path: keyof VirtualRouter<T$1>, options?: RouterGoOptions): Promise<void>;
|
|
1101
|
-
anchor(path: string, options?: RouterGoOptions): AnchorProps;
|
|
1102
|
-
anchor(path: keyof VirtualRouter<T$1>, options?: RouterGoOptions): AnchorProps;
|
|
1103
|
-
base(path: string): string;
|
|
1104
|
-
/**
|
|
1105
|
-
* Set query params.
|
|
1106
|
-
*
|
|
1107
|
-
* @param record
|
|
1108
|
-
* @param options
|
|
1109
|
-
*/
|
|
1110
|
-
setQueryParams(record: Record<string, any> | ((queryParams: Record<string, any>) => Record<string, any>), options?: {
|
|
1111
|
-
/**
|
|
1112
|
-
* If true, this will add a new entry to the history stack.
|
|
1113
|
-
*/
|
|
1114
|
-
push?: boolean;
|
|
1115
|
-
}): void;
|
|
1116
|
-
}
|
|
1117
|
-
type VirtualRouter<T$1> = { [K in keyof T$1 as T$1[K] extends PagePrimitive ? K : never]: T$1[K] };
|
|
1118
|
-
//#endregion
|
|
1119
|
-
//#region ../../src/core/hooks/useRouter.d.ts
|
|
1120
|
-
/**
|
|
1121
|
-
* Use this hook to access the React Router instance.
|
|
1122
|
-
*
|
|
1123
|
-
* You can add a type parameter to specify the type of your application.
|
|
1124
|
-
* This will allow you to use the router in a typesafe way.
|
|
1125
|
-
*
|
|
1126
|
-
* @example
|
|
1127
|
-
* class App {
|
|
1128
|
-
* home = $page();
|
|
1129
|
-
* }
|
|
1130
|
-
*
|
|
1131
|
-
* const router = useRouter<App>();
|
|
1132
|
-
* router.go("home"); // typesafe
|
|
1133
|
-
*/
|
|
1134
|
-
declare const useRouter: <T$1 extends object = any>() => ReactRouter<T$1>;
|
|
1135
|
-
//#endregion
|
|
1136
|
-
//#region ../../src/core/hooks/useRouterState.d.ts
|
|
1137
|
-
declare const useRouterState: () => ReactRouterState;
|
|
1138
|
-
//#endregion
|
|
1139
|
-
//#region ../../src/core/providers/ReactServerProvider.d.ts
|
|
1140
|
-
declare const envSchema: alepha19.TObject<{
|
|
1141
|
-
REACT_SSR_ENABLED: alepha19.TOptional<alepha19.TBoolean>;
|
|
1142
|
-
REACT_ROOT_ID: alepha19.TString;
|
|
1143
|
-
}>;
|
|
1144
|
-
declare module "alepha" {
|
|
1145
|
-
interface Env extends Partial<Static<typeof envSchema>> {}
|
|
1146
|
-
interface State {
|
|
1147
|
-
"alepha.react.server.ssr"?: boolean;
|
|
1148
|
-
"alepha.react.server.template"?: string;
|
|
1149
|
-
}
|
|
1150
|
-
}
|
|
1151
|
-
/**
|
|
1152
|
-
* React server provider configuration atom
|
|
1153
|
-
*/
|
|
1154
|
-
declare const reactServerOptions: alepha19.Atom<alepha19.TObject<{
|
|
1155
|
-
publicDir: alepha19.TString;
|
|
1156
|
-
staticServer: alepha19.TObject<{
|
|
1157
|
-
disabled: alepha19.TBoolean;
|
|
1158
|
-
path: alepha19.TString;
|
|
1159
|
-
}>;
|
|
1160
|
-
}>, "alepha.react.server.options">;
|
|
1161
|
-
type ReactServerProviderOptions = Static<typeof reactServerOptions.schema>;
|
|
1162
|
-
declare module "alepha" {
|
|
1163
|
-
interface State {
|
|
1164
|
-
[reactServerOptions.key]: ReactServerProviderOptions;
|
|
1165
|
-
}
|
|
1166
|
-
}
|
|
1167
|
-
declare class ReactServerProvider {
|
|
1168
|
-
protected readonly log: alepha_logger1.Logger;
|
|
1169
|
-
protected readonly alepha: Alepha;
|
|
1170
|
-
protected readonly env: {
|
|
1171
|
-
REACT_SSR_ENABLED?: boolean | undefined;
|
|
1172
|
-
REACT_ROOT_ID: string;
|
|
1173
|
-
};
|
|
1174
|
-
protected readonly pageApi: ReactPageProvider;
|
|
1175
|
-
protected readonly serverProvider: ServerProvider;
|
|
1176
|
-
protected readonly serverStaticProvider: ServerStaticProvider;
|
|
1177
|
-
protected readonly serverRouterProvider: ServerRouterProvider;
|
|
1178
|
-
protected readonly serverTimingProvider: ServerTimingProvider;
|
|
1179
|
-
readonly ROOT_DIV_REGEX: RegExp;
|
|
1180
|
-
protected preprocessedTemplate: PreprocessedTemplate | null;
|
|
1181
|
-
protected readonly options: Readonly<{
|
|
1182
|
-
publicDir: string;
|
|
1183
|
-
staticServer: {
|
|
1184
|
-
disabled: boolean;
|
|
1185
|
-
path: string;
|
|
1186
|
-
};
|
|
1187
|
-
}>;
|
|
1188
|
-
/**
|
|
1189
|
-
* Configure the React server provider.
|
|
1190
|
-
*/
|
|
1191
|
-
readonly onConfigure: alepha19.HookPrimitive<"configure">;
|
|
1192
|
-
get template(): string;
|
|
1193
|
-
protected registerPages(templateLoader: TemplateLoader): Promise<void>;
|
|
1194
|
-
/**
|
|
1195
|
-
* Get the public directory path where static files are located.
|
|
1196
|
-
*/
|
|
1197
|
-
protected getPublicDirectory(): string;
|
|
1198
|
-
/**
|
|
1199
|
-
* Configure the static file server to serve files from the given root directory.
|
|
1200
|
-
*/
|
|
1201
|
-
protected configureStaticServer(root: string): Promise<void>;
|
|
1202
|
-
/**
|
|
1203
|
-
* Configure Vite for SSR.
|
|
1204
|
-
*/
|
|
1205
|
-
protected configureVite(ssrEnabled: boolean): Promise<void>;
|
|
1206
|
-
/**
|
|
1207
|
-
* For testing purposes, creates a render function that can be used.
|
|
1208
|
-
*/
|
|
1209
|
-
render(name: string, options?: PagePrimitiveRenderOptions): Promise<PagePrimitiveRenderResult>;
|
|
1210
|
-
protected createHandler(route: PageRoute, templateLoader: TemplateLoader): ServerHandler;
|
|
1211
|
-
renderToHtml(template: string, state: ReactRouterState, hydration?: boolean): string | Redirection;
|
|
1212
|
-
protected preprocessTemplate(template: string): PreprocessedTemplate;
|
|
1213
|
-
protected fillTemplate(response: {
|
|
1214
|
-
html: string;
|
|
1215
|
-
}, app: string, script: string): void;
|
|
1216
|
-
}
|
|
1217
|
-
type TemplateLoader = () => Promise<string | undefined>;
|
|
1218
|
-
interface PreprocessedTemplate {
|
|
1219
|
-
beforeApp: string;
|
|
1220
|
-
afterApp: string;
|
|
1221
|
-
beforeScript: string;
|
|
1222
|
-
afterScript: string;
|
|
1223
|
-
}
|
|
1224
|
-
//#endregion
|
|
1225
396
|
//#region ../../src/core/index.d.ts
|
|
1226
397
|
declare module "alepha" {
|
|
1227
|
-
interface State {
|
|
1228
|
-
"alepha.react.router.state"?: ReactRouterState;
|
|
1229
|
-
}
|
|
1230
398
|
interface Hooks {
|
|
1231
|
-
/**
|
|
1232
|
-
* Fires when the React application is starting to be rendered on the server.
|
|
1233
|
-
*/
|
|
1234
|
-
"react:server:render:begin": {
|
|
1235
|
-
request?: ServerRequest;
|
|
1236
|
-
state: ReactRouterState;
|
|
1237
|
-
};
|
|
1238
|
-
/**
|
|
1239
|
-
* Fires when the React application has been rendered on the server.
|
|
1240
|
-
*/
|
|
1241
|
-
"react:server:render:end": {
|
|
1242
|
-
request?: ServerRequest;
|
|
1243
|
-
state: ReactRouterState;
|
|
1244
|
-
html: string;
|
|
1245
|
-
};
|
|
1246
|
-
/**
|
|
1247
|
-
* Fires when the React application is being rendered on the browser.
|
|
1248
|
-
*/
|
|
1249
|
-
"react:browser:render": {
|
|
1250
|
-
root: HTMLElement;
|
|
1251
|
-
element: ReactNode;
|
|
1252
|
-
state: ReactRouterState;
|
|
1253
|
-
hydration?: ReactHydrationState;
|
|
1254
|
-
};
|
|
1255
399
|
/**
|
|
1256
400
|
* Fires when a user action is starting.
|
|
1257
401
|
* Action can be a form submission, a route transition, or a custom action.
|
|
@@ -1285,33 +429,6 @@ declare module "alepha" {
|
|
|
1285
429
|
type: string;
|
|
1286
430
|
id?: string;
|
|
1287
431
|
};
|
|
1288
|
-
/**
|
|
1289
|
-
* Fires when a route transition is starting.
|
|
1290
|
-
*/
|
|
1291
|
-
"react:transition:begin": {
|
|
1292
|
-
previous: ReactRouterState;
|
|
1293
|
-
state: ReactRouterState;
|
|
1294
|
-
animation?: PageAnimation;
|
|
1295
|
-
};
|
|
1296
|
-
/**
|
|
1297
|
-
* Fires when a route transition has succeeded.
|
|
1298
|
-
*/
|
|
1299
|
-
"react:transition:success": {
|
|
1300
|
-
state: ReactRouterState;
|
|
1301
|
-
};
|
|
1302
|
-
/**
|
|
1303
|
-
* Fires when a route transition has failed.
|
|
1304
|
-
*/
|
|
1305
|
-
"react:transition:error": {
|
|
1306
|
-
state: ReactRouterState;
|
|
1307
|
-
error: Error;
|
|
1308
|
-
};
|
|
1309
|
-
/**
|
|
1310
|
-
* Fires when a route transition has completed, regardless of success or failure.
|
|
1311
|
-
*/
|
|
1312
|
-
"react:transition:end": {
|
|
1313
|
-
state: ReactRouterState;
|
|
1314
|
-
};
|
|
1315
432
|
}
|
|
1316
433
|
}
|
|
1317
434
|
/**
|
|
@@ -1324,7 +441,7 @@ declare module "alepha" {
|
|
|
1324
441
|
* @see {@link $page}
|
|
1325
442
|
* @module alepha.react
|
|
1326
443
|
*/
|
|
1327
|
-
declare const AlephaReact:
|
|
444
|
+
declare const AlephaReact: alepha0.Service<alepha0.Module>;
|
|
1328
445
|
//#endregion
|
|
1329
|
-
export {
|
|
446
|
+
export { ActionContext, AlephaContext, AlephaProvider, AlephaProviderProps, AlephaReact, ClientOnly, ClientOnlyProps, ErrorBoundary, ErrorBoundaryProps, UseActionOptions, UseActionReturn, UseStoreReturn, useAction, useAlepha, useClient, useEvents, useInject, useStore };
|
|
1330
447
|
//# sourceMappingURL=index.d.ts.map
|