alepha 0.9.1 → 0.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/react/head.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import * as _alepha_core0$1 from "alepha";
1
+ import * as _alepha_core1 from "alepha";
2
2
  import * as _alepha_core0 from "alepha";
3
+ import { Descriptor, KIND } from "alepha";
3
4
  import { PageConfigSchema, PageReactContext, PageRoute, RouterState, TPropsDefault, TPropsParentDefault } from "alepha/react";
4
5
 
5
6
  //#region src/interfaces/Head.d.ts
@@ -44,21 +45,58 @@ interface SimpleHead {
44
45
  }
45
46
  //# sourceMappingURL=Head.d.ts.map
46
47
  //#endregion
47
- //#region src/hooks/useHead.d.ts
48
- declare const useHead: (head?: Head | ((previous?: Head) => Head)) => void;
49
- //# sourceMappingURL=useHead.d.ts.map
50
- //#endregion
51
48
  //#region src/providers/HeadProvider.d.ts
52
49
  declare class HeadProvider {
50
+ global?: Head | (() => Head);
51
+ protected getGlobalHead(): Head | undefined;
53
52
  fillHead(state: RouterState, context: PageReactContext): void;
54
53
  protected fillHeadByPage(page: PageRoute, context: PageReactContext, props: Record<string, any>): void;
55
54
  }
56
55
  //# sourceMappingURL=HeadProvider.d.ts.map
57
56
  //#endregion
57
+ //#region src/descriptors/$head.d.ts
58
+ /**
59
+ * Set global `<head>` options for the application.
60
+ */
61
+ declare const $head: {
62
+ (options: HeadDescriptorOptions): HeadDescriptor;
63
+ [KIND]: typeof HeadDescriptor;
64
+ };
65
+ type HeadDescriptorOptions = Head | (() => Head);
66
+ declare class HeadDescriptor extends Descriptor<HeadDescriptorOptions> {
67
+ protected readonly provider: HeadProvider;
68
+ protected onInit(): void;
69
+ }
70
+ //# sourceMappingURL=$head.d.ts.map
71
+
72
+ //#endregion
73
+ //#region src/hooks/useHead.d.ts
74
+ /**
75
+ * ```tsx
76
+ * const App = () => {
77
+ * const [head, setHead] = useHead({
78
+ * // will set the document title on the first render
79
+ * title: "My App",
80
+ * });
81
+ *
82
+ * return (
83
+ * // This will update the document title when the button is clicked
84
+ * <button onClick={() => setHead({ title: "Change Title" })}>
85
+ * Change Title {head.title}
86
+ * </button>
87
+ * );
88
+ * }
89
+ * ```
90
+ */
91
+ declare const useHead: (options?: UseHeadOptions) => void;
92
+ type UseHeadOptions = Head | ((previous?: Head) => Head);
93
+ type UseHeadReturn = [Head, (head?: Head | ((previous?: Head) => Head)) => void];
94
+ //# sourceMappingURL=useHead.d.ts.map
95
+ //#endregion
58
96
  //#region src/providers/ServerHeadProvider.d.ts
