@alepha/react 0.9.4 → 0.10.0

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 CHANGED
@@ -1,15 +1,14 @@
1
1
  import * as _alepha_core14 from "@alepha/core";
2
- import { Alepha, Async, Descriptor, KIND, Service, State, Static, TObject, TSchema } from "@alepha/core";
3
- import { RequestConfigSchema, ServerHandler, ServerRequest, ServerRouterProvider, ServerTimingProvider } from "@alepha/server";
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";
4
7
  import * as _alepha_logger1 from "@alepha/logger";
5
8
  import { DateTimeProvider } from "@alepha/datetime";
6
9
  import { ClientScope, HttpVirtualClient, LinkProvider, VirtualAction } from "@alepha/server-links";
7
- import { Root } from "react-dom/client";
8
10
  import { Route, RouterProvider } from "@alepha/router";
9
- import * as react0 from "react";
10
- import React, { AnchorHTMLAttributes, CSSProperties, ErrorInfo, FC, PropsWithChildren, ReactNode } from "react";
11
- import { ServerRouteCache } from "@alepha/server-cache";
12
- import * as react_jsx_runtime0 from "react/jsx-runtime";
11
+ import * as react_jsx_runtime1 from "react/jsx-runtime";
13
12
  import { ServerStaticProvider } from "@alepha/server-static";
14
13
 
15
14
  //#region src/components/ClientOnly.d.ts
@@ -40,9 +39,217 @@ declare class Redirection extends Error {
40
39
  constructor(redirect: string);
41
40
  }
42
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
43
165
  //#region src/descriptors/$page.d.ts
44
166
  /**
45
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
+ * ```
46
253
  */
47
254
  declare const $page: {
48
255
  <TConfig extends PageConfigSchema = PageConfigSchema, TProps extends object = any, TPropsParent extends object = TPropsParentDefault>(options: PageDescriptorOptions<TConfig, TProps, TPropsParent>): PageDescriptor<TConfig, TProps, TPropsParent>;
@@ -177,6 +384,49 @@ interface PageDescriptorOptions<TConfig extends PageConfigSchema = PageConfigSch
177
384
  * Called when user leaves the page. (browser only)
178
385
  */
179
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;
180
430
  }
181
431
  type ErrorHandler = (error: Error, state: ReactRouterState) => ReactNode | Redirection | undefined;
182
432
  declare class PageDescriptor<TConfig extends PageConfigSchema = PageConfigSchema, TProps extends object = TPropsDefault, TPropsParent extends object = TPropsParentDefault> extends Descriptor<PageDescriptorOptions<TConfig, TProps, TPropsParent>> {
@@ -187,6 +437,10 @@ declare class PageDescriptor<TConfig extends PageConfigSchema = PageConfigSchema
187
437
  * Only valid for server-side rendering, it will throw an error if called on the client-side.
188
438
  */
189
439
  render(options?: PageDescriptorRenderOptions): Promise<PageDescriptorRenderResult>;
440
+ fetch(options?: PageDescriptorRenderOptions): Promise<{
441
+ html: string;
442
+ response: Response;
443
+ }>;
190
444
  match(url: string): boolean;
191
445
  pathname(config: any): string;
192
446
  }
@@ -199,136 +453,36 @@ type TPropsParentDefault = {};
199
453
  interface PageDescriptorRenderOptions {
200
454
  params?: Record<string, string>;
201
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
+ */
202
462
  html?: boolean;
203
463
  hydration?: boolean;
204
464
  }
205
465
  interface PageDescriptorRenderResult {
206
466
  html: string;
207
467
  state: ReactRouterState;
468
+ redirect?: string;
208
469
  }
209
470
  interface PageRequestConfig<TConfig extends PageConfigSchema = PageConfigSchema> {
210
471
  params: TConfig["params"] extends TSchema ? Static<TConfig["params"]> : Record<string, string>;
211
472
  query: TConfig["query"] extends TSchema ? Static<TConfig["query"]> : Record<string, string>;
212
473
  }
213
474
  type PageResolve<TConfig extends PageConfigSchema = PageConfigSchema, TPropsParent extends object = TPropsParentDefault> = PageRequestConfig<TConfig> & TPropsParent & Omit<ReactRouterState, "layers" | "onError">;
