@alepha/react 0.15.0 → 0.15.1

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 (81) hide show
  1. package/dist/auth/index.browser.js +603 -242
  2. package/dist/auth/index.browser.js.map +1 -1
  3. package/dist/auth/index.d.ts +6 -6
  4. package/dist/auth/index.d.ts.map +1 -1
  5. package/dist/auth/index.js +1296 -922
  6. package/dist/auth/index.js.map +1 -1
  7. package/dist/core/index.d.ts +128 -128
  8. package/dist/core/index.d.ts.map +1 -1
  9. package/dist/core/index.js +20 -20
  10. package/dist/core/index.js.map +1 -1
  11. package/dist/form/index.d.ts +36 -36
  12. package/dist/form/index.d.ts.map +1 -1
  13. package/dist/form/index.js +15 -15
  14. package/dist/form/index.js.map +1 -1
  15. package/dist/head/index.browser.js +20 -0
  16. package/dist/head/index.browser.js.map +1 -1
  17. package/dist/head/index.d.ts +73 -65
  18. package/dist/head/index.d.ts.map +1 -1
  19. package/dist/head/index.js +20 -0
  20. package/dist/head/index.js.map +1 -1
  21. package/dist/i18n/index.d.ts +37 -37
  22. package/dist/i18n/index.d.ts.map +1 -1
  23. package/dist/i18n/index.js.map +1 -1
  24. package/dist/router/index.browser.js +605 -244
  25. package/dist/router/index.browser.js.map +1 -1
  26. package/dist/router/index.d.ts +539 -550
  27. package/dist/router/index.d.ts.map +1 -1
  28. package/dist/router/index.js +1296 -922
  29. package/dist/router/index.js.map +1 -1
  30. package/dist/websocket/index.d.ts +38 -38
  31. package/dist/websocket/index.d.ts.map +1 -1
  32. package/package.json +6 -6
  33. package/src/auth/__tests__/$auth.spec.ts +162 -147
  34. package/src/auth/index.ts +9 -3
  35. package/src/auth/services/ReactAuth.ts +15 -5
  36. package/src/core/hooks/useAction.ts +1 -2
  37. package/src/core/index.ts +4 -4
  38. package/src/form/errors/FormValidationError.ts +4 -6
  39. package/src/form/hooks/useFormState.ts +1 -1
  40. package/src/form/index.ts +1 -1
  41. package/src/form/services/FormModel.ts +31 -25
  42. package/src/head/helpers/SeoExpander.ts +2 -1
  43. package/src/head/hooks/useHead.spec.tsx +2 -2
  44. package/src/head/index.browser.ts +2 -2
  45. package/src/head/index.ts +4 -4
  46. package/src/head/interfaces/Head.ts +15 -3
  47. package/src/head/primitives/$head.ts +2 -5
  48. package/src/head/providers/BrowserHeadProvider.ts +55 -0
  49. package/src/head/providers/HeadProvider.ts +4 -1
  50. package/src/i18n/__tests__/integration.spec.tsx +1 -1
  51. package/src/i18n/components/Localize.spec.tsx +2 -2
  52. package/src/i18n/hooks/useI18n.browser.spec.tsx +2 -2
  53. package/src/i18n/index.ts +1 -1
  54. package/src/i18n/primitives/$dictionary.ts +1 -1
  55. package/src/i18n/providers/I18nProvider.spec.ts +1 -1
  56. package/src/i18n/providers/I18nProvider.ts +1 -1
  57. package/src/router/__tests__/page-head-browser.browser.spec.ts +5 -1
  58. package/src/router/__tests__/page-head.spec.ts +11 -7
  59. package/src/router/__tests__/seo-head.spec.ts +7 -3
  60. package/src/router/atoms/ssrManifestAtom.ts +2 -11
  61. package/src/router/components/ErrorViewer.tsx +626 -167
  62. package/src/router/components/Link.tsx +4 -2
  63. package/src/router/components/NestedView.tsx +7 -9
  64. package/src/router/components/NotFound.tsx +2 -2
  65. package/src/router/hooks/useQueryParams.ts +1 -1
  66. package/src/router/hooks/useRouter.ts +1 -1
  67. package/src/router/hooks/useRouterState.ts +1 -1
  68. package/src/router/index.browser.ts +10 -11
  69. package/src/router/index.shared.ts +7 -7
  70. package/src/router/index.ts +10 -7
  71. package/src/router/primitives/$page.browser.spec.tsx +6 -1
  72. package/src/router/primitives/$page.spec.tsx +7 -1
  73. package/src/router/primitives/$page.ts +5 -9
  74. package/src/router/providers/ReactBrowserProvider.ts +17 -6
  75. package/src/router/providers/ReactBrowserRouterProvider.ts +1 -1
  76. package/src/router/providers/ReactPageProvider.ts +4 -3
  77. package/src/router/providers/ReactServerProvider.ts +29 -37
  78. package/src/router/providers/ReactServerTemplateProvider.ts +300 -137
  79. package/src/router/providers/SSRManifestProvider.ts +17 -60
  80. package/src/router/services/ReactPageService.ts +4 -1
  81. package/src/router/services/ReactRouter.ts +6 -5
