@alepha/react 0.13.1 → 0.13.3
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 +10 -5
- package/dist/auth/index.browser.js.map +1 -1
- package/dist/auth/index.d.ts +401 -330
- package/dist/auth/index.js +12 -7
- package/dist/auth/index.js.map +1 -1
- package/dist/core/index.browser.js +50 -28
- package/dist/core/index.browser.js.map +1 -1
- package/dist/core/index.d.ts +382 -344
- package/dist/core/index.js +65 -37
- 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 +28 -17
- package/dist/head/index.browser.js.map +1 -1
- package/dist/head/index.d.ts +270 -267
- package/dist/head/index.js +29 -17
- 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 +21 -12
- package/src/auth/index.ts +1 -1
- package/src/auth/providers/ReactAuthProvider.ts +1 -1
- package/src/auth/services/ReactAuth.ts +15 -5
- package/src/core/components/NestedView.tsx +6 -2
- package/src/core/components/NotFound.tsx +10 -6
- 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 +3 -2
- package/src/core/providers/ReactPageProvider.ts +28 -11
- package/src/core/providers/ReactServerProvider.ts +34 -23
- package/src/core/services/ReactPageServerService.ts +6 -6
- package/src/core/services/ReactPageService.ts +6 -6
- package/src/core/services/ReactRouter.ts +19 -3
- package/src/head/index.browser.ts +3 -3
- package/src/head/index.ts +4 -4
- package/src/head/interfaces/Head.ts +1 -0
- package/src/head/{descriptors → primitives}/$head.ts +10 -7
- package/src/head/providers/BrowserHeadProvider.ts +13 -0
- package/src/head/providers/HeadProvider.ts +11 -9
- package/src/head/providers/ServerHeadProvider.ts +6 -0
- 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
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@alepha/react",
|
|
3
3
|
"description": "React components and hooks for building Alepha applications.",
|
|
4
4
|
"author": "Nicolas Foures",
|
|
5
|
-
"version": "0.13.
|
|
5
|
+
"version": "0.13.3",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"engines": {
|
|
8
8
|
"node": ">=22.0.0"
|
|
@@ -18,20 +18,20 @@
|
|
|
18
18
|
"bin": "./dist/index.js",
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@vitejs/plugin-react": "^5.1.1",
|
|
21
|
-
"react-dom": "^19.2.
|
|
21
|
+
"react-dom": "^19.2.1"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@testing-library/dom": "^10.4.1",
|
|
25
25
|
"@testing-library/react": "^16.3.0",
|
|
26
26
|
"@types/react": "^19.2.7",
|
|
27
27
|
"@types/react-dom": "^19.2.3",
|
|
28
|
-
"alepha": "0.13.
|
|
28
|
+
"alepha": "0.13.3",
|
|
29
29
|
"jsdom": "^27.2.0",
|
|
30
|
-
"react": "^19.2.
|
|
31
|
-
"vitest": "^4.0.
|
|
30
|
+
"react": "^19.2.1",
|
|
31
|
+
"vitest": "^4.0.15"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"alepha": "0.13.
|
|
34
|
+
"alepha": "0.13.3",
|
|
35
35
|
"react": "^19.2.0"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
@@ -56,30 +56,39 @@
|
|
|
56
56
|
"exports": {
|
|
57
57
|
"./auth": {
|
|
58
58
|
"types": "./dist/auth/index.js",
|
|
59
|
+
"react-native": "./dist/auth/index.browser.js",
|
|
59
60
|
"browser": "./dist/auth/index.browser.js",
|
|
60
|
-
"import": "./dist/auth/index.js"
|
|
61
|
+
"import": "./dist/auth/index.js",
|
|
62
|
+
"default": "./dist/auth/index.js"
|
|
61
63
|
},
|
|
62
64
|
".": {
|
|
63
65
|
"types": "./dist/core/index.js",
|
|
66
|
+
"react-native": "./dist/core/index.native.js",
|
|
64
67
|
"browser": "./dist/core/index.browser.js",
|
|
65
|
-
"import": "./dist/core/index.js"
|
|
68
|
+
"import": "./dist/core/index.js",
|
|
69
|
+
"default": "./dist/core/index.js"
|
|
66
70
|
},
|
|
67
71
|
"./form": {
|
|
68
72
|
"types": "./dist/form/index.js",
|
|
69
|
-
"import": "./dist/form/index.js"
|
|
73
|
+
"import": "./dist/form/index.js",
|
|
74
|
+
"default": "./dist/form/index.js"
|
|
70
75
|
},
|
|
71
76
|
"./head": {
|
|
72
77
|
"types": "./dist/head/index.js",
|
|
78
|
+
"react-native": "./dist/head/index.browser.js",
|
|
73
79
|
"browser": "./dist/head/index.browser.js",
|
|
74
|
-
"import": "./dist/head/index.js"
|
|
80
|
+
"import": "./dist/head/index.js",
|
|
81
|
+
"default": "./dist/head/index.js"
|
|
75
82
|
},
|
|
76
83
|
"./i18n": {
|
|
77
84
|
"types": "./dist/i18n/index.js",
|
|
78
|
-
"import": "./dist/i18n/index.js"
|
|
85
|
+
"import": "./dist/i18n/index.js",
|
|
86
|
+
"default": "./dist/i18n/index.js"
|
|
79
87
|
},
|
|
80
88
|
"./websocket": {
|
|
81
89
|
"types": "./dist/websocket/index.js",
|
|
82
|
-
"import": "./dist/websocket/index.js"
|
|
90
|
+
"import": "./dist/websocket/index.js",
|
|
91
|
+
"default": "./dist/websocket/index.js"
|
|
83
92
|
}
|
|
84
93
|
},
|
|
85
94
|
"module": "./dist/index.js"
|
package/src/auth/index.ts
CHANGED
|
@@ -29,6 +29,6 @@ declare module "@alepha/react" {
|
|
|
29
29
|
*/
|
|
30
30
|
export const AlephaReactAuth = $module({
|
|
31
31
|
name: "alepha.react.auth",
|
|
32
|
-
|
|
32
|
+
primitives: [$auth],
|
|
33
33
|
services: [AlephaReact, AlephaServerLinks, AlephaServerAuth, ReactAuthProvider, ReactAuth],
|
|
34
34
|
});
|
|
@@ -8,7 +8,7 @@ export class ReactAuthProvider {
|
|
|
8
8
|
handler: async ({ request, state }) => {
|
|
9
9
|
if (request?.user) {
|
|
10
10
|
const { token, realm, ...user } = request.user; // do not send token and realm to the client
|
|
11
|
-
this.alepha.
|
|
11
|
+
this.alepha.store.set("alepha.server.request.user", user); // for hydration, browser, etc...
|
|
12
12
|
state.user = user;
|
|
13
13
|
}
|
|
14
14
|
},
|
|
@@ -4,6 +4,7 @@ import { $logger } from "alepha/logger";
|
|
|
4
4
|
import type { UserAccountToken } from "alepha/security";
|
|
5
5
|
import { HttpClient } from "alepha/server";
|
|
6
6
|
import { alephaServerAuthRoutes, tokenResponseSchema, type Tokens, userinfoResponseSchema } from "alepha/server/auth";
|
|
7
|
+
import { LinkProvider } from "alepha/server/links";
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Browser, SSR friendly, service to handle authentication.
|
|
@@ -12,6 +13,7 @@ export class ReactAuth {
|
|
|
12
13
|
protected readonly log = $logger();
|
|
13
14
|
protected readonly alepha = $inject(Alepha);
|
|
14
15
|
protected readonly httpClient = $inject(HttpClient);
|
|
16
|
+
protected readonly linkProvider = $inject(LinkProvider);
|
|
15
17
|
|
|
16
18
|
protected readonly onBeginTransition = $hook({
|
|
17
19
|
on: "react:transition:begin",
|
|
@@ -40,7 +42,7 @@ export class ReactAuth {
|
|
|
40
42
|
* Alias for `alepha.state.get("user")`
|
|
41
43
|
*/
|
|
42
44
|
public get user(): UserAccountToken | undefined {
|
|
43
|
-
return this.alepha.
|
|
45
|
+
return this.alepha.store.get("alepha.server.request.user");
|
|
44
46
|
}
|
|
45
47
|
|
|
46
48
|
public async ping() {
|
|
@@ -48,12 +50,20 @@ export class ReactAuth {
|
|
|
48
50
|
schema: { response: userinfoResponseSchema },
|
|
49
51
|
});
|
|
50
52
|
|
|
51
|
-
this.alepha.
|
|
52
|
-
this.alepha.
|
|
53
|
+
this.alepha.store.set("alepha.server.request.apiLinks", data.api);
|
|
54
|
+
this.alepha.store.set("alepha.server.request.user", data.user);
|
|
53
55
|
|
|
54
56
|
return data.user;
|
|
55
57
|
}
|
|
56
58
|
|
|
59
|
+
public can(action: string): boolean {
|
|
60
|
+
if (!this.user) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return this.linkProvider.can(action);
|
|
65
|
+
}
|
|
66
|
+
|
|
57
67
|
public async login(
|
|
58
68
|
provider: string,
|
|
59
69
|
options: {
|
|
@@ -78,8 +88,8 @@ export class ReactAuth {
|
|
|
78
88
|
},
|
|
79
89
|
);
|
|
80
90
|
|
|
81
|
-
this.alepha.
|
|
82
|
-
this.alepha.
|
|
91
|
+
this.alepha.store.set("alepha.server.request.apiLinks", data.api);
|
|
92
|
+
this.alepha.store.set("alepha.server.request.user", data.user);
|
|
83
93
|
|
|
84
94
|
return data;
|
|
85
95
|
}
|
|
@@ -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";
|
|
@@ -50,7 +50,11 @@ const NestedView = (props: NestedViewProps) => {
|
|
|
50
50
|
"react:transition:begin": async ({ previous, state }) => {
|
|
51
51
|
// --------- Animations Begin ---------
|
|
52
52
|
const layer = previous.layers[index];
|
|
53
|
-
if (
|
|
53
|
+
if (!layer) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (`${state.url.pathname}/`.startsWith(`${layer.path}/`)) {
|
|
54
58
|
return;
|
|
55
59
|
}
|
|
56
60
|
|
|
@@ -4,20 +4,24 @@ export default function NotFoundPage(props: { style?: CSSProperties }) {
|
|
|
4
4
|
return (
|
|
5
5
|
<div
|
|
6
6
|
style={{
|
|
7
|
-
|
|
7
|
+
width: "100%",
|
|
8
|
+
minHeight: "90vh",
|
|
9
|
+
boxSizing: "border-box",
|
|
8
10
|
display: "flex",
|
|
9
11
|
flexDirection: "column",
|
|
10
12
|
justifyContent: "center",
|
|
11
13
|
alignItems: "center",
|
|
12
14
|
textAlign: "center",
|
|
13
|
-
fontFamily:
|
|
14
|
-
|
|
15
|
+
fontFamily:
|
|
16
|
+
'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',
|
|
17
|
+
padding: "2rem",
|
|
15
18
|
...props.style,
|
|
16
19
|
}}
|
|
17
20
|
>
|
|
18
|
-
<
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
<div style={{ fontSize: "6rem", fontWeight: 200, lineHeight: 1 }}>404</div>
|
|
22
|
+
<div style={{ fontSize: "0.875rem", marginTop: "1rem", opacity: 0.6 }}>
|
|
23
|
+
Page not found
|
|
24
|
+
</div>
|
|
21
25
|
</div>
|
|
22
26
|
);
|
|
23
27
|
}
|
|
@@ -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
|
|
|
@@ -77,6 +77,7 @@ export class ReactBrowserRouterProvider extends RouterProvider<BrowserRoute> {
|
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
+
state.name = route?.page.name;
|
|
80
81
|
state.query = query;
|
|
81
82
|
state.params = params ?? {};
|
|
82
83
|
|
|
@@ -135,7 +136,7 @@ export class ReactBrowserRouterProvider extends RouterProvider<BrowserRoute> {
|
|
|
135
136
|
}
|
|
136
137
|
}
|
|
137
138
|
|
|
138
|
-
this.alepha.
|
|
139
|
+
this.alepha.store.set("alepha.react.router.state", state);
|
|
139
140
|
|
|
140
141
|
await this.alepha.events.emit("react:action:end", {
|
|
141
142
|
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;
|
|
@@ -680,6 +694,9 @@ export interface ReactRouterState {
|
|
|
680
694
|
* Optional meta information associated with the current page.
|
|
681
695
|
*/
|
|
682
696
|
meta: Record<string, any>;
|
|
697
|
+
|
|
698
|
+
//
|
|
699
|
+
name?: string;
|
|
683
700
|
}
|
|
684
701
|
|
|
685
702
|
export interface RouterStackItem {
|