@alepha/react 0.14.0 → 0.14.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.
Files changed (72) hide show
  1. package/README.md +1 -1
  2. package/dist/auth/index.browser.js +1488 -4
  3. package/dist/auth/index.browser.js.map +1 -1
  4. package/dist/auth/index.d.ts +2 -2
  5. package/dist/auth/index.js +1827 -4
  6. package/dist/auth/index.js.map +1 -1
  7. package/dist/core/index.d.ts +54 -937
  8. package/dist/core/index.d.ts.map +1 -1
  9. package/dist/core/index.js +132 -2010
  10. package/dist/core/index.js.map +1 -1
  11. package/dist/form/index.d.ts.map +1 -1
  12. package/dist/form/index.js +6 -1
  13. package/dist/form/index.js.map +1 -1
  14. package/dist/head/index.browser.js +191 -17
  15. package/dist/head/index.browser.js.map +1 -1
  16. package/dist/head/index.d.ts +652 -31
  17. package/dist/head/index.d.ts.map +1 -1
  18. package/dist/head/index.js +209 -18
  19. package/dist/head/index.js.map +1 -1
  20. package/dist/{core → router}/index.browser.js +126 -516
  21. package/dist/router/index.browser.js.map +1 -0
  22. package/dist/router/index.d.ts +1334 -0
  23. package/dist/router/index.d.ts.map +1 -0
  24. package/dist/router/index.js +1939 -0
  25. package/dist/router/index.js.map +1 -0
  26. package/package.json +12 -6
  27. package/src/auth/index.ts +1 -1
  28. package/src/auth/services/ReactAuth.ts +1 -1
  29. package/src/core/components/ClientOnly.tsx +14 -0
  30. package/src/core/components/ErrorBoundary.tsx +3 -2
  31. package/src/core/contexts/AlephaContext.ts +3 -0
  32. package/src/core/contexts/AlephaProvider.tsx +2 -1
  33. package/src/core/index.ts +13 -102
  34. package/src/form/services/FormModel.ts +5 -0
  35. package/src/head/helpers/SeoExpander.ts +141 -0
  36. package/src/head/index.browser.ts +1 -0
  37. package/src/head/index.ts +17 -7
  38. package/src/head/interfaces/Head.ts +69 -27
  39. package/src/head/providers/BrowserHeadProvider.ts +45 -12
  40. package/src/head/providers/HeadProvider.ts +32 -8
  41. package/src/head/providers/ServerHeadProvider.ts +34 -2
  42. package/src/{core → router}/components/ErrorViewer.tsx +2 -0
  43. package/src/router/components/Link.tsx +21 -0
  44. package/src/{core → router}/components/NestedView.tsx +3 -5
  45. package/src/router/components/NotFound.tsx +30 -0
  46. package/src/router/errors/Redirection.ts +28 -0
  47. package/src/{core → router}/hooks/useActive.ts +6 -2
  48. package/src/{core → router}/hooks/useQueryParams.ts +2 -2
  49. package/src/{core → router}/hooks/useRouter.ts +1 -1
  50. package/src/{core → router}/hooks/useRouterState.ts +1 -1
  51. package/src/{core → router}/index.browser.ts +14 -12
  52. package/src/{core/index.shared-router.ts → router/index.shared.ts} +6 -3
  53. package/src/router/index.ts +125 -0
  54. package/src/{core → router}/primitives/$page.ts +1 -1
  55. package/src/{core → router}/providers/ReactBrowserProvider.ts +3 -13
  56. package/src/{core → router}/providers/ReactBrowserRendererProvider.ts +3 -0
  57. package/src/{core → router}/providers/ReactBrowserRouterProvider.ts +3 -0
  58. package/src/{core → router}/providers/ReactPageProvider.ts +5 -3
  59. package/src/{core → router}/providers/ReactServerProvider.ts +9 -28
  60. package/src/{core → router}/services/ReactPageServerService.ts +3 -0
  61. package/src/{core → router}/services/ReactPageService.ts +5 -5
  62. package/src/{core → router}/services/ReactRouter.ts +26 -5
  63. package/dist/core/index.browser.js.map +0 -1
  64. package/dist/core/index.native.js +0 -403
  65. package/dist/core/index.native.js.map +0 -1
  66. package/src/core/components/Link.tsx +0 -18
  67. package/src/core/components/NotFound.tsx +0 -27
  68. package/src/core/errors/Redirection.ts +0 -13
  69. package/src/core/hooks/useSchema.ts +0 -88
  70. package/src/core/index.native.ts +0 -21
  71. package/src/core/index.shared.ts +0 -9
  72. /package/src/{core → router}/contexts/RouterLayerContext.ts +0 -0
@@ -1,9 +1,18 @@
1
- import { AlephaReact, ReactBrowserProvider, Redirection, useAlepha, useStore } from "@alepha/react";
2
- import { $hook, $inject, $module, Alepha } from "alepha";
1
+ import { AlephaContext, AlephaReact, ClientOnly, ErrorBoundary, useAlepha, useEvents, useStore } from "@alepha/react";
2
+ import { $atom, $env, $hook, $inject, $module, $use, Alepha, AlephaError, KIND, Primitive, createPrimitive, t } from "alepha";
3
+ import { AlephaDateTime, DateTimeProvider } from "alepha/datetime";
3
4
  import { $logger } from "alepha/logger";
4
- import { HttpClient } from "alepha/server";
5
+ import { AlephaServerLinks, LinkProvider, ServerLinksProvider } from "alepha/server/links";
6
+ import { RouterProvider } from "alepha/router";
7
+ import { StrictMode, createContext, createElement, memo, use, useRef, useState } from "react";
8
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
9
+ import { AlephaServer, HttpClient, ServerProvider, ServerRouterProvider, ServerTimingProvider } from "alepha/server";
10
+ import { existsSync } from "node:fs";
11
+ import { join } from "node:path";
12
+ import { ServerStaticProvider } from "alepha/server/static";
13
+ import { renderToString } from "react-dom/server";
14
+ import { AlephaServerCache } from "alepha/server/cache";
5
15
  import { $auth, AlephaServerAuth, alephaServerAuthRoutes, tokenResponseSchema, userinfoResponseSchema } from "alepha/server/auth";
6
- import { AlephaServerLinks, LinkProvider } from "alepha/server/links";
7
16
 
8
17
  //#region ../../src/auth/providers/ReactAuthProvider.ts
9
18
  var ReactAuthProvider = class {
@@ -20,6 +29,1820 @@ var ReactAuthProvider = class {
20
29
  });
21
30
  };
22
31
 
