alepha 0.9.2 → 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.d.ts CHANGED
@@ -1,11 +1,14 @@
1
- import * as _alepha_core0$1 from "alepha";
1
+ import * as _alepha_core1 from "alepha";
2
2
  import * as _alepha_core0 from "alepha";
3
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";
4
6
 
5
7
  //#region src/providers/I18nProvider.d.ts
6
8
  declare class I18nProvider {
7
- logger: _alepha_core0$1.Logger;
9
+ logger: _alepha_core1.Logger;
8
10
  alepha: Alepha;
11
+ cookie: _alepha_server_cookies0.AbstractCookieDescriptor<_sinclair_typebox0.TString>;
9
12
  registry: Array<{
10
13
  name: string;
11
14
  lang: string;
@@ -15,15 +18,49 @@ declare class I18nProvider {
15
18
  options: {
16
19
  fallbackLang: string;
17
20
  };
18
- onRender: _alepha_core0$1.HookDescriptor<"server:onRequest">;
19
- onStart: _alepha_core0$1.HookDescriptor<"start">;
21
+ get languages(): string[];
22
+ onRender: _alepha_core1.HookDescriptor<"server:onRequest">;
23
+ onStart: _alepha_core1.HookDescriptor<"start">;
20
24
  setLang(lang: string): Promise<void>;
21
25
  get lang(): string;
22
- translate: (key: string) => string;
26
+ translate: (key: string, args?: string[]) => string;
27
+ protected render(item: string, args: string[]): string;
23
28
  }
24
29
  //# sourceMappingURL=I18nProvider.d.ts.map
30
+
25
31
  //#endregion
26
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
+ */
27
64
  declare const $dictionary: {
28
65
  <T extends Record<string, string>>(options: DictionaryDescriptorOptions<T>): DictionaryDescriptor<T>;
29
66
  [KIND]: typeof DictionaryDescriptor;
@@ -48,9 +85,11 @@ declare class DictionaryDescriptor<T extends Record<string, string>> extends Des
48
85
  declare const useI18n: <S extends object, K extends keyof ServiceDictionary<S>>() => {
49
86
  lang: string;
50
87
  setLang: (lang: string) => Promise<void>;
51
- tr: (key: keyof ServiceDictionary<S>[K]) => string;
88
+ tr: (key: keyof ServiceDictionary<S>[K] | string, args?: string[]) => string;
89
+ languages: string[];
52
90
  };
53
91
  type ServiceDictionary<T extends object> = { [K in keyof T]: T[K] extends DictionaryDescriptor<infer U> ? U : never };
92
+ //# sourceMappingURL=useI18n.d.ts.map
54
93
  //#endregion
55
94
  //#region src/index.d.ts
56
95
  declare module "alepha" {
@@ -65,9 +104,9 @@ declare module "alepha" {
65
104
  *
66
105
  * @module alepha.react.i18n
67
106
  */
68
- declare const AlephaReactI18n: _alepha_core0.ModuleDescriptor;
107
+ declare const AlephaReactI18n: _alepha_core0.Service<_alepha_core0.Module>;
69
108
  //# sourceMappingURL=index.d.ts.map
70
109
 
71
110
  //#endregion
72
- export { $dictionary, AlephaReactI18n, DictionaryDescriptor, DictionaryDescriptorOptions, I18nProvider, useI18n };
111
+ export { $dictionary, AlephaReactI18n, DictionaryDescriptor, DictionaryDescriptorOptions, I18nProvider, ServiceDictionary, useI18n };
73
112
  //# sourceMappingURL=index.d.ts.map