@alepha/react 0.10.0 → 0.10.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/index.d.cts DELETED
@@ -1,904 +0,0 @@
1
- import * as _alepha_core14 from "@alepha/core";
2
- import { Alepha, Async, Descriptor, Hooks, KIND, Service, State, Static, TObject, TSchema } from "@alepha/core";
3
- import { RequestConfigSchema, ServerHandler, ServerProvider, ServerRequest, ServerRouterProvider, ServerTimingProvider } from "@alepha/server";
4
- import * as react0 from "react";
5
- import React, { AnchorHTMLAttributes, CSSProperties, ErrorInfo, FC, PropsWithChildren, ReactNode } from "react";
6
- import { ServerRouteCache } from "@alepha/server-cache";
7
- import * as _alepha_logger1 from "@alepha/logger";
8
- import { DateTimeProvider } from "@alepha/datetime";
9
- import { ClientScope, HttpVirtualClient, LinkProvider, VirtualAction } from "@alepha/server-links";
10
- import { Route, RouterProvider } from "@alepha/router";
11
- import * as react_jsx_runtime1 from "react/jsx-runtime";
12
- import { ServerStaticProvider } from "@alepha/server-static";
13
-
14
- //#region src/components/ClientOnly.d.ts
15
- interface ClientOnlyProps {
16
- fallback?: ReactNode;
17
- disabled?: boolean;
18
- }
19
- /**
20
- * A small utility component that renders its children only on the client side.
21
- *
22
- * Optionally, you can provide a fallback React node that will be rendered.
23
- *
24
- * You should use this component when
25
- * - you have code that relies on browser-specific APIs
26
- * - you want to avoid server-side rendering for a specific part of your application
27
- * - you want to prevent pre-rendering of a component
28
- */
29
- declare const ClientOnly: (props: PropsWithChildren<ClientOnlyProps>) => ReactNode;
30
- //#endregion
31
- //#region src/errors/Redirection.d.ts
32
- /**
33
- * Used for Redirection during the page loading.
34
- *
35
- * Depends on the context, it can be thrown or just returned.
36
- */
37
- declare class Redirection extends Error {
38
- readonly redirect: string;
39
- constructor(redirect: string);
40
- }
41
- //#endregion
42
- //#region src/providers/ReactPageProvider.d.ts
43
- declare const envSchema$2: _alepha_core14.TObject<{
44
- REACT_STRICT_MODE: _alepha_core14.TBoolean;
45
- }>;
46
- declare module "@alepha/core" {
47
- interface Env extends Partial<Static<typeof envSchema$2>> {}
48
- }
49
- declare class ReactPageProvider {
50
- protected readonly log: _alepha_logger1.Logger;
51
- protected readonly env: {
52
- REACT_STRICT_MODE: boolean;
53
- };
54
- protected readonly alepha: Alepha;
55
- protected readonly pages: PageRoute[];
56
- getPages(): PageRoute[];
57
- page(name: string): PageRoute;
58
- pathname(name: string, options?: {
59
- params?: Record<string, string>;
60
- query?: Record<string, string>;
61
- }): string;
62
- url(name: string, options?: {
63
- params?: Record<string, string>;
64
- host?: string;
65
- }): URL;
66
- root(state: ReactRouterState): ReactNode;
67
- protected convertStringObjectToObject: (schema?: TSchema, value?: any) => any;
68
- /**
69
- * Create a new RouterState based on a given route and request.
70
- * This method resolves the layers for the route, applying any query and params schemas defined in the route.
71
- * It also handles errors and redirects.
72
- */
73
- createLayers(route: PageRoute, state: ReactRouterState, previous?: PreviousLayerData[]): Promise<CreateLayersResult>;
74
- protected createRedirectionLayer(redirect: string): CreateLayersResult;
75
- protected getErrorHandler(route: PageRoute): ErrorHandler | undefined;
76
- protected createElement(page: PageRoute, props: Record<string, any>): Promise<ReactNode>;
77
- renderError(error: Error): ReactNode;
78
- renderEmptyView(): ReactNode;
79
- href(page: {
80
- options: {
81
- name?: string;
82
- };
83
- }, params?: Record<string, any>): string;
84
- compile(path: string, params?: Record<string, string>): string;
85
- protected renderView(index: number, path: string, view: ReactNode | undefined, page: PageRoute): ReactNode;
86
- protected readonly configure: _alepha_core14.HookDescriptor<"configure">;
87
- protected map(pages: Array<PageDescriptor>, target: PageDescriptor): PageRouteEntry;
88
- add(entry: PageRouteEntry): void;
89
- protected createMatch(page: PageRoute): string;
90
- protected _next: number;
91
- protected nextId(): string;
92
- }
93
- declare const isPageRoute: (it: any) => it is PageRoute;
94
- interface PageRouteEntry extends Omit<PageDescriptorOptions, "children" | "parent"> {
95
- children?: PageRouteEntry[];
96
- }
97
- interface PageRoute extends PageRouteEntry {
98
- type: "page";
99
- name: string;
100
- parent?: PageRoute;
101
- match: string;
102
- }
103
- interface Layer {
104
- config?: {
105
- query?: Record<string, any>;
106
- params?: Record<string, any>;
107
- context?: Record<string, any>;
108
- };
109
- name: string;
110
- props?: Record<string, any>;
111
- error?: Error;
112
- part?: string;
113
- element: ReactNode;
114
- index: number;
115
- path: string;
116
- route?: PageRoute;
117
- cache?: boolean;
118
- }
119
- type PreviousLayerData = Omit<Layer, "element" | "index" | "path">;
120
- interface AnchorProps {
121
- href: string;
122
- onClick: (ev?: any) => any;
123
- }
124
- interface ReactRouterState {
125
- /**
126
- * Stack of layers for the current page.
127
- */
128
- layers: Array<Layer>;
129
- /**
130
- * URL of the current page.
131
- */
132
- url: URL;
133
- /**
134
- * Error handler for the current page.
135
- */
136
- onError: ErrorHandler;
137
- /**
138
- * Params extracted from the URL for the current page.
139
- */
140
- params: Record<string, any>;
141
- /**
142
- * Query parameters extracted from the URL for the current page.
143
- */
144
- query: Record<string, string>;
145
- /**
146
- * Optional meta information associated with the current page.
147
- */
148
- meta: Record<string, any>;
149
- }
150
- interface RouterStackItem {
151
- route: PageRoute;
152
- config?: Record<string, any>;
153
- props?: Record<string, any>;
154
- error?: Error;
155
- cache?: boolean;
156
- }
157
- interface TransitionOptions {
158
- previous?: PreviousLayerData[];
159
- }
160
- interface CreateLayersResult {
161
- redirect?: string;
162
- state?: ReactRouterState;
163
- }
164
- //#endregion
165
- //#region src/descriptors/$page.d.ts
166
- /**
167
- * Main descriptor for defining a React route in the application.
168
- *
169
- * The $page descriptor is the core building block for creating type-safe, SSR-enabled React routes.
170
- * It provides a declarative way to define pages with powerful features:
171
- *
172
- * **Routing & Navigation**
173
- * - URL pattern matching with parameters (e.g., `/users/:id`)
174
- * - Nested routing with parent-child relationships
175
- * - Type-safe URL parameter and query string validation
176
- *
177
- * **Data Loading**
178
- * - Server-side data fetching with the `resolve` function
179
- * - Automatic serialization and hydration for SSR
180
- * - Access to request context, URL params, and parent data
181
- *
182
- * **Component Loading**
183
- * - Direct component rendering or lazy loading for code splitting
184
- * - Client-only rendering when browser APIs are needed
185
- * - Automatic fallback handling during hydration
186
- *
187
- * **Performance Optimization**
188
- * - Static generation for pre-rendered pages at build time
189
- * - Server-side caching with configurable TTL and providers
190
- * - Code splitting through lazy component loading
191
- *
192
- * **Error Handling**
193
- * - Custom error handlers with support for redirects
194
- * - Hierarchical error handling (child → parent)
195
- * - HTTP status code handling (404, 401, etc.)
196
- *
197
- * **Page Animations**
198
- * - CSS-based enter/exit animations
199
- * - Dynamic animations based on page state
200
- * - Custom timing and easing functions
201
- *
202
- * **Lifecycle Management**
203
- * - Server response hooks for headers and status codes
204
- * - Page leave handlers for cleanup (browser only)
205
- * - Permission-based access control
206
- *
207
- * @example Simple page with data fetching
208
- * ```typescript
209
- * const userProfile = $page({
210
- * path: "/users/:id",
211
- * schema: {
212
- * params: t.object({ id: t.int() }),
213
- * query: t.object({ tab: t.optional(t.string()) })
214
- * },
215
- * resolve: async ({ params }) => {
216
- * const user = await userApi.getUser(params.id);
217
- * return { user };
218
- * },
219
- * lazy: () => import("./UserProfile.tsx")
220
- * });
221
- * ```
222
- *
223
- * @example Nested routing with error handling
224
- * ```typescript
225
- * const projectSection = $page({
226
- * path: "/projects/:id",
227
- * children: () => [projectBoard, projectSettings],
228
- * resolve: async ({ params }) => {
229
- * const project = await projectApi.get(params.id);
230
- * return { project };
231
- * },
232
- * errorHandler: (error) => {
233
- * if (HttpError.is(error, 404)) {
234
- * return <ProjectNotFound />;
235
- * }
236
- * }
237
- * });
238
- * ```
239
- *
240
- * @example Static generation with caching
241
- * ```typescript
242
- * const blogPost = $page({
243
- * path: "/blog/:slug",
244
- * static: {
245
- * entries: posts.map(p => ({ params: { slug: p.slug } }))
246
- * },
247
- * resolve: async ({ params }) => {
248
- * const post = await loadPost(params.slug);
249
- * return { post };
250
- * }
251
- * });
252
- * ```
253
- */
254
- declare const $page: {
255
- <TConfig extends PageConfigSchema = PageConfigSchema, TProps extends object = any, TPropsParent extends object = TPropsParentDefault>(options: PageDescriptorOptions<TConfig, TProps, TPropsParent>): PageDescriptor<TConfig, TProps, TPropsParent>;
256
- [KIND]: typeof PageDescriptor;
257
- };
258
- interface PageDescriptorOptions<TConfig extends PageConfigSchema = PageConfigSchema, TProps extends object = TPropsDefault, TPropsParent extends object = TPropsParentDefault> {
259
- /**
260
- * Name your page.
261
- *
262
- * @default Descriptor key
263
- */
264
- name?: string;
265
- /**
266
- * Optional description of the page.
267
- */
268
- description?: string;
269
- /**
270
- * Add a pathname to the page.
271
- *
272
- * Pathname can contain parameters, like `/post/:slug`.
273
- *
274
- * @default ""
275
- */
276
- path?: string;
277
- /**
278
- * Add an input schema to define:
279
- * - `params`: parameters from the pathname.
280
- * - `query`: query parameters from the URL.
281
- */
282
- schema?: TConfig;
283
- /**
284
- * Load data before rendering the page.
285
- *
286
- * This function receives
287
- * - the request context and
288
- * - the parent props (if page has a parent)
289
- *
290
- * In SSR, the returned data will be serialized and sent to the client, then reused during the client-side hydration.
291
- *
292
- * Resolve can be stopped by throwing an error, which will be handled by the `errorHandler` function.
293
- * It's common to throw a `NotFoundError` to display a 404 page.
294
- *
295
- * RedirectError can be thrown to redirect the user to another page.
296
- */
297
- resolve?: (context: PageResolve<TConfig, TPropsParent>) => Async<TProps>;
298
- /**
299
- * The component to render when the page is loaded.
300
- *
301
- * If `lazy` is defined, this will be ignored.
302
- * Prefer using `lazy` to improve the initial loading time.
303
- */
304
- component?: FC<TProps & TPropsParent>;
305
- /**
306
- * Lazy load the component when the page is loaded.
307
- *
308
- * It's recommended to use this for components to improve the initial loading time
309
- * and enable code-splitting.
310
- */
311
- lazy?: () => Promise<{
312
- default: FC<TProps & TPropsParent>;
313
- }>;
314
- /**
315
- * Set some children pages and make the page a parent page.
316
- *
317
- * /!\ Parent page can't be rendered directly. /!\
318
- *
319
- * If you still want to render at this pathname, add a child page with an empty path.
320
- */
321
- children?: Array<PageDescriptor> | (() => Array<PageDescriptor>);
322
- parent?: PageDescriptor<PageConfigSchema, TPropsParent>;
323
- can?: () => boolean;
324
- /**
325
- * Catch any error from the `resolve` function or during `rendering`.
326
- *
327
- * Expected to return one of the following:
328
- * - a ReactNode to render an error page
329
- * - a Redirection to redirect the user
330
- * - undefined to let the error propagate
331
- *
332
- * If not defined, the error will be thrown and handled by the server or client error handler.
333
- * If a leaf $page does not define an error handler, the error can be caught by parent pages.
334
- *
335
- * @example Catch a 404 from API and render a custom not found component:
336
- * ```ts
337
- * resolve: async ({ params, query }) => {
338
- * api.fetch("/api/resource", { params, query });
339
- * },
340
- * errorHandler: (error, context) => {
341
- * if (HttpError.is(error, 404)) {
342
- * return <ResourceNotFound />;
343
- * }
344
- * }
345
- * ```
346
- *
347
- * @example Catch an 401 error and redirect the user to the login page:
348
- * ```ts
349
- * resolve: async ({ params, query }) => {
350
- * // but the user is not authenticated
351
- * api.fetch("/api/resource", { params, query });
352
- * },
353
- * errorHandler: (error, context) => {
354
- * if (HttpError.is(error, 401)) {
355
- * // throwing a Redirection is also valid!
356
- * return new Redirection("/login");
357
- * }
358
- * }
359
- * ```
360
- */
361
- errorHandler?: ErrorHandler;
362
- /**
363
- * If true, the page will be considered as a static page, immutable and cacheable.
364
- * Replace boolean by an object to define static entries. (e.g. list of params/query)
365
- *
366
- * For now, it only works with `@alepha/vite` which can pre-render the page at build time.
367
- *
368
- * It will act as timeless cached page server-side. You can use `cache` to configure the cache behavior.
369
- */
370
- static?: boolean | {
371
- entries?: Array<Partial<PageRequestConfig<TConfig>>>;
372
- };
373
- cache?: ServerRouteCache;
374
- /**
375
- * If true, force the page to be rendered only on the client-side.
376
- * It uses the `<ClientOnly/>` component to render the page.
377
- */
378
- client?: boolean | ClientOnlyProps;
379
- /**
380
- * Called before the server response is sent to the client.
381
- */
382
- onServerResponse?: (request: ServerRequest) => any;
383
- /**
384
- * Called when user leaves the page. (browser only)
385
- */
386
- onLeave?: () => void;
387
- /**
388
- * @experimental
389
- *
390
- * Add a css animation when the page is loaded or unloaded.
391
- * It uses CSS animations, so you need to define the keyframes in your CSS.
392
- *
393
- * @example Simple animation name
394
- * ```ts
395
- * animation: "fadeIn"
396
- * ```
397
- *
398
- * CSS example:
399
- * ```css
400
- * @keyframes fadeIn {
401
- * from { opacity: 0; }
402
- * to { opacity: 1; }
403
- * }
404
- * ```
405
- *
406
- * @example Detailed animation
407
- * ```ts
408
- * animation: {
409
- * enter: { name: "fadeIn", duration: 300 },
410
- * exit: { name: "fadeOut", duration: 200, timing: "ease-in-out" },
411
- * }
412
- * ```
413
- *
414
- * @example Only exit animation
415
- * ```ts
416
- * animation: {
417
- * exit: "fadeOut"
418
- * }
419
- * ```
420
- *
421
- * @example With custom timing function
422
- * ```ts
423
- * animation: {
424
- * enter: { name: "fadeIn", duration: 300, timing: "cubic-bezier(0.4, 0, 0.2, 1)" },
425
- * exit: { name: "fadeOut", duration: 200, timing: "ease-in-out" },
426
- * }
427
- * ```
428
- */
429
- animation?: PageAnimation;
430
- }
431
- type ErrorHandler = (error: Error, state: ReactRouterState) => ReactNode | Redirection | undefined;
432
- declare class PageDescriptor<TConfig extends PageConfigSchema = PageConfigSchema, TProps extends object = TPropsDefault, TPropsParent extends object = TPropsParentDefault> extends Descriptor<PageDescriptorOptions<TConfig, TProps, TPropsParent>> {
433
- protected onInit(): void;
434
- get name(): string;
435
- /**
436
- * For testing or build purposes, this will render the page (with or without the HTML layout) and return the HTML and context.
437
- * Only valid for server-side rendering, it will throw an error if called on the client-side.
438
- */
439
- render(options?: PageDescriptorRenderOptions): Promise<PageDescriptorRenderResult>;
440
- fetch(options?: PageDescriptorRenderOptions): Promise<{
441
- html: string;
442
- response: Response;
443
- }>;
444
- match(url: string): boolean;
445
- pathname(config: any): string;
446
- }
447
- interface PageConfigSchema {
448
- query?: TSchema;
449
- params?: TSchema;
450
- }
451
- type TPropsDefault = any;
452
- type TPropsParentDefault = {};
453
- interface PageDescriptorRenderOptions {
454
- params?: Record<string, string>;
455
- query?: Record<string, string>;
456
- /**
457
- * If true, the HTML layout will be included in the response.
458
- * If false, only the page content will be returned.
459
- *
460
- * @default true
461
- */
462
- html?: boolean;
463
- hydration?: boolean;
464
- }
465
- interface PageDescriptorRenderResult {
466
- html: string;
467
- state: ReactRouterState;
468
- redirect?: string;
469
- }
470
- interface PageRequestConfig<TConfig extends PageConfigSchema = PageConfigSchema> {
471
- params: TConfig["params"] extends TSchema ? Static<TConfig["params"]> : Record<string, string>;
472
- query: TConfig["query"] extends TSchema ? Static<TConfig["query"]> : Record<string, string>;
473
- }
474
- type PageResolve<TConfig extends PageConfigSchema = PageConfigSchema, TPropsParent extends object = TPropsParentDefault> = PageRequestConfig<TConfig> & TPropsParent & Omit<ReactRouterState, "layers" | "onError">;
475
- type PageAnimation = PageAnimationObject | ((state: ReactRouterState) => PageAnimationObject | undefined);
476
- type PageAnimationObject = CssAnimationName | {
477
- enter?: CssAnimation | CssAnimationName;
478
- exit?: CssAnimation | CssAnimationName;
479
- };
480
- type CssAnimationName = string;
481
- type CssAnimation = {
482
- name: string;
483
- duration?: number;
484
- timing?: string;
485
- };
486
- //#endregion
487
- //#region src/providers/ReactBrowserRouterProvider.d.ts
488
- interface BrowserRoute extends Route {
489
- page: PageRoute;
490
- }
491
- declare class ReactBrowserRouterProvider extends RouterProvider<BrowserRoute> {
492
- protected readonly log: _alepha_logger1.Logger;
493
- protected readonly alepha: Alepha;
494
- protected readonly pageApi: ReactPageProvider;
495
- add(entry: PageRouteEntry): void;
496
- protected readonly configure: _alepha_core14.HookDescriptor<"configure">;
497
- transition(url: URL, previous?: PreviousLayerData[], meta?: {}): Promise<string | void>;
498
- root(state: ReactRouterState): ReactNode;
499
- }
500
- //#endregion
501
- //#region src/providers/ReactBrowserProvider.d.ts
502
- declare const envSchema$1: _alepha_core14.TObject<{
503
- REACT_ROOT_ID: _alepha_core14.TString;
504
- }>;
505
- declare module "@alepha/core" {
506
- interface Env extends Partial<Static<typeof envSchema$1>> {}
507
- }
508
- interface ReactBrowserRendererOptions {
509
- scrollRestoration?: "top" | "manual";
510
- }
511
- declare class ReactBrowserProvider {
512
- protected readonly env: {
513
- REACT_ROOT_ID: string;
514
- };
515
- protected readonly log: _alepha_logger1.Logger;
516
- protected readonly client: LinkProvider;
517
- protected readonly alepha: Alepha;
518
- protected readonly router: ReactBrowserRouterProvider;
519
- protected readonly dateTimeProvider: DateTimeProvider;
520
- options: ReactBrowserRendererOptions;
521
- protected getRootElement(): HTMLElement;
522
- transitioning?: {
523
- to: string;
524
- from?: string;
525
- };
526
- get state(): ReactRouterState;
527
- /**
528
- * Accessor for Document DOM API.
529
- */
530
- get document(): Document;
531
- /**
532
- * Accessor for History DOM API.
533
- */
534
- get history(): History;
535
- /**
536
- * Accessor for Location DOM API.
537
- */
538
- get location(): Location;
539
- get base(): string;
540
- get url(): string;
541
- pushState(path: string, replace?: boolean): void;
542
- invalidate(props?: Record<string, any>): Promise<void>;
543
- go(url: string, options?: RouterGoOptions): Promise<void>;
544
- protected render(options?: RouterRenderOptions): Promise<void>;
545
- /**
546
- * Get embedded layers from the server.
547
- */
548
- protected getHydrationState(): ReactHydrationState | undefined;
549
- protected readonly onTransitionEnd: _alepha_core14.HookDescriptor<"react:transition:end">;
550
- readonly ready: _alepha_core14.HookDescriptor<"ready">;
551
- }
552
- interface RouterGoOptions {
553
- replace?: boolean;
554
- match?: TransitionOptions;
555
- params?: Record<string, string>;
556
- query?: Record<string, string>;
557
- meta?: Record<string, any>;
558
- /**
559
- * Recreate the whole page, ignoring the current state.
560
- */
561
- force?: boolean;
562
- }
563
- type ReactHydrationState = {
564
- layers?: Array<PreviousLayerData>;
565
- } & {
566
- [key: string]: any;
567
- };
568
- interface RouterRenderOptions {
569
- url?: string;
570
- previous?: PreviousLayerData[];
571
- meta?: Record<string, any>;
572
- }
573
- //#endregion
574
- //#region src/components/ErrorBoundary.d.ts
575
- /**
576
- * Props for the ErrorBoundary component.
577
- */
578
- interface ErrorBoundaryProps {
579
- /**
580
- * Fallback React node to render when an error is caught.
581
- * If not provided, a default error message will be shown.
582
- */
583
- fallback: (error: Error) => ReactNode;
584
- /**
585
- * Optional callback that receives the error and error info.
586
- * Use this to log errors to a monitoring service.
587
- */
588
- onError?: (error: Error, info: ErrorInfo) => void;
589
- }
590
- /**
591
- * State of the ErrorBoundary component.
592
- */
593
- interface ErrorBoundaryState {
594
- error?: Error;
595
- }
596
- /**
597
- * A reusable error boundary for catching rendering errors
598
- * in any part of the React component tree.
599
- */
600
- declare class ErrorBoundary extends React.Component<PropsWithChildren<ErrorBoundaryProps>, ErrorBoundaryState> {
601
- constructor(props: ErrorBoundaryProps);
602
- /**
603
- * Update state so the next render shows the fallback UI.
604
- */
605
- static getDerivedStateFromError(error: Error): ErrorBoundaryState;
606
- /**
607
- * Lifecycle method called when an error is caught.
608
- * You can log the error or perform side effects here.
609
- */
610
- componentDidCatch(error: Error, info: ErrorInfo): void;
611
- render(): ReactNode;
612
- }
613
- //#endregion
614
- //#region src/components/ErrorViewer.d.ts
615
- interface ErrorViewerProps {
616
- error: Error;
617
- alepha: Alepha;
618
- }
619
- declare const ErrorViewer: ({
620
- error,
621
- alepha
622
- }: ErrorViewerProps) => react_jsx_runtime1.JSX.Element;
623
- //#endregion
624
- //#region src/components/Link.d.ts
625
- interface LinkProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
626
- href: string;
627
- }
628
- declare const Link: (props: LinkProps) => react_jsx_runtime1.JSX.Element;
629
- //#endregion
630
- //#region src/components/NestedView.d.ts
631
- interface NestedViewProps {
632
- children?: ReactNode;
633
- errorBoundary?: false | ((error: Error) => ReactNode);
634
- }
635
- declare const _default: react0.MemoExoticComponent<(props: NestedViewProps) => react_jsx_runtime1.JSX.Element>;
636
- //#endregion
637
- //#region src/components/NotFound.d.ts
638
- declare function NotFoundPage(props: {
639
- style?: CSSProperties;
640
- }): react_jsx_runtime1.JSX.Element;
641
- //#endregion
642
- //#region src/contexts/AlephaContext.d.ts
643
- declare const AlephaContext: react0.Context<Alepha | undefined>;
644
- //#endregion
645
- //#region src/contexts/RouterLayerContext.d.ts
646
- interface RouterLayerContextValue {
647
- index: number;
648
- path: string;
649
- }
650
- declare const RouterLayerContext: react0.Context<RouterLayerContextValue | undefined>;
651
- //#endregion
652
- //#region src/hooks/useActive.d.ts
653
- interface UseActiveOptions {
654
- href: string;
655
- startWith?: boolean;
656
- }
657
- declare const useActive: (args: string | UseActiveOptions) => UseActiveHook;
658
- interface UseActiveHook {
659
- isActive: boolean;
660
- anchorProps: AnchorProps;
661
- isPending: boolean;
662
- }
663
- //#endregion
664
- //#region src/hooks/useAlepha.d.ts
665
- /**
666
- * Main Alepha hook.
667
- *
668
- * It provides access to the Alepha instance within a React component.
669
- *
670
- * With Alepha, you can access the core functionalities of the framework:
671
- *
672
- * - alepha.state() for state management
673
- * - alepha.inject() for dependency injection
674
- * - alepha.events.emit() for event handling
675
- * etc...
676
- */
677
- declare const useAlepha: () => Alepha;
678
- //#endregion
679
- //#region src/hooks/useClient.d.ts
680
- /**
681
- * Hook to get a virtual client for the specified scope.
682
- *
683
- * It's the React-hook version of `$client()`, from `AlephaServerLinks` module.
684
- */
685
- declare const useClient: <T extends object>(scope?: ClientScope) => HttpVirtualClient<T>;
686
- //#endregion
687
- //#region src/hooks/useInject.d.ts
688
- /**
689
- * Hook to inject a service instance.
690
- * It's a wrapper of `useAlepha().inject(service)` with a memoization.
691
- */
692
- declare const useInject: <T extends object>(service: Service<T>) => T;
693
- //#endregion
694
- //#region src/hooks/useQueryParams.d.ts
695
- /**
696
- * Not well tested. Use with caution.
697
- */
698
- declare const useQueryParams: <T extends TObject>(schema: T, options?: UseQueryParamsHookOptions) => [Partial<Static<T>>, (data: Static<T>) => void];
699
- interface UseQueryParamsHookOptions {
700
- format?: "base64" | "querystring";
701
- key?: string;
702
- push?: boolean;
703
- }
704
- //#endregion
705
- //#region src/services/ReactRouter.d.ts
706
- declare class ReactRouter<T extends object> {
707
- protected readonly alepha: Alepha;
708
- protected readonly pageApi: ReactPageProvider;
709
- get state(): ReactRouterState;
710
- get pages(): PageRoute[];
711
- get browser(): ReactBrowserProvider | undefined;
712
- path(name: keyof VirtualRouter<T>, config?: {
713
- params?: Record<string, any>;
714
- query?: Record<string, any>;
715
- }): string;
716
- getURL(): URL;
717
- get location(): Location;
718
- get current(): ReactRouterState;
719
- get pathname(): string;
720
- get query(): Record<string, string>;
721
- back(): Promise<void>;
722
- forward(): Promise<void>;
723
- invalidate(props?: Record<string, any>): Promise<void>;
724
- go(path: string, options?: RouterGoOptions): Promise<void>;
725
- go(path: keyof VirtualRouter<T>, options?: RouterGoOptions): Promise<void>;
726
- anchor(path: string, options?: RouterGoOptions): AnchorProps;
727
- anchor(path: keyof VirtualRouter<T>, options?: RouterGoOptions): AnchorProps;
728
- base(path: string): string;
729
- /**
730
- * Set query params.
731
- *
732
- * @param record
733
- * @param options
734
- */
735
- setQueryParams(record: Record<string, any> | ((queryParams: Record<string, any>) => Record<string, any>), options?: {
736
- /**
737
- * If true, this will add a new entry to the history stack.
738
- */
739
- push?: boolean;
740
- }): void;
741
- }
742
- type VirtualRouter<T> = { [K in keyof T as T[K] extends PageDescriptor ? K : never]: T[K] };
743
- //#endregion
744
- //#region src/hooks/useRouter.d.ts
745
- /**
746
- * Use this hook to access the React Router instance.
747
- *
748
- * You can add a type parameter to specify the type of your application.
749
- * This will allow you to use the router in a typesafe way.
750
- *
751
- * @example
752
- * class App {
753
- * home = $page();
754
- * }
755
- *
756
- * const router = useRouter<App>();
757
- * router.go("home"); // typesafe
758
- */
759
- declare const useRouter: <T extends object = any>() => ReactRouter<T>;
760
- //#endregion
761
- //#region src/hooks/useRouterEvents.d.ts
762
- type Hook<T extends keyof Hooks> = ((ev: Hooks[T]) => void) | {
763
- priority?: "first" | "last";
764
- callback: (ev: Hooks[T]) => void;
765
- };
766
- /**
767
- * Subscribe to various router events.
768
- */
769
- declare const useRouterEvents: (opts?: {
770
- onBegin?: Hook<"react:transition:begin">;
771
- onError?: Hook<"react:transition:error">;
772
- onEnd?: Hook<"react:transition:end">;
773
- onSuccess?: Hook<"react:transition:success">;
774
- }, deps?: any[]) => void;
775
- //#endregion
776
- //#region src/hooks/useRouterState.d.ts
777
- declare const useRouterState: () => ReactRouterState;
778
- //#endregion
779
- //#region src/hooks/useSchema.d.ts
780
- declare const useSchema: <TConfig extends RequestConfigSchema>(action: VirtualAction<TConfig>) => UseSchemaReturn<TConfig>;
781
- type UseSchemaReturn<TConfig extends RequestConfigSchema> = TConfig & {
782
- loading: boolean;
783
- };
784
- /**
785
- * Get an action schema during server-side rendering (SSR) or client-side rendering (CSR).
786
- */
787
- declare const ssrSchemaLoading: (alepha: Alepha, name: string) => RequestConfigSchema | {
788
- loading: boolean;
789
- };
790
- //#endregion
791
- //#region src/hooks/useStore.d.ts
792
- /**
793
- * Hook to access and mutate the Alepha state.
794
- */
795
- declare const useStore: <Key extends keyof State>(key: Key, defaultValue?: State[Key]) => [State[Key], (value: State[Key]) => void];
796
- //#endregion
797
- //#region src/providers/ReactServerProvider.d.ts
798
- declare const envSchema: _alepha_core14.TObject<{
799
- REACT_SERVER_DIST: _alepha_core14.TString;
800
- REACT_SERVER_PREFIX: _alepha_core14.TString;
801
- REACT_SSR_ENABLED: _alepha_core14.TOptional<_alepha_core14.TBoolean>;
802
- REACT_ROOT_ID: _alepha_core14.TString;
803
- REACT_SERVER_TEMPLATE: _alepha_core14.TOptional<_alepha_core14.TString>;
804
- }>;
805
- declare module "@alepha/core" {
806
- interface Env extends Partial<Static<typeof envSchema>> {}
807
- interface State {
808
- "react.server.ssr"?: boolean;
809
- }
810
- }
811
- declare class ReactServerProvider {
812
- protected readonly log: _alepha_logger1.Logger;
813
- protected readonly alepha: Alepha;
814
- protected readonly pageApi: ReactPageProvider;
815
- protected readonly serverProvider: ServerProvider;
816
- protected readonly serverStaticProvider: ServerStaticProvider;
817
- protected readonly serverRouterProvider: ServerRouterProvider;
818
- protected readonly serverTimingProvider: ServerTimingProvider;
819
- protected readonly env: {
820
- REACT_SSR_ENABLED?: boolean | undefined;
821
- REACT_SERVER_TEMPLATE?: string | undefined;
822
- REACT_SERVER_DIST: string;
823
- REACT_SERVER_PREFIX: string;
824
- REACT_ROOT_ID: string;
825
- };
826
- protected readonly ROOT_DIV_REGEX: RegExp;
827
- protected preprocessedTemplate: PreprocessedTemplate | null;
828
- readonly onConfigure: _alepha_core14.HookDescriptor<"configure">;
829
- get template(): string;
830
- protected registerPages(templateLoader: TemplateLoader): Promise<void>;
831
- protected getPublicDirectory(): string;
832
- protected configureStaticServer(root: string): Promise<void>;
833
- protected configureVite(ssrEnabled: boolean): Promise<void>;
834
- /**
835
- * For testing purposes, creates a render function that can be used.
836
- */
837
- protected createRenderFunction(name: string, withIndex?: boolean): (options?: PageDescriptorRenderOptions) => Promise<PageDescriptorRenderResult>;
838
- protected createHandler(route: PageRoute, templateLoader: TemplateLoader): ServerHandler;
839
- renderToHtml(template: string, state: ReactRouterState, hydration?: boolean): string | Redirection;
840
- protected preprocessTemplate(template: string): PreprocessedTemplate;
841
- protected fillTemplate(response: {
842
- html: string;
843
- }, app: string, script: string): void;
844
- }
845
- type TemplateLoader = () => Promise<string | undefined>;
846
- interface PreprocessedTemplate {
847
- beforeApp: string;
848
- afterApp: string;
849
- beforeScript: string;
850
- afterScript: string;
851
- }
852
- //#endregion
853
- //#region src/index.d.ts
854
- declare module "@alepha/core" {
855
- interface State {
856
- "react.router.state"?: ReactRouterState;
857
- }
858
- interface Hooks {
859
- "react:server:render:begin": {
860
- request?: ServerRequest;
861
- state: ReactRouterState;
862
- };
863
- "react:server:render:end": {
864
- request?: ServerRequest;
865
- state: ReactRouterState;
866
- html: string;
867
- };
868
- "react:browser:render": {
869
- root: HTMLDivElement;
870
- element: ReactNode;
871
- state: ReactRouterState;
872
- hydration?: ReactHydrationState;
873
- };
874
- "react:transition:begin": {
875
- previous: ReactRouterState;
876
- state: ReactRouterState;
877
- animation?: PageAnimation;
878
- };
879
- "react:transition:success": {
880
- state: ReactRouterState;
881
- };
882
- "react:transition:error": {
883
- state: ReactRouterState;
884
- error: Error;
885
- };
886
- "react:transition:end": {
887
- state: ReactRouterState;
888
- };
889
- }
890
- }
891
- /**
892
- * Provides full-stack React development with declarative routing, server-side rendering, and client-side hydration.
893
- *
894
- * The React module enables building modern React applications using the `$page` descriptor on class properties.
895
- * It delivers seamless server-side rendering, automatic code splitting, and client-side navigation with full
896
- * type safety and schema validation for route parameters and data.
897
- *
898
- * @see {@link $page}
899
- * @module alepha.react
900
- */
901
- declare const AlephaReact: _alepha_core14.Service<_alepha_core14.Module>;
902
- //#endregion
903
- export { $page, AlephaContext, AlephaReact, AnchorProps, ClientOnly, CreateLayersResult, ErrorBoundary, ErrorHandler, ErrorViewer, Layer, Link, LinkProps, _default as NestedView, NotFoundPage as NotFound, PageAnimation, PageConfigSchema, PageDescriptor, PageDescriptorOptions, PageDescriptorRenderOptions, PageDescriptorRenderResult, PageRequestConfig, PageResolve, PageRoute, PageRouteEntry, PreviousLayerData, ReactBrowserProvider, ReactBrowserRendererOptions, ReactHydrationState, ReactPageProvider, ReactRouter, ReactRouterState, ReactServerProvider, Redirection, RouterGoOptions, RouterLayerContext, RouterLayerContextValue, RouterRenderOptions, RouterStackItem, TPropsDefault, TPropsParentDefault, TransitionOptions, UseActiveHook, UseActiveOptions, UseQueryParamsHookOptions, UseSchemaReturn, VirtualRouter, isPageRoute, ssrSchemaLoading, useActive, useAlepha, useClient, useInject, useQueryParams, useRouter, useRouterEvents, useRouterState, useSchema, useStore };
904
- //# sourceMappingURL=index.d.cts.map