alepha 0.11.4 → 0.11.5

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 +1,120 @@
1
- export * from '@alepha/react-head';
1
+ import * as _alepha_core1 from "alepha";
2
+ import { Descriptor, KIND } from "alepha";
3
+ import { PageConfigSchema, PageRoute, ReactRouterState, TPropsDefault, TPropsParentDefault } from "alepha/react";
4
+ import { ServerTimingProvider } from "alepha/server";
5
+
6
+ //#region src/interfaces/Head.d.ts
7
+ interface Head extends SimpleHead {
8
+ description?: string;
9
+ keywords?: string[];
10
+ author?: string;
11
+ robots?: string;
12
+ themeColor?: string;
13
+ viewport?: string | {
14
+ width?: string;
15
+ height?: string;
16
+ initialScale?: string;
17
+ maximumScale?: string;
18
+ userScalable?: "no" | "yes" | "0" | "1";
19
+ interactiveWidget?: "resizes-visual" | "resizes-content" | "overlays-content";
20
+ };
21
+ og?: {
22
+ title?: string;
23
+ description?: string;
24
+ image?: string;
25
+ url?: string;
26
+ type?: string;
27
+ };
28
+ twitter?: {
29
+ card?: string;
30
+ title?: string;
31
+ description?: string;
32
+ image?: string;
33
+ site?: string;
34
+ };
35
+ }
36
+ interface SimpleHead {
37
+ title?: string;
38
+ titleSeparator?: string;
39
+ htmlAttributes?: Record<string, string>;
40
+ bodyAttributes?: Record<string, string>;
41
+ meta?: Array<{
42
+ name: string;
43
+ content: string;
44
+ }>;
45
+ }
46
+ //#endregion
47
+ //#region src/providers/HeadProvider.d.ts
48
+ declare class HeadProvider {
49
+ global?: Head | (() => Head);
50
+ protected getGlobalHead(): Head | undefined;
51
+ fillHead(state: ReactRouterState): void;
52
+ protected fillHeadByPage(page: PageRoute, state: ReactRouterState, props: Record<string, any>): void;
53
+ }
54
+ //#endregion
55
+ //#region src/descriptors/$head.d.ts
56
+ /**
57
+ * Set global `<head>` options for the application.
58
+ */
59
+ declare const $head: {
60
+ (options: HeadDescriptorOptions): HeadDescriptor;
61
+ [KIND]: typeof HeadDescriptor;
62
+ };
63
+ type HeadDescriptorOptions = Head | (() => Head);
64
+ declare class HeadDescriptor extends Descriptor<HeadDescriptorOptions> {
65
+ protected readonly provider: HeadProvider;
66
+ protected onInit(): void;
67
+ }
68
+ //#endregion
69
+ //#region src/hooks/useHead.d.ts
70
+ /**
71
+ * ```tsx
72
+ * const App = () => {
73
+ * const [head, setHead] = useHead({
74
+ * // will set the document title on the first render
75
+ * title: "My App",
76
+ * });
77
+ *
78
+ * return (
79
+ * // This will update the document title when the button is clicked
80
+ * <button onClick={() => setHead({ title: "Change Title" })}>
81
+ * Change Title {head.title}
82
+ * </button>
83
+ * );
84
+ * }
85
+ * ```
86
+ */
87
+ declare const useHead: (options?: UseHeadOptions) => UseHeadReturn;
88
+ type UseHeadOptions = Head | ((previous?: Head) => Head);
89
+ type UseHeadReturn = [Head, (head?: Head | ((previous?: Head) => Head)) => void];
90
+ //#endregion
91
+ //#region src/providers/ServerHeadProvider.d.ts
92
+ declare class ServerHeadProvider {
93
+ protected readonly headProvider: HeadProvider;
94
+ protected readonly serverTimingProvider: ServerTimingProvider;
95
+ protected readonly onServerRenderEnd: _alepha_core1.HookDescriptor<"react:server:render:end">;
96
+ renderHead(template: string, head: SimpleHead): string;
97
+ protected mergeAttributes(existing: string, attrs: Record<string, string>): string;
98
+ protected parseAttributes(attrStr: string): Record<string, string>;
99
+ protected escapeHtml(str: string): string;
100
+ }
101
+ //#endregion
102
+ //#region src/index.d.ts
103
+ declare module "alepha/react" {
104
+ interface PageDescriptorOptions<TConfig extends PageConfigSchema = PageConfigSchema, TProps extends object = TPropsDefault, TPropsParent extends object = TPropsParentDefault> {
105
+ head?: Head | ((props: TProps, previous?: Head) => Head);
106
+ }
107
+ interface ReactRouterState {
108
+ head: Head;
109
+ }
110
+ }
111
+ /**
112
+ * Fill `<head>` server & client side.
113
+ *
114
+ * @see {@link ServerHeadProvider}
115
+ * @module alepha.react.head
116
+ */
117
+ declare const AlephaReactHead: _alepha_core1.Service<_alepha_core1.Module<{}>>;
118
+ //#endregion
119
+ export { $head, AlephaReactHead, Head, HeadDescriptor, HeadDescriptorOptions, ServerHeadProvider, SimpleHead, UseHeadOptions, UseHeadReturn, useHead };
120
+ //# sourceMappingURL=index.d.ts.map
package/react/i18n.d.ts CHANGED
@@ -1 +1,168 @@
1
- export * from '@alepha/react-i18n';
1
+ import * as _alepha_core1 from "alepha";
2
+ import { Alepha, Descriptor, KIND, TypeBoxError } from "alepha";
3
+ import { DateTime, DateTimeProvider } from "alepha/datetime";
4
+ import * as _alepha_logger0 from "alepha/logger";
5
+ import * as _alepha_server_cookies0 from "alepha/server/cookies";
6
+ import * as typebox0 from "typebox";
7
+
8
+ //#region src/components/Localize.d.ts
9
+ interface LocalizeProps {
10
+ value: string | number | Date | DateTime | TypeBoxError;
11
+ /**
12
+ * Options for number formatting (when value is a number)
13
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat
14
+ */
15
+ number?: Intl.NumberFormatOptions;
16
+ /**
17
+ * Options for date formatting (when value is a Date or DateTime)
18
+ * Can be:
19
+ * - A dayjs format string (e.g., "LLL", "YYYY-MM-DD", "dddd, MMMM D YYYY")
20
+ * - "fromNow" for relative time (e.g., "2 hours ago")
21
+ * - Intl.DateTimeFormatOptions for native formatting
22
+ * @see https://day.js.org/docs/en/display/format
23
+ * @see https://day.js.org/docs/en/display/from-now
24
+ */
25
+ date?: string | "fromNow" | Intl.DateTimeFormatOptions;
26
+ /**
27
+ * Timezone to display dates in (when value is a Date or DateTime)
28
+ * Uses IANA timezone names (e.g., "America/New_York", "Europe/Paris", "Asia/Tokyo")
29
+ * @see https://day.js.org/docs/en/timezone/timezone
30
+ */
31
+ timezone?: string;
32
+ }
33
+ declare const Localize: (props: LocalizeProps) => string;
34
+ //#endregion
35
+ //#region src/hooks/useI18n.d.ts
36
+ /**
37
+ * Hook to access the i18n service.
38
+ */
39
+ declare const useI18n: <S extends object, K$1 extends keyof ServiceDictionary<S>>() => I18nProvider<S, K$1>;
40
+ type ServiceDictionary<T extends object> = { [K in keyof T]: T[K] extends DictionaryDescriptor<infer U> ? U : never };
41
+ //#endregion
42
+ //#region src/providers/I18nProvider.d.ts
43
+ declare class I18nProvider<S extends object, K$1 extends keyof ServiceDictionary<S>> {
44
+ protected logger: _alepha_logger0.Logger;
45
+ protected alepha: Alepha;
46
+ protected dateTimeProvider: DateTimeProvider;
47
+ protected cookie: _alepha_server_cookies0.AbstractCookieDescriptor<typebox0.TString>;
48
+ readonly registry: Array<{
49
+ name: string;
50
+ lang: string;
51
+ loader: () => Promise<Record<string, string>>;
52
+ translations: Record<string, string>;
53
+ }>;
54
+ options: {
55
+ fallbackLang: string;
56
+ };
57
+ dateFormat: {
58
+ format: (value: Date) => string;
59
+ };
60
+ numberFormat: {
61
+ format: (value: number) => string;
62
+ };
63
+ get languages(): string[];
64
+ constructor();
65
+ protected readonly onRender: _alepha_core1.HookDescriptor<"server:onRequest">;
66
+ protected readonly onStart: _alepha_core1.HookDescriptor<"start">;
67
+ protected refreshLocale(): void;
68
+ setLang: (lang: string) => Promise<void>;
69
+ protected readonly mutate: _alepha_core1.HookDescriptor<"state:mutate">;
70
+ get lang(): string;
71
+ translate: (key: string, args?: string[]) => string;
72
+ readonly l: (value: I18nLocalizeType, options?: I18nLocalizeOptions) => string;
73
+ readonly tr: (key: keyof ServiceDictionary<S>[K$1], options?: {
74
+ args?: string[];
75
+ default?: string;
76
+ }) => string;
77
+ protected render(item: string, args: string[]): string;
78
+ }
79
+ type I18nLocalizeType = string | number | Date | DateTime | TypeBoxError;
80
+ interface I18nLocalizeOptions {
81
+ /**
82
+ * Options for number formatting (when value is a number)
83
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat
84
+ */
85
+ number?: Intl.NumberFormatOptions;
86
+ /**
87
+ * Options for date formatting (when value is a Date or DateTime)
88
+ * Can be:
89
+ * - A dayjs format string (e.g., "LLL", "YYYY-MM-DD", "dddd, MMMM D YYYY")
90
+ * - "fromNow" for relative time (e.g., "2 hours ago")
91
+ * - Intl.DateTimeFormatOptions for native formatting
92
+ * @see https://day.js.org/docs/en/display/format
93
+ * @see https://day.js.org/docs/en/display/from-now
94
+ */
95
+ date?: string | "fromNow" | Intl.DateTimeFormatOptions;
96
+ /**
97
+ * Timezone to display dates in (when value is a Date or DateTime)
98
+ * Uses IANA timezone names (e.g., "America/New_York", "Europe/Paris", "Asia/Tokyo")
99
+ * @see https://day.js.org/docs/en/timezone/timezone
100
+ */
101
+ timezone?: string;
102
+ }
103
+ //#endregion
104
+ //#region src/descriptors/$dictionary.d.ts
105
+ /**
106
+ * Register a dictionary entry for translations.
107
+ *
108
+ * It allows you to define a set of translations for a specific language.
109
+ * Entry can be lazy-loaded, which is useful for large dictionaries or when translations are not needed immediately.
110
+ *
111
+ * @example
112
+ * ```ts
113
+ * import { $dictionary } from "alepha/react-i18n";
114
+ *
115
+ * const Example = () => {
116
+ * const { tr } = useI18n<App, "en">();
117
+ * return <div>{tr("hello")}</div>; //
118
+ * }
119
+ *
120
+ * class App {
121
+ *
122
+ * en = $dictionary({
123
+ * // { default: { hello: "Hey" } }
124
+ * lazy: () => import("./translations/en.ts"),
125
+ * });
126
+ *
127
+ * home = $page({
128
+ * path: "/",
129
+ * component: Example,
130
+ * })
131
+ * }
132
+ *
133
+ * run(App);
134
+ * ```
135
+ */
136
+ declare const $dictionary: {
137
+ <T extends Record<string, string>>(options: DictionaryDescriptorOptions<T>): DictionaryDescriptor<T>;
138
+ [KIND]: typeof DictionaryDescriptor;
139
+ };
140
+ interface DictionaryDescriptorOptions<T extends Record<string, string>> {
141
+ lang?: string;
142
+ name?: string;
143
+ lazy: () => Promise<{
144
+ default: T;
145
+ }>;
146
+ }
147
+ declare class DictionaryDescriptor<T extends Record<string, string>> extends Descriptor<DictionaryDescriptorOptions<T>> {
148
+ protected provider: I18nProvider<object, never>;
149
+ protected onInit(): void;
150
+ }
151
+ //#endregion
152
+ //#region src/index.d.ts
153
+ declare module "alepha" {
154
+ interface State {
155
+ "react.i18n.lang"?: string;
156
+ }
157
+ }
158
+ /**
159
+ * Add i18n support to your Alepha React application. SSR and CSR compatible.
160
+ *
161
+ * It supports lazy loading of translations and provides a context to access the current language.
162
+ *
163
+ * @module alepha.react.i18n
164
+ */
165
+ declare const AlephaReactI18n: _alepha_core1.Service<_alepha_core1.Module<{}>>;
166
+ //#endregion
167
+ export { $dictionary, AlephaReactI18n, DictionaryDescriptor, DictionaryDescriptorOptions, I18nLocalizeOptions, I18nLocalizeType, I18nProvider, Localize, type LocalizeProps, ServiceDictionary, useI18n };
168
+ //# sourceMappingURL=index.d.ts.map