@alepha/react 0.13.1 → 0.13.2
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 +5 -5
- package/dist/auth/index.browser.js.map +1 -1
- package/dist/auth/index.d.ts +330 -330
- package/dist/auth/index.js +7 -7
- package/dist/auth/index.js.map +1 -1
- package/dist/core/index.browser.js +19 -18
- package/dist/core/index.browser.js.map +1 -1
- package/dist/core/index.d.ts +352 -344
- package/dist/core/index.js +25 -24
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.native.js +381 -0
- package/dist/core/index.native.js.map +1 -0
- package/dist/form/index.d.ts +2 -2
- package/dist/head/index.browser.js +7 -7
- package/dist/head/index.browser.js.map +1 -1
- package/dist/head/index.d.ts +265 -265
- package/dist/head/index.js +7 -7
- package/dist/head/index.js.map +1 -1
- package/dist/i18n/index.d.ts +20 -20
- package/dist/i18n/index.js +12 -12
- package/dist/i18n/index.js.map +1 -1
- package/dist/websocket/index.d.ts +7 -7
- package/dist/websocket/index.js.map +1 -1
- package/package.json +18 -9
- package/src/auth/index.ts +1 -1
- package/src/auth/providers/ReactAuthProvider.ts +1 -1
- package/src/auth/services/ReactAuth.ts +5 -5
- package/src/core/components/NestedView.tsx +1 -1
- package/src/core/hooks/useStore.ts +4 -4
- package/src/core/index.browser.ts +2 -2
- package/src/core/index.native.ts +1 -1
- package/src/core/index.shared-router.ts +1 -1
- package/src/core/index.ts +3 -3
- package/src/core/{descriptors → primitives}/$page.ts +20 -20
- package/src/core/providers/ReactBrowserProvider.ts +2 -2
- package/src/core/providers/ReactBrowserRouterProvider.ts +2 -2
- package/src/core/providers/ReactPageProvider.ts +25 -11
- package/src/core/providers/ReactServerProvider.ts +12 -12
- package/src/core/services/ReactPageServerService.ts +6 -6
- package/src/core/services/ReactPageService.ts +6 -6
- package/src/core/services/ReactRouter.ts +3 -3
- package/src/head/index.browser.ts +3 -3
- package/src/head/index.ts +4 -4
- package/src/head/{descriptors → primitives}/$head.ts +6 -6
- package/src/i18n/hooks/useI18n.ts +2 -2
- package/src/i18n/index.ts +3 -3
- package/src/i18n/{descriptors → primitives}/$dictionary.ts +8 -8
- package/src/i18n/providers/I18nProvider.ts +5 -5
- package/src/websocket/hooks/useRoom.tsx +3 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { memo, type ReactNode, use, useRef, useState } from "react";
|
|
2
2
|
import { RouterLayerContext } from "../contexts/RouterLayerContext.ts";
|
|
3
|
-
import type { PageAnimation } from "../
|
|
3
|
+
import type { PageAnimation } from "../primitives/$page.ts";
|
|
4
4
|
import { Redirection } from "../errors/Redirection.ts";
|
|
5
5
|
import { useEvents } from "../hooks/useEvents.ts";
|
|
6
6
|
import { useRouterState } from "../hooks/useRouterState.ts";
|
|
@@ -18,12 +18,12 @@ function useStore(target: any, defaultValue?: any): any {
|
|
|
18
18
|
const alepha = useAlepha();
|
|
19
19
|
|
|
20
20
|
useMemo(() => {
|
|
21
|
-
if (defaultValue != null && alepha.
|
|
22
|
-
alepha.
|
|
21
|
+
if (defaultValue != null && alepha.store.get(target) == null) {
|
|
22
|
+
alepha.store.set(target, defaultValue);
|
|
23
23
|
}
|
|
24
24
|
}, [defaultValue]);
|
|
25
25
|
|
|
26
|
-
const [state, setState] = useState(alepha.
|
|
26
|
+
const [state, setState] = useState(alepha.store.get(target));
|
|
27
27
|
|
|
28
28
|
useEffect(() => {
|
|
29
29
|
if (!alepha.isBrowser()) {
|
|
@@ -42,7 +42,7 @@ function useStore(target: any, defaultValue?: any): any {
|
|
|
42
42
|
return [
|
|
43
43
|
state,
|
|
44
44
|
(value: any) => {
|
|
45
|
-
alepha.
|
|
45
|
+
alepha.store.set(target, value);
|
|
46
46
|
},
|
|
47
47
|
] as const;
|
|
48
48
|
}
|
|
@@ -2,7 +2,7 @@ import { $module } from "alepha";
|
|
|
2
2
|
import { AlephaDateTime } from "alepha/datetime";
|
|
3
3
|
import { AlephaServer } from "alepha/server";
|
|
4
4
|
import { AlephaServerLinks } from "alepha/server/links";
|
|
5
|
-
import { $page } from "./
|
|
5
|
+
import { $page } from "./primitives/$page.ts";
|
|
6
6
|
import { ReactBrowserProvider } from "./providers/ReactBrowserProvider.ts";
|
|
7
7
|
import { ReactBrowserRendererProvider } from "./providers/ReactBrowserRendererProvider.ts";
|
|
8
8
|
import { ReactBrowserRouterProvider } from "./providers/ReactBrowserRouterProvider.ts";
|
|
@@ -22,7 +22,7 @@ export * from "./providers/ReactPageProvider.ts";
|
|
|
22
22
|
|
|
23
23
|
export const AlephaReact = $module({
|
|
24
24
|
name: "alepha.react",
|
|
25
|
-
|
|
25
|
+
primitives: [$page],
|
|
26
26
|
services: [
|
|
27
27
|
ReactPageProvider,
|
|
28
28
|
ReactBrowserRouterProvider,
|
package/src/core/index.native.ts
CHANGED
|
@@ -5,7 +5,7 @@ export { default as Link, type LinkProps } from "./components/Link.tsx";
|
|
|
5
5
|
export { default as NestedView } from "./components/NestedView.tsx";
|
|
6
6
|
export { default as NotFound } from "./components/NotFound.tsx";
|
|
7
7
|
export * from "./contexts/RouterLayerContext.ts";
|
|
8
|
-
export * from "./
|
|
8
|
+
export * from "./primitives/$page.ts";
|
|
9
9
|
export * from "./errors/Redirection.ts";
|
|
10
10
|
export * from "./hooks/useActive.ts";
|
|
11
11
|
export * from "./hooks/useQueryParams.ts";
|
package/src/core/index.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { AlephaServer, type ServerRequest } from "alepha/server";
|
|
|
4
4
|
import { AlephaServerCache } from "alepha/server/cache";
|
|
5
5
|
import { AlephaServerLinks } from "alepha/server/links";
|
|
6
6
|
import type { ReactNode } from "react";
|
|
7
|
-
import { $page, type PageAnimation } from "./
|
|
7
|
+
import { $page, type PageAnimation } from "./primitives/$page.ts";
|
|
8
8
|
import type { ReactHydrationState } from "./providers/ReactBrowserProvider.ts";
|
|
9
9
|
import {
|
|
10
10
|
ReactPageProvider,
|
|
@@ -128,7 +128,7 @@ declare module "alepha" {
|
|
|
128
128
|
/**
|
|
129
129
|
* Provides full-stack React development with declarative routing, server-side rendering, and client-side hydration.
|
|
130
130
|
*
|
|
131
|
-
* The React module enables building modern React applications using the `$page`
|
|
131
|
+
* The React module enables building modern React applications using the `$page` primitive on class properties.
|
|
132
132
|
* It delivers seamless server-side rendering, automatic code splitting, and client-side navigation with full
|
|
133
133
|
* type safety and schema validation for route parameters and data.
|
|
134
134
|
*
|
|
@@ -137,7 +137,7 @@ declare module "alepha" {
|
|
|
137
137
|
*/
|
|
138
138
|
export const AlephaReact = $module({
|
|
139
139
|
name: "alepha.react",
|
|
140
|
-
|
|
140
|
+
primitives: [$page],
|
|
141
141
|
services: [
|
|
142
142
|
ReactServerProvider,
|
|
143
143
|
ReactPageProvider,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
$inject,
|
|
3
3
|
type Async,
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
createPrimitive,
|
|
5
|
+
Primitive,
|
|
6
6
|
KIND,
|
|
7
7
|
type Static,
|
|
8
8
|
type TSchema,
|
|
@@ -16,9 +16,9 @@ import type { ReactRouterState } from "../providers/ReactPageProvider.ts";
|
|
|
16
16
|
import { ReactPageService } from "../services/ReactPageService.ts";
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
* Main
|
|
19
|
+
* Main primitive for defining a React route in the application.
|
|
20
20
|
*
|
|
21
|
-
* The $page
|
|
21
|
+
* The $page primitive is the core building block for creating type-safe, SSR-enabled React routes.
|
|
22
22
|
* It provides a declarative way to define pages with powerful features:
|
|
23
23
|
*
|
|
24
24
|
* **Routing & Navigation**
|
|
@@ -108,17 +108,17 @@ export const $page = <
|
|
|
108
108
|
TProps extends object = TPropsDefault,
|
|
109
109
|
TPropsParent extends object = TPropsParentDefault,
|
|
110
110
|
>(
|
|
111
|
-
options:
|
|
112
|
-
):
|
|
113
|
-
return
|
|
114
|
-
|
|
111
|
+
options: PagePrimitiveOptions<TConfig, TProps, TPropsParent>,
|
|
112
|
+
): PagePrimitive<TConfig, TProps, TPropsParent> => {
|
|
113
|
+
return createPrimitive(
|
|
114
|
+
PagePrimitive<TConfig, TProps, TPropsParent>,
|
|
115
115
|
options,
|
|
116
116
|
);
|
|
117
117
|
};
|
|
118
118
|
|
|
119
119
|
// ---------------------------------------------------------------------------------------------------------------------
|
|
120
120
|
|
|
121
|
-
export interface
|
|
121
|
+
export interface PagePrimitiveOptions<
|
|
122
122
|
TConfig extends PageConfigSchema = PageConfigSchema,
|
|
123
123
|
TProps extends object = TPropsDefault,
|
|
124
124
|
TPropsParent extends object = TPropsParentDefault,
|
|
@@ -126,7 +126,7 @@ export interface PageDescriptorOptions<
|
|
|
126
126
|
/**
|
|
127
127
|
* Identifier name for the page. Must be unique.
|
|
128
128
|
*
|
|
129
|
-
* @default
|
|
129
|
+
* @default Primitive key
|
|
130
130
|
*/
|
|
131
131
|
name?: string;
|
|
132
132
|
|
|
@@ -182,12 +182,12 @@ export interface PageDescriptorOptions<
|
|
|
182
182
|
* Attach child pages to create nested routes.
|
|
183
183
|
* This will make the page a parent route.
|
|
184
184
|
*/
|
|
185
|
-
children?: Array<
|
|
185
|
+
children?: Array<PagePrimitive> | (() => Array<PagePrimitive>);
|
|
186
186
|
|
|
187
187
|
/**
|
|
188
188
|
* Define a parent page for nested routing.
|
|
189
189
|
*/
|
|
190
|
-
parent?:
|
|
190
|
+
parent?: PagePrimitive<PageConfigSchema, TPropsParent, any>;
|
|
191
191
|
|
|
192
192
|
can?: () => boolean;
|
|
193
193
|
|
|
@@ -312,11 +312,11 @@ export type ErrorHandler = (
|
|
|
312
312
|
state: ReactRouterState,
|
|
313
313
|
) => ReactNode | Redirection | undefined;
|
|
314
314
|
|
|
315
|
-
export class
|
|
315
|
+
export class PagePrimitive<
|
|
316
316
|
TConfig extends PageConfigSchema = PageConfigSchema,
|
|
317
317
|
TProps extends object = TPropsDefault,
|
|
318
318
|
TPropsParent extends object = TPropsParentDefault,
|
|
319
|
-
> extends
|
|
319
|
+
> extends Primitive<PagePrimitiveOptions<TConfig, TProps, TPropsParent>> {
|
|
320
320
|
protected readonly reactPageService = $inject(ReactPageService);
|
|
321
321
|
|
|
322
322
|
protected onInit() {
|
|
@@ -341,12 +341,12 @@ export class PageDescriptor<
|
|
|
341
341
|
* Only valid for server-side rendering, it will throw an error if called on the client-side.
|
|
342
342
|
*/
|
|
343
343
|
public async render(
|
|
344
|
-
options?:
|
|
345
|
-
): Promise<
|
|
344
|
+
options?: PagePrimitiveRenderOptions,
|
|
345
|
+
): Promise<PagePrimitiveRenderResult> {
|
|
346
346
|
return this.reactPageService.render(this.name, options);
|
|
347
347
|
}
|
|
348
348
|
|
|
349
|
-
public async fetch(options?:
|
|
349
|
+
public async fetch(options?: PagePrimitiveRenderOptions): Promise<{
|
|
350
350
|
html: string;
|
|
351
351
|
response: Response;
|
|
352
352
|
}> {
|
|
@@ -364,7 +364,7 @@ export class PageDescriptor<
|
|
|
364
364
|
}
|
|
365
365
|
}
|
|
366
366
|
|
|
367
|
-
$page[KIND] =
|
|
367
|
+
$page[KIND] = PagePrimitive;
|
|
368
368
|
|
|
369
369
|
// ---------------------------------------------------------------------------------------------------------------------
|
|
370
370
|
|
|
@@ -377,7 +377,7 @@ export type TPropsDefault = any;
|
|
|
377
377
|
|
|
378
378
|
export type TPropsParentDefault = {};
|
|
379
379
|
|
|
380
|
-
export interface
|
|
380
|
+
export interface PagePrimitiveRenderOptions {
|
|
381
381
|
params?: Record<string, string>;
|
|
382
382
|
query?: Record<string, string>;
|
|
383
383
|
|
|
@@ -391,7 +391,7 @@ export interface PageDescriptorRenderOptions {
|
|
|
391
391
|
hydration?: boolean;
|
|
392
392
|
}
|
|
393
393
|
|
|
394
|
-
export interface
|
|
394
|
+
export interface PagePrimitiveRenderResult {
|
|
395
395
|
html: string;
|
|
396
396
|
state: ReactRouterState;
|
|
397
397
|
redirect?: string;
|
|
@@ -84,7 +84,7 @@ export class ReactBrowserProvider {
|
|
|
84
84
|
};
|
|
85
85
|
|
|
86
86
|
public get state(): ReactRouterState {
|
|
87
|
-
return this.alepha.
|
|
87
|
+
return this.alepha.store.get("alepha.react.router.state")!;
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
/**
|
|
@@ -262,7 +262,7 @@ export class ReactBrowserProvider {
|
|
|
262
262
|
// low budget, but works for now
|
|
263
263
|
for (const [key, value] of Object.entries(hydration)) {
|
|
264
264
|
if (key !== "layers") {
|
|
265
|
-
this.alepha.
|
|
265
|
+
this.alepha.store.set(key as keyof State, value);
|
|
266
266
|
}
|
|
267
267
|
}
|
|
268
268
|
}
|
|
@@ -63,7 +63,7 @@ export class ReactBrowserRouterProvider extends RouterProvider<BrowserRoute> {
|
|
|
63
63
|
type: "transition",
|
|
64
64
|
});
|
|
65
65
|
await this.alepha.events.emit("react:transition:begin", {
|
|
66
|
-
previous: this.alepha.
|
|
66
|
+
previous: this.alepha.store.get("alepha.react.router.state")!,
|
|
67
67
|
state,
|
|
68
68
|
});
|
|
69
69
|
|
|
@@ -135,7 +135,7 @@ export class ReactBrowserRouterProvider extends RouterProvider<BrowserRoute> {
|
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
-
this.alepha.
|
|
138
|
+
this.alepha.store.set("alepha.react.router.state", state);
|
|
139
139
|
|
|
140
140
|
await this.alepha.events.emit("react:action:end", {
|
|
141
141
|
type: "transition",
|
|
@@ -19,9 +19,9 @@ import { RouterLayerContext } from "../contexts/RouterLayerContext.ts";
|
|
|
19
19
|
import {
|
|
20
20
|
$page,
|
|
21
21
|
type ErrorHandler,
|
|
22
|
-
type
|
|
23
|
-
type
|
|
24
|
-
} from "../
|
|
22
|
+
type PagePrimitive,
|
|
23
|
+
type PagePrimitiveOptions,
|
|
24
|
+
} from "../primitives/$page.ts";
|
|
25
25
|
import { Redirection } from "../errors/Redirection.ts";
|
|
26
26
|
|
|
27
27
|
const envSchema = t.object({
|
|
@@ -42,12 +42,14 @@ export class ReactPageProvider {
|
|
|
42
42
|
return this.pages;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
public getConcretePages():
|
|
46
|
-
const pages:
|
|
45
|
+
public getConcretePages(): ConcretePageRoute[] {
|
|
46
|
+
const pages: ConcretePageRoute[] = [];
|
|
47
47
|
for (const page of this.pages) {
|
|
48
48
|
if (page.children && page.children.length > 0) {
|
|
49
49
|
continue;
|
|
50
50
|
}
|
|
51
|
+
|
|
52
|
+
// check if the page has dynamic params
|
|
51
53
|
const fullPath = this.pathname(page.name);
|
|
52
54
|
if (fullPath.includes(":") || fullPath.includes("*")) {
|
|
53
55
|
if (typeof page.static === "object") {
|
|
@@ -60,6 +62,7 @@ export class ReactPageProvider {
|
|
|
60
62
|
pages.push({
|
|
61
63
|
...page,
|
|
62
64
|
name: params[Object.keys(params)[0]],
|
|
65
|
+
staticName: page.name,
|
|
63
66
|
path,
|
|
64
67
|
...entry,
|
|
65
68
|
});
|
|
@@ -70,6 +73,7 @@ export class ReactPageProvider {
|
|
|
70
73
|
|
|
71
74
|
continue;
|
|
72
75
|
}
|
|
76
|
+
|
|
73
77
|
pages.push(page);
|
|
74
78
|
}
|
|
75
79
|
return pages;
|
|
@@ -481,9 +485,9 @@ export class ReactPageProvider {
|
|
|
481
485
|
on: "configure",
|
|
482
486
|
handler: () => {
|
|
483
487
|
let hasNotFoundHandler = false;
|
|
484
|
-
const pages = this.alepha.
|
|
488
|
+
const pages = this.alepha.primitives($page);
|
|
485
489
|
|
|
486
|
-
const hasParent = (it:
|
|
490
|
+
const hasParent = (it: PagePrimitive) => {
|
|
487
491
|
if (it.options.parent) {
|
|
488
492
|
return true;
|
|
489
493
|
}
|
|
@@ -529,8 +533,8 @@ export class ReactPageProvider {
|
|
|
529
533
|
});
|
|
530
534
|
|
|
531
535
|
protected map(
|
|
532
|
-
pages: Array<
|
|
533
|
-
target:
|
|
536
|
+
pages: Array<PagePrimitive>,
|
|
537
|
+
target: PagePrimitive,
|
|
534
538
|
): PageRouteEntry {
|
|
535
539
|
const children = target.options.children
|
|
536
540
|
? Array.isArray(target.options.children)
|
|
@@ -538,7 +542,7 @@ export class ReactPageProvider {
|
|
|
538
542
|
: target.options.children()
|
|
539
543
|
: [];
|
|
540
544
|
|
|
541
|
-
const getChildrenFromParent = (it:
|
|
545
|
+
const getChildrenFromParent = (it: PagePrimitive): PagePrimitive[] => {
|
|
542
546
|
const children = [];
|
|
543
547
|
for (const page of pages) {
|
|
544
548
|
if (page.options.parent === it) {
|
|
@@ -613,10 +617,20 @@ export const isPageRoute = (it: any): it is PageRoute => {
|
|
|
613
617
|
};
|
|
614
618
|
|
|
615
619
|
export interface PageRouteEntry
|
|
616
|
-
extends Omit<
|
|
620
|
+
extends Omit<PagePrimitiveOptions, "children" | "parent"> {
|
|
617
621
|
children?: PageRouteEntry[];
|
|
618
622
|
}
|
|
619
623
|
|
|
624
|
+
export interface ConcretePageRoute extends PageRoute {
|
|
625
|
+
/**
|
|
626
|
+
* When exported, static routes can be split into multiple pages with different params.
|
|
627
|
+
* We replace 'name' by the new name for each static entry, and old 'name' becomes 'staticName'.
|
|
628
|
+
*/
|
|
629
|
+
staticName?: string;
|
|
630
|
+
|
|
631
|
+
params?: Record<string, string>;
|
|
632
|
+
}
|
|
633
|
+
|
|
620
634
|
export interface PageRoute extends PageRouteEntry {
|
|
621
635
|
type: "page";
|
|
622
636
|
name: string;
|
|
@@ -23,9 +23,9 @@ import { ServerStaticProvider } from "alepha/server/static";
|
|
|
23
23
|
import { renderToString } from "react-dom/server";
|
|
24
24
|
import {
|
|
25
25
|
$page,
|
|
26
|
-
type
|
|
27
|
-
type
|
|
28
|
-
} from "../
|
|
26
|
+
type PagePrimitiveRenderOptions,
|
|
27
|
+
type PagePrimitiveRenderResult,
|
|
28
|
+
} from "../primitives/$page.ts";
|
|
29
29
|
import { Redirection } from "../errors/Redirection.ts";
|
|
30
30
|
import type { ReactHydrationState } from "./ReactBrowserProvider.ts";
|
|
31
31
|
import {
|
|
@@ -112,12 +112,12 @@ export class ReactServerProvider {
|
|
|
112
112
|
public readonly onConfigure = $hook({
|
|
113
113
|
on: "configure",
|
|
114
114
|
handler: async () => {
|
|
115
|
-
const pages = this.alepha.
|
|
115
|
+
const pages = this.alepha.primitives($page);
|
|
116
116
|
|
|
117
117
|
const ssrEnabled =
|
|
118
118
|
pages.length > 0 && this.env.REACT_SSR_ENABLED !== false;
|
|
119
119
|
|
|
120
|
-
this.alepha.
|
|
120
|
+
this.alepha.store.set("alepha.react.server.ssr", ssrEnabled);
|
|
121
121
|
|
|
122
122
|
// development mode
|
|
123
123
|
if (this.alepha.isViteDev()) {
|
|
@@ -192,7 +192,7 @@ export class ReactServerProvider {
|
|
|
192
192
|
|
|
193
193
|
this.serverRouterProvider.createRoute({
|
|
194
194
|
...page,
|
|
195
|
-
schema: undefined, // schema is handled by the page
|
|
195
|
+
schema: undefined, // schema is handled by the page primitive provider for now (shared by browser and server)
|
|
196
196
|
method: "GET",
|
|
197
197
|
path: page.match,
|
|
198
198
|
handler: this.createHandler(page, templateLoader),
|
|
@@ -257,8 +257,8 @@ export class ReactServerProvider {
|
|
|
257
257
|
*/
|
|
258
258
|
public async render(
|
|
259
259
|
name: string,
|
|
260
|
-
options:
|
|
261
|
-
): Promise<
|
|
260
|
+
options: PagePrimitiveRenderOptions = {},
|
|
261
|
+
): Promise<PagePrimitiveRenderResult> {
|
|
262
262
|
const page = this.pageApi.page(name);
|
|
263
263
|
const url = new URL(this.pageApi.url(name, options));
|
|
264
264
|
const entry: Partial<ReactRouterState> = {
|
|
@@ -289,7 +289,7 @@ export class ReactServerProvider {
|
|
|
289
289
|
}
|
|
290
290
|
|
|
291
291
|
if (!options.html) {
|
|
292
|
-
this.alepha.
|
|
292
|
+
this.alepha.store.set("alepha.react.router.state", state);
|
|
293
293
|
|
|
294
294
|
return {
|
|
295
295
|
state,
|
|
@@ -340,7 +340,7 @@ export class ReactServerProvider {
|
|
|
340
340
|
const state = entry as ReactRouterState;
|
|
341
341
|
|
|
342
342
|
if (this.alepha.has(ServerLinksProvider)) {
|
|
343
|
-
this.alepha.
|
|
343
|
+
this.alepha.store.set(
|
|
344
344
|
"alepha.server.request.apiLinks",
|
|
345
345
|
await this.alepha.inject(ServerLinksProvider).getUserApiLinks({
|
|
346
346
|
user: (serverRequest as any).user, // TODO: fix type
|
|
@@ -349,7 +349,7 @@ export class ReactServerProvider {
|
|
|
349
349
|
);
|
|
350
350
|
}
|
|
351
351
|
|
|
352
|
-
let target: PageRoute | undefined = route; // TODO: move to
|
|
352
|
+
let target: PageRoute | undefined = route; // TODO: move to PagePrimitiveProvider
|
|
353
353
|
while (target) {
|
|
354
354
|
if (route.can && !route.can()) {
|
|
355
355
|
// if the page is not accessible, return 403
|
|
@@ -431,7 +431,7 @@ export class ReactServerProvider {
|
|
|
431
431
|
const element = this.pageApi.root(state);
|
|
432
432
|
|
|
433
433
|
// attach react router state to the http request context
|
|
434
|
-
this.alepha.
|
|
434
|
+
this.alepha.store.set("alepha.react.router.state", state);
|
|
435
435
|
|
|
436
436
|
this.serverTimingProvider.beginTiming("renderToString");
|
|
437
437
|
let app = "";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { $inject, AlephaError } from "alepha";
|
|
2
2
|
import { ServerProvider } from "alepha/server";
|
|
3
3
|
import type {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} from "../
|
|
4
|
+
PagePrimitiveRenderOptions,
|
|
5
|
+
PagePrimitiveRenderResult,
|
|
6
|
+
} from "../primitives/$page.ts";
|
|
7
7
|
import { ReactServerProvider } from "../providers/ReactServerProvider.ts";
|
|
8
8
|
import { ReactPageService } from "./ReactPageService.ts";
|
|
9
9
|
|
|
@@ -13,14 +13,14 @@ export class ReactPageServerService extends ReactPageService {
|
|
|
13
13
|
|
|
14
14
|
public async render(
|
|
15
15
|
name: string,
|
|
16
|
-
options:
|
|
17
|
-
): Promise<
|
|
16
|
+
options: PagePrimitiveRenderOptions = {},
|
|
17
|
+
): Promise<PagePrimitiveRenderResult> {
|
|
18
18
|
return this.reactServerProvider.render(name, options);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
public async fetch(
|
|
22
22
|
pathname: string,
|
|
23
|
-
options:
|
|
23
|
+
options: PagePrimitiveRenderOptions = {},
|
|
24
24
|
): Promise<{
|
|
25
25
|
html: string;
|
|
26
26
|
response: Response;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { AlephaError } from "alepha";
|
|
2
2
|
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
} from "../
|
|
3
|
+
PagePrimitiveRenderOptions,
|
|
4
|
+
PagePrimitiveRenderResult,
|
|
5
|
+
} from "../primitives/$page.ts";
|
|
6
6
|
|
|
7
7
|
export class ReactPageService {
|
|
8
8
|
public fetch(
|
|
9
9
|
pathname: string,
|
|
10
|
-
options:
|
|
10
|
+
options: PagePrimitiveRenderOptions = {},
|
|
11
11
|
): Promise<{
|
|
12
12
|
html: string;
|
|
13
13
|
response: Response;
|
|
@@ -17,8 +17,8 @@ export class ReactPageService {
|
|
|
17
17
|
|
|
18
18
|
public render(
|
|
19
19
|
name: string,
|
|
20
|
-
options:
|
|
21
|
-
): Promise<
|
|
20
|
+
options: PagePrimitiveRenderOptions = {},
|
|
21
|
+
): Promise<PagePrimitiveRenderResult> {
|
|
22
22
|
throw new AlephaError("Render is not available for this environment.");
|
|
23
23
|
}
|
|
24
24
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { $inject, Alepha } from "alepha";
|
|
2
|
-
import type {
|
|
2
|
+
import type { PagePrimitive } from "../primitives/$page.ts";
|
|
3
3
|
import {
|
|
4
4
|
ReactBrowserProvider,
|
|
5
5
|
type RouterGoOptions,
|
|
@@ -15,7 +15,7 @@ export class ReactRouter<T extends object> {
|
|
|
15
15
|
protected readonly pageApi = $inject(ReactPageProvider);
|
|
16
16
|
|
|
17
17
|
public get state(): ReactRouterState {
|
|
18
|
-
return this.alepha.
|
|
18
|
+
return this.alepha.store.get("alepha.react.router.state")!;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
public get pages() {
|
|
@@ -220,5 +220,5 @@ export class ReactRouter<T extends object> {
|
|
|
220
220
|
}
|
|
221
221
|
|
|
222
222
|
export type VirtualRouter<T> = {
|
|
223
|
-
[K in keyof T as T[K] extends
|
|
223
|
+
[K in keyof T as T[K] extends PagePrimitive ? K : never]: T[K];
|
|
224
224
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { AlephaReact } from "@alepha/react";
|
|
2
2
|
import { $module } from "alepha";
|
|
3
|
-
import { $head } from "./
|
|
3
|
+
import { $head } from "./primitives/$head.ts";
|
|
4
4
|
import { BrowserHeadProvider } from "./providers/BrowserHeadProvider.ts";
|
|
5
5
|
|
|
6
6
|
// ---------------------------------------------------------------------------------------------------------------------
|
|
7
7
|
|
|
8
|
-
export * from "./
|
|
8
|
+
export * from "./primitives/$head.ts";
|
|
9
9
|
export * from "./hooks/useHead.ts";
|
|
10
10
|
export * from "./interfaces/Head.ts";
|
|
11
11
|
export * from "./providers/BrowserHeadProvider.ts";
|
|
@@ -20,6 +20,6 @@ export * from "./providers/BrowserHeadProvider.ts";
|
|
|
20
20
|
*/
|
|
21
21
|
export const AlephaReactHead = $module({
|
|
22
22
|
name: "alepha.react.head",
|
|
23
|
-
|
|
23
|
+
primitives: [$head],
|
|
24
24
|
services: [AlephaReact, BrowserHeadProvider],
|
|
25
25
|
});
|
package/src/head/index.ts
CHANGED
|
@@ -5,13 +5,13 @@ import {
|
|
|
5
5
|
type TPropsParentDefault,
|
|
6
6
|
} from "@alepha/react";
|
|
7
7
|
import { $module } from "alepha";
|
|
8
|
-
import { $head } from "./
|
|
8
|
+
import { $head } from "./primitives/$head.ts";
|
|
9
9
|
import type { Head } from "./interfaces/Head.ts";
|
|
10
10
|
import { ServerHeadProvider } from "./providers/ServerHeadProvider.ts";
|
|
11
11
|
|
|
12
12
|
// ---------------------------------------------------------------------------------------------------------------------
|
|
13
13
|
|
|
14
|
-
export * from "./
|
|
14
|
+
export * from "./primitives/$head.ts";
|
|
15
15
|
export * from "./hooks/useHead.ts";
|
|
16
16
|
export * from "./interfaces/Head.ts";
|
|
17
17
|
export * from "./providers/ServerHeadProvider.ts";
|
|
@@ -19,7 +19,7 @@ export * from "./providers/ServerHeadProvider.ts";
|
|
|
19
19
|
// ---------------------------------------------------------------------------------------------------------------------
|
|
20
20
|
|
|
21
21
|
declare module "@alepha/react" {
|
|
22
|
-
interface
|
|
22
|
+
interface PagePrimitiveOptions<
|
|
23
23
|
TConfig extends PageConfigSchema = PageConfigSchema,
|
|
24
24
|
TProps extends object = TPropsDefault,
|
|
25
25
|
TPropsParent extends object = TPropsParentDefault,
|
|
@@ -42,6 +42,6 @@ declare module "@alepha/react" {
|
|
|
42
42
|
*/
|
|
43
43
|
export const AlephaReactHead = $module({
|
|
44
44
|
name: "alepha.react.head",
|
|
45
|
-
|
|
45
|
+
primitives: [$head],
|
|
46
46
|
services: [AlephaReact, ServerHeadProvider],
|
|
47
47
|
});
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { $inject,
|
|
1
|
+
import { $inject, createPrimitive, Primitive, KIND } from "alepha";
|
|
2
2
|
import type { Head } from "../interfaces/Head.ts";
|
|
3
3
|
import { HeadProvider } from "../providers/HeadProvider.ts";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Set global `<head>` options for the application.
|
|
7
7
|
*/
|
|
8
|
-
export const $head = (options:
|
|
9
|
-
return
|
|
8
|
+
export const $head = (options: HeadPrimitiveOptions) => {
|
|
9
|
+
return createPrimitive(HeadPrimitive, options);
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
// ---------------------------------------------------------------------------------------------------------------------
|
|
13
13
|
|
|
14
|
-
export type
|
|
14
|
+
export type HeadPrimitiveOptions = Head | (() => Head);
|
|
15
15
|
|
|
16
16
|
// ---------------------------------------------------------------------------------------------------------------------
|
|
17
17
|
|
|
18
|
-
export class
|
|
18
|
+
export class HeadPrimitive extends Primitive<HeadPrimitiveOptions> {
|
|
19
19
|
protected readonly provider = $inject(HeadProvider);
|
|
20
20
|
protected onInit() {
|
|
21
21
|
this.provider.global = this.options;
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
$head[KIND] =
|
|
25
|
+
$head[KIND] = HeadPrimitive;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useInject, useStore } from "@alepha/react";
|
|
2
|
-
import type {
|
|
2
|
+
import type { DictionaryPrimitive } from "../primitives/$dictionary.ts";
|
|
3
3
|
import { I18nProvider } from "../providers/I18nProvider.ts";
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -14,5 +14,5 @@ export const useI18n = <
|
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
export type ServiceDictionary<T extends object> = {
|
|
17
|
-
[K in keyof T]: T[K] extends
|
|
17
|
+
[K in keyof T]: T[K] extends DictionaryPrimitive<infer U> ? U : never;
|
|
18
18
|
};
|
package/src/i18n/index.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { $module } from "alepha";
|
|
2
|
-
import { $dictionary } from "./
|
|
2
|
+
import { $dictionary } from "./primitives/$dictionary.ts";
|
|
3
3
|
import { I18nProvider } from "./providers/I18nProvider.ts";
|
|
4
4
|
|
|
5
5
|
// ---------------------------------------------------------------------------------------------------------------------
|
|
6
6
|
|
|
7
7
|
export type { LocalizeProps } from "./components/Localize.tsx";
|
|
8
8
|
export { default as Localize } from "./components/Localize.tsx";
|
|
9
|
-
export * from "./
|
|
9
|
+
export * from "./primitives/$dictionary.ts";
|
|
10
10
|
export * from "./hooks/useI18n.ts";
|
|
11
11
|
export * from "./providers/I18nProvider.ts";
|
|
12
12
|
|
|
@@ -29,6 +29,6 @@ declare module "alepha" {
|
|
|
29
29
|
*/
|
|
30
30
|
export const AlephaReactI18n = $module({
|
|
31
31
|
name: "alepha.react.i18n",
|
|
32
|
-
|
|
32
|
+
primitives: [$dictionary],
|
|
33
33
|
services: [I18nProvider],
|
|
34
34
|
});
|