214
- //#endregion
215
- //#region src/providers/ReactPageProvider.d.ts
216
- declare const envSchema$2: _alepha_core14.TObject<{
217
- REACT_STRICT_MODE: _alepha_core14.TBoolean;
218
- }>;
219
- declare module "@alepha/core" {
220
- interface Env extends Partial<Static<typeof envSchema$2>> {}
221
- }
222
- declare class ReactPageProvider {
223
- protected readonly log: _alepha_logger1.Logger;
224
- protected readonly env: {
225
- REACT_STRICT_MODE: boolean;
226
- };
227
- protected readonly alepha: Alepha;
228
- protected readonly pages: PageRoute[];
229
- getPages(): PageRoute[];
230
- page(name: string): PageRoute;
231
- pathname(name: string, options?: {
232
- params?: Record<string, string>;
233
- query?: Record<string, string>;
234
- }): string;
235
- url(name: string, options?: {
236
- params?: Record<string, string>;
237
- host?: string;
238
- }): URL;
239
- root(state: ReactRouterState): ReactNode;
240
- /**
241
- * Create a new RouterState based on a given route and request.
242
- * This method resolves the layers for the route, applying any query and params schemas defined in the route.
243
- * It also handles errors and redirects.
244
- */
245
- createLayers(route: PageRoute, state: ReactRouterState, previous?: PreviousLayerData[]): Promise<CreateLayersResult>;
246
- protected createRedirectionLayer(redirect: string): CreateLayersResult;
247
- protected getErrorHandler(route: PageRoute): ErrorHandler | undefined;
248
- protected createElement(page: PageRoute, props: Record<string, any>): Promise<ReactNode>;
249
- renderError(error: Error): ReactNode;
250
- renderEmptyView(): ReactNode;
251
- href(page: {
252
- options: {
253
- name?: string;
254
- };
255
- }, params?: Record<string, any>): string;
256
- compile(path: string, params?: Record<string, string>): string;
257
- protected renderView(index: number, path: string, view: ReactNode | undefined, page: PageRoute): ReactNode;
258
- protected readonly configure: _alepha_core14.HookDescriptor<"configure">;
259
- protected map(pages: Array<PageDescriptor>, target: PageDescriptor): PageRouteEntry;
260
- add(entry: PageRouteEntry): void;
261
- protected createMatch(page: PageRoute): string;
262
- protected _next: number;
263
- protected nextId(): string;
264
- }
265
- declare const isPageRoute: (it: any) => it is PageRoute;
266
- interface PageRouteEntry extends Omit<PageDescriptorOptions, "children" | "parent"> {
267
- children?: PageRouteEntry[];
268
- }
269
- interface PageRoute extends PageRouteEntry {
270
- type: "page";
271
- name: string;
272
- parent?: PageRoute;
273
- match: string;
274
- }
275
- interface Layer {
276
- config?: {
277
- query?: Record<string, any>;
278
- params?: Record<string, any>;
279
- context?: Record<string, any>;
280
- };
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 = {
281
482
  name: string;
282
- props?: Record<string, any>;
283
- error?: Error;
284
- part?: string;
285
- element: ReactNode;
286
- index: number;
287
- path: string;
288
- route?: PageRoute;
289
- cache?: boolean;
290
- }
291
- type PreviousLayerData = Omit<Layer, "element" | "index" | "path">;
292
- interface AnchorProps {
293
- href: string;
294
- onClick: (ev?: any) => any;
295
- }
296
- interface ReactRouterState {
297
- /**
298
- * Stack of layers for the current page.
299
- */
300
- layers: Array<Layer>;
301
- /**
302
- * URL of the current page.
303
- */
304
- url: URL;
305
- /**
306
- * Error handler for the current page.
307
- */
308
- onError: ErrorHandler;
309
- /**
310
- * Params extracted from the URL for the current page.
311
- */
312
- params: Record<string, any>;
313
- /**
314
- * Query parameters extracted from the URL for the current page.
315
- */
316
- query: Record<string, string>;
317
- }
318
- interface RouterStackItem {
319
- route: PageRoute;
320
- config?: Record<string, any>;
321
- props?: Record<string, any>;
322
- error?: Error;
323
- cache?: boolean;
324
- }
325
- interface TransitionOptions {
326
- previous?: PreviousLayerData[];
327
- }
328
- interface CreateLayersResult {
329
- redirect?: string;
330
- state?: ReactRouterState;
331
- }
483
+ duration?: number;
484
+ timing?: string;
485
+ };
332
486
  //#endregion