32
+ //#endregion
33
+ //#region ../../src/router/services/ReactPageService.ts
34
+ /**
35
+ * $page methods interface.
36
+ */
37
+ var ReactPageService = class {
38
+ fetch(pathname, options = {}) {
39
+ throw new AlephaError("Fetch is not available for this environment.");
40
+ }
41
+ render(name, options = {}) {
42
+ throw new AlephaError("Render is not available for this environment.");
43
+ }
44
+ };
45
+
46
+ //#endregion
47
+ //#region ../../src/router/primitives/$page.ts
48
+ /**
49
+ * Main primitive for defining a React route in the application.
50
+ *
51
+ * The $page primitive is the core building block for creating type-safe, SSR-enabled React routes.
52
+ * It provides a declarative way to define pages with powerful features:
53
+ *
54
+ * **Routing & Navigation**
55
+ * - URL pattern matching with parameters (e.g., `/users/:id`)
56
+ * - Nested routing with parent-child relationships
57
+ * - Type-safe URL parameter and query string validation
58
+ *
59
+ * **Data Loading**
60
+ * - Server-side data fetching with the `resolve` function
61
+ * - Automatic serialization and hydration for SSR
62
+ * - Access to request context, URL params, and parent data
63
+ *
64
+ * **Component Loading**
65
+ * - Direct component rendering or lazy loading for code splitting
66
+ * - Client-only rendering when browser APIs are needed
67
+ * - Automatic fallback handling during hydration
68
+ *
69
+ * **Performance Optimization**
70
+ * - Static generation for pre-rendered pages at build time
71
+ * - Server-side caching with configurable TTL and providers
72
+ * - Code splitting through lazy component loading
73
+ *
74
+ * **Error Handling**
75
+ * - Custom error handlers with support for redirects
76
+ * - Hierarchical error handling (child → parent)
77
+ * - HTTP status code handling (404, 401, etc.)
78
+ *
79
+ * **Page Animations**
80
+ * - CSS-based enter/exit animations
81
+ * - Dynamic animations based on page state
82
+ * - Custom timing and easing functions
83
+ *
84
+ * **Lifecycle Management**
85
+ * - Server response hooks for headers and status codes
86
+ * - Page leave handlers for cleanup (browser only)
87
+ * - Permission-based access control
88
+ *
89
+ * @example Simple page with data fetching
90
+ * ```typescript
91
+ * const userProfile = $page({
92
+ * path: "/users/:id",
93
+ * schema: {
94
+ * params: t.object({ id: t.integer() }),
95
+ * query: t.object({ tab: t.optional(t.text()) })
96
+ * },
97
+ * resolve: async ({ params }) => {
98
+ * const user = await userApi.getUser(params.id);
99
+ * return { user };
100
+ * },
101
+ * lazy: () => import("./UserProfile.tsx")
102
+ * });
103
+ * ```
104
+ *
105
+ * @example Nested routing with error handling
106
+ * ```typescript
107
+ * const projectSection = $page({
108
+ * path: "/projects/:id",
109
+ * children: () => [projectBoard, projectSettings],
110
+ * resolve: async ({ params }) => {
111
+ * const project = await projectApi.get(params.id);
112
+ * return { project };
113
+ * },
114
+ * errorHandler: (error) => {
115
+ * if (HttpError.is(error, 404)) {
116
+ * return <ProjectNotFound />;
117
+ * }
118
+ * }
119
+ * });
120
+ * ```
121
+ *
122
+ * @example Static generation with caching
123
+ * ```typescript
124
+ * const blogPost = $page({
125
+ * path: "/blog/:slug",
126
+ * static: {
127
+ * entries: posts.map(p => ({ params: { slug: p.slug } }))
128
+ * },
129
+ * resolve: async ({ params }) => {
130
+ * const post = await loadPost(params.slug);
131
+ * return { post };
132
+ * }
133
+ * });
134
+ * ```
135
+ */
136
+ const $page = (options) => {
137
+ return createPrimitive(PagePrimitive, options);
138
+ };
139
+ var PagePrimitive = class extends Primitive {
140
+ reactPageService = $inject(ReactPageService);
141
+ onInit() {
142
+ if (this.options.static) this.options.cache ??= { store: {
143
+ provider: "memory",
144
+ ttl: [1, "week"]
145
+ } };
146
+ }
147
+ get name() {
148
+ return this.options.name ?? this.config.propertyKey;
149
+ }
150
+ /**
151
+ * For testing or build purposes.
152
+ *
153
+ * This will render the page (HTML layout included or not) and return the HTML + context.
154
+ * Only valid for server-side rendering, it will throw an error if called on the client-side.
155
+ */
156
+ async render(options) {
157
+ return this.reactPageService.render(this.name, options);
158
+ }
159
+ async fetch(options) {
160
+ return this.reactPageService.fetch(this.options.path || "", options);
161
+ }
162
+ match(url) {
163
+ return false;
164
+ }
165
+ pathname(config) {
166
+ return this.options.path || "";
167
+ }
168
+ };
169
+ $page[KIND] = PagePrimitive;
170
+
171
+ //#endregion
172
+ //#region ../../src/router/components/NotFound.tsx
173
+ /**
174
+ * Default 404 Not Found page component.
175
+ */
176
+ const NotFound = (props) => /* @__PURE__ */ jsxs("div", {
177
+ style: {
178
+ width: "100%",
179
+ minHeight: "90vh",
180
+ boxSizing: "border-box",
181
+ display: "flex",
182
+ flexDirection: "column",
183
+ justifyContent: "center",
184
+ alignItems: "center",
185
+ textAlign: "center",
186
+ fontFamily: "system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, sans-serif",
187
+ padding: "2rem",
188
+ ...props.style
189
+ },
190
+ children: [/* @__PURE__ */ jsx("div", {
191
+ style: {
192
+ fontSize: "6rem",
193
+ fontWeight: 200,
194
+ lineHeight: 1
195
+ },
196
+ children: "404"
197
+ }), /* @__PURE__ */ jsx("div", {
198
+ style: {
199
+ fontSize: "0.875rem",
200
+ marginTop: "1rem",
201
+ opacity: .6
202
+ },
203
+ children: "Page not found"
204
+ })]
205
+ });
206
+ var NotFound_default = NotFound;
207
+
208
+ //#endregion
209
+ //#region ../../src/router/components/ErrorViewer.tsx
210
+ /**
211
+ * Error viewer component that displays error details in development mode
212
+ */
213
+ const ErrorViewer = ({ error, alepha }) => {
214
+ const [expanded, setExpanded] = useState(false);
215
+ if (alepha.isProduction()) return /* @__PURE__ */ jsx(ErrorViewerProduction, {});
216
+ const frames = parseStackTrace(error.stack);
217
+ const visibleFrames = expanded ? frames : frames.slice(0, 6);
218
+ const hiddenCount = frames.length - 6;
219
+ return /* @__PURE__ */ jsx("div", {
220
+ style: styles.overlay,
221
+ children: /* @__PURE__ */ jsxs("div", {
222
+ style: styles.container,
223
+ children: [/* @__PURE__ */ jsx(Header, { error }), /* @__PURE__ */ jsx(StackTraceSection, {
224
+ frames,
225
+ visibleFrames,
226
+ expanded,
227
+ hiddenCount,
228
+ onToggle: () => setExpanded(!expanded)
229
+ })]
230
+ })
231
+ });
232
+ };
233
+ var ErrorViewer_default = ErrorViewer;
234
+ /**
235
+ * Parse stack trace string into structured frames
236
+ */
237
+ function parseStackTrace(stack) {
238
+ if (!stack) return [];
239
+ const lines = stack.split("\n").slice(1);
240
+ const frames = [];
241
+ for (const line of lines) {
242
+ const trimmed = line.trim();
243
+ if (!trimmed.startsWith("at ")) continue;
244
+ const frame = parseStackLine(trimmed);
245
+ if (frame) frames.push(frame);
246
+ }
247
+ return frames;
248
+ }
249
+ /**
250
+ * Parse a single stack trace line into a structured frame
251
+ */
252
+ function parseStackLine(line) {
253
+ const withFn = line.match(/^at\s+(.+?)\s+\((.+):(\d+):(\d+)\)$/);
254
+ if (withFn) return {
255
+ fn: withFn[1],
256
+ file: withFn[2],
257
+ line: withFn[3],
258
+ col: withFn[4],
259
+ raw: line
260
+ };
261
+ const withoutFn = line.match(/^at\s+(.+):(\d+):(\d+)$/);
262
+ if (withoutFn) return {
263
+ fn: "<anonymous>",
264
+ file: withoutFn[1],
265
+ line: withoutFn[2],
266
+ col: withoutFn[3],
267
+ raw: line
268
+ };
269
+ return {
270
+ fn: "",
271
+ file: line.replace(/^at\s+/, ""),
272
+ line: "",
273
+ col: "",
274
+ raw: line
275
+ };
276
+ }
277
+ /**
278
+ * Copy text to clipboard
279
+ */
280
+ function copyToClipboard(text) {
281
+ navigator.clipboard.writeText(text).catch((err) => {
282
+ console.error("Clipboard error:", err);
283
+ });
284
+ }
285
+ /**
286
+ * Header section with error type and message
287
+ */
288
+ function Header({ error }) {
289
+ const [copied, setCopied] = useState(false);
290
+ const handleCopy = () => {
291
+ copyToClipboard(error.stack || error.message);
292
+ setCopied(true);
293
+ setTimeout(() => setCopied(false), 2e3);
294
+ };
295
+ return /* @__PURE__ */ jsxs("div", {
296
+ style: styles.header,
297
+ children: [/* @__PURE__ */ jsxs("div", {
298
+ style: styles.headerTop,
299
+ children: [/* @__PURE__ */ jsx("div", {
300
+ style: styles.badge,
301
+ children: error.name
302
+ }), /* @__PURE__ */ jsx("button", {
303
+ type: "button",
304
+ onClick: handleCopy,
305
+ style: styles.copyBtn,
306
+ children: copied ? "Copied" : "Copy Stack"
307
+ })]
308
+ }), /* @__PURE__ */ jsx("h1", {
309
+ style: styles.message,
310
+ children: error.message
311
+ })]
312
+ });
313
+ }
314
+ /**
315
+ * Stack trace section with expandable frames
316
+ */
317
+ function StackTraceSection({ frames, visibleFrames, expanded, hiddenCount, onToggle }) {
318
+ if (frames.length === 0) return null;
319
+ return /* @__PURE__ */ jsxs("div", {
320
+ style: styles.stackSection,
321
+ children: [/* @__PURE__ */ jsx("div", {
322
+ style: styles.stackHeader,
323
+ children: "Call Stack"
324
+ }), /* @__PURE__ */ jsxs("div", {
325
+ style: styles.frameList,
326
+ children: [
327
+ visibleFrames.map((frame, i) => /* @__PURE__ */ jsx(StackFrameRow, {
328
+ frame,
329
+ index: i
330
+ }, i)),
331
+ !expanded && hiddenCount > 0 && /* @__PURE__ */ jsxs("button", {
332
+ type: "button",
333
+ onClick: onToggle,
334
+ style: styles.expandBtn,
335
+ children: [
336
+ "Show ",
337
+ hiddenCount,
338
+ " more frames"
339
+ ]
340
+ }),
341
+ expanded && hiddenCount > 0 && /* @__PURE__ */ jsx("button", {
342
+ type: "button",
343
+ onClick: onToggle,
344
+ style: styles.expandBtn,
345
+ children: "Show less"
346
+ })
347
+ ]
348
+ })]
349
+ });
350
+ }
351
+ /**
352
+ * Single stack frame row
353
+ */
354
+ function StackFrameRow({ frame, index }) {
355
+ const isFirst = index === 0;
356
+ const fileName = frame.file.split("/").pop() || frame.file;
357
+ const dirPath = frame.file.substring(0, frame.file.length - fileName.length);
358
+ return /* @__PURE__ */ jsxs("div", {
359
+ style: {
360
+ ...styles.frame,
361
+ ...isFirst ? styles.frameFirst : {}
362
+ },
363
+ children: [/* @__PURE__ */ jsx("div", {
364
+ style: styles.frameIndex,
365
+ children: index + 1
366
+ }), /* @__PURE__ */ jsxs("div", {
367
+ style: styles.frameContent,
368
+ children: [frame.fn && /* @__PURE__ */ jsx("div", {
369
+ style: styles.fnName,
370
+ children: frame.fn
371
+ }), /* @__PURE__ */ jsxs("div", {
372
+ style: styles.filePath,
373
+ children: [
374
+ /* @__PURE__ */ jsx("span", {
375
+ style: styles.dirPath,
376
+ children: dirPath
377
+ }),
378
+ /* @__PURE__ */ jsx("span", {
379
+ style: styles.fileName,
380
+ children: fileName
381
+ }),
382
+ frame.line && /* @__PURE__ */ jsxs("span", {
383
+ style: styles.lineCol,
384
+ children: [
385
+ ":",
386
+ frame.line,
387
+ ":",
388
+ frame.col
389
+ ]
390
+ })
391
+ ]
392
+ })]
393
+ })]
394
+ });
395
+ }
396
+ /**
397
+ * Production error view - minimal information
398
+ */
399
+ function ErrorViewerProduction() {
400
+ return /* @__PURE__ */ jsx("div", {
401
+ style: styles.overlay,
402
+ children: /* @__PURE__ */ jsxs("div", {
403
+ style: styles.prodContainer,
404
+ children: [
405
+ /* @__PURE__ */ jsx("div", {
406
+ style: styles.prodIcon,
407
+ children: "!"
408
+ }),
409
+ /* @__PURE__ */ jsx("h1", {
410
+ style: styles.prodTitle,
411
+ children: "Application Error"
412
+ }),
413
+ /* @__PURE__ */ jsx("p", {
414
+ style: styles.prodMessage,
415
+ children: "An unexpected error occurred. Please try again later."
416
+ }),
417
+ /* @__PURE__ */ jsx("button", {
418
+ type: "button",
419
+ onClick: () => window.location.reload(),
420
+ style: styles.prodButton,
421
+ children: "Reload Page"
422
+ })
423
+ ]
424
+ })
425
+ });
426
+ }
427
+ const styles = {
428
+ overlay: {
429
+ position: "fixed",
430
+ inset: 0,
431
+ backgroundColor: "rgba(0, 0, 0, 0.8)",
432
+ display: "flex",
433
+ alignItems: "flex-start",
434
+ justifyContent: "center",
435
+ padding: "40px 20px",
436
+ overflow: "auto",
437
+ fontFamily: "-apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, sans-serif",
438
+ zIndex: 99999
439
+ },
440
+ container: {
441
+ width: "100%",
442
+ maxWidth: "960px",
443
+ backgroundColor: "#1a1a1a",
444
+ borderRadius: "12px",
445
+ overflow: "hidden",
446
+ boxShadow: "0 25px 50px -12px rgba(0, 0, 0, 0.5)"
447
+ },
448
+ header: {
449
+ padding: "24px 28px",
450
+ borderBottom: "1px solid #333",
451
+ background: "linear-gradient(to bottom, #1f1f1f, #1a1a1a)"
452
+ },
453
+ headerTop: {
454
+ display: "flex",
455
+ alignItems: "center",
456
+ justifyContent: "space-between",
457
+ marginBottom: "16px"
458
+ },
459
+ badge: {
460
+ display: "inline-block",
461
+ padding: "6px 12px",
462
+ backgroundColor: "#dc2626",
463
+ color: "#fff",
464
+ fontSize: "12px",
465
+ fontWeight: 600,
466
+ borderRadius: "6px",
467
+ letterSpacing: "0.025em"
468
+ },
469
+ copyBtn: {
470
+ padding: "8px 16px",
471
+ backgroundColor: "transparent",
472
+ color: "#888",
473
+ fontSize: "13px",
474
+ fontWeight: 500,
475
+ border: "1px solid #444",
476
+ borderRadius: "6px",
477
+ cursor: "pointer",
478
+ transition: "all 0.15s"
479
+ },
480
+ message: {
481
+ margin: 0,
482
+ fontSize: "20px",
483
+ fontWeight: 500,
484
+ color: "#fff",
485
+ lineHeight: 1.5,
486
+ wordBreak: "break-word"
487
+ },
488
+ stackSection: { padding: "0" },
489
+ stackHeader: {
490
+ padding: "16px 28px",
491
+ fontSize: "11px",
492
+ fontWeight: 600,
493
+ color: "#666",
494
+ textTransform: "uppercase",
495
+ letterSpacing: "0.1em",
496
+ borderBottom: "1px solid #2a2a2a"
497
+ },
498
+ frameList: {
499
+ display: "flex",
500
+ flexDirection: "column"
501
+ },
502
+ frame: {
503
+ display: "flex",
504
+ alignItems: "flex-start",
505
+ padding: "14px 28px",
506
+ borderBottom: "1px solid #252525",
507
+ transition: "background-color 0.15s"
508
+ },
509
+ frameFirst: { backgroundColor: "rgba(220, 38, 38, 0.1)" },
510
+ frameIndex: {
511
+ width: "28px",
512
+ flexShrink: 0,
513
+ fontSize: "12px",
514
+ fontWeight: 500,
515
+ color: "#555",
516
+ fontFamily: "monospace"
517
+ },
518
+ frameContent: {
519
+ flex: 1,
520
+ minWidth: 0
521
+ },
522
+ fnName: {
523
+ fontSize: "14px",
524
+ fontWeight: 500,
525
+ color: "#e5e5e5",
526
+ marginBottom: "4px",
527
+ fontFamily: "ui-monospace, SFMono-Regular, \"SF Mono\", Menlo, Consolas, monospace"
528
+ },
529
+ filePath: {
530
+ fontSize: "13px",
531
+ color: "#888",
532
+ fontFamily: "ui-monospace, SFMono-Regular, \"SF Mono\", Menlo, Consolas, monospace",
533
+ wordBreak: "break-all"
534
+ },
535
+ dirPath: { color: "#555" },
536
+ fileName: { color: "#0ea5e9" },
537
+ lineCol: { color: "#eab308" },
538
+ expandBtn: {
539
+ padding: "16px 28px",
540
+ backgroundColor: "transparent",
541
+ color: "#666",
542
+ fontSize: "13px",
543
+ fontWeight: 500,
544
+ border: "none",
545
+ borderTop: "1px solid #252525",
546
+ cursor: "pointer",
547
+ textAlign: "left",
548
+ transition: "all 0.15s"
549
+ },
550
+ prodContainer: {
551
+ textAlign: "center",
552
+ padding: "60px 40px",
553
+ backgroundColor: "#1a1a1a",
554
+ borderRadius: "12px",
555
+ maxWidth: "400px"
556
+ },
557
+ prodIcon: {
558
+ width: "64px",
559
+ height: "64px",
560
+ margin: "0 auto 24px",
561
+ backgroundColor: "#dc2626",
562
+ borderRadius: "50%",
563
+ display: "flex",
564
+ alignItems: "center",
565
+ justifyContent: "center",
566
+ fontSize: "32px",
567
+ fontWeight: 700,
568
+ color: "#fff"
569
+ },
570
+ prodTitle: {
571
+ margin: "0 0 12px",
572
+ fontSize: "24px",
573
+ fontWeight: 600,
574
+ color: "#fff"
575
+ },
576
+ prodMessage: {
577
+ margin: "0 0 28px",
578
+ fontSize: "15px",
579
+ color: "#888",
580
+ lineHeight: 1.6
581
+ },
582
+ prodButton: {
583
+ padding: "12px 24px",
584
+ backgroundColor: "#fff",
585
+ color: "#000",
586
+ fontSize: "14px",
587
+ fontWeight: 600,
588
+ border: "none",
589
+ borderRadius: "8px",
590
+ cursor: "pointer"
591
+ }
592
+ };
593
+
594
+ //#endregion
595
+ //#region ../../src/router/contexts/RouterLayerContext.ts
596
+ const RouterLayerContext = createContext(void 0);
597
+
598
+ //#endregion
599
+ //#region ../../src/router/errors/Redirection.ts
600
+ /**
601
+ * Used for Redirection during the page loading.
602
+ *
603
+ * Depends on the context, it can be thrown or just returned.
604
+ *
605
+ * @example
606
+ * ```ts
607
+ * import { Redirection } from "@alepha/react";
608
+ *
609
+ * const MyPage = $page({
610
+ * resolve: async () => {
611
+ * if (needRedirect) {
612
+ * throw new Redirection("/new-path");
613
+ * }
614
+ * },
615
+ * });
616
+ * ```
617
+ */
618
+ var Redirection = class extends AlephaError {
619
+ redirect;
620
+ constructor(redirect) {
621
+ super("Redirection");
622
+ this.redirect = redirect;
623
+ }
624
+ };
625
+
626
+ //#endregion
627
+ //#region ../../src/router/hooks/useRouterState.ts
628
+ const useRouterState = () => {
629
+ const [state] = useStore("alepha.react.router.state");
630
+ if (!state) throw new AlephaError("Missing react router state");
631
+ return state;
632
+ };
633
+
634
+ //#endregion
635
+ //#region ../../src/router/components/NestedView.tsx
636
+ /**
637
+ * A component that renders the current view of the nested router layer.
638
+ *
639
+ * To be simple, it renders the `element` of the current child page of a parent page.
640
+ *
641
+ * @example
642
+ * ```tsx
643
+ * import { NestedView } from "@alepha/react";
644
+ *
645
+ * class App {
646
+ * parent = $page({
647
+ * component: () => <NestedView />,
648
+ * });
649
+ *
650
+ * child = $page({
651
+ * parent: this.root,
652
+ * component: () => <div>Child Page</div>,
653
+ * });
654
+ * }
655
+ * ```
656
+ */
657
+ const NestedView = (props) => {
658
+ const routerLayer = use(RouterLayerContext);
659
+ const index = routerLayer?.index ?? 0;
660
+ const onError = routerLayer?.onError;
661
+ const state = useRouterState();
662
+ const alepha = useAlepha();
663
+ const [view, setView] = useState(state.layers[index]?.element);
664
+ const [animation, setAnimation] = useState("");
665
+ const animationExitDuration = useRef(0);
666
+ const animationExitNow = useRef(0);
667
+ useEvents({
668
+ "react:transition:begin": async ({ previous, state: state$1 }) => {
669
+ const layer = previous.layers[index];
670
+ if (!layer) return;
671
+ if (`${state$1.url.pathname}/`.startsWith(`${layer.path}/`)) return;
672
+ const animationExit = parseAnimation(layer.route?.animation, state$1, "exit");
673
+ if (animationExit) {
674
+ const duration = animationExit.duration || 200;
675
+ animationExitNow.current = Date.now();
676
+ animationExitDuration.current = duration;
677
+ setAnimation(animationExit.animation);
678
+ } else {
679
+ animationExitNow.current = 0;
680
+ animationExitDuration.current = 0;
681
+ setAnimation("");
682
+ }
683
+ },
684
+ "react:transition:end": async ({ state: state$1 }) => {
685
+ const layer = state$1.layers[index];
686
+ if (animationExitNow.current) {
687
+ const duration = animationExitDuration.current;
688
+ const diff = Date.now() - animationExitNow.current;
689
+ if (diff < duration) await new Promise((resolve) => setTimeout(resolve, duration - diff));
690
+ }
691
+ if (!layer?.cache) {
692
+ setView(layer?.element);
693
+ const animationEnter = parseAnimation(layer?.route?.animation, state$1, "enter");
694
+ if (animationEnter) setAnimation(animationEnter.animation);
695
+ else setAnimation("");
696
+ }
697
+ }
698
+ }, []);
699
+ let element = view ?? props.children ?? null;
700
+ if (animation) element = /* @__PURE__ */ jsx("div", {
701
+ style: {
702
+ display: "flex",
703
+ flex: 1,
704
+ height: "100%",
705
+ width: "100%",
706
+ position: "relative",
707
+ overflow: "hidden"
708
+ },
709
+ children: /* @__PURE__ */ jsx("div", {
710
+ style: {
711
+ height: "100%",
712
+ width: "100%",
713
+ display: "flex",
714
+ animation
715
+ },
716
+ children: element
717
+ })
718
+ });
719
+ if (props.errorBoundary === false) return /* @__PURE__ */ jsx(Fragment, { children: element });
720
+ if (props.errorBoundary) return /* @__PURE__ */ jsx(ErrorBoundary, {
721
+ fallback: props.errorBoundary,
722
+ children: element
723
+ });
724
+ const fallback = (error) => {
725
+ const result = onError?.(error, state) ?? /* @__PURE__ */ jsx(ErrorViewer_default, {
726
+ error,
727
+ alepha
728
+ });
729
+ if (result instanceof Redirection) return "Redirection inside ErrorBoundary is not allowed.";
730
+ return result;
731
+ };
732
+ return /* @__PURE__ */ jsx(ErrorBoundary, {
733
+ fallback,
734
+ children: element
735
+ });
736
+ };
737
+ var NestedView_default = memo(NestedView);
738
+ function parseAnimation(animationLike, state, type = "enter") {
739
+ if (!animationLike) return;
740
+ const DEFAULT_DURATION = 300;
741
+ const animation = typeof animationLike === "function" ? animationLike(state) : animationLike;
742
+ if (typeof animation === "string") {
743
+ if (type === "exit") return;
744
+ return {
745
+ duration: DEFAULT_DURATION,
746
+ animation: `${DEFAULT_DURATION}ms ${animation}`
747
+ };
748
+ }
749
+ if (typeof animation === "object") {
750
+ const anim = animation[type];
751
+ const duration = typeof anim === "object" ? anim.duration ?? DEFAULT_DURATION : DEFAULT_DURATION;
752
+ const name = typeof anim === "object" ? anim.name : anim;
753
+ if (type === "exit") return {
754
+ duration,
755
+ animation: `${duration}ms ${typeof anim === "object" ? anim.timing ?? "" : ""} ${name}`
756
+ };
757
+ return {
758
+ duration,
759
+ animation: `${duration}ms ${typeof anim === "object" ? anim.timing ?? "" : ""} ${name}`
760
+ };
761
+ }
762
+ }
763
+
764
+ //#endregion
765
+ //#region ../../src/router/providers/ReactPageProvider.ts
766
+ const envSchema$2 = t.object({ REACT_STRICT_MODE: t.boolean({ default: true }) });
767
+ /**
768
+ * Handle page routes for React applications. (Browser and Server)
769
+ */
770
+ var ReactPageProvider = class {
771
+ log = $logger();
772
+ env = $env(envSchema$2);
773
+ alepha = $inject(Alepha);
774
+ pages = [];
775
+ getPages() {
776
+ return this.pages;
777
+ }
778
+ getConcretePages() {
779
+ const pages = [];
780
+ for (const page of this.pages) {
781
+ if (page.children && page.children.length > 0) continue;
782
+ const fullPath = this.pathname(page.name);
783
+ if (fullPath.includes(":") || fullPath.includes("*")) {
784
+ if (typeof page.static === "object") {
785
+ const entries = page.static.entries;
786
+ if (entries && entries.length > 0) for (const entry of entries) {
787
+ const params = entry.params;
788
+ const path = this.compile(page.path ?? "", params);
789
+ if (!path.includes(":") && !path.includes("*")) pages.push({
790
+ ...page,
791
+ name: params[Object.keys(params)[0]],
792
+ staticName: page.name,
793
+ path,
794
+ ...entry
795
+ });
796
+ }
797
+ }
798
+ continue;
799
+ }
800
+ pages.push(page);
801
+ }
802
+ return pages;
803
+ }
804
+ page(name) {
805
+ for (const page of this.pages) if (page.name === name) return page;
806
+ throw new AlephaError(`Page '${name}' not found`);
807
+ }
808
+ pathname(name, options = {}) {
809
+ const page = this.page(name);
810
+ if (!page) throw new Error(`Page ${name} not found`);
811
+ let url = page.path ?? "";
812
+ let parent = page.parent;
813
+ while (parent) {
814
+ url = `${parent.path ?? ""}/${url}`;
815
+ parent = parent.parent;
816
+ }
817
+ url = this.compile(url, options.params ?? {});
818
+ if (options.query) {
819
+ const query = new URLSearchParams(options.query);
820
+ if (query.toString()) url += `?${query.toString()}`;
821
+ }
822
+ return url.replace(/\/\/+/g, "/") || "/";
823
+ }
824
+ url(name, options = {}) {
825
+ return new URL(this.pathname(name, options), options.host ?? `http://localhost`);
826
+ }
827
+ root(state) {
828
+ const root = createElement(AlephaContext.Provider, { value: this.alepha }, createElement(NestedView_default, {}, state.layers[0]?.element));
829
+ if (this.env.REACT_STRICT_MODE) return createElement(StrictMode, {}, root);
830
+ return root;
831
+ }
832
+ convertStringObjectToObject = (schema, value) => {
833
+ if (t.schema.isObject(schema) && typeof value === "object") {
834
+ for (const key in schema.properties) if (t.schema.isObject(schema.properties[key]) && typeof value[key] === "string") try {
835
+ value[key] = this.alepha.codec.decode(schema.properties[key], decodeURIComponent(value[key]));
836
+ } catch (e) {}
837
+ }
838
+ return value;
839
+ };
840
+ /**
841
+ * Create a new RouterState based on a given route and request.
842
+ * This method resolves the layers for the route, applying any query and params schemas defined in the route.
843
+ * It also handles errors and redirects.
844
+ */
845
+ async createLayers(route, state, previous = []) {
846
+ let context = {};
847
+ const stack = [{ route }];
848
+ let parent = route.parent;
849
+ while (parent) {
850
+ stack.unshift({ route: parent });
851
+ parent = parent.parent;
852
+ }
853
+ let forceRefresh = false;
854
+ for (let i = 0; i < stack.length; i++) {
855
+ const it = stack[i];
856
+ const route$1 = it.route;
857
+ const config = {};
858
+ try {
859
+ this.convertStringObjectToObject(route$1.schema?.query, state.query);
860
+ config.query = route$1.schema?.query ? this.alepha.codec.decode(route$1.schema.query, state.query) : {};
861
+ } catch (e) {
862
+ it.error = e;
863
+ break;
864
+ }
865
+ try {
866
+ config.params = route$1.schema?.params ? this.alepha.codec.decode(route$1.schema.params, state.params) : {};
867
+ } catch (e) {
868
+ it.error = e;
869
+ break;
870
+ }
871
+ it.config = { ...config };
872
+ if (previous?.[i] && !forceRefresh && previous[i].name === route$1.name) {
873
+ const url = (str) => str ? str.replace(/\/\/+/g, "/") : "/";
874
+ if (JSON.stringify({
875
+ part: url(previous[i].part),
876
+ params: previous[i].config?.params ?? {}
877
+ }) === JSON.stringify({
878
+ part: url(route$1.path),
879
+ params: config.params ?? {}
880
+ })) {
881
+ it.props = previous[i].props;
882
+ it.error = previous[i].error;
883
+ it.cache = true;
884
+ context = {
885
+ ...context,
886
+ ...it.props
887
+ };
888
+ continue;
889
+ }
890
+ forceRefresh = true;
891
+ }
892
+ if (!route$1.resolve) continue;
893
+ try {
894
+ const args = Object.create(state);
895
+ Object.assign(args, config, context);
896
+ const props = await route$1.resolve?.(args) ?? {};
897
+ it.props = { ...props };
898
+ context = {
899
+ ...context,
900
+ ...props
901
+ };
902
+ } catch (e) {
903
+ if (e instanceof Redirection) return { redirect: e.redirect };
904
+ this.log.error("Page resolver has failed", e);
905
+ it.error = e;
906
+ break;
907
+ }
908
+ }
909
+ let acc = "";
910
+ for (let i = 0; i < stack.length; i++) {
911
+ const it = stack[i];
912
+ const props = it.props ?? {};
913
+ const params = { ...it.config?.params };
914
+ for (const key of Object.keys(params)) params[key] = String(params[key]);
915
+ acc += "/";
916
+ acc += it.route.path ? this.compile(it.route.path, params) : "";
917
+ const path = acc.replace(/\/+/, "/");
918
+ const localErrorHandler = this.getErrorHandler(it.route);
919
+ if (localErrorHandler) {
920
+ const onErrorParent = state.onError;
921
+ state.onError = (error, context$1) => {
922
+ const result = localErrorHandler(error, context$1);
923
+ if (result === void 0) return onErrorParent(error, context$1);
924
+ return result;
925
+ };
926
+ }
927
+ if (!it.error) try {
928
+ const element = await this.createElement(it.route, {
929
+ ...it.route.props ? it.route.props() : {},
930
+ ...props,
931
+ ...context
932
+ });
933
+ state.layers.push({
934
+ name: it.route.name,
935
+ props,
936
+ part: it.route.path,
937
+ config: it.config,
938
+ element: this.renderView(i + 1, path, element, it.route),
939
+ index: i + 1,
940
+ path,
941
+ route: it.route,
942
+ cache: it.cache
943
+ });
944
+ } catch (e) {
945
+ it.error = e;
946
+ }
947
+ if (it.error) try {
948
+ let element = await state.onError(it.error, state);
949
+ if (element === void 0) throw it.error;
950
+ if (element instanceof Redirection) return { redirect: element.redirect };
951
+ if (element === null) element = this.renderError(it.error);
952
+ state.layers.push({
953
+ props,
954
+ error: it.error,
955
+ name: it.route.name,
956
+ part: it.route.path,
957
+ config: it.config,
958
+ element: this.renderView(i + 1, path, element, it.route),
959
+ index: i + 1,
960
+ path,
961
+ route: it.route
962
+ });
963
+ break;
964
+ } catch (e) {
965
+ if (e instanceof Redirection) return { redirect: e.redirect };
966
+ throw e;
967
+ }
968
+ }
969
+ return { state };
970
+ }
971
+ getErrorHandler(route) {
972
+ if (route.errorHandler) return route.errorHandler;
973
+ let parent = route.parent;
974
+ while (parent) {
975
+ if (parent.errorHandler) return parent.errorHandler;
976
+ parent = parent.parent;
977
+ }
978
+ }
979
+ async createElement(page, props) {
980
+ if (page.lazy && page.component) this.log.warn(`Page ${page.name} has both lazy and component options, lazy will be used`);
981
+ if (page.lazy) return createElement((await page.lazy()).default, props);
982
+ if (page.component) return createElement(page.component, props);
983
+ }
984
+ renderError(error) {
985
+ return createElement(ErrorViewer_default, {
986
+ error,
987
+ alepha: this.alepha
988
+ });
989
+ }
990
+ renderEmptyView() {
991
+ return createElement(NestedView_default, {});
992
+ }
993
+ href(page, params = {}) {
994
+ const found = this.pages.find((it) => it.name === page.options.name);
995
+ if (!found) throw new AlephaError(`Page ${page.options.name} not found`);
996
+ let url = found.path ?? "";
997
+ let parent = found.parent;
998
+ while (parent) {
999
+ url = `${parent.path ?? ""}/${url}`;
1000
+ parent = parent.parent;
1001
+ }
1002
+ url = this.compile(url, params);
1003
+ return url.replace(/\/\/+/g, "/") || "/";
1004
+ }
1005
+ compile(path, params = {}) {
1006
+ for (const [key, value] of Object.entries(params)) path = path.replace(`:${key}`, value);
1007
+ return path;
1008
+ }
1009
+ renderView(index, path, view, page) {
1010
+ view ??= this.renderEmptyView();
1011
+ const element = page.client ? createElement(ClientOnly, typeof page.client === "object" ? page.client : {}, view) : view;
1012
+ return createElement(RouterLayerContext.Provider, { value: {
1013
+ index,
1014
+ path,
1015
+ onError: this.getErrorHandler(page) ?? ((error) => this.renderError(error))
1016
+ } }, element);
1017
+ }
1018
+ configure = $hook({
1019
+ on: "configure",
1020
+ handler: () => {
1021
+ let hasNotFoundHandler = false;
1022
+ const pages = this.alepha.primitives($page);
1023
+ const hasParent = (it) => {
1024
+ if (it.options.parent) return true;
1025
+ for (const page of pages) if ((page.options.children ? Array.isArray(page.options.children) ? page.options.children : page.options.children() : []).includes(it)) return true;
1026
+ };
1027
+ for (const page of pages) {
1028
+ if (page.options.path === "/*") hasNotFoundHandler = true;
1029
+ if (hasParent(page)) continue;
1030
+ this.add(this.map(pages, page));
1031
+ }
1032
+ if (!hasNotFoundHandler && pages.length > 0) this.add({
1033
+ path: "/*",
1034
+ name: "notFound",
1035
+ cache: true,
1036
+ component: NotFound_default,
1037
+ onServerResponse: ({ reply }) => {
1038
+ reply.status = 404;
1039
+ }
1040
+ });
1041
+ }
1042
+ });
1043
+ map(pages, target) {
1044
+ const children = target.options.children ? Array.isArray(target.options.children) ? target.options.children : target.options.children() : [];
1045
+ const getChildrenFromParent = (it) => {
1046
+ const children$1 = [];
1047
+ for (const page of pages) if (page.options.parent === it) children$1.push(page);
1048
+ return children$1;
1049
+ };
1050
+ children.push(...getChildrenFromParent(target));
1051
+ return {
1052
+ ...target.options,
1053
+ name: target.name,
1054
+ parent: void 0,
1055
+ children: children.map((it) => this.map(pages, it))
1056
+ };
1057
+ }
1058
+ add(entry) {
1059
+ if (this.alepha.isReady()) throw new AlephaError("Router is already initialized");
1060
+ entry.name ??= this.nextId();
1061
+ const page = entry;
1062
+ page.match = this.createMatch(page);
1063
+ this.pages.push(page);
1064
+ if (page.children) for (const child of page.children) {
1065
+ child.parent = page;
1066
+ this.add(child);
1067
+ }
1068
+ }
1069
+ createMatch(page) {
1070
+ let url = page.path ?? "/";
1071
+ let target = page.parent;
1072
+ while (target) {
1073
+ url = `${target.path ?? ""}/${url}`;
1074
+ target = target.parent;
1075
+ }
1076
+ let path = url.replace(/\/\/+/g, "/");
1077
+ if (path.endsWith("/") && path !== "/") path = path.slice(0, -1);
1078
+ return path;
1079
+ }
1080
+ _next = 0;
1081
+ nextId() {
1082
+ this._next += 1;
1083
+ return `P${this._next}`;
1084
+ }
1085
+ };
1086
+ const isPageRoute = (it) => {
1087
+ return it && typeof it === "object" && typeof it.path === "string" && typeof it.page === "object";
1088
+ };
1089
+
1090
+ //#endregion
1091
+ //#region ../../src/router/providers/ReactBrowserRouterProvider.ts
1092
+ /**
1093
+ * Implementation of AlephaRouter for React in browser environment.
1094
+ */
1095
+ var ReactBrowserRouterProvider = class extends RouterProvider {
1096
+ log = $logger();
1097
+ alepha = $inject(Alepha);
1098
+ pageApi = $inject(ReactPageProvider);
1099
+ add(entry) {
1100
+ this.pageApi.add(entry);
1101
+ }
1102
+ configure = $hook({
1103
+ on: "configure",
1104
+ handler: async () => {
1105
+ for (const page of this.pageApi.getPages()) if (page.component || page.lazy) this.push({
1106
+ path: page.match,
1107
+ page
1108
+ });
1109
+ }
1110
+ });
1111
+ async transition(url, previous = [], meta = {}) {
1112
+ const { pathname, search } = url;
1113
+ const state = {
1114
+ url,
1115
+ query: {},
1116
+ params: {},
1117
+ layers: [],
1118
+ onError: () => null,
1119
+ meta
1120
+ };
1121
+ await this.alepha.events.emit("react:action:begin", { type: "transition" });
1122
+ await this.alepha.events.emit("react:transition:begin", {
1123
+ previous: this.alepha.store.get("alepha.react.router.state"),
1124
+ state
1125
+ });
1126
+ try {
1127
+ const { route, params } = this.match(pathname);
1128
+ const query = {};
1129
+ if (search) for (const [key, value] of new URLSearchParams(search).entries()) query[key] = String(value);
1130
+ state.name = route?.page.name;
1131
+ state.query = query;
1132
+ state.params = params ?? {};
1133
+ if (isPageRoute(route)) {
1134
+ const { redirect } = await this.pageApi.createLayers(route.page, state, previous);
1135
+ if (redirect) return redirect;
1136
+ }
1137
+ if (state.layers.length === 0) state.layers.push({
1138
+ name: "not-found",
1139
+ element: createElement(NotFound_default),
1140
+ index: 0,
1141
+ path: "/"
1142
+ });
1143
+ await this.alepha.events.emit("react:action:success", { type: "transition" });
1144
+ await this.alepha.events.emit("react:transition:success", { state });
1145
+ } catch (e) {
1146
+ this.log.error("Transition has failed", e);
1147
+ state.layers = [{
1148
+ name: "error",
1149
+ element: this.pageApi.renderError(e),
1150
+ index: 0,
1151
+ path: "/"
1152
+ }];
1153
+ await this.alepha.events.emit("react:action:error", {
1154
+ type: "transition",
1155
+ error: e
1156
+ });
1157
+ await this.alepha.events.emit("react:transition:error", {
1158
+ error: e,
1159
+ state
1160
+ });
1161
+ }
1162
+ if (previous) for (let i = 0; i < previous.length; i++) {
1163
+ const layer = previous[i];
1164
+ if (state.layers[i]?.name !== layer.name) this.pageApi.page(layer.name)?.onLeave?.();
1165
+ }
1166
+ this.alepha.store.set("alepha.react.router.state", state);
1167
+ await this.alepha.events.emit("react:action:end", { type: "transition" });
1168
+ await this.alepha.events.emit("react:transition:end", { state });
1169
+ }
1170
+ root(state) {
1171
+ return this.pageApi.root(state);
1172
+ }
1173
+ };
1174
+
1175
+ //#endregion
1176
+ //#region ../../src/router/providers/ReactBrowserProvider.ts
1177
+ const envSchema$1 = t.object({ REACT_ROOT_ID: t.text({ default: "root" }) });
1178
+ /**
1179
+ * React browser renderer configuration atom
1180
+ */
1181
+ const reactBrowserOptions = $atom({
1182
+ name: "alepha.react.browser.options",
1183
+ schema: t.object({ scrollRestoration: t.enum(["top", "manual"]) }),
1184
+ default: { scrollRestoration: "top" }
1185
+ });
1186
+ var ReactBrowserProvider = class {
1187
+ env = $env(envSchema$1);
1188
+ log = $logger();
1189
+ client = $inject(LinkProvider);
1190
+ alepha = $inject(Alepha);
1191
+ router = $inject(ReactBrowserRouterProvider);
1192
+ dateTimeProvider = $inject(DateTimeProvider);
1193
+ options = $use(reactBrowserOptions);
1194
+ getRootElement() {
1195
+ const root = this.document.getElementById(this.env.REACT_ROOT_ID);
1196
+ if (root) return root;
1197
+ const div = this.document.createElement("div");
1198
+ div.id = this.env.REACT_ROOT_ID;
1199
+ this.document.body.prepend(div);
1200
+ return div;
1201
+ }
1202
+ transitioning;
1203
+ get state() {
1204
+ return this.alepha.store.get("alepha.react.router.state");
1205
+ }
1206
+ /**
1207
+ * Accessor for Document DOM API.
1208
+ */
1209
+ get document() {
1210
+ return window.document;
1211
+ }
1212
+ /**
1213
+ * Accessor for History DOM API.
1214
+ */
1215
+ get history() {
1216
+ return window.history;
1217
+ }
1218
+ /**
1219
+ * Accessor for Location DOM API.
1220
+ */
1221
+ get location() {
1222
+ return window.location;
1223
+ }
1224
+ get base() {
1225
+ const base = import.meta.env?.BASE_URL;
1226
+ if (!base || base === "/") return "";
1227
+ return base;
1228
+ }
1229
+ get url() {
1230
+ const url = this.location.pathname + this.location.search;
1231
+ if (this.base) return url.replace(this.base, "");
1232
+ return url;
1233
+ }
1234
+ pushState(path, replace) {
1235
+ const url = this.base + path;
1236
+ if (replace) this.history.replaceState({}, "", url);
1237
+ else this.history.pushState({}, "", url);
1238
+ }
1239
+ async invalidate(props) {
1240
+ const previous = [];
1241
+ this.log.trace("Invalidating layers");
1242
+ if (props) {
1243
+ const [key] = Object.keys(props);
1244
+ const value = props[key];
1245
+ for (const layer of this.state.layers) {
1246
+ if (layer.props?.[key]) {
1247
+ previous.push({
1248
+ ...layer,
1249
+ props: {
1250
+ ...layer.props,
1251
+ [key]: value
1252
+ }
1253
+ });
1254
+ break;
1255
+ }
1256
+ previous.push(layer);
1257
+ }
1258
+ }
1259
+ await this.render({ previous });
1260
+ }
1261
+ async go(url, options = {}) {
1262
+ this.log.trace(`Going to ${url}`, {
1263
+ url,
1264
+ options
1265
+ });
1266
+ await this.render({
1267
+ url,
1268
+ previous: options.force ? [] : this.state.layers,
1269
+ meta: options.meta
1270
+ });
1271
+ if (this.state.url.pathname + this.state.url.search !== url) {
1272
+ this.pushState(this.state.url.pathname + this.state.url.search);
1273
+ return;
1274
+ }
1275
+ this.pushState(url, options.replace);
1276
+ }
1277
+ async render(options = {}) {
1278
+ const previous = options.previous ?? this.state.layers;
1279
+ const url = options.url ?? this.url;
1280
+ const start = this.dateTimeProvider.now();
1281
+ this.transitioning = {
1282
+ to: url,
1283
+ from: this.state?.url.pathname
1284
+ };
1285
+ this.log.debug("Transitioning...", { to: url });
1286
+ const redirect = await this.router.transition(new URL(`http://localhost${url}`), previous, options.meta);
1287
+ if (redirect) {
1288
+ this.log.info("Redirecting to", { redirect });
1289
+ if (redirect.startsWith("http")) window.location.href = redirect;
1290
+ else return await this.render({ url: redirect });
1291
+ }
1292
+ const ms = this.dateTimeProvider.now().diff(start);
1293
+ this.log.info(`Transition OK [${ms}ms]`, this.transitioning);
1294
+ this.transitioning = void 0;
1295
+ }
1296
+ /**
1297
+ * Get embedded layers from the server.
1298
+ */
1299
+ getHydrationState() {
1300
+ try {
1301
+ if ("__ssr" in window && typeof window.__ssr === "object") return window.__ssr;
1302
+ } catch (error) {
1303
+ console.error(error);
1304
+ }
1305
+ }
1306
+ onTransitionEnd = $hook({
1307
+ on: "react:transition:end",
1308
+ handler: () => {
1309
+ if (this.options.scrollRestoration === "top" && typeof window !== "undefined" && !this.alepha.isTest()) {
1310
+ this.log.trace("Restoring scroll position to top");
1311
+ window.scrollTo(0, 0);
1312
+ }
1313
+ }
1314
+ });
1315
+ ready = $hook({
1316
+ on: "ready",
1317
+ handler: async () => {
1318
+ const hydration = this.getHydrationState();
1319
+ const previous = hydration?.layers ?? [];
1320
+ if (hydration) {
1321
+ for (const [key, value] of Object.entries(hydration)) if (key !== "layers") this.alepha.store.set(key, value);
1322
+ }
1323
+ await this.render({ previous });
1324
+ const element = this.router.root(this.state);
1325
+ await this.alepha.events.emit("react:browser:render", {
1326
+ element,
1327
+ root: this.getRootElement(),
1328
+ hydration,
1329
+ state: this.state
1330
+ });
1331
+ window.addEventListener("popstate", () => {
1332
+ if (this.base + this.state.url.pathname === this.location.pathname) return;
1333
+ this.log.debug("Popstate event triggered - rendering new state", { url: this.location.pathname + this.location.search });
1334
+ this.render();
1335
+ });
1336
+ }
1337
+ });
1338
+ };
1339
+
1340
+ //#endregion
1341
+ //#region ../../src/router/services/ReactRouter.ts
1342
+ /**
1343
+ * Friendly browser router API.
1344
+ *
1345
+ * Can be safely used server-side, but most methods will be no-op.
1346
+ */
1347
+ var ReactRouter = class {
1348
+ alepha = $inject(Alepha);
1349
+ pageApi = $inject(ReactPageProvider);
1350
+ get state() {
1351
+ return this.alepha.store.get("alepha.react.router.state");
1352
+ }
1353
+ get pages() {
1354
+ return this.pageApi.getPages();
1355
+ }
1356
+ get concretePages() {
1357
+ return this.pageApi.getConcretePages();
1358
+ }
1359
+ get browser() {
1360
+ if (this.alepha.isBrowser()) return this.alepha.inject(ReactBrowserProvider);
1361
+ }
1362
+ isActive(href, options = {}) {
1363
+ const current = this.state.url.pathname;
1364
+ let isActive = current === href || current === `${href}/` || `${current}/` === href;
1365
+ if (options.startWith && !isActive) isActive = current.startsWith(href);
1366
+ return isActive;
1367
+ }
1368
+ node(name, config = {}) {
1369
+ const page = this.pageApi.page(name);
1370
+ if (!page.lazy && !page.component) return {
1371
+ ...page,
1372
+ label: page.label ?? page.name,
1373
+ children: void 0
1374
+ };
1375
+ return {
1376
+ ...page,
1377
+ label: page.label ?? page.name,
1378
+ href: this.path(name, config),
1379
+ children: void 0
1380
+ };
1381
+ }
1382
+ path(name, config = {}) {
1383
+ return this.pageApi.pathname(name, {
1384
+ params: {
1385
+ ...this.state?.params,
1386
+ ...config.params
1387
+ },
1388
+ query: config.query
1389
+ });
1390
+ }
1391
+ /**
1392
+ * Reload the current page.
1393
+ * This is equivalent to calling `go()` with the current pathname and search.
1394
+ */
1395
+ async reload() {
1396
+ if (!this.browser) return;
1397
+ await this.go(this.location.pathname + this.location.search, {
1398
+ replace: true,
1399
+ force: true
1400
+ });
1401
+ }
1402
+ getURL() {
1403
+ if (!this.browser) return this.state.url;
1404
+ return new URL(this.location.href);
1405
+ }
1406
+ get location() {
1407
+ if (!this.browser) throw new Error("Browser is required");
1408
+ return this.browser.location;
1409
+ }
1410
+ get current() {
1411
+ return this.state;
1412
+ }
1413
+ get pathname() {
1414
+ return this.state.url.pathname;
1415
+ }
1416
+ get query() {
1417
+ const query = {};
1418
+ for (const [key, value] of new URLSearchParams(this.state.url.search).entries()) query[key] = String(value);
1419
+ return query;
1420
+ }
1421
+ async back() {
1422
+ this.browser?.history.back();
1423
+ }
1424
+ async forward() {
1425
+ this.browser?.history.forward();
1426
+ }
1427
+ async invalidate(props) {
1428
+ await this.browser?.invalidate(props);
1429
+ }
1430
+ async go(path, options) {
1431
+ for (const page of this.pages) if (page.name === path) {
1432
+ await this.browser?.go(this.path(path, options), options);
1433
+ return;
1434
+ }
1435
+ await this.browser?.go(path, options);
1436
+ }
1437
+ anchor(path, options = {}) {
1438
+ let href = path;
1439
+ for (const page of this.pages) if (page.name === path) {
1440
+ href = this.path(path, options);
1441
+ break;
1442
+ }
1443
+ return {
1444
+ href: this.base(href),
1445
+ onClick: (ev) => {
1446
+ ev.stopPropagation();
1447
+ ev.preventDefault();
1448
+ this.go(href, options).catch(console.error);
1449
+ }
1450
+ };
1451
+ }
1452
+ base(path) {
1453
+ const base = import.meta.env?.BASE_URL;
1454
+ if (!base || base === "/") return path;
1455
+ return base + path;
1456
+ }
1457
+ /**
1458
+ * Set query params.
1459
+ *
1460
+ * @param record
1461
+ * @param options
1462
+ */
1463
+ setQueryParams(record, options = {}) {
1464
+ const func = typeof record === "function" ? record : () => record;
1465
+ const search = new URLSearchParams(func(this.query)).toString();
1466
+ const state = search ? `${this.pathname}?${search}` : this.pathname;
1467
+ if (options.push) window.history.pushState({}, "", state);
1468
+ else window.history.replaceState({}, "", state);
1469
+ }
1470
+ };
1471
+
1472
+ //#endregion
1473
+ //#region ../../src/router/providers/ReactServerProvider.ts
1474
+ const envSchema = t.object({
1475
+ REACT_SSR_ENABLED: t.optional(t.boolean()),
1476
+ REACT_ROOT_ID: t.text({ default: "root" })
1477
+ });
1478
+ /**
1479
+ * React server provider configuration atom
1480
+ */
1481
+ const reactServerOptions = $atom({
1482
+ name: "alepha.react.server.options",
1483
+ schema: t.object({
1484
+ publicDir: t.string(),
1485
+ staticServer: t.object({
1486
+ disabled: t.boolean(),
1487
+ path: t.string({ description: "URL path where static files will be served." })
1488
+ })
1489
+ }),
1490
+ default: {
1491
+ publicDir: "public",
1492
+ staticServer: {
1493
+ disabled: false,
1494
+ path: "/"
1495
+ }
1496
+ }
1497
+ });
1498
+ /**
1499
+ * React server provider responsible for SSR and static file serving.
1500
+ *
1501
+ * Use `react-dom/server` under the hood.
1502
+ */
1503
+ var ReactServerProvider = class {
1504
+ log = $logger();
1505
+ alepha = $inject(Alepha);
1506
+ env = $env(envSchema);
1507
+ pageApi = $inject(ReactPageProvider);
1508
+ serverStaticProvider = $inject(ServerStaticProvider);
1509
+ serverRouterProvider = $inject(ServerRouterProvider);
1510
+ serverTimingProvider = $inject(ServerTimingProvider);
1511
+ ROOT_DIV_REGEX = new RegExp(`<div([^>]*)\\s+id=["']${this.env.REACT_ROOT_ID}["']([^>]*)>(.*?)<\\/div>`, "is");
1512
+ preprocessedTemplate = null;
1513
+ options = $use(reactServerOptions);
1514
+ /**
1515
+ * Configure the React server provider.
1516
+ */
1517
+ onConfigure = $hook({
1518
+ on: "configure",
1519
+ handler: async () => {
1520
+ const ssrEnabled = this.alepha.primitives($page).length > 0 && this.env.REACT_SSR_ENABLED !== false;
1521
+ this.alepha.store.set("alepha.react.server.ssr", ssrEnabled);
1522
+ if (this.alepha.isViteDev()) {
1523
+ await this.configureVite(ssrEnabled);
1524
+ return;
1525
+ }
1526
+ let root = "";
1527
+ if (!this.alepha.isServerless()) {
1528
+ root = this.getPublicDirectory();
1529
+ if (!root) this.log.warn("Missing static files, static file server will be disabled");
1530
+ else {
1531
+ this.log.debug(`Using static files from: ${root}`);
1532
+ await this.configureStaticServer(root);
1533
+ }
1534
+ }
1535
+ if (ssrEnabled) {
1536
+ await this.registerPages(async () => this.template);
1537
+ this.log.info("SSR OK");
1538
+ return;
1539
+ }
1540
+ this.log.info("SSR is disabled, use History API fallback");
1541
+ this.serverRouterProvider.createRoute({
1542
+ path: "*",
1543
+ handler: async ({ url, reply }) => {
1544
+ if (url.pathname.includes(".")) {
1545
+ reply.headers["content-type"] = "text/plain";
1546
+ reply.body = "Not Found";
1547
+ reply.status = 404;
1548
+ return;
1549
+ }
1550
+ reply.headers["content-type"] = "text/html";
1551
+ return this.template;
1552
+ }
1553
+ });
1554
+ }
1555
+ });
1556
+ get template() {
1557
+ return this.alepha.store.get("alepha.react.server.template") ?? "<!DOCTYPE html><html lang='en'><head></head><body></body></html>";
1558
+ }
1559
+ async registerPages(templateLoader) {
1560
+ const template = await templateLoader();
1561
+ if (template) this.preprocessedTemplate = this.preprocessTemplate(template);
1562
+ for (const page of this.pageApi.getPages()) if (page.component || page.lazy) {
1563
+ this.log.debug(`+ ${page.match} -> ${page.name}`);
1564
+ this.serverRouterProvider.createRoute({
1565
+ ...page,
1566
+ schema: void 0,
1567
+ method: "GET",
1568
+ path: page.match,
1569
+ handler: this.createHandler(page, templateLoader)
1570
+ });
1571
+ }
1572
+ }
1573
+ /**
1574
+ * Get the public directory path where static files are located.
1575
+ */
1576
+ getPublicDirectory() {
1577
+ const maybe = [join(process.cwd(), `dist/${this.options.publicDir}`), join(process.cwd(), this.options.publicDir)];
1578
+ for (const it of maybe) if (existsSync(it)) return it;
1579
+ return "";
1580
+ }
1581
+ /**
1582
+ * Configure the static file server to serve files from the given root directory.
1583
+ */
1584
+ async configureStaticServer(root) {
1585
+ await this.serverStaticProvider.createStaticServer({
1586
+ root,
1587
+ cacheControl: {
1588
+ maxAge: 3600,
1589
+ immutable: true
1590
+ },
1591
+ ...this.options.staticServer
1592
+ });
1593
+ }
1594
+ /**
1595
+ * Configure Vite for SSR.
1596
+ */
1597
+ async configureVite(ssrEnabled) {
1598
+ if (!ssrEnabled) return;
1599
+ this.log.info("SSR (dev) OK");
1600
+ const url = `http://${process.env.SERVER_HOST}:${process.env.SERVER_PORT}`;
1601
+ await this.registerPages(() => fetch(`${url}/index.html`).then((it) => it.text()).catch(() => void 0));
1602
+ }
1603
+ /**
1604
+ * For testing purposes, creates a render function that can be used.
1605
+ */
1606
+ async render(name, options = {}) {
1607
+ const page = this.pageApi.page(name);
1608
+ const url = new URL(this.pageApi.url(name, options));
1609
+ const state = {
1610
+ url,
1611
+ params: options.params ?? {},
1612
+ query: options.query ?? {},
1613
+ onError: () => null,
1614
+ layers: [],
1615
+ meta: {}
1616
+ };
1617
+ this.log.trace("Rendering", { url });
1618
+ await this.alepha.events.emit("react:server:render:begin", { state });
1619
+ const { redirect } = await this.pageApi.createLayers(page, state);
1620
+ if (redirect) return {
1621
+ state,
1622
+ html: "",
1623
+ redirect
1624
+ };
1625
+ if (!options.html) {
1626
+ this.alepha.store.set("alepha.react.router.state", state);
1627
+ return {
1628
+ state,
1629
+ html: renderToString(this.pageApi.root(state))
1630
+ };
1631
+ }
1632
+ const template = this.template ?? "";
1633
+ const html = this.renderToHtml(template, state, options.hydration);
1634
+ if (html instanceof Redirection) return {
1635
+ state,
1636
+ html: "",
1637
+ redirect
1638
+ };
1639
+ const result = {
1640
+ state,
1641
+ html
1642
+ };
1643
+ await this.alepha.events.emit("react:server:render:end", result);
1644
+ return result;
1645
+ }
1646
+ createHandler(route, templateLoader) {
1647
+ return async (serverRequest) => {
1648
+ const { url, reply, query, params } = serverRequest;
1649
+ const template = await templateLoader();
1650
+ if (!template) throw new AlephaError("Missing template for SSR rendering");
1651
+ this.log.trace("Rendering page", { name: route.name });
1652
+ const state = {
1653
+ url,
1654
+ params,
1655
+ query,
1656
+ onError: () => null,
1657
+ layers: []
1658
+ };
1659
+ state.name = route.name;
1660
+ if (this.alepha.has(ServerLinksProvider)) this.alepha.store.set("alepha.server.request.apiLinks", await this.alepha.inject(ServerLinksProvider).getUserApiLinks({
1661
+ user: serverRequest.user,
1662
+ authorization: serverRequest.headers.authorization
1663
+ }));
1664
+ let target = route;
1665
+ while (target) {
1666
+ if (route.can && !route.can()) {
1667
+ this.log.warn(`Access to page '${route.name}' is forbidden by can() check`);
1668
+ reply.status = 403;
1669
+ reply.headers["content-type"] = "text/plain";
1670
+ return "Forbidden";
1671
+ }
1672
+ target = target.parent;
1673
+ }
1674
+ await this.alepha.events.emit("react:server:render:begin", {
1675
+ request: serverRequest,
1676
+ state
1677
+ });
1678
+ this.serverTimingProvider.beginTiming("createLayers");
1679
+ const { redirect } = await this.pageApi.createLayers(route, state);
1680
+ this.serverTimingProvider.endTiming("createLayers");
1681
+ if (redirect) {
1682
+ this.log.debug("Resolver resulted in redirection", { redirect });
1683
+ return reply.redirect(redirect);
1684
+ }
1685
+ reply.headers["content-type"] = "text/html";
1686
+ reply.headers["cache-control"] = "no-store, no-cache, must-revalidate, proxy-revalidate";
1687
+ reply.headers.pragma = "no-cache";
1688
+ reply.headers.expires = "0";
1689
+ const html = this.renderToHtml(template, state);
1690
+ if (html instanceof Redirection) {
1691
+ reply.redirect(typeof html.redirect === "string" ? html.redirect : this.pageApi.href(html.redirect));
1692
+ this.log.debug("Rendering resulted in redirection", { redirect: html.redirect });
1693
+ return;
1694
+ }
1695
+ this.log.trace("Page rendered to HTML successfully");
1696
+ const event = {
1697
+ request: serverRequest,
1698
+ state,
1699
+ html
1700
+ };
1701
+ await this.alepha.events.emit("react:server:render:end", event);
1702
+ route.onServerResponse?.(serverRequest);
1703
+ this.log.trace("Page rendered", { name: route.name });
1704
+ return event.html;
1705
+ };
1706
+ }
1707
+ renderToHtml(template, state, hydration = true) {
1708
+ const element = this.pageApi.root(state);
1709
+ this.alepha.store.set("alepha.react.router.state", state);
1710
+ this.serverTimingProvider.beginTiming("renderToString");
1711
+ let app = "";
1712
+ try {
1713
+ app = renderToString(element);
1714
+ } catch (error) {
1715
+ this.log.error("renderToString has failed, fallback to error handler", error);
1716
+ const element$1 = state.onError(error, state);
1717
+ if (element$1 instanceof Redirection) return element$1;
1718
+ app = renderToString(element$1);
1719
+ this.log.debug("Error handled successfully with fallback");
1720
+ }
1721
+ this.serverTimingProvider.endTiming("renderToString");
1722
+ const response = { html: template };
1723
+ if (hydration) {
1724
+ const { request, context, ...store } = this.alepha.context.als?.getStore() ?? {};
1725
+ const hydrationData = {
1726
+ ...store,
1727
+ "alepha.react.router.state": void 0,
1728
+ layers: state.layers.map((it) => ({
1729
+ ...it,
1730
+ error: it.error ? {
1731
+ ...it.error,
1732
+ name: it.error.name,
1733
+ message: it.error.message,
1734
+ stack: !this.alepha.isProduction() ? it.error.stack : void 0
1735
+ } : void 0,
1736
+ index: void 0,
1737
+ path: void 0,
1738
+ element: void 0,
1739
+ route: void 0
1740
+ }))
1741
+ };
1742
+ const script = `<script>window.__ssr=${JSON.stringify(hydrationData)}<\/script>`;
1743
+ this.fillTemplate(response, app, script);
1744
+ }
1745
+ return response.html;
1746
+ }
1747
+ preprocessTemplate(template) {
1748
+ const bodyCloseIndex = template.match(/<\/body>/i)?.index ?? template.length;
1749
+ const beforeScript = template.substring(0, bodyCloseIndex);
1750
+ const afterScript = template.substring(bodyCloseIndex);
1751
+ const rootDivMatch = beforeScript.match(this.ROOT_DIV_REGEX);
1752
+ if (rootDivMatch) {
1753
+ const beforeDiv = beforeScript.substring(0, rootDivMatch.index);
1754
+ const afterDivStart = rootDivMatch.index + rootDivMatch[0].length;
1755
+ const afterDiv = beforeScript.substring(afterDivStart);
1756
+ return {
1757
+ beforeApp: `${beforeDiv}<div${rootDivMatch[1]} id="${this.env.REACT_ROOT_ID}"${rootDivMatch[2]}>`,
1758
+ afterApp: `</div>${afterDiv}`,
1759
+ beforeScript: "",
1760
+ afterScript
1761
+ };
1762
+ }
1763
+ const bodyMatch = beforeScript.match(/<body([^>]*)>/i);
1764
+ if (bodyMatch) {
1765
+ const beforeBody = beforeScript.substring(0, bodyMatch.index + bodyMatch[0].length);
1766
+ const afterBody = beforeScript.substring(bodyMatch.index + bodyMatch[0].length);
1767
+ return {
1768
+ beforeApp: `${beforeBody}<div id="${this.env.REACT_ROOT_ID}">`,
1769
+ afterApp: `</div>${afterBody}`,
1770
+ beforeScript: "",
1771
+ afterScript
1772
+ };
1773
+ }
1774
+ return {
1775
+ beforeApp: `<div id="${this.env.REACT_ROOT_ID}">`,
1776
+ afterApp: `</div>`,
1777
+ beforeScript,
1778
+ afterScript
1779
+ };
1780
+ }
1781
+ fillTemplate(response, app, script) {
1782
+ if (!this.preprocessedTemplate) this.preprocessedTemplate = this.preprocessTemplate(response.html);
1783
+ response.html = this.preprocessedTemplate.beforeApp + app + this.preprocessedTemplate.afterApp + script + this.preprocessedTemplate.afterScript;
1784
+ }
1785
+ };
1786
+
1787
+ //#endregion
1788
+ //#region ../../src/router/services/ReactPageServerService.ts
1789
+ /**
1790
+ * $page methods for server-side.
1791
+ */
1792
+ var ReactPageServerService = class extends ReactPageService {
1793
+ reactServerProvider = $inject(ReactServerProvider);
1794
+ serverProvider = $inject(ServerProvider);
1795
+ async render(name, options = {}) {
1796
+ return this.reactServerProvider.render(name, options);
1797
+ }
1798
+ async fetch(pathname, options = {}) {
1799
+ const response = await fetch(`${this.serverProvider.hostname}/${pathname}`);
1800
+ const html = await response.text();
1801
+ if (options?.html) return {
1802
+ html,
1803
+ response
1804
+ };
1805
+ const match = html.match(this.reactServerProvider.ROOT_DIV_REGEX);
1806
+ if (match) return {
1807
+ html: match[3],
1808
+ response
1809
+ };
1810
+ throw new AlephaError("Invalid HTML response");
1811
+ }
1812
+ };
1813
+
1814
+ //#endregion
1815
+ //#region ../../src/router/index.ts
1816
+ /**
1817
+ * Provides declarative routing with the `$page` primitive for building type-safe React routes.
1818
+ *
1819
+ * This module enables:
1820
+ * - URL pattern matching with parameters (e.g., `/users/:id`)
1821
+ * - Nested routing with parent-child relationships
1822
+ * - Type-safe URL parameter and query string validation
1823
+ * - Server-side data fetching with the `resolve` function
1824
+ * - Lazy loading and code splitting
1825
+ * - Page animations and error handling
1826
+ *
1827
+ * @see {@link $page}
1828
+ * @module alepha.react.router
1829
+ */
1830
+ const AlephaReactRouter = $module({
1831
+ name: "alepha.react.router",
1832
+ primitives: [$page],
1833
+ services: [
1834
+ ReactPageProvider,
1835
+ ReactPageService,
1836
+ ReactRouter,
1837
+ ReactServerProvider,
1838
+ ReactPageServerService
1839
+ ],
1840
+ register: (alepha) => alepha.with(AlephaReact).with(AlephaDateTime).with(AlephaServer).with(AlephaServerCache).with(AlephaServerLinks).with({
1841
+ provide: ReactPageService,
1842
+ use: ReactPageServerService
1843
+ }).with(ReactServerProvider).with(ReactPageProvider).with(ReactRouter)
1844
+ });
1845
+
23
1846
  //#endregion
24
1847
  //#region ../../src/auth/services/ReactAuth.ts
25
1848
  /**