@alepha/react 0.12.1 → 0.13.1

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