@@ -1,10 +1,10 @@
1
1
  import { $inject, Alepha, type Static } from "alepha";
2
2
  import {
3
- ssrManifestAtom,
4
3
  type SsrManifestAtomSchema,
4
+ ssrManifestAtom,
5
5
  } from "../atoms/ssrManifestAtom.ts";
6
- import type { PageRoute } from "./ReactPageProvider.ts";
7
6
  import { PAGE_PRELOAD_KEY } from "../constants/PAGE_PRELOAD_KEY.ts";
7
+ import type { PageRoute } from "./ReactPageProvider.ts";
8
8
 
9
9
  /**
10
10
  * Provider for SSR manifest data used for module preloading.
@@ -15,7 +15,6 @@ import { PAGE_PRELOAD_KEY } from "../constants/PAGE_PRELOAD_KEY.ts";
15
15
  *
16
16
  * Manifest files are generated during `vite build`:
17
17
  * - manifest.json (client manifest)
18
- * - ssr-manifest.json (SSR manifest)
19
18
  * - preload-manifest.json (from viteAlephaSsrPreload plugin)
20
19
  */
21
20
  export class SSRManifestProvider {
@@ -26,7 +25,11 @@ export class SSRManifestProvider {
26
25
  * This ensures the manifest is available even when set after module load.
27
26
  */
28
27
  protected get manifest(): Static<SsrManifestAtomSchema> {
29
- return (this.alepha.store.get(ssrManifestAtom) as Static<SsrManifestAtomSchema>) ?? {};
28
+ return (
29
+ (this.alepha.store.get(
30
+ ssrManifestAtom,
31
+ ) as Static<SsrManifestAtomSchema>) ?? {}
32
+ );
30
33
  }
31
34
 
32
35
  /**
@@ -36,13 +39,6 @@ export class SSRManifestProvider {
36
39
  return this.manifest.preload;
37
40
  }
38
41
 
39
- /**
40
- * Get the SSR manifest.
41
- */
42
- protected get ssrManifest(): SSRManifest | undefined {
43
- return this.manifest.ssr;
44
- }
45
-
46
42
  /**
47
43
  * Get the client manifest.
48
44
  */
@@ -66,16 +62,14 @@ export class SSRManifestProvider {
66
62
  /**
67
63
  * Get all chunks required for a source file, including transitive dependencies.
68
64
  *
69
- * Uses the client manifest to recursively resolve all imported chunks,
70
- * not just the direct chunks from the SSR manifest.
65
+ * Uses the client manifest to recursively resolve all imported chunks.
71
66
  *
72
67
  * @param sourcePath - Source file path (e.g., "src/pages/Home.tsx")
73
68
  * @returns Array of chunk URLs to preload, or empty array if not found
74
69
  */
75
70
  public getChunks(sourcePath: string): string[] {
76
71
  if (!this.clientManifest) {
77
- // Fallback to SSR manifest if client manifest not available
78
- return this.getChunksFromSSRManifest(sourcePath);
72
+ return [];
79
73
  }
80
74
 
81
75
  // Find entry in client manifest
@@ -134,13 +128,13 @@ export class SSRManifestProvider {
134
128
 
135
129
  // Add main chunk file (with leading slash for URL)
136
130
  if (entry.file) {
137
- chunks.add("/" + entry.file);
131
+ chunks.add(`/${entry.file}`);
138
132
  }
139
133
 
140
134
  // Add CSS files
141
135
  if (entry.css) {
142
136
  for (const css of entry.css) {
143
- chunks.add("/" + css);
137
+ chunks.add(`/${css}`);
144
138
  }
145
139
  }
146
140
 
@@ -159,31 +153,6 @@ export class SSRManifestProvider {
159
153
  // Those are lazy-loaded and shouldn't be preloaded
160
154
  }
161
155
 
162
- /**
163
- * Fallback to SSR manifest for chunk lookup.
164
- */
165
- protected getChunksFromSSRManifest(sourcePath: string): string[] {
166
- if (!this.ssrManifest) {
167
- return [];
168
- }
169
-
170
- // Try exact match
171
- if (this.ssrManifest[sourcePath]) {
172
- return this.ssrManifest[sourcePath];
173
- }
174
-
175
- // Try with different extensions
176
- const basePath = sourcePath.replace(/\.[^.]+$/, "");
177
- for (const ext of [".tsx", ".ts", ".jsx", ".js"]) {
178
- const pathWithExt = basePath + ext;
179
- if (this.ssrManifest[pathWithExt]) {
180
- return this.ssrManifest[pathWithExt];
181
- }
182
- }
183
-
184
- return [];
185
- }
186
-
187
156
  /**
188
157
  * Collect modulepreload links for a route and its parent chain.
189
158
  */
@@ -200,8 +169,7 @@ export class SSRManifestProvider {
200
169
  while (current) {
201
170
  const preloadKey = current[PAGE_PRELOAD_KEY];
202
171
  if (preloadKey) {
203
- const sourcePath =
204
- this.resolvePreloadKey(preloadKey);
172
+ const sourcePath = this.resolvePreloadKey(preloadKey);
205
173
  if (sourcePath) {
206
174
  preloadPaths.push(sourcePath);
207
175
  }
@@ -243,10 +211,10 @@ export class SSRManifestProvider {
243
211
  }
244
212
 
245
213
  /**
246
- * Check if manifests are loaded and available.
214
+ * Check if manifest is loaded and available.
247
215
  */
248
216
  public isAvailable(): boolean {
249
- return this.clientManifest !== undefined || this.ssrManifest !== undefined;
217
+ return this.clientManifest !== undefined;
250
218
  }
251
219
 
252
220
  /**
@@ -275,8 +243,8 @@ export class SSRManifestProvider {
275
243
  for (const [key, entry] of Object.entries(this.clientManifest)) {
276
244
  if (entry.isEntry) {
277
245
  this.cachedEntryAssets = {
278
- js: "/" + entry.file,
279
- css: entry.css?.map((css) => "/" + css) ?? [],
246
+ js: `/${entry.file}`,
247
+ css: entry.css?.map((css) => `/${css}`) ?? [],
280
248
  };
281
249
  return this.cachedEntryAssets;
282
250
  }
@@ -324,7 +292,6 @@ export class SSRManifestProvider {
324
292
 
325
293
  // ---------------------------------------------------------------------------------------------------------------------
326
294
 
327
-
328
295
  /**
329
296
  * Entry assets structure containing the main entry JS and associated CSS files.
330
297
  */
@@ -335,26 +302,16 @@ export interface EntryAssets {
335
302
  css: string[];
336
303
  }
337
304
 
338
- /**
339
- * SSR Manifest structure from Vite.
340
- * Maps source file paths to their required chunks/assets.
341
- */
342
- export type SSRManifest = Record<string, string[]>;
343
-
344
305
  /**
345
306
  * Client manifest structure from Vite.
346
- * Maps source files to their output information.
307
+ * Only includes fields actually used for preloading.
347
308
  */
348
309
  export interface ClientManifest {
349
310
  [key: string]: {
350
311
  file: string;
351
- src?: string;
352
312
  isEntry?: boolean;
353
- isDynamicEntry?: boolean;
354
313
  imports?: string[];
355
- dynamicImports?: string[];
356
314
  css?: string[];
357
- assets?: string[];
358
315
  };
359
316
  }
360
317
 
@@ -1,5 +1,8 @@
1
1
  import { AlephaError } from "alepha";
2
- import type { PagePrimitiveRenderOptions, PagePrimitiveRenderResult, } from "../../router/primitives/$page.ts";
2
+ import type {
3
+ PagePrimitiveRenderOptions,
4
+ PagePrimitiveRenderResult,
5
+ } from "../../router/primitives/$page.ts";
3
6
 
4
7
  /**
5
8
  * $page methods interface.
@@ -1,11 +1,11 @@
1
1
  import { $inject, Alepha } from "alepha";
2
+ import type { PagePrimitive } from "../primitives/$page.ts";
2
3
  import { ReactBrowserProvider } from "../providers/ReactBrowserProvider.ts";
3
4
  import {
4
- type AnchorProps, type PageRoute,
5
+ type AnchorProps,
5
6
  ReactPageProvider,
6
7
  type ReactRouterState,
7
8
  } from "../providers/ReactPageProvider.ts";
8
- import type { PagePrimitive, PagePrimitiveOptions } from "../primitives/$page.ts";
9
9
 
10
10
  export interface RouterGoOptions {
11
11
  replace?: boolean;
@@ -70,14 +70,15 @@ export class ReactRouter<T extends object> {
70
70
  params?: Record<string, any>;
71
71
  query?: Record<string, any>;
72
72
  } = {},
73
- ): any { // TODO: improve typing (or just remove this method)
73
+ ): any {
74
+ // TODO: improve typing (or just remove this method)
74
75
  const page = this.pageApi.page(name as string);
75
76
  if (!page.lazy && !page.component) {
76
77
  return {
77
78
  ...page,
78
79
  label: page.label ?? page.name,
79
80
  children: undefined,
80
- }
81
+ };
81
82
  }
82
83
 
83
84
  return {
@@ -85,7 +86,7 @@ export class ReactRouter<T extends object> {
85
86
  label: page.label ?? page.name,
86
87
  href: this.path(name, config),
87
88
  children: undefined,
88
- }
89
+ };
89
90
  }
90
91
 
91
92
  public path(