@alepha/react 0.11.10 → 0.11.12

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.
Files changed (128) hide show
  1. package/README.md +1 -183
  2. package/dist/auth/index.browser.js +1460 -0
  3. package/dist/auth/index.browser.js.map +1 -0
  4. package/dist/auth/index.cjs +3647 -0
  5. package/dist/auth/index.cjs.map +1 -0
  6. package/dist/auth/index.d.cts +564 -0
  7. package/dist/auth/index.d.cts.map +1 -0
  8. package/dist/auth/index.d.ts +564 -0
  9. package/dist/auth/index.d.ts.map +1 -0
  10. package/dist/auth/index.js +3615 -0
  11. package/dist/auth/index.js.map +1 -0
  12. package/dist/{index.browser.js → core/index.browser.js} +36 -35
  13. package/dist/core/index.browser.js.map +1 -0
  14. package/dist/{index.cjs → core/index.cjs} +141 -140
  15. package/dist/core/index.cjs.map +1 -0
  16. package/dist/{index.d.cts → core/index.d.cts} +68 -68
  17. package/dist/core/index.d.cts.map +1 -0
  18. package/dist/{index.d.ts → core/index.d.ts} +68 -68
  19. package/dist/core/index.d.ts.map +1 -0
  20. package/dist/{index.js → core/index.js} +39 -38
  21. package/dist/core/index.js.map +1 -0
  22. package/dist/form/index.cjs +2054 -0
  23. package/dist/form/index.cjs.map +1 -0
  24. package/dist/form/index.d.cts +211 -0
  25. package/dist/form/index.d.cts.map +1 -0
  26. package/dist/form/index.d.ts +211 -0
  27. package/dist/form/index.d.ts.map +1 -0
  28. package/dist/form/index.js +2026 -0
  29. package/dist/form/index.js.map +1 -0
  30. package/dist/head/index.browser.js +1503 -0
  31. package/dist/head/index.browser.js.map +1 -0
  32. package/dist/head/index.cjs +1908 -0
  33. package/dist/head/index.cjs.map +1 -0
  34. package/dist/head/index.d.cts +595 -0
  35. package/dist/head/index.d.cts.map +1 -0
  36. package/dist/head/index.d.ts +601 -0
  37. package/dist/head/index.d.ts.map +1 -0
  38. package/dist/head/index.js +1880 -0
  39. package/dist/head/index.js.map +1 -0
  40. package/dist/i18n/index.cjs +1886 -0
  41. package/dist/i18n/index.cjs.map +1 -0
  42. package/dist/i18n/index.d.cts +168 -0
  43. package/dist/i18n/index.d.cts.map +1 -0
  44. package/dist/i18n/index.d.ts +168 -0
  45. package/dist/i18n/index.d.ts.map +1 -0
  46. package/dist/i18n/index.js +1857 -0
  47. package/dist/i18n/index.js.map +1 -0
  48. package/dist/websocket/index.cjs +1774 -0
  49. package/dist/websocket/index.cjs.map +1 -0
  50. package/dist/websocket/index.d.cts +118 -0
  51. package/dist/websocket/index.d.cts.map +1 -0
  52. package/dist/websocket/index.d.ts +118 -0
  53. package/dist/websocket/index.d.ts.map +1 -0
  54. package/dist/websocket/index.js +1750 -0
  55. package/dist/websocket/index.js.map +1 -0
  56. package/package.json +89 -67
  57. package/src/auth/descriptors/$auth.ts +436 -0
  58. package/src/auth/descriptors/$authApple.ts +8 -0
  59. package/src/auth/descriptors/$authGithub.ts +81 -0
  60. package/src/auth/descriptors/$authGoogle.ts +38 -0
  61. package/src/auth/errors/SessionExpiredError.ts +6 -0
  62. package/src/auth/hooks/useAuth.ts +31 -0
  63. package/src/auth/index.browser.ts +16 -0
  64. package/src/auth/index.shared.ts +3 -0
  65. package/src/auth/index.ts +47 -0
  66. package/src/auth/providers/ReactAuthProvider.ts +629 -0
  67. package/src/auth/schemas/tokenResponseSchema.ts +11 -0
  68. package/src/auth/schemas/tokensSchema.ts +21 -0
  69. package/src/auth/schemas/userinfoResponseSchema.ts +10 -0
  70. package/src/auth/services/ReactAuth.ts +124 -0
  71. package/src/{components → core/components}/ErrorViewer.tsx +3 -2
  72. package/src/{components → core/components}/NestedView.tsx +1 -1
  73. package/src/{contexts → core/contexts}/AlephaContext.ts +1 -1
  74. package/src/{descriptors → core/descriptors}/$page.ts +4 -4
  75. package/src/{hooks → core/hooks}/useAction.ts +1 -1
  76. package/src/{hooks → core/hooks}/useAlepha.ts +1 -1
  77. package/src/{hooks → core/hooks}/useClient.ts +1 -1
  78. package/src/{hooks → core/hooks}/useEvents.ts +1 -1
  79. package/src/{hooks → core/hooks}/useInject.ts +1 -1
  80. package/src/{hooks → core/hooks}/useQueryParams.ts +1 -1
  81. package/src/{hooks → core/hooks}/useRouterState.ts +1 -1
  82. package/src/{hooks → core/hooks}/useSchema.ts +3 -3
  83. package/src/{hooks → core/hooks}/useStore.ts +2 -2
  84. package/src/{index.browser.ts → core/index.browser.ts} +4 -4
  85. package/src/{index.ts → core/index.ts} +6 -6
  86. package/src/{providers → core/providers}/ReactBrowserProvider.ts +6 -6
  87. package/src/{providers → core/providers}/ReactBrowserRendererProvider.ts +2 -2
  88. package/src/{providers → core/providers}/ReactBrowserRouterProvider.ts +3 -3
  89. package/src/{providers → core/providers}/ReactPageProvider.ts +3 -3
  90. package/src/{providers → core/providers}/ReactServerProvider.ts +7 -7
  91. package/src/{services → core/services}/ReactPageServerService.ts +2 -2
  92. package/src/{services → core/services}/ReactPageService.ts +1 -1
  93. package/src/{services → core/services}/ReactRouter.ts +1 -1
  94. package/src/form/components/FormState.tsx +17 -0
  95. package/src/form/hooks/useForm.ts +47 -0
  96. package/src/form/hooks/useFormState.ts +130 -0
  97. package/src/form/index.ts +38 -0
  98. package/src/form/services/FormModel.ts +548 -0
  99. package/src/head/descriptors/$head.ts +25 -0
  100. package/src/head/hooks/useHead.ts +62 -0
  101. package/src/head/index.browser.ts +25 -0
  102. package/src/head/index.ts +47 -0
  103. package/src/head/interfaces/Head.ts +46 -0
  104. package/src/head/providers/BrowserHeadProvider.ts +105 -0
  105. package/src/head/providers/HeadProvider.ts +73 -0
  106. package/src/head/providers/ServerHeadProvider.ts +109 -0
  107. package/src/i18n/README.md +76 -0
  108. package/src/i18n/components/Localize.tsx +35 -0
  109. package/src/i18n/descriptors/$dictionary.ts +65 -0
  110. package/src/i18n/hooks/useI18n.ts +18 -0
  111. package/src/i18n/index.ts +34 -0
  112. package/src/i18n/providers/I18nProvider.ts +277 -0
  113. package/src/websocket/hooks/useRoom.tsx +223 -0
  114. package/src/websocket/index.ts +7 -0
  115. package/dist/index.browser.js.map +0 -1
  116. package/dist/index.cjs.map +0 -1
  117. package/dist/index.d.cts.map +0 -1
  118. package/dist/index.d.ts.map +0 -1
  119. package/dist/index.js.map +0 -1
  120. /package/src/{components → core/components}/ClientOnly.tsx +0 -0
  121. /package/src/{components → core/components}/ErrorBoundary.tsx +0 -0
  122. /package/src/{components → core/components}/Link.tsx +0 -0
  123. /package/src/{components → core/components}/NotFound.tsx +0 -0
  124. /package/src/{contexts → core/contexts}/RouterLayerContext.ts +0 -0
  125. /package/src/{errors → core/errors}/Redirection.ts +0 -0
  126. /package/src/{hooks → core/hooks}/useActive.ts +0 -0
  127. /package/src/{hooks → core/hooks}/useRouter.ts +0 -0
  128. /package/src/{index.shared.ts → core/index.shared.ts} +0 -0
