@stone-js/use-react 0.1.0 → 0.3.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.ts CHANGED
@@ -1,11 +1,11 @@
1
- import { HTMLMetaDescriptor, HeadContext as HeadContext$1, FunctionalEventHandler, Route, Router, DecoratorPageRouteDefinition, NavigateOptions } from '@stone-js/router';
1
+ import { HeadContext as HeadContext$1, HTMLMetaDescriptor, FunctionalEventHandler, Route, Router, DecoratorPageRouteDefinition, NavigateOptions } from '@stone-js/router';
2
2
  import * as react from 'react';
3
- import { ReactNode, ElementType, FunctionComponent } from 'react';
3
+ import { ReactNode, ElementType, FunctionComponent, AnchorHTMLAttributes, HTMLAttributes } from 'react';
4
4
  import { Config } from '@stone-js/config';
5
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';
6
+ import { IncomingHttpEvent, OutgoingHttpResponse, RedirectResponse, IncomingHttpEventOptions, RedirectResponseOptions, OutgoingHttpResponseOptions } from '@stone-js/http-core';
7
+ import { IncomingBrowserEvent, IncomingBrowserEventOptions, OutgoingBrowserResponse, RedirectBrowserResponse, RedirectBrowserResponseOptions, OutgoingBrowserResponseOptions } from '@stone-js/browser-core';
8
+ import { AdapterErrorHandlerOptions, FunctionalAdapterErrorHandler, IBlueprint, IContainer, AdapterContext, ErrorHandlerOptions, FunctionalErrorHandler, Promiseable, HookName as HookName$1, Laziable, LifecycleHookType, OutgoingResponseOptions, IEventHandler, IErrorHandler, AdapterErrorContext, IServiceProvider, AppConfig, StoneBlueprint, IAdapterErrorHandler, AdapterEventBuilderType, InitializationError, ErrorOptions, ClassType, BlueprintContext, NextMiddleware, ILogger, MetaMiddleware } from '@stone-js/core';
9
9
  import { Root } from 'react-dom/client';
10
10
 
11
11
  /**
@@ -66,6 +66,14 @@ type ReactIncomingEvent = IncomingHttpEvent | IncomingBrowserEvent;
66
66
  * Incoming event options for React.
67
67
  */
68
68
  type ReactIncomingEventOptions = IncomingBrowserEventOptions | IncomingHttpEventOptions;
69
+ /**
70
+ * Redirect response options for React.
71
+ */
72
+ type ReactRedirectResponseOptions = RedirectResponseOptions | RedirectBrowserResponseOptions;
73
+ /**
74
+ * Outgoing response options for React.
75
+ */
76
+ type ReactResponseOptions = OutgoingHttpResponseOptions | ReactOutgoingResponseOptions | ReactRedirectResponseOptions | OutgoingBrowserResponseOptions;
69
77
  /**
70
78
  * Outgoing response for React.
71
79
  */
@@ -382,6 +390,12 @@ interface MetaAdapterErrorPage<RawEventType, RawResponseType, ExecutionContextTy
382
390
  module: AdapterErrorPageType<RawEventType, RawResponseType, ExecutionContextType> | Laziable<AdapterErrorPageType<RawEventType, RawResponseType, ExecutionContextType>>;
383
391
  }
384
392
 
393
+ /**
394
+ * Stone context.
395
+ * Usefull to pass data to the components.
396
+ */
397
+ declare const StoneContext: react.Context<StoneContextType>;
398
+
385
399
  /**
386
400
  * ReactRuntimeOptions
387
401
  */
@@ -466,49 +480,6 @@ declare const MetaReactRuntime: {
466
480
  singleton: boolean;
467
481
  };
