@stone-js/use-react 0.1.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.
@@ -0,0 +1,1566 @@
1
+ import { HTMLMetaDescriptor, HeadContext as HeadContext$1, FunctionalEventHandler, Route, Router, DecoratorPageRouteDefinition, NavigateOptions } from '@stone-js/router';
2
+ import * as react from 'react';
3
+ import { ReactNode, ElementType, FunctionComponent } from 'react';
4
+ import { Config } from '@stone-js/config';
5
+ import { BrowserEvent, BrowserResponse, BrowserContext, BrowserAdapterResponseBuilder } from '@stone-js/browser-adapter';
6
+ import { IncomingHttpEvent, OutgoingHttpResponse, RedirectResponse, IncomingHttpEventOptions, OutgoingHttpResponseOptions, RedirectResponseOptions } from '@stone-js/http-core';
7
+ import { IncomingBrowserEvent, OutgoingBrowserResponse, RedirectBrowserResponse, IncomingBrowserEventOptions, OutgoingBrowserResponseOptions, RedirectBrowserResponseOptions } from '@stone-js/browser-core';
8
+ import { IContainer, Promiseable, Laziable, FunctionalErrorHandler, IBlueprint, FunctionalAdapterErrorHandler, OutgoingResponseOptions, HookName as HookName$1, LifecycleHookType, ErrorHandlerOptions, AdapterErrorHandlerOptions, AdapterContext, IAdapterErrorHandler, AdapterErrorContext, AdapterEventBuilderType, IEventHandler, IErrorHandler, ILogger, IServiceProvider, StoneBlueprint, AppConfig, ClassType, InitializationError, ErrorOptions, BlueprintContext, NextMiddleware, MetaMiddleware } from '@stone-js/core';
9
+ import { Root } from 'react-dom/client';
10
+
11
+ /**
12
+ * Stone DOM Attribute.
13
+ */
14
+ declare const STONE_DOM_ATTR = "data-stone-head";
15
+ /**
16
+ * Apply meta tags to the document document.head.
17
+ *
18
+ * @param document - The document object.
19
+ * @param meta - The meta tag descriptor.
20
+ */
21
+ declare const applyMeta: (document: Document, meta: HTMLMetaDescriptor) => void;
22
+ /**
23
+ * Apply the head context to the document document.head.
24
+ *
25
+ * @param document - The document object.
26
+ * @param context - The head context containing meta, link, script, and style descriptors.
27
+ */
28
+ declare const applyHeadContextToDom: (document: Document, context: HeadContext$1) => void;
29
+ /**
30
+ * Escape HTML special characters in a string.
31
+ *
32
+ * @param context - The head context containing meta, link, script, and style descriptors.
33
+ * @param html - The HTML string to escape.
34
+ * @returns The escaped string.
35
+ */
36
+ declare const applyHeadContextToHtmlString: (context: HeadContext$1, html: string) => string;
37
+
38
+ /**
39
+ * The type representing the Head Context for React.
40
+ * It extends the BaseHeadContext to include additional properties specific to React.
41
+ * This type is used to manage the head elements of a React application.
42
+ */
43
+ type HeadContext = HeadContext$1;
44
+ /**
45
+ * The type representing a Snapshot.
46
+ * An object that represents the state of the application at a given time.
47
+ */
48
+ type ISnapshot = Config;
49
+ /**
50
+ * Route for React.
51
+ */
52
+ type IRoute = Route<ReactIncomingEvent, ReactOutgoingResponse>;
53
+ /**
54
+ * Router for React.
55
+ */
56
+ type IRouter = Router<ReactIncomingEvent, ReactOutgoingResponse>;
57
+ /**
58
+ * Headers type for React.
59
+ */
60
+ type HeadersType = Headers | Map<string, string | string[]> | Record<string, string | string[]>;
61
+ /**
62
+ * Incoming event for React.
63
+ */
64
+ type ReactIncomingEvent = IncomingHttpEvent | IncomingBrowserEvent;
65
+ /**
66
+ * Incoming event options for React.
67
+ */
68
+ type ReactIncomingEventOptions = IncomingBrowserEventOptions | IncomingHttpEventOptions;
69
+ /**
70
+ * Outgoing response for React.
71
+ */
72
+ type ReactOutgoingResponse = (OutgoingHttpResponse | OutgoingBrowserResponse | RedirectResponse | RedirectBrowserResponse) & {
73
+ content: any;
74
+ };
75
+ /**
76
+ * Options for creating a React Outgoing Response.
77
+ */
78
+ interface ReactOutgoingResponseOptions extends OutgoingResponseOptions {
79
+ headers?: HeadersType;
80
+ }
81
+ /**
82
+ * UseReactHookName Type.
83
+ */
84
+ type UseReactHookName = 'onPreparingPage';
85
+ /**
86
+ * HookName Type.
87
+ *
88
+ * extends Core HookName.
89
+ */
90
+ type HookName = HookName$1 | UseReactHookName;
91
+ /**
92
+ * Use React Hook Listener Context.
93
+ */
94
+ interface UseReactHookListenerContext {
95
+ data: any;
96
+ error?: any;
97
+ head?: HeadContext;
98
+ container: IContainer;
99
+ componentType: unknown;
100
+ event: ReactIncomingEvent;
101
+ snapshot: ResponseSnapshotType;
102
+ response: ReactOutgoingResponse;
103
+ }
104
+ /**
105
+ * UseReactHookListener Type.
106
+ *
107
+ * Represents a listener hook that can either be synchronous or asynchronous.
108
+ */
109
+ type UseReactHookListener = (context: UseReactHookListenerContext) => Promiseable<void>;
110
+ /**
111
+ * UseReactHook Type.
112
+ */
113
+ interface UseReactHookType {
114
+ onPreparingPage?: UseReactHookListener[];
115
+ }
116
+ /**
117
+ * ReactLifecycleHookType Type.
118
+ */
119
+ type ReactLifecycleHookType = LifecycleHookType<IBlueprint, any, any, ReactIncomingEvent, any> & UseReactHookType;
120
+ /**
121
+ * Options for configuring the `Page` decorator.
122
+ * Extends `PageRouteDefinition` but excludes the `methods` property,
123
+ * as it is predefined as `'GET'` by the decorator.
124
+ */
125
+ interface PageOptions extends DecoratorPageRouteDefinition {
126
+ layout?: string;
127
+ headers?: HeadersType;
128
+ }
129
+ /**
130
+ * Options for configuring the `PageLayout` decorator.
131
+ */
132
+ interface PageLayoutOptions {
133
+ name?: 'default' | string;
134
+ }
135
+ /**
136
+ * Options for configuring the `ErrorPage` decorator.
137
+ */
138
+ interface ErrorPageOptions extends ErrorHandlerOptions {
139
+ layout?: string;
140
+ }
141
+ /**
142
+ * Options for configuring the `AdapterErrorPage` decorator.
143
+ */
144
+ interface AdapterErrorPageOptions extends AdapterErrorHandlerOptions {
145
+ layout?: string;
146
+ }
147
+ /**
148
+ * Browser Adapter Context for React.
149
+ */
150
+ type ReactBrowserAdapterContext = AdapterContext<BrowserEvent, BrowserResponse, BrowserContext, IncomingBrowserEvent, IncomingBrowserEventOptions, OutgoingBrowserResponse>;
151
+ /**
152
+ * Stone data snapshot type.
153
+ */
154
+ interface ResponseSnapshotType {
155
+ data?: any;
156
+ error?: any;
157
+ ssr: boolean;
158
+ layout?: unknown;
159
+ statusCode?: number;
160
+ }
161
+ /**
162
+ * Browser response content for React.
163
+ */
164
+ interface BrowserResponseContent {
165
+ ssr?: boolean;
166
+ app?: ReactNode;
167
+ head?: HeadContext;
168
+ fullRender?: boolean;
169
+ component?: ReactNode;
170
+ targetUrl?: string | URL;
171
+ }
172
+ /**
173
+ * Context for React.
174
+ */
175
+ interface StoneContextType {
176
+ data: any;
177
+ container: IContainer;
178
+ event: ReactIncomingEvent;
179
+ }
180
+ /**
181
+ * React page render context.
182
+ */
183
+ interface PageRenderContext<TData = any> {
184
+ data?: TData;
185
+ statusCode?: number;
186
+ container: IContainer;
187
+ event: ReactIncomingEvent;
188
+ }
189
+ /**
190
+ * React page head context.
191
+ */
192
+ interface PageHeadContext<TData = any> {
193
+ data?: TData;
194
+ statusCode?: number;
195
+ event: ReactIncomingEvent;
196
+ }
197
+ /**
198
+ * Represents a page class.
199
+ *
200
+ * @template IncomingEventType - The type representing the incoming event.
201
+ * @template OutgoingResponseType - The type representing the outgoing response.
202
+ */
203
+ type PageClass<IncomingEventType extends ReactIncomingEvent, OutgoingResponseType = unknown> = new (...args: any[]) => IPage<IncomingEventType, OutgoingResponseType>;
204
+ /**
205
+ * Represents a page.
206
+ *
207
+ * @template IncomingEventType - The type representing the incoming event.
208
+ * @template OutgoingResponseType - The type representing the outgoing response.
209
+ */
210
+ interface IPage<IncomingEventType extends ReactIncomingEvent, OutgoingResponseType = unknown> {
211
+ render: (context: PageRenderContext<any>) => ReactNode;
212
+ handle?: FunctionalEventHandler<IncomingEventType, OutgoingResponseType>;
213
+ head?: (context: PageHeadContext<any>) => Promiseable<HeadContext>;
214
+ }
215
+ /**
216
+ * Represents a factory page.
217
+ *
218
+ * @template IncomingEventType - The type representing the incoming event.
219
+ * @template OutgoingResponseType - The type representing the outgoing response.
220
+ */
221
+ type FactoryPage<IncomingEventType extends ReactIncomingEvent, OutgoingResponseType = unknown> = (container?: IContainer | any) => IPage<IncomingEventType, OutgoingResponseType>;
222
+ /**
223
+ * Represents a page type.
224
+ *
225
+ * @template IncomingEventType - The type representing the incoming event.
226
+ * @template OutgoingResponseType - The type representing the outgoing response.
227
+ */
228
+ type PageType<IncomingEventType extends ReactIncomingEvent, OutgoingResponseType = unknown> = PageClass<IncomingEventType, OutgoingResponseType> | FactoryPage<IncomingEventType, OutgoingResponseType>;
229
+ /**
230
+ * Represents a meta page.
231
+ *
232
+ * @template IncomingEventType - The type representing the incoming event.
233
+ * @template OutgoingResponseType - The type representing the outgoing response.
234
+ */
235
+ interface MetaPage<IncomingEventType extends ReactIncomingEvent, OutgoingResponseType = unknown> {
236
+ lazy?: boolean;
237
+ layout?: unknown;
238
+ isClass?: boolean;
239
+ isFactory?: boolean;
240
+ isComponent?: boolean;
241
+ module: PageType<IncomingEventType, OutgoingResponseType> | Laziable<PageType<IncomingEventType, OutgoingResponseType>>;
242
+ }
243
+ /**
244
+ * React render page layout options.
245
+ */
246
+ interface PageLayoutRenderContext {
247
+ children: ReactNode;
248
+ container: IContainer;
249
+ }
250
+ /**
251
+ * React render page layout options.
252
+ */
253
+ interface AdapterPageLayoutRenderContext {
254
+ children: ReactNode;
255
+ blueprint: IBlueprint;
256
+ }
257
+ /**
258
+ * Represents a Page layout class.
259
+ */
260
+ type PageLayoutClass = new (...args: any[]) => IPageLayout;
261
+ /**
262
+ * Represents a Page layout.
263
+ */
264
+ interface IPageLayout {
265
+ head?: () => Promiseable<HeadContext>;
266
+ render: (context: PageLayoutRenderContext | AdapterPageLayoutRenderContext | any) => ReactNode;
267
+ }
268
+ /**
269
+ * Represents a factory page layout.
270
+ */
271
+ type FactoryPageLayout = (container?: IContainer | any) => IPageLayout;
272
+ /**
273
+ * Represents a page layout type.
274
+ */
275
+ type PageLayoutType = PageLayoutClass | FactoryPageLayout;
276
+ /**
277
+ * Represents a meta page layout.
278
+ */
279
+ interface MetaPageLayout {
280
+ lazy?: boolean;
281
+ isClass?: boolean;
282
+ isFactory?: boolean;
283
+ module: PageLayoutType | Laziable<PageLayoutType>;
284
+ }
285
+ /**
286
+ * React error page render context.
287
+ */
288
+ interface ErrorPageRenderContext<TError = any, UData = any> extends PageRenderContext<UData> {
289
+ error: TError;
290
+ }
291
+ /**
292
+ * React error page head context.
293
+ */
294
+ interface ErrorPageHeadContext<TError = any, UData = any> extends PageHeadContext<UData> {
295
+ error: TError;
296
+ }
297
+ /**
298
+ * Represents an error page class.
299
+ *
300
+ * @template IncomingEventType - The type representing the incoming event.
301
+ * @template OutgoingResponseType - The type representing the outgoing response.
302
+ */
303
+ type ErrorPageClass<IncomingEventType extends ReactIncomingEvent, OutgoingResponseType = unknown> = new (...args: any[]) => IErrorPage<IncomingEventType, OutgoingResponseType>;
304
+ /**
305
+ * Represents an error page.
306
+ *
307
+ * @template IncomingEventType - The type representing the incoming event.
308
+ * @template OutgoingResponseType - The type representing the outgoing response.
309
+ */
310
+ interface IErrorPage<IncomingEventType extends ReactIncomingEvent, OutgoingResponseType = unknown> {
311
+ handle?: FunctionalErrorHandler<IncomingEventType, OutgoingResponseType>;
312
+ render: (context: ErrorPageRenderContext<any, any>) => ReactNode;
313
+ head?: (context: ErrorPageHeadContext<any, any>) => Promiseable<HeadContext>;
314
+ }
315
+ /**
316
+ * Represents a factory error page.
317
+ *
318
+ * @template IncomingEventType - The type representing the incoming event.
319
+ * @template OutgoingResponseType - The type representing the outgoing response.
320
+ */
321
+ type FactoryErrorPage<IncomingEventType extends ReactIncomingEvent, OutgoingResponseType = unknown> = (container?: IContainer | any) => IErrorPage<IncomingEventType, OutgoingResponseType>;
322
+ /**
323
+ * Represents an error page type.
324
+ *
325
+ * @template IncomingEventType - The type representing the incoming event.
326
+ * @template OutgoingResponseType - The type representing the outgoing response.
327
+ */
328
+ type ErrorPageType<IncomingEventType extends ReactIncomingEvent, OutgoingResponseType = unknown> = ErrorPageClass<IncomingEventType, OutgoingResponseType> | FactoryErrorPage<IncomingEventType, OutgoingResponseType>;
329
+ /**
330
+ * Represents a meta error page.
331
+ *
332
+ * @template IncomingEventType - The type representing the incoming event.
333
+ * @template OutgoingResponseType - The type representing the outgoing response.
334
+ */
335
+ interface MetaErrorPage<IncomingEventType extends ReactIncomingEvent, OutgoingResponseType = unknown> {
336
+ error?: any;
337
+ lazy?: boolean;
338
+ layout?: unknown;
339
+ isClass?: boolean;
340
+ isFactory?: boolean;
341
+ module: ErrorPageType<IncomingEventType, OutgoingResponseType> | Laziable<ErrorPageType<IncomingEventType, OutgoingResponseType>>;
342
+ }
343
+ /** ****** Adapter Error page *************/
344
+ /**
345
+ * React Adapter render page error options.
346
+ */
347
+ interface AdapterErrorPageRenderContext<TError = any> {
348
+ error: TError;
349
+ statusCode: number;
350
+ blueprint: IBlueprint;
351
+ }
352
+ /**
353
+ * Represents an Adapter component error handler class.
354
+ */
355
+ type AdapterErrorPageClass<RawEventType, RawResponseType, ExecutionContextType> = new (...args: any[]) => IAdapterErrorPage<RawEventType, RawResponseType, ExecutionContextType>;
356
+ /**
357
+ * Represents an Adapter component error handler.
358
+ */
359
+ interface IAdapterErrorPage<RawEventType, RawResponseType, ExecutionContextType> {
360
+ handle?: FunctionalAdapterErrorHandler<RawEventType, RawResponseType, ExecutionContextType>;
361
+ render: (context: AdapterErrorPageRenderContext<any>) => ReactNode;
362
+ }
363
+ /**
364
+ * Represents an Adapter factory component error handler.
365
+ */
366
+ type FactoryAdapterErrorPage<RawEventType, RawResponseType, ExecutionContextType> = (container?: IContainer | any) => IAdapterErrorPage<RawEventType, RawResponseType, ExecutionContextType>;
367
+ /**
368
+ * Represents an Adapter component error handler type.
369
+ */
370
+ type AdapterErrorPageType<RawEventType, RawResponseType, ExecutionContextType> = AdapterErrorPageClass<RawEventType, RawResponseType, ExecutionContextType> | FactoryAdapterErrorPage<RawEventType, RawResponseType, ExecutionContextType>;
371
+ /**
372
+ * Represents an Adapter meta component error handler.
373
+ */
374
+ interface MetaAdapterErrorPage<RawEventType, RawResponseType, ExecutionContextType> {
375
+ error?: any;
376
+ lazy?: boolean;
377
+ layout?: unknown;
378
+ platform?: string;
379
+ isClass?: boolean;
380
+ isFactory?: boolean;
381
+ adapterAlias?: string;
382
+ module: AdapterErrorPageType<RawEventType, RawResponseType, ExecutionContextType> | Laziable<AdapterErrorPageType<RawEventType, RawResponseType, ExecutionContextType>>;
383
+ }
384
+
385
+ /**
386
+ * ReactRuntimeOptions
387
+ */
388
+ interface ReactRuntimeOptions {
389
+ snapshot: ISnapshot;
390
+ blueprint: IBlueprint;
391
+ container: IContainer;
392
+ }
393
+ /**
394
+ * Class representing a ReactRuntime.
395
+ *
396
+ * This class is responsible for handling the React runtime environment,
397
+ * including create snapshots and managing errors.
398
+ */
399
+ declare class ReactRuntime {
400
+ private readonly _snapshot;
401
+ private readonly container;
402
+ private readonly blueprint;
403
+ /**
404
+ * The ReactRuntime instance.
405
+ *
406
+ * @type {ReactRuntime}
407
+ */
408
+ static instance?: ReactRuntime;
409
+ /**
410
+ * Create a ReactRuntime.
411
+ *
412
+ * @param options - ReactRuntime options.
413
+ */
414
+ constructor({ container, blueprint, snapshot }: ReactRuntimeOptions);
415
+ /**
416
+ * Create a snapshot.
417
+ *
418
+ * This method will create a snapshot of the current event.
419
+ * If the environment is server, it will create a snapshot.
420
+ * If the environment is client, it will return the snapshot.
421
+ *
422
+ * @param key - The key to store the snapshot.
423
+ * @param handler - The handler to create the snapshot.
424
+ * @returns The snapshot value.
425
+ */
426
+ snapshot<T>(key: string, handler: (container?: IContainer) => Promiseable<T>): Promise<T>;
427
+ /**
428
+ * Set html head tags.
429
+ *
430
+ * This method will set the head elements in the document.
431
+ *
432
+ * @param value - The head context to set.
433
+ */
434
+ head(value: HeadContext$1): void;
435
+ /**
436
+ * Throw an error.
437
+ *
438
+ * This method will handle the error and render the error component.
439
+ * If no error handler is found, the error will be thrown.
440
+ *
441
+ * @param error - The error to throw.
442
+ * @param statusCode - The status code to return.
443
+ * @returns void
444
+ * @throws error
445
+ */
446
+ throwError(error: any, statusCode?: number): Promise<void>;
447
+ /**
448
+ * Render an error component.
449
+ *
450
+ * This method will render the error component.
451
+ *
452
+ * @param error - The error to render.
453
+ * @param metavalue - The meta value to render.
454
+ * @param statusCode - The status code to return.
455
+ * @returns void
456
+ */
457
+ private renderErrorComponent;
458
+ }
459
+ /**
460
+ * MetaReactRuntime
461
+ */
462
+ declare const MetaReactRuntime: {
463
+ module: typeof ReactRuntime;
464
+ isClass: boolean;
465
+ alias: string;
466
+ singleton: boolean;
467
+ };
468
+
469
+ /**
470
+ * UseReactBrowserErrorHandler options.
471
+ */
472
+ interface UseReactBrowserErrorHandlerOptions {
473
+ blueprint: IBlueprint;
474
+ }
475
+ /**
476
+ * Class representing an UseReactBrowserErrorHandler.
477
+ *
478
+ * Adapter level error handler for React applications.
479
+ */
480
+ declare class UseReactBrowserErrorHandler implements IAdapterErrorHandler<unknown, unknown, unknown> {
481
+ private readonly logger;
482
+ private readonly blueprint;
483
+ /**
484
+ * Create an UseReactBrowserErrorHandler.
485
+ *
486
+ * @param options - UseReactBrowserErrorHandler options.
487
+ */
488
+ constructor({ blueprint }: UseReactBrowserErrorHandlerOptions);
489
+ /**
490
+ * Handle an error.
491
+ *
492
+ * @param error - The error to handle.
493
+ * @param context - The context of the adapter.
494
+ * @returns The raw response.
495
+ */
496
+ handle(error: any, context: AdapterErrorContext<unknown, unknown, unknown>): Promise<AdapterEventBuilderType<unknown>>;
497
+ /**
498
+ * Get the error body.
499
+ *
500
+ * @param error - The error to handle.
501
+ * @returns The error body.
502
+ */
503
+ private renderError;
504
+ }
505
+
506
+ /**
507
+ * Stone context.
508
+ * Usefull to pass data to the components.
509
+ */
510
+ declare const StoneContext: react.Context<StoneContextType>;
511
+
512
+ /**
513
+ * A useReact event handler for processing incoming events
514
+ * For single event handler.
515
+ *
516
+ * Multiple event handlers will be processed by the router.
517
+ *
518
+ * @template IncomingEventType - The type representing the incoming event.
519
+ * @template OutgoingResponseType - The type representing the outgoing response.
520
+ */
521
+ declare class UseReactEventHandler<IncomingEventType extends ReactIncomingEvent = ReactIncomingEvent> implements IEventHandler<IncomingEventType, MetaPage<IncomingEventType>> {
522
+ private readonly blueprint;
523
+ /**
524
+ * Constructs a `UseReactEventHandler` instance.
525
+ *
526
+ * @param options - The UseReactEventHandler options including blueprint.
527
+ */
528
+ constructor({ blueprint }: {
529
+ blueprint: IBlueprint;
530
+ });
531
+ /**
532
+ * Handle an incoming event.
533
+ *
534
+ * @returns The outgoing response.
535
+ */
536
+ handle(): MetaPage<IncomingEventType>;
537
+ /**
538
+ * Get the component event handler.
539
+ *
540
+ * @returns The component event handler.
541
+ * @throws {UseReactError} If the component event handler is missing.
542
+ */
543
+ private getComponentEventHandler;
544
+ }
545
+
546
+ /**
547
+ * UseReactError response type.
548
+ */
549
+ type UseReactErrorResponseType = Record<'content' | 'statusCode', Partial<MetaErrorPage<ReactIncomingEvent>> | number>;
550
+ /**
551
+ * Class representing an UseReactUseReactKernelErrorHandler.
552
+ *
553
+ * Kernel level error handler for React applications.
554
+ */
555
+ declare class UseReactKernelErrorHandler implements IErrorHandler<ReactIncomingEvent, UseReactErrorResponseType> {
556
+ private readonly blueprint;
557
+ /**
558
+ * Create an UseReactUseReactKernelErrorHandler.
559
+ *
560
+ * @param options - UseReactUseReactKernelErrorHandler options.
561
+ */
562
+ constructor({ blueprint }: {
563
+ blueprint: IBlueprint;
564
+ });
565
+ /**
566
+ * Handle an error.
567
+ *
568
+ * @param error - The error to handle.
569
+ * @returns The outgoing http response.
570
+ */
571
+ handle(error: any): UseReactErrorResponseType;
572
+ }
573
+
574
+ /**
575
+ * Options for onPreparingResponse hook.
576
+ */
577
+ interface OnPreparingResponseOptions {
578
+ container: IContainer;
579
+ event: IncomingBrowserEvent;
580
+ response: ReactOutgoingResponse;
581
+ }
582
+ /**
583
+ * Hook that runs just before preparing the response.
584
+ *
585
+ * @param context - The context of the hook.
586
+ */
587
+ declare function onPreparingResponse({ event, response, container }: OnPreparingResponseOptions): Promise<void>;
588
+
589
+ /**
590
+ * Build the React application for the current route.
591
+ * Or for the main handler if the route is not defined.
592
+ *
593
+ * @param event - ReactIncomingEvent
594
+ * @param container - Service Container
595
+ * @param component - The component response.
596
+ * @param layout - The layout response.
597
+ * @param data - The data to pass to the component.
598
+ * @returns The resolved ReactNode.
599
+ */
600
+ declare const buildAppComponent: (event: ReactIncomingEvent, container: IContainer, component?: ElementType, layout?: unknown, data?: any, statusCode?: number, error?: any) => Promise<ReactNode>;
601
+ /**
602
+ * Get response layout in the current route for mutli pages application.
603
+ * Or get it from the blueprint configuration for single page application.
604
+ * Or get the default layout defined by the user.
605
+ * If not defined, return undefined.
606
+ *
607
+ * @param container - Service Container.
608
+ * @param children - The children to render.
609
+ * @param layoutName - The layout name.
610
+ * @returns The resolved layout element.
611
+ */
612
+ declare const buildLayoutComponent: (container: IContainer, children: ReactNode, layoutName?: unknown) => Promise<ReactNode | undefined>;
613
+ /**
614
+ * Get response component in the current route.
615
+ * If not defined, return an empty object.
616
+ *
617
+ * @param event - ReactIncomingEvent
618
+ * @param container - Service Container
619
+ * @param component - The component response.
620
+ * @param data - The data to pass to the component.
621
+ * @param statusCode - The status code of the error.
622
+ * @param error - The error object.
623
+ * @returns The resolved component element.
624
+ */
625
+ declare const buildPageComponent: (event: ReactIncomingEvent, container: IContainer, component?: ElementType, data?: any, statusCode?: number, error?: any) => ReactNode;
626
+ /**
627
+ * Get adapter error component.
628
+ *
629
+ * This error handler is different from the kernel error handler.
630
+ * Because there is no container at adapter level.
631
+ *
632
+ * @param blueprint - The blueprint.
633
+ * @param context - The context of the adapter.
634
+ * @param statusCode - The status code of the error.
635
+ * @param error - The error object.
636
+ * @returns The resolved layout element.
637
+ */
638
+ declare const buildAdapterErrorComponent: <RawEventType, RawResponseType, ExecutionContextType>(blueprint: IBlueprint, context: AdapterErrorContext<RawEventType, RawResponseType, ExecutionContextType>, statusCode: number, error: any) => Promise<ReactNode | undefined>;
639
+ /**
640
+ * Resolve the event handler for the component.
641
+ *
642
+ * Can also resolve dynamically loaded components.
643
+ *
644
+ * @param container - The service container.
645
+ * @param metaComponent - The meta component event handler.
646
+ * @returns The resolved element type.
647
+ */
648
+ declare const resolveComponent: <T = IPage<ReactIncomingEvent> | IErrorPage<ReactIncomingEvent> | IPageLayout>(container: IContainer, metaComponent?: MetaPage<ReactIncomingEvent> | MetaErrorPage<ReactIncomingEvent> | MetaPageLayout) => Promise<T | undefined>;
649
+ /**
650
+ * Resolve lazy loaded components.
651
+ *
652
+ * @param metaComponent - The meta component event handler.
653
+ * @returns The resolved element type.
654
+ */
655
+ declare const resolveLazyComponent: (metaComponent?: MetaPageLayout | MetaPage<ReactIncomingEvent> | MetaErrorPage<ReactIncomingEvent> | MetaAdapterErrorPage<any, any, any>) => Promise<MetaPageLayout | MetaPage<ReactIncomingEvent> | MetaErrorPage<ReactIncomingEvent> | MetaAdapterErrorPage<any, any, any> | undefined>;
656
+ /**
657
+ * Get the root element to render the React components.
658
+ *
659
+ * @param blueprint - The blueprint.
660
+ * @returns The root element to render the React components.
661
+ * @throws {UseReactError} If the root container is not found.
662
+ */
663
+ declare const getAppRootElement: (blueprint: IBlueprint) => HTMLElement;
664
+ /**
665
+ * Renders the React app.
666
+ *
667
+ * @param app - The React app to render.
668
+ * @param blueprint - The blueprint.
669
+ * @returns The React root instance.
670
+ */
671
+ declare const renderReactApp: (app: ReactNode, blueprint: IBlueprint) => Root;
672
+ /**
673
+ * Hydrates the React app when SSR is enabled.
674
+ *
675
+ * @param app - The React app to hydrate.
676
+ * @param blueprint - The blueprint.
677
+ * @returns The React root instance.
678
+ */
679
+ declare const hydrateReactApp: (app: ReactNode, blueprint: IBlueprint) => Root;
680
+ /**
681
+ * Check if the current environment is the server.
682
+ *
683
+ * @returns True if the current environment is the server.
684
+ */
685
+ declare const isServer: () => boolean;
686
+ /**
687
+ * Check if the current environment is the client.
688
+ *
689
+ * @returns True if the current environment is the client.
690
+ */
691
+ declare const isClient: () => boolean;
692
+ /**
693
+ * Get the HTML template for the React application.
694
+ *
695
+ * @param blueprint - The blueprint.
696
+ * @returns The HTML template.
697
+ */
698
+ declare const htmlTemplate: (blueprint: IBlueprint) => string;
699
+ /**
700
+ * Determine if the application is running on the server side.
701
+ *
702
+ * @returns True if the application is running on the server side, false otherwise.
703
+ */
704
+ declare function isSSR(): boolean;
705
+ /**
706
+ * Execute the handler.
707
+ *
708
+ * This method will try to get data from the snapshot
709
+ * If the snapshot is not present, it will execute the handler.
710
+ * If the handler is not present, it will return undefined.
711
+ *
712
+ * @param response - The response object.
713
+ * @returns The data from the response.
714
+ */
715
+ declare function executeHandler(event: IncomingBrowserEvent, response: ReactOutgoingResponse, snapshot: ResponseSnapshotType, handler?: (IPage<IncomingBrowserEvent> | IErrorPage<IncomingBrowserEvent>), error?: any): Promise<any>;
716
+ /**
717
+ * Get the browser content.
718
+ *
719
+ * @param app - The app component to render.
720
+ * @param component - The component to render.
721
+ * @param layout - The layout to use.
722
+ * @param snapshot - The response snapshot.
723
+ * @param head - The head context.
724
+ * @returns The browser response content.
725
+ */
726
+ declare function getBrowserContent(app: ReactNode, component: ReactNode, layout: any, snapshot: ResponseSnapshotType, head?: HeadContext): BrowserResponseContent;
727
+ /**
728
+ * Get the server content.
729
+ *
730
+ * @param component - The React component to hydrate.
731
+ * @param data - The data to pass to the components.
732
+ * @param container - The service container.
733
+ * @param event - The incoming browser event.
734
+ * @param head - The head context.
735
+ * @returns A promise that resolves when the content is hydrated.
736
+ */
737
+ declare function getServerContent(component: ReactNode, data: Partial<ResponseSnapshotType>, container: IContainer, event: IncomingBrowserEvent, head?: HeadContext): Promise<string>;
738
+ /**
739
+ * Get the response snapshot.
740
+ *
741
+ * @param event - The incoming browser event.
742
+ * @returns The response snapshot.
743
+ */
744
+ declare function getResponseSnapshot(event: IncomingBrowserEvent, container: IContainer): ResponseSnapshotType;
745
+ /**
746
+ * Snapshot the response data.
747
+ *
748
+ * @param event - The incoming HTTP event.
749
+ * @param data - The data to snapshot.
750
+ */
751
+ declare function snapshotResponse(event: IncomingBrowserEvent, container: IContainer, data: Partial<ResponseSnapshotType>): string;
752
+ /**
753
+ * Render Stone snapshot.
754
+ *
755
+ * @param snapshot - The snapshot to render.
756
+ * @returns The script tag.
757
+ */
758
+ declare function renderStoneSnapshot(snapshot: string): string;
759
+ /**
760
+ * Execute hooks.
761
+ *
762
+ * @param name - The name of the hook.
763
+ * @param context - The context of the adapter.
764
+ */
765
+ declare function executeHooks(name: UseReactHookName, context: UseReactHookListenerContext): Promise<void>;
766
+
767
+ /**
768
+ * Prepare the page to render.
769
+ *
770
+ * Here we prepare the page to render by resolving
771
+ * the handler, handler the event, and rendering the component.
772
+ *
773
+ * @param event - The incoming HTTP event.
774
+ * @param response - The outgoing HTTP response.
775
+ * @param container - The service container.
776
+ * @param snapshot - The response snapshot.
777
+ */
778
+ declare function preparePage(event: IncomingBrowserEvent, response: ReactOutgoingResponse, container: IContainer, snapshot: ResponseSnapshotType): Promise<void>;
779
+ /**
780
+ * Prepare the error page to render.
781
+ *
782
+ * Error pages are prepared sepatately because their handler
783
+ * is different from the normal page handler.
784
+ * Their handler takes an error as the first argument and the event as the second.
785
+ *
786
+ * @param event - The incoming HTTP event.
787
+ * @param response - The outgoing HTTP response.
788
+ * @param container - The service container.
789
+ * @param snapshot - The response snapshot.
790
+ */
791
+ declare function prepareErrorPage(event: IncomingBrowserEvent, response: ReactOutgoingResponse, container: IContainer, snapshot: ResponseSnapshotType): Promise<void>;
792
+ /**
793
+ * Prepare the fallback error page to render.
794
+ *
795
+ * We prepare a fallback error page if no event nor error handler is provided.
796
+ *
797
+ * @param event - The incoming event.
798
+ * @param response - The outgoing response.
799
+ * @param container - The service container.
800
+ * @param snapshot - The response snapshot.
801
+ */
802
+ declare function prepareFallbackErrorPage(event: IncomingBrowserEvent, response: ReactOutgoingResponse, container: IContainer, snapshot: ResponseSnapshotType): Promise<void>;
803
+
804
+ /**
805
+ * Create an UseReact response.
806
+ *
807
+ * @param options - The options for creating the response.
808
+ * @returns The React response.
809
+ */
810
+ declare const reactResponse: (options: OutgoingHttpResponseOptions | OutgoingBrowserResponseOptions | RedirectResponseOptions | RedirectBrowserResponseOptions) => Promise<ReactOutgoingResponse>;
811
+ /**
812
+ * Create an UseReact redirect response.
813
+ *
814
+ * @param options - The options for creating the response.
815
+ * @returns The React redirect response.
816
+ */
817
+ declare const reactRedirectResponse: (options: RedirectResponseOptions | RedirectBrowserResponseOptions) => Promise<ReactOutgoingResponse>;
818
+
819
+ /**
820
+ * UseReactServerErrorHandler options.
821
+ */
822
+ interface UseReactServerErrorHandlerOptions {
823
+ logger: ILogger;
824
+ blueprint: IBlueprint;
825
+ }
826
+ /**
827
+ * Class representing an UseReactServerErrorHandler.
828
+ *
829
+ * Adapter level error handler for React applications.
830
+ */
831
+ declare class UseReactServerErrorHandler implements IAdapterErrorHandler<unknown, unknown, unknown> {
832
+ private readonly logger;
833
+ private readonly blueprint;
834
+ /**
835
+ * Create an UseReactServerErrorHandler.
836
+ *
837
+ * @param options - UseReactServerErrorHandler options.
838
+ */
839
+ constructor({ blueprint }: UseReactServerErrorHandlerOptions);
840
+ /**
841
+ * Handle an error.
842
+ *
843
+ * @param error - The error to handle.
844
+ * @param context - The context of the adapter.
845
+ * @returns The raw response.
846
+ */
847
+ handle(error: any, context: AdapterErrorContext<unknown, unknown, unknown>): Promise<AdapterEventBuilderType<unknown>>;
848
+ /**
849
+ * Get the error body.
850
+ *
851
+ * @param error - The error to handle.
852
+ * @returns The error body.
853
+ */
854
+ private getErrorBody;
855
+ }
856
+
857
+ /**
858
+ * Constants for the Stone SNAPSHOT
859
+ */
860
+ declare const STONE_SNAPSHOT = "__STONE_SNAPSHOT__";
861
+ /**
862
+ * Constants for the Stone Page Event Outlet
863
+ */
864
+ declare const STONE_PAGE_EVENT_OUTLET = "stone:inject:react-page:outlet";
865
+
866
+ /**
867
+ * Options for configuring the use-react service provider.
868
+ */
869
+ interface UseReactServiceProviderOptions {
870
+ container: IContainer;
871
+ }
872
+ /**
873
+ * Use React Service Provider.
874
+ */
875
+ declare class UseReactServiceProvider implements IServiceProvider {
876
+ private readonly container;
877
+ /**
878
+ * Constructs a new `UseReactServiceProvider` instance.
879
+ *
880
+ * @param container - The container to register services in.
881
+ */
882
+ constructor(container: IContainer);
883
+ /**
884
+ * Register method for the service provider.
885
+ */
886
+ register(): Promiseable<void>;
887
+ /**
888
+ * Boot method for the service provider.
889
+ */
890
+ boot(): Promiseable<void>;
891
+ /**
892
+ * Register the snapshot.
893
+ *
894
+ * We save the snapshot on server side rendering and
895
+ * we use it to hydrate the application on the client side.
896
+ */
897
+ private registerSnapshot;
898
+ }
899
+ /**
900
+ * MetaUseReactServiceProvider
901
+ */
902
+ declare const MetaUseReactServiceProvider: {
903
+ module: typeof UseReactServiceProvider;
904
+ isClass: boolean;
905
+ };
906
+
907
+ /**
908
+ * Configuration options for integrating React with Stone.js.
909
+ */
910
+ interface UseReactConfig {
911
+ /**
912
+ * The ID of the root DOM element where React will be mounted.
913
+ */
914
+ rootElementId?: string;
915
+ /**
916
+ * The content of the HTML template as a string.
917
+ * This can be used to define the structure of the HTML document.
918
+ * This is useful for inline templates or when the template is dynamically generated.
919
+ * Note: This is not a file path, but the actual HTML content.
920
+ */
921
+ htmlTemplateContent?: string;
922
+ /**
923
+ * A map of layout components with their respective event handlers.
924
+ */
925
+ layout?: Record<string, MetaPageLayout>;
926
+ /**
927
+ * Handles incoming events for the root React component.
928
+ */
929
+ componentEventHandler?: MetaPage<ReactIncomingEvent>;
930
+ /**
931
+ * A map of error pages for specific components.
932
+ */
933
+ errorPages?: Record<string, MetaErrorPage<ReactIncomingEvent>>;
934
+ /**
935
+ * A map of error pages for adapter-level errors.
936
+ */
937
+ adapterErrorPages?: Record<string, MetaAdapterErrorPage<unknown, unknown, unknown>>;
938
+ }
939
+ /**
940
+ * Application-level configuration that extends `AppConfig` with React-specific settings.
941
+ */
942
+ interface UseReactAppConfig extends Partial<AppConfig<ReactIncomingEvent, ReactOutgoingResponse>> {
943
+ /**
944
+ * React integration settings, extending the base application config.
945
+ */
946
+ useReact: UseReactConfig;
947
+ }
948
+ /**
949
+ * Stone.js blueprint for a React-based application.
950
+ */
951
+ interface UseReactBlueprint extends StoneBlueprint<ReactIncomingEvent, ReactOutgoingResponse> {
952
+ /**
953
+ * Contains the full application configuration, including middleware,
954
+ * lifecycle hooks, and React integration settings.
955
+ */
956
+ stone: UseReactAppConfig;
957
+ }
958
+ /**
959
+ * Default blueprint for a React-based Stone.js application.
960
+ *
961
+ * - Defines middleware, lifecycle hooks, and the default HTML template path.
962
+ */
963
+ declare const useReactBlueprint: UseReactBlueprint;
964
+
965
+ /**
966
+ * Utility function to define a factory-based adapter error page.
967
+ *
968
+ * @param module - The adapter error page module.
969
+ * @param options - Optional adapter error page options.
970
+ * @returns The UseReactBlueprint.
971
+ */
972
+ declare function defineAdapterErrorPage(module: FactoryAdapterErrorPage<unknown, unknown, unknown>, options?: AdapterErrorPageOptions): UseReactBlueprint;
973
+ /**
974
+ * Utility function to define a class-based adapter error page.
975
+ *
976
+ * @param module - The adapter error page module.
977
+ * @param options - Adapter error page options.
978
+ * @returns The UseReactBlueprint.
979
+ */
980
+ declare function defineAdapterErrorPage(module: AdapterErrorPageClass<unknown, unknown, unknown>, options: AdapterErrorPageOptions & {
981
+ isClass: boolean;
982
+ }): UseReactBlueprint;
983
+
984
+ /**
985
+ * Defines a Stone React app using a factory-based main handler.
986
+ *
987
+ * @param module - A factory function for the main page.
988
+ * @param options - Optional application-level configuration.
989
+ * @param blueprints - Additional blueprints to merge.
990
+ * @returns A fully merged Stone blueprint.
991
+ */
992
+ declare function defineStoneReactApp<U extends ReactIncomingEvent = ReactIncomingEvent>(module: FactoryPage<U>, options?: Partial<UseReactAppConfig>, blueprints?: Array<StoneBlueprint<any, any> & Record<string, any>>): StoneBlueprint<U>;
993
+ /**
994
+ * Defines a Stone React app using a class-based main handler.
995
+ *
996
+ * @param module - A class constructor for the main page.
997
+ * @param options - Optional application-level configuration.
998
+ * @param blueprints - Additional blueprints to merge.
999
+ * @returns A fully merged Stone blueprint.
1000
+ */
1001
+ declare function defineStoneReactApp<U extends ReactIncomingEvent = ReactIncomingEvent>(module: PageClass<U>, options: Partial<UseReactAppConfig> & {
1002
+ isClass: boolean;
1003
+ }, blueprints?: Array<StoneBlueprint<any, any> & Record<string, any>>): StoneBlueprint<U>;
1004
+ /**
1005
+ * Defines a Stone React app without a main handler (router-only).
1006
+ *
1007
+ * @param options - Application-level configuration.
1008
+ * @param blueprints - Additional blueprints to merge.
1009
+ * @returns A fully merged Stone blueprint.
1010
+ */
1011
+ declare function defineStoneReactApp<U extends ReactIncomingEvent = ReactIncomingEvent>(options?: Partial<UseReactAppConfig>, blueprints?: Array<StoneBlueprint<any, any> & Record<string, any>>): StoneBlueprint<U>;
1012
+
1013
+ /**
1014
+ * Stone Client options.
1015
+ */
1016
+ interface StoneClientOptions {
1017
+ children: ReactNode;
1018
+ }
1019
+ /**
1020
+ * Stone Client.
1021
+ * This component is used to wrap content
1022
+ * that should only be rendered on the client.
1023
+ *
1024
+ * @param options - The options to create the Stone Client.
1025
+ */
1026
+ declare const StoneClient: FunctionComponent<StoneClientOptions>;
1027
+
1028
+ /**
1029
+ * Utility function to define a factory-based page.
1030
+ *
1031
+ * @param module - The EventHandler module.
1032
+ * @param options - Page definition options.
1033
+ * @returns The UseReactBlueprint.
1034
+ */
1035
+ declare function definePage<U extends ReactIncomingEvent = ReactIncomingEvent>(module: FactoryPage<U>, options: PageOptions & {
1036
+ isClass?: undefined;
1037
+ }): Partial<StoneBlueprint<U>>;
1038
+ /**
1039
+ * Utility function to define a class-based page.
1040
+ *
1041
+ * @param module - The EventHandler module.
1042
+ * @param options - Page definition options.
1043
+ * @returns The UseReactBlueprint.
1044
+ */
1045
+ declare function definePage<U extends ReactIncomingEvent = ReactIncomingEvent>(module: PageClass<U>, options: PageOptions & {
1046
+ isClass: true;
1047
+ }): Partial<StoneBlueprint<U>>;
1048
+ /**
1049
+ * Utility function to define a factory-based page layout.
1050
+ *
1051
+ * @param module - The layout module.
1052
+ * @param options - Optional page layout definition options.
1053
+ * @returns The UseReactBlueprint.
1054
+ */
1055
+ declare function definePageLayout(module: FactoryPageLayout, options?: PageLayoutOptions & {
1056
+ isClass?: undefined;
1057
+ }): UseReactBlueprint;
1058
+ /**
1059
+ * Utility function to define a class-based page layout.
1060
+ *
1061
+ * @param module - The layout module.
1062
+ * @param options - Optional page layout definition options.
1063
+ * @returns The UseReactBlueprint.
1064
+ */
1065
+ declare function definePageLayout(module: PageLayoutClass, options: PageLayoutOptions & {
1066
+ isClass: true;
1067
+ }): UseReactBlueprint;
1068
+ /**
1069
+ * Utility function to define a factory-based error page.
1070
+ *
1071
+ * @param module - The layout module.
1072
+ * @param options - Optional page layout definition options.
1073
+ * @returns The UseReactBlueprint.
1074
+ */
1075
+ declare function defineErrorPage(module: FactoryErrorPage<ReactIncomingEvent>, options?: ErrorPageOptions & {
1076
+ isClass?: undefined;
1077
+ }): UseReactBlueprint;
1078
+ /**
1079
+ * Utility function to define a class-based error page.
1080
+ *
1081
+ * @param module - The layout module.
1082
+ * @param options - Optional page layout definition options.
1083
+ * @returns The UseReactBlueprint.
1084
+ */
1085
+ declare function defineErrorPage(module: ErrorPageClass<ReactIncomingEvent>, options: ErrorPageOptions & {
1086
+ isClass: true;
1087
+ }): UseReactBlueprint;
1088
+
1089
+ /**
1090
+ * Stone Error.
1091
+ */
1092
+ declare const StoneError: FunctionComponent;
1093
+
1094
+ interface BaseProps {
1095
+ rel?: string;
1096
+ href?: string;
1097
+ target?: string;
1098
+ noRel?: boolean;
1099
+ external?: boolean;
1100
+ className?: string;
1101
+ children: ReactNode;
1102
+ defaultNav?: boolean;
1103
+ selectedClass?: string;
1104
+ ariaCurrentValue?: 'time' | 'location' | 'page' | 'step' | 'date' | 'true' | 'false';
1105
+ }
1106
+ type StoneLinkOptions = (BaseProps & {
1107
+ href: string;
1108
+ to?: string | NavigateOptions;
1109
+ }) | (BaseProps & {
1110
+ href?: string;
1111
+ to: string | NavigateOptions;
1112
+ });
1113
+ /**
1114
+ * Main StoneLink component delegating to internal or external versions.
1115
+ */
1116
+ declare const StoneLink: FunctionComponent<StoneLinkOptions>;
1117
+
1118
+ /**
1119
+ * Stone Outlet options.
1120
+ */
1121
+ interface StoneOutletOptions {
1122
+ children: ReactNode;
1123
+ }
1124
+ /**
1125
+ * A dynamic rendering component that updates its content based on a global event.
1126
+ *
1127
+ * - Listens for `stone:inject:react-page:outlet` and updates its view when triggered.
1128
+ * - Uses `useState` to manage the currently displayed content.
1129
+ * - Automatically cleans up event listeners on unmount.
1130
+ *
1131
+ * This component enables dynamic content updates within a Stone.js application.
1132
+ *
1133
+ * @param options - The options to create the Stone Outlet.
1134
+ * @returns The Stone Outlet component.
1135
+ */
1136
+ declare const StoneOutlet: FunctionComponent<StoneOutletOptions>;
1137
+
1138
+ /**
1139
+ * Stone Page options.
1140
+ */
1141
+ interface StonePageOptions {
1142
+ children: ReactNode;
1143
+ context: StoneContextType;
1144
+ }
1145
+ /**
1146
+ * Provides a scoped `StoneContext` for its children within a strict mode.
1147
+ *
1148
+ * - Wraps content in `React.StrictMode` for enhanced debugging.
1149
+ * - Supplies a `StoneContext.Provider` to get access to the event, data and container.
1150
+ *
1151
+ * This component ensures that all child components have access to the provided
1152
+ * context within a Stone.js application.
1153
+ *
1154
+ * @param options - The options to create the Stone Page.
1155
+ * @returns The Stone Page component.
1156
+ */
1157
+ declare const StonePage: FunctionComponent<StonePageOptions>;
1158
+
1159
+ /**
1160
+ * Stone Server options.
1161
+ */
1162
+ interface StoneServerOptions {
1163
+ children: ReactNode;
1164
+ }
1165
+ /**
1166
+ * Stone Server.
1167
+ * This component is used to wrap content
1168
+ * that should only be rendered on the server.
1169
+ *
1170
+ * @param options - The options to create the Stone Server.
1171
+ */
1172
+ declare const StoneServer: FunctionComponent<StoneServerOptions>;
1173
+
1174
+ /**
1175
+ * A class decorator for defining a class as a React Handler layout.
1176
+ *
1177
+ * @param options - Configuration options for the layout definition.
1178
+ * @returns A method decorator to be applied to a class method.
1179
+ *
1180
+ * @example
1181
+ * ```typescript
1182
+ * import { AdapterErrorPage } from '@stone-js/use-react';
1183
+ *
1184
+ * @AdapterErrorPage({ error: 'UserNotFoundError' })
1185
+ * class UserAdapterErrorPage {
1186
+ * render({ error }) {
1187
+ * return <h1>User name: {error.message}</h1>;
1188
+ * }
1189
+ * }
1190
+ * ```
1191
+ */
1192
+ declare const AdapterErrorPage: <T extends ClassType = ClassType>(options: AdapterErrorPageOptions) => ClassDecorator;
1193
+
1194
+ /**
1195
+ * Hook decorator to mark a method as a lifecycle hook
1196
+ * And automatically add it to the global lifecycle hook registry.
1197
+ *
1198
+ * @example
1199
+ * ```typescript
1200
+ * class MyClass {
1201
+ * // ...
1202
+ * @Hook('onPreparingPage')
1203
+ * onPreparingPage () {}
1204
+ * }
1205
+ * ```
1206
+ *
1207
+ * @param name - The name of the lifecycle hook.
1208
+ * @returns A class decorator function that sets the metadata using the provided options.
1209
+ */
1210
+ declare const Hook: <T extends Function = Function>(name: HookName) => MethodDecorator;
1211
+
1212
+ /**
1213
+ * A class decorator for defining a class as a React Page route action.
1214
+ * Uses the `Match` decorator internally to register the route with the HTTP `GET` method.
1215
+ *
1216
+ * @param options - Configuration options for the route definition, excluding the `methods` property.
1217
+ * @returns A method decorator to be applied to a class method.
1218
+ *
1219
+ * @example
1220
+ * ```typescript
1221
+ * import { Page } from '@stone-js/use-react';
1222
+ *
1223
+ * @Page('/user-profile')
1224
+ * class UserPage {
1225
+ * handle({ event }): Record<string, string> {
1226
+ * return { name: 'Jane Doe' };
1227
+ * }
1228
+ *
1229
+ * render({ data }) {
1230
+ * return <h1>User name: {data.name}</h1>;
1231
+ * }
1232
+ * }
1233
+ * ```
1234
+ */
1235
+ declare const Page: <T extends ClassType = ClassType>(path: string, options?: PageOptions) => ClassDecorator;
1236
+
1237
+ /**
1238
+ * A class decorator for defining a class as a React Handler layout.
1239
+ *
1240
+ * @param options - Configuration options for the layout definition.
1241
+ * @returns A method decorator to be applied to a class method.
1242
+ *
1243
+ * @example
1244
+ * ```typescript
1245
+ * import { ErrorPage } from '@stone-js/use-react';
1246
+ *
1247
+ * @ErrorPage({ error: 'UserNotFoundError' })
1248
+ * class UserErrorPage {
1249
+ * render({ error }) {
1250
+ * return <h1>User name: {error.message}</h1>;
1251
+ * }
1252
+ * }
1253
+ * ```
1254
+ */
1255
+ declare const ErrorPage: <T extends ClassType = ClassType>(options: ErrorPageOptions) => ClassDecorator;
1256
+
1257
+ /**
1258
+ * A class decorator for defining a class as a React Page layout.
1259
+ *
1260
+ * @param options - Configuration options for the layout definition.
1261
+ * @returns A method decorator to be applied to a class method.
1262
+ *
1263
+ * @example
1264
+ * ```typescript
1265
+ * import { PageLayout } from '@stone-js/use-react';
1266
+ *
1267
+ * @PageLayout({ name: 'UserPageLayout' })
1268
+ * class UserPageLayout {
1269
+ * render({ data }) {
1270
+ * return <h1>User name: {data.name}</h1>;
1271
+ * }
1272
+ * }
1273
+ * ```
1274
+ */
1275
+ declare const PageLayout: <T extends ClassType = ClassType>(options: PageLayoutOptions) => ClassDecorator;
1276
+
1277
+ /**
1278
+ * Decorator to set the status code of the response.
1279
+ *
1280
+ * @param statusCode - The status code of the response.
1281
+ * @param headers - The headers for the response.
1282
+ * @returns A method decorator.
1283
+ *
1284
+ * @example
1285
+ * ```typescript
1286
+ * import { Page, PageStatus } from '@stone-js/use-react';
1287
+ *
1288
+ * @Page('/user-profile')
1289
+ * class UserPage {
1290
+ * @PageStatus()
1291
+ * handle() {
1292
+ * return { name: 'John Doe' };
1293
+ * }
1294
+ * }
1295
+ * ```
1296
+ */
1297
+ declare const PageStatus: <T extends Function = Function>(statusCode?: number, headers?: HeadersType) => MethodDecorator;
1298
+
1299
+ /**
1300
+ * Decorator to create a snapshot of the current data.
1301
+ *
1302
+ * @param name - The name of the snapshot.
1303
+ * @returns A method decorator.
1304
+ *
1305
+ * @example
1306
+ * ```typescript
1307
+ * import { Service } from '@stone-js/core';
1308
+ * import { Snapshot } from '@stone-js/use-react';
1309
+ *
1310
+ * @Service({ alias: 'userService' })
1311
+ * class UserService {
1312
+ * @Snapshot()
1313
+ * showProfile() {
1314
+ * return { name: 'John Doe' };
1315
+ * }
1316
+ * }
1317
+ * ```
1318
+ */
1319
+ declare const Snapshot: <T extends Function = Function>(name?: string) => MethodDecorator;
1320
+
1321
+ /**
1322
+ * UseReact decorator options.
1323
+ */
1324
+ interface UseReactOptions extends Partial<UseReactConfig> {
1325
+ }
1326
+ /**
1327
+ * UseReact decorator.
1328
+ *
1329
+ * UseReact is a class decorator that allows you to use React components in your Stone application.
1330
+ * The decorator is used to define the React configuration for the class.
1331
+ *
1332
+ * @param options - UseReactOptions
1333
+ * @returns ClassDecorator
1334
+ */
1335
+ declare const UseReact: <T extends ClassType = ClassType>(options?: UseReactOptions) => ClassDecorator;
1336
+
1337
+ /**
1338
+ * Custom error for react operations.
1339
+ */
1340
+ declare class UseReactError extends InitializationError {
1341
+ constructor(message: string, options?: ErrorOptions);
1342
+ }
1343
+
1344
+ /**
1345
+ * Blueprint middleware to dynamically set lifecycle hooks for react.
1346
+ *
1347
+ * @param context - The configuration context containing modules and blueprint.
1348
+ * @param next - The next pipeline function to continue processing.
1349
+ * @returns The updated blueprint or a promise resolving to it.
1350
+ *
1351
+ * @example
1352
+ * ```typescript
1353
+ * SetUseReactHooksMiddleware(context, next)
1354
+ * ```
1355
+ */
1356
+ declare const SetUseReactHooksMiddleware: (context: BlueprintContext<IBlueprint, ClassType>, next: NextMiddleware<BlueprintContext<IBlueprint, ClassType>, IBlueprint>) => Promiseable<IBlueprint>;
1357
+ /**
1358
+ * Blueprint middleware to set BrowserResponseMiddleware for the Browser adapter.
1359
+ *
1360
+ * The MetaBrowserResponseMiddleware is an adapter middleware and is useful
1361
+ * for handling outgoing responses and rendering them in the browser.
1362
+ *
1363
+ * @param context - The configuration context containing modules and blueprint.
1364
+ * @param next - The next pipeline function to continue processing.
1365
+ * @returns The updated blueprint or a promise resolving to it.
1366
+ *
1367
+ * @example
1368
+ * ```typescript
1369
+ * SetBrowserResponseMiddlewareMiddleware(context, next)
1370
+ * ```
1371
+ */
1372
+ declare const SetBrowserResponseMiddlewareMiddleware: (context: BlueprintContext<IBlueprint, ClassType>, next: NextMiddleware<BlueprintContext<IBlueprint, ClassType>, IBlueprint>) => Promise<IBlueprint>;
1373
+ /**
1374
+ * Blueprint middleware to process and register kernel error page definitions from modules.
1375
+ *
1376
+ * @param context - The configuration context containing modules and blueprint.
1377
+ * @param next - The next pipeline function to continue processing.
1378
+ * @returns The updated blueprint or a promise resolving to it.
1379
+ *
1380
+ * @example
1381
+ * ```typescript
1382
+ * SetReactKernelErrorPageMiddleware(context, next)
1383
+ * ```
1384
+ */
1385
+ declare const SetReactKernelErrorPageMiddleware: (context: BlueprintContext<IBlueprint, ClassType>, next: NextMiddleware<BlueprintContext<IBlueprint, ClassType>, IBlueprint>) => Promiseable<IBlueprint>;
1386
+ /**
1387
+ * Blueprint middleware to process and register adapter error page definitions from modules.
1388
+ *
1389
+ * @param context - The configuration context containing modules and blueprint.
1390
+ * @param next - The next pipeline function to continue processing.
1391
+ * @returns The updated blueprint or a promise resolving to it.
1392
+ *
1393
+ * @example
1394
+ * ```typescript
1395
+ * SetReactAdapterErrorPageMiddleware(context, next)
1396
+ * ```
1397
+ */
1398
+ declare const SetReactAdapterErrorPageMiddleware: (context: BlueprintContext<IBlueprint, ClassType>, next: NextMiddleware<BlueprintContext<IBlueprint, ClassType>, IBlueprint>) => Promiseable<IBlueprint>;
1399
+ /**
1400
+ * Blueprint middleware to set StaticFileMiddleware for SSR adapter.
1401
+ *
1402
+ * @param context - The configuration context containing modules and blueprint.
1403
+ * @param next - The next pipeline function to continue processing.
1404
+ * @returns The updated blueprint or a promise resolving to it.
1405
+ *
1406
+ * @example
1407
+ * ```typescript
1408
+ * SetSSRStaticFileMiddleware(context, next)
1409
+ * ```
1410
+ */
1411
+ declare const SetSSRStaticFileMiddleware: (context: BlueprintContext<IBlueprint, ClassType>, next: NextMiddleware<BlueprintContext<IBlueprint, ClassType>, IBlueprint>) => Promise<IBlueprint>;
1412
+ /**
1413
+ * Blueprint middleware to set CompressionMiddleware for SSR adapter.
1414
+ *
1415
+ * @param context - The configuration context containing modules and blueprint.
1416
+ * @param next - The next pipeline function to continue processing.
1417
+ * @returns The updated blueprint or a promise resolving to it.
1418
+ *
1419
+ * @example
1420
+ * ```typescript
1421
+ * SetSSRCompressionMiddleware(context, next)
1422
+ * ```
1423
+ */
1424
+ declare const SetSSRCompressionMiddleware: (context: BlueprintContext<IBlueprint, ClassType>, next: NextMiddleware<BlueprintContext<IBlueprint, ClassType>, IBlueprint>) => Promise<IBlueprint>;
1425
+ /**
1426
+ * Blueprint middleware to process and register route definitions from modules.
1427
+ *
1428
+ * @param context - The configuration context containing modules and blueprint.
1429
+ * @param next - The next pipeline function to continue processing.
1430
+ * @returns The updated blueprint or a promise resolving to it.
1431
+ *
1432
+ * @example
1433
+ * ```typescript
1434
+ * SetReactRouteDefinitionsMiddleware(context, next)
1435
+ * ```
1436
+ */
1437
+ declare const SetReactRouteDefinitionsMiddleware: (context: BlueprintContext<IBlueprint, ClassType>, next: NextMiddleware<BlueprintContext<IBlueprint, ClassType>, IBlueprint>) => Promiseable<IBlueprint>;
1438
+ /**
1439
+ * Blueprint middleware to process and register layout definitions from modules.
1440
+ *
1441
+ * @param context - The configuration context containing modules and blueprint.
1442
+ * @param next - The next pipeline function to continue processing.
1443
+ * @returns The updated blueprint or a promise resolving to it.
1444
+ *
1445
+ * @example
1446
+ * ```typescript
1447
+ * SetReactPageLayoutMiddleware(context, next)
1448
+ * ```
1449
+ */
1450
+ declare const SetReactPageLayoutMiddleware: (context: BlueprintContext<IBlueprint, ClassType>, next: NextMiddleware<BlueprintContext<IBlueprint, ClassType>, IBlueprint>) => Promiseable<IBlueprint>;
1451
+ /**
1452
+ * Blueprint middleware to set the UseReact as the main event handler for the application.
1453
+ *
1454
+ * Set as fallback event handler if none of the other event handlers are registered.
1455
+ *
1456
+ * @param context - The configuration context containing modules and blueprint.
1457
+ * @param next - The next function in the pipeline.
1458
+ * @returns The updated blueprint.
1459
+ *
1460
+ * @example
1461
+ * ```typescript
1462
+ * SetUseReactEventHandlerMiddleware({ modules, blueprint }, next);
1463
+ * ```
1464
+ */
1465
+ declare function SetUseReactEventHandlerMiddleware(context: BlueprintContext<IBlueprint, ClassType>, next: NextMiddleware<BlueprintContext<IBlueprint, ClassType>, IBlueprint>): Promise<IBlueprint>;
1466
+ /**
1467
+ * Configuration for react processing middleware.
1468
+ *
1469
+ * This array defines a list of middleware pipes, each with a `pipe` function and a `priority`.
1470
+ * These pipes are executed in the order of their priority values, with lower values running first.
1471
+ */
1472
+ declare const metaUseReactBlueprintMiddleware: Array<MetaMiddleware<BlueprintContext<IBlueprint, ClassType>, IBlueprint>>;
1473
+
1474
+ /**
1475
+ * Adapter Middleware for handling outgoing responses and rendering them in the browser.
1476
+ */
1477
+ declare class BrowserResponseMiddleware {
1478
+ private readonly isRendered;
1479
+ private readonly blueprint;
1480
+ /**
1481
+ * Create a BrowserResponseMiddleware.
1482
+ *
1483
+ * @param {blueprint} options - Options for creating the BrowserResponseMiddleware.
1484
+ */
1485
+ constructor({ blueprint }: {
1486
+ blueprint: IBlueprint;
1487
+ });
1488
+ /**
1489
+ * Handles the outgoing response, processes it, and invokes the next middleware in the pipeline.
1490
+ *
1491
+ * @param context - The adapter context containing the raw event, execution context, and other data.
1492
+ * @param next - The next middleware to be invoked in the pipeline.
1493
+ * @returns A promise resolving to the processed context.
1494
+ * @throws {NodeHttpAdapterError} If required components are missing in the context.
1495
+ */
1496
+ handle(context: ReactBrowserAdapterContext, next: NextMiddleware<ReactBrowserAdapterContext, BrowserAdapterResponseBuilder>): Promise<BrowserAdapterResponseBuilder>;
1497
+ /**
1498
+ * Ensures the context and response builder have the required components.
1499
+ */
1500
+ private ensureValidContext;
1501
+ /**
1502
+ * Renders the provided React content.
1503
+ *
1504
+ * @param response - The response object.
1505
+ */
1506
+ private renderComponent;
1507
+ /**
1508
+ * Handles navigation redirection.
1509
+ *
1510
+ * @param path - The path to redirect to.
1511
+ */
1512
+ private handleRedirect;
1513
+ /**
1514
+ * Hydrates the React app when SSR is enabled.
1515
+ *
1516
+ * @param app - The React app to hydrate.
1517
+ */
1518
+ private hydrateReactApp;
1519
+ /**
1520
+ * Renders the React app.
1521
+ *
1522
+ * @param app - The React app to render.
1523
+ */
1524
+ private renderReactApp;
1525
+ /**
1526
+ * Dispatches a component to the layout outlet when no layout is defined.
1527
+ *
1528
+ * @param component - The component to dispatch.
1529
+ */
1530
+ private dispatchComponentToOutlet;
1531
+ }
1532
+ /**
1533
+ * Meta Middleware for processing browser responses.
1534
+ */
1535
+ declare const MetaBrowserResponseMiddleware: {
1536
+ module: typeof BrowserResponseMiddleware;
1537
+ isClass: boolean;
1538
+ };
1539
+
1540
+ /**
1541
+ * Constants are defined here to prevent Circular dependency between modules
1542
+ * This pattern must be applied to all Stone libraries or third party libraries.
1543
+ */
1544
+ /**
1545
+ * A unique symbol key to mark classes as React Page component.
1546
+ */
1547
+ declare const REACT_PAGE_KEY: unique symbol;
1548
+ /**
1549
+ * A unique symbol key to mark classes as React Page layout component.
1550
+ */
1551
+ declare const REACT_PAGE_LAYOUT_KEY: unique symbol;
1552
+ /**
1553
+ * A unique symbol key to mark classes as React Error handler component.
1554
+ */
1555
+ declare const REACT_ERROR_PAGE_KEY: unique symbol;
1556
+ /**
1557
+ * A unique symbol key to mark classes as React Adapter Error handler component.
1558
+ */
1559
+ declare const REACT_ADAPTER_ERROR_PAGE_KEY: unique symbol;
1560
+ /**
1561
+ * A unique symbol key to mark classes as React Stone application entry point.
1562
+ */
1563
+ declare const STONE_REACT_APP_KEY: unique symbol;
1564
+
1565
+ export { AdapterErrorPage, BrowserResponseMiddleware, ErrorPage, Hook, MetaBrowserResponseMiddleware, MetaReactRuntime, MetaUseReactServiceProvider, Page, PageLayout, PageStatus, REACT_ADAPTER_ERROR_PAGE_KEY, REACT_ERROR_PAGE_KEY, REACT_PAGE_KEY, REACT_PAGE_LAYOUT_KEY, ReactRuntime, STONE_DOM_ATTR, STONE_PAGE_EVENT_OUTLET, STONE_REACT_APP_KEY, STONE_SNAPSHOT, SetBrowserResponseMiddlewareMiddleware, SetReactAdapterErrorPageMiddleware, SetReactKernelErrorPageMiddleware, SetReactPageLayoutMiddleware, SetReactRouteDefinitionsMiddleware, SetSSRCompressionMiddleware, SetSSRStaticFileMiddleware, SetUseReactEventHandlerMiddleware, SetUseReactHooksMiddleware, Snapshot, StoneClient, StoneContext, StoneError, StoneLink, StoneOutlet, StonePage, StoneServer, UseReact, UseReactBrowserErrorHandler, UseReactError, UseReactEventHandler, UseReactKernelErrorHandler, UseReactServerErrorHandler, UseReactServiceProvider, applyHeadContextToDom, applyHeadContextToHtmlString, applyMeta, buildAdapterErrorComponent, buildAppComponent, buildLayoutComponent, buildPageComponent, defineAdapterErrorPage, defineErrorPage, definePage, definePageLayout, defineStoneReactApp, executeHandler, executeHooks, getAppRootElement, getBrowserContent, getResponseSnapshot, getServerContent, htmlTemplate, hydrateReactApp, isClient, isSSR, isServer, metaUseReactBlueprintMiddleware, onPreparingResponse, prepareErrorPage, prepareFallbackErrorPage, preparePage, reactRedirectResponse, reactResponse, renderReactApp, renderStoneSnapshot, resolveComponent, resolveLazyComponent, snapshotResponse, useReactBlueprint };
1566
+ export type { AdapterErrorPageClass, AdapterErrorPageOptions, AdapterErrorPageRenderContext, AdapterErrorPageType, AdapterPageLayoutRenderContext, BrowserResponseContent, ErrorPageClass, ErrorPageHeadContext, ErrorPageOptions, ErrorPageRenderContext, ErrorPageType, FactoryAdapterErrorPage, FactoryErrorPage, FactoryPage, FactoryPageLayout, HeadContext, HeadersType, HookName, IAdapterErrorPage, IErrorPage, IPage, IPageLayout, IRoute, IRouter, ISnapshot, MetaAdapterErrorPage, MetaErrorPage, MetaPage, MetaPageLayout, OnPreparingResponseOptions, PageClass, PageHeadContext, PageLayoutClass, PageLayoutOptions, PageLayoutRenderContext, PageLayoutType, PageOptions, PageRenderContext, PageType, ReactBrowserAdapterContext, ReactIncomingEvent, ReactIncomingEventOptions, ReactLifecycleHookType, ReactOutgoingResponse, ReactOutgoingResponseOptions, ReactRuntimeOptions, ResponseSnapshotType, StoneContextType, StoneLinkOptions, StoneOutletOptions, UseReactAppConfig, UseReactBlueprint, UseReactBrowserErrorHandlerOptions, UseReactConfig, UseReactErrorResponseType, UseReactHookListener, UseReactHookListenerContext, UseReactHookName, UseReactHookType, UseReactOptions, UseReactServerErrorHandlerOptions, UseReactServiceProviderOptions };