59
97
  declare class ServerHeadProvider {
60
98
  protected readonly headProvider: HeadProvider;
61
- protected readonly onServerRenderEnd: _alepha_core0$1.HookDescriptor<"react:server:render:end">;
99
+ protected readonly onServerRenderEnd: _alepha_core1.HookDescriptor<"react:server:render:end">;
62
100
  renderHead(template: string, head: SimpleHead): string;
63
101
  protected mergeAttributes(existing: string, attrs: Record<string, string>): string;
64
102
  protected parseAttributes(attrStr: string): Record<string, string>;
@@ -81,9 +119,9 @@ declare module "alepha/react" {
81
119
  * @see {@link ServerHeadProvider}
82
120
  * @module alepha.react.head
83
121
  */
84
- declare const AlephaReactHead: _alepha_core0.ModuleDescriptor;
122
+ declare const AlephaReactHead: _alepha_core0.Service<_alepha_core0.Module>;
85
123
  //# sourceMappingURL=index.d.ts.map
86
124
 
87
125
  //#endregion
88
- export { AlephaReactHead, Head, ServerHeadProvider, SimpleHead, useHead };
126
+ export { $head, AlephaReactHead, Head, HeadDescriptor, HeadDescriptorOptions, ServerHeadProvider, SimpleHead, UseHeadOptions, UseHeadReturn, useHead };
89
127
  //# sourceMappingURL=index.d.ts.map
package/react/i18n.cjs ADDED
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+ var m = require('@alepha/react-i18n');
3
+ Object.keys(m).forEach(function (k) {
4
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
5
+ enumerable: true,
6
+ get: function () { return m[k]; }
7
+ });
8
+ });
@@ -0,0 +1,112 @@
1
+ import * as _alepha_core1 from "alepha";
2
+ import * as _alepha_core0 from "alepha";
3
+ import { Alepha, Descriptor, KIND } from "alepha";
4
+ import * as _alepha_server_cookies0 from "alepha/server/cookies";
5
+ import * as _sinclair_typebox0 from "@sinclair/typebox";
6
+
7
+ //#region src/providers/I18nProvider.d.ts
8
+ declare class I18nProvider {
9
+ logger: _alepha_core1.Logger;
10
+ alepha: Alepha;
11
+ cookie: _alepha_server_cookies0.AbstractCookieDescriptor<_sinclair_typebox0.TString>;
12
+ registry: Array<{
13
+ name: string;
14
+ lang: string;
15
+ loader: () => Promise<Record<string, string>>;
16
+ translations: Record<string, string>;
17
+ }>;
18
+ options: {
19
+ fallbackLang: string;
20
+ };
21
+ get languages(): string[];
22
+ onRender: _alepha_core1.HookDescriptor<"server:onRequest">;
23
+ onStart: _alepha_core1.HookDescriptor<"start">;
24
+ setLang(lang: string): Promise<void>;
25
+ get lang(): string;
26
+ translate: (key: string, args?: string[]) => string;
27
+ protected render(item: string, args: string[]): string;
28
+ }
29
+ //# sourceMappingURL=I18nProvider.d.ts.map
30
+
31
+ //#endregion
32
+ //#region src/descriptors/$dictionary.d.ts
33
+ /**
34
+ * Register a dictionary entry for translations.
35
+ *
36
+ * It allows you to define a set of translations for a specific language.
37
+ * Entry can be lazy-loaded, which is useful for large dictionaries or when translations are not needed immediately.
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * import { $dictionary } from "alepha/react/i18n";
42
+ *
43
+ * const Example = () => {
44
+ * const { tr } = useI18n<App, "en">();
45
+ * return <div>{tr("hello")}</div>; //
46
+ * }
47
+ *
48
+ * class App {
49
+ *
50
+ * en = $dictionary({
51
+ * // { default: { hello: "Hey" } }
52
+ * lazy: () => import("./translations/en.ts"),
53
+ * });
54
+ *
55
+ * home = $page({
56
+ * path: "/",
57
+ * component: Example,
58
+ * })
59
+ * }
60
+ *
61
+ * run(App);
62
+ * ```
63
+ */
64
+ declare const $dictionary: {
65
+ <T extends Record<string, string>>(options: DictionaryDescriptorOptions<T>): DictionaryDescriptor<T>;
66
+ [KIND]: typeof DictionaryDescriptor;
67
+ };
68
+ interface DictionaryDescriptorOptions<T extends Record<string, string>> {
69
+ lang?: string;
70
+ name?: string;
71
+ lazy: () => Promise<{
72
+ default: T;
73
+ }>;
74
+ }
75
+ declare class DictionaryDescriptor<T extends Record<string, string>> extends Descriptor<DictionaryDescriptorOptions<T>> {
76
+ protected provider: I18nProvider;
77
+ protected onInit(): void;
78
+ }
79
+ //# sourceMappingURL=$dictionary.d.ts.map
80
+ //#endregion
81
+ //#region src/hooks/useI18n.d.ts
82
+ /**
83
+ * Hook to access the i18n service.
84
+ */
85
+ declare const useI18n: <S extends object, K extends keyof ServiceDictionary<S>>() => {
86
+ lang: string;
87
+ setLang: (lang: string) => Promise<void>;
88
+ tr: (key: keyof ServiceDictionary<S>[K] | string, args?: string[]) => string;
89
+ languages: string[];
90
+ };
91
+ type ServiceDictionary<T extends object> = { [K in keyof T]: T[K] extends DictionaryDescriptor<infer U> ? U : never };
92
+ //# sourceMappingURL=useI18n.d.ts.map
93
+ //#endregion
94
+ //#region src/index.d.ts
95
+ declare module "alepha" {
96
+ interface State {
97
+ "react.i18n.lang"?: string;
98
+ }
99
+ }
100
+ /**
101
+ * Add i18n support to your Alepha React application. SSR and CSR compatible.
102
+ *
103
+ * It supports lazy loading of translations and provides a context to access the current language.
104
+ *
105
+ * @module alepha.react.i18n
106
+ */
107
+ declare const AlephaReactI18n: _alepha_core0.Service<_alepha_core0.Module>;
108
+ //# sourceMappingURL=index.d.ts.map
109
+
110
+ //#endregion
111
+ export { $dictionary, AlephaReactI18n, DictionaryDescriptor, DictionaryDescriptorOptions, I18nProvider, ServiceDictionary, useI18n };
112
+ //# sourceMappingURL=index.d.ts.map
package/react/i18n.js ADDED
@@ -0,0 +1 @@
1
+ export * from '@alepha/react-i18n'