@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.
- package/dist/auth/index.browser.js +603 -242
- package/dist/auth/index.browser.js.map +1 -1
- package/dist/auth/index.d.ts +6 -6
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +1296 -922
- package/dist/auth/index.js.map +1 -1
- package/dist/core/index.d.ts +128 -128
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +20 -20
- package/dist/core/index.js.map +1 -1
- package/dist/form/index.d.ts +36 -36
- package/dist/form/index.d.ts.map +1 -1
- package/dist/form/index.js +15 -15
- package/dist/form/index.js.map +1 -1
- package/dist/head/index.browser.js +20 -0
- package/dist/head/index.browser.js.map +1 -1
- package/dist/head/index.d.ts +73 -65
- package/dist/head/index.d.ts.map +1 -1
- package/dist/head/index.js +20 -0
- package/dist/head/index.js.map +1 -1
- package/dist/i18n/index.d.ts +37 -37
- package/dist/i18n/index.d.ts.map +1 -1
- package/dist/i18n/index.js.map +1 -1
- package/dist/router/index.browser.js +605 -244
- package/dist/router/index.browser.js.map +1 -1
- package/dist/router/index.d.ts +539 -550
- package/dist/router/index.d.ts.map +1 -1
- package/dist/router/index.js +1296 -922
- package/dist/router/index.js.map +1 -1
- package/dist/websocket/index.d.ts +38 -38
- package/dist/websocket/index.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/auth/__tests__/$auth.spec.ts +162 -147
- package/src/auth/index.ts +9 -3
- package/src/auth/services/ReactAuth.ts +15 -5
- package/src/core/hooks/useAction.ts +1 -2
- package/src/core/index.ts +4 -4
- package/src/form/errors/FormValidationError.ts +4 -6
- package/src/form/hooks/useFormState.ts +1 -1
- package/src/form/index.ts +1 -1
- package/src/form/services/FormModel.ts +31 -25
- package/src/head/helpers/SeoExpander.ts +2 -1
- package/src/head/hooks/useHead.spec.tsx +2 -2
- package/src/head/index.browser.ts +2 -2
- package/src/head/index.ts +4 -4
- package/src/head/interfaces/Head.ts +15 -3
- package/src/head/primitives/$head.ts +2 -5
- package/src/head/providers/BrowserHeadProvider.ts +55 -0
- package/src/head/providers/HeadProvider.ts +4 -1
- package/src/i18n/__tests__/integration.spec.tsx +1 -1
- package/src/i18n/components/Localize.spec.tsx +2 -2
- package/src/i18n/hooks/useI18n.browser.spec.tsx +2 -2
- package/src/i18n/index.ts +1 -1
- package/src/i18n/primitives/$dictionary.ts +1 -1
- package/src/i18n/providers/I18nProvider.spec.ts +1 -1
- package/src/i18n/providers/I18nProvider.ts +1 -1
- package/src/router/__tests__/page-head-browser.browser.spec.ts +5 -1
- package/src/router/__tests__/page-head.spec.ts +11 -7
- package/src/router/__tests__/seo-head.spec.ts +7 -3
- package/src/router/atoms/ssrManifestAtom.ts +2 -11
- package/src/router/components/ErrorViewer.tsx +626 -167
- package/src/router/components/Link.tsx +4 -2
- package/src/router/components/NestedView.tsx +7 -9
- package/src/router/components/NotFound.tsx +2 -2
- package/src/router/hooks/useQueryParams.ts +1 -1
- package/src/router/hooks/useRouter.ts +1 -1
- package/src/router/hooks/useRouterState.ts +1 -1
- package/src/router/index.browser.ts +10 -11
- package/src/router/index.shared.ts +7 -7
- package/src/router/index.ts +10 -7
- package/src/router/primitives/$page.browser.spec.tsx +6 -1
- package/src/router/primitives/$page.spec.tsx +7 -1
- package/src/router/primitives/$page.ts +5 -9
- package/src/router/providers/ReactBrowserProvider.ts +17 -6
- package/src/router/providers/ReactBrowserRouterProvider.ts +1 -1
- package/src/router/providers/ReactPageProvider.ts +4 -3
- package/src/router/providers/ReactServerProvider.ts +29 -37
- package/src/router/providers/ReactServerTemplateProvider.ts +300 -137
- package/src/router/providers/SSRManifestProvider.ts +17 -60
- package/src/router/services/ReactPageService.ts +4 -1
- 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 (
|
|
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
|
-
|
|
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(
|
|
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(
|
|
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
|
|
214
|
+
* Check if manifest is loaded and available.
|
|
247
215
|
*/
|
|
248
216
|
public isAvailable(): boolean {
|
|
249
|
-
return this.clientManifest !== 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:
|
|
279
|
-
css: entry.css?.map((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
|
-
*
|
|
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 {
|
|
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,
|
|
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 {
|
|
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(
|