333
487
  //#region src/providers/ReactBrowserRouterProvider.d.ts
334
488
  interface BrowserRoute extends Route {
@@ -340,7 +494,7 @@ declare class ReactBrowserRouterProvider extends RouterProvider<BrowserRoute> {
340
494
  protected readonly pageApi: ReactPageProvider;
341
495
  add(entry: PageRouteEntry): void;
342
496
  protected readonly configure: _alepha_core14.HookDescriptor<"configure">;
343
- transition(url: URL, previous?: PreviousLayerData[]): Promise<string | void>;
497
+ transition(url: URL, previous?: PreviousLayerData[], meta?: {}): Promise<string | void>;
344
498
  root(state: ReactRouterState): ReactNode;
345
499
  }
346
500
  //#endregion
@@ -363,7 +517,6 @@ declare class ReactBrowserProvider {
363
517
  protected readonly alepha: Alepha;
364
518
  protected readonly router: ReactBrowserRouterProvider;
365
519
  protected readonly dateTimeProvider: DateTimeProvider;
366
- protected root?: Root;
367
520
  options: ReactBrowserRendererOptions;
368
521
  protected getRootElement(): HTMLElement;
369
522
  transitioning?: {
@@ -388,10 +541,7 @@ declare class ReactBrowserProvider {
388
541
  pushState(path: string, replace?: boolean): void;
389
542
  invalidate(props?: Record<string, any>): Promise<void>;
390
543
  go(url: string, options?: RouterGoOptions): Promise<void>;
391
- protected render(options?: {
392
- url?: string;
393
- previous?: PreviousLayerData[];
394
- }): Promise<void>;
544
+ protected render(options?: RouterRenderOptions): Promise<void>;
395
545
  /**
396
546
  * Get embedded layers from the server.
397
547
  */
@@ -404,6 +554,7 @@ interface RouterGoOptions {
404
554
  match?: TransitionOptions;
405
555
  params?: Record<string, string>;
406
556
  query?: Record<string, string>;
557
+ meta?: Record<string, any>;
407
558
  /**
408
559
  * Recreate the whole page, ignoring the current state.
409
560
  */
@@ -414,6 +565,11 @@ type ReactHydrationState = {
414
565
  } & {
415
566
  [key: string]: any;
416
567
  };
568
+ interface RouterRenderOptions {
569
+ url?: string;
570
+ previous?: PreviousLayerData[];
571
+ meta?: Record<string, any>;
572
+ }
417
573
  //#endregion
418
574
  //#region src/components/ErrorBoundary.d.ts
419
575
  /**
@@ -463,46 +619,25 @@ interface ErrorViewerProps {
463
619
  declare const ErrorViewer: ({
464
620
  error,
465
621
  alepha
466
- }: ErrorViewerProps) => react_jsx_runtime0.JSX.Element;
622
+ }: ErrorViewerProps) => react_jsx_runtime1.JSX.Element;
467
623
  //#endregion
468
624
  //#region src/components/Link.d.ts
469
625
  interface LinkProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
470
- to: string;
471
- children?: React.ReactNode;
626
+ href: string;
472
627
  }
473
- declare const Link: (props: LinkProps) => react_jsx_runtime0.JSX.Element;
628
+ declare const Link: (props: LinkProps) => react_jsx_runtime1.JSX.Element;
474
629
  //#endregion
475
630
  //#region src/components/NestedView.d.ts
476
631
  interface NestedViewProps {
477
632
  children?: ReactNode;
633
+ errorBoundary?: false | ((error: Error) => ReactNode);
478
634
  }
479
- /**
480
- * A component that renders the current view of the nested router layer.
481
- *
482
- * To be simple, it renders the `element` of the current child page of a parent page.
483
- *
484
- * @example
485
- * ```tsx
486
- * import { NestedView } from "@alepha/react";
487
- *
488
- * class App {
489
- * parent = $page({
490
- * component: () => <NestedView />,
491
- * });
492
- *
493
- * child = $page({
494
- * parent: this.root,
495
- * component: () => <div>Child Page</div>,
496
- * });
497
- * }
498
- * ```
499
- */
500
- declare const NestedView: (props: NestedViewProps) => react_jsx_runtime0.JSX.Element;
635
+ declare const _default: react0.MemoExoticComponent<(props: NestedViewProps) => react_jsx_runtime1.JSX.Element>;
501
636
  //#endregion
502
637
  //#region src/components/NotFound.d.ts
503
638
  declare function NotFoundPage(props: {
504
639
  style?: CSSProperties;
505
- }): react_jsx_runtime0.JSX.Element;
640
+ }): react_jsx_runtime1.JSX.Element;
506
641
  //#endregion
507
642
  //#region src/contexts/AlephaContext.d.ts
508
643
  declare const AlephaContext: react0.Context<Alepha | undefined>;
@@ -524,7 +659,6 @@ interface UseActiveHook {
524
659
  isActive: boolean;
525
660
  anchorProps: AnchorProps;
526
661
  isPending: boolean;
527
- name?: string;
528
662
  }
529
663
  //#endregion
530
664
  //#region src/hooks/useAlepha.d.ts
@@ -537,7 +671,7 @@ interface UseActiveHook {
537
671
  *
538
672
  * - alepha.state() for state management
539
673
  * - alepha.inject() for dependency injection
540
- * - alepha.emit() for event handling
674
+ * - alepha.events.emit() for event handling
541
675
  * etc...
542
676
  */
543
677
  declare const useAlepha: () => Alepha;
@@ -561,7 +695,7 @@ declare const useInject: <T extends object>(service: Service<T>) => T;
561
695
  /**
562
696
  * Not well tested. Use with caution.
563
697
  */
564
- declare const useQueryParams: <T extends TObject>(schema: T, options?: UseQueryParamsHookOptions) => [Static<T>, (data: Static<T>) => void];
698
+ declare const useQueryParams: <T extends TObject>(schema: T, options?: UseQueryParamsHookOptions) => [Partial<Static<T>>, (data: Static<T>) => void];
565
699
  interface UseQueryParamsHookOptions {
566
700
  format?: "base64" | "querystring";
567
701
  key?: string;
@@ -576,8 +710,8 @@ declare class ReactRouter<T extends object> {
576
710
  get pages(): PageRoute[];
577
711
  get browser(): ReactBrowserProvider | undefined;
578
712
  path(name: keyof VirtualRouter<T>, config?: {
579
- params?: Record<string, string>;
580
- query?: Record<string, string>;
713
+ params?: Record<string, any>;
714
+ query?: Record<string, any>;
581
715
  }): string;
582
716
  getURL(): URL;
583
717
  get location(): Location;
@@ -589,12 +723,8 @@ declare class ReactRouter<T extends object> {
589
723
  invalidate(props?: Record<string, any>): Promise<void>;
590
724
  go(path: string, options?: RouterGoOptions): Promise<void>;
591
725
  go(path: keyof VirtualRouter<T>, options?: RouterGoOptions): Promise<void>;
592
- anchor(path: string, options?: {
593
- params?: Record<string, any>;
594
- }): AnchorProps;
595
- anchor(path: keyof VirtualRouter<T>, options?: {
596
- params?: Record<string, any>;
597
- }): AnchorProps;
726
+ anchor(path: string, options?: RouterGoOptions): AnchorProps;
727
+ anchor(path: keyof VirtualRouter<T>, options?: RouterGoOptions): AnchorProps;
598
728
  base(path: string): string;
599
729
  /**
600
730
  * Set query params.
@@ -629,20 +759,18 @@ type VirtualRouter<T> = { [K in keyof T as T[K] extends PageDescriptor ? K : nev
629
759
  declare const useRouter: <T extends object = any>() => ReactRouter<T>;
630
760
  //#endregion
631
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
+ };
632
766
  /**
633
767
  * Subscribe to various router events.
634
768
  */
635
769
  declare const useRouterEvents: (opts?: {
636
- onBegin?: (ev: {
637
- state: ReactRouterState;
638
- }) => void;
639
- onEnd?: (ev: {
640
- state: ReactRouterState;
641
- }) => void;
642
- onError?: (ev: {
643
- state: ReactRouterState;
644
- error: Error;
645
- }) => void;
770
+ onBegin?: Hook<"react:transition:begin">;
771
+ onError?: Hook<"react:transition:error">;
772
+ onEnd?: Hook<"react:transition:end">;
773
+ onSuccess?: Hook<"react:transition:success">;
646
774
  }, deps?: any[]) => void;
647
775
  //#endregion
648
776
  //#region src/hooks/useRouterState.d.ts
@@ -684,6 +812,7 @@ declare class ReactServerProvider {
684
812
  protected readonly log: _alepha_logger1.Logger;
685
813
  protected readonly alepha: Alepha;
686
814
  protected readonly pageApi: ReactPageProvider;
815
+ protected readonly serverProvider: ServerProvider;
687
816
  protected readonly serverStaticProvider: ServerStaticProvider;
688
817
  protected readonly serverRouterProvider: ServerRouterProvider;
689
818
  protected readonly serverTimingProvider: ServerTimingProvider;
@@ -695,6 +824,7 @@ declare class ReactServerProvider {
695
824
  REACT_ROOT_ID: string;
696
825
  };
697
826
  protected readonly ROOT_DIV_REGEX: RegExp;
827
+ protected preprocessedTemplate: PreprocessedTemplate | null;
698
828
  readonly onConfigure: _alepha_core14.HookDescriptor<"configure">;
699
829
  get template(): string;
700
830
  protected registerPages(templateLoader: TemplateLoader): Promise<void>;
@@ -704,17 +834,21 @@ declare class ReactServerProvider {
704
834
  /**
705
835
  * For testing purposes, creates a render function that can be used.
706
836
  */
707
- protected createRenderFunction(name: string, withIndex?: boolean): (options?: PageDescriptorRenderOptions) => Promise<{
708
- state: ReactRouterState;
709
- html: string;
710
- }>;
837
+ protected createRenderFunction(name: string, withIndex?: boolean): (options?: PageDescriptorRenderOptions) => Promise<PageDescriptorRenderResult>;
711
838
  protected createHandler(route: PageRoute, templateLoader: TemplateLoader): ServerHandler;
712
839
  renderToHtml(template: string, state: ReactRouterState, hydration?: boolean): string | Redirection;
840
+ protected preprocessTemplate(template: string): PreprocessedTemplate;
713
841
  protected fillTemplate(response: {
714
842
  html: string;
715
843
  }, app: string, script: string): void;
716
844
  }
717
845
  type TemplateLoader = () => Promise<string | undefined>;
846
+ interface PreprocessedTemplate {
847
+ beforeApp: string;
848
+ afterApp: string;
849
+ beforeScript: string;
850
+ afterScript: string;
851
+ }
718
852
  //#endregion
719
853
  //#region src/index.d.ts
720
854
  declare module "@alepha/core" {
@@ -732,11 +866,15 @@ declare module "@alepha/core" {
732
866
  html: string;
733
867
  };
734
868
  "react:browser:render": {
869
+ root: HTMLDivElement;
870
+ element: ReactNode;
735
871
  state: ReactRouterState;
736
872
  hydration?: ReactHydrationState;
737
873
  };
738
874
  "react:transition:begin": {
875
+ previous: ReactRouterState;
739
876
  state: ReactRouterState;
877
+ animation?: PageAnimation;
740
878
  };
741
879
  "react:transition:success": {
742
880
  state: ReactRouterState;
@@ -762,5 +900,5 @@ declare module "@alepha/core" {
762
900
  */
763
901
  declare const AlephaReact: _alepha_core14.Service<_alepha_core14.Module>;
764
902
  //#endregion
765
- export { $page, AlephaContext, AlephaReact, AnchorProps, ClientOnly, CreateLayersResult, ErrorBoundary, ErrorHandler, ErrorViewer, Layer, Link, LinkProps, NestedView, NotFoundPage as NotFound, PageConfigSchema, PageDescriptor, PageDescriptorOptions, PageDescriptorRenderOptions, PageDescriptorRenderResult, PageRequestConfig, PageResolve, PageRoute, PageRouteEntry, PreviousLayerData, ReactBrowserProvider, ReactBrowserRendererOptions, ReactHydrationState, ReactPageProvider, ReactRouter, ReactRouterState, ReactServerProvider, Redirection, RouterGoOptions, RouterLayerContext, RouterLayerContextValue, RouterStackItem, TPropsDefault, TPropsParentDefault, TransitionOptions, UseActiveHook, UseActiveOptions, UseQueryParamsHookOptions, UseSchemaReturn, VirtualRouter, isPageRoute, ssrSchemaLoading, useActive, useAlepha, useClient, useInject, useQueryParams, useRouter, useRouterEvents, useRouterState, useSchema, useStore };
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 };
766
904
  //# sourceMappingURL=index.d.cts.map