@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
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Alepha React
2
2
 
3
- Build server-side rendered (SSR) or single-page React applications.
3
+ React components and hooks for building Alepha applications.
4
4
 
5
5
  ## Installation
6
6
 
@@ -10,185 +10,3 @@ This package is part of the Alepha framework and can be installed via the all-in
10
10
  npm install alepha
11
11
  ```
12
12
 
13
- ## Module
14
-
15
- Provides full-stack React development with declarative routing, server-side rendering, and client-side hydration.
16
-
17
- The React module enables building modern React applications using the `$page` descriptor on class properties.
18
- It delivers seamless server-side rendering, automatic code splitting, and client-side navigation with full
19
- type safety and schema validation for route parameters and data.
20
-
21
- This module can be imported and used as follows:
22
-
23
- ```typescript
24
- import { Alepha, run } from "alepha";
25
- import { AlephaReact } from "alepha/react";
26
-
27
- const alepha = Alepha.create()
28
- .with(AlephaReact);
29
-
30
- run(alepha);
31
- ```
32
-
33
- ## API Reference
34
-
35
- ### Descriptors
36
-
37
- Descriptors are functions that define and configure various aspects of your application. They follow the convention of starting with ` $ ` and return configured descriptor instances.
38
-
39
- For more details, see the [Descriptors documentation](/docs/descriptors).
40
-
41
- #### $page()
42
-
43
- Main descriptor for defining a React route in the application.
44
-
45
- The $page descriptor is the core building block for creating type-safe, SSR-enabled React routes.
46
- It provides a declarative way to define pages with powerful features:
47
-
48
- **Routing & Navigation**
49
- - URL pattern matching with parameters (e.g., `/users/:id`)
50
- - Nested routing with parent-child relationships
51
- - Type-safe URL parameter and query string validation
52
-
53
- **Data Loading**
54
- - Server-side data fetching with the `resolve` function
55
- - Automatic serialization and hydration for SSR
56
- - Access to request context, URL params, and parent data
57
-
58
- **Component Loading**
59
- - Direct component rendering or lazy loading for code splitting
60
- - Client-only rendering when browser APIs are needed
61
- - Automatic fallback handling during hydration
62
-
63
- **Performance Optimization**
64
- - Static generation for pre-rendered pages at build time
65
- - Server-side caching with configurable TTL and providers
66
- - Code splitting through lazy component loading
67
-
68
- **Error Handling**
69
- - Custom error handlers with support for redirects
70
- - Hierarchical error handling (child → parent)
71
- - HTTP status code handling (404, 401, etc.)
72
-
73
- **Page Animations**
74
- - CSS-based enter/exit animations
75
- - Dynamic animations based on page state
76
- - Custom timing and easing functions
77
-
78
- **Lifecycle Management**
79
- - Server response hooks for headers and status codes
80
- - Page leave handlers for cleanup (browser only)
81
- - Permission-based access control
82
-
83
- ```typescript
84
- const userProfile = $page({
85
- path: "/users/:id",
86
- schema: {
87
- params: t.object({ id: t.int() }),
88
- query: t.object({ tab: t.optional(t.text()) })
89
- },
90
- resolve: async ({ params }) => {
91
- const user = await userApi.getUser(params.id);
92
- return { user };
93
- },
94
- lazy: () => import("./UserProfile.tsx")
95
- });
96
- ```
97
-
98
- ```typescript
99
- const projectSection = $page({
100
- path: "/projects/:id",
101
- children: () => [projectBoard, projectSettings],
102
- resolve: async ({ params }) => {
103
- const project = await projectApi.get(params.id);
104
- return { project };
105
- },
106
- errorHandler: (error) => {
107
- if (HttpError.is(error, 404)) {
108
- return <ProjectNotFound />;
109
- }
110
- }
111
- });
112
- ```
113
-
114
- ```typescript
115
- const blogPost = $page({
116
- path: "/blog/:slug",
117
- static: {
118
- entries: posts.map(p => ({ params: { slug: p.slug } }))
119
- },
120
- resolve: async ({ params }) => {
121
- const post = await loadPost(params.slug);
122
- return { post };
123
- }
124
- });
125
- ```
126
-
127
- ### Hooks
128
-
129
- Hooks provide a way to tap into various lifecycle events and extend functionality. They follow the convention of starting with `use` and return configured hook instances.
130
-
131
- #### useAlepha()
132
-
133
- Main Alepha hook.
134
-
135
- It provides access to the Alepha instance within a React component.
136
-
137
- With Alepha, you can access the core functionalities of the framework:
138
-
139
- - alepha.state() for state management
140
- - alepha.inject() for dependency injection
141
- - alepha.events.emit() for event handling
142
- etc...
143
-
144
- #### useClient()
145
-
146
- Hook to get a virtual client for the specified scope.
147
-
148
- It's the React-hook version of `$client()`, from `AlephaServerLinks` module.
149
-
150
- #### useEvents()
151
-
152
- Allow subscribing to multiple Alepha events. See {@link Hooks} for available events.
153
-
154
- useEvents is fully typed to ensure correct event callback signatures.
155
-
156
- ```tsx
157
- useEvents(
158
- {
159
- "react:transition:begin": (ev) => {
160
- console.log("Transition began to:", ev.to);
161
- },
162
- "react:transition:error": {
163
- priority: "first",
164
- callback: (ev) => {
165
- console.error("Transition error:", ev.error);
166
- },
167
- },
168
- },
169
- [],
170
- );
171
- ```
172
-
173
- #### useInject()
174
-
175
- Hook to inject a service instance.
176
- It's a wrapper of `useAlepha().inject(service)` with a memoization.
177
-
178
- #### useQueryParams()
179
-
180
- Not well tested. Use with caution.
181
-
182
- #### useRouter()
183
-
184
- Use this hook to access the React Router instance.
185
-
186
- You can add a type parameter to specify the type of your application.
187
- This will allow you to use the router in a typesafe way.
188
-
189
- class App {
190
- home = $page();
191
- }
192
-
193
- const router = useRouter<App>();
194
- router.go("home"); // typesafe