468
482
 
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
483
  /**
513
484
  * A useReact event handler for processing incoming events
514
485
  * For single event handler.
@@ -732,9 +703,9 @@ declare function getBrowserContent(app: ReactNode, component: ReactNode, layout:
732
703
  * @param container - The service container.
733
704
  * @param event - The incoming browser event.
734
705
  * @param head - The head context.
735
- * @returns A promise that resolves when the content is hydrated.
706
+ * @returns The server response content as a string.
736
707
  */
737
- declare function getServerContent(component: ReactNode, data: Partial<ResponseSnapshotType>, container: IContainer, event: IncomingBrowserEvent, head?: HeadContext): Promise<string>;
708
+ declare function getServerContent(component: ReactNode, data: Partial<ResponseSnapshotType>, container: IContainer, event: IncomingBrowserEvent, head?: HeadContext): string;
738
709
  /**
739
710
  * Get the response snapshot.
740
711
  *
@@ -801,59 +772,6 @@ declare function prepareErrorPage(event: IncomingBrowserEvent, response: ReactOu
801
772
  */
802
773
  declare function prepareFallbackErrorPage(event: IncomingBrowserEvent, response: ReactOutgoingResponse, container: IContainer, snapshot: ResponseSnapshotType): Promise<void>;
803
774
 
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
775
  /**
858
776
  * Constants for the Stone SNAPSHOT
859
777
  */
@@ -923,6 +841,12 @@ interface UseReactConfig {
923
841
  * A map of layout components with their respective event handlers.
924
842
  */
925
843
  layout?: Record<string, MetaPageLayout>;
844
+ /**
845
+ * A list of platforms to ignore for React rendering.
846
+ * This can be used to disable React rendering on specific platforms.
847
+ * For example, you might want to ignore rendering on CLI platforms.
848
+ */
849
+ ignorePlatforms?: string[];
926
850
  /**
927
851
  * Handles incoming events for the root React component.
928
852
  */
@@ -960,26 +884,7 @@ interface UseReactBlueprint extends StoneBlueprint<ReactIncomingEvent, ReactOutg
960
884
  *
961
885
  * - Defines middleware, lifecycle hooks, and the default HTML template path.
962
886
  */
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;
887
+ declare const internalUseReactBlueprint: UseReactBlueprint;
983
888
 
984
889
  /**
985
890
  * Defines a Stone React app using a factory-based main handler.
@@ -1010,6 +915,82 @@ declare function defineStoneReactApp<U extends ReactIncomingEvent = ReactIncomin
1010
915
  */
1011
916
  declare function defineStoneReactApp<U extends ReactIncomingEvent = ReactIncomingEvent>(options?: Partial<UseReactAppConfig>, blueprints?: Array<StoneBlueprint<any, any> & Record<string, any>>): StoneBlueprint<U>;
1012
917
 
918
+ /**
919
+ * Utility function to define a factory-based adapter error page.
920
+ *
921
+ * @param module - The adapter error page module.
922
+ * @param options - Optional adapter error page options.
923
+ * @returns The UseReactBlueprint.
924
+ */
925
+ declare function defineAdapterErrorPage(module: FactoryAdapterErrorPage<unknown, unknown, unknown>, options?: AdapterErrorPageOptions): UseReactBlueprint;
926
+ /**
927
+ * Utility function to define a class-based adapter error page.
928
+ *
929
+ * @param module - The adapter error page module.
930
+ * @param options - Adapter error page options.
931
+ * @returns The UseReactBlueprint.
932
+ */
933
+ declare function defineAdapterErrorPage(module: AdapterErrorPageClass<unknown, unknown, unknown>, options: AdapterErrorPageOptions & {
934
+ isClass: boolean;
935
+ }): UseReactBlueprint;
936
+
937
+ /**
938
+ * UseReactBrowserErrorHandler options.
939
+ */
940
+ interface UseReactBrowserErrorHandlerOptions {
941
+ blueprint: IBlueprint;
942
+ }
943
+ /**
944
+ * Class representing an UseReactBrowserErrorHandler.
945
+ *
946
+ * Adapter level error handler for React applications.
947
+ */
948
+ declare class UseReactBrowserErrorHandler implements IAdapterErrorHandler<unknown, unknown, unknown> {
949
+ private readonly logger;
950
+ private readonly blueprint;
951
+ /**
952
+ * Create an UseReactBrowserErrorHandler.
953
+ *
954
+ * @param options - UseReactBrowserErrorHandler options.
955
+ */
956
+ constructor({ blueprint }: UseReactBrowserErrorHandlerOptions);
957
+ /**
958
+ * Handle an error.
959
+ *
960
+ * @param error - The error to handle.
961
+ * @param context - The context of the adapter.
962
+ * @returns The raw response.
963
+ */
964
+ handle(error: any, context: AdapterErrorContext<unknown, unknown, unknown>): Promise<AdapterEventBuilderType<unknown>>;
965
+ /**
966
+ * Get the error body.
967
+ *
968
+ * @param error - The error to handle.
969
+ * @returns The error body.
970
+ */
971
+ private renderError;
972
+ }
973
+
974
+ /**
975
+ * Stone Error.
976
+ */
977
+ declare const StoneError: FunctionComponent;
978
+
979
+ /**
980
+ * Create an UseReact response.
981
+ *
982
+ * @param options - The options for creating the response.
983
+ * @returns The React response.
984
+ */
985
+ declare const reactResponse: (options: ReactResponseOptions) => ReactOutgoingResponse;
986
+ /**
987
+ * Create an UseReact redirect response.
988
+ *
989
+ * @param options - The options for creating the response.
990
+ * @returns The React redirect response.
991
+ */
992
+ declare const reactRedirectResponse: (options: ReactRedirectResponseOptions) => ReactOutgoingResponse;
993
+
1013
994
  /**
1014
995
  * Stone Client options.
1015
996
  */
@@ -1086,18 +1067,9 @@ declare function defineErrorPage(module: ErrorPageClass<ReactIncomingEvent>, opt
1086
1067
  isClass: true;
1087
1068
  }): UseReactBlueprint;
1088
1069
 
1089
- /**
1090
- * Stone Error.
1091
- */
1092
- declare const StoneError: FunctionComponent;
1093
-
1094
- interface BaseProps {
1095
- rel?: string;
1096
- href?: string;
1097
- target?: string;
1070
+ interface BaseProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
1098
1071
  noRel?: boolean;
1099
1072
  external?: boolean;
1100
- className?: string;
1101
1073
  children: ReactNode;
1102
1074
  defaultNav?: boolean;
1103
1075
  selectedClass?: string;
@@ -1111,30 +1083,10 @@ type StoneLinkOptions = (BaseProps & {
1111
1083
  to: string | NavigateOptions;
1112
1084
  });
1113
1085
  /**
1114
- * Main StoneLink component delegating to internal or external versions.
1086
+ * Internal link component using Stone.js router.
1115
1087
  */
1116
1088
  declare const StoneLink: FunctionComponent<StoneLinkOptions>;
1117
1089
 
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
1090
  /**
1139
1091
  * Stone Page options.
1140
1092
  */
@@ -1156,6 +1108,25 @@ interface StonePageOptions {
1156
1108
  */
1157
1109
  declare const StonePage: FunctionComponent<StonePageOptions>;
1158
1110
 
1111
+ /**
1112
+ * Stone Outlet options.
1113
+ */
1114
+ interface StoneOutletOptions extends HTMLAttributes<HTMLDivElement> {
1115
+ }
1116
+ /**
1117
+ * A dynamic rendering component that updates its content based on a global event.
1118
+ *
1119
+ * - Listens for `stone:inject:react-page:outlet` and updates its view when triggered.
1120
+ * - Uses `useState` to manage the currently displayed content.
1121
+ * - Automatically cleans up event listeners on unmount.
1122
+ *
1123
+ * This component enables dynamic content updates within a Stone.js application.
1124
+ *
1125
+ * @param options - The options to create the Stone Outlet.
1126
+ * @returns The Stone Outlet component.
1127
+ */
1128
+ declare const StoneOutlet: FunctionComponent<StoneOutletOptions>;
1129
+
1159
1130
  /**
1160
1131
  * Stone Server options.
1161
1132
  */
@@ -1171,6 +1142,13 @@ interface StoneServerOptions {
1171
1142
  */
1172
1143
  declare const StoneServer: FunctionComponent<StoneServerOptions>;
1173
1144
 
1145
+ /**
1146
+ * Custom error for react operations.
1147
+ */
1148
+ declare class UseReactError extends InitializationError {
1149
+ constructor(message: string, options?: ErrorOptions);
1150
+ }
1151
+
1174
1152
  /**
1175
1153
  * A class decorator for defining a class as a React Handler layout.
1176
1154
  *
@@ -1191,6 +1169,26 @@ declare const StoneServer: FunctionComponent<StoneServerOptions>;
1191
1169
  */
1192
1170
  declare const AdapterErrorPage: <T extends ClassType = ClassType>(options: AdapterErrorPageOptions) => ClassDecorator;
1193
1171
 
1172
+ /**
1173
+ * A class decorator for defining a class as a React Handler layout.
1174
+ *
1175
+ * @param options - Configuration options for the layout definition.
1176
+ * @returns A method decorator to be applied to a class method.
1177
+ *
1178
+ * @example
1179
+ * ```typescript
1180
+ * import { ErrorPage } from '@stone-js/use-react';
1181
+ *
1182
+ * @ErrorPage({ error: 'UserNotFoundError' })
1183
+ * class UserErrorPage {
1184
+ * render({ error }) {
1185
+ * return <h1>User name: {error.message}</h1>;
1186
+ * }
1187
+ * }
1188
+ * ```
1189
+ */
1190
+ declare const ErrorPage: <T extends ClassType = ClassType>(options: ErrorPageOptions) => ClassDecorator;
1191
+
1194
1192
  /**
1195
1193
  * Hook decorator to mark a method as a lifecycle hook
1196
1194
  * And automatically add it to the global lifecycle hook registry.
@@ -1232,27 +1230,29 @@ declare const Hook: <T extends Function = Function>(name: HookName) => MethodDec
1232
1230
  * }
1233
1231
  * ```
1234
1232
  */
1235
- declare const Page: <T extends ClassType = ClassType>(path: string, options?: PageOptions) => ClassDecorator;
1233
+ declare const Page: <T extends ClassType = ClassType>(path: string | string[], options?: PageOptions) => ClassDecorator;
1236
1234
 
1237
1235
  /**
1238
- * A class decorator for defining a class as a React Handler layout.
1236
+ * Decorator to set the status code of the response.
1239
1237
  *
1240
- * @param options - Configuration options for the layout definition.
1241
- * @returns A method decorator to be applied to a class method.
1238
+ * @param statusCode - The status code of the response.
1239
+ * @param headers - The headers for the response.
1240
+ * @returns A method decorator.
1242
1241
  *
1243
1242
  * @example
1244
1243
  * ```typescript
1245
- * import { ErrorPage } from '@stone-js/use-react';
1244
+ * import { Page, PageStatus } from '@stone-js/use-react';
1246
1245
  *
1247
- * @ErrorPage({ error: 'UserNotFoundError' })
1248
- * class UserErrorPage {
1249
- * render({ error }) {
1250
- * return <h1>User name: {error.message}</h1>;
1246
+ * @Page('/user-profile')
1247
+ * class UserPage {
1248
+ * @PageStatus()
1249
+ * handle() {
1250
+ * return { name: 'John Doe' };
1251
1251
  * }
1252
1252
  * }
1253
1253
  * ```
1254
1254
  */
1255
- declare const ErrorPage: <T extends ClassType = ClassType>(options: ErrorPageOptions) => ClassDecorator;
1255
+ declare const PageStatus: <T extends Function = Function>(statusCode?: number, headers?: HeadersType) => MethodDecorator;
1256
1256
 
1257
1257
  /**
1258
1258
  * A class decorator for defining a class as a React Page layout.
@@ -1274,28 +1274,6 @@ declare const ErrorPage: <T extends ClassType = ClassType>(options: ErrorPageOpt
1274
1274
  */
1275
1275
  declare const PageLayout: <T extends ClassType = ClassType>(options: PageLayoutOptions) => ClassDecorator;
1276
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
1277
  /**
1300
1278
  * Decorator to create a snapshot of the current data.
1301
1279
  *
@@ -1319,27 +1297,29 @@ declare const PageStatus: <T extends Function = Function>(statusCode?: number, h
1319
1297
  declare const Snapshot: <T extends Function = Function>(name?: string) => MethodDecorator;
1320
1298
 
1321
1299
  /**
1322
- * UseReact decorator options.
1300
+ * Constants are defined here to prevent Circular dependency between modules
1301
+ * This pattern must be applied to all Stone libraries or third party libraries.
1323
1302
  */
1324
- interface UseReactOptions extends Partial<UseReactConfig> {
1325
- }
1326
1303
  /**
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
1304
+ * A unique symbol key to mark classes as React Page component.
1334
1305
  */
1335
- declare const UseReact: <T extends ClassType = ClassType>(options?: UseReactOptions) => ClassDecorator;
1336
-
1306
+ declare const REACT_PAGE_KEY: unique symbol;
1337
1307
  /**
1338
- * Custom error for react operations.
1308
+ * A unique symbol key to mark classes as React Page layout component.
1339
1309
  */
1340
- declare class UseReactError extends InitializationError {
1341
- constructor(message: string, options?: ErrorOptions);
1342
- }
1310
+ declare const REACT_PAGE_LAYOUT_KEY: unique symbol;
1311
+ /**
1312
+ * A unique symbol key to mark classes as React Error handler component.
1313
+ */
1314
+ declare const REACT_ERROR_PAGE_KEY: unique symbol;
1315
+ /**
1316
+ * A unique symbol key to mark classes as React Adapter Error handler component.
1317
+ */
1318
+ declare const REACT_ADAPTER_ERROR_PAGE_KEY: unique symbol;
1319
+ /**
1320
+ * A unique symbol key to mark classes as React Stone application entry point.
1321
+ */
1322
+ declare const STONE_REACT_APP_KEY: unique symbol;
1343
1323
 
1344
1324
  /**
1345
1325
  * Blueprint middleware to dynamically set lifecycle hooks for react.
@@ -1354,22 +1334,6 @@ declare class UseReactError extends InitializationError {
1354
1334
  * ```
1355
1335
  */
1356
1336
  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
1337
  /**
1374
1338
  * Blueprint middleware to process and register kernel error page definitions from modules.
1375
1339
  *
@@ -1383,45 +1347,6 @@ declare const SetBrowserResponseMiddlewareMiddleware: (context: BlueprintContext
1383
1347
  * ```
1384
1348
  */
1385
1349
  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
1350
  /**
1426
1351
  * Blueprint middleware to process and register route definitions from modules.
1427
1352
  *
@@ -1463,13 +1388,69 @@ declare const SetReactPageLayoutMiddleware: (context: BlueprintContext<IBlueprin
1463
1388
  * ```
1464
1389
  */
1465
1390
  declare function SetUseReactEventHandlerMiddleware(context: BlueprintContext<IBlueprint, ClassType>, next: NextMiddleware<BlueprintContext<IBlueprint, ClassType>, IBlueprint>): Promise<IBlueprint>;
1391
+
1466
1392
  /**
1467
- * Configuration for react processing middleware.
1393
+ * UseReactServerErrorHandler options.
1394
+ */
1395
+ interface UseReactServerErrorHandlerOptions {
1396
+ logger: ILogger;
1397
+ blueprint: IBlueprint;
1398
+ }
1399
+ /**
1400
+ * Class representing an UseReactServerErrorHandler.
1468
1401
  *
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.
1402
+ * Adapter level error handler for React applications.
1471
1403
  */
1472
- declare const metaUseReactBlueprintMiddleware: Array<MetaMiddleware<BlueprintContext<IBlueprint, ClassType>, IBlueprint>>;
1404
+ declare class UseReactServerErrorHandler implements IAdapterErrorHandler<unknown, unknown, unknown> {
1405
+ private readonly logger;
1406
+ private readonly blueprint;
1407
+ /**
1408
+ * Create an UseReactServerErrorHandler.
1409
+ *
1410
+ * @param options - UseReactServerErrorHandler options.
1411
+ */
1412
+ constructor({ blueprint }: UseReactServerErrorHandlerOptions);
1413
+ /**
1414
+ * Handle an error.
1415
+ *
1416
+ * @param error - The error to handle.
1417
+ * @param context - The context of the adapter.
1418
+ * @returns The raw response.
1419
+ */
1420
+ handle(error: any, context: AdapterErrorContext<unknown, unknown, unknown>): Promise<AdapterEventBuilderType<unknown>>;
1421
+ /**
1422
+ * Get the error body.
1423
+ *
1424
+ * @param error - The error to handle.
1425
+ * @returns The error body.
1426
+ */
1427
+ private getErrorBody;
1428
+ }
1429
+
1430
+ /**
1431
+ * Sets the error handler for the React adapter and registers error pages.
1432
+ *
1433
+ * @param errorHandler - The error handler to set for the React adapter.
1434
+ * @param context - The blueprint context containing modules and blueprint.
1435
+ * @returns The updated blueprint context with the error handler and error pages set.
1436
+ */
1437
+ declare function setUseReactAdapterErrorHandler(errorHandler: typeof UseReactServerErrorHandler | typeof UseReactBrowserErrorHandler, context: BlueprintContext<IBlueprint, ClassType>): BlueprintContext<IBlueprint, ClassType>;
1438
+
1439
+ /**
1440
+ * UseReact decorator options.
1441
+ */
1442
+ interface UseReactOptions extends Partial<UseReactConfig> {
1443
+ }
1444
+ /**
1445
+ * UseReact decorator.
1446
+ *
1447
+ * UseReact is a class decorator that allows you to use React components in your Stone application.
1448
+ * The decorator is used to define the React configuration for the class.
1449
+ *
1450
+ * @param options - UseReactOptions
1451
+ * @returns ClassDecorator
1452
+ */
1453
+ declare const UseReact: <T extends ClassType = ClassType>(options?: UseReactOptions) => ClassDecorator;
1473
1454
 
1474
1455
  /**
1475
1456
  * Adapter Middleware for handling outgoing responses and rendering them in the browser.
@@ -1538,29 +1519,48 @@ declare const MetaBrowserResponseMiddleware: {
1538
1519
  };
1539
1520
 
1540
1521
  /**
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.
1522
+ * Default blueprint for a React-based Stone.js application.
1523
+ *
1524
+ * - Defines middleware, lifecycle hooks, and the default HTML template path.
1550
1525
  */
1551
- declare const REACT_PAGE_LAYOUT_KEY: unique symbol;
1526
+ declare const useReactBlueprint: UseReactBlueprint;
1527
+
1552
1528
  /**
1553
- * A unique symbol key to mark classes as React Error handler component.
1529
+ * Blueprint middleware to set BrowserResponseMiddleware for the Browser adapter.
1530
+ *
1531
+ * The MetaBrowserResponseMiddleware is an adapter middleware and is useful
1532
+ * for handling outgoing responses and rendering them in the browser.
1533
+ *
1534
+ * @param context - The configuration context containing modules and blueprint.
1535
+ * @param next - The next pipeline function to continue processing.
1536
+ * @returns The updated blueprint or a promise resolving to it.
1537
+ *
1538
+ * @example
1539
+ * ```typescript
1540
+ * SetBrowserResponseMiddlewareMiddleware(context, next)
1541
+ * ```
1554
1542
  */
1555
- declare const REACT_ERROR_PAGE_KEY: unique symbol;
1543
+ declare const SetBrowserResponseMiddlewareMiddleware: (context: BlueprintContext<IBlueprint, ClassType>, next: NextMiddleware<BlueprintContext<IBlueprint, ClassType>, IBlueprint>) => Promise<IBlueprint>;
1556
1544
  /**
1557
- * A unique symbol key to mark classes as React Adapter Error handler component.
1545
+ * Blueprint middleware to process and register adapter error page definitions from modules.
1546
+ *
1547
+ * @param context - The configuration context containing modules and blueprint.
1548
+ * @param next - The next pipeline function to continue processing.
1549
+ * @returns The updated blueprint or a promise resolving to it.
1550
+ *
1551
+ * @example
1552
+ * ```typescript
1553
+ * SetReactAdapterErrorPageMiddleware(context, next)
1554
+ * ```
1558
1555
  */
1559
- declare const REACT_ADAPTER_ERROR_PAGE_KEY: unique symbol;
1556
+ declare const SetReactAdapterErrorPageMiddleware: (context: BlueprintContext<IBlueprint, ClassType>, next: NextMiddleware<BlueprintContext<IBlueprint, ClassType>, IBlueprint>) => Promiseable<IBlueprint>;
1560
1557
  /**
1561
- * A unique symbol key to mark classes as React Stone application entry point.
1558
+ * Configuration for react processing middleware.
1559
+ *
1560
+ * This array defines a list of middleware pipes, each with a `pipe` function and a `priority`.
1561
+ * These pipes are executed in the order of their priority values, with lower values running first.
1562
1562
  */
1563
- declare const STONE_REACT_APP_KEY: unique symbol;
1563
+ declare const metaBrowserUseReactBlueprintMiddleware: Array<MetaMiddleware<BlueprintContext<IBlueprint, ClassType>, IBlueprint>>;
1564
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 };
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, SetUseReactEventHandlerMiddleware, SetUseReactHooksMiddleware, Snapshot, StoneClient, StoneContext, StoneError, StoneLink, StoneOutlet, StonePage, StoneServer, UseReact, UseReactBrowserErrorHandler, UseReactError, UseReactEventHandler, UseReactKernelErrorHandler, UseReactServiceProvider, applyHeadContextToDom, applyHeadContextToHtmlString, applyMeta, buildAdapterErrorComponent, buildAppComponent, buildLayoutComponent, buildPageComponent, defineAdapterErrorPage, defineErrorPage, definePage, definePageLayout, defineStoneReactApp, executeHandler, executeHooks, getAppRootElement, getBrowserContent, getResponseSnapshot, getServerContent, htmlTemplate, hydrateReactApp, internalUseReactBlueprint, isClient, isSSR, isServer, metaBrowserUseReactBlueprintMiddleware, onPreparingResponse, prepareErrorPage, prepareFallbackErrorPage, preparePage, reactRedirectResponse, reactResponse, renderReactApp, renderStoneSnapshot, resolveComponent, resolveLazyComponent, setUseReactAdapterErrorHandler, 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, ReactRedirectResponseOptions, ReactResponseOptions, ReactRuntimeOptions, ResponseSnapshotType, StoneContextType, StoneLinkOptions, StoneOutletOptions, UseReactAppConfig, UseReactBlueprint, UseReactBrowserErrorHandlerOptions, UseReactConfig, UseReactErrorResponseType, UseReactHookListener, UseReactHookListenerContext, UseReactHookName, UseReactHookType, UseReactOptions, UseReactServiceProviderOptions };