@@ -0,0 +1,601 @@
1
+ import * as alepha23 from "alepha";
2
+ import { Alepha, Async, Atom, Descriptor, KIND, Static, TSchema } from "alepha";
3
+ import { DateTimeProvider } from "alepha/datetime";
4
+ import { ServerProvider, ServerRequest, ServerRouterProvider, ServerTimingProvider } from "alepha/server";
5
+ import { ServerRouteCache } from "alepha/server/cache";
6
+ import { LinkProvider } from "alepha/server/links";
7
+ import "alepha/logger";
8
+ import React, { FC, ReactNode } from "react";
9
+ import "react/jsx-runtime";
10
+ import { ServerStaticProvider } from "alepha/server/static";
11
+ import { RouterProvider } from "alepha/router";
12
+ import * as typebox0 from "typebox";
13
+
14
+ //#region src/core/components/ClientOnly.d.ts
15
+ interface ClientOnlyProps {
16
+ fallback?: ReactNode;
17
+ disabled?: boolean;
18
+ }
19
+ //#endregion
20
+ //#region src/core/errors/Redirection.d.ts
21
+ /**
22
+ * Used for Redirection during the page loading.
23
+ *
24
+ * Depends on the context, it can be thrown or just returned.
25
+ */
26
+ declare class Redirection extends Error {
27
+ readonly redirect: string;
28
+ constructor(redirect: string);
29
+ }
30
+ //#endregion
31
+ //#region src/core/providers/ReactPageProvider.d.ts
32
+ declare const envSchema$2: alepha23.TObject<{
33
+ REACT_STRICT_MODE: alepha23.TBoolean;
34
+ }>;
35
+ declare module "alepha" {
36
+ interface Env extends Partial<Static<typeof envSchema$2>> {}
37
+ }
38
+ interface PageRouteEntry extends Omit<PageDescriptorOptions, "children" | "parent"> {
39
+ children?: PageRouteEntry[];
40
+ }
41
+ interface PageRoute extends PageRouteEntry {
42
+ type: "page";
43
+ name: string;
44
+ parent?: PageRoute;
45
+ match: string;
46
+ }
47
+ interface Layer {
48
+ config?: {
49
+ query?: Record<string, any>;
50
+ params?: Record<string, any>;
51
+ context?: Record<string, any>;
52
+ };
53
+ name: string;
54
+ props?: Record<string, any>;
55
+ error?: Error;
56
+ part?: string;
57
+ element: ReactNode;
58
+ index: number;
59
+ path: string;
60
+ route?: PageRoute;
61
+ cache?: boolean;
62
+ }
63
+ type PreviousLayerData = Omit<Layer, "element" | "index" | "path">;
64
+ interface ReactRouterState {
65
+ /**
66
+ * Stack of layers for the current page.
67
+ */
68
+ layers: Array<Layer>;
69
+ /**
70
+ * URL of the current page.
71
+ */
72
+ url: URL;
73
+ /**
74
+ * Error handler for the current page.
75
+ */
76
+ onError: ErrorHandler;
77
+ /**
78
+ * Params extracted from the URL for the current page.
79
+ */
80
+ params: Record<string, any>;
81
+ /**
82
+ * Query parameters extracted from the URL for the current page.
83
+ */
84
+ query: Record<string, string>;
85
+ /**
86
+ * Optional meta information associated with the current page.
87
+ */
88
+ meta: Record<string, any>;
89
+ }
90
+ //#endregion
91
+ //#region src/core/services/ReactPageService.d.ts
92
+ declare class ReactPageService {
93
+ fetch(pathname: string, options?: PageDescriptorRenderOptions): Promise<{
94
+ html: string;
95
+ response: Response;
96
+ }>;
97
+ render(name: string, options?: PageDescriptorRenderOptions): Promise<PageDescriptorRenderResult>;
98
+ }
99
+ //#endregion
100
+ //#region src/core/descriptors/$page.d.ts
101
+
102
+ interface PageDescriptorOptions<TConfig extends PageConfigSchema = PageConfigSchema, TProps extends object = TPropsDefault, TPropsParent extends object = TPropsParentDefault> {
103
+ /**
104
+ * Identifier name for the page. Must be unique.
105
+ *
106
+ * @default Descriptor key
107
+ */
108
+ name?: string;
109
+ /**
110
+ * Add a pathname to the page.
111
+ *
112
+ * Pathname can contain parameters, like `/post/:slug`.
113
+ *
114
+ * @default ""
115
+ */
116
+ path?: string;
117
+ /**
118
+ * Add an input schema to define:
119
+ * - `params`: parameters from the pathname.
120
+ * - `query`: query parameters from the URL.
121
+ */
122
+ schema?: TConfig;
123
+ /**
124
+ * Load data before rendering the page.
125
+ *
126
+ * This function receives
127
+ * - the request context and
128
+ * - the parent props (if page has a parent)
129
+ *
130
+ * In SSR, the returned data will be serialized and sent to the client, then reused during the client-side hydration.
131
+ *
132
+ * Resolve can be stopped by throwing an error, which will be handled by the `errorHandler` function.
133
+ * It's common to throw a `NotFoundError` to display a 404 page.
134
+ *
135
+ * RedirectError can be thrown to redirect the user to another page.
136
+ */
137
+ resolve?: (context: PageResolve<TConfig, TPropsParent>) => Async<TProps>;
138
+ /**
139
+ * The component to render when the page is loaded.
140
+ *
141
+ * If `lazy` is defined, this will be ignored.
142
+ * Prefer using `lazy` to improve the initial loading time.
143
+ */
144
+ component?: FC<TProps & TPropsParent>;
145
+ /**
146
+ * Lazy load the component when the page is loaded.
147
+ *
148
+ * It's recommended to use this for components to improve the initial loading time
149
+ * and enable code-splitting.
150
+ */
151
+ lazy?: () => Promise<{
152
+ default: FC<TProps & TPropsParent>;
153
+ }>;
154
+ /**
155
+ * Attach child pages to create nested routes.
156
+ * This will make the page a parent route.
157
+ */
158
+ children?: Array<PageDescriptor> | (() => Array<PageDescriptor>);
159
+ /**
160
+ * Define a parent page for nested routing.
161
+ */
162
+ parent?: PageDescriptor<PageConfigSchema, TPropsParent, any>;
163
+ can?: () => boolean;
164
+ /**
165
+ * Catch any error from the `resolve` function or during `rendering`.
166
+ *
167
+ * Expected to return one of the following:
168
+ * - a ReactNode to render an error page
169
+ * - a Redirection to redirect the user
170
+ * - undefined to let the error propagate
171
+ *
172
+ * If not defined, the error will be thrown and handled by the server or client error handler.
173
+ * If a leaf $page does not define an error handler, the error can be caught by parent pages.
174
+ *
175
+ * @example Catch a 404 from API and render a custom not found component:
176
+ * ```ts
177
+ * resolve: async ({ params, query }) => {
178
+ * api.fetch("/api/resource", { params, query });
179
+ * },
180
+ * errorHandler: (error, context) => {
181
+ * if (HttpError.is(error, 404)) {
182
+ * return <ResourceNotFound />;
183
+ * }
184
+ * }
185
+ * ```
186
+ *
187
+ * @example Catch an 401 error and redirect the user to the login page:
188
+ * ```ts
189
+ * resolve: async ({ params, query }) => {
190
+ * // but the user is not authenticated
191
+ * api.fetch("/api/resource", { params, query });
192
+ * },
193
+ * errorHandler: (error, context) => {
194
+ * if (HttpError.is(error, 401)) {
195
+ * // throwing a Redirection is also valid!
196
+ * return new Redirection("/login");
197
+ * }
198
+ * }
199
+ * ```
200
+ */
201
+ errorHandler?: ErrorHandler;
202
+ /**
203
+ * If true, the page will be considered as a static page, immutable and cacheable.
204
+ * Replace boolean by an object to define static entries. (e.g. list of params/query)
205
+ *
206
+ * Browser-side: it only works with `alepha/vite`, which can pre-render the page at build time.
207
+ *
208
+ * Server-side: It will act as timeless cached page. You can use `cache` to configure the cache behavior.
209
+ */
210
+ static?: boolean | {
211
+ entries?: Array<Partial<PageRequestConfig<TConfig>>>;
212
+ };
213
+ cache?: ServerRouteCache;
214
+ /**
215
+ * If true, force the page to be rendered only on the client-side (browser).
216
+ * It uses the `<ClientOnly/>` component to render the page.
217
+ */
218
+ client?: boolean | ClientOnlyProps;
219
+ /**
220
+ * Called before the server response is sent to the client. (server only)
221
+ */
222
+ onServerResponse?: (request: ServerRequest) => unknown;
223
+ /**
224
+ * Called when user leaves the page. (browser only)
225
+ */
226
+ onLeave?: () => void;
227
+ /**
228
+ * @experimental
229
+ *
230
+ * Add a css animation when the page is loaded or unloaded.
231
+ * It uses CSS animations, so you need to define the keyframes in your CSS.
232
+ *
233
+ * @example Simple animation name
234
+ * ```ts
235
+ * animation: "fadeIn"
236
+ * ```
237
+ *
238
+ * CSS example:
239
+ * ```css
240
+ * @keyframes fadeIn {
241
+ * from { opacity: 0; }
242
+ * to { opacity: 1; }
243
+ * }
244
+ * ```
245
+ *
246
+ * @example Detailed animation
247
+ * ```ts
248
+ * animation: {
249
+ * enter: { name: "fadeIn", duration: 300 },
250
+ * exit: { name: "fadeOut", duration: 200, timing: "ease-in-out" },
251
+ * }
252
+ * ```
253
+ *
254
+ * @example Only exit animation
255
+ * ```ts
256
+ * animation: {
257
+ * exit: "fadeOut"
258
+ * }
259
+ * ```
260
+ *
261
+ * @example With custom timing function
262
+ * ```ts
263
+ * animation: {
264
+ * enter: { name: "fadeIn", duration: 300, timing: "cubic-bezier(0.4, 0, 0.2, 1)" },
265
+ * exit: { name: "fadeOut", duration: 200, timing: "ease-in-out" },
266
+ * }
267
+ * ```
268
+ */
269
+ animation?: PageAnimation;
270
+ }
271
+ type ErrorHandler = (error: Error, state: ReactRouterState) => ReactNode | Redirection | undefined;
272
+ declare class PageDescriptor<TConfig extends PageConfigSchema = PageConfigSchema, TProps extends object = TPropsDefault, TPropsParent extends object = TPropsParentDefault> extends Descriptor<PageDescriptorOptions<TConfig, TProps, TPropsParent>> {
273
+ protected readonly reactPageService: ReactPageService;
274
+ protected onInit(): void;
275
+ get name(): string;
276
+ /**
277
+ * For testing or build purposes.
278
+ *
279
+ * This will render the page (HTML layout included or not) and return the HTML + context.
280
+ * Only valid for server-side rendering, it will throw an error if called on the client-side.
281
+ */
282
+ render(options?: PageDescriptorRenderOptions): Promise<PageDescriptorRenderResult>;
283
+ fetch(options?: PageDescriptorRenderOptions): Promise<{
284
+ html: string;
285
+ response: Response;
286
+ }>;
287
+ match(url: string): boolean;
288
+ pathname(config: any): string;
289
+ }
290
+ interface PageConfigSchema {
291
+ query?: TSchema;
292
+ params?: TSchema;
293
+ }
294
+ type TPropsDefault = any;
295
+ type TPropsParentDefault = {};
296
+ interface PageDescriptorRenderOptions {
297
+ params?: Record<string, string>;
298
+ query?: Record<string, string>;
299
+ /**
300
+ * If true, the HTML layout will be included in the response.
301
+ * If false, only the page content will be returned.
302
+ *
303
+ * @default true
304
+ */
305
+ html?: boolean;
306
+ hydration?: boolean;
307
+ }
308
+ interface PageDescriptorRenderResult {
309
+ html: string;
310
+ state: ReactRouterState;
311
+ redirect?: string;
312
+ }
313
+ interface PageRequestConfig<TConfig extends PageConfigSchema = PageConfigSchema> {
314
+ params: TConfig["params"] extends TSchema ? Static<TConfig["params"]> : Record<string, string>;
315
+ query: TConfig["query"] extends TSchema ? Static<TConfig["query"]> : Record<string, string>;
316
+ }
317
+ type PageResolve<TConfig extends PageConfigSchema = PageConfigSchema, TPropsParent extends object = TPropsParentDefault> = PageRequestConfig<TConfig> & TPropsParent & Omit<ReactRouterState, "layers" | "onError">;
318
+ type PageAnimation = PageAnimationObject | ((state: ReactRouterState) => PageAnimationObject | undefined);
319
+ type PageAnimationObject = CssAnimationName | {
320
+ enter?: CssAnimation | CssAnimationName;
321
+ exit?: CssAnimation | CssAnimationName;
322
+ };
323
+ type CssAnimationName = string;
324
+ type CssAnimation = {
325
+ name: string;
326
+ duration?: number;
327
+ timing?: string;
328
+ };
329
+ //#endregion
330
+ //#region src/core/providers/ReactBrowserProvider.d.ts
331
+ declare const envSchema$1: alepha23.TObject<{
332
+ REACT_ROOT_ID: alepha23.TString;
333
+ }>;
334
+ declare module "alepha" {
335
+ interface Env extends Partial<Static<typeof envSchema$1>> {}
336
+ }
337
+ /**
338
+ * React browser renderer configuration atom
339
+ */
340
+ declare const reactBrowserOptions: alepha23.Atom<alepha23.TObject<{
341
+ scrollRestoration: typebox0.TUnsafe<"top" | "manual">;
342
+ }>, "alepha.react.browser.options">;
343
+ type ReactBrowserRendererOptions = Static<typeof reactBrowserOptions.schema>;
344
+ declare module "alepha" {
345
+ interface State {
346
+ [reactBrowserOptions.key]: ReactBrowserRendererOptions;
347
+ }
348
+ }
349
+ type ReactHydrationState = {
350
+ layers?: Array<PreviousLayerData>;
351
+ } & {
352
+ [key: string]: any;
353
+ };
354
+ //#endregion
355
+ //#region src/core/providers/ReactServerProvider.d.ts
356
+ declare const envSchema: alepha23.TObject<{
357
+ REACT_SSR_ENABLED: alepha23.TOptional<alepha23.TBoolean>;
358
+ REACT_ROOT_ID: alepha23.TString;
359
+ REACT_SERVER_TEMPLATE: alepha23.TOptional<alepha23.TString>;
360
+ }>;
361
+ declare module "alepha" {
362
+ interface Env extends Partial<Static<typeof envSchema>> {}
363
+ interface State {
364
+ "alepha.react.server.ssr"?: boolean;
365
+ }
366
+ }
367
+ /**
368
+ * React server provider configuration atom
369
+ */
370
+ declare const reactServerOptions: alepha23.Atom<alepha23.TObject<{
371
+ publicDir: alepha23.TString;
372
+ staticServer: alepha23.TObject<{
373
+ disabled: alepha23.TBoolean;
374
+ path: alepha23.TString;
375
+ }>;
376
+ }>, "alepha.react.server.options">;
377
+ type ReactServerProviderOptions = Static<typeof reactServerOptions.schema>;
378
+ declare module "alepha" {
379
+ interface State {
380
+ [reactServerOptions.key]: ReactServerProviderOptions;
381
+ }
382
+ }
383
+ //#endregion
384
+ //#region src/core/index.d.ts
385
+ declare module "alepha" {
386
+ interface State {
387
+ "alepha.react.router.state"?: ReactRouterState;
388
+ }
389
+ interface Hooks {
390
+ /**
391
+ * Fires when the React application is starting to be rendered on the server.
392
+ */
393
+ "react:server:render:begin": {
394
+ request?: ServerRequest;
395
+ state: ReactRouterState;
396
+ };
397
+ /**
398
+ * Fires when the React application has been rendered on the server.
399
+ */
400
+ "react:server:render:end": {
401
+ request?: ServerRequest;
402
+ state: ReactRouterState;
403
+ html: string;
404
+ };
405
+ /**
406
+ * Fires when the React application is being rendered on the browser.
407
+ */
408
+ "react:browser:render": {
409
+ root: HTMLElement;
410
+ element: ReactNode;
411
+ state: ReactRouterState;
412
+ hydration?: ReactHydrationState;
413
+ };
414
+ /**
415
+ * Fires when a user action is starting.
416
+ * Action can be a form submission, a route transition, or a custom action.
417
+ */
418
+ "react:action:begin": {
419
+ type: string;
420
+ id?: string;
421
+ };
422
+ /**
423
+ * Fires when a user action has succeeded.
424
+ * Action can be a form submission, a route transition, or a custom action.
425
+ */
426
+ "react:action:success": {
427
+ type: string;
428
+ id?: string;
429
+ };
430
+ /**
431
+ * Fires when a user action has failed.
432
+ * Action can be a form submission, a route transition, or a custom action.
433
+ */
434
+ "react:action:error": {
435
+ type: string;
436
+ id?: string;
437
+ error: Error;
438
+ };
439
+ /**
440
+ * Fires when a user action has completed, regardless of success or failure.
441
+ * Action can be a form submission, a route transition, or a custom action.
442
+ */
443
+ "react:action:end": {
444
+ type: string;
445
+ id?: string;
446
+ };
447
+ /**
448
+ * Fires when a route transition is starting.
449
+ */
450
+ "react:transition:begin": {
451
+ previous: ReactRouterState;
452
+ state: ReactRouterState;
453
+ animation?: PageAnimation;
454
+ };
455
+ /**
456
+ * Fires when a route transition has succeeded.
457
+ */
458
+ "react:transition:success": {
459
+ state: ReactRouterState;
460
+ };
461
+ /**
462
+ * Fires when a route transition has failed.
463
+ */
464
+ "react:transition:error": {
465
+ state: ReactRouterState;
466
+ error: Error;
467
+ };
468
+ /**
469
+ * Fires when a route transition has completed, regardless of success or failure.
470
+ */
471
+ "react:transition:end": {
472
+ state: ReactRouterState;
473
+ };
474
+ }
475
+ }
476
+ /**
477
+ * Provides full-stack React development with declarative routing, server-side rendering, and client-side hydration.
478
+ *
479
+ * The React module enables building modern React applications using the `$page` descriptor on class properties.
480
+ * It delivers seamless server-side rendering, automatic code splitting, and client-side navigation with full
481
+ * type safety and schema validation for route parameters and data.
482
+ *
483
+ * @see {@link $page}
484
+ * @module alepha.react
485
+ */
486
+ //#endregion
487
+ //#region src/head/interfaces/Head.d.ts
488
+ interface Head extends SimpleHead {
489
+ description?: string;
490
+ keywords?: string[];
491
+ author?: string;
492
+ robots?: string;
493
+ themeColor?: string;
494
+ viewport?: string | {
495
+ width?: string;
496
+ height?: string;
497
+ initialScale?: string;
498
+ maximumScale?: string;
499
+ userScalable?: "no" | "yes" | "0" | "1";
500
+ interactiveWidget?: "resizes-visual" | "resizes-content" | "overlays-content";
501
+ };
502
+ og?: {
503
+ title?: string;
504
+ description?: string;
505
+ image?: string;
506
+ url?: string;
507
+ type?: string;
508
+ };
509
+ twitter?: {
510
+ card?: string;
511
+ title?: string;
512
+ description?: string;
513
+ image?: string;
514
+ site?: string;
515
+ };
516
+ }
517
+ interface SimpleHead {
518
+ title?: string;
519
+ titleSeparator?: string;
520
+ htmlAttributes?: Record<string, string>;
521
+ bodyAttributes?: Record<string, string>;
522
+ meta?: Array<{
523
+ name: string;
524
+ content: string;
525
+ }>;
526
+ }
527
+ //#endregion
528
+ //#region src/head/providers/HeadProvider.d.ts
529
+ declare class HeadProvider {
530
+ global?: Head | (() => Head);
531
+ protected getGlobalHead(): Head | undefined;
532
+ fillHead(state: ReactRouterState): void;
533
+ protected fillHeadByPage(page: PageRoute, state: ReactRouterState, props: Record<string, any>): void;
534
+ }
535
+ //#endregion
536
+ //#region src/head/descriptors/$head.d.ts
537
+ /**
538
+ * Set global `<head>` options for the application.
539
+ */
540
+ declare const $head: {
541
+ (options: HeadDescriptorOptions): HeadDescriptor;
542
+ [KIND]: typeof HeadDescriptor;
543
+ };
544
+ type HeadDescriptorOptions = Head | (() => Head);
545
+ declare class HeadDescriptor extends Descriptor<HeadDescriptorOptions> {
546
+ protected readonly provider: HeadProvider;
547
+ protected onInit(): void;
548
+ }
549
+ //#endregion
550
+ //#region src/head/hooks/useHead.d.ts
551
+ /**
552
+ * ```tsx
553
+ * const App = () => {
554
+ * const [head, setHead] = useHead({
555
+ * // will set the document title on the first render
556
+ * title: "My App",
557
+ * });
558
+ *
559
+ * return (
560
+ * // This will update the document title when the button is clicked
561
+ * <button onClick={() => setHead({ title: "Change Title" })}>
562
+ * Change Title {head.title}
563
+ * </button>
564
+ * );
565
+ * }
566
+ * ```
567
+ */
568
+ declare const useHead: (options?: UseHeadOptions) => UseHeadReturn;
569
+ type UseHeadOptions = Head | ((previous?: Head) => Head);
570
+ type UseHeadReturn = [Head, (head?: Head | ((previous?: Head) => Head)) => void];
571
+ //#endregion
572
+ //#region src/head/providers/ServerHeadProvider.d.ts
573
+ declare class ServerHeadProvider {
574
+ protected readonly headProvider: HeadProvider;
575
+ protected readonly serverTimingProvider: ServerTimingProvider;
576
+ protected readonly onServerRenderEnd: alepha23.HookDescriptor<"react:server:render:end">;
577
+ renderHead(template: string, head: SimpleHead): string;
578
+ protected mergeAttributes(existing: string, attrs: Record<string, string>): string;
579
+ protected parseAttributes(attrStr: string): Record<string, string>;
580
+ protected escapeHtml(str: string): string;
581
+ }
582
+ //#endregion
583
+ //#region src/head/index.d.ts
584
+ declare module "@alepha/react" {
585
+ interface PageDescriptorOptions<TConfig extends PageConfigSchema = PageConfigSchema, TProps extends object = TPropsDefault, TPropsParent extends object = TPropsParentDefault> {
586
+ head?: Head | ((props: TProps, previous?: Head) => Head);
587
+ }
588
+ interface ReactRouterState {
589
+ head: Head;
590
+ }
591
+ }
592
+ /**
593
+ * Fill `<head>` server & client side.
594
+ *
595
+ * @see {@link ServerHeadProvider}
596
+ * @module alepha.react.head
597
+ */
598
+ declare const AlephaReactHead: alepha23.Service<alepha23.Module>;
599
+ //#endregion
600
+ export { $head, AlephaReactHead, Head, HeadDescriptor, HeadDescriptorOptions, ServerHeadProvider, SimpleHead, UseHeadOptions, UseHeadReturn, useHead };
601
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/core/components/ClientOnly.tsx","../../src/core/errors/Redirection.ts","../../src/core/providers/ReactPageProvider.ts","../../src/core/services/ReactPageService.ts","../../src/core/descriptors/$page.ts","../../src/core/providers/ReactBrowserProvider.ts","../../src/core/providers/ReactServerProvider.ts","../../src/core/index.ts","../../src/head/interfaces/Head.ts","../../src/head/providers/HeadProvider.ts","../../src/head/descriptors/$head.ts","../../src/head/hooks/useHead.ts","../../src/head/providers/ServerHeadProvider.ts","../../src/head/index.ts"],"sourcesContent":[],